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