9#ifndef BOTAN_P11_RSA_H_
10#define BOTAN_P11_RSA_H_
12#include <botan/p11_types.h>
13#include <botan/p11_object.h>
14#include <botan/pk_keys.h>
15#include <botan/bigint.h>
17#if defined(BOTAN_HAS_RSA)
29 explicit RSA_PublicKeyGenerationProperties(Ulong bits);
32 inline void set_pub_exponent(
const BigInt& pub_exponent = BigInt(0x10001))
34 add_binary(AttributeType::PublicExponent, BigInt::encode(pub_exponent));
37 virtual ~RSA_PublicKeyGenerationProperties() =
default;
46 RSA_PublicKeyImportProperties(
const BigInt& modulus,
const BigInt& pub_exponent);
49 inline const BigInt& modulus()
const
55 inline const BigInt& pub_exponent()
const
57 return m_pub_exponent;
60 virtual ~RSA_PublicKeyImportProperties() =
default;
62 const BigInt m_modulus;
63 const BigInt m_pub_exponent;
67class BOTAN_PUBLIC_API(2,0) PKCS11_RSA_PublicKey :
public Object,
public RSA_PublicKey
77 PKCS11_RSA_PublicKey(Session& session, ObjectHandle handle);
84 PKCS11_RSA_PublicKey(Session& session,
const RSA_PublicKeyImportProperties& pubkey_props);
86 std::unique_ptr<PK_Ops::Encryption>
87 create_encryption_op(RandomNumberGenerator& rng,
88 const std::string& params,
89 const std::string& provider)
const override;
91 std::unique_ptr<PK_Ops::Verification>
92 create_verification_op(
const std::string& params,
93 const std::string& provider)
const override;
104 RSA_PrivateKeyImportProperties(
const BigInt& modulus,
const BigInt& priv_exponent);
107 inline void set_pub_exponent(
const BigInt& pub_exponent)
109 add_binary(AttributeType::PublicExponent, BigInt::encode(pub_exponent));
113 inline void set_prime_1(
const BigInt& prime1)
115 add_binary(AttributeType::Prime1, BigInt::encode(prime1));
119 inline void set_prime_2(
const BigInt& prime2)
121 add_binary(AttributeType::Prime2, BigInt::encode(prime2));
125 inline void set_exponent_1(
const BigInt& exp1)
127 add_binary(AttributeType::Exponent1, BigInt::encode(exp1));
131 inline void set_exponent_2(
const BigInt& exp2)
133 add_binary(AttributeType::Exponent2, BigInt::encode(exp2));
137 inline void set_coefficient(
const BigInt& coeff)
139 add_binary(AttributeType::Coefficient, BigInt::encode(coeff));
143 inline const BigInt& modulus()
const
149 inline const BigInt& priv_exponent()
const
151 return m_priv_exponent;
154 virtual ~RSA_PrivateKeyImportProperties() =
default;
157 const BigInt m_modulus;
158 const BigInt m_priv_exponent;
165 RSA_PrivateKeyGenerationProperties()
169 virtual ~RSA_PrivateKeyGenerationProperties() =
default;
174 public Object,
public Private_Key,
public RSA_PublicKey
180 PKCS11_RSA_PrivateKey(Session& session, ObjectHandle handle);
187 PKCS11_RSA_PrivateKey(Session& session,
const RSA_PrivateKeyImportProperties& priv_key_props);
196 PKCS11_RSA_PrivateKey(Session& session, uint32_t bits,
const RSA_PrivateKeyGenerationProperties& priv_key_props);
199 RSA_PrivateKey export_key()
const;
201 secure_vector<uint8_t> private_key_bits()
const override;
203 std::unique_ptr<PK_Ops::Decryption>
204 create_decryption_op(RandomNumberGenerator& rng,
205 const std::string& params,
206 const std::string& provider)
const override;
208 std::unique_ptr<PK_Ops::Signature>
209 create_signature_op(RandomNumberGenerator& rng,
210 const std::string& params,
211 const std::string& provider)
const override;
214using PKCS11_RSA_KeyPair = std::pair<PKCS11_RSA_PublicKey, PKCS11_RSA_PrivateKey>;
222BOTAN_PUBLIC_API(2,0) PKCS11_RSA_KeyPair generate_rsa_keypair(Session& session, const RSA_PublicKeyGenerationProperties& pub_props,
223 const RSA_PrivateKeyGenerationProperties& priv_props);
int(* final)(unsigned char *, CTX *)
#define BOTAN_PUBLIC_API(maj, min)