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/chacha.h@16:048e5e270a58, 2019-11-19 (annotated)
- Committer:
- sPymbed
- Date:
- Tue Nov 19 14:32:16 2019 +0000
- Revision:
- 16:048e5e270a58
- Parent:
- 15:117db924cf7c
working ssl
Who changed what in which revision?
| User | Revision | Line number | New contents of line | 
|---|---|---|---|
| wolfSSL | 15:117db924cf7c | 1 | /* chacha.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 | \file wolfssl/wolfcrypt/chacha.h | 
| wolfSSL | 15:117db924cf7c | 24 | */ | 
| wolfSSL | 15:117db924cf7c | 25 | |
| wolfSSL | 15:117db924cf7c | 26 | |
| wolfSSL | 15:117db924cf7c | 27 | #ifndef WOLF_CRYPT_CHACHA_H | 
| wolfSSL | 15:117db924cf7c | 28 | #define WOLF_CRYPT_CHACHA_H | 
| wolfSSL | 15:117db924cf7c | 29 | |
| wolfSSL | 15:117db924cf7c | 30 | #include <wolfssl/wolfcrypt/types.h> | 
| wolfSSL | 15:117db924cf7c | 31 | |
| wolfSSL | 15:117db924cf7c | 32 | #ifdef HAVE_CHACHA | 
| wolfSSL | 15:117db924cf7c | 33 | |
| wolfSSL | 15:117db924cf7c | 34 | #ifdef __cplusplus | 
| wolfSSL | 15:117db924cf7c | 35 | extern "C" { | 
| wolfSSL | 15:117db924cf7c | 36 | #endif | 
| wolfSSL | 15:117db924cf7c | 37 | |
| wolfSSL | 15:117db924cf7c | 38 | /* Size of the IV */ | 
| wolfSSL | 15:117db924cf7c | 39 | #define CHACHA_IV_WORDS 3 | 
| wolfSSL | 15:117db924cf7c | 40 | #define CHACHA_IV_BYTES (CHACHA_IV_WORDS * sizeof(word32)) | 
| wolfSSL | 15:117db924cf7c | 41 | |
| wolfSSL | 15:117db924cf7c | 42 | /* Size of ChaCha chunks */ | 
| wolfSSL | 15:117db924cf7c | 43 | #define CHACHA_CHUNK_WORDS 16 | 
| wolfSSL | 15:117db924cf7c | 44 | #define CHACHA_CHUNK_BYTES (CHACHA_CHUNK_WORDS * sizeof(word32)) | 
| wolfSSL | 15:117db924cf7c | 45 | |
| wolfSSL | 15:117db924cf7c | 46 | #ifdef WOLFSSL_X86_64_BUILD | 
| wolfSSL | 15:117db924cf7c | 47 | #if defined(USE_INTEL_SPEEDUP) && !defined(NO_CHACHA_ASM) | 
| wolfSSL | 15:117db924cf7c | 48 | #define USE_INTEL_CHACHA_SPEEDUP | 
| wolfSSL | 15:117db924cf7c | 49 | #define HAVE_INTEL_AVX1 | 
| wolfSSL | 15:117db924cf7c | 50 | #endif | 
| wolfSSL | 15:117db924cf7c | 51 | #endif | 
| wolfSSL | 15:117db924cf7c | 52 | |
| wolfSSL | 15:117db924cf7c | 53 | enum { | 
| wolfSSL | 15:117db924cf7c | 54 | CHACHA_ENC_TYPE = WC_CIPHER_CHACHA, /* cipher unique type */ | 
| wolfSSL | 15:117db924cf7c | 55 | CHACHA_MAX_KEY_SZ = 32, | 
| wolfSSL | 15:117db924cf7c | 56 | }; | 
| wolfSSL | 15:117db924cf7c | 57 | |
| wolfSSL | 15:117db924cf7c | 58 | typedef struct ChaCha { | 
| wolfSSL | 15:117db924cf7c | 59 | word32 X[CHACHA_CHUNK_WORDS]; /* state of cipher */ | 
| wolfSSL | 15:117db924cf7c | 60 | #ifdef HAVE_INTEL_AVX1 | 
| wolfSSL | 15:117db924cf7c | 61 | /* vpshufd reads 16 bytes but we only use bottom 4. */ | 
| wolfSSL | 15:117db924cf7c | 62 | byte extra[12]; | 
| wolfSSL | 15:117db924cf7c | 63 | #endif | 
| wolfSSL | 15:117db924cf7c | 64 | } ChaCha; | 
| wolfSSL | 15:117db924cf7c | 65 | |
| wolfSSL | 15:117db924cf7c | 66 | /** | 
| wolfSSL | 15:117db924cf7c | 67 | * IV(nonce) changes with each record | 
| wolfSSL | 15:117db924cf7c | 68 | * counter is for what value the block counter should start ... usually 0 | 
| wolfSSL | 15:117db924cf7c | 69 | */ | 
| wolfSSL | 15:117db924cf7c | 70 | WOLFSSL_API int wc_Chacha_SetIV(ChaCha* ctx, const byte* inIv, word32 counter); | 
| wolfSSL | 15:117db924cf7c | 71 | |
| wolfSSL | 15:117db924cf7c | 72 | WOLFSSL_API int wc_Chacha_Process(ChaCha* ctx, byte* cipher, const byte* plain, | 
| wolfSSL | 15:117db924cf7c | 73 | word32 msglen); | 
| wolfSSL | 15:117db924cf7c | 74 | WOLFSSL_API int wc_Chacha_SetKey(ChaCha* ctx, const byte* key, word32 keySz); | 
| wolfSSL | 15:117db924cf7c | 75 | |
| wolfSSL | 15:117db924cf7c | 76 | #ifdef __cplusplus | 
| wolfSSL | 15:117db924cf7c | 77 | } /* extern "C" */ | 
| wolfSSL | 15:117db924cf7c | 78 | #endif | 
| wolfSSL | 15:117db924cf7c | 79 | |
| wolfSSL | 15:117db924cf7c | 80 | #endif /* HAVE_CHACHA */ | 
| wolfSSL | 15:117db924cf7c | 81 | #endif /* WOLF_CRYPT_CHACHA_H */ | 
| wolfSSL | 15:117db924cf7c | 82 | |
| wolfSSL | 15:117db924cf7c | 83 |