2
0

ec_deprecated.c 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. /*
  2. * Copyright 2002-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. * Suppress deprecation warnings for EC low level implementations that are
  11. * kept until removal.
  12. */
  13. #define OPENSSL_SUPPRESS_DEPRECATED
  14. #include <openssl/crypto.h>
  15. #include <openssl/err.h>
  16. #include <openssl/ec.h>
  17. #ifndef OPENSSL_NO_DEPRECATED_3_0
  18. BIGNUM *EC_POINT_point2bn(const EC_GROUP *group,
  19. const EC_POINT *point,
  20. point_conversion_form_t form,
  21. BIGNUM *ret, BN_CTX *ctx)
  22. {
  23. size_t buf_len = 0;
  24. unsigned char *buf;
  25. buf_len = EC_POINT_point2buf(group, point, form, &buf, ctx);
  26. if (buf_len == 0)
  27. return NULL;
  28. ret = BN_bin2bn(buf, buf_len, ret);
  29. OPENSSL_free(buf);
  30. return ret;
  31. }
  32. EC_POINT *EC_POINT_bn2point(const EC_GROUP *group,
  33. const BIGNUM *bn, EC_POINT *point, BN_CTX *ctx)
  34. {
  35. size_t buf_len = 0;
  36. unsigned char *buf;
  37. EC_POINT *ret;
  38. if ((buf_len = BN_num_bytes(bn)) == 0)
  39. buf_len = 1;
  40. if ((buf = OPENSSL_malloc(buf_len)) == NULL)
  41. return NULL;
  42. if (BN_bn2binpad(bn, buf, buf_len) < 0) {
  43. OPENSSL_free(buf);
  44. return NULL;
  45. }
  46. if (point == NULL) {
  47. if ((ret = EC_POINT_new(group)) == NULL) {
  48. OPENSSL_free(buf);
  49. return NULL;
  50. }
  51. } else
  52. ret = point;
  53. if (!EC_POINT_oct2point(group, ret, buf, buf_len, ctx)) {
  54. if (ret != point)
  55. EC_POINT_clear_free(ret);
  56. OPENSSL_free(buf);
  57. return NULL;
  58. }
  59. OPENSSL_free(buf);
  60. return ret;
  61. }
  62. #endif /* OPENSSL_NO_DEPRECATED_3_0 */