EDGESEC  0.1.0-alpha.0+sha.ca29a8277b72f80785649ea9ef9cd7edf642d939
Secure router - reference implementation
cryptou.h
Go to the documentation of this file.
1 
11 #ifndef CRYPTOU_H
12 #define CRYPTOU_H
13 
14 #include <stddef.h>
15 #include <stdint.h>
16 #include <sys/types.h>
17 
18 #define AES_BLOCK_SIZE 16
19 #define IV_SIZE AES_BLOCK_SIZE
20 #define SALT_SIZE 16
21 #define AES_KEY_SIZE 32
22 #define MAX_KEY_ITERATIONS 1000
23 
24 #define MAX_CERT_FIELD_SIZE 64
25 
27  long not_before;
28  long not_after;
33 };
34 
36 
44 int crypto_geniv(uint8_t *buf, int iv_size);
45 
53 int crypto_gensalt(uint8_t *buf, int salt_size);
54 
62 int crypto_genkey(uint8_t *buf, int key_size);
63 
76 int crypto_buf2key(const uint8_t *buf, int buf_size, const uint8_t *salt,
77  int salt_size, uint8_t *key, int key_size);
78 
89 ssize_t crypto_encrypt(const uint8_t *in, int in_size, const uint8_t *key,
90  const uint8_t *iv, uint8_t *out);
91 
102 ssize_t crypto_decrypt(uint8_t *in, int in_size, uint8_t *key, uint8_t *iv,
103  uint8_t *out);
104 
113 int crypto_generate_privkey_str(enum CRYPTO_KEY_TYPE type, int bits,
114  char **key);
115 
124 int crypto_generate_pubkey_str(uint8_t *key, size_t key_size, char **pub);
125 
135 int crypto_generate_cert_str(struct certificate_meta *meta, uint8_t *key,
136  size_t key_size, char **cert);
137 
148 ssize_t crypto_sign_data(uint8_t *key, size_t key_size, uint8_t *in,
149  size_t in_size, uint8_t **out);
150 #endif
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.
Definition: cryptou.c:545
int crypto_genkey(uint8_t *buf, int key_size)
Generate a random key.
Definition: cryptou.c:46
CRYPTO_KEY_TYPE
Definition: cryptou.h:35
@ CRYPTO_KEY_EC
Definition: cryptou.h:35
@ CRYPTO_KEY_RSA
Definition: cryptou.h:35
@ CRYPTO_KEY_NONE
Definition: cryptou.h:35
#define MAX_CERT_FIELD_SIZE
Definition: cryptou.h:24
int crypto_gensalt(uint8_t *buf, int salt_size)
Generate salt.
Definition: cryptou.c:42
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.
Definition: cryptou.c:50
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.
Definition: cryptou.c:61
int crypto_geniv(uint8_t *buf, int iv_size)
Generate IV.
Definition: cryptou.c:40
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.
Definition: cryptou.c:440
int crypto_generate_privkey_str(enum CRYPTO_KEY_TYPE type, int bits, char **key)
Generate a private RSA key string.
Definition: cryptou.c:384
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.
Definition: cryptou.c:116
int crypto_generate_pubkey_str(uint8_t *key, size_t key_size, char **pub)
Generates a public key string from a private key.
Definition: cryptou.c:412
bool meta
Definition: log.c:59
Definition: cryptou.h:26
long not_before
Definition: cryptou.h:27
char c[MAX_CERT_FIELD_SIZE]
Definition: cryptou.h:29
char o[MAX_CERT_FIELD_SIZE]
Definition: cryptou.h:30
char ou[MAX_CERT_FIELD_SIZE]
Definition: cryptou.h:31
char cn[MAX_CERT_FIELD_SIZE]
Definition: cryptou.h:32
long not_after
Definition: cryptou.h:28