]>
Commit | Line | Data |
---|---|---|
0f113f3e | 1 | /* |
3b855b1f TH |
2 | * Copyright 2004-2018 The OpenSSL Project Authors. All Rights Reserved. |
3 | * Copyright (c) 2004, EdelKey Project. All Rights Reserved. | |
edc032b5 | 4 | * |
48f4ad77 | 5 | * Licensed under the Apache License 2.0 (the "License"). You may not use |
21dcbebc RS |
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 | |
3b855b1f TH |
9 | * |
10 | * Originally written by Christophe Renou and Peter Sylvester, | |
11 | * for the EdelKey project. | |
edc032b5 | 12 | */ |
21dcbebc | 13 | |
ae4186b0 DMSP |
14 | #ifndef OPENSSL_SRP_H |
15 | # define OPENSSL_SRP_H | |
d86167ec DMSP |
16 | # pragma once |
17 | ||
18 | # include <openssl/macros.h> | |
19 | # if !OPENSSL_API_3 | |
20 | # define HEADER_SRP_H | |
21 | # endif | |
edc032b5 | 22 | |
857048a7 | 23 | #include <openssl/opensslconf.h> |
edc032b5 | 24 | |
3c27208f | 25 | #ifndef OPENSSL_NO_SRP |
857048a7 RS |
26 | # include <stdio.h> |
27 | # include <string.h> | |
857048a7 RS |
28 | # include <openssl/safestack.h> |
29 | # include <openssl/bn.h> | |
30 | # include <openssl/crypto.h> | |
edc032b5 | 31 | |
3c27208f RS |
32 | # ifdef __cplusplus |
33 | extern "C" { | |
34 | # endif | |
35 | ||
0f113f3e MC |
36 | typedef struct SRP_gN_cache_st { |
37 | char *b64_bn; | |
38 | BIGNUM *bn; | |
39 | } SRP_gN_cache; | |
edc032b5 BL |
40 | |
41 | ||
85885715 | 42 | DEFINE_STACK_OF(SRP_gN_cache) |
edc032b5 | 43 | |
0f113f3e | 44 | typedef struct SRP_user_pwd_st { |
380f18ed | 45 | /* Owned by us. */ |
0f113f3e MC |
46 | char *id; |
47 | BIGNUM *s; | |
48 | BIGNUM *v; | |
380f18ed | 49 | /* Not owned by us. */ |
0f113f3e MC |
50 | const BIGNUM *g; |
51 | const BIGNUM *N; | |
380f18ed | 52 | /* Owned by us. */ |
0f113f3e MC |
53 | char *info; |
54 | } SRP_user_pwd; | |
edc032b5 | 55 | |
ebfd055b | 56 | SRP_user_pwd *SRP_user_pwd_new(void); |
380f18ed EK |
57 | void SRP_user_pwd_free(SRP_user_pwd *user_pwd); |
58 | ||
ebfd055b AS |
59 | void SRP_user_pwd_set_gN(SRP_user_pwd *user_pwd, const BIGNUM *g, const BIGNUM *N); |
60 | int SRP_user_pwd_set1_ids(SRP_user_pwd *user_pwd, const char *id, const char *info); | |
61 | int SRP_user_pwd_set0_sv(SRP_user_pwd *user_pwd, BIGNUM *s, BIGNUM *v); | |
62 | ||
85885715 | 63 | DEFINE_STACK_OF(SRP_user_pwd) |
edc032b5 | 64 | |
0f113f3e MC |
65 | typedef struct SRP_VBASE_st { |
66 | STACK_OF(SRP_user_pwd) *users_pwd; | |
67 | STACK_OF(SRP_gN_cache) *gN_cache; | |
edc032b5 | 68 | /* to simulate a user */ |
0f113f3e | 69 | char *seed_key; |
98370c2d MC |
70 | const BIGNUM *default_g; |
71 | const BIGNUM *default_N; | |
0f113f3e | 72 | } SRP_VBASE; |
edc032b5 | 73 | |
0f113f3e | 74 | /* |
02e112a8 | 75 | * Internal structure storing N and g pair |
0f113f3e MC |
76 | */ |
77 | typedef struct SRP_gN_st { | |
78 | char *id; | |
98370c2d MC |
79 | const BIGNUM *g; |
80 | const BIGNUM *N; | |
0f113f3e | 81 | } SRP_gN; |
edc032b5 | 82 | |
85885715 | 83 | DEFINE_STACK_OF(SRP_gN) |
edc032b5 BL |
84 | |
85 | SRP_VBASE *SRP_VBASE_new(char *seed_key); | |
895cba19 | 86 | void SRP_VBASE_free(SRP_VBASE *vb); |
0f113f3e | 87 | int SRP_VBASE_init(SRP_VBASE *vb, char *verifier_file); |
380f18ed | 88 | |
51f03f12 | 89 | int SRP_VBASE_add0_user(SRP_VBASE *vb, SRP_user_pwd *user_pwd); |
380f18ed EK |
90 | /* This method ignores the configured seed and fails for an unknown user. */ |
91 | DEPRECATEDIN_1_1_0(SRP_user_pwd *SRP_VBASE_get_by_user(SRP_VBASE *vb, char *username)) | |
92 | /* NOTE: unlike in SRP_VBASE_get_by_user, caller owns the returned pointer.*/ | |
93 | SRP_user_pwd *SRP_VBASE_get1_by_user(SRP_VBASE *vb, char *username); | |
94 | ||
edc032b5 | 95 | char *SRP_create_verifier(const char *user, const char *pass, char **salt, |
0f113f3e MC |
96 | char **verifier, const char *N, const char *g); |
97 | int SRP_create_verifier_BN(const char *user, const char *pass, BIGNUM **salt, | |
98 | BIGNUM **verifier, const BIGNUM *N, | |
99 | const BIGNUM *g); | |
100 | ||
857048a7 RS |
101 | # define SRP_NO_ERROR 0 |
102 | # define SRP_ERR_VBASE_INCOMPLETE_FILE 1 | |
103 | # define SRP_ERR_VBASE_BN_LIB 2 | |
104 | # define SRP_ERR_OPEN_FILE 3 | |
105 | # define SRP_ERR_MEMORY 4 | |
106 | ||
107 | # define DB_srptype 0 | |
108 | # define DB_srpverifier 1 | |
109 | # define DB_srpsalt 2 | |
110 | # define DB_srpid 3 | |
111 | # define DB_srpgN 4 | |
112 | # define DB_srpinfo 5 | |
113 | # undef DB_NUMBER | |
114 | # define DB_NUMBER 6 | |
115 | ||
116 | # define DB_SRP_INDEX 'I' | |
117 | # define DB_SRP_VALID 'V' | |
118 | # define DB_SRP_REVOKED 'R' | |
119 | # define DB_SRP_MODIF 'v' | |
edc032b5 BL |
120 | |
121 | /* see srp.c */ | |
98370c2d | 122 | char *SRP_check_known_gN_param(const BIGNUM *g, const BIGNUM *N); |
0f113f3e | 123 | SRP_gN *SRP_get_default_gN(const char *id); |
edc032b5 BL |
124 | |
125 | /* server side .... */ | |
98370c2d MC |
126 | BIGNUM *SRP_Calc_server_key(const BIGNUM *A, const BIGNUM *v, const BIGNUM *u, |
127 | const BIGNUM *b, const BIGNUM *N); | |
128 | BIGNUM *SRP_Calc_B(const BIGNUM *b, const BIGNUM *N, const BIGNUM *g, | |
129 | const BIGNUM *v); | |
130 | int SRP_Verify_A_mod_N(const BIGNUM *A, const BIGNUM *N); | |
131 | BIGNUM *SRP_Calc_u(const BIGNUM *A, const BIGNUM *B, const BIGNUM *N); | |
edc032b5 BL |
132 | |
133 | /* client side .... */ | |
98370c2d MC |
134 | BIGNUM *SRP_Calc_x(const BIGNUM *s, const char *user, const char *pass); |
135 | BIGNUM *SRP_Calc_A(const BIGNUM *a, const BIGNUM *N, const BIGNUM *g); | |
136 | BIGNUM *SRP_Calc_client_key(const BIGNUM *N, const BIGNUM *B, const BIGNUM *g, | |
137 | const BIGNUM *x, const BIGNUM *a, const BIGNUM *u); | |
138 | int SRP_Verify_B_mod_N(const BIGNUM *B, const BIGNUM *N); | |
edc032b5 | 139 | |
857048a7 | 140 | # define SRP_MINIMAL_N 1024 |
edc032b5 | 141 | |
3c27208f | 142 | # ifdef __cplusplus |
edc032b5 | 143 | } |
3c27208f RS |
144 | # endif |
145 | # endif | |
edc032b5 | 146 | |
edc032b5 | 147 | #endif |