boringssl/crypto
Kris Kwiatkowski 628c450c81 Add support for SIKE/p503 post-quantum KEM
Based on Microsoft's implementation available on github:
Source: https://github.com/Microsoft/PQCrypto-SIDH
Commit: 77044b76181eb61c744ac8eb7ddc7a8fe72f6919

Following changes has been applied

* In intel assembly, use MOV instead of MOVQ:
  Intel instruction reference in the Intel Software Developer's Manual
  volume 2A, the MOVQ has 4 forms. None of them mentions moving
  literal to GPR, hence "movq $rax, 0x0" is wrong. Instead, on 64bit
  system, MOV can be used.

* Some variables were wrongly zero-initialized (as per C99 spec)

* Move constant values to .RODATA segment, as keeping them in .TEXT
  segment is not compatible with XOM.

* Fixes issue in arm64 code related to the fact that compiler doesn't
  reserve enough space for the linker to relocate address of a global
  variable when used by 'ldr' instructions. Solution is to use 'adrp'
  followed by 'add' instruction. Relocations for 'adrp' and 'add'
  instructions is generated by prefixing the label with :pg_hi21:
  and :lo12: respectively.

* Enable MULX and ADX. Code from MS doesn't support PIC. MULX can't
  reference global variable directly. Instead RIP-relative addressing
  can be used. This improves performance around 10%-13% on SkyLake

* Check if CPU supports BMI2 and ADOX instruction at runtime. On AMD64
  optimized implementation of montgomery multiplication and reduction
  have 2 implementations - faster one takes advantage of BMI2
  instruction set introduced in Haswell and ADOX introduced in
  Broadwell. Thanks to OPENSSL_ia32cap_P it can be decided at runtime
  which implementation to choose. As CPU configuration is static by
  nature, branch predictor will be correct most of the time and hence
  this check very often has no cost.

* Reuse some utilities from boringssl instead of reimplementing them.
  This includes things like:
  * definition of a limb size (use crypto_word_t instead of digit_t)
  * use functions for checking in constant time if value is 0 and/or
    less then
  * #define's used for conditional compilation

* Use SSE2 for conditional swap on vector registers. Improves
  performance a little bit.

* Fix f2elm_t definition. Code imported from MSR defines f2elm_t type as
  a array of arrays. This decays to a pointer to an array (when passing
  as an argument). In C, one can't assign const pointer to an array with
  non-const pointer to an array. Seems it violates 6.7.3/8 from C99
  (same for C11). This problem occures in GCC 6, only when -pedantic
  flag is specified and it occures always in GCC 4.9 (debian jessie).

* Fix definition of eval_3_isog. Second argument in eval_3_isog mustn't be
  const. Similar reason as above.

* Use HMAC-SHA256 instead of cSHAKE-256 to avoid upstreaming cSHAKE
  and SHA3 code.

* Add speed and unit tests for SIKE.

Change-Id: I22f0bb1f9edff314a35cd74b48e8c4962568e330
2019-03-26 23:07:02 +00:00
..
asn1 Reject long inputs in c2i_ASN1_INTEGER. 2019-03-18 17:19:52 +00:00
base64 Modernize OPENSSL_COMPILE_ASSERT, part 2. 2018-11-14 16:06:37 +00:00
bio Fix d2i_*_bio on partial reads. 2018-12-05 22:05:28 +00:00
bn_extra Add some Node compatibility functions. 2019-01-25 16:50:30 +00:00
buf Flatten most of the crypto target. 2018-09-05 23:41:25 +00:00
bytestring Add uint64_t support in CBS and CBB. 2019-02-22 20:38:17 +00:00
chacha Add ABI tests for ChaCha20_ctr32. 2019-01-09 03:11:45 +00:00
cipher_extra Prefer vpaes over bsaes in AES-GCM-SIV and AES-CCM. 2019-03-05 17:55:03 +00:00
cmac Flatten most of the crypto target. 2018-09-05 23:41:25 +00:00
conf Use proper functions for lh_*. 2018-10-15 23:37:04 +00:00
curve25519 Automatically disable assembly with MSAN. 2018-09-07 21:12:37 +00:00
dh Flatten most of the crypto target. 2018-09-05 23:41:25 +00:00
digest_extra Fix undefined pointer casts in SHA-512 code. 2019-01-22 23:18:36 +00:00
dsa Tidy up dsa_sign_setup. 2018-10-25 21:51:57 +00:00
ec_extra Use EC_RAW_POINT in ECDSA. 2018-11-13 02:06:46 +00:00
ecdh_extra Clean up EC_POINT to byte conversions. 2018-11-13 17:27:59 +00:00
ecdsa_extra Remove unreachable code. 2018-11-12 23:34:36 +00:00
engine Flatten most of the crypto target. 2018-09-05 23:41:25 +00:00
err Enforce key usage for RSA keys in TLS 1.2. 2019-01-30 21:28:34 +00:00
evp Add a very roundabout EC keygen API. 2019-01-25 23:08:12 +00:00
fipsmodule Rewrite BN_CTX. 2019-03-18 19:18:31 +00:00
hkdf Flatten most of the crypto target. 2018-09-05 23:41:25 +00:00
hmac_extra Convert a number of tests to GTest. 2017-06-01 17:02:13 +00:00
hrss HRSS: flatten sample distribution. 2019-01-22 22:06:43 +00:00
lhash Fix undefined function pointer casts in LHASH. 2018-10-15 23:53:24 +00:00
obj Add initial HRSS support. 2018-12-12 17:35:02 +00:00
pem Rewrite PEM_X509_INFO_read_bio. 2018-10-01 17:35:10 +00:00
perlasm Fix x86_64-xlate.pl comment regex. 2019-02-21 16:50:17 +00:00
pkcs7 Fix undefined function pointer casts in {d2i,i2d}_Foo_{bio,fp} 2018-10-01 17:34:53 +00:00
pkcs8 Fix undefined function pointer casts in {d2i,i2d}_Foo_{bio,fp} 2018-10-01 17:34:53 +00:00
poly1305 Automatically disable assembly with MSAN. 2018-09-07 21:12:37 +00:00
pool Clear out a bunch of -Wextra-semi warnings. 2019-02-21 19:12:39 +00:00
rand_extra Unwind RDRAND functions correctly on Windows. 2019-02-12 20:24:27 +00:00
rc4 Flatten most of the crypto target. 2018-09-05 23:41:25 +00:00
rsa_extra Rename OPENSSL_NO_THREADS, part 1. 2018-09-26 19:10:02 +00:00
stack Implement sk_find manually. 2019-03-14 15:21:48 +00:00
test Add a reference for Linux ARM ABI. 2019-02-27 17:18:02 +00:00
x509 Fix d2i_*_bio on partial reads. 2018-12-05 22:05:28 +00:00
x509v3 Unexport and rename hex_to_string, string_to_hex, and name_cmp. 2018-11-27 00:08:39 +00:00
abi_self_test.cc Use Windows symbol APIs in the unwind tester. 2019-02-12 20:42:47 +00:00
CMakeLists.txt Add support for SIKE/p503 post-quantum KEM 2019-03-26 23:07:02 +00:00
compiler_test.cc Test that nullptr has the obvious memory representation. 2017-07-28 17:39:28 +00:00
constant_time_test.cc Add a test for CRYPTO_memcmp. 2018-03-27 16:22:47 +00:00
cpu-aarch64-fuchsia.c Add cpu-aarch64-fuchsia.c 2018-02-13 20:12:47 +00:00
cpu-aarch64-linux.c Add cpu-aarch64-fuchsia.c 2018-02-13 20:12:47 +00:00
cpu-arm-linux_test.cc Move ARM cpuinfo functions to the header. 2018-11-21 00:46:57 +00:00
cpu-arm-linux.c Move ARM cpuinfo functions to the header. 2018-11-21 00:46:57 +00:00
cpu-arm-linux.h Move ARM cpuinfo functions to the header. 2018-11-21 00:46:57 +00:00
cpu-arm.c Rewrite ARM feature detection. 2016-03-26 04:54:44 +00:00
cpu-intel.c Pretend AMD XOP was never a thing. 2018-12-03 22:59:55 +00:00
cpu-ppc64le.c Run the comment converter on libcrypto. 2017-08-18 21:49:04 +00:00
crypto.c Add test of assembly code dispatch. 2019-01-22 20:22:53 +00:00
ex_data.c Unexport more of lhash. 2017-10-25 04:17:18 +00:00
impl_dispatch_test.cc Enable vpaes for AES_* functions. 2019-02-22 23:09:19 +00:00
internal.h Fix header file for _byteswap_ulong and _byteswap_uint64 from MSVC CRT 2019-01-14 19:49:39 +00:00
mem.c Tell ASan about the OPENSSL_malloc prefix. 2019-03-05 17:53:16 +00:00
refcount_c11.c Run the comment converter on libcrypto. 2017-08-18 21:49:04 +00:00
refcount_lock.c Modernize OPENSSL_COMPILE_ASSERT, part 2. 2018-11-14 16:06:37 +00:00
refcount_test.cc Rename OPENSSL_NO_THREADS, part 1. 2018-09-26 19:10:02 +00:00
self_test.cc Extract FIPS KAT tests into a function. 2018-01-22 20:16:38 +00:00
thread_none.c Rename OPENSSL_NO_THREADS, part 1. 2018-09-26 19:10:02 +00:00
thread_pthread.c Modernize OPENSSL_COMPILE_ASSERT, part 2. 2018-11-14 16:06:37 +00:00
thread_test.cc Rename OPENSSL_NO_THREADS, part 1. 2018-09-26 19:10:02 +00:00
thread_win.c Replace the last CRITICAL_SECTION with SRWLOCK. 2018-12-03 20:37:35 +00:00
thread.c Remove a bunch of unnecessary includes. 2016-06-28 20:31:14 +00:00