diff options
author | lloyd <[email protected]> | 2010-07-09 15:06:31 +0000 |
---|---|---|
committer | lloyd <[email protected]> | 2010-07-09 15:06:31 +0000 |
commit | f9162c355d3cee11be911c4cf469044b5c3c4699 (patch) | |
tree | 710c305d8e0f965543f56dc06ce2535c842fc524 /doc/examples | |
parent | 14bfa0d15fc666b83a0b58a0713abba76c85dc41 (diff) |
Rename S2K to PBKDF, because that is by far the most common name - S2K
really is only used by OpenPGP, and largely it was named S2K here
because the OpenPGP S2K was implemented years before the ones in PKCS
#5. We have a typedef of PBKDF to S2K, and an inlined get_s2k that
calls get_pbkdf for source compatability.
There doesn't seem to be any reason to have a forward for the renamed
s2k.h header - to actually use a PBKDF, you'd have to either include
lookup.h and call get_s2k / get_pbkdf, or else include an
algorithm-specific header and use it directly. In either case,
including s2k.h is neither necessary nor sufficient.
Diffstat (limited to 'doc/examples')
-rw-r--r-- | doc/examples/decrypt.cpp | 20 | ||||
-rw-r--r-- | doc/examples/encrypt.cpp | 22 | ||||
-rw-r--r-- | doc/examples/readme.txt | 2 | ||||
-rw-r--r-- | doc/examples/row_encryptor.cpp | 28 |
4 files changed, 37 insertions, 35 deletions
diff --git a/doc/examples/decrypt.cpp b/doc/examples/decrypt.cpp index de261b5f3..2e913d2d3 100644 --- a/doc/examples/decrypt.cpp +++ b/doc/examples/decrypt.cpp @@ -105,23 +105,23 @@ 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<S2K> s2k(get_s2k("PBKDF2(SHA-1)")); + std::auto_ptr<PBKDF> pbkdf(get_pbkdf("PBKDF2(SHA-1)")); const u32bit PBKDF2_ITERATIONS = 8192; SecureVector<byte> salt = b64_decode(salt_str); - SymmetricKey bc_key = s2k->derive_key(key_len, "BLK" + passphrase, - &salt[0], salt.size(), - PBKDF2_ITERATIONS); + SymmetricKey bc_key = pbkdf->derive_key(key_len, "BLK" + passphrase, + &salt[0], salt.size(), + PBKDF2_ITERATIONS); - InitializationVector iv = s2k->derive_key(iv_len, "IVL" + passphrase, - &salt[0], salt.size(), - PBKDF2_ITERATIONS); + InitializationVector iv = pbkdf->derive_key(iv_len, "IVL" + passphrase, + &salt[0], salt.size(), + PBKDF2_ITERATIONS); - SymmetricKey mac_key = s2k->derive_key(16, "MAC" + passphrase, - &salt[0], salt.size(), - PBKDF2_ITERATIONS); + SymmetricKey mac_key = pbkdf->derive_key(16, "MAC" + passphrase, + &salt[0], salt.size(), + PBKDF2_ITERATIONS); Pipe pipe(new Base64_Decoder, get_cipher(algo + "/CBC", bc_key, iv, DECRYPTION), diff --git a/doc/examples/encrypt.cpp b/doc/examples/encrypt.cpp index 4999fa086..b5568ca50 100644 --- a/doc/examples/encrypt.cpp +++ b/doc/examples/encrypt.cpp @@ -124,22 +124,24 @@ int main(int argc, char* argv[]) AutoSeeded_RNG rng; - std::auto_ptr<S2K> s2k(get_s2k("PBKDF2(SHA-1)")); + std::auto_ptr<PBKDF> pbkdf(get_pbkdf("PBKDF2(SHA-1)")); SecureVector<byte> salt(8); rng.randomize(&salt[0], salt.size()); const u32bit PBKDF2_ITERATIONS = 8192; - SymmetricKey bc_key = s2k->derive_key(key_len, "BLK" + passphrase, - &salt[0], salt.size(), - PBKDF2_ITERATIONS); - InitializationVector iv = s2k->derive_key(iv_len, "IVL" + passphrase, - &salt[0], salt.size(), - PBKDF2_ITERATIONS); - SymmetricKey mac_key = s2k->derive_key(16, "MAC" + passphrase, - &salt[0], salt.size(), - PBKDF2_ITERATIONS); + SymmetricKey bc_key = pbkdf->derive_key(key_len, "BLK" + passphrase, + &salt[0], salt.size(), + PBKDF2_ITERATIONS); + + InitializationVector iv = pbkdf->derive_key(iv_len, "IVL" + passphrase, + &salt[0], salt.size(), + PBKDF2_ITERATIONS); + + SymmetricKey mac_key = pbkdf->derive_key(16, "MAC" + passphrase, + &salt[0], salt.size(), + PBKDF2_ITERATIONS); // Just to be all fancy we even write a (simple) header. out << "-------- ENCRYPTED FILE --------" << std::endl; diff --git a/doc/examples/readme.txt b/doc/examples/readme.txt index 48686db71..fb6a03ddf 100644 --- a/doc/examples/readme.txt +++ b/doc/examples/readme.txt @@ -32,7 +32,7 @@ pkcs10: Generates a PKCS #10 certificate request for a 1024 bit RSA key self_sig: Generates a self-signed X.509v3 certificate with a 1024 bit RSA key -------- -* RSA examples (also uses X.509, PKCS #8, block ciphers, MACs, S2K algorithms) +* RSA examples (also uses X.509, PKCS #8, block ciphers, MACs, PBKDF algorithms) -------- rsa_kgen: Generate an RSA key, encrypt the private key with a passphrase, output the keys to a pair of files diff --git a/doc/examples/row_encryptor.cpp b/doc/examples/row_encryptor.cpp index 7c234105d..8c1df66a0 100644 --- a/doc/examples/row_encryptor.cpp +++ b/doc/examples/row_encryptor.cpp @@ -16,8 +16,8 @@ using namespace Botan; -/** -Encrypt and decrypt small rows +/* +* Encrypt and decrypt small rows */ class Row_Encryptor { @@ -34,14 +34,14 @@ class Row_Encryptor std::string decrypt(const std::string& input, const MemoryRegion<byte>& salt); - SecureVector<byte> get_s2k_salt() const { return s2k_salt; } + SecureVector<byte> get_pbkdf_salt() const { return pbkdf_salt; } private: void init(const std::string& passphrase); Row_Encryptor(const Row_Encryptor&) {} Row_Encryptor& operator=(const Row_Encryptor&) { return (*this); } - SecureVector<byte> s2k_salt; + SecureVector<byte> pbkdf_salt; Pipe enc_pipe, dec_pipe; EAX_Encryption* eax_enc; // owned by enc_pipe EAX_Decryption* eax_dec; // owned by dec_pipe; @@ -50,24 +50,24 @@ class Row_Encryptor Row_Encryptor::Row_Encryptor(const std::string& passphrase, RandomNumberGenerator& rng) { - s2k_salt.resize(10); // 80 bits - rng.randomize(&s2k_salt[0], s2k_salt.size()); + pbkdf_salt.resize(10); // 80 bits + rng.randomize(&pbkdf_salt[0], pbkdf_salt.size()); init(passphrase); } Row_Encryptor::Row_Encryptor(const std::string& passphrase, const MemoryRegion<byte>& salt) { - s2k_salt = salt; + pbkdf_salt = salt; init(passphrase); } void Row_Encryptor::init(const std::string& passphrase) { - std::auto_ptr<S2K> s2k(get_s2k("PBKDF2(SHA-160)")); + std::auto_ptr<PBKDF> pbkdf(get_pbkdf("PBKDF2(SHA-160)")); - SecureVector<byte> key = s2k->derive_key(32, passphrase, - &s2k_salt[0], s2k_salt.size(), + SecureVector<byte> key = pbkdf->derive_key(32, passphrase, + &pbkdf_salt[0], pbkdf_salt.size(), 10000).bits_of(); /* @@ -159,13 +159,13 @@ int main() std::cout << "BOOM " << i << "\n"; } - Row_Encryptor test_s2k_salt_copy(secret_passphrase, - encryptor.get_s2k_salt()); + Row_Encryptor test_pbkdf_salt_copy(secret_passphrase, + encryptor.get_pbkdf_salt()); salt.clear(); // all-0 - std::string test = test_s2k_salt_copy.decrypt(encrypted_values[0], salt); + std::string test = test_pbkdf_salt_copy.decrypt(encrypted_values[0], salt); if(test != original_inputs[0]) - std::cout << "S2K salt copy failed to decrypt properly\n"; + std::cout << "PBKDF salt copy failed to decrypt properly\n"; return 0; } |