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 
19 #include <stdint.h>
20 #include <stddef.h>
21 
22 #ifdef __cplusplus
23 extern "C" {
24 #endif
25 
30 typedef struct {
31  uint32_t state[16];
32  uint8_t rounds;
33 } chacha_ctx;
34 
48  unsigned rounds,
49  const uint8_t *key, uint32_t keylen,
50  const uint8_t nonce[8]);
51 
64 void chacha_keystream_bytes(chacha_ctx *ctx, void *x);
65 
79 void chacha_encrypt_bytes(chacha_ctx *ctx, const uint8_t *m, uint8_t *c);
80 
84 static inline void chacha_decrypt_bytes(chacha_ctx *ctx, const uint8_t *m,
85  uint8_t *c)
86 {
87  chacha_encrypt_bytes(ctx, m, c);
88 }
89 
108 void chacha_prng_seed(const void *data, size_t bytes);
109 
118 uint32_t chacha_prng_next(void);
119 
120 #ifdef __cplusplus
121 }
122 #endif
123 
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:84
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:30
uint8_t rounds
Number of iterations.
Definition: chacha.h:32