File containing the definition of the cryptographic utilities.
More...
#include <stddef.h>
#include <stdint.h>
#include <sys/types.h>
Go to the source code of this file.
|
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...
|
|
File containing the definition of the cryptographic utilities.
- Author
- Alexandru Mereacre
- Date
- 2021
- Copyright
- SPDX-FileCopyrightText: © 2021 NQMCyber Ltd and edgesec contributors SPDX-License-Identifier: LGPL-3.0-or-later
◆ AES_BLOCK_SIZE
#define AES_BLOCK_SIZE 16 |
◆ AES_KEY_SIZE
◆ IV_SIZE
◆ MAX_CERT_FIELD_SIZE
#define MAX_CERT_FIELD_SIZE 64 |
◆ MAX_KEY_ITERATIONS
#define MAX_KEY_ITERATIONS 1000 |
◆ SALT_SIZE
◆ CRYPTO_KEY_TYPE
Enumerator |
---|
CRYPTO_KEY_NONE | |
CRYPTO_KEY_RSA | |
CRYPTO_KEY_EC | |
◆ 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
-
| buf | The secret buffer |
| buf_size | The secret buf size |
| salt | The salt buffer |
| salt_size | The salt buffer size |
[out] | key | The ouput buffer to store the key. |
| key_size | The size of the key buffer. |
- Return values
-
◆ 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
-
in | The input buffer |
in_size | The input buffer size |
key | The 256 bit key |
iv | The 128 bit key |
out | The 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
-
| in | The input buffer |
| in_size | The input buffer size |
| key | The 256 bit key |
| iv | The 128 bit key |
[out] | out | The 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
-
meta | Certificate metadata |
key | The private key buffer |
key_size | The private key buffer size |
cert | The 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
-
type | The key type |
bits | Number of key bits |
key | The 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
-
key | The private key buffer |
key_size | The private key buffer size |
pub | The 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
-
buf | The output buffer |
iv_size | The 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
-
buf | The output buffer |
key_size | The 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
-
buf | The output buffer |
salt_size | The 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
-
key | The private key buffer |
key_size | The private key buffer size |
in | The input buffer |
in_size | The input buffer size |
out | The output signature |
- Returns
- ssize_t the length of the signature, -1 on failure