diff options
author | lloyd <[email protected]> | 2008-09-28 22:02:06 +0000 |
---|---|---|
committer | lloyd <[email protected]> | 2008-09-28 22:02:06 +0000 |
commit | 6fd841dc614a77b7a672681606d236e45e308219 (patch) | |
tree | b98b8a76f69dfb80ce69a7b37b45a2818b9b0ec8 /src | |
parent | 3983245c0e72e2056a4323d4cd2852b0338e43ca (diff) |
Add dl_algo and dl_group modules
Diffstat (limited to 'src')
-rw-r--r-- | src/pk/dh/modinfo.txt | 5 | ||||
-rw-r--r-- | src/pk/dl_algo/dl_algo.cpp (renamed from src/dl_algo.cpp) | 0 | ||||
-rw-r--r-- | src/pk/dl_algo/dl_algo.h | 61 | ||||
-rw-r--r-- | src/pk/dl_group/dl_group.cpp (renamed from src/dl_group.cpp) | 0 | ||||
-rw-r--r-- | src/pk/dl_group/dl_group.h | 74 | ||||
-rw-r--r-- | src/pk/dsa/modinfo.txt | 5 | ||||
-rw-r--r-- | src/pk/nr/modinfo.txt | 5 | ||||
-rw-r--r-- | src/pk/rsa/modinfo.txt | 1 | ||||
-rw-r--r-- | src/pk/rw/modinfo.txt | 1 |
9 files changed, 152 insertions, 0 deletions
diff --git a/src/pk/dh/modinfo.txt b/src/pk/dh/modinfo.txt index e3bbe3f32..eed21833d 100644 --- a/src/pk/dh/modinfo.txt +++ b/src/pk/dh/modinfo.txt @@ -8,3 +8,8 @@ load_on auto dh.cpp dh.h </add> + +<requires> +asn1 +dl_algo +</requires> diff --git a/src/dl_algo.cpp b/src/pk/dl_algo/dl_algo.cpp index 2b59a334e..2b59a334e 100644 --- a/src/dl_algo.cpp +++ b/src/pk/dl_algo/dl_algo.cpp diff --git a/src/pk/dl_algo/dl_algo.h b/src/pk/dl_algo/dl_algo.h new file mode 100644 index 000000000..a8d8d1d51 --- /dev/null +++ b/src/pk/dl_algo/dl_algo.h @@ -0,0 +1,61 @@ +/************************************************* +* DL Scheme Header File * +* (C) 1999-2007 Jack Lloyd * +*************************************************/ + +#ifndef BOTAN_DL_ALGO_H__ +#define BOTAN_DL_ALGO_H__ + +#include <botan/dl_group.h> +#include <botan/x509_key.h> +#include <botan/pkcs8.h> +#include <botan/rng.h> + +namespace Botan { + +/************************************************* +* DL Public Key * +*************************************************/ +class BOTAN_DLL DL_Scheme_PublicKey : public virtual Public_Key + { + public: + bool check_key(RandomNumberGenerator& rng, bool) const; + + const DL_Group& get_domain() const { return group; } + const BigInt& get_y() const { return y; } + const BigInt& group_p() const { return group.get_p(); } + const BigInt& group_q() const { return group.get_q(); } + const BigInt& group_g() const { return group.get_g(); } + virtual DL_Group::Format group_format() const = 0; + + X509_Encoder* x509_encoder() const; + X509_Decoder* x509_decoder(); + protected: + BigInt y; + DL_Group group; + private: + virtual void X509_load_hook() {} + }; + +/************************************************* +* DL Private Key * +*************************************************/ +class BOTAN_DLL DL_Scheme_PrivateKey : public virtual DL_Scheme_PublicKey, + public virtual Private_Key + { + public: + bool check_key(RandomNumberGenerator& rng, bool) const; + + const BigInt& get_x() const { return x; } + + PKCS8_Encoder* pkcs8_encoder() const; + PKCS8_Decoder* pkcs8_decoder(RandomNumberGenerator&); + protected: + BigInt x; + private: + virtual void PKCS8_load_hook(RandomNumberGenerator&, bool = false) {} + }; + +} + +#endif diff --git a/src/dl_group.cpp b/src/pk/dl_group/dl_group.cpp index b37bc238c..b37bc238c 100644 --- a/src/dl_group.cpp +++ b/src/pk/dl_group/dl_group.cpp diff --git a/src/pk/dl_group/dl_group.h b/src/pk/dl_group/dl_group.h new file mode 100644 index 000000000..5d4f46e2d --- /dev/null +++ b/src/pk/dl_group/dl_group.h @@ -0,0 +1,74 @@ +/************************************************* +* Discrete Logarithm Group Header File * +* (C) 1999-2008 Jack Lloyd * +*************************************************/ + +#ifndef BOTAN_DL_PARAM_H__ +#define BOTAN_DL_PARAM_H__ + +#include <botan/bigint.h> +#include <botan/data_src.h> + +namespace Botan { + +/************************************************* +* Discrete Logarithm Group * +*************************************************/ +class BOTAN_DLL DL_Group + { + public: + static SecureVector<byte> + generate_dsa_primes(RandomNumberGenerator& rng, + BigInt& p, BigInt& q, + u32bit pbits, u32bit qbits); + + static bool generate_dsa_primes(RandomNumberGenerator& rng, + BigInt& p_out, BigInt& q_out, + u32bit p_bits, u32bit q_bits, + const MemoryRegion<byte>& seed); + + const BigInt& get_p() const; + const BigInt& get_q() const; + const BigInt& get_g() const; + + enum Format { + ANSI_X9_42, + ANSI_X9_57, + PKCS_3, + + DSA_PARAMETERS = ANSI_X9_57, + DH_PARAMETERS = ANSI_X9_42, + X942_DH_PARAMETERS = ANSI_X9_42, + PKCS3_DH_PARAMETERS = PKCS_3 + }; + + enum PrimeType { Strong, Prime_Subgroup, DSA_Kosherizer }; + + bool verify_group(RandomNumberGenerator& rng, bool) const; + + std::string PEM_encode(Format) const; + SecureVector<byte> DER_encode(Format) const; + void BER_decode(DataSource&, Format); + void PEM_decode(DataSource&); + + DL_Group(); + DL_Group(const std::string&); + + DL_Group(RandomNumberGenerator& rng, PrimeType, u32bit, u32bit = 0); + DL_Group(RandomNumberGenerator& rng, const MemoryRegion<byte>&, + u32bit = 1024, u32bit = 0); + + DL_Group(const BigInt& p, const BigInt& g); + DL_Group(const BigInt& p, const BigInt& g, const BigInt& q); + private: + static BigInt make_dsa_generator(const BigInt&, const BigInt&); + + void init_check() const; + void initialize(const BigInt&, const BigInt&, const BigInt&); + bool initialized; + BigInt p, q, g; + }; + +} + +#endif diff --git a/src/pk/dsa/modinfo.txt b/src/pk/dsa/modinfo.txt index 77bb48396..503d9f23a 100644 --- a/src/pk/dsa/modinfo.txt +++ b/src/pk/dsa/modinfo.txt @@ -8,3 +8,8 @@ load_on auto dsa.cpp dsa.h </add> + +<requires> +asn1 +dl_algo +</requires> diff --git a/src/pk/nr/modinfo.txt b/src/pk/nr/modinfo.txt index 4cb1b1bf5..c54631f16 100644 --- a/src/pk/nr/modinfo.txt +++ b/src/pk/nr/modinfo.txt @@ -8,3 +8,8 @@ load_on auto nr.cpp nr.h </add> + +<requires> +asn1 +dl_algo +</requires> diff --git a/src/pk/rsa/modinfo.txt b/src/pk/rsa/modinfo.txt index 8125d7efb..041c01ca9 100644 --- a/src/pk/rsa/modinfo.txt +++ b/src/pk/rsa/modinfo.txt @@ -10,5 +10,6 @@ rsa.h </add> <requires> +asn1 if_algo </requires> diff --git a/src/pk/rw/modinfo.txt b/src/pk/rw/modinfo.txt index dee83c95d..f9989b3b8 100644 --- a/src/pk/rw/modinfo.txt +++ b/src/pk/rw/modinfo.txt @@ -10,5 +10,6 @@ rw.h </add> <requires> +asn1 if_algo </requires> |