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/block/cast/cast128.cpp | |
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/block/cast/cast128.cpp')
-rw-r--r-- | src/lib/block/cast/cast128.cpp | 46 |
1 files changed, 23 insertions, 23 deletions
diff --git a/src/lib/block/cast/cast128.cpp b/src/lib/block/cast/cast128.cpp index 96c4f45a7..d955dfeef 100644 --- a/src/lib/block/cast/cast128.cpp +++ b/src/lib/block/cast/cast128.cpp @@ -16,9 +16,9 @@ namespace { /* * CAST-128 Round Type 1 */ -inline void R1(u32bit& L, u32bit R, u32bit MK, byte RK) +inline void R1(uint32_t& L, uint32_t R, uint32_t MK, uint8_t RK) { - u32bit T = rotate_left(MK + R, RK); + uint32_t T = rotate_left(MK + R, RK); L ^= (CAST_SBOX1[get_byte(0, T)] ^ CAST_SBOX2[get_byte(1, T)]) - CAST_SBOX3[get_byte(2, T)] + CAST_SBOX4[get_byte(3, T)]; } @@ -26,9 +26,9 @@ inline void R1(u32bit& L, u32bit R, u32bit MK, byte RK) /* * CAST-128 Round Type 2 */ -inline void R2(u32bit& L, u32bit R, u32bit MK, byte RK) +inline void R2(uint32_t& L, uint32_t R, uint32_t MK, uint8_t RK) { - u32bit T = rotate_left(MK ^ R, RK); + uint32_t T = rotate_left(MK ^ R, RK); L ^= (CAST_SBOX1[get_byte(0, T)] - CAST_SBOX2[get_byte(1, T)] + CAST_SBOX3[get_byte(2, T)]) ^ CAST_SBOX4[get_byte(3, T)]; } @@ -36,9 +36,9 @@ inline void R2(u32bit& L, u32bit R, u32bit MK, byte RK) /* * CAST-128 Round Type 3 */ -inline void R3(u32bit& L, u32bit R, u32bit MK, byte RK) +inline void R3(uint32_t& L, uint32_t R, uint32_t MK, uint8_t RK) { - u32bit T = rotate_left(MK - R, RK); + uint32_t T = rotate_left(MK - R, RK); L ^= ((CAST_SBOX1[get_byte(0, T)] + CAST_SBOX2[get_byte(1, T)]) ^ CAST_SBOX3[get_byte(2, T)]) - CAST_SBOX4[get_byte(3, T)]; } @@ -48,11 +48,11 @@ inline void R3(u32bit& L, u32bit R, u32bit MK, byte RK) /* * CAST-128 Encryption */ -void CAST_128::encrypt_n(const byte in[], byte out[], size_t blocks) const +void CAST_128::encrypt_n(const uint8_t in[], uint8_t out[], size_t blocks) const { BOTAN_PARALLEL_FOR(size_t i = 0; i < blocks; ++i) { - u32bit L, R; + uint32_t L, R; load_be(in + BLOCK_SIZE*i, L, R); R1(L, R, m_MK[ 0], m_RK[ 0]); @@ -79,11 +79,11 @@ void CAST_128::encrypt_n(const byte in[], byte out[], size_t blocks) const /* * CAST-128 Decryption */ -void CAST_128::decrypt_n(const byte in[], byte out[], size_t blocks) const +void CAST_128::decrypt_n(const uint8_t in[], uint8_t out[], size_t blocks) const { BOTAN_PARALLEL_FOR(size_t i = 0; i < blocks; ++i) { - u32bit L, R; + uint32_t L, R; load_be(in + BLOCK_SIZE*i, L, R); R1(L, R, m_MK[15], m_RK[15]); @@ -110,18 +110,18 @@ void CAST_128::decrypt_n(const byte in[], byte out[], size_t blocks) const /* * CAST-128 Key Schedule */ -void CAST_128::key_schedule(const byte key[], size_t length) +void CAST_128::key_schedule(const uint8_t key[], size_t length) { m_MK.resize(48); m_RK.resize(48); - secure_vector<u32bit> X(4); + secure_vector<uint32_t> X(4); for(size_t i = 0; i != length; ++i) X[i/4] = (X[i/4] << 8) + key[i]; cast_ks(m_MK, X); - secure_vector<u32bit> RK32(48); + secure_vector<uint32_t> RK32(48); cast_ks(RK32, X); for(size_t i = 0; i != 16; ++i) @@ -137,10 +137,10 @@ void CAST_128::clear() /* * S-Box Based Key Expansion */ -void CAST_128::cast_ks(secure_vector<u32bit>& K, - secure_vector<u32bit>& X) +void CAST_128::cast_ks(secure_vector<uint32_t>& K, + secure_vector<uint32_t>& X) { - static const u32bit S5[256] = { + static const uint32_t S5[256] = { 0x7EC90C04, 0x2C6E74B9, 0x9B0E66DF, 0xA6337911, 0xB86A7FFF, 0x1DD358F5, 0x44DD9D44, 0x1731167F, 0x08FBF1FA, 0xE7F511CC, 0xD2051B00, 0x735ABA00, 0x2AB722D8, 0x386381CB, 0xACF6243A, 0x69BEFD7A, 0xE6A2E77F, 0xF0C720CD, @@ -185,7 +185,7 @@ void CAST_128::cast_ks(secure_vector<u32bit>& K, 0x34010718, 0xBB30CAB8, 0xE822FE15, 0x88570983, 0x750E6249, 0xDA627E55, 0x5E76FFA8, 0xB1534546, 0x6D47DE08, 0xEFE9E7D4 }; - static const u32bit S6[256] = { + static const uint32_t S6[256] = { 0xF6FA8F9D, 0x2CAC6CE1, 0x4CA34867, 0xE2337F7C, 0x95DB08E7, 0x016843B4, 0xECED5CBC, 0x325553AC, 0xBF9F0960, 0xDFA1E2ED, 0x83F0579D, 0x63ED86B9, 0x1AB6A6B8, 0xDE5EBE39, 0xF38FF732, 0x8989B138, 0x33F14961, 0xC01937BD, @@ -230,7 +230,7 @@ void CAST_128::cast_ks(secure_vector<u32bit>& K, 0xB0E93524, 0xBEBB8FBD, 0xA2D762CF, 0x49C92F54, 0x38B5F331, 0x7128A454, 0x48392905, 0xA65B1DB8, 0x851C97BD, 0xD675CF2F }; - static const u32bit S7[256] = { + static const uint32_t S7[256] = { 0x85E04019, 0x332BF567, 0x662DBFFF, 0xCFC65693, 0x2A8D7F6F, 0xAB9BC912, 0xDE6008A1, 0x2028DA1F, 0x0227BCE7, 0x4D642916, 0x18FAC300, 0x50F18B82, 0x2CB2CB11, 0xB232E75C, 0x4B3695F2, 0xB28707DE, 0xA05FBCF6, 0xCD4181E9, @@ -275,7 +275,7 @@ void CAST_128::cast_ks(secure_vector<u32bit>& K, 0xC3C0BDAE, 0x4958C24C, 0x518F36B2, 0x84B1D370, 0x0FEDCE83, 0x878DDADA, 0xF2A279C7, 0x94E01BE8, 0x90716F4B, 0x954B8AA3 }; - static const u32bit S8[256] = { + static const uint32_t S8[256] = { 0xE216300D, 0xBBDDFFFC, 0xA7EBDABD, 0x35648095, 0x7789F8B7, 0xE6C1121B, 0x0E241600, 0x052CE8B5, 0x11A9CFB0, 0xE5952F11, 0xECE7990A, 0x9386D174, 0x2A42931C, 0x76E38111, 0xB12DEF3A, 0x37DDDDFC, 0xDE9ADEB1, 0x0A0CC32C, @@ -323,13 +323,13 @@ void CAST_128::cast_ks(secure_vector<u32bit>& K, class ByteReader { public: - byte operator()(size_t i) { return (m_X[i/4] >> (8*(3 - (i%4)))); } - explicit ByteReader(const u32bit* x) : m_X(x) {} + uint8_t operator()(size_t i) { return (m_X[i/4] >> (8*(3 - (i%4)))); } + explicit ByteReader(const uint32_t* x) : m_X(x) {} private: - const u32bit* m_X; + const uint32_t* m_X; }; - secure_vector<u32bit> Z(4); + secure_vector<uint32_t> Z(4); ByteReader x(X.data()), z(Z.data()); Z[0] = X[0] ^ S5[x(13)] ^ S6[x(15)] ^ S7[x(12)] ^ S8[x(14)] ^ S7[x( 8)]; |