#include "vsl_api.h"
#include <stdarg.h>
#include <stdbool.h>
Go to the source code of this file.
Defines | |
#define | RANDDEV "/dev/urandom" |
Random device. | |
Typedefs | |
typedef ssize_t(*) | transmit_fn (vfer_fd, void *, size_t) |
Functions | |
void | aes_ctr (unsigned char *ctr, const unsigned char *key, unsigned char *buf, const size_t len) |
void | ctr_inc (unsigned char *ctr) |
int | gen_key (unsigned char *key) |
uint64_t | htonll (uint64_t val) |
void | init_keys_c (vsl_sock *sock, const unsigned char *key) |
void | init_keys_s (vsl_sock *sock, const unsigned char *key) |
bool | is_blocking (vsl_sock *socket) |
void | md5 (const unsigned char *s1, int l1, const unsigned char *s2, int l2, unsigned char *hash) |
uint64_t | ntohll (uint64_t val) |
unsigned char * | read_objs (unsigned char *src, size_t max,...) |
void | set_blocking (vsl_sock *socket, bool mode) |
void | sha256 (const unsigned char *s1, int l1, const unsigned char *s2, int l2, unsigned char *hash) |
int | transfer (vsl_sock *sock, transmit_fn fn, unsigned char *buf, size_t min, size_t len) |
unsigned char * | write_objs (size_t *total,...) |
void | xor16 (unsigned char *b1, unsigned char *b2) |
Definition in file vsl_util.h.
#define RANDDEV "/dev/urandom" |
typedef ssize_t(*) transmit_fn(vfer_fd, void *, size_t) |
Definition at line 47 of file vsl_util.h.
void aes_ctr | ( | unsigned char * | ctr, | |
const unsigned char * | key, | |||
unsigned char * | buf, | |||
const size_t | len | |||
) |
Encrypts data in AES CTR mode. The counter is modified in place. The first 8 bytes of the counter must contain the nonce and the last 8 bytes should be initialised to zero.
Note that the function cannot be called multiple times without reinitalizing the counter before each invocation.
ctr | counter | |
[in] | key | encryption key, length VSL_ENC_KEYLEN |
buf | buffer to encrypt | |
[in] | len | length of buffer |
Definition at line 344 of file vsl_util.c.
void ctr_inc | ( | unsigned char * | ctr | ) | [inline] |
Increase the counter by one. Uses only the last 8 bytes, aborts in case of an overflow. Works in Little Endian.
ctr | counter to increase |
Definition at line 377 of file vsl_util.c.
int gen_key | ( | unsigned char * | key | ) |
Generate a random shared secret of length VSL_KEYLEN
[out] | key | generated key |
Definition at line 33 of file vsl_util.c.
uint64_t htonll | ( | uint64_t | val | ) | [inline] |
Convert uint64 from host byte order to network byte order.
[in] | val | value to convert |
Definition at line 294 of file vsl_util.c.
void init_keys_c | ( | vsl_sock * | sock, | |
const unsigned char * | key | |||
) |
Initialize session keys (client mode) from a shared secret.
[in] | sock | VSL socket |
[in] | key | shared secret to generate keys from |
Definition at line 63 of file vsl_util.c.
void init_keys_s | ( | vsl_sock * | sock, | |
const unsigned char * | key | |||
) |
Initialize session keys (server mode) from a shared secret.
[in] | sock | VSL socket |
[in] | key | shared secret to generate keys from |
Definition at line 87 of file vsl_util.c.
bool is_blocking | ( | vsl_sock * | socket | ) |
Check whether the underlying vfer fd is blocking
[in] | socket | VSL socket |
Definition at line 144 of file vsl_util.c.
void md5 | ( | const unsigned char * | s1, | |
int | l1, | |||
const unsigned char * | s2, | |||
int | l2, | |||
unsigned char * | hash | |||
) |
Generate a 16 byte MD5 hash of two char arrays
[in] | s1 | first char array |
[in] | l1 | length of first array |
[in] | s2 | second char array |
[in] | l2 | length of second array |
[out] | hash | resulting hash (length 16 bytes) |
Definition at line 112 of file vsl_util.c.
uint64_t ntohll | ( | uint64_t | val | ) | [inline] |
Convert uint64 from host network order to host byte order.
[in] | val | value to convert |
Definition at line 316 of file vsl_util.c.
unsigned char* read_objs | ( | unsigned char * | src, | |
size_t | max, | |||
... | ||||
) |
Decomposes a buffer into a number of separate variables.
The variables have to be given as pairs of a void pointer to the variable and an size_t value describing the length of the variable in bytes. The argument list has to be terminated with a NULL
pointer. For each pair void* dat, size_t len
, the next len bytes of src are copied into dat. After the last object was copied, a pointer to the remainder of src is returned.
Example:
remainder = read_objs(src, (void*) &data1, sizeof(data1), (void*) &data2, sizeof(data2));
[in] | src | source buffer |
[in] | max | length of source buffer |
[out] | ... | list of alternating void* and size_t arguments, terminated by NULL . |
NULL
the length of the varables was bigger than the source buffer Definition at line 259 of file vsl_util.c.
void set_blocking | ( | vsl_sock * | socket, | |
bool | mode | |||
) |
Sets the underlying vfer fd to blocking or nonblocking
[in] | socket | VSL socket |
[in] | mode | whether to block or not |
Definition at line 161 of file vsl_util.c.
void sha256 | ( | const unsigned char * | s1, | |
int | l1, | |||
const unsigned char * | s2, | |||
int | l2, | |||
unsigned char * | hash | |||
) |
Generate a 32 byte SHA256 hash of two char arrays
[in] | s1 | first char array |
[in] | l1 | length of first array |
[in] | s2 | second char array |
[in] | l2 | length of second array |
[out] | hash | resulting hash (length 32 bytes) |
Definition at line 129 of file vsl_util.c.
int transfer | ( | vsl_sock * | sock, | |
transmit_fn | fn, | |||
unsigned char * | buf, | |||
size_t | min, | |||
size_t | len | |||
) |
Transfer's exactly len (streaming socket) or between min and len (datagram socket) bytes using the specified function (either vfer_send() or vfer_recv()).
[in] | sock | socket to use |
[in] | fn | function to use |
buf | buffer to transmit | |
[in] | min | minimum amount to process for datagram sockets |
[in] | len | length of buf |
Definition at line 429 of file vsl_util.c.
unsigned char* write_objs | ( | size_t * | total, | |
... | ||||
) |
Allocates a buffer and writes a sequence of variables into it. The variables have to be given as pairs of a void pointer to the variable and an size_t value describing the length of the variable in bytes. The argument list has to be terminated with a NULL
pointer. The total length of the allocated buffer is written into total.
Example:
buf = write_objs(len, (void*) &data1, sizeof(data1), (void*) &data2, sizeof(data2));
sizeof(data1) + sizeof(data2)
, and writes the objects data1
and data2
into it.
[out] | total | total allocated length |
[in] | ... | list of alternating void* and size_t arguments, terminated by NULL . |
Definition at line 198 of file vsl_util.c.
void xor16 | ( | unsigned char * | b1, | |
unsigned char * | b2 | |||
) | [inline] |
XOR 2 16 byte blocks. Argument 1 is modified in place.
b1 | first block | |
[in] | b2 | second block |
Definition at line 398 of file vsl_util.c.