@@ -58,6 +58,11 @@ type keyMaterial struct {
58
58
serverSecretKey * ecc.Scalar
59
59
serverPublicKey []byte
60
60
oprfSeed []byte
61
+ oprfClientSeed []byte
62
+ }
63
+
64
+ type OPRFSeedOptions struct {
65
+ OPRFSeed []byte
61
66
}
62
67
63
68
// NewServer returns a Server instantiation given the application Configuration.
@@ -84,49 +89,67 @@ func (s *Server) GetConf() *internal.Configuration {
84
89
return s .conf
85
90
}
86
91
87
- func (s * Server ) oprfResponse (element * ecc.Element , oprfSeed , credentialIdentifier []byte ) * ecc.Element {
88
- seed := s .conf .KDF .Expand (
89
- oprfSeed ,
90
- encoding .SuffixString (credentialIdentifier , tag .ExpandOPRF ),
91
- internal .SeedLength ,
92
- )
92
+ func (s * Server ) oprfResponse (element * ecc.Element , credentialIdentifier []byte ) (* ecc.Element , error ) {
93
+ if s .keyMaterial == nil {
94
+ return nil , fmt .Errorf ("key material must be specified" )
95
+ }
96
+ seed := s .keyMaterial .oprfClientSeed
97
+ if seed == nil {
98
+ if s .keyMaterial .oprfSeed == nil {
99
+ return nil , fmt .Errorf ("OPRF seed must be specified" )
100
+ }
101
+ seed = s .conf .KDF .Expand (
102
+ s .keyMaterial .oprfSeed ,
103
+ encoding .SuffixString (credentialIdentifier , tag .ExpandOPRF ),
104
+ internal .SeedLength ,
105
+ )
106
+ }
93
107
ku := s .conf .OPRF .DeriveKey (seed , []byte (tag .DeriveKeyPair ))
94
108
95
- return s .conf .OPRF .Evaluate (ku , element )
109
+ return s .conf .OPRF .Evaluate (ku , element ), nil
96
110
}
97
111
98
112
// RegistrationResponse returns a RegistrationResponse message to the input RegistrationRequest message and given
99
113
// identifiers.
100
114
func (s * Server ) RegistrationResponse (
101
115
req * message.RegistrationRequest ,
102
- serverPublicKey * ecc.Element ,
103
- credentialIdentifier , oprfSeed []byte ,
104
- ) * message.RegistrationResponse {
105
- z := s .oprfResponse (req .BlindedMessage , oprfSeed , credentialIdentifier )
116
+ credentialIdentifier []byte ,
117
+ ) (* message.RegistrationResponse , error ) {
118
+ z , err := s .oprfResponse (req .BlindedMessage , credentialIdentifier )
119
+ if err != nil {
120
+ return nil , err
121
+ }
122
+
123
+ serverPublicKey := s .conf .Group .NewElement ()
124
+ if err := serverPublicKey .Decode (s .keyMaterial .serverPublicKey ); err != nil {
125
+ return nil , fmt .Errorf ("invalid server public key: %w" , err )
126
+ }
106
127
107
128
return & message.RegistrationResponse {
108
129
EvaluatedMessage : z ,
109
130
Pks : serverPublicKey ,
110
- }
131
+ }, nil
111
132
}
112
133
113
134
func (s * Server ) credentialResponse (
114
135
req * message.CredentialRequest ,
115
- serverPublicKey []byte ,
116
136
record * message.RegistrationRecord ,
117
- credentialIdentifier , oprfSeed , maskingNonce []byte ,
118
- ) * message.CredentialResponse {
119
- z := s .oprfResponse (req .BlindedMessage , oprfSeed , credentialIdentifier )
137
+ credentialIdentifier , maskingNonce []byte ,
138
+ ) (* message.CredentialResponse , error ) {
139
+ z , err := s .oprfResponse (req .BlindedMessage , credentialIdentifier )
140
+ if err != nil {
141
+ return nil , err
142
+ }
120
143
121
144
maskingNonce , maskedResponse := masking .Mask (
122
145
s .conf ,
123
146
maskingNonce ,
124
147
record .MaskingKey ,
125
- serverPublicKey ,
148
+ s . keyMaterial . serverPublicKey ,
126
149
record .Envelope ,
127
150
)
128
151
129
- return message .NewCredentialResponse (z , maskingNonce , maskedResponse )
152
+ return message .NewCredentialResponse (z , maskingNonce , maskedResponse ), nil
130
153
}
131
154
132
155
// GenerateKE2Options enables setting optional values for the session, which default to secure random values if not
@@ -160,7 +183,7 @@ func getGenerateKE2Options(options []GenerateKE2Options) *ake.Options {
160
183
// - serverSecretKey is the server's secret AKE key.
161
184
// - serverPublicKey is the server's public AKE key to the serverSecretKey.
162
185
// - oprfSeed is the long-term OPRF input seed.
163
- func (s * Server ) SetKeyMaterial (serverIdentity , serverSecretKey , serverPublicKey , oprfSeed []byte ) error {
186
+ func (s * Server ) SetKeyMaterial (serverIdentity , serverSecretKey , serverPublicKey , oprfSeed []byte , oprfClientSeed [] byte ) error {
164
187
sks := s .conf .Group .NewScalar ()
165
188
if err := sks .Decode (serverSecretKey ); err != nil {
166
189
return fmt .Errorf ("invalid server AKE secret key: %w" , err )
@@ -170,7 +193,15 @@ func (s *Server) SetKeyMaterial(serverIdentity, serverSecretKey, serverPublicKey
170
193
return ErrZeroSKS
171
194
}
172
195
173
- if len (oprfSeed ) != s .conf .Hash .Size () {
196
+ if oprfSeed != nil {
197
+ if len (oprfSeed ) != s .conf .Hash .Size () {
198
+ return ErrInvalidOPRFSeedLength
199
+ }
200
+ } else if oprfClientSeed != nil {
201
+ if len (oprfClientSeed ) != internal .SeedLength {
202
+ return ErrInvalidOPRFSeedLength
203
+ }
204
+ } else {
174
205
return ErrInvalidOPRFSeedLength
175
206
}
176
207
@@ -187,6 +218,7 @@ func (s *Server) SetKeyMaterial(serverIdentity, serverSecretKey, serverPublicKey
187
218
serverSecretKey : sks ,
188
219
serverPublicKey : serverPublicKey ,
189
220
oprfSeed : oprfSeed ,
221
+ oprfClientSeed : oprfClientSeed ,
190
222
}
191
223
192
224
return nil
@@ -211,8 +243,11 @@ func (s *Server) GenerateKE2(
211
243
212
244
op := getGenerateKE2Options (options )
213
245
214
- response := s .credentialResponse (ke1 .CredentialRequest , s .keyMaterial .serverPublicKey ,
215
- record .RegistrationRecord , record .CredentialIdentifier , s .keyMaterial .oprfSeed , record .TestMaskNonce )
246
+ response , err := s .credentialResponse (ke1 .CredentialRequest ,
247
+ record .RegistrationRecord , record .CredentialIdentifier , record .TestMaskNonce )
248
+ if err != nil {
249
+ return nil , err
250
+ }
216
251
217
252
identities := ake.Identities {
218
253
ClientIdentity : record .ClientIdentity ,
0 commit comments