aboutsummaryrefslogtreecommitdiffstats
path: root/doc/examples
diff options
context:
space:
mode:
Diffstat (limited to 'doc/examples')
-rw-r--r--doc/examples/decrypt.cpp20
-rw-r--r--doc/examples/encrypt.cpp22
-rw-r--r--doc/examples/readme.txt2
-rw-r--r--doc/examples/row_encryptor.cpp28
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;
}