1*19261079SEd Maste /* $OpenBSD: chacha.h,v 1.5 2021/04/03 05:54:14 djm Exp $ */ 2f7167e0eSDag-Erling Smørgrav 3f7167e0eSDag-Erling Smørgrav /* 4f7167e0eSDag-Erling Smørgrav chacha-merged.c version 20080118 5f7167e0eSDag-Erling Smørgrav D. J. Bernstein 6f7167e0eSDag-Erling Smørgrav Public domain. 7f7167e0eSDag-Erling Smørgrav */ 8f7167e0eSDag-Erling Smørgrav 9f7167e0eSDag-Erling Smørgrav #ifndef CHACHA_H 10f7167e0eSDag-Erling Smørgrav #define CHACHA_H 11f7167e0eSDag-Erling Smørgrav 12f7167e0eSDag-Erling Smørgrav #include <sys/types.h> 13ca86bcf2SDag-Erling Smørgrav #include <stdlib.h> 14f7167e0eSDag-Erling Smørgrav 15f7167e0eSDag-Erling Smørgrav struct chacha_ctx { 16f7167e0eSDag-Erling Smørgrav u_int input[16]; 17f7167e0eSDag-Erling Smørgrav }; 18f7167e0eSDag-Erling Smørgrav 19f7167e0eSDag-Erling Smørgrav #define CHACHA_MINKEYLEN 16 20f7167e0eSDag-Erling Smørgrav #define CHACHA_NONCELEN 8 21f7167e0eSDag-Erling Smørgrav #define CHACHA_CTRLEN 8 22f7167e0eSDag-Erling Smørgrav #define CHACHA_STATELEN (CHACHA_NONCELEN+CHACHA_CTRLEN) 23f7167e0eSDag-Erling Smørgrav #define CHACHA_BLOCKLEN 64 24f7167e0eSDag-Erling Smørgrav 25f7167e0eSDag-Erling Smørgrav void chacha_keysetup(struct chacha_ctx *x, const u_char *k, u_int kbits) 26f7167e0eSDag-Erling Smørgrav __attribute__((__bounded__(__minbytes__, 2, CHACHA_MINKEYLEN))); 27f7167e0eSDag-Erling Smørgrav void chacha_ivsetup(struct chacha_ctx *x, const u_char *iv, const u_char *ctr) 28f7167e0eSDag-Erling Smørgrav __attribute__((__bounded__(__minbytes__, 2, CHACHA_NONCELEN))) 29f7167e0eSDag-Erling Smørgrav __attribute__((__bounded__(__minbytes__, 3, CHACHA_CTRLEN))); 30f7167e0eSDag-Erling Smørgrav void chacha_encrypt_bytes(struct chacha_ctx *x, const u_char *m, 31f7167e0eSDag-Erling Smørgrav u_char *c, u_int bytes) 32f7167e0eSDag-Erling Smørgrav __attribute__((__bounded__(__buffer__, 2, 4))) 33f7167e0eSDag-Erling Smørgrav __attribute__((__bounded__(__buffer__, 3, 4))); 34f7167e0eSDag-Erling Smørgrav 35f7167e0eSDag-Erling Smørgrav #endif /* CHACHA_H */ 36f7167e0eSDag-Erling Smørgrav 37