9#ifndef BOTAN_P11_RSA_H_
10#define BOTAN_P11_RSA_H_
12#include <botan/bigint.h>
13#include <botan/p11_object.h>
14#include <botan/p11_types.h>
15#include <botan/pk_keys.h>
17#if defined(BOTAN_HAS_RSA)
18 #include <botan/rsa.h>
27 explicit RSA_PublicKeyGenerationProperties(Ulong bits);
30 inline void set_pub_exponent(
const BigInt& pub_exponent = BigInt::from_word(0x10001)) {
31 add_binary(AttributeType::PublicExponent, pub_exponent.serialize());
34 ~RSA_PublicKeyGenerationProperties()
override =
default;
42 RSA_PublicKeyImportProperties(
const BigInt& modulus,
const BigInt& pub_exponent);
45 inline const BigInt& modulus()
const {
return m_modulus; }
48 inline const BigInt& pub_exponent()
const {
return m_pub_exponent; }
50 ~RSA_PublicKeyImportProperties()
override =
default;
53 const BigInt m_modulus;
54 const BigInt m_pub_exponent;
59 public RSA_PublicKey {
68 PKCS11_RSA_PublicKey(Session& session, ObjectHandle handle);
75 PKCS11_RSA_PublicKey(Session& session,
const RSA_PublicKeyImportProperties& pubkey_props);
80 std::unique_ptr<Private_Key> generate_another(RandomNumberGenerator&)
const final {
81 throw Not_Implemented(
"Cannot generate a new PKCS#11 RSA keypair from this public key");
84 std::unique_ptr<PK_Ops::Encryption> create_encryption_op(RandomNumberGenerator& rng,
85 std::string_view params,
86 std::string_view provider)
const override;
88 std::unique_ptr<PK_Ops::Verification> create_verification_op(std::string_view params,
89 std::string_view provider)
const override;
99 RSA_PrivateKeyImportProperties(
const BigInt& modulus,
const BigInt& priv_exponent);
102 inline void set_pub_exponent(
const BigInt& pub_exponent) {
103 add_binary(AttributeType::PublicExponent, pub_exponent.serialize());
107 inline void set_prime_1(
const BigInt& prime1) { add_binary(AttributeType::Prime1, prime1.serialize()); }
110 inline void set_prime_2(
const BigInt& prime2) { add_binary(AttributeType::Prime2, prime2.serialize()); }
113 inline void set_exponent_1(
const BigInt& exp1) { add_binary(AttributeType::Exponent1, exp1.serialize()); }
116 inline void set_exponent_2(
const BigInt& exp2) { add_binary(AttributeType::Exponent2, exp2.serialize()); }
119 inline void set_coefficient(
const BigInt& coeff) { add_binary(AttributeType::Coefficient, coeff.serialize()); }
122 inline const BigInt& modulus()
const {
return m_modulus; }
125 inline const BigInt& priv_exponent()
const {
return m_priv_exponent; }
127 ~RSA_PrivateKeyImportProperties()
override =
default;
130 const BigInt m_modulus;
131 const BigInt m_priv_exponent;
137 RSA_PrivateKeyGenerationProperties() : PrivateKeyProperties(
KeyType::
Rsa) {}
139 ~RSA_PrivateKeyGenerationProperties()
override =
default;
149 public RSA_PublicKey {
154 PKCS11_RSA_PrivateKey(Session& session, ObjectHandle handle);
161 PKCS11_RSA_PrivateKey(Session& session,
const RSA_PrivateKeyImportProperties& priv_key_props);
170 PKCS11_RSA_PrivateKey(Session& session, uint32_t bits,
const RSA_PrivateKeyGenerationProperties& priv_key_props);
173 RSA_PrivateKey export_key()
const;
182 void set_use_software_padding(
bool software_padding) { m_use_software_padding = software_padding; }
184 bool uses_software_padding()
const {
return m_use_software_padding; }
186 secure_vector<uint8_t> private_key_bits()
const override;
188 std::unique_ptr<Public_Key> public_key()
const override;
190 std::unique_ptr<PK_Ops::Decryption> create_decryption_op(RandomNumberGenerator& rng,
191 std::string_view params,
192 std::string_view provider)
const override;
194 std::unique_ptr<PK_Ops::Signature> create_signature_op(RandomNumberGenerator& rng,
195 std::string_view params,
196 std::string_view provider)
const override;
199 bool m_use_software_padding =
false;
204using PKCS11_RSA_KeyPair = std::pair<PKCS11_RSA_PublicKey, PKCS11_RSA_PrivateKey>;
213PKCS11_RSA_KeyPair generate_rsa_keypair(Session& session,
214 const RSA_PublicKeyGenerationProperties& pub_props,
215 const RSA_PrivateKeyGenerationProperties& priv_props);
int(* final)(unsigned char *, CTX *)
#define BOTAN_DIAGNOSTIC_POP
#define BOTAN_DIAGNOSTIC_PUSH
#define BOTAN_DIAGNOSTIC_IGNORE_INHERITED_VIA_DOMINANCE
#define BOTAN_PUBLIC_API(maj, min)