Bug Summary

File:lib/auth/srp.c
Location:line 931, column 8
Description:Although the value stored to 'ret' is used in the enclosing expression, the value is never actually read from 'ret'

Annotated Source Code

1/*
2 * Copyright (C) 2001-2012 Free Software Foundation, Inc.
3 *
4 * Author: Nikos Mavrogiannopoulos
5 *
6 * This file is part of GnuTLS.
7 *
8 * The GnuTLS is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU Lesser General Public License
10 * as published by the Free Software Foundation; either version 3 of
11 * the License, or (at your option) any later version.
12 *
13 * This library is distributed in the hope that it will be useful, but
14 * WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 * Lesser General Public License for more details.
17 *
18 * You should have received a copy of the GNU Lesser General Public License
19 * along with this program. If not, see <http://www.gnu.org/licenses/>
20 *
21 */
22
23#include <gnutls_int.h>
24
25#ifdef ENABLE_SRP1
26
27#include "gnutls_errors.h"
28#include <auth/srp_passwd.h>
29#include "gnutls_auth.h"
30#include "gnutls_auth.h"
31#include "gnutls_srp.h"
32#include "gnutls_num.h"
33#include <auth/srp.h>
34#include <gnutls_str.h>
35#include <gnutls_datumgnutls_datum_t.h>
36#include <ext/srp.h>
37
38const mod_auth_st srp_auth_struct = {
39 "SRP",
40 NULL((void*)0),
41 NULL((void*)0),
42 _gnutls_gen_srp_server_kx,
43 _gnutls_gen_srp_client_kx,
44 NULL((void*)0),
45 NULL((void*)0),
46
47 NULL((void*)0),
48 NULL((void*)0), /* certificate */
49 _gnutls_proc_srp_server_kx,
50 _gnutls_proc_srp_client_kx,
51 NULL((void*)0),
52 NULL((void*)0)
53};
54
55
56#define _bsession->key->b session->key->b
57#define Bsession->key->B session->key->Bsession->key->B
58#define _asession->key->a session->key->a
59#define Asession->key->A session->key->Asession->key->A
60#define Nsession->key->client_p session->key->client_p
61#define Gsession->key->client_g session->key->client_g
62#define Vsession->key->x session->key->x
63#define Ssession->key->KEY session->key->KEY
64
65/* Checks if b%n==0 which is a fatal srp error.
66 * Returns a proper error code in that case, and 0 when
67 * all are ok.
68 */
69inline static int
70check_b_mod_n (bigint_t b, bigint_t n)
71{
72 int ret;
73 bigint_t r;
74
75 r = _gnutls_mpi_mod (b, n)_gnutls_mpi_ops.bigint_mod(b,n);
76
77 if (r == NULL((void*)0))
78 {
79 gnutls_assert ()do { if (__builtin_expect((_gnutls_log_level >= 2), 0)) _gnutls_log
( 2, "ASSERT: %s:%d\n", "srp.c",79); } while(0);
;
80 return GNUTLS_E_MEMORY_ERROR-25;
81 }
82
83 ret = _gnutls_mpi_cmp_ui (r, 0)_gnutls_mpi_ops.bigint_cmp_ui(r,0);
84
85 _gnutls_mpi_release (&r);
86
87 if (ret == 0)
88 {
89 gnutls_assert ()do { if (__builtin_expect((_gnutls_log_level >= 2), 0)) _gnutls_log
( 2, "ASSERT: %s:%d\n", "srp.c",89); } while(0);
;
90 return GNUTLS_E_RECEIVED_ILLEGAL_PARAMETER-55;
91 }
92
93 return 0;
94}
95
96/* Checks if a%n==0,+1,-1%n which is a fatal srp error.
97 * Returns a proper error code in that case, and 0 when
98 * all are ok.
99 */
100inline static int
101check_a_mod_n (bigint_t a, bigint_t n)
102{
103 int ret;
104 bigint_t r;
105
106 r = _gnutls_mpi_mod (a, n)_gnutls_mpi_ops.bigint_mod(a,n);
107 if (r == NULL((void*)0))
108 {
109 gnutls_assert ()do { if (__builtin_expect((_gnutls_log_level >= 2), 0)) _gnutls_log
( 2, "ASSERT: %s:%d\n", "srp.c",109); } while(0);
;
110 return GNUTLS_E_MEMORY_ERROR-25;
111 }
112
113 ret = _gnutls_mpi_cmp_ui (r, 0)_gnutls_mpi_ops.bigint_cmp_ui(r,0);
114
115 _gnutls_mpi_release (&r);
116
117 if (ret == 0)
118 {
119 gnutls_assert ()do { if (__builtin_expect((_gnutls_log_level >= 2), 0)) _gnutls_log
( 2, "ASSERT: %s:%d\n", "srp.c",119); } while(0);
;
120 return GNUTLS_E_RECEIVED_ILLEGAL_PARAMETER-55;
121 }
122
123 return 0;
124}
125
126
127/* Send the first key exchange message ( g, n, s) and append the verifier algorithm number
128 * Data is allocated by the caller, and should have data_size size.
129 */
130int
131_gnutls_gen_srp_server_kx (gnutls_session_t session, gnutls_buffer_st* data)
132{
133 int ret;
134 char *username;
135 SRP_PWD_ENTRY *pwd_entry;
136 srp_server_auth_info_t info;
137 size_t tmp_size;
138 extension_priv_data_t epriv;
139 srp_ext_st *priv;
140
141 ret = _gnutls_ext_get_session_data (session, GNUTLS_EXTENSION_SRP, &epriv);
142 if (ret < 0) /* peer didn't send a username */
143 {
144 gnutls_assert ()do { if (__builtin_expect((_gnutls_log_level >= 2), 0)) _gnutls_log
( 2, "ASSERT: %s:%d\n", "srp.c",144); } while(0);
;
145 return GNUTLS_E_UNKNOWN_SRP_USERNAME-109;
146 }
147 priv = epriv.ptr;
148
149 if ((ret =
150 _gnutls_auth_info_set (session, GNUTLS_CRD_SRP,
151 sizeof (srp_server_auth_info_st), 1)) < 0)
152 {
153 gnutls_assert ()do { if (__builtin_expect((_gnutls_log_level >= 2), 0)) _gnutls_log
( 2, "ASSERT: %s:%d\n", "srp.c",153); } while(0);
;
154 return ret;
155 }
156
157 info = _gnutls_get_auth_info (session);
158 username = info->username;
159
160 _gnutls_str_cpy (username, MAX_USERNAME_SIZE128, priv->username);
161
162 ret = _gnutls_srp_pwd_read_entry (session, username, &pwd_entry);
163
164 if (ret < 0)
165 {
166 gnutls_assert ()do { if (__builtin_expect((_gnutls_log_level >= 2), 0)) _gnutls_log
( 2, "ASSERT: %s:%d\n", "srp.c",166); } while(0);
;
167 return ret;
168 }
169
170 /* copy from pwd_entry to local variables (actually in session) */
171 tmp_size = pwd_entry->g.size;
172 if (_gnutls_mpi_scan_nz (&Gsession->key->client_g, pwd_entry->g.data, tmp_size) < 0)
173 {
174 gnutls_assert ()do { if (__builtin_expect((_gnutls_log_level >= 2), 0)) _gnutls_log
( 2, "ASSERT: %s:%d\n", "srp.c",174); } while(0);
;
175 ret = GNUTLS_E_MPI_SCAN_FAILED-23;
176 goto cleanup;
177 }
178
179 tmp_size = pwd_entry->n.size;
180 if (_gnutls_mpi_scan_nz (&Nsession->key->client_p, pwd_entry->n.data, tmp_size) < 0)
181 {
182 gnutls_assert ()do { if (__builtin_expect((_gnutls_log_level >= 2), 0)) _gnutls_log
( 2, "ASSERT: %s:%d\n", "srp.c",182); } while(0);
;
183 ret = GNUTLS_E_MPI_SCAN_FAILED-23;
184 goto cleanup;
185 }
186
187 tmp_size = pwd_entry->v.size;
188 if (_gnutls_mpi_scan_nz (&Vsession->key->x, pwd_entry->v.data, tmp_size) < 0)
189 {
190 gnutls_assert ()do { if (__builtin_expect((_gnutls_log_level >= 2), 0)) _gnutls_log
( 2, "ASSERT: %s:%d\n", "srp.c",190); } while(0);
;
191 ret = GNUTLS_E_MPI_SCAN_FAILED-23;
192 goto cleanup;
193 }
194
195 /* Calculate: B = (k*v + g^b) % N
196 */
197 Bsession->key->B = _gnutls_calc_srp_B (&_bsession->key->b, Gsession->key->client_g, Nsession->key->client_p, Vsession->key->x);
198 if (Bsession->key->B == NULL((void*)0))
199 {
200 gnutls_assert ()do { if (__builtin_expect((_gnutls_log_level >= 2), 0)) _gnutls_log
( 2, "ASSERT: %s:%d\n", "srp.c",200); } while(0);
;
201 ret = GNUTLS_E_MEMORY_ERROR-25;
202 goto cleanup;
203 }
204
205 /* copy N (mod n)
206 */
207 ret = _gnutls_buffer_append_data_prefix( data, 16, pwd_entry->n.data,
208 pwd_entry->n.size);
209 if (ret < 0)
210 {
211 gnutls_assert()do { if (__builtin_expect((_gnutls_log_level >= 2), 0)) _gnutls_log
( 2, "ASSERT: %s:%d\n", "srp.c",211); } while(0);
;
212 goto cleanup;
213 }
214
215 /* copy G (generator) to data
216 */
217 ret = _gnutls_buffer_append_data_prefix( data, 16, pwd_entry->g.data,
218 pwd_entry->g.size);
219 if (ret < 0)
220 {
221 gnutls_assert()do { if (__builtin_expect((_gnutls_log_level >= 2), 0)) _gnutls_log
( 2, "ASSERT: %s:%d\n", "srp.c",221); } while(0);
;
222 goto cleanup;
223 }
224
225 /* copy the salt
226 */
227 ret = _gnutls_buffer_append_data_prefix( data, 8, pwd_entry->salt.data,
228 pwd_entry->salt.size);
229 if (ret < 0)
230 {
231 gnutls_assert()do { if (__builtin_expect((_gnutls_log_level >= 2), 0)) _gnutls_log
( 2, "ASSERT: %s:%d\n", "srp.c",231); } while(0);
;
232 goto cleanup;
233 }
234
235 /* Copy the B value
236 */
237
238 ret = _gnutls_buffer_append_mpi( data, 16, Bsession->key->B, 0);
239 if (ret < 0)
240 {
241 gnutls_assert()do { if (__builtin_expect((_gnutls_log_level >= 2), 0)) _gnutls_log
( 2, "ASSERT: %s:%d\n", "srp.c",241); } while(0);
;
242 goto cleanup;
243 }
244
245 _gnutls_mpi_log ("SRP B: ", Bsession->key->B);
246
247 _gnutls_srp_entry_free (pwd_entry);
248
249 ret = data->length;
250
251cleanup:
252 _gnutls_srp_entry_free (pwd_entry);
253 return ret;
254}
255
256/* return A = g^a % N */
257int
258_gnutls_gen_srp_client_kx (gnutls_session_t session, gnutls_buffer_st* data)
259{
260 int ret;
261 char *username, *password;
262 gnutls_srp_client_credentials_t cred;
263 extension_priv_data_t epriv;
264 srp_ext_st *priv;
265
266 ret = _gnutls_ext_get_session_data (session, GNUTLS_EXTENSION_SRP, &epriv);
267 if (ret < 0) /* peer didn't send a username */
268 {
269 gnutls_assert ()do { if (__builtin_expect((_gnutls_log_level >= 2), 0)) _gnutls_log
( 2, "ASSERT: %s:%d\n", "srp.c",269); } while(0);
;
270 return GNUTLS_E_UNKNOWN_SRP_USERNAME-109;
271 }
272 priv = epriv.ptr;
273
274 cred = (gnutls_srp_client_credentials_t)
275 _gnutls_get_cred (session->key, GNUTLS_CRD_SRP, NULL((void*)0));
276
277 if (cred == NULL((void*)0))
278 {
279 gnutls_assert ()do { if (__builtin_expect((_gnutls_log_level >= 2), 0)) _gnutls_log
( 2, "ASSERT: %s:%d\n", "srp.c",279); } while(0);
;
280 return GNUTLS_E_INSUFFICIENT_CREDENTIALS-32;
281 }
282
283 if (priv->username == NULL((void*)0))
284 {
285 username = cred->username;
286 password = cred->password;
287 }
288 else
289 {
290
291 username = priv->username;
292 password = priv->password;
293 }
294
295 if (username == NULL((void*)0) || password == NULL((void*)0))
296 {
297 gnutls_assert ()do { if (__builtin_expect((_gnutls_log_level >= 2), 0)) _gnutls_log
( 2, "ASSERT: %s:%d\n", "srp.c",297); } while(0);
;
298 return GNUTLS_E_INSUFFICIENT_CREDENTIALS-32;
299 }
300
301 /* calc A = g^a % N
302 */
303 if (Gsession->key->client_g == NULL((void*)0) || Nsession->key->client_p == NULL((void*)0))
304 {
305 gnutls_assert ()do { if (__builtin_expect((_gnutls_log_level >= 2), 0)) _gnutls_log
( 2, "ASSERT: %s:%d\n", "srp.c",305); } while(0);
;
306 return GNUTLS_E_INSUFFICIENT_CREDENTIALS-32;
307 }
308
309 Asession->key->A = _gnutls_calc_srp_A (&_asession->key->a, Gsession->key->client_g, Nsession->key->client_p);
310 if (Asession->key->A == NULL((void*)0))
311 {
312 gnutls_assert ()do { if (__builtin_expect((_gnutls_log_level >= 2), 0)) _gnutls_log
( 2, "ASSERT: %s:%d\n", "srp.c",312); } while(0);
;
313 return GNUTLS_E_MEMORY_ERROR-25;
314 }
315
316 /* Rest of SRP calculations
317 */
318
319 /* calculate u */
320 session->key->u = _gnutls_calc_srp_u (Asession->key->A, Bsession->key->B, Nsession->key->client_p);
321 if (session->key->u == NULL((void*)0))
322 {
323 gnutls_assert ()do { if (__builtin_expect((_gnutls_log_level >= 2), 0)) _gnutls_log
( 2, "ASSERT: %s:%d\n", "srp.c",323); } while(0);
;
324 return GNUTLS_E_MEMORY_ERROR-25;
325 }
326
327 _gnutls_mpi_log ("SRP U: ", session->key->u);
328
329 /* S = (B - g^x) ^ (a + u * x) % N */
330 Ssession->key->KEY = _gnutls_calc_srp_S2 (Bsession->key->B, Gsession->key->client_g, session->key->x, _asession->key->a, session->key->u, Nsession->key->client_p);
331 if (Ssession->key->KEY == NULL((void*)0))
332 {
333 gnutls_assert ()do { if (__builtin_expect((_gnutls_log_level >= 2), 0)) _gnutls_log
( 2, "ASSERT: %s:%d\n", "srp.c",333); } while(0);
;
334 return GNUTLS_E_MEMORY_ERROR-25;
335 }
336
337 _gnutls_mpi_log ("SRP B: ", Bsession->key->B);
338
339 _gnutls_mpi_release (&_bsession->key->b);
340 _gnutls_mpi_release (&Vsession->key->x);
341 _gnutls_mpi_release (&session->key->u);
342 _gnutls_mpi_release (&Bsession->key->B);
343
344 ret = _gnutls_mpi_dprint (session->key->KEY, &session->key->key);
345 _gnutls_mpi_release (&Ssession->key->KEY);
346
347 if (ret < 0)
348 {
349 gnutls_assert ()do { if (__builtin_expect((_gnutls_log_level >= 2), 0)) _gnutls_log
( 2, "ASSERT: %s:%d\n", "srp.c",349); } while(0);
;
350 return ret;
351 }
352
353 ret = _gnutls_buffer_append_mpi(data, 16, Asession->key->A, 0);
354 if (ret < 0)
355 return gnutls_assert_val(ret)gnutls_assert_val_int(ret, "srp.c", 355);
356
357 _gnutls_mpi_log ("SRP A: ", Asession->key->A);
358
359 _gnutls_mpi_release (&Asession->key->A);
360
361 return data->length;
362}
363
364
365/* just read A and put it to session */
366int
367_gnutls_proc_srp_client_kx (gnutls_session_t session, opaque * data,
368 size_t _data_size)
369{
370 size_t _n_A;
371 ssize_t data_size = _data_size;
372 int ret;
373
374 DECR_LEN (data_size, 2)do { data_size-=2; if (data_size<0) {do { if (__builtin_expect
((_gnutls_log_level >= 2), 0)) _gnutls_log( 2, "ASSERT: %s:%d\n"
, "srp.c",374); } while(0);; return -9;} } while (0)
;
375 _n_A = _gnutls_read_uint16 (&data[0]);
376
377 DECR_LEN (data_size, _n_A)do { data_size-=_n_A; if (data_size<0) {do { if (__builtin_expect
((_gnutls_log_level >= 2), 0)) _gnutls_log( 2, "ASSERT: %s:%d\n"
, "srp.c",377); } while(0);; return -9;} } while (0)
;
378 if (_gnutls_mpi_scan_nz (&Asession->key->A, &data[2], _n_A) || Asession->key->A == NULL((void*)0))
379 {
380 gnutls_assert ()do { if (__builtin_expect((_gnutls_log_level >= 2), 0)) _gnutls_log
( 2, "ASSERT: %s:%d\n", "srp.c",380); } while(0);
;
381 return GNUTLS_E_MPI_SCAN_FAILED-23;
382 }
383
384 _gnutls_mpi_log ("SRP A: ", Asession->key->A);
385 _gnutls_mpi_log ("SRP B: ", Bsession->key->B);
386
387 /* Checks if A % n == 0.
388 */
389 if ((ret = check_a_mod_n (Asession->key->A, Nsession->key->client_p)) < 0)
390 {
391 gnutls_assert ()do { if (__builtin_expect((_gnutls_log_level >= 2), 0)) _gnutls_log
( 2, "ASSERT: %s:%d\n", "srp.c",391); } while(0);
;
392 return ret;
393 }
394
395 /* Start the SRP calculations.
396 * - Calculate u
397 */
398 session->key->u = _gnutls_calc_srp_u (Asession->key->A, Bsession->key->B, Nsession->key->client_p);
399 if (session->key->u == NULL((void*)0))
400 {
401 gnutls_assert ()do { if (__builtin_expect((_gnutls_log_level >= 2), 0)) _gnutls_log
( 2, "ASSERT: %s:%d\n", "srp.c",401); } while(0);
;
402 return GNUTLS_E_MEMORY_ERROR-25;
403 }
404
405 _gnutls_mpi_log ("SRP U: ", session->key->u);
406
407 /* S = (A * v^u) ^ b % N
408 */
409 Ssession->key->KEY = _gnutls_calc_srp_S1 (Asession->key->A, _bsession->key->b, session->key->u, Vsession->key->x, Nsession->key->client_p);
410 if (Ssession->key->KEY == NULL((void*)0))
411 {
412 gnutls_assert ()do { if (__builtin_expect((_gnutls_log_level >= 2), 0)) _gnutls_log
( 2, "ASSERT: %s:%d\n", "srp.c",412); } while(0);
;
413 return GNUTLS_E_MEMORY_ERROR-25;
414 }
415
416 _gnutls_mpi_log ("SRP S: ", Ssession->key->KEY);
417
418 _gnutls_mpi_release (&Asession->key->A);
419 _gnutls_mpi_release (&_bsession->key->b);
420 _gnutls_mpi_release (&Vsession->key->x);
421 _gnutls_mpi_release (&session->key->u);
422 _gnutls_mpi_release (&Bsession->key->B);
423
424 ret = _gnutls_mpi_dprint (session->key->KEY, &session->key->key);
425 _gnutls_mpi_release (&Ssession->key->KEY);
426
427 if (ret < 0)
428 {
429 gnutls_assert ()do { if (__builtin_expect((_gnutls_log_level >= 2), 0)) _gnutls_log
( 2, "ASSERT: %s:%d\n", "srp.c",429); } while(0);
;
430 return ret;
431 }
432
433 return 0;
434}
435
436
437
438/* Static parameters according to draft-ietf-tls-srp-07
439 * Note that if more parameters are added check_g_n()
440 * and _gnutls_srp_entry_free() should be changed.
441 */
442static const unsigned char srp_params_1024[] = {
443 0xEE, 0xAF, 0x0A, 0xB9, 0xAD, 0xB3, 0x8D, 0xD6,
444 0x9C, 0x33, 0xF8, 0x0A, 0xFA, 0x8F, 0xC5, 0xE8,
445 0x60, 0x72, 0x61, 0x87, 0x75, 0xFF, 0x3C, 0x0B,
446 0x9E, 0xA2, 0x31, 0x4C, 0x9C, 0x25, 0x65, 0x76,
447 0xD6, 0x74, 0xDF, 0x74, 0x96, 0xEA, 0x81, 0xD3,
448 0x38, 0x3B, 0x48, 0x13, 0xD6, 0x92, 0xC6, 0xE0,
449 0xE0, 0xD5, 0xD8, 0xE2, 0x50, 0xB9, 0x8B, 0xE4,
450 0x8E, 0x49, 0x5C, 0x1D, 0x60, 0x89, 0xDA, 0xD1,
451 0x5D, 0xC7, 0xD7, 0xB4, 0x61, 0x54, 0xD6, 0xB6,
452 0xCE, 0x8E, 0xF4, 0xAD, 0x69, 0xB1, 0x5D, 0x49,
453 0x82, 0x55, 0x9B, 0x29, 0x7B, 0xCF, 0x18, 0x85,
454 0xC5, 0x29, 0xF5, 0x66, 0x66, 0x0E, 0x57, 0xEC,
455 0x68, 0xED, 0xBC, 0x3C, 0x05, 0x72, 0x6C, 0xC0,
456 0x2F, 0xD4, 0xCB, 0xF4, 0x97, 0x6E, 0xAA, 0x9A,
457 0xFD, 0x51, 0x38, 0xFE, 0x83, 0x76, 0x43, 0x5B,
458 0x9F, 0xC6, 0x1D, 0x2F, 0xC0, 0xEB, 0x06, 0xE3
459};
460
461static const unsigned char srp_generator = 0x02;
462static const unsigned char srp3072_generator = 0x05;
463
464const gnutls_datum_t gnutls_srp_1024_group_prime = {
465 (void *) srp_params_1024, sizeof (srp_params_1024)
466};
467
468const gnutls_datum_t gnutls_srp_1024_group_generator = {
469 (void *) &srp_generator, sizeof (srp_generator)
470};
471
472static const unsigned char srp_params_1536[] = {
473 0x9D, 0xEF, 0x3C, 0xAF, 0xB9, 0x39, 0x27, 0x7A, 0xB1,
474 0xF1, 0x2A, 0x86, 0x17, 0xA4, 0x7B, 0xBB, 0xDB, 0xA5,
475 0x1D, 0xF4, 0x99, 0xAC, 0x4C, 0x80, 0xBE, 0xEE, 0xA9,
476 0x61, 0x4B, 0x19, 0xCC, 0x4D, 0x5F, 0x4F, 0x5F, 0x55,
477 0x6E, 0x27, 0xCB, 0xDE, 0x51, 0xC6, 0xA9, 0x4B, 0xE4,
478 0x60, 0x7A, 0x29, 0x15, 0x58, 0x90, 0x3B, 0xA0, 0xD0,
479 0xF8, 0x43, 0x80, 0xB6, 0x55, 0xBB, 0x9A, 0x22, 0xE8,
480 0xDC, 0xDF, 0x02, 0x8A, 0x7C, 0xEC, 0x67, 0xF0, 0xD0,
481 0x81, 0x34, 0xB1, 0xC8, 0xB9, 0x79, 0x89, 0x14, 0x9B,
482 0x60, 0x9E, 0x0B, 0xE3, 0xBA, 0xB6, 0x3D, 0x47, 0x54,
483 0x83, 0x81, 0xDB, 0xC5, 0xB1, 0xFC, 0x76, 0x4E, 0x3F,
484 0x4B, 0x53, 0xDD, 0x9D, 0xA1, 0x15, 0x8B, 0xFD, 0x3E,
485 0x2B, 0x9C, 0x8C, 0xF5, 0x6E, 0xDF, 0x01, 0x95, 0x39,
486 0x34, 0x96, 0x27, 0xDB, 0x2F, 0xD5, 0x3D, 0x24, 0xB7,
487 0xC4, 0x86, 0x65, 0x77, 0x2E, 0x43, 0x7D, 0x6C, 0x7F,
488 0x8C, 0xE4, 0x42, 0x73, 0x4A, 0xF7, 0xCC, 0xB7, 0xAE,
489 0x83, 0x7C, 0x26, 0x4A, 0xE3, 0xA9, 0xBE, 0xB8, 0x7F,
490 0x8A, 0x2F, 0xE9, 0xB8, 0xB5, 0x29, 0x2E, 0x5A, 0x02,
491 0x1F, 0xFF, 0x5E, 0x91, 0x47, 0x9E, 0x8C, 0xE7, 0xA2,
492 0x8C, 0x24, 0x42, 0xC6, 0xF3, 0x15, 0x18, 0x0F, 0x93,
493 0x49, 0x9A, 0x23, 0x4D, 0xCF, 0x76, 0xE3, 0xFE, 0xD1,
494 0x35, 0xF9, 0xBB
495};
496
497const gnutls_datum_t gnutls_srp_1536_group_prime = {
498 (void *) srp_params_1536, sizeof (srp_params_1536)
499};
500
501const gnutls_datum_t gnutls_srp_1536_group_generator = {
502 (void *) &srp_generator, sizeof (srp_generator)
503};
504
505static const unsigned char srp_params_2048[] = {
506 0xAC, 0x6B, 0xDB, 0x41, 0x32, 0x4A, 0x9A, 0x9B, 0xF1,
507 0x66, 0xDE, 0x5E, 0x13, 0x89, 0x58, 0x2F, 0xAF, 0x72,
508 0xB6, 0x65, 0x19, 0x87, 0xEE, 0x07, 0xFC, 0x31, 0x92,
509 0x94, 0x3D, 0xB5, 0x60, 0x50, 0xA3, 0x73, 0x29, 0xCB,
510 0xB4, 0xA0, 0x99, 0xED, 0x81, 0x93, 0xE0, 0x75, 0x77,
511 0x67, 0xA1, 0x3D, 0xD5, 0x23, 0x12, 0xAB, 0x4B, 0x03,
512 0x31, 0x0D, 0xCD, 0x7F, 0x48, 0xA9, 0xDA, 0x04, 0xFD,
513 0x50, 0xE8, 0x08, 0x39, 0x69, 0xED, 0xB7, 0x67, 0xB0,
514 0xCF, 0x60, 0x95, 0x17, 0x9A, 0x16, 0x3A, 0xB3, 0x66,
515 0x1A, 0x05, 0xFB, 0xD5, 0xFA, 0xAA, 0xE8, 0x29, 0x18,
516 0xA9, 0x96, 0x2F, 0x0B, 0x93, 0xB8, 0x55, 0xF9, 0x79,
517 0x93, 0xEC, 0x97, 0x5E, 0xEA, 0xA8, 0x0D, 0x74, 0x0A,
518 0xDB, 0xF4, 0xFF, 0x74, 0x73, 0x59, 0xD0, 0x41, 0xD5,
519 0xC3, 0x3E, 0xA7, 0x1D, 0x28, 0x1E, 0x44, 0x6B, 0x14,
520 0x77, 0x3B, 0xCA, 0x97, 0xB4, 0x3A, 0x23, 0xFB, 0x80,
521 0x16, 0x76, 0xBD, 0x20, 0x7A, 0x43, 0x6C, 0x64, 0x81,
522 0xF1, 0xD2, 0xB9, 0x07, 0x87, 0x17, 0x46, 0x1A, 0x5B,
523 0x9D, 0x32, 0xE6, 0x88, 0xF8, 0x77, 0x48, 0x54, 0x45,
524 0x23, 0xB5, 0x24, 0xB0, 0xD5, 0x7D, 0x5E, 0xA7, 0x7A,
525 0x27, 0x75, 0xD2, 0xEC, 0xFA, 0x03, 0x2C, 0xFB, 0xDB,
526 0xF5, 0x2F, 0xB3, 0x78, 0x61, 0x60, 0x27, 0x90, 0x04,
527 0xE5, 0x7A, 0xE6, 0xAF, 0x87, 0x4E, 0x73, 0x03, 0xCE,
528 0x53, 0x29, 0x9C, 0xCC, 0x04, 0x1C, 0x7B, 0xC3, 0x08,
529 0xD8, 0x2A, 0x56, 0x98, 0xF3, 0xA8, 0xD0, 0xC3, 0x82,
530 0x71, 0xAE, 0x35, 0xF8, 0xE9, 0xDB, 0xFB, 0xB6, 0x94,
531 0xB5, 0xC8, 0x03, 0xD8, 0x9F, 0x7A, 0xE4, 0x35, 0xDE,
532 0x23, 0x6D, 0x52, 0x5F, 0x54, 0x75, 0x9B, 0x65, 0xE3,
533 0x72, 0xFC, 0xD6, 0x8E, 0xF2, 0x0F, 0xA7, 0x11, 0x1F,
534 0x9E, 0x4A, 0xFF, 0x73
535};
536
537const gnutls_datum_t gnutls_srp_2048_group_prime = {
538 (void *) srp_params_2048, sizeof (srp_params_2048)
539};
540
541const gnutls_datum_t gnutls_srp_2048_group_generator = {
542 (void *) &srp_generator, sizeof (srp_generator)
543};
544
545static const unsigned char srp_params_3072[] = {
546 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xC9,
547 0x0F, 0xDA, 0xA2, 0x21, 0x68, 0xC2, 0x34, 0xC4, 0xC6,
548 0x62, 0x8B, 0x80, 0xDC, 0x1C, 0xD1, 0x29, 0x02, 0x4E,
549 0x08, 0x8A, 0x67, 0xCC, 0x74, 0x02, 0x0B, 0xBE, 0xA6,
550 0x3B, 0x13, 0x9B, 0x22, 0x51, 0x4A, 0x08, 0x79, 0x8E,
551 0x34, 0x04, 0xDD, 0xEF, 0x95, 0x19, 0xB3, 0xCD, 0x3A,
552 0x43, 0x1B, 0x30, 0x2B, 0x0A, 0x6D, 0xF2, 0x5F, 0x14,
553 0x37, 0x4F, 0xE1, 0x35, 0x6D, 0x6D, 0x51, 0xC2, 0x45,
554 0xE4, 0x85, 0xB5, 0x76, 0x62, 0x5E, 0x7E, 0xC6, 0xF4,
555 0x4C, 0x42, 0xE9, 0xA6, 0x37, 0xED, 0x6B, 0x0B, 0xFF,
556 0x5C, 0xB6, 0xF4, 0x06, 0xB7, 0xED, 0xEE, 0x38, 0x6B,
557 0xFB, 0x5A, 0x89, 0x9F, 0xA5, 0xAE, 0x9F, 0x24, 0x11,
558 0x7C, 0x4B, 0x1F, 0xE6, 0x49, 0x28, 0x66, 0x51, 0xEC,
559 0xE4, 0x5B, 0x3D, 0xC2, 0x00, 0x7C, 0xB8, 0xA1, 0x63,
560 0xBF, 0x05, 0x98, 0xDA, 0x48, 0x36, 0x1C, 0x55, 0xD3,
561 0x9A, 0x69, 0x16, 0x3F, 0xA8, 0xFD, 0x24, 0xCF, 0x5F,
562 0x83, 0x65, 0x5D, 0x23, 0xDC, 0xA3, 0xAD, 0x96, 0x1C,
563 0x62, 0xF3, 0x56, 0x20, 0x85, 0x52, 0xBB, 0x9E, 0xD5,
564 0x29, 0x07, 0x70, 0x96, 0x96, 0x6D, 0x67, 0x0C, 0x35,
565 0x4E, 0x4A, 0xBC, 0x98, 0x04, 0xF1, 0x74, 0x6C, 0x08,
566 0xCA, 0x18, 0x21, 0x7C, 0x32, 0x90, 0x5E, 0x46, 0x2E,
567 0x36, 0xCE, 0x3B, 0xE3, 0x9E, 0x77, 0x2C, 0x18, 0x0E,
568 0x86, 0x03, 0x9B, 0x27, 0x83, 0xA2, 0xEC, 0x07, 0xA2,
569 0x8F, 0xB5, 0xC5, 0x5D, 0xF0, 0x6F, 0x4C, 0x52, 0xC9,
570 0xDE, 0x2B, 0xCB, 0xF6, 0x95, 0x58, 0x17, 0x18, 0x39,
571 0x95, 0x49, 0x7C, 0xEA, 0x95, 0x6A, 0xE5, 0x15, 0xD2,
572 0x26, 0x18, 0x98, 0xFA, 0x05, 0x10, 0x15, 0x72, 0x8E,
573 0x5A, 0x8A, 0xAA, 0xC4, 0x2D, 0xAD, 0x33, 0x17, 0x0D,
574 0x04, 0x50, 0x7A, 0x33, 0xA8, 0x55, 0x21, 0xAB, 0xDF,
575 0x1C, 0xBA, 0x64, 0xEC, 0xFB, 0x85, 0x04, 0x58, 0xDB,
576 0xEF, 0x0A, 0x8A, 0xEA, 0x71, 0x57, 0x5D, 0x06, 0x0C,
577 0x7D, 0xB3, 0x97, 0x0F, 0x85, 0xA6, 0xE1, 0xE4, 0xC7,
578 0xAB, 0xF5, 0xAE, 0x8C, 0xDB, 0x09, 0x33, 0xD7, 0x1E,
579 0x8C, 0x94, 0xE0, 0x4A, 0x25, 0x61, 0x9D, 0xCE, 0xE3,
580 0xD2, 0x26, 0x1A, 0xD2, 0xEE, 0x6B, 0xF1, 0x2F, 0xFA,
581 0x06, 0xD9, 0x8A, 0x08, 0x64, 0xD8, 0x76, 0x02, 0x73,
582 0x3E, 0xC8, 0x6A, 0x64, 0x52, 0x1F, 0x2B, 0x18, 0x17,
583 0x7B, 0x20, 0x0C, 0xBB, 0xE1, 0x17, 0x57, 0x7A, 0x61,
584 0x5D, 0x6C, 0x77, 0x09, 0x88, 0xC0, 0xBA, 0xD9, 0x46,
585 0xE2, 0x08, 0xE2, 0x4F, 0xA0, 0x74, 0xE5, 0xAB, 0x31,
586 0x43, 0xDB, 0x5B, 0xFC, 0xE0, 0xFD, 0x10, 0x8E, 0x4B,
587 0x82, 0xD1, 0x20, 0xA9, 0x3A, 0xD2, 0xCA, 0xFF, 0xFF,
588 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF
589};
590
591const gnutls_datum_t gnutls_srp_3072_group_generator = {
592 (void *) &srp3072_generator, sizeof (srp3072_generator)
593};
594
595const gnutls_datum_t gnutls_srp_3072_group_prime = {
596 (void *) srp_params_3072, sizeof (srp_params_3072)
597};
598
599static const unsigned char srp_params_4096[] = {
6000xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xC9, 0x0F, 0xDA, 0xA2,
6010x21, 0x68, 0xC2, 0x34, 0xC4, 0xC6, 0x62, 0x8B, 0x80, 0xDC, 0x1C, 0xD1,
6020x29, 0x02, 0x4E, 0x08, 0x8A, 0x67, 0xCC, 0x74, 0x02, 0x0B, 0xBE, 0xA6,
6030x3B, 0x13, 0x9B, 0x22, 0x51, 0x4A, 0x08, 0x79, 0x8E, 0x34, 0x04, 0xDD,
6040xEF, 0x95, 0x19, 0xB3, 0xCD, 0x3A, 0x43, 0x1B, 0x30, 0x2B, 0x0A, 0x6D,
6050xF2, 0x5F, 0x14, 0x37, 0x4F, 0xE1, 0x35, 0x6D, 0x6D, 0x51, 0xC2, 0x45,
6060xE4, 0x85, 0xB5, 0x76, 0x62, 0x5E, 0x7E, 0xC6, 0xF4, 0x4C, 0x42, 0xE9,
6070xA6, 0x37, 0xED, 0x6B, 0x0B, 0xFF, 0x5C, 0xB6, 0xF4, 0x06, 0xB7, 0xED,
6080xEE, 0x38, 0x6B, 0xFB, 0x5A, 0x89, 0x9F, 0xA5, 0xAE, 0x9F, 0x24, 0x11,
6090x7C, 0x4B, 0x1F, 0xE6, 0x49, 0x28, 0x66, 0x51, 0xEC, 0xE4, 0x5B, 0x3D,
6100xC2, 0x00, 0x7C, 0xB8, 0xA1, 0x63, 0xBF, 0x05, 0x98, 0xDA, 0x48, 0x36,
6110x1C, 0x55, 0xD3, 0x9A, 0x69, 0x16, 0x3F, 0xA8, 0xFD, 0x24, 0xCF, 0x5F,
6120x83, 0x65, 0x5D, 0x23, 0xDC, 0xA3, 0xAD, 0x96, 0x1C, 0x62, 0xF3, 0x56,
6130x20, 0x85, 0x52, 0xBB, 0x9E, 0xD5, 0x29, 0x07, 0x70, 0x96, 0x96, 0x6D,
6140x67, 0x0C, 0x35, 0x4E, 0x4A, 0xBC, 0x98, 0x04, 0xF1, 0x74, 0x6C, 0x08,
6150xCA, 0x18, 0x21, 0x7C, 0x32, 0x90, 0x5E, 0x46, 0x2E, 0x36, 0xCE, 0x3B,
6160xE3, 0x9E, 0x77, 0x2C, 0x18, 0x0E, 0x86, 0x03, 0x9B, 0x27, 0x83, 0xA2,
6170xEC, 0x07, 0xA2, 0x8F, 0xB5, 0xC5, 0x5D, 0xF0, 0x6F, 0x4C, 0x52, 0xC9,
6180xDE, 0x2B, 0xCB, 0xF6, 0x95, 0x58, 0x17, 0x18, 0x39, 0x95, 0x49, 0x7C,
6190xEA, 0x95, 0x6A, 0xE5, 0x15, 0xD2, 0x26, 0x18, 0x98, 0xFA, 0x05, 0x10,
6200x15, 0x72, 0x8E, 0x5A, 0x8A, 0xAA, 0xC4, 0x2D, 0xAD, 0x33, 0x17, 0x0D,
6210x04, 0x50, 0x7A, 0x33, 0xA8, 0x55, 0x21, 0xAB, 0xDF, 0x1C, 0xBA, 0x64,
6220xEC, 0xFB, 0x85, 0x04, 0x58, 0xDB, 0xEF, 0x0A, 0x8A, 0xEA, 0x71, 0x57,
6230x5D, 0x06, 0x0C, 0x7D, 0xB3, 0x97, 0x0F, 0x85, 0xA6, 0xE1, 0xE4, 0xC7,
6240xAB, 0xF5, 0xAE, 0x8C, 0xDB, 0x09, 0x33, 0xD7, 0x1E, 0x8C, 0x94, 0xE0,
6250x4A, 0x25, 0x61, 0x9D, 0xCE, 0xE3, 0xD2, 0x26, 0x1A, 0xD2, 0xEE, 0x6B,
6260xF1, 0x2F, 0xFA, 0x06, 0xD9, 0x8A, 0x08, 0x64, 0xD8, 0x76, 0x02, 0x73,
6270x3E, 0xC8, 0x6A, 0x64, 0x52, 0x1F, 0x2B, 0x18, 0x17, 0x7B, 0x20, 0x0C,
6280xBB, 0xE1, 0x17, 0x57, 0x7A, 0x61, 0x5D, 0x6C, 0x77, 0x09, 0x88, 0xC0,
6290xBA, 0xD9, 0x46, 0xE2, 0x08, 0xE2, 0x4F, 0xA0, 0x74, 0xE5, 0xAB, 0x31,
6300x43, 0xDB, 0x5B, 0xFC, 0xE0, 0xFD, 0x10, 0x8E, 0x4B, 0x82, 0xD1, 0x20,
6310xA9, 0x21, 0x08, 0x01, 0x1A, 0x72, 0x3C, 0x12, 0xA7, 0x87, 0xE6, 0xD7,
6320x88, 0x71, 0x9A, 0x10, 0xBD, 0xBA, 0x5B, 0x26, 0x99, 0xC3, 0x27, 0x18,
6330x6A, 0xF4, 0xE2, 0x3C, 0x1A, 0x94, 0x68, 0x34, 0xB6, 0x15, 0x0B, 0xDA,
6340x25, 0x83, 0xE9, 0xCA, 0x2A, 0xD4, 0x4C, 0xE8, 0xDB, 0xBB, 0xC2, 0xDB,
6350x04, 0xDE, 0x8E, 0xF9, 0x2E, 0x8E, 0xFC, 0x14, 0x1F, 0xBE, 0xCA, 0xA6,
6360x28, 0x7C, 0x59, 0x47, 0x4E, 0x6B, 0xC0, 0x5D, 0x99, 0xB2, 0x96, 0x4F,
6370xA0, 0x90, 0xC3, 0xA2, 0x23, 0x3B, 0xA1, 0x86, 0x51, 0x5B, 0xE7, 0xED,
6380x1F, 0x61, 0x29, 0x70, 0xCE, 0xE2, 0xD7, 0xAF, 0xB8, 0x1B, 0xDD, 0x76,
6390x21, 0x70, 0x48, 0x1C, 0xD0, 0x06, 0x91, 0x27, 0xD5, 0xB0, 0x5A, 0xA9,
6400x93, 0xB4, 0xEA, 0x98, 0x8D, 0x8F, 0xDD, 0xC1, 0x86, 0xFF, 0xB7, 0xDC,
6410x90, 0xA6, 0xC0, 0x8F, 0x4D, 0xF4, 0x35, 0xC9, 0x34, 0x06, 0x31, 0x99,
6420xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF
643};
644
645const gnutls_datum_t gnutls_srp_4096_group_generator = {
646 (void *) &srp3072_generator, sizeof (srp3072_generator)
647};
648
649const gnutls_datum_t gnutls_srp_4096_group_prime = {
650 (void *) srp_params_4096, sizeof (srp_params_4096)
651};
652
653/* Check if G and N are parameters from the SRP draft.
654 */
655static int
656check_g_n (const opaque * g, size_t n_g, const opaque * n, size_t n_n)
657{
658
659 if ((n_n == sizeof (srp_params_3072) &&
660 memcmp (srp_params_3072, n, n_n) == 0) ||
661 (n_n == sizeof (srp_params_4096) &&
662 memcmp (srp_params_4096, n, n_n) == 0))
663 {
664 if (n_g != 1 || g[0] != srp3072_generator)
665 {
666 return gnutls_assert_val(GNUTLS_E_RECEIVED_ILLEGAL_PARAMETER)gnutls_assert_val_int(-55, "srp.c", 666);
667 }
668 return 0;
669 }
670
671 if (n_g != 1 || g[0] != srp_generator)
672 {
673 gnutls_assert ()do { if (__builtin_expect((_gnutls_log_level >= 2), 0)) _gnutls_log
( 2, "ASSERT: %s:%d\n", "srp.c",673); } while(0);
;
674 return GNUTLS_E_RECEIVED_ILLEGAL_PARAMETER-55;
675 }
676
677 if (n_n == sizeof (srp_params_1024) &&
678 memcmp (srp_params_1024, n, n_n) == 0)
679 {
680 return 0;
681 }
682
683 if (n_n == sizeof (srp_params_1536) &&
684 memcmp (srp_params_1536, n, n_n) == 0)
685 {
686 return 0;
687 }
688
689 if (n_n == sizeof (srp_params_2048) &&
690 memcmp (srp_params_2048, n, n_n) == 0)
691 {
692 return 0;
693 }
694
695 gnutls_assert ()do { if (__builtin_expect((_gnutls_log_level >= 2), 0)) _gnutls_log
( 2, "ASSERT: %s:%d\n", "srp.c",695); } while(0);
;
696 return GNUTLS_E_RECEIVED_ILLEGAL_PARAMETER-55;
697}
698
699/* Check if N is a prime and G a generator of the
700 * group. This is check only done if N is big enough.
701 * Otherwise only the included parameters must be used.
702 */
703static int
704group_check_g_n (gnutls_session_t session, bigint_t g, bigint_t n)
705{
706 bigint_t q = NULL((void*)0), two = NULL((void*)0), w = NULL((void*)0);
707 int ret;
708
709 if (_gnutls_mpi_get_nbits (n)_gnutls_mpi_ops.bigint_get_nbits(n) < (session->internals.srp_prime_bits
710 ? session->internals.srp_prime_bits
711 : 2048))
712 {
713 gnutls_assert ()do { if (__builtin_expect((_gnutls_log_level >= 2), 0)) _gnutls_log
( 2, "ASSERT: %s:%d\n", "srp.c",713); } while(0);
;
714 return GNUTLS_E_RECEIVED_ILLEGAL_PARAMETER-55;
715 }
716
717 /* N must be of the form N=2q+1
718 * where q is also a prime.
719 */
720 if (_gnutls_prime_check (n)_gnutls_mpi_ops.bigint_prime_check(n) != 0)
721 {
722 _gnutls_mpi_log ("no prime N: ", n);
723 gnutls_assert ()do { if (__builtin_expect((_gnutls_log_level >= 2), 0)) _gnutls_log
( 2, "ASSERT: %s:%d\n", "srp.c",723); } while(0);
;
724 return GNUTLS_E_RECEIVED_ILLEGAL_PARAMETER-55;
725 }
726
727 two = _gnutls_mpi_new (4)_gnutls_mpi_ops.bigint_new(4);
728 if (two == NULL((void*)0))
729 {
730 gnutls_assert ()do { if (__builtin_expect((_gnutls_log_level >= 2), 0)) _gnutls_log
( 2, "ASSERT: %s:%d\n", "srp.c",730); } while(0);
;
731 return GNUTLS_E_MEMORY_ERROR-25;
732 }
733
734 q = _gnutls_mpi_alloc_like (n)_gnutls_mpi_ops.bigint_new(_gnutls_mpi_ops.bigint_get_nbits(n
))
;
735 if (q == NULL((void*)0))
736 {
737 gnutls_assert ()do { if (__builtin_expect((_gnutls_log_level >= 2), 0)) _gnutls_log
( 2, "ASSERT: %s:%d\n", "srp.c",737); } while(0);
;
738 ret = GNUTLS_E_MEMORY_ERROR-25;
739 goto error;
740 }
741
742 /* q = n-1
743 */
744 _gnutls_mpi_sub_ui (q, n, 1)_gnutls_mpi_ops.bigint_sub_ui(q,n,1);
745
746 /* q = q/2, remember that q is divisible by 2 (prime - 1)
747 */
748 _gnutls_mpi_set_ui (two, 2)_gnutls_mpi_ops.bigint_set_ui(two,2);
749 _gnutls_mpi_div (q, q, two)_gnutls_mpi_ops.bigint_div(q,q,two);
750
751 if (_gnutls_prime_check (q)_gnutls_mpi_ops.bigint_prime_check(q) != 0)
752 {
753 /* N was not on the form N=2q+1, where q = prime
754 */
755 _gnutls_mpi_log ("no prime Q: ", q);
756 gnutls_assert ()do { if (__builtin_expect((_gnutls_log_level >= 2), 0)) _gnutls_log
( 2, "ASSERT: %s:%d\n", "srp.c",756); } while(0);
;
757 return GNUTLS_E_RECEIVED_ILLEGAL_PARAMETER-55;
758 }
759
760 /* We also check whether g is a generator,
761 */
762
763 /* check if g < q < N
764 */
765 if (_gnutls_mpi_cmp (g, q)_gnutls_mpi_ops.bigint_cmp(g,q) >= 0)
766 {
767 gnutls_assert ()do { if (__builtin_expect((_gnutls_log_level >= 2), 0)) _gnutls_log
( 2, "ASSERT: %s:%d\n", "srp.c",767); } while(0);
;
768 ret = GNUTLS_E_RECEIVED_ILLEGAL_PARAMETER-55;
769 goto error;
770 }
771
772 w = _gnutls_mpi_alloc_like (q)_gnutls_mpi_ops.bigint_new(_gnutls_mpi_ops.bigint_get_nbits(q
))
;
773 if (w == NULL((void*)0))
774 {
775 gnutls_assert ()do { if (__builtin_expect((_gnutls_log_level >= 2), 0)) _gnutls_log
( 2, "ASSERT: %s:%d\n", "srp.c",775); } while(0);
;
776 ret = GNUTLS_E_MEMORY_ERROR-25;
777 goto error;
778 }
779
780 /* check if g^q mod N == N-1
781 * w = g^q mod N
782 */
783 _gnutls_mpi_powm (w, g, q, n)_gnutls_mpi_ops.bigint_powm(w,g,q,n);
784
785 /* w++
786 */
787 _gnutls_mpi_add_ui (w, w, 1)_gnutls_mpi_ops.bigint_add_ui(w,w,1);
788
789 if (_gnutls_mpi_cmp (w, n)_gnutls_mpi_ops.bigint_cmp(w,n) != 0)
790 {
791 gnutls_assert ()do { if (__builtin_expect((_gnutls_log_level >= 2), 0)) _gnutls_log
( 2, "ASSERT: %s:%d\n", "srp.c",791); } while(0);
;
792 ret = GNUTLS_E_RECEIVED_ILLEGAL_PARAMETER-55;
793 goto error;
794 }
795
796 ret = 0;
797
798error:
799 _gnutls_mpi_release (&q);
800 _gnutls_mpi_release (&two);
801 _gnutls_mpi_release (&w);
802
803 return ret;
804
805}
806
807/* receive the key exchange message ( n, g, s, B)
808 */
809int
810_gnutls_proc_srp_server_kx (gnutls_session_t session, opaque * data,
811 size_t _data_size)
812{
813 uint8_t n_s;
814 uint16_t n_g, n_n, n_b;
815 size_t _n_g, _n_n, _n_b;
816 const uint8_t *data_n;
817 const uint8_t *data_g;
818 const uint8_t *data_s;
819 const uint8_t *data_b;
820 int i, ret;
821 opaque hd[SRP_MAX_HASH_SIZE24];
822 char *username, *password;
823 ssize_t data_size = _data_size;
824 gnutls_srp_client_credentials_t cred;
825 extension_priv_data_t epriv;
826 srp_ext_st *priv;
827
828 ret = _gnutls_ext_get_session_data (session, GNUTLS_EXTENSION_SRP, &epriv);
829 if (ret < 0)
830 {
831 gnutls_assert ()do { if (__builtin_expect((_gnutls_log_level >= 2), 0)) _gnutls_log
( 2, "ASSERT: %s:%d\n", "srp.c",831); } while(0);
;
832 return GNUTLS_E_UNKNOWN_SRP_USERNAME-109;
833 }
834 priv = epriv.ptr;
835
836 cred = (gnutls_srp_client_credentials_t)
837 _gnutls_get_cred (session->key, GNUTLS_CRD_SRP, NULL((void*)0));
838
839 if (cred == NULL((void*)0))
840 {
841 gnutls_assert ()do { if (__builtin_expect((_gnutls_log_level >= 2), 0)) _gnutls_log
( 2, "ASSERT: %s:%d\n", "srp.c",841); } while(0);
;
842 return GNUTLS_E_INSUFFICIENT_CREDENTIALS-32;
843 }
844
845 if (priv->username == NULL((void*)0))
846 {
847 username = cred->username;
848 password = cred->password;
849 }
850 else
851 {
852 username = priv->username;
853 password = priv->password;
854 }
855
856 if (username == NULL((void*)0) || password == NULL((void*)0))
857 {
858 gnutls_assert ()do { if (__builtin_expect((_gnutls_log_level >= 2), 0)) _gnutls_log
( 2, "ASSERT: %s:%d\n", "srp.c",858); } while(0);
;
859 return GNUTLS_E_INSUFFICIENT_CREDENTIALS-32;
860 }
861
862 i = 0;
863
864 /* Read N
865 */
866 DECR_LEN (data_size, 2)do { data_size-=2; if (data_size<0) {do { if (__builtin_expect
((_gnutls_log_level >= 2), 0)) _gnutls_log( 2, "ASSERT: %s:%d\n"
, "srp.c",866); } while(0);; return -9;} } while (0)
;
867 n_n = _gnutls_read_uint16 (&data[i]);
868 i += 2;
869
870 DECR_LEN (data_size, n_n)do { data_size-=n_n; if (data_size<0) {do { if (__builtin_expect
((_gnutls_log_level >= 2), 0)) _gnutls_log( 2, "ASSERT: %s:%d\n"
, "srp.c",870); } while(0);; return -9;} } while (0)
;
871 data_n = &data[i];
872 i += n_n;
873
874 /* Read G
875 */
876 DECR_LEN (data_size, 2)do { data_size-=2; if (data_size<0) {do { if (__builtin_expect
((_gnutls_log_level >= 2), 0)) _gnutls_log( 2, "ASSERT: %s:%d\n"
, "srp.c",876); } while(0);; return -9;} } while (0)
;
877 n_g = _gnutls_read_uint16 (&data[i]);
878 i += 2;
879
880 DECR_LEN (data_size, n_g)do { data_size-=n_g; if (data_size<0) {do { if (__builtin_expect
((_gnutls_log_level >= 2), 0)) _gnutls_log( 2, "ASSERT: %s:%d\n"
, "srp.c",880); } while(0);; return -9;} } while (0)
;
881 data_g = &data[i];
882 i += n_g;
883
884 /* Read salt
885 */
886 DECR_LEN (data_size, 1)do { data_size-=1; if (data_size<0) {do { if (__builtin_expect
((_gnutls_log_level >= 2), 0)) _gnutls_log( 2, "ASSERT: %s:%d\n"
, "srp.c",886); } while(0);; return -9;} } while (0)
;
887 n_s = data[i];
888 i += 1;
889
890 DECR_LEN (data_size, n_s)do { data_size-=n_s; if (data_size<0) {do { if (__builtin_expect
((_gnutls_log_level >= 2), 0)) _gnutls_log( 2, "ASSERT: %s:%d\n"
, "srp.c",890); } while(0);; return -9;} } while (0)
;
891 data_s = &data[i];
892 i += n_s;
893
894 /* Read B
895 */
896 DECR_LEN (data_size, 2)do { data_size-=2; if (data_size<0) {do { if (__builtin_expect
((_gnutls_log_level >= 2), 0)) _gnutls_log( 2, "ASSERT: %s:%d\n"
, "srp.c",896); } while(0);; return -9;} } while (0)
;
897 n_b = _gnutls_read_uint16 (&data[i]);
898 i += 2;
899
900 DECR_LEN (data_size, n_b)do { data_size-=n_b; if (data_size<0) {do { if (__builtin_expect
((_gnutls_log_level >= 2), 0)) _gnutls_log( 2, "ASSERT: %s:%d\n"
, "srp.c",900); } while(0);; return -9;} } while (0)
;
901 data_b = &data[i];
902 i += n_b;
903
904 _n_g = n_g;
905 _n_n = n_n;
906 _n_b = n_b;
907
908 if (_gnutls_mpi_scan_nz (&Nsession->key->client_p, data_n, _n_n) != 0)
909 {
910 gnutls_assert ()do { if (__builtin_expect((_gnutls_log_level >= 2), 0)) _gnutls_log
( 2, "ASSERT: %s:%d\n", "srp.c",910); } while(0);
;
911 return GNUTLS_E_MPI_SCAN_FAILED-23;
912 }
913
914 if (_gnutls_mpi_scan_nz (&Gsession->key->client_g, data_g, _n_g) != 0)
915 {
916 gnutls_assert ()do { if (__builtin_expect((_gnutls_log_level >= 2), 0)) _gnutls_log
( 2, "ASSERT: %s:%d\n", "srp.c",916); } while(0);
;
917 return GNUTLS_E_MPI_SCAN_FAILED-23;
918 }
919
920 if (_gnutls_mpi_scan_nz (&Bsession->key->B, data_b, _n_b) != 0)
921 {
922 gnutls_assert ()do { if (__builtin_expect((_gnutls_log_level >= 2), 0)) _gnutls_log
( 2, "ASSERT: %s:%d\n", "srp.c",922); } while(0);
;
923 return GNUTLS_E_MPI_SCAN_FAILED-23;
924 }
925
926
927 /* Check if the g and n are from the SRP
928 * draft. Otherwise check if N is a prime and G
929 * a generator.
930 */
931 if ((ret = check_g_n (data_g, _n_g, data_n, _n_n)) < 0)
Although the value stored to 'ret' is used in the enclosing expression, the value is never actually read from 'ret'
932 {
933 _gnutls_audit_log (session, "SRP group parameters are not in the white list. Checking validity.\n");
934 if ((ret = group_check_g_n (session, Gsession->key->client_g, Nsession->key->client_p)) < 0)
935 {
936 gnutls_assert ()do { if (__builtin_expect((_gnutls_log_level >= 2), 0)) _gnutls_log
( 2, "ASSERT: %s:%d\n", "srp.c",936); } while(0);
;
937 return ret;
938 }
939 }
940
941 /* Checks if b % n == 0
942 */
943 if ((ret = check_b_mod_n (Bsession->key->B, Nsession->key->client_p)) < 0)
944 {
945 gnutls_assert ()do { if (__builtin_expect((_gnutls_log_level >= 2), 0)) _gnutls_log
( 2, "ASSERT: %s:%d\n", "srp.c",945); } while(0);
;
946 return ret;
947 }
948
949
950 /* generate x = SHA(s | SHA(U | ":" | p))
951 * (or the equivalent using bcrypt)
952 */
953 if ((ret =
954 _gnutls_calc_srp_x (username, password, (opaque *) data_s, n_s,
955 &_n_g, hd)) < 0)
956 {
957 gnutls_assert ()do { if (__builtin_expect((_gnutls_log_level >= 2), 0)) _gnutls_log
( 2, "ASSERT: %s:%d\n", "srp.c",957); } while(0);
;
958 return ret;
959 }
960
961 if (_gnutls_mpi_scan_nz (&session->key->x, hd, _n_g) != 0)
962 {
963 gnutls_assert ()do { if (__builtin_expect((_gnutls_log_level >= 2), 0)) _gnutls_log
( 2, "ASSERT: %s:%d\n", "srp.c",963); } while(0);
;
964 return GNUTLS_E_MPI_SCAN_FAILED-23;
965 }
966
967
968 return i; /* return the processed data
969 * needed in auth_srp_rsa.
970 */
971}
972
973#endif /* ENABLE_SRP */