dh_local.h 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  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. #include <openssl/dh.h>
  10. #include "internal/refcount.h"
  11. #include "internal/ffc.h"
  12. #define DH_MIN_MODULUS_BITS 512
  13. struct dh_st {
  14. /*
  15. * This first argument is used to pick up errors when a DH is passed
  16. * instead of a EVP_PKEY
  17. */
  18. int pad;
  19. int version;
  20. FFC_PARAMS params;
  21. /* max generated private key length (can be less than len(q)) */
  22. int32_t length;
  23. BIGNUM *pub_key; /* g^x % p */
  24. BIGNUM *priv_key; /* x */
  25. int flags;
  26. BN_MONT_CTX *method_mont_p;
  27. CRYPTO_REF_COUNT references;
  28. #ifndef FIPS_MODULE
  29. CRYPTO_EX_DATA ex_data;
  30. ENGINE *engine;
  31. #endif
  32. OSSL_LIB_CTX *libctx;
  33. const DH_METHOD *meth;
  34. CRYPTO_RWLOCK *lock;
  35. /* Provider data */
  36. size_t dirty_cnt; /* If any key material changes, increment this */
  37. };
  38. struct dh_method {
  39. char *name;
  40. /* Methods here */
  41. int (*generate_key) (DH *dh);
  42. int (*compute_key) (unsigned char *key, const BIGNUM *pub_key, DH *dh);
  43. /* Can be null */
  44. int (*bn_mod_exp) (const DH *dh, BIGNUM *r, const BIGNUM *a,
  45. const BIGNUM *p, const BIGNUM *m, BN_CTX *ctx,
  46. BN_MONT_CTX *m_ctx);
  47. int (*init) (DH *dh);
  48. int (*finish) (DH *dh);
  49. int flags;
  50. char *app_data;
  51. /* If this is non-NULL, it will be used to generate parameters */
  52. int (*generate_params) (DH *dh, int prime_len, int generator,
  53. BN_GENCB *cb);
  54. };