aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorlloyd <[email protected]>2012-05-18 14:24:51 +0000
committerlloyd <[email protected]>2012-05-18 14:24:51 +0000
commitab5c922f0e2635dc0e45fc757b27be9f28986acb (patch)
treec21a18bbfb316196b1b13488ef05f184f12be9f0
parent2c3dc93d6466a9215d585613fb55f5222ce70d10 (diff)
Remove all uses of MemoryRegion::copy outside of internal uses in
secmem.h. Mostly replaced by assign or copy_mem.
-rw-r--r--src/algo_base/symkey.cpp5
-rw-r--r--src/block/des/desx.cpp4
-rw-r--r--src/block/lion/lion.cpp4
-rw-r--r--src/block/rc2/rc2.cpp2
-rw-r--r--src/block/serpent/serpent.cpp3
-rw-r--r--src/block/square/square.cpp7
-rw-r--r--src/filters/codec_filt/b64_filt.cpp2
-rw-r--r--src/filters/codec_filt/hex_filt.cpp2
-rw-r--r--src/filters/modes/cts/cts.cpp2
-rw-r--r--src/filters/modes/eax/eax_dec.cpp4
-rw-r--r--src/filters/modes/xts/xts.cpp16
-rw-r--r--src/hash/gost_3411/gost_3411.cpp2
-rw-r--r--src/hash/md2/md2.cpp2
-rw-r--r--src/hash/skein/skein_512.cpp2
-rw-r--r--src/mac/cmac/cmac.cpp2
-rw-r--r--src/mac/ssl3mac/ssl3_mac.cpp5
-rw-r--r--src/math/bigint/bigint.cpp15
-rw-r--r--src/pubkey/dlies/dlies.cpp2
18 files changed, 39 insertions, 42 deletions
diff --git a/src/algo_base/symkey.cpp b/src/algo_base/symkey.cpp
index a84ce2f19..5509b83bc 100644
--- a/src/algo_base/symkey.cpp
+++ b/src/algo_base/symkey.cpp
@@ -37,8 +37,7 @@ OctetString::OctetString(const std::string& hex_string)
*/
OctetString::OctetString(const byte in[], size_t n)
{
- bits.resize(n);
- bits.copy(in, n);
+ bits.assign(in, in + n);
}
OctetString::OctetString(const MemoryRegion<byte>& b) : bits(b)
@@ -129,7 +128,7 @@ OctetString operator+(const OctetString& k1, const OctetString& k2)
OctetString operator^(const OctetString& k1, const OctetString& k2)
{
SecureVector<byte> ret(std::max(k1.length(), k2.length()));
- ret.copy(k1.begin(), k1.length());
+ copy_mem(&ret[0], k1.begin(), k1.length());
xor_buf(ret, k2.begin(), k2.length());
return OctetString(ret);
}
diff --git a/src/block/des/desx.cpp b/src/block/des/desx.cpp
index b92011e56..7f68e406a 100644
--- a/src/block/des/desx.cpp
+++ b/src/block/des/desx.cpp
@@ -47,9 +47,9 @@ void DESX::decrypt_n(const byte in[], byte out[], size_t blocks) const
*/
void DESX::key_schedule(const byte key[], size_t)
{
- K1.copy(key, 8);
+ K1.assign(key, key + 8);
des.set_key(key + 8, 8);
- K2.copy(key + 16, 8);
+ K2.assign(key + 16, key + 24);
}
}
diff --git a/src/block/lion/lion.cpp b/src/block/lion/lion.cpp
index 8c39eee65..4a9e8b901 100644
--- a/src/block/lion/lion.cpp
+++ b/src/block/lion/lion.cpp
@@ -72,8 +72,8 @@ void Lion::key_schedule(const byte key[], size_t length)
{
clear();
- key1.copy(key, length / 2);
- key2.copy(key + length / 2, length / 2);
+ key1.assign(key, key + (length / 2));
+ key2.assign(key + (length / 2), key + length);
}
/*
diff --git a/src/block/rc2/rc2.cpp b/src/block/rc2/rc2.cpp
index 97ca5d577..071e4e209 100644
--- a/src/block/rc2/rc2.cpp
+++ b/src/block/rc2/rc2.cpp
@@ -125,7 +125,7 @@ void RC2::key_schedule(const byte key[], size_t length)
0xFE, 0x7F, 0xC1, 0xAD };
SecureVector<byte> L(128);
- L.copy(key, length);
+ copy_mem(&L[0], key, length);
for(size_t i = length; i != 128; ++i)
L[i] = TABLE[(L[i-1] + L[i-length]) % 256];
diff --git a/src/block/serpent/serpent.cpp b/src/block/serpent/serpent.cpp
index b3cf0f6c9..b1e632c29 100644
--- a/src/block/serpent/serpent.cpp
+++ b/src/block/serpent/serpent.cpp
@@ -387,7 +387,8 @@ void Serpent::key_schedule(const byte key[], size_t length)
SBoxE8(W[120],W[121],W[122],W[123]); SBoxE7(W[124],W[125],W[126],W[127]);
SBoxE6(W[128],W[129],W[130],W[131]); SBoxE5(W[132],W[133],W[134],W[135]);
SBoxE4(W[136],W[137],W[138],W[139]);
- round_key.copy(&W[8], 132);
+
+ round_key.assign(&W[8], &W[140]);
}
}
diff --git a/src/block/square/square.cpp b/src/block/square/square.cpp
index cd1865582..ff98c040e 100644
--- a/src/block/square/square.cpp
+++ b/src/block/square/square.cpp
@@ -160,6 +160,9 @@ void Square::key_schedule(const byte key[], size_t)
transform(&XEK[4*i]);
}
+ ME.resize(16);
+ MD.resize(16);
+
for(size_t i = 0; i != 4; ++i)
for(size_t j = 0; j != 4; ++j)
{
@@ -169,8 +172,8 @@ void Square::key_schedule(const byte key[], size_t)
MD[4*i+j+16] = get_byte(j, XEK[i ]);
}
- EK.copy(&XEK[4], 28);
- DK.copy(&XDK[4], 28);
+ EK.assign(&XEK[4], &XEK[36]);
+ DK.assign(&XDK[4], &XDK[36]);
}
/*
diff --git a/src/filters/codec_filt/b64_filt.cpp b/src/filters/codec_filt/b64_filt.cpp
index 55eaac965..b804b33c7 100644
--- a/src/filters/codec_filt/b64_filt.cpp
+++ b/src/filters/codec_filt/b64_filt.cpp
@@ -91,7 +91,7 @@ void Base64_Encoder::write(const byte input[], size_t length)
input += in.size();
length -= in.size();
}
- in.copy(input, length);
+ copy_mem(&in[0], input, length);
position = 0;
}
position += length;
diff --git a/src/filters/codec_filt/hex_filt.cpp b/src/filters/codec_filt/hex_filt.cpp
index 47995f928..e85bdb17e 100644
--- a/src/filters/codec_filt/hex_filt.cpp
+++ b/src/filters/codec_filt/hex_filt.cpp
@@ -87,7 +87,7 @@ void Hex_Encoder::write(const byte input[], size_t length)
input += in.size();
length -= in.size();
}
- in.copy(input, length);
+ copy_mem(&in[0], input, length);
position = 0;
}
position += length;
diff --git a/src/filters/modes/cts/cts.cpp b/src/filters/modes/cts/cts.cpp
index bc9c99d73..694d7d524 100644
--- a/src/filters/modes/cts/cts.cpp
+++ b/src/filters/modes/cts/cts.cpp
@@ -161,7 +161,7 @@ void CTS_Decryption::decrypt(const byte block[])
cipher->decrypt(block, &temp[0]);
xor_buf(temp, state, cipher->block_size());
send(temp, cipher->block_size());
- state.copy(block, cipher->block_size());
+ copy_mem(&state[0], block, cipher->block_size());
}
/*
diff --git a/src/filters/modes/eax/eax_dec.cpp b/src/filters/modes/eax/eax_dec.cpp
index 3cf29a532..d14ba5e70 100644
--- a/src/filters/modes/eax/eax_dec.cpp
+++ b/src/filters/modes/eax/eax_dec.cpp
@@ -63,8 +63,8 @@ void EAX_Decryption::write(const byte input[], size_t length)
queue_start >= queue.size() / 2)
{
SecureVector<byte> queue_data(TAG_SIZE);
- queue_data.copy(&queue[queue_start], TAG_SIZE);
- queue.copy(&queue_data[0], TAG_SIZE);
+ copy_mem(&queue_data[0], &queue[queue_start], TAG_SIZE);
+ copy_mem(&queue[0], &queue_data[0], TAG_SIZE);
queue_start = 0;
queue_end = TAG_SIZE;
}
diff --git a/src/filters/modes/xts/xts.cpp b/src/filters/modes/xts/xts.cpp
index 317edf1f8..42b1f2bf0 100644
--- a/src/filters/modes/xts/xts.cpp
+++ b/src/filters/modes/xts/xts.cpp
@@ -92,7 +92,7 @@ void XTS_Encryption::set_iv(const InitializationVector& iv)
const size_t blocks_in_tweak = tweak.size() / cipher->block_size();
- tweak.copy(iv.begin(), iv.length());
+ tweak.assign(iv.begin(), iv.end());
cipher2->encrypt(tweak);
for(size_t i = 1; i < blocks_in_tweak; ++i)
@@ -151,8 +151,10 @@ void XTS_Encryption::buffered_block(const byte input[], size_t length)
send(temp, to_proc_bytes);
- tweak.copy(&tweak[(to_proc-1)*cipher->block_size()],
- cipher->block_size());
+ copy_mem(&tweak[0],
+ &tweak[(to_proc-1)*cipher->block_size()],
+ cipher->block_size());
+
poly_double(&tweak[0], cipher->block_size());
for(size_t i = 1; i < blocks_in_tweak; ++i)
@@ -264,7 +266,7 @@ void XTS_Decryption::set_iv(const InitializationVector& iv)
const size_t blocks_in_tweak = tweak.size() / cipher->block_size();
- tweak.copy(iv.begin(), iv.length());
+ tweak.assign(iv.begin(), iv.end());
cipher2->encrypt(tweak);
for(size_t i = 1; i < blocks_in_tweak; ++i)
@@ -324,8 +326,10 @@ void XTS_Decryption::buffered_block(const byte input[], size_t input_length)
send(temp, to_proc_bytes);
- tweak.copy(&tweak[(to_proc-1)*cipher->block_size()],
- cipher->block_size());
+ copy_mem(&tweak[0],
+ &tweak[(to_proc-1)*cipher->block_size()],
+ cipher->block_size());
+
poly_double(&tweak[0], cipher->block_size());
for(size_t i = 1; i < blocks_in_tweak; ++i)
diff --git a/src/hash/gost_3411/gost_3411.cpp b/src/hash/gost_3411/gost_3411.cpp
index 6996e45e6..6e56c2b97 100644
--- a/src/hash/gost_3411/gost_3411.cpp
+++ b/src/hash/gost_3411/gost_3411.cpp
@@ -210,7 +210,7 @@ void GOST_34_11::compress_n(const byte input[], size_t blocks)
S2[30] = S[ 2] ^ S[ 4] ^ S[ 8] ^ S[14] ^ S[16] ^ S[18] ^ S[22] ^ S[24] ^ S[28] ^ S[30];
S2[31] = S[ 3] ^ S[ 5] ^ S[ 9] ^ S[15] ^ S[17] ^ S[19] ^ S[23] ^ S[25] ^ S[29] ^ S[31];
- hash.copy(S2, 32);
+ copy_mem(&hash[0], &S2[0], 32);
}
}
diff --git a/src/hash/md2/md2.cpp b/src/hash/md2/md2.cpp
index f44053a1c..8f6a90208 100644
--- a/src/hash/md2/md2.cpp
+++ b/src/hash/md2/md2.cpp
@@ -79,7 +79,7 @@ void MD2::add_data(const byte input[], size_t length)
input += hash_block_size();
length -= hash_block_size();
}
- buffer.copy(input, length);
+ copy_mem(&buffer[0], input, length);
position = 0;
}
position += length;
diff --git a/src/hash/skein/skein_512.cpp b/src/hash/skein/skein_512.cpp
index f6541fba7..2458bf5f0 100644
--- a/src/hash/skein/skein_512.cpp
+++ b/src/hash/skein/skein_512.cpp
@@ -251,7 +251,7 @@ void Skein_512::final_result(byte out[])
{
const size_t to_proc = std::min<size_t>(out_bytes, 64);
- H_out.copy(&H[0], 8);
+ copy_mem(&H_out[0], &H[0], 8);
reset_tweak(T, SKEIN_OUTPUT, true);
ubi_512(H_out, T, counter, sizeof(counter));
diff --git a/src/mac/cmac/cmac.cpp b/src/mac/cmac/cmac.cpp
index adc08852c..7cd53f578 100644
--- a/src/mac/cmac/cmac.cpp
+++ b/src/mac/cmac/cmac.cpp
@@ -52,7 +52,7 @@ void CMAC::add_data(const byte input[], size_t length)
input += output_length();
length -= output_length();
}
- buffer.copy(input, length);
+ copy_mem(&buffer[0], input, length);
position = 0;
}
position += length;
diff --git a/src/mac/ssl3mac/ssl3_mac.cpp b/src/mac/ssl3mac/ssl3_mac.cpp
index a07622eb3..8799c96a5 100644
--- a/src/mac/ssl3mac/ssl3_mac.cpp
+++ b/src/mac/ssl3mac/ssl3_mac.cpp
@@ -38,8 +38,9 @@ void SSL3_MAC::key_schedule(const byte key[], size_t length)
std::fill(i_key.begin(), i_key.end(), 0x36);
std::fill(o_key.begin(), o_key.end(), 0x5C);
- i_key.copy(key, length);
- o_key.copy(key, length);
+ copy_mem(&i_key[0], key, length);
+ copy_mem(&o_key[0], key, length);
+
hash->update(i_key);
}
diff --git a/src/math/bigint/bigint.cpp b/src/math/bigint/bigint.cpp
index e2bbe7f5a..df4414aba 100644
--- a/src/math/bigint/bigint.cpp
+++ b/src/math/bigint/bigint.cpp
@@ -44,19 +44,8 @@ BigInt::BigInt(Sign s, size_t size)
*/
BigInt::BigInt(const BigInt& b)
{
- const size_t b_words = b.sig_words();
-
- if(b_words)
- {
- reg.resize(round_up<size_t>(b_words, 8));
- reg.copy(b.data(), b_words);
- set_sign(b.sign());
- }
- else
- {
- reg.resize(2);
- set_sign(Positive);
- }
+ reg = b.get_reg();
+ set_sign(b.sign());
}
/*
diff --git a/src/pubkey/dlies/dlies.cpp b/src/pubkey/dlies/dlies.cpp
index 129cc46d9..80dde048b 100644
--- a/src/pubkey/dlies/dlies.cpp
+++ b/src/pubkey/dlies/dlies.cpp
@@ -43,7 +43,7 @@ SecureVector<byte> DLIES_Encryptor::enc(const byte in[], size_t length,
throw Invalid_State("DLIES: The other key was never set");
SecureVector<byte> out(my_key.size() + length + mac->output_length());
- out.copy(&my_key[0], my_key.size());
+ buffer_insert(out, 0, my_key);
buffer_insert(out, my_key.size(), in, length);
SecureVector<byte> vz = my_key;