This is a fork of the mbed port of axTLS

Dependents:   TLS_axTLS-Example HTTPSClientExample

Embed: (wiki syntax)

« Back to documentation index

crypto.h File Reference

crypto.h File Reference

Go to the source code of this file.

Functions

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.
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.
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.
void AES_convert_key (AES_CTX *ctx)
 Change a key for decryption.
void RC4_setup (RC4_CTX *s, const uint8_t *key, int length)
 An implementation of the RC4/ARC4 algorithm.
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).
void SHA1_Init (SHA1_CTX *)
 Initialize the SHA1 context.
void SHA1_Update (SHA1_CTX *, const uint8_t *msg, int len)
 Accepts an array of octets as the next portion of the message.
void SHA1_Final (uint8_t *digest, SHA1_CTX *)
 Return the 160-bit message digest into the user's array.
EXP_FUNC void STDCALL MD5_Init (MD5_CTX *)
 MD5 initialization - begins an MD5 operation, writing a new ctx.
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.
EXP_FUNC void STDCALL MD5_Final (uint8_t *digest, MD5_CTX *)
 Return the 128-bit message digest into the user's array.
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.
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.
void RSA_free (RSA_CTX *ctx)
 Free up any RSA context resources.
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.
bigintRSA_private (const RSA_CTX *c, bigint *bi_msg)
 Performs m = c^d mod n.
bigintRSA_public (const RSA_CTX *c, bigint *bi_msg)
 Performs c = m^e mod n.
int RSA_encrypt (const RSA_CTX *ctx, const uint8_t *in_data, uint16_t in_len, uint8_t *out_data, int is_signing)
 Use PKCS1.5 for encryption/signing.
void RSA_print (const RSA_CTX *ctx)
 Used for diagnostics.
EXP_FUNC void STDCALL RNG_initialize (void)
 Initialise the Random Number Generator engine.
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.
EXP_FUNC void STDCALL RNG_terminate (void)
 Terminate the RNG engine.
EXP_FUNC void STDCALL get_random (int num_rand_bytes, uint8_t *rand_data)
 Set a series of bytes with a random number.
void get_random_NZ (int num_rand_bytes, uint8_t *rand_data)
 Set a series of bytes with a random number.

Detailed Description

Definition in file crypto.h.


Function Documentation

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 at line 312 of file aes.c.

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 at line 273 of file aes.c.

void AES_convert_key ( AES_CTX *  ctx )

Change a key for decryption.

Definition at line 254 of file aes.c.

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 at line 179 of file aes.c.

EXP_FUNC void STDCALL get_random ( int  num_rand_bytes,
uint8_t *  rand_data 
)

Set a series of bytes with a random number.

Individual bytes can be 0

Definition at line 164 of file crypto_misc.c.

void get_random_NZ ( int  num_rand_bytes,
uint8_t *  rand_data 
)

Set a series of bytes with a random number.

Individual bytes are not zero.

Definition at line 214 of file crypto_misc.c.

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.

Perform HMAC-MD5 NOTE: does not handle keys larger than the block size.

Definition at line 45 of file hmac.c.

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 at line 78 of file hmac.c.

EXP_FUNC void STDCALL MD5_Final ( uint8_t *  digest,
MD5_CTX *   
)

Return the 128-bit message digest into the user's array.

Definition at line 157 of file md5.c.

EXP_FUNC void STDCALL MD5_Init ( MD5_CTX *   )

MD5 initialization - begins an MD5 operation, writing a new ctx.

Definition at line 106 of file md5.c.

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 at line 121 of file md5.c.

void RC4_crypt ( RC4_CTX *  ctx,
const uint8_t *  msg,
uint8_t *  out,
int  length 
)

Perform the encrypt/decrypt operation (can use it for either since this is a stream cipher).

NOTE: *msg and *out must be the same pointer (performance tweak)

Definition at line 72 of file rc4.c.

void RC4_setup ( RC4_CTX *  ctx,
const uint8_t *  key,
int  length 
)

An implementation of the RC4/ARC4 algorithm.

Originally written by Christophe Devine. Get ready for an encrypt/decrypt operation

Definition at line 43 of file rc4.c.

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 at line 139 of file crypto_misc.c.

EXP_FUNC void STDCALL RNG_initialize ( void   )

Initialise the Random Number Generator engine.

  • On Win32 use the platform SDK's crypto engine.
  • On Linux use /dev/urandom
  • If none of these work then use a custom RNG.

Definition at line 109 of file crypto_misc.c.

EXP_FUNC void STDCALL RNG_terminate ( void   )

Terminate the RNG engine.

Definition at line 152 of file crypto_misc.c.

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.

Parameters:
ctx[in] The context
in_data[in] The data to encrypt (must be < modulus size-11)
out_data[out] The encrypted data.
is_decryption[in] Decryption or verify operation.
Returns:
The number of bytes that were originally encrypted. -1 on error.
See also:
http://www.rsasecurity.com/rsalabs/node.asp?id=2125

Definition at line 143 of file rsa.c.

int RSA_encrypt ( const RSA_CTX *  ctx,
const uint8_t *  in_data,
uint16_t  in_len,
uint8_t *  out_data,
int  is_signing 
)

Use PKCS1.5 for encryption/signing.

see http://www.rsasecurity.com/rsalabs/node.asp?id=2125

Definition at line 235 of file rsa.c.

void RSA_free ( RSA_CTX *  ctx )

Free up any RSA context resources.

Definition at line 102 of file rsa.c.

void RSA_print ( const RSA_CTX *  ctx )

Used for diagnostics.

Definition at line 208 of file rsa.c.

bigint* RSA_private ( const RSA_CTX *  c,
bigint bi_msg 
)

Performs m = c^d mod n.

Definition at line 192 of file rsa.c.

bigint* RSA_public ( const RSA_CTX *  c,
bigint bi_msg 
)

Performs c = m^e mod n.

Definition at line 225 of file rsa.c.

void SHA1_Final ( uint8_t *  digest,
SHA1_CTX *   
)

Return the 160-bit message digest into the user's array.

Definition at line 88 of file sha1.c.

void SHA1_Init ( SHA1_CTX *   )

Initialize the SHA1 context.

Definition at line 53 of file sha1.c.

void SHA1_Update ( SHA1_CTX *  ,
const uint8_t *  msg,
int  len 
)

Accepts an array of octets as the next portion of the message.

Definition at line 68 of file sha1.c.