Generate error queue entry on FFC_CHECK_BAD_LN_PAIR for DH and DSA
[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 typedef struct SRP_gN_cache_st {
37     char *b64_bn;
38     BIGNUM *bn;
39 } SRP_gN_cache;
40 DEFINE_OR_DECLARE_STACK_OF(SRP_gN_cache)
41
42 typedef struct SRP_user_pwd_st {
43     /* Owned by us. */
44     char *id;
45     BIGNUM *s;
46     BIGNUM *v;
47     /* Not owned by us. */
48     const BIGNUM *g;
49     const BIGNUM *N;
50     /* Owned by us. */
51     char *info;
52 } SRP_user_pwd;
53 DEFINE_OR_DECLARE_STACK_OF(SRP_user_pwd)
54
55 SRP_user_pwd *SRP_user_pwd_new(void);
56 void SRP_user_pwd_free(SRP_user_pwd *user_pwd);
57
58 void SRP_user_pwd_set_gN(SRP_user_pwd *user_pwd, const BIGNUM *g, const BIGNUM *N);
59 int SRP_user_pwd_set1_ids(SRP_user_pwd *user_pwd, const char *id, const char *info);
60 int SRP_user_pwd_set0_sv(SRP_user_pwd *user_pwd, BIGNUM *s, BIGNUM *v);
61
62 typedef struct SRP_VBASE_st {
63     STACK_OF(SRP_user_pwd) *users_pwd;
64     STACK_OF(SRP_gN_cache) *gN_cache;
65 /* to simulate a user */
66     char *seed_key;
67     const BIGNUM *default_g;
68     const BIGNUM *default_N;
69 } SRP_VBASE;
70
71 /*
72  * Internal structure storing N and g pair
73  */
74 typedef struct SRP_gN_st {
75     char *id;
76     const BIGNUM *g;
77     const BIGNUM *N;
78 } SRP_gN;
79 DEFINE_OR_DECLARE_STACK_OF(SRP_gN)
80
81 SRP_VBASE *SRP_VBASE_new(char *seed_key);
82 void SRP_VBASE_free(SRP_VBASE *vb);
83 int SRP_VBASE_init(SRP_VBASE *vb, char *verifier_file);
84
85 int SRP_VBASE_add0_user(SRP_VBASE *vb, SRP_user_pwd *user_pwd);
86 /* This method ignores the configured seed and fails for an unknown user. */
87 DEPRECATEDIN_1_1_0(SRP_user_pwd *SRP_VBASE_get_by_user(SRP_VBASE *vb, char *username))
88 /* NOTE: unlike in SRP_VBASE_get_by_user, caller owns the returned pointer.*/
89 SRP_user_pwd *SRP_VBASE_get1_by_user(SRP_VBASE *vb, char *username);
90
91 char *SRP_create_verifier_ex(const char *user, const char *pass, char **salt,
92                              char **verifier, const char *N, const char *g,
93                              OPENSSL_CTX *libctx, const char *propq);
94 char *SRP_create_verifier(const char *user, const char *pass, char **salt,
95                           char **verifier, const char *N, const char *g);
96 int SRP_create_verifier_BN_ex(const char *user, const char *pass, BIGNUM **salt,
97                               BIGNUM **verifier, const BIGNUM *N,
98                               const BIGNUM *g, OPENSSL_CTX *libctx,
99                               const char *propq);
100 int SRP_create_verifier_BN(const char *user, const char *pass, BIGNUM **salt,
101                            BIGNUM **verifier, const BIGNUM *N,
102                            const BIGNUM *g);
103
104 # define SRP_NO_ERROR 0
105 # define SRP_ERR_VBASE_INCOMPLETE_FILE 1
106 # define SRP_ERR_VBASE_BN_LIB 2
107 # define SRP_ERR_OPEN_FILE 3
108 # define SRP_ERR_MEMORY 4
109
110 # define DB_srptype      0
111 # define DB_srpverifier  1
112 # define DB_srpsalt      2
113 # define DB_srpid        3
114 # define DB_srpgN        4
115 # define DB_srpinfo      5
116 # undef  DB_NUMBER
117 # define DB_NUMBER       6
118
119 # define DB_SRP_INDEX    'I'
120 # define DB_SRP_VALID    'V'
121 # define DB_SRP_REVOKED  'R'
122 # define DB_SRP_MODIF    'v'
123
124 /* see srp.c */
125 char *SRP_check_known_gN_param(const BIGNUM *g, const BIGNUM *N);
126 SRP_gN *SRP_get_default_gN(const char *id);
127
128 /* server side .... */
129 BIGNUM *SRP_Calc_server_key(const BIGNUM *A, const BIGNUM *v, const BIGNUM *u,
130                             const BIGNUM *b, const BIGNUM *N);
131 BIGNUM *SRP_Calc_B_ex(const BIGNUM *b, const BIGNUM *N, const BIGNUM *g,
132                       const BIGNUM *v, OPENSSL_CTX *libctx, const char *propq);
133 BIGNUM *SRP_Calc_B(const BIGNUM *b, const BIGNUM *N, const BIGNUM *g,
134                    const BIGNUM *v);
135 int SRP_Verify_A_mod_N(const BIGNUM *A, const BIGNUM *N);
136 BIGNUM *SRP_Calc_u_ex(const BIGNUM *A, const BIGNUM *B, const BIGNUM *N,
137                       OPENSSL_CTX *libctx, const char *propq);
138 BIGNUM *SRP_Calc_u(const BIGNUM *A, const BIGNUM *B, const BIGNUM *N);
139
140 /* client side .... */
141 BIGNUM *SRP_Calc_x_ex(const BIGNUM *s, const char *user, const char *pass,
142                       OPENSSL_CTX *libctx, const char *propq);
143 BIGNUM *SRP_Calc_x(const BIGNUM *s, const char *user, const char *pass);
144 BIGNUM *SRP_Calc_A(const BIGNUM *a, const BIGNUM *N, const BIGNUM *g);
145 BIGNUM *SRP_Calc_client_key_ex(const BIGNUM *N, const BIGNUM *B, const BIGNUM *g,
146                             const BIGNUM *x, const BIGNUM *a, const BIGNUM *u,
147                             OPENSSL_CTX *libctx, const char *propq);
148 BIGNUM *SRP_Calc_client_key(const BIGNUM *N, const BIGNUM *B, const BIGNUM *g,
149                             const BIGNUM *x, const BIGNUM *a, const BIGNUM *u);
150 int SRP_Verify_B_mod_N(const BIGNUM *B, const BIGNUM *N);
151
152 # define SRP_MINIMAL_N 1024
153
154 # ifdef  __cplusplus
155 }
156 # endif
157 # endif
158
159 #endif