Libu2f-emu
0.0.0
Universal 2nd Factor (U2F) Emulation C Library
|
#include <fcntl.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sys/stat.h>
#include <sys/types.h>
#include <unistd.h>
#include <openssl/bio.h>
#include <openssl/pem.h>
#include <openssl/rand.h>
#include <openssl/x509.h>
#include <openssl/x509v3.h>
#include "crypto.h"
#include "utils.h"
Functions | |
static size_t | crypto_pem_length (const char *pem) |
Compute the PEM length. More... | |
EC_KEY * | crypto_ec_bytes_to_key (const unsigned char *buffer, long size) |
Get the ec key from ec key bytes. More... | |
size_t | crypto_aes_decrypt (struct crypto_core *crypto_core, const unsigned char *data, int size, unsigned char **buffer) |
Decrypt data using AES. More... | |
size_t | crypto_aes_encrypt (struct crypto_core *crypto_core, const unsigned char *data, int data_len, unsigned char **buffer) |
Encrypt data using AES. More... | |
int | crypto_ec_key_to_bytes (EC_KEY *key, unsigned char **buffer) |
Get the ec key bytes. More... | |
unsigned int | crypto_ec_sign_with_key (EC_KEY *key, const unsigned char *digest, int digest_len, unsigned char **signature) |
Sign a digest with a specific key. More... | |
unsigned int | crypto_ec_sign (struct crypto_core *crypto_core, const unsigned char *digest, int digest_len, unsigned char **signature) |
Sign a digest. More... | |
size_t | crypto_hash (const void *data, size_t data_len, unsigned char **hash) |
Hash data using sha256. More... | |
size_t | crypto_ec_pubkey_to_bytes (const EC_KEY *key, unsigned char **buffer) |
Get the ec key bytes. More... | |
int | crypto_x509_get_bytes (struct crypto_core *crypto_core, unsigned char **buffer) |
Get the x509 certificate bytes. More... | |
static bool | crypto_x509_add_ext (X509 *cert, int nid, const char *value, bool critical) |
Add an extension to a x509 certificate. More... | |
static X509 * | crypto_x509_generate (EC_KEY *key) |
Generate a new x509 certificate from an ec key. More... | |
EC_KEY * | crypto_ec_generate_key (void) |
Generate an ec pair key. More... | |
static X509 * | crypto_x509_from_file (const char *dirpath, const char *filename) |
Get the x509 from file. More... | |
static X509 * | crypto_x509_from_pem (const char *x509_pem) |
Get the x509 from PEM. More... | |
static EC_KEY * | crypto_ec_privkey_from_file (const char *dirpath, const char *filename) |
Get the ec private key from file. More... | |
static EC_KEY * | crypto_ec_privkey_from_pem (const char *private_key_pem) |
Get the ec private key from PEM. More... | |
static bool | crypto_entropy_from_file (const char *dirpath, const char *filename, uint8_t entropy[48]) |
Get the entropy from file. More... | |
EC_KEY * | crypto_ec_pubkey_from_priv (EC_KEY *privkey) |
Get the ec public key from its private key. More... | |
bool | crypto_new (const char *certificate, const char *private_key, const uint8_t entropy[48], struct crypto_core **core_ref) |
Instantiate a new crypto core. More... | |
bool | crypto_new_ephemeral (struct crypto_core **core_ref) |
Instantiate a new ephemeral crypto core. More... | |
bool | crypto_new_from_dir (const char *dirpath, struct crypto_core **core_ref) |
Setup a crypto core from a dir. More... | |
void | crypto_free (struct crypto_core *crypto_core) |
Release the memory allocated by the crypto_core. More... | |
size_t crypto_aes_decrypt | ( | struct crypto_core * | core, |
const unsigned char * | data, | ||
int | size, | ||
unsigned char ** | buffer | ||
) |
Decrypt data using AES.
core | The crypto core. |
data | The data to decrypt. |
size | The data size. |
buffer | The resulting buffer where clear data is put. |
size_t crypto_aes_encrypt | ( | struct crypto_core * | core, |
const unsigned char * | data, | ||
int | data_len, | ||
unsigned char ** | buffer | ||
) |
Encrypt data using AES.
core | The crypto core. |
data | The data to encrypt. |
data_len | The data size. |
buffer | The resulting buffer where cipher data is put. |
EC_KEY* crypto_ec_bytes_to_key | ( | const unsigned char * | buffer, |
long | size | ||
) |
Get the ec key from ec key bytes.
buffer | The buffer containing the ec key bytes. |
size | The size of the buffer. |
EC_KEY* crypto_ec_generate_key | ( | void | ) |
Generate an ec pair key.
int crypto_ec_key_to_bytes | ( | EC_KEY * | key, |
unsigned char ** | buffer | ||
) |
Get the ec key bytes.
key | The ec key. |
buffer | The buffer use to put the bytes |
|
static |
Get the ec private key from file.
dirpath | The path of the directory. |
filename | The filename. |
|
static |
Get the ec private key from PEM.
private_key_pem | The ec private key PEM. |
EC_KEY* crypto_ec_pubkey_from_priv | ( | EC_KEY * | privkey | ) |
Get the ec public key from its private key.
privkey | the ec privkey. |
size_t crypto_ec_pubkey_to_bytes | ( | const EC_KEY * | key, |
unsigned char ** | buffer | ||
) |
Get the ec key bytes.
key | The ec key. |
buffer | The buffer use to put the bytes. |
unsigned int crypto_ec_sign | ( | struct crypto_core * | core, |
const unsigned char * | digest, | ||
int | digest_len, | ||
unsigned char ** | signature | ||
) |
Sign a digest.
core | The crypto core. |
digest | The digest. |
digest_len | The digest length? |
signature | The ref buffer to put the signature. |
unsigned int crypto_ec_sign_with_key | ( | EC_KEY * | key, |
const unsigned char * | digest, | ||
int | digest_len, | ||
unsigned char ** | signature | ||
) |
Sign a digest with a specific key.
key | The ec key. |
digest | The digest. |
digest_len | The digest len. |
signature | The ref buffer to put the signature. |
|
static |
Get the entropy from file.
dirpath | The path of the directory. |
filename | The filename. |
entropy | The entropy to setu. |
void crypto_free | ( | struct crypto_core * | core | ) |
Release the memory allocated by the crypto_core.
core | The crypto core to release. |
size_t crypto_hash | ( | const void * | data, |
size_t | data_len, | ||
unsigned char ** | hash | ||
) |
Hash data using sha256.
data | The data. |
data_len | The data length. |
hash | The ref buffer to put the hash. |
bool crypto_new | ( | const char * | certificate, |
const char * | private_key, | ||
const uint8_t | entropy[48], | ||
struct crypto_core ** | core_ref | ||
) |
Instantiate a new crypto core.
certificate | PEM ec certificate. |
private_key | PEM ec Private key of the certificate. |
entropy | Random bits used in encryption. |
core_ref | The crypto core reference. |
bool crypto_new_ephemeral | ( | struct crypto_core ** | core_ref | ) |
Instantiate a new ephemeral crypto core.
core_ref | The crypto core reference. |
bool crypto_new_from_dir | ( | const char * | dirpath, |
struct crypto_core ** | core_ref | ||
) |
Setup a crypto core from a dir.
dirpath | The path of the setup directory. |
core_ref | The crypto core to setup. |
|
static |
Compute the PEM length.
pem | The PEM. |
|
static |
Add an extension to a x509 certificate.
cert | The cert to add the extension. |
nid | The nid of the extenstion. |
value | The value of the extension. |
critical | The extension critism. |
|
static |
Get the x509 from file.
dirpath | The path of the directory. |
filename | The filename. |
|
static |
Get the x509 from PEM.
x509_pem | The x509 PEM. |
|
static |
Generate a new x509 certificate from an ec key.
key | The ec key. |
int crypto_x509_get_bytes | ( | struct crypto_core * | core, |
unsigned char ** | buffer | ||
) |
Get the x509 certificate bytes.
core | The crypto core. |
buffer | The buffer to put the bytes. |