Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-18 10:02:16

0001 /* salsa20.h
0002 
0003    The Salsa20 stream cipher.
0004 
0005    Copyright (C) 2012 Simon Josefsson
0006    Copyright (C) 2001 Niels Möller
0007 
0008    This file is part of GNU Nettle.
0009 
0010    GNU Nettle is free software: you can redistribute it and/or
0011    modify it under the terms of either:
0012 
0013      * the GNU Lesser General Public License as published by the Free
0014        Software Foundation; either version 3 of the License, or (at your
0015        option) any later version.
0016 
0017    or
0018 
0019      * the GNU General Public License as published by the Free
0020        Software Foundation; either version 2 of the License, or (at your
0021        option) any later version.
0022 
0023    or both in parallel, as here.
0024 
0025    GNU Nettle is distributed in the hope that it will be useful,
0026    but WITHOUT ANY WARRANTY; without even the implied warranty of
0027    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
0028    General Public License for more details.
0029 
0030    You should have received copies of the GNU General Public License and
0031    the GNU Lesser General Public License along with this program.  If
0032    not, see http://www.gnu.org/licenses/.
0033 */
0034 
0035 #ifndef NETTLE_SALSA20_H_INCLUDED
0036 #define NETTLE_SALSA20_H_INCLUDED
0037 
0038 #include "nettle-types.h"
0039 
0040 #ifdef __cplusplus
0041 extern "C" {
0042 #endif
0043 
0044 /* Name mangling */
0045 #define salsa20_set_key nettle_salsa20_set_key
0046 #define salsa20_128_set_key nettle_salsa20_128_set_key
0047 #define salsa20_256_set_key nettle_salsa20_256_set_key
0048 #define salsa20_set_nonce nettle_salsa20_set_nonce
0049 #define salsa20_crypt nettle_salsa20_crypt
0050 
0051 #define salsa20r12_crypt nettle_salsa20r12_crypt
0052 
0053 /* Alias for backwards compatibility */
0054 #define salsa20_set_iv nettle_salsa20_set_nonce
0055 
0056 /* In octets.*/
0057 #define SALSA20_128_KEY_SIZE 16
0058 #define SALSA20_256_KEY_SIZE 32
0059 #define SALSA20_BLOCK_SIZE 64
0060 #define SALSA20_NONCE_SIZE 8
0061 #define SALSA20_IV_SIZE SALSA20_NONCE_SIZE
0062 
0063 /* Aliases */
0064 #define SALSA20_MIN_KEY_SIZE 16
0065 #define SALSA20_MAX_KEY_SIZE 32
0066 #define SALSA20_KEY_SIZE 32
0067 
0068 #define _SALSA20_INPUT_LENGTH 16
0069 
0070 struct salsa20_ctx
0071 {
0072   /* Indices 1-4 and 11-14 holds the key (two identical copies for the
0073      shorter key size), indices 0, 5, 10, 15 are constant, indices 6, 7
0074      are the IV, and indices 8, 9 are the block counter:
0075 
0076      C K K K
0077      K C I I
0078      B B C K
0079      K K K C
0080   */
0081   uint32_t input[_SALSA20_INPUT_LENGTH];
0082 };
0083 
0084 void
0085 salsa20_128_set_key(struct salsa20_ctx *ctx, const uint8_t *key);
0086 void
0087 salsa20_256_set_key(struct salsa20_ctx *ctx, const uint8_t *key);
0088 
0089 void
0090 salsa20_set_key(struct salsa20_ctx *ctx,
0091         size_t length, const uint8_t *key);
0092 
0093 void
0094 salsa20_set_nonce(struct salsa20_ctx *ctx, const uint8_t *nonce);
0095   
0096 void
0097 salsa20_crypt(struct salsa20_ctx *ctx,
0098           size_t length, uint8_t *dst,
0099           const uint8_t *src);
0100 
0101 void
0102 salsa20r12_crypt(struct salsa20_ctx *ctx,
0103          size_t length, uint8_t *dst,
0104          const uint8_t *src);
0105 
0106 #ifdef __cplusplus
0107 }
0108 #endif
0109 
0110 #endif /* NETTLE_SALSA20_H_INCLUDED */