Botan
1.11.15
|
#include <rw.h>
Public Member Functions | |
std::string | algo_name () const |
AlgorithmIdentifier | algorithm_identifier () const |
bool | check_key (RandomNumberGenerator &rng, bool) const |
size_t | estimated_strength () const override |
const BigInt & | get_c () const |
const BigInt & | get_d () const |
const BigInt & | get_d1 () const |
const BigInt & | get_d2 () const |
const BigInt & | get_e () const |
const BigInt & | get_n () const |
virtual OID | get_oid () const |
const BigInt & | get_p () const |
const BigInt & | get_q () const |
size_t | max_input_bits () const |
virtual size_t | message_part_size () const |
virtual size_t | message_parts () const |
virtual AlgorithmIdentifier | pkcs8_algorithm_identifier () const |
secure_vector< byte > | pkcs8_private_key () const |
RW_PrivateKey (const AlgorithmIdentifier &alg_id, const secure_vector< byte > &key_bits, RandomNumberGenerator &rng) | |
RW_PrivateKey (RandomNumberGenerator &rng, const BigInt &p, const BigInt &q, const BigInt &e, const BigInt &d=0, const BigInt &n=0) | |
RW_PrivateKey (RandomNumberGenerator &rng, size_t bits, size_t=2) | |
std::vector< byte > | x509_subject_public_key () const |
Protected Member Functions | |
void | gen_check (RandomNumberGenerator &rng) const |
virtual void | load_check (RandomNumberGenerator &rng) const |
void | load_check (RandomNumberGenerator &rng) const |
Protected Attributes | |
BigInt | c |
BigInt | d |
BigInt | d1 |
BigInt | d2 |
BigInt | e |
BigInt | n |
BigInt | p |
BigInt | q |
Botan::RW_PrivateKey::RW_PrivateKey | ( | const AlgorithmIdentifier & | alg_id, |
const secure_vector< byte > & | key_bits, | ||
RandomNumberGenerator & | rng | ||
) | [inline] |
Definition at line 43 of file rw.h.
: IF_Scheme_PrivateKey(rng, alg_id, key_bits) {}
Botan::RW_PrivateKey::RW_PrivateKey | ( | RandomNumberGenerator & | rng, |
const BigInt & | p, | ||
const BigInt & | q, | ||
const BigInt & | e, | ||
const BigInt & | d = 0 , |
||
const BigInt & | n = 0 |
||
) | [inline] |
Botan::RW_PrivateKey::RW_PrivateKey | ( | RandomNumberGenerator & | rng, |
size_t | bits, | ||
size_t | exp = 2 |
||
) |
Definition at line 22 of file rw.cpp.
References Botan::RW_PublicKey::algo_name(), Botan::BigInt::bits(), Botan::IF_Scheme_PrivateKey::c, Botan::IF_Scheme_PrivateKey::d, Botan::IF_Scheme_PrivateKey::d1, Botan::IF_Scheme_PrivateKey::d2, Botan::IF_Scheme_PublicKey::e, Botan::Private_Key::gen_check(), Botan::inverse_mod(), Botan::lcm(), Botan::IF_Scheme_PublicKey::n, Botan::IF_Scheme_PrivateKey::p, Botan::IF_Scheme_PrivateKey::q, Botan::random_prime(), and Botan::ASN1::to_string().
{ if(bits < 1024) throw Invalid_Argument(algo_name() + ": Can't make a key that is only " + std::to_string(bits) + " bits long"); if(exp < 2 || exp % 2 == 1) throw Invalid_Argument(algo_name() + ": Invalid encryption exponent"); e = exp; do { p = random_prime(rng, (bits + 1) / 2, e / 2, 3, 4); q = random_prime(rng, bits - p.bits(), e / 2, ((p % 8 == 3) ? 7 : 3), 8); n = p * q; } while(n.bits() != bits); d = inverse_mod(e, lcm(p - 1, q - 1) >> 1); d1 = d % (p - 1); d2 = d % (q - 1); c = inverse_mod(q, p); gen_check(rng); }
std::string Botan::RW_PublicKey::algo_name | ( | ) | const [inline, virtual, inherited] |
Get the name of the underlying public key scheme.
Implements Botan::Public_Key.
Definition at line 21 of file rw.h.
Referenced by RW_PrivateKey().
{ return "RW"; }
AlgorithmIdentifier Botan::IF_Scheme_PublicKey::algorithm_identifier | ( | ) | const [virtual, inherited] |
Implements Botan::Public_Key.
Definition at line 21 of file if_algo.cpp.
References Botan::Public_Key::get_oid(), and Botan::AlgorithmIdentifier::USE_NULL_PARAM.
{ return AlgorithmIdentifier(get_oid(), AlgorithmIdentifier::USE_NULL_PARAM); }
bool Botan::RW_PrivateKey::check_key | ( | RandomNumberGenerator & | rng, |
bool | strong | ||
) | const [virtual] |
Test the key values for consistency.
rng | rng to use |
strong | whether to perform strong and lengthy version of the test |
Reimplemented from Botan::IF_Scheme_PrivateKey.
Definition at line 51 of file rw.cpp.
References Botan::IF_Scheme_PrivateKey::check_key(), Botan::IF_Scheme_PrivateKey::d, Botan::IF_Scheme_PublicKey::e, Botan::lcm(), Botan::IF_Scheme_PrivateKey::p, Botan::IF_Scheme_PrivateKey::q, and Botan::KeyPair::signature_consistency_check().
{ if(!IF_Scheme_PrivateKey::check_key(rng, strong)) return false; if(!strong) return true; if((e * d) % (lcm(p - 1, q - 1) / 2) != 1) return false; return KeyPair::signature_consistency_check(rng, *this, "EMSA2(SHA-1)"); }
size_t Botan::IF_Scheme_PublicKey::estimated_strength | ( | ) | const [override, virtual, inherited] |
Return the estimated strength of the underlying key against the best currently known attack. Note that this ignores anything but pure attacks against the key itself and do not take into account padding schemes, usage mistakes, etc which might reduce the strength. However it does suffice to provide an upper bound.
Implements Botan::Public_Key.
Definition at line 16 of file if_algo.cpp.
References Botan::BigInt::bits(), Botan::dl_work_factor(), and Botan::IF_Scheme_PublicKey::n.
{ return dl_work_factor(n.bits()); }
void Botan::Private_Key::gen_check | ( | RandomNumberGenerator & | rng | ) | const [protected, inherited] |
Self-test after generating a key
rng | a random number generator |
Definition at line 49 of file pk_keys.cpp.
References Botan::Public_Key::algo_name(), and Botan::Public_Key::check_key().
Referenced by Botan::DH_PrivateKey::DH_PrivateKey(), Botan::DSA_PrivateKey::DSA_PrivateKey(), Botan::ElGamal_PrivateKey::ElGamal_PrivateKey(), Botan::NR_PrivateKey::NR_PrivateKey(), Botan::RSA_PrivateKey::RSA_PrivateKey(), and RW_PrivateKey().
const BigInt& Botan::IF_Scheme_PrivateKey::get_c | ( | ) | const [inline, inherited] |
const BigInt& Botan::IF_Scheme_PrivateKey::get_d | ( | ) | const [inline, inherited] |
const BigInt& Botan::IF_Scheme_PrivateKey::get_d1 | ( | ) | const [inline, inherited] |
const BigInt& Botan::IF_Scheme_PrivateKey::get_d2 | ( | ) | const [inline, inherited] |
const BigInt& Botan::IF_Scheme_PublicKey::get_e | ( | ) | const [inline, inherited] |
const BigInt& Botan::IF_Scheme_PublicKey::get_n | ( | ) | const [inline, inherited] |
OID Botan::Public_Key::get_oid | ( | ) | const [virtual, inherited] |
Get the OID of the underlying public key scheme.
Definition at line 17 of file pk_keys.cpp.
References Botan::Public_Key::algo_name(), and Botan::OIDS::lookup().
Referenced by Botan::DL_Scheme_PublicKey::algorithm_identifier(), Botan::Curve25519_PublicKey::algorithm_identifier(), Botan::IF_Scheme_PublicKey::algorithm_identifier(), Botan::GOST_3410_PublicKey::algorithm_identifier(), Botan::EC_PublicKey::algorithm_identifier(), and Botan::McEliece_PublicKey::algorithm_identifier().
{ try { return OIDS::lookup(algo_name()); } catch(Lookup_Error) { throw Lookup_Error("PK algo " + algo_name() + " has no defined OIDs"); } }
const BigInt& Botan::IF_Scheme_PrivateKey::get_p | ( | ) | const [inline, inherited] |
const BigInt& Botan::IF_Scheme_PrivateKey::get_q | ( | ) | const [inline, inherited] |
void Botan::Public_Key::load_check | ( | RandomNumberGenerator & | rng | ) | const [protected, virtual, inherited] |
Self-test after loading a key
rng | a random number generator |
Reimplemented in Botan::Private_Key.
Definition at line 31 of file pk_keys.cpp.
References Botan::Public_Key::algo_name(), and Botan::Public_Key::check_key().
{ if(!check_key(rng, BOTAN_PUBLIC_KEY_STRONG_CHECKS_ON_LOAD)) throw Invalid_Argument(algo_name() + ": Invalid public key"); }
void Botan::Private_Key::load_check | ( | RandomNumberGenerator & | rng | ) | const [protected, virtual, inherited] |
Self-test after loading a key
rng | a random number generator |
Reimplemented from Botan::Public_Key.
Definition at line 40 of file pk_keys.cpp.
References Botan::Public_Key::algo_name(), and Botan::Public_Key::check_key().
Referenced by Botan::Curve25519_PrivateKey::Curve25519_PrivateKey(), Botan::DH_PrivateKey::DH_PrivateKey(), Botan::DSA_PrivateKey::DSA_PrivateKey(), Botan::ElGamal_PrivateKey::ElGamal_PrivateKey(), Botan::IF_Scheme_PrivateKey::IF_Scheme_PrivateKey(), and Botan::NR_PrivateKey::NR_PrivateKey().
{ if(!check_key(rng, BOTAN_PRIVATE_KEY_STRONG_CHECKS_ON_LOAD)) throw Invalid_Argument(algo_name() + ": Invalid private key"); }
size_t Botan::IF_Scheme_PublicKey::max_input_bits | ( | ) | const [inline, virtual, inherited] |
virtual size_t Botan::Public_Key::message_part_size | ( | ) | const [inline, virtual, inherited] |
Find out the message part size supported by this scheme/key.
Reimplemented in Botan::GOST_3410_PublicKey, Botan::ECDSA_PublicKey, Botan::NR_PublicKey, and Botan::DSA_PublicKey.
Definition at line 67 of file pk_keys.h.
{ return 0; }
virtual size_t Botan::Public_Key::message_parts | ( | ) | const [inline, virtual, inherited] |
Find out the number of message parts supported by this scheme.
Reimplemented in Botan::GOST_3410_PublicKey, Botan::ECDSA_PublicKey, Botan::NR_PublicKey, and Botan::DSA_PublicKey.
Definition at line 61 of file pk_keys.h.
Referenced by Botan::EAC_Signed_Object::check_signature(), Botan::X509_Object::check_signature(), and Botan::choose_sig_format().
{ return 1; }
virtual AlgorithmIdentifier Botan::Private_Key::pkcs8_algorithm_identifier | ( | ) | const [inline, virtual, inherited] |
Reimplemented in Botan::GOST_3410_PrivateKey.
Definition at line 109 of file pk_keys.h.
Referenced by Botan::PKCS8::BER_encode().
{ return algorithm_identifier(); }
secure_vector< byte > Botan::IF_Scheme_PrivateKey::pkcs8_private_key | ( | ) | const [virtual, inherited] |
Implements Botan::Private_Key.
Definition at line 58 of file if_algo.cpp.
References Botan::IF_Scheme_PrivateKey::c, Botan::IF_Scheme_PrivateKey::d, Botan::IF_Scheme_PrivateKey::d1, Botan::IF_Scheme_PrivateKey::d2, Botan::IF_Scheme_PublicKey::e, Botan::DER_Encoder::encode(), Botan::DER_Encoder::end_cons(), Botan::DER_Encoder::get_contents(), Botan::IF_Scheme_PublicKey::n, Botan::IF_Scheme_PrivateKey::p, Botan::IF_Scheme_PrivateKey::q, Botan::SEQUENCE, and Botan::DER_Encoder::start_cons().
std::vector< byte > Botan::IF_Scheme_PublicKey::x509_subject_public_key | ( | ) | const [virtual, inherited] |
Implements Botan::Public_Key.
Definition at line 27 of file if_algo.cpp.
References Botan::IF_Scheme_PublicKey::e, Botan::DER_Encoder::encode(), Botan::DER_Encoder::end_cons(), Botan::DER_Encoder::get_contents_unlocked(), Botan::IF_Scheme_PublicKey::n, Botan::SEQUENCE, and Botan::DER_Encoder::start_cons().
BigInt Botan::IF_Scheme_PrivateKey::c [protected, inherited] |
Definition at line 103 of file if_algo.h.
Referenced by Botan::IF_Scheme_PrivateKey::check_key(), Botan::IF_Scheme_PrivateKey::IF_Scheme_PrivateKey(), Botan::IF_Scheme_PrivateKey::pkcs8_private_key(), Botan::RSA_PrivateKey::RSA_PrivateKey(), and RW_PrivateKey().
BigInt Botan::IF_Scheme_PrivateKey::d [protected, inherited] |
Definition at line 103 of file if_algo.h.
Referenced by Botan::RSA_PrivateKey::check_key(), check_key(), Botan::IF_Scheme_PrivateKey::check_key(), Botan::IF_Scheme_PrivateKey::IF_Scheme_PrivateKey(), Botan::IF_Scheme_PrivateKey::pkcs8_private_key(), Botan::RSA_PrivateKey::RSA_PrivateKey(), and RW_PrivateKey().
BigInt Botan::IF_Scheme_PrivateKey::d1 [protected, inherited] |
Definition at line 103 of file if_algo.h.
Referenced by Botan::IF_Scheme_PrivateKey::check_key(), Botan::IF_Scheme_PrivateKey::IF_Scheme_PrivateKey(), Botan::IF_Scheme_PrivateKey::pkcs8_private_key(), Botan::RSA_PrivateKey::RSA_PrivateKey(), and RW_PrivateKey().
BigInt Botan::IF_Scheme_PrivateKey::d2 [protected, inherited] |
Definition at line 103 of file if_algo.h.
Referenced by Botan::IF_Scheme_PrivateKey::check_key(), Botan::IF_Scheme_PrivateKey::IF_Scheme_PrivateKey(), Botan::IF_Scheme_PrivateKey::pkcs8_private_key(), Botan::RSA_PrivateKey::RSA_PrivateKey(), and RW_PrivateKey().
BigInt Botan::IF_Scheme_PublicKey::e [protected, inherited] |
Definition at line 53 of file if_algo.h.
Referenced by Botan::IF_Scheme_PublicKey::check_key(), Botan::RSA_PrivateKey::check_key(), check_key(), Botan::IF_Scheme_PrivateKey::check_key(), Botan::IF_Scheme_PrivateKey::IF_Scheme_PrivateKey(), Botan::IF_Scheme_PublicKey::IF_Scheme_PublicKey(), Botan::IF_Scheme_PrivateKey::pkcs8_private_key(), Botan::RSA_PrivateKey::RSA_PrivateKey(), RW_PrivateKey(), and Botan::IF_Scheme_PublicKey::x509_subject_public_key().
BigInt Botan::IF_Scheme_PublicKey::n [protected, inherited] |
Definition at line 53 of file if_algo.h.
Referenced by Botan::IF_Scheme_PublicKey::check_key(), Botan::IF_Scheme_PrivateKey::check_key(), Botan::IF_Scheme_PublicKey::estimated_strength(), Botan::IF_Scheme_PrivateKey::IF_Scheme_PrivateKey(), Botan::IF_Scheme_PublicKey::IF_Scheme_PublicKey(), Botan::IF_Scheme_PrivateKey::pkcs8_private_key(), Botan::RSA_PrivateKey::RSA_PrivateKey(), RW_PrivateKey(), and Botan::IF_Scheme_PublicKey::x509_subject_public_key().
BigInt Botan::IF_Scheme_PrivateKey::p [protected, inherited] |
Definition at line 103 of file if_algo.h.
Referenced by Botan::RSA_PrivateKey::check_key(), check_key(), Botan::IF_Scheme_PrivateKey::check_key(), Botan::IF_Scheme_PrivateKey::IF_Scheme_PrivateKey(), Botan::IF_Scheme_PrivateKey::pkcs8_private_key(), Botan::RSA_PrivateKey::RSA_PrivateKey(), and RW_PrivateKey().
BigInt Botan::IF_Scheme_PrivateKey::q [protected, inherited] |
Definition at line 103 of file if_algo.h.
Referenced by Botan::RSA_PrivateKey::check_key(), check_key(), Botan::IF_Scheme_PrivateKey::check_key(), Botan::IF_Scheme_PrivateKey::IF_Scheme_PrivateKey(), Botan::IF_Scheme_PrivateKey::pkcs8_private_key(), Botan::RSA_PrivateKey::RSA_PrivateKey(), and RW_PrivateKey().