diff options
author | lloyd <[email protected]> | 2015-01-23 17:47:31 +0000 |
---|---|---|
committer | lloyd <[email protected]> | 2015-01-23 17:47:31 +0000 |
commit | 848314e16daed06e6e519dbf8c40edf9c85a51bf (patch) | |
tree | a7d246972486ae5f49090689090af7d351110ec6 /src/lib/pubkey | |
parent | b6cc9a4084caf6d9d4b955fadc321f6521f2b36e (diff) |
Centralize where string.h/cstring is included to mem_ops.h
See github 42 for background
Diffstat (limited to 'src/lib/pubkey')
-rw-r--r-- | src/lib/pubkey/curve25519/donna.cpp | 13 | ||||
-rw-r--r-- | src/lib/pubkey/mce/binary_matrix.cpp | 3 | ||||
-rw-r--r-- | src/lib/pubkey/mce/binary_matrix.h | 3 | ||||
-rw-r--r-- | src/lib/pubkey/mce/code_based_key_gen.cpp | 6 | ||||
-rw-r--r-- | src/lib/pubkey/mce/goppa_code.cpp | 2 | ||||
-rw-r--r-- | src/lib/pubkey/mce/mceliece.cpp | 8 | ||||
-rw-r--r-- | src/lib/pubkey/mce/mceliece.h | 10 | ||||
-rw-r--r-- | src/lib/pubkey/mce/polyn_gf2m.cpp | 9 |
8 files changed, 24 insertions, 30 deletions
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); } |