aboutsummaryrefslogtreecommitdiffstats
path: root/src/lib/block/kasumi
diff options
context:
space:
mode:
authorJack Lloyd <[email protected]>2016-12-11 15:28:38 -0500
committerJack Lloyd <[email protected]>2016-12-18 16:48:24 -0500
commitf3cb3edb512bdcab498d825886c3366c341b3f78 (patch)
tree645c73ec295a5a34f25d99903b6d9fa9751e86d3 /src/lib/block/kasumi
parentc1dd21253c1f3188ff45d3ad47698efd08235ae8 (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/kasumi')
-rw-r--r--src/lib/block/kasumi/kasumi.cpp48
-rw-r--r--src/lib/block/kasumi/kasumi.h8
2 files changed, 28 insertions, 28 deletions
diff --git a/src/lib/block/kasumi/kasumi.cpp b/src/lib/block/kasumi/kasumi.cpp
index 014987bc6..92ad5dd14 100644
--- a/src/lib/block/kasumi/kasumi.cpp
+++ b/src/lib/block/kasumi/kasumi.cpp
@@ -15,7 +15,7 @@ namespace {
/*
* KASUMI S-Boxes
*/
-const byte KASUMI_SBOX_S7[128] = {
+const uint8_t KASUMI_SBOX_S7[128] = {
0x36, 0x32, 0x3E, 0x38, 0x16, 0x22, 0x5E, 0x60, 0x26, 0x06, 0x3F, 0x5D,
0x02, 0x12, 0x7B, 0x21, 0x37, 0x71, 0x27, 0x72, 0x15, 0x43, 0x41, 0x0C,
0x2F, 0x49, 0x2E, 0x1B, 0x19, 0x6F, 0x7C, 0x51, 0x35, 0x09, 0x79, 0x4F,
@@ -28,7 +28,7 @@ const byte KASUMI_SBOX_S7[128] = {
0x44, 0x1D, 0x73, 0x2C, 0x40, 0x6B, 0x6C, 0x18, 0x6E, 0x53, 0x24, 0x4E,
0x2A, 0x13, 0x0F, 0x29, 0x58, 0x77, 0x3B, 0x03 };
-const u16bit KASUMI_SBOX_S9[512] = {
+const uint16_t KASUMI_SBOX_S9[512] = {
0x00A7, 0x00EF, 0x00A1, 0x017B, 0x0187, 0x014E, 0x0009, 0x0152, 0x0026,
0x00E2, 0x0030, 0x0166, 0x01C4, 0x0181, 0x005A, 0x018D, 0x00B7, 0x00FD,
0x0093, 0x014B, 0x019F, 0x0154, 0x0033, 0x016A, 0x0132, 0x01F4, 0x0106,
@@ -90,10 +90,10 @@ const u16bit KASUMI_SBOX_S9[512] = {
/*
* KASUMI FI Function
*/
-u16bit FI(u16bit I, u16bit K)
+uint16_t FI(uint16_t I, uint16_t K)
{
- u16bit D9 = (I >> 7);
- byte D7 = (I & 0x7F);
+ uint16_t D9 = (I >> 7);
+ uint8_t D7 = (I & 0x7F);
D9 = KASUMI_SBOX_S9[D9] ^ D7;
D7 = KASUMI_SBOX_S7[D7] ^ (D9 & 0x7F);
@@ -108,21 +108,21 @@ u16bit FI(u16bit I, u16bit K)
/*
* KASUMI Encryption
*/
-void KASUMI::encrypt_n(const byte in[], byte out[], size_t blocks) const
+void KASUMI::encrypt_n(const uint8_t in[], uint8_t out[], size_t blocks) const
{
for(size_t i = 0; i != blocks; ++i)
{
- u16bit B0 = load_be<u16bit>(in, 0);
- u16bit B1 = load_be<u16bit>(in, 1);
- u16bit B2 = load_be<u16bit>(in, 2);
- u16bit B3 = load_be<u16bit>(in, 3);
+ uint16_t B0 = load_be<uint16_t>(in, 0);
+ uint16_t B1 = load_be<uint16_t>(in, 1);
+ uint16_t B2 = load_be<uint16_t>(in, 2);
+ uint16_t B3 = load_be<uint16_t>(in, 3);
for(size_t j = 0; j != 8; j += 2)
{
- const u16bit* K = &m_EK[8*j];
+ const uint16_t* K = &m_EK[8*j];
- u16bit R = B1 ^ (rotate_left(B0, 1) & K[0]);
- u16bit L = B0 ^ (rotate_left(R, 1) | K[1]);
+ uint16_t R = B1 ^ (rotate_left(B0, 1) & K[0]);
+ uint16_t L = B0 ^ (rotate_left(R, 1) | K[1]);
L = FI(L ^ K[ 2], K[ 3]) ^ R;
R = FI(R ^ K[ 4], K[ 5]) ^ L;
@@ -152,20 +152,20 @@ void KASUMI::encrypt_n(const byte in[], byte out[], size_t blocks) const
/*
* KASUMI Decryption
*/
-void KASUMI::decrypt_n(const byte in[], byte out[], size_t blocks) const
+void KASUMI::decrypt_n(const uint8_t in[], uint8_t out[], size_t blocks) const
{
for(size_t i = 0; i != blocks; ++i)
{
- u16bit B0 = load_be<u16bit>(in, 0);
- u16bit B1 = load_be<u16bit>(in, 1);
- u16bit B2 = load_be<u16bit>(in, 2);
- u16bit B3 = load_be<u16bit>(in, 3);
+ uint16_t B0 = load_be<uint16_t>(in, 0);
+ uint16_t B1 = load_be<uint16_t>(in, 1);
+ uint16_t B2 = load_be<uint16_t>(in, 2);
+ uint16_t B3 = load_be<uint16_t>(in, 3);
for(size_t j = 0; j != 8; j += 2)
{
- const u16bit* K = &m_EK[8*(6-j)];
+ const uint16_t* K = &m_EK[8*(6-j)];
- u16bit L = B2, R = B3;
+ uint16_t L = B2, R = B3;
L = FI(L ^ K[10], K[11]) ^ R;
R = FI(R ^ K[12], K[13]) ^ L;
@@ -198,15 +198,15 @@ void KASUMI::decrypt_n(const byte in[], byte out[], size_t blocks) const
/*
* KASUMI Key Schedule
*/
-void KASUMI::key_schedule(const byte key[], size_t)
+void KASUMI::key_schedule(const uint8_t key[], size_t)
{
- static const u16bit RC[] = { 0x0123, 0x4567, 0x89AB, 0xCDEF,
+ static const uint16_t RC[] = { 0x0123, 0x4567, 0x89AB, 0xCDEF,
0xFEDC, 0xBA98, 0x7654, 0x3210 };
- secure_vector<u16bit> K(16);
+ secure_vector<uint16_t> K(16);
for(size_t i = 0; i != 8; ++i)
{
- K[i] = load_be<u16bit>(key, i);
+ K[i] = load_be<uint16_t>(key, i);
K[i+8] = K[i] ^ RC[i];
}
diff --git a/src/lib/block/kasumi/kasumi.h b/src/lib/block/kasumi/kasumi.h
index 24fd83050..4c6acdadd 100644
--- a/src/lib/block/kasumi/kasumi.h
+++ b/src/lib/block/kasumi/kasumi.h
@@ -18,16 +18,16 @@ namespace Botan {
class BOTAN_DLL KASUMI final : public Block_Cipher_Fixed_Params<8, 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 "KASUMI"; }
BlockCipher* clone() const override { return new KASUMI; }
private:
- void key_schedule(const byte[], size_t) override;
+ void key_schedule(const uint8_t[], size_t) override;
- secure_vector<u16bit> m_EK;
+ secure_vector<uint16_t> m_EK;
};
}