Update README.ssltests.md
[oweals/openssl.git] / include / openssl / srp.h
1 /*
2  * Copyright 2004-2020 The OpenSSL Project Authors. All Rights Reserved.
3  * Copyright (c) 2004, EdelKey Project. All Rights Reserved.
4  *
5  * Licensed under the Apache License 2.0 (the "License").  You may not use
6  * this file except in compliance with the License.  You can obtain a copy
7  * in the file LICENSE in the source distribution or at
8  * https://www.openssl.org/source/license.html
9  *
10  * Originally written by Christophe Renou and Peter Sylvester,
11  * for the EdelKey project.
12  */
13
14 #ifndef OPENSSL_SRP_H
15 # define OPENSSL_SRP_H
16 # pragma once
17
18 # include <openssl/macros.h>
19 # ifndef OPENSSL_NO_DEPRECATED_3_0
20 #  define HEADER_SRP_H
21 # endif
22
23 #include <openssl/opensslconf.h>
24
25 #ifndef OPENSSL_NO_SRP
26 # include <stdio.h>
27 # include <string.h>
28 # include <openssl/safestack.h>
29 # include <openssl/bn.h>
30 # include <openssl/crypto.h>
31
32 # ifdef  __cplusplus
33 extern "C" {
34 # endif
35
36 DEFINE_OR_DECLARE_STACK_OF(SRP_gN_cache)
37 DEFINE_OR_DECLARE_STACK_OF(SRP_user_pwd)
38 DEFINE_OR_DECLARE_STACK_OF(SRP_gN)
39
40 typedef struct SRP_gN_cache_st {
41     char *b64_bn;
42     BIGNUM *bn;
43 } SRP_gN_cache;
44
45 typedef struct SRP_user_pwd_st {
46     /* Owned by us. */
47     char *id;
48     BIGNUM *s;
49     BIGNUM *v;
50     /* Not owned by us. */
51     const BIGNUM *g;
52     const BIGNUM *N;
53     /* Owned by us. */
54     char *info;
55 } SRP_user_pwd;
56
57 SRP_user_pwd *SRP_user_pwd_new(void);
58 void SRP_user_pwd_free(SRP_user_pwd *user_pwd);
59
60 void SRP_user_pwd_set_gN(SRP_user_pwd *user_pwd, const BIGNUM *g, const BIGNUM *N);
61 int SRP_user_pwd_set1_ids(SRP_user_pwd *user_pwd, const char *id, const char *info);
62 int SRP_user_pwd_set0_sv(SRP_user_pwd *user_pwd, BIGNUM *s, BIGNUM *v);
63
64
65 typedef struct SRP_VBASE_st {
66     STACK_OF(SRP_user_pwd) *users_pwd;
67     STACK_OF(SRP_gN_cache) *gN_cache;
68 /* to simulate a user */
69     char *seed_key;
70     const BIGNUM *default_g;
71     const BIGNUM *default_N;
72 } SRP_VBASE;
73
74 /*
75  * Internal structure storing N and g pair
76  */
77 typedef struct SRP_gN_st {
78     char *id;
79     const BIGNUM *g;
80     const BIGNUM *N;
81 } SRP_gN;
82
83
84 SRP_VBASE *SRP_VBASE_new(char *seed_key);
85 void SRP_VBASE_free(SRP_VBASE *vb);
86 int SRP_VBASE_init(SRP_VBASE *vb, char *verifier_file);
87
88 int SRP_VBASE_add0_user(SRP_VBASE *vb, SRP_user_pwd *user_pwd);
89 /* This method ignores the configured seed and fails for an unknown user. */
90 DEPRECATEDIN_1_1_0(SRP_user_pwd *SRP_VBASE_get_by_user(SRP_VBASE *vb, char *username))
91 /* NOTE: unlike in SRP_VBASE_get_by_user, caller owns the returned pointer.*/
92 SRP_user_pwd *SRP_VBASE_get1_by_user(SRP_VBASE *vb, char *username);
93
94 char *SRP_create_verifier_ex(const char *user, const char *pass, char **salt,
95                              char **verifier, const char *N, const char *g,
96                              OPENSSL_CTX *libctx, const char *propq);
97 char *SRP_create_verifier(const char *user, const char *pass, char **salt,
98                           char **verifier, const char *N, const char *g);
99 int SRP_create_verifier_BN_ex(const char *user, const char *pass, BIGNUM **salt,
100                               BIGNUM **verifier, const BIGNUM *N,
101                               const BIGNUM *g, OPENSSL_CTX *libctx,
102                               const char *propq);
103 int SRP_create_verifier_BN(const char *user, const char *pass, BIGNUM **salt,
104                            BIGNUM **verifier, const BIGNUM *N,
105                            const BIGNUM *g);
106
107 # define SRP_NO_ERROR 0
108 # define SRP_ERR_VBASE_INCOMPLETE_FILE 1
109 # define SRP_ERR_VBASE_BN_LIB 2
110 # define SRP_ERR_OPEN_FILE 3
111 # define SRP_ERR_MEMORY 4
112
113 # define DB_srptype      0
114 # define DB_srpverifier  1
115 # define DB_srpsalt      2
116 # define DB_srpid        3
117 # define DB_srpgN        4
118 # define DB_srpinfo      5
119 # undef  DB_NUMBER
120 # define DB_NUMBER       6
121
122 # define DB_SRP_INDEX    'I'
123 # define DB_SRP_VALID    'V'
124 # define DB_SRP_REVOKED  'R'
125 # define DB_SRP_MODIF    'v'
126
127 /* see srp.c */
128 char *SRP_check_known_gN_param(const BIGNUM *g, const BIGNUM *N);
129 SRP_gN *SRP_get_default_gN(const char *id);
130
131 /* server side .... */
132 BIGNUM *SRP_Calc_server_key(const BIGNUM *A, const BIGNUM *v, const BIGNUM *u,
133                             const BIGNUM *b, const BIGNUM *N);
134 BIGNUM *SRP_Calc_B_ex(const BIGNUM *b, const BIGNUM *N, const BIGNUM *g,
135                       const BIGNUM *v, OPENSSL_CTX *libctx, const char *propq);
136 BIGNUM *SRP_Calc_B(const BIGNUM *b, const BIGNUM *N, const BIGNUM *g,
137                    const BIGNUM *v);
138 int SRP_Verify_A_mod_N(const BIGNUM *A, const BIGNUM *N);
139 BIGNUM *SRP_Calc_u_ex(const BIGNUM *A, const BIGNUM *B, const BIGNUM *N,
140                       OPENSSL_CTX *libctx, const char *propq);
141 BIGNUM *SRP_Calc_u(const BIGNUM *A, const BIGNUM *B, const BIGNUM *N);
142
143 /* client side .... */
144 BIGNUM *SRP_Calc_x_ex(const BIGNUM *s, const char *user, const char *pass,
145                       OPENSSL_CTX *libctx, const char *propq);
146 BIGNUM *SRP_Calc_x(const BIGNUM *s, const char *user, const char *pass);
147 BIGNUM *SRP_Calc_A(const BIGNUM *a, const BIGNUM *N, const BIGNUM *g);
148 BIGNUM *SRP_Calc_client_key_ex(const BIGNUM *N, const BIGNUM *B, const BIGNUM *g,
149                             const BIGNUM *x, const BIGNUM *a, const BIGNUM *u,
150                             OPENSSL_CTX *libctx, const char *propq);
151 BIGNUM *SRP_Calc_client_key(const BIGNUM *N, const BIGNUM *B, const BIGNUM *g,
152                             const BIGNUM *x, const BIGNUM *a, const BIGNUM *u);
153 int SRP_Verify_B_mod_N(const BIGNUM *B, const BIGNUM *N);
154
155 # define SRP_MINIMAL_N 1024
156
157 # ifdef  __cplusplus
158 }
159 # endif
160 # endif
161
162 #endif