aboutsummaryrefslogtreecommitdiffstats
path: root/src/lib/modes/aead
diff options
context:
space:
mode:
Diffstat (limited to 'src/lib/modes/aead')
-rw-r--r--src/lib/modes/aead/ccm/ccm.cpp10
-rw-r--r--src/lib/modes/aead/gcm/gcm.cpp8
-rw-r--r--src/lib/modes/aead/ocb/ocb.cpp10
3 files changed, 15 insertions, 13 deletions
diff --git a/src/lib/modes/aead/ccm/ccm.cpp b/src/lib/modes/aead/ccm/ccm.cpp
index 6149718f0..410bd6910 100644
--- a/src/lib/modes/aead/ccm/ccm.cpp
+++ b/src/lib/modes/aead/ccm/ccm.cpp
@@ -88,7 +88,7 @@ void CCM_Mode::set_associated_data(const uint8_t ad[], size_t length)
if(length)
{
// FIXME: support larger AD using length encoding rules
- BOTAN_ASSERT(length < (0xFFFF - 0xFF), "Supported CCM AD length");
+ BOTAN_ARG_CHECK(length < (0xFFFF - 0xFF), "Supported CCM AD length");
m_ad_buf.push_back(get_byte(0, static_cast<uint16_t>(length)));
m_ad_buf.push_back(get_byte(1, static_cast<uint16_t>(length)));
@@ -160,7 +160,7 @@ secure_vector<uint8_t> CCM_Mode::format_c0()
void CCM_Encryption::finish(secure_vector<uint8_t>& buffer, size_t offset)
{
- BOTAN_ASSERT(buffer.size() >= offset, "Offset is sane");
+ BOTAN_ARG_CHECK(buffer.size() >= offset, "Offset is sane");
buffer.insert(buffer.begin() + offset, msg_buf().begin(), msg_buf().end());
@@ -168,7 +168,7 @@ void CCM_Encryption::finish(secure_vector<uint8_t>& buffer, size_t offset)
uint8_t* buf = buffer.data() + offset;
const secure_vector<uint8_t>& ad = ad_buf();
- BOTAN_ASSERT(ad.size() % CCM_BS == 0, "AD is block size multiple");
+ BOTAN_ARG_CHECK(ad.size() % CCM_BS == 0, "AD is block size multiple");
const BlockCipher& E = cipher();
@@ -211,7 +211,7 @@ void CCM_Encryption::finish(secure_vector<uint8_t>& buffer, size_t offset)
void CCM_Decryption::finish(secure_vector<uint8_t>& buffer, size_t offset)
{
- BOTAN_ASSERT(buffer.size() >= offset, "Offset is sane");
+ BOTAN_ARG_CHECK(buffer.size() >= offset, "Offset is sane");
buffer.insert(buffer.begin() + offset, msg_buf().begin(), msg_buf().end());
@@ -221,7 +221,7 @@ void CCM_Decryption::finish(secure_vector<uint8_t>& buffer, size_t offset)
BOTAN_ASSERT(sz >= tag_size(), "We have the tag");
const secure_vector<uint8_t>& ad = ad_buf();
- BOTAN_ASSERT(ad.size() % CCM_BS == 0, "AD is block size multiple");
+ BOTAN_ARG_CHECK(ad.size() % CCM_BS == 0, "AD is block size multiple");
const BlockCipher& E = cipher();
diff --git a/src/lib/modes/aead/gcm/gcm.cpp b/src/lib/modes/aead/gcm/gcm.cpp
index b0240eb7f..2bdae3a6f 100644
--- a/src/lib/modes/aead/gcm/gcm.cpp
+++ b/src/lib/modes/aead/gcm/gcm.cpp
@@ -110,7 +110,7 @@ void GCM_Mode::start_msg(const uint8_t nonce[], size_t nonce_len)
size_t GCM_Encryption::process(uint8_t buf[], size_t sz)
{
- BOTAN_ARG_CHECK(sz % update_granularity() == 0);
+ BOTAN_ARG_CHECK(sz % update_granularity() == 0, "Invalid buffer size");
m_ctr->cipher(buf, buf, sz);
m_ghash->update(buf, sz);
return sz;
@@ -118,7 +118,7 @@ size_t GCM_Encryption::process(uint8_t buf[], size_t sz)
void GCM_Encryption::finish(secure_vector<uint8_t>& buffer, size_t offset)
{
- BOTAN_ARG_CHECK(offset <= buffer.size());
+ BOTAN_ARG_CHECK(offset <= buffer.size(), "Invalid offset");
const size_t sz = buffer.size() - offset;
uint8_t* buf = buffer.data() + offset;
@@ -130,7 +130,7 @@ void GCM_Encryption::finish(secure_vector<uint8_t>& buffer, size_t offset)
size_t GCM_Decryption::process(uint8_t buf[], size_t sz)
{
- BOTAN_ARG_CHECK(sz % update_granularity() == 0);
+ BOTAN_ARG_CHECK(sz % update_granularity() == 0, "Invalid buffer size");
m_ghash->update(buf, sz);
m_ctr->cipher(buf, buf, sz);
return sz;
@@ -138,7 +138,7 @@ size_t GCM_Decryption::process(uint8_t buf[], size_t sz)
void GCM_Decryption::finish(secure_vector<uint8_t>& buffer, size_t offset)
{
- BOTAN_ARG_CHECK(offset <= buffer.size());
+ BOTAN_ARG_CHECK(offset <= buffer.size(), "Invalid offset");
const size_t sz = buffer.size() - offset;
uint8_t* buf = buffer.data() + offset;
diff --git a/src/lib/modes/aead/ocb/ocb.cpp b/src/lib/modes/aead/ocb/ocb.cpp
index 23af75e8f..317b417b3 100644
--- a/src/lib/modes/aead/ocb/ocb.cpp
+++ b/src/lib/modes/aead/ocb/ocb.cpp
@@ -171,11 +171,13 @@ OCB_Mode::OCB_Mode(BlockCipher* cipher, size_t tag_size) :
* sizes but only 128, 192, 256 and 512 bit are currently supported
* by this implementation.
*/
- if(BS != 16 && BS != 24 && BS != 32 && BS != 64)
- throw Invalid_Argument("OCB does not support cipher " + m_cipher->name());
+ BOTAN_ARG_CHECK(BS == 16 || BS == 24 || BS == 32 || BS == 64,
+ "Invalid block size for OCB");
- if(m_tag_size % 4 != 0 || m_tag_size < 8 || m_tag_size > BS || m_tag_size > 32)
- throw Invalid_Argument("Invalid OCB tag length");
+ BOTAN_ARG_CHECK(m_tag_size % 4 == 0 &&
+ m_tag_size >= 8 && m_tag_size <= BS &&
+ m_tag_size <= 32,
+ "Invalid OCB tag length");
}
OCB_Mode::~OCB_Mode() { /* for unique_ptr destructor */ }