|
EDGESEC
0.1.0-alpha.0+sha.ca29a8277b72f80785649ea9ef9cd7edf642d939
Secure router - reference implementation
|
File containing the implementation of the cryptographic utilities. More...
#include <stdint.h>#include <openssl/conf.h>#include <openssl/crypto.h>#include <openssl/err.h>#include <openssl/evp.h>#include <openssl/pem.h>#include <openssl/rand.h>#include <openssl/rsa.h>#include <openssl/sha.h>#include <openssl/x509v3.h>#include <openssl/engine.h>#include "cryptou.h"#include "../utils/allocs.h"#include "../utils/log.h"#include "../utils/os.h"Macros | |
| #define | OPENSSL_API_COMPAT 10101 |
| #define | OPENSSL_NO_DEPRECATED 1 |
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... | |
| EVP_PKEY * | crypto_generate_rsa_key (int bits) |
| EVP_PKEY * | crypto_generate_ec_key (void) |
| X509 * | crypto_generate_cert (EVP_PKEY *pkey, struct certificate_meta *meta) |
| EVP_PKEY * | crypto_key2evp (uint8_t *key, size_t key_size) |
| EVP_PKEY * | crypto_priv2pub (EVP_PKEY *key) |
| char * | crypto_get_key_str (bool private, EVP_PKEY *pkey) |
| 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... | |
| int | crypto_verify_data (uint8_t *key, size_t key_size, uint8_t *in, size_t in_size, uint8_t *sig, size_t sig_size) |
| 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 implementation of the cryptographic utilities.
| #define OPENSSL_API_COMPAT 10101 |
| #define OPENSSL_NO_DEPRECATED 1 |
| 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.
| 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. |
| 0 | on success |
| -1 | on failure |
| 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.
| in | The input buffer |
| in_size | The input buffer size |
| key | The 256 bit key |
| iv | The 128 bit key |
| out | The output buffer |
| 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.
| 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 |
| X509* crypto_generate_cert | ( | EVP_PKEY * | pkey, |
| struct certificate_meta * | meta | ||
| ) |
| 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.
| meta | Certificate metadata |
| key | The private key buffer |
| key_size | The private key buffer size |
| cert | The certificate string |
| EVP_PKEY* crypto_generate_ec_key | ( | void | ) |
| int crypto_generate_privkey_str | ( | enum CRYPTO_KEY_TYPE | type, |
| int | bits, | ||
| char ** | key | ||
| ) |
Generate a private RSA key string.
| type | The key type |
| bits | Number of key bits |
| key | The output key string |
| int crypto_generate_pubkey_str | ( | uint8_t * | key, |
| size_t | key_size, | ||
| char ** | pub | ||
| ) |
Generates a public key string from a private key.
| key | The private key buffer |
| key_size | The private key buffer size |
| pub | The public key string |
| EVP_PKEY* crypto_generate_rsa_key | ( | int | bits | ) |
| int crypto_geniv | ( | uint8_t * | buf, |
| int | iv_size | ||
| ) |
Generate IV.
| buf | The output buffer |
| iv_size | The IV size |
| int crypto_genkey | ( | uint8_t * | buf, |
| int | key_size | ||
| ) |
Generate a random key.
| buf | The output buffer |
| key_size | The key size in bytes |
| int crypto_gensalt | ( | uint8_t * | buf, |
| int | salt_size | ||
| ) |
Generate salt.
| buf | The output buffer |
| salt_size | The salt size in bytes |
| char* crypto_get_key_str | ( | bool | private, |
| EVP_PKEY * | pkey | ||
| ) |
| EVP_PKEY* crypto_key2evp | ( | uint8_t * | key, |
| size_t | key_size | ||
| ) |
| EVP_PKEY* crypto_priv2pub | ( | EVP_PKEY * | key | ) |
| 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.
| 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 |
| int crypto_verify_data | ( | uint8_t * | key, |
| size_t | key_size, | ||
| uint8_t * | in, | ||
| size_t | in_size, | ||
| uint8_t * | sig, | ||
| size_t | sig_size | ||
| ) |