diff options
author | lloyd <[email protected]> | 2010-03-04 17:38:59 +0000 |
---|---|---|
committer | lloyd <[email protected]> | 2010-03-04 17:38:59 +0000 |
commit | 788e524d35d01d90c56c825dbf63a96c3c42a32c (patch) | |
tree | 0147300f6b0f6dd2fd1f16e4e8b5b4e55c35c473 /src/pubkey/if_algo | |
parent | e63bcc23c6121245c143b7b026127ebf0be55c22 (diff) |
New IF constructors, simplifies RSA/RW
Diffstat (limited to 'src/pubkey/if_algo')
-rw-r--r-- | src/pubkey/if_algo/if_algo.cpp | 32 | ||||
-rw-r--r-- | src/pubkey/if_algo/if_algo.h | 11 |
2 files changed, 42 insertions, 1 deletions
diff --git a/src/pubkey/if_algo/if_algo.cpp b/src/pubkey/if_algo/if_algo.cpp index e0042fc1a..62f83ff00 100644 --- a/src/pubkey/if_algo/if_algo.cpp +++ b/src/pubkey/if_algo/if_algo.cpp @@ -78,6 +78,38 @@ IF_Scheme_PrivateKey::IF_Scheme_PrivateKey(const AlgorithmIdentifier&, throw Decoding_Error("Unknown PKCS #1 key format version"); } +IF_Scheme_PrivateKey::IF_Scheme_PrivateKey(RandomNumberGenerator& rng, + const BigInt& prime1, + const BigInt& prime2, + const BigInt& exp, + const BigInt& d_exp, + const BigInt& mod) + { + p = prime1; + q = prime2; + e = exp; + d = d_exp; + n = mod; + + if(d == 0) + { + BigInt inv_for_d = lcm(p - 1, q - 1); + if(e.is_even()) + inv_for_d >>= 1; + + d = inverse_mod(e, inv_for_d); + } + + if(n == 0) n = p * q; + if(d1 == 0) d1 = d % (p - 1); + if(d2 == 0) d2 = d % (q - 1); + if(c == 0) c = inverse_mod(q, p); + + core = IF_Core(rng, e, n, d, p, q, d1, d2, c); + + load_check(rng); + } + /* * Algorithm Specific PKCS #8 Initialization Code */ diff --git a/src/pubkey/if_algo/if_algo.h b/src/pubkey/if_algo/if_algo.h index d5e3ce5b3..01e370854 100644 --- a/src/pubkey/if_algo/if_algo.h +++ b/src/pubkey/if_algo/if_algo.h @@ -24,6 +24,9 @@ class BOTAN_DLL IF_Scheme_PublicKey : public virtual Public_Key IF_Scheme_PublicKey(const AlgorithmIdentifier& alg_id, const MemoryRegion<byte>& key_bits); + IF_Scheme_PublicKey(const BigInt& n, const BigInt& e) : + n(n), e(e) {} + bool check_key(RandomNumberGenerator& rng, bool) const; AlgorithmIdentifier algorithm_identifier() const; @@ -59,6 +62,12 @@ class BOTAN_DLL IF_Scheme_PrivateKey : public virtual IF_Scheme_PublicKey, public virtual Private_Key { public: + + IF_Scheme_PrivateKey(RandomNumberGenerator& rng, + const BigInt& prime1, const BigInt& prime2, + const BigInt& exp, const BigInt& d_exp, + const BigInt& mod); + IF_Scheme_PrivateKey(const AlgorithmIdentifier& alg_id, const MemoryRegion<byte>& key_bits); @@ -87,7 +96,7 @@ class BOTAN_DLL IF_Scheme_PrivateKey : public virtual IF_Scheme_PublicKey, protected: IF_Scheme_PrivateKey() {} - virtual void PKCS8_load_hook(RandomNumberGenerator&, bool = false); + void PKCS8_load_hook(RandomNumberGenerator&, bool = false); BigInt d, p, q, d1, d2, c; }; |