aboutsummaryrefslogtreecommitdiffstats
path: root/src/block/blowfish
diff options
context:
space:
mode:
Diffstat (limited to 'src/block/blowfish')
-rw-r--r--src/block/blowfish/blowfish.cpp17
-rw-r--r--src/block/blowfish/blowfish.h5
2 files changed, 13 insertions, 9 deletions
diff --git a/src/block/blowfish/blowfish.cpp b/src/block/blowfish/blowfish.cpp
index 9f5ac1724..c224f479b 100644
--- a/src/block/blowfish/blowfish.cpp
+++ b/src/block/blowfish/blowfish.cpp
@@ -85,7 +85,11 @@ void Blowfish::decrypt_n(const byte in[], byte out[], size_t blocks) const
*/
void Blowfish::key_schedule(const byte key[], size_t length)
{
- clear();
+ P.resize(18);
+ std::copy(P_INIT, P_INIT + 18, P.begin());
+
+ S.resize(1024);
+ std::copy(S_INIT, S_INIT + 1024, S.begin());
const byte null_salt[16] = { 0 };
@@ -125,12 +129,15 @@ void Blowfish::eks_key_schedule(const byte key[], size_t length,
if(workfactor > 18)
throw std::invalid_argument("Requested Bcrypt work factor too large");
- clear();
+ P.resize(18);
+ std::copy(P_INIT, P_INIT + 18, P.begin());
- const byte null_salt[16] = { 0 };
+ S.resize(1024);
+ std::copy(S_INIT, S_INIT + 1024, S.begin());
key_expansion(key, length, salt);
+ const byte null_salt[16] = { 0 };
const size_t rounds = 1 << workfactor;
for(size_t r = 0; r != rounds; ++r)
@@ -180,8 +187,8 @@ void Blowfish::generate_sbox(secure_vector<u32bit>& box,
*/
void Blowfish::clear()
{
- std::copy(P_INIT, P_INIT + 18, P.begin());
- std::copy(S_INIT, S_INIT + 1024, S.begin());
+ P.clear();
+ S.clear();
}
}
diff --git a/src/block/blowfish/blowfish.h b/src/block/blowfish/blowfish.h
index 5bec4b231..cdf65f285 100644
--- a/src/block/blowfish/blowfish.h
+++ b/src/block/blowfish/blowfish.h
@@ -30,8 +30,6 @@ class BOTAN_DLL Blowfish : public Block_Cipher_Fixed_Params<8, 1, 56>
void clear();
std::string name() const { return "Blowfish"; }
BlockCipher* clone() const { return new Blowfish; }
-
- Blowfish() : S(1024), P(18) {}
private:
void key_schedule(const byte key[], size_t length);
@@ -47,8 +45,7 @@ class BOTAN_DLL Blowfish : public Block_Cipher_Fixed_Params<8, 1, 56>
static const u32bit P_INIT[18];
static const u32bit S_INIT[1024];
- secure_vector<u32bit> S;
- secure_vector<u32bit> P;
+ secure_vector<u32bit> S, P;
};
}