mirror of
https://github.com/apple/swift-crypto
synced 2026-11-22 04:30:39 +00:00
Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
60f13f60c4 | ||
|
|
b71d0c1c9b | ||
|
|
ac03330c12 |
No files matched your search
@@ -9,7 +9,7 @@ about: If something isn't working as expected
|
||||
### New Issue Checklist
|
||||
|
||||
- [ ] I'm using the latest version of Swift Crypto (`main` branch)
|
||||
- [ ] I read the [Contribution Guidelines](https://github.com/apple/swift-crypto/blob/main/CONTRIBUTING.md)
|
||||
- [ ] I read the [Contribution Guidelines](https://github.com/apple/swift-crypto/blob/master/CONTRIBUTING.md)
|
||||
- [ ] I searched for [existing GitHub issues](https://github.com/apple/swift-crypto/issues)
|
||||
|
||||
### Expected behavior
|
||||
|
||||
@@ -6,8 +6,8 @@ about: Not sure how something works or how to implement some functionality? Ask
|
||||
|
||||
### Question Checklist
|
||||
|
||||
- [ ] I'm using the latest version of Swift Crypto (main branch)
|
||||
- [ ] I read the [Contribution Guidelines](https://github.com/apple/swift-crypto/blob/main/CONTRIBUTING.md)
|
||||
- [ ] I'm using the latest version of Swift Crypto (master branch)
|
||||
- [ ] I read the [Contribution Guidelines](https://github.com/apple/swift-crypto/blob/master/CONTRIBUTING.md)
|
||||
- [ ] I searched for [existing GitHub issues](https://github.com/apple/swift-crypto/issues)
|
||||
|
||||
### Question Subject
|
||||
|
||||
@@ -8,8 +8,8 @@ about: If a recent release broke a feature (Please make sure you know the last k
|
||||
|
||||
### New Regression Checklist
|
||||
|
||||
- [ ] I'm using the latest version of Swift Crypto (main branch)
|
||||
- [ ] I read the [Contribution Guidelines](https://github.com/apple/swift-crypto/blob/main/CONTRIBUTING.md)
|
||||
- [ ] I'm using the latest version of Swift Crypto (master branch)
|
||||
- [ ] I read the [Contribution Guidelines](https://github.com/apple/swift-crypto/blob/master/CONTRIBUTING.md)
|
||||
- [ ] I searched for [existing GitHub issues](https://github.com/apple/swift-crypto/issues)
|
||||
|
||||
### Regression Information
|
||||
|
||||
@@ -1,14 +0,0 @@
|
||||
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
|
||||
@@ -1,22 +0,0 @@
|
||||
name: Main
|
||||
|
||||
on:
|
||||
push:
|
||||
branches: [main]
|
||||
schedule:
|
||||
- cron: "0 8,20 * * *"
|
||||
|
||||
jobs:
|
||||
unit-tests:
|
||||
name: Unit tests
|
||||
uses: apple/swift-nio/.github/workflows/unit_tests.yml@main
|
||||
with:
|
||||
linux_5_9_arguments_override: "--explicit-target-dependency-import-check error"
|
||||
linux_5_10_arguments_override: "--explicit-target-dependency-import-check error"
|
||||
linux_6_0_arguments_override: "--explicit-target-dependency-import-check error"
|
||||
linux_nightly_6_0_arguments_override: "--explicit-target-dependency-import-check error"
|
||||
linux_nightly_main_arguments_override: "--explicit-target-dependency-import-check error"
|
||||
|
||||
cxx-interop:
|
||||
name: Cxx interop
|
||||
uses: apple/swift-nio/.github/workflows/cxx_interop.yml@main
|
||||
@@ -1,40 +0,0 @@
|
||||
name: PR
|
||||
|
||||
on:
|
||||
pull_request:
|
||||
types: [opened, reopened, synchronize]
|
||||
|
||||
jobs:
|
||||
soundness:
|
||||
name: Soundness
|
||||
uses: swiftlang/github-workflows/.github/workflows/soundness.yml@main
|
||||
with:
|
||||
license_header_check_project_name: "SwiftCrypto"
|
||||
format_check_enabled: false
|
||||
|
||||
cmake-lists:
|
||||
name: Check cmake lists
|
||||
uses: apple/swift-nio/.github/workflows/swift_matrix.yml@main
|
||||
with:
|
||||
name: "Check cmake lists"
|
||||
matrix_linux_command: ./scripts/check-cmake-lists.sh
|
||||
|
||||
unit-tests:
|
||||
name: Unit tests
|
||||
uses: apple/swift-nio/.github/workflows/unit_tests.yml@main
|
||||
with:
|
||||
linux_5_9_arguments_override: "--explicit-target-dependency-import-check error"
|
||||
linux_5_10_arguments_override: "--explicit-target-dependency-import-check error"
|
||||
linux_6_0_arguments_override: "--explicit-target-dependency-import-check error"
|
||||
linux_nightly_6_0_arguments_override: "--explicit-target-dependency-import-check error"
|
||||
linux_nightly_main_arguments_override: "--explicit-target-dependency-import-check error"
|
||||
windows_6_0_enabled: true
|
||||
windows_nightly_6_0_enabled: true
|
||||
windows_nightly_main_enabled: true
|
||||
windows_6_0_arguments_override: "--explicit-target-dependency-import-check error"
|
||||
windows_nightly_6_0_arguments_override: "--explicit-target-dependency-import-check error"
|
||||
windows_nightly_main_arguments_override: "--explicit-target-dependency-import-check error"
|
||||
|
||||
cxx-interop:
|
||||
name: Cxx interop
|
||||
uses: apple/swift-nio/.github/workflows/cxx_interop.yml@main
|
||||
@@ -1,18 +0,0 @@
|
||||
name: PR label
|
||||
|
||||
on:
|
||||
pull_request:
|
||||
types: [labeled, unlabeled, opened, reopened, synchronize]
|
||||
|
||||
jobs:
|
||||
semver-label-check:
|
||||
name: Semantic Version label check
|
||||
runs-on: ubuntu-latest
|
||||
timeout-minutes: 1
|
||||
steps:
|
||||
- name: Checkout repository
|
||||
uses: actions/checkout@v4
|
||||
with:
|
||||
persist-credentials: false
|
||||
- name: Check for Semantic Version label
|
||||
uses: apple/swift-nio/.github/actions/pull_request_semver_label_checker@main
|
||||
@@ -15,4 +15,3 @@ DerivedData
|
||||
|
||||
.*.sw[nop]
|
||||
|
||||
.vscode
|
||||
@@ -1,48 +0,0 @@
|
||||
.gitignore
|
||||
**/.gitignore
|
||||
.licenseignore
|
||||
.unacceptablelanguageignore
|
||||
.gitattributes
|
||||
.git-blame-ignore-revs
|
||||
.mailfilter
|
||||
.mailmap
|
||||
.spi.yml
|
||||
.swift-format
|
||||
.editorconfig
|
||||
.github/*
|
||||
*.md
|
||||
*.txt
|
||||
*.yml
|
||||
*.yaml
|
||||
*.json
|
||||
Package.swift
|
||||
**/Package.swift
|
||||
Package@-*.swift
|
||||
**/Package@-*.swift
|
||||
Package.resolved
|
||||
**/Package.resolved
|
||||
Makefile
|
||||
*.modulemap
|
||||
**/*.modulemap
|
||||
**/*.docc/*
|
||||
*.xcprivacy
|
||||
**/*.xcprivacy
|
||||
*.symlink
|
||||
**/*.symlink
|
||||
Dockerfile
|
||||
**/Dockerfile
|
||||
Snippets/*
|
||||
dev/git.commit.template
|
||||
dev/update-benchmark-thresholds
|
||||
*.crt
|
||||
**/*.crt
|
||||
*.pem
|
||||
**/*.pem
|
||||
*.der
|
||||
**/*.der
|
||||
.swiftformat
|
||||
Sources/CCryptoBoringSSL/*
|
||||
**/*.swift.gyb
|
||||
scripts/*.patch
|
||||
scripts/gyb
|
||||
scripts/gyb.py
|
||||
@@ -1 +0,0 @@
|
||||
Sources/CCryptoBoringSSL/*
|
||||
@@ -0,0 +1,5 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
|
||||
<plist version="1.0">
|
||||
<array/>
|
||||
</plist>
|
||||
+1
-15
@@ -6,7 +6,7 @@
|
||||
## Licensed under Apache License v2.0
|
||||
##
|
||||
## See LICENSE.txt for license information
|
||||
## See CONTRIBUTORS.txt for the list of SwiftCrypto project authors
|
||||
## See CONTRIBUTORS.md for the list of SwiftCrypto project authors
|
||||
##
|
||||
## SPDX-License-Identifier: Apache-2.0
|
||||
##
|
||||
@@ -31,10 +31,6 @@ endif()
|
||||
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin)
|
||||
set(CMAKE_Swift_MODULE_DIRECTORY ${CMAKE_BINARY_DIR}/swift)
|
||||
|
||||
set(SWIFT_CRYPTO_COMPILE_OPTIONS
|
||||
-package-name com.apple.swift-crypto
|
||||
)
|
||||
|
||||
option(BUILD_SHARED_LIBS "Build shared libraries by default" YES)
|
||||
|
||||
if(BUILD_SHARED_LIBS)
|
||||
@@ -52,15 +48,5 @@ if(NOT CMAKE_SYSTEM_NAME STREQUAL Darwin)
|
||||
find_package(Foundation CONFIG)
|
||||
endif()
|
||||
|
||||
include(FetchContent)
|
||||
find_package(SwiftASN1 CONFIG)
|
||||
if(NOT SwiftASN1_FOUND)
|
||||
message("-- Vending swift-asn1")
|
||||
FetchContent_Declare(ASN1
|
||||
GIT_REPOSITORY https://github.com/apple/swift-asn1
|
||||
GIT_TAG 1.1.0)
|
||||
FetchContent_MakeAvailable(ASN1)
|
||||
endif()
|
||||
|
||||
add_subdirectory(Sources)
|
||||
add_subdirectory(cmake/modules)
|
||||
File renamed without changes.
+1
-1
@@ -28,7 +28,7 @@ components that this product depends on.
|
||||
This product contains test vectors from Google's wycheproof project.
|
||||
|
||||
* LICENSE (Apache License 2.0):
|
||||
* https://github.com/C2SP/wycheproof/blob/31387e2cd596587c859c611027b6a44d2e2b65ff/LICENSE
|
||||
* https://github.com/google/wycheproof/blob/master/LICENSE
|
||||
* HOMEPAGE:
|
||||
* https://github.com/google/wycheproof
|
||||
|
||||
|
||||
+20
-48
@@ -1,4 +1,4 @@
|
||||
// swift-tools-version:5.9
|
||||
// swift-tools-version:5.6
|
||||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// This source file is part of the SwiftCrypto open source project
|
||||
@@ -7,7 +7,7 @@
|
||||
// Licensed under Apache License v2.0
|
||||
//
|
||||
// See LICENSE.txt for license information
|
||||
// See CONTRIBUTORS.txt for the list of SwiftCrypto project authors
|
||||
// See CONTRIBUTORS.md for the list of SwiftCrypto project authors
|
||||
//
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
//
|
||||
@@ -20,7 +20,7 @@
|
||||
// Sources/CCryptoBoringSSL directory. The source repository is at
|
||||
// https://boringssl.googlesource.com/boringssl.
|
||||
//
|
||||
// BoringSSL Commit: 2587c4974dbe9872451151c8e975f58567a1ce0d
|
||||
// BoringSSL Commit: 7ae2b910c13017b63f1a8bd6c8decfce692869b0
|
||||
|
||||
import PackageDescription
|
||||
|
||||
@@ -57,18 +57,6 @@ 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: [
|
||||
@@ -84,13 +72,11 @@ let package = Package(
|
||||
.library(name: "CCryptoBoringSSL", type: .static, targets: ["CCryptoBoringSSL"]),
|
||||
MANGLE_END */
|
||||
],
|
||||
dependencies: [
|
||||
.package(url: "https://github.com/apple/swift-asn1.git", from: "1.2.0")
|
||||
],
|
||||
dependencies: [],
|
||||
targets: [
|
||||
.target(
|
||||
name: "CCryptoBoringSSL",
|
||||
exclude: privacyManifestExclude + [
|
||||
exclude: [
|
||||
"hash.txt",
|
||||
"include/boringssl_prefix_symbols_nasm.inc",
|
||||
"CMakeLists.txt",
|
||||
@@ -102,13 +88,13 @@ let package = Package(
|
||||
"crypto/bio/socket_helper.c",
|
||||
"crypto/bio/socket.c"
|
||||
],
|
||||
resources: privacyManifestResource,
|
||||
cSettings: [
|
||||
// These defines come from BoringSSL's build system
|
||||
.define("_HAS_EXCEPTIONS", to: "0", .when(platforms: [Platform.windows])),
|
||||
.define("WIN32_LEAN_AND_MEAN", .when(platforms: [Platform.windows])),
|
||||
.define("NOMINMAX", .when(platforms: [Platform.windows])),
|
||||
.define("_CRT_SECURE_NO_WARNINGS", .when(platforms: [Platform.windows])),
|
||||
/*
|
||||
* This define is required on Windows, but because we need older
|
||||
* versions of SPM, we cannot conditionally define this on Windows
|
||||
* only. Unconditionally define it instead.
|
||||
*/
|
||||
.define("WIN32_LEAN_AND_MEAN"),
|
||||
/*
|
||||
* These defines are required on Wasm/WASI, to disable use of pthread.
|
||||
*/
|
||||
@@ -119,22 +105,20 @@ let package = Package(
|
||||
.target(
|
||||
name: "CCryptoBoringSSLShims",
|
||||
dependencies: ["CCryptoBoringSSL"],
|
||||
exclude: privacyManifestExclude + [
|
||||
exclude: [
|
||||
"CMakeLists.txt"
|
||||
],
|
||||
resources: privacyManifestResource
|
||||
]
|
||||
),
|
||||
.target(
|
||||
name: "Crypto",
|
||||
dependencies: dependencies,
|
||||
exclude: privacyManifestExclude + [
|
||||
exclude: [
|
||||
"CMakeLists.txt",
|
||||
"AEADs/Nonces.swift.gyb",
|
||||
"Digests/Digests.swift.gyb",
|
||||
"Key Agreement/ECDH.swift.gyb",
|
||||
"Signatures/ECDSA.swift.gyb",
|
||||
],
|
||||
resources: privacyManifestResource,
|
||||
swiftSettings: swiftSettings
|
||||
),
|
||||
.target(
|
||||
@@ -143,14 +127,11 @@ let package = Package(
|
||||
"CCryptoBoringSSL",
|
||||
"CCryptoBoringSSLShims",
|
||||
"CryptoBoringWrapper",
|
||||
"Crypto",
|
||||
.product(name: "SwiftASN1", package: "swift-asn1")
|
||||
"Crypto"
|
||||
],
|
||||
exclude: privacyManifestExclude + [
|
||||
exclude: [
|
||||
"CMakeLists.txt",
|
||||
],
|
||||
resources: privacyManifestResource,
|
||||
swiftSettings: swiftSettings
|
||||
]
|
||||
),
|
||||
.target(
|
||||
name: "CryptoBoringWrapper",
|
||||
@@ -158,22 +139,13 @@ let package = Package(
|
||||
"CCryptoBoringSSL",
|
||||
"CCryptoBoringSSLShims"
|
||||
],
|
||||
exclude: privacyManifestExclude + [
|
||||
exclude: [
|
||||
"CMakeLists.txt",
|
||||
],
|
||||
resources: privacyManifestResource
|
||||
]
|
||||
),
|
||||
.executableTarget(name: "crypto-shasum", dependencies: ["Crypto"]),
|
||||
.testTarget(
|
||||
name: "CryptoTests",
|
||||
dependencies: ["Crypto"],
|
||||
resources: [
|
||||
.copy("HPKE/hpke-test-vectors.json"),
|
||||
],
|
||||
swiftSettings: swiftSettings
|
||||
),
|
||||
.testTarget(name: "CryptoTests", dependencies: ["Crypto"], swiftSettings: swiftSettings),
|
||||
.testTarget(name: "_CryptoExtrasTests", dependencies: ["_CryptoExtras"]),
|
||||
.testTarget(name: "CryptoBoringWrapperTests", dependencies: ["CryptoBoringWrapper"]),
|
||||
],
|
||||
cxxLanguageStandard: .cxx11
|
||||
)
|
||||
@@ -7,9 +7,9 @@ Swift Crypto is an open-source implementation of a substantial portion of the AP
|
||||
Swift Crypto is available as a Swift Package Manager package. To use it, add the following dependency in your `Package.swift`:
|
||||
|
||||
```swift
|
||||
// swift-crypto 1.x, 2.x and 3.x are almost API compatible, so most clients
|
||||
// should allow any of them
|
||||
.package(url: "https://github.com/apple/swift-crypto.git", "1.0.0" ..< "4.0.0"),
|
||||
// swift-crypto 1.x and 2.x are almost API compatible, so most clients should
|
||||
// allow either
|
||||
.package(url: "https://github.com/apple/swift-crypto.git", "1.0.0" ..< "3.0.0"),
|
||||
```
|
||||
|
||||
and to your target, add `Crypto` to your dependencies. You can then `import Crypto` to get access to Swift Crypto's functionality.
|
||||
@@ -108,17 +108,14 @@ If you believe you have identified a vulnerability in Swift Crypto, please [repo
|
||||
|
||||
### Swift versions
|
||||
|
||||
The most recent versions of Swift Crypto support Swift 5.7 and newer. The minimum Swift version supported by Swift Crypto releases are detailed below:
|
||||
The most recent versions of Swift Crypto support Swift 5.6 and newer. The minimum Swift version supported by Swift Crypto releases are detailed below:
|
||||
|
||||
Swift Crypto | Minimum Swift Version
|
||||
------------------|----------------------
|
||||
`2.0.0 ..< 2.1.0` | 5.2
|
||||
`2.1.0 ..< 2.2.0` | 5.4
|
||||
`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 ..< 3.8.0` | 5.8
|
||||
`3.8.0 ...` | 5.9
|
||||
`2.4.2 ...` | 5.6
|
||||
|
||||
### Compatibility
|
||||
|
||||
@@ -138,5 +135,5 @@ To do so, please use the following dependency in your `Package.swift`:
|
||||
|
||||
### Developing Swift Crypto on macOS
|
||||
|
||||
Swift Crypto normally defers to the OS implementation of CryptoKit on macOS. Naturally, this makes developing Swift Crypto on macOS tricky. To get Swift Crypto to build the open source implementation on macOS, in `Package.swift`, change `let development = false` to `let development = true`, as this will force Swift Crypto to build its public API.
|
||||
Swift Crypto normally defers to the OS implementation of CryptoKit on macOS. Naturally, this makes developing Swift Crypto on macOS tricky. To get Swift Crypto to build the open source implementation on macOS, in `Package.swift`, uncomment the line that reads: `//.define("CRYPTO_IN_SWIFTPM_FORCE_BUILD_API")`, as this will force Swift Crypto to build its public API.
|
||||
|
||||
+169
-115
@@ -6,7 +6,7 @@
|
||||
## Licensed under Apache License v2.0
|
||||
##
|
||||
## See LICENSE.txt for license information
|
||||
## See CONTRIBUTORS.txt for the list of SwiftCrypto project authors
|
||||
## See CONTRIBUTORS.md for the list of SwiftCrypto project authors
|
||||
##
|
||||
## SPDX-License-Identifier: Apache-2.0
|
||||
##
|
||||
@@ -80,6 +80,7 @@ add_library(CCryptoBoringSSL STATIC
|
||||
"crypto/cpu_aarch64_openbsd.c"
|
||||
"crypto/cpu_aarch64_sysreg.c"
|
||||
"crypto/cpu_aarch64_win.c"
|
||||
"crypto/cpu_arm.c"
|
||||
"crypto/cpu_arm_freebsd.c"
|
||||
"crypto/cpu_arm_linux.c"
|
||||
"crypto/cpu_intel.c"
|
||||
@@ -91,7 +92,6 @@ 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"
|
||||
@@ -101,11 +101,10 @@ 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"
|
||||
@@ -121,17 +120,89 @@ add_library(CCryptoBoringSSL STATIC
|
||||
"crypto/evp/scrypt.c"
|
||||
"crypto/evp/sign.c"
|
||||
"crypto/ex_data.c"
|
||||
"crypto/fipsmodule/bcm.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/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/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"
|
||||
@@ -152,37 +223,19 @@ 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_extra.c"
|
||||
"crypto/rsa_extra/rsa_print.c"
|
||||
"crypto/sha/sha1.c"
|
||||
"crypto/sha/sha256.c"
|
||||
"crypto/sha/sha512.c"
|
||||
"crypto/siphash/siphash.c"
|
||||
"crypto/slhdsa/fors.c"
|
||||
"crypto/slhdsa/merkle.c"
|
||||
"crypto/slhdsa/slhdsa.c"
|
||||
"crypto/slhdsa/thash.c"
|
||||
"crypto/slhdsa/wots.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/spx_wots.c"
|
||||
"crypto/stack/stack.c"
|
||||
"crypto/thread.c"
|
||||
"crypto/thread_none.c"
|
||||
@@ -206,29 +259,6 @@ add_library(CCryptoBoringSSL STATIC
|
||||
"crypto/x509/t_req.c"
|
||||
"crypto/x509/t_x509.c"
|
||||
"crypto/x509/t_x509a.c"
|
||||
"crypto/x509/v3_akey.c"
|
||||
"crypto/x509/v3_akeya.c"
|
||||
"crypto/x509/v3_alt.c"
|
||||
"crypto/x509/v3_bcons.c"
|
||||
"crypto/x509/v3_bitst.c"
|
||||
"crypto/x509/v3_conf.c"
|
||||
"crypto/x509/v3_cpols.c"
|
||||
"crypto/x509/v3_crld.c"
|
||||
"crypto/x509/v3_enum.c"
|
||||
"crypto/x509/v3_extku.c"
|
||||
"crypto/x509/v3_genn.c"
|
||||
"crypto/x509/v3_ia5.c"
|
||||
"crypto/x509/v3_info.c"
|
||||
"crypto/x509/v3_int.c"
|
||||
"crypto/x509/v3_lib.c"
|
||||
"crypto/x509/v3_ncons.c"
|
||||
"crypto/x509/v3_ocsp.c"
|
||||
"crypto/x509/v3_pcons.c"
|
||||
"crypto/x509/v3_pmaps.c"
|
||||
"crypto/x509/v3_prn.c"
|
||||
"crypto/x509/v3_purp.c"
|
||||
"crypto/x509/v3_skey.c"
|
||||
"crypto/x509/v3_utl.c"
|
||||
"crypto/x509/x509.c"
|
||||
"crypto/x509/x509_att.c"
|
||||
"crypto/x509/x509_cmp.c"
|
||||
@@ -253,7 +283,9 @@ add_library(CCryptoBoringSSL STATIC
|
||||
"crypto/x509/x_attrib.c"
|
||||
"crypto/x509/x_crl.c"
|
||||
"crypto/x509/x_exten.c"
|
||||
"crypto/x509/x_info.c"
|
||||
"crypto/x509/x_name.c"
|
||||
"crypto/x509/x_pkey.c"
|
||||
"crypto/x509/x_pubkey.c"
|
||||
"crypto/x509/x_req.c"
|
||||
"crypto/x509/x_sig.c"
|
||||
@@ -261,80 +293,102 @@ add_library(CCryptoBoringSSL STATIC
|
||||
"crypto/x509/x_val.c"
|
||||
"crypto/x509/x_x509.c"
|
||||
"crypto/x509/x_x509a.c"
|
||||
"gen/crypto/err_data.c")
|
||||
"crypto/x509v3/v3_akey.c"
|
||||
"crypto/x509v3/v3_akeya.c"
|
||||
"crypto/x509v3/v3_alt.c"
|
||||
"crypto/x509v3/v3_bcons.c"
|
||||
"crypto/x509v3/v3_bitst.c"
|
||||
"crypto/x509v3/v3_conf.c"
|
||||
"crypto/x509v3/v3_cpols.c"
|
||||
"crypto/x509v3/v3_crld.c"
|
||||
"crypto/x509v3/v3_enum.c"
|
||||
"crypto/x509v3/v3_extku.c"
|
||||
"crypto/x509v3/v3_genn.c"
|
||||
"crypto/x509v3/v3_ia5.c"
|
||||
"crypto/x509v3/v3_info.c"
|
||||
"crypto/x509v3/v3_int.c"
|
||||
"crypto/x509v3/v3_lib.c"
|
||||
"crypto/x509v3/v3_ncons.c"
|
||||
"crypto/x509v3/v3_ocsp.c"
|
||||
"crypto/x509v3/v3_pcons.c"
|
||||
"crypto/x509v3/v3_pmaps.c"
|
||||
"crypto/x509v3/v3_prn.c"
|
||||
"crypto/x509v3/v3_purp.c"
|
||||
"crypto/x509v3/v3_skey.c"
|
||||
"crypto/x509v3/v3_utl.c")
|
||||
|
||||
if(CMAKE_SYSTEM_NAME STREQUAL Darwin AND CMAKE_SYSTEM_PROCESSOR MATCHES "amd64|x86_64")
|
||||
target_sources(CCryptoBoringSSL PRIVATE
|
||||
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)
|
||||
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)
|
||||
elseif(CMAKE_SYSTEM_NAME MATCHES "Linux|Android" AND CMAKE_SYSTEM_PROCESSOR MATCHES "amd64|x86_64")
|
||||
target_sources(CCryptoBoringSSL PRIVATE
|
||||
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)
|
||||
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)
|
||||
elseif(CMAKE_SYSTEM_NAME STREQUAL Darwin AND CMAKE_SYSTEM_PROCESSOR MATCHES "arm64|aarch64")
|
||||
target_sources(CCryptoBoringSSL PRIVATE
|
||||
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)
|
||||
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)
|
||||
elseif(CMAKE_SYSTEM_NAME MATCHES "Linux|Android" AND CMAKE_SYSTEM_PROCESSOR MATCHES "arm64|aarch64")
|
||||
target_sources(CCryptoBoringSSL PRIVATE
|
||||
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)
|
||||
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)
|
||||
endif()
|
||||
|
||||
target_include_directories(CCryptoBoringSSL PUBLIC
|
||||
|
||||
-15
@@ -1,15 +0,0 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
|
||||
<plist version="1.0">
|
||||
<dict>
|
||||
<key>NSPrivacyTracking</key>
|
||||
<false/>
|
||||
<key>NSPrivacyAccessedAPITypes</key>
|
||||
<array/>
|
||||
<key>NSPrivacyCollectedDataTypes</key>
|
||||
<array/>
|
||||
<key>NSPrivacyTrackingDomains</key>
|
||||
<array/>
|
||||
</dict>
|
||||
</plist>
|
||||
|
||||
@@ -58,7 +58,7 @@
|
||||
#include <CCryptoBoringSSL_bytestring.h>
|
||||
#include <CCryptoBoringSSL_err.h>
|
||||
#include <CCryptoBoringSSL_mem.h>
|
||||
#include <CCryptoBoringSSL_posix_time.h>
|
||||
#include <CCryptoBoringSSL_time.h>
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
@@ -97,22 +97,22 @@ int ASN1_mbstring_ncopy(ASN1_STRING **out, const unsigned char *in,
|
||||
int error;
|
||||
switch (inform) {
|
||||
case MBSTRING_BMP:
|
||||
decode_func = CBS_get_ucs2_be;
|
||||
decode_func = cbs_get_ucs2_be;
|
||||
error = ASN1_R_INVALID_BMPSTRING;
|
||||
break;
|
||||
|
||||
case MBSTRING_UNIV:
|
||||
decode_func = CBS_get_utf32_be;
|
||||
decode_func = cbs_get_utf32_be;
|
||||
error = ASN1_R_INVALID_UNIVERSALSTRING;
|
||||
break;
|
||||
|
||||
case MBSTRING_UTF8:
|
||||
decode_func = CBS_get_utf8;
|
||||
decode_func = cbs_get_utf8;
|
||||
error = ASN1_R_INVALID_UTF8STRING;
|
||||
break;
|
||||
|
||||
case MBSTRING_ASC:
|
||||
decode_func = CBS_get_latin1;
|
||||
decode_func = cbs_get_latin1;
|
||||
error = ERR_R_INTERNAL_ERROR; // Latin-1 inputs are never invalid.
|
||||
break;
|
||||
|
||||
@@ -162,7 +162,7 @@ int ASN1_mbstring_ncopy(ASN1_STRING **out, const unsigned char *in,
|
||||
}
|
||||
|
||||
nchar++;
|
||||
utf8_len += CBB_get_utf8_len(c);
|
||||
utf8_len += cbb_get_utf8_len(c);
|
||||
if (maxsize > 0 && nchar > (size_t)maxsize) {
|
||||
OPENSSL_PUT_ERROR(ASN1, ASN1_R_STRING_TOO_LONG);
|
||||
ERR_add_error_dataf("maxsize=%zu", (size_t)maxsize);
|
||||
@@ -178,7 +178,7 @@ int ASN1_mbstring_ncopy(ASN1_STRING **out, const unsigned char *in,
|
||||
|
||||
// Now work out output format and string type
|
||||
int str_type;
|
||||
int (*encode_func)(CBB *, uint32_t) = CBB_add_latin1;
|
||||
int (*encode_func)(CBB *, uint32_t) = cbb_add_latin1;
|
||||
size_t size_estimate = nchar;
|
||||
int outform = MBSTRING_ASC;
|
||||
if (mask & B_ASN1_PRINTABLESTRING) {
|
||||
@@ -190,17 +190,17 @@ int ASN1_mbstring_ncopy(ASN1_STRING **out, const unsigned char *in,
|
||||
} else if (mask & B_ASN1_BMPSTRING) {
|
||||
str_type = V_ASN1_BMPSTRING;
|
||||
outform = MBSTRING_BMP;
|
||||
encode_func = CBB_add_ucs2_be;
|
||||
encode_func = cbb_add_ucs2_be;
|
||||
size_estimate = 2 * nchar;
|
||||
} else if (mask & B_ASN1_UNIVERSALSTRING) {
|
||||
str_type = V_ASN1_UNIVERSALSTRING;
|
||||
encode_func = CBB_add_utf32_be;
|
||||
encode_func = cbb_add_utf32_be;
|
||||
size_estimate = 4 * nchar;
|
||||
outform = MBSTRING_UNIV;
|
||||
} else if (mask & B_ASN1_UTF8STRING) {
|
||||
str_type = V_ASN1_UTF8STRING;
|
||||
outform = MBSTRING_UTF8;
|
||||
encode_func = CBB_add_utf8;
|
||||
encode_func = cbb_add_utf8;
|
||||
size_estimate = utf8_len;
|
||||
} else {
|
||||
OPENSSL_PUT_ERROR(ASN1, ASN1_R_ILLEGAL_CHARACTERS);
|
||||
|
||||
@@ -68,7 +68,6 @@
|
||||
#include <CCryptoBoringSSL_mem.h>
|
||||
|
||||
#include "../bytestring/internal.h"
|
||||
#include "../internal.h"
|
||||
#include "internal.h"
|
||||
|
||||
|
||||
@@ -138,19 +137,19 @@ static int do_buf(const unsigned char *buf, int buflen, int encoding,
|
||||
int get_char_error;
|
||||
switch (encoding) {
|
||||
case MBSTRING_UNIV:
|
||||
get_char = CBS_get_utf32_be;
|
||||
get_char = cbs_get_utf32_be;
|
||||
get_char_error = ASN1_R_INVALID_UNIVERSALSTRING;
|
||||
break;
|
||||
case MBSTRING_BMP:
|
||||
get_char = CBS_get_ucs2_be;
|
||||
get_char = cbs_get_ucs2_be;
|
||||
get_char_error = ASN1_R_INVALID_BMPSTRING;
|
||||
break;
|
||||
case MBSTRING_ASC:
|
||||
get_char = CBS_get_latin1;
|
||||
get_char = cbs_get_latin1;
|
||||
get_char_error = ERR_R_INTERNAL_ERROR; // Should not be possible.
|
||||
break;
|
||||
case MBSTRING_UTF8:
|
||||
get_char = CBS_get_utf8;
|
||||
get_char = cbs_get_utf8;
|
||||
get_char_error = ASN1_R_INVALID_UTF8STRING;
|
||||
break;
|
||||
default:
|
||||
@@ -173,7 +172,7 @@ static int do_buf(const unsigned char *buf, int buflen, int encoding,
|
||||
uint8_t utf8_buf[6];
|
||||
CBB utf8_cbb;
|
||||
CBB_init_fixed(&utf8_cbb, utf8_buf, sizeof(utf8_buf));
|
||||
if (!CBB_add_utf8(&utf8_cbb, c)) {
|
||||
if (!cbb_add_utf8(&utf8_cbb, c)) {
|
||||
OPENSSL_PUT_ERROR(ASN1, ERR_R_INTERNAL_ERROR);
|
||||
return 1;
|
||||
}
|
||||
@@ -239,8 +238,22 @@ static int do_dump(unsigned long flags, BIO *out, const ASN1_STRING *str) {
|
||||
// Placing the ASN1_STRING in a temporary ASN1_TYPE allows the DER encoding
|
||||
// to readily obtained.
|
||||
ASN1_TYPE t;
|
||||
OPENSSL_memset(&t, 0, sizeof(ASN1_TYPE));
|
||||
asn1_type_set0_string(&t, (ASN1_STRING *)str);
|
||||
t.type = str->type;
|
||||
// Negative INTEGER and ENUMERATED values are the only case where
|
||||
// |ASN1_STRING| and |ASN1_TYPE| types do not match.
|
||||
//
|
||||
// TODO(davidben): There are also some type fields which, in |ASN1_TYPE|, do
|
||||
// not correspond to |ASN1_STRING|. It is unclear whether those are allowed
|
||||
// in |ASN1_STRING| at all, or what the space of allowed types is.
|
||||
// |ASN1_item_ex_d2i| will never produce such a value so, for now, we say
|
||||
// this is an invalid input. But this corner of the library in general
|
||||
// should be more robust.
|
||||
if (t.type == V_ASN1_NEG_INTEGER) {
|
||||
t.type = V_ASN1_INTEGER;
|
||||
} else if (t.type == V_ASN1_NEG_ENUMERATED) {
|
||||
t.type = V_ASN1_ENUMERATED;
|
||||
}
|
||||
t.value.asn1_string = (ASN1_STRING *)str;
|
||||
unsigned char *der_buf = NULL;
|
||||
int der_len = i2d_ASN1_TYPE(&t, &der_buf);
|
||||
if (der_len < 0) {
|
||||
|
||||
@@ -55,7 +55,7 @@
|
||||
* [including the GNU Public Licence.] */
|
||||
|
||||
#include <CCryptoBoringSSL_asn1.h>
|
||||
#include <CCryptoBoringSSL_posix_time.h>
|
||||
#include <CCryptoBoringSSL_time.h>
|
||||
|
||||
#include <string.h>
|
||||
#include <time.h>
|
||||
|
||||
@@ -56,8 +56,7 @@
|
||||
|
||||
#include <CCryptoBoringSSL_asn1.h>
|
||||
|
||||
#include <assert.h>
|
||||
|
||||
#include <CCryptoBoringSSL_asn1t.h>
|
||||
#include <CCryptoBoringSSL_err.h>
|
||||
#include <CCryptoBoringSSL_mem.h>
|
||||
#include <CCryptoBoringSSL_obj.h>
|
||||
@@ -90,23 +89,6 @@ const void *asn1_type_value_as_pointer(const ASN1_TYPE *a) {
|
||||
}
|
||||
}
|
||||
|
||||
void asn1_type_set0_string(ASN1_TYPE *a, ASN1_STRING *str) {
|
||||
// |ASN1_STRING| types are almost the same as |ASN1_TYPE| types, except that
|
||||
// the negative flag is not reflected into |ASN1_TYPE|.
|
||||
int type = str->type;
|
||||
if (type == V_ASN1_NEG_INTEGER) {
|
||||
type = V_ASN1_INTEGER;
|
||||
} else if (type == V_ASN1_NEG_ENUMERATED) {
|
||||
type = V_ASN1_ENUMERATED;
|
||||
}
|
||||
|
||||
// These types are not |ASN1_STRING| types and use a different
|
||||
// representation when stored in |ASN1_TYPE|.
|
||||
assert(type != V_ASN1_NULL && type != V_ASN1_OBJECT &&
|
||||
type != V_ASN1_BOOLEAN);
|
||||
ASN1_TYPE_set(a, type, str);
|
||||
}
|
||||
|
||||
void asn1_type_cleanup(ASN1_TYPE *a) {
|
||||
switch (a->type) {
|
||||
case V_ASN1_NULL:
|
||||
|
||||
@@ -58,7 +58,7 @@
|
||||
#include <CCryptoBoringSSL_bytestring.h>
|
||||
#include <CCryptoBoringSSL_err.h>
|
||||
#include <CCryptoBoringSSL_mem.h>
|
||||
#include <CCryptoBoringSSL_posix_time.h>
|
||||
#include <CCryptoBoringSSL_time.h>
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
@@ -102,15 +102,6 @@ OPENSSL_DECLARE_ERROR_REASON(ASN1, UNKNOWN_FORMAT)
|
||||
OPENSSL_DECLARE_ERROR_REASON(ASN1, UNKNOWN_TAG)
|
||||
OPENSSL_DECLARE_ERROR_REASON(ASN1, UNSUPPORTED_TYPE)
|
||||
|
||||
// Limit |ASN1_STRING|s to 64 MiB of data. Most of this module, as well as
|
||||
// downstream code, does not correctly handle overflow. We cap string fields
|
||||
// more tightly than strictly necessary to fit in |int|. This is not expected to
|
||||
// impact real world uses of this field.
|
||||
//
|
||||
// In particular, this limit is small enough that the bit count of a BIT STRING
|
||||
// comfortably fits in an |int|, with room for arithmetic.
|
||||
#define ASN1_STRING_MAX (64 * 1024 * 1024)
|
||||
|
||||
static void asn1_put_length(unsigned char **pp, int length);
|
||||
|
||||
int ASN1_get_object(const unsigned char **inp, long *out_len, int *out_tag,
|
||||
@@ -282,8 +273,9 @@ int ASN1_STRING_set(ASN1_STRING *str, const void *_data, ossl_ssize_t len_s) {
|
||||
len = (size_t)len_s;
|
||||
}
|
||||
|
||||
static_assert(ASN1_STRING_MAX < INT_MAX, "len will not overflow int");
|
||||
if (len > ASN1_STRING_MAX) {
|
||||
// |ASN1_STRING| cannot represent strings that exceed |int|, and we must
|
||||
// reserve space for a trailing NUL below.
|
||||
if (len > INT_MAX || len + 1 < len) {
|
||||
OPENSSL_PUT_ERROR(ASN1, ERR_R_OVERFLOW);
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -76,12 +76,18 @@ extern "C" {
|
||||
// returned. On failure NULL is returned.
|
||||
OPENSSL_EXPORT struct tm *OPENSSL_gmtime(const time_t *time, struct tm *result);
|
||||
|
||||
// OPENSSL_timegm converts a time value between the years 0 and 9999 in |tm| to
|
||||
// a time_t value in |out|. One is returned on success, zero is returned on
|
||||
// failure. It is a failure if the converted time can not be represented in a
|
||||
// time_t, or if the tm contains out of range values.
|
||||
OPENSSL_EXPORT int OPENSSL_timegm(const struct tm *tm, time_t *out);
|
||||
|
||||
// OPENSSL_gmtime_adj returns one on success, and updates |tm| by adding
|
||||
// |offset_day| days and |offset_sec| seconds. It returns zero on failure. |tm|
|
||||
// must be in the range of year 0000 to 9999 both before and after the update or
|
||||
// a failure will be returned.
|
||||
OPENSSL_EXPORT int OPENSSL_gmtime_adj(struct tm *tm, int offset_day,
|
||||
int64_t offset_sec);
|
||||
long offset_sec);
|
||||
|
||||
// OPENSSL_gmtime_diff calculates the difference between |from| and |to|. It
|
||||
// returns one, and outputs the difference as a number of days and seconds in
|
||||
@@ -204,10 +210,6 @@ void asn1_encoding_clear(ASN1_ENCODING *enc);
|
||||
// a pointer.
|
||||
const void *asn1_type_value_as_pointer(const ASN1_TYPE *a);
|
||||
|
||||
// asn1_type_set0_string sets |a|'s value to the object represented by |str| and
|
||||
// takes ownership of |str|.
|
||||
void asn1_type_set0_string(ASN1_TYPE *a, ASN1_STRING *str);
|
||||
|
||||
// asn1_type_cleanup releases memory associated with |a|'s value, without
|
||||
// freeing |a| itself.
|
||||
void asn1_type_cleanup(ASN1_TYPE *a);
|
||||
@@ -254,6 +256,7 @@ typedef void ASN1_ex_free_func(ASN1_VALUE **pval, const ASN1_ITEM *it);
|
||||
typedef struct ASN1_EXTERN_FUNCS_st {
|
||||
ASN1_ex_new_func *asn1_ex_new;
|
||||
ASN1_ex_free_func *asn1_ex_free;
|
||||
ASN1_ex_free_func *asn1_ex_clear;
|
||||
ASN1_ex_d2i *asn1_ex_d2i;
|
||||
ASN1_ex_i2d *asn1_ex_i2d;
|
||||
} ASN1_EXTERN_FUNCS;
|
||||
|
||||
@@ -15,7 +15,7 @@
|
||||
// Time conversion to/from POSIX time_t and struct tm, with no support
|
||||
// for time zones other than UTC
|
||||
|
||||
#include <CCryptoBoringSSL_posix_time.h>
|
||||
#include <CCryptoBoringSSL_time.h>
|
||||
|
||||
#include <assert.h>
|
||||
#include <inttypes.h>
|
||||
@@ -26,12 +26,12 @@
|
||||
#include "internal.h"
|
||||
|
||||
#define SECS_PER_HOUR (60 * 60)
|
||||
#define SECS_PER_DAY (INT64_C(24) * SECS_PER_HOUR)
|
||||
#define SECS_PER_DAY (24 * SECS_PER_HOUR)
|
||||
|
||||
|
||||
// Is a year/month/day combination valid, in the range from year 0000
|
||||
// to 9999?
|
||||
static int is_valid_date(int64_t year, int64_t month, int64_t day) {
|
||||
static int is_valid_date(int year, int month, int day) {
|
||||
if (day < 1 || month < 1 || year < 0 || year > 9999) {
|
||||
return 0;
|
||||
}
|
||||
@@ -62,7 +62,7 @@ static int is_valid_date(int64_t year, int64_t month, int64_t day) {
|
||||
|
||||
// Is a time valid? Leap seconds of 60 are not considered valid, as
|
||||
// the POSIX time in seconds does not include them.
|
||||
static int is_valid_time(int64_t hours, int64_t minutes, int64_t seconds) {
|
||||
static int is_valid_time(int hours, int minutes, int seconds) {
|
||||
if (hours < 0 || minutes < 0 || seconds < 0 || hours > 23 || minutes > 59 ||
|
||||
seconds > 59) {
|
||||
return 0;
|
||||
@@ -70,22 +70,17 @@ static int is_valid_time(int64_t hours, int64_t minutes, int64_t seconds) {
|
||||
return 1;
|
||||
}
|
||||
|
||||
// 0000-01-01 00:00:00 UTC
|
||||
#define MIN_POSIX_TIME INT64_C(-62167219200)
|
||||
// 9999-12-31 23:59:59 UTC
|
||||
#define MAX_POSIX_TIME INT64_C(253402300799)
|
||||
|
||||
// Is an int64 time within our expected range?
|
||||
static int is_valid_posix_time(int64_t time) {
|
||||
return MIN_POSIX_TIME <= time && time <= MAX_POSIX_TIME;
|
||||
// Is a int64 time representing a time within our expected range?
|
||||
static int is_valid_epoch_time(int64_t time) {
|
||||
// 0000-01-01 00:00:00 UTC to 9999-12-31 23:59:59 UTC
|
||||
return (int64_t)-62167219200 <= time && time <= (int64_t)253402300799;
|
||||
}
|
||||
|
||||
// Inspired by algorithms presented in
|
||||
// https://howardhinnant.github.io/date_algorithms.html
|
||||
// (Public Domain)
|
||||
static int posix_time_from_utc(int64_t year, int64_t month, int64_t day,
|
||||
int64_t hours, int64_t minutes, int64_t seconds,
|
||||
int64_t *out_time) {
|
||||
static int posix_time_from_utc(int year, int month, int day, int hours,
|
||||
int minutes, int seconds, int64_t *out_time) {
|
||||
if (!is_valid_date(year, month, day) ||
|
||||
!is_valid_time(hours, minutes, seconds)) {
|
||||
return 0;
|
||||
@@ -113,7 +108,7 @@ static int posix_time_from_utc(int64_t year, int64_t month, int64_t day,
|
||||
static int utc_from_posix_time(int64_t time, int *out_year, int *out_month,
|
||||
int *out_day, int *out_hours, int *out_minutes,
|
||||
int *out_seconds) {
|
||||
if (!is_valid_posix_time(time)) {
|
||||
if (!is_valid_epoch_time(time)) {
|
||||
return 0;
|
||||
}
|
||||
int64_t days = time / SECS_PER_DAY;
|
||||
@@ -148,21 +143,19 @@ static int utc_from_posix_time(int64_t time, int *out_year, int *out_month,
|
||||
}
|
||||
|
||||
int OPENSSL_tm_to_posix(const struct tm *tm, int64_t *out) {
|
||||
return posix_time_from_utc(tm->tm_year + INT64_C(1900),
|
||||
tm->tm_mon + INT64_C(1), tm->tm_mday, tm->tm_hour,
|
||||
tm->tm_min, tm->tm_sec, out);
|
||||
return posix_time_from_utc(tm->tm_year + 1900, tm->tm_mon + 1, tm->tm_mday,
|
||||
tm->tm_hour, tm->tm_min, tm->tm_sec, out);
|
||||
}
|
||||
|
||||
int OPENSSL_posix_to_tm(int64_t time, struct tm *out_tm) {
|
||||
struct tm tmp_tm = {0};
|
||||
if (!utc_from_posix_time(time, &tmp_tm.tm_year, &tmp_tm.tm_mon,
|
||||
&tmp_tm.tm_mday, &tmp_tm.tm_hour, &tmp_tm.tm_min,
|
||||
&tmp_tm.tm_sec)) {
|
||||
memset(out_tm, 0, sizeof(struct tm));
|
||||
if (!utc_from_posix_time(time, &out_tm->tm_year, &out_tm->tm_mon,
|
||||
&out_tm->tm_mday, &out_tm->tm_hour, &out_tm->tm_min,
|
||||
&out_tm->tm_sec)) {
|
||||
return 0;
|
||||
}
|
||||
tmp_tm.tm_year -= 1900;
|
||||
tmp_tm.tm_mon -= 1;
|
||||
*out_tm = tmp_tm;
|
||||
out_tm->tm_year -= 1900;
|
||||
out_tm->tm_mon -= 1;
|
||||
|
||||
return 1;
|
||||
}
|
||||
@@ -194,47 +187,43 @@ struct tm *OPENSSL_gmtime(const time_t *time, struct tm *out_tm) {
|
||||
return out_tm;
|
||||
}
|
||||
|
||||
int OPENSSL_gmtime_adj(struct tm *tm, int offset_day, int64_t offset_sec) {
|
||||
int OPENSSL_gmtime_adj(struct tm *tm, int off_day, long offset_sec) {
|
||||
int64_t posix_time;
|
||||
if (!OPENSSL_tm_to_posix(tm, &posix_time)) {
|
||||
if (!posix_time_from_utc(tm->tm_year + 1900, tm->tm_mon + 1, tm->tm_mday,
|
||||
tm->tm_hour, tm->tm_min, tm->tm_sec, &posix_time)) {
|
||||
return 0;
|
||||
}
|
||||
static_assert(INT_MAX <= INT64_MAX / SECS_PER_DAY,
|
||||
"day offset in seconds cannot overflow");
|
||||
static_assert(MAX_POSIX_TIME <= INT64_MAX - INT_MAX * SECS_PER_DAY,
|
||||
"addition cannot overflow");
|
||||
static_assert(MIN_POSIX_TIME >= INT64_MIN - INT_MIN * SECS_PER_DAY,
|
||||
"addition cannot underflow");
|
||||
posix_time += offset_day * SECS_PER_DAY;
|
||||
if (posix_time > 0 && offset_sec > INT64_MAX - posix_time) {
|
||||
return 0;
|
||||
}
|
||||
if (posix_time < 0 && offset_sec < INT64_MIN - posix_time) {
|
||||
return 0;
|
||||
}
|
||||
posix_time += offset_sec;
|
||||
|
||||
if (!OPENSSL_posix_to_tm(posix_time, tm)) {
|
||||
if (!utc_from_posix_time(
|
||||
posix_time + (int64_t)off_day * SECS_PER_DAY + offset_sec,
|
||||
&tm->tm_year, &tm->tm_mon, &tm->tm_mday, &tm->tm_hour, &tm->tm_min,
|
||||
&tm->tm_sec)) {
|
||||
return 0;
|
||||
}
|
||||
tm->tm_year -= 1900;
|
||||
tm->tm_mon -= 1;
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
int OPENSSL_gmtime_diff(int *out_days, int *out_secs, const struct tm *from,
|
||||
const struct tm *to) {
|
||||
int64_t time_to, time_from;
|
||||
if (!OPENSSL_tm_to_posix(to, &time_to) ||
|
||||
!OPENSSL_tm_to_posix(from, &time_from)) {
|
||||
int64_t time_to;
|
||||
if (!posix_time_from_utc(to->tm_year + 1900, to->tm_mon + 1, to->tm_mday,
|
||||
to->tm_hour, to->tm_min, to->tm_sec, &time_to)) {
|
||||
return 0;
|
||||
}
|
||||
int64_t time_from;
|
||||
if (!posix_time_from_utc(from->tm_year + 1900, from->tm_mon + 1,
|
||||
from->tm_mday, from->tm_hour, from->tm_min,
|
||||
from->tm_sec, &time_from)) {
|
||||
return 0;
|
||||
}
|
||||
// Times are in range, so these calculations can not overflow.
|
||||
static_assert(SECS_PER_DAY <= INT_MAX, "seconds per day does not fit in int");
|
||||
static_assert((MAX_POSIX_TIME - MIN_POSIX_TIME) / SECS_PER_DAY <= INT_MAX,
|
||||
"range of valid POSIX times, in days, does not fit in int");
|
||||
int64_t timediff = time_to - time_from;
|
||||
int64_t daydiff = timediff / SECS_PER_DAY;
|
||||
timediff %= SECS_PER_DAY;
|
||||
if (daydiff > INT_MAX || daydiff < INT_MIN) {
|
||||
return 0;
|
||||
}
|
||||
*out_secs = (int)timediff;
|
||||
*out_days = (int)daydiff;
|
||||
return 1;
|
||||
|
||||
@@ -850,7 +850,7 @@ static int asn1_ex_c2i(ASN1_VALUE **pval, const unsigned char *cont, long len,
|
||||
if (utype == V_ASN1_BMPSTRING) {
|
||||
while (CBS_len(&cbs) != 0) {
|
||||
uint32_t c;
|
||||
if (!CBS_get_ucs2_be(&cbs, &c)) {
|
||||
if (!cbs_get_ucs2_be(&cbs, &c)) {
|
||||
OPENSSL_PUT_ERROR(ASN1, ASN1_R_INVALID_BMPSTRING);
|
||||
goto err;
|
||||
}
|
||||
@@ -859,7 +859,7 @@ static int asn1_ex_c2i(ASN1_VALUE **pval, const unsigned char *cont, long len,
|
||||
if (utype == V_ASN1_UNIVERSALSTRING) {
|
||||
while (CBS_len(&cbs) != 0) {
|
||||
uint32_t c;
|
||||
if (!CBS_get_utf32_be(&cbs, &c)) {
|
||||
if (!cbs_get_utf32_be(&cbs, &c)) {
|
||||
OPENSSL_PUT_ERROR(ASN1, ASN1_R_INVALID_UNIVERSALSTRING);
|
||||
goto err;
|
||||
}
|
||||
@@ -868,7 +868,7 @@ static int asn1_ex_c2i(ASN1_VALUE **pval, const unsigned char *cont, long len,
|
||||
if (utype == V_ASN1_UTF8STRING) {
|
||||
while (CBS_len(&cbs) != 0) {
|
||||
uint32_t c;
|
||||
if (!CBS_get_utf8(&cbs, &c)) {
|
||||
if (!cbs_get_utf8(&cbs, &c)) {
|
||||
OPENSSL_PUT_ERROR(ASN1, ASN1_R_INVALID_UTF8STRING);
|
||||
goto err;
|
||||
}
|
||||
|
||||
@@ -452,9 +452,14 @@ static int asn1_set_seq_out(STACK_OF(ASN1_VALUE) *sk, unsigned char **out,
|
||||
return 1;
|
||||
}
|
||||
|
||||
if (sk_ASN1_VALUE_num(sk) > ((size_t)-1) / sizeof(DER_ENC)) {
|
||||
OPENSSL_PUT_ERROR(ASN1, ERR_R_OVERFLOW);
|
||||
return 0;
|
||||
}
|
||||
|
||||
int ret = 0;
|
||||
unsigned char *const buf = OPENSSL_malloc(skcontlen);
|
||||
DER_ENC *encoded = OPENSSL_calloc(sk_ASN1_VALUE_num(sk), sizeof(*encoded));
|
||||
DER_ENC *encoded = OPENSSL_malloc(sk_ASN1_VALUE_num(sk) * sizeof(*encoded));
|
||||
if (encoded == NULL || buf == NULL) {
|
||||
goto err;
|
||||
}
|
||||
|
||||
@@ -127,10 +127,11 @@ int ASN1_item_ex_new(ASN1_VALUE **pval, const ASN1_ITEM *it) {
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
*pval = OPENSSL_zalloc(it->size);
|
||||
*pval = OPENSSL_malloc(it->size);
|
||||
if (!*pval) {
|
||||
goto memerr;
|
||||
}
|
||||
OPENSSL_memset(*pval, 0, it->size);
|
||||
asn1_set_choice_selector(pval, -1, it);
|
||||
if (asn1_cb && !asn1_cb(ASN1_OP_NEW_POST, pval, it, NULL)) {
|
||||
goto auxerr2;
|
||||
@@ -150,10 +151,11 @@ int ASN1_item_ex_new(ASN1_VALUE **pval, const ASN1_ITEM *it) {
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
*pval = OPENSSL_zalloc(it->size);
|
||||
*pval = OPENSSL_malloc(it->size);
|
||||
if (!*pval) {
|
||||
goto memerr;
|
||||
}
|
||||
OPENSSL_memset(*pval, 0, it->size);
|
||||
asn1_refcount_set_one(pval, it);
|
||||
asn1_enc_init(pval, it);
|
||||
for (i = 0, tt = it->templates; i < it->tcount; tt++, i++) {
|
||||
@@ -183,9 +185,16 @@ auxerr:
|
||||
}
|
||||
|
||||
static void asn1_item_clear(ASN1_VALUE **pval, const ASN1_ITEM *it) {
|
||||
const ASN1_EXTERN_FUNCS *ef;
|
||||
|
||||
switch (it->itype) {
|
||||
case ASN1_ITYPE_EXTERN:
|
||||
*pval = NULL;
|
||||
ef = it->funcs;
|
||||
if (ef && ef->asn1_ex_clear) {
|
||||
ef->asn1_ex_clear(pval, it);
|
||||
} else {
|
||||
*pval = NULL;
|
||||
}
|
||||
break;
|
||||
|
||||
case ASN1_ITYPE_PRIMITIVE:
|
||||
@@ -267,7 +276,7 @@ static int ASN1_primitive_new(ASN1_VALUE **pval, const ASN1_ITEM *it) {
|
||||
}
|
||||
switch (utype) {
|
||||
case V_ASN1_OBJECT:
|
||||
*pval = (ASN1_VALUE *)OBJ_get_undef();
|
||||
*pval = (ASN1_VALUE *)OBJ_nid2obj(NID_undef);
|
||||
return 1;
|
||||
|
||||
case V_ASN1_BOOLEAN:
|
||||
|
||||
@@ -121,7 +121,12 @@ int EVP_EncodedLength(size_t *out_len, size_t len) {
|
||||
}
|
||||
|
||||
EVP_ENCODE_CTX *EVP_ENCODE_CTX_new(void) {
|
||||
return OPENSSL_zalloc(sizeof(EVP_ENCODE_CTX));
|
||||
EVP_ENCODE_CTX *ret = OPENSSL_malloc(sizeof(EVP_ENCODE_CTX));
|
||||
if (ret == NULL) {
|
||||
return NULL;
|
||||
}
|
||||
OPENSSL_memset(ret, 0, sizeof(EVP_ENCODE_CTX));
|
||||
return ret;
|
||||
}
|
||||
|
||||
void EVP_ENCODE_CTX_free(EVP_ENCODE_CTX *ctx) {
|
||||
@@ -307,10 +312,6 @@ 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.
|
||||
|
||||
@@ -1,119 +0,0 @@
|
||||
/* 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_SUPPORT_H
|
||||
#define OPENSSL_HEADER_CRYPTO_BCM_SUPPORT_H
|
||||
|
||||
#include <CCryptoBoringSSL_base.h>
|
||||
|
||||
#include <stdio.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
|
||||
// duplication.
|
||||
#define OPENSSL_FORK_DETECTION
|
||||
#define OPENSSL_FORK_DETECTION_MADVISE
|
||||
#elif defined(OPENSSL_MACOS) || defined(OPENSSL_IOS) || \
|
||||
defined(OPENSSL_OPENBSD) || defined(OPENSSL_FREEBSD)
|
||||
// These platforms may detect address space duplication with pthread_atfork.
|
||||
// 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) || \
|
||||
defined(__ZEPHYR__) || defined(CROS_EC)
|
||||
// These platforms do not fork.
|
||||
#define OPENSSL_DOES_NOT_FORK
|
||||
#endif
|
||||
|
||||
#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
|
||||
// is a non-zero, strictly-monotonic counter with the property that, if queried
|
||||
// in an address space and then again in a subsequently forked copy, the forked
|
||||
// address space will observe a greater value.
|
||||
//
|
||||
// This function may be used to clear cached values across a fork. When
|
||||
// initializing a cache, record the fork generation. Before using the cache,
|
||||
// check if the fork generation has changed. If so, drop the cache and update
|
||||
// the save fork generation. Note this logic transparently handles platforms
|
||||
// which always return zero.
|
||||
//
|
||||
// This is not reliably supported on all platforms which implement |fork|, so it
|
||||
// should only be used as a hardening measure.
|
||||
OPENSSL_EXPORT uint64_t CRYPTO_get_fork_generation(void);
|
||||
|
||||
// CRYPTO_fork_detect_force_madv_wipeonfork_for_testing is an internal detail
|
||||
// used for testing purposes.
|
||||
OPENSSL_EXPORT void CRYPTO_fork_detect_force_madv_wipeonfork_for_testing(
|
||||
int on);
|
||||
|
||||
// CRYPTO_get_stderr returns stderr. This function exists to avoid BCM needing
|
||||
// a data dependency on libc.
|
||||
FILE *CRYPTO_get_stderr(void);
|
||||
|
||||
|
||||
#if defined(__cplusplus)
|
||||
} // extern C
|
||||
#endif
|
||||
|
||||
#endif // OPENSSL_HEADER_CRYPTO_BCM_SUPPORT_H
|
||||
@@ -69,19 +69,16 @@
|
||||
#include "../internal.h"
|
||||
|
||||
|
||||
static CRYPTO_EX_DATA_CLASS g_ex_data_class =
|
||||
CRYPTO_EX_DATA_CLASS_INIT_WITH_APP_DATA;
|
||||
|
||||
BIO *BIO_new(const BIO_METHOD *method) {
|
||||
BIO *ret = OPENSSL_zalloc(sizeof(BIO));
|
||||
BIO *ret = OPENSSL_malloc(sizeof(BIO));
|
||||
if (ret == NULL) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
OPENSSL_memset(ret, 0, sizeof(BIO));
|
||||
ret->method = method;
|
||||
ret->shutdown = 1;
|
||||
ret->references = 1;
|
||||
CRYPTO_new_ex_data(&ret->ex_data);
|
||||
|
||||
if (method->create != NULL && !method->create(ret)) {
|
||||
OPENSSL_free(ret);
|
||||
@@ -105,7 +102,6 @@ int BIO_free(BIO *bio) {
|
||||
bio->method->destroy(bio);
|
||||
}
|
||||
|
||||
CRYPTO_free_ex_data(&g_ex_data_class, bio, &bio->ex_data);
|
||||
OPENSSL_free(bio);
|
||||
}
|
||||
return 1;
|
||||
@@ -345,11 +341,11 @@ int BIO_set_close(BIO *bio, int close_flag) {
|
||||
return (int)BIO_ctrl(bio, BIO_CTRL_SET_CLOSE, close_flag, NULL);
|
||||
}
|
||||
|
||||
OPENSSL_EXPORT uint64_t BIO_number_read(const BIO *bio) {
|
||||
OPENSSL_EXPORT size_t BIO_number_read(const BIO *bio) {
|
||||
return bio->num_read;
|
||||
}
|
||||
|
||||
OPENSSL_EXPORT uint64_t BIO_number_written(const BIO *bio) {
|
||||
OPENSSL_EXPORT size_t BIO_number_written(const BIO *bio) {
|
||||
return bio->num_write;
|
||||
}
|
||||
|
||||
@@ -644,10 +640,11 @@ int BIO_get_new_index(void) {
|
||||
}
|
||||
|
||||
BIO_METHOD *BIO_meth_new(int type, const char *name) {
|
||||
BIO_METHOD *method = OPENSSL_zalloc(sizeof(BIO_METHOD));
|
||||
BIO_METHOD *method = OPENSSL_malloc(sizeof(BIO_METHOD));
|
||||
if (method == NULL) {
|
||||
return NULL;
|
||||
}
|
||||
OPENSSL_memset(method, 0, sizeof(BIO_METHOD));
|
||||
method->type = type;
|
||||
method->name = name;
|
||||
return method;
|
||||
@@ -658,38 +655,38 @@ void BIO_meth_free(BIO_METHOD *method) {
|
||||
}
|
||||
|
||||
int BIO_meth_set_create(BIO_METHOD *method,
|
||||
int (*create_func)(BIO *)) {
|
||||
method->create = create_func;
|
||||
int (*create)(BIO *)) {
|
||||
method->create = create;
|
||||
return 1;
|
||||
}
|
||||
|
||||
int BIO_meth_set_destroy(BIO_METHOD *method,
|
||||
int (*destroy_func)(BIO *)) {
|
||||
method->destroy = destroy_func;
|
||||
int (*destroy)(BIO *)) {
|
||||
method->destroy = destroy;
|
||||
return 1;
|
||||
}
|
||||
|
||||
int BIO_meth_set_write(BIO_METHOD *method,
|
||||
int (*write_func)(BIO *, const char *, int)) {
|
||||
method->bwrite = write_func;
|
||||
int (*write)(BIO *, const char *, int)) {
|
||||
method->bwrite = write;
|
||||
return 1;
|
||||
}
|
||||
|
||||
int BIO_meth_set_read(BIO_METHOD *method,
|
||||
int (*read_func)(BIO *, char *, int)) {
|
||||
method->bread = read_func;
|
||||
int (*read)(BIO *, char *, int)) {
|
||||
method->bread = read;
|
||||
return 1;
|
||||
}
|
||||
|
||||
int BIO_meth_set_gets(BIO_METHOD *method,
|
||||
int (*gets_func)(BIO *, char *, int)) {
|
||||
method->bgets = gets_func;
|
||||
int (*gets)(BIO *, char *, int)) {
|
||||
method->bgets = gets;
|
||||
return 1;
|
||||
}
|
||||
|
||||
int BIO_meth_set_ctrl(BIO_METHOD *method,
|
||||
long (*ctrl_func)(BIO *, int, long, void *)) {
|
||||
method->ctrl = ctrl_func;
|
||||
long (*ctrl)(BIO *, int, long, void *)) {
|
||||
method->ctrl = ctrl;
|
||||
return 1;
|
||||
}
|
||||
|
||||
@@ -709,18 +706,3 @@ int BIO_meth_set_puts(BIO_METHOD *method, int (*puts)(BIO *, const char *)) {
|
||||
// Ignore the parameter. We implement |BIO_puts| using |BIO_write|.
|
||||
return 1;
|
||||
}
|
||||
|
||||
int BIO_get_ex_new_index(long argl, void *argp,
|
||||
CRYPTO_EX_unused *unused,
|
||||
CRYPTO_EX_dup *dup_unused,
|
||||
CRYPTO_EX_free *free_func) {
|
||||
return CRYPTO_get_ex_new_index_ex(&g_ex_data_class, argl, argp, free_func);
|
||||
}
|
||||
|
||||
int BIO_set_ex_data(BIO *bio, int idx, void *data) {
|
||||
return CRYPTO_set_ex_data(&bio->ex_data, idx, data);
|
||||
}
|
||||
|
||||
void *BIO_get_ex_data(const BIO *bio, int idx) {
|
||||
return CRYPTO_get_ex_data(&bio->ex_data, idx);
|
||||
}
|
||||
@@ -296,10 +296,13 @@ end:
|
||||
}
|
||||
|
||||
static BIO_CONNECT *BIO_CONNECT_new(void) {
|
||||
BIO_CONNECT *ret = OPENSSL_zalloc(sizeof(BIO_CONNECT));
|
||||
BIO_CONNECT *ret = OPENSSL_malloc(sizeof(BIO_CONNECT));
|
||||
|
||||
if (ret == NULL) {
|
||||
return NULL;
|
||||
}
|
||||
OPENSSL_memset(ret, 0, sizeof(BIO_CONNECT));
|
||||
|
||||
ret->state = BIO_CONN_S_BEFORE;
|
||||
return ret;
|
||||
}
|
||||
@@ -487,11 +490,7 @@ static long conn_callback_ctrl(BIO *bio, int cmd, bio_info_cb fp) {
|
||||
// convention.
|
||||
OPENSSL_MSVC_PRAGMA(warning(push))
|
||||
OPENSSL_MSVC_PRAGMA(warning(disable : 4191))
|
||||
OPENSSL_CLANG_PRAGMA("clang diagnostic push")
|
||||
OPENSSL_CLANG_PRAGMA("clang diagnostic ignored \"-Wunknown-warning-option\"")
|
||||
OPENSSL_CLANG_PRAGMA("clang diagnostic ignored \"-Wcast-function-type\"")
|
||||
data->info_callback = (int (*)(const struct bio_st *, int, int))fp;
|
||||
OPENSSL_CLANG_PRAGMA("clang diagnostic pop")
|
||||
OPENSSL_MSVC_PRAGMA(warning(pop))
|
||||
break;
|
||||
default:
|
||||
|
||||
@@ -73,7 +73,6 @@
|
||||
|
||||
#include <CCryptoBoringSSL_bio.h>
|
||||
|
||||
#include <assert.h>
|
||||
#include <errno.h>
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
@@ -83,10 +82,6 @@
|
||||
|
||||
#include "../internal.h"
|
||||
|
||||
#if defined(OPENSSL_WINDOWS)
|
||||
#include <fcntl.h>
|
||||
#include <io.h>
|
||||
#endif
|
||||
|
||||
#define BIO_FP_READ 0x02
|
||||
#define BIO_FP_WRITE 0x04
|
||||
@@ -127,13 +122,14 @@ BIO *BIO_new_file(const char *filename, const char *mode) {
|
||||
return ret;
|
||||
}
|
||||
|
||||
BIO *BIO_new_fp(FILE *stream, int flags) {
|
||||
BIO *BIO_new_fp(FILE *stream, int close_flag) {
|
||||
BIO *ret = BIO_new(BIO_s_file());
|
||||
|
||||
if (ret == NULL) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
BIO_set_fp(ret, stream, flags);
|
||||
BIO_set_fp(ret, stream, close_flag);
|
||||
return ret;
|
||||
}
|
||||
|
||||
@@ -200,17 +196,6 @@ static long file_ctrl(BIO *b, int cmd, long num, void *ptr) {
|
||||
break;
|
||||
case BIO_C_SET_FILE_PTR:
|
||||
file_free(b);
|
||||
static_assert((BIO_CLOSE & BIO_FP_TEXT) == 0,
|
||||
"BIO_CLOSE and BIO_FP_TEXT must not collide");
|
||||
#if defined(OPENSSL_WINDOWS)
|
||||
// If |BIO_FP_TEXT| is not set, OpenSSL will switch the file to binary
|
||||
// mode. BoringSSL intentionally diverges here because it means code
|
||||
// tested under POSIX will inadvertently change the state of |FILE|
|
||||
// objects when wrapping them in a |BIO|.
|
||||
if (num & BIO_FP_TEXT) {
|
||||
_setmode(_fileno(ptr), _O_TEXT);
|
||||
}
|
||||
#endif
|
||||
b->shutdown = (int)num & BIO_CLOSE;
|
||||
b->ptr = ptr;
|
||||
b->init = 1;
|
||||
@@ -221,16 +206,16 @@ static long file_ctrl(BIO *b, int cmd, long num, void *ptr) {
|
||||
const char *mode;
|
||||
if (num & BIO_FP_APPEND) {
|
||||
if (num & BIO_FP_READ) {
|
||||
mode = "ab+";
|
||||
mode = "a+";
|
||||
} else {
|
||||
mode = "ab";
|
||||
mode = "a";
|
||||
}
|
||||
} else if ((num & BIO_FP_READ) && (num & BIO_FP_WRITE)) {
|
||||
mode = "rb+";
|
||||
mode = "r+";
|
||||
} else if (num & BIO_FP_WRITE) {
|
||||
mode = "wb";
|
||||
mode = "w";
|
||||
} else if (num & BIO_FP_READ) {
|
||||
mode = "rb";
|
||||
mode = "r";
|
||||
} else {
|
||||
OPENSSL_PUT_ERROR(BIO, BIO_R_BAD_FOPEN_MODE);
|
||||
ret = 0;
|
||||
@@ -302,8 +287,8 @@ int BIO_get_fp(BIO *bio, FILE **out_file) {
|
||||
return (int)BIO_ctrl(bio, BIO_C_GET_FILE_PTR, 0, (char *)out_file);
|
||||
}
|
||||
|
||||
int BIO_set_fp(BIO *bio, FILE *file, int flags) {
|
||||
return (int)BIO_ctrl(bio, BIO_C_SET_FILE_PTR, flags, (char *)file);
|
||||
int BIO_set_fp(BIO *bio, FILE *file, int close_flag) {
|
||||
return (int)BIO_ctrl(bio, BIO_C_SET_FILE_PTR, close_flag, (char *)file);
|
||||
}
|
||||
|
||||
int BIO_read_filename(BIO *bio, const char *filename) {
|
||||
|
||||
@@ -81,10 +81,13 @@ struct bio_bio_st {
|
||||
};
|
||||
|
||||
static int bio_new(BIO *bio) {
|
||||
struct bio_bio_st *b = OPENSSL_zalloc(sizeof *b);
|
||||
struct bio_bio_st *b;
|
||||
|
||||
b = OPENSSL_malloc(sizeof *b);
|
||||
if (b == NULL) {
|
||||
return 0;
|
||||
}
|
||||
OPENSSL_memset(b, 0, sizeof(struct bio_bio_st));
|
||||
|
||||
b->size = 17 * 1024; // enough for one TLS record (just a default)
|
||||
bio->ptr = b;
|
||||
|
||||
@@ -455,11 +455,3 @@ int BN_bn2binpad(const BIGNUM *in, uint8_t *out, int len) {
|
||||
}
|
||||
return len;
|
||||
}
|
||||
|
||||
int BN_bn2lebinpad(const BIGNUM *in, uint8_t *out, int len) {
|
||||
if (len < 0 ||
|
||||
!BN_bn2le_padded(out, (size_t)len, in)) {
|
||||
return -1;
|
||||
}
|
||||
return len;
|
||||
}
|
||||
@@ -64,7 +64,17 @@
|
||||
#include "../internal.h"
|
||||
|
||||
|
||||
BUF_MEM *BUF_MEM_new(void) { return OPENSSL_zalloc(sizeof(BUF_MEM)); }
|
||||
BUF_MEM *BUF_MEM_new(void) {
|
||||
BUF_MEM *ret;
|
||||
|
||||
ret = OPENSSL_malloc(sizeof(BUF_MEM));
|
||||
if (ret == NULL) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
OPENSSL_memset(ret, 0, sizeof(BUF_MEM));
|
||||
return ret;
|
||||
}
|
||||
|
||||
void BUF_MEM_free(BUF_MEM *buf) {
|
||||
if (buf == NULL) {
|
||||
|
||||
@@ -18,10 +18,13 @@
|
||||
#include <string.h>
|
||||
|
||||
#include "internal.h"
|
||||
#include "../internal.h"
|
||||
|
||||
|
||||
// kMaxDepth limits the recursion depth to avoid overflowing the stack.
|
||||
static const uint32_t kMaxDepth = 128;
|
||||
// kMaxDepth is a just a sanity limit. The code should be such that the length
|
||||
// of the input being processes always decreases. None the less, a very large
|
||||
// input could otherwise cause the stack to overflow.
|
||||
static const uint32_t kMaxDepth = 2048;
|
||||
|
||||
// is_string_type returns one if |tag| is a string type and zero otherwise. It
|
||||
// ignores the constructed bit.
|
||||
@@ -53,11 +56,13 @@ static int is_string_type(CBS_ASN1_TAG tag) {
|
||||
// found. The value of |orig_in| is not changed. It returns one on success (i.e.
|
||||
// |*ber_found| was set) and zero on error.
|
||||
static int cbs_find_ber(const CBS *orig_in, int *ber_found, uint32_t depth) {
|
||||
CBS in;
|
||||
|
||||
if (depth > kMaxDepth) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
CBS in = *orig_in;
|
||||
CBS_init(&in, CBS_data(orig_in), CBS_len(orig_in));
|
||||
*ber_found = 0;
|
||||
|
||||
while (CBS_len(&in) > 0) {
|
||||
@@ -82,10 +87,6 @@ static int cbs_find_ber(const CBS *orig_in, int *ber_found, uint32_t depth) {
|
||||
!cbs_find_ber(&contents, ber_found, depth + 1)) {
|
||||
return 0;
|
||||
}
|
||||
if (*ber_found) {
|
||||
// We already found BER. No need to continue parsing.
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -155,29 +155,6 @@ static struct cbb_buffer_st *cbb_get_base(CBB *cbb) {
|
||||
return &cbb->u.base;
|
||||
}
|
||||
|
||||
static void cbb_on_error(CBB *cbb) {
|
||||
// Due to C's lack of destructors and |CBB|'s auto-flushing API, a failing
|
||||
// |CBB|-taking function may leave a dangling pointer to a child |CBB|. As a
|
||||
// result, the convention is callers may not write to |CBB|s that have failed.
|
||||
// But, as a safety measure, we lock the |CBB| into an error state. Once the
|
||||
// error bit is set, |cbb->child| will not be read.
|
||||
//
|
||||
// TODO(davidben): This still isn't quite ideal. A |CBB| function *outside*
|
||||
// this file may originate an error while the |CBB| points to a local child.
|
||||
// In that case we don't set the error bit and are reliant on the error
|
||||
// convention. Perhaps we allow |CBB_cleanup| on child |CBB|s and make every
|
||||
// child's |CBB_cleanup| set the error bit if unflushed. That will be
|
||||
// convenient for C++ callers, but very tedious for C callers. So C callers
|
||||
// perhaps should get a |CBB_on_error| function that can be, less tediously,
|
||||
// stuck in a |goto err| block.
|
||||
cbb_get_base(cbb)->error = 1;
|
||||
|
||||
// Clearing the pointer is not strictly necessary, but GCC's dangling pointer
|
||||
// warning does not know |cbb->child| will not be read once |error| is set
|
||||
// above.
|
||||
cbb->child = NULL;
|
||||
}
|
||||
|
||||
// CBB_flush recurses and then writes out any pending length prefix. The
|
||||
// current length of the underlying base is taken to be the length of the
|
||||
// length-prefixed data.
|
||||
@@ -267,7 +244,7 @@ int CBB_flush(CBB *cbb) {
|
||||
return 1;
|
||||
|
||||
err:
|
||||
cbb_on_error(cbb);
|
||||
base->error = 1;
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -443,7 +420,7 @@ static int cbb_add_u(CBB *cbb, uint64_t v, size_t len_len) {
|
||||
|
||||
// |v| must fit in |len_len| bytes.
|
||||
if (v != 0) {
|
||||
cbb_on_error(cbb);
|
||||
cbb_get_base(cbb)->error = 1;
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -502,7 +479,7 @@ int CBB_add_asn1_uint64(CBB *cbb, uint64_t value) {
|
||||
int CBB_add_asn1_uint64_with_tag(CBB *cbb, uint64_t value, CBS_ASN1_TAG tag) {
|
||||
CBB child;
|
||||
if (!CBB_add_asn1(cbb, &child, tag)) {
|
||||
goto err;
|
||||
return 0;
|
||||
}
|
||||
|
||||
int started = 0;
|
||||
@@ -516,25 +493,21 @@ int CBB_add_asn1_uint64_with_tag(CBB *cbb, uint64_t value, CBS_ASN1_TAG tag) {
|
||||
// If the high bit is set, add a padding byte to make it
|
||||
// unsigned.
|
||||
if ((byte & 0x80) && !CBB_add_u8(&child, 0)) {
|
||||
goto err;
|
||||
return 0;
|
||||
}
|
||||
started = 1;
|
||||
}
|
||||
if (!CBB_add_u8(&child, byte)) {
|
||||
goto err;
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
// 0 is encoded as a single 0, not the empty string.
|
||||
if (!started && !CBB_add_u8(&child, 0)) {
|
||||
goto err;
|
||||
return 0;
|
||||
}
|
||||
|
||||
return CBB_flush(cbb);
|
||||
|
||||
err:
|
||||
cbb_on_error(cbb);
|
||||
return 0;
|
||||
}
|
||||
|
||||
int CBB_add_asn1_int64(CBB *cbb, int64_t value) {
|
||||
@@ -556,18 +529,14 @@ int CBB_add_asn1_int64_with_tag(CBB *cbb, int64_t value, CBS_ASN1_TAG tag) {
|
||||
|
||||
CBB child;
|
||||
if (!CBB_add_asn1(cbb, &child, tag)) {
|
||||
goto err;
|
||||
return 0;
|
||||
}
|
||||
for (int i = start; i >= 0; i--) {
|
||||
if (!CBB_add_u8(&child, bytes[i])) {
|
||||
goto err;
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
return CBB_flush(cbb);
|
||||
|
||||
err:
|
||||
cbb_on_error(cbb);
|
||||
return 0;
|
||||
}
|
||||
|
||||
int CBB_add_asn1_octet_string(CBB *cbb, const uint8_t *data, size_t data_len) {
|
||||
@@ -575,7 +544,6 @@ int CBB_add_asn1_octet_string(CBB *cbb, const uint8_t *data, size_t data_len) {
|
||||
if (!CBB_add_asn1(cbb, &child, CBS_ASN1_OCTETSTRING) ||
|
||||
!CBB_add_bytes(&child, data, data_len) ||
|
||||
!CBB_flush(cbb)) {
|
||||
cbb_on_error(cbb);
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -587,7 +555,6 @@ int CBB_add_asn1_bool(CBB *cbb, int value) {
|
||||
if (!CBB_add_asn1(cbb, &child, CBS_ASN1_BOOLEAN) ||
|
||||
!CBB_add_u8(&child, value != 0 ? 0xff : 0) ||
|
||||
!CBB_flush(cbb)) {
|
||||
cbb_on_error(cbb);
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -682,13 +649,16 @@ int CBB_flush_asn1_set_of(CBB *cbb) {
|
||||
if (num_children < 2) {
|
||||
return 1; // Nothing to do. This is the common case for X.509.
|
||||
}
|
||||
if (num_children > ((size_t)-1) / sizeof(CBS)) {
|
||||
return 0; // Overflow.
|
||||
}
|
||||
|
||||
// Parse out the children and sort. We alias them into a copy of so they
|
||||
// remain valid as we rewrite |cbb|.
|
||||
int ret = 0;
|
||||
size_t buf_len = CBB_len(cbb);
|
||||
uint8_t *buf = OPENSSL_memdup(CBB_data(cbb), buf_len);
|
||||
CBS *children = OPENSSL_calloc(num_children, sizeof(CBS));
|
||||
CBS *children = OPENSSL_malloc(num_children * sizeof(CBS));
|
||||
if (buf == NULL || children == NULL) {
|
||||
goto err;
|
||||
}
|
||||
|
||||
@@ -26,6 +26,11 @@
|
||||
#include "internal.h"
|
||||
|
||||
|
||||
void CBS_init(CBS *cbs, const uint8_t *data, size_t len) {
|
||||
cbs->data = data;
|
||||
cbs->len = len;
|
||||
}
|
||||
|
||||
static int cbs_get(CBS *cbs, const uint8_t **p, size_t n) {
|
||||
if (cbs->len < n) {
|
||||
return 0;
|
||||
@@ -42,6 +47,14 @@ int CBS_skip(CBS *cbs, size_t len) {
|
||||
return cbs_get(cbs, &dummy, len);
|
||||
}
|
||||
|
||||
const uint8_t *CBS_data(const CBS *cbs) {
|
||||
return cbs->data;
|
||||
}
|
||||
|
||||
size_t CBS_len(const CBS *cbs) {
|
||||
return cbs->len;
|
||||
}
|
||||
|
||||
int CBS_stow(const CBS *cbs, uint8_t **out_ptr, size_t *out_len) {
|
||||
OPENSSL_free(*out_ptr);
|
||||
*out_ptr = NULL;
|
||||
@@ -507,9 +520,11 @@ int CBS_get_asn1_int64(CBS *cbs, int64_t *out) {
|
||||
return 0;
|
||||
}
|
||||
uint8_t sign_extend[sizeof(int64_t)];
|
||||
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);
|
||||
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));
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
||||
@@ -67,6 +67,28 @@ OPENSSL_EXPORT int CBS_get_asn1_implicit_string(CBS *in, CBS *out,
|
||||
int CBB_finish_i2d(CBB *cbb, uint8_t **outp);
|
||||
|
||||
|
||||
// Unicode utilities.
|
||||
|
||||
// The following functions read one Unicode code point from |cbs| with the
|
||||
// corresponding encoding and store it in |*out|. They return one on success and
|
||||
// zero on error.
|
||||
OPENSSL_EXPORT int cbs_get_utf8(CBS *cbs, uint32_t *out);
|
||||
OPENSSL_EXPORT int cbs_get_latin1(CBS *cbs, uint32_t *out);
|
||||
OPENSSL_EXPORT int cbs_get_ucs2_be(CBS *cbs, uint32_t *out);
|
||||
OPENSSL_EXPORT int cbs_get_utf32_be(CBS *cbs, uint32_t *out);
|
||||
|
||||
// cbb_get_utf8_len returns the number of bytes needed to represent |u| in
|
||||
// UTF-8.
|
||||
OPENSSL_EXPORT size_t cbb_get_utf8_len(uint32_t u);
|
||||
|
||||
// The following functions encode |u| to |cbb| with the corresponding
|
||||
// encoding. They return one on success and zero on error.
|
||||
OPENSSL_EXPORT int cbb_add_utf8(CBB *cbb, uint32_t u);
|
||||
OPENSSL_EXPORT int cbb_add_latin1(CBB *cbb, uint32_t u);
|
||||
OPENSSL_EXPORT int cbb_add_ucs2_be(CBB *cbb, uint32_t u);
|
||||
OPENSSL_EXPORT int cbb_add_utf32_be(CBB *cbb, uint32_t u);
|
||||
|
||||
|
||||
#if defined(__cplusplus)
|
||||
} // extern C
|
||||
#endif
|
||||
|
||||
@@ -18,12 +18,11 @@
|
||||
|
||||
|
||||
static int is_valid_code_point(uint32_t v) {
|
||||
// References in the following are to Unicode 15.0.0.
|
||||
// References in the following are to Unicode 9.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
|
||||
// as noncharacters (3.4 D14). See also 23.7. As our APIs are intended for
|
||||
// "open interchange", such as ASN.1, we reject them.
|
||||
// (3.4 D14)
|
||||
(v & 0xfffe) == 0xfffe ||
|
||||
(v >= 0xfdd0 && v <= 0xfdef) ||
|
||||
// Surrogate code points are invalid (3.2 C1).
|
||||
@@ -39,7 +38,7 @@ static int is_valid_code_point(uint32_t v) {
|
||||
// TOP_BITS returns a byte with the top |n| bits set.
|
||||
#define TOP_BITS(n) ((uint8_t)~BOTTOM_BITS(8 - (n)))
|
||||
|
||||
int CBS_get_utf8(CBS *cbs, uint32_t *out) {
|
||||
int cbs_get_utf8(CBS *cbs, uint32_t *out) {
|
||||
uint8_t c;
|
||||
if (!CBS_get_u8(cbs, &c)) {
|
||||
return 0;
|
||||
@@ -81,7 +80,7 @@ int CBS_get_utf8(CBS *cbs, uint32_t *out) {
|
||||
return 1;
|
||||
}
|
||||
|
||||
int CBS_get_latin1(CBS *cbs, uint32_t *out) {
|
||||
int cbs_get_latin1(CBS *cbs, uint32_t *out) {
|
||||
uint8_t c;
|
||||
if (!CBS_get_u8(cbs, &c)) {
|
||||
return 0;
|
||||
@@ -90,7 +89,7 @@ int CBS_get_latin1(CBS *cbs, uint32_t *out) {
|
||||
return 1;
|
||||
}
|
||||
|
||||
int CBS_get_ucs2_be(CBS *cbs, uint32_t *out) {
|
||||
int cbs_get_ucs2_be(CBS *cbs, uint32_t *out) {
|
||||
// Note UCS-2 (used by BMPString) does not support surrogates.
|
||||
uint16_t c;
|
||||
if (!CBS_get_u16(cbs, &c) ||
|
||||
@@ -101,11 +100,11 @@ int CBS_get_ucs2_be(CBS *cbs, uint32_t *out) {
|
||||
return 1;
|
||||
}
|
||||
|
||||
int CBS_get_utf32_be(CBS *cbs, uint32_t *out) {
|
||||
int cbs_get_utf32_be(CBS *cbs, uint32_t *out) {
|
||||
return CBS_get_u32(cbs, out) && is_valid_code_point(*out);
|
||||
}
|
||||
|
||||
size_t CBB_get_utf8_len(uint32_t u) {
|
||||
size_t cbb_get_utf8_len(uint32_t u) {
|
||||
if (u <= 0x7f) {
|
||||
return 1;
|
||||
}
|
||||
@@ -118,7 +117,7 @@ size_t CBB_get_utf8_len(uint32_t u) {
|
||||
return 4;
|
||||
}
|
||||
|
||||
int CBB_add_utf8(CBB *cbb, uint32_t u) {
|
||||
int cbb_add_utf8(CBB *cbb, uint32_t u) {
|
||||
if (!is_valid_code_point(u)) {
|
||||
return 0;
|
||||
}
|
||||
@@ -143,14 +142,14 @@ int CBB_add_utf8(CBB *cbb, uint32_t u) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
int CBB_add_latin1(CBB *cbb, uint32_t u) {
|
||||
int cbb_add_latin1(CBB *cbb, uint32_t u) {
|
||||
return u <= 0xff && CBB_add_u8(cbb, (uint8_t)u);
|
||||
}
|
||||
|
||||
int CBB_add_ucs2_be(CBB *cbb, uint32_t u) {
|
||||
int cbb_add_ucs2_be(CBB *cbb, uint32_t u) {
|
||||
return u <= 0xffff && is_valid_code_point(u) && CBB_add_u16(cbb, (uint16_t)u);
|
||||
}
|
||||
|
||||
int CBB_add_utf32_be(CBB *cbb, uint32_t u) {
|
||||
int cbb_add_utf32_be(CBB *cbb, uint32_t u) {
|
||||
return is_valid_code_point(u) && CBB_add_u32(cbb, u);
|
||||
}
|
||||
File diff suppressed because it is too large.
Load diff
+52
-19
@@ -1,4 +1,5 @@
|
||||
#define BORINGSSL_PREFIX CCryptoBoringSSL
|
||||
#if defined(__arm__) && defined(__linux__)
|
||||
// This file is generated from a similarly-named Perl script in the BoringSSL
|
||||
// source tree. Do not edit by hand.
|
||||
|
||||
@@ -30,17 +31,47 @@
|
||||
.long 0x61707865,0x3320646e,0x79622d32,0x6b206574 @ endian-neutral
|
||||
.Lone:
|
||||
.long 1,0,0,0
|
||||
#if __ARM_MAX_ARCH__>=7
|
||||
.LOPENSSL_armcap:
|
||||
.word OPENSSL_armcap_P-.LChaCha20_ctr32
|
||||
#else
|
||||
.word -1
|
||||
#endif
|
||||
|
||||
.globl ChaCha20_ctr32_nohw
|
||||
.hidden ChaCha20_ctr32_nohw
|
||||
.type ChaCha20_ctr32_nohw,%function
|
||||
.globl ChaCha20_ctr32
|
||||
.hidden ChaCha20_ctr32
|
||||
.type ChaCha20_ctr32,%function
|
||||
.align 5
|
||||
ChaCha20_ctr32_nohw:
|
||||
ChaCha20_ctr32:
|
||||
.LChaCha20_ctr32:
|
||||
ldr r12,[sp,#0] @ pull pointer to counter and nonce
|
||||
stmdb sp!,{r0,r1,r2,r4-r11,lr}
|
||||
adr r14,.Lsigma
|
||||
#if __ARM_ARCH__<7 && !defined(__thumb2__)
|
||||
sub r14,pc,#16 @ ChaCha20_ctr32
|
||||
#else
|
||||
adr r14,.LChaCha20_ctr32
|
||||
#endif
|
||||
cmp r2,#0 @ len==0?
|
||||
#ifdef __thumb2__
|
||||
itt eq
|
||||
#endif
|
||||
addeq sp,sp,#4*3
|
||||
beq .Lno_data
|
||||
#if __ARM_MAX_ARCH__>=7
|
||||
cmp r2,#192 @ test len
|
||||
bls .Lshort
|
||||
ldr r4,[r14,#-32]
|
||||
ldr r4,[r14,r4]
|
||||
# ifdef __APPLE__
|
||||
ldr r4,[r4]
|
||||
# endif
|
||||
tst r4,#ARMV7_NEON
|
||||
bne .LChaCha20_neon
|
||||
.Lshort:
|
||||
#endif
|
||||
ldmia r12,{r4,r5,r6,r7} @ load counter and nonce
|
||||
sub sp,sp,#4*(16) @ off-load area
|
||||
sub r14,r14,#64 @ .Lsigma
|
||||
stmdb sp!,{r4,r5,r6,r7} @ copy counter and nonce
|
||||
ldmia r3,{r4,r5,r6,r7,r8,r9,r10,r11} @ load key
|
||||
ldmia r14,{r0,r1,r2,r3} @ load sigma
|
||||
@@ -201,8 +232,8 @@ ChaCha20_ctr32_nohw:
|
||||
ldr r8,[sp,#4*(0)] @ load key material
|
||||
ldr r9,[sp,#4*(1)]
|
||||
|
||||
#if __ARM_ARCH>=6 || !defined(__ARMEB__)
|
||||
# if __ARM_ARCH<7
|
||||
#if __ARM_ARCH__>=6 || !defined(__ARMEB__)
|
||||
# if __ARM_ARCH__<7
|
||||
orr r10,r12,r14
|
||||
tst r10,#3 @ are input and output aligned?
|
||||
ldr r10,[sp,#4*(2)]
|
||||
@@ -228,7 +259,7 @@ ChaCha20_ctr32_nohw:
|
||||
# endif
|
||||
ldrhs r10,[r12,#-8]
|
||||
ldrhs r11,[r12,#-4]
|
||||
# if __ARM_ARCH>=6 && defined(__ARMEB__)
|
||||
# if __ARM_ARCH__>=6 && defined(__ARMEB__)
|
||||
rev r0,r0
|
||||
rev r1,r1
|
||||
rev r2,r2
|
||||
@@ -265,7 +296,7 @@ ChaCha20_ctr32_nohw:
|
||||
# endif
|
||||
ldrhs r10,[r12,#-8]
|
||||
ldrhs r11,[r12,#-4]
|
||||
# if __ARM_ARCH>=6 && defined(__ARMEB__)
|
||||
# if __ARM_ARCH__>=6 && defined(__ARMEB__)
|
||||
rev r4,r4
|
||||
rev r5,r5
|
||||
rev r6,r6
|
||||
@@ -310,7 +341,7 @@ ChaCha20_ctr32_nohw:
|
||||
# endif
|
||||
ldrhs r10,[r12,#-8]
|
||||
ldrhs r11,[r12,#-4]
|
||||
# if __ARM_ARCH>=6 && defined(__ARMEB__)
|
||||
# if __ARM_ARCH__>=6 && defined(__ARMEB__)
|
||||
rev r0,r0
|
||||
rev r1,r1
|
||||
rev r2,r2
|
||||
@@ -352,7 +383,7 @@ ChaCha20_ctr32_nohw:
|
||||
# endif
|
||||
ldrhs r10,[r12,#-8]
|
||||
ldrhs r11,[r12,#-4]
|
||||
# if __ARM_ARCH>=6 && defined(__ARMEB__)
|
||||
# if __ARM_ARCH__>=6 && defined(__ARMEB__)
|
||||
rev r4,r4
|
||||
rev r5,r5
|
||||
rev r6,r6
|
||||
@@ -383,7 +414,7 @@ ChaCha20_ctr32_nohw:
|
||||
bhi .Loop_outer
|
||||
|
||||
beq .Ldone
|
||||
# if __ARM_ARCH<7
|
||||
# if __ARM_ARCH__<7
|
||||
b .Ltail
|
||||
|
||||
.align 4
|
||||
@@ -391,7 +422,7 @@ ChaCha20_ctr32_nohw:
|
||||
cmp r11,#64 @ restore flags
|
||||
# endif
|
||||
#endif
|
||||
#if __ARM_ARCH<7
|
||||
#if __ARM_ARCH__<7
|
||||
ldr r11,[sp,#4*(3)]
|
||||
add r0,r0,r8 @ accumulate key material
|
||||
add r1,r1,r9
|
||||
@@ -767,19 +798,19 @@ ChaCha20_ctr32_nohw:
|
||||
|
||||
.Ldone:
|
||||
add sp,sp,#4*(32+3)
|
||||
.Lno_data:
|
||||
ldmia sp!,{r4,r5,r6,r7,r8,r9,r10,r11,pc}
|
||||
.size ChaCha20_ctr32_nohw,.-ChaCha20_ctr32_nohw
|
||||
.size ChaCha20_ctr32,.-ChaCha20_ctr32
|
||||
#if __ARM_MAX_ARCH__>=7
|
||||
.arch armv7-a
|
||||
.fpu neon
|
||||
|
||||
.globl ChaCha20_ctr32_neon
|
||||
.hidden ChaCha20_ctr32_neon
|
||||
.type ChaCha20_ctr32_neon,%function
|
||||
.type ChaCha20_neon,%function
|
||||
.align 5
|
||||
ChaCha20_ctr32_neon:
|
||||
ChaCha20_neon:
|
||||
ldr r12,[sp,#0] @ pull pointer to counter and nonce
|
||||
stmdb sp!,{r0,r1,r2,r4-r11,lr}
|
||||
.LChaCha20_neon:
|
||||
adr r14,.Lsigma
|
||||
vstmdb sp!,{d8,d9,d10,d11,d12,d13,d14,d15} @ ABI spec says so
|
||||
stmdb sp!,{r0,r1,r2,r3}
|
||||
@@ -1447,9 +1478,11 @@ ChaCha20_ctr32_neon:
|
||||
vldmia sp,{d8,d9,d10,d11,d12,d13,d14,d15}
|
||||
add sp,sp,#4*(16+3)
|
||||
ldmia sp!,{r4,r5,r6,r7,r8,r9,r10,r11,pc}
|
||||
.size ChaCha20_ctr32_neon,.-ChaCha20_ctr32_neon
|
||||
.size ChaCha20_neon,.-ChaCha20_neon
|
||||
.comm OPENSSL_armcap_P,4,4
|
||||
#endif
|
||||
#endif // !OPENSSL_NO_ASM && defined(OPENSSL_ARM) && defined(__ELF__)
|
||||
#endif // defined(__arm__) && defined(__linux__)
|
||||
#if defined(__linux__) && defined(__ELF__)
|
||||
.section .note.GNU-stack,"",%progbits
|
||||
#endif
|
||||
+24
-6
@@ -1,4 +1,5 @@
|
||||
#define BORINGSSL_PREFIX CCryptoBoringSSL
|
||||
#if defined(__aarch64__) && defined(__APPLE__)
|
||||
// This file is generated from a similarly-named Perl script in the BoringSSL
|
||||
// source tree. Do not edit by hand.
|
||||
|
||||
@@ -7,6 +8,9 @@
|
||||
#if !defined(OPENSSL_NO_ASM) && defined(OPENSSL_AARCH64) && defined(__APPLE__)
|
||||
#include <CCryptoBoringSSL_arm_arch.h>
|
||||
|
||||
|
||||
.private_extern _OPENSSL_armcap_P
|
||||
|
||||
.section __TEXT,__const
|
||||
|
||||
.align 5
|
||||
@@ -19,11 +23,25 @@ Lone:
|
||||
|
||||
.text
|
||||
|
||||
.globl _ChaCha20_ctr32_nohw
|
||||
.private_extern _ChaCha20_ctr32_nohw
|
||||
.globl _ChaCha20_ctr32
|
||||
.private_extern _ChaCha20_ctr32
|
||||
|
||||
.align 5
|
||||
_ChaCha20_ctr32_nohw:
|
||||
_ChaCha20_ctr32:
|
||||
AARCH64_VALID_CALL_TARGET
|
||||
cbz x2,Labort
|
||||
#if defined(OPENSSL_HWASAN) && __clang_major__ >= 10
|
||||
adrp x5,:pg_hi21_nc:_OPENSSL_armcap_P
|
||||
#else
|
||||
adrp x5,_OPENSSL_armcap_P@PAGE
|
||||
#endif
|
||||
cmp x2,#192
|
||||
b.lo Lshort
|
||||
ldr w17,[x5,_OPENSSL_armcap_P@PAGEOFF]
|
||||
tst w17,#ARMV7_NEON
|
||||
b.ne ChaCha20_neon
|
||||
|
||||
Lshort:
|
||||
AARCH64_SIGN_LINK_REGISTER
|
||||
stp x29,x30,[sp,#-96]!
|
||||
add x29,sp,#0
|
||||
@@ -238,6 +256,7 @@ Loop:
|
||||
ldp x27,x28,[x29,#80]
|
||||
ldp x29,x30,[sp],#96
|
||||
AARCH64_VALIDATE_LINK_REGISTER
|
||||
Labort:
|
||||
ret
|
||||
|
||||
.align 4
|
||||
@@ -297,11 +316,9 @@ Loop_tail:
|
||||
ret
|
||||
|
||||
|
||||
.globl _ChaCha20_ctr32_neon
|
||||
.private_extern _ChaCha20_ctr32_neon
|
||||
|
||||
.align 5
|
||||
_ChaCha20_ctr32_neon:
|
||||
ChaCha20_neon:
|
||||
AARCH64_SIGN_LINK_REGISTER
|
||||
stp x29,x30,[sp,#-96]!
|
||||
add x29,sp,#0
|
||||
@@ -1967,6 +1984,7 @@ Ldone_512_neon:
|
||||
ret
|
||||
|
||||
#endif // !OPENSSL_NO_ASM && defined(OPENSSL_AARCH64) && defined(__APPLE__)
|
||||
#endif // defined(__aarch64__) && defined(__APPLE__)
|
||||
#if defined(__linux__) && defined(__ELF__)
|
||||
.section .note.GNU-stack,"",%progbits
|
||||
#endif
|
||||
+28
-10
@@ -1,4 +1,5 @@
|
||||
#define BORINGSSL_PREFIX CCryptoBoringSSL
|
||||
#if defined(__aarch64__) && defined(__linux__)
|
||||
// This file is generated from a similarly-named Perl script in the BoringSSL
|
||||
// source tree. Do not edit by hand.
|
||||
|
||||
@@ -7,6 +8,9 @@
|
||||
#if !defined(OPENSSL_NO_ASM) && defined(OPENSSL_AARCH64) && defined(__ELF__)
|
||||
#include <CCryptoBoringSSL_arm_arch.h>
|
||||
|
||||
|
||||
.hidden OPENSSL_armcap_P
|
||||
|
||||
.section .rodata
|
||||
|
||||
.align 5
|
||||
@@ -19,11 +23,25 @@
|
||||
|
||||
.text
|
||||
|
||||
.globl ChaCha20_ctr32_nohw
|
||||
.hidden ChaCha20_ctr32_nohw
|
||||
.type ChaCha20_ctr32_nohw,%function
|
||||
.globl ChaCha20_ctr32
|
||||
.hidden ChaCha20_ctr32
|
||||
.type ChaCha20_ctr32,%function
|
||||
.align 5
|
||||
ChaCha20_ctr32_nohw:
|
||||
ChaCha20_ctr32:
|
||||
AARCH64_VALID_CALL_TARGET
|
||||
cbz x2,.Labort
|
||||
#if defined(OPENSSL_HWASAN) && __clang_major__ >= 10
|
||||
adrp x5,:pg_hi21_nc:OPENSSL_armcap_P
|
||||
#else
|
||||
adrp x5,OPENSSL_armcap_P
|
||||
#endif
|
||||
cmp x2,#192
|
||||
b.lo .Lshort
|
||||
ldr w17,[x5,:lo12:OPENSSL_armcap_P]
|
||||
tst w17,#ARMV7_NEON
|
||||
b.ne ChaCha20_neon
|
||||
|
||||
.Lshort:
|
||||
AARCH64_SIGN_LINK_REGISTER
|
||||
stp x29,x30,[sp,#-96]!
|
||||
add x29,sp,#0
|
||||
@@ -238,6 +256,7 @@ ChaCha20_ctr32_nohw:
|
||||
ldp x27,x28,[x29,#80]
|
||||
ldp x29,x30,[sp],#96
|
||||
AARCH64_VALIDATE_LINK_REGISTER
|
||||
.Labort:
|
||||
ret
|
||||
|
||||
.align 4
|
||||
@@ -295,13 +314,11 @@ ChaCha20_ctr32_nohw:
|
||||
ldp x29,x30,[sp],#96
|
||||
AARCH64_VALIDATE_LINK_REGISTER
|
||||
ret
|
||||
.size ChaCha20_ctr32_nohw,.-ChaCha20_ctr32_nohw
|
||||
.size ChaCha20_ctr32,.-ChaCha20_ctr32
|
||||
|
||||
.globl ChaCha20_ctr32_neon
|
||||
.hidden ChaCha20_ctr32_neon
|
||||
.type ChaCha20_ctr32_neon,%function
|
||||
.type ChaCha20_neon,%function
|
||||
.align 5
|
||||
ChaCha20_ctr32_neon:
|
||||
ChaCha20_neon:
|
||||
AARCH64_SIGN_LINK_REGISTER
|
||||
stp x29,x30,[sp,#-96]!
|
||||
add x29,sp,#0
|
||||
@@ -795,7 +812,7 @@ ChaCha20_ctr32_neon:
|
||||
ldp x29,x30,[sp],#96
|
||||
AARCH64_VALIDATE_LINK_REGISTER
|
||||
ret
|
||||
.size ChaCha20_ctr32_neon,.-ChaCha20_ctr32_neon
|
||||
.size ChaCha20_neon,.-ChaCha20_neon
|
||||
.type ChaCha20_512_neon,%function
|
||||
.align 5
|
||||
ChaCha20_512_neon:
|
||||
@@ -1967,6 +1984,7 @@ ChaCha20_512_neon:
|
||||
ret
|
||||
.size ChaCha20_512_neon,.-ChaCha20_512_neon
|
||||
#endif // !OPENSSL_NO_ASM && defined(OPENSSL_AARCH64) && defined(__ELF__)
|
||||
#endif // defined(__aarch64__) && defined(__linux__)
|
||||
#if defined(__linux__) && defined(__ELF__)
|
||||
.section .note.GNU-stack,"",%progbits
|
||||
#endif
|
||||
+62
-48
@@ -1,4 +1,5 @@
|
||||
#define BORINGSSL_PREFIX CCryptoBoringSSL
|
||||
#if defined(__i386__) && defined(__linux__)
|
||||
// This file is generated from a similarly-named Perl script in the BoringSSL
|
||||
// source tree. Do not edit by hand.
|
||||
|
||||
@@ -6,16 +7,29 @@
|
||||
|
||||
#if !defined(OPENSSL_NO_ASM) && defined(OPENSSL_X86) && defined(__ELF__)
|
||||
.text
|
||||
.globl ChaCha20_ctr32_nohw
|
||||
.hidden ChaCha20_ctr32_nohw
|
||||
.type ChaCha20_ctr32_nohw,@function
|
||||
.globl ChaCha20_ctr32
|
||||
.hidden ChaCha20_ctr32
|
||||
.type ChaCha20_ctr32,@function
|
||||
.align 16
|
||||
ChaCha20_ctr32_nohw:
|
||||
.L_ChaCha20_ctr32_nohw_begin:
|
||||
ChaCha20_ctr32:
|
||||
.L_ChaCha20_ctr32_begin:
|
||||
pushl %ebp
|
||||
pushl %ebx
|
||||
pushl %esi
|
||||
pushl %edi
|
||||
xorl %eax,%eax
|
||||
cmpl 28(%esp),%eax
|
||||
je .L000no_data
|
||||
call .Lpic_point
|
||||
.Lpic_point:
|
||||
popl %eax
|
||||
leal OPENSSL_ia32cap_P-.Lpic_point(%eax),%ebp
|
||||
testl $16777216,(%ebp)
|
||||
jz .L001x86
|
||||
testl $512,4(%ebp)
|
||||
jz .L001x86
|
||||
jmp .Lssse3_shortcut
|
||||
.L001x86:
|
||||
movl 32(%esp),%esi
|
||||
movl 36(%esp),%edi
|
||||
subl $132,%esp
|
||||
@@ -44,13 +58,13 @@ ChaCha20_ctr32_nohw:
|
||||
movl %ebx,116(%esp)
|
||||
movl %ecx,120(%esp)
|
||||
movl %edx,124(%esp)
|
||||
jmp .L000entry
|
||||
jmp .L002entry
|
||||
.align 16
|
||||
.L001outer_loop:
|
||||
.L003outer_loop:
|
||||
movl %ebx,156(%esp)
|
||||
movl %eax,152(%esp)
|
||||
movl %ecx,160(%esp)
|
||||
.L000entry:
|
||||
.L002entry:
|
||||
movl $1634760805,%eax
|
||||
movl $857760878,4(%esp)
|
||||
movl $2036477234,8(%esp)
|
||||
@@ -78,9 +92,9 @@ ChaCha20_ctr32_nohw:
|
||||
movl %edi,60(%esp)
|
||||
movl %edx,112(%esp)
|
||||
movl $10,%ebx
|
||||
jmp .L002loop
|
||||
jmp .L004loop
|
||||
.align 16
|
||||
.L002loop:
|
||||
.L004loop:
|
||||
addl %ebp,%eax
|
||||
movl %ebx,128(%esp)
|
||||
movl %ebp,%ebx
|
||||
@@ -234,14 +248,14 @@ ChaCha20_ctr32_nohw:
|
||||
xorl %esi,%ebp
|
||||
roll $7,%ebp
|
||||
decl %ebx
|
||||
jnz .L002loop
|
||||
jnz .L004loop
|
||||
movl 160(%esp),%ebx
|
||||
addl $1634760805,%eax
|
||||
addl 80(%esp),%ebp
|
||||
addl 96(%esp),%ecx
|
||||
addl 100(%esp),%esi
|
||||
cmpl $64,%ebx
|
||||
jb .L003tail
|
||||
jb .L005tail
|
||||
movl 156(%esp),%ebx
|
||||
addl 112(%esp),%edx
|
||||
addl 120(%esp),%edi
|
||||
@@ -304,9 +318,9 @@ ChaCha20_ctr32_nohw:
|
||||
movl %ebp,(%eax)
|
||||
leal 64(%eax),%eax
|
||||
subl $64,%ecx
|
||||
jnz .L001outer_loop
|
||||
jmp .L004done
|
||||
.L003tail:
|
||||
jnz .L003outer_loop
|
||||
jmp .L006done
|
||||
.L005tail:
|
||||
addl 112(%esp),%edx
|
||||
addl 120(%esp),%edi
|
||||
movl %eax,(%esp)
|
||||
@@ -350,35 +364,34 @@ ChaCha20_ctr32_nohw:
|
||||
movl %edi,60(%esp)
|
||||
xorl %eax,%eax
|
||||
xorl %edx,%edx
|
||||
.L005tail_loop:
|
||||
.L007tail_loop:
|
||||
movb (%esi,%ebp,1),%al
|
||||
movb (%esp,%esi,1),%dl
|
||||
leal 1(%esi),%esi
|
||||
xorb %dl,%al
|
||||
movb %al,-1(%ecx,%esi,1)
|
||||
decl %ebx
|
||||
jnz .L005tail_loop
|
||||
.L004done:
|
||||
jnz .L007tail_loop
|
||||
.L006done:
|
||||
addl $132,%esp
|
||||
.L000no_data:
|
||||
popl %edi
|
||||
popl %esi
|
||||
popl %ebx
|
||||
popl %ebp
|
||||
ret
|
||||
.size ChaCha20_ctr32_nohw,.-.L_ChaCha20_ctr32_nohw_begin
|
||||
.globl ChaCha20_ctr32_ssse3
|
||||
.hidden ChaCha20_ctr32_ssse3
|
||||
.type ChaCha20_ctr32_ssse3,@function
|
||||
.size ChaCha20_ctr32,.-.L_ChaCha20_ctr32_begin
|
||||
.globl ChaCha20_ssse3
|
||||
.hidden ChaCha20_ssse3
|
||||
.type ChaCha20_ssse3,@function
|
||||
.align 16
|
||||
ChaCha20_ctr32_ssse3:
|
||||
.L_ChaCha20_ctr32_ssse3_begin:
|
||||
ChaCha20_ssse3:
|
||||
.L_ChaCha20_ssse3_begin:
|
||||
pushl %ebp
|
||||
pushl %ebx
|
||||
pushl %esi
|
||||
pushl %edi
|
||||
call .Lpic_point
|
||||
.Lpic_point:
|
||||
popl %eax
|
||||
.Lssse3_shortcut:
|
||||
movl 20(%esp),%edi
|
||||
movl 24(%esp),%esi
|
||||
movl 28(%esp),%ecx
|
||||
@@ -391,7 +404,7 @@ ChaCha20_ctr32_ssse3:
|
||||
leal .Lssse3_data-.Lpic_point(%eax),%eax
|
||||
movdqu (%ebx),%xmm3
|
||||
cmpl $256,%ecx
|
||||
jb .L0061x
|
||||
jb .L0081x
|
||||
movl %edx,516(%esp)
|
||||
movl %ebx,520(%esp)
|
||||
subl $256,%ecx
|
||||
@@ -436,9 +449,9 @@ ChaCha20_ctr32_ssse3:
|
||||
movdqa %xmm7,-80(%ebp)
|
||||
leal 128(%esi),%esi
|
||||
leal 128(%edi),%edi
|
||||
jmp .L007outer_loop
|
||||
jmp .L009outer_loop
|
||||
.align 16
|
||||
.L007outer_loop:
|
||||
.L009outer_loop:
|
||||
movdqa -112(%ebp),%xmm1
|
||||
movdqa -96(%ebp),%xmm2
|
||||
movdqa -80(%ebp),%xmm3
|
||||
@@ -473,7 +486,7 @@ ChaCha20_ctr32_ssse3:
|
||||
movl $10,%edx
|
||||
nop
|
||||
.align 16
|
||||
.L008loop:
|
||||
.L010loop:
|
||||
paddd %xmm3,%xmm0
|
||||
movdqa %xmm3,%xmm2
|
||||
pxor %xmm0,%xmm6
|
||||
@@ -673,7 +686,7 @@ ChaCha20_ctr32_ssse3:
|
||||
psrld $25,%xmm1
|
||||
por %xmm1,%xmm3
|
||||
decl %edx
|
||||
jnz .L008loop
|
||||
jnz .L010loop
|
||||
movdqa %xmm3,-64(%ebx)
|
||||
movdqa %xmm4,(%ebx)
|
||||
movdqa %xmm5,16(%ebx)
|
||||
@@ -815,9 +828,9 @@ ChaCha20_ctr32_ssse3:
|
||||
movdqu %xmm7,64(%edi)
|
||||
leal 208(%edi),%edi
|
||||
subl $256,%ecx
|
||||
jnc .L007outer_loop
|
||||
jnc .L009outer_loop
|
||||
addl $256,%ecx
|
||||
jz .L009done
|
||||
jz .L011done
|
||||
movl 520(%esp),%ebx
|
||||
leal -128(%esi),%esi
|
||||
movl 516(%esp),%edx
|
||||
@@ -827,7 +840,7 @@ ChaCha20_ctr32_ssse3:
|
||||
paddd 96(%eax),%xmm2
|
||||
pand 112(%eax),%xmm3
|
||||
por %xmm2,%xmm3
|
||||
.L0061x:
|
||||
.L0081x:
|
||||
movdqa 32(%eax),%xmm0
|
||||
movdqu (%edx),%xmm1
|
||||
movdqu 16(%edx),%xmm2
|
||||
@@ -839,9 +852,9 @@ ChaCha20_ctr32_ssse3:
|
||||
movdqa %xmm2,32(%esp)
|
||||
movdqa %xmm3,48(%esp)
|
||||
movl $10,%edx
|
||||
jmp .L010loop1x
|
||||
jmp .L012loop1x
|
||||
.align 16
|
||||
.L011outer1x:
|
||||
.L013outer1x:
|
||||
movdqa 80(%eax),%xmm3
|
||||
movdqa (%esp),%xmm0
|
||||
movdqa 16(%esp),%xmm1
|
||||
@@ -849,9 +862,9 @@ ChaCha20_ctr32_ssse3:
|
||||
paddd 48(%esp),%xmm3
|
||||
movl $10,%edx
|
||||
movdqa %xmm3,48(%esp)
|
||||
jmp .L010loop1x
|
||||
jmp .L012loop1x
|
||||
.align 16
|
||||
.L010loop1x:
|
||||
.L012loop1x:
|
||||
paddd %xmm1,%xmm0
|
||||
pxor %xmm0,%xmm3
|
||||
.byte 102,15,56,0,222
|
||||
@@ -896,13 +909,13 @@ ChaCha20_ctr32_ssse3:
|
||||
pshufd $147,%xmm1,%xmm1
|
||||
pshufd $57,%xmm3,%xmm3
|
||||
decl %edx
|
||||
jnz .L010loop1x
|
||||
jnz .L012loop1x
|
||||
paddd (%esp),%xmm0
|
||||
paddd 16(%esp),%xmm1
|
||||
paddd 32(%esp),%xmm2
|
||||
paddd 48(%esp),%xmm3
|
||||
cmpl $64,%ecx
|
||||
jb .L012tail
|
||||
jb .L014tail
|
||||
movdqu (%esi),%xmm4
|
||||
movdqu 16(%esi),%xmm5
|
||||
pxor %xmm4,%xmm0
|
||||
@@ -918,9 +931,9 @@ ChaCha20_ctr32_ssse3:
|
||||
movdqu %xmm3,48(%edi)
|
||||
leal 64(%edi),%edi
|
||||
subl $64,%ecx
|
||||
jnz .L011outer1x
|
||||
jmp .L009done
|
||||
.L012tail:
|
||||
jnz .L013outer1x
|
||||
jmp .L011done
|
||||
.L014tail:
|
||||
movdqa %xmm0,(%esp)
|
||||
movdqa %xmm1,16(%esp)
|
||||
movdqa %xmm2,32(%esp)
|
||||
@@ -928,22 +941,22 @@ ChaCha20_ctr32_ssse3:
|
||||
xorl %eax,%eax
|
||||
xorl %edx,%edx
|
||||
xorl %ebp,%ebp
|
||||
.L013tail_loop:
|
||||
.L015tail_loop:
|
||||
movb (%esp,%ebp,1),%al
|
||||
movb (%esi,%ebp,1),%dl
|
||||
leal 1(%ebp),%ebp
|
||||
xorb %dl,%al
|
||||
movb %al,-1(%edi,%ebp,1)
|
||||
decl %ecx
|
||||
jnz .L013tail_loop
|
||||
.L009done:
|
||||
jnz .L015tail_loop
|
||||
.L011done:
|
||||
movl 512(%esp),%esp
|
||||
popl %edi
|
||||
popl %esi
|
||||
popl %ebx
|
||||
popl %ebp
|
||||
ret
|
||||
.size ChaCha20_ctr32_ssse3,.-.L_ChaCha20_ctr32_ssse3_begin
|
||||
.size ChaCha20_ssse3,.-.L_ChaCha20_ssse3_begin
|
||||
.align 64
|
||||
.Lssse3_data:
|
||||
.byte 2,3,0,1,6,7,4,5,10,11,8,9,14,15,12,13
|
||||
@@ -960,6 +973,7 @@ ChaCha20_ctr32_ssse3:
|
||||
.byte 60,97,112,112,114,111,64,111,112,101,110,115,115,108,46,111
|
||||
.byte 114,103,62,0
|
||||
#endif // !defined(OPENSSL_NO_ASM) && defined(OPENSSL_X86) && defined(__ELF__)
|
||||
#endif // defined(__i386__) && defined(__linux__)
|
||||
#if defined(__linux__) && defined(__ELF__)
|
||||
.section .note.GNU-stack,"",%progbits
|
||||
#endif
|
||||
@@ -0,0 +1,987 @@
|
||||
#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
|
||||
align 16
|
||||
_ChaCha20_ctr32:
|
||||
L$_ChaCha20_ctr32_begin:
|
||||
push ebp
|
||||
push ebx
|
||||
push esi
|
||||
push edi
|
||||
xor eax,eax
|
||||
cmp eax,DWORD [28+esp]
|
||||
je NEAR L$000no_data
|
||||
call L$pic_point
|
||||
L$pic_point:
|
||||
pop eax
|
||||
lea ebp,[_OPENSSL_ia32cap_P]
|
||||
test DWORD [ebp],16777216
|
||||
jz NEAR L$001x86
|
||||
test DWORD [4+ebp],512
|
||||
jz NEAR L$001x86
|
||||
jmp NEAR L$ssse3_shortcut
|
||||
L$001x86:
|
||||
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$002entry
|
||||
align 16
|
||||
L$003outer_loop:
|
||||
mov DWORD [156+esp],ebx
|
||||
mov DWORD [152+esp],eax
|
||||
mov DWORD [160+esp],ecx
|
||||
L$002entry:
|
||||
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$004loop
|
||||
align 16
|
||||
L$004loop:
|
||||
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$004loop
|
||||
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$005tail
|
||||
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$003outer_loop
|
||||
jmp NEAR L$006done
|
||||
L$005tail:
|
||||
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$007tail_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$007tail_loop
|
||||
L$006done:
|
||||
add esp,132
|
||||
L$000no_data:
|
||||
pop edi
|
||||
pop esi
|
||||
pop ebx
|
||||
pop ebp
|
||||
ret
|
||||
global _ChaCha20_ssse3
|
||||
align 16
|
||||
_ChaCha20_ssse3:
|
||||
L$_ChaCha20_ssse3_begin:
|
||||
push ebp
|
||||
push ebx
|
||||
push esi
|
||||
push edi
|
||||
L$ssse3_shortcut:
|
||||
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$0081x
|
||||
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$009outer_loop
|
||||
align 16
|
||||
L$009outer_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$010loop:
|
||||
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$010loop
|
||||
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$009outer_loop
|
||||
add ecx,256
|
||||
jz NEAR L$011done
|
||||
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$0081x:
|
||||
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$012loop1x
|
||||
align 16
|
||||
L$013outer1x:
|
||||
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$012loop1x
|
||||
align 16
|
||||
L$012loop1x:
|
||||
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$012loop1x
|
||||
paddd xmm0,[esp]
|
||||
paddd xmm1,[16+esp]
|
||||
paddd xmm2,[32+esp]
|
||||
paddd xmm3,[48+esp]
|
||||
cmp ecx,64
|
||||
jb NEAR L$014tail
|
||||
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$013outer1x
|
||||
jmp NEAR L$011done
|
||||
L$014tail:
|
||||
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$015tail_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$015tail_loop
|
||||
L$011done:
|
||||
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
|
||||
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
|
||||
|
||||
+48
-27
@@ -1,4 +1,5 @@
|
||||
#define BORINGSSL_PREFIX CCryptoBoringSSL
|
||||
#if defined(__x86_64__) && defined(__linux__)
|
||||
// This file is generated from a similarly-named Perl script in the BoringSSL
|
||||
// source tree. Do not edit by hand.
|
||||
|
||||
@@ -7,6 +8,9 @@
|
||||
#if !defined(OPENSSL_NO_ASM) && defined(OPENSSL_X86_64) && defined(__ELF__)
|
||||
.text
|
||||
|
||||
.extern OPENSSL_ia32cap_P
|
||||
.hidden OPENSSL_ia32cap_P
|
||||
|
||||
.section .rodata
|
||||
.align 64
|
||||
.Lzero:
|
||||
@@ -38,13 +42,19 @@
|
||||
.long 16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16
|
||||
.byte 67,104,97,67,104,97,50,48,32,102,111,114,32,120,56,54,95,54,52,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
|
||||
.text
|
||||
.globl ChaCha20_ctr32_nohw
|
||||
.hidden ChaCha20_ctr32_nohw
|
||||
.type ChaCha20_ctr32_nohw,@function
|
||||
.globl ChaCha20_ctr32
|
||||
.hidden ChaCha20_ctr32
|
||||
.type ChaCha20_ctr32,@function
|
||||
.align 64
|
||||
ChaCha20_ctr32_nohw:
|
||||
ChaCha20_ctr32:
|
||||
.cfi_startproc
|
||||
_CET_ENDBR
|
||||
cmpq $0,%rdx
|
||||
je .Lno_data
|
||||
movq OPENSSL_ia32cap_P+4(%rip),%r10
|
||||
testl $512,%r10d
|
||||
jnz .LChaCha20_ssse3
|
||||
|
||||
pushq %rbx
|
||||
.cfi_adjust_cfa_offset 8
|
||||
.cfi_offset rbx,-16
|
||||
@@ -319,18 +329,20 @@ _CET_ENDBR
|
||||
leaq (%rsi),%rsp
|
||||
.cfi_adjust_cfa_offset -136
|
||||
.Lno_data:
|
||||
ret
|
||||
.byte 0xf3,0xc3
|
||||
.cfi_endproc
|
||||
.size ChaCha20_ctr32_nohw,.-ChaCha20_ctr32_nohw
|
||||
.globl ChaCha20_ctr32_ssse3
|
||||
.hidden ChaCha20_ctr32_ssse3
|
||||
.type ChaCha20_ctr32_ssse3,@function
|
||||
.size ChaCha20_ctr32,.-ChaCha20_ctr32
|
||||
.type ChaCha20_ssse3,@function
|
||||
.align 32
|
||||
ChaCha20_ctr32_ssse3:
|
||||
ChaCha20_ssse3:
|
||||
.LChaCha20_ssse3:
|
||||
.cfi_startproc
|
||||
_CET_ENDBR
|
||||
movq %rsp,%r9
|
||||
.cfi_def_cfa_register r9
|
||||
cmpq $128,%rdx
|
||||
ja .LChaCha20_4x
|
||||
|
||||
.Ldo_sse3_after_all:
|
||||
subq $64+8,%rsp
|
||||
movdqa .Lsigma(%rip),%xmm0
|
||||
movdqu (%rcx),%xmm1
|
||||
@@ -454,18 +466,28 @@ _CET_ENDBR
|
||||
leaq (%r9),%rsp
|
||||
.cfi_def_cfa_register rsp
|
||||
.Lssse3_epilogue:
|
||||
ret
|
||||
.byte 0xf3,0xc3
|
||||
.cfi_endproc
|
||||
.size ChaCha20_ctr32_ssse3,.-ChaCha20_ctr32_ssse3
|
||||
.globl ChaCha20_ctr32_ssse3_4x
|
||||
.hidden ChaCha20_ctr32_ssse3_4x
|
||||
.type ChaCha20_ctr32_ssse3_4x,@function
|
||||
.size ChaCha20_ssse3,.-ChaCha20_ssse3
|
||||
.type ChaCha20_4x,@function
|
||||
.align 32
|
||||
ChaCha20_ctr32_ssse3_4x:
|
||||
ChaCha20_4x:
|
||||
.LChaCha20_4x:
|
||||
.cfi_startproc
|
||||
_CET_ENDBR
|
||||
movq %rsp,%r9
|
||||
.cfi_def_cfa_register r9
|
||||
movq %r10,%r11
|
||||
shrq $32,%r10
|
||||
testq $32,%r10
|
||||
jnz .LChaCha20_8x
|
||||
cmpq $192,%rdx
|
||||
ja .Lproceed4x
|
||||
|
||||
andq $71303168,%r11
|
||||
cmpq $4194304,%r11
|
||||
je .Ldo_sse3_after_all
|
||||
|
||||
.Lproceed4x:
|
||||
subq $0x140+8,%rsp
|
||||
movdqa .Lsigma(%rip),%xmm11
|
||||
movdqu (%rcx),%xmm15
|
||||
@@ -996,16 +1018,14 @@ _CET_ENDBR
|
||||
leaq (%r9),%rsp
|
||||
.cfi_def_cfa_register rsp
|
||||
.L4x_epilogue:
|
||||
ret
|
||||
.byte 0xf3,0xc3
|
||||
.cfi_endproc
|
||||
.size ChaCha20_ctr32_ssse3_4x,.-ChaCha20_ctr32_ssse3_4x
|
||||
.globl ChaCha20_ctr32_avx2
|
||||
.hidden ChaCha20_ctr32_avx2
|
||||
.type ChaCha20_ctr32_avx2,@function
|
||||
.size ChaCha20_4x,.-ChaCha20_4x
|
||||
.type ChaCha20_8x,@function
|
||||
.align 32
|
||||
ChaCha20_ctr32_avx2:
|
||||
ChaCha20_8x:
|
||||
.LChaCha20_8x:
|
||||
.cfi_startproc
|
||||
_CET_ENDBR
|
||||
movq %rsp,%r9
|
||||
.cfi_def_cfa_register r9
|
||||
subq $0x280+8,%rsp
|
||||
@@ -1604,10 +1624,11 @@ _CET_ENDBR
|
||||
leaq (%r9),%rsp
|
||||
.cfi_def_cfa_register rsp
|
||||
.L8x_epilogue:
|
||||
ret
|
||||
.byte 0xf3,0xc3
|
||||
.cfi_endproc
|
||||
.size ChaCha20_ctr32_avx2,.-ChaCha20_ctr32_avx2
|
||||
.size ChaCha20_8x,.-ChaCha20_8x
|
||||
#endif
|
||||
#endif // defined(__x86_64__) && defined(__linux__)
|
||||
#if defined(__linux__) && defined(__ELF__)
|
||||
.section .note.GNU-stack,"",%progbits
|
||||
#endif
|
||||
+39
-19
@@ -1,4 +1,5 @@
|
||||
#define BORINGSSL_PREFIX CCryptoBoringSSL
|
||||
#if defined(__x86_64__) && defined(__APPLE__)
|
||||
// This file is generated from a similarly-named Perl script in the BoringSSL
|
||||
// source tree. Do not edit by hand.
|
||||
|
||||
@@ -7,6 +8,8 @@
|
||||
#if !defined(OPENSSL_NO_ASM) && defined(OPENSSL_X86_64) && defined(__APPLE__)
|
||||
.text
|
||||
|
||||
|
||||
|
||||
.section __DATA,__const
|
||||
.p2align 6
|
||||
L$zero:
|
||||
@@ -38,13 +41,19 @@ L$sixteen:
|
||||
.long 16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16
|
||||
.byte 67,104,97,67,104,97,50,48,32,102,111,114,32,120,56,54,95,54,52,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
|
||||
.text
|
||||
.globl _ChaCha20_ctr32_nohw
|
||||
.private_extern _ChaCha20_ctr32_nohw
|
||||
.globl _ChaCha20_ctr32
|
||||
.private_extern _ChaCha20_ctr32
|
||||
|
||||
.p2align 6
|
||||
_ChaCha20_ctr32_nohw:
|
||||
_ChaCha20_ctr32:
|
||||
|
||||
_CET_ENDBR
|
||||
cmpq $0,%rdx
|
||||
je L$no_data
|
||||
movq _OPENSSL_ia32cap_P+4(%rip),%r10
|
||||
testl $512,%r10d
|
||||
jnz L$ChaCha20_ssse3
|
||||
|
||||
pushq %rbx
|
||||
|
||||
pushq %rbp
|
||||
@@ -313,18 +322,20 @@ L$done:
|
||||
leaq (%rsi),%rsp
|
||||
|
||||
L$no_data:
|
||||
ret
|
||||
.byte 0xf3,0xc3
|
||||
|
||||
|
||||
.globl _ChaCha20_ctr32_ssse3
|
||||
.private_extern _ChaCha20_ctr32_ssse3
|
||||
|
||||
.p2align 5
|
||||
_ChaCha20_ctr32_ssse3:
|
||||
ChaCha20_ssse3:
|
||||
L$ChaCha20_ssse3:
|
||||
|
||||
_CET_ENDBR
|
||||
movq %rsp,%r9
|
||||
|
||||
cmpq $128,%rdx
|
||||
ja L$ChaCha20_4x
|
||||
|
||||
L$do_sse3_after_all:
|
||||
subq $64+8,%rsp
|
||||
movdqa L$sigma(%rip),%xmm0
|
||||
movdqu (%rcx),%xmm1
|
||||
@@ -448,18 +459,28 @@ L$done_ssse3:
|
||||
leaq (%r9),%rsp
|
||||
|
||||
L$ssse3_epilogue:
|
||||
ret
|
||||
.byte 0xf3,0xc3
|
||||
|
||||
|
||||
.globl _ChaCha20_ctr32_ssse3_4x
|
||||
.private_extern _ChaCha20_ctr32_ssse3_4x
|
||||
|
||||
.p2align 5
|
||||
_ChaCha20_ctr32_ssse3_4x:
|
||||
ChaCha20_4x:
|
||||
L$ChaCha20_4x:
|
||||
|
||||
_CET_ENDBR
|
||||
movq %rsp,%r9
|
||||
|
||||
movq %r10,%r11
|
||||
shrq $32,%r10
|
||||
testq $32,%r10
|
||||
jnz L$ChaCha20_8x
|
||||
cmpq $192,%rdx
|
||||
ja L$proceed4x
|
||||
|
||||
andq $71303168,%r11
|
||||
cmpq $4194304,%r11
|
||||
je L$do_sse3_after_all
|
||||
|
||||
L$proceed4x:
|
||||
subq $0x140+8,%rsp
|
||||
movdqa L$sigma(%rip),%xmm11
|
||||
movdqu (%rcx),%xmm15
|
||||
@@ -990,16 +1011,14 @@ L$done4x:
|
||||
leaq (%r9),%rsp
|
||||
|
||||
L$4x_epilogue:
|
||||
ret
|
||||
.byte 0xf3,0xc3
|
||||
|
||||
|
||||
.globl _ChaCha20_ctr32_avx2
|
||||
.private_extern _ChaCha20_ctr32_avx2
|
||||
|
||||
.p2align 5
|
||||
_ChaCha20_ctr32_avx2:
|
||||
ChaCha20_8x:
|
||||
L$ChaCha20_8x:
|
||||
|
||||
_CET_ENDBR
|
||||
movq %rsp,%r9
|
||||
|
||||
subq $0x280+8,%rsp
|
||||
@@ -1598,10 +1617,11 @@ L$done8x:
|
||||
leaq (%r9),%rsp
|
||||
|
||||
L$8x_epilogue:
|
||||
ret
|
||||
.byte 0xf3,0xc3
|
||||
|
||||
|
||||
#endif
|
||||
#endif // defined(__x86_64__) && defined(__APPLE__)
|
||||
#if defined(__linux__) && defined(__ELF__)
|
||||
.section .note.GNU-stack,"",%progbits
|
||||
#endif
|
||||
@@ -60,40 +60,7 @@ void CRYPTO_hchacha20(uint8_t out[32], const uint8_t key[32],
|
||||
OPENSSL_memcpy(&out[16], &x[12], sizeof(uint32_t) * 4);
|
||||
}
|
||||
|
||||
#if defined(CHACHA20_ASM_NOHW)
|
||||
static void ChaCha20_ctr32(uint8_t *out, const uint8_t *in, size_t in_len,
|
||||
const uint32_t key[8], const uint32_t counter[4]) {
|
||||
#if defined(CHACHA20_ASM_NEON)
|
||||
if (ChaCha20_ctr32_neon_capable(in_len)) {
|
||||
ChaCha20_ctr32_neon(out, in, in_len, key, counter);
|
||||
return;
|
||||
}
|
||||
#endif
|
||||
#if defined(CHACHA20_ASM_AVX2)
|
||||
if (ChaCha20_ctr32_avx2_capable(in_len)) {
|
||||
ChaCha20_ctr32_avx2(out, in, in_len, key, counter);
|
||||
return;
|
||||
}
|
||||
#endif
|
||||
#if defined(CHACHA20_ASM_SSSE3_4X)
|
||||
if (ChaCha20_ctr32_ssse3_4x_capable(in_len)) {
|
||||
ChaCha20_ctr32_ssse3_4x(out, in, in_len, key, counter);
|
||||
return;
|
||||
}
|
||||
#endif
|
||||
#if defined(CHACHA20_ASM_SSSE3)
|
||||
if (ChaCha20_ctr32_ssse3_capable(in_len)) {
|
||||
ChaCha20_ctr32_ssse3(out, in, in_len, key, counter);
|
||||
return;
|
||||
}
|
||||
#endif
|
||||
if (in_len > 0) {
|
||||
ChaCha20_ctr32_nohw(out, in, in_len, key, counter);
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
#if defined(CHACHA20_ASM_NOHW)
|
||||
#if defined(CHACHA20_ASM)
|
||||
|
||||
void CRYPTO_chacha_20(uint8_t *out, const uint8_t *in, size_t in_len,
|
||||
const uint8_t key[32], const uint8_t nonce[12],
|
||||
|
||||
@@ -17,8 +17,6 @@
|
||||
|
||||
#include <CCryptoBoringSSL_base.h>
|
||||
|
||||
#include "../internal.h"
|
||||
|
||||
#if defined(__cplusplus)
|
||||
extern "C" {
|
||||
#endif
|
||||
@@ -29,69 +27,21 @@ extern "C" {
|
||||
void CRYPTO_hchacha20(uint8_t out[32], const uint8_t key[32],
|
||||
const uint8_t nonce[16]);
|
||||
|
||||
#if !defined(OPENSSL_NO_ASM) && defined(OPENSSL_X86)
|
||||
#if !defined(OPENSSL_NO_ASM) && \
|
||||
(defined(OPENSSL_X86) || defined(OPENSSL_X86_64) || \
|
||||
defined(OPENSSL_ARM) || defined(OPENSSL_AARCH64))
|
||||
#define CHACHA20_ASM
|
||||
|
||||
#define CHACHA20_ASM_NOHW
|
||||
|
||||
#define CHACHA20_ASM_SSSE3
|
||||
OPENSSL_INLINE int ChaCha20_ctr32_ssse3_capable(size_t len) {
|
||||
// Unlike the x86_64 version, the x86 SSSE3 routine runs for all non-zero
|
||||
// lengths.
|
||||
return len > 0 && CRYPTO_is_SSSE3_capable() && CRYPTO_is_FXSR_capable();
|
||||
}
|
||||
void ChaCha20_ctr32_ssse3(uint8_t *out, const uint8_t *in, size_t in_len,
|
||||
const uint32_t key[8], const uint32_t counter[4]);
|
||||
|
||||
#elif !defined(OPENSSL_NO_ASM) && \
|
||||
(defined(OPENSSL_ARM) || defined(OPENSSL_AARCH64))
|
||||
|
||||
#define CHACHA20_ASM_NOHW
|
||||
|
||||
#define CHACHA20_ASM_NEON
|
||||
OPENSSL_INLINE int ChaCha20_ctr32_neon_capable(size_t len) {
|
||||
return len >= 192 && CRYPTO_is_NEON_capable();
|
||||
}
|
||||
void ChaCha20_ctr32_neon(uint8_t *out, const uint8_t *in, size_t in_len,
|
||||
const uint32_t key[8], const uint32_t counter[4]);
|
||||
#elif !defined(OPENSSL_NO_ASM) && defined(OPENSSL_X86_64)
|
||||
#define CHACHA20_ASM_NOHW
|
||||
|
||||
#define CHACHA20_ASM_AVX2
|
||||
OPENSSL_INLINE int ChaCha20_ctr32_avx2_capable(size_t len) {
|
||||
return len > 128 && CRYPTO_is_AVX2_capable();
|
||||
}
|
||||
void ChaCha20_ctr32_avx2(uint8_t *out, const uint8_t *in, size_t in_len,
|
||||
const uint32_t key[8], const uint32_t counter[4]);
|
||||
|
||||
#define CHACHA20_ASM_SSSE3_4X
|
||||
OPENSSL_INLINE int ChaCha20_ctr32_ssse3_4x_capable(size_t len) {
|
||||
int capable = len > 128 && CRYPTO_is_SSSE3_capable();
|
||||
int faster = len > 192 || !CRYPTO_cpu_perf_is_like_silvermont();
|
||||
return capable && faster;
|
||||
}
|
||||
void ChaCha20_ctr32_ssse3_4x(uint8_t *out, const uint8_t *in, size_t in_len,
|
||||
const uint32_t key[8], const uint32_t counter[4]);
|
||||
|
||||
#define CHACHA20_ASM_SSSE3
|
||||
OPENSSL_INLINE int ChaCha20_ctr32_ssse3_capable(size_t len) {
|
||||
return len > 128 && CRYPTO_is_SSSE3_capable();
|
||||
}
|
||||
void ChaCha20_ctr32_ssse3(uint8_t *out, const uint8_t *in, size_t in_len,
|
||||
const uint32_t key[8], const uint32_t counter[4]);
|
||||
#endif
|
||||
|
||||
#if defined(CHACHA20_ASM_NOHW)
|
||||
// ChaCha20_ctr32_nohw encrypts |in_len| bytes from |in| and writes the result
|
||||
// to |out|. If |in| and |out| alias, they must be equal. |in_len| may not be
|
||||
// zero.
|
||||
// ChaCha20_ctr32 encrypts |in_len| bytes from |in| and writes the result to
|
||||
// |out|. If |in| and |out| alias, they must be equal.
|
||||
//
|
||||
// |counter[0]| is the initial 32-bit block counter, and the remainder is the
|
||||
// 96-bit nonce. If the counter overflows, the output is undefined. The function
|
||||
// will produce output, but the output may vary by machine and may not be
|
||||
// self-consistent. (On some architectures, the assembly implements a mix of
|
||||
// 64-bit and 32-bit counters.)
|
||||
void ChaCha20_ctr32_nohw(uint8_t *out, const uint8_t *in, size_t in_len,
|
||||
const uint32_t key[8], const uint32_t counter[4]);
|
||||
void ChaCha20_ctr32(uint8_t *out, const uint8_t *in, size_t in_len,
|
||||
const uint32_t key[8], const uint32_t counter[4]);
|
||||
#endif
|
||||
|
||||
|
||||
|
||||
+35
-35
@@ -1,4 +1,5 @@
|
||||
#define BORINGSSL_PREFIX CCryptoBoringSSL
|
||||
#if defined(__x86_64__) && defined(__linux__)
|
||||
// This file is generated from a similarly-named Perl script in the BoringSSL
|
||||
// source tree. Do not edit by hand.
|
||||
|
||||
@@ -63,7 +64,7 @@ GFMUL:
|
||||
vpxor %xmm4,%xmm3,%xmm2
|
||||
|
||||
vpxor %xmm5,%xmm2,%xmm0
|
||||
ret
|
||||
.byte 0xf3,0xc3
|
||||
.cfi_endproc
|
||||
.size GFMUL, .-GFMUL
|
||||
.globl aesgcmsiv_htable_init
|
||||
@@ -90,7 +91,7 @@ _CET_ENDBR
|
||||
vmovdqa %xmm0,96(%rdi)
|
||||
call GFMUL
|
||||
vmovdqa %xmm0,112(%rdi)
|
||||
ret
|
||||
.byte 0xf3,0xc3
|
||||
.cfi_endproc
|
||||
.size aesgcmsiv_htable_init, .-aesgcmsiv_htable_init
|
||||
.globl aesgcmsiv_htable6_init
|
||||
@@ -113,7 +114,7 @@ _CET_ENDBR
|
||||
vmovdqa %xmm0,64(%rdi)
|
||||
call GFMUL
|
||||
vmovdqa %xmm0,80(%rdi)
|
||||
ret
|
||||
.byte 0xf3,0xc3
|
||||
.cfi_endproc
|
||||
.size aesgcmsiv_htable6_init, .-aesgcmsiv_htable6_init
|
||||
.globl aesgcmsiv_htable_polyval
|
||||
@@ -125,7 +126,7 @@ aesgcmsiv_htable_polyval:
|
||||
_CET_ENDBR
|
||||
testq %rdx,%rdx
|
||||
jnz .Lhtable_polyval_start
|
||||
ret
|
||||
.byte 0xf3,0xc3
|
||||
|
||||
.Lhtable_polyval_start:
|
||||
vzeroall
|
||||
@@ -331,7 +332,7 @@ _CET_ENDBR
|
||||
|
||||
vmovdqu %xmm1,(%rcx)
|
||||
vzeroupper
|
||||
ret
|
||||
.byte 0xf3,0xc3
|
||||
.cfi_endproc
|
||||
.size aesgcmsiv_htable_polyval,.-aesgcmsiv_htable_polyval
|
||||
.globl aesgcmsiv_polyval_horner
|
||||
@@ -343,7 +344,7 @@ aesgcmsiv_polyval_horner:
|
||||
_CET_ENDBR
|
||||
testq %rcx,%rcx
|
||||
jnz .Lpolyval_horner_start
|
||||
ret
|
||||
.byte 0xf3,0xc3
|
||||
|
||||
.Lpolyval_horner_start:
|
||||
|
||||
@@ -365,7 +366,7 @@ _CET_ENDBR
|
||||
|
||||
|
||||
vmovdqa %xmm0,(%rdi)
|
||||
ret
|
||||
.byte 0xf3,0xc3
|
||||
.cfi_endproc
|
||||
.size aesgcmsiv_polyval_horner,.-aesgcmsiv_polyval_horner
|
||||
.globl aes128gcmsiv_aes_ks
|
||||
@@ -422,7 +423,7 @@ _CET_ENDBR
|
||||
vpxor %xmm3,%xmm1,%xmm1
|
||||
vpxor %xmm2,%xmm1,%xmm1
|
||||
vmovdqa %xmm1,32(%rsi)
|
||||
ret
|
||||
.byte 0xf3,0xc3
|
||||
.cfi_endproc
|
||||
.size aes128gcmsiv_aes_ks,.-aes128gcmsiv_aes_ks
|
||||
.globl aes256gcmsiv_aes_ks
|
||||
@@ -471,7 +472,7 @@ _CET_ENDBR
|
||||
vpxor %xmm4,%xmm1,%xmm1
|
||||
vpxor %xmm2,%xmm1,%xmm1
|
||||
vmovdqa %xmm1,32(%rsi)
|
||||
ret
|
||||
.byte 0xf3,0xc3
|
||||
.cfi_endproc
|
||||
.globl aes128gcmsiv_aes_ks_enc_x1
|
||||
.hidden aes128gcmsiv_aes_ks_enc_x1
|
||||
@@ -613,7 +614,7 @@ _CET_ENDBR
|
||||
|
||||
|
||||
vmovdqa %xmm4,0(%rsi)
|
||||
ret
|
||||
.byte 0xf3,0xc3
|
||||
.cfi_endproc
|
||||
.size aes128gcmsiv_aes_ks_enc_x1,.-aes128gcmsiv_aes_ks_enc_x1
|
||||
.globl aes128gcmsiv_kdf
|
||||
@@ -707,7 +708,7 @@ _CET_ENDBR
|
||||
vmovdqa %xmm10,16(%rsi)
|
||||
vmovdqa %xmm11,32(%rsi)
|
||||
vmovdqa %xmm12,48(%rsi)
|
||||
ret
|
||||
.byte 0xf3,0xc3
|
||||
.cfi_endproc
|
||||
.size aes128gcmsiv_kdf,.-aes128gcmsiv_kdf
|
||||
.globl aes128gcmsiv_enc_msg_x4
|
||||
@@ -719,7 +720,7 @@ aes128gcmsiv_enc_msg_x4:
|
||||
_CET_ENDBR
|
||||
testq %r8,%r8
|
||||
jnz .L128_enc_msg_x4_start
|
||||
ret
|
||||
.byte 0xf3,0xc3
|
||||
|
||||
.L128_enc_msg_x4_start:
|
||||
pushq %r12
|
||||
@@ -887,7 +888,7 @@ _CET_ENDBR
|
||||
popq %r12
|
||||
.cfi_adjust_cfa_offset -8
|
||||
.cfi_restore %r12
|
||||
ret
|
||||
.byte 0xf3,0xc3
|
||||
.cfi_endproc
|
||||
.size aes128gcmsiv_enc_msg_x4,.-aes128gcmsiv_enc_msg_x4
|
||||
.globl aes128gcmsiv_enc_msg_x8
|
||||
@@ -899,7 +900,7 @@ aes128gcmsiv_enc_msg_x8:
|
||||
_CET_ENDBR
|
||||
testq %r8,%r8
|
||||
jnz .L128_enc_msg_x8_start
|
||||
ret
|
||||
.byte 0xf3,0xc3
|
||||
|
||||
.L128_enc_msg_x8_start:
|
||||
pushq %r12
|
||||
@@ -1149,7 +1150,7 @@ _CET_ENDBR
|
||||
popq %r12
|
||||
.cfi_adjust_cfa_offset -8
|
||||
.cfi_restore %r12
|
||||
ret
|
||||
.byte 0xf3,0xc3
|
||||
.cfi_endproc
|
||||
.size aes128gcmsiv_enc_msg_x8,.-aes128gcmsiv_enc_msg_x8
|
||||
.globl aes128gcmsiv_dec
|
||||
@@ -1161,20 +1162,19 @@ aes128gcmsiv_dec:
|
||||
_CET_ENDBR
|
||||
testq $~15,%r9
|
||||
jnz .L128_dec_start
|
||||
ret
|
||||
.byte 0xf3,0xc3
|
||||
|
||||
.L128_dec_start:
|
||||
vzeroupper
|
||||
vmovdqa (%rdx),%xmm0
|
||||
|
||||
|
||||
vmovdqu 16(%rdx),%xmm15
|
||||
vpor OR_MASK(%rip),%xmm15,%xmm15
|
||||
movq %rdx,%rax
|
||||
|
||||
leaq 32(%rax),%rax
|
||||
leaq 32(%rcx),%rcx
|
||||
|
||||
|
||||
vmovdqu (%rdi,%r9,1),%xmm15
|
||||
vpor OR_MASK(%rip),%xmm15,%xmm15
|
||||
andq $~15,%r9
|
||||
|
||||
|
||||
@@ -1643,7 +1643,7 @@ _CET_ENDBR
|
||||
|
||||
.L128_dec_out:
|
||||
vmovdqu %xmm0,(%rdx)
|
||||
ret
|
||||
.byte 0xf3,0xc3
|
||||
.cfi_endproc
|
||||
.size aes128gcmsiv_dec, .-aes128gcmsiv_dec
|
||||
.globl aes128gcmsiv_ecb_enc_block
|
||||
@@ -1669,7 +1669,7 @@ _CET_ENDBR
|
||||
|
||||
vmovdqa %xmm1,(%rsi)
|
||||
|
||||
ret
|
||||
.byte 0xf3,0xc3
|
||||
.cfi_endproc
|
||||
.size aes128gcmsiv_ecb_enc_block,.-aes128gcmsiv_ecb_enc_block
|
||||
.globl aes256gcmsiv_aes_ks_enc_x1
|
||||
@@ -1853,7 +1853,7 @@ _CET_ENDBR
|
||||
vmovdqu %xmm1,224(%rdx)
|
||||
|
||||
vmovdqa %xmm8,(%rsi)
|
||||
ret
|
||||
.byte 0xf3,0xc3
|
||||
.cfi_endproc
|
||||
.size aes256gcmsiv_aes_ks_enc_x1,.-aes256gcmsiv_aes_ks_enc_x1
|
||||
.globl aes256gcmsiv_ecb_enc_block
|
||||
@@ -1880,7 +1880,7 @@ _CET_ENDBR
|
||||
vaesenc 208(%rdx),%xmm1,%xmm1
|
||||
vaesenclast 224(%rdx),%xmm1,%xmm1
|
||||
vmovdqa %xmm1,(%rsi)
|
||||
ret
|
||||
.byte 0xf3,0xc3
|
||||
.cfi_endproc
|
||||
.size aes256gcmsiv_ecb_enc_block,.-aes256gcmsiv_ecb_enc_block
|
||||
.globl aes256gcmsiv_enc_msg_x4
|
||||
@@ -1892,7 +1892,7 @@ aes256gcmsiv_enc_msg_x4:
|
||||
_CET_ENDBR
|
||||
testq %r8,%r8
|
||||
jnz .L256_enc_msg_x4_start
|
||||
ret
|
||||
.byte 0xf3,0xc3
|
||||
|
||||
.L256_enc_msg_x4_start:
|
||||
movq %r8,%r10
|
||||
@@ -2082,7 +2082,7 @@ _CET_ENDBR
|
||||
jne .L256_enc_msg_x4_loop2
|
||||
|
||||
.L256_enc_msg_x4_out:
|
||||
ret
|
||||
.byte 0xf3,0xc3
|
||||
.cfi_endproc
|
||||
.size aes256gcmsiv_enc_msg_x4,.-aes256gcmsiv_enc_msg_x4
|
||||
.globl aes256gcmsiv_enc_msg_x8
|
||||
@@ -2094,7 +2094,7 @@ aes256gcmsiv_enc_msg_x8:
|
||||
_CET_ENDBR
|
||||
testq %r8,%r8
|
||||
jnz .L256_enc_msg_x8_start
|
||||
ret
|
||||
.byte 0xf3,0xc3
|
||||
|
||||
.L256_enc_msg_x8_start:
|
||||
|
||||
@@ -2371,7 +2371,7 @@ _CET_ENDBR
|
||||
jnz .L256_enc_msg_x8_loop2
|
||||
|
||||
.L256_enc_msg_x8_out:
|
||||
ret
|
||||
.byte 0xf3,0xc3
|
||||
|
||||
.cfi_endproc
|
||||
.size aes256gcmsiv_enc_msg_x8,.-aes256gcmsiv_enc_msg_x8
|
||||
@@ -2384,20 +2384,19 @@ aes256gcmsiv_dec:
|
||||
_CET_ENDBR
|
||||
testq $~15,%r9
|
||||
jnz .L256_dec_start
|
||||
ret
|
||||
.byte 0xf3,0xc3
|
||||
|
||||
.L256_dec_start:
|
||||
vzeroupper
|
||||
vmovdqa (%rdx),%xmm0
|
||||
|
||||
|
||||
vmovdqu 16(%rdx),%xmm15
|
||||
vpor OR_MASK(%rip),%xmm15,%xmm15
|
||||
movq %rdx,%rax
|
||||
|
||||
leaq 32(%rax),%rax
|
||||
leaq 32(%rcx),%rcx
|
||||
|
||||
|
||||
vmovdqu (%rdi,%r9,1),%xmm15
|
||||
vpor OR_MASK(%rip),%xmm15,%xmm15
|
||||
andq $~15,%r9
|
||||
|
||||
|
||||
@@ -2934,7 +2933,7 @@ _CET_ENDBR
|
||||
|
||||
.L256_dec_out:
|
||||
vmovdqu %xmm0,(%rdx)
|
||||
ret
|
||||
.byte 0xf3,0xc3
|
||||
.cfi_endproc
|
||||
.size aes256gcmsiv_dec, .-aes256gcmsiv_dec
|
||||
.globl aes256gcmsiv_kdf
|
||||
@@ -3086,10 +3085,11 @@ _CET_ENDBR
|
||||
vmovdqa %xmm11,48(%rsi)
|
||||
vmovdqa %xmm12,64(%rsi)
|
||||
vmovdqa %xmm13,80(%rsi)
|
||||
ret
|
||||
.byte 0xf3,0xc3
|
||||
.cfi_endproc
|
||||
.size aes256gcmsiv_kdf, .-aes256gcmsiv_kdf
|
||||
#endif
|
||||
#endif // defined(__x86_64__) && defined(__linux__)
|
||||
#if defined(__linux__) && defined(__ELF__)
|
||||
.section .note.GNU-stack,"",%progbits
|
||||
#endif
|
||||
+35
-35
@@ -1,4 +1,5 @@
|
||||
#define BORINGSSL_PREFIX CCryptoBoringSSL
|
||||
#if defined(__x86_64__) && defined(__APPLE__)
|
||||
// This file is generated from a similarly-named Perl script in the BoringSSL
|
||||
// source tree. Do not edit by hand.
|
||||
|
||||
@@ -63,7 +64,7 @@ GFMUL:
|
||||
vpxor %xmm4,%xmm3,%xmm2
|
||||
|
||||
vpxor %xmm5,%xmm2,%xmm0
|
||||
ret
|
||||
.byte 0xf3,0xc3
|
||||
|
||||
|
||||
.globl _aesgcmsiv_htable_init
|
||||
@@ -90,7 +91,7 @@ _CET_ENDBR
|
||||
vmovdqa %xmm0,96(%rdi)
|
||||
call GFMUL
|
||||
vmovdqa %xmm0,112(%rdi)
|
||||
ret
|
||||
.byte 0xf3,0xc3
|
||||
|
||||
|
||||
.globl _aesgcmsiv_htable6_init
|
||||
@@ -113,7 +114,7 @@ _CET_ENDBR
|
||||
vmovdqa %xmm0,64(%rdi)
|
||||
call GFMUL
|
||||
vmovdqa %xmm0,80(%rdi)
|
||||
ret
|
||||
.byte 0xf3,0xc3
|
||||
|
||||
|
||||
.globl _aesgcmsiv_htable_polyval
|
||||
@@ -125,7 +126,7 @@ _aesgcmsiv_htable_polyval:
|
||||
_CET_ENDBR
|
||||
testq %rdx,%rdx
|
||||
jnz L$htable_polyval_start
|
||||
ret
|
||||
.byte 0xf3,0xc3
|
||||
|
||||
L$htable_polyval_start:
|
||||
vzeroall
|
||||
@@ -331,7 +332,7 @@ L$htable_polyval_out:
|
||||
|
||||
vmovdqu %xmm1,(%rcx)
|
||||
vzeroupper
|
||||
ret
|
||||
.byte 0xf3,0xc3
|
||||
|
||||
|
||||
.globl _aesgcmsiv_polyval_horner
|
||||
@@ -343,7 +344,7 @@ _aesgcmsiv_polyval_horner:
|
||||
_CET_ENDBR
|
||||
testq %rcx,%rcx
|
||||
jnz L$polyval_horner_start
|
||||
ret
|
||||
.byte 0xf3,0xc3
|
||||
|
||||
L$polyval_horner_start:
|
||||
|
||||
@@ -365,7 +366,7 @@ L$polyval_horner_loop:
|
||||
|
||||
|
||||
vmovdqa %xmm0,(%rdi)
|
||||
ret
|
||||
.byte 0xf3,0xc3
|
||||
|
||||
|
||||
.globl _aes128gcmsiv_aes_ks
|
||||
@@ -422,7 +423,7 @@ L$ks128_loop:
|
||||
vpxor %xmm3,%xmm1,%xmm1
|
||||
vpxor %xmm2,%xmm1,%xmm1
|
||||
vmovdqa %xmm1,32(%rsi)
|
||||
ret
|
||||
.byte 0xf3,0xc3
|
||||
|
||||
|
||||
.globl _aes256gcmsiv_aes_ks
|
||||
@@ -471,7 +472,7 @@ L$ks256_loop:
|
||||
vpxor %xmm4,%xmm1,%xmm1
|
||||
vpxor %xmm2,%xmm1,%xmm1
|
||||
vmovdqa %xmm1,32(%rsi)
|
||||
ret
|
||||
.byte 0xf3,0xc3
|
||||
|
||||
.globl _aes128gcmsiv_aes_ks_enc_x1
|
||||
.private_extern _aes128gcmsiv_aes_ks_enc_x1
|
||||
@@ -613,7 +614,7 @@ _CET_ENDBR
|
||||
|
||||
|
||||
vmovdqa %xmm4,0(%rsi)
|
||||
ret
|
||||
.byte 0xf3,0xc3
|
||||
|
||||
|
||||
.globl _aes128gcmsiv_kdf
|
||||
@@ -707,7 +708,7 @@ _CET_ENDBR
|
||||
vmovdqa %xmm10,16(%rsi)
|
||||
vmovdqa %xmm11,32(%rsi)
|
||||
vmovdqa %xmm12,48(%rsi)
|
||||
ret
|
||||
.byte 0xf3,0xc3
|
||||
|
||||
|
||||
.globl _aes128gcmsiv_enc_msg_x4
|
||||
@@ -719,7 +720,7 @@ _aes128gcmsiv_enc_msg_x4:
|
||||
_CET_ENDBR
|
||||
testq %r8,%r8
|
||||
jnz L$128_enc_msg_x4_start
|
||||
ret
|
||||
.byte 0xf3,0xc3
|
||||
|
||||
L$128_enc_msg_x4_start:
|
||||
pushq %r12
|
||||
@@ -883,7 +884,7 @@ L$128_enc_msg_x4_out:
|
||||
|
||||
popq %r12
|
||||
|
||||
ret
|
||||
.byte 0xf3,0xc3
|
||||
|
||||
|
||||
.globl _aes128gcmsiv_enc_msg_x8
|
||||
@@ -895,7 +896,7 @@ _aes128gcmsiv_enc_msg_x8:
|
||||
_CET_ENDBR
|
||||
testq %r8,%r8
|
||||
jnz L$128_enc_msg_x8_start
|
||||
ret
|
||||
.byte 0xf3,0xc3
|
||||
|
||||
L$128_enc_msg_x8_start:
|
||||
pushq %r12
|
||||
@@ -1139,7 +1140,7 @@ L$128_enc_msg_x8_out:
|
||||
|
||||
popq %r12
|
||||
|
||||
ret
|
||||
.byte 0xf3,0xc3
|
||||
|
||||
|
||||
.globl _aes128gcmsiv_dec
|
||||
@@ -1151,20 +1152,19 @@ _aes128gcmsiv_dec:
|
||||
_CET_ENDBR
|
||||
testq $~15,%r9
|
||||
jnz L$128_dec_start
|
||||
ret
|
||||
.byte 0xf3,0xc3
|
||||
|
||||
L$128_dec_start:
|
||||
vzeroupper
|
||||
vmovdqa (%rdx),%xmm0
|
||||
|
||||
|
||||
vmovdqu 16(%rdx),%xmm15
|
||||
vpor OR_MASK(%rip),%xmm15,%xmm15
|
||||
movq %rdx,%rax
|
||||
|
||||
leaq 32(%rax),%rax
|
||||
leaq 32(%rcx),%rcx
|
||||
|
||||
|
||||
vmovdqu (%rdi,%r9,1),%xmm15
|
||||
vpor OR_MASK(%rip),%xmm15,%xmm15
|
||||
andq $~15,%r9
|
||||
|
||||
|
||||
@@ -1633,7 +1633,7 @@ L$128_dec_loop2:
|
||||
|
||||
L$128_dec_out:
|
||||
vmovdqu %xmm0,(%rdx)
|
||||
ret
|
||||
.byte 0xf3,0xc3
|
||||
|
||||
|
||||
.globl _aes128gcmsiv_ecb_enc_block
|
||||
@@ -1659,7 +1659,7 @@ _CET_ENDBR
|
||||
|
||||
vmovdqa %xmm1,(%rsi)
|
||||
|
||||
ret
|
||||
.byte 0xf3,0xc3
|
||||
|
||||
|
||||
.globl _aes256gcmsiv_aes_ks_enc_x1
|
||||
@@ -1843,7 +1843,7 @@ _CET_ENDBR
|
||||
vmovdqu %xmm1,224(%rdx)
|
||||
|
||||
vmovdqa %xmm8,(%rsi)
|
||||
ret
|
||||
.byte 0xf3,0xc3
|
||||
|
||||
|
||||
.globl _aes256gcmsiv_ecb_enc_block
|
||||
@@ -1870,7 +1870,7 @@ _CET_ENDBR
|
||||
vaesenc 208(%rdx),%xmm1,%xmm1
|
||||
vaesenclast 224(%rdx),%xmm1,%xmm1
|
||||
vmovdqa %xmm1,(%rsi)
|
||||
ret
|
||||
.byte 0xf3,0xc3
|
||||
|
||||
|
||||
.globl _aes256gcmsiv_enc_msg_x4
|
||||
@@ -1882,7 +1882,7 @@ _aes256gcmsiv_enc_msg_x4:
|
||||
_CET_ENDBR
|
||||
testq %r8,%r8
|
||||
jnz L$256_enc_msg_x4_start
|
||||
ret
|
||||
.byte 0xf3,0xc3
|
||||
|
||||
L$256_enc_msg_x4_start:
|
||||
movq %r8,%r10
|
||||
@@ -2072,7 +2072,7 @@ L$256_enc_msg_x4_loop2:
|
||||
jne L$256_enc_msg_x4_loop2
|
||||
|
||||
L$256_enc_msg_x4_out:
|
||||
ret
|
||||
.byte 0xf3,0xc3
|
||||
|
||||
|
||||
.globl _aes256gcmsiv_enc_msg_x8
|
||||
@@ -2084,7 +2084,7 @@ _aes256gcmsiv_enc_msg_x8:
|
||||
_CET_ENDBR
|
||||
testq %r8,%r8
|
||||
jnz L$256_enc_msg_x8_start
|
||||
ret
|
||||
.byte 0xf3,0xc3
|
||||
|
||||
L$256_enc_msg_x8_start:
|
||||
|
||||
@@ -2361,7 +2361,7 @@ L$256_enc_msg_x8_loop2:
|
||||
jnz L$256_enc_msg_x8_loop2
|
||||
|
||||
L$256_enc_msg_x8_out:
|
||||
ret
|
||||
.byte 0xf3,0xc3
|
||||
|
||||
|
||||
|
||||
@@ -2374,20 +2374,19 @@ _aes256gcmsiv_dec:
|
||||
_CET_ENDBR
|
||||
testq $~15,%r9
|
||||
jnz L$256_dec_start
|
||||
ret
|
||||
.byte 0xf3,0xc3
|
||||
|
||||
L$256_dec_start:
|
||||
vzeroupper
|
||||
vmovdqa (%rdx),%xmm0
|
||||
|
||||
|
||||
vmovdqu 16(%rdx),%xmm15
|
||||
vpor OR_MASK(%rip),%xmm15,%xmm15
|
||||
movq %rdx,%rax
|
||||
|
||||
leaq 32(%rax),%rax
|
||||
leaq 32(%rcx),%rcx
|
||||
|
||||
|
||||
vmovdqu (%rdi,%r9,1),%xmm15
|
||||
vpor OR_MASK(%rip),%xmm15,%xmm15
|
||||
andq $~15,%r9
|
||||
|
||||
|
||||
@@ -2924,7 +2923,7 @@ L$256_dec_loop2:
|
||||
|
||||
L$256_dec_out:
|
||||
vmovdqu %xmm0,(%rdx)
|
||||
ret
|
||||
.byte 0xf3,0xc3
|
||||
|
||||
|
||||
.globl _aes256gcmsiv_kdf
|
||||
@@ -3076,10 +3075,11 @@ _CET_ENDBR
|
||||
vmovdqa %xmm11,48(%rsi)
|
||||
vmovdqa %xmm12,64(%rsi)
|
||||
vmovdqa %xmm13,80(%rsi)
|
||||
ret
|
||||
.byte 0xf3,0xc3
|
||||
|
||||
|
||||
#endif
|
||||
#endif // defined(__x86_64__) && defined(__APPLE__)
|
||||
#if defined(__linux__) && defined(__ELF__)
|
||||
.section .note.GNU-stack,"",%progbits
|
||||
#endif
|
||||
+2
@@ -1,4 +1,5 @@
|
||||
#define BORINGSSL_PREFIX CCryptoBoringSSL
|
||||
#if defined(__aarch64__) && defined(__APPLE__)
|
||||
// This file is generated from a similarly-named Perl script in the BoringSSL
|
||||
// source tree. Do not edit by hand.
|
||||
|
||||
@@ -3008,6 +3009,7 @@ Lopen_128_hash_64:
|
||||
.cfi_endproc
|
||||
|
||||
#endif // !OPENSSL_NO_ASM && defined(OPENSSL_AARCH64) && defined(__APPLE__)
|
||||
#endif // defined(__aarch64__) && defined(__APPLE__)
|
||||
#if defined(__linux__) && defined(__ELF__)
|
||||
.section .note.GNU-stack,"",%progbits
|
||||
#endif
|
||||
+2
@@ -1,4 +1,5 @@
|
||||
#define BORINGSSL_PREFIX CCryptoBoringSSL
|
||||
#if defined(__aarch64__) && defined(__linux__)
|
||||
// This file is generated from a similarly-named Perl script in the BoringSSL
|
||||
// source tree. Do not edit by hand.
|
||||
|
||||
@@ -3008,6 +3009,7 @@ chacha20_poly1305_open:
|
||||
.cfi_endproc
|
||||
.size chacha20_poly1305_open,.-chacha20_poly1305_open
|
||||
#endif // !OPENSSL_NO_ASM && defined(OPENSSL_AARCH64) && defined(__ELF__)
|
||||
#endif // defined(__aarch64__) && defined(__linux__)
|
||||
#if defined(__linux__) && defined(__ELF__)
|
||||
.section .note.GNU-stack,"",%progbits
|
||||
#endif
|
||||
+36
-56
@@ -1,13 +1,19 @@
|
||||
#define BORINGSSL_PREFIX CCryptoBoringSSL
|
||||
#if defined(__x86_64__) && defined(__linux__)
|
||||
// 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_X86_64) && defined(__ELF__)
|
||||
.text
|
||||
.extern OPENSSL_ia32cap_P
|
||||
.hidden OPENSSL_ia32cap_P
|
||||
|
||||
chacha20_poly1305_constants:
|
||||
|
||||
.section .rodata
|
||||
.align 64
|
||||
chacha20_poly1305_constants:
|
||||
.Lchacha20_consts:
|
||||
.byte 'e','x','p','a','n','d',' ','3','2','-','b','y','t','e',' ','k'
|
||||
.byte 'e','x','p','a','n','d',' ','3','2','-','b','y','t','e',' ','k'
|
||||
@@ -100,7 +106,7 @@ poly_hash_ad_internal:
|
||||
adcq %r9,%r11
|
||||
adcq $0,%r12
|
||||
|
||||
ret
|
||||
.byte 0xf3,0xc3
|
||||
.Lhash_ad_loop:
|
||||
|
||||
cmpq $16,%r8
|
||||
@@ -209,15 +215,15 @@ poly_hash_ad_internal:
|
||||
|
||||
|
||||
.Lhash_ad_done:
|
||||
ret
|
||||
.byte 0xf3,0xc3
|
||||
.cfi_endproc
|
||||
.size poly_hash_ad_internal, .-poly_hash_ad_internal
|
||||
|
||||
.globl chacha20_poly1305_open_nohw
|
||||
.hidden chacha20_poly1305_open_nohw
|
||||
.type chacha20_poly1305_open_nohw,@function
|
||||
.globl chacha20_poly1305_open
|
||||
.hidden chacha20_poly1305_open
|
||||
.type chacha20_poly1305_open,@function
|
||||
.align 64
|
||||
chacha20_poly1305_open_nohw:
|
||||
chacha20_poly1305_open:
|
||||
.cfi_startproc
|
||||
_CET_ENDBR
|
||||
pushq %rbp
|
||||
@@ -253,6 +259,11 @@ _CET_ENDBR
|
||||
movq %r8,0+0+32(%rbp)
|
||||
movq %rbx,8+0+32(%rbp)
|
||||
|
||||
movl OPENSSL_ia32cap_P+8(%rip),%eax
|
||||
andl $288,%eax
|
||||
xorl $288,%eax
|
||||
jz chacha20_poly1305_open_avx2
|
||||
|
||||
cmpq $128,%rbx
|
||||
jbe .Lopen_sse_128
|
||||
|
||||
@@ -1853,7 +1864,7 @@ _CET_ENDBR
|
||||
popq %rbp
|
||||
.cfi_adjust_cfa_offset -8
|
||||
.cfi_restore %rbp
|
||||
ret
|
||||
.byte 0xf3,0xc3
|
||||
|
||||
.Lopen_sse_128:
|
||||
.cfi_restore_state
|
||||
@@ -2085,7 +2096,7 @@ _CET_ENDBR
|
||||
movdqa %xmm10,%xmm6
|
||||
movdqa %xmm14,%xmm10
|
||||
jmp .Lopen_sse_128_xor_hash
|
||||
.size chacha20_poly1305_open_nohw, .-chacha20_poly1305_open_nohw
|
||||
.size chacha20_poly1305_open, .-chacha20_poly1305_open
|
||||
.cfi_endproc
|
||||
|
||||
|
||||
@@ -2094,11 +2105,11 @@ _CET_ENDBR
|
||||
|
||||
|
||||
|
||||
.globl chacha20_poly1305_seal_nohw
|
||||
.hidden chacha20_poly1305_seal_nohw
|
||||
.type chacha20_poly1305_seal_nohw,@function
|
||||
.globl chacha20_poly1305_seal
|
||||
.hidden chacha20_poly1305_seal
|
||||
.type chacha20_poly1305_seal,@function
|
||||
.align 64
|
||||
chacha20_poly1305_seal_nohw:
|
||||
chacha20_poly1305_seal:
|
||||
.cfi_startproc
|
||||
_CET_ENDBR
|
||||
pushq %rbp
|
||||
@@ -2135,6 +2146,11 @@ _CET_ENDBR
|
||||
movq %rbx,8+0+32(%rbp)
|
||||
movq %rdx,%rbx
|
||||
|
||||
movl OPENSSL_ia32cap_P+8(%rip),%eax
|
||||
andl $288,%eax
|
||||
xorl $288,%eax
|
||||
jz chacha20_poly1305_seal_avx2
|
||||
|
||||
cmpq $128,%rbx
|
||||
jbe .Lseal_sse_128
|
||||
|
||||
@@ -3914,7 +3930,7 @@ process_extra_in_trailer:
|
||||
popq %rbp
|
||||
.cfi_adjust_cfa_offset -8
|
||||
.cfi_restore %rbp
|
||||
ret
|
||||
.byte 0xf3,0xc3
|
||||
|
||||
.Lseal_sse_128:
|
||||
.cfi_restore_state
|
||||
@@ -4086,50 +4102,32 @@ process_extra_in_trailer:
|
||||
movq %r8,%r8
|
||||
call poly_hash_ad_internal
|
||||
jmp .Lseal_sse_128_tail_xor
|
||||
.size chacha20_poly1305_seal_nohw, .-chacha20_poly1305_seal_nohw
|
||||
.size chacha20_poly1305_seal, .-chacha20_poly1305_seal
|
||||
.cfi_endproc
|
||||
|
||||
|
||||
.globl chacha20_poly1305_open_avx2
|
||||
.hidden chacha20_poly1305_open_avx2
|
||||
.type chacha20_poly1305_open_avx2,@function
|
||||
.align 64
|
||||
chacha20_poly1305_open_avx2:
|
||||
.cfi_startproc
|
||||
_CET_ENDBR
|
||||
pushq %rbp
|
||||
|
||||
|
||||
.cfi_adjust_cfa_offset 8
|
||||
.cfi_offset %rbp,-16
|
||||
pushq %rbx
|
||||
.cfi_adjust_cfa_offset 8
|
||||
.cfi_offset %rbx,-24
|
||||
pushq %r12
|
||||
.cfi_adjust_cfa_offset 8
|
||||
.cfi_offset %r12,-32
|
||||
pushq %r13
|
||||
.cfi_adjust_cfa_offset 8
|
||||
.cfi_offset %r13,-40
|
||||
pushq %r14
|
||||
.cfi_adjust_cfa_offset 8
|
||||
.cfi_offset %r14,-48
|
||||
pushq %r15
|
||||
.cfi_adjust_cfa_offset 8
|
||||
.cfi_offset %r15,-56
|
||||
|
||||
|
||||
pushq %r9
|
||||
.cfi_adjust_cfa_offset 8
|
||||
.cfi_offset %r9,-64
|
||||
subq $288 + 0 + 32,%rsp
|
||||
.cfi_adjust_cfa_offset 288 + 32
|
||||
|
||||
leaq 32(%rsp),%rbp
|
||||
andq $-32,%rbp
|
||||
|
||||
movq %rdx,%rbx
|
||||
movq %r8,0+0+32(%rbp)
|
||||
movq %rbx,8+0+32(%rbp)
|
||||
|
||||
vzeroupper
|
||||
vmovdqa .Lchacha20_consts(%rip),%ymm0
|
||||
vbroadcasti128 0(%r9),%ymm4
|
||||
@@ -6263,46 +6261,27 @@ _CET_ENDBR
|
||||
.cfi_endproc
|
||||
|
||||
|
||||
.globl chacha20_poly1305_seal_avx2
|
||||
.hidden chacha20_poly1305_seal_avx2
|
||||
.type chacha20_poly1305_seal_avx2,@function
|
||||
.align 64
|
||||
chacha20_poly1305_seal_avx2:
|
||||
.cfi_startproc
|
||||
_CET_ENDBR
|
||||
pushq %rbp
|
||||
|
||||
|
||||
.cfi_adjust_cfa_offset 8
|
||||
.cfi_offset %rbp,-16
|
||||
pushq %rbx
|
||||
.cfi_adjust_cfa_offset 8
|
||||
.cfi_offset %rbx,-24
|
||||
pushq %r12
|
||||
.cfi_adjust_cfa_offset 8
|
||||
.cfi_offset %r12,-32
|
||||
pushq %r13
|
||||
.cfi_adjust_cfa_offset 8
|
||||
.cfi_offset %r13,-40
|
||||
pushq %r14
|
||||
.cfi_adjust_cfa_offset 8
|
||||
.cfi_offset %r14,-48
|
||||
pushq %r15
|
||||
.cfi_adjust_cfa_offset 8
|
||||
.cfi_offset %r15,-56
|
||||
|
||||
|
||||
pushq %r9
|
||||
.cfi_adjust_cfa_offset 8
|
||||
.cfi_offset %r9,-64
|
||||
subq $288 + 0 + 32,%rsp
|
||||
.cfi_adjust_cfa_offset 288 + 32
|
||||
leaq 32(%rsp),%rbp
|
||||
andq $-32,%rbp
|
||||
|
||||
movq 56(%r9),%rbx
|
||||
addq %rdx,%rbx
|
||||
movq %r8,0+0+32(%rbp)
|
||||
movq %rbx,8+0+32(%rbp)
|
||||
movq %rdx,%rbx
|
||||
|
||||
vzeroupper
|
||||
vmovdqa .Lchacha20_consts(%rip),%ymm0
|
||||
@@ -8939,6 +8918,7 @@ _CET_ENDBR
|
||||
.cfi_endproc
|
||||
.size chacha20_poly1305_seal_avx2, .-chacha20_poly1305_seal_avx2
|
||||
#endif
|
||||
#endif // defined(__x86_64__) && defined(__linux__)
|
||||
#if defined(__linux__) && defined(__ELF__)
|
||||
.section .note.GNU-stack,"",%progbits
|
||||
#endif
|
||||
+39
-60
@@ -1,13 +1,18 @@
|
||||
#define BORINGSSL_PREFIX CCryptoBoringSSL
|
||||
#if defined(__x86_64__) && 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_X86_64) && defined(__APPLE__)
|
||||
.text
|
||||
|
||||
|
||||
chacha20_poly1305_constants:
|
||||
|
||||
.section __DATA,__const
|
||||
.p2align 6
|
||||
chacha20_poly1305_constants:
|
||||
L$chacha20_consts:
|
||||
.byte 'e','x','p','a','n','d',' ','3','2','-','b','y','t','e',' ','k'
|
||||
.byte 'e','x','p','a','n','d',' ','3','2','-','b','y','t','e',' ','k'
|
||||
@@ -100,7 +105,7 @@ L$poly_fast_tls_ad:
|
||||
adcq %r9,%r11
|
||||
adcq $0,%r12
|
||||
|
||||
ret
|
||||
.byte 0xf3,0xc3
|
||||
L$hash_ad_loop:
|
||||
|
||||
cmpq $16,%r8
|
||||
@@ -209,15 +214,15 @@ L$hash_ad_tail_loop:
|
||||
|
||||
|
||||
L$hash_ad_done:
|
||||
ret
|
||||
.byte 0xf3,0xc3
|
||||
|
||||
|
||||
|
||||
.globl _chacha20_poly1305_open_nohw
|
||||
.private_extern _chacha20_poly1305_open_nohw
|
||||
.globl _chacha20_poly1305_open
|
||||
.private_extern _chacha20_poly1305_open
|
||||
|
||||
.p2align 6
|
||||
_chacha20_poly1305_open_nohw:
|
||||
_chacha20_poly1305_open:
|
||||
|
||||
_CET_ENDBR
|
||||
pushq %rbp
|
||||
@@ -246,6 +251,11 @@ _CET_ENDBR
|
||||
movq %r8,0+0+32(%rbp)
|
||||
movq %rbx,8+0+32(%rbp)
|
||||
|
||||
movl _OPENSSL_ia32cap_P+8(%rip),%eax
|
||||
andl $288,%eax
|
||||
xorl $288,%eax
|
||||
jz chacha20_poly1305_open_avx2
|
||||
|
||||
cmpq $128,%rbx
|
||||
jbe L$open_sse_128
|
||||
|
||||
@@ -1839,7 +1849,7 @@ L$open_sse_finalize:
|
||||
|
||||
popq %rbp
|
||||
|
||||
ret
|
||||
.byte 0xf3,0xc3
|
||||
|
||||
L$open_sse_128:
|
||||
|
||||
@@ -2080,11 +2090,11 @@ L$open_sse_128_xor_hash:
|
||||
|
||||
|
||||
|
||||
.globl _chacha20_poly1305_seal_nohw
|
||||
.private_extern _chacha20_poly1305_seal_nohw
|
||||
.globl _chacha20_poly1305_seal
|
||||
.private_extern _chacha20_poly1305_seal
|
||||
|
||||
.p2align 6
|
||||
_chacha20_poly1305_seal_nohw:
|
||||
_chacha20_poly1305_seal:
|
||||
|
||||
_CET_ENDBR
|
||||
pushq %rbp
|
||||
@@ -2114,6 +2124,11 @@ _CET_ENDBR
|
||||
movq %rbx,8+0+32(%rbp)
|
||||
movq %rdx,%rbx
|
||||
|
||||
movl _OPENSSL_ia32cap_P+8(%rip),%eax
|
||||
andl $288,%eax
|
||||
xorl $288,%eax
|
||||
jz chacha20_poly1305_seal_avx2
|
||||
|
||||
cmpq $128,%rbx
|
||||
jbe L$seal_sse_128
|
||||
|
||||
@@ -3886,7 +3901,7 @@ L$do_length_block:
|
||||
|
||||
popq %rbp
|
||||
|
||||
ret
|
||||
.byte 0xf3,0xc3
|
||||
|
||||
L$seal_sse_128:
|
||||
|
||||
@@ -4062,38 +4077,20 @@ L$seal_sse_128_rounds:
|
||||
|
||||
|
||||
|
||||
.globl _chacha20_poly1305_open_avx2
|
||||
.private_extern _chacha20_poly1305_open_avx2
|
||||
|
||||
.p2align 6
|
||||
_chacha20_poly1305_open_avx2:
|
||||
|
||||
_CET_ENDBR
|
||||
pushq %rbp
|
||||
|
||||
pushq %rbx
|
||||
|
||||
pushq %r12
|
||||
|
||||
pushq %r13
|
||||
|
||||
pushq %r14
|
||||
|
||||
pushq %r15
|
||||
chacha20_poly1305_open_avx2:
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
pushq %r9
|
||||
|
||||
subq $288 + 0 + 32,%rsp
|
||||
|
||||
|
||||
leaq 32(%rsp),%rbp
|
||||
andq $-32,%rbp
|
||||
|
||||
movq %rdx,%rbx
|
||||
movq %r8,0+0+32(%rbp)
|
||||
movq %rbx,8+0+32(%rbp)
|
||||
|
||||
vzeroupper
|
||||
vmovdqa L$chacha20_consts(%rip),%ymm0
|
||||
@@ -6228,39 +6225,20 @@ L$open_avx2_320_rounds:
|
||||
|
||||
|
||||
|
||||
.globl _chacha20_poly1305_seal_avx2
|
||||
.private_extern _chacha20_poly1305_seal_avx2
|
||||
|
||||
.p2align 6
|
||||
_chacha20_poly1305_seal_avx2:
|
||||
|
||||
_CET_ENDBR
|
||||
pushq %rbp
|
||||
|
||||
pushq %rbx
|
||||
|
||||
pushq %r12
|
||||
|
||||
pushq %r13
|
||||
|
||||
pushq %r14
|
||||
|
||||
pushq %r15
|
||||
chacha20_poly1305_seal_avx2:
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
pushq %r9
|
||||
|
||||
subq $288 + 0 + 32,%rsp
|
||||
|
||||
leaq 32(%rsp),%rbp
|
||||
andq $-32,%rbp
|
||||
|
||||
movq 56(%r9),%rbx
|
||||
addq %rdx,%rbx
|
||||
movq %r8,0+0+32(%rbp)
|
||||
movq %rbx,8+0+32(%rbp)
|
||||
movq %rdx,%rbx
|
||||
|
||||
vzeroupper
|
||||
vmovdqa L$chacha20_consts(%rip),%ymm0
|
||||
@@ -8897,6 +8875,7 @@ L$seal_avx2_exit:
|
||||
|
||||
|
||||
#endif
|
||||
#endif // defined(__x86_64__) && defined(__APPLE__)
|
||||
#if defined(__linux__) && defined(__ELF__)
|
||||
.section .note.GNU-stack,"",%progbits
|
||||
#endif
|
||||
@@ -126,16 +126,16 @@ extern void aesgcmsiv_htable_polyval(const uint8_t htable[16 * 8],
|
||||
uint8_t in_out_poly[16]);
|
||||
|
||||
// aes128gcmsiv_dec decrypts |in_len| & ~15 bytes from |out| and writes them to
|
||||
// |in|. |in| and |out| may be equal, but must not otherwise alias.
|
||||
// |in|. (The full value of |in_len| is still used to find the authentication
|
||||
// tag appended to the ciphertext, however, so must not be pre-masked.)
|
||||
//
|
||||
// |in_out_calculated_tag_and_scratch|, on entry, must contain:
|
||||
// 1. The current value of the calculated tag, which will be updated during
|
||||
// decryption and written back to the beginning of this buffer on exit.
|
||||
// 2. The claimed tag, which is needed to derive counter values.
|
||||
// |in| and |out| may be equal, but must not otherwise overlap.
|
||||
//
|
||||
// While decrypting, the whole of |in_out_calculated_tag_and_scratch| may be
|
||||
// used for other purposes. In order to decrypt and update the POLYVAL value, it
|
||||
// uses the expanded key from |key| and the table of powers in |htable|.
|
||||
// While decrypting, it updates the POLYVAL value found at the beginning of
|
||||
// |in_out_calculated_tag_and_scratch| and writes the updated value back before
|
||||
// return. During executation, it may use the whole of this space for other
|
||||
// purposes. In order to decrypt and update the POLYVAL value, it uses the
|
||||
// expanded key from |key| and the table of powers in |htable|.
|
||||
extern void aes128gcmsiv_dec(const uint8_t *in, uint8_t *out,
|
||||
uint8_t in_out_calculated_tag_and_scratch[16 * 8],
|
||||
const uint8_t htable[16 * 6],
|
||||
@@ -393,10 +393,14 @@ static int aead_aes_gcm_siv_asm_seal_scatter(
|
||||
return 1;
|
||||
}
|
||||
|
||||
static int aead_aes_gcm_siv_asm_open_gather(
|
||||
const EVP_AEAD_CTX *ctx, uint8_t *out, const uint8_t *nonce,
|
||||
size_t nonce_len, const uint8_t *in, size_t in_len, const uint8_t *in_tag,
|
||||
size_t in_tag_len, const uint8_t *ad, size_t ad_len) {
|
||||
// TODO(martinkr): Add aead_aes_gcm_siv_asm_open_gather. N.B. aes128gcmsiv_dec
|
||||
// expects ciphertext and tag in a contiguous buffer.
|
||||
|
||||
static int aead_aes_gcm_siv_asm_open(const EVP_AEAD_CTX *ctx, uint8_t *out,
|
||||
size_t *out_len, size_t max_out_len,
|
||||
const uint8_t *nonce, size_t nonce_len,
|
||||
const uint8_t *in, size_t in_len,
|
||||
const uint8_t *ad, size_t ad_len) {
|
||||
const uint64_t ad_len_64 = ad_len;
|
||||
if (ad_len_64 >= (UINT64_C(1) << 61)) {
|
||||
OPENSSL_PUT_ERROR(CIPHER, CIPHER_R_TOO_LARGE);
|
||||
@@ -404,8 +408,8 @@ static int aead_aes_gcm_siv_asm_open_gather(
|
||||
}
|
||||
|
||||
const uint64_t in_len_64 = in_len;
|
||||
if (in_len_64 > UINT64_C(1) << 36 ||
|
||||
in_tag_len != EVP_AEAD_AES_GCM_SIV_TAG_LEN) {
|
||||
if (in_len < EVP_AEAD_AES_GCM_SIV_TAG_LEN ||
|
||||
in_len_64 > (UINT64_C(1) << 36) + AES_BLOCK_SIZE) {
|
||||
OPENSSL_PUT_ERROR(CIPHER, CIPHER_R_BAD_DECRYPT);
|
||||
return 0;
|
||||
}
|
||||
@@ -416,6 +420,13 @@ static int aead_aes_gcm_siv_asm_open_gather(
|
||||
}
|
||||
|
||||
const struct aead_aes_gcm_siv_asm_ctx *gcm_siv_ctx = asm_ctx_from_ctx(ctx);
|
||||
const size_t plaintext_len = in_len - EVP_AEAD_AES_GCM_SIV_TAG_LEN;
|
||||
const uint8_t *const given_tag = in + plaintext_len;
|
||||
|
||||
if (max_out_len < plaintext_len) {
|
||||
OPENSSL_PUT_ERROR(CIPHER, CIPHER_R_BUFFER_TOO_SMALL);
|
||||
return 0;
|
||||
}
|
||||
|
||||
alignas(16) uint64_t record_auth_key[2];
|
||||
alignas(16) uint64_t record_enc_key[4];
|
||||
@@ -448,27 +459,27 @@ static int aead_aes_gcm_siv_asm_open_gather(
|
||||
alignas(16) uint8_t htable[16 * 6];
|
||||
aesgcmsiv_htable6_init(htable, (const uint8_t *)record_auth_key);
|
||||
|
||||
// aes[128|256]gcmsiv_dec needs access to the claimed tag. So it's put into
|
||||
// its scratch space.
|
||||
memcpy(calculated_tag + 16, in_tag, EVP_AEAD_AES_GCM_SIV_TAG_LEN);
|
||||
if (gcm_siv_ctx->is_128_bit) {
|
||||
aes128gcmsiv_dec(in, out, calculated_tag, htable, &expanded_key, in_len);
|
||||
aes128gcmsiv_dec(in, out, calculated_tag, htable, &expanded_key,
|
||||
plaintext_len);
|
||||
} else {
|
||||
aes256gcmsiv_dec(in, out, calculated_tag, htable, &expanded_key, in_len);
|
||||
aes256gcmsiv_dec(in, out, calculated_tag, htable, &expanded_key,
|
||||
plaintext_len);
|
||||
}
|
||||
|
||||
if (in_len & 15) {
|
||||
if (plaintext_len & 15) {
|
||||
aead_aes_gcm_siv_asm_crypt_last_block(gcm_siv_ctx->is_128_bit, out, in,
|
||||
in_len, in_tag, &expanded_key);
|
||||
plaintext_len, given_tag,
|
||||
&expanded_key);
|
||||
OPENSSL_memset(scratch, 0, sizeof(scratch));
|
||||
OPENSSL_memcpy(scratch, out + (in_len & ~15), in_len & 15);
|
||||
OPENSSL_memcpy(scratch, out + (plaintext_len & ~15), plaintext_len & 15);
|
||||
aesgcmsiv_polyval_horner(calculated_tag, (const uint8_t *)record_auth_key,
|
||||
scratch, 1);
|
||||
}
|
||||
|
||||
uint8_t length_block[16];
|
||||
CRYPTO_store_u64_le(length_block, ad_len * 8);
|
||||
CRYPTO_store_u64_le(length_block + 8, in_len * 8);
|
||||
CRYPTO_store_u64_le(length_block + 8, plaintext_len * 8);
|
||||
aesgcmsiv_polyval_horner(calculated_tag, (const uint8_t *)record_auth_key,
|
||||
length_block, 1);
|
||||
|
||||
@@ -484,12 +495,13 @@ static int aead_aes_gcm_siv_asm_open_gather(
|
||||
aes256gcmsiv_ecb_enc_block(calculated_tag, calculated_tag, &expanded_key);
|
||||
}
|
||||
|
||||
if (CRYPTO_memcmp(calculated_tag, in_tag, EVP_AEAD_AES_GCM_SIV_TAG_LEN) !=
|
||||
if (CRYPTO_memcmp(calculated_tag, given_tag, EVP_AEAD_AES_GCM_SIV_TAG_LEN) !=
|
||||
0) {
|
||||
OPENSSL_PUT_ERROR(CIPHER, CIPHER_R_BAD_DECRYPT);
|
||||
return 0;
|
||||
}
|
||||
|
||||
*out_len = in_len - EVP_AEAD_AES_GCM_SIV_TAG_LEN;
|
||||
return 1;
|
||||
}
|
||||
|
||||
@@ -503,9 +515,9 @@ static const EVP_AEAD aead_aes_128_gcm_siv_asm = {
|
||||
aead_aes_gcm_siv_asm_init,
|
||||
NULL /* init_with_direction */,
|
||||
aead_aes_gcm_siv_asm_cleanup,
|
||||
NULL /* open */,
|
||||
aead_aes_gcm_siv_asm_open,
|
||||
aead_aes_gcm_siv_asm_seal_scatter,
|
||||
aead_aes_gcm_siv_asm_open_gather,
|
||||
NULL /* open_gather */,
|
||||
NULL /* get_iv */,
|
||||
NULL /* tag_len */,
|
||||
};
|
||||
@@ -520,9 +532,9 @@ static const EVP_AEAD aead_aes_256_gcm_siv_asm = {
|
||||
aead_aes_gcm_siv_asm_init,
|
||||
NULL /* init_with_direction */,
|
||||
aead_aes_gcm_siv_asm_cleanup,
|
||||
NULL /* open */,
|
||||
aead_aes_gcm_siv_asm_open,
|
||||
aead_aes_gcm_siv_asm_seal_scatter,
|
||||
aead_aes_gcm_siv_asm_open_gather,
|
||||
NULL /* open_gather */,
|
||||
NULL /* get_iv */,
|
||||
NULL /* tag_len */,
|
||||
};
|
||||
@@ -635,8 +647,8 @@ static void gcm_siv_polyval(
|
||||
}
|
||||
|
||||
uint8_t length_block[16];
|
||||
CRYPTO_store_u64_le(length_block, ((uint64_t) ad_len) * 8);
|
||||
CRYPTO_store_u64_le(length_block + 8, ((uint64_t) in_len) * 8);
|
||||
CRYPTO_store_u64_le(length_block, ad_len * 8);
|
||||
CRYPTO_store_u64_le(length_block + 8, in_len * 8);
|
||||
CRYPTO_POLYVAL_update_blocks(&polyval_ctx, length_block,
|
||||
sizeof(length_block));
|
||||
|
||||
|
||||
@@ -58,7 +58,6 @@
|
||||
#include <CCryptoBoringSSL_des.h>
|
||||
#include <CCryptoBoringSSL_nid.h>
|
||||
|
||||
#include "../des/internal.h"
|
||||
#include "../fipsmodule/cipher/internal.h"
|
||||
#include "internal.h"
|
||||
|
||||
@@ -72,27 +71,35 @@ typedef struct {
|
||||
|
||||
static int des_init_key(EVP_CIPHER_CTX *ctx, const uint8_t *key,
|
||||
const uint8_t *iv, int enc) {
|
||||
DES_cblock *deskey = (DES_cblock *)key;
|
||||
EVP_DES_KEY *dat = (EVP_DES_KEY *)ctx->cipher_data;
|
||||
DES_set_key_ex(key, &dat->ks.ks);
|
||||
|
||||
DES_set_key(deskey, &dat->ks.ks);
|
||||
return 1;
|
||||
}
|
||||
|
||||
static int des_cbc_cipher(EVP_CIPHER_CTX *ctx, uint8_t *out, const uint8_t *in,
|
||||
size_t in_len) {
|
||||
EVP_DES_KEY *dat = (EVP_DES_KEY *)ctx->cipher_data;
|
||||
DES_ncbc_encrypt_ex(in, out, in_len, &dat->ks.ks, ctx->iv, ctx->encrypt);
|
||||
|
||||
DES_ncbc_encrypt(in, out, in_len, &dat->ks.ks, (DES_cblock *)ctx->iv,
|
||||
ctx->encrypt);
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
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,
|
||||
.init = des_init_key,
|
||||
.cipher = des_cbc_cipher,
|
||||
/* 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,
|
||||
};
|
||||
|
||||
const EVP_CIPHER *EVP_des_cbc(void) { return &evp_des_cbc; }
|
||||
@@ -106,20 +113,24 @@ static int des_ecb_cipher(EVP_CIPHER_CTX *ctx, uint8_t *out, const uint8_t *in,
|
||||
|
||||
EVP_DES_KEY *dat = (EVP_DES_KEY *)ctx->cipher_data;
|
||||
for (size_t i = 0; i <= in_len; i += ctx->cipher->block_size) {
|
||||
DES_ecb_encrypt_ex(in + i, out + i, &dat->ks.ks, ctx->encrypt);
|
||||
DES_ecb_encrypt((DES_cblock *)(in + i), (DES_cblock *)(out + i),
|
||||
&dat->ks.ks, ctx->encrypt);
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
|
||||
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,
|
||||
.init = des_init_key,
|
||||
.cipher = des_ecb_cipher,
|
||||
/* 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,
|
||||
};
|
||||
|
||||
const EVP_CIPHER *EVP_des_ecb(void) { return &evp_des_ecb; }
|
||||
@@ -133,53 +144,66 @@ typedef struct {
|
||||
|
||||
static int des_ede3_init_key(EVP_CIPHER_CTX *ctx, const uint8_t *key,
|
||||
const uint8_t *iv, int enc) {
|
||||
DES_cblock *deskey = (DES_cblock *)key;
|
||||
DES_EDE_KEY *dat = (DES_EDE_KEY *)ctx->cipher_data;
|
||||
DES_set_key_ex(key, &dat->ks.ks[0]);
|
||||
DES_set_key_ex(key + 8, &dat->ks.ks[1]);
|
||||
DES_set_key_ex(key + 16, &dat->ks.ks[2]);
|
||||
|
||||
DES_set_key(&deskey[0], &dat->ks.ks[0]);
|
||||
DES_set_key(&deskey[1], &dat->ks.ks[1]);
|
||||
DES_set_key(&deskey[2], &dat->ks.ks[2]);
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
static int des_ede3_cbc_cipher(EVP_CIPHER_CTX *ctx, uint8_t *out,
|
||||
const uint8_t *in, size_t in_len) {
|
||||
DES_EDE_KEY *dat = (DES_EDE_KEY *)ctx->cipher_data;
|
||||
DES_ede3_cbc_encrypt_ex(in, out, in_len, &dat->ks.ks[0], &dat->ks.ks[1],
|
||||
&dat->ks.ks[2], ctx->iv, ctx->encrypt);
|
||||
|
||||
DES_ede3_cbc_encrypt(in, out, in_len, &dat->ks.ks[0], &dat->ks.ks[1],
|
||||
&dat->ks.ks[2], (DES_cblock *)ctx->iv, ctx->encrypt);
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
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,
|
||||
.init = des_ede3_init_key,
|
||||
.cipher = des_ede3_cbc_cipher,
|
||||
/* 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,
|
||||
};
|
||||
|
||||
const EVP_CIPHER *EVP_des_ede3_cbc(void) { return &evp_des_ede3_cbc; }
|
||||
|
||||
static int des_ede_init_key(EVP_CIPHER_CTX *ctx, const uint8_t *key,
|
||||
const uint8_t *iv, int enc) {
|
||||
DES_cblock *deskey = (DES_cblock *)key;
|
||||
DES_EDE_KEY *dat = (DES_EDE_KEY *)ctx->cipher_data;
|
||||
// 2-DES is 3-DES with the first key used twice.
|
||||
DES_set_key_ex(key, &dat->ks.ks[0]);
|
||||
DES_set_key_ex(key + 8, &dat->ks.ks[1]);
|
||||
DES_set_key_ex(key, &dat->ks.ks[2]);
|
||||
|
||||
DES_set_key(&deskey[0], &dat->ks.ks[0]);
|
||||
DES_set_key(&deskey[1], &dat->ks.ks[1]);
|
||||
DES_set_key(&deskey[0], &dat->ks.ks[2]);
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
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,
|
||||
.init = des_ede_init_key,
|
||||
.cipher = des_ede3_cbc_cipher,
|
||||
/* 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,
|
||||
};
|
||||
|
||||
const EVP_CIPHER *EVP_des_ede_cbc(void) { return &evp_des_ede_cbc; }
|
||||
@@ -193,34 +217,41 @@ static int des_ede_ecb_cipher(EVP_CIPHER_CTX *ctx, uint8_t *out,
|
||||
|
||||
DES_EDE_KEY *dat = (DES_EDE_KEY *) ctx->cipher_data;
|
||||
for (size_t i = 0; i <= in_len; i += ctx->cipher->block_size) {
|
||||
DES_ecb3_encrypt_ex(in + i, out + i, &dat->ks.ks[0], &dat->ks.ks[1],
|
||||
&dat->ks.ks[2], ctx->encrypt);
|
||||
DES_ecb3_encrypt((DES_cblock *) (in + i), (DES_cblock *) (out + i),
|
||||
&dat->ks.ks[0], &dat->ks.ks[1], &dat->ks.ks[2],
|
||||
ctx->encrypt);
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
|
||||
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,
|
||||
.init = des_ede_init_key,
|
||||
.cipher = des_ede_ecb_cipher,
|
||||
/* 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,
|
||||
};
|
||||
|
||||
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,
|
||||
.init = des_ede3_init_key,
|
||||
.cipher = des_ede_ecb_cipher,
|
||||
/* 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,
|
||||
};
|
||||
|
||||
const EVP_CIPHER *EVP_des_ede3(void) { return &evp_des_ede3; }
|
||||
|
||||
@@ -78,13 +78,9 @@ static int null_cipher(EVP_CIPHER_CTX *ctx, uint8_t *out,
|
||||
}
|
||||
|
||||
static const EVP_CIPHER n_cipher = {
|
||||
.nid = NID_undef,
|
||||
.block_size = 1,
|
||||
.key_len = 0,
|
||||
.iv_len = 0,
|
||||
.ctx_size = 0,
|
||||
.init = null_init_key,
|
||||
.cipher = null_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 */,
|
||||
};
|
||||
|
||||
const EVP_CIPHER *EVP_enc_null(void) { return &n_cipher; }
|
||||
@@ -427,29 +427,37 @@ static int rc2_ctrl(EVP_CIPHER_CTX *ctx, int type, int arg, void *ptr) {
|
||||
}
|
||||
|
||||
static const EVP_CIPHER rc2_40_cbc = {
|
||||
.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,
|
||||
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,
|
||||
};
|
||||
|
||||
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 = 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,
|
||||
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,
|
||||
};
|
||||
|
||||
const EVP_CIPHER *EVP_rc2_cbc(void) { return &rc2_cbc; }
|
||||
const EVP_CIPHER *EVP_rc2_cbc(void) {
|
||||
return &rc2_cbc;
|
||||
}
|
||||
@@ -81,14 +81,9 @@ static int rc4_cipher(EVP_CIPHER_CTX *ctx, uint8_t *out, const uint8_t *in,
|
||||
}
|
||||
|
||||
static const EVP_CIPHER rc4 = {
|
||||
.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,
|
||||
};
|
||||
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 */, };
|
||||
|
||||
const EVP_CIPHER *EVP_rc4(void) { return &rc4; }
|
||||
@@ -442,7 +442,6 @@ static int aead_tls_get_iv(const EVP_AEAD_CTX *ctx, const uint8_t **out_iv,
|
||||
const AEAD_TLS_CTX *tls_ctx = (AEAD_TLS_CTX *)&ctx->state;
|
||||
const size_t iv_len = EVP_CIPHER_CTX_iv_length(&tls_ctx->cipher_ctx);
|
||||
if (iv_len <= 1) {
|
||||
OPENSSL_PUT_ERROR(CIPHER, ERR_R_SHOULD_NOT_HAVE_BEEN_CALLED);
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
@@ -192,65 +192,22 @@ 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;
|
||||
|
||||
declassify_assert(orig_len >= in_len);
|
||||
declassify_assert(in_len >= md_size);
|
||||
assert(orig_len >= in_len);
|
||||
assert(in_len >= md_size);
|
||||
assert(md_size <= EVP_MAX_MD_SIZE);
|
||||
assert(md_size > 0);
|
||||
|
||||
|
||||
@@ -56,7 +56,6 @@
|
||||
|
||||
#include <CCryptoBoringSSL_conf.h>
|
||||
|
||||
#include <assert.h>
|
||||
#include <string.h>
|
||||
#include <ctype.h>
|
||||
|
||||
@@ -66,141 +65,131 @@
|
||||
#include <CCryptoBoringSSL_lhash.h>
|
||||
#include <CCryptoBoringSSL_mem.h>
|
||||
|
||||
#include "conf_def.h"
|
||||
#include "internal.h"
|
||||
#include "../internal.h"
|
||||
|
||||
|
||||
struct conf_section_st {
|
||||
char *name;
|
||||
// values contains non-owning pointers to the values in the section.
|
||||
STACK_OF(CONF_VALUE) *values;
|
||||
};
|
||||
|
||||
static const char kDefaultSectionName[] = "default";
|
||||
|
||||
static uint32_t conf_section_hash(const CONF_SECTION *s) {
|
||||
return OPENSSL_strhash(s->name);
|
||||
}
|
||||
|
||||
static int conf_section_cmp(const CONF_SECTION *a, const CONF_SECTION *b) {
|
||||
return strcmp(a->name, b->name);
|
||||
}
|
||||
|
||||
static uint32_t conf_value_hash(const CONF_VALUE *v) {
|
||||
const uint32_t section_hash = OPENSSL_strhash(v->section);
|
||||
const uint32_t name_hash = OPENSSL_strhash(v->name);
|
||||
const uint32_t section_hash = v->section ? OPENSSL_strhash(v->section) : 0;
|
||||
const uint32_t name_hash = v->name ? OPENSSL_strhash(v->name) : 0;
|
||||
return (section_hash << 2) ^ name_hash;
|
||||
}
|
||||
|
||||
static int conf_value_cmp(const CONF_VALUE *a, const CONF_VALUE *b) {
|
||||
int cmp = strcmp(a->section, b->section);
|
||||
if (cmp != 0) {
|
||||
return cmp;
|
||||
int i;
|
||||
|
||||
if (a->section != b->section) {
|
||||
i = strcmp(a->section, b->section);
|
||||
if (i) {
|
||||
return i;
|
||||
}
|
||||
}
|
||||
|
||||
return strcmp(a->name, b->name);
|
||||
if (a->name != NULL && b->name != NULL) {
|
||||
return strcmp(a->name, b->name);
|
||||
} else if (a->name == b->name) {
|
||||
return 0;
|
||||
} else {
|
||||
return (a->name == NULL) ? -1 : 1;
|
||||
}
|
||||
}
|
||||
|
||||
CONF *NCONF_new(void *method) {
|
||||
CONF *conf;
|
||||
|
||||
if (method != NULL) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
CONF *conf = OPENSSL_malloc(sizeof(CONF));
|
||||
conf = OPENSSL_malloc(sizeof(CONF));
|
||||
if (conf == NULL) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
conf->sections = lh_CONF_SECTION_new(conf_section_hash, conf_section_cmp);
|
||||
conf->values = lh_CONF_VALUE_new(conf_value_hash, conf_value_cmp);
|
||||
if (conf->sections == NULL || conf->values == NULL) {
|
||||
NCONF_free(conf);
|
||||
conf->data = lh_CONF_VALUE_new(conf_value_hash, conf_value_cmp);
|
||||
if (conf->data == NULL) {
|
||||
OPENSSL_free(conf);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
return conf;
|
||||
}
|
||||
|
||||
CONF_VALUE *CONF_VALUE_new(void) { return OPENSSL_zalloc(sizeof(CONF_VALUE)); }
|
||||
|
||||
static void value_free(CONF_VALUE *value) {
|
||||
if (value == NULL) {
|
||||
return;
|
||||
CONF_VALUE *CONF_VALUE_new(void) {
|
||||
CONF_VALUE *v = OPENSSL_malloc(sizeof(CONF_VALUE));
|
||||
if (!v) {
|
||||
return NULL;
|
||||
}
|
||||
OPENSSL_free(value->section);
|
||||
OPENSSL_free(value->name);
|
||||
OPENSSL_free(value->value);
|
||||
OPENSSL_free(value);
|
||||
OPENSSL_memset(v, 0, sizeof(CONF_VALUE));
|
||||
return v;
|
||||
}
|
||||
|
||||
static void section_free(CONF_SECTION *section) {
|
||||
if (section == NULL) {
|
||||
return;
|
||||
static void value_free_contents(CONF_VALUE *value) {
|
||||
OPENSSL_free(value->section);
|
||||
if (value->name) {
|
||||
OPENSSL_free(value->name);
|
||||
OPENSSL_free(value->value);
|
||||
} else {
|
||||
// TODO(davidben): When |value->name| is NULL, |CONF_VALUE| is actually an
|
||||
// entirely different structure. This is fragile and confusing. Make a
|
||||
// proper |CONF_SECTION| type that doesn't require this.
|
||||
sk_CONF_VALUE_free((STACK_OF(CONF_VALUE) *)value->value);
|
||||
}
|
||||
}
|
||||
|
||||
static void value_free(CONF_VALUE *value) {
|
||||
if (value != NULL) {
|
||||
value_free_contents(value);
|
||||
OPENSSL_free(value);
|
||||
}
|
||||
OPENSSL_free(section->name);
|
||||
sk_CONF_VALUE_free(section->values);
|
||||
OPENSSL_free(section);
|
||||
}
|
||||
|
||||
static void value_free_arg(CONF_VALUE *value, void *arg) { value_free(value); }
|
||||
|
||||
static void section_free_arg(CONF_SECTION *section, void *arg) {
|
||||
section_free(section);
|
||||
}
|
||||
|
||||
void NCONF_free(CONF *conf) {
|
||||
if (conf == NULL) {
|
||||
if (conf == NULL || conf->data == NULL) {
|
||||
return;
|
||||
}
|
||||
|
||||
lh_CONF_SECTION_doall_arg(conf->sections, section_free_arg, NULL);
|
||||
lh_CONF_SECTION_free(conf->sections);
|
||||
lh_CONF_VALUE_doall_arg(conf->values, value_free_arg, NULL);
|
||||
lh_CONF_VALUE_free(conf->values);
|
||||
lh_CONF_VALUE_doall_arg(conf->data, value_free_arg, NULL);
|
||||
lh_CONF_VALUE_free(conf->data);
|
||||
OPENSSL_free(conf);
|
||||
}
|
||||
|
||||
static CONF_SECTION *NCONF_new_section(const CONF *conf, const char *section) {
|
||||
CONF_SECTION *s = OPENSSL_malloc(sizeof(CONF_SECTION));
|
||||
if (!s) {
|
||||
return NULL;
|
||||
static CONF_VALUE *NCONF_new_section(const CONF *conf, const char *section) {
|
||||
STACK_OF(CONF_VALUE) *sk = NULL;
|
||||
int ok = 0;
|
||||
CONF_VALUE *v = NULL, *old_value;
|
||||
|
||||
sk = sk_CONF_VALUE_new_null();
|
||||
v = CONF_VALUE_new();
|
||||
if (sk == NULL || v == NULL) {
|
||||
goto err;
|
||||
}
|
||||
s->name = OPENSSL_strdup(section);
|
||||
s->values = sk_CONF_VALUE_new_null();
|
||||
if (s->name == NULL || s->values == NULL) {
|
||||
v->section = OPENSSL_strdup(section);
|
||||
if (v->section == NULL) {
|
||||
goto err;
|
||||
}
|
||||
|
||||
CONF_SECTION *old_section;
|
||||
if (!lh_CONF_SECTION_insert(conf->sections, &old_section, s)) {
|
||||
v->name = NULL;
|
||||
v->value = (char *)sk;
|
||||
|
||||
if (!lh_CONF_VALUE_insert(conf->data, &old_value, v)) {
|
||||
goto err;
|
||||
}
|
||||
section_free(old_section);
|
||||
return s;
|
||||
value_free(old_value);
|
||||
ok = 1;
|
||||
|
||||
err:
|
||||
section_free(s);
|
||||
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 == '-';
|
||||
if (!ok) {
|
||||
sk_CONF_VALUE_free(sk);
|
||||
OPENSSL_free(v);
|
||||
v = NULL;
|
||||
}
|
||||
return v;
|
||||
}
|
||||
|
||||
static int str_copy(CONF *conf, char *section, char **pto, char *from) {
|
||||
@@ -219,13 +208,13 @@ static int str_copy(CONF *conf, char *section, char **pto, char *from) {
|
||||
}
|
||||
|
||||
for (;;) {
|
||||
if (is_quote(*from)) {
|
||||
if (IS_QUOTE(conf, *from)) {
|
||||
q = *from;
|
||||
from++;
|
||||
while (*from != '\0' && *from != q) {
|
||||
if (is_esc(*from)) {
|
||||
while (!IS_EOF(conf, *from) && (*from != q)) {
|
||||
if (IS_ESC(conf, *from)) {
|
||||
from++;
|
||||
if (*from == '\0') {
|
||||
if (IS_EOF(conf, *from)) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
@@ -234,10 +223,10 @@ static int str_copy(CONF *conf, char *section, char **pto, char *from) {
|
||||
if (*from == q) {
|
||||
from++;
|
||||
}
|
||||
} else if (is_esc(*from)) {
|
||||
} else if (IS_ESC(conf, *from)) {
|
||||
from++;
|
||||
v = *(from++);
|
||||
if (v == '\0') {
|
||||
if (IS_EOF(conf, v)) {
|
||||
break;
|
||||
} else if (v == 'r') {
|
||||
v = '\r';
|
||||
@@ -249,13 +238,11 @@ static int str_copy(CONF *conf, char *section, char **pto, char *from) {
|
||||
v = '\t';
|
||||
}
|
||||
buf->data[to++] = v;
|
||||
} else if (*from == '\0') {
|
||||
} else if (IS_EOF(conf, *from)) {
|
||||
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. If
|
||||
// trying to embed '$' in a line, either escape it or wrap the value in
|
||||
// quotes.
|
||||
// feature has been removed as it was unused and is a DoS vector.
|
||||
OPENSSL_PUT_ERROR(CONF, CONF_R_VARIABLE_EXPANSION_NOT_SUPPORTED);
|
||||
goto err;
|
||||
} else {
|
||||
@@ -274,20 +261,21 @@ err:
|
||||
return 0;
|
||||
}
|
||||
|
||||
static CONF_SECTION *get_section(const CONF *conf, const char *section) {
|
||||
CONF_SECTION template;
|
||||
static CONF_VALUE *get_section(const CONF *conf, const char *section) {
|
||||
CONF_VALUE template;
|
||||
|
||||
OPENSSL_memset(&template, 0, sizeof(template));
|
||||
template.name = (char *) section;
|
||||
return lh_CONF_SECTION_retrieve(conf->sections, &template);
|
||||
template.section = (char *) section;
|
||||
return lh_CONF_VALUE_retrieve(conf->data, &template);
|
||||
}
|
||||
|
||||
const STACK_OF(CONF_VALUE) *NCONF_get_section(const CONF *conf,
|
||||
const char *section) {
|
||||
const CONF_SECTION *section_obj = get_section(conf, section);
|
||||
if (section_obj == NULL) {
|
||||
const CONF_VALUE *section_value = get_section(conf, section);
|
||||
if (section_value == NULL) {
|
||||
return NULL;
|
||||
}
|
||||
return section_obj->values;
|
||||
return (STACK_OF(CONF_VALUE)*) section_value->value;
|
||||
}
|
||||
|
||||
const char *NCONF_get_string(const CONF *conf, const char *section,
|
||||
@@ -299,74 +287,66 @@ const char *NCONF_get_string(const CONF *conf, const char *section,
|
||||
}
|
||||
|
||||
OPENSSL_memset(&template, 0, sizeof(template));
|
||||
template.section = (char *)section;
|
||||
template.name = (char *)name;
|
||||
value = lh_CONF_VALUE_retrieve(conf->values, &template);
|
||||
template.section = (char *) section;
|
||||
template.name = (char *) name;
|
||||
value = lh_CONF_VALUE_retrieve(conf->data, &template);
|
||||
if (value == NULL) {
|
||||
return NULL;
|
||||
}
|
||||
return value->value;
|
||||
}
|
||||
|
||||
static int add_string(const CONF *conf, CONF_SECTION *section,
|
||||
static int add_string(const CONF *conf, CONF_VALUE *section,
|
||||
CONF_VALUE *value) {
|
||||
value->section = OPENSSL_strdup(section->name);
|
||||
if (value->section == NULL) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (!sk_CONF_VALUE_push(section->values, value)) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
STACK_OF(CONF_VALUE) *section_stack = (STACK_OF(CONF_VALUE)*) section->value;
|
||||
CONF_VALUE *old_value;
|
||||
if (!lh_CONF_VALUE_insert(conf->values, &old_value, value)) {
|
||||
// Remove |value| from |section->values|, so we do not leave a dangling
|
||||
// pointer.
|
||||
sk_CONF_VALUE_pop(section->values);
|
||||
|
||||
value->section = OPENSSL_strdup(section->section);
|
||||
if (!sk_CONF_VALUE_push(section_stack, value)) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (!lh_CONF_VALUE_insert(conf->data, &old_value, value)) {
|
||||
return 0;
|
||||
}
|
||||
if (old_value != NULL) {
|
||||
(void)sk_CONF_VALUE_delete_ptr(section->values, old_value);
|
||||
(void)sk_CONF_VALUE_delete_ptr(section_stack, old_value);
|
||||
value_free(old_value);
|
||||
}
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
static char *eat_ws(char *p) {
|
||||
while (*p != '\0' && is_conf_ws(*p)) {
|
||||
static char *eat_ws(CONF *conf, char *p) {
|
||||
while (IS_WS(conf, *p) && !IS_EOF(conf, *p)) {
|
||||
p++;
|
||||
}
|
||||
return p;
|
||||
}
|
||||
|
||||
static char *scan_esc(char *p) {
|
||||
assert(p[0] == '\\');
|
||||
return p[1] == '\0' ? p + 1 : p + 2;
|
||||
}
|
||||
#define scan_esc(conf, p) (((IS_EOF((conf), (p)[1])) ? ((p) + 1) : ((p) + 2)))
|
||||
|
||||
static char *eat_name(char *p) {
|
||||
static char *eat_alpha_numeric(CONF *conf, char *p) {
|
||||
for (;;) {
|
||||
if (is_esc(*p)) {
|
||||
p = scan_esc(p);
|
||||
if (IS_ESC(conf, *p)) {
|
||||
p = scan_esc(conf, p);
|
||||
continue;
|
||||
}
|
||||
if (!is_name_char(*p)) {
|
||||
if (!IS_ALPHA_NUMERIC_PUNCT(conf, *p)) {
|
||||
return p;
|
||||
}
|
||||
p++;
|
||||
}
|
||||
}
|
||||
|
||||
static char *scan_quote(char *p) {
|
||||
static char *scan_quote(CONF *conf, char *p) {
|
||||
int q = *p;
|
||||
|
||||
p++;
|
||||
while (*p != '\0' && *p != q) {
|
||||
if (is_esc(*p)) {
|
||||
while (!IS_EOF(conf, *p) && *p != q) {
|
||||
if (IS_ESC(conf, *p)) {
|
||||
p++;
|
||||
if (*p == '\0') {
|
||||
if (IS_EOF(conf, *p)) {
|
||||
return p;
|
||||
}
|
||||
}
|
||||
@@ -378,28 +358,28 @@ static char *scan_quote(char *p) {
|
||||
return p;
|
||||
}
|
||||
|
||||
static void clear_comments(char *p) {
|
||||
static void clear_comments(CONF *conf, char *p) {
|
||||
for (;;) {
|
||||
if (!is_conf_ws(*p)) {
|
||||
if (!IS_WS(conf, *p)) {
|
||||
break;
|
||||
}
|
||||
p++;
|
||||
}
|
||||
|
||||
for (;;) {
|
||||
if (is_comment(*p)) {
|
||||
if (IS_COMMENT(conf, *p)) {
|
||||
*p = '\0';
|
||||
return;
|
||||
}
|
||||
if (is_quote(*p)) {
|
||||
p = scan_quote(p);
|
||||
if (IS_QUOTE(conf, *p)) {
|
||||
p = scan_quote(conf, p);
|
||||
continue;
|
||||
}
|
||||
if (is_esc(*p)) {
|
||||
p = scan_esc(p);
|
||||
if (IS_ESC(conf, *p)) {
|
||||
p = scan_esc(conf, p);
|
||||
continue;
|
||||
}
|
||||
if (*p == '\0') {
|
||||
if (IS_EOF(conf, *p)) {
|
||||
return;
|
||||
} else {
|
||||
p++;
|
||||
@@ -415,8 +395,8 @@ int NCONF_load_bio(CONF *conf, BIO *in, long *out_error_line) {
|
||||
int again;
|
||||
long eline = 0;
|
||||
char btmp[DECIMAL_SIZE(eline) + 1];
|
||||
CONF_VALUE *v = NULL;
|
||||
CONF_SECTION *sv = NULL;
|
||||
CONF_VALUE *v = NULL, *tv;
|
||||
CONF_VALUE *sv = NULL;
|
||||
char *section = NULL, *buf;
|
||||
char *start, *psection, *pname;
|
||||
|
||||
@@ -479,7 +459,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(p[0]) && ((bufnum <= 1) || !is_esc(p[-1]))) {
|
||||
if (IS_ESC(conf, p[0]) && ((bufnum <= 1) || !IS_ESC(conf, p[-1]))) {
|
||||
bufnum--;
|
||||
again = 1;
|
||||
}
|
||||
@@ -490,20 +470,20 @@ int NCONF_load_bio(CONF *conf, BIO *in, long *out_error_line) {
|
||||
bufnum = 0;
|
||||
buf = buff->data;
|
||||
|
||||
clear_comments(buf);
|
||||
s = eat_ws(buf);
|
||||
if (*s == '\0') {
|
||||
clear_comments(conf, buf);
|
||||
s = eat_ws(conf, buf);
|
||||
if (IS_EOF(conf, *s)) {
|
||||
continue; // blank line
|
||||
}
|
||||
if (*s == '[') {
|
||||
char *ss;
|
||||
|
||||
s++;
|
||||
start = eat_ws(s);
|
||||
start = eat_ws(conf, s);
|
||||
ss = start;
|
||||
again:
|
||||
end = eat_name(ss);
|
||||
p = eat_ws(end);
|
||||
end = eat_alpha_numeric(conf, ss);
|
||||
p = eat_ws(conf, end);
|
||||
if (*p != ']') {
|
||||
if (*p != '\0' && ss != p) {
|
||||
ss = p;
|
||||
@@ -527,27 +507,27 @@ int NCONF_load_bio(CONF *conf, BIO *in, long *out_error_line) {
|
||||
} else {
|
||||
pname = s;
|
||||
psection = NULL;
|
||||
end = eat_name(s);
|
||||
end = eat_alpha_numeric(conf, s);
|
||||
if ((end[0] == ':') && (end[1] == ':')) {
|
||||
*end = '\0';
|
||||
end += 2;
|
||||
psection = pname;
|
||||
pname = end;
|
||||
end = eat_name(end);
|
||||
end = eat_alpha_numeric(conf, end);
|
||||
}
|
||||
p = eat_ws(end);
|
||||
p = eat_ws(conf, end);
|
||||
if (*p != '=') {
|
||||
OPENSSL_PUT_ERROR(CONF, CONF_R_MISSING_EQUAL_SIGN);
|
||||
goto err;
|
||||
}
|
||||
*end = '\0';
|
||||
p++;
|
||||
start = eat_ws(p);
|
||||
while (*p != '\0') {
|
||||
start = eat_ws(conf, p);
|
||||
while (!IS_EOF(conf, *p)) {
|
||||
p++;
|
||||
}
|
||||
p--;
|
||||
while (p != start && is_conf_ws(*p)) {
|
||||
while ((p != start) && (IS_WS(conf, *p))) {
|
||||
p--;
|
||||
}
|
||||
p++;
|
||||
@@ -567,7 +547,6 @@ int NCONF_load_bio(CONF *conf, BIO *in, long *out_error_line) {
|
||||
goto err;
|
||||
}
|
||||
|
||||
CONF_SECTION *tv;
|
||||
if (strcmp(psection, section) != 0) {
|
||||
if ((tv = get_section(conf, psection)) == NULL) {
|
||||
tv = NCONF_new_section(conf, psection);
|
||||
@@ -597,7 +576,12 @@ err:
|
||||
}
|
||||
snprintf(btmp, sizeof btmp, "%ld", eline);
|
||||
ERR_add_error_data(2, "line ", btmp);
|
||||
value_free(v);
|
||||
|
||||
if (v != NULL) {
|
||||
OPENSSL_free(v->name);
|
||||
OPENSSL_free(v->value);
|
||||
OPENSSL_free(v);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,122 @@
|
||||
/* 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,
|
||||
};
|
||||
@@ -24,14 +24,10 @@ extern "C" {
|
||||
#endif
|
||||
|
||||
|
||||
typedef struct conf_section_st CONF_SECTION;
|
||||
|
||||
DEFINE_LHASH_OF(CONF_SECTION)
|
||||
DEFINE_LHASH_OF(CONF_VALUE)
|
||||
|
||||
struct conf_st {
|
||||
LHASH_OF(CONF_VALUE) *values;
|
||||
LHASH_OF(CONF_SECTION) *sections;
|
||||
LHASH_OF(CONF_VALUE) *data;
|
||||
};
|
||||
|
||||
// CONF_VALUE_new returns a freshly allocated and zeroed |CONF_VALUE|.
|
||||
|
||||
@@ -15,7 +15,7 @@
|
||||
#include "internal.h"
|
||||
|
||||
#if defined(OPENSSL_AARCH64) && defined(OPENSSL_APPLE) && \
|
||||
!defined(OPENSSL_STATIC_ARMCAP) && !defined(OPENSSL_NO_ASM)
|
||||
!defined(OPENSSL_STATIC_ARMCAP)
|
||||
|
||||
#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_NO_ASM)
|
||||
!defined(OPENSSL_STATIC_ARMCAP)
|
||||
|
||||
#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_NO_ASM)
|
||||
!defined(OPENSSL_STATIC_ARMCAP)
|
||||
|
||||
#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_NO_ASM)
|
||||
!defined(OPENSSL_STATIC_ARMCAP)
|
||||
|
||||
#include <machine/armreg.h>
|
||||
#include <machine/cpu.h>
|
||||
#include <sys/sysctl.h>
|
||||
#include <machine/cpu.h>
|
||||
#include <machine/armreg.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,8 +18,7 @@
|
||||
// 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(OPENSSL_NO_ASM)
|
||||
(defined(ANDROID_BAREMETAL) || defined(OPENSSL_FREEBSD))
|
||||
|
||||
#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_NO_ASM)
|
||||
!defined(OPENSSL_STATIC_ARMCAP)
|
||||
|
||||
#include <windows.h>
|
||||
|
||||
|
||||
@@ -0,0 +1,36 @@
|
||||
/* Copyright (c) 2014, Google Inc.
|
||||
*
|
||||
* Permission to use, copy, modify, and/or distribute this software for any
|
||||
* purpose with or without fee is hereby granted, provided that the above
|
||||
* copyright notice and this permission notice appear in all copies.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
|
||||
* WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
|
||||
* MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
|
||||
* SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
|
||||
* WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION
|
||||
* OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
|
||||
* CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. */
|
||||
|
||||
#include "internal.h"
|
||||
|
||||
#if (defined(OPENSSL_ARM) || defined(OPENSSL_AARCH64)) && \
|
||||
!defined(OPENSSL_STATIC_ARMCAP)
|
||||
|
||||
#include <CCryptoBoringSSL_arm_arch.h>
|
||||
|
||||
|
||||
int CRYPTO_is_NEON_capable_at_runtime(void) {
|
||||
return (OPENSSL_armcap_P & ARMV7_NEON) != 0;
|
||||
}
|
||||
|
||||
int CRYPTO_is_ARMv8_AES_capable_at_runtime(void) {
|
||||
return (OPENSSL_armcap_P & ARMV8_AES) != 0;
|
||||
}
|
||||
|
||||
int CRYPTO_is_ARMv8_PMULL_capable_at_runtime(void) {
|
||||
return (OPENSSL_armcap_P & ARMV8_PMULL) != 0;
|
||||
}
|
||||
|
||||
#endif /* (defined(OPENSSL_ARM) || defined(OPENSSL_AARCH64)) &&
|
||||
!defined(OPENSSL_STATIC_ARMCAP) */
|
||||
@@ -143,9 +143,6 @@ void OPENSSL_cpuid_setup(void) {
|
||||
|
||||
int CRYPTO_has_broken_NEON(void) { return 0; }
|
||||
|
||||
int CRYPTO_needs_hwcap2_workaround(void) {
|
||||
OPENSSL_init_cpuid();
|
||||
return g_needs_hwcap2_workaround;
|
||||
}
|
||||
int CRYPTO_needs_hwcap2_workaround(void) { return g_needs_hwcap2_workaround; }
|
||||
|
||||
#endif // OPENSSL_ARM && OPENSSL_LINUX && !OPENSSL_STATIC_ARMCAP
|
||||
@@ -173,21 +173,20 @@ 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.
|
||||
@@ -209,6 +208,14 @@ 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.
|
||||
if ((eax & 0x0fff0ff0) == 0x00050670 /* Knights Landing */ ||
|
||||
(eax & 0x0fff0ff0) == 0x00080650 /* Knights Mill (per SDE) */) {
|
||||
ecx &= ~(1u << 26);
|
||||
}
|
||||
} else {
|
||||
edx &= ~(1u << 30);
|
||||
}
|
||||
@@ -228,67 +235,24 @@ void OPENSSL_cpuid_setup(void) {
|
||||
ecx &= ~(1u << 28); // AVX
|
||||
ecx &= ~(1u << 12); // FMA
|
||||
ecx &= ~(1u << 11); // AMD XOP
|
||||
extended_features[0] &= ~(1u << 5); // AVX2
|
||||
extended_features[1] &= ~(1u << 9); // VAES
|
||||
extended_features[1] &= ~(1u << 10); // VPCLMULQDQ
|
||||
}
|
||||
// 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) {
|
||||
// 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.
|
||||
// Clear AVX2 and AVX512* bits.
|
||||
//
|
||||
// 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
|
||||
// TODO(davidben): Should bits 17 and 26-28 also be cleared? Upstream
|
||||
// doesn't clear those.
|
||||
extended_features[0] &=
|
||||
~((1u << 5) | (1u << 16) | (1u << 21) | (1u << 30) | (1u << 31));
|
||||
}
|
||||
// See Intel manual, volume 1, section 15.2.
|
||||
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);
|
||||
}
|
||||
|
||||
// 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);
|
||||
// Disable ADX instructions on Knights Landing. See OpenSSL commit
|
||||
// 64d92d74985ebb3d0be58a9718f9e080a14a8e7f.
|
||||
if ((ecx & (1u << 26)) == 0) {
|
||||
extended_features[0] &= ~(1u << 19);
|
||||
}
|
||||
|
||||
OPENSSL_ia32cap_P[0] = edx;
|
||||
|
||||
@@ -15,16 +15,32 @@
|
||||
#include <CCryptoBoringSSL_crypto.h>
|
||||
|
||||
#include <assert.h>
|
||||
#include <stdio.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
|
||||
@@ -62,11 +78,6 @@ HIDDEN uint8_t BORINGSSL_function_hit[7] = {0};
|
||||
// This value must be explicitly initialized to zero. See similar comment above.
|
||||
HIDDEN uint32_t OPENSSL_ia32cap_P[4] = {0};
|
||||
|
||||
uint32_t OPENSSL_get_ia32cap(int idx) {
|
||||
OPENSSL_init_cpuid();
|
||||
return OPENSSL_ia32cap_P[idx];
|
||||
}
|
||||
|
||||
#elif defined(OPENSSL_ARM) || defined(OPENSSL_AARCH64)
|
||||
|
||||
#include <CCryptoBoringSSL_arm_arch.h>
|
||||
@@ -105,24 +116,54 @@ HIDDEN uint32_t OPENSSL_armcap_P =
|
||||
HIDDEN uint32_t OPENSSL_armcap_P = 0;
|
||||
|
||||
uint32_t *OPENSSL_get_armcap_pointer_for_test(void) {
|
||||
OPENSSL_init_cpuid();
|
||||
return &OPENSSL_armcap_P;
|
||||
}
|
||||
#endif
|
||||
|
||||
uint32_t OPENSSL_get_armcap(void) {
|
||||
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();
|
||||
#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
|
||||
|
||||
#if defined(NEED_CPUID)
|
||||
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) {}
|
||||
}
|
||||
|
||||
int CRYPTO_is_confidential_build(void) {
|
||||
#if defined(BORINGSSL_CONFIDENTIAL)
|
||||
@@ -142,7 +183,7 @@ int CRYPTO_has_asm(void) {
|
||||
|
||||
void CRYPTO_pre_sandbox_init(void) {
|
||||
// Read from /proc/cpuinfo if needed.
|
||||
OPENSSL_init_cpuid();
|
||||
CRYPTO_library_init();
|
||||
// Open /dev/urandom if needed.
|
||||
CRYPTO_init_sysrand();
|
||||
// Set up MADV_WIPEONFORK state if needed.
|
||||
@@ -183,9 +224,8 @@ 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;
|
||||
}
|
||||
|
||||
void OPENSSL_cleanup(void) {}
|
||||
|
||||
FILE *CRYPTO_get_stderr(void) { return stderr; }
|
||||
@@ -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++) { \
|
||||
declassify_assert(f[_assert_fe_i] <= UINT64_C(0x8cccccccccccc)); \
|
||||
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++) { \
|
||||
declassify_assert(f[_assert_fe_i] <= UINT64_C(0x1a666666666664)); \
|
||||
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++) { \
|
||||
declassify_assert(f[_assert_fe_i] <= \
|
||||
((_assert_fe_i & 1) ? 0x2333333u : 0x4666666u)); \
|
||||
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++) { \
|
||||
declassify_assert(f[_assert_fe_i] <= \
|
||||
((_assert_fe_i & 1) ? 0x6999999u : 0xd333332u)); \
|
||||
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.
|
||||
declassify_assert((s[31] & 0x80) == 0);
|
||||
assert((s[31] & 0x80) == 0);
|
||||
fiat_25519_from_bytes(h->v, s);
|
||||
assert_fe(h->v);
|
||||
}
|
||||
@@ -1906,8 +1906,6 @@ int ED25519_sign(uint8_t out_sig[64], const uint8_t *message,
|
||||
x25519_sc_reduce(hram);
|
||||
sc_muladd(out_sig + 32, hram, az, nonce);
|
||||
|
||||
// The signature is computed from the private key, but is public.
|
||||
CONSTTIME_DECLASSIFY(out_sig, 64);
|
||||
return 1;
|
||||
}
|
||||
|
||||
@@ -1985,8 +1983,6 @@ void ED25519_keypair_from_seed(uint8_t out_public_key[32],
|
||||
ge_p3 A;
|
||||
x25519_ge_scalarmult_base(&A, az);
|
||||
ge_p3_tobytes(out_public_key, &A);
|
||||
// The public key is derived from the private key, but it is public.
|
||||
CONSTTIME_DECLASSIFY(out_public_key, 32);
|
||||
|
||||
OPENSSL_memcpy(out_private_key, seed, 32);
|
||||
OPENSSL_memcpy(out_private_key + 32, out_public_key, 32);
|
||||
|
||||
@@ -32,7 +32,7 @@ void x25519_NEON(uint8_t out[32], const uint8_t scalar[32],
|
||||
#endif
|
||||
|
||||
#if !defined(OPENSSL_NO_ASM) && !defined(OPENSSL_SMALL) && \
|
||||
defined(__GNUC__) && defined(__x86_64__) && !defined(OPENSSL_WINDOWS)
|
||||
defined(__GNUC__) && defined(__x86_64__)
|
||||
#define BORINGSSL_FE25519_ADX
|
||||
|
||||
// fiat_curve25519_adx_mul is defined in
|
||||
|
||||
@@ -272,11 +272,12 @@ static const uint8_t kSpakeMSmallPrecomp[15 * 2 * 32] = {
|
||||
SPAKE2_CTX *SPAKE2_CTX_new(enum spake2_role_t my_role,
|
||||
const uint8_t *my_name, size_t my_name_len,
|
||||
const uint8_t *their_name, size_t their_name_len) {
|
||||
SPAKE2_CTX *ctx = OPENSSL_zalloc(sizeof(SPAKE2_CTX));
|
||||
SPAKE2_CTX *ctx = OPENSSL_malloc(sizeof(SPAKE2_CTX));
|
||||
if (ctx == NULL) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
OPENSSL_memset(ctx, 0, sizeof(SPAKE2_CTX));
|
||||
ctx->my_role = my_role;
|
||||
|
||||
CBS my_name_cbs, their_name_cbs;
|
||||
|
||||
@@ -61,91 +61,6 @@
|
||||
#include "internal.h"
|
||||
|
||||
|
||||
/* IP and FP
|
||||
* The problem is more of a geometric problem that random bit fiddling.
|
||||
0 1 2 3 4 5 6 7 62 54 46 38 30 22 14 6
|
||||
8 9 10 11 12 13 14 15 60 52 44 36 28 20 12 4
|
||||
16 17 18 19 20 21 22 23 58 50 42 34 26 18 10 2
|
||||
24 25 26 27 28 29 30 31 to 56 48 40 32 24 16 8 0
|
||||
|
||||
32 33 34 35 36 37 38 39 63 55 47 39 31 23 15 7
|
||||
40 41 42 43 44 45 46 47 61 53 45 37 29 21 13 5
|
||||
48 49 50 51 52 53 54 55 59 51 43 35 27 19 11 3
|
||||
56 57 58 59 60 61 62 63 57 49 41 33 25 17 9 1
|
||||
|
||||
The output has been subject to swaps of the form
|
||||
0 1 -> 3 1 but the odd and even bits have been put into
|
||||
2 3 2 0
|
||||
different words. The main trick is to remember that
|
||||
t=((l>>size)^r)&(mask);
|
||||
r^=t;
|
||||
l^=(t<<size);
|
||||
can be used to swap and move bits between words.
|
||||
|
||||
So l = 0 1 2 3 r = 16 17 18 19
|
||||
4 5 6 7 20 21 22 23
|
||||
8 9 10 11 24 25 26 27
|
||||
12 13 14 15 28 29 30 31
|
||||
becomes (for size == 2 and mask == 0x3333)
|
||||
t = 2^16 3^17 -- -- l = 0 1 16 17 r = 2 3 18 19
|
||||
6^20 7^21 -- -- 4 5 20 21 6 7 22 23
|
||||
10^24 11^25 -- -- 8 9 24 25 10 11 24 25
|
||||
14^28 15^29 -- -- 12 13 28 29 14 15 28 29
|
||||
|
||||
Thanks for hints from Richard Outerbridge - he told me IP&FP
|
||||
could be done in 15 xor, 10 shifts and 5 ands.
|
||||
When I finally started to think of the problem in 2D
|
||||
I first got ~42 operations without xors. When I remembered
|
||||
how to use xors :-) I got it to its final state.
|
||||
*/
|
||||
#define PERM_OP(a, b, t, n, m) \
|
||||
do { \
|
||||
(t) = ((((a) >> (n)) ^ (b)) & (m)); \
|
||||
(b) ^= (t); \
|
||||
(a) ^= ((t) << (n)); \
|
||||
} while (0)
|
||||
|
||||
#define IP(l, r) \
|
||||
do { \
|
||||
uint32_t tt; \
|
||||
PERM_OP(r, l, tt, 4, 0x0f0f0f0fL); \
|
||||
PERM_OP(l, r, tt, 16, 0x0000ffffL); \
|
||||
PERM_OP(r, l, tt, 2, 0x33333333L); \
|
||||
PERM_OP(l, r, tt, 8, 0x00ff00ffL); \
|
||||
PERM_OP(r, l, tt, 1, 0x55555555L); \
|
||||
} while (0)
|
||||
|
||||
#define FP(l, r) \
|
||||
do { \
|
||||
uint32_t tt; \
|
||||
PERM_OP(l, r, tt, 1, 0x55555555L); \
|
||||
PERM_OP(r, l, tt, 8, 0x00ff00ffL); \
|
||||
PERM_OP(l, r, tt, 2, 0x33333333L); \
|
||||
PERM_OP(r, l, tt, 16, 0x0000ffffL); \
|
||||
PERM_OP(l, r, tt, 4, 0x0f0f0f0fL); \
|
||||
} while (0)
|
||||
|
||||
#define LOAD_DATA(ks, R, S, u, t, E0, E1) \
|
||||
do { \
|
||||
(u) = (R) ^ (ks)->subkeys[S][0]; \
|
||||
(t) = (R) ^ (ks)->subkeys[S][1]; \
|
||||
} while (0)
|
||||
|
||||
#define D_ENCRYPT(ks, LL, R, S) \
|
||||
do { \
|
||||
LOAD_DATA(ks, R, S, u, t, E0, E1); \
|
||||
t = CRYPTO_rotr_u32(t, 4); \
|
||||
(LL) ^= \
|
||||
DES_SPtrans[0][(u >> 2L) & 0x3f] ^ DES_SPtrans[2][(u >> 10L) & 0x3f] ^ \
|
||||
DES_SPtrans[4][(u >> 18L) & 0x3f] ^ \
|
||||
DES_SPtrans[6][(u >> 26L) & 0x3f] ^ DES_SPtrans[1][(t >> 2L) & 0x3f] ^ \
|
||||
DES_SPtrans[3][(t >> 10L) & 0x3f] ^ \
|
||||
DES_SPtrans[5][(t >> 18L) & 0x3f] ^ DES_SPtrans[7][(t >> 26L) & 0x3f]; \
|
||||
} while (0)
|
||||
|
||||
#define ITERATIONS 16
|
||||
#define HALF_ITERATIONS 8
|
||||
|
||||
static const uint32_t des_skb[8][64] = {
|
||||
{ // for C bits (numbered as per FIPS 46) 1 2 3 4 5 6
|
||||
0x00000000, 0x00000010, 0x20000000, 0x20000010, 0x00010000,
|
||||
@@ -379,17 +294,13 @@ static const uint32_t DES_SPtrans[8][64] = {
|
||||
(a) = (a) ^ (t) ^ ((t) >> (16 - (n))))
|
||||
|
||||
void DES_set_key(const DES_cblock *key, DES_key_schedule *schedule) {
|
||||
DES_set_key_ex(key->bytes, schedule);
|
||||
}
|
||||
|
||||
void DES_set_key_ex(const uint8_t key[8], DES_key_schedule *schedule) {
|
||||
static const int shifts2[16] = {0, 0, 1, 1, 1, 1, 1, 1,
|
||||
0, 1, 1, 1, 1, 1, 1, 0};
|
||||
uint32_t c, d, t, s, t2;
|
||||
const uint8_t *in;
|
||||
int i;
|
||||
|
||||
in = key;
|
||||
in = key->bytes;
|
||||
|
||||
c2l(in, c);
|
||||
c2l(in, d);
|
||||
@@ -467,8 +378,7 @@ void DES_set_odd_parity(DES_cblock *key) {
|
||||
}
|
||||
}
|
||||
|
||||
static void DES_encrypt1(uint32_t data[2], const DES_key_schedule *ks,
|
||||
int enc) {
|
||||
static void DES_encrypt1(uint32_t *data, const DES_key_schedule *ks, int enc) {
|
||||
uint32_t l, r, t, u;
|
||||
|
||||
r = data[0];
|
||||
@@ -532,8 +442,7 @@ static void DES_encrypt1(uint32_t data[2], const DES_key_schedule *ks,
|
||||
data[1] = r;
|
||||
}
|
||||
|
||||
static void DES_encrypt2(uint32_t data[2], const DES_key_schedule *ks,
|
||||
int enc) {
|
||||
static void DES_encrypt2(uint32_t *data, const DES_key_schedule *ks, int enc) {
|
||||
uint32_t l, r, t, u;
|
||||
|
||||
r = data[0];
|
||||
@@ -590,7 +499,7 @@ static void DES_encrypt2(uint32_t data[2], const DES_key_schedule *ks,
|
||||
data[1] = CRYPTO_rotr_u32(r, 3);
|
||||
}
|
||||
|
||||
void DES_encrypt3(uint32_t data[2], const DES_key_schedule *ks1,
|
||||
void DES_encrypt3(uint32_t *data, const DES_key_schedule *ks1,
|
||||
const DES_key_schedule *ks2, const DES_key_schedule *ks3) {
|
||||
uint32_t l, r;
|
||||
|
||||
@@ -599,9 +508,9 @@ void DES_encrypt3(uint32_t data[2], const DES_key_schedule *ks1,
|
||||
IP(l, r);
|
||||
data[0] = l;
|
||||
data[1] = r;
|
||||
DES_encrypt2(data, ks1, DES_ENCRYPT);
|
||||
DES_encrypt2(data, ks2, DES_DECRYPT);
|
||||
DES_encrypt2(data, ks3, DES_ENCRYPT);
|
||||
DES_encrypt2((uint32_t *)data, ks1, DES_ENCRYPT);
|
||||
DES_encrypt2((uint32_t *)data, ks2, DES_DECRYPT);
|
||||
DES_encrypt2((uint32_t *)data, ks3, DES_ENCRYPT);
|
||||
l = data[0];
|
||||
r = data[1];
|
||||
FP(r, l);
|
||||
@@ -609,7 +518,7 @@ void DES_encrypt3(uint32_t data[2], const DES_key_schedule *ks1,
|
||||
data[1] = r;
|
||||
}
|
||||
|
||||
void DES_decrypt3(uint32_t data[2], const DES_key_schedule *ks1,
|
||||
void DES_decrypt3(uint32_t *data, const DES_key_schedule *ks1,
|
||||
const DES_key_schedule *ks2, const DES_key_schedule *ks3) {
|
||||
uint32_t l, r;
|
||||
|
||||
@@ -618,9 +527,9 @@ void DES_decrypt3(uint32_t data[2], const DES_key_schedule *ks1,
|
||||
IP(l, r);
|
||||
data[0] = l;
|
||||
data[1] = r;
|
||||
DES_encrypt2(data, ks3, DES_DECRYPT);
|
||||
DES_encrypt2(data, ks2, DES_ENCRYPT);
|
||||
DES_encrypt2(data, ks1, DES_DECRYPT);
|
||||
DES_encrypt2((uint32_t *)data, ks3, DES_DECRYPT);
|
||||
DES_encrypt2((uint32_t *)data, ks2, DES_ENCRYPT);
|
||||
DES_encrypt2((uint32_t *)data, ks1, DES_DECRYPT);
|
||||
l = data[0];
|
||||
r = data[1];
|
||||
FP(r, l);
|
||||
@@ -630,34 +539,32 @@ void DES_decrypt3(uint32_t data[2], const DES_key_schedule *ks1,
|
||||
|
||||
void DES_ecb_encrypt(const DES_cblock *in_block, DES_cblock *out_block,
|
||||
const DES_key_schedule *schedule, int is_encrypt) {
|
||||
DES_ecb_encrypt_ex(in_block->bytes, out_block->bytes, schedule, is_encrypt);
|
||||
}
|
||||
|
||||
void DES_ecb_encrypt_ex(const uint8_t in[8], uint8_t out[8],
|
||||
const DES_key_schedule *schedule, int is_encrypt) {
|
||||
uint32_t l;
|
||||
uint32_t ll[2];
|
||||
ll[0] = CRYPTO_load_u32_le(in);
|
||||
ll[1] = CRYPTO_load_u32_le(in + 4);
|
||||
const uint8_t *in = in_block->bytes;
|
||||
uint8_t *out = out_block->bytes;
|
||||
|
||||
c2l(in, l);
|
||||
ll[0] = l;
|
||||
c2l(in, l);
|
||||
ll[1] = l;
|
||||
DES_encrypt1(ll, schedule, is_encrypt);
|
||||
CRYPTO_store_u32_le(out, ll[0]);
|
||||
CRYPTO_store_u32_le(out + 4, ll[1]);
|
||||
l = ll[0];
|
||||
l2c(l, out);
|
||||
l = ll[1];
|
||||
l2c(l, out);
|
||||
ll[0] = ll[1] = 0;
|
||||
}
|
||||
|
||||
void DES_ncbc_encrypt(const uint8_t *in, uint8_t *out, size_t len,
|
||||
const DES_key_schedule *schedule, DES_cblock *ivec,
|
||||
int enc) {
|
||||
DES_ncbc_encrypt_ex(in, out, len, schedule, ivec->bytes, enc);
|
||||
}
|
||||
|
||||
void DES_ncbc_encrypt_ex(const uint8_t *in, uint8_t *out, size_t len,
|
||||
const DES_key_schedule *schedule, uint8_t ivec[8],
|
||||
int enc) {
|
||||
uint32_t tin0, tin1;
|
||||
uint32_t tout0, tout1, xor0, xor1;
|
||||
uint32_t tin[2];
|
||||
unsigned char *iv;
|
||||
|
||||
iv = ivec;
|
||||
iv = ivec->bytes;
|
||||
|
||||
if (enc) {
|
||||
c2l(iv, tout0);
|
||||
@@ -669,7 +576,7 @@ void DES_ncbc_encrypt_ex(const uint8_t *in, uint8_t *out, size_t len,
|
||||
tin[0] = tin0;
|
||||
tin1 ^= tout1;
|
||||
tin[1] = tin1;
|
||||
DES_encrypt1(tin, schedule, DES_ENCRYPT);
|
||||
DES_encrypt1((uint32_t *)tin, schedule, DES_ENCRYPT);
|
||||
tout0 = tin[0];
|
||||
l2c(tout0, out);
|
||||
tout1 = tin[1];
|
||||
@@ -681,13 +588,13 @@ void DES_ncbc_encrypt_ex(const uint8_t *in, uint8_t *out, size_t len,
|
||||
tin[0] = tin0;
|
||||
tin1 ^= tout1;
|
||||
tin[1] = tin1;
|
||||
DES_encrypt1(tin, schedule, DES_ENCRYPT);
|
||||
DES_encrypt1((uint32_t *)tin, schedule, DES_ENCRYPT);
|
||||
tout0 = tin[0];
|
||||
l2c(tout0, out);
|
||||
tout1 = tin[1];
|
||||
l2c(tout1, out);
|
||||
}
|
||||
iv = ivec;
|
||||
iv = ivec->bytes;
|
||||
l2c(tout0, iv);
|
||||
l2c(tout1, iv);
|
||||
} else {
|
||||
@@ -698,7 +605,7 @@ void DES_ncbc_encrypt_ex(const uint8_t *in, uint8_t *out, size_t len,
|
||||
tin[0] = tin0;
|
||||
c2l(in, tin1);
|
||||
tin[1] = tin1;
|
||||
DES_encrypt1(tin, schedule, DES_DECRYPT);
|
||||
DES_encrypt1((uint32_t *)tin, schedule, DES_DECRYPT);
|
||||
tout0 = tin[0] ^ xor0;
|
||||
tout1 = tin[1] ^ xor1;
|
||||
l2c(tout0, out);
|
||||
@@ -711,14 +618,14 @@ void DES_ncbc_encrypt_ex(const uint8_t *in, uint8_t *out, size_t len,
|
||||
tin[0] = tin0;
|
||||
c2l(in, tin1);
|
||||
tin[1] = tin1;
|
||||
DES_encrypt1(tin, schedule, DES_DECRYPT);
|
||||
DES_encrypt1((uint32_t *)tin, schedule, DES_DECRYPT);
|
||||
tout0 = tin[0] ^ xor0;
|
||||
tout1 = tin[1] ^ xor1;
|
||||
l2cn(tout0, tout1, out, len);
|
||||
xor0 = tin0;
|
||||
xor1 = tin1;
|
||||
}
|
||||
iv = ivec;
|
||||
iv = ivec->bytes;
|
||||
l2c(xor0, iv);
|
||||
l2c(xor1, iv);
|
||||
}
|
||||
@@ -728,23 +635,24 @@ void DES_ncbc_encrypt_ex(const uint8_t *in, uint8_t *out, size_t len,
|
||||
void DES_ecb3_encrypt(const DES_cblock *input, DES_cblock *output,
|
||||
const DES_key_schedule *ks1, const DES_key_schedule *ks2,
|
||||
const DES_key_schedule *ks3, int enc) {
|
||||
DES_ecb3_encrypt_ex(input->bytes, output->bytes, ks1, ks2, ks3, enc);
|
||||
}
|
||||
|
||||
void DES_ecb3_encrypt_ex(const uint8_t in[8], uint8_t out[8],
|
||||
const DES_key_schedule *ks1,
|
||||
const DES_key_schedule *ks2,
|
||||
const DES_key_schedule *ks3, int enc) {
|
||||
uint32_t l0, l1;
|
||||
uint32_t ll[2];
|
||||
ll[0] = CRYPTO_load_u32_le(in);
|
||||
ll[1] = CRYPTO_load_u32_le(in + 4);
|
||||
const uint8_t *in = input->bytes;
|
||||
uint8_t *out = output->bytes;
|
||||
|
||||
c2l(in, l0);
|
||||
c2l(in, l1);
|
||||
ll[0] = l0;
|
||||
ll[1] = l1;
|
||||
if (enc) {
|
||||
DES_encrypt3(ll, ks1, ks2, ks3);
|
||||
} else {
|
||||
DES_decrypt3(ll, ks1, ks2, ks3);
|
||||
}
|
||||
CRYPTO_store_u32_le(out, ll[0]);
|
||||
CRYPTO_store_u32_le(out + 4, ll[1]);
|
||||
l0 = ll[0];
|
||||
l1 = ll[1];
|
||||
l2c(l0, out);
|
||||
l2c(l1, out);
|
||||
}
|
||||
|
||||
void DES_ede3_cbc_encrypt(const uint8_t *in, uint8_t *out, size_t len,
|
||||
@@ -752,20 +660,12 @@ void DES_ede3_cbc_encrypt(const uint8_t *in, uint8_t *out, size_t len,
|
||||
const DES_key_schedule *ks2,
|
||||
const DES_key_schedule *ks3, DES_cblock *ivec,
|
||||
int enc) {
|
||||
DES_ede3_cbc_encrypt_ex(in, out, len, ks1, ks2, ks3, ivec->bytes, enc);
|
||||
}
|
||||
|
||||
void DES_ede3_cbc_encrypt_ex(const uint8_t *in, uint8_t *out, size_t len,
|
||||
const DES_key_schedule *ks1,
|
||||
const DES_key_schedule *ks2,
|
||||
const DES_key_schedule *ks3, uint8_t ivec[8],
|
||||
int enc) {
|
||||
uint32_t tin0, tin1;
|
||||
uint32_t tout0, tout1, xor0, xor1;
|
||||
uint32_t tin[2];
|
||||
uint8_t *iv;
|
||||
|
||||
iv = ivec;
|
||||
iv = ivec->bytes;
|
||||
|
||||
if (enc) {
|
||||
c2l(iv, tout0);
|
||||
@@ -778,7 +678,7 @@ void DES_ede3_cbc_encrypt_ex(const uint8_t *in, uint8_t *out, size_t len,
|
||||
|
||||
tin[0] = tin0;
|
||||
tin[1] = tin1;
|
||||
DES_encrypt3(tin, ks1, ks2, ks3);
|
||||
DES_encrypt3((uint32_t *)tin, ks1, ks2, ks3);
|
||||
tout0 = tin[0];
|
||||
tout1 = tin[1];
|
||||
|
||||
@@ -792,14 +692,14 @@ void DES_ede3_cbc_encrypt_ex(const uint8_t *in, uint8_t *out, size_t len,
|
||||
|
||||
tin[0] = tin0;
|
||||
tin[1] = tin1;
|
||||
DES_encrypt3(tin, ks1, ks2, ks3);
|
||||
DES_encrypt3((uint32_t *)tin, ks1, ks2, ks3);
|
||||
tout0 = tin[0];
|
||||
tout1 = tin[1];
|
||||
|
||||
l2c(tout0, out);
|
||||
l2c(tout1, out);
|
||||
}
|
||||
iv = ivec;
|
||||
iv = ivec->bytes;
|
||||
l2c(tout0, iv);
|
||||
l2c(tout1, iv);
|
||||
} else {
|
||||
@@ -816,7 +716,7 @@ void DES_ede3_cbc_encrypt_ex(const uint8_t *in, uint8_t *out, size_t len,
|
||||
|
||||
tin[0] = tin0;
|
||||
tin[1] = tin1;
|
||||
DES_decrypt3(tin, ks1, ks2, ks3);
|
||||
DES_decrypt3((uint32_t *)tin, ks1, ks2, ks3);
|
||||
tout0 = tin[0];
|
||||
tout1 = tin[1];
|
||||
|
||||
@@ -836,7 +736,7 @@ void DES_ede3_cbc_encrypt_ex(const uint8_t *in, uint8_t *out, size_t len,
|
||||
|
||||
tin[0] = tin0;
|
||||
tin[1] = tin1;
|
||||
DES_decrypt3(tin, ks1, ks2, ks3);
|
||||
DES_decrypt3((uint32_t *)tin, ks1, ks2, ks3);
|
||||
tout0 = tin[0];
|
||||
tout1 = tin[1];
|
||||
|
||||
@@ -847,7 +747,7 @@ void DES_ede3_cbc_encrypt_ex(const uint8_t *in, uint8_t *out, size_t len,
|
||||
xor1 = t1;
|
||||
}
|
||||
|
||||
iv = ivec;
|
||||
iv = ivec->bytes;
|
||||
l2c(xor0, iv);
|
||||
l2c(xor1, iv);
|
||||
}
|
||||
@@ -869,3 +769,16 @@ void DES_ede2_cbc_encrypt(const uint8_t *in, uint8_t *out, size_t len,
|
||||
void DES_set_key_unchecked(const DES_cblock *key, DES_key_schedule *schedule) {
|
||||
DES_set_key(key, schedule);
|
||||
}
|
||||
|
||||
#undef HPERM_OP
|
||||
#undef c2l
|
||||
#undef l2c
|
||||
#undef c2ln
|
||||
#undef l2cn
|
||||
#undef PERM_OP
|
||||
#undef IP
|
||||
#undef FP
|
||||
#undef LOAD_DATA
|
||||
#undef D_ENCRYPT
|
||||
#undef ITERATIONS
|
||||
#undef HALF_ITERATIONS
|
||||
@@ -58,7 +58,6 @@
|
||||
#define OPENSSL_HEADER_DES_INTERNAL_H
|
||||
|
||||
#include <CCryptoBoringSSL_base.h>
|
||||
#include <CCryptoBoringSSL_des.h>
|
||||
|
||||
#include "../internal.h"
|
||||
|
||||
@@ -67,9 +66,6 @@ extern "C" {
|
||||
#endif
|
||||
|
||||
|
||||
// TODO(davidben): Ideally these macros would be replaced with
|
||||
// |CRYPTO_load_u32_le| and |CRYPTO_store_u32_le|.
|
||||
|
||||
#define c2l(c, l) \
|
||||
do { \
|
||||
(l) = ((uint32_t)(*((c)++))); \
|
||||
@@ -149,39 +145,90 @@ extern "C" {
|
||||
} \
|
||||
} while (0)
|
||||
|
||||
/* IP and FP
|
||||
* The problem is more of a geometric problem that random bit fiddling.
|
||||
0 1 2 3 4 5 6 7 62 54 46 38 30 22 14 6
|
||||
8 9 10 11 12 13 14 15 60 52 44 36 28 20 12 4
|
||||
16 17 18 19 20 21 22 23 58 50 42 34 26 18 10 2
|
||||
24 25 26 27 28 29 30 31 to 56 48 40 32 24 16 8 0
|
||||
|
||||
// Correctly-typed versions of DES functions.
|
||||
//
|
||||
// See https://crbug.com/boringssl/683.
|
||||
32 33 34 35 36 37 38 39 63 55 47 39 31 23 15 7
|
||||
40 41 42 43 44 45 46 47 61 53 45 37 29 21 13 5
|
||||
48 49 50 51 52 53 54 55 59 51 43 35 27 19 11 3
|
||||
56 57 58 59 60 61 62 63 57 49 41 33 25 17 9 1
|
||||
|
||||
void DES_set_key_ex(const uint8_t key[8], DES_key_schedule *schedule);
|
||||
void DES_ecb_encrypt_ex(const uint8_t in[8], uint8_t out[8],
|
||||
const DES_key_schedule *schedule, int is_encrypt);
|
||||
void DES_ncbc_encrypt_ex(const uint8_t *in, uint8_t *out, size_t len,
|
||||
const DES_key_schedule *schedule, uint8_t ivec[8],
|
||||
int enc);
|
||||
void DES_ecb3_encrypt_ex(const uint8_t input[8], uint8_t output[8],
|
||||
const DES_key_schedule *ks1,
|
||||
const DES_key_schedule *ks2,
|
||||
const DES_key_schedule *ks3, int enc);
|
||||
void DES_ede3_cbc_encrypt_ex(const uint8_t *in, uint8_t *out, size_t len,
|
||||
const DES_key_schedule *ks1,
|
||||
const DES_key_schedule *ks2,
|
||||
const DES_key_schedule *ks3, uint8_t ivec[8],
|
||||
int enc);
|
||||
The output has been subject to swaps of the form
|
||||
0 1 -> 3 1 but the odd and even bits have been put into
|
||||
2 3 2 0
|
||||
different words. The main trick is to remember that
|
||||
t=((l>>size)^r)&(mask);
|
||||
r^=t;
|
||||
l^=(t<<size);
|
||||
can be used to swap and move bits between words.
|
||||
|
||||
So l = 0 1 2 3 r = 16 17 18 19
|
||||
4 5 6 7 20 21 22 23
|
||||
8 9 10 11 24 25 26 27
|
||||
12 13 14 15 28 29 30 31
|
||||
becomes (for size == 2 and mask == 0x3333)
|
||||
t = 2^16 3^17 -- -- l = 0 1 16 17 r = 2 3 18 19
|
||||
6^20 7^21 -- -- 4 5 20 21 6 7 22 23
|
||||
10^24 11^25 -- -- 8 9 24 25 10 11 24 25
|
||||
14^28 15^29 -- -- 12 13 28 29 14 15 28 29
|
||||
|
||||
// Private functions.
|
||||
//
|
||||
// These functions are only exported for use in |decrepit|.
|
||||
Thanks for hints from Richard Outerbridge - he told me IP&FP
|
||||
could be done in 15 xor, 10 shifts and 5 ands.
|
||||
When I finally started to think of the problem in 2D
|
||||
I first got ~42 operations without xors. When I remembered
|
||||
how to use xors :-) I got it to its final state.
|
||||
*/
|
||||
#define PERM_OP(a, b, t, n, m) \
|
||||
do { \
|
||||
(t) = ((((a) >> (n)) ^ (b)) & (m)); \
|
||||
(b) ^= (t); \
|
||||
(a) ^= ((t) << (n)); \
|
||||
} while (0)
|
||||
|
||||
OPENSSL_EXPORT void DES_decrypt3(uint32_t data[2], const DES_key_schedule *ks1,
|
||||
const DES_key_schedule *ks2,
|
||||
const DES_key_schedule *ks3);
|
||||
#define IP(l, r) \
|
||||
do { \
|
||||
uint32_t tt; \
|
||||
PERM_OP(r, l, tt, 4, 0x0f0f0f0fL); \
|
||||
PERM_OP(l, r, tt, 16, 0x0000ffffL); \
|
||||
PERM_OP(r, l, tt, 2, 0x33333333L); \
|
||||
PERM_OP(l, r, tt, 8, 0x00ff00ffL); \
|
||||
PERM_OP(r, l, tt, 1, 0x55555555L); \
|
||||
} while (0)
|
||||
|
||||
OPENSSL_EXPORT void DES_encrypt3(uint32_t data[2], const DES_key_schedule *ks1,
|
||||
const DES_key_schedule *ks2,
|
||||
const DES_key_schedule *ks3);
|
||||
#define FP(l, r) \
|
||||
do { \
|
||||
uint32_t tt; \
|
||||
PERM_OP(l, r, tt, 1, 0x55555555L); \
|
||||
PERM_OP(r, l, tt, 8, 0x00ff00ffL); \
|
||||
PERM_OP(l, r, tt, 2, 0x33333333L); \
|
||||
PERM_OP(r, l, tt, 16, 0x0000ffffL); \
|
||||
PERM_OP(l, r, tt, 4, 0x0f0f0f0fL); \
|
||||
} while (0)
|
||||
|
||||
#define LOAD_DATA(ks, R, S, u, t, E0, E1) \
|
||||
do { \
|
||||
(u) = (R) ^ (ks)->subkeys[S][0]; \
|
||||
(t) = (R) ^ (ks)->subkeys[S][1]; \
|
||||
} while (0)
|
||||
|
||||
#define D_ENCRYPT(ks, LL, R, S) \
|
||||
do { \
|
||||
LOAD_DATA(ks, R, S, u, t, E0, E1); \
|
||||
t = CRYPTO_rotr_u32(t, 4); \
|
||||
(LL) ^= \
|
||||
DES_SPtrans[0][(u >> 2L) & 0x3f] ^ DES_SPtrans[2][(u >> 10L) & 0x3f] ^ \
|
||||
DES_SPtrans[4][(u >> 18L) & 0x3f] ^ \
|
||||
DES_SPtrans[6][(u >> 26L) & 0x3f] ^ DES_SPtrans[1][(t >> 2L) & 0x3f] ^ \
|
||||
DES_SPtrans[3][(t >> 10L) & 0x3f] ^ \
|
||||
DES_SPtrans[5][(t >> 18L) & 0x3f] ^ DES_SPtrans[7][(t >> 26L) & 0x3f]; \
|
||||
} while (0)
|
||||
|
||||
#define ITERATIONS 16
|
||||
#define HALF_ITERATIONS 8
|
||||
|
||||
|
||||
#if defined(__cplusplus)
|
||||
|
||||
@@ -110,10 +110,6 @@ DH *DH_parse_parameters(CBS *cbs) {
|
||||
goto err;
|
||||
}
|
||||
|
||||
if (!dh_check_params_fast(ret)) {
|
||||
goto err;
|
||||
}
|
||||
|
||||
return ret;
|
||||
|
||||
err:
|
||||
|
||||
@@ -337,11 +337,6 @@ int DH_generate_parameters_ex(DH *dh, int prime_bits, int generator,
|
||||
// It's just as OK (and in some sense better) to use a generator of the
|
||||
// order-q subgroup.
|
||||
|
||||
if (prime_bits <= 0 || prime_bits > OPENSSL_DH_MAX_MODULUS_BITS) {
|
||||
OPENSSL_PUT_ERROR(DH, DH_R_MODULUS_TOO_LARGE);
|
||||
return 0;
|
||||
}
|
||||
|
||||
BIGNUM *t1, *t2;
|
||||
int g, ok = 0;
|
||||
BN_CTX *ctx = NULL;
|
||||
|
||||
@@ -61,8 +61,6 @@
|
||||
#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"
|
||||
@@ -222,7 +220,6 @@ 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;
|
||||
@@ -266,90 +263,3 @@ 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
@@ -1,58 +0,0 @@
|
||||
/* 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
|
||||
@@ -88,14 +88,18 @@ static int dsa_sign_setup(const DSA *dsa, BN_CTX *ctx_in, BIGNUM **out_kinv,
|
||||
static CRYPTO_EX_DATA_CLASS g_ex_data_class = CRYPTO_EX_DATA_CLASS_INIT;
|
||||
|
||||
DSA *DSA_new(void) {
|
||||
DSA *dsa = OPENSSL_zalloc(sizeof(DSA));
|
||||
DSA *dsa = OPENSSL_malloc(sizeof(DSA));
|
||||
if (dsa == NULL) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
OPENSSL_memset(dsa, 0, sizeof(DSA));
|
||||
|
||||
dsa->references = 1;
|
||||
|
||||
CRYPTO_MUTEX_init(&dsa->method_mont_lock);
|
||||
CRYPTO_new_ex_data(&dsa->ex_data);
|
||||
|
||||
return dsa;
|
||||
}
|
||||
|
||||
@@ -208,11 +212,6 @@ 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];
|
||||
@@ -279,8 +278,6 @@ 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;
|
||||
@@ -484,13 +481,11 @@ DSA *DSAparams_dup(const DSA *dsa) {
|
||||
}
|
||||
|
||||
int DSA_generate_key(DSA *dsa) {
|
||||
if (!dsa_check_key(dsa)) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
int ok = 0;
|
||||
BN_CTX *ctx = NULL;
|
||||
BIGNUM *pub_key = NULL, *priv_key = NULL;
|
||||
BN_CTX *ctx = BN_CTX_new();
|
||||
|
||||
ctx = BN_CTX_new();
|
||||
if (ctx == NULL) {
|
||||
goto err;
|
||||
}
|
||||
@@ -522,9 +517,6 @@ 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;
|
||||
@@ -541,7 +533,16 @@ err:
|
||||
return ok;
|
||||
}
|
||||
|
||||
DSA_SIG *DSA_SIG_new(void) { return OPENSSL_zalloc(sizeof(DSA_SIG)); }
|
||||
DSA_SIG *DSA_SIG_new(void) {
|
||||
DSA_SIG *sig;
|
||||
sig = OPENSSL_malloc(sizeof(DSA_SIG));
|
||||
if (!sig) {
|
||||
return NULL;
|
||||
}
|
||||
sig->r = NULL;
|
||||
sig->s = NULL;
|
||||
return sig;
|
||||
}
|
||||
|
||||
void DSA_SIG_free(DSA_SIG *sig) {
|
||||
if (!sig) {
|
||||
@@ -661,10 +662,6 @@ 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)) {
|
||||
@@ -697,7 +694,7 @@ err:
|
||||
return ret;
|
||||
}
|
||||
|
||||
int DSA_do_verify(const uint8_t *digest, size_t digest_len, const DSA_SIG *sig,
|
||||
int DSA_do_verify(const uint8_t *digest, size_t digest_len, DSA_SIG *sig,
|
||||
const DSA *dsa) {
|
||||
int valid;
|
||||
if (!DSA_do_check_signature(&valid, digest, digest_len, sig, dsa)) {
|
||||
@@ -707,8 +704,7 @@ int DSA_do_verify(const uint8_t *digest, size_t digest_len, const DSA_SIG *sig,
|
||||
}
|
||||
|
||||
int DSA_do_check_signature(int *out_valid, const uint8_t *digest,
|
||||
size_t digest_len, const DSA_SIG *sig,
|
||||
const DSA *dsa) {
|
||||
size_t digest_len, DSA_SIG *sig, const DSA *dsa) {
|
||||
*out_valid = 0;
|
||||
if (!dsa_check_key(dsa)) {
|
||||
return 0;
|
||||
@@ -916,19 +912,15 @@ 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)) {
|
||||
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) ||
|
||||
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) ||
|
||||
// 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)) {
|
||||
@@ -955,7 +947,12 @@ err:
|
||||
|
||||
int DSA_get_ex_new_index(long argl, void *argp, CRYPTO_EX_unused *unused,
|
||||
CRYPTO_EX_dup *dup_unused, CRYPTO_EX_free *free_func) {
|
||||
return CRYPTO_get_ex_new_index_ex(&g_ex_data_class, argl, argp, free_func);
|
||||
int index;
|
||||
if (!CRYPTO_get_ex_new_index(&g_ex_data_class, &index, argl, argp,
|
||||
free_func)) {
|
||||
return -1;
|
||||
}
|
||||
return index;
|
||||
}
|
||||
|
||||
int DSA_set_ex_data(DSA *dsa, int idx, void *arg) {
|
||||
|
||||
@@ -65,6 +65,8 @@
|
||||
#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.
|
||||
@@ -117,9 +119,8 @@ 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) ||
|
||||
constant_time_declassify_int(BN_is_zero(dsa->priv_key)) ||
|
||||
constant_time_declassify_int(BN_cmp(dsa->priv_key, dsa->q) >= 0)) {
|
||||
if (BN_is_negative(dsa->priv_key) || BN_is_zero(dsa->priv_key) ||
|
||||
BN_cmp(dsa->priv_key, dsa->q) >= 0) {
|
||||
OPENSSL_PUT_ERROR(DSA, DSA_R_INVALID_PARAMETERS);
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -478,41 +478,6 @@ int i2d_ECPrivateKey(const EC_KEY *key, uint8_t **outp) {
|
||||
return CBB_finish_i2d(&cbb, outp);
|
||||
}
|
||||
|
||||
EC_GROUP *d2i_ECPKParameters(EC_GROUP **out, const uint8_t **inp, long len) {
|
||||
if (len < 0) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
CBS cbs;
|
||||
CBS_init(&cbs, *inp, (size_t)len);
|
||||
EC_GROUP *ret = EC_KEY_parse_parameters(&cbs);
|
||||
if (ret == NULL) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
if (out != NULL) {
|
||||
EC_GROUP_free(*out);
|
||||
*out = ret;
|
||||
}
|
||||
*inp = CBS_data(&cbs);
|
||||
return ret;
|
||||
}
|
||||
|
||||
int i2d_ECPKParameters(const EC_GROUP *group, uint8_t **outp) {
|
||||
if (group == NULL) {
|
||||
OPENSSL_PUT_ERROR(EC, ERR_R_PASSED_NULL_PARAMETER);
|
||||
return -1;
|
||||
}
|
||||
|
||||
CBB cbb;
|
||||
if (!CBB_init(&cbb, 0) || //
|
||||
!EC_KEY_marshal_curve_name(&cbb, group)) {
|
||||
CBB_cleanup(&cbb);
|
||||
return -1;
|
||||
}
|
||||
return CBB_finish_i2d(&cbb, outp);
|
||||
}
|
||||
|
||||
EC_KEY *d2i_ECParameters(EC_KEY **out_key, const uint8_t **inp, long len) {
|
||||
if (len < 0) {
|
||||
return NULL;
|
||||
|
||||
@@ -26,7 +26,8 @@
|
||||
#include "../internal.h"
|
||||
|
||||
|
||||
// This file implements hash-to-curve, as described in RFC 9380.
|
||||
// This file implements hash-to-curve, as described in
|
||||
// draft-irtf-cfrg-hash-to-curve-16.
|
||||
//
|
||||
// This hash-to-curve implementation is written generically with the
|
||||
// expectation that we will eventually wish to support other curves. If it
|
||||
@@ -47,7 +48,8 @@
|
||||
// templates to make specializing more convenient.
|
||||
|
||||
// expand_message_xmd implements the operation described in section 5.3.1 of
|
||||
// RFC 9380. It returns one on success and zero on error.
|
||||
// draft-irtf-cfrg-hash-to-curve-16. It returns one on success and zero on
|
||||
// error.
|
||||
static int expand_message_xmd(const EVP_MD *md, uint8_t *out, size_t out_len,
|
||||
const uint8_t *msg, size_t msg_len,
|
||||
const uint8_t *dst, size_t dst_len) {
|
||||
@@ -136,7 +138,7 @@ err:
|
||||
|
||||
// num_bytes_to_derive determines the number of bytes to derive when hashing to
|
||||
// a number modulo |modulus|. See the hash_to_field operation defined in
|
||||
// section 5.2 of RFC 9380.
|
||||
// section 5.2 of draft-irtf-cfrg-hash-to-curve-16.
|
||||
static int num_bytes_to_derive(size_t *out, const BIGNUM *modulus, unsigned k) {
|
||||
size_t bits = BN_num_bits(modulus);
|
||||
size_t L = (bits + k + 7) / 8;
|
||||
@@ -169,7 +171,8 @@ static void big_endian_to_words(BN_ULONG *out, size_t num_words,
|
||||
}
|
||||
|
||||
// hash_to_field implements the operation described in section 5.2
|
||||
// of RFC 9380, with count = 2. |k| is the security factor.
|
||||
// of draft-irtf-cfrg-hash-to-curve-16, with count = 2. |k| is the security
|
||||
// factor.
|
||||
static int hash_to_field2(const EC_GROUP *group, const EVP_MD *md,
|
||||
EC_FELEM *out1, EC_FELEM *out2, const uint8_t *dst,
|
||||
size_t dst_len, unsigned k, const uint8_t *msg,
|
||||
@@ -218,7 +221,8 @@ static inline void mul_A(const EC_GROUP *group, EC_FELEM *out,
|
||||
ec_felem_sub(group, out, in, &tmp); // out = -3*in
|
||||
}
|
||||
|
||||
// sgn0 implements the operation described in section 4.1.2 of RFC 9380.
|
||||
// sgn0 implements the operation described in section 4.1.2 of
|
||||
// draft-irtf-cfrg-hash-to-curve-16.
|
||||
static BN_ULONG sgn0(const EC_GROUP *group, const EC_FELEM *a) {
|
||||
uint8_t buf[EC_MAX_BYTES];
|
||||
size_t len;
|
||||
@@ -231,7 +235,7 @@ OPENSSL_UNUSED static int is_3mod4(const EC_GROUP *group) {
|
||||
}
|
||||
|
||||
// sqrt_ratio_3mod4 implements the operation described in appendix F.2.1.2
|
||||
// of RFC 9380.
|
||||
// of draft-irtf-cfrg-hash-to-curve-16.
|
||||
static BN_ULONG sqrt_ratio_3mod4(const EC_GROUP *group, const EC_FELEM *Z,
|
||||
const BN_ULONG *c1, size_t num_c1,
|
||||
const EC_FELEM *c2, EC_FELEM *out_y,
|
||||
@@ -266,7 +270,8 @@ static BN_ULONG sqrt_ratio_3mod4(const EC_GROUP *group, const EC_FELEM *Z,
|
||||
}
|
||||
|
||||
// map_to_curve_simple_swu implements the operation described in section 6.6.2
|
||||
// of RFC 9380, using the straight-line implementation in appendix F.2.
|
||||
// of draft-irtf-cfrg-hash-to-curve-16, using the straight-line implementation
|
||||
// in appendix F.2.
|
||||
static void map_to_curve_simple_swu(const EC_GROUP *group, const EC_FELEM *Z,
|
||||
const BN_ULONG *c1, size_t num_c1,
|
||||
const EC_FELEM *c2, EC_JACOBIAN *out,
|
||||
@@ -400,7 +405,7 @@ int ec_hash_to_curve_p256_xmd_sha256_sswu(const EC_GROUP *group,
|
||||
EC_JACOBIAN *out, const uint8_t *dst,
|
||||
size_t dst_len, const uint8_t *msg,
|
||||
size_t msg_len) {
|
||||
// See section 8.3 of RFC 9380.
|
||||
// See section 8.3 of draft-irtf-cfrg-hash-to-curve-16.
|
||||
if (EC_GROUP_get_curve_name(group) != NID_X9_62_prime256v1) {
|
||||
OPENSSL_PUT_ERROR(EC, EC_R_GROUP_MISMATCH);
|
||||
return 0;
|
||||
@@ -433,7 +438,7 @@ int ec_hash_to_curve_p384_xmd_sha384_sswu(const EC_GROUP *group,
|
||||
EC_JACOBIAN *out, const uint8_t *dst,
|
||||
size_t dst_len, const uint8_t *msg,
|
||||
size_t msg_len) {
|
||||
// See section 8.3 of RFC 9380.
|
||||
// See section 8.3 of draft-irtf-cfrg-hash-to-curve-16.
|
||||
if (EC_GROUP_get_curve_name(group) != NID_secp384r1) {
|
||||
OPENSSL_PUT_ERROR(EC, EC_R_GROUP_MISMATCH);
|
||||
return 0;
|
||||
|
||||
@@ -30,22 +30,24 @@ extern "C" {
|
||||
|
||||
// ec_hash_to_curve_p256_xmd_sha256_sswu hashes |msg| to a point on |group| and
|
||||
// writes the result to |out|, implementing the P256_XMD:SHA-256_SSWU_RO_ suite
|
||||
// from RFC 9380. It returns one on success and zero on error.
|
||||
// from draft-irtf-cfrg-hash-to-curve-16. It returns one on success and zero on
|
||||
// error.
|
||||
OPENSSL_EXPORT int ec_hash_to_curve_p256_xmd_sha256_sswu(
|
||||
const EC_GROUP *group, EC_JACOBIAN *out, const uint8_t *dst, size_t dst_len,
|
||||
const uint8_t *msg, size_t msg_len);
|
||||
|
||||
// ec_hash_to_curve_p384_xmd_sha384_sswu hashes |msg| to a point on |group| and
|
||||
// writes the result to |out|, implementing the P384_XMD:SHA-384_SSWU_RO_ suite
|
||||
// from RFC 9380. It returns one on success and zero on error.
|
||||
// from draft-irtf-cfrg-hash-to-curve-16. It returns one on success and zero on
|
||||
// error.
|
||||
OPENSSL_EXPORT int ec_hash_to_curve_p384_xmd_sha384_sswu(
|
||||
const EC_GROUP *group, EC_JACOBIAN *out, const uint8_t *dst, size_t dst_len,
|
||||
const uint8_t *msg, size_t msg_len);
|
||||
|
||||
// ec_hash_to_scalar_p384_xmd_sha384 hashes |msg| to a scalar on |group|
|
||||
// and writes the result to |out|, using the hash_to_field operation from the
|
||||
// P384_XMD:SHA-384_SSWU_RO_ suite from RFC 9380, but generating a value modulo
|
||||
// the group order rather than a field element.
|
||||
// P384_XMD:SHA-384_SSWU_RO_ suite from draft-irtf-cfrg-hash-to-curve-16, but
|
||||
// generating a value modulo the group order rather than a field element.
|
||||
OPENSSL_EXPORT int ec_hash_to_scalar_p384_xmd_sha384(
|
||||
const EC_GROUP *group, EC_SCALAR *out, const uint8_t *dst, size_t dst_len,
|
||||
const uint8_t *msg, size_t msg_len);
|
||||
|
||||
@@ -62,87 +62,34 @@
|
||||
#include <CCryptoBoringSSL_mem.h>
|
||||
|
||||
#include "../bytestring/internal.h"
|
||||
#include "../fipsmodule/ecdsa/internal.h"
|
||||
#include "../fipsmodule/ec/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 *out_sig_len, const EC_KEY *eckey) {
|
||||
unsigned int *sig_len, const EC_KEY *eckey) {
|
||||
if (eckey->ecdsa_meth && eckey->ecdsa_meth->sign) {
|
||||
return eckey->ecdsa_meth->sign(digest, digest_len, sig, out_sig_len,
|
||||
return eckey->ecdsa_meth->sign(digest, digest_len, sig, sig_len,
|
||||
(EC_KEY*) eckey /* cast away const */);
|
||||
}
|
||||
|
||||
*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;
|
||||
ECDSA_SIG *s = ECDSA_do_sign(digest, digest_len, eckey);
|
||||
if (s == NULL) {
|
||||
*sig_len = 0;
|
||||
goto err;
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
*out_sig_len = (unsigned)len;
|
||||
*sig_len = (unsigned)len;
|
||||
ret = 1;
|
||||
|
||||
err:
|
||||
@@ -152,13 +99,12 @@ 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) {
|
||||
// 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.
|
||||
ECDSA_SIG *s;
|
||||
int ret = 0;
|
||||
uint8_t *der = NULL;
|
||||
ECDSA_SIG *s = ECDSA_SIG_from_bytes(sig, sig_len);
|
||||
|
||||
// Decode the ECDSA signature.
|
||||
s = ECDSA_SIG_from_bytes(sig, sig_len);
|
||||
if (s == NULL) {
|
||||
goto err;
|
||||
}
|
||||
@@ -172,10 +118,7 @@ int ECDSA_verify(int type, const uint8_t *digest, size_t digest_len,
|
||||
goto err;
|
||||
}
|
||||
|
||||
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);
|
||||
ret = ECDSA_do_verify(digest, digest_len, s, eckey);
|
||||
|
||||
err:
|
||||
OPENSSL_free(der);
|
||||
@@ -204,95 +147,6 @@ 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) {
|
||||
|
||||
@@ -31,7 +31,15 @@ struct engine_st {
|
||||
ECDSA_METHOD *ecdsa_method;
|
||||
};
|
||||
|
||||
ENGINE *ENGINE_new(void) { return OPENSSL_zalloc(sizeof(ENGINE)); }
|
||||
ENGINE *ENGINE_new(void) {
|
||||
ENGINE *engine = OPENSSL_malloc(sizeof(ENGINE));
|
||||
if (engine == NULL) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
OPENSSL_memset(engine, 0, sizeof(ENGINE));
|
||||
return engine;
|
||||
}
|
||||
|
||||
int ENGINE_free(ENGINE *engine) {
|
||||
// Methods are currently required to be static so are not unref'ed.
|
||||
|
||||
@@ -164,17 +164,6 @@ 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);
|
||||
@@ -185,9 +174,13 @@ 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_libc_malloc(src->data);
|
||||
dst->data = strdup(src->data);
|
||||
OPENSSL_MSVC_PRAGMA(warning(pop))
|
||||
}
|
||||
dst->packed = src->packed;
|
||||
dst->line = src->line;
|
||||
@@ -435,52 +428,50 @@ static const char *err_string_lookup(uint32_t lib, uint32_t key,
|
||||
return &string_data[(*result) & 0x7fff];
|
||||
}
|
||||
|
||||
typedef struct library_name_st {
|
||||
const char *str;
|
||||
const char *symbol;
|
||||
const char *reason_symbol;
|
||||
} LIBRARY_NAME;
|
||||
|
||||
static const LIBRARY_NAME kLibraryNames[ERR_NUM_LIBS] = {
|
||||
{"invalid library (0)", NULL, NULL},
|
||||
{"unknown library", "NONE", "NONE_LIB"},
|
||||
{"system library", "SYS", "SYS_LIB"},
|
||||
{"bignum routines", "BN", "BN_LIB"},
|
||||
{"RSA routines", "RSA", "RSA_LIB"},
|
||||
{"Diffie-Hellman routines", "DH", "DH_LIB"},
|
||||
{"public key routines", "EVP", "EVP_LIB"},
|
||||
{"memory buffer routines", "BUF", "BUF_LIB"},
|
||||
{"object identifier routines", "OBJ", "OBJ_LIB"},
|
||||
{"PEM routines", "PEM", "PEM_LIB"},
|
||||
{"DSA routines", "DSA", "DSA_LIB"},
|
||||
{"X.509 certificate routines", "X509", "X509_LIB"},
|
||||
{"ASN.1 encoding routines", "ASN1", "ASN1_LIB"},
|
||||
{"configuration file routines", "CONF", "CONF_LIB"},
|
||||
{"common libcrypto routines", "CRYPTO", "CRYPTO_LIB"},
|
||||
{"elliptic curve routines", "EC", "EC_LIB"},
|
||||
{"SSL routines", "SSL", "SSL_LIB"},
|
||||
{"BIO routines", "BIO", "BIO_LIB"},
|
||||
{"PKCS7 routines", "PKCS7", "PKCS7_LIB"},
|
||||
{"PKCS8 routines", "PKCS8", "PKCS8_LIB"},
|
||||
{"X509 V3 routines", "X509V3", "X509V3_LIB"},
|
||||
{"random number generator", "RAND", "RAND_LIB"},
|
||||
{"ENGINE routines", "ENGINE", "ENGINE_LIB"},
|
||||
{"OCSP routines", "OCSP", "OCSP_LIB"},
|
||||
{"UI routines", "UI", "UI_LIB"},
|
||||
{"COMP routines", "COMP", "COMP_LIB"},
|
||||
{"ECDSA routines", "ECDSA", "ECDSA_LIB"},
|
||||
{"ECDH routines", "ECDH", "ECDH_LIB"},
|
||||
{"HMAC routines", "HMAC", "HMAC_LIB"},
|
||||
{"Digest functions", "DIGEST", "DIGEST_LIB"},
|
||||
{"Cipher functions", "CIPHER", "CIPHER_LIB"},
|
||||
{"HKDF functions", "HKDF", "HKDF_LIB"},
|
||||
{"Trust Token functions", "TRUST_TOKEN", "TRUST_TOKEN_LIB"},
|
||||
{"User defined functions", "USER", "USER_LIB"},
|
||||
static const char *const kLibraryNames[ERR_NUM_LIBS] = {
|
||||
"invalid library (0)",
|
||||
"unknown library", // ERR_LIB_NONE
|
||||
"system library", // ERR_LIB_SYS
|
||||
"bignum routines", // ERR_LIB_BN
|
||||
"RSA routines", // ERR_LIB_RSA
|
||||
"Diffie-Hellman routines", // ERR_LIB_DH
|
||||
"public key routines", // ERR_LIB_EVP
|
||||
"memory buffer routines", // ERR_LIB_BUF
|
||||
"object identifier routines", // ERR_LIB_OBJ
|
||||
"PEM routines", // ERR_LIB_PEM
|
||||
"DSA routines", // ERR_LIB_DSA
|
||||
"X.509 certificate routines", // ERR_LIB_X509
|
||||
"ASN.1 encoding routines", // ERR_LIB_ASN1
|
||||
"configuration file routines", // ERR_LIB_CONF
|
||||
"common libcrypto routines", // ERR_LIB_CRYPTO
|
||||
"elliptic curve routines", // ERR_LIB_EC
|
||||
"SSL routines", // ERR_LIB_SSL
|
||||
"BIO routines", // ERR_LIB_BIO
|
||||
"PKCS7 routines", // ERR_LIB_PKCS7
|
||||
"PKCS8 routines", // ERR_LIB_PKCS8
|
||||
"X509 V3 routines", // ERR_LIB_X509V3
|
||||
"random number generator", // ERR_LIB_RAND
|
||||
"ENGINE routines", // ERR_LIB_ENGINE
|
||||
"OCSP routines", // ERR_LIB_OCSP
|
||||
"UI routines", // ERR_LIB_UI
|
||||
"COMP routines", // ERR_LIB_COMP
|
||||
"ECDSA routines", // ERR_LIB_ECDSA
|
||||
"ECDH routines", // ERR_LIB_ECDH
|
||||
"HMAC routines", // ERR_LIB_HMAC
|
||||
"Digest functions", // ERR_LIB_DIGEST
|
||||
"Cipher functions", // ERR_LIB_CIPHER
|
||||
"HKDF functions", // ERR_LIB_HKDF
|
||||
"Trust Token functions", // ERR_LIB_TRUST_TOKEN
|
||||
"User defined functions", // ERR_LIB_USER
|
||||
};
|
||||
|
||||
static const char *err_lib_error_string(uint32_t packed_error) {
|
||||
const uint32_t lib = ERR_GET_LIB(packed_error);
|
||||
return lib >= ERR_NUM_LIBS ? NULL : kLibraryNames[lib].str;
|
||||
|
||||
if (lib >= ERR_NUM_LIBS) {
|
||||
return NULL;
|
||||
}
|
||||
return kLibraryNames[lib];
|
||||
}
|
||||
|
||||
const char *ERR_lib_error_string(uint32_t packed_error) {
|
||||
@@ -488,67 +479,51 @@ const char *ERR_lib_error_string(uint32_t packed_error) {
|
||||
return ret == NULL ? "unknown library" : ret;
|
||||
}
|
||||
|
||||
const char *ERR_lib_symbol_name(uint32_t packed_error) {
|
||||
const uint32_t lib = ERR_GET_LIB(packed_error);
|
||||
return lib >= ERR_NUM_LIBS ? NULL : kLibraryNames[lib].symbol;
|
||||
}
|
||||
|
||||
const char *ERR_func_error_string(uint32_t packed_error) {
|
||||
return "OPENSSL_internal";
|
||||
}
|
||||
|
||||
static const char *err_reason_error_string(uint32_t packed_error, int symbol) {
|
||||
static const char *err_reason_error_string(uint32_t packed_error) {
|
||||
const uint32_t lib = ERR_GET_LIB(packed_error);
|
||||
const uint32_t reason = ERR_GET_REASON(packed_error);
|
||||
|
||||
if (lib == ERR_LIB_SYS) {
|
||||
if (!symbol && reason < 127) {
|
||||
if (reason < 127) {
|
||||
return strerror(reason);
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
||||
if (reason < ERR_NUM_LIBS) {
|
||||
return symbol ? kLibraryNames[reason].reason_symbol
|
||||
: kLibraryNames[reason].str;
|
||||
return kLibraryNames[reason];
|
||||
}
|
||||
|
||||
if (reason < 100) {
|
||||
// TODO(davidben): All our other reason strings match the symbol name. Only
|
||||
// the common ones differ. Should we just consistently return the symbol
|
||||
// name?
|
||||
switch (reason) {
|
||||
case ERR_R_MALLOC_FAILURE:
|
||||
return symbol ? "MALLOC_FAILURE" : "malloc failure";
|
||||
return "malloc failure";
|
||||
case ERR_R_SHOULD_NOT_HAVE_BEEN_CALLED:
|
||||
return symbol ? "SHOULD_NOT_HAVE_BEEN_CALLED"
|
||||
: "function should not have been called";
|
||||
return "function should not have been called";
|
||||
case ERR_R_PASSED_NULL_PARAMETER:
|
||||
return symbol ? "PASSED_NULL_PARAMETER" : "passed a null parameter";
|
||||
return "passed a null parameter";
|
||||
case ERR_R_INTERNAL_ERROR:
|
||||
return symbol ? "INTERNAL_ERROR" : "internal error";
|
||||
return "internal error";
|
||||
case ERR_R_OVERFLOW:
|
||||
return symbol ? "OVERFLOW" : "overflow";
|
||||
return "overflow";
|
||||
default:
|
||||
return NULL;
|
||||
}
|
||||
}
|
||||
|
||||
// Unlike OpenSSL, BoringSSL's reason strings already match symbol name, so we
|
||||
// do not need to check |symbol|.
|
||||
return err_string_lookup(lib, reason, kOpenSSLReasonValues,
|
||||
kOpenSSLReasonValuesLen, kOpenSSLReasonStringData);
|
||||
}
|
||||
|
||||
const char *ERR_reason_error_string(uint32_t packed_error) {
|
||||
const char *ret = err_reason_error_string(packed_error, /*symbol=*/0);
|
||||
const char *ret = err_reason_error_string(packed_error);
|
||||
return ret == NULL ? "unknown error" : ret;
|
||||
}
|
||||
|
||||
const char *ERR_reason_symbol_name(uint32_t packed_error) {
|
||||
return err_reason_error_string(packed_error, /*symbol=*/1);
|
||||
}
|
||||
|
||||
char *ERR_error_string(uint32_t packed_error, char *ret) {
|
||||
static char buf[ERR_ERROR_STRING_BUF_LEN];
|
||||
|
||||
@@ -575,7 +550,7 @@ char *ERR_error_string_n(uint32_t packed_error, char *buf, size_t len) {
|
||||
unsigned reason = ERR_GET_REASON(packed_error);
|
||||
|
||||
const char *lib_str = err_lib_error_string(packed_error);
|
||||
const char *reason_str = err_reason_error_string(packed_error, /*symbol=*/0);
|
||||
const char *reason_str = err_reason_error_string(packed_error);
|
||||
|
||||
char lib_buf[32], reason_buf[32];
|
||||
if (lib_str == NULL) {
|
||||
@@ -774,9 +749,13 @@ 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_libc_malloc(data);
|
||||
char *copy = strdup(data);
|
||||
OPENSSL_MSVC_PRAGMA(warning(pop))
|
||||
if (copy != NULL) {
|
||||
err_set_error_data(copy);
|
||||
}
|
||||
|
||||
+498
-503
File diff suppressed because it is too large.
Load diff
@@ -59,9 +59,12 @@
|
||||
#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"
|
||||
@@ -78,13 +81,17 @@ OPENSSL_DECLARE_ERROR_REASON(EVP, NOT_XOF_OR_INVALID_LENGTH)
|
||||
OPENSSL_DECLARE_ERROR_REASON(EVP, EMPTY_PSK)
|
||||
|
||||
EVP_PKEY *EVP_PKEY_new(void) {
|
||||
EVP_PKEY *ret = OPENSSL_zalloc(sizeof(EVP_PKEY));
|
||||
EVP_PKEY *ret;
|
||||
|
||||
ret = OPENSSL_malloc(sizeof(EVP_PKEY));
|
||||
if (ret == NULL) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
OPENSSL_memset(ret, 0, sizeof(EVP_PKEY));
|
||||
ret->type = EVP_PKEY_NONE;
|
||||
ret->references = 1;
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
@@ -146,7 +153,9 @@ 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) {
|
||||
evp_pkey_set_method(to, from->ameth);
|
||||
if (!EVP_PKEY_set_type(to, from->type)) {
|
||||
return 0;
|
||||
}
|
||||
} else if (to->type != from->type) {
|
||||
OPENSSL_PUT_ERROR(EVP, EVP_R_DIFFERENT_KEY_TYPES);
|
||||
return 0;
|
||||
@@ -220,21 +229,117 @@ static const EVP_PKEY_ASN1_METHOD *evp_pkey_asn1_find(int nid) {
|
||||
}
|
||||
}
|
||||
|
||||
void evp_pkey_set_method(EVP_PKEY *pkey, const EVP_PKEY_ASN1_METHOD *method) {
|
||||
static 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) {
|
||||
// In OpenSSL, this was used to map between type aliases. BoringSSL supports
|
||||
// no type aliases, so this function is just the identity.
|
||||
return nid;
|
||||
const EVP_PKEY_ASN1_METHOD *meth = evp_pkey_asn1_find(nid);
|
||||
if (meth == NULL) {
|
||||
return NID_undef;
|
||||
}
|
||||
return meth->pkey_id;
|
||||
}
|
||||
|
||||
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, EC, and DH keys. Other
|
||||
// key types have internal representations which are not exposed through the
|
||||
// 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
|
||||
// public API.
|
||||
switch (type) {
|
||||
case EVP_PKEY_RSA:
|
||||
@@ -243,8 +348,6 @@ 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);
|
||||
@@ -276,26 +379,16 @@ 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) {
|
||||
// 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;
|
||||
}
|
||||
|
||||
EVP_PKEY *ret = EVP_PKEY_new();
|
||||
if (ret == NULL) {
|
||||
if (ret == NULL ||
|
||||
!EVP_PKEY_set_type(ret, type)) {
|
||||
goto err;
|
||||
}
|
||||
|
||||
if (ret->ameth->set_priv_raw == NULL) {
|
||||
OPENSSL_PUT_ERROR(EVP, EVP_R_OPERATION_NOT_SUPPORTED_FOR_THIS_KEYTYPE);
|
||||
goto err;
|
||||
}
|
||||
evp_pkey_set_method(ret, method);
|
||||
|
||||
if (!ret->ameth->set_priv_raw(ret, in, len)) {
|
||||
goto err;
|
||||
@@ -310,26 +403,16 @@ err:
|
||||
|
||||
EVP_PKEY *EVP_PKEY_new_raw_public_key(int type, ENGINE *unused,
|
||||
const uint8_t *in, size_t len) {
|
||||
// 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;
|
||||
}
|
||||
|
||||
EVP_PKEY *ret = EVP_PKEY_new();
|
||||
if (ret == NULL) {
|
||||
if (ret == NULL ||
|
||||
!EVP_PKEY_set_type(ret, type)) {
|
||||
goto err;
|
||||
}
|
||||
|
||||
if (ret->ameth->set_pub_raw == NULL) {
|
||||
OPENSSL_PUT_ERROR(EVP, EVP_R_OPERATION_NOT_SUPPORTED_FOR_THIS_KEYTYPE);
|
||||
goto err;
|
||||
}
|
||||
evp_pkey_set_method(ret, method);
|
||||
|
||||
if (!ret->ameth->set_pub_raw(ret, in, len)) {
|
||||
goto err;
|
||||
|
||||
Loaded 100 of 723 files, more files were not shown because too many files have changed in this diff.
Show more
Reference in new issue
Block a user