Loading...
Searching...
No Matches
chacha.h
Go to the documentation of this file.
1/*
2 * SPDX-FileCopyrightText: 2008 D. J. Bernstein (dedicated to the public domain)
3 * SPDX-FileCopyrightText: 2015 René Kijewski <rene.kijewski@fu-berlin.de>
4 * SPDX-License-Identifier: MIT
5 */
6
7#pragma once
8
18
19#include <stdint.h>
20#include <stddef.h>
21
22#include "compiler_hints.h"
23
24#ifdef __cplusplus
25extern "C" {
26#endif
27
32typedef struct {
33 uint32_t state[16];
34 uint8_t rounds;
36
49ACCESS(read_only, 3, 4)
51 unsigned rounds,
52 const uint8_t *key, uint32_t keylen,
53 const uint8_t nonce[8]);
54
68
82void chacha_encrypt_bytes(chacha_ctx *ctx, const uint8_t *m, uint8_t *c);
83
87static inline void chacha_decrypt_bytes(chacha_ctx *ctx, const uint8_t *m,
88 uint8_t *c)
89{
90 chacha_encrypt_bytes(ctx, m, c);
91}
92
111ACCESS(read_only, 1, 2)
112void chacha_prng_seed(const void *data, size_t bytes);
113
122uint32_t chacha_prng_next(void);
123
124#ifdef __cplusplus
125}
126#endif
127
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:87
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.
Common macros and compiler attributes/pragmas configuration.
#define ACCESS(mode, ptr_idx, size_idx)
Emit an attribute (if supported by the compiler) that declares how a function will access its paramet...
A ChaCha cipher stream context.
Definition chacha.h:32
uint8_t rounds
Number of iterations.
Definition chacha.h:34
uint32_t state[16]
The current state of the stream.
Definition chacha.h:33