Botan  1.11.15
src/lib/pubkey/if_algo/if_algo.h
Go to the documentation of this file.
00001 /*
00002 * IF Scheme
00003 * (C) 1999-2007 Jack Lloyd
00004 *
00005 * Botan is released under the Simplified BSD License (see license.txt)
00006 */
00007 
00008 #ifndef BOTAN_IF_ALGO_H__
00009 #define BOTAN_IF_ALGO_H__
00010 
00011 #include <botan/bigint.h>
00012 #include <botan/x509_key.h>
00013 #include <botan/pkcs8.h>
00014 
00015 namespace Botan {
00016 
00017 /**
00018 * This class represents public keys
00019 * of integer factorization based (IF) public key schemes.
00020 */
00021 class BOTAN_DLL IF_Scheme_PublicKey : public virtual Public_Key
00022    {
00023    public:
00024       IF_Scheme_PublicKey(const AlgorithmIdentifier& alg_id,
00025                           const secure_vector<byte>& key_bits);
00026 
00027       IF_Scheme_PublicKey(const BigInt& n, const BigInt& e) :
00028          n(n), e(e) {}
00029 
00030       bool check_key(RandomNumberGenerator& rng, bool) const;
00031 
00032       AlgorithmIdentifier algorithm_identifier() const;
00033 
00034       std::vector<byte> x509_subject_public_key() const;
00035 
00036       /**
00037       * @return public modulus
00038       */
00039       const BigInt& get_n() const { return n; }
00040 
00041       /**
00042       * @return public exponent
00043       */
00044       const BigInt& get_e() const { return e; }
00045 
00046       size_t max_input_bits() const { return (n.bits() - 1); }
00047 
00048       size_t estimated_strength() const override;
00049 
00050    protected:
00051       IF_Scheme_PublicKey() {}
00052 
00053       BigInt n, e;
00054    };
00055 
00056 /**
00057 * This class represents public keys
00058 * of integer factorization based (IF) public key schemes.
00059 */
00060 class BOTAN_DLL IF_Scheme_PrivateKey : public virtual IF_Scheme_PublicKey,
00061                                        public virtual Private_Key
00062    {
00063    public:
00064 
00065       IF_Scheme_PrivateKey(RandomNumberGenerator& rng,
00066                            const BigInt& prime1, const BigInt& prime2,
00067                            const BigInt& exp, const BigInt& d_exp,
00068                            const BigInt& mod);
00069 
00070       IF_Scheme_PrivateKey(RandomNumberGenerator& rng,
00071                            const AlgorithmIdentifier& alg_id,
00072                            const secure_vector<byte>& key_bits);
00073 
00074       bool check_key(RandomNumberGenerator& rng, bool) const;
00075 
00076       /**
00077       * Get the first prime p.
00078       * @return prime p
00079       */
00080       const BigInt& get_p() const { return p; }
00081 
00082       /**
00083       * Get the second prime q.
00084       * @return prime q
00085       */
00086       const BigInt& get_q() const { return q; }
00087 
00088       /**
00089       * Get d with exp * d = 1 mod (p - 1, q - 1).
00090       * @return d
00091       */
00092       const BigInt& get_d() const { return d; }
00093 
00094       const BigInt& get_c() const { return c; }
00095       const BigInt& get_d1() const { return d1; }
00096       const BigInt& get_d2() const { return d2; }
00097 
00098       secure_vector<byte> pkcs8_private_key() const;
00099 
00100    protected:
00101       IF_Scheme_PrivateKey() {}
00102 
00103       BigInt d, p, q, d1, d2, c;
00104    };
00105 
00106 }
00107 
00108 #endif