From jussi.kivilinna at iki.fi Sun Nov 3 21:49:46 2019 From: jussi.kivilinna at iki.fi (Jussi Kivilinna) Date: Sun, 3 Nov 2019 22:49:46 +0200 Subject: [PATCH] Add i386/SSSE3 implementation of SHA512 Message-ID: <157281418659.5721.9714199059143789987.stgit@localhost.localdomain> * LICENSES: Add 'sha512-ssse3-i386.c'. * configure.ac: Add 'sha512-ssse3-i386.lo'. * cipher/Makefile.am: Add 'sha512-ssse3-i386.c'. * cipher/sha512-ssse3-i386.c: New. * cipher/sha512.c (USE_SSSE3_I386, _gcry_sha512_transform_i386_ssse3) (do_sha512_transform_i386_ssse3): New. (_gcry_sha512_transform_arm) [USE_SSSE3_I386]: Use i386/SSSE3 transform function if supported by CPU. -- Benchmark on AMD Ryzen 7 3700X: Before: | nanosecs/byte mebibytes/sec cycles/byte auto Mhz SHA512 | 12.58 ns/B 75.79 MiB/s 55.06 c/B 4375 After (~4.5x faster): | nanosecs/byte mebibytes/sec cycles/byte auto Mhz SHA512 | 2.78 ns/B 343.3 MiB/s 12.09 c/B 4351 Signed-off-by: Jussi Kivilinna --- 0 files changed diff --git a/LICENSES b/LICENSES index f6733a692..31f8eae83 100644 --- a/LICENSES +++ b/LICENSES @@ -18,6 +18,7 @@ with any binary distributions derived from the GNU C Library. - cipher/sha512-avx-amd64.S - cipher/sha512-avx2-bmi2-amd64.S - cipher/sha512-ssse3-amd64.S + - cipher/sha512-ssse3-i386.c #+begin_quote Copyright (c) 2012, Intel Corporation diff --git a/cipher/Makefile.am b/cipher/Makefile.am index dc63a736f..020a96162 100644 --- a/cipher/Makefile.am +++ b/cipher/Makefile.am @@ -117,7 +117,7 @@ EXTRA_libcipher_la_SOURCES = \ sha512.c sha512-ssse3-amd64.S sha512-avx-amd64.S \ sha512-avx2-bmi2-amd64.S \ sha512-armv7-neon.S sha512-arm.S \ - sha512-ppc.c \ + sha512-ppc.c sha512-ssse3-i386.c \ sm3.c \ keccak.c keccak_permute_32.h keccak_permute_64.h keccak-armv7-neon.S \ stribog.c \ @@ -197,6 +197,12 @@ sha256-intel-shaext.o: $(srcdir)/sha256-intel-shaext.c Makefile sha256-intel-shaext.lo: $(srcdir)/sha256-intel-shaext.c Makefile `echo $(LTCOMPILE) -c $< | $(instrumentation_munging) ` +sha256-ssse3-i386.o: $(srcdir)/sha256-ssse3-i386.c Makefile + `echo $(COMPILE) -c $< | $(instrumentation_munging) ` + +sha256-ssse3-i386.lo: $(srcdir)/sha256-ssse3-i386.c Makefile + `echo $(LTCOMPILE) -c $< | $(instrumentation_munging) ` + crc-intel-pclmul.o: $(srcdir)/crc-intel-pclmul.c Makefile `echo $(COMPILE) -c $< | $(instrumentation_munging) ` diff --git a/cipher/sha512-ssse3-i386.c b/cipher/sha512-ssse3-i386.c new file mode 100644 index 000000000..1b53e132d --- /dev/null +++ b/cipher/sha512-ssse3-i386.c @@ -0,0 +1,401 @@ +/* sha512-ssse3-i386.c - i386/SSSE3 implementation of SHA-512 transform + * Copyright (C) 2019 Jussi Kivilinna + * + * This file is part of Libgcrypt. + * + * Libgcrypt is free software; you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License as + * published by the Free Software Foundation; either version 2.1 of + * the License, or (at your option) any later version. + * + * Libgcrypt is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this program; if not, see . + */ + +/* + * SHA512 Message Expansion (I2 and W2 macros) based on implementation + * from file "sha512-ssse3-amd64.s": + ************************************************************************ + * Copyright (c) 2012, Intel Corporation + * + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the + * distribution. + * + * * Neither the name of the Intel Corporation nor the names of its + * contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * + * + * THIS SOFTWARE IS PROVIDED BY INTEL CORPORATION "AS IS" AND ANY + * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL INTEL CORPORATION OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF + * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + ************************************************************************ + */ + +#include + +#if defined(__i386__) && SIZEOF_UNSIGNED_LONG == 4 && __GNUC__ >= 4 && \ + defined(HAVE_GCC_INLINE_ASM_SSSE3) && defined(USE_SHA512) + +#include "bufhelp.h" + + +#if _GCRY_GCC_VERSION >= 40400 /* 4.4 */ +/* Prevent compiler from issuing SSE/MMX instructions between asm blocks. */ +# pragma GCC target("no-sse") +# pragma GCC target("no-mmx") +#endif +#if __clang__ +# pragma clang attribute push (__attribute__((target("no-sse"))), apply_to = function) +# pragma clang attribute push (__attribute__((target("no-mmx"))), apply_to = function) +#endif + + +#define ALWAYS_INLINE inline __attribute__((always_inline)) +#define NO_INLINE __attribute__((noinline)) +#define NO_INSTRUMENT_FUNCTION __attribute__((no_instrument_function)) + +#define ASM_FUNC_ATTR NO_INSTRUMENT_FUNCTION +#define ASM_FUNC_ATTR_INLINE ASM_FUNC_ATTR ALWAYS_INLINE +#define ASM_FUNC_ATTR_NOINLINE ASM_FUNC_ATTR NO_INLINE + + +static const u64 K[80] __attribute__ ((aligned (16))) = + { + U64_C(0x428a2f98d728ae22), U64_C(0x7137449123ef65cd), + U64_C(0xb5c0fbcfec4d3b2f), U64_C(0xe9b5dba58189dbbc), + U64_C(0x3956c25bf348b538), U64_C(0x59f111f1b605d019), + U64_C(0x923f82a4af194f9b), U64_C(0xab1c5ed5da6d8118), + U64_C(0xd807aa98a3030242), U64_C(0x12835b0145706fbe), + U64_C(0x243185be4ee4b28c), U64_C(0x550c7dc3d5ffb4e2), + U64_C(0x72be5d74f27b896f), U64_C(0x80deb1fe3b1696b1), + U64_C(0x9bdc06a725c71235), U64_C(0xc19bf174cf692694), + U64_C(0xe49b69c19ef14ad2), U64_C(0xefbe4786384f25e3), + U64_C(0x0fc19dc68b8cd5b5), U64_C(0x240ca1cc77ac9c65), + U64_C(0x2de92c6f592b0275), U64_C(0x4a7484aa6ea6e483), + U64_C(0x5cb0a9dcbd41fbd4), U64_C(0x76f988da831153b5), + U64_C(0x983e5152ee66dfab), U64_C(0xa831c66d2db43210), + U64_C(0xb00327c898fb213f), U64_C(0xbf597fc7beef0ee4), + U64_C(0xc6e00bf33da88fc2), U64_C(0xd5a79147930aa725), + U64_C(0x06ca6351e003826f), U64_C(0x142929670a0e6e70), + U64_C(0x27b70a8546d22ffc), U64_C(0x2e1b21385c26c926), + U64_C(0x4d2c6dfc5ac42aed), U64_C(0x53380d139d95b3df), + U64_C(0x650a73548baf63de), U64_C(0x766a0abb3c77b2a8), + U64_C(0x81c2c92e47edaee6), U64_C(0x92722c851482353b), + U64_C(0xa2bfe8a14cf10364), U64_C(0xa81a664bbc423001), + U64_C(0xc24b8b70d0f89791), U64_C(0xc76c51a30654be30), + U64_C(0xd192e819d6ef5218), U64_C(0xd69906245565a910), + U64_C(0xf40e35855771202a), U64_C(0x106aa07032bbd1b8), + U64_C(0x19a4c116b8d2d0c8), U64_C(0x1e376c085141ab53), + U64_C(0x2748774cdf8eeb99), U64_C(0x34b0bcb5e19b48a8), + U64_C(0x391c0cb3c5c95a63), U64_C(0x4ed8aa4ae3418acb), + U64_C(0x5b9cca4f7763e373), U64_C(0x682e6ff3d6b2b8a3), + U64_C(0x748f82ee5defb2fc), U64_C(0x78a5636f43172f60), + U64_C(0x84c87814a1f0ab72), U64_C(0x8cc702081a6439ec), + U64_C(0x90befffa23631e28), U64_C(0xa4506cebde82bde9), + U64_C(0xbef9a3f7b2c67915), U64_C(0xc67178f2e372532b), + U64_C(0xca273eceea26619c), U64_C(0xd186b8c721c0c207), + U64_C(0xeada7dd6cde0eb1e), U64_C(0xf57d4f7fee6ed178), + U64_C(0x06f067aa72176fba), U64_C(0x0a637dc5a2c898a6), + U64_C(0x113f9804bef90dae), U64_C(0x1b710b35131c471b), + U64_C(0x28db77f523047d84), U64_C(0x32caab7b40c72493), + U64_C(0x3c9ebe0a15c9bebc), U64_C(0x431d67c49c100d4c), + U64_C(0x4cc5d4becb3e42b6), U64_C(0x597f299cfc657e2a), + U64_C(0x5fcb6fab3ad6faec), U64_C(0x6c44198c4a475817) + }; + +static const unsigned char bshuf_mask[16] __attribute__ ((aligned (16))) = + { 7, 6, 5, 4, 3, 2, 1, 0, 15, 14, 13, 12, 11, 10, 9, 8 }; + + +/* SHA2 round */ +#define RA "%%mm0" +#define RB "%%mm1" +#define RC "%%mm2" +#define RD "%%mm3" +#define RE "%%mm4" +#define RF "%%mm5" +#define RG "%%mm6" +#define RH "%%mm7" + +#define Rx(a,b,c,d,e,f,g,h,wk) \ + asm volatile (/* Cho + Sum1 */ \ + "movq2dq "a", %%xmm2;\n\t" \ + "movq "e", "a";\n\t" \ + "movq2dq "c", %%xmm3;\n\t" \ + "movq "e", "c";\n\t" \ + "movq2dq "b", %%xmm4;\n\t" \ + "movq "e", "b";\n\t" \ + "psrlq $(41-18), "c";\n\t" \ + "pandn "g", "a";\n\t" \ + "pxor "e", "c";\n\t" \ + "pand "f", "b";\n\t" \ + "psrlq $(18-14), "c";\n\t" \ + "paddq "a", "h";\n\t" \ + wk(a) \ + "pxor "e", "c";\n\t" \ + "paddq "b", "h";\n\t" \ + "psrlq $(14), "c";\n\t" \ + "movq "e", "b";\n\t" \ + "psllq $(50-46), "b";\n\t" \ + "paddq "a", "h";\n\t" \ + "movdq2q %%xmm2, "a";\n\t" \ + "pxor "e", "b";\n\t" \ + "psllq $(46-23), "b";\n\t" \ + "pxor "e", "b";\n\t" \ + "psllq $(23), "b";\n\t" \ + "pxor "b", "c";\n\t" \ + "movdq2q %%xmm4, "b";\n\t" \ + "paddq "c", "h";\n\t" \ + "movdq2q %%xmm3, "c";\n\t" \ + \ + /* Maj + Sum0 */ \ + "movq2dq "e", %%xmm2;\n\t" \ + "movq "a", "e";\n\t" \ + "movq2dq "g", %%xmm3;\n\t" \ + "movq "a", "g";\n\t" \ + "movq2dq "f", %%xmm4;\n\t" \ + "movq "a", "f";\n\t" \ + "psrlq $(39-34), "g";\n\t" \ + "pxor "b", "e";\n\t" \ + "pxor "a", "g";\n\t" \ + "pand "b", "f";\n\t" \ + "psrlq $(34-28), "g";\n\t" \ + "pand "c", "e";\n\t" \ + "pxor "a", "g";\n\t" \ + "paddq "h", "d";\n\t" \ + "paddq "f", "h";\n\t" \ + "movdq2q %%xmm4, "f";\n\t" \ + "psrlq $28, "g";\n\t" \ + "paddq "e", "h";\n\t" \ + "movq "a", "e";\n\t" \ + "psllq $(36-30), "e";\n\t" \ + "pxor "a", "e";\n\t" \ + "psllq $(30-25), "e";\n\t" \ + "pxor "a", "e";\n\t" \ + "psllq $(25), "e";\n\t" \ + "pxor "e", "g";\n\t" \ + "movdq2q %%xmm2, "e";\n\t" \ + "paddq "g", "h";\n\t" \ + "movdq2q %%xmm3, "g";\n\t" \ + \ + : \ + : \ + : "memory" ) + +#define WK0(tmp) "movdq2q %%xmm0, "tmp";\n\t" \ + "pshufd $0xee, %%xmm0, %%xmm0;\n\t" + +#define WK1(tmp) "movdq2q %%xmm0, "tmp";\n\t" + +/* Message expansion */ +#define I2(i) \ + asm volatile ("movdqu %[inbuf], %%xmm0;\n\t" \ + "pshufb %%xmm5, %%xmm0;\n\t" \ + "movdqu %%xmm0, %[w];\n\t" \ + "paddq %[k], %%xmm0;\n\t" \ + : \ + : [k] "m" (K[i]), \ + [w] "m" (w[i]), \ + [inbuf] "m" (data[(i)*8]) \ + : "memory" ) + +#define W2(i) \ + asm volatile ("movdqu %[w_t_m_2], %%xmm2;\n\t" \ + "movdqa %%xmm2, %%xmm0;\n\t" \ + "movdqu %[w_t_m_15], %%xmm5;\n\t" \ + "movdqa %%xmm5, %%xmm3;\n\t" \ + "psrlq $(61-19), %%xmm0;\n\t" \ + "psrlq $(8-7), %%xmm3;\n\t" \ + "pxor %%xmm2, %%xmm0;\n\t" \ + "pxor %%xmm5, %%xmm3;\n\t" \ + "psrlq $(19-6), %%xmm0;\n\t" \ + "psrlq $(7-1), %%xmm3;\n\t" \ + "pxor %%xmm2, %%xmm0;\n\t" \ + "pxor %%xmm5, %%xmm3;\n\t" \ + "psrlq $6, %%xmm0;\n\t" \ + "psrlq $1, %%xmm3;\n\t" \ + "movdqa %%xmm2, %%xmm1;\n\t" \ + "movdqa %%xmm5, %%xmm4;\n\t" \ + "psllq $(61-19), %%xmm1;\n\t" \ + "psllq $(8-1), %%xmm4;\n\t" \ + "pxor %%xmm2, %%xmm1;\n\t" \ + "pxor %%xmm5, %%xmm4;\n\t" \ + "psllq $(64-61), %%xmm1;\n\t" \ + "psllq $(64-8), %%xmm4;\n\t" \ + "pxor %%xmm1, %%xmm0;\n\t" \ + "movdqu %[w_t_m_16], %%xmm2;\n\t" \ + "pxor %%xmm4, %%xmm3;\n\t" \ + "movdqu %[w_t_m_7], %%xmm1;\n\t" \ + "paddq %%xmm3, %%xmm0;\n\t" \ + "paddq %%xmm2, %%xmm0;\n\t" \ + "paddq %%xmm1, %%xmm0;\n\t" \ + "movdqu %%xmm0, %[w_t_m_0];\n\t" \ + "paddq %[k], %%xmm0;\n\t" \ + : [w_t_m_0] "=m" (w[(i)-0]) \ + : [k] "m" (K[i]), \ + [w_t_m_2] "m" (w[(i)-2]), \ + [w_t_m_7] "m" (w[(i)-7]), \ + [w_t_m_15] "m" (w[(i)-15]), \ + [w_t_m_16] "m" (w[(i)-16]) \ + : "memory" ) + +unsigned int ASM_FUNC_ATTR +_gcry_sha512_transform_i386_ssse3(u64 state[8], const unsigned char *data, + size_t nblks) +{ + unsigned int t; + u64 w[80]; + + /* Load state to MMX registers. */ + asm volatile ("emms;\n\t" + "movq 8*0(%[state]), "RA";\n\t" + "movq 8*1(%[state]), "RB";\n\t" + "movq 8*2(%[state]), "RC";\n\t" + "movq 8*3(%[state]), "RD";\n\t" + "movq 8*4(%[state]), "RE";\n\t" + "movq 8*5(%[state]), "RF";\n\t" + "movq 8*6(%[state]), "RG";\n\t" + "movq 8*7(%[state]), "RH";\n\t" + : + : [state] "r" (state) + : "memory" ); + + while (nblks) + { + asm volatile ("movdqa %[bshuf_mask], %%xmm5;\n\t" + : + : [bshuf_mask] "m" (*bshuf_mask) + : "memory" ); + + I2(0); + Rx(RA, RB, RC, RD, RE, RF, RG, RH, WK0); + Rx(RH, RA, RB, RC, RD, RE, RF, RG, WK1); + I2(2); + Rx(RG, RH, RA, RB, RC, RD, RE, RF, WK0); + Rx(RF, RG, RH, RA, RB, RC, RD, RE, WK1); + I2(4); + Rx(RE, RF, RG, RH, RA, RB, RC, RD, WK0); + Rx(RD, RE, RF, RG, RH, RA, RB, RC, WK1); + I2(6); + Rx(RC, RD, RE, RF, RG, RH, RA, RB, WK0); + Rx(RB, RC, RD, RE, RF, RG, RH, RA, WK1); + I2(8); + Rx(RA, RB, RC, RD, RE, RF, RG, RH, WK0); + Rx(RH, RA, RB, RC, RD, RE, RF, RG, WK1); + I2(10); + Rx(RG, RH, RA, RB, RC, RD, RE, RF, WK0); + Rx(RF, RG, RH, RA, RB, RC, RD, RE, WK1); + I2(12); + Rx(RE, RF, RG, RH, RA, RB, RC, RD, WK0); + Rx(RD, RE, RF, RG, RH, RA, RB, RC, WK1); + I2(14); + Rx(RC, RD, RE, RF, RG, RH, RA, RB, WK0); + Rx(RB, RC, RD, RE, RF, RG, RH, RA, WK1); + data += 128; + + for (t = 16; t < 80; t += 16) + { + W2(t + 0); + Rx(RA, RB, RC, RD, RE, RF, RG, RH, WK0); + Rx(RH, RA, RB, RC, RD, RE, RF, RG, WK1); + W2(t + 2); + Rx(RG, RH, RA, RB, RC, RD, RE, RF, WK0); + Rx(RF, RG, RH, RA, RB, RC, RD, RE, WK1); + W2(t + 4); + Rx(RE, RF, RG, RH, RA, RB, RC, RD, WK0); + Rx(RD, RE, RF, RG, RH, RA, RB, RC, WK1); + W2(t + 6); + Rx(RC, RD, RE, RF, RG, RH, RA, RB, WK0); + Rx(RB, RC, RD, RE, RF, RG, RH, RA, WK1); + W2(t + 8); + Rx(RA, RB, RC, RD, RE, RF, RG, RH, WK0); + Rx(RH, RA, RB, RC, RD, RE, RF, RG, WK1); + W2(t + 10); + Rx(RG, RH, RA, RB, RC, RD, RE, RF, WK0); + Rx(RF, RG, RH, RA, RB, RC, RD, RE, WK1); + W2(t + 12); + Rx(RE, RF, RG, RH, RA, RB, RC, RD, WK0); + Rx(RD, RE, RF, RG, RH, RA, RB, RC, WK1); + W2(t + 14); + Rx(RC, RD, RE, RF, RG, RH, RA, RB, WK0); + Rx(RB, RC, RD, RE, RF, RG, RH, RA, WK1); + } + + asm volatile ("paddq 8*0(%[state]), "RA";\n\t" + "paddq 8*1(%[state]), "RB";\n\t" + "paddq 8*2(%[state]), "RC";\n\t" + "paddq 8*3(%[state]), "RD";\n\t" + "paddq 8*4(%[state]), "RE";\n\t" + "paddq 8*5(%[state]), "RF";\n\t" + "paddq 8*6(%[state]), "RG";\n\t" + "paddq 8*7(%[state]), "RH";\n\t" + "movq "RA", 8*0(%[state]);\n\t" + "movq "RB", 8*1(%[state]);\n\t" + "movq "RC", 8*2(%[state]);\n\t" + "movq "RD", 8*3(%[state]);\n\t" + "movq "RE", 8*4(%[state]);\n\t" + "movq "RF", 8*5(%[state]);\n\t" + "movq "RG", 8*6(%[state]);\n\t" + "movq "RH", 8*7(%[state]);\n\t" + : + : [state] "r" (state) + : "memory" ); + + nblks--; + } + + /* Clear registers */ + asm volatile ("pxor %%xmm0, %%xmm0;\n\t" + "pxor %%xmm1, %%xmm1;\n\t" + "pxor %%xmm2, %%xmm2;\n\t" + "pxor %%xmm3, %%xmm3;\n\t" + "pxor %%xmm4, %%xmm4;\n\t" + "pxor %%xmm5, %%xmm5;\n\t" + "pxor %%xmm6, %%xmm6;\n\t" + "pxor %%mm0, %%mm0;\n\t" + "pxor %%mm1, %%mm1;\n\t" + "pxor %%mm2, %%mm2;\n\t" + "pxor %%mm3, %%mm3;\n\t" + "pxor %%mm4, %%mm4;\n\t" + "pxor %%mm5, %%mm5;\n\t" + "pxor %%mm6, %%mm6;\n\t" + "pxor %%mm7, %%mm7;\n\t" + "emms;\n\t" + : + : + : "memory" ); + + return sizeof(w) + sizeof(u64) * 6; +} + +#if __clang__ +# pragma clang attribute pop +# pragma clang attribute pop +#endif + +#endif diff --git a/cipher/sha512.c b/cipher/sha512.c index df9a449c3..b603af8d3 100644 --- a/cipher/sha512.c +++ b/cipher/sha512.c @@ -104,6 +104,14 @@ #endif +/* USE_SSSE3_I386 indicates whether to compile with Intel SSSE3/i386 code. */ +#undef USE_SSSE3_I386 +#if defined(__i386__) && SIZEOF_UNSIGNED_LONG == 4 && __GNUC__ >= 4 && \ + defined(HAVE_GCC_INLINE_ASM_SSSE3) +# define USE_SSSE3_I386 1 +#endif + + /* USE_PPC_CRYPTO indicates whether to enable PowerPC vector crypto * accelerated code. */ #undef USE_PPC_CRYPTO @@ -248,6 +256,20 @@ do_sha512_transform_amd64_avx2(void *ctx, const unsigned char *data, } #endif +#ifdef USE_SSSE3_I386 +unsigned int _gcry_sha512_transform_i386_ssse3(u64 state[8], + const unsigned char *input_data, + size_t num_blks); + +static unsigned int +do_sha512_transform_i386_ssse3(void *ctx, const unsigned char *data, + size_t nblks) +{ + SHA512_CONTEXT *hd = ctx; + return _gcry_sha512_transform_i386_ssse3 (&hd->state.h0, data, nblks); +} +#endif + #ifdef USE_ARM_ASM unsigned int _gcry_sha512_transform_arm (SHA512_STATE *hd, @@ -329,6 +351,10 @@ sha512_init_common (SHA512_CONTEXT *ctx, unsigned int flags) ctx->bctx.bwrite = do_sha512_transform_ppc8; if ((features & HWF_PPC_VCRYPTO) != 0 && (features & HWF_PPC_ARCH_3_00) != 0) ctx->bctx.bwrite = do_sha512_transform_ppc9; +#endif +#ifdef USE_SSSE3_I386 + if ((features & HWF_INTEL_SSSE3) != 0) + ctx->bctx.bwrite = do_sha512_transform_i386_ssse3; #endif (void)features; } diff --git a/configure.ac b/configure.ac index 75ec82160..4d4fb49aa 100644 --- a/configure.ac +++ b/configure.ac @@ -2672,6 +2672,10 @@ if test "$found" = "1" ; then GCRYPT_DIGESTS="$GCRYPT_DIGESTS sha512-avx-amd64.lo" GCRYPT_DIGESTS="$GCRYPT_DIGESTS sha512-avx2-bmi2-amd64.lo" ;; + i?86-*-*) + # Build with the assembly implementation + GCRYPT_DIGESTS="$GCRYPT_DIGESTS sha512-ssse3-i386.lo" + ;; arm*-*-*) # Build with the assembly implementation GCRYPT_DIGESTS="$GCRYPT_DIGESTS sha512-arm.lo" From jussi.kivilinna at iki.fi Mon Nov 4 20:50:18 2019 From: jussi.kivilinna at iki.fi (Jussi Kivilinna) Date: Mon, 4 Nov 2019 21:50:18 +0200 Subject: [PATCH] mpi/amd64: use SSE2 for shifting instead of MMX Message-ID: <157289701865.9547.625594576419497749.stgit@localhost.localdomain> * mpi/amd64/mpih-lshift.S: Convert to SSE2. * mpi/amd64/mpih-rshift.S: Ditto. -- On current Intel processors, MMX instructions is slower than SSE2. Switch lshift and rshift functions to use SSE2 registers instead of MMX. Signed-off-by: Jussi Kivilinna --- 0 files changed diff --git a/mpi/amd64/mpih-lshift.S b/mpi/amd64/mpih-lshift.S index 9e8979b10..009bece64 100644 --- a/mpi/amd64/mpih-lshift.S +++ b/mpi/amd64/mpih-lshift.S @@ -43,37 +43,37 @@ .globl C_SYMBOL_NAME(_gcry_mpih_lshift) C_SYMBOL_NAME(_gcry_mpih_lshift:) FUNC_ENTRY() - movq -8(%rsi,%rdx,8), %mm7 - movd %ecx, %mm1 + /* Note: %xmm6 and %xmm7 not used for WIN64 ABI compatibility. */ + movq -8(%rsi,%rdx,8), %xmm4 + movd %ecx, %xmm1 movl $64, %eax subl %ecx, %eax - movd %eax, %mm0 - movq %mm7, %mm3 - psrlq %mm0, %mm7 - movd %mm7, %rax + movd %eax, %xmm0 + movq %xmm4, %xmm3 + psrlq %xmm0, %xmm4 + movd %xmm4, %rax subq $2, %rdx jl .Lendo ALIGN(4) /* minimal alignment for claimed speed */ -.Loop: movq (%rsi,%rdx,8), %mm6 - movq %mm6, %mm2 - psrlq %mm0, %mm6 - psllq %mm1, %mm3 - por %mm6, %mm3 - movq %mm3, 8(%rdi,%rdx,8) +.Loop: movq (%rsi,%rdx,8), %xmm5 + movq %xmm5, %xmm2 + psrlq %xmm0, %xmm5 + psllq %xmm1, %xmm3 + por %xmm5, %xmm3 + movq %xmm3, 8(%rdi,%rdx,8) je .Lende - movq -8(%rsi,%rdx,8), %mm7 - movq %mm7, %mm3 - psrlq %mm0, %mm7 - psllq %mm1, %mm2 - por %mm7, %mm2 - movq %mm2, (%rdi,%rdx,8) + movq -8(%rsi,%rdx,8), %xmm4 + movq %xmm4, %xmm3 + psrlq %xmm0, %xmm4 + psllq %xmm1, %xmm2 + por %xmm4, %xmm2 + movq %xmm2, (%rdi,%rdx,8) subq $2, %rdx jge .Loop -.Lendo: movq %mm3, %mm2 -.Lende: psllq %mm1, %mm2 - movq %mm2, (%rdi) - emms +.Lendo: movq %xmm3, %xmm2 +.Lende: psllq %xmm1, %xmm2 + movq %xmm2, (%rdi) FUNC_EXIT() ret diff --git a/mpi/amd64/mpih-rshift.S b/mpi/amd64/mpih-rshift.S index 7bd594216..db31060de 100644 --- a/mpi/amd64/mpih-rshift.S +++ b/mpi/amd64/mpih-rshift.S @@ -43,14 +43,15 @@ .globl C_SYMBOL_NAME(_gcry_mpih_rshift) C_SYMBOL_NAME(_gcry_mpih_rshift:) FUNC_ENTRY() - movq (%rsi), %mm7 - movd %ecx, %mm1 + /* Note: %xmm6 and %xmm7 not used for WIN64 ABI compatibility. */ + movq (%rsi), %xmm4 + movd %ecx, %xmm1 movl $64, %eax subl %ecx, %eax - movd %eax, %mm0 - movq %mm7, %mm3 - psllq %mm0, %mm7 - movd %mm7, %rax + movd %eax, %xmm0 + movq %xmm4, %xmm3 + psllq %xmm0, %xmm4 + movd %xmm4, %rax leaq (%rsi,%rdx,8), %rsi leaq (%rdi,%rdx,8), %rdi negq %rdx @@ -58,25 +59,24 @@ C_SYMBOL_NAME(_gcry_mpih_rshift:) jg .Lendo ALIGN(4) /* minimal alignment for claimed speed */ -.Loop: movq -8(%rsi,%rdx,8), %mm6 - movq %mm6, %mm2 - psllq %mm0, %mm6 - psrlq %mm1, %mm3 - por %mm6, %mm3 - movq %mm3, -16(%rdi,%rdx,8) +.Loop: movq -8(%rsi,%rdx,8), %xmm5 + movq %xmm5, %xmm2 + psllq %xmm0, %xmm5 + psrlq %xmm1, %xmm3 + por %xmm5, %xmm3 + movq %xmm3, -16(%rdi,%rdx,8) je .Lende - movq (%rsi,%rdx,8), %mm7 - movq %mm7, %mm3 - psllq %mm0, %mm7 - psrlq %mm1, %mm2 - por %mm7, %mm2 - movq %mm2, -8(%rdi,%rdx,8) + movq (%rsi,%rdx,8), %xmm4 + movq %xmm4, %xmm3 + psllq %xmm0, %xmm4 + psrlq %xmm1, %xmm2 + por %xmm4, %xmm2 + movq %xmm2, -8(%rdi,%rdx,8) addq $2, %rdx jle .Loop -.Lendo: movq %mm3, %mm2 -.Lende: psrlq %mm1, %mm2 - movq %mm2, -8(%rdi) - emms +.Lendo: movq %xmm3, %xmm2 +.Lende: psrlq %xmm1, %xmm2 + movq %xmm2, -8(%rdi) FUNC_EXIT() ret From jussi.kivilinna at iki.fi Mon Nov 4 20:50:53 2019 From: jussi.kivilinna at iki.fi (Jussi Kivilinna) Date: Mon, 4 Nov 2019 21:50:53 +0200 Subject: [PATCH] ec: fix left shift overflows on WIN64 build Message-ID: <157289705313.9735.11394241960977035841.stgit@localhost.localdomain> * mpi/ec.c (ec_mulm_448): Cast constants to (mpi_limb_t) before shifting left by 32. -- Patch fixes following warnings: .../libgcrypt/mpi/ec.c: In function 'ec_mulm_448': .../libgcrypt/mpi/ec.c:563:35: warning: left shift count >= width of type [-Wshift-count-overflow] 563 | b0[LIMB_SIZE_HALF_448-1] &= (1UL<<32)-1; | ^~ .../libgcrypt/mpi/ec.c:564:35: warning: left shift count >= width of type [-Wshift-count-overflow] 564 | a2[LIMB_SIZE_HALF_448-1] &= (1UL<<32)-1; | ^~ .../libgcrypt/mpi/ec.c:576:29: warning: left shift count >= width of type [-Wshift-count-overflow] 576 | b1_rest = b1v & ((1UL <<32)-1); | ^~ .../libgcrypt/mpi/ec.c:577:29: warning: left shift count >= width of type [-Wshift-count-overflow] 577 | a3_rest = a3v & ((1UL <<32)-1); | ^~ .../libgcrypt/mpi/ec.c:586:37: warning: left shift count >= width of type [-Wshift-count-overflow] 586 | wp[LIMB_SIZE_HALF_448-1] &= ((1UL <<32)-1); | ^~ .../libgcrypt/mpi/ec.c:603:29: warning: left shift count >= width of type [-Wshift-count-overflow] 603 | b1_rest = b1v & ((1UL <<32)-1); | ^~ Signed-off-by: Jussi Kivilinna --- 0 files changed diff --git a/mpi/ec.c b/mpi/ec.c index 8f463bd10..d4c4f9535 100644 --- a/mpi/ec.c +++ b/mpi/ec.c @@ -560,8 +560,8 @@ ec_mulm_448 (gcry_mpi_t w, gcry_mpi_t u, gcry_mpi_t v, mpi_ec_t ctx) } #if (LIMB_SIZE_HALF_448 > LIMB_SIZE_448/2) - b0[LIMB_SIZE_HALF_448-1] &= (1UL<<32)-1; - a2[LIMB_SIZE_HALF_448-1] &= (1UL<<32)-1; + b0[LIMB_SIZE_HALF_448-1] &= ((mpi_limb_t)1UL<<32)-1; + a2[LIMB_SIZE_HALF_448-1] &= ((mpi_limb_t)1UL<<32)-1; b1_rest = 0; a3_rest = 0; @@ -573,8 +573,8 @@ ec_mulm_448 (gcry_mpi_t w, gcry_mpi_t u, gcry_mpi_t v, mpi_ec_t ctx) a3v = a3[i]; b1[i] = (b1_rest<<32) | (b1v >> 32); a3[i] = (a3_rest<<32) | (a3v >> 32); - b1_rest = b1v & ((1UL <<32)-1); - a3_rest = a3v & ((1UL <<32)-1); + b1_rest = b1v & (((mpi_limb_t)1UL <<32)-1); + a3_rest = a3v & (((mpi_limb_t)1UL <<32)-1); } #endif @@ -583,7 +583,7 @@ ec_mulm_448 (gcry_mpi_t w, gcry_mpi_t u, gcry_mpi_t v, mpi_ec_t ctx) for (i = 0; i < (wsize + 1)/ 2; i++) wp[i] = b0[i]; #if (LIMB_SIZE_HALF_448 > LIMB_SIZE_448/2) - wp[LIMB_SIZE_HALF_448-1] &= ((1UL <<32)-1); + wp[LIMB_SIZE_HALF_448-1] &= (((mpi_limb_t)1UL <<32)-1); #endif #if (LIMB_SIZE_HALF_448 > LIMB_SIZE_448/2) @@ -600,7 +600,7 @@ ec_mulm_448 (gcry_mpi_t w, gcry_mpi_t u, gcry_mpi_t v, mpi_ec_t ctx) { mpi_limb_t b1v = b1[i]; b1[i] = (b1_rest<<32) | (b1v >> 32); - b1_rest = b1v & ((1UL <<32)-1); + b1_rest = b1v & (((mpi_limb_t)1UL <<32)-1); } wp[LIMB_SIZE_HALF_448-1] |= (b1_rest << 32); #endif From gniibe at fsij.org Wed Nov 6 07:37:12 2019 From: gniibe at fsij.org (Niibe Yutaka) Date: Wed, 06 Nov 2019 15:37:12 +0900 Subject: [PATCH] ec: fix left shift overflows on WIN64 build In-Reply-To: <157289705313.9735.11394241960977035841.stgit@localhost.localdomain> References: <157289705313.9735.11394241960977035841.stgit@localhost.localdomain> Message-ID: <871rul4ijr.fsf@jumper.gniibe.org> Jussi Kivilinna via Gcrypt-devel wrote: > * mpi/ec.c (ec_mulm_448): Cast constants to (mpi_limb_t) before > shifting left by 32. Thanks. When I wrote that, I forgot to consider about LLP64 system. -- From dbaryshkov at gmail.com Tue Nov 12 08:58:18 2019 From: dbaryshkov at gmail.com (dbaryshkov at gmail.com) Date: Tue, 12 Nov 2019 10:58:18 +0300 Subject: [PATCH 3/4] ecc: add OID for GOST2012-512-test curve In-Reply-To: <20191112075819.11112-1-dbaryshkov@gmail.com> References: <20191112075819.11112-1-dbaryshkov@gmail.com> Message-ID: <20191112075819.11112-3-dbaryshkov@gmail.com> From: Dmitry Eremin-Solenikov * cipher/ecc-curves.c (curve_aliases): add OID for GOST2012-512-test. Signed-off-by: Dmitry Eremin-Solenikov --- cipher/ecc-curves.c | 1 + 1 file changed, 1 insertion(+) diff --git a/cipher/ecc-curves.c b/cipher/ecc-curves.c index 021c19261f27..732219a99572 100644 --- a/cipher/ecc-curves.c +++ b/cipher/ecc-curves.c @@ -104,6 +104,7 @@ static const struct { "GOST2001-CryptoPro-C", "1.2.643.7.1.2.1.1.4" }, { "GOST2001-CryptoPro-C", "GOST2012-256-tc26-D" }, + { "GOST2012-512-test", " 1.2.643.7.1.2.1.2.0" }, { "GOST2012-512-tc26-A", "GOST2012-tc26-A" }, { "GOST2012-512-tc26-B", "GOST2012-tc26-B" }, { "GOST2012-512-tc26-A", "1.2.643.7.1.2.1.2.1" }, -- 2.24.0 From dbaryshkov at gmail.com Tue Nov 12 08:58:16 2019 From: dbaryshkov at gmail.com (dbaryshkov at gmail.com) Date: Tue, 12 Nov 2019 10:58:16 +0300 Subject: [PATCH 1/4] ecc: rename 512-bit GOST curves Message-ID: <20191112075819.11112-1-dbaryshkov@gmail.com> From: Paul Wolneykien * cipher/ecc-curves.c (domain_parms): rename GOST 2012 curves to contain curve bit size (curve_aliases): rename curves and provide backwards-compatible aliases. * tests/basic.c (check_pubkey): use new name for GOST2012 512-bit test curve. * tests/benchmark.c (ecc_bench): use new name for GOST2012 512-bit test curve. -- In preparation to adding new GOST2012 curves, rename old GOST2012 curves to specifically mention that they are 512-bit curves. Signed-off-by: Paul Wolneykien Signed-off-by: Dmitry Eremin-Solenikov --- cipher/ecc-curves.c | 12 +++++++----- tests/basic.c | 4 ++-- tests/benchmark.c | 2 +- 3 files changed, 10 insertions(+), 8 deletions(-) diff --git a/cipher/ecc-curves.c b/cipher/ecc-curves.c index 581ba4d66e54..4ba66cb353dd 100644 --- a/cipher/ecc-curves.c +++ b/cipher/ecc-curves.c @@ -97,8 +97,10 @@ static const struct { "GOST2001-CryptoPro-A", "1.2.643.2.2.36.0" }, { "GOST2001-CryptoPro-C", "1.2.643.2.2.36.1" }, - { "GOST2012-tc26-A", "1.2.643.7.1.2.1.2.1" }, - { "GOST2012-tc26-B", "1.2.643.7.1.2.1.2.2" }, + { "GOST2012-512-tc26-A", "GOST2012-tc26-A" }, + { "GOST2012-512-tc26-B", "GOST2012-tc26-B" }, + { "GOST2012-512-tc26-A", "1.2.643.7.1.2.1.2.1" }, + { "GOST2012-512-tc26-B", "1.2.643.7.1.2.1.2.2" }, { "secp256k1", "1.3.132.0.10" }, @@ -408,7 +410,7 @@ static const ecc_domain_parms_t domain_parms[] = 1 }, { - "GOST2012-test", 511, 0, + "GOST2012-512-test", 511, 0, MPI_EC_WEIERSTRASS, ECC_DIALECT_STANDARD, "0x4531acd1fe0023c7550d267b6b2fee80922b14b2ffb90f04d4eb7c09b5d2d15d" "f1d852741af4704a0458047e80e4546d35b8336fac224dd81664bbf528be6373", @@ -425,7 +427,7 @@ static const ecc_domain_parms_t domain_parms[] = 1 }, { - "GOST2012-tc26-A", 512, 0, + "GOST2012-512-tc26-A", 512, 0, MPI_EC_WEIERSTRASS, ECC_DIALECT_STANDARD, "0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff" "fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffdc7", @@ -442,7 +444,7 @@ static const ecc_domain_parms_t domain_parms[] = 1 }, { - "GOST2012-tc26-B", 512, 0, + "GOST2012-512-tc26-B", 512, 0, MPI_EC_WEIERSTRASS, ECC_DIALECT_STANDARD, "0x8000000000000000000000000000000000000000000000000000000000000000" "000000000000000000000000000000000000000000000000000000000000006f", diff --git a/tests/basic.c b/tests/basic.c index b798eaafa21c..8337bcfb7ba0 100644 --- a/tests/basic.c +++ b/tests/basic.c @@ -13227,7 +13227,7 @@ check_pubkey (void) { "(private-key\n" " (ecc\n" - " (curve GOST2012-test)\n" + " (curve GOST2012-512-test)\n" " (q #04115DC5BC96760C7B48598D8AB9E740D4C4A85A65BE33C1" " 815B5C320C854621DD5A515856D13314AF69BC5B924C8B" " 4DDFF75C45415C1D9DD9DD33612CD530EFE137C7C90CD4" @@ -13240,7 +13240,7 @@ check_pubkey (void) "(public-key\n" " (ecc\n" - " (curve GOST2012-test)\n" + " (curve GOST2012-512-test)\n" " (q #04115DC5BC96760C7B48598D8AB9E740D4C4A85A65BE33C1" " 815B5C320C854621DD5A515856D13314AF69BC5B924C8B" " 4DDFF75C45415C1D9DD9DD33612CD530EFE137C7C90CD4" diff --git a/tests/benchmark.c b/tests/benchmark.c index 0f15c0d89fe7..a245152c0228 100644 --- a/tests/benchmark.c +++ b/tests/benchmark.c @@ -1528,7 +1528,7 @@ ecc_bench (int iterations, int print_header) else if (is_gost) err = gcry_sexp_build (&key_spec, NULL, "(genkey (ecdsa (curve %s)))", - p_size == 256 ? "GOST2001-test" : "GOST2012-test"); + p_size == 256 ? "GOST2001-test" : "GOST2012-512-test"); else err = gcry_sexp_build (&key_spec, NULL, "(genkey (ECDSA (nbits %d)))", p_size); -- 2.24.0 From dbaryshkov at gmail.com Tue Nov 12 08:58:19 2019 From: dbaryshkov at gmail.com (dbaryshkov at gmail.com) Date: Tue, 12 Nov 2019 10:58:19 +0300 Subject: [PATCH 4/4] ecc: added GOST R 34.10-2012 Edwards curves from RFC 7836 In-Reply-To: <20191112075819.11112-1-dbaryshkov@gmail.com> References: <20191112075819.11112-1-dbaryshkov@gmail.com> Message-ID: <20191112075819.11112-4-dbaryshkov@gmail.com> From: Paul Wolneykien * cipher/ecc-curves.c (domain_parms): add two curves defined in RFC 7836 (curve_aliases): add OIDs for new curves. -- [DES: added curve GOST2012-512-tc26-C, fixed cofactors to the value 4.] Signed-off-by: Paul Wolneykien Signed-off-by: Dmitry Eremin-Solenikov --- cipher/ecc-curves.c | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/cipher/ecc-curves.c b/cipher/ecc-curves.c index 732219a99572..e1085f817b04 100644 --- a/cipher/ecc-curves.c +++ b/cipher/ecc-curves.c @@ -97,6 +97,7 @@ static const struct { "GOST2001-CryptoPro-A", "1.2.643.2.2.36.0" }, { "GOST2001-CryptoPro-C", "1.2.643.2.2.36.1" }, + { "GOST2012-256-tc26-A", "1.2.643.7.1.2.1.1.1" }, { "GOST2001-CryptoPro-A", "1.2.643.7.1.2.1.1.2" }, { "GOST2001-CryptoPro-A", "GOST2012-256-tc26-B" }, { "GOST2001-CryptoPro-B", "1.2.643.7.1.2.1.1.3" }, @@ -109,6 +110,7 @@ static const struct { "GOST2012-512-tc26-B", "GOST2012-tc26-B" }, { "GOST2012-512-tc26-A", "1.2.643.7.1.2.1.2.1" }, { "GOST2012-512-tc26-B", "1.2.643.7.1.2.1.2.2" }, + { "GOST2012-512-tc26-C", "1.2.643.7.1.2.1.2.3" }, { "secp256k1", "1.3.132.0.10" }, @@ -479,6 +481,23 @@ static const ecc_domain_parms_t domain_parms[] = "dcb228fd1edf4a39152cbcaaf8c0398828041055f94ceeec7e21340780fe41bd", 1 }, + { + "GOST2012-512-tc26-C", 512, 0, + MPI_EC_WEIERSTRASS, ECC_DIALECT_STANDARD, + "0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff" + "fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffdc7", + "0xdc9203e514a721875485a529d2c722fb187bc8980eb866644de41c68e1430645" + "46e861c0e2c9edd92ade71f46fcf50ff2ad97f951fda9f2a2eb6546f39689bd3", + "0xb4c4ee28cebc6c2c8ac12952cf37f16ac7efb6a9f69f4b57ffda2e4f0de5ade0" + "38cbc2fff719d2c18de0284b8bfef3b52b8cc7a5f5bf0a3c8d2319a5312557e1", + "0x3fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff" + "c98cdba46506ab004c33a9ff5147502cc8eda9e7a769a12694623cef47f023ed", + "0xe2e31edfc23de7bdebe241ce593ef5de2295b7a9cbaef021d385f7074cea043a" + "a27272a7ae602bf2a7b9033db9ed3610c6fb85487eae97aac5bc7928c1950148", + "0xf5ce40d95b5eb899abbccff5911cb8577939804d6527378b8c108c3d2090ff9be" + "18e2d33e3021ed2ef32d85822423b6304f726aa854bae07d0396e9a9addc40f", + 4 + }, { "secp256k1", 256, 0, -- 2.24.0 From dbaryshkov at gmail.com Tue Nov 12 08:58:17 2019 From: dbaryshkov at gmail.com (dbaryshkov at gmail.com) Date: Tue, 12 Nov 2019 10:58:17 +0300 Subject: [PATCH 2/4] ecc: added GOST R 34.10-2012 curve aliases In-Reply-To: <20191112075819.11112-1-dbaryshkov@gmail.com> References: <20191112075819.11112-1-dbaryshkov@gmail.com> Message-ID: <20191112075819.11112-2-dbaryshkov@gmail.com> From: Paul Wolneykien * cipher/ecc-curves.c (curve_aliases): add new OIDs and aliases for GOST2012 curves. -- TC26 has defined new OIDs (and new names) for old 256-bit curves. Add new aliaes for CryptoPro curves. Signed-off-by: Paul Wolneykien Signed-off-by: Dmitry Eremin-Solenikov --- cipher/ecc-curves.c | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/cipher/ecc-curves.c b/cipher/ecc-curves.c index 4ba66cb353dd..021c19261f27 100644 --- a/cipher/ecc-curves.c +++ b/cipher/ecc-curves.c @@ -97,6 +97,13 @@ static const struct { "GOST2001-CryptoPro-A", "1.2.643.2.2.36.0" }, { "GOST2001-CryptoPro-C", "1.2.643.2.2.36.1" }, + { "GOST2001-CryptoPro-A", "1.2.643.7.1.2.1.1.2" }, + { "GOST2001-CryptoPro-A", "GOST2012-256-tc26-B" }, + { "GOST2001-CryptoPro-B", "1.2.643.7.1.2.1.1.3" }, + { "GOST2001-CryptoPro-B", "GOST2012-256-tc26-C" }, + { "GOST2001-CryptoPro-C", "1.2.643.7.1.2.1.1.4" }, + { "GOST2001-CryptoPro-C", "GOST2012-256-tc26-D" }, + { "GOST2012-512-tc26-A", "GOST2012-tc26-A" }, { "GOST2012-512-tc26-B", "GOST2012-tc26-B" }, { "GOST2012-512-tc26-A", "1.2.643.7.1.2.1.2.1" }, @@ -409,6 +416,17 @@ static const ecc_domain_parms_t domain_parms[] = "0x41ece55743711a8c3cbf3783cd08c0ee4d4dc440d4641a8f366e550dfdb3bb67", 1 }, + { + "GOST2012-256-A", 256, 0, + MPI_EC_WEIERSTRASS, ECC_DIALECT_STANDARD, + "0xfffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffd97", + "0xc2173f1513981673af4892c23035a27ce25e2013bf95aa33b22c656f277e7335", + "0x295f9bae7428ed9ccc20e7c359a9d41a22fccd9108e17bf7ba9337a6f8ae9513", + "0x400000000000000000000000000000000fd8cddfc87b6635c115af556c360c67", + "0x91e38443a5e82c0d880923425712b2bb658b9196932e02c78b2582fe742daa28", + "0x32879423ab1a0375895786c4bb46e9565fde0b5344766740af268adb32322e5c", + 4 + }, { "GOST2012-512-test", 511, 0, MPI_EC_WEIERSTRASS, ECC_DIALECT_STANDARD, -- 2.24.0 From dbaryshkov at gmail.com Tue Nov 12 14:50:02 2019 From: dbaryshkov at gmail.com (dbaryshkov at gmail.com) Date: Tue, 12 Nov 2019 16:50:02 +0300 Subject: [PATCH 1/4] gostr3411-94: small speedup Message-ID: <20191112135005.7697-1-dbaryshkov@gmail.com> From: Dmitry Eremin-Solenikov * cipher/gostr3411-94.c (do_p): unroll loop for a small spedup -- Before: GOSTR3411_94 | 25.12 ns/B 37.96 MiB/s - c/B GOSTR3411_CP | 25.14 ns/B 37.93 MiB/s - c/B After: GOSTR3411_94 | 24.57 ns/B 38.81 MiB/s - c/B GOSTR3411_CP | 24.59 ns/B 38.79 MiB/s - c/B Signed-off-by: Dmitry Eremin-Solenikov --- cipher/gostr3411-94.c | 50 +++++++++++++++++++++++++++++++++---------- 1 file changed, 39 insertions(+), 11 deletions(-) diff --git a/cipher/gostr3411-94.c b/cipher/gostr3411-94.c index ebf9e0a242f3..c5a0aef63de3 100644 --- a/cipher/gostr3411-94.c +++ b/cipher/gostr3411-94.c @@ -83,17 +83,45 @@ do_p (u32 *p, u32 *u, u32 *v) for (k = 0; k < 8; k++) t[k] = u[k] ^ v[k]; - for (k = 0; k < 4; k++) - { - p[k+0] = ((t[0] >> (8*k)) & 0xff) << 0 | - ((t[2] >> (8*k)) & 0xff) << 8 | - ((t[4] >> (8*k)) & 0xff) << 16 | - ((t[6] >> (8*k)) & 0xff) << 24; - p[k+4] = ((t[1] >> (8*k)) & 0xff) << 0 | - ((t[3] >> (8*k)) & 0xff) << 8 | - ((t[5] >> (8*k)) & 0xff) << 16 | - ((t[7] >> (8*k)) & 0xff) << 24; - } + k = 0; + p[k+0] = ((t[0] >> (8*k)) & 0xff) << 0 | + ((t[2] >> (8*k)) & 0xff) << 8 | + ((t[4] >> (8*k)) & 0xff) << 16 | + ((t[6] >> (8*k)) & 0xff) << 24; + p[k+4] = ((t[1] >> (8*k)) & 0xff) << 0 | + ((t[3] >> (8*k)) & 0xff) << 8 | + ((t[5] >> (8*k)) & 0xff) << 16 | + ((t[7] >> (8*k)) & 0xff) << 24; + + k = 1; + p[k+0] = ((t[0] >> (8*k)) & 0xff) << 0 | + ((t[2] >> (8*k)) & 0xff) << 8 | + ((t[4] >> (8*k)) & 0xff) << 16 | + ((t[6] >> (8*k)) & 0xff) << 24; + p[k+4] = ((t[1] >> (8*k)) & 0xff) << 0 | + ((t[3] >> (8*k)) & 0xff) << 8 | + ((t[5] >> (8*k)) & 0xff) << 16 | + ((t[7] >> (8*k)) & 0xff) << 24; + + k = 2; + p[k+0] = ((t[0] >> (8*k)) & 0xff) << 0 | + ((t[2] >> (8*k)) & 0xff) << 8 | + ((t[4] >> (8*k)) & 0xff) << 16 | + ((t[6] >> (8*k)) & 0xff) << 24; + p[k+4] = ((t[1] >> (8*k)) & 0xff) << 0 | + ((t[3] >> (8*k)) & 0xff) << 8 | + ((t[5] >> (8*k)) & 0xff) << 16 | + ((t[7] >> (8*k)) & 0xff) << 24; + + k = 3; + p[k+0] = ((t[0] >> (8*k)) & 0xff) << 0 | + ((t[2] >> (8*k)) & 0xff) << 8 | + ((t[4] >> (8*k)) & 0xff) << 16 | + ((t[6] >> (8*k)) & 0xff) << 24; + p[k+4] = ((t[1] >> (8*k)) & 0xff) << 0 | + ((t[3] >> (8*k)) & 0xff) << 8 | + ((t[5] >> (8*k)) & 0xff) << 16 | + ((t[7] >> (8*k)) & 0xff) << 24; } static void -- 2.24.0 From dbaryshkov at gmail.com Tue Nov 12 14:50:04 2019 From: dbaryshkov at gmail.com (dbaryshkov at gmail.com) Date: Tue, 12 Nov 2019 16:50:04 +0300 Subject: [PATCH 3/4] gost28147: do not use GOST28147_CONTEXT outside of GOST 28147 calculation In-Reply-To: <20191112135005.7697-1-dbaryshkov@gmail.com> References: <20191112135005.7697-1-dbaryshkov@gmail.com> Message-ID: <20191112135005.7697-3-dbaryshkov@gmail.com> From: Dmitry Eremin-Solenikov * cipher/gost28147.c (_gcry_gost_enc_data): remove unused context argument * cipher/gostr3411-94.c (GOSTR3411_CONTEXT, gostr3411_init, do_hash_step): remove unused GOST 28147-89 context. Signed-off-by: Dmitry Eremin-Solenikov --- cipher/gost.h | 2 +- cipher/gost28147.c | 2 +- cipher/gostr3411-94.c | 4 +--- 3 files changed, 3 insertions(+), 5 deletions(-) diff --git a/cipher/gost.h b/cipher/gost.h index 025119c90656..04c2f85e57d2 100644 --- a/cipher/gost.h +++ b/cipher/gost.h @@ -26,7 +26,7 @@ typedef struct { } GOST28147_context; /* This is a simple interface that will be used by GOST R 34.11-94 */ -unsigned int _gcry_gost_enc_data (GOST28147_context *c, const u32 *key, +unsigned int _gcry_gost_enc_data (const u32 *key, u32 *o1, u32 *o2, u32 n1, u32 n2, int cryptopro); #endif diff --git a/cipher/gost28147.c b/cipher/gost28147.c index 85d398d7b7de..db7e9412c7cd 100644 --- a/cipher/gost28147.c +++ b/cipher/gost28147.c @@ -120,7 +120,7 @@ gost_encrypt_block (void *c, byte *outbuf, const byte *inbuf) return /* burn_stack */ burn + 6*sizeof(void*) /* func call */; } -unsigned int _gcry_gost_enc_data (GOST28147_context *c, const u32 *key, +unsigned int _gcry_gost_enc_data (const u32 *key, u32 *o1, u32 *o2, u32 n1, u32 n2, int cryptopro) { const u32 *sbox; diff --git a/cipher/gostr3411-94.c b/cipher/gostr3411-94.c index c5a0aef63de3..7cf0637e26ed 100644 --- a/cipher/gostr3411-94.c +++ b/cipher/gostr3411-94.c @@ -35,7 +35,6 @@ typedef struct { gcry_md_block_ctx_t bctx; - GOST28147_context hd; union { u32 h[8]; byte result[32]; @@ -55,7 +54,6 @@ gost3411_init (void *context, unsigned int flags) (void)flags; - memset (&hd->hd, 0, sizeof(hd->hd)); memset (hd->h, 0, 32); memset (hd->sigma, 0, 32); @@ -228,7 +226,7 @@ do_hash_step (GOSTR3411_CONTEXT *hd, u32 *h, u32 *m) for (i = 0; i < 4; i++) { do_p (k, u, v); - burn = _gcry_gost_enc_data (&hd->hd, k, &s[2*i], &s[2*i+1], h[2*i], h[2*i+1], hd->cryptopro); + burn = _gcry_gost_enc_data (k, &s[2*i], &s[2*i+1], h[2*i], h[2*i+1], hd->cryptopro); do_a (u); if (i == 1) -- 2.24.0 From dbaryshkov at gmail.com Tue Nov 12 14:50:03 2019 From: dbaryshkov at gmail.com (dbaryshkov at gmail.com) Date: Tue, 12 Nov 2019 16:50:03 +0300 Subject: [PATCH 2/4] gost28147: simplify internal code In-Reply-To: <20191112135005.7697-1-dbaryshkov@gmail.com> References: <20191112135005.7697-1-dbaryshkov@gmail.com> Message-ID: <20191112135005.7697-2-dbaryshkov@gmail.com> From: Dmitry Eremin-Solenikov * cipher/gost28147.c (gost_val, _gost_encrypt_data): don't use gost context internally * cipher/gost28147.c (gost_encrypt_block, gost_decrypt_block, _gcry_gost_enc_data): adapt to internal changes. -- This saves us one memcpy in _gcry_gost_enc_data(), thus speeding up GOST R 34.11-94. Signed-off-by: Dmitry Eremin-Solenikov --- cipher/gost28147.c | 103 ++++++++++++++++++++++----------------------- 1 file changed, 51 insertions(+), 52 deletions(-) diff --git a/cipher/gost28147.c b/cipher/gost28147.c index 1b8ab7aebfba..85d398d7b7de 100644 --- a/cipher/gost28147.c +++ b/cipher/gost28147.c @@ -61,40 +61,38 @@ gost_setkey (void *c, const byte *key, unsigned keylen, } static u32 -gost_val (GOST28147_context *ctx, u32 cm1, int subkey) +gost_val (u32 subkey, u32 cm1, const u32 *sbox) { - cm1 += ctx->key[subkey]; - cm1 = ctx->sbox[0*256 + ((cm1 >> 0) & 0xff)] | - ctx->sbox[1*256 + ((cm1 >> 8) & 0xff)] | - ctx->sbox[2*256 + ((cm1 >> 16) & 0xff)] | - ctx->sbox[3*256 + ((cm1 >> 24) & 0xff)]; + cm1 += subkey; + cm1 = sbox[0*256 + ((cm1 >> 0) & 0xff)] | + sbox[1*256 + ((cm1 >> 8) & 0xff)] | + sbox[2*256 + ((cm1 >> 16) & 0xff)] | + sbox[3*256 + ((cm1 >> 24) & 0xff)]; return cm1; } static unsigned int -_gost_encrypt_data (void *c, u32 *o1, u32 *o2, u32 n1, u32 n2) +_gost_encrypt_data (const u32 *sbox, const u32 *key, u32 *o1, u32 *o2, u32 n1, u32 n2) { - GOST28147_context *ctx = c; - - n2 ^= gost_val (ctx, n1, 0); n1 ^= gost_val (ctx, n2, 1); - n2 ^= gost_val (ctx, n1, 2); n1 ^= gost_val (ctx, n2, 3); - n2 ^= gost_val (ctx, n1, 4); n1 ^= gost_val (ctx, n2, 5); - n2 ^= gost_val (ctx, n1, 6); n1 ^= gost_val (ctx, n2, 7); - - n2 ^= gost_val (ctx, n1, 0); n1 ^= gost_val (ctx, n2, 1); - n2 ^= gost_val (ctx, n1, 2); n1 ^= gost_val (ctx, n2, 3); - n2 ^= gost_val (ctx, n1, 4); n1 ^= gost_val (ctx, n2, 5); - n2 ^= gost_val (ctx, n1, 6); n1 ^= gost_val (ctx, n2, 7); - - n2 ^= gost_val (ctx, n1, 0); n1 ^= gost_val (ctx, n2, 1); - n2 ^= gost_val (ctx, n1, 2); n1 ^= gost_val (ctx, n2, 3); - n2 ^= gost_val (ctx, n1, 4); n1 ^= gost_val (ctx, n2, 5); - n2 ^= gost_val (ctx, n1, 6); n1 ^= gost_val (ctx, n2, 7); - - n2 ^= gost_val (ctx, n1, 7); n1 ^= gost_val (ctx, n2, 6); - n2 ^= gost_val (ctx, n1, 5); n1 ^= gost_val (ctx, n2, 4); - n2 ^= gost_val (ctx, n1, 3); n1 ^= gost_val (ctx, n2, 2); - n2 ^= gost_val (ctx, n1, 1); n1 ^= gost_val (ctx, n2, 0); + n2 ^= gost_val (key[0], n1, sbox); n1 ^= gost_val (key[1], n2, sbox); + n2 ^= gost_val (key[2], n1, sbox); n1 ^= gost_val (key[3], n2, sbox); + n2 ^= gost_val (key[4], n1, sbox); n1 ^= gost_val (key[5], n2, sbox); + n2 ^= gost_val (key[6], n1, sbox); n1 ^= gost_val (key[7], n2, sbox); + + n2 ^= gost_val (key[0], n1, sbox); n1 ^= gost_val (key[1], n2, sbox); + n2 ^= gost_val (key[2], n1, sbox); n1 ^= gost_val (key[3], n2, sbox); + n2 ^= gost_val (key[4], n1, sbox); n1 ^= gost_val (key[5], n2, sbox); + n2 ^= gost_val (key[6], n1, sbox); n1 ^= gost_val (key[7], n2, sbox); + + n2 ^= gost_val (key[0], n1, sbox); n1 ^= gost_val (key[1], n2, sbox); + n2 ^= gost_val (key[2], n1, sbox); n1 ^= gost_val (key[3], n2, sbox); + n2 ^= gost_val (key[4], n1, sbox); n1 ^= gost_val (key[5], n2, sbox); + n2 ^= gost_val (key[6], n1, sbox); n1 ^= gost_val (key[7], n2, sbox); + + n2 ^= gost_val (key[7], n1, sbox); n1 ^= gost_val (key[6], n2, sbox); + n2 ^= gost_val (key[5], n1, sbox); n1 ^= gost_val (key[4], n2, sbox); + n2 ^= gost_val (key[3], n1, sbox); n1 ^= gost_val (key[2], n2, sbox); + n2 ^= gost_val (key[1], n1, sbox); n1 ^= gost_val (key[0], n2, sbox); *o1 = n2; *o2 = n1; @@ -114,7 +112,7 @@ gost_encrypt_block (void *c, byte *outbuf, const byte *inbuf) n1 = buf_get_le32 (inbuf); n2 = buf_get_le32 (inbuf+4); - burn = _gost_encrypt_data(ctx, &n1, &n2, n1, n2); + burn = _gost_encrypt_data(ctx->sbox, ctx->key, &n1, &n2, n1, n2); buf_put_le32 (outbuf+0, n1); buf_put_le32 (outbuf+4, n2); @@ -125,12 +123,12 @@ gost_encrypt_block (void *c, byte *outbuf, const byte *inbuf) unsigned int _gcry_gost_enc_data (GOST28147_context *c, const u32 *key, u32 *o1, u32 *o2, u32 n1, u32 n2, int cryptopro) { + const u32 *sbox; if (cryptopro) - c->sbox = sbox_CryptoPro_3411; + sbox = sbox_CryptoPro_3411; else - c->sbox = sbox_test_3411; - memcpy (c->key, key, 8*4); - return _gost_encrypt_data (c, o1, o2, n1, n2) + 7 * sizeof(void *); + sbox = sbox_test_3411; + return _gost_encrypt_data (sbox, key, o1, o2, n1, n2) + 7 * sizeof(void *); } static unsigned int @@ -138,29 +136,30 @@ gost_decrypt_block (void *c, byte *outbuf, const byte *inbuf) { GOST28147_context *ctx = c; u32 n1, n2; + const u32 *sbox = ctx->sbox; n1 = buf_get_le32 (inbuf); n2 = buf_get_le32 (inbuf+4); - n2 ^= gost_val (ctx, n1, 0); n1 ^= gost_val (ctx, n2, 1); - n2 ^= gost_val (ctx, n1, 2); n1 ^= gost_val (ctx, n2, 3); - n2 ^= gost_val (ctx, n1, 4); n1 ^= gost_val (ctx, n2, 5); - n2 ^= gost_val (ctx, n1, 6); n1 ^= gost_val (ctx, n2, 7); - - n2 ^= gost_val (ctx, n1, 7); n1 ^= gost_val (ctx, n2, 6); - n2 ^= gost_val (ctx, n1, 5); n1 ^= gost_val (ctx, n2, 4); - n2 ^= gost_val (ctx, n1, 3); n1 ^= gost_val (ctx, n2, 2); - n2 ^= gost_val (ctx, n1, 1); n1 ^= gost_val (ctx, n2, 0); - - n2 ^= gost_val (ctx, n1, 7); n1 ^= gost_val (ctx, n2, 6); - n2 ^= gost_val (ctx, n1, 5); n1 ^= gost_val (ctx, n2, 4); - n2 ^= gost_val (ctx, n1, 3); n1 ^= gost_val (ctx, n2, 2); - n2 ^= gost_val (ctx, n1, 1); n1 ^= gost_val (ctx, n2, 0); - - n2 ^= gost_val (ctx, n1, 7); n1 ^= gost_val (ctx, n2, 6); - n2 ^= gost_val (ctx, n1, 5); n1 ^= gost_val (ctx, n2, 4); - n2 ^= gost_val (ctx, n1, 3); n1 ^= gost_val (ctx, n2, 2); - n2 ^= gost_val (ctx, n1, 1); n1 ^= gost_val (ctx, n2, 0); + n2 ^= gost_val (ctx->key[0], n1, sbox); n1 ^= gost_val (ctx->key[1], n2, sbox); + n2 ^= gost_val (ctx->key[2], n1, sbox); n1 ^= gost_val (ctx->key[3], n2, sbox); + n2 ^= gost_val (ctx->key[4], n1, sbox); n1 ^= gost_val (ctx->key[5], n2, sbox); + n2 ^= gost_val (ctx->key[6], n1, sbox); n1 ^= gost_val (ctx->key[7], n2, sbox); + + n2 ^= gost_val (ctx->key[7], n1, sbox); n1 ^= gost_val (ctx->key[6], n2, sbox); + n2 ^= gost_val (ctx->key[5], n1, sbox); n1 ^= gost_val (ctx->key[4], n2, sbox); + n2 ^= gost_val (ctx->key[3], n1, sbox); n1 ^= gost_val (ctx->key[2], n2, sbox); + n2 ^= gost_val (ctx->key[1], n1, sbox); n1 ^= gost_val (ctx->key[0], n2, sbox); + + n2 ^= gost_val (ctx->key[7], n1, sbox); n1 ^= gost_val (ctx->key[6], n2, sbox); + n2 ^= gost_val (ctx->key[5], n1, sbox); n1 ^= gost_val (ctx->key[4], n2, sbox); + n2 ^= gost_val (ctx->key[3], n1, sbox); n1 ^= gost_val (ctx->key[2], n2, sbox); + n2 ^= gost_val (ctx->key[1], n1, sbox); n1 ^= gost_val (ctx->key[0], n2, sbox); + + n2 ^= gost_val (ctx->key[7], n1, sbox); n1 ^= gost_val (ctx->key[6], n2, sbox); + n2 ^= gost_val (ctx->key[5], n1, sbox); n1 ^= gost_val (ctx->key[4], n2, sbox); + n2 ^= gost_val (ctx->key[3], n1, sbox); n1 ^= gost_val (ctx->key[2], n2, sbox); + n2 ^= gost_val (ctx->key[1], n1, sbox); n1 ^= gost_val (ctx->key[0], n2, sbox); buf_put_le32 (outbuf+0, n2); buf_put_le32 (outbuf+4, n1); -- 2.24.0 From dbaryshkov at gmail.com Tue Nov 12 14:50:05 2019 From: dbaryshkov at gmail.com (dbaryshkov at gmail.com) Date: Tue, 12 Nov 2019 16:50:05 +0300 Subject: [PATCH 4/4] gost28147: inline gost_val function to speed up code In-Reply-To: <20191112135005.7697-1-dbaryshkov@gmail.com> References: <20191112135005.7697-1-dbaryshkov@gmail.com> Message-ID: <20191112135005.7697-4-dbaryshkov@gmail.com> From: Dmitry Eremin-Solenikov * cipher/gost28147.c (gost_val): mark function as inline -- This improves the speed of the cipher Cipher: GOST28147 | nanosecs/byte mebibytes/sec cycles/byte Before: ECB enc | 18.89 ns/B 50.48 MiB/s - c/B ECB dec | 18.71 ns/B 50.96 MiB/s - c/B After: ECB enc | 17.83 ns/B 53.48 MiB/s - c/B ECB dec | 17.38 ns/B 54.89 MiB/s - c/B Signed-off-by: Dmitry Eremin-Solenikov --- cipher/gost28147.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cipher/gost28147.c b/cipher/gost28147.c index db7e9412c7cd..f30ca16a4d02 100644 --- a/cipher/gost28147.c +++ b/cipher/gost28147.c @@ -60,7 +60,7 @@ gost_setkey (void *c, const byte *key, unsigned keylen, return GPG_ERR_NO_ERROR; } -static u32 +static inline u32 gost_val (u32 subkey, u32 cm1, const u32 *sbox) { cm1 += subkey; -- 2.24.0 From wk at gnupg.org Tue Nov 12 16:17:54 2019 From: wk at gnupg.org (Werner Koch) Date: Tue, 12 Nov 2019 16:17:54 +0100 Subject: [PATCH 1/4] ecc: rename 512-bit GOST curves In-Reply-To: <20191112075819.11112-1-dbaryshkov@gmail.com> (Dmitry Eremin-Solenikov via Gcrypt-devel's message of "Tue, 12 Nov 2019 10:58:16 +0300") References: <20191112075819.11112-1-dbaryshkov@gmail.com> Message-ID: <87mud13yzh.fsf@wheatstone.g10code.de> On Tue, 12 Nov 2019 10:58, Dmitry Eremin-Solenikov said: > * cipher/ecc-curves.c (domain_parms): rename GOST 2012 curves to contain > curve bit size > (curve_aliases): rename curves and provide backwards-compatible > aliases. I can't immediately see that there are new aliases. > - { "GOST2012-tc26-A", "1.2.643.7.1.2.1.2.1" }, > - { "GOST2012-tc26-B", "1.2.643.7.1.2.1.2.2" }, These have been removed but we need to keep them - at least as an alias. Actually even turning the curves into an alias would be an ABI change; however we can accept that. > - "GOST2012-test", 511, 0, > + "GOST2012-512-test", 511, 0, Ditto. Can you please check again and if possible I would also appreciate a single patch for the new curve names. Shalom-Salam, Werner -- Die Gedanken sind frei. Ausnahmen regelt ein Bundesgesetz. -------------- next part -------------- A non-text attachment was scrubbed... Name: signature.asc Type: application/pgp-signature Size: 227 bytes Desc: not available URL: From dbaryshkov at gmail.com Tue Nov 12 16:35:12 2019 From: dbaryshkov at gmail.com (Dmitry Eremin-Solenikov) Date: Tue, 12 Nov 2019 18:35:12 +0300 Subject: [PATCH 1/4] ecc: rename 512-bit GOST curves In-Reply-To: <87mud13yzh.fsf@wheatstone.g10code.de> References: <20191112075819.11112-1-dbaryshkov@gmail.com> <87mud13yzh.fsf@wheatstone.g10code.de> Message-ID: ??, 12 ????. 2019 ?. ? 18:20, Werner Koch : > > On Tue, 12 Nov 2019 10:58, Dmitry Eremin-Solenikov said: > > > * cipher/ecc-curves.c (domain_parms): rename GOST 2012 curves to contain > > curve bit size > > (curve_aliases): rename curves and provide backwards-compatible > > aliases. > > I can't immediately see that there are new aliases. GOST2012-tc26-A is a current name, now provided in alias. GOST2012-512-tc26-A is a new curve name. > > > - { "GOST2012-tc26-A", "1.2.643.7.1.2.1.2.1" }, > > - { "GOST2012-tc26-B", "1.2.643.7.1.2.1.2.2" }, > > These have been removed but we need to keep them - at least as an alias. > Actually even turning the curves into an alias would be an ABI change; > however we can accept that. Hmm. I have added aliases both for OIDs and for old names. Could you please tell what did I miss? > > > - "GOST2012-test", 511, 0, > > + "GOST2012-512-test", 511, 0, > > Ditto. Ah, I missed this one. I'll add GOST2012-test alias to point to GOST2012-512-test. > > Can you please check again and if possible I would also appreciate a > single patch for the new curve names. Which patches would you like to be squashed? Or should I just update this patch? -- With best wishes Dmitry From wk at gnupg.org Tue Nov 12 17:48:44 2019 From: wk at gnupg.org (Werner Koch) Date: Tue, 12 Nov 2019 17:48:44 +0100 Subject: [PATCH 1/4] ecc: rename 512-bit GOST curves In-Reply-To: (Dmitry Eremin-Solenikov via Gcrypt-devel's message of "Tue, 12 Nov 2019 18:35:12 +0300") References: <20191112075819.11112-1-dbaryshkov@gmail.com> <87mud13yzh.fsf@wheatstone.g10code.de> Message-ID: <87a7913us3.fsf@wheatstone.g10code.de> On Tue, 12 Nov 2019 18:35, Dmitry Eremin-Solenikov said: > GOST2012-tc26-A is a current name, now provided in alias. > GOST2012-512-tc26-A is a new curve name. Okay, I missed that. >> > - "GOST2012-test", 511, 0, >> > + "GOST2012-512-test", 511, 0, >> >> Ditto. > > Ah, I missed this one. I'll add GOST2012-test alias to point to > GOST2012-512-test. Good. > Which patches would you like to be squashed? Or should I just update this patch? I think squasing all 4 would bea easiest. Salam-Shalom, Werner -- Die Gedanken sind frei. Ausnahmen regelt ein Bundesgesetz. -------------- next part -------------- A non-text attachment was scrubbed... Name: signature.asc Type: application/pgp-signature Size: 227 bytes Desc: not available URL: From dbaryshkov at gmail.com Tue Nov 12 20:40:34 2019 From: dbaryshkov at gmail.com (dbaryshkov at gmail.com) Date: Tue, 12 Nov 2019 22:40:34 +0300 Subject: [PATCH] ecc: update GOST2012 curves Message-ID: <20191112194034.17221-1-dbaryshkov@gmail.com> From: Paul Wolneykien * cipher/ecc-curves.c (domain_parms): rename GOST 2012 curves to contain curve bit size (curve_aliases): rename curves, provide backwards-compatible aliases, add new OIDs and two new curves. * cipher/ecc-curves.c (curve_aliases): add new OIDs and aliases for * tests/basic.c (check_pubkey): use new name for GOST2012 512-bit test curve. * tests/benchmark.c (ecc_bench): use new name for GOST2012 512-bit test curve. -- Rename old GOST2012 curves to specifically mention that they are 512-bit curves, add new OIDs for old curves and add two new curves. Signed-off-by: Paul Wolneykien Signed-off-by: Dmitry Eremin-Solenikov --- cipher/ecc-curves.c | 51 ++++++++++++++++++++++++++++++++++++++++----- tests/basic.c | 4 ++-- tests/benchmark.c | 2 +- 3 files changed, 49 insertions(+), 8 deletions(-) diff --git a/cipher/ecc-curves.c b/cipher/ecc-curves.c index 581ba4d66e54..52872c5ec473 100644 --- a/cipher/ecc-curves.c +++ b/cipher/ecc-curves.c @@ -97,8 +97,21 @@ static const struct { "GOST2001-CryptoPro-A", "1.2.643.2.2.36.0" }, { "GOST2001-CryptoPro-C", "1.2.643.2.2.36.1" }, - { "GOST2012-tc26-A", "1.2.643.7.1.2.1.2.1" }, - { "GOST2012-tc26-B", "1.2.643.7.1.2.1.2.2" }, + { "GOST2012-256-tc26-A", "1.2.643.7.1.2.1.1.1" }, + { "GOST2001-CryptoPro-A", "1.2.643.7.1.2.1.1.2" }, + { "GOST2001-CryptoPro-A", "GOST2012-256-tc26-B" }, + { "GOST2001-CryptoPro-B", "1.2.643.7.1.2.1.1.3" }, + { "GOST2001-CryptoPro-B", "GOST2012-256-tc26-C" }, + { "GOST2001-CryptoPro-C", "1.2.643.7.1.2.1.1.4" }, + { "GOST2001-CryptoPro-C", "GOST2012-256-tc26-D" }, + + { "GOST2012-512-test", "GOST2012-test" }, + { "GOST2012-512-test", "1.2.643.7.1.2.1.2.0" }, + { "GOST2012-512-tc26-A", "GOST2012-tc26-A" }, + { "GOST2012-512-tc26-B", "GOST2012-tc26-B" }, + { "GOST2012-512-tc26-A", "1.2.643.7.1.2.1.2.1" }, + { "GOST2012-512-tc26-B", "1.2.643.7.1.2.1.2.2" }, + { "GOST2012-512-tc26-C", "1.2.643.7.1.2.1.2.3" }, { "secp256k1", "1.3.132.0.10" }, @@ -408,7 +421,18 @@ static const ecc_domain_parms_t domain_parms[] = 1 }, { - "GOST2012-test", 511, 0, + "GOST2012-256-A", 256, 0, + MPI_EC_WEIERSTRASS, ECC_DIALECT_STANDARD, + "0xfffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffd97", + "0xc2173f1513981673af4892c23035a27ce25e2013bf95aa33b22c656f277e7335", + "0x295f9bae7428ed9ccc20e7c359a9d41a22fccd9108e17bf7ba9337a6f8ae9513", + "0x400000000000000000000000000000000fd8cddfc87b6635c115af556c360c67", + "0x91e38443a5e82c0d880923425712b2bb658b9196932e02c78b2582fe742daa28", + "0x32879423ab1a0375895786c4bb46e9565fde0b5344766740af268adb32322e5c", + 4 + }, + { + "GOST2012-512-test", 511, 0, MPI_EC_WEIERSTRASS, ECC_DIALECT_STANDARD, "0x4531acd1fe0023c7550d267b6b2fee80922b14b2ffb90f04d4eb7c09b5d2d15d" "f1d852741af4704a0458047e80e4546d35b8336fac224dd81664bbf528be6373", @@ -425,7 +449,7 @@ static const ecc_domain_parms_t domain_parms[] = 1 }, { - "GOST2012-tc26-A", 512, 0, + "GOST2012-512-tc26-A", 512, 0, MPI_EC_WEIERSTRASS, ECC_DIALECT_STANDARD, "0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff" "fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffdc7", @@ -442,7 +466,7 @@ static const ecc_domain_parms_t domain_parms[] = 1 }, { - "GOST2012-tc26-B", 512, 0, + "GOST2012-512-tc26-B", 512, 0, MPI_EC_WEIERSTRASS, ECC_DIALECT_STANDARD, "0x8000000000000000000000000000000000000000000000000000000000000000" "000000000000000000000000000000000000000000000000000000000000006f", @@ -458,6 +482,23 @@ static const ecc_domain_parms_t domain_parms[] = "dcb228fd1edf4a39152cbcaaf8c0398828041055f94ceeec7e21340780fe41bd", 1 }, + { + "GOST2012-512-tc26-C", 512, 0, + MPI_EC_WEIERSTRASS, ECC_DIALECT_STANDARD, + "0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff" + "fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffdc7", + "0xdc9203e514a721875485a529d2c722fb187bc8980eb866644de41c68e1430645" + "46e861c0e2c9edd92ade71f46fcf50ff2ad97f951fda9f2a2eb6546f39689bd3", + "0xb4c4ee28cebc6c2c8ac12952cf37f16ac7efb6a9f69f4b57ffda2e4f0de5ade0" + "38cbc2fff719d2c18de0284b8bfef3b52b8cc7a5f5bf0a3c8d2319a5312557e1", + "0x3fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff" + "c98cdba46506ab004c33a9ff5147502cc8eda9e7a769a12694623cef47f023ed", + "0xe2e31edfc23de7bdebe241ce593ef5de2295b7a9cbaef021d385f7074cea043a" + "a27272a7ae602bf2a7b9033db9ed3610c6fb85487eae97aac5bc7928c1950148", + "0xf5ce40d95b5eb899abbccff5911cb8577939804d6527378b8c108c3d2090ff9be" + "18e2d33e3021ed2ef32d85822423b6304f726aa854bae07d0396e9a9addc40f", + 4 + }, { "secp256k1", 256, 0, diff --git a/tests/basic.c b/tests/basic.c index b798eaafa21c..8337bcfb7ba0 100644 --- a/tests/basic.c +++ b/tests/basic.c @@ -13227,7 +13227,7 @@ check_pubkey (void) { "(private-key\n" " (ecc\n" - " (curve GOST2012-test)\n" + " (curve GOST2012-512-test)\n" " (q #04115DC5BC96760C7B48598D8AB9E740D4C4A85A65BE33C1" " 815B5C320C854621DD5A515856D13314AF69BC5B924C8B" " 4DDFF75C45415C1D9DD9DD33612CD530EFE137C7C90CD4" @@ -13240,7 +13240,7 @@ check_pubkey (void) "(public-key\n" " (ecc\n" - " (curve GOST2012-test)\n" + " (curve GOST2012-512-test)\n" " (q #04115DC5BC96760C7B48598D8AB9E740D4C4A85A65BE33C1" " 815B5C320C854621DD5A515856D13314AF69BC5B924C8B" " 4DDFF75C45415C1D9DD9DD33612CD530EFE137C7C90CD4" diff --git a/tests/benchmark.c b/tests/benchmark.c index 0f15c0d89fe7..a245152c0228 100644 --- a/tests/benchmark.c +++ b/tests/benchmark.c @@ -1528,7 +1528,7 @@ ecc_bench (int iterations, int print_header) else if (is_gost) err = gcry_sexp_build (&key_spec, NULL, "(genkey (ecdsa (curve %s)))", - p_size == 256 ? "GOST2001-test" : "GOST2012-test"); + p_size == 256 ? "GOST2001-test" : "GOST2012-512-test"); else err = gcry_sexp_build (&key_spec, NULL, "(genkey (ECDSA (nbits %d)))", p_size); -- 2.24.0 From wk at gnupg.org Mon Nov 18 21:42:59 2019 From: wk at gnupg.org (Werner Koch) Date: Mon, 18 Nov 2019 21:42:59 +0100 Subject: [PATCH] ecc: update GOST2012 curves In-Reply-To: <20191112194034.17221-1-dbaryshkov@gmail.com> (Dmitry Eremin-Solenikov via Gcrypt-devel's message of "Tue, 12 Nov 2019 22:40:34 +0300") References: <20191112194034.17221-1-dbaryshkov@gmail.com> Message-ID: <87eey4j4q4.fsf@wheatstone.g10code.de> Hi! Thanks for the patch. I just applied it. Shalom-Salam, Werner -- Die Gedanken sind frei. Ausnahmen regelt ein Bundesgesetz. -------------- next part -------------- A non-text attachment was scrubbed... Name: signature.asc Type: application/pgp-signature Size: 227 bytes Desc: not available URL: From manowar at altlinux.org Tue Nov 19 18:44:59 2019 From: manowar at altlinux.org (Paul Wolneykien) Date: Tue, 19 Nov 2019 20:44:59 +0300 Subject: Paul Wolneykien's DCO Message-ID: <20191119204459.312927aa@rigel.localdomain> Libgcrypt Developer's Certificate of Origin. Version 1.0 ========================================================= By making a contribution to the Libgcrypt project, I certify that: (a) The contribution was created in whole or in part by me and I have the right to submit it under the free software license indicated in the file; or (b) The contribution is based upon previous work that, to the best of my knowledge, is covered under an appropriate free software license and I have the right under that license to submit that work with modifications, whether created in whole or in part by me, under the same free software license (unless I am permitted to submit under a different license), as indicated in the file; or (c) The contribution was provided directly to me by some other person who certified (a), (b) or (c) and I have not modified it. (d) I understand and agree that this project and the contribution are public and that a record of the contribution (including all personal information I submit with it, including my sign-off) is maintained indefinitely and may be redistributed consistent with this project or the free software license(s) involved. Signed-off-by: Paul Wolneykien -------------- next part -------------- A non-text attachment was scrubbed... Name: not available Type: application/pgp-signature Size: 862 bytes Desc: ???????????????? ?????????????? OpenPGP URL: From wk at gnupg.org Wed Nov 20 09:26:28 2019 From: wk at gnupg.org (Werner Koch) Date: Wed, 20 Nov 2019 09:26:28 +0100 Subject: Paul Wolneykien's DCO In-Reply-To: <20191119204459.312927aa@rigel.localdomain> (Paul Wolneykien's message of "Tue, 19 Nov 2019 20:44:59 +0300") References: <20191119204459.312927aa@rigel.localdomain> Message-ID: <87wobveyx7.fsf@wheatstone.g10code.de> On Tue, 19 Nov 2019 20:44, Paul Wolneykien said: > Libgcrypt Developer's Certificate of Origin. Version 1.0 > ========================================================= Thanks. Salam-Shalom, Werner -- Die Gedanken sind frei. Ausnahmen regelt ein Bundesgesetz. -------------- next part -------------- A non-text attachment was scrubbed... Name: signature.asc Type: application/pgp-signature Size: 227 bytes Desc: not available URL: From dbaryshkov at gmail.com Wed Nov 20 10:16:30 2019 From: dbaryshkov at gmail.com (Dmitry Eremin-Solenikov) Date: Wed, 20 Nov 2019 12:16:30 +0300 Subject: [PATCH] ecc: update GOST2012 curves In-Reply-To: <87eey4j4q4.fsf@wheatstone.g10code.de> References: <20191112194034.17221-1-dbaryshkov@gmail.com> <87eey4j4q4.fsf@wheatstone.g10code.de> Message-ID: Hi! ??, 18 ????. 2019 ?. ? 23:45, Werner Koch : > Thanks for the patch. I just applied it. Thanks! -- With best wishes Dmitry From dbaryshkov at gmail.com Wed Nov 20 10:18:45 2019 From: dbaryshkov at gmail.com (Dmitry Eremin-Solenikov) Date: Wed, 20 Nov 2019 12:18:45 +0300 Subject: [PATCH 1/4] gostr3411-94: small speedup In-Reply-To: <20191112135005.7697-1-dbaryshkov@gmail.com> References: <20191112135005.7697-1-dbaryshkov@gmail.com> Message-ID: Hello, ??, 12 ????. 2019 ?. ? 16:50, : > > From: Dmitry Eremin-Solenikov > > * cipher/gostr3411-94.c (do_p): unroll loop for a small spedup What about these patches? They bring in small speedups and also serve as a foundation for next few patches adding counter and MAC modes (rfc 5830), key meshing (rfc 4357) and Magma cipher (draft-dolmatov-magma). -- With best wishes Dmitry From jussi.kivilinna at iki.fi Thu Nov 21 17:44:26 2019 From: jussi.kivilinna at iki.fi (Jussi Kivilinna) Date: Thu, 21 Nov 2019 18:44:26 +0200 Subject: [PATCH 1/4] gostr3411-94: small speedup In-Reply-To: References: <20191112135005.7697-1-dbaryshkov@gmail.com> Message-ID: <8af53432-f500-e8cb-db5f-2de8e07d52fc@iki.fi> Hello, On 20.11.2019 11.18, Dmitry Eremin-Solenikov via Gcrypt-devel wrote: > Hello, > > ??, 12 ????. 2019 ?. ? 16:50, : >> >> From: Dmitry Eremin-Solenikov >> >> * cipher/gostr3411-94.c (do_p): unroll loop for a small spedup > > What about these patches? They bring in small speedups and also serve > as a foundation for next few patches adding counter and MAC modes (rfc > 5830), key meshing (rfc 4357) and Magma cipher (draft-dolmatov-magma). > Patches tested and applied. Thanks. -Jussi