diff options
Diffstat (limited to 'src/lib/libcrypto/dh/dh.h')
-rw-r--r-- | src/lib/libcrypto/dh/dh.h | 131 |
1 files changed, 88 insertions, 43 deletions
diff --git a/src/lib/libcrypto/dh/dh.h b/src/lib/libcrypto/dh/dh.h index 4cc1df2650..05851f8429 100644 --- a/src/lib/libcrypto/dh/dh.h +++ b/src/lib/libcrypto/dh/dh.h | |||
@@ -59,15 +59,41 @@ | |||
59 | #ifndef HEADER_DH_H | 59 | #ifndef HEADER_DH_H |
60 | #define HEADER_DH_H | 60 | #define HEADER_DH_H |
61 | 61 | ||
62 | #ifdef OPENSSL_NO_DH | ||
63 | #error DH is disabled. | ||
64 | #endif | ||
65 | |||
66 | #ifndef OPENSSL_NO_BIO | ||
67 | #include <openssl/bio.h> | ||
68 | #endif | ||
69 | #include <openssl/bn.h> | ||
70 | #include <openssl/crypto.h> | ||
71 | #include <openssl/ossl_typ.h> | ||
72 | |||
73 | #define DH_FLAG_CACHE_MONT_P 0x01 | ||
74 | |||
62 | #ifdef __cplusplus | 75 | #ifdef __cplusplus |
63 | extern "C" { | 76 | extern "C" { |
64 | #endif | 77 | #endif |
65 | 78 | ||
66 | #ifndef HEADER_BN_H | 79 | typedef struct dh_st DH; |
67 | #define BIGNUM char | 80 | |
68 | #endif | 81 | typedef struct dh_method { |
82 | const char *name; | ||
83 | /* Methods here */ | ||
84 | int (*generate_key)(DH *dh); | ||
85 | int (*compute_key)(unsigned char *key,const BIGNUM *pub_key,DH *dh); | ||
86 | int (*bn_mod_exp)(const DH *dh, BIGNUM *r, const BIGNUM *a, | ||
87 | const BIGNUM *p, const BIGNUM *m, BN_CTX *ctx, | ||
88 | BN_MONT_CTX *m_ctx); /* Can be null */ | ||
89 | |||
90 | int (*init)(DH *dh); | ||
91 | int (*finish)(DH *dh); | ||
92 | int flags; | ||
93 | char *app_data; | ||
94 | } DH_METHOD; | ||
69 | 95 | ||
70 | typedef struct dh_st | 96 | struct dh_st |
71 | { | 97 | { |
72 | /* This first argument is used to pick up errors when | 98 | /* This first argument is used to pick up errors when |
73 | * a DH is passed instead of a EVP_PKEY */ | 99 | * a DH is passed instead of a EVP_PKEY */ |
@@ -75,10 +101,24 @@ typedef struct dh_st | |||
75 | int version; | 101 | int version; |
76 | BIGNUM *p; | 102 | BIGNUM *p; |
77 | BIGNUM *g; | 103 | BIGNUM *g; |
78 | int length; /* optional */ | 104 | long length; /* optional */ |
79 | BIGNUM *pub_key; /* y */ | 105 | BIGNUM *pub_key; /* g^x */ |
80 | BIGNUM *priv_key; /* x */ | 106 | BIGNUM *priv_key; /* x */ |
81 | } DH; | 107 | |
108 | int flags; | ||
109 | char *method_mont_p; | ||
110 | /* Place holders if we want to do X9.42 DH */ | ||
111 | BIGNUM *q; | ||
112 | BIGNUM *j; | ||
113 | unsigned char *seed; | ||
114 | int seedlen; | ||
115 | BIGNUM *counter; | ||
116 | |||
117 | int references; | ||
118 | CRYPTO_EX_DATA ex_data; | ||
119 | const DH_METHOD *meth; | ||
120 | ENGINE *engine; | ||
121 | }; | ||
82 | 122 | ||
83 | #define DH_GENERATOR_2 2 | 123 | #define DH_GENERATOR_2 2 |
84 | /* #define DH_GENERATOR_3 3 */ | 124 | /* #define DH_GENERATOR_3 3 */ |
@@ -86,10 +126,14 @@ typedef struct dh_st | |||
86 | 126 | ||
87 | /* DH_check error codes */ | 127 | /* DH_check error codes */ |
88 | #define DH_CHECK_P_NOT_PRIME 0x01 | 128 | #define DH_CHECK_P_NOT_PRIME 0x01 |
89 | #define DH_CHECK_P_NOT_STRONG_PRIME 0x02 | 129 | #define DH_CHECK_P_NOT_SAFE_PRIME 0x02 |
90 | #define DH_UNABLE_TO_CHECK_GENERATOR 0x04 | 130 | #define DH_UNABLE_TO_CHECK_GENERATOR 0x04 |
91 | #define DH_NOT_SUITABLE_GENERATOR 0x08 | 131 | #define DH_NOT_SUITABLE_GENERATOR 0x08 |
92 | 132 | ||
133 | /* primes p where (p-1)/2 is prime too are called "safe"; we define | ||
134 | this for backward compatibility: */ | ||
135 | #define DH_CHECK_P_NOT_STRONG_PRIME DH_CHECK_P_NOT_SAFE_PRIME | ||
136 | |||
93 | #define DHparams_dup(x) (DH *)ASN1_dup((int (*)())i2d_DHparams, \ | 137 | #define DHparams_dup(x) (DH *)ASN1_dup((int (*)())i2d_DHparams, \ |
94 | (char *(*)())d2i_DHparams,(char *)(x)) | 138 | (char *(*)())d2i_DHparams,(char *)(x)) |
95 | #define d2i_DHparams_fp(fp,x) (DH *)ASN1_d2i_fp((char *(*)())DH_new, \ | 139 | #define d2i_DHparams_fp(fp,x) (DH *)ASN1_d2i_fp((char *(*)())DH_new, \ |
@@ -98,50 +142,51 @@ typedef struct dh_st | |||
98 | (unsigned char *)(x)) | 142 | (unsigned char *)(x)) |
99 | #define d2i_DHparams_bio(bp,x) (DH *)ASN1_d2i_bio((char *(*)())DH_new, \ | 143 | #define d2i_DHparams_bio(bp,x) (DH *)ASN1_d2i_bio((char *(*)())DH_new, \ |
100 | (char *(*)())d2i_DHparams,(bp),(unsigned char **)(x)) | 144 | (char *(*)())d2i_DHparams,(bp),(unsigned char **)(x)) |
145 | #ifdef __cplusplus | ||
146 | #define i2d_DHparams_bio(bp,x) ASN1_i2d_bio((int (*)())i2d_DHparams,(bp), \ | ||
147 | (unsigned char *)(x)) | ||
148 | #else | ||
101 | #define i2d_DHparams_bio(bp,x) ASN1_i2d_bio(i2d_DHparams,(bp), \ | 149 | #define i2d_DHparams_bio(bp,x) ASN1_i2d_bio(i2d_DHparams,(bp), \ |
102 | (unsigned char *)(x)) | 150 | (unsigned char *)(x)) |
151 | #endif | ||
152 | |||
153 | const DH_METHOD *DH_OpenSSL(void); | ||
154 | |||
155 | void DH_set_default_method(const DH_METHOD *meth); | ||
156 | const DH_METHOD *DH_get_default_method(void); | ||
157 | int DH_set_method(DH *dh, const DH_METHOD *meth); | ||
158 | DH *DH_new_method(ENGINE *engine); | ||
103 | 159 | ||
104 | #ifndef NOPROTO | ||
105 | DH * DH_new(void); | 160 | DH * DH_new(void); |
106 | void DH_free(DH *dh); | 161 | void DH_free(DH *dh); |
107 | int DH_size(DH *dh); | 162 | int DH_up_ref(DH *dh); |
163 | int DH_size(const DH *dh); | ||
164 | int DH_get_ex_new_index(long argl, void *argp, CRYPTO_EX_new *new_func, | ||
165 | CRYPTO_EX_dup *dup_func, CRYPTO_EX_free *free_func); | ||
166 | int DH_set_ex_data(DH *d, int idx, void *arg); | ||
167 | void *DH_get_ex_data(DH *d, int idx); | ||
108 | DH * DH_generate_parameters(int prime_len,int generator, | 168 | DH * DH_generate_parameters(int prime_len,int generator, |
109 | void (*callback)(int,int,char *),char *cb_arg); | 169 | void (*callback)(int,int,void *),void *cb_arg); |
110 | int DH_check(DH *dh,int *codes); | 170 | int DH_check(const DH *dh,int *codes); |
111 | int DH_generate_key(DH *dh); | 171 | int DH_generate_key(DH *dh); |
112 | int DH_compute_key(unsigned char *key,BIGNUM *pub_key,DH *dh); | 172 | int DH_compute_key(unsigned char *key,const BIGNUM *pub_key,DH *dh); |
113 | DH * d2i_DHparams(DH **a,unsigned char **pp, long length); | 173 | DH * d2i_DHparams(DH **a,const unsigned char **pp, long length); |
114 | int i2d_DHparams(DH *a,unsigned char **pp); | 174 | int i2d_DHparams(const DH *a,unsigned char **pp); |
115 | #ifndef NO_FP_API | 175 | #ifndef OPENSSL_NO_FP_API |
116 | int DHparams_print_fp(FILE *fp, DH *x); | 176 | int DHparams_print_fp(FILE *fp, const DH *x); |
117 | #endif | 177 | #endif |
118 | #ifdef HEADER_BIO_H | 178 | #ifndef OPENSSL_NO_BIO |
119 | int DHparams_print(BIO *bp, DH *x); | 179 | int DHparams_print(BIO *bp, const DH *x); |
120 | #else | 180 | #else |
121 | int DHparams_print(char *bp, DH *x); | 181 | int DHparams_print(char *bp, const DH *x); |
122 | #endif | ||
123 | void ERR_load_DH_strings(void ); | ||
124 | |||
125 | #else | ||
126 | |||
127 | DH * DH_new(); | ||
128 | void DH_free(); | ||
129 | int DH_size(); | ||
130 | DH * DH_generate_parameters(); | ||
131 | int DH_check(); | ||
132 | int DH_generate_key(); | ||
133 | int DH_compute_key(); | ||
134 | DH * d2i_DHparams(); | ||
135 | int i2d_DHparams(); | ||
136 | #ifndef NO_FP_API | ||
137 | int DHparams_print_fp(); | ||
138 | #endif | ||
139 | int DHparams_print(); | ||
140 | void ERR_load_DH_strings(); | ||
141 | |||
142 | #endif | 182 | #endif |
143 | 183 | ||
144 | /* BEGIN ERROR CODES */ | 184 | /* BEGIN ERROR CODES */ |
185 | /* The following lines are auto generated by the script mkerr.pl. Any changes | ||
186 | * made after this point may be overwritten when the script is next run. | ||
187 | */ | ||
188 | void ERR_load_DH_strings(void); | ||
189 | |||
145 | /* Error codes for the DH functions. */ | 190 | /* Error codes for the DH functions. */ |
146 | 191 | ||
147 | /* Function codes. */ | 192 | /* Function codes. */ |
@@ -150,13 +195,13 @@ void ERR_load_DH_strings(); | |||
150 | #define DH_F_DH_COMPUTE_KEY 102 | 195 | #define DH_F_DH_COMPUTE_KEY 102 |
151 | #define DH_F_DH_GENERATE_KEY 103 | 196 | #define DH_F_DH_GENERATE_KEY 103 |
152 | #define DH_F_DH_GENERATE_PARAMETERS 104 | 197 | #define DH_F_DH_GENERATE_PARAMETERS 104 |
153 | #define DH_F_DH_NEW 105 | 198 | #define DH_F_DH_NEW_METHOD 105 |
154 | 199 | ||
155 | /* Reason codes. */ | 200 | /* Reason codes. */ |
201 | #define DH_R_BAD_GENERATOR 101 | ||
156 | #define DH_R_NO_PRIVATE_VALUE 100 | 202 | #define DH_R_NO_PRIVATE_VALUE 100 |
157 | 203 | ||
158 | #ifdef __cplusplus | 204 | #ifdef __cplusplus |
159 | } | 205 | } |
160 | #endif | 206 | #endif |
161 | #endif | 207 | #endif |
162 | |||