mirror of
https://github.com/apple/swift-crypto
synced 2026-11-23 04:34:21 +00:00
Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
296d3308b4 | ||
|
|
8ff3d9dc83 | ||
|
|
5c066af98c | ||
|
|
26d3f525eb | ||
|
|
03581fe6ef | ||
|
|
f9e47ba809 | ||
|
|
42f5ffecd4 | ||
|
|
47640ada33 | ||
|
|
73dc51e2b2 | ||
|
|
f8034c8319 | ||
|
|
85d00fea15 |
No files matched your search
@@ -1,5 +1,6 @@
|
||||
.DS_Store
|
||||
/.build
|
||||
/out
|
||||
/Packages
|
||||
/*.xcodeproj
|
||||
Package.pins
|
||||
@@ -13,3 +14,4 @@ DerivedData
|
||||
**/gyb.pyc
|
||||
|
||||
.*.sw[nop]
|
||||
|
||||
@@ -0,0 +1,46 @@
|
||||
##===----------------------------------------------------------------------===##
|
||||
##
|
||||
## This source file is part of the SwiftCrypto open source project
|
||||
##
|
||||
## Copyright (c) 2021 Apple Inc. and the SwiftCrypto project authors
|
||||
## Licensed under Apache License v2.0
|
||||
##
|
||||
## See LICENSE.txt for license information
|
||||
## See CONTRIBUTORS.md for the list of SwiftCrypto project authors
|
||||
##
|
||||
## SPDX-License-Identifier: Apache-2.0
|
||||
##
|
||||
##===----------------------------------------------------------------------===##
|
||||
|
||||
cmake_minimum_required(VERSION 3.15.1)
|
||||
|
||||
project(SwiftCrypto
|
||||
LANGUAGES ASM C Swift)
|
||||
|
||||
list(APPEND CMAKE_MODULE_PATH ${CMAKE_CURRENT_SOURCE_DIR}/cmake/modules)
|
||||
|
||||
include(SwiftSupport)
|
||||
|
||||
if(CMAKE_VERSION VERSION_LESS 3.16 AND CMAKE_SYSTEM_NAME STREQUAL Windows)
|
||||
set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin)
|
||||
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin)
|
||||
else()
|
||||
set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/lib)
|
||||
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/lib)
|
||||
endif()
|
||||
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin)
|
||||
set(CMAKE_Swift_MODULE_DIRECTORY ${CMAKE_BINARY_DIR}/swift)
|
||||
|
||||
option(BUILD_SHARED_LIBS "Build shared libraries by default" YES)
|
||||
|
||||
if(BUILD_SHARED_LIBS)
|
||||
set(CMAKE_POSITION_INDEPENDENT_CODE YES)
|
||||
endif()
|
||||
|
||||
if(NOT CMAKE_SYSTEM_NAME STREQUAL Darwin)
|
||||
find_package(dispatch CONFIG)
|
||||
find_package(Foundation CONFIG)
|
||||
endif()
|
||||
|
||||
add_subdirectory(Sources)
|
||||
add_subdirectory(cmake/modules)
|
||||
+1
-1
@@ -20,7 +20,7 @@
|
||||
// Sources/CCryptoBoringSSL directory. The source repository is at
|
||||
// https://boringssl.googlesource.com/boringssl.
|
||||
//
|
||||
// BoringSSL Commit: 9dae0ac4f0ae18ebed988d36bfb4c4e4023fc574
|
||||
// BoringSSL Commit: bb43a45d6de7375f3310511d37f040d1055f8a10
|
||||
|
||||
import PackageDescription
|
||||
|
||||
|
||||
+373
@@ -0,0 +1,373 @@
|
||||
##===----------------------------------------------------------------------===##
|
||||
##
|
||||
## This source file is part of the SwiftCrypto open source project
|
||||
##
|
||||
## Copyright (c) 2021 Apple Inc. and the SwiftCrypto project authors
|
||||
## Licensed under Apache License v2.0
|
||||
##
|
||||
## See LICENSE.txt for license information
|
||||
## See CONTRIBUTORS.md for the list of SwiftCrypto project authors
|
||||
##
|
||||
## SPDX-License-Identifier: Apache-2.0
|
||||
##
|
||||
##===----------------------------------------------------------------------===##
|
||||
|
||||
add_library(CCryptoBoringSSL STATIC
|
||||
"crypto/asn1/a_bitstr.c"
|
||||
"crypto/asn1/a_bool.c"
|
||||
"crypto/asn1/a_d2i_fp.c"
|
||||
"crypto/asn1/a_dup.c"
|
||||
"crypto/asn1/a_enum.c"
|
||||
"crypto/asn1/a_gentm.c"
|
||||
"crypto/asn1/a_i2d_fp.c"
|
||||
"crypto/asn1/a_int.c"
|
||||
"crypto/asn1/a_mbstr.c"
|
||||
"crypto/asn1/a_object.c"
|
||||
"crypto/asn1/a_octet.c"
|
||||
"crypto/asn1/a_print.c"
|
||||
"crypto/asn1/a_strnid.c"
|
||||
"crypto/asn1/a_time.c"
|
||||
"crypto/asn1/a_type.c"
|
||||
"crypto/asn1/a_utctm.c"
|
||||
"crypto/asn1/a_utf8.c"
|
||||
"crypto/asn1/asn1_lib.c"
|
||||
"crypto/asn1/asn1_par.c"
|
||||
"crypto/asn1/asn_pack.c"
|
||||
"crypto/asn1/f_enum.c"
|
||||
"crypto/asn1/f_int.c"
|
||||
"crypto/asn1/f_string.c"
|
||||
"crypto/asn1/tasn_dec.c"
|
||||
"crypto/asn1/tasn_enc.c"
|
||||
"crypto/asn1/tasn_fre.c"
|
||||
"crypto/asn1/tasn_new.c"
|
||||
"crypto/asn1/tasn_typ.c"
|
||||
"crypto/asn1/tasn_utl.c"
|
||||
"crypto/asn1/time_support.c"
|
||||
"crypto/base64/base64.c"
|
||||
"crypto/bio/bio.c"
|
||||
"crypto/bio/bio_mem.c"
|
||||
"crypto/bio/connect.c"
|
||||
"crypto/bio/fd.c"
|
||||
"crypto/bio/file.c"
|
||||
"crypto/bio/hexdump.c"
|
||||
"crypto/bio/pair.c"
|
||||
"crypto/bio/printf.c"
|
||||
"crypto/bio/socket.c"
|
||||
"crypto/bio/socket_helper.c"
|
||||
"crypto/blake2/blake2.c"
|
||||
"crypto/bn_extra/bn_asn1.c"
|
||||
"crypto/bn_extra/convert.c"
|
||||
"crypto/buf/buf.c"
|
||||
"crypto/bytestring/asn1_compat.c"
|
||||
"crypto/bytestring/ber.c"
|
||||
"crypto/bytestring/cbb.c"
|
||||
"crypto/bytestring/cbs.c"
|
||||
"crypto/bytestring/unicode.c"
|
||||
"crypto/chacha/chacha.c"
|
||||
"crypto/cipher_extra/cipher_extra.c"
|
||||
"crypto/cipher_extra/derive_key.c"
|
||||
"crypto/cipher_extra/e_aesccm.c"
|
||||
"crypto/cipher_extra/e_aesctrhmac.c"
|
||||
"crypto/cipher_extra/e_aesgcmsiv.c"
|
||||
"crypto/cipher_extra/e_chacha20poly1305.c"
|
||||
"crypto/cipher_extra/e_null.c"
|
||||
"crypto/cipher_extra/e_rc2.c"
|
||||
"crypto/cipher_extra/e_rc4.c"
|
||||
"crypto/cipher_extra/e_tls.c"
|
||||
"crypto/cipher_extra/tls_cbc.c"
|
||||
"crypto/cmac/cmac.c"
|
||||
"crypto/conf/conf.c"
|
||||
"crypto/cpu-aarch64-fuchsia.c"
|
||||
"crypto/cpu-aarch64-linux.c"
|
||||
"crypto/cpu-aarch64-win.c"
|
||||
"crypto/cpu-arm-linux.c"
|
||||
"crypto/cpu-arm.c"
|
||||
"crypto/cpu-intel.c"
|
||||
"crypto/cpu-ppc64le.c"
|
||||
"crypto/crypto.c"
|
||||
"crypto/curve25519/curve25519.c"
|
||||
"crypto/curve25519/spake25519.c"
|
||||
"crypto/dh_extra/dh_asn1.c"
|
||||
"crypto/dh_extra/params.c"
|
||||
"crypto/digest_extra/digest_extra.c"
|
||||
"crypto/dsa/dsa.c"
|
||||
"crypto/dsa/dsa_asn1.c"
|
||||
"crypto/ec_extra/ec_asn1.c"
|
||||
"crypto/ec_extra/ec_derive.c"
|
||||
"crypto/ec_extra/hash_to_curve.c"
|
||||
"crypto/ecdh_extra/ecdh_extra.c"
|
||||
"crypto/ecdsa_extra/ecdsa_asn1.c"
|
||||
"crypto/engine/engine.c"
|
||||
"crypto/err/err.c"
|
||||
"crypto/err/err_data.c"
|
||||
"crypto/evp/digestsign.c"
|
||||
"crypto/evp/evp.c"
|
||||
"crypto/evp/evp_asn1.c"
|
||||
"crypto/evp/evp_ctx.c"
|
||||
"crypto/evp/p_dsa_asn1.c"
|
||||
"crypto/evp/p_ec.c"
|
||||
"crypto/evp/p_ec_asn1.c"
|
||||
"crypto/evp/p_ed25519.c"
|
||||
"crypto/evp/p_ed25519_asn1.c"
|
||||
"crypto/evp/p_rsa.c"
|
||||
"crypto/evp/p_rsa_asn1.c"
|
||||
"crypto/evp/p_x25519.c"
|
||||
"crypto/evp/p_x25519_asn1.c"
|
||||
"crypto/evp/pbkdf.c"
|
||||
"crypto/evp/print.c"
|
||||
"crypto/evp/scrypt.c"
|
||||
"crypto/evp/sign.c"
|
||||
"crypto/ex_data.c"
|
||||
"crypto/fipsmodule/aes/aes.c"
|
||||
"crypto/fipsmodule/aes/aes_nohw.c"
|
||||
"crypto/fipsmodule/aes/key_wrap.c"
|
||||
"crypto/fipsmodule/aes/mode_wrappers.c"
|
||||
"crypto/fipsmodule/bn/add.c"
|
||||
"crypto/fipsmodule/bn/asm/x86_64-gcc.c"
|
||||
"crypto/fipsmodule/bn/bn.c"
|
||||
"crypto/fipsmodule/bn/bytes.c"
|
||||
"crypto/fipsmodule/bn/cmp.c"
|
||||
"crypto/fipsmodule/bn/ctx.c"
|
||||
"crypto/fipsmodule/bn/div.c"
|
||||
"crypto/fipsmodule/bn/div_extra.c"
|
||||
"crypto/fipsmodule/bn/exponentiation.c"
|
||||
"crypto/fipsmodule/bn/gcd.c"
|
||||
"crypto/fipsmodule/bn/gcd_extra.c"
|
||||
"crypto/fipsmodule/bn/generic.c"
|
||||
"crypto/fipsmodule/bn/jacobi.c"
|
||||
"crypto/fipsmodule/bn/montgomery.c"
|
||||
"crypto/fipsmodule/bn/montgomery_inv.c"
|
||||
"crypto/fipsmodule/bn/mul.c"
|
||||
"crypto/fipsmodule/bn/prime.c"
|
||||
"crypto/fipsmodule/bn/random.c"
|
||||
"crypto/fipsmodule/bn/rsaz_exp.c"
|
||||
"crypto/fipsmodule/bn/shift.c"
|
||||
"crypto/fipsmodule/bn/sqrt.c"
|
||||
"crypto/fipsmodule/cipher/aead.c"
|
||||
"crypto/fipsmodule/cipher/cipher.c"
|
||||
"crypto/fipsmodule/cipher/e_aes.c"
|
||||
"crypto/fipsmodule/cipher/e_des.c"
|
||||
"crypto/fipsmodule/des/des.c"
|
||||
"crypto/fipsmodule/dh/check.c"
|
||||
"crypto/fipsmodule/dh/dh.c"
|
||||
"crypto/fipsmodule/digest/digest.c"
|
||||
"crypto/fipsmodule/digest/digests.c"
|
||||
"crypto/fipsmodule/ec/ec.c"
|
||||
"crypto/fipsmodule/ec/ec_key.c"
|
||||
"crypto/fipsmodule/ec/ec_montgomery.c"
|
||||
"crypto/fipsmodule/ec/felem.c"
|
||||
"crypto/fipsmodule/ec/oct.c"
|
||||
"crypto/fipsmodule/ec/p224-64.c"
|
||||
"crypto/fipsmodule/ec/p256-x86_64.c"
|
||||
"crypto/fipsmodule/ec/p256.c"
|
||||
"crypto/fipsmodule/ec/scalar.c"
|
||||
"crypto/fipsmodule/ec/simple.c"
|
||||
"crypto/fipsmodule/ec/simple_mul.c"
|
||||
"crypto/fipsmodule/ec/util.c"
|
||||
"crypto/fipsmodule/ec/wnaf.c"
|
||||
"crypto/fipsmodule/ecdh/ecdh.c"
|
||||
"crypto/fipsmodule/ecdsa/ecdsa.c"
|
||||
"crypto/fipsmodule/fips_shared_support.c"
|
||||
"crypto/fipsmodule/hmac/hmac.c"
|
||||
"crypto/fipsmodule/is_fips.c"
|
||||
"crypto/fipsmodule/md4/md4.c"
|
||||
"crypto/fipsmodule/md5/md5.c"
|
||||
"crypto/fipsmodule/modes/cbc.c"
|
||||
"crypto/fipsmodule/modes/cfb.c"
|
||||
"crypto/fipsmodule/modes/ctr.c"
|
||||
"crypto/fipsmodule/modes/gcm.c"
|
||||
"crypto/fipsmodule/modes/gcm_nohw.c"
|
||||
"crypto/fipsmodule/modes/ofb.c"
|
||||
"crypto/fipsmodule/modes/polyval.c"
|
||||
"crypto/fipsmodule/rand/ctrdrbg.c"
|
||||
"crypto/fipsmodule/rand/fork_detect.c"
|
||||
"crypto/fipsmodule/rand/rand.c"
|
||||
"crypto/fipsmodule/rand/urandom.c"
|
||||
"crypto/fipsmodule/rsa/blinding.c"
|
||||
"crypto/fipsmodule/rsa/padding.c"
|
||||
"crypto/fipsmodule/rsa/rsa.c"
|
||||
"crypto/fipsmodule/rsa/rsa_impl.c"
|
||||
"crypto/fipsmodule/self_check/self_check.c"
|
||||
"crypto/fipsmodule/sha/sha1-altivec.c"
|
||||
"crypto/fipsmodule/sha/sha1.c"
|
||||
"crypto/fipsmodule/sha/sha256.c"
|
||||
"crypto/fipsmodule/sha/sha512.c"
|
||||
"crypto/fipsmodule/tls/kdf.c"
|
||||
"crypto/hkdf/hkdf.c"
|
||||
"crypto/hpke/hpke.c"
|
||||
"crypto/hrss/hrss.c"
|
||||
"crypto/lhash/lhash.c"
|
||||
"crypto/mem.c"
|
||||
"crypto/obj/obj.c"
|
||||
"crypto/obj/obj_xref.c"
|
||||
"crypto/pem/pem_all.c"
|
||||
"crypto/pem/pem_info.c"
|
||||
"crypto/pem/pem_lib.c"
|
||||
"crypto/pem/pem_oth.c"
|
||||
"crypto/pem/pem_pk8.c"
|
||||
"crypto/pem/pem_pkey.c"
|
||||
"crypto/pem/pem_x509.c"
|
||||
"crypto/pem/pem_xaux.c"
|
||||
"crypto/pkcs7/pkcs7.c"
|
||||
"crypto/pkcs7/pkcs7_x509.c"
|
||||
"crypto/pkcs8/p5_pbev2.c"
|
||||
"crypto/pkcs8/pkcs8.c"
|
||||
"crypto/pkcs8/pkcs8_x509.c"
|
||||
"crypto/poly1305/poly1305.c"
|
||||
"crypto/poly1305/poly1305_arm.c"
|
||||
"crypto/poly1305/poly1305_vec.c"
|
||||
"crypto/pool/pool.c"
|
||||
"crypto/rand_extra/deterministic.c"
|
||||
"crypto/rand_extra/forkunsafe.c"
|
||||
"crypto/rand_extra/fuchsia.c"
|
||||
"crypto/rand_extra/passive.c"
|
||||
"crypto/rand_extra/rand_extra.c"
|
||||
"crypto/rand_extra/windows.c"
|
||||
"crypto/rc4/rc4.c"
|
||||
"crypto/refcount_c11.c"
|
||||
"crypto/refcount_lock.c"
|
||||
"crypto/rsa_extra/rsa_asn1.c"
|
||||
"crypto/rsa_extra/rsa_print.c"
|
||||
"crypto/siphash/siphash.c"
|
||||
"crypto/stack/stack.c"
|
||||
"crypto/thread.c"
|
||||
"crypto/thread_none.c"
|
||||
"crypto/thread_pthread.c"
|
||||
"crypto/thread_win.c"
|
||||
"crypto/trust_token/pmbtoken.c"
|
||||
"crypto/trust_token/trust_token.c"
|
||||
"crypto/trust_token/voprf.c"
|
||||
"crypto/x509/a_digest.c"
|
||||
"crypto/x509/a_sign.c"
|
||||
"crypto/x509/a_strex.c"
|
||||
"crypto/x509/a_verify.c"
|
||||
"crypto/x509/algorithm.c"
|
||||
"crypto/x509/asn1_gen.c"
|
||||
"crypto/x509/by_dir.c"
|
||||
"crypto/x509/by_file.c"
|
||||
"crypto/x509/i2d_pr.c"
|
||||
"crypto/x509/rsa_pss.c"
|
||||
"crypto/x509/t_crl.c"
|
||||
"crypto/x509/t_req.c"
|
||||
"crypto/x509/t_x509.c"
|
||||
"crypto/x509/t_x509a.c"
|
||||
"crypto/x509/x509.c"
|
||||
"crypto/x509/x509_att.c"
|
||||
"crypto/x509/x509_cmp.c"
|
||||
"crypto/x509/x509_d2.c"
|
||||
"crypto/x509/x509_def.c"
|
||||
"crypto/x509/x509_ext.c"
|
||||
"crypto/x509/x509_lu.c"
|
||||
"crypto/x509/x509_obj.c"
|
||||
"crypto/x509/x509_r2x.c"
|
||||
"crypto/x509/x509_req.c"
|
||||
"crypto/x509/x509_set.c"
|
||||
"crypto/x509/x509_trs.c"
|
||||
"crypto/x509/x509_txt.c"
|
||||
"crypto/x509/x509_v3.c"
|
||||
"crypto/x509/x509_vfy.c"
|
||||
"crypto/x509/x509_vpm.c"
|
||||
"crypto/x509/x509cset.c"
|
||||
"crypto/x509/x509name.c"
|
||||
"crypto/x509/x509rset.c"
|
||||
"crypto/x509/x509spki.c"
|
||||
"crypto/x509/x_algor.c"
|
||||
"crypto/x509/x_all.c"
|
||||
"crypto/x509/x_attrib.c"
|
||||
"crypto/x509/x_crl.c"
|
||||
"crypto/x509/x_exten.c"
|
||||
"crypto/x509/x_info.c"
|
||||
"crypto/x509/x_name.c"
|
||||
"crypto/x509/x_pkey.c"
|
||||
"crypto/x509/x_pubkey.c"
|
||||
"crypto/x509/x_req.c"
|
||||
"crypto/x509/x_sig.c"
|
||||
"crypto/x509/x_spki.c"
|
||||
"crypto/x509/x_val.c"
|
||||
"crypto/x509/x_x509.c"
|
||||
"crypto/x509/x_x509a.c"
|
||||
"crypto/x509v3/pcy_cache.c"
|
||||
"crypto/x509v3/pcy_data.c"
|
||||
"crypto/x509v3/pcy_lib.c"
|
||||
"crypto/x509v3/pcy_map.c"
|
||||
"crypto/x509v3/pcy_node.c"
|
||||
"crypto/x509v3/pcy_tree.c"
|
||||
"crypto/x509v3/v3_akey.c"
|
||||
"crypto/x509v3/v3_akeya.c"
|
||||
"crypto/x509v3/v3_alt.c"
|
||||
"crypto/x509v3/v3_bcons.c"
|
||||
"crypto/x509v3/v3_bitst.c"
|
||||
"crypto/x509v3/v3_conf.c"
|
||||
"crypto/x509v3/v3_cpols.c"
|
||||
"crypto/x509v3/v3_crld.c"
|
||||
"crypto/x509v3/v3_enum.c"
|
||||
"crypto/x509v3/v3_extku.c"
|
||||
"crypto/x509v3/v3_genn.c"
|
||||
"crypto/x509v3/v3_ia5.c"
|
||||
"crypto/x509v3/v3_info.c"
|
||||
"crypto/x509v3/v3_int.c"
|
||||
"crypto/x509v3/v3_lib.c"
|
||||
"crypto/x509v3/v3_ncons.c"
|
||||
"crypto/x509v3/v3_ocsp.c"
|
||||
"crypto/x509v3/v3_pci.c"
|
||||
"crypto/x509v3/v3_pcia.c"
|
||||
"crypto/x509v3/v3_pcons.c"
|
||||
"crypto/x509v3/v3_pmaps.c"
|
||||
"crypto/x509v3/v3_prn.c"
|
||||
"crypto/x509v3/v3_purp.c"
|
||||
"crypto/x509v3/v3_skey.c"
|
||||
"crypto/x509v3/v3_utl.c")
|
||||
|
||||
if(CMAKE_SYSTEM_PROCESSOR MATCHES "x86_64|amd64")
|
||||
if(CMAKE_SYSTEM_NAME STREQUAL Darwin)
|
||||
target_sources(CCryptoBoringSSL PRIVATE
|
||||
crypto/chacha/chacha-x86_64.mac.x86_64.S
|
||||
crypto/cipher_extra/aes128gcmsiv-x86_64.mac.x86_64.S
|
||||
crypto/cipher_extra/chacha20_poly1305_x86_64.mac.x86_64.S
|
||||
crypto/fipsmodule/aesni-gcm-x86_64.mac.x86_64.S
|
||||
crypto/fipsmodule/aesni-x86_64.mac.x86_64.S
|
||||
crypto/fipsmodule/ghash-ssse3-x86_64.mac.x86_64.S
|
||||
crypto/fipsmodule/ghash-x86_64.mac.x86_64.S
|
||||
crypto/fipsmodule/md5-x86_64.mac.x86_64.S
|
||||
crypto/fipsmodule/p256-x86_64-asm.mac.x86_64.S
|
||||
crypto/fipsmodule/p256_beeu-x86_64-asm.mac.x86_64.S
|
||||
crypto/fipsmodule/rdrand-x86_64.mac.x86_64.S
|
||||
crypto/fipsmodule/rsaz-avx2.mac.x86_64.S
|
||||
crypto/fipsmodule/sha1-x86_64.mac.x86_64.S
|
||||
crypto/fipsmodule/sha256-x86_64.mac.x86_64.S
|
||||
crypto/fipsmodule/sha512-x86_64.mac.x86_64.S
|
||||
crypto/fipsmodule/vpaes-x86_64.mac.x86_64.S
|
||||
crypto/fipsmodule/x86_64-mont.mac.x86_64.S
|
||||
crypto/fipsmodule/x86_64-mont5.mac.x86_64.S)
|
||||
elseif(CMAKE_SYSTEM_NAME STREQUAL Linux)
|
||||
target_sources(CCryptoBoringSSL PRIVATE
|
||||
crypto/chacha/chacha-x86_64.linux.x86_64.S
|
||||
crypto/cipher_extra/aes128gcmsiv-x86_64.linux.x86_64.S
|
||||
crypto/cipher_extra/chacha20_poly1305_x86_64.linux.x86_64.S
|
||||
crypto/fipsmodule/aesni-gcm-x86_64.linux.x86_64.S
|
||||
crypto/fipsmodule/aesni-x86_64.linux.x86_64.S
|
||||
crypto/fipsmodule/ghash-ssse3-x86_64.linux.x86_64.S
|
||||
crypto/fipsmodule/ghash-x86_64.linux.x86_64.S
|
||||
crypto/fipsmodule/md5-x86_64.linux.x86_64.S
|
||||
crypto/fipsmodule/p256-x86_64-asm.linux.x86_64.S
|
||||
crypto/fipsmodule/p256_beeu-x86_64-asm.linux.x86_64.S
|
||||
crypto/fipsmodule/rdrand-x86_64.linux.x86_64.S
|
||||
crypto/fipsmodule/rsaz-avx2.linux.x86_64.S
|
||||
crypto/fipsmodule/sha1-x86_64.linux.x86_64.S
|
||||
crypto/fipsmodule/sha256-x86_64.linux.x86_64.S
|
||||
crypto/fipsmodule/sha512-x86_64.linux.x86_64.S
|
||||
crypto/fipsmodule/vpaes-x86_64.linux.x86_64.S
|
||||
crypto/fipsmodule/x86_64-mont.linux.x86_64.S
|
||||
crypto/fipsmodule/x86_64-mont5.linux.x86_64.S)
|
||||
endif()
|
||||
endif()
|
||||
|
||||
target_include_directories(CCryptoBoringSSL PUBLIC
|
||||
include)
|
||||
|
||||
target_compile_definitions(CCryptoBoringSSL PRIVATE
|
||||
$<$<PLATFORM_ID:Windows>:WIN32_LEAN_AND_MEAN>)
|
||||
set_target_properties(CCryptoBoringSSL PROPERTIES
|
||||
INTERFACE_INCLUDE_DIRECTORIES "${CMAKE_CURRENT_SOURCE_DIR}/include;${CMAKE_Swift_MODULE_DIRECTORY}")
|
||||
|
||||
set_property(GLOBAL APPEND PROPERTY SWIFT_CRYPTO_EXPORTS CCryptoBoringSSL)
|
||||
@@ -223,6 +223,15 @@ static int asn1_item_ex_d2i(ASN1_VALUE **pval, const unsigned char **in,
|
||||
break;
|
||||
|
||||
case ASN1_ITYPE_MSTRING:
|
||||
/*
|
||||
* It never makes sense for multi-strings to have implicit tagging, so
|
||||
* if tag != -1, then this looks like an error in the template.
|
||||
*/
|
||||
if (tag != -1) {
|
||||
OPENSSL_PUT_ERROR(ASN1, ASN1_R_BAD_TEMPLATE);
|
||||
goto err;
|
||||
}
|
||||
|
||||
p = *in;
|
||||
/* Just read in tag and class */
|
||||
ret = asn1_check_tlen(NULL, &otag, &oclass, NULL, NULL,
|
||||
@@ -256,6 +265,15 @@ static int asn1_item_ex_d2i(ASN1_VALUE **pval, const unsigned char **in,
|
||||
return ef->asn1_ex_d2i(pval, in, len, it, tag, aclass, opt, ctx);
|
||||
|
||||
case ASN1_ITYPE_CHOICE:
|
||||
/*
|
||||
* It never makes sense for CHOICE types to have implicit tagging, so if
|
||||
* tag != -1, then this looks like an error in the template.
|
||||
*/
|
||||
if (tag != -1) {
|
||||
OPENSSL_PUT_ERROR(ASN1, ASN1_R_BAD_TEMPLATE);
|
||||
goto err;
|
||||
}
|
||||
|
||||
if (asn1_cb && !asn1_cb(ASN1_OP_D2I_PRE, pval, it, NULL))
|
||||
goto auxerr;
|
||||
|
||||
|
||||
@@ -145,9 +145,25 @@ int ASN1_item_ex_i2d(ASN1_VALUE **pval, unsigned char **out,
|
||||
break;
|
||||
|
||||
case ASN1_ITYPE_MSTRING:
|
||||
/*
|
||||
* It never makes sense for multi-strings to have implicit tagging, so
|
||||
* if tag != -1, then this looks like an error in the template.
|
||||
*/
|
||||
if (tag != -1) {
|
||||
OPENSSL_PUT_ERROR(ASN1, ASN1_R_BAD_TEMPLATE);
|
||||
return -1;
|
||||
}
|
||||
return asn1_i2d_ex_primitive(pval, out, it, -1, aclass);
|
||||
|
||||
case ASN1_ITYPE_CHOICE:
|
||||
/*
|
||||
* It never makes sense for CHOICE types to have implicit tagging, so if
|
||||
* tag != -1, then this looks like an error in the template.
|
||||
*/
|
||||
if (tag != -1) {
|
||||
OPENSSL_PUT_ERROR(ASN1, ASN1_R_BAD_TEMPLATE);
|
||||
return -1;
|
||||
}
|
||||
if (asn1_cb && !asn1_cb(ASN1_OP_I2D_PRE, pval, it, NULL))
|
||||
return 0;
|
||||
i = asn1_get_choice_selector(pval, it);
|
||||
|
||||
@@ -55,7 +55,11 @@ int bio_ip_and_port_to_socket_and_addr(int *out_sock,
|
||||
ret = getaddrinfo(hostname, port_str, &hint, &result);
|
||||
if (ret != 0) {
|
||||
OPENSSL_PUT_ERROR(SYS, 0);
|
||||
#if defined(OPENSSL_WINDOWS)
|
||||
ERR_add_error_data(1, gai_strerrorA(ret));
|
||||
#else
|
||||
ERR_add_error_data(1, gai_strerror(ret));
|
||||
#endif
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,158 @@
|
||||
/* Copyright (c) 2021, Google Inc.
|
||||
*
|
||||
* Permission to use, copy, modify, and/or distribute this software for any
|
||||
* purpose with or without fee is hereby granted, provided that the above
|
||||
* copyright notice and this permission notice appear in all copies.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
|
||||
* WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
|
||||
* MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
|
||||
* SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
|
||||
* WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION
|
||||
* OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
|
||||
* CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. */
|
||||
|
||||
#include <CCryptoBoringSSL_blake2.h>
|
||||
|
||||
#include <CCryptoBoringSSL_type_check.h>
|
||||
|
||||
#include "../internal.h"
|
||||
|
||||
// https://tools.ietf.org/html/rfc7693#section-2.6
|
||||
static const uint64_t kIV[8] = {
|
||||
UINT64_C(0x6a09e667f3bcc908), UINT64_C(0xbb67ae8584caa73b),
|
||||
UINT64_C(0x3c6ef372fe94f82b), UINT64_C(0xa54ff53a5f1d36f1),
|
||||
UINT64_C(0x510e527fade682d1), UINT64_C(0x9b05688c2b3e6c1f),
|
||||
UINT64_C(0x1f83d9abfb41bd6b), UINT64_C(0x5be0cd19137e2179),
|
||||
};
|
||||
|
||||
// https://tools.ietf.org/html/rfc7693#section-2.7
|
||||
static const uint8_t kSigma[10 * 16] = {
|
||||
// clang-format off
|
||||
0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15,
|
||||
14, 10, 4, 8, 9, 15, 13, 6, 1, 12, 0, 2, 11, 7, 5, 3,
|
||||
11, 8, 12, 0, 5, 2, 15, 13, 10, 14, 3, 6, 7, 1, 9, 4,
|
||||
7, 9, 3, 1, 13, 12, 11, 14, 2, 6, 5, 10, 4, 0, 15, 8,
|
||||
9, 0, 5, 7, 2, 4, 10, 15, 14, 1, 11, 12, 6, 8, 3, 13,
|
||||
2, 12, 6, 10, 0, 11, 8, 3, 4, 13, 7, 5, 15, 14, 1, 9,
|
||||
12, 5, 1, 15, 14, 13, 4, 10, 0, 7, 6, 3, 9, 2, 8, 11,
|
||||
13, 11, 7, 14, 12, 1, 3, 9, 5, 0, 15, 4, 8, 6, 2, 10,
|
||||
6, 15, 14, 9, 11, 3, 0, 8, 12, 2, 13, 7, 1, 4, 10, 5,
|
||||
10, 2, 8, 4, 7, 6, 1, 5, 15, 11, 9, 14, 3, 12, 13, 0,
|
||||
// clang-format on
|
||||
};
|
||||
|
||||
#define RIGHT_ROTATE(v, n) (((v) >> (n)) | ((v) << (64 - (n))))
|
||||
|
||||
// https://tools.ietf.org/html/rfc7693#section-3.1
|
||||
static void blake2b_mix(uint64_t v[16], int a, int b, int c, int d, uint64_t x,
|
||||
uint64_t y) {
|
||||
v[a] = v[a] + v[b] + x;
|
||||
v[d] = RIGHT_ROTATE(v[d] ^ v[a], 32);
|
||||
v[c] = v[c] + v[d];
|
||||
v[b] = RIGHT_ROTATE(v[b] ^ v[c], 24);
|
||||
v[a] = v[a] + v[b] + y;
|
||||
v[d] = RIGHT_ROTATE(v[d] ^ v[a], 16);
|
||||
v[c] = v[c] + v[d];
|
||||
v[b] = RIGHT_ROTATE(v[b] ^ v[c], 63);
|
||||
}
|
||||
|
||||
static void blake2b_transform(
|
||||
BLAKE2B_CTX *b2b,
|
||||
const uint64_t block_words[BLAKE2B_CBLOCK / sizeof(uint64_t)],
|
||||
size_t num_bytes, int is_final_block) {
|
||||
// https://tools.ietf.org/html/rfc7693#section-3.2
|
||||
uint64_t v[16];
|
||||
OPENSSL_STATIC_ASSERT(sizeof(v) == sizeof(b2b->h) + sizeof(kIV), "");
|
||||
OPENSSL_memcpy(v, b2b->h, sizeof(b2b->h));
|
||||
OPENSSL_memcpy(&v[8], kIV, sizeof(kIV));
|
||||
|
||||
b2b->t_low += num_bytes;
|
||||
if (b2b->t_low < num_bytes) {
|
||||
b2b->t_high++;
|
||||
}
|
||||
v[12] ^= b2b->t_low;
|
||||
v[13] ^= b2b->t_high;
|
||||
|
||||
if (is_final_block) {
|
||||
v[14] = ~v[14];
|
||||
}
|
||||
|
||||
for (int round = 0; round < 12; round++) {
|
||||
const uint8_t *const s = &kSigma[16 * (round % 10)];
|
||||
blake2b_mix(v, 0, 4, 8, 12, block_words[s[0]], block_words[s[1]]);
|
||||
blake2b_mix(v, 1, 5, 9, 13, block_words[s[2]], block_words[s[3]]);
|
||||
blake2b_mix(v, 2, 6, 10, 14, block_words[s[4]], block_words[s[5]]);
|
||||
blake2b_mix(v, 3, 7, 11, 15, block_words[s[6]], block_words[s[7]]);
|
||||
blake2b_mix(v, 0, 5, 10, 15, block_words[s[8]], block_words[s[9]]);
|
||||
blake2b_mix(v, 1, 6, 11, 12, block_words[s[10]], block_words[s[11]]);
|
||||
blake2b_mix(v, 2, 7, 8, 13, block_words[s[12]], block_words[s[13]]);
|
||||
blake2b_mix(v, 3, 4, 9, 14, block_words[s[14]], block_words[s[15]]);
|
||||
}
|
||||
|
||||
for (size_t i = 0; i < OPENSSL_ARRAY_SIZE(b2b->h); i++) {
|
||||
b2b->h[i] ^= v[i];
|
||||
b2b->h[i] ^= v[i + 8];
|
||||
}
|
||||
}
|
||||
|
||||
void BLAKE2B256_Init(BLAKE2B_CTX *b2b) {
|
||||
OPENSSL_memset(b2b, 0, sizeof(BLAKE2B_CTX));
|
||||
|
||||
OPENSSL_STATIC_ASSERT(sizeof(kIV) == sizeof(b2b->h), "");
|
||||
OPENSSL_memcpy(&b2b->h, kIV, sizeof(kIV));
|
||||
|
||||
// https://tools.ietf.org/html/rfc7693#section-2.5
|
||||
b2b->h[0] ^= 0x01010000 | BLAKE2B256_DIGEST_LENGTH;
|
||||
}
|
||||
|
||||
void BLAKE2B256_Update(BLAKE2B_CTX *b2b, const void *in_data, size_t len) {
|
||||
const uint8_t *data = (const uint8_t *)in_data;
|
||||
|
||||
size_t todo = sizeof(b2b->block.bytes) - b2b->block_used;
|
||||
if (todo > len) {
|
||||
todo = len;
|
||||
}
|
||||
OPENSSL_memcpy(&b2b->block.bytes[b2b->block_used], data, todo);
|
||||
b2b->block_used += todo;
|
||||
data += todo;
|
||||
len -= todo;
|
||||
|
||||
if (!len) {
|
||||
return;
|
||||
}
|
||||
|
||||
// More input remains therefore we must have filled |b2b->block|.
|
||||
assert(b2b->block_used == BLAKE2B_CBLOCK);
|
||||
blake2b_transform(b2b, b2b->block.words, BLAKE2B_CBLOCK,
|
||||
/*is_final_block=*/0);
|
||||
b2b->block_used = 0;
|
||||
|
||||
while (len > BLAKE2B_CBLOCK) {
|
||||
uint64_t block_words[BLAKE2B_CBLOCK / sizeof(uint64_t)];
|
||||
OPENSSL_memcpy(block_words, data, sizeof(block_words));
|
||||
blake2b_transform(b2b, block_words, BLAKE2B_CBLOCK, /*is_final_block=*/0);
|
||||
data += BLAKE2B_CBLOCK;
|
||||
len -= BLAKE2B_CBLOCK;
|
||||
}
|
||||
|
||||
OPENSSL_memcpy(b2b->block.bytes, data, len);
|
||||
b2b->block_used = len;
|
||||
}
|
||||
|
||||
void BLAKE2B256_Final(uint8_t out[BLAKE2B256_DIGEST_LENGTH], BLAKE2B_CTX *b2b) {
|
||||
OPENSSL_memset(&b2b->block.bytes[b2b->block_used], 0,
|
||||
sizeof(b2b->block.bytes) - b2b->block_used);
|
||||
blake2b_transform(b2b, b2b->block.words, b2b->block_used,
|
||||
/*is_final_block=*/1);
|
||||
OPENSSL_STATIC_ASSERT(BLAKE2B256_DIGEST_LENGTH <= sizeof(b2b->h), "");
|
||||
memcpy(out, b2b->h, BLAKE2B256_DIGEST_LENGTH);
|
||||
}
|
||||
|
||||
void BLAKE2B256(const uint8_t *data, size_t len,
|
||||
uint8_t out[BLAKE2B256_DIGEST_LENGTH]) {
|
||||
BLAKE2B_CTX ctx;
|
||||
BLAKE2B256_Init(&ctx);
|
||||
BLAKE2B256_Update(&ctx, data, len);
|
||||
BLAKE2B256_Final(out, &ctx);
|
||||
}
|
||||
@@ -53,7 +53,7 @@ static int is_string_type(unsigned tag) {
|
||||
// depending on whether an indefinite length element or constructed string was
|
||||
// found. The value of |orig_in| is not changed. It returns one on success (i.e.
|
||||
// |*ber_found| was set) and zero on error.
|
||||
static int cbs_find_ber(const CBS *orig_in, char *ber_found, unsigned depth) {
|
||||
static int cbs_find_ber(const CBS *orig_in, int *ber_found, unsigned depth) {
|
||||
CBS in;
|
||||
|
||||
if (depth > kMaxDepth) {
|
||||
@@ -68,14 +68,11 @@ static int cbs_find_ber(const CBS *orig_in, char *ber_found, unsigned depth) {
|
||||
unsigned tag;
|
||||
size_t header_len;
|
||||
|
||||
if (!CBS_get_any_ber_asn1_element(&in, &contents, &tag, &header_len)) {
|
||||
if (!CBS_get_any_ber_asn1_element(&in, &contents, &tag, &header_len,
|
||||
ber_found)) {
|
||||
return 0;
|
||||
}
|
||||
if (CBS_len(&contents) == header_len &&
|
||||
header_len > 0 &&
|
||||
CBS_data(&contents)[header_len-1] == 0x80) {
|
||||
// Found an indefinite-length element.
|
||||
*ber_found = 1;
|
||||
if (*ber_found) {
|
||||
return 1;
|
||||
}
|
||||
if (tag & CBS_ASN1_CONSTRUCTED) {
|
||||
@@ -120,9 +117,11 @@ static int cbs_convert_ber(CBS *in, CBB *out, unsigned string_tag,
|
||||
CBS contents;
|
||||
unsigned tag, child_string_tag = string_tag;
|
||||
size_t header_len;
|
||||
int ber_found;
|
||||
CBB *out_contents, out_contents_storage;
|
||||
|
||||
if (!CBS_get_any_ber_asn1_element(in, &contents, &tag, &header_len)) {
|
||||
if (!CBS_get_any_ber_asn1_element(in, &contents, &tag, &header_len,
|
||||
&ber_found)) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -194,7 +193,7 @@ int CBS_asn1_ber_to_der(CBS *in, CBS *out, uint8_t **out_storage) {
|
||||
|
||||
// First, do a quick walk to find any indefinite-length elements. Most of the
|
||||
// time we hope that there aren't any and thus we can quickly return.
|
||||
char conversion_needed;
|
||||
int conversion_needed;
|
||||
if (!cbs_find_ber(in, &conversion_needed, 0)) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -254,8 +254,7 @@ static int parse_asn1_tag(CBS *cbs, unsigned *out) {
|
||||
//
|
||||
// If the number portion is 31 (0x1f, the largest value that fits in the
|
||||
// allotted bits), then the tag is more than one byte long and the
|
||||
// continuation bytes contain the tag number. This parser only supports tag
|
||||
// numbers less than 31 (and thus single-byte tags).
|
||||
// continuation bytes contain the tag number.
|
||||
unsigned tag = ((unsigned)tag_byte & 0xe0) << CBS_ASN1_TAG_SHIFT;
|
||||
unsigned tag_number = tag_byte & 0x1f;
|
||||
if (tag_number == 0x1f) {
|
||||
@@ -263,7 +262,7 @@ static int parse_asn1_tag(CBS *cbs, unsigned *out) {
|
||||
if (!parse_base128_integer(cbs, &v) ||
|
||||
// Check the tag number is within our supported bounds.
|
||||
v > CBS_ASN1_TAG_NUMBER_MASK ||
|
||||
// Small tag numbers should have used low tag number form.
|
||||
// Small tag numbers should have used low tag number form, even in BER.
|
||||
v < 0x1f) {
|
||||
return 0;
|
||||
}
|
||||
@@ -277,13 +276,17 @@ static int parse_asn1_tag(CBS *cbs, unsigned *out) {
|
||||
}
|
||||
|
||||
static int cbs_get_any_asn1_element(CBS *cbs, CBS *out, unsigned *out_tag,
|
||||
size_t *out_header_len, int ber_ok) {
|
||||
size_t *out_header_len, int *out_ber_found,
|
||||
int ber_ok) {
|
||||
CBS header = *cbs;
|
||||
CBS throwaway;
|
||||
|
||||
if (out == NULL) {
|
||||
out = &throwaway;
|
||||
}
|
||||
if (ber_ok) {
|
||||
*out_ber_found = 0;
|
||||
}
|
||||
|
||||
unsigned tag;
|
||||
if (!parse_asn1_tag(&header, &tag)) {
|
||||
@@ -321,27 +324,38 @@ static int cbs_get_any_asn1_element(CBS *cbs, CBS *out, unsigned *out_tag,
|
||||
if (out_header_len != NULL) {
|
||||
*out_header_len = header_len;
|
||||
}
|
||||
*out_ber_found = 1;
|
||||
return CBS_get_bytes(cbs, out, header_len);
|
||||
}
|
||||
|
||||
// ITU-T X.690 clause 8.1.3.5.c specifies that the value 0xff shall not be
|
||||
// used as the first byte of the length. If this parser encounters that
|
||||
// value, num_bytes will be parsed as 127, which will fail the check below.
|
||||
// value, num_bytes will be parsed as 127, which will fail this check.
|
||||
if (num_bytes == 0 || num_bytes > 4) {
|
||||
return 0;
|
||||
}
|
||||
if (!cbs_get_u(&header, &len64, num_bytes)) {
|
||||
return 0;
|
||||
}
|
||||
// ITU-T X.690 section 10.1 (DER length forms) requires encoding the length
|
||||
// with the minimum number of octets.
|
||||
// ITU-T X.690 section 10.1 (DER length forms) requires encoding the
|
||||
// length with the minimum number of octets. BER could, technically, have
|
||||
// 125 superfluous zero bytes. We do not attempt to handle that and still
|
||||
// require that the length fit in a |uint32_t| for BER.
|
||||
if (len64 < 128) {
|
||||
// Length should have used short-form encoding.
|
||||
return 0;
|
||||
if (ber_ok) {
|
||||
*out_ber_found = 1;
|
||||
} else {
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
if ((len64 >> ((num_bytes-1)*8)) == 0) {
|
||||
if ((len64 >> ((num_bytes - 1) * 8)) == 0) {
|
||||
// Length should have been at least one byte shorter.
|
||||
return 0;
|
||||
if (ber_ok) {
|
||||
*out_ber_found = 1;
|
||||
} else {
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
len = len64;
|
||||
if (len + header_len + num_bytes < len) {
|
||||
@@ -374,13 +388,15 @@ int CBS_get_any_asn1(CBS *cbs, CBS *out, unsigned *out_tag) {
|
||||
int CBS_get_any_asn1_element(CBS *cbs, CBS *out, unsigned *out_tag,
|
||||
size_t *out_header_len) {
|
||||
return cbs_get_any_asn1_element(cbs, out, out_tag, out_header_len,
|
||||
0 /* DER only */);
|
||||
NULL, 0 /* DER only */);
|
||||
}
|
||||
|
||||
int CBS_get_any_ber_asn1_element(CBS *cbs, CBS *out, unsigned *out_tag,
|
||||
size_t *out_header_len) {
|
||||
return cbs_get_any_asn1_element(cbs, out, out_tag, out_header_len,
|
||||
1 /* BER allowed */);
|
||||
size_t *out_header_len, int *out_ber_found) {
|
||||
int ber_found_temp;
|
||||
return cbs_get_any_asn1_element(
|
||||
cbs, out, out_tag, out_header_len,
|
||||
out_ber_found ? out_ber_found : &ber_found_temp, 1 /* BER allowed */);
|
||||
}
|
||||
|
||||
static int cbs_get_asn1(CBS *cbs, CBS *out, unsigned tag_value,
|
||||
|
||||
@@ -17,6 +17,7 @@
|
||||
#include <CCryptoBoringSSL_arm_arch.h>
|
||||
|
||||
|
||||
.private_extern _OPENSSL_armcap_P
|
||||
|
||||
.section __TEXT,__const
|
||||
|
||||
|
||||
@@ -18,6 +18,7 @@
|
||||
#include <CCryptoBoringSSL_arm_arch.h>
|
||||
|
||||
|
||||
.hidden OPENSSL_armcap_P
|
||||
|
||||
.section .rodata
|
||||
|
||||
|
||||
+1915
-1980
File diff suppressed because it is too large.
Load diff
+1870
-1977
File diff suppressed because it is too large.
Load diff
@@ -18,18 +18,15 @@
|
||||
|
||||
#include <CCryptoBoringSSL_chacha.h>
|
||||
#include <CCryptoBoringSSL_cipher.h>
|
||||
#include <CCryptoBoringSSL_cpu.h>
|
||||
#include <CCryptoBoringSSL_err.h>
|
||||
#include <CCryptoBoringSSL_mem.h>
|
||||
#include <CCryptoBoringSSL_poly1305.h>
|
||||
#include <CCryptoBoringSSL_type_check.h>
|
||||
|
||||
#include "internal.h"
|
||||
#include "../chacha/internal.h"
|
||||
#include "../fipsmodule/cipher/internal.h"
|
||||
#include "../internal.h"
|
||||
#include "../chacha/internal.h"
|
||||
|
||||
|
||||
#define POLY1305_TAG_LEN 16
|
||||
|
||||
struct aead_chacha20_poly1305_ctx {
|
||||
uint8_t key[32];
|
||||
@@ -44,78 +41,6 @@ OPENSSL_STATIC_ASSERT(alignof(union evp_aead_ctx_st_state) >=
|
||||
"AEAD state has insufficient alignment");
|
||||
#endif
|
||||
|
||||
// For convenience (the x86_64 calling convention allows only six parameters in
|
||||
// registers), the final parameter for the assembly functions is both an input
|
||||
// and output parameter.
|
||||
union open_data {
|
||||
struct {
|
||||
alignas(16) uint8_t key[32];
|
||||
uint32_t counter;
|
||||
uint8_t nonce[12];
|
||||
} in;
|
||||
struct {
|
||||
uint8_t tag[POLY1305_TAG_LEN];
|
||||
} out;
|
||||
};
|
||||
|
||||
union seal_data {
|
||||
struct {
|
||||
alignas(16) uint8_t key[32];
|
||||
uint32_t counter;
|
||||
uint8_t nonce[12];
|
||||
const uint8_t *extra_ciphertext;
|
||||
size_t extra_ciphertext_len;
|
||||
} in;
|
||||
struct {
|
||||
uint8_t tag[POLY1305_TAG_LEN];
|
||||
} out;
|
||||
};
|
||||
|
||||
#if defined(OPENSSL_X86_64) && !defined(OPENSSL_NO_ASM) && \
|
||||
!defined(OPENSSL_WINDOWS)
|
||||
static int asm_capable(void) {
|
||||
const int sse41_capable = (OPENSSL_ia32cap_P[1] & (1 << 19)) != 0;
|
||||
return sse41_capable;
|
||||
}
|
||||
|
||||
OPENSSL_STATIC_ASSERT(sizeof(union open_data) == 48, "wrong open_data size");
|
||||
OPENSSL_STATIC_ASSERT(sizeof(union seal_data) == 48 + 8 + 8,
|
||||
"wrong seal_data size");
|
||||
|
||||
// chacha20_poly1305_open is defined in chacha20_poly1305_x86_64.pl. It decrypts
|
||||
// |plaintext_len| bytes from |ciphertext| and writes them to |out_plaintext|.
|
||||
// Additional input parameters are passed in |aead_data->in|. On exit, it will
|
||||
// write calculated tag value to |aead_data->out.tag|, which the caller must
|
||||
// check.
|
||||
extern void chacha20_poly1305_open(uint8_t *out_plaintext,
|
||||
const uint8_t *ciphertext,
|
||||
size_t plaintext_len, const uint8_t *ad,
|
||||
size_t ad_len, union open_data *aead_data);
|
||||
|
||||
// chacha20_poly1305_open is defined in chacha20_poly1305_x86_64.pl. It encrypts
|
||||
// |plaintext_len| bytes from |plaintext| and writes them to |out_ciphertext|.
|
||||
// Additional input parameters are passed in |aead_data->in|. The calculated tag
|
||||
// value is over the computed ciphertext concatenated with |extra_ciphertext|
|
||||
// and written to |aead_data->out.tag|.
|
||||
extern void chacha20_poly1305_seal(uint8_t *out_ciphertext,
|
||||
const uint8_t *plaintext,
|
||||
size_t plaintext_len, const uint8_t *ad,
|
||||
size_t ad_len, union seal_data *aead_data);
|
||||
#else
|
||||
static int asm_capable(void) { return 0; }
|
||||
|
||||
|
||||
static void chacha20_poly1305_open(uint8_t *out_plaintext,
|
||||
const uint8_t *ciphertext,
|
||||
size_t plaintext_len, const uint8_t *ad,
|
||||
size_t ad_len, union open_data *aead_data) {}
|
||||
|
||||
static void chacha20_poly1305_seal(uint8_t *out_ciphertext,
|
||||
const uint8_t *plaintext,
|
||||
size_t plaintext_len, const uint8_t *ad,
|
||||
size_t ad_len, union seal_data *aead_data) {}
|
||||
#endif
|
||||
|
||||
static int aead_chacha20_poly1305_init(EVP_AEAD_CTX *ctx, const uint8_t *key,
|
||||
size_t key_len, size_t tag_len) {
|
||||
struct aead_chacha20_poly1305_ctx *c20_ctx =
|
||||
@@ -238,8 +163,8 @@ static int chacha20_poly1305_seal_scatter(
|
||||
}
|
||||
}
|
||||
|
||||
union seal_data data;
|
||||
if (asm_capable()) {
|
||||
union chacha20_poly1305_seal_data data;
|
||||
if (chacha20_poly1305_asm_capable()) {
|
||||
OPENSSL_memcpy(data.in.key, key, 32);
|
||||
data.in.counter = 0;
|
||||
OPENSSL_memcpy(data.in.nonce, nonce, 12);
|
||||
@@ -321,8 +246,8 @@ static int chacha20_poly1305_open_gather(
|
||||
return 0;
|
||||
}
|
||||
|
||||
union open_data data;
|
||||
if (asm_capable()) {
|
||||
union chacha20_poly1305_open_data data;
|
||||
if (chacha20_poly1305_asm_capable()) {
|
||||
OPENSSL_memcpy(data.in.key, key, 32);
|
||||
data.in.counter = 0;
|
||||
OPENSSL_memcpy(data.in.nonce, nonce, 12);
|
||||
|
||||
@@ -57,7 +57,11 @@
|
||||
#ifndef OPENSSL_HEADER_CIPHER_EXTRA_INTERNAL_H
|
||||
#define OPENSSL_HEADER_CIPHER_EXTRA_INTERNAL_H
|
||||
|
||||
#include <stdlib.h>
|
||||
|
||||
#include <CCryptoBoringSSL_base.h>
|
||||
#include <CCryptoBoringSSL_cpu.h>
|
||||
#include <CCryptoBoringSSL_type_check.h>
|
||||
|
||||
#include "../internal.h"
|
||||
|
||||
@@ -120,6 +124,89 @@ int EVP_tls_cbc_digest_record(const EVP_MD *md, uint8_t *md_out,
|
||||
const uint8_t *mac_secret,
|
||||
unsigned mac_secret_length);
|
||||
|
||||
#define POLY1305_TAG_LEN 16
|
||||
|
||||
// For convenience (the x86_64 calling convention allows only six parameters in
|
||||
// registers), the final parameter for the assembly functions is both an input
|
||||
// and output parameter.
|
||||
union chacha20_poly1305_open_data {
|
||||
struct {
|
||||
alignas(16) uint8_t key[32];
|
||||
uint32_t counter;
|
||||
uint8_t nonce[12];
|
||||
} in;
|
||||
struct {
|
||||
uint8_t tag[POLY1305_TAG_LEN];
|
||||
} out;
|
||||
};
|
||||
|
||||
union chacha20_poly1305_seal_data {
|
||||
struct {
|
||||
alignas(16) uint8_t key[32];
|
||||
uint32_t counter;
|
||||
uint8_t nonce[12];
|
||||
const uint8_t *extra_ciphertext;
|
||||
size_t extra_ciphertext_len;
|
||||
} in;
|
||||
struct {
|
||||
uint8_t tag[POLY1305_TAG_LEN];
|
||||
} out;
|
||||
};
|
||||
|
||||
#if defined(OPENSSL_X86_64) && !defined(OPENSSL_NO_ASM)
|
||||
|
||||
OPENSSL_STATIC_ASSERT(sizeof(union chacha20_poly1305_open_data) == 48,
|
||||
"wrong chacha20_poly1305_open_data size");
|
||||
OPENSSL_STATIC_ASSERT(sizeof(union chacha20_poly1305_seal_data) == 48 + 8 + 8,
|
||||
"wrong chacha20_poly1305_seal_data size");
|
||||
|
||||
OPENSSL_INLINE int chacha20_poly1305_asm_capable(void) {
|
||||
const int sse41_capable = (OPENSSL_ia32cap_P[1] & (1 << 19)) != 0;
|
||||
return sse41_capable;
|
||||
}
|
||||
|
||||
// chacha20_poly1305_open is defined in chacha20_poly1305_x86_64.pl. It decrypts
|
||||
// |plaintext_len| bytes from |ciphertext| and writes them to |out_plaintext|.
|
||||
// Additional input parameters are passed in |aead_data->in|. On exit, it will
|
||||
// write calculated tag value to |aead_data->out.tag|, which the caller must
|
||||
// check.
|
||||
extern void chacha20_poly1305_open(uint8_t *out_plaintext,
|
||||
const uint8_t *ciphertext,
|
||||
size_t plaintext_len, const uint8_t *ad,
|
||||
size_t ad_len,
|
||||
union chacha20_poly1305_open_data *data);
|
||||
|
||||
// chacha20_poly1305_open is defined in chacha20_poly1305_x86_64.pl. It encrypts
|
||||
// |plaintext_len| bytes from |plaintext| and writes them to |out_ciphertext|.
|
||||
// Additional input parameters are passed in |aead_data->in|. The calculated tag
|
||||
// value is over the computed ciphertext concatenated with |extra_ciphertext|
|
||||
// and written to |aead_data->out.tag|.
|
||||
extern void chacha20_poly1305_seal(uint8_t *out_ciphertext,
|
||||
const uint8_t *plaintext,
|
||||
size_t plaintext_len, const uint8_t *ad,
|
||||
size_t ad_len,
|
||||
union chacha20_poly1305_seal_data *data);
|
||||
#else
|
||||
|
||||
OPENSSL_INLINE int chacha20_poly1305_asm_capable(void) { return 0; }
|
||||
|
||||
OPENSSL_INLINE void chacha20_poly1305_open(uint8_t *out_plaintext,
|
||||
const uint8_t *ciphertext,
|
||||
size_t plaintext_len, const uint8_t *ad,
|
||||
size_t ad_len,
|
||||
union chacha20_poly1305_open_data *data) {
|
||||
abort();
|
||||
}
|
||||
|
||||
OPENSSL_INLINE void chacha20_poly1305_seal(uint8_t *out_ciphertext,
|
||||
const uint8_t *plaintext,
|
||||
size_t plaintext_len, const uint8_t *ad,
|
||||
size_t ad_len,
|
||||
union chacha20_poly1305_seal_data *data) {
|
||||
abort();
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
#if defined(__cplusplus)
|
||||
} // extern C
|
||||
|
||||
@@ -0,0 +1,41 @@
|
||||
/* Copyright (c) 2018, Google Inc.
|
||||
* Copyright (c) 2020, Arm Ltd.
|
||||
*
|
||||
* Permission to use, copy, modify, and/or distribute this software for any
|
||||
* purpose with or without fee is hereby granted, provided that the above
|
||||
* copyright notice and this permission notice appear in all copies.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
|
||||
* WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
|
||||
* MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
|
||||
* SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
|
||||
* WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION
|
||||
* OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
|
||||
* CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. */
|
||||
|
||||
#include <CCryptoBoringSSL_cpu.h>
|
||||
|
||||
#if defined(OPENSSL_AARCH64) && defined(OPENSSL_WINDOWS) && \
|
||||
!defined(OPENSSL_STATIC_ARMCAP)
|
||||
|
||||
#include <windows.h>
|
||||
|
||||
#include <CCryptoBoringSSL_arm_arch.h>
|
||||
|
||||
#include "internal.h"
|
||||
|
||||
extern uint32_t OPENSSL_armcap_P;
|
||||
void OPENSSL_cpuid_setup(void) {
|
||||
// We do not need to check for the presence of NEON, as Armv8-A always has it
|
||||
OPENSSL_armcap_P |= ARMV7_NEON;
|
||||
|
||||
if (IsProcessorFeaturePresent(PF_ARM_V8_CRYPTO_INSTRUCTIONS_AVAILABLE)) {
|
||||
// These are all covered by one call in Windows
|
||||
OPENSSL_armcap_P |= ARMV8_AES;
|
||||
OPENSSL_armcap_P |= ARMV8_PMULL;
|
||||
OPENSSL_armcap_P |= ARMV8_SHA1;
|
||||
OPENSSL_armcap_P |= ARMV8_SHA256;
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
||||
File renamed without changes.
+179
@@ -53,6 +53,8 @@
|
||||
#include <CCryptoBoringSSL_dh.h>
|
||||
|
||||
#include <CCryptoBoringSSL_bn.h>
|
||||
#include <CCryptoBoringSSL_err.h>
|
||||
#include <CCryptoBoringSSL_mem.h>
|
||||
|
||||
#include "../fipsmodule/bn/internal.h"
|
||||
|
||||
@@ -91,3 +93,180 @@ BIGNUM *BN_get_rfc3526_prime_1536(BIGNUM *ret) {
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
int DH_generate_parameters_ex(DH *dh, int prime_bits, int generator,
|
||||
BN_GENCB *cb) {
|
||||
// We generate DH parameters as follows
|
||||
// find a prime q which is prime_bits/2 bits long.
|
||||
// p=(2*q)+1 or (p-1)/2 = q
|
||||
// For this case, g is a generator if
|
||||
// g^((p-1)/q) mod p != 1 for values of q which are the factors of p-1.
|
||||
// Since the factors of p-1 are q and 2, we just need to check
|
||||
// g^2 mod p != 1 and g^q mod p != 1.
|
||||
//
|
||||
// Having said all that,
|
||||
// there is another special case method for the generators 2, 3 and 5.
|
||||
// for 2, p mod 24 == 11
|
||||
// for 3, p mod 12 == 5 <<<<< does not work for safe primes.
|
||||
// for 5, p mod 10 == 3 or 7
|
||||
//
|
||||
// Thanks to Phil Karn <karn@qualcomm.com> for the pointers about the
|
||||
// special generators and for answering some of my questions.
|
||||
//
|
||||
// I've implemented the second simple method :-).
|
||||
// Since DH should be using a safe prime (both p and q are prime),
|
||||
// this generator function can take a very very long time to run.
|
||||
|
||||
// Actually there is no reason to insist that 'generator' be a generator.
|
||||
// It's just as OK (and in some sense better) to use a generator of the
|
||||
// order-q subgroup.
|
||||
|
||||
BIGNUM *t1, *t2;
|
||||
int g, ok = 0;
|
||||
BN_CTX *ctx = NULL;
|
||||
|
||||
ctx = BN_CTX_new();
|
||||
if (ctx == NULL) {
|
||||
goto err;
|
||||
}
|
||||
BN_CTX_start(ctx);
|
||||
t1 = BN_CTX_get(ctx);
|
||||
t2 = BN_CTX_get(ctx);
|
||||
if (t1 == NULL || t2 == NULL) {
|
||||
goto err;
|
||||
}
|
||||
|
||||
// Make sure |dh| has the necessary elements
|
||||
if (dh->p == NULL) {
|
||||
dh->p = BN_new();
|
||||
if (dh->p == NULL) {
|
||||
goto err;
|
||||
}
|
||||
}
|
||||
if (dh->g == NULL) {
|
||||
dh->g = BN_new();
|
||||
if (dh->g == NULL) {
|
||||
goto err;
|
||||
}
|
||||
}
|
||||
|
||||
if (generator <= 1) {
|
||||
OPENSSL_PUT_ERROR(DH, DH_R_BAD_GENERATOR);
|
||||
goto err;
|
||||
}
|
||||
if (generator == DH_GENERATOR_2) {
|
||||
if (!BN_set_word(t1, 24)) {
|
||||
goto err;
|
||||
}
|
||||
if (!BN_set_word(t2, 11)) {
|
||||
goto err;
|
||||
}
|
||||
g = 2;
|
||||
} else if (generator == DH_GENERATOR_5) {
|
||||
if (!BN_set_word(t1, 10)) {
|
||||
goto err;
|
||||
}
|
||||
if (!BN_set_word(t2, 3)) {
|
||||
goto err;
|
||||
}
|
||||
// BN_set_word(t3,7); just have to miss
|
||||
// out on these ones :-(
|
||||
g = 5;
|
||||
} else {
|
||||
// in the general case, don't worry if 'generator' is a
|
||||
// generator or not: since we are using safe primes,
|
||||
// it will generate either an order-q or an order-2q group,
|
||||
// which both is OK
|
||||
if (!BN_set_word(t1, 2)) {
|
||||
goto err;
|
||||
}
|
||||
if (!BN_set_word(t2, 1)) {
|
||||
goto err;
|
||||
}
|
||||
g = generator;
|
||||
}
|
||||
|
||||
if (!BN_generate_prime_ex(dh->p, prime_bits, 1, t1, t2, cb)) {
|
||||
goto err;
|
||||
}
|
||||
if (!BN_GENCB_call(cb, 3, 0)) {
|
||||
goto err;
|
||||
}
|
||||
if (!BN_set_word(dh->g, g)) {
|
||||
goto err;
|
||||
}
|
||||
ok = 1;
|
||||
|
||||
err:
|
||||
if (!ok) {
|
||||
OPENSSL_PUT_ERROR(DH, ERR_R_BN_LIB);
|
||||
}
|
||||
|
||||
if (ctx != NULL) {
|
||||
BN_CTX_end(ctx);
|
||||
BN_CTX_free(ctx);
|
||||
}
|
||||
return ok;
|
||||
}
|
||||
|
||||
static int int_dh_bn_cpy(BIGNUM **dst, const BIGNUM *src) {
|
||||
BIGNUM *a = NULL;
|
||||
|
||||
if (src) {
|
||||
a = BN_dup(src);
|
||||
if (!a) {
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
BN_free(*dst);
|
||||
*dst = a;
|
||||
return 1;
|
||||
}
|
||||
|
||||
static int int_dh_param_copy(DH *to, const DH *from, int is_x942) {
|
||||
if (is_x942 == -1) {
|
||||
is_x942 = !!from->q;
|
||||
}
|
||||
if (!int_dh_bn_cpy(&to->p, from->p) ||
|
||||
!int_dh_bn_cpy(&to->g, from->g)) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (!is_x942) {
|
||||
return 1;
|
||||
}
|
||||
|
||||
if (!int_dh_bn_cpy(&to->q, from->q) ||
|
||||
!int_dh_bn_cpy(&to->j, from->j)) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
OPENSSL_free(to->seed);
|
||||
to->seed = NULL;
|
||||
to->seedlen = 0;
|
||||
|
||||
if (from->seed) {
|
||||
to->seed = OPENSSL_memdup(from->seed, from->seedlen);
|
||||
if (!to->seed) {
|
||||
return 0;
|
||||
}
|
||||
to->seedlen = from->seedlen;
|
||||
}
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
DH *DHparams_dup(const DH *dh) {
|
||||
DH *ret = DH_new();
|
||||
if (!ret) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
if (!int_dh_param_copy(ret, dh, -1)) {
|
||||
DH_free(ret);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
@@ -59,10 +59,12 @@
|
||||
#include <string.h>
|
||||
|
||||
#include <CCryptoBoringSSL_asn1.h>
|
||||
#include <CCryptoBoringSSL_blake2.h>
|
||||
#include <CCryptoBoringSSL_bytestring.h>
|
||||
#include <CCryptoBoringSSL_nid.h>
|
||||
|
||||
#include "../internal.h"
|
||||
#include "../fipsmodule/digest/internal.h"
|
||||
|
||||
|
||||
struct nid_to_digest {
|
||||
@@ -238,3 +240,26 @@ const EVP_MD *EVP_get_digestbyname(const char *name) {
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
static void blake2b256_init(EVP_MD_CTX *ctx) { BLAKE2B256_Init(ctx->md_data); }
|
||||
|
||||
static void blake2b256_update(EVP_MD_CTX *ctx, const void *data, size_t len) {
|
||||
BLAKE2B256_Update(ctx->md_data, data, len);
|
||||
}
|
||||
|
||||
static void blake2b256_final(EVP_MD_CTX *ctx, uint8_t *md) {
|
||||
BLAKE2B256_Final(md, ctx->md_data);
|
||||
}
|
||||
|
||||
static const EVP_MD evp_md_blake2b256 = {
|
||||
NID_undef,
|
||||
BLAKE2B256_DIGEST_LENGTH,
|
||||
0,
|
||||
blake2b256_init,
|
||||
blake2b256_update,
|
||||
blake2b256_final,
|
||||
BLAKE2B_CBLOCK,
|
||||
sizeof(BLAKE2B_CTX),
|
||||
};
|
||||
|
||||
const EVP_MD *EVP_blake2b256(void) { return &evp_md_blake2b256; }
|
||||
File diff suppressed because it is too large.
Load diff
@@ -632,20 +632,34 @@ _aes_hw_ctr32_encrypt_blocks:
|
||||
add r7,r3,#32
|
||||
mov r6,r5
|
||||
movlo r12,#0
|
||||
|
||||
@ ARM Cortex-A57 and Cortex-A72 cores running in 32-bit mode are
|
||||
@ affected by silicon errata #1742098 [0] and #1655431 [1],
|
||||
@ respectively, where the second instruction of an aese/aesmc
|
||||
@ instruction pair may execute twice if an interrupt is taken right
|
||||
@ after the first instruction consumes an input register of which a
|
||||
@ single 32-bit lane has been updated the last time it was modified.
|
||||
@
|
||||
@ This function uses a counter in one 32-bit lane. The
|
||||
@ could write to q1 and q10 directly, but that trips this bugs.
|
||||
@ We write to q6 and copy to the final register as a workaround.
|
||||
@
|
||||
@ [0] ARM-EPM-049219 v23 Cortex-A57 MPCore Software Developers Errata Notice
|
||||
@ [1] ARM-EPM-012079 v11.0 Cortex-A72 MPCore Software Developers Errata Notice
|
||||
#ifndef __ARMEB__
|
||||
rev r8, r8
|
||||
#endif
|
||||
vorr q1,q0,q0
|
||||
add r10, r8, #1
|
||||
vorr q10,q0,q0
|
||||
add r8, r8, #2
|
||||
vorr q6,q0,q0
|
||||
rev r10, r10
|
||||
vmov.32 d3[1],r10
|
||||
vmov.32 d13[1],r10
|
||||
add r8, r8, #2
|
||||
vorr q1,q6,q6
|
||||
bls Lctr32_tail
|
||||
rev r12, r8
|
||||
vmov.32 d13[1],r12
|
||||
sub r2,r2,#3 @ bias
|
||||
vmov.32 d21[1],r12
|
||||
vorr q10,q6,q6
|
||||
b Loop3x_ctr32
|
||||
|
||||
.align 4
|
||||
@@ -672,11 +686,11 @@ Loop3x_ctr32:
|
||||
.byte 0x20,0x23,0xb0,0xf3 @ aese q1,q8
|
||||
.byte 0x82,0xa3,0xb0,0xf3 @ aesmc q5,q1
|
||||
vld1.8 {q2},[r0]!
|
||||
vorr q0,q6,q6
|
||||
add r9,r8,#1
|
||||
.byte 0x20,0x43,0xf0,0xf3 @ aese q10,q8
|
||||
.byte 0xa4,0x43,0xf0,0xf3 @ aesmc q10,q10
|
||||
vld1.8 {q3},[r0]!
|
||||
vorr q1,q6,q6
|
||||
rev r9,r9
|
||||
.byte 0x22,0x83,0xb0,0xf3 @ aese q4,q9
|
||||
.byte 0x88,0x83,0xb0,0xf3 @ aesmc q4,q4
|
||||
.byte 0x22,0xa3,0xb0,0xf3 @ aese q5,q9
|
||||
@@ -685,8 +699,6 @@ Loop3x_ctr32:
|
||||
mov r7,r3
|
||||
.byte 0x22,0x43,0xf0,0xf3 @ aese q10,q9
|
||||
.byte 0xa4,0x23,0xf0,0xf3 @ aesmc q9,q10
|
||||
vorr q10,q6,q6
|
||||
add r9,r8,#1
|
||||
.byte 0x28,0x83,0xb0,0xf3 @ aese q4,q12
|
||||
.byte 0x88,0x83,0xb0,0xf3 @ aesmc q4,q4
|
||||
.byte 0x28,0xa3,0xb0,0xf3 @ aese q5,q12
|
||||
@@ -701,21 +713,26 @@ Loop3x_ctr32:
|
||||
.byte 0x88,0x83,0xb0,0xf3 @ aesmc q4,q4
|
||||
.byte 0x2a,0xa3,0xb0,0xf3 @ aese q5,q13
|
||||
.byte 0x8a,0xa3,0xb0,0xf3 @ aesmc q5,q5
|
||||
@ Note the logic to update q0, q1, and q1 is written to work
|
||||
@ around a bug in ARM Cortex-A57 and Cortex-A72 cores running in
|
||||
@ 32-bit mode. See the comment above.
|
||||
veor q11,q11,q7
|
||||
rev r9,r9
|
||||
vmov.32 d13[1], r9
|
||||
.byte 0x2a,0x23,0xf0,0xf3 @ aese q9,q13
|
||||
.byte 0xa2,0x23,0xf0,0xf3 @ aesmc q9,q9
|
||||
vmov.32 d1[1], r9
|
||||
vorr q0,q6,q6
|
||||
rev r10,r10
|
||||
.byte 0x2c,0x83,0xb0,0xf3 @ aese q4,q14
|
||||
.byte 0x88,0x83,0xb0,0xf3 @ aesmc q4,q4
|
||||
vmov.32 d13[1], r10
|
||||
rev r12,r8
|
||||
.byte 0x2c,0xa3,0xb0,0xf3 @ aese q5,q14
|
||||
.byte 0x8a,0xa3,0xb0,0xf3 @ aesmc q5,q5
|
||||
vmov.32 d3[1], r10
|
||||
rev r12,r8
|
||||
vorr q1,q6,q6
|
||||
vmov.32 d13[1], r12
|
||||
.byte 0x2c,0x23,0xf0,0xf3 @ aese q9,q14
|
||||
.byte 0xa2,0x23,0xf0,0xf3 @ aesmc q9,q9
|
||||
vmov.32 d21[1], r12
|
||||
vorr q10,q6,q6
|
||||
subs r2,r2,#3
|
||||
.byte 0x2e,0x83,0xb0,0xf3 @ aese q4,q15
|
||||
.byte 0x2e,0xa3,0xb0,0xf3 @ aese q5,q15
|
||||
|
||||
@@ -621,20 +621,34 @@ aes_hw_ctr32_encrypt_blocks:
|
||||
add r7,r3,#32
|
||||
mov r6,r5
|
||||
movlo r12,#0
|
||||
|
||||
@ ARM Cortex-A57 and Cortex-A72 cores running in 32-bit mode are
|
||||
@ affected by silicon errata #1742098 [0] and #1655431 [1],
|
||||
@ respectively, where the second instruction of an aese/aesmc
|
||||
@ instruction pair may execute twice if an interrupt is taken right
|
||||
@ after the first instruction consumes an input register of which a
|
||||
@ single 32-bit lane has been updated the last time it was modified.
|
||||
@
|
||||
@ This function uses a counter in one 32-bit lane. The
|
||||
@ could write to q1 and q10 directly, but that trips this bugs.
|
||||
@ We write to q6 and copy to the final register as a workaround.
|
||||
@
|
||||
@ [0] ARM-EPM-049219 v23 Cortex-A57 MPCore Software Developers Errata Notice
|
||||
@ [1] ARM-EPM-012079 v11.0 Cortex-A72 MPCore Software Developers Errata Notice
|
||||
#ifndef __ARMEB__
|
||||
rev r8, r8
|
||||
#endif
|
||||
vorr q1,q0,q0
|
||||
add r10, r8, #1
|
||||
vorr q10,q0,q0
|
||||
add r8, r8, #2
|
||||
vorr q6,q0,q0
|
||||
rev r10, r10
|
||||
vmov.32 d3[1],r10
|
||||
vmov.32 d13[1],r10
|
||||
add r8, r8, #2
|
||||
vorr q1,q6,q6
|
||||
bls .Lctr32_tail
|
||||
rev r12, r8
|
||||
vmov.32 d13[1],r12
|
||||
sub r2,r2,#3 @ bias
|
||||
vmov.32 d21[1],r12
|
||||
vorr q10,q6,q6
|
||||
b .Loop3x_ctr32
|
||||
|
||||
.align 4
|
||||
@@ -661,11 +675,11 @@ aes_hw_ctr32_encrypt_blocks:
|
||||
.byte 0x20,0x23,0xb0,0xf3 @ aese q1,q8
|
||||
.byte 0x82,0xa3,0xb0,0xf3 @ aesmc q5,q1
|
||||
vld1.8 {q2},[r0]!
|
||||
vorr q0,q6,q6
|
||||
add r9,r8,#1
|
||||
.byte 0x20,0x43,0xf0,0xf3 @ aese q10,q8
|
||||
.byte 0xa4,0x43,0xf0,0xf3 @ aesmc q10,q10
|
||||
vld1.8 {q3},[r0]!
|
||||
vorr q1,q6,q6
|
||||
rev r9,r9
|
||||
.byte 0x22,0x83,0xb0,0xf3 @ aese q4,q9
|
||||
.byte 0x88,0x83,0xb0,0xf3 @ aesmc q4,q4
|
||||
.byte 0x22,0xa3,0xb0,0xf3 @ aese q5,q9
|
||||
@@ -674,8 +688,6 @@ aes_hw_ctr32_encrypt_blocks:
|
||||
mov r7,r3
|
||||
.byte 0x22,0x43,0xf0,0xf3 @ aese q10,q9
|
||||
.byte 0xa4,0x23,0xf0,0xf3 @ aesmc q9,q10
|
||||
vorr q10,q6,q6
|
||||
add r9,r8,#1
|
||||
.byte 0x28,0x83,0xb0,0xf3 @ aese q4,q12
|
||||
.byte 0x88,0x83,0xb0,0xf3 @ aesmc q4,q4
|
||||
.byte 0x28,0xa3,0xb0,0xf3 @ aese q5,q12
|
||||
@@ -690,21 +702,26 @@ aes_hw_ctr32_encrypt_blocks:
|
||||
.byte 0x88,0x83,0xb0,0xf3 @ aesmc q4,q4
|
||||
.byte 0x2a,0xa3,0xb0,0xf3 @ aese q5,q13
|
||||
.byte 0x8a,0xa3,0xb0,0xf3 @ aesmc q5,q5
|
||||
@ Note the logic to update q0, q1, and q1 is written to work
|
||||
@ around a bug in ARM Cortex-A57 and Cortex-A72 cores running in
|
||||
@ 32-bit mode. See the comment above.
|
||||
veor q11,q11,q7
|
||||
rev r9,r9
|
||||
vmov.32 d13[1], r9
|
||||
.byte 0x2a,0x23,0xf0,0xf3 @ aese q9,q13
|
||||
.byte 0xa2,0x23,0xf0,0xf3 @ aesmc q9,q9
|
||||
vmov.32 d1[1], r9
|
||||
vorr q0,q6,q6
|
||||
rev r10,r10
|
||||
.byte 0x2c,0x83,0xb0,0xf3 @ aese q4,q14
|
||||
.byte 0x88,0x83,0xb0,0xf3 @ aesmc q4,q4
|
||||
vmov.32 d13[1], r10
|
||||
rev r12,r8
|
||||
.byte 0x2c,0xa3,0xb0,0xf3 @ aese q5,q14
|
||||
.byte 0x8a,0xa3,0xb0,0xf3 @ aesmc q5,q5
|
||||
vmov.32 d3[1], r10
|
||||
rev r12,r8
|
||||
vorr q1,q6,q6
|
||||
vmov.32 d13[1], r12
|
||||
.byte 0x2c,0x23,0xf0,0xf3 @ aese q9,q14
|
||||
.byte 0xa2,0x23,0xf0,0xf3 @ aesmc q9,q9
|
||||
vmov.32 d21[1], r12
|
||||
vorr q10,q6,q6
|
||||
subs r2,r2,#3
|
||||
.byte 0x2e,0x83,0xb0,0xf3 @ aese q4,q15
|
||||
.byte 0x2e,0xa3,0xb0,0xf3 @ aese q5,q15
|
||||
|
||||
@@ -622,20 +622,34 @@ _aes_hw_ctr32_encrypt_blocks:
|
||||
add x7,x3,#32
|
||||
mov w6,w5
|
||||
csel x12,xzr,x12,lo
|
||||
|
||||
// ARM Cortex-A57 and Cortex-A72 cores running in 32-bit mode are
|
||||
// affected by silicon errata #1742098 [0] and #1655431 [1],
|
||||
// respectively, where the second instruction of an aese/aesmc
|
||||
// instruction pair may execute twice if an interrupt is taken right
|
||||
// after the first instruction consumes an input register of which a
|
||||
// single 32-bit lane has been updated the last time it was modified.
|
||||
//
|
||||
// This function uses a counter in one 32-bit lane. The vmov lines
|
||||
// could write to v1.16b and v18.16b directly, but that trips this bugs.
|
||||
// We write to v6.16b and copy to the final register as a workaround.
|
||||
//
|
||||
// [0] ARM-EPM-049219 v23 Cortex-A57 MPCore Software Developers Errata Notice
|
||||
// [1] ARM-EPM-012079 v11.0 Cortex-A72 MPCore Software Developers Errata Notice
|
||||
#ifndef __ARMEB__
|
||||
rev w8, w8
|
||||
#endif
|
||||
orr v1.16b,v0.16b,v0.16b
|
||||
add w10, w8, #1
|
||||
orr v18.16b,v0.16b,v0.16b
|
||||
add w8, w8, #2
|
||||
orr v6.16b,v0.16b,v0.16b
|
||||
rev w10, w10
|
||||
mov v1.s[3],w10
|
||||
mov v6.s[3],w10
|
||||
add w8, w8, #2
|
||||
orr v1.16b,v6.16b,v6.16b
|
||||
b.ls Lctr32_tail
|
||||
rev w12, w8
|
||||
mov v6.s[3],w12
|
||||
sub x2,x2,#3 // bias
|
||||
mov v18.s[3],w12
|
||||
orr v18.16b,v6.16b,v6.16b
|
||||
b Loop3x_ctr32
|
||||
|
||||
.align 4
|
||||
@@ -662,11 +676,11 @@ Loop3x_ctr32:
|
||||
aese v1.16b,v16.16b
|
||||
aesmc v5.16b,v1.16b
|
||||
ld1 {v2.16b},[x0],#16
|
||||
orr v0.16b,v6.16b,v6.16b
|
||||
add w9,w8,#1
|
||||
aese v18.16b,v16.16b
|
||||
aesmc v18.16b,v18.16b
|
||||
ld1 {v3.16b},[x0],#16
|
||||
orr v1.16b,v6.16b,v6.16b
|
||||
rev w9,w9
|
||||
aese v4.16b,v17.16b
|
||||
aesmc v4.16b,v4.16b
|
||||
aese v5.16b,v17.16b
|
||||
@@ -675,8 +689,6 @@ Loop3x_ctr32:
|
||||
mov x7,x3
|
||||
aese v18.16b,v17.16b
|
||||
aesmc v17.16b,v18.16b
|
||||
orr v18.16b,v6.16b,v6.16b
|
||||
add w9,w8,#1
|
||||
aese v4.16b,v20.16b
|
||||
aesmc v4.16b,v4.16b
|
||||
aese v5.16b,v20.16b
|
||||
@@ -691,21 +703,26 @@ Loop3x_ctr32:
|
||||
aesmc v4.16b,v4.16b
|
||||
aese v5.16b,v21.16b
|
||||
aesmc v5.16b,v5.16b
|
||||
// Note the logic to update v0.16b, v1.16b, and v1.16b is written to work
|
||||
// around a bug in ARM Cortex-A57 and Cortex-A72 cores running in
|
||||
// 32-bit mode. See the comment above.
|
||||
eor v19.16b,v19.16b,v7.16b
|
||||
rev w9,w9
|
||||
mov v6.s[3], w9
|
||||
aese v17.16b,v21.16b
|
||||
aesmc v17.16b,v17.16b
|
||||
mov v0.s[3], w9
|
||||
orr v0.16b,v6.16b,v6.16b
|
||||
rev w10,w10
|
||||
aese v4.16b,v22.16b
|
||||
aesmc v4.16b,v4.16b
|
||||
mov v6.s[3], w10
|
||||
rev w12,w8
|
||||
aese v5.16b,v22.16b
|
||||
aesmc v5.16b,v5.16b
|
||||
mov v1.s[3], w10
|
||||
rev w12,w8
|
||||
orr v1.16b,v6.16b,v6.16b
|
||||
mov v6.s[3], w12
|
||||
aese v17.16b,v22.16b
|
||||
aesmc v17.16b,v17.16b
|
||||
mov v18.s[3], w12
|
||||
orr v18.16b,v6.16b,v6.16b
|
||||
subs x2,x2,#3
|
||||
aese v4.16b,v23.16b
|
||||
aese v5.16b,v23.16b
|
||||
|
||||
@@ -623,20 +623,34 @@ aes_hw_ctr32_encrypt_blocks:
|
||||
add x7,x3,#32
|
||||
mov w6,w5
|
||||
csel x12,xzr,x12,lo
|
||||
|
||||
// ARM Cortex-A57 and Cortex-A72 cores running in 32-bit mode are
|
||||
// affected by silicon errata #1742098 [0] and #1655431 [1],
|
||||
// respectively, where the second instruction of an aese/aesmc
|
||||
// instruction pair may execute twice if an interrupt is taken right
|
||||
// after the first instruction consumes an input register of which a
|
||||
// single 32-bit lane has been updated the last time it was modified.
|
||||
//
|
||||
// This function uses a counter in one 32-bit lane. The vmov lines
|
||||
// could write to v1.16b and v18.16b directly, but that trips this bugs.
|
||||
// We write to v6.16b and copy to the final register as a workaround.
|
||||
//
|
||||
// [0] ARM-EPM-049219 v23 Cortex-A57 MPCore Software Developers Errata Notice
|
||||
// [1] ARM-EPM-012079 v11.0 Cortex-A72 MPCore Software Developers Errata Notice
|
||||
#ifndef __ARMEB__
|
||||
rev w8, w8
|
||||
#endif
|
||||
orr v1.16b,v0.16b,v0.16b
|
||||
add w10, w8, #1
|
||||
orr v18.16b,v0.16b,v0.16b
|
||||
add w8, w8, #2
|
||||
orr v6.16b,v0.16b,v0.16b
|
||||
rev w10, w10
|
||||
mov v1.s[3],w10
|
||||
mov v6.s[3],w10
|
||||
add w8, w8, #2
|
||||
orr v1.16b,v6.16b,v6.16b
|
||||
b.ls .Lctr32_tail
|
||||
rev w12, w8
|
||||
mov v6.s[3],w12
|
||||
sub x2,x2,#3 // bias
|
||||
mov v18.s[3],w12
|
||||
orr v18.16b,v6.16b,v6.16b
|
||||
b .Loop3x_ctr32
|
||||
|
||||
.align 4
|
||||
@@ -663,11 +677,11 @@ aes_hw_ctr32_encrypt_blocks:
|
||||
aese v1.16b,v16.16b
|
||||
aesmc v5.16b,v1.16b
|
||||
ld1 {v2.16b},[x0],#16
|
||||
orr v0.16b,v6.16b,v6.16b
|
||||
add w9,w8,#1
|
||||
aese v18.16b,v16.16b
|
||||
aesmc v18.16b,v18.16b
|
||||
ld1 {v3.16b},[x0],#16
|
||||
orr v1.16b,v6.16b,v6.16b
|
||||
rev w9,w9
|
||||
aese v4.16b,v17.16b
|
||||
aesmc v4.16b,v4.16b
|
||||
aese v5.16b,v17.16b
|
||||
@@ -676,8 +690,6 @@ aes_hw_ctr32_encrypt_blocks:
|
||||
mov x7,x3
|
||||
aese v18.16b,v17.16b
|
||||
aesmc v17.16b,v18.16b
|
||||
orr v18.16b,v6.16b,v6.16b
|
||||
add w9,w8,#1
|
||||
aese v4.16b,v20.16b
|
||||
aesmc v4.16b,v4.16b
|
||||
aese v5.16b,v20.16b
|
||||
@@ -692,21 +704,26 @@ aes_hw_ctr32_encrypt_blocks:
|
||||
aesmc v4.16b,v4.16b
|
||||
aese v5.16b,v21.16b
|
||||
aesmc v5.16b,v5.16b
|
||||
// Note the logic to update v0.16b, v1.16b, and v1.16b is written to work
|
||||
// around a bug in ARM Cortex-A57 and Cortex-A72 cores running in
|
||||
// 32-bit mode. See the comment above.
|
||||
eor v19.16b,v19.16b,v7.16b
|
||||
rev w9,w9
|
||||
mov v6.s[3], w9
|
||||
aese v17.16b,v21.16b
|
||||
aesmc v17.16b,v17.16b
|
||||
mov v0.s[3], w9
|
||||
orr v0.16b,v6.16b,v6.16b
|
||||
rev w10,w10
|
||||
aese v4.16b,v22.16b
|
||||
aesmc v4.16b,v4.16b
|
||||
mov v6.s[3], w10
|
||||
rev w12,w8
|
||||
aese v5.16b,v22.16b
|
||||
aesmc v5.16b,v5.16b
|
||||
mov v1.s[3], w10
|
||||
rev w12,w8
|
||||
orr v1.16b,v6.16b,v6.16b
|
||||
mov v6.s[3], w12
|
||||
aese v17.16b,v22.16b
|
||||
aesmc v17.16b,v17.16b
|
||||
mov v18.s[3], w12
|
||||
orr v18.16b,v6.16b,v6.16b
|
||||
subs x2,x2,#3
|
||||
aese v4.16b,v23.16b
|
||||
aese v5.16b,v23.16b
|
||||
|
||||
@@ -101,26 +101,7 @@ void BN_free(BIGNUM *bn) {
|
||||
}
|
||||
|
||||
void BN_clear_free(BIGNUM *bn) {
|
||||
char should_free;
|
||||
|
||||
if (bn == NULL) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (bn->d != NULL) {
|
||||
if ((bn->flags & BN_FLG_STATIC_DATA) == 0) {
|
||||
OPENSSL_free(bn->d);
|
||||
} else {
|
||||
OPENSSL_cleanse(bn->d, bn->dmax * sizeof(bn->d[0]));
|
||||
}
|
||||
}
|
||||
|
||||
should_free = (bn->flags & BN_FLG_MALLOCED) != 0;
|
||||
if (should_free) {
|
||||
OPENSSL_free(bn);
|
||||
} else {
|
||||
OPENSSL_cleanse(bn, sizeof(BIGNUM));
|
||||
}
|
||||
BN_free(bn);
|
||||
}
|
||||
|
||||
BIGNUM *BN_dup(const BIGNUM *src) {
|
||||
@@ -302,6 +283,18 @@ int bn_set_words(BIGNUM *bn, const BN_ULONG *words, size_t num) {
|
||||
return 1;
|
||||
}
|
||||
|
||||
void bn_set_static_words(BIGNUM *bn, const BN_ULONG *words, size_t num) {
|
||||
if ((bn->flags & BN_FLG_STATIC_DATA) == 0) {
|
||||
OPENSSL_free(bn->d);
|
||||
}
|
||||
bn->d = (BN_ULONG *)words;
|
||||
|
||||
bn->width = num;
|
||||
bn->dmax = num;
|
||||
bn->neg = 0;
|
||||
bn->flags |= BN_FLG_STATIC_DATA;
|
||||
}
|
||||
|
||||
int bn_fits_in_words(const BIGNUM *bn, size_t num) {
|
||||
// All words beyond |num| must be zero.
|
||||
BN_ULONG mask = 0;
|
||||
|
||||
@@ -64,10 +64,10 @@
|
||||
#include "internal.h"
|
||||
|
||||
|
||||
#if !defined(BN_CAN_DIVIDE_ULLONG) && !defined(BN_CAN_USE_INLINE_ASM)
|
||||
// bn_div_words divides a double-width |h|,|l| by |d| and returns the result,
|
||||
// which must fit in a |BN_ULONG|.
|
||||
static BN_ULONG bn_div_words(BN_ULONG h, BN_ULONG l, BN_ULONG d) {
|
||||
OPENSSL_UNUSED static BN_ULONG bn_div_words(BN_ULONG h, BN_ULONG l,
|
||||
BN_ULONG d) {
|
||||
BN_ULONG dh, dl, q, ret = 0, th, tl, t;
|
||||
int i, count = 2;
|
||||
|
||||
@@ -135,7 +135,6 @@ static BN_ULONG bn_div_words(BN_ULONG h, BN_ULONG l, BN_ULONG d) {
|
||||
ret |= q;
|
||||
return ret;
|
||||
}
|
||||
#endif // !defined(BN_CAN_DIVIDE_ULLONG) && !defined(BN_CAN_USE_INLINE_ASM)
|
||||
|
||||
static inline void bn_div_rem_words(BN_ULONG *quotient_out, BN_ULONG *rem_out,
|
||||
BN_ULONG n0, BN_ULONG n1, BN_ULONG d0) {
|
||||
|
||||
@@ -123,7 +123,7 @@
|
||||
#ifndef OPENSSL_HEADER_BN_INTERNAL_H
|
||||
#define OPENSSL_HEADER_BN_INTERNAL_H
|
||||
|
||||
#include <CCryptoBoringSSL_base.h>
|
||||
#include <CCryptoBoringSSL_bn.h>
|
||||
|
||||
#if defined(OPENSSL_X86_64) && defined(_MSC_VER)
|
||||
OPENSSL_MSVC_PRAGMA(warning(push, 3))
|
||||
@@ -241,6 +241,14 @@ void bn_select_words(BN_ULONG *r, BN_ULONG mask, const BN_ULONG *a,
|
||||
// least significant word first.
|
||||
int bn_set_words(BIGNUM *bn, const BN_ULONG *words, size_t num);
|
||||
|
||||
// bn_set_static_words acts like |bn_set_words|, but doesn't copy the data. A
|
||||
// flag is set on |bn| so that |BN_free| won't attempt to free the data.
|
||||
//
|
||||
// The |STATIC_BIGNUM| macro is probably a better solution for this outside of
|
||||
// the FIPS module. Inside of the FIPS module that macro generates rel.ro data,
|
||||
// which doesn't work with FIPS requirements.
|
||||
void bn_set_static_words(BIGNUM *bn, const BN_ULONG *words, size_t num);
|
||||
|
||||
// bn_fits_in_words returns one if |bn| may be represented in |num| words, plus
|
||||
// a sign bit, and zero otherwise.
|
||||
int bn_fits_in_words(const BIGNUM *bn, size_t num);
|
||||
|
||||
File renamed without changes.
+105
-233
@@ -60,17 +60,15 @@
|
||||
|
||||
#include <CCryptoBoringSSL_bn.h>
|
||||
#include <CCryptoBoringSSL_err.h>
|
||||
#include <CCryptoBoringSSL_ex_data.h>
|
||||
#include <CCryptoBoringSSL_digest.h>
|
||||
#include <CCryptoBoringSSL_mem.h>
|
||||
#include <CCryptoBoringSSL_thread.h>
|
||||
|
||||
#include "../internal.h"
|
||||
#include "../../internal.h"
|
||||
|
||||
|
||||
#define OPENSSL_DH_MAX_MODULUS_BITS 10000
|
||||
|
||||
static CRYPTO_EX_DATA_CLASS g_ex_data_class = CRYPTO_EX_DATA_CLASS_INIT;
|
||||
|
||||
DH *DH_new(void) {
|
||||
DH *dh = OPENSSL_malloc(sizeof(DH));
|
||||
if (dh == NULL) {
|
||||
@@ -83,7 +81,6 @@ DH *DH_new(void) {
|
||||
CRYPTO_MUTEX_init(&dh->method_mont_p_lock);
|
||||
|
||||
dh->references = 1;
|
||||
CRYPTO_new_ex_data(&dh->ex_data);
|
||||
|
||||
return dh;
|
||||
}
|
||||
@@ -97,8 +94,6 @@ void DH_free(DH *dh) {
|
||||
return;
|
||||
}
|
||||
|
||||
CRYPTO_free_ex_data(&g_ex_data_class, dh, &dh->ex_data);
|
||||
|
||||
BN_MONT_CTX_free(dh->method_mont_p);
|
||||
BN_clear_free(dh->p);
|
||||
BN_clear_free(dh->g);
|
||||
@@ -189,120 +184,6 @@ int DH_set_length(DH *dh, unsigned priv_length) {
|
||||
return 1;
|
||||
}
|
||||
|
||||
int DH_generate_parameters_ex(DH *dh, int prime_bits, int generator, BN_GENCB *cb) {
|
||||
// We generate DH parameters as follows
|
||||
// find a prime q which is prime_bits/2 bits long.
|
||||
// p=(2*q)+1 or (p-1)/2 = q
|
||||
// For this case, g is a generator if
|
||||
// g^((p-1)/q) mod p != 1 for values of q which are the factors of p-1.
|
||||
// Since the factors of p-1 are q and 2, we just need to check
|
||||
// g^2 mod p != 1 and g^q mod p != 1.
|
||||
//
|
||||
// Having said all that,
|
||||
// there is another special case method for the generators 2, 3 and 5.
|
||||
// for 2, p mod 24 == 11
|
||||
// for 3, p mod 12 == 5 <<<<< does not work for safe primes.
|
||||
// for 5, p mod 10 == 3 or 7
|
||||
//
|
||||
// Thanks to Phil Karn <karn@qualcomm.com> for the pointers about the
|
||||
// special generators and for answering some of my questions.
|
||||
//
|
||||
// I've implemented the second simple method :-).
|
||||
// Since DH should be using a safe prime (both p and q are prime),
|
||||
// this generator function can take a very very long time to run.
|
||||
|
||||
// Actually there is no reason to insist that 'generator' be a generator.
|
||||
// It's just as OK (and in some sense better) to use a generator of the
|
||||
// order-q subgroup.
|
||||
|
||||
BIGNUM *t1, *t2;
|
||||
int g, ok = 0;
|
||||
BN_CTX *ctx = NULL;
|
||||
|
||||
ctx = BN_CTX_new();
|
||||
if (ctx == NULL) {
|
||||
goto err;
|
||||
}
|
||||
BN_CTX_start(ctx);
|
||||
t1 = BN_CTX_get(ctx);
|
||||
t2 = BN_CTX_get(ctx);
|
||||
if (t1 == NULL || t2 == NULL) {
|
||||
goto err;
|
||||
}
|
||||
|
||||
// Make sure |dh| has the necessary elements
|
||||
if (dh->p == NULL) {
|
||||
dh->p = BN_new();
|
||||
if (dh->p == NULL) {
|
||||
goto err;
|
||||
}
|
||||
}
|
||||
if (dh->g == NULL) {
|
||||
dh->g = BN_new();
|
||||
if (dh->g == NULL) {
|
||||
goto err;
|
||||
}
|
||||
}
|
||||
|
||||
if (generator <= 1) {
|
||||
OPENSSL_PUT_ERROR(DH, DH_R_BAD_GENERATOR);
|
||||
goto err;
|
||||
}
|
||||
if (generator == DH_GENERATOR_2) {
|
||||
if (!BN_set_word(t1, 24)) {
|
||||
goto err;
|
||||
}
|
||||
if (!BN_set_word(t2, 11)) {
|
||||
goto err;
|
||||
}
|
||||
g = 2;
|
||||
} else if (generator == DH_GENERATOR_5) {
|
||||
if (!BN_set_word(t1, 10)) {
|
||||
goto err;
|
||||
}
|
||||
if (!BN_set_word(t2, 3)) {
|
||||
goto err;
|
||||
}
|
||||
// BN_set_word(t3,7); just have to miss
|
||||
// out on these ones :-(
|
||||
g = 5;
|
||||
} else {
|
||||
// in the general case, don't worry if 'generator' is a
|
||||
// generator or not: since we are using safe primes,
|
||||
// it will generate either an order-q or an order-2q group,
|
||||
// which both is OK
|
||||
if (!BN_set_word(t1, 2)) {
|
||||
goto err;
|
||||
}
|
||||
if (!BN_set_word(t2, 1)) {
|
||||
goto err;
|
||||
}
|
||||
g = generator;
|
||||
}
|
||||
|
||||
if (!BN_generate_prime_ex(dh->p, prime_bits, 1, t1, t2, cb)) {
|
||||
goto err;
|
||||
}
|
||||
if (!BN_GENCB_call(cb, 3, 0)) {
|
||||
goto err;
|
||||
}
|
||||
if (!BN_set_word(dh->g, g)) {
|
||||
goto err;
|
||||
}
|
||||
ok = 1;
|
||||
|
||||
err:
|
||||
if (!ok) {
|
||||
OPENSSL_PUT_ERROR(DH, ERR_R_BN_LIB);
|
||||
}
|
||||
|
||||
if (ctx != NULL) {
|
||||
BN_CTX_end(ctx);
|
||||
BN_CTX_free(ctx);
|
||||
}
|
||||
return ok;
|
||||
}
|
||||
|
||||
int DH_generate_key(DH *dh) {
|
||||
int ok = 0;
|
||||
int generate_new_key = 0;
|
||||
@@ -390,56 +271,127 @@ err:
|
||||
return ok;
|
||||
}
|
||||
|
||||
int DH_compute_key(unsigned char *out, const BIGNUM *peers_key, DH *dh) {
|
||||
BN_CTX *ctx = NULL;
|
||||
BIGNUM *shared_key;
|
||||
int ret = -1;
|
||||
int check_result;
|
||||
|
||||
static int dh_compute_key(DH *dh, BIGNUM *out_shared_key,
|
||||
const BIGNUM *peers_key, BN_CTX *ctx) {
|
||||
if (BN_num_bits(dh->p) > OPENSSL_DH_MAX_MODULUS_BITS) {
|
||||
OPENSSL_PUT_ERROR(DH, DH_R_MODULUS_TOO_LARGE);
|
||||
goto err;
|
||||
}
|
||||
|
||||
ctx = BN_CTX_new();
|
||||
if (ctx == NULL) {
|
||||
goto err;
|
||||
}
|
||||
BN_CTX_start(ctx);
|
||||
shared_key = BN_CTX_get(ctx);
|
||||
if (shared_key == NULL) {
|
||||
goto err;
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (dh->priv_key == NULL) {
|
||||
OPENSSL_PUT_ERROR(DH, DH_R_NO_PRIVATE_VALUE);
|
||||
goto err;
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (!BN_MONT_CTX_set_locked(&dh->method_mont_p, &dh->method_mont_p_lock,
|
||||
int check_result;
|
||||
if (!DH_check_pub_key(dh, peers_key, &check_result) || check_result) {
|
||||
OPENSSL_PUT_ERROR(DH, DH_R_INVALID_PUBKEY);
|
||||
return 0;
|
||||
}
|
||||
|
||||
int ret = 0;
|
||||
BN_CTX_start(ctx);
|
||||
BIGNUM *p_minus_1 = BN_CTX_get(ctx);
|
||||
|
||||
if (!p_minus_1 ||
|
||||
!BN_MONT_CTX_set_locked(&dh->method_mont_p, &dh->method_mont_p_lock,
|
||||
dh->p, ctx)) {
|
||||
goto err;
|
||||
}
|
||||
|
||||
if (!DH_check_pub_key(dh, peers_key, &check_result) || check_result) {
|
||||
OPENSSL_PUT_ERROR(DH, DH_R_INVALID_PUBKEY);
|
||||
goto err;
|
||||
}
|
||||
|
||||
if (!BN_mod_exp_mont_consttime(shared_key, peers_key, dh->priv_key, dh->p,
|
||||
ctx, dh->method_mont_p)) {
|
||||
if (!BN_mod_exp_mont_consttime(out_shared_key, peers_key, dh->priv_key, dh->p,
|
||||
ctx, dh->method_mont_p) ||
|
||||
!BN_copy(p_minus_1, dh->p) ||
|
||||
!BN_sub_word(p_minus_1, 1)) {
|
||||
OPENSSL_PUT_ERROR(DH, ERR_R_BN_LIB);
|
||||
goto err;
|
||||
}
|
||||
|
||||
ret = BN_bn2bin(shared_key, out);
|
||||
|
||||
err:
|
||||
if (ctx != NULL) {
|
||||
BN_CTX_end(ctx);
|
||||
BN_CTX_free(ctx);
|
||||
// This performs the check required by SP 800-56Ar3 section 5.7.1.1 step two.
|
||||
if (BN_cmp_word(out_shared_key, 1) <= 0 ||
|
||||
BN_cmp(out_shared_key, p_minus_1) == 0) {
|
||||
OPENSSL_PUT_ERROR(DH, DH_R_INVALID_PUBKEY);
|
||||
goto err;
|
||||
}
|
||||
|
||||
ret = 1;
|
||||
|
||||
err:
|
||||
BN_CTX_end(ctx);
|
||||
return ret;
|
||||
}
|
||||
|
||||
int DH_compute_key_padded(unsigned char *out, const BIGNUM *peers_key, DH *dh) {
|
||||
BN_CTX *ctx = BN_CTX_new();
|
||||
if (ctx == NULL) {
|
||||
return -1;
|
||||
}
|
||||
BN_CTX_start(ctx);
|
||||
|
||||
int dh_size = DH_size(dh);
|
||||
int ret = -1;
|
||||
BIGNUM *shared_key = BN_CTX_get(ctx);
|
||||
if (shared_key &&
|
||||
dh_compute_key(dh, shared_key, peers_key, ctx) &&
|
||||
BN_bn2bin_padded(out, dh_size, shared_key)) {
|
||||
ret = dh_size;
|
||||
}
|
||||
|
||||
BN_CTX_end(ctx);
|
||||
BN_CTX_free(ctx);
|
||||
return ret;
|
||||
}
|
||||
|
||||
int DH_compute_key(unsigned char *out, const BIGNUM *peers_key, DH *dh) {
|
||||
BN_CTX *ctx = BN_CTX_new();
|
||||
if (ctx == NULL) {
|
||||
return -1;
|
||||
}
|
||||
BN_CTX_start(ctx);
|
||||
|
||||
int ret = -1;
|
||||
BIGNUM *shared_key = BN_CTX_get(ctx);
|
||||
if (shared_key && dh_compute_key(dh, shared_key, peers_key, ctx)) {
|
||||
ret = BN_bn2bin(shared_key, out);
|
||||
}
|
||||
|
||||
BN_CTX_end(ctx);
|
||||
BN_CTX_free(ctx);
|
||||
return ret;
|
||||
}
|
||||
|
||||
int DH_compute_key_hashed(DH *dh, uint8_t *out, size_t *out_len,
|
||||
size_t max_out_len, const BIGNUM *peers_key,
|
||||
const EVP_MD *digest) {
|
||||
*out_len = (size_t)-1;
|
||||
|
||||
const size_t digest_len = EVP_MD_size(digest);
|
||||
if (digest_len > max_out_len) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
int ret = 0;
|
||||
const size_t dh_len = DH_size(dh);
|
||||
uint8_t *shared_bytes = OPENSSL_malloc(dh_len);
|
||||
unsigned out_len_unsigned;
|
||||
if (!shared_bytes ||
|
||||
// SP 800-56A is ambiguous about whether the output should be padded prior
|
||||
// to revision three. But revision three, section C.1, awkwardly specifies
|
||||
// padding to the length of p.
|
||||
//
|
||||
// Also, padded output avoids side-channels, so is always strongly
|
||||
// advisable.
|
||||
DH_compute_key_padded(shared_bytes, peers_key, dh) != (int)dh_len ||
|
||||
!EVP_Digest(shared_bytes, dh_len, out, &out_len_unsigned, digest, NULL) ||
|
||||
out_len_unsigned != digest_len) {
|
||||
goto err;
|
||||
}
|
||||
|
||||
*out_len = digest_len;
|
||||
ret = 1;
|
||||
|
||||
err:
|
||||
OPENSSL_free(shared_bytes);
|
||||
return ret;
|
||||
}
|
||||
|
||||
@@ -451,83 +403,3 @@ int DH_up_ref(DH *dh) {
|
||||
CRYPTO_refcount_inc(&dh->references);
|
||||
return 1;
|
||||
}
|
||||
|
||||
static int int_dh_bn_cpy(BIGNUM **dst, const BIGNUM *src) {
|
||||
BIGNUM *a = NULL;
|
||||
|
||||
if (src) {
|
||||
a = BN_dup(src);
|
||||
if (!a) {
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
BN_free(*dst);
|
||||
*dst = a;
|
||||
return 1;
|
||||
}
|
||||
|
||||
static int int_dh_param_copy(DH *to, const DH *from, int is_x942) {
|
||||
if (is_x942 == -1) {
|
||||
is_x942 = !!from->q;
|
||||
}
|
||||
if (!int_dh_bn_cpy(&to->p, from->p) ||
|
||||
!int_dh_bn_cpy(&to->g, from->g)) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (!is_x942) {
|
||||
return 1;
|
||||
}
|
||||
|
||||
if (!int_dh_bn_cpy(&to->q, from->q) ||
|
||||
!int_dh_bn_cpy(&to->j, from->j)) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
OPENSSL_free(to->seed);
|
||||
to->seed = NULL;
|
||||
to->seedlen = 0;
|
||||
|
||||
if (from->seed) {
|
||||
to->seed = OPENSSL_memdup(from->seed, from->seedlen);
|
||||
if (!to->seed) {
|
||||
return 0;
|
||||
}
|
||||
to->seedlen = from->seedlen;
|
||||
}
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
DH *DHparams_dup(const DH *dh) {
|
||||
DH *ret = DH_new();
|
||||
if (!ret) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
if (!int_dh_param_copy(ret, dh, -1)) {
|
||||
DH_free(ret);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
int DH_get_ex_new_index(long argl, void *argp, CRYPTO_EX_unused *unused,
|
||||
CRYPTO_EX_dup *dup_unused, CRYPTO_EX_free *free_func) {
|
||||
int index;
|
||||
if (!CRYPTO_get_ex_new_index(&g_ex_data_class, &index, argl, argp,
|
||||
free_func)) {
|
||||
return -1;
|
||||
}
|
||||
return index;
|
||||
}
|
||||
|
||||
int DH_set_ex_data(DH *d, int idx, void *arg) {
|
||||
return CRYPTO_set_ex_data(&d->ex_data, idx, arg);
|
||||
}
|
||||
|
||||
void *DH_get_ex_data(DH *d, int idx) {
|
||||
return CRYPTO_get_ex_data(&d->ex_data, idx);
|
||||
}
|
||||
@@ -797,6 +797,12 @@ int EC_POINT_get_affine_coordinates_GFp(const EC_GROUP *group,
|
||||
return 1;
|
||||
}
|
||||
|
||||
int EC_POINT_get_affine_coordinates(const EC_GROUP *group,
|
||||
const EC_POINT *point, BIGNUM *x, BIGNUM *y,
|
||||
BN_CTX *ctx) {
|
||||
return EC_POINT_get_affine_coordinates_GFp(group, point, x, y, ctx);
|
||||
}
|
||||
|
||||
void ec_affine_to_jacobian(const EC_GROUP *group, EC_RAW_POINT *out,
|
||||
const EC_AFFINE *p) {
|
||||
out->X = p->X;
|
||||
@@ -879,6 +885,12 @@ int EC_POINT_set_affine_coordinates_GFp(const EC_GROUP *group, EC_POINT *point,
|
||||
return 1;
|
||||
}
|
||||
|
||||
int EC_POINT_set_affine_coordinates(const EC_GROUP *group, EC_POINT *point,
|
||||
const BIGNUM *x, const BIGNUM *y,
|
||||
BN_CTX *ctx) {
|
||||
return EC_POINT_set_affine_coordinates_GFp(group, point, x, y, ctx);
|
||||
}
|
||||
|
||||
int EC_POINT_add(const EC_GROUP *group, EC_POINT *r, const EC_POINT *a,
|
||||
const EC_POINT *b, BN_CTX *ctx) {
|
||||
if (EC_GROUP_cmp(group, r->group, NULL) != 0 ||
|
||||
|
||||
@@ -440,7 +440,15 @@ int EC_KEY_generate_key(EC_KEY *key) {
|
||||
}
|
||||
|
||||
int EC_KEY_generate_key_fips(EC_KEY *eckey) {
|
||||
return EC_KEY_generate_key(eckey) && EC_KEY_check_fips(eckey);
|
||||
if (EC_KEY_generate_key(eckey) && EC_KEY_check_fips(eckey)) {
|
||||
return 1;
|
||||
}
|
||||
|
||||
EC_POINT_free(eckey->pub_key);
|
||||
ec_wrapped_scalar_free(eckey->priv_key);
|
||||
eckey->pub_key = NULL;
|
||||
eckey->priv_key = NULL;
|
||||
return 0;
|
||||
}
|
||||
|
||||
int EC_KEY_get_ex_new_index(long argl, void *argp, CRYPTO_EX_unused *unused,
|
||||
|
||||
@@ -36,6 +36,34 @@ extern "C" {
|
||||
void RAND_bytes_with_additional_data(uint8_t *out, size_t out_len,
|
||||
const uint8_t user_additional_data[32]);
|
||||
|
||||
#if defined(BORINGSSL_FIPS)
|
||||
|
||||
// We overread from /dev/urandom or RDRAND by a factor of 10 and XOR to whiten.
|
||||
#define BORINGSSL_FIPS_OVERREAD 10
|
||||
|
||||
// CRYPTO_get_seed_entropy writes |out_entropy_len| bytes of entropy, suitable
|
||||
// for seeding a DRBG, to |out_entropy|. It sets |*out_used_cpu| to one if the
|
||||
// entropy came directly from the CPU and zero if it came from the OS. It
|
||||
// actively obtains entropy from the CPU/OS and so should not be called from
|
||||
// within the FIPS module if |BORINGSSL_FIPS_PASSIVE_ENTROPY| is defined.
|
||||
void CRYPTO_get_seed_entropy(uint8_t *out_entropy, size_t out_entropy_len,
|
||||
int *out_used_cpu);
|
||||
|
||||
#if defined(BORINGSSL_FIPS_PASSIVE_ENTROPY)
|
||||
|
||||
// RAND_load_entropy supplies |entropy_len| bytes of entropy to the module. The
|
||||
// |from_cpu| parameter is true iff the entropy was obtained directly from the
|
||||
// CPU.
|
||||
void RAND_load_entropy(const uint8_t *entropy, size_t entropy_len,
|
||||
int from_cpu);
|
||||
|
||||
// RAND_need_entropy is implemented outside of the FIPS module and is called
|
||||
// when the module has stopped because it has run out of entropy.
|
||||
void RAND_need_entropy(size_t bytes_needed);
|
||||
|
||||
#endif // BORINGSSL_FIPS_PASSIVE_ENTROPY
|
||||
#endif // BORINGSSL_FIPS
|
||||
|
||||
// CRYPTO_sysrand fills |len| bytes at |buf| with entropy from the operating
|
||||
// system.
|
||||
void CRYPTO_sysrand(uint8_t *buf, size_t len);
|
||||
|
||||
@@ -25,6 +25,7 @@
|
||||
#include <CCryptoBoringSSL_chacha.h>
|
||||
#include <CCryptoBoringSSL_cpu.h>
|
||||
#include <CCryptoBoringSSL_mem.h>
|
||||
#include <CCryptoBoringSSL_type_check.h>
|
||||
|
||||
#include "internal.h"
|
||||
#include "fork_detect.h"
|
||||
@@ -63,11 +64,11 @@ struct rand_thread_state {
|
||||
// (re)seeded. This is bound by |kReseedInterval|.
|
||||
unsigned calls;
|
||||
// last_block_valid is non-zero iff |last_block| contains data from
|
||||
// |CRYPTO_sysrand_for_seed|.
|
||||
// |get_seed_entropy|.
|
||||
int last_block_valid;
|
||||
|
||||
#if defined(BORINGSSL_FIPS)
|
||||
// last_block contains the previous block from |CRYPTO_sysrand_for_seed|.
|
||||
// last_block contains the previous block from |get_seed_entropy|.
|
||||
uint8_t last_block[CRNGT_BLOCK_SIZE];
|
||||
// next and prev form a NULL-terminated, double-linked list of all states in
|
||||
// a process.
|
||||
@@ -146,12 +147,6 @@ static int rdrand(uint8_t *buf, const size_t len) {
|
||||
OPENSSL_memcpy(buf + len_multiple8, rand_buf, remainder);
|
||||
}
|
||||
|
||||
#if defined(BORINGSSL_FIPS_BREAK_CRNG)
|
||||
// This breaks the "continuous random number generator test" defined in FIPS
|
||||
// 140-2, section 4.9.2, and implemented in rand_get_seed().
|
||||
OPENSSL_memset(buf, 0, len);
|
||||
#endif
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
@@ -165,25 +160,110 @@ static int rdrand(uint8_t *buf, size_t len) {
|
||||
|
||||
#if defined(BORINGSSL_FIPS)
|
||||
|
||||
void CRYPTO_get_seed_entropy(uint8_t *out_entropy, size_t out_entropy_len,
|
||||
int *out_used_cpu) {
|
||||
*out_used_cpu = 0;
|
||||
if (have_rdrand() && rdrand(out_entropy, out_entropy_len)) {
|
||||
*out_used_cpu = 1;
|
||||
} else {
|
||||
CRYPTO_sysrand_for_seed(out_entropy, out_entropy_len);
|
||||
}
|
||||
|
||||
#if defined(BORINGSSL_FIPS_BREAK_CRNG)
|
||||
// This breaks the "continuous random number generator test" defined in FIPS
|
||||
// 140-2, section 4.9.2, and implemented in |rand_get_seed|.
|
||||
OPENSSL_memset(out_entropy, 0, out_entropy_len);
|
||||
#endif
|
||||
}
|
||||
|
||||
#if defined(BORINGSSL_FIPS_PASSIVE_ENTROPY)
|
||||
|
||||
// In passive entropy mode, entropy is supplied from outside of the module via
|
||||
// |RAND_load_entropy| and is stored in global instance of the following
|
||||
// structure.
|
||||
|
||||
struct entropy_buffer {
|
||||
// bytes contains entropy suitable for seeding a DRBG.
|
||||
uint8_t bytes[CTR_DRBG_ENTROPY_LEN * BORINGSSL_FIPS_OVERREAD];
|
||||
// bytes_valid indicates the number of bytes of |bytes| that contain valid
|
||||
// data.
|
||||
size_t bytes_valid;
|
||||
// from_cpu is true if any of the contents of |bytes| were obtained directly
|
||||
// from the CPU.
|
||||
int from_cpu;
|
||||
};
|
||||
|
||||
DEFINE_BSS_GET(struct entropy_buffer, entropy_buffer);
|
||||
DEFINE_STATIC_MUTEX(entropy_buffer_lock);
|
||||
|
||||
void RAND_load_entropy(const uint8_t *entropy, size_t entropy_len,
|
||||
int from_cpu) {
|
||||
struct entropy_buffer *const buffer = entropy_buffer_bss_get();
|
||||
|
||||
CRYPTO_STATIC_MUTEX_lock_write(entropy_buffer_lock_bss_get());
|
||||
const size_t space = sizeof(buffer->bytes) - buffer->bytes_valid;
|
||||
if (entropy_len > space) {
|
||||
entropy_len = space;
|
||||
}
|
||||
|
||||
OPENSSL_memcpy(&buffer->bytes[buffer->bytes_valid], entropy, entropy_len);
|
||||
buffer->bytes_valid += entropy_len;
|
||||
buffer->from_cpu |= from_cpu && (entropy_len != 0);
|
||||
CRYPTO_STATIC_MUTEX_unlock_write(entropy_buffer_lock_bss_get());
|
||||
}
|
||||
|
||||
// get_seed_entropy fills |out_entropy_len| bytes of |out_entropy| from the
|
||||
// global |entropy_buffer|.
|
||||
static void get_seed_entropy(uint8_t *out_entropy, size_t out_entropy_len,
|
||||
int *out_used_cpu) {
|
||||
struct entropy_buffer *const buffer = entropy_buffer_bss_get();
|
||||
if (out_entropy_len > sizeof(buffer->bytes)) {
|
||||
abort();
|
||||
}
|
||||
|
||||
CRYPTO_STATIC_MUTEX_lock_write(entropy_buffer_lock_bss_get());
|
||||
while (buffer->bytes_valid < out_entropy_len) {
|
||||
CRYPTO_STATIC_MUTEX_unlock_write(entropy_buffer_lock_bss_get());
|
||||
RAND_need_entropy(out_entropy_len - buffer->bytes_valid);
|
||||
CRYPTO_STATIC_MUTEX_lock_write(entropy_buffer_lock_bss_get());
|
||||
}
|
||||
|
||||
*out_used_cpu = buffer->from_cpu;
|
||||
OPENSSL_memcpy(out_entropy, buffer->bytes, out_entropy_len);
|
||||
OPENSSL_memmove(buffer->bytes, &buffer->bytes[out_entropy_len],
|
||||
buffer->bytes_valid - out_entropy_len);
|
||||
buffer->bytes_valid -= out_entropy_len;
|
||||
if (buffer->bytes_valid == 0) {
|
||||
buffer->from_cpu = 0;
|
||||
}
|
||||
|
||||
CRYPTO_STATIC_MUTEX_unlock_write(entropy_buffer_lock_bss_get());
|
||||
}
|
||||
|
||||
#else
|
||||
|
||||
// In the active case, |get_seed_entropy| simply calls |CRYPTO_get_seed_entropy|
|
||||
// in order to obtain entropy from the CPU or OS.
|
||||
static void get_seed_entropy(uint8_t *out_entropy, size_t out_entropy_len,
|
||||
int *out_used_cpu) {
|
||||
CRYPTO_get_seed_entropy(out_entropy, out_entropy_len, out_used_cpu);
|
||||
}
|
||||
|
||||
#endif // !BORINGSSL_FIPS_PASSIVE_ENTROPY
|
||||
|
||||
// rand_get_seed fills |seed| with entropy and sets |*out_used_cpu| to one if
|
||||
// that entropy came directly from the CPU and zero otherwise.
|
||||
static void rand_get_seed(struct rand_thread_state *state,
|
||||
uint8_t seed[CTR_DRBG_ENTROPY_LEN]) {
|
||||
uint8_t seed[CTR_DRBG_ENTROPY_LEN],
|
||||
int *out_used_cpu) {
|
||||
if (!state->last_block_valid) {
|
||||
if (!have_rdrand() ||
|
||||
!rdrand(state->last_block, sizeof(state->last_block))) {
|
||||
CRYPTO_sysrand_for_seed(state->last_block, sizeof(state->last_block));
|
||||
}
|
||||
int unused;
|
||||
get_seed_entropy(state->last_block, sizeof(state->last_block), &unused);
|
||||
state->last_block_valid = 1;
|
||||
}
|
||||
|
||||
// We overread from /dev/urandom or RDRAND by a factor of 10 and XOR to
|
||||
// whiten.
|
||||
#define FIPS_OVERREAD 10
|
||||
uint8_t entropy[CTR_DRBG_ENTROPY_LEN * FIPS_OVERREAD];
|
||||
|
||||
int used_rdrand = have_rdrand() && rdrand(entropy, sizeof(entropy));
|
||||
if (!used_rdrand) {
|
||||
CRYPTO_sysrand_for_seed(entropy, sizeof(entropy));
|
||||
}
|
||||
uint8_t entropy[CTR_DRBG_ENTROPY_LEN * BORINGSSL_FIPS_OVERREAD];
|
||||
get_seed_entropy(entropy, sizeof(entropy), out_used_cpu);
|
||||
|
||||
// See FIPS 140-2, section 4.9.2. This is the “continuous random number
|
||||
// generator test” which causes the program to randomly abort. Hopefully the
|
||||
@@ -193,6 +273,7 @@ static void rand_get_seed(struct rand_thread_state *state,
|
||||
BORINGSSL_FIPS_abort();
|
||||
}
|
||||
|
||||
OPENSSL_STATIC_ASSERT(sizeof(entropy) % CRNGT_BLOCK_SIZE == 0, "");
|
||||
for (size_t i = CRNGT_BLOCK_SIZE; i < sizeof(entropy);
|
||||
i += CRNGT_BLOCK_SIZE) {
|
||||
if (CRYPTO_memcmp(entropy + i - CRNGT_BLOCK_SIZE, entropy + i,
|
||||
@@ -207,31 +288,24 @@ static void rand_get_seed(struct rand_thread_state *state,
|
||||
|
||||
OPENSSL_memcpy(seed, entropy, CTR_DRBG_ENTROPY_LEN);
|
||||
|
||||
for (size_t i = 1; i < FIPS_OVERREAD; i++) {
|
||||
for (size_t i = 1; i < BORINGSSL_FIPS_OVERREAD; i++) {
|
||||
for (size_t j = 0; j < CTR_DRBG_ENTROPY_LEN; j++) {
|
||||
seed[j] ^= entropy[CTR_DRBG_ENTROPY_LEN * i + j];
|
||||
}
|
||||
}
|
||||
|
||||
#if defined(OPENSSL_URANDOM)
|
||||
// If we used RDRAND, also opportunistically read from the system. This avoids
|
||||
// solely relying on the hardware once the entropy pool has been initialized.
|
||||
if (used_rdrand) {
|
||||
CRYPTO_sysrand_if_available(entropy, CTR_DRBG_ENTROPY_LEN);
|
||||
for (size_t i = 0; i < CTR_DRBG_ENTROPY_LEN; i++) {
|
||||
seed[i] ^= entropy[i];
|
||||
}
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
#else
|
||||
|
||||
// rand_get_seed fills |seed| with entropy and sets |*out_used_cpu| to one if
|
||||
// that entropy came directly from the CPU and zero otherwise.
|
||||
static void rand_get_seed(struct rand_thread_state *state,
|
||||
uint8_t seed[CTR_DRBG_ENTROPY_LEN]) {
|
||||
uint8_t seed[CTR_DRBG_ENTROPY_LEN],
|
||||
int *out_used_cpu) {
|
||||
// If not in FIPS mode, we don't overread from the system entropy source and
|
||||
// we don't depend only on the hardware RDRAND.
|
||||
CRYPTO_sysrand(seed, CTR_DRBG_ENTROPY_LEN);
|
||||
*out_used_cpu = 0;
|
||||
}
|
||||
|
||||
#endif
|
||||
@@ -290,8 +364,23 @@ void RAND_bytes_with_additional_data(uint8_t *out, size_t out_len,
|
||||
|
||||
state->last_block_valid = 0;
|
||||
uint8_t seed[CTR_DRBG_ENTROPY_LEN];
|
||||
rand_get_seed(state, seed);
|
||||
if (!CTR_DRBG_init(&state->drbg, seed, NULL, 0)) {
|
||||
int used_cpu;
|
||||
rand_get_seed(state, seed, &used_cpu);
|
||||
|
||||
uint8_t personalization[CTR_DRBG_ENTROPY_LEN];
|
||||
size_t personalization_len = 0;
|
||||
#if defined(OPENSSL_URANDOM)
|
||||
// If we used RDRAND, also opportunistically read from the system. This
|
||||
// avoids solely relying on the hardware once the entropy pool has been
|
||||
// initialized.
|
||||
if (used_cpu &&
|
||||
CRYPTO_sysrand_if_available(personalization, sizeof(personalization))) {
|
||||
personalization_len = sizeof(personalization);
|
||||
}
|
||||
#endif
|
||||
|
||||
if (!CTR_DRBG_init(&state->drbg, seed, personalization,
|
||||
personalization_len)) {
|
||||
abort();
|
||||
}
|
||||
state->calls = 0;
|
||||
@@ -315,7 +404,8 @@ void RAND_bytes_with_additional_data(uint8_t *out, size_t out_len,
|
||||
if (state->calls >= kReseedInterval ||
|
||||
state->fork_generation != fork_generation) {
|
||||
uint8_t seed[CTR_DRBG_ENTROPY_LEN];
|
||||
rand_get_seed(state, seed);
|
||||
int used_cpu;
|
||||
rand_get_seed(state, seed, &used_cpu);
|
||||
#if defined(BORINGSSL_FIPS)
|
||||
// Take a read lock around accesses to |state->drbg|. This is needed to
|
||||
// avoid returning bad entropy if we race with
|
||||
|
||||
@@ -366,14 +366,7 @@ void CRYPTO_sysrand_for_seed(uint8_t *out, size_t requested) {
|
||||
perror("entropy fill failed");
|
||||
abort();
|
||||
}
|
||||
|
||||
#if defined(BORINGSSL_FIPS_BREAK_CRNG)
|
||||
// This breaks the "continuous random number generator test" defined in FIPS
|
||||
// 140-2, section 4.9.2, and implemented in rand_get_seed().
|
||||
OPENSSL_memset(out, 0, requested);
|
||||
#endif
|
||||
}
|
||||
|
||||
#endif // BORINGSSL_FIPS
|
||||
|
||||
int CRYPTO_sysrand_if_available(uint8_t *out, size_t requested) {
|
||||
|
||||
@@ -1316,52 +1316,72 @@ static void replace_bn_mont_ctx(BN_MONT_CTX **out, BN_MONT_CTX **in) {
|
||||
*in = NULL;
|
||||
}
|
||||
|
||||
int RSA_generate_key_ex(RSA *rsa, int bits, const BIGNUM *e_value,
|
||||
BN_GENCB *cb) {
|
||||
static int RSA_generate_key_ex_maybe_fips(RSA *rsa, int bits,
|
||||
const BIGNUM *e_value, BN_GENCB *cb,
|
||||
int check_fips) {
|
||||
RSA *tmp = NULL;
|
||||
uint32_t err;
|
||||
int ret = 0;
|
||||
|
||||
// |rsa_generate_key_impl|'s 2^-20 failure probability is too high at scale,
|
||||
// so we run the FIPS algorithm four times, bringing it down to 2^-80. We
|
||||
// should just adjust the retry limit, but FIPS 186-4 prescribes that value
|
||||
// and thus results in unnecessary complexity.
|
||||
for (int i = 0; i < 4; i++) {
|
||||
int failures = 0;
|
||||
do {
|
||||
ERR_clear_error();
|
||||
// Generate into scratch space, to avoid leaving partial work on failure.
|
||||
RSA *tmp = RSA_new();
|
||||
tmp = RSA_new();
|
||||
if (tmp == NULL) {
|
||||
return 0;
|
||||
goto out;
|
||||
}
|
||||
|
||||
if (rsa_generate_key_impl(tmp, bits, e_value, cb)) {
|
||||
replace_bignum(&rsa->n, &tmp->n);
|
||||
replace_bignum(&rsa->e, &tmp->e);
|
||||
replace_bignum(&rsa->d, &tmp->d);
|
||||
replace_bignum(&rsa->p, &tmp->p);
|
||||
replace_bignum(&rsa->q, &tmp->q);
|
||||
replace_bignum(&rsa->dmp1, &tmp->dmp1);
|
||||
replace_bignum(&rsa->dmq1, &tmp->dmq1);
|
||||
replace_bignum(&rsa->iqmp, &tmp->iqmp);
|
||||
replace_bn_mont_ctx(&rsa->mont_n, &tmp->mont_n);
|
||||
replace_bn_mont_ctx(&rsa->mont_p, &tmp->mont_p);
|
||||
replace_bn_mont_ctx(&rsa->mont_q, &tmp->mont_q);
|
||||
replace_bignum(&rsa->d_fixed, &tmp->d_fixed);
|
||||
replace_bignum(&rsa->dmp1_fixed, &tmp->dmp1_fixed);
|
||||
replace_bignum(&rsa->dmq1_fixed, &tmp->dmq1_fixed);
|
||||
replace_bignum(&rsa->inv_small_mod_large_mont,
|
||||
&tmp->inv_small_mod_large_mont);
|
||||
rsa->private_key_frozen = tmp->private_key_frozen;
|
||||
RSA_free(tmp);
|
||||
return 1;
|
||||
break;
|
||||
}
|
||||
uint32_t err = ERR_peek_error();
|
||||
|
||||
err = ERR_peek_error();
|
||||
RSA_free(tmp);
|
||||
tmp = NULL;
|
||||
failures++;
|
||||
|
||||
// Only retry on |RSA_R_TOO_MANY_ITERATIONS|. This is so a caller-induced
|
||||
// failure in |BN_GENCB_call| is still fatal.
|
||||
if (ERR_GET_LIB(err) != ERR_LIB_RSA ||
|
||||
ERR_GET_REASON(err) != RSA_R_TOO_MANY_ITERATIONS) {
|
||||
return 0;
|
||||
}
|
||||
} while (failures < 4 && ERR_GET_LIB(err) == ERR_LIB_RSA &&
|
||||
ERR_GET_REASON(err) == RSA_R_TOO_MANY_ITERATIONS);
|
||||
|
||||
if (tmp == NULL || (check_fips && !RSA_check_fips(tmp))) {
|
||||
goto out;
|
||||
}
|
||||
|
||||
return 0;
|
||||
replace_bignum(&rsa->n, &tmp->n);
|
||||
replace_bignum(&rsa->e, &tmp->e);
|
||||
replace_bignum(&rsa->d, &tmp->d);
|
||||
replace_bignum(&rsa->p, &tmp->p);
|
||||
replace_bignum(&rsa->q, &tmp->q);
|
||||
replace_bignum(&rsa->dmp1, &tmp->dmp1);
|
||||
replace_bignum(&rsa->dmq1, &tmp->dmq1);
|
||||
replace_bignum(&rsa->iqmp, &tmp->iqmp);
|
||||
replace_bn_mont_ctx(&rsa->mont_n, &tmp->mont_n);
|
||||
replace_bn_mont_ctx(&rsa->mont_p, &tmp->mont_p);
|
||||
replace_bn_mont_ctx(&rsa->mont_q, &tmp->mont_q);
|
||||
replace_bignum(&rsa->d_fixed, &tmp->d_fixed);
|
||||
replace_bignum(&rsa->dmp1_fixed, &tmp->dmp1_fixed);
|
||||
replace_bignum(&rsa->dmq1_fixed, &tmp->dmq1_fixed);
|
||||
replace_bignum(&rsa->inv_small_mod_large_mont,
|
||||
&tmp->inv_small_mod_large_mont);
|
||||
rsa->private_key_frozen = tmp->private_key_frozen;
|
||||
ret = 1;
|
||||
|
||||
out:
|
||||
RSA_free(tmp);
|
||||
return ret;
|
||||
}
|
||||
|
||||
int RSA_generate_key_ex(RSA *rsa, int bits, const BIGNUM *e_value,
|
||||
BN_GENCB *cb) {
|
||||
return RSA_generate_key_ex_maybe_fips(rsa, bits, e_value, cb,
|
||||
/*check_fips=*/0);
|
||||
}
|
||||
|
||||
int RSA_generate_key_fips(RSA *rsa, int bits, BN_GENCB *cb) {
|
||||
@@ -1377,8 +1397,7 @@ int RSA_generate_key_fips(RSA *rsa, int bits, BN_GENCB *cb) {
|
||||
BIGNUM *e = BN_new();
|
||||
int ret = e != NULL &&
|
||||
BN_set_word(e, RSA_F4) &&
|
||||
RSA_generate_key_ex(rsa, bits, e, cb) &&
|
||||
RSA_check_fips(rsa);
|
||||
RSA_generate_key_ex_maybe_fips(rsa, bits, e, cb, /*check_fips=*/1);
|
||||
BN_free(e);
|
||||
return ret;
|
||||
}
|
||||
|
||||
@@ -21,6 +21,7 @@
|
||||
#include <CCryptoBoringSSL_aes.h>
|
||||
#include <CCryptoBoringSSL_bn.h>
|
||||
#include <CCryptoBoringSSL_des.h>
|
||||
#include <CCryptoBoringSSL_dh.h>
|
||||
#include <CCryptoBoringSSL_digest.h>
|
||||
#include <CCryptoBoringSSL_ec.h>
|
||||
#include <CCryptoBoringSSL_ecdsa.h>
|
||||
@@ -246,6 +247,77 @@ static EC_KEY *self_test_ecdsa_key(void) {
|
||||
return ec_key;
|
||||
}
|
||||
|
||||
static DH *self_test_dh(void) {
|
||||
// This is the prime from https://tools.ietf.org/html/rfc7919#appendix-A.1,
|
||||
// which is specifically approved for FIPS in appendix D of SP 800-56Ar3.
|
||||
static const BN_ULONG kFFDHE2048Data[] = {
|
||||
TOBN(0xffffffff, 0xffffffff), TOBN(0x886b4238, 0x61285c97),
|
||||
TOBN(0xc6f34a26, 0xc1b2effa), TOBN(0xc58ef183, 0x7d1683b2),
|
||||
TOBN(0x3bb5fcbc, 0x2ec22005), TOBN(0xc3fe3b1b, 0x4c6fad73),
|
||||
TOBN(0x8e4f1232, 0xeef28183), TOBN(0x9172fe9c, 0xe98583ff),
|
||||
TOBN(0xc03404cd, 0x28342f61), TOBN(0x9e02fce1, 0xcdf7e2ec),
|
||||
TOBN(0x0b07a7c8, 0xee0a6d70), TOBN(0xae56ede7, 0x6372bb19),
|
||||
TOBN(0x1d4f42a3, 0xde394df4), TOBN(0xb96adab7, 0x60d7f468),
|
||||
TOBN(0xd108a94b, 0xb2c8e3fb), TOBN(0xbc0ab182, 0xb324fb61),
|
||||
TOBN(0x30acca4f, 0x483a797a), TOBN(0x1df158a1, 0x36ade735),
|
||||
TOBN(0xe2a689da, 0xf3efe872), TOBN(0x984f0c70, 0xe0e68b77),
|
||||
TOBN(0xb557135e, 0x7f57c935), TOBN(0x85636555, 0x3ded1af3),
|
||||
TOBN(0x2433f51f, 0x5f066ed0), TOBN(0xd3df1ed5, 0xd5fd6561),
|
||||
TOBN(0xf681b202, 0xaec4617a), TOBN(0x7d2fe363, 0x630c75d8),
|
||||
TOBN(0xcc939dce, 0x249b3ef9), TOBN(0xa9e13641, 0x146433fb),
|
||||
TOBN(0xd8b9c583, 0xce2d3695), TOBN(0xafdc5620, 0x273d3cf1),
|
||||
TOBN(0xadf85458, 0xa2bb4a9a), TOBN(0xffffffff, 0xffffffff),
|
||||
};
|
||||
|
||||
// kFFDHE2048PrivateKeyData is a 225-bit value. (225 because that's the
|
||||
// minimum private key size in
|
||||
// https://tools.ietf.org/html/rfc7919#appendix-A.1.)
|
||||
static const BN_ULONG kFFDHE2048PrivateKeyData[] = {
|
||||
TOBN(0x187be36b, 0xd38a4fa1),
|
||||
TOBN(0x0a152f39, 0x6458f3b8),
|
||||
TOBN(0x0570187e, 0xc422eeb7),
|
||||
TOBN(0x00000001, 0x91173f2a),
|
||||
};
|
||||
|
||||
BIGNUM *const ffdhe2048_p = BN_new();
|
||||
BIGNUM *const ffdhe2048_q = BN_new();
|
||||
BIGNUM *const ffdhe2048_g = BN_new();
|
||||
BIGNUM *ffdhe2048_priv = BN_new();
|
||||
DH *const dh = DH_new();
|
||||
|
||||
if (!ffdhe2048_p || !ffdhe2048_q || !ffdhe2048_g || !ffdhe2048_priv || !dh) {
|
||||
goto err;
|
||||
}
|
||||
|
||||
bn_set_static_words(ffdhe2048_p, kFFDHE2048Data,
|
||||
OPENSSL_ARRAY_SIZE(kFFDHE2048Data));
|
||||
bn_set_static_words(ffdhe2048_priv, kFFDHE2048PrivateKeyData,
|
||||
OPENSSL_ARRAY_SIZE(kFFDHE2048PrivateKeyData));
|
||||
|
||||
if (!BN_copy(ffdhe2048_q, ffdhe2048_p) ||
|
||||
!BN_sub_word(ffdhe2048_q, 1) ||
|
||||
BN_div_word(ffdhe2048_q, 2) != 0 ||
|
||||
!BN_set_word(ffdhe2048_g, 2) ||
|
||||
!DH_set0_key(dh, NULL, ffdhe2048_priv)) {
|
||||
goto err;
|
||||
}
|
||||
|
||||
ffdhe2048_priv = NULL;
|
||||
if (!DH_set0_pqg(dh, ffdhe2048_p, ffdhe2048_q, ffdhe2048_g)) {
|
||||
goto err;
|
||||
}
|
||||
|
||||
return dh;
|
||||
|
||||
err:
|
||||
BN_free(ffdhe2048_p);
|
||||
BN_free(ffdhe2048_q);
|
||||
BN_free(ffdhe2048_g);
|
||||
BN_free(ffdhe2048_priv);
|
||||
DH_free(dh);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
#if defined(OPENSSL_ANDROID)
|
||||
static const size_t kModuleDigestSize = SHA256_DIGEST_LENGTH;
|
||||
#else
|
||||
@@ -487,6 +559,57 @@ int boringssl_fips_self_test(
|
||||
0x31, 0x1e, 0x2b, 0x21, 0x41, 0x8d, 0x32, 0x81,
|
||||
};
|
||||
|
||||
// kFFDHE2048PublicValueData is an arbitrary public value, mod
|
||||
// kFFDHE2048Data. (The private key happens to be 4096.)
|
||||
static const BN_ULONG kFFDHE2048PublicValueData[] = {
|
||||
TOBN(0x187be36b, 0xd38a4fa1), TOBN(0x0a152f39, 0x6458f3b8),
|
||||
TOBN(0x0570187e, 0xc422eeb7), TOBN(0x18af7482, 0x91173f2a),
|
||||
TOBN(0xe9fdac6a, 0xcff4eaaa), TOBN(0xf6afebb7, 0x6e589d6c),
|
||||
TOBN(0xf92f8e9a, 0xb7e33fb0), TOBN(0x70acf2aa, 0x4cf36ddd),
|
||||
TOBN(0x561ab426, 0xd07137fd), TOBN(0x5f57d037, 0x430ee91e),
|
||||
TOBN(0xe3e768c8, 0x60d10b8a), TOBN(0xb14884d8, 0xa18af8ce),
|
||||
TOBN(0xf8a98014, 0xa12b74e4), TOBN(0x748d407c, 0x3437b7a8),
|
||||
TOBN(0x627588c4, 0x9875d5a7), TOBN(0xdd24a127, 0x53c8f09d),
|
||||
TOBN(0x85a997d5, 0x0cd51aec), TOBN(0x44f0c619, 0xce348458),
|
||||
TOBN(0x9b894b24, 0x5f6b69a1), TOBN(0xae1302f2, 0xf6d4777e),
|
||||
TOBN(0xe6678eeb, 0x375db18e), TOBN(0x2674e1d6, 0x4fbcbdc8),
|
||||
TOBN(0xb297a823, 0x6fa93d28), TOBN(0x6a12fb70, 0x7c8c0510),
|
||||
TOBN(0x5c6d1aeb, 0xdb06f65b), TOBN(0xe8c2954e, 0x4c1804ca),
|
||||
TOBN(0x06bdeac1, 0xf5500fa7), TOBN(0x6a315604, 0x189cd76b),
|
||||
TOBN(0xbae7b0b3, 0x6e362dc0), TOBN(0xa57c73bd, 0xdc70fb82),
|
||||
TOBN(0xfaff50d2, 0x9d573457), TOBN(0x352bd399, 0xbe84058e),
|
||||
};
|
||||
|
||||
const uint8_t kDHOutput[2048 / 8] = {
|
||||
0x2a, 0xe6, 0xd3, 0xa6, 0x13, 0x58, 0x8e, 0xce, 0x53, 0xaa, 0xf6, 0x5d,
|
||||
0x9a, 0xae, 0x02, 0x12, 0xf5, 0x80, 0x3d, 0x06, 0x09, 0x76, 0xac, 0x57,
|
||||
0x37, 0x9e, 0xab, 0x38, 0x62, 0x25, 0x05, 0x1d, 0xf3, 0xa9, 0x39, 0x60,
|
||||
0xf6, 0xae, 0x90, 0xed, 0x1e, 0xad, 0x6e, 0xe9, 0xe3, 0xba, 0x27, 0xf6,
|
||||
0xdb, 0x54, 0xdf, 0xe2, 0xbd, 0xbb, 0x7f, 0xf1, 0x81, 0xac, 0x1a, 0xfa,
|
||||
0xdb, 0x87, 0x07, 0x98, 0x76, 0x90, 0x21, 0xf2, 0xae, 0xda, 0x0d, 0x84,
|
||||
0x97, 0x64, 0x0b, 0xbf, 0xb8, 0x8d, 0x10, 0x46, 0xe2, 0xd5, 0xca, 0x1b,
|
||||
0xbb, 0xe5, 0x37, 0xb2, 0x3b, 0x35, 0xd3, 0x1b, 0x65, 0xea, 0xae, 0xf2,
|
||||
0x03, 0xe2, 0xb6, 0xde, 0x22, 0xb7, 0x86, 0x49, 0x79, 0xfe, 0xd7, 0x16,
|
||||
0xf7, 0xdc, 0x9c, 0x59, 0xf5, 0xb7, 0x70, 0xc0, 0x53, 0x42, 0x6f, 0xb1,
|
||||
0xd2, 0x4e, 0x00, 0x25, 0x4b, 0x2d, 0x5a, 0x9b, 0xd0, 0xe9, 0x27, 0x43,
|
||||
0xcc, 0x00, 0x66, 0xea, 0x94, 0x7a, 0x0b, 0xb9, 0x89, 0x0c, 0x5e, 0x94,
|
||||
0xb8, 0x3a, 0x78, 0x9c, 0x4d, 0x84, 0xe6, 0x32, 0x2c, 0x38, 0x7c, 0xf7,
|
||||
0x43, 0x9c, 0xd8, 0xb8, 0x1c, 0xce, 0x24, 0x91, 0x20, 0x67, 0x7a, 0x54,
|
||||
0x1f, 0x7e, 0x86, 0x7f, 0xa1, 0xc1, 0x03, 0x4e, 0x2c, 0x26, 0x71, 0xb2,
|
||||
0x06, 0x30, 0xb3, 0x6c, 0x15, 0xcc, 0xac, 0x25, 0xe5, 0x37, 0x3f, 0x24,
|
||||
0x8f, 0x2a, 0x89, 0x5e, 0x3d, 0x43, 0x94, 0xc9, 0x36, 0xae, 0x40, 0x00,
|
||||
0x6a, 0x0d, 0xb0, 0x6e, 0x8b, 0x2e, 0x70, 0x57, 0xe1, 0x88, 0x53, 0xd6,
|
||||
0x06, 0x80, 0x2a, 0x4e, 0x5a, 0xf0, 0x1e, 0xaa, 0xcb, 0xab, 0x06, 0x0e,
|
||||
0x27, 0x0f, 0xd9, 0x88, 0xd9, 0x01, 0xe3, 0x07, 0xeb, 0xdf, 0xc3, 0x12,
|
||||
0xe3, 0x40, 0x88, 0x7b, 0x5f, 0x59, 0x78, 0x6e, 0x26, 0x20, 0xc3, 0xdf,
|
||||
0xc8, 0xe4, 0x5e,
|
||||
#if !defined(BORINGSSL_FIPS_BREAK_FFC_DH)
|
||||
0xb8,
|
||||
#else
|
||||
0x00,
|
||||
#endif
|
||||
};
|
||||
|
||||
EVP_AEAD_CTX aead_ctx;
|
||||
EVP_AEAD_CTX_zero(&aead_ctx);
|
||||
RSA *rsa_key = NULL;
|
||||
@@ -692,6 +815,29 @@ int boringssl_fips_self_test(
|
||||
goto err;
|
||||
}
|
||||
|
||||
// FFC Diffie-Hellman KAT
|
||||
|
||||
BIGNUM *const ffdhe2048_value = BN_new();
|
||||
DH *const dh = self_test_dh();
|
||||
int dh_ok = 0;
|
||||
if (ffdhe2048_value && dh) {
|
||||
bn_set_static_words(ffdhe2048_value, kFFDHE2048PublicValueData,
|
||||
OPENSSL_ARRAY_SIZE(kFFDHE2048PublicValueData));
|
||||
|
||||
uint8_t dh_out[sizeof(kDHOutput)];
|
||||
dh_ok =
|
||||
sizeof(dh_out) == DH_size(dh) &&
|
||||
DH_compute_key_padded(dh_out, ffdhe2048_value, dh) == sizeof(dh_out) &&
|
||||
check_test(kDHOutput, dh_out, sizeof(dh_out), "FFC DH");
|
||||
}
|
||||
|
||||
BN_free(ffdhe2048_value);
|
||||
DH_free(dh);
|
||||
if (!dh_ok) {
|
||||
fprintf(stderr, "FFDH failed.\n");
|
||||
goto err;
|
||||
}
|
||||
|
||||
// DBRG KAT
|
||||
CTR_DRBG_STATE drbg;
|
||||
if (!CTR_DRBG_init(&drbg, kDRBGEntropy, kDRBGPersonalization,
|
||||
|
||||
@@ -19,6 +19,7 @@
|
||||
.text
|
||||
|
||||
|
||||
.private_extern _OPENSSL_armcap_P
|
||||
.globl _sha1_block_data_order
|
||||
.private_extern _sha1_block_data_order
|
||||
|
||||
@@ -1233,8 +1234,6 @@ Lconst:
|
||||
.byte 83,72,65,49,32,98,108,111,99,107,32,116,114,97,110,115,102,111,114,109,32,102,111,114,32,65,82,77,118,56,44,32,67,82,89,80,84,79,71,65,77,83,32,98,121,32,60,97,112,112,114,111,64,111,112,101,110,115,115,108,46,111,114,103,62,0
|
||||
.align 2
|
||||
.align 2
|
||||
.comm _OPENSSL_armcap_P,4,4
|
||||
.private_extern _OPENSSL_armcap_P
|
||||
#endif // !OPENSSL_NO_ASM
|
||||
#endif // defined(__aarch64__) && defined(__APPLE__)
|
||||
#if defined(__linux__) && defined(__ELF__)
|
||||
|
||||
@@ -20,6 +20,7 @@
|
||||
.text
|
||||
|
||||
|
||||
.hidden OPENSSL_armcap_P
|
||||
.globl sha1_block_data_order
|
||||
.hidden sha1_block_data_order
|
||||
.type sha1_block_data_order,%function
|
||||
@@ -1234,8 +1235,6 @@ sha1_block_armv8:
|
||||
.byte 83,72,65,49,32,98,108,111,99,107,32,116,114,97,110,115,102,111,114,109,32,102,111,114,32,65,82,77,118,56,44,32,67,82,89,80,84,79,71,65,77,83,32,98,121,32,60,97,112,112,114,111,64,111,112,101,110,115,115,108,46,111,114,103,62,0
|
||||
.align 2
|
||||
.align 2
|
||||
.comm OPENSSL_armcap_P,4,4
|
||||
.hidden OPENSSL_armcap_P
|
||||
#endif
|
||||
#endif // !OPENSSL_NO_ASM
|
||||
.section .note.GNU-stack,"",%progbits
|
||||
|
||||
@@ -60,6 +60,7 @@
|
||||
.text
|
||||
|
||||
|
||||
.private_extern _OPENSSL_armcap_P
|
||||
.globl _sha256_block_data_order
|
||||
.private_extern _sha256_block_data_order
|
||||
|
||||
@@ -1208,10 +1209,6 @@ Loop_hw:
|
||||
ldr x29,[sp],#16
|
||||
ret
|
||||
|
||||
#endif
|
||||
#ifndef __KERNEL__
|
||||
.comm _OPENSSL_armcap_P,4,4
|
||||
.private_extern _OPENSSL_armcap_P
|
||||
#endif
|
||||
#endif // !OPENSSL_NO_ASM
|
||||
#endif // defined(__aarch64__) && defined(__APPLE__)
|
||||
|
||||
@@ -61,6 +61,7 @@
|
||||
.text
|
||||
|
||||
|
||||
.hidden OPENSSL_armcap_P
|
||||
.globl sha256_block_data_order
|
||||
.hidden sha256_block_data_order
|
||||
.type sha256_block_data_order,%function
|
||||
@@ -1210,10 +1211,6 @@ sha256_block_armv8:
|
||||
ret
|
||||
.size sha256_block_armv8,.-sha256_block_armv8
|
||||
#endif
|
||||
#ifndef __KERNEL__
|
||||
.comm OPENSSL_armcap_P,4,4
|
||||
.hidden OPENSSL_armcap_P
|
||||
#endif
|
||||
#endif
|
||||
#endif // !OPENSSL_NO_ASM
|
||||
.section .note.GNU-stack,"",%progbits
|
||||
|
||||
@@ -60,6 +60,7 @@
|
||||
.text
|
||||
|
||||
|
||||
.private_extern _OPENSSL_armcap_P
|
||||
.globl _sha512_block_data_order
|
||||
.private_extern _sha512_block_data_order
|
||||
|
||||
@@ -1079,10 +1080,6 @@ LK512:
|
||||
.byte 83,72,65,53,49,50,32,98,108,111,99,107,32,116,114,97,110,115,102,111,114,109,32,102,111,114,32,65,82,77,118,56,44,32,67,82,89,80,84,79,71,65,77,83,32,98,121,32,60,97,112,112,114,111,64,111,112,101,110,115,115,108,46,111,114,103,62,0
|
||||
.align 2
|
||||
.align 2
|
||||
#ifndef __KERNEL__
|
||||
.comm _OPENSSL_armcap_P,4,4
|
||||
.private_extern _OPENSSL_armcap_P
|
||||
#endif
|
||||
#endif // !OPENSSL_NO_ASM
|
||||
#endif // defined(__aarch64__) && defined(__APPLE__)
|
||||
#if defined(__linux__) && defined(__ELF__)
|
||||
|
||||
@@ -61,6 +61,7 @@
|
||||
.text
|
||||
|
||||
|
||||
.hidden OPENSSL_armcap_P
|
||||
.globl sha512_block_data_order
|
||||
.hidden sha512_block_data_order
|
||||
.type sha512_block_data_order,%function
|
||||
@@ -1080,10 +1081,6 @@ sha512_block_data_order:
|
||||
.byte 83,72,65,53,49,50,32,98,108,111,99,107,32,116,114,97,110,115,102,111,114,109,32,102,111,114,32,65,82,77,118,56,44,32,67,82,89,80,84,79,71,65,77,83,32,98,121,32,60,97,112,112,114,111,64,111,112,101,110,115,115,108,46,111,114,103,62,0
|
||||
.align 2
|
||||
.align 2
|
||||
#ifndef __KERNEL__
|
||||
.comm OPENSSL_armcap_P,4,4
|
||||
.hidden OPENSSL_armcap_P
|
||||
#endif
|
||||
#endif
|
||||
#endif // !OPENSSL_NO_ASM
|
||||
.section .note.GNU-stack,"",%progbits
|
||||
|
||||
@@ -1010,7 +1010,7 @@ Lschedule_mangle_dec:
|
||||
|
||||
Lschedule_mangle_both:
|
||||
tbl v3.16b, {v3.16b}, v1.16b // vpshufb %xmm1, %xmm3, %xmm3
|
||||
add x8, x8, #64-16 // add $-16, %r8
|
||||
add x8, x8, #48 // add $-16, %r8
|
||||
and x8, x8, #~(1<<6) // and $0x30, %r8
|
||||
st1 {v3.2d}, [x2] // vmovdqu %xmm3, (%rdx)
|
||||
ret
|
||||
|
||||
@@ -1011,7 +1011,7 @@ _vpaes_schedule_mangle:
|
||||
|
||||
.Lschedule_mangle_both:
|
||||
tbl v3.16b, {v3.16b}, v1.16b // vpshufb %xmm1, %xmm3, %xmm3
|
||||
add x8, x8, #64-16 // add $-16, %r8
|
||||
add x8, x8, #48 // add $-16, %r8
|
||||
and x8, x8, #~(1<<6) // and $0x30, %r8
|
||||
st1 {v3.2d}, [x2] // vmovdqu %xmm3, (%rdx)
|
||||
ret
|
||||
|
||||
@@ -27,7 +27,7 @@
|
||||
#include "internal.h"
|
||||
|
||||
|
||||
// This file implements draft-irtf-cfrg-hpke-05.
|
||||
// This file implements draft-irtf-cfrg-hpke-07.
|
||||
|
||||
#define KEM_CONTEXT_LEN (2 * X25519_PUBLIC_VALUE_LEN)
|
||||
|
||||
@@ -40,7 +40,7 @@
|
||||
#define HPKE_MODE_BASE 0
|
||||
#define HPKE_MODE_PSK 1
|
||||
|
||||
static const char kHpkeRfcId[] = "HPKE-05 ";
|
||||
static const char kHpkeRfcId[] = "HPKE-07";
|
||||
|
||||
static int add_label_string(CBB *cbb, const char *label) {
|
||||
return CBB_add_bytes(cbb, (const uint8_t *)label, strlen(label));
|
||||
@@ -125,7 +125,7 @@ static int hpke_extract_and_expand(const EVP_MD *hkdf_md, uint8_t *out_key,
|
||||
return 1;
|
||||
}
|
||||
|
||||
static const EVP_AEAD *hpke_get_aead(uint16_t aead_id) {
|
||||
const EVP_AEAD *EVP_HPKE_get_aead(uint16_t aead_id) {
|
||||
switch (aead_id) {
|
||||
case EVP_HPKE_AEAD_AES_GCM_128:
|
||||
return EVP_aead_aes_128_gcm();
|
||||
@@ -138,7 +138,7 @@ static const EVP_AEAD *hpke_get_aead(uint16_t aead_id) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
static const EVP_MD *hpke_get_kdf(uint16_t kdf_id) {
|
||||
const EVP_MD *EVP_HPKE_get_hkdf_md(uint16_t kdf_id) {
|
||||
switch (kdf_id) {
|
||||
case EVP_HPKE_HKDF_SHA256:
|
||||
return EVP_sha256();
|
||||
@@ -174,7 +174,7 @@ static int hpke_key_schedule(EVP_HPKE_CTX *hpke, uint8_t mode,
|
||||
}
|
||||
|
||||
// Attempt to get an EVP_AEAD*.
|
||||
const EVP_AEAD *aead = hpke_get_aead(hpke->aead_id);
|
||||
const EVP_AEAD *aead = EVP_HPKE_get_aead(hpke->aead_id);
|
||||
if (aead == NULL) {
|
||||
return 0;
|
||||
}
|
||||
@@ -216,24 +216,13 @@ static int hpke_key_schedule(EVP_HPKE_CTX *hpke, uint8_t mode,
|
||||
return 0;
|
||||
}
|
||||
|
||||
// psk_hash = LabeledExtract("", "psk_hash", psk)
|
||||
static const char kPskHashLabel[] = "psk_hash";
|
||||
uint8_t psk_hash[EVP_MAX_MD_SIZE];
|
||||
size_t psk_hash_len;
|
||||
if (!hpke_labeled_extract(hpke->hkdf_md, psk_hash, &psk_hash_len, NULL, 0,
|
||||
suite_id, sizeof(suite_id), kPskHashLabel, psk,
|
||||
psk_len)) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
// secret = LabeledExtract(psk_hash, "secret", shared_secret)
|
||||
// secret = LabeledExtract(shared_secret, "secret", psk)
|
||||
static const char kSecretExtractLabel[] = "secret";
|
||||
uint8_t secret[EVP_MAX_MD_SIZE];
|
||||
size_t secret_len;
|
||||
if (!hpke_labeled_extract(hpke->hkdf_md, secret, &secret_len, psk_hash,
|
||||
psk_hash_len, suite_id, sizeof(suite_id),
|
||||
kSecretExtractLabel, shared_secret,
|
||||
shared_secret_len)) {
|
||||
if (!hpke_labeled_extract(hpke->hkdf_md, secret, &secret_len, shared_secret,
|
||||
shared_secret_len, suite_id, sizeof(suite_id),
|
||||
kSecretExtractLabel, psk, psk_len)) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -252,9 +241,9 @@ static int hpke_key_schedule(EVP_HPKE_CTX *hpke, uint8_t mode,
|
||||
return 0;
|
||||
}
|
||||
|
||||
// nonce = LabeledExpand(secret, "nonce", key_schedule_context, Nn)
|
||||
static const char kNonceExpandLabel[] = "nonce";
|
||||
if (!hpke_labeled_expand(hpke->hkdf_md, hpke->nonce,
|
||||
// base_nonce = LabeledExpand(secret, "base_nonce", key_schedule_context, Nn)
|
||||
static const char kNonceExpandLabel[] = "base_nonce";
|
||||
if (!hpke_labeled_expand(hpke->hkdf_md, hpke->base_nonce,
|
||||
EVP_AEAD_nonce_length(aead), secret, secret_len,
|
||||
suite_id, sizeof(suite_id), kNonceExpandLabel,
|
||||
context, context_len)) {
|
||||
@@ -351,7 +340,7 @@ int EVP_HPKE_CTX_setup_base_s_x25519_for_test(
|
||||
hpke->is_sender = 1;
|
||||
hpke->kdf_id = kdf_id;
|
||||
hpke->aead_id = aead_id;
|
||||
hpke->hkdf_md = hpke_get_kdf(kdf_id);
|
||||
hpke->hkdf_md = EVP_HPKE_get_hkdf_md(kdf_id);
|
||||
if (hpke->hkdf_md == NULL) {
|
||||
return 0;
|
||||
}
|
||||
@@ -375,7 +364,7 @@ int EVP_HPKE_CTX_setup_base_r_x25519(
|
||||
hpke->is_sender = 0;
|
||||
hpke->kdf_id = kdf_id;
|
||||
hpke->aead_id = aead_id;
|
||||
hpke->hkdf_md = hpke_get_kdf(kdf_id);
|
||||
hpke->hkdf_md = EVP_HPKE_get_hkdf_md(kdf_id);
|
||||
if (hpke->hkdf_md == NULL) {
|
||||
return 0;
|
||||
}
|
||||
@@ -415,7 +404,7 @@ int EVP_HPKE_CTX_setup_psk_s_x25519_for_test(
|
||||
hpke->is_sender = 1;
|
||||
hpke->kdf_id = kdf_id;
|
||||
hpke->aead_id = aead_id;
|
||||
hpke->hkdf_md = hpke_get_kdf(kdf_id);
|
||||
hpke->hkdf_md = EVP_HPKE_get_hkdf_md(kdf_id);
|
||||
if (hpke->hkdf_md == NULL) {
|
||||
return 0;
|
||||
}
|
||||
@@ -440,7 +429,7 @@ int EVP_HPKE_CTX_setup_psk_r_x25519(
|
||||
hpke->is_sender = 0;
|
||||
hpke->kdf_id = kdf_id;
|
||||
hpke->aead_id = aead_id;
|
||||
hpke->hkdf_md = hpke_get_kdf(kdf_id);
|
||||
hpke->hkdf_md = EVP_HPKE_get_hkdf_md(kdf_id);
|
||||
if (hpke->hkdf_md == NULL) {
|
||||
return 0;
|
||||
}
|
||||
@@ -466,9 +455,9 @@ static void hpke_nonce(const EVP_HPKE_CTX *hpke, uint8_t *out_nonce,
|
||||
seq_copy >>= 8;
|
||||
}
|
||||
|
||||
// XOR the encoded sequence with the |hpke->nonce|.
|
||||
// XOR the encoded sequence with the |hpke->base_nonce|.
|
||||
for (size_t i = 0; i < nonce_len; i++) {
|
||||
out_nonce[i] ^= hpke->nonce[i];
|
||||
out_nonce[i] ^= hpke->base_nonce[i];
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -18,6 +18,7 @@
|
||||
#include <CCryptoBoringSSL_aead.h>
|
||||
#include <CCryptoBoringSSL_base.h>
|
||||
#include <CCryptoBoringSSL_curve25519.h>
|
||||
#include <CCryptoBoringSSL_digest.h>
|
||||
|
||||
#if defined(__cplusplus)
|
||||
extern "C" {
|
||||
@@ -30,7 +31,7 @@ extern "C" {
|
||||
// receiver with a public key. Optionally, the sender may authenticate its
|
||||
// possession of a pre-shared key to the recipient.
|
||||
//
|
||||
// See https://tools.ietf.org/html/draft-irtf-cfrg-hpke-05.
|
||||
// See https://tools.ietf.org/html/draft-irtf-cfrg-hpke-07.
|
||||
|
||||
// EVP_HPKE_AEAD_* are AEAD identifiers.
|
||||
#define EVP_HPKE_AEAD_AES_GCM_128 0x0001
|
||||
@@ -55,7 +56,7 @@ typedef struct evp_hpke_ctx_st {
|
||||
EVP_AEAD_CTX aead_ctx;
|
||||
uint16_t kdf_id;
|
||||
uint16_t aead_id;
|
||||
uint8_t nonce[EVP_AEAD_MAX_NONCE_LENGTH];
|
||||
uint8_t base_nonce[EVP_AEAD_MAX_NONCE_LENGTH];
|
||||
uint8_t exporter_secret[EVP_MAX_MD_SIZE];
|
||||
uint64_t seq;
|
||||
int is_sender;
|
||||
@@ -77,8 +78,8 @@ OPENSSL_EXPORT void EVP_HPKE_CTX_cleanup(EVP_HPKE_CTX *ctx);
|
||||
// In each of the following functions, |hpke| must have been initialized with
|
||||
// |EVP_HPKE_CTX_init|. |kdf_id| selects the KDF for non-KEM HPKE operations and
|
||||
// must be one of the |EVP_HPKE_HKDF_*| constants. |aead_id| selects the AEAD
|
||||
// for the "open" and "seal" operations and must be one of the |EVP_HPKE_AEAD_*"
|
||||
// constants."
|
||||
// for the "open" and "seal" operations and must be one of the |EVP_HPKE_AEAD_*|
|
||||
// constants.
|
||||
|
||||
// EVP_HPKE_CTX_setup_base_s_x25519 sets up |hpke| as a sender context that can
|
||||
// encrypt for the private key corresponding to |peer_public_value| (the
|
||||
@@ -215,6 +216,14 @@ OPENSSL_EXPORT int EVP_HPKE_CTX_export(const EVP_HPKE_CTX *hpke, uint8_t *out,
|
||||
// set up as a sender.
|
||||
OPENSSL_EXPORT size_t EVP_HPKE_CTX_max_overhead(const EVP_HPKE_CTX *hpke);
|
||||
|
||||
// EVP_HPKE_get_aead returns the AEAD corresponding to |aead_id|, or NULL if
|
||||
// |aead_id| is not a known AEAD identifier.
|
||||
OPENSSL_EXPORT const EVP_AEAD *EVP_HPKE_get_aead(uint16_t aead_id);
|
||||
|
||||
// EVP_HPKE_get_hkdf_md returns the hash function associated with |kdf_id|, or
|
||||
// NULL if |kdf_id| is not a known KDF identifier that uses HKDF.
|
||||
OPENSSL_EXPORT const EVP_MD *EVP_HPKE_get_hkdf_md(uint16_t kdf_id);
|
||||
|
||||
|
||||
#if defined(__cplusplus)
|
||||
} // extern C
|
||||
|
||||
@@ -46,10 +46,14 @@ struct poly1305_state_st {
|
||||
uint32_t s1, s2, s3, s4;
|
||||
uint32_t h0, h1, h2, h3, h4;
|
||||
uint8_t buf[16];
|
||||
unsigned int buf_used;
|
||||
size_t buf_used;
|
||||
uint8_t key[16];
|
||||
};
|
||||
|
||||
OPENSSL_STATIC_ASSERT(
|
||||
sizeof(struct poly1305_state_st) + 63 <= sizeof(poly1305_state),
|
||||
"poly1305_state isn't large enough to hold aligned poly1305_state_st");
|
||||
|
||||
static inline struct poly1305_state_st *poly1305_aligned_state(
|
||||
poly1305_state *state) {
|
||||
return (struct poly1305_state_st *)(((uintptr_t)state + 63) & ~63);
|
||||
@@ -200,7 +204,6 @@ void CRYPTO_poly1305_init(poly1305_state *statep, const uint8_t key[32]) {
|
||||
|
||||
void CRYPTO_poly1305_update(poly1305_state *statep, const uint8_t *in,
|
||||
size_t in_len) {
|
||||
unsigned int i;
|
||||
struct poly1305_state_st *state = poly1305_aligned_state(statep);
|
||||
|
||||
#if defined(OPENSSL_POLY1305_NEON)
|
||||
@@ -211,11 +214,11 @@ void CRYPTO_poly1305_update(poly1305_state *statep, const uint8_t *in,
|
||||
#endif
|
||||
|
||||
if (state->buf_used) {
|
||||
unsigned todo = 16 - state->buf_used;
|
||||
size_t todo = 16 - state->buf_used;
|
||||
if (todo > in_len) {
|
||||
todo = (unsigned)in_len;
|
||||
todo = in_len;
|
||||
}
|
||||
for (i = 0; i < todo; i++) {
|
||||
for (size_t i = 0; i < todo; i++) {
|
||||
state->buf[state->buf_used + i] = in[i];
|
||||
}
|
||||
state->buf_used += todo;
|
||||
@@ -236,10 +239,10 @@ void CRYPTO_poly1305_update(poly1305_state *statep, const uint8_t *in,
|
||||
}
|
||||
|
||||
if (in_len) {
|
||||
for (i = 0; i < in_len; i++) {
|
||||
for (size_t i = 0; i < in_len; i++) {
|
||||
state->buf[i] = in[i];
|
||||
}
|
||||
state->buf_used = (unsigned)in_len;
|
||||
state->buf_used = in_len;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -36,7 +36,7 @@ extern void addmulmod(fe1305x2 *r, const fe1305x2 *x, const fe1305x2 *y,
|
||||
const fe1305x2 *c);
|
||||
|
||||
extern int blocks(fe1305x2 *h, const fe1305x2 *precomp, const uint8_t *in,
|
||||
unsigned int inlen);
|
||||
size_t inlen);
|
||||
|
||||
static void freeze(fe1305x2 *r) {
|
||||
int i;
|
||||
@@ -136,7 +136,7 @@ static void fe1305x2_tobytearray(uint8_t r[16], fe1305x2 *x) {
|
||||
}
|
||||
|
||||
static void fe1305x2_frombytearray(fe1305x2 *r, const uint8_t *x, size_t xlen) {
|
||||
unsigned i;
|
||||
size_t i;
|
||||
uint8_t t[17];
|
||||
|
||||
for (i = 0; (i < 16) && (i < xlen); i++) {
|
||||
@@ -179,17 +179,20 @@ static const alignas(16) fe1305x2 zero;
|
||||
struct poly1305_state_st {
|
||||
uint8_t data[sizeof(fe1305x2[5]) + 128];
|
||||
uint8_t buf[32];
|
||||
unsigned int buf_used;
|
||||
size_t buf_used;
|
||||
uint8_t key[16];
|
||||
};
|
||||
|
||||
OPENSSL_STATIC_ASSERT(
|
||||
sizeof(struct poly1305_state_st) + 63 <= sizeof(poly1305_state),
|
||||
"poly1305_state isn't large enough to hold aligned poly1305_state_st.");
|
||||
|
||||
void CRYPTO_poly1305_init_neon(poly1305_state *state, const uint8_t key[32]) {
|
||||
struct poly1305_state_st *st = (struct poly1305_state_st *)(state);
|
||||
fe1305x2 *const r = (fe1305x2 *)(st->data + (15 & (-(int)st->data)));
|
||||
fe1305x2 *const h = r + 1;
|
||||
fe1305x2 *const c = h + 1;
|
||||
fe1305x2 *const precomp = c + 1;
|
||||
unsigned int j;
|
||||
|
||||
r->v[1] = r->v[0] = 0x3ffffff & load32(key);
|
||||
r->v[3] = r->v[2] = 0x3ffff03 & (load32(key + 3) >> 2);
|
||||
@@ -197,7 +200,7 @@ void CRYPTO_poly1305_init_neon(poly1305_state *state, const uint8_t key[32]) {
|
||||
r->v[7] = r->v[6] = 0x3f03fff & (load32(key + 9) >> 6);
|
||||
r->v[9] = r->v[8] = 0x00fffff & (load32(key + 12) >> 8);
|
||||
|
||||
for (j = 0; j < 10; j++) {
|
||||
for (size_t j = 0; j < 10; j++) {
|
||||
h->v[j] = 0; // XXX: should fast-forward a bit
|
||||
}
|
||||
|
||||
@@ -215,14 +218,13 @@ void CRYPTO_poly1305_update_neon(poly1305_state *state, const uint8_t *in,
|
||||
fe1305x2 *const h = r + 1;
|
||||
fe1305x2 *const c = h + 1;
|
||||
fe1305x2 *const precomp = c + 1;
|
||||
unsigned int i;
|
||||
|
||||
if (st->buf_used) {
|
||||
unsigned int todo = 32 - st->buf_used;
|
||||
size_t todo = 32 - st->buf_used;
|
||||
if (todo > in_len) {
|
||||
todo = in_len;
|
||||
}
|
||||
for (i = 0; i < todo; i++) {
|
||||
for (size_t i = 0; i < todo; i++) {
|
||||
st->buf[st->buf_used + i] = in[i];
|
||||
}
|
||||
st->buf_used += todo;
|
||||
@@ -232,7 +234,7 @@ void CRYPTO_poly1305_update_neon(poly1305_state *state, const uint8_t *in,
|
||||
if (st->buf_used == sizeof(st->buf) && in_len) {
|
||||
addmulmod(h, h, precomp, &zero);
|
||||
fe1305x2_frombytearray(c, st->buf, sizeof(st->buf));
|
||||
for (i = 0; i < 10; i++) {
|
||||
for (size_t i = 0; i < 10; i++) {
|
||||
h->v[i] += c->v[i];
|
||||
}
|
||||
st->buf_used = 0;
|
||||
@@ -240,7 +242,7 @@ void CRYPTO_poly1305_update_neon(poly1305_state *state, const uint8_t *in,
|
||||
}
|
||||
|
||||
while (in_len > 32) {
|
||||
unsigned int tlen = 1048576;
|
||||
size_t tlen = 1048576;
|
||||
if (in_len < tlen) {
|
||||
tlen = in_len;
|
||||
}
|
||||
@@ -250,7 +252,7 @@ void CRYPTO_poly1305_update_neon(poly1305_state *state, const uint8_t *in,
|
||||
}
|
||||
|
||||
if (in_len) {
|
||||
for (i = 0; i < in_len; i++) {
|
||||
for (size_t i = 0; i < in_len; i++) {
|
||||
st->buf[i] = in[i];
|
||||
}
|
||||
st->buf_used = in_len;
|
||||
|
||||
@@ -92,6 +92,10 @@ typedef struct poly1305_state_internal_t {
|
||||
} poly1305_state_internal; /* 448 bytes total + 63 bytes for
|
||||
alignment = 511 bytes raw */
|
||||
|
||||
OPENSSL_STATIC_ASSERT(
|
||||
sizeof(struct poly1305_state_internal_t) + 63 <= sizeof(poly1305_state),
|
||||
"poly1305_state isn't large enough to hold aligned poly1305_state_internal_t");
|
||||
|
||||
static inline poly1305_state_internal *poly1305_aligned_state(
|
||||
poly1305_state *state) {
|
||||
return (poly1305_state_internal *)(((uint64_t)state + 63) & ~63);
|
||||
|
||||
@@ -0,0 +1,34 @@
|
||||
/* Copyright (c) 2020, Google Inc.
|
||||
*
|
||||
* Permission to use, copy, modify, and/or distribute this software for any
|
||||
* purpose with or without fee is hereby granted, provided that the above
|
||||
* copyright notice and this permission notice appear in all copies.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
|
||||
* WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
|
||||
* MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
|
||||
* SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
|
||||
* WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION
|
||||
* OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
|
||||
* CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. */
|
||||
|
||||
#include <CCryptoBoringSSL_base.h>
|
||||
#include "../fipsmodule/rand/internal.h"
|
||||
|
||||
#if defined(BORINGSSL_FIPS_PASSIVE_ENTROPY)
|
||||
|
||||
// RAND_need_entropy is called by the FIPS module when it has blocked because of
|
||||
// a lack of entropy. This signal is used as an indication to feed it more.
|
||||
void RAND_need_entropy(size_t bytes_needed) {
|
||||
uint8_t buf[CTR_DRBG_ENTROPY_LEN * BORINGSSL_FIPS_OVERREAD];
|
||||
size_t todo = sizeof(buf);
|
||||
if (todo > bytes_needed) {
|
||||
todo = bytes_needed;
|
||||
}
|
||||
|
||||
int used_cpu;
|
||||
CRYPTO_get_seed_entropy(buf, todo, &used_cpu);
|
||||
RAND_load_entropy(buf, todo, used_cpu);
|
||||
}
|
||||
|
||||
#endif // BORINGSSL_FIPS_PASSIVE_ENTROPY
|
||||
@@ -63,6 +63,10 @@ RAND_METHOD *RAND_SSLeay(void) {
|
||||
return (RAND_METHOD*) &kSSLeayMethod;
|
||||
}
|
||||
|
||||
RAND_METHOD *RAND_OpenSSL(void) {
|
||||
return RAND_SSLeay();
|
||||
}
|
||||
|
||||
const RAND_METHOD *RAND_get_rand_method(void) { return RAND_SSLeay(); }
|
||||
|
||||
void RAND_set_rand_method(const RAND_METHOD *method) {}
|
||||
|
||||
@@ -57,7 +57,6 @@
|
||||
#include <CCryptoBoringSSL_stack.h>
|
||||
|
||||
#include <assert.h>
|
||||
#include <string.h>
|
||||
|
||||
#include <CCryptoBoringSSL_mem.h>
|
||||
|
||||
@@ -69,11 +68,9 @@
|
||||
static const size_t kMinSize = 4;
|
||||
|
||||
_STACK *sk_new(stack_cmp_func comp) {
|
||||
_STACK *ret;
|
||||
|
||||
ret = OPENSSL_malloc(sizeof(_STACK));
|
||||
_STACK *ret = OPENSSL_malloc(sizeof(_STACK));
|
||||
if (ret == NULL) {
|
||||
goto err;
|
||||
return NULL;
|
||||
}
|
||||
OPENSSL_memset(ret, 0, sizeof(_STACK));
|
||||
|
||||
@@ -331,23 +328,20 @@ void *sk_pop(_STACK *sk) {
|
||||
}
|
||||
|
||||
_STACK *sk_dup(const _STACK *sk) {
|
||||
_STACK *ret;
|
||||
void **s;
|
||||
|
||||
if (sk == NULL) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
ret = sk_new(sk->comp);
|
||||
_STACK *ret = OPENSSL_malloc(sizeof(_STACK));
|
||||
if (ret == NULL) {
|
||||
goto err;
|
||||
return NULL;
|
||||
}
|
||||
OPENSSL_memset(ret, 0, sizeof(_STACK));
|
||||
|
||||
s = (void **)OPENSSL_realloc(ret->data, sizeof(void *) * sk->num_alloc);
|
||||
if (s == NULL) {
|
||||
ret->data = OPENSSL_malloc(sizeof(void *) * sk->num_alloc);
|
||||
if (ret->data == NULL) {
|
||||
goto err;
|
||||
}
|
||||
ret->data = s;
|
||||
|
||||
ret->num = sk->num;
|
||||
OPENSSL_memcpy(ret->data, sk->data, sizeof(void *) * sk->num);
|
||||
|
||||
@@ -136,12 +136,10 @@ static int x509_cb(int operation, ASN1_VALUE **pval, const ASN1_ITEM *it,
|
||||
}
|
||||
|
||||
/* Per RFC5280, section 4.1.2.9, extensions require v3. */
|
||||
/* Check disabled. TODO re-enable in Jan 2021.
|
||||
https://crbug.com/boringssl/375
|
||||
if (version != 2 && ret->cert_info->extensions != NULL) {
|
||||
OPENSSL_PUT_ERROR(X509, X509_R_INVALID_FIELD_FOR_VERSION);
|
||||
return 0;
|
||||
}*/
|
||||
}
|
||||
|
||||
break;
|
||||
}
|
||||
|
||||
@@ -72,8 +72,9 @@ ASN1_SEQUENCE(OTHERNAME) = {
|
||||
IMPLEMENT_ASN1_FUNCTIONS(OTHERNAME)
|
||||
|
||||
ASN1_SEQUENCE(EDIPARTYNAME) = {
|
||||
ASN1_IMP_OPT(EDIPARTYNAME, nameAssigner, DIRECTORYSTRING, 0),
|
||||
ASN1_IMP_OPT(EDIPARTYNAME, partyName, DIRECTORYSTRING, 1)
|
||||
/* DirectoryString is a CHOICE type, so use explicit tagging. */
|
||||
ASN1_EXP_OPT(EDIPARTYNAME, nameAssigner, DIRECTORYSTRING, 0),
|
||||
ASN1_EXP(EDIPARTYNAME, partyName, DIRECTORYSTRING, 1)
|
||||
} ASN1_SEQUENCE_END(EDIPARTYNAME)
|
||||
|
||||
IMPLEMENT_ASN1_FUNCTIONS(EDIPARTYNAME)
|
||||
@@ -102,42 +103,56 @@ IMPLEMENT_ASN1_FUNCTIONS(GENERAL_NAMES)
|
||||
|
||||
IMPLEMENT_ASN1_DUP_FUNCTION(GENERAL_NAME)
|
||||
|
||||
/* Returns 0 if they are equal, != 0 otherwise. */
|
||||
int GENERAL_NAME_cmp(GENERAL_NAME *a, GENERAL_NAME *b)
|
||||
static int edipartyname_cmp(const EDIPARTYNAME *a, const EDIPARTYNAME *b)
|
||||
{
|
||||
int result = -1;
|
||||
/* nameAssigner is optional and may be NULL. */
|
||||
if (a->nameAssigner == NULL) {
|
||||
if (b->nameAssigner != NULL) {
|
||||
return -1;
|
||||
}
|
||||
} else {
|
||||
if (b->nameAssigner == NULL ||
|
||||
ASN1_STRING_cmp(a->nameAssigner, b->nameAssigner) != 0) {
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
||||
/* partyName may not be NULL. */
|
||||
return ASN1_STRING_cmp(a->partyName, b->partyName);
|
||||
}
|
||||
|
||||
/* Returns 0 if they are equal, != 0 otherwise. */
|
||||
int GENERAL_NAME_cmp(const GENERAL_NAME *a, const GENERAL_NAME *b)
|
||||
{
|
||||
if (!a || !b || a->type != b->type)
|
||||
return -1;
|
||||
|
||||
switch (a->type) {
|
||||
case GEN_X400:
|
||||
return ASN1_TYPE_cmp(a->d.x400Address, b->d.x400Address);
|
||||
|
||||
case GEN_EDIPARTY:
|
||||
result = ASN1_TYPE_cmp(a->d.other, b->d.other);
|
||||
break;
|
||||
return edipartyname_cmp(a->d.ediPartyName, b->d.ediPartyName);
|
||||
|
||||
case GEN_OTHERNAME:
|
||||
result = OTHERNAME_cmp(a->d.otherName, b->d.otherName);
|
||||
break;
|
||||
return OTHERNAME_cmp(a->d.otherName, b->d.otherName);
|
||||
|
||||
case GEN_EMAIL:
|
||||
case GEN_DNS:
|
||||
case GEN_URI:
|
||||
result = ASN1_STRING_cmp(a->d.ia5, b->d.ia5);
|
||||
break;
|
||||
return ASN1_STRING_cmp(a->d.ia5, b->d.ia5);
|
||||
|
||||
case GEN_DIRNAME:
|
||||
result = X509_NAME_cmp(a->d.dirn, b->d.dirn);
|
||||
break;
|
||||
return X509_NAME_cmp(a->d.dirn, b->d.dirn);
|
||||
|
||||
case GEN_IPADD:
|
||||
result = ASN1_OCTET_STRING_cmp(a->d.ip, b->d.ip);
|
||||
break;
|
||||
return ASN1_OCTET_STRING_cmp(a->d.ip, b->d.ip);
|
||||
|
||||
case GEN_RID:
|
||||
result = OBJ_cmp(a->d.rid, b->d.rid);
|
||||
break;
|
||||
return OBJ_cmp(a->d.rid, b->d.rid);
|
||||
}
|
||||
return result;
|
||||
|
||||
return -1;
|
||||
}
|
||||
|
||||
/* Returns 0 if they are equal, != 0 otherwise. */
|
||||
@@ -159,8 +174,11 @@ void GENERAL_NAME_set0_value(GENERAL_NAME *a, int type, void *value)
|
||||
{
|
||||
switch (type) {
|
||||
case GEN_X400:
|
||||
a->d.x400Address = value;
|
||||
break;
|
||||
|
||||
case GEN_EDIPARTY:
|
||||
a->d.other = value;
|
||||
a->d.ediPartyName = value;
|
||||
break;
|
||||
|
||||
case GEN_OTHERNAME:
|
||||
@@ -194,8 +212,10 @@ void *GENERAL_NAME_get0_value(const GENERAL_NAME *a, int *ptype)
|
||||
*ptype = a->type;
|
||||
switch (a->type) {
|
||||
case GEN_X400:
|
||||
return a->d.x400Address;
|
||||
|
||||
case GEN_EDIPARTY:
|
||||
return a->d.other;
|
||||
return a->d.ediPartyName;
|
||||
|
||||
case GEN_OTHERNAME:
|
||||
return a->d.otherName;
|
||||
|
||||
Vendored
+1
-1
@@ -1 +1 @@
|
||||
This directory is derived from BoringSSL cloned from https://boringssl.googlesource.com/boringssl at revision 9dae0ac4f0ae18ebed988d36bfb4c4e4023fc574
|
||||
This directory is derived from BoringSSL cloned from https://boringssl.googlesource.com/boringssl at revision bb43a45d6de7375f3310511d37f040d1055f8a10
|
||||
@@ -1,6 +1,6 @@
|
||||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// This source file is part of the SwitCrypto open source project
|
||||
// This source file is part of the SwiftCrypto open source project
|
||||
//
|
||||
// Copyright (c) 2019 Apple Inc. and the SwiftCrypto project authors
|
||||
// Licensed under Apache License v2.0
|
||||
@@ -20,6 +20,7 @@
|
||||
#include "CCryptoBoringSSL_asn1t.h"
|
||||
#include "CCryptoBoringSSL_base.h"
|
||||
#include "CCryptoBoringSSL_bio.h"
|
||||
#include "CCryptoBoringSSL_blake2.h"
|
||||
#include "CCryptoBoringSSL_blowfish.h"
|
||||
#include "CCryptoBoringSSL_boringssl_prefix_symbols.h"
|
||||
#include "CCryptoBoringSSL_boringssl_prefix_symbols_asm.h"
|
||||
|
||||
@@ -1012,5 +1012,6 @@ BSSL_NAMESPACE_END
|
||||
#define ASN1_R_WRONG_TAG 190
|
||||
#define ASN1_R_WRONG_TYPE 191
|
||||
#define ASN1_R_NESTED_TOO_DEEP 192
|
||||
#define ASN1_R_BAD_TEMPLATE 193
|
||||
|
||||
#endif
|
||||
@@ -98,19 +98,19 @@ extern "C" {
|
||||
#elif defined(__x86) || defined(__i386) || defined(__i386__) || defined(_M_IX86)
|
||||
#define OPENSSL_32_BIT
|
||||
#define OPENSSL_X86
|
||||
#elif defined(__aarch64__) || defined(_M_ARM64)
|
||||
#elif defined(__AARCH64EL__) || defined(_M_ARM64)
|
||||
#define OPENSSL_64_BIT
|
||||
#define OPENSSL_AARCH64
|
||||
#elif defined(__arm) || defined(__arm__) || defined(_M_ARM)
|
||||
#elif defined(__ARMEL__) || defined(_M_ARM)
|
||||
#define OPENSSL_32_BIT
|
||||
#define OPENSSL_ARM
|
||||
#elif (defined(__PPC64__) || defined(__powerpc64__)) && defined(_LITTLE_ENDIAN)
|
||||
#define OPENSSL_64_BIT
|
||||
#define OPENSSL_PPC64LE
|
||||
#elif defined(__mips__) && !defined(__LP64__)
|
||||
#elif defined(__MIPSEL__) && !defined(__LP64__)
|
||||
#define OPENSSL_32_BIT
|
||||
#define OPENSSL_MIPS
|
||||
#elif defined(__mips__) && defined(__LP64__)
|
||||
#elif defined(__MIPSEL__) && defined(__LP64__)
|
||||
#define OPENSSL_64_BIT
|
||||
#define OPENSSL_MIPS64
|
||||
#elif defined(__pnacl__)
|
||||
@@ -164,6 +164,10 @@ extern "C" {
|
||||
|
||||
#if defined(__ANDROID_API__)
|
||||
#define OPENSSL_ANDROID
|
||||
#if defined(BORINGSSL_FIPS)
|
||||
// The FIPS module on Android passively receives entropy.
|
||||
#define BORINGSSL_FIPS_PASSIVE_ENTROPY
|
||||
#endif
|
||||
#endif
|
||||
|
||||
// BoringSSL requires platform's locking APIs to make internal global state
|
||||
@@ -195,7 +199,7 @@ extern "C" {
|
||||
// A consumer may use this symbol in the preprocessor to temporarily build
|
||||
// against multiple revisions of BoringSSL at the same time. It is not
|
||||
// recommended to do so for longer than is necessary.
|
||||
#define BORINGSSL_API_VERSION 12
|
||||
#define BORINGSSL_API_VERSION 14
|
||||
|
||||
#if defined(BORINGSSL_SHARED_LIBRARY)
|
||||
|
||||
@@ -380,6 +384,7 @@ typedef struct bignum_ctx BN_CTX;
|
||||
typedef struct bignum_st BIGNUM;
|
||||
typedef struct bio_method_st BIO_METHOD;
|
||||
typedef struct bio_st BIO;
|
||||
typedef struct blake2b_state_st BLAKE2B_CTX;
|
||||
typedef struct bn_gencb_st BN_GENCB;
|
||||
typedef struct bn_mont_ctx_st BN_MONT_CTX;
|
||||
typedef struct buf_mem_st BUF_MEM;
|
||||
|
||||
@@ -0,0 +1,62 @@
|
||||
/* Copyright (c) 2021, Google Inc.
|
||||
*
|
||||
* Permission to use, copy, modify, and/or distribute this software for any
|
||||
* purpose with or without fee is hereby granted, provided that the above
|
||||
* copyright notice and this permission notice appear in all copies.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
|
||||
* WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
|
||||
* MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
|
||||
* SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
|
||||
* WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION
|
||||
* OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
|
||||
* CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. */
|
||||
|
||||
#ifndef OPENSSL_HEADER_BLAKE2_H
|
||||
#define OPENSSL_HEADER_BLAKE2_H
|
||||
|
||||
#include "CCryptoBoringSSL_base.h"
|
||||
|
||||
#if defined(__cplusplus)
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
|
||||
#define BLAKE2B256_DIGEST_LENGTH (256 / 8)
|
||||
#define BLAKE2B_CBLOCK 128
|
||||
|
||||
struct blake2b_state_st {
|
||||
uint64_t h[8];
|
||||
uint64_t t_low, t_high;
|
||||
union {
|
||||
uint8_t bytes[BLAKE2B_CBLOCK];
|
||||
uint64_t words[16];
|
||||
} block;
|
||||
size_t block_used;
|
||||
};
|
||||
|
||||
// BLAKE2B256_Init initialises |b2b| to perform a BLAKE2b-256 hash. There are no
|
||||
// pointers inside |b2b| thus release of |b2b| is purely managed by the caller.
|
||||
OPENSSL_EXPORT void BLAKE2B256_Init(BLAKE2B_CTX *b2b);
|
||||
|
||||
// BLAKE2B256_Update appends |len| bytes from |data| to the digest being
|
||||
// calculated by |b2b|.
|
||||
OPENSSL_EXPORT void BLAKE2B256_Update(BLAKE2B_CTX *b2b, const void *data,
|
||||
size_t len);
|
||||
|
||||
// BLAKE2B256_Final completes the digest calculated by |b2b| and writes
|
||||
// |BLAKE2B256_DIGEST_LENGTH| bytes to |out|.
|
||||
OPENSSL_EXPORT void BLAKE2B256_Final(uint8_t out[BLAKE2B256_DIGEST_LENGTH],
|
||||
BLAKE2B_CTX *b2b);
|
||||
|
||||
// BLAKE2B256 writes the BLAKE2b-256 digset of |len| bytes from |data| to
|
||||
// |out|.
|
||||
OPENSSL_EXPORT void BLAKE2B256(const uint8_t *data, size_t len,
|
||||
uint8_t out[BLAKE2B256_DIGEST_LENGTH]);
|
||||
|
||||
|
||||
#if defined(__cplusplus)
|
||||
} // extern C
|
||||
#endif
|
||||
|
||||
#endif // OPENSSL_HEADER_BLAKE2_H
|
||||
@@ -300,6 +300,10 @@
|
||||
#define BIO_write BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, BIO_write)
|
||||
#define BIO_write_all BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, BIO_write_all)
|
||||
#define BIO_write_filename BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, BIO_write_filename)
|
||||
#define BLAKE2B256 BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, BLAKE2B256)
|
||||
#define BLAKE2B256_Final BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, BLAKE2B256_Final)
|
||||
#define BLAKE2B256_Init BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, BLAKE2B256_Init)
|
||||
#define BLAKE2B256_Update BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, BLAKE2B256_Update)
|
||||
#define BN_BLINDING_convert BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, BN_BLINDING_convert)
|
||||
#define BN_BLINDING_free BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, BN_BLINDING_free)
|
||||
#define BN_BLINDING_invalidate BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, BN_BLINDING_invalidate)
|
||||
@@ -640,6 +644,8 @@
|
||||
#define DH_check BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, DH_check)
|
||||
#define DH_check_pub_key BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, DH_check_pub_key)
|
||||
#define DH_compute_key BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, DH_compute_key)
|
||||
#define DH_compute_key_hashed BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, DH_compute_key_hashed)
|
||||
#define DH_compute_key_padded BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, DH_compute_key_padded)
|
||||
#define DH_free BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, DH_free)
|
||||
#define DH_generate_key BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, DH_generate_key)
|
||||
#define DH_generate_parameters_ex BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, DH_generate_parameters_ex)
|
||||
@@ -650,15 +656,12 @@
|
||||
#define DH_get0_priv_key BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, DH_get0_priv_key)
|
||||
#define DH_get0_pub_key BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, DH_get0_pub_key)
|
||||
#define DH_get0_q BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, DH_get0_q)
|
||||
#define DH_get_ex_data BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, DH_get_ex_data)
|
||||
#define DH_get_ex_new_index BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, DH_get_ex_new_index)
|
||||
#define DH_marshal_parameters BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, DH_marshal_parameters)
|
||||
#define DH_new BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, DH_new)
|
||||
#define DH_num_bits BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, DH_num_bits)
|
||||
#define DH_parse_parameters BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, DH_parse_parameters)
|
||||
#define DH_set0_key BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, DH_set0_key)
|
||||
#define DH_set0_pqg BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, DH_set0_pqg)
|
||||
#define DH_set_ex_data BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, DH_set_ex_data)
|
||||
#define DH_set_length BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, DH_set_length)
|
||||
#define DH_size BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, DH_size)
|
||||
#define DH_up_ref BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, DH_up_ref)
|
||||
@@ -792,6 +795,7 @@
|
||||
#define EC_POINT_dbl BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, EC_POINT_dbl)
|
||||
#define EC_POINT_dup BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, EC_POINT_dup)
|
||||
#define EC_POINT_free BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, EC_POINT_free)
|
||||
#define EC_POINT_get_affine_coordinates BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, EC_POINT_get_affine_coordinates)
|
||||
#define EC_POINT_get_affine_coordinates_GFp BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, EC_POINT_get_affine_coordinates_GFp)
|
||||
#define EC_POINT_invert BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, EC_POINT_invert)
|
||||
#define EC_POINT_is_at_infinity BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, EC_POINT_is_at_infinity)
|
||||
@@ -801,6 +805,7 @@
|
||||
#define EC_POINT_oct2point BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, EC_POINT_oct2point)
|
||||
#define EC_POINT_point2cbb BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, EC_POINT_point2cbb)
|
||||
#define EC_POINT_point2oct BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, EC_POINT_point2oct)
|
||||
#define EC_POINT_set_affine_coordinates BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, EC_POINT_set_affine_coordinates)
|
||||
#define EC_POINT_set_affine_coordinates_GFp BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, EC_POINT_set_affine_coordinates_GFp)
|
||||
#define EC_POINT_set_compressed_coordinates_GFp BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, EC_POINT_set_compressed_coordinates_GFp)
|
||||
#define EC_POINT_set_to_infinity BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, EC_POINT_set_to_infinity)
|
||||
@@ -952,6 +957,8 @@
|
||||
#define EVP_HPKE_CTX_setup_psk_r_x25519 BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, EVP_HPKE_CTX_setup_psk_r_x25519)
|
||||
#define EVP_HPKE_CTX_setup_psk_s_x25519 BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, EVP_HPKE_CTX_setup_psk_s_x25519)
|
||||
#define EVP_HPKE_CTX_setup_psk_s_x25519_for_test BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, EVP_HPKE_CTX_setup_psk_s_x25519_for_test)
|
||||
#define EVP_HPKE_get_aead BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, EVP_HPKE_get_aead)
|
||||
#define EVP_HPKE_get_hkdf_md BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, EVP_HPKE_get_hkdf_md)
|
||||
#define EVP_MD_CTX_block_size BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, EVP_MD_CTX_block_size)
|
||||
#define EVP_MD_CTX_cleanup BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, EVP_MD_CTX_cleanup)
|
||||
#define EVP_MD_CTX_copy BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, EVP_MD_CTX_copy)
|
||||
@@ -1106,6 +1113,7 @@
|
||||
#define EVP_aes_256_ecb BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, EVP_aes_256_ecb)
|
||||
#define EVP_aes_256_gcm BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, EVP_aes_256_gcm)
|
||||
#define EVP_aes_256_ofb BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, EVP_aes_256_ofb)
|
||||
#define EVP_blake2b256 BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, EVP_blake2b256)
|
||||
#define EVP_cleanup BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, EVP_cleanup)
|
||||
#define EVP_des_cbc BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, EVP_des_cbc)
|
||||
#define EVP_des_ecb BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, EVP_des_ecb)
|
||||
@@ -1433,6 +1441,7 @@
|
||||
#define PROXY_POLICY_free BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, PROXY_POLICY_free)
|
||||
#define PROXY_POLICY_it BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, PROXY_POLICY_it)
|
||||
#define PROXY_POLICY_new BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, PROXY_POLICY_new)
|
||||
#define RAND_OpenSSL BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, RAND_OpenSSL)
|
||||
#define RAND_SSLeay BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, RAND_SSLeay)
|
||||
#define RAND_add BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, RAND_add)
|
||||
#define RAND_bytes BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, RAND_bytes)
|
||||
@@ -2245,6 +2254,7 @@
|
||||
#define bn_scatter5 BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, bn_scatter5)
|
||||
#define bn_select_words BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, bn_select_words)
|
||||
#define bn_set_minimal_width BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, bn_set_minimal_width)
|
||||
#define bn_set_static_words BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, bn_set_static_words)
|
||||
#define bn_set_words BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, bn_set_words)
|
||||
#define bn_sqr8x_internal BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, bn_sqr8x_internal)
|
||||
#define bn_sqr_comba4 BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, bn_sqr_comba4)
|
||||
|
||||
@@ -305,6 +305,10 @@
|
||||
#define _BIO_write BORINGSSL_ADD_PREFIX_MAC_ASM(BORINGSSL_PREFIX, BIO_write)
|
||||
#define _BIO_write_all BORINGSSL_ADD_PREFIX_MAC_ASM(BORINGSSL_PREFIX, BIO_write_all)
|
||||
#define _BIO_write_filename BORINGSSL_ADD_PREFIX_MAC_ASM(BORINGSSL_PREFIX, BIO_write_filename)
|
||||
#define _BLAKE2B256 BORINGSSL_ADD_PREFIX_MAC_ASM(BORINGSSL_PREFIX, BLAKE2B256)
|
||||
#define _BLAKE2B256_Final BORINGSSL_ADD_PREFIX_MAC_ASM(BORINGSSL_PREFIX, BLAKE2B256_Final)
|
||||
#define _BLAKE2B256_Init BORINGSSL_ADD_PREFIX_MAC_ASM(BORINGSSL_PREFIX, BLAKE2B256_Init)
|
||||
#define _BLAKE2B256_Update BORINGSSL_ADD_PREFIX_MAC_ASM(BORINGSSL_PREFIX, BLAKE2B256_Update)
|
||||
#define _BN_BLINDING_convert BORINGSSL_ADD_PREFIX_MAC_ASM(BORINGSSL_PREFIX, BN_BLINDING_convert)
|
||||
#define _BN_BLINDING_free BORINGSSL_ADD_PREFIX_MAC_ASM(BORINGSSL_PREFIX, BN_BLINDING_free)
|
||||
#define _BN_BLINDING_invalidate BORINGSSL_ADD_PREFIX_MAC_ASM(BORINGSSL_PREFIX, BN_BLINDING_invalidate)
|
||||
@@ -645,6 +649,8 @@
|
||||
#define _DH_check BORINGSSL_ADD_PREFIX_MAC_ASM(BORINGSSL_PREFIX, DH_check)
|
||||
#define _DH_check_pub_key BORINGSSL_ADD_PREFIX_MAC_ASM(BORINGSSL_PREFIX, DH_check_pub_key)
|
||||
#define _DH_compute_key BORINGSSL_ADD_PREFIX_MAC_ASM(BORINGSSL_PREFIX, DH_compute_key)
|
||||
#define _DH_compute_key_hashed BORINGSSL_ADD_PREFIX_MAC_ASM(BORINGSSL_PREFIX, DH_compute_key_hashed)
|
||||
#define _DH_compute_key_padded BORINGSSL_ADD_PREFIX_MAC_ASM(BORINGSSL_PREFIX, DH_compute_key_padded)
|
||||
#define _DH_free BORINGSSL_ADD_PREFIX_MAC_ASM(BORINGSSL_PREFIX, DH_free)
|
||||
#define _DH_generate_key BORINGSSL_ADD_PREFIX_MAC_ASM(BORINGSSL_PREFIX, DH_generate_key)
|
||||
#define _DH_generate_parameters_ex BORINGSSL_ADD_PREFIX_MAC_ASM(BORINGSSL_PREFIX, DH_generate_parameters_ex)
|
||||
@@ -655,15 +661,12 @@
|
||||
#define _DH_get0_priv_key BORINGSSL_ADD_PREFIX_MAC_ASM(BORINGSSL_PREFIX, DH_get0_priv_key)
|
||||
#define _DH_get0_pub_key BORINGSSL_ADD_PREFIX_MAC_ASM(BORINGSSL_PREFIX, DH_get0_pub_key)
|
||||
#define _DH_get0_q BORINGSSL_ADD_PREFIX_MAC_ASM(BORINGSSL_PREFIX, DH_get0_q)
|
||||
#define _DH_get_ex_data BORINGSSL_ADD_PREFIX_MAC_ASM(BORINGSSL_PREFIX, DH_get_ex_data)
|
||||
#define _DH_get_ex_new_index BORINGSSL_ADD_PREFIX_MAC_ASM(BORINGSSL_PREFIX, DH_get_ex_new_index)
|
||||
#define _DH_marshal_parameters BORINGSSL_ADD_PREFIX_MAC_ASM(BORINGSSL_PREFIX, DH_marshal_parameters)
|
||||
#define _DH_new BORINGSSL_ADD_PREFIX_MAC_ASM(BORINGSSL_PREFIX, DH_new)
|
||||
#define _DH_num_bits BORINGSSL_ADD_PREFIX_MAC_ASM(BORINGSSL_PREFIX, DH_num_bits)
|
||||
#define _DH_parse_parameters BORINGSSL_ADD_PREFIX_MAC_ASM(BORINGSSL_PREFIX, DH_parse_parameters)
|
||||
#define _DH_set0_key BORINGSSL_ADD_PREFIX_MAC_ASM(BORINGSSL_PREFIX, DH_set0_key)
|
||||
#define _DH_set0_pqg BORINGSSL_ADD_PREFIX_MAC_ASM(BORINGSSL_PREFIX, DH_set0_pqg)
|
||||
#define _DH_set_ex_data BORINGSSL_ADD_PREFIX_MAC_ASM(BORINGSSL_PREFIX, DH_set_ex_data)
|
||||
#define _DH_set_length BORINGSSL_ADD_PREFIX_MAC_ASM(BORINGSSL_PREFIX, DH_set_length)
|
||||
#define _DH_size BORINGSSL_ADD_PREFIX_MAC_ASM(BORINGSSL_PREFIX, DH_size)
|
||||
#define _DH_up_ref BORINGSSL_ADD_PREFIX_MAC_ASM(BORINGSSL_PREFIX, DH_up_ref)
|
||||
@@ -797,6 +800,7 @@
|
||||
#define _EC_POINT_dbl BORINGSSL_ADD_PREFIX_MAC_ASM(BORINGSSL_PREFIX, EC_POINT_dbl)
|
||||
#define _EC_POINT_dup BORINGSSL_ADD_PREFIX_MAC_ASM(BORINGSSL_PREFIX, EC_POINT_dup)
|
||||
#define _EC_POINT_free BORINGSSL_ADD_PREFIX_MAC_ASM(BORINGSSL_PREFIX, EC_POINT_free)
|
||||
#define _EC_POINT_get_affine_coordinates BORINGSSL_ADD_PREFIX_MAC_ASM(BORINGSSL_PREFIX, EC_POINT_get_affine_coordinates)
|
||||
#define _EC_POINT_get_affine_coordinates_GFp BORINGSSL_ADD_PREFIX_MAC_ASM(BORINGSSL_PREFIX, EC_POINT_get_affine_coordinates_GFp)
|
||||
#define _EC_POINT_invert BORINGSSL_ADD_PREFIX_MAC_ASM(BORINGSSL_PREFIX, EC_POINT_invert)
|
||||
#define _EC_POINT_is_at_infinity BORINGSSL_ADD_PREFIX_MAC_ASM(BORINGSSL_PREFIX, EC_POINT_is_at_infinity)
|
||||
@@ -806,6 +810,7 @@
|
||||
#define _EC_POINT_oct2point BORINGSSL_ADD_PREFIX_MAC_ASM(BORINGSSL_PREFIX, EC_POINT_oct2point)
|
||||
#define _EC_POINT_point2cbb BORINGSSL_ADD_PREFIX_MAC_ASM(BORINGSSL_PREFIX, EC_POINT_point2cbb)
|
||||
#define _EC_POINT_point2oct BORINGSSL_ADD_PREFIX_MAC_ASM(BORINGSSL_PREFIX, EC_POINT_point2oct)
|
||||
#define _EC_POINT_set_affine_coordinates BORINGSSL_ADD_PREFIX_MAC_ASM(BORINGSSL_PREFIX, EC_POINT_set_affine_coordinates)
|
||||
#define _EC_POINT_set_affine_coordinates_GFp BORINGSSL_ADD_PREFIX_MAC_ASM(BORINGSSL_PREFIX, EC_POINT_set_affine_coordinates_GFp)
|
||||
#define _EC_POINT_set_compressed_coordinates_GFp BORINGSSL_ADD_PREFIX_MAC_ASM(BORINGSSL_PREFIX, EC_POINT_set_compressed_coordinates_GFp)
|
||||
#define _EC_POINT_set_to_infinity BORINGSSL_ADD_PREFIX_MAC_ASM(BORINGSSL_PREFIX, EC_POINT_set_to_infinity)
|
||||
@@ -957,6 +962,8 @@
|
||||
#define _EVP_HPKE_CTX_setup_psk_r_x25519 BORINGSSL_ADD_PREFIX_MAC_ASM(BORINGSSL_PREFIX, EVP_HPKE_CTX_setup_psk_r_x25519)
|
||||
#define _EVP_HPKE_CTX_setup_psk_s_x25519 BORINGSSL_ADD_PREFIX_MAC_ASM(BORINGSSL_PREFIX, EVP_HPKE_CTX_setup_psk_s_x25519)
|
||||
#define _EVP_HPKE_CTX_setup_psk_s_x25519_for_test BORINGSSL_ADD_PREFIX_MAC_ASM(BORINGSSL_PREFIX, EVP_HPKE_CTX_setup_psk_s_x25519_for_test)
|
||||
#define _EVP_HPKE_get_aead BORINGSSL_ADD_PREFIX_MAC_ASM(BORINGSSL_PREFIX, EVP_HPKE_get_aead)
|
||||
#define _EVP_HPKE_get_hkdf_md BORINGSSL_ADD_PREFIX_MAC_ASM(BORINGSSL_PREFIX, EVP_HPKE_get_hkdf_md)
|
||||
#define _EVP_MD_CTX_block_size BORINGSSL_ADD_PREFIX_MAC_ASM(BORINGSSL_PREFIX, EVP_MD_CTX_block_size)
|
||||
#define _EVP_MD_CTX_cleanup BORINGSSL_ADD_PREFIX_MAC_ASM(BORINGSSL_PREFIX, EVP_MD_CTX_cleanup)
|
||||
#define _EVP_MD_CTX_copy BORINGSSL_ADD_PREFIX_MAC_ASM(BORINGSSL_PREFIX, EVP_MD_CTX_copy)
|
||||
@@ -1111,6 +1118,7 @@
|
||||
#define _EVP_aes_256_ecb BORINGSSL_ADD_PREFIX_MAC_ASM(BORINGSSL_PREFIX, EVP_aes_256_ecb)
|
||||
#define _EVP_aes_256_gcm BORINGSSL_ADD_PREFIX_MAC_ASM(BORINGSSL_PREFIX, EVP_aes_256_gcm)
|
||||
#define _EVP_aes_256_ofb BORINGSSL_ADD_PREFIX_MAC_ASM(BORINGSSL_PREFIX, EVP_aes_256_ofb)
|
||||
#define _EVP_blake2b256 BORINGSSL_ADD_PREFIX_MAC_ASM(BORINGSSL_PREFIX, EVP_blake2b256)
|
||||
#define _EVP_cleanup BORINGSSL_ADD_PREFIX_MAC_ASM(BORINGSSL_PREFIX, EVP_cleanup)
|
||||
#define _EVP_des_cbc BORINGSSL_ADD_PREFIX_MAC_ASM(BORINGSSL_PREFIX, EVP_des_cbc)
|
||||
#define _EVP_des_ecb BORINGSSL_ADD_PREFIX_MAC_ASM(BORINGSSL_PREFIX, EVP_des_ecb)
|
||||
@@ -1438,6 +1446,7 @@
|
||||
#define _PROXY_POLICY_free BORINGSSL_ADD_PREFIX_MAC_ASM(BORINGSSL_PREFIX, PROXY_POLICY_free)
|
||||
#define _PROXY_POLICY_it BORINGSSL_ADD_PREFIX_MAC_ASM(BORINGSSL_PREFIX, PROXY_POLICY_it)
|
||||
#define _PROXY_POLICY_new BORINGSSL_ADD_PREFIX_MAC_ASM(BORINGSSL_PREFIX, PROXY_POLICY_new)
|
||||
#define _RAND_OpenSSL BORINGSSL_ADD_PREFIX_MAC_ASM(BORINGSSL_PREFIX, RAND_OpenSSL)
|
||||
#define _RAND_SSLeay BORINGSSL_ADD_PREFIX_MAC_ASM(BORINGSSL_PREFIX, RAND_SSLeay)
|
||||
#define _RAND_add BORINGSSL_ADD_PREFIX_MAC_ASM(BORINGSSL_PREFIX, RAND_add)
|
||||
#define _RAND_bytes BORINGSSL_ADD_PREFIX_MAC_ASM(BORINGSSL_PREFIX, RAND_bytes)
|
||||
@@ -2250,6 +2259,7 @@
|
||||
#define _bn_scatter5 BORINGSSL_ADD_PREFIX_MAC_ASM(BORINGSSL_PREFIX, bn_scatter5)
|
||||
#define _bn_select_words BORINGSSL_ADD_PREFIX_MAC_ASM(BORINGSSL_PREFIX, bn_select_words)
|
||||
#define _bn_set_minimal_width BORINGSSL_ADD_PREFIX_MAC_ASM(BORINGSSL_PREFIX, bn_set_minimal_width)
|
||||
#define _bn_set_static_words BORINGSSL_ADD_PREFIX_MAC_ASM(BORINGSSL_PREFIX, bn_set_static_words)
|
||||
#define _bn_set_words BORINGSSL_ADD_PREFIX_MAC_ASM(BORINGSSL_PREFIX, bn_set_words)
|
||||
#define _bn_sqr8x_internal BORINGSSL_ADD_PREFIX_MAC_ASM(BORINGSSL_PREFIX, bn_sqr8x_internal)
|
||||
#define _bn_sqr_comba4 BORINGSSL_ADD_PREFIX_MAC_ASM(BORINGSSL_PREFIX, bn_sqr_comba4)
|
||||
|
||||
@@ -252,12 +252,16 @@ OPENSSL_EXPORT int CBS_get_any_asn1_element(CBS *cbs, CBS *out,
|
||||
size_t *out_header_len);
|
||||
|
||||
// CBS_get_any_ber_asn1_element acts the same as |CBS_get_any_asn1_element| but
|
||||
// also allows indefinite-length elements to be returned. In that case,
|
||||
// |*out_header_len| and |CBS_len(out)| will both be two as only the header is
|
||||
// returned, otherwise it behaves the same as the previous function.
|
||||
// also allows indefinite-length elements to be returned and does not enforce
|
||||
// that lengths are minimal. For indefinite-lengths, |*out_header_len| and
|
||||
// |CBS_len(out)| will be equal as only the header is returned (although this is
|
||||
// also true for empty elements so the length must be checked too). If
|
||||
// |out_ber_found| is not NULL then it is set to one if any case of invalid DER
|
||||
// but valid BER is found, and to zero otherwise.
|
||||
OPENSSL_EXPORT int CBS_get_any_ber_asn1_element(CBS *cbs, CBS *out,
|
||||
unsigned *out_tag,
|
||||
size_t *out_header_len);
|
||||
size_t *out_header_len,
|
||||
int *out_ber_found);
|
||||
|
||||
// CBS_get_asn1_uint64 gets an ASN.1 INTEGER from |cbs| using |CBS_get_asn1|
|
||||
// and sets |*out| to its value. It returns one on success and zero on error,
|
||||
|
||||
@@ -431,9 +431,24 @@ OPENSSL_EXPORT const EVP_CIPHER *EVP_des_ede3_ecb(void);
|
||||
// EVP_aes_128_cfb128 is only available in decrepit.
|
||||
OPENSSL_EXPORT const EVP_CIPHER *EVP_aes_128_cfb128(void);
|
||||
|
||||
// EVP_aes_128_cfb is an alias for |EVP_aes_128_cfb128| and is only available in
|
||||
// decrepit.
|
||||
OPENSSL_EXPORT const EVP_CIPHER *EVP_aes_128_cfb(void);
|
||||
|
||||
// EVP_aes_192_cfb128 is only available in decrepit.
|
||||
OPENSSL_EXPORT const EVP_CIPHER *EVP_aes_192_cfb128(void);
|
||||
|
||||
// EVP_aes_192_cfb is an alias for |EVP_aes_192_cfb128| and is only available in
|
||||
// decrepit.
|
||||
OPENSSL_EXPORT const EVP_CIPHER *EVP_aes_192_cfb(void);
|
||||
|
||||
// EVP_aes_256_cfb128 is only available in decrepit.
|
||||
OPENSSL_EXPORT const EVP_CIPHER *EVP_aes_256_cfb128(void);
|
||||
|
||||
// EVP_aes_256_cfb is an alias for |EVP_aes_256_cfb128| and is only available in
|
||||
// decrepit.
|
||||
OPENSSL_EXPORT const EVP_CIPHER *EVP_aes_256_cfb(void);
|
||||
|
||||
// EVP_bf_ecb is Blowfish in ECB mode and is only available in decrepit.
|
||||
OPENSSL_EXPORT const EVP_CIPHER *EVP_bf_ecb(void);
|
||||
|
||||
|
||||
@@ -59,7 +59,6 @@
|
||||
|
||||
#include "CCryptoBoringSSL_base.h"
|
||||
|
||||
#include "CCryptoBoringSSL_ex_data.h"
|
||||
#include "CCryptoBoringSSL_thread.h"
|
||||
|
||||
#if defined(__cplusplus)
|
||||
@@ -164,20 +163,37 @@ OPENSSL_EXPORT int DH_generate_parameters_ex(DH *dh, int prime_bits,
|
||||
// |dh|. It returns one on success and zero on error.
|
||||
OPENSSL_EXPORT int DH_generate_key(DH *dh);
|
||||
|
||||
// DH_compute_key calculates the shared key between |dh| and |peers_key| and
|
||||
// writes it as a big-endian integer into |out|, which must have |DH_size|
|
||||
// bytes of space. It returns the number of bytes written, or a negative number
|
||||
// on error.
|
||||
// DH_compute_key_padded calculates the shared key between |dh| and |peers_key|
|
||||
// and writes it as a big-endian integer into |out|, padded up to |DH_size|
|
||||
// bytes. It returns the number of bytes written, which is always |DH_size|, or
|
||||
// a negative number on error. |out| must have |DH_size| bytes of space.
|
||||
//
|
||||
// Note the output may be shorter than |DH_size| bytes. Contrary to PKCS #3,
|
||||
// this function returns a variable-length shared key with leading zeros
|
||||
// removed. This may result in sporadic key mismatch and, if |dh| is reused,
|
||||
// side channel attacks such as https://raccoon-attack.com/.
|
||||
// WARNING: this differs from the usual BoringSSL return-value convention.
|
||||
//
|
||||
// This is a legacy algorithm, so we do not provide a fixed-width variant. Use
|
||||
// X25519 or ECDH with P-256 instead.
|
||||
OPENSSL_EXPORT int DH_compute_key(uint8_t *out, const BIGNUM *peers_key,
|
||||
DH *dh);
|
||||
// Note this function differs from |DH_compute_key| in that it preserves leading
|
||||
// zeros in the secret. This function is the preferred variant. It matches PKCS
|
||||
// #3 and avoids some side channel attacks. However, the two functions are not
|
||||
// drop-in replacements for each other. Using a different variant than the
|
||||
// application expects will result in sporadic key mismatches.
|
||||
//
|
||||
// Callers that expect a fixed-width secret should use this function over
|
||||
// |DH_compute_key|. Callers that use either function should migrate to a modern
|
||||
// primitive such as X25519 or ECDH with P-256 instead.
|
||||
OPENSSL_EXPORT int DH_compute_key_padded(uint8_t *out, const BIGNUM *peers_key,
|
||||
DH *dh);
|
||||
|
||||
// DH_compute_key_hashed calculates the shared key between |dh| and |peers_key|
|
||||
// and hashes it with the given |digest|. If the hash output is less than
|
||||
// |max_out_len| bytes then it writes the hash output to |out| and sets
|
||||
// |*out_len| to the number of bytes written. Otherwise it signals an error. It
|
||||
// returns one on success or zero on error.
|
||||
//
|
||||
// NOTE: this follows the usual BoringSSL return-value convention, but that's
|
||||
// different from |DH_compute_key| and |DH_compute_key_padded|.
|
||||
OPENSSL_EXPORT int DH_compute_key_hashed(DH *dh, uint8_t *out, size_t *out_len,
|
||||
size_t max_out_len,
|
||||
const BIGNUM *peers_key,
|
||||
const EVP_MD *digest);
|
||||
|
||||
|
||||
// Utility functions.
|
||||
@@ -237,18 +253,6 @@ OPENSSL_EXPORT DH *DH_parse_parameters(CBS *cbs);
|
||||
OPENSSL_EXPORT int DH_marshal_parameters(CBB *cbb, const DH *dh);
|
||||
|
||||
|
||||
// ex_data functions.
|
||||
//
|
||||
// See |ex_data.h| for details.
|
||||
|
||||
OPENSSL_EXPORT int DH_get_ex_new_index(long argl, void *argp,
|
||||
CRYPTO_EX_unused *unused,
|
||||
CRYPTO_EX_dup *dup_unused,
|
||||
CRYPTO_EX_free *free_func);
|
||||
OPENSSL_EXPORT int DH_set_ex_data(DH *d, int idx, void *arg);
|
||||
OPENSSL_EXPORT void *DH_get_ex_data(DH *d, int idx);
|
||||
|
||||
|
||||
// Deprecated functions.
|
||||
|
||||
// DH_generate_parameters behaves like |DH_generate_parameters_ex|, which is
|
||||
@@ -278,6 +282,28 @@ OPENSSL_EXPORT DH *d2i_DHparams(DH **ret, const unsigned char **inp, long len);
|
||||
// Use |DH_marshal_parameters| instead.
|
||||
OPENSSL_EXPORT int i2d_DHparams(const DH *in, unsigned char **outp);
|
||||
|
||||
// DH_compute_key behaves like |DH_compute_key_padded| but, contrary to PKCS #3,
|
||||
// returns a variable-length shared key with leading zeros. It returns the
|
||||
// number of bytes written, or a negative number on error. |out| must have
|
||||
// |DH_size| bytes of space.
|
||||
//
|
||||
// WARNING: this differs from the usual BoringSSL return-value convention.
|
||||
//
|
||||
// Note this function's running time and memory access pattern leaks information
|
||||
// about the shared secret. Particularly if |dh| is reused, this may result in
|
||||
// side channel attacks such as https://raccoon-attack.com/.
|
||||
//
|
||||
// |DH_compute_key_padded| is the preferred variant and avoids the above
|
||||
// attacks. However, the two functions are not drop-in replacements for each
|
||||
// other. Using a different variant than the application expects will result in
|
||||
// sporadic key mismatches.
|
||||
//
|
||||
// Callers that expect a fixed-width secret should use |DH_compute_key_padded|
|
||||
// instead. Callers that use either function should migrate to a modern
|
||||
// primitive such as X25519 or ECDH with P-256 instead.
|
||||
OPENSSL_EXPORT int DH_compute_key(uint8_t *out, const BIGNUM *peers_key,
|
||||
DH *dh);
|
||||
|
||||
|
||||
struct dh_st {
|
||||
BIGNUM *p;
|
||||
@@ -301,7 +327,6 @@ struct dh_st {
|
||||
|
||||
int flags;
|
||||
CRYPTO_refcount_t references;
|
||||
CRYPTO_EX_DATA ex_data;
|
||||
};
|
||||
|
||||
|
||||
|
||||
@@ -84,6 +84,7 @@ OPENSSL_EXPORT const EVP_MD *EVP_sha256(void);
|
||||
OPENSSL_EXPORT const EVP_MD *EVP_sha384(void);
|
||||
OPENSSL_EXPORT const EVP_MD *EVP_sha512(void);
|
||||
OPENSSL_EXPORT const EVP_MD *EVP_sha512_256(void);
|
||||
OPENSSL_EXPORT const EVP_MD *EVP_blake2b256(void);
|
||||
|
||||
// EVP_md5_sha1 is a TLS-specific |EVP_MD| which computes the concatenation of
|
||||
// MD5 and SHA-1, as used in TLS 1.1 and below.
|
||||
|
||||
@@ -221,6 +221,13 @@ OPENSSL_EXPORT int EC_POINT_get_affine_coordinates_GFp(const EC_GROUP *group,
|
||||
BIGNUM *x, BIGNUM *y,
|
||||
BN_CTX *ctx);
|
||||
|
||||
// EC_POINT_get_affine_coordinates is an alias of
|
||||
// |EC_POINT_get_affine_coordinates_GFp|.
|
||||
OPENSSL_EXPORT int EC_POINT_get_affine_coordinates(const EC_GROUP *group,
|
||||
const EC_POINT *point,
|
||||
BIGNUM *x, BIGNUM *y,
|
||||
BN_CTX *ctx);
|
||||
|
||||
// EC_POINT_set_affine_coordinates_GFp sets the value of |point| to be
|
||||
// (|x|, |y|). The |ctx| argument may be used if not NULL. It returns one
|
||||
// on success or zero on error. It's considered an error if the point is not on
|
||||
@@ -237,6 +244,14 @@ OPENSSL_EXPORT int EC_POINT_set_affine_coordinates_GFp(const EC_GROUP *group,
|
||||
const BIGNUM *y,
|
||||
BN_CTX *ctx);
|
||||
|
||||
// EC_POINT_set_affine_coordinates is an alias of
|
||||
// |EC_POINT_set_affine_coordinates_GFp|.
|
||||
OPENSSL_EXPORT int EC_POINT_set_affine_coordinates(const EC_GROUP *group,
|
||||
EC_POINT *point,
|
||||
const BIGNUM *x,
|
||||
const BIGNUM *y,
|
||||
BN_CTX *ctx);
|
||||
|
||||
// EC_POINT_point2oct serialises |point| into the X9.62 form given by |form|
|
||||
// into, at most, |len| bytes at |buf|. It returns the number of bytes written
|
||||
// or zero on error if |buf| is non-NULL, else the number of bytes needed. The
|
||||
|
||||
@@ -97,6 +97,9 @@ struct rand_meth_st {
|
||||
// RAND_SSLeay returns a pointer to a dummy |RAND_METHOD|.
|
||||
OPENSSL_EXPORT RAND_METHOD *RAND_SSLeay(void);
|
||||
|
||||
// RAND_OpenSSL returns a pointer to a dummy |RAND_METHOD|.
|
||||
OPENSSL_EXPORT RAND_METHOD *RAND_OpenSSL(void);
|
||||
|
||||
// RAND_get_rand_method returns |RAND_SSLeay()|.
|
||||
OPENSSL_EXPORT const RAND_METHOD *RAND_get_rand_method(void);
|
||||
|
||||
|
||||
@@ -21,8 +21,9 @@
|
||||
|
||||
extern "C++" {
|
||||
|
||||
#include <stdlib.h>
|
||||
|
||||
#include <algorithm>
|
||||
#include <cstdlib>
|
||||
#include <type_traits>
|
||||
|
||||
BSSL_NAMESPACE_BEGIN
|
||||
|
||||
@@ -474,7 +474,12 @@ DECLARE_ASN1_FUNCTIONS(AUTHORITY_KEYID)
|
||||
|
||||
DECLARE_ASN1_FUNCTIONS(GENERAL_NAME)
|
||||
OPENSSL_EXPORT GENERAL_NAME *GENERAL_NAME_dup(GENERAL_NAME *a);
|
||||
OPENSSL_EXPORT int GENERAL_NAME_cmp(GENERAL_NAME *a, GENERAL_NAME *b);
|
||||
|
||||
// GENERAL_NAME_cmp returns zero if |a| and |b| are equal and a non-zero
|
||||
// value otherwise. Note this function does not provide a comparison suitable
|
||||
// for sorting.
|
||||
OPENSSL_EXPORT int GENERAL_NAME_cmp(const GENERAL_NAME *a,
|
||||
const GENERAL_NAME *b);
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -297,6 +297,10 @@
|
||||
%xdefine _BIO_write _ %+ BORINGSSL_PREFIX %+ _BIO_write
|
||||
%xdefine _BIO_write_all _ %+ BORINGSSL_PREFIX %+ _BIO_write_all
|
||||
%xdefine _BIO_write_filename _ %+ BORINGSSL_PREFIX %+ _BIO_write_filename
|
||||
%xdefine _BLAKE2B256 _ %+ BORINGSSL_PREFIX %+ _BLAKE2B256
|
||||
%xdefine _BLAKE2B256_Final _ %+ BORINGSSL_PREFIX %+ _BLAKE2B256_Final
|
||||
%xdefine _BLAKE2B256_Init _ %+ BORINGSSL_PREFIX %+ _BLAKE2B256_Init
|
||||
%xdefine _BLAKE2B256_Update _ %+ BORINGSSL_PREFIX %+ _BLAKE2B256_Update
|
||||
%xdefine _BN_BLINDING_convert _ %+ BORINGSSL_PREFIX %+ _BN_BLINDING_convert
|
||||
%xdefine _BN_BLINDING_free _ %+ BORINGSSL_PREFIX %+ _BN_BLINDING_free
|
||||
%xdefine _BN_BLINDING_invalidate _ %+ BORINGSSL_PREFIX %+ _BN_BLINDING_invalidate
|
||||
@@ -637,6 +641,8 @@
|
||||
%xdefine _DH_check _ %+ BORINGSSL_PREFIX %+ _DH_check
|
||||
%xdefine _DH_check_pub_key _ %+ BORINGSSL_PREFIX %+ _DH_check_pub_key
|
||||
%xdefine _DH_compute_key _ %+ BORINGSSL_PREFIX %+ _DH_compute_key
|
||||
%xdefine _DH_compute_key_hashed _ %+ BORINGSSL_PREFIX %+ _DH_compute_key_hashed
|
||||
%xdefine _DH_compute_key_padded _ %+ BORINGSSL_PREFIX %+ _DH_compute_key_padded
|
||||
%xdefine _DH_free _ %+ BORINGSSL_PREFIX %+ _DH_free
|
||||
%xdefine _DH_generate_key _ %+ BORINGSSL_PREFIX %+ _DH_generate_key
|
||||
%xdefine _DH_generate_parameters_ex _ %+ BORINGSSL_PREFIX %+ _DH_generate_parameters_ex
|
||||
@@ -647,15 +653,12 @@
|
||||
%xdefine _DH_get0_priv_key _ %+ BORINGSSL_PREFIX %+ _DH_get0_priv_key
|
||||
%xdefine _DH_get0_pub_key _ %+ BORINGSSL_PREFIX %+ _DH_get0_pub_key
|
||||
%xdefine _DH_get0_q _ %+ BORINGSSL_PREFIX %+ _DH_get0_q
|
||||
%xdefine _DH_get_ex_data _ %+ BORINGSSL_PREFIX %+ _DH_get_ex_data
|
||||
%xdefine _DH_get_ex_new_index _ %+ BORINGSSL_PREFIX %+ _DH_get_ex_new_index
|
||||
%xdefine _DH_marshal_parameters _ %+ BORINGSSL_PREFIX %+ _DH_marshal_parameters
|
||||
%xdefine _DH_new _ %+ BORINGSSL_PREFIX %+ _DH_new
|
||||
%xdefine _DH_num_bits _ %+ BORINGSSL_PREFIX %+ _DH_num_bits
|
||||
%xdefine _DH_parse_parameters _ %+ BORINGSSL_PREFIX %+ _DH_parse_parameters
|
||||
%xdefine _DH_set0_key _ %+ BORINGSSL_PREFIX %+ _DH_set0_key
|
||||
%xdefine _DH_set0_pqg _ %+ BORINGSSL_PREFIX %+ _DH_set0_pqg
|
||||
%xdefine _DH_set_ex_data _ %+ BORINGSSL_PREFIX %+ _DH_set_ex_data
|
||||
%xdefine _DH_set_length _ %+ BORINGSSL_PREFIX %+ _DH_set_length
|
||||
%xdefine _DH_size _ %+ BORINGSSL_PREFIX %+ _DH_size
|
||||
%xdefine _DH_up_ref _ %+ BORINGSSL_PREFIX %+ _DH_up_ref
|
||||
@@ -789,6 +792,7 @@
|
||||
%xdefine _EC_POINT_dbl _ %+ BORINGSSL_PREFIX %+ _EC_POINT_dbl
|
||||
%xdefine _EC_POINT_dup _ %+ BORINGSSL_PREFIX %+ _EC_POINT_dup
|
||||
%xdefine _EC_POINT_free _ %+ BORINGSSL_PREFIX %+ _EC_POINT_free
|
||||
%xdefine _EC_POINT_get_affine_coordinates _ %+ BORINGSSL_PREFIX %+ _EC_POINT_get_affine_coordinates
|
||||
%xdefine _EC_POINT_get_affine_coordinates_GFp _ %+ BORINGSSL_PREFIX %+ _EC_POINT_get_affine_coordinates_GFp
|
||||
%xdefine _EC_POINT_invert _ %+ BORINGSSL_PREFIX %+ _EC_POINT_invert
|
||||
%xdefine _EC_POINT_is_at_infinity _ %+ BORINGSSL_PREFIX %+ _EC_POINT_is_at_infinity
|
||||
@@ -798,6 +802,7 @@
|
||||
%xdefine _EC_POINT_oct2point _ %+ BORINGSSL_PREFIX %+ _EC_POINT_oct2point
|
||||
%xdefine _EC_POINT_point2cbb _ %+ BORINGSSL_PREFIX %+ _EC_POINT_point2cbb
|
||||
%xdefine _EC_POINT_point2oct _ %+ BORINGSSL_PREFIX %+ _EC_POINT_point2oct
|
||||
%xdefine _EC_POINT_set_affine_coordinates _ %+ BORINGSSL_PREFIX %+ _EC_POINT_set_affine_coordinates
|
||||
%xdefine _EC_POINT_set_affine_coordinates_GFp _ %+ BORINGSSL_PREFIX %+ _EC_POINT_set_affine_coordinates_GFp
|
||||
%xdefine _EC_POINT_set_compressed_coordinates_GFp _ %+ BORINGSSL_PREFIX %+ _EC_POINT_set_compressed_coordinates_GFp
|
||||
%xdefine _EC_POINT_set_to_infinity _ %+ BORINGSSL_PREFIX %+ _EC_POINT_set_to_infinity
|
||||
@@ -949,6 +954,8 @@
|
||||
%xdefine _EVP_HPKE_CTX_setup_psk_r_x25519 _ %+ BORINGSSL_PREFIX %+ _EVP_HPKE_CTX_setup_psk_r_x25519
|
||||
%xdefine _EVP_HPKE_CTX_setup_psk_s_x25519 _ %+ BORINGSSL_PREFIX %+ _EVP_HPKE_CTX_setup_psk_s_x25519
|
||||
%xdefine _EVP_HPKE_CTX_setup_psk_s_x25519_for_test _ %+ BORINGSSL_PREFIX %+ _EVP_HPKE_CTX_setup_psk_s_x25519_for_test
|
||||
%xdefine _EVP_HPKE_get_aead _ %+ BORINGSSL_PREFIX %+ _EVP_HPKE_get_aead
|
||||
%xdefine _EVP_HPKE_get_hkdf_md _ %+ BORINGSSL_PREFIX %+ _EVP_HPKE_get_hkdf_md
|
||||
%xdefine _EVP_MD_CTX_block_size _ %+ BORINGSSL_PREFIX %+ _EVP_MD_CTX_block_size
|
||||
%xdefine _EVP_MD_CTX_cleanup _ %+ BORINGSSL_PREFIX %+ _EVP_MD_CTX_cleanup
|
||||
%xdefine _EVP_MD_CTX_copy _ %+ BORINGSSL_PREFIX %+ _EVP_MD_CTX_copy
|
||||
@@ -1103,6 +1110,7 @@
|
||||
%xdefine _EVP_aes_256_ecb _ %+ BORINGSSL_PREFIX %+ _EVP_aes_256_ecb
|
||||
%xdefine _EVP_aes_256_gcm _ %+ BORINGSSL_PREFIX %+ _EVP_aes_256_gcm
|
||||
%xdefine _EVP_aes_256_ofb _ %+ BORINGSSL_PREFIX %+ _EVP_aes_256_ofb
|
||||
%xdefine _EVP_blake2b256 _ %+ BORINGSSL_PREFIX %+ _EVP_blake2b256
|
||||
%xdefine _EVP_cleanup _ %+ BORINGSSL_PREFIX %+ _EVP_cleanup
|
||||
%xdefine _EVP_des_cbc _ %+ BORINGSSL_PREFIX %+ _EVP_des_cbc
|
||||
%xdefine _EVP_des_ecb _ %+ BORINGSSL_PREFIX %+ _EVP_des_ecb
|
||||
@@ -1430,6 +1438,7 @@
|
||||
%xdefine _PROXY_POLICY_free _ %+ BORINGSSL_PREFIX %+ _PROXY_POLICY_free
|
||||
%xdefine _PROXY_POLICY_it _ %+ BORINGSSL_PREFIX %+ _PROXY_POLICY_it
|
||||
%xdefine _PROXY_POLICY_new _ %+ BORINGSSL_PREFIX %+ _PROXY_POLICY_new
|
||||
%xdefine _RAND_OpenSSL _ %+ BORINGSSL_PREFIX %+ _RAND_OpenSSL
|
||||
%xdefine _RAND_SSLeay _ %+ BORINGSSL_PREFIX %+ _RAND_SSLeay
|
||||
%xdefine _RAND_add _ %+ BORINGSSL_PREFIX %+ _RAND_add
|
||||
%xdefine _RAND_bytes _ %+ BORINGSSL_PREFIX %+ _RAND_bytes
|
||||
@@ -2242,6 +2251,7 @@
|
||||
%xdefine _bn_scatter5 _ %+ BORINGSSL_PREFIX %+ _bn_scatter5
|
||||
%xdefine _bn_select_words _ %+ BORINGSSL_PREFIX %+ _bn_select_words
|
||||
%xdefine _bn_set_minimal_width _ %+ BORINGSSL_PREFIX %+ _bn_set_minimal_width
|
||||
%xdefine _bn_set_static_words _ %+ BORINGSSL_PREFIX %+ _bn_set_static_words
|
||||
%xdefine _bn_set_words _ %+ BORINGSSL_PREFIX %+ _bn_set_words
|
||||
%xdefine _bn_sqr8x_internal _ %+ BORINGSSL_PREFIX %+ _bn_sqr8x_internal
|
||||
%xdefine _bn_sqr_comba4 _ %+ BORINGSSL_PREFIX %+ _bn_sqr_comba4
|
||||
@@ -3094,6 +3104,10 @@
|
||||
%xdefine BIO_write BORINGSSL_PREFIX %+ _BIO_write
|
||||
%xdefine BIO_write_all BORINGSSL_PREFIX %+ _BIO_write_all
|
||||
%xdefine BIO_write_filename BORINGSSL_PREFIX %+ _BIO_write_filename
|
||||
%xdefine BLAKE2B256 BORINGSSL_PREFIX %+ _BLAKE2B256
|
||||
%xdefine BLAKE2B256_Final BORINGSSL_PREFIX %+ _BLAKE2B256_Final
|
||||
%xdefine BLAKE2B256_Init BORINGSSL_PREFIX %+ _BLAKE2B256_Init
|
||||
%xdefine BLAKE2B256_Update BORINGSSL_PREFIX %+ _BLAKE2B256_Update
|
||||
%xdefine BN_BLINDING_convert BORINGSSL_PREFIX %+ _BN_BLINDING_convert
|
||||
%xdefine BN_BLINDING_free BORINGSSL_PREFIX %+ _BN_BLINDING_free
|
||||
%xdefine BN_BLINDING_invalidate BORINGSSL_PREFIX %+ _BN_BLINDING_invalidate
|
||||
@@ -3434,6 +3448,8 @@
|
||||
%xdefine DH_check BORINGSSL_PREFIX %+ _DH_check
|
||||
%xdefine DH_check_pub_key BORINGSSL_PREFIX %+ _DH_check_pub_key
|
||||
%xdefine DH_compute_key BORINGSSL_PREFIX %+ _DH_compute_key
|
||||
%xdefine DH_compute_key_hashed BORINGSSL_PREFIX %+ _DH_compute_key_hashed
|
||||
%xdefine DH_compute_key_padded BORINGSSL_PREFIX %+ _DH_compute_key_padded
|
||||
%xdefine DH_free BORINGSSL_PREFIX %+ _DH_free
|
||||
%xdefine DH_generate_key BORINGSSL_PREFIX %+ _DH_generate_key
|
||||
%xdefine DH_generate_parameters_ex BORINGSSL_PREFIX %+ _DH_generate_parameters_ex
|
||||
@@ -3444,15 +3460,12 @@
|
||||
%xdefine DH_get0_priv_key BORINGSSL_PREFIX %+ _DH_get0_priv_key
|
||||
%xdefine DH_get0_pub_key BORINGSSL_PREFIX %+ _DH_get0_pub_key
|
||||
%xdefine DH_get0_q BORINGSSL_PREFIX %+ _DH_get0_q
|
||||
%xdefine DH_get_ex_data BORINGSSL_PREFIX %+ _DH_get_ex_data
|
||||
%xdefine DH_get_ex_new_index BORINGSSL_PREFIX %+ _DH_get_ex_new_index
|
||||
%xdefine DH_marshal_parameters BORINGSSL_PREFIX %+ _DH_marshal_parameters
|
||||
%xdefine DH_new BORINGSSL_PREFIX %+ _DH_new
|
||||
%xdefine DH_num_bits BORINGSSL_PREFIX %+ _DH_num_bits
|
||||
%xdefine DH_parse_parameters BORINGSSL_PREFIX %+ _DH_parse_parameters
|
||||
%xdefine DH_set0_key BORINGSSL_PREFIX %+ _DH_set0_key
|
||||
%xdefine DH_set0_pqg BORINGSSL_PREFIX %+ _DH_set0_pqg
|
||||
%xdefine DH_set_ex_data BORINGSSL_PREFIX %+ _DH_set_ex_data
|
||||
%xdefine DH_set_length BORINGSSL_PREFIX %+ _DH_set_length
|
||||
%xdefine DH_size BORINGSSL_PREFIX %+ _DH_size
|
||||
%xdefine DH_up_ref BORINGSSL_PREFIX %+ _DH_up_ref
|
||||
@@ -3586,6 +3599,7 @@
|
||||
%xdefine EC_POINT_dbl BORINGSSL_PREFIX %+ _EC_POINT_dbl
|
||||
%xdefine EC_POINT_dup BORINGSSL_PREFIX %+ _EC_POINT_dup
|
||||
%xdefine EC_POINT_free BORINGSSL_PREFIX %+ _EC_POINT_free
|
||||
%xdefine EC_POINT_get_affine_coordinates BORINGSSL_PREFIX %+ _EC_POINT_get_affine_coordinates
|
||||
%xdefine EC_POINT_get_affine_coordinates_GFp BORINGSSL_PREFIX %+ _EC_POINT_get_affine_coordinates_GFp
|
||||
%xdefine EC_POINT_invert BORINGSSL_PREFIX %+ _EC_POINT_invert
|
||||
%xdefine EC_POINT_is_at_infinity BORINGSSL_PREFIX %+ _EC_POINT_is_at_infinity
|
||||
@@ -3595,6 +3609,7 @@
|
||||
%xdefine EC_POINT_oct2point BORINGSSL_PREFIX %+ _EC_POINT_oct2point
|
||||
%xdefine EC_POINT_point2cbb BORINGSSL_PREFIX %+ _EC_POINT_point2cbb
|
||||
%xdefine EC_POINT_point2oct BORINGSSL_PREFIX %+ _EC_POINT_point2oct
|
||||
%xdefine EC_POINT_set_affine_coordinates BORINGSSL_PREFIX %+ _EC_POINT_set_affine_coordinates
|
||||
%xdefine EC_POINT_set_affine_coordinates_GFp BORINGSSL_PREFIX %+ _EC_POINT_set_affine_coordinates_GFp
|
||||
%xdefine EC_POINT_set_compressed_coordinates_GFp BORINGSSL_PREFIX %+ _EC_POINT_set_compressed_coordinates_GFp
|
||||
%xdefine EC_POINT_set_to_infinity BORINGSSL_PREFIX %+ _EC_POINT_set_to_infinity
|
||||
@@ -3746,6 +3761,8 @@
|
||||
%xdefine EVP_HPKE_CTX_setup_psk_r_x25519 BORINGSSL_PREFIX %+ _EVP_HPKE_CTX_setup_psk_r_x25519
|
||||
%xdefine EVP_HPKE_CTX_setup_psk_s_x25519 BORINGSSL_PREFIX %+ _EVP_HPKE_CTX_setup_psk_s_x25519
|
||||
%xdefine EVP_HPKE_CTX_setup_psk_s_x25519_for_test BORINGSSL_PREFIX %+ _EVP_HPKE_CTX_setup_psk_s_x25519_for_test
|
||||
%xdefine EVP_HPKE_get_aead BORINGSSL_PREFIX %+ _EVP_HPKE_get_aead
|
||||
%xdefine EVP_HPKE_get_hkdf_md BORINGSSL_PREFIX %+ _EVP_HPKE_get_hkdf_md
|
||||
%xdefine EVP_MD_CTX_block_size BORINGSSL_PREFIX %+ _EVP_MD_CTX_block_size
|
||||
%xdefine EVP_MD_CTX_cleanup BORINGSSL_PREFIX %+ _EVP_MD_CTX_cleanup
|
||||
%xdefine EVP_MD_CTX_copy BORINGSSL_PREFIX %+ _EVP_MD_CTX_copy
|
||||
@@ -3900,6 +3917,7 @@
|
||||
%xdefine EVP_aes_256_ecb BORINGSSL_PREFIX %+ _EVP_aes_256_ecb
|
||||
%xdefine EVP_aes_256_gcm BORINGSSL_PREFIX %+ _EVP_aes_256_gcm
|
||||
%xdefine EVP_aes_256_ofb BORINGSSL_PREFIX %+ _EVP_aes_256_ofb
|
||||
%xdefine EVP_blake2b256 BORINGSSL_PREFIX %+ _EVP_blake2b256
|
||||
%xdefine EVP_cleanup BORINGSSL_PREFIX %+ _EVP_cleanup
|
||||
%xdefine EVP_des_cbc BORINGSSL_PREFIX %+ _EVP_des_cbc
|
||||
%xdefine EVP_des_ecb BORINGSSL_PREFIX %+ _EVP_des_ecb
|
||||
@@ -4227,6 +4245,7 @@
|
||||
%xdefine PROXY_POLICY_free BORINGSSL_PREFIX %+ _PROXY_POLICY_free
|
||||
%xdefine PROXY_POLICY_it BORINGSSL_PREFIX %+ _PROXY_POLICY_it
|
||||
%xdefine PROXY_POLICY_new BORINGSSL_PREFIX %+ _PROXY_POLICY_new
|
||||
%xdefine RAND_OpenSSL BORINGSSL_PREFIX %+ _RAND_OpenSSL
|
||||
%xdefine RAND_SSLeay BORINGSSL_PREFIX %+ _RAND_SSLeay
|
||||
%xdefine RAND_add BORINGSSL_PREFIX %+ _RAND_add
|
||||
%xdefine RAND_bytes BORINGSSL_PREFIX %+ _RAND_bytes
|
||||
@@ -5039,6 +5058,7 @@
|
||||
%xdefine bn_scatter5 BORINGSSL_PREFIX %+ _bn_scatter5
|
||||
%xdefine bn_select_words BORINGSSL_PREFIX %+ _bn_select_words
|
||||
%xdefine bn_set_minimal_width BORINGSSL_PREFIX %+ _bn_set_minimal_width
|
||||
%xdefine bn_set_static_words BORINGSSL_PREFIX %+ _bn_set_static_words
|
||||
%xdefine bn_set_words BORINGSSL_PREFIX %+ _bn_set_words
|
||||
%xdefine bn_sqr8x_internal BORINGSSL_PREFIX %+ _bn_sqr8x_internal
|
||||
%xdefine bn_sqr_comba4 BORINGSSL_PREFIX %+ _bn_sqr_comba4
|
||||
|
||||
@@ -0,0 +1,4 @@
|
||||
module CCryptoBoringSSL {
|
||||
header "CCryptoBoringSSL.h"
|
||||
export *
|
||||
}
|
||||
@@ -0,0 +1,28 @@
|
||||
##===----------------------------------------------------------------------===##
|
||||
##
|
||||
## This source file is part of the SwiftCrypto open source project
|
||||
##
|
||||
## Copyright (c) 2021 Apple Inc. and the SwiftCrypto project authors
|
||||
## Licensed under Apache License v2.0
|
||||
##
|
||||
## See LICENSE.txt for license information
|
||||
## See CONTRIBUTORS.md for the list of SwiftCrypto project authors
|
||||
##
|
||||
## SPDX-License-Identifier: Apache-2.0
|
||||
##
|
||||
##===----------------------------------------------------------------------===##
|
||||
|
||||
add_library(CCryptoBoringSSLShims STATIC
|
||||
"shims.c")
|
||||
|
||||
target_include_directories(CCryptoBoringSSLShims PUBLIC
|
||||
include
|
||||
$<TARGET_PROPERTY:CCryptoBoringSSL,INCLUDE_DIRECTORIES>)
|
||||
|
||||
target_link_libraries(CCryptoBoringSSLShims PUBLIC
|
||||
CCryptoBoringSSL)
|
||||
|
||||
set_target_properties(CCryptoBoringSSLShims PROPERTIES
|
||||
INTERFACE_INCLUDE_DIRECTORIES ${CMAKE_Swift_MODULE_DIRECTORY})
|
||||
|
||||
set_property(GLOBAL APPEND PROPERTY SWIFT_CRYPTO_EXPORTS CCryptoBoringSSLShims)
|
||||
@@ -0,0 +1,4 @@
|
||||
module CCryptoBoringSSLShims {
|
||||
header "CCryptoBoringSSLShims.h"
|
||||
export *
|
||||
}
|
||||
@@ -0,0 +1,17 @@
|
||||
##===----------------------------------------------------------------------===##
|
||||
##
|
||||
## This source file is part of the SwiftCrypto open source project
|
||||
##
|
||||
## Copyright (c) 2021 Apple Inc. and the SwiftCrypto project authors
|
||||
## Licensed under Apache License v2.0
|
||||
##
|
||||
## See LICENSE.txt for license information
|
||||
## See CONTRIBUTORS.md for the list of SwiftCrypto project authors
|
||||
##
|
||||
## SPDX-License-Identifier: Apache-2.0
|
||||
##
|
||||
##===----------------------------------------------------------------------===##
|
||||
|
||||
add_subdirectory(CCryptoBoringSSL)
|
||||
add_subdirectory(CCryptoBoringSSLShims)
|
||||
add_subdirectory(Crypto)
|
||||
@@ -0,0 +1,91 @@
|
||||
##===----------------------------------------------------------------------===##
|
||||
##
|
||||
## This source file is part of the SwiftCrypto open source project
|
||||
##
|
||||
## Copyright (c) 2021 Apple Inc. and the SwiftCrypto project authors
|
||||
## Licensed under Apache License v2.0
|
||||
##
|
||||
## See LICENSE.txt for license information
|
||||
## See CONTRIBUTORS.md for the list of SwiftCrypto project authors
|
||||
##
|
||||
## SPDX-License-Identifier: Apache-2.0
|
||||
##
|
||||
##===----------------------------------------------------------------------===##
|
||||
|
||||
add_library(Crypto
|
||||
"AEADs/AES/GCM/AES-GCM.swift"
|
||||
"AEADs/AES/GCM/BoringSSL/AES-GCM_boring.swift"
|
||||
"AEADs/ChachaPoly/BoringSSL/ChaChaPoly_boring.swift"
|
||||
"AEADs/ChachaPoly/ChaChaPoly.swift"
|
||||
"AEADs/Cipher.swift"
|
||||
"AEADs/Nonces.swift"
|
||||
"ASN1/ASN1.swift"
|
||||
"ASN1/Basic ASN1 Types/ASN1BitString.swift"
|
||||
"ASN1/Basic ASN1 Types/ASN1Identifier.swift"
|
||||
"ASN1/Basic ASN1 Types/ASN1Integer.swift"
|
||||
"ASN1/Basic ASN1 Types/ASN1OctetString.swift"
|
||||
"ASN1/Basic ASN1 Types/ArraySliceBigint.swift"
|
||||
"ASN1/Basic ASN1 Types/ObjectIdentifier.swift"
|
||||
"ASN1/ECDSASignature.swift"
|
||||
"ASN1/PEMDocument.swift"
|
||||
"ASN1/PKCS8PrivateKey.swift"
|
||||
"ASN1/SEC1PrivateKey.swift"
|
||||
"ASN1/SubjectPublicKeyInfo.swift"
|
||||
"CryptoKitErrors.swift"
|
||||
"Digests/BoringSSL/Digest_boring.swift"
|
||||
"Digests/Digest.swift"
|
||||
"Digests/Digests.swift"
|
||||
"Digests/HashFunctions.swift"
|
||||
"Digests/HashFunctions_SHA2.swift"
|
||||
"Insecure/Insecure.swift"
|
||||
"Insecure/Insecure_HashFunctions.swift"
|
||||
"Key Agreement/BoringSSL/ECDH_boring.swift"
|
||||
"Key Agreement/DH.swift"
|
||||
"Key Agreement/ECDH.swift"
|
||||
"Key Derivation/HKDF.swift"
|
||||
"Keys/EC/BoringSSL/Ed25519_boring.swift"
|
||||
"Keys/EC/BoringSSL/EllipticCurvePoint_boring.swift"
|
||||
"Keys/EC/BoringSSL/EllipticCurve_boring.swift"
|
||||
"Keys/EC/BoringSSL/NISTCurvesKeys_boring.swift"
|
||||
"Keys/EC/BoringSSL/X25519Keys_boring.swift"
|
||||
"Keys/EC/Curve25519.swift"
|
||||
"Keys/EC/Ed25519.swift"
|
||||
"Keys/EC/NISTCurvesKeys.swift"
|
||||
"Keys/EC/X25519Keys.swift"
|
||||
"Keys/Symmetric/SymmetricKeys.swift"
|
||||
"Message Authentication Codes/HMAC/HMAC.swift"
|
||||
"Message Authentication Codes/MACFunctions.swift"
|
||||
"Message Authentication Codes/MessageAuthenticationCode.swift"
|
||||
"PRF/AES.swift"
|
||||
"Signatures/BoringSSL/ECDSASignature_boring.swift"
|
||||
"Signatures/BoringSSL/ECDSA_boring.swift"
|
||||
"Signatures/BoringSSL/EdDSA_boring.swift"
|
||||
"Signatures/ECDSA.swift"
|
||||
"Signatures/EdDSA.swift"
|
||||
"Signatures/Signature.swift"
|
||||
"Util/BoringSSL/ArbitraryPrecisionInteger_boring.swift"
|
||||
"Util/BoringSSL/CryptoKitErrors_boring.swift"
|
||||
"Util/BoringSSL/FiniteFieldArithmeticContext_boring.swift"
|
||||
"Util/BoringSSL/RNG_boring.swift"
|
||||
"Util/BoringSSL/SafeCompare_boring.swift"
|
||||
"Util/BoringSSL/Zeroization_boring.swift"
|
||||
"Util/PrettyBytes.swift"
|
||||
"Util/SafeCompare.swift"
|
||||
"Util/SecureBytes.swift"
|
||||
"Util/Zeroization.swift")
|
||||
|
||||
target_compile_definitions(Crypto PRIVATE
|
||||
CRYPTO_IN_SWIFTPM_FORCE_BUILD_API)
|
||||
target_include_directories(Crypto PRIVATE
|
||||
$<TARGET_PROPERTY:CCryptoBoringSSL,INCLUDE_DIRECTORIES>
|
||||
$<TARGET_PROPERTY:CCryptoBoringSSLShims,INCLUDE_DIRECTORIES>)
|
||||
target_link_libraries(Crypto PUBLIC
|
||||
$<$<NOT:$<PLATFORM_ID:Darwin>>:dispatch>
|
||||
$<$<NOT:$<PLATFORM_ID:Darwin>>:Foundation>
|
||||
CCryptoBoringSSL
|
||||
CCryptoBoringSSLShims)
|
||||
set_target_properties(Crypto PROPERTIES
|
||||
INTERFACE_INCLUDE_DIRECTORIES ${CMAKE_Swift_MODULE_DIRECTORY})
|
||||
|
||||
_install_target(Crypto)
|
||||
set_property(GLOBAL APPEND PROPERTY SWIFT_CRYPTO_EXPORTS Crypto)
|
||||
@@ -25,7 +25,7 @@ public struct SymmetricKeySize {
|
||||
return self.init(bitCount: 128)
|
||||
}
|
||||
|
||||
/// Symmetric key size of 128 bits
|
||||
/// Symmetric key size of 192 bits
|
||||
public static var bits192: SymmetricKeySize {
|
||||
return self.init(bitCount: 192)
|
||||
}
|
||||
|
||||
@@ -49,7 +49,7 @@ class DERTests: XCTestCase {
|
||||
}
|
||||
|
||||
func randomBytes(count: Int) -> [UInt8] {
|
||||
#if (os(macOS) || os(iOS) || os(watchOS) || os(tvOS)) || os(Linux) || os(Android)
|
||||
#if (os(macOS) || os(iOS) || os(watchOS) || os(tvOS)) || os(Linux) || os(Android) || os(Windows)
|
||||
var rng = SystemRandomNumberGenerator()
|
||||
return (0..<count).map { _ in rng.next() }
|
||||
#else
|
||||
|
||||
@@ -23,7 +23,7 @@ import XCTest
|
||||
#endif
|
||||
|
||||
final class SecureBytesTests: XCTestCase {
|
||||
func testBasicSanity() {
|
||||
func testBasicSoundness() {
|
||||
var first = SecureBytes()
|
||||
var second = SecureBytes()
|
||||
|
||||
|
||||
@@ -0,0 +1,20 @@
|
||||
##===----------------------------------------------------------------------===##
|
||||
##
|
||||
## This source file is part of the SwiftCrypto open source project
|
||||
##
|
||||
## Copyright (c) 2021 Apple Inc. and the SwiftCrypto project authors
|
||||
## Licensed under Apache License v2.0
|
||||
##
|
||||
## See LICENSE.txt for license information
|
||||
## See CONTRIBUTORS.md for the list of SwiftCrypto project authors
|
||||
##
|
||||
## SPDX-License-Identifier: Apache-2.0
|
||||
##
|
||||
##===----------------------------------------------------------------------===##
|
||||
|
||||
set(SWIFT_CRYPTO_EXPORTS_FILE ${CMAKE_CURRENT_BINARY_DIR}/SwiftCryptoExports.cmake)
|
||||
configure_file(SwiftCryptoConfig.cmake.in
|
||||
${CMAKE_CURRENT_BINARY_DIR}/SwiftCryptoConfig.cmake)
|
||||
|
||||
get_property(SWIFT_CRYPTO_EXPORTS GLOBAL PROPERTY SWIFT_CRYPTO_EXPORTS)
|
||||
export(TARGETS ${SWIFT_CRYPTO_EXPORTS} FILE ${SWIFT_CRYPTO_EXPORTS_FILE})
|
||||
@@ -0,0 +1,17 @@
|
||||
##===----------------------------------------------------------------------===##
|
||||
##
|
||||
## This source file is part of the SwiftCrypto open source project
|
||||
##
|
||||
## Copyright (c) 2021 Apple Inc. and the SwiftCrypto project authors
|
||||
## Licensed under Apache License v2.0
|
||||
##
|
||||
## See LICENSE.txt for license information
|
||||
## See CONTRIBUTORS.md for the list of SwiftCrypto project authors
|
||||
##
|
||||
## SPDX-License-Identifier: Apache-2.0
|
||||
##
|
||||
##===----------------------------------------------------------------------===##
|
||||
|
||||
if(NOT TARGET SwiftCrypto)
|
||||
include(@SWIFT_CRYPTO_EXPORTS_FILE@)
|
||||
endif()
|
||||
@@ -0,0 +1,108 @@
|
||||
##===----------------------------------------------------------------------===##
|
||||
##
|
||||
## This source file is part of the SwiftCrypto open source project
|
||||
##
|
||||
## Copyright (c) 2021 Apple Inc. and the SwiftCrypto project authors
|
||||
## Licensed under Apache License v2.0
|
||||
##
|
||||
## See LICENSE.txt for license information
|
||||
## See CONTRIBUTORS.md for the list of SwiftCrypto project authors
|
||||
##
|
||||
## SPDX-License-Identifier: Apache-2.0
|
||||
##
|
||||
##===----------------------------------------------------------------------===##
|
||||
|
||||
# Returns the architecture name in a variable
|
||||
#
|
||||
# Usage:
|
||||
# get_swift_host_arch(result_var_name)
|
||||
#
|
||||
# Sets ${result_var_name} with the converted architecture name derived from
|
||||
# CMAKE_SYSTEM_PROCESSOR.
|
||||
function(get_swift_host_arch result_var_name)
|
||||
if("${CMAKE_SYSTEM_PROCESSOR}" STREQUAL "x86_64")
|
||||
set("${result_var_name}" "x86_64" PARENT_SCOPE)
|
||||
elseif("${CMAKE_SYSTEM_PROCESSOR}" STREQUAL "aarch64")
|
||||
set("${result_var_name}" "aarch64" PARENT_SCOPE)
|
||||
elseif("${CMAKE_SYSTEM_PROCESSOR}" STREQUAL "arm64")
|
||||
set("${result_var_name}" "aarch64" PARENT_SCOPE)
|
||||
elseif("${CMAKE_SYSTEM_PROCESSOR}" STREQUAL "ppc64")
|
||||
set("${result_var_name}" "powerpc64" PARENT_SCOPE)
|
||||
elseif("${CMAKE_SYSTEM_PROCESSOR}" STREQUAL "ppc64le")
|
||||
set("${result_var_name}" "powerpc64le" PARENT_SCOPE)
|
||||
elseif("${CMAKE_SYSTEM_PROCESSOR}" STREQUAL "s390x")
|
||||
set("${result_var_name}" "s390x" PARENT_SCOPE)
|
||||
elseif("${CMAKE_SYSTEM_PROCESSOR}" STREQUAL "armv6l")
|
||||
set("${result_var_name}" "armv6" PARENT_SCOPE)
|
||||
elseif("${CMAKE_SYSTEM_PROCESSOR}" STREQUAL "armv7l")
|
||||
set("${result_var_name}" "armv7" PARENT_SCOPE)
|
||||
elseif("${CMAKE_SYSTEM_PROCESSOR}" STREQUAL "armv7-a")
|
||||
set("${result_var_name}" "armv7" PARENT_SCOPE)
|
||||
elseif("${CMAKE_SYSTEM_PROCESSOR}" STREQUAL "AMD64")
|
||||
set("${result_var_name}" "x86_64" PARENT_SCOPE)
|
||||
elseif("${CMAKE_SYSTEM_PROCESSOR}" STREQUAL "IA64")
|
||||
set("${result_var_name}" "itanium" PARENT_SCOPE)
|
||||
elseif("${CMAKE_SYSTEM_PROCESSOR}" STREQUAL "x86")
|
||||
set("${result_var_name}" "i686" PARENT_SCOPE)
|
||||
elseif("${CMAKE_SYSTEM_PROCESSOR}" STREQUAL "i686")
|
||||
set("${result_var_name}" "i686" PARENT_SCOPE)
|
||||
else()
|
||||
message(FATAL_ERROR "Unrecognized architecture on host system: ${CMAKE_SYSTEM_PROCESSOR}")
|
||||
endif()
|
||||
endfunction()
|
||||
|
||||
# Returns the os name in a variable
|
||||
#
|
||||
# Usage:
|
||||
# get_swift_host_os(result_var_name)
|
||||
#
|
||||
#
|
||||
# Sets ${result_var_name} with the converted OS name derived from
|
||||
# CMAKE_SYSTEM_NAME.
|
||||
function(get_swift_host_os result_var_name)
|
||||
if(CMAKE_SYSTEM_NAME STREQUAL Darwin)
|
||||
set(${result_var_name} macosx PARENT_SCOPE)
|
||||
else()
|
||||
string(TOLOWER ${CMAKE_SYSTEM_NAME} cmake_system_name_lc)
|
||||
set(${result_var_name} ${cmake_system_name_lc} PARENT_SCOPE)
|
||||
endif()
|
||||
endfunction()
|
||||
|
||||
function(_install_target module)
|
||||
get_swift_host_os(swift_os)
|
||||
get_target_property(type ${module} TYPE)
|
||||
|
||||
if(type STREQUAL STATIC_LIBRARY)
|
||||
set(swift swift_static)
|
||||
else()
|
||||
set(swift swift)
|
||||
endif()
|
||||
|
||||
install(TARGETS ${module}
|
||||
ARCHIVE DESTINATION lib/${swift}/${swift_os}
|
||||
LIBRARY DESTINATION lib/${swift}/${swift_os}
|
||||
RUNTIME DESTINATION bin)
|
||||
if(type STREQUAL EXECUTABLE)
|
||||
return()
|
||||
endif()
|
||||
|
||||
get_swift_host_arch(swift_arch)
|
||||
get_target_property(module_name ${module} Swift_MODULE_NAME)
|
||||
if(NOT module_name)
|
||||
set(module_name ${module})
|
||||
endif()
|
||||
|
||||
if(CMAKE_SYSTEM_NAME STREQUAL Darwin)
|
||||
install(FILES $<TARGET_PROPERTY:${module},Swift_MODULE_DIRECTORY>/${module_name}.swiftdoc
|
||||
DESTINATION lib/${swift}/${swift_os}/${module_name}.swiftmodule
|
||||
RENAME ${swift_arch}.swiftdoc)
|
||||
install(FILES $<TARGET_PROPERTY:${module},Swift_MODULE_DIRECTORY>/${module_name}.swiftmodule
|
||||
DESTINATION lib/${swift}/${swift_os}/${module_name}.swiftmodule
|
||||
RENAME ${swift_arch}.swiftmodule)
|
||||
else()
|
||||
install(FILES
|
||||
$<TARGET_PROPERTY:${module},Swift_MODULE_DIRECTORY>/${module_name}.swiftdoc
|
||||
$<TARGET_PROPERTY:${module},Swift_MODULE_DIRECTORY>/${module_name}.swiftmodule
|
||||
DESTINATION lib/${swift}/${swift_os}/${swift_arch})
|
||||
endif()
|
||||
endfunction()
|
||||
+4
-1
@@ -21,7 +21,10 @@ RUN apt-get update && apt-get install -y lsof dnsutils netcat-openbsd net-tools
|
||||
|
||||
# ruby and jazzy for docs generation
|
||||
RUN apt-get update && apt-get install -y ruby ruby-dev libsqlite3-dev
|
||||
RUN gem install jazzy --no-ri --no-rdoc
|
||||
RUN if [ "${ubuntu_version}" != "focal" ] ; then gem install jazzy --no-document ; fi
|
||||
|
||||
# cmake build
|
||||
RUN apt-get update && apt-get install -y cmake ninja-build
|
||||
|
||||
# tools
|
||||
RUN mkdir -p $HOME/.tools
|
||||
|
||||
@@ -0,0 +1,21 @@
|
||||
version: "3"
|
||||
|
||||
services:
|
||||
|
||||
runtime-setup:
|
||||
image: swift-crypto:20.04-5.3
|
||||
build:
|
||||
args:
|
||||
ubuntu_version: "focal"
|
||||
swift_version: "5.3"
|
||||
|
||||
test:
|
||||
image: swift-crypto:20.04-5.3
|
||||
environment: []
|
||||
#- SANITIZER_ARG=--sanitize=thread
|
||||
|
||||
cmake:
|
||||
image: swift-crypto:20.04-5.3
|
||||
|
||||
shell:
|
||||
image: swift-crypto:20.04-5.3
|
||||
@@ -22,15 +22,19 @@ services:
|
||||
- CAP_NET_RAW
|
||||
- CAP_NET_BIND_SERVICE
|
||||
|
||||
sanity:
|
||||
soundness:
|
||||
<<: *common
|
||||
command: /bin/bash -xcl "./scripts/sanity.sh"
|
||||
command: /bin/bash -xcl "./scripts/soundness.sh"
|
||||
|
||||
test:
|
||||
<<: *common
|
||||
# FIXME: get rid of existing warnings
|
||||
#command: /bin/bash -xcl "swift test --enable-test-discovery -Xswiftc -warnings-as-errors $${SANITIZER_ARG-}"
|
||||
command: /bin/bash -xcl "swift test --enable-test-discovery"
|
||||
|
||||
cmake:
|
||||
<<: *common
|
||||
command: /bin/bash -xcl "cmake -G Ninja -D CMAKE_BUILD_TYPE=Release -B out -S . && ninja -C out"
|
||||
|
||||
# util
|
||||
|
||||
|
||||
@@ -36,6 +36,8 @@ function build_and_do() {
|
||||
(
|
||||
cd "$repodir"
|
||||
git checkout -q "$tag"
|
||||
# Clean up output from previous build to prevent potential interference
|
||||
rm -rf .build
|
||||
swift build
|
||||
while read -r module; do
|
||||
swift api-digester -sdk "$sdk" -dump-sdk -module "$module" \
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
##
|
||||
## This source file is part of the SwiftCrypto open source project
|
||||
##
|
||||
## Copyright (c) 2019 Apple Inc. and the SwiftCrypto project authors
|
||||
## Copyright (c) 2019-2021 Apple Inc. and the SwiftCrypto project authors
|
||||
## Licensed under Apache License v2.0
|
||||
##
|
||||
## See LICENSE.txt for license information
|
||||
@@ -17,9 +17,25 @@ set -eu
|
||||
here="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
|
||||
function replace_acceptable_years() {
|
||||
# this needs to replace all acceptable forms with 'YEARS'
|
||||
sed -e 's/20[12][890]-20[12][90]/YEARS/' -e 's/2019/YEARS/' -e 's/2020/YEARS/'
|
||||
sed -e 's/20[12][890]-20[12][190]/YEARS/' -e 's/2019/YEARS/' -e 's/2020/YEARS/' -e 's/2021/YEARS/'
|
||||
}
|
||||
|
||||
printf "=> Checking for unacceptable language... "
|
||||
# This greps for unacceptable terminology. The square bracket[s] are so that
|
||||
# "git grep" doesn't find the lines that greps :).
|
||||
# We exclude the vendored BoringSSL copy from this check.
|
||||
unacceptable_terms=(
|
||||
-e blacklis[t]
|
||||
-e whitelis[t]
|
||||
-e slav[e]
|
||||
-e sanit[y]
|
||||
)
|
||||
if git grep --color=never -i "${unacceptable_terms[@]}" ':(exclude)Sources/CCryptoBoringSSL*' > /dev/null; then
|
||||
printf "\033[0;31mUnacceptable language found.\033[0m\n"
|
||||
git grep -i "${unacceptable_terms[@]}" ':(exclude)Sources/CCryptoBoringSSL*'
|
||||
exit 1
|
||||
fi
|
||||
printf "\033[0;32mokay.\033[0m\n"
|
||||
|
||||
# Run gyb, if generated files was changed -> fail
|
||||
printf "=> Detecting manual edits in generated Swift files by comparing to gyb output\n"
|
||||
@@ -32,15 +48,24 @@ if [ "$out" == *"error"* ]; then
|
||||
exit 1
|
||||
fi
|
||||
if [[ "$FIRST_OUT" != "$SECOND_OUT" ]]; then
|
||||
printf "\033[0;31mRunning gyb results in changes! Have you manually editted the generated swift files? Or did you forget to run gyb and commit changes?\033[0m\n"
|
||||
printf "\033[0;31mRunning gyb results in changes! Have you manually edited the generated Swift files? Or did you forget to run gyb and commit changes?\033[0m\n"
|
||||
exit 1
|
||||
fi
|
||||
printf "\033[0;32mokay.\033[0m\n"
|
||||
|
||||
printf "=> Detecting changes in source files for CMake build\n"
|
||||
FIRST_OUT="$(git status --porcelain)"
|
||||
out=$($here/update_cmakelists.sh 2>&1)
|
||||
SECOND_OUT="$(git status --porcelain)"
|
||||
if [[ "$FIRST_OUT" != "$SECOND_OUT" ]]; then
|
||||
printf "\033[0;31mThere are source file changes! Have you added or renamed source files? Or did you forget to run 'update_cmakelists.sh' and commit changes?\033[0m\n"
|
||||
exit 1
|
||||
fi
|
||||
printf "\033[0;32mokay.\033[0m\n"
|
||||
|
||||
printf "=> Checking format\n"
|
||||
FIRST_OUT="$(git status --porcelain)"
|
||||
# only checking direcotry named BoringSSL, rest is shared code and we need to preserve original format
|
||||
# only checking directory named BoringSSL, rest is shared code and we need to preserve original format
|
||||
shopt -u dotglob
|
||||
find Sources/* Tests/* -name BoringSSL -type d | while IFS= read -r d; do
|
||||
printf " * checking $d... "
|
||||
@@ -68,9 +93,9 @@ else
|
||||
fi
|
||||
|
||||
printf "=> Checking license headers\n"
|
||||
tmp=$(mktemp /tmp/.swift-crypto-sanity_XXXXXX)
|
||||
tmp=$(mktemp /tmp/.swift-crypto-soundness_XXXXXX)
|
||||
|
||||
for language in swift-or-c bash dtrace; do
|
||||
for language in swift-or-c bash dtrace cmake; do
|
||||
printf " * $language... "
|
||||
declare -a matching_files
|
||||
declare -a exceptions
|
||||
@@ -132,6 +157,24 @@ EOF
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*
|
||||
*===----------------------------------------------------------------------===*/
|
||||
EOF
|
||||
;;
|
||||
cmake)
|
||||
matching_files=( -name 'SwiftSupport.cmake' -o -name 'CMakeLists.txt' )
|
||||
cat > "$tmp" <<"EOF"
|
||||
##===----------------------------------------------------------------------===##
|
||||
##
|
||||
## This source file is part of the SwiftCrypto open source project
|
||||
##
|
||||
## Copyright (c) YEARS Apple Inc. and the SwiftCrypto project authors
|
||||
## Licensed under Apache License v2.0
|
||||
##
|
||||
## See LICENSE.txt for license information
|
||||
## See CONTRIBUTORS.md for the list of SwiftCrypto project authors
|
||||
##
|
||||
## SPDX-License-Identifier: Apache-2.0
|
||||
##
|
||||
##===----------------------------------------------------------------------===##
|
||||
EOF
|
||||
;;
|
||||
*)
|
||||
Executable
+79
@@ -0,0 +1,79 @@
|
||||
#!/bin/bash
|
||||
##===----------------------------------------------------------------------===##
|
||||
##
|
||||
## This source file is part of the SwiftCrypto open source project
|
||||
##
|
||||
## Copyright (c) 2021 Apple Inc. and the SwiftCrypto project authors
|
||||
## Licensed under Apache License v2.0
|
||||
##
|
||||
## See LICENSE.txt for license information
|
||||
## See CONTRIBUTORS.md for the list of SwiftCrypto project authors
|
||||
##
|
||||
## SPDX-License-Identifier: Apache-2.0
|
||||
##
|
||||
##===----------------------------------------------------------------------===##
|
||||
|
||||
set -eu
|
||||
|
||||
here=$(pwd)
|
||||
|
||||
case "$(uname -s)" in
|
||||
Darwin)
|
||||
find=gfind # brew install findutils
|
||||
;;
|
||||
*)
|
||||
find=find
|
||||
;;
|
||||
esac
|
||||
|
||||
function update_cmakelists_source() {
|
||||
src_root="$here/Sources/$1"
|
||||
|
||||
# Build an array with the rest of the arguments
|
||||
shift
|
||||
src_exts=("$@")
|
||||
echo "Finding source files (${src_exts[@]}) under $src_root"
|
||||
|
||||
num_exts=${#src_exts[@]}
|
||||
|
||||
# Build file extensions argument for `find`
|
||||
declare -a exts_arg
|
||||
exts_arg+=(-name "${src_exts[0]}")
|
||||
for (( i=1; i<$num_exts; i++ ));
|
||||
do
|
||||
exts_arg+=(-o -name "${src_exts[$i]}")
|
||||
done
|
||||
|
||||
# Wrap quotes around each filename since it might contain spaces
|
||||
srcs=$($find "${src_root}" -type f \( "${exts_arg[@]}" \) -printf ' "%P"\n' | LC_ALL=POSIX sort)
|
||||
echo "$srcs"
|
||||
|
||||
# Update list of source files in CMakeLists.txt
|
||||
# The first part in `BEGIN` (i.e., `undef $/;`) is for working with multi-line;
|
||||
# the second is so that we can pass in a variable to replace with.
|
||||
perl -pi -e 'BEGIN { undef $/; $replace = shift } s/add_library\(([^\n]+)\n([^\)]+)/add_library\($1\n$replace/' "$srcs" "$src_root/CMakeLists.txt"
|
||||
echo "Updated $src_root/CMakeLists.txt"
|
||||
}
|
||||
|
||||
function update_cmakelists_assembly() {
|
||||
src_root="$here/Sources/$1"
|
||||
echo "Finding assembly files (.S) under $src_root"
|
||||
|
||||
mac_asms=$($find "${src_root}" -type f -name "*.mac.x86_64.S" -printf ' %P\n' | LC_ALL=POSIX sort)
|
||||
linux_asms=$($find "${src_root}" -type f -name "*.linux.x86_64.S" -printf ' %P\n' | LC_ALL=POSIX sort)
|
||||
echo "$mac_asms"
|
||||
echo "$linux_asms"
|
||||
|
||||
# Update list of assembly files in CMakeLists.txt
|
||||
# The first part in `BEGIN` (i.e., `undef $/;`) is for working with multi-line;
|
||||
# the second is so that we can pass in a variable to replace with.
|
||||
perl -pi -e 'BEGIN { undef $/; $replace = shift } s/Darwin\)\n(.+)target_sources\(([^\n]+)\n([^\)]+)/Darwin\)\n$1target_sources\($2\n$replace/' "$mac_asms" "$src_root/CMakeLists.txt"
|
||||
perl -pi -e 'BEGIN { undef $/; $replace = shift } s/Linux\)\n(.+)target_sources\(([^\n]+)\n([^\)]+)/Linux\)\n$1target_sources\($2\n$replace/' "$linux_asms" "$src_root/CMakeLists.txt"
|
||||
echo "Updated $src_root/CMakeLists.txt"
|
||||
}
|
||||
|
||||
update_cmakelists_source "CCryptoBoringSSL" "*.c"
|
||||
update_cmakelists_source "CCryptoBoringSSLShims" "*.c"
|
||||
update_cmakelists_source "Crypto" "*.swift"
|
||||
|
||||
update_cmakelists_assembly "CCryptoBoringSSL"
|
||||
@@ -3,7 +3,7 @@
|
||||
##
|
||||
## This source file is part of the SwiftCrypto open source project
|
||||
##
|
||||
## Copyright (c) 2019 Apple Inc. and the SwiftCrypto project authors
|
||||
## Copyright (c) 2019-2021 Apple Inc. and the SwiftCrypto project authors
|
||||
## Licensed under Apache License v2.0
|
||||
##
|
||||
## See LICENSE.txt for license information
|
||||
@@ -285,7 +285,7 @@ echo "MODULARISING BoringSSL"
|
||||
cat << EOF > "$DSTROOT/include/CCryptoBoringSSL.h"
|
||||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// This source file is part of the SwitCrypto open source project
|
||||
// This source file is part of the SwiftCrypto open source project
|
||||
//
|
||||
// Copyright (c) 2019 Apple Inc. and the SwiftCrypto project authors
|
||||
// Licensed under Apache License v2.0
|
||||
@@ -305,6 +305,7 @@ cat << EOF > "$DSTROOT/include/CCryptoBoringSSL.h"
|
||||
#include "CCryptoBoringSSL_asn1t.h"
|
||||
#include "CCryptoBoringSSL_base.h"
|
||||
#include "CCryptoBoringSSL_bio.h"
|
||||
#include "CCryptoBoringSSL_blake2.h"
|
||||
#include "CCryptoBoringSSL_blowfish.h"
|
||||
#include "CCryptoBoringSSL_boringssl_prefix_symbols.h"
|
||||
#include "CCryptoBoringSSL_boringssl_prefix_symbols_asm.h"
|
||||
@@ -347,6 +348,15 @@ cat << EOF > "$DSTROOT/include/CCryptoBoringSSL.h"
|
||||
#endif // C_CRYPTO_BORINGSSL_H
|
||||
EOF
|
||||
|
||||
# modulemap is required by the cmake build
|
||||
echo "CREATING modulemap"
|
||||
cat << EOF > "$DSTROOT/include/module.modulemap"
|
||||
module CCryptoBoringSSL {
|
||||
header "CCryptoBoringSSL.h"
|
||||
export *
|
||||
}
|
||||
EOF
|
||||
|
||||
echo "RECORDING BoringSSL revision"
|
||||
$sed -i -e "s/BoringSSL Commit: [0-9a-f]\+/BoringSSL Commit: ${BORINGSSL_REVISION}/" "$HERE/Package.swift"
|
||||
echo "This directory is derived from BoringSSL cloned from https://boringssl.googlesource.com/boringssl at revision ${BORINGSSL_REVISION}" > "$DSTROOT/hash.txt"
|
||||
|
||||
Reference in new issue
Block a user