dh_local.h 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. /*
  2. * Copyright 2016 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. #define DH_MIN_MODULUS_BITS 512
  12. struct dh_st {
  13. /*
  14. * This first argument is used to pick up errors when a DH is passed
  15. * instead of a EVP_PKEY
  16. */
  17. int pad;
  18. int version;
  19. BIGNUM *p;
  20. BIGNUM *g;
  21. int32_t length; /* optional */
  22. BIGNUM *pub_key; /* g^x % p */
  23. BIGNUM *priv_key; /* x */
  24. int flags;
  25. BN_MONT_CTX *method_mont_p;
  26. /* Place holders if we want to do X9.42 DH */
  27. BIGNUM *q;
  28. BIGNUM *j;
  29. unsigned char *seed;
  30. int seedlen;
  31. BIGNUM *counter;
  32. CRYPTO_REF_COUNT references;
  33. CRYPTO_EX_DATA ex_data;
  34. const DH_METHOD *meth;
  35. ENGINE *engine;
  36. CRYPTO_RWLOCK *lock;
  37. /* Provider data */
  38. size_t dirty_cnt; /* If any key material changes, increment this */
  39. };
  40. struct dh_method {
  41. char *name;
  42. /* Methods here */
  43. int (*generate_key) (DH *dh);
  44. int (*compute_key) (unsigned char *key, const BIGNUM *pub_key, DH *dh);
  45. /* Can be null */
  46. int (*bn_mod_exp) (const DH *dh, BIGNUM *r, const BIGNUM *a,
  47. const BIGNUM *p, const BIGNUM *m, BN_CTX *ctx,
  48. BN_MONT_CTX *m_ctx);
  49. int (*init) (DH *dh);
  50. int (*finish) (DH *dh);
  51. int flags;
  52. char *app_data;
  53. /* If this is non-NULL, it will be used to generate parameters */
  54. int (*generate_params) (DH *dh, int prime_len, int generator,
  55. BN_GENCB *cb);
  56. };
  57. int dh_buf2key(DH *key, const unsigned char *buf, size_t len);
  58. size_t dh_key2buf(const DH *dh, unsigned char **pbuf);