Botan  1.11.15
src/lib/pubkey/gost_3410/gost_3410.h
Go to the documentation of this file.
00001 /*
00002 * GOST 34.10-2001
00003 * (C) 2007 Falko Strenzke, FlexSecure GmbH
00004 *          Manuel Hartl, FlexSecure GmbH
00005 * (C) 2008-2010 Jack Lloyd
00006 *
00007 * Botan is released under the Simplified BSD License (see license.txt)
00008 */
00009 
00010 #ifndef BOTAN_GOST_3410_KEY_H__
00011 #define BOTAN_GOST_3410_KEY_H__
00012 
00013 #include <botan/ecc_key.h>
00014 
00015 namespace Botan {
00016 
00017 /**
00018 * GOST-34.10 Public Key
00019 */
00020 class BOTAN_DLL GOST_3410_PublicKey : public virtual EC_PublicKey
00021    {
00022    public:
00023 
00024       /**
00025       * Construct a public key from a given public point.
00026       * @param dom_par the domain parameters associated with this key
00027       * @param public_point the public point defining this key
00028       */
00029       GOST_3410_PublicKey(const EC_Group& dom_par,
00030                           const PointGFp& public_point) :
00031          EC_PublicKey(dom_par, public_point) {}
00032 
00033       /**
00034       * Construct from X.509 algorithm id and subject public key bits
00035       */
00036       GOST_3410_PublicKey(const AlgorithmIdentifier& alg_id,
00037                           const secure_vector<byte>& key_bits);
00038 
00039       /**
00040       * Get this keys algorithm name.
00041       * @result this keys algorithm name
00042       */
00043       std::string algo_name() const { return "GOST-34.10"; }
00044 
00045       AlgorithmIdentifier algorithm_identifier() const;
00046 
00047       std::vector<byte> x509_subject_public_key() const;
00048 
00049       /**
00050       * Get the maximum number of bits allowed to be fed to this key.
00051       * This is the bitlength of the order of the base point.
00052 
00053       * @result the maximum number of input bits
00054       */
00055       size_t max_input_bits() const { return domain().get_order().bits(); }
00056 
00057       size_t message_parts() const { return 2; }
00058 
00059       size_t message_part_size() const
00060          { return domain().get_order().bytes(); }
00061 
00062    protected:
00063       GOST_3410_PublicKey() {}
00064    };
00065 
00066 /**
00067 * GOST-34.10 Private Key
00068 */
00069 class BOTAN_DLL GOST_3410_PrivateKey : public GOST_3410_PublicKey,
00070                                        public EC_PrivateKey
00071    {
00072    public:
00073 
00074       GOST_3410_PrivateKey(const AlgorithmIdentifier& alg_id,
00075                            const secure_vector<byte>& key_bits) :
00076          EC_PrivateKey(alg_id, key_bits) {}
00077 
00078       /**
00079       * Generate a new private key
00080       * @param rng a random number generator
00081       * @param domain parameters to used for this key
00082       * @param x the private key; if zero, a new random key is generated
00083       */
00084       GOST_3410_PrivateKey(RandomNumberGenerator& rng,
00085                            const EC_Group& domain,
00086                            const BigInt& x = 0) :
00087          EC_PrivateKey(rng, domain, x) {}
00088 
00089       AlgorithmIdentifier pkcs8_algorithm_identifier() const
00090          { return EC_PublicKey::algorithm_identifier(); }
00091    };
00092 
00093 }
00094 
00095 #endif