diff options
author | lloyd <[email protected]> | 2008-10-08 03:15:34 +0000 |
---|---|---|
committer | lloyd <[email protected]> | 2008-10-08 03:15:34 +0000 |
commit | 8343194ea16297eb3e51627eb3f35c529850c6f8 (patch) | |
tree | 22aeac286d2cbbdbe8790b08e4187d369f3c4efb /doc/examples | |
parent | be5e48619a63559ad777396d69cc8cc95ef0af15 (diff) |
Update examples for recent API changes
Diffstat (limited to 'doc/examples')
-rw-r--r-- | doc/examples/cms_dec.cpp | 8 | ||||
-rw-r--r-- | doc/examples/cms_enc.cpp | 14 | ||||
-rw-r--r-- | doc/examples/eax_test.cpp | 4 | ||||
-rw-r--r-- | doc/examples/ecdsa.cpp | 19 | ||||
-rw-r--r-- | doc/examples/factor.cpp | 2 | ||||
-rw-r--r-- | doc/examples/passhash.cpp | 8 | ||||
-rw-r--r-- | doc/examples/pqg_gen.cpp | 4 | ||||
-rw-r--r-- | doc/examples/ressol.cpp | 2 | ||||
-rw-r--r-- | doc/examples/rng_test.cpp | 4 | ||||
-rw-r--r-- | doc/examples/xor_ciph.cpp | 2 |
10 files changed, 46 insertions, 21 deletions
diff --git a/doc/examples/cms_dec.cpp b/doc/examples/cms_dec.cpp index 593cf2e09..08d43e7b8 100644 --- a/doc/examples/cms_dec.cpp +++ b/doc/examples/cms_dec.cpp @@ -1,7 +1,10 @@ +#include <botan/botan.h> +#include <botan/pkcs8.h> #include <botan/cms_dec.h> using namespace Botan; #include <iostream> +#include <memory> int main(int argc, char* argv[]) { @@ -14,8 +17,11 @@ int main(int argc, char* argv[]) LibraryInitializer init; try { + std::auto_ptr<RandomNumberGenerator> rng( + RandomNumberGenerator::make_rng()); + X509_Certificate mycert("mycert.pem"); - PKCS8_PrivateKey* mykey = PKCS8::load_key("mykey.pem", "cut"); + PKCS8_PrivateKey* mykey = PKCS8::load_key("mykey.pem", *rng, "cut"); X509_Certificate yourcert("yourcert.pem"); X509_Certificate cacert("cacert.pem"); diff --git a/doc/examples/cms_enc.cpp b/doc/examples/cms_enc.cpp index 0319925d8..50babc650 100644 --- a/doc/examples/cms_enc.cpp +++ b/doc/examples/cms_enc.cpp @@ -1,15 +1,16 @@ +#include <botan/botan.h> #include <botan/cms_enc.h> using namespace Botan; #include <iostream> #include <fstream> +#include <memory> int main() { LibraryInitializer init; try { - PKCS8_PrivateKey* mykey = PKCS8::load_key("mykey.pem", "cut"); X509_Certificate mycert("mycert.pem"); X509_Certificate mycert2("mycert2.pem"); @@ -17,6 +18,9 @@ int main() X509_Certificate cacert("cacert.pem"); X509_Certificate int_ca("int_ca.pem"); + std::auto_ptr<RandomNumberGenerator> rng( + RandomNumberGenerator::make_rng()); + X509_Store store; store.add_cert(mycert); store.add_cert(mycert2); @@ -30,13 +34,17 @@ int main() encoder.compress("Zlib"); encoder.digest(); - encoder.encrypt(mycert); + encoder.encrypt(*rng, mycert); + + /* + PKCS8_PrivateKey* mykey = PKCS8::load_key("mykey.pem", *rng, "cut"); encoder.sign(store, *mykey); + */ SecureVector<byte> raw = encoder.get_contents(); std::ofstream out("out.der"); - out.write((const char*)raw.ptr(), raw.size()); + out.write((const char*)raw.begin(), raw.size()); } catch(std::exception& e) { diff --git a/doc/examples/eax_test.cpp b/doc/examples/eax_test.cpp index 3a508ea83..f0e6b8d33 100644 --- a/doc/examples/eax_test.cpp +++ b/doc/examples/eax_test.cpp @@ -48,8 +48,8 @@ void eax_test(const std::string& algo, plaintext_str.c_str(), ciphertext.c_str()); */ - //std::auto_ptr<RandomNumberGenerator> rng( - xRandomNumberGenerator::make_rng()); + std::auto_ptr<RandomNumberGenerator> rng( + RandomNumberGenerator::make_rng()); SymmetricKey key(key_str); InitializationVector iv(nonce_str); diff --git a/doc/examples/ecdsa.cpp b/doc/examples/ecdsa.cpp index 1c1715f1b..83cdad967 100644 --- a/doc/examples/ecdsa.cpp +++ b/doc/examples/ecdsa.cpp @@ -8,13 +8,20 @@ using namespace Botan; int main() { - std::auto_ptr<RandomNumberGenerator> rng(RandomNumberGenerator::make_rng()); + try + { + std::auto_ptr<RandomNumberGenerator> rng( + RandomNumberGenerator::make_rng()); - EC_Domain_Params params = get_EC_Dom_Pars_by_oid("1.3.132.8"); + EC_Domain_Params params = get_EC_Dom_Pars_by_oid("1.3.132.8"); - std::cout << params.get_curve().get_p() << "\n"; - std::cout << params.get_order() << "\n"; - - ECDSA_PrivateKey ecdsa(*rng, params); + std::cout << params.get_curve().get_p() << "\n"; + std::cout << params.get_order() << "\n"; + ECDSA_PrivateKey ecdsa(*rng, params); + } + catch(std::exception& e) + { + std::cout << e.what() << "\n"; + } } diff --git a/doc/examples/factor.cpp b/doc/examples/factor.cpp index c3a46a6ba..cf4d395d0 100644 --- a/doc/examples/factor.cpp +++ b/doc/examples/factor.cpp @@ -18,7 +18,7 @@ using namespace Botan; BigInt rho(const BigInt& n, RandomNumberGenerator& rng) { - BigInt x = random_integer(rng, 0, n-1); + BigInt x = BigInt::random_integer(rng, 0, n-1); BigInt y = x; BigInt d = 0; diff --git a/doc/examples/passhash.cpp b/doc/examples/passhash.cpp index 6df4a4e1d..78ced1c66 100644 --- a/doc/examples/passhash.cpp +++ b/doc/examples/passhash.cpp @@ -1,5 +1,7 @@ #include <botan/botan.h> -#include <botan/pkcs5.h> +#include <botan/pbkdf2.h> +#include <botan/hmac.h> +#include <botan/sha160.h> #include <iostream> #include <memory> @@ -49,7 +51,7 @@ int main(int argc, char* argv[]) std::string password_hash(const std::string& pass, RandomNumberGenerator& rng) { - PKCS5_PBKDF2 kdf("SHA-1"); + PKCS5_PBKDF2 kdf(new HMAC(new SHA_160)); kdf.set_iterations(10000); kdf.new_random_salt(rng, 6); // 48 bits @@ -72,7 +74,7 @@ bool password_hash_ok(const std::string& pass, const std::string& hash) SecureVector<byte> hash_bin = pipe.read_all(); - PKCS5_PBKDF2 kdf("SHA-1"); + PKCS5_PBKDF2 kdf(new HMAC(new SHA_160)); kdf.set_iterations(10000); kdf.change_salt(hash_bin, 6); diff --git a/doc/examples/pqg_gen.cpp b/doc/examples/pqg_gen.cpp index 328dc785e..8683cb2df 100644 --- a/doc/examples/pqg_gen.cpp +++ b/doc/examples/pqg_gen.cpp @@ -97,8 +97,8 @@ bool check(RandomNumberGenerator& rng, u32bit qbits = (p.bits() <= 1024) ? 160 : 256; - bool found = DL_Group::generate_dsa_primes(rng, our_p, our_q, - p.bits(), qbits, seed); + bool found = generate_dsa_primes(rng, our_p, our_q, + p.bits(), qbits, seed); if(!found) /* bad seed */ return false; diff --git a/doc/examples/ressol.cpp b/doc/examples/ressol.cpp index 9fedc8115..ff49ef19d 100644 --- a/doc/examples/ressol.cpp +++ b/doc/examples/ressol.cpp @@ -14,7 +14,7 @@ void test_ressol(const BigInt& p, RandomNumberGenerator& rng) for(int j = 0; j != 1000; ++j) { - BigInt x = random_integer(rng, 0, p); + BigInt x = BigInt::random_integer(rng, 0, p); //if(x % p_16 == 0) //std::cout << "p = " << p << " x = " << x << "\n"; diff --git a/doc/examples/rng_test.cpp b/doc/examples/rng_test.cpp index caefba6cd..e38628d15 100644 --- a/doc/examples/rng_test.cpp +++ b/doc/examples/rng_test.cpp @@ -1,6 +1,7 @@ #include <botan/botan.h> #include <botan/x931_rng.h> #include <botan/filters.h> +#include <botan/lookup.h> #include <iostream> #include <fstream> @@ -79,7 +80,8 @@ void x931_tests(std::vector<std::pair<std::string, std::string> > vecs, const std::string result = vecs[j].first; const std::string input = vecs[j].second; - ANSI_X931_RNG prng(cipher, new Fixed_Output_RNG); + ANSI_X931_RNG prng(get_block_cipher(cipher), + new Fixed_Output_RNG); SecureVector<byte> x = decode_hex(input); prng.add_entropy(x.begin(), x.size()); diff --git a/doc/examples/xor_ciph.cpp b/doc/examples/xor_ciph.cpp index 496d23323..a8632911c 100644 --- a/doc/examples/xor_ciph.cpp +++ b/doc/examples/xor_ciph.cpp @@ -57,7 +57,7 @@ void XOR_Cipher::key(const byte key[], u32bit length) int main() { - add_algorithm(new XOR_Cipher); // make it available to use + add_algorithm(global_state(), new XOR_Cipher); // make it available to use global_state().add_alias("Vernam", "XOR"); // make Vernam an alias for XOR // a hex key value |