Loading...
Searching...
No Matches
chacha.h
Go to the documentation of this file.
1/*
2 * Copyright (C) 2008 D. J. Bernstein (dedicated to the public domain)
3 * Copyright (C) 2015 René Kijewski <rene.kijewski@fu-berlin.de>
4 *
5 * Permission is hereby granted, free of charge, to any person obtaining a copy
6 * of this software and associated documentation files (the "Software"), to deal
7 * in the Software without restriction, including without limitation the rights
8 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9 * copies of the Software, and to permit persons to whom the Software is
10 * furnished to do so, subject to the following conditions:
11 *
12 * The above copyright notice and this permission notice shall be included in
13 * all copies or substantial portions of the Software.
14 *
15 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21 * THE SOFTWARE.
22 */
23
34#ifndef CRYPTO_CHACHA_H
35#define CRYPTO_CHACHA_H
36
37#include <stdint.h>
38#include <stddef.h>
39
40#ifdef __cplusplus
41extern "C" {
42#endif
43
48typedef struct {
49 uint32_t state[16];
50 uint8_t rounds;
52
66 unsigned rounds,
67 const uint8_t *key, uint32_t keylen,
68 const uint8_t nonce[8]);
69
83
97void chacha_encrypt_bytes(chacha_ctx *ctx, const uint8_t *m, uint8_t *c);
98
102static inline void chacha_decrypt_bytes(chacha_ctx *ctx, const uint8_t *m,
103 uint8_t *c)
104{
105 chacha_encrypt_bytes(ctx, m, c);
106}
107
126void chacha_prng_seed(const void *data, size_t bytes);
127
136uint32_t chacha_prng_next(void);
137
138#ifdef __cplusplus
139}
140#endif
141
142#endif /* CRYPTO_CHACHA_H */
143
void chacha_keystream_bytes(chacha_ctx *ctx, void *x)
Generate next block in the keystream.
uint32_t chacha_prng_next(void)
Extract a number from the pseudo-random number generator.
static void chacha_decrypt_bytes(chacha_ctx *ctx, const uint8_t *m, uint8_t *c)
Encode or decode a block of data.
Definition chacha.h:102
void chacha_prng_seed(const void *data, size_t bytes)
Seed the pseudo-random number generator.
void chacha_encrypt_bytes(chacha_ctx *ctx, const uint8_t *m, uint8_t *c)
Encode or decode a block of data.
int chacha_init(chacha_ctx *ctx, unsigned rounds, const uint8_t *key, uint32_t keylen, const uint8_t nonce[8])
Initialize a ChaCha context.
A ChaCha cipher stream context.
Definition chacha.h:48
uint8_t rounds
Number of iterations.
Definition chacha.h:50