aboutsummaryrefslogtreecommitdiffstats
path: root/src/block/safer/safer_sk.cpp
diff options
context:
space:
mode:
authorlloyd <[email protected]>2012-05-25 22:52:00 +0000
committerlloyd <[email protected]>2012-05-25 22:52:00 +0000
commit12090a7148d9ee73572cc1a7268fc489504a8173 (patch)
tree51e50ce0852c56231e9e6dc13f168b10edd45d01 /src/block/safer/safer_sk.cpp
parent9594979caf775dc4062850044715b804d1fda60c (diff)
parent65cc04445f8d40497f02a14bd8cb97081790e54b (diff)
propagate from branch 'net.randombit.botan.x509-path-validation' (head 63b5a20eab129ca13287fda33d2d02eec329708f)
to branch 'net.randombit.botan' (head 8b8150f09c55184f028f2929c4e7f7cd0d46d96e)
Diffstat (limited to 'src/block/safer/safer_sk.cpp')
-rw-r--r--src/block/safer/safer_sk.cpp18
1 files changed, 7 insertions, 11 deletions
diff --git a/src/block/safer/safer_sk.cpp b/src/block/safer/safer_sk.cpp
index a3a6cefd8..1b79b3c2c 100644
--- a/src/block/safer/safer_sk.cpp
+++ b/src/block/safer/safer_sk.cpp
@@ -90,8 +90,6 @@ const byte LOG[512] = {
*/
void SAFER_SK::encrypt_n(const byte in[], byte out[], size_t blocks) const
{
- const size_t rounds = get_rounds();
-
for(size_t i = 0; i != blocks; ++i)
{
byte A = in[0], B = in[1], C = in[2], D = in[3],
@@ -128,8 +126,6 @@ void SAFER_SK::encrypt_n(const byte in[], byte out[], size_t blocks) const
*/
void SAFER_SK::decrypt_n(const byte in[], byte out[], size_t blocks) const
{
- const size_t rounds = get_rounds();
-
for(size_t i = 0; i != blocks; ++i)
{
byte A = in[0], B = in[1], C = in[2], D = in[3],
@@ -208,7 +204,9 @@ void SAFER_SK::key_schedule(const byte key[], size_t)
0x07, 0x08, 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x11, 0x09, 0x0A, 0x0B,
0x0C, 0x0D, 0x0E, 0x0F };
- SecureVector<byte> KB(18);
+ EK.resize(16 * rounds + 8);
+
+ secure_vector<byte> KB(18);
for(size_t i = 0; i != 8; ++i)
{
@@ -216,7 +214,7 @@ void SAFER_SK::key_schedule(const byte key[], size_t)
KB[17] ^= KB[i+9] = EK[i] = key[i+8];
}
- for(size_t i = 0; i != get_rounds(); ++i)
+ for(size_t i = 0; i != rounds; ++i)
{
for(size_t j = 0; j != 18; ++j)
KB[j] = rotate_left(KB[j], 6);
@@ -230,7 +228,7 @@ void SAFER_SK::key_schedule(const byte key[], size_t)
*/
std::string SAFER_SK::name() const
{
- return "SAFER-SK(" + to_string(get_rounds()) + ")";
+ return "SAFER-SK(" + std::to_string(rounds) + ")";
}
/*
@@ -238,18 +236,16 @@ std::string SAFER_SK::name() const
*/
BlockCipher* SAFER_SK::clone() const
{
- return new SAFER_SK(get_rounds());
+ return new SAFER_SK(rounds);
}
/*
* SAFER-SK Constructor
*/
-SAFER_SK::SAFER_SK(size_t rounds)
+SAFER_SK::SAFER_SK(size_t r) : rounds(r)
{
if(rounds > 13 || rounds == 0)
throw Invalid_Argument(name() + ": Invalid number of rounds");
-
- EK.resize(16 * rounds + 8);
}
}