diff options
author | lloyd <[email protected]> | 2008-05-24 18:47:11 +0000 |
---|---|---|
committer | lloyd <[email protected]> | 2008-05-24 18:47:11 +0000 |
commit | c4bad5476b30811ad51b1edd3bd873864d423c07 (patch) | |
tree | 94679d6cee3a38da1d64b8f5f671986566ac8a18 /doc/examples | |
parent | ebc67ae27481549a152858f24fff4a7a82ad4e51 (diff) |
Avoid using the global RNG in check_key, instead pass a reference.
Update the examples
Diffstat (limited to 'doc/examples')
-rw-r--r-- | doc/examples/dh.cpp | 7 | ||||
-rw-r--r-- | doc/examples/dsa_kgen.cpp | 7 | ||||
-rw-r--r-- | doc/examples/factor.cpp | 5 | ||||
-rw-r--r-- | doc/examples/pkcs10.cpp | 6 | ||||
-rw-r--r-- | doc/examples/rsa_kgen.cpp | 5 | ||||
-rw-r--r-- | doc/examples/self_sig.cpp | 7 |
6 files changed, 24 insertions, 13 deletions
diff --git a/doc/examples/dh.cpp b/doc/examples/dh.cpp index 17dd29f56..c8e13dbb4 100644 --- a/doc/examples/dh.cpp +++ b/doc/examples/dh.cpp @@ -7,6 +7,7 @@ */ #include <botan/botan.h> #include <botan/dh.h> +#include <botan/libstate.h> using namespace Botan; #include <iostream> @@ -15,11 +16,13 @@ int main() { try { // Alice creates a DH key and sends (the public part) to Bob - DH_PrivateKey private_a(DL_Group("modp/ietf/1024")); + DH_PrivateKey private_a(DL_Group("modp/ietf/1024"), + global_state().prng_reference()); DH_PublicKey public_a = private_a; // Bob gets this // Bob creates a key with a matching group - DH_PrivateKey private_b(public_a.get_domain()); + DH_PrivateKey private_b(public_a.get_domain(), + global_state().prng_reference()); // Bob sends the key back to Alice DH_PublicKey public_b = private_b; // Alice gets this diff --git a/doc/examples/dsa_kgen.cpp b/doc/examples/dsa_kgen.cpp index 3dc55a443..c078d7fa3 100644 --- a/doc/examples/dsa_kgen.cpp +++ b/doc/examples/dsa_kgen.cpp @@ -21,6 +21,7 @@ This file is in the public domain #include <string> #include <botan/botan.h> #include <botan/dsa.h> +#include <botan/libstate.h> using namespace Botan; int main(int argc, char* argv[]) @@ -39,8 +40,10 @@ int main(int argc, char* argv[]) return 1; } - try { - DSA_PrivateKey key(DL_Group("dsa/jce/1024")); + try + { + DSA_PrivateKey key(DL_Group("dsa/jce/1024"), + global_state().prng_reference()); pub << X509::PEM_encode(key); if(argc == 1) diff --git a/doc/examples/factor.cpp b/doc/examples/factor.cpp index 6972ec108..2c9d94fa9 100644 --- a/doc/examples/factor.cpp +++ b/doc/examples/factor.cpp @@ -5,6 +5,7 @@ #include <botan/botan.h> #include <botan/reducer.h> #include <botan/numthry.h> +#include <botan/libstate.h> using namespace Botan; #include <algorithm> @@ -17,7 +18,7 @@ using namespace Botan; BigInt rho(const BigInt& n) { - BigInt x = random_integer(0, n-1); + BigInt x = random_integer(global_state().prng_reference(), 0, n-1); BigInt y = x; BigInt d = 0; @@ -90,7 +91,7 @@ std::vector<BigInt> factorize(const BigInt& n_in) while(n != 1) { - if(is_prime(n)) + if(is_prime(n, global_state().prng_reference())) { factors.push_back(n); break; diff --git a/doc/examples/pkcs10.cpp b/doc/examples/pkcs10.cpp index a4f6efb04..7e374ad72 100644 --- a/doc/examples/pkcs10.cpp +++ b/doc/examples/pkcs10.cpp @@ -11,6 +11,7 @@ This file is in the public domain #include <botan/x509self.h> #include <botan/rsa.h> #include <botan/dsa.h> +#include <botan/libstate.h> using namespace Botan; #include <iostream> @@ -25,8 +26,9 @@ int main(int argc, char* argv[]) return 1; } - try { - RSA_PrivateKey priv_key(1024); + try + { + RSA_PrivateKey priv_key(1024, global_state().prng_reference()); // If you want a DSA key instead of RSA, comment out the above line and // uncomment this one: //DSA_PrivateKey priv_key(DL_Group("dsa/jce/1024")); diff --git a/doc/examples/rsa_kgen.cpp b/doc/examples/rsa_kgen.cpp index e57f60c06..de2ed0db7 100644 --- a/doc/examples/rsa_kgen.cpp +++ b/doc/examples/rsa_kgen.cpp @@ -14,6 +14,7 @@ This file is in the public domain #include <string> #include <botan/botan.h> #include <botan/rsa.h> +#include <botan/libstate.h> using namespace Botan; int main(int argc, char* argv[]) @@ -26,7 +27,7 @@ int main(int argc, char* argv[]) } u32bit bits = std::atoi(argv[1]); - if(bits < 512 || bits > 4096) + if(bits < 1024 || bits > 4096) { std::cout << "Invalid argument for bitsize" << std::endl; return 1; @@ -42,7 +43,7 @@ int main(int argc, char* argv[]) try { - RSA_PrivateKey key(bits); + RSA_PrivateKey key(bits, global_state().prng_reference()); pub << X509::PEM_encode(key); if(argc == 2) diff --git a/doc/examples/self_sig.cpp b/doc/examples/self_sig.cpp index d00bcb3b4..c2118be40 100644 --- a/doc/examples/self_sig.cpp +++ b/doc/examples/self_sig.cpp @@ -13,6 +13,7 @@ This file is in the public domain #include <botan/x509self.h> #include <botan/rsa.h> #include <botan/dsa.h> +#include <botan/libstate.h> using namespace Botan; #include <iostream> @@ -39,9 +40,9 @@ int main(int argc, char* argv[]) return 1; } - try { - RSA_PrivateKey key(1024); - //DSA_PrivateKey key(DL_Group("dsa/jce/1024")); + try + { + RSA_PrivateKey key(1024, global_state().prng_reference()); std::ofstream priv_key("private.pem"); priv_key << PKCS8::PEM_encode(key, argv[1]); |