source: azure_iot_hub_f767zi/trunk/wolfssl-4.4.0/wolfssl/wolfcrypt/chacha.h@ 457

Last change on this file since 457 was 457, checked in by coas-nagasima, 4 years ago

ファイルを追加

  • Property svn:eol-style set to native
  • Property svn:mime-type set to text/x-chdr;charset=UTF-8
File size: 2.3 KB
Line 
1/* chacha.h
2 *
3 * Copyright (C) 2006-2020 wolfSSL Inc.
4 *
5 * This file is part of wolfSSL.
6 *
7 * wolfSSL is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 2 of the License, or
10 * (at your option) any later version.
11 *
12 * wolfSSL is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, write to the Free Software
19 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1335, USA
20 */
21
22/*!
23 \file wolfssl/wolfcrypt/chacha.h
24*/
25
26
27#ifndef WOLF_CRYPT_CHACHA_H
28#define WOLF_CRYPT_CHACHA_H
29
30#include <wolfssl/wolfcrypt/types.h>
31
32#ifdef HAVE_CHACHA
33
34#ifdef __cplusplus
35 extern "C" {
36#endif
37
38/* Size of the IV */
39#define CHACHA_IV_WORDS 3
40#define CHACHA_IV_BYTES (CHACHA_IV_WORDS * sizeof(word32))
41
42/* Size of ChaCha chunks */
43#define CHACHA_CHUNK_WORDS 16
44#define CHACHA_CHUNK_BYTES (CHACHA_CHUNK_WORDS * sizeof(word32))
45
46#ifdef WOLFSSL_X86_64_BUILD
47#if defined(USE_INTEL_SPEEDUP) && !defined(NO_CHACHA_ASM)
48 #define USE_INTEL_CHACHA_SPEEDUP
49 #define HAVE_INTEL_AVX1
50#endif
51#endif
52
53enum {
54 CHACHA_ENC_TYPE = WC_CIPHER_CHACHA, /* cipher unique type */
55 CHACHA_MAX_KEY_SZ = 32,
56};
57
58typedef struct ChaCha {
59 word32 X[CHACHA_CHUNK_WORDS]; /* state of cipher */
60 word32 left; /* number of bytes leftover */
61#ifdef HAVE_INTEL_AVX1
62 /* vpshufd reads 16 bytes but we only use bottom 4. */
63 byte extra[12];
64#endif
65} ChaCha;
66
67/**
68 * IV(nonce) changes with each record
69 * counter is for what value the block counter should start ... usually 0
70 */
71WOLFSSL_API int wc_Chacha_SetIV(ChaCha* ctx, const byte* inIv, word32 counter);
72
73WOLFSSL_API int wc_Chacha_Process(ChaCha* ctx, byte* cipher, const byte* plain,
74 word32 msglen);
75WOLFSSL_API int wc_Chacha_SetKey(ChaCha* ctx, const byte* key, word32 keySz);
76
77#ifdef __cplusplus
78 } /* extern "C" */
79#endif
80
81#endif /* HAVE_CHACHA */
82#endif /* WOLF_CRYPT_CHACHA_H */
83
Note: See TracBrowser for help on using the repository browser.