wolfSSL SSL/TLS library, support up to TLS1.3

Dependents:   CyaSSL-Twitter-OAuth4Tw Example-client-tls-cert TwitterReader TweetTest ... more

Committer:
wolfSSL
Date:
Tue Aug 22 10:48:22 2017 +0000
Revision:
13:f67a6c6013ca
Parent:
4:1b0d80432c79
wolfSSL3.12.0 with TLS1.3

Who changed what in which revision?

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