aboutsummaryrefslogtreecommitdiffstats
path: root/src/lib/block/blowfish
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/blowfish
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/blowfish')
-rw-r--r--src/lib/block/blowfish/blowfish.cpp66
-rw-r--r--src/lib/block/blowfish/blowfish.h22
2 files changed, 44 insertions, 44 deletions
diff --git a/src/lib/block/blowfish/blowfish.cpp b/src/lib/block/blowfish/blowfish.cpp
index 69d345baa..17ac00a1f 100644
--- a/src/lib/block/blowfish/blowfish.cpp
+++ b/src/lib/block/blowfish/blowfish.cpp
@@ -12,12 +12,12 @@ namespace Botan {
namespace {
-const u32bit P_INIT[18] = {
+const uint32_t P_INIT[18] = {
0x243F6A88, 0x85A308D3, 0x13198A2E, 0x03707344, 0xA4093822, 0x299F31D0,
0x082EFA98, 0xEC4E6C89, 0x452821E6, 0x38D01377, 0xBE5466CF, 0x34E90C6C,
0xC0AC29B7, 0xC97C50DD, 0x3F84D5B5, 0xB5470917, 0x9216D5D9, 0x8979FB1B };
-const u32bit S_INIT[1024] = {
+const uint32_t S_INIT[1024] = {
0xD1310BA6, 0x98DFB5AC, 0x2FFD72DB, 0xD01ADFB7, 0xB8E1AFED, 0x6A267E96,
0xBA7C9045, 0xF12C7F99, 0x24A19947, 0xB3916CF7, 0x0801F2E2, 0x858EFC16,
0x636920D8, 0x71574E69, 0xA458FEA3, 0xF4933D7E, 0x0D95748F, 0x728EB658,
@@ -195,16 +195,16 @@ const u32bit S_INIT[1024] = {
/*
* Blowfish Encryption
*/
-void Blowfish::encrypt_n(const byte in[], byte out[], size_t blocks) const
+void Blowfish::encrypt_n(const uint8_t in[], uint8_t out[], size_t blocks) const
{
- const u32bit* S1 = &m_S[0];
- const u32bit* S2 = &m_S[256];
- const u32bit* S3 = &m_S[512];
- const u32bit* S4 = &m_S[768];
+ const uint32_t* S1 = &m_S[0];
+ const uint32_t* S2 = &m_S[256];
+ const uint32_t* S3 = &m_S[512];
+ const uint32_t* S4 = &m_S[768];
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);
for(size_t j = 0; j != 16; j += 2)
@@ -227,16 +227,16 @@ void Blowfish::encrypt_n(const byte in[], byte out[], size_t blocks) const
/*
* Blowfish Decryption
*/
-void Blowfish::decrypt_n(const byte in[], byte out[], size_t blocks) const
+void Blowfish::decrypt_n(const uint8_t in[], uint8_t out[], size_t blocks) const
{
- const u32bit* S1 = &m_S[0];
- const u32bit* S2 = &m_S[256];
- const u32bit* S3 = &m_S[512];
- const u32bit* S4 = &m_S[768];
+ const uint32_t* S1 = &m_S[0];
+ const uint32_t* S2 = &m_S[256];
+ const uint32_t* S3 = &m_S[512];
+ const uint32_t* S4 = &m_S[768];
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);
for(size_t j = 17; j != 1; j -= 2)
@@ -259,7 +259,7 @@ void Blowfish::decrypt_n(const byte in[], byte out[], size_t blocks) const
/*
* Blowfish Key Schedule
*/
-void Blowfish::key_schedule(const byte key[], size_t length)
+void Blowfish::key_schedule(const uint8_t key[], size_t length)
{
m_P.resize(18);
copy_mem(m_P.data(), P_INIT, 18);
@@ -267,20 +267,20 @@ void Blowfish::key_schedule(const byte key[], size_t length)
m_S.resize(1024);
copy_mem(m_S.data(), S_INIT, 1024);
- const byte null_salt[16] = { 0 };
+ const uint8_t null_salt[16] = { 0 };
key_expansion(key, length, null_salt);
}
-void Blowfish::key_expansion(const byte key[],
+void Blowfish::key_expansion(const uint8_t key[],
size_t length,
- const byte salt[16])
+ const uint8_t salt[16])
{
for(size_t i = 0, j = 0; i != 18; ++i, j += 4)
- m_P[i] ^= make_u32bit(key[(j ) % length], key[(j+1) % length],
+ m_P[i] ^= make_uint32(key[(j ) % length], key[(j+1) % length],
key[(j+2) % length], key[(j+3) % length]);
- u32bit L = 0, R = 0;
+ uint32_t L = 0, R = 0;
generate_sbox(m_P, L, R, salt, 0);
generate_sbox(m_S, L, R, salt, 2);
}
@@ -288,8 +288,8 @@ void Blowfish::key_expansion(const byte key[],
/*
* Modified key schedule used for bcrypt password hashing
*/
-void Blowfish::eks_key_schedule(const byte key[], size_t length,
- const byte salt[16], size_t workfactor)
+void Blowfish::eks_key_schedule(const uint8_t key[], size_t length,
+ const uint8_t salt[16], size_t workfactor)
{
// Truncate longer passwords to the 56 byte limit Blowfish enforces
length = std::min<size_t>(length, 55);
@@ -314,7 +314,7 @@ void Blowfish::eks_key_schedule(const byte key[], size_t length,
key_expansion(key, length, salt);
- const byte null_salt[16] = { 0 };
+ const uint8_t null_salt[16] = { 0 };
const size_t rounds = static_cast<size_t>(1) << workfactor;
for(size_t r = 0; r != rounds; ++r)
@@ -327,20 +327,20 @@ void Blowfish::eks_key_schedule(const byte key[], size_t length,
/*
* Generate one of the Sboxes
*/
-void Blowfish::generate_sbox(secure_vector<u32bit>& box,
- u32bit& L, u32bit& R,
- const byte salt[16],
+void Blowfish::generate_sbox(secure_vector<uint32_t>& box,
+ uint32_t& L, uint32_t& R,
+ const uint8_t salt[16],
size_t salt_off) const
{
- const u32bit* S1 = &m_S[0];
- const u32bit* S2 = &m_S[256];
- const u32bit* S3 = &m_S[512];
- const u32bit* S4 = &m_S[768];
+ const uint32_t* S1 = &m_S[0];
+ const uint32_t* S2 = &m_S[256];
+ const uint32_t* S3 = &m_S[512];
+ const uint32_t* S4 = &m_S[768];
for(size_t i = 0; i != box.size(); i += 2)
{
- L ^= load_be<u32bit>(salt, (i + salt_off) % 4);
- R ^= load_be<u32bit>(salt, (i + salt_off + 1) % 4);
+ L ^= load_be<uint32_t>(salt, (i + salt_off) % 4);
+ R ^= load_be<uint32_t>(salt, (i + salt_off + 1) % 4);
for(size_t j = 0; j != 16; j += 2)
{
@@ -353,7 +353,7 @@ void Blowfish::generate_sbox(secure_vector<u32bit>& box,
S3[get_byte(2, R)]) + S4[get_byte(3, R)];
}
- u32bit T = R; R = L ^ m_P[16]; L = T ^ m_P[17];
+ uint32_t T = R; R = L ^ m_P[16]; L = T ^ m_P[17];
box[i] = L;
box[i+1] = R;
}
diff --git a/src/lib/block/blowfish/blowfish.h b/src/lib/block/blowfish/blowfish.h
index 5aa35f337..690b9c400 100644
--- a/src/lib/block/blowfish/blowfish.h
+++ b/src/lib/block/blowfish/blowfish.h
@@ -18,31 +18,31 @@ namespace Botan {
class BOTAN_DLL Blowfish final : public Block_Cipher_Fixed_Params<8, 1, 56>
{
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;
/**
* Modified EKSBlowfish key schedule, used for bcrypt password hashing
*/
- void eks_key_schedule(const byte key[], size_t key_length,
- const byte salt[16], size_t workfactor);
+ void eks_key_schedule(const uint8_t key[], size_t key_length,
+ const uint8_t salt[16], size_t workfactor);
void clear() override;
std::string name() const override { return "Blowfish"; }
BlockCipher* clone() const override { return new Blowfish; }
private:
- void key_schedule(const byte key[], size_t length) override;
+ void key_schedule(const uint8_t key[], size_t length) override;
- void key_expansion(const byte key[],
+ void key_expansion(const uint8_t key[],
size_t key_length,
- const byte salt[16]);
+ const uint8_t salt[16]);
- void generate_sbox(secure_vector<u32bit>& box,
- u32bit& L, u32bit& R,
- const byte salt[16],
+ void generate_sbox(secure_vector<uint32_t>& box,
+ uint32_t& L, uint32_t& R,
+ const uint8_t salt[16],
size_t salt_off) const;
- secure_vector<u32bit> m_S, m_P;
+ secure_vector<uint32_t> m_S, m_P;
};
}