rsa.h 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132
  1. /*
  2. * Copyright 2019-2024 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. #ifndef OSSL_INTERNAL_RSA_H
  10. # define OSSL_INTERNAL_RSA_H
  11. # pragma once
  12. # include <openssl/core.h>
  13. # include <openssl/rsa.h>
  14. # include "crypto/types.h"
  15. #define RSA_MIN_MODULUS_BITS 512
  16. typedef struct rsa_pss_params_30_st {
  17. int hash_algorithm_nid;
  18. struct {
  19. int algorithm_nid; /* Currently always NID_mgf1 */
  20. int hash_algorithm_nid;
  21. } mask_gen;
  22. int salt_len;
  23. int trailer_field;
  24. } RSA_PSS_PARAMS_30;
  25. RSA_PSS_PARAMS_30 *ossl_rsa_get0_pss_params_30(RSA *r);
  26. int ossl_rsa_pss_params_30_set_defaults(RSA_PSS_PARAMS_30 *rsa_pss_params);
  27. int ossl_rsa_pss_params_30_copy(RSA_PSS_PARAMS_30 *to,
  28. const RSA_PSS_PARAMS_30 *from);
  29. int ossl_rsa_pss_params_30_is_unrestricted(const RSA_PSS_PARAMS_30 *rsa_pss_params);
  30. int ossl_rsa_pss_params_30_set_hashalg(RSA_PSS_PARAMS_30 *rsa_pss_params,
  31. int hashalg_nid);
  32. int ossl_rsa_pss_params_30_set_maskgenhashalg(RSA_PSS_PARAMS_30 *rsa_pss_params,
  33. int maskgenhashalg_nid);
  34. int ossl_rsa_pss_params_30_set_saltlen(RSA_PSS_PARAMS_30 *rsa_pss_params,
  35. int saltlen);
  36. int ossl_rsa_pss_params_30_set_trailerfield(RSA_PSS_PARAMS_30 *rsa_pss_params,
  37. int trailerfield);
  38. int ossl_rsa_pss_params_30_hashalg(const RSA_PSS_PARAMS_30 *rsa_pss_params);
  39. int ossl_rsa_pss_params_30_maskgenalg(const RSA_PSS_PARAMS_30 *rsa_pss_params);
  40. int ossl_rsa_pss_params_30_maskgenhashalg(const RSA_PSS_PARAMS_30 *rsa_pss_params);
  41. int ossl_rsa_pss_params_30_saltlen(const RSA_PSS_PARAMS_30 *rsa_pss_params);
  42. int ossl_rsa_pss_params_30_trailerfield(const RSA_PSS_PARAMS_30 *rsa_pss_params);
  43. const char *ossl_rsa_mgf_nid2name(int mgf);
  44. int ossl_rsa_oaeppss_md2nid(const EVP_MD *md);
  45. const char *ossl_rsa_oaeppss_nid2name(int md);
  46. RSA *ossl_rsa_new_with_ctx(OSSL_LIB_CTX *libctx);
  47. OSSL_LIB_CTX *ossl_rsa_get0_libctx(RSA *r);
  48. void ossl_rsa_set0_libctx(RSA *r, OSSL_LIB_CTX *libctx);
  49. int ossl_rsa_set0_all_params(RSA *r, STACK_OF(BIGNUM) *primes,
  50. STACK_OF(BIGNUM) *exps,
  51. STACK_OF(BIGNUM) *coeffs);
  52. int ossl_rsa_get0_all_params(RSA *r, STACK_OF(BIGNUM_const) *primes,
  53. STACK_OF(BIGNUM_const) *exps,
  54. STACK_OF(BIGNUM_const) *coeffs);
  55. int ossl_rsa_is_foreign(const RSA *rsa);
  56. RSA *ossl_rsa_dup(const RSA *rsa, int selection);
  57. int ossl_rsa_todata(RSA *rsa, OSSL_PARAM_BLD *bld, OSSL_PARAM params[],
  58. int include_private);
  59. int ossl_rsa_fromdata(RSA *rsa, const OSSL_PARAM params[], int include_private);
  60. int ossl_rsa_pss_params_30_todata(const RSA_PSS_PARAMS_30 *pss,
  61. OSSL_PARAM_BLD *bld, OSSL_PARAM params[]);
  62. int ossl_rsa_pss_params_30_fromdata(RSA_PSS_PARAMS_30 *pss_params,
  63. int *defaults_set,
  64. const OSSL_PARAM params[],
  65. OSSL_LIB_CTX *libctx);
  66. int ossl_rsa_set0_pss_params(RSA *r, RSA_PSS_PARAMS *pss);
  67. int ossl_rsa_pss_get_param_unverified(const RSA_PSS_PARAMS *pss,
  68. const EVP_MD **pmd, const EVP_MD **pmgf1md,
  69. int *psaltlen, int *ptrailerField);
  70. RSA_PSS_PARAMS *ossl_rsa_pss_decode(const X509_ALGOR *alg);
  71. int ossl_rsa_param_decode(RSA *rsa, const X509_ALGOR *alg);
  72. RSA *ossl_rsa_key_from_pkcs8(const PKCS8_PRIV_KEY_INFO *p8inf,
  73. OSSL_LIB_CTX *libctx, const char *propq);
  74. int ossl_rsa_padding_check_PKCS1_type_2(OSSL_LIB_CTX *ctx,
  75. unsigned char *to, int tlen,
  76. const unsigned char *from, int flen,
  77. int num, unsigned char *kdk);
  78. int ossl_rsa_padding_check_PKCS1_type_2_TLS(OSSL_LIB_CTX *ctx, unsigned char *to,
  79. size_t tlen,
  80. const unsigned char *from,
  81. size_t flen, int client_version,
  82. int alt_version);
  83. int ossl_rsa_padding_add_PKCS1_OAEP_mgf1_ex(OSSL_LIB_CTX *libctx,
  84. unsigned char *to, int tlen,
  85. const unsigned char *from, int flen,
  86. const unsigned char *param,
  87. int plen, const EVP_MD *md,
  88. const EVP_MD *mgf1md);
  89. int ossl_rsa_validate_public(const RSA *key);
  90. int ossl_rsa_validate_private(const RSA *key);
  91. int ossl_rsa_validate_pairwise(const RSA *key);
  92. int ossl_rsa_verify(int dtype, const unsigned char *m,
  93. unsigned int m_len, unsigned char *rm,
  94. size_t *prm_len, const unsigned char *sigbuf,
  95. size_t siglen, RSA *rsa);
  96. const unsigned char *ossl_rsa_digestinfo_encoding(int md_nid, size_t *len);
  97. extern const char *ossl_rsa_mp_factor_names[];
  98. extern const char *ossl_rsa_mp_exp_names[];
  99. extern const char *ossl_rsa_mp_coeff_names[];
  100. ASN1_STRING *ossl_rsa_ctx_to_pss_string(EVP_PKEY_CTX *pkctx);
  101. int ossl_rsa_pss_to_ctx(EVP_MD_CTX *ctx, EVP_PKEY_CTX *pkctx,
  102. const X509_ALGOR *sigalg, EVP_PKEY *pkey);
  103. # if defined(FIPS_MODULE) && !defined(OPENSSL_NO_ACVP_TESTS)
  104. int ossl_rsa_acvp_test_gen_params_new(OSSL_PARAM **dst, const OSSL_PARAM src[]);
  105. void ossl_rsa_acvp_test_gen_params_free(OSSL_PARAM *dst);
  106. int ossl_rsa_acvp_test_set_params(RSA *r, const OSSL_PARAM params[]);
  107. int ossl_rsa_acvp_test_get_params(RSA *r, OSSL_PARAM params[]);
  108. typedef struct rsa_acvp_test_st RSA_ACVP_TEST;
  109. void ossl_rsa_acvp_test_free(RSA_ACVP_TEST *t);
  110. # else
  111. # define RSA_ACVP_TEST void
  112. # endif
  113. RSA *evp_pkey_get1_RSA_PSS(EVP_PKEY *pkey);
  114. #endif