Back to home page

EIC code displayed by LXR

 
 

    


Warning, file /include/nettle/chacha.h was not indexed or was modified since last indexation (in which case cross-reference links may be missing, inaccurate or erroneous).

0001 /* chacha.h
0002 
0003    The ChaCha stream cipher.
0004 
0005    Copyright (C) 2013 Joachim Strömbergson
0006    Copyright (C) 2012 Simon Josefsson
0007    Copyright (C) 2014 Niels Möller
0008 
0009    This file is part of GNU Nettle.
0010 
0011    GNU Nettle is free software: you can redistribute it and/or
0012    modify it under the terms of either:
0013 
0014      * the GNU Lesser General Public License as published by the Free
0015        Software Foundation; either version 3 of the License, or (at your
0016        option) any later version.
0017 
0018    or
0019 
0020      * the GNU General Public License as published by the Free
0021        Software Foundation; either version 2 of the License, or (at your
0022        option) any later version.
0023 
0024    or both in parallel, as here.
0025 
0026    GNU Nettle is distributed in the hope that it will be useful,
0027    but WITHOUT ANY WARRANTY; without even the implied warranty of
0028    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
0029    General Public License for more details.
0030 
0031    You should have received copies of the GNU General Public License and
0032    the GNU Lesser General Public License along with this program.  If
0033    not, see http://www.gnu.org/licenses/.
0034 */
0035 
0036 #ifndef NETTLE_CHACHA_H_INCLUDED
0037 #define NETTLE_CHACHA_H_INCLUDED
0038 
0039 #include "nettle-types.h"
0040 
0041 #ifdef __cplusplus
0042 extern "C" {
0043 #endif
0044 
0045 /* Name mangling */
0046 #define chacha_set_key nettle_chacha_set_key
0047 #define chacha_set_nonce nettle_chacha_set_nonce
0048 #define chacha_set_nonce96 nettle_chacha_set_nonce96
0049 #define chacha_set_counter nettle_chacha_set_counter
0050 #define chacha_set_counter32 nettle_chacha_set_counter32
0051 #define chacha_crypt nettle_chacha_crypt
0052 #define chacha_crypt32 nettle_chacha_crypt32
0053 
0054 /* Currently, only 256-bit keys are supported. */
0055 #define CHACHA_KEY_SIZE 32
0056 #define CHACHA_BLOCK_SIZE 64
0057 #define CHACHA_NONCE_SIZE 8
0058 #define CHACHA_NONCE96_SIZE 12
0059 #define CHACHA_COUNTER_SIZE 8
0060 #define CHACHA_COUNTER32_SIZE 4
0061 
0062 #define _CHACHA_STATE_LENGTH 16
0063 
0064 struct chacha_ctx
0065 {
0066   /* Indices 0-3 holds a constant (SIGMA or TAU).
0067      Indices 4-11 holds the key.
0068      Indices 12-13 holds the block counter.
0069      Indices 14-15 holds the IV:
0070 
0071      This creates the state matrix:
0072      C C C C
0073      K K K K
0074      K K K K
0075      B B I I
0076   */
0077   uint32_t state[_CHACHA_STATE_LENGTH];
0078 };
0079 
0080 void
0081 chacha_set_key(struct chacha_ctx *ctx, const uint8_t *key);
0082 
0083 void
0084 chacha_set_nonce(struct chacha_ctx *ctx, const uint8_t *nonce);
0085 
0086 void
0087 chacha_set_nonce96(struct chacha_ctx *ctx, const uint8_t *nonce);
0088 
0089 void
0090 chacha_set_counter(struct chacha_ctx *ctx, const uint8_t *counter);
0091 
0092 void
0093 chacha_set_counter32(struct chacha_ctx *ctx, const uint8_t *counter);
0094 
0095 void
0096 chacha_crypt(struct chacha_ctx *ctx, size_t length, 
0097              uint8_t *dst, const uint8_t *src);
0098 
0099 void
0100 chacha_crypt32(struct chacha_ctx *ctx, size_t length,
0101            uint8_t *dst, const uint8_t *src);
0102 
0103 #ifdef __cplusplus
0104 }
0105 #endif
0106 
0107 #endif /* NETTLE_CHACHA_H_INCLUDED */