diff options
-rw-r--r-- | src/pubkey/nr/nr.cpp | 60 | ||||
-rw-r--r-- | src/pubkey/nr/nr.h | 32 |
2 files changed, 34 insertions, 58 deletions
diff --git a/src/pubkey/nr/nr.cpp b/src/pubkey/nr/nr.cpp index ad4ae78d3..cdcaf3af3 100644 --- a/src/pubkey/nr/nr.cpp +++ b/src/pubkey/nr/nr.cpp @@ -12,6 +12,13 @@ namespace Botan { +NR_PublicKey::NR_PublicKey(const AlgorithmIdentifier& alg_id, + const MemoryRegion<byte>& key_bits) : + DL_Scheme_PublicKey(alg_id, key_bits, DL_Group::ANSI_X9_57) + { + core = NR_Core(group, y); + } + /* * NR_PublicKey Constructor */ @@ -19,14 +26,7 @@ NR_PublicKey::NR_PublicKey(const DL_Group& grp, const BigInt& y1) { group = grp; y = y1; - X509_load_hook(); - } -/* -* Algorithm Specific X.509 Initialization Code -*/ -void NR_PublicKey::X509_load_hook() - { core = NR_Core(group, y); } @@ -39,22 +39,6 @@ SecureVector<byte> NR_PublicKey::verify(const byte sig[], u32bit sig_len) const } /* -* Return the maximum input size in bits -*/ -u32bit NR_PublicKey::max_input_bits() const - { - return (group_q().bits() - 1); - } - -/* -* Return the size of each portion of the sig -*/ -u32bit NR_PublicKey::message_part_size() const - { - return group_q().bytes(); - } - -/* * Create a NR private key */ NR_PrivateKey::NR_PrivateKey(RandomNumberGenerator& rng, @@ -65,30 +49,30 @@ NR_PrivateKey::NR_PrivateKey(RandomNumberGenerator& rng, x = x_arg; if(x == 0) - { x = BigInt::random_integer(rng, 2, group_q() - 1); - PKCS8_load_hook(rng, true); - } - else - PKCS8_load_hook(rng, false); - } -/* -* Algorithm Specific PKCS #8 Initialization Code -*/ -void NR_PrivateKey::PKCS8_load_hook(RandomNumberGenerator& rng, - bool generated) - { - if(y == 0) - y = power_mod(group_g(), x, group_p()); + y = power_mod(group_g(), x, group_p()); + core = NR_Core(group, y, x); - if(generated) + if(x_arg == 0) gen_check(rng); else load_check(rng); } +NR_PrivateKey::NR_PrivateKey(const AlgorithmIdentifier& alg_id, + const MemoryRegion<byte>& key_bits, + RandomNumberGenerator& rng) : + DL_Scheme_PrivateKey(alg_id, key_bits, DL_Group::ANSI_X9_57) + { + y = power_mod(group_g(), x, group_p()); + + core = NR_Core(group, y, x); + + load_check(rng); + } + /* * Nyberg-Rueppel Signature Operation */ diff --git a/src/pubkey/nr/nr.h b/src/pubkey/nr/nr.h index df4d9ec48..1479ef064 100644 --- a/src/pubkey/nr/nr.h +++ b/src/pubkey/nr/nr.h @@ -22,24 +22,21 @@ class BOTAN_DLL NR_PublicKey : public PK_Verifying_with_MR_Key, public: std::string algo_name() const { return "NR"; } - SecureVector<byte> verify(const byte[], u32bit) const; - u32bit max_input_bits() const; + SecureVector<byte> verify(const byte sig[], u32bit sig_len) const; + + u32bit max_input_bits() const { return (group_q().bits() - 1); } DL_Group::Format group_format() const { return DL_Group::ANSI_X9_57; } u32bit message_parts() const { return 2; } - u32bit message_part_size() const; + u32bit message_part_size() const { return group_q().bytes(); } NR_PublicKey(const AlgorithmIdentifier& alg_id, - const MemoryRegion<byte>& key_bits) : - DL_Scheme_PublicKey(alg_id, key_bits, DL_Group::ANSI_X9_57) - { X509_load_hook(); } + const MemoryRegion<byte>& key_bits); - NR_PublicKey(const DL_Group&, const BigInt&); + NR_PublicKey(const DL_Group& group, const BigInt& pub_key); protected: NR_PublicKey() {} NR_Core core; - private: - void X509_load_hook(); }; /* @@ -50,23 +47,18 @@ class BOTAN_DLL NR_PrivateKey : public NR_PublicKey, public virtual DL_Scheme_PrivateKey { public: - SecureVector<byte> sign(const byte[], u32bit, + SecureVector<byte> sign(const byte msg[], u32bit msg_len, RandomNumberGenerator& rng) const; - bool check_key(RandomNumberGenerator& rng, bool) const; + bool check_key(RandomNumberGenerator& rng, bool strong) const; NR_PrivateKey(const AlgorithmIdentifier& alg_id, const MemoryRegion<byte>& key_bits, - RandomNumberGenerator& rng) : - DL_Scheme_PrivateKey(alg_id, key_bits, DL_Group::ANSI_X9_57) - { - PKCS8_load_hook(rng); - } + RandomNumberGenerator& rng); - NR_PrivateKey(RandomNumberGenerator&, const DL_Group&, - const BigInt& = 0); - private: - void PKCS8_load_hook(RandomNumberGenerator&, bool = false); + NR_PrivateKey(RandomNumberGenerator& rng, + const DL_Group& group, + const BigInt& x = 0); }; } |