ec.h 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. /*
  2. * Copyright 2018-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. /* Internal EC functions for other submodules: not for application use */
  10. #ifndef OSSL_CRYPTO_EC_H
  11. # define OSSL_CRYPTO_EC_H
  12. # include <openssl/opensslconf.h>
  13. # ifndef OPENSSL_NO_EC
  14. # include <openssl/core.h>
  15. # include <openssl/ec.h>
  16. /*-
  17. * Computes the multiplicative inverse of x in the range
  18. * [1,EC_GROUP::order), where EC_GROUP::order is the cardinality of the
  19. * subgroup generated by the generator G:
  20. *
  21. * res := x^(-1) (mod EC_GROUP::order).
  22. *
  23. * This function expects the following two conditions to hold:
  24. * - the EC_GROUP order is prime, and
  25. * - x is included in the range [1, EC_GROUP::order).
  26. *
  27. * This function returns 1 on success, 0 on error.
  28. *
  29. * If the EC_GROUP order is even, this function explicitly returns 0 as
  30. * an error.
  31. * In case any of the two conditions stated above is not satisfied,
  32. * the correctness of its output is not guaranteed, even if the return
  33. * value could still be 1 (as primality testing and a conditional modular
  34. * reduction round on the input can be omitted by the underlying
  35. * implementations for better SCA properties on regular input values).
  36. */
  37. __owur int ec_group_do_inverse_ord(const EC_GROUP *group, BIGNUM *res,
  38. const BIGNUM *x, BN_CTX *ctx);
  39. /*-
  40. * ECDH Key Derivation Function as defined in ANSI X9.63
  41. */
  42. int ecdh_KDF_X9_63(unsigned char *out, size_t outlen,
  43. const unsigned char *Z, size_t Zlen,
  44. const unsigned char *sinfo, size_t sinfolen,
  45. const EVP_MD *md);
  46. int ec_generate_key(OPENSSL_CTX *libctx, EC_KEY *eckey, int pairwise_test);
  47. int ec_key_public_check(const EC_KEY *eckey, BN_CTX *ctx);
  48. int ec_key_private_check(const EC_KEY *eckey);
  49. int ec_key_pairwise_check(const EC_KEY *eckey, BN_CTX *ctx);
  50. OPENSSL_CTX *ec_key_get_libctx(const EC_KEY *eckey);
  51. const char *ec_key_get0_propq(const EC_KEY *eckey);
  52. const char *ec_curve_nid2name(int nid);
  53. int ec_curve_name2nid(const char *name);
  54. const unsigned char *ecdsa_algorithmidentifier_encoding(int md_nid, size_t *len);
  55. /* Backend support */
  56. int ec_key_fromdata(EC_KEY *ecx, const OSSL_PARAM params[], int include_private);
  57. int ec_key_domparams_fromdata(EC_KEY *ecx, const OSSL_PARAM params[]);
  58. int ec_key_otherparams_fromdata(EC_KEY *ec, const OSSL_PARAM params[]);
  59. int ec_set_ecdh_cofactor_mode(EC_KEY *ec, int mode);
  60. # endif /* OPENSSL_NO_EC */
  61. #endif