Botan  1.11.15
src/lib/pubkey/dl_algo/dl_algo.h
Go to the documentation of this file.
00001 /*
00002 * DL 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_DL_ALGO_H__
00009 #define BOTAN_DL_ALGO_H__
00010 
00011 #include <botan/dl_group.h>
00012 #include <botan/x509_key.h>
00013 #include <botan/pkcs8.h>
00014 
00015 namespace Botan {
00016 
00017 /**
00018 * This class represents discrete logarithm (DL) public keys.
00019 */
00020 class BOTAN_DLL DL_Scheme_PublicKey : public virtual Public_Key
00021    {
00022    public:
00023       bool check_key(RandomNumberGenerator& rng, bool) const;
00024 
00025       AlgorithmIdentifier algorithm_identifier() const;
00026 
00027       std::vector<byte> x509_subject_public_key() const;
00028 
00029       /**
00030       * Get the DL domain parameters of this key.
00031       * @return DL domain parameters of this key
00032       */
00033       const DL_Group& get_domain() const { return group; }
00034 
00035       /**
00036       * Get the public value y with y = g^x mod p where x is the secret key.
00037       */
00038       const BigInt& get_y() const { return y; }
00039 
00040       /**
00041       * Get the prime p of the underlying DL group.
00042       * @return prime p
00043       */
00044       const BigInt& group_p() const { return group.get_p(); }
00045 
00046       /**
00047       * Get the prime q of the underlying DL group.
00048       * @return prime q
00049       */
00050       const BigInt& group_q() const { return group.get_q(); }
00051 
00052       /**
00053       * Get the generator g of the underlying DL group.
00054       * @return generator g
00055       */
00056       const BigInt& group_g() const { return group.get_g(); }
00057 
00058       /**
00059       * Get the underlying groups encoding format.
00060       * @return encoding format
00061       */
00062       virtual DL_Group::Format group_format() const = 0;
00063 
00064       size_t estimated_strength() const override;
00065 
00066       DL_Scheme_PublicKey(const AlgorithmIdentifier& alg_id,
00067                           const secure_vector<byte>& key_bits,
00068                           DL_Group::Format group_format);
00069 
00070    protected:
00071       DL_Scheme_PublicKey() {}
00072 
00073       /**
00074       * The DL public key
00075       */
00076       BigInt y;
00077 
00078       /**
00079       * The DL group
00080       */
00081       DL_Group group;
00082    };
00083 
00084 /**
00085 * This class represents discrete logarithm (DL) private keys.
00086 */
00087 class BOTAN_DLL DL_Scheme_PrivateKey : public virtual DL_Scheme_PublicKey,
00088                                        public virtual Private_Key
00089    {
00090    public:
00091       bool check_key(RandomNumberGenerator& rng, bool) const;
00092 
00093       /**
00094       * Get the secret key x.
00095       * @return secret key
00096       */
00097       const BigInt& get_x() const { return x; }
00098 
00099       secure_vector<byte> pkcs8_private_key() const;
00100 
00101       DL_Scheme_PrivateKey(const AlgorithmIdentifier& alg_id,
00102                            const secure_vector<byte>& key_bits,
00103                            DL_Group::Format group_format);
00104 
00105    protected:
00106       DL_Scheme_PrivateKey() {}
00107 
00108       /**
00109       * The DL private key
00110       */
00111       BigInt x;
00112    };
00113 
00114 }
00115 
00116 #endif