diff options
Diffstat (limited to 'doc/examples')
-rw-r--r-- | doc/examples/ca.cpp | 6 | ||||
-rw-r--r-- | doc/examples/dh.cpp | 3 | ||||
-rw-r--r-- | doc/examples/dsa_kgen.cpp | 4 | ||||
-rw-r--r-- | doc/examples/dsa_sign.cpp | 15 | ||||
-rw-r--r-- | doc/examples/dsa_ver.cpp | 17 | ||||
-rw-r--r-- | doc/examples/encrypt.cpp | 3 | ||||
-rw-r--r-- | doc/examples/factor.cpp | 3 | ||||
-rw-r--r-- | doc/examples/passhash.cpp | 3 | ||||
-rw-r--r-- | doc/examples/pkcs10.cpp | 4 | ||||
-rw-r--r-- | doc/examples/rsa_dec.cpp | 8 | ||||
-rw-r--r-- | doc/examples/rsa_enc.cpp | 6 | ||||
-rw-r--r-- | doc/examples/rsa_kgen.cpp | 4 | ||||
-rw-r--r-- | doc/examples/self_sig.cpp | 4 |
13 files changed, 50 insertions, 30 deletions
diff --git a/doc/examples/ca.cpp b/doc/examples/ca.cpp index 0bcb9a38e..d0fd32d17 100644 --- a/doc/examples/ca.cpp +++ b/doc/examples/ca.cpp @@ -38,7 +38,8 @@ int main(int argc, char* argv[]) const std::string arg_ca_key = argv[3]; const std::string arg_req_file = argv[4]; - std::auto_ptr<RandomNumberGenerator> rng(make_rng()); + std::auto_ptr<RandomNumberGenerator> rng( + RandomNumberGenerator::make_rng()); X509_Certificate ca_cert(arg_ca_cert); @@ -58,7 +59,8 @@ int main(int argc, char* argv[]) X509_Time start_time(system_time()); X509_Time end_time(system_time() + 365 * 60 * 60 * 24); - X509_Certificate new_cert = ca.sign_request(req, *rng, start_time, end_time); + X509_Certificate new_cert = ca.sign_request(req, *rng, + start_time, end_time); // send the new cert back to the requestor std::cout << new_cert.PEM_encode(); diff --git a/doc/examples/dh.cpp b/doc/examples/dh.cpp index 1957215bc..f2a43e7f6 100644 --- a/doc/examples/dh.cpp +++ b/doc/examples/dh.cpp @@ -17,7 +17,8 @@ int main() { try { - std::auto_ptr<RandomNumberGenerator> rng(make_rng()); + std::auto_ptr<RandomNumberGenerator> rng( + RandomNumberGenerator::make_rng()); // Alice creates a DH key and sends (the public part) to Bob DH_PrivateKey private_a(*rng, DL_Group("modp/ietf/1024")); diff --git a/doc/examples/dsa_kgen.cpp b/doc/examples/dsa_kgen.cpp index 0a380cd9e..2a66d90a3 100644 --- a/doc/examples/dsa_kgen.cpp +++ b/doc/examples/dsa_kgen.cpp @@ -44,7 +44,9 @@ int main(int argc, char* argv[]) try { - std::auto_ptr<RandomNumberGenerator> rng(make_rng()); + std::auto_ptr<RandomNumberGenerator> rng( + RandomNumberGenerator::make_rng()); + DSA_PrivateKey key(*rng, DL_Group("dsa/jce/1024")); pub << X509::PEM_encode(key); diff --git a/doc/examples/dsa_sign.cpp b/doc/examples/dsa_sign.cpp index 67800497e..b45bd9d70 100644 --- a/doc/examples/dsa_sign.cpp +++ b/doc/examples/dsa_sign.cpp @@ -48,7 +48,8 @@ int main(int argc, char* argv[]) return 1; } - std::auto_ptr<RandomNumberGenerator> rng(make_rng()); + std::auto_ptr<RandomNumberGenerator> rng( + RandomNumberGenerator::make_rng()); std::auto_ptr<PKCS8_PrivateKey> key( PKCS8::load_key(argv[1], *rng, passphrase) @@ -62,13 +63,15 @@ int main(int argc, char* argv[]) return 1; } - Pipe pipe(new PK_Signer_Filter(get_pk_signer(*dsakey, "EMSA1(SHA-1)")), - new Base64_Encoder); + PK_Signer signer(*dsakey, "EMSA1(SHA-1)"); - pipe.start_msg(); - message >> pipe; - pipe.end_msg(); + DataSource_Stream in(message); + byte buf[4096] = { 0 }; + while(u32bit got = in.read(buf, sizeof(buf))) + signer.update(buf, got); + Pipe pipe(new Base64_Encoder); + pipe.process_msg(signer.signature(*rng)); sigfile << pipe.read_all_as_string() << std::endl; } catch(std::exception& e) diff --git a/doc/examples/dsa_ver.cpp b/doc/examples/dsa_ver.cpp index 155fbe894..90af8d68f 100644 --- a/doc/examples/dsa_ver.cpp +++ b/doc/examples/dsa_ver.cpp @@ -67,19 +67,16 @@ int main(int argc, char* argv[]) SecureVector<byte> sig = b64_decode(sigstr); - Pipe pipe(new PK_Verifier_Filter( - get_pk_verifier(*dsakey, "EMSA1(SHA-1)"), sig - ) - ); + std::auto_ptr<PK_Verifier> ver(get_pk_verifier(*dsakey, "EMSA1(SHA-1)")); - pipe.start_msg(); - message >> pipe; - pipe.end_msg(); + DataSource_Stream in(message); + byte buf[4096] = { 0 }; + while(u32bit got = in.read(buf, sizeof(buf))) + ver->update(buf, got); - byte result = 0; - pipe.read(result); + bool ok = ver->check_signature(sig); - if(result) + if(ok) std::cout << "Signature verified\n"; else std::cout << "Signature did NOT verify\n"; diff --git a/doc/examples/encrypt.cpp b/doc/examples/encrypt.cpp index 8d0636c35..e5245cd5d 100644 --- a/doc/examples/encrypt.cpp +++ b/doc/examples/encrypt.cpp @@ -121,7 +121,8 @@ int main(int argc, char* argv[]) const u32bit key_len = max_keylength_of(algo); const u32bit iv_len = block_size_of(algo); - std::auto_ptr<RandomNumberGenerator> rng(make_rng()); + std::auto_ptr<RandomNumberGenerator> rng( + RandomNumberGenerator::make_rng()); std::auto_ptr<S2K> s2k(get_s2k("PBKDF2(SHA-1)")); s2k->set_iterations(8192); diff --git a/doc/examples/factor.cpp b/doc/examples/factor.cpp index 63bd1b00f..c3a46a6ba 100644 --- a/doc/examples/factor.cpp +++ b/doc/examples/factor.cpp @@ -123,7 +123,8 @@ int main(int argc, char* argv[]) { BigInt n(argv[1]); - std::auto_ptr<RandomNumberGenerator> rng(make_rng()); + std::auto_ptr<RandomNumberGenerator> rng( + RandomNumberGenerator::make_rng()); std::vector<BigInt> factors = factorize(n, *rng); std::sort(factors.begin(), factors.end()); diff --git a/doc/examples/passhash.cpp b/doc/examples/passhash.cpp index 00fd9affa..6df4a4e1d 100644 --- a/doc/examples/passhash.cpp +++ b/doc/examples/passhash.cpp @@ -23,7 +23,8 @@ int main(int argc, char* argv[]) if(argc == 2) { - std::auto_ptr<RandomNumberGenerator> rng(make_rng()); + std::auto_ptr<RandomNumberGenerator> rng( + RandomNumberGenerator::make_rng()); std::cout << "H('" << argv[1] << "') = " << password_hash(argv[1], *rng) << '\n'; diff --git a/doc/examples/pkcs10.cpp b/doc/examples/pkcs10.cpp index fd3ea0e1d..3983d5891 100644 --- a/doc/examples/pkcs10.cpp +++ b/doc/examples/pkcs10.cpp @@ -28,7 +28,9 @@ int main(int argc, char* argv[]) try { - std::auto_ptr<RandomNumberGenerator> rng(make_rng()); + std::auto_ptr<RandomNumberGenerator> rng( + RandomNumberGenerator::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: diff --git a/doc/examples/rsa_dec.cpp b/doc/examples/rsa_dec.cpp index 910d07adf..ca93756f2 100644 --- a/doc/examples/rsa_dec.cpp +++ b/doc/examples/rsa_dec.cpp @@ -34,8 +34,12 @@ int main(int argc, char* argv[]) try { - std::auto_ptr<RandomNumberGenerator> rng(make_rng()); - std::auto_ptr<PKCS8_PrivateKey> key(PKCS8::load_key(argv[1], *rng, argv[3])); + std::auto_ptr<RandomNumberGenerator> rng( + RandomNumberGenerator::make_rng()); + + std::auto_ptr<PKCS8_PrivateKey> key( + PKCS8::load_key(argv[1], *rng, argv[3])); + RSA_PrivateKey* rsakey = dynamic_cast<RSA_PrivateKey*>(key.get()); if(!rsakey) { diff --git a/doc/examples/rsa_enc.cpp b/doc/examples/rsa_enc.cpp index e0127d63f..aebe42e72 100644 --- a/doc/examples/rsa_enc.cpp +++ b/doc/examples/rsa_enc.cpp @@ -73,7 +73,8 @@ int main(int argc, char* argv[]) return 1; } - std::auto_ptr<RandomNumberGenerator> rng(make_rng()); + std::auto_ptr<RandomNumberGenerator> rng( + RandomNumberGenerator::make_rng()); std::auto_ptr<PK_Encryptor> encryptor(get_pk_encryptor(*rsakey, "EME1(SHA-1)")); @@ -89,7 +90,8 @@ int main(int argc, char* argv[]) statistically indepedent. Practically speaking I don't think this is a problem. */ - SymmetricKey masterkey(*rng, std::min(32U, encryptor->maximum_input_size())); + SymmetricKey masterkey(*rng, + std::min(32U, encryptor->maximum_input_size())); SymmetricKey cast_key = derive_key("CAST", masterkey, 16); SymmetricKey mac_key = derive_key("MAC", masterkey, 16); diff --git a/doc/examples/rsa_kgen.cpp b/doc/examples/rsa_kgen.cpp index 7230e7a4a..c3942971b 100644 --- a/doc/examples/rsa_kgen.cpp +++ b/doc/examples/rsa_kgen.cpp @@ -45,7 +45,9 @@ int main(int argc, char* argv[]) try { - std::auto_ptr<RandomNumberGenerator> rng(make_rng()); + std::auto_ptr<RandomNumberGenerator> rng( + RandomNumberGenerator::make_rng()); + RSA_PrivateKey key(*rng, bits); pub << X509::PEM_encode(key); diff --git a/doc/examples/self_sig.cpp b/doc/examples/self_sig.cpp index 91aa4b2ea..42a58b485 100644 --- a/doc/examples/self_sig.cpp +++ b/doc/examples/self_sig.cpp @@ -42,7 +42,9 @@ int main(int argc, char* argv[]) try { - std::auto_ptr<RandomNumberGenerator> rng(make_rng()); + std::auto_ptr<RandomNumberGenerator> rng( + RandomNumberGenerator::make_rng()); + RSA_PrivateKey key(*rng, 1024); std::ofstream priv_key("private.pem"); |