]> git.ipfire.org Git - thirdparty/openssl.git/blob - include/openssl/srp.h.in
Rename OPENSSL_CTX prefix to OSSL_LIB_CTX
[thirdparty/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 typedef struct SRP_gN_cache_st {
43 char *b64_bn;
44 BIGNUM *bn;
45 } SRP_gN_cache;
46 {-
47 generate_stack_macros("SRP_gN_cache");
48 -}
49
50
51 typedef struct SRP_user_pwd_st {
52 /* Owned by us. */
53 char *id;
54 BIGNUM *s;
55 BIGNUM *v;
56 /* Not owned by us. */
57 const BIGNUM *g;
58 const BIGNUM *N;
59 /* Owned by us. */
60 char *info;
61 } SRP_user_pwd;
62 {-
63 generate_stack_macros("SRP_user_pwd");
64 -}
65
66 SRP_user_pwd *SRP_user_pwd_new(void);
67 void SRP_user_pwd_free(SRP_user_pwd *user_pwd);
68
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);
72
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 */
77 char *seed_key;
78 const BIGNUM *default_g;
79 const BIGNUM *default_N;
80 } SRP_VBASE;
81
82 /*
83 * Internal structure storing N and g pair
84 */
85 typedef struct SRP_gN_st {
86 char *id;
87 const BIGNUM *g;
88 const BIGNUM *N;
89 } SRP_gN;
90 {-
91 generate_stack_macros("SRP_gN");
92 -}
93
94
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);
98
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);
104
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,
113 const char *propq);
114 int SRP_create_verifier_BN(const char *user, const char *pass, BIGNUM **salt,
115 BIGNUM **verifier, const BIGNUM *N,
116 const BIGNUM *g);
117
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
123
124 # define DB_srptype 0
125 # define DB_srpverifier 1
126 # define DB_srpsalt 2
127 # define DB_srpid 3
128 # define DB_srpgN 4
129 # define DB_srpinfo 5
130 # undef DB_NUMBER
131 # define DB_NUMBER 6
132
133 # define DB_SRP_INDEX 'I'
134 # define DB_SRP_VALID 'V'
135 # define DB_SRP_REVOKED 'R'
136 # define DB_SRP_MODIF 'v'
137
138 /* see srp.c */
139 char *SRP_check_known_gN_param(const BIGNUM *g, const BIGNUM *N);
140 SRP_gN *SRP_get_default_gN(const char *id);
141
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,
148 const BIGNUM *v);
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);
153
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);
165
166 # define SRP_MINIMAL_N 1024
167
168 # ifdef __cplusplus
169 }
170 # endif
171 # endif
172
173 #endif