aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorlloyd <[email protected]>2015-01-23 17:47:31 +0000
committerlloyd <[email protected]>2015-01-23 17:47:31 +0000
commit848314e16daed06e6e519dbf8c40edf9c85a51bf (patch)
treea7d246972486ae5f49090689090af7d351110ec6 /src
parentb6cc9a4084caf6d9d4b955fadc321f6521f2b36e (diff)
Centralize where string.h/cstring is included to mem_ops.h
See github 42 for background
Diffstat (limited to 'src')
-rw-r--r--src/cmd/base64.cpp1
-rw-r--r--src/cmd/main.cpp1
-rw-r--r--src/lib/compression/comp_util.cpp4
-rw-r--r--src/lib/compression/comp_util.h5
-rw-r--r--src/lib/compression/zlib/zlib.cpp2
-rw-r--r--src/lib/entropy/dev_random/dev_random.cpp1
-rw-r--r--src/lib/entropy/egd/es_egd.cpp4
-rw-r--r--src/lib/entropy/proc_walk/proc_walk.cpp1
-rw-r--r--src/lib/pubkey/curve25519/donna.cpp13
-rw-r--r--src/lib/pubkey/mce/binary_matrix.cpp3
-rw-r--r--src/lib/pubkey/mce/binary_matrix.h3
-rw-r--r--src/lib/pubkey/mce/code_based_key_gen.cpp6
-rw-r--r--src/lib/pubkey/mce/goppa_code.cpp2
-rw-r--r--src/lib/pubkey/mce/mceliece.cpp8
-rw-r--r--src/lib/pubkey/mce/mceliece.h10
-rw-r--r--src/lib/pubkey/mce/polyn_gf2m.cpp9
-rw-r--r--src/lib/rng/system_rng/system_rng.cpp1
-rw-r--r--src/lib/utils/loadstor.h2
18 files changed, 32 insertions, 44 deletions
diff --git a/src/cmd/base64.cpp b/src/cmd/base64.cpp
index 9a841ba2c..b0e39132f 100644
--- a/src/cmd/base64.cpp
+++ b/src/cmd/base64.cpp
@@ -10,7 +10,6 @@
#include <iostream>
#include <string>
#include <vector>
-#include <cstring>
#include <cstdlib>
#include <botan/b64_filt.h>
#include <botan/pipe.h>
diff --git a/src/cmd/main.cpp b/src/cmd/main.cpp
index e605c814c..21a9ba78b 100644
--- a/src/cmd/main.cpp
+++ b/src/cmd/main.cpp
@@ -9,7 +9,6 @@
#include <iostream>
#include <cstdlib>
-#include <cstring>
#include <exception>
#include <limits>
#include <memory>
diff --git a/src/lib/compression/comp_util.cpp b/src/lib/compression/comp_util.cpp
index 77b381c4e..05c9ddb3b 100644
--- a/src/lib/compression/comp_util.cpp
+++ b/src/lib/compression/comp_util.cpp
@@ -6,7 +6,7 @@
*/
#include <botan/internal/comp_util.h>
-#include <cstring>
+#include <botan/mem_ops.h>
#include <cstdlib>
namespace Botan {
@@ -29,7 +29,7 @@ void Compression_Alloc_Info::do_free(void* ptr)
if(i == m_current_allocs.end())
throw std::runtime_error("Compression_Alloc_Info::free got pointer not allocated by us");
- std::memset(ptr, 0, i->second);
+ zero_mem(ptr, i->second);
std::free(ptr);
m_current_allocs.erase(i);
}
diff --git a/src/lib/compression/comp_util.h b/src/lib/compression/comp_util.h
index 92989e518..6e1ee1671 100644
--- a/src/lib/compression/comp_util.h
+++ b/src/lib/compression/comp_util.h
@@ -9,7 +9,6 @@
#define BOTAN_COMPRESSION_UTILS_H__
#include <botan/compression.h>
-#include <cstring>
#include <memory>
#include <unordered_map>
@@ -64,13 +63,13 @@ class Zlib_Style_Stream : public Compression_Stream
Zlib_Style_Stream()
{
- std::memset(&m_stream, 0, sizeof(stream_t));
+ clear_mem(&m_stream, 1);
m_allocs.reset(new Compression_Alloc_Info);
}
~Zlib_Style_Stream()
{
- std::memset(&m_stream, 0, sizeof(stream_t));
+ clear_mem(&m_stream, 1);
m_allocs.reset();
}
diff --git a/src/lib/compression/zlib/zlib.cpp b/src/lib/compression/zlib/zlib.cpp
index 10581b739..8c94e4331 100644
--- a/src/lib/compression/zlib/zlib.cpp
+++ b/src/lib/compression/zlib/zlib.cpp
@@ -120,7 +120,7 @@ class Gzip_Compression_Stream : public Zlib_Compression_Stream
Gzip_Compression_Stream(size_t level, int wbits, byte os_code) :
Zlib_Compression_Stream(level, wbits, 16)
{
- std::memset(&m_header, 0, sizeof(m_header));
+ clear_mem(&m_header, 1);
m_header.os = os_code;
m_header.time = std::time(nullptr);
diff --git a/src/lib/entropy/dev_random/dev_random.cpp b/src/lib/entropy/dev_random/dev_random.cpp
index 06c420a67..7c95fe20d 100644
--- a/src/lib/entropy/dev_random/dev_random.cpp
+++ b/src/lib/entropy/dev_random/dev_random.cpp
@@ -13,7 +13,6 @@
#include <sys/stat.h>
#include <unistd.h>
#include <fcntl.h>
-#include <string.h>
namespace Botan {
diff --git a/src/lib/entropy/egd/es_egd.cpp b/src/lib/entropy/egd/es_egd.cpp
index 2ddb233bd..36ad70e3a 100644
--- a/src/lib/entropy/egd/es_egd.cpp
+++ b/src/lib/entropy/egd/es_egd.cpp
@@ -8,7 +8,7 @@
#include <botan/internal/es_egd.h>
#include <botan/parsing.h>
#include <botan/exceptn.h>
-#include <cstring>
+#include <botan/mem_ops.h>
#include <stdexcept>
#include <sys/types.h>
@@ -40,7 +40,7 @@ int EGD_EntropySource::EGD_Socket::open_socket(const std::string& path)
if(fd >= 0)
{
sockaddr_un addr;
- std::memset(&addr, 0, sizeof(addr));
+ clear_mem(&addr, 1);
addr.sun_family = PF_LOCAL;
if(path.length() >= sizeof(addr.sun_path))
diff --git a/src/lib/entropy/proc_walk/proc_walk.cpp b/src/lib/entropy/proc_walk/proc_walk.cpp
index 7ea785361..95dc4e8e3 100644
--- a/src/lib/entropy/proc_walk/proc_walk.cpp
+++ b/src/lib/entropy/proc_walk/proc_walk.cpp
@@ -9,7 +9,6 @@
#include <botan/internal/proc_walk.h>
#include <botan/secmem.h>
-#include <cstring>
#include <deque>
#ifndef _POSIX_C_SOURCE
diff --git a/src/lib/pubkey/curve25519/donna.cpp b/src/lib/pubkey/curve25519/donna.cpp
index 8a29e0db9..83d68ff6b 100644
--- a/src/lib/pubkey/curve25519/donna.cpp
+++ b/src/lib/pubkey/curve25519/donna.cpp
@@ -31,7 +31,6 @@
#include <botan/mul128.h>
#include <botan/internal/donna128.h>
#include <botan/loadstor.h>
-#include <string.h>
namespace Botan {
@@ -288,16 +287,16 @@ fmonty(limb *x2, limb *z2, /* output 2Q */
limb origx[5], origxprime[5], zzz[5], xx[5], zz[5], xxprime[5],
zzprime[5], zzzprime[5];
- memcpy(origx, x, 5 * sizeof(limb));
+ copy_mem(origx, x, 5);
fsum(x, z);
fdifference_backwards(z, origx); // does x - z
- memcpy(origxprime, xprime, sizeof(limb) * 5);
+ copy_mem(origxprime, xprime, 5);
fsum(xprime, zprime);
fdifference_backwards(zprime, origxprime);
fmul(xxprime, xprime, z);
fmul(zzprime, x, zprime);
- memcpy(origxprime, xxprime, sizeof(limb) * 5);
+ copy_mem(origxprime, xxprime, 5);
fsum(xxprime, zzprime);
fdifference_backwards(zzprime, origxprime);
fsquare_times(x3, xxprime, 1);
@@ -347,7 +346,7 @@ cmult(limb *resultx, limb *resultz, const u8 *n, const limb *q) {
unsigned i, j;
- memcpy(nqpqx, q, sizeof(limb) * 5);
+ copy_mem(nqpqx, q, 5);
for (i = 0; i < 32; ++i) {
u8 byte = n[31 - i];
@@ -381,8 +380,8 @@ cmult(limb *resultx, limb *resultz, const u8 *n, const limb *q) {
}
}
- memcpy(resultx, nqx, sizeof(limb) * 5);
- memcpy(resultz, nqz, sizeof(limb) * 5);
+ copy_mem(resultx, nqx, 5);
+ copy_mem(resultz, nqz, 5);
}
diff --git a/src/lib/pubkey/mce/binary_matrix.cpp b/src/lib/pubkey/mce/binary_matrix.cpp
index 30d04b987..12c842669 100644
--- a/src/lib/pubkey/mce/binary_matrix.cpp
+++ b/src/lib/pubkey/mce/binary_matrix.cpp
@@ -19,8 +19,7 @@ binary_matrix::binary_matrix (u32bit rown, u32bit coln)
m_coln = coln;
m_rown = rown;
m_rwdcnt = (1 + (m_coln - 1) / BITS_PER_U32);
- m_alloc_size = m_rown * (*this).m_rwdcnt * sizeof (u32bit);
- m_elem = std::vector<u32bit>((*this).m_alloc_size/4);
+ m_elem = std::vector<u32bit>(m_rown * m_rwdcnt);
}
void binary_matrix::row_xor(u32bit a, u32bit b)
diff --git a/src/lib/pubkey/mce/binary_matrix.h b/src/lib/pubkey/mce/binary_matrix.h
index 29d09cf45..feb44632f 100644
--- a/src/lib/pubkey/mce/binary_matrix.h
+++ b/src/lib/pubkey/mce/binary_matrix.h
@@ -46,13 +46,12 @@ struct binary_matrix
void set_to_zero()
{
- std::memset(&m_elem[0], 0, m_alloc_size);
+ zeroise(m_elem);
}
u32bit m_rown; // number of rows.
u32bit m_coln; // number of columns.
u32bit m_rwdcnt; // number of words in a row
- u32bit m_alloc_size; // number of allocated bytes
std::vector<u32bit> m_elem;
};
diff --git a/src/lib/pubkey/mce/code_based_key_gen.cpp b/src/lib/pubkey/mce/code_based_key_gen.cpp
index 3936e6960..150f9b2ee 100644
--- a/src/lib/pubkey/mce/code_based_key_gen.cpp
+++ b/src/lib/pubkey/mce/code_based_key_gen.cpp
@@ -173,10 +173,10 @@ McEliece_PrivateKey generate_mceliece_key( RandomNumberGenerator & rng, u32bit e
{
Linv[L[i]] = i;
}
- std::vector<byte> pubmat (R->m_alloc_size);
- for(i = 0; i < R->m_alloc_size/4; i++)
+ std::vector<byte> pubmat (R->m_elem.size() * 4);
+ for(i = 0; i < R->m_elem.size(); i++)
{
- store_le(R->m_elem[i], &pubmat[i*4] );
+ store_le(R->m_elem[i], &pubmat[i*4]);
}
return McEliece_PrivateKey(g, H, sqrtmod, Linv, pubmat);
diff --git a/src/lib/pubkey/mce/goppa_code.cpp b/src/lib/pubkey/mce/goppa_code.cpp
index bb335e994..59e8ab97d 100644
--- a/src/lib/pubkey/mce/goppa_code.cpp
+++ b/src/lib/pubkey/mce/goppa_code.cpp
@@ -179,7 +179,7 @@ secure_vector<byte> mceliece_decrypt(
secure_vector<byte> cleartext(cleartext_len);
- std::memcpy(&cleartext[0], ciphertext, cleartext_len);
+ copy_mem(&cleartext[0], ciphertext, cleartext_len);
for(u32bit i = 0; i < nb_err; i++)
{
diff --git a/src/lib/pubkey/mce/mceliece.cpp b/src/lib/pubkey/mce/mceliece.cpp
index d0c36a92e..15a6f5ea8 100644
--- a/src/lib/pubkey/mce/mceliece.cpp
+++ b/src/lib/pubkey/mce/mceliece.cpp
@@ -26,8 +26,8 @@ void concat_vectors(unsigned char* x, const unsigned char* a, const unsigned cha
{
if(dimension % 8 == 0)
{
- std::memcpy(x, a, bit_size_to_byte_size(dimension));
- std::memcpy(((unsigned char *) x) + bit_size_to_byte_size(dimension), b, bit_size_to_byte_size(codimension));
+ copy_mem(x, a, bit_size_to_byte_size(dimension));
+ copy_mem(((unsigned char *) x) + bit_size_to_byte_size(dimension), b, bit_size_to_byte_size(codimension));
}
else
{
@@ -35,7 +35,7 @@ void concat_vectors(unsigned char* x, const unsigned char* a, const unsigned cha
i = dimension - 8 * (dimension/ 8);
j = 8 - i;
l = dimension / 8;
- std::memcpy(x, a, 1 * (dimension / 8));
+ copy_mem(x, a, 1 * (dimension / 8));
x[l] = ((byte) (a[l] & ((1 << i) - 1)));
for(k = 0; k < codimension / 8; ++k)
@@ -149,7 +149,7 @@ secure_vector<byte> McEliece_Public_Operation::encrypt(const byte msg[], size_t
std::vector<byte> ciphertext_tmp = mceliece_encrypt( message_word, m_pub_key.get_public_matrix(), err_pos, m_code_length);
- std::memcpy(&ciphertext[0], &ciphertext_tmp[0], ciphertext.size());
+ copy_mem(&ciphertext[0], &ciphertext_tmp[0], ciphertext.size());
return ciphertext;
}
diff --git a/src/lib/pubkey/mce/mceliece.h b/src/lib/pubkey/mce/mceliece.h
index 649153233..c77dfe5b1 100644
--- a/src/lib/pubkey/mce/mceliece.h
+++ b/src/lib/pubkey/mce/mceliece.h
@@ -37,7 +37,7 @@ class mceliece_message_parts
m_code_length(code_length)
{
m_message_word.resize(message_length);
- std::memcpy(&m_message_word[0], message, message_length);
+ copy_mem(&m_message_word[0], message, message_length);
};
mceliece_message_parts(const secure_vector<gf2m>& err_pos, const secure_vector<byte>& message, unsigned code_length)
@@ -70,16 +70,16 @@ class mceliece_message_parts
}
size_t err_vec_start_pos = message_concat_errors_len - err_vec_len;
m_message_word = secure_vector<byte>(err_vec_start_pos );
- std::memcpy(&m_message_word[0], &message_concat_errors[0], err_vec_start_pos);
+ copy_mem(&m_message_word[0], &message_concat_errors[0], err_vec_start_pos);
m_error_vector = secure_vector<byte>(err_vec_len );
- std::memcpy(&m_error_vector[0], &message_concat_errors[err_vec_start_pos], err_vec_len);
+ copy_mem(&m_error_vector[0], &message_concat_errors[err_vec_start_pos], err_vec_len);
};
secure_vector<byte> get_concat() const
{
secure_vector<byte> result(m_error_vector.size() + m_message_word.size());
- std::memcpy(&result[0], &m_message_word[0], m_message_word.size());
- std::memcpy(&result[m_message_word.size()], &m_error_vector[0], m_error_vector.size());
+ copy_mem(&result[0], &m_message_word[0], m_message_word.size());
+ copy_mem(&result[m_message_word.size()], &m_error_vector[0], m_error_vector.size());
return result;
};
secure_vector<gf2m> get_error_positions() const
diff --git a/src/lib/pubkey/mce/polyn_gf2m.cpp b/src/lib/pubkey/mce/polyn_gf2m.cpp
index e340e29e8..489332069 100644
--- a/src/lib/pubkey/mce/polyn_gf2m.cpp
+++ b/src/lib/pubkey/mce/polyn_gf2m.cpp
@@ -10,9 +10,6 @@
*/
#include <botan/polyn_gf2m.h>
-#include <cstring>
-#include <iostream>
-
#include <botan/gf2m_rootfind_dcmp.h>
#include <botan/code_based_util.h>
#include <botan/gf2m_small_m.h>
@@ -219,7 +216,7 @@ void polyn_gf2m::encode(u32bit min_numo_coeffs, byte* mem, u32bit mem_len) const
void polyn_gf2m::set_to_zero()
{
- memset(&this->coeff[0], 0, this->coeff.size() * sizeof (gf2m));
+ clear_mem(&this->coeff[0], this->coeff.size());
this->m_deg = -1;
}
@@ -304,8 +301,8 @@ std::vector<polyn_gf2m> polyn_gf2m::sqmod_init(const polyn_gf2m & g)
for (; i < d; ++i)
{
- memset(&sq[i].coeff[0], 0, 2 * sizeof (gf2m));
- memcpy(&sq[i].coeff[0] + 2, &sq[i - 1].coeff[0], d * sizeof (gf2m));
+ clear_mem(&sq[i].coeff[0], 2);
+ copy_mem(&sq[i].coeff[0] + 2, &sq[i - 1].coeff[0], d);
sq[i].set_degree( sq[i - 1].get_degree() + 2);
polyn_gf2m::remainder(sq[i], g);
}
diff --git a/src/lib/rng/system_rng/system_rng.cpp b/src/lib/rng/system_rng/system_rng.cpp
index 2f7c0f168..59a8b014f 100644
--- a/src/lib/rng/system_rng/system_rng.cpp
+++ b/src/lib/rng/system_rng/system_rng.cpp
@@ -20,7 +20,6 @@
#include <sys/stat.h>
#include <fcntl.h>
#include <unistd.h>
-#include <string.h>
#include <errno.h>
#endif
diff --git a/src/lib/utils/loadstor.h b/src/lib/utils/loadstor.h
index 771bbd533..4db3d07fa 100644
--- a/src/lib/utils/loadstor.h
+++ b/src/lib/utils/loadstor.h
@@ -12,7 +12,7 @@
#include <botan/types.h>
#include <botan/bswap.h>
#include <botan/get_byte.h>
-#include <cstring>
+#include <botan/mem_ops.h>
#include <vector>
#if BOTAN_TARGET_UNALIGNED_MEMORY_ACCESS_OK