diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/aead/aead.h | 7 | ||||
-rw-r--r-- | src/aead/eax/eax.h | 9 | ||||
-rw-r--r-- | src/aead/gcm/gcm.h | 9 | ||||
-rw-r--r-- | src/aead/ocb/ocb.h | 9 |
4 files changed, 34 insertions, 0 deletions
diff --git a/src/aead/aead.h b/src/aead/aead.h index 1daa67f59..eb9e7ec7d 100644 --- a/src/aead/aead.h +++ b/src/aead/aead.h @@ -23,6 +23,13 @@ class AEAD_Mode : public SymmetricAlgorithm { public: /** + * Returns the size of the output if this mode is used to process + * a message with input_length bytes. Typically this will be + * input_length plus or minus the length of the tag. + */ + virtual size_t output_length(size_t input_length) const = 0; + + /** * @return size of required blocks to update */ virtual size_t update_granularity() const = 0; diff --git a/src/aead/eax/eax.h b/src/aead/eax/eax.h index 6720bdca4..f93e48d22 100644 --- a/src/aead/eax/eax.h +++ b/src/aead/eax/eax.h @@ -73,6 +73,9 @@ class BOTAN_DLL EAX_Encryption : public EAX_Mode EAX_Encryption(BlockCipher* cipher, size_t tag_size = 16) : EAX_Mode(cipher, tag_size) {} + size_t output_length(size_t input_length) const override + { return input_length + tag_size(); } + size_t minimum_final_size() const override { return 0; } void update(secure_vector<byte>& blocks, size_t offset) override; @@ -93,6 +96,12 @@ class BOTAN_DLL EAX_Decryption : public EAX_Mode EAX_Decryption(BlockCipher* cipher, size_t tag_size = 16) : EAX_Mode(cipher, tag_size) {} + size_t output_length(size_t input_length) const override + { + BOTAN_ASSERT(input_length > tag_size(), "Sufficient input"); + return input_length - tag_size(); + } + size_t minimum_final_size() const override { return tag_size(); } void update(secure_vector<byte>& blocks, size_t offset) override; diff --git a/src/aead/gcm/gcm.h b/src/aead/gcm/gcm.h index bc7eaae20..f36aafc5f 100644 --- a/src/aead/gcm/gcm.h +++ b/src/aead/gcm/gcm.h @@ -68,6 +68,9 @@ class BOTAN_DLL GCM_Encryption : public GCM_Mode GCM_Encryption(BlockCipher* cipher, size_t tag_size = 16) : GCM_Mode(cipher, tag_size) {} + size_t output_length(size_t input_length) const override + { return input_length + tag_size(); } + size_t minimum_final_size() const override { return 0; } void update(secure_vector<byte>& blocks, size_t offset) override; @@ -88,6 +91,12 @@ class BOTAN_DLL GCM_Decryption : public GCM_Mode GCM_Decryption(BlockCipher* cipher, size_t tag_size = 16) : GCM_Mode(cipher, tag_size) {} + size_t output_length(size_t input_length) const override + { + BOTAN_ASSERT(input_length > tag_size(), "Sufficient input"); + return input_length - tag_size(); + } + size_t minimum_final_size() const override { return tag_size(); } void update(secure_vector<byte>& blocks, size_t offset) override; diff --git a/src/aead/ocb/ocb.h b/src/aead/ocb/ocb.h index d50710a79..d2b207fd8 100644 --- a/src/aead/ocb/ocb.h +++ b/src/aead/ocb/ocb.h @@ -82,6 +82,9 @@ class BOTAN_DLL OCB_Encryption : public OCB_Mode OCB_Encryption(BlockCipher* cipher, size_t tag_size = 16) : OCB_Mode(cipher, tag_size) {} + size_t output_length(size_t input_length) const override + { return input_length + tag_size(); } + size_t minimum_final_size() const override { return 0; } void update(secure_vector<byte>& blocks, size_t offset) override; @@ -101,6 +104,12 @@ class BOTAN_DLL OCB_Decryption : public OCB_Mode OCB_Decryption(BlockCipher* cipher, size_t tag_size = 16) : OCB_Mode(cipher, tag_size) {} + size_t output_length(size_t input_length) const override + { + BOTAN_ASSERT(input_length > tag_size(), "Sufficient input"); + return input_length - tag_size(); + } + size_t minimum_final_size() const override { return tag_size(); } void update(secure_vector<byte>& blocks, size_t offset) override; |