diff options
Diffstat (limited to 'src/lib/block/twofish')
-rw-r--r-- | src/lib/block/twofish/twofish.cpp | 38 | ||||
-rw-r--r-- | src/lib/block/twofish/twofish.h | 30 | ||||
-rw-r--r-- | src/lib/block/twofish/twofish_tab.cpp | 18 |
3 files changed, 43 insertions, 43 deletions
diff --git a/src/lib/block/twofish/twofish.cpp b/src/lib/block/twofish/twofish.cpp index 0b30d4080..51ef01ea9 100644 --- a/src/lib/block/twofish/twofish.cpp +++ b/src/lib/block/twofish/twofish.cpp @@ -17,11 +17,11 @@ namespace Botan { /* * Twofish Encryption */ -void Twofish::encrypt_n(const byte in[], byte out[], size_t blocks) const +void Twofish::encrypt_n(const uint8_t in[], uint8_t out[], size_t blocks) const { BOTAN_PARALLEL_FOR(size_t i = 0; i < blocks; ++i) { - u32bit A, B, C, D; + uint32_t A, B, C, D; load_le(in + BLOCK_SIZE*i, A, B, C, D); A ^= m_RK[0]; @@ -31,7 +31,7 @@ void Twofish::encrypt_n(const byte in[], byte out[], size_t blocks) const for(size_t j = 0; j != 16; j += 2) { - u32bit X, Y; + uint32_t X, Y; X = m_SB[ get_byte(3, A)] ^ m_SB[256+get_byte(2, A)] ^ m_SB[512+get_byte(1, A)] ^ m_SB[768+get_byte(0, A)]; @@ -68,11 +68,11 @@ void Twofish::encrypt_n(const byte in[], byte out[], size_t blocks) const /* * Twofish Decryption */ -void Twofish::decrypt_n(const byte in[], byte out[], size_t blocks) const +void Twofish::decrypt_n(const uint8_t in[], uint8_t out[], size_t blocks) const { BOTAN_PARALLEL_FOR(size_t i = 0; i < blocks; ++i) { - u32bit A, B, C, D; + uint32_t A, B, C, D; load_le(in + BLOCK_SIZE*i, A, B, C, D); A ^= m_RK[4]; @@ -82,7 +82,7 @@ void Twofish::decrypt_n(const byte in[], byte out[], size_t blocks) const for(size_t j = 0; j != 16; j += 2) { - u32bit X, Y; + uint32_t X, Y; X = m_SB[ get_byte(3, A)] ^ m_SB[256+get_byte(2, A)] ^ m_SB[512+get_byte(1, A)] ^ m_SB[768+get_byte(0, A)]; @@ -119,12 +119,12 @@ void Twofish::decrypt_n(const byte in[], byte out[], size_t blocks) const /* * Twofish Key Schedule */ -void Twofish::key_schedule(const byte key[], size_t length) +void Twofish::key_schedule(const uint8_t key[], size_t length) { m_SB.resize(1024); m_RK.resize(40); - secure_vector<byte> S(16); + secure_vector<uint8_t> S(16); for(size_t i = 0; i != length; ++i) { @@ -133,12 +133,12 @@ void Twofish::key_schedule(const byte key[], size_t length) */ if(key[i]) { - byte X = POLY_TO_EXP[key[i] - 1]; + uint8_t X = POLY_TO_EXP[key[i] - 1]; - byte RS1 = RS[(4*i ) % 32]; - byte RS2 = RS[(4*i+1) % 32]; - byte RS3 = RS[(4*i+2) % 32]; - byte RS4 = RS[(4*i+3) % 32]; + uint8_t RS1 = RS[(4*i ) % 32]; + uint8_t RS2 = RS[(4*i+1) % 32]; + uint8_t RS3 = RS[(4*i+2) % 32]; + uint8_t RS4 = RS[(4*i+3) % 32]; S[4*(i/8) ] ^= EXP_TO_POLY[(X + POLY_TO_EXP[RS1 - 1]) % 255]; S[4*(i/8)+1] ^= EXP_TO_POLY[(X + POLY_TO_EXP[RS2 - 1]) % 255]; @@ -159,11 +159,11 @@ void Twofish::key_schedule(const byte key[], size_t length) BOTAN_PARALLEL_FOR(size_t i = 0; i < 40; i += 2) { - u32bit X = MDS0[Q0[Q0[i ]^key[ 8]]^key[ 0]] ^ + uint32_t X = MDS0[Q0[Q0[i ]^key[ 8]]^key[ 0]] ^ MDS1[Q0[Q1[i ]^key[ 9]]^key[ 1]] ^ MDS2[Q1[Q0[i ]^key[10]]^key[ 2]] ^ MDS3[Q1[Q1[i ]^key[11]]^key[ 3]]; - u32bit Y = MDS0[Q0[Q0[i+1]^key[12]]^key[ 4]] ^ + uint32_t Y = MDS0[Q0[Q0[i+1]^key[12]]^key[ 4]] ^ MDS1[Q0[Q1[i+1]^key[13]]^key[ 5]] ^ MDS2[Q1[Q0[i+1]^key[14]]^key[ 6]] ^ MDS3[Q1[Q1[i+1]^key[15]]^key[ 7]]; @@ -186,11 +186,11 @@ void Twofish::key_schedule(const byte key[], size_t length) BOTAN_PARALLEL_FOR(size_t i = 0; i < 40; i += 2) { - u32bit X = MDS0[Q0[Q0[Q1[i ]^key[16]]^key[ 8]]^key[ 0]] ^ + uint32_t X = MDS0[Q0[Q0[Q1[i ]^key[16]]^key[ 8]]^key[ 0]] ^ MDS1[Q0[Q1[Q1[i ]^key[17]]^key[ 9]]^key[ 1]] ^ MDS2[Q1[Q0[Q0[i ]^key[18]]^key[10]]^key[ 2]] ^ MDS3[Q1[Q1[Q0[i ]^key[19]]^key[11]]^key[ 3]]; - u32bit Y = MDS0[Q0[Q0[Q1[i+1]^key[20]]^key[12]]^key[ 4]] ^ + uint32_t Y = MDS0[Q0[Q0[Q1[i+1]^key[20]]^key[12]]^key[ 4]] ^ MDS1[Q0[Q1[Q1[i+1]^key[21]]^key[13]]^key[ 5]] ^ MDS2[Q1[Q0[Q0[i+1]^key[22]]^key[14]]^key[ 6]] ^ MDS3[Q1[Q1[Q0[i+1]^key[23]]^key[15]]^key[ 7]]; @@ -213,11 +213,11 @@ void Twofish::key_schedule(const byte key[], size_t length) BOTAN_PARALLEL_FOR(size_t i = 0; i < 40; i += 2) { - u32bit X = MDS0[Q0[Q0[Q1[Q1[i ]^key[24]]^key[16]]^key[ 8]]^key[ 0]] ^ + uint32_t X = MDS0[Q0[Q0[Q1[Q1[i ]^key[24]]^key[16]]^key[ 8]]^key[ 0]] ^ MDS1[Q0[Q1[Q1[Q0[i ]^key[25]]^key[17]]^key[ 9]]^key[ 1]] ^ MDS2[Q1[Q0[Q0[Q0[i ]^key[26]]^key[18]]^key[10]]^key[ 2]] ^ MDS3[Q1[Q1[Q0[Q1[i ]^key[27]]^key[19]]^key[11]]^key[ 3]]; - u32bit Y = MDS0[Q0[Q0[Q1[Q1[i+1]^key[28]]^key[20]]^key[12]]^key[ 4]] ^ + uint32_t Y = MDS0[Q0[Q0[Q1[Q1[i+1]^key[28]]^key[20]]^key[12]]^key[ 4]] ^ MDS1[Q0[Q1[Q1[Q0[i+1]^key[29]]^key[21]]^key[13]]^key[ 5]] ^ MDS2[Q1[Q0[Q0[Q0[i+1]^key[30]]^key[22]]^key[14]]^key[ 6]] ^ MDS3[Q1[Q1[Q0[Q1[i+1]^key[31]]^key[23]]^key[15]]^key[ 7]]; diff --git a/src/lib/block/twofish/twofish.h b/src/lib/block/twofish/twofish.h index b8021263e..50168ffdf 100644 --- a/src/lib/block/twofish/twofish.h +++ b/src/lib/block/twofish/twofish.h @@ -18,26 +18,26 @@ namespace Botan { class BOTAN_DLL Twofish final : public Block_Cipher_Fixed_Params<16, 16, 32, 8> { public: - void encrypt_n(const byte in[], byte out[], size_t blocks) const override; - void decrypt_n(const byte in[], byte out[], size_t blocks) const override; + void encrypt_n(const uint8_t in[], uint8_t out[], size_t blocks) const override; + void decrypt_n(const uint8_t in[], uint8_t out[], size_t blocks) const override; void clear() override; std::string name() const override { return "Twofish"; } BlockCipher* clone() const override { return new Twofish; } private: - void key_schedule(const byte[], size_t) override; - - static const u32bit MDS0[256]; - static const u32bit MDS1[256]; - static const u32bit MDS2[256]; - static const u32bit MDS3[256]; - static const byte Q0[256]; - static const byte Q1[256]; - static const byte RS[32]; - static const byte EXP_TO_POLY[255]; - static const byte POLY_TO_EXP[255]; - - secure_vector<u32bit> m_SB, m_RK; + void key_schedule(const uint8_t[], size_t) override; + + static const uint32_t MDS0[256]; + static const uint32_t MDS1[256]; + static const uint32_t MDS2[256]; + static const uint32_t MDS3[256]; + static const uint8_t Q0[256]; + static const uint8_t Q1[256]; + static const uint8_t RS[32]; + static const uint8_t EXP_TO_POLY[255]; + static const uint8_t POLY_TO_EXP[255]; + + secure_vector<uint32_t> m_SB, m_RK; }; } diff --git a/src/lib/block/twofish/twofish_tab.cpp b/src/lib/block/twofish/twofish_tab.cpp index 6eb6b62f0..d6ac8f41b 100644 --- a/src/lib/block/twofish/twofish_tab.cpp +++ b/src/lib/block/twofish/twofish_tab.cpp @@ -9,7 +9,7 @@ namespace Botan { -const byte Twofish::Q0[256] = { +const uint8_t Twofish::Q0[256] = { 0xA9, 0x67, 0xB3, 0xE8, 0x04, 0xFD, 0xA3, 0x76, 0x9A, 0x92, 0x80, 0x78, 0xE4, 0xDD, 0xD1, 0x38, 0x0D, 0xC6, 0x35, 0x98, 0x18, 0xF7, 0xEC, 0x6C, 0x43, 0x75, 0x37, 0x26, 0xFA, 0x13, 0x94, 0x48, 0xF2, 0xD0, 0x8B, 0x30, @@ -33,7 +33,7 @@ const byte Twofish::Q0[256] = { 0xCA, 0x10, 0x21, 0xF0, 0xD3, 0x5D, 0x0F, 0x00, 0x6F, 0x9D, 0x36, 0x42, 0x4A, 0x5E, 0xC1, 0xE0 }; -const byte Twofish::Q1[256] = { +const uint8_t Twofish::Q1[256] = { 0x75, 0xF3, 0xC6, 0xF4, 0xDB, 0x7B, 0xFB, 0xC8, 0x4A, 0xD3, 0xE6, 0x6B, 0x45, 0x7D, 0xE8, 0x4B, 0xD6, 0x32, 0xD8, 0xFD, 0x37, 0x71, 0xF1, 0xE1, 0x30, 0x0F, 0xF8, 0x1B, 0x87, 0xFA, 0x06, 0x3F, 0x5E, 0xBA, 0xAE, 0x5B, @@ -57,12 +57,12 @@ const byte Twofish::Q1[256] = { 0xD7, 0x61, 0x1E, 0xB4, 0x50, 0x04, 0xF6, 0xC2, 0x16, 0x25, 0x86, 0x56, 0x55, 0x09, 0xBE, 0x91 }; -const byte Twofish::RS[32] = { +const uint8_t Twofish::RS[32] = { 0x01, 0xA4, 0x02, 0xA4, 0xA4, 0x56, 0xA1, 0x55, 0x55, 0x82, 0xFC, 0x87, 0x87, 0xF3, 0xC1, 0x5A, 0x5A, 0x1E, 0x47, 0x58, 0x58, 0xC6, 0xAE, 0xDB, 0xDB, 0x68, 0x3D, 0x9E, 0x9E, 0xE5, 0x19, 0x03 }; -const byte Twofish::EXP_TO_POLY[255] = { +const uint8_t Twofish::EXP_TO_POLY[255] = { 0x01, 0x02, 0x04, 0x08, 0x10, 0x20, 0x40, 0x80, 0x4D, 0x9A, 0x79, 0xF2, 0xA9, 0x1F, 0x3E, 0x7C, 0xF8, 0xBD, 0x37, 0x6E, 0xDC, 0xF5, 0xA7, 0x03, 0x06, 0x0C, 0x18, 0x30, 0x60, 0xC0, 0xCD, 0xD7, 0xE3, 0x8B, 0x5B, 0xB6, @@ -86,7 +86,7 @@ const byte Twofish::EXP_TO_POLY[255] = { 0x3B, 0x76, 0xEC, 0x95, 0x67, 0xCE, 0xD1, 0xEF, 0x93, 0x6B, 0xD6, 0xE1, 0x8F, 0x53, 0xA6 }; -const byte Twofish::POLY_TO_EXP[255] = { +const uint8_t Twofish::POLY_TO_EXP[255] = { 0x00, 0x01, 0x17, 0x02, 0x2E, 0x18, 0x53, 0x03, 0x6A, 0x2F, 0x93, 0x19, 0x34, 0x54, 0x45, 0x04, 0x5C, 0x6B, 0xB6, 0x30, 0xA6, 0x94, 0x4B, 0x1A, 0x8C, 0x35, 0x81, 0x55, 0xAA, 0x46, 0x0D, 0x05, 0x24, 0x5D, 0x87, 0x6C, @@ -110,7 +110,7 @@ const byte Twofish::POLY_TO_EXP[255] = { 0xB4, 0x0B, 0x7F, 0x51, 0x15, 0x43, 0x91, 0x10, 0x71, 0xBB, 0xEE, 0xBF, 0x85, 0xC8, 0xA1 }; -const u32bit Twofish::MDS0[256] = { +const uint32_t Twofish::MDS0[256] = { 0xBCBC3275, 0xECEC21F3, 0x202043C6, 0xB3B3C9F4, 0xDADA03DB, 0x02028B7B, 0xE2E22BFB, 0x9E9EFAC8, 0xC9C9EC4A, 0xD4D409D3, 0x18186BE6, 0x1E1E9F6B, 0x98980E45, 0xB2B2387D, 0xA6A6D2E8, 0x2626B74B, 0x3C3C57D6, 0x93938A32, @@ -155,7 +155,7 @@ const u32bit Twofish::MDS0[256] = { 0x04047FF6, 0x272746C2, 0xACACA716, 0xD0D07625, 0x50501386, 0xDCDCF756, 0x84841A55, 0xE1E15109, 0x7A7A25BE, 0x1313EF91 }; -const u32bit Twofish::MDS1[256] = { +const uint32_t Twofish::MDS1[256] = { 0xA9D93939, 0x67901717, 0xB3719C9C, 0xE8D2A6A6, 0x04050707, 0xFD985252, 0xA3658080, 0x76DFE4E4, 0x9A084545, 0x92024B4B, 0x80A0E0E0, 0x78665A5A, 0xE4DDAFAF, 0xDDB06A6A, 0xD1BF6363, 0x38362A2A, 0x0D54E6E6, 0xC6432020, @@ -200,7 +200,7 @@ const u32bit Twofish::MDS1[256] = { 0x0FE25151, 0x00000000, 0x6F9A1919, 0x9DE01A1A, 0x368F9494, 0x42E6C7C7, 0x4AECC9C9, 0x5EFDD2D2, 0xC1AB7F7F, 0xE0D8A8A8 }; -const u32bit Twofish::MDS2[256] = { +const uint32_t Twofish::MDS2[256] = { 0xBC75BC32, 0xECF3EC21, 0x20C62043, 0xB3F4B3C9, 0xDADBDA03, 0x027B028B, 0xE2FBE22B, 0x9EC89EFA, 0xC94AC9EC, 0xD4D3D409, 0x18E6186B, 0x1E6B1E9F, 0x9845980E, 0xB27DB238, 0xA6E8A6D2, 0x264B26B7, 0x3CD63C57, 0x9332938A, @@ -245,7 +245,7 @@ const u32bit Twofish::MDS2[256] = { 0x04F6047F, 0x27C22746, 0xAC16ACA7, 0xD025D076, 0x50865013, 0xDC56DCF7, 0x8455841A, 0xE109E151, 0x7ABE7A25, 0x139113EF }; -const u32bit Twofish::MDS3[256] = { +const uint32_t Twofish::MDS3[256] = { 0xD939A9D9, 0x90176790, 0x719CB371, 0xD2A6E8D2, 0x05070405, 0x9852FD98, 0x6580A365, 0xDFE476DF, 0x08459A08, 0x024B9202, 0xA0E080A0, 0x665A7866, 0xDDAFE4DD, 0xB06ADDB0, 0xBF63D1BF, 0x362A3836, 0x54E60D54, 0x4320C643, |