summaryrefslogtreecommitdiff
Commit message (Collapse)AuthorAgeFilesLines
* Check if assembler is compatible with AMD64 assembly implementationscipher-amd64-optimizationsJussi Kivilinna2013-06-2015-16/+50
| | | | | | | | | | | | | | | | | | | | | | | | | | | | * cipher/blowfish-amd64.S: Enable only if HAVE_COMPATIBLE_GCC_AMD64_PLATFORM_AS is defined. * cipher/camellia-aesni-avx-amd64.S: Ditto. * cipher/camellia-aesni-avx2-amd64.S: Ditto. * cipher/cast5-amd64.S: Ditto. * cipher/rinjdael-amd64.S: Ditto. * cipher/serpent-avx2-amd64.S: Ditto. * cipher/serpent-sse2-amd64.S: Ditto. * cipher/twofish-amd64.S: Ditto. * cipher/blowfish.c: Use AMD64 assembly implementation only if HAVE_COMPATIBLE_GCC_AMD64_PLATFORM_AS is defined * cipher/camellia-glue.c: Ditto. * cipher/cast5.c: Ditto. * cipher/rijndael.c: Ditto. * cipher/serpent.c: Ditto. * cipher/twofish.c: Ditto. * configure.ac: Check gcc/as compatibility with AMD64 assembly implementations. -- Later these checks can be split and assembly implementations adapted to handle different platforms, but for now disable AMD64 assembly implementations if assembler does not look to be able to handle them. Signed-off-by: Jussi Kivilinna <jussi.kivilinna@iki.fi>
* Optimize _gcry_burn_stack for 32-bit and 64-bit architecturesJussi Kivilinna2013-06-091-0/+26
| | | | | | | | | | | | | | | * src/misc.c (_gcry_burn_stack): Add optimization for 32-bit and 64-bit architectures. -- Busy looping 'tests/benchmark --cipher-repetitions 10 cipher blowfish' on ARM Cortex-A8 shows that _gcry_burn_stack takes 21% of CPU time. With this patch, that number drops to 3.4%. On AMD64 (Intel i5-4570) CPU usage for _gcry_burn_stack in the same test drops from 3.5% to 1.1%. Signed-off-by: Jussi Kivilinna <jussi.kivilinna@iki.fi>
* Add Camellia AES-NI/AVX2 implementationJussi Kivilinna2013-06-094-4/+1395
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | * cipher/Makefile.am: Add 'camellia-aesni-avx2-amd64.S'. * cipher/camellia-aesni-avx2-amd64.S: New file. * cipher/camellia-glue.c (USE_AESNI_AVX2): New macro. (CAMELLIA_context) [USE_AESNI_AVX2]: Add 'use_aesni_avx2'. [USE_AESNI_AVX2] (_gcry_camellia_aesni_avx2_ctr_enc) (_gcry_camellia_aesni_avx2_cbc_dec) (_gcry_camellia_aesni_avx2_cfb_dec): New prototypes. (camellia_setkey) [USE_AESNI_AVX2]: Check AVX2+AES-NI capable hardware and set 'ctx->use_aesni_avx2'. (_gcry_camellia_ctr_enc) [USE_AESNI_AVX2]: Add AVX2 accelerated code. (_gcry_camellia_cbc_dec) [USE_AESNI_AVX2]: Add AVX2 accelerated code. (_gcry_camellia_cfb_dec) [USE_AESNI_AVX2]: Add AVX2 accelerated code. (selftest_ctr_128, selftest_cbc_128, selftest_cfb_128): Grow 'nblocks' so that AVX2 codepaths get tested. * configure.ac (camellia) [avx2support, aesnisupport]: Add 'camellia-aesni-avx2-amd64.lo'. -- Add new AVX2/AES-NI implementation of Camellia that processes 32 blocks in parallel. Speed old (AVX/AES-NI) vs. new (AVX2/AES-NI) on Intel Core i5-4570: ECB/Stream CBC CFB OFB CTR --------------- --------------- --------------- --------------- --------------- CAMELLIA128 1.00x 0.99x 1.00x 1.53x 1.00x 1.49x 1.00x 1.00x 1.54x 1.54x CAMELLIA256 0.99x 1.00x 1.00x 1.50x 1.00x 1.50x 1.00x 1.00x 1.54x 1.52x Signed-off-by: Jussi Kivilinna <jussi.kivilinna@iki.fi>
* Add Serpent AVX2 implementationJussi Kivilinna2013-06-094-4/+1028
| | | | | | | | | | | | | | | | | | | | | | | | | | | * cipher/Makefile.am: Add 'serpent-avx2-amd64.S'. * cipher/serpent-avx2-amd64.S: New file. * cipher/serpent.c (USE_AVX2): New macro. (serpent_context_t) [USE_AVX2]: Add 'use_avx2'. [USE_AVX2] (_gcry_serpent_avx2_ctr_enc, _gcry_serpent_avx2_cbc_dec) (_gcry_serpent_avx2_cfb_dec): New prototypes. (serpent_setkey_internal) [USE_AVX2]: Check for AVX2 capable hardware and set 'use_avx2'. (_gcry_serpent_ctr_enc) [USE_AVX2]: Use AVX2 accelerated functions. (_gcry_serpent_cbc_dec) [USE_AVX2]: Use AVX2 accelerated functions. (_gcry_serpent_cfb_dec) [USE_AVX2]: Use AVX2 accelerated functions. (selftest_ctr_128, selftest_cbc_128, selftest_cfb_128): Grow 'nblocks' so that AVX2 codepaths are tested. * configure.ac (serpent) [avx2support]: Add 'serpent-avx2-amd64.lo'. -- Add new AVX2 implementation of Serpent that processes 16 blocks in parallel. Speed old (SSE2) vs. new (AVX2) on Intel Core i5-4570: ECB/Stream CBC CFB OFB CTR --------------- --------------- --------------- --------------- --------------- SERPENT128 1.00x 1.00x 1.00x 2.10x 1.00x 2.16x 1.01x 1.00x 2.16x 2.18x Signed-off-by: Jussi Kivilinna <jussi.kivilinna@iki.fi>
* Add detection for Intel AVX2 instruction setJussi Kivilinna2013-06-094-3/+58
| | | | | | | | | | | | | | | | * configure.ac: Add option --disable-avx2-support. (HAVE_GCC_INLINE_ASM_AVX2): New. (ENABLE_AVX2_SUPPORT): New. * src/g10lib.h (HWF_INTEL_AVX2): New. * src/global.c (hwflist): Add HWF_INTEL_AVX2. * src/hwf-x86.c [__i386__] (get_cpuid): Initialize registers to zero before cpuid. [__x86_64__] (get_cpuid): Initialize registers to zero before cpuid. (detect_x86_gnuc): Store maximum cpuid level. (detect_x86_gnuc) [ENABLE_AVX2_SUPPORT]: Add detection for AVX2. -- Signed-off-by: Jussi Kivilinna <jussi.kivilinna@iki.fi>
* twofish: add amd64 assembly implementationJussi Kivilinna2013-06-096-1/+1036
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | * cipher/Makefile.am: Add 'twofish-amd64.S'. * cipher/twofish-amd64.S: New file. * cipher/twofish.c (USE_AMD64_ASM): New macro. [USE_AMD64_ASM] (_gcry_twofish_amd64_encrypt_block) (_gcry_twofish_amd64_decrypt_block, _gcry_twofish_amd64_ctr_enc) (_gcry_twofish_amd64_cbc_dec, _gcry_twofish_amd64_cfb_dec): New prototypes. [USE_AMD64_ASM] (do_twofish_encrypt, do_twofish_decrypt) (twofish_encrypt, twofish_decrypt): New functions. (_gcry_twofish_ctr_enc, _gcry_twofish_cbc_dec, _gcry_twofish_cfb_dec) (selftest_ctr, selftest_cbc, selftest_cfb): New functions. (selftest): Call new bulk selftests. * cipher/cipher.c (gcry_cipher_open) [USE_TWOFISH]: Register Twofish bulk functions for ctr-enc, cbc-dec and cfb-dec. * configure.ac (twofish) [x86_64]: Add 'twofish-amd64.lo'. * src/cipher.h (_gcry_twofish_ctr_enc, _gcry_twofish_cbc_dec) (gcry_twofish_cfb_dec): New prototypes. -- Provides non-parallel implementations for small speed-up and 3-way parallel implementations that gets accelerated on `out-of-order' CPUs. Speed old vs. new on Intel Core i5-4570: ECB/Stream CBC CFB OFB CTR --------------- --------------- --------------- --------------- --------------- TWOFISH128 1.08x 1.07x 1.10x 1.80x 1.09x 1.70x 1.08x 1.08x 1.70x 1.69x Speed old vs. new on Intel Core2 T8100: ECB/Stream CBC CFB OFB CTR --------------- --------------- --------------- --------------- --------------- TWOFISH128 1.11x 1.10x 1.13x 1.65x 1.13x 1.62x 1.12x 1.11x 1.63x 1.59x Signed-off-by: Jussi Kivilinna <jussi.kivilinna@iki.fi>
* rinjdael: add amd64 assembly implementationJussi Kivilinna2013-05-294-1/+1456
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | * cipher/Makefile.am: Add 'rijndael-amd64.S'. * cipher/rijndael-amd64.S: New file. * cipher/rijndael.c (USE_AMD64_ASM): New macro. [USE_AMD64_ASM] (_gcry_aes_amd64_encrypt_block) (_gcry_aes_amd64_decrypt_block): New prototypes. (do_encrypt_aligned) [USE_AMD64_ASM]: Use amd64 assembly function. (do_encrypt): Disable input/output alignment when USE_AMD64_ASM is set. (do_decrypt_aligned) [USE_AMD64_ASM]: Use amd64 assembly function. (do_decrypt): Disable input/output alignment when USE_AMD64_AES is set. * configure.ac (aes) [x86-64]: Add 'rijndael-amd64.lo'. -- Add optimized amd64 assembly implementation for AES. Old vs new, on AMD Phenom II: ECB/Stream CBC CFB OFB CTR --------------- --------------- --------------- --------------- --------------- AES 1.74x 1.72x 1.81x 1.85x 1.82x 1.76x 1.67x 1.64x 1.79x 1.81x AES192 1.77x 1.77x 1.79x 1.88x 1.90x 1.80x 1.69x 1.69x 1.85x 1.81x AES256 1.79x 1.81x 1.83x 1.89x 1.88x 1.82x 1.72x 1.70x 1.87x 1.89x Old vs new, on Intel Core2: ECB/Stream CBC CFB OFB CTR --------------- --------------- --------------- --------------- --------------- AES 1.77x 1.75x 1.78x 1.76x 1.76x 1.77x 1.75x 1.76x 1.76x 1.82x AES192 1.80x 1.73x 1.81x 1.76x 1.79x 1.85x 1.77x 1.76x 1.80x 1.85x AES256 1.81x 1.77x 1.81x 1.77x 1.80x 1.79x 1.78x 1.77x 1.81x 1.85x Signed-off-by: Jussi Kivilinna <jussi.kivilinna@iki.fi>
* blowfish: add amd64 assembly implementationJussi Kivilinna2013-05-296-1/+832
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | * cipher/Makefile.am: Add 'blowfish-amd64.S'. * cipher/blowfish-amd64.S: New file. * cipher/blowfish.c (USE_AMD64_ASM): New macro. [USE_AMD64_ASM] (_gcry_blowfish_amd64_do_encrypt) (_gcry_blowfish_amd64_encrypt_block) (_gcry_blowfish_amd64_decrypt_block, _gcry_blowfish_amd64_ctr_enc) (_gcry_blowfish_amd64_cbc_dec, _gcry_blowfish_amd64_cfb_dec): New prototypes. [USE_AMD64_ASM] (do_encrypt, do_encrypt_block, do_decrypt_block) (encrypt_block, decrypt_block): New functions. (_gcry_blowfish_ctr_enc, _gcry_blowfish_cbc_dec) (_gcry_blowfish_cfb_dec, selftest_ctr, selftest_cbc, selftest_cfb): New functions. (selftest): Call new bulk selftests. * cipher/cipher.c (gcry_cipher_open) [USE_BLOWFISH]: Register Blowfish bulk functions for ctr-enc, cbc-dec and cfb-dec. * configure.ac (blowfish) [x86_64]: Add 'blowfish-amd64.lo'. * src/cipher.h (_gcry_blowfish_ctr_enc, _gcry_blowfish_cbc_dec) (gcry_blowfish_cfb_dec): New prototypes. -- Add non-parallel functions for small speed-up and 4-way parallel functions for modes of operation that support parallel processing. Speed old vs. new on AMD Phenom II X6 1055T: ECB/Stream CBC CFB OFB CTR --------------- --------------- --------------- --------------- --------------- BLOWFISH 1.21x 1.12x 1.17x 3.52x 1.18x 3.34x 1.16x 1.15x 3.38x 3.47x Speed old vs. new on Intel Core i5-2450M (Sandy-Bridge): ECB/Stream CBC CFB OFB CTR --------------- --------------- --------------- --------------- --------------- BLOWFISH 1.16x 1.10x 1.17x 2.98x 1.18x 2.88x 1.16x 1.15x 3.00x 3.02x Signed-off-by: Jussi Kivilinna <jussi.kivilinna@iki.fi>
* ecc: Simplify the compliant point generation.Werner Koch2013-05-241-28/+17
| | | | | | | * cipher/ecc.c (generate_key): Use point_snatch_set, replaces unneeded variable copies, etc. Signed-off-by: Werner Koch <wk@gnupg.org>
* ecc: Fix a minor flaw in the generation of K.Werner Koch2013-05-245-104/+117
| | | | | | | | | | | | | | | | * cipher/dsa.c (gen_k): Factor code out to .. * cipher/dsa-common.c (_gcry_dsa_gen_k): new file and function. Add arg security_level and re-indent a bit. * cipher/ecc.c (gen_k): Remove and change callers to _gcry_dsa_gen_k. * cipher/dsa.c: Include pubkey-internal. * cipher/Makefile.am (libcipher_la_SOURCES): Add dsa-common.c -- The ECDSA code used the simple $k = k \bmod p$ method which introduces a small bias. We now use the bias free method we have always used with DSA. Signed-off-by: Werner Koch <wk@gnupg.org>
* cast5: add amd64 assembly implementationJussi Kivilinna2013-05-246-9/+885
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | * cipher/Makefile.am: Add 'cast5-amd64.S'. * cipher/cast5-amd64.S: New file. * cipher/cast5.c (USE_AMD64_ASM): New macro. (_gcry_cast5_s1tos4): Merge arrays s1, s2, s3, s4 to single array to simplify access from assembly implementation. (s1, s2, s3, s4): New macros pointing to subarrays in _gcry_cast5_s1tos4. [USE_AMD64_ASM] (_gcry_cast5_amd64_encrypt_block) (_gcry_cast5_amd64_decrypt_block, _gcry_cast5_amd64_ctr_enc) (_gcry_cast5_amd64_cbc_dec, _gcry_cast5_amd64_cfb_dec): New prototypes. [USE_AMD64_ASM] (do_encrypt_block, do_decrypt_block, encrypt_block) (decrypt_block): New functions. (_gcry_cast5_ctr_enc, _gcry_cast5_cbc_dec, _gcry_cast5_cfb_dec) (selftest_ctr, selftest_cbc, selftest_cfb): New functions. (selftest): Call new bulk selftests. * cipher/cipher.c (gcry_cipher_open) [USE_CAST5]: Register CAST5 bulk functions for ctr-enc, cbc-dec and cfb-dec. * configure.ac (cast5) [x86_64]: Add 'cast5-amd64.lo'. * src/cipher.h (_gcry_cast5_ctr_enc, _gcry_cast5_cbc_dec) (gcry_cast5_cfb_dec): New prototypes. -- Provides non-parallel implementations for small speed-up and 4-way parallel implementations that gets accelerated on `out-of-order' CPUs. Speed old vs. new on AMD Phenom II X6 1055T: ECB/Stream CBC CFB OFB CTR --------------- --------------- --------------- --------------- --------------- CAST5 1.23x 1.22x 1.21x 2.86x 1.21x 2.83x 1.22x 1.17x 2.73x 2.73x Speed old vs. new on Intel Core i5-2450M (Sandy-Bridge): ECB/Stream CBC CFB OFB CTR --------------- --------------- --------------- --------------- --------------- CAST5 1.00x 1.04x 1.06x 2.56x 1.06x 2.37x 1.03x 1.01x 2.43x 2.41x Signed-off-by: Jussi Kivilinna <jussi.kivilinna@iki.fi>
* cipher-selftest: make selftest work with any block-sizeJussi Kivilinna2013-05-245-79/+85
| | | | | | | | | | | | | | | | | | | | * cipher/cipher-selftest.c (_gcry_selftest_helper_cbc_128) (_gcry_selftest_helper_cfb_128, _gcry_selftest_helper_ctr_128): Renamed functions from '<name>_128' to '<name>'. (_gcry_selftest_helper_cbc, _gcry_selftest_helper_cfb) (_gcry_selftest_helper_ctr): Make work with different block sizes. * cipher/cipher-selftest.h (_gcry_selftest_helper_cbc_128) (_gcry_selftest_helper_cfb_128, _gcry_selftest_helper_ctr_128): Renamed prototypes from '<name>_128' to '<name>'. * cipher/camellia-glue.c (selftest_ctr_128, selftest_cfb_128) (selftest_ctr_128): Change to use new function names. * cipher/rijndael.c (selftest_ctr_128, selftest_cfb_128) (selftest_ctr_128): Change to use new function names. * cipher/serpent.c (selftest_ctr_128, selftest_cfb_128) (selftest_ctr_128): Change to use new function names. -- Signed-off-by: Jussi Kivilinna <jussi.kivilinna@iki.fi>
* serpent: add parallel processing for CFB decryptionJussi Kivilinna2013-05-234-0/+158
| | | | | | | | | | | | | | | | | | * cipher/cipher.c (gcry_cipher_open): Add bulf CFB decryption function for Serpent. * cipher/serpent-sse2-amd64.S (_gcry_serpent_sse2_cfb_dec): New function. * cipher/serpent.c (_gcry_serpent_sse2_cfb_dec): New prototype. (_gcry_serpent_cfb_dec) New function. (selftest_cfb_128) New function. (selftest) Call selftest_cfb_128. * src/cipher.h (_gcry_serpent_cfb_dec): New prototype. -- Patch makes Serpent-CFB decryption 4.0 times faster on Intel Sandy-Bridge and 2.7 times faster on AMD K10. Signed-off-by: Jussi Kivilinna <jussi.kivilinna@iki.fi>
* camellia: add parallel processing for CFB decryptionJussi Kivilinna2013-05-234-0/+143
| | | | | | | | | | | | | | | | | | * cipher/camellia-aesni-avx-amd64.S (_gcry_camellia_aesni_avx_cfb_dec): New function. * cipher/camellia-glue.c (_gcry_camellia_aesni_avx_cfb_dec): New prototype. (_gcry_camellia_cfb_dec): New function. (selftest_cfb_128): New function. (selftest): Call selftest_cfb_128. * cipher/cipher.c (gry_cipher_open): Add bulk CFB decryption function for Camellia. * src/cipher.h (_gcry_camellia_cfb_dec): New prototype. -- Patch makes Camellia-CFB decryption 4.7 times faster on Intel Sandy-Bridge. Signed-off-by: Jussi Kivilinna <jussi.kivilinna@iki.fi>
* rinjdael: add parallel processing for CFB decryption with AES-NIJussi Kivilinna2013-05-233-1/+299
| | | | | | | | | | | | | | | | | * cipher/cipher-selftest.c (_gcry_selftest_helper_cfb_128): New function for CFB selftests. * cipher/cipher-selftest.h (_gcry_selftest_helper_cfb_128): New prototype. * cipher/rijndael.c [USE_AESNI] (do_aesni_enc_vec4): New function. (_gcry_aes_cfb_dec) [USE_AESNI]: Add parallelized CFB decryption. (selftest_cfb_128): New function. (selftest): Call selftest_cfb_128. -- CFB decryption can be parallelized for additional performance. On Intel Sandy-Bridge processor, this change makes CFB decryption 4.6 times faster. Signed-off-by: Jussi Kivilinna <jussi.kivilinna@iki.fi>
* Avoid compiler warning due to the global symbol setkey.Werner Koch2013-05-231-4/+6
| | | | | | | | * cipher/cipher-selftest.c (_gcry_selftest_helper_cbc_128) (_gcry_selftest_helper_ctr_128): Rename setkey to setkey_func. -- setkey is a POSIX.1 function defined in stdlib.
* serpent: add SSE2 accelerated amd64 implementationJussi Kivilinna2013-05-236-3/+1066
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | * configure.ac (serpent): Add 'serpent-sse2-amd64.lo'. * cipher/Makefile.am (EXTRA_libcipher_la_SOURCES): Add 'serpent-sse2-amd64.S'. * cipher/cipher.c (gcry_cipher_open) [USE_SERPENT]: Register bulk functions for CBC-decryption and CTR-mode. * cipher/serpent.c (USE_SSE2): New macro. [USE_SSE2] (_gcry_serpent_sse2_ctr_enc, _gcry_serpent_sse2_cbc_dec): New prototypes to assembler functions. (serpent_setkey): Set 'serpent_init_done' before calling serpent_test. (_gcry_serpent_ctr_enc): New function. (_gcry_serpent_cbc_dec): New function. (selftest_ctr_128): New function. (selftest_cbc_128): New function. (selftest): Call selftest_ctr_128 and selftest_cbc_128. * cipher/serpent-sse2-amd64.S: New file. * src/cipher.h (_gcry_serpent_ctr_enc): New prototype. (_gcry_serpent_cbc_dec): New prototype. -- [v2]: Converted to SSE2, to support all amd64 processors (SSE2 is required feature by AMD64 SysV ABI). Patch adds word-sliced SSE2 implementation of Serpent for amd64 for speeding up parallelizable workloads (CTR mode, CBC mode decryption). Implementation processes eight blocks in parallel, with two four-block sets interleaved for out-of-order scheduling. Speed old vs. new on Intel Core i5-2450M (Sandy-Bridge): ECB/Stream CBC CFB OFB CTR --------------- --------------- --------------- --------------- --------------- SERPENT128 1.00x 0.99x 1.00x 3.98x 1.00x 1.01x 1.00x 1.01x 4.04x 4.04x Speed old vs. new on AMD Phenom II X6 1055T: ECB/Stream CBC CFB OFB CTR --------------- --------------- --------------- --------------- --------------- SERPENT128 1.02x 1.01x 1.00x 2.83x 1.00x 1.00x 1.00x 1.00x 2.72x 2.72x Speed old vs. new on Intel Core2 Duo T8100: ECB/Stream CBC CFB OFB CTR --------------- --------------- --------------- --------------- --------------- SERPENT128 1.00x 1.02x 0.97x 4.02x 0.98x 1.01x 0.98x 1.00x 3.82x 3.91x Signed-off-by: Jussi Kivilinna <jussi.kivilinna@iki.fi>
* Serpent: faster S-box implementationJussi Kivilinna2013-05-231-350/+250
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | * cipher/serpent.c (SBOX0, SBOX1, SBOX2, SBOX3, SBOX4, SBOX5, SBOX6) (SBOX7, SBOX0_INVERSE, SBOX1_INVERSE, SBOX2_INVERSE, SBOX3_INVERSE) (SBOX4_INVERSE, SBOX5_INVERSE, SBOX6_INVERSE, SBOX7_INVERSE): Replace with new definitions. -- These new S-box definitions are from 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. Available at http://www.ii.uib.no/~osvik/pub/aes3.ps.gz Although these were optimized for two-operand instructions on i386 and for old Pentium-1 processors, they are slightly faster on current processors on i386 and x86-64. On ARM, the performance of these S-boxes is about the same as with the old S-boxes. new vs old speed ratios (AMD K10, x86-64): ECB/Stream CBC CFB OFB CTR --------------- --------------- --------------- --------------- --------------- SERPENT128 1.06x 1.02x 1.06x 1.02x 1.06x 1.06x 1.06x 1.05x 1.07x 1.07x new vs old speed ratios (Intel Atom, i486): ECB/Stream CBC CFB OFB CTR --------------- --------------- --------------- --------------- --------------- SERPENT128 1.12x 1.15x 1.12x 1.15x 1.13x 1.11x 1.12x 1.12x 1.12x 1.13x new vs old speed ratios (ARM Cortex A8): ECB/Stream CBC CFB OFB CTR --------------- --------------- --------------- --------------- --------------- SERPENT128 1.04x 1.02x 1.02x 0.99x 1.02x 1.02x 1.03x 1.03x 1.01x 1.01x Signed-off-by: Jussi Kivilinna <jussi.kivilinna@iki.fi>
* w32: Fix installing of .def file.Werner Koch2013-05-221-0/+1
| | | | | | | * src/Makefile.am (install-def-file): Create libdir first. -- Reported-by: LRN <lrn1986@gmail.com>
* Register a DCO.Werner Koch2013-05-221-0/+3
| | | | --
* Add control commands to disable mlock and setuid dropping.Werner Koch2013-05-226-9/+59
| | | | | | | | | | | | | * src/gcrypt.h.in (GCRYCTL_DISABLE_LOCKED_SECMEM): New. (GCRYCTL_DISABLE_PRIV_DROP): New. * src/global.c (_gcry_vcontrol): Implement them. * src/secmem.h (GCRY_SECMEM_FLAG_NO_MLOCK): New. (GCRY_SECMEM_FLAG_NO_PRIV_DROP): New. * src/secmem.c (no_mlock, no_priv_drop): New. (_gcry_secmem_set_flags, _gcry_secmem_get_flags): Set and get them. (lock_pool): Handle no_mlock and no_priv_drop. Signed-off-by: Werner Koch <wk@gnupg.org>
* Fix libtool 2.4.2 to correctly detect .def files.Werner Koch2013-05-222-5/+9
| | | | | | | | | | | | | | | | | | | * ltmain.sh (sed_uncomment_deffile): New. (orig_export_symbols): Uncomment def file before testing for EXPORTS. * m4/libtool.m4: Do the same for the generated code. -- The old code was not correct in that it only looked at the first line and puts an EXPORTS keyword in front if missing. Binutils 2.22 accepted a duplicated EXPORTS keyword but at least 2.23.2 is more stringent and bails out without this fix. There is no need to send this upstream. Upstream's git master has a lot of changes including a similar fix for this problems. There are no signs that a libtool 2.4.3 will be released to fix this problem and thus we need to stick to our copy of 2.4.2 along with this patch. Signed-off-by: Werner Koch <wk@gnupg.org>
* Add AES bulk CBC decryption selftestJussi Kivilinna2013-05-221-0/+18
| | | | | | | | * cipher/rinjdael.c (selftest_cbc_128): New. (selftest): Call selftest_cbc_128. -- Signed-off-by: Jussi Kivilinna <jussi.kivilinna@iki.fi>
* Change AES bulk CTR encryption selftest use new selftest helper functionJussi Kivilinna2013-05-221-86/+7
| | | | | | | | * cipher/rinjdael.c: (selftest_ctr_128): Change to use new selftest helper function. -- Signed-off-by: Jussi Kivilinna <jussi.kivilinna@iki.fi>
* Convert bulk CTR and CBC selftest functions in Camellia to generic selftest ↵Jussi Kivilinna2013-05-224-157/+357
| | | | | | | | | | | | | | | | | helper functions * cipher/Makefile.am (libcipher_la_SOURCES): Add cipher-selftest files. * cipher/camellia-glue.c (selftest_ctr_128, selftest_cbc_128): Change to use the new selftest helper functions. * cipher/cipher-selftest.c: New. * cipher/cipher-selftest.h: New. -- Convert selftest functions into generic helper functions for code sharing. [v2]: use syslog for more detailed selftest error messages Signed-off-by: Jussi Kivilinna <jussi.kivilinna@iki.fi>
* camellia: add bulk CBC decryption selftestJussi Kivilinna2013-05-221-0/+83
| | | | | | | | | | | * cipher/camellia-glue.c: (selftest_cbc_128): New selftest function for bulk CBC decryption. (selftest): Add call to selftest_cbc_128. -- Add selftest for the parallel code paths in bulk CBC decryption. Signed-off-by: Jussi Kivilinna <jussi.kivilinna@iki.fi>
* camellia: Rename camellia_aesni_avx_x86-64.S to camellia-aesni-avx-amd64.SJussi Kivilinna2013-05-223-4/+4
| | | | | | | | | | * cipher/camellia_aesni_avx_x86-64.S: Remove. * cipher/camellia-aesni-avx-amd64.S: New. * cipher/Makefile.am: Use the new filename. * configure.ac: Use the new filename. -- Signed-off-by: Jussi Kivilinna <jussi.kivilinna@iki.fi>
* Fix indentation and save on string space.Werner Koch2013-05-212-33/+46
| | | | | * cipher/ecc.c (generate_key): Use the same string for both fatal messages.
* mpi_sub( r, a, b ) expects r to be initialized; other minor cleanup in ecc ↵Andrey2013-05-191-6/+10
| | | | | | generate_key compliant key generation. This fixes the 'make check' of libgcrypt.
* Generate ECC keys Q=(x,y) as compliant keys, enabling their compact ↵compliant-ecc-keygenAndrey2013-05-091-4/+49
| | | | | | | representation as simply x. See http://tools.ietf.org/html/draft-jivsov-ecc-compact for the method description and security proof. This tweak doesn't change any format; it is only a preparation without any negative impact for future changes.
* cipher: Fix regression in Padlock support.Werner Koch2013-04-182-7/+3
| | | | | | | | | | | | | | | | * cipher/rijndael.c (do_setkey): Remove dummy padlock key generation case and use the standard one. -- This is really a brown paper bag bug. I should have been able to fix it by a bit of code staring or bi-secting it myself. Instead Rafaël Carré did this and with the donation of a VIA nano board from Stefan Krüger. Thanks to both of you. (regression since commit b825c5db17292988d261fefdc83cbc43d97d4b02) Signed-off-by: Werner Koch <wk@gnupg.org> (cherry picked from commit f1f016855418aae561ede4472590d45a24ab4476)
* mpi: Yet another fix to get option flag munging right.Werner Koch2013-04-181-1/+1
| | | | * cipher/Makefile.am (o_flag_munging): Yet another fix.
* mpi: Make using gcc's -Ofast easier.Werner Koch2013-04-181-1/+1
| | | | | | | | * cipher/Makefile.am (o_flag_munging): Take -Ofast in account. -- GnuPG-bug-id: 1468 (cherry picked from commit d313255350e6f397500ce23714ddec8780f32449)
* Fix alignment problem in idea.c.Werner Koch2013-04-181-27/+27
| | | | | | | | | | | | | | | | | | | * cipher/idea.c (cipher): Rework parameter use to fix alignment problems. * cipher/idea.c (FNCCAST_SETKEY, FNCCAST_CRYPT): Remove unused macros. Signed-off-by: Werner Koch <wk@gnupg.org> Fix alignment problem in idea.c. * cipher/idea.c (cipher): Rework parameter use to fix alignment problems. * cipher/idea.c (FNCCAST_SETKEY, FNCCAST_CRYPT): Remove unused macros. Signed-off-by: Werner Koch <wk@gnupg.org> (cherry picked from 4cd279556777e02eda79973f68efaa4b741f9175)
* Add some const attributes.Vladimir Serbinenko2013-04-183-3/+6
| | | | | | | | | | | | * cipher/md4.c (transform): Add const attribute. * cipher/md5.c (transform): Ditto. * cipher/rmd160.c (transform): Ditto. -- This is the same as http://bzr.savannah.gnu.org/lh/grub/trunk/grub/revision/3685 Signed-off-by: Werner Koch <wk@gnupg.org>
* Fix alignment problem in serpent.c.Vladimir Serbinenko2013-04-182-56/+36
| | | | | | | | | | | | | | | | | | | | | | | * cipher/serpent.c (serpent_key_prepare): Fix misaligned access. (serpent_setkey): Likewise. (serpent_encrypt_internal): Likewise. (serpent_decrypt_internal): Likewise. (serpent_encrypt): Don't put an alignment-increasing cast. (serpent_decrypt): Likewise. (serpent_test): Likewise. -- This is a port of the fix for the Libgcrypt code in GRUB: http://bzr.savannah.gnu.org/lh/grub/trunk/grub/revision/3685 GRUB is FSF copyrighted and thus we can use this code without a DCO. Note that the above fix was not correct and failed the selftests, thus I fixed this fix. GnuPG-bug-id: 1384 Signed-off-by: Werner Koch <wk@gnupg.org> (cherry picked from commit 8eab66ad6852ec985bfb1e7fec35981d5e31148a)
* Fix multiply by zero in gcry_mpi_ec_mul.Werner Koch2013-04-162-5/+32
| | | | | | | * mpi/ec.c (_gcry_mpi_ec_mul_point): Handle case of SCALAR == 0. * tests/t-mpi-point.c (basic_ec_math): Add a test case for this. Signed-off-by: Werner Koch <wk@wheatstone.g10code.de>
* Add macros to return pre-defined MPIs.Werner Koch2013-04-157-1/+47
| | | | | | | | | | * src/gcrypt.h.in (GCRYMPI_CONST_ONE, GCRYMPI_CONST_TWO) (GCRYMPI_CONST_THREE, GCRYMPI_CONST_FOUR, GCRYMPI_CONST_EIGHT): New. (_gcry_mpi_get_const): New private function. * src/visibility.c (_gcry_mpi_get_const): New. * src/visibility.h: Mark it visible. Signed-off-by: Werner Koch <wk@gnupg.org>
* Fix addition of EC points.Werner Koch2013-04-151-1/+1
| | | | | | | | | | | * mpi/ec.c (_gcry_mpi_ec_add_points): Fix case of P1 given in affine coordinates. -- This was a plain copy and paste error, which was found due to explicit use of affine coordinates by GNUnet's new pseudonyms code. Signed-off-by: Werner Koch <wk@gnupg.org>
* Add hack to allow using an "ecc" key for "ecdsa" or "ecdh".Werner Koch2013-04-123-128/+360
| | | | | | | | | | | | | | | | | * cipher/pubkey.c (sexp_to_key): Add optional arg USE. (gcry_pk_encrypt, gcry_pk_decrypt): Call sexp_to_key with usage sign. (gcry_pk_sign, gcry_pk_verify): Call sexp_to_key with usage encrypt. * tests/basic.c (show_sexp): New. (check_pubkey_sign): Print test number and add cases for ecc. (check_pubkey_sign_ecdsa): New. (do_check_one_pubkey): Divert to new function. -- The problem we try to address is that in the mdoule specs both, ECDSA and ECDH have the same alias name "ecc". This patch allows to use for example gcry_pk_verify with a key that has only "ecc" in it. Signed-off-by: Werner Koch <wk@gnupg.org>
* Add gcry_pubkey_get_sexp.Werner Koch2013-04-1118-13/+367
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | * src/gcrypt.h.in (GCRY_PK_GET_PUBKEY): New. (GCRY_PK_GET_SECKEY): New. (gcry_pubkey_get_sexp): New. * src/visibility.c (gcry_pubkey_get_sexp): New. * src/visibility.h (gcry_pubkey_get_sexp): Mark visible. * src/libgcrypt.def, src/libgcrypt.vers: Add new function. * cipher/pubkey-internal.h: New. * cipher/Makefile.am (libcipher_la_SOURCES): Add new file. * cipher/ecc.c: Include pubkey-internal.h (_gcry_pk_ecc_get_sexp): New. * cipher/pubkey.c: Include pubkey-internal.h and context.h. (_gcry_pubkey_get_sexp): New. * src/context.c (_gcry_ctx_find_pointer): New. * src/cipher-proto.h: Add _gcry_pubkey_get_sexp. * tests/t-mpi-point.c (print_sexp): New. (context_param, basic_ec_math_simplified): Add tests for the new function. * configure.ac (NEED_GPG_ERROR_VERSION): Set to 1.11. (AH_BOTTOM) Add error codes from gpg-error 1.12 * src/g10lib.h (fips_not_operational): Use GPG_ERR_NOT_OPERATIONAL. * mpi/ec.c (_gcry_mpi_ec_get_mpi): Fix computation of Q. (_gcry_mpi_ec_get_point): Ditto. -- While checking the new code I figured that the auto-computation of Q must have led to a segv. It seems we had no test case for that. Signed-off-by: Werner Koch <wk@gnupg.org>
* Remove obsolete warning note from gcry_pk_keygrip.Werner Koch2013-04-111-2/+2
| | | | | | | | | -- The keygrip is for a long time now a standard feature of libgcrypt. The existance of the warning comment in gcrypt.h was an oversight. Signed-off-by: Werner Koch <wk@gnupg.org>
* Remove unused code.Werner Koch2013-04-112-96/+0
| | | | | | | | | | * cipher/pubkey.c (_gcry_pk_module_lookup, _gcry_pk_module_release) (_gcry_pk_get_elements): Remove. -- This code was only used by the removed ac interface. Signed-off-by: Werner Koch <wk@gnupg.org>
* Clarify DCO for Werner KochWerner Koch2013-04-051-1/+1
| | | | | | | -- All work on Libgcrypt done by Werner Koch is work made for hire by his company. Added as a mail style comment to the signed-off-by address.
* Make the Q parameter optional for ECC signing.Werner Koch2013-04-054-26/+112
| | | | | | | | | | | | | | | | | | | | | * cipher/ecc.c (ecc_sign): Remove the need for Q. * cipher/pubkey.c (sexp_elements_extract_ecc): Make Q optional for a private key. (sexp_to_key): Add optional arg R_IS_ECC. (gcry_pk_sign): Do not call gcry_pk_get_nbits for ECC keys. * tests/pubkey.c (die): Make sure to print a LF. (check_ecc_sample_key): New. (main): Call new test. -- Q is the actual public key which is not used for signing. Thus we can make it optional and even speed up the signing by parsing less stuff. Note: There seems to be a memory leak somewhere. Running tests/pubkey with just the new test enabled shows it. Signed-off-by: Werner Koch <wk@gnupg.org>
* Add test case for SCRYPT and rework the code.Werner Koch2013-04-0512-544/+393
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | * tests/t-kdf.c (check_scrypt): New. (main): Call new test. * configure.ac: Support disabling of the scrypt algorithm. Make KDF enabling similar to the other algorithm classes. Disable scrypt if we don't have a 64 bit type. * cipher/memxor.c, cipher/memxor.h: Remove. * cipher/scrypt.h: Remove. * cipher/kdf-internal.h: New. * cipher/Makefile.am: Remove files. Add new file. Move scrypt.c to EXTRA_libcipher_la_SOURCES. (GCRYPT_MODULES): Add GCRYPT_KDFS. * src/gcrypt.h.in (GCRY_KDF_SCRYPT): Change value. * cipher/kdf.c (pkdf2): Rename to _gcry_kdf_pkdf2. (_gcry_kdf_pkdf2): Don't bail out for SALTLEN==0. (gcry_kdf_derive): Allow for a passwordlen of zero for scrypt. Check for SALTLEN > 0 for GCRY_KDF_PBKDF2. Pass algo to _gcry_kdf_scrypt. (gcry_kdf_derive) [!USE_SCRYPT]: Return an error. * cipher/scrypt.c: Replace memxor.h by bufhelp.h. Replace scrypt.h by kdf-internal.h. Enable code only if HAVE_U64_TYPEDEF is defined. Replace C99 types uint64_t, uint32_t, and uint8_t by libgcrypt types. (_SALSA20_INPUT_LENGTH): Remove underscore from identifier. (_scryptBlockMix): Replace memxor by buf_xor. (_gcry_kdf_scrypt): Use gcry_malloc and gcry_free. Check for integer overflow. Add hack to support blocksize of 1 for tests. Return errors from calls to _gcry_kdf_pkdf2. * cipher/kdf.c (openpgp_s2k): Make static. -- This patch prepares the addition of more KDF functions, brings the code into Libgcrypt shape, adds a test case and makes the code more robust. For example, scrypt would have fail silently if Libgcrypt was not build with SHA256 support. Also fixed symbol naming for systems without a visibility support. Signed-off-by: Werner Koch <wk@gnupg.org>
* Add the SCRYPT KDF functionChristian Grothoff2013-04-048-2/+710
| | | | | | | | | | | | | | | * scrypt.c, scrypt.h: New files. * memxor.c, memxor.h: New files. * cipher/Makefile.am: Add new files. * cipher/kdf.c (gcry_kdf_derive): Support GCRY_KDF_SCRYPT. * src/gcrypt.h.in (GCRY_KDF_SCRYPT): New. -- Signed-off-by: Christian Grothoff <christian@grothoff.org> I added the ChangeLog entry and the missing signed-off line. Signed-off-by: Werner Koch <wk@gnupg.org>
* Doc fix.Werner Koch2013-03-261-1/+2
| | | | --
* Add DCO by Christian GrothoffWerner Koch2013-03-221-7/+21
| | | | --
* Replace deprecated AM_CONFIG_HEADER macro.Werner Koch2013-03-221-2/+2
| | | | * configure.ac: s/AM_CONFIG_HEADER/AC_CONFIG_HEADER/