-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbcrandom.h
38 lines (31 loc) · 1.43 KB
/
bcrandom.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
#pragma once
#include<gcrypt.h>
// XXX I feel like obliv_common.h doesn't belong here
#include<obliv_common.h>
#define BC_MAXBLEN 20 // internal constant (i.e. private)
#define BC_SEEDLEN_DEFAULT (128/8)
#define BC_ALGO_DEFAULT GCRY_CIPHER_AES128
#define BC_SEEDLEN_MAX (256/8)
// Simply applies a block cipher in counter mode on zeroes
typedef struct
{ gcry_cipher_hd_t cipher;
unsigned char zeroes[BC_MAXBLEN], ctr[BC_MAXBLEN];
size_t blen,klen;
int algo;
} BCipherRandomGen;
BCipherRandomGen* newBCipherRandomGen();
BCipherRandomGen* newBCipherRandomGenByKey(const char* key);
BCipherRandomGen* newBCipherRandomGenByAlgoKey(int algo,const char* key);
BCipherRandomGen* copyBCipherRandomGenNoKey(BCipherRandomGen* bc);
void releaseBCipherRandomGen(BCipherRandomGen* gen);
// key is assumed to be gen->klen long
void resetBCipherRandomGen(BCipherRandomGen* gen,const char* key);
void randomizeBuffer(BCipherRandomGen* gen,char* dest,size_t len);
// key is assumed to be BC_SEEDLEN_DEFAULT bytes long
void randomizeBufferByKey(const char* key,char* dest,size_t len);
gcry_mpi_t dhRandomExp(BCipherRandomGen* gen);
unsigned long long bcRandomInt(BCipherRandomGen* gen,unsigned long long max);
void bcRandomShuffle(BCipherRandomGen* gen,unsigned arr[],size_t n);
void bcRandomPermutation(BCipherRandomGen* gen,unsigned arr[],size_t n);
// Weird function being used externally
void setctrFromIntBCipherRandomGen(BCipherRandomGen* gen,uint64_t ctr);