84dc4b3e7eea3e9c8fafa5f4fd632a51ee8b356fMukund Sivaraman * Taken from OpenBSD CVS src/lib/libc/crypt/chacha_private.h on
84dc4b3e7eea3e9c8fafa5f4fd632a51ee8b356fMukund Sivaraman * May 12, 2014.
84dc4b3e7eea3e9c8fafa5f4fd632a51ee8b356fMukund SivaramanD. J. Bernstein
84dc4b3e7eea3e9c8fafa5f4fd632a51ee8b356fMukund SivaramanPublic domain.
84dc4b3e7eea3e9c8fafa5f4fd632a51ee8b356fMukund Sivaramantypedef struct
84dc4b3e7eea3e9c8fafa5f4fd632a51ee8b356fMukund Sivaraman#define U32V(v) ((u32)(v) & U32C(0xFFFFFFFF))
84dc4b3e7eea3e9c8fafa5f4fd632a51ee8b356fMukund Sivaraman (((u32)((p)[0]) ) | \
84dc4b3e7eea3e9c8fafa5f4fd632a51ee8b356fMukund Sivaraman (p)[0] = U8V((v) ); \
5331f97edc125f66ac6d0060b3d016309169f411Mark Andrewsstatic const char sigma[16] = { 'e', 'x', 'p', 'a', 'n', 'd', ' ', '3',
5331f97edc125f66ac6d0060b3d016309169f411Mark Andrewsstatic const char tau[16] = { 'e', 'x', 'p', 'a', 'n', 'd', ' ', '1',
84dc4b3e7eea3e9c8fafa5f4fd632a51ee8b356fMukund Sivaramanchacha_keysetup(chacha_ctx *x,const u8 *k,u32 kbits,u32 ivbits)
84dc4b3e7eea3e9c8fafa5f4fd632a51ee8b356fMukund Sivaraman } else { /* kbits == 128 */
84dc4b3e7eea3e9c8fafa5f4fd632a51ee8b356fMukund Sivaraman x->input[0] = U8TO32_LITTLE(constants + 0);
84dc4b3e7eea3e9c8fafa5f4fd632a51ee8b356fMukund Sivaraman x->input[1] = U8TO32_LITTLE(constants + 4);
84dc4b3e7eea3e9c8fafa5f4fd632a51ee8b356fMukund Sivaraman x->input[2] = U8TO32_LITTLE(constants + 8);
84dc4b3e7eea3e9c8fafa5f4fd632a51ee8b356fMukund Sivaraman x->input[3] = U8TO32_LITTLE(constants + 12);
84dc4b3e7eea3e9c8fafa5f4fd632a51ee8b356fMukund Sivaramanchacha_encrypt_bytes(chacha_ctx *x,const u8 *m,u8 *c,u32 bytes)
84dc4b3e7eea3e9c8fafa5f4fd632a51ee8b356fMukund Sivaraman u32 x0, x1, x2, x3, x4, x5, x6, x7, x8, x9, x10, x11, x12, x13, x14, x15;
84dc4b3e7eea3e9c8fafa5f4fd632a51ee8b356fMukund Sivaraman u32 j0, j1, j2, j3, j4, j5, j6, j7, j8, j9, j10, j11, j12, j13, j14, j15;
84dc4b3e7eea3e9c8fafa5f4fd632a51ee8b356fMukund Sivaraman /* stopping at 2^70 bytes per nonce is user's responsibility */
84dc4b3e7eea3e9c8fafa5f4fd632a51ee8b356fMukund Sivaraman for (i = 0;i < bytes;++i) ctarget[i] = c[i];