16f9291ceSJung-uk Kim /*
288e852c0SJung-uk Kim * Copyright 2004-2021 The OpenSSL Project Authors. All Rights Reserved.
3e71b7053SJung-uk Kim * Copyright (c) 2004, EdelKey Project. All Rights Reserved.
4e71b7053SJung-uk Kim *
5*b077aed3SPierre Pronchery * Licensed under the Apache License 2.0 (the "License"). You may not use
6e71b7053SJung-uk Kim * this file except in compliance with the License. You can obtain a copy
7e71b7053SJung-uk Kim * in the file LICENSE in the source distribution or at
8e71b7053SJung-uk Kim * https://www.openssl.org/source/license.html
9e71b7053SJung-uk Kim *
10e71b7053SJung-uk Kim * Originally written by Christophe Renou and Peter Sylvester,
11e71b7053SJung-uk Kim * for the EdelKey project.
121f13597dSJung-uk Kim */
13e71b7053SJung-uk Kim
14*b077aed3SPierre Pronchery /* All the SRP APIs in this file are deprecated */
15*b077aed3SPierre Pronchery #define OPENSSL_SUPPRESS_DEPRECATED
16*b077aed3SPierre Pronchery
171f13597dSJung-uk Kim #ifndef OPENSSL_NO_SRP
18e71b7053SJung-uk Kim # include "internal/cryptlib.h"
19e71b7053SJung-uk Kim # include <openssl/sha.h>
201f13597dSJung-uk Kim # include <openssl/srp.h>
211f13597dSJung-uk Kim # include <openssl/evp.h>
2217f01e99SJung-uk Kim # include "crypto/bn_srp.h"
231f13597dSJung-uk Kim
24e71b7053SJung-uk Kim /* calculate = SHA1(PAD(x) || PAD(y)) */
251f13597dSJung-uk Kim
srp_Calc_xy(const BIGNUM * x,const BIGNUM * y,const BIGNUM * N,OSSL_LIB_CTX * libctx,const char * propq)26*b077aed3SPierre Pronchery static BIGNUM *srp_Calc_xy(const BIGNUM *x, const BIGNUM *y, const BIGNUM *N,
27*b077aed3SPierre Pronchery OSSL_LIB_CTX *libctx, const char *propq)
28e71b7053SJung-uk Kim {
29e71b7053SJung-uk Kim unsigned char digest[SHA_DIGEST_LENGTH];
30e71b7053SJung-uk Kim unsigned char *tmp = NULL;
31e71b7053SJung-uk Kim int numN = BN_num_bytes(N);
32e71b7053SJung-uk Kim BIGNUM *res = NULL;
33*b077aed3SPierre Pronchery EVP_MD *sha1 = EVP_MD_fetch(libctx, "SHA1", propq);
34*b077aed3SPierre Pronchery
35*b077aed3SPierre Pronchery if (sha1 == NULL)
36*b077aed3SPierre Pronchery return NULL;
376935a639SJung-uk Kim
38e71b7053SJung-uk Kim if (x != N && BN_ucmp(x, N) >= 0)
39*b077aed3SPierre Pronchery goto err;
40e71b7053SJung-uk Kim if (y != N && BN_ucmp(y, N) >= 0)
41*b077aed3SPierre Pronchery goto err;
42e71b7053SJung-uk Kim if ((tmp = OPENSSL_malloc(numN * 2)) == NULL)
43e71b7053SJung-uk Kim goto err;
44e71b7053SJung-uk Kim if (BN_bn2binpad(x, tmp, numN) < 0
45e71b7053SJung-uk Kim || BN_bn2binpad(y, tmp + numN, numN) < 0
46*b077aed3SPierre Pronchery || !EVP_Digest(tmp, numN * 2, digest, NULL, sha1, NULL))
47e71b7053SJung-uk Kim goto err;
48e71b7053SJung-uk Kim res = BN_bin2bn(digest, sizeof(digest), NULL);
49e71b7053SJung-uk Kim err:
50*b077aed3SPierre Pronchery EVP_MD_free(sha1);
51e71b7053SJung-uk Kim OPENSSL_free(tmp);
52e71b7053SJung-uk Kim return res;
53e71b7053SJung-uk Kim }
541f13597dSJung-uk Kim
srp_Calc_k(const BIGNUM * N,const BIGNUM * g,OSSL_LIB_CTX * libctx,const char * propq)55*b077aed3SPierre Pronchery static BIGNUM *srp_Calc_k(const BIGNUM *N, const BIGNUM *g,
56*b077aed3SPierre Pronchery OSSL_LIB_CTX *libctx,
57*b077aed3SPierre Pronchery const char *propq)
581f13597dSJung-uk Kim {
59*b077aed3SPierre Pronchery /* k = SHA1(N | PAD(g)) -- tls-srp RFC 5054 */
60*b077aed3SPierre Pronchery return srp_Calc_xy(N, g, N, libctx, propq);
61*b077aed3SPierre Pronchery }
62*b077aed3SPierre Pronchery
SRP_Calc_u_ex(const BIGNUM * A,const BIGNUM * B,const BIGNUM * N,OSSL_LIB_CTX * libctx,const char * propq)63*b077aed3SPierre Pronchery BIGNUM *SRP_Calc_u_ex(const BIGNUM *A, const BIGNUM *B, const BIGNUM *N,
64*b077aed3SPierre Pronchery OSSL_LIB_CTX *libctx, const char *propq)
65*b077aed3SPierre Pronchery {
66*b077aed3SPierre Pronchery /* u = SHA1(PAD(A) || PAD(B) ) -- tls-srp RFC 5054 */
67*b077aed3SPierre Pronchery return srp_Calc_xy(A, B, N, libctx, propq);
681f13597dSJung-uk Kim }
691f13597dSJung-uk Kim
SRP_Calc_u(const BIGNUM * A,const BIGNUM * B,const BIGNUM * N)70e71b7053SJung-uk Kim BIGNUM *SRP_Calc_u(const BIGNUM *A, const BIGNUM *B, const BIGNUM *N)
711f13597dSJung-uk Kim {
72*b077aed3SPierre Pronchery /* u = SHA1(PAD(A) || PAD(B) ) -- tls-srp RFC 5054 */
73*b077aed3SPierre Pronchery return srp_Calc_xy(A, B, N, NULL, NULL);
741f13597dSJung-uk Kim }
751f13597dSJung-uk Kim
SRP_Calc_server_key(const BIGNUM * A,const BIGNUM * v,const BIGNUM * u,const BIGNUM * b,const BIGNUM * N)76e71b7053SJung-uk Kim BIGNUM *SRP_Calc_server_key(const BIGNUM *A, const BIGNUM *v, const BIGNUM *u,
77e71b7053SJung-uk Kim const BIGNUM *b, const BIGNUM *N)
781f13597dSJung-uk Kim {
791f13597dSJung-uk Kim BIGNUM *tmp = NULL, *S = NULL;
801f13597dSJung-uk Kim BN_CTX *bn_ctx;
811f13597dSJung-uk Kim
821f13597dSJung-uk Kim if (u == NULL || A == NULL || v == NULL || b == NULL || N == NULL)
831f13597dSJung-uk Kim return NULL;
841f13597dSJung-uk Kim
85aeb5019cSJung-uk Kim if ((bn_ctx = BN_CTX_new()) == NULL || (tmp = BN_new()) == NULL)
861f13597dSJung-uk Kim goto err;
871f13597dSJung-uk Kim
881f13597dSJung-uk Kim /* S = (A*v**u) ** b */
891f13597dSJung-uk Kim
901f13597dSJung-uk Kim if (!BN_mod_exp(tmp, v, u, N, bn_ctx))
911f13597dSJung-uk Kim goto err;
921f13597dSJung-uk Kim if (!BN_mod_mul(tmp, A, tmp, N, bn_ctx))
931f13597dSJung-uk Kim goto err;
94aeb5019cSJung-uk Kim
95aeb5019cSJung-uk Kim S = BN_new();
96aeb5019cSJung-uk Kim if (S != NULL && !BN_mod_exp(S, tmp, b, N, bn_ctx)) {
97aeb5019cSJung-uk Kim BN_free(S);
98aeb5019cSJung-uk Kim S = NULL;
99aeb5019cSJung-uk Kim }
1001f13597dSJung-uk Kim err:
1011f13597dSJung-uk Kim BN_CTX_free(bn_ctx);
1021f13597dSJung-uk Kim BN_clear_free(tmp);
1031f13597dSJung-uk Kim return S;
1041f13597dSJung-uk Kim }
1051f13597dSJung-uk Kim
SRP_Calc_B_ex(const BIGNUM * b,const BIGNUM * N,const BIGNUM * g,const BIGNUM * v,OSSL_LIB_CTX * libctx,const char * propq)106*b077aed3SPierre Pronchery BIGNUM *SRP_Calc_B_ex(const BIGNUM *b, const BIGNUM *N, const BIGNUM *g,
107*b077aed3SPierre Pronchery const BIGNUM *v, OSSL_LIB_CTX *libctx, const char *propq)
1081f13597dSJung-uk Kim {
1091f13597dSJung-uk Kim BIGNUM *kv = NULL, *gb = NULL;
1101f13597dSJung-uk Kim BIGNUM *B = NULL, *k = NULL;
1111f13597dSJung-uk Kim BN_CTX *bn_ctx;
1121f13597dSJung-uk Kim
1131f13597dSJung-uk Kim if (b == NULL || N == NULL || g == NULL || v == NULL ||
114*b077aed3SPierre Pronchery (bn_ctx = BN_CTX_new_ex(libctx)) == NULL)
1151f13597dSJung-uk Kim return NULL;
1161f13597dSJung-uk Kim
1171f13597dSJung-uk Kim if ((kv = BN_new()) == NULL ||
1186f9291ceSJung-uk Kim (gb = BN_new()) == NULL || (B = BN_new()) == NULL)
1191f13597dSJung-uk Kim goto err;
1201f13597dSJung-uk Kim
1211f13597dSJung-uk Kim /* B = g**b + k*v */
1221f13597dSJung-uk Kim
123e71b7053SJung-uk Kim if (!BN_mod_exp(gb, g, b, N, bn_ctx)
124*b077aed3SPierre Pronchery || (k = srp_Calc_k(N, g, libctx, propq)) == NULL
125e71b7053SJung-uk Kim || !BN_mod_mul(kv, v, k, N, bn_ctx)
126e71b7053SJung-uk Kim || !BN_mod_add(B, gb, kv, N, bn_ctx)) {
1271f13597dSJung-uk Kim BN_free(B);
1281f13597dSJung-uk Kim B = NULL;
1291f13597dSJung-uk Kim }
1301f13597dSJung-uk Kim err:
1311f13597dSJung-uk Kim BN_CTX_free(bn_ctx);
1321f13597dSJung-uk Kim BN_clear_free(kv);
1331f13597dSJung-uk Kim BN_clear_free(gb);
1341f13597dSJung-uk Kim BN_free(k);
1351f13597dSJung-uk Kim return B;
1361f13597dSJung-uk Kim }
1371f13597dSJung-uk Kim
SRP_Calc_B(const BIGNUM * b,const BIGNUM * N,const BIGNUM * g,const BIGNUM * v)138*b077aed3SPierre Pronchery BIGNUM *SRP_Calc_B(const BIGNUM *b, const BIGNUM *N, const BIGNUM *g,
139*b077aed3SPierre Pronchery const BIGNUM *v)
140*b077aed3SPierre Pronchery {
141*b077aed3SPierre Pronchery return SRP_Calc_B_ex(b, N, g, v, NULL, NULL);
142*b077aed3SPierre Pronchery }
143*b077aed3SPierre Pronchery
SRP_Calc_x_ex(const BIGNUM * s,const char * user,const char * pass,OSSL_LIB_CTX * libctx,const char * propq)144*b077aed3SPierre Pronchery BIGNUM *SRP_Calc_x_ex(const BIGNUM *s, const char *user, const char *pass,
145*b077aed3SPierre Pronchery OSSL_LIB_CTX *libctx, const char *propq)
1461f13597dSJung-uk Kim {
1471f13597dSJung-uk Kim unsigned char dig[SHA_DIGEST_LENGTH];
148e71b7053SJung-uk Kim EVP_MD_CTX *ctxt;
149e71b7053SJung-uk Kim unsigned char *cs = NULL;
150e71b7053SJung-uk Kim BIGNUM *res = NULL;
151*b077aed3SPierre Pronchery EVP_MD *sha1 = NULL;
1521f13597dSJung-uk Kim
1536f9291ceSJung-uk Kim if ((s == NULL) || (user == NULL) || (pass == NULL))
1541f13597dSJung-uk Kim return NULL;
1551f13597dSJung-uk Kim
156e71b7053SJung-uk Kim ctxt = EVP_MD_CTX_new();
157e71b7053SJung-uk Kim if (ctxt == NULL)
1581f13597dSJung-uk Kim return NULL;
159e71b7053SJung-uk Kim if ((cs = OPENSSL_malloc(BN_num_bytes(s))) == NULL)
160e71b7053SJung-uk Kim goto err;
1611f13597dSJung-uk Kim
162*b077aed3SPierre Pronchery sha1 = EVP_MD_fetch(libctx, "SHA1", propq);
163*b077aed3SPierre Pronchery if (sha1 == NULL)
164*b077aed3SPierre Pronchery goto err;
165*b077aed3SPierre Pronchery
166*b077aed3SPierre Pronchery if (!EVP_DigestInit_ex(ctxt, sha1, NULL)
167e71b7053SJung-uk Kim || !EVP_DigestUpdate(ctxt, user, strlen(user))
168e71b7053SJung-uk Kim || !EVP_DigestUpdate(ctxt, ":", 1)
169e71b7053SJung-uk Kim || !EVP_DigestUpdate(ctxt, pass, strlen(pass))
170e71b7053SJung-uk Kim || !EVP_DigestFinal_ex(ctxt, dig, NULL)
171*b077aed3SPierre Pronchery || !EVP_DigestInit_ex(ctxt, sha1, NULL))
172e71b7053SJung-uk Kim goto err;
1736935a639SJung-uk Kim if (BN_bn2bin(s, cs) < 0)
1746935a639SJung-uk Kim goto err;
175e71b7053SJung-uk Kim if (!EVP_DigestUpdate(ctxt, cs, BN_num_bytes(s)))
176e71b7053SJung-uk Kim goto err;
1771f13597dSJung-uk Kim
178e71b7053SJung-uk Kim if (!EVP_DigestUpdate(ctxt, dig, sizeof(dig))
179e71b7053SJung-uk Kim || !EVP_DigestFinal_ex(ctxt, dig, NULL))
180e71b7053SJung-uk Kim goto err;
181e71b7053SJung-uk Kim
182e71b7053SJung-uk Kim res = BN_bin2bn(dig, sizeof(dig), NULL);
183e71b7053SJung-uk Kim
184e71b7053SJung-uk Kim err:
185*b077aed3SPierre Pronchery EVP_MD_free(sha1);
186e71b7053SJung-uk Kim OPENSSL_free(cs);
187e71b7053SJung-uk Kim EVP_MD_CTX_free(ctxt);
188e71b7053SJung-uk Kim return res;
1891f13597dSJung-uk Kim }
1901f13597dSJung-uk Kim
SRP_Calc_x(const BIGNUM * s,const char * user,const char * pass)191*b077aed3SPierre Pronchery BIGNUM *SRP_Calc_x(const BIGNUM *s, const char *user, const char *pass)
192*b077aed3SPierre Pronchery {
193*b077aed3SPierre Pronchery return SRP_Calc_x_ex(s, user, pass, NULL, NULL);
194*b077aed3SPierre Pronchery }
195*b077aed3SPierre Pronchery
SRP_Calc_A(const BIGNUM * a,const BIGNUM * N,const BIGNUM * g)196e71b7053SJung-uk Kim BIGNUM *SRP_Calc_A(const BIGNUM *a, const BIGNUM *N, const BIGNUM *g)
1971f13597dSJung-uk Kim {
1981f13597dSJung-uk Kim BN_CTX *bn_ctx;
1991f13597dSJung-uk Kim BIGNUM *A = NULL;
2001f13597dSJung-uk Kim
201e71b7053SJung-uk Kim if (a == NULL || N == NULL || g == NULL || (bn_ctx = BN_CTX_new()) == NULL)
2021f13597dSJung-uk Kim return NULL;
2031f13597dSJung-uk Kim
2046f9291ceSJung-uk Kim if ((A = BN_new()) != NULL && !BN_mod_exp(A, g, a, N, bn_ctx)) {
2051f13597dSJung-uk Kim BN_free(A);
2061f13597dSJung-uk Kim A = NULL;
2071f13597dSJung-uk Kim }
2081f13597dSJung-uk Kim BN_CTX_free(bn_ctx);
2091f13597dSJung-uk Kim return A;
2101f13597dSJung-uk Kim }
2111f13597dSJung-uk Kim
SRP_Calc_client_key_ex(const BIGNUM * N,const BIGNUM * B,const BIGNUM * g,const BIGNUM * x,const BIGNUM * a,const BIGNUM * u,OSSL_LIB_CTX * libctx,const char * propq)212*b077aed3SPierre Pronchery BIGNUM *SRP_Calc_client_key_ex(const BIGNUM *N, const BIGNUM *B, const BIGNUM *g,
213*b077aed3SPierre Pronchery const BIGNUM *x, const BIGNUM *a, const BIGNUM *u,
214*b077aed3SPierre Pronchery OSSL_LIB_CTX *libctx, const char *propq)
2151f13597dSJung-uk Kim {
2161f13597dSJung-uk Kim BIGNUM *tmp = NULL, *tmp2 = NULL, *tmp3 = NULL, *k = NULL, *K = NULL;
21788e852c0SJung-uk Kim BIGNUM *xtmp = NULL;
2181f13597dSJung-uk Kim BN_CTX *bn_ctx;
2191f13597dSJung-uk Kim
2206f9291ceSJung-uk Kim if (u == NULL || B == NULL || N == NULL || g == NULL || x == NULL
221*b077aed3SPierre Pronchery || a == NULL || (bn_ctx = BN_CTX_new_ex(libctx)) == NULL)
2221f13597dSJung-uk Kim return NULL;
2231f13597dSJung-uk Kim
2241f13597dSJung-uk Kim if ((tmp = BN_new()) == NULL ||
2251f13597dSJung-uk Kim (tmp2 = BN_new()) == NULL ||
22688e852c0SJung-uk Kim (tmp3 = BN_new()) == NULL ||
22788e852c0SJung-uk Kim (xtmp = BN_new()) == NULL)
2281f13597dSJung-uk Kim goto err;
2291f13597dSJung-uk Kim
23088e852c0SJung-uk Kim BN_with_flags(xtmp, x, BN_FLG_CONSTTIME);
23188e852c0SJung-uk Kim BN_set_flags(tmp, BN_FLG_CONSTTIME);
23288e852c0SJung-uk Kim if (!BN_mod_exp(tmp, g, xtmp, N, bn_ctx))
2331f13597dSJung-uk Kim goto err;
234*b077aed3SPierre Pronchery if ((k = srp_Calc_k(N, g, libctx, propq)) == NULL)
2351f13597dSJung-uk Kim goto err;
2361f13597dSJung-uk Kim if (!BN_mod_mul(tmp2, tmp, k, N, bn_ctx))
2371f13597dSJung-uk Kim goto err;
2381f13597dSJung-uk Kim if (!BN_mod_sub(tmp, B, tmp2, N, bn_ctx))
2391f13597dSJung-uk Kim goto err;
24088e852c0SJung-uk Kim if (!BN_mul(tmp3, u, xtmp, bn_ctx))
2411f13597dSJung-uk Kim goto err;
242aeb5019cSJung-uk Kim if (!BN_add(tmp2, a, tmp3))
2431f13597dSJung-uk Kim goto err;
244aeb5019cSJung-uk Kim K = BN_new();
245aeb5019cSJung-uk Kim if (K != NULL && !BN_mod_exp(K, tmp, tmp2, N, bn_ctx)) {
246aeb5019cSJung-uk Kim BN_free(K);
247aeb5019cSJung-uk Kim K = NULL;
248aeb5019cSJung-uk Kim }
2491f13597dSJung-uk Kim
2501f13597dSJung-uk Kim err:
2511f13597dSJung-uk Kim BN_CTX_free(bn_ctx);
25288e852c0SJung-uk Kim BN_free(xtmp);
2531f13597dSJung-uk Kim BN_clear_free(tmp);
2541f13597dSJung-uk Kim BN_clear_free(tmp2);
2551f13597dSJung-uk Kim BN_clear_free(tmp3);
2561f13597dSJung-uk Kim BN_free(k);
2571f13597dSJung-uk Kim return K;
2581f13597dSJung-uk Kim }
2591f13597dSJung-uk Kim
SRP_Calc_client_key(const BIGNUM * N,const BIGNUM * B,const BIGNUM * g,const BIGNUM * x,const BIGNUM * a,const BIGNUM * u)260*b077aed3SPierre Pronchery BIGNUM *SRP_Calc_client_key(const BIGNUM *N, const BIGNUM *B, const BIGNUM *g,
261*b077aed3SPierre Pronchery const BIGNUM *x, const BIGNUM *a, const BIGNUM *u)
262*b077aed3SPierre Pronchery {
263*b077aed3SPierre Pronchery return SRP_Calc_client_key_ex(N, B, g, x, a, u, NULL, NULL);
264*b077aed3SPierre Pronchery }
265*b077aed3SPierre Pronchery
SRP_Verify_B_mod_N(const BIGNUM * B,const BIGNUM * N)266e71b7053SJung-uk Kim int SRP_Verify_B_mod_N(const BIGNUM *B, const BIGNUM *N)
2671f13597dSJung-uk Kim {
2681f13597dSJung-uk Kim BIGNUM *r;
2691f13597dSJung-uk Kim BN_CTX *bn_ctx;
2701f13597dSJung-uk Kim int ret = 0;
2711f13597dSJung-uk Kim
2726f9291ceSJung-uk Kim if (B == NULL || N == NULL || (bn_ctx = BN_CTX_new()) == NULL)
2731f13597dSJung-uk Kim return 0;
2741f13597dSJung-uk Kim
2751f13597dSJung-uk Kim if ((r = BN_new()) == NULL)
2761f13597dSJung-uk Kim goto err;
2771f13597dSJung-uk Kim /* Checks if B % N == 0 */
2781f13597dSJung-uk Kim if (!BN_nnmod(r, B, N, bn_ctx))
2791f13597dSJung-uk Kim goto err;
2801f13597dSJung-uk Kim ret = !BN_is_zero(r);
2811f13597dSJung-uk Kim err:
2821f13597dSJung-uk Kim BN_CTX_free(bn_ctx);
2831f13597dSJung-uk Kim BN_free(r);
2841f13597dSJung-uk Kim return ret;
2851f13597dSJung-uk Kim }
2861f13597dSJung-uk Kim
SRP_Verify_A_mod_N(const BIGNUM * A,const BIGNUM * N)287e71b7053SJung-uk Kim int SRP_Verify_A_mod_N(const BIGNUM *A, const BIGNUM *N)
2881f13597dSJung-uk Kim {
2891f13597dSJung-uk Kim /* Checks if A % N == 0 */
2901f13597dSJung-uk Kim return SRP_Verify_B_mod_N(A, N);
2911f13597dSJung-uk Kim }
2921f13597dSJung-uk Kim
293e71b7053SJung-uk Kim static SRP_gN knowngN[] = {
294*b077aed3SPierre Pronchery {"8192", &ossl_bn_generator_19, &ossl_bn_group_8192},
295*b077aed3SPierre Pronchery {"6144", &ossl_bn_generator_5, &ossl_bn_group_6144},
296*b077aed3SPierre Pronchery {"4096", &ossl_bn_generator_5, &ossl_bn_group_4096},
297*b077aed3SPierre Pronchery {"3072", &ossl_bn_generator_5, &ossl_bn_group_3072},
298*b077aed3SPierre Pronchery {"2048", &ossl_bn_generator_2, &ossl_bn_group_2048},
299*b077aed3SPierre Pronchery {"1536", &ossl_bn_generator_2, &ossl_bn_group_1536},
300*b077aed3SPierre Pronchery {"1024", &ossl_bn_generator_2, &ossl_bn_group_1024},
301e71b7053SJung-uk Kim };
302e71b7053SJung-uk Kim
303e71b7053SJung-uk Kim # define KNOWN_GN_NUMBER sizeof(knowngN) / sizeof(SRP_gN)
304e71b7053SJung-uk Kim
3056f9291ceSJung-uk Kim /*
306e71b7053SJung-uk Kim * Check if G and N are known parameters. The values have been generated
307*b077aed3SPierre Pronchery * from the IETF RFC 5054
3081f13597dSJung-uk Kim */
SRP_check_known_gN_param(const BIGNUM * g,const BIGNUM * N)309e71b7053SJung-uk Kim char *SRP_check_known_gN_param(const BIGNUM *g, const BIGNUM *N)
3101f13597dSJung-uk Kim {
3111f13597dSJung-uk Kim size_t i;
3121f13597dSJung-uk Kim if ((g == NULL) || (N == NULL))
313*b077aed3SPierre Pronchery return NULL;
3141f13597dSJung-uk Kim
3156f9291ceSJung-uk Kim for (i = 0; i < KNOWN_GN_NUMBER; i++) {
3161f13597dSJung-uk Kim if (BN_cmp(knowngN[i].g, g) == 0 && BN_cmp(knowngN[i].N, N) == 0)
3171f13597dSJung-uk Kim return knowngN[i].id;
3181f13597dSJung-uk Kim }
3191f13597dSJung-uk Kim return NULL;
3201f13597dSJung-uk Kim }
3211f13597dSJung-uk Kim
SRP_get_default_gN(const char * id)3221f13597dSJung-uk Kim SRP_gN *SRP_get_default_gN(const char *id)
3231f13597dSJung-uk Kim {
3241f13597dSJung-uk Kim size_t i;
3251f13597dSJung-uk Kim
3261f13597dSJung-uk Kim if (id == NULL)
3271f13597dSJung-uk Kim return knowngN;
3286f9291ceSJung-uk Kim for (i = 0; i < KNOWN_GN_NUMBER; i++) {
3291f13597dSJung-uk Kim if (strcmp(knowngN[i].id, id) == 0)
3301f13597dSJung-uk Kim return knowngN + i;
3311f13597dSJung-uk Kim }
3321f13597dSJung-uk Kim return NULL;
3331f13597dSJung-uk Kim }
3341f13597dSJung-uk Kim #endif
335