From gniibe at fsij.org Wed Nov 4 03:30:06 2026 From: gniibe at fsij.org (NIIBE Yutaka) Date: Wed, 04 Nov 2026 11:30:06 +0900 Subject: gcry_create_nonce after a snapshot or checkpoint restore In-Reply-To: <87mrrvtzsr.fsf@haruna.fsij.org> References: <87bj8nyfqe.fsf@haruna.fsij.org> <5f37bbfa-9576-4258-97a5-cd3011eb625c@icloud.com> <87bj8dnhb1.fsf@haruna.fsij.org> <179328110640.2199465.18425657517662925255@icloud.com> <87mrrvtzsr.fsf@haruna.fsij.org> Message-ID: <87mrrpxr9t.fsf@haruna.fsij.org> Hello, Please note that adding new control means update of API. Thus... I wonder if it's needed or not (hesitate to do that, just only for this purpose). Anyhow, attached is a patch to fix GCRYCTL_CLOSE_RANDOM_DEVICE, so that it surely finalizes the buffer for gcry_create_nonce. My idea is: let us apply this change of GCRYCTL_CLOSE_RANDOM_DEVICE at first. An application should use GCRYCTL_CLOSE_RANDOM_DEVICE when it needs to reseed the random number generation (for now). Let us see if better name of the control will be needed. -- -------------- next part -------------- A non-text attachment was scrubbed... Name: 0001-random-Make-sure-GCRYCTL_CLOSE_RANDOM_DEVICE-finish-.patch Type: text/x-diff Size: 3255 bytes Desc: not available URL: From kurath0307 at icloud.com Wed Nov 4 14:50:21 2026 From: kurath0307 at icloud.com (Yuxiang Ji) Date: Wed, 04 Nov 2026 21:50:21 +0800 Subject: gcry_create_nonce after a snapshot or checkpoint restore In-Reply-To: <87mrrpxr9t.fsf@haruna.fsij.org> References: <87bj8nyfqe.fsf@haruna.fsij.org> <5f37bbfa-9576-4258-97a5-cd3011eb625c@icloud.com> <87bj8dnhb1.fsf@haruna.fsij.org> <179328110640.2199465.18425657517662925255@icloud.com> <87mrrvtzsr.fsf@haruna.fsij.org> <87mrrpxr9t.fsf@haruna.fsij.org> Message-ID: <179380022106.1460065.2738836707635634830@icloud.com> Hello, Thank you for the patch. The existing control is fine for our case; we do not need a new one. We applied the patch to 1.12.2 and ran the unshare-then-fork reproducer, in which parent and child are both pid 1. In 32 runs of each case, this is how often the child's nonce equalled the parent's: without the patch, no call 32 of 32 without the patch, the control in the child 32 of 32 with the patch, no call 32 of 32 with the patch, the control in the child 0 of 32 with the patch, the control in both processes 0 of 32 make check passes with the patch. One suggestion for the manual. Its entry for GCRYCTL_CLOSE_RANDOM_DEVICE says only that the control closes the random device after fork(), so an application looking for a way to reseed would not find it there. Once the patch is in, a sentence could say that the control also makes gcry_create_nonce re-initialise its state, and that an application should call it in a child that keeps its parent's pid, and after its process or virtual machine is restored from a snapshot or checkpoint. We are glad to send that as a patch to doc/gcrypt.texi. Best regards, Yuxiang Ji From jussi.kivilinna at iki.fi Fri Nov 6 07:04:52 2026 From: jussi.kivilinna at iki.fi (Jussi Kivilinna) Date: Fri, 6 Nov 2026 08:04:52 +0200 Subject: sntrup761: implicit-rejection key differs from the specification since 4e963e91 In-Reply-To: References: Message-ID: <12d292e7-5eab-48d3-a0d3-7e0b453fbfad@iki.fi> Hello, On 05/11/2026 22:31, 007bsd wrote: > Hello, > > libgcrypt's sntrup761 decapsulation returns a different rejection key > from the specification since a constant-time refactor in 2025. I found > no attack (reasoning below), so I am reporting it here as a normal bug > with a one-line fix. > Thanks for reporting. I've created ticket in issue tracker for this: https://dev.gnupg.org/T8542 -Jussi From jussi.kivilinna at iki.fi Fri Nov 6 09:07:21 2026 From: jussi.kivilinna at iki.fi (Jussi Kivilinna) Date: Fri, 6 Nov 2026 10:07:21 +0200 Subject: [PATCH 2/4] aria: add x86_64 AESNI/AVX 1-block implementation In-Reply-To: <20261106080723.291622-1-jussi.kivilinna@iki.fi> References: <20261106080723.291622-1-jussi.kivilinna@iki.fi> Message-ID: <20261106080723.291622-2-jussi.kivilinna@iki.fi> * cipher/aria-aesni-avx-amd64.S (filter_8bit_split): New. (filter_8bit): Use filter_8bit_split. (_gcry_aria_aesni_avx_crypt_blk1): New. * cipher/aria.c [USE_AESNI_AVX] (_gcry_aria_aesni_avx_crypt_blk1): New prototype. (aria_crypt_uses_sboxes): New. (aria_crypt) [USE_AESNI_AVX]: Use AESNI/AVX 1-block implementation if supported by CPU. (aria_encrypt, aria_decrypt, _gcry_aria_cbc_enc, _gcry_aria_cfb_enc): Prefetch sbox tables only if used. -- Benchmark on AMD Ryzen 9 9950X3D (zen5): Before: ARIA128 | nanosecs/byte mebibytes/sec cycles/byte auto Mhz CBC enc | 3.26 ns/B 292.8 MiB/s 17.48 c/B 5365 CFB enc | 3.25 ns/B 293.2 MiB/s 17.52 c/B 5386±1 After (~3% faster): ARIA128 | nanosecs/byte mebibytes/sec cycles/byte auto Mhz CBC enc | 3.17 ns/B 301.2 MiB/s 16.92 c/B 5343±1 CFB enc | 3.17 ns/B 300.5 MiB/s 16.99 c/B 5352±2 Benchmark on AMD Ryzen 9 7900X (zen4): Before: ARIA128 | nanosecs/byte mebibytes/sec cycles/byte auto Mhz CBC enc | 3.87 ns/B 246.5 MiB/s 21.72 c/B 5614±10 CFB enc | 3.86 ns/B 247.3 MiB/s 21.46 c/B 5566 After (~1.4x faster): ARIA128 | nanosecs/byte mebibytes/sec cycles/byte auto Mhz CBC enc | 2.75 ns/B 346.6 MiB/s 15.13 c/B 5500 CFB enc | 2.73 ns/B 349.8 MiB/s 15.00 c/B 5500 Benchmark on AMD EPYC 7713 (zen3): Before: ARIA128 | nanosecs/byte mebibytes/sec cycles/byte auto Mhz CBC enc | 6.66 ns/B 143.3 MiB/s 20.63 c/B 3100 CFB enc | 6.66 ns/B 143.1 MiB/s 20.66 c/B 3100 After (~1.4x faster): ARIA128 | nanosecs/byte mebibytes/sec cycles/byte auto Mhz CBC enc | 4.83 ns/B 197.5 MiB/s 14.97 c/B 3100 CFB enc | 4.84 ns/B 196.9 MiB/s 15.02 c/B 3100 Benchmark on AMD EPYC 7402P (zen2): Before: ARIA128 | nanosecs/byte mebibytes/sec cycles/byte auto Mhz CBC enc | 6.43 ns/B 148.4 MiB/s 21.48 c/B 3344 CFB enc | 6.43 ns/B 148.4 MiB/s 21.49 c/B 3343 After (~1.6x faster): ARIA128 | nanosecs/byte mebibytes/sec cycles/byte auto Mhz CBC enc | 3.93 ns/B 242.6 MiB/s 13.14 c/B 3343 CFB enc | 3.94 ns/B 242.3 MiB/s 13.16 c/B 3344 Benchmark on AMD Ryzen 5 2600X (zen+): Before: ARIA128 | nanosecs/byte mebibytes/sec cycles/byte auto Mhz CBC enc | 5.63 ns/B 169.4 MiB/s 22.83 c/B 4054 CFB enc | 5.68 ns/B 168.0 MiB/s 22.98 c/B 4049±1 After (~1.7x faster): ARIA128 | nanosecs/byte mebibytes/sec cycles/byte auto Mhz CBC enc | 3.37 ns/B 282.7 MiB/s 13.65 c/B 4045±3 CFB enc | 3.38 ns/B 281.9 MiB/s 13.72 c/B 4056 Benchmark on Intel Core i3-1115G4 (tigerlake): Before: ARIA128 | nanosecs/byte mebibytes/sec cycles/byte auto Mhz CBC enc | 5.56 ns/B 171.4 MiB/s 22.76 c/B 4090 CFB enc | 5.57 ns/B 171.3 MiB/s 22.76 c/B 4090 After (~1.6x faster): ARIA128 | nanosecs/byte mebibytes/sec cycles/byte auto Mhz CBC enc | 3.51 ns/B 271.7 MiB/s 14.36 c/B 4090 CFB enc | 3.49 ns/B 273.3 MiB/s 14.27 c/B 4090 Benchmark on Intel Xeon E5-2620 v3 (haswell): Before: ARIA128 | nanosecs/byte mebibytes/sec cycles/byte auto Mhz CBC enc | 8.75 ns/B 109.0 MiB/s 22.72 c/B 2595 CFB enc | 8.75 ns/B 108.9 MiB/s 22.72 c/B 2595 After (~27% faster): ARIA128 | nanosecs/byte mebibytes/sec cycles/byte auto Mhz CBC enc | 6.87 ns/B 138.9 MiB/s 17.82 c/B 2595 CFB enc | 6.85 ns/B 139.2 MiB/s 17.77 c/B 2595 Signed-off-by: Jussi Kivilinna --- cipher/aria-aesni-avx-amd64.S | 225 +++++++++++++++++++++++++++++++++- cipher/aria.c | 35 +++++- 2 files changed, 250 insertions(+), 10 deletions(-) diff --git a/cipher/aria-aesni-avx-amd64.S b/cipher/aria-aesni-avx-amd64.S index ee542b00..8d3a38f2 100644 --- a/cipher/aria-aesni-avx-amd64.S +++ b/cipher/aria-aesni-avx-amd64.S @@ -66,13 +66,17 @@ ((l0) << (7 * 8)) ) /* asm macros */ -#define filter_8bit(x, lo_t, hi_t, mask4bit, tmp0) \ - vpand x, mask4bit, tmp0; \ - vpandn x, mask4bit, x; \ - vpsrld $4, x, x; \ +/* lo_out must not alias x. */ +#define filter_8bit_split(lo_out, hi_out, x, lo_t, hi_t, mask4bit) \ + vpand x, mask4bit, lo_out; \ + vpandn x, mask4bit, hi_out; \ + vpsrld $4, hi_out, hi_out; \ \ - vpshufb tmp0, lo_t, tmp0; \ - vpshufb x, hi_t, x; \ + vpshufb lo_out, lo_t, lo_out; \ + vpshufb hi_out, hi_t, hi_out; + +#define filter_8bit(x, lo_t, hi_t, mask4bit, tmp0) \ + filter_8bit_split(tmp0, x, x, lo_t, hi_t, mask4bit); \ vpxor tmp0, x, x; #define transpose_4x4(x0, x1, x2, x3, t1, t2) \ @@ -816,6 +820,47 @@ SECTION_RODATA .byte 0x0f, 0x0e, 0x0d, 0x0c, 0x0b, 0x0a, 0x09, 0x08 .byte 0x07, 0x06, 0x05, 0x04, 0x03, 0x02, 0x01, 0x00 +/* 1-block diffusion layer, with AES (inverse) shift rows folded in. Tables + * shared by even and odd rounds (S1 and X1 outputs swapped in odd rounds), + * then S2 and X2 tables of even and odd rounds. */ +.Lshuf_even_odd_blk1: + .byte 0x0e, 0x0a, 0x0e, 0x02, 0x0a, 0x02, 0x0a, 0x0e + .byte 0x02, 0x0e, 0x0a, 0x0a, 0x0a, 0x0e, 0x06, 0x0a + .byte 0x04, 0x08, 0x04, 0x00, 0x00, 0x04, 0x00, 0x08 + .byte 0x00, 0x00, 0x08, 0x04, 0x0c, 0x00, 0x00, 0x04 + .byte 0x06, 0x80, 0x02, 0x06, 0x06, 0x06, 0x02, 0x80 + .byte 0x80, 0x06, 0x0e, 0x06, 0x0e, 0x02, 0x80, 0x02 + .byte 0x08, 0x0c, 0x0c, 0x80, 0x08, 0x80, 0x0c, 0x0c + .byte 0x04, 0x0c, 0x80, 0x0c, 0x80, 0x08, 0x04, 0x08 +.Lshuf_even_blk1: + .byte 0x07, 0x0b, 0x0f, 0x0b, 0x0f, 0x07, 0x0b, 0x07 + .byte 0x0b, 0x0f, 0x07, 0x07, 0x0b, 0x07, 0x07, 0x03 + .byte 0x0d, 0x09, 0x05, 0x09, 0x09, 0x05, 0x0d, 0x05 + .byte 0x05, 0x05, 0x09, 0x0d, 0x05, 0x01, 0x09, 0x05 + .byte 0x80, 0x03, 0x03, 0x0f, 0x03, 0x03, 0x80, 0x0f + .byte 0x03, 0x80, 0x03, 0x0b, 0x0f, 0x0b, 0x0f, 0x80 + .byte 0x01, 0x0d, 0x80, 0x01, 0x80, 0x0d, 0x01, 0x01 + .byte 0x01, 0x09, 0x01, 0x80, 0x0d, 0x80, 0x0d, 0x09 +.Lshuf_odd_blk1: + .byte 0x05, 0x01, 0x0d, 0x01, 0x01, 0x0d, 0x05, 0x0d + .byte 0x0d, 0x0d, 0x01, 0x05, 0x0d, 0x09, 0x01, 0x0d + .byte 0x0f, 0x03, 0x07, 0x03, 0x07, 0x0f, 0x03, 0x0f + .byte 0x03, 0x07, 0x0f, 0x0f, 0x03, 0x0f, 0x0f, 0x0b + .byte 0x09, 0x05, 0x80, 0x09, 0x80, 0x05, 0x09, 0x09 + .byte 0x09, 0x01, 0x09, 0x80, 0x05, 0x80, 0x05, 0x01 + .byte 0x80, 0x0b, 0x0b, 0x07, 0x0b, 0x0b, 0x80, 0x07 + .byte 0x0b, 0x80, 0x0b, 0x03, 0x07, 0x03, 0x07, 0x80 +/* 1-block last round: bytes from S1, S2, X1, X2 outputs. */ +.Lshuf_final_blk1: + .byte 0x80, 0x80, 0x0a, 0x80, 0x80, 0x80, 0x0e, 0x80 + .byte 0x80, 0x80, 0x02, 0x80, 0x80, 0x80, 0x06, 0x80 + .byte 0x80, 0x80, 0x80, 0x07, 0x80, 0x80, 0x80, 0x0b + .byte 0x80, 0x80, 0x80, 0x0f, 0x80, 0x80, 0x80, 0x03 + .byte 0x00, 0x80, 0x80, 0x80, 0x04, 0x80, 0x80, 0x80 + .byte 0x08, 0x80, 0x80, 0x80, 0x0c, 0x80, 0x80, 0x80 + .byte 0x80, 0x05, 0x80, 0x80, 0x80, 0x09, 0x80, 0x80 + .byte 0x80, 0x0d, 0x80, 0x80, 0x80, 0x01, 0x80, 0x80 + /* AES inverse affine and S2 combined: * 1 1 0 0 0 0 0 1 x0 0 * 0 1 0 0 1 0 0 0 x1 0 @@ -953,6 +998,10 @@ SECTION_RODATA .text +/********************************************************************** + 16-block parallel ARIA (AESNI/AVX) + **********************************************************************/ + .align 16 ELF(.type __aria_aesni_avx_crypt_16way, at function;) __aria_aesni_avx_crypt_16way: @@ -1228,6 +1277,11 @@ _gcry_aria_aesni_avx_ctr_crypt_blk16: ELF(.size _gcry_aria_aesni_avx_ctr_crypt_blk16,.-_gcry_aria_aesni_avx_ctr_crypt_blk16;) #ifdef CONFIG_AS_GFNI + +/********************************************************************** + 16-block parallel ARIA (GFNI/AVX) + **********************************************************************/ + .align 16 ELF(.type __aria_gfni_avx_crypt_16way, at function;) __aria_gfni_avx_crypt_16way: @@ -1416,5 +1470,164 @@ _gcry_aria_gfni_avx_ctr_crypt_blk16: ELF(.size _gcry_aria_gfni_avx_ctr_crypt_blk16,.-_gcry_aria_gfni_avx_ctr_crypt_blk16;) #endif /* CONFIG_AS_GFNI */ +/********************************************************************** + 1-block non-parallel ARIA (AESNI/AVX) + **********************************************************************/ + +#define MASK4BIT %xmm10 +#define TF_LO_S2 %xmm11 +#define TF_HI_S2 %xmm12 +#define TF_LO_X2 %xmm13 +#define TF_HI_X2 %xmm14 +#define ZERO %xmm15 + +#define SHUF_EVEN_0 .Lshuf_even_odd_blk1 + 0 * 16 rRIP +#define SHUF_EVEN_1 .Lshuf_even_blk1 + 0 * 16 rRIP +#define SHUF_EVEN_2 .Lshuf_even_odd_blk1 + 1 * 16 rRIP +#define SHUF_EVEN_3 .Lshuf_even_blk1 + 1 * 16 rRIP +#define SHUF_EVEN_4 .Lshuf_even_odd_blk1 + 2 * 16 rRIP +#define SHUF_EVEN_5 .Lshuf_even_blk1 + 2 * 16 rRIP +#define SHUF_EVEN_6 .Lshuf_even_odd_blk1 + 3 * 16 rRIP +#define SHUF_EVEN_7 .Lshuf_even_blk1 + 3 * 16 rRIP +#define SHUF_ODD_0 SHUF_EVEN_2 +#define SHUF_ODD_1 .Lshuf_odd_blk1 + 0 * 16 rRIP +#define SHUF_ODD_2 SHUF_EVEN_0 +#define SHUF_ODD_3 .Lshuf_odd_blk1 + 1 * 16 rRIP +#define SHUF_ODD_4 SHUF_EVEN_6 +#define SHUF_ODD_5 .Lshuf_odd_blk1 + 2 * 16 rRIP +#define SHUF_ODD_6 SHUF_EVEN_4 +#define SHUF_ODD_7 .Lshuf_odd_blk1 + 3 * 16 rRIP + +#define preload_blk1_consts() \ + vbroadcastss .L0f0f0f0f rRIP, MASK4BIT; \ + vmovdqa .Ltf_lo__inv_aff__and__s2 rRIP, TF_LO_S2; \ + vmovdqa .Ltf_hi__inv_aff__and__s2 rRIP, TF_HI_S2; \ + vmovdqa .Ltf_lo__x2__and__fwd_aff rRIP, TF_LO_X2; \ + vmovdqa .Ltf_hi__x2__and__fwd_aff rRIP, TF_HI_X2; \ + vpxor ZERO, ZERO, ZERO; + +#define aria_ark_blk1(x, rk, round) \ + vpxor ((round) * 16)(rk), x, x; + +/* Outputs keep AES shift rows; S2 output left as lo/hi lookup halves. */ +#define aria_sbox_blk1(x, s1, s2lo, s2hi, x1, x2, t0) \ + vaesenclast ZERO, x, s1; \ + vaesdeclast ZERO, x, x1; \ + \ + /* affine transformation for S2 */ \ + filter_8bit_split(s2lo, s2hi, s1, TF_LO_S2, TF_HI_S2, MASK4BIT); \ + \ + /* affine transformation for X2 */ \ + filter_8bit(x, TF_LO_X2, TF_HI_X2, MASK4BIT, t0); \ + vaesdeclast ZERO, x, x2; + +#define aria_diff_blk1(x, s1, s2lo, s2hi, x1, x2, t0, t1, t2, t3, \ + shuf, rk, next_round) \ + vpshufb shuf ## _0, s1, x; \ + vpshufb shuf ## _4, s1, s1; \ + vpshufb shuf ## _2, x1, t1; \ + vpshufb shuf ## _6, x1, x1; \ + vpshufb shuf ## _1, s2lo, t0; \ + vpshufb shuf ## _5, s2lo, s2lo; \ + vpshufb shuf ## _1, s2hi, t3; \ + vpshufb shuf ## _5, s2hi, s2hi; \ + vpshufb shuf ## _3, x2, t2; \ + vpshufb shuf ## _7, x2, x2; \ + vpxor s1, x, x; \ + vpxor t1, x1, x1; \ + vpxor ((next_round) * 16)(rk), x, x; \ + vpxor x1, x, x; \ + vpxor t0, s2lo, s2lo; \ + vpxor s2lo, x, x; \ + vpxor t3, s2hi, s2hi; \ + vpxor s2hi, x, x; \ + vpxor t2, x2, x2; \ + vpxor x2, x, x; + +#define aria_diff_final_blk1(x, s1, s2lo, s2hi, x1, x2, rk, last_round) \ + vpshufb .Lshuf_final_blk1 + 0 * 16 rRIP, s1, s1; \ + vpshufb .Lshuf_final_blk1 + 2 * 16 rRIP, x1, x1; \ + vpshufb .Lshuf_final_blk1 + 1 * 16 rRIP, s2lo, s2lo; \ + vpshufb .Lshuf_final_blk1 + 1 * 16 rRIP, s2hi, s2hi; \ + vpshufb .Lshuf_final_blk1 + 3 * 16 rRIP, x2, x2; \ + vpxor ((last_round) * 16)(rk), s1, x; \ + vpxor x1, x, x; \ + vpxor s2lo, x, x; \ + vpxor s2hi, x, x; \ + vpxor x2, x, x; + +#define aria_fe_blk1(x, rk, next_round) \ + aria_sbox_blk1(x, %xmm1, %xmm2, %xmm8, %xmm3, %xmm4, %xmm5); \ + aria_diff_blk1(x, %xmm1, %xmm2, %xmm8, %xmm3, %xmm4, %xmm5, %xmm6, \ + %xmm7, %xmm9, SHUF_EVEN, rk, next_round); + +#define aria_fo_blk1(x, rk, next_round) \ + aria_sbox_blk1(x, %xmm1, %xmm2, %xmm8, %xmm3, %xmm4, %xmm5); \ + aria_diff_blk1(x, %xmm1, %xmm2, %xmm8, %xmm3, %xmm4, %xmm5, %xmm6, \ + %xmm7, %xmm9, SHUF_ODD, rk, next_round); + +#define aria_ff_blk1(x, rk, last_round) \ + aria_sbox_blk1(x, %xmm1, %xmm2, %xmm8, %xmm3, %xmm4, %xmm5); \ + aria_diff_final_blk1(x, %xmm1, %xmm2, %xmm8, %xmm3, %xmm4, rk, \ + last_round); + +.align 16 +.globl _gcry_aria_aesni_avx_crypt_blk1 +ELF(.type _gcry_aria_aesni_avx_crypt_blk1, at function;) +_gcry_aria_aesni_avx_crypt_blk1: + /* input: + * %rdi: ctx, CTX + * %rsi: dst + * %rdx: src + * %rcx: round keys + */ + CFI_STARTPROC(); + + vmovdqu (%rdx), %xmm0; + + preload_blk1_consts(); + + aria_ark_blk1(%xmm0, %rcx, 0); + + movl ARIA_CTX_rounds(CTX), %r9d; + subl $2, %r9d; + + aria_fo_blk1(%xmm0, %rcx, 1); + leaq 2*16(%rcx), %rcx; + +.align 16 +.Loop_aesni_blk1: + aria_fe_blk1(%xmm0, %rcx, 0); + aria_fo_blk1(%xmm0, %rcx, 1); + leaq 2*16(%rcx), %rcx; + subl $2, %r9d; + jnz .Loop_aesni_blk1; + + aria_ff_blk1(%xmm0, %rcx, 0); + + vmovdqu %xmm0, (%rsi); + + vzeroall; + ret_spec_stop; + CFI_ENDPROC(); +ELF(.size _gcry_aria_aesni_avx_crypt_blk1,.-_gcry_aria_aesni_avx_crypt_blk1;) + +#undef SHUF_EVEN_0 +#undef SHUF_EVEN_1 +#undef SHUF_EVEN_2 +#undef SHUF_EVEN_3 +#undef SHUF_EVEN_4 +#undef SHUF_EVEN_5 +#undef SHUF_EVEN_6 +#undef SHUF_EVEN_7 +#undef SHUF_ODD_0 +#undef SHUF_ODD_1 +#undef SHUF_ODD_2 +#undef SHUF_ODD_3 +#undef SHUF_ODD_4 +#undef SHUF_ODD_5 +#undef SHUF_ODD_6 +#undef SHUF_ODD_7 + #endif /* ENABLE_AVX_SUPPORT && ENABLE_AESNI_SUPPORT */ #endif /* __x86_64 */ diff --git a/cipher/aria.c b/cipher/aria.c index 80fe185b..38d11e5a 100644 --- a/cipher/aria.c +++ b/cipher/aria.c @@ -449,6 +449,9 @@ static struct }; #ifdef USE_AESNI_AVX +extern void +_gcry_aria_aesni_avx_crypt_blk1(const void *ctx, byte *out, const byte *in, + const void *key) ASM_FUNC_ABI; extern unsigned int _gcry_aria_aesni_avx_ecb_crypt_blk1_16(const void *ctx, byte *out, const byte *in, const void *key, @@ -991,6 +994,18 @@ aria_set_decrypt_key(ARIA_context *ctx) } } +/* Returns true if aria_crypt uses sbox tables. */ +static inline int +aria_crypt_uses_sboxes(ARIA_context *ctx) +{ +#ifdef USE_AESNI_AVX + if (ctx->use_aesni_avx) + return 0; +#endif + (void)ctx; + return 1; +} + static NO_INLINE unsigned int aria_crypt(ARIA_context *ctx, byte *out, const byte *in, u32 key[][ARIA_RD_KEY_WORDS]) @@ -999,6 +1014,14 @@ aria_crypt(ARIA_context *ctx, byte *out, const byte *in, int rounds = ctx->rounds; int rkidx = 0; +#ifdef USE_AESNI_AVX + if (ctx->use_aesni_avx) + { + _gcry_aria_aesni_avx_crypt_blk1(ctx, out, in, key); + return ASM_EXTRA_STACK; + } +#endif + reg0 = buf_get_le32(in + 0); reg1 = buf_get_le32(in + 4); reg2 = buf_get_le32(in + 8); @@ -1037,7 +1060,8 @@ aria_encrypt(void *c, byte *outbuf, const byte *inbuf) { ARIA_context *ctx = (ARIA_context *)c; - prefetch_sboxes (); + if (aria_crypt_uses_sboxes (ctx)) + prefetch_sboxes (); return aria_crypt (ctx, outbuf, inbuf, ctx->enc_key); } @@ -1053,7 +1077,8 @@ aria_decrypt(void *c, byte *outbuf, const byte *inbuf) ctx->decryption_prepared = 1; } - prefetch_sboxes (); + if (aria_crypt_uses_sboxes (ctx)) + prefetch_sboxes (); return aria_crypt (ctx, outbuf, inbuf, ctx->dec_key); } @@ -1323,7 +1348,8 @@ _gcry_aria_cbc_enc (void *context, unsigned char *iv, unsigned char *last_iv; unsigned int burn_depth = 0; - prefetch_sboxes(); + if (aria_crypt_uses_sboxes (ctx)) + prefetch_sboxes(); last_iv = iv; @@ -1396,7 +1422,8 @@ _gcry_aria_cfb_enc (void *context, unsigned char *iv, const unsigned char *inbuf = inbuf_arg; unsigned int burn_depth = 0; - prefetch_sboxes(); + if (aria_crypt_uses_sboxes (ctx)) + prefetch_sboxes(); for (; nblocks; nblocks--) { -- 2.53.0 From jussi.kivilinna at iki.fi Fri Nov 6 09:07:23 2026 From: jussi.kivilinna at iki.fi (Jussi Kivilinna) Date: Fri, 6 Nov 2026 10:07:23 +0200 Subject: [PATCH 4/4] aria: add x86_64 GFNI/AVX512 1-block implementation In-Reply-To: <20261106080723.291622-1-jussi.kivilinna@iki.fi> References: <20261106080723.291622-1-jussi.kivilinna@iki.fi> Message-ID: <20261106080723.291622-4-jussi.kivilinna@iki.fi> * cipher/aria-gfni-avx512-amd64.S (_gcry_aria_gfni_avx512_crypt_blk1): New. * cipher/aria.c [USE_GFNI_AVX512] (_gcry_aria_gfni_avx512_crypt_blk1): New prototype. (aria_crypt_uses_sboxes) [USE_GFNI_AVX512]: Handle GFNI/AVX512 implementation. (aria_crypt) [USE_GFNI_AVX512]: Use GFNI/AVX512 1-block implementation if supported by CPU. -- Benchmark on AMD Ryzen 9 9950X3D (zen5): Generic C: ARIA128 | nanosecs/byte mebibytes/sec cycles/byte auto Mhz CBC enc | 3.26 ns/B 292.8 MiB/s 17.48 c/B 5365 CFB enc | 3.25 ns/B 293.2 MiB/s 17.52 c/B 5386±1 Before (GFNI/AVX): ARIA128 | nanosecs/byte mebibytes/sec cycles/byte auto Mhz CBC enc | 2.72 ns/B 351.2 MiB/s 14.13 c/B 5204 CFB enc | 2.72 ns/B 351.2 MiB/s 14.26 c/B 5252 After (~20% faster than GFNI/AVX, ~1.5x faster than generic C): ARIA128 | nanosecs/byte mebibytes/sec cycles/byte auto Mhz CBC enc | 2.15 ns/B 442.6 MiB/s 11.73 c/B 5442±2 CFB enc | 2.17 ns/B 439.0 MiB/s 11.85 c/B 5455±1 Benchmark on AMD Ryzen 9 7900X (zen4): Generic C: ARIA128 | nanosecs/byte mebibytes/sec cycles/byte auto Mhz CBC enc | 3.87 ns/B 246.5 MiB/s 21.72 c/B 5614±10 CFB enc | 3.86 ns/B 247.3 MiB/s 21.46 c/B 5566 Before (GFNI/AVX): ARIA128 | nanosecs/byte mebibytes/sec cycles/byte auto Mhz CBC enc | 2.09 ns/B 455.6 MiB/s 11.51 c/B 5500 CFB enc | 2.09 ns/B 455.5 MiB/s 11.52 c/B 5500 After (~9% faster than GFNI/AVX, ~2.1x faster than generic C): ARIA128 | nanosecs/byte mebibytes/sec cycles/byte auto Mhz CBC enc | 1.92 ns/B 496.9 MiB/s 10.56 c/B 5502±1 CFB enc | 1.98 ns/B 482.1 MiB/s 10.90 c/B 5512±1 Benchmark on Intel Core i3-1115G4 (tigerlake): Generic C: ARIA128 | nanosecs/byte mebibytes/sec cycles/byte auto Mhz CBC enc | 5.56 ns/B 171.4 MiB/s 22.76 c/B 4090 CFB enc | 5.57 ns/B 171.3 MiB/s 22.76 c/B 4090 Before (GFNI/AVX): ARIA128 | nanosecs/byte mebibytes/sec cycles/byte auto Mhz CBC enc | 3.04 ns/B 313.7 MiB/s 12.44 c/B 4090 CFB enc | 3.05 ns/B 312.7 MiB/s 12.47 c/B 4090 After (~15% faster than GFNI/AVX, ~2.1x faster than generic C): ARIA128 | nanosecs/byte mebibytes/sec cycles/byte auto Mhz CBC enc | 2.65 ns/B 359.5 MiB/s 10.85 c/B 4090 CFB enc | 2.66 ns/B 358.9 MiB/s 10.87 c/B 4090 Signed-off-by: Jussi Kivilinna --- cipher/aria-gfni-avx512-amd64.S | 172 ++++++++++++++++++++++++++++++++ cipher/aria.c | 14 +++ 2 files changed, 186 insertions(+) diff --git a/cipher/aria-gfni-avx512-amd64.S b/cipher/aria-gfni-avx512-amd64.S index 47d93329..4fabe1bd 100644 --- a/cipher/aria-gfni-avx512-amd64.S +++ b/cipher/aria-gfni-avx512-amd64.S @@ -582,6 +582,38 @@ SECTION_RODATA .byte 0x0f, 0x0e, 0x0d, 0x0c, 0x0b, 0x0a, 0x09, 0x08 .byte 0x07, 0x06, 0x05, 0x04, 0x03, 0x02, 0x01, 0x00 +.align 16 +/* 1-block diffusion layer: first input byte from S1, S2, X1, X2 outputs, + * then second input byte from S1, S2, X1, X2 outputs. Odd rounds use + * same tables with S and X outputs swapped. */ +Lshuf_even_odd_blk1: + .byte 0x06, 0x02, 0x06, 0x0a, 0x02, 0x0a, 0x02, 0x06 + .byte 0x0a, 0x06, 0x02, 0x02, 0x02, 0x06, 0x0e, 0x02 + .byte 0x03, 0x07, 0x0b, 0x07, 0x0b, 0x03, 0x07, 0x03 + .byte 0x07, 0x0b, 0x03, 0x03, 0x07, 0x03, 0x03, 0x0f + .byte 0x04, 0x08, 0x04, 0x00, 0x00, 0x04, 0x00, 0x08 + .byte 0x00, 0x00, 0x08, 0x04, 0x0c, 0x00, 0x00, 0x04 + .byte 0x09, 0x05, 0x01, 0x05, 0x05, 0x01, 0x09, 0x01 + .byte 0x01, 0x01, 0x05, 0x09, 0x01, 0x0d, 0x05, 0x01 + .byte 0x0e, 0x80, 0x0a, 0x0e, 0x0e, 0x0e, 0x0a, 0x80 + .byte 0x80, 0x0e, 0x06, 0x0e, 0x06, 0x0a, 0x80, 0x0a + .byte 0x80, 0x0f, 0x0f, 0x0b, 0x0f, 0x0f, 0x80, 0x0b + .byte 0x0f, 0x80, 0x0f, 0x07, 0x0b, 0x07, 0x0b, 0x80 + .byte 0x08, 0x0c, 0x0c, 0x80, 0x08, 0x80, 0x0c, 0x0c + .byte 0x04, 0x0c, 0x80, 0x0c, 0x80, 0x08, 0x04, 0x08 + .byte 0x0d, 0x09, 0x80, 0x0d, 0x80, 0x09, 0x0d, 0x0d + .byte 0x0d, 0x05, 0x0d, 0x80, 0x09, 0x80, 0x09, 0x05 +/* 1-block last round: bytes from S1, S2, X1, X2 outputs. */ +.Lshuf_final_blk1: + .byte 0x80, 0x80, 0x02, 0x80, 0x80, 0x80, 0x06, 0x80 + .byte 0x80, 0x80, 0x0a, 0x80, 0x80, 0x80, 0x0e, 0x80 + .byte 0x80, 0x80, 0x80, 0x03, 0x80, 0x80, 0x80, 0x07 + .byte 0x80, 0x80, 0x80, 0x0b, 0x80, 0x80, 0x80, 0x0f + .byte 0x00, 0x80, 0x80, 0x80, 0x04, 0x80, 0x80, 0x80 + .byte 0x08, 0x80, 0x80, 0x80, 0x0c, 0x80, 0x80, 0x80 + .byte 0x80, 0x01, 0x80, 0x80, 0x80, 0x05, 0x80, 0x80 + .byte 0x80, 0x09, 0x80, 0x80, 0x80, 0x0d, 0x80, 0x80 + .align 8 /* AES affine: */ #define tf_aff_const BV8(1, 1, 0, 0, 0, 1, 1, 0) @@ -673,6 +705,10 @@ SECTION_RODATA .text +/********************************************************************** + 64-block parallel ARIA (GFNI/AVX512) + **********************************************************************/ + .align 16 ELF(.type __aria_gfni_avx512_crypt_64way, at function;) __aria_gfni_avx512_crypt_64way: @@ -953,5 +989,141 @@ _gcry_aria_gfni_avx512_ctr_crypt_blk64: ELF(.size _gcry_aria_gfni_avx512_ctr_crypt_blk64, .-_gcry_aria_gfni_avx512_ctr_crypt_blk64;) +/********************************************************************** + 1-block non-parallel ARIA (GFNI/AVX512) + **********************************************************************/ + +#define RAFF %xmm8 +#define RS2 %xmm9 +#define RINV %xmm10 +#define RX2 %xmm11 +#define RID %xmm12 + +#define SHUF_EVEN_0 %xmm13 +#define SHUF_EVEN_1 %xmm14 +#define SHUF_EVEN_2 %xmm15 +#define SHUF_EVEN_3 %xmm16 +#define SHUF_EVEN_4 %xmm17 +#define SHUF_EVEN_5 %xmm18 +#define SHUF_EVEN_6 %xmm19 +#define SHUF_EVEN_7 %xmm20 +#define SHUF_ODD_0 SHUF_EVEN_2 +#define SHUF_ODD_1 SHUF_EVEN_3 +#define SHUF_ODD_2 SHUF_EVEN_0 +#define SHUF_ODD_3 SHUF_EVEN_1 +#define SHUF_ODD_4 SHUF_EVEN_6 +#define SHUF_ODD_5 SHUF_EVEN_7 +#define SHUF_ODD_6 SHUF_EVEN_4 +#define SHUF_ODD_7 SHUF_EVEN_5 + +#define preload_blk1_consts() \ + vpbroadcastq .Ltf_aff_bitmatrix rRIP, RAFF; \ + vpbroadcastq .Ltf_s2_bitmatrix rRIP, RS2; \ + vpbroadcastq .Ltf_inv_bitmatrix rRIP, RINV; \ + vpbroadcastq .Ltf_x2_bitmatrix rRIP, RX2; \ + vpbroadcastq .Ltf_id_bitmatrix rRIP, RID; \ + vmovdqa64 Lshuf_even_odd_blk1 + 0 * 16 rRIP, SHUF_EVEN_0; \ + vmovdqa64 Lshuf_even_odd_blk1 + 1 * 16 rRIP, SHUF_EVEN_1; \ + vmovdqa64 Lshuf_even_odd_blk1 + 2 * 16 rRIP, SHUF_EVEN_2; \ + vmovdqa64 Lshuf_even_odd_blk1 + 3 * 16 rRIP, SHUF_EVEN_3; \ + vmovdqa64 Lshuf_even_odd_blk1 + 4 * 16 rRIP, SHUF_EVEN_4; \ + vmovdqa64 Lshuf_even_odd_blk1 + 5 * 16 rRIP, SHUF_EVEN_5; \ + vmovdqa64 Lshuf_even_odd_blk1 + 6 * 16 rRIP, SHUF_EVEN_6; \ + vmovdqa64 Lshuf_even_odd_blk1 + 7 * 16 rRIP, SHUF_EVEN_7; + +#define clear_blk1_consts() \ + clear_vec4(%ymm16, %ymm17, %ymm18, %ymm19); \ + vpxord %ymm20, %ymm20, %ymm20; + +#define aria_ark_blk1(x, rk, round) \ + vpxor ((round) * 16)(rk), x, x; + +#define aria_sbox_blk1(x, s1, s2, x1, x2) \ + vgf2p8affineqb $(tf_inv_const), RINV, x, x1; \ + vgf2p8affineqb $(tf_x2_const), RX2, x, x2; \ + vgf2p8affineinvqb $(tf_aff_const), RAFF, x, s1; \ + vgf2p8affineinvqb $(tf_s2_const), RS2, x, s2; \ + vgf2p8affineinvqb $0, RID, x1, x1; \ + vgf2p8affineinvqb $0, RID, x2, x2; + +#define aria_diff_blk1(x, s1, s2, x1, x2, t0, t1, t2, shuf, rk, next_round) \ + vpshufb shuf ## _0, s1, x; \ + vpshufb shuf ## _4, s1, s1; \ + vpshufb shuf ## _1, s2, t0; \ + vpshufb shuf ## _5, s2, s2; \ + vpshufb shuf ## _2, x1, t1; \ + vpshufb shuf ## _6, x1, x1; \ + vpshufb shuf ## _3, x2, t2; \ + vpshufb shuf ## _7, x2, x2; \ + vpternlogq $0x96, t0, s1, x; \ + vpternlogq $0x96, ((next_round) * 16)(rk), s2, x; \ + vpternlogq $0x96, t2, x1, t1; \ + vpternlogq $0x96, x2, t1, x; + +#define aria_diff_final_blk1(x, s1, s2, x1, x2, rk, last_round) \ + vpshufb .Lshuf_final_blk1 + 0 * 16 rRIP, s1, x; \ + vpshufb .Lshuf_final_blk1 + 1 * 16 rRIP, s2, s2; \ + vpshufb .Lshuf_final_blk1 + 2 * 16 rRIP, x1, x1; \ + vpshufb .Lshuf_final_blk1 + 3 * 16 rRIP, x2, x2; \ + vpternlogq $0x96, ((last_round) * 16)(rk), s2, x; \ + vpternlogq $0x96, x2, x1, x; + +#define aria_fe_blk1(x, rk, next_round) \ + aria_sbox_blk1(x, %xmm1, %xmm2, %xmm3, %xmm4); \ + aria_diff_blk1(x, %xmm1, %xmm2, %xmm3, %xmm4, %xmm5, %xmm6, %xmm7, \ + SHUF_EVEN, rk, next_round); + +#define aria_fo_blk1(x, rk, next_round) \ + aria_sbox_blk1(x, %xmm1, %xmm2, %xmm3, %xmm4); \ + aria_diff_blk1(x, %xmm1, %xmm2, %xmm3, %xmm4, %xmm5, %xmm6, %xmm7, \ + SHUF_ODD, rk, next_round); + +#define aria_ff_blk1(x, rk, last_round) \ + aria_sbox_blk1(x, %xmm1, %xmm2, %xmm3, %xmm4); \ + aria_diff_final_blk1(x, %xmm1, %xmm2, %xmm3, %xmm4, rk, last_round); + +.align 16 +.globl _gcry_aria_gfni_avx512_crypt_blk1 +ELF(.type _gcry_aria_gfni_avx512_crypt_blk1, at function;) +_gcry_aria_gfni_avx512_crypt_blk1: + /* input: + * %rdi: ctx, CTX + * %rsi: dst + * %rdx: src + * %rcx: round keys + */ + CFI_STARTPROC(); + spec_stop_avx512; + + vmovdqu (%rdx), %xmm0; + + preload_blk1_consts(); + + aria_ark_blk1(%xmm0, %rcx, 0); + + movl ARIA_CTX_rounds(CTX), %r9d; + subl $2, %r9d; + + aria_fo_blk1(%xmm0, %rcx, 1); + leaq 2*16(%rcx), %rcx; + +.align 16 +.Loop_blk1: + aria_fe_blk1(%xmm0, %rcx, 0); + aria_fo_blk1(%xmm0, %rcx, 1); + leaq 2*16(%rcx), %rcx; + subl $2, %r9d; + jnz .Loop_blk1; + + aria_ff_blk1(%xmm0, %rcx, 0); + + vmovdqu %xmm0, (%rsi); + + clear_blk1_consts(); + vzeroall; + ret_spec_stop; + CFI_ENDPROC(); +ELF(.size _gcry_aria_gfni_avx512_crypt_blk1,.-_gcry_aria_gfni_avx512_crypt_blk1;) + #endif /* ENABLE_AVX512_SUPPORT && ENABLE_GFNI_SUPPORT */ #endif /* __x86_64 */ diff --git a/cipher/aria.c b/cipher/aria.c index 2f8d7685..85b972bd 100644 --- a/cipher/aria.c +++ b/cipher/aria.c @@ -575,6 +575,9 @@ aria_avx2_ctr_crypt_blk32(const ARIA_context *ctx, byte *out, const byte *in, #endif /* USE_AESNI_AVX2 */ #ifdef USE_GFNI_AVX512 +extern void +_gcry_aria_gfni_avx512_crypt_blk1(const void *ctx, byte *out, const byte *in, + const void *key) ASM_FUNC_ABI; extern unsigned int _gcry_aria_gfni_avx512_ecb_crypt_blk64(const void *ctx, byte *out, const byte *in, @@ -1001,6 +1004,10 @@ aria_set_decrypt_key(ARIA_context *ctx) static inline int aria_crypt_uses_sboxes(ARIA_context *ctx) { +#ifdef USE_GFNI_AVX512 + if (ctx->use_gfni_avx512) + return 0; +#endif #ifdef USE_GFNI_AVX if (ctx->use_gfni_avx) return 0; @@ -1021,6 +1028,13 @@ aria_crypt(ARIA_context *ctx, byte *out, const byte *in, int rounds = ctx->rounds; int rkidx = 0; +#ifdef USE_GFNI_AVX512 + if (ctx->use_gfni_avx512) + { + _gcry_aria_gfni_avx512_crypt_blk1(ctx, out, in, key); + return ASM_EXTRA_STACK; + } +#endif #ifdef USE_GFNI_AVX if (ctx->use_gfni_avx) { -- 2.53.0 From jussi.kivilinna at iki.fi Fri Nov 6 09:07:22 2026 From: jussi.kivilinna at iki.fi (Jussi Kivilinna) Date: Fri, 6 Nov 2026 10:07:22 +0200 Subject: [PATCH 3/4] aria: add x86_64 GFNI/AVX 1-block implementation In-Reply-To: <20261106080723.291622-1-jussi.kivilinna@iki.fi> References: <20261106080723.291622-1-jussi.kivilinna@iki.fi> Message-ID: <20261106080723.291622-3-jussi.kivilinna@iki.fi> * cipher/aria-aesni-avx-amd64.S (_gcry_aria_gfni_avx_crypt_blk1): New. * cipher/aria.c [USE_GFNI_AVX] (_gcry_aria_gfni_avx_crypt_blk1): New prototype. (aria_crypt_uses_sboxes) [USE_GFNI_AVX]: Handle GFNI/AVX implementation. (aria_crypt) [USE_GFNI_AVX]: Use GFNI/AVX 1-block implementation if supported by CPU. -- Benchmark on AMD Ryzen 9 9950X3D (zen5): Generic C: ARIA128 | nanosecs/byte mebibytes/sec cycles/byte auto Mhz CBC enc | 3.26 ns/B 292.8 MiB/s 17.48 c/B 5365 CFB enc | 3.25 ns/B 293.2 MiB/s 17.52 c/B 5386±1 Before (AESNI/AVX): ARIA128 | nanosecs/byte mebibytes/sec cycles/byte auto Mhz CBC enc | 3.17 ns/B 301.2 MiB/s 16.92 c/B 5343±1 CFB enc | 3.17 ns/B 300.5 MiB/s 16.99 c/B 5352±2 After (~19% faster than AESNI/AVX, ~23% faster than generic C): ARIA128 | nanosecs/byte mebibytes/sec cycles/byte auto Mhz CBC enc | 2.62 ns/B 364.0 MiB/s 14.21 c/B 5425±2 CFB enc | 2.61 ns/B 365.7 MiB/s 14.17 c/B 5434±2 Benchmark on AMD Ryzen 9 7900X (zen4): Generic C: ARIA128 | nanosecs/byte mebibytes/sec cycles/byte auto Mhz CBC enc | 3.87 ns/B 246.5 MiB/s 21.72 c/B 5614±10 CFB enc | 3.86 ns/B 247.3 MiB/s 21.46 c/B 5566 Before (AESNI/AVX): ARIA128 | nanosecs/byte mebibytes/sec cycles/byte auto Mhz CBC enc | 2.75 ns/B 346.6 MiB/s 15.13 c/B 5500 CFB enc | 2.73 ns/B 349.8 MiB/s 15.00 c/B 5500 After (~31% faster than AESNI/AVX, ~1.9x faster than generic C): ARIA128 | nanosecs/byte mebibytes/sec cycles/byte auto Mhz CBC enc | 2.09 ns/B 455.6 MiB/s 11.51 c/B 5500 CFB enc | 2.09 ns/B 455.5 MiB/s 11.52 c/B 5500 Benchmark on Intel Core i3-1115G4 (tigerlake): Generic C: ARIA128 | nanosecs/byte mebibytes/sec cycles/byte auto Mhz CBC enc | 5.56 ns/B 171.4 MiB/s 22.76 c/B 4090 CFB enc | 5.57 ns/B 171.3 MiB/s 22.76 c/B 4090 Before (AESNI/AVX): ARIA128 | nanosecs/byte mebibytes/sec cycles/byte auto Mhz CBC enc | 3.51 ns/B 271.7 MiB/s 14.36 c/B 4090 CFB enc | 3.49 ns/B 273.3 MiB/s 14.27 c/B 4090 After (~14% faster than AESNI/AVX, ~1.8x faster than generic C): ARIA128 | nanosecs/byte mebibytes/sec cycles/byte auto Mhz CBC enc | 3.07 ns/B 311.1 MiB/s 12.54 c/B 4090 CFB enc | 3.08 ns/B 309.3 MiB/s 12.61 c/B 4090 Signed-off-by: Jussi Kivilinna --- cipher/aria-aesni-avx-amd64.S | 163 ++++++++++++++++++++++++++++++++++ cipher/aria.c | 14 +++ 2 files changed, 177 insertions(+) diff --git a/cipher/aria-aesni-avx-amd64.S b/cipher/aria-aesni-avx-amd64.S index 8d3a38f2..22da7bf0 100644 --- a/cipher/aria-aesni-avx-amd64.S +++ b/cipher/aria-aesni-avx-amd64.S @@ -989,6 +989,37 @@ SECTION_RODATA BV8(0, 0, 0, 0, 0, 1, 0, 0), BV8(0, 0, 0, 0, 0, 0, 1, 0), BV8(0, 0, 0, 0, 0, 0, 0, 1)) + +.align 16 +/* 1-block diffusion layer for GFNI without shift rows. Odd rounds use same + * tables with S and X outputs swapped. */ +.Lshuf_even_odd_gfni_blk1: + .byte 0x06, 0x02, 0x06, 0x0a, 0x02, 0x0a, 0x02, 0x06 + .byte 0x0a, 0x06, 0x02, 0x02, 0x02, 0x06, 0x0e, 0x02 + .byte 0x03, 0x07, 0x0b, 0x07, 0x0b, 0x03, 0x07, 0x03 + .byte 0x07, 0x0b, 0x03, 0x03, 0x07, 0x03, 0x03, 0x0f + .byte 0x04, 0x08, 0x04, 0x00, 0x00, 0x04, 0x00, 0x08 + .byte 0x00, 0x00, 0x08, 0x04, 0x0c, 0x00, 0x00, 0x04 + .byte 0x09, 0x05, 0x01, 0x05, 0x05, 0x01, 0x09, 0x01 + .byte 0x01, 0x01, 0x05, 0x09, 0x01, 0x0d, 0x05, 0x01 + .byte 0x0e, 0x80, 0x0a, 0x0e, 0x0e, 0x0e, 0x0a, 0x80 + .byte 0x80, 0x0e, 0x06, 0x0e, 0x06, 0x0a, 0x80, 0x0a + .byte 0x80, 0x0f, 0x0f, 0x0b, 0x0f, 0x0f, 0x80, 0x0b + .byte 0x0f, 0x80, 0x0f, 0x07, 0x0b, 0x07, 0x0b, 0x80 + .byte 0x08, 0x0c, 0x0c, 0x80, 0x08, 0x80, 0x0c, 0x0c + .byte 0x04, 0x0c, 0x80, 0x0c, 0x80, 0x08, 0x04, 0x08 + .byte 0x0d, 0x09, 0x80, 0x0d, 0x80, 0x09, 0x0d, 0x0d + .byte 0x0d, 0x05, 0x0d, 0x80, 0x09, 0x80, 0x09, 0x05 +/* 1-block last round for GFNI. */ +.Lshuf_final_gfni_blk1: + .byte 0x80, 0x80, 0x02, 0x80, 0x80, 0x80, 0x06, 0x80 + .byte 0x80, 0x80, 0x0a, 0x80, 0x80, 0x80, 0x0e, 0x80 + .byte 0x80, 0x80, 0x80, 0x03, 0x80, 0x80, 0x80, 0x07 + .byte 0x80, 0x80, 0x80, 0x0b, 0x80, 0x80, 0x80, 0x0f + .byte 0x00, 0x80, 0x80, 0x80, 0x04, 0x80, 0x80, 0x80 + .byte 0x08, 0x80, 0x80, 0x80, 0x0c, 0x80, 0x80, 0x80 + .byte 0x80, 0x01, 0x80, 0x80, 0x80, 0x05, 0x80, 0x80 + .byte 0x80, 0x09, 0x80, 0x80, 0x80, 0x0d, 0x80, 0x80 #endif /* CONFIG_AS_GFNI */ /* 4-bit mask */ @@ -1629,5 +1660,137 @@ ELF(.size _gcry_aria_aesni_avx_crypt_blk1,.-_gcry_aria_aesni_avx_crypt_blk1;) #undef SHUF_ODD_6 #undef SHUF_ODD_7 +#ifdef CONFIG_AS_GFNI +/********************************************************************** + 1-block non-parallel ARIA (GFNI/AVX) + **********************************************************************/ + +#define RAFF %xmm11 +#define RS2 %xmm12 +#define RINV %xmm13 +#define RX2 %xmm14 +#define RID %xmm15 + +#define SHUF_EVEN_0 %xmm8 +#define SHUF_EVEN_1 .Lshuf_even_odd_gfni_blk1 + 1 * 16 rRIP +#define SHUF_EVEN_2 %xmm9 +#define SHUF_EVEN_3 .Lshuf_even_odd_gfni_blk1 + 3 * 16 rRIP +#define SHUF_EVEN_4 %xmm10 +#define SHUF_EVEN_5 .Lshuf_even_odd_gfni_blk1 + 5 * 16 rRIP +#define SHUF_EVEN_6 .Lshuf_even_odd_gfni_blk1 + 6 * 16 rRIP +#define SHUF_EVEN_7 .Lshuf_even_odd_gfni_blk1 + 7 * 16 rRIP +#define SHUF_ODD_0 SHUF_EVEN_2 +#define SHUF_ODD_1 SHUF_EVEN_3 +#define SHUF_ODD_2 SHUF_EVEN_0 +#define SHUF_ODD_3 SHUF_EVEN_1 +#define SHUF_ODD_4 SHUF_EVEN_6 +#define SHUF_ODD_5 SHUF_EVEN_7 +#define SHUF_ODD_6 SHUF_EVEN_4 +#define SHUF_ODD_7 SHUF_EVEN_5 + +#define preload_blk1_consts_gfni() \ + vmovddup .Ltf_aff_bitmatrix rRIP, RAFF; \ + vmovddup .Ltf_s2_bitmatrix rRIP, RS2; \ + vmovddup .Ltf_inv_bitmatrix rRIP, RINV; \ + vmovddup .Ltf_x2_bitmatrix rRIP, RX2; \ + vmovddup .Ltf_id_bitmatrix rRIP, RID; \ + vmovdqa .Lshuf_even_odd_gfni_blk1 + 0 * 16 rRIP, SHUF_EVEN_0; \ + vmovdqa .Lshuf_even_odd_gfni_blk1 + 2 * 16 rRIP, SHUF_EVEN_2; \ + vmovdqa .Lshuf_even_odd_gfni_blk1 + 4 * 16 rRIP, SHUF_EVEN_4; + +#define aria_sbox_blk1_gfni(x, s1, s2, x1, x2) \ + vgf2p8affineqb $(tf_inv_const), RINV, x, x1; \ + vgf2p8affineqb $(tf_x2_const), RX2, x, x2; \ + vgf2p8affineinvqb $(tf_aff_const), RAFF, x, s1; \ + vgf2p8affineinvqb $(tf_s2_const), RS2, x, s2; \ + vgf2p8affineinvqb $0, RID, x1, x1; \ + vgf2p8affineinvqb $0, RID, x2, x2; + +#define aria_diff_blk1_gfni(x, s1, s2, x1, x2, t0, t1, t2, \ + shuf, rk, next_round) \ + vpshufb shuf ## _0, s1, x; \ + vpshufb shuf ## _4, s1, s1; \ + vpshufb shuf ## _1, s2, t0; \ + vpshufb shuf ## _5, s2, s2; \ + vpshufb shuf ## _2, x1, t1; \ + vpshufb shuf ## _6, x1, x1; \ + vpshufb shuf ## _3, x2, t2; \ + vpshufb shuf ## _7, x2, x2; \ + vpxor s1, x, x; \ + vpxor t0, s2, s2; \ + vpxor ((next_round) * 16)(rk), x, x; \ + vpxor s2, x, x; \ + vpxor t1, x1, x1; \ + vpxor t2, x2, x2; \ + vpxor x1, x, x; \ + vpxor x2, x, x; + +#define aria_diff_final_blk1_gfni(x, s1, s2, x1, x2, rk, last_round) \ + vpshufb .Lshuf_final_gfni_blk1 + 0 * 16 rRIP, s1, s1; \ + vpshufb .Lshuf_final_gfni_blk1 + 1 * 16 rRIP, s2, s2; \ + vpshufb .Lshuf_final_gfni_blk1 + 2 * 16 rRIP, x1, x1; \ + vpshufb .Lshuf_final_gfni_blk1 + 3 * 16 rRIP, x2, x2; \ + vpxor ((last_round) * 16)(rk), s1, x; \ + vpxor s2, x, x; \ + vpxor x1, x, x; \ + vpxor x2, x, x; + +#define aria_fe_blk1_gfni(x, rk, next_round) \ + aria_sbox_blk1_gfni(x, %xmm1, %xmm2, %xmm3, %xmm4); \ + aria_diff_blk1_gfni(x, %xmm1, %xmm2, %xmm3, %xmm4, %xmm5, %xmm6, \ + %xmm7, SHUF_EVEN, rk, next_round); + +#define aria_fo_blk1_gfni(x, rk, next_round) \ + aria_sbox_blk1_gfni(x, %xmm1, %xmm2, %xmm3, %xmm4); \ + aria_diff_blk1_gfni(x, %xmm1, %xmm2, %xmm3, %xmm4, %xmm5, %xmm6, \ + %xmm7, SHUF_ODD, rk, next_round); + +#define aria_ff_blk1_gfni(x, rk, last_round) \ + aria_sbox_blk1_gfni(x, %xmm1, %xmm2, %xmm3, %xmm4); \ + aria_diff_final_blk1_gfni(x, %xmm1, %xmm2, %xmm3, %xmm4, rk, \ + last_round); + +.align 16 +.globl _gcry_aria_gfni_avx_crypt_blk1 +ELF(.type _gcry_aria_gfni_avx_crypt_blk1, at function;) +_gcry_aria_gfni_avx_crypt_blk1: + /* input: + * %rdi: ctx, CTX + * %rsi: dst + * %rdx: src + * %rcx: round keys + */ + CFI_STARTPROC(); + + vmovdqu (%rdx), %xmm0; + + preload_blk1_consts_gfni(); + + aria_ark_blk1(%xmm0, %rcx, 0); + + movl ARIA_CTX_rounds(CTX), %r9d; + subl $2, %r9d; + + aria_fo_blk1_gfni(%xmm0, %rcx, 1); + leaq 2*16(%rcx), %rcx; + +.align 16 +.Loop_gfni_blk1: + aria_fe_blk1_gfni(%xmm0, %rcx, 0); + aria_fo_blk1_gfni(%xmm0, %rcx, 1); + leaq 2*16(%rcx), %rcx; + subl $2, %r9d; + jnz .Loop_gfni_blk1; + + aria_ff_blk1_gfni(%xmm0, %rcx, 0); + + vmovdqu %xmm0, (%rsi); + + vzeroall; + ret_spec_stop; + CFI_ENDPROC(); +ELF(.size _gcry_aria_gfni_avx_crypt_blk1,.-_gcry_aria_gfni_avx_crypt_blk1;) +#endif /* CONFIG_AS_GFNI */ + #endif /* ENABLE_AVX_SUPPORT && ENABLE_AESNI_SUPPORT */ #endif /* __x86_64 */ diff --git a/cipher/aria.c b/cipher/aria.c index 38d11e5a..2f8d7685 100644 --- a/cipher/aria.c +++ b/cipher/aria.c @@ -461,6 +461,9 @@ _gcry_aria_aesni_avx_ctr_crypt_blk16(const void *ctx, byte *out, const byte *in, byte *iv) ASM_FUNC_ABI; #ifdef USE_GFNI_AVX +extern void +_gcry_aria_gfni_avx_crypt_blk1(const void *ctx, byte *out, const byte *in, + const void *key) ASM_FUNC_ABI; extern unsigned int _gcry_aria_gfni_avx_ecb_crypt_blk1_16(const void *ctx, byte *out, const byte *in, const void *key, @@ -998,6 +1001,10 @@ aria_set_decrypt_key(ARIA_context *ctx) static inline int aria_crypt_uses_sboxes(ARIA_context *ctx) { +#ifdef USE_GFNI_AVX + if (ctx->use_gfni_avx) + return 0; +#endif #ifdef USE_AESNI_AVX if (ctx->use_aesni_avx) return 0; @@ -1014,6 +1021,13 @@ aria_crypt(ARIA_context *ctx, byte *out, const byte *in, int rounds = ctx->rounds; int rkidx = 0; +#ifdef USE_GFNI_AVX + if (ctx->use_gfni_avx) + { + _gcry_aria_gfni_avx_crypt_blk1(ctx, out, in, key); + return ASM_EXTRA_STACK; + } +#endif #ifdef USE_AESNI_AVX if (ctx->use_aesni_avx) { -- 2.53.0 From 007bsd at proton.me Thu Nov 5 21:31:23 2026 From: 007bsd at proton.me (007bsd) Date: Thu, 05 Nov 2026 20:31:23 +0000 Subject: sntrup761: implicit-rejection key differs from the specification since 4e963e91 Message-ID: Hello, libgcrypt's sntrup761 decapsulation returns a different rejection key from the specification since a constant-time refactor in 2025. I found no attack (reasoning below), so I am reporting it here as a normal bug with a one-line fix. Summary ------- On a rejected ciphertext, sntrup761_dec() returns HashSession(0, Encode(r') XOR rho, C) instead of the specification's HashSession(0, rho, C) (NTRU Prime round 3, Decap). The accept path is unaffected. - File: cipher/sntrup761.c, sntrup761_dec(), lines 1038-1041 (master 53742c7e, 1.12.4) - Cause: commit 4e963e91 (2025-09-17), "sntrup761: use const-time helpers for memory comparison and cond move", and its 1.11 branch cherry-pick 7ff58b28; posted as [PATCH 06/10], https://lists.gnupg.org/pipermail/gcrypt-devel/2025-September/005961.html - Affected: 1.11.3, 1.12.0 to 1.12.4, master - Correct: 1.11.0 to 1.11.2 How to reproduce ---------------- The program below (sntrup761_reject_key.c) uses only the public gcry_kem_* API. It decapsulates 8 rejected ciphertexts (one bit flipped in the confirmation hash) and compares each key with the specification formula computed from rho in the secret key: cc sntrup761_reject_key.c -lgcrypt -o sntrup761_reject_key ./sntrup761_reject_key 1.11.2: rejected ciphertexts matching the specification: 8/8 -> MATCH 1.12.4: rejected ciphertexts matching the specification: 0/8 -> DIFF Independently, liboqs decapsulating the same secret key and ciphertext bytes gives the same accept key but a different reject key (0/8), while OpenSSH, leancrypto and liboqs all match the specification (8/8). Root cause ---------- The original SUPERCOP line was for (i = 0; i < Inputs_bytes; ++i) r_enc[i] ^= mask & (r_enc[i] ^ rho[i]); which on reject sets r_enc = rho. Commit 4e963e91 replaced it with for (i = 0; i < Inputs_bytes; ++i) tmp[i] = r_enc[i] ^ rho[i]; _gcry_ct_memmov_cond (r_enc, tmp, Inputs_bytes, mask & 1); which on reject sets r_enc = r_enc ^ rho: the second XOR is lost. Neither tests/t-kem.c nor tests/t-sntrup761.c checks a rejection key, so the change was not caught. Impact ------ I found no attack. The full input ciphertext C is still hashed, so distinct rejected ciphertexts give distinct keys, and the key stays unpredictable without rho. The effect is interoperability: libgcrypt's rejection keys differ from every other implementation, and any reject-path test vector fails. libssh with the gcrypt backend uses this code for sntrup761x25519-sha512 (src/sntrup761.c). Suggested fix ------------- Move rho itself, as the original code did: - for (i = 0; i < Inputs_bytes; ++i) - tmp[i] = r_enc[i] ^ rho[i]; - _gcry_ct_memmov_cond (r_enc, tmp, Inputs_bytes, mask & 1); + _gcry_ct_memmov_cond (r_enc, rho, Inputs_bytes, mask & 1); (and drop the now unused tmp and i). With this change, 1.12.4 matches the specification 8/8 and tests/t-kem and t-sntrup761 still pass. AI tools assisted the analysis; every result above was reproduced and checked by hand. If you fix it, please credit Bhabani Sankar Das (https://github.com/007bsd). -------------------------- sntrup761_reject_key.c -------------------------- /* sntrup761 implicit-rejection key check for libgcrypt (public gcry_kem_* API). * * Decapsulates a rejected ciphertext (one bit flipped in an honest one) and * compares the result with the NTRU Prime round 3 rejection key, * K = Hash_prefix(0, Hash_prefix(3, rho) || C), * Hash_prefix(b, x) = SHA-512(b || x)[0..31], * where rho is the 191-byte value stored in the secret key * (sk = 2*Small_bytes || pk || rho || cache, as in SUPERCOP) and C is the * full input ciphertext. * * Build: cc sntrup761_reject_key.c -lgcrypt -o sntrup761_reject_key * Output "MATCH" = conformant, "DIFF" = rejection key differs from the spec. */ #include #include #include #define SMALL_BYTES 191 #define CACHE_BYTES 32 static void hash_prefix (unsigned char out[32], unsigned char b, const unsigned char *x, size_t xlen) { unsigned char full[64]; gcry_md_hd_t h; gcry_md_open (&h, GCRY_MD_SHA512, 0); gcry_md_putc (h, b); gcry_md_write (h, x, xlen); memcpy (full, gcry_md_read (h, GCRY_MD_SHA512), 64); gcry_md_close (h); memcpy (out, full, 32); } int main (void) { static unsigned char pk[GCRY_KEM_SNTRUP761_PUBKEY_LEN]; static unsigned char sk[GCRY_KEM_SNTRUP761_SECKEY_LEN]; static unsigned char ct[GCRY_KEM_SNTRUP761_CIPHER_LEN]; static unsigned char buf[32 + GCRY_KEM_SNTRUP761_CIPHER_LEN]; unsigned char ss[32], k_rej[32], inner[32], spec[32]; const unsigned char *rho; int bit, ok = 0, n = 8; if (!gcry_check_version (NULL)) return 2; gcry_control (GCRYCTL_INITIALIZATION_FINISHED, 0); printf ("libgcrypt %s\n", gcry_check_version (NULL)); if (gcry_kem_keypair (GCRY_KEM_SNTRUP761, pk, sizeof pk, sk, sizeof sk) || gcry_kem_encap (GCRY_KEM_SNTRUP761, pk, sizeof pk, ct, sizeof ct, ss, sizeof ss, NULL, 0)) return 2; rho = sk + sizeof sk - CACHE_BYTES - SMALL_BYTES; hash_prefix (inner, 3, rho, SMALL_BYTES); for (bit = 0; bit < n; bit++) { /* Flip one bit in the trailing confirmation hash: rejected, and it still decrypts to the same r'. */ ct[sizeof ct - 1 - bit / 8] ^= (unsigned char)(1 << (bit % 8)); if (gcry_kem_decap (GCRY_KEM_SNTRUP761, sk, sizeof sk, ct, sizeof ct, k_rej, sizeof k_rej, NULL, 0)) return 2; memcpy (buf, inner, 32); memcpy (buf + 32, ct, sizeof ct); hash_prefix (spec, 0, buf, sizeof buf); ok += !memcmp (k_rej, spec, 32); ct[sizeof ct - 1 - bit / 8] ^= (unsigned char)(1 << (bit % 8)); } printf ("rejected ciphertexts matching the specification: %d/%d -> %s\n", ok, n, ok == n ? "MATCH" : "DIFF"); return ok == n ? 0 : 1; } From jussi.kivilinna at iki.fi Fri Nov 6 09:07:20 2026 From: jussi.kivilinna at iki.fi (Jussi Kivilinna) Date: Fri, 6 Nov 2026 10:07:20 +0200 Subject: [PATCH 1/4] aria: use little-endian word order for encrypt/decrypt Message-ID: <20261106080723.291622-1-jussi.kivilinna@iki.fi> * cipher/aria-aesni-avx-amd64.S (aria_ark_8way): Use plain byte order for round key. * cipher/aria-aesni-avx2-amd64.S (aria_ark_8way): Likewise. * cipher/aria-gfni-avx512-amd64.S (aria_ark_16way): Likewise. * cipher/aria.c (key_rc, sboxes): Convert to little-endian. (bswap16x2): New. (get_u8, make_u32, aria_m, aria_last_round): Adjust for little-endian words. (aria_diff_byte): Use bswap16x2; make always inline. (aria_gsrk): Byte-swap output round key. (aria_set_encrypt_key): Load key as little-endian; byte-swap w0..w3 before aria_gsrk. (aria_crypt, aria_crypt_2blks): Load and store blocks as little-endian. -- Generic implementation used big-endian 32-bit words, which needed byte swaps for every block on little-endian hosts. ARIA round function is not tied to word endianness, so switch to little-endian words and byte-swap only around GSRK in key setup. Round keys are now stored in plain byte order and x86 assembly round key loads are adjusted to match. Generic CBC decryption with clang on Zen5 goes from 12.21 to 9.77 cycles/byte. Signed-off-by: Jussi Kivilinna --- cipher/aria-aesni-avx-amd64.S | 16 +- cipher/aria-aesni-avx2-amd64.S | 16 +- cipher/aria-gfni-avx512-amd64.S | 32 +- cipher/aria.c | 667 +++++++++++++++++--------------- 4 files changed, 379 insertions(+), 352 deletions(-) diff --git a/cipher/aria-aesni-avx-amd64.S b/cipher/aria-aesni-avx-amd64.S index b177ca5e..ee542b00 100644 --- a/cipher/aria-aesni-avx-amd64.S +++ b/cipher/aria-aesni-avx-amd64.S @@ -352,22 +352,22 @@ idx, round) \ /* AddRoundKey */ \ vmovd ((round * 16) + idx + 0)(rk), t0; \ - vpshufb .Lthree_x16 rRIP, t0, t2; \ + vpshufb t1, t0, t2; \ vpxor t2, x0, x0; \ - vpshufb .Ltwo_x16 rRIP, t0, t2; \ - vpxor t2, x1, x1; \ vpshufb .Lone_x16 rRIP, t0, t2; \ + vpxor t2, x1, x1; \ + vpshufb .Ltwo_x16 rRIP, t0, t2; \ vpxor t2, x2, x2; \ - vpshufb t1, t0, t2; \ + vpshufb .Lthree_x16 rRIP, t0, t2; \ vpxor t2, x3, x3; \ vmovd ((round * 16) + idx + 4)(rk), t0; \ - vpshufb .Lthree_x16 rRIP, t0, t2; \ + vpshufb t1, t0, t2; \ vpxor t2, x4, x4; \ - vpshufb .Ltwo_x16 rRIP, t0, t2; \ - vpxor t2, x5, x5; \ vpshufb .Lone_x16 rRIP, t0, t2; \ + vpxor t2, x5, x5; \ + vpshufb .Ltwo_x16 rRIP, t0, t2; \ vpxor t2, x6, x6; \ - vpshufb t1, t0, t2; \ + vpshufb .Lthree_x16 rRIP, t0, t2; \ vpxor t2, x7, x7; #ifdef CONFIG_AS_GFNI diff --git a/cipher/aria-aesni-avx2-amd64.S b/cipher/aria-aesni-avx2-amd64.S index 99eca542..ccb27ea0 100644 --- a/cipher/aria-aesni-avx2-amd64.S +++ b/cipher/aria-aesni-avx2-amd64.S @@ -314,21 +314,21 @@ x4, x5, x6, x7, \ t0, rk, idx, round) \ /* AddRoundKey */ \ - vpbroadcastb ((round * 16) + idx + 3)(rk), t0; \ + vpbroadcastb ((round * 16) + idx + 0)(rk), t0; \ vpxor t0, x0, x0; \ - vpbroadcastb ((round * 16) + idx + 2)(rk), t0; \ - vpxor t0, x1, x1; \ vpbroadcastb ((round * 16) + idx + 1)(rk), t0; \ + vpxor t0, x1, x1; \ + vpbroadcastb ((round * 16) + idx + 2)(rk), t0; \ vpxor t0, x2, x2; \ - vpbroadcastb ((round * 16) + idx + 0)(rk), t0; \ + vpbroadcastb ((round * 16) + idx + 3)(rk), t0; \ vpxor t0, x3, x3; \ - vpbroadcastb ((round * 16) + idx + 7)(rk), t0; \ + vpbroadcastb ((round * 16) + idx + 4)(rk), t0; \ vpxor t0, x4, x4; \ - vpbroadcastb ((round * 16) + idx + 6)(rk), t0; \ - vpxor t0, x5, x5; \ vpbroadcastb ((round * 16) + idx + 5)(rk), t0; \ + vpxor t0, x5, x5; \ + vpbroadcastb ((round * 16) + idx + 6)(rk), t0; \ vpxor t0, x6, x6; \ - vpbroadcastb ((round * 16) + idx + 4)(rk), t0; \ + vpbroadcastb ((round * 16) + idx + 7)(rk), t0; \ vpxor t0, x7, x7; #ifdef CONFIG_AS_GFNI diff --git a/cipher/aria-gfni-avx512-amd64.S b/cipher/aria-gfni-avx512-amd64.S index c25caf86..47d93329 100644 --- a/cipher/aria-gfni-avx512-amd64.S +++ b/cipher/aria-gfni-avx512-amd64.S @@ -308,37 +308,37 @@ y4, y5, y6, y7, \ t0, rk, round) \ /* AddRoundKey */ \ - vpbroadcastb ((round * 16) + 3)(rk), t0; \ + vpbroadcastb ((round * 16) + 0)(rk), t0; \ vpxorq t0, x0, x0; \ - vpbroadcastb ((round * 16) + 2)(rk), t0; \ - vpxorq t0, x1, x1; \ vpbroadcastb ((round * 16) + 1)(rk), t0; \ + vpxorq t0, x1, x1; \ + vpbroadcastb ((round * 16) + 2)(rk), t0; \ vpxorq t0, x2, x2; \ - vpbroadcastb ((round * 16) + 0)(rk), t0; \ + vpbroadcastb ((round * 16) + 3)(rk), t0; \ vpxorq t0, x3, x3; \ - vpbroadcastb ((round * 16) + 7)(rk), t0; \ + vpbroadcastb ((round * 16) + 4)(rk), t0; \ vpxorq t0, x4, x4; \ - vpbroadcastb ((round * 16) + 6)(rk), t0; \ - vpxorq t0, x5, x5; \ vpbroadcastb ((round * 16) + 5)(rk), t0; \ + vpxorq t0, x5, x5; \ + vpbroadcastb ((round * 16) + 6)(rk), t0; \ vpxorq t0, x6, x6; \ - vpbroadcastb ((round * 16) + 4)(rk), t0; \ + vpbroadcastb ((round * 16) + 7)(rk), t0; \ vpxorq t0, x7, x7; \ - vpbroadcastb ((round * 16) + 11)(rk), t0; \ + vpbroadcastb ((round * 16) + 8)(rk), t0; \ vpxorq t0, y0, y0; \ - vpbroadcastb ((round * 16) + 10)(rk), t0; \ - vpxorq t0, y1, y1; \ vpbroadcastb ((round * 16) + 9)(rk), t0; \ + vpxorq t0, y1, y1; \ + vpbroadcastb ((round * 16) + 10)(rk), t0; \ vpxorq t0, y2, y2; \ - vpbroadcastb ((round * 16) + 8)(rk), t0; \ + vpbroadcastb ((round * 16) + 11)(rk), t0; \ vpxorq t0, y3, y3; \ - vpbroadcastb ((round * 16) + 15)(rk), t0; \ + vpbroadcastb ((round * 16) + 12)(rk), t0; \ vpxorq t0, y4, y4; \ - vpbroadcastb ((round * 16) + 14)(rk), t0; \ - vpxorq t0, y5, y5; \ vpbroadcastb ((round * 16) + 13)(rk), t0; \ + vpxorq t0, y5, y5; \ + vpbroadcastb ((round * 16) + 14)(rk), t0; \ vpxorq t0, y6, y6; \ - vpbroadcastb ((round * 16) + 12)(rk), t0; \ + vpbroadcastb ((round * 16) + 15)(rk), t0; \ vpxorq t0, y7, y7; #define aria_sbox_8way_gfni(x0, x1, x2, x3, \ diff --git a/cipher/aria.c b/cipher/aria.c index 227affb4..80fe185b 100644 --- a/cipher/aria.c +++ b/cipher/aria.c @@ -159,11 +159,11 @@ typedef struct static const u32 key_rc[20] = { - 0x517cc1b7, 0x27220a94, 0xfe13abe8, 0xfa9a6ee0, - 0x6db14acc, 0x9e21c820, 0xff28b1d5, 0xef5de2b0, - 0xdb92371d, 0x2126e970, 0x03249775, 0x04e8c90e, - 0x517cc1b7, 0x27220a94, 0xfe13abe8, 0xfa9a6ee0, - 0x6db14acc, 0x9e21c820, 0xff28b1d5, 0xef5de2b0 + 0xb7c17c51, 0x940a2227, 0xe8ab13fe, 0xe06e9afa, + 0xcc4ab16d, 0x20c8219e, 0xd5b128ff, 0xb0e25def, + 0x1d3792db, 0x70e92621, 0x75972403, 0x0ec9e804, + 0xb7c17c51, 0x940a2227, 0xe8ab13fe, 0xe06e9afa, + 0xcc4ab16d, 0x20c8219e, 0xd5b128ff, 0xb0e25def }; @@ -182,268 +182,268 @@ static struct { 0, }, { /* s1 */ - 0x00636363, 0x007c7c7c, 0x00777777, 0x007b7b7b, - 0x00f2f2f2, 0x006b6b6b, 0x006f6f6f, 0x00c5c5c5, - 0x00303030, 0x00010101, 0x00676767, 0x002b2b2b, - 0x00fefefe, 0x00d7d7d7, 0x00ababab, 0x00767676, - 0x00cacaca, 0x00828282, 0x00c9c9c9, 0x007d7d7d, - 0x00fafafa, 0x00595959, 0x00474747, 0x00f0f0f0, - 0x00adadad, 0x00d4d4d4, 0x00a2a2a2, 0x00afafaf, - 0x009c9c9c, 0x00a4a4a4, 0x00727272, 0x00c0c0c0, - 0x00b7b7b7, 0x00fdfdfd, 0x00939393, 0x00262626, - 0x00363636, 0x003f3f3f, 0x00f7f7f7, 0x00cccccc, - 0x00343434, 0x00a5a5a5, 0x00e5e5e5, 0x00f1f1f1, - 0x00717171, 0x00d8d8d8, 0x00313131, 0x00151515, - 0x00040404, 0x00c7c7c7, 0x00232323, 0x00c3c3c3, - 0x00181818, 0x00969696, 0x00050505, 0x009a9a9a, - 0x00070707, 0x00121212, 0x00808080, 0x00e2e2e2, - 0x00ebebeb, 0x00272727, 0x00b2b2b2, 0x00757575, - 0x00090909, 0x00838383, 0x002c2c2c, 0x001a1a1a, - 0x001b1b1b, 0x006e6e6e, 0x005a5a5a, 0x00a0a0a0, - 0x00525252, 0x003b3b3b, 0x00d6d6d6, 0x00b3b3b3, - 0x00292929, 0x00e3e3e3, 0x002f2f2f, 0x00848484, - 0x00535353, 0x00d1d1d1, 0x00000000, 0x00ededed, - 0x00202020, 0x00fcfcfc, 0x00b1b1b1, 0x005b5b5b, - 0x006a6a6a, 0x00cbcbcb, 0x00bebebe, 0x00393939, - 0x004a4a4a, 0x004c4c4c, 0x00585858, 0x00cfcfcf, - 0x00d0d0d0, 0x00efefef, 0x00aaaaaa, 0x00fbfbfb, - 0x00434343, 0x004d4d4d, 0x00333333, 0x00858585, - 0x00454545, 0x00f9f9f9, 0x00020202, 0x007f7f7f, - 0x00505050, 0x003c3c3c, 0x009f9f9f, 0x00a8a8a8, - 0x00515151, 0x00a3a3a3, 0x00404040, 0x008f8f8f, - 0x00929292, 0x009d9d9d, 0x00383838, 0x00f5f5f5, - 0x00bcbcbc, 0x00b6b6b6, 0x00dadada, 0x00212121, - 0x00101010, 0x00ffffff, 0x00f3f3f3, 0x00d2d2d2, - 0x00cdcdcd, 0x000c0c0c, 0x00131313, 0x00ececec, - 0x005f5f5f, 0x00979797, 0x00444444, 0x00171717, - 0x00c4c4c4, 0x00a7a7a7, 0x007e7e7e, 0x003d3d3d, - 0x00646464, 0x005d5d5d, 0x00191919, 0x00737373, - 0x00606060, 0x00818181, 0x004f4f4f, 0x00dcdcdc, - 0x00222222, 0x002a2a2a, 0x00909090, 0x00888888, - 0x00464646, 0x00eeeeee, 0x00b8b8b8, 0x00141414, - 0x00dedede, 0x005e5e5e, 0x000b0b0b, 0x00dbdbdb, - 0x00e0e0e0, 0x00323232, 0x003a3a3a, 0x000a0a0a, - 0x00494949, 0x00060606, 0x00242424, 0x005c5c5c, - 0x00c2c2c2, 0x00d3d3d3, 0x00acacac, 0x00626262, - 0x00919191, 0x00959595, 0x00e4e4e4, 0x00797979, - 0x00e7e7e7, 0x00c8c8c8, 0x00373737, 0x006d6d6d, - 0x008d8d8d, 0x00d5d5d5, 0x004e4e4e, 0x00a9a9a9, - 0x006c6c6c, 0x00565656, 0x00f4f4f4, 0x00eaeaea, - 0x00656565, 0x007a7a7a, 0x00aeaeae, 0x00080808, - 0x00bababa, 0x00787878, 0x00252525, 0x002e2e2e, - 0x001c1c1c, 0x00a6a6a6, 0x00b4b4b4, 0x00c6c6c6, - 0x00e8e8e8, 0x00dddddd, 0x00747474, 0x001f1f1f, - 0x004b4b4b, 0x00bdbdbd, 0x008b8b8b, 0x008a8a8a, - 0x00707070, 0x003e3e3e, 0x00b5b5b5, 0x00666666, - 0x00484848, 0x00030303, 0x00f6f6f6, 0x000e0e0e, - 0x00616161, 0x00353535, 0x00575757, 0x00b9b9b9, - 0x00868686, 0x00c1c1c1, 0x001d1d1d, 0x009e9e9e, - 0x00e1e1e1, 0x00f8f8f8, 0x00989898, 0x00111111, - 0x00696969, 0x00d9d9d9, 0x008e8e8e, 0x00949494, - 0x009b9b9b, 0x001e1e1e, 0x00878787, 0x00e9e9e9, - 0x00cecece, 0x00555555, 0x00282828, 0x00dfdfdf, - 0x008c8c8c, 0x00a1a1a1, 0x00898989, 0x000d0d0d, - 0x00bfbfbf, 0x00e6e6e6, 0x00424242, 0x00686868, - 0x00414141, 0x00999999, 0x002d2d2d, 0x000f0f0f, - 0x00b0b0b0, 0x00545454, 0x00bbbbbb, 0x00161616 + 0x63636300, 0x7c7c7c00, 0x77777700, 0x7b7b7b00, + 0xf2f2f200, 0x6b6b6b00, 0x6f6f6f00, 0xc5c5c500, + 0x30303000, 0x01010100, 0x67676700, 0x2b2b2b00, + 0xfefefe00, 0xd7d7d700, 0xababab00, 0x76767600, + 0xcacaca00, 0x82828200, 0xc9c9c900, 0x7d7d7d00, + 0xfafafa00, 0x59595900, 0x47474700, 0xf0f0f000, + 0xadadad00, 0xd4d4d400, 0xa2a2a200, 0xafafaf00, + 0x9c9c9c00, 0xa4a4a400, 0x72727200, 0xc0c0c000, + 0xb7b7b700, 0xfdfdfd00, 0x93939300, 0x26262600, + 0x36363600, 0x3f3f3f00, 0xf7f7f700, 0xcccccc00, + 0x34343400, 0xa5a5a500, 0xe5e5e500, 0xf1f1f100, + 0x71717100, 0xd8d8d800, 0x31313100, 0x15151500, + 0x04040400, 0xc7c7c700, 0x23232300, 0xc3c3c300, + 0x18181800, 0x96969600, 0x05050500, 0x9a9a9a00, + 0x07070700, 0x12121200, 0x80808000, 0xe2e2e200, + 0xebebeb00, 0x27272700, 0xb2b2b200, 0x75757500, + 0x09090900, 0x83838300, 0x2c2c2c00, 0x1a1a1a00, + 0x1b1b1b00, 0x6e6e6e00, 0x5a5a5a00, 0xa0a0a000, + 0x52525200, 0x3b3b3b00, 0xd6d6d600, 0xb3b3b300, + 0x29292900, 0xe3e3e300, 0x2f2f2f00, 0x84848400, + 0x53535300, 0xd1d1d100, 0x00000000, 0xededed00, + 0x20202000, 0xfcfcfc00, 0xb1b1b100, 0x5b5b5b00, + 0x6a6a6a00, 0xcbcbcb00, 0xbebebe00, 0x39393900, + 0x4a4a4a00, 0x4c4c4c00, 0x58585800, 0xcfcfcf00, + 0xd0d0d000, 0xefefef00, 0xaaaaaa00, 0xfbfbfb00, + 0x43434300, 0x4d4d4d00, 0x33333300, 0x85858500, + 0x45454500, 0xf9f9f900, 0x02020200, 0x7f7f7f00, + 0x50505000, 0x3c3c3c00, 0x9f9f9f00, 0xa8a8a800, + 0x51515100, 0xa3a3a300, 0x40404000, 0x8f8f8f00, + 0x92929200, 0x9d9d9d00, 0x38383800, 0xf5f5f500, + 0xbcbcbc00, 0xb6b6b600, 0xdadada00, 0x21212100, + 0x10101000, 0xffffff00, 0xf3f3f300, 0xd2d2d200, + 0xcdcdcd00, 0x0c0c0c00, 0x13131300, 0xececec00, + 0x5f5f5f00, 0x97979700, 0x44444400, 0x17171700, + 0xc4c4c400, 0xa7a7a700, 0x7e7e7e00, 0x3d3d3d00, + 0x64646400, 0x5d5d5d00, 0x19191900, 0x73737300, + 0x60606000, 0x81818100, 0x4f4f4f00, 0xdcdcdc00, + 0x22222200, 0x2a2a2a00, 0x90909000, 0x88888800, + 0x46464600, 0xeeeeee00, 0xb8b8b800, 0x14141400, + 0xdedede00, 0x5e5e5e00, 0x0b0b0b00, 0xdbdbdb00, + 0xe0e0e000, 0x32323200, 0x3a3a3a00, 0x0a0a0a00, + 0x49494900, 0x06060600, 0x24242400, 0x5c5c5c00, + 0xc2c2c200, 0xd3d3d300, 0xacacac00, 0x62626200, + 0x91919100, 0x95959500, 0xe4e4e400, 0x79797900, + 0xe7e7e700, 0xc8c8c800, 0x37373700, 0x6d6d6d00, + 0x8d8d8d00, 0xd5d5d500, 0x4e4e4e00, 0xa9a9a900, + 0x6c6c6c00, 0x56565600, 0xf4f4f400, 0xeaeaea00, + 0x65656500, 0x7a7a7a00, 0xaeaeae00, 0x08080800, + 0xbababa00, 0x78787800, 0x25252500, 0x2e2e2e00, + 0x1c1c1c00, 0xa6a6a600, 0xb4b4b400, 0xc6c6c600, + 0xe8e8e800, 0xdddddd00, 0x74747400, 0x1f1f1f00, + 0x4b4b4b00, 0xbdbdbd00, 0x8b8b8b00, 0x8a8a8a00, + 0x70707000, 0x3e3e3e00, 0xb5b5b500, 0x66666600, + 0x48484800, 0x03030300, 0xf6f6f600, 0x0e0e0e00, + 0x61616100, 0x35353500, 0x57575700, 0xb9b9b900, + 0x86868600, 0xc1c1c100, 0x1d1d1d00, 0x9e9e9e00, + 0xe1e1e100, 0xf8f8f800, 0x98989800, 0x11111100, + 0x69696900, 0xd9d9d900, 0x8e8e8e00, 0x94949400, + 0x9b9b9b00, 0x1e1e1e00, 0x87878700, 0xe9e9e900, + 0xcecece00, 0x55555500, 0x28282800, 0xdfdfdf00, + 0x8c8c8c00, 0xa1a1a100, 0x89898900, 0x0d0d0d00, + 0xbfbfbf00, 0xe6e6e600, 0x42424200, 0x68686800, + 0x41414100, 0x99999900, 0x2d2d2d00, 0x0f0f0f00, + 0xb0b0b000, 0x54545400, 0xbbbbbb00, 0x16161600 }, { /* s2 */ - 0xe200e2e2, 0x4e004e4e, 0x54005454, 0xfc00fcfc, - 0x94009494, 0xc200c2c2, 0x4a004a4a, 0xcc00cccc, - 0x62006262, 0x0d000d0d, 0x6a006a6a, 0x46004646, - 0x3c003c3c, 0x4d004d4d, 0x8b008b8b, 0xd100d1d1, - 0x5e005e5e, 0xfa00fafa, 0x64006464, 0xcb00cbcb, - 0xb400b4b4, 0x97009797, 0xbe00bebe, 0x2b002b2b, - 0xbc00bcbc, 0x77007777, 0x2e002e2e, 0x03000303, - 0xd300d3d3, 0x19001919, 0x59005959, 0xc100c1c1, - 0x1d001d1d, 0x06000606, 0x41004141, 0x6b006b6b, - 0x55005555, 0xf000f0f0, 0x99009999, 0x69006969, - 0xea00eaea, 0x9c009c9c, 0x18001818, 0xae00aeae, - 0x63006363, 0xdf00dfdf, 0xe700e7e7, 0xbb00bbbb, - 0x00000000, 0x73007373, 0x66006666, 0xfb00fbfb, - 0x96009696, 0x4c004c4c, 0x85008585, 0xe400e4e4, - 0x3a003a3a, 0x09000909, 0x45004545, 0xaa00aaaa, - 0x0f000f0f, 0xee00eeee, 0x10001010, 0xeb00ebeb, - 0x2d002d2d, 0x7f007f7f, 0xf400f4f4, 0x29002929, - 0xac00acac, 0xcf00cfcf, 0xad00adad, 0x91009191, - 0x8d008d8d, 0x78007878, 0xc800c8c8, 0x95009595, - 0xf900f9f9, 0x2f002f2f, 0xce00cece, 0xcd00cdcd, - 0x08000808, 0x7a007a7a, 0x88008888, 0x38003838, - 0x5c005c5c, 0x83008383, 0x2a002a2a, 0x28002828, - 0x47004747, 0xdb00dbdb, 0xb800b8b8, 0xc700c7c7, - 0x93009393, 0xa400a4a4, 0x12001212, 0x53005353, - 0xff00ffff, 0x87008787, 0x0e000e0e, 0x31003131, - 0x36003636, 0x21002121, 0x58005858, 0x48004848, - 0x01000101, 0x8e008e8e, 0x37003737, 0x74007474, - 0x32003232, 0xca00caca, 0xe900e9e9, 0xb100b1b1, - 0xb700b7b7, 0xab00abab, 0x0c000c0c, 0xd700d7d7, - 0xc400c4c4, 0x56005656, 0x42004242, 0x26002626, - 0x07000707, 0x98009898, 0x60006060, 0xd900d9d9, - 0xb600b6b6, 0xb900b9b9, 0x11001111, 0x40004040, - 0xec00ecec, 0x20002020, 0x8c008c8c, 0xbd00bdbd, - 0xa000a0a0, 0xc900c9c9, 0x84008484, 0x04000404, - 0x49004949, 0x23002323, 0xf100f1f1, 0x4f004f4f, - 0x50005050, 0x1f001f1f, 0x13001313, 0xdc00dcdc, - 0xd800d8d8, 0xc000c0c0, 0x9e009e9e, 0x57005757, - 0xe300e3e3, 0xc300c3c3, 0x7b007b7b, 0x65006565, - 0x3b003b3b, 0x02000202, 0x8f008f8f, 0x3e003e3e, - 0xe800e8e8, 0x25002525, 0x92009292, 0xe500e5e5, - 0x15001515, 0xdd00dddd, 0xfd00fdfd, 0x17001717, - 0xa900a9a9, 0xbf00bfbf, 0xd400d4d4, 0x9a009a9a, - 0x7e007e7e, 0xc500c5c5, 0x39003939, 0x67006767, - 0xfe00fefe, 0x76007676, 0x9d009d9d, 0x43004343, - 0xa700a7a7, 0xe100e1e1, 0xd000d0d0, 0xf500f5f5, - 0x68006868, 0xf200f2f2, 0x1b001b1b, 0x34003434, - 0x70007070, 0x05000505, 0xa300a3a3, 0x8a008a8a, - 0xd500d5d5, 0x79007979, 0x86008686, 0xa800a8a8, - 0x30003030, 0xc600c6c6, 0x51005151, 0x4b004b4b, - 0x1e001e1e, 0xa600a6a6, 0x27002727, 0xf600f6f6, - 0x35003535, 0xd200d2d2, 0x6e006e6e, 0x24002424, - 0x16001616, 0x82008282, 0x5f005f5f, 0xda00dada, - 0xe600e6e6, 0x75007575, 0xa200a2a2, 0xef00efef, - 0x2c002c2c, 0xb200b2b2, 0x1c001c1c, 0x9f009f9f, - 0x5d005d5d, 0x6f006f6f, 0x80008080, 0x0a000a0a, - 0x72007272, 0x44004444, 0x9b009b9b, 0x6c006c6c, - 0x90009090, 0x0b000b0b, 0x5b005b5b, 0x33003333, - 0x7d007d7d, 0x5a005a5a, 0x52005252, 0xf300f3f3, - 0x61006161, 0xa100a1a1, 0xf700f7f7, 0xb000b0b0, - 0xd600d6d6, 0x3f003f3f, 0x7c007c7c, 0x6d006d6d, - 0xed00eded, 0x14001414, 0xe000e0e0, 0xa500a5a5, - 0x3d003d3d, 0x22002222, 0xb300b3b3, 0xf800f8f8, - 0x89008989, 0xde00dede, 0x71007171, 0x1a001a1a, - 0xaf00afaf, 0xba00baba, 0xb500b5b5, 0x81008181 + 0xe2e200e2, 0x4e4e004e, 0x54540054, 0xfcfc00fc, + 0x94940094, 0xc2c200c2, 0x4a4a004a, 0xcccc00cc, + 0x62620062, 0x0d0d000d, 0x6a6a006a, 0x46460046, + 0x3c3c003c, 0x4d4d004d, 0x8b8b008b, 0xd1d100d1, + 0x5e5e005e, 0xfafa00fa, 0x64640064, 0xcbcb00cb, + 0xb4b400b4, 0x97970097, 0xbebe00be, 0x2b2b002b, + 0xbcbc00bc, 0x77770077, 0x2e2e002e, 0x03030003, + 0xd3d300d3, 0x19190019, 0x59590059, 0xc1c100c1, + 0x1d1d001d, 0x06060006, 0x41410041, 0x6b6b006b, + 0x55550055, 0xf0f000f0, 0x99990099, 0x69690069, + 0xeaea00ea, 0x9c9c009c, 0x18180018, 0xaeae00ae, + 0x63630063, 0xdfdf00df, 0xe7e700e7, 0xbbbb00bb, + 0x00000000, 0x73730073, 0x66660066, 0xfbfb00fb, + 0x96960096, 0x4c4c004c, 0x85850085, 0xe4e400e4, + 0x3a3a003a, 0x09090009, 0x45450045, 0xaaaa00aa, + 0x0f0f000f, 0xeeee00ee, 0x10100010, 0xebeb00eb, + 0x2d2d002d, 0x7f7f007f, 0xf4f400f4, 0x29290029, + 0xacac00ac, 0xcfcf00cf, 0xadad00ad, 0x91910091, + 0x8d8d008d, 0x78780078, 0xc8c800c8, 0x95950095, + 0xf9f900f9, 0x2f2f002f, 0xcece00ce, 0xcdcd00cd, + 0x08080008, 0x7a7a007a, 0x88880088, 0x38380038, + 0x5c5c005c, 0x83830083, 0x2a2a002a, 0x28280028, + 0x47470047, 0xdbdb00db, 0xb8b800b8, 0xc7c700c7, + 0x93930093, 0xa4a400a4, 0x12120012, 0x53530053, + 0xffff00ff, 0x87870087, 0x0e0e000e, 0x31310031, + 0x36360036, 0x21210021, 0x58580058, 0x48480048, + 0x01010001, 0x8e8e008e, 0x37370037, 0x74740074, + 0x32320032, 0xcaca00ca, 0xe9e900e9, 0xb1b100b1, + 0xb7b700b7, 0xabab00ab, 0x0c0c000c, 0xd7d700d7, + 0xc4c400c4, 0x56560056, 0x42420042, 0x26260026, + 0x07070007, 0x98980098, 0x60600060, 0xd9d900d9, + 0xb6b600b6, 0xb9b900b9, 0x11110011, 0x40400040, + 0xecec00ec, 0x20200020, 0x8c8c008c, 0xbdbd00bd, + 0xa0a000a0, 0xc9c900c9, 0x84840084, 0x04040004, + 0x49490049, 0x23230023, 0xf1f100f1, 0x4f4f004f, + 0x50500050, 0x1f1f001f, 0x13130013, 0xdcdc00dc, + 0xd8d800d8, 0xc0c000c0, 0x9e9e009e, 0x57570057, + 0xe3e300e3, 0xc3c300c3, 0x7b7b007b, 0x65650065, + 0x3b3b003b, 0x02020002, 0x8f8f008f, 0x3e3e003e, + 0xe8e800e8, 0x25250025, 0x92920092, 0xe5e500e5, + 0x15150015, 0xdddd00dd, 0xfdfd00fd, 0x17170017, + 0xa9a900a9, 0xbfbf00bf, 0xd4d400d4, 0x9a9a009a, + 0x7e7e007e, 0xc5c500c5, 0x39390039, 0x67670067, + 0xfefe00fe, 0x76760076, 0x9d9d009d, 0x43430043, + 0xa7a700a7, 0xe1e100e1, 0xd0d000d0, 0xf5f500f5, + 0x68680068, 0xf2f200f2, 0x1b1b001b, 0x34340034, + 0x70700070, 0x05050005, 0xa3a300a3, 0x8a8a008a, + 0xd5d500d5, 0x79790079, 0x86860086, 0xa8a800a8, + 0x30300030, 0xc6c600c6, 0x51510051, 0x4b4b004b, + 0x1e1e001e, 0xa6a600a6, 0x27270027, 0xf6f600f6, + 0x35350035, 0xd2d200d2, 0x6e6e006e, 0x24240024, + 0x16160016, 0x82820082, 0x5f5f005f, 0xdada00da, + 0xe6e600e6, 0x75750075, 0xa2a200a2, 0xefef00ef, + 0x2c2c002c, 0xb2b200b2, 0x1c1c001c, 0x9f9f009f, + 0x5d5d005d, 0x6f6f006f, 0x80800080, 0x0a0a000a, + 0x72720072, 0x44440044, 0x9b9b009b, 0x6c6c006c, + 0x90900090, 0x0b0b000b, 0x5b5b005b, 0x33330033, + 0x7d7d007d, 0x5a5a005a, 0x52520052, 0xf3f300f3, + 0x61610061, 0xa1a100a1, 0xf7f700f7, 0xb0b000b0, + 0xd6d600d6, 0x3f3f003f, 0x7c7c007c, 0x6d6d006d, + 0xeded00ed, 0x14140014, 0xe0e000e0, 0xa5a500a5, + 0x3d3d003d, 0x22220022, 0xb3b300b3, 0xf8f800f8, + 0x89890089, 0xdede00de, 0x71710071, 0x1a1a001a, + 0xafaf00af, 0xbaba00ba, 0xb5b500b5, 0x81810081 }, { /* x1 */ - 0x52520052, 0x09090009, 0x6a6a006a, 0xd5d500d5, - 0x30300030, 0x36360036, 0xa5a500a5, 0x38380038, - 0xbfbf00bf, 0x40400040, 0xa3a300a3, 0x9e9e009e, - 0x81810081, 0xf3f300f3, 0xd7d700d7, 0xfbfb00fb, - 0x7c7c007c, 0xe3e300e3, 0x39390039, 0x82820082, - 0x9b9b009b, 0x2f2f002f, 0xffff00ff, 0x87870087, - 0x34340034, 0x8e8e008e, 0x43430043, 0x44440044, - 0xc4c400c4, 0xdede00de, 0xe9e900e9, 0xcbcb00cb, - 0x54540054, 0x7b7b007b, 0x94940094, 0x32320032, - 0xa6a600a6, 0xc2c200c2, 0x23230023, 0x3d3d003d, - 0xeeee00ee, 0x4c4c004c, 0x95950095, 0x0b0b000b, - 0x42420042, 0xfafa00fa, 0xc3c300c3, 0x4e4e004e, - 0x08080008, 0x2e2e002e, 0xa1a100a1, 0x66660066, - 0x28280028, 0xd9d900d9, 0x24240024, 0xb2b200b2, - 0x76760076, 0x5b5b005b, 0xa2a200a2, 0x49490049, - 0x6d6d006d, 0x8b8b008b, 0xd1d100d1, 0x25250025, - 0x72720072, 0xf8f800f8, 0xf6f600f6, 0x64640064, - 0x86860086, 0x68680068, 0x98980098, 0x16160016, - 0xd4d400d4, 0xa4a400a4, 0x5c5c005c, 0xcccc00cc, - 0x5d5d005d, 0x65650065, 0xb6b600b6, 0x92920092, - 0x6c6c006c, 0x70700070, 0x48480048, 0x50500050, - 0xfdfd00fd, 0xeded00ed, 0xb9b900b9, 0xdada00da, - 0x5e5e005e, 0x15150015, 0x46460046, 0x57570057, - 0xa7a700a7, 0x8d8d008d, 0x9d9d009d, 0x84840084, - 0x90900090, 0xd8d800d8, 0xabab00ab, 0x00000000, - 0x8c8c008c, 0xbcbc00bc, 0xd3d300d3, 0x0a0a000a, - 0xf7f700f7, 0xe4e400e4, 0x58580058, 0x05050005, - 0xb8b800b8, 0xb3b300b3, 0x45450045, 0x06060006, - 0xd0d000d0, 0x2c2c002c, 0x1e1e001e, 0x8f8f008f, - 0xcaca00ca, 0x3f3f003f, 0x0f0f000f, 0x02020002, - 0xc1c100c1, 0xafaf00af, 0xbdbd00bd, 0x03030003, - 0x01010001, 0x13130013, 0x8a8a008a, 0x6b6b006b, - 0x3a3a003a, 0x91910091, 0x11110011, 0x41410041, - 0x4f4f004f, 0x67670067, 0xdcdc00dc, 0xeaea00ea, - 0x97970097, 0xf2f200f2, 0xcfcf00cf, 0xcece00ce, - 0xf0f000f0, 0xb4b400b4, 0xe6e600e6, 0x73730073, - 0x96960096, 0xacac00ac, 0x74740074, 0x22220022, - 0xe7e700e7, 0xadad00ad, 0x35350035, 0x85850085, - 0xe2e200e2, 0xf9f900f9, 0x37370037, 0xe8e800e8, - 0x1c1c001c, 0x75750075, 0xdfdf00df, 0x6e6e006e, - 0x47470047, 0xf1f100f1, 0x1a1a001a, 0x71710071, - 0x1d1d001d, 0x29290029, 0xc5c500c5, 0x89890089, - 0x6f6f006f, 0xb7b700b7, 0x62620062, 0x0e0e000e, - 0xaaaa00aa, 0x18180018, 0xbebe00be, 0x1b1b001b, - 0xfcfc00fc, 0x56560056, 0x3e3e003e, 0x4b4b004b, - 0xc6c600c6, 0xd2d200d2, 0x79790079, 0x20200020, - 0x9a9a009a, 0xdbdb00db, 0xc0c000c0, 0xfefe00fe, - 0x78780078, 0xcdcd00cd, 0x5a5a005a, 0xf4f400f4, - 0x1f1f001f, 0xdddd00dd, 0xa8a800a8, 0x33330033, - 0x88880088, 0x07070007, 0xc7c700c7, 0x31310031, - 0xb1b100b1, 0x12120012, 0x10100010, 0x59590059, - 0x27270027, 0x80800080, 0xecec00ec, 0x5f5f005f, - 0x60600060, 0x51510051, 0x7f7f007f, 0xa9a900a9, - 0x19190019, 0xb5b500b5, 0x4a4a004a, 0x0d0d000d, - 0x2d2d002d, 0xe5e500e5, 0x7a7a007a, 0x9f9f009f, - 0x93930093, 0xc9c900c9, 0x9c9c009c, 0xefef00ef, - 0xa0a000a0, 0xe0e000e0, 0x3b3b003b, 0x4d4d004d, - 0xaeae00ae, 0x2a2a002a, 0xf5f500f5, 0xb0b000b0, - 0xc8c800c8, 0xebeb00eb, 0xbbbb00bb, 0x3c3c003c, - 0x83830083, 0x53530053, 0x99990099, 0x61610061, - 0x17170017, 0x2b2b002b, 0x04040004, 0x7e7e007e, - 0xbaba00ba, 0x77770077, 0xd6d600d6, 0x26260026, - 0xe1e100e1, 0x69690069, 0x14140014, 0x63630063, - 0x55550055, 0x21210021, 0x0c0c000c, 0x7d7d007d + 0x52005252, 0x09000909, 0x6a006a6a, 0xd500d5d5, + 0x30003030, 0x36003636, 0xa500a5a5, 0x38003838, + 0xbf00bfbf, 0x40004040, 0xa300a3a3, 0x9e009e9e, + 0x81008181, 0xf300f3f3, 0xd700d7d7, 0xfb00fbfb, + 0x7c007c7c, 0xe300e3e3, 0x39003939, 0x82008282, + 0x9b009b9b, 0x2f002f2f, 0xff00ffff, 0x87008787, + 0x34003434, 0x8e008e8e, 0x43004343, 0x44004444, + 0xc400c4c4, 0xde00dede, 0xe900e9e9, 0xcb00cbcb, + 0x54005454, 0x7b007b7b, 0x94009494, 0x32003232, + 0xa600a6a6, 0xc200c2c2, 0x23002323, 0x3d003d3d, + 0xee00eeee, 0x4c004c4c, 0x95009595, 0x0b000b0b, + 0x42004242, 0xfa00fafa, 0xc300c3c3, 0x4e004e4e, + 0x08000808, 0x2e002e2e, 0xa100a1a1, 0x66006666, + 0x28002828, 0xd900d9d9, 0x24002424, 0xb200b2b2, + 0x76007676, 0x5b005b5b, 0xa200a2a2, 0x49004949, + 0x6d006d6d, 0x8b008b8b, 0xd100d1d1, 0x25002525, + 0x72007272, 0xf800f8f8, 0xf600f6f6, 0x64006464, + 0x86008686, 0x68006868, 0x98009898, 0x16001616, + 0xd400d4d4, 0xa400a4a4, 0x5c005c5c, 0xcc00cccc, + 0x5d005d5d, 0x65006565, 0xb600b6b6, 0x92009292, + 0x6c006c6c, 0x70007070, 0x48004848, 0x50005050, + 0xfd00fdfd, 0xed00eded, 0xb900b9b9, 0xda00dada, + 0x5e005e5e, 0x15001515, 0x46004646, 0x57005757, + 0xa700a7a7, 0x8d008d8d, 0x9d009d9d, 0x84008484, + 0x90009090, 0xd800d8d8, 0xab00abab, 0x00000000, + 0x8c008c8c, 0xbc00bcbc, 0xd300d3d3, 0x0a000a0a, + 0xf700f7f7, 0xe400e4e4, 0x58005858, 0x05000505, + 0xb800b8b8, 0xb300b3b3, 0x45004545, 0x06000606, + 0xd000d0d0, 0x2c002c2c, 0x1e001e1e, 0x8f008f8f, + 0xca00caca, 0x3f003f3f, 0x0f000f0f, 0x02000202, + 0xc100c1c1, 0xaf00afaf, 0xbd00bdbd, 0x03000303, + 0x01000101, 0x13001313, 0x8a008a8a, 0x6b006b6b, + 0x3a003a3a, 0x91009191, 0x11001111, 0x41004141, + 0x4f004f4f, 0x67006767, 0xdc00dcdc, 0xea00eaea, + 0x97009797, 0xf200f2f2, 0xcf00cfcf, 0xce00cece, + 0xf000f0f0, 0xb400b4b4, 0xe600e6e6, 0x73007373, + 0x96009696, 0xac00acac, 0x74007474, 0x22002222, + 0xe700e7e7, 0xad00adad, 0x35003535, 0x85008585, + 0xe200e2e2, 0xf900f9f9, 0x37003737, 0xe800e8e8, + 0x1c001c1c, 0x75007575, 0xdf00dfdf, 0x6e006e6e, + 0x47004747, 0xf100f1f1, 0x1a001a1a, 0x71007171, + 0x1d001d1d, 0x29002929, 0xc500c5c5, 0x89008989, + 0x6f006f6f, 0xb700b7b7, 0x62006262, 0x0e000e0e, + 0xaa00aaaa, 0x18001818, 0xbe00bebe, 0x1b001b1b, + 0xfc00fcfc, 0x56005656, 0x3e003e3e, 0x4b004b4b, + 0xc600c6c6, 0xd200d2d2, 0x79007979, 0x20002020, + 0x9a009a9a, 0xdb00dbdb, 0xc000c0c0, 0xfe00fefe, + 0x78007878, 0xcd00cdcd, 0x5a005a5a, 0xf400f4f4, + 0x1f001f1f, 0xdd00dddd, 0xa800a8a8, 0x33003333, + 0x88008888, 0x07000707, 0xc700c7c7, 0x31003131, + 0xb100b1b1, 0x12001212, 0x10001010, 0x59005959, + 0x27002727, 0x80008080, 0xec00ecec, 0x5f005f5f, + 0x60006060, 0x51005151, 0x7f007f7f, 0xa900a9a9, + 0x19001919, 0xb500b5b5, 0x4a004a4a, 0x0d000d0d, + 0x2d002d2d, 0xe500e5e5, 0x7a007a7a, 0x9f009f9f, + 0x93009393, 0xc900c9c9, 0x9c009c9c, 0xef00efef, + 0xa000a0a0, 0xe000e0e0, 0x3b003b3b, 0x4d004d4d, + 0xae00aeae, 0x2a002a2a, 0xf500f5f5, 0xb000b0b0, + 0xc800c8c8, 0xeb00ebeb, 0xbb00bbbb, 0x3c003c3c, + 0x83008383, 0x53005353, 0x99009999, 0x61006161, + 0x17001717, 0x2b002b2b, 0x04000404, 0x7e007e7e, + 0xba00baba, 0x77007777, 0xd600d6d6, 0x26002626, + 0xe100e1e1, 0x69006969, 0x14001414, 0x63006363, + 0x55005555, 0x21002121, 0x0c000c0c, 0x7d007d7d }, { /* x2 */ - 0x30303000, 0x68686800, 0x99999900, 0x1b1b1b00, - 0x87878700, 0xb9b9b900, 0x21212100, 0x78787800, - 0x50505000, 0x39393900, 0xdbdbdb00, 0xe1e1e100, - 0x72727200, 0x09090900, 0x62626200, 0x3c3c3c00, - 0x3e3e3e00, 0x7e7e7e00, 0x5e5e5e00, 0x8e8e8e00, - 0xf1f1f100, 0xa0a0a000, 0xcccccc00, 0xa3a3a300, - 0x2a2a2a00, 0x1d1d1d00, 0xfbfbfb00, 0xb6b6b600, - 0xd6d6d600, 0x20202000, 0xc4c4c400, 0x8d8d8d00, - 0x81818100, 0x65656500, 0xf5f5f500, 0x89898900, - 0xcbcbcb00, 0x9d9d9d00, 0x77777700, 0xc6c6c600, - 0x57575700, 0x43434300, 0x56565600, 0x17171700, - 0xd4d4d400, 0x40404000, 0x1a1a1a00, 0x4d4d4d00, - 0xc0c0c000, 0x63636300, 0x6c6c6c00, 0xe3e3e300, - 0xb7b7b700, 0xc8c8c800, 0x64646400, 0x6a6a6a00, - 0x53535300, 0xaaaaaa00, 0x38383800, 0x98989800, - 0x0c0c0c00, 0xf4f4f400, 0x9b9b9b00, 0xededed00, - 0x7f7f7f00, 0x22222200, 0x76767600, 0xafafaf00, - 0xdddddd00, 0x3a3a3a00, 0x0b0b0b00, 0x58585800, - 0x67676700, 0x88888800, 0x06060600, 0xc3c3c300, - 0x35353500, 0x0d0d0d00, 0x01010100, 0x8b8b8b00, - 0x8c8c8c00, 0xc2c2c200, 0xe6e6e600, 0x5f5f5f00, - 0x02020200, 0x24242400, 0x75757500, 0x93939300, - 0x66666600, 0x1e1e1e00, 0xe5e5e500, 0xe2e2e200, - 0x54545400, 0xd8d8d800, 0x10101000, 0xcecece00, - 0x7a7a7a00, 0xe8e8e800, 0x08080800, 0x2c2c2c00, - 0x12121200, 0x97979700, 0x32323200, 0xababab00, - 0xb4b4b400, 0x27272700, 0x0a0a0a00, 0x23232300, - 0xdfdfdf00, 0xefefef00, 0xcacaca00, 0xd9d9d900, - 0xb8b8b800, 0xfafafa00, 0xdcdcdc00, 0x31313100, - 0x6b6b6b00, 0xd1d1d100, 0xadadad00, 0x19191900, - 0x49494900, 0xbdbdbd00, 0x51515100, 0x96969600, - 0xeeeeee00, 0xe4e4e400, 0xa8a8a800, 0x41414100, - 0xdadada00, 0xffffff00, 0xcdcdcd00, 0x55555500, - 0x86868600, 0x36363600, 0xbebebe00, 0x61616100, - 0x52525200, 0xf8f8f800, 0xbbbbbb00, 0x0e0e0e00, - 0x82828200, 0x48484800, 0x69696900, 0x9a9a9a00, - 0xe0e0e000, 0x47474700, 0x9e9e9e00, 0x5c5c5c00, - 0x04040400, 0x4b4b4b00, 0x34343400, 0x15151500, - 0x79797900, 0x26262600, 0xa7a7a700, 0xdedede00, - 0x29292900, 0xaeaeae00, 0x92929200, 0xd7d7d700, - 0x84848400, 0xe9e9e900, 0xd2d2d200, 0xbababa00, - 0x5d5d5d00, 0xf3f3f300, 0xc5c5c500, 0xb0b0b000, - 0xbfbfbf00, 0xa4a4a400, 0x3b3b3b00, 0x71717100, - 0x44444400, 0x46464600, 0x2b2b2b00, 0xfcfcfc00, - 0xebebeb00, 0x6f6f6f00, 0xd5d5d500, 0xf6f6f600, - 0x14141400, 0xfefefe00, 0x7c7c7c00, 0x70707000, - 0x5a5a5a00, 0x7d7d7d00, 0xfdfdfd00, 0x2f2f2f00, - 0x18181800, 0x83838300, 0x16161600, 0xa5a5a500, - 0x91919100, 0x1f1f1f00, 0x05050500, 0x95959500, - 0x74747400, 0xa9a9a900, 0xc1c1c100, 0x5b5b5b00, - 0x4a4a4a00, 0x85858500, 0x6d6d6d00, 0x13131300, - 0x07070700, 0x4f4f4f00, 0x4e4e4e00, 0x45454500, - 0xb2b2b200, 0x0f0f0f00, 0xc9c9c900, 0x1c1c1c00, - 0xa6a6a600, 0xbcbcbc00, 0xececec00, 0x73737300, - 0x90909000, 0x7b7b7b00, 0xcfcfcf00, 0x59595900, - 0x8f8f8f00, 0xa1a1a100, 0xf9f9f900, 0x2d2d2d00, - 0xf2f2f200, 0xb1b1b100, 0x00000000, 0x94949400, - 0x37373700, 0x9f9f9f00, 0xd0d0d000, 0x2e2e2e00, - 0x9c9c9c00, 0x6e6e6e00, 0x28282800, 0x3f3f3f00, - 0x80808000, 0xf0f0f000, 0x3d3d3d00, 0xd3d3d300, - 0x25252500, 0x8a8a8a00, 0xb5b5b500, 0xe7e7e700, - 0x42424200, 0xb3b3b300, 0xc7c7c700, 0xeaeaea00, - 0xf7f7f700, 0x4c4c4c00, 0x11111100, 0x33333300, - 0x03030300, 0xa2a2a200, 0xacacac00, 0x60606000 + 0x00303030, 0x00686868, 0x00999999, 0x001b1b1b, + 0x00878787, 0x00b9b9b9, 0x00212121, 0x00787878, + 0x00505050, 0x00393939, 0x00dbdbdb, 0x00e1e1e1, + 0x00727272, 0x00090909, 0x00626262, 0x003c3c3c, + 0x003e3e3e, 0x007e7e7e, 0x005e5e5e, 0x008e8e8e, + 0x00f1f1f1, 0x00a0a0a0, 0x00cccccc, 0x00a3a3a3, + 0x002a2a2a, 0x001d1d1d, 0x00fbfbfb, 0x00b6b6b6, + 0x00d6d6d6, 0x00202020, 0x00c4c4c4, 0x008d8d8d, + 0x00818181, 0x00656565, 0x00f5f5f5, 0x00898989, + 0x00cbcbcb, 0x009d9d9d, 0x00777777, 0x00c6c6c6, + 0x00575757, 0x00434343, 0x00565656, 0x00171717, + 0x00d4d4d4, 0x00404040, 0x001a1a1a, 0x004d4d4d, + 0x00c0c0c0, 0x00636363, 0x006c6c6c, 0x00e3e3e3, + 0x00b7b7b7, 0x00c8c8c8, 0x00646464, 0x006a6a6a, + 0x00535353, 0x00aaaaaa, 0x00383838, 0x00989898, + 0x000c0c0c, 0x00f4f4f4, 0x009b9b9b, 0x00ededed, + 0x007f7f7f, 0x00222222, 0x00767676, 0x00afafaf, + 0x00dddddd, 0x003a3a3a, 0x000b0b0b, 0x00585858, + 0x00676767, 0x00888888, 0x00060606, 0x00c3c3c3, + 0x00353535, 0x000d0d0d, 0x00010101, 0x008b8b8b, + 0x008c8c8c, 0x00c2c2c2, 0x00e6e6e6, 0x005f5f5f, + 0x00020202, 0x00242424, 0x00757575, 0x00939393, + 0x00666666, 0x001e1e1e, 0x00e5e5e5, 0x00e2e2e2, + 0x00545454, 0x00d8d8d8, 0x00101010, 0x00cecece, + 0x007a7a7a, 0x00e8e8e8, 0x00080808, 0x002c2c2c, + 0x00121212, 0x00979797, 0x00323232, 0x00ababab, + 0x00b4b4b4, 0x00272727, 0x000a0a0a, 0x00232323, + 0x00dfdfdf, 0x00efefef, 0x00cacaca, 0x00d9d9d9, + 0x00b8b8b8, 0x00fafafa, 0x00dcdcdc, 0x00313131, + 0x006b6b6b, 0x00d1d1d1, 0x00adadad, 0x00191919, + 0x00494949, 0x00bdbdbd, 0x00515151, 0x00969696, + 0x00eeeeee, 0x00e4e4e4, 0x00a8a8a8, 0x00414141, + 0x00dadada, 0x00ffffff, 0x00cdcdcd, 0x00555555, + 0x00868686, 0x00363636, 0x00bebebe, 0x00616161, + 0x00525252, 0x00f8f8f8, 0x00bbbbbb, 0x000e0e0e, + 0x00828282, 0x00484848, 0x00696969, 0x009a9a9a, + 0x00e0e0e0, 0x00474747, 0x009e9e9e, 0x005c5c5c, + 0x00040404, 0x004b4b4b, 0x00343434, 0x00151515, + 0x00797979, 0x00262626, 0x00a7a7a7, 0x00dedede, + 0x00292929, 0x00aeaeae, 0x00929292, 0x00d7d7d7, + 0x00848484, 0x00e9e9e9, 0x00d2d2d2, 0x00bababa, + 0x005d5d5d, 0x00f3f3f3, 0x00c5c5c5, 0x00b0b0b0, + 0x00bfbfbf, 0x00a4a4a4, 0x003b3b3b, 0x00717171, + 0x00444444, 0x00464646, 0x002b2b2b, 0x00fcfcfc, + 0x00ebebeb, 0x006f6f6f, 0x00d5d5d5, 0x00f6f6f6, + 0x00141414, 0x00fefefe, 0x007c7c7c, 0x00707070, + 0x005a5a5a, 0x007d7d7d, 0x00fdfdfd, 0x002f2f2f, + 0x00181818, 0x00838383, 0x00161616, 0x00a5a5a5, + 0x00919191, 0x001f1f1f, 0x00050505, 0x00959595, + 0x00747474, 0x00a9a9a9, 0x00c1c1c1, 0x005b5b5b, + 0x004a4a4a, 0x00858585, 0x006d6d6d, 0x00131313, + 0x00070707, 0x004f4f4f, 0x004e4e4e, 0x00454545, + 0x00b2b2b2, 0x000f0f0f, 0x00c9c9c9, 0x001c1c1c, + 0x00a6a6a6, 0x00bcbcbc, 0x00ececec, 0x00737373, + 0x00909090, 0x007b7b7b, 0x00cfcfcf, 0x00595959, + 0x008f8f8f, 0x00a1a1a1, 0x00f9f9f9, 0x002d2d2d, + 0x00f2f2f2, 0x00b1b1b1, 0x00000000, 0x00949494, + 0x00373737, 0x009f9f9f, 0x00d0d0d0, 0x002e2e2e, + 0x009c9c9c, 0x006e6e6e, 0x00282828, 0x003f3f3f, + 0x00808080, 0x00f0f0f0, 0x003d3d3d, 0x00d3d3d3, + 0x00252525, 0x008a8a8a, 0x00b5b5b5, 0x00e7e7e7, + 0x00424242, 0x00b3b3b3, 0x00c7c7c7, 0x00eaeaea, + 0x00f7f7f7, 0x004c4c4c, 0x00111111, 0x00333333, + 0x00030303, 0x00a2a2a2, 0x00acacac, 0x00606060 }, 0 }; @@ -636,28 +636,34 @@ prefetch_sboxes(void) } -static ALWAYS_INLINE -u32 rotr32(u32 v, u32 r) +static ALWAYS_INLINE u32 +rotr32(u32 v, u32 r) { return ror(v, r); } +static ALWAYS_INLINE u32 +bswap16x2(u32 v) +{ + return ((v << 8) & 0xff00ff00) ^ ((v >> 8) & 0x00ff00ff); +} + static ALWAYS_INLINE u32 get_u8(u32 x, u32 y) { - return (x >> ((3 - y) * 8)) & 0xFF; + return (x >> (y * 8)) & 0xFF; } static ALWAYS_INLINE u32 make_u32(byte v0, byte v1, byte v2, byte v3) { - return ((u32)v0 << 24) | ((u32)v1 << 16) | ((u32)v2 << 8) | ((u32)v3); + return ((u32)v3 << 24) | ((u32)v2 << 16) | ((u32)v1 << 8) | ((u32)v0); } static ALWAYS_INLINE u32 aria_m(u32 t0) { - return rotr32(t0, 8) ^ rotr32(t0 ^ rotr32(t0, 8), 16); + return rotr32(t0, 24) ^ rotr32(t0 ^ rotr32(t0, 24), 16); } /* S-Box Layer 1 + M */ @@ -718,9 +724,10 @@ aria_diff_word(u32 *t0, u32 *t1, u32 *t2, u32 *t3) } /* Byte-level diffusion */ -static inline void aria_diff_byte(u32 *t1, u32 *t2, u32 *t3) +static ALWAYS_INLINE void +aria_diff_byte(u32 *t1, u32 *t2, u32 *t3) { - *t1 = ((*t1 << 8) & 0xff00ff00) ^ ((*t1 >> 8) & 0x00ff00ff); + *t1 = bswap16x2(*t1); *t2 = rotr32(*t2, 16); *t3 = _gcry_bswap32(*t3); } @@ -760,20 +767,20 @@ static ALWAYS_INLINE void aria_last_round(u32 *t0, u32 *t1, u32 *t2, u32 *t3) { *t0 = make_u32((byte)(sboxes.x1[get_u8(*t0, 0)]), - (byte)(sboxes.x2[get_u8(*t0, 1)] >> 24), - (byte)(sboxes.s1[get_u8(*t0, 2)]), + (byte)(sboxes.x2[get_u8(*t0, 1)]), + (byte)(sboxes.s1[get_u8(*t0, 2)] >> 24), (byte)(sboxes.s2[get_u8(*t0, 3)])); *t1 = make_u32((byte)(sboxes.x1[get_u8(*t1, 0)]), - (byte)(sboxes.x2[get_u8(*t1, 1)] >> 24), - (byte)(sboxes.s1[get_u8(*t1, 2)]), + (byte)(sboxes.x2[get_u8(*t1, 1)]), + (byte)(sboxes.s1[get_u8(*t1, 2)] >> 24), (byte)(sboxes.s2[get_u8(*t1, 3)])); *t2 = make_u32((byte)(sboxes.x1[get_u8(*t2, 0)]), - (byte)(sboxes.x2[get_u8(*t2, 1)] >> 24), - (byte)(sboxes.s1[get_u8(*t2, 2)]), + (byte)(sboxes.x2[get_u8(*t2, 1)]), + (byte)(sboxes.s1[get_u8(*t2, 2)] >> 24), (byte)(sboxes.s2[get_u8(*t2, 3)])); *t3 = make_u32((byte)(sboxes.x1[get_u8(*t3, 0)]), - (byte)(sboxes.x2[get_u8(*t3, 1)] >> 24), - (byte)(sboxes.s1[get_u8(*t3, 2)]), + (byte)(sboxes.x2[get_u8(*t3, 1)]), + (byte)(sboxes.s1[get_u8(*t3, 2)] >> 24), (byte)(sboxes.s2[get_u8(*t3, 3)])); } @@ -784,18 +791,18 @@ aria_gsrk(u32 *rk, u32 *x, u32 *y, u32 n) int q = 4 - (n / 32); int r = n % 32; - rk[0] = (x[0]) ^ - ((y[q % 4]) >> r) ^ - ((y[(q + 3) % 4]) << (32 - r)); - rk[1] = (x[1]) ^ - ((y[(q + 1) % 4]) >> r) ^ - ((y[q % 4]) << (32 - r)); - rk[2] = (x[2]) ^ - ((y[(q + 2) % 4]) >> r) ^ - ((y[(q + 1) % 4]) << (32 - r)); - rk[3] = (x[3]) ^ - ((y[(q + 3) % 4]) >> r) ^ - ((y[(q + 2) % 4]) << (32 - r)); + rk[0] = _gcry_bswap32((x[0]) ^ + ((y[q % 4]) >> r) ^ + ((y[(q + 3) % 4]) << (32 - r))); + rk[1] = _gcry_bswap32((x[1]) ^ + ((y[(q + 1) % 4]) >> r) ^ + ((y[q % 4]) << (32 - r))); + rk[2] = _gcry_bswap32((x[2]) ^ + ((y[(q + 2) % 4]) >> r) ^ + ((y[(q + 1) % 4]) << (32 - r))); + rk[3] = _gcry_bswap32((x[3]) ^ + ((y[(q + 3) % 4]) >> r) ^ + ((y[(q + 2) % 4]) << (32 - r))); } @@ -812,10 +819,10 @@ aria_set_encrypt_key(ARIA_context *ctx, const byte *in_key, u32 key_len) ck = &key_rc[(key_len - 16) / 2]; - w0[0] = buf_get_be32(in_key + 0); - w0[1] = buf_get_be32(in_key + 4); - w0[2] = buf_get_be32(in_key + 8); - w0[3] = buf_get_be32(in_key + 12); + w0[0] = buf_get_le32(in_key + 0); + w0[1] = buf_get_le32(in_key + 4); + w0[2] = buf_get_le32(in_key + 8); + w0[3] = buf_get_le32(in_key + 12); reg0 = w0[0] ^ ck[0]; reg1 = w0[1] ^ ck[1]; @@ -826,12 +833,12 @@ aria_set_encrypt_key(ARIA_context *ctx, const byte *in_key, u32 key_len) if (key_len > 16) { - w1[0] = buf_get_be32(in_key + 16); - w1[1] = buf_get_be32(in_key + 20); + w1[0] = buf_get_le32(in_key + 16); + w1[1] = buf_get_le32(in_key + 20); if (key_len > 24) { - w1[2] = buf_get_be32(in_key + 24); - w1[3] = buf_get_be32(in_key + 28); + w1[2] = buf_get_le32(in_key + 24); + w1[3] = buf_get_le32(in_key + 28); } else { @@ -886,6 +893,26 @@ aria_set_encrypt_key(ARIA_context *ctx, const byte *in_key, u32 key_len) w3[2] = reg2 ^ w1[2]; w3[3] = reg3 ^ w1[3]; + w0[0] = _gcry_bswap32(w0[0]); + w0[1] = _gcry_bswap32(w0[1]); + w0[2] = _gcry_bswap32(w0[2]); + w0[3] = _gcry_bswap32(w0[3]); + + w1[0] = _gcry_bswap32(w1[0]); + w1[1] = _gcry_bswap32(w1[1]); + w1[2] = _gcry_bswap32(w1[2]); + w1[3] = _gcry_bswap32(w1[3]); + + w2[0] = _gcry_bswap32(w2[0]); + w2[1] = _gcry_bswap32(w2[1]); + w2[2] = _gcry_bswap32(w2[2]); + w2[3] = _gcry_bswap32(w2[3]); + + w3[0] = _gcry_bswap32(w3[0]); + w3[1] = _gcry_bswap32(w3[1]); + w3[2] = _gcry_bswap32(w3[2]); + w3[3] = _gcry_bswap32(w3[3]); + aria_gsrk(ctx->enc_key[rkidx], w0, w1, 19); rkidx++; aria_gsrk(ctx->enc_key[rkidx], w1, w2, 19); @@ -972,10 +999,10 @@ aria_crypt(ARIA_context *ctx, byte *out, const byte *in, int rounds = ctx->rounds; int rkidx = 0; - reg0 = buf_get_be32(in + 0); - reg1 = buf_get_be32(in + 4); - reg2 = buf_get_be32(in + 8); - reg3 = buf_get_be32(in + 12); + reg0 = buf_get_le32(in + 0); + reg1 = buf_get_le32(in + 4); + reg2 = buf_get_le32(in + 8); + reg3 = buf_get_le32(in + 12); aria_add_round_key(key[rkidx], ®0, ®1, ®2, ®3); rkidx++; @@ -997,10 +1024,10 @@ aria_crypt(ARIA_context *ctx, byte *out, const byte *in, aria_last_round(®0, ®1, ®2, ®3); aria_add_round_key(key[rkidx], ®0, ®1, ®2, ®3); - buf_put_be32(out + 0, reg0); - buf_put_be32(out + 4, reg1); - buf_put_be32(out + 8, reg2); - buf_put_be32(out + 12, reg3); + buf_put_le32(out + 0, reg0); + buf_put_le32(out + 4, reg1); + buf_put_le32(out + 8, reg2); + buf_put_le32(out + 12, reg3); return 4 * sizeof(void *) + 4 * sizeof(u32); /* stack burn depth */ } @@ -1041,14 +1068,14 @@ aria_crypt_2blks(ARIA_context *ctx, byte *out, const byte *in, int rounds = ctx->rounds; int rkidx = 0; - ra0 = buf_get_be32(in + 0); - ra1 = buf_get_be32(in + 4); - ra2 = buf_get_be32(in + 8); - ra3 = buf_get_be32(in + 12); - rb0 = buf_get_be32(in + 16); - rb1 = buf_get_be32(in + 20); - rb2 = buf_get_be32(in + 24); - rb3 = buf_get_be32(in + 28); + ra0 = buf_get_le32(in + 0); + ra1 = buf_get_le32(in + 4); + ra2 = buf_get_le32(in + 8); + ra3 = buf_get_le32(in + 12); + rb0 = buf_get_le32(in + 16); + rb1 = buf_get_le32(in + 20); + rb2 = buf_get_le32(in + 24); + rb3 = buf_get_le32(in + 28); while (1) { @@ -1074,14 +1101,14 @@ aria_crypt_2blks(ARIA_context *ctx, byte *out, const byte *in, aria_add_round_key(key[rkidx], &ra0, &ra1, &ra2, &ra3); aria_add_round_key(key[rkidx], &rb0, &rb1, &rb2, &rb3); - buf_put_be32(out + 0, ra0); - buf_put_be32(out + 4, ra1); - buf_put_be32(out + 8, ra2); - buf_put_be32(out + 12, ra3); - buf_put_be32(out + 16, rb0); - buf_put_be32(out + 20, rb1); - buf_put_be32(out + 24, rb2); - buf_put_be32(out + 28, rb3); + buf_put_le32(out + 0, ra0); + buf_put_le32(out + 4, ra1); + buf_put_le32(out + 8, ra2); + buf_put_le32(out + 12, ra3); + buf_put_le32(out + 16, rb0); + buf_put_le32(out + 20, rb1); + buf_put_le32(out + 24, rb2); + buf_put_le32(out + 28, rb3); return 4 * sizeof(void *) + 8 * sizeof(u32); /* stack burn depth */ } -- 2.53.0 From jussi.kivilinna at iki.fi Sat Nov 7 06:30:05 2026 From: jussi.kivilinna at iki.fi (Jussi Kivilinna) Date: Sat, 7 Nov 2026 07:30:05 +0200 Subject: [PATCH 2/3] salsa20: allow setting block counter with 16-byte IV In-Reply-To: <20261107053006.8047-1-jussi.kivilinna@iki.fi> References: <20261107053006.8047-1-jussi.kivilinna@iki.fi> Message-ID: <20261107053006.8047-2-jussi.kivilinna@iki.fi> * cipher/salsa20-amd64.S (_gcry_salsa20_amd64_ivsetup): Load block counter from IV. * cipher/salsa20.c (SALSA20_CTR_SIZE): New. (salsa20_ivsetup, salsa20_ivsetup_neon): Set block counter from IV. (salsa20_setiv): Accept 16-byte IV. * tests/basic.c (check_salsa20_block_counter): New. (check_cipher_modes): Run 'check_salsa20_block_counter'. -- ChaCha20 already accepts 16-byte IV with block counter. Salsa20 had only 8-byte nonce, so programs needing other block counter values had to carry own copy of algorithm. Signed-off-by: Jussi Kivilinna --- cipher/salsa20-amd64.S | 4 +- cipher/salsa20.c | 21 ++++----- tests/basic.c | 104 +++++++++++++++++++++++++++++++++++++++++ 3 files changed, 115 insertions(+), 14 deletions(-) diff --git a/cipher/salsa20-amd64.S b/cipher/salsa20-amd64.S index ce1495c4..d1fdc5da 100644 --- a/cipher/salsa20-amd64.S +++ b/cipher/salsa20-amd64.S @@ -94,9 +94,9 @@ ELF(.type _gcry_salsa20_amd64_ivsetup, at function;) _gcry_salsa20_amd64_ivsetup: CFI_STARTPROC(); movl 0(%rsi),%r8d + movl 8(%rsi),%r9d + movl 12(%rsi),%eax movl 4(%rsi),%esi - mov $0,%r9 - mov $0,%rax movl %r8d,24(%rdi) movl %esi,44(%rdi) movl %r9d,32(%rdi) diff --git a/cipher/salsa20.c b/cipher/salsa20.c index 176542b2..21d5b344 100644 --- a/cipher/salsa20.c +++ b/cipher/salsa20.c @@ -64,6 +64,7 @@ #define SALSA20_MAX_KEY_SIZE 32 /* Bytes. */ #define SALSA20_BLOCK_SIZE 64 /* Bytes. */ #define SALSA20_IV_SIZE 8 /* Bytes. */ +#define SALSA20_CTR_SIZE 16 /* Bytes, IV and block counter. */ #define SALSA20_INPUT_LENGTH 16 /* Bytes. */ /* Number of rounds. The standard uses 20 rounds. In any case the @@ -270,9 +271,8 @@ static void salsa20_ivsetup(SALSA20_context_t *ctx, const byte *iv) { ctx->input[6] = LE_READ_UINT32(iv + 0); ctx->input[7] = LE_READ_UINT32(iv + 4); - /* Reset the block counter. */ - ctx->input[8] = 0; - ctx->input[9] = 0; + ctx->input[8] = LE_READ_UINT32(iv + 8); + ctx->input[9] = LE_READ_UINT32(iv + 12); } #endif /*!USE_AMD64*/ @@ -292,9 +292,7 @@ salsa20_core_neon (u32 *dst, SALSA20_context_t *ctx, unsigned int rounds) static void salsa20_ivsetup_neon(SALSA20_context_t *ctx, const byte *iv) { - memcpy(ctx->input + 8, iv, 8); - /* Reset the block counter. */ - memset(ctx->input + 10, 0, 8); + memcpy(ctx->input + 8, iv, SALSA20_CTR_SIZE); } static void @@ -382,15 +380,14 @@ static void salsa20_setiv (void *context, const byte *iv, size_t ivlen) { SALSA20_context_t *ctx = (SALSA20_context_t *)context; - byte tmp[SALSA20_IV_SIZE]; + byte tmp[SALSA20_CTR_SIZE]; - if (iv && ivlen != SALSA20_IV_SIZE) + if (iv && ivlen != SALSA20_IV_SIZE && ivlen != SALSA20_CTR_SIZE) log_info ("WARNING: salsa20_setiv: bad ivlen=%u\n", (u32)ivlen); - if (!iv || ivlen != SALSA20_IV_SIZE) - memset (tmp, 0, sizeof(tmp)); - else - memcpy (tmp, iv, SALSA20_IV_SIZE); + memset (tmp, 0, sizeof(tmp)); + if (iv && (ivlen == SALSA20_IV_SIZE || ivlen == SALSA20_CTR_SIZE)) + memcpy (tmp, iv, ivlen); ctx->ivsetup (ctx, tmp); diff --git a/tests/basic.c b/tests/basic.c index 4305082b..875e8228 100644 --- a/tests/basic.c +++ b/tests/basic.c @@ -11258,6 +11258,107 @@ check_stream_cipher (void) } +#if USE_SALSA20 +static void +check_salsa20_block_counter (void) +{ + static const struct + { + int algo; + const char *iv; + const char *out; + } tv[] = + { + { GCRY_CIPHER_SALSA20, + "0102030405060708feffffff00000000", + "29f8daaf88e94b8803eebdd7c6529f503a270cbcea797681c3a8419c7e69ec8f" + "34bb34fbadbc78d54699b24bd6ccdbb9ea3c81295198ed85338dac20c6888bb2" + "03556063cd90830e614a97c43b4278e3eb6b6a3e91f837e0622c0791679377b8" + "4fc9b35f4794df0edfa202618b304dd8eb1e89c66e2d8dbcb9c46dc0246eb666" + "7553d5b2ebb0245f13b23383e89d7959603772aeeaecdefd07983e2589b60376" + "6ea9c940313ab9447b182d6bc81adc33e6c2d6ad7b065d7ff46b29b47839a5c8" + "e6f3bff8a32d5b94fadfaab81d81d22f30570ef5ddaa066bc9678226c4432cc0" + "bfcc4e52d9604afe2e93b4bd864879ad4c7f862c5422dba9476e955fafbd6cc0" + "03ed0e7f0e5c872a87dc97ee0fb47f45b62dcdcaba5c267d3efe479f97c18e4f" + "35f195f475c64977fb108b6bef5608de7d7d869e252e82f1591b9ac89a42b411" + }, + { GCRY_CIPHER_SALSA20, + "0102030405060708ffffffffffffffff", + "fd719c60c32e5d32097e9fdf3628ac56716f1bb49f4e00315cf639b9508141e8" + "ba1428b9ba29e3ab38036426a9ca9e16482eb254ce5ce2d2b8392dfac1664a29" + "67d3c3a70cf9352b1b35f4babe33ef661658105cad7e18a42496bc51119accd4" + "0953038a9573de32922d9b34660c044637dfdc77037b62c8ca4576ef4c08f650" + }, + { GCRY_CIPHER_SALSA20R12, + "0102030405060708ffffffff00000000", + "b0e67dd1433028591322fbd6ffd2bebbee241181f30a8924fa5972d1c42dafd6" + "a2ffa7e8146837878ec41764e0ff06480b046c9f251e4dce6d84517e0eca3a0d" + "49bc1f43faaad6d5c3adeb1fdaecc0c932825b6febedb8857d15032b873d47a2" + "5df47100b21ac6d525d52a471555b43c335bd952de91a501fd882fe2da14e0c0" + } + }; + static const unsigned char key[33] = + "\x01\x02\x03\x04\x05\x06\x07\x08\x09\x0a\x0b\x0c\x0d\x0e\x0f\x10" + "\x11\x12\x13\x14\x15\x16\x17\x18\x19\x1a\x1b\x1c\x1d\x1e\x1f\x20"; + unsigned char buf[320]; + gcry_cipher_hd_t hd; + gcry_error_t err; + unsigned int i; + + if (verbose) + fprintf (stderr, " Starting Salsa20 block counter checks.\n"); + + for (i = 0; i < DIM (tv); i++) + { + unsigned char *iv, *out; + size_t ivlen, outlen; + + if (gcry_cipher_test_algo (tv[i].algo) && in_fips_mode) + { + if (verbose) + fprintf (stderr, " algorithm %d not available in fips mode\n", + tv[i].algo); + continue; + } + + iv = hex2buffer (tv[i].iv, &ivlen); + out = hex2buffer (tv[i].out, &outlen); + + err = gcry_cipher_open (&hd, tv[i].algo, GCRY_CIPHER_MODE_STREAM, 0); + if (err) + { + fail ("salsa20 counter, gcry_cipher_open failed: %s\n", + gpg_strerror (err)); + xfree (iv); + xfree (out); + continue; + } + + memset (buf, 0, outlen); + err = gcry_cipher_setkey (hd, key, 32); + if (!err) + err = gcry_cipher_setiv (hd, iv, ivlen); + if (!err) + err = gcry_cipher_encrypt (hd, buf, outlen, NULL, 0); + if (err) + fail ("salsa20 counter, test %u failed: %s\n", i, gpg_strerror (err)); + else if (memcmp (buf, out, outlen)) + { + mismatch (out, outlen, buf, outlen); + fail ("salsa20 counter, test %u: mismatch\n", i); + } + + gcry_cipher_close (hd); + xfree (iv); + xfree (out); + } + + if (verbose) + fprintf (stderr, " Completed Salsa20 block counter checks.\n"); +} +#endif /*USE_SALSA20*/ + + static void check_stream_cipher_large_block (void) { @@ -14157,6 +14258,9 @@ check_cipher_modes(void) check_gcm_siv_cipher (); check_gost28147_cipher (); check_stream_cipher (); +#if USE_SALSA20 + check_salsa20_block_counter (); +#endif check_stream_cipher_large_block (); if (verbose) -- 2.53.0 From jussi.kivilinna at iki.fi Sat Nov 7 06:30:06 2026 From: jussi.kivilinna at iki.fi (Jussi Kivilinna) Date: Sat, 7 Nov 2026 07:30:06 +0200 Subject: [PATCH 3/3] tests/t-sntrup761: add checksum test from libntruprime In-Reply-To: <20261107053006.8047-1-jussi.kivilinna@iki.fi> References: <20261107053006.8047-1-jussi.kivilinna@iki.fi> Message-ID: <20261107053006.8047-3-jussi.kivilinna@iki.fi> * tests/basic.c (NEED_MISMATCH): New. (mismatch): Move to... * tests/t-common.h (mismatch): ...here. * tests/t-sntrup761.c (t_sntrup761_md_hash_buffer) (t_sntrup761_ct_not_memequal, t_sntrup761_ct_memmov_cond): Implement instead of stubbing. (salsa20_block, checksum_clear, checksum_update, known_random) (vector_random, corrupt_ciphertext, test_checksums): New. (main): Run 'test_checksums'. -- No test compared sntrup761 output against other implementation. Expected values are from public domain libntruprime test suite, which covers keypair, encapsulation, decapsulation and rejection keys of corrupted ciphertexts. Test is skipped if ChaCha20, Salsa20 or SHA-512 is not available. GnuPG-bug-id: 8542 Signed-off-by: Jussi Kivilinna --- tests/basic.c | 17 +--- tests/t-common.h | 17 ++++ tests/t-sntrup761.c | 216 +++++++++++++++++++++++++++++++++++++++++--- 3 files changed, 220 insertions(+), 30 deletions(-) diff --git a/tests/basic.c b/tests/basic.c index 875e8228..f7a50799 100644 --- a/tests/basic.c +++ b/tests/basic.c @@ -39,6 +39,7 @@ #include "../src/gcrypt-testapi.h" #define PGM "basic" +#define NEED_MISMATCH #include "t-common.h" #if __GNUC__ >= 4 @@ -75,22 +76,6 @@ static int in_fips_mode; #define MAX_DATA_LEN 1040 -static void -mismatch (const void *expected, size_t expectedlen, - const void *computed, size_t computedlen) -{ - const unsigned char *p; - - fprintf (stderr, "expected:"); - for (p = expected; expectedlen; p++, expectedlen--) - fprintf (stderr, " %02x", *p); - fprintf (stderr, "\ncomputed:"); - for (p = computed; computedlen; p++, computedlen--) - fprintf (stderr, " %02x", *p); - fprintf (stderr, "\n"); -} - - /* Convert STRING consisting of hex characters into its binary representation and return it as an allocated buffer. The valid length of the buffer is returned at R_LENGTH. The string is diff --git a/tests/t-common.h b/tests/t-common.h index eb3f03c0..ba327169 100644 --- a/tests/t-common.h +++ b/tests/t-common.h @@ -309,6 +309,23 @@ copy_data (char **buffer, const char *line, int lineno) } #endif +#ifdef NEED_MISMATCH +static void +mismatch (const void *expected, size_t expectedlen, + const void *computed, size_t computedlen) +{ + const unsigned char *ptr; + + fprintf (stderr, "expected:"); + for (ptr = expected; expectedlen; ptr++, expectedlen--) + fprintf (stderr, " %02x", *ptr); + fprintf (stderr, "\ncomputed:"); + for (ptr = computed; computedlen; ptr++, computedlen--) + fprintf (stderr, " %02x", *ptr); + fprintf (stderr, "\n"); +} +#endif + #ifdef NEED_HEX2BUFFER /* Convert STRING consisting of hex characters into its binary representation and return it as an allocated buffer. The valid diff --git a/tests/t-sntrup761.c b/tests/t-sntrup761.c index a8fd55c1..1f1c5318 100644 --- a/tests/t-sntrup761.c +++ b/tests/t-sntrup761.c @@ -34,7 +34,7 @@ #include #include -/* Stub out external dependencies so that including implementation does +/* Redirect internal dependencies so that including implementation does not require linking them. */ #define _gcry_md_hash_buffer t_sntrup761_md_hash_buffer #define _gcry_ct_not_memequal t_sntrup761_ct_not_memequal @@ -56,36 +56,29 @@ t_sntrup761_ct_memmov_cond (void *dst, const void *src, size_t len, #include "../cipher/sntrup761.c" #define PGM "t-sntrup761" +#define NEED_HEX2BUFFER +#define NEED_MISMATCH #include "t-common.h" static void t_sntrup761_md_hash_buffer (int algo, void *digest, const void *buf, size_t len) { - (void)buf; - (void)len; - - if (algo == GCRY_MD_SHA512) - memset(digest, 0, 64); + gcry_md_hash_buffer (algo, digest, buf, len); } static unsigned int t_sntrup761_ct_not_memequal (const void *b1, const void *b2, size_t len) { - (void)b1; - (void)b2; - (void)len; - return 0; + return memcmp (b1, b2, len) != 0; } static void t_sntrup761_ct_memmov_cond (void *dst, const void *src, size_t len, unsigned long op_enable) { - (void)dst; - (void)src; - (void)len; - (void)op_enable; + if (op_enable) + memmove (dst, src, len); } static uint32_t rng_counter; @@ -363,6 +356,200 @@ test_mult (void) } } +/* Inputs and checksums of libntruprime test suite. */ + +#define CHECKSUM_RNG_BYTES 736 +#define CHECKSUM_CT_BYTES (Ciphertexts_bytes + Confirm_bytes) + +static unsigned char checksum_state[64]; +static unsigned char known_random_key[32]; +static unsigned char known_random_buf[CHECKSUM_RNG_BYTES]; +static size_t known_random_pos; +static gcry_cipher_hd_t known_random_hd; +static gcry_cipher_hd_t salsa20_hd; +static uint64_t vector_random_ctr; + +static void +salsa20_block (unsigned char *out, const unsigned char *in, + const unsigned char *key) +{ + gcry_error_t err; + + err = gcry_cipher_setkey (salsa20_hd, key, 32); + if (!err) + err = gcry_cipher_setiv (salsa20_hd, in, 16); + memset (out, 0, 64); + if (!err) + err = gcry_cipher_encrypt (salsa20_hd, out, 64, NULL, 0); + if (err) + die ("Salsa20 failed: %s\n", gpg_strerror (err)); +} + +static void +checksum_clear (void) +{ + memset (checksum_state, 0, sizeof (checksum_state)); + memset (known_random_key, 0, sizeof (known_random_key)); + known_random_pos = CHECKSUM_RNG_BYTES; + vector_random_ctr = 0; +} + +static void +checksum_update (const unsigned char *x, size_t xlen) +{ + unsigned char block[16]; + + while (xlen >= 16) + { + salsa20_block (checksum_state, x, checksum_state); + x += 16; + xlen -= 16; + } + + memset (block, 0, sizeof (block)); + memcpy (block, x, xlen); + block[xlen] = 1; + checksum_state[0] ^= 1; + salsa20_block (checksum_state, block, checksum_state); +} + +static void +known_random (void *ctx, size_t length, uint8_t *dst) +{ + unsigned char block[32 + CHECKSUM_RNG_BYTES]; + gcry_error_t err; + + (void)ctx; + + while (length) + { + if (known_random_pos == CHECKSUM_RNG_BYTES) + { + memset (block, 0, sizeof (block)); + err = gcry_cipher_setkey (known_random_hd, known_random_key, + sizeof (known_random_key)); + if (!err) + err = gcry_cipher_encrypt (known_random_hd, block, sizeof (block), + NULL, 0); + if (err) + die ("ChaCha20 failed: %s\n", gpg_strerror (err)); + memcpy (known_random_key, block, sizeof (known_random_key)); + memcpy (known_random_buf, block + 32, CHECKSUM_RNG_BYTES); + known_random_pos = 0; + } + *dst++ = known_random_buf[known_random_pos++]; + length--; + } +} + +static uint64_t +vector_random (void) +{ + static const unsigned char key[33] = "generate inputs for test vectors"; + unsigned char in[16], out[64]; + uint64_t v = le_bswap64 (vector_random_ctr++); + + memset (in, 0, sizeof (in)); + memcpy (in, &v, sizeof (v)); + + salsa20_block (out, in, key); + + memcpy (&v, out, sizeof (v)); + return le_bswap64 (v); +} + +static void +corrupt_ciphertext (unsigned char *ct) +{ + /* Expected checksums depend on value being drawn before position. */ + uint64_t value = vector_random (); + uint64_t pos = vector_random (); + + ct[pos % CHECKSUM_CT_BYTES] += 1 + (value % 255); +} + +static void +test_checksums (void) +{ + static const struct + { + int loops; + const char *checksum; + } tv[] = + { + { 8, "4081ab3f61bac9aae91bff7f9b212855177591ec4427dff2a501be124c5bb97d" }, + { 64, "730a572b64fa05a42bce7b1573edc04b70ef75909db309c012aa27f53f1f2f41" } + }; + static unsigned char pk[PublicKeys_bytes]; + static unsigned char sk[SecretKeys_bytes + PublicKeys_bytes + + Inputs_bytes + Hash_bytes]; + static unsigned char ct[CHECKSUM_CT_BYTES]; + unsigned char key1[32], key2[32]; + unsigned char *want; + size_t wantlen; + gcry_error_t err; + unsigned int n; + int i, loop; + + if (gcry_cipher_test_algo (GCRY_CIPHER_CHACHA20) + || gcry_cipher_test_algo (GCRY_CIPHER_SALSA20) + || gcry_md_test_algo (GCRY_MD_SHA512)) + { + if (verbose) + info ("ChaCha20, Salsa20 or SHA-512 not available, skipping checksums\n"); + return; + } + + err = gcry_cipher_open (&known_random_hd, GCRY_CIPHER_CHACHA20, + GCRY_CIPHER_MODE_STREAM, 0); + if (!err) + err = gcry_cipher_open (&salsa20_hd, GCRY_CIPHER_SALSA20, + GCRY_CIPHER_MODE_STREAM, 0); + if (err) + die ("gcry_cipher_open failed: %s\n", gpg_strerror (err)); + + for (n = 0; n < DIM (tv); n++) + { + checksum_clear (); + + for (loop = 0; loop < tv[n].loops; loop++) + { + sntrup761_keypair (pk, sk, NULL, known_random); + checksum_update (pk, sizeof (pk)); + checksum_update (sk, sizeof (sk)); + + sntrup761_enc (ct, key1, pk, NULL, known_random); + checksum_update (ct, sizeof (ct)); + checksum_update (key1, sizeof (key1)); + + sntrup761_dec (key2, ct, sk); + if (memcmp (key1, key2, sizeof (key1))) + fail ("decapsulation mismatch, loop %d", loop); + checksum_update (key2, sizeof (key2)); + + for (i = 0; i < 3; i++) + { + corrupt_ciphertext (ct); + sntrup761_dec (key2, ct, sk); + checksum_update (key2, sizeof (key2)); + } + } + + want = hex2buffer (tv[n].checksum, &wantlen); + if (!want) + die ("invalid checksum string\n"); + if (memcmp (checksum_state, want, wantlen)) + { + mismatch (want, wantlen, checksum_state, wantlen); + fail ("checksum of %d loops mismatch", tv[n].loops); + } + xfree (want); + } + + gcry_cipher_close (known_random_hd); + gcry_cipher_close (salsa20_hd); +} + int main (int argc, char **argv) { @@ -412,6 +599,7 @@ main (int argc, char **argv) test_freeze_helpers (); test_mult (); + test_checksums (); if (verbose) fprintf (stderr, PGM ": %d error(s)\n", error_count); -- 2.53.0 From jussi.kivilinna at iki.fi Sat Nov 7 06:30:04 2026 From: jussi.kivilinna at iki.fi (Jussi Kivilinna) Date: Sat, 7 Nov 2026 07:30:04 +0200 Subject: [PATCH 1/3] sntrup761: fix implicit rejection key in decapsulation In-Reply-To: References: Message-ID: <20261107053006.8047-1-jussi.kivilinna@iki.fi> * cipher/sntrup761.c (sntrup761_dec): Move 'rho' to 'r_enc' on reject instead of 'r_enc ^ rho'. * tests/t-kem.c (test_kem_sntrup761_reject): New. (test_kem_sntrup761): Check rejection key. -- Commit 4e963e91 "sntrup761: use const-time helpers for memory comparison and cond move" kept XOR of 'r_enc' and 'rho' as source for conditional move, so rejection key was HashSession(0, r_enc ^ rho, C) instead of HashSession(0, rho, C) of specification. Rejection key stays unpredictable without 'rho', accept path is not affected. GnuPG-bug-id: 8542 Reported-by: Bhabani Sankar Das <007bsd at proton.me> Signed-off-by: Jussi Kivilinna --- cipher/sntrup761.c | 6 +----- tests/t-kem.c | 45 +++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 46 insertions(+), 5 deletions(-) diff --git a/cipher/sntrup761.c b/cipher/sntrup761.c index bcb6e651..c8c8f78d 100644 --- a/cipher/sntrup761.c +++ b/cipher/sntrup761.c @@ -1027,16 +1027,12 @@ sntrup761_dec (unsigned char *k, const unsigned char *c, const unsigned char *sk const unsigned char *cache = rho + Inputs_bytes; Inputs r; unsigned char r_enc[Inputs_bytes]; - unsigned char tmp[Inputs_bytes]; unsigned char cnew[Ciphertexts_bytes + Confirm_bytes]; int mask; - int i; ZDecrypt (r, c, sk); Hide (cnew, r_enc, r, pk, cache); mask = Ciphertexts_diff_mask (c, cnew); - for (i = 0; i < Inputs_bytes; ++i) - tmp[i] = r_enc[i] ^ rho[i]; - _gcry_ct_memmov_cond (r_enc, tmp, Inputs_bytes, mask & 1); + _gcry_ct_memmov_cond (r_enc, rho, Inputs_bytes, mask & 1); HashSession (k, 1 + mask, r_enc, c); } diff --git a/tests/t-kem.c b/tests/t-kem.c index 557e3473..6a2dde38 100644 --- a/tests/t-kem.c +++ b/tests/t-kem.c @@ -33,6 +33,49 @@ static int in_fips_mode; +#define SNTRUP761_RHO_LEN 191 +#define SNTRUP761_CACHE_LEN 32 +#define SNTRUP761_HASH_LEN 32 + +static void +test_kem_sntrup761_reject (int testno, const uint8_t *seckey, + uint8_t *ciphertext) +{ + gcry_error_t err; + const uint8_t *rho = seckey + GCRY_KEM_SNTRUP761_SECKEY_LEN + - SNTRUP761_CACHE_LEN - SNTRUP761_RHO_LEN; + uint8_t buf[1 + SNTRUP761_HASH_LEN + GCRY_KEM_SNTRUP761_ENCAPS_LEN]; + uint8_t digest[64]; + uint8_t key[GCRY_KEM_SNTRUP761_SHARED_LEN]; + + ciphertext[GCRY_KEM_SNTRUP761_ENCAPS_LEN - 1] ^= 1 << (testno % 8); + + err = gcry_kem_decap (GCRY_KEM_SNTRUP761, + seckey, GCRY_KEM_SNTRUP761_SECKEY_LEN, + ciphertext, GCRY_KEM_SNTRUP761_ENCAPS_LEN, + key, GCRY_KEM_SNTRUP761_SHARED_LEN, + NULL, 0); + if (err) + { + fail ("gcry_kem_decap reject %d: %s", testno, gpg_strerror (err)); + return; + } + + buf[0] = 3; + memcpy (buf + 1, rho, SNTRUP761_RHO_LEN); + gcry_md_hash_buffer (GCRY_MD_SHA512, digest, buf, 1 + SNTRUP761_RHO_LEN); + + buf[0] = 0; + memcpy (buf + 1, digest, SNTRUP761_HASH_LEN); + memcpy (buf + 1 + SNTRUP761_HASH_LEN, ciphertext, + GCRY_KEM_SNTRUP761_ENCAPS_LEN); + gcry_md_hash_buffer (GCRY_MD_SHA512, digest, buf, sizeof buf); + + if (memcmp (key, digest, GCRY_KEM_SNTRUP761_SHARED_LEN) != 0) + fail ("sntrup761 test %d failed: rejection key mismatch\n", testno); +} + + static void test_kem_sntrup761 (int testno) { @@ -89,6 +132,8 @@ test_kem_sntrup761 (int testno) fprintf (stderr, " %02x", key2[i]); putc ('\n', stderr); } + + test_kem_sntrup761_reject (testno, seckey, ciphertext); } -- 2.53.0 From soap at gentoo.org Thu Nov 12 12:53:54 2026 From: soap at gentoo.org (David Seifert) Date: Thu, 12 Nov 2026 12:53:54 +0100 Subject: [PATCH libgcrypt] ecc: Fix keygrip of native 25519 points starting with 0x02 or 0x03. Message-ID: <20261112115354.132945-1-soap@gentoo.org> * cipher/ecc.c (compute_keygrip): Do not try to uncompress the point of a 255 bit Edwards or Montgomery curve. * tests/keygrip.c (key_grips): Add test vectors. -- Without flags, the q of an Ed25519, Curve25519 or ietf25 key is the native 32 byte encoding of the point. This is the form of keys from X.509 certificates (RFC 8410) as returned by libksba and of RFC 9580 X25519 keys in GnuPG. If the first byte of such a point is 0x02 or 0x03, compute_keygrip takes it for a compressed Weierstrass point and tries to uncompress it. This fails because p is not 3 mod 4 for these curves, and thus gcry_pk_get_keygrip fails for about 2 in 256 keys. Skip the uncompression for these curves and hash the point as it is. This yields the same keygrip as the flagged form of the key. Only keygrips which could not be computed before are affected. The 448 bit curves are left alone: X448 and flagged Ed448 points starting with 0x02 or 0x03 do get uncompressed and changing that would change existing keygrips. Signed-off-by: David Seifert --- cipher/ecc.c | 8 ++++++ tests/keygrip.c | 70 +++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 78 insertions(+) diff --git a/cipher/ecc.c b/cipher/ecc.c index 8545145d..aa6320f2 100644 --- a/cipher/ecc.c +++ b/cipher/ecc.c @@ -1820,6 +1820,14 @@ compute_keygrip (gcry_md_hd_t md, gcry_sexp_t keyparms) } maybe_uncompress = 0; } + else if (model != MPI_EC_WEIERSTRASS && mpi_get_nbits (values[0]) == 255) + /* Without flags, an Ed25519, Curve25519 or ietf25 point is in + its native encoding (e.g. X.509 per RFC 8410 or RFC 9580 + X25519) and a leading 0x02 or 0x03 is part of the point. + Trying to uncompress it would fail. The 448 bit curves are + left alone because X448 and flagged Ed448 points do get + uncompressed and changing that would change their keygrips. */ + maybe_uncompress = 0; else maybe_uncompress = 1; diff --git a/tests/keygrip.c b/tests/keygrip.c index 503a2c05..6e67cf56 100644 --- a/tests/keygrip.c +++ b/tests/keygrip.c @@ -254,6 +254,76 @@ static struct "\x33\x23\x98\xF5\xD4\x80\x67\x7D\xF4\x9C", 1 }, + /* Native Ed25519 and Curve25519 points without flags, as in X.509 + * (RFC 8410) or RFC 9580 X25519, which start with 0x02 or 0x03. + * The keygrips must match those of the flagged forms. */ + { /* Ed25519 (X.509) */ + GCRY_PK_ECC, + "(public-key" + " (ecc" + " (curve \"1.3.101.112\")" + " (q #02C94DD0731AC5162EF1FBFD812893E9AB92DFAC2BB0D2C39CA43BB6DD33BA6E#)" + " ))", + "\x00\xC7\x93\x46\x46\xE9\x00\xDA\x9F\x00" + "\x14\x81\x62\x7D\x1A\x76\xEB\x30\xB9\x89" + }, + { /* Ed25519+EdDSA, same key */ + GCRY_PK_ECC, + "(public-key" + " (ecc" + " (curve Ed25519)(flags eddsa)" + " (q #40" + " 02C94DD0731AC5162EF1FBFD812893E9AB92DFAC2BB0D2C39CA43BB6DD33BA6E#)" + " ))", + "\x00\xC7\x93\x46\x46\xE9\x00\xDA\x9F\x00" + "\x14\x81\x62\x7D\x1A\x76\xEB\x30\xB9\x89" + }, + { /* Cv25519 (X.509) */ + GCRY_PK_ECC, + "(public-key" + " (ecc" + " (curve \"1.3.101.110\")" + " (q #033D6693A55C7408AA43A4FF49F3CB82AD48AD4D70212BCA51B4ED0FA678B038#)" + " ))", + "\xCE\xF4\x74\x27\x54\xA4\xA0\x13\xE2\xD6" + "\xFB\x0D\xEE\xCE\x90\x5F\x56\x4B\xC9\x68", + 1 + }, + { /* Cv25519, same key */ + GCRY_PK_ECC, + "(public-key" + " (ecc" + " (curve Curve25519)(flags djb-tweak)" + " (q #40" + " 033D6693A55C7408AA43A4FF49F3CB82AD48AD4D70212BCA51B4ED0FA678B038#)" + " ))", + "\xCE\xF4\x74\x27\x54\xA4\xA0\x13\xE2\xD6" + "\xFB\x0D\xEE\xCE\x90\x5F\x56\x4B\xC9\x68", + 1 + }, + { /* X25519 (RFC 9580) */ + GCRY_PK_ECC, + "(public-key" + " (ecc" + " (curve ietf25)" + " (q #02F682704BF3DAEB87ECC31430DA17D783CCBD6A5B587A0EA1C6DEDBC020592F#)" + " ))", + "\x96\x8E\x51\xF9\xF0\x72\x6B\x29\xDD\x61" + "\xD6\xBA\x8D\xF1\x0A\x39\x58\x8C\x76\xAD", + 1 + }, + { /* X25519 with flag, same key */ + GCRY_PK_ECC, + "(public-key" + " (ecc" + " (curve ietf25)(flags djb-tweak)" + " (q #40" + " 02F682704BF3DAEB87ECC31430DA17D783CCBD6A5B587A0EA1C6DEDBC020592F#)" + " ))", + "\x96\x8E\x51\xF9\xF0\x72\x6B\x29\xDD\x61" + "\xD6\xBA\x8D\xF1\x0A\x39\x58\x8C\x76\xAD", + 1 + }, { /* Random key */ GCRY_PK_RSA, "(shadowed-private-key" -- 2.56.0 From jussi.kivilinna at iki.fi Sat Nov 14 16:22:53 2026 From: jussi.kivilinna at iki.fi (Jussi Kivilinna) Date: Sat, 14 Nov 2026 17:22:53 +0200 Subject: [PATCH] serpent-avx512-x86: use depth-optimized vpternlogd S-boxes Message-ID: <20261114152253.3967511-1-jussi.kivilinna@iki.fi> * cipher/serpent-avx512-x86.c (vpternlogd): New. (SBOX0, SBOX0_INVERSE, SBOX1, SBOX1_INVERSE, SBOX2, SBOX2_INVERSE) (SBOX3, SBOX3_INVERSE, SBOX4, SBOX4_INVERSE, SBOX5, SBOX5_INVERSE) (SBOX6, SBOX6_INVERSE, SBOX7, SBOX7_INVERSE): Replace with ternary logic circuits. -- S-box circuits were found with SAT solver search over 3-input gates, minimizing critical path through S-box, key mixing and linear transformation. Benchmark on AMD Ryzen 9 9950X3D (zen5): Before: SERPENT128 | nanosecs/byte mebibytes/sec cycles/byte auto Mhz ECB enc | 0.487 ns/B 1958 MiB/s 2.10 c/B 4320 ECB dec | 0.409 ns/B 2329 MiB/s 1.77 c/B 4317±1 After (~27% faster encryption, ~14% faster decryption): SERPENT128 | nanosecs/byte mebibytes/sec cycles/byte auto Mhz ECB enc | 0.382 ns/B 2495 MiB/s 1.65 c/B 4314 ECB dec | 0.359 ns/B 2658 MiB/s 1.55 c/B 4312 Benchmark on AMD Ryzen 9 7900X (zen4): Before: SERPENT128 | nanosecs/byte mebibytes/sec cycles/byte auto Mhz ECB enc | 0.572 ns/B 1668 MiB/s 2.66 c/B 4650 ECB dec | 0.549 ns/B 1737 MiB/s 2.55 c/B 4650 After (~19% faster encryption, ~11% faster decryption): SERPENT128 | nanosecs/byte mebibytes/sec cycles/byte auto Mhz ECB enc | 0.479 ns/B 1989 MiB/s 2.23 c/B 4650 ECB dec | 0.495 ns/B 1926 MiB/s 2.30 c/B 4650 Benchmark on Intel Core i3-1115G4 (tigerlake): Before: SERPENT128 | nanosecs/byte mebibytes/sec cycles/byte auto Mhz ECB enc | 0.495 ns/B 1927 MiB/s 2.03 c/B 4097±4 ECB dec | 0.511 ns/B 1867 MiB/s 2.09 c/B 4097±3 After (~14% faster encryption, ~11% faster decryption): SERPENT128 | nanosecs/byte mebibytes/sec cycles/byte auto Mhz ECB enc | 0.433 ns/B 2205 MiB/s 1.77 c/B 4104 ECB dec | 0.461 ns/B 2071 MiB/s 1.89 c/B 4097±3 Signed-off-by: Jussi Kivilinna --- cipher/serpent-avx512-x86.c | 438 ++++++++++++++++-------------------- 1 file changed, 197 insertions(+), 241 deletions(-) diff --git a/cipher/serpent-avx512-x86.c b/cipher/serpent-avx512-x86.c index dfbe2432..626206cd 100644 --- a/cipher/serpent-avx512-x86.c +++ b/cipher/serpent-avx512-x86.c @@ -59,6 +59,9 @@ typedef unsigned int serpent_subkeys_t[ROUNDS + 1][4]; #define vror(x, s) _mm512_ror_epi32((x), (s)) #define vshl(x, s) _mm512_slli_epi32((x), (s)) +#define vpternlogd(a, b, c, imm) \ + _mm512_ternarylogic_epi32((a), (b), (c), (imm)) + /* 4x4 32-bit integer matrix transpose */ #define transpose_4x4(x0, x1, x2, x3, t1, t2, t3) \ vpunpckhdq(x1, x0, t2); \ @@ -73,310 +76,263 @@ typedef unsigned int serpent_subkeys_t[ROUNDS + 1][4]; vpunpckhqdq(x2, t2, x3); \ vpunpcklqdq(x2, t2, x2); -/* - * These are the S-Boxes of Serpent from following research paper. - * - * D. A. Osvik, “Speeding up Serpent,” in Third AES Candidate Conference, - * (New York, New York, USA), p. 317–329, National Institute of Standards and - * Technology, 2000. - * - * Paper is also available at: http://www.ii.uib.no/~osvik/pub/aes3.pdf - * - * -- - * - * Following logic gets heavily optimized by compiler to use AVX512F - * 'vpternlogq' instruction. This gives higher performance increase than - * would be expected from simple wideing of vectors from AVX2/256bit to - * AVX512/512bit. - * - */ +/* Serpent S-boxes as minimal-gate-count AVX512 ternary logic circuits. */ #define SBOX0(r0, r1, r2, r3, w, x, y, z) \ { \ - __m512i r4; \ - \ - r3 ^= r0; r4 = r1; \ - r1 &= r3; r4 ^= r2; \ - r1 ^= r0; r0 |= r3; \ - r0 ^= r4; r4 ^= r3; \ - r3 ^= r2; r2 |= r1; \ - r2 ^= r4; r4 = ~r4; \ - r4 |= r1; r1 ^= r3; \ - r1 ^= r4; r3 |= r0; \ - r1 ^= r3; r4 ^= r3; \ - \ - w = r1; x = r4; y = r2; z = r0; \ + __m512i t4, t5, t6, t7, t8, t9, t10, t11; \ + \ + t4 = vpternlogd(r0, r1, r3, 0xb8); \ + t5 = vpternlogd(r0, r1, r3, 0x36); \ + t6 = vpternlogd(r0, r1, r3, 0x6c); \ + t7 = vpternlogd(r0, r2, r3, 0x96); \ + t8 = r2 ^ t5; \ + t9 = vpternlogd(t4, t5, t7, 0x6c); \ + t10 = vpternlogd(t4, t7, t8, 0x1b); \ + t11 = vpternlogd(t4, t6, t7, 0x4d); \ + \ + w = t11; x = t10; y = t9; z = t8; \ } #define SBOX0_INVERSE(r0, r1, r2, r3, w, x, y, z) \ { \ - __m512i r4; \ - \ - r2 = ~r2; r4 = r1; \ - r1 |= r0; r4 = ~r4; \ - r1 ^= r2; r2 |= r4; \ - r1 ^= r3; r0 ^= r4; \ - r2 ^= r0; r0 &= r3; \ - r4 ^= r0; r0 |= r1; \ - r0 ^= r2; r3 ^= r4; \ - r2 ^= r1; r3 ^= r0; \ - r3 ^= r1; \ - r2 &= r3; \ - r4 ^= r2; \ - \ - w = r0; x = r4; y = r1; z = r3; \ + __m512i t4, t5, t6, t7, t8, t9, t10, t11; \ + \ + t4 = vpternlogd(r0, r1, r3, 0x4e); \ + t5 = vpternlogd(r0, r1, r2, 0xa9); \ + t6 = r3 ^ t5; \ + t7 = vpternlogd(r0, r1, r2, 0x63); \ + t8 = vpternlogd(r0, r1, r2, 0x81); \ + t9 = vpternlogd(r3, t7, t8, 0xc9); \ + t10 = vpternlogd(t4, t5, t9, 0x27); \ + t11 = vpternlogd(t4, t5, t9, 0x69); \ + \ + w = t9; x = t10; y = t6; z = t11; \ } #define SBOX1(r0, r1, r2, r3, w, x, y, z) \ { \ - __m512i r4; \ - \ - r0 = ~r0; r2 = ~r2; \ - r4 = r0; r0 &= r1; \ - r2 ^= r0; r0 |= r3; \ - r3 ^= r2; r1 ^= r0; \ - r0 ^= r4; r4 |= r1; \ - r1 ^= r3; r2 |= r0; \ - r2 &= r4; r0 ^= r1; \ - r1 &= r2; \ - r1 ^= r0; r0 &= r2; \ - r0 ^= r4; \ - \ - w = r2; x = r0; y = r3; z = r1; \ + __m512i t4, t5, t6, t7, t8, t9, t10; \ + \ + t4 = vpternlogd(r0, r1, r3, 0xd8); \ + t5 = vpternlogd(r0, r1, r3, 0x96); \ + t6 = vpternlogd(r0, r1, r2, 0x59); \ + t7 = vpternlogd(t4, t5, t6, 0x36); \ + t8 = vpternlogd(t4, t5, t6, 0x93); \ + t9 = r3 ^ t6; \ + t10 = vpternlogd(t4, t5, t6, 0x2b); \ + \ + w = t10; x = t7; y = t9; z = t8; \ } #define SBOX1_INVERSE(r0, r1, r2, r3, w, x, y, z) \ { \ - __m512i r4; \ - \ - r4 = r1; r1 ^= r3; \ - r3 &= r1; r4 ^= r2; \ - r3 ^= r0; r0 |= r1; \ - r2 ^= r3; r0 ^= r4; \ - r0 |= r2; r1 ^= r3; \ - r0 ^= r1; r1 |= r3; \ - r1 ^= r0; r4 = ~r4; \ - r4 ^= r1; r1 |= r0; \ - r1 ^= r0; \ - r1 |= r4; \ - r3 ^= r1; \ - \ - w = r4; x = r0; y = r3; z = r2; \ + __m512i t4, t5, t6, t7, t8, t9, t10, t11; \ + \ + t4 = vpternlogd(r0, r1, r2, 0x6a); \ + t5 = vpternlogd(r0, r1, r2, 0xe4); \ + t6 = vpternlogd(r0, r1, r2, 0x7c); \ + t7 = vpternlogd(r3, t4, t6, 0x69); \ + t8 = vpternlogd(r0, t5, t7, 0x8d); \ + t9 = vpternlogd(r1, t4, t7, 0xc5); \ + t10 = vpternlogd(r3, t5, t6, 0x95); \ + t11 = vpternlogd(r2, t7, t10, 0x6c); \ + \ + w = t10; x = t8; y = t11; z = t9; \ } #define SBOX2(r0, r1, r2, r3, w, x, y, z) \ { \ - __m512i r4; \ - \ - r4 = r0; r0 &= r2; \ - r0 ^= r3; r2 ^= r1; \ - r2 ^= r0; r3 |= r4; \ - r3 ^= r1; r4 ^= r2; \ - r1 = r3; r3 |= r4; \ - r3 ^= r0; r0 &= r1; \ - r4 ^= r0; r1 ^= r3; \ - r1 ^= r4; r4 = ~r4; \ - \ - w = r2; x = r3; y = r1; z = r4; \ + __m512i t4, t5, t6, t7, t8, t9, t10; \ + \ + t4 = vpternlogd(r0, r2, r3, 0x6a); \ + t5 = vpternlogd(r0, r1, r2, 0x96); \ + t6 = vpternlogd(r0, r2, r3, 0xc6); \ + t7 = vpternlogd(r0, t4, t5, 0x96); \ + t8 = vpternlogd(t4, t5, t6, 0x8e); \ + t9 = vpternlogd(t4, t5, t6, 0xb4); \ + t10 = vpternlogd(t5, t6, t9, 0x8d); \ + \ + w = t7; x = t8; y = t9; z = t10; \ } #define SBOX2_INVERSE(r0, r1, r2, r3, w, x, y, z) \ { \ - __m512i r4; \ - \ - r2 ^= r3; r3 ^= r0; \ - r4 = r3; r3 &= r2; \ - r3 ^= r1; r1 |= r2; \ - r1 ^= r4; r4 &= r3; \ - r2 ^= r3; r4 &= r0; \ - r4 ^= r2; r2 &= r1; \ - r2 |= r0; r3 = ~r3; \ - r2 ^= r3; r0 ^= r3; \ - r0 &= r1; r3 ^= r4; \ - r3 ^= r0; \ - \ - w = r1; x = r4; y = r2; z = r3; \ + __m512i t4, t5, t6, t7, t8, t9, t10, t11; \ + \ + t4 = vpternlogd(r0, r1, r2, 0x1e); \ + t5 = vpternlogd(r1, r3, t4, 0x6a); \ + t6 = vpternlogd(r1, r2, r3, 0xca); \ + t7 = vpternlogd(r1, r2, r3, 0x8d); \ + t8 = vpternlogd(r1, r2, r3, 0x49); \ + t9 = vpternlogd(t4, t7, t8, 0x56); \ + t10 = vpternlogd(t5, t6, t7, 0x93); \ + t11 = vpternlogd(t5, t6, t7, 0x3a); \ + \ + w = t5; x = t9; y = t10; z = t11; \ } #define SBOX3(r0, r1, r2, r3, w, x, y, z) \ { \ - __m512i r4; \ - \ - r4 = r0; r0 |= r3; \ - r3 ^= r1; r1 &= r4; \ - r4 ^= r2; r2 ^= r3; \ - r3 &= r0; r4 |= r1; \ - r3 ^= r4; r0 ^= r1; \ - r4 &= r0; r1 ^= r3; \ - r4 ^= r2; r1 |= r0; \ - r1 ^= r2; r0 ^= r3; \ - r2 = r1; r1 |= r3; \ - r1 ^= r0; \ - \ - w = r1; x = r2; y = r3; z = r4; \ + __m512i t4, t5, t6, t7, t8, t9, t10, t11; \ + \ + t4 = vpternlogd(r0, r1, r3, 0x1c); \ + t5 = vpternlogd(r0, r2, r3, 0x62); \ + t6 = vpternlogd(r0, r1, r2, 0x1a); \ + t7 = vpternlogd(r1, r2, r3, 0xb0); \ + t8 = vpternlogd(r0, t5, t7, 0x56); \ + t9 = vpternlogd(r1, t5, t6, 0x16); \ + t10 = vpternlogd(r3, t4, t6, 0x9a); \ + t11 = vpternlogd(r3, t4, t5, 0x96); \ + \ + w = t8; x = t11; y = t10; z = t9; \ } #define SBOX3_INVERSE(r0, r1, r2, r3, w, x, y, z) \ { \ - __m512i r4; \ - \ - r4 = r2; r2 ^= r1; \ - r0 ^= r2; r4 &= r2; \ - r4 ^= r0; r0 &= r1; \ - r1 ^= r3; r3 |= r4; \ - r2 ^= r3; r0 ^= r3; \ - r1 ^= r4; r3 &= r2; \ - r3 ^= r1; r1 ^= r0; \ - r1 |= r2; r0 ^= r3; \ - r1 ^= r4; \ - r0 ^= r1; \ - \ - w = r2; x = r1; y = r3; z = r0; \ + __m512i t4, t5, t6, t7, t8, t9, t10, t11; \ + \ + t4 = r1 ^ r2; \ + t5 = vpternlogd(r0, r1, r2, 0xb4); \ + t6 = vpternlogd(r3, t4, t5, 0x36); \ + t7 = vpternlogd(r3, t4, t5, 0xe3); \ + t8 = vpternlogd(r1, t5, t7, 0x75); \ + t9 = vpternlogd(r1, r3, t5, 0x96); \ + t10 = vpternlogd(r2, t7, t9, 0x79); \ + t11 = vpternlogd(t4, t6, t9, 0xa6); \ + \ + w = t6; x = t8; y = t11; z = t10; \ } #define SBOX4(r0, r1, r2, r3, w, x, y, z) \ { \ - __m512i r4; \ - \ - r1 ^= r3; r3 = ~r3; \ - r2 ^= r3; r3 ^= r0; \ - r4 = r1; r1 &= r3; \ - r1 ^= r2; r4 ^= r3; \ - r0 ^= r4; r2 &= r4; \ - r2 ^= r0; r0 &= r1; \ - r3 ^= r0; r4 |= r1; \ - r4 ^= r0; r0 |= r3; \ - r0 ^= r2; r2 &= r3; \ - r0 = ~r0; r4 ^= r2; \ - \ - w = r1; x = r4; y = r0; z = r3; \ + __m512i t4, t5, t6, t7, t8, t9, t10, t11; \ + \ + t4 = vpternlogd(r0, r2, r3, 0x36); \ + t5 = vpternlogd(r0, r1, r3, 0x96); \ + t6 = vpternlogd(r0, r2, r3, 0x93); \ + t7 = vpternlogd(r0, r1, r3, 0x2e); \ + t8 = vpternlogd(t5, t6, t7, 0x4b); \ + t9 = t6 ^ t7; \ + t10 = vpternlogd(r1, t5, t9, 0xc9); \ + t11 = vpternlogd(t4, t5, t8, 0xd2); \ + \ + w = t9; x = t11; y = t8; z = t10; \ } #define SBOX4_INVERSE(r0, r1, r2, r3, w, x, y, z) \ { \ - __m512i r4; \ - \ - r4 = r2; r2 &= r3; \ - r2 ^= r1; r1 |= r3; \ - r1 &= r0; r4 ^= r2; \ - r4 ^= r1; r1 &= r2; \ - r0 = ~r0; r3 ^= r4; \ - r1 ^= r3; r3 &= r0; \ - r3 ^= r2; r0 ^= r1; \ - r2 &= r0; r3 ^= r0; \ - r2 ^= r4; \ - r2 |= r3; r3 ^= r0; \ - r2 ^= r1; \ - \ - w = r0; x = r3; y = r2; z = r4; \ + __m512i t4, t5, t6, t7, t8, t9, t10, t11; \ + \ + t4 = vpternlogd(r0, r2, r3, 0x26); \ + t5 = vpternlogd(r0, r1, r3, 0x6e); \ + t6 = vpternlogd(r0, r1, r2, 0x3a); \ + t7 = vpternlogd(r0, t4, t5, 0x6c); \ + t8 = vpternlogd(r0, r1, r2, 0x96); \ + t9 = vpternlogd(r2, t5, t6, 0xc9); \ + t10 = vpternlogd(r3, t6, t8, 0x65); \ + t11 = vpternlogd(t4, t6, t10, 0x69); \ + \ + w = t10; x = t7; y = t9; z = t11; \ } #define SBOX5(r0, r1, r2, r3, w, x, y, z) \ { \ - __m512i r4; \ - \ - r0 ^= r1; r1 ^= r3; \ - r3 = ~r3; r4 = r1; \ - r1 &= r0; r2 ^= r3; \ - r1 ^= r2; r2 |= r4; \ - r4 ^= r3; r3 &= r1; \ - r3 ^= r0; r4 ^= r1; \ - r4 ^= r2; r2 ^= r0; \ - r0 &= r3; r2 = ~r2; \ - r0 ^= r4; r4 |= r3; \ - r2 ^= r4; \ - \ - w = r1; x = r3; y = r0; z = r2; \ + __m512i t4, t5, t6, t7, t8, t9, t10, t11; \ + \ + t4 = vpternlogd(r0, r1, r2, 0x6e); \ + t5 = vpternlogd(r0, r1, r3, 0x38); \ + t6 = vpternlogd(r0, r1, r3, 0x7e); \ + t7 = vpternlogd(r0, r2, t6, 0x69); \ + t8 = vpternlogd(r3, t4, t6, 0x87); \ + t9 = vpternlogd(r3, t5, t8, 0x4d); \ + t10 = vpternlogd(r1, t7, t9, 0x96); \ + t11 = vpternlogd(r2, r3, t5, 0xa9); \ + \ + w = t7; x = t11; y = t8; z = t10; \ } #define SBOX5_INVERSE(r0, r1, r2, r3, w, x, y, z) \ { \ - __m512i r4; \ - \ - r1 = ~r1; r4 = r3; \ - r2 ^= r1; r3 |= r0; \ - r3 ^= r2; r2 |= r1; \ - r2 &= r0; r4 ^= r3; \ - r2 ^= r4; r4 |= r0; \ - r4 ^= r1; r1 &= r2; \ - r1 ^= r3; r4 ^= r2; \ - r3 &= r4; r4 ^= r1; \ - r3 ^= r4; r4 = ~r4; \ - r3 ^= r0; \ - \ - w = r1; x = r4; y = r3; z = r2; \ + __m512i t4, t5, t6, t7, t8, t9, t10, t11; \ + \ + t4 = vpternlogd(r0, r1, r2, 0x5b); \ + t5 = vpternlogd(r0, r1, r3, 0x38); \ + t6 = vpternlogd(r0, r3, t4, 0xc5); \ + t7 = vpternlogd(r1, r3, t4, 0xac); \ + t8 = vpternlogd(r1, r2, t6, 0x59); \ + t9 = vpternlogd(r2, t5, t6, 0x9c); \ + t10 = vpternlogd(r3, t4, t5, 0xc9); \ + t11 = t5 ^ t7; \ + \ + w = t11; x = t10; y = t9; z = t8; \ } #define SBOX6(r0, r1, r2, r3, w, x, y, z) \ { \ - __m512i r4; \ - \ - r2 = ~r2; r4 = r3; \ - r3 &= r0; r0 ^= r4; \ - r3 ^= r2; r2 |= r4; \ - r1 ^= r3; r2 ^= r0; \ - r0 |= r1; r2 ^= r1; \ - r4 ^= r0; r0 |= r3; \ - r0 ^= r2; r4 ^= r3; \ - r4 ^= r0; r3 = ~r3; \ - r2 &= r4; \ - r2 ^= r3; \ - \ - w = r0; x = r1; y = r4; z = r2; \ + __m512i t4, t5, t6, t7, t8, t9, t10, t11; \ + \ + t4 = vpternlogd(r0, r1, r3, 0x16); \ + t5 = vpternlogd(r0, r1, r3, 0x62); \ + t6 = vpternlogd(r0, r1, r3, 0x2e); \ + t7 = vpternlogd(r0, r2, r3, 0x93); \ + t8 = vpternlogd(r2, t4, t5, 0xa3); \ + t9 = vpternlogd(r2, t4, t6, 0xc9); \ + t10 = r1 ^ t7; \ + t11 = vpternlogd(t7, t8, t9, 0x2d); \ + \ + w = t8; x = t10; y = t9; z = t11; \ } #define SBOX6_INVERSE(r0, r1, r2, r3, w, x, y, z) \ { \ - __m512i r4; \ - \ - r0 ^= r2; r4 = r2; \ - r2 &= r0; r4 ^= r3; \ - r2 = ~r2; r3 ^= r1; \ - r2 ^= r3; r4 |= r0; \ - r0 ^= r2; r3 ^= r4; \ - r4 ^= r1; r1 &= r3; \ - r1 ^= r0; r0 ^= r3; \ - r0 |= r2; r3 ^= r1; \ - r4 ^= r0; \ - \ - w = r1; x = r2; y = r4; z = r3; \ + __m512i t4, t5, t6, t7, t8, t9, t10, t11, t12; \ + \ + t4 = vpternlogd(r0, r2, r3, 0xd8); \ + t5 = vpternlogd(r0, r1, r2, 0xd0); \ + t6 = vpternlogd(r0, r2, r3, 0x78); \ + t7 = vpternlogd(r0, r1, r2, 0x48); \ + t8 = vpternlogd(r0, r1, r2, 0x39); \ + t9 = r3 ^ t8; \ + t10 = vpternlogd(r3, t5, t7, 0xc9); \ + t11 = vpternlogd(r1, t6, t10, 0x93); \ + t12 = vpternlogd(t4, t8, t10, 0x69); \ + \ + w = t10; x = t9; y = t11; z = t12; \ } #define SBOX7(r0, r1, r2, r3, w, x, y, z) \ { \ - __m512i r4; \ - \ - r4 = r1; r1 |= r2; \ - r1 ^= r3; r4 ^= r2; \ - r2 ^= r1; r3 |= r4; \ - r3 &= r0; r4 ^= r2; \ - r3 ^= r1; r1 |= r4; \ - r1 ^= r0; r0 |= r4; \ - r0 ^= r2; r1 ^= r4; \ - r2 ^= r1; r1 &= r0; \ - r1 ^= r4; r2 = ~r2; \ - r2 |= r0; \ - r4 ^= r2; \ - \ - w = r4; x = r3; y = r1; z = r0; \ + __m512i t4, t5, t6, t7, t8, t9, t10, t11, t12; \ + \ + t4 = vpternlogd(r0, r2, r3, 0x64); \ + t5 = vpternlogd(r0, r1, r2, 0x62); \ + t6 = vpternlogd(r0, r2, r3, 0xd2); \ + t7 = vpternlogd(r0, r1, r2, 0x16); \ + t8 = vpternlogd(r0, t4, t7, 0x6a); \ + t9 = vpternlogd(r1, t4, t6, 0x93); \ + t10 = vpternlogd(r3, t5, t7, 0x3a); \ + t11 = vpternlogd(r3, t5, t7, 0x26); \ + t12 = vpternlogd(t6, t9, t11, 0x59); \ + \ + w = t9; x = t12; y = t10; z = t8; \ } #define SBOX7_INVERSE(r0, r1, r2, r3, w, x, y, z) \ { \ - __m512i r4; \ - \ - r4 = r2; r2 ^= r0; \ - r0 &= r3; r4 |= r3; \ - r2 = ~r2; r3 ^= r1; \ - r1 |= r0; r0 ^= r2; \ - r2 &= r4; r3 &= r4; \ - r1 ^= r2; r2 ^= r0; \ - r0 |= r2; r4 ^= r1; \ - r0 ^= r3; r3 ^= r4; \ - r4 |= r0; r3 ^= r2; \ - r4 ^= r2; \ - \ - w = r3; x = r0; y = r1; z = r4; \ + __m512i t4, t5, t6, t7, t8, t9, t10, t11, t12; \ + \ + t4 = vpternlogd(r0, r1, r2, 0x87); \ + t5 = vpternlogd(r0, r1, r2, 0x26); \ + t6 = vpternlogd(r1, r3, t5, 0x76); \ + t7 = vpternlogd(r1, r3, t4, 0x34); \ + t8 = t5 ^ t7; \ + t9 = vpternlogd(r0, t6, t7, 0x49); \ + t10 = vpternlogd(r2, r3, t4, 0x2e); \ + t11 = vpternlogd(r2, t4, t6, 0x2a); \ + t12 = t7 ^ t10; \ + \ + w = t12; x = t9; y = t11; z = t8; \ } /* XOR BLOCK1 into BLOCK0. */ -- 2.53.0 From gniibe at fsij.org Mon Nov 16 05:50:51 2026 From: gniibe at fsij.org (NIIBE Yutaka) Date: Mon, 16 Nov 2026 13:50:51 +0900 Subject: [PATCH libgcrypt] ecc: Fix keygrip of native 25519 points starting with 0x02 or 0x03. In-Reply-To: <20261112115354.132945-1-soap@gentoo.org> References: <20261112115354.132945-1-soap@gentoo.org> Message-ID: <87fqx1fkgk.fsf@haruna.fsij.org> Hello, Thank you for your pointing out the issue. Firstly, I think that we need this change: ========================== diff --git a/cipher/ecc.c b/cipher/ecc.c index 8545145d..47b51c31 100644 --- a/cipher/ecc.c +++ b/cipher/ecc.c @@ -1792,7 +1792,11 @@ compute_keygrip (gcry_md_hd_t md, gcry_sexp_t keyparms) the compressed version. Because we don't support any non-eddsa compression, the only thing we need to do is to compress EdDSA. */ - if ((flags & PUBKEY_FLAG_EDDSA) && dialect == ECC_DIALECT_ED25519) + if (dialect == ECC_DIALECT_SAFECURVE) + { + maybe_uncompress = 0; + } + else if ((flags & PUBKEY_FLAG_EDDSA) && dialect == ECC_DIALECT_ED25519) { const unsigned int pbits = mpi_get_nbits (values[0]); ========================== That is, for keys with its native format (which should come with no flags), compression is irrelevant. The curves are: ietf25 for X25519, Ed448 and X448. David Seifert wrote: > * cipher/ecc.c (compute_keygrip): Do not try to uncompress the point > of a 255 bit Edwards or Montgomery curve. > * tests/keygrip.c (key_grips): Add test vectors. For (normal) use of Ed25519 and Curve25519, the relevant flags should be supplied. Historically, Ed25519 with no flags were introduced when Ed25519 was not mature and it was specifically for ECDSA (not EdDSA). Around the same time, Curve25519 with the flag was introduced to compute X25519 (with big-endian private key). > This is the form of keys from X.509 certificates (RFC 8410) as > returned by libksba I don't understand this claim. Does libksba return an SEXP key with no flags? If so, it is libksba which should be fixed. Please let us know. > If the first byte of such a point is 0x02 or 0x03, compute_keygrip > takes it for a compressed Weierstrass point and tries to uncompress > it. Yes, this is the behavior. -- From gniibe at fsij.org Tue Nov 17 03:01:24 2026 From: gniibe at fsij.org (NIIBE Yutaka) Date: Tue, 17 Nov 2026 11:01:24 +0900 Subject: [PATCH libgcrypt] ecc: Fix keygrip of native 25519 points starting with 0x02 or 0x03. In-Reply-To: References: <20261112115354.132945-1-soap@gentoo.org> <87fqx1fkgk.fsf@haruna.fsij.org> Message-ID: <87ld6sp66j.fsf@haruna.fsij.org> Hello, I pushed the change, including your test vector with ietf25. -- From gniibe at fsij.org Tue Nov 17 06:47:47 2026 From: gniibe at fsij.org (NIIBE Yutaka) Date: Tue, 17 Nov 2026 14:47:47 +0900 Subject: 1.11 branch Message-ID: <87h5hgovp8.fsf@haruna.fsij.org> Hello, For forthcoming 1.11.4 release, I backported changes in master. Please test the 1.11 branch. And if any other backport is needed, tell us. -- From jussi.kivilinna at iki.fi Tue Nov 17 18:25:08 2026 From: jussi.kivilinna at iki.fi (Jussi Kivilinna) Date: Tue, 17 Nov 2026 19:25:08 +0200 Subject: 1.11 branch In-Reply-To: <87h5hgovp8.fsf@haruna.fsij.org> References: <87h5hgovp8.fsf@haruna.fsij.org> Message-ID: <2c3d6cd4-4df2-4126-8067-be8349a18893@iki.fi> Hello, On 17/11/2026 07:47, NIIBE Yutaka via Gcrypt-devel wrote: > Hello, > > For forthcoming 1.11.4 release, I backported changes in master. Please > test the 1.11 branch. And if any other backport is needed, tell us. These could be backported: - 3a7a156a4e69c1fdcabe04b245193a00413ae453 (poly1305-p10le: fix lost carry in conversion from base 2^26) - 87714ba050304926c1a1b717c60ff981ed25ba4c (poly1305-avx512: fix lost carry and bit 130 in base 2^44 conversions) - 92a2b41e94c1b63700b8b01ae11ccbeb0ae4a2a8 (Fix carry flag clobber for powerpc inline assembly with clang) -Jussi From gniibe at fsij.org Wed Nov 18 02:54:49 2026 From: gniibe at fsij.org (NIIBE Yutaka) Date: Wed, 18 Nov 2026 10:54:49 +0900 Subject: 1.11 branch In-Reply-To: <2c3d6cd4-4df2-4126-8067-be8349a18893@iki.fi> References: <87h5hgovp8.fsf@haruna.fsij.org> <2c3d6cd4-4df2-4126-8067-be8349a18893@iki.fi> Message-ID: <87y0aqkiom.fsf@haruna.fsij.org> Hello, Thank you for your quick response. Jussi Kivilinna wrote: > - 3a7a156a4e69c1fdcabe04b245193a00413ae453 (poly1305-p10le: fix lost carry in conversion from base 2^26) > - 87714ba050304926c1a1b717c60ff981ed25ba4c (poly1305-avx512: fix lost carry and bit 130 in base 2^44 conversions) > - 92a2b41e94c1b63700b8b01ae11ccbeb0ae4a2a8 (Fix carry flag clobber for powerpc inline assembly with clang) I cherry-picked those to 1.11 branch (LIBGCRYPT-1.11-BRANCH). --