aboutsummaryrefslogtreecommitdiffstats
path: root/src/lib/block/des/des.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/lib/block/des/des.cpp')
-rw-r--r--src/lib/block/des/des.cpp56
1 files changed, 28 insertions, 28 deletions
diff --git a/src/lib/block/des/des.cpp b/src/lib/block/des/des.cpp
index a55c43ec7..44f315047 100644
--- a/src/lib/block/des/des.cpp
+++ b/src/lib/block/des/des.cpp
@@ -18,12 +18,12 @@ namespace {
/*
* DES Key Schedule
*/
-void des_key_schedule(u32bit round_key[32], const byte key[8])
+void des_key_schedule(uint32_t round_key[32], const uint8_t key[8])
{
- static const byte ROT[16] = { 1, 1, 2, 2, 2, 2, 2, 2,
+ static const uint8_t ROT[16] = { 1, 1, 2, 2, 2, 2, 2, 2,
1, 2, 2, 2, 2, 2, 2, 1 };
- u32bit C = ((key[7] & 0x80) << 20) | ((key[6] & 0x80) << 19) |
+ uint32_t C = ((key[7] & 0x80) << 20) | ((key[6] & 0x80) << 19) |
((key[5] & 0x80) << 18) | ((key[4] & 0x80) << 17) |
((key[3] & 0x80) << 16) | ((key[2] & 0x80) << 15) |
((key[1] & 0x80) << 14) | ((key[0] & 0x80) << 13) |
@@ -37,7 +37,7 @@ void des_key_schedule(u32bit round_key[32], const byte key[8])
((key[1] & 0x20) ) | ((key[0] & 0x20) >> 1) |
((key[7] & 0x10) >> 1) | ((key[6] & 0x10) >> 2) |
((key[5] & 0x10) >> 3) | ((key[4] & 0x10) >> 4);
- u32bit D = ((key[7] & 0x02) << 26) | ((key[6] & 0x02) << 25) |
+ uint32_t D = ((key[7] & 0x02) << 26) | ((key[6] & 0x02) << 25) |
((key[5] & 0x02) << 24) | ((key[4] & 0x02) << 23) |
((key[3] & 0x02) << 22) | ((key[2] & 0x02) << 21) |
((key[1] & 0x02) << 20) | ((key[0] & 0x02) << 19) |
@@ -84,12 +84,12 @@ void des_key_schedule(u32bit round_key[32], const byte key[8])
/*
* DES Encryption
*/
-void des_encrypt(u32bit& L, u32bit& R,
- const u32bit round_key[32])
+void des_encrypt(uint32_t& L, uint32_t& R,
+ const uint32_t round_key[32])
{
for(size_t i = 0; i != 16; i += 2)
{
- u32bit T0, T1;
+ uint32_t T0, T1;
T0 = rotate_right(R, 4) ^ round_key[2*i];
T1 = R ^ round_key[2*i + 1];
@@ -112,12 +112,12 @@ void des_encrypt(u32bit& L, u32bit& R,
/*
* DES Decryption
*/
-void des_decrypt(u32bit& L, u32bit& R,
- const u32bit round_key[32])
+void des_decrypt(uint32_t& L, uint32_t& R,
+ const uint32_t round_key[32])
{
for(size_t i = 16; i != 0; i -= 2)
{
- u32bit T0, T1;
+ uint32_t T0, T1;
T0 = rotate_right(R, 4) ^ round_key[2*i - 2];
T1 = R ^ round_key[2*i - 1];
@@ -142,17 +142,17 @@ void des_decrypt(u32bit& L, u32bit& R,
/*
* DES Encryption
*/
-void DES::encrypt_n(const byte in[], byte out[], size_t blocks) const
+void DES::encrypt_n(const uint8_t in[], uint8_t out[], size_t blocks) const
{
for(size_t i = 0; i < blocks; ++i)
{
- u64bit T = (DES_IPTAB1[in[8*i+0]] ) | (DES_IPTAB1[in[8*i+1]] << 1) |
+ uint64_t T = (DES_IPTAB1[in[8*i+0]] ) | (DES_IPTAB1[in[8*i+1]] << 1) |
(DES_IPTAB1[in[8*i+2]] << 2) | (DES_IPTAB1[in[8*i+3]] << 3) |
(DES_IPTAB1[in[8*i+4]] << 4) | (DES_IPTAB1[in[8*i+5]] << 5) |
(DES_IPTAB1[in[8*i+6]] << 6) | (DES_IPTAB2[in[8*i+7]] );
- u32bit L = static_cast<u32bit>(T >> 32);
- u32bit R = static_cast<u32bit>(T);
+ uint32_t L = static_cast<uint32_t>(T >> 32);
+ uint32_t R = static_cast<uint32_t>(T);
des_encrypt(L, R, m_round_key.data());
@@ -169,17 +169,17 @@ void DES::encrypt_n(const byte in[], byte out[], size_t blocks) const
/*
* DES Decryption
*/
-void DES::decrypt_n(const byte in[], byte out[], size_t blocks) const
+void DES::decrypt_n(const uint8_t in[], uint8_t out[], size_t blocks) const
{
for(size_t i = 0; i < blocks; ++i)
{
- u64bit T = (DES_IPTAB1[in[BLOCK_SIZE*i+0]] ) | (DES_IPTAB1[in[BLOCK_SIZE*i+1]] << 1) |
+ uint64_t T = (DES_IPTAB1[in[BLOCK_SIZE*i+0]] ) | (DES_IPTAB1[in[BLOCK_SIZE*i+1]] << 1) |
(DES_IPTAB1[in[BLOCK_SIZE*i+2]] << 2) | (DES_IPTAB1[in[BLOCK_SIZE*i+3]] << 3) |
(DES_IPTAB1[in[BLOCK_SIZE*i+4]] << 4) | (DES_IPTAB1[in[BLOCK_SIZE*i+5]] << 5) |
(DES_IPTAB1[in[BLOCK_SIZE*i+6]] << 6) | (DES_IPTAB2[in[BLOCK_SIZE*i+7]] );
- u32bit L = static_cast<u32bit>(T >> 32);
- u32bit R = static_cast<u32bit>(T);
+ uint32_t L = static_cast<uint32_t>(T >> 32);
+ uint32_t R = static_cast<uint32_t>(T);
des_decrypt(L, R, m_round_key.data());
@@ -197,7 +197,7 @@ void DES::decrypt_n(const byte in[], byte out[], size_t blocks) const
/*
* DES Key Schedule
*/
-void DES::key_schedule(const byte key[], size_t)
+void DES::key_schedule(const uint8_t key[], size_t)
{
m_round_key.resize(32);
des_key_schedule(m_round_key.data(), key);
@@ -211,17 +211,17 @@ void DES::clear()
/*
* TripleDES Encryption
*/
-void TripleDES::encrypt_n(const byte in[], byte out[], size_t blocks) const
+void TripleDES::encrypt_n(const uint8_t in[], uint8_t out[], size_t blocks) const
{
for(size_t i = 0; i != blocks; ++i)
{
- u64bit T = (DES_IPTAB1[in[0]] ) | (DES_IPTAB1[in[1]] << 1) |
+ uint64_t T = (DES_IPTAB1[in[0]] ) | (DES_IPTAB1[in[1]] << 1) |
(DES_IPTAB1[in[2]] << 2) | (DES_IPTAB1[in[3]] << 3) |
(DES_IPTAB1[in[4]] << 4) | (DES_IPTAB1[in[5]] << 5) |
(DES_IPTAB1[in[6]] << 6) | (DES_IPTAB2[in[7]] );
- u32bit L = static_cast<u32bit>(T >> 32);
- u32bit R = static_cast<u32bit>(T);
+ uint32_t L = static_cast<uint32_t>(T >> 32);
+ uint32_t R = static_cast<uint32_t>(T);
des_encrypt(L, R, &m_round_key[0]);
des_decrypt(R, L, &m_round_key[32]);
@@ -244,17 +244,17 @@ void TripleDES::encrypt_n(const byte in[], byte out[], size_t blocks) const
/*
* TripleDES Decryption
*/
-void TripleDES::decrypt_n(const byte in[], byte out[], size_t blocks) const
+void TripleDES::decrypt_n(const uint8_t in[], uint8_t out[], size_t blocks) const
{
for(size_t i = 0; i != blocks; ++i)
{
- u64bit T = (DES_IPTAB1[in[0]] ) | (DES_IPTAB1[in[1]] << 1) |
+ uint64_t T = (DES_IPTAB1[in[0]] ) | (DES_IPTAB1[in[1]] << 1) |
(DES_IPTAB1[in[2]] << 2) | (DES_IPTAB1[in[3]] << 3) |
(DES_IPTAB1[in[4]] << 4) | (DES_IPTAB1[in[5]] << 5) |
(DES_IPTAB1[in[6]] << 6) | (DES_IPTAB2[in[7]] );
- u32bit L = static_cast<u32bit>(T >> 32);
- u32bit R = static_cast<u32bit>(T);
+ uint32_t L = static_cast<uint32_t>(T >> 32);
+ uint32_t R = static_cast<uint32_t>(T);
des_decrypt(L, R, &m_round_key[64]);
des_encrypt(R, L, &m_round_key[32]);
@@ -277,7 +277,7 @@ void TripleDES::decrypt_n(const byte in[], byte out[], size_t blocks) const
/*
* TripleDES Key Schedule
*/
-void TripleDES::key_schedule(const byte key[], size_t length)
+void TripleDES::key_schedule(const uint8_t key[], size_t length)
{
m_round_key.resize(3*32);
des_key_schedule(&m_round_key[0], key);