2
0

dh_rfc5114.c 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  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. /*
  20. * Macro to make a DH structure from BIGNUM data. NB: although just copying
  21. * the BIGNUM static pointers would be more efficient, we can't do that
  22. * because they get wiped using BN_clear_free() when DH_free() is called.
  23. */
  24. #define make_dh(x) \
  25. DH *DH_get_##x(void) \
  26. { \
  27. DH *dh = DH_new(); \
  28. \
  29. if (dh == NULL) \
  30. return NULL; \
  31. dh->params.p = BN_dup(&ossl_bignum_dh##x##_p); \
  32. dh->params.g = BN_dup(&ossl_bignum_dh##x##_g); \
  33. dh->params.q = BN_dup(&ossl_bignum_dh##x##_q); \
  34. if (dh->params.p == NULL || dh->params.q == NULL || dh->params.g == NULL) {\
  35. DH_free(dh); \
  36. return NULL; \
  37. } \
  38. return dh; \
  39. }
  40. make_dh(1024_160)
  41. make_dh(2048_224)
  42. make_dh(2048_256)