srp_vfy.c 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660
  1. /* crypto/srp/srp_vfy.c */
  2. /* Written by Christophe Renou (christophe.renou@edelweb.fr) with
  3. * the precious help of Peter Sylvester (peter.sylvester@edelweb.fr)
  4. * for the EdelKey project and contributed to the OpenSSL project 2004.
  5. */
  6. /* ====================================================================
  7. * Copyright (c) 2004 The OpenSSL Project. All rights reserved.
  8. *
  9. * Redistribution and use in source and binary forms, with or without
  10. * modification, are permitted provided that the following conditions
  11. * are met:
  12. *
  13. * 1. Redistributions of source code must retain the above copyright
  14. * notice, this list of conditions and the following disclaimer.
  15. *
  16. * 2. Redistributions in binary form must reproduce the above copyright
  17. * notice, this list of conditions and the following disclaimer in
  18. * the documentation and/or other materials provided with the
  19. * distribution.
  20. *
  21. * 3. All advertising materials mentioning features or use of this
  22. * software must display the following acknowledgment:
  23. * "This product includes software developed by the OpenSSL Project
  24. * for use in the OpenSSL Toolkit. (http://www.OpenSSL.org/)"
  25. *
  26. * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
  27. * endorse or promote products derived from this software without
  28. * prior written permission. For written permission, please contact
  29. * licensing@OpenSSL.org.
  30. *
  31. * 5. Products derived from this software may not be called "OpenSSL"
  32. * nor may "OpenSSL" appear in their names without prior written
  33. * permission of the OpenSSL Project.
  34. *
  35. * 6. Redistributions of any form whatsoever must retain the following
  36. * acknowledgment:
  37. * "This product includes software developed by the OpenSSL Project
  38. * for use in the OpenSSL Toolkit (http://www.OpenSSL.org/)"
  39. *
  40. * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
  41. * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  42. * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
  43. * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR
  44. * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
  45. * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
  46. * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
  47. * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
  48. * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
  49. * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
  50. * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
  51. * OF THE POSSIBILITY OF SUCH DAMAGE.
  52. * ====================================================================
  53. *
  54. * This product includes cryptographic software written by Eric Young
  55. * (eay@cryptsoft.com). This product includes software written by Tim
  56. * Hudson (tjh@cryptsoft.com).
  57. *
  58. */
  59. #ifndef OPENSSL_NO_SRP
  60. #include "cryptlib.h"
  61. #include "srp_lcl.h"
  62. #include <openssl/srp.h>
  63. #include <openssl/evp.h>
  64. #include <openssl/buffer.h>
  65. #include <openssl/rand.h>
  66. #include <openssl/txt_db.h>
  67. #define SRP_RANDOM_SALT_LEN 20
  68. #define MAX_LEN 2500
  69. static char b64table[] =
  70. "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz./";
  71. /* the following two conversion routines have been inspired by code from Stanford */
  72. /*
  73. * Convert a base64 string into raw byte array representation.
  74. */
  75. static int t_fromb64(unsigned char *a, const char *src)
  76. {
  77. char *loc;
  78. int i, j;
  79. int size;
  80. while(*src && (*src == ' ' || *src == '\t' || *src == '\n'))
  81. ++src;
  82. size = strlen((const char *)src);
  83. i = 0;
  84. while(i < size)
  85. {
  86. loc = strchr(b64table, src[i]);
  87. if(loc == (char *) 0) break;
  88. else a[i] = loc - b64table;
  89. ++i;
  90. }
  91. size = i;
  92. i = size - 1;
  93. j = size;
  94. while(1)
  95. {
  96. a[j] = a[i];
  97. if(--i < 0) break;
  98. a[j] |= (a[i] & 3) << 6;
  99. --j;
  100. a[j] = (unsigned char) ((a[i] & 0x3c) >> 2);
  101. if(--i < 0) break;
  102. a[j] |= (a[i] & 0xf) << 4;
  103. --j;
  104. a[j] = (unsigned char) ((a[i] & 0x30) >> 4);
  105. if(--i < 0) break;
  106. a[j] |= (a[i] << 2);
  107. a[--j] = 0;
  108. if(--i < 0) break;
  109. }
  110. while(a[j] == 0 && j <= size) ++j;
  111. i = 0;
  112. while (j <= size) a[i++] = a[j++];
  113. return i;
  114. }
  115. /*
  116. * Convert a raw byte string into a null-terminated base64 ASCII string.
  117. */
  118. static char *t_tob64(char *dst, const unsigned char *src, int size)
  119. {
  120. int c, pos = size % 3;
  121. unsigned char b0 = 0, b1 = 0, b2 = 0, notleading = 0;
  122. char *olddst = dst;
  123. switch(pos)
  124. {
  125. case 1:
  126. b2 = src[0];
  127. break;
  128. case 2:
  129. b1 = src[0];
  130. b2 = src[1];
  131. break;
  132. }
  133. while(1)
  134. {
  135. c = (b0 & 0xfc) >> 2;
  136. if(notleading || c != 0)
  137. {
  138. *dst++ = b64table[c];
  139. notleading = 1;
  140. }
  141. c = ((b0 & 3) << 4) | ((b1 & 0xf0) >> 4);
  142. if(notleading || c != 0)
  143. {
  144. *dst++ = b64table[c];
  145. notleading = 1;
  146. }
  147. c = ((b1 & 0xf) << 2) | ((b2 & 0xc0) >> 6);
  148. if(notleading || c != 0)
  149. {
  150. *dst++ = b64table[c];
  151. notleading = 1;
  152. }
  153. c = b2 & 0x3f;
  154. if(notleading || c != 0)
  155. {
  156. *dst++ = b64table[c];
  157. notleading = 1;
  158. }
  159. if(pos >= size) break;
  160. else
  161. {
  162. b0 = src[pos++];
  163. b1 = src[pos++];
  164. b2 = src[pos++];
  165. }
  166. }
  167. *dst++ = '\0';
  168. return olddst;
  169. }
  170. static void SRP_user_pwd_free(SRP_user_pwd *user_pwd)
  171. {
  172. if (user_pwd == NULL)
  173. return;
  174. BN_free(user_pwd->s);
  175. BN_clear_free(user_pwd->v);
  176. OPENSSL_free(user_pwd->id);
  177. OPENSSL_free(user_pwd->info);
  178. OPENSSL_free(user_pwd);
  179. }
  180. static SRP_user_pwd * SRP_user_pwd_new(void)
  181. {
  182. SRP_user_pwd * ret = OPENSSL_malloc(sizeof(SRP_user_pwd));
  183. if (ret == NULL)
  184. return NULL;
  185. ret->N = NULL;
  186. ret->g = NULL;
  187. ret->s = NULL;
  188. ret->v = NULL;
  189. ret->id = NULL ;
  190. ret->info = NULL;
  191. return ret;
  192. }
  193. static void SRP_user_pwd_set_gN(SRP_user_pwd *vinfo, const BIGNUM *g,
  194. const BIGNUM *N)
  195. {
  196. vinfo->N = N;
  197. vinfo->g = g;
  198. }
  199. static int SRP_user_pwd_set_ids(SRP_user_pwd *vinfo, const char *id,
  200. const char *info)
  201. {
  202. if (id != NULL && NULL == (vinfo->id = BUF_strdup(id)))
  203. return 0;
  204. return (info == NULL || NULL != (vinfo->info = BUF_strdup(info))) ;
  205. }
  206. static int SRP_user_pwd_set_sv(SRP_user_pwd *vinfo, const char *s,
  207. const char *v)
  208. {
  209. unsigned char tmp[MAX_LEN];
  210. int len;
  211. if (strlen(s) > MAX_LEN || strlen(v) > MAX_LEN)
  212. return 0;
  213. len = t_fromb64(tmp, v);
  214. if (NULL == (vinfo->v = BN_bin2bn(tmp, len, NULL)) )
  215. return 0;
  216. len = t_fromb64(tmp, s);
  217. return ((vinfo->s = BN_bin2bn(tmp, len, NULL)) != NULL) ;
  218. }
  219. static int SRP_user_pwd_set_sv_BN(SRP_user_pwd * vinfo, BIGNUM * s, BIGNUM * v)
  220. {
  221. vinfo->v = v;
  222. vinfo->s = s;
  223. return (vinfo->s != NULL && vinfo->v != NULL) ;
  224. }
  225. SRP_VBASE *SRP_VBASE_new(char *seed_key)
  226. {
  227. SRP_VBASE *vb = (SRP_VBASE *) OPENSSL_malloc(sizeof(SRP_VBASE));
  228. if (vb == NULL)
  229. return NULL;
  230. if (!(vb->users_pwd = sk_SRP_user_pwd_new_null()) ||
  231. !(vb->gN_cache = sk_SRP_gN_cache_new_null()))
  232. {
  233. OPENSSL_free(vb);
  234. return NULL;
  235. }
  236. vb->default_g = NULL;
  237. vb->default_N = NULL;
  238. vb->seed_key = NULL;
  239. if ((seed_key != NULL) &&
  240. (vb->seed_key = BUF_strdup(seed_key)) == NULL)
  241. {
  242. sk_SRP_user_pwd_free(vb->users_pwd);
  243. sk_SRP_gN_cache_free(vb->gN_cache);
  244. OPENSSL_free(vb);
  245. return NULL;
  246. }
  247. return vb;
  248. }
  249. int SRP_VBASE_free(SRP_VBASE *vb)
  250. {
  251. sk_SRP_user_pwd_pop_free(vb->users_pwd,SRP_user_pwd_free);
  252. sk_SRP_gN_cache_free(vb->gN_cache);
  253. OPENSSL_free(vb->seed_key);
  254. OPENSSL_free(vb);
  255. return 0;
  256. }
  257. static SRP_gN_cache *SRP_gN_new_init(const char *ch)
  258. {
  259. unsigned char tmp[MAX_LEN];
  260. int len;
  261. SRP_gN_cache *newgN = (SRP_gN_cache *)OPENSSL_malloc(sizeof(SRP_gN_cache));
  262. if (newgN == NULL)
  263. return NULL;
  264. if ((newgN->b64_bn = BUF_strdup(ch)) == NULL)
  265. goto err;
  266. len = t_fromb64(tmp, ch);
  267. if ((newgN->bn = BN_bin2bn(tmp, len, NULL)))
  268. return newgN;
  269. OPENSSL_free(newgN->b64_bn);
  270. err:
  271. OPENSSL_free(newgN);
  272. return NULL;
  273. }
  274. static void SRP_gN_free(SRP_gN_cache *gN_cache)
  275. {
  276. if (gN_cache == NULL)
  277. return;
  278. OPENSSL_free(gN_cache->b64_bn);
  279. BN_free(gN_cache->bn);
  280. OPENSSL_free(gN_cache);
  281. }
  282. static SRP_gN *SRP_get_gN_by_id(const char *id, STACK_OF(SRP_gN) *gN_tab)
  283. {
  284. int i;
  285. SRP_gN *gN;
  286. if (gN_tab != NULL)
  287. for(i = 0; i < sk_SRP_gN_num(gN_tab); i++)
  288. {
  289. gN = sk_SRP_gN_value(gN_tab, i);
  290. if (gN && (id == NULL || strcmp(gN->id,id)==0))
  291. return gN;
  292. }
  293. return SRP_get_default_gN(id);
  294. }
  295. static BIGNUM *SRP_gN_place_bn(STACK_OF(SRP_gN_cache) *gN_cache, char *ch)
  296. {
  297. int i;
  298. if (gN_cache == NULL)
  299. return NULL;
  300. /* search if we have already one... */
  301. for(i = 0; i < sk_SRP_gN_cache_num(gN_cache); i++)
  302. {
  303. SRP_gN_cache *cache = sk_SRP_gN_cache_value(gN_cache, i);
  304. if (strcmp(cache->b64_bn,ch)==0)
  305. return cache->bn;
  306. }
  307. { /* it is the first time that we find it */
  308. SRP_gN_cache *newgN = SRP_gN_new_init(ch);
  309. if (newgN)
  310. {
  311. if (sk_SRP_gN_cache_insert(gN_cache,newgN,0)>0)
  312. return newgN->bn;
  313. SRP_gN_free(newgN);
  314. }
  315. }
  316. return NULL;
  317. }
  318. /* this function parses verifier file. Format is:
  319. * string(index):base64(N):base64(g):0
  320. * string(username):base64(v):base64(salt):int(index)
  321. */
  322. int SRP_VBASE_init(SRP_VBASE *vb, char *verifier_file)
  323. {
  324. int error_code ;
  325. STACK_OF(SRP_gN) *SRP_gN_tab = sk_SRP_gN_new_null();
  326. char *last_index = NULL;
  327. int i;
  328. char **pp;
  329. SRP_gN *gN = NULL;
  330. SRP_user_pwd *user_pwd = NULL ;
  331. TXT_DB *tmpdb = NULL;
  332. BIO *in = BIO_new(BIO_s_file());
  333. error_code = SRP_ERR_OPEN_FILE;
  334. if (in == NULL || BIO_read_filename(in,verifier_file) <= 0)
  335. goto err;
  336. error_code = SRP_ERR_VBASE_INCOMPLETE_FILE;
  337. if ((tmpdb =TXT_DB_read(in,DB_NUMBER)) == NULL)
  338. goto err;
  339. error_code = SRP_ERR_MEMORY;
  340. if (vb->seed_key)
  341. {
  342. last_index = SRP_get_default_gN(NULL)->id;
  343. }
  344. for (i=0; i < sk_OPENSSL_PSTRING_num(tmpdb->data); i++)
  345. {
  346. pp=sk_OPENSSL_PSTRING_value(tmpdb->data,i);
  347. if (pp[DB_srptype][0] == DB_SRP_INDEX)
  348. {
  349. /*we add this couple in the internal Stack */
  350. if ((gN = (SRP_gN *)OPENSSL_malloc(sizeof(SRP_gN))) == NULL)
  351. goto err;
  352. if (!(gN->id = BUF_strdup(pp[DB_srpid]))
  353. || !(gN->N = SRP_gN_place_bn(vb->gN_cache,pp[DB_srpverifier]))
  354. || !(gN->g = SRP_gN_place_bn(vb->gN_cache,pp[DB_srpsalt]))
  355. || sk_SRP_gN_insert(SRP_gN_tab,gN,0) == 0)
  356. goto err;
  357. gN = NULL;
  358. if (vb->seed_key != NULL)
  359. {
  360. last_index = pp[DB_srpid];
  361. }
  362. }
  363. else if (pp[DB_srptype][0] == DB_SRP_VALID)
  364. {
  365. /* it is a user .... */
  366. SRP_gN *lgN;
  367. if ((lgN = SRP_get_gN_by_id(pp[DB_srpgN],SRP_gN_tab))!=NULL)
  368. {
  369. error_code = SRP_ERR_MEMORY;
  370. if ((user_pwd = SRP_user_pwd_new()) == NULL)
  371. goto err;
  372. SRP_user_pwd_set_gN(user_pwd,lgN->g,lgN->N);
  373. if (!SRP_user_pwd_set_ids(user_pwd, pp[DB_srpid],
  374. pp[DB_srpinfo]))
  375. goto err;
  376. error_code = SRP_ERR_VBASE_BN_LIB;
  377. if (!SRP_user_pwd_set_sv(user_pwd, pp[DB_srpsalt],
  378. pp[DB_srpverifier]))
  379. goto err;
  380. if (sk_SRP_user_pwd_insert(vb->users_pwd,user_pwd,0) == 0)
  381. goto err;
  382. user_pwd = NULL; /* abandon responsability */
  383. }
  384. }
  385. }
  386. if (last_index != NULL)
  387. {
  388. /* this means that we want to simulate a default user */
  389. if (((gN = SRP_get_gN_by_id(last_index,SRP_gN_tab))==NULL))
  390. {
  391. error_code = SRP_ERR_VBASE_BN_LIB;
  392. goto err;
  393. }
  394. vb->default_g = gN->g ;
  395. vb->default_N = gN->N ;
  396. gN = NULL ;
  397. }
  398. error_code = SRP_NO_ERROR;
  399. err:
  400. /* there may be still some leaks to fix, if this fails, the application terminates most likely */
  401. if (gN != NULL)
  402. {
  403. OPENSSL_free(gN->id);
  404. OPENSSL_free(gN);
  405. }
  406. SRP_user_pwd_free(user_pwd);
  407. if (tmpdb) TXT_DB_free(tmpdb);
  408. if (in) BIO_free_all(in);
  409. sk_SRP_gN_free(SRP_gN_tab);
  410. return error_code;
  411. }
  412. SRP_user_pwd *SRP_VBASE_get_by_user(SRP_VBASE *vb, char *username)
  413. {
  414. int i;
  415. SRP_user_pwd *user;
  416. unsigned char digv[SHA_DIGEST_LENGTH];
  417. unsigned char digs[SHA_DIGEST_LENGTH];
  418. EVP_MD_CTX ctxt;
  419. if (vb == NULL)
  420. return NULL;
  421. for(i = 0; i < sk_SRP_user_pwd_num(vb->users_pwd); i++)
  422. {
  423. user = sk_SRP_user_pwd_value(vb->users_pwd, i);
  424. if (strcmp(user->id,username)==0)
  425. return user;
  426. }
  427. if ((vb->seed_key == NULL) ||
  428. (vb->default_g == NULL) ||
  429. (vb->default_N == NULL))
  430. return NULL;
  431. /* if the user is unknown we set parameters as well if we have a seed_key */
  432. if ((user = SRP_user_pwd_new()) == NULL)
  433. return NULL;
  434. SRP_user_pwd_set_gN(user,vb->default_g,vb->default_N);
  435. if (!SRP_user_pwd_set_ids(user,username,NULL))
  436. goto err;
  437. RAND_pseudo_bytes(digv, SHA_DIGEST_LENGTH);
  438. EVP_MD_CTX_init(&ctxt);
  439. EVP_DigestInit_ex(&ctxt, EVP_sha1(), NULL);
  440. EVP_DigestUpdate(&ctxt, vb->seed_key, strlen(vb->seed_key));
  441. EVP_DigestUpdate(&ctxt, username, strlen(username));
  442. EVP_DigestFinal_ex(&ctxt, digs, NULL);
  443. EVP_MD_CTX_cleanup(&ctxt);
  444. if (SRP_user_pwd_set_sv_BN(user, BN_bin2bn(digs,SHA_DIGEST_LENGTH,NULL), BN_bin2bn(digv,SHA_DIGEST_LENGTH, NULL)))
  445. return user;
  446. err: SRP_user_pwd_free(user);
  447. return NULL;
  448. }
  449. /*
  450. create a verifier (*salt,*verifier,g and N are in base64)
  451. */
  452. char *SRP_create_verifier(const char *user, const char *pass, char **salt,
  453. char **verifier, const char *N, const char *g)
  454. {
  455. int len;
  456. char * result=NULL;
  457. char *vf;
  458. BIGNUM *N_bn = NULL, *g_bn = NULL, *s = NULL, *v = NULL;
  459. unsigned char tmp[MAX_LEN];
  460. unsigned char tmp2[MAX_LEN];
  461. char * defgNid = NULL;
  462. if ((user == NULL)||
  463. (pass == NULL)||
  464. (salt == NULL)||
  465. (verifier == NULL))
  466. goto err;
  467. if (N)
  468. {
  469. if (!(len = t_fromb64(tmp, N))) goto err;
  470. N_bn = BN_bin2bn(tmp,len,NULL);
  471. if (!(len = t_fromb64(tmp, g))) goto err;
  472. g_bn = BN_bin2bn(tmp, len, NULL);
  473. defgNid = "*";
  474. }
  475. else
  476. {
  477. SRP_gN * gN = SRP_get_gN_by_id(g, NULL) ;
  478. if (gN == NULL)
  479. goto err;
  480. N_bn = gN->N;
  481. g_bn = gN->g;
  482. defgNid = gN->id;
  483. }
  484. if (*salt == NULL)
  485. {
  486. RAND_pseudo_bytes(tmp2, SRP_RANDOM_SALT_LEN);
  487. s = BN_bin2bn(tmp2, SRP_RANDOM_SALT_LEN, NULL);
  488. }
  489. else
  490. {
  491. if (!(len = t_fromb64(tmp2, *salt)))
  492. goto err;
  493. s = BN_bin2bn(tmp2,len,NULL);
  494. }
  495. if(!SRP_create_verifier_BN(user, pass, &s, &v, N_bn, g_bn)) goto err;
  496. BN_bn2bin(v,tmp);
  497. if (((vf = OPENSSL_malloc(BN_num_bytes(v)*2)) == NULL))
  498. goto err;
  499. t_tob64(vf, tmp, BN_num_bytes(v));
  500. *verifier = vf;
  501. if (*salt == NULL)
  502. {
  503. char *tmp_salt;
  504. if ((tmp_salt = OPENSSL_malloc(SRP_RANDOM_SALT_LEN*2)) == NULL)
  505. {
  506. OPENSSL_free(vf);
  507. goto err;
  508. }
  509. t_tob64(tmp_salt,tmp2,SRP_RANDOM_SALT_LEN);
  510. *salt = tmp_salt;
  511. }
  512. result=defgNid;
  513. err:
  514. if(N)
  515. {
  516. BN_free(N_bn);
  517. BN_free(g_bn);
  518. }
  519. return result;
  520. }
  521. /*
  522. create a verifier (*salt,*verifier,g and N are BIGNUMs)
  523. */
  524. int SRP_create_verifier_BN(const char *user, const char *pass, BIGNUM **salt, BIGNUM **verifier, BIGNUM *N, BIGNUM *g)
  525. {
  526. int result=0;
  527. BIGNUM *x = NULL;
  528. BN_CTX *bn_ctx = BN_CTX_new();
  529. unsigned char tmp2[MAX_LEN];
  530. if ((user == NULL)||
  531. (pass == NULL)||
  532. (salt == NULL)||
  533. (verifier == NULL)||
  534. (N == NULL)||
  535. (g == NULL)||
  536. (bn_ctx == NULL))
  537. goto err;
  538. srp_bn_print(N);
  539. srp_bn_print(g);
  540. if (*salt == NULL)
  541. {
  542. RAND_pseudo_bytes(tmp2, SRP_RANDOM_SALT_LEN);
  543. *salt = BN_bin2bn(tmp2,SRP_RANDOM_SALT_LEN,NULL);
  544. }
  545. x = SRP_Calc_x(*salt,user,pass);
  546. *verifier = BN_new();
  547. if(*verifier == NULL) goto err;
  548. if (!BN_mod_exp(*verifier,g,x,N,bn_ctx))
  549. {
  550. BN_clear_free(*verifier);
  551. goto err;
  552. }
  553. srp_bn_print(*verifier);
  554. result=1;
  555. err:
  556. BN_clear_free(x);
  557. BN_CTX_free(bn_ctx);
  558. return result;
  559. }
  560. #endif