// poly1305.h - written and placed in the public domain by Jeffrey Walton and Jean-Pierre Munch // Based on Andy Polyakov's Base-2^26 scalar multiplication implementation for OpenSSL. /// \file poly1305.h /// \brief Classes for Poly1305 message authentication code /// \details Poly1305-AES is a state-of-the-art message-authentication code suitable for a wide /// variety of applications. Poly1305-AES computes a 16-byte authenticator of a variable-length /// message, using a 16-byte AES key, a 16-byte additional key, and a 16-byte nonce. /// \details Each message must use a unique security context, which means either the key or nonce /// must be changed after each message. It can be accomplished in one of two ways. First, you /// can create a new Poly1305 object with a key and nonce each time its needed. ///
SecByteBlock key(32), nonce(16); /// prng.GenerateBlock(key, key.size()); /// prng.GenerateBlock(nonce, nonce.size()); /// /// Poly1305/// /// \details Second, you can create a Poly1305 object, reuse the key, and set a fresh nonce /// for each message. The second and subsequent nonces can be generated directly using a /// RandomNumberGenerator() derived class; or it can be generated using GetNextIV(). ///poly1305(key, key.size(), nonce, nonce.size()); /// poly1305.Update(...); /// poly1305.Final(...);
SecByteBlock key(32), nonce(16); /// prng.GenerateBlock(key, key.size()); /// prng.GenerateBlock(nonce, nonce.size()); /// /// // First message /// Poly1305/// \sa Daniel J. Bernstein The Poly1305-AES /// Message-Authentication Code (20050329) and Andy Polyakov Poly1305 Revised /// \since Crypto++ 6.0 #ifndef CRYPTOPP_POLY1305_H #define CRYPTOPP_POLY1305_H #include "cryptlib.h" #include "seckey.h" #include "secblock.h" #include "argnames.h" #include "algparam.h" NAMESPACE_BEGIN(CryptoPP) /// \brief Poly1305 message authentication code base class /// \tparam T class derived from BlockCipherDocumentation with 16-byte key and 16-byte blocksize /// \since Crypto++ 6.0 templatepoly1305(key, key.size()); /// poly1305.Resynchronize(nonce); /// poly1305.Update(...); /// poly1305.Final(...); /// /// // Second message /// poly1305.GetNextIV(prng, nonce); /// poly1305.Resynchronize(nonce); /// poly1305.Update(...); /// poly1305.Final(...); /// ...
SecByteBlock key(32), nonce(16); /// prng.GenerateBlock(key, key.size()); /// prng.GenerateBlock(nonce, nonce.size()); /// /// Poly1305/// /// \details Second, you can create a Poly1305 object, reuse the key, and set a fresh nonce /// for each message. The second and subsequent nonces can be generated directly using a /// RandomNumberGenerator() derived class; or it can be generated using GetNextIV(). ///poly1305(key, key.size(), nonce, nonce.size()); /// poly1305.Update(...); /// poly1305.Final(...);
SecByteBlock key(32), nonce(16); /// prng.GenerateBlock(key, key.size()); /// prng.GenerateBlock(nonce, nonce.size()); /// /// // First message /// Poly1305/// \warning The Poly1305 class does not enforce a fresh nonce for each message. The source code /// will assert in debug builds to alert of nonce reuse. No action is taken in release builds. /// \sa Daniel J. Bernstein The Poly1305-AES /// Message-Authentication Code (20050329) and Andy Polyakov Poly1305 Revised /// \since Crypto++ 6.0 templatepoly1305(key, key.size()); /// poly1305.Resynchronize(nonce); /// poly1305.Update(...); /// poly1305.Final(...); /// /// // Second message /// poly1305.GetNextIV(prng, nonce); /// poly1305.Resynchronize(nonce); /// poly1305.Update(...); /// poly1305.Final(...); /// ...