aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorlloyd <[email protected]>2013-03-17 16:27:12 +0000
committerlloyd <[email protected]>2013-03-17 16:27:12 +0000
commitbab497b57eb67faf292313a27bcf95b0053a4d0f (patch)
treec41a2117d314993ff9358185cd58c87affe87088 /src
parent7d035f642ad7d9e4a80907d45332031ff5b795e3 (diff)
Add an interface to Keyed_Filter returning a Key_Length_Specification
so the full details of what keylength(s) the filter supports are now available.
Diffstat (limited to 'src')
-rw-r--r--src/filters/aead/eax/eax.cpp10
-rw-r--r--src/filters/aead/eax/eax.h2
-rw-r--r--src/filters/aead/gcm/gcm.cpp10
-rw-r--r--src/filters/aead/gcm/gcm.h2
-rw-r--r--src/filters/aead/ocb/ocb.cpp5
-rw-r--r--src/filters/aead/ocb/ocb.h2
-rw-r--r--src/filters/filters.h16
-rw-r--r--src/filters/key_filt.h10
-rw-r--r--src/filters/modes/cbc/cbc.h6
-rw-r--r--src/filters/modes/cfb/cfb.h6
-rw-r--r--src/filters/modes/cts/cts.h6
-rw-r--r--src/filters/modes/ecb/ecb.h6
-rw-r--r--src/filters/modes/xts/xts.cpp19
-rw-r--r--src/filters/modes/xts/xts.h6
14 files changed, 43 insertions, 63 deletions
diff --git a/src/filters/aead/eax/eax.cpp b/src/filters/aead/eax/eax.cpp
index 57f62833b..d4a982aaf 100644
--- a/src/filters/aead/eax/eax.cpp
+++ b/src/filters/aead/eax/eax.cpp
@@ -58,16 +58,6 @@ EAX_Mode::EAX_Mode(BlockCipher* cipher, size_t tag_size, bool decrypting) :
}
/*
-* Check if a keylength is valid for EAX
-*/
-bool EAX_Mode::valid_keylength(size_t n) const
- {
- if(!ctr->valid_keylength(n))
- return false;
- return true;
- }
-
-/*
* Set the EAX key
*/
void EAX_Mode::set_key(const SymmetricKey& key)
diff --git a/src/filters/aead/eax/eax.h b/src/filters/aead/eax/eax.h
index e219487cb..a85377524 100644
--- a/src/filters/aead/eax/eax.h
+++ b/src/filters/aead/eax/eax.h
@@ -32,7 +32,7 @@ class BOTAN_DLL EAX_Mode : public AEAD_Mode,
std::string name() const override;
- bool valid_keylength(size_t key_len) const override;
+ Key_Length_Specification key_spec() const override { return ctr->key_spec(); }
// EAX supports arbitrary IV lengths
bool valid_iv_length(size_t) const override { return true; }
diff --git a/src/filters/aead/gcm/gcm.cpp b/src/filters/aead/gcm/gcm.cpp
index 013757b59..32a763df7 100644
--- a/src/filters/aead/gcm/gcm.cpp
+++ b/src/filters/aead/gcm/gcm.cpp
@@ -107,16 +107,6 @@ GCM_Mode::GCM_Mode(BlockCipher* cipher, size_t tag_size, bool decrypting) :
throw Invalid_Argument(name() + ": Bad tag size " + std::to_string(m_tag_size));
}
-/*
-* Check if a keylength is valid for GCM
-*/
-bool GCM_Mode::valid_keylength(size_t n) const
- {
- if(!m_ctr->valid_keylength(n))
- return false;
- return true;
- }
-
void GCM_Mode::set_key(const SymmetricKey& key)
{
m_ctr->set_key(key);
diff --git a/src/filters/aead/gcm/gcm.h b/src/filters/aead/gcm/gcm.h
index fa13597ce..067b19298 100644
--- a/src/filters/aead/gcm/gcm.h
+++ b/src/filters/aead/gcm/gcm.h
@@ -32,7 +32,7 @@ class BOTAN_DLL GCM_Mode : public AEAD_Mode,
*/
void set_associated_data(const byte ad[], size_t ad_len) override;
- bool valid_keylength(size_t key_len) const override;
+ Key_Length_Specification key_spec() const override { return m_ctr->key_spec(); }
// GCM supports arbitrary IV lengths
bool valid_iv_length(size_t) const override { return true; }
diff --git a/src/filters/aead/ocb/ocb.cpp b/src/filters/aead/ocb/ocb.cpp
index ebf440d32..eb10b6e9f 100644
--- a/src/filters/aead/ocb/ocb.cpp
+++ b/src/filters/aead/ocb/ocb.cpp
@@ -180,11 +180,6 @@ OCB_Mode::OCB_Mode(BlockCipher* cipher, size_t tag_size, bool decrypting) :
OCB_Mode::~OCB_Mode() { /* for unique_ptr destructor */ }
-bool OCB_Mode::valid_keylength(size_t n) const
- {
- return m_cipher->valid_keylength(n);
- }
-
std::string OCB_Mode::name() const
{
return m_cipher->name() + "/OCB"; // include tag size
diff --git a/src/filters/aead/ocb/ocb.h b/src/filters/aead/ocb/ocb.h
index 5e3c5cf0a..f5209df12 100644
--- a/src/filters/aead/ocb/ocb.h
+++ b/src/filters/aead/ocb/ocb.h
@@ -37,7 +37,7 @@ class BOTAN_DLL OCB_Mode : public AEAD_Mode,
void set_associated_data(const byte ad[], size_t ad_len) override;
- bool valid_keylength(size_t n) const override;
+ Key_Length_Specification key_spec() const override { return m_cipher->key_spec(); }
std::string name() const override;
diff --git a/src/filters/filters.h b/src/filters/filters.h
index 08b505bc0..8fcc2d85d 100644
--- a/src/filters/filters.h
+++ b/src/filters/filters.h
@@ -58,13 +58,7 @@ class BOTAN_DLL StreamCipher_Filter : public Keyed_Filter
*/
void set_key(const SymmetricKey& key) { cipher->set_key(key); }
- /**
- * Check whether a key length is valid for this filter.
- * @param length the key length to be checked for validity
- * @return true if the key length is valid, false otherwise
- */
- bool valid_keylength(size_t length) const
- { return cipher->valid_keylength(length); }
+ Key_Length_Specification key_spec() const override { return cipher->key_spec(); }
/**
* Construct a stream cipher filter.
@@ -153,13 +147,7 @@ class BOTAN_DLL MAC_Filter : public Keyed_Filter
*/
void set_key(const SymmetricKey& key) { mac->set_key(key); }
- /**
- * Check whether a key length is valid for this filter.
- * @param length the key length to be checked for validity
- * @return true if the key length is valid, false otherwise
- */
- bool valid_keylength(size_t length) const
- { return mac->valid_keylength(length); }
+ Key_Length_Specification key_spec() const override { return mac->key_spec(); }
/**
* Construct a MAC filter. The MAC key will be left empty.
diff --git a/src/filters/key_filt.h b/src/filters/key_filt.h
index 3c79ebac9..6d69d6b83 100644
--- a/src/filters/key_filt.h
+++ b/src/filters/key_filt.h
@@ -38,7 +38,15 @@ class BOTAN_DLL Keyed_Filter : public Filter
* @param length the key length to be checked for validity
* @return true if the key length is valid, false otherwise
*/
- virtual bool valid_keylength(size_t length) const = 0;
+ bool valid_keylength(size_t length) const
+ {
+ return key_spec().valid_keylength(length);
+ }
+
+ /**
+ * @return object describing limits on key size
+ */
+ virtual Key_Length_Specification key_spec() const = 0;
/**
* Check whether an IV length is valid for this filter
diff --git a/src/filters/modes/cbc/cbc.h b/src/filters/modes/cbc/cbc.h
index 4fd0f7d66..51e217e70 100644
--- a/src/filters/modes/cbc/cbc.h
+++ b/src/filters/modes/cbc/cbc.h
@@ -28,8 +28,7 @@ class BOTAN_DLL CBC_Encryption : public Keyed_Filter,
void set_key(const SymmetricKey& key) { cipher->set_key(key); }
- bool valid_keylength(size_t key_len) const
- { return cipher->valid_keylength(key_len); }
+ Key_Length_Specification key_spec() const override { return cipher->key_spec(); }
bool valid_iv_length(size_t iv_len) const
{ return (iv_len == cipher->block_size()); }
@@ -68,8 +67,7 @@ class BOTAN_DLL CBC_Decryption : public Keyed_Filter,
void set_key(const SymmetricKey& key) { cipher->set_key(key); }
- bool valid_keylength(size_t key_len) const
- { return cipher->valid_keylength(key_len); }
+ Key_Length_Specification key_spec() const override { return cipher->key_spec(); }
bool valid_iv_length(size_t iv_len) const
{ return (iv_len == cipher->block_size()); }
diff --git a/src/filters/modes/cfb/cfb.h b/src/filters/modes/cfb/cfb.h
index 212ac76da..02154ebb9 100644
--- a/src/filters/modes/cfb/cfb.h
+++ b/src/filters/modes/cfb/cfb.h
@@ -25,8 +25,7 @@ class BOTAN_DLL CFB_Encryption : public Keyed_Filter
void set_key(const SymmetricKey& key) { cipher->set_key(key); }
- bool valid_keylength(size_t key_len) const
- { return cipher->valid_keylength(key_len); }
+ Key_Length_Specification key_spec() const override { return cipher->key_spec(); }
bool valid_iv_length(size_t iv_len) const
{ return (iv_len == cipher->block_size()); }
@@ -59,8 +58,7 @@ class BOTAN_DLL CFB_Decryption : public Keyed_Filter
void set_key(const SymmetricKey& key) { cipher->set_key(key); }
- bool valid_keylength(size_t key_len) const
- { return cipher->valid_keylength(key_len); }
+ Key_Length_Specification key_spec() const override { return cipher->key_spec(); }
bool valid_iv_length(size_t iv_len) const
{ return (iv_len == cipher->block_size()); }
diff --git a/src/filters/modes/cts/cts.h b/src/filters/modes/cts/cts.h
index ac296316f..b0efb6944 100644
--- a/src/filters/modes/cts/cts.h
+++ b/src/filters/modes/cts/cts.h
@@ -25,8 +25,7 @@ class BOTAN_DLL CTS_Encryption : public Keyed_Filter
void set_key(const SymmetricKey& key) { cipher->set_key(key); }
- bool valid_keylength(size_t key_len) const
- { return cipher->valid_keylength(key_len); }
+ Key_Length_Specification key_spec() const override { return cipher->key_spec(); }
bool valid_iv_length(size_t iv_len) const
{ return (iv_len == cipher->block_size()); }
@@ -60,8 +59,7 @@ class BOTAN_DLL CTS_Decryption : public Keyed_Filter
void set_key(const SymmetricKey& key) { cipher->set_key(key); }
- bool valid_keylength(size_t key_len) const
- { return cipher->valid_keylength(key_len); }
+ Key_Length_Specification key_spec() const override { return cipher->key_spec(); }
bool valid_iv_length(size_t iv_len) const
{ return (iv_len == cipher->block_size()); }
diff --git a/src/filters/modes/ecb/ecb.h b/src/filters/modes/ecb/ecb.h
index e6476ab5d..8f4e6f1b5 100644
--- a/src/filters/modes/ecb/ecb.h
+++ b/src/filters/modes/ecb/ecb.h
@@ -26,8 +26,7 @@ class BOTAN_DLL ECB_Encryption : public Keyed_Filter,
void set_key(const SymmetricKey& key) { cipher->set_key(key); }
- bool valid_keylength(size_t key_len) const
- { return cipher->valid_keylength(key_len); }
+ Key_Length_Specification key_spec() const override { return cipher->key_spec(); }
ECB_Encryption(BlockCipher* ciph,
BlockCipherModePaddingMethod* pad);
@@ -60,8 +59,7 @@ class BOTAN_DLL ECB_Decryption : public Keyed_Filter,
void set_key(const SymmetricKey& key) { cipher->set_key(key); }
- bool valid_keylength(size_t key_len) const
- { return cipher->valid_keylength(key_len); }
+ Key_Length_Specification key_spec() const override { return cipher->key_spec(); }
ECB_Decryption(BlockCipher* ciph,
BlockCipherModePaddingMethod* pad);
diff --git a/src/filters/modes/xts/xts.cpp b/src/filters/modes/xts/xts.cpp
index e29ef6b98..df38614bb 100644
--- a/src/filters/modes/xts/xts.cpp
+++ b/src/filters/modes/xts/xts.cpp
@@ -39,6 +39,15 @@ size_t xts_parallelism(BlockCipher* cipher)
2 * cipher->block_size());
}
+Key_Length_Specification xts_key_spec(const BlockCipher& cipher)
+ {
+ const Key_Length_Specification& spec = cipher.key_spec();
+
+ return Key_Length_Specification(2*spec.minimum_keylength(),
+ 2*spec.maximum_keylength(),
+ 2*spec.keylength_multiple());
+ }
+
}
/*
@@ -82,6 +91,11 @@ std::string XTS_Encryption::name() const
return (cipher->name() + "/XTS");
}
+Key_Length_Specification XTS_Encryption::key_spec() const
+ {
+ return xts_key_spec(*cipher);
+ }
+
/*
* Set new tweak
*/
@@ -256,6 +270,11 @@ std::string XTS_Decryption::name() const
return (cipher->name() + "/XTS");
}
+Key_Length_Specification XTS_Decryption::key_spec() const
+ {
+ return xts_key_spec(*cipher);
+ }
+
/*
* Set new tweak
*/
diff --git a/src/filters/modes/xts/xts.h b/src/filters/modes/xts/xts.h
index d4801cd37..05a779703 100644
--- a/src/filters/modes/xts/xts.h
+++ b/src/filters/modes/xts/xts.h
@@ -24,8 +24,7 @@ class BOTAN_DLL XTS_Encryption : public Keyed_Filter,
void set_key(const SymmetricKey& key);
void set_iv(const InitializationVector& iv);
- bool valid_keylength(size_t key_len) const
- { return cipher->valid_keylength(key_len); }
+ Key_Length_Specification key_spec() const override;
bool valid_iv_length(size_t iv_len) const
{ return (iv_len == cipher->block_size()); }
@@ -61,8 +60,7 @@ class BOTAN_DLL XTS_Decryption : public Keyed_Filter,
void set_key(const SymmetricKey& key);
void set_iv(const InitializationVector& iv);
- bool valid_keylength(size_t key_len) const
- { return cipher->valid_keylength(key_len); }
+ Key_Length_Specification key_spec() const override;
bool valid_iv_length(size_t iv_len) const
{ return (iv_len == cipher->block_size()); }