1e7168004SJohn Baldwin /*- 2*4d846d26SWarner Losh * SPDX-License-Identifier: BSD-2-Clause 3e7168004SJohn Baldwin * 4e7168004SJohn Baldwin * Copyright (c) 2021 The FreeBSD Foundation 5e7168004SJohn Baldwin * 6e7168004SJohn Baldwin * This software was developed by Ararat River Consulting, LLC under 7e7168004SJohn Baldwin * sponsorship from the FreeBSD Foundation. 8e7168004SJohn Baldwin * 9e7168004SJohn Baldwin * Redistribution and use in source and binary forms, with or without 10e7168004SJohn Baldwin * modification, are permitted provided that the following conditions 11e7168004SJohn Baldwin * are met: 12e7168004SJohn Baldwin * 1. Redistributions of source code must retain the above copyright 13e7168004SJohn Baldwin * notice, this list of conditions and the following disclaimer. 14e7168004SJohn Baldwin * 2. Redistributions in binary form must reproduce the above copyright 15e7168004SJohn Baldwin * notice, this list of conditions and the following disclaimer in the 16e7168004SJohn Baldwin * documentation and/or other materials provided with the distribution. 17e7168004SJohn Baldwin * 1889e0ee0dSJohn Baldwin * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 19e7168004SJohn Baldwin * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 20e7168004SJohn Baldwin * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 2189e0ee0dSJohn Baldwin * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 22e7168004SJohn Baldwin * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 23e7168004SJohn Baldwin * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 24e7168004SJohn Baldwin * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 25e7168004SJohn Baldwin * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 26e7168004SJohn Baldwin * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 27e7168004SJohn Baldwin * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 28e7168004SJohn Baldwin * SUCH DAMAGE. 29e7168004SJohn Baldwin */ 30e7168004SJohn Baldwin 31e7168004SJohn Baldwin #ifndef __CRYPTO_CHACHA20_POLY1305_H__ 32e7168004SJohn Baldwin #define __CRYPTO_CHACHA20_POLY1305_H__ 33e7168004SJohn Baldwin 34e7168004SJohn Baldwin #include <sys/types.h> 35e7168004SJohn Baldwin 36e7168004SJohn Baldwin /* The Poly1305 tag is appended to the cipher text. */ 37e7168004SJohn Baldwin 38e7168004SJohn Baldwin void chacha20_poly1305_encrypt(uint8_t *dst, const uint8_t *src, 39e7168004SJohn Baldwin const size_t src_len, const uint8_t *aad, const size_t aad_len, 40e7168004SJohn Baldwin const uint8_t *nonce, const size_t nonce_len, const uint8_t *key); 41e7168004SJohn Baldwin 42e7168004SJohn Baldwin bool chacha20_poly1305_decrypt(uint8_t *dst, const uint8_t *src, 43e7168004SJohn Baldwin const size_t src_len, const uint8_t *aad, const size_t aad_len, 44e7168004SJohn Baldwin const uint8_t *nonce, const size_t nonce_len, const uint8_t *key); 45e7168004SJohn Baldwin 46e7168004SJohn Baldwin void xchacha20_poly1305_encrypt(uint8_t *dst, const uint8_t *src, 47e7168004SJohn Baldwin const size_t src_len, const uint8_t *aad, const size_t aad_len, 48e7168004SJohn Baldwin const uint8_t *nonce, const uint8_t *key); 49e7168004SJohn Baldwin 50e7168004SJohn Baldwin bool xchacha20_poly1305_decrypt(uint8_t *dst, const uint8_t *src, 51e7168004SJohn Baldwin const size_t src_len, const uint8_t *aad, const size_t aad_len, 52e7168004SJohn Baldwin const uint8_t *nonce, const uint8_t *key); 53e7168004SJohn Baldwin 54e7168004SJohn Baldwin #endif /* !__CRYPTO_CHACHA20_POLY1305_H__ */ 55