22 #include <openssl/evp.h>
23 #include <openssl/sha.h>
28 #include "../typedefs.h"
29 #include "../constants.h"
32 #include "../socket.h"
34 const uint8_t ZERO_IV[AES_BYTES] = { 0 };
36 const uint8_t const_seed[] = { 0x00, 0x11, 0x22, 0x33, 0x44, 0x55, 0x66, 0x77, 0x88, 0x99, 0xAA, 0xBB, 0xCC, 0xDD, 0xEE, 0xFF };
42 typedef EVP_CIPHER_CTX AES_KEY_CTX;
62 crypto(uint32_t symsecbits, uint8_t* seed);
63 crypto(uint32_t symsecbits);
67 void gen_rnd(uint8_t* resbuf, uint32_t numbytes);
69 void gen_rnd_uniform(uint8_t* resbuf, uint64_t mod);
70 void gen_rnd_perm(uint32_t* perm, uint32_t neles);
73 void encrypt(uint8_t* resbuf, uint8_t* inbuf, uint32_t ninbytes);
74 void decrypt(uint8_t* resbuf, uint8_t* inbuf, uint32_t ninbytes);
77 void hash(uint8_t* resbuf, uint32_t noutbytes, uint8_t* inbuf, uint32_t ninbytes);
78 void hash_ctr(uint8_t* resbuf, uint32_t noutbytes, uint8_t* inbuf, uint32_t ninbytes, uint32_t ctr);
79 void fixed_key_aes_hash(AES_KEY_CTX* aes_key, uint8_t* resbuf, uint32_t noutbytes, uint8_t* inbuf, uint32_t ninbytes);
80 void fixed_key_aes_hash_ctr(uint8_t* resbuf, uint32_t noutbytes, uint8_t* inbuf, uint32_t ninbytes);
83 void seed_aes_hash(uint8_t* seed, bc_mode mode = ECB,
const uint8_t* iv = ZERO_IV);
84 void seed_aes_enc(uint8_t* seed, bc_mode mode = ECB,
const uint8_t* iv = ZERO_IV);
87 void init_aes_key(AES_KEY_CTX* aes_key, uint8_t* seed, bc_mode mode = ECB,
const uint8_t* iv = ZERO_IV);
88 void init_aes_key(AES_KEY_CTX* aes_key, uint32_t symbits, uint8_t* seed, bc_mode mode = ECB,
const uint8_t* iv = ZERO_IV);
89 uint32_t get_aes_key_bytes();
90 void encrypt(AES_KEY_CTX* enc_key, uint8_t* resbuf, uint8_t* inbuf, uint32_t ninbytes);
91 void decrypt(AES_KEY_CTX* dec_key, uint8_t* resbuf, uint8_t* inbuf, uint32_t ninbytes);
99 uint32_t get_hash_bytes();
102 void init_prf_state(
prf_state_ctx* prf_state, uint8_t* seed);
105 void seed_aes_key(AES_KEY_CTX* aeskey, uint8_t* seed, bc_mode mode = ECB,
const uint8_t* iv = ZERO_IV,
bool encrypt =
true);
106 void seed_aes_key(AES_KEY_CTX* aeskey, uint32_t symseclvl, uint8_t* seed, bc_mode mode = ECB,
const uint8_t* iv = ZERO_IV,
bool encrypt =
true);
107 void init(uint32_t symsecbits, uint8_t* seed);
110 AES_KEY_CTX aes_hash_key;
111 AES_KEY_CTX aes_enc_key;
112 AES_KEY_CTX aes_dec_key;
116 uint8_t* aes_hash_in_buf;
117 uint8_t* aes_hash_out_buf;
118 uint8_t* aes_hash_buf_y1;
119 uint8_t* aes_hash_buf_y2;
121 uint8_t* sha_hash_buf;
123 void (*hash_routine)(uint8_t*, uint32_t, uint8_t*, uint32_t, uint8_t*);
127 void sha1_hash(uint8_t* resbuf, uint32_t noutbytes, uint8_t* inbuf, uint32_t ninbytes, uint8_t* hash_buf);
128 void sha256_hash(uint8_t* resbuf, uint32_t noutbytes, uint8_t* inbuf, uint32_t ninbytes, uint8_t* hash_buf);
129 void sha512_hash(uint8_t* resbuf, uint32_t noutbytes, uint8_t* inbuf, uint32_t ninbytes, uint8_t* hash_buf);
130 void gen_secure_random(uint8_t* dest, uint32_t nbytes);
131 void gen_rnd_bytes(
prf_state_ctx* prf_state, uint8_t* resbuf, uint32_t nbytes);
133 seclvl get_sec_lvl(uint32_t symsecbits);
135 static const uint32_t m_nCodeWordBits = 256;
136 static const uint32_t m_nCodeWordBytes = m_nCodeWordBits / 8;
Definition: pk-crypto.h:30
Class with finite-field-cryptography operations (using the GMP library)
Class with ECC operations.
Definition: typedefs.h:79