aboutsummaryrefslogtreecommitdiffstats
path: root/doc
diff options
context:
space:
mode:
authorlloyd <[email protected]>2012-05-18 20:32:36 +0000
committerlloyd <[email protected]>2012-05-18 20:32:36 +0000
commitc691561f3198f481c13457433efbccc1c9fcd898 (patch)
treea45ea2c5a30e0cb009fbcb68a61ef39332ff790c /doc
parentd76700f01c7ecac5633edf75f8d7408b46c5dbac (diff)
Fairly huge update that replaces the old secmem types with std::vector
using a custom allocator. Currently our allocator just does new/delete with a memset before deletion, and the mmap and mlock allocators have been removed.
Diffstat (limited to 'doc')
-rw-r--r--doc/examples/GNUmakefile4
-rw-r--r--doc/examples/asn1.cpp10
-rw-r--r--doc/examples/bzip.cpp15
-rw-r--r--doc/examples/credentials.h2
-rw-r--r--doc/examples/decrypt.cpp6
-rw-r--r--doc/examples/dh.cpp4
-rw-r--r--doc/examples/dsa_ver.cpp4
-rw-r--r--doc/examples/ecdsa.cpp2
-rw-r--r--doc/examples/encrypt.cpp6
-rw-r--r--doc/examples/encrypt2.cpp10
-rw-r--r--doc/examples/fpe.cpp6
-rw-r--r--doc/examples/keywrap.cpp4
-rw-r--r--doc/examples/new_engine.cpp2
-rw-r--r--doc/examples/pqg_gen.cpp6
-rw-r--r--doc/examples/read_ssh.cpp2
-rw-r--r--doc/examples/rng_test.cpp8
-rw-r--r--doc/examples/row_encryptor.cpp20
-rw-r--r--doc/examples/rsa_dec.cpp8
-rw-r--r--doc/examples/rsa_enc.cpp14
-rw-r--r--doc/examples/tls_client.cpp2
-rw-r--r--doc/examples/tss.cpp2
21 files changed, 64 insertions, 73 deletions
diff --git a/doc/examples/GNUmakefile b/doc/examples/GNUmakefile
index fb2788218..b034cac78 100644
--- a/doc/examples/GNUmakefile
+++ b/doc/examples/GNUmakefile
@@ -1,7 +1,7 @@
BOTAN_CONFIG = botan-config
-CXX = g++-4.6.0
+CXX = g++-4.8.0-r187608
CFLAGS = -O2 -ansi -std=c++0x -W -Wall -I../../build/include
LIBS = -L../.. -lbotan-1.99
@@ -18,7 +18,7 @@ clean:
$(CXX) $(CFLAGS) $? $(LIBS) -o $@
eax_test: eax_test.cpp
- echo $(CXX) $(CFLAGS) $? $(LIBS) -lboost_regex -o $@
+ $(CXX) $(CFLAGS) $? $(LIBS) -lboost_regex -o $@
asio_tls_server: asio_tls_server.cpp credentials.h
$(CXX) $(CFLAGS) $< $(LIBS) -lboost_thread -lboost_system -o $@
diff --git a/doc/examples/asn1.cpp b/doc/examples/asn1.cpp
index 866e57d75..d12ee1eec 100644
--- a/doc/examples/asn1.cpp
+++ b/doc/examples/asn1.cpp
@@ -72,8 +72,8 @@ void decode(BER_Decoder& decoder, size_t level)
/* hack to insert the tag+length back in front of the stuff now
that we've gotten the type info */
DER_Encoder encoder;
- encoder.add_object(type_tag, class_tag, obj.value, obj.value.size());
- SecureVector<byte> bits = encoder.get_contents();
+ encoder.add_object(type_tag, class_tag, obj.value);
+ secure_vector<byte> bits = encoder.get_contents();
BER_Decoder data(bits);
@@ -143,7 +143,7 @@ void decode(BER_Decoder& decoder, size_t level)
BigInt number;
data.decode(number);
- SecureVector<byte> rep;
+ std::vector<byte> rep;
/* If it's small, it's probably a number, not a hash */
if(number.bits() <= 16)
@@ -170,7 +170,7 @@ void decode(BER_Decoder& decoder, size_t level)
}
else if(type_tag == OCTET_STRING)
{
- SecureVector<byte> bits;
+ secure_vector<byte> bits;
data.decode(bits, type_tag);
bool not_text = false;
@@ -184,7 +184,7 @@ void decode(BER_Decoder& decoder, size_t level)
}
else if(type_tag == BIT_STRING)
{
- SecureVector<byte> bits;
+ secure_vector<byte> bits;
data.decode(bits, type_tag);
std::vector<bool> bit_set;
diff --git a/doc/examples/bzip.cpp b/doc/examples/bzip.cpp
index 6137bb6af..74ba431ed 100644
--- a/doc/examples/bzip.cpp
+++ b/doc/examples/bzip.cpp
@@ -37,6 +37,7 @@ int main(int argc, char* argv[])
Botan::LibraryInitializer init;
+#ifdef BOTAN_HAS_COMPRESSOR_BZIP2
std::vector<std::string> files;
bool decompress = false, small = false;
int level = 9;
@@ -60,18 +61,10 @@ int main(int argc, char* argv[])
try {
Botan::Filter* bzip = 0;
-#ifdef BOTAN_HAS_COMPRESSOR_BZIP2
if(decompress)
bzip = new Botan::Bzip_Decompression(small);
else
bzip = new Botan::Bzip_Compression(level);
-#endif
-
- if(!bzip)
- {
- std::cout << "Sorry, support for bzip2 not compiled into Botan\n";
- return 1;
- }
Botan::Pipe pipe(bzip);
@@ -112,5 +105,11 @@ int main(int argc, char* argv[])
std::cout << "Exception caught: " << e.what() << std::endl;
return 1;
}
+#else
+
+ std::cout << "Sorry, support for bzip2 not compiled into Botan\n";
+
+#endif
+
return 0;
}
diff --git a/doc/examples/credentials.h b/doc/examples/credentials.h
index 4e4427585..2734b1649 100644
--- a/doc/examples/credentials.h
+++ b/doc/examples/credentials.h
@@ -97,7 +97,7 @@ class Credentials_Manager_Simple : public Botan::Credentials_Manager
const std::string& identifier,
std::string& group_id,
Botan::BigInt& verifier,
- Botan::MemoryRegion<Botan::byte>& salt,
+ std::vector<Botan::byte>& salt,
bool generate_fake_on_unknown)
{
diff --git a/doc/examples/decrypt.cpp b/doc/examples/decrypt.cpp
index ea510c5e9..42c4071c7 100644
--- a/doc/examples/decrypt.cpp
+++ b/doc/examples/decrypt.cpp
@@ -27,7 +27,7 @@ stderr so there is no confusion.
using namespace Botan;
-SecureVector<byte> b64_decode(const std::string&);
+secure_vector<byte> b64_decode(const std::string&);
int main(int argc, char* argv[])
{
@@ -111,7 +111,7 @@ int main(int argc, char* argv[])
const u32bit PBKDF2_ITERATIONS = 8192;
- SecureVector<byte> salt = b64_decode(salt_str);
+ secure_vector<byte> salt = b64_decode(salt_str);
SymmetricKey bc_key = pbkdf->derive_key(key_len, "BLK" + passphrase,
&salt[0], salt.size(),
@@ -165,7 +165,7 @@ int main(int argc, char* argv[])
return 0;
}
-SecureVector<byte> b64_decode(const std::string& in)
+secure_vector<byte> b64_decode(const std::string& in)
{
Pipe pipe(new Base64_Decoder);
pipe.process_msg(in);
diff --git a/doc/examples/dh.cpp b/doc/examples/dh.cpp
index 8d163303a..d62d49f65 100644
--- a/doc/examples/dh.cpp
+++ b/doc/examples/dh.cpp
@@ -24,12 +24,12 @@ int main()
DH_PrivateKey private_b(rng, shared_domain);
// Alice sends to Bob her public key and a session parameter
- MemoryVector<byte> public_a = private_a.public_value();
+ std::vector<byte> public_a = private_a.public_value();
const std::string session_param =
"Alice and Bob's shared session parameter";
// Bob sends his public key to Alice
- MemoryVector<byte> public_b = private_b.public_value();
+ std::vector<byte> public_b = private_b.public_value();
// Now Alice performs the key agreement operation
PK_Key_Agreement ka_alice(private_a, "KDF2(SHA-256)");
diff --git a/doc/examples/dsa_ver.cpp b/doc/examples/dsa_ver.cpp
index 9cb85740e..e6910a4e1 100644
--- a/doc/examples/dsa_ver.cpp
+++ b/doc/examples/dsa_ver.cpp
@@ -12,7 +12,7 @@ using namespace Botan;
namespace {
-SecureVector<byte> b64_decode(const std::string& in)
+secure_vector<byte> b64_decode(const std::string& in)
{
Pipe pipe(new Base64_Decoder);
pipe.process_msg(in);
@@ -60,7 +60,7 @@ int main(int argc, char* argv[])
return 1;
}
- SecureVector<byte> sig = b64_decode(sigstr);
+ secure_vector<byte> sig = b64_decode(sigstr);
PK_Verifier ver(*dsakey, "EMSA1(SHA-1)");
diff --git a/doc/examples/ecdsa.cpp b/doc/examples/ecdsa.cpp
index 1607107eb..b0a66a888 100644
--- a/doc/examples/ecdsa.cpp
+++ b/doc/examples/ecdsa.cpp
@@ -40,7 +40,7 @@ int main()
signer.update((const byte*)message, strlen(message));
- SecureVector<byte> sig = signer.signature(rng);
+ std::vector<byte> sig = signer.signature(rng);
std::cout << sig.size() << "\n";
diff --git a/doc/examples/encrypt.cpp b/doc/examples/encrypt.cpp
index 28017d875..158806936 100644
--- a/doc/examples/encrypt.cpp
+++ b/doc/examples/encrypt.cpp
@@ -33,7 +33,7 @@ you're encrypting is 1 Gb... you better have a lot of RAM.
using namespace Botan;
-std::string b64_encode(const SecureVector<byte>&);
+std::string b64_encode(const secure_vector<byte>&);
int main(int argc, char* argv[])
{
@@ -128,7 +128,7 @@ int main(int argc, char* argv[])
std::auto_ptr<PBKDF> pbkdf(get_pbkdf("PBKDF2(SHA-1)"));
- SecureVector<byte> salt(8);
+ secure_vector<byte> salt(8);
rng.randomize(&salt[0], salt.size());
const u32bit PBKDF2_ITERATIONS = 8192;
@@ -185,7 +185,7 @@ int main(int argc, char* argv[])
return 0;
}
-std::string b64_encode(const SecureVector<byte>& in)
+std::string b64_encode(const secure_vector<byte>& in)
{
Pipe pipe(new Base64_Encoder);
pipe.process_msg(in);
diff --git a/doc/examples/encrypt2.cpp b/doc/examples/encrypt2.cpp
index 41f4fb478..c6c735af9 100644
--- a/doc/examples/encrypt2.cpp
+++ b/doc/examples/encrypt2.cpp
@@ -28,10 +28,10 @@ int main()
const u32bit PBKDF2_ITERATIONS = 8192;
- SecureVector<byte> salt(8);
+ secure_vector<byte> salt(8);
rng.randomize(&salt[0], salt.size());
- SecureVector<byte> master_key = pbkdf2.derive_key(48, passphrase,
+ secure_vector<byte> master_key = pbkdf2.derive_key(48, passphrase,
&salt[0], salt.size(),
PBKDF2_ITERATIONS).bits_of();
@@ -55,12 +55,12 @@ int main()
)
);
- outfile.write((const char*)salt.begin(), salt.size());
+ outfile.write((const char*)&salt[0], salt.size());
pipe.start_msg();
infile >> pipe;
pipe.end_msg();
- SecureVector<byte> hmac = pipe.read_all(1);
- outfile.write((const char*)hmac.begin(), hmac.size());
+ secure_vector<byte> hmac = pipe.read_all(1);
+ outfile.write((const char*)&hmac[0], hmac.size());
}
diff --git a/doc/examples/fpe.cpp b/doc/examples/fpe.cpp
index 029a761e7..8f5eaca9f 100644
--- a/doc/examples/fpe.cpp
+++ b/doc/examples/fpe.cpp
@@ -55,11 +55,11 @@ u64bit cc_derank(u64bit cc_number)
/*
* Use the SHA-1 hash of the account name or ID as a tweak
*/
-SecureVector<byte> sha1(const std::string& acct_name)
+std::vector<byte> sha1(const std::string& acct_name)
{
SHA_160 hash;
hash.update(acct_name);
- return hash.final();
+ return unlock(hash.final());
}
u64bit encrypt_cc_number(u64bit cc_number,
@@ -123,7 +123,7 @@ int main(int argc, char* argv[])
* In practice something like PBKDF2 with a salt and high iteration
* count would be a good idea.
*/
- SymmetricKey key = sha1(passwd);
+ SymmetricKey key(sha1(passwd));
u64bit enc_cc = encrypt_cc_number(cc_number, key, acct_name);
diff --git a/doc/examples/keywrap.cpp b/doc/examples/keywrap.cpp
index 730bcb6c9..93cdbfb84 100644
--- a/doc/examples/keywrap.cpp
+++ b/doc/examples/keywrap.cpp
@@ -28,11 +28,11 @@ int main()
Algorithm_Factory& af = global_state().algorithm_factory();
- SecureVector<byte> enc = rfc3394_keywrap(key.bits_of(), kek, af);
+ secure_vector<byte> enc = rfc3394_keywrap(key.bits_of(), kek, af);
std::cout << "Encrypted: " << hex_encode(enc) << "\n";
- SecureVector<byte> dec = rfc3394_keyunwrap(enc, kek, af);
+ secure_vector<byte> dec = rfc3394_keyunwrap(enc, kek, af);
std::cout << "Decrypted: " << hex_encode(dec) << "\n";
}
diff --git a/doc/examples/new_engine.cpp b/doc/examples/new_engine.cpp
index 42e5dbe33..7e51df2e2 100644
--- a/doc/examples/new_engine.cpp
+++ b/doc/examples/new_engine.cpp
@@ -43,7 +43,7 @@ class XOR_Cipher : public StreamCipher
copy_mem(&mask[0], key, length);
}
- SecureVector<byte> mask;
+ secure_vector<byte> mask;
u32bit mask_pos;
};
diff --git a/doc/examples/pqg_gen.cpp b/doc/examples/pqg_gen.cpp
index c033dac3b..b24c30844 100644
--- a/doc/examples/pqg_gen.cpp
+++ b/doc/examples/pqg_gen.cpp
@@ -13,7 +13,7 @@
#include <botan/botan.h>
#include <botan/auto_rng.h>
-#include <botan/dsa.h>
+#include <botan/hex.h>
#include <botan/numthry.h>
#include <botan/dl_group.h>
using namespace Botan;
@@ -94,9 +94,7 @@ bool check(RandomNumberGenerator& rng,
//u32bit c = to_u32bit(inputs["c"]);
- Pipe pipe(new Hex_Decoder);
- pipe.process_msg(inputs["Seed"]);
- SecureVector<byte> seed = pipe.read_all();
+ std::vector<byte> seed = unlock(hex_decode(inputs["Seed"]));
BigInt our_p, our_q;
diff --git a/doc/examples/read_ssh.cpp b/doc/examples/read_ssh.cpp
index f6299a29d..0392786a5 100644
--- a/doc/examples/read_ssh.cpp
+++ b/doc/examples/read_ssh.cpp
@@ -42,7 +42,7 @@ BigInt read_bigint(Pipe& pipe)
{
u32bit len = read_u32bit(pipe);
- SecureVector<byte> buf(len);
+ secure_vector<byte> buf(len);
pipe.read(&buf[0], len);
return BigInt::decode(buf);
}
diff --git a/doc/examples/rng_test.cpp b/doc/examples/rng_test.cpp
index c0d24fd80..385ac57f3 100644
--- a/doc/examples/rng_test.cpp
+++ b/doc/examples/rng_test.cpp
@@ -68,11 +68,11 @@ void x931_tests(std::vector<std::pair<std::string, std::string> > vecs,
ANSI_X931_RNG prng(get_block_cipher(cipher),
new Fixed_Output_RNG);
- SecureVector<byte> x = hex_decode(input);
- prng.add_entropy(x.begin(), x.size());
+ secure_vector<byte> x = hex_decode(input);
+ prng.add_entropy(&x[0], x.size());
- SecureVector<byte> output(result.size() / 2);
- prng.randomize(output, output.size());
+ secure_vector<byte> output(result.size() / 2);
+ prng.randomize(&output[0], output.size());
if(hex_decode(result) != output)
std::cout << "FAIL";
diff --git a/doc/examples/row_encryptor.cpp b/doc/examples/row_encryptor.cpp
index 685850945..b512025b6 100644
--- a/doc/examples/row_encryptor.cpp
+++ b/doc/examples/row_encryptor.cpp
@@ -26,22 +26,22 @@ class Row_Encryptor
RandomNumberGenerator& rng);
Row_Encryptor(const std::string& passphrase,
- const MemoryRegion<byte>& salt);
+ const std::vector<byte>& salt);
std::string encrypt(const std::string& input,
- const MemoryRegion<byte>& salt);
+ const std::vector<byte>& salt);
std::string decrypt(const std::string& input,
- const MemoryRegion<byte>& salt);
+ const std::vector<byte>& salt);
- SecureVector<byte> get_pbkdf_salt() const { return pbkdf_salt; }
+ std::vector<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> pbkdf_salt;
+ std::vector<byte> pbkdf_salt;
Pipe enc_pipe, dec_pipe;
EAX_Encryption* eax_enc; // owned by enc_pipe
EAX_Decryption* eax_dec; // owned by dec_pipe;
@@ -56,7 +56,7 @@ Row_Encryptor::Row_Encryptor(const std::string& passphrase,
}
Row_Encryptor::Row_Encryptor(const std::string& passphrase,
- const MemoryRegion<byte>& salt)
+ const std::vector<byte>& salt)
{
pbkdf_salt = salt;
init(passphrase);
@@ -66,7 +66,7 @@ void Row_Encryptor::init(const std::string& passphrase)
{
std::auto_ptr<PBKDF> pbkdf(get_pbkdf("PBKDF2(SHA-160)"));
- SecureVector<byte> key = pbkdf->derive_key(32, passphrase,
+ secure_vector<byte> key = pbkdf->derive_key(32, passphrase,
&pbkdf_salt[0], pbkdf_salt.size(),
10000).bits_of();
@@ -89,7 +89,7 @@ void Row_Encryptor::init(const std::string& passphrase)
}
std::string Row_Encryptor::encrypt(const std::string& input,
- const MemoryRegion<byte>& salt)
+ const std::vector<byte>& salt)
{
eax_enc->set_iv(salt);
enc_pipe.process_msg(input);
@@ -97,7 +97,7 @@ std::string Row_Encryptor::encrypt(const std::string& input,
}
std::string Row_Encryptor::decrypt(const std::string& input,
- const MemoryRegion<byte>& salt)
+ const std::vector<byte>& salt)
{
eax_dec->set_iv(salt);
dec_pipe.process_msg(input);
@@ -133,7 +133,7 @@ int main()
}
std::vector<std::string> encrypted_values;
- MemoryVector<byte> salt(4); // keep out of loop to avoid excessive dynamic allocation
+ std::vector<byte> salt(4);
for(u32bit i = 0; i != original_inputs.size(); ++i)
{
diff --git a/doc/examples/rsa_dec.cpp b/doc/examples/rsa_dec.cpp
index 9c470b8e9..98768cda7 100644
--- a/doc/examples/rsa_dec.cpp
+++ b/doc/examples/rsa_dec.cpp
@@ -20,7 +20,7 @@ same key format as that generated by rsa_kgen.
#include <botan/rsa.h>
using namespace Botan;
-SecureVector<byte> b64_decode(const std::string&);
+secure_vector<byte> b64_decode(const std::string&);
SymmetricKey derive_key(const std::string&, const SymmetricKey&, u32bit);
const std::string SUFFIX = ".enc";
@@ -73,11 +73,11 @@ int main(int argc, char* argv[])
std::string mac_str;
std::getline(message, mac_str);
- SecureVector<byte> enc_masterkey = b64_decode(enc_masterkey_str);
+ secure_vector<byte> enc_masterkey = b64_decode(enc_masterkey_str);
PK_Decryptor_EME decryptor(*rsakey, "EME1(SHA-1)");
- SecureVector<byte> masterkey = decryptor.decrypt(enc_masterkey);
+ secure_vector<byte> masterkey = decryptor.decrypt(enc_masterkey);
SymmetricKey cast_key = derive_key("CAST", masterkey, 16);
InitializationVector iv = derive_key("IV", masterkey, 8);
@@ -113,7 +113,7 @@ int main(int argc, char* argv[])
return 0;
}
-SecureVector<byte> b64_decode(const std::string& in)
+secure_vector<byte> b64_decode(const std::string& in)
{
Pipe pipe(new Base64_Decoder);
pipe.process_msg(in);
diff --git a/doc/examples/rsa_enc.cpp b/doc/examples/rsa_enc.cpp
index ac609c4b3..b8e5d874b 100644
--- a/doc/examples/rsa_enc.cpp
+++ b/doc/examples/rsa_enc.cpp
@@ -34,9 +34,10 @@
#include <botan/botan.h>
#include <botan/pubkey.h>
#include <botan/rsa.h>
+#include <botan/base64.h>
+
using namespace Botan;
-std::string b64_encode(const SecureVector<byte>&);
SymmetricKey derive_key(const std::string&, const SymmetricKey&, u32bit);
int main(int argc, char* argv[])
@@ -98,10 +99,10 @@ int main(int argc, char* argv[])
SymmetricKey mac_key = derive_key("MAC", masterkey, 16);
SymmetricKey iv = derive_key("IV", masterkey, 8);
- SecureVector<byte> encrypted_key =
+ std::vector<byte> encrypted_key =
encryptor.encrypt(masterkey.bits_of(), rng);
- ciphertext << b64_encode(encrypted_key) << std::endl;
+ ciphertext << base64_encode(encrypted_key) << std::endl;
Pipe pipe(new Fork(
new Chain(
@@ -135,13 +136,6 @@ int main(int argc, char* argv[])
return 0;
}
-std::string b64_encode(const SecureVector<byte>& in)
- {
- Pipe pipe(new Base64_Encoder);
- pipe.process_msg(in);
- return pipe.read_all_as_string();
- }
-
SymmetricKey derive_key(const std::string& param,
const SymmetricKey& masterkey,
u32bit outputlength)
diff --git a/doc/examples/tls_client.cpp b/doc/examples/tls_client.cpp
index 5de8a59ce..deb0ff460 100644
--- a/doc/examples/tls_client.cpp
+++ b/doc/examples/tls_client.cpp
@@ -168,7 +168,7 @@ void doit(RandomNumberGenerator& rng,
continue;
}
- const size_t needed = client.received_data(buf, got);
+ client.received_data(buf, got);
//std::cout << "Socket - got " << got << " bytes, need " << needed << "\n";
}
else if(FD_ISSET(STDIN_FILENO, &readfds))
diff --git a/doc/examples/tss.cpp b/doc/examples/tss.cpp
index 03d7699bf..aecf95796 100644
--- a/doc/examples/tss.cpp
+++ b/doc/examples/tss.cpp
@@ -11,7 +11,7 @@
namespace {
-void print(const Botan::SecureVector<Botan::byte>& r)
+void print(const Botan::secure_vector<Botan::byte>& r)
{
for(Botan::u32bit i = 0; i != r.size(); ++i)
printf("%02X", r[i]);