aboutsummaryrefslogtreecommitdiffstats
path: root/src/lib/pubkey/mce/mceliece.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/lib/pubkey/mce/mceliece.cpp')
-rw-r--r--src/lib/pubkey/mce/mceliece.cpp52
1 files changed, 26 insertions, 26 deletions
diff --git a/src/lib/pubkey/mce/mceliece.cpp b/src/lib/pubkey/mce/mceliece.cpp
index 7617ff11f..fd985c032 100644
--- a/src/lib/pubkey/mce/mceliece.cpp
+++ b/src/lib/pubkey/mce/mceliece.cpp
@@ -19,10 +19,10 @@ namespace Botan {
namespace {
-secure_vector<byte> concat_vectors(const secure_vector<byte>& a, const secure_vector<byte>& b,
- u32bit dimension, u32bit codimension)
+secure_vector<uint8_t> concat_vectors(const secure_vector<uint8_t>& a, const secure_vector<uint8_t>& b,
+ uint32_t dimension, uint32_t codimension)
{
- secure_vector<byte> x(bit_size_to_byte_size(dimension) + bit_size_to_byte_size(codimension));
+ secure_vector<uint8_t> x(bit_size_to_byte_size(dimension) + bit_size_to_byte_size(codimension));
const size_t final_bits = dimension % 8;
@@ -35,31 +35,31 @@ secure_vector<byte> concat_vectors(const secure_vector<byte>& a, const secure_ve
else
{
copy_mem(&x[0], a.data(), (dimension / 8));
- u32bit l = dimension / 8;
- x[l] = static_cast<byte>(a[l] & ((1 << final_bits) - 1));
+ uint32_t l = dimension / 8;
+ x[l] = static_cast<uint8_t>(a[l] & ((1 << final_bits) - 1));
- for(u32bit k = 0; k < codimension / 8; ++k)
+ for(uint32_t k = 0; k < codimension / 8; ++k)
{
- x[l] ^= static_cast<byte>(b[k] << final_bits);
+ x[l] ^= static_cast<uint8_t>(b[k] << final_bits);
++l;
- x[l] = static_cast<byte>(b[k] >> (8 - final_bits));
+ x[l] = static_cast<uint8_t>(b[k] >> (8 - final_bits));
}
- x[l] ^= static_cast<byte>(b[codimension/8] << final_bits);
+ x[l] ^= static_cast<uint8_t>(b[codimension/8] << final_bits);
}
return x;
}
-secure_vector<byte> mult_by_pubkey(const secure_vector<byte>& cleartext,
- std::vector<byte> const& public_matrix,
- u32bit code_length, u32bit t)
+secure_vector<uint8_t> mult_by_pubkey(const secure_vector<uint8_t>& cleartext,
+ std::vector<uint8_t> const& public_matrix,
+ uint32_t code_length, uint32_t t)
{
- const u32bit ext_deg = ceil_log2(code_length);
- const u32bit codimension = ext_deg * t;
- const u32bit dimension = code_length - codimension;
- secure_vector<byte> cR(bit_size_to_32bit_size(codimension) * sizeof(u32bit));
+ const uint32_t ext_deg = ceil_log2(code_length);
+ const uint32_t codimension = ext_deg * t;
+ const uint32_t dimension = code_length - codimension;
+ secure_vector<uint8_t> cR(bit_size_to_32bit_size(codimension) * sizeof(uint32_t));
- const byte* pt = public_matrix.data();
+ const uint8_t* pt = public_matrix.data();
for(size_t i = 0; i < dimension / 8; ++i)
{
@@ -82,16 +82,16 @@ secure_vector<byte> mult_by_pubkey(const secure_vector<byte>& cleartext,
pt += cR.size();
}
- secure_vector<byte> ciphertext = concat_vectors(cleartext, cR, dimension, codimension);
+ secure_vector<uint8_t> ciphertext = concat_vectors(cleartext, cR, dimension, codimension);
ciphertext.resize((code_length+7)/8);
return ciphertext;
}
-secure_vector<byte> create_random_error_vector(unsigned code_length,
+secure_vector<uint8_t> create_random_error_vector(unsigned code_length,
unsigned error_weight,
RandomNumberGenerator& rng)
{
- secure_vector<byte> result((code_length+7)/8);
+ secure_vector<uint8_t> result((code_length+7)/8);
size_t bits_set = 0;
@@ -101,7 +101,7 @@ secure_vector<byte> create_random_error_vector(unsigned code_length,
const size_t byte_pos = x / 8, bit_pos = x % 8;
- const byte mask = (1 << bit_pos);
+ const uint8_t mask = (1 << bit_pos);
if(result[byte_pos] & mask)
continue; // already set this bit
@@ -115,15 +115,15 @@ secure_vector<byte> create_random_error_vector(unsigned code_length,
}
-void mceliece_encrypt(secure_vector<byte>& ciphertext_out,
- secure_vector<byte>& error_mask_out,
- const secure_vector<byte>& plaintext,
+void mceliece_encrypt(secure_vector<uint8_t>& ciphertext_out,
+ secure_vector<uint8_t>& error_mask_out,
+ const secure_vector<uint8_t>& plaintext,
const McEliece_PublicKey& key,
RandomNumberGenerator& rng)
{
- secure_vector<byte> error_mask = create_random_error_vector(key.get_code_length(), key.get_t(), rng);
+ secure_vector<uint8_t> error_mask = create_random_error_vector(key.get_code_length(), key.get_t(), rng);
- secure_vector<byte> ciphertext = mult_by_pubkey(plaintext, key.get_public_matrix(),
+ secure_vector<uint8_t> ciphertext = mult_by_pubkey(plaintext, key.get_public_matrix(),
key.get_code_length(), key.get_t());
ciphertext ^= error_mask;