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