diff options
author | lloyd <[email protected]> | 2010-10-28 20:05:21 +0000 |
---|---|---|
committer | lloyd <[email protected]> | 2010-10-28 20:05:21 +0000 |
commit | 7c2ac02f29fd4b5d629e187381baa783b53bd2e4 (patch) | |
tree | 9d07a452f0a7bd44a2b9d3aaac16f9d9e692fde5 /src/constructs | |
parent | b502cefaf0f9396354d58c4c18a78ac7870f6168 (diff) | |
parent | 7e4c62045c8216138dbed1c586139a1de7cd7f27 (diff) |
propagate from branch 'net.randombit.botan' (head 2841fb518e20d2fe0a374e4f6b08bdbb14d5d158)
to branch 'net.randombit.botan.c++0x' (head 0b9275139d6346bd3aa28d63bf8b8a03851d853d)
Diffstat (limited to 'src/constructs')
-rw-r--r-- | src/constructs/aont/package.cpp | 24 | ||||
-rw-r--r-- | src/constructs/aont/package.h | 4 | ||||
-rw-r--r-- | src/constructs/cryptobox/cryptobox.cpp | 28 | ||||
-rw-r--r-- | src/constructs/cryptobox/cryptobox.h | 4 | ||||
-rw-r--r-- | src/constructs/fpe/fpe.cpp | 22 | ||||
-rw-r--r-- | src/constructs/passhash/passhash9.cpp | 20 | ||||
-rw-r--r-- | src/constructs/tss/tss.cpp | 2 | ||||
-rw-r--r-- | src/constructs/tss/tss.h | 2 |
8 files changed, 53 insertions, 53 deletions
diff --git a/src/constructs/aont/package.cpp b/src/constructs/aont/package.cpp index a773d6558..4d92a789c 100644 --- a/src/constructs/aont/package.cpp +++ b/src/constructs/aont/package.cpp @@ -16,7 +16,7 @@ namespace Botan { void aont_package(RandomNumberGenerator& rng, BlockCipher* cipher, - const byte input[], u32bit input_len, + const byte input[], size_t input_len, byte output[]) { const size_t BLOCK_SIZE = cipher->block_size(); @@ -39,7 +39,7 @@ void aont_package(RandomNumberGenerator& rng, SecureVector<byte> buf(BLOCK_SIZE); - const u32bit blocks = + const size_t blocks = (input_len + BLOCK_SIZE - 1) / BLOCK_SIZE; byte* final_block = output + input_len; @@ -48,14 +48,14 @@ void aont_package(RandomNumberGenerator& rng, // XOR the hash blocks into the final block for(u32bit i = 0; i != blocks; ++i) { - u32bit left = std::min<u32bit>(BLOCK_SIZE, - input_len - BLOCK_SIZE * i); + const size_t left = std::min<size_t>(BLOCK_SIZE, + input_len - BLOCK_SIZE * i); zeroise(buf); copy_mem(&buf[0], output + BLOCK_SIZE * i, left); - for(u32bit j = 0; j != 4; ++j) - buf[BLOCK_SIZE - 1 - j] ^= get_byte(3-j, i); + for(size_t j = 0; j != sizeof(i); ++j) + buf[BLOCK_SIZE - 1 - j] ^= get_byte(sizeof(i)-1-j, i); cipher->encrypt(buf); @@ -67,7 +67,7 @@ void aont_package(RandomNumberGenerator& rng, } void aont_unpackage(BlockCipher* cipher, - const byte input[], u32bit input_len, + const byte input[], size_t input_len, byte output[]) { const size_t BLOCK_SIZE = cipher->block_size(); @@ -91,19 +91,19 @@ void aont_unpackage(BlockCipher* cipher, input + (input_len - BLOCK_SIZE), BLOCK_SIZE); - const u32bit blocks = ((input_len - 1) / BLOCK_SIZE); + const size_t blocks = ((input_len - 1) / BLOCK_SIZE); // XOR the blocks into the package key bits for(u32bit i = 0; i != blocks; ++i) { - u32bit left = std::min<u32bit>(BLOCK_SIZE, - input_len - BLOCK_SIZE * (i+1)); + const size_t left = std::min<size_t>(BLOCK_SIZE, + input_len - BLOCK_SIZE * (i+1)); zeroise(buf); copy_mem(&buf[0], input + BLOCK_SIZE * i, left); - for(u32bit j = 0; j != 4; ++j) - buf[BLOCK_SIZE - 1 - j] ^= get_byte(3-j, i); + for(size_t j = 0; j != sizeof(i); ++j) + buf[BLOCK_SIZE - 1 - j] ^= get_byte(sizeof(i)-1-j, i); cipher->encrypt(buf); diff --git a/src/constructs/aont/package.h b/src/constructs/aont/package.h index 34e0f35d5..52d1c2190 100644 --- a/src/constructs/aont/package.h +++ b/src/constructs/aont/package.h @@ -24,7 +24,7 @@ namespace Botan { */ void BOTAN_DLL aont_package(RandomNumberGenerator& rng, BlockCipher* cipher, - const byte input[], u32bit input_len, + const byte input[], size_t input_len, byte output[]); /** @@ -36,7 +36,7 @@ void BOTAN_DLL aont_package(RandomNumberGenerator& rng, * input_len - cipher->BLOCK_SIZE bytes long) */ void BOTAN_DLL aont_unpackage(BlockCipher* cipher, - const byte input[], u32bit input_len, + const byte input[], size_t input_len, byte output[]); } diff --git a/src/constructs/cryptobox/cryptobox.cpp b/src/constructs/cryptobox/cryptobox.cpp index 6e393ecb4..ab263c3e9 100644 --- a/src/constructs/cryptobox/cryptobox.cpp +++ b/src/constructs/cryptobox/cryptobox.cpp @@ -28,19 +28,19 @@ for later use as flags, etc if needed */ const u32bit CRYPTOBOX_VERSION_CODE = 0xEFC22400; -const u32bit VERSION_CODE_LEN = 4; -const u32bit CIPHER_KEY_LEN = 32; -const u32bit CIPHER_IV_LEN = 16; -const u32bit MAC_KEY_LEN = 32; -const u32bit MAC_OUTPUT_LEN = 20; -const u32bit PBKDF_SALT_LEN = 10; -const u32bit PBKDF_ITERATIONS = 8 * 1024; +const size_t VERSION_CODE_LEN = 4; +const size_t CIPHER_KEY_LEN = 32; +const size_t CIPHER_IV_LEN = 16; +const size_t MAC_KEY_LEN = 32; +const size_t MAC_OUTPUT_LEN = 20; +const size_t PBKDF_SALT_LEN = 10; +const size_t PBKDF_ITERATIONS = 8 * 1024; -const u32bit PBKDF_OUTPUT_LEN = CIPHER_KEY_LEN + CIPHER_IV_LEN + MAC_KEY_LEN; +const size_t PBKDF_OUTPUT_LEN = CIPHER_KEY_LEN + CIPHER_IV_LEN + MAC_KEY_LEN; } -std::string encrypt(const byte input[], u32bit input_len, +std::string encrypt(const byte input[], size_t input_len, const std::string& passphrase, RandomNumberGenerator& rng) { @@ -77,14 +77,14 @@ std::string encrypt(const byte input[], u32bit input_len, mac (20 bytes) ciphertext */ - const u32bit ciphertext_len = pipe.remaining(0); + const size_t ciphertext_len = pipe.remaining(0); SecureVector<byte> out_buf(VERSION_CODE_LEN + PBKDF_SALT_LEN + MAC_OUTPUT_LEN + ciphertext_len); - for(u32bit i = 0; i != VERSION_CODE_LEN; ++i) + for(size_t i = 0; i != VERSION_CODE_LEN; ++i) out_buf[i] = get_byte(i, CRYPTOBOX_VERSION_CODE); copy_mem(&out_buf[VERSION_CODE_LEN], &pbkdf_salt[0], PBKDF_SALT_LEN); @@ -96,7 +96,7 @@ std::string encrypt(const byte input[], u32bit input_len, return PEM_Code::encode(out_buf, "BOTAN CRYPTOBOX MESSAGE"); } -std::string decrypt(const byte input[], u32bit input_len, +std::string decrypt(const byte input[], size_t input_len, const std::string& passphrase) { DataSource_Memory input_src(input, input_len); @@ -107,7 +107,7 @@ std::string decrypt(const byte input[], u32bit input_len, if(ciphertext.size() < (VERSION_CODE_LEN + PBKDF_SALT_LEN + MAC_OUTPUT_LEN)) throw Decoding_Error("Invalid CryptoBox input"); - for(u32bit i = 0; i != VERSION_CODE_LEN; ++i) + for(size_t i = 0; i != VERSION_CODE_LEN; ++i) if(ciphertext[i] != get_byte(i, CRYPTOBOX_VERSION_CODE)) throw Decoding_Error("Bad CryptoBox version"); @@ -133,7 +133,7 @@ std::string decrypt(const byte input[], u32bit input_len, new MAC_Filter(new HMAC(new SHA_512), mac_key, MAC_OUTPUT_LEN))); - const u32bit ciphertext_offset = + const size_t ciphertext_offset = VERSION_CODE_LEN + PBKDF_SALT_LEN + MAC_OUTPUT_LEN; pipe.process_msg(&ciphertext[ciphertext_offset], diff --git a/src/constructs/cryptobox/cryptobox.h b/src/constructs/cryptobox/cryptobox.h index 12f054eff..ce1bb9ab0 100644 --- a/src/constructs/cryptobox/cryptobox.h +++ b/src/constructs/cryptobox/cryptobox.h @@ -25,7 +25,7 @@ namespace CryptoBox { * @param passphrase the passphrase used to encrypt the message * @param rng a ref to a random number generator, such as AutoSeeded_RNG */ -BOTAN_DLL std::string encrypt(const byte input[], u32bit input_len, +BOTAN_DLL std::string encrypt(const byte input[], size_t input_len, const std::string& passphrase, RandomNumberGenerator& rng); @@ -35,7 +35,7 @@ BOTAN_DLL std::string encrypt(const byte input[], u32bit input_len, * @param input_len the length of input in bytes * @param passphrase the passphrase used to encrypt the message */ -BOTAN_DLL std::string decrypt(const byte input[], u32bit input_len, +BOTAN_DLL std::string decrypt(const byte input[], size_t input_len, const std::string& passphrase); /** diff --git a/src/constructs/fpe/fpe.cpp b/src/constructs/fpe/fpe.cpp index 3747171c2..1023b067c 100644 --- a/src/constructs/fpe/fpe.cpp +++ b/src/constructs/fpe/fpe.cpp @@ -19,7 +19,7 @@ namespace Botan { namespace { // Normally FPE is for SSNs, CC#s, etc, nothing too big -const u32bit MAX_N_BYTES = 128/8; +const size_t MAX_N_BYTES = 128/8; /* * Factor n into a and b which are as close together as possible. @@ -34,13 +34,13 @@ void factor(BigInt n, BigInt& a, BigInt& b) a = 1; b = 1; - u32bit n_low_zero = low_zero_bits(n); + size_t n_low_zero = low_zero_bits(n); a <<= (n_low_zero / 2); b <<= n_low_zero - (n_low_zero / 2); n >>= n_low_zero; - for(u32bit i = 0; i != PRIME_TABLE_SIZE; ++i) + for(size_t i = 0; i != PRIME_TABLE_SIZE; ++i) { while(n % PRIMES[i] == 0) { @@ -67,7 +67,7 @@ void factor(BigInt n, BigInt& a, BigInt& b) * so 3 rounds is safe. The FPE factorization routine should always * return a >= b, so just confirm that and return 3. */ -u32bit rounds(const BigInt& a, const BigInt& b) +size_t rounds(const BigInt& a, const BigInt& b) { if(a < b) throw std::logic_error("FPE rounds: a < b"); @@ -86,7 +86,7 @@ class FPE_Encryptor ~FPE_Encryptor() { delete mac; } - BigInt operator()(u32bit i, const BigInt& R); + BigInt operator()(size_t i, const BigInt& R); private: MessageAuthenticationCode* mac; @@ -114,12 +114,12 @@ FPE_Encryptor::FPE_Encryptor(const SymmetricKey& key, mac_n_t = mac->final(); } -BigInt FPE_Encryptor::operator()(u32bit round_no, const BigInt& R) +BigInt FPE_Encryptor::operator()(size_t round_no, const BigInt& R) { SecureVector<byte> r_bin = BigInt::encode(R); mac->update(mac_n_t); - mac->update_be(round_no); + mac->update_be((u32bit)round_no); mac->update_be((u32bit)r_bin.size()); mac->update(&r_bin[0], r_bin.size()); @@ -142,11 +142,11 @@ BigInt fpe_encrypt(const BigInt& n, const BigInt& X0, BigInt a, b; factor(n, a, b); - const u32bit r = rounds(a, b); + const size_t r = rounds(a, b); BigInt X = X0; - for(u32bit i = 0; i != r; ++i) + for(size_t i = 0; i != r; ++i) { BigInt L = X / b; BigInt R = X % b; @@ -170,11 +170,11 @@ BigInt fpe_decrypt(const BigInt& n, const BigInt& X0, BigInt a, b; factor(n, a, b); - const u32bit r = rounds(a, b); + const size_t r = rounds(a, b); BigInt X = X0; - for(u32bit i = 0; i != r; ++i) + for(size_t i = 0; i != r; ++i) { BigInt W = X % a; BigInt R = X / a; diff --git a/src/constructs/passhash/passhash9.cpp b/src/constructs/passhash/passhash9.cpp index 1834ed949..367583a0a 100644 --- a/src/constructs/passhash/passhash9.cpp +++ b/src/constructs/passhash/passhash9.cpp @@ -9,7 +9,7 @@ #include <botan/loadstor.h> #include <botan/libstate.h> #include <botan/pbkdf2.h> -#include <botan/base64.h> +#include <botan/b64_filt.h> #include <botan/pipe.h> namespace Botan { @@ -18,14 +18,14 @@ namespace { const std::string MAGIC_PREFIX = "$9$"; -const u32bit WORKFACTOR_BYTES = 2; -const u32bit ALGID_BYTES = 1; -const u32bit SALT_BYTES = 12; // 96 bits of salt -const u32bit PASSHASH9_PBKDF_OUTPUT_LEN = 24; // 192 bits output +const size_t WORKFACTOR_BYTES = 2; +const size_t ALGID_BYTES = 1; +const size_t SALT_BYTES = 12; // 96 bits of salt +const size_t PASSHASH9_PBKDF_OUTPUT_LEN = 24; // 192 bits output const byte PASSHASH9_DEFAULT_ALGO = 0; // HMAC(SHA-1) -const u32bit WORK_FACTOR_SCALE = 10000; +const size_t WORK_FACTOR_SCALE = 10000; MessageAuthenticationCode* get_pbkdf_prf(byte alg_id) { @@ -71,7 +71,7 @@ std::string generate_passhash9(const std::string& pass, SecureVector<byte> salt(SALT_BYTES); rng.randomize(&salt[0], salt.size()); - u32bit kdf_iterations = WORK_FACTOR_SCALE * work_factor; + const size_t kdf_iterations = WORK_FACTOR_SCALE * work_factor; SecureVector<byte> pbkdf2_output = kdf.derive_key(PASSHASH9_PBKDF_OUTPUT_LEN, @@ -93,13 +93,13 @@ std::string generate_passhash9(const std::string& pass, bool check_passhash9(const std::string& pass, const std::string& hash) { - const u32bit BINARY_LENGTH = + const size_t BINARY_LENGTH = ALGID_BYTES + WORKFACTOR_BYTES + PASSHASH9_PBKDF_OUTPUT_LEN + SALT_BYTES; - const u32bit BASE64_LENGTH = + const size_t BASE64_LENGTH = MAGIC_PREFIX.size() + (BINARY_LENGTH * 8) / 6; if(hash.size() != BASE64_LENGTH) @@ -121,7 +121,7 @@ bool check_passhash9(const std::string& pass, const std::string& hash) byte alg_id = bin[0]; - u32bit kdf_iterations = + const size_t kdf_iterations = WORK_FACTOR_SCALE * load_be<u16bit>(&bin[ALGID_BYTES], 0); if(kdf_iterations == 0) diff --git a/src/constructs/tss/tss.cpp b/src/constructs/tss/tss.cpp index 055bc79ad..2bd4ec016 100644 --- a/src/constructs/tss/tss.cpp +++ b/src/constructs/tss/tss.cpp @@ -181,7 +181,7 @@ RTSS_Share::split(byte M, byte N, SecureVector<byte> RTSS_Share::reconstruct(const std::vector<RTSS_Share>& shares) { - const u32bit RTSS_HEADER_SIZE = 20; + const size_t RTSS_HEADER_SIZE = 20; for(size_t i = 0; i != shares.size(); ++i) { diff --git a/src/constructs/tss/tss.h b/src/constructs/tss/tss.h index 485e42c53..297c65971 100644 --- a/src/constructs/tss/tss.h +++ b/src/constructs/tss/tss.h @@ -61,7 +61,7 @@ class BOTAN_DLL RTSS_Share /** * @return size of this share in bytes */ - u32bit size() const { return contents.size(); } + size_t size() const { return contents.size(); } /** * @return if this TSS share was initialized or not |