aboutsummaryrefslogtreecommitdiffstats
path: root/src/lib/block/cast
diff options
context:
space:
mode:
Diffstat (limited to 'src/lib/block/cast')
-rw-r--r--src/lib/block/cast/cast128.cpp46
-rw-r--r--src/lib/block/cast/cast128.h14
-rw-r--r--src/lib/block/cast/cast256.cpp42
-rw-r--r--src/lib/block/cast/cast256.h10
-rw-r--r--src/lib/block/cast/cast_sboxes.h8
5 files changed, 60 insertions, 60 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)];
diff --git a/src/lib/block/cast/cast128.h b/src/lib/block/cast/cast128.h
index 2782e96b9..96e543aed 100644
--- a/src/lib/block/cast/cast128.h
+++ b/src/lib/block/cast/cast128.h
@@ -18,21 +18,21 @@ namespace Botan {
class BOTAN_DLL CAST_128 final : public Block_Cipher_Fixed_Params<8, 11, 16>
{
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 "CAST-128"; }
BlockCipher* clone() const override { return new CAST_128; }
private:
- void key_schedule(const byte[], size_t) override;
+ void key_schedule(const uint8_t[], size_t) override;
- static void cast_ks(secure_vector<u32bit>& ks,
- secure_vector<u32bit>& user_key);
+ static void cast_ks(secure_vector<uint32_t>& ks,
+ secure_vector<uint32_t>& user_key);
- secure_vector<u32bit> m_MK;
- secure_vector<byte> m_RK;
+ secure_vector<uint32_t> m_MK;
+ secure_vector<uint8_t> m_RK;
};
}
diff --git a/src/lib/block/cast/cast256.cpp b/src/lib/block/cast/cast256.cpp
index 637fdfee2..a4a7dbd36 100644
--- a/src/lib/block/cast/cast256.cpp
+++ b/src/lib/block/cast/cast256.cpp
@@ -16,9 +16,9 @@ namespace {
/*
* CAST-256 Round Type 1
*/
-void round1(u32bit& out, u32bit in, u32bit mask, u32bit rot)
+void round1(uint32_t& out, uint32_t in, uint32_t mask, uint32_t rot)
{
- u32bit temp = rotate_left(mask + in, rot);
+ uint32_t temp = rotate_left(mask + in, rot);
out ^= (CAST_SBOX1[get_byte(0, temp)] ^ CAST_SBOX2[get_byte(1, temp)]) -
CAST_SBOX3[get_byte(2, temp)] + CAST_SBOX4[get_byte(3, temp)];
}
@@ -26,9 +26,9 @@ void round1(u32bit& out, u32bit in, u32bit mask, u32bit rot)
/*
* CAST-256 Round Type 2
*/
-void round2(u32bit& out, u32bit in, u32bit mask, u32bit rot)
+void round2(uint32_t& out, uint32_t in, uint32_t mask, uint32_t rot)
{
- u32bit temp = rotate_left(mask ^ in, rot);
+ uint32_t temp = rotate_left(mask ^ in, rot);
out ^= (CAST_SBOX1[get_byte(0, temp)] - CAST_SBOX2[get_byte(1, temp)] +
CAST_SBOX3[get_byte(2, temp)]) ^ CAST_SBOX4[get_byte(3, temp)];
}
@@ -36,9 +36,9 @@ void round2(u32bit& out, u32bit in, u32bit mask, u32bit rot)
/*
* CAST-256 Round Type 3
*/
-void round3(u32bit& out, u32bit in, u32bit mask, u32bit rot)
+void round3(uint32_t& out, uint32_t in, uint32_t mask, uint32_t rot)
{
- u32bit temp = rotate_left(mask - in, rot);
+ uint32_t temp = rotate_left(mask - in, rot);
out ^= ((CAST_SBOX1[get_byte(0, temp)] + CAST_SBOX2[get_byte(1, temp)]) ^
CAST_SBOX3[get_byte(2, temp)]) - CAST_SBOX4[get_byte(3, temp)];
}
@@ -48,14 +48,14 @@ void round3(u32bit& out, u32bit in, u32bit mask, u32bit rot)
/*
* CAST-256 Encryption
*/
-void CAST_256::encrypt_n(const byte in[], byte out[], size_t blocks) const
+void CAST_256::encrypt_n(const uint8_t in[], uint8_t out[], size_t blocks) const
{
for(size_t i = 0; i != blocks; ++i)
{
- u32bit A = load_be<u32bit>(in, 0);
- u32bit B = load_be<u32bit>(in, 1);
- u32bit C = load_be<u32bit>(in, 2);
- u32bit D = load_be<u32bit>(in, 3);
+ uint32_t A = load_be<uint32_t>(in, 0);
+ uint32_t B = load_be<uint32_t>(in, 1);
+ uint32_t C = load_be<uint32_t>(in, 2);
+ uint32_t D = load_be<uint32_t>(in, 3);
round1(C, D, m_MK[ 0], m_RK[ 0]); round2(B, C, m_MK[ 1], m_RK[ 1]);
round3(A, B, m_MK[ 2], m_RK[ 2]); round1(D, A, m_MK[ 3], m_RK[ 3]);
@@ -92,14 +92,14 @@ void CAST_256::encrypt_n(const byte in[], byte out[], size_t blocks) const
/*
* CAST-256 Decryption
*/
-void CAST_256::decrypt_n(const byte in[], byte out[], size_t blocks) const
+void CAST_256::decrypt_n(const uint8_t in[], uint8_t out[], size_t blocks) const
{
for(size_t i = 0; i != blocks; ++i)
{
- u32bit A = load_be<u32bit>(in, 0);
- u32bit B = load_be<u32bit>(in, 1);
- u32bit C = load_be<u32bit>(in, 2);
- u32bit D = load_be<u32bit>(in, 3);
+ uint32_t A = load_be<uint32_t>(in, 0);
+ uint32_t B = load_be<uint32_t>(in, 1);
+ uint32_t C = load_be<uint32_t>(in, 2);
+ uint32_t D = load_be<uint32_t>(in, 3);
round1(C, D, m_MK[44], m_RK[44]); round2(B, C, m_MK[45], m_RK[45]);
round3(A, B, m_MK[46], m_RK[46]); round1(D, A, m_MK[47], m_RK[47]);
@@ -136,9 +136,9 @@ void CAST_256::decrypt_n(const byte in[], byte out[], size_t blocks) const
/*
* CAST-256 Key Schedule
*/
-void CAST_256::key_schedule(const byte key[], size_t length)
+void CAST_256::key_schedule(const uint8_t key[], size_t length)
{
- static const u32bit KEY_MASK[192] = {
+ static const uint32_t KEY_MASK[192] = {
0x5A827999, 0xC95C653A, 0x383650DB, 0xA7103C7C, 0x15EA281D, 0x84C413BE,
0xF39DFF5F, 0x6277EB00, 0xD151D6A1, 0x402BC242, 0xAF05ADE3, 0x1DDF9984,
0x8CB98525, 0xFB9370C6, 0x6A6D5C67, 0xD9474808, 0x482133A9, 0xB6FB1F4A,
@@ -172,7 +172,7 @@ void CAST_256::key_schedule(const byte key[], size_t length)
0x4BBC26CD, 0xBA96126E, 0x296FFE0F, 0x9849E9B0, 0x0723D551, 0x75FDC0F2,
0xE4D7AC93, 0x53B19834, 0xC28B83D5, 0x31656F76, 0xA03F5B17, 0x0F1946B8 };
- static const byte KEY_ROT[32] = {
+ static const uint8_t KEY_ROT[32] = {
0x13, 0x04, 0x15, 0x06, 0x17, 0x08, 0x19, 0x0A, 0x1B, 0x0C,
0x1D, 0x0E, 0x1F, 0x10, 0x01, 0x12, 0x03, 0x14, 0x05, 0x16,
0x07, 0x18, 0x09, 0x1A, 0x0B, 0x1C, 0x0D, 0x1E, 0x0F, 0x00,
@@ -181,11 +181,11 @@ void CAST_256::key_schedule(const byte key[], size_t length)
m_MK.resize(48);
m_RK.resize(48);
- secure_vector<u32bit> K(8);
+ secure_vector<uint32_t> K(8);
for(size_t i = 0; i != length; ++i)
K[i/4] = (K[i/4] << 8) + key[i];
- u32bit A = K[0], B = K[1], C = K[2], D = K[3],
+ uint32_t A = K[0], B = K[1], C = K[2], D = K[3],
E = K[4], F = K[5], G = K[6], H = K[7];
for(size_t i = 0; i != 48; i += 4)
diff --git a/src/lib/block/cast/cast256.h b/src/lib/block/cast/cast256.h
index 086c94331..fe35abfba 100644
--- a/src/lib/block/cast/cast256.h
+++ b/src/lib/block/cast/cast256.h
@@ -18,17 +18,17 @@ namespace Botan {
class BOTAN_DLL CAST_256 final : public Block_Cipher_Fixed_Params<16, 4, 32, 4>
{
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 "CAST-256"; }
BlockCipher* clone() const override { return new CAST_256; }
private:
- void key_schedule(const byte[], size_t) override;
+ void key_schedule(const uint8_t[], size_t) override;
- secure_vector<u32bit> m_MK;
- secure_vector<byte> m_RK;
+ secure_vector<uint32_t> m_MK;
+ secure_vector<uint8_t> m_RK;
};
}
diff --git a/src/lib/block/cast/cast_sboxes.h b/src/lib/block/cast/cast_sboxes.h
index f73ce8142..c8d6a3a90 100644
--- a/src/lib/block/cast/cast_sboxes.h
+++ b/src/lib/block/cast/cast_sboxes.h
@@ -12,7 +12,7 @@
namespace Botan {
-const u32bit CAST_SBOX1[256] = {
+const uint32_t CAST_SBOX1[256] = {
0x30FB40D4, 0x9FA0FF0B, 0x6BECCD2F, 0x3F258C7A, 0x1E213F2F, 0x9C004DD3,
0x6003E540, 0xCF9FC949, 0xBFD4AF27, 0x88BBBDB5, 0xE2034090, 0x98D09675,
0x6E63A0E0, 0x15C361D2, 0xC2E7661D, 0x22D4FF8E, 0x28683B6F, 0xC07FD059,
@@ -57,7 +57,7 @@ const u32bit CAST_SBOX1[256] = {
0xB141AB08, 0x7CCA89B9, 0x1A69E783, 0x02CC4843, 0xA2F7C579, 0x429EF47D,
0x427B169C, 0x5AC9F049, 0xDD8F0F00, 0x5C8165BF };
-const u32bit CAST_SBOX2[256] = {
+const uint32_t CAST_SBOX2[256] = {
0x1F201094, 0xEF0BA75B, 0x69E3CF7E, 0x393F4380, 0xFE61CF7A, 0xEEC5207A,
0x55889C94, 0x72FC0651, 0xADA7EF79, 0x4E1D7235, 0xD55A63CE, 0xDE0436BA,
0x99C430EF, 0x5F0C0794, 0x18DCDB7D, 0xA1D6EFF3, 0xA0B52F7B, 0x59E83605,
@@ -102,7 +102,7 @@ const u32bit CAST_SBOX2[256] = {
0x5C038323, 0x3E5D3BB9, 0x43D79572, 0x7E6DD07C, 0x06DFDF1E, 0x6C6CC4EF,
0x7160A539, 0x73BFBE70, 0x83877605, 0x4523ECF1 };
-const u32bit CAST_SBOX3[256] = {
+const uint32_t CAST_SBOX3[256] = {
0x8DEFC240, 0x25FA5D9F, 0xEB903DBF, 0xE810C907, 0x47607FFF, 0x369FE44B,
0x8C1FC644, 0xAECECA90, 0xBEB1F9BF, 0xEEFBCAEA, 0xE8CF1950, 0x51DF07AE,
0x920E8806, 0xF0AD0548, 0xE13C8D83, 0x927010D5, 0x11107D9F, 0x07647DB9,
@@ -147,7 +147,7 @@ const u32bit CAST_SBOX3[256] = {
0x52BCE688, 0x1B03588A, 0xF7BAEFD5, 0x4142ED9C, 0xA4315C11, 0x83323EC5,
0xDFEF4636, 0xA133C501, 0xE9D3531C, 0xEE353783 };
-const u32bit CAST_SBOX4[256] = {
+const uint32_t CAST_SBOX4[256] = {
0x9DB30420, 0x1FB6E9DE, 0xA7BE7BEF, 0xD273A298, 0x4A4F7BDB, 0x64AD8C57,
0x85510443, 0xFA020ED1, 0x7E287AFF, 0xE60FB663, 0x095F35A1, 0x79EBF120,
0xFD059D43, 0x6497B7B1, 0xF3641F63, 0x241E4ADF, 0x28147F5F, 0x4FA2B8CD,