ssh lib

Dependents:   OS

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers chacha.h Source File

chacha.h

00001 /* chacha.h
00002  *
00003  * Copyright (C) 2006-2017 wolfSSL Inc.
00004  *
00005  * This file is part of wolfSSL.
00006  *
00007  * wolfSSL is free software; you can redistribute it and/or modify
00008  * it under the terms of the GNU General Public License as published by
00009  * the Free Software Foundation; either version 2 of the License, or
00010  * (at your option) any later version.
00011  *
00012  * wolfSSL is distributed in the hope that it will be useful,
00013  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00014  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00015  * GNU General Public License for more details.
00016  *
00017  * You should have received a copy of the GNU General Public License
00018  * along with this program; if not, write to the Free Software
00019  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1335, USA
00020  */
00021 
00022 /*!
00023     \file wolfssl/wolfcrypt/chacha.h
00024 */
00025 
00026 
00027 #ifndef WOLF_CRYPT_CHACHA_H
00028 #define WOLF_CRYPT_CHACHA_H
00029 
00030 #include <wolfcrypt/types.h>
00031 
00032 #ifdef HAVE_CHACHA
00033 
00034 #ifdef __cplusplus
00035     extern "C" {
00036 #endif
00037 
00038 /* Size of the IV */
00039 #define CHACHA_IV_WORDS    3
00040 #define CHACHA_IV_BYTES    (CHACHA_IV_WORDS * sizeof(word32))
00041 
00042 /* Size of ChaCha chunks */
00043 #define CHACHA_CHUNK_WORDS 16
00044 #define CHACHA_CHUNK_BYTES (CHACHA_CHUNK_WORDS * sizeof(word32))
00045 
00046 #ifdef WOLFSSL_X86_64_BUILD
00047 #if defined(USE_INTEL_SPEEDUP) && !defined(NO_CHACHA_ASM)
00048     #define USE_INTEL_CHACHA_SPEEDUP
00049     #define HAVE_INTEL_AVX1
00050 #endif
00051 #endif
00052 
00053 enum {
00054     CHACHA_ENC_TYPE = WC_CIPHER_CHACHA,    /* cipher unique type */
00055     CHACHA_MAX_KEY_SZ = 32,
00056 };
00057 
00058 typedef struct ChaCha {
00059     word32 X[CHACHA_CHUNK_WORDS];           /* state of cipher */
00060 #ifdef HAVE_INTEL_AVX1
00061     /* vpshufd reads 16 bytes but we only use bottom 4. */
00062     byte extra[12];
00063 #endif
00064 } ChaCha;
00065 
00066 /**
00067   * IV(nonce) changes with each record
00068   * counter is for what value the block counter should start ... usually 0
00069   */
00070 WOLFSSL_API int wc_Chacha_SetIV(ChaCha* ctx, const byte* inIv, word32 counter);
00071 
00072 WOLFSSL_API int wc_Chacha_Process(ChaCha* ctx, byte* cipher, const byte* plain,
00073                               word32 msglen);
00074 WOLFSSL_API int wc_Chacha_SetKey(ChaCha* ctx, const byte* key, word32 keySz);
00075 
00076 #ifdef __cplusplus
00077     } /* extern "C" */
00078 #endif
00079 
00080 #endif /* HAVE_CHACHA */
00081 #endif /* WOLF_CRYPT_CHACHA_H */
00082 
00083