crypto/crypto_layer.c
int decrypt_message(struct keyset *keys, struct message *m, uint8_t *out, uint64_t outlen) {
	if(m->length < 40 || m->length > outlen + 40) {
		errno = EINVAL;
		return -1;
	}

	uint8_t mac[32];
	uint64_t plen = m->length - 40; /* 32 for mac and 8 for nonce */
	uint64_t nonce;

	hmac_sha256(keys->recv_hmac_key, 32, m->message, 8 + plen, mac);

	uint8_t res = memcmp_ct(mac, &m->message[8 + plen], 32);
	if(res != 0) {
		errno = EINVAL;
		return -1;
	}

	nonce = decbe64(m->message);

	chacha_dec(keys->recv_symm_key, 32, nonce, &m->message[8], out, plen);
	return 0;
}
/* decrypts the given message using 256-bit chacha */
/* returns non-zero in case of failure */
decrypts the given message using 256-bit chacha
returns non-zero in case of failure
decrypts the given message using 256 - bit chacha returns non - zero in case of failure
int decrypt_message(struct keyset *keys, struct message *m, uint8_t *out, uint64_t outlen) {
	if(m->length < 40 || m->length > outlen + 40) {
		errno = EINVAL;
		return -1;
	}
	uint8_t mac[32];
	uint64_t plen = m->length - 40; 
	uint64_t nonce;
	hmac_sha256(keys->recv_hmac_key, 32, m->message, 8 + plen, mac);
	uint8_t res = memcmp_ct(mac, &m->message[8 + plen], 32);
	if(res != 0) {
		errno = EINVAL;
		return -1;
	}
	nonce = decbe64(m->message);
	chacha_dec(keys->recv_symm_key, 32, nonce, &m->message[8], out, plen);
	return 0;
}
int decrypt_message ( struct keyset * keys , struct message * m , uint8_t * out , uint64_t outlen ) { if ( m -> length < 40 || m -> length > outlen + 40 ) { errno = EINVAL ; return -1 ; } uint8_t mac [ 32 ] ; uint64_t plen = m -> length - 40 ; uint64_t nonce ; hmac_sha256 ( keys -> recv_hmac_key , 32 , m -> message , 8 + plen , mac ) ; uint8_t res = memcmp_ct ( mac , & m -> message [ 8 + plen ] , 32 ) ; if ( res != 0 ) { errno = EINVAL ; return -1 ; } nonce = decbe64 ( m -> message ) ; chacha_dec ( keys -> recv_symm_key , 32 , nonce , & m -> message [ 8 ] , out , plen ) ; return 0 ; }
decrypts the given message using 256-bit chacha
returns non-zero in case of failure
decrypts the given message using 256 - bit chacha returns non - zero in case of failure
/* 32 for mac and 8 for nonce */