ecdsa_sign.c 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. /*
  2. * Copyright 2015-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. * ECDSA low level APIs are deprecated for public use, but still ok for
  11. * internal use.
  12. */
  13. #include "internal/deprecated.h"
  14. #include <openssl/ec.h>
  15. #include "ec_local.h"
  16. #include <openssl/err.h>
  17. ECDSA_SIG *ECDSA_do_sign(const unsigned char *dgst, int dlen, EC_KEY *eckey)
  18. {
  19. return ECDSA_do_sign_ex(dgst, dlen, NULL, NULL, eckey);
  20. }
  21. ECDSA_SIG *ECDSA_do_sign_ex(const unsigned char *dgst, int dlen,
  22. const BIGNUM *kinv, const BIGNUM *rp,
  23. EC_KEY *eckey)
  24. {
  25. if (eckey->meth->sign_sig != NULL)
  26. return eckey->meth->sign_sig(dgst, dlen, kinv, rp, eckey);
  27. ERR_raise(ERR_LIB_EC, EC_R_OPERATION_NOT_SUPPORTED);
  28. return NULL;
  29. }
  30. int ECDSA_sign(int type, const unsigned char *dgst, int dlen, unsigned char
  31. *sig, unsigned int *siglen, EC_KEY *eckey)
  32. {
  33. return ECDSA_sign_ex(type, dgst, dlen, sig, siglen, NULL, NULL, eckey);
  34. }
  35. int ECDSA_sign_ex(int type, const unsigned char *dgst, int dlen,
  36. unsigned char *sig, unsigned int *siglen, const BIGNUM *kinv,
  37. const BIGNUM *r, EC_KEY *eckey)
  38. {
  39. if (eckey->meth->sign != NULL)
  40. return eckey->meth->sign(type, dgst, dlen, sig, siglen, kinv, r, eckey);
  41. ERR_raise(ERR_LIB_EC, EC_R_OPERATION_NOT_SUPPORTED);
  42. return 0;
  43. }
  44. int ECDSA_sign_setup(EC_KEY *eckey, BN_CTX *ctx_in, BIGNUM **kinvp,
  45. BIGNUM **rp)
  46. {
  47. if (eckey->meth->sign_setup != NULL)
  48. return eckey->meth->sign_setup(eckey, ctx_in, kinvp, rp);
  49. ERR_raise(ERR_LIB_EC, EC_R_OPERATION_NOT_SUPPORTED);
  50. return 0;
  51. }