aboutsummaryrefslogtreecommitdiffstats
path: root/src/wg_noise.c
diff options
context:
space:
mode:
authorJohn Baldwin <jhb@FreeBSD.org>2022-01-20 15:26:30 -0800
committerJason A. Donenfeld <Jason@zx2c4.com>2022-06-10 19:04:15 +0200
commit352883bb38467c72956e23822b7d3e00d652fdcf (patch)
tree0a8f0d44e61d4e61fa538cb165a2c0a2d04a3431 /src/wg_noise.c
parentif_wg: wg_module_init: clean up more if the self tests fail (diff)
downloadwireguard-freebsd-352883bb38467c72956e23822b7d3e00d652fdcf.tar.xz
wireguard-freebsd-352883bb38467c72956e23822b7d3e00d652fdcf.zip
crypto: return an error code from mbuf crypt routines
This permits returning different error codes for different conditions. Signed-off-by: John Baldwin <jhb@FreeBSD.org>
Diffstat (limited to 'src/wg_noise.c')
-rw-r--r--src/wg_noise.c13
1 files changed, 9 insertions, 4 deletions
diff --git a/src/wg_noise.c b/src/wg_noise.c
index 6848627..d166543 100644
--- a/src/wg_noise.c
+++ b/src/wg_noise.c
@@ -903,8 +903,11 @@ noise_keep_key_fresh_recv(struct noise_remote *r)
int
noise_keypair_encrypt(struct noise_keypair *kp, uint32_t *r_idx, uint64_t nonce, struct mbuf *m)
{
- if (chacha20poly1305_encrypt_mbuf(m, nonce, kp->kp_send) == 0)
- return (ENOMEM);
+ int ret;
+
+ ret = chacha20poly1305_encrypt_mbuf(m, nonce, kp->kp_send);
+ if (ret)
+ return (ret);
*r_idx = kp->kp_index.i_remote_index;
return (0);
@@ -914,6 +917,7 @@ int
noise_keypair_decrypt(struct noise_keypair *kp, uint64_t nonce, struct mbuf *m)
{
uint64_t cur_nonce;
+ int ret;
#ifdef __LP64__
cur_nonce = ck_pr_load_64(&kp->kp_nonce_recv);
@@ -927,8 +931,9 @@ noise_keypair_decrypt(struct noise_keypair *kp, uint64_t nonce, struct mbuf *m)
noise_timer_expired(kp->kp_birthdate, REJECT_AFTER_TIME, 0))
return (EINVAL);
- if (chacha20poly1305_decrypt_mbuf(m, nonce, kp->kp_recv) == 0)
- return (EINVAL);
+ ret = chacha20poly1305_decrypt_mbuf(m, nonce, kp->kp_recv);
+ if (ret)
+ return (ret);
return (0);
}