diff options
author | Jack Lloyd <[email protected]> | 2016-12-11 15:28:38 -0500 |
---|---|---|
committer | Jack Lloyd <[email protected]> | 2016-12-18 16:48:24 -0500 |
commit | f3cb3edb512bdcab498d825886c3366c341b3f78 (patch) | |
tree | 645c73ec295a5a34f25d99903b6d9fa9751e86d3 /src/lib/misc | |
parent | c1dd21253c1f3188ff45d3ad47698efd08235ae8 (diff) |
Convert to using standard uintN_t integer types
Renames a couple of functions for somewhat better name consistency,
eg make_u32bit becomes make_uint32. The old typedefs remain for now
since probably lots of application code uses them.
Diffstat (limited to 'src/lib/misc')
-rw-r--r-- | src/lib/misc/aont/package.cpp | 16 | ||||
-rw-r--r-- | src/lib/misc/aont/package.h | 8 | ||||
-rw-r--r-- | src/lib/misc/cryptobox/cryptobox.cpp | 22 | ||||
-rw-r--r-- | src/lib/misc/cryptobox/cryptobox.h | 4 | ||||
-rw-r--r-- | src/lib/misc/fpe_fe1/fpe_fe1.cpp | 24 | ||||
-rw-r--r-- | src/lib/misc/fpe_fe1/fpe_fe1.h | 4 | ||||
-rw-r--r-- | src/lib/misc/rfc3394/rfc3394.cpp | 22 | ||||
-rw-r--r-- | src/lib/misc/rfc3394/rfc3394.h | 4 | ||||
-rw-r--r-- | src/lib/misc/srp6/srp6.cpp | 10 | ||||
-rw-r--r-- | src/lib/misc/srp6/srp6.h | 4 | ||||
-rw-r--r-- | src/lib/misc/srp6/srp6_files.cpp | 4 | ||||
-rw-r--r-- | src/lib/misc/srp6/srp6_files.h | 6 | ||||
-rw-r--r-- | src/lib/misc/tss/tss.cpp | 58 | ||||
-rw-r--r-- | src/lib/misc/tss/tss.h | 12 |
14 files changed, 99 insertions, 99 deletions
diff --git a/src/lib/misc/aont/package.cpp b/src/lib/misc/aont/package.cpp index cec07d298..9c106e1d0 100644 --- a/src/lib/misc/aont/package.cpp +++ b/src/lib/misc/aont/package.cpp @@ -15,8 +15,8 @@ namespace Botan { void aont_package(RandomNumberGenerator& rng, BlockCipher* cipher, - const byte input[], size_t input_len, - byte output[]) + const uint8_t input[], size_t input_len, + uint8_t output[]) { const size_t BLOCK_SIZE = cipher->block_size(); @@ -37,12 +37,12 @@ void aont_package(RandomNumberGenerator& rng, // Set K0 (the all zero key) cipher->set_key(SymmetricKey(all_zeros)); - secure_vector<byte> buf(BLOCK_SIZE); + secure_vector<uint8_t> buf(BLOCK_SIZE); const size_t blocks = (input_len + BLOCK_SIZE - 1) / BLOCK_SIZE; - byte* final_block = output + input_len; + uint8_t* final_block = output + input_len; clear_mem(final_block, BLOCK_SIZE); // XOR the hash blocks into the final block @@ -67,8 +67,8 @@ void aont_package(RandomNumberGenerator& rng, } void aont_unpackage(BlockCipher* cipher, - const byte input[], size_t input_len, - byte output[]) + const uint8_t input[], size_t input_len, + uint8_t output[]) { const size_t BLOCK_SIZE = cipher->block_size(); @@ -83,8 +83,8 @@ void aont_unpackage(BlockCipher* cipher, cipher->set_key(SymmetricKey(all_zeros)); - secure_vector<byte> package_key(BLOCK_SIZE); - secure_vector<byte> buf(BLOCK_SIZE); + secure_vector<uint8_t> package_key(BLOCK_SIZE); + secure_vector<uint8_t> buf(BLOCK_SIZE); // Copy the package key (masked with the block hashes) copy_mem(package_key.data(), diff --git a/src/lib/misc/aont/package.h b/src/lib/misc/aont/package.h index 76e679490..48d4b44e0 100644 --- a/src/lib/misc/aont/package.h +++ b/src/lib/misc/aont/package.h @@ -24,8 +24,8 @@ namespace Botan { */ void BOTAN_DLL aont_package(RandomNumberGenerator& rng, BlockCipher* cipher, - const byte input[], size_t input_len, - byte output[]); + const uint8_t input[], size_t input_len, + uint8_t output[]); /** * Rivest's Package Tranform (Inversion) @@ -36,8 +36,8 @@ void BOTAN_DLL aont_package(RandomNumberGenerator& rng, * input_len - cipher->BLOCK_SIZE bytes long) */ void BOTAN_DLL aont_unpackage(BlockCipher* cipher, - const byte input[], size_t input_len, - byte output[]); + const uint8_t input[], size_t input_len, + uint8_t output[]); } diff --git a/src/lib/misc/cryptobox/cryptobox.cpp b/src/lib/misc/cryptobox/cryptobox.cpp index 95cdda149..944adef49 100644 --- a/src/lib/misc/cryptobox/cryptobox.cpp +++ b/src/lib/misc/cryptobox/cryptobox.cpp @@ -25,7 +25,7 @@ namespace { First 24 bits of SHA-256("Botan Cryptobox"), followed by 8 0 bits for later use as flags, etc if needed */ -const u32bit CRYPTOBOX_VERSION_CODE = 0xEFC22400; +const uint32_t CRYPTOBOX_VERSION_CODE = 0xEFC22400; const size_t VERSION_CODE_LEN = 4; const size_t CIPHER_KEY_LEN = 32; @@ -39,11 +39,11 @@ const size_t PBKDF_OUTPUT_LEN = CIPHER_KEY_LEN + CIPHER_IV_LEN + MAC_KEY_LEN; } -std::string encrypt(const byte input[], size_t input_len, +std::string encrypt(const uint8_t input[], size_t input_len, const std::string& passphrase, RandomNumberGenerator& rng) { - secure_vector<byte> pbkdf_salt(PBKDF_SALT_LEN); + secure_vector<uint8_t> pbkdf_salt(PBKDF_SALT_LEN); rng.randomize(pbkdf_salt.data(), pbkdf_salt.size()); PKCS5_PBKDF2 pbkdf(new HMAC(new SHA_512)); @@ -55,7 +55,7 @@ std::string encrypt(const byte input[], size_t input_len, pbkdf_salt.size(), PBKDF_ITERATIONS); - const byte* mk = master_key.begin(); + const uint8_t* mk = master_key.begin(); SymmetricKey cipher_key(mk, CIPHER_KEY_LEN); SymmetricKey mac_key(&mk[CIPHER_KEY_LEN], MAC_KEY_LEN); @@ -78,7 +78,7 @@ std::string encrypt(const byte input[], size_t input_len, */ const size_t ciphertext_len = pipe.remaining(0); - std::vector<byte> out_buf(VERSION_CODE_LEN + + std::vector<uint8_t> out_buf(VERSION_CODE_LEN + PBKDF_SALT_LEN + MAC_OUTPUT_LEN + ciphertext_len); @@ -99,11 +99,11 @@ std::string encrypt(const byte input[], size_t input_len, return PEM_Code::encode(out_buf, "BOTAN CRYPTOBOX MESSAGE"); } -std::string decrypt(const byte input[], size_t input_len, +std::string decrypt(const uint8_t input[], size_t input_len, const std::string& passphrase) { DataSource_Memory input_src(input, input_len); - secure_vector<byte> ciphertext = + secure_vector<uint8_t> ciphertext = PEM_Code::decode_check_label(input_src, "BOTAN CRYPTOBOX MESSAGE"); @@ -114,7 +114,7 @@ std::string decrypt(const byte input[], size_t input_len, if(ciphertext[i] != get_byte(i, CRYPTOBOX_VERSION_CODE)) throw Decoding_Error("Bad CryptoBox version"); - const byte* pbkdf_salt = &ciphertext[VERSION_CODE_LEN]; + const uint8_t* pbkdf_salt = &ciphertext[VERSION_CODE_LEN]; PKCS5_PBKDF2 pbkdf(new HMAC(new SHA_512)); @@ -125,7 +125,7 @@ std::string decrypt(const byte input[], size_t input_len, PBKDF_SALT_LEN, PBKDF_ITERATIONS); - const byte* mk = master_key.begin(); + const uint8_t* mk = master_key.begin(); SymmetricKey cipher_key(mk, CIPHER_KEY_LEN); SymmetricKey mac_key(&mk[CIPHER_KEY_LEN], MAC_KEY_LEN); @@ -142,7 +142,7 @@ std::string decrypt(const byte input[], size_t input_len, pipe.process_msg(&ciphertext[ciphertext_offset], ciphertext.size() - ciphertext_offset); - byte computed_mac[MAC_OUTPUT_LEN]; + uint8_t computed_mac[MAC_OUTPUT_LEN]; BOTAN_ASSERT_EQUAL(MAC_OUTPUT_LEN, pipe.read(computed_mac, MAC_OUTPUT_LEN, 1), "MAC size"); if(!same_mem(computed_mac, @@ -156,7 +156,7 @@ std::string decrypt(const byte input[], size_t input_len, std::string decrypt(const std::string& input, const std::string& passphrase) { - return decrypt(reinterpret_cast<const byte*>(input.data()), + return decrypt(reinterpret_cast<const uint8_t*>(input.data()), input.size(), passphrase); } diff --git a/src/lib/misc/cryptobox/cryptobox.h b/src/lib/misc/cryptobox/cryptobox.h index 27dc55a68..8a524c93c 100644 --- a/src/lib/misc/cryptobox/cryptobox.h +++ b/src/lib/misc/cryptobox/cryptobox.h @@ -26,7 +26,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[], size_t input_len, +BOTAN_DLL std::string encrypt(const uint8_t input[], size_t input_len, const std::string& passphrase, RandomNumberGenerator& rng); @@ -37,7 +37,7 @@ BOTAN_DLL std::string encrypt(const byte input[], size_t 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[], size_t input_len, +BOTAN_DLL std::string decrypt(const uint8_t input[], size_t input_len, const std::string& passphrase); /** diff --git a/src/lib/misc/fpe_fe1/fpe_fe1.cpp b/src/lib/misc/fpe_fe1/fpe_fe1.cpp index c59e41e78..72e154374 100644 --- a/src/lib/misc/fpe_fe1/fpe_fe1.cpp +++ b/src/lib/misc/fpe_fe1/fpe_fe1.cpp @@ -80,31 +80,31 @@ class FPE_Encryptor public: FPE_Encryptor(const SymmetricKey& key, const BigInt& n, - const std::vector<byte>& tweak); + const std::vector<uint8_t>& tweak); BigInt operator()(size_t i, const BigInt& R); private: std::unique_ptr<MessageAuthenticationCode> m_mac; - std::vector<byte> m_mac_n_t; + std::vector<uint8_t> m_mac_n_t; }; FPE_Encryptor::FPE_Encryptor(const SymmetricKey& key, const BigInt& n, - const std::vector<byte>& tweak) + const std::vector<uint8_t>& tweak) { m_mac.reset(new HMAC(new SHA_256)); m_mac->set_key(key); - std::vector<byte> n_bin = BigInt::encode(n); + std::vector<uint8_t> n_bin = BigInt::encode(n); if(n_bin.size() > MAX_N_BYTES) throw Exception("N is too large for FPE encryption"); - m_mac->update_be(static_cast<u32bit>(n_bin.size())); + m_mac->update_be(static_cast<uint32_t>(n_bin.size())); m_mac->update(n_bin.data(), n_bin.size()); - m_mac->update_be(static_cast<u32bit>(tweak.size())); + m_mac->update_be(static_cast<uint32_t>(tweak.size())); m_mac->update(tweak.data(), tweak.size()); m_mac_n_t = unlock(m_mac->final()); @@ -112,15 +112,15 @@ FPE_Encryptor::FPE_Encryptor(const SymmetricKey& key, BigInt FPE_Encryptor::operator()(size_t round_no, const BigInt& R) { - secure_vector<byte> r_bin = BigInt::encode_locked(R); + secure_vector<uint8_t> r_bin = BigInt::encode_locked(R); m_mac->update(m_mac_n_t); - m_mac->update_be(static_cast<u32bit>(round_no)); + m_mac->update_be(static_cast<uint32_t>(round_no)); - m_mac->update_be(static_cast<u32bit>(r_bin.size())); + m_mac->update_be(static_cast<uint32_t>(r_bin.size())); m_mac->update(r_bin.data(), r_bin.size()); - secure_vector<byte> X = m_mac->final(); + secure_vector<uint8_t> X = m_mac->final(); return BigInt(X.data(), X.size()); } @@ -131,7 +131,7 @@ BigInt FPE_Encryptor::operator()(size_t round_no, const BigInt& R) */ BigInt fe1_encrypt(const BigInt& n, const BigInt& X0, const SymmetricKey& key, - const std::vector<byte>& tweak) + const std::vector<uint8_t>& tweak) { FPE_Encryptor F(key, n, tweak); @@ -159,7 +159,7 @@ BigInt fe1_encrypt(const BigInt& n, const BigInt& X0, */ BigInt fe1_decrypt(const BigInt& n, const BigInt& X0, const SymmetricKey& key, - const std::vector<byte>& tweak) + const std::vector<uint8_t>& tweak) { FPE_Encryptor F(key, n, tweak); diff --git a/src/lib/misc/fpe_fe1/fpe_fe1.h b/src/lib/misc/fpe_fe1/fpe_fe1.h index a1cae9917..fe86f0718 100644 --- a/src/lib/misc/fpe_fe1/fpe_fe1.h +++ b/src/lib/misc/fpe_fe1/fpe_fe1.h @@ -28,7 +28,7 @@ namespace FPE { */ BigInt BOTAN_DLL fe1_encrypt(const BigInt& n, const BigInt& X, const SymmetricKey& key, - const std::vector<byte>& tweak); + const std::vector<uint8_t>& tweak); /** * Decrypt X from and onto the group Z_n using key and tweak @@ -39,7 +39,7 @@ BigInt BOTAN_DLL fe1_encrypt(const BigInt& n, const BigInt& X, */ BigInt BOTAN_DLL fe1_decrypt(const BigInt& n, const BigInt& X, const SymmetricKey& key, - const std::vector<byte>& tweak); + const std::vector<uint8_t>& tweak); } diff --git a/src/lib/misc/rfc3394/rfc3394.cpp b/src/lib/misc/rfc3394/rfc3394.cpp index 9ec053ef3..2ec49ac65 100644 --- a/src/lib/misc/rfc3394/rfc3394.cpp +++ b/src/lib/misc/rfc3394/rfc3394.cpp @@ -12,7 +12,7 @@ namespace Botan { -secure_vector<byte> rfc3394_keywrap(const secure_vector<byte>& key, +secure_vector<uint8_t> rfc3394_keywrap(const secure_vector<uint8_t>& key, const SymmetricKey& kek) { if(key.size() % 8 != 0) @@ -27,8 +27,8 @@ secure_vector<byte> rfc3394_keywrap(const secure_vector<byte>& key, const size_t n = key.size() / 8; - secure_vector<byte> R((n + 1) * 8); - secure_vector<byte> A(16); + secure_vector<uint8_t> R((n + 1) * 8); + secure_vector<uint8_t> A(16); for(size_t i = 0; i != 8; ++i) A[i] = 0xA6; @@ -39,14 +39,14 @@ secure_vector<byte> rfc3394_keywrap(const secure_vector<byte>& key, { for(size_t i = 1; i <= n; ++i) { - const u32bit t = (n * j) + i; + const uint32_t t = (n * j) + i; copy_mem(&A[8], &R[8*i], 8); aes->encrypt(A.data()); copy_mem(&R[8*i], &A[8], 8); - byte t_buf[4] = { 0 }; + uint8_t t_buf[4] = { 0 }; store_be(t, t_buf); xor_buf(&A[4], t_buf, 4); } @@ -57,7 +57,7 @@ secure_vector<byte> rfc3394_keywrap(const secure_vector<byte>& key, return R; } -secure_vector<byte> rfc3394_keyunwrap(const secure_vector<byte>& key, +secure_vector<uint8_t> rfc3394_keyunwrap(const secure_vector<uint8_t>& key, const SymmetricKey& kek) { if(key.size() < 16 || key.size() % 8 != 0) @@ -72,8 +72,8 @@ secure_vector<byte> rfc3394_keyunwrap(const secure_vector<byte>& key, const size_t n = (key.size() - 8) / 8; - secure_vector<byte> R(n * 8); - secure_vector<byte> A(16); + secure_vector<uint8_t> R(n * 8); + secure_vector<uint8_t> A(16); for(size_t i = 0; i != 8; ++i) A[i] = key[i]; @@ -84,9 +84,9 @@ secure_vector<byte> rfc3394_keyunwrap(const secure_vector<byte>& key, { for(size_t i = n; i != 0; --i) { - const u32bit t = (5 - j) * n + i; + const uint32_t t = (5 - j) * n + i; - byte t_buf[4] = { 0 }; + uint8_t t_buf[4] = { 0 }; store_be(t, t_buf); xor_buf(&A[4], t_buf, 4); @@ -99,7 +99,7 @@ secure_vector<byte> rfc3394_keyunwrap(const secure_vector<byte>& key, } } - if(load_be<u64bit>(A.data(), 0) != 0xA6A6A6A6A6A6A6A6) + if(load_be<uint64_t>(A.data(), 0) != 0xA6A6A6A6A6A6A6A6) throw Integrity_Failure("NIST key unwrap failed"); return R; diff --git a/src/lib/misc/rfc3394/rfc3394.h b/src/lib/misc/rfc3394/rfc3394.h index af869505a..5690c4713 100644 --- a/src/lib/misc/rfc3394/rfc3394.h +++ b/src/lib/misc/rfc3394/rfc3394.h @@ -20,7 +20,7 @@ namespace Botan { * @param kek the key encryption key * @return key encrypted under kek */ -secure_vector<byte> BOTAN_DLL rfc3394_keywrap(const secure_vector<byte>& key, +secure_vector<uint8_t> BOTAN_DLL rfc3394_keywrap(const secure_vector<uint8_t>& key, const SymmetricKey& kek); /** @@ -31,7 +31,7 @@ secure_vector<byte> BOTAN_DLL rfc3394_keywrap(const secure_vector<byte>& key, * @param kek the key encryption key * @return key decrypted under kek */ -secure_vector<byte> BOTAN_DLL rfc3394_keyunwrap(const secure_vector<byte>& key, +secure_vector<uint8_t> BOTAN_DLL rfc3394_keyunwrap(const secure_vector<uint8_t>& key, const SymmetricKey& kek); } diff --git a/src/lib/misc/srp6/srp6.cpp b/src/lib/misc/srp6/srp6.cpp index f54726151..12107715f 100644 --- a/src/lib/misc/srp6/srp6.cpp +++ b/src/lib/misc/srp6/srp6.cpp @@ -29,7 +29,7 @@ BigInt hash_seq(const std::string& hash_id, BigInt compute_x(const std::string& hash_id, const std::string& identifier, const std::string& password, - const std::vector<byte>& salt) + const std::vector<uint8_t>& salt) { std::unique_ptr<HashFunction> hash_fn(HashFunction::create_or_throw(hash_id)); @@ -37,12 +37,12 @@ BigInt compute_x(const std::string& hash_id, hash_fn->update(":"); hash_fn->update(password); - secure_vector<byte> inner_h = hash_fn->final(); + secure_vector<uint8_t> inner_h = hash_fn->final(); hash_fn->update(salt); hash_fn->update(inner_h); - secure_vector<byte> outer_h = hash_fn->final(); + secure_vector<uint8_t> outer_h = hash_fn->final(); return BigInt::decode(outer_h); } @@ -77,7 +77,7 @@ srp6_client_agree(const std::string& identifier, const std::string& password, const std::string& group_id, const std::string& hash_id, - const std::vector<byte>& salt, + const std::vector<uint8_t>& salt, const BigInt& B, RandomNumberGenerator& rng) { @@ -109,7 +109,7 @@ srp6_client_agree(const std::string& identifier, BigInt generate_srp6_verifier(const std::string& identifier, const std::string& password, - const std::vector<byte>& salt, + const std::vector<uint8_t>& salt, const std::string& group_id, const std::string& hash_id) { diff --git a/src/lib/misc/srp6/srp6.h b/src/lib/misc/srp6/srp6.h index 5db433ad6..af9f427d0 100644 --- a/src/lib/misc/srp6/srp6.h +++ b/src/lib/misc/srp6/srp6.h @@ -33,7 +33,7 @@ BOTAN_DLL srp6_client_agree(const std::string& username, const std::string& password, const std::string& group_id, const std::string& hash_id, - const std::vector<byte>& salt, + const std::vector<uint8_t>& salt, const BigInt& B, RandomNumberGenerator& rng); @@ -47,7 +47,7 @@ BOTAN_DLL srp6_client_agree(const std::string& username, */ BigInt BOTAN_DLL generate_srp6_verifier(const std::string& identifier, const std::string& password, - const std::vector<byte>& salt, + const std::vector<uint8_t>& salt, const std::string& group_id, const std::string& hash_id); diff --git a/src/lib/misc/srp6/srp6_files.cpp b/src/lib/misc/srp6/srp6_files.cpp index 606c12ad7..0e1569a1c 100644 --- a/src/lib/misc/srp6/srp6_files.cpp +++ b/src/lib/misc/srp6/srp6_files.cpp @@ -28,7 +28,7 @@ SRP6_Authenticator_File::SRP6_Authenticator_File(std::istream& in) std::string username = parts[0]; BigInt v = BigInt::decode(base64_decode(parts[1])); - std::vector<byte> salt = unlock(base64_decode(parts[2])); + std::vector<uint8_t> salt = unlock(base64_decode(parts[2])); BigInt group_id_idx = BigInt::decode(base64_decode(parts[3])); std::string group_id; @@ -48,7 +48,7 @@ SRP6_Authenticator_File::SRP6_Authenticator_File(std::istream& in) bool SRP6_Authenticator_File::lookup_user(const std::string& username, BigInt& v, - std::vector<byte>& salt, + std::vector<uint8_t>& salt, std::string& group_id) const { std::map<std::string, SRP6_Data>::const_iterator i = m_entries.find(username); diff --git a/src/lib/misc/srp6/srp6_files.h b/src/lib/misc/srp6/srp6_files.h index 8c899aad6..124bfc86a 100644 --- a/src/lib/misc/srp6/srp6_files.h +++ b/src/lib/misc/srp6/srp6_files.h @@ -37,7 +37,7 @@ class BOTAN_DLL SRP6_Authenticator_File */ bool lookup_user(const std::string& username, BigInt& v, - std::vector<byte>& salt, + std::vector<uint8_t>& salt, std::string& group_id) const; private: struct SRP6_Data @@ -45,7 +45,7 @@ class BOTAN_DLL SRP6_Authenticator_File SRP6_Data() {} SRP6_Data(const BigInt& v_, - const std::vector<byte>& salt_, + const std::vector<uint8_t>& salt_, const std::string& group_id_) : v(v_), salt(salt_), group_id(group_id_) {} @@ -53,7 +53,7 @@ class BOTAN_DLL SRP6_Authenticator_File BigInt v; // public member variable: - std::vector<byte> salt; + std::vector<uint8_t> salt; // public member variable: std::string group_id; diff --git a/src/lib/misc/tss/tss.cpp b/src/lib/misc/tss/tss.cpp index b77e6c2b9..a7b0c4eac 100644 --- a/src/lib/misc/tss/tss.cpp +++ b/src/lib/misc/tss/tss.cpp @@ -18,7 +18,7 @@ namespace { /** Table for GF(2^8) arithmetic (exponentials) */ -const byte RTSS_EXP[256] = { +const uint8_t RTSS_EXP[256] = { 0x01, 0x03, 0x05, 0x0F, 0x11, 0x33, 0x55, 0xFF, 0x1A, 0x2E, 0x72, 0x96, 0xA1, 0xF8, 0x13, 0x35, 0x5F, 0xE1, 0x38, 0x48, 0xD8, 0x73, 0x95, 0xA4, 0xF7, 0x02, 0x06, 0x0A, 0x1E, 0x22, 0x66, 0xAA, 0xE5, @@ -47,7 +47,7 @@ const byte RTSS_EXP[256] = { /** Table for GF(2^8) arithmetic (logarithms) */ -const byte RTSS_LOG[] = { +const uint8_t RTSS_LOG[] = { 0x90, 0x00, 0x19, 0x01, 0x32, 0x02, 0x1A, 0xC6, 0x4B, 0xC7, 0x1B, 0x68, 0x33, 0xEE, 0xDF, 0x03, 0x64, 0x04, 0xE0, 0x0E, 0x34, 0x8D, 0x81, 0xEF, 0x4C, 0x71, 0x08, 0xC8, 0xF8, 0x69, 0x1C, 0xC1, 0x7D, @@ -73,14 +73,14 @@ const byte RTSS_LOG[] = { 0xED, 0xDE, 0xC5, 0x31, 0xFE, 0x18, 0x0D, 0x63, 0x8C, 0x80, 0xC0, 0xF7, 0x70, 0x07 }; -byte gfp_mul(byte x, byte y) +uint8_t gfp_mul(uint8_t x, uint8_t y) { if(x == 0 || y == 0) return 0; return RTSS_EXP[(RTSS_LOG[x] + RTSS_LOG[y]) % 255]; } -byte rtss_hash_id(const std::string& hash_name) +uint8_t rtss_hash_id(const std::string& hash_name) { if(hash_name == "SHA-160") return 1; @@ -90,7 +90,7 @@ byte rtss_hash_id(const std::string& hash_name) throw Invalid_Argument("RTSS only supports SHA-1 and SHA-256"); } -HashFunction* get_rtss_hash_by_id(byte id) +HashFunction* get_rtss_hash_by_id(uint8_t id) { if(id == 1) return new SHA_160; @@ -107,7 +107,7 @@ RTSS_Share::RTSS_Share(const std::string& hex_input) m_contents = hex_decode_locked(hex_input); } -byte RTSS_Share::share_id() const +uint8_t RTSS_Share::share_id() const { if(!initialized()) throw Invalid_State("RTSS_Share::share_id not initialized"); @@ -121,9 +121,9 @@ std::string RTSS_Share::to_string() const } std::vector<RTSS_Share> -RTSS_Share::split(byte M, byte N, - const byte S[], u16bit S_len, - const byte identifier[16], +RTSS_Share::split(uint8_t M, uint8_t N, + const uint8_t S[], uint16_t S_len, + const uint8_t identifier[16], RandomNumberGenerator& rng) { if(M == 0 || N == 0 || M > N) @@ -134,7 +134,7 @@ RTSS_Share::split(byte M, byte N, std::vector<RTSS_Share> shares(N); // Create RTSS header in each share - for(byte i = 0; i != N; ++i) + for(uint8_t i = 0; i != N; ++i) { shares[i].m_contents += std::make_pair(identifier, 16); shares[i].m_contents += rtss_hash_id(hash.name()); @@ -144,24 +144,24 @@ RTSS_Share::split(byte M, byte N, } // Choose sequential values for X starting from 1 - for(byte i = 0; i != N; ++i) + for(uint8_t i = 0; i != N; ++i) shares[i].m_contents.push_back(i+1); // secret = S || H(S) - secure_vector<byte> secret(S, S + S_len); + secure_vector<uint8_t> secret(S, S + S_len); secret += hash.process(S, S_len); for(size_t i = 0; i != secret.size(); ++i) { - std::vector<byte> coefficients(M-1); + std::vector<uint8_t> coefficients(M-1); rng.randomize(coefficients.data(), coefficients.size()); - for(byte j = 0; j != N; ++j) + for(uint8_t j = 0; j != N; ++j) { - const byte X = j + 1; + const uint8_t X = j + 1; - byte sum = secret[i]; - byte X_i = X; + uint8_t sum = secret[i]; + uint8_t X_i = X; for(size_t k = 0; k != coefficients.size(); ++k) { @@ -176,7 +176,7 @@ RTSS_Share::split(byte M, byte N, return shares; } -secure_vector<byte> +secure_vector<uint8_t> RTSS_Share::reconstruct(const std::vector<RTSS_Share>& shares) { const size_t RTSS_HEADER_SIZE = 20; @@ -198,41 +198,41 @@ RTSS_Share::reconstruct(const std::vector<RTSS_Share>& shares) if(shares.size() < shares[0].m_contents[17]) throw Decoding_Error("Insufficient shares to do TSS reconstruction"); - u16bit secret_len = make_u16bit(shares[0].m_contents[18], + uint16_t secret_len = make_uint16(shares[0].m_contents[18], shares[0].m_contents[19]); - byte hash_id = shares[0].m_contents[16]; + uint8_t hash_id = shares[0].m_contents[16]; std::unique_ptr<HashFunction> hash(get_rtss_hash_by_id(hash_id)); if(shares[0].size() != secret_len + hash->output_length() + RTSS_HEADER_SIZE + 1) throw Decoding_Error("Bad RTSS length field in header"); - std::vector<byte> V(shares.size()); - secure_vector<byte> secret; + std::vector<uint8_t> V(shares.size()); + secure_vector<uint8_t> secret; for(size_t i = RTSS_HEADER_SIZE + 1; i != shares[0].size(); ++i) { for(size_t j = 0; j != V.size(); ++j) V[j] = shares[j].m_contents[i]; - byte r = 0; + uint8_t r = 0; for(size_t k = 0; k != shares.size(); ++k) { // L_i function: - byte r2 = 1; + uint8_t r2 = 1; for(size_t l = 0; l != shares.size(); ++l) { if(k == l) continue; - byte share_k = shares[k].share_id(); - byte share_l = shares[l].share_id(); + uint8_t share_k = shares[k].share_id(); + uint8_t share_l = shares[l].share_id(); if(share_k == share_l) throw Decoding_Error("Duplicate shares found in RTSS recovery"); - byte div = RTSS_EXP[(255 + + uint8_t div = RTSS_EXP[(255 + RTSS_LOG[share_l] - RTSS_LOG[share_k ^ share_l]) % 255]; @@ -248,13 +248,13 @@ RTSS_Share::reconstruct(const std::vector<RTSS_Share>& shares) throw Decoding_Error("Bad length in RTSS output"); hash->update(secret.data(), secret_len); - secure_vector<byte> hash_check = hash->final(); + secure_vector<uint8_t> hash_check = hash->final(); if(!same_mem(hash_check.data(), &secret[secret_len], hash->output_length())) throw Decoding_Error("RTSS hash check failed"); - return secure_vector<byte>(secret.cbegin(), secret.cbegin() + secret_len); + return secure_vector<uint8_t>(secret.cbegin(), secret.cbegin() + secret_len); } } diff --git a/src/lib/misc/tss/tss.h b/src/lib/misc/tss/tss.h index 6ff47a0cc..79aa417c3 100644 --- a/src/lib/misc/tss/tss.h +++ b/src/lib/misc/tss/tss.h @@ -30,15 +30,15 @@ class BOTAN_DLL RTSS_Share * @param rng the random number generator to use */ static std::vector<RTSS_Share> - split(byte M, byte N, - const byte secret[], u16bit secret_len, - const byte identifier[16], + split(uint8_t M, uint8_t N, + const uint8_t secret[], uint16_t secret_len, + const uint8_t identifier[16], RandomNumberGenerator& rng); /** * @param shares the list of shares */ - static secure_vector<byte> + static secure_vector<uint8_t> reconstruct(const std::vector<RTSS_Share>& shares); RTSS_Share() {} @@ -56,7 +56,7 @@ class BOTAN_DLL RTSS_Share /** * @return share identifier */ - byte share_id() const; + uint8_t share_id() const; /** * @return size of this share in bytes @@ -68,7 +68,7 @@ class BOTAN_DLL RTSS_Share */ bool initialized() const { return (m_contents.size() > 0); } private: - secure_vector<byte> m_contents; + secure_vector<uint8_t> m_contents; }; } |