2 * {- join("\n * ", @autowarntext) -}
4 * Copyright 2004-2020 The OpenSSL Project Authors. All Rights Reserved.
5 * Copyright (c) 2004, EdelKey Project. All Rights Reserved.
7 * Licensed under the Apache License 2.0 (the "License"). You may not use
8 * this file except in compliance with the License. You can obtain a copy
9 * in the file LICENSE in the source distribution or at
10 * https://www.openssl.org/source/license.html
12 * Originally written by Christophe Renou and Peter Sylvester,
13 * for the EdelKey project.
17 use OpenSSL::stackhash qw(generate_stack_macros);
21 # define OPENSSL_SRP_H
24 # include <openssl/macros.h>
25 # ifndef OPENSSL_NO_DEPRECATED_3_0
29 #include <openssl/opensslconf.h>
31 #ifndef OPENSSL_NO_SRP
34 # include <openssl/safestack.h>
35 # include <openssl/bn.h>
36 # include <openssl/crypto.h>
42 typedef struct SRP_gN_cache_st {
47 generate_stack_macros("SRP_gN_cache");
51 typedef struct SRP_user_pwd_st {
56 /* Not owned by us. */
63 generate_stack_macros("SRP_user_pwd");
66 SRP_user_pwd *SRP_user_pwd_new(void);
67 void SRP_user_pwd_free(SRP_user_pwd *user_pwd);
69 void SRP_user_pwd_set_gN(SRP_user_pwd *user_pwd, const BIGNUM *g, const BIGNUM *N);
70 int SRP_user_pwd_set1_ids(SRP_user_pwd *user_pwd, const char *id, const char *info);
71 int SRP_user_pwd_set0_sv(SRP_user_pwd *user_pwd, BIGNUM *s, BIGNUM *v);
73 typedef struct SRP_VBASE_st {
74 STACK_OF(SRP_user_pwd) *users_pwd;
75 STACK_OF(SRP_gN_cache) *gN_cache;
76 /* to simulate a user */
78 const BIGNUM *default_g;
79 const BIGNUM *default_N;
83 * Internal structure storing N and g pair
85 typedef struct SRP_gN_st {
91 generate_stack_macros("SRP_gN");
95 SRP_VBASE *SRP_VBASE_new(char *seed_key);
96 void SRP_VBASE_free(SRP_VBASE *vb);
97 int SRP_VBASE_init(SRP_VBASE *vb, char *verifier_file);
99 int SRP_VBASE_add0_user(SRP_VBASE *vb, SRP_user_pwd *user_pwd);
100 /* This method ignores the configured seed and fails for an unknown user. */
101 DEPRECATEDIN_1_1_0(SRP_user_pwd *SRP_VBASE_get_by_user(SRP_VBASE *vb, char *username))
102 /* NOTE: unlike in SRP_VBASE_get_by_user, caller owns the returned pointer.*/
103 SRP_user_pwd *SRP_VBASE_get1_by_user(SRP_VBASE *vb, char *username);
105 char *SRP_create_verifier_ex(const char *user, const char *pass, char **salt,
106 char **verifier, const char *N, const char *g,
107 OSSL_LIB_CTX *libctx, const char *propq);
108 char *SRP_create_verifier(const char *user, const char *pass, char **salt,
109 char **verifier, const char *N, const char *g);
110 int SRP_create_verifier_BN_ex(const char *user, const char *pass, BIGNUM **salt,
111 BIGNUM **verifier, const BIGNUM *N,
112 const BIGNUM *g, OSSL_LIB_CTX *libctx,
114 int SRP_create_verifier_BN(const char *user, const char *pass, BIGNUM **salt,
115 BIGNUM **verifier, const BIGNUM *N,
118 # define SRP_NO_ERROR 0
119 # define SRP_ERR_VBASE_INCOMPLETE_FILE 1
120 # define SRP_ERR_VBASE_BN_LIB 2
121 # define SRP_ERR_OPEN_FILE 3
122 # define SRP_ERR_MEMORY 4
124 # define DB_srptype 0
125 # define DB_srpverifier 1
126 # define DB_srpsalt 2
129 # define DB_srpinfo 5
133 # define DB_SRP_INDEX 'I'
134 # define DB_SRP_VALID 'V'
135 # define DB_SRP_REVOKED 'R'
136 # define DB_SRP_MODIF 'v'
139 char *SRP_check_known_gN_param(const BIGNUM *g, const BIGNUM *N);
140 SRP_gN *SRP_get_default_gN(const char *id);
142 /* server side .... */
143 BIGNUM *SRP_Calc_server_key(const BIGNUM *A, const BIGNUM *v, const BIGNUM *u,
144 const BIGNUM *b, const BIGNUM *N);
145 BIGNUM *SRP_Calc_B_ex(const BIGNUM *b, const BIGNUM *N, const BIGNUM *g,
146 const BIGNUM *v, OSSL_LIB_CTX *libctx, const char *propq);
147 BIGNUM *SRP_Calc_B(const BIGNUM *b, const BIGNUM *N, const BIGNUM *g,
149 int SRP_Verify_A_mod_N(const BIGNUM *A, const BIGNUM *N);
150 BIGNUM *SRP_Calc_u_ex(const BIGNUM *A, const BIGNUM *B, const BIGNUM *N,
151 OSSL_LIB_CTX *libctx, const char *propq);
152 BIGNUM *SRP_Calc_u(const BIGNUM *A, const BIGNUM *B, const BIGNUM *N);
154 /* client side .... */
155 BIGNUM *SRP_Calc_x_ex(const BIGNUM *s, const char *user, const char *pass,
156 OSSL_LIB_CTX *libctx, const char *propq);
157 BIGNUM *SRP_Calc_x(const BIGNUM *s, const char *user, const char *pass);
158 BIGNUM *SRP_Calc_A(const BIGNUM *a, const BIGNUM *N, const BIGNUM *g);
159 BIGNUM *SRP_Calc_client_key_ex(const BIGNUM *N, const BIGNUM *B, const BIGNUM *g,
160 const BIGNUM *x, const BIGNUM *a, const BIGNUM *u,
161 OSSL_LIB_CTX *libctx, const char *propq);
162 BIGNUM *SRP_Calc_client_key(const BIGNUM *N, const BIGNUM *B, const BIGNUM *g,
163 const BIGNUM *x, const BIGNUM *a, const BIGNUM *u);
164 int SRP_Verify_B_mod_N(const BIGNUM *B, const BIGNUM *N);
166 # define SRP_MINIMAL_N 1024