@@ -1760,137 +1760,6 @@ class KEM final {
17601760
17611761#endif // OPENSSL_VERSION_MAJOR >= 3
17621762
1763- // ============================================================================
1764- // AEAD (Authenticated Encryption with Associated Data)
1765- // Note that the underlying EVP_AEAD interface is specific to BoringSSL. AEAD
1766- // primitives are accessed through the Cipher class instead, if using OpenSSL.
1767-
1768- #ifdef OPENSSL_IS_BORINGSSL
1769- class Aead final : public ModeMixin<Aead> {
1770- private:
1771- // BoringSSL does not keep a list of AEADs, so we need to maintain our own.
1772- struct AeadInfo {
1773- std::string name;
1774- int mode;
1775- int nid = 0 ; // Note: BoringSSL only defines NIDs for some AEADs
1776- };
1777-
1778- public:
1779- Aead () = default ;
1780- Aead (const AeadInfo* info, const EVP_AEAD* aead) : info_(info), aead_(aead) {}
1781- Aead (const Aead&) = default ;
1782- Aead& operator =(const Aead&) = default ;
1783- NCRYPTO_DISALLOW_MOVE (Aead)
1784-
1785- inline const EVP_AEAD* get () const { return aead_; }
1786- inline operator const EVP_AEAD*() const { return aead_; }
1787- inline operator bool () const { return aead_ != nullptr ; }
1788-
1789- int getMode () const ;
1790- int getNonceLength () const ;
1791- int getKeyLength () const ;
1792- int getBlockSize () const ;
1793- int getMaxOverhead () const ;
1794- int getMaxTagLength () const ;
1795- std::string_view getName () const ;
1796-
1797- static const Aead FromName (std::string_view name);
1798-
1799- // TODO(npaun): BoringSSL does not define NIDs for all AEADs.
1800- // This method is included only for implementing getCipherInfo and can't be
1801- // used to construct an Aead instance.
1802- int getNid () const ;
1803- // static const AEAD FromNid(int nid);
1804-
1805- static const Aead FromCtx (std::string_view name, const AeadCtxPointer& ctx);
1806-
1807- using AeadNameCallback = std::function<void (std::string_view name)>;
1808-
1809- // Iterates the known ciphers if the underlying implementation
1810- // is able to do so.
1811- static void ForEach (AeadNameCallback callback);
1812-
1813- // Utilities to get various AEADs by type.
1814-
1815- static const Aead EMPTY;
1816- static const Aead AES_128_GCM;
1817- static const Aead AES_192_GCM;
1818- static const Aead AES_256_GCM;
1819- static const Aead CHACHA20_POLY1305;
1820- static const Aead XCHACHA20_POLY1305;
1821- static const Aead AES_128_CTR_HMAC_SHA256;
1822- static const Aead AES_256_CTR_HMAC_SHA256;
1823- static const Aead AES_128_GCM_SIV;
1824- static const Aead AES_256_GCM_SIV;
1825- static const Aead AES_128_GCM_RANDNONCE;
1826- static const Aead AES_256_GCM_RANDNONCE;
1827- static const Aead AES_128_CCM_BLUETOOTH;
1828- static const Aead AES_128_CCM_BLUETOOTH_8;
1829- static const Aead AES_128_CCM_MATTER;
1830- static const Aead AES_128_EAX;
1831- static const Aead AES_256_EAX;
1832-
1833- private:
1834- const EVP_AEAD* aead_ = nullptr ;
1835- const AeadInfo* info_ = nullptr ;
1836-
1837- using AeadConstructor = const EVP_AEAD* (*)();
1838- static const std::unordered_map<AeadConstructor, AeadInfo> aeadIndex;
1839- static const Aead FromConstructor (AeadConstructor construct);
1840- };
1841-
1842- class AeadCtxPointer final {
1843- public:
1844- static AeadCtxPointer New (
1845- const Aead& aead,
1846- bool encrypt,
1847- const unsigned char * key = nullptr ,
1848- size_t keyLen = 0 ,
1849- size_t tagLen = EVP_AEAD_DEFAULT_TAG_LENGTH /* = 0 */ );
1850-
1851- AeadCtxPointer () = default ;
1852- explicit AeadCtxPointer (EVP_AEAD_CTX* ctx);
1853- AeadCtxPointer (AeadCtxPointer&& other) noexcept ;
1854- AeadCtxPointer& operator =(AeadCtxPointer&& other) noexcept ;
1855- NCRYPTO_DISALLOW_COPY (AeadCtxPointer)
1856- ~AeadCtxPointer ();
1857-
1858- inline bool operator ==(std::nullptr_t ) const noexcept {
1859- return ctx_ == nullptr ;
1860- }
1861- inline operator bool () const { return ctx_ != nullptr ; }
1862- inline EVP_AEAD_CTX* get () const { return ctx_.get (); }
1863- inline operator EVP_AEAD_CTX*() const { return ctx_.get (); }
1864- void reset (EVP_AEAD_CTX* ctx = nullptr );
1865- EVP_AEAD_CTX* release ();
1866-
1867- bool init (const Aead& aead,
1868- bool encrypt,
1869- const unsigned char * key = nullptr ,
1870- size_t keyLen = 0 ,
1871- size_t tagLen = EVP_AEAD_DEFAULT_TAG_LENGTH /* = 0 */ );
1872-
1873- // TODO(npaun): BoringSSL does not define NIDs for all AEADs.
1874- // Decide if we will even implement this method.
1875- // int getNid() const;
1876-
1877- bool encrypt (const Buffer<const unsigned char >& in,
1878- Buffer<unsigned char >& out,
1879- Buffer<unsigned char >& tag,
1880- const Buffer<const unsigned char >& nonce,
1881- const Buffer<const unsigned char >& aad);
1882-
1883- bool decrypt (const Buffer<const unsigned char >& in,
1884- Buffer<unsigned char >& out,
1885- const Buffer<const unsigned char >& tag,
1886- const Buffer<const unsigned char >& nonce,
1887- const Buffer<const unsigned char >& aad);
1888-
1889- private:
1890- DeleteFnPtr<EVP_AEAD_CTX, EVP_AEAD_CTX_free> ctx_;
1891- };
1892- #endif
1893-
18941763// ============================================================================
18951764// Version metadata
18961765#define NCRYPTO_VERSION " 0.0.1"
0 commit comments