diff options
Diffstat (limited to 'src/lib/block/kasumi/kasumi.cpp')
-rw-r--r-- | src/lib/block/kasumi/kasumi.cpp | 48 |
1 files changed, 24 insertions, 24 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]; } |