xref: /dflybsd-src/crypto/openssh/chacha.h (revision 50a69bb51183a7916e776f2c9f5fa64c999f1a2f)
1*50a69bb5SSascha Wildner /* $OpenBSD: chacha.h,v 1.5 2021/04/03 05:54:14 djm Exp $ */
236e94dc5SPeter Avalos 
336e94dc5SPeter Avalos /*
436e94dc5SPeter Avalos chacha-merged.c version 20080118
536e94dc5SPeter Avalos D. J. Bernstein
636e94dc5SPeter Avalos Public domain.
736e94dc5SPeter Avalos */
836e94dc5SPeter Avalos 
936e94dc5SPeter Avalos #ifndef CHACHA_H
1036e94dc5SPeter Avalos #define CHACHA_H
1136e94dc5SPeter Avalos 
1236e94dc5SPeter Avalos #include <sys/types.h>
13ce74bacaSMatthew Dillon #include <stdlib.h>
1436e94dc5SPeter Avalos 
1536e94dc5SPeter Avalos struct chacha_ctx {
1636e94dc5SPeter Avalos 	u_int input[16];
1736e94dc5SPeter Avalos };
1836e94dc5SPeter Avalos 
1936e94dc5SPeter Avalos #define CHACHA_MINKEYLEN	16
2036e94dc5SPeter Avalos #define CHACHA_NONCELEN		8
2136e94dc5SPeter Avalos #define CHACHA_CTRLEN		8
2236e94dc5SPeter Avalos #define CHACHA_STATELEN		(CHACHA_NONCELEN+CHACHA_CTRLEN)
2336e94dc5SPeter Avalos #define CHACHA_BLOCKLEN		64
2436e94dc5SPeter Avalos 
2536e94dc5SPeter Avalos void chacha_keysetup(struct chacha_ctx *x, const u_char *k, u_int kbits)
2636e94dc5SPeter Avalos     __attribute__((__bounded__(__minbytes__, 2, CHACHA_MINKEYLEN)));
2736e94dc5SPeter Avalos void chacha_ivsetup(struct chacha_ctx *x, const u_char *iv, const u_char *ctr)
2836e94dc5SPeter Avalos     __attribute__((__bounded__(__minbytes__, 2, CHACHA_NONCELEN)))
2936e94dc5SPeter Avalos     __attribute__((__bounded__(__minbytes__, 3, CHACHA_CTRLEN)));
3036e94dc5SPeter Avalos void chacha_encrypt_bytes(struct chacha_ctx *x, const u_char *m,
3136e94dc5SPeter Avalos     u_char *c, u_int bytes)
3236e94dc5SPeter Avalos     __attribute__((__bounded__(__buffer__, 2, 4)))
3336e94dc5SPeter Avalos     __attribute__((__bounded__(__buffer__, 3, 4)));
3436e94dc5SPeter Avalos 
3536e94dc5SPeter Avalos #endif	/* CHACHA_H */
3636e94dc5SPeter Avalos 
37