aboutsummaryrefslogtreecommitdiffstats
path: root/src/lib/modes/aead/ocb
diff options
context:
space:
mode:
authorJack Lloyd <[email protected]>2016-12-11 15:28:38 -0500
committerJack Lloyd <[email protected]>2016-12-18 16:48:24 -0500
commitf3cb3edb512bdcab498d825886c3366c341b3f78 (patch)
tree645c73ec295a5a34f25d99903b6d9fa9751e86d3 /src/lib/modes/aead/ocb
parentc1dd21253c1f3188ff45d3ad47698efd08235ae8 (diff)
Convert to using standard uintN_t integer types
Renames a couple of functions for somewhat better name consistency, eg make_u32bit becomes make_uint32. The old typedefs remain for now since probably lots of application code uses them.
Diffstat (limited to 'src/lib/modes/aead/ocb')
-rw-r--r--src/lib/modes/aead/ocb/ocb.cpp74
-rw-r--r--src/lib/modes/aead/ocb/ocb.h26
2 files changed, 50 insertions, 50 deletions
diff --git a/src/lib/modes/aead/ocb/ocb.cpp b/src/lib/modes/aead/ocb/ocb.cpp
index c530dda5d..84787ad38 100644
--- a/src/lib/modes/aead/ocb/ocb.cpp
+++ b/src/lib/modes/aead/ocb/ocb.cpp
@@ -24,13 +24,13 @@ class L_computer
m_L.push_back(poly_double(dollar()));
}
- const secure_vector<byte>& star() const { return m_L_star; }
+ const secure_vector<uint8_t>& star() const { return m_L_star; }
- const secure_vector<byte>& dollar() const { return m_L_dollar; }
+ const secure_vector<uint8_t>& dollar() const { return m_L_dollar; }
- const secure_vector<byte>& operator()(size_t i) const { return get(i); }
+ const secure_vector<uint8_t>& operator()(size_t i) const { return get(i); }
- const secure_vector<byte>& compute_offsets(secure_vector<byte>& offset,
+ const secure_vector<uint8_t>& compute_offsets(secure_vector<uint8_t>& offset,
size_t block_index,
size_t blocks) const
{
@@ -46,7 +46,7 @@ class L_computer
}
private:
- const secure_vector<byte>& get(size_t i) const
+ const secure_vector<uint8_t>& get(size_t i) const
{
while(m_L.size() <= i)
m_L.push_back(poly_double(m_L.back()));
@@ -54,14 +54,14 @@ class L_computer
return m_L.at(i);
}
- secure_vector<byte> poly_double(const secure_vector<byte>& in) const
+ secure_vector<uint8_t> poly_double(const secure_vector<uint8_t>& in) const
{
return CMAC::poly_double(in);
}
- secure_vector<byte> m_L_dollar, m_L_star;
- mutable std::vector<secure_vector<byte>> m_L;
- mutable secure_vector<byte> m_offset_buf;
+ secure_vector<uint8_t> m_L_dollar, m_L_star;
+ mutable std::vector<secure_vector<uint8_t>> m_L;
+ mutable secure_vector<uint8_t> m_offset_buf;
};
namespace {
@@ -69,14 +69,14 @@ namespace {
/*
* OCB's HASH
*/
-secure_vector<byte> ocb_hash(const L_computer& L,
+secure_vector<uint8_t> ocb_hash(const L_computer& L,
const BlockCipher& cipher,
- const byte ad[], size_t ad_len)
+ const uint8_t ad[], size_t ad_len)
{
- secure_vector<byte> sum(16);
- secure_vector<byte> offset(16);
+ secure_vector<uint8_t> sum(16);
+ secure_vector<uint8_t> offset(16);
- secure_vector<byte> buf(16);
+ secure_vector<uint8_t> buf(16);
const size_t ad_blocks = (ad_len / 16);
const size_t ad_remainder = (ad_len % 16);
@@ -165,30 +165,30 @@ Key_Length_Specification OCB_Mode::key_spec() const
return m_cipher->key_spec();
}
-void OCB_Mode::key_schedule(const byte key[], size_t length)
+void OCB_Mode::key_schedule(const uint8_t key[], size_t length)
{
m_cipher->set_key(key, length);
m_L.reset(new L_computer(*m_cipher));
}
-void OCB_Mode::set_associated_data(const byte ad[], size_t ad_len)
+void OCB_Mode::set_associated_data(const uint8_t ad[], size_t ad_len)
{
BOTAN_ASSERT(m_L, "A key was set");
m_ad_hash = ocb_hash(*m_L, *m_cipher, ad, ad_len);
}
-secure_vector<byte>
-OCB_Mode::update_nonce(const byte nonce[], size_t nonce_len)
+secure_vector<uint8_t>
+OCB_Mode::update_nonce(const uint8_t nonce[], size_t nonce_len)
{
BOTAN_ASSERT(nonce_len < 16, "OCB nonce is less than cipher block size");
- secure_vector<byte> nonce_buf(16);
+ secure_vector<uint8_t> nonce_buf(16);
copy_mem(&nonce_buf[16 - nonce_len], nonce, nonce_len);
nonce_buf[0] = ((tag_size() * 8) % 128) << 1;
nonce_buf[16 - nonce_len - 1] = 1;
- const byte bottom = nonce_buf[16-1] & 0x3F;
+ const uint8_t bottom = nonce_buf[16-1] & 0x3F;
nonce_buf[16-1] &= 0xC0;
const bool need_new_stretch = (m_last_nonce != nonce_buf);
@@ -210,7 +210,7 @@ OCB_Mode::update_nonce(const byte nonce[], size_t nonce_len)
const size_t shift_bytes = bottom / 8;
const size_t shift_bits = bottom % 8;
- secure_vector<byte> offset(16);
+ secure_vector<uint8_t> offset(16);
for(size_t i = 0; i != 16; ++i)
{
offset[i] = (m_stretch[i+shift_bytes] << shift_bits);
@@ -220,7 +220,7 @@ OCB_Mode::update_nonce(const byte nonce[], size_t nonce_len)
return offset;
}
-void OCB_Mode::start_msg(const byte nonce[], size_t nonce_len)
+void OCB_Mode::start_msg(const uint8_t nonce[], size_t nonce_len)
{
if(!valid_nonce_length(nonce_len))
throw Invalid_IV_Length(name(), nonce_len);
@@ -232,7 +232,7 @@ void OCB_Mode::start_msg(const byte nonce[], size_t nonce_len)
m_block_index = 0;
}
-void OCB_Encryption::encrypt(byte buffer[], size_t blocks)
+void OCB_Encryption::encrypt(uint8_t buffer[], size_t blocks)
{
const size_t par_blocks = m_checksum.size() / 16;
@@ -262,11 +262,11 @@ size_t OCB_Encryption::process(uint8_t buf[], size_t sz)
return sz;
}
-void OCB_Encryption::finish(secure_vector<byte>& buffer, size_t offset)
+void OCB_Encryption::finish(secure_vector<uint8_t>& buffer, size_t offset)
{
BOTAN_ASSERT(buffer.size() >= offset, "Offset is sane");
const size_t sz = buffer.size() - offset;
- byte* buf = buffer.data() + offset;
+ uint8_t* buf = buffer.data() + offset;
if(sz)
{
@@ -278,27 +278,27 @@ void OCB_Encryption::finish(secure_vector<byte>& buffer, size_t offset)
if(remainder_bytes)
{
BOTAN_ASSERT(remainder_bytes < 16, "Only a partial block left");
- byte* remainder = &buf[sz - remainder_bytes];
+ uint8_t* remainder = &buf[sz - remainder_bytes];
xor_buf(m_checksum.data(), remainder, remainder_bytes);
m_checksum[remainder_bytes] ^= 0x80;
m_offset ^= m_L->star(); // Offset_*
- secure_vector<byte> zeros(16);
+ secure_vector<uint8_t> zeros(16);
m_cipher->encrypt(m_offset, zeros);
xor_buf(remainder, zeros.data(), remainder_bytes);
}
}
- secure_vector<byte> checksum(16);
+ secure_vector<uint8_t> checksum(16);
// fold checksum
for(size_t i = 0; i != m_checksum.size(); ++i)
checksum[i % checksum.size()] ^= m_checksum[i];
// now compute the tag
- secure_vector<byte> mac = m_offset;
+ secure_vector<uint8_t> mac = m_offset;
mac ^= checksum;
mac ^= m_L->dollar();
@@ -313,7 +313,7 @@ void OCB_Encryption::finish(secure_vector<byte>& buffer, size_t offset)
m_block_index = 0;
}
-void OCB_Decryption::decrypt(byte buffer[], size_t blocks)
+void OCB_Decryption::decrypt(uint8_t buffer[], size_t blocks)
{
const size_t par_bytes = m_cipher->parallel_bytes();
@@ -347,11 +347,11 @@ size_t OCB_Decryption::process(uint8_t buf[], size_t sz)
return sz;
}
-void OCB_Decryption::finish(secure_vector<byte>& buffer, size_t offset)
+void OCB_Decryption::finish(secure_vector<uint8_t>& buffer, size_t offset)
{
BOTAN_ASSERT(buffer.size() >= offset, "Offset is sane");
const size_t sz = buffer.size() - offset;
- byte* buf = buffer.data() + offset;
+ uint8_t* buf = buffer.data() + offset;
BOTAN_ASSERT(sz >= tag_size(), "We have the tag");
@@ -368,11 +368,11 @@ void OCB_Decryption::finish(secure_vector<byte>& buffer, size_t offset)
{
BOTAN_ASSERT(final_bytes < 16, "Only a partial block left");
- byte* remainder = &buf[remaining - final_bytes];
+ uint8_t* remainder = &buf[remaining - final_bytes];
m_offset ^= m_L->star(); // Offset_*
- secure_vector<byte> pad(16);
+ secure_vector<uint8_t> pad(16);
m_cipher->encrypt(m_offset, pad); // P_*
xor_buf(remainder, pad.data(), final_bytes);
@@ -382,14 +382,14 @@ void OCB_Decryption::finish(secure_vector<byte>& buffer, size_t offset)
}
}
- secure_vector<byte> checksum(16);
+ secure_vector<uint8_t> checksum(16);
// fold checksum
for(size_t i = 0; i != m_checksum.size(); ++i)
checksum[i % checksum.size()] ^= m_checksum[i];
// compute the mac
- secure_vector<byte> mac = m_offset;
+ secure_vector<uint8_t> mac = m_offset;
mac ^= checksum;
mac ^= m_L->dollar();
@@ -403,7 +403,7 @@ void OCB_Decryption::finish(secure_vector<byte>& buffer, size_t offset)
m_block_index = 0;
// compare mac
- const byte* included_tag = &buf[remaining];
+ const uint8_t* included_tag = &buf[remaining];
if(!same_mem(mac.data(), included_tag, tag_size()))
throw Integrity_Failure("OCB tag check failed");
diff --git a/src/lib/modes/aead/ocb/ocb.h b/src/lib/modes/aead/ocb/ocb.h
index dfdb8c18c..cac87ddb6 100644
--- a/src/lib/modes/aead/ocb/ocb.h
+++ b/src/lib/modes/aead/ocb/ocb.h
@@ -28,7 +28,7 @@ class L_computer;
class BOTAN_DLL OCB_Mode : public AEAD_Mode
{
public:
- void set_associated_data(const byte ad[], size_t ad_len) override;
+ void set_associated_data(const uint8_t ad[], size_t ad_len) override;
std::string name() const override;
@@ -58,19 +58,19 @@ class BOTAN_DLL OCB_Mode : public AEAD_Mode
size_t m_block_index = 0;
- secure_vector<byte> m_checksum;
- secure_vector<byte> m_offset;
- secure_vector<byte> m_ad_hash;
+ secure_vector<uint8_t> m_checksum;
+ secure_vector<uint8_t> m_offset;
+ secure_vector<uint8_t> m_ad_hash;
private:
- void start_msg(const byte nonce[], size_t nonce_len) override;
+ void start_msg(const uint8_t nonce[], size_t nonce_len) override;
- void key_schedule(const byte key[], size_t length) override;
+ void key_schedule(const uint8_t key[], size_t length) override;
- secure_vector<byte> update_nonce(const byte nonce[], size_t nonce_len);
+ secure_vector<uint8_t> update_nonce(const uint8_t nonce[], size_t nonce_len);
size_t m_tag_size = 0;
- secure_vector<byte> m_last_nonce;
- secure_vector<byte> m_stretch;
+ secure_vector<uint8_t> m_last_nonce;
+ secure_vector<uint8_t> m_stretch;
};
class BOTAN_DLL OCB_Encryption final : public OCB_Mode
@@ -90,9 +90,9 @@ class BOTAN_DLL OCB_Encryption final : public OCB_Mode
size_t process(uint8_t buf[], size_t size) override;
- void finish(secure_vector<byte>& final_block, size_t offset = 0) override;
+ void finish(secure_vector<uint8_t>& final_block, size_t offset = 0) override;
private:
- void encrypt(byte input[], size_t blocks);
+ void encrypt(uint8_t input[], size_t blocks);
};
class BOTAN_DLL OCB_Decryption final : public OCB_Mode
@@ -115,9 +115,9 @@ class BOTAN_DLL OCB_Decryption final : public OCB_Mode
size_t process(uint8_t buf[], size_t size) override;
- void finish(secure_vector<byte>& final_block, size_t offset = 0) override;
+ void finish(secure_vector<uint8_t>& final_block, size_t offset = 0) override;
private:
- void decrypt(byte input[], size_t blocks);
+ void decrypt(uint8_t input[], size_t blocks);
};
}