]>
Commit | Line | Data |
---|---|---|
0aeddcfa MC |
1 | /* |
2 | * Copyright 2016 The OpenSSL Project Authors. All Rights Reserved. | |
3 | * | |
e38873f5 | 4 | * Licensed under the Apache License 2.0 (the "License"). You may not use |
aa6bb135 RS |
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 | |
0aeddcfa | 7 | * https://www.openssl.org/source/license.html |
0aeddcfa MC |
8 | */ |
9 | ||
10 | #include <openssl/dh.h> | |
2f545ae4 | 11 | #include "internal/refcount.h" |
0aeddcfa | 12 | |
6de1fe90 BE |
13 | #define DH_MIN_MODULUS_BITS 512 |
14 | ||
0aeddcfa MC |
15 | struct dh_st { |
16 | /* | |
17 | * This first argument is used to pick up errors when a DH is passed | |
18 | * instead of a EVP_PKEY | |
19 | */ | |
20 | int pad; | |
21 | int version; | |
22 | BIGNUM *p; | |
23 | BIGNUM *g; | |
6a32a3c0 | 24 | int32_t length; /* optional */ |
0aeddcfa MC |
25 | BIGNUM *pub_key; /* g^x % p */ |
26 | BIGNUM *priv_key; /* x */ | |
27 | int flags; | |
28 | BN_MONT_CTX *method_mont_p; | |
29 | /* Place holders if we want to do X9.42 DH */ | |
30 | BIGNUM *q; | |
31 | BIGNUM *j; | |
32 | unsigned char *seed; | |
33 | int seedlen; | |
34 | BIGNUM *counter; | |
2f545ae4 | 35 | CRYPTO_REF_COUNT references; |
a3327784 | 36 | #ifndef FIPS_MODE |
0aeddcfa | 37 | CRYPTO_EX_DATA ex_data; |
62f49b90 | 38 | ENGINE *engine; |
a3327784 | 39 | #endif |
0aeddcfa | 40 | const DH_METHOD *meth; |
0aeddcfa | 41 | CRYPTO_RWLOCK *lock; |
8b84b075 RL |
42 | |
43 | /* Provider data */ | |
44 | size_t dirty_cnt; /* If any key material changes, increment this */ | |
0aeddcfa | 45 | }; |
17e01abb MC |
46 | |
47 | struct dh_method { | |
48 | char *name; | |
49 | /* Methods here */ | |
50 | int (*generate_key) (DH *dh); | |
51 | int (*compute_key) (unsigned char *key, const BIGNUM *pub_key, DH *dh); | |
0263b992 | 52 | |
17e01abb MC |
53 | /* Can be null */ |
54 | int (*bn_mod_exp) (const DH *dh, BIGNUM *r, const BIGNUM *a, | |
55 | const BIGNUM *p, const BIGNUM *m, BN_CTX *ctx, | |
56 | BN_MONT_CTX *m_ctx); | |
57 | int (*init) (DH *dh); | |
58 | int (*finish) (DH *dh); | |
59 | int flags; | |
60 | char *app_data; | |
61 | /* If this is non-NULL, it will be used to generate parameters */ | |
62 | int (*generate_params) (DH *dh, int prime_len, int generator, | |
63 | BN_GENCB *cb); | |
64 | }; | |
9aaecbfc | 65 | |
66 | int dh_buf2key(DH *key, const unsigned char *buf, size_t len); | |
67 | size_t dh_key2buf(const DH *dh, unsigned char **pbuf); |