Xuyi Wang / wolfSSL

Dependents:   OS

Committer:
wolfSSL
Date:
Tue May 02 08:44:47 2017 +0000
Revision:
7:481bce714567
wolfSSL3.10.2

Who changed what in which revision?

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