35 #ifndef HEADER_CRYPTO_H 36 #define HEADER_CRYPTO_H 43 #include "bigint_impl.h" 47 #if defined(CONFIG_SSL_FULL_MODE) 48 #define CONFIG_SSL_ENABLE_CLIENT 49 #define CONFIG_SSL_CERT_VERIFICATION 50 #elif defined(CONFIG_SSL_ENABLE_CLIENT) 51 #define CONFIG_SSL_CERT_VERIFICATION 58 #define AES_MAXROUNDS 14 59 #define AES_BLOCKSIZE 16 60 #define AES_IV_SIZE 16 66 uint32_t ks[(AES_MAXROUNDS+1)*8];
67 uint8_t iv[AES_IV_SIZE];
77 const uint8_t *iv, AES_MODE mode);
79 uint8_t *out,
int length);
98 #define SHA256_SIZE 32 112 uint32_t Intermediate_Hash[SHA1_SIZE/4];
114 uint32_t Length_High;
115 uint16_t Message_Block_Index;
116 uint8_t Message_Block[64];
131 unsigned char cksum[16];
132 unsigned char state[48];
133 unsigned char buffer[16];
137 EXP_FUNC
void STDCALL MD2_Init(
MD2_CTX *ctx);
138 EXP_FUNC
void STDCALL MD2_Update(
MD2_CTX *ctx,
const uint8_t *input,
int ilen);
139 EXP_FUNC
void STDCALL MD2_Final(uint8_t *digest,
MD2_CTX *ctx);
161 void hmac_md5(
const uint8_t *msg,
int length,
const uint8_t *key,
162 int key_len, uint8_t *digest);
163 void hmac_sha1(
const uint8_t *msg,
int length,
const uint8_t *key,
164 int key_len, uint8_t *digest);
175 #ifdef CONFIG_BIGINT_CRT 187 const uint8_t *modulus,
int mod_len,
188 const uint8_t *pub_exp,
int pub_len,
189 const uint8_t *priv_exp,
int priv_len
190 #ifdef CONFIG_BIGINT_CRT
191 ,
const uint8_t *p,
int p_len,
192 const uint8_t *q,
int q_len,
193 const uint8_t *dP,
int dP_len,
194 const uint8_t *dQ,
int dQ_len,
195 const uint8_t *qInv,
int qInv_len
198 void RSA_pub_key_new(
RSA_CTX **rsa_ctx,
199 const uint8_t *modulus,
int mod_len,
200 const uint8_t *pub_exp,
int pub_len);
205 #if defined(CONFIG_SSL_CERT_VERIFICATION) || defined(CONFIG_SSL_GENERATE_X509_CERT) 206 bigint *RSA_sign_verify(
BI_CTX *ctx,
const uint8_t *sig,
int sig_len,
209 int RSA_encrypt(
const RSA_CTX *ctx,
const uint8_t *in_data, uint16_t in_len,
210 uint8_t *out_data,
int is_signing);
211 void RSA_print(
const RSA_CTX *ctx);
218 EXP_FUNC
void STDCALL
RNG_custom_init(
const uint8_t *seed_buf,
int size);
220 EXP_FUNC
void STDCALL
get_random(
int num_rand_bytes, uint8_t *rand_data);
void SHA1_Final(uint8_t *digest, SHA1_CTX *)
Return the 160-bit message digest into the user's array.
Definition: sha1.c:88
EXP_FUNC void STDCALL MD5_Update(MD5_CTX *, const uint8_t *msg, int len)
Accepts an array of octets as the next portion of the message.
Definition: md5.c:121
EXP_FUNC void STDCALL get_random(int num_rand_bytes, uint8_t *rand_data)
Set a series of bytes with a random number.
Definition: crypto_misc.c:192
EXP_FUNC void STDCALL MD5_Init(MD5_CTX *)
MD5 initialization - begins an MD5 operation, writing a new ctx.
Definition: md5.c:106
void get_random_NZ(int num_rand_bytes, uint8_t *rand_data)
Set a series of bytes with a random number.
Definition: crypto_misc.c:239
void RC4_setup(RC4_CTX *s, const uint8_t *key, int length)
An implementation of the RC4/ARC4 algorithm.
Definition: rc4.c:43
void RSA_free(RSA_CTX *ctx)
Free up any RSA context resources.
Definition: rsa.c:102
EXP_FUNC void STDCALL RNG_terminate(void)
Terminate the RNG engine.
Definition: crypto_misc.c:180
int RSA_decrypt(const RSA_CTX *ctx, const uint8_t *in_data, uint8_t *out_data, int is_decryption)
Use PKCS1.5 for decryption/verification.
Definition: rsa.c:143
void hmac_sha1(const uint8_t *msg, int length, const uint8_t *key, int key_len, uint8_t *digest)
Perform HMAC-SHA1 NOTE: does not handle keys larger than the block size.
Definition: hmac.c:78
void hmac_md5(const uint8_t *msg, int length, const uint8_t *key, int key_len, uint8_t *digest)
HMAC implementation - This code was originally taken from RFC2104 See http://www.ietf.org/rfc/rfc2104.txt and http://www.faqs.org/rfcs/rfc2202.html.
Definition: hmac.c:45
void SHA1_Init(SHA1_CTX *)
Initialize the SHA1 context.
Definition: sha1.c:53
bigint * RSA_private(const RSA_CTX *c, bigint *bi_msg)
Performs m = c^d mod n.
Definition: rsa.c:192
void AES_cbc_encrypt(AES_CTX *ctx, const uint8_t *msg, uint8_t *out, int length)
Encrypt a byte sequence (with a block size 16) using the AES cipher.
Definition: aes.c:284
EXP_FUNC void STDCALL MD5_Final(uint8_t *digest, MD5_CTX *)
Return the 128-bit message digest into the user's array.
Definition: md5.c:157
void AES_cbc_decrypt(AES_CTX *ks, const uint8_t *in, uint8_t *out, int length)
Decrypt a byte sequence (with a block size 16) using the AES cipher.
Definition: aes.c:323
void RC4_crypt(RC4_CTX *s, const uint8_t *msg, uint8_t *data, int length)
Perform the encrypt/decrypt operation (can use it for either since this is a stream cipher)...
Definition: rc4.c:72
void AES_set_key(AES_CTX *ctx, const uint8_t *key, const uint8_t *iv, AES_MODE mode)
Set up AES with the key/iv and cipher size.
Definition: aes.c:190
EXP_FUNC void STDCALL RNG_initialize(void)
Initialise the Random Number Generator engine.
Definition: crypto_misc.c:134
EXP_FUNC void STDCALL RNG_custom_init(const uint8_t *seed_buf, int size)
If no /dev/urandom, then initialise the RNG with something interesting.
Definition: crypto_misc.c:164
void AES_convert_key(AES_CTX *ctx)
Change a key for decryption.
Definition: aes.c:265
A big integer basic object.
Definition: bigint_impl.h:83
void SHA1_Update(SHA1_CTX *, const uint8_t *msg, int len)
Accepts an array of octets as the next portion of the message.
Definition: sha1.c:68
void RSA_priv_key_new(RSA_CTX **rsa_ctx, const uint8_t *modulus, int mod_len, const uint8_t *pub_exp, int pub_len, const uint8_t *priv_exp, int priv_len)
Implements the RSA public encryption algorithm.
Definition: rsa.c:43
Maintains the state of the cache, and a number of variables used in reduction.
Definition: bigint_impl.h:98