aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--doc/examples/passhash.cpp17
-rw-r--r--doc/examples/pkcs10.cpp8
2 files changed, 16 insertions, 9 deletions
diff --git a/doc/examples/passhash.cpp b/doc/examples/passhash.cpp
index f8bac1443..00fd9affa 100644
--- a/doc/examples/passhash.cpp
+++ b/doc/examples/passhash.cpp
@@ -1,11 +1,12 @@
#include <botan/botan.h>
#include <botan/pkcs5.h>
-#include <botan/libstate.h>
#include <iostream>
+#include <memory>
using namespace Botan;
-std::string password_hash(const std::string& pass);
+std::string password_hash(const std::string& pass,
+ RandomNumberGenerator& rng);
bool password_hash_ok(const std::string& pass, const std::string& hash);
int main(int argc, char* argv[])
@@ -19,9 +20,14 @@ int main(int argc, char* argv[])
try
{
+
if(argc == 2)
+ {
+ std::auto_ptr<RandomNumberGenerator> rng(make_rng());
+
std::cout << "H('" << argv[1] << "') = "
- << password_hash(argv[1]) << '\n';
+ << password_hash(argv[1], *rng) << '\n';
+ }
else
{
bool ok = password_hash_ok(argv[1], argv[2]);
@@ -39,12 +45,13 @@ int main(int argc, char* argv[])
return 0;
}
-std::string password_hash(const std::string& pass)
+std::string password_hash(const std::string& pass,
+ RandomNumberGenerator& rng)
{
PKCS5_PBKDF2 kdf("SHA-1");
kdf.set_iterations(10000);
- kdf.new_random_salt(global_state().prng_reference(), 6); // 48 bits
+ kdf.new_random_salt(rng, 6); // 48 bits
Pipe pipe(new Base64_Encoder);
pipe.start_msg();
diff --git a/doc/examples/pkcs10.cpp b/doc/examples/pkcs10.cpp
index ae8230186..fd3ea0e1d 100644
--- a/doc/examples/pkcs10.cpp
+++ b/doc/examples/pkcs10.cpp
@@ -11,7 +11,6 @@ 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>
@@ -29,13 +28,14 @@ int main(int argc, char* argv[])
try
{
- RSA_PrivateKey priv_key(1024, global_state().prng_reference());
+ std::auto_ptr<RandomNumberGenerator> rng(make_rng());
+ RSA_PrivateKey priv_key(*rng, 1024);
// 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"));
std::ofstream key_file("private.pem");
- key_file << PKCS8::PEM_encode(priv_key, argv[1]);
+ key_file << PKCS8::PEM_encode(priv_key, *rng, argv[1]);
X509_Cert_Options opts;
@@ -55,7 +55,7 @@ int main(int argc, char* argv[])
opts.xmpp = "[email protected]";
- PKCS10_Request req = X509::create_cert_req(opts, priv_key);
+ PKCS10_Request req = X509::create_cert_req(opts, priv_key, *rng);
std::ofstream req_file("req.pem");
req_file << req.PEM_encode();