]> git.ipfire.org Git - thirdparty/openssl.git/blob - crypto/dh/dh_local.h
Modify DSA and DH keys to use a shared FFC_PARAMS struct
[thirdparty/openssl.git] / crypto / dh / dh_local.h
1 /*
2 * Copyright 2016-2020 The OpenSSL Project Authors. All Rights Reserved.
3 *
4 * Licensed under the Apache License 2.0 (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 #include <openssl/dh.h>
11 #include "internal/refcount.h"
12 #include "internal/ffc.h"
13
14 #define DH_MIN_MODULUS_BITS 512
15
16 struct dh_st {
17 /*
18 * This first argument is used to pick up errors when a DH is passed
19 * instead of a EVP_PKEY
20 */
21 int pad;
22 int version;
23 FFC_PARAMS params;
24 int32_t length; /* optional value of N (if there is no q) */
25 BIGNUM *pub_key; /* g^x % p */
26 BIGNUM *priv_key; /* x */
27 int flags;
28 BN_MONT_CTX *method_mont_p;
29 CRYPTO_REF_COUNT references;
30 #ifndef FIPS_MODE
31 CRYPTO_EX_DATA ex_data;
32 ENGINE *engine;
33 #endif
34 const DH_METHOD *meth;
35 CRYPTO_RWLOCK *lock;
36
37 /* Provider data */
38 size_t dirty_cnt; /* If any key material changes, increment this */
39 };
40
41 struct dh_method {
42 char *name;
43 /* Methods here */
44 int (*generate_key) (DH *dh);
45 int (*compute_key) (unsigned char *key, const BIGNUM *pub_key, DH *dh);
46
47 /* Can be null */
48 int (*bn_mod_exp) (const DH *dh, BIGNUM *r, const BIGNUM *a,
49 const BIGNUM *p, const BIGNUM *m, BN_CTX *ctx,
50 BN_MONT_CTX *m_ctx);
51 int (*init) (DH *dh);
52 int (*finish) (DH *dh);
53 int flags;
54 char *app_data;
55 /* If this is non-NULL, it will be used to generate parameters */
56 int (*generate_params) (DH *dh, int prime_len, int generator,
57 BN_GENCB *cb);
58 };
59
60 int dh_buf2key(DH *key, const unsigned char *buf, size_t len);
61 size_t dh_key2buf(const DH *dh, unsigned char **pbuf);