aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/constructs/fpe/fpe.cpp18
-rw-r--r--src/kdf/kdf2/kdf2.cpp5
-rw-r--r--src/kdf/mgf1/mgf1.cpp4
-rw-r--r--src/utils/buf_comp/buf_comp.h10
4 files changed, 19 insertions, 18 deletions
diff --git a/src/constructs/fpe/fpe.cpp b/src/constructs/fpe/fpe.cpp
index 4eaff0eb6..d7101c544 100644
--- a/src/constructs/fpe/fpe.cpp
+++ b/src/constructs/fpe/fpe.cpp
@@ -12,7 +12,6 @@
#include <botan/numthry.h>
#include <botan/hmac.h>
#include <botan/sha2_32.h>
-#include <botan/get_byte.h>
#include <stdexcept>
namespace Botan {
@@ -106,12 +105,10 @@ FPE_Encryptor::FPE_Encryptor(const SymmetricKey& key,
if(n_bin.size() > MAX_N_BYTES)
throw std::runtime_error("N is too large for FPE encryption");
- for(u32bit i = 0; i != 4; ++i)
- mac->update(get_byte(i, n_bin.size()));
+ mac->update_be(n_bin.size(), 4);
mac->update(&n_bin[0], n_bin.size());
- for(u32bit i = 0; i != 4; ++i)
- mac->update(get_byte(i, tweak.size()));
+ mac->update_be(tweak.size(), 4);
mac->update(&tweak[0], tweak.size());
mac_n_t = mac->final();
@@ -119,15 +116,12 @@ FPE_Encryptor::FPE_Encryptor(const SymmetricKey& key,
BigInt FPE_Encryptor::operator()(u32bit round_no, const BigInt& R)
{
- mac->update(mac_n_t);
-
- for(u32bit i = 0; i != 4; ++i)
- mac->update(get_byte(i, round_no));
-
SecureVector<byte> r_bin = BigInt::encode(R);
- for(u32bit i = 0; i != 4; ++i)
- mac->update(get_byte(i, r_bin.size()));
+ mac->update(mac_n_t);
+ mac->update_be(round_no, 4);
+
+ mac->update_be(r_bin.size(), 4);
mac->update(&r_bin[0], r_bin.size());
SecureVector<byte> X = mac->final();
diff --git a/src/kdf/kdf2/kdf2.cpp b/src/kdf/kdf2/kdf2.cpp
index b10077e35..51b9e41ea 100644
--- a/src/kdf/kdf2/kdf2.cpp
+++ b/src/kdf/kdf2/kdf2.cpp
@@ -6,7 +6,6 @@
*/
#include <botan/kdf2.h>
-#include <botan/get_byte.h>
namespace Botan {
@@ -23,9 +22,9 @@ SecureVector<byte> KDF2::derive(size_t out_len,
while(out_len && counter)
{
hash->update(secret, secret_len);
- for(size_t i = 0; i != 4; ++i)
- hash->update(get_byte(i, counter));
+ hash->update_be(counter);
hash->update(P, P_len);
+
SecureVector<byte> hash_result = hash->final();
size_t added = std::min(hash_result.size(), out_len);
diff --git a/src/kdf/mgf1/mgf1.cpp b/src/kdf/mgf1/mgf1.cpp
index 6dc028bad..7d949c2b8 100644
--- a/src/kdf/mgf1/mgf1.cpp
+++ b/src/kdf/mgf1/mgf1.cpp
@@ -6,7 +6,6 @@
*/
#include <botan/mgf1.h>
-#include <botan/get_byte.h>
#include <botan/exceptn.h>
#include <botan/internal/xor_buf.h>
#include <algorithm>
@@ -25,8 +24,7 @@ void MGF1::mask(const byte in[], size_t in_len, byte out[],
while(out_len)
{
hash->update(in, in_len);
- for(size_t i = 0; i != 4; ++i)
- hash->update(get_byte(i, counter));
+ hash->update_be(counter);
SecureVector<byte> buffer = hash->final();
size_t xored = std::min<size_t>(buffer.size(), out_len);
diff --git a/src/utils/buf_comp/buf_comp.h b/src/utils/buf_comp/buf_comp.h
index 3afa086b0..784a3285d 100644
--- a/src/utils/buf_comp/buf_comp.h
+++ b/src/utils/buf_comp/buf_comp.h
@@ -9,6 +9,7 @@
#define BOTAN_BUFFERED_COMPUTATION_H__
#include <botan/secmem.h>
+#include <botan/get_byte.h>
namespace Botan {
@@ -42,6 +43,15 @@ class BOTAN_DLL BufferedComputation
add_data(&in[0], in.size());
}
+ template<typename T> void update_be(const T in, size_t upto = sizeof(T))
+ {
+ for(size_t i = 0; i != std::min(upto, sizeof(T)); ++i)
+ {
+ byte b = get_byte(i, in);
+ add_data(&b, 1);
+ }
+ }
+
/**
* Add new input to process.
* @param str the input to process as a std::string. Will be interpreted