From a60535ed57a871366b1b192d5c9cd14a5876e2c2 Mon Sep 17 00:00:00 2001 From: Vsevolod Stakhov Date: Thu, 7 May 2015 12:55:20 +0100 Subject: [PATCH] Fix some unaligned cases. --- src/libcryptobox/cryptobox.c | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/src/libcryptobox/cryptobox.c b/src/libcryptobox/cryptobox.c index 4ca3d3238..e6bd45c94 100644 --- a/src/libcryptobox/cryptobox.c +++ b/src/libcryptobox/cryptobox.c @@ -238,7 +238,7 @@ void rspamd_cryptobox_encryptv_nm_inplace (struct rspamd_cryptobox_segment *segm seg_offset = 0; for (;;) { - if (cur - segments == cnt) { + if (cur - segments == (gint)cnt) { break; } @@ -249,6 +249,8 @@ void rspamd_cryptobox_encryptv_nm_inplace (struct rspamd_cryptobox_segment *segm cur ++; if (remain == 0) { + chacha_update (&s, outbuf, outbuf, sizeof (outbuf)); + poly1305_update (&mac_ctx, outbuf, sizeof (outbuf)); rspamd_cryptobox_flush_outbuf (start_seg, outbuf, sizeof (outbuf), seg_offset); start_seg = cur; @@ -289,13 +291,14 @@ void rspamd_cryptobox_encryptv_nm_inplace (struct rspamd_cryptobox_segment *segm } } + seg_offset = cur->len - (sizeof (outbuf) - remain); cur ++; - seg_offset = inremain; } } - r = chacha_final (&s, out); - remain -= r; + r = chacha_update (&s, outbuf, outbuf, sizeof (outbuf) - remain); + out = outbuf + r; + chacha_final (&s, out); poly1305_update (&mac_ctx, outbuf, sizeof (outbuf) - remain); poly1305_finish (&mac_ctx, sig); -- 2.39.5