aboutsummaryrefslogtreecommitdiffstats
path: root/src/lib
diff options
context:
space:
mode:
authorJack Lloyd <[email protected]>2017-11-18 17:03:06 -0500
committerJack Lloyd <[email protected]>2017-11-18 17:03:06 -0500
commitf926f14095873df0a59aea5c398b7519a196b316 (patch)
tree0b33621493000bb52a74053e66ec17e4464eee82 /src/lib
parentc8f026ef5958f2e4732c406f45b9d070e98be2c0 (diff)
Add a function for checking if poly_double_n supports a particular size
Diffstat (limited to 'src/lib')
-rw-r--r--src/lib/mac/cmac/cmac.cpp3
-rw-r--r--src/lib/modes/xts/xts.cpp5
-rw-r--r--src/lib/utils/poly_dbl/poly_dbl.h8
3 files changed, 10 insertions, 6 deletions
diff --git a/src/lib/mac/cmac/cmac.cpp b/src/lib/mac/cmac/cmac.cpp
index 18f7c151c..bd2a53a72 100644
--- a/src/lib/mac/cmac/cmac.cpp
+++ b/src/lib/mac/cmac/cmac.cpp
@@ -121,8 +121,7 @@ CMAC::CMAC(BlockCipher* cipher) :
m_cipher(cipher),
m_block_size(m_cipher->block_size())
{
- if(m_block_size != 8 && m_block_size != 16 &&
- m_block_size != 32 && m_block_size != 64)
+ if(poly_double_supported_size(m_block_size) == false)
{
throw Invalid_Argument("CMAC cannot use the " +
std::to_string(m_block_size * 8) +
diff --git a/src/lib/modes/xts/xts.cpp b/src/lib/modes/xts/xts.cpp
index 496b71c5f..0b10faa92 100644
--- a/src/lib/modes/xts/xts.cpp
+++ b/src/lib/modes/xts/xts.cpp
@@ -13,10 +13,7 @@ namespace Botan {
XTS_Mode::XTS_Mode(BlockCipher* cipher) : m_cipher(cipher)
{
- if(m_cipher->block_size() != 8 &&
- m_cipher->block_size() != 16 &&
- m_cipher->block_size() != 32 &&
- m_cipher->block_size() != 64)
+ if(poly_double_supported_size(m_cipher->block_size()) == false)
{
throw Invalid_Argument("Cannot use " + cipher->name() + " with XTS");
}
diff --git a/src/lib/utils/poly_dbl/poly_dbl.h b/src/lib/utils/poly_dbl/poly_dbl.h
index 10c85c567..8f9c0d3aa 100644
--- a/src/lib/utils/poly_dbl/poly_dbl.h
+++ b/src/lib/utils/poly_dbl/poly_dbl.h
@@ -16,6 +16,14 @@ namespace Botan {
*/
void BOTAN_PUBLIC_API(2,3) poly_double_n(uint8_t out[], const uint8_t in[], size_t n);
+/**
+* Returns true iff poly_double_n is implemented for this size.
+*/
+inline bool poly_double_supported_size(size_t n)
+ {
+ return (n == 8 || n == 16 || n == 24 || n == 32 || n == 64);
+ }
+
inline void poly_double_n(uint8_t buf[], size_t n)
{
return poly_double_n(buf, buf, n);