diff options
Diffstat (limited to 'doc/examples/encrypt2.cpp')
-rw-r--r-- | doc/examples/encrypt2.cpp | 21 |
1 files changed, 16 insertions, 5 deletions
diff --git a/doc/examples/encrypt2.cpp b/doc/examples/encrypt2.cpp index 4af0cf019..41f4fb478 100644 --- a/doc/examples/encrypt2.cpp +++ b/doc/examples/encrypt2.cpp @@ -1,3 +1,9 @@ +/* +* (C) 2009 Jack Lloyd +* +* Distributed under the terms of the Botan license +*/ + #include <botan/botan.h> #include <botan/pbkdf2.h> #include <botan/hmac.h> @@ -20,16 +26,21 @@ int main() PKCS5_PBKDF2 pbkdf2(new HMAC(new SHA_160)); - pbkdf2.set_iterations(4096); - pbkdf2.new_random_salt(rng, 8); - SecureVector<byte> the_salt = pbkdf2.current_salt(); + const u32bit PBKDF2_ITERATIONS = 8192; + + SecureVector<byte> salt(8); + rng.randomize(&salt[0], salt.size()); - SecureVector<byte> master_key = pbkdf2.derive_key(48, passphrase).bits_of(); + SecureVector<byte> master_key = pbkdf2.derive_key(48, passphrase, + &salt[0], salt.size(), + PBKDF2_ITERATIONS).bits_of(); KDF* kdf = get_kdf("KDF2(SHA-1)"); SymmetricKey key = kdf->derive_key(20, master_key, "cipher key"); + SymmetricKey mac_key = kdf->derive_key(20, master_key, "hmac key"); + InitializationVector iv = kdf->derive_key(8, master_key, "cipher iv"); Pipe pipe(new Fork( @@ -44,7 +55,7 @@ int main() ) ); - outfile.write((const char*)the_salt.begin(), the_salt.size()); + outfile.write((const char*)salt.begin(), salt.size()); pipe.start_msg(); infile >> pipe; |