1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
/* srp.h
*
* Copyright (C) 2006-2026 wolfSSL Inc.
*
* This file is part of wolfSSL.
*
* wolfSSL is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 3 of the License, or
* (at your option) any later version.
*
* wolfSSL is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1335, USA
*/
/*!
\file wolfssl/wolfcrypt/srp.h
*/
extern "C"
/* Set the minimum number of bits acceptable in an SRP modulus */
/* Set the minimum number of bits acceptable for private keys (RFC 5054) */
/* salt size for SRP password */
/**
* SRP side, client or server.
*/
typedef enum SrpSide;
/**
* SRP hash type, SHA[1|256|384|512].
*/
typedef enum SrpType;
/**
* SRP hash struct.
*/
typedef struct SrpHash;
typedef struct Srp Srp;
/**
* Initializes the Srp struct for usage.
*
* @param[out] srp the Srp structure to be initialized.
* @param[in] type the hash type to be used.
* @param[in] side the side of the communication.
*
* @return 0 on success, {@literal <} 0 on error. @see error-crypt.h
*/
WOLFSSL_API int ;
WOLFSSL_API int ;
/**
* Releases the Srp struct resources after usage.
*
* @param[in,out] srp the Srp structure to be terminated.
*/
WOLFSSL_API void ;
/**
* Sets the username.
*
* This function MUST be called after wc_SrpInit.
*
* @param[in,out] srp the Srp structure.
* @param[in] username the buffer containing the username.
* @param[in] size the username size in bytes
*
* @return 0 on success, {@literal <} 0 on error. @see error-crypt.h
*/
WOLFSSL_API int ;
/**
* Sets the srp parameters based on the username.
*
* This function MUST be called after wc_SrpSetUsername.
*
* @param[in,out] srp the Srp structure.
* @param[in] N the Modulus. N = 2q+1, [q, N] are primes.
* @param[in] nSz the N size in bytes.
* @param[in] g the Generator modulo N.
* @param[in] gSz the g size in bytes
* @param[in] salt a small random salt. Specific for each username.
* @param[in] saltSz the salt size in bytes
*
* @return 0 on success, {@literal <} 0 on error. @see error-crypt.h
*/
WOLFSSL_API int ;
/**
* Sets the password.
*
* Setting the password does not persists the clear password data in the
* srp structure. The client calculates x = H(salt + H(user:pswd)) and stores
* it in the auth field.
*
* This function MUST be called after wc_SrpSetParams and is CLIENT SIDE ONLY.
*
* @param[in,out] srp the Srp structure.
* @param[in] password the buffer containing the password.
* @param[in] size the password size in bytes.
*
* @return 0 on success, {@literal <} 0 on error. @see error-crypt.h
*/
WOLFSSL_API int ;
/**
* Sets the verifier.
*
* This function MUST be called after wc_SrpSetParams and is SERVER SIDE ONLY.
*
* @param[in,out] srp the Srp structure.
* @param[in] verifier the buffer containing the verifier.
* @param[in] size the verifier size in bytes.
*
* @return 0 on success, {@literal <} 0 on error. @see error-crypt.h
*/
WOLFSSL_API int ;
/**
* Gets the verifier.
*
* The client calculates the verifier with v = g ^ x % N.
* This function MAY be called after wc_SrpSetPassword and is CLIENT SIDE ONLY.
*
* @param[in,out] srp the Srp structure.
* @param[out] verifier the buffer to write the verifier.
* @param[in,out] size the buffer size in bytes. Will be updated with the
* verifier size.
*
* @return 0 on success, {@literal <} 0 on error. @see error-crypt.h
*/
WOLFSSL_API int ;
/**
* Sets the private ephemeral value.
*
* The private ephemeral value is known as:
* a at the client side. a = random()
* b at the server side. b = random()
* This function is handy for unit test cases or if the developer wants to use
* an external random source to set the ephemeral value.
* This function MAY be called before wc_SrpGetPublic.
*
* @param[in,out] srp the Srp structure.
* @param[in] priv the ephemeral value.
* @param[in] size the private size in bytes.
*
* @return 0 on success, {@literal <} 0 on error. @see error-crypt.h
*/
WOLFSSL_API int ;
/**
* Gets the public ephemeral value.
*
* The public ephemeral value is known as:
* A at the client side. A = g ^ a % N
* B at the server side. B = (k * v + (g ^ b % N)) % N
* This function MUST be called after wc_SrpSetPassword or wc_SrpSetVerifier.
*
* @param[in,out] srp the Srp structure.
* @param[out] pub the buffer to write the public ephemeral value.
* @param[in,out] size the the buffer size in bytes. Will be updated with
* the ephemeral value size.
*
* @return 0 on success, {@literal <} 0 on error. @see error-crypt.h
*/
WOLFSSL_API int ;
/**
* Computes the session key.
*
* The key can be accessed at srp->key after success.
*
* @param[in,out] srp the Srp structure.
* @param[in] clientPubKey the client's public ephemeral value.
* @param[in] clientPubKeySz the client's public ephemeral value size.
* @param[in] serverPubKey the server's public ephemeral value.
* @param[in] serverPubKeySz the server's public ephemeral value size.
*
* @return 0 on success, {@literal <} 0 on error. @see error-crypt.h
*/
WOLFSSL_API int ;
/**
* Gets the proof.
*
* This function MUST be called after wc_SrpComputeKey.
*
* @param[in,out] srp the Srp structure.
* @param[out] proof the buffer to write the proof.
* @param[in,out] size the buffer size in bytes. Will be updated with the
* proof size.
*
* @return 0 on success, {@literal <} 0 on error. @see error-crypt.h
*/
WOLFSSL_API int ;
/**
* Verifies the peers proof.
*
* This function MUST be called before wc_SrpGetSessionKey.
*
* @param[in,out] srp the Srp structure.
* @param[in] proof the peers proof.
* @param[in] size the proof size in bytes.
*
* @return 0 on success, {@literal <} 0 on error. @see error-crypt.h
*/
WOLFSSL_API int ;
} /* extern "C" */
/* WOLFCRYPT_SRP_H */
/* WOLFCRYPT_HAVE_SRP */