-
Notifications
You must be signed in to change notification settings - Fork 1
/
rabbit.h
50 lines (44 loc) · 1.58 KB
/
rabbit.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
/* Author: Lucas Clemente Vella
* Source code placed into public domain. */
#pragma once
#include <inttypes.h>
typedef struct
{
uint32_t x[8];
uint32_t c[8];
uint8_t carry;
} rabbit_state;
/** Initialize the Rabbit master state with key.
*
* The state initialized by this function can be used directly in the
* encryption/decryption process, or can be used to generate other encryption
* states based on an Initialization Vector (IV). See function
* rabbit_init_iv().
*
* @param state The uninitialized state.
* @param key 16 bytes buffer of the 128-bit key. The buffer must be aligned
* to at least 4 bytes (depending on the platform it may or may not work with
* unaligned memory).
*/
void rabbit_init_key(rabbit_state *state, const uint8_t *key);
/** Initialize the Rabbit state for encryption/decryption.
*
* The master state initialized in rabbit_init_key() can be reused many
* times to generate different encryption states based on different
* Initialization Vectors (IVs).
*
* Notice: an IV should never be reused.
*
* @param iv_state The output state, to be initialized with the IV.
* @param master The master state, already initialized with the key.
* @param iv 8 bytes buffer containing the IV. Must be 4 byte aligned.
*/
void rabbit_init_iv(rabbit_state *iv_state, const rabbit_state *master,
const uint8_t *iv);
/** Performs one round of the algorithm.
*
* @param state The algorithm state.
* @param stream A 16 byte buffer where the generated stream will be stored.
* Must be 4 byte aligned.
*/
void rabbit_extract(rabbit_state *state, uint8_t *stream);