ec_deprecated.c 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  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. ECerr(EC_F_EC_POINT_BN2POINT, ERR_R_MALLOC_FAILURE);
  42. return NULL;
  43. }
  44. if (!BN_bn2binpad(bn, buf, buf_len)) {
  45. OPENSSL_free(buf);
  46. return NULL;
  47. }
  48. if (point == NULL) {
  49. if ((ret = EC_POINT_new(group)) == NULL) {
  50. OPENSSL_free(buf);
  51. return NULL;
  52. }
  53. } else
  54. ret = point;
  55. if (!EC_POINT_oct2point(group, ret, buf, buf_len, ctx)) {
  56. if (ret != point)
  57. EC_POINT_clear_free(ret);
  58. OPENSSL_free(buf);
  59. return NULL;
  60. }
  61. OPENSSL_free(buf);
  62. return ret;
  63. }
  64. #endif /* OPENSSL_NO_DEPRECATED_3_0 */