Botan  1.11.15
src/lib/modes/aead/aead.h
Go to the documentation of this file.
00001 /*
00002 * Interface for AEAD modes
00003 * (C) 2013 Jack Lloyd
00004 *
00005 * Botan is released under the Simplified BSD License (see license.txt)
00006 */
00007 
00008 #ifndef BOTAN_AEAD_MODE_H__
00009 #define BOTAN_AEAD_MODE_H__
00010 
00011 #include <botan/cipher_mode.h>
00012 
00013 namespace Botan {
00014 
00015 /**
00016 * Interface for AEAD (Authenticated Encryption with Associated Data)
00017 * modes. These modes provide both encryption and message
00018 * authentication, and can authenticate additional per-message data
00019 * which is not included in the ciphertext (for instance a sequence
00020 * number).
00021 */
00022 class BOTAN_DLL AEAD_Mode : public Cipher_Mode
00023    {
00024    public:
00025       bool authenticated() const override { return true; }
00026 
00027       /**
00028       * Set associated data that is not included in the ciphertext but
00029       * that should be authenticated. Must be called after set_key and
00030       * before start.
00031       *
00032       * Unless reset by another call, the associated data is kept
00033       * between messages. Thus, if the AD does not change, calling
00034       * once (after set_key) is the optimum.
00035       *
00036       * @param ad the associated data
00037       * @param ad_len length of add in bytes
00038       */
00039       virtual void set_associated_data(const byte ad[], size_t ad_len) = 0;
00040 
00041       template<typename Alloc>
00042       void set_associated_data_vec(const std::vector<byte, Alloc>& ad)
00043          {
00044          set_associated_data(&ad[0], ad.size());
00045          }
00046 
00047       template<typename Alloc>
00048       void set_ad(const std::vector<byte, Alloc>& ad)
00049          {
00050          set_associated_data(&ad[0], ad.size());
00051          }
00052 
00053       /**
00054       * Default AEAD nonce size (a commonly supported value among AEAD
00055       * modes, and large enough that random collisions are unlikely).
00056       */
00057       size_t default_nonce_length() const override { return 12; }
00058    };
00059 
00060 /**
00061 * Get an AEAD mode by name (eg "AES-128/GCM" or "Serpent/EAX")
00062 */
00063 BOTAN_DLL AEAD_Mode* get_aead(const std::string& name, Cipher_Dir direction);
00064 
00065 }
00066 
00067 #endif