EDGESEC  0.1.0-alpha.0+sha.ca29a8277b72f80785649ea9ef9cd7edf642d939
Secure router - reference implementation
Data Structures | Macros | Enumerations | Functions
cryptou.h File Reference

File containing the definition of the cryptographic utilities. More...

#include <stddef.h>
#include <stdint.h>
#include <sys/types.h>
Include dependency graph for cryptou.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Data Structures

struct  certificate_meta
 

Macros

#define AES_BLOCK_SIZE   16
 
#define IV_SIZE   AES_BLOCK_SIZE
 
#define SALT_SIZE   16
 
#define AES_KEY_SIZE   32
 
#define MAX_KEY_ITERATIONS   1000
 
#define MAX_CERT_FIELD_SIZE   64
 

Enumerations

enum  CRYPTO_KEY_TYPE { CRYPTO_KEY_NONE = 0 , CRYPTO_KEY_RSA , CRYPTO_KEY_EC }
 

Functions

int crypto_geniv (uint8_t *buf, int iv_size)
 Generate IV. More...
 
int crypto_gensalt (uint8_t *buf, int salt_size)
 Generate salt. More...
 
int crypto_genkey (uint8_t *buf, int key_size)
 Generate a random key. More...
 
int crypto_buf2key (const uint8_t *buf, int buf_size, const uint8_t *salt, int salt_size, uint8_t *key, int key_size)
 Transforms a secret buf into a key. More...
 
ssize_t crypto_encrypt (const uint8_t *in, int in_size, const uint8_t *key, const uint8_t *iv, uint8_t *out)
 Encrypts a buffer with AES CBC 256. More...
 
ssize_t crypto_decrypt (uint8_t *in, int in_size, uint8_t *key, uint8_t *iv, uint8_t *out)
 Decrypts a buffer with AES CBC 256. More...
 
int crypto_generate_privkey_str (enum CRYPTO_KEY_TYPE type, int bits, char **key)
 Generate a private RSA key string. More...
 
int crypto_generate_pubkey_str (uint8_t *key, size_t key_size, char **pub)
 Generates a public key string from a private key. More...
 
int crypto_generate_cert_str (struct certificate_meta *meta, uint8_t *key, size_t key_size, char **cert)
 Generates a pair of private key and certificate strings. More...
 
ssize_t crypto_sign_data (uint8_t *key, size_t key_size, uint8_t *in, size_t in_size, uint8_t **out)
 Signs a buffer with a private key string. More...
 

Detailed Description

File containing the definition of the cryptographic utilities.

Author
Alexandru Mereacre
Date
2021

Macro Definition Documentation

◆ AES_BLOCK_SIZE

#define AES_BLOCK_SIZE   16

◆ AES_KEY_SIZE

#define AES_KEY_SIZE   32

◆ IV_SIZE

#define IV_SIZE   AES_BLOCK_SIZE

◆ MAX_CERT_FIELD_SIZE

#define MAX_CERT_FIELD_SIZE   64

◆ MAX_KEY_ITERATIONS

#define MAX_KEY_ITERATIONS   1000

◆ SALT_SIZE

#define SALT_SIZE   16

Enumeration Type Documentation

◆ CRYPTO_KEY_TYPE

Enumerator
CRYPTO_KEY_NONE 
CRYPTO_KEY_RSA 
CRYPTO_KEY_EC 

Function Documentation

◆ crypto_buf2key()

int crypto_buf2key ( const uint8_t *  buf,
int  buf_size,
const uint8_t *  salt,
int  salt_size,
uint8_t *  key,
int  key_size 
)

Transforms a secret buf into a key.

Parameters
bufThe secret buffer
buf_sizeThe secret buf size
saltThe salt buffer
salt_sizeThe salt buffer size
[out]keyThe ouput buffer to store the key.
key_sizeThe size of the key buffer.
Return values
0on success
-1on failure

◆ crypto_decrypt()

ssize_t crypto_decrypt ( uint8_t *  in,
int  in_size,
uint8_t *  key,
uint8_t *  iv,
uint8_t *  out 
)

Decrypts a buffer with AES CBC 256.

Parameters
inThe input buffer
in_sizeThe input buffer size
keyThe 256 bit key
ivThe 128 bit key
outThe output buffer
Returns
The output size, -1 on error

◆ crypto_encrypt()

ssize_t crypto_encrypt ( const uint8_t *  in,
int  in_size,
const uint8_t *  key,
const uint8_t *  iv,
uint8_t *  out 
)

Encrypts a buffer with AES CBC 256.

Parameters
inThe input buffer
in_sizeThe input buffer size
keyThe 256 bit key
ivThe 128 bit key
[out]outThe output buffer
Returns
The output size, -1 on error

◆ crypto_generate_cert_str()

int crypto_generate_cert_str ( struct certificate_meta meta,
uint8_t *  key,
size_t  key_size,
char **  cert 
)

Generates a pair of private key and certificate strings.

Parameters
metaCertificate metadata
keyThe private key buffer
key_sizeThe private key buffer size
certThe certificate string
Returns
int 0 on success, -1 on failure

◆ crypto_generate_privkey_str()

int crypto_generate_privkey_str ( enum CRYPTO_KEY_TYPE  type,
int  bits,
char **  key 
)

Generate a private RSA key string.

Parameters
typeThe key type
bitsNumber of key bits
keyThe output key string
Returns
int 0 on success, -1 on failure

◆ crypto_generate_pubkey_str()

int crypto_generate_pubkey_str ( uint8_t *  key,
size_t  key_size,
char **  pub 
)

Generates a public key string from a private key.

Parameters
keyThe private key buffer
key_sizeThe private key buffer size
pubThe public key string
Returns
int 0 on success, -1 on failure

◆ crypto_geniv()

int crypto_geniv ( uint8_t *  buf,
int  iv_size 
)

Generate IV.

Parameters
bufThe output buffer
iv_sizeThe IV size
Returns
1 on success, 0 on failure

◆ crypto_genkey()

int crypto_genkey ( uint8_t *  buf,
int  key_size 
)

Generate a random key.

Parameters
bufThe output buffer
key_sizeThe key size in bytes
Returns
1 on success, 0 on failure

◆ crypto_gensalt()

int crypto_gensalt ( uint8_t *  buf,
int  salt_size 
)

Generate salt.

Parameters
bufThe output buffer
salt_sizeThe salt size in bytes
Returns
1 on success, 0 on failure

◆ crypto_sign_data()

ssize_t crypto_sign_data ( uint8_t *  key,
size_t  key_size,
uint8_t *  in,
size_t  in_size,
uint8_t **  out 
)

Signs a buffer with a private key string.

Parameters
keyThe private key buffer
key_sizeThe private key buffer size
inThe input buffer
in_sizeThe input buffer size
outThe output signature
Returns
ssize_t the length of the signature, -1 on failure