crypto/crypto_layer.c
struct message *encrypt_message(struct keyset *keys, uint8_t *ptext, uint64_t plen) {
	uint64_t length = 8 + plen + 32; /* message plus hmac */

	struct message *m = alloc_message(length);
	if(m == NULL) {
		return NULL;
	}

	m->length = length;
	m->seq_num = keys->nonce;

	encbe64(keys->nonce, m->message);
	chacha_enc(keys->send_symm_key, 32, keys->nonce, ptext, &m->message[8], plen);
	hmac_sha256(keys->send_hmac_key, 32, m->message, plen + 8, &m->message[8 + plen]);

	return m;
}
/* encrypts the given message using 256-bit chacha */
/* returns NULL in the case of failure */
encrypts the given message using 256-bit chacha
returns NULL in the case of failure
encrypts the given message using 256 - bit chacha returns NULL in the case of failure
struct message *encrypt_message(struct keyset *keys, uint8_t *ptext, uint64_t plen) {
	uint64_t length = 8 + plen + 32; 
	struct message *m = alloc_message(length);
	if(m == NULL) {
		return NULL;
	}
	m->length = length;
	m->seq_num = keys->nonce;
	encbe64(keys->nonce, m->message);
	chacha_enc(keys->send_symm_key, 32, keys->nonce, ptext, &m->message[8], plen);
	hmac_sha256(keys->send_hmac_key, 32, m->message, plen + 8, &m->message[8 + plen]);
	return m;
}
struct message * encrypt_message ( struct keyset * keys , uint8_t * ptext , uint64_t plen ) { uint64_t length = 8 + plen + 32 ; struct message * m = alloc_message ( length ) ; if ( m == NULL ) { return NULL ; } m -> length = length ; m -> seq_num = keys -> nonce ; encbe64 ( keys -> nonce , m -> message ) ; chacha_enc ( keys -> send_symm_key , 32 , keys -> nonce , ptext , & m -> message [ 8 ] , plen ) ; hmac_sha256 ( keys -> send_hmac_key , 32 , m -> message , plen + 8 , & m -> message [ 8 + plen ] ) ; return m ; }
encrypts the given message using 256-bit chacha
returns NULL in the case of failure
encrypts the given message using 256 - bit chacha returns NULL in the case of failure
/* message plus hmac */