dh_rfc5114.c 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. /*
  2. * Copyright 2011-2021 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. * DH low level APIs are deprecated for public use, but still ok for
  11. * internal use.
  12. */
  13. #include "internal/deprecated.h"
  14. #include <stdio.h>
  15. #include "internal/cryptlib.h"
  16. #include "dh_local.h"
  17. #include <openssl/bn.h>
  18. #include "crypto/bn_dh.h"
  19. #include "../crypto/bn/bn_local.h"
  20. /*
  21. * Macro to make a DH structure from BIGNUM data. NB: although just copying
  22. * the BIGNUM static pointers would be more efficient, we can't do that
  23. * because they get wiped using BN_clear_free() when DH_free() is called.
  24. */
  25. #define make_dh(x) \
  26. DH *DH_get_##x(void) \
  27. { \
  28. DH *dh = DH_new(); \
  29. \
  30. if (dh == NULL) \
  31. return NULL; \
  32. dh->params.p = BN_dup(&ossl_bignum_dh##x##_p); \
  33. dh->params.g = BN_dup(&ossl_bignum_dh##x##_g); \
  34. dh->params.q = BN_dup(&ossl_bignum_dh##x##_q); \
  35. if (dh->params.p == NULL || dh->params.q == NULL || dh->params.g == NULL) {\
  36. DH_free(dh); \
  37. return NULL; \
  38. } \
  39. return dh; \
  40. }
  41. make_dh(1024_160)
  42. make_dh(2048_224)
  43. make_dh(2048_256)