aboutsummaryrefslogtreecommitdiffstats
path: root/src/lib/block/des
diff options
context:
space:
mode:
Diffstat (limited to 'src/lib/block/des')
-rw-r--r--src/lib/block/des/des.cpp56
-rw-r--r--src/lib/block/des/des.h40
-rw-r--r--src/lib/block/des/des_tab.cpp24
-rw-r--r--src/lib/block/des/desx.cpp6
-rw-r--r--src/lib/block/des/desx.h8
5 files changed, 67 insertions, 67 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);
diff --git a/src/lib/block/des/des.h b/src/lib/block/des/des.h
index ff31421d2..f0c32be29 100644
--- a/src/lib/block/des/des.h
+++ b/src/lib/block/des/des.h
@@ -18,16 +18,16 @@ namespace Botan {
class BOTAN_DLL DES final : public Block_Cipher_Fixed_Params<8, 8>
{
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 "DES"; }
BlockCipher* clone() const override { return new DES; }
private:
- void key_schedule(const byte[], size_t) override;
+ void key_schedule(const uint8_t[], size_t) override;
- secure_vector<u32bit> m_round_key;
+ secure_vector<uint32_t> m_round_key;
};
/**
@@ -36,34 +36,34 @@ class BOTAN_DLL DES final : public Block_Cipher_Fixed_Params<8, 8>
class BOTAN_DLL TripleDES final : public Block_Cipher_Fixed_Params<8, 16, 24, 8>
{
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 "TripleDES"; }
BlockCipher* clone() const override { return new TripleDES; }
private:
- void key_schedule(const byte[], size_t) override;
+ void key_schedule(const uint8_t[], size_t) override;
- secure_vector<u32bit> m_round_key;
+ secure_vector<uint32_t> m_round_key;
};
/*
* DES Tables
*/
-extern const u32bit DES_SPBOX1[256];
-extern const u32bit DES_SPBOX2[256];
-extern const u32bit DES_SPBOX3[256];
-extern const u32bit DES_SPBOX4[256];
-extern const u32bit DES_SPBOX5[256];
-extern const u32bit DES_SPBOX6[256];
-extern const u32bit DES_SPBOX7[256];
-extern const u32bit DES_SPBOX8[256];
+extern const uint32_t DES_SPBOX1[256];
+extern const uint32_t DES_SPBOX2[256];
+extern const uint32_t DES_SPBOX3[256];
+extern const uint32_t DES_SPBOX4[256];
+extern const uint32_t DES_SPBOX5[256];
+extern const uint32_t DES_SPBOX6[256];
+extern const uint32_t DES_SPBOX7[256];
+extern const uint32_t DES_SPBOX8[256];
-extern const u64bit DES_IPTAB1[256];
-extern const u64bit DES_IPTAB2[256];
-extern const u64bit DES_FPTAB1[256];
-extern const u64bit DES_FPTAB2[256];
+extern const uint64_t DES_IPTAB1[256];
+extern const uint64_t DES_IPTAB2[256];
+extern const uint64_t DES_FPTAB1[256];
+extern const uint64_t DES_FPTAB2[256];
}
diff --git a/src/lib/block/des/des_tab.cpp b/src/lib/block/des/des_tab.cpp
index 0f8179995..c64b6baf6 100644
--- a/src/lib/block/des/des_tab.cpp
+++ b/src/lib/block/des/des_tab.cpp
@@ -9,7 +9,7 @@
namespace Botan {
-const u32bit DES_SPBOX1[256] = {
+const uint32_t DES_SPBOX1[256] = {
0x01010400, 0x00000000, 0x00010000, 0x01010404, 0x01010004, 0x00010404,
0x00000004, 0x00010000, 0x00000400, 0x01010400, 0x01010404, 0x00000400,
0x01000404, 0x01010004, 0x01000000, 0x00000004, 0x00000404, 0x01000400,
@@ -54,7 +54,7 @@ const u32bit DES_SPBOX1[256] = {
0x00010404, 0x01010400, 0x00000404, 0x01000400, 0x01000400, 0x00000000,
0x00010004, 0x00010400, 0x00000000, 0x01010004 };
-const u32bit DES_SPBOX2[256] = {
+const uint32_t DES_SPBOX2[256] = {
0x80108020, 0x80008000, 0x00008000, 0x00108020, 0x00100000, 0x00000020,
0x80100020, 0x80008020, 0x80000020, 0x80108020, 0x80108000, 0x80000000,
0x80008000, 0x00100000, 0x00000020, 0x80100020, 0x00108000, 0x00100020,
@@ -99,7 +99,7 @@ const u32bit DES_SPBOX2[256] = {
0x80000020, 0x00100020, 0x00108000, 0x00000000, 0x80008000, 0x00008020,
0x80000000, 0x80100020, 0x80108020, 0x00108000 };
-const u32bit DES_SPBOX3[256] = {
+const uint32_t DES_SPBOX3[256] = {
0x00000208, 0x08020200, 0x00000000, 0x08020008, 0x08000200, 0x00000000,
0x00020208, 0x08000200, 0x00020008, 0x08000008, 0x08000008, 0x00020000,
0x08020208, 0x00020008, 0x08020000, 0x00000208, 0x08000000, 0x00000008,
@@ -144,7 +144,7 @@ const u32bit DES_SPBOX3[256] = {
0x00020200, 0x08000008, 0x08020000, 0x08000208, 0x00000208, 0x08020000,
0x00020208, 0x00000008, 0x08020008, 0x00020200 };
-const u32bit DES_SPBOX4[256] = {
+const uint32_t DES_SPBOX4[256] = {
0x00802001, 0x00002081, 0x00002081, 0x00000080, 0x00802080, 0x00800081,
0x00800001, 0x00002001, 0x00000000, 0x00802000, 0x00802000, 0x00802081,
0x00000081, 0x00000000, 0x00800080, 0x00800001, 0x00000001, 0x00002000,
@@ -189,7 +189,7 @@ const u32bit DES_SPBOX4[256] = {
0x00802080, 0x00800081, 0x00002001, 0x00002080, 0x00800000, 0x00802001,
0x00000080, 0x00800000, 0x00002000, 0x00802080 };
-const u32bit DES_SPBOX5[256] = {
+const uint32_t DES_SPBOX5[256] = {
0x00000100, 0x02080100, 0x02080000, 0x42000100, 0x00080000, 0x00000100,
0x40000000, 0x02080000, 0x40080100, 0x00080000, 0x02000100, 0x40080100,
0x42000100, 0x42080000, 0x00080100, 0x40000000, 0x02000000, 0x40080000,
@@ -234,7 +234,7 @@ const u32bit DES_SPBOX5[256] = {
0x40080000, 0x42000000, 0x00080100, 0x02000100, 0x40000100, 0x00080000,
0x00000000, 0x40080000, 0x02080100, 0x40000100 };
-const u32bit DES_SPBOX6[256] = {
+const uint32_t DES_SPBOX6[256] = {
0x20000010, 0x20400000, 0x00004000, 0x20404010, 0x20400000, 0x00000010,
0x20404010, 0x00400000, 0x20004000, 0x00404010, 0x00400000, 0x20000010,
0x00400010, 0x20004000, 0x20000000, 0x00004010, 0x00000000, 0x00400010,
@@ -279,7 +279,7 @@ const u32bit DES_SPBOX6[256] = {
0x20400000, 0x00404010, 0x00004000, 0x00400010, 0x20004010, 0x00000000,
0x20404000, 0x20000000, 0x00400010, 0x20004010 };
-const u32bit DES_SPBOX7[256] = {
+const uint32_t DES_SPBOX7[256] = {
0x00200000, 0x04200002, 0x04000802, 0x00000000, 0x00000800, 0x04000802,
0x00200802, 0x04200800, 0x04200802, 0x00200000, 0x00000000, 0x04000002,
0x00000002, 0x04000000, 0x04200002, 0x00000802, 0x04000800, 0x00200802,
@@ -324,7 +324,7 @@ const u32bit DES_SPBOX7[256] = {
0x00000002, 0x04200802, 0x00000000, 0x00200802, 0x04200000, 0x00000800,
0x04000002, 0x04000800, 0x00000800, 0x00200002 };
-const u32bit DES_SPBOX8[256] = {
+const uint32_t DES_SPBOX8[256] = {
0x10001040, 0x00001000, 0x00040000, 0x10041040, 0x10000000, 0x10001040,
0x00000040, 0x10000000, 0x00040040, 0x10040000, 0x10041040, 0x00041000,
0x10041000, 0x00041040, 0x00001000, 0x00000040, 0x10040000, 0x10000040,
@@ -369,7 +369,7 @@ const u32bit DES_SPBOX8[256] = {
0x10001040, 0x00000000, 0x10041040, 0x00041000, 0x00041000, 0x00001040,
0x00001040, 0x00040040, 0x10000000, 0x10041000 };
-const u64bit DES_IPTAB1[256] = {
+const uint64_t DES_IPTAB1[256] = {
0x0000000000000000, 0x0000000200000000, 0x0000000000000002, 0x0000000200000002,
0x0000020000000000, 0x0000020200000000, 0x0000020000000002, 0x0000020200000002,
0x0000000000000200, 0x0000000200000200, 0x0000000000000202, 0x0000000200000202,
@@ -435,7 +435,7 @@ const u64bit DES_IPTAB1[256] = {
0x0202000002020200, 0x0202000202020200, 0x0202000002020202, 0x0202000202020202,
0x0202020002020200, 0x0202020202020200, 0x0202020002020202, 0x0202020202020202 };
-const u64bit DES_IPTAB2[256] = {
+const uint64_t DES_IPTAB2[256] = {
0x0000000000000000, 0x0000010000000000, 0x0000000000000100, 0x0000010000000100,
0x0001000000000000, 0x0001010000000000, 0x0001000000000100, 0x0001010000000100,
0x0000000000010000, 0x0000010000010000, 0x0000000000010100, 0x0000010000010100,
@@ -501,7 +501,7 @@ const u64bit DES_IPTAB2[256] = {
0x0100000101010001, 0x0100010101010001, 0x0100000101010101, 0x0100010101010101,
0x0101000101010001, 0x0101010101010001, 0x0101000101010101, 0x0101010101010101 };
-const u64bit DES_FPTAB1[256] = {
+const uint64_t DES_FPTAB1[256] = {
0x0000000000000000, 0x0000000100000000, 0x0000000004000000, 0x0000000104000000,
0x0000000000040000, 0x0000000100040000, 0x0000000004040000, 0x0000000104040000,
0x0000000000000400, 0x0000000100000400, 0x0000000004000400, 0x0000000104000400,
@@ -567,7 +567,7 @@ const u64bit DES_FPTAB1[256] = {
0x0404040000000404, 0x0404040100000404, 0x0404040004000404, 0x0404040104000404,
0x0404040000040404, 0x0404040100040404, 0x0404040004040404, 0x0404040104040404 };
-const u64bit DES_FPTAB2[256] = {
+const uint64_t DES_FPTAB2[256] = {
0x0000000000000000, 0x0000004000000000, 0x0000000001000000, 0x0000004001000000,
0x0000000000010000, 0x0000004000010000, 0x0000000001010000, 0x0000004001010000,
0x0000000000000100, 0x0000004000000100, 0x0000000001000100, 0x0000004001000100,
diff --git a/src/lib/block/des/desx.cpp b/src/lib/block/des/desx.cpp
index 76a50f9a2..7c9995523 100644
--- a/src/lib/block/des/desx.cpp
+++ b/src/lib/block/des/desx.cpp
@@ -12,7 +12,7 @@ namespace Botan {
/*
* DESX Encryption
*/
-void DESX::encrypt_n(const byte in[], byte out[], size_t blocks) const
+void DESX::encrypt_n(const uint8_t in[], uint8_t out[], size_t blocks) const
{
for(size_t i = 0; i != blocks; ++i)
{
@@ -28,7 +28,7 @@ void DESX::encrypt_n(const byte in[], byte out[], size_t blocks) const
/*
* DESX Decryption
*/
-void DESX::decrypt_n(const byte in[], byte out[], size_t blocks) const
+void DESX::decrypt_n(const uint8_t in[], uint8_t out[], size_t blocks) const
{
for(size_t i = 0; i != blocks; ++i)
{
@@ -44,7 +44,7 @@ void DESX::decrypt_n(const byte in[], byte out[], size_t blocks) const
/*
* DESX Key Schedule
*/
-void DESX::key_schedule(const byte key[], size_t)
+void DESX::key_schedule(const uint8_t key[], size_t)
{
m_K1.assign(key, key + 8);
m_des.set_key(key + 8, 8);
diff --git a/src/lib/block/des/desx.h b/src/lib/block/des/desx.h
index f3c9ac99a..7bc7d047f 100644
--- a/src/lib/block/des/desx.h
+++ b/src/lib/block/des/desx.h
@@ -18,15 +18,15 @@ namespace Botan {
class BOTAN_DLL DESX final : public Block_Cipher_Fixed_Params<8, 24>
{
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 "DESX"; }
BlockCipher* clone() const override { return new DESX; }
private:
- void key_schedule(const byte[], size_t) override;
- secure_vector<byte> m_K1, m_K2;
+ void key_schedule(const uint8_t[], size_t) override;
+ secure_vector<uint8_t> m_K1, m_K2;
DES m_des;
};