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
24#pragma once
25
35
36#include <stdint.h>
37#include <stddef.h>
38
39#ifdef __cplusplus
40extern "C" {
41#endif
42
47typedef struct {
48 uint32_t state[16];
49 uint8_t rounds;
51
65 unsigned rounds,
66 const uint8_t *key, uint32_t keylen,
67 const uint8_t nonce[8]);
68
82
96void chacha_encrypt_bytes(chacha_ctx *ctx, const uint8_t *m, uint8_t *c);
97
101static inline void chacha_decrypt_bytes(chacha_ctx *ctx, const uint8_t *m,
102 uint8_t *c)
103{
104 chacha_encrypt_bytes(ctx, m, c);
105}
106
125void chacha_prng_seed(const void *data, size_t bytes);
126
135uint32_t chacha_prng_next(void);
136
137#ifdef __cplusplus
138}
139#endif
140
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:101
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:47
uint8_t rounds
Number of iterations.
Definition chacha.h:49
uint32_t state[16]
The current state of the stream.
Definition chacha.h:48