aboutsummaryrefslogtreecommitdiffstats
path: root/src/pk_pad
diff options
context:
space:
mode:
Diffstat (limited to 'src/pk_pad')
-rw-r--r--src/pk_pad/eme.cpp8
-rw-r--r--src/pk_pad/eme.h12
-rw-r--r--src/pk_pad/eme1/eme1.cpp17
-rw-r--r--src/pk_pad/eme1/eme1.h6
-rw-r--r--src/pk_pad/eme_pkcs/eme_pkcs.cpp10
-rw-r--r--src/pk_pad/eme_pkcs/eme_pkcs.h4
-rw-r--r--src/pk_pad/emsa.h8
-rw-r--r--src/pk_pad/emsa1/emsa1.cpp14
-rw-r--r--src/pk_pad/emsa1/emsa1.h6
-rw-r--r--src/pk_pad/emsa1_bsi/emsa1_bsi.cpp2
-rw-r--r--src/pk_pad/emsa1_bsi/emsa1_bsi.h2
-rw-r--r--src/pk_pad/emsa2/emsa2.cpp16
-rw-r--r--src/pk_pad/emsa2/emsa2.h8
-rw-r--r--src/pk_pad/emsa3/emsa3.cpp30
-rw-r--r--src/pk_pad/emsa3/emsa3.h16
-rw-r--r--src/pk_pad/emsa4/emsa4.cpp52
-rw-r--r--src/pk_pad/emsa4/emsa4.h6
-rw-r--r--src/pk_pad/emsa_raw/emsa_raw.cpp10
-rw-r--r--src/pk_pad/emsa_raw/emsa_raw.h8
-rw-r--r--src/pk_pad/hash_id/hash_id.cpp43
-rw-r--r--src/pk_pad/hash_id/hash_id.h2
21 files changed, 151 insertions, 129 deletions
diff --git a/src/pk_pad/eme.cpp b/src/pk_pad/eme.cpp
index cfdaa240d..f90239d8c 100644
--- a/src/pk_pad/eme.cpp
+++ b/src/pk_pad/eme.cpp
@@ -12,7 +12,7 @@ namespace Botan {
/*
* Encode a message
*/
-SecureVector<byte> EME::encode(const byte msg[], size_t msg_len,
+secure_vector<byte> EME::encode(const byte msg[], size_t msg_len,
size_t key_bits,
RandomNumberGenerator& rng) const
{
@@ -22,7 +22,7 @@ SecureVector<byte> EME::encode(const byte msg[], size_t msg_len,
/*
* Encode a message
*/
-SecureVector<byte> EME::encode(const MemoryRegion<byte>& msg,
+secure_vector<byte> EME::encode(const secure_vector<byte>& msg,
size_t key_bits,
RandomNumberGenerator& rng) const
{
@@ -32,7 +32,7 @@ SecureVector<byte> EME::encode(const MemoryRegion<byte>& msg,
/*
* Decode a message
*/
-SecureVector<byte> EME::decode(const byte msg[], size_t msg_len,
+secure_vector<byte> EME::decode(const byte msg[], size_t msg_len,
size_t key_bits) const
{
return unpad(msg, msg_len, key_bits);
@@ -41,7 +41,7 @@ SecureVector<byte> EME::decode(const byte msg[], size_t msg_len,
/*
* Decode a message
*/
-SecureVector<byte> EME::decode(const MemoryRegion<byte>& msg,
+secure_vector<byte> EME::decode(const secure_vector<byte>& msg,
size_t key_bits) const
{
return unpad(&msg[0], msg.size(), key_bits);
diff --git a/src/pk_pad/eme.h b/src/pk_pad/eme.h
index 4e89ef9d3..6f8acaa23 100644
--- a/src/pk_pad/eme.h
+++ b/src/pk_pad/eme.h
@@ -34,7 +34,7 @@ class BOTAN_DLL EME
* @param rng a random number generator
* @return encoded plaintext
*/
- SecureVector<byte> encode(const byte in[],
+ secure_vector<byte> encode(const byte in[],
size_t in_length,
size_t key_length,
RandomNumberGenerator& rng) const;
@@ -46,7 +46,7 @@ class BOTAN_DLL EME
* @param rng a random number generator
* @return encoded plaintext
*/
- SecureVector<byte> encode(const MemoryRegion<byte>& in,
+ secure_vector<byte> encode(const secure_vector<byte>& in,
size_t key_length,
RandomNumberGenerator& rng) const;
@@ -57,7 +57,7 @@ class BOTAN_DLL EME
* @param key_length length of the key in bits
* @return plaintext
*/
- SecureVector<byte> decode(const byte in[],
+ secure_vector<byte> decode(const byte in[],
size_t in_length,
size_t key_length) const;
@@ -67,7 +67,7 @@ class BOTAN_DLL EME
* @param key_length length of the key in bits
* @return plaintext
*/
- SecureVector<byte> decode(const MemoryRegion<byte>& in,
+ secure_vector<byte> decode(const secure_vector<byte>& in,
size_t key_length) const;
virtual ~EME() {}
@@ -80,7 +80,7 @@ class BOTAN_DLL EME
* @param rng a random number generator
* @return encoded plaintext
*/
- virtual SecureVector<byte> pad(const byte in[],
+ virtual secure_vector<byte> pad(const byte in[],
size_t in_length,
size_t key_length,
RandomNumberGenerator& rng) const = 0;
@@ -92,7 +92,7 @@ class BOTAN_DLL EME
* @param key_length length of the key in bits
* @return plaintext
*/
- virtual SecureVector<byte> unpad(const byte in[],
+ virtual secure_vector<byte> unpad(const byte in[],
size_t in_length,
size_t key_length) const = 0;
};
diff --git a/src/pk_pad/eme1/eme1.cpp b/src/pk_pad/eme1/eme1.cpp
index 1cc0c332d..57275d4f9 100644
--- a/src/pk_pad/eme1/eme1.cpp
+++ b/src/pk_pad/eme1/eme1.cpp
@@ -15,7 +15,7 @@ namespace Botan {
/*
* EME1 Pad Operation
*/
-SecureVector<byte> EME1::pad(const byte in[], size_t in_length,
+secure_vector<byte> EME1::pad(const byte in[], size_t in_length,
size_t key_length,
RandomNumberGenerator& rng) const
{
@@ -24,13 +24,13 @@ SecureVector<byte> EME1::pad(const byte in[], size_t in_length,
if(in_length > key_length - 2*Phash.size() - 1)
throw Invalid_Argument("EME1: Input is too large");
- SecureVector<byte> out(key_length);
+ secure_vector<byte> out(key_length);
rng.randomize(&out[0], Phash.size());
- out.copy(Phash.size(), &Phash[0], Phash.size());
+ buffer_insert(out, Phash.size(), &Phash[0], Phash.size());
out[out.size() - in_length - 1] = 0x01;
- out.copy(out.size() - in_length, in, in_length);
+ buffer_insert(out, out.size() - in_length, in, in_length);
mgf->mask(&out[0], Phash.size(),
&out[Phash.size()], out.size() - Phash.size());
@@ -44,7 +44,7 @@ SecureVector<byte> EME1::pad(const byte in[], size_t in_length,
/*
* EME1 Unpad Operation
*/
-SecureVector<byte> EME1::unpad(const byte in[], size_t in_length,
+secure_vector<byte> EME1::unpad(const byte in[], size_t in_length,
size_t key_length) const
{
/*
@@ -65,8 +65,8 @@ SecureVector<byte> EME1::unpad(const byte in[], size_t in_length,
if(in_length > key_length)
in_length = 0;
- SecureVector<byte> input(key_length);
- input.copy(key_length - in_length, in, in_length);
+ secure_vector<byte> input(key_length);
+ buffer_insert(input, key_length - in_length, in, in_length);
mgf->mask(&input[Phash.size()], input.size() - Phash.size(),
&input[0], Phash.size());
@@ -104,8 +104,7 @@ SecureVector<byte> EME1::unpad(const byte in[], size_t in_length,
if(bad_input)
throw Decoding_Error("Invalid EME1 encoding");
- return SecureVector<byte>(input + delim_idx + 1,
- input.size() - delim_idx - 1);
+ return secure_vector<byte>(&input[delim_idx + 1], &input[input.size()]);
}
/*
diff --git a/src/pk_pad/eme1/eme1.h b/src/pk_pad/eme1/eme1.h
index 0d0223de0..eb6fc6bf5 100644
--- a/src/pk_pad/eme1/eme1.h
+++ b/src/pk_pad/eme1/eme1.h
@@ -30,11 +30,11 @@ class BOTAN_DLL EME1 : public EME
~EME1() { delete mgf; }
private:
- SecureVector<byte> pad(const byte[], size_t, size_t,
+ secure_vector<byte> pad(const byte[], size_t, size_t,
RandomNumberGenerator&) const;
- SecureVector<byte> unpad(const byte[], size_t, size_t) const;
+ secure_vector<byte> unpad(const byte[], size_t, size_t) const;
- SecureVector<byte> Phash;
+ secure_vector<byte> Phash;
MGF* mgf;
};
diff --git a/src/pk_pad/eme_pkcs/eme_pkcs.cpp b/src/pk_pad/eme_pkcs/eme_pkcs.cpp
index c4d6838b1..0e7d1fc30 100644
--- a/src/pk_pad/eme_pkcs/eme_pkcs.cpp
+++ b/src/pk_pad/eme_pkcs/eme_pkcs.cpp
@@ -12,7 +12,7 @@ namespace Botan {
/*
* PKCS1 Pad Operation
*/
-SecureVector<byte> EME_PKCS1v15::pad(const byte in[], size_t inlen,
+secure_vector<byte> EME_PKCS1v15::pad(const byte in[], size_t inlen,
size_t olen,
RandomNumberGenerator& rng) const
{
@@ -23,13 +23,13 @@ SecureVector<byte> EME_PKCS1v15::pad(const byte in[], size_t inlen,
if(inlen > olen - 10)
throw Encoding_Error("PKCS1: Input is too large");
- SecureVector<byte> out(olen);
+ secure_vector<byte> out(olen);
out[0] = 0x02;
for(size_t j = 1; j != olen - inlen - 1; ++j)
while(out[j] == 0)
out[j] = rng.next_byte();
- out.copy(olen - inlen, in, inlen);
+ buffer_insert(out, olen - inlen, in, inlen);
return out;
}
@@ -37,7 +37,7 @@ SecureVector<byte> EME_PKCS1v15::pad(const byte in[], size_t inlen,
/*
* PKCS1 Unpad Operation
*/
-SecureVector<byte> EME_PKCS1v15::unpad(const byte in[], size_t inlen,
+secure_vector<byte> EME_PKCS1v15::unpad(const byte in[], size_t inlen,
size_t key_len) const
{
if(inlen != key_len / 8 || inlen < 10 || in[0] != 0x02)
@@ -53,7 +53,7 @@ SecureVector<byte> EME_PKCS1v15::unpad(const byte in[], size_t inlen,
if(seperator < 9)
throw Decoding_Error("PKCS1::unpad");
- return SecureVector<byte>(in + seperator + 1, inlen - seperator - 1);
+ return secure_vector<byte>(&in[seperator + 1], &in[inlen]);
}
/*
diff --git a/src/pk_pad/eme_pkcs/eme_pkcs.h b/src/pk_pad/eme_pkcs/eme_pkcs.h
index 4c4614bda..2808e18d6 100644
--- a/src/pk_pad/eme_pkcs/eme_pkcs.h
+++ b/src/pk_pad/eme_pkcs/eme_pkcs.h
@@ -20,9 +20,9 @@ class BOTAN_DLL EME_PKCS1v15 : public EME
public:
size_t maximum_input_size(size_t) const;
private:
- SecureVector<byte> pad(const byte[], size_t, size_t,
+ secure_vector<byte> pad(const byte[], size_t, size_t,
RandomNumberGenerator&) const;
- SecureVector<byte> unpad(const byte[], size_t, size_t) const;
+ secure_vector<byte> unpad(const byte[], size_t, size_t) const;
};
}
diff --git a/src/pk_pad/emsa.h b/src/pk_pad/emsa.h
index e943fc5eb..821ca782f 100644
--- a/src/pk_pad/emsa.h
+++ b/src/pk_pad/emsa.h
@@ -29,7 +29,7 @@ class BOTAN_DLL EMSA
/**
* @return raw hash
*/
- virtual SecureVector<byte> raw_data() = 0;
+ virtual secure_vector<byte> raw_data() = 0;
/**
* Return the encoding of a message
@@ -38,7 +38,7 @@ class BOTAN_DLL EMSA
* @param rng a random number generator
* @return encoded signature
*/
- virtual SecureVector<byte> encoding_of(const MemoryRegion<byte>& msg,
+ virtual secure_vector<byte> encoding_of(const secure_vector<byte>& msg,
size_t output_bits,
RandomNumberGenerator& rng) = 0;
@@ -49,8 +49,8 @@ class BOTAN_DLL EMSA
* @param key_bits the size of the key in bits
* @return true if coded is a valid encoding of raw, otherwise false
*/
- virtual bool verify(const MemoryRegion<byte>& coded,
- const MemoryRegion<byte>& raw,
+ virtual bool verify(const secure_vector<byte>& coded,
+ const secure_vector<byte>& raw,
size_t key_bits) = 0;
virtual ~EMSA() {}
};
diff --git a/src/pk_pad/emsa1/emsa1.cpp b/src/pk_pad/emsa1/emsa1.cpp
index ba861898a..7f9a1885f 100644
--- a/src/pk_pad/emsa1/emsa1.cpp
+++ b/src/pk_pad/emsa1/emsa1.cpp
@@ -11,7 +11,7 @@ namespace Botan {
namespace {
-SecureVector<byte> emsa1_encoding(const MemoryRegion<byte>& msg,
+secure_vector<byte> emsa1_encoding(const secure_vector<byte>& msg,
size_t output_bits)
{
if(8*msg.size() <= output_bits)
@@ -20,7 +20,7 @@ SecureVector<byte> emsa1_encoding(const MemoryRegion<byte>& msg,
size_t shift = 8*msg.size() - output_bits;
size_t byte_shift = shift / 8, bit_shift = shift % 8;
- SecureVector<byte> digest(msg.size() - byte_shift);
+ secure_vector<byte> digest(msg.size() - byte_shift);
for(size_t j = 0; j != msg.size() - byte_shift; ++j)
digest[j] = msg[j];
@@ -51,7 +51,7 @@ void EMSA1::update(const byte input[], size_t length)
/*
* Return the raw (unencoded) data
*/
-SecureVector<byte> EMSA1::raw_data()
+secure_vector<byte> EMSA1::raw_data()
{
return hash->final();
}
@@ -59,7 +59,7 @@ SecureVector<byte> EMSA1::raw_data()
/*
* EMSA1 Encode Operation
*/
-SecureVector<byte> EMSA1::encoding_of(const MemoryRegion<byte>& msg,
+secure_vector<byte> EMSA1::encoding_of(const secure_vector<byte>& msg,
size_t output_bits,
RandomNumberGenerator&)
{
@@ -71,14 +71,14 @@ SecureVector<byte> EMSA1::encoding_of(const MemoryRegion<byte>& msg,
/*
* EMSA1 Decode/Verify Operation
*/
-bool EMSA1::verify(const MemoryRegion<byte>& coded,
- const MemoryRegion<byte>& raw, size_t key_bits)
+bool EMSA1::verify(const secure_vector<byte>& coded,
+ const secure_vector<byte>& raw, size_t key_bits)
{
try {
if(raw.size() != hash->output_length())
throw Encoding_Error("EMSA1::encoding_of: Invalid size for input");
- SecureVector<byte> our_coding = emsa1_encoding(raw, key_bits);
+ secure_vector<byte> our_coding = emsa1_encoding(raw, key_bits);
if(our_coding == coded) return true;
if(our_coding[0] != 0) return false;
diff --git a/src/pk_pad/emsa1/emsa1.h b/src/pk_pad/emsa1/emsa1.h
index 120cb0cd3..f84ca5ae7 100644
--- a/src/pk_pad/emsa1/emsa1.h
+++ b/src/pk_pad/emsa1/emsa1.h
@@ -32,12 +32,12 @@ class BOTAN_DLL EMSA1 : public EMSA
const HashFunction* hash_ptr() const { return hash; }
private:
void update(const byte[], size_t);
- SecureVector<byte> raw_data();
+ secure_vector<byte> raw_data();
- SecureVector<byte> encoding_of(const MemoryRegion<byte>&, size_t,
+ secure_vector<byte> encoding_of(const secure_vector<byte>&, size_t,
RandomNumberGenerator& rng);
- bool verify(const MemoryRegion<byte>&, const MemoryRegion<byte>&,
+ bool verify(const secure_vector<byte>&, const secure_vector<byte>&,
size_t);
HashFunction* hash;
diff --git a/src/pk_pad/emsa1_bsi/emsa1_bsi.cpp b/src/pk_pad/emsa1_bsi/emsa1_bsi.cpp
index bbcc5aae7..9096edfbf 100644
--- a/src/pk_pad/emsa1_bsi/emsa1_bsi.cpp
+++ b/src/pk_pad/emsa1_bsi/emsa1_bsi.cpp
@@ -13,7 +13,7 @@ namespace Botan {
/*
* EMSA1 BSI Encode Operation
*/
-SecureVector<byte> EMSA1_BSI::encoding_of(const MemoryRegion<byte>& msg,
+secure_vector<byte> EMSA1_BSI::encoding_of(const secure_vector<byte>& msg,
size_t output_bits,
RandomNumberGenerator&)
{
diff --git a/src/pk_pad/emsa1_bsi/emsa1_bsi.h b/src/pk_pad/emsa1_bsi/emsa1_bsi.h
index 51ed6bc00..1b90f48df 100644
--- a/src/pk_pad/emsa1_bsi/emsa1_bsi.h
+++ b/src/pk_pad/emsa1_bsi/emsa1_bsi.h
@@ -26,7 +26,7 @@ class BOTAN_DLL EMSA1_BSI : public EMSA1
*/
EMSA1_BSI(HashFunction* hash) : EMSA1(hash) {}
private:
- SecureVector<byte> encoding_of(const MemoryRegion<byte>&, size_t,
+ secure_vector<byte> encoding_of(const secure_vector<byte>&, size_t,
RandomNumberGenerator& rng);
};
diff --git a/src/pk_pad/emsa2/emsa2.cpp b/src/pk_pad/emsa2/emsa2.cpp
index 96ac8e908..d299ddacd 100644
--- a/src/pk_pad/emsa2/emsa2.cpp
+++ b/src/pk_pad/emsa2/emsa2.cpp
@@ -15,9 +15,9 @@ namespace {
/*
* EMSA2 Encode Operation
*/
-SecureVector<byte> emsa2_encoding(const MemoryRegion<byte>& msg,
+secure_vector<byte> emsa2_encoding(const secure_vector<byte>& msg,
size_t output_bits,
- const MemoryRegion<byte>& empty_hash,
+ const secure_vector<byte>& empty_hash,
byte hash_id)
{
const size_t HASH_SIZE = empty_hash.size();
@@ -34,12 +34,12 @@ SecureVector<byte> emsa2_encoding(const MemoryRegion<byte>& msg,
if(empty_hash[j] != msg[j])
empty = false;
- SecureVector<byte> output(output_length);
+ secure_vector<byte> output(output_length);
output[0] = (empty ? 0x4B : 0x6B);
output[output_length - 3 - HASH_SIZE] = 0xBA;
set_mem(&output[1], output_length - 4 - HASH_SIZE, 0xBB);
- output.copy(output_length - (HASH_SIZE + 2), &msg[0], msg.size());
+ buffer_insert(output, output_length - (HASH_SIZE + 2), &msg[0], msg.size());
output[output_length-2] = hash_id;
output[output_length-1] = 0xCC;
@@ -59,7 +59,7 @@ void EMSA2::update(const byte input[], size_t length)
/*
* Return the raw (unencoded) data
*/
-SecureVector<byte> EMSA2::raw_data()
+secure_vector<byte> EMSA2::raw_data()
{
return hash->final();
}
@@ -67,7 +67,7 @@ SecureVector<byte> EMSA2::raw_data()
/*
* EMSA2 Encode Operation
*/
-SecureVector<byte> EMSA2::encoding_of(const MemoryRegion<byte>& msg,
+secure_vector<byte> EMSA2::encoding_of(const secure_vector<byte>& msg,
size_t output_bits,
RandomNumberGenerator&)
{
@@ -77,8 +77,8 @@ SecureVector<byte> EMSA2::encoding_of(const MemoryRegion<byte>& msg,
/*
* EMSA2 Verify Operation
*/
-bool EMSA2::verify(const MemoryRegion<byte>& coded,
- const MemoryRegion<byte>& raw,
+bool EMSA2::verify(const secure_vector<byte>& coded,
+ const secure_vector<byte>& raw,
size_t key_bits)
{
try
diff --git a/src/pk_pad/emsa2/emsa2.h b/src/pk_pad/emsa2/emsa2.h
index 9e0fa6a95..fb0cecb21 100644
--- a/src/pk_pad/emsa2/emsa2.h
+++ b/src/pk_pad/emsa2/emsa2.h
@@ -27,15 +27,15 @@ class BOTAN_DLL EMSA2 : public EMSA
~EMSA2() { delete hash; }
private:
void update(const byte[], size_t);
- SecureVector<byte> raw_data();
+ secure_vector<byte> raw_data();
- SecureVector<byte> encoding_of(const MemoryRegion<byte>&, size_t,
+ secure_vector<byte> encoding_of(const secure_vector<byte>&, size_t,
RandomNumberGenerator& rng);
- bool verify(const MemoryRegion<byte>&, const MemoryRegion<byte>&,
+ bool verify(const secure_vector<byte>&, const secure_vector<byte>&,
size_t);
- SecureVector<byte> empty_hash;
+ secure_vector<byte> empty_hash;
HashFunction* hash;
byte hash_id;
};
diff --git a/src/pk_pad/emsa3/emsa3.cpp b/src/pk_pad/emsa3/emsa3.cpp
index a381a82f6..0d603c508 100644
--- a/src/pk_pad/emsa3/emsa3.cpp
+++ b/src/pk_pad/emsa3/emsa3.cpp
@@ -15,7 +15,7 @@ namespace {
/*
* EMSA3 Encode Operation
*/
-SecureVector<byte> emsa3_encoding(const MemoryRegion<byte>& msg,
+secure_vector<byte> emsa3_encoding(const secure_vector<byte>& msg,
size_t output_bits,
const byte hash_id[],
size_t hash_id_length)
@@ -24,14 +24,14 @@ SecureVector<byte> emsa3_encoding(const MemoryRegion<byte>& msg,
if(output_length < hash_id_length + msg.size() + 10)
throw Encoding_Error("emsa3_encoding: Output length is too small");
- SecureVector<byte> T(output_length);
+ secure_vector<byte> T(output_length);
const size_t P_LENGTH = output_length - msg.size() - hash_id_length - 2;
T[0] = 0x01;
set_mem(&T[1], P_LENGTH, 0xFF);
T[P_LENGTH+1] = 0x00;
- T.copy(P_LENGTH+2, hash_id, hash_id_length);
- T.copy(output_length-msg.size(), &msg[0], msg.size());
+ buffer_insert(T, P_LENGTH+2, hash_id, hash_id_length);
+ buffer_insert(T, output_length-msg.size(), &msg[0], msg.size());
return T;
}
@@ -48,7 +48,7 @@ void EMSA3::update(const byte input[], size_t length)
/*
* Return the raw (unencoded) data
*/
-SecureVector<byte> EMSA3::raw_data()
+secure_vector<byte> EMSA3::raw_data()
{
return hash->final();
}
@@ -56,7 +56,7 @@ SecureVector<byte> EMSA3::raw_data()
/*
* EMSA3 Encode Operation
*/
-SecureVector<byte> EMSA3::encoding_of(const MemoryRegion<byte>& msg,
+secure_vector<byte> EMSA3::encoding_of(const secure_vector<byte>& msg,
size_t output_bits,
RandomNumberGenerator&)
{
@@ -70,8 +70,8 @@ SecureVector<byte> EMSA3::encoding_of(const MemoryRegion<byte>& msg,
/*
* Default signature decoding
*/
-bool EMSA3::verify(const MemoryRegion<byte>& coded,
- const MemoryRegion<byte>& raw,
+bool EMSA3::verify(const secure_vector<byte>& coded,
+ const secure_vector<byte>& raw,
size_t key_bits)
{
if(raw.size() != hash->output_length())
@@ -115,9 +115,9 @@ void EMSA3_Raw::update(const byte input[], size_t length)
/*
* Return the raw (unencoded) data
*/
-SecureVector<byte> EMSA3_Raw::raw_data()
+secure_vector<byte> EMSA3_Raw::raw_data()
{
- SecureVector<byte> ret;
+ secure_vector<byte> ret;
std::swap(ret, message);
return ret;
}
@@ -125,23 +125,23 @@ SecureVector<byte> EMSA3_Raw::raw_data()
/*
* EMSA3_Raw Encode Operation
*/
-SecureVector<byte> EMSA3_Raw::encoding_of(const MemoryRegion<byte>& msg,
+secure_vector<byte> EMSA3_Raw::encoding_of(const secure_vector<byte>& msg,
size_t output_bits,
RandomNumberGenerator&)
{
- return emsa3_encoding(msg, output_bits, 0, 0);
+ return emsa3_encoding(msg, output_bits, nullptr, 0);
}
/*
* Default signature decoding
*/
-bool EMSA3_Raw::verify(const MemoryRegion<byte>& coded,
- const MemoryRegion<byte>& raw,
+bool EMSA3_Raw::verify(const secure_vector<byte>& coded,
+ const secure_vector<byte>& raw,
size_t key_bits)
{
try
{
- return (coded == emsa3_encoding(raw, key_bits, 0, 0));
+ return (coded == emsa3_encoding(raw, key_bits, nullptr, 0));
}
catch(...)
{
diff --git a/src/pk_pad/emsa3/emsa3.h b/src/pk_pad/emsa3/emsa3.h
index 5faf9d7e5..9fbda67ee 100644
--- a/src/pk_pad/emsa3/emsa3.h
+++ b/src/pk_pad/emsa3/emsa3.h
@@ -29,16 +29,16 @@ class BOTAN_DLL EMSA3 : public EMSA
void update(const byte[], size_t);
- SecureVector<byte> raw_data();
+ secure_vector<byte> raw_data();
- SecureVector<byte> encoding_of(const MemoryRegion<byte>&, size_t,
+ secure_vector<byte> encoding_of(const secure_vector<byte>&, size_t,
RandomNumberGenerator& rng);
- bool verify(const MemoryRegion<byte>&, const MemoryRegion<byte>&,
+ bool verify(const secure_vector<byte>&, const secure_vector<byte>&,
size_t);
private:
HashFunction* hash;
- SecureVector<byte> hash_id;
+ std::vector<byte> hash_id;
};
/**
@@ -51,16 +51,16 @@ class BOTAN_DLL EMSA3_Raw : public EMSA
public:
void update(const byte[], size_t);
- SecureVector<byte> raw_data();
+ secure_vector<byte> raw_data();
- SecureVector<byte> encoding_of(const MemoryRegion<byte>&, size_t,
+ secure_vector<byte> encoding_of(const secure_vector<byte>&, size_t,
RandomNumberGenerator& rng);
- bool verify(const MemoryRegion<byte>&, const MemoryRegion<byte>&,
+ bool verify(const secure_vector<byte>&, const secure_vector<byte>&,
size_t);
private:
- SecureVector<byte> message;
+ secure_vector<byte> message;
};
}
diff --git a/src/pk_pad/emsa4/emsa4.cpp b/src/pk_pad/emsa4/emsa4.cpp
index ef88e1953..c8b8cbc6a 100644
--- a/src/pk_pad/emsa4/emsa4.cpp
+++ b/src/pk_pad/emsa4/emsa4.cpp
@@ -22,7 +22,7 @@ void EMSA4::update(const byte input[], size_t length)
/*
* Return the raw (unencoded) data
*/
-SecureVector<byte> EMSA4::raw_data()
+secure_vector<byte> EMSA4::raw_data()
{
return hash->final();
}
@@ -30,7 +30,7 @@ SecureVector<byte> EMSA4::raw_data()
/*
* EMSA4 Encode Operation
*/
-SecureVector<byte> EMSA4::encoding_of(const MemoryRegion<byte>& msg,
+secure_vector<byte> EMSA4::encoding_of(const secure_vector<byte>& msg,
size_t output_bits,
RandomNumberGenerator& rng)
{
@@ -43,21 +43,21 @@ SecureVector<byte> EMSA4::encoding_of(const MemoryRegion<byte>& msg,
const size_t output_length = (output_bits + 7) / 8;
- SecureVector<byte> salt = rng.random_vec(SALT_SIZE);
+ secure_vector<byte> salt = rng.random_vec(SALT_SIZE);
for(size_t j = 0; j != 8; ++j)
hash->update(0);
hash->update(msg);
- hash->update(salt, SALT_SIZE);
- SecureVector<byte> H = hash->final();
+ hash->update(salt);
+ secure_vector<byte> H = hash->final();
- SecureVector<byte> EM(output_length);
+ secure_vector<byte> EM(output_length);
EM[output_length - HASH_SIZE - SALT_SIZE - 2] = 0x01;
- EM.copy(output_length - 1 - HASH_SIZE - SALT_SIZE, salt, SALT_SIZE);
- mgf->mask(H, HASH_SIZE, EM, output_length - HASH_SIZE - 1);
+ buffer_insert(EM, output_length - 1 - HASH_SIZE - SALT_SIZE, salt);
+ mgf->mask(&H[0], HASH_SIZE, &EM[0], output_length - HASH_SIZE - 1);
EM[0] &= 0xFF >> (8 * ((output_bits + 7) / 8) - output_bits);
- EM.copy(output_length - 1 - HASH_SIZE, H, HASH_SIZE);
+ buffer_insert(EM, output_length - 1 - HASH_SIZE, H);
EM[output_length-1] = 0xBC;
return EM;
@@ -66,26 +66,29 @@ SecureVector<byte> EMSA4::encoding_of(const MemoryRegion<byte>& msg,
/*
* EMSA4 Decode/Verify Operation
*/
-bool EMSA4::verify(const MemoryRegion<byte>& const_coded,
- const MemoryRegion<byte>& raw, size_t key_bits)
+bool EMSA4::verify(const secure_vector<byte>& const_coded,
+ const secure_vector<byte>& raw, size_t key_bits)
{
const size_t HASH_SIZE = hash->output_length();
const size_t KEY_BYTES = (key_bits + 7) / 8;
if(key_bits < 8*HASH_SIZE + 9)
return false;
+
if(raw.size() != HASH_SIZE)
return false;
- if(const_coded.size() > KEY_BYTES)
+
+ if(const_coded.size() > KEY_BYTES || const_coded.size() <= 1)
return false;
+
if(const_coded[const_coded.size()-1] != 0xBC)
return false;
- SecureVector<byte> coded = const_coded;
+ secure_vector<byte> coded = const_coded;
if(coded.size() < KEY_BYTES)
{
- SecureVector<byte> temp(KEY_BYTES);
- temp.copy(KEY_BYTES - coded.size(), coded, coded.size());
+ secure_vector<byte> temp(KEY_BYTES);
+ buffer_insert(temp, KEY_BYTES - coded.size(), coded);
coded = temp;
}
@@ -93,14 +96,17 @@ bool EMSA4::verify(const MemoryRegion<byte>& const_coded,
if(TOP_BITS > 8 - high_bit(coded[0]))
return false;
- SecureVector<byte> DB(&coded[0], coded.size() - HASH_SIZE - 1);
- SecureVector<byte> H(&coded[coded.size() - HASH_SIZE - 1], HASH_SIZE);
+ byte* DB = &coded[0];
+ const size_t DB_size = coded.size() - HASH_SIZE - 1;
- mgf->mask(H, H.size(), DB, coded.size() - H.size() - 1);
+ const byte* H = &coded[DB_size];
+ const size_t H_size = HASH_SIZE;
+
+ mgf->mask(&H[0], H_size, &DB[0], DB_size);
DB[0] &= 0xFF >> TOP_BITS;
size_t salt_offset = 0;
- for(size_t j = 0; j != DB.size(); ++j)
+ for(size_t j = 0; j != DB_size; ++j)
{
if(DB[j] == 0x01)
{ salt_offset = j + 1; break; }
@@ -110,15 +116,13 @@ bool EMSA4::verify(const MemoryRegion<byte>& const_coded,
if(salt_offset == 0)
return false;
- SecureVector<byte> salt(&DB[salt_offset], DB.size() - salt_offset);
-
for(size_t j = 0; j != 8; ++j)
hash->update(0);
hash->update(raw);
- hash->update(salt);
- SecureVector<byte> H2 = hash->final();
+ hash->update(&DB[salt_offset], DB_size - salt_offset);
+ secure_vector<byte> H2 = hash->final();
- return (H == H2);
+ return same_mem(&H[0], &H2[0], HASH_SIZE);
}
/*
diff --git a/src/pk_pad/emsa4/emsa4.h b/src/pk_pad/emsa4/emsa4.h
index bd8b32ca1..44bf5a429 100644
--- a/src/pk_pad/emsa4/emsa4.h
+++ b/src/pk_pad/emsa4/emsa4.h
@@ -34,11 +34,11 @@ class BOTAN_DLL EMSA4 : public EMSA
~EMSA4() { delete hash; delete mgf; }
private:
void update(const byte[], size_t);
- SecureVector<byte> raw_data();
+ secure_vector<byte> raw_data();
- SecureVector<byte> encoding_of(const MemoryRegion<byte>&, size_t,
+ secure_vector<byte> encoding_of(const secure_vector<byte>&, size_t,
RandomNumberGenerator& rng);
- bool verify(const MemoryRegion<byte>&, const MemoryRegion<byte>&,
+ bool verify(const secure_vector<byte>&, const secure_vector<byte>&,
size_t);
size_t SALT_SIZE;
diff --git a/src/pk_pad/emsa_raw/emsa_raw.cpp b/src/pk_pad/emsa_raw/emsa_raw.cpp
index d0f3918dd..cb0f99e9c 100644
--- a/src/pk_pad/emsa_raw/emsa_raw.cpp
+++ b/src/pk_pad/emsa_raw/emsa_raw.cpp
@@ -20,9 +20,9 @@ void EMSA_Raw::update(const byte input[], size_t length)
/*
* Return the raw (unencoded) data
*/
-SecureVector<byte> EMSA_Raw::raw_data()
+secure_vector<byte> EMSA_Raw::raw_data()
{
- SecureVector<byte> output;
+ secure_vector<byte> output;
std::swap(message, output);
return output;
}
@@ -30,7 +30,7 @@ SecureVector<byte> EMSA_Raw::raw_data()
/*
* EMSA-Raw Encode Operation
*/
-SecureVector<byte> EMSA_Raw::encoding_of(const MemoryRegion<byte>& msg,
+secure_vector<byte> EMSA_Raw::encoding_of(const secure_vector<byte>& msg,
size_t,
RandomNumberGenerator&)
{
@@ -40,8 +40,8 @@ SecureVector<byte> EMSA_Raw::encoding_of(const MemoryRegion<byte>& msg,
/*
* EMSA-Raw Verify Operation
*/
-bool EMSA_Raw::verify(const MemoryRegion<byte>& coded,
- const MemoryRegion<byte>& raw,
+bool EMSA_Raw::verify(const secure_vector<byte>& coded,
+ const secure_vector<byte>& raw,
size_t)
{
if(coded.size() == raw.size())
diff --git a/src/pk_pad/emsa_raw/emsa_raw.h b/src/pk_pad/emsa_raw/emsa_raw.h
index 2ccd076f2..8ab763575 100644
--- a/src/pk_pad/emsa_raw/emsa_raw.h
+++ b/src/pk_pad/emsa_raw/emsa_raw.h
@@ -20,14 +20,14 @@ class BOTAN_DLL EMSA_Raw : public EMSA
{
private:
void update(const byte[], size_t);
- SecureVector<byte> raw_data();
+ secure_vector<byte> raw_data();
- SecureVector<byte> encoding_of(const MemoryRegion<byte>&, size_t,
+ secure_vector<byte> encoding_of(const secure_vector<byte>&, size_t,
RandomNumberGenerator&);
- bool verify(const MemoryRegion<byte>&, const MemoryRegion<byte>&,
+ bool verify(const secure_vector<byte>&, const secure_vector<byte>&,
size_t);
- SecureVector<byte> message;
+ secure_vector<byte> message;
};
}
diff --git a/src/pk_pad/hash_id/hash_id.cpp b/src/pk_pad/hash_id/hash_id.cpp
index 74653cb83..a60e53352 100644
--- a/src/pk_pad/hash_id/hash_id.cpp
+++ b/src/pk_pad/hash_id/hash_id.cpp
@@ -57,32 +57,51 @@ const byte TIGER_PKCS_ID[] = {
/*
* HashID as specified by PKCS
*/
-MemoryVector<byte> pkcs_hash_id(const std::string& name)
+std::vector<byte> pkcs_hash_id(const std::string& name)
{
// Special case for SSL/TLS RSA signatures
if(name == "Parallel(MD5,SHA-160)")
- return MemoryVector<byte>();
+ return std::vector<byte>();
if(name == "MD2")
- return MemoryVector<byte>(MD2_PKCS_ID, sizeof(MD2_PKCS_ID));
+ return std::vector<byte>(MD2_PKCS_ID,
+ MD2_PKCS_ID + sizeof(MD2_PKCS_ID));
+
if(name == "MD5")
- return MemoryVector<byte>(MD5_PKCS_ID, sizeof(MD5_PKCS_ID));
+ return std::vector<byte>(MD5_PKCS_ID,
+ MD5_PKCS_ID + sizeof(MD5_PKCS_ID));
+
if(name == "RIPEMD-128")
- return MemoryVector<byte>(RIPEMD_128_PKCS_ID, sizeof(RIPEMD_128_PKCS_ID));
+ return std::vector<byte>(RIPEMD_128_PKCS_ID,
+ RIPEMD_128_PKCS_ID + sizeof(RIPEMD_128_PKCS_ID));
+
if(name == "RIPEMD-160")
- return MemoryVector<byte>(RIPEMD_160_PKCS_ID, sizeof(RIPEMD_160_PKCS_ID));
+ return std::vector<byte>(RIPEMD_160_PKCS_ID,
+ RIPEMD_160_PKCS_ID + sizeof(RIPEMD_160_PKCS_ID));
+
if(name == "SHA-160")
- return MemoryVector<byte>(SHA_160_PKCS_ID, sizeof(SHA_160_PKCS_ID));
+ return std::vector<byte>(SHA_160_PKCS_ID,
+ SHA_160_PKCS_ID + sizeof(SHA_160_PKCS_ID));
+
if(name == "SHA-224")
- return MemoryVector<byte>(SHA_224_PKCS_ID, sizeof(SHA_224_PKCS_ID));
+ return std::vector<byte>(SHA_224_PKCS_ID,
+ SHA_224_PKCS_ID + sizeof(SHA_224_PKCS_ID));
+
if(name == "SHA-256")
- return MemoryVector<byte>(SHA_256_PKCS_ID, sizeof(SHA_256_PKCS_ID));
+ return std::vector<byte>(SHA_256_PKCS_ID,
+ SHA_256_PKCS_ID + sizeof(SHA_256_PKCS_ID));
+
if(name == "SHA-384")
- return MemoryVector<byte>(SHA_384_PKCS_ID, sizeof(SHA_384_PKCS_ID));
+ return std::vector<byte>(SHA_384_PKCS_ID,
+ SHA_384_PKCS_ID + sizeof(SHA_384_PKCS_ID));
+
if(name == "SHA-512")
- return MemoryVector<byte>(SHA_512_PKCS_ID, sizeof(SHA_512_PKCS_ID));
+ return std::vector<byte>(SHA_512_PKCS_ID,
+ SHA_512_PKCS_ID + sizeof(SHA_512_PKCS_ID));
+
if(name == "Tiger(24,3)")
- return MemoryVector<byte>(TIGER_PKCS_ID, sizeof(TIGER_PKCS_ID));
+ return std::vector<byte>(TIGER_PKCS_ID,
+ TIGER_PKCS_ID + sizeof(TIGER_PKCS_ID));
throw Invalid_Argument("No PKCS #1 identifier for " + name);
}
diff --git a/src/pk_pad/hash_id/hash_id.h b/src/pk_pad/hash_id/hash_id.h
index 909cc6b19..070e7ddb9 100644
--- a/src/pk_pad/hash_id/hash_id.h
+++ b/src/pk_pad/hash_id/hash_id.h
@@ -20,7 +20,7 @@ namespace Botan {
* @return byte sequence identifying the hash
* @throw Invalid_Argument if the hash has no known PKCS #1 hash id
*/
-BOTAN_DLL MemoryVector<byte> pkcs_hash_id(const std::string& hash_name);
+BOTAN_DLL std::vector<byte> pkcs_hash_id(const std::string& hash_name);
/**
* Return the IEEE 1363 hash identifier