aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorlloyd <[email protected]>2010-06-16 14:23:30 +0000
committerlloyd <[email protected]>2010-06-16 14:23:30 +0000
commit64301bf302c486e454f9dae112f581cfc5ca2294 (patch)
treecbe611edc5db73ce24c6f759bf86744a0becb585 /src
parent155e3146937fec7e93cce7a03f6b3597279a3ec2 (diff)
Add Keyed_Filter::valid_iv_length (it was already in
StreamCipher_Filter, but not elsewhere). Add to all modes. Defaults to return true iff the IV length is zero; ie that IVs are not supported.
Diffstat (limited to 'src')
-rw-r--r--src/filters/basefilt.cpp5
-rw-r--r--src/filters/filters.h2
-rw-r--r--src/filters/key_filt.h18
-rw-r--r--src/filters/modes/cbc/cbc.cpp4
-rw-r--r--src/filters/modes/cbc/cbc.h6
-rw-r--r--src/filters/modes/cfb/cfb.cpp4
-rw-r--r--src/filters/modes/cfb/cfb.h6
-rw-r--r--src/filters/modes/cts/cts.cpp4
-rw-r--r--src/filters/modes/cts/cts.h6
-rw-r--r--src/filters/modes/eax/eax.h5
-rw-r--r--src/filters/modes/xts/xts.cpp4
-rw-r--r--src/filters/modes/xts/xts.h6
12 files changed, 56 insertions, 14 deletions
diff --git a/src/filters/basefilt.cpp b/src/filters/basefilt.cpp
index bf9a526df..e5ecd5418 100644
--- a/src/filters/basefilt.cpp
+++ b/src/filters/basefilt.cpp
@@ -16,6 +16,11 @@ void Keyed_Filter::set_iv(const InitializationVector&)
{
}
+bool Keyed_Filter::valid_iv_length(u32bit length) const
+ {
+ return (length == 0);
+ }
+
/*
* Chain Constructor
*/
diff --git a/src/filters/filters.h b/src/filters/filters.h
index 6c78f77aa..5953518d3 100644
--- a/src/filters/filters.h
+++ b/src/filters/filters.h
@@ -44,7 +44,7 @@ class BOTAN_DLL StreamCipher_Filter : public Keyed_Filter
*/
void write(const byte input[], u32bit input_len);
- bool valid_iv_length(u32bit iv_len)
+ bool valid_iv_length(u32bit iv_len) const
{ return cipher->valid_iv_length(iv_len); }
/**
diff --git a/src/filters/key_filt.h b/src/filters/key_filt.h
index 5b34751b4..55d4f8580 100644
--- a/src/filters/key_filt.h
+++ b/src/filters/key_filt.h
@@ -21,23 +21,31 @@ class BOTAN_DLL Keyed_Filter : public Filter
{
public:
/**
- * Set the key of this filter.
- * @param key the key to set
+ * Set the key of this filter
+ * @param key the key to use
*/
virtual void set_key(const SymmetricKey& key) = 0;
/**
- * Set the initialization vector of this filter.
- * @param iv the initialization vector to set
+ * Set the initialization vector of this filter. Note: you should
+ * call set_iv() only after you have called set_key()
+ * @param iv the initialization vector to use
*/
virtual void set_iv(const InitializationVector& iv);
/**
- * Check whether a key length is valid for this filter.
+ * 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
*/
virtual bool valid_keylength(u32bit length) const = 0;
+
+ /**
+ * Check whether an IV length is valid for this filter
+ * @param length the IV length to be checked for validity
+ * @return true if the IV length is valid, false otherwise
+ */
+ virtual bool valid_iv_length(u32bit length) const;
};
}
diff --git a/src/filters/modes/cbc/cbc.cpp b/src/filters/modes/cbc/cbc.cpp
index a3866749c..b0c3493e7 100644
--- a/src/filters/modes/cbc/cbc.cpp
+++ b/src/filters/modes/cbc/cbc.cpp
@@ -49,7 +49,7 @@ CBC_Encryption::CBC_Encryption(BlockCipher* ciph,
*/
void CBC_Encryption::set_iv(const InitializationVector& iv)
{
- if(iv.length() != state.size())
+ if(!valid_iv_length(iv.length()))
throw Invalid_IV_Length(name(), iv.length());
state = iv.bits_of();
@@ -149,7 +149,7 @@ CBC_Decryption::CBC_Decryption(BlockCipher* ciph,
*/
void CBC_Decryption::set_iv(const InitializationVector& iv)
{
- if(iv.length() != state.size())
+ if(!valid_iv_length(iv.length()))
throw Invalid_IV_Length(name(), iv.length());
state = iv.bits_of();
diff --git a/src/filters/modes/cbc/cbc.h b/src/filters/modes/cbc/cbc.h
index 3145f60ba..4f682530b 100644
--- a/src/filters/modes/cbc/cbc.h
+++ b/src/filters/modes/cbc/cbc.h
@@ -31,6 +31,9 @@ class BOTAN_DLL CBC_Encryption : public Keyed_Filter,
bool valid_keylength(u32bit key_len) const
{ return cipher->valid_keylength(key_len); }
+ bool valid_iv_length(u32bit iv_len) const
+ { return (iv_len == cipher->BLOCK_SIZE); }
+
CBC_Encryption(BlockCipher* cipher,
BlockCipherModePaddingMethod* padding);
@@ -68,6 +71,9 @@ class BOTAN_DLL CBC_Decryption : public Keyed_Filter,
bool valid_keylength(u32bit key_len) const
{ return cipher->valid_keylength(key_len); }
+ bool valid_iv_length(u32bit iv_len) const
+ { return (iv_len == cipher->BLOCK_SIZE); }
+
CBC_Decryption(BlockCipher* cipher,
BlockCipherModePaddingMethod* padding);
diff --git a/src/filters/modes/cfb/cfb.cpp b/src/filters/modes/cfb/cfb.cpp
index 778d47484..239b03254 100644
--- a/src/filters/modes/cfb/cfb.cpp
+++ b/src/filters/modes/cfb/cfb.cpp
@@ -54,7 +54,7 @@ CFB_Encryption::CFB_Encryption(BlockCipher* ciph,
void CFB_Encryption::set_iv(const InitializationVector& iv)
{
- if(iv.length() != state.size())
+ if(!valid_iv_length(iv.length()))
throw Invalid_IV_Length(name(), iv.length());
state = iv.bits_of();
@@ -131,7 +131,7 @@ CFB_Decryption::CFB_Decryption(BlockCipher* ciph,
void CFB_Decryption::set_iv(const InitializationVector& iv)
{
- if(iv.length() != state.size())
+ if(!valid_iv_length(iv.length()))
throw Invalid_IV_Length(name(), iv.length());
state = iv.bits_of();
diff --git a/src/filters/modes/cfb/cfb.h b/src/filters/modes/cfb/cfb.h
index 758a47b33..05fb9574f 100644
--- a/src/filters/modes/cfb/cfb.h
+++ b/src/filters/modes/cfb/cfb.h
@@ -28,6 +28,9 @@ class BOTAN_DLL CFB_Encryption : public Keyed_Filter
bool valid_keylength(u32bit key_len) const
{ return cipher->valid_keylength(key_len); }
+ bool valid_iv_length(u32bit iv_len) const
+ { return (iv_len == cipher->BLOCK_SIZE); }
+
CFB_Encryption(BlockCipher* cipher, u32bit feedback = 0);
CFB_Encryption(BlockCipher* cipher,
@@ -59,6 +62,9 @@ class BOTAN_DLL CFB_Decryption : public Keyed_Filter
bool valid_keylength(u32bit key_len) const
{ return cipher->valid_keylength(key_len); }
+ bool valid_iv_length(u32bit iv_len) const
+ { return (iv_len == cipher->BLOCK_SIZE); }
+
CFB_Decryption(BlockCipher* cipher, u32bit feedback = 0);
CFB_Decryption(BlockCipher* cipher,
diff --git a/src/filters/modes/cts/cts.cpp b/src/filters/modes/cts/cts.cpp
index b27b9b3c5..61df8897b 100644
--- a/src/filters/modes/cts/cts.cpp
+++ b/src/filters/modes/cts/cts.cpp
@@ -43,7 +43,7 @@ CTS_Encryption::CTS_Encryption(BlockCipher* ciph,
*/
void CTS_Encryption::set_iv(const InitializationVector& iv)
{
- if(iv.length() != state.size())
+ if(!valid_iv_length(iv.length()))
throw Invalid_IV_Length(name(), iv.length());
state = iv.bits_of();
@@ -145,7 +145,7 @@ CTS_Decryption::CTS_Decryption(BlockCipher* ciph,
*/
void CTS_Decryption::set_iv(const InitializationVector& iv)
{
- if(iv.length() != state.size())
+ if(!valid_iv_length(iv.length()))
throw Invalid_IV_Length(name(), iv.length());
state = iv.bits_of();
diff --git a/src/filters/modes/cts/cts.h b/src/filters/modes/cts/cts.h
index 3f63060cf..e9c8ec592 100644
--- a/src/filters/modes/cts/cts.h
+++ b/src/filters/modes/cts/cts.h
@@ -28,6 +28,9 @@ class BOTAN_DLL CTS_Encryption : public Keyed_Filter
bool valid_keylength(u32bit key_len) const
{ return cipher->valid_keylength(key_len); }
+ bool valid_iv_length(u32bit iv_len) const
+ { return (iv_len == cipher->BLOCK_SIZE); }
+
CTS_Encryption(BlockCipher* cipher);
CTS_Encryption(BlockCipher* cipher,
@@ -60,6 +63,9 @@ class BOTAN_DLL CTS_Decryption : public Keyed_Filter
bool valid_keylength(u32bit key_len) const
{ return cipher->valid_keylength(key_len); }
+ bool valid_iv_length(u32bit iv_len) const
+ { return (iv_len == cipher->BLOCK_SIZE); }
+
CTS_Decryption(BlockCipher* cipher);
CTS_Decryption(BlockCipher* cipher,
diff --git a/src/filters/modes/eax/eax.h b/src/filters/modes/eax/eax.h
index 7d45a18ba..8f79039d9 100644
--- a/src/filters/modes/eax/eax.h
+++ b/src/filters/modes/eax/eax.h
@@ -39,6 +39,11 @@ class BOTAN_DLL EAX_Base : public Keyed_Filter
bool valid_keylength(u32bit key_len) const;
+ /**
+ * EAX supports arbitrary IV lengths
+ */
+ bool valid_iv_length(u32bit) const { return true; }
+
~EAX_Base() { delete ctr; delete cmac; }
protected:
/**
diff --git a/src/filters/modes/xts/xts.cpp b/src/filters/modes/xts/xts.cpp
index 77920d4ac..608c315ff 100644
--- a/src/filters/modes/xts/xts.cpp
+++ b/src/filters/modes/xts/xts.cpp
@@ -87,7 +87,7 @@ std::string XTS_Encryption::name() const
*/
void XTS_Encryption::set_iv(const InitializationVector& iv)
{
- if(iv.length() != cipher->BLOCK_SIZE)
+ if(!valid_iv_length(iv.length()))
throw Invalid_IV_Length(name(), iv.length());
const u32bit blocks_in_tweak = tweak.size() / cipher->BLOCK_SIZE;
@@ -259,7 +259,7 @@ std::string XTS_Decryption::name() const
*/
void XTS_Decryption::set_iv(const InitializationVector& iv)
{
- if(iv.length() != cipher->BLOCK_SIZE)
+ if(!valid_iv_length(iv.length()))
throw Invalid_IV_Length(name(), iv.length());
const u32bit blocks_in_tweak = tweak.size() / cipher->BLOCK_SIZE;
diff --git a/src/filters/modes/xts/xts.h b/src/filters/modes/xts/xts.h
index a6ec10ff3..67c087c72 100644
--- a/src/filters/modes/xts/xts.h
+++ b/src/filters/modes/xts/xts.h
@@ -27,6 +27,9 @@ class BOTAN_DLL XTS_Encryption : public Keyed_Filter,
bool valid_keylength(u32bit key_len) const
{ return cipher->valid_keylength(key_len); }
+ bool valid_iv_length(u32bit iv_len) const
+ { return (iv_len == cipher->BLOCK_SIZE); }
+
std::string name() const;
XTS_Encryption(BlockCipher* ciph);
@@ -61,6 +64,9 @@ class BOTAN_DLL XTS_Decryption : public Keyed_Filter,
bool valid_keylength(u32bit key_len) const
{ return cipher->valid_keylength(key_len); }
+ bool valid_iv_length(u32bit iv_len) const
+ { return (iv_len == cipher->BLOCK_SIZE); }
+
std::string name() const;
XTS_Decryption(BlockCipher* ciph);