TianoCore EDK2 master
Loading...
Searching...
No Matches
srp.h
1/*
2 * WARNING: do not edit!
3 * Generated by Makefile from include/openssl/srp.h.in
4 *
5 * Copyright 2004-2021 The OpenSSL Project Authors. All Rights Reserved.
6 * Copyright (c) 2004, EdelKey Project. All Rights Reserved.
7 *
8 * Licensed under the Apache License 2.0 (the "License"). You may not use
9 * this file except in compliance with the License. You can obtain a copy
10 * in the file LICENSE in the source distribution or at
11 * https://www.openssl.org/source/license.html
12 *
13 * Originally written by Christophe Renou and Peter Sylvester,
14 * for the EdelKey project.
15 */
16
17
18
19#ifndef OPENSSL_SRP_H
20# define OPENSSL_SRP_H
21# pragma once
22
23# include <openssl/macros.h>
24# ifndef OPENSSL_NO_DEPRECATED_3_0
25# define HEADER_SRP_H
26# endif
27
28#include <openssl/opensslconf.h>
29
30#ifndef OPENSSL_NO_SRP
31# include <stdio.h>
32# include <string.h>
33# include <openssl/safestack.h>
34# include <openssl/bn.h>
35# include <openssl/crypto.h>
36
37# ifdef __cplusplus
38extern "C" {
39# endif
40
41# ifndef OPENSSL_NO_DEPRECATED_3_0
42
43typedef struct SRP_gN_cache_st {
44 char *b64_bn;
45 BIGNUM *bn;
47SKM_DEFINE_STACK_OF_INTERNAL(SRP_gN_cache, SRP_gN_cache, SRP_gN_cache)
48#define sk_SRP_gN_cache_num(sk) OPENSSL_sk_num(ossl_check_const_SRP_gN_cache_sk_type(sk))
49#define sk_SRP_gN_cache_value(sk, idx) ((SRP_gN_cache *)OPENSSL_sk_value(ossl_check_const_SRP_gN_cache_sk_type(sk), (idx)))
50#define sk_SRP_gN_cache_new(cmp) ((STACK_OF(SRP_gN_cache) *)OPENSSL_sk_new(ossl_check_SRP_gN_cache_compfunc_type(cmp)))
51#define sk_SRP_gN_cache_new_null() ((STACK_OF(SRP_gN_cache) *)OPENSSL_sk_new_null())
52#define sk_SRP_gN_cache_new_reserve(cmp, n) ((STACK_OF(SRP_gN_cache) *)OPENSSL_sk_new_reserve(ossl_check_SRP_gN_cache_compfunc_type(cmp), (n)))
53#define sk_SRP_gN_cache_reserve(sk, n) OPENSSL_sk_reserve(ossl_check_SRP_gN_cache_sk_type(sk), (n))
54#define sk_SRP_gN_cache_free(sk) OPENSSL_sk_free(ossl_check_SRP_gN_cache_sk_type(sk))
55#define sk_SRP_gN_cache_zero(sk) OPENSSL_sk_zero(ossl_check_SRP_gN_cache_sk_type(sk))
56#define sk_SRP_gN_cache_delete(sk, i) ((SRP_gN_cache *)OPENSSL_sk_delete(ossl_check_SRP_gN_cache_sk_type(sk), (i)))
57#define sk_SRP_gN_cache_delete_ptr(sk, ptr) ((SRP_gN_cache *)OPENSSL_sk_delete_ptr(ossl_check_SRP_gN_cache_sk_type(sk), ossl_check_SRP_gN_cache_type(ptr)))
58#define sk_SRP_gN_cache_push(sk, ptr) OPENSSL_sk_push(ossl_check_SRP_gN_cache_sk_type(sk), ossl_check_SRP_gN_cache_type(ptr))
59#define sk_SRP_gN_cache_unshift(sk, ptr) OPENSSL_sk_unshift(ossl_check_SRP_gN_cache_sk_type(sk), ossl_check_SRP_gN_cache_type(ptr))
60#define sk_SRP_gN_cache_pop(sk) ((SRP_gN_cache *)OPENSSL_sk_pop(ossl_check_SRP_gN_cache_sk_type(sk)))
61#define sk_SRP_gN_cache_shift(sk) ((SRP_gN_cache *)OPENSSL_sk_shift(ossl_check_SRP_gN_cache_sk_type(sk)))
62#define sk_SRP_gN_cache_pop_free(sk, freefunc) OPENSSL_sk_pop_free(ossl_check_SRP_gN_cache_sk_type(sk),ossl_check_SRP_gN_cache_freefunc_type(freefunc))
63#define sk_SRP_gN_cache_insert(sk, ptr, idx) OPENSSL_sk_insert(ossl_check_SRP_gN_cache_sk_type(sk), ossl_check_SRP_gN_cache_type(ptr), (idx))
64#define sk_SRP_gN_cache_set(sk, idx, ptr) ((SRP_gN_cache *)OPENSSL_sk_set(ossl_check_SRP_gN_cache_sk_type(sk), (idx), ossl_check_SRP_gN_cache_type(ptr)))
65#define sk_SRP_gN_cache_find(sk, ptr) OPENSSL_sk_find(ossl_check_SRP_gN_cache_sk_type(sk), ossl_check_SRP_gN_cache_type(ptr))
66#define sk_SRP_gN_cache_find_ex(sk, ptr) OPENSSL_sk_find_ex(ossl_check_SRP_gN_cache_sk_type(sk), ossl_check_SRP_gN_cache_type(ptr))
67#define sk_SRP_gN_cache_find_all(sk, ptr, pnum) OPENSSL_sk_find_all(ossl_check_SRP_gN_cache_sk_type(sk), ossl_check_SRP_gN_cache_type(ptr), pnum)
68#define sk_SRP_gN_cache_sort(sk) OPENSSL_sk_sort(ossl_check_SRP_gN_cache_sk_type(sk))
69#define sk_SRP_gN_cache_is_sorted(sk) OPENSSL_sk_is_sorted(ossl_check_const_SRP_gN_cache_sk_type(sk))
70#define sk_SRP_gN_cache_dup(sk) ((STACK_OF(SRP_gN_cache) *)OPENSSL_sk_dup(ossl_check_const_SRP_gN_cache_sk_type(sk)))
71#define sk_SRP_gN_cache_deep_copy(sk, copyfunc, freefunc) ((STACK_OF(SRP_gN_cache) *)OPENSSL_sk_deep_copy(ossl_check_const_SRP_gN_cache_sk_type(sk), ossl_check_SRP_gN_cache_copyfunc_type(copyfunc), ossl_check_SRP_gN_cache_freefunc_type(freefunc)))
72#define sk_SRP_gN_cache_set_cmp_func(sk, cmp) ((sk_SRP_gN_cache_compfunc)OPENSSL_sk_set_cmp_func(ossl_check_SRP_gN_cache_sk_type(sk), ossl_check_SRP_gN_cache_compfunc_type(cmp)))
73
74
75
76typedef struct SRP_user_pwd_st {
77 /* Owned by us. */
78 char *id;
79 BIGNUM *s;
80 BIGNUM *v;
81 /* Not owned by us. */
82 const BIGNUM *g;
83 const BIGNUM *N;
84 /* Owned by us. */
85 char *info;
87SKM_DEFINE_STACK_OF_INTERNAL(SRP_user_pwd, SRP_user_pwd, SRP_user_pwd)
88#define sk_SRP_user_pwd_num(sk) OPENSSL_sk_num(ossl_check_const_SRP_user_pwd_sk_type(sk))
89#define sk_SRP_user_pwd_value(sk, idx) ((SRP_user_pwd *)OPENSSL_sk_value(ossl_check_const_SRP_user_pwd_sk_type(sk), (idx)))
90#define sk_SRP_user_pwd_new(cmp) ((STACK_OF(SRP_user_pwd) *)OPENSSL_sk_new(ossl_check_SRP_user_pwd_compfunc_type(cmp)))
91#define sk_SRP_user_pwd_new_null() ((STACK_OF(SRP_user_pwd) *)OPENSSL_sk_new_null())
92#define sk_SRP_user_pwd_new_reserve(cmp, n) ((STACK_OF(SRP_user_pwd) *)OPENSSL_sk_new_reserve(ossl_check_SRP_user_pwd_compfunc_type(cmp), (n)))
93#define sk_SRP_user_pwd_reserve(sk, n) OPENSSL_sk_reserve(ossl_check_SRP_user_pwd_sk_type(sk), (n))
94#define sk_SRP_user_pwd_free(sk) OPENSSL_sk_free(ossl_check_SRP_user_pwd_sk_type(sk))
95#define sk_SRP_user_pwd_zero(sk) OPENSSL_sk_zero(ossl_check_SRP_user_pwd_sk_type(sk))
96#define sk_SRP_user_pwd_delete(sk, i) ((SRP_user_pwd *)OPENSSL_sk_delete(ossl_check_SRP_user_pwd_sk_type(sk), (i)))
97#define sk_SRP_user_pwd_delete_ptr(sk, ptr) ((SRP_user_pwd *)OPENSSL_sk_delete_ptr(ossl_check_SRP_user_pwd_sk_type(sk), ossl_check_SRP_user_pwd_type(ptr)))
98#define sk_SRP_user_pwd_push(sk, ptr) OPENSSL_sk_push(ossl_check_SRP_user_pwd_sk_type(sk), ossl_check_SRP_user_pwd_type(ptr))
99#define sk_SRP_user_pwd_unshift(sk, ptr) OPENSSL_sk_unshift(ossl_check_SRP_user_pwd_sk_type(sk), ossl_check_SRP_user_pwd_type(ptr))
100#define sk_SRP_user_pwd_pop(sk) ((SRP_user_pwd *)OPENSSL_sk_pop(ossl_check_SRP_user_pwd_sk_type(sk)))
101#define sk_SRP_user_pwd_shift(sk) ((SRP_user_pwd *)OPENSSL_sk_shift(ossl_check_SRP_user_pwd_sk_type(sk)))
102#define sk_SRP_user_pwd_pop_free(sk, freefunc) OPENSSL_sk_pop_free(ossl_check_SRP_user_pwd_sk_type(sk),ossl_check_SRP_user_pwd_freefunc_type(freefunc))
103#define sk_SRP_user_pwd_insert(sk, ptr, idx) OPENSSL_sk_insert(ossl_check_SRP_user_pwd_sk_type(sk), ossl_check_SRP_user_pwd_type(ptr), (idx))
104#define sk_SRP_user_pwd_set(sk, idx, ptr) ((SRP_user_pwd *)OPENSSL_sk_set(ossl_check_SRP_user_pwd_sk_type(sk), (idx), ossl_check_SRP_user_pwd_type(ptr)))
105#define sk_SRP_user_pwd_find(sk, ptr) OPENSSL_sk_find(ossl_check_SRP_user_pwd_sk_type(sk), ossl_check_SRP_user_pwd_type(ptr))
106#define sk_SRP_user_pwd_find_ex(sk, ptr) OPENSSL_sk_find_ex(ossl_check_SRP_user_pwd_sk_type(sk), ossl_check_SRP_user_pwd_type(ptr))
107#define sk_SRP_user_pwd_find_all(sk, ptr, pnum) OPENSSL_sk_find_all(ossl_check_SRP_user_pwd_sk_type(sk), ossl_check_SRP_user_pwd_type(ptr), pnum)
108#define sk_SRP_user_pwd_sort(sk) OPENSSL_sk_sort(ossl_check_SRP_user_pwd_sk_type(sk))
109#define sk_SRP_user_pwd_is_sorted(sk) OPENSSL_sk_is_sorted(ossl_check_const_SRP_user_pwd_sk_type(sk))
110#define sk_SRP_user_pwd_dup(sk) ((STACK_OF(SRP_user_pwd) *)OPENSSL_sk_dup(ossl_check_const_SRP_user_pwd_sk_type(sk)))
111#define sk_SRP_user_pwd_deep_copy(sk, copyfunc, freefunc) ((STACK_OF(SRP_user_pwd) *)OPENSSL_sk_deep_copy(ossl_check_const_SRP_user_pwd_sk_type(sk), ossl_check_SRP_user_pwd_copyfunc_type(copyfunc), ossl_check_SRP_user_pwd_freefunc_type(freefunc)))
112#define sk_SRP_user_pwd_set_cmp_func(sk, cmp) ((sk_SRP_user_pwd_compfunc)OPENSSL_sk_set_cmp_func(ossl_check_SRP_user_pwd_sk_type(sk), ossl_check_SRP_user_pwd_compfunc_type(cmp)))
113
114
115OSSL_DEPRECATEDIN_3_0
116SRP_user_pwd *SRP_user_pwd_new(void);
117OSSL_DEPRECATEDIN_3_0
118void SRP_user_pwd_free(SRP_user_pwd *user_pwd);
119
120OSSL_DEPRECATEDIN_3_0
121void SRP_user_pwd_set_gN(SRP_user_pwd *user_pwd, const BIGNUM *g,
122 const BIGNUM *N);
123OSSL_DEPRECATEDIN_3_0
124int SRP_user_pwd_set1_ids(SRP_user_pwd *user_pwd, const char *id,
125 const char *info);
126OSSL_DEPRECATEDIN_3_0
127int SRP_user_pwd_set0_sv(SRP_user_pwd *user_pwd, BIGNUM *s, BIGNUM *v);
128
129typedef struct SRP_VBASE_st {
130 STACK_OF(SRP_user_pwd) *users_pwd;
131 STACK_OF(SRP_gN_cache) *gN_cache;
132/* to simulate a user */
133 char *seed_key;
134 const BIGNUM *default_g;
135 const BIGNUM *default_N;
136} SRP_VBASE;
137
138/*
139 * Internal structure storing N and g pair
140 */
141typedef struct SRP_gN_st {
142 char *id;
143 const BIGNUM *g;
144 const BIGNUM *N;
145} SRP_gN;
146SKM_DEFINE_STACK_OF_INTERNAL(SRP_gN, SRP_gN, SRP_gN)
147#define sk_SRP_gN_num(sk) OPENSSL_sk_num(ossl_check_const_SRP_gN_sk_type(sk))
148#define sk_SRP_gN_value(sk, idx) ((SRP_gN *)OPENSSL_sk_value(ossl_check_const_SRP_gN_sk_type(sk), (idx)))
149#define sk_SRP_gN_new(cmp) ((STACK_OF(SRP_gN) *)OPENSSL_sk_new(ossl_check_SRP_gN_compfunc_type(cmp)))
150#define sk_SRP_gN_new_null() ((STACK_OF(SRP_gN) *)OPENSSL_sk_new_null())
151#define sk_SRP_gN_new_reserve(cmp, n) ((STACK_OF(SRP_gN) *)OPENSSL_sk_new_reserve(ossl_check_SRP_gN_compfunc_type(cmp), (n)))
152#define sk_SRP_gN_reserve(sk, n) OPENSSL_sk_reserve(ossl_check_SRP_gN_sk_type(sk), (n))
153#define sk_SRP_gN_free(sk) OPENSSL_sk_free(ossl_check_SRP_gN_sk_type(sk))
154#define sk_SRP_gN_zero(sk) OPENSSL_sk_zero(ossl_check_SRP_gN_sk_type(sk))
155#define sk_SRP_gN_delete(sk, i) ((SRP_gN *)OPENSSL_sk_delete(ossl_check_SRP_gN_sk_type(sk), (i)))
156#define sk_SRP_gN_delete_ptr(sk, ptr) ((SRP_gN *)OPENSSL_sk_delete_ptr(ossl_check_SRP_gN_sk_type(sk), ossl_check_SRP_gN_type(ptr)))
157#define sk_SRP_gN_push(sk, ptr) OPENSSL_sk_push(ossl_check_SRP_gN_sk_type(sk), ossl_check_SRP_gN_type(ptr))
158#define sk_SRP_gN_unshift(sk, ptr) OPENSSL_sk_unshift(ossl_check_SRP_gN_sk_type(sk), ossl_check_SRP_gN_type(ptr))
159#define sk_SRP_gN_pop(sk) ((SRP_gN *)OPENSSL_sk_pop(ossl_check_SRP_gN_sk_type(sk)))
160#define sk_SRP_gN_shift(sk) ((SRP_gN *)OPENSSL_sk_shift(ossl_check_SRP_gN_sk_type(sk)))
161#define sk_SRP_gN_pop_free(sk, freefunc) OPENSSL_sk_pop_free(ossl_check_SRP_gN_sk_type(sk),ossl_check_SRP_gN_freefunc_type(freefunc))
162#define sk_SRP_gN_insert(sk, ptr, idx) OPENSSL_sk_insert(ossl_check_SRP_gN_sk_type(sk), ossl_check_SRP_gN_type(ptr), (idx))
163#define sk_SRP_gN_set(sk, idx, ptr) ((SRP_gN *)OPENSSL_sk_set(ossl_check_SRP_gN_sk_type(sk), (idx), ossl_check_SRP_gN_type(ptr)))
164#define sk_SRP_gN_find(sk, ptr) OPENSSL_sk_find(ossl_check_SRP_gN_sk_type(sk), ossl_check_SRP_gN_type(ptr))
165#define sk_SRP_gN_find_ex(sk, ptr) OPENSSL_sk_find_ex(ossl_check_SRP_gN_sk_type(sk), ossl_check_SRP_gN_type(ptr))
166#define sk_SRP_gN_find_all(sk, ptr, pnum) OPENSSL_sk_find_all(ossl_check_SRP_gN_sk_type(sk), ossl_check_SRP_gN_type(ptr), pnum)
167#define sk_SRP_gN_sort(sk) OPENSSL_sk_sort(ossl_check_SRP_gN_sk_type(sk))
168#define sk_SRP_gN_is_sorted(sk) OPENSSL_sk_is_sorted(ossl_check_const_SRP_gN_sk_type(sk))
169#define sk_SRP_gN_dup(sk) ((STACK_OF(SRP_gN) *)OPENSSL_sk_dup(ossl_check_const_SRP_gN_sk_type(sk)))
170#define sk_SRP_gN_deep_copy(sk, copyfunc, freefunc) ((STACK_OF(SRP_gN) *)OPENSSL_sk_deep_copy(ossl_check_const_SRP_gN_sk_type(sk), ossl_check_SRP_gN_copyfunc_type(copyfunc), ossl_check_SRP_gN_freefunc_type(freefunc)))
171#define sk_SRP_gN_set_cmp_func(sk, cmp) ((sk_SRP_gN_compfunc)OPENSSL_sk_set_cmp_func(ossl_check_SRP_gN_sk_type(sk), ossl_check_SRP_gN_compfunc_type(cmp)))
172
173
174
175OSSL_DEPRECATEDIN_3_0
176SRP_VBASE *SRP_VBASE_new(char *seed_key);
177OSSL_DEPRECATEDIN_3_0
178void SRP_VBASE_free(SRP_VBASE *vb);
179OSSL_DEPRECATEDIN_3_0
180int SRP_VBASE_init(SRP_VBASE *vb, char *verifier_file);
181
182OSSL_DEPRECATEDIN_3_0
183int SRP_VBASE_add0_user(SRP_VBASE *vb, SRP_user_pwd *user_pwd);
184
185/* NOTE: unlike in SRP_VBASE_get_by_user, caller owns the returned pointer.*/
186OSSL_DEPRECATEDIN_3_0
187SRP_user_pwd *SRP_VBASE_get1_by_user(SRP_VBASE *vb, char *username);
188
189OSSL_DEPRECATEDIN_3_0
190char *SRP_create_verifier_ex(const char *user, const char *pass, char **salt,
191 char **verifier, const char *N, const char *g,
192 OSSL_LIB_CTX *libctx, const char *propq);
193OSSL_DEPRECATEDIN_3_0
194char *SRP_create_verifier(const char *user, const char *pass, char **salt,
195 char **verifier, const char *N, const char *g);
196OSSL_DEPRECATEDIN_3_0
197int SRP_create_verifier_BN_ex(const char *user, const char *pass, BIGNUM **salt,
198 BIGNUM **verifier, const BIGNUM *N,
199 const BIGNUM *g, OSSL_LIB_CTX *libctx,
200 const char *propq);
201OSSL_DEPRECATEDIN_3_0
202int SRP_create_verifier_BN(const char *user, const char *pass, BIGNUM **salt,
203 BIGNUM **verifier, const BIGNUM *N,
204 const BIGNUM *g);
205
206# define SRP_NO_ERROR 0
207# define SRP_ERR_VBASE_INCOMPLETE_FILE 1
208# define SRP_ERR_VBASE_BN_LIB 2
209# define SRP_ERR_OPEN_FILE 3
210# define SRP_ERR_MEMORY 4
211
212# define DB_srptype 0
213# define DB_srpverifier 1
214# define DB_srpsalt 2
215# define DB_srpid 3
216# define DB_srpgN 4
217# define DB_srpinfo 5
218# undef DB_NUMBER
219# define DB_NUMBER 6
220
221# define DB_SRP_INDEX 'I'
222# define DB_SRP_VALID 'V'
223# define DB_SRP_REVOKED 'R'
224# define DB_SRP_MODIF 'v'
225
226/* see srp.c */
227OSSL_DEPRECATEDIN_3_0
228char *SRP_check_known_gN_param(const BIGNUM *g, const BIGNUM *N);
229OSSL_DEPRECATEDIN_3_0
230SRP_gN *SRP_get_default_gN(const char *id);
231
232/* server side .... */
233OSSL_DEPRECATEDIN_3_0
234BIGNUM *SRP_Calc_server_key(const BIGNUM *A, const BIGNUM *v, const BIGNUM *u,
235 const BIGNUM *b, const BIGNUM *N);
236OSSL_DEPRECATEDIN_3_0
237BIGNUM *SRP_Calc_B_ex(const BIGNUM *b, const BIGNUM *N, const BIGNUM *g,
238 const BIGNUM *v, OSSL_LIB_CTX *libctx, const char *propq);
239OSSL_DEPRECATEDIN_3_0
240BIGNUM *SRP_Calc_B(const BIGNUM *b, const BIGNUM *N, const BIGNUM *g,
241 const BIGNUM *v);
242
243OSSL_DEPRECATEDIN_3_0
244int SRP_Verify_A_mod_N(const BIGNUM *A, const BIGNUM *N);
245OSSL_DEPRECATEDIN_3_0
246BIGNUM *SRP_Calc_u_ex(const BIGNUM *A, const BIGNUM *B, const BIGNUM *N,
247 OSSL_LIB_CTX *libctx, const char *propq);
248OSSL_DEPRECATEDIN_3_0
249BIGNUM *SRP_Calc_u(const BIGNUM *A, const BIGNUM *B, const BIGNUM *N);
250
251/* client side .... */
252
253OSSL_DEPRECATEDIN_3_0
254BIGNUM *SRP_Calc_x_ex(const BIGNUM *s, const char *user, const char *pass,
255 OSSL_LIB_CTX *libctx, const char *propq);
256OSSL_DEPRECATEDIN_3_0
257BIGNUM *SRP_Calc_x(const BIGNUM *s, const char *user, const char *pass);
258OSSL_DEPRECATEDIN_3_0
259BIGNUM *SRP_Calc_A(const BIGNUM *a, const BIGNUM *N, const BIGNUM *g);
260OSSL_DEPRECATEDIN_3_0
261BIGNUM *SRP_Calc_client_key_ex(const BIGNUM *N, const BIGNUM *B, const BIGNUM *g,
262 const BIGNUM *x, const BIGNUM *a, const BIGNUM *u,
263 OSSL_LIB_CTX *libctx, const char *propq);
264OSSL_DEPRECATEDIN_3_0
265BIGNUM *SRP_Calc_client_key(const BIGNUM *N, const BIGNUM *B, const BIGNUM *g,
266 const BIGNUM *x, const BIGNUM *a, const BIGNUM *u);
267OSSL_DEPRECATEDIN_3_0
268int SRP_Verify_B_mod_N(const BIGNUM *B, const BIGNUM *N);
269
270# define SRP_MINIMAL_N 1024
271
272# endif /* OPENSSL_NO_DEPRECATED_3_0 */
273
274/* This method ignores the configured seed and fails for an unknown user. */
275# ifndef OPENSSL_NO_DEPRECATED_1_1_0
276OSSL_DEPRECATEDIN_1_1_0
277SRP_user_pwd *SRP_VBASE_get_by_user(SRP_VBASE *vb, char *username);
278# endif
279
280# ifdef __cplusplus
281}
282# endif
283# endif
284
285#endif
Definition: srp.h:141