forked from danaj/Math-Prime-Util
-
Notifications
You must be signed in to change notification settings - Fork 0
/
chacha.h
29 lines (21 loc) · 847 Bytes
/
chacha.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
#ifndef MPU_CHACHA_H
#define MPU_CHACHA_H
#include "ptypes.h"
/* State info */
#define STATESZ 16 /* words: 4 constant, 8 key, 2 counter, 2 nonce */
#define KEYSZ 40 /* bytes of user supplied key+nonce */
#define CORESZ 64 /* bytes output by core */
#define BUFSZ 16*CORESZ /* bytes we get at a time (1024) */
typedef struct {
uint32_t state[STATESZ];
unsigned char buf[BUFSZ];
uint16_t have;
char goodseed;
} chacha_context_t;
/* API */
extern void chacha_seed(chacha_context_t *cs, uint32_t bytes, const unsigned char* data, char good);
extern void chacha_rand_bytes(chacha_context_t *cs, uint32_t bytes, unsigned char* data);
extern uint32_t chacha_irand32(chacha_context_t *cs);
extern UV chacha_irand64(chacha_context_t *cs);
extern int chacha_selftest(void);
#endif