wolfSSL 3.11.1 for TLS1.3 beta

Fork of wolfSSL by wolf SSL

Committer:
wolfSSL
Date:
Fri Jun 26 00:39:20 2015 +0000
Revision:
0:d92f9d21154c
wolfSSL 3.6.0

Who changed what in which revision?

UserRevisionLine numberNew contents of line
wolfSSL 0:d92f9d21154c 1 /* chacha20_poly1305.h
wolfSSL 0:d92f9d21154c 2 *
wolfSSL 0:d92f9d21154c 3 * Copyright (C) 2006-2015 wolfSSL Inc.
wolfSSL 0:d92f9d21154c 4 *
wolfSSL 0:d92f9d21154c 5 * This file is part of wolfSSL. (formerly known as CyaSSL)
wolfSSL 0:d92f9d21154c 6 *
wolfSSL 0:d92f9d21154c 7 * wolfSSL is free software; you can redistribute it and/or modify
wolfSSL 0:d92f9d21154c 8 * it under the terms of the GNU General Public License as published by
wolfSSL 0:d92f9d21154c 9 * the Free Software Foundation; either version 2 of the License, or
wolfSSL 0:d92f9d21154c 10 * (at your option) any later version.
wolfSSL 0:d92f9d21154c 11 *
wolfSSL 0:d92f9d21154c 12 * wolfSSL is distributed in the hope that it will be useful,
wolfSSL 0:d92f9d21154c 13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
wolfSSL 0:d92f9d21154c 14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
wolfSSL 0:d92f9d21154c 15 * GNU General Public License for more details.
wolfSSL 0:d92f9d21154c 16 *
wolfSSL 0:d92f9d21154c 17 * You should have received a copy of the GNU General Public License
wolfSSL 0:d92f9d21154c 18 * along with this program; if not, write to the Free Software
wolfSSL 0:d92f9d21154c 19 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
wolfSSL 0:d92f9d21154c 20 */
wolfSSL 0:d92f9d21154c 21
wolfSSL 0:d92f9d21154c 22 /* This implementation of the ChaCha20-Poly1305 AEAD is based on "ChaCha20
wolfSSL 0:d92f9d21154c 23 * and Poly1305 for IETF protocols" (draft-irtf-cfrg-chacha20-poly1305-10):
wolfSSL 0:d92f9d21154c 24 * https://tools.ietf.org/html/draft-irtf-cfrg-chacha20-poly1305-10
wolfSSL 0:d92f9d21154c 25 */
wolfSSL 0:d92f9d21154c 26
wolfSSL 0:d92f9d21154c 27 #ifndef WOLF_CRYPT_CHACHA20_POLY1305_H
wolfSSL 0:d92f9d21154c 28 #define WOLF_CRYPT_CHACHA20_POLY1305_H
wolfSSL 0:d92f9d21154c 29
wolfSSL 0:d92f9d21154c 30 #include <wolfssl/wolfcrypt/types.h>
wolfSSL 0:d92f9d21154c 31
wolfSSL 0:d92f9d21154c 32 #if defined(HAVE_CHACHA) && defined(HAVE_POLY1305)
wolfSSL 0:d92f9d21154c 33
wolfSSL 0:d92f9d21154c 34 #ifdef __cplusplus
wolfSSL 0:d92f9d21154c 35 extern "C" {
wolfSSL 0:d92f9d21154c 36 #endif
wolfSSL 0:d92f9d21154c 37
wolfSSL 0:d92f9d21154c 38 #define CHACHA20_POLY1305_AEAD_KEYSIZE 32
wolfSSL 0:d92f9d21154c 39 #define CHACHA20_POLY1305_AEAD_IV_SIZE 12
wolfSSL 0:d92f9d21154c 40 #define CHACHA20_POLY1305_AEAD_AUTHTAG_SIZE 16
wolfSSL 0:d92f9d21154c 41
wolfSSL 0:d92f9d21154c 42 enum {
wolfSSL 0:d92f9d21154c 43 CHACHA20_POLY_1305_ENC_TYPE = 8 /* cipher unique type */
wolfSSL 0:d92f9d21154c 44 };
wolfSSL 0:d92f9d21154c 45
wolfSSL 0:d92f9d21154c 46 /*
wolfSSL 0:d92f9d21154c 47 * The IV for this implementation is 96 bits to give the most flexibility.
wolfSSL 0:d92f9d21154c 48 *
wolfSSL 0:d92f9d21154c 49 * Some protocols may have unique per-invocation inputs that are not
wolfSSL 0:d92f9d21154c 50 * 96-bit in length. For example, IPsec may specify a 64-bit nonce. In
wolfSSL 0:d92f9d21154c 51 * such a case, it is up to the protocol document to define how to
wolfSSL 0:d92f9d21154c 52 * transform the protocol nonce into a 96-bit nonce, for example by
wolfSSL 0:d92f9d21154c 53 * concatenating a constant value.
wolfSSL 0:d92f9d21154c 54 */
wolfSSL 0:d92f9d21154c 55
wolfSSL 0:d92f9d21154c 56 WOLFSSL_API
wolfSSL 0:d92f9d21154c 57 int wc_ChaCha20Poly1305_Encrypt(
wolfSSL 0:d92f9d21154c 58 const byte inKey[CHACHA20_POLY1305_AEAD_KEYSIZE],
wolfSSL 0:d92f9d21154c 59 const byte inIV[CHACHA20_POLY1305_AEAD_IV_SIZE],
wolfSSL 0:d92f9d21154c 60 const byte* inAAD, const word32 inAADLen,
wolfSSL 0:d92f9d21154c 61 const byte* inPlaintext, const word32 inPlaintextLen,
wolfSSL 0:d92f9d21154c 62 byte* outCiphertext,
wolfSSL 0:d92f9d21154c 63 byte outAuthTag[CHACHA20_POLY1305_AEAD_AUTHTAG_SIZE]);
wolfSSL 0:d92f9d21154c 64
wolfSSL 0:d92f9d21154c 65 WOLFSSL_API
wolfSSL 0:d92f9d21154c 66 int wc_ChaCha20Poly1305_Decrypt(
wolfSSL 0:d92f9d21154c 67 const byte inKey[CHACHA20_POLY1305_AEAD_KEYSIZE],
wolfSSL 0:d92f9d21154c 68 const byte inIV[CHACHA20_POLY1305_AEAD_IV_SIZE],
wolfSSL 0:d92f9d21154c 69 const byte* inAAD, const word32 inAADLen,
wolfSSL 0:d92f9d21154c 70 const byte* inCiphertext, const word32 inCiphertextLen,
wolfSSL 0:d92f9d21154c 71 const byte inAuthTag[CHACHA20_POLY1305_AEAD_AUTHTAG_SIZE],
wolfSSL 0:d92f9d21154c 72 byte* outPlaintext);
wolfSSL 0:d92f9d21154c 73
wolfSSL 0:d92f9d21154c 74 #ifdef __cplusplus
wolfSSL 0:d92f9d21154c 75 } /* extern "C" */
wolfSSL 0:d92f9d21154c 76 #endif
wolfSSL 0:d92f9d21154c 77
wolfSSL 0:d92f9d21154c 78 #endif /* HAVE_CHACHA && HAVE_POLY1305 */
wolfSSL 0:d92f9d21154c 79 #endif /* WOLF_CRYPT_CHACHA20_POLY1305_H */
wolfSSL 0:d92f9d21154c 80