]> git.ipfire.org Git - thirdparty/openssl.git/blame - include/crypto/rsa.h
Fix change in behaviour of EVP_PKEY_CTRL_RSA_KEYGEN_BITS
[thirdparty/openssl.git] / include / crypto / rsa.h
CommitLineData
c3a4fa4c 1/*
a28d06f3 2 * Copyright 2019-2021 The OpenSSL Project Authors. All Rights Reserved.
c3a4fa4c
RL
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#ifndef OSSL_INTERNAL_RSA_H
11# define OSSL_INTERNAL_RSA_H
80ce21fe 12# pragma once
c3a4fa4c 13
4f2271d5
SL
14# include <openssl/core.h>
15# include <openssl/rsa.h>
cf333799 16# include <openssl/x509.h>
d7e498ac 17# include "crypto/types.h"
c3a4fa4c 18
c6b09ea0
MC
19#define RSA_MIN_MODULUS_BITS 512
20
15671090
RL
21typedef struct rsa_pss_params_30_st {
22 int hash_algorithm_nid;
23 struct {
24 int algorithm_nid; /* Currently always NID_mgf1 */
25 int hash_algorithm_nid;
26 } mask_gen;
6ce6ad39
RL
27 int salt_len;
28 int trailer_field;
15671090
RL
29} RSA_PSS_PARAMS_30;
30
23b2fc0b
P
31RSA_PSS_PARAMS_30 *ossl_rsa_get0_pss_params_30(RSA *r);
32int ossl_rsa_pss_params_30_set_defaults(RSA_PSS_PARAMS_30 *rsa_pss_params);
33int ossl_rsa_pss_params_30_copy(RSA_PSS_PARAMS_30 *to,
34 const RSA_PSS_PARAMS_30 *from);
35int ossl_rsa_pss_params_30_is_unrestricted(const RSA_PSS_PARAMS_30 *rsa_pss_params);
36int ossl_rsa_pss_params_30_set_hashalg(RSA_PSS_PARAMS_30 *rsa_pss_params,
37 int hashalg_nid);
38int ossl_rsa_pss_params_30_set_maskgenalg(RSA_PSS_PARAMS_30 *rsa_pss_params,
39 int maskgenalg_nid);
40int ossl_rsa_pss_params_30_set_maskgenhashalg(RSA_PSS_PARAMS_30 *rsa_pss_params,
41 int maskgenhashalg_nid);
42int ossl_rsa_pss_params_30_set_saltlen(RSA_PSS_PARAMS_30 *rsa_pss_params,
43 int saltlen);
44int ossl_rsa_pss_params_30_set_trailerfield(RSA_PSS_PARAMS_30 *rsa_pss_params,
45 int trailerfield);
46int ossl_rsa_pss_params_30_hashalg(const RSA_PSS_PARAMS_30 *rsa_pss_params);
47int ossl_rsa_pss_params_30_maskgenalg(const RSA_PSS_PARAMS_30 *rsa_pss_params);
48int ossl_rsa_pss_params_30_maskgenhashalg(const RSA_PSS_PARAMS_30 *rsa_pss_params);
49int ossl_rsa_pss_params_30_saltlen(const RSA_PSS_PARAMS_30 *rsa_pss_params);
50int ossl_rsa_pss_params_30_trailerfield(const RSA_PSS_PARAMS_30 *rsa_pss_params);
51
52const char *ossl_rsa_mgf_nid2name(int mgf);
53int ossl_rsa_oaeppss_md2nid(const EVP_MD *md);
54const char *ossl_rsa_oaeppss_nid2name(int md);
55
b4250010
DMSP
56RSA *ossl_rsa_new_with_ctx(OSSL_LIB_CTX *libctx);
57OSSL_LIB_CTX *ossl_rsa_get0_libctx(RSA *r);
6963979f 58void ossl_rsa_set0_libctx(RSA *r, OSSL_LIB_CTX *libctx);
23b2fc0b
P
59
60int ossl_rsa_set0_all_params(RSA *r, const STACK_OF(BIGNUM) *primes,
61 const STACK_OF(BIGNUM) *exps,
62 const STACK_OF(BIGNUM) *coeffs);
63int ossl_rsa_get0_all_params(RSA *r, STACK_OF(BIGNUM_const) *primes,
64 STACK_OF(BIGNUM_const) *exps,
65 STACK_OF(BIGNUM_const) *coeffs);
66
67int ossl_rsa_todata(RSA *rsa, OSSL_PARAM_BLD *bld, OSSL_PARAM params[]);
68int ossl_rsa_fromdata(RSA *rsa, const OSSL_PARAM params[]);
69int ossl_rsa_pss_params_30_todata(const RSA_PSS_PARAMS_30 *pss,
70 OSSL_PARAM_BLD *bld, OSSL_PARAM params[]);
71int ossl_rsa_pss_params_30_fromdata(RSA_PSS_PARAMS_30 *pss_params,
bbde8566 72 int *defaults_set,
23b2fc0b 73 const OSSL_PARAM params[],
b4250010 74 OSSL_LIB_CTX *libctx);
cf333799
RL
75int ossl_rsa_set0_pss_params(RSA *r, RSA_PSS_PARAMS *pss);
76int ossl_rsa_pss_get_param_unverified(const RSA_PSS_PARAMS *pss,
77 const EVP_MD **pmd, const EVP_MD **pmgf1md,
78 int *psaltlen, int *ptrailerField);
79RSA_PSS_PARAMS *ossl_rsa_pss_decode(const X509_ALGOR *alg);
80int ossl_rsa_param_decode(RSA *rsa, const X509_ALGOR *alg);
81RSA *ossl_rsa_key_from_pkcs8(const PKCS8_PRIV_KEY_INFO *p8inf,
82 OSSL_LIB_CTX *libctx, const char *propq);
23b2fc0b 83
b4250010 84int ossl_rsa_padding_check_PKCS1_type_2_TLS(OSSL_LIB_CTX *ctx, unsigned char *to,
23b2fc0b
P
85 size_t tlen,
86 const unsigned char *from,
87 size_t flen, int client_version,
88 int alt_version);
b4250010 89int ossl_rsa_padding_add_PKCS1_OAEP_mgf1_ex(OSSL_LIB_CTX *libctx,
23b2fc0b
P
90 unsigned char *to, int tlen,
91 const unsigned char *from, int flen,
92 const unsigned char *param,
93 int plen, const EVP_MD *md,
94 const EVP_MD *mgf1md);
95
96int ossl_rsa_validate_public(const RSA *key);
97int ossl_rsa_validate_private(const RSA *key);
98int ossl_rsa_validate_pairwise(const RSA *key);
12603de6 99
4158b0dc
SL
100int ossl_rsa_verify(int dtype, const unsigned char *m,
101 unsigned int m_len, unsigned char *rm,
102 size_t *prm_len, const unsigned char *sigbuf,
103 size_t siglen, RSA *rsa);
6f4b7663 104
23b2fc0b 105const unsigned char *ossl_rsa_digestinfo_encoding(int md_nid, size_t *len);
6f4b7663 106
23b2fc0b
P
107extern const char *ossl_rsa_mp_factor_names[];
108extern const char *ossl_rsa_mp_exp_names[];
109extern const char *ossl_rsa_mp_coeff_names[];
96ebe52e 110
9ab7fe48
MC
111ASN1_STRING *ossl_rsa_ctx_to_pss_string(EVP_PKEY_CTX *pkctx);
112int ossl_rsa_pss_to_ctx(EVP_MD_CTX *ctx, EVP_PKEY_CTX *pkctx,
113 const X509_ALGOR *sigalg, EVP_PKEY *pkey);
114
4f2271d5 115# if defined(FIPS_MODULE) && !defined(OPENSSL_NO_ACVP_TESTS)
4158b0dc
SL
116int ossl_rsa_acvp_test_gen_params_new(OSSL_PARAM **dst, const OSSL_PARAM src[]);
117void ossl_rsa_acvp_test_gen_params_free(OSSL_PARAM *dst);
4f2271d5 118
4158b0dc
SL
119int ossl_rsa_acvp_test_set_params(RSA *r, const OSSL_PARAM params[]);
120int ossl_rsa_acvp_test_get_params(RSA *r, OSSL_PARAM params[]);
4f2271d5 121typedef struct rsa_acvp_test_st RSA_ACVP_TEST;
4158b0dc 122void ossl_rsa_acvp_test_free(RSA_ACVP_TEST *t);
4f2271d5
SL
123# else
124# define RSA_ACVP_TEST void
125# endif
126
cf333799 127RSA *evp_pkey_get1_RSA_PSS(EVP_PKEY *pkey);
c3a4fa4c 128#endif