07b2e6fd5be585a3a6aebaba01e1033f48ce5b58
[openssl.git] / include / openssl / srp.h.in
1 /*
2  * {- join("\n * ", @autowarntext) -}
3  *
4  * Copyright 2004-2020 The OpenSSL Project Authors. All Rights Reserved.
5  * Copyright (c) 2004, EdelKey Project. All Rights Reserved.
6  *
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
11  *
12  * Originally written by Christophe Renou and Peter Sylvester,
13  * for the EdelKey project.
14  */
15
16 {-
17 use OpenSSL::stackhash qw(generate_stack_macros);
18 -}
19
20 #ifndef OPENSSL_SRP_H
21 # define OPENSSL_SRP_H
22 # pragma once
23
24 # include <openssl/macros.h>
25 # ifndef OPENSSL_NO_DEPRECATED_3_0
26 #  define HEADER_SRP_H
27 # endif
28
29 #include <openssl/opensslconf.h>
30
31 #ifndef OPENSSL_NO_SRP
32 # include <stdio.h>
33 # include <string.h>
34 # include <openssl/safestack.h>
35 # include <openssl/bn.h>
36 # include <openssl/crypto.h>
37
38 # ifdef  __cplusplus
39 extern "C" {
40 # endif
41
42 # ifndef OPENSSL_NO_DEPRECATED_3_0
43
44 typedef struct SRP_gN_cache_st {
45     char *b64_bn;
46     BIGNUM *bn;
47 } SRP_gN_cache;
48 {-
49     generate_stack_macros("SRP_gN_cache");
50 -}
51
52
53 typedef struct SRP_user_pwd_st {
54     /* Owned by us. */
55     char *id;
56     BIGNUM *s;
57     BIGNUM *v;
58     /* Not owned by us. */
59     const BIGNUM *g;
60     const BIGNUM *N;
61     /* Owned by us. */
62     char *info;
63 } SRP_user_pwd;
64 {-
65     generate_stack_macros("SRP_user_pwd");
66 -}
67
68 OSSL_DEPRECATEDIN_3_0
69 SRP_user_pwd *SRP_user_pwd_new(void);
70 OSSL_DEPRECATEDIN_3_0
71 void SRP_user_pwd_free(SRP_user_pwd *user_pwd);
72
73 OSSL_DEPRECATEDIN_3_0
74 void SRP_user_pwd_set_gN(SRP_user_pwd *user_pwd, const BIGNUM *g,
75                          const BIGNUM *N);
76 OSSL_DEPRECATEDIN_3_0
77 int SRP_user_pwd_set1_ids(SRP_user_pwd *user_pwd, const char *id,
78                           const char *info);
79 OSSL_DEPRECATEDIN_3_0
80 int SRP_user_pwd_set0_sv(SRP_user_pwd *user_pwd, BIGNUM *s, BIGNUM *v);
81
82 typedef struct SRP_VBASE_st {
83     STACK_OF(SRP_user_pwd) *users_pwd;
84     STACK_OF(SRP_gN_cache) *gN_cache;
85 /* to simulate a user */
86     char *seed_key;
87     const BIGNUM *default_g;
88     const BIGNUM *default_N;
89 } SRP_VBASE;
90
91 /*
92  * Internal structure storing N and g pair
93  */
94 typedef struct SRP_gN_st {
95     char *id;
96     const BIGNUM *g;
97     const BIGNUM *N;
98 } SRP_gN;
99 {-
100     generate_stack_macros("SRP_gN");
101 -}
102
103
104 OSSL_DEPRECATEDIN_3_0
105 SRP_VBASE *SRP_VBASE_new(char *seed_key);
106 OSSL_DEPRECATEDIN_3_0
107 void SRP_VBASE_free(SRP_VBASE *vb);
108 OSSL_DEPRECATEDIN_3_0
109 int SRP_VBASE_init(SRP_VBASE *vb, char *verifier_file);
110
111 OSSL_DEPRECATEDIN_3_0
112 int SRP_VBASE_add0_user(SRP_VBASE *vb, SRP_user_pwd *user_pwd);
113
114 /* NOTE: unlike in SRP_VBASE_get_by_user, caller owns the returned pointer.*/
115 OSSL_DEPRECATEDIN_3_0
116 SRP_user_pwd *SRP_VBASE_get1_by_user(SRP_VBASE *vb, char *username);
117
118 OSSL_DEPRECATEDIN_3_0
119 char *SRP_create_verifier_ex(const char *user, const char *pass, char **salt,
120                              char **verifier, const char *N, const char *g,
121                              OSSL_LIB_CTX *libctx, const char *propq);
122 OSSL_DEPRECATEDIN_3_0
123 char *SRP_create_verifier(const char *user, const char *pass, char **salt,
124                           char **verifier, const char *N, const char *g);
125 OSSL_DEPRECATEDIN_3_0
126 int SRP_create_verifier_BN_ex(const char *user, const char *pass, BIGNUM **salt,
127                               BIGNUM **verifier, const BIGNUM *N,
128                               const BIGNUM *g, OSSL_LIB_CTX *libctx,
129                               const char *propq);
130 OSSL_DEPRECATEDIN_3_0
131 int SRP_create_verifier_BN(const char *user, const char *pass, BIGNUM **salt,
132                            BIGNUM **verifier, const BIGNUM *N,
133                            const BIGNUM *g);
134
135 #  define SRP_NO_ERROR 0
136 #  define SRP_ERR_VBASE_INCOMPLETE_FILE 1
137 #  define SRP_ERR_VBASE_BN_LIB 2
138 #  define SRP_ERR_OPEN_FILE 3
139 #  define SRP_ERR_MEMORY 4
140
141 #  define DB_srptype      0
142 #  define DB_srpverifier  1
143 #  define DB_srpsalt      2
144 #  define DB_srpid        3
145 #  define DB_srpgN        4
146 #  define DB_srpinfo      5
147 #  undef  DB_NUMBER
148 #  define DB_NUMBER       6
149
150 #  define DB_SRP_INDEX    'I'
151 #  define DB_SRP_VALID    'V'
152 #  define DB_SRP_REVOKED  'R'
153 #  define DB_SRP_MODIF    'v'
154
155 /* see srp.c */
156 OSSL_DEPRECATEDIN_3_0
157 char *SRP_check_known_gN_param(const BIGNUM *g, const BIGNUM *N);
158 OSSL_DEPRECATEDIN_3_0
159 SRP_gN *SRP_get_default_gN(const char *id);
160
161 /* server side .... */
162 OSSL_DEPRECATEDIN_3_0
163 BIGNUM *SRP_Calc_server_key(const BIGNUM *A, const BIGNUM *v, const BIGNUM *u,
164                             const BIGNUM *b, const BIGNUM *N);
165 OSSL_DEPRECATEDIN_3_0
166 BIGNUM *SRP_Calc_B_ex(const BIGNUM *b, const BIGNUM *N, const BIGNUM *g,
167                       const BIGNUM *v, OSSL_LIB_CTX *libctx, const char *propq);
168 OSSL_DEPRECATEDIN_3_0
169 BIGNUM *SRP_Calc_B(const BIGNUM *b, const BIGNUM *N, const BIGNUM *g,
170                    const BIGNUM *v);
171
172 OSSL_DEPRECATEDIN_3_0
173 int SRP_Verify_A_mod_N(const BIGNUM *A, const BIGNUM *N);
174 OSSL_DEPRECATEDIN_3_0
175 BIGNUM *SRP_Calc_u_ex(const BIGNUM *A, const BIGNUM *B, const BIGNUM *N,
176                       OSSL_LIB_CTX *libctx, const char *propq);
177 OSSL_DEPRECATEDIN_3_0
178 BIGNUM *SRP_Calc_u(const BIGNUM *A, const BIGNUM *B, const BIGNUM *N);
179
180 /* client side .... */
181
182 OSSL_DEPRECATEDIN_3_0
183 BIGNUM *SRP_Calc_x_ex(const BIGNUM *s, const char *user, const char *pass,
184                       OSSL_LIB_CTX *libctx, const char *propq);
185 OSSL_DEPRECATEDIN_3_0
186 BIGNUM *SRP_Calc_x(const BIGNUM *s, const char *user, const char *pass);
187 OSSL_DEPRECATEDIN_3_0
188 BIGNUM *SRP_Calc_A(const BIGNUM *a, const BIGNUM *N, const BIGNUM *g);
189 OSSL_DEPRECATEDIN_3_0
190 BIGNUM *SRP_Calc_client_key_ex(const BIGNUM *N, const BIGNUM *B, const BIGNUM *g,
191                             const BIGNUM *x, const BIGNUM *a, const BIGNUM *u,
192                             OSSL_LIB_CTX *libctx, const char *propq);
193 OSSL_DEPRECATEDIN_3_0
194 BIGNUM *SRP_Calc_client_key(const BIGNUM *N, const BIGNUM *B, const BIGNUM *g,
195                             const BIGNUM *x, const BIGNUM *a, const BIGNUM *u);
196 OSSL_DEPRECATEDIN_3_0
197 int SRP_Verify_B_mod_N(const BIGNUM *B, const BIGNUM *N);
198
199 #  define SRP_MINIMAL_N 1024
200
201 # endif /* OPENSSL_NO_DEPRECATED_3_0 */
202
203 /* This method ignores the configured seed and fails for an unknown user. */
204 # ifndef OPENSSL_NO_DEPRECATED_1_1_0
205 OSSL_DEPRECATEDIN_1_1_0
206 SRP_user_pwd *SRP_VBASE_get_by_user(SRP_VBASE *vb, char *username);
207 # endif
208
209 # ifdef  __cplusplus
210 }
211 # endif
212 # endif
213
214 #endif