mirror of
https://github.com/apple/swift-crypto
synced 2026-11-22 04:30:39 +00:00
Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
ffca28be3c | ||
|
|
35703579f6 | ||
|
|
a24950b8aa | ||
|
|
e8f2ddd49e | ||
|
|
55201a8f83 | ||
|
|
81bee98e70 | ||
|
|
ce204da6f6 | ||
|
|
9f95b4d033 |
No files matched your search
@@ -0,0 +1,14 @@
|
||||
changelog:
|
||||
categories:
|
||||
- title: SemVer Major
|
||||
labels:
|
||||
- ⚠️ semver/major
|
||||
- title: SemVer Minor
|
||||
labels:
|
||||
- semver/minor
|
||||
- title: SemVer Patch
|
||||
labels:
|
||||
- semver/patch
|
||||
- title: Other Changes
|
||||
labels:
|
||||
- semver/none
|
||||
+24
-22
@@ -1,4 +1,4 @@
|
||||
// swift-tools-version:5.8
|
||||
// swift-tools-version:5.9
|
||||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// This source file is part of the SwiftCrypto open source project
|
||||
@@ -20,7 +20,7 @@
|
||||
// Sources/CCryptoBoringSSL directory. The source repository is at
|
||||
// https://boringssl.googlesource.com/boringssl.
|
||||
//
|
||||
// BoringSSL Commit: dbad745811195c00b729efd0ee0a09b7d9fce1d2
|
||||
// BoringSSL Commit: 6a2ccdcc2ed1d37a43a2183658d2ae61fd5ce208
|
||||
|
||||
import PackageDescription
|
||||
|
||||
@@ -57,6 +57,18 @@ if development {
|
||||
]
|
||||
}
|
||||
|
||||
// This doesn't work when cross-compiling: the privacy manifest will be included in the Bundle and
|
||||
// Foundation will be linked. This is, however, strictly better than unconditionally adding the
|
||||
// resource.
|
||||
#if canImport(Darwin)
|
||||
let privacyManifestExclude: [String] = []
|
||||
let privacyManifestResource: [PackageDescription.Resource] = [.copy("PrivacyInfo.xcprivacy")]
|
||||
#else
|
||||
// Exclude on other platforms to avoid build warnings.
|
||||
let privacyManifestExclude: [String] = ["PrivacyInfo.xcprivacy"]
|
||||
let privacyManifestResource: [PackageDescription.Resource] = []
|
||||
#endif
|
||||
|
||||
let package = Package(
|
||||
name: "swift-crypto",
|
||||
platforms: [
|
||||
@@ -76,7 +88,7 @@ let package = Package(
|
||||
targets: [
|
||||
.target(
|
||||
name: "CCryptoBoringSSL",
|
||||
exclude: [
|
||||
exclude: privacyManifestExclude + [
|
||||
"hash.txt",
|
||||
"include/boringssl_prefix_symbols_nasm.inc",
|
||||
"CMakeLists.txt",
|
||||
@@ -88,9 +100,7 @@ let package = Package(
|
||||
"crypto/bio/socket_helper.c",
|
||||
"crypto/bio/socket.c"
|
||||
],
|
||||
resources: [
|
||||
.copy("PrivacyInfo.xcprivacy"),
|
||||
],
|
||||
resources: privacyManifestResource,
|
||||
cSettings: [
|
||||
// These defines come from BoringSSL's build system
|
||||
.define("_HAS_EXCEPTIONS", to: "0", .when(platforms: [Platform.windows])),
|
||||
@@ -107,26 +117,22 @@ let package = Package(
|
||||
.target(
|
||||
name: "CCryptoBoringSSLShims",
|
||||
dependencies: ["CCryptoBoringSSL"],
|
||||
exclude: [
|
||||
exclude: privacyManifestExclude + [
|
||||
"CMakeLists.txt"
|
||||
],
|
||||
resources: [
|
||||
.copy("PrivacyInfo.xcprivacy"),
|
||||
]
|
||||
resources: privacyManifestResource
|
||||
),
|
||||
.target(
|
||||
name: "Crypto",
|
||||
dependencies: dependencies,
|
||||
exclude: [
|
||||
exclude: privacyManifestExclude + [
|
||||
"CMakeLists.txt",
|
||||
"AEADs/Nonces.swift.gyb",
|
||||
"Digests/Digests.swift.gyb",
|
||||
"Key Agreement/ECDH.swift.gyb",
|
||||
"Signatures/ECDSA.swift.gyb",
|
||||
],
|
||||
resources: [
|
||||
.copy("PrivacyInfo.xcprivacy"),
|
||||
],
|
||||
resources: privacyManifestResource,
|
||||
swiftSettings: swiftSettings + [.define("MODULE_IS_CRYPTO")]
|
||||
),
|
||||
.target(
|
||||
@@ -137,12 +143,10 @@ let package = Package(
|
||||
"CryptoBoringWrapper",
|
||||
"Crypto"
|
||||
],
|
||||
exclude: [
|
||||
exclude: privacyManifestExclude + [
|
||||
"CMakeLists.txt",
|
||||
],
|
||||
resources: [
|
||||
.copy("PrivacyInfo.xcprivacy"),
|
||||
],
|
||||
resources: privacyManifestResource,
|
||||
swiftSettings: swiftSettings
|
||||
),
|
||||
.target(
|
||||
@@ -151,12 +155,10 @@ let package = Package(
|
||||
"CCryptoBoringSSL",
|
||||
"CCryptoBoringSSLShims"
|
||||
],
|
||||
exclude: [
|
||||
exclude: privacyManifestExclude + [
|
||||
"CMakeLists.txt",
|
||||
],
|
||||
resources: [
|
||||
.copy("PrivacyInfo.xcprivacy"),
|
||||
]
|
||||
resources: privacyManifestResource
|
||||
),
|
||||
.executableTarget(name: "crypto-shasum", dependencies: ["Crypto"]),
|
||||
.testTarget(
|
||||
|
||||
@@ -117,7 +117,8 @@ Swift Crypto | Minimum Swift Version
|
||||
`2.2.0 ..< 2.4.2` | 5.5
|
||||
`2.4.2 ..< 3.1.0` | 5.6
|
||||
`3.1.0 ..< 3.3.0` | 5.7
|
||||
`3.3.0 ...` | 5.8
|
||||
`3.3.0 ..< 3.8.0` | 5.8
|
||||
`3.8.0 ...` | 5.9
|
||||
|
||||
### Compatibility
|
||||
|
||||
|
||||
+81
-147
@@ -91,6 +91,7 @@ add_library(CCryptoBoringSSL STATIC
|
||||
"crypto/dh_extra/dh_asn1.c"
|
||||
"crypto/dh_extra/params.c"
|
||||
"crypto/digest_extra/digest_extra.c"
|
||||
"crypto/dilithium/dilithium.c"
|
||||
"crypto/dsa/dsa.c"
|
||||
"crypto/dsa/dsa_asn1.c"
|
||||
"crypto/ec_extra/ec_asn1.c"
|
||||
@@ -100,10 +101,11 @@ add_library(CCryptoBoringSSL STATIC
|
||||
"crypto/ecdsa_extra/ecdsa_asn1.c"
|
||||
"crypto/engine/engine.c"
|
||||
"crypto/err/err.c"
|
||||
"crypto/err/err_data.c"
|
||||
"crypto/evp/evp.c"
|
||||
"crypto/evp/evp_asn1.c"
|
||||
"crypto/evp/evp_ctx.c"
|
||||
"crypto/evp/p_dh.c"
|
||||
"crypto/evp/p_dh_asn1.c"
|
||||
"crypto/evp/p_dsa_asn1.c"
|
||||
"crypto/evp/p_ec.c"
|
||||
"crypto/evp/p_ec_asn1.c"
|
||||
@@ -119,89 +121,17 @@ add_library(CCryptoBoringSSL STATIC
|
||||
"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_aesccm.c"
|
||||
"crypto/fipsmodule/cmac/cmac.c"
|
||||
"crypto/fipsmodule/dh/check.c"
|
||||
"crypto/fipsmodule/dh/dh.c"
|
||||
"crypto/fipsmodule/digest/digest.c"
|
||||
"crypto/fipsmodule/digest/digests.c"
|
||||
"crypto/fipsmodule/digestsign/digestsign.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-nistz.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/bcm.c"
|
||||
"crypto/fipsmodule/fips_shared_support.c"
|
||||
"crypto/fipsmodule/hkdf/hkdf.c"
|
||||
"crypto/fipsmodule/hmac/hmac.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/fips.c"
|
||||
"crypto/fipsmodule/self_check/self_check.c"
|
||||
"crypto/fipsmodule/service_indicator/service_indicator.c"
|
||||
"crypto/fipsmodule/sha/sha1.c"
|
||||
"crypto/fipsmodule/sha/sha256.c"
|
||||
"crypto/fipsmodule/sha/sha512.c"
|
||||
"crypto/fipsmodule/tls/kdf.c"
|
||||
"crypto/hpke/hpke.c"
|
||||
"crypto/hrss/hrss.c"
|
||||
"crypto/keccak/keccak.c"
|
||||
"crypto/kyber/kyber.c"
|
||||
"crypto/lhash/lhash.c"
|
||||
"crypto/md4/md4.c"
|
||||
"crypto/md5/md5.c"
|
||||
"crypto/mem.c"
|
||||
"crypto/mldsa/mldsa.c"
|
||||
"crypto/obj/obj.c"
|
||||
"crypto/obj/obj_xref.c"
|
||||
"crypto/pem/pem_all.c"
|
||||
@@ -222,26 +152,29 @@ add_library(CCryptoBoringSSL STATIC
|
||||
"crypto/poly1305/poly1305_vec.c"
|
||||
"crypto/pool/pool.c"
|
||||
"crypto/rand_extra/deterministic.c"
|
||||
"crypto/rand_extra/fork_detect.c"
|
||||
"crypto/rand_extra/forkunsafe.c"
|
||||
"crypto/rand_extra/getentropy.c"
|
||||
"crypto/rand_extra/ios.c"
|
||||
"crypto/rand_extra/passive.c"
|
||||
"crypto/rand_extra/rand_extra.c"
|
||||
"crypto/rand_extra/trusty.c"
|
||||
"crypto/rand_extra/urandom.c"
|
||||
"crypto/rand_extra/windows.c"
|
||||
"crypto/rc4/rc4.c"
|
||||
"crypto/refcount.c"
|
||||
"crypto/rsa_extra/rsa_asn1.c"
|
||||
"crypto/rsa_extra/rsa_crypt.c"
|
||||
"crypto/rsa_extra/rsa_print.c"
|
||||
"crypto/sha/sha1.c"
|
||||
"crypto/siphash/siphash.c"
|
||||
"crypto/spx/address.c"
|
||||
"crypto/spx/fors.c"
|
||||
"crypto/spx/merkle.c"
|
||||
"crypto/spx/spx.c"
|
||||
"crypto/spx/spx_address.c"
|
||||
"crypto/spx/spx_fors.c"
|
||||
"crypto/spx/spx_merkle.c"
|
||||
"crypto/spx/spx_thash.c"
|
||||
"crypto/spx/spx_util.c"
|
||||
"crypto/spx/thash.c"
|
||||
"crypto/spx/wots.c"
|
||||
"crypto/spx/spx_wots.c"
|
||||
"crypto/stack/stack.c"
|
||||
"crypto/thread.c"
|
||||
"crypto/thread_none.c"
|
||||
@@ -319,80 +252,81 @@ add_library(CCryptoBoringSSL STATIC
|
||||
"crypto/x509/x_spki.c"
|
||||
"crypto/x509/x_val.c"
|
||||
"crypto/x509/x_x509.c"
|
||||
"crypto/x509/x_x509a.c")
|
||||
"crypto/x509/x_x509a.c"
|
||||
"gen/crypto/err_data.c")
|
||||
|
||||
if(CMAKE_SYSTEM_NAME STREQUAL Darwin AND CMAKE_SYSTEM_PROCESSOR MATCHES "amd64|x86_64")
|
||||
target_sources(CCryptoBoringSSL PRIVATE
|
||||
crypto/chacha/chacha-x86_64-mac.mac.x86_64.S
|
||||
crypto/cipher_extra/aes128gcmsiv-x86_64-mac.mac.x86_64.S
|
||||
crypto/cipher_extra/chacha20_poly1305_x86_64-mac.mac.x86_64.S
|
||||
crypto/fipsmodule/aesni-gcm-x86_64-mac.mac.x86_64.S
|
||||
crypto/fipsmodule/aesni-x86_64-mac.mac.x86_64.S
|
||||
crypto/fipsmodule/ghash-ssse3-x86_64-mac.mac.x86_64.S
|
||||
crypto/fipsmodule/ghash-x86_64-mac.mac.x86_64.S
|
||||
crypto/fipsmodule/md5-x86_64-mac.mac.x86_64.S
|
||||
crypto/fipsmodule/p256-x86_64-asm-mac.mac.x86_64.S
|
||||
crypto/fipsmodule/p256_beeu-x86_64-asm-mac.mac.x86_64.S
|
||||
crypto/fipsmodule/rdrand-x86_64-mac.mac.x86_64.S
|
||||
crypto/fipsmodule/rsaz-avx2-mac.mac.x86_64.S
|
||||
crypto/fipsmodule/sha1-x86_64-mac.mac.x86_64.S
|
||||
crypto/fipsmodule/sha256-x86_64-mac.mac.x86_64.S
|
||||
crypto/fipsmodule/sha512-x86_64-mac.mac.x86_64.S
|
||||
crypto/fipsmodule/vpaes-x86_64-mac.mac.x86_64.S
|
||||
crypto/fipsmodule/x86_64-mont-mac.mac.x86_64.S
|
||||
crypto/fipsmodule/x86_64-mont5-mac.mac.x86_64.S)
|
||||
gen/bcm/aesni-gcm-x86_64-apple.S
|
||||
gen/bcm/aesni-x86_64-apple.S
|
||||
gen/bcm/ghash-ssse3-x86_64-apple.S
|
||||
gen/bcm/ghash-x86_64-apple.S
|
||||
gen/bcm/p256-x86_64-asm-apple.S
|
||||
gen/bcm/p256_beeu-x86_64-asm-apple.S
|
||||
gen/bcm/rdrand-x86_64-apple.S
|
||||
gen/bcm/rsaz-avx2-apple.S
|
||||
gen/bcm/sha1-x86_64-apple.S
|
||||
gen/bcm/sha256-x86_64-apple.S
|
||||
gen/bcm/sha512-x86_64-apple.S
|
||||
gen/bcm/vpaes-x86_64-apple.S
|
||||
gen/bcm/x86_64-mont-apple.S
|
||||
gen/bcm/x86_64-mont5-apple.S
|
||||
gen/crypto/aes128gcmsiv-x86_64-apple.S
|
||||
gen/crypto/chacha-x86_64-apple.S
|
||||
gen/crypto/chacha20_poly1305_x86_64-apple.S
|
||||
gen/crypto/md5-x86_64-apple.S)
|
||||
elseif(CMAKE_SYSTEM_NAME MATCHES "Linux|Android" AND CMAKE_SYSTEM_PROCESSOR MATCHES "amd64|x86_64")
|
||||
target_sources(CCryptoBoringSSL PRIVATE
|
||||
crypto/chacha/chacha-x86_64-linux.linux.x86_64.S
|
||||
crypto/cipher_extra/aes128gcmsiv-x86_64-linux.linux.x86_64.S
|
||||
crypto/cipher_extra/chacha20_poly1305_x86_64-linux.linux.x86_64.S
|
||||
crypto/fipsmodule/aesni-gcm-x86_64-linux.linux.x86_64.S
|
||||
crypto/fipsmodule/aesni-x86_64-linux.linux.x86_64.S
|
||||
crypto/fipsmodule/ghash-ssse3-x86_64-linux.linux.x86_64.S
|
||||
crypto/fipsmodule/ghash-x86_64-linux.linux.x86_64.S
|
||||
crypto/fipsmodule/md5-x86_64-linux.linux.x86_64.S
|
||||
crypto/fipsmodule/p256-x86_64-asm-linux.linux.x86_64.S
|
||||
crypto/fipsmodule/p256_beeu-x86_64-asm-linux.linux.x86_64.S
|
||||
crypto/fipsmodule/rdrand-x86_64-linux.linux.x86_64.S
|
||||
crypto/fipsmodule/rsaz-avx2-linux.linux.x86_64.S
|
||||
crypto/fipsmodule/sha1-x86_64-linux.linux.x86_64.S
|
||||
crypto/fipsmodule/sha256-x86_64-linux.linux.x86_64.S
|
||||
crypto/fipsmodule/sha512-x86_64-linux.linux.x86_64.S
|
||||
crypto/fipsmodule/vpaes-x86_64-linux.linux.x86_64.S
|
||||
crypto/fipsmodule/x86_64-mont-linux.linux.x86_64.S
|
||||
crypto/fipsmodule/x86_64-mont5-linux.linux.x86_64.S)
|
||||
gen/bcm/aesni-gcm-x86_64-linux.S
|
||||
gen/bcm/aesni-x86_64-linux.S
|
||||
gen/bcm/ghash-ssse3-x86_64-linux.S
|
||||
gen/bcm/ghash-x86_64-linux.S
|
||||
gen/bcm/p256-x86_64-asm-linux.S
|
||||
gen/bcm/p256_beeu-x86_64-asm-linux.S
|
||||
gen/bcm/rdrand-x86_64-linux.S
|
||||
gen/bcm/rsaz-avx2-linux.S
|
||||
gen/bcm/sha1-x86_64-linux.S
|
||||
gen/bcm/sha256-x86_64-linux.S
|
||||
gen/bcm/sha512-x86_64-linux.S
|
||||
gen/bcm/vpaes-x86_64-linux.S
|
||||
gen/bcm/x86_64-mont-linux.S
|
||||
gen/bcm/x86_64-mont5-linux.S
|
||||
gen/crypto/aes128gcmsiv-x86_64-linux.S
|
||||
gen/crypto/chacha-x86_64-linux.S
|
||||
gen/crypto/chacha20_poly1305_x86_64-linux.S
|
||||
gen/crypto/md5-x86_64-linux.S)
|
||||
elseif(CMAKE_SYSTEM_NAME STREQUAL Darwin AND CMAKE_SYSTEM_PROCESSOR MATCHES "arm64|aarch64")
|
||||
target_sources(CCryptoBoringSSL PRIVATE
|
||||
crypto/chacha/chacha-armv8-ios.ios.aarch64.S
|
||||
crypto/cipher_extra/chacha20_poly1305_armv8-ios.ios.aarch64.S
|
||||
crypto/fipsmodule/aesv8-armv8-ios.ios.aarch64.S
|
||||
crypto/fipsmodule/aesv8-gcm-armv8-ios.ios.aarch64.S
|
||||
crypto/fipsmodule/armv8-mont-ios.ios.aarch64.S
|
||||
crypto/fipsmodule/bn-armv8-ios.ios.aarch64.S
|
||||
crypto/fipsmodule/ghash-neon-armv8-ios.ios.aarch64.S
|
||||
crypto/fipsmodule/ghashv8-armv8-ios.ios.aarch64.S
|
||||
crypto/fipsmodule/p256-armv8-asm-ios.ios.aarch64.S
|
||||
crypto/fipsmodule/p256_beeu-armv8-asm-ios.ios.aarch64.S
|
||||
crypto/fipsmodule/sha1-armv8-ios.ios.aarch64.S
|
||||
crypto/fipsmodule/sha256-armv8-ios.ios.aarch64.S
|
||||
crypto/fipsmodule/sha512-armv8-ios.ios.aarch64.S
|
||||
crypto/fipsmodule/vpaes-armv8-ios.ios.aarch64.S)
|
||||
gen/bcm/aesv8-armv8-apple.S
|
||||
gen/bcm/aesv8-gcm-armv8-apple.S
|
||||
gen/bcm/armv8-mont-apple.S
|
||||
gen/bcm/bn-armv8-apple.S
|
||||
gen/bcm/ghash-neon-armv8-apple.S
|
||||
gen/bcm/ghashv8-armv8-apple.S
|
||||
gen/bcm/p256-armv8-asm-apple.S
|
||||
gen/bcm/p256_beeu-armv8-asm-apple.S
|
||||
gen/bcm/sha1-armv8-apple.S
|
||||
gen/bcm/sha256-armv8-apple.S
|
||||
gen/bcm/sha512-armv8-apple.S
|
||||
gen/bcm/vpaes-armv8-apple.S
|
||||
gen/crypto/chacha-armv8-apple.S
|
||||
gen/crypto/chacha20_poly1305_armv8-apple.S)
|
||||
elseif(CMAKE_SYSTEM_NAME MATCHES "Linux|Android" AND CMAKE_SYSTEM_PROCESSOR MATCHES "arm64|aarch64")
|
||||
target_sources(CCryptoBoringSSL PRIVATE
|
||||
crypto/chacha/chacha-armv8-linux.linux.aarch64.S
|
||||
crypto/cipher_extra/chacha20_poly1305_armv8-linux.linux.aarch64.S
|
||||
crypto/fipsmodule/aesv8-armv8-linux.linux.aarch64.S
|
||||
crypto/fipsmodule/aesv8-gcm-armv8-linux.linux.aarch64.S
|
||||
crypto/fipsmodule/armv8-mont-linux.linux.aarch64.S
|
||||
crypto/fipsmodule/bn-armv8-linux.linux.aarch64.S
|
||||
crypto/fipsmodule/ghash-neon-armv8-linux.linux.aarch64.S
|
||||
crypto/fipsmodule/ghashv8-armv8-linux.linux.aarch64.S
|
||||
crypto/fipsmodule/p256-armv8-asm-linux.linux.aarch64.S
|
||||
crypto/fipsmodule/p256_beeu-armv8-asm-linux.linux.aarch64.S
|
||||
crypto/fipsmodule/sha1-armv8-linux.linux.aarch64.S
|
||||
crypto/fipsmodule/sha256-armv8-linux.linux.aarch64.S
|
||||
crypto/fipsmodule/sha512-armv8-linux.linux.aarch64.S
|
||||
crypto/fipsmodule/vpaes-armv8-linux.linux.aarch64.S)
|
||||
gen/bcm/aesv8-armv8-linux.S
|
||||
gen/bcm/aesv8-gcm-armv8-linux.S
|
||||
gen/bcm/armv8-mont-linux.S
|
||||
gen/bcm/bn-armv8-linux.S
|
||||
gen/bcm/ghash-neon-armv8-linux.S
|
||||
gen/bcm/ghashv8-armv8-linux.S
|
||||
gen/bcm/p256-armv8-asm-linux.S
|
||||
gen/bcm/p256_beeu-armv8-asm-linux.S
|
||||
gen/bcm/sha1-armv8-linux.S
|
||||
gen/bcm/sha256-armv8-linux.S
|
||||
gen/bcm/sha512-armv8-linux.S
|
||||
gen/bcm/vpaes-armv8-linux.S
|
||||
gen/crypto/chacha-armv8-linux.S
|
||||
gen/crypto/chacha20_poly1305_armv8-linux.S)
|
||||
endif()
|
||||
|
||||
target_include_directories(CCryptoBoringSSL PUBLIC
|
||||
|
||||
@@ -307,6 +307,10 @@ static int base64_decode_quad(uint8_t *out, size_t *out_num_bytes,
|
||||
(in[2] == '=') << 1 |
|
||||
(in[3] == '=');
|
||||
|
||||
// In presence of padding, the lowest bits of v are unused. Canonical encoding
|
||||
// (RFC 4648, section 3.5) requires that these bits all be set to zero. Common
|
||||
// PEM parsers accept noncanonical base64, adding to the malleability of the
|
||||
// format. This decoder follows OpenSSL's and Go's PEM parsers and accepts it.
|
||||
switch (padding_pattern) {
|
||||
case 0:
|
||||
// The common case of no padding.
|
||||
|
||||
+53
-7
@@ -1,4 +1,4 @@
|
||||
/* Copyright (c) 2020, Google Inc.
|
||||
/* Copyright (c) 2024, 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
|
||||
@@ -12,11 +12,17 @@
|
||||
* OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
|
||||
* CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. */
|
||||
|
||||
#ifndef OPENSSL_HEADER_CRYPTO_FORK_DETECT_H
|
||||
#define OPENSSL_HEADER_CRYPTO_FORK_DETECT_H
|
||||
#ifndef OPENSSL_HEADER_CRYPTO_BCM_SUPPORT_H
|
||||
#define OPENSSL_HEADER_CRYPTO_BCM_SUPPORT_H
|
||||
|
||||
#include <CCryptoBoringSSL_base.h>
|
||||
|
||||
// Provided by libcrypto, called from BCM
|
||||
|
||||
#if defined(__cplusplus)
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#if defined(OPENSSL_LINUX)
|
||||
// On linux we use MADVISE instead of pthread_atfork(), due
|
||||
// to concerns about clone() being used for address space
|
||||
@@ -29,15 +35,54 @@
|
||||
// iOS doesn't normally allow fork in apps, but it's there.
|
||||
#define OPENSSL_FORK_DETECTION
|
||||
#define OPENSSL_FORK_DETECTION_PTHREAD_ATFORK
|
||||
#elif defined(OPENSSL_WINDOWS) || defined(OPENSSL_TRUSTY)
|
||||
#elif defined(OPENSSL_WINDOWS) || defined(OPENSSL_TRUSTY) || \
|
||||
defined(__ZEPHYR__) || defined(CROS_EC)
|
||||
// These platforms do not fork.
|
||||
#define OPENSSL_DOES_NOT_FORK
|
||||
#endif
|
||||
|
||||
#if defined(__cplusplus)
|
||||
extern "C" {
|
||||
#if defined(BORINGSSL_UNSAFE_DETERMINISTIC_MODE)
|
||||
#define OPENSSL_RAND_DETERMINISTIC
|
||||
#elif defined(OPENSSL_TRUSTY)
|
||||
#define OPENSSL_RAND_TRUSTY
|
||||
#elif defined(OPENSSL_WINDOWS)
|
||||
#define OPENSSL_RAND_WINDOWS
|
||||
#elif defined(OPENSSL_LINUX)
|
||||
#define OPENSSL_RAND_URANDOM
|
||||
#elif defined(OPENSSL_APPLE) && !defined(OPENSSL_MACOS)
|
||||
// Unlike macOS, iOS and similar hide away getentropy().
|
||||
#define OPENSSL_RAND_IOS
|
||||
#else
|
||||
// By default if you are integrating BoringSSL we expect you to
|
||||
// provide getentropy from the <unistd.h> header file.
|
||||
#define OPENSSL_RAND_GETENTROPY
|
||||
#endif
|
||||
|
||||
// Provided by libcrypto, called from BCM
|
||||
|
||||
// CRYPTO_init_sysrand initializes long-lived resources needed to draw entropy
|
||||
// from the operating system, if the operating system requires initialization.
|
||||
void CRYPTO_init_sysrand(void);
|
||||
|
||||
// CRYPTO_sysrand fills |len| bytes at |buf| with entropy from the operating
|
||||
// system.
|
||||
void CRYPTO_sysrand(uint8_t *buf, size_t len);
|
||||
|
||||
// CRYPTO_sysrand_if_available fills |len| bytes at |buf| with entropy from the
|
||||
// operating system, or early /dev/urandom data, and returns 1, _if_ the entropy
|
||||
// pool is initialized or if getrandom() is not available and not in FIPS mode.
|
||||
// Otherwise it will not block and will instead fill |buf| with all zeros and
|
||||
// return 0.
|
||||
int CRYPTO_sysrand_if_available(uint8_t *buf, size_t len);
|
||||
|
||||
// CRYPTO_sysrand_for_seed fills |len| bytes at |buf| with entropy from the
|
||||
// operating system. It may draw from the |GRND_RANDOM| pool on Android,
|
||||
// depending on the vendor's configuration.
|
||||
void CRYPTO_sysrand_for_seed(uint8_t *buf, size_t len);
|
||||
|
||||
// RAND_need_entropy is called whenever the BCM module has stopped because it
|
||||
// has run out of entropy.
|
||||
void RAND_need_entropy(size_t bytes_needed);
|
||||
|
||||
// crypto_get_fork_generation returns the fork generation number for the current
|
||||
// process, or zero if not supported on the platform. The fork generation number
|
||||
@@ -60,8 +105,9 @@ OPENSSL_EXPORT uint64_t CRYPTO_get_fork_generation(void);
|
||||
OPENSSL_EXPORT void CRYPTO_fork_detect_force_madv_wipeonfork_for_testing(
|
||||
int on);
|
||||
|
||||
|
||||
#if defined(__cplusplus)
|
||||
} // extern C
|
||||
#endif
|
||||
|
||||
#endif // OPENSSL_HEADER_CRYPTO_FORK_DETECT_H
|
||||
#endif // OPENSSL_HEADER_CRYPTO_BCM_SUPPORT_H
|
||||
@@ -658,38 +658,38 @@ void BIO_meth_free(BIO_METHOD *method) {
|
||||
}
|
||||
|
||||
int BIO_meth_set_create(BIO_METHOD *method,
|
||||
int (*create)(BIO *)) {
|
||||
method->create = create;
|
||||
int (*create_func)(BIO *)) {
|
||||
method->create = create_func;
|
||||
return 1;
|
||||
}
|
||||
|
||||
int BIO_meth_set_destroy(BIO_METHOD *method,
|
||||
int (*destroy)(BIO *)) {
|
||||
method->destroy = destroy;
|
||||
int (*destroy_func)(BIO *)) {
|
||||
method->destroy = destroy_func;
|
||||
return 1;
|
||||
}
|
||||
|
||||
int BIO_meth_set_write(BIO_METHOD *method,
|
||||
int (*write)(BIO *, const char *, int)) {
|
||||
method->bwrite = write;
|
||||
int (*write_func)(BIO *, const char *, int)) {
|
||||
method->bwrite = write_func;
|
||||
return 1;
|
||||
}
|
||||
|
||||
int BIO_meth_set_read(BIO_METHOD *method,
|
||||
int (*read)(BIO *, char *, int)) {
|
||||
method->bread = read;
|
||||
int (*read_func)(BIO *, char *, int)) {
|
||||
method->bread = read_func;
|
||||
return 1;
|
||||
}
|
||||
|
||||
int BIO_meth_set_gets(BIO_METHOD *method,
|
||||
int (*gets)(BIO *, char *, int)) {
|
||||
method->bgets = gets;
|
||||
int (*gets_func)(BIO *, char *, int)) {
|
||||
method->bgets = gets_func;
|
||||
return 1;
|
||||
}
|
||||
|
||||
int BIO_meth_set_ctrl(BIO_METHOD *method,
|
||||
long (*ctrl)(BIO *, int, long, void *)) {
|
||||
method->ctrl = ctrl;
|
||||
long (*ctrl_func)(BIO *, int, long, void *)) {
|
||||
method->ctrl = ctrl_func;
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
||||
@@ -507,11 +507,9 @@ int CBS_get_asn1_int64(CBS *cbs, int64_t *out) {
|
||||
return 0;
|
||||
}
|
||||
uint8_t sign_extend[sizeof(int64_t)];
|
||||
memset(sign_extend, is_negative ? 0xff : 0, sizeof(sign_extend));
|
||||
for (size_t i = 0; i < len; i++) {
|
||||
sign_extend[i] = data[len - i - 1];
|
||||
}
|
||||
memcpy(out, sign_extend, sizeof(sign_extend));
|
||||
OPENSSL_memset(sign_extend, is_negative ? 0xff : 0, sizeof(sign_extend));
|
||||
OPENSSL_memcpy(sign_extend + sizeof(int64_t) - len, data, len);
|
||||
*out = CRYPTO_load_u64_be(sign_extend);
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
||||
@@ -18,11 +18,12 @@
|
||||
|
||||
|
||||
static int is_valid_code_point(uint32_t v) {
|
||||
// References in the following are to Unicode 9.0.0.
|
||||
// References in the following are to Unicode 15.0.0.
|
||||
if (// The Unicode space runs from zero to 0x10ffff (3.4 D9).
|
||||
v > 0x10ffff ||
|
||||
// Values 0x...fffe, 0x...ffff, and 0xfdd0-0xfdef are permanently reserved
|
||||
// (3.4 D14)
|
||||
// as noncharacters (3.4 D14). See also 23.7. As our APIs are intended for
|
||||
// "open interchange", such as ASN.1, we reject them.
|
||||
(v & 0xfffe) == 0xfffe ||
|
||||
(v >= 0xfdd0 && v <= 0xfdef) ||
|
||||
// Surrogate code points are invalid (3.2 C1).
|
||||
|
||||
File diff suppressed because it is too large.
Load diff
@@ -1,973 +0,0 @@
|
||||
#define BORINGSSL_PREFIX CCryptoBoringSSL
|
||||
#if defined(__i386__) && defined(_WIN32)
|
||||
; This file is generated from a similarly-named Perl script in the BoringSSL
|
||||
; source tree. Do not edit by hand.
|
||||
|
||||
%ifdef BORINGSSL_PREFIX
|
||||
%include "boringssl_prefix_symbols_nasm.inc"
|
||||
%endif
|
||||
%ifidn __OUTPUT_FORMAT__, win32
|
||||
%ifidn __OUTPUT_FORMAT__,obj
|
||||
section code use32 class=code align=64
|
||||
%elifidn __OUTPUT_FORMAT__,win32
|
||||
$@feat.00 equ 1
|
||||
section .text code align=64
|
||||
%else
|
||||
section .text code
|
||||
%endif
|
||||
global _ChaCha20_ctr32_nohw
|
||||
align 16
|
||||
_ChaCha20_ctr32_nohw:
|
||||
L$_ChaCha20_ctr32_nohw_begin:
|
||||
push ebp
|
||||
push ebx
|
||||
push esi
|
||||
push edi
|
||||
mov esi,DWORD [32+esp]
|
||||
mov edi,DWORD [36+esp]
|
||||
sub esp,132
|
||||
mov eax,DWORD [esi]
|
||||
mov ebx,DWORD [4+esi]
|
||||
mov ecx,DWORD [8+esi]
|
||||
mov edx,DWORD [12+esi]
|
||||
mov DWORD [80+esp],eax
|
||||
mov DWORD [84+esp],ebx
|
||||
mov DWORD [88+esp],ecx
|
||||
mov DWORD [92+esp],edx
|
||||
mov eax,DWORD [16+esi]
|
||||
mov ebx,DWORD [20+esi]
|
||||
mov ecx,DWORD [24+esi]
|
||||
mov edx,DWORD [28+esi]
|
||||
mov DWORD [96+esp],eax
|
||||
mov DWORD [100+esp],ebx
|
||||
mov DWORD [104+esp],ecx
|
||||
mov DWORD [108+esp],edx
|
||||
mov eax,DWORD [edi]
|
||||
mov ebx,DWORD [4+edi]
|
||||
mov ecx,DWORD [8+edi]
|
||||
mov edx,DWORD [12+edi]
|
||||
sub eax,1
|
||||
mov DWORD [112+esp],eax
|
||||
mov DWORD [116+esp],ebx
|
||||
mov DWORD [120+esp],ecx
|
||||
mov DWORD [124+esp],edx
|
||||
jmp NEAR L$000entry
|
||||
align 16
|
||||
L$001outer_loop:
|
||||
mov DWORD [156+esp],ebx
|
||||
mov DWORD [152+esp],eax
|
||||
mov DWORD [160+esp],ecx
|
||||
L$000entry:
|
||||
mov eax,1634760805
|
||||
mov DWORD [4+esp],857760878
|
||||
mov DWORD [8+esp],2036477234
|
||||
mov DWORD [12+esp],1797285236
|
||||
mov ebx,DWORD [84+esp]
|
||||
mov ebp,DWORD [88+esp]
|
||||
mov ecx,DWORD [104+esp]
|
||||
mov esi,DWORD [108+esp]
|
||||
mov edx,DWORD [116+esp]
|
||||
mov edi,DWORD [120+esp]
|
||||
mov DWORD [20+esp],ebx
|
||||
mov DWORD [24+esp],ebp
|
||||
mov DWORD [40+esp],ecx
|
||||
mov DWORD [44+esp],esi
|
||||
mov DWORD [52+esp],edx
|
||||
mov DWORD [56+esp],edi
|
||||
mov ebx,DWORD [92+esp]
|
||||
mov edi,DWORD [124+esp]
|
||||
mov edx,DWORD [112+esp]
|
||||
mov ebp,DWORD [80+esp]
|
||||
mov ecx,DWORD [96+esp]
|
||||
mov esi,DWORD [100+esp]
|
||||
add edx,1
|
||||
mov DWORD [28+esp],ebx
|
||||
mov DWORD [60+esp],edi
|
||||
mov DWORD [112+esp],edx
|
||||
mov ebx,10
|
||||
jmp NEAR L$002loop
|
||||
align 16
|
||||
L$002loop:
|
||||
add eax,ebp
|
||||
mov DWORD [128+esp],ebx
|
||||
mov ebx,ebp
|
||||
xor edx,eax
|
||||
rol edx,16
|
||||
add ecx,edx
|
||||
xor ebx,ecx
|
||||
mov edi,DWORD [52+esp]
|
||||
rol ebx,12
|
||||
mov ebp,DWORD [20+esp]
|
||||
add eax,ebx
|
||||
xor edx,eax
|
||||
mov DWORD [esp],eax
|
||||
rol edx,8
|
||||
mov eax,DWORD [4+esp]
|
||||
add ecx,edx
|
||||
mov DWORD [48+esp],edx
|
||||
xor ebx,ecx
|
||||
add eax,ebp
|
||||
rol ebx,7
|
||||
xor edi,eax
|
||||
mov DWORD [32+esp],ecx
|
||||
rol edi,16
|
||||
mov DWORD [16+esp],ebx
|
||||
add esi,edi
|
||||
mov ecx,DWORD [40+esp]
|
||||
xor ebp,esi
|
||||
mov edx,DWORD [56+esp]
|
||||
rol ebp,12
|
||||
mov ebx,DWORD [24+esp]
|
||||
add eax,ebp
|
||||
xor edi,eax
|
||||
mov DWORD [4+esp],eax
|
||||
rol edi,8
|
||||
mov eax,DWORD [8+esp]
|
||||
add esi,edi
|
||||
mov DWORD [52+esp],edi
|
||||
xor ebp,esi
|
||||
add eax,ebx
|
||||
rol ebp,7
|
||||
xor edx,eax
|
||||
mov DWORD [36+esp],esi
|
||||
rol edx,16
|
||||
mov DWORD [20+esp],ebp
|
||||
add ecx,edx
|
||||
mov esi,DWORD [44+esp]
|
||||
xor ebx,ecx
|
||||
mov edi,DWORD [60+esp]
|
||||
rol ebx,12
|
||||
mov ebp,DWORD [28+esp]
|
||||
add eax,ebx
|
||||
xor edx,eax
|
||||
mov DWORD [8+esp],eax
|
||||
rol edx,8
|
||||
mov eax,DWORD [12+esp]
|
||||
add ecx,edx
|
||||
mov DWORD [56+esp],edx
|
||||
xor ebx,ecx
|
||||
add eax,ebp
|
||||
rol ebx,7
|
||||
xor edi,eax
|
||||
rol edi,16
|
||||
mov DWORD [24+esp],ebx
|
||||
add esi,edi
|
||||
xor ebp,esi
|
||||
rol ebp,12
|
||||
mov ebx,DWORD [20+esp]
|
||||
add eax,ebp
|
||||
xor edi,eax
|
||||
mov DWORD [12+esp],eax
|
||||
rol edi,8
|
||||
mov eax,DWORD [esp]
|
||||
add esi,edi
|
||||
mov edx,edi
|
||||
xor ebp,esi
|
||||
add eax,ebx
|
||||
rol ebp,7
|
||||
xor edx,eax
|
||||
rol edx,16
|
||||
mov DWORD [28+esp],ebp
|
||||
add ecx,edx
|
||||
xor ebx,ecx
|
||||
mov edi,DWORD [48+esp]
|
||||
rol ebx,12
|
||||
mov ebp,DWORD [24+esp]
|
||||
add eax,ebx
|
||||
xor edx,eax
|
||||
mov DWORD [esp],eax
|
||||
rol edx,8
|
||||
mov eax,DWORD [4+esp]
|
||||
add ecx,edx
|
||||
mov DWORD [60+esp],edx
|
||||
xor ebx,ecx
|
||||
add eax,ebp
|
||||
rol ebx,7
|
||||
xor edi,eax
|
||||
mov DWORD [40+esp],ecx
|
||||
rol edi,16
|
||||
mov DWORD [20+esp],ebx
|
||||
add esi,edi
|
||||
mov ecx,DWORD [32+esp]
|
||||
xor ebp,esi
|
||||
mov edx,DWORD [52+esp]
|
||||
rol ebp,12
|
||||
mov ebx,DWORD [28+esp]
|
||||
add eax,ebp
|
||||
xor edi,eax
|
||||
mov DWORD [4+esp],eax
|
||||
rol edi,8
|
||||
mov eax,DWORD [8+esp]
|
||||
add esi,edi
|
||||
mov DWORD [48+esp],edi
|
||||
xor ebp,esi
|
||||
add eax,ebx
|
||||
rol ebp,7
|
||||
xor edx,eax
|
||||
mov DWORD [44+esp],esi
|
||||
rol edx,16
|
||||
mov DWORD [24+esp],ebp
|
||||
add ecx,edx
|
||||
mov esi,DWORD [36+esp]
|
||||
xor ebx,ecx
|
||||
mov edi,DWORD [56+esp]
|
||||
rol ebx,12
|
||||
mov ebp,DWORD [16+esp]
|
||||
add eax,ebx
|
||||
xor edx,eax
|
||||
mov DWORD [8+esp],eax
|
||||
rol edx,8
|
||||
mov eax,DWORD [12+esp]
|
||||
add ecx,edx
|
||||
mov DWORD [52+esp],edx
|
||||
xor ebx,ecx
|
||||
add eax,ebp
|
||||
rol ebx,7
|
||||
xor edi,eax
|
||||
rol edi,16
|
||||
mov DWORD [28+esp],ebx
|
||||
add esi,edi
|
||||
xor ebp,esi
|
||||
mov edx,DWORD [48+esp]
|
||||
rol ebp,12
|
||||
mov ebx,DWORD [128+esp]
|
||||
add eax,ebp
|
||||
xor edi,eax
|
||||
mov DWORD [12+esp],eax
|
||||
rol edi,8
|
||||
mov eax,DWORD [esp]
|
||||
add esi,edi
|
||||
mov DWORD [56+esp],edi
|
||||
xor ebp,esi
|
||||
rol ebp,7
|
||||
dec ebx
|
||||
jnz NEAR L$002loop
|
||||
mov ebx,DWORD [160+esp]
|
||||
add eax,1634760805
|
||||
add ebp,DWORD [80+esp]
|
||||
add ecx,DWORD [96+esp]
|
||||
add esi,DWORD [100+esp]
|
||||
cmp ebx,64
|
||||
jb NEAR L$003tail
|
||||
mov ebx,DWORD [156+esp]
|
||||
add edx,DWORD [112+esp]
|
||||
add edi,DWORD [120+esp]
|
||||
xor eax,DWORD [ebx]
|
||||
xor ebp,DWORD [16+ebx]
|
||||
mov DWORD [esp],eax
|
||||
mov eax,DWORD [152+esp]
|
||||
xor ecx,DWORD [32+ebx]
|
||||
xor esi,DWORD [36+ebx]
|
||||
xor edx,DWORD [48+ebx]
|
||||
xor edi,DWORD [56+ebx]
|
||||
mov DWORD [16+eax],ebp
|
||||
mov DWORD [32+eax],ecx
|
||||
mov DWORD [36+eax],esi
|
||||
mov DWORD [48+eax],edx
|
||||
mov DWORD [56+eax],edi
|
||||
mov ebp,DWORD [4+esp]
|
||||
mov ecx,DWORD [8+esp]
|
||||
mov esi,DWORD [12+esp]
|
||||
mov edx,DWORD [20+esp]
|
||||
mov edi,DWORD [24+esp]
|
||||
add ebp,857760878
|
||||
add ecx,2036477234
|
||||
add esi,1797285236
|
||||
add edx,DWORD [84+esp]
|
||||
add edi,DWORD [88+esp]
|
||||
xor ebp,DWORD [4+ebx]
|
||||
xor ecx,DWORD [8+ebx]
|
||||
xor esi,DWORD [12+ebx]
|
||||
xor edx,DWORD [20+ebx]
|
||||
xor edi,DWORD [24+ebx]
|
||||
mov DWORD [4+eax],ebp
|
||||
mov DWORD [8+eax],ecx
|
||||
mov DWORD [12+eax],esi
|
||||
mov DWORD [20+eax],edx
|
||||
mov DWORD [24+eax],edi
|
||||
mov ebp,DWORD [28+esp]
|
||||
mov ecx,DWORD [40+esp]
|
||||
mov esi,DWORD [44+esp]
|
||||
mov edx,DWORD [52+esp]
|
||||
mov edi,DWORD [60+esp]
|
||||
add ebp,DWORD [92+esp]
|
||||
add ecx,DWORD [104+esp]
|
||||
add esi,DWORD [108+esp]
|
||||
add edx,DWORD [116+esp]
|
||||
add edi,DWORD [124+esp]
|
||||
xor ebp,DWORD [28+ebx]
|
||||
xor ecx,DWORD [40+ebx]
|
||||
xor esi,DWORD [44+ebx]
|
||||
xor edx,DWORD [52+ebx]
|
||||
xor edi,DWORD [60+ebx]
|
||||
lea ebx,[64+ebx]
|
||||
mov DWORD [28+eax],ebp
|
||||
mov ebp,DWORD [esp]
|
||||
mov DWORD [40+eax],ecx
|
||||
mov ecx,DWORD [160+esp]
|
||||
mov DWORD [44+eax],esi
|
||||
mov DWORD [52+eax],edx
|
||||
mov DWORD [60+eax],edi
|
||||
mov DWORD [eax],ebp
|
||||
lea eax,[64+eax]
|
||||
sub ecx,64
|
||||
jnz NEAR L$001outer_loop
|
||||
jmp NEAR L$004done
|
||||
L$003tail:
|
||||
add edx,DWORD [112+esp]
|
||||
add edi,DWORD [120+esp]
|
||||
mov DWORD [esp],eax
|
||||
mov DWORD [16+esp],ebp
|
||||
mov DWORD [32+esp],ecx
|
||||
mov DWORD [36+esp],esi
|
||||
mov DWORD [48+esp],edx
|
||||
mov DWORD [56+esp],edi
|
||||
mov ebp,DWORD [4+esp]
|
||||
mov ecx,DWORD [8+esp]
|
||||
mov esi,DWORD [12+esp]
|
||||
mov edx,DWORD [20+esp]
|
||||
mov edi,DWORD [24+esp]
|
||||
add ebp,857760878
|
||||
add ecx,2036477234
|
||||
add esi,1797285236
|
||||
add edx,DWORD [84+esp]
|
||||
add edi,DWORD [88+esp]
|
||||
mov DWORD [4+esp],ebp
|
||||
mov DWORD [8+esp],ecx
|
||||
mov DWORD [12+esp],esi
|
||||
mov DWORD [20+esp],edx
|
||||
mov DWORD [24+esp],edi
|
||||
mov ebp,DWORD [28+esp]
|
||||
mov ecx,DWORD [40+esp]
|
||||
mov esi,DWORD [44+esp]
|
||||
mov edx,DWORD [52+esp]
|
||||
mov edi,DWORD [60+esp]
|
||||
add ebp,DWORD [92+esp]
|
||||
add ecx,DWORD [104+esp]
|
||||
add esi,DWORD [108+esp]
|
||||
add edx,DWORD [116+esp]
|
||||
add edi,DWORD [124+esp]
|
||||
mov DWORD [28+esp],ebp
|
||||
mov ebp,DWORD [156+esp]
|
||||
mov DWORD [40+esp],ecx
|
||||
mov ecx,DWORD [152+esp]
|
||||
mov DWORD [44+esp],esi
|
||||
xor esi,esi
|
||||
mov DWORD [52+esp],edx
|
||||
mov DWORD [60+esp],edi
|
||||
xor eax,eax
|
||||
xor edx,edx
|
||||
L$005tail_loop:
|
||||
mov al,BYTE [ebp*1+esi]
|
||||
mov dl,BYTE [esi*1+esp]
|
||||
lea esi,[1+esi]
|
||||
xor al,dl
|
||||
mov BYTE [esi*1+ecx-1],al
|
||||
dec ebx
|
||||
jnz NEAR L$005tail_loop
|
||||
L$004done:
|
||||
add esp,132
|
||||
pop edi
|
||||
pop esi
|
||||
pop ebx
|
||||
pop ebp
|
||||
ret
|
||||
global _ChaCha20_ctr32_ssse3
|
||||
align 16
|
||||
_ChaCha20_ctr32_ssse3:
|
||||
L$_ChaCha20_ctr32_ssse3_begin:
|
||||
push ebp
|
||||
push ebx
|
||||
push esi
|
||||
push edi
|
||||
call L$pic_point
|
||||
L$pic_point:
|
||||
pop eax
|
||||
mov edi,DWORD [20+esp]
|
||||
mov esi,DWORD [24+esp]
|
||||
mov ecx,DWORD [28+esp]
|
||||
mov edx,DWORD [32+esp]
|
||||
mov ebx,DWORD [36+esp]
|
||||
mov ebp,esp
|
||||
sub esp,524
|
||||
and esp,-64
|
||||
mov DWORD [512+esp],ebp
|
||||
lea eax,[(L$ssse3_data-L$pic_point)+eax]
|
||||
movdqu xmm3,[ebx]
|
||||
cmp ecx,256
|
||||
jb NEAR L$0061x
|
||||
mov DWORD [516+esp],edx
|
||||
mov DWORD [520+esp],ebx
|
||||
sub ecx,256
|
||||
lea ebp,[384+esp]
|
||||
movdqu xmm7,[edx]
|
||||
pshufd xmm0,xmm3,0
|
||||
pshufd xmm1,xmm3,85
|
||||
pshufd xmm2,xmm3,170
|
||||
pshufd xmm3,xmm3,255
|
||||
paddd xmm0,[48+eax]
|
||||
pshufd xmm4,xmm7,0
|
||||
pshufd xmm5,xmm7,85
|
||||
psubd xmm0,[64+eax]
|
||||
pshufd xmm6,xmm7,170
|
||||
pshufd xmm7,xmm7,255
|
||||
movdqa [64+ebp],xmm0
|
||||
movdqa [80+ebp],xmm1
|
||||
movdqa [96+ebp],xmm2
|
||||
movdqa [112+ebp],xmm3
|
||||
movdqu xmm3,[16+edx]
|
||||
movdqa [ebp-64],xmm4
|
||||
movdqa [ebp-48],xmm5
|
||||
movdqa [ebp-32],xmm6
|
||||
movdqa [ebp-16],xmm7
|
||||
movdqa xmm7,[32+eax]
|
||||
lea ebx,[128+esp]
|
||||
pshufd xmm0,xmm3,0
|
||||
pshufd xmm1,xmm3,85
|
||||
pshufd xmm2,xmm3,170
|
||||
pshufd xmm3,xmm3,255
|
||||
pshufd xmm4,xmm7,0
|
||||
pshufd xmm5,xmm7,85
|
||||
pshufd xmm6,xmm7,170
|
||||
pshufd xmm7,xmm7,255
|
||||
movdqa [ebp],xmm0
|
||||
movdqa [16+ebp],xmm1
|
||||
movdqa [32+ebp],xmm2
|
||||
movdqa [48+ebp],xmm3
|
||||
movdqa [ebp-128],xmm4
|
||||
movdqa [ebp-112],xmm5
|
||||
movdqa [ebp-96],xmm6
|
||||
movdqa [ebp-80],xmm7
|
||||
lea esi,[128+esi]
|
||||
lea edi,[128+edi]
|
||||
jmp NEAR L$007outer_loop
|
||||
align 16
|
||||
L$007outer_loop:
|
||||
movdqa xmm1,[ebp-112]
|
||||
movdqa xmm2,[ebp-96]
|
||||
movdqa xmm3,[ebp-80]
|
||||
movdqa xmm5,[ebp-48]
|
||||
movdqa xmm6,[ebp-32]
|
||||
movdqa xmm7,[ebp-16]
|
||||
movdqa [ebx-112],xmm1
|
||||
movdqa [ebx-96],xmm2
|
||||
movdqa [ebx-80],xmm3
|
||||
movdqa [ebx-48],xmm5
|
||||
movdqa [ebx-32],xmm6
|
||||
movdqa [ebx-16],xmm7
|
||||
movdqa xmm2,[32+ebp]
|
||||
movdqa xmm3,[48+ebp]
|
||||
movdqa xmm4,[64+ebp]
|
||||
movdqa xmm5,[80+ebp]
|
||||
movdqa xmm6,[96+ebp]
|
||||
movdqa xmm7,[112+ebp]
|
||||
paddd xmm4,[64+eax]
|
||||
movdqa [32+ebx],xmm2
|
||||
movdqa [48+ebx],xmm3
|
||||
movdqa [64+ebx],xmm4
|
||||
movdqa [80+ebx],xmm5
|
||||
movdqa [96+ebx],xmm6
|
||||
movdqa [112+ebx],xmm7
|
||||
movdqa [64+ebp],xmm4
|
||||
movdqa xmm0,[ebp-128]
|
||||
movdqa xmm6,xmm4
|
||||
movdqa xmm3,[ebp-64]
|
||||
movdqa xmm4,[ebp]
|
||||
movdqa xmm5,[16+ebp]
|
||||
mov edx,10
|
||||
nop
|
||||
align 16
|
||||
L$008loop:
|
||||
paddd xmm0,xmm3
|
||||
movdqa xmm2,xmm3
|
||||
pxor xmm6,xmm0
|
||||
pshufb xmm6,[eax]
|
||||
paddd xmm4,xmm6
|
||||
pxor xmm2,xmm4
|
||||
movdqa xmm3,[ebx-48]
|
||||
movdqa xmm1,xmm2
|
||||
pslld xmm2,12
|
||||
psrld xmm1,20
|
||||
por xmm2,xmm1
|
||||
movdqa xmm1,[ebx-112]
|
||||
paddd xmm0,xmm2
|
||||
movdqa xmm7,[80+ebx]
|
||||
pxor xmm6,xmm0
|
||||
movdqa [ebx-128],xmm0
|
||||
pshufb xmm6,[16+eax]
|
||||
paddd xmm4,xmm6
|
||||
movdqa [64+ebx],xmm6
|
||||
pxor xmm2,xmm4
|
||||
paddd xmm1,xmm3
|
||||
movdqa xmm0,xmm2
|
||||
pslld xmm2,7
|
||||
psrld xmm0,25
|
||||
pxor xmm7,xmm1
|
||||
por xmm2,xmm0
|
||||
movdqa [ebx],xmm4
|
||||
pshufb xmm7,[eax]
|
||||
movdqa [ebx-64],xmm2
|
||||
paddd xmm5,xmm7
|
||||
movdqa xmm4,[32+ebx]
|
||||
pxor xmm3,xmm5
|
||||
movdqa xmm2,[ebx-32]
|
||||
movdqa xmm0,xmm3
|
||||
pslld xmm3,12
|
||||
psrld xmm0,20
|
||||
por xmm3,xmm0
|
||||
movdqa xmm0,[ebx-96]
|
||||
paddd xmm1,xmm3
|
||||
movdqa xmm6,[96+ebx]
|
||||
pxor xmm7,xmm1
|
||||
movdqa [ebx-112],xmm1
|
||||
pshufb xmm7,[16+eax]
|
||||
paddd xmm5,xmm7
|
||||
movdqa [80+ebx],xmm7
|
||||
pxor xmm3,xmm5
|
||||
paddd xmm0,xmm2
|
||||
movdqa xmm1,xmm3
|
||||
pslld xmm3,7
|
||||
psrld xmm1,25
|
||||
pxor xmm6,xmm0
|
||||
por xmm3,xmm1
|
||||
movdqa [16+ebx],xmm5
|
||||
pshufb xmm6,[eax]
|
||||
movdqa [ebx-48],xmm3
|
||||
paddd xmm4,xmm6
|
||||
movdqa xmm5,[48+ebx]
|
||||
pxor xmm2,xmm4
|
||||
movdqa xmm3,[ebx-16]
|
||||
movdqa xmm1,xmm2
|
||||
pslld xmm2,12
|
||||
psrld xmm1,20
|
||||
por xmm2,xmm1
|
||||
movdqa xmm1,[ebx-80]
|
||||
paddd xmm0,xmm2
|
||||
movdqa xmm7,[112+ebx]
|
||||
pxor xmm6,xmm0
|
||||
movdqa [ebx-96],xmm0
|
||||
pshufb xmm6,[16+eax]
|
||||
paddd xmm4,xmm6
|
||||
movdqa [96+ebx],xmm6
|
||||
pxor xmm2,xmm4
|
||||
paddd xmm1,xmm3
|
||||
movdqa xmm0,xmm2
|
||||
pslld xmm2,7
|
||||
psrld xmm0,25
|
||||
pxor xmm7,xmm1
|
||||
por xmm2,xmm0
|
||||
pshufb xmm7,[eax]
|
||||
movdqa [ebx-32],xmm2
|
||||
paddd xmm5,xmm7
|
||||
pxor xmm3,xmm5
|
||||
movdqa xmm2,[ebx-48]
|
||||
movdqa xmm0,xmm3
|
||||
pslld xmm3,12
|
||||
psrld xmm0,20
|
||||
por xmm3,xmm0
|
||||
movdqa xmm0,[ebx-128]
|
||||
paddd xmm1,xmm3
|
||||
pxor xmm7,xmm1
|
||||
movdqa [ebx-80],xmm1
|
||||
pshufb xmm7,[16+eax]
|
||||
paddd xmm5,xmm7
|
||||
movdqa xmm6,xmm7
|
||||
pxor xmm3,xmm5
|
||||
paddd xmm0,xmm2
|
||||
movdqa xmm1,xmm3
|
||||
pslld xmm3,7
|
||||
psrld xmm1,25
|
||||
pxor xmm6,xmm0
|
||||
por xmm3,xmm1
|
||||
pshufb xmm6,[eax]
|
||||
movdqa [ebx-16],xmm3
|
||||
paddd xmm4,xmm6
|
||||
pxor xmm2,xmm4
|
||||
movdqa xmm3,[ebx-32]
|
||||
movdqa xmm1,xmm2
|
||||
pslld xmm2,12
|
||||
psrld xmm1,20
|
||||
por xmm2,xmm1
|
||||
movdqa xmm1,[ebx-112]
|
||||
paddd xmm0,xmm2
|
||||
movdqa xmm7,[64+ebx]
|
||||
pxor xmm6,xmm0
|
||||
movdqa [ebx-128],xmm0
|
||||
pshufb xmm6,[16+eax]
|
||||
paddd xmm4,xmm6
|
||||
movdqa [112+ebx],xmm6
|
||||
pxor xmm2,xmm4
|
||||
paddd xmm1,xmm3
|
||||
movdqa xmm0,xmm2
|
||||
pslld xmm2,7
|
||||
psrld xmm0,25
|
||||
pxor xmm7,xmm1
|
||||
por xmm2,xmm0
|
||||
movdqa [32+ebx],xmm4
|
||||
pshufb xmm7,[eax]
|
||||
movdqa [ebx-48],xmm2
|
||||
paddd xmm5,xmm7
|
||||
movdqa xmm4,[ebx]
|
||||
pxor xmm3,xmm5
|
||||
movdqa xmm2,[ebx-16]
|
||||
movdqa xmm0,xmm3
|
||||
pslld xmm3,12
|
||||
psrld xmm0,20
|
||||
por xmm3,xmm0
|
||||
movdqa xmm0,[ebx-96]
|
||||
paddd xmm1,xmm3
|
||||
movdqa xmm6,[80+ebx]
|
||||
pxor xmm7,xmm1
|
||||
movdqa [ebx-112],xmm1
|
||||
pshufb xmm7,[16+eax]
|
||||
paddd xmm5,xmm7
|
||||
movdqa [64+ebx],xmm7
|
||||
pxor xmm3,xmm5
|
||||
paddd xmm0,xmm2
|
||||
movdqa xmm1,xmm3
|
||||
pslld xmm3,7
|
||||
psrld xmm1,25
|
||||
pxor xmm6,xmm0
|
||||
por xmm3,xmm1
|
||||
movdqa [48+ebx],xmm5
|
||||
pshufb xmm6,[eax]
|
||||
movdqa [ebx-32],xmm3
|
||||
paddd xmm4,xmm6
|
||||
movdqa xmm5,[16+ebx]
|
||||
pxor xmm2,xmm4
|
||||
movdqa xmm3,[ebx-64]
|
||||
movdqa xmm1,xmm2
|
||||
pslld xmm2,12
|
||||
psrld xmm1,20
|
||||
por xmm2,xmm1
|
||||
movdqa xmm1,[ebx-80]
|
||||
paddd xmm0,xmm2
|
||||
movdqa xmm7,[96+ebx]
|
||||
pxor xmm6,xmm0
|
||||
movdqa [ebx-96],xmm0
|
||||
pshufb xmm6,[16+eax]
|
||||
paddd xmm4,xmm6
|
||||
movdqa [80+ebx],xmm6
|
||||
pxor xmm2,xmm4
|
||||
paddd xmm1,xmm3
|
||||
movdqa xmm0,xmm2
|
||||
pslld xmm2,7
|
||||
psrld xmm0,25
|
||||
pxor xmm7,xmm1
|
||||
por xmm2,xmm0
|
||||
pshufb xmm7,[eax]
|
||||
movdqa [ebx-16],xmm2
|
||||
paddd xmm5,xmm7
|
||||
pxor xmm3,xmm5
|
||||
movdqa xmm0,xmm3
|
||||
pslld xmm3,12
|
||||
psrld xmm0,20
|
||||
por xmm3,xmm0
|
||||
movdqa xmm0,[ebx-128]
|
||||
paddd xmm1,xmm3
|
||||
movdqa xmm6,[64+ebx]
|
||||
pxor xmm7,xmm1
|
||||
movdqa [ebx-80],xmm1
|
||||
pshufb xmm7,[16+eax]
|
||||
paddd xmm5,xmm7
|
||||
movdqa [96+ebx],xmm7
|
||||
pxor xmm3,xmm5
|
||||
movdqa xmm1,xmm3
|
||||
pslld xmm3,7
|
||||
psrld xmm1,25
|
||||
por xmm3,xmm1
|
||||
dec edx
|
||||
jnz NEAR L$008loop
|
||||
movdqa [ebx-64],xmm3
|
||||
movdqa [ebx],xmm4
|
||||
movdqa [16+ebx],xmm5
|
||||
movdqa [64+ebx],xmm6
|
||||
movdqa [96+ebx],xmm7
|
||||
movdqa xmm1,[ebx-112]
|
||||
movdqa xmm2,[ebx-96]
|
||||
movdqa xmm3,[ebx-80]
|
||||
paddd xmm0,[ebp-128]
|
||||
paddd xmm1,[ebp-112]
|
||||
paddd xmm2,[ebp-96]
|
||||
paddd xmm3,[ebp-80]
|
||||
movdqa xmm6,xmm0
|
||||
punpckldq xmm0,xmm1
|
||||
movdqa xmm7,xmm2
|
||||
punpckldq xmm2,xmm3
|
||||
punpckhdq xmm6,xmm1
|
||||
punpckhdq xmm7,xmm3
|
||||
movdqa xmm1,xmm0
|
||||
punpcklqdq xmm0,xmm2
|
||||
movdqa xmm3,xmm6
|
||||
punpcklqdq xmm6,xmm7
|
||||
punpckhqdq xmm1,xmm2
|
||||
punpckhqdq xmm3,xmm7
|
||||
movdqu xmm4,[esi-128]
|
||||
movdqu xmm5,[esi-64]
|
||||
movdqu xmm2,[esi]
|
||||
movdqu xmm7,[64+esi]
|
||||
lea esi,[16+esi]
|
||||
pxor xmm4,xmm0
|
||||
movdqa xmm0,[ebx-64]
|
||||
pxor xmm5,xmm1
|
||||
movdqa xmm1,[ebx-48]
|
||||
pxor xmm6,xmm2
|
||||
movdqa xmm2,[ebx-32]
|
||||
pxor xmm7,xmm3
|
||||
movdqa xmm3,[ebx-16]
|
||||
movdqu [edi-128],xmm4
|
||||
movdqu [edi-64],xmm5
|
||||
movdqu [edi],xmm6
|
||||
movdqu [64+edi],xmm7
|
||||
lea edi,[16+edi]
|
||||
paddd xmm0,[ebp-64]
|
||||
paddd xmm1,[ebp-48]
|
||||
paddd xmm2,[ebp-32]
|
||||
paddd xmm3,[ebp-16]
|
||||
movdqa xmm6,xmm0
|
||||
punpckldq xmm0,xmm1
|
||||
movdqa xmm7,xmm2
|
||||
punpckldq xmm2,xmm3
|
||||
punpckhdq xmm6,xmm1
|
||||
punpckhdq xmm7,xmm3
|
||||
movdqa xmm1,xmm0
|
||||
punpcklqdq xmm0,xmm2
|
||||
movdqa xmm3,xmm6
|
||||
punpcklqdq xmm6,xmm7
|
||||
punpckhqdq xmm1,xmm2
|
||||
punpckhqdq xmm3,xmm7
|
||||
movdqu xmm4,[esi-128]
|
||||
movdqu xmm5,[esi-64]
|
||||
movdqu xmm2,[esi]
|
||||
movdqu xmm7,[64+esi]
|
||||
lea esi,[16+esi]
|
||||
pxor xmm4,xmm0
|
||||
movdqa xmm0,[ebx]
|
||||
pxor xmm5,xmm1
|
||||
movdqa xmm1,[16+ebx]
|
||||
pxor xmm6,xmm2
|
||||
movdqa xmm2,[32+ebx]
|
||||
pxor xmm7,xmm3
|
||||
movdqa xmm3,[48+ebx]
|
||||
movdqu [edi-128],xmm4
|
||||
movdqu [edi-64],xmm5
|
||||
movdqu [edi],xmm6
|
||||
movdqu [64+edi],xmm7
|
||||
lea edi,[16+edi]
|
||||
paddd xmm0,[ebp]
|
||||
paddd xmm1,[16+ebp]
|
||||
paddd xmm2,[32+ebp]
|
||||
paddd xmm3,[48+ebp]
|
||||
movdqa xmm6,xmm0
|
||||
punpckldq xmm0,xmm1
|
||||
movdqa xmm7,xmm2
|
||||
punpckldq xmm2,xmm3
|
||||
punpckhdq xmm6,xmm1
|
||||
punpckhdq xmm7,xmm3
|
||||
movdqa xmm1,xmm0
|
||||
punpcklqdq xmm0,xmm2
|
||||
movdqa xmm3,xmm6
|
||||
punpcklqdq xmm6,xmm7
|
||||
punpckhqdq xmm1,xmm2
|
||||
punpckhqdq xmm3,xmm7
|
||||
movdqu xmm4,[esi-128]
|
||||
movdqu xmm5,[esi-64]
|
||||
movdqu xmm2,[esi]
|
||||
movdqu xmm7,[64+esi]
|
||||
lea esi,[16+esi]
|
||||
pxor xmm4,xmm0
|
||||
movdqa xmm0,[64+ebx]
|
||||
pxor xmm5,xmm1
|
||||
movdqa xmm1,[80+ebx]
|
||||
pxor xmm6,xmm2
|
||||
movdqa xmm2,[96+ebx]
|
||||
pxor xmm7,xmm3
|
||||
movdqa xmm3,[112+ebx]
|
||||
movdqu [edi-128],xmm4
|
||||
movdqu [edi-64],xmm5
|
||||
movdqu [edi],xmm6
|
||||
movdqu [64+edi],xmm7
|
||||
lea edi,[16+edi]
|
||||
paddd xmm0,[64+ebp]
|
||||
paddd xmm1,[80+ebp]
|
||||
paddd xmm2,[96+ebp]
|
||||
paddd xmm3,[112+ebp]
|
||||
movdqa xmm6,xmm0
|
||||
punpckldq xmm0,xmm1
|
||||
movdqa xmm7,xmm2
|
||||
punpckldq xmm2,xmm3
|
||||
punpckhdq xmm6,xmm1
|
||||
punpckhdq xmm7,xmm3
|
||||
movdqa xmm1,xmm0
|
||||
punpcklqdq xmm0,xmm2
|
||||
movdqa xmm3,xmm6
|
||||
punpcklqdq xmm6,xmm7
|
||||
punpckhqdq xmm1,xmm2
|
||||
punpckhqdq xmm3,xmm7
|
||||
movdqu xmm4,[esi-128]
|
||||
movdqu xmm5,[esi-64]
|
||||
movdqu xmm2,[esi]
|
||||
movdqu xmm7,[64+esi]
|
||||
lea esi,[208+esi]
|
||||
pxor xmm4,xmm0
|
||||
pxor xmm5,xmm1
|
||||
pxor xmm6,xmm2
|
||||
pxor xmm7,xmm3
|
||||
movdqu [edi-128],xmm4
|
||||
movdqu [edi-64],xmm5
|
||||
movdqu [edi],xmm6
|
||||
movdqu [64+edi],xmm7
|
||||
lea edi,[208+edi]
|
||||
sub ecx,256
|
||||
jnc NEAR L$007outer_loop
|
||||
add ecx,256
|
||||
jz NEAR L$009done
|
||||
mov ebx,DWORD [520+esp]
|
||||
lea esi,[esi-128]
|
||||
mov edx,DWORD [516+esp]
|
||||
lea edi,[edi-128]
|
||||
movd xmm2,DWORD [64+ebp]
|
||||
movdqu xmm3,[ebx]
|
||||
paddd xmm2,[96+eax]
|
||||
pand xmm3,[112+eax]
|
||||
por xmm3,xmm2
|
||||
L$0061x:
|
||||
movdqa xmm0,[32+eax]
|
||||
movdqu xmm1,[edx]
|
||||
movdqu xmm2,[16+edx]
|
||||
movdqa xmm6,[eax]
|
||||
movdqa xmm7,[16+eax]
|
||||
mov DWORD [48+esp],ebp
|
||||
movdqa [esp],xmm0
|
||||
movdqa [16+esp],xmm1
|
||||
movdqa [32+esp],xmm2
|
||||
movdqa [48+esp],xmm3
|
||||
mov edx,10
|
||||
jmp NEAR L$010loop1x
|
||||
align 16
|
||||
L$011outer1x:
|
||||
movdqa xmm3,[80+eax]
|
||||
movdqa xmm0,[esp]
|
||||
movdqa xmm1,[16+esp]
|
||||
movdqa xmm2,[32+esp]
|
||||
paddd xmm3,[48+esp]
|
||||
mov edx,10
|
||||
movdqa [48+esp],xmm3
|
||||
jmp NEAR L$010loop1x
|
||||
align 16
|
||||
L$010loop1x:
|
||||
paddd xmm0,xmm1
|
||||
pxor xmm3,xmm0
|
||||
db 102,15,56,0,222
|
||||
paddd xmm2,xmm3
|
||||
pxor xmm1,xmm2
|
||||
movdqa xmm4,xmm1
|
||||
psrld xmm1,20
|
||||
pslld xmm4,12
|
||||
por xmm1,xmm4
|
||||
paddd xmm0,xmm1
|
||||
pxor xmm3,xmm0
|
||||
db 102,15,56,0,223
|
||||
paddd xmm2,xmm3
|
||||
pxor xmm1,xmm2
|
||||
movdqa xmm4,xmm1
|
||||
psrld xmm1,25
|
||||
pslld xmm4,7
|
||||
por xmm1,xmm4
|
||||
pshufd xmm2,xmm2,78
|
||||
pshufd xmm1,xmm1,57
|
||||
pshufd xmm3,xmm3,147
|
||||
nop
|
||||
paddd xmm0,xmm1
|
||||
pxor xmm3,xmm0
|
||||
db 102,15,56,0,222
|
||||
paddd xmm2,xmm3
|
||||
pxor xmm1,xmm2
|
||||
movdqa xmm4,xmm1
|
||||
psrld xmm1,20
|
||||
pslld xmm4,12
|
||||
por xmm1,xmm4
|
||||
paddd xmm0,xmm1
|
||||
pxor xmm3,xmm0
|
||||
db 102,15,56,0,223
|
||||
paddd xmm2,xmm3
|
||||
pxor xmm1,xmm2
|
||||
movdqa xmm4,xmm1
|
||||
psrld xmm1,25
|
||||
pslld xmm4,7
|
||||
por xmm1,xmm4
|
||||
pshufd xmm2,xmm2,78
|
||||
pshufd xmm1,xmm1,147
|
||||
pshufd xmm3,xmm3,57
|
||||
dec edx
|
||||
jnz NEAR L$010loop1x
|
||||
paddd xmm0,[esp]
|
||||
paddd xmm1,[16+esp]
|
||||
paddd xmm2,[32+esp]
|
||||
paddd xmm3,[48+esp]
|
||||
cmp ecx,64
|
||||
jb NEAR L$012tail
|
||||
movdqu xmm4,[esi]
|
||||
movdqu xmm5,[16+esi]
|
||||
pxor xmm0,xmm4
|
||||
movdqu xmm4,[32+esi]
|
||||
pxor xmm1,xmm5
|
||||
movdqu xmm5,[48+esi]
|
||||
pxor xmm2,xmm4
|
||||
pxor xmm3,xmm5
|
||||
lea esi,[64+esi]
|
||||
movdqu [edi],xmm0
|
||||
movdqu [16+edi],xmm1
|
||||
movdqu [32+edi],xmm2
|
||||
movdqu [48+edi],xmm3
|
||||
lea edi,[64+edi]
|
||||
sub ecx,64
|
||||
jnz NEAR L$011outer1x
|
||||
jmp NEAR L$009done
|
||||
L$012tail:
|
||||
movdqa [esp],xmm0
|
||||
movdqa [16+esp],xmm1
|
||||
movdqa [32+esp],xmm2
|
||||
movdqa [48+esp],xmm3
|
||||
xor eax,eax
|
||||
xor edx,edx
|
||||
xor ebp,ebp
|
||||
L$013tail_loop:
|
||||
mov al,BYTE [ebp*1+esp]
|
||||
mov dl,BYTE [ebp*1+esi]
|
||||
lea ebp,[1+ebp]
|
||||
xor al,dl
|
||||
mov BYTE [ebp*1+edi-1],al
|
||||
dec ecx
|
||||
jnz NEAR L$013tail_loop
|
||||
L$009done:
|
||||
mov esp,DWORD [512+esp]
|
||||
pop edi
|
||||
pop esi
|
||||
pop ebx
|
||||
pop ebp
|
||||
ret
|
||||
align 64
|
||||
L$ssse3_data:
|
||||
db 2,3,0,1,6,7,4,5,10,11,8,9,14,15,12,13
|
||||
db 3,0,1,2,7,4,5,6,11,8,9,10,15,12,13,14
|
||||
dd 1634760805,857760878,2036477234,1797285236
|
||||
dd 0,1,2,3
|
||||
dd 4,4,4,4
|
||||
dd 1,0,0,0
|
||||
dd 4,0,0,0
|
||||
dd 0,-1,-1,-1
|
||||
align 64
|
||||
db 67,104,97,67,104,97,50,48,32,102,111,114,32,120,56,54
|
||||
db 44,32,67,82,89,80,84,79,71,65,77,83,32,98,121,32
|
||||
db 60,97,112,112,114,111,64,111,112,101,110,115,115,108,46,111
|
||||
db 114,103,62,0
|
||||
%else
|
||||
; Work around https://bugzilla.nasm.us/show_bug.cgi?id=3392738
|
||||
ret
|
||||
%endif
|
||||
#endif // defined(__i386__) && defined(_WIN32)
|
||||
#if defined(__linux__) && defined(__ELF__)
|
||||
.section .note.GNU-stack,"",%progbits
|
||||
#endif
|
||||
|
||||
@@ -85,17 +85,14 @@ static int des_cbc_cipher(EVP_CIPHER_CTX *ctx, uint8_t *out, const uint8_t *in,
|
||||
}
|
||||
|
||||
static const EVP_CIPHER evp_des_cbc = {
|
||||
/* nid = */ NID_des_cbc,
|
||||
/* block_size = */ 8,
|
||||
/* key_len = */ 8,
|
||||
/* iv_len = */ 8,
|
||||
/* ctx_size = */ sizeof(EVP_DES_KEY),
|
||||
/* flags = */ EVP_CIPH_CBC_MODE,
|
||||
/* app_data = */ NULL,
|
||||
/* init = */ des_init_key,
|
||||
/* cipher = */ des_cbc_cipher,
|
||||
/* cleanup = */ NULL,
|
||||
/* ctrl = */ NULL,
|
||||
.nid = NID_des_cbc,
|
||||
.block_size = 8,
|
||||
.key_len = 8,
|
||||
.iv_len = 8,
|
||||
.ctx_size = sizeof(EVP_DES_KEY),
|
||||
.flags = EVP_CIPH_CBC_MODE,
|
||||
.init = des_init_key,
|
||||
.cipher = des_cbc_cipher,
|
||||
};
|
||||
|
||||
const EVP_CIPHER *EVP_des_cbc(void) { return &evp_des_cbc; }
|
||||
@@ -115,17 +112,14 @@ static int des_ecb_cipher(EVP_CIPHER_CTX *ctx, uint8_t *out, const uint8_t *in,
|
||||
}
|
||||
|
||||
static const EVP_CIPHER evp_des_ecb = {
|
||||
/* nid = */ NID_des_ecb,
|
||||
/* block_size = */ 8,
|
||||
/* key_len = */ 8,
|
||||
/* iv_len = */ 0,
|
||||
/* ctx_size = */ sizeof(EVP_DES_KEY),
|
||||
/* flags = */ EVP_CIPH_ECB_MODE,
|
||||
/* app_data = */ NULL,
|
||||
/* init = */ des_init_key,
|
||||
/* cipher = */ des_ecb_cipher,
|
||||
/* cleanup = */ NULL,
|
||||
/* ctrl = */ NULL,
|
||||
.nid = NID_des_ecb,
|
||||
.block_size = 8,
|
||||
.key_len = 8,
|
||||
.iv_len = 0,
|
||||
.ctx_size = sizeof(EVP_DES_KEY),
|
||||
.flags = EVP_CIPH_ECB_MODE,
|
||||
.init = des_init_key,
|
||||
.cipher = des_ecb_cipher,
|
||||
};
|
||||
|
||||
const EVP_CIPHER *EVP_des_ecb(void) { return &evp_des_ecb; }
|
||||
@@ -155,17 +149,14 @@ static int des_ede3_cbc_cipher(EVP_CIPHER_CTX *ctx, uint8_t *out,
|
||||
}
|
||||
|
||||
static const EVP_CIPHER evp_des_ede3_cbc = {
|
||||
/* nid = */ NID_des_ede3_cbc,
|
||||
/* block_size = */ 8,
|
||||
/* key_len = */ 24,
|
||||
/* iv_len = */ 8,
|
||||
/* ctx_size = */ sizeof(DES_EDE_KEY),
|
||||
/* flags = */ EVP_CIPH_CBC_MODE,
|
||||
/* app_data = */ NULL,
|
||||
/* init = */ des_ede3_init_key,
|
||||
/* cipher = */ des_ede3_cbc_cipher,
|
||||
/* cleanup = */ NULL,
|
||||
/* ctrl = */ NULL,
|
||||
.nid = NID_des_ede3_cbc,
|
||||
.block_size = 8,
|
||||
.key_len = 24,
|
||||
.iv_len = 8,
|
||||
.ctx_size = sizeof(DES_EDE_KEY),
|
||||
.flags = EVP_CIPH_CBC_MODE,
|
||||
.init = des_ede3_init_key,
|
||||
.cipher = des_ede3_cbc_cipher,
|
||||
};
|
||||
|
||||
const EVP_CIPHER *EVP_des_ede3_cbc(void) { return &evp_des_ede3_cbc; }
|
||||
@@ -181,17 +172,14 @@ static int des_ede_init_key(EVP_CIPHER_CTX *ctx, const uint8_t *key,
|
||||
}
|
||||
|
||||
static const EVP_CIPHER evp_des_ede_cbc = {
|
||||
/* nid = */ NID_des_ede_cbc,
|
||||
/* block_size = */ 8,
|
||||
/* key_len = */ 16,
|
||||
/* iv_len = */ 8,
|
||||
/* ctx_size = */ sizeof(DES_EDE_KEY),
|
||||
/* flags = */ EVP_CIPH_CBC_MODE,
|
||||
/* app_data = */ NULL,
|
||||
/* init = */ des_ede_init_key,
|
||||
/* cipher = */ des_ede3_cbc_cipher,
|
||||
/* cleanup = */ NULL,
|
||||
/* ctrl = */ NULL,
|
||||
.nid = NID_des_ede_cbc,
|
||||
.block_size = 8,
|
||||
.key_len = 16,
|
||||
.iv_len = 8,
|
||||
.ctx_size = sizeof(DES_EDE_KEY),
|
||||
.flags = EVP_CIPH_CBC_MODE,
|
||||
.init = des_ede_init_key,
|
||||
.cipher = des_ede3_cbc_cipher,
|
||||
};
|
||||
|
||||
const EVP_CIPHER *EVP_des_ede_cbc(void) { return &evp_des_ede_cbc; }
|
||||
@@ -212,33 +200,27 @@ static int des_ede_ecb_cipher(EVP_CIPHER_CTX *ctx, uint8_t *out,
|
||||
}
|
||||
|
||||
static const EVP_CIPHER evp_des_ede = {
|
||||
/* nid = */ NID_des_ede_ecb,
|
||||
/* block_size = */ 8,
|
||||
/* key_len = */ 16,
|
||||
/* iv_len = */ 0,
|
||||
/* ctx_size = */ sizeof(DES_EDE_KEY),
|
||||
/* flags = */ EVP_CIPH_ECB_MODE,
|
||||
/* app_data = */ NULL,
|
||||
/* init = */ des_ede_init_key,
|
||||
/* cipher = */ des_ede_ecb_cipher,
|
||||
/* cleanup = */ NULL,
|
||||
/* ctrl = */ NULL,
|
||||
.nid = NID_des_ede_ecb,
|
||||
.block_size = 8,
|
||||
.key_len = 16,
|
||||
.iv_len = 0,
|
||||
.ctx_size = sizeof(DES_EDE_KEY),
|
||||
.flags = EVP_CIPH_ECB_MODE,
|
||||
.init = des_ede_init_key,
|
||||
.cipher = des_ede_ecb_cipher,
|
||||
};
|
||||
|
||||
const EVP_CIPHER *EVP_des_ede(void) { return &evp_des_ede; }
|
||||
|
||||
static const EVP_CIPHER evp_des_ede3 = {
|
||||
/* nid = */ NID_des_ede3_ecb,
|
||||
/* block_size = */ 8,
|
||||
/* key_len = */ 24,
|
||||
/* iv_len = */ 0,
|
||||
/* ctx_size = */ sizeof(DES_EDE_KEY),
|
||||
/* flags = */ EVP_CIPH_ECB_MODE,
|
||||
/* app_data = */ NULL,
|
||||
/* init = */ des_ede3_init_key,
|
||||
/* cipher = */ des_ede_ecb_cipher,
|
||||
/* cleanup = */ NULL,
|
||||
/* ctrl = */ NULL,
|
||||
.nid = NID_des_ede3_ecb,
|
||||
.block_size = 8,
|
||||
.key_len = 24,
|
||||
.iv_len = 0,
|
||||
.ctx_size = sizeof(DES_EDE_KEY),
|
||||
.flags = EVP_CIPH_ECB_MODE,
|
||||
.init = des_ede3_init_key,
|
||||
.cipher = des_ede_ecb_cipher,
|
||||
};
|
||||
|
||||
const EVP_CIPHER *EVP_des_ede3(void) { return &evp_des_ede3; }
|
||||
|
||||
@@ -78,9 +78,13 @@ static int null_cipher(EVP_CIPHER_CTX *ctx, uint8_t *out,
|
||||
}
|
||||
|
||||
static const EVP_CIPHER n_cipher = {
|
||||
NID_undef, 1 /* block size */, 0 /* key_len */, 0 /* iv_len */,
|
||||
0 /* ctx_size */, 0 /* flags */, NULL /* app_data */, null_init_key,
|
||||
null_cipher, NULL /* cleanup */, NULL /* ctrl */,
|
||||
.nid = NID_undef,
|
||||
.block_size = 1,
|
||||
.key_len = 0,
|
||||
.iv_len = 0,
|
||||
.ctx_size = 0,
|
||||
.init = null_init_key,
|
||||
.cipher = null_cipher,
|
||||
};
|
||||
|
||||
const EVP_CIPHER *EVP_enc_null(void) { return &n_cipher; }
|
||||
@@ -427,37 +427,29 @@ static int rc2_ctrl(EVP_CIPHER_CTX *ctx, int type, int arg, void *ptr) {
|
||||
}
|
||||
|
||||
static const EVP_CIPHER rc2_40_cbc = {
|
||||
NID_rc2_40_cbc,
|
||||
8 /* block size */,
|
||||
5 /* 40 bit */,
|
||||
8 /* iv len */,
|
||||
sizeof(EVP_RC2_KEY),
|
||||
EVP_CIPH_CBC_MODE | EVP_CIPH_VARIABLE_LENGTH | EVP_CIPH_CTRL_INIT,
|
||||
NULL /* app_data */,
|
||||
rc2_init_key,
|
||||
rc2_cbc_cipher,
|
||||
NULL,
|
||||
rc2_ctrl,
|
||||
.nid = NID_rc2_40_cbc,
|
||||
.block_size = 8,
|
||||
.key_len = 5 /* 40 bit */,
|
||||
.iv_len = 8,
|
||||
.ctx_size = sizeof(EVP_RC2_KEY),
|
||||
.flags = EVP_CIPH_CBC_MODE | EVP_CIPH_VARIABLE_LENGTH | EVP_CIPH_CTRL_INIT,
|
||||
.init = rc2_init_key,
|
||||
.cipher = rc2_cbc_cipher,
|
||||
.ctrl = rc2_ctrl,
|
||||
};
|
||||
|
||||
const EVP_CIPHER *EVP_rc2_40_cbc(void) {
|
||||
return &rc2_40_cbc;
|
||||
}
|
||||
const EVP_CIPHER *EVP_rc2_40_cbc(void) { return &rc2_40_cbc; }
|
||||
|
||||
static const EVP_CIPHER rc2_cbc = {
|
||||
NID_rc2_cbc,
|
||||
8 /* block size */,
|
||||
16 /* 128 bit */,
|
||||
8 /* iv len */,
|
||||
sizeof(EVP_RC2_KEY),
|
||||
EVP_CIPH_CBC_MODE | EVP_CIPH_VARIABLE_LENGTH | EVP_CIPH_CTRL_INIT,
|
||||
NULL /* app_data */,
|
||||
rc2_init_key,
|
||||
rc2_cbc_cipher,
|
||||
NULL,
|
||||
rc2_ctrl,
|
||||
.nid = NID_rc2_cbc,
|
||||
.block_size = 8,
|
||||
.key_len = 16 /* 128 bit */,
|
||||
.iv_len = 8,
|
||||
.ctx_size = sizeof(EVP_RC2_KEY),
|
||||
.flags = EVP_CIPH_CBC_MODE | EVP_CIPH_VARIABLE_LENGTH | EVP_CIPH_CTRL_INIT,
|
||||
.init = rc2_init_key,
|
||||
.cipher = rc2_cbc_cipher,
|
||||
.ctrl = rc2_ctrl,
|
||||
};
|
||||
|
||||
const EVP_CIPHER *EVP_rc2_cbc(void) {
|
||||
return &rc2_cbc;
|
||||
}
|
||||
const EVP_CIPHER *EVP_rc2_cbc(void) { return &rc2_cbc; }
|
||||
@@ -81,9 +81,14 @@ static int rc4_cipher(EVP_CIPHER_CTX *ctx, uint8_t *out, const uint8_t *in,
|
||||
}
|
||||
|
||||
static const EVP_CIPHER rc4 = {
|
||||
NID_rc4, 1 /* block_size */, 16 /* key_size */,
|
||||
0 /* iv_len */, sizeof(RC4_KEY), EVP_CIPH_VARIABLE_LENGTH,
|
||||
NULL /* app_data */, rc4_init_key, rc4_cipher,
|
||||
NULL /* cleanup */, NULL /* ctrl */, };
|
||||
.nid = NID_rc4,
|
||||
.block_size = 1,
|
||||
.key_len = 16,
|
||||
.iv_len = 0,
|
||||
.ctx_size = sizeof(RC4_KEY),
|
||||
.flags = EVP_CIPH_VARIABLE_LENGTH,
|
||||
.init = rc4_init_key,
|
||||
.cipher = rc4_cipher,
|
||||
};
|
||||
|
||||
const EVP_CIPHER *EVP_rc4(void) { return &rc4; }
|
||||
@@ -192,22 +192,65 @@ OPENSSL_INLINE int chacha20_poly1305_asm_capable(void) {
|
||||
// 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.
|
||||
#if defined(OPENSSL_X86_64)
|
||||
extern void chacha20_poly1305_open_nohw(
|
||||
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);
|
||||
extern void chacha20_poly1305_open_avx2(
|
||||
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);
|
||||
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) {
|
||||
if (CRYPTO_is_AVX2_capable() && CRYPTO_is_BMI2_capable()) {
|
||||
chacha20_poly1305_open_avx2(out_plaintext, ciphertext, plaintext_len, ad,
|
||||
ad_len, data);
|
||||
} else {
|
||||
chacha20_poly1305_open_nohw(out_plaintext, ciphertext, plaintext_len, ad,
|
||||
ad_len, data);
|
||||
}
|
||||
}
|
||||
#else
|
||||
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);
|
||||
#endif
|
||||
|
||||
// chacha20_poly1305_open is defined in chacha20_poly1305_*.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|.
|
||||
#if defined(OPENSSL_X86_64)
|
||||
extern void chacha20_poly1305_seal_nohw(
|
||||
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);
|
||||
extern void chacha20_poly1305_seal_avx2(
|
||||
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);
|
||||
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) {
|
||||
if (CRYPTO_is_AVX2_capable() && CRYPTO_is_BMI2_capable()) {
|
||||
chacha20_poly1305_seal_avx2(out_ciphertext, plaintext, plaintext_len, ad,
|
||||
ad_len, data);
|
||||
} else {
|
||||
chacha20_poly1305_seal_nohw(out_ciphertext, plaintext, plaintext_len, ad,
|
||||
ad_len, data);
|
||||
}
|
||||
}
|
||||
#else
|
||||
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);
|
||||
#endif
|
||||
|
||||
#else
|
||||
|
||||
OPENSSL_INLINE int chacha20_poly1305_asm_capable(void) { return 0; }
|
||||
|
||||
@@ -121,8 +121,8 @@ void EVP_tls_cbc_copy_mac(uint8_t *out, size_t md_size, const uint8_t *in,
|
||||
size_t mac_end = in_len;
|
||||
size_t mac_start = mac_end - md_size;
|
||||
|
||||
assert(orig_len >= in_len);
|
||||
assert(in_len >= md_size);
|
||||
declassify_assert(orig_len >= in_len);
|
||||
declassify_assert(in_len >= md_size);
|
||||
assert(md_size <= EVP_MAX_MD_SIZE);
|
||||
assert(md_size > 0);
|
||||
|
||||
|
||||
@@ -56,6 +56,7 @@
|
||||
|
||||
#include <CCryptoBoringSSL_conf.h>
|
||||
|
||||
#include <assert.h>
|
||||
#include <string.h>
|
||||
#include <ctype.h>
|
||||
|
||||
@@ -65,7 +66,6 @@
|
||||
#include <CCryptoBoringSSL_lhash.h>
|
||||
#include <CCryptoBoringSSL_mem.h>
|
||||
|
||||
#include "conf_def.h"
|
||||
#include "internal.h"
|
||||
#include "../internal.h"
|
||||
|
||||
@@ -183,6 +183,26 @@ err:
|
||||
return NULL;
|
||||
}
|
||||
|
||||
static int is_comment(char c) { return c == '#'; }
|
||||
|
||||
static int is_quote(char c) { return c == '"' || c == '\'' || c == '`'; }
|
||||
|
||||
static int is_esc(char c) { return c == '\\'; }
|
||||
|
||||
static int is_conf_ws(char c) {
|
||||
// This differs from |OPENSSL_isspace| in that CONF does not accept '\v' and
|
||||
// '\f' as whitespace.
|
||||
return c == ' ' || c == '\t' || c == '\r' || c == '\n';
|
||||
}
|
||||
|
||||
static int is_name_char(char c) {
|
||||
// Alphanumeric characters, and a handful of symbols, may appear in value and
|
||||
// section names without escaping.
|
||||
return OPENSSL_isalnum(c) || c == '_' || c == '!' || c == '.' || c == '%' ||
|
||||
c == '&' || c == '*' || c == '+' || c == ',' || c == '/' || c == ';' ||
|
||||
c == '?' || c == '@' || c == '^' || c == '~' || c == '|' || c == '-';
|
||||
}
|
||||
|
||||
static int str_copy(CONF *conf, char *section, char **pto, char *from) {
|
||||
int q, to = 0, len = 0;
|
||||
char v;
|
||||
@@ -199,13 +219,13 @@ static int str_copy(CONF *conf, char *section, char **pto, char *from) {
|
||||
}
|
||||
|
||||
for (;;) {
|
||||
if (IS_QUOTE(conf, *from)) {
|
||||
if (is_quote(*from)) {
|
||||
q = *from;
|
||||
from++;
|
||||
while (!IS_EOF(conf, *from) && (*from != q)) {
|
||||
if (IS_ESC(conf, *from)) {
|
||||
while (*from != '\0' && *from != q) {
|
||||
if (is_esc(*from)) {
|
||||
from++;
|
||||
if (IS_EOF(conf, *from)) {
|
||||
if (*from == '\0') {
|
||||
break;
|
||||
}
|
||||
}
|
||||
@@ -214,10 +234,10 @@ static int str_copy(CONF *conf, char *section, char **pto, char *from) {
|
||||
if (*from == q) {
|
||||
from++;
|
||||
}
|
||||
} else if (IS_ESC(conf, *from)) {
|
||||
} else if (is_esc(*from)) {
|
||||
from++;
|
||||
v = *(from++);
|
||||
if (IS_EOF(conf, v)) {
|
||||
if (v == '\0') {
|
||||
break;
|
||||
} else if (v == 'r') {
|
||||
v = '\r';
|
||||
@@ -229,11 +249,13 @@ static int str_copy(CONF *conf, char *section, char **pto, char *from) {
|
||||
v = '\t';
|
||||
}
|
||||
buf->data[to++] = v;
|
||||
} else if (IS_EOF(conf, *from)) {
|
||||
} else if (*from == '\0') {
|
||||
break;
|
||||
} else if (*from == '$') {
|
||||
// Historically, $foo would expand to a previously-parsed value. This
|
||||
// feature has been removed as it was unused and is a DoS vector.
|
||||
// feature has been removed as it was unused and is a DoS vector. If
|
||||
// trying to embed '$' in a line, either escape it or wrap the value in
|
||||
// quotes.
|
||||
OPENSSL_PUT_ERROR(CONF, CONF_R_VARIABLE_EXPANSION_NOT_SUPPORTED);
|
||||
goto err;
|
||||
} else {
|
||||
@@ -312,36 +334,39 @@ static int add_string(const CONF *conf, CONF_SECTION *section,
|
||||
return 1;
|
||||
}
|
||||
|
||||
static char *eat_ws(CONF *conf, char *p) {
|
||||
while (IS_WS(conf, *p) && !IS_EOF(conf, *p)) {
|
||||
static char *eat_ws(char *p) {
|
||||
while (*p != '\0' && is_conf_ws(*p)) {
|
||||
p++;
|
||||
}
|
||||
return p;
|
||||
}
|
||||
|
||||
#define scan_esc(conf, p) (((IS_EOF((conf), (p)[1])) ? ((p) + 1) : ((p) + 2)))
|
||||
static char *scan_esc(char *p) {
|
||||
assert(p[0] == '\\');
|
||||
return p[1] == '\0' ? p + 1 : p + 2;
|
||||
}
|
||||
|
||||
static char *eat_alpha_numeric(CONF *conf, char *p) {
|
||||
static char *eat_name(char *p) {
|
||||
for (;;) {
|
||||
if (IS_ESC(conf, *p)) {
|
||||
p = scan_esc(conf, p);
|
||||
if (is_esc(*p)) {
|
||||
p = scan_esc(p);
|
||||
continue;
|
||||
}
|
||||
if (!IS_ALPHA_NUMERIC_PUNCT(conf, *p)) {
|
||||
if (!is_name_char(*p)) {
|
||||
return p;
|
||||
}
|
||||
p++;
|
||||
}
|
||||
}
|
||||
|
||||
static char *scan_quote(CONF *conf, char *p) {
|
||||
static char *scan_quote(char *p) {
|
||||
int q = *p;
|
||||
|
||||
p++;
|
||||
while (!IS_EOF(conf, *p) && *p != q) {
|
||||
if (IS_ESC(conf, *p)) {
|
||||
while (*p != '\0' && *p != q) {
|
||||
if (is_esc(*p)) {
|
||||
p++;
|
||||
if (IS_EOF(conf, *p)) {
|
||||
if (*p == '\0') {
|
||||
return p;
|
||||
}
|
||||
}
|
||||
@@ -353,28 +378,28 @@ static char *scan_quote(CONF *conf, char *p) {
|
||||
return p;
|
||||
}
|
||||
|
||||
static void clear_comments(CONF *conf, char *p) {
|
||||
static void clear_comments(char *p) {
|
||||
for (;;) {
|
||||
if (!IS_WS(conf, *p)) {
|
||||
if (!is_conf_ws(*p)) {
|
||||
break;
|
||||
}
|
||||
p++;
|
||||
}
|
||||
|
||||
for (;;) {
|
||||
if (IS_COMMENT(conf, *p)) {
|
||||
if (is_comment(*p)) {
|
||||
*p = '\0';
|
||||
return;
|
||||
}
|
||||
if (IS_QUOTE(conf, *p)) {
|
||||
p = scan_quote(conf, p);
|
||||
if (is_quote(*p)) {
|
||||
p = scan_quote(p);
|
||||
continue;
|
||||
}
|
||||
if (IS_ESC(conf, *p)) {
|
||||
p = scan_esc(conf, p);
|
||||
if (is_esc(*p)) {
|
||||
p = scan_esc(p);
|
||||
continue;
|
||||
}
|
||||
if (IS_EOF(conf, *p)) {
|
||||
if (*p == '\0') {
|
||||
return;
|
||||
} else {
|
||||
p++;
|
||||
@@ -454,7 +479,7 @@ int NCONF_load_bio(CONF *conf, BIO *in, long *out_error_line) {
|
||||
// If we have bytes and the last char '\\' and
|
||||
// second last char is not '\\'
|
||||
p = &(buff->data[bufnum - 1]);
|
||||
if (IS_ESC(conf, p[0]) && ((bufnum <= 1) || !IS_ESC(conf, p[-1]))) {
|
||||
if (is_esc(p[0]) && ((bufnum <= 1) || !is_esc(p[-1]))) {
|
||||
bufnum--;
|
||||
again = 1;
|
||||
}
|
||||
@@ -465,20 +490,20 @@ int NCONF_load_bio(CONF *conf, BIO *in, long *out_error_line) {
|
||||
bufnum = 0;
|
||||
buf = buff->data;
|
||||
|
||||
clear_comments(conf, buf);
|
||||
s = eat_ws(conf, buf);
|
||||
if (IS_EOF(conf, *s)) {
|
||||
clear_comments(buf);
|
||||
s = eat_ws(buf);
|
||||
if (*s == '\0') {
|
||||
continue; // blank line
|
||||
}
|
||||
if (*s == '[') {
|
||||
char *ss;
|
||||
|
||||
s++;
|
||||
start = eat_ws(conf, s);
|
||||
start = eat_ws(s);
|
||||
ss = start;
|
||||
again:
|
||||
end = eat_alpha_numeric(conf, ss);
|
||||
p = eat_ws(conf, end);
|
||||
end = eat_name(ss);
|
||||
p = eat_ws(end);
|
||||
if (*p != ']') {
|
||||
if (*p != '\0' && ss != p) {
|
||||
ss = p;
|
||||
@@ -502,27 +527,27 @@ int NCONF_load_bio(CONF *conf, BIO *in, long *out_error_line) {
|
||||
} else {
|
||||
pname = s;
|
||||
psection = NULL;
|
||||
end = eat_alpha_numeric(conf, s);
|
||||
end = eat_name(s);
|
||||
if ((end[0] == ':') && (end[1] == ':')) {
|
||||
*end = '\0';
|
||||
end += 2;
|
||||
psection = pname;
|
||||
pname = end;
|
||||
end = eat_alpha_numeric(conf, end);
|
||||
end = eat_name(end);
|
||||
}
|
||||
p = eat_ws(conf, end);
|
||||
p = eat_ws(end);
|
||||
if (*p != '=') {
|
||||
OPENSSL_PUT_ERROR(CONF, CONF_R_MISSING_EQUAL_SIGN);
|
||||
goto err;
|
||||
}
|
||||
*end = '\0';
|
||||
p++;
|
||||
start = eat_ws(conf, p);
|
||||
while (!IS_EOF(conf, *p)) {
|
||||
start = eat_ws(p);
|
||||
while (*p != '\0') {
|
||||
p++;
|
||||
}
|
||||
p--;
|
||||
while ((p != start) && (IS_WS(conf, *p))) {
|
||||
while (p != start && is_conf_ws(*p)) {
|
||||
p--;
|
||||
}
|
||||
p++;
|
||||
|
||||
@@ -1,122 +0,0 @@
|
||||
/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
|
||||
* All rights reserved.
|
||||
*
|
||||
* This package is an SSL implementation written
|
||||
* by Eric Young (eay@cryptsoft.com).
|
||||
* The implementation was written so as to conform with Netscapes SSL.
|
||||
*
|
||||
* This library is free for commercial and non-commercial use as long as
|
||||
* the following conditions are aheared to. The following conditions
|
||||
* apply to all code found in this distribution, be it the RC4, RSA,
|
||||
* lhash, DES, etc., code; not just the SSL code. The SSL documentation
|
||||
* included with this distribution is covered by the same copyright terms
|
||||
* except that the holder is Tim Hudson (tjh@cryptsoft.com).
|
||||
*
|
||||
* Copyright remains Eric Young's, and as such any Copyright notices in
|
||||
* the code are not to be removed.
|
||||
* If this package is used in a product, Eric Young should be given attribution
|
||||
* as the author of the parts of the library used.
|
||||
* This can be in the form of a textual message at program startup or
|
||||
* in documentation (online or textual) provided with the package.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
* 1. Redistributions of source code must retain the copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
* 3. All advertising materials mentioning features or use of this software
|
||||
* must display the following acknowledgement:
|
||||
* "This product includes cryptographic software written by
|
||||
* Eric Young (eay@cryptsoft.com)"
|
||||
* The word 'cryptographic' can be left out if the rouines from the library
|
||||
* being used are not cryptographic related :-).
|
||||
* 4. If you include any Windows specific code (or a derivative thereof) from
|
||||
* the apps directory (application code) you must include an acknowledgement:
|
||||
* "This product includes software written by Tim Hudson (tjh@cryptsoft.com)"
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND
|
||||
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
* ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
|
||||
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
||||
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
||||
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
||||
* SUCH DAMAGE.
|
||||
*
|
||||
* The licence and distribution terms for any publically available version or
|
||||
* derivative of this code cannot be changed. i.e. this code cannot simply be
|
||||
* copied and put under another distribution licence
|
||||
* [including the GNU Public Licence.]
|
||||
*/
|
||||
|
||||
// This file was historically generated by keysets.pl in OpenSSL.
|
||||
//
|
||||
// TODO(davidben): Replace it with something more readable.
|
||||
|
||||
#define CONF_NUMBER 1
|
||||
#define CONF_UPPER 2
|
||||
#define CONF_LOWER 4
|
||||
#define CONF_UNDER 256
|
||||
#define CONF_PUNCTUATION 512
|
||||
#define CONF_WS 16
|
||||
#define CONF_ESC 32
|
||||
#define CONF_QUOTE 64
|
||||
#define CONF_COMMENT 128
|
||||
#define CONF_EOF 8
|
||||
#define CONF_HIGHBIT 4096
|
||||
#define CONF_ALPHA (CONF_UPPER|CONF_LOWER)
|
||||
#define CONF_ALPHA_NUMERIC (CONF_ALPHA|CONF_NUMBER|CONF_UNDER)
|
||||
#define CONF_ALPHA_NUMERIC_PUNCT (CONF_ALPHA|CONF_NUMBER|CONF_UNDER| \
|
||||
CONF_PUNCTUATION)
|
||||
|
||||
#define KEYTYPES(c) CONF_type_default
|
||||
#define IS_COMMENT(c,a) (KEYTYPES(c)[(a)&0xff]&CONF_COMMENT)
|
||||
#define IS_EOF(c,a) (KEYTYPES(c)[(a)&0xff]&CONF_EOF)
|
||||
#define IS_ESC(c,a) (KEYTYPES(c)[(a)&0xff]&CONF_ESC)
|
||||
#define IS_NUMBER(c,a) (KEYTYPES(c)[(a)&0xff]&CONF_NUMBER)
|
||||
#define IS_WS(c,a) (KEYTYPES(c)[(a)&0xff]&CONF_WS)
|
||||
#define IS_ALPHA_NUMERIC(c,a) (KEYTYPES(c)[(a)&0xff]&CONF_ALPHA_NUMERIC)
|
||||
#define IS_ALPHA_NUMERIC_PUNCT(c,a) \
|
||||
(KEYTYPES(c)[(a)&0xff]&CONF_ALPHA_NUMERIC_PUNCT)
|
||||
#define IS_QUOTE(c,a) (KEYTYPES(c)[(a)&0xff]&CONF_QUOTE)
|
||||
|
||||
static const unsigned short CONF_type_default[256]={
|
||||
0x0008,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,
|
||||
0x0000,0x0010,0x0010,0x0000,0x0000,0x0010,0x0000,0x0000,
|
||||
0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,
|
||||
0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,
|
||||
0x0010,0x0200,0x0040,0x0080,0x0000,0x0200,0x0200,0x0040,
|
||||
0x0000,0x0000,0x0200,0x0200,0x0200,0x0200,0x0200,0x0200,
|
||||
0x0001,0x0001,0x0001,0x0001,0x0001,0x0001,0x0001,0x0001,
|
||||
0x0001,0x0001,0x0000,0x0200,0x0000,0x0000,0x0000,0x0200,
|
||||
0x0200,0x0002,0x0002,0x0002,0x0002,0x0002,0x0002,0x0002,
|
||||
0x0002,0x0002,0x0002,0x0002,0x0002,0x0002,0x0002,0x0002,
|
||||
0x0002,0x0002,0x0002,0x0002,0x0002,0x0002,0x0002,0x0002,
|
||||
0x0002,0x0002,0x0002,0x0000,0x0020,0x0000,0x0200,0x0100,
|
||||
0x0040,0x0004,0x0004,0x0004,0x0004,0x0004,0x0004,0x0004,
|
||||
0x0004,0x0004,0x0004,0x0004,0x0004,0x0004,0x0004,0x0004,
|
||||
0x0004,0x0004,0x0004,0x0004,0x0004,0x0004,0x0004,0x0004,
|
||||
0x0004,0x0004,0x0004,0x0000,0x0200,0x0000,0x0200,0x0000,
|
||||
0x1000,0x1000,0x1000,0x1000,0x1000,0x1000,0x1000,0x1000,
|
||||
0x1000,0x1000,0x1000,0x1000,0x1000,0x1000,0x1000,0x1000,
|
||||
0x1000,0x1000,0x1000,0x1000,0x1000,0x1000,0x1000,0x1000,
|
||||
0x1000,0x1000,0x1000,0x1000,0x1000,0x1000,0x1000,0x1000,
|
||||
0x1000,0x1000,0x1000,0x1000,0x1000,0x1000,0x1000,0x1000,
|
||||
0x1000,0x1000,0x1000,0x1000,0x1000,0x1000,0x1000,0x1000,
|
||||
0x1000,0x1000,0x1000,0x1000,0x1000,0x1000,0x1000,0x1000,
|
||||
0x1000,0x1000,0x1000,0x1000,0x1000,0x1000,0x1000,0x1000,
|
||||
0x1000,0x1000,0x1000,0x1000,0x1000,0x1000,0x1000,0x1000,
|
||||
0x1000,0x1000,0x1000,0x1000,0x1000,0x1000,0x1000,0x1000,
|
||||
0x1000,0x1000,0x1000,0x1000,0x1000,0x1000,0x1000,0x1000,
|
||||
0x1000,0x1000,0x1000,0x1000,0x1000,0x1000,0x1000,0x1000,
|
||||
0x1000,0x1000,0x1000,0x1000,0x1000,0x1000,0x1000,0x1000,
|
||||
0x1000,0x1000,0x1000,0x1000,0x1000,0x1000,0x1000,0x1000,
|
||||
0x1000,0x1000,0x1000,0x1000,0x1000,0x1000,0x1000,0x1000,
|
||||
0x1000,0x1000,0x1000,0x1000,0x1000,0x1000,0x1000,0x1000,
|
||||
};
|
||||
@@ -15,7 +15,7 @@
|
||||
#include "internal.h"
|
||||
|
||||
#if defined(OPENSSL_AARCH64) && defined(OPENSSL_APPLE) && \
|
||||
!defined(OPENSSL_STATIC_ARMCAP)
|
||||
!defined(OPENSSL_STATIC_ARMCAP) && !defined(OPENSSL_NO_ASM)
|
||||
|
||||
#include <sys/sysctl.h>
|
||||
#include <sys/types.h>
|
||||
|
||||
@@ -15,7 +15,7 @@
|
||||
#include "internal.h"
|
||||
|
||||
#if defined(OPENSSL_AARCH64) && defined(OPENSSL_FUCHSIA) && \
|
||||
!defined(OPENSSL_STATIC_ARMCAP)
|
||||
!defined(OPENSSL_STATIC_ARMCAP) && !defined(OPENSSL_NO_ASM)
|
||||
|
||||
#include <zircon/features.h>
|
||||
#include <zircon/syscalls.h>
|
||||
|
||||
@@ -15,7 +15,7 @@
|
||||
#include "internal.h"
|
||||
|
||||
#if defined(OPENSSL_AARCH64) && defined(OPENSSL_LINUX) && \
|
||||
!defined(OPENSSL_STATIC_ARMCAP)
|
||||
!defined(OPENSSL_STATIC_ARMCAP) && !defined(OPENSSL_NO_ASM)
|
||||
|
||||
#include <sys/auxv.h>
|
||||
|
||||
|
||||
@@ -15,11 +15,11 @@
|
||||
#include <CCryptoBoringSSL_cpu.h>
|
||||
|
||||
#if defined(OPENSSL_AARCH64) && defined(OPENSSL_OPENBSD) && \
|
||||
!defined(OPENSSL_STATIC_ARMCAP)
|
||||
!defined(OPENSSL_STATIC_ARMCAP) && !defined(OPENSSL_NO_ASM)
|
||||
|
||||
#include <sys/sysctl.h>
|
||||
#include <machine/cpu.h>
|
||||
#include <machine/armreg.h>
|
||||
#include <machine/cpu.h>
|
||||
#include <sys/sysctl.h>
|
||||
|
||||
#include <CCryptoBoringSSL_arm_arch.h>
|
||||
|
||||
@@ -27,7 +27,7 @@
|
||||
|
||||
|
||||
void OPENSSL_cpuid_setup(void) {
|
||||
int isar0_mib[] = { CTL_MACHDEP, CPU_ID_AA64ISAR0 };
|
||||
int isar0_mib[] = {CTL_MACHDEP, CPU_ID_AA64ISAR0};
|
||||
uint64_t cpu_id = 0;
|
||||
size_t len = sizeof(cpu_id);
|
||||
|
||||
|
||||
@@ -18,7 +18,8 @@
|
||||
// expects userspace to simply read them. It traps the reads and fills in CPU
|
||||
// capabilities.
|
||||
#if defined(OPENSSL_AARCH64) && !defined(OPENSSL_STATIC_ARMCAP) && \
|
||||
(defined(ANDROID_BAREMETAL) || defined(OPENSSL_FREEBSD))
|
||||
(defined(ANDROID_BAREMETAL) || defined(OPENSSL_FREEBSD)) && \
|
||||
!defined(OPENSSL_NO_ASM)
|
||||
|
||||
#include <CCryptoBoringSSL_arm_arch.h>
|
||||
|
||||
|
||||
@@ -16,7 +16,7 @@
|
||||
#include "internal.h"
|
||||
|
||||
#if defined(OPENSSL_AARCH64) && defined(OPENSSL_WINDOWS) && \
|
||||
!defined(OPENSSL_STATIC_ARMCAP)
|
||||
!defined(OPENSSL_STATIC_ARMCAP) && !defined(OPENSSL_NO_ASM)
|
||||
|
||||
#include <windows.h>
|
||||
|
||||
|
||||
@@ -143,6 +143,9 @@ void OPENSSL_cpuid_setup(void) {
|
||||
|
||||
int CRYPTO_has_broken_NEON(void) { return 0; }
|
||||
|
||||
int CRYPTO_needs_hwcap2_workaround(void) { return g_needs_hwcap2_workaround; }
|
||||
int CRYPTO_needs_hwcap2_workaround(void) {
|
||||
OPENSSL_init_cpuid();
|
||||
return g_needs_hwcap2_workaround;
|
||||
}
|
||||
|
||||
#endif // OPENSSL_ARM && OPENSSL_LINUX && !OPENSSL_STATIC_ARMCAP
|
||||
@@ -173,20 +173,21 @@ void OPENSSL_cpuid_setup(void) {
|
||||
|
||||
OPENSSL_cpuid(&eax, &ebx, &ecx, &edx, 1);
|
||||
|
||||
const uint32_t base_family = (eax >> 8) & 15;
|
||||
const uint32_t base_model = (eax >> 4) & 15;
|
||||
|
||||
uint32_t family = base_family;
|
||||
uint32_t model = base_model;
|
||||
if (base_family == 15) {
|
||||
const uint32_t ext_family = (eax >> 20) & 255;
|
||||
family += ext_family;
|
||||
}
|
||||
if (base_family == 6 || base_family == 15) {
|
||||
const uint32_t ext_model = (eax >> 16) & 15;
|
||||
model |= ext_model << 4;
|
||||
}
|
||||
|
||||
if (is_amd) {
|
||||
// See https://www.amd.com/system/files/TechDocs/25481.pdf, page 10.
|
||||
const uint32_t base_family = (eax >> 8) & 15;
|
||||
const uint32_t base_model = (eax >> 4) & 15;
|
||||
|
||||
uint32_t family = base_family;
|
||||
uint32_t model = base_model;
|
||||
if (base_family == 0xf) {
|
||||
const uint32_t ext_family = (eax >> 20) & 255;
|
||||
family += ext_family;
|
||||
const uint32_t ext_model = (eax >> 16) & 15;
|
||||
model |= ext_model << 4;
|
||||
}
|
||||
|
||||
if (family < 0x17 || (family == 0x17 && 0x70 <= model && model <= 0x7f)) {
|
||||
// Disable RDRAND on AMD families before 0x17 (Zen) due to reported
|
||||
// failures after suspend.
|
||||
@@ -208,15 +209,6 @@ void OPENSSL_cpuid_setup(void) {
|
||||
// Reserved bit #30 is repurposed to signal an Intel CPU.
|
||||
if (is_intel) {
|
||||
edx |= (1u << 30);
|
||||
|
||||
// Clear the XSAVE bit on Knights Landing to mimic Silvermont. This enables
|
||||
// some Silvermont-specific codepaths which perform better. See OpenSSL
|
||||
// commit 64d92d74985ebb3d0be58a9718f9e080a14a8e7f and
|
||||
// |CRYPTO_cpu_perf_is_like_silvermont|.
|
||||
if ((eax & 0x0fff0ff0) == 0x00050670 /* Knights Landing */ ||
|
||||
(eax & 0x0fff0ff0) == 0x00080650 /* Knights Mill (per SDE) */) {
|
||||
ecx &= ~(1u << 26);
|
||||
}
|
||||
} else {
|
||||
edx &= ~(1u << 30);
|
||||
}
|
||||
@@ -236,25 +228,67 @@ void OPENSSL_cpuid_setup(void) {
|
||||
ecx &= ~(1u << 28); // AVX
|
||||
ecx &= ~(1u << 12); // FMA
|
||||
ecx &= ~(1u << 11); // AMD XOP
|
||||
// Clear AVX2 and AVX512* bits.
|
||||
//
|
||||
// TODO(davidben): Should bits 17 and 26-28 also be cleared? Upstream
|
||||
// doesn't clear those. See the comments in
|
||||
// |CRYPTO_hardware_supports_XSAVE|.
|
||||
extended_features[0] &=
|
||||
~((1u << 5) | (1u << 16) | (1u << 21) | (1u << 30) | (1u << 31));
|
||||
extended_features[0] &= ~(1u << 5); // AVX2
|
||||
extended_features[1] &= ~(1u << 9); // VAES
|
||||
extended_features[1] &= ~(1u << 10); // VPCLMULQDQ
|
||||
}
|
||||
// See Intel manual, volume 1, section 15.2.
|
||||
// See Intel manual, volume 1, sections 15.2 ("Detection of AVX-512 Foundation
|
||||
// Instructions") through 15.4 ("Detection of Intel AVX-512 Instruction Groups
|
||||
// Operating at 256 and 128-bit Vector Lengths").
|
||||
if ((xcr0 & 0xe6) != 0xe6) {
|
||||
// Clear AVX512F. Note we don't touch other AVX512 extensions because they
|
||||
// can be used with YMM.
|
||||
extended_features[0] &= ~(1u << 16);
|
||||
// Without XCR0.111xx11x, no AVX512 feature can be used. This includes ZMM
|
||||
// registers, masking, SIMD registers 16-31 (even if accessed as YMM or
|
||||
// XMM), and EVEX-coded instructions (even on YMM or XMM). Even if only
|
||||
// XCR0.ZMM_Hi256 is missing, it isn't valid to use AVX512 features on
|
||||
// shorter vectors, since AVX512 ties everything to the availability of
|
||||
// 512-bit vectors. See the above-mentioned sections of the Intel manual,
|
||||
// which say that *all* these XCR0 bits must be checked even when just using
|
||||
// 128-bit or 256-bit vectors, and also volume 2a section 2.7.11 ("#UD
|
||||
// Equations for EVEX") which says that all EVEX-coded instructions raise an
|
||||
// undefined-instruction exception if any of these XCR0 bits is zero.
|
||||
//
|
||||
// AVX10 fixes this by reorganizing the features that used to be part of
|
||||
// "AVX512" and allowing them to be used independently of 512-bit support.
|
||||
// TODO: add AVX10 detection.
|
||||
extended_features[0] &= ~(1u << 16); // AVX512F
|
||||
extended_features[0] &= ~(1u << 17); // AVX512DQ
|
||||
extended_features[0] &= ~(1u << 21); // AVX512IFMA
|
||||
extended_features[0] &= ~(1u << 26); // AVX512PF
|
||||
extended_features[0] &= ~(1u << 27); // AVX512ER
|
||||
extended_features[0] &= ~(1u << 28); // AVX512CD
|
||||
extended_features[0] &= ~(1u << 30); // AVX512BW
|
||||
extended_features[0] &= ~(1u << 31); // AVX512VL
|
||||
extended_features[1] &= ~(1u << 1); // AVX512VBMI
|
||||
extended_features[1] &= ~(1u << 6); // AVX512VBMI2
|
||||
extended_features[1] &= ~(1u << 11); // AVX512VNNI
|
||||
extended_features[1] &= ~(1u << 12); // AVX512BITALG
|
||||
extended_features[1] &= ~(1u << 14); // AVX512VPOPCNTDQ
|
||||
}
|
||||
|
||||
// Disable ADX instructions on Knights Landing. See OpenSSL commit
|
||||
// 64d92d74985ebb3d0be58a9718f9e080a14a8e7f.
|
||||
if ((ecx & (1u << 26)) == 0) {
|
||||
extended_features[0] &= ~(1u << 19);
|
||||
// Repurpose the bit for the removed MPX feature to indicate when using zmm
|
||||
// registers should be avoided even when they are supported. (When set, AVX512
|
||||
// features can still be used, but only using ymm or xmm registers.) Skylake
|
||||
// suffered from severe downclocking when zmm registers were used, which
|
||||
// affected unrelated code running on the system, making zmm registers not too
|
||||
// useful outside of benchmarks. The situation improved significantly by Ice
|
||||
// Lake, but a small amount of downclocking remained. (See
|
||||
// https://lore.kernel.org/linux-crypto/e8ce1146-3952-6977-1d0e-a22758e58914@intel.com/)
|
||||
// We take a conservative approach of not allowing zmm registers until after
|
||||
// Ice Lake and Tiger Lake, i.e. until Sapphire Rapids on the server side.
|
||||
//
|
||||
// AMD CPUs, which support AVX512 starting with Zen 4, have not been reported
|
||||
// to have any downclocking problem when zmm registers are used.
|
||||
if (is_intel && family == 6 &&
|
||||
(model == 85 || // Skylake, Cascade Lake, Cooper Lake (server)
|
||||
model == 106 || // Ice Lake (server)
|
||||
model == 108 || // Ice Lake (micro server)
|
||||
model == 125 || // Ice Lake (client)
|
||||
model == 126 || // Ice Lake (mobile)
|
||||
model == 140 || // Tiger Lake (mobile)
|
||||
model == 141)) { // Tiger Lake (client)
|
||||
extended_features[0] |= 1u << 14;
|
||||
} else {
|
||||
extended_features[0] &= ~(1u << 14);
|
||||
}
|
||||
|
||||
OPENSSL_ia32cap_P[0] = edx;
|
||||
|
||||
@@ -16,31 +16,14 @@
|
||||
|
||||
#include <assert.h>
|
||||
|
||||
#include "fipsmodule/rand/fork_detect.h"
|
||||
#include "fipsmodule/rand/internal.h"
|
||||
#include "bcm_support.h"
|
||||
#include "internal.h"
|
||||
|
||||
|
||||
static_assert(sizeof(ossl_ssize_t) == sizeof(size_t),
|
||||
"ossl_ssize_t should be the same size as size_t");
|
||||
|
||||
#if !defined(OPENSSL_NO_ASM) && !defined(OPENSSL_STATIC_ARMCAP) && \
|
||||
(defined(OPENSSL_X86) || defined(OPENSSL_X86_64) || \
|
||||
defined(OPENSSL_ARM) || defined(OPENSSL_AARCH64))
|
||||
// x86, x86_64, and the ARMs need to record the result of a cpuid/getauxval call
|
||||
// for the asm to work correctly, unless compiled without asm code.
|
||||
#define NEED_CPUID
|
||||
|
||||
#else
|
||||
|
||||
// Otherwise, don't emit a static initialiser.
|
||||
|
||||
#if !defined(BORINGSSL_NO_STATIC_INITIALIZER)
|
||||
#define BORINGSSL_NO_STATIC_INITIALIZER
|
||||
#endif
|
||||
|
||||
#endif // !NO_ASM && !STATIC_ARMCAP && (X86 || X86_64 || ARM || AARCH64)
|
||||
|
||||
|
||||
// Our assembly does not use the GOT to reference symbols, which means
|
||||
// references to visible symbols will often require a TEXTREL. This is
|
||||
@@ -79,7 +62,7 @@ HIDDEN uint8_t BORINGSSL_function_hit[7] = {0};
|
||||
HIDDEN uint32_t OPENSSL_ia32cap_P[4] = {0};
|
||||
|
||||
uint32_t OPENSSL_get_ia32cap(int idx) {
|
||||
CRYPTO_library_init();
|
||||
OPENSSL_init_cpuid();
|
||||
return OPENSSL_ia32cap_P[idx];
|
||||
}
|
||||
|
||||
@@ -121,60 +104,24 @@ HIDDEN uint32_t OPENSSL_armcap_P =
|
||||
HIDDEN uint32_t OPENSSL_armcap_P = 0;
|
||||
|
||||
uint32_t *OPENSSL_get_armcap_pointer_for_test(void) {
|
||||
CRYPTO_library_init();
|
||||
OPENSSL_init_cpuid();
|
||||
return &OPENSSL_armcap_P;
|
||||
}
|
||||
#endif
|
||||
|
||||
uint32_t OPENSSL_get_armcap(void) {
|
||||
CRYPTO_library_init();
|
||||
OPENSSL_init_cpuid();
|
||||
return OPENSSL_armcap_P;
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
#if defined(BORINGSSL_FIPS)
|
||||
// In FIPS mode, the power-on self-test function calls |CRYPTO_library_init|
|
||||
// because we have to ensure that CPUID detection occurs first.
|
||||
#define BORINGSSL_NO_STATIC_INITIALIZER
|
||||
#endif
|
||||
|
||||
#if defined(OPENSSL_WINDOWS) && !defined(BORINGSSL_NO_STATIC_INITIALIZER)
|
||||
#define OPENSSL_CDECL __cdecl
|
||||
#else
|
||||
#define OPENSSL_CDECL
|
||||
#endif
|
||||
|
||||
#if defined(BORINGSSL_NO_STATIC_INITIALIZER)
|
||||
static CRYPTO_once_t once = CRYPTO_ONCE_INIT;
|
||||
#elif defined(_MSC_VER)
|
||||
#pragma section(".CRT$XCU", read)
|
||||
static void __cdecl do_library_init(void);
|
||||
__declspec(allocate(".CRT$XCU")) void(*library_init_constructor)(void) =
|
||||
do_library_init;
|
||||
#else
|
||||
static void do_library_init(void) __attribute__ ((constructor));
|
||||
#endif
|
||||
|
||||
// do_library_init is the actual initialization function. If
|
||||
// BORINGSSL_NO_STATIC_INITIALIZER isn't defined, this is set as a static
|
||||
// initializer. Otherwise, it is called by CRYPTO_library_init.
|
||||
static void OPENSSL_CDECL do_library_init(void) {
|
||||
// WARNING: this function may only configure the capability variables. See the
|
||||
// note above about the linker bug.
|
||||
#if defined(NEED_CPUID)
|
||||
OPENSSL_cpuid_setup();
|
||||
static CRYPTO_once_t once = CRYPTO_ONCE_INIT;
|
||||
void OPENSSL_init_cpuid(void) { CRYPTO_once(&once, OPENSSL_cpuid_setup); }
|
||||
#endif
|
||||
}
|
||||
|
||||
void CRYPTO_library_init(void) {
|
||||
// TODO(davidben): It would be tidier if this build knob could be replaced
|
||||
// with an internal lazy-init mechanism that would handle things correctly
|
||||
// in-library. https://crbug.com/542879
|
||||
#if defined(BORINGSSL_NO_STATIC_INITIALIZER)
|
||||
CRYPTO_once(&once, do_library_init);
|
||||
#endif
|
||||
}
|
||||
void CRYPTO_library_init(void) {}
|
||||
|
||||
int CRYPTO_is_confidential_build(void) {
|
||||
#if defined(BORINGSSL_CONFIDENTIAL)
|
||||
@@ -194,7 +141,7 @@ int CRYPTO_has_asm(void) {
|
||||
|
||||
void CRYPTO_pre_sandbox_init(void) {
|
||||
// Read from /proc/cpuinfo if needed.
|
||||
CRYPTO_library_init();
|
||||
OPENSSL_init_cpuid();
|
||||
// Open /dev/urandom if needed.
|
||||
CRYPTO_init_sysrand();
|
||||
// Set up MADV_WIPEONFORK state if needed.
|
||||
@@ -235,7 +182,6 @@ int ENGINE_register_all_complete(void) { return 1; }
|
||||
void OPENSSL_load_builtin_modules(void) {}
|
||||
|
||||
int OPENSSL_init_crypto(uint64_t opts, const OPENSSL_INIT_SETTINGS *settings) {
|
||||
CRYPTO_library_init();
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
||||
@@ -81,7 +81,7 @@ typedef uint64_t fe_limb_t;
|
||||
#define assert_fe(f) \
|
||||
do { \
|
||||
for (unsigned _assert_fe_i = 0; _assert_fe_i < 5; _assert_fe_i++) { \
|
||||
assert(f[_assert_fe_i] <= UINT64_C(0x8cccccccccccc)); \
|
||||
declassify_assert(f[_assert_fe_i] <= UINT64_C(0x8cccccccccccc)); \
|
||||
} \
|
||||
} while (0)
|
||||
|
||||
@@ -98,7 +98,7 @@ typedef uint64_t fe_limb_t;
|
||||
#define assert_fe_loose(f) \
|
||||
do { \
|
||||
for (unsigned _assert_fe_i = 0; _assert_fe_i < 5; _assert_fe_i++) { \
|
||||
assert(f[_assert_fe_i] <= UINT64_C(0x1a666666666664)); \
|
||||
declassify_assert(f[_assert_fe_i] <= UINT64_C(0x1a666666666664)); \
|
||||
} \
|
||||
} while (0)
|
||||
|
||||
@@ -120,8 +120,8 @@ typedef uint32_t fe_limb_t;
|
||||
#define assert_fe(f) \
|
||||
do { \
|
||||
for (unsigned _assert_fe_i = 0; _assert_fe_i < 10; _assert_fe_i++) { \
|
||||
assert(f[_assert_fe_i] <= \
|
||||
((_assert_fe_i & 1) ? 0x2333333u : 0x4666666u)); \
|
||||
declassify_assert(f[_assert_fe_i] <= \
|
||||
((_assert_fe_i & 1) ? 0x2333333u : 0x4666666u)); \
|
||||
} \
|
||||
} while (0)
|
||||
|
||||
@@ -138,8 +138,8 @@ typedef uint32_t fe_limb_t;
|
||||
#define assert_fe_loose(f) \
|
||||
do { \
|
||||
for (unsigned _assert_fe_i = 0; _assert_fe_i < 10; _assert_fe_i++) { \
|
||||
assert(f[_assert_fe_i] <= \
|
||||
((_assert_fe_i & 1) ? 0x6999999u : 0xd333332u)); \
|
||||
declassify_assert(f[_assert_fe_i] <= \
|
||||
((_assert_fe_i & 1) ? 0x6999999u : 0xd333332u)); \
|
||||
} \
|
||||
} while (0)
|
||||
|
||||
@@ -150,7 +150,7 @@ static_assert(sizeof(fe) == sizeof(fe_limb_t) * FE_NUM_LIMBS,
|
||||
|
||||
static void fe_frombytes_strict(fe *h, const uint8_t s[32]) {
|
||||
// |fiat_25519_from_bytes| requires the top-most bit be clear.
|
||||
assert((s[31] & 0x80) == 0);
|
||||
declassify_assert((s[31] & 0x80) == 0);
|
||||
fiat_25519_from_bytes(h->v, s);
|
||||
assert_fe(h->v);
|
||||
}
|
||||
|
||||
@@ -61,6 +61,8 @@
|
||||
#include <CCryptoBoringSSL_blake2.h>
|
||||
#include <CCryptoBoringSSL_bytestring.h>
|
||||
#include <CCryptoBoringSSL_obj.h>
|
||||
#include <CCryptoBoringSSL_md4.h>
|
||||
#include <CCryptoBoringSSL_md5.h>
|
||||
#include <CCryptoBoringSSL_nid.h>
|
||||
|
||||
#include "../asn1/internal.h"
|
||||
@@ -220,6 +222,7 @@ int EVP_marshal_digest_algorithm(CBB *cbb, const EVP_MD *md) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
// TODO(crbug.com/boringssl/710): Is this correct? See RFC 4055, section 2.1.
|
||||
if (!CBB_add_asn1(&algorithm, &null, CBS_ASN1_NULL) ||
|
||||
!CBB_flush(cbb)) {
|
||||
return 0;
|
||||
@@ -263,3 +266,90 @@ static const EVP_MD evp_md_blake2b256 = {
|
||||
};
|
||||
|
||||
const EVP_MD *EVP_blake2b256(void) { return &evp_md_blake2b256; }
|
||||
|
||||
|
||||
static void md4_init(EVP_MD_CTX *ctx) {
|
||||
BSSL_CHECK(MD4_Init(ctx->md_data));
|
||||
}
|
||||
|
||||
static void md4_update(EVP_MD_CTX *ctx, const void *data, size_t count) {
|
||||
BSSL_CHECK(MD4_Update(ctx->md_data, data, count));
|
||||
}
|
||||
|
||||
static void md4_final(EVP_MD_CTX *ctx, uint8_t *out) {
|
||||
BSSL_CHECK(MD4_Final(out, ctx->md_data));
|
||||
}
|
||||
|
||||
static const EVP_MD evp_md_md4 = {
|
||||
NID_md4,
|
||||
MD4_DIGEST_LENGTH,
|
||||
0,
|
||||
md4_init,
|
||||
md4_update,
|
||||
md4_final,
|
||||
64,
|
||||
sizeof(MD4_CTX),
|
||||
};
|
||||
|
||||
const EVP_MD *EVP_md4(void) { return &evp_md_md4; }
|
||||
|
||||
static void md5_init(EVP_MD_CTX *ctx) {
|
||||
BSSL_CHECK(MD5_Init(ctx->md_data));
|
||||
}
|
||||
|
||||
static void md5_update(EVP_MD_CTX *ctx, const void *data, size_t count) {
|
||||
BSSL_CHECK(MD5_Update(ctx->md_data, data, count));
|
||||
}
|
||||
|
||||
static void md5_final(EVP_MD_CTX *ctx, uint8_t *out) {
|
||||
BSSL_CHECK(MD5_Final(out, ctx->md_data));
|
||||
}
|
||||
|
||||
static const EVP_MD evp_md_md5 = {
|
||||
NID_md5,
|
||||
MD5_DIGEST_LENGTH,
|
||||
0,
|
||||
md5_init,
|
||||
md5_update,
|
||||
md5_final,
|
||||
64,
|
||||
sizeof(MD5_CTX),
|
||||
};
|
||||
|
||||
const EVP_MD *EVP_md5(void) { return &evp_md_md5; }
|
||||
|
||||
typedef struct {
|
||||
MD5_CTX md5;
|
||||
SHA_CTX sha1;
|
||||
} MD5_SHA1_CTX;
|
||||
|
||||
static void md5_sha1_init(EVP_MD_CTX *md_ctx) {
|
||||
MD5_SHA1_CTX *ctx = md_ctx->md_data;
|
||||
BSSL_CHECK(MD5_Init(&ctx->md5) && SHA1_Init(&ctx->sha1));
|
||||
}
|
||||
|
||||
static void md5_sha1_update(EVP_MD_CTX *md_ctx, const void *data,
|
||||
size_t count) {
|
||||
MD5_SHA1_CTX *ctx = md_ctx->md_data;
|
||||
BSSL_CHECK(MD5_Update(&ctx->md5, data, count) &&
|
||||
SHA1_Update(&ctx->sha1, data, count));
|
||||
}
|
||||
|
||||
static void md5_sha1_final(EVP_MD_CTX *md_ctx, uint8_t *out) {
|
||||
MD5_SHA1_CTX *ctx = md_ctx->md_data;
|
||||
BSSL_CHECK(MD5_Final(out, &ctx->md5) &&
|
||||
SHA1_Final(out + MD5_DIGEST_LENGTH, &ctx->sha1));
|
||||
}
|
||||
|
||||
const EVP_MD evp_md_md5_sha1 = {
|
||||
NID_md5_sha1,
|
||||
MD5_DIGEST_LENGTH + SHA_DIGEST_LENGTH,
|
||||
0,
|
||||
md5_sha1_init,
|
||||
md5_sha1_update,
|
||||
md5_sha1_final,
|
||||
64,
|
||||
sizeof(MD5_SHA1_CTX),
|
||||
};
|
||||
|
||||
const EVP_MD *EVP_md5_sha1(void) { return &evp_md_md5_sha1; }
|
||||
File diff suppressed because it is too large.
Load diff
@@ -0,0 +1,58 @@
|
||||
/* Copyright (c) 2023, Google LLC
|
||||
*
|
||||
* 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_CRYPTO_DILITHIUM_INTERNAL_H
|
||||
#define OPENSSL_HEADER_CRYPTO_DILITHIUM_INTERNAL_H
|
||||
|
||||
#include <CCryptoBoringSSL_base.h>
|
||||
#include <experimental/CCryptoBoringSSL_dilithium.h>
|
||||
|
||||
#if defined(__cplusplus)
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
|
||||
// DILITHIUM_GENERATE_KEY_ENTROPY is the number of bytes of uniformly random
|
||||
// entropy necessary to generate a key pair.
|
||||
#define DILITHIUM_GENERATE_KEY_ENTROPY 32
|
||||
|
||||
// DILITHIUM_SIGNATURE_RANDOMIZER_BYTES is the number of bytes of uniformly
|
||||
// random entropy necessary to generate a signature in randomized mode.
|
||||
#define DILITHIUM_SIGNATURE_RANDOMIZER_BYTES 32
|
||||
|
||||
// DILITHIUM_generate_key_external_entropy generates a public/private key pair
|
||||
// using the given seed, writes the encoded public key to
|
||||
// |out_encoded_public_key| and sets |out_private_key| to the private key,
|
||||
// returning 1 on success and 0 on failure. Returns 1 on success and 0 on
|
||||
// failure.
|
||||
OPENSSL_EXPORT int DILITHIUM_generate_key_external_entropy(
|
||||
uint8_t out_encoded_public_key[DILITHIUM_PUBLIC_KEY_BYTES],
|
||||
struct DILITHIUM_private_key *out_private_key,
|
||||
const uint8_t entropy[DILITHIUM_GENERATE_KEY_ENTROPY]);
|
||||
|
||||
// DILITHIUM_sign_deterministic generates a signature for the message |msg| of
|
||||
// length |msg_len| using |private_key| following the deterministic algorithm,
|
||||
// and writes the encoded signature to |out_encoded_signature|. Returns 1 on
|
||||
// success and 0 on failure.
|
||||
OPENSSL_EXPORT int DILITHIUM_sign_deterministic(
|
||||
uint8_t out_encoded_signature[DILITHIUM_SIGNATURE_BYTES],
|
||||
const struct DILITHIUM_private_key *private_key, const uint8_t *msg,
|
||||
size_t msg_len);
|
||||
|
||||
|
||||
#if defined(__cplusplus)
|
||||
} // extern C
|
||||
#endif
|
||||
|
||||
#endif // OPENSSL_HEADER_CRYPTO_DILITHIUM_INTERNAL_H
|
||||
@@ -208,6 +208,11 @@ int DSA_set0_pqg(DSA *dsa, BIGNUM *p, BIGNUM *q, BIGNUM *g) {
|
||||
int DSA_generate_parameters_ex(DSA *dsa, unsigned bits, const uint8_t *seed_in,
|
||||
size_t seed_len, int *out_counter,
|
||||
unsigned long *out_h, BN_GENCB *cb) {
|
||||
if (bits > OPENSSL_DSA_MAX_MODULUS_BITS) {
|
||||
OPENSSL_PUT_ERROR(DSA, DSA_R_INVALID_PARAMETERS);
|
||||
return 0;
|
||||
}
|
||||
|
||||
int ok = 0;
|
||||
unsigned char seed[SHA256_DIGEST_LENGTH];
|
||||
unsigned char md[SHA256_DIGEST_LENGTH];
|
||||
@@ -274,6 +279,8 @@ int DSA_generate_parameters_ex(DSA *dsa, unsigned bits, const uint8_t *seed_in,
|
||||
if (!RAND_bytes(seed, qsize)) {
|
||||
goto err;
|
||||
}
|
||||
// DSA parameters are public.
|
||||
CONSTTIME_DECLASSIFY(seed, qsize);
|
||||
} else {
|
||||
// If we come back through, use random seed next time.
|
||||
seed_in = NULL;
|
||||
@@ -477,11 +484,13 @@ DSA *DSAparams_dup(const DSA *dsa) {
|
||||
}
|
||||
|
||||
int DSA_generate_key(DSA *dsa) {
|
||||
int ok = 0;
|
||||
BN_CTX *ctx = NULL;
|
||||
BIGNUM *pub_key = NULL, *priv_key = NULL;
|
||||
if (!dsa_check_key(dsa)) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
ctx = BN_CTX_new();
|
||||
int ok = 0;
|
||||
BIGNUM *pub_key = NULL, *priv_key = NULL;
|
||||
BN_CTX *ctx = BN_CTX_new();
|
||||
if (ctx == NULL) {
|
||||
goto err;
|
||||
}
|
||||
@@ -513,6 +522,9 @@ int DSA_generate_key(DSA *dsa) {
|
||||
goto err;
|
||||
}
|
||||
|
||||
// The public key is computed from the private key, but is public.
|
||||
bn_declassify(pub_key);
|
||||
|
||||
dsa->priv_key = priv_key;
|
||||
dsa->pub_key = pub_key;
|
||||
ok = 1;
|
||||
@@ -649,6 +661,10 @@ redo:
|
||||
goto err;
|
||||
}
|
||||
|
||||
// The signature is computed from the private key, but is public.
|
||||
bn_declassify(r);
|
||||
bn_declassify(s);
|
||||
|
||||
// Redo if r or s is zero as required by FIPS 186-3: this is
|
||||
// very unlikely.
|
||||
if (BN_is_zero(r) || BN_is_zero(s)) {
|
||||
@@ -681,7 +697,7 @@ err:
|
||||
return ret;
|
||||
}
|
||||
|
||||
int DSA_do_verify(const uint8_t *digest, size_t digest_len, DSA_SIG *sig,
|
||||
int DSA_do_verify(const uint8_t *digest, size_t digest_len, const DSA_SIG *sig,
|
||||
const DSA *dsa) {
|
||||
int valid;
|
||||
if (!DSA_do_check_signature(&valid, digest, digest_len, sig, dsa)) {
|
||||
@@ -691,7 +707,8 @@ int DSA_do_verify(const uint8_t *digest, size_t digest_len, DSA_SIG *sig,
|
||||
}
|
||||
|
||||
int DSA_do_check_signature(int *out_valid, const uint8_t *digest,
|
||||
size_t digest_len, DSA_SIG *sig, const DSA *dsa) {
|
||||
size_t digest_len, const DSA_SIG *sig,
|
||||
const DSA *dsa) {
|
||||
*out_valid = 0;
|
||||
if (!dsa_check_key(dsa)) {
|
||||
return 0;
|
||||
@@ -899,15 +916,19 @@ static int dsa_sign_setup(const DSA *dsa, BN_CTX *ctx, BIGNUM **out_kinv,
|
||||
ctx) ||
|
||||
// Compute r = (g^k mod p) mod q
|
||||
!BN_mod_exp_mont_consttime(r, dsa->g, &k, dsa->p, ctx,
|
||||
dsa->method_mont_p) ||
|
||||
// Note |BN_mod| below is not constant-time and may leak information about
|
||||
// |r|. |dsa->p| may be significantly larger than |dsa->q|, so this is not
|
||||
// easily performed in constant-time with Montgomery reduction.
|
||||
//
|
||||
// However, |r| at this point is g^k (mod p). It is almost the value of
|
||||
// |r| revealed in the signature anyway (g^k (mod p) (mod q)), going from
|
||||
// it to |k| would require computing a discrete log.
|
||||
!BN_mod(r, r, dsa->q, ctx) ||
|
||||
dsa->method_mont_p)) {
|
||||
OPENSSL_PUT_ERROR(DSA, ERR_R_BN_LIB);
|
||||
goto err;
|
||||
}
|
||||
// Note |BN_mod| below is not constant-time and may leak information about
|
||||
// |r|. |dsa->p| may be significantly larger than |dsa->q|, so this is not
|
||||
// easily performed in constant-time with Montgomery reduction.
|
||||
//
|
||||
// However, |r| at this point is g^k (mod p). It is almost the value of |r|
|
||||
// revealed in the signature anyway (g^k (mod p) (mod q)), going from it to
|
||||
// |k| would require computing a discrete log.
|
||||
bn_declassify(r);
|
||||
if (!BN_mod(r, r, dsa->q, ctx) ||
|
||||
// Compute part of 's = inv(k) (m + xr) mod q' using Fermat's Little
|
||||
// Theorem.
|
||||
!bn_mod_inverse_prime(kinv, &k, dsa->q, ctx, dsa->method_mont_q)) {
|
||||
|
||||
@@ -65,8 +65,6 @@
|
||||
#include "../bytestring/internal.h"
|
||||
|
||||
|
||||
#define OPENSSL_DSA_MAX_MODULUS_BITS 10000
|
||||
|
||||
// This function is in dsa_asn1.c rather than dsa.c because it is reachable from
|
||||
// |EVP_PKEY| parsers. This makes it easier for the static linker to drop most
|
||||
// of the DSA implementation.
|
||||
@@ -119,8 +117,9 @@ int dsa_check_key(const DSA *dsa) {
|
||||
if (dsa->priv_key != NULL) {
|
||||
// The private key is a non-zero element of the scalar field, determined by
|
||||
// |q|.
|
||||
if (BN_is_negative(dsa->priv_key) || BN_is_zero(dsa->priv_key) ||
|
||||
BN_cmp(dsa->priv_key, dsa->q) >= 0) {
|
||||
if (BN_is_negative(dsa->priv_key) ||
|
||||
constant_time_declassify_int(BN_is_zero(dsa->priv_key)) ||
|
||||
constant_time_declassify_int(BN_cmp(dsa->priv_key, dsa->q) >= 0)) {
|
||||
OPENSSL_PUT_ERROR(DSA, DSA_R_INVALID_PARAMETERS);
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -42,6 +42,8 @@ struct dsa_st {
|
||||
CRYPTO_EX_DATA ex_data;
|
||||
};
|
||||
|
||||
#define OPENSSL_DSA_MAX_MODULUS_BITS 10000
|
||||
|
||||
// dsa_check_key performs cheap self-checks on |dsa|, and ensures it is within
|
||||
// DoS bounds. It returns one on success and zero on error.
|
||||
int dsa_check_key(const DSA *dsa);
|
||||
|
||||
@@ -62,34 +62,87 @@
|
||||
#include <CCryptoBoringSSL_mem.h>
|
||||
|
||||
#include "../bytestring/internal.h"
|
||||
#include "../fipsmodule/ec/internal.h"
|
||||
#include "../fipsmodule/ecdsa/internal.h"
|
||||
#include "../internal.h"
|
||||
|
||||
|
||||
static ECDSA_SIG *ecdsa_sig_from_fixed(const EC_KEY *key, const uint8_t *in,
|
||||
size_t len) {
|
||||
const EC_GROUP *group = EC_KEY_get0_group(key);
|
||||
if (group == NULL) {
|
||||
OPENSSL_PUT_ERROR(ECDSA, ERR_R_PASSED_NULL_PARAMETER);
|
||||
return NULL;
|
||||
}
|
||||
size_t scalar_len = BN_num_bytes(EC_GROUP_get0_order(group));
|
||||
if (len != 2 * scalar_len) {
|
||||
OPENSSL_PUT_ERROR(ECDSA, ECDSA_R_BAD_SIGNATURE);
|
||||
return NULL;
|
||||
}
|
||||
ECDSA_SIG *ret = ECDSA_SIG_new();
|
||||
if (ret == NULL ||
|
||||
!BN_bin2bn(in, scalar_len, ret->r) ||
|
||||
!BN_bin2bn(in + scalar_len, scalar_len, ret->s)) {
|
||||
ECDSA_SIG_free(ret);
|
||||
return NULL;
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
static int ecdsa_sig_to_fixed(const EC_KEY *key, uint8_t *out, size_t *out_len,
|
||||
size_t max_out, const ECDSA_SIG *sig) {
|
||||
const EC_GROUP *group = EC_KEY_get0_group(key);
|
||||
if (group == NULL) {
|
||||
OPENSSL_PUT_ERROR(ECDSA, ERR_R_PASSED_NULL_PARAMETER);
|
||||
return 0;
|
||||
}
|
||||
size_t scalar_len = BN_num_bytes(EC_GROUP_get0_order(group));
|
||||
if (max_out < 2 * scalar_len) {
|
||||
OPENSSL_PUT_ERROR(EC, EC_R_BUFFER_TOO_SMALL);
|
||||
return 0;
|
||||
}
|
||||
if (BN_is_negative(sig->r) ||
|
||||
!BN_bn2bin_padded(out, scalar_len, sig->r) ||
|
||||
BN_is_negative(sig->s) ||
|
||||
!BN_bn2bin_padded(out + scalar_len, scalar_len, sig->s)) {
|
||||
OPENSSL_PUT_ERROR(ECDSA, ECDSA_R_BAD_SIGNATURE);
|
||||
return 0;
|
||||
}
|
||||
*out_len = 2 * scalar_len;
|
||||
return 1;
|
||||
}
|
||||
|
||||
int ECDSA_sign(int type, const uint8_t *digest, size_t digest_len, uint8_t *sig,
|
||||
unsigned int *sig_len, const EC_KEY *eckey) {
|
||||
unsigned int *out_sig_len, const EC_KEY *eckey) {
|
||||
if (eckey->ecdsa_meth && eckey->ecdsa_meth->sign) {
|
||||
return eckey->ecdsa_meth->sign(digest, digest_len, sig, sig_len,
|
||||
return eckey->ecdsa_meth->sign(digest, digest_len, sig, out_sig_len,
|
||||
(EC_KEY*) eckey /* cast away const */);
|
||||
}
|
||||
|
||||
int ret = 0;
|
||||
ECDSA_SIG *s = ECDSA_do_sign(digest, digest_len, eckey);
|
||||
if (s == NULL) {
|
||||
*sig_len = 0;
|
||||
goto err;
|
||||
*out_sig_len = 0;
|
||||
uint8_t fixed[ECDSA_MAX_FIXED_LEN];
|
||||
size_t fixed_len;
|
||||
if (!ecdsa_sign_fixed(digest, digest_len, fixed, &fixed_len, sizeof(fixed),
|
||||
eckey)) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
// TODO(davidben): We can actually do better and go straight from the DER
|
||||
// format to the fixed-width format without a malloc.
|
||||
ECDSA_SIG *s = ecdsa_sig_from_fixed(eckey, fixed, fixed_len);
|
||||
if (s == NULL) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
int ret = 0;
|
||||
CBB cbb;
|
||||
CBB_init_fixed(&cbb, sig, ECDSA_size(eckey));
|
||||
size_t len;
|
||||
if (!ECDSA_SIG_marshal(&cbb, s) ||
|
||||
!CBB_finish(&cbb, NULL, &len)) {
|
||||
OPENSSL_PUT_ERROR(ECDSA, ECDSA_R_ENCODE_ERROR);
|
||||
*sig_len = 0;
|
||||
goto err;
|
||||
}
|
||||
*sig_len = (unsigned)len;
|
||||
*out_sig_len = (unsigned)len;
|
||||
ret = 1;
|
||||
|
||||
err:
|
||||
@@ -99,12 +152,13 @@ err:
|
||||
|
||||
int ECDSA_verify(int type, const uint8_t *digest, size_t digest_len,
|
||||
const uint8_t *sig, size_t sig_len, const EC_KEY *eckey) {
|
||||
ECDSA_SIG *s;
|
||||
// Decode the ECDSA signature.
|
||||
//
|
||||
// TODO(davidben): We can actually do better and go straight from the DER
|
||||
// format to the fixed-width format without a malloc.
|
||||
int ret = 0;
|
||||
uint8_t *der = NULL;
|
||||
|
||||
// Decode the ECDSA signature.
|
||||
s = ECDSA_SIG_from_bytes(sig, sig_len);
|
||||
ECDSA_SIG *s = ECDSA_SIG_from_bytes(sig, sig_len);
|
||||
if (s == NULL) {
|
||||
goto err;
|
||||
}
|
||||
@@ -118,7 +172,10 @@ int ECDSA_verify(int type, const uint8_t *digest, size_t digest_len,
|
||||
goto err;
|
||||
}
|
||||
|
||||
ret = ECDSA_do_verify(digest, digest_len, s, eckey);
|
||||
uint8_t fixed[ECDSA_MAX_FIXED_LEN];
|
||||
size_t fixed_len;
|
||||
ret = ecdsa_sig_to_fixed(eckey, fixed, &fixed_len, sizeof(fixed), s) &&
|
||||
ecdsa_verify_fixed(digest, digest_len, fixed, fixed_len, eckey);
|
||||
|
||||
err:
|
||||
OPENSSL_free(der);
|
||||
@@ -147,6 +204,95 @@ size_t ECDSA_size(const EC_KEY *key) {
|
||||
return ECDSA_SIG_max_len(group_order_size);
|
||||
}
|
||||
|
||||
ECDSA_SIG *ECDSA_SIG_new(void) {
|
||||
ECDSA_SIG *sig = OPENSSL_malloc(sizeof(ECDSA_SIG));
|
||||
if (sig == NULL) {
|
||||
return NULL;
|
||||
}
|
||||
sig->r = BN_new();
|
||||
sig->s = BN_new();
|
||||
if (sig->r == NULL || sig->s == NULL) {
|
||||
ECDSA_SIG_free(sig);
|
||||
return NULL;
|
||||
}
|
||||
return sig;
|
||||
}
|
||||
|
||||
void ECDSA_SIG_free(ECDSA_SIG *sig) {
|
||||
if (sig == NULL) {
|
||||
return;
|
||||
}
|
||||
|
||||
BN_free(sig->r);
|
||||
BN_free(sig->s);
|
||||
OPENSSL_free(sig);
|
||||
}
|
||||
|
||||
const BIGNUM *ECDSA_SIG_get0_r(const ECDSA_SIG *sig) {
|
||||
return sig->r;
|
||||
}
|
||||
|
||||
const BIGNUM *ECDSA_SIG_get0_s(const ECDSA_SIG *sig) {
|
||||
return sig->s;
|
||||
}
|
||||
|
||||
void ECDSA_SIG_get0(const ECDSA_SIG *sig, const BIGNUM **out_r,
|
||||
const BIGNUM **out_s) {
|
||||
if (out_r != NULL) {
|
||||
*out_r = sig->r;
|
||||
}
|
||||
if (out_s != NULL) {
|
||||
*out_s = sig->s;
|
||||
}
|
||||
}
|
||||
|
||||
int ECDSA_SIG_set0(ECDSA_SIG *sig, BIGNUM *r, BIGNUM *s) {
|
||||
if (r == NULL || s == NULL) {
|
||||
return 0;
|
||||
}
|
||||
BN_free(sig->r);
|
||||
BN_free(sig->s);
|
||||
sig->r = r;
|
||||
sig->s = s;
|
||||
return 1;
|
||||
}
|
||||
|
||||
int ECDSA_do_verify(const uint8_t *digest, size_t digest_len,
|
||||
const ECDSA_SIG *sig, const EC_KEY *eckey) {
|
||||
uint8_t fixed[ECDSA_MAX_FIXED_LEN];
|
||||
size_t fixed_len;
|
||||
return ecdsa_sig_to_fixed(eckey, fixed, &fixed_len, sizeof(fixed), sig) &&
|
||||
ecdsa_verify_fixed(digest, digest_len, fixed, fixed_len, eckey);
|
||||
}
|
||||
|
||||
// This function is only exported for testing and is not called in production
|
||||
// code.
|
||||
ECDSA_SIG *ECDSA_sign_with_nonce_and_leak_private_key_for_testing(
|
||||
const uint8_t *digest, size_t digest_len, const EC_KEY *eckey,
|
||||
const uint8_t *nonce, size_t nonce_len) {
|
||||
uint8_t sig[ECDSA_MAX_FIXED_LEN];
|
||||
size_t sig_len;
|
||||
if (!ecdsa_sign_fixed_with_nonce_for_known_answer_test(
|
||||
digest, digest_len, sig, &sig_len, sizeof(sig), eckey, nonce,
|
||||
nonce_len)) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
return ecdsa_sig_from_fixed(eckey, sig, sig_len);
|
||||
}
|
||||
|
||||
ECDSA_SIG *ECDSA_do_sign(const uint8_t *digest, size_t digest_len,
|
||||
const EC_KEY *eckey) {
|
||||
uint8_t sig[ECDSA_MAX_FIXED_LEN];
|
||||
size_t sig_len;
|
||||
if (!ecdsa_sign_fixed(digest, digest_len, sig, &sig_len, sizeof(sig),
|
||||
eckey)) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
return ecdsa_sig_from_fixed(eckey, sig, sig_len);
|
||||
}
|
||||
|
||||
ECDSA_SIG *ECDSA_SIG_parse(CBS *cbs) {
|
||||
ECDSA_SIG *ret = ECDSA_SIG_new();
|
||||
if (ret == NULL) {
|
||||
|
||||
@@ -164,6 +164,17 @@ extern const uint32_t kOpenSSLReasonValues[];
|
||||
extern const size_t kOpenSSLReasonValuesLen;
|
||||
extern const char kOpenSSLReasonStringData[];
|
||||
|
||||
static char *strdup_libc_malloc(const char *str) {
|
||||
// |strdup| is not in C until C23, so MSVC triggers deprecation warnings, and
|
||||
// glibc and musl gate it on a feature macro. Reimplementing it is easier.
|
||||
size_t len = strlen(str);
|
||||
char *ret = malloc(len + 1);
|
||||
if (ret != NULL) {
|
||||
memcpy(ret, str, len + 1);
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
// err_clear clears the given queued error.
|
||||
static void err_clear(struct err_error_st *error) {
|
||||
free(error->data);
|
||||
@@ -174,13 +185,9 @@ static void err_copy(struct err_error_st *dst, const struct err_error_st *src) {
|
||||
err_clear(dst);
|
||||
dst->file = src->file;
|
||||
if (src->data != NULL) {
|
||||
// Disable deprecated functions on msvc so it doesn't complain about strdup.
|
||||
OPENSSL_MSVC_PRAGMA(warning(push))
|
||||
OPENSSL_MSVC_PRAGMA(warning(disable : 4996))
|
||||
// We can't use OPENSSL_strdup because we don't want to call OPENSSL_malloc,
|
||||
// which can affect the error stack.
|
||||
dst->data = strdup(src->data);
|
||||
OPENSSL_MSVC_PRAGMA(warning(pop))
|
||||
dst->data = strdup_libc_malloc(src->data);
|
||||
}
|
||||
dst->packed = src->packed;
|
||||
dst->line = src->line;
|
||||
@@ -767,13 +774,9 @@ void ERR_set_error_data(char *data, int flags) {
|
||||
assert(0);
|
||||
return;
|
||||
}
|
||||
// Disable deprecated functions on msvc so it doesn't complain about strdup.
|
||||
OPENSSL_MSVC_PRAGMA(warning(push))
|
||||
OPENSSL_MSVC_PRAGMA(warning(disable : 4996))
|
||||
// We can not use OPENSSL_strdup because we don't want to call OPENSSL_malloc,
|
||||
// which can affect the error stack.
|
||||
char *copy = strdup(data);
|
||||
OPENSSL_MSVC_PRAGMA(warning(pop))
|
||||
char *copy = strdup_libc_malloc(data);
|
||||
if (copy != NULL) {
|
||||
err_set_error_data(copy);
|
||||
}
|
||||
|
||||
@@ -59,12 +59,9 @@
|
||||
#include <assert.h>
|
||||
#include <string.h>
|
||||
|
||||
#include <CCryptoBoringSSL_dsa.h>
|
||||
#include <CCryptoBoringSSL_ec.h>
|
||||
#include <CCryptoBoringSSL_err.h>
|
||||
#include <CCryptoBoringSSL_mem.h>
|
||||
#include <CCryptoBoringSSL_nid.h>
|
||||
#include <CCryptoBoringSSL_rsa.h>
|
||||
#include <CCryptoBoringSSL_thread.h>
|
||||
|
||||
#include "internal.h"
|
||||
@@ -149,9 +146,7 @@ int EVP_PKEY_cmp(const EVP_PKEY *a, const EVP_PKEY *b) {
|
||||
|
||||
int EVP_PKEY_copy_parameters(EVP_PKEY *to, const EVP_PKEY *from) {
|
||||
if (to->type == EVP_PKEY_NONE) {
|
||||
if (!EVP_PKEY_set_type(to, from->type)) {
|
||||
return 0;
|
||||
}
|
||||
evp_pkey_set_method(to, from->ameth);
|
||||
} else if (to->type != from->type) {
|
||||
OPENSSL_PUT_ERROR(EVP, EVP_R_DIFFERENT_KEY_TYPES);
|
||||
return 0;
|
||||
@@ -225,117 +220,21 @@ static const EVP_PKEY_ASN1_METHOD *evp_pkey_asn1_find(int nid) {
|
||||
}
|
||||
}
|
||||
|
||||
static void evp_pkey_set_method(EVP_PKEY *pkey,
|
||||
const EVP_PKEY_ASN1_METHOD *method) {
|
||||
void evp_pkey_set_method(EVP_PKEY *pkey, const EVP_PKEY_ASN1_METHOD *method) {
|
||||
free_it(pkey);
|
||||
pkey->ameth = method;
|
||||
pkey->type = pkey->ameth->pkey_id;
|
||||
}
|
||||
|
||||
int EVP_PKEY_type(int nid) {
|
||||
const EVP_PKEY_ASN1_METHOD *meth = evp_pkey_asn1_find(nid);
|
||||
if (meth == NULL) {
|
||||
return NID_undef;
|
||||
}
|
||||
return meth->pkey_id;
|
||||
// In OpenSSL, this was used to map between type aliases. BoringSSL supports
|
||||
// no type aliases, so this function is just the identity.
|
||||
return nid;
|
||||
}
|
||||
|
||||
int EVP_PKEY_set1_RSA(EVP_PKEY *pkey, RSA *key) {
|
||||
if (EVP_PKEY_assign_RSA(pkey, key)) {
|
||||
RSA_up_ref(key);
|
||||
return 1;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
int EVP_PKEY_assign_RSA(EVP_PKEY *pkey, RSA *key) {
|
||||
evp_pkey_set_method(pkey, &rsa_asn1_meth);
|
||||
pkey->pkey = key;
|
||||
return key != NULL;
|
||||
}
|
||||
|
||||
RSA *EVP_PKEY_get0_RSA(const EVP_PKEY *pkey) {
|
||||
if (pkey->type != EVP_PKEY_RSA) {
|
||||
OPENSSL_PUT_ERROR(EVP, EVP_R_EXPECTING_AN_RSA_KEY);
|
||||
return NULL;
|
||||
}
|
||||
return pkey->pkey;
|
||||
}
|
||||
|
||||
RSA *EVP_PKEY_get1_RSA(const EVP_PKEY *pkey) {
|
||||
RSA *rsa = EVP_PKEY_get0_RSA(pkey);
|
||||
if (rsa != NULL) {
|
||||
RSA_up_ref(rsa);
|
||||
}
|
||||
return rsa;
|
||||
}
|
||||
|
||||
int EVP_PKEY_set1_DSA(EVP_PKEY *pkey, DSA *key) {
|
||||
if (EVP_PKEY_assign_DSA(pkey, key)) {
|
||||
DSA_up_ref(key);
|
||||
return 1;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
int EVP_PKEY_assign_DSA(EVP_PKEY *pkey, DSA *key) {
|
||||
evp_pkey_set_method(pkey, &dsa_asn1_meth);
|
||||
pkey->pkey = key;
|
||||
return key != NULL;
|
||||
}
|
||||
|
||||
DSA *EVP_PKEY_get0_DSA(const EVP_PKEY *pkey) {
|
||||
if (pkey->type != EVP_PKEY_DSA) {
|
||||
OPENSSL_PUT_ERROR(EVP, EVP_R_EXPECTING_A_DSA_KEY);
|
||||
return NULL;
|
||||
}
|
||||
return pkey->pkey;
|
||||
}
|
||||
|
||||
DSA *EVP_PKEY_get1_DSA(const EVP_PKEY *pkey) {
|
||||
DSA *dsa = EVP_PKEY_get0_DSA(pkey);
|
||||
if (dsa != NULL) {
|
||||
DSA_up_ref(dsa);
|
||||
}
|
||||
return dsa;
|
||||
}
|
||||
|
||||
int EVP_PKEY_set1_EC_KEY(EVP_PKEY *pkey, EC_KEY *key) {
|
||||
if (EVP_PKEY_assign_EC_KEY(pkey, key)) {
|
||||
EC_KEY_up_ref(key);
|
||||
return 1;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
int EVP_PKEY_assign_EC_KEY(EVP_PKEY *pkey, EC_KEY *key) {
|
||||
evp_pkey_set_method(pkey, &ec_asn1_meth);
|
||||
pkey->pkey = key;
|
||||
return key != NULL;
|
||||
}
|
||||
|
||||
EC_KEY *EVP_PKEY_get0_EC_KEY(const EVP_PKEY *pkey) {
|
||||
if (pkey->type != EVP_PKEY_EC) {
|
||||
OPENSSL_PUT_ERROR(EVP, EVP_R_EXPECTING_AN_EC_KEY_KEY);
|
||||
return NULL;
|
||||
}
|
||||
return pkey->pkey;
|
||||
}
|
||||
|
||||
EC_KEY *EVP_PKEY_get1_EC_KEY(const EVP_PKEY *pkey) {
|
||||
EC_KEY *ec_key = EVP_PKEY_get0_EC_KEY(pkey);
|
||||
if (ec_key != NULL) {
|
||||
EC_KEY_up_ref(ec_key);
|
||||
}
|
||||
return ec_key;
|
||||
}
|
||||
|
||||
DH *EVP_PKEY_get0_DH(const EVP_PKEY *pkey) { return NULL; }
|
||||
DH *EVP_PKEY_get1_DH(const EVP_PKEY *pkey) { return NULL; }
|
||||
|
||||
int EVP_PKEY_assign(EVP_PKEY *pkey, int type, void *key) {
|
||||
// This function can only be used to assign RSA, DSA, and EC keys. Other key
|
||||
// types have internal representations which are not exposed through the
|
||||
// This function can only be used to assign RSA, DSA, EC, and DH keys. Other
|
||||
// key types have internal representations which are not exposed through the
|
||||
// public API.
|
||||
switch (type) {
|
||||
case EVP_PKEY_RSA:
|
||||
@@ -344,6 +243,8 @@ int EVP_PKEY_assign(EVP_PKEY *pkey, int type, void *key) {
|
||||
return EVP_PKEY_assign_DSA(pkey, key);
|
||||
case EVP_PKEY_EC:
|
||||
return EVP_PKEY_assign_EC_KEY(pkey, key);
|
||||
case EVP_PKEY_DH:
|
||||
return EVP_PKEY_assign_DH(pkey, key);
|
||||
}
|
||||
|
||||
OPENSSL_PUT_ERROR(EVP, EVP_R_UNSUPPORTED_ALGORITHM);
|
||||
@@ -375,16 +276,26 @@ int EVP_PKEY_set_type(EVP_PKEY *pkey, int type) {
|
||||
|
||||
EVP_PKEY *EVP_PKEY_new_raw_private_key(int type, ENGINE *unused,
|
||||
const uint8_t *in, size_t len) {
|
||||
EVP_PKEY *ret = EVP_PKEY_new();
|
||||
if (ret == NULL ||
|
||||
!EVP_PKEY_set_type(ret, type)) {
|
||||
goto err;
|
||||
// To avoid pulling in all key types, look for specifically the key types that
|
||||
// support |set_priv_raw|.
|
||||
const EVP_PKEY_ASN1_METHOD *method;
|
||||
switch (type) {
|
||||
case EVP_PKEY_X25519:
|
||||
method = &x25519_asn1_meth;
|
||||
break;
|
||||
case EVP_PKEY_ED25519:
|
||||
method = &ed25519_asn1_meth;
|
||||
break;
|
||||
default:
|
||||
OPENSSL_PUT_ERROR(EVP, EVP_R_UNSUPPORTED_ALGORITHM);
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (ret->ameth->set_priv_raw == NULL) {
|
||||
OPENSSL_PUT_ERROR(EVP, EVP_R_OPERATION_NOT_SUPPORTED_FOR_THIS_KEYTYPE);
|
||||
EVP_PKEY *ret = EVP_PKEY_new();
|
||||
if (ret == NULL) {
|
||||
goto err;
|
||||
}
|
||||
evp_pkey_set_method(ret, method);
|
||||
|
||||
if (!ret->ameth->set_priv_raw(ret, in, len)) {
|
||||
goto err;
|
||||
@@ -399,16 +310,26 @@ err:
|
||||
|
||||
EVP_PKEY *EVP_PKEY_new_raw_public_key(int type, ENGINE *unused,
|
||||
const uint8_t *in, size_t len) {
|
||||
EVP_PKEY *ret = EVP_PKEY_new();
|
||||
if (ret == NULL ||
|
||||
!EVP_PKEY_set_type(ret, type)) {
|
||||
goto err;
|
||||
// To avoid pulling in all key types, look for specifically the key types that
|
||||
// support |set_pub_raw|.
|
||||
const EVP_PKEY_ASN1_METHOD *method;
|
||||
switch (type) {
|
||||
case EVP_PKEY_X25519:
|
||||
method = &x25519_asn1_meth;
|
||||
break;
|
||||
case EVP_PKEY_ED25519:
|
||||
method = &ed25519_asn1_meth;
|
||||
break;
|
||||
default:
|
||||
OPENSSL_PUT_ERROR(EVP, EVP_R_UNSUPPORTED_ALGORITHM);
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (ret->ameth->set_pub_raw == NULL) {
|
||||
OPENSSL_PUT_ERROR(EVP, EVP_R_OPERATION_NOT_SUPPORTED_FOR_THIS_KEYTYPE);
|
||||
EVP_PKEY *ret = EVP_PKEY_new();
|
||||
if (ret == NULL) {
|
||||
goto err;
|
||||
}
|
||||
evp_pkey_set_method(ret, method);
|
||||
|
||||
if (!ret->ameth->set_pub_raw(ret, in, len)) {
|
||||
goto err;
|
||||
|
||||
@@ -69,6 +69,7 @@
|
||||
#include "../internal.h"
|
||||
|
||||
|
||||
// We intentionally omit |dh_asn1_meth| from this list. It is not serializable.
|
||||
static const EVP_PKEY_ASN1_METHOD *const kASN1Methods[] = {
|
||||
&rsa_asn1_meth,
|
||||
&ec_asn1_meth,
|
||||
@@ -77,28 +78,26 @@ static const EVP_PKEY_ASN1_METHOD *const kASN1Methods[] = {
|
||||
&x25519_asn1_meth,
|
||||
};
|
||||
|
||||
static int parse_key_type(CBS *cbs, int *out_type) {
|
||||
static const EVP_PKEY_ASN1_METHOD *parse_key_type(CBS *cbs) {
|
||||
CBS oid;
|
||||
if (!CBS_get_asn1(cbs, &oid, CBS_ASN1_OBJECT)) {
|
||||
return 0;
|
||||
return NULL;
|
||||
}
|
||||
|
||||
for (unsigned i = 0; i < OPENSSL_ARRAY_SIZE(kASN1Methods); i++) {
|
||||
const EVP_PKEY_ASN1_METHOD *method = kASN1Methods[i];
|
||||
if (CBS_len(&oid) == method->oid_len &&
|
||||
OPENSSL_memcmp(CBS_data(&oid), method->oid, method->oid_len) == 0) {
|
||||
*out_type = method->pkey_id;
|
||||
return 1;
|
||||
return method;
|
||||
}
|
||||
}
|
||||
|
||||
return 0;
|
||||
return NULL;
|
||||
}
|
||||
|
||||
EVP_PKEY *EVP_parse_public_key(CBS *cbs) {
|
||||
// Parse the SubjectPublicKeyInfo.
|
||||
CBS spki, algorithm, key;
|
||||
int type;
|
||||
uint8_t padding;
|
||||
if (!CBS_get_asn1(cbs, &spki, CBS_ASN1_SEQUENCE) ||
|
||||
!CBS_get_asn1(&spki, &algorithm, CBS_ASN1_SEQUENCE) ||
|
||||
@@ -107,7 +106,8 @@ EVP_PKEY *EVP_parse_public_key(CBS *cbs) {
|
||||
OPENSSL_PUT_ERROR(EVP, EVP_R_DECODE_ERROR);
|
||||
return NULL;
|
||||
}
|
||||
if (!parse_key_type(&algorithm, &type)) {
|
||||
const EVP_PKEY_ASN1_METHOD *method = parse_key_type(&algorithm);
|
||||
if (method == NULL) {
|
||||
OPENSSL_PUT_ERROR(EVP, EVP_R_UNSUPPORTED_ALGORITHM);
|
||||
return NULL;
|
||||
}
|
||||
@@ -121,10 +121,10 @@ EVP_PKEY *EVP_parse_public_key(CBS *cbs) {
|
||||
|
||||
// Set up an |EVP_PKEY| of the appropriate type.
|
||||
EVP_PKEY *ret = EVP_PKEY_new();
|
||||
if (ret == NULL ||
|
||||
!EVP_PKEY_set_type(ret, type)) {
|
||||
if (ret == NULL) {
|
||||
goto err;
|
||||
}
|
||||
evp_pkey_set_method(ret, method);
|
||||
|
||||
// Call into the type-specific SPKI decoding function.
|
||||
if (ret->ameth->pub_decode == NULL) {
|
||||
@@ -155,7 +155,6 @@ EVP_PKEY *EVP_parse_private_key(CBS *cbs) {
|
||||
// Parse the PrivateKeyInfo.
|
||||
CBS pkcs8, algorithm, key;
|
||||
uint64_t version;
|
||||
int type;
|
||||
if (!CBS_get_asn1(cbs, &pkcs8, CBS_ASN1_SEQUENCE) ||
|
||||
!CBS_get_asn1_uint64(&pkcs8, &version) ||
|
||||
version != 0 ||
|
||||
@@ -164,7 +163,8 @@ EVP_PKEY *EVP_parse_private_key(CBS *cbs) {
|
||||
OPENSSL_PUT_ERROR(EVP, EVP_R_DECODE_ERROR);
|
||||
return NULL;
|
||||
}
|
||||
if (!parse_key_type(&algorithm, &type)) {
|
||||
const EVP_PKEY_ASN1_METHOD *method = parse_key_type(&algorithm);
|
||||
if (method == NULL) {
|
||||
OPENSSL_PUT_ERROR(EVP, EVP_R_UNSUPPORTED_ALGORITHM);
|
||||
return NULL;
|
||||
}
|
||||
@@ -173,10 +173,10 @@ EVP_PKEY *EVP_parse_private_key(CBS *cbs) {
|
||||
|
||||
// Set up an |EVP_PKEY| of the appropriate type.
|
||||
EVP_PKEY *ret = EVP_PKEY_new();
|
||||
if (ret == NULL ||
|
||||
!EVP_PKEY_set_type(ret, type)) {
|
||||
if (ret == NULL) {
|
||||
goto err;
|
||||
}
|
||||
evp_pkey_set_method(ret, method);
|
||||
|
||||
// Call into the type-specific PrivateKeyInfo decoding function.
|
||||
if (ret->ameth->priv_decode == NULL) {
|
||||
|
||||
@@ -213,6 +213,7 @@ OPENSSL_EXPORT int EVP_PKEY_CTX_ctrl(EVP_PKEY_CTX *ctx, int keytype, int optype,
|
||||
#define EVP_PKEY_CTRL_HKDF_KEY (EVP_PKEY_ALG_CTRL + 16)
|
||||
#define EVP_PKEY_CTRL_HKDF_SALT (EVP_PKEY_ALG_CTRL + 17)
|
||||
#define EVP_PKEY_CTRL_HKDF_INFO (EVP_PKEY_ALG_CTRL + 18)
|
||||
#define EVP_PKEY_CTRL_DH_PAD (EVP_PKEY_ALG_CTRL + 19)
|
||||
|
||||
struct evp_pkey_ctx_st {
|
||||
// Method associated with this operation
|
||||
@@ -288,12 +289,18 @@ extern const EVP_PKEY_ASN1_METHOD ec_asn1_meth;
|
||||
extern const EVP_PKEY_ASN1_METHOD rsa_asn1_meth;
|
||||
extern const EVP_PKEY_ASN1_METHOD ed25519_asn1_meth;
|
||||
extern const EVP_PKEY_ASN1_METHOD x25519_asn1_meth;
|
||||
extern const EVP_PKEY_ASN1_METHOD dh_asn1_meth;
|
||||
|
||||
extern const EVP_PKEY_METHOD rsa_pkey_meth;
|
||||
extern const EVP_PKEY_METHOD ec_pkey_meth;
|
||||
extern const EVP_PKEY_METHOD ed25519_pkey_meth;
|
||||
extern const EVP_PKEY_METHOD x25519_pkey_meth;
|
||||
extern const EVP_PKEY_METHOD hkdf_pkey_meth;
|
||||
extern const EVP_PKEY_METHOD dh_pkey_meth;
|
||||
|
||||
// evp_pkey_set_method behaves like |EVP_PKEY_set_type|, but takes a pointer to
|
||||
// a method table. This avoids depending on every |EVP_PKEY_ASN1_METHOD|.
|
||||
void evp_pkey_set_method(EVP_PKEY *pkey, const EVP_PKEY_ASN1_METHOD *method);
|
||||
|
||||
|
||||
#if defined(__cplusplus)
|
||||
|
||||
@@ -0,0 +1,137 @@
|
||||
/*
|
||||
* Copyright 2006-2019 The OpenSSL Project Authors. All Rights Reserved.
|
||||
*
|
||||
* Licensed under the OpenSSL license (the "License"). You may not use
|
||||
* this file except in compliance with the License. You can obtain a copy
|
||||
* in the file LICENSE in the source distribution or at
|
||||
* https://www.openssl.org/source/license.html
|
||||
*/
|
||||
|
||||
#include <CCryptoBoringSSL_evp.h>
|
||||
|
||||
#include <assert.h>
|
||||
|
||||
#include <CCryptoBoringSSL_dh.h>
|
||||
#include <CCryptoBoringSSL_err.h>
|
||||
#include <CCryptoBoringSSL_mem.h>
|
||||
|
||||
#include "internal.h"
|
||||
|
||||
|
||||
typedef struct dh_pkey_ctx_st {
|
||||
int pad;
|
||||
} DH_PKEY_CTX;
|
||||
|
||||
static int pkey_dh_init(EVP_PKEY_CTX *ctx) {
|
||||
DH_PKEY_CTX *dctx = OPENSSL_zalloc(sizeof(DH_PKEY_CTX));
|
||||
if (dctx == NULL) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
ctx->data = dctx;
|
||||
return 1;
|
||||
}
|
||||
|
||||
static int pkey_dh_copy(EVP_PKEY_CTX *dst, EVP_PKEY_CTX *src) {
|
||||
if (!pkey_dh_init(dst)) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
const DH_PKEY_CTX *sctx = src->data;
|
||||
DH_PKEY_CTX *dctx = dst->data;
|
||||
dctx->pad = sctx->pad;
|
||||
return 1;
|
||||
}
|
||||
|
||||
static void pkey_dh_cleanup(EVP_PKEY_CTX *ctx) {
|
||||
OPENSSL_free(ctx->data);
|
||||
ctx->data = NULL;
|
||||
}
|
||||
|
||||
static int pkey_dh_keygen(EVP_PKEY_CTX *ctx, EVP_PKEY *pkey) {
|
||||
DH *dh = DH_new();
|
||||
if (dh == NULL || !EVP_PKEY_assign_DH(pkey, dh)) {
|
||||
DH_free(dh);
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (ctx->pkey != NULL && !EVP_PKEY_copy_parameters(pkey, ctx->pkey)) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
return DH_generate_key(dh);
|
||||
}
|
||||
|
||||
static int pkey_dh_derive(EVP_PKEY_CTX *ctx, uint8_t *out, size_t *out_len) {
|
||||
DH_PKEY_CTX *dctx = ctx->data;
|
||||
if (ctx->pkey == NULL || ctx->peerkey == NULL) {
|
||||
OPENSSL_PUT_ERROR(EVP, EVP_R_KEYS_NOT_SET);
|
||||
return 0;
|
||||
}
|
||||
|
||||
DH *our_key = ctx->pkey->pkey;
|
||||
DH *peer_key = ctx->peerkey->pkey;
|
||||
if (our_key == NULL || peer_key == NULL) {
|
||||
OPENSSL_PUT_ERROR(EVP, EVP_R_KEYS_NOT_SET);
|
||||
return 0;
|
||||
}
|
||||
|
||||
const BIGNUM *pub_key = DH_get0_pub_key(peer_key);
|
||||
if (pub_key == NULL) {
|
||||
OPENSSL_PUT_ERROR(EVP, EVP_R_KEYS_NOT_SET);
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (out == NULL) {
|
||||
*out_len = DH_size(our_key);
|
||||
return 1;
|
||||
}
|
||||
|
||||
if (*out_len < (size_t)DH_size(our_key)) {
|
||||
OPENSSL_PUT_ERROR(EVP, EVP_R_BUFFER_TOO_SMALL);
|
||||
return 0;
|
||||
}
|
||||
|
||||
int ret = dctx->pad ? DH_compute_key_padded(out, pub_key, our_key)
|
||||
: DH_compute_key(out, pub_key, our_key);
|
||||
if (ret < 0) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
assert(ret <= DH_size(our_key));
|
||||
*out_len = (size_t)ret;
|
||||
return 1;
|
||||
}
|
||||
|
||||
static int pkey_dh_ctrl(EVP_PKEY_CTX *ctx, int type, int p1, void *p2) {
|
||||
DH_PKEY_CTX *dctx = ctx->data;
|
||||
switch (type) {
|
||||
case EVP_PKEY_CTRL_PEER_KEY:
|
||||
// |EVP_PKEY_derive_set_peer| requires the key implement this command,
|
||||
// even if it is a no-op.
|
||||
return 1;
|
||||
|
||||
case EVP_PKEY_CTRL_DH_PAD:
|
||||
dctx->pad = p1;
|
||||
return 1;
|
||||
|
||||
default:
|
||||
OPENSSL_PUT_ERROR(EVP, EVP_R_COMMAND_NOT_SUPPORTED);
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
const EVP_PKEY_METHOD dh_pkey_meth = {
|
||||
.pkey_id = EVP_PKEY_DH,
|
||||
.init = pkey_dh_init,
|
||||
.copy = pkey_dh_copy,
|
||||
.cleanup = pkey_dh_cleanup,
|
||||
.keygen = pkey_dh_keygen,
|
||||
.derive = pkey_dh_derive,
|
||||
.ctrl = pkey_dh_ctrl,
|
||||
};
|
||||
|
||||
int EVP_PKEY_CTX_set_dh_pad(EVP_PKEY_CTX *ctx, int pad) {
|
||||
return EVP_PKEY_CTX_ctrl(ctx, EVP_PKEY_DH, EVP_PKEY_OP_DERIVE,
|
||||
EVP_PKEY_CTRL_DH_PAD, pad, NULL);
|
||||
}
|
||||
@@ -0,0 +1,120 @@
|
||||
/*
|
||||
* Copyright 2006-2021 The OpenSSL Project Authors. All Rights Reserved.
|
||||
*
|
||||
* Licensed under the OpenSSL license (the "License"). You may not use
|
||||
* this file except in compliance with the License. You can obtain a copy
|
||||
* in the file LICENSE in the source distribution or at
|
||||
* https://www.openssl.org/source/license.html
|
||||
*/
|
||||
|
||||
#include <CCryptoBoringSSL_evp.h>
|
||||
|
||||
#include <CCryptoBoringSSL_bn.h>
|
||||
#include <CCryptoBoringSSL_dh.h>
|
||||
#include <CCryptoBoringSSL_err.h>
|
||||
|
||||
#include "internal.h"
|
||||
#include "../internal.h"
|
||||
|
||||
|
||||
static void dh_free(EVP_PKEY *pkey) {
|
||||
DH_free(pkey->pkey);
|
||||
pkey->pkey = NULL;
|
||||
}
|
||||
|
||||
static int dh_size(const EVP_PKEY *pkey) { return DH_size(pkey->pkey); }
|
||||
|
||||
static int dh_bits(const EVP_PKEY *pkey) { return DH_bits(pkey->pkey); }
|
||||
|
||||
static int dh_param_missing(const EVP_PKEY *pkey) {
|
||||
const DH *dh = pkey->pkey;
|
||||
return dh == NULL || DH_get0_p(dh) == NULL || DH_get0_g(dh) == NULL;
|
||||
}
|
||||
|
||||
static int dh_param_copy(EVP_PKEY *to, const EVP_PKEY *from) {
|
||||
if (dh_param_missing(from)) {
|
||||
OPENSSL_PUT_ERROR(EVP, EVP_R_MISSING_PARAMETERS);
|
||||
return 0;
|
||||
}
|
||||
|
||||
const DH *dh = from->pkey;
|
||||
const BIGNUM *q_old = DH_get0_q(dh);
|
||||
BIGNUM *p = BN_dup(DH_get0_p(dh));
|
||||
BIGNUM *q = q_old == NULL ? NULL : BN_dup(q_old);
|
||||
BIGNUM *g = BN_dup(DH_get0_g(dh));
|
||||
if (p == NULL || (q_old != NULL && q == NULL) || g == NULL ||
|
||||
!DH_set0_pqg(to->pkey, p, q, g)) {
|
||||
BN_free(p);
|
||||
BN_free(q);
|
||||
BN_free(g);
|
||||
return 0;
|
||||
}
|
||||
|
||||
// |DH_set0_pqg| took ownership of |p|, |q|, and |g|.
|
||||
return 1;
|
||||
}
|
||||
|
||||
static int dh_param_cmp(const EVP_PKEY *a, const EVP_PKEY *b) {
|
||||
if (dh_param_missing(a) || dh_param_missing(b)) {
|
||||
return -2;
|
||||
}
|
||||
|
||||
// Matching OpenSSL, only compare p and g for PKCS#3-style Diffie-Hellman.
|
||||
// OpenSSL only checks q in X9.42-style Diffie-Hellman ("DHX").
|
||||
const DH *a_dh = a->pkey;
|
||||
const DH *b_dh = b->pkey;
|
||||
return BN_cmp(DH_get0_p(a_dh), DH_get0_p(b_dh)) == 0 &&
|
||||
BN_cmp(DH_get0_g(a_dh), DH_get0_g(b_dh)) == 0;
|
||||
}
|
||||
|
||||
static int dh_pub_cmp(const EVP_PKEY *a, const EVP_PKEY *b) {
|
||||
if (dh_param_cmp(a, b) <= 0) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
const DH *a_dh = a->pkey;
|
||||
const DH *b_dh = b->pkey;
|
||||
return BN_cmp(DH_get0_pub_key(a_dh), DH_get0_pub_key(b_dh)) == 0;
|
||||
}
|
||||
|
||||
const EVP_PKEY_ASN1_METHOD dh_asn1_meth = {
|
||||
.pkey_id = EVP_PKEY_DH,
|
||||
.pkey_method = &dh_pkey_meth,
|
||||
.pub_cmp = dh_pub_cmp,
|
||||
.pkey_size = dh_size,
|
||||
.pkey_bits = dh_bits,
|
||||
.param_missing = dh_param_missing,
|
||||
.param_copy = dh_param_copy,
|
||||
.param_cmp = dh_param_cmp,
|
||||
.pkey_free = dh_free,
|
||||
};
|
||||
|
||||
int EVP_PKEY_set1_DH(EVP_PKEY *pkey, DH *key) {
|
||||
if (EVP_PKEY_assign_DH(pkey, key)) {
|
||||
DH_up_ref(key);
|
||||
return 1;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
int EVP_PKEY_assign_DH(EVP_PKEY *pkey, DH *key) {
|
||||
evp_pkey_set_method(pkey, &dh_asn1_meth);
|
||||
pkey->pkey = key;
|
||||
return key != NULL;
|
||||
}
|
||||
|
||||
DH *EVP_PKEY_get0_DH(const EVP_PKEY *pkey) {
|
||||
if (pkey->type != EVP_PKEY_DH) {
|
||||
OPENSSL_PUT_ERROR(EVP, EVP_R_EXPECTING_A_DH_KEY);
|
||||
return NULL;
|
||||
}
|
||||
return pkey->pkey;
|
||||
}
|
||||
|
||||
DH *EVP_PKEY_get1_DH(const EVP_PKEY *pkey) {
|
||||
DH *dh = EVP_PKEY_get0_DH(pkey);
|
||||
if (dh != NULL) {
|
||||
DH_up_ref(dh);
|
||||
}
|
||||
return dh;
|
||||
}
|
||||
@@ -306,3 +306,33 @@ int EVP_PKEY_CTX_set_dsa_paramgen_q_bits(EVP_PKEY_CTX *ctx, int qbits) {
|
||||
OPENSSL_PUT_ERROR(EVP, ERR_R_SHOULD_NOT_HAVE_BEEN_CALLED);
|
||||
return 0;
|
||||
}
|
||||
|
||||
int EVP_PKEY_set1_DSA(EVP_PKEY *pkey, DSA *key) {
|
||||
if (EVP_PKEY_assign_DSA(pkey, key)) {
|
||||
DSA_up_ref(key);
|
||||
return 1;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
int EVP_PKEY_assign_DSA(EVP_PKEY *pkey, DSA *key) {
|
||||
evp_pkey_set_method(pkey, &dsa_asn1_meth);
|
||||
pkey->pkey = key;
|
||||
return key != NULL;
|
||||
}
|
||||
|
||||
DSA *EVP_PKEY_get0_DSA(const EVP_PKEY *pkey) {
|
||||
if (pkey->type != EVP_PKEY_DSA) {
|
||||
OPENSSL_PUT_ERROR(EVP, EVP_R_EXPECTING_A_DSA_KEY);
|
||||
return NULL;
|
||||
}
|
||||
return pkey->pkey;
|
||||
}
|
||||
|
||||
DSA *EVP_PKEY_get1_DSA(const EVP_PKEY *pkey) {
|
||||
DSA *dsa = EVP_PKEY_get0_DSA(pkey);
|
||||
if (dsa != NULL) {
|
||||
DSA_up_ref(dsa);
|
||||
}
|
||||
return dsa;
|
||||
}
|
||||
@@ -90,15 +90,14 @@ static int pkey_ec_init(EVP_PKEY_CTX *ctx) {
|
||||
}
|
||||
|
||||
static int pkey_ec_copy(EVP_PKEY_CTX *dst, EVP_PKEY_CTX *src) {
|
||||
EC_PKEY_CTX *dctx, *sctx;
|
||||
if (!pkey_ec_init(dst)) {
|
||||
return 0;
|
||||
}
|
||||
sctx = src->data;
|
||||
dctx = dst->data;
|
||||
|
||||
const EC_PKEY_CTX *sctx = src->data;
|
||||
EC_PKEY_CTX *dctx = dst->data;
|
||||
dctx->md = sctx->md;
|
||||
|
||||
dctx->gen_group = sctx->gen_group;
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
||||
@@ -300,3 +300,33 @@ const EVP_PKEY_ASN1_METHOD ec_asn1_meth = {
|
||||
|
||||
int_ec_free,
|
||||
};
|
||||
|
||||
int EVP_PKEY_set1_EC_KEY(EVP_PKEY *pkey, EC_KEY *key) {
|
||||
if (EVP_PKEY_assign_EC_KEY(pkey, key)) {
|
||||
EC_KEY_up_ref(key);
|
||||
return 1;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
int EVP_PKEY_assign_EC_KEY(EVP_PKEY *pkey, EC_KEY *key) {
|
||||
evp_pkey_set_method(pkey, &ec_asn1_meth);
|
||||
pkey->pkey = key;
|
||||
return key != NULL;
|
||||
}
|
||||
|
||||
EC_KEY *EVP_PKEY_get0_EC_KEY(const EVP_PKEY *pkey) {
|
||||
if (pkey->type != EVP_PKEY_EC) {
|
||||
OPENSSL_PUT_ERROR(EVP, EVP_R_EXPECTING_AN_EC_KEY_KEY);
|
||||
return NULL;
|
||||
}
|
||||
return pkey->pkey;
|
||||
}
|
||||
|
||||
EC_KEY *EVP_PKEY_get1_EC_KEY(const EVP_PKEY *pkey) {
|
||||
EC_KEY *ec_key = EVP_PKEY_get0_EC_KEY(pkey);
|
||||
if (ec_key != NULL) {
|
||||
EC_KEY_up_ref(ec_key);
|
||||
}
|
||||
return ec_key;
|
||||
}
|
||||
@@ -30,10 +30,7 @@ static int pkey_ed25519_keygen(EVP_PKEY_CTX *ctx, EVP_PKEY *pkey) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (!EVP_PKEY_set_type(pkey, EVP_PKEY_ED25519)) {
|
||||
OPENSSL_free(key);
|
||||
return 0;
|
||||
}
|
||||
evp_pkey_set_method(pkey, &ed25519_asn1_meth);
|
||||
|
||||
uint8_t pubkey_unused[32];
|
||||
ED25519_keypair(pubkey_unused, key->key);
|
||||
|
||||
@@ -209,3 +209,33 @@ const EVP_PKEY_ASN1_METHOD rsa_asn1_meth = {
|
||||
|
||||
int_rsa_free,
|
||||
};
|
||||
|
||||
int EVP_PKEY_set1_RSA(EVP_PKEY *pkey, RSA *key) {
|
||||
if (EVP_PKEY_assign_RSA(pkey, key)) {
|
||||
RSA_up_ref(key);
|
||||
return 1;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
int EVP_PKEY_assign_RSA(EVP_PKEY *pkey, RSA *key) {
|
||||
evp_pkey_set_method(pkey, &rsa_asn1_meth);
|
||||
pkey->pkey = key;
|
||||
return key != NULL;
|
||||
}
|
||||
|
||||
RSA *EVP_PKEY_get0_RSA(const EVP_PKEY *pkey) {
|
||||
if (pkey->type != EVP_PKEY_RSA) {
|
||||
OPENSSL_PUT_ERROR(EVP, EVP_R_EXPECTING_AN_RSA_KEY);
|
||||
return NULL;
|
||||
}
|
||||
return pkey->pkey;
|
||||
}
|
||||
|
||||
RSA *EVP_PKEY_get1_RSA(const EVP_PKEY *pkey) {
|
||||
RSA *rsa = EVP_PKEY_get0_RSA(pkey);
|
||||
if (rsa != NULL) {
|
||||
RSA_up_ref(rsa);
|
||||
}
|
||||
return rsa;
|
||||
}
|
||||
@@ -30,10 +30,7 @@ static int pkey_x25519_keygen(EVP_PKEY_CTX *ctx, EVP_PKEY *pkey) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (!EVP_PKEY_set_type(pkey, EVP_PKEY_X25519)) {
|
||||
OPENSSL_free(key);
|
||||
return 0;
|
||||
}
|
||||
evp_pkey_set_method(pkey, &x25519_asn1_meth);
|
||||
|
||||
X25519_keypair(key->pub, key->priv);
|
||||
key->has_private = 1;
|
||||
|
||||
+21
@@ -104,3 +104,24 @@ int AES_set_decrypt_key(const uint8_t *key, unsigned bits, AES_KEY *aeskey) {
|
||||
return aes_nohw_set_decrypt_key(key, bits, aeskey);
|
||||
}
|
||||
}
|
||||
|
||||
#if defined(HWAES) && (defined(OPENSSL_X86) || defined(OPENSSL_X86_64))
|
||||
// On x86 and x86_64, |aes_hw_set_decrypt_key|, we implement
|
||||
// |aes_hw_encrypt_key_to_decrypt_key| in assembly and rely on C code to combine
|
||||
// the operations.
|
||||
int aes_hw_set_decrypt_key(const uint8_t *user_key, int bits, AES_KEY *key) {
|
||||
int ret = aes_hw_set_encrypt_key(user_key, bits, key);
|
||||
if (ret == 0) {
|
||||
aes_hw_encrypt_key_to_decrypt_key(key);
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
int aes_hw_set_encrypt_key(const uint8_t *user_key, int bits, AES_KEY *key) {
|
||||
if (aes_hw_set_encrypt_key_alt_preferred()) {
|
||||
return aes_hw_set_encrypt_key_alt(user_key, bits, key);
|
||||
} else {
|
||||
return aes_hw_set_encrypt_key_base(user_key, bits, key);
|
||||
}
|
||||
}
|
||||
#endif
|
||||
File renamed without changes.
@@ -17,6 +17,8 @@
|
||||
|
||||
#include <stdlib.h>
|
||||
|
||||
#include <CCryptoBoringSSL_aes.h>
|
||||
|
||||
#include "../../internal.h"
|
||||
|
||||
#if defined(__cplusplus)
|
||||
@@ -66,17 +68,41 @@ OPENSSL_INLINE int vpaes_capable(void) { return CRYPTO_is_NEON_capable(); }
|
||||
|
||||
#if defined(HWAES)
|
||||
|
||||
int aes_hw_set_encrypt_key(const uint8_t *user_key, const int bits,
|
||||
AES_KEY *key);
|
||||
int aes_hw_set_decrypt_key(const uint8_t *user_key, const int bits,
|
||||
AES_KEY *key);
|
||||
int aes_hw_set_encrypt_key(const uint8_t *user_key, int bits, AES_KEY *key);
|
||||
int aes_hw_set_decrypt_key(const uint8_t *user_key, int bits, AES_KEY *key);
|
||||
void aes_hw_encrypt(const uint8_t *in, uint8_t *out, const AES_KEY *key);
|
||||
void aes_hw_decrypt(const uint8_t *in, uint8_t *out, const AES_KEY *key);
|
||||
void aes_hw_cbc_encrypt(const uint8_t *in, uint8_t *out, size_t length,
|
||||
const AES_KEY *key, uint8_t *ivec, const int enc);
|
||||
const AES_KEY *key, uint8_t *ivec, int enc);
|
||||
void aes_hw_ctr32_encrypt_blocks(const uint8_t *in, uint8_t *out, size_t len,
|
||||
const AES_KEY *key, const uint8_t ivec[16]);
|
||||
|
||||
#if defined(OPENSSL_X86) || defined(OPENSSL_X86_64)
|
||||
// On x86 and x86_64, |aes_hw_set_decrypt_key| is implemented in terms of
|
||||
// |aes_hw_set_encrypt_key| and a conversion function.
|
||||
void aes_hw_encrypt_key_to_decrypt_key(AES_KEY *key);
|
||||
|
||||
// There are two variants of this function, one which uses aeskeygenassist
|
||||
// ("base") and one which uses aesenclast + pshufb ("alt"). aesenclast is
|
||||
// overall faster but is slower on some older processors. It doesn't use AVX,
|
||||
// but AVX is used as a proxy to detecting this. See
|
||||
// https://groups.google.com/g/mailing.openssl.dev/c/OuFXwW4NfO8/m/7d2ZXVjkxVkJ
|
||||
//
|
||||
// TODO(davidben): It is unclear if the aeskeygenassist version is still
|
||||
// worthwhile. However, the aesenclast version requires SSSE3. SSSE3 long
|
||||
// predates AES-NI, but it's not clear if AES-NI implies SSSE3. In OpenSSL, the
|
||||
// CCM AES-NI assembly seems to assume it does.
|
||||
OPENSSL_INLINE int aes_hw_set_encrypt_key_alt_capable(void) {
|
||||
return hwaes_capable() && CRYPTO_is_SSSE3_capable();
|
||||
}
|
||||
OPENSSL_INLINE int aes_hw_set_encrypt_key_alt_preferred(void) {
|
||||
return hwaes_capable() && CRYPTO_is_AVX_capable();
|
||||
}
|
||||
int aes_hw_set_encrypt_key_base(const uint8_t *user_key, int bits,
|
||||
AES_KEY *key);
|
||||
int aes_hw_set_encrypt_key_alt(const uint8_t *user_key, int bits, AES_KEY *key);
|
||||
#endif // OPENSSL_X86 || OPENSSL_X86_64
|
||||
|
||||
#else
|
||||
|
||||
// If HWAES isn't defined then we provide dummy functions for each of the hwaes
|
||||
@@ -120,7 +146,7 @@ OPENSSL_INLINE void aes_hw_ctr32_encrypt_blocks(const uint8_t *in, uint8_t *out,
|
||||
|
||||
#if defined(HWAES_ECB)
|
||||
void aes_hw_ecb_encrypt(const uint8_t *in, uint8_t *out, size_t length,
|
||||
const AES_KEY *key, const int enc);
|
||||
const AES_KEY *key, int enc);
|
||||
#endif // HWAES_ECB
|
||||
|
||||
|
||||
@@ -218,7 +244,7 @@ void aes_nohw_ctr32_encrypt_blocks(const uint8_t *in, uint8_t *out,
|
||||
size_t blocks, const AES_KEY *key,
|
||||
const uint8_t ivec[16]);
|
||||
void aes_nohw_cbc_encrypt(const uint8_t *in, uint8_t *out, size_t len,
|
||||
const AES_KEY *key, uint8_t *ivec, const int enc);
|
||||
const AES_KEY *key, uint8_t *ivec, int enc);
|
||||
|
||||
|
||||
#if defined(__cplusplus)
|
||||
|
||||
File renamed without changes.
File renamed without changes.
File diff suppressed because it is too large.
Load diff
@@ -1,808 +0,0 @@
|
||||
#define BORINGSSL_PREFIX CCryptoBoringSSL
|
||||
#if defined(__arm__) && defined(__APPLE__)
|
||||
// This file is generated from a similarly-named Perl script in the BoringSSL
|
||||
// source tree. Do not edit by hand.
|
||||
|
||||
#include <CCryptoBoringSSL_asm_base.h>
|
||||
|
||||
#if !defined(OPENSSL_NO_ASM) && defined(OPENSSL_ARM) && defined(__APPLE__)
|
||||
#include <CCryptoBoringSSL_arm_arch.h>
|
||||
|
||||
#if __ARM_MAX_ARCH__>=7
|
||||
.text
|
||||
|
||||
|
||||
.code 32
|
||||
#undef __thumb2__
|
||||
.align 5
|
||||
Lrcon:
|
||||
.long 0x01,0x01,0x01,0x01
|
||||
.long 0x0c0f0e0d,0x0c0f0e0d,0x0c0f0e0d,0x0c0f0e0d @ rotate-n-splat
|
||||
.long 0x1b,0x1b,0x1b,0x1b
|
||||
|
||||
.text
|
||||
|
||||
.globl _aes_hw_set_encrypt_key
|
||||
.private_extern _aes_hw_set_encrypt_key
|
||||
#ifdef __thumb2__
|
||||
.thumb_func _aes_hw_set_encrypt_key
|
||||
#endif
|
||||
.align 5
|
||||
_aes_hw_set_encrypt_key:
|
||||
Lenc_key:
|
||||
mov r3,#-1
|
||||
cmp r0,#0
|
||||
beq Lenc_key_abort
|
||||
cmp r2,#0
|
||||
beq Lenc_key_abort
|
||||
mov r3,#-2
|
||||
cmp r1,#128
|
||||
blt Lenc_key_abort
|
||||
cmp r1,#256
|
||||
bgt Lenc_key_abort
|
||||
tst r1,#0x3f
|
||||
bne Lenc_key_abort
|
||||
|
||||
adr r3,Lrcon
|
||||
cmp r1,#192
|
||||
|
||||
veor q0,q0,q0
|
||||
vld1.8 {q3},[r0]!
|
||||
mov r1,#8 @ reuse r1
|
||||
vld1.32 {q1,q2},[r3]!
|
||||
|
||||
blt Loop128
|
||||
beq L192
|
||||
b L256
|
||||
|
||||
.align 4
|
||||
Loop128:
|
||||
vtbl.8 d20,{q3},d4
|
||||
vtbl.8 d21,{q3},d5
|
||||
vext.8 q9,q0,q3,#12
|
||||
vst1.32 {q3},[r2]!
|
||||
.byte 0x00,0x43,0xf0,0xf3 @ aese q10,q0
|
||||
subs r1,r1,#1
|
||||
|
||||
veor q3,q3,q9
|
||||
vext.8 q9,q0,q9,#12
|
||||
veor q3,q3,q9
|
||||
vext.8 q9,q0,q9,#12
|
||||
veor q10,q10,q1
|
||||
veor q3,q3,q9
|
||||
vshl.u8 q1,q1,#1
|
||||
veor q3,q3,q10
|
||||
bne Loop128
|
||||
|
||||
vld1.32 {q1},[r3]
|
||||
|
||||
vtbl.8 d20,{q3},d4
|
||||
vtbl.8 d21,{q3},d5
|
||||
vext.8 q9,q0,q3,#12
|
||||
vst1.32 {q3},[r2]!
|
||||
.byte 0x00,0x43,0xf0,0xf3 @ aese q10,q0
|
||||
|
||||
veor q3,q3,q9
|
||||
vext.8 q9,q0,q9,#12
|
||||
veor q3,q3,q9
|
||||
vext.8 q9,q0,q9,#12
|
||||
veor q10,q10,q1
|
||||
veor q3,q3,q9
|
||||
vshl.u8 q1,q1,#1
|
||||
veor q3,q3,q10
|
||||
|
||||
vtbl.8 d20,{q3},d4
|
||||
vtbl.8 d21,{q3},d5
|
||||
vext.8 q9,q0,q3,#12
|
||||
vst1.32 {q3},[r2]!
|
||||
.byte 0x00,0x43,0xf0,0xf3 @ aese q10,q0
|
||||
|
||||
veor q3,q3,q9
|
||||
vext.8 q9,q0,q9,#12
|
||||
veor q3,q3,q9
|
||||
vext.8 q9,q0,q9,#12
|
||||
veor q10,q10,q1
|
||||
veor q3,q3,q9
|
||||
veor q3,q3,q10
|
||||
vst1.32 {q3},[r2]
|
||||
add r2,r2,#0x50
|
||||
|
||||
mov r12,#10
|
||||
b Ldone
|
||||
|
||||
.align 4
|
||||
L192:
|
||||
vld1.8 {d16},[r0]!
|
||||
vmov.i8 q10,#8 @ borrow q10
|
||||
vst1.32 {q3},[r2]!
|
||||
vsub.i8 q2,q2,q10 @ adjust the mask
|
||||
|
||||
Loop192:
|
||||
vtbl.8 d20,{q8},d4
|
||||
vtbl.8 d21,{q8},d5
|
||||
vext.8 q9,q0,q3,#12
|
||||
vst1.32 {d16},[r2]!
|
||||
.byte 0x00,0x43,0xf0,0xf3 @ aese q10,q0
|
||||
subs r1,r1,#1
|
||||
|
||||
veor q3,q3,q9
|
||||
vext.8 q9,q0,q9,#12
|
||||
veor q3,q3,q9
|
||||
vext.8 q9,q0,q9,#12
|
||||
veor q3,q3,q9
|
||||
|
||||
vdup.32 q9,d7[1]
|
||||
veor q9,q9,q8
|
||||
veor q10,q10,q1
|
||||
vext.8 q8,q0,q8,#12
|
||||
vshl.u8 q1,q1,#1
|
||||
veor q8,q8,q9
|
||||
veor q3,q3,q10
|
||||
veor q8,q8,q10
|
||||
vst1.32 {q3},[r2]!
|
||||
bne Loop192
|
||||
|
||||
mov r12,#12
|
||||
add r2,r2,#0x20
|
||||
b Ldone
|
||||
|
||||
.align 4
|
||||
L256:
|
||||
vld1.8 {q8},[r0]
|
||||
mov r1,#7
|
||||
mov r12,#14
|
||||
vst1.32 {q3},[r2]!
|
||||
|
||||
Loop256:
|
||||
vtbl.8 d20,{q8},d4
|
||||
vtbl.8 d21,{q8},d5
|
||||
vext.8 q9,q0,q3,#12
|
||||
vst1.32 {q8},[r2]!
|
||||
.byte 0x00,0x43,0xf0,0xf3 @ aese q10,q0
|
||||
subs r1,r1,#1
|
||||
|
||||
veor q3,q3,q9
|
||||
vext.8 q9,q0,q9,#12
|
||||
veor q3,q3,q9
|
||||
vext.8 q9,q0,q9,#12
|
||||
veor q10,q10,q1
|
||||
veor q3,q3,q9
|
||||
vshl.u8 q1,q1,#1
|
||||
veor q3,q3,q10
|
||||
vst1.32 {q3},[r2]!
|
||||
beq Ldone
|
||||
|
||||
vdup.32 q10,d7[1]
|
||||
vext.8 q9,q0,q8,#12
|
||||
.byte 0x00,0x43,0xf0,0xf3 @ aese q10,q0
|
||||
|
||||
veor q8,q8,q9
|
||||
vext.8 q9,q0,q9,#12
|
||||
veor q8,q8,q9
|
||||
vext.8 q9,q0,q9,#12
|
||||
veor q8,q8,q9
|
||||
|
||||
veor q8,q8,q10
|
||||
b Loop256
|
||||
|
||||
Ldone:
|
||||
str r12,[r2]
|
||||
mov r3,#0
|
||||
|
||||
Lenc_key_abort:
|
||||
mov r0,r3 @ return value
|
||||
|
||||
bx lr
|
||||
|
||||
|
||||
.globl _aes_hw_set_decrypt_key
|
||||
.private_extern _aes_hw_set_decrypt_key
|
||||
#ifdef __thumb2__
|
||||
.thumb_func _aes_hw_set_decrypt_key
|
||||
#endif
|
||||
.align 5
|
||||
_aes_hw_set_decrypt_key:
|
||||
stmdb sp!,{r4,lr}
|
||||
bl Lenc_key
|
||||
|
||||
cmp r0,#0
|
||||
bne Ldec_key_abort
|
||||
|
||||
sub r2,r2,#240 @ restore original r2
|
||||
mov r4,#-16
|
||||
add r0,r2,r12,lsl#4 @ end of key schedule
|
||||
|
||||
vld1.32 {q0},[r2]
|
||||
vld1.32 {q1},[r0]
|
||||
vst1.32 {q0},[r0],r4
|
||||
vst1.32 {q1},[r2]!
|
||||
|
||||
Loop_imc:
|
||||
vld1.32 {q0},[r2]
|
||||
vld1.32 {q1},[r0]
|
||||
.byte 0xc0,0x03,0xb0,0xf3 @ aesimc q0,q0
|
||||
.byte 0xc2,0x23,0xb0,0xf3 @ aesimc q1,q1
|
||||
vst1.32 {q0},[r0],r4
|
||||
vst1.32 {q1},[r2]!
|
||||
cmp r0,r2
|
||||
bhi Loop_imc
|
||||
|
||||
vld1.32 {q0},[r2]
|
||||
.byte 0xc0,0x03,0xb0,0xf3 @ aesimc q0,q0
|
||||
vst1.32 {q0},[r0]
|
||||
|
||||
eor r0,r0,r0 @ return value
|
||||
Ldec_key_abort:
|
||||
ldmia sp!,{r4,pc}
|
||||
|
||||
.globl _aes_hw_encrypt
|
||||
.private_extern _aes_hw_encrypt
|
||||
#ifdef __thumb2__
|
||||
.thumb_func _aes_hw_encrypt
|
||||
#endif
|
||||
.align 5
|
||||
_aes_hw_encrypt:
|
||||
AARCH64_VALID_CALL_TARGET
|
||||
ldr r3,[r2,#240]
|
||||
vld1.32 {q0},[r2]!
|
||||
vld1.8 {q2},[r0]
|
||||
sub r3,r3,#2
|
||||
vld1.32 {q1},[r2]!
|
||||
|
||||
Loop_enc:
|
||||
.byte 0x00,0x43,0xb0,0xf3 @ aese q2,q0
|
||||
.byte 0x84,0x43,0xb0,0xf3 @ aesmc q2,q2
|
||||
vld1.32 {q0},[r2]!
|
||||
subs r3,r3,#2
|
||||
.byte 0x02,0x43,0xb0,0xf3 @ aese q2,q1
|
||||
.byte 0x84,0x43,0xb0,0xf3 @ aesmc q2,q2
|
||||
vld1.32 {q1},[r2]!
|
||||
bgt Loop_enc
|
||||
|
||||
.byte 0x00,0x43,0xb0,0xf3 @ aese q2,q0
|
||||
.byte 0x84,0x43,0xb0,0xf3 @ aesmc q2,q2
|
||||
vld1.32 {q0},[r2]
|
||||
.byte 0x02,0x43,0xb0,0xf3 @ aese q2,q1
|
||||
veor q2,q2,q0
|
||||
|
||||
vst1.8 {q2},[r1]
|
||||
bx lr
|
||||
|
||||
.globl _aes_hw_decrypt
|
||||
.private_extern _aes_hw_decrypt
|
||||
#ifdef __thumb2__
|
||||
.thumb_func _aes_hw_decrypt
|
||||
#endif
|
||||
.align 5
|
||||
_aes_hw_decrypt:
|
||||
AARCH64_VALID_CALL_TARGET
|
||||
ldr r3,[r2,#240]
|
||||
vld1.32 {q0},[r2]!
|
||||
vld1.8 {q2},[r0]
|
||||
sub r3,r3,#2
|
||||
vld1.32 {q1},[r2]!
|
||||
|
||||
Loop_dec:
|
||||
.byte 0x40,0x43,0xb0,0xf3 @ aesd q2,q0
|
||||
.byte 0xc4,0x43,0xb0,0xf3 @ aesimc q2,q2
|
||||
vld1.32 {q0},[r2]!
|
||||
subs r3,r3,#2
|
||||
.byte 0x42,0x43,0xb0,0xf3 @ aesd q2,q1
|
||||
.byte 0xc4,0x43,0xb0,0xf3 @ aesimc q2,q2
|
||||
vld1.32 {q1},[r2]!
|
||||
bgt Loop_dec
|
||||
|
||||
.byte 0x40,0x43,0xb0,0xf3 @ aesd q2,q0
|
||||
.byte 0xc4,0x43,0xb0,0xf3 @ aesimc q2,q2
|
||||
vld1.32 {q0},[r2]
|
||||
.byte 0x42,0x43,0xb0,0xf3 @ aesd q2,q1
|
||||
veor q2,q2,q0
|
||||
|
||||
vst1.8 {q2},[r1]
|
||||
bx lr
|
||||
|
||||
.globl _aes_hw_cbc_encrypt
|
||||
.private_extern _aes_hw_cbc_encrypt
|
||||
#ifdef __thumb2__
|
||||
.thumb_func _aes_hw_cbc_encrypt
|
||||
#endif
|
||||
.align 5
|
||||
_aes_hw_cbc_encrypt:
|
||||
mov ip,sp
|
||||
stmdb sp!,{r4,r5,r6,r7,r8,lr}
|
||||
vstmdb sp!,{d8,d9,d10,d11,d12,d13,d14,d15} @ ABI specification says so
|
||||
ldmia ip,{r4,r5} @ load remaining args
|
||||
subs r2,r2,#16
|
||||
mov r8,#16
|
||||
blo Lcbc_abort
|
||||
moveq r8,#0
|
||||
|
||||
cmp r5,#0 @ en- or decrypting?
|
||||
ldr r5,[r3,#240]
|
||||
and r2,r2,#-16
|
||||
vld1.8 {q6},[r4]
|
||||
vld1.8 {q0},[r0],r8
|
||||
|
||||
vld1.32 {q8,q9},[r3] @ load key schedule...
|
||||
sub r5,r5,#6
|
||||
add r7,r3,r5,lsl#4 @ pointer to last 7 round keys
|
||||
sub r5,r5,#2
|
||||
vld1.32 {q10,q11},[r7]!
|
||||
vld1.32 {q12,q13},[r7]!
|
||||
vld1.32 {q14,q15},[r7]!
|
||||
vld1.32 {q7},[r7]
|
||||
|
||||
add r7,r3,#32
|
||||
mov r6,r5
|
||||
beq Lcbc_dec
|
||||
|
||||
cmp r5,#2
|
||||
veor q0,q0,q6
|
||||
veor q5,q8,q7
|
||||
beq Lcbc_enc128
|
||||
|
||||
vld1.32 {q2,q3},[r7]
|
||||
add r7,r3,#16
|
||||
add r6,r3,#16*4
|
||||
add r12,r3,#16*5
|
||||
.byte 0x20,0x03,0xb0,0xf3 @ aese q0,q8
|
||||
.byte 0x80,0x03,0xb0,0xf3 @ aesmc q0,q0
|
||||
add r14,r3,#16*6
|
||||
add r3,r3,#16*7
|
||||
b Lenter_cbc_enc
|
||||
|
||||
.align 4
|
||||
Loop_cbc_enc:
|
||||
.byte 0x20,0x03,0xb0,0xf3 @ aese q0,q8
|
||||
.byte 0x80,0x03,0xb0,0xf3 @ aesmc q0,q0
|
||||
vst1.8 {q6},[r1]!
|
||||
Lenter_cbc_enc:
|
||||
.byte 0x22,0x03,0xb0,0xf3 @ aese q0,q9
|
||||
.byte 0x80,0x03,0xb0,0xf3 @ aesmc q0,q0
|
||||
.byte 0x04,0x03,0xb0,0xf3 @ aese q0,q2
|
||||
.byte 0x80,0x03,0xb0,0xf3 @ aesmc q0,q0
|
||||
vld1.32 {q8},[r6]
|
||||
cmp r5,#4
|
||||
.byte 0x06,0x03,0xb0,0xf3 @ aese q0,q3
|
||||
.byte 0x80,0x03,0xb0,0xf3 @ aesmc q0,q0
|
||||
vld1.32 {q9},[r12]
|
||||
beq Lcbc_enc192
|
||||
|
||||
.byte 0x20,0x03,0xb0,0xf3 @ aese q0,q8
|
||||
.byte 0x80,0x03,0xb0,0xf3 @ aesmc q0,q0
|
||||
vld1.32 {q8},[r14]
|
||||
.byte 0x22,0x03,0xb0,0xf3 @ aese q0,q9
|
||||
.byte 0x80,0x03,0xb0,0xf3 @ aesmc q0,q0
|
||||
vld1.32 {q9},[r3]
|
||||
nop
|
||||
|
||||
Lcbc_enc192:
|
||||
.byte 0x20,0x03,0xb0,0xf3 @ aese q0,q8
|
||||
.byte 0x80,0x03,0xb0,0xf3 @ aesmc q0,q0
|
||||
subs r2,r2,#16
|
||||
.byte 0x22,0x03,0xb0,0xf3 @ aese q0,q9
|
||||
.byte 0x80,0x03,0xb0,0xf3 @ aesmc q0,q0
|
||||
moveq r8,#0
|
||||
.byte 0x24,0x03,0xb0,0xf3 @ aese q0,q10
|
||||
.byte 0x80,0x03,0xb0,0xf3 @ aesmc q0,q0
|
||||
.byte 0x26,0x03,0xb0,0xf3 @ aese q0,q11
|
||||
.byte 0x80,0x03,0xb0,0xf3 @ aesmc q0,q0
|
||||
vld1.8 {q8},[r0],r8
|
||||
.byte 0x28,0x03,0xb0,0xf3 @ aese q0,q12
|
||||
.byte 0x80,0x03,0xb0,0xf3 @ aesmc q0,q0
|
||||
veor q8,q8,q5
|
||||
.byte 0x2a,0x03,0xb0,0xf3 @ aese q0,q13
|
||||
.byte 0x80,0x03,0xb0,0xf3 @ aesmc q0,q0
|
||||
vld1.32 {q9},[r7] @ re-pre-load rndkey[1]
|
||||
.byte 0x2c,0x03,0xb0,0xf3 @ aese q0,q14
|
||||
.byte 0x80,0x03,0xb0,0xf3 @ aesmc q0,q0
|
||||
.byte 0x2e,0x03,0xb0,0xf3 @ aese q0,q15
|
||||
veor q6,q0,q7
|
||||
bhs Loop_cbc_enc
|
||||
|
||||
vst1.8 {q6},[r1]!
|
||||
b Lcbc_done
|
||||
|
||||
.align 5
|
||||
Lcbc_enc128:
|
||||
vld1.32 {q2,q3},[r7]
|
||||
.byte 0x20,0x03,0xb0,0xf3 @ aese q0,q8
|
||||
.byte 0x80,0x03,0xb0,0xf3 @ aesmc q0,q0
|
||||
b Lenter_cbc_enc128
|
||||
Loop_cbc_enc128:
|
||||
.byte 0x20,0x03,0xb0,0xf3 @ aese q0,q8
|
||||
.byte 0x80,0x03,0xb0,0xf3 @ aesmc q0,q0
|
||||
vst1.8 {q6},[r1]!
|
||||
Lenter_cbc_enc128:
|
||||
.byte 0x22,0x03,0xb0,0xf3 @ aese q0,q9
|
||||
.byte 0x80,0x03,0xb0,0xf3 @ aesmc q0,q0
|
||||
subs r2,r2,#16
|
||||
.byte 0x04,0x03,0xb0,0xf3 @ aese q0,q2
|
||||
.byte 0x80,0x03,0xb0,0xf3 @ aesmc q0,q0
|
||||
moveq r8,#0
|
||||
.byte 0x06,0x03,0xb0,0xf3 @ aese q0,q3
|
||||
.byte 0x80,0x03,0xb0,0xf3 @ aesmc q0,q0
|
||||
.byte 0x24,0x03,0xb0,0xf3 @ aese q0,q10
|
||||
.byte 0x80,0x03,0xb0,0xf3 @ aesmc q0,q0
|
||||
.byte 0x26,0x03,0xb0,0xf3 @ aese q0,q11
|
||||
.byte 0x80,0x03,0xb0,0xf3 @ aesmc q0,q0
|
||||
vld1.8 {q8},[r0],r8
|
||||
.byte 0x28,0x03,0xb0,0xf3 @ aese q0,q12
|
||||
.byte 0x80,0x03,0xb0,0xf3 @ aesmc q0,q0
|
||||
.byte 0x2a,0x03,0xb0,0xf3 @ aese q0,q13
|
||||
.byte 0x80,0x03,0xb0,0xf3 @ aesmc q0,q0
|
||||
.byte 0x2c,0x03,0xb0,0xf3 @ aese q0,q14
|
||||
.byte 0x80,0x03,0xb0,0xf3 @ aesmc q0,q0
|
||||
veor q8,q8,q5
|
||||
.byte 0x2e,0x03,0xb0,0xf3 @ aese q0,q15
|
||||
veor q6,q0,q7
|
||||
bhs Loop_cbc_enc128
|
||||
|
||||
vst1.8 {q6},[r1]!
|
||||
b Lcbc_done
|
||||
.align 5
|
||||
Lcbc_dec:
|
||||
vld1.8 {q10},[r0]!
|
||||
subs r2,r2,#32 @ bias
|
||||
add r6,r5,#2
|
||||
vorr q3,q0,q0
|
||||
vorr q1,q0,q0
|
||||
vorr q11,q10,q10
|
||||
blo Lcbc_dec_tail
|
||||
|
||||
vorr q1,q10,q10
|
||||
vld1.8 {q10},[r0]!
|
||||
vorr q2,q0,q0
|
||||
vorr q3,q1,q1
|
||||
vorr q11,q10,q10
|
||||
|
||||
Loop3x_cbc_dec:
|
||||
.byte 0x60,0x03,0xb0,0xf3 @ aesd q0,q8
|
||||
.byte 0xc0,0x03,0xb0,0xf3 @ aesimc q0,q0
|
||||
.byte 0x60,0x23,0xb0,0xf3 @ aesd q1,q8
|
||||
.byte 0xc2,0x23,0xb0,0xf3 @ aesimc q1,q1
|
||||
.byte 0x60,0x43,0xf0,0xf3 @ aesd q10,q8
|
||||
.byte 0xe4,0x43,0xf0,0xf3 @ aesimc q10,q10
|
||||
vld1.32 {q8},[r7]!
|
||||
subs r6,r6,#2
|
||||
.byte 0x62,0x03,0xb0,0xf3 @ aesd q0,q9
|
||||
.byte 0xc0,0x03,0xb0,0xf3 @ aesimc q0,q0
|
||||
.byte 0x62,0x23,0xb0,0xf3 @ aesd q1,q9
|
||||
.byte 0xc2,0x23,0xb0,0xf3 @ aesimc q1,q1
|
||||
.byte 0x62,0x43,0xf0,0xf3 @ aesd q10,q9
|
||||
.byte 0xe4,0x43,0xf0,0xf3 @ aesimc q10,q10
|
||||
vld1.32 {q9},[r7]!
|
||||
bgt Loop3x_cbc_dec
|
||||
|
||||
.byte 0x60,0x03,0xb0,0xf3 @ aesd q0,q8
|
||||
.byte 0xc0,0x03,0xb0,0xf3 @ aesimc q0,q0
|
||||
.byte 0x60,0x23,0xb0,0xf3 @ aesd q1,q8
|
||||
.byte 0xc2,0x23,0xb0,0xf3 @ aesimc q1,q1
|
||||
.byte 0x60,0x43,0xf0,0xf3 @ aesd q10,q8
|
||||
.byte 0xe4,0x43,0xf0,0xf3 @ aesimc q10,q10
|
||||
veor q4,q6,q7
|
||||
subs r2,r2,#0x30
|
||||
veor q5,q2,q7
|
||||
movlo r6,r2 @ r6, r6, is zero at this point
|
||||
.byte 0x62,0x03,0xb0,0xf3 @ aesd q0,q9
|
||||
.byte 0xc0,0x03,0xb0,0xf3 @ aesimc q0,q0
|
||||
.byte 0x62,0x23,0xb0,0xf3 @ aesd q1,q9
|
||||
.byte 0xc2,0x23,0xb0,0xf3 @ aesimc q1,q1
|
||||
.byte 0x62,0x43,0xf0,0xf3 @ aesd q10,q9
|
||||
.byte 0xe4,0x43,0xf0,0xf3 @ aesimc q10,q10
|
||||
veor q9,q3,q7
|
||||
add r0,r0,r6 @ r0 is adjusted in such way that
|
||||
@ at exit from the loop q1-q10
|
||||
@ are loaded with last "words"
|
||||
vorr q6,q11,q11
|
||||
mov r7,r3
|
||||
.byte 0x68,0x03,0xb0,0xf3 @ aesd q0,q12
|
||||
.byte 0xc0,0x03,0xb0,0xf3 @ aesimc q0,q0
|
||||
.byte 0x68,0x23,0xb0,0xf3 @ aesd q1,q12
|
||||
.byte 0xc2,0x23,0xb0,0xf3 @ aesimc q1,q1
|
||||
.byte 0x68,0x43,0xf0,0xf3 @ aesd q10,q12
|
||||
.byte 0xe4,0x43,0xf0,0xf3 @ aesimc q10,q10
|
||||
vld1.8 {q2},[r0]!
|
||||
.byte 0x6a,0x03,0xb0,0xf3 @ aesd q0,q13
|
||||
.byte 0xc0,0x03,0xb0,0xf3 @ aesimc q0,q0
|
||||
.byte 0x6a,0x23,0xb0,0xf3 @ aesd q1,q13
|
||||
.byte 0xc2,0x23,0xb0,0xf3 @ aesimc q1,q1
|
||||
.byte 0x6a,0x43,0xf0,0xf3 @ aesd q10,q13
|
||||
.byte 0xe4,0x43,0xf0,0xf3 @ aesimc q10,q10
|
||||
vld1.8 {q3},[r0]!
|
||||
.byte 0x6c,0x03,0xb0,0xf3 @ aesd q0,q14
|
||||
.byte 0xc0,0x03,0xb0,0xf3 @ aesimc q0,q0
|
||||
.byte 0x6c,0x23,0xb0,0xf3 @ aesd q1,q14
|
||||
.byte 0xc2,0x23,0xb0,0xf3 @ aesimc q1,q1
|
||||
.byte 0x6c,0x43,0xf0,0xf3 @ aesd q10,q14
|
||||
.byte 0xe4,0x43,0xf0,0xf3 @ aesimc q10,q10
|
||||
vld1.8 {q11},[r0]!
|
||||
.byte 0x6e,0x03,0xb0,0xf3 @ aesd q0,q15
|
||||
.byte 0x6e,0x23,0xb0,0xf3 @ aesd q1,q15
|
||||
.byte 0x6e,0x43,0xf0,0xf3 @ aesd q10,q15
|
||||
vld1.32 {q8},[r7]! @ re-pre-load rndkey[0]
|
||||
add r6,r5,#2
|
||||
veor q4,q4,q0
|
||||
veor q5,q5,q1
|
||||
veor q10,q10,q9
|
||||
vld1.32 {q9},[r7]! @ re-pre-load rndkey[1]
|
||||
vst1.8 {q4},[r1]!
|
||||
vorr q0,q2,q2
|
||||
vst1.8 {q5},[r1]!
|
||||
vorr q1,q3,q3
|
||||
vst1.8 {q10},[r1]!
|
||||
vorr q10,q11,q11
|
||||
bhs Loop3x_cbc_dec
|
||||
|
||||
cmn r2,#0x30
|
||||
beq Lcbc_done
|
||||
nop
|
||||
|
||||
Lcbc_dec_tail:
|
||||
.byte 0x60,0x23,0xb0,0xf3 @ aesd q1,q8
|
||||
.byte 0xc2,0x23,0xb0,0xf3 @ aesimc q1,q1
|
||||
.byte 0x60,0x43,0xf0,0xf3 @ aesd q10,q8
|
||||
.byte 0xe4,0x43,0xf0,0xf3 @ aesimc q10,q10
|
||||
vld1.32 {q8},[r7]!
|
||||
subs r6,r6,#2
|
||||
.byte 0x62,0x23,0xb0,0xf3 @ aesd q1,q9
|
||||
.byte 0xc2,0x23,0xb0,0xf3 @ aesimc q1,q1
|
||||
.byte 0x62,0x43,0xf0,0xf3 @ aesd q10,q9
|
||||
.byte 0xe4,0x43,0xf0,0xf3 @ aesimc q10,q10
|
||||
vld1.32 {q9},[r7]!
|
||||
bgt Lcbc_dec_tail
|
||||
|
||||
.byte 0x60,0x23,0xb0,0xf3 @ aesd q1,q8
|
||||
.byte 0xc2,0x23,0xb0,0xf3 @ aesimc q1,q1
|
||||
.byte 0x60,0x43,0xf0,0xf3 @ aesd q10,q8
|
||||
.byte 0xe4,0x43,0xf0,0xf3 @ aesimc q10,q10
|
||||
.byte 0x62,0x23,0xb0,0xf3 @ aesd q1,q9
|
||||
.byte 0xc2,0x23,0xb0,0xf3 @ aesimc q1,q1
|
||||
.byte 0x62,0x43,0xf0,0xf3 @ aesd q10,q9
|
||||
.byte 0xe4,0x43,0xf0,0xf3 @ aesimc q10,q10
|
||||
.byte 0x68,0x23,0xb0,0xf3 @ aesd q1,q12
|
||||
.byte 0xc2,0x23,0xb0,0xf3 @ aesimc q1,q1
|
||||
.byte 0x68,0x43,0xf0,0xf3 @ aesd q10,q12
|
||||
.byte 0xe4,0x43,0xf0,0xf3 @ aesimc q10,q10
|
||||
cmn r2,#0x20
|
||||
.byte 0x6a,0x23,0xb0,0xf3 @ aesd q1,q13
|
||||
.byte 0xc2,0x23,0xb0,0xf3 @ aesimc q1,q1
|
||||
.byte 0x6a,0x43,0xf0,0xf3 @ aesd q10,q13
|
||||
.byte 0xe4,0x43,0xf0,0xf3 @ aesimc q10,q10
|
||||
veor q5,q6,q7
|
||||
.byte 0x6c,0x23,0xb0,0xf3 @ aesd q1,q14
|
||||
.byte 0xc2,0x23,0xb0,0xf3 @ aesimc q1,q1
|
||||
.byte 0x6c,0x43,0xf0,0xf3 @ aesd q10,q14
|
||||
.byte 0xe4,0x43,0xf0,0xf3 @ aesimc q10,q10
|
||||
veor q9,q3,q7
|
||||
.byte 0x6e,0x23,0xb0,0xf3 @ aesd q1,q15
|
||||
.byte 0x6e,0x43,0xf0,0xf3 @ aesd q10,q15
|
||||
beq Lcbc_dec_one
|
||||
veor q5,q5,q1
|
||||
veor q9,q9,q10
|
||||
vorr q6,q11,q11
|
||||
vst1.8 {q5},[r1]!
|
||||
vst1.8 {q9},[r1]!
|
||||
b Lcbc_done
|
||||
|
||||
Lcbc_dec_one:
|
||||
veor q5,q5,q10
|
||||
vorr q6,q11,q11
|
||||
vst1.8 {q5},[r1]!
|
||||
|
||||
Lcbc_done:
|
||||
vst1.8 {q6},[r4]
|
||||
Lcbc_abort:
|
||||
vldmia sp!,{d8,d9,d10,d11,d12,d13,d14,d15}
|
||||
ldmia sp!,{r4,r5,r6,r7,r8,pc}
|
||||
|
||||
.globl _aes_hw_ctr32_encrypt_blocks
|
||||
.private_extern _aes_hw_ctr32_encrypt_blocks
|
||||
#ifdef __thumb2__
|
||||
.thumb_func _aes_hw_ctr32_encrypt_blocks
|
||||
#endif
|
||||
.align 5
|
||||
_aes_hw_ctr32_encrypt_blocks:
|
||||
mov ip,sp
|
||||
stmdb sp!,{r4,r5,r6,r7,r8,r9,r10,lr}
|
||||
vstmdb sp!,{d8,d9,d10,d11,d12,d13,d14,d15} @ ABI specification says so
|
||||
ldr r4, [ip] @ load remaining arg
|
||||
ldr r5,[r3,#240]
|
||||
|
||||
ldr r8, [r4, #12]
|
||||
vld1.32 {q0},[r4]
|
||||
|
||||
vld1.32 {q8,q9},[r3] @ load key schedule...
|
||||
sub r5,r5,#4
|
||||
mov r12,#16
|
||||
cmp r2,#2
|
||||
add r7,r3,r5,lsl#4 @ pointer to last 5 round keys
|
||||
sub r5,r5,#2
|
||||
vld1.32 {q12,q13},[r7]!
|
||||
vld1.32 {q14,q15},[r7]!
|
||||
vld1.32 {q7},[r7]
|
||||
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
|
||||
add r10, r8, #1
|
||||
vorr q6,q0,q0
|
||||
rev r10, 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
|
||||
vorr q10,q6,q6
|
||||
b Loop3x_ctr32
|
||||
|
||||
.align 4
|
||||
Loop3x_ctr32:
|
||||
.byte 0x20,0x03,0xb0,0xf3 @ aese q0,q8
|
||||
.byte 0x80,0x03,0xb0,0xf3 @ aesmc q0,q0
|
||||
.byte 0x20,0x23,0xb0,0xf3 @ aese q1,q8
|
||||
.byte 0x82,0x23,0xb0,0xf3 @ aesmc q1,q1
|
||||
.byte 0x20,0x43,0xf0,0xf3 @ aese q10,q8
|
||||
.byte 0xa4,0x43,0xf0,0xf3 @ aesmc q10,q10
|
||||
vld1.32 {q8},[r7]!
|
||||
subs r6,r6,#2
|
||||
.byte 0x22,0x03,0xb0,0xf3 @ aese q0,q9
|
||||
.byte 0x80,0x03,0xb0,0xf3 @ aesmc q0,q0
|
||||
.byte 0x22,0x23,0xb0,0xf3 @ aese q1,q9
|
||||
.byte 0x82,0x23,0xb0,0xf3 @ aesmc q1,q1
|
||||
.byte 0x22,0x43,0xf0,0xf3 @ aese q10,q9
|
||||
.byte 0xa4,0x43,0xf0,0xf3 @ aesmc q10,q10
|
||||
vld1.32 {q9},[r7]!
|
||||
bgt Loop3x_ctr32
|
||||
|
||||
.byte 0x20,0x03,0xb0,0xf3 @ aese q0,q8
|
||||
.byte 0x80,0x83,0xb0,0xf3 @ aesmc q4,q0
|
||||
.byte 0x20,0x23,0xb0,0xf3 @ aese q1,q8
|
||||
.byte 0x82,0xa3,0xb0,0xf3 @ aesmc q5,q1
|
||||
vld1.8 {q2},[r0]!
|
||||
add r9,r8,#1
|
||||
.byte 0x20,0x43,0xf0,0xf3 @ aese q10,q8
|
||||
.byte 0xa4,0x43,0xf0,0xf3 @ aesmc q10,q10
|
||||
vld1.8 {q3},[r0]!
|
||||
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
|
||||
.byte 0x8a,0xa3,0xb0,0xf3 @ aesmc q5,q5
|
||||
vld1.8 {q11},[r0]!
|
||||
mov r7,r3
|
||||
.byte 0x22,0x43,0xf0,0xf3 @ aese q10,q9
|
||||
.byte 0xa4,0x23,0xf0,0xf3 @ aesmc q9,q10
|
||||
.byte 0x28,0x83,0xb0,0xf3 @ aese q4,q12
|
||||
.byte 0x88,0x83,0xb0,0xf3 @ aesmc q4,q4
|
||||
.byte 0x28,0xa3,0xb0,0xf3 @ aese q5,q12
|
||||
.byte 0x8a,0xa3,0xb0,0xf3 @ aesmc q5,q5
|
||||
veor q2,q2,q7
|
||||
add r10,r8,#2
|
||||
.byte 0x28,0x23,0xf0,0xf3 @ aese q9,q12
|
||||
.byte 0xa2,0x23,0xf0,0xf3 @ aesmc q9,q9
|
||||
veor q3,q3,q7
|
||||
add r8,r8,#3
|
||||
.byte 0x2a,0x83,0xb0,0xf3 @ aese q4,q13
|
||||
.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
|
||||
vmov.32 d13[1], r9
|
||||
.byte 0x2a,0x23,0xf0,0xf3 @ aese q9,q13
|
||||
.byte 0xa2,0x23,0xf0,0xf3 @ aesmc q9,q9
|
||||
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
|
||||
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
|
||||
vorr q10,q6,q6
|
||||
subs r2,r2,#3
|
||||
.byte 0x2e,0x83,0xb0,0xf3 @ aese q4,q15
|
||||
.byte 0x2e,0xa3,0xb0,0xf3 @ aese q5,q15
|
||||
.byte 0x2e,0x23,0xf0,0xf3 @ aese q9,q15
|
||||
|
||||
veor q2,q2,q4
|
||||
vld1.32 {q8},[r7]! @ re-pre-load rndkey[0]
|
||||
vst1.8 {q2},[r1]!
|
||||
veor q3,q3,q5
|
||||
mov r6,r5
|
||||
vst1.8 {q3},[r1]!
|
||||
veor q11,q11,q9
|
||||
vld1.32 {q9},[r7]! @ re-pre-load rndkey[1]
|
||||
vst1.8 {q11},[r1]!
|
||||
bhs Loop3x_ctr32
|
||||
|
||||
adds r2,r2,#3
|
||||
beq Lctr32_done
|
||||
cmp r2,#1
|
||||
mov r12,#16
|
||||
moveq r12,#0
|
||||
|
||||
Lctr32_tail:
|
||||
.byte 0x20,0x03,0xb0,0xf3 @ aese q0,q8
|
||||
.byte 0x80,0x03,0xb0,0xf3 @ aesmc q0,q0
|
||||
.byte 0x20,0x23,0xb0,0xf3 @ aese q1,q8
|
||||
.byte 0x82,0x23,0xb0,0xf3 @ aesmc q1,q1
|
||||
vld1.32 {q8},[r7]!
|
||||
subs r6,r6,#2
|
||||
.byte 0x22,0x03,0xb0,0xf3 @ aese q0,q9
|
||||
.byte 0x80,0x03,0xb0,0xf3 @ aesmc q0,q0
|
||||
.byte 0x22,0x23,0xb0,0xf3 @ aese q1,q9
|
||||
.byte 0x82,0x23,0xb0,0xf3 @ aesmc q1,q1
|
||||
vld1.32 {q9},[r7]!
|
||||
bgt Lctr32_tail
|
||||
|
||||
.byte 0x20,0x03,0xb0,0xf3 @ aese q0,q8
|
||||
.byte 0x80,0x03,0xb0,0xf3 @ aesmc q0,q0
|
||||
.byte 0x20,0x23,0xb0,0xf3 @ aese q1,q8
|
||||
.byte 0x82,0x23,0xb0,0xf3 @ aesmc q1,q1
|
||||
.byte 0x22,0x03,0xb0,0xf3 @ aese q0,q9
|
||||
.byte 0x80,0x03,0xb0,0xf3 @ aesmc q0,q0
|
||||
.byte 0x22,0x23,0xb0,0xf3 @ aese q1,q9
|
||||
.byte 0x82,0x23,0xb0,0xf3 @ aesmc q1,q1
|
||||
vld1.8 {q2},[r0],r12
|
||||
.byte 0x28,0x03,0xb0,0xf3 @ aese q0,q12
|
||||
.byte 0x80,0x03,0xb0,0xf3 @ aesmc q0,q0
|
||||
.byte 0x28,0x23,0xb0,0xf3 @ aese q1,q12
|
||||
.byte 0x82,0x23,0xb0,0xf3 @ aesmc q1,q1
|
||||
vld1.8 {q3},[r0]
|
||||
.byte 0x2a,0x03,0xb0,0xf3 @ aese q0,q13
|
||||
.byte 0x80,0x03,0xb0,0xf3 @ aesmc q0,q0
|
||||
.byte 0x2a,0x23,0xb0,0xf3 @ aese q1,q13
|
||||
.byte 0x82,0x23,0xb0,0xf3 @ aesmc q1,q1
|
||||
veor q2,q2,q7
|
||||
.byte 0x2c,0x03,0xb0,0xf3 @ aese q0,q14
|
||||
.byte 0x80,0x03,0xb0,0xf3 @ aesmc q0,q0
|
||||
.byte 0x2c,0x23,0xb0,0xf3 @ aese q1,q14
|
||||
.byte 0x82,0x23,0xb0,0xf3 @ aesmc q1,q1
|
||||
veor q3,q3,q7
|
||||
.byte 0x2e,0x03,0xb0,0xf3 @ aese q0,q15
|
||||
.byte 0x2e,0x23,0xb0,0xf3 @ aese q1,q15
|
||||
|
||||
cmp r2,#1
|
||||
veor q2,q2,q0
|
||||
veor q3,q3,q1
|
||||
vst1.8 {q2},[r1]!
|
||||
beq Lctr32_done
|
||||
vst1.8 {q3},[r1]
|
||||
|
||||
Lctr32_done:
|
||||
vldmia sp!,{d8,d9,d10,d11,d12,d13,d14,d15}
|
||||
ldmia sp!,{r4,r5,r6,r7,r8,r9,r10,pc}
|
||||
|
||||
#endif
|
||||
#endif // !OPENSSL_NO_ASM && defined(OPENSSL_ARM) && defined(__APPLE__)
|
||||
#endif // defined(__arm__) && defined(__APPLE__)
|
||||
#if defined(__linux__) && defined(__ELF__)
|
||||
.section .note.GNU-stack,"",%progbits
|
||||
#endif
|
||||
|
||||
@@ -1,950 +0,0 @@
|
||||
#define BORINGSSL_PREFIX CCryptoBoringSSL
|
||||
#if defined(__arm__) && defined(__APPLE__)
|
||||
// This file is generated from a similarly-named Perl script in the BoringSSL
|
||||
// source tree. Do not edit by hand.
|
||||
|
||||
#include <CCryptoBoringSSL_asm_base.h>
|
||||
|
||||
#if !defined(OPENSSL_NO_ASM) && defined(OPENSSL_ARM) && defined(__APPLE__)
|
||||
#include <CCryptoBoringSSL_arm_arch.h>
|
||||
|
||||
@ Silence ARMv8 deprecated IT instruction warnings. This file is used by both
|
||||
@ ARMv7 and ARMv8 processors and does not use ARMv8 instructions.
|
||||
|
||||
|
||||
.text
|
||||
#if defined(__thumb2__)
|
||||
.syntax unified
|
||||
.thumb
|
||||
#else
|
||||
.code 32
|
||||
#endif
|
||||
|
||||
.globl _bn_mul_mont_nohw
|
||||
.private_extern _bn_mul_mont_nohw
|
||||
#ifdef __thumb2__
|
||||
.thumb_func _bn_mul_mont_nohw
|
||||
#endif
|
||||
|
||||
.align 5
|
||||
_bn_mul_mont_nohw:
|
||||
ldr ip,[sp,#4] @ load num
|
||||
stmdb sp!,{r0,r2} @ sp points at argument block
|
||||
cmp ip,#2
|
||||
mov r0,ip @ load num
|
||||
#ifdef __thumb2__
|
||||
ittt lt
|
||||
#endif
|
||||
movlt r0,#0
|
||||
addlt sp,sp,#2*4
|
||||
blt Labrt
|
||||
|
||||
stmdb sp!,{r4,r5,r6,r7,r8,r9,r10,r11,r12,lr} @ save 10 registers
|
||||
|
||||
mov r0,r0,lsl#2 @ rescale r0 for byte count
|
||||
sub sp,sp,r0 @ alloca(4*num)
|
||||
sub sp,sp,#4 @ +extra dword
|
||||
sub r0,r0,#4 @ "num=num-1"
|
||||
add r4,r2,r0 @ &bp[num-1]
|
||||
|
||||
add r0,sp,r0 @ r0 to point at &tp[num-1]
|
||||
ldr r8,[r0,#14*4] @ &n0
|
||||
ldr r2,[r2] @ bp[0]
|
||||
ldr r5,[r1],#4 @ ap[0],ap++
|
||||
ldr r6,[r3],#4 @ np[0],np++
|
||||
ldr r8,[r8] @ *n0
|
||||
str r4,[r0,#15*4] @ save &bp[num]
|
||||
|
||||
umull r10,r11,r5,r2 @ ap[0]*bp[0]
|
||||
str r8,[r0,#14*4] @ save n0 value
|
||||
mul r8,r10,r8 @ "tp[0]"*n0
|
||||
mov r12,#0
|
||||
umlal r10,r12,r6,r8 @ np[0]*n0+"t[0]"
|
||||
mov r4,sp
|
||||
|
||||
L1st:
|
||||
ldr r5,[r1],#4 @ ap[j],ap++
|
||||
mov r10,r11
|
||||
ldr r6,[r3],#4 @ np[j],np++
|
||||
mov r11,#0
|
||||
umlal r10,r11,r5,r2 @ ap[j]*bp[0]
|
||||
mov r14,#0
|
||||
umlal r12,r14,r6,r8 @ np[j]*n0
|
||||
adds r12,r12,r10
|
||||
str r12,[r4],#4 @ tp[j-1]=,tp++
|
||||
adc r12,r14,#0
|
||||
cmp r4,r0
|
||||
bne L1st
|
||||
|
||||
adds r12,r12,r11
|
||||
ldr r4,[r0,#13*4] @ restore bp
|
||||
mov r14,#0
|
||||
ldr r8,[r0,#14*4] @ restore n0
|
||||
adc r14,r14,#0
|
||||
str r12,[r0] @ tp[num-1]=
|
||||
mov r7,sp
|
||||
str r14,[r0,#4] @ tp[num]=
|
||||
|
||||
Louter:
|
||||
sub r7,r0,r7 @ "original" r0-1 value
|
||||
sub r1,r1,r7 @ "rewind" ap to &ap[1]
|
||||
ldr r2,[r4,#4]! @ *(++bp)
|
||||
sub r3,r3,r7 @ "rewind" np to &np[1]
|
||||
ldr r5,[r1,#-4] @ ap[0]
|
||||
ldr r10,[sp] @ tp[0]
|
||||
ldr r6,[r3,#-4] @ np[0]
|
||||
ldr r7,[sp,#4] @ tp[1]
|
||||
|
||||
mov r11,#0
|
||||
umlal r10,r11,r5,r2 @ ap[0]*bp[i]+tp[0]
|
||||
str r4,[r0,#13*4] @ save bp
|
||||
mul r8,r10,r8
|
||||
mov r12,#0
|
||||
umlal r10,r12,r6,r8 @ np[0]*n0+"tp[0]"
|
||||
mov r4,sp
|
||||
|
||||
Linner:
|
||||
ldr r5,[r1],#4 @ ap[j],ap++
|
||||
adds r10,r11,r7 @ +=tp[j]
|
||||
ldr r6,[r3],#4 @ np[j],np++
|
||||
mov r11,#0
|
||||
umlal r10,r11,r5,r2 @ ap[j]*bp[i]
|
||||
mov r14,#0
|
||||
umlal r12,r14,r6,r8 @ np[j]*n0
|
||||
adc r11,r11,#0
|
||||
ldr r7,[r4,#8] @ tp[j+1]
|
||||
adds r12,r12,r10
|
||||
str r12,[r4],#4 @ tp[j-1]=,tp++
|
||||
adc r12,r14,#0
|
||||
cmp r4,r0
|
||||
bne Linner
|
||||
|
||||
adds r12,r12,r11
|
||||
mov r14,#0
|
||||
ldr r4,[r0,#13*4] @ restore bp
|
||||
adc r14,r14,#0
|
||||
ldr r8,[r0,#14*4] @ restore n0
|
||||
adds r12,r12,r7
|
||||
ldr r7,[r0,#15*4] @ restore &bp[num]
|
||||
adc r14,r14,#0
|
||||
str r12,[r0] @ tp[num-1]=
|
||||
str r14,[r0,#4] @ tp[num]=
|
||||
|
||||
cmp r4,r7
|
||||
#ifdef __thumb2__
|
||||
itt ne
|
||||
#endif
|
||||
movne r7,sp
|
||||
bne Louter
|
||||
|
||||
ldr r2,[r0,#12*4] @ pull rp
|
||||
mov r5,sp
|
||||
add r0,r0,#4 @ r0 to point at &tp[num]
|
||||
sub r5,r0,r5 @ "original" num value
|
||||
mov r4,sp @ "rewind" r4
|
||||
mov r1,r4 @ "borrow" r1
|
||||
sub r3,r3,r5 @ "rewind" r3 to &np[0]
|
||||
|
||||
subs r7,r7,r7 @ "clear" carry flag
|
||||
Lsub: ldr r7,[r4],#4
|
||||
ldr r6,[r3],#4
|
||||
sbcs r7,r7,r6 @ tp[j]-np[j]
|
||||
str r7,[r2],#4 @ rp[j]=
|
||||
teq r4,r0 @ preserve carry
|
||||
bne Lsub
|
||||
sbcs r14,r14,#0 @ upmost carry
|
||||
mov r4,sp @ "rewind" r4
|
||||
sub r2,r2,r5 @ "rewind" r2
|
||||
|
||||
Lcopy: ldr r7,[r4] @ conditional copy
|
||||
ldr r5,[r2]
|
||||
str sp,[r4],#4 @ zap tp
|
||||
#ifdef __thumb2__
|
||||
it cc
|
||||
#endif
|
||||
movcc r5,r7
|
||||
str r5,[r2],#4
|
||||
teq r4,r0 @ preserve carry
|
||||
bne Lcopy
|
||||
|
||||
mov sp,r0
|
||||
add sp,sp,#4 @ skip over tp[num+1]
|
||||
ldmia sp!,{r4,r5,r6,r7,r8,r9,r10,r11,r12,lr} @ restore registers
|
||||
add sp,sp,#2*4 @ skip over {r0,r2}
|
||||
mov r0,#1
|
||||
Labrt:
|
||||
#if __ARM_ARCH>=5
|
||||
bx lr @ bx lr
|
||||
#else
|
||||
tst lr,#1
|
||||
moveq pc,lr @ be binary compatible with V4, yet
|
||||
.word 0xe12fff1e @ interoperable with Thumb ISA:-)
|
||||
#endif
|
||||
|
||||
#if __ARM_MAX_ARCH__>=7
|
||||
|
||||
|
||||
|
||||
.globl _bn_mul8x_mont_neon
|
||||
.private_extern _bn_mul8x_mont_neon
|
||||
#ifdef __thumb2__
|
||||
.thumb_func _bn_mul8x_mont_neon
|
||||
#endif
|
||||
.align 5
|
||||
_bn_mul8x_mont_neon:
|
||||
mov ip,sp
|
||||
stmdb sp!,{r4,r5,r6,r7,r8,r9,r10,r11}
|
||||
vstmdb sp!,{d8,d9,d10,d11,d12,d13,d14,d15} @ ABI specification says so
|
||||
ldmia ip,{r4,r5} @ load rest of parameter block
|
||||
mov ip,sp
|
||||
|
||||
cmp r5,#8
|
||||
bhi LNEON_8n
|
||||
|
||||
@ special case for r5==8, everything is in register bank...
|
||||
|
||||
vld1.32 {d28[0]}, [r2,:32]!
|
||||
veor d8,d8,d8
|
||||
sub r7,sp,r5,lsl#4
|
||||
vld1.32 {d0,d1,d2,d3}, [r1]! @ can't specify :32 :-(
|
||||
and r7,r7,#-64
|
||||
vld1.32 {d30[0]}, [r4,:32]
|
||||
mov sp,r7 @ alloca
|
||||
vzip.16 d28,d8
|
||||
|
||||
vmull.u32 q6,d28,d0[0]
|
||||
vmull.u32 q7,d28,d0[1]
|
||||
vmull.u32 q8,d28,d1[0]
|
||||
vshl.i64 d29,d13,#16
|
||||
vmull.u32 q9,d28,d1[1]
|
||||
|
||||
vadd.u64 d29,d29,d12
|
||||
veor d8,d8,d8
|
||||
vmul.u32 d29,d29,d30
|
||||
|
||||
vmull.u32 q10,d28,d2[0]
|
||||
vld1.32 {d4,d5,d6,d7}, [r3]!
|
||||
vmull.u32 q11,d28,d2[1]
|
||||
vmull.u32 q12,d28,d3[0]
|
||||
vzip.16 d29,d8
|
||||
vmull.u32 q13,d28,d3[1]
|
||||
|
||||
vmlal.u32 q6,d29,d4[0]
|
||||
sub r9,r5,#1
|
||||
vmlal.u32 q7,d29,d4[1]
|
||||
vmlal.u32 q8,d29,d5[0]
|
||||
vmlal.u32 q9,d29,d5[1]
|
||||
|
||||
vmlal.u32 q10,d29,d6[0]
|
||||
vmov q5,q6
|
||||
vmlal.u32 q11,d29,d6[1]
|
||||
vmov q6,q7
|
||||
vmlal.u32 q12,d29,d7[0]
|
||||
vmov q7,q8
|
||||
vmlal.u32 q13,d29,d7[1]
|
||||
vmov q8,q9
|
||||
vmov q9,q10
|
||||
vshr.u64 d10,d10,#16
|
||||
vmov q10,q11
|
||||
vmov q11,q12
|
||||
vadd.u64 d10,d10,d11
|
||||
vmov q12,q13
|
||||
veor q13,q13
|
||||
vshr.u64 d10,d10,#16
|
||||
|
||||
b LNEON_outer8
|
||||
|
||||
.align 4
|
||||
LNEON_outer8:
|
||||
vld1.32 {d28[0]}, [r2,:32]!
|
||||
veor d8,d8,d8
|
||||
vzip.16 d28,d8
|
||||
vadd.u64 d12,d12,d10
|
||||
|
||||
vmlal.u32 q6,d28,d0[0]
|
||||
vmlal.u32 q7,d28,d0[1]
|
||||
vmlal.u32 q8,d28,d1[0]
|
||||
vshl.i64 d29,d13,#16
|
||||
vmlal.u32 q9,d28,d1[1]
|
||||
|
||||
vadd.u64 d29,d29,d12
|
||||
veor d8,d8,d8
|
||||
subs r9,r9,#1
|
||||
vmul.u32 d29,d29,d30
|
||||
|
||||
vmlal.u32 q10,d28,d2[0]
|
||||
vmlal.u32 q11,d28,d2[1]
|
||||
vmlal.u32 q12,d28,d3[0]
|
||||
vzip.16 d29,d8
|
||||
vmlal.u32 q13,d28,d3[1]
|
||||
|
||||
vmlal.u32 q6,d29,d4[0]
|
||||
vmlal.u32 q7,d29,d4[1]
|
||||
vmlal.u32 q8,d29,d5[0]
|
||||
vmlal.u32 q9,d29,d5[1]
|
||||
|
||||
vmlal.u32 q10,d29,d6[0]
|
||||
vmov q5,q6
|
||||
vmlal.u32 q11,d29,d6[1]
|
||||
vmov q6,q7
|
||||
vmlal.u32 q12,d29,d7[0]
|
||||
vmov q7,q8
|
||||
vmlal.u32 q13,d29,d7[1]
|
||||
vmov q8,q9
|
||||
vmov q9,q10
|
||||
vshr.u64 d10,d10,#16
|
||||
vmov q10,q11
|
||||
vmov q11,q12
|
||||
vadd.u64 d10,d10,d11
|
||||
vmov q12,q13
|
||||
veor q13,q13
|
||||
vshr.u64 d10,d10,#16
|
||||
|
||||
bne LNEON_outer8
|
||||
|
||||
vadd.u64 d12,d12,d10
|
||||
mov r7,sp
|
||||
vshr.u64 d10,d12,#16
|
||||
mov r8,r5
|
||||
vadd.u64 d13,d13,d10
|
||||
add r6,sp,#96
|
||||
vshr.u64 d10,d13,#16
|
||||
vzip.16 d12,d13
|
||||
|
||||
b LNEON_tail_entry
|
||||
|
||||
.align 4
|
||||
LNEON_8n:
|
||||
veor q6,q6,q6
|
||||
sub r7,sp,#128
|
||||
veor q7,q7,q7
|
||||
sub r7,r7,r5,lsl#4
|
||||
veor q8,q8,q8
|
||||
and r7,r7,#-64
|
||||
veor q9,q9,q9
|
||||
mov sp,r7 @ alloca
|
||||
veor q10,q10,q10
|
||||
add r7,r7,#256
|
||||
veor q11,q11,q11
|
||||
sub r8,r5,#8
|
||||
veor q12,q12,q12
|
||||
veor q13,q13,q13
|
||||
|
||||
LNEON_8n_init:
|
||||
vst1.64 {q6,q7},[r7,:256]!
|
||||
subs r8,r8,#8
|
||||
vst1.64 {q8,q9},[r7,:256]!
|
||||
vst1.64 {q10,q11},[r7,:256]!
|
||||
vst1.64 {q12,q13},[r7,:256]!
|
||||
bne LNEON_8n_init
|
||||
|
||||
add r6,sp,#256
|
||||
vld1.32 {d0,d1,d2,d3},[r1]!
|
||||
add r10,sp,#8
|
||||
vld1.32 {d30[0]},[r4,:32]
|
||||
mov r9,r5
|
||||
b LNEON_8n_outer
|
||||
|
||||
.align 4
|
||||
LNEON_8n_outer:
|
||||
vld1.32 {d28[0]},[r2,:32]! @ *b++
|
||||
veor d8,d8,d8
|
||||
vzip.16 d28,d8
|
||||
add r7,sp,#128
|
||||
vld1.32 {d4,d5,d6,d7},[r3]!
|
||||
|
||||
vmlal.u32 q6,d28,d0[0]
|
||||
vmlal.u32 q7,d28,d0[1]
|
||||
veor d8,d8,d8
|
||||
vmlal.u32 q8,d28,d1[0]
|
||||
vshl.i64 d29,d13,#16
|
||||
vmlal.u32 q9,d28,d1[1]
|
||||
vadd.u64 d29,d29,d12
|
||||
vmlal.u32 q10,d28,d2[0]
|
||||
vmul.u32 d29,d29,d30
|
||||
vmlal.u32 q11,d28,d2[1]
|
||||
vst1.32 {d28},[sp,:64] @ put aside smashed b[8*i+0]
|
||||
vmlal.u32 q12,d28,d3[0]
|
||||
vzip.16 d29,d8
|
||||
vmlal.u32 q13,d28,d3[1]
|
||||
vld1.32 {d28[0]},[r2,:32]! @ *b++
|
||||
vmlal.u32 q6,d29,d4[0]
|
||||
veor d10,d10,d10
|
||||
vmlal.u32 q7,d29,d4[1]
|
||||
vzip.16 d28,d10
|
||||
vmlal.u32 q8,d29,d5[0]
|
||||
vshr.u64 d12,d12,#16
|
||||
vmlal.u32 q9,d29,d5[1]
|
||||
vmlal.u32 q10,d29,d6[0]
|
||||
vadd.u64 d12,d12,d13
|
||||
vmlal.u32 q11,d29,d6[1]
|
||||
vshr.u64 d12,d12,#16
|
||||
vmlal.u32 q12,d29,d7[0]
|
||||
vmlal.u32 q13,d29,d7[1]
|
||||
vadd.u64 d14,d14,d12
|
||||
vst1.32 {d29},[r10,:64]! @ put aside smashed m[8*i+0]
|
||||
vmlal.u32 q7,d28,d0[0]
|
||||
vld1.64 {q6},[r6,:128]!
|
||||
vmlal.u32 q8,d28,d0[1]
|
||||
veor d8,d8,d8
|
||||
vmlal.u32 q9,d28,d1[0]
|
||||
vshl.i64 d29,d15,#16
|
||||
vmlal.u32 q10,d28,d1[1]
|
||||
vadd.u64 d29,d29,d14
|
||||
vmlal.u32 q11,d28,d2[0]
|
||||
vmul.u32 d29,d29,d30
|
||||
vmlal.u32 q12,d28,d2[1]
|
||||
vst1.32 {d28},[r10,:64]! @ put aside smashed b[8*i+1]
|
||||
vmlal.u32 q13,d28,d3[0]
|
||||
vzip.16 d29,d8
|
||||
vmlal.u32 q6,d28,d3[1]
|
||||
vld1.32 {d28[0]},[r2,:32]! @ *b++
|
||||
vmlal.u32 q7,d29,d4[0]
|
||||
veor d10,d10,d10
|
||||
vmlal.u32 q8,d29,d4[1]
|
||||
vzip.16 d28,d10
|
||||
vmlal.u32 q9,d29,d5[0]
|
||||
vshr.u64 d14,d14,#16
|
||||
vmlal.u32 q10,d29,d5[1]
|
||||
vmlal.u32 q11,d29,d6[0]
|
||||
vadd.u64 d14,d14,d15
|
||||
vmlal.u32 q12,d29,d6[1]
|
||||
vshr.u64 d14,d14,#16
|
||||
vmlal.u32 q13,d29,d7[0]
|
||||
vmlal.u32 q6,d29,d7[1]
|
||||
vadd.u64 d16,d16,d14
|
||||
vst1.32 {d29},[r10,:64]! @ put aside smashed m[8*i+1]
|
||||
vmlal.u32 q8,d28,d0[0]
|
||||
vld1.64 {q7},[r6,:128]!
|
||||
vmlal.u32 q9,d28,d0[1]
|
||||
veor d8,d8,d8
|
||||
vmlal.u32 q10,d28,d1[0]
|
||||
vshl.i64 d29,d17,#16
|
||||
vmlal.u32 q11,d28,d1[1]
|
||||
vadd.u64 d29,d29,d16
|
||||
vmlal.u32 q12,d28,d2[0]
|
||||
vmul.u32 d29,d29,d30
|
||||
vmlal.u32 q13,d28,d2[1]
|
||||
vst1.32 {d28},[r10,:64]! @ put aside smashed b[8*i+2]
|
||||
vmlal.u32 q6,d28,d3[0]
|
||||
vzip.16 d29,d8
|
||||
vmlal.u32 q7,d28,d3[1]
|
||||
vld1.32 {d28[0]},[r2,:32]! @ *b++
|
||||
vmlal.u32 q8,d29,d4[0]
|
||||
veor d10,d10,d10
|
||||
vmlal.u32 q9,d29,d4[1]
|
||||
vzip.16 d28,d10
|
||||
vmlal.u32 q10,d29,d5[0]
|
||||
vshr.u64 d16,d16,#16
|
||||
vmlal.u32 q11,d29,d5[1]
|
||||
vmlal.u32 q12,d29,d6[0]
|
||||
vadd.u64 d16,d16,d17
|
||||
vmlal.u32 q13,d29,d6[1]
|
||||
vshr.u64 d16,d16,#16
|
||||
vmlal.u32 q6,d29,d7[0]
|
||||
vmlal.u32 q7,d29,d7[1]
|
||||
vadd.u64 d18,d18,d16
|
||||
vst1.32 {d29},[r10,:64]! @ put aside smashed m[8*i+2]
|
||||
vmlal.u32 q9,d28,d0[0]
|
||||
vld1.64 {q8},[r6,:128]!
|
||||
vmlal.u32 q10,d28,d0[1]
|
||||
veor d8,d8,d8
|
||||
vmlal.u32 q11,d28,d1[0]
|
||||
vshl.i64 d29,d19,#16
|
||||
vmlal.u32 q12,d28,d1[1]
|
||||
vadd.u64 d29,d29,d18
|
||||
vmlal.u32 q13,d28,d2[0]
|
||||
vmul.u32 d29,d29,d30
|
||||
vmlal.u32 q6,d28,d2[1]
|
||||
vst1.32 {d28},[r10,:64]! @ put aside smashed b[8*i+3]
|
||||
vmlal.u32 q7,d28,d3[0]
|
||||
vzip.16 d29,d8
|
||||
vmlal.u32 q8,d28,d3[1]
|
||||
vld1.32 {d28[0]},[r2,:32]! @ *b++
|
||||
vmlal.u32 q9,d29,d4[0]
|
||||
veor d10,d10,d10
|
||||
vmlal.u32 q10,d29,d4[1]
|
||||
vzip.16 d28,d10
|
||||
vmlal.u32 q11,d29,d5[0]
|
||||
vshr.u64 d18,d18,#16
|
||||
vmlal.u32 q12,d29,d5[1]
|
||||
vmlal.u32 q13,d29,d6[0]
|
||||
vadd.u64 d18,d18,d19
|
||||
vmlal.u32 q6,d29,d6[1]
|
||||
vshr.u64 d18,d18,#16
|
||||
vmlal.u32 q7,d29,d7[0]
|
||||
vmlal.u32 q8,d29,d7[1]
|
||||
vadd.u64 d20,d20,d18
|
||||
vst1.32 {d29},[r10,:64]! @ put aside smashed m[8*i+3]
|
||||
vmlal.u32 q10,d28,d0[0]
|
||||
vld1.64 {q9},[r6,:128]!
|
||||
vmlal.u32 q11,d28,d0[1]
|
||||
veor d8,d8,d8
|
||||
vmlal.u32 q12,d28,d1[0]
|
||||
vshl.i64 d29,d21,#16
|
||||
vmlal.u32 q13,d28,d1[1]
|
||||
vadd.u64 d29,d29,d20
|
||||
vmlal.u32 q6,d28,d2[0]
|
||||
vmul.u32 d29,d29,d30
|
||||
vmlal.u32 q7,d28,d2[1]
|
||||
vst1.32 {d28},[r10,:64]! @ put aside smashed b[8*i+4]
|
||||
vmlal.u32 q8,d28,d3[0]
|
||||
vzip.16 d29,d8
|
||||
vmlal.u32 q9,d28,d3[1]
|
||||
vld1.32 {d28[0]},[r2,:32]! @ *b++
|
||||
vmlal.u32 q10,d29,d4[0]
|
||||
veor d10,d10,d10
|
||||
vmlal.u32 q11,d29,d4[1]
|
||||
vzip.16 d28,d10
|
||||
vmlal.u32 q12,d29,d5[0]
|
||||
vshr.u64 d20,d20,#16
|
||||
vmlal.u32 q13,d29,d5[1]
|
||||
vmlal.u32 q6,d29,d6[0]
|
||||
vadd.u64 d20,d20,d21
|
||||
vmlal.u32 q7,d29,d6[1]
|
||||
vshr.u64 d20,d20,#16
|
||||
vmlal.u32 q8,d29,d7[0]
|
||||
vmlal.u32 q9,d29,d7[1]
|
||||
vadd.u64 d22,d22,d20
|
||||
vst1.32 {d29},[r10,:64]! @ put aside smashed m[8*i+4]
|
||||
vmlal.u32 q11,d28,d0[0]
|
||||
vld1.64 {q10},[r6,:128]!
|
||||
vmlal.u32 q12,d28,d0[1]
|
||||
veor d8,d8,d8
|
||||
vmlal.u32 q13,d28,d1[0]
|
||||
vshl.i64 d29,d23,#16
|
||||
vmlal.u32 q6,d28,d1[1]
|
||||
vadd.u64 d29,d29,d22
|
||||
vmlal.u32 q7,d28,d2[0]
|
||||
vmul.u32 d29,d29,d30
|
||||
vmlal.u32 q8,d28,d2[1]
|
||||
vst1.32 {d28},[r10,:64]! @ put aside smashed b[8*i+5]
|
||||
vmlal.u32 q9,d28,d3[0]
|
||||
vzip.16 d29,d8
|
||||
vmlal.u32 q10,d28,d3[1]
|
||||
vld1.32 {d28[0]},[r2,:32]! @ *b++
|
||||
vmlal.u32 q11,d29,d4[0]
|
||||
veor d10,d10,d10
|
||||
vmlal.u32 q12,d29,d4[1]
|
||||
vzip.16 d28,d10
|
||||
vmlal.u32 q13,d29,d5[0]
|
||||
vshr.u64 d22,d22,#16
|
||||
vmlal.u32 q6,d29,d5[1]
|
||||
vmlal.u32 q7,d29,d6[0]
|
||||
vadd.u64 d22,d22,d23
|
||||
vmlal.u32 q8,d29,d6[1]
|
||||
vshr.u64 d22,d22,#16
|
||||
vmlal.u32 q9,d29,d7[0]
|
||||
vmlal.u32 q10,d29,d7[1]
|
||||
vadd.u64 d24,d24,d22
|
||||
vst1.32 {d29},[r10,:64]! @ put aside smashed m[8*i+5]
|
||||
vmlal.u32 q12,d28,d0[0]
|
||||
vld1.64 {q11},[r6,:128]!
|
||||
vmlal.u32 q13,d28,d0[1]
|
||||
veor d8,d8,d8
|
||||
vmlal.u32 q6,d28,d1[0]
|
||||
vshl.i64 d29,d25,#16
|
||||
vmlal.u32 q7,d28,d1[1]
|
||||
vadd.u64 d29,d29,d24
|
||||
vmlal.u32 q8,d28,d2[0]
|
||||
vmul.u32 d29,d29,d30
|
||||
vmlal.u32 q9,d28,d2[1]
|
||||
vst1.32 {d28},[r10,:64]! @ put aside smashed b[8*i+6]
|
||||
vmlal.u32 q10,d28,d3[0]
|
||||
vzip.16 d29,d8
|
||||
vmlal.u32 q11,d28,d3[1]
|
||||
vld1.32 {d28[0]},[r2,:32]! @ *b++
|
||||
vmlal.u32 q12,d29,d4[0]
|
||||
veor d10,d10,d10
|
||||
vmlal.u32 q13,d29,d4[1]
|
||||
vzip.16 d28,d10
|
||||
vmlal.u32 q6,d29,d5[0]
|
||||
vshr.u64 d24,d24,#16
|
||||
vmlal.u32 q7,d29,d5[1]
|
||||
vmlal.u32 q8,d29,d6[0]
|
||||
vadd.u64 d24,d24,d25
|
||||
vmlal.u32 q9,d29,d6[1]
|
||||
vshr.u64 d24,d24,#16
|
||||
vmlal.u32 q10,d29,d7[0]
|
||||
vmlal.u32 q11,d29,d7[1]
|
||||
vadd.u64 d26,d26,d24
|
||||
vst1.32 {d29},[r10,:64]! @ put aside smashed m[8*i+6]
|
||||
vmlal.u32 q13,d28,d0[0]
|
||||
vld1.64 {q12},[r6,:128]!
|
||||
vmlal.u32 q6,d28,d0[1]
|
||||
veor d8,d8,d8
|
||||
vmlal.u32 q7,d28,d1[0]
|
||||
vshl.i64 d29,d27,#16
|
||||
vmlal.u32 q8,d28,d1[1]
|
||||
vadd.u64 d29,d29,d26
|
||||
vmlal.u32 q9,d28,d2[0]
|
||||
vmul.u32 d29,d29,d30
|
||||
vmlal.u32 q10,d28,d2[1]
|
||||
vst1.32 {d28},[r10,:64]! @ put aside smashed b[8*i+7]
|
||||
vmlal.u32 q11,d28,d3[0]
|
||||
vzip.16 d29,d8
|
||||
vmlal.u32 q12,d28,d3[1]
|
||||
vld1.32 {d28},[sp,:64] @ pull smashed b[8*i+0]
|
||||
vmlal.u32 q13,d29,d4[0]
|
||||
vld1.32 {d0,d1,d2,d3},[r1]!
|
||||
vmlal.u32 q6,d29,d4[1]
|
||||
vmlal.u32 q7,d29,d5[0]
|
||||
vshr.u64 d26,d26,#16
|
||||
vmlal.u32 q8,d29,d5[1]
|
||||
vmlal.u32 q9,d29,d6[0]
|
||||
vadd.u64 d26,d26,d27
|
||||
vmlal.u32 q10,d29,d6[1]
|
||||
vshr.u64 d26,d26,#16
|
||||
vmlal.u32 q11,d29,d7[0]
|
||||
vmlal.u32 q12,d29,d7[1]
|
||||
vadd.u64 d12,d12,d26
|
||||
vst1.32 {d29},[r10,:64] @ put aside smashed m[8*i+7]
|
||||
add r10,sp,#8 @ rewind
|
||||
sub r8,r5,#8
|
||||
b LNEON_8n_inner
|
||||
|
||||
.align 4
|
||||
LNEON_8n_inner:
|
||||
subs r8,r8,#8
|
||||
vmlal.u32 q6,d28,d0[0]
|
||||
vld1.64 {q13},[r6,:128]
|
||||
vmlal.u32 q7,d28,d0[1]
|
||||
vld1.32 {d29},[r10,:64]! @ pull smashed m[8*i+0]
|
||||
vmlal.u32 q8,d28,d1[0]
|
||||
vld1.32 {d4,d5,d6,d7},[r3]!
|
||||
vmlal.u32 q9,d28,d1[1]
|
||||
it ne
|
||||
addne r6,r6,#16 @ don't advance in last iteration
|
||||
vmlal.u32 q10,d28,d2[0]
|
||||
vmlal.u32 q11,d28,d2[1]
|
||||
vmlal.u32 q12,d28,d3[0]
|
||||
vmlal.u32 q13,d28,d3[1]
|
||||
vld1.32 {d28},[r10,:64]! @ pull smashed b[8*i+1]
|
||||
vmlal.u32 q6,d29,d4[0]
|
||||
vmlal.u32 q7,d29,d4[1]
|
||||
vmlal.u32 q8,d29,d5[0]
|
||||
vmlal.u32 q9,d29,d5[1]
|
||||
vmlal.u32 q10,d29,d6[0]
|
||||
vmlal.u32 q11,d29,d6[1]
|
||||
vmlal.u32 q12,d29,d7[0]
|
||||
vmlal.u32 q13,d29,d7[1]
|
||||
vst1.64 {q6},[r7,:128]!
|
||||
vmlal.u32 q7,d28,d0[0]
|
||||
vld1.64 {q6},[r6,:128]
|
||||
vmlal.u32 q8,d28,d0[1]
|
||||
vld1.32 {d29},[r10,:64]! @ pull smashed m[8*i+1]
|
||||
vmlal.u32 q9,d28,d1[0]
|
||||
it ne
|
||||
addne r6,r6,#16 @ don't advance in last iteration
|
||||
vmlal.u32 q10,d28,d1[1]
|
||||
vmlal.u32 q11,d28,d2[0]
|
||||
vmlal.u32 q12,d28,d2[1]
|
||||
vmlal.u32 q13,d28,d3[0]
|
||||
vmlal.u32 q6,d28,d3[1]
|
||||
vld1.32 {d28},[r10,:64]! @ pull smashed b[8*i+2]
|
||||
vmlal.u32 q7,d29,d4[0]
|
||||
vmlal.u32 q8,d29,d4[1]
|
||||
vmlal.u32 q9,d29,d5[0]
|
||||
vmlal.u32 q10,d29,d5[1]
|
||||
vmlal.u32 q11,d29,d6[0]
|
||||
vmlal.u32 q12,d29,d6[1]
|
||||
vmlal.u32 q13,d29,d7[0]
|
||||
vmlal.u32 q6,d29,d7[1]
|
||||
vst1.64 {q7},[r7,:128]!
|
||||
vmlal.u32 q8,d28,d0[0]
|
||||
vld1.64 {q7},[r6,:128]
|
||||
vmlal.u32 q9,d28,d0[1]
|
||||
vld1.32 {d29},[r10,:64]! @ pull smashed m[8*i+2]
|
||||
vmlal.u32 q10,d28,d1[0]
|
||||
it ne
|
||||
addne r6,r6,#16 @ don't advance in last iteration
|
||||
vmlal.u32 q11,d28,d1[1]
|
||||
vmlal.u32 q12,d28,d2[0]
|
||||
vmlal.u32 q13,d28,d2[1]
|
||||
vmlal.u32 q6,d28,d3[0]
|
||||
vmlal.u32 q7,d28,d3[1]
|
||||
vld1.32 {d28},[r10,:64]! @ pull smashed b[8*i+3]
|
||||
vmlal.u32 q8,d29,d4[0]
|
||||
vmlal.u32 q9,d29,d4[1]
|
||||
vmlal.u32 q10,d29,d5[0]
|
||||
vmlal.u32 q11,d29,d5[1]
|
||||
vmlal.u32 q12,d29,d6[0]
|
||||
vmlal.u32 q13,d29,d6[1]
|
||||
vmlal.u32 q6,d29,d7[0]
|
||||
vmlal.u32 q7,d29,d7[1]
|
||||
vst1.64 {q8},[r7,:128]!
|
||||
vmlal.u32 q9,d28,d0[0]
|
||||
vld1.64 {q8},[r6,:128]
|
||||
vmlal.u32 q10,d28,d0[1]
|
||||
vld1.32 {d29},[r10,:64]! @ pull smashed m[8*i+3]
|
||||
vmlal.u32 q11,d28,d1[0]
|
||||
it ne
|
||||
addne r6,r6,#16 @ don't advance in last iteration
|
||||
vmlal.u32 q12,d28,d1[1]
|
||||
vmlal.u32 q13,d28,d2[0]
|
||||
vmlal.u32 q6,d28,d2[1]
|
||||
vmlal.u32 q7,d28,d3[0]
|
||||
vmlal.u32 q8,d28,d3[1]
|
||||
vld1.32 {d28},[r10,:64]! @ pull smashed b[8*i+4]
|
||||
vmlal.u32 q9,d29,d4[0]
|
||||
vmlal.u32 q10,d29,d4[1]
|
||||
vmlal.u32 q11,d29,d5[0]
|
||||
vmlal.u32 q12,d29,d5[1]
|
||||
vmlal.u32 q13,d29,d6[0]
|
||||
vmlal.u32 q6,d29,d6[1]
|
||||
vmlal.u32 q7,d29,d7[0]
|
||||
vmlal.u32 q8,d29,d7[1]
|
||||
vst1.64 {q9},[r7,:128]!
|
||||
vmlal.u32 q10,d28,d0[0]
|
||||
vld1.64 {q9},[r6,:128]
|
||||
vmlal.u32 q11,d28,d0[1]
|
||||
vld1.32 {d29},[r10,:64]! @ pull smashed m[8*i+4]
|
||||
vmlal.u32 q12,d28,d1[0]
|
||||
it ne
|
||||
addne r6,r6,#16 @ don't advance in last iteration
|
||||
vmlal.u32 q13,d28,d1[1]
|
||||
vmlal.u32 q6,d28,d2[0]
|
||||
vmlal.u32 q7,d28,d2[1]
|
||||
vmlal.u32 q8,d28,d3[0]
|
||||
vmlal.u32 q9,d28,d3[1]
|
||||
vld1.32 {d28},[r10,:64]! @ pull smashed b[8*i+5]
|
||||
vmlal.u32 q10,d29,d4[0]
|
||||
vmlal.u32 q11,d29,d4[1]
|
||||
vmlal.u32 q12,d29,d5[0]
|
||||
vmlal.u32 q13,d29,d5[1]
|
||||
vmlal.u32 q6,d29,d6[0]
|
||||
vmlal.u32 q7,d29,d6[1]
|
||||
vmlal.u32 q8,d29,d7[0]
|
||||
vmlal.u32 q9,d29,d7[1]
|
||||
vst1.64 {q10},[r7,:128]!
|
||||
vmlal.u32 q11,d28,d0[0]
|
||||
vld1.64 {q10},[r6,:128]
|
||||
vmlal.u32 q12,d28,d0[1]
|
||||
vld1.32 {d29},[r10,:64]! @ pull smashed m[8*i+5]
|
||||
vmlal.u32 q13,d28,d1[0]
|
||||
it ne
|
||||
addne r6,r6,#16 @ don't advance in last iteration
|
||||
vmlal.u32 q6,d28,d1[1]
|
||||
vmlal.u32 q7,d28,d2[0]
|
||||
vmlal.u32 q8,d28,d2[1]
|
||||
vmlal.u32 q9,d28,d3[0]
|
||||
vmlal.u32 q10,d28,d3[1]
|
||||
vld1.32 {d28},[r10,:64]! @ pull smashed b[8*i+6]
|
||||
vmlal.u32 q11,d29,d4[0]
|
||||
vmlal.u32 q12,d29,d4[1]
|
||||
vmlal.u32 q13,d29,d5[0]
|
||||
vmlal.u32 q6,d29,d5[1]
|
||||
vmlal.u32 q7,d29,d6[0]
|
||||
vmlal.u32 q8,d29,d6[1]
|
||||
vmlal.u32 q9,d29,d7[0]
|
||||
vmlal.u32 q10,d29,d7[1]
|
||||
vst1.64 {q11},[r7,:128]!
|
||||
vmlal.u32 q12,d28,d0[0]
|
||||
vld1.64 {q11},[r6,:128]
|
||||
vmlal.u32 q13,d28,d0[1]
|
||||
vld1.32 {d29},[r10,:64]! @ pull smashed m[8*i+6]
|
||||
vmlal.u32 q6,d28,d1[0]
|
||||
it ne
|
||||
addne r6,r6,#16 @ don't advance in last iteration
|
||||
vmlal.u32 q7,d28,d1[1]
|
||||
vmlal.u32 q8,d28,d2[0]
|
||||
vmlal.u32 q9,d28,d2[1]
|
||||
vmlal.u32 q10,d28,d3[0]
|
||||
vmlal.u32 q11,d28,d3[1]
|
||||
vld1.32 {d28},[r10,:64]! @ pull smashed b[8*i+7]
|
||||
vmlal.u32 q12,d29,d4[0]
|
||||
vmlal.u32 q13,d29,d4[1]
|
||||
vmlal.u32 q6,d29,d5[0]
|
||||
vmlal.u32 q7,d29,d5[1]
|
||||
vmlal.u32 q8,d29,d6[0]
|
||||
vmlal.u32 q9,d29,d6[1]
|
||||
vmlal.u32 q10,d29,d7[0]
|
||||
vmlal.u32 q11,d29,d7[1]
|
||||
vst1.64 {q12},[r7,:128]!
|
||||
vmlal.u32 q13,d28,d0[0]
|
||||
vld1.64 {q12},[r6,:128]
|
||||
vmlal.u32 q6,d28,d0[1]
|
||||
vld1.32 {d29},[r10,:64]! @ pull smashed m[8*i+7]
|
||||
vmlal.u32 q7,d28,d1[0]
|
||||
it ne
|
||||
addne r6,r6,#16 @ don't advance in last iteration
|
||||
vmlal.u32 q8,d28,d1[1]
|
||||
vmlal.u32 q9,d28,d2[0]
|
||||
vmlal.u32 q10,d28,d2[1]
|
||||
vmlal.u32 q11,d28,d3[0]
|
||||
vmlal.u32 q12,d28,d3[1]
|
||||
it eq
|
||||
subeq r1,r1,r5,lsl#2 @ rewind
|
||||
vmlal.u32 q13,d29,d4[0]
|
||||
vld1.32 {d28},[sp,:64] @ pull smashed b[8*i+0]
|
||||
vmlal.u32 q6,d29,d4[1]
|
||||
vld1.32 {d0,d1,d2,d3},[r1]!
|
||||
vmlal.u32 q7,d29,d5[0]
|
||||
add r10,sp,#8 @ rewind
|
||||
vmlal.u32 q8,d29,d5[1]
|
||||
vmlal.u32 q9,d29,d6[0]
|
||||
vmlal.u32 q10,d29,d6[1]
|
||||
vmlal.u32 q11,d29,d7[0]
|
||||
vst1.64 {q13},[r7,:128]!
|
||||
vmlal.u32 q12,d29,d7[1]
|
||||
|
||||
bne LNEON_8n_inner
|
||||
add r6,sp,#128
|
||||
vst1.64 {q6,q7},[r7,:256]!
|
||||
veor q2,q2,q2 @ d4-d5
|
||||
vst1.64 {q8,q9},[r7,:256]!
|
||||
veor q3,q3,q3 @ d6-d7
|
||||
vst1.64 {q10,q11},[r7,:256]!
|
||||
vst1.64 {q12},[r7,:128]
|
||||
|
||||
subs r9,r9,#8
|
||||
vld1.64 {q6,q7},[r6,:256]!
|
||||
vld1.64 {q8,q9},[r6,:256]!
|
||||
vld1.64 {q10,q11},[r6,:256]!
|
||||
vld1.64 {q12,q13},[r6,:256]!
|
||||
|
||||
itt ne
|
||||
subne r3,r3,r5,lsl#2 @ rewind
|
||||
bne LNEON_8n_outer
|
||||
|
||||
add r7,sp,#128
|
||||
vst1.64 {q2,q3}, [sp,:256]! @ start wiping stack frame
|
||||
vshr.u64 d10,d12,#16
|
||||
vst1.64 {q2,q3},[sp,:256]!
|
||||
vadd.u64 d13,d13,d10
|
||||
vst1.64 {q2,q3}, [sp,:256]!
|
||||
vshr.u64 d10,d13,#16
|
||||
vst1.64 {q2,q3}, [sp,:256]!
|
||||
vzip.16 d12,d13
|
||||
|
||||
mov r8,r5
|
||||
b LNEON_tail_entry
|
||||
|
||||
.align 4
|
||||
LNEON_tail:
|
||||
vadd.u64 d12,d12,d10
|
||||
vshr.u64 d10,d12,#16
|
||||
vld1.64 {q8,q9}, [r6, :256]!
|
||||
vadd.u64 d13,d13,d10
|
||||
vld1.64 {q10,q11}, [r6, :256]!
|
||||
vshr.u64 d10,d13,#16
|
||||
vld1.64 {q12,q13}, [r6, :256]!
|
||||
vzip.16 d12,d13
|
||||
|
||||
LNEON_tail_entry:
|
||||
vadd.u64 d14,d14,d10
|
||||
vst1.32 {d12[0]}, [r7, :32]!
|
||||
vshr.u64 d10,d14,#16
|
||||
vadd.u64 d15,d15,d10
|
||||
vshr.u64 d10,d15,#16
|
||||
vzip.16 d14,d15
|
||||
vadd.u64 d16,d16,d10
|
||||
vst1.32 {d14[0]}, [r7, :32]!
|
||||
vshr.u64 d10,d16,#16
|
||||
vadd.u64 d17,d17,d10
|
||||
vshr.u64 d10,d17,#16
|
||||
vzip.16 d16,d17
|
||||
vadd.u64 d18,d18,d10
|
||||
vst1.32 {d16[0]}, [r7, :32]!
|
||||
vshr.u64 d10,d18,#16
|
||||
vadd.u64 d19,d19,d10
|
||||
vshr.u64 d10,d19,#16
|
||||
vzip.16 d18,d19
|
||||
vadd.u64 d20,d20,d10
|
||||
vst1.32 {d18[0]}, [r7, :32]!
|
||||
vshr.u64 d10,d20,#16
|
||||
vadd.u64 d21,d21,d10
|
||||
vshr.u64 d10,d21,#16
|
||||
vzip.16 d20,d21
|
||||
vadd.u64 d22,d22,d10
|
||||
vst1.32 {d20[0]}, [r7, :32]!
|
||||
vshr.u64 d10,d22,#16
|
||||
vadd.u64 d23,d23,d10
|
||||
vshr.u64 d10,d23,#16
|
||||
vzip.16 d22,d23
|
||||
vadd.u64 d24,d24,d10
|
||||
vst1.32 {d22[0]}, [r7, :32]!
|
||||
vshr.u64 d10,d24,#16
|
||||
vadd.u64 d25,d25,d10
|
||||
vshr.u64 d10,d25,#16
|
||||
vzip.16 d24,d25
|
||||
vadd.u64 d26,d26,d10
|
||||
vst1.32 {d24[0]}, [r7, :32]!
|
||||
vshr.u64 d10,d26,#16
|
||||
vadd.u64 d27,d27,d10
|
||||
vshr.u64 d10,d27,#16
|
||||
vzip.16 d26,d27
|
||||
vld1.64 {q6,q7}, [r6, :256]!
|
||||
subs r8,r8,#8
|
||||
vst1.32 {d26[0]}, [r7, :32]!
|
||||
bne LNEON_tail
|
||||
|
||||
vst1.32 {d10[0]}, [r7, :32] @ top-most bit
|
||||
sub r3,r3,r5,lsl#2 @ rewind r3
|
||||
subs r1,sp,#0 @ clear carry flag
|
||||
add r2,sp,r5,lsl#2
|
||||
|
||||
LNEON_sub:
|
||||
ldmia r1!, {r4,r5,r6,r7}
|
||||
ldmia r3!, {r8,r9,r10,r11}
|
||||
sbcs r8, r4,r8
|
||||
sbcs r9, r5,r9
|
||||
sbcs r10,r6,r10
|
||||
sbcs r11,r7,r11
|
||||
teq r1,r2 @ preserves carry
|
||||
stmia r0!, {r8,r9,r10,r11}
|
||||
bne LNEON_sub
|
||||
|
||||
ldr r10, [r1] @ load top-most bit
|
||||
mov r11,sp
|
||||
veor q0,q0,q0
|
||||
sub r11,r2,r11 @ this is num*4
|
||||
veor q1,q1,q1
|
||||
mov r1,sp
|
||||
sub r0,r0,r11 @ rewind r0
|
||||
mov r3,r2 @ second 3/4th of frame
|
||||
sbcs r10,r10,#0 @ result is carry flag
|
||||
|
||||
LNEON_copy_n_zap:
|
||||
ldmia r1!, {r4,r5,r6,r7}
|
||||
ldmia r0, {r8,r9,r10,r11}
|
||||
it cc
|
||||
movcc r8, r4
|
||||
vst1.64 {q0,q1}, [r3,:256]! @ wipe
|
||||
itt cc
|
||||
movcc r9, r5
|
||||
movcc r10,r6
|
||||
vst1.64 {q0,q1}, [r3,:256]! @ wipe
|
||||
it cc
|
||||
movcc r11,r7
|
||||
ldmia r1, {r4,r5,r6,r7}
|
||||
stmia r0!, {r8,r9,r10,r11}
|
||||
sub r1,r1,#16
|
||||
ldmia r0, {r8,r9,r10,r11}
|
||||
it cc
|
||||
movcc r8, r4
|
||||
vst1.64 {q0,q1}, [r1,:256]! @ wipe
|
||||
itt cc
|
||||
movcc r9, r5
|
||||
movcc r10,r6
|
||||
vst1.64 {q0,q1}, [r3,:256]! @ wipe
|
||||
it cc
|
||||
movcc r11,r7
|
||||
teq r1,r2 @ preserves carry
|
||||
stmia r0!, {r8,r9,r10,r11}
|
||||
bne LNEON_copy_n_zap
|
||||
|
||||
mov sp,ip
|
||||
vldmia sp!,{d8,d9,d10,d11,d12,d13,d14,d15}
|
||||
ldmia sp!,{r4,r5,r6,r7,r8,r9,r10,r11}
|
||||
bx lr @ bx lr
|
||||
|
||||
#endif
|
||||
.byte 77,111,110,116,103,111,109,101,114,121,32,109,117,108,116,105,112,108,105,99,97,116,105,111,110,32,102,111,114,32,65,82,77,118,52,47,78,69,79,78,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
|
||||
#endif // !OPENSSL_NO_ASM && defined(OPENSSL_ARM) && defined(__APPLE__)
|
||||
#endif // defined(__arm__) && defined(__APPLE__)
|
||||
#if defined(__linux__) && defined(__ELF__)
|
||||
.section .note.GNU-stack,"",%progbits
|
||||
#endif
|
||||
|
||||
@@ -0,0 +1,277 @@
|
||||
/* Copyright (c) 2017, 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. */
|
||||
|
||||
#if !defined(_GNU_SOURCE)
|
||||
#define _GNU_SOURCE // needed for syscall() on Linux.
|
||||
#endif
|
||||
|
||||
#include <CCryptoBoringSSL_crypto.h>
|
||||
|
||||
#include <stdlib.h>
|
||||
#if defined(BORINGSSL_FIPS)
|
||||
#include <sys/mman.h>
|
||||
#include <unistd.h>
|
||||
#endif
|
||||
|
||||
#include <CCryptoBoringSSL_digest.h>
|
||||
#include <CCryptoBoringSSL_hmac.h>
|
||||
#include <CCryptoBoringSSL_sha.h>
|
||||
|
||||
#include "bcm_interface.h"
|
||||
#include "../internal.h"
|
||||
|
||||
// TODO(crbug.com/362530616): When delocate is removed, build these files as
|
||||
// separate compilation units again.
|
||||
#include "aes/aes.c.inc"
|
||||
#include "aes/aes_nohw.c.inc"
|
||||
#include "aes/key_wrap.c.inc"
|
||||
#include "aes/mode_wrappers.c.inc"
|
||||
#include "bn/add.c.inc"
|
||||
#include "bn/asm/x86_64-gcc.c.inc"
|
||||
#include "bn/bn.c.inc"
|
||||
#include "bn/bytes.c.inc"
|
||||
#include "bn/cmp.c.inc"
|
||||
#include "bn/ctx.c.inc"
|
||||
#include "bn/div.c.inc"
|
||||
#include "bn/div_extra.c.inc"
|
||||
#include "bn/exponentiation.c.inc"
|
||||
#include "bn/gcd.c.inc"
|
||||
#include "bn/gcd_extra.c.inc"
|
||||
#include "bn/generic.c.inc"
|
||||
#include "bn/jacobi.c.inc"
|
||||
#include "bn/montgomery.c.inc"
|
||||
#include "bn/montgomery_inv.c.inc"
|
||||
#include "bn/mul.c.inc"
|
||||
#include "bn/prime.c.inc"
|
||||
#include "bn/random.c.inc"
|
||||
#include "bn/rsaz_exp.c.inc"
|
||||
#include "bn/shift.c.inc"
|
||||
#include "bn/sqrt.c.inc"
|
||||
#include "cipher/aead.c.inc"
|
||||
#include "cipher/cipher.c.inc"
|
||||
#include "cipher/e_aes.c.inc"
|
||||
#include "cipher/e_aesccm.c.inc"
|
||||
#include "cmac/cmac.c.inc"
|
||||
#include "dh/check.c.inc"
|
||||
#include "dh/dh.c.inc"
|
||||
#include "digest/digest.c.inc"
|
||||
#include "digest/digests.c.inc"
|
||||
#include "digestsign/digestsign.c.inc"
|
||||
#include "ecdh/ecdh.c.inc"
|
||||
#include "ecdsa/ecdsa.c.inc"
|
||||
#include "ec/ec.c.inc"
|
||||
#include "ec/ec_key.c.inc"
|
||||
#include "ec/ec_montgomery.c.inc"
|
||||
#include "ec/felem.c.inc"
|
||||
#include "ec/oct.c.inc"
|
||||
#include "ec/p224-64.c.inc"
|
||||
#include "ec/p256.c.inc"
|
||||
#include "ec/p256-nistz.c.inc"
|
||||
#include "ec/scalar.c.inc"
|
||||
#include "ec/simple.c.inc"
|
||||
#include "ec/simple_mul.c.inc"
|
||||
#include "ec/util.c.inc"
|
||||
#include "ec/wnaf.c.inc"
|
||||
#include "hkdf/hkdf.c.inc"
|
||||
#include "hmac/hmac.c.inc"
|
||||
#include "modes/cbc.c.inc"
|
||||
#include "modes/cfb.c.inc"
|
||||
#include "modes/ctr.c.inc"
|
||||
#include "modes/gcm.c.inc"
|
||||
#include "modes/gcm_nohw.c.inc"
|
||||
#include "modes/ofb.c.inc"
|
||||
#include "modes/polyval.c.inc"
|
||||
#include "rand/ctrdrbg.c.inc"
|
||||
#include "rand/rand.c.inc"
|
||||
#include "rsa/blinding.c.inc"
|
||||
#include "rsa/padding.c.inc"
|
||||
#include "rsa/rsa.c.inc"
|
||||
#include "rsa/rsa_impl.c.inc"
|
||||
#include "self_check/fips.c.inc"
|
||||
#include "self_check/self_check.c.inc"
|
||||
#include "service_indicator/service_indicator.c.inc"
|
||||
#include "sha/sha1.c.inc"
|
||||
#include "sha/sha256.c.inc"
|
||||
#include "sha/sha512.c.inc"
|
||||
#include "tls/kdf.c.inc"
|
||||
|
||||
|
||||
#if defined(BORINGSSL_FIPS)
|
||||
|
||||
#if !defined(OPENSSL_ASAN)
|
||||
|
||||
// These symbols are filled in by delocate.go (in static builds) or a linker
|
||||
// script (in shared builds). They point to the start and end of the module, and
|
||||
// the location of the integrity hash, respectively.
|
||||
extern const uint8_t BORINGSSL_bcm_text_start[];
|
||||
extern const uint8_t BORINGSSL_bcm_text_end[];
|
||||
extern const uint8_t BORINGSSL_bcm_text_hash[];
|
||||
#if defined(BORINGSSL_SHARED_LIBRARY)
|
||||
extern const uint8_t BORINGSSL_bcm_rodata_start[];
|
||||
extern const uint8_t BORINGSSL_bcm_rodata_end[];
|
||||
#endif
|
||||
|
||||
// assert_within is used to sanity check that certain symbols are within the
|
||||
// bounds of the integrity check. It checks that start <= symbol < end and
|
||||
// aborts otherwise.
|
||||
static void assert_within(const void *start, const void *symbol,
|
||||
const void *end) {
|
||||
const uintptr_t start_val = (uintptr_t) start;
|
||||
const uintptr_t symbol_val = (uintptr_t) symbol;
|
||||
const uintptr_t end_val = (uintptr_t) end;
|
||||
|
||||
if (start_val <= symbol_val && symbol_val < end_val) {
|
||||
return;
|
||||
}
|
||||
|
||||
fprintf(
|
||||
stderr,
|
||||
"FIPS module doesn't span expected symbol. Expected %p <= %p < %p\n",
|
||||
start, symbol, end);
|
||||
BORINGSSL_FIPS_abort();
|
||||
}
|
||||
|
||||
#if defined(OPENSSL_ANDROID) && defined(OPENSSL_AARCH64)
|
||||
static void BORINGSSL_maybe_set_module_text_permissions(int permission) {
|
||||
// Android may be compiled in execute-only-memory mode, in which case the
|
||||
// .text segment cannot be read. That conflicts with the need for a FIPS
|
||||
// module to hash its own contents, therefore |mprotect| is used to make
|
||||
// the module's .text readable for the duration of the hashing process. In
|
||||
// other build configurations this is a no-op.
|
||||
const uintptr_t page_size = getpagesize();
|
||||
const uintptr_t page_start =
|
||||
((uintptr_t)BORINGSSL_bcm_text_start) & ~(page_size - 1);
|
||||
|
||||
if (mprotect((void *)page_start,
|
||||
((uintptr_t)BORINGSSL_bcm_text_end) - page_start,
|
||||
permission) != 0) {
|
||||
perror("BoringSSL: mprotect");
|
||||
}
|
||||
}
|
||||
#else
|
||||
static void BORINGSSL_maybe_set_module_text_permissions(int permission) {}
|
||||
#endif // !ANDROID
|
||||
|
||||
#endif // !ASAN
|
||||
|
||||
static void __attribute__((constructor))
|
||||
BORINGSSL_bcm_power_on_self_test(void) {
|
||||
#if !defined(OPENSSL_ASAN)
|
||||
// Integrity tests cannot run under ASAN because it involves reading the full
|
||||
// .text section, which triggers the global-buffer overflow detection.
|
||||
if (!BORINGSSL_integrity_test()) {
|
||||
goto err;
|
||||
}
|
||||
#endif // OPENSSL_ASAN
|
||||
|
||||
if (!boringssl_self_test_startup()) {
|
||||
goto err;
|
||||
}
|
||||
|
||||
return;
|
||||
|
||||
err:
|
||||
BORINGSSL_FIPS_abort();
|
||||
}
|
||||
|
||||
#if !defined(OPENSSL_ASAN)
|
||||
int BORINGSSL_integrity_test(void) {
|
||||
const uint8_t *const start = BORINGSSL_bcm_text_start;
|
||||
const uint8_t *const end = BORINGSSL_bcm_text_end;
|
||||
|
||||
assert_within(start, AES_encrypt, end);
|
||||
assert_within(start, RSA_sign, end);
|
||||
assert_within(start, BCM_rand_bytes, end);
|
||||
assert_within(start, EC_GROUP_cmp, end);
|
||||
assert_within(start, SHA256_Update, end);
|
||||
assert_within(start, ecdsa_verify_fixed, end);
|
||||
assert_within(start, EVP_AEAD_CTX_seal, end);
|
||||
|
||||
#if defined(BORINGSSL_SHARED_LIBRARY)
|
||||
const uint8_t *const rodata_start = BORINGSSL_bcm_rodata_start;
|
||||
const uint8_t *const rodata_end = BORINGSSL_bcm_rodata_end;
|
||||
#else
|
||||
// In the static build, read-only data is placed within the .text segment.
|
||||
const uint8_t *const rodata_start = BORINGSSL_bcm_text_start;
|
||||
const uint8_t *const rodata_end = BORINGSSL_bcm_text_end;
|
||||
#endif
|
||||
|
||||
assert_within(rodata_start, kPrimes, rodata_end);
|
||||
assert_within(rodata_start, kP256Field, rodata_end);
|
||||
assert_within(rodata_start, kPKCS1SigPrefixes, rodata_end);
|
||||
|
||||
uint8_t result[SHA256_DIGEST_LENGTH];
|
||||
const EVP_MD *const kHashFunction = EVP_sha256();
|
||||
if (!boringssl_self_test_sha256() ||
|
||||
!boringssl_self_test_hmac_sha256()) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
static const uint8_t kHMACKey[64] = {0};
|
||||
unsigned result_len;
|
||||
HMAC_CTX hmac_ctx;
|
||||
HMAC_CTX_init(&hmac_ctx);
|
||||
if (!HMAC_Init_ex(&hmac_ctx, kHMACKey, sizeof(kHMACKey), kHashFunction,
|
||||
NULL /* no ENGINE */)) {
|
||||
fprintf(stderr, "HMAC_Init_ex failed.\n");
|
||||
return 0;
|
||||
}
|
||||
|
||||
BORINGSSL_maybe_set_module_text_permissions(PROT_READ | PROT_EXEC);
|
||||
#if defined(BORINGSSL_SHARED_LIBRARY)
|
||||
uint64_t length = end - start;
|
||||
HMAC_Update(&hmac_ctx, (const uint8_t *) &length, sizeof(length));
|
||||
HMAC_Update(&hmac_ctx, start, length);
|
||||
|
||||
length = rodata_end - rodata_start;
|
||||
HMAC_Update(&hmac_ctx, (const uint8_t *) &length, sizeof(length));
|
||||
HMAC_Update(&hmac_ctx, rodata_start, length);
|
||||
#else
|
||||
HMAC_Update(&hmac_ctx, start, end - start);
|
||||
#endif
|
||||
BORINGSSL_maybe_set_module_text_permissions(PROT_EXEC);
|
||||
|
||||
if (!HMAC_Final(&hmac_ctx, result, &result_len) ||
|
||||
result_len != sizeof(result)) {
|
||||
fprintf(stderr, "HMAC failed.\n");
|
||||
return 0;
|
||||
}
|
||||
HMAC_CTX_cleanse(&hmac_ctx); // FIPS 140-3, AS05.10.
|
||||
|
||||
const uint8_t *expected = BORINGSSL_bcm_text_hash;
|
||||
|
||||
if (!check_test(expected, result, sizeof(result), "FIPS integrity test")) {
|
||||
#if !defined(BORINGSSL_FIPS_BREAK_TESTS)
|
||||
return 0;
|
||||
#endif
|
||||
}
|
||||
|
||||
OPENSSL_cleanse(result, sizeof(result)); // FIPS 140-3, AS05.10.
|
||||
return 1;
|
||||
}
|
||||
|
||||
const uint8_t* FIPS_module_hash(void) {
|
||||
return BORINGSSL_bcm_text_hash;
|
||||
}
|
||||
|
||||
#endif // OPENSSL_ASAN
|
||||
|
||||
void BORINGSSL_FIPS_abort(void) {
|
||||
for (;;) {
|
||||
abort();
|
||||
exit(1);
|
||||
}
|
||||
}
|
||||
|
||||
#endif // BORINGSSL_FIPS
|
||||
@@ -0,0 +1,132 @@
|
||||
/* Copyright (c) 2024, 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_CRYPTO_BCM_INTERFACE_H
|
||||
#define OPENSSL_HEADER_CRYPTO_BCM_INTERFACE_H
|
||||
|
||||
#include <CCryptoBoringSSL_bcm_public.h>
|
||||
|
||||
// This header will eventually become the interface between BCM and the
|
||||
// rest of libcrypto. More cleanly separating the two is still a work in
|
||||
// progress (see https://crbug.com/boringssl/722) so, at the moment, we
|
||||
// consider this no different from any other header in BCM.
|
||||
//
|
||||
// Over time, calls from libcrypto to BCM will all move to this header
|
||||
// and the separation will become more meaningful.
|
||||
|
||||
#if defined(__cplusplus)
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
// Enumerated types for return values from bcm functions, both infallible
|
||||
// and fallible functions. Two success values are used to correspond to the
|
||||
// FIPS service indicator. For the moment, the official service indicator
|
||||
// remains the counter, not these values. Once we fully transition to
|
||||
// these return values from bcm we will change that.
|
||||
enum bcm_infallible_t {
|
||||
bcm_infallible_approved,
|
||||
bcm_infallible_not_approved,
|
||||
};
|
||||
|
||||
enum bcm_status_t {
|
||||
bcm_status_approved,
|
||||
bcm_status_not_approved,
|
||||
|
||||
// Failure codes, which must all be negative.
|
||||
bcm_status_failure,
|
||||
};
|
||||
typedef enum bcm_status_t bcm_status;
|
||||
typedef enum bcm_infallible_t bcm_infallible;
|
||||
|
||||
OPENSSL_INLINE int bcm_success(bcm_status status) {
|
||||
return status == bcm_status_approved || status == bcm_status_not_approved;
|
||||
}
|
||||
|
||||
|
||||
// Random number generator.
|
||||
|
||||
#if defined(BORINGSSL_FIPS)
|
||||
|
||||
// We overread from /dev/urandom or RDRAND by a factor of 10 and XOR to whiten.
|
||||
// TODO(bbe): disentangle this value which is used to calculate the size of the
|
||||
// stack buffer in RAND_need entropy based on a calculation.
|
||||
#define BORINGSSL_FIPS_OVERREAD 10
|
||||
|
||||
#endif // BORINGSSL_FIPS
|
||||
|
||||
// BCM_rand_load_entropy supplies |entropy_len| bytes of entropy to the BCM
|
||||
// module. The |want_additional_input| parameter is true iff the entropy was
|
||||
// obtained from a source other than the system, e.g. directly from the CPU.
|
||||
bcm_infallible BCM_rand_load_entropy(const uint8_t *entropy, size_t entropy_len,
|
||||
int want_additional_input);
|
||||
|
||||
// BCM_rand_bytes is the same as the public |RAND_bytes| function, other
|
||||
// than returning a bcm_infallible status indicator.
|
||||
OPENSSL_EXPORT bcm_infallible BCM_rand_bytes(uint8_t *out, size_t out_len);
|
||||
|
||||
// BCM_rand_bytes_hwrng attempts to fill |out| with |len| bytes of entropy from
|
||||
// the CPU hardware random number generator if one is present.
|
||||
// bcm_status_approved is returned on success, and a failure status is
|
||||
// returned otherwise.
|
||||
bcm_status BCM_rand_bytes_hwrng(uint8_t *out, size_t len);
|
||||
|
||||
// BCM_rand_bytes_with_additional_data samples from the RNG after mixing 32
|
||||
// bytes from |user_additional_data| in.
|
||||
bcm_infallible BCM_rand_bytes_with_additional_data(
|
||||
uint8_t *out, size_t out_len, const uint8_t user_additional_data[32]);
|
||||
|
||||
|
||||
// SHA-1
|
||||
|
||||
// BCM_SHA_DIGEST_LENGTH is the length of a SHA-1 digest.
|
||||
#define BCM_SHA_DIGEST_LENGTH 20
|
||||
|
||||
// BCM_sha1_init initialises |sha|.
|
||||
bcm_infallible BCM_sha1_init(SHA_CTX *sha);
|
||||
|
||||
// BCM_SHA1_transform is a low-level function that performs a single, SHA-1
|
||||
// block transformation using the state from |sha| and |SHA_CBLOCK| bytes from
|
||||
// |block|.
|
||||
bcm_infallible BCM_sha1_transform(SHA_CTX *c, const uint8_t data[BCM_SHA_CBLOCK]);
|
||||
|
||||
// BCM_sha1_update adds |len| bytes from |data| to |sha|.
|
||||
bcm_infallible BCM_sha1_update(SHA_CTX *c, const void *data, size_t len);
|
||||
|
||||
// BCM_sha1_final adds the final padding to |sha| and writes the resulting
|
||||
// digest to |out|, which must have at least |SHA_DIGEST_LENGTH| bytes of space.
|
||||
bcm_infallible BCM_sha1_final(uint8_t out[BCM_SHA_DIGEST_LENGTH], SHA_CTX *c);
|
||||
|
||||
|
||||
// BCM_fips_186_2_prf derives |out_len| bytes from |xkey| using the PRF
|
||||
// defined in FIPS 186-2, Appendix 3.1, with change notice 1 applied. The b
|
||||
// parameter is 160 and seed, XKEY, is also 160 bits. The optional XSEED user
|
||||
// input is all zeros.
|
||||
//
|
||||
// The PRF generates a sequence of 320-bit numbers. Each number is encoded as a
|
||||
// 40-byte string in big-endian and then concatenated to form |out|. If
|
||||
// |out_len| is not a multiple of 40, the result is truncated. This matches the
|
||||
// construction used in Section 7 of RFC 4186 and Section 7 of RFC 4187.
|
||||
//
|
||||
// This PRF is based on SHA-1, a weak hash function, and should not be used
|
||||
// in new protocols. It is provided for compatibility with some legacy EAP
|
||||
// methods.
|
||||
bcm_infallible BCM_fips_186_2_prf(uint8_t *out, size_t out_len,
|
||||
const uint8_t xkey[BCM_SHA_DIGEST_LENGTH]);
|
||||
|
||||
|
||||
#if defined(__cplusplus)
|
||||
} // extern C
|
||||
#endif
|
||||
|
||||
#endif // OPENSSL_HEADER_CRYPTO_BCM_INTERFACE_H
|
||||
@@ -1,989 +0,0 @@
|
||||
#define BORINGSSL_PREFIX CCryptoBoringSSL
|
||||
#if defined(__i386__) && defined(_WIN32)
|
||||
; This file is generated from a similarly-named Perl script in the BoringSSL
|
||||
; source tree. Do not edit by hand.
|
||||
|
||||
%ifdef BORINGSSL_PREFIX
|
||||
%include "boringssl_prefix_symbols_nasm.inc"
|
||||
%endif
|
||||
%ifidn __OUTPUT_FORMAT__, win32
|
||||
%ifidn __OUTPUT_FORMAT__,obj
|
||||
section code use32 class=code align=64
|
||||
%elifidn __OUTPUT_FORMAT__,win32
|
||||
$@feat.00 equ 1
|
||||
section .text code align=64
|
||||
%else
|
||||
section .text code
|
||||
%endif
|
||||
;extern _OPENSSL_ia32cap_P
|
||||
global _bn_mul_add_words
|
||||
align 16
|
||||
_bn_mul_add_words:
|
||||
L$_bn_mul_add_words_begin:
|
||||
lea eax,[_OPENSSL_ia32cap_P]
|
||||
bt DWORD [eax],26
|
||||
jnc NEAR L$000maw_non_sse2
|
||||
mov eax,DWORD [4+esp]
|
||||
mov edx,DWORD [8+esp]
|
||||
mov ecx,DWORD [12+esp]
|
||||
movd mm0,DWORD [16+esp]
|
||||
pxor mm1,mm1
|
||||
jmp NEAR L$001maw_sse2_entry
|
||||
align 16
|
||||
L$002maw_sse2_unrolled:
|
||||
movd mm3,DWORD [eax]
|
||||
paddq mm1,mm3
|
||||
movd mm2,DWORD [edx]
|
||||
pmuludq mm2,mm0
|
||||
movd mm4,DWORD [4+edx]
|
||||
pmuludq mm4,mm0
|
||||
movd mm6,DWORD [8+edx]
|
||||
pmuludq mm6,mm0
|
||||
movd mm7,DWORD [12+edx]
|
||||
pmuludq mm7,mm0
|
||||
paddq mm1,mm2
|
||||
movd mm3,DWORD [4+eax]
|
||||
paddq mm3,mm4
|
||||
movd mm5,DWORD [8+eax]
|
||||
paddq mm5,mm6
|
||||
movd mm4,DWORD [12+eax]
|
||||
paddq mm7,mm4
|
||||
movd DWORD [eax],mm1
|
||||
movd mm2,DWORD [16+edx]
|
||||
pmuludq mm2,mm0
|
||||
psrlq mm1,32
|
||||
movd mm4,DWORD [20+edx]
|
||||
pmuludq mm4,mm0
|
||||
paddq mm1,mm3
|
||||
movd mm6,DWORD [24+edx]
|
||||
pmuludq mm6,mm0
|
||||
movd DWORD [4+eax],mm1
|
||||
psrlq mm1,32
|
||||
movd mm3,DWORD [28+edx]
|
||||
add edx,32
|
||||
pmuludq mm3,mm0
|
||||
paddq mm1,mm5
|
||||
movd mm5,DWORD [16+eax]
|
||||
paddq mm2,mm5
|
||||
movd DWORD [8+eax],mm1
|
||||
psrlq mm1,32
|
||||
paddq mm1,mm7
|
||||
movd mm5,DWORD [20+eax]
|
||||
paddq mm4,mm5
|
||||
movd DWORD [12+eax],mm1
|
||||
psrlq mm1,32
|
||||
paddq mm1,mm2
|
||||
movd mm5,DWORD [24+eax]
|
||||
paddq mm6,mm5
|
||||
movd DWORD [16+eax],mm1
|
||||
psrlq mm1,32
|
||||
paddq mm1,mm4
|
||||
movd mm5,DWORD [28+eax]
|
||||
paddq mm3,mm5
|
||||
movd DWORD [20+eax],mm1
|
||||
psrlq mm1,32
|
||||
paddq mm1,mm6
|
||||
movd DWORD [24+eax],mm1
|
||||
psrlq mm1,32
|
||||
paddq mm1,mm3
|
||||
movd DWORD [28+eax],mm1
|
||||
lea eax,[32+eax]
|
||||
psrlq mm1,32
|
||||
sub ecx,8
|
||||
jz NEAR L$003maw_sse2_exit
|
||||
L$001maw_sse2_entry:
|
||||
test ecx,4294967288
|
||||
jnz NEAR L$002maw_sse2_unrolled
|
||||
align 4
|
||||
L$004maw_sse2_loop:
|
||||
movd mm2,DWORD [edx]
|
||||
movd mm3,DWORD [eax]
|
||||
pmuludq mm2,mm0
|
||||
lea edx,[4+edx]
|
||||
paddq mm1,mm3
|
||||
paddq mm1,mm2
|
||||
movd DWORD [eax],mm1
|
||||
sub ecx,1
|
||||
psrlq mm1,32
|
||||
lea eax,[4+eax]
|
||||
jnz NEAR L$004maw_sse2_loop
|
||||
L$003maw_sse2_exit:
|
||||
movd eax,mm1
|
||||
emms
|
||||
ret
|
||||
align 16
|
||||
L$000maw_non_sse2:
|
||||
push ebp
|
||||
push ebx
|
||||
push esi
|
||||
push edi
|
||||
;
|
||||
xor esi,esi
|
||||
mov edi,DWORD [20+esp]
|
||||
mov ecx,DWORD [28+esp]
|
||||
mov ebx,DWORD [24+esp]
|
||||
and ecx,4294967288
|
||||
mov ebp,DWORD [32+esp]
|
||||
push ecx
|
||||
jz NEAR L$005maw_finish
|
||||
align 16
|
||||
L$006maw_loop:
|
||||
; Round 0
|
||||
mov eax,DWORD [ebx]
|
||||
mul ebp
|
||||
add eax,esi
|
||||
adc edx,0
|
||||
add eax,DWORD [edi]
|
||||
adc edx,0
|
||||
mov DWORD [edi],eax
|
||||
mov esi,edx
|
||||
; Round 4
|
||||
mov eax,DWORD [4+ebx]
|
||||
mul ebp
|
||||
add eax,esi
|
||||
adc edx,0
|
||||
add eax,DWORD [4+edi]
|
||||
adc edx,0
|
||||
mov DWORD [4+edi],eax
|
||||
mov esi,edx
|
||||
; Round 8
|
||||
mov eax,DWORD [8+ebx]
|
||||
mul ebp
|
||||
add eax,esi
|
||||
adc edx,0
|
||||
add eax,DWORD [8+edi]
|
||||
adc edx,0
|
||||
mov DWORD [8+edi],eax
|
||||
mov esi,edx
|
||||
; Round 12
|
||||
mov eax,DWORD [12+ebx]
|
||||
mul ebp
|
||||
add eax,esi
|
||||
adc edx,0
|
||||
add eax,DWORD [12+edi]
|
||||
adc edx,0
|
||||
mov DWORD [12+edi],eax
|
||||
mov esi,edx
|
||||
; Round 16
|
||||
mov eax,DWORD [16+ebx]
|
||||
mul ebp
|
||||
add eax,esi
|
||||
adc edx,0
|
||||
add eax,DWORD [16+edi]
|
||||
adc edx,0
|
||||
mov DWORD [16+edi],eax
|
||||
mov esi,edx
|
||||
; Round 20
|
||||
mov eax,DWORD [20+ebx]
|
||||
mul ebp
|
||||
add eax,esi
|
||||
adc edx,0
|
||||
add eax,DWORD [20+edi]
|
||||
adc edx,0
|
||||
mov DWORD [20+edi],eax
|
||||
mov esi,edx
|
||||
; Round 24
|
||||
mov eax,DWORD [24+ebx]
|
||||
mul ebp
|
||||
add eax,esi
|
||||
adc edx,0
|
||||
add eax,DWORD [24+edi]
|
||||
adc edx,0
|
||||
mov DWORD [24+edi],eax
|
||||
mov esi,edx
|
||||
; Round 28
|
||||
mov eax,DWORD [28+ebx]
|
||||
mul ebp
|
||||
add eax,esi
|
||||
adc edx,0
|
||||
add eax,DWORD [28+edi]
|
||||
adc edx,0
|
||||
mov DWORD [28+edi],eax
|
||||
mov esi,edx
|
||||
;
|
||||
sub ecx,8
|
||||
lea ebx,[32+ebx]
|
||||
lea edi,[32+edi]
|
||||
jnz NEAR L$006maw_loop
|
||||
L$005maw_finish:
|
||||
mov ecx,DWORD [32+esp]
|
||||
and ecx,7
|
||||
jnz NEAR L$007maw_finish2
|
||||
jmp NEAR L$008maw_end
|
||||
L$007maw_finish2:
|
||||
; Tail Round 0
|
||||
mov eax,DWORD [ebx]
|
||||
mul ebp
|
||||
add eax,esi
|
||||
adc edx,0
|
||||
add eax,DWORD [edi]
|
||||
adc edx,0
|
||||
dec ecx
|
||||
mov DWORD [edi],eax
|
||||
mov esi,edx
|
||||
jz NEAR L$008maw_end
|
||||
; Tail Round 1
|
||||
mov eax,DWORD [4+ebx]
|
||||
mul ebp
|
||||
add eax,esi
|
||||
adc edx,0
|
||||
add eax,DWORD [4+edi]
|
||||
adc edx,0
|
||||
dec ecx
|
||||
mov DWORD [4+edi],eax
|
||||
mov esi,edx
|
||||
jz NEAR L$008maw_end
|
||||
; Tail Round 2
|
||||
mov eax,DWORD [8+ebx]
|
||||
mul ebp
|
||||
add eax,esi
|
||||
adc edx,0
|
||||
add eax,DWORD [8+edi]
|
||||
adc edx,0
|
||||
dec ecx
|
||||
mov DWORD [8+edi],eax
|
||||
mov esi,edx
|
||||
jz NEAR L$008maw_end
|
||||
; Tail Round 3
|
||||
mov eax,DWORD [12+ebx]
|
||||
mul ebp
|
||||
add eax,esi
|
||||
adc edx,0
|
||||
add eax,DWORD [12+edi]
|
||||
adc edx,0
|
||||
dec ecx
|
||||
mov DWORD [12+edi],eax
|
||||
mov esi,edx
|
||||
jz NEAR L$008maw_end
|
||||
; Tail Round 4
|
||||
mov eax,DWORD [16+ebx]
|
||||
mul ebp
|
||||
add eax,esi
|
||||
adc edx,0
|
||||
add eax,DWORD [16+edi]
|
||||
adc edx,0
|
||||
dec ecx
|
||||
mov DWORD [16+edi],eax
|
||||
mov esi,edx
|
||||
jz NEAR L$008maw_end
|
||||
; Tail Round 5
|
||||
mov eax,DWORD [20+ebx]
|
||||
mul ebp
|
||||
add eax,esi
|
||||
adc edx,0
|
||||
add eax,DWORD [20+edi]
|
||||
adc edx,0
|
||||
dec ecx
|
||||
mov DWORD [20+edi],eax
|
||||
mov esi,edx
|
||||
jz NEAR L$008maw_end
|
||||
; Tail Round 6
|
||||
mov eax,DWORD [24+ebx]
|
||||
mul ebp
|
||||
add eax,esi
|
||||
adc edx,0
|
||||
add eax,DWORD [24+edi]
|
||||
adc edx,0
|
||||
mov DWORD [24+edi],eax
|
||||
mov esi,edx
|
||||
L$008maw_end:
|
||||
mov eax,esi
|
||||
pop ecx
|
||||
pop edi
|
||||
pop esi
|
||||
pop ebx
|
||||
pop ebp
|
||||
ret
|
||||
global _bn_mul_words
|
||||
align 16
|
||||
_bn_mul_words:
|
||||
L$_bn_mul_words_begin:
|
||||
lea eax,[_OPENSSL_ia32cap_P]
|
||||
bt DWORD [eax],26
|
||||
jnc NEAR L$009mw_non_sse2
|
||||
mov eax,DWORD [4+esp]
|
||||
mov edx,DWORD [8+esp]
|
||||
mov ecx,DWORD [12+esp]
|
||||
movd mm0,DWORD [16+esp]
|
||||
pxor mm1,mm1
|
||||
align 16
|
||||
L$010mw_sse2_loop:
|
||||
movd mm2,DWORD [edx]
|
||||
pmuludq mm2,mm0
|
||||
lea edx,[4+edx]
|
||||
paddq mm1,mm2
|
||||
movd DWORD [eax],mm1
|
||||
sub ecx,1
|
||||
psrlq mm1,32
|
||||
lea eax,[4+eax]
|
||||
jnz NEAR L$010mw_sse2_loop
|
||||
movd eax,mm1
|
||||
emms
|
||||
ret
|
||||
align 16
|
||||
L$009mw_non_sse2:
|
||||
push ebp
|
||||
push ebx
|
||||
push esi
|
||||
push edi
|
||||
;
|
||||
xor esi,esi
|
||||
mov edi,DWORD [20+esp]
|
||||
mov ebx,DWORD [24+esp]
|
||||
mov ebp,DWORD [28+esp]
|
||||
mov ecx,DWORD [32+esp]
|
||||
and ebp,4294967288
|
||||
jz NEAR L$011mw_finish
|
||||
L$012mw_loop:
|
||||
; Round 0
|
||||
mov eax,DWORD [ebx]
|
||||
mul ecx
|
||||
add eax,esi
|
||||
adc edx,0
|
||||
mov DWORD [edi],eax
|
||||
mov esi,edx
|
||||
; Round 4
|
||||
mov eax,DWORD [4+ebx]
|
||||
mul ecx
|
||||
add eax,esi
|
||||
adc edx,0
|
||||
mov DWORD [4+edi],eax
|
||||
mov esi,edx
|
||||
; Round 8
|
||||
mov eax,DWORD [8+ebx]
|
||||
mul ecx
|
||||
add eax,esi
|
||||
adc edx,0
|
||||
mov DWORD [8+edi],eax
|
||||
mov esi,edx
|
||||
; Round 12
|
||||
mov eax,DWORD [12+ebx]
|
||||
mul ecx
|
||||
add eax,esi
|
||||
adc edx,0
|
||||
mov DWORD [12+edi],eax
|
||||
mov esi,edx
|
||||
; Round 16
|
||||
mov eax,DWORD [16+ebx]
|
||||
mul ecx
|
||||
add eax,esi
|
||||
adc edx,0
|
||||
mov DWORD [16+edi],eax
|
||||
mov esi,edx
|
||||
; Round 20
|
||||
mov eax,DWORD [20+ebx]
|
||||
mul ecx
|
||||
add eax,esi
|
||||
adc edx,0
|
||||
mov DWORD [20+edi],eax
|
||||
mov esi,edx
|
||||
; Round 24
|
||||
mov eax,DWORD [24+ebx]
|
||||
mul ecx
|
||||
add eax,esi
|
||||
adc edx,0
|
||||
mov DWORD [24+edi],eax
|
||||
mov esi,edx
|
||||
; Round 28
|
||||
mov eax,DWORD [28+ebx]
|
||||
mul ecx
|
||||
add eax,esi
|
||||
adc edx,0
|
||||
mov DWORD [28+edi],eax
|
||||
mov esi,edx
|
||||
;
|
||||
add ebx,32
|
||||
add edi,32
|
||||
sub ebp,8
|
||||
jz NEAR L$011mw_finish
|
||||
jmp NEAR L$012mw_loop
|
||||
L$011mw_finish:
|
||||
mov ebp,DWORD [28+esp]
|
||||
and ebp,7
|
||||
jnz NEAR L$013mw_finish2
|
||||
jmp NEAR L$014mw_end
|
||||
L$013mw_finish2:
|
||||
; Tail Round 0
|
||||
mov eax,DWORD [ebx]
|
||||
mul ecx
|
||||
add eax,esi
|
||||
adc edx,0
|
||||
mov DWORD [edi],eax
|
||||
mov esi,edx
|
||||
dec ebp
|
||||
jz NEAR L$014mw_end
|
||||
; Tail Round 1
|
||||
mov eax,DWORD [4+ebx]
|
||||
mul ecx
|
||||
add eax,esi
|
||||
adc edx,0
|
||||
mov DWORD [4+edi],eax
|
||||
mov esi,edx
|
||||
dec ebp
|
||||
jz NEAR L$014mw_end
|
||||
; Tail Round 2
|
||||
mov eax,DWORD [8+ebx]
|
||||
mul ecx
|
||||
add eax,esi
|
||||
adc edx,0
|
||||
mov DWORD [8+edi],eax
|
||||
mov esi,edx
|
||||
dec ebp
|
||||
jz NEAR L$014mw_end
|
||||
; Tail Round 3
|
||||
mov eax,DWORD [12+ebx]
|
||||
mul ecx
|
||||
add eax,esi
|
||||
adc edx,0
|
||||
mov DWORD [12+edi],eax
|
||||
mov esi,edx
|
||||
dec ebp
|
||||
jz NEAR L$014mw_end
|
||||
; Tail Round 4
|
||||
mov eax,DWORD [16+ebx]
|
||||
mul ecx
|
||||
add eax,esi
|
||||
adc edx,0
|
||||
mov DWORD [16+edi],eax
|
||||
mov esi,edx
|
||||
dec ebp
|
||||
jz NEAR L$014mw_end
|
||||
; Tail Round 5
|
||||
mov eax,DWORD [20+ebx]
|
||||
mul ecx
|
||||
add eax,esi
|
||||
adc edx,0
|
||||
mov DWORD [20+edi],eax
|
||||
mov esi,edx
|
||||
dec ebp
|
||||
jz NEAR L$014mw_end
|
||||
; Tail Round 6
|
||||
mov eax,DWORD [24+ebx]
|
||||
mul ecx
|
||||
add eax,esi
|
||||
adc edx,0
|
||||
mov DWORD [24+edi],eax
|
||||
mov esi,edx
|
||||
L$014mw_end:
|
||||
mov eax,esi
|
||||
pop edi
|
||||
pop esi
|
||||
pop ebx
|
||||
pop ebp
|
||||
ret
|
||||
global _bn_sqr_words
|
||||
align 16
|
||||
_bn_sqr_words:
|
||||
L$_bn_sqr_words_begin:
|
||||
lea eax,[_OPENSSL_ia32cap_P]
|
||||
bt DWORD [eax],26
|
||||
jnc NEAR L$015sqr_non_sse2
|
||||
mov eax,DWORD [4+esp]
|
||||
mov edx,DWORD [8+esp]
|
||||
mov ecx,DWORD [12+esp]
|
||||
align 16
|
||||
L$016sqr_sse2_loop:
|
||||
movd mm0,DWORD [edx]
|
||||
pmuludq mm0,mm0
|
||||
lea edx,[4+edx]
|
||||
movq [eax],mm0
|
||||
sub ecx,1
|
||||
lea eax,[8+eax]
|
||||
jnz NEAR L$016sqr_sse2_loop
|
||||
emms
|
||||
ret
|
||||
align 16
|
||||
L$015sqr_non_sse2:
|
||||
push ebp
|
||||
push ebx
|
||||
push esi
|
||||
push edi
|
||||
;
|
||||
mov esi,DWORD [20+esp]
|
||||
mov edi,DWORD [24+esp]
|
||||
mov ebx,DWORD [28+esp]
|
||||
and ebx,4294967288
|
||||
jz NEAR L$017sw_finish
|
||||
L$018sw_loop:
|
||||
; Round 0
|
||||
mov eax,DWORD [edi]
|
||||
mul eax
|
||||
mov DWORD [esi],eax
|
||||
mov DWORD [4+esi],edx
|
||||
; Round 4
|
||||
mov eax,DWORD [4+edi]
|
||||
mul eax
|
||||
mov DWORD [8+esi],eax
|
||||
mov DWORD [12+esi],edx
|
||||
; Round 8
|
||||
mov eax,DWORD [8+edi]
|
||||
mul eax
|
||||
mov DWORD [16+esi],eax
|
||||
mov DWORD [20+esi],edx
|
||||
; Round 12
|
||||
mov eax,DWORD [12+edi]
|
||||
mul eax
|
||||
mov DWORD [24+esi],eax
|
||||
mov DWORD [28+esi],edx
|
||||
; Round 16
|
||||
mov eax,DWORD [16+edi]
|
||||
mul eax
|
||||
mov DWORD [32+esi],eax
|
||||
mov DWORD [36+esi],edx
|
||||
; Round 20
|
||||
mov eax,DWORD [20+edi]
|
||||
mul eax
|
||||
mov DWORD [40+esi],eax
|
||||
mov DWORD [44+esi],edx
|
||||
; Round 24
|
||||
mov eax,DWORD [24+edi]
|
||||
mul eax
|
||||
mov DWORD [48+esi],eax
|
||||
mov DWORD [52+esi],edx
|
||||
; Round 28
|
||||
mov eax,DWORD [28+edi]
|
||||
mul eax
|
||||
mov DWORD [56+esi],eax
|
||||
mov DWORD [60+esi],edx
|
||||
;
|
||||
add edi,32
|
||||
add esi,64
|
||||
sub ebx,8
|
||||
jnz NEAR L$018sw_loop
|
||||
L$017sw_finish:
|
||||
mov ebx,DWORD [28+esp]
|
||||
and ebx,7
|
||||
jz NEAR L$019sw_end
|
||||
; Tail Round 0
|
||||
mov eax,DWORD [edi]
|
||||
mul eax
|
||||
mov DWORD [esi],eax
|
||||
dec ebx
|
||||
mov DWORD [4+esi],edx
|
||||
jz NEAR L$019sw_end
|
||||
; Tail Round 1
|
||||
mov eax,DWORD [4+edi]
|
||||
mul eax
|
||||
mov DWORD [8+esi],eax
|
||||
dec ebx
|
||||
mov DWORD [12+esi],edx
|
||||
jz NEAR L$019sw_end
|
||||
; Tail Round 2
|
||||
mov eax,DWORD [8+edi]
|
||||
mul eax
|
||||
mov DWORD [16+esi],eax
|
||||
dec ebx
|
||||
mov DWORD [20+esi],edx
|
||||
jz NEAR L$019sw_end
|
||||
; Tail Round 3
|
||||
mov eax,DWORD [12+edi]
|
||||
mul eax
|
||||
mov DWORD [24+esi],eax
|
||||
dec ebx
|
||||
mov DWORD [28+esi],edx
|
||||
jz NEAR L$019sw_end
|
||||
; Tail Round 4
|
||||
mov eax,DWORD [16+edi]
|
||||
mul eax
|
||||
mov DWORD [32+esi],eax
|
||||
dec ebx
|
||||
mov DWORD [36+esi],edx
|
||||
jz NEAR L$019sw_end
|
||||
; Tail Round 5
|
||||
mov eax,DWORD [20+edi]
|
||||
mul eax
|
||||
mov DWORD [40+esi],eax
|
||||
dec ebx
|
||||
mov DWORD [44+esi],edx
|
||||
jz NEAR L$019sw_end
|
||||
; Tail Round 6
|
||||
mov eax,DWORD [24+edi]
|
||||
mul eax
|
||||
mov DWORD [48+esi],eax
|
||||
mov DWORD [52+esi],edx
|
||||
L$019sw_end:
|
||||
pop edi
|
||||
pop esi
|
||||
pop ebx
|
||||
pop ebp
|
||||
ret
|
||||
global _bn_div_words
|
||||
align 16
|
||||
_bn_div_words:
|
||||
L$_bn_div_words_begin:
|
||||
mov edx,DWORD [4+esp]
|
||||
mov eax,DWORD [8+esp]
|
||||
mov ecx,DWORD [12+esp]
|
||||
div ecx
|
||||
ret
|
||||
global _bn_add_words
|
||||
align 16
|
||||
_bn_add_words:
|
||||
L$_bn_add_words_begin:
|
||||
push ebp
|
||||
push ebx
|
||||
push esi
|
||||
push edi
|
||||
;
|
||||
mov ebx,DWORD [20+esp]
|
||||
mov esi,DWORD [24+esp]
|
||||
mov edi,DWORD [28+esp]
|
||||
mov ebp,DWORD [32+esp]
|
||||
xor eax,eax
|
||||
and ebp,4294967288
|
||||
jz NEAR L$020aw_finish
|
||||
L$021aw_loop:
|
||||
; Round 0
|
||||
mov ecx,DWORD [esi]
|
||||
mov edx,DWORD [edi]
|
||||
add ecx,eax
|
||||
mov eax,0
|
||||
adc eax,eax
|
||||
add ecx,edx
|
||||
adc eax,0
|
||||
mov DWORD [ebx],ecx
|
||||
; Round 1
|
||||
mov ecx,DWORD [4+esi]
|
||||
mov edx,DWORD [4+edi]
|
||||
add ecx,eax
|
||||
mov eax,0
|
||||
adc eax,eax
|
||||
add ecx,edx
|
||||
adc eax,0
|
||||
mov DWORD [4+ebx],ecx
|
||||
; Round 2
|
||||
mov ecx,DWORD [8+esi]
|
||||
mov edx,DWORD [8+edi]
|
||||
add ecx,eax
|
||||
mov eax,0
|
||||
adc eax,eax
|
||||
add ecx,edx
|
||||
adc eax,0
|
||||
mov DWORD [8+ebx],ecx
|
||||
; Round 3
|
||||
mov ecx,DWORD [12+esi]
|
||||
mov edx,DWORD [12+edi]
|
||||
add ecx,eax
|
||||
mov eax,0
|
||||
adc eax,eax
|
||||
add ecx,edx
|
||||
adc eax,0
|
||||
mov DWORD [12+ebx],ecx
|
||||
; Round 4
|
||||
mov ecx,DWORD [16+esi]
|
||||
mov edx,DWORD [16+edi]
|
||||
add ecx,eax
|
||||
mov eax,0
|
||||
adc eax,eax
|
||||
add ecx,edx
|
||||
adc eax,0
|
||||
mov DWORD [16+ebx],ecx
|
||||
; Round 5
|
||||
mov ecx,DWORD [20+esi]
|
||||
mov edx,DWORD [20+edi]
|
||||
add ecx,eax
|
||||
mov eax,0
|
||||
adc eax,eax
|
||||
add ecx,edx
|
||||
adc eax,0
|
||||
mov DWORD [20+ebx],ecx
|
||||
; Round 6
|
||||
mov ecx,DWORD [24+esi]
|
||||
mov edx,DWORD [24+edi]
|
||||
add ecx,eax
|
||||
mov eax,0
|
||||
adc eax,eax
|
||||
add ecx,edx
|
||||
adc eax,0
|
||||
mov DWORD [24+ebx],ecx
|
||||
; Round 7
|
||||
mov ecx,DWORD [28+esi]
|
||||
mov edx,DWORD [28+edi]
|
||||
add ecx,eax
|
||||
mov eax,0
|
||||
adc eax,eax
|
||||
add ecx,edx
|
||||
adc eax,0
|
||||
mov DWORD [28+ebx],ecx
|
||||
;
|
||||
add esi,32
|
||||
add edi,32
|
||||
add ebx,32
|
||||
sub ebp,8
|
||||
jnz NEAR L$021aw_loop
|
||||
L$020aw_finish:
|
||||
mov ebp,DWORD [32+esp]
|
||||
and ebp,7
|
||||
jz NEAR L$022aw_end
|
||||
; Tail Round 0
|
||||
mov ecx,DWORD [esi]
|
||||
mov edx,DWORD [edi]
|
||||
add ecx,eax
|
||||
mov eax,0
|
||||
adc eax,eax
|
||||
add ecx,edx
|
||||
adc eax,0
|
||||
dec ebp
|
||||
mov DWORD [ebx],ecx
|
||||
jz NEAR L$022aw_end
|
||||
; Tail Round 1
|
||||
mov ecx,DWORD [4+esi]
|
||||
mov edx,DWORD [4+edi]
|
||||
add ecx,eax
|
||||
mov eax,0
|
||||
adc eax,eax
|
||||
add ecx,edx
|
||||
adc eax,0
|
||||
dec ebp
|
||||
mov DWORD [4+ebx],ecx
|
||||
jz NEAR L$022aw_end
|
||||
; Tail Round 2
|
||||
mov ecx,DWORD [8+esi]
|
||||
mov edx,DWORD [8+edi]
|
||||
add ecx,eax
|
||||
mov eax,0
|
||||
adc eax,eax
|
||||
add ecx,edx
|
||||
adc eax,0
|
||||
dec ebp
|
||||
mov DWORD [8+ebx],ecx
|
||||
jz NEAR L$022aw_end
|
||||
; Tail Round 3
|
||||
mov ecx,DWORD [12+esi]
|
||||
mov edx,DWORD [12+edi]
|
||||
add ecx,eax
|
||||
mov eax,0
|
||||
adc eax,eax
|
||||
add ecx,edx
|
||||
adc eax,0
|
||||
dec ebp
|
||||
mov DWORD [12+ebx],ecx
|
||||
jz NEAR L$022aw_end
|
||||
; Tail Round 4
|
||||
mov ecx,DWORD [16+esi]
|
||||
mov edx,DWORD [16+edi]
|
||||
add ecx,eax
|
||||
mov eax,0
|
||||
adc eax,eax
|
||||
add ecx,edx
|
||||
adc eax,0
|
||||
dec ebp
|
||||
mov DWORD [16+ebx],ecx
|
||||
jz NEAR L$022aw_end
|
||||
; Tail Round 5
|
||||
mov ecx,DWORD [20+esi]
|
||||
mov edx,DWORD [20+edi]
|
||||
add ecx,eax
|
||||
mov eax,0
|
||||
adc eax,eax
|
||||
add ecx,edx
|
||||
adc eax,0
|
||||
dec ebp
|
||||
mov DWORD [20+ebx],ecx
|
||||
jz NEAR L$022aw_end
|
||||
; Tail Round 6
|
||||
mov ecx,DWORD [24+esi]
|
||||
mov edx,DWORD [24+edi]
|
||||
add ecx,eax
|
||||
mov eax,0
|
||||
adc eax,eax
|
||||
add ecx,edx
|
||||
adc eax,0
|
||||
mov DWORD [24+ebx],ecx
|
||||
L$022aw_end:
|
||||
pop edi
|
||||
pop esi
|
||||
pop ebx
|
||||
pop ebp
|
||||
ret
|
||||
global _bn_sub_words
|
||||
align 16
|
||||
_bn_sub_words:
|
||||
L$_bn_sub_words_begin:
|
||||
push ebp
|
||||
push ebx
|
||||
push esi
|
||||
push edi
|
||||
;
|
||||
mov ebx,DWORD [20+esp]
|
||||
mov esi,DWORD [24+esp]
|
||||
mov edi,DWORD [28+esp]
|
||||
mov ebp,DWORD [32+esp]
|
||||
xor eax,eax
|
||||
and ebp,4294967288
|
||||
jz NEAR L$023aw_finish
|
||||
L$024aw_loop:
|
||||
; Round 0
|
||||
mov ecx,DWORD [esi]
|
||||
mov edx,DWORD [edi]
|
||||
sub ecx,eax
|
||||
mov eax,0
|
||||
adc eax,eax
|
||||
sub ecx,edx
|
||||
adc eax,0
|
||||
mov DWORD [ebx],ecx
|
||||
; Round 1
|
||||
mov ecx,DWORD [4+esi]
|
||||
mov edx,DWORD [4+edi]
|
||||
sub ecx,eax
|
||||
mov eax,0
|
||||
adc eax,eax
|
||||
sub ecx,edx
|
||||
adc eax,0
|
||||
mov DWORD [4+ebx],ecx
|
||||
; Round 2
|
||||
mov ecx,DWORD [8+esi]
|
||||
mov edx,DWORD [8+edi]
|
||||
sub ecx,eax
|
||||
mov eax,0
|
||||
adc eax,eax
|
||||
sub ecx,edx
|
||||
adc eax,0
|
||||
mov DWORD [8+ebx],ecx
|
||||
; Round 3
|
||||
mov ecx,DWORD [12+esi]
|
||||
mov edx,DWORD [12+edi]
|
||||
sub ecx,eax
|
||||
mov eax,0
|
||||
adc eax,eax
|
||||
sub ecx,edx
|
||||
adc eax,0
|
||||
mov DWORD [12+ebx],ecx
|
||||
; Round 4
|
||||
mov ecx,DWORD [16+esi]
|
||||
mov edx,DWORD [16+edi]
|
||||
sub ecx,eax
|
||||
mov eax,0
|
||||
adc eax,eax
|
||||
sub ecx,edx
|
||||
adc eax,0
|
||||
mov DWORD [16+ebx],ecx
|
||||
; Round 5
|
||||
mov ecx,DWORD [20+esi]
|
||||
mov edx,DWORD [20+edi]
|
||||
sub ecx,eax
|
||||
mov eax,0
|
||||
adc eax,eax
|
||||
sub ecx,edx
|
||||
adc eax,0
|
||||
mov DWORD [20+ebx],ecx
|
||||
; Round 6
|
||||
mov ecx,DWORD [24+esi]
|
||||
mov edx,DWORD [24+edi]
|
||||
sub ecx,eax
|
||||
mov eax,0
|
||||
adc eax,eax
|
||||
sub ecx,edx
|
||||
adc eax,0
|
||||
mov DWORD [24+ebx],ecx
|
||||
; Round 7
|
||||
mov ecx,DWORD [28+esi]
|
||||
mov edx,DWORD [28+edi]
|
||||
sub ecx,eax
|
||||
mov eax,0
|
||||
adc eax,eax
|
||||
sub ecx,edx
|
||||
adc eax,0
|
||||
mov DWORD [28+ebx],ecx
|
||||
;
|
||||
add esi,32
|
||||
add edi,32
|
||||
add ebx,32
|
||||
sub ebp,8
|
||||
jnz NEAR L$024aw_loop
|
||||
L$023aw_finish:
|
||||
mov ebp,DWORD [32+esp]
|
||||
and ebp,7
|
||||
jz NEAR L$025aw_end
|
||||
; Tail Round 0
|
||||
mov ecx,DWORD [esi]
|
||||
mov edx,DWORD [edi]
|
||||
sub ecx,eax
|
||||
mov eax,0
|
||||
adc eax,eax
|
||||
sub ecx,edx
|
||||
adc eax,0
|
||||
dec ebp
|
||||
mov DWORD [ebx],ecx
|
||||
jz NEAR L$025aw_end
|
||||
; Tail Round 1
|
||||
mov ecx,DWORD [4+esi]
|
||||
mov edx,DWORD [4+edi]
|
||||
sub ecx,eax
|
||||
mov eax,0
|
||||
adc eax,eax
|
||||
sub ecx,edx
|
||||
adc eax,0
|
||||
dec ebp
|
||||
mov DWORD [4+ebx],ecx
|
||||
jz NEAR L$025aw_end
|
||||
; Tail Round 2
|
||||
mov ecx,DWORD [8+esi]
|
||||
mov edx,DWORD [8+edi]
|
||||
sub ecx,eax
|
||||
mov eax,0
|
||||
adc eax,eax
|
||||
sub ecx,edx
|
||||
adc eax,0
|
||||
dec ebp
|
||||
mov DWORD [8+ebx],ecx
|
||||
jz NEAR L$025aw_end
|
||||
; Tail Round 3
|
||||
mov ecx,DWORD [12+esi]
|
||||
mov edx,DWORD [12+edi]
|
||||
sub ecx,eax
|
||||
mov eax,0
|
||||
adc eax,eax
|
||||
sub ecx,edx
|
||||
adc eax,0
|
||||
dec ebp
|
||||
mov DWORD [12+ebx],ecx
|
||||
jz NEAR L$025aw_end
|
||||
; Tail Round 4
|
||||
mov ecx,DWORD [16+esi]
|
||||
mov edx,DWORD [16+edi]
|
||||
sub ecx,eax
|
||||
mov eax,0
|
||||
adc eax,eax
|
||||
sub ecx,edx
|
||||
adc eax,0
|
||||
dec ebp
|
||||
mov DWORD [16+ebx],ecx
|
||||
jz NEAR L$025aw_end
|
||||
; Tail Round 5
|
||||
mov ecx,DWORD [20+esi]
|
||||
mov edx,DWORD [20+edi]
|
||||
sub ecx,eax
|
||||
mov eax,0
|
||||
adc eax,eax
|
||||
sub ecx,edx
|
||||
adc eax,0
|
||||
dec ebp
|
||||
mov DWORD [20+ebx],ecx
|
||||
jz NEAR L$025aw_end
|
||||
; Tail Round 6
|
||||
mov ecx,DWORD [24+esi]
|
||||
mov edx,DWORD [24+edi]
|
||||
sub ecx,eax
|
||||
mov eax,0
|
||||
adc eax,eax
|
||||
sub ecx,edx
|
||||
adc eax,0
|
||||
mov DWORD [24+ebx],ecx
|
||||
L$025aw_end:
|
||||
pop edi
|
||||
pop esi
|
||||
pop ebx
|
||||
pop ebp
|
||||
ret
|
||||
segment .bss
|
||||
common _OPENSSL_ia32cap_P 16
|
||||
%else
|
||||
; Work around https://bugzilla.nasm.us/show_bug.cgi?id=3392738
|
||||
ret
|
||||
%endif
|
||||
#endif // defined(__i386__) && defined(_WIN32)
|
||||
#if defined(__linux__) && defined(__ELF__)
|
||||
.section .note.GNU-stack,"",%progbits
|
||||
#endif
|
||||
|
||||
File renamed without changes.
File renamed without changes.
File renamed without changes.
+1
-1
@@ -186,7 +186,7 @@ void bn_assert_fits_in_bytes(const BIGNUM *bn, size_t num) {
|
||||
void bn_words_to_big_endian(uint8_t *out, size_t out_len, const BN_ULONG *in,
|
||||
size_t in_len) {
|
||||
// The caller should have selected an output length without truncation.
|
||||
assert(fits_in_bytes(in, in_len, out_len));
|
||||
declassify_assert(fits_in_bytes(in, in_len, out_len));
|
||||
|
||||
// We only support little-endian platforms, so the internal representation is
|
||||
// also little-endian as bytes. We can simply copy it in reverse.
|
||||
File renamed without changes.
File renamed without changes.
+150
-183
@@ -149,11 +149,11 @@ static inline void bn_div_rem_words(BN_ULONG *quotient_out, BN_ULONG *rem_out,
|
||||
// * https://gcc.gnu.org/bugzilla/show_bug.cgi?id=65668
|
||||
//
|
||||
// Clang bugs:
|
||||
// * https://llvm.org/bugs/show_bug.cgi?id=6397
|
||||
// * https://llvm.org/bugs/show_bug.cgi?id=12418
|
||||
// * https://github.com/llvm/llvm-project/issues/6769
|
||||
// * https://github.com/llvm/llvm-project/issues/12790
|
||||
//
|
||||
// These issues aren't specific to x86 and x86_64, so it might be worthwhile
|
||||
// to add more assembly language implementations.
|
||||
// These is specific to x86 and x86_64; Arm and RISC-V do not have double-wide
|
||||
// division instructions.
|
||||
#if defined(BN_CAN_USE_INLINE_ASM) && defined(OPENSSL_X86)
|
||||
__asm__ volatile("divl %4"
|
||||
: "=a"(*quotient_out), "=d"(*rem_out)
|
||||
@@ -175,44 +175,16 @@ static inline void bn_div_rem_words(BN_ULONG *quotient_out, BN_ULONG *rem_out,
|
||||
#endif
|
||||
}
|
||||
|
||||
// BN_div computes "quotient := numerator / divisor", rounding towards zero,
|
||||
// and sets up |rem| such that "quotient * divisor + rem = numerator" holds.
|
||||
//
|
||||
// Thus:
|
||||
//
|
||||
// quotient->neg == numerator->neg ^ divisor->neg
|
||||
// (unless the result is zero)
|
||||
// rem->neg == numerator->neg
|
||||
// (unless the remainder is zero)
|
||||
//
|
||||
// If |quotient| or |rem| is NULL, the respective value is not returned.
|
||||
//
|
||||
// This was specifically designed to contain fewer branches that may leak
|
||||
// sensitive information; see "New Branch Prediction Vulnerabilities in OpenSSL
|
||||
// and Necessary Software Countermeasures" by Onur Acıçmez, Shay Gueron, and
|
||||
// Jean-Pierre Seifert.
|
||||
int BN_div(BIGNUM *quotient, BIGNUM *rem, const BIGNUM *numerator,
|
||||
const BIGNUM *divisor, BN_CTX *ctx) {
|
||||
int norm_shift, loop;
|
||||
BIGNUM wnum;
|
||||
BN_ULONG *resp, *wnump;
|
||||
BN_ULONG d0, d1;
|
||||
int num_n, div_n;
|
||||
|
||||
// This function relies on the historical minimal-width |BIGNUM| invariant.
|
||||
// It is already not constant-time (constant-time reductions should use
|
||||
// Montgomery logic), so we shrink all inputs and intermediate values to
|
||||
// retain the previous behavior.
|
||||
|
||||
// Invalid zero-padding would have particularly bad consequences.
|
||||
int numerator_width = bn_minimal_width(numerator);
|
||||
int divisor_width = bn_minimal_width(divisor);
|
||||
if ((numerator_width > 0 && numerator->d[numerator_width - 1] == 0) ||
|
||||
(divisor_width > 0 && divisor->d[divisor_width - 1] == 0)) {
|
||||
OPENSSL_PUT_ERROR(BN, BN_R_NOT_INITIALIZED);
|
||||
return 0;
|
||||
}
|
||||
|
||||
// This function implements long division, per Knuth, The Art of Computer
|
||||
// Programming, Volume 2, Chapter 4.3.1, Algorithm D. This algorithm only
|
||||
// divides non-negative integers, but we round towards zero, so we divide
|
||||
// absolute values and adjust the signs separately.
|
||||
//
|
||||
// Inputs to this function are assumed public and may be leaked by timing and
|
||||
// cache side channels. Division with secret inputs should use other
|
||||
// implementation strategies such as Montgomery reduction.
|
||||
if (BN_is_zero(divisor)) {
|
||||
OPENSSL_PUT_ERROR(BN, BN_R_DIV_BY_ZERO);
|
||||
return 0;
|
||||
@@ -222,174 +194,168 @@ int BN_div(BIGNUM *quotient, BIGNUM *rem, const BIGNUM *numerator,
|
||||
BIGNUM *tmp = BN_CTX_get(ctx);
|
||||
BIGNUM *snum = BN_CTX_get(ctx);
|
||||
BIGNUM *sdiv = BN_CTX_get(ctx);
|
||||
BIGNUM *res = NULL;
|
||||
if (quotient == NULL) {
|
||||
res = BN_CTX_get(ctx);
|
||||
} else {
|
||||
res = quotient;
|
||||
}
|
||||
if (sdiv == NULL || res == NULL) {
|
||||
BIGNUM *res = quotient == NULL ? BN_CTX_get(ctx) : quotient;
|
||||
if (tmp == NULL || snum == NULL || sdiv == NULL || res == NULL) {
|
||||
goto err;
|
||||
}
|
||||
|
||||
// First we normalise the numbers
|
||||
norm_shift = BN_BITS2 - (BN_num_bits(divisor) % BN_BITS2);
|
||||
if (!BN_lshift(sdiv, divisor, norm_shift)) {
|
||||
// Knuth step D1: Normalise the numbers such that the divisor's MSB is set.
|
||||
// This ensures, in Knuth's terminology, that v1 >= b/2, needed for the
|
||||
// quotient estimation step.
|
||||
int norm_shift = BN_BITS2 - (BN_num_bits(divisor) % BN_BITS2);
|
||||
if (!BN_lshift(sdiv, divisor, norm_shift) ||
|
||||
!BN_lshift(snum, numerator, norm_shift)) {
|
||||
goto err;
|
||||
}
|
||||
|
||||
// This algorithm relies on |sdiv| being minimal width. We do not use this
|
||||
// function on secret inputs, so leaking this is fine. Also minimize |snum| to
|
||||
// avoid looping on leading zeros, as we're not trying to be leak-free.
|
||||
bn_set_minimal_width(sdiv);
|
||||
sdiv->neg = 0;
|
||||
norm_shift += BN_BITS2;
|
||||
if (!BN_lshift(snum, numerator, norm_shift)) {
|
||||
goto err;
|
||||
}
|
||||
bn_set_minimal_width(snum);
|
||||
snum->neg = 0;
|
||||
int div_n = sdiv->width;
|
||||
const BN_ULONG d0 = sdiv->d[div_n - 1];
|
||||
const BN_ULONG d1 = (div_n == 1) ? 0 : sdiv->d[div_n - 2];
|
||||
assert(d0 & (((BN_ULONG)1) << (BN_BITS2 - 1)));
|
||||
|
||||
// Since we don't want to have special-case logic for the case where snum is
|
||||
// larger than sdiv, we pad snum with enough zeroes without changing its
|
||||
// value.
|
||||
if (snum->width <= sdiv->width + 1) {
|
||||
if (!bn_wexpand(snum, sdiv->width + 2)) {
|
||||
goto err;
|
||||
}
|
||||
for (int i = snum->width; i < sdiv->width + 2; i++) {
|
||||
snum->d[i] = 0;
|
||||
}
|
||||
snum->width = sdiv->width + 2;
|
||||
} else {
|
||||
if (!bn_wexpand(snum, snum->width + 1)) {
|
||||
goto err;
|
||||
}
|
||||
snum->d[snum->width] = 0;
|
||||
snum->width++;
|
||||
}
|
||||
|
||||
div_n = sdiv->width;
|
||||
num_n = snum->width;
|
||||
loop = num_n - div_n;
|
||||
// Lets setup a 'window' into snum
|
||||
// This is the part that corresponds to the current
|
||||
// 'area' being divided
|
||||
wnum.neg = 0;
|
||||
wnum.d = &(snum->d[loop]);
|
||||
wnum.width = div_n;
|
||||
// only needed when BN_ucmp messes up the values between width and max
|
||||
wnum.dmax = snum->dmax - loop; // so we don't step out of bounds
|
||||
|
||||
// Get the top 2 words of sdiv
|
||||
// div_n=sdiv->width;
|
||||
d0 = sdiv->d[div_n - 1];
|
||||
d1 = (div_n == 1) ? 0 : sdiv->d[div_n - 2];
|
||||
|
||||
// pointer to the 'top' of snum
|
||||
wnump = &(snum->d[num_n - 1]);
|
||||
|
||||
// Setup |res|. |numerator| and |res| may alias, so we save |numerator->neg|
|
||||
// for later.
|
||||
const int numerator_neg = numerator->neg;
|
||||
res->neg = (numerator_neg ^ divisor->neg);
|
||||
if (!bn_wexpand(res, loop + 1)) {
|
||||
goto err;
|
||||
}
|
||||
res->width = loop - 1;
|
||||
resp = &(res->d[loop - 1]);
|
||||
|
||||
// space for temp
|
||||
if (!bn_wexpand(tmp, div_n + 1)) {
|
||||
// Extend |snum| with zeros to satisfy the long division invariants:
|
||||
// - |snum| must have at least |div_n| + 1 words.
|
||||
// - |snum|'s most significant word must be zero to guarantee the first loop
|
||||
// iteration works with a prefix greater than |sdiv|. (This is the extra u0
|
||||
// digit in Knuth step D1.)
|
||||
int num_n = snum->width <= div_n ? div_n + 1 : snum->width + 1;
|
||||
if (!bn_resize_words(snum, num_n)) {
|
||||
goto err;
|
||||
}
|
||||
|
||||
// if res->width == 0 then clear the neg value otherwise decrease
|
||||
// the resp pointer
|
||||
if (res->width == 0) {
|
||||
res->neg = 0;
|
||||
} else {
|
||||
resp--;
|
||||
// Knuth step D2: The quotient's width is the difference between numerator and
|
||||
// denominator. Also set up its sign and size a temporary for the loop.
|
||||
int loop = num_n - div_n;
|
||||
res->neg = snum->neg ^ sdiv->neg;
|
||||
if (!bn_wexpand(res, loop) || //
|
||||
!bn_wexpand(tmp, div_n + 1)) {
|
||||
goto err;
|
||||
}
|
||||
res->width = loop;
|
||||
|
||||
for (int i = 0; i < loop - 1; i++, wnump--, resp--) {
|
||||
BN_ULONG q, l0;
|
||||
// the first part of the loop uses the top two words of snum and sdiv to
|
||||
// calculate a BN_ULONG q such that | wnum - sdiv * q | < sdiv
|
||||
BN_ULONG n0, n1, rm = 0;
|
||||
|
||||
n0 = wnump[0];
|
||||
n1 = wnump[-1];
|
||||
// Knuth steps D2 through D7: Compute the quotient with a word-by-word long
|
||||
// division. Note that Knuth indexes words from most to least significant, so
|
||||
// our index is reversed. Each loop iteration computes res->d[i] of the
|
||||
// quotient and updates snum with the running remainder. Before each loop
|
||||
// iteration, the div_n words beginning at snum->d[i+1] must be less than
|
||||
// snum.
|
||||
for (int i = loop - 1; i >= 0; i--) {
|
||||
// The next word of the quotient, q, is floor(wnum / sdiv), where wnum is
|
||||
// the div_n + 1 words beginning at snum->d[i]. i starts at
|
||||
// num_n - div_n - 1, so there are at least div_n + 1 words available.
|
||||
//
|
||||
// Knuth step D3: Compute q', an estimate of q by looking at the top words
|
||||
// of wnum and sdiv. We must estimate such that q' = q or q' = q + 1.
|
||||
BN_ULONG q, rm = 0;
|
||||
BN_ULONG *wnum = snum->d + i;
|
||||
BN_ULONG n0 = wnum[div_n];
|
||||
BN_ULONG n1 = wnum[div_n - 1];
|
||||
if (n0 == d0) {
|
||||
// Estimate q' = b - 1, where b is the base.
|
||||
q = BN_MASK2;
|
||||
// Knuth also runs the fixup routine in this case, but this would require
|
||||
// computing rm and is unnecessary. q' is already close enough. That is,
|
||||
// the true quotient, q is either b - 1 or b - 2.
|
||||
//
|
||||
// By the loop invariant, q <= b - 1, so we must show that q >= b - 2. We
|
||||
// do this by showing wnum / sdiv >= b - 2. Suppose wnum / sdiv < b - 2.
|
||||
// wnum and sdiv have the same most significant word, so:
|
||||
//
|
||||
// wnum >= n0 * b^div_n
|
||||
// sdiv < (n0 + 1) * b^(d_div - 1)
|
||||
//
|
||||
// Thus:
|
||||
//
|
||||
// b - 2 > wnum / sdiv
|
||||
// > (n0 * b^div_n) / (n0 + 1) * b^(div_n - 1)
|
||||
// = (n0 * b) / (n0 + 1)
|
||||
//
|
||||
// (n0 + 1) * (b - 2) > n0 * b
|
||||
// n0 * b + b - 2 * n0 - 2 > n0 * b
|
||||
// b - 2 > 2 * n0
|
||||
// b/2 - 1 > n0
|
||||
//
|
||||
// This contradicts the normalization condition, so q >= b - 2 and our
|
||||
// estimate is close enough.
|
||||
} else {
|
||||
// n0 < d0
|
||||
// Estimate q' = floor(n0n1 / d0). Per Theorem B, q' - 2 <= q <= q', which
|
||||
// is slightly outside of our bounds.
|
||||
assert(n0 < d0);
|
||||
bn_div_rem_words(&q, &rm, n0, n1, d0);
|
||||
|
||||
// Fix the estimate by examining one more word and adjusting q' as needed.
|
||||
// This is the second half of step D3 and is sufficient per exercises 19,
|
||||
// 20, and 21. Although only one iteration is needed to correct q + 2 to
|
||||
// q + 1, Knuth uses a loop. A loop will often also correct q + 1 to q,
|
||||
// saving the slightly more expensive underflow handling below.
|
||||
if (div_n > 1) {
|
||||
BN_ULONG n2 = wnum[div_n - 2];
|
||||
#ifdef BN_ULLONG
|
||||
BN_ULLONG t2 = (BN_ULLONG)d1 * q;
|
||||
for (;;) {
|
||||
if (t2 <= ((((BN_ULLONG)rm) << BN_BITS2) | wnump[-2])) {
|
||||
break;
|
||||
BN_ULLONG t2 = (BN_ULLONG)d1 * q;
|
||||
for (;;) {
|
||||
if (t2 <= ((((BN_ULLONG)rm) << BN_BITS2) | n2)) {
|
||||
break;
|
||||
}
|
||||
q--;
|
||||
rm += d0;
|
||||
if (rm < d0) {
|
||||
// If rm overflows, the true value exceeds BN_ULONG and the next
|
||||
// t2 comparison should exit the loop.
|
||||
break;
|
||||
}
|
||||
t2 -= d1;
|
||||
}
|
||||
q--;
|
||||
rm += d0;
|
||||
if (rm < d0) {
|
||||
break; // don't let rm overflow
|
||||
#else // !BN_ULLONG
|
||||
BN_ULONG t2l, t2h;
|
||||
BN_UMULT_LOHI(t2l, t2h, d1, q);
|
||||
for (;;) {
|
||||
if (t2h < rm || (t2h == rm && t2l <= n2)) {
|
||||
break;
|
||||
}
|
||||
q--;
|
||||
rm += d0;
|
||||
if (rm < d0) {
|
||||
// If rm overflows, the true value exceeds BN_ULONG and the next
|
||||
// t2 comparison should exit the loop.
|
||||
break;
|
||||
}
|
||||
if (t2l < d1) {
|
||||
t2h--;
|
||||
}
|
||||
t2l -= d1;
|
||||
}
|
||||
t2 -= d1;
|
||||
}
|
||||
#else // !BN_ULLONG
|
||||
BN_ULONG t2l, t2h;
|
||||
BN_UMULT_LOHI(t2l, t2h, d1, q);
|
||||
for (;;) {
|
||||
if (t2h < rm ||
|
||||
(t2h == rm && t2l <= wnump[-2])) {
|
||||
break;
|
||||
}
|
||||
q--;
|
||||
rm += d0;
|
||||
if (rm < d0) {
|
||||
break; // don't let rm overflow
|
||||
}
|
||||
if (t2l < d1) {
|
||||
t2h--;
|
||||
}
|
||||
t2l -= d1;
|
||||
}
|
||||
#endif // !BN_ULLONG
|
||||
}
|
||||
|
||||
l0 = bn_mul_words(tmp->d, sdiv->d, div_n, q);
|
||||
tmp->d[div_n] = l0;
|
||||
wnum.d--;
|
||||
// ingore top values of the bignums just sub the two
|
||||
// BN_ULONG arrays with bn_sub_words
|
||||
if (bn_sub_words(wnum.d, wnum.d, tmp->d, div_n + 1)) {
|
||||
// Note: As we have considered only the leading
|
||||
// two BN_ULONGs in the calculation of q, sdiv * q
|
||||
// might be greater than wnum (but then (q-1) * sdiv
|
||||
// is less or equal than wnum)
|
||||
q--;
|
||||
if (bn_add_words(wnum.d, wnum.d, sdiv->d, div_n)) {
|
||||
// we can't have an overflow here (assuming
|
||||
// that q != 0, but if q == 0 then tmp is
|
||||
// zero anyway)
|
||||
(*wnump)++;
|
||||
}
|
||||
}
|
||||
// store part of the result
|
||||
*resp = q;
|
||||
|
||||
// Knuth step D4 through D6: Now q' = q or q' = q + 1, and
|
||||
// -sdiv < wnum - sdiv * q < sdiv. If q' = q + 1, the subtraction will
|
||||
// underflow, and we fix it up below.
|
||||
tmp->d[div_n] = bn_mul_words(tmp->d, sdiv->d, div_n, q);
|
||||
if (bn_sub_words(wnum, wnum, tmp->d, div_n + 1)) {
|
||||
q--;
|
||||
// The final addition is expected to overflow, canceling the underflow.
|
||||
wnum[div_n] += bn_add_words(wnum, wnum, sdiv->d, div_n);
|
||||
}
|
||||
|
||||
// q is now correct, and wnum has been updated to the running remainder.
|
||||
res->d[i] = q;
|
||||
}
|
||||
|
||||
// Trim leading zeros and correct any negative zeros.
|
||||
bn_set_minimal_width(snum);
|
||||
bn_set_minimal_width(res);
|
||||
|
||||
if (rem != NULL) {
|
||||
if (!BN_rshift(rem, snum, norm_shift)) {
|
||||
goto err;
|
||||
}
|
||||
if (!BN_is_zero(rem)) {
|
||||
rem->neg = numerator_neg;
|
||||
}
|
||||
// Knuth step D8: Unnormalize. snum now contains the remainder.
|
||||
if (rem != NULL && !BN_rshift(rem, snum, norm_shift)) {
|
||||
goto err;
|
||||
}
|
||||
|
||||
bn_set_minimal_width(res);
|
||||
BN_CTX_end(ctx);
|
||||
return 1;
|
||||
|
||||
@@ -406,8 +372,9 @@ int BN_nnmod(BIGNUM *r, const BIGNUM *m, const BIGNUM *d, BN_CTX *ctx) {
|
||||
return 1;
|
||||
}
|
||||
|
||||
// now -|d| < r < 0, so we have to set r := r + |d|.
|
||||
return (d->neg ? BN_sub : BN_add)(r, r, d);
|
||||
// now -d < r < 0, so we have to set r := r + d. Ignoring the sign bits, this
|
||||
// is r = d - r.
|
||||
return BN_usub(r, d, r);
|
||||
}
|
||||
|
||||
BN_ULONG bn_reduce_once(BN_ULONG *r, const BN_ULONG *a, BN_ULONG carry,
|
||||
@@ -425,7 +392,7 @@ BN_ULONG bn_reduce_once(BN_ULONG *r, const BN_ULONG *a, BN_ULONG carry,
|
||||
//
|
||||
// Although |carry| may be one if it was one on input and |bn_sub_words|
|
||||
// returns zero, this would give |r| > |m|, violating our input assumptions.
|
||||
assert(carry == 0 || carry == (BN_ULONG)-1);
|
||||
declassify_assert(carry + 1 <= 1);
|
||||
bn_select_words(r, carry, a /* r < 0 */, r /* r >= 0 */, num);
|
||||
return carry;
|
||||
}
|
||||
@@ -434,7 +401,7 @@ BN_ULONG bn_reduce_once_in_place(BN_ULONG *r, BN_ULONG carry, const BN_ULONG *m,
|
||||
BN_ULONG *tmp, size_t num) {
|
||||
// See |bn_reduce_once| for why this logic works.
|
||||
carry -= bn_sub_words(tmp, r, m, num);
|
||||
assert(carry == 0 || carry == (BN_ULONG)-1);
|
||||
declassify_assert(carry + 1 <= 1);
|
||||
bn_select_words(r, carry, r /* tmp < 0 */, tmp /* tmp >= 0 */, num);
|
||||
return carry;
|
||||
}
|
||||
@@ -504,7 +471,7 @@ int bn_div_consttime(BIGNUM *quotient, BIGNUM *remainder,
|
||||
// |divisor_min_bits| bits, the top |divisor_min_bits - 1| can be incorporated
|
||||
// without reductions. This significantly speeds up |RSA_check_key|. For
|
||||
// simplicity, we round down to a whole number of words.
|
||||
assert(divisor_min_bits <= BN_num_bits(divisor));
|
||||
declassify_assert(divisor_min_bits <= BN_num_bits(divisor));
|
||||
int initial_words = 0;
|
||||
if (divisor_min_bits > 0) {
|
||||
initial_words = (divisor_min_bits - 1) / BN_BITS2;
|
||||
+1
-1
@@ -39,7 +39,7 @@ static uint16_t mod_u16(uint32_t n, uint16_t d, uint32_t p, uint32_t m) {
|
||||
|
||||
// Multiply and subtract to get the remainder.
|
||||
n -= d * t;
|
||||
assert(n < d);
|
||||
declassify_assert(n < d);
|
||||
return n;
|
||||
}
|
||||
|
||||
+46
-2
@@ -119,6 +119,50 @@
|
||||
#include "internal.h"
|
||||
#include "rsaz_exp.h"
|
||||
|
||||
#if defined(OPENSSL_BN_ASM_MONT5)
|
||||
|
||||
// bn_mul_mont_gather5 multiples loads index |power| of |table|, multiplies it
|
||||
// by |ap| modulo |np|, and stores the result in |rp|. The values are |num|
|
||||
// words long and represented in Montgomery form. |n0| is a pointer to the
|
||||
// corresponding field in |BN_MONT_CTX|. |table| must be aligned to at least
|
||||
// 16 bytes. |power| must be less than 32 and is treated as secret.
|
||||
//
|
||||
// WARNING: This function implements Almost Montgomery Multiplication from
|
||||
// https://eprint.iacr.org/2011/239. The inputs do not need to be fully reduced.
|
||||
// However, even if they are fully reduced, the output may not be.
|
||||
static void bn_mul_mont_gather5(
|
||||
BN_ULONG *rp, const BN_ULONG *ap, const BN_ULONG *table, const BN_ULONG *np,
|
||||
const BN_ULONG *n0, int num, int power) {
|
||||
if (bn_mulx4x_mont_gather5_capable(num)) {
|
||||
bn_mulx4x_mont_gather5(rp, ap, table, np, n0, num, power);
|
||||
} else if (bn_mul4x_mont_gather5_capable(num)) {
|
||||
bn_mul4x_mont_gather5(rp, ap, table, np, n0, num, power);
|
||||
} else {
|
||||
bn_mul_mont_gather5_nohw(rp, ap, table, np, n0, num, power);
|
||||
}
|
||||
}
|
||||
|
||||
// bn_power5 squares |ap| five times and multiplies it by the value stored at
|
||||
// index |power| of |table|, modulo |np|. It stores the result in |rp|. The
|
||||
// values are |num| words long and represented in Montgomery form. |n0| is a
|
||||
// pointer to the corresponding field in |BN_MONT_CTX|. |num| must be divisible
|
||||
// by 8. |power| must be less than 32 and is treated as secret.
|
||||
//
|
||||
// WARNING: This function implements Almost Montgomery Multiplication from
|
||||
// https://eprint.iacr.org/2011/239. The inputs do not need to be fully reduced.
|
||||
// However, even if they are fully reduced, the output may not be.
|
||||
static void bn_power5(BN_ULONG *rp, const BN_ULONG *ap, const BN_ULONG *table,
|
||||
const BN_ULONG *np, const BN_ULONG *n0, int num,
|
||||
int power) {
|
||||
assert(bn_power5_capable(num));
|
||||
if (bn_powerx5_capable(num)) {
|
||||
bn_powerx5(rp, ap, table, np, n0, num, power);
|
||||
} else {
|
||||
bn_power5_nohw(rp, ap, table, np, n0, num, power);
|
||||
}
|
||||
}
|
||||
|
||||
#endif // defined(OPENSSL_BN_ASM_MONT5)
|
||||
|
||||
int BN_exp(BIGNUM *r, const BIGNUM *a, const BIGNUM *p, BN_CTX *ctx) {
|
||||
int i, bits, ret = 0;
|
||||
@@ -1013,7 +1057,7 @@ int BN_mod_exp_mont_consttime(BIGNUM *rr, const BIGNUM *a, const BIGNUM *p,
|
||||
|
||||
// Prepare a^1 in the Montgomery domain.
|
||||
assert(!a->neg);
|
||||
assert(BN_ucmp(a, m) < 0);
|
||||
declassify_assert(BN_ucmp(a, m) < 0);
|
||||
if (!BN_to_montgomery(&am, a, mont, ctx) ||
|
||||
!bn_resize_words(&am, top)) {
|
||||
goto err;
|
||||
@@ -1079,7 +1123,7 @@ int BN_mod_exp_mont_consttime(BIGNUM *rr, const BIGNUM *a, const BIGNUM *p,
|
||||
|
||||
// Scan the exponent one window at a time starting from the most
|
||||
// significant bits.
|
||||
if (top & 7) {
|
||||
if (!bn_power5_capable(top)) {
|
||||
while (bits >= 0) {
|
||||
for (wvalue = 0, i = 0; i < 5; i++, bits--) {
|
||||
wvalue = (wvalue << 1) + BN_is_bit_set(p, bits);
|
||||
File renamed without changes.
+8
-5
@@ -93,7 +93,7 @@ static int bn_gcd_consttime(BIGNUM *r, unsigned *out_shift, const BIGNUM *x,
|
||||
// At least one of |u| and |v| is now even.
|
||||
BN_ULONG u_is_odd = word_is_odd_mask(u->d[0]);
|
||||
BN_ULONG v_is_odd = word_is_odd_mask(v->d[0]);
|
||||
assert(!(u_is_odd & v_is_odd));
|
||||
declassify_assert(!(u_is_odd & v_is_odd));
|
||||
|
||||
// If both are even, the final GCD gains a factor of two.
|
||||
shift += 1 & (~u_is_odd & ~v_is_odd);
|
||||
@@ -106,7 +106,7 @@ static int bn_gcd_consttime(BIGNUM *r, unsigned *out_shift, const BIGNUM *x,
|
||||
// One of |u| or |v| is zero at this point. The algorithm usually makes |u|
|
||||
// zero, unless |y| was already zero on input. Fix this by combining the
|
||||
// values.
|
||||
assert(BN_is_zero(u) || BN_is_zero(v));
|
||||
declassify_assert(BN_is_zero(u) | BN_is_zero(v));
|
||||
for (size_t i = 0; i < width; i++) {
|
||||
v->d[i] |= u->d[i];
|
||||
}
|
||||
@@ -289,7 +289,7 @@ int bn_mod_inverse_consttime(BIGNUM *r, int *out_no_inverse, const BIGNUM *a,
|
||||
// and |v| is now even.
|
||||
BN_ULONG u_is_even = ~word_is_odd_mask(u->d[0]);
|
||||
BN_ULONG v_is_even = ~word_is_odd_mask(v->d[0]);
|
||||
assert(u_is_even != v_is_even);
|
||||
declassify_assert(u_is_even != v_is_even);
|
||||
|
||||
// Halve the even one and adjust the corresponding coefficient.
|
||||
maybe_rshift1_words(u->d, u_is_even, tmp->d, n_width);
|
||||
@@ -313,8 +313,11 @@ int bn_mod_inverse_consttime(BIGNUM *r, int *out_no_inverse, const BIGNUM *a,
|
||||
maybe_rshift1_words_carry(D->d, D_carry, v_is_even, tmp->d, a_width);
|
||||
}
|
||||
|
||||
assert(BN_is_zero(v));
|
||||
if (!BN_is_one(u)) {
|
||||
declassify_assert(BN_is_zero(v));
|
||||
// While the inputs and output are secret, this function considers whether the
|
||||
// input was invertible to be public. It is used as part of RSA key
|
||||
// generation, where inputs are chosen to already be invertible.
|
||||
if (constant_time_declassify_int(!BN_is_one(u))) {
|
||||
*out_no_inverse = 1;
|
||||
OPENSSL_PUT_ERROR(BN, BN_R_NO_INVERSE);
|
||||
goto err;
|
||||
File renamed without changes.
@@ -438,18 +438,26 @@ int bn_mul_mont_nohw(BN_ULONG *rp, const BN_ULONG *ap, const BN_ULONG *bp,
|
||||
#if !defined(OPENSSL_NO_ASM) && defined(OPENSSL_X86_64)
|
||||
#define OPENSSL_BN_ASM_MONT5
|
||||
|
||||
// bn_mul_mont_gather5 multiples loads index |power| of |table|, multiplies it
|
||||
// by |ap| modulo |np|, and stores the result in |rp|. The values are |num|
|
||||
// words long and represented in Montgomery form. |n0| is a pointer to the
|
||||
// corresponding field in |BN_MONT_CTX|. |table| must be aligned to at least
|
||||
// 16 bytes. |power| must be less than 32 and is treated as secret.
|
||||
//
|
||||
// WARNING: This function implements Almost Montgomery Multiplication from
|
||||
// https://eprint.iacr.org/2011/239. The inputs do not need to be fully reduced.
|
||||
// However, even if they are fully reduced, the output may not be.
|
||||
void bn_mul_mont_gather5(BN_ULONG *rp, const BN_ULONG *ap,
|
||||
const BN_ULONG *table, const BN_ULONG *np,
|
||||
const BN_ULONG *n0, int num, int power);
|
||||
// The following functions implement |bn_mul_mont_gather5|. See
|
||||
// |bn_mul_mont_gather5| for details.
|
||||
OPENSSL_INLINE int bn_mul4x_mont_gather5_capable(int num) {
|
||||
return (num & 7) == 0;
|
||||
}
|
||||
void bn_mul4x_mont_gather5(BN_ULONG *rp, const BN_ULONG *ap,
|
||||
const BN_ULONG *table, const BN_ULONG *np,
|
||||
const BN_ULONG *n0, int num, int power);
|
||||
|
||||
OPENSSL_INLINE int bn_mulx4x_mont_gather5_capable(int num) {
|
||||
return bn_mul4x_mont_gather5_capable(num) && CRYPTO_is_ADX_capable() &&
|
||||
CRYPTO_is_BMI1_capable() && CRYPTO_is_BMI2_capable();
|
||||
}
|
||||
void bn_mulx4x_mont_gather5(BN_ULONG *rp, const BN_ULONG *ap,
|
||||
const BN_ULONG *table, const BN_ULONG *np,
|
||||
const BN_ULONG *n0, int num, int power);
|
||||
|
||||
void bn_mul_mont_gather5_nohw(BN_ULONG *rp, const BN_ULONG *ap,
|
||||
const BN_ULONG *table, const BN_ULONG *np,
|
||||
const BN_ULONG *n0, int num, int power);
|
||||
|
||||
// bn_scatter5 stores |inp| to index |power| of |table|. |inp| and each entry of
|
||||
// |table| are |num| words long. |power| must be less than 32 and is treated as
|
||||
@@ -463,17 +471,19 @@ void bn_scatter5(const BN_ULONG *inp, size_t num, BN_ULONG *table,
|
||||
// is treated as secret. |table| must be aligned to at least 16 bytes.
|
||||
void bn_gather5(BN_ULONG *out, size_t num, const BN_ULONG *table, size_t power);
|
||||
|
||||
// bn_power5 squares |ap| five times and multiplies it by the value stored at
|
||||
// index |power| of |table|, modulo |np|. It stores the result in |rp|. The
|
||||
// values are |num| words long and represented in Montgomery form. |n0| is a
|
||||
// pointer to the corresponding field in |BN_MONT_CTX|. |num| must be divisible
|
||||
// by 8. |power| must be less than 32 and is treated as secret.
|
||||
//
|
||||
// WARNING: This function implements Almost Montgomery Multiplication from
|
||||
// https://eprint.iacr.org/2011/239. The inputs do not need to be fully reduced.
|
||||
// However, even if they are fully reduced, the output may not be.
|
||||
void bn_power5(BN_ULONG *rp, const BN_ULONG *ap, const BN_ULONG *table,
|
||||
const BN_ULONG *np, const BN_ULONG *n0, int num, int power);
|
||||
// The following functions implement |bn_power5|. See |bn_power5| for details.
|
||||
void bn_power5_nohw(BN_ULONG *rp, const BN_ULONG *ap, const BN_ULONG *table,
|
||||
const BN_ULONG *np, const BN_ULONG *n0, int num, int power);
|
||||
|
||||
OPENSSL_INLINE int bn_power5_capable(int num) { return (num & 7) == 0; }
|
||||
|
||||
OPENSSL_INLINE int bn_powerx5_capable(int num) {
|
||||
return bn_power5_capable(num) && CRYPTO_is_ADX_capable() &&
|
||||
CRYPTO_is_BMI1_capable() && CRYPTO_is_BMI2_capable();
|
||||
}
|
||||
void bn_powerx5(BN_ULONG *rp, const BN_ULONG *ap, const BN_ULONG *table,
|
||||
const BN_ULONG *np, const BN_ULONG *n0, int num, int power);
|
||||
|
||||
#endif // !OPENSSL_NO_ASM && OPENSSL_X86_64
|
||||
|
||||
uint64_t bn_mont_n0(const BIGNUM *n);
|
||||
|
||||
File renamed without changes.
File renamed without changes.
+1
-1
@@ -153,7 +153,7 @@ static uint64_t bn_neg_inv_mod_r_u64(uint64_t n) {
|
||||
|
||||
// The invariant now shows that u*r - v*n == 1 since r == 2 * alpha.
|
||||
#if BN_BITS2 == 64 && defined(BN_ULLONG)
|
||||
assert(1 == ((BN_ULLONG)u * 2 * alpha) - ((BN_ULLONG)v * beta));
|
||||
declassify_assert(1 == ((BN_ULLONG)u * 2 * alpha) - ((BN_ULLONG)v * beta));
|
||||
#endif
|
||||
|
||||
return v;
|
||||
+2
-2
@@ -292,7 +292,7 @@ static void bn_mul_recursive(BN_ULONG *r, const BN_ULONG *a, const BN_ULONG *b,
|
||||
}
|
||||
|
||||
// The product should fit without carries.
|
||||
assert(c == 0);
|
||||
declassify_assert(c == 0);
|
||||
}
|
||||
|
||||
// bn_mul_part_recursive sets |r| to |a| * |b|, using |t| as scratch space. |r|
|
||||
@@ -406,7 +406,7 @@ static void bn_mul_part_recursive(BN_ULONG *r, const BN_ULONG *a,
|
||||
}
|
||||
|
||||
// The product should fit without carries.
|
||||
assert(c == 0);
|
||||
declassify_assert(c == 0);
|
||||
}
|
||||
|
||||
// bn_mul_impl implements |BN_mul| and |bn_mul_consttime|. Note this function
|
||||
+14
-7
@@ -487,7 +487,10 @@ err:
|
||||
static int bn_trial_division(uint16_t *out, const BIGNUM *bn) {
|
||||
const size_t num_primes = num_trial_division_primes(bn);
|
||||
for (size_t i = 1; i < num_primes; i++) {
|
||||
if (bn_mod_u16_consttime(bn, kPrimes[i]) == 0) {
|
||||
// During RSA key generation, |bn| may be secret, but only if |bn| was
|
||||
// prime, so it is safe to leak failed trial divisions.
|
||||
if (constant_time_declassify_int(bn_mod_u16_consttime(bn, kPrimes[i]) ==
|
||||
0)) {
|
||||
*out = kPrimes[i];
|
||||
return 1;
|
||||
}
|
||||
@@ -573,7 +576,8 @@ int bn_miller_rabin_iteration(const BN_MILLER_RABIN *miller_rabin,
|
||||
// To avoid leaking |a|, we run the loop to |w_bits| and mask off all
|
||||
// iterations once |j| = |a|.
|
||||
for (int j = 1; j < miller_rabin->w_bits; j++) {
|
||||
if (constant_time_eq_int(j, miller_rabin->a) & ~is_possibly_prime) {
|
||||
if (constant_time_declassify_w(constant_time_eq_int(j, miller_rabin->a) &
|
||||
~is_possibly_prime)) {
|
||||
// If the loop is done and we haven't seen z = 1 or z = w-1 yet, the
|
||||
// value is composite and we can break in variable time.
|
||||
break;
|
||||
@@ -593,12 +597,14 @@ int bn_miller_rabin_iteration(const BN_MILLER_RABIN *miller_rabin,
|
||||
// Step 4.5.3. If z = 1 and the loop is not done, the previous value of z
|
||||
// was not -1. There are no non-trivial square roots of 1 modulo a prime, so
|
||||
// w is composite and we may exit in variable time.
|
||||
if (BN_equal_consttime(z, miller_rabin->one_mont) & ~is_possibly_prime) {
|
||||
if (constant_time_declassify_w(
|
||||
BN_equal_consttime(z, miller_rabin->one_mont) &
|
||||
~is_possibly_prime)) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
*out_is_possibly_prime = is_possibly_prime & 1;
|
||||
*out_is_possibly_prime = constant_time_declassify_w(is_possibly_prime) & 1;
|
||||
ret = 1;
|
||||
|
||||
err:
|
||||
@@ -736,8 +742,9 @@ int BN_primality_test(int *out_is_probably_prime, const BIGNUM *w, int checks,
|
||||
crypto_word_t uniform_iterations = 0;
|
||||
// Using |constant_time_lt_w| seems to prevent the compiler from optimizing
|
||||
// this into two jumps.
|
||||
for (int i = 1; (i <= BN_PRIME_CHECKS_BLINDED) |
|
||||
constant_time_lt_w(uniform_iterations, checks);
|
||||
for (int i = 1; constant_time_declassify_w(
|
||||
(i <= BN_PRIME_CHECKS_BLINDED) |
|
||||
constant_time_lt_w(uniform_iterations, checks));
|
||||
i++) {
|
||||
// Step 4.1-4.2
|
||||
int is_uniform;
|
||||
@@ -766,7 +773,7 @@ int BN_primality_test(int *out_is_probably_prime, const BIGNUM *w, int checks,
|
||||
}
|
||||
}
|
||||
|
||||
assert(uniform_iterations >= (crypto_word_t)checks);
|
||||
declassify_assert(uniform_iterations >= (crypto_word_t)checks);
|
||||
*out_is_probably_prime = 1;
|
||||
ret = 1;
|
||||
|
||||
+8
-9
@@ -113,10 +113,9 @@
|
||||
#include <string.h>
|
||||
|
||||
#include <CCryptoBoringSSL_err.h>
|
||||
#include <CCryptoBoringSSL_rand.h>
|
||||
|
||||
#include "../../internal.h"
|
||||
#include "../rand/internal.h"
|
||||
#include "../bcm_interface.h"
|
||||
#include "../service_indicator/internal.h"
|
||||
#include "internal.h"
|
||||
|
||||
@@ -157,7 +156,7 @@ int BN_rand(BIGNUM *rnd, int bits, int top, int bottom) {
|
||||
}
|
||||
|
||||
FIPS_service_indicator_lock_state();
|
||||
RAND_bytes((uint8_t *)rnd->d, words * sizeof(BN_ULONG));
|
||||
BCM_rand_bytes((uint8_t *)rnd->d, words * sizeof(BN_ULONG));
|
||||
FIPS_service_indicator_unlock_state();
|
||||
|
||||
rnd->d[words - 1] &= mask;
|
||||
@@ -225,8 +224,7 @@ static int bn_range_to_mask(size_t *out_words, BN_ULONG *out_mask,
|
||||
while (words > 0 && max_exclusive[words - 1] == 0) {
|
||||
words--;
|
||||
}
|
||||
if (words == 0 ||
|
||||
(words == 1 && max_exclusive[0] <= min_inclusive)) {
|
||||
if (words == 0 || (words == 1 && max_exclusive[0] <= min_inclusive)) {
|
||||
OPENSSL_PUT_ERROR(BN, BN_R_INVALID_RANGE);
|
||||
return 0;
|
||||
}
|
||||
@@ -275,8 +273,8 @@ int bn_rand_range_words(BN_ULONG *out, BN_ULONG min_inclusive,
|
||||
// Steps 4 and 5. Use |words| and |mask| together to obtain a string of N
|
||||
// bits, where N is the bit length of |max_exclusive|.
|
||||
FIPS_service_indicator_lock_state();
|
||||
RAND_bytes_with_additional_data((uint8_t *)out, words * sizeof(BN_ULONG),
|
||||
additional_data);
|
||||
BCM_rand_bytes_with_additional_data(
|
||||
(uint8_t *)out, words * sizeof(BN_ULONG), additional_data);
|
||||
FIPS_service_indicator_unlock_state();
|
||||
out[words - 1] &= mask;
|
||||
|
||||
@@ -326,7 +324,7 @@ int bn_rand_secret_range(BIGNUM *r, int *out_is_uniform, BN_ULONG min_inclusive,
|
||||
|
||||
// Select a uniform random number with num_bits(max_exclusive) bits.
|
||||
FIPS_service_indicator_lock_state();
|
||||
RAND_bytes((uint8_t *)r->d, words * sizeof(BN_ULONG));
|
||||
BCM_rand_bytes((uint8_t *)r->d, words * sizeof(BN_ULONG));
|
||||
FIPS_service_indicator_unlock_state();
|
||||
r->d[words - 1] &= mask;
|
||||
|
||||
@@ -339,7 +337,8 @@ int bn_rand_secret_range(BIGNUM *r, int *out_is_uniform, BN_ULONG min_inclusive,
|
||||
// If the value is not in range, force it to be in range.
|
||||
r->d[0] |= constant_time_select_w(in_range, 0, min_inclusive);
|
||||
r->d[words - 1] &= constant_time_select_w(in_range, BN_MASK2, mask >> 1);
|
||||
assert(bn_in_range_words(r->d, min_inclusive, max_exclusive->d, words));
|
||||
declassify_assert(
|
||||
bn_in_range_words(r->d, min_inclusive, max_exclusive->d, words));
|
||||
|
||||
r->neg = 0;
|
||||
r->width = (int)words;
|
||||
File renamed without changes.
File renamed without changes.
+1
-1
@@ -236,7 +236,7 @@ BIGNUM *BN_mod_sqrt(BIGNUM *in, const BIGNUM *a, const BIGNUM *p, BN_CTX *ctx) {
|
||||
goto end;
|
||||
}
|
||||
if (BN_ucmp(y, p) >= 0) {
|
||||
if (!(p->neg ? BN_add : BN_sub)(y, y, p)) {
|
||||
if (BN_usub(y, y, p)) {
|
||||
goto end;
|
||||
}
|
||||
}
|
||||
File diff suppressed because it is too large.
Load diff
File renamed without changes.
File renamed without changes.
+9
-8
@@ -56,11 +56,11 @@
|
||||
#include <CCryptoBoringSSL_err.h>
|
||||
#include <CCryptoBoringSSL_mem.h>
|
||||
#include <CCryptoBoringSSL_nid.h>
|
||||
#include <CCryptoBoringSSL_rand.h>
|
||||
|
||||
#include "internal.h"
|
||||
#include "../../internal.h"
|
||||
#include "../aes/internal.h"
|
||||
#include "../bcm_interface.h"
|
||||
#include "../modes/internal.h"
|
||||
#include "../service_indicator/internal.h"
|
||||
#include "../delocate.h"
|
||||
@@ -471,11 +471,11 @@ static int aes_gcm_ctrl(EVP_CIPHER_CTX *c, int type, int arg, void *ptr) {
|
||||
}
|
||||
OPENSSL_memcpy(gctx->iv, ptr, arg);
|
||||
if (c->encrypt) {
|
||||
// |RAND_bytes| calls within the fipsmodule should be wrapped with state
|
||||
// lock functions to avoid updating the service indicator with the DRBG
|
||||
// functions.
|
||||
// |BCM_rand_bytes| calls within the fipsmodule should be wrapped with
|
||||
// state lock functions to avoid updating the service indicator with the
|
||||
// DRBG functions.
|
||||
FIPS_service_indicator_lock_state();
|
||||
RAND_bytes(gctx->iv + arg, gctx->ivlen - arg);
|
||||
BCM_rand_bytes(gctx->iv + arg, gctx->ivlen - arg);
|
||||
FIPS_service_indicator_unlock_state();
|
||||
}
|
||||
gctx->iv_gen = 1;
|
||||
@@ -1167,10 +1167,11 @@ static int aead_aes_gcm_seal_scatter_randnonce(
|
||||
return 0;
|
||||
}
|
||||
|
||||
// |RAND_bytes| calls within the fipsmodule should be wrapped with state lock
|
||||
// functions to avoid updating the service indicator with the DRBG functions.
|
||||
// |BCM_rand_bytes| calls within the fipsmodule should be wrapped with state
|
||||
// lock functions to avoid updating the service indicator with the DRBG
|
||||
// functions.
|
||||
FIPS_service_indicator_lock_state();
|
||||
RAND_bytes(nonce, sizeof(nonce));
|
||||
BCM_rand_bytes(nonce, sizeof(nonce));
|
||||
FIPS_service_indicator_unlock_state();
|
||||
|
||||
const struct aead_aes_gcm_ctx *gcm_ctx =
|
||||
File renamed without changes.
@@ -134,9 +134,6 @@ struct evp_cipher_st {
|
||||
// flags contains the OR of a number of flags. See |EVP_CIPH_*|.
|
||||
uint32_t flags;
|
||||
|
||||
// app_data is a pointer to opaque, user data.
|
||||
void *app_data;
|
||||
|
||||
int (*init)(EVP_CIPHER_CTX *ctx, const uint8_t *key, const uint8_t *iv,
|
||||
int enc);
|
||||
|
||||
|
||||
File renamed without changes.
File diff suppressed because it is too large.
Load diff
File renamed without changes.
File renamed without changes.
File renamed without changes.
+4
-89
@@ -59,8 +59,6 @@
|
||||
#include <assert.h>
|
||||
#include <string.h>
|
||||
|
||||
#include <CCryptoBoringSSL_md4.h>
|
||||
#include <CCryptoBoringSSL_md5.h>
|
||||
#include <CCryptoBoringSSL_nid.h>
|
||||
#include <CCryptoBoringSSL_sha.h>
|
||||
|
||||
@@ -75,69 +73,21 @@
|
||||
#endif
|
||||
|
||||
|
||||
static void md4_init(EVP_MD_CTX *ctx) {
|
||||
CHECK(MD4_Init(ctx->md_data));
|
||||
}
|
||||
|
||||
static void md4_update(EVP_MD_CTX *ctx, const void *data, size_t count) {
|
||||
CHECK(MD4_Update(ctx->md_data, data, count));
|
||||
}
|
||||
|
||||
static void md4_final(EVP_MD_CTX *ctx, uint8_t *out) {
|
||||
CHECK(MD4_Final(out, ctx->md_data));
|
||||
}
|
||||
|
||||
DEFINE_METHOD_FUNCTION(EVP_MD, EVP_md4) {
|
||||
out->type = NID_md4;
|
||||
out->md_size = MD4_DIGEST_LENGTH;
|
||||
out->flags = 0;
|
||||
out->init = md4_init;
|
||||
out->update = md4_update;
|
||||
out->final = md4_final;
|
||||
out->block_size = 64;
|
||||
out->ctx_size = sizeof(MD4_CTX);
|
||||
}
|
||||
|
||||
|
||||
static void md5_init(EVP_MD_CTX *ctx) {
|
||||
CHECK(MD5_Init(ctx->md_data));
|
||||
}
|
||||
|
||||
static void md5_update(EVP_MD_CTX *ctx, const void *data, size_t count) {
|
||||
CHECK(MD5_Update(ctx->md_data, data, count));
|
||||
}
|
||||
|
||||
static void md5_final(EVP_MD_CTX *ctx, uint8_t *out) {
|
||||
CHECK(MD5_Final(out, ctx->md_data));
|
||||
}
|
||||
|
||||
DEFINE_METHOD_FUNCTION(EVP_MD, EVP_md5) {
|
||||
out->type = NID_md5;
|
||||
out->md_size = MD5_DIGEST_LENGTH;
|
||||
out->flags = 0;
|
||||
out->init = md5_init;
|
||||
out->update = md5_update;
|
||||
out->final = md5_final;
|
||||
out->block_size = 64;
|
||||
out->ctx_size = sizeof(MD5_CTX);
|
||||
}
|
||||
|
||||
|
||||
static void sha1_init(EVP_MD_CTX *ctx) {
|
||||
CHECK(SHA1_Init(ctx->md_data));
|
||||
BCM_sha1_init(ctx->md_data);
|
||||
}
|
||||
|
||||
static void sha1_update(EVP_MD_CTX *ctx, const void *data, size_t count) {
|
||||
CHECK(SHA1_Update(ctx->md_data, data, count));
|
||||
BCM_sha1_update(ctx->md_data, data, count);
|
||||
}
|
||||
|
||||
static void sha1_final(EVP_MD_CTX *ctx, uint8_t *md) {
|
||||
CHECK(SHA1_Final(md, ctx->md_data));
|
||||
BCM_sha1_final(md, ctx->md_data);
|
||||
}
|
||||
|
||||
DEFINE_METHOD_FUNCTION(EVP_MD, EVP_sha1) {
|
||||
out->type = NID_sha1;
|
||||
out->md_size = SHA_DIGEST_LENGTH;
|
||||
out->md_size = BCM_SHA_DIGEST_LENGTH;
|
||||
out->flags = 0;
|
||||
out->init = sha1_init;
|
||||
out->update = sha1_update;
|
||||
@@ -266,39 +216,4 @@ DEFINE_METHOD_FUNCTION(EVP_MD, EVP_sha512_256) {
|
||||
out->ctx_size = sizeof(SHA512_CTX);
|
||||
}
|
||||
|
||||
|
||||
typedef struct {
|
||||
MD5_CTX md5;
|
||||
SHA_CTX sha1;
|
||||
} MD5_SHA1_CTX;
|
||||
|
||||
static void md5_sha1_init(EVP_MD_CTX *md_ctx) {
|
||||
MD5_SHA1_CTX *ctx = md_ctx->md_data;
|
||||
CHECK(MD5_Init(&ctx->md5) && SHA1_Init(&ctx->sha1));
|
||||
}
|
||||
|
||||
static void md5_sha1_update(EVP_MD_CTX *md_ctx, const void *data,
|
||||
size_t count) {
|
||||
MD5_SHA1_CTX *ctx = md_ctx->md_data;
|
||||
CHECK(MD5_Update(&ctx->md5, data, count) &&
|
||||
SHA1_Update(&ctx->sha1, data, count));
|
||||
}
|
||||
|
||||
static void md5_sha1_final(EVP_MD_CTX *md_ctx, uint8_t *out) {
|
||||
MD5_SHA1_CTX *ctx = md_ctx->md_data;
|
||||
CHECK(MD5_Final(out, &ctx->md5) &&
|
||||
SHA1_Final(out + MD5_DIGEST_LENGTH, &ctx->sha1));
|
||||
}
|
||||
|
||||
DEFINE_METHOD_FUNCTION(EVP_MD, EVP_md5_sha1) {
|
||||
out->type = NID_md5_sha1;
|
||||
out->md_size = MD5_DIGEST_LENGTH + SHA_DIGEST_LENGTH;
|
||||
out->flags = 0;
|
||||
out->init = md5_sha1_init;
|
||||
out->update = md5_sha1_update;
|
||||
out->final = md5_sha1_final;
|
||||
out->block_size = 64;
|
||||
out->ctx_size = sizeof(MD5_SHA1_CTX);
|
||||
}
|
||||
|
||||
#undef CHECK
|
||||
File renamed without changes.
File renamed without changes.
+21
-9
@@ -75,10 +75,12 @@
|
||||
#include <CCryptoBoringSSL_err.h>
|
||||
#include <CCryptoBoringSSL_ex_data.h>
|
||||
#include <CCryptoBoringSSL_mem.h>
|
||||
#include <CCryptoBoringSSL_sha.h>
|
||||
#include <CCryptoBoringSSL_thread.h>
|
||||
|
||||
#include "internal.h"
|
||||
#include "../delocate.h"
|
||||
#include "../ecdsa/internal.h"
|
||||
#include "../service_indicator/internal.h"
|
||||
#include "../../internal.h"
|
||||
|
||||
@@ -242,7 +244,10 @@ int EC_KEY_set_private_key(EC_KEY *key, const BIGNUM *priv_key) {
|
||||
return 0;
|
||||
}
|
||||
if (!ec_bignum_to_scalar(key->group, &scalar->scalar, priv_key) ||
|
||||
ec_scalar_is_zero(key->group, &scalar->scalar)) {
|
||||
// Zero is not a valid private key, so it is safe to leak the result of
|
||||
// this comparison.
|
||||
constant_time_declassify_int(
|
||||
ec_scalar_is_zero(key->group, &scalar->scalar))) {
|
||||
OPENSSL_PUT_ERROR(EC, EC_R_INVALID_PRIVATE_KEY);
|
||||
ec_wrapped_scalar_free(scalar);
|
||||
return 0;
|
||||
@@ -341,15 +346,17 @@ int EC_KEY_check_fips(const EC_KEY *key) {
|
||||
}
|
||||
|
||||
if (key->priv_key) {
|
||||
uint8_t data[16] = {0};
|
||||
ECDSA_SIG *sig = ECDSA_do_sign(data, sizeof(data), key);
|
||||
if (boringssl_fips_break_test("ECDSA_PWCT")) {
|
||||
data[0] = ~data[0];
|
||||
uint8_t digest[SHA256_DIGEST_LENGTH] = {0};
|
||||
uint8_t sig[ECDSA_MAX_FIXED_LEN];
|
||||
size_t sig_len;
|
||||
if (!ecdsa_sign_fixed(digest, sizeof(digest), sig, &sig_len, sizeof(sig),
|
||||
key)) {
|
||||
goto end;
|
||||
}
|
||||
int ok = sig != NULL &&
|
||||
ECDSA_do_verify(data, sizeof(data), sig, key);
|
||||
ECDSA_SIG_free(sig);
|
||||
if (!ok) {
|
||||
if (boringssl_fips_break_test("ECDSA_PWCT")) {
|
||||
digest[0] = ~digest[0];
|
||||
}
|
||||
if (!ecdsa_verify_fixed(digest, sizeof(digest), sig, sig_len, key)) {
|
||||
OPENSSL_PUT_ERROR(EC, EC_R_PUBLIC_KEY_VALIDATION_FAILED);
|
||||
goto end;
|
||||
}
|
||||
@@ -518,6 +525,11 @@ int EC_KEY_generate_key(EC_KEY *key) {
|
||||
}
|
||||
|
||||
int EC_KEY_generate_key_fips(EC_KEY *eckey) {
|
||||
if (eckey == NULL || eckey->group == NULL) {
|
||||
OPENSSL_PUT_ERROR(EC, ERR_R_PASSED_NULL_PARAMETER);
|
||||
return 0;
|
||||
}
|
||||
|
||||
boringssl_ensure_ecc_self_test();
|
||||
|
||||
if (EC_KEY_generate_key(eckey) && EC_KEY_check_fips(eckey)) {
|
||||
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Loaded 100 of 376 files, more files were not shown because too many files have changed in this diff.
Show more
Reference in new issue
Block a user