1ed20078bSArd Biesheuvel /* SPDX-License-Identifier: GPL-2.0 OR MIT */ 2ed20078bSArd Biesheuvel /* 3ed20078bSArd Biesheuvel * Copyright (C) 2015-2019 Jason A. Donenfeld <Jason@zx2c4.com>. All Rights Reserved. 4ed20078bSArd Biesheuvel */ 5ed20078bSArd Biesheuvel 6ed20078bSArd Biesheuvel #ifndef __CHACHA20POLY1305_H 7ed20078bSArd Biesheuvel #define __CHACHA20POLY1305_H 8ed20078bSArd Biesheuvel 9ed20078bSArd Biesheuvel #include <linux/types.h> 10d95312a3SArd Biesheuvel #include <linux/scatterlist.h> 11ed20078bSArd Biesheuvel 12ed20078bSArd Biesheuvel enum chacha20poly1305_lengths { 13ed20078bSArd Biesheuvel XCHACHA20POLY1305_NONCE_SIZE = 24, 14ed20078bSArd Biesheuvel CHACHA20POLY1305_KEY_SIZE = 32, 15ed20078bSArd Biesheuvel CHACHA20POLY1305_AUTHTAG_SIZE = 16 16ed20078bSArd Biesheuvel }; 17ed20078bSArd Biesheuvel 18ed20078bSArd Biesheuvel void chacha20poly1305_encrypt(u8 *dst, const u8 *src, const size_t src_len, 19ed20078bSArd Biesheuvel const u8 *ad, const size_t ad_len, 20ed20078bSArd Biesheuvel const u64 nonce, 21ed20078bSArd Biesheuvel const u8 key[CHACHA20POLY1305_KEY_SIZE]); 22ed20078bSArd Biesheuvel 23ed20078bSArd Biesheuvel bool __must_check 24ed20078bSArd Biesheuvel chacha20poly1305_decrypt(u8 *dst, const u8 *src, const size_t src_len, 25ed20078bSArd Biesheuvel const u8 *ad, const size_t ad_len, const u64 nonce, 26ed20078bSArd Biesheuvel const u8 key[CHACHA20POLY1305_KEY_SIZE]); 27ed20078bSArd Biesheuvel 28ed20078bSArd Biesheuvel void xchacha20poly1305_encrypt(u8 *dst, const u8 *src, const size_t src_len, 29ed20078bSArd Biesheuvel const u8 *ad, const size_t ad_len, 30ed20078bSArd Biesheuvel const u8 nonce[XCHACHA20POLY1305_NONCE_SIZE], 31ed20078bSArd Biesheuvel const u8 key[CHACHA20POLY1305_KEY_SIZE]); 32ed20078bSArd Biesheuvel 33ed20078bSArd Biesheuvel bool __must_check xchacha20poly1305_decrypt( 34ed20078bSArd Biesheuvel u8 *dst, const u8 *src, const size_t src_len, const u8 *ad, 35ed20078bSArd Biesheuvel const size_t ad_len, const u8 nonce[XCHACHA20POLY1305_NONCE_SIZE], 36ed20078bSArd Biesheuvel const u8 key[CHACHA20POLY1305_KEY_SIZE]); 37ed20078bSArd Biesheuvel 38d95312a3SArd Biesheuvel bool chacha20poly1305_encrypt_sg_inplace(struct scatterlist *src, size_t src_len, 39d95312a3SArd Biesheuvel const u8 *ad, const size_t ad_len, 40d95312a3SArd Biesheuvel const u64 nonce, 41d95312a3SArd Biesheuvel const u8 key[CHACHA20POLY1305_KEY_SIZE]); 42d95312a3SArd Biesheuvel 43d95312a3SArd Biesheuvel bool chacha20poly1305_decrypt_sg_inplace(struct scatterlist *src, size_t src_len, 44d95312a3SArd Biesheuvel const u8 *ad, const size_t ad_len, 45d95312a3SArd Biesheuvel const u64 nonce, 46d95312a3SArd Biesheuvel const u8 key[CHACHA20POLY1305_KEY_SIZE]); 47d95312a3SArd Biesheuvel 48*06cc2afbSHerbert Xu bool chacha20poly1305_selftest(void); 49*06cc2afbSHerbert Xu 50ed20078bSArd Biesheuvel #endif /* __CHACHA20POLY1305_H */ 51