mirror of
https://github.com/apple/swift-crypto
synced 2026-11-22 04:30:39 +00:00
Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
176abc28e0 | ||
|
|
64a4de00fb | ||
|
|
84b1d49411 | ||
|
|
88b9c9b3b7 | ||
|
|
993467897d | ||
|
|
75475b8063 | ||
|
|
e5f10a704b | ||
|
|
871f95d0eb | ||
|
|
af6be725f5 | ||
|
|
93a2ebfad7 | ||
|
|
9fb2fd8d3c | ||
|
|
4ce1b9b001 | ||
|
|
74167641f8 | ||
|
|
6214426408 | ||
|
|
dbb455989c | ||
|
|
46eca5f54b | ||
|
|
3ef65592d6 | ||
|
|
010a4486f0 | ||
|
|
0d32399af8 | ||
|
|
d4d7fefc90 | ||
|
|
5bd06ee1d2 | ||
|
|
9fe7f6e388 | ||
|
|
cedae37153 | ||
|
|
041199614e | ||
|
|
e9a2ec1845 | ||
|
|
1f483f4240 | ||
|
|
6db5a75258 | ||
|
|
e8d6eba1fe | ||
|
|
e2285965a8 | ||
|
|
219076f8a0 | ||
|
|
05ca26c7dc | ||
|
|
ced89100e1 |
No files matched your search
@@ -11,12 +11,31 @@ jobs:
|
||||
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_6_1_arguments_override: "--explicit-target-dependency-import-check error"
|
||||
linux_nightly_next_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_6_1_enabled: true
|
||||
windows_nightly_next_enabled: true
|
||||
windows_nightly_main_enabled: true
|
||||
windows_6_0_arguments_override: "--explicit-target-dependency-import-check error"
|
||||
windows_6_1_arguments_override: "--explicit-target-dependency-import-check error"
|
||||
windows_nightly_next_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
|
||||
|
||||
static-sdk:
|
||||
name: Static SDK
|
||||
uses: apple/swift-nio/.github/workflows/static_sdk.yml@main
|
||||
|
||||
macos-tests:
|
||||
name: macOS tests
|
||||
uses: apple/swift-nio/.github/workflows/macos_tests.yml@main
|
||||
with:
|
||||
runner_pool: nightly
|
||||
build_scheme: swift-crypto-Package
|
||||
@@ -12,29 +12,51 @@ jobs:
|
||||
license_header_check_project_name: "SwiftCrypto"
|
||||
docs_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_6_1_arguments_override: "--explicit-target-dependency-import-check error"
|
||||
linux_nightly_next_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_6_1_enabled: true
|
||||
windows_nightly_next_enabled: true
|
||||
windows_nightly_main_enabled: true
|
||||
windows_6_0_arguments_override: "--explicit-target-dependency-import-check error"
|
||||
windows_6_1_arguments_override: "--explicit-target-dependency-import-check error"
|
||||
windows_nightly_next_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
|
||||
|
||||
cmake-checks:
|
||||
name: CMake checks
|
||||
uses: apple/swift-nio/.github/workflows/cmake_tests.yml@main
|
||||
with:
|
||||
update_cmake_lists_config: >-
|
||||
{
|
||||
"targets": [
|
||||
{ "name": "CCryptoBoringSSL", "type": "source", "exceptions": [] },
|
||||
{ "name": "CCryptoBoringSSLShims", "type": "source", "exceptions": [] },
|
||||
{ "name": "CryptoBoringWrapper", "type": "source", "exceptions": [] },
|
||||
{ "name": "Crypto", "type": "source", "exceptions": [] },
|
||||
{ "name": "_CryptoExtras", "type": "source", "exceptions": [] },
|
||||
{ "name": "CCryptoBoringSSL", "type": "assembly", "exceptions": [ "*/AES/*.swift" ] }
|
||||
]
|
||||
}
|
||||
|
||||
macos-tests:
|
||||
name: macOS tests
|
||||
uses: apple/swift-nio/.github/workflows/macos_tests.yml@main
|
||||
with:
|
||||
runner_pool: general
|
||||
build_scheme: swift-crypto-Package
|
||||
|
||||
static-sdk:
|
||||
name: Static SDK
|
||||
uses: apple/swift-nio/.github/workflows/static_sdk.yml@main
|
||||
@@ -94,7 +94,6 @@ Sources/_CryptoExtras/OPRFs/VOPRFClient.swift
|
||||
Sources/_CryptoExtras/OPRFs/VOPRFServer.swift
|
||||
Sources/_CryptoExtras/RSA/RSA+BlindSigning.swift
|
||||
Sources/_CryptoExtras/RSA/RSA.swift
|
||||
Sources/_CryptoExtras/RSA/RSA_security.swift
|
||||
Sources/_CryptoExtras/Util/BoringSSLHelpers.swift
|
||||
Sources/_CryptoExtras/Util/DigestType.swift
|
||||
Sources/_CryptoExtras/Util/Error.swift
|
||||
|
||||
@@ -0,0 +1,206 @@
|
||||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// This source file is part of the SwiftCrypto open source project
|
||||
//
|
||||
// Copyright (c) 2025 Apple Inc. and the SwiftCrypto project authors
|
||||
// Licensed under Apache License v2.0
|
||||
//
|
||||
// See LICENSE.txt for license information
|
||||
// See CONTRIBUTORS.txt for the list of SwiftCrypto project authors
|
||||
//
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
import Benchmark
|
||||
import Crypto
|
||||
import Foundation
|
||||
import _CryptoExtras
|
||||
|
||||
let benchmarks = {
|
||||
let defaultMetrics: [BenchmarkMetric] = [.mallocCountTotal, .cpuTotal]
|
||||
|
||||
Benchmark(
|
||||
"arc-issue-p256",
|
||||
configuration: Benchmark.Configuration(
|
||||
metrics: defaultMetrics,
|
||||
scalingFactor: .kilo,
|
||||
maxDuration: .seconds(10_000_000),
|
||||
maxIterations: 3
|
||||
)
|
||||
) { benchmark in
|
||||
let privateKey = P256._ARCV1.PrivateKey()
|
||||
let publicKey = privateKey.publicKey
|
||||
let requestContext = Data("shared request context".utf8)
|
||||
let precredential = try publicKey.prepareCredentialRequest(requestContext: requestContext)
|
||||
let credentialRequest = precredential.credentialRequest
|
||||
|
||||
benchmark.startMeasurement()
|
||||
|
||||
for _ in benchmark.scaledIterations {
|
||||
blackHole(try privateKey.issue(credentialRequest))
|
||||
}
|
||||
}
|
||||
|
||||
Benchmark(
|
||||
"arc-verify-p256",
|
||||
configuration: Benchmark.Configuration(
|
||||
metrics: defaultMetrics,
|
||||
scalingFactor: .kilo,
|
||||
maxDuration: .seconds(10_000_000),
|
||||
maxIterations: 10
|
||||
)
|
||||
) { benchmark in
|
||||
let privateKey = P256._ARCV1.PrivateKey()
|
||||
let publicKey = privateKey.publicKey
|
||||
let requestContext = Data("shared request context".utf8)
|
||||
let (presentationContext, presentationLimit) = (Data("shared presentation context".utf8), 2)
|
||||
let precredential = try publicKey.prepareCredentialRequest(requestContext: requestContext)
|
||||
let credentialRequest = precredential.credentialRequest
|
||||
let credentialResponse = try privateKey.issue(credentialRequest)
|
||||
var credential = try publicKey.finalize(credentialResponse, for: precredential)
|
||||
let (presentation, nonce) = try credential.makePresentation(
|
||||
context: presentationContext,
|
||||
presentationLimit: presentationLimit
|
||||
)
|
||||
|
||||
benchmark.startMeasurement()
|
||||
|
||||
for _ in benchmark.scaledIterations {
|
||||
blackHole(
|
||||
try privateKey.verify(
|
||||
presentation,
|
||||
requestContext: requestContext,
|
||||
presentationContext: presentationContext,
|
||||
presentationLimit: presentationLimit,
|
||||
nonce: nonce
|
||||
)
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
Benchmark(
|
||||
"arc-issue-p384",
|
||||
configuration: Benchmark.Configuration(
|
||||
metrics: defaultMetrics,
|
||||
scalingFactor: .kilo,
|
||||
maxDuration: .seconds(10_000_000),
|
||||
maxIterations: 3
|
||||
)
|
||||
) { benchmark in
|
||||
let privateKey = P384._ARCV1.PrivateKey()
|
||||
let publicKey = privateKey.publicKey
|
||||
let requestContext = Data("shared request context".utf8)
|
||||
let precredential = try publicKey.prepareCredentialRequest(requestContext: requestContext)
|
||||
let credentialRequest = precredential.credentialRequest
|
||||
|
||||
benchmark.startMeasurement()
|
||||
|
||||
for _ in benchmark.scaledIterations {
|
||||
blackHole(try privateKey.issue(credentialRequest))
|
||||
}
|
||||
}
|
||||
|
||||
Benchmark(
|
||||
"arc-verify-p384",
|
||||
configuration: Benchmark.Configuration(
|
||||
metrics: defaultMetrics,
|
||||
scalingFactor: .kilo,
|
||||
maxDuration: .seconds(10_000_000),
|
||||
maxIterations: 10
|
||||
)
|
||||
) { benchmark in
|
||||
let privateKey = P384._ARCV1.PrivateKey()
|
||||
let publicKey = privateKey.publicKey
|
||||
let requestContext = Data("shared request context".utf8)
|
||||
let (presentationContext, presentationLimit) = (Data("shared presentation context".utf8), 2)
|
||||
let precredential = try publicKey.prepareCredentialRequest(requestContext: requestContext)
|
||||
let credentialRequest = precredential.credentialRequest
|
||||
let credentialResponse = try privateKey.issue(credentialRequest)
|
||||
var credential = try publicKey.finalize(credentialResponse, for: precredential)
|
||||
let (presentation, nonce) = try credential.makePresentation(
|
||||
context: presentationContext,
|
||||
presentationLimit: presentationLimit
|
||||
)
|
||||
|
||||
benchmark.startMeasurement()
|
||||
|
||||
for _ in benchmark.scaledIterations {
|
||||
blackHole(
|
||||
try privateKey.verify(
|
||||
presentation,
|
||||
requestContext: requestContext,
|
||||
presentationContext: presentationContext,
|
||||
presentationLimit: presentationLimit,
|
||||
nonce: nonce
|
||||
)
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
Benchmark(
|
||||
"voprf-evaluate-p384",
|
||||
configuration: Benchmark.Configuration(
|
||||
metrics: defaultMetrics,
|
||||
scalingFactor: .kilo,
|
||||
maxDuration: .seconds(10_000_000),
|
||||
maxIterations: 3
|
||||
)
|
||||
) { benchmark in
|
||||
let privateKey = P384._VOPRF.PrivateKey()
|
||||
let publicKey = privateKey.publicKey
|
||||
let privateInput = Data("This is some input data".utf8)
|
||||
let blindedInput = try publicKey.blind(privateInput)
|
||||
let blindedElement = blindedInput.blindedElement
|
||||
|
||||
benchmark.startMeasurement()
|
||||
|
||||
for _ in benchmark.scaledIterations {
|
||||
blackHole(try privateKey.evaluate(blindedElement))
|
||||
}
|
||||
}
|
||||
|
||||
Benchmark(
|
||||
"key-exchange-p256",
|
||||
configuration: Benchmark.Configuration(
|
||||
metrics: defaultMetrics,
|
||||
scalingFactor: .kilo,
|
||||
maxDuration: .seconds(10_000_000),
|
||||
maxIterations: 10
|
||||
)
|
||||
) { benchmark in
|
||||
for _ in benchmark.scaledIterations {
|
||||
let (key1, key2) = (P256.KeyAgreement.PrivateKey(), P256.KeyAgreement.PrivateKey())
|
||||
blackHole(try key1.sharedSecretFromKeyAgreement(with: key2.publicKey))
|
||||
}
|
||||
}
|
||||
|
||||
Benchmark(
|
||||
"key-exchange-p384",
|
||||
configuration: Benchmark.Configuration(
|
||||
metrics: defaultMetrics,
|
||||
scalingFactor: .kilo,
|
||||
maxDuration: .seconds(10_000_000),
|
||||
maxIterations: 10
|
||||
)
|
||||
) { benchmark in
|
||||
for _ in benchmark.scaledIterations {
|
||||
let (key1, key2) = (P384.KeyAgreement.PrivateKey(), P384.KeyAgreement.PrivateKey())
|
||||
blackHole(try key1.sharedSecretFromKeyAgreement(with: key2.publicKey))
|
||||
}
|
||||
}
|
||||
|
||||
Benchmark(
|
||||
"key-exchange-p521",
|
||||
configuration: Benchmark.Configuration(
|
||||
metrics: defaultMetrics,
|
||||
scalingFactor: .kilo,
|
||||
maxDuration: .seconds(10_000_000),
|
||||
maxIterations: 10
|
||||
)
|
||||
) { benchmark in
|
||||
for _ in benchmark.scaledIterations {
|
||||
let (key1, key2) = (P521.KeyAgreement.PrivateKey(), P521.KeyAgreement.PrivateKey())
|
||||
blackHole(try key1.sharedSecretFromKeyAgreement(with: key2.publicKey))
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,25 @@
|
||||
// swift-tools-version:5.10
|
||||
import PackageDescription
|
||||
|
||||
let package = Package(
|
||||
name: "swift-crypto-benchmarks",
|
||||
platforms: [.macOS("14")],
|
||||
dependencies: [
|
||||
.package(name: "swift-crypto", path: "../"),
|
||||
.package(url: "https://github.com/ordo-one/package-benchmark", from: "1.22.0"),
|
||||
],
|
||||
targets: [
|
||||
.executableTarget(
|
||||
name: "SwiftCryptoBenchmarks",
|
||||
dependencies: [
|
||||
.product(name: "Benchmark", package: "package-benchmark"),
|
||||
.product(name: "Crypto", package: "swift-crypto"),
|
||||
.product(name: "_CryptoExtras", package: "swift-crypto"),
|
||||
],
|
||||
path: "Benchmarks/",
|
||||
plugins: [
|
||||
.plugin(name: "BenchmarkPlugin", package: "package-benchmark")
|
||||
]
|
||||
)
|
||||
]
|
||||
)
|
||||
@@ -14,6 +14,10 @@
|
||||
|
||||
cmake_minimum_required(VERSION 3.15.1)
|
||||
|
||||
if(POLICY CMP0157)
|
||||
cmake_policy(SET CMP0157 NEW)
|
||||
endif()
|
||||
|
||||
project(SwiftCrypto
|
||||
LANGUAGES ASM C CXX Swift)
|
||||
|
||||
@@ -47,6 +51,18 @@ if(CMAKE_SYSTEM_NAME STREQUAL Darwin AND NOT CMAKE_CROSSCOMPILING)
|
||||
set(CMAKE_RANLIB "/usr/bin/ranlib")
|
||||
endif()
|
||||
|
||||
set(CMAKE_CXX_STANDARD 17)
|
||||
if(CMAKE_SYSTEM_NAME STREQUAL Windows)
|
||||
# We need to ensure that we don't include the min/max macros from the Windows SDK.
|
||||
add_compile_definitions(NOMINMAX)
|
||||
# We can only link against the DLL version of the MSVC runtime library for now.
|
||||
set(CMAKE_MSVC_RUNTIME_LIBRARY "MultiThreadedDLL")
|
||||
if(CMAKE_Swift_COMPILER_VERSION VERSION_EQUAL 0.0.0 OR CMAKE_Swift_COMPILER_VERSION VERSION_GREATER_EQUAL 6.2)
|
||||
# We need to set the static library prefix to "lib" so that we can link against the static libraries.
|
||||
set(CMAKE_STATIC_LIBRARY_PREFIX_Swift "lib")
|
||||
endif()
|
||||
endif()
|
||||
|
||||
if(NOT CMAKE_SYSTEM_NAME STREQUAL Darwin)
|
||||
find_package(dispatch CONFIG)
|
||||
find_package(Foundation CONFIG)
|
||||
|
||||
@@ -58,6 +58,20 @@ A good swift-crypto patch is:
|
||||
|
||||
Please open a pull request at https://github.com/apple/swift-crypto. Make sure the CI passes, and then wait for code review.
|
||||
|
||||
### How to update CMakeLists files
|
||||
|
||||
If you wish to update the CMakeLists files you can either do this by using [act](https://github.com/nektos/act) or calling the remotely hosted CI script.
|
||||
|
||||
Issuing a command such as the following to `act` causes it to run the `cmake-lists` job locally which updates the CMakeLists files and if it finds no changes performs a build. The `--bind` flag means that the VM be acts on your local filesystem so be aware that this could delete/change files (including your git setup/branches).
|
||||
```
|
||||
act --container-architecture linux/amd64 pull_request -j cmake-lists -W ./.github/workflows/pull_request.yml --bind
|
||||
```
|
||||
|
||||
You can find the underlying script at https://github.com/apple/swift-nio/blob/main/scripts/update-cmake-lists.sh . Using the script directly is less straightforwards because it requires you to pass the JSON config from the `pull_request.yml` file into the script, such as:
|
||||
```
|
||||
curl -s https://raw.githubusercontent.com/apple/swift-nio/main/scripts/update-cmake-lists.sh | CONFIG_JSON='{"targets":[{"name":"CCryptoBoringSSL","type":"source","exceptions":[]},{"name":"CCryptoBoringSSLShims","type":"source","exceptions":[]},{"name":"CryptoBoringWrapper","type":"source","exceptions":[]},{"name":"Crypto","type":"source","exceptions":[]},{"name":"_CryptoExtras","type":"source","exceptions":[]},{"name":"CCryptoBoringSSL","type":"assembly","exceptions":["*/AES/*.swift"]}]}' bash
|
||||
```
|
||||
|
||||
## API Evolution
|
||||
|
||||
swift-crypto is a unique project in that it is an open-source reimplementation of APIs provided by an Apple system library. For this reason, it is intended to remain compatible with those APIs.
|
||||
|
||||
+4
-3
@@ -1,4 +1,4 @@
|
||||
// swift-tools-version:5.9
|
||||
// swift-tools-version:5.10
|
||||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// This source file is part of the SwiftCrypto open source project
|
||||
@@ -20,7 +20,7 @@
|
||||
// Sources/CCryptoBoringSSL directory. The source repository is at
|
||||
// https://boringssl.googlesource.com/boringssl.
|
||||
//
|
||||
// BoringSSL Commit: aefa5d24da34ef77ac797bdbe684734e5bd870f4
|
||||
// BoringSSL Commit: 035e720641f385e82c72b7b0a9e1d89e58cb5ed5
|
||||
|
||||
import PackageDescription
|
||||
|
||||
@@ -56,6 +56,7 @@ if development || isFreeBSD {
|
||||
Platform.android,
|
||||
Platform.windows,
|
||||
Platform.wasi,
|
||||
Platform.openbsd,
|
||||
]
|
||||
swiftSettings = [
|
||||
.define("CRYPTO_IN_SWIFTPM"),
|
||||
@@ -194,7 +195,7 @@ let package = Package(
|
||||
),
|
||||
.testTarget(name: "CryptoBoringWrapperTests", dependencies: ["CryptoBoringWrapper"]),
|
||||
],
|
||||
cxxLanguageStandard: .cxx14
|
||||
cxxLanguageStandard: .cxx17
|
||||
)
|
||||
|
||||
// Switch between local and remote dependencies depending on an environment variable
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
# Swift Crypto
|
||||
|
||||
Swift Crypto is an open-source implementation of a substantial portion of the API of [Apple CryptoKit](https://developer.apple.com/documentation/cryptokit) suitable for use on Linux platforms. It enables cross-platform or server applications with the advantages of CryptoKit.
|
||||
Swift Crypto is an open-source implementation of a substantial portion of the API of [Apple CryptoKit](https://developer.apple.com/documentation/cryptokit) suitable for use on Linux and ARM64 Windows platforms. It enables cross-platform or server applications with the advantages of CryptoKit.
|
||||
|
||||
## Using Swift Crypto
|
||||
|
||||
@@ -28,7 +28,7 @@ Swift Crypto compiles in two distinct modes depending on the platform for which
|
||||
|
||||
When building Swift Crypto for use on an Apple platform where CryptoKit is already available, Swift Crypto compiles its entire API surface down to nothing and simply re-exports the API of CryptoKit. This means that when using Apple platforms Swift Crypto simply delegates all work to the core implementation of CryptoKit, as though Swift Crypto was not even there.
|
||||
|
||||
When building Swift Crypto for use on Linux, Swift Crypto builds substantially more code. In particular, we build:
|
||||
When building Swift Crypto for use on Linux or Windows, Swift Crypto builds substantially more code. In particular, we build:
|
||||
|
||||
1. A vendored copy of BoringSSL's libcrypto.
|
||||
2. The common API of Swift Crypto and CryptoKit.
|
||||
@@ -110,15 +110,16 @@ If you believe you have identified a vulnerability in Swift Crypto, please [repo
|
||||
|
||||
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:
|
||||
|
||||
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
|
||||
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.9.0 ..< 3.13.0` | 5.9
|
||||
`3.13.0 ...` | 5.10
|
||||
|
||||
### Compatibility
|
||||
|
||||
@@ -128,7 +129,7 @@ What this means for you is that you should depend on Swift Crypto with a version
|
||||
In SwiftPM that can be easily done specifying for example `from: "1.0.0"` meaning that you support Swift Crypto in every version starting from 1.0.0 up to (excluding) 2.0.0.
|
||||
SemVer and Swift Crypto's Public API guarantees should result in a working program without having to worry about testing every single version for compatibility.
|
||||
|
||||
Swift Crypto 2.0.0 was released in September 2021. The only breaking change between Swift Crypto 2.0.0 and 1.0.0 was the addition of new cases in the `CryptoKitError` enumeration. For most users, then, it's safe to depend on either the 1.0.0 _or_ 2.0.0 series of releases.
|
||||
Swift Crypto 2.0.0 was released in September 2021. The only breaking change between Swift Crypto 2.0.0 and 1.0.0 was the addition of new cases in the `CryptoError` enumeration. For most users, then, it's safe to depend on either the 1.0.0 _or_ 2.0.0 series of releases.
|
||||
|
||||
To do so, please use the following dependency in your `Package.swift`:
|
||||
|
||||
|
||||
+72
-43
@@ -13,6 +13,7 @@
|
||||
##===----------------------------------------------------------------------===##
|
||||
|
||||
add_library(CCryptoBoringSSL STATIC
|
||||
"crypto/aes/aes.cc"
|
||||
"crypto/asn1/a_bitstr.cc"
|
||||
"crypto/asn1/a_bool.cc"
|
||||
"crypto/asn1/a_d2i_fp.cc"
|
||||
@@ -53,8 +54,11 @@ add_library(CCryptoBoringSSL STATIC
|
||||
"crypto/bio/socket.cc"
|
||||
"crypto/bio/socket_helper.cc"
|
||||
"crypto/blake2/blake2.cc"
|
||||
"crypto/bn_extra/bn_asn1.cc"
|
||||
"crypto/bn_extra/convert.cc"
|
||||
"crypto/bn/bn_asn1.cc"
|
||||
"crypto/bn/convert.cc"
|
||||
"crypto/bn/div.cc"
|
||||
"crypto/bn/exponentiation.cc"
|
||||
"crypto/bn/sqrt.cc"
|
||||
"crypto/buf/buf.cc"
|
||||
"crypto/bytestring/asn1_compat.cc"
|
||||
"crypto/bytestring/ber.cc"
|
||||
@@ -62,17 +66,19 @@ add_library(CCryptoBoringSSL STATIC
|
||||
"crypto/bytestring/cbs.cc"
|
||||
"crypto/bytestring/unicode.cc"
|
||||
"crypto/chacha/chacha.cc"
|
||||
"crypto/cipher_extra/cipher_extra.cc"
|
||||
"crypto/cipher_extra/derive_key.cc"
|
||||
"crypto/cipher_extra/e_aesctrhmac.cc"
|
||||
"crypto/cipher_extra/e_aesgcmsiv.cc"
|
||||
"crypto/cipher_extra/e_chacha20poly1305.cc"
|
||||
"crypto/cipher_extra/e_des.cc"
|
||||
"crypto/cipher_extra/e_null.cc"
|
||||
"crypto/cipher_extra/e_rc2.cc"
|
||||
"crypto/cipher_extra/e_rc4.cc"
|
||||
"crypto/cipher_extra/e_tls.cc"
|
||||
"crypto/cipher_extra/tls_cbc.cc"
|
||||
"crypto/cipher/derive_key.cc"
|
||||
"crypto/cipher/e_aesctrhmac.cc"
|
||||
"crypto/cipher/e_aeseax.cc"
|
||||
"crypto/cipher/e_aesgcmsiv.cc"
|
||||
"crypto/cipher/e_chacha20poly1305.cc"
|
||||
"crypto/cipher/e_des.cc"
|
||||
"crypto/cipher/e_null.cc"
|
||||
"crypto/cipher/e_rc2.cc"
|
||||
"crypto/cipher/e_rc4.cc"
|
||||
"crypto/cipher/e_tls.cc"
|
||||
"crypto/cipher/get_cipher.cc"
|
||||
"crypto/cipher/tls_cbc.cc"
|
||||
"crypto/cms/cms.cc"
|
||||
"crypto/conf/conf.cc"
|
||||
"crypto/cpu_aarch64_apple.cc"
|
||||
"crypto/cpu_aarch64_fuchsia.cc"
|
||||
@@ -88,16 +94,17 @@ add_library(CCryptoBoringSSL STATIC
|
||||
"crypto/curve25519/curve25519_64_adx.cc"
|
||||
"crypto/curve25519/spake25519.cc"
|
||||
"crypto/des/des.cc"
|
||||
"crypto/dh_extra/dh_asn1.cc"
|
||||
"crypto/dh_extra/params.cc"
|
||||
"crypto/digest_extra/digest_extra.cc"
|
||||
"crypto/dh/dh_asn1.cc"
|
||||
"crypto/dh/params.cc"
|
||||
"crypto/digest/digest_extra.cc"
|
||||
"crypto/dsa/dsa.cc"
|
||||
"crypto/dsa/dsa_asn1.cc"
|
||||
"crypto/ec_extra/ec_asn1.cc"
|
||||
"crypto/ec_extra/ec_derive.cc"
|
||||
"crypto/ec_extra/hash_to_curve.cc"
|
||||
"crypto/ecdh_extra/ecdh_extra.cc"
|
||||
"crypto/ecdsa_extra/ecdsa_asn1.cc"
|
||||
"crypto/ec/ec_asn1.cc"
|
||||
"crypto/ec/ec_derive.cc"
|
||||
"crypto/ec/hash_to_curve.cc"
|
||||
"crypto/ecdh/ecdh.cc"
|
||||
"crypto/ecdsa/ecdsa_asn1.cc"
|
||||
"crypto/ecdsa/ecdsa_p1363.cc"
|
||||
"crypto/engine/engine.cc"
|
||||
"crypto/err/err.cc"
|
||||
"crypto/evp/evp.cc"
|
||||
@@ -122,6 +129,7 @@ add_library(CCryptoBoringSSL STATIC
|
||||
"crypto/ex_data.cc"
|
||||
"crypto/fipsmodule/bcm.cc"
|
||||
"crypto/fipsmodule/fips_shared_support.cc"
|
||||
"crypto/fuzzer_mode.cc"
|
||||
"crypto/hpke/hpke.cc"
|
||||
"crypto/hrss/hrss.cc"
|
||||
"crypto/kyber/kyber.cc"
|
||||
@@ -150,31 +158,28 @@ add_library(CCryptoBoringSSL STATIC
|
||||
"crypto/poly1305/poly1305_arm.cc"
|
||||
"crypto/poly1305/poly1305_vec.cc"
|
||||
"crypto/pool/pool.cc"
|
||||
"crypto/rand_extra/deterministic.cc"
|
||||
"crypto/rand_extra/fork_detect.cc"
|
||||
"crypto/rand_extra/forkunsafe.cc"
|
||||
"crypto/rand_extra/getentropy.cc"
|
||||
"crypto/rand_extra/ios.cc"
|
||||
"crypto/rand_extra/passive.cc"
|
||||
"crypto/rand_extra/rand_extra.cc"
|
||||
"crypto/rand_extra/trusty.cc"
|
||||
"crypto/rand_extra/urandom.cc"
|
||||
"crypto/rand_extra/windows.cc"
|
||||
"crypto/rand/deterministic.cc"
|
||||
"crypto/rand/fork_detect.cc"
|
||||
"crypto/rand/forkunsafe.cc"
|
||||
"crypto/rand/getentropy.cc"
|
||||
"crypto/rand/ios.cc"
|
||||
"crypto/rand/passive.cc"
|
||||
"crypto/rand/rand.cc"
|
||||
"crypto/rand/trusty.cc"
|
||||
"crypto/rand/urandom.cc"
|
||||
"crypto/rand/windows.cc"
|
||||
"crypto/rc4/rc4.cc"
|
||||
"crypto/refcount.cc"
|
||||
"crypto/rsa_extra/rsa_asn1.cc"
|
||||
"crypto/rsa_extra/rsa_crypt.cc"
|
||||
"crypto/rsa_extra/rsa_extra.cc"
|
||||
"crypto/rsa_extra/rsa_print.cc"
|
||||
"crypto/rsa/rsa_asn1.cc"
|
||||
"crypto/rsa/rsa_crypt.cc"
|
||||
"crypto/rsa/rsa_extra.cc"
|
||||
"crypto/rsa/rsa_print.cc"
|
||||
"crypto/sha/sha1.cc"
|
||||
"crypto/sha/sha256.cc"
|
||||
"crypto/sha/sha512.cc"
|
||||
"crypto/siphash/siphash.cc"
|
||||
"crypto/slhdsa/fors.cc"
|
||||
"crypto/slhdsa/merkle.cc"
|
||||
"crypto/slhdsa/slhdsa.cc"
|
||||
"crypto/slhdsa/thash.cc"
|
||||
"crypto/slhdsa/wots.cc"
|
||||
"crypto/spake2plus/spake2plus.cc"
|
||||
"crypto/stack/stack.cc"
|
||||
"crypto/thread.cc"
|
||||
"crypto/thread_none.cc"
|
||||
@@ -253,6 +258,7 @@ add_library(CCryptoBoringSSL STATIC
|
||||
"crypto/x509/x_val.cc"
|
||||
"crypto/x509/x_x509.cc"
|
||||
"crypto/x509/x_x509a.cc"
|
||||
"crypto/xwing/xwing.cc"
|
||||
"gen/crypto/err_data.cc"
|
||||
"$<$<NOT:$<PLATFORM_ID:Windows>>:crypto/hrss/asm/poly_rq_mul.S>"
|
||||
"$<$<NOT:$<PLATFORM_ID:Windows>>:third_party/fiat/asm/fiat_curve25519_adx_mul.S>"
|
||||
@@ -262,7 +268,8 @@ add_library(CCryptoBoringSSL STATIC
|
||||
|
||||
if(CMAKE_SYSTEM_NAME STREQUAL Darwin AND CMAKE_SYSTEM_PROCESSOR MATCHES "amd64|x86_64")
|
||||
target_sources(CCryptoBoringSSL PRIVATE
|
||||
gen/bcm/aes-gcm-avx10-x86_64-apple.S
|
||||
gen/bcm/aes-gcm-avx2-x86_64-apple.S
|
||||
gen/bcm/aes-gcm-avx512-x86_64-apple.S
|
||||
gen/bcm/aesni-gcm-x86_64-apple.S
|
||||
gen/bcm/aesni-x86_64-apple.S
|
||||
gen/bcm/ghash-ssse3-x86_64-apple.S
|
||||
@@ -281,9 +288,10 @@ if(CMAKE_SYSTEM_NAME STREQUAL Darwin AND CMAKE_SYSTEM_PROCESSOR MATCHES "amd64|x
|
||||
gen/crypto/chacha-x86_64-apple.S
|
||||
gen/crypto/chacha20_poly1305_x86_64-apple.S
|
||||
gen/crypto/md5-x86_64-apple.S)
|
||||
elseif(CMAKE_SYSTEM_NAME MATCHES "Linux|Android|FreeBSD" AND CMAKE_SYSTEM_PROCESSOR MATCHES "amd64|x86_64")
|
||||
elseif(CMAKE_SYSTEM_NAME MATCHES "Linux|Android|FreeBSD|OpenBSD" AND CMAKE_SYSTEM_PROCESSOR MATCHES "amd64|x86_64")
|
||||
target_sources(CCryptoBoringSSL PRIVATE
|
||||
gen/bcm/aes-gcm-avx10-x86_64-linux.S
|
||||
gen/bcm/aes-gcm-avx2-x86_64-linux.S
|
||||
gen/bcm/aes-gcm-avx512-x86_64-linux.S
|
||||
gen/bcm/aesni-gcm-x86_64-linux.S
|
||||
gen/bcm/aesni-x86_64-linux.S
|
||||
gen/bcm/ghash-ssse3-x86_64-linux.S
|
||||
@@ -318,7 +326,7 @@ elseif(CMAKE_SYSTEM_NAME STREQUAL Darwin AND CMAKE_SYSTEM_PROCESSOR MATCHES "arm
|
||||
gen/bcm/vpaes-armv8-apple.S
|
||||
gen/crypto/chacha-armv8-apple.S
|
||||
gen/crypto/chacha20_poly1305_armv8-apple.S)
|
||||
elseif(CMAKE_SYSTEM_NAME MATCHES "Linux|Android|FreeBSD" AND CMAKE_SYSTEM_PROCESSOR MATCHES "arm64|aarch64")
|
||||
elseif(CMAKE_SYSTEM_NAME MATCHES "Linux|Android|FreeBSD|OpenBSD" AND CMAKE_SYSTEM_PROCESSOR MATCHES "arm64|aarch64")
|
||||
target_sources(CCryptoBoringSSL PRIVATE
|
||||
gen/bcm/aesv8-armv8-linux.S
|
||||
gen/bcm/aesv8-gcm-armv8-linux.S
|
||||
@@ -334,6 +342,27 @@ elseif(CMAKE_SYSTEM_NAME MATCHES "Linux|Android|FreeBSD" AND CMAKE_SYSTEM_PROCES
|
||||
gen/bcm/vpaes-armv8-linux.S
|
||||
gen/crypto/chacha-armv8-linux.S
|
||||
gen/crypto/chacha20_poly1305_armv8-linux.S)
|
||||
elseif(CMAKE_SYSTEM_NAME MATCHES "Windows" AND CMAKE_SYSTEM_PROCESSOR MATCHES "AMD64|amd64|x86_64")
|
||||
target_sources(CCryptoBoringSSL PRIVATE
|
||||
)
|
||||
elseif(CMAKE_SYSTEM_NAME MATCHES "Windows" AND CMAKE_SYSTEM_PROCESSOR MATCHES "ARM64|arm64|aarch64")
|
||||
target_sources(CCryptoBoringSSL PRIVATE
|
||||
gen/bcm/aesv8-armv8-win.S
|
||||
gen/bcm/aesv8-gcm-armv8-win.S
|
||||
gen/bcm/armv8-mont-win.S
|
||||
gen/bcm/bn-armv8-win.S
|
||||
gen/bcm/ghash-neon-armv8-win.S
|
||||
gen/bcm/ghashv8-armv8-win.S
|
||||
gen/bcm/p256-armv8-asm-win.S
|
||||
gen/bcm/p256_beeu-armv8-asm-win.S
|
||||
gen/bcm/sha1-armv8-win.S
|
||||
gen/bcm/sha256-armv8-win.S
|
||||
gen/bcm/sha512-armv8-win.S
|
||||
gen/bcm/vpaes-armv8-win.S
|
||||
gen/crypto/chacha-armv8-win.S
|
||||
gen/crypto/chacha20_poly1305_armv8-win.S)
|
||||
else()
|
||||
message(FATAL_ERROR "platform sources are not defined here for ${CMAKE_SYSTEM_NAME} on ${CMAKE_SYSTEM_PROCESSOR}")
|
||||
endif()
|
||||
|
||||
target_include_directories(CCryptoBoringSSL PUBLIC
|
||||
|
||||
@@ -0,0 +1,41 @@
|
||||
// Copyright 2025 The BoringSSL Authors
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// https://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
#include <assert.h>
|
||||
|
||||
#include <CCryptoBoringSSL_aes.h>
|
||||
|
||||
#include "../fipsmodule/bcm_interface.h"
|
||||
|
||||
void AES_encrypt(const uint8_t *in, uint8_t *out, const AES_KEY *key) {
|
||||
BCM_aes_encrypt(in, out, key);
|
||||
}
|
||||
|
||||
void AES_decrypt(const uint8_t *in, uint8_t *out, const AES_KEY *key) {
|
||||
BCM_aes_decrypt(in, out, key);
|
||||
}
|
||||
|
||||
int AES_set_encrypt_key(const uint8_t *key, unsigned bits, AES_KEY *aeskey) {
|
||||
if (bits != 128 && bits != 192 && bits != 256) {
|
||||
return -2;
|
||||
}
|
||||
return bcm_success(BCM_aes_set_encrypt_key(key, bits, aeskey)) ? 0 : -1;
|
||||
}
|
||||
|
||||
int AES_set_decrypt_key(const uint8_t *key, unsigned bits, AES_KEY *aeskey) {
|
||||
if (bits != 128 && bits != 192 && bits != 256) {
|
||||
return -2;
|
||||
}
|
||||
return bcm_success(BCM_aes_set_decrypt_key(key, bits, aeskey)) ? 0 : -1;
|
||||
}
|
||||
@@ -1,64 +1,23 @@
|
||||
/* 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.] */
|
||||
// Copyright 1995-2016 The OpenSSL Project Authors. All Rights Reserved.
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// https://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
#include <CCryptoBoringSSL_asn1.h>
|
||||
|
||||
#include <limits.h>
|
||||
#include <string.h>
|
||||
|
||||
#include <CCryptoBoringSSL_bytestring.h>
|
||||
#include <CCryptoBoringSSL_err.h>
|
||||
#include <CCryptoBoringSSL_mem.h>
|
||||
|
||||
@@ -136,6 +95,21 @@ int i2c_ASN1_BIT_STRING(const ASN1_BIT_STRING *a, unsigned char **pp) {
|
||||
return ret;
|
||||
}
|
||||
|
||||
int asn1_marshal_bit_string(CBB *out, const ASN1_BIT_STRING *in,
|
||||
CBS_ASN1_TAG tag) {
|
||||
int len = i2c_ASN1_BIT_STRING(in, nullptr);
|
||||
if (len <= 0) {
|
||||
return 0;
|
||||
}
|
||||
tag = tag == 0 ? CBS_ASN1_BITSTRING : tag;
|
||||
CBB child;
|
||||
uint8_t *ptr;
|
||||
return CBB_add_asn1(out, &child, tag) && //
|
||||
CBB_add_space(&child, &ptr, static_cast<size_t>(len)) && //
|
||||
i2c_ASN1_BIT_STRING(in, &ptr) == len && //
|
||||
CBB_flush(out);
|
||||
}
|
||||
|
||||
ASN1_BIT_STRING *c2i_ASN1_BIT_STRING(ASN1_BIT_STRING **a,
|
||||
const unsigned char **pp, long len) {
|
||||
ASN1_BIT_STRING *ret = NULL;
|
||||
|
||||
@@ -1,58 +1,16 @@
|
||||
/* 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.] */
|
||||
// Copyright 1995-2016 The OpenSSL Project Authors. All Rights Reserved.
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// https://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
#include <CCryptoBoringSSL_asn1.h>
|
||||
|
||||
|
||||
@@ -1,58 +1,16 @@
|
||||
/* 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.] */
|
||||
// Copyright 1995-2016 The OpenSSL Project Authors. All Rights Reserved.
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// https://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
#include <CCryptoBoringSSL_asn1.h>
|
||||
|
||||
|
||||
@@ -1,58 +1,16 @@
|
||||
/* 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.] */
|
||||
// Copyright 1995-2016 The OpenSSL Project Authors. All Rights Reserved.
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// https://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
#include <CCryptoBoringSSL_asn1.h>
|
||||
|
||||
|
||||
@@ -1,58 +1,16 @@
|
||||
/* 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.] */
|
||||
// Copyright 1995-2016 The OpenSSL Project Authors. All Rights Reserved.
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// https://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
#include <CCryptoBoringSSL_asn1.h>
|
||||
#include <CCryptoBoringSSL_bytestring.h>
|
||||
@@ -105,7 +63,8 @@ ASN1_GENERALIZEDTIME *ASN1_GENERALIZEDTIME_set(ASN1_GENERALIZEDTIME *s,
|
||||
}
|
||||
|
||||
ASN1_GENERALIZEDTIME *ASN1_GENERALIZEDTIME_adj(ASN1_GENERALIZEDTIME *s,
|
||||
int64_t posix_time, int offset_day,
|
||||
int64_t posix_time,
|
||||
int offset_day,
|
||||
long offset_sec) {
|
||||
struct tm data;
|
||||
if (!OPENSSL_posix_to_tm(posix_time, &data)) {
|
||||
@@ -127,9 +86,8 @@ ASN1_GENERALIZEDTIME *ASN1_GENERALIZEDTIME_adj(ASN1_GENERALIZEDTIME *s,
|
||||
int ret = snprintf(buf, sizeof(buf), "%04d%02d%02d%02d%02d%02dZ",
|
||||
data.tm_year + 1900, data.tm_mon + 1, data.tm_mday,
|
||||
data.tm_hour, data.tm_min, data.tm_sec);
|
||||
if (ret != (int)(sizeof(buf) - 1)) {
|
||||
abort(); // |snprintf| should neither truncate nor write fewer bytes.
|
||||
}
|
||||
// |snprintf| must write exactly 15 bytes (plus the NUL) to the buffer.
|
||||
BSSL_CHECK(ret == static_cast<int>(sizeof(buf) - 1));
|
||||
|
||||
int free_s = 0;
|
||||
if (s == NULL) {
|
||||
|
||||
@@ -1,58 +1,16 @@
|
||||
/* 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.] */
|
||||
// Copyright 1995-2016 The OpenSSL Project Authors. All Rights Reserved.
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// https://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
#include <CCryptoBoringSSL_asn1.h>
|
||||
|
||||
|
||||
@@ -1,58 +1,16 @@
|
||||
/* 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.] */
|
||||
// Copyright 1995-2016 The OpenSSL Project Authors. All Rights Reserved.
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// https://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
#include <CCryptoBoringSSL_asn1.h>
|
||||
|
||||
@@ -65,6 +23,7 @@
|
||||
#include <CCryptoBoringSSL_mem.h>
|
||||
|
||||
#include "../internal.h"
|
||||
#include "internal.h"
|
||||
|
||||
|
||||
ASN1_INTEGER *ASN1_INTEGER_dup(const ASN1_INTEGER *x) {
|
||||
@@ -114,6 +73,20 @@ static int is_all_zeros(const uint8_t *in, size_t len) {
|
||||
return 1;
|
||||
}
|
||||
|
||||
int asn1_marshal_integer(CBB *out, const ASN1_INTEGER *in, CBS_ASN1_TAG tag) {
|
||||
int len = i2c_ASN1_INTEGER(in, nullptr);
|
||||
if (len <= 0) {
|
||||
return 0;
|
||||
}
|
||||
tag = tag == 0 ? CBS_ASN1_INTEGER : tag;
|
||||
CBB child;
|
||||
uint8_t *ptr;
|
||||
return CBB_add_asn1(out, &child, tag) && //
|
||||
CBB_add_space(&child, &ptr, static_cast<size_t>(len)) && //
|
||||
i2c_ASN1_INTEGER(in, &ptr) == len && //
|
||||
CBB_flush(out);
|
||||
}
|
||||
|
||||
int i2c_ASN1_INTEGER(const ASN1_INTEGER *in, unsigned char **outp) {
|
||||
if (in == NULL) {
|
||||
return 0;
|
||||
|
||||
@@ -1,58 +1,16 @@
|
||||
/* 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.] */
|
||||
// Copyright 1999-2016 The OpenSSL Project Authors. All Rights Reserved.
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// https://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
#include <CCryptoBoringSSL_asn1.h>
|
||||
|
||||
|
||||
@@ -1,58 +1,16 @@
|
||||
/* 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.] */
|
||||
// Copyright 1995-2016 The OpenSSL Project Authors. All Rights Reserved.
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// https://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
#include <CCryptoBoringSSL_asn1.h>
|
||||
|
||||
|
||||
@@ -1,58 +1,16 @@
|
||||
/* 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.] */
|
||||
// Copyright 1995-2016 The OpenSSL Project Authors. All Rights Reserved.
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// https://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
#include <CCryptoBoringSSL_asn1.h>
|
||||
|
||||
|
||||
@@ -1,58 +1,16 @@
|
||||
/* 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.] */
|
||||
// Copyright 2000-2016 The OpenSSL Project Authors. All Rights Reserved.
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// https://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
#include <CCryptoBoringSSL_asn1.h>
|
||||
|
||||
|
||||
@@ -1,58 +1,16 @@
|
||||
/* 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.] */
|
||||
// Copyright 1999-2016 The OpenSSL Project Authors. All Rights Reserved.
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// https://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
#include <CCryptoBoringSSL_asn1.h>
|
||||
|
||||
|
||||
@@ -1,58 +1,16 @@
|
||||
/* 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.] */
|
||||
// Copyright 1999-2016 The OpenSSL Project Authors. All Rights Reserved.
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// https://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
#include <CCryptoBoringSSL_asn1.h>
|
||||
#include <CCryptoBoringSSL_posix_time.h>
|
||||
@@ -116,16 +74,13 @@ int ASN1_TIME_check(const ASN1_TIME *t) {
|
||||
}
|
||||
|
||||
// Convert an ASN1_TIME structure to GeneralizedTime
|
||||
ASN1_GENERALIZEDTIME *ASN1_TIME_to_generalizedtime(const ASN1_TIME *t,
|
||||
ASN1_GENERALIZEDTIME *ASN1_TIME_to_generalizedtime(const ASN1_TIME *in,
|
||||
ASN1_GENERALIZEDTIME **out) {
|
||||
ASN1_GENERALIZEDTIME *ret = NULL;
|
||||
char *str;
|
||||
int newlen;
|
||||
|
||||
if (!ASN1_TIME_check(t)) {
|
||||
if (!ASN1_TIME_check(in)) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
ASN1_GENERALIZEDTIME *ret = NULL;
|
||||
if (!out || !*out) {
|
||||
if (!(ret = ASN1_GENERALIZEDTIME_new())) {
|
||||
goto err;
|
||||
@@ -135,28 +90,30 @@ ASN1_GENERALIZEDTIME *ASN1_TIME_to_generalizedtime(const ASN1_TIME *t,
|
||||
}
|
||||
|
||||
// If already GeneralizedTime just copy across
|
||||
if (t->type == V_ASN1_GENERALIZEDTIME) {
|
||||
if (!ASN1_STRING_set(ret, t->data, t->length)) {
|
||||
if (in->type == V_ASN1_GENERALIZEDTIME) {
|
||||
if (!ASN1_STRING_set(ret, in->data, in->length)) {
|
||||
goto err;
|
||||
}
|
||||
goto done;
|
||||
}
|
||||
|
||||
// grow the string
|
||||
if (!ASN1_STRING_set(ret, NULL, t->length + 2)) {
|
||||
// Grow the string to accomodate the two-digit century.
|
||||
if (!ASN1_STRING_set(ret, NULL, in->length + 2)) {
|
||||
goto err;
|
||||
}
|
||||
// ASN1_STRING_set() allocated 'len + 1' bytes.
|
||||
newlen = t->length + 2 + 1;
|
||||
str = (char *)ret->data;
|
||||
// Work out the century and prepend
|
||||
if (t->data[0] >= '5') {
|
||||
OPENSSL_strlcpy(str, "19", newlen);
|
||||
} else {
|
||||
OPENSSL_strlcpy(str, "20", newlen);
|
||||
}
|
||||
|
||||
OPENSSL_strlcat(str, (char *)t->data, newlen);
|
||||
{
|
||||
char *const out_str = (char *)ret->data;
|
||||
// |ASN1_STRING_set| also allocates an additional byte for a trailing NUL.
|
||||
const size_t out_str_capacity = in->length + 2 + 1;
|
||||
// Work out the century and prepend
|
||||
if (in->data[0] >= '5') {
|
||||
OPENSSL_strlcpy(out_str, "19", out_str_capacity);
|
||||
} else {
|
||||
OPENSSL_strlcpy(out_str, "20", out_str_capacity);
|
||||
}
|
||||
OPENSSL_strlcat(out_str, (const char *)in->data, out_str_capacity);
|
||||
}
|
||||
|
||||
done:
|
||||
if (out != NULL && *out == NULL) {
|
||||
@@ -178,7 +135,7 @@ int ASN1_TIME_set_string(ASN1_TIME *s, const char *str) {
|
||||
|
||||
int ASN1_TIME_set_string_X509(ASN1_TIME *s, const char *str) {
|
||||
CBS cbs;
|
||||
CBS_init(&cbs, (const uint8_t*)str, strlen(str));
|
||||
CBS_init(&cbs, (const uint8_t *)str, strlen(str));
|
||||
int type;
|
||||
struct tm tm;
|
||||
if (CBS_parse_utc_time(&cbs, /*out_tm=*/NULL,
|
||||
@@ -234,6 +191,14 @@ int ASN1_TIME_diff(int *out_days, int *out_seconds, const ASN1_TIME *from,
|
||||
return OPENSSL_gmtime_diff(out_days, out_seconds, &tm_from, &tm_to);
|
||||
}
|
||||
|
||||
int ASN1_TIME_to_posix_nonstandard(const ASN1_TIME *t, int64_t *out_time) {
|
||||
struct tm tm;
|
||||
if (!asn1_time_to_tm(&tm, t, /*allow_timezone_offset=*/1)) {
|
||||
return 0;
|
||||
}
|
||||
return OPENSSL_tm_to_posix(&tm, out_time);
|
||||
}
|
||||
|
||||
// The functions below do *not* permissively allow the use of four digit
|
||||
// timezone offsets in UTC times, as is done elsewhere in the code. They are
|
||||
// both new API, and used internally to X509_cmp_time. This is to discourage the
|
||||
|
||||
@@ -1,58 +1,16 @@
|
||||
/* 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.] */
|
||||
// Copyright 1995-2016 The OpenSSL Project Authors. All Rights Reserved.
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// https://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
#include <CCryptoBoringSSL_asn1.h>
|
||||
|
||||
|
||||
@@ -1,58 +1,16 @@
|
||||
/* 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.] */
|
||||
// Copyright 1995-2016 The OpenSSL Project Authors. All Rights Reserved.
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// https://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
#include <CCryptoBoringSSL_asn1.h>
|
||||
#include <CCryptoBoringSSL_bytestring.h>
|
||||
@@ -107,8 +65,8 @@ ASN1_UTCTIME *ASN1_UTCTIME_set(ASN1_UTCTIME *s, int64_t posix_time) {
|
||||
return ASN1_UTCTIME_adj(s, posix_time, 0, 0);
|
||||
}
|
||||
|
||||
ASN1_UTCTIME *ASN1_UTCTIME_adj(ASN1_UTCTIME *s, int64_t posix_time, int offset_day,
|
||||
long offset_sec) {
|
||||
ASN1_UTCTIME *ASN1_UTCTIME_adj(ASN1_UTCTIME *s, int64_t posix_time,
|
||||
int offset_day, long offset_sec) {
|
||||
struct tm data;
|
||||
if (!OPENSSL_posix_to_tm(posix_time, &data)) {
|
||||
return NULL;
|
||||
@@ -128,9 +86,8 @@ ASN1_UTCTIME *ASN1_UTCTIME_adj(ASN1_UTCTIME *s, int64_t posix_time, int offset_d
|
||||
int ret = snprintf(buf, sizeof(buf), "%02d%02d%02d%02d%02d%02dZ",
|
||||
data.tm_year % 100, data.tm_mon + 1, data.tm_mday,
|
||||
data.tm_hour, data.tm_min, data.tm_sec);
|
||||
if (ret != (int)(sizeof(buf) - 1)) {
|
||||
abort(); // |snprintf| should neither truncate nor write fewer bytes.
|
||||
}
|
||||
// |snprintf| must write exactly 15 bytes (plus the NUL) to the buffer.
|
||||
BSSL_CHECK(ret == static_cast<int>(sizeof(buf) - 1));
|
||||
|
||||
int free_s = 0;
|
||||
if (s == NULL) {
|
||||
@@ -150,34 +107,3 @@ ASN1_UTCTIME *ASN1_UTCTIME_adj(ASN1_UTCTIME *s, int64_t posix_time, int offset_d
|
||||
s->type = V_ASN1_UTCTIME;
|
||||
return s;
|
||||
}
|
||||
|
||||
int ASN1_UTCTIME_cmp_time_t(const ASN1_UTCTIME *s, time_t t) {
|
||||
struct tm stm, ttm;
|
||||
int day, sec;
|
||||
|
||||
if (!asn1_utctime_to_tm(&stm, s, /*allow_timezone_offset=*/1)) {
|
||||
return -2;
|
||||
}
|
||||
|
||||
if (!OPENSSL_posix_to_tm(t, &ttm)) {
|
||||
return -2;
|
||||
}
|
||||
|
||||
if (!OPENSSL_gmtime_diff(&day, &sec, &ttm, &stm)) {
|
||||
return -2;
|
||||
}
|
||||
|
||||
if (day > 0) {
|
||||
return 1;
|
||||
}
|
||||
if (day < 0) {
|
||||
return -1;
|
||||
}
|
||||
if (sec > 0) {
|
||||
return 1;
|
||||
}
|
||||
if (sec < 0) {
|
||||
return -1;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
@@ -1,58 +1,16 @@
|
||||
/* 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.] */
|
||||
// Copyright 1995-2016 The OpenSSL Project Authors. All Rights Reserved.
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// https://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
#include <CCryptoBoringSSL_asn1.h>
|
||||
|
||||
|
||||
@@ -1,58 +1,16 @@
|
||||
/* 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.] */
|
||||
// Copyright 1995-2016 The OpenSSL Project Authors. All Rights Reserved.
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// https://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
#include <CCryptoBoringSSL_asn1.h>
|
||||
|
||||
|
||||
@@ -1,58 +1,16 @@
|
||||
/* 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.] */
|
||||
// Copyright 1999-2016 The OpenSSL Project Authors. All Rights Reserved.
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// https://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
#include <CCryptoBoringSSL_asn1.h>
|
||||
|
||||
|
||||
@@ -1,58 +1,16 @@
|
||||
/* 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.] */
|
||||
// Copyright 1995-2016 The OpenSSL Project Authors. All Rights Reserved.
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// https://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
#include <CCryptoBoringSSL_asn1.h>
|
||||
|
||||
|
||||
@@ -1,58 +1,16 @@
|
||||
/* 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.] */
|
||||
// Copyright 1995-2016 The OpenSSL Project Authors. All Rights Reserved.
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// https://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
#include <CCryptoBoringSSL_asn1.h>
|
||||
|
||||
|
||||
@@ -1,63 +1,19 @@
|
||||
/*
|
||||
* Written by Dr Stephen N Henson (steve@openssl.org) for the OpenSSL project
|
||||
* 2006.
|
||||
*/
|
||||
/* ====================================================================
|
||||
* Copyright (c) 2006 The OpenSSL Project. All rights reserved.
|
||||
*
|
||||
* 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 above 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 acknowledgment:
|
||||
* "This product includes software developed by the OpenSSL Project
|
||||
* for use in the OpenSSL Toolkit. (http://www.OpenSSL.org/)"
|
||||
*
|
||||
* 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
|
||||
* endorse or promote products derived from this software without
|
||||
* prior written permission. For written permission, please contact
|
||||
* licensing@OpenSSL.org.
|
||||
*
|
||||
* 5. Products derived from this software may not be called "OpenSSL"
|
||||
* nor may "OpenSSL" appear in their names without prior written
|
||||
* permission of the OpenSSL Project.
|
||||
*
|
||||
* 6. Redistributions of any form whatsoever must retain the following
|
||||
* acknowledgment:
|
||||
* "This product includes software developed by the OpenSSL Project
|
||||
* for use in the OpenSSL Toolkit (http://www.OpenSSL.org/)"
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
|
||||
* EXPRESSED 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 OpenSSL PROJECT OR
|
||||
* ITS 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.
|
||||
* ====================================================================
|
||||
*
|
||||
* This product includes cryptographic software written by Eric Young
|
||||
* (eay@cryptsoft.com). This product includes software written by Tim
|
||||
* Hudson (tjh@cryptsoft.com).
|
||||
*
|
||||
*/
|
||||
// Copyright 2005-2016 The OpenSSL Project Authors. All Rights Reserved.
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// https://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
#ifndef OPENSSL_HEADER_ASN1_INTERNAL_H
|
||||
#define OPENSSL_HEADER_ASN1_INTERNAL_H
|
||||
#ifndef OPENSSL_HEADER_CRYPTO_ASN1_INTERNAL_H
|
||||
#define OPENSSL_HEADER_CRYPTO_ASN1_INTERNAL_H
|
||||
|
||||
#include <time.h>
|
||||
|
||||
@@ -224,6 +180,17 @@ int asn1_is_printable(uint32_t value);
|
||||
int asn1_bit_string_length(const ASN1_BIT_STRING *str,
|
||||
uint8_t *out_padding_bits);
|
||||
|
||||
// asn1_marshal_bit_string marshals |in| as a DER-encoded, ASN.1 BIT STRING and
|
||||
// writes the result to |out|. It returns one on success and zero on error. If
|
||||
// |tag| is non-zero, the tag is replaced with |tag|.
|
||||
int asn1_marshal_bit_string(CBB *out, const ASN1_BIT_STRING *in,
|
||||
CBS_ASN1_TAG tag);
|
||||
|
||||
// asn1_marshal_integer marshals |in| as a DER-encoded, ASN.1 INTEGER and writes
|
||||
// the result to |out|. It returns one on success and zero on error. If |tag| is
|
||||
// non-zero, the tag is replaced with |tag|.
|
||||
int asn1_marshal_integer(CBB *out, const ASN1_INTEGER *in, CBS_ASN1_TAG tag);
|
||||
|
||||
typedef struct {
|
||||
int nid;
|
||||
long minsize;
|
||||
@@ -258,9 +225,14 @@ typedef struct ASN1_EXTERN_FUNCS_st {
|
||||
ASN1_ex_i2d *asn1_ex_i2d;
|
||||
} ASN1_EXTERN_FUNCS;
|
||||
|
||||
// ASN1_ANY_AS_STRING is an |ASN1_ITEM| with ASN.1 type ANY and C type
|
||||
// |ASN1_STRING*|. Types which are not represented with |ASN1_STRING|, such as
|
||||
// |ASN1_OBJECT|, are represented with type |V_ASN1_OTHER|.
|
||||
DECLARE_ASN1_ITEM(ASN1_ANY_AS_STRING)
|
||||
|
||||
|
||||
#if defined(__cplusplus)
|
||||
} // extern C
|
||||
#endif
|
||||
|
||||
#endif // OPENSSL_HEADER_ASN1_INTERNAL_H
|
||||
#endif // OPENSSL_HEADER_CRYPTO_ASN1_INTERNAL_H
|
||||
@@ -1,16 +1,16 @@
|
||||
/* Copyright 2022 The BoringSSL Authors
|
||||
*
|
||||
* 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. */
|
||||
// Copyright 2022 The BoringSSL Authors
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// https://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
// Time conversion to/from POSIX time_t and struct tm, with no support
|
||||
// for time zones other than UTC
|
||||
|
||||
@@ -1,58 +1,16 @@
|
||||
/* 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.] */
|
||||
// Copyright 2000-2016 The OpenSSL Project Authors. All Rights Reserved.
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// https://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
#include <CCryptoBoringSSL_asn1.h>
|
||||
#include <CCryptoBoringSSL_asn1t.h>
|
||||
@@ -94,46 +52,43 @@ static int asn1_item_ex_d2i(ASN1_VALUE **pval, const unsigned char **in,
|
||||
long len, const ASN1_ITEM *it, int tag, int aclass,
|
||||
char opt, CRYPTO_BUFFER *buf, int depth);
|
||||
|
||||
// Table to convert tags to bit values, used for MSTRING type
|
||||
static const unsigned long tag2bit[31] = {
|
||||
0, // (reserved)
|
||||
0, // BOOLEAN
|
||||
0, // INTEGER
|
||||
B_ASN1_BIT_STRING,
|
||||
B_ASN1_OCTET_STRING,
|
||||
0, // NULL
|
||||
0, // OBJECT IDENTIFIER
|
||||
B_ASN1_UNKNOWN, // ObjectDescriptor
|
||||
B_ASN1_UNKNOWN, // EXTERNAL
|
||||
B_ASN1_UNKNOWN, // REAL
|
||||
B_ASN1_UNKNOWN, // ENUMERATED
|
||||
B_ASN1_UNKNOWN, // EMBEDDED PDV
|
||||
B_ASN1_UTF8STRING,
|
||||
B_ASN1_UNKNOWN, // RELATIVE-OID
|
||||
B_ASN1_UNKNOWN, // TIME
|
||||
B_ASN1_UNKNOWN, // (reserved)
|
||||
B_ASN1_SEQUENCE,
|
||||
0, // SET
|
||||
B_ASN1_NUMERICSTRING,
|
||||
B_ASN1_PRINTABLESTRING,
|
||||
B_ASN1_T61STRING,
|
||||
B_ASN1_VIDEOTEXSTRING,
|
||||
B_ASN1_IA5STRING,
|
||||
B_ASN1_UTCTIME,
|
||||
B_ASN1_GENERALIZEDTIME,
|
||||
B_ASN1_GRAPHICSTRING,
|
||||
B_ASN1_ISO64STRING,
|
||||
B_ASN1_GENERALSTRING,
|
||||
B_ASN1_UNIVERSALSTRING,
|
||||
B_ASN1_UNKNOWN, // CHARACTER STRING
|
||||
B_ASN1_BMPSTRING,
|
||||
};
|
||||
|
||||
unsigned long ASN1_tag2bit(int tag) {
|
||||
if (tag < 0 || tag > 30) {
|
||||
return 0;
|
||||
switch (tag) {
|
||||
case V_ASN1_BIT_STRING:
|
||||
return B_ASN1_BIT_STRING;
|
||||
case V_ASN1_OCTET_STRING:
|
||||
return B_ASN1_OCTET_STRING;
|
||||
case V_ASN1_UTF8STRING:
|
||||
return B_ASN1_UTF8STRING;
|
||||
case V_ASN1_SEQUENCE:
|
||||
return B_ASN1_SEQUENCE;
|
||||
case V_ASN1_NUMERICSTRING:
|
||||
return B_ASN1_NUMERICSTRING;
|
||||
case V_ASN1_PRINTABLESTRING:
|
||||
return B_ASN1_PRINTABLESTRING;
|
||||
case V_ASN1_T61STRING:
|
||||
return B_ASN1_T61STRING;
|
||||
case V_ASN1_VIDEOTEXSTRING:
|
||||
return B_ASN1_VIDEOTEXSTRING;
|
||||
case V_ASN1_IA5STRING:
|
||||
return B_ASN1_IA5STRING;
|
||||
case V_ASN1_UTCTIME:
|
||||
return B_ASN1_UTCTIME;
|
||||
case V_ASN1_GENERALIZEDTIME:
|
||||
return B_ASN1_GENERALIZEDTIME;
|
||||
case V_ASN1_GRAPHICSTRING:
|
||||
return B_ASN1_GRAPHICSTRING;
|
||||
case V_ASN1_ISO64STRING:
|
||||
return B_ASN1_ISO64STRING;
|
||||
case V_ASN1_GENERALSTRING:
|
||||
return B_ASN1_GENERALSTRING;
|
||||
case V_ASN1_UNIVERSALSTRING:
|
||||
return B_ASN1_UNIVERSALSTRING;
|
||||
case V_ASN1_BMPSTRING:
|
||||
return B_ASN1_BMPSTRING;
|
||||
default:
|
||||
return 0;
|
||||
}
|
||||
return tag2bit[tag];
|
||||
}
|
||||
|
||||
static int is_supported_universal_type(int tag, int aclass) {
|
||||
@@ -671,6 +626,7 @@ static int asn1_d2i_ex_primitive(ASN1_VALUE **pval, const unsigned char **in,
|
||||
return 0; // Should never happen
|
||||
}
|
||||
|
||||
assert(it->itype == ASN1_ITYPE_PRIMITIVE || it->itype == ASN1_ITYPE_MSTRING);
|
||||
if (it->itype == ASN1_ITYPE_MSTRING) {
|
||||
utype = tag;
|
||||
tag = -1;
|
||||
@@ -678,7 +634,7 @@ static int asn1_d2i_ex_primitive(ASN1_VALUE **pval, const unsigned char **in,
|
||||
utype = it->utype;
|
||||
}
|
||||
|
||||
if (utype == V_ASN1_ANY) {
|
||||
if (utype == V_ASN1_ANY || utype == V_ASN1_ANY_AS_STRING) {
|
||||
// If type is ANY need to figure out type from tag
|
||||
unsigned char oclass;
|
||||
if (tag >= 0) {
|
||||
@@ -689,8 +645,9 @@ static int asn1_d2i_ex_primitive(ASN1_VALUE **pval, const unsigned char **in,
|
||||
OPENSSL_PUT_ERROR(ASN1, ASN1_R_ILLEGAL_OPTIONAL_ANY);
|
||||
return 0;
|
||||
}
|
||||
const int is_string = utype == V_ASN1_ANY_AS_STRING;
|
||||
p = *in;
|
||||
ret = asn1_check_tlen(NULL, &utype, &oclass, NULL, &p, inlen, -1, 0, 0);
|
||||
ret = asn1_check_tlen(&plen, &utype, &oclass, &cst, &p, inlen, -1, 0, 0);
|
||||
if (!ret) {
|
||||
OPENSSL_PUT_ERROR(ASN1, ASN1_R_NESTED_ASN1_ERROR);
|
||||
return 0;
|
||||
@@ -698,6 +655,37 @@ static int asn1_d2i_ex_primitive(ASN1_VALUE **pval, const unsigned char **in,
|
||||
if (!is_supported_universal_type(utype, oclass)) {
|
||||
utype = V_ASN1_OTHER;
|
||||
}
|
||||
// These three types are not represented as |ASN1_STRING|, so they must be
|
||||
// parsed separately and then treated as an opaque |V_ASN1_OTHER|.
|
||||
if (is_string && (utype == V_ASN1_OBJECT || utype == V_ASN1_NULL ||
|
||||
utype == V_ASN1_BOOLEAN)) {
|
||||
if (cst) {
|
||||
OPENSSL_PUT_ERROR(ASN1, ASN1_R_TYPE_NOT_PRIMITIVE);
|
||||
return 0;
|
||||
}
|
||||
CBS cbs;
|
||||
CBS_init(&cbs, p, plen);
|
||||
if (utype == V_ASN1_OBJECT && !CBS_is_valid_asn1_oid(&cbs)) {
|
||||
OPENSSL_PUT_ERROR(ASN1, ASN1_R_INVALID_OBJECT_ENCODING);
|
||||
return 0;
|
||||
}
|
||||
if (utype == V_ASN1_NULL && CBS_len(&cbs) != 0) {
|
||||
OPENSSL_PUT_ERROR(ASN1, ASN1_R_NULL_IS_WRONG_LENGTH);
|
||||
return 0;
|
||||
}
|
||||
if (utype == V_ASN1_BOOLEAN) {
|
||||
if (CBS_len(&cbs) != 1) {
|
||||
OPENSSL_PUT_ERROR(ASN1, ASN1_R_BOOLEAN_IS_WRONG_LENGTH);
|
||||
return 0;
|
||||
}
|
||||
uint8_t v = CBS_data(&cbs)[0];
|
||||
if (v != 0 && v != 0xff) {
|
||||
OPENSSL_PUT_ERROR(ASN1, ASN1_R_DECODE_ERROR);
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
utype = V_ASN1_OTHER;
|
||||
}
|
||||
}
|
||||
if (tag == -1) {
|
||||
tag = utype;
|
||||
@@ -780,6 +768,10 @@ static int asn1_ex_c2i(ASN1_VALUE **pval, const unsigned char *cont, long len,
|
||||
opval = pval;
|
||||
pval = &typ->value.asn1_value;
|
||||
}
|
||||
|
||||
// If implementing a type that is not represented in |ASN1_STRING|, the
|
||||
// |V_ASN1_ANY_AS_STRING| logic must be modified to redirect it to
|
||||
// |V_ASN1_OTHER|.
|
||||
switch (utype) {
|
||||
case V_ASN1_OBJECT:
|
||||
if (!c2i_ASN1_OBJECT((ASN1_OBJECT **)pval, &cont, len)) {
|
||||
@@ -838,14 +830,7 @@ static int asn1_ex_c2i(ASN1_VALUE **pval, const unsigned char *cont, long len,
|
||||
case V_ASN1_UTF8STRING:
|
||||
case V_ASN1_OTHER:
|
||||
case V_ASN1_SET:
|
||||
case V_ASN1_SEQUENCE:
|
||||
// TODO(crbug.com/boringssl/412): This default case should be removed, now
|
||||
// that we've resolved https://crbug.com/boringssl/561. However, it is still
|
||||
// needed to support some edge cases in |ASN1_PRINTABLE|. |ASN1_PRINTABLE|
|
||||
// broadly doesn't tolerate unrecognized universal tags, but except for
|
||||
// eight values that map to |B_ASN1_UNKNOWN| instead of zero. See the
|
||||
// X509Test.NameAttributeValues test.
|
||||
default: {
|
||||
case V_ASN1_SEQUENCE: {
|
||||
CBS cbs;
|
||||
CBS_init(&cbs, cont, (size_t)len);
|
||||
if (utype == V_ASN1_BMPSTRING) {
|
||||
@@ -908,6 +893,10 @@ static int asn1_ex_c2i(ASN1_VALUE **pval, const unsigned char *cont, long len,
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
default:
|
||||
OPENSSL_PUT_ERROR(ASN1, ASN1_R_BAD_TEMPLATE);
|
||||
goto err;
|
||||
}
|
||||
// If ASN1_ANY and NULL type fix up value
|
||||
if (typ && (utype == V_ASN1_NULL)) {
|
||||
|
||||
@@ -1,58 +1,16 @@
|
||||
/* 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.] */
|
||||
// Copyright 2000-2016 The OpenSSL Project Authors. All Rights Reserved.
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// https://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
#include <CCryptoBoringSSL_asn1.h>
|
||||
|
||||
@@ -569,21 +527,23 @@ static int asn1_ex_i2c(ASN1_VALUE **pval, unsigned char *cout, int *out_omit,
|
||||
unsigned char c;
|
||||
int len;
|
||||
|
||||
assert(it->itype == ASN1_ITYPE_PRIMITIVE || it->itype == ASN1_ITYPE_MSTRING);
|
||||
// Historically, |it->funcs| for primitive types contained an
|
||||
// |ASN1_PRIMITIVE_FUNCS| table of callbacks.
|
||||
assert(it->funcs == NULL);
|
||||
|
||||
*out_omit = 0;
|
||||
|
||||
// Should type be omitted?
|
||||
if ((it->itype != ASN1_ITYPE_PRIMITIVE) || (it->utype != V_ASN1_BOOLEAN)) {
|
||||
// Handle omitted optional values for all but BOOLEAN, which uses a
|
||||
// non-pointer representation.
|
||||
if (it->itype != ASN1_ITYPE_PRIMITIVE || it->utype != V_ASN1_BOOLEAN) {
|
||||
if (!*pval) {
|
||||
*out_omit = 1;
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
if (it->itype == ASN1_ITYPE_MSTRING) {
|
||||
if (it->itype == ASN1_ITYPE_MSTRING || it->utype == V_ASN1_ANY_AS_STRING) {
|
||||
// If MSTRING type set the underlying type
|
||||
strtmp = (ASN1_STRING *)*pval;
|
||||
utype = strtmp->type;
|
||||
@@ -592,15 +552,8 @@ static int asn1_ex_i2c(ASN1_VALUE **pval, unsigned char *cout, int *out_omit,
|
||||
OPENSSL_PUT_ERROR(ASN1, ASN1_R_WRONG_TYPE);
|
||||
return -1;
|
||||
}
|
||||
// Negative INTEGER and ENUMERATED values use |ASN1_STRING| type values
|
||||
// that do not match their corresponding utype values. INTEGERs cannot
|
||||
// participate in MSTRING types, but ENUMERATEDs can.
|
||||
//
|
||||
// TODO(davidben): Is this a bug? Although arguably one of the MSTRING
|
||||
// types should contain more values, rather than less. See
|
||||
// https://crbug.com/boringssl/412. But it is not possible to fit all
|
||||
// possible ANY values into an |ASN1_STRING|, so matching the spec here
|
||||
// is somewhat hopeless.
|
||||
// Negative INTEGER and ENUMERATED values use |ASN1_STRING| type values that
|
||||
// do not match their corresponding utype values.
|
||||
if (utype == V_ASN1_NEG_INTEGER) {
|
||||
utype = V_ASN1_INTEGER;
|
||||
} else if (utype == V_ASN1_NEG_ENUMERATED) {
|
||||
@@ -691,18 +644,15 @@ static int asn1_ex_i2c(ASN1_VALUE **pval, unsigned char *cout, int *out_omit,
|
||||
case V_ASN1_SET:
|
||||
// This is not a valid |ASN1_ITEM| type, but it appears in |ASN1_TYPE|.
|
||||
case V_ASN1_OTHER:
|
||||
// TODO(crbug.com/boringssl/412): This default case should be removed, now
|
||||
// that we've resolved https://crbug.com/boringssl/561. However, it is still
|
||||
// needed to support some edge cases in |ASN1_PRINTABLE|. |ASN1_PRINTABLE|
|
||||
// broadly doesn't tolerate unrecognized universal tags, but except for
|
||||
// eight values that map to |B_ASN1_UNKNOWN| instead of zero. See the
|
||||
// X509Test.NameAttributeValues test.
|
||||
default:
|
||||
// All based on ASN1_STRING and handled the same
|
||||
strtmp = (ASN1_STRING *)*pval;
|
||||
cont = strtmp->data;
|
||||
len = strtmp->length;
|
||||
break;
|
||||
|
||||
default:
|
||||
OPENSSL_PUT_ERROR(ASN1, ASN1_R_BAD_TEMPLATE);
|
||||
return -1;
|
||||
}
|
||||
if (cout && len) {
|
||||
OPENSSL_memcpy(cout, cont, len);
|
||||
|
||||
@@ -1,58 +1,16 @@
|
||||
/* 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.] */
|
||||
// Copyright 2000-2016 The OpenSSL Project Authors. All Rights Reserved.
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// https://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
#include <CCryptoBoringSSL_asn1.h>
|
||||
|
||||
|
||||
@@ -1,58 +1,16 @@
|
||||
/* 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.] */
|
||||
// Copyright 2000-2016 The OpenSSL Project Authors. All Rights Reserved.
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// https://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
#include <CCryptoBoringSSL_asn1.h>
|
||||
|
||||
|
||||
@@ -1,64 +1,23 @@
|
||||
/* 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.] */
|
||||
// Copyright 2000-2016 The OpenSSL Project Authors. All Rights Reserved.
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// https://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
#include <CCryptoBoringSSL_asn1.h>
|
||||
|
||||
#include <CCryptoBoringSSL_asn1t.h>
|
||||
|
||||
// Declarations for string types
|
||||
#include "internal.h"
|
||||
|
||||
|
||||
#define IMPLEMENT_ASN1_STRING_FUNCTIONS(sname) \
|
||||
IMPLEMENT_ASN1_TYPE(sname) \
|
||||
@@ -87,18 +46,13 @@ IMPLEMENT_ASN1_FUNCTIONS_const(ASN1_NULL)
|
||||
IMPLEMENT_ASN1_TYPE(ASN1_OBJECT)
|
||||
|
||||
IMPLEMENT_ASN1_TYPE(ASN1_ANY)
|
||||
IMPLEMENT_ASN1_TYPE(ASN1_ANY_AS_STRING)
|
||||
|
||||
// Just swallow an ASN1_SEQUENCE in an ASN1_STRING
|
||||
IMPLEMENT_ASN1_TYPE(ASN1_SEQUENCE)
|
||||
|
||||
IMPLEMENT_ASN1_FUNCTIONS_const_fname(ASN1_TYPE, ASN1_ANY, ASN1_TYPE)
|
||||
|
||||
// Multistring types
|
||||
|
||||
IMPLEMENT_ASN1_MSTRING(ASN1_PRINTABLE, B_ASN1_PRINTABLE)
|
||||
IMPLEMENT_ASN1_FUNCTIONS_const_fname(ASN1_STRING, ASN1_PRINTABLE,
|
||||
ASN1_PRINTABLE)
|
||||
|
||||
IMPLEMENT_ASN1_MSTRING(DISPLAYTEXT, B_ASN1_DISPLAYTEXT)
|
||||
IMPLEMENT_ASN1_FUNCTIONS_const_fname(ASN1_STRING, DISPLAYTEXT, DISPLAYTEXT)
|
||||
|
||||
|
||||
@@ -1,58 +1,16 @@
|
||||
/* 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.] */
|
||||
// Copyright 2000-2016 The OpenSSL Project Authors. All Rights Reserved.
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// https://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
#include <CCryptoBoringSSL_asn1.h>
|
||||
|
||||
@@ -64,7 +22,6 @@
|
||||
#include <CCryptoBoringSSL_mem.h>
|
||||
#include <CCryptoBoringSSL_obj.h>
|
||||
#include <CCryptoBoringSSL_pool.h>
|
||||
#include <CCryptoBoringSSL_thread.h>
|
||||
|
||||
#include "../internal.h"
|
||||
#include "internal.h"
|
||||
|
||||
@@ -1,58 +1,16 @@
|
||||
/* 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.] */
|
||||
// Copyright 1995-2016 The OpenSSL Project Authors. All Rights Reserved.
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// https://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
#include <CCryptoBoringSSL_base64.h>
|
||||
|
||||
|
||||
@@ -1,16 +1,16 @@
|
||||
/* Copyright 2024 The BoringSSL Authors
|
||||
*
|
||||
* 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. */
|
||||
// Copyright 2024 The BoringSSL Authors
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// https://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
#ifndef OPENSSL_HEADER_CRYPTO_BCM_SUPPORT_H
|
||||
#define OPENSSL_HEADER_CRYPTO_BCM_SUPPORT_H
|
||||
@@ -25,41 +25,6 @@
|
||||
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
|
||||
|
||||
@@ -1,58 +1,16 @@
|
||||
/* 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.] */
|
||||
// Copyright 1995-2016 The OpenSSL Project Authors. All Rights Reserved.
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// https://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
#include <CCryptoBoringSSL_bio.h>
|
||||
|
||||
@@ -64,9 +22,9 @@
|
||||
#include <CCryptoBoringSSL_asn1.h>
|
||||
#include <CCryptoBoringSSL_err.h>
|
||||
#include <CCryptoBoringSSL_mem.h>
|
||||
#include <CCryptoBoringSSL_thread.h>
|
||||
|
||||
#include "../internal.h"
|
||||
#include "internal.h"
|
||||
|
||||
|
||||
static CRYPTO_EX_DATA_CLASS g_ex_data_class =
|
||||
@@ -105,7 +63,7 @@ int BIO_free(BIO *bio) {
|
||||
bio->method->destroy(bio);
|
||||
}
|
||||
|
||||
CRYPTO_free_ex_data(&g_ex_data_class, bio, &bio->ex_data);
|
||||
CRYPTO_free_ex_data(&g_ex_data_class, &bio->ex_data);
|
||||
OPENSSL_free(bio);
|
||||
}
|
||||
return 1;
|
||||
@@ -286,7 +244,7 @@ void BIO_copy_next_retry(BIO *bio) {
|
||||
bio->retry_reason = bio->next_bio->retry_reason;
|
||||
}
|
||||
|
||||
long BIO_callback_ctrl(BIO *bio, int cmd, bio_info_cb fp) {
|
||||
long BIO_callback_ctrl(BIO *bio, int cmd, BIO_info_cb *fp) {
|
||||
if (bio == NULL) {
|
||||
return 0;
|
||||
}
|
||||
@@ -667,6 +625,13 @@ int BIO_meth_set_ctrl(BIO_METHOD *method,
|
||||
return 1;
|
||||
}
|
||||
|
||||
int BIO_meth_set_callback_ctrl(BIO_METHOD *method,
|
||||
long (*callback_ctrl_func)(BIO *, int,
|
||||
BIO_info_cb *)) {
|
||||
method->callback_ctrl = callback_ctrl_func;
|
||||
return 1;
|
||||
}
|
||||
|
||||
void BIO_set_data(BIO *bio, void *ptr) { bio->ptr = ptr; }
|
||||
|
||||
void *BIO_get_data(BIO *bio) { return bio->ptr; }
|
||||
|
||||
@@ -1,58 +1,16 @@
|
||||
/* 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.] */
|
||||
// Copyright 1995-2016 The OpenSSL Project Authors. All Rights Reserved.
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// https://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
#include <CCryptoBoringSSL_bio.h>
|
||||
|
||||
@@ -64,6 +22,7 @@
|
||||
#include <CCryptoBoringSSL_mem.h>
|
||||
|
||||
#include "../internal.h"
|
||||
#include "internal.h"
|
||||
|
||||
|
||||
BIO *BIO_new_mem_buf(const void *buf, ossl_ssize_t len) {
|
||||
@@ -206,10 +165,7 @@ static int mem_gets(BIO *bio, char *buf, int size) {
|
||||
}
|
||||
|
||||
static long mem_ctrl(BIO *bio, int cmd, long num, void *ptr) {
|
||||
long ret = 1;
|
||||
|
||||
BUF_MEM *b = (BUF_MEM *)bio->ptr;
|
||||
|
||||
BUF_MEM *b = static_cast<BUF_MEM *>(bio->ptr);
|
||||
switch (cmd) {
|
||||
case BIO_CTRL_RESET:
|
||||
if (b->data != NULL) {
|
||||
@@ -222,60 +178,52 @@ static long mem_ctrl(BIO *bio, int cmd, long num, void *ptr) {
|
||||
b->length = 0;
|
||||
}
|
||||
}
|
||||
break;
|
||||
return 1;
|
||||
case BIO_CTRL_EOF:
|
||||
ret = (long)(b->length == 0);
|
||||
break;
|
||||
return b->length == 0;
|
||||
case BIO_C_SET_BUF_MEM_EOF_RETURN:
|
||||
bio->num = (int)num;
|
||||
break;
|
||||
bio->num = static_cast<int>(num);
|
||||
return 1;
|
||||
case BIO_CTRL_INFO:
|
||||
ret = (long)b->length;
|
||||
if (ptr != NULL) {
|
||||
char **pptr = reinterpret_cast<char **>(ptr);
|
||||
*pptr = b->data;
|
||||
if (ptr != nullptr) {
|
||||
char **out = reinterpret_cast<char **>(ptr);
|
||||
*out = b->data;
|
||||
}
|
||||
break;
|
||||
// This API can overflow on 64-bit Windows, where |long| is smaller than
|
||||
// |ptrdiff_t|. |BIO_mem_contents| is the overflow-safe API.
|
||||
return static_cast<long>(b->length);
|
||||
case BIO_C_SET_BUF_MEM:
|
||||
mem_free(bio);
|
||||
bio->shutdown = (int)num;
|
||||
bio->shutdown = static_cast<int>(num);
|
||||
bio->ptr = ptr;
|
||||
break;
|
||||
return 1;
|
||||
case BIO_C_GET_BUF_MEM_PTR:
|
||||
if (ptr != NULL) {
|
||||
BUF_MEM **pptr = reinterpret_cast<BUF_MEM **>(ptr);
|
||||
*pptr = b;
|
||||
BUF_MEM **out = reinterpret_cast<BUF_MEM **>(ptr);
|
||||
*out = b;
|
||||
}
|
||||
break;
|
||||
return 1;
|
||||
case BIO_CTRL_GET_CLOSE:
|
||||
ret = (long)bio->shutdown;
|
||||
break;
|
||||
return bio->shutdown;
|
||||
case BIO_CTRL_SET_CLOSE:
|
||||
bio->shutdown = (int)num;
|
||||
break;
|
||||
|
||||
bio->shutdown = static_cast<int>(num);
|
||||
return 1;
|
||||
case BIO_CTRL_WPENDING:
|
||||
ret = 0L;
|
||||
break;
|
||||
return 0;
|
||||
case BIO_CTRL_PENDING:
|
||||
ret = (long)b->length;
|
||||
break;
|
||||
// TODO(crbug.com/412584975): This can overflow on 64-bit Windows.
|
||||
return static_cast<long>(b->length);
|
||||
case BIO_CTRL_FLUSH:
|
||||
ret = 1;
|
||||
break;
|
||||
return 1;
|
||||
default:
|
||||
ret = 0;
|
||||
break;
|
||||
return 0;
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
static const BIO_METHOD mem_method = {
|
||||
BIO_TYPE_MEM, "memory buffer",
|
||||
mem_write, mem_read,
|
||||
NULL /* puts */, mem_gets,
|
||||
mem_ctrl, mem_new,
|
||||
mem_free, NULL /* callback_ctrl */,
|
||||
BIO_TYPE_MEM, "memory buffer", mem_write,
|
||||
mem_read, mem_gets, mem_ctrl,
|
||||
mem_new, mem_free, /*callback_ctrl=*/nullptr,
|
||||
};
|
||||
|
||||
const BIO_METHOD *BIO_s_mem(void) { return &mem_method; }
|
||||
|
||||
@@ -1,58 +1,16 @@
|
||||
/* 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.] */
|
||||
// Copyright 1995-2016 The OpenSSL Project Authors. All Rights Reserved.
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// https://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
#include <CCryptoBoringSSL_bio.h>
|
||||
|
||||
@@ -68,10 +26,8 @@
|
||||
#include <sys/socket.h>
|
||||
#include <unistd.h>
|
||||
#else
|
||||
OPENSSL_MSVC_PRAGMA(warning(push, 3))
|
||||
#include <winsock2.h>
|
||||
#include <ws2tcpip.h>
|
||||
OPENSSL_MSVC_PRAGMA(warning(pop))
|
||||
#endif
|
||||
|
||||
#include <CCryptoBoringSSL_err.h>
|
||||
@@ -87,6 +43,7 @@ enum {
|
||||
BIO_CONN_S_OK,
|
||||
};
|
||||
|
||||
namespace {
|
||||
typedef struct bio_connect_st {
|
||||
int state;
|
||||
|
||||
@@ -105,8 +62,9 @@ typedef struct bio_connect_st {
|
||||
// info_callback is called when the connection is initially made
|
||||
// callback(BIO,state,ret); The callback should return 'ret', state is for
|
||||
// compatibility with the SSL info_callback.
|
||||
int (*info_callback)(const BIO *bio, int state, int ret);
|
||||
int (*info_callback)(BIO *bio, int state, int ret);
|
||||
} BIO_CONNECT;
|
||||
} // namespace
|
||||
|
||||
#if !defined(OPENSSL_WINDOWS)
|
||||
static int closesocket(int sock) { return close(sock); }
|
||||
@@ -166,7 +124,7 @@ static int split_host_and_port(char **out_host, char **out_port,
|
||||
|
||||
static int conn_state(BIO *bio, BIO_CONNECT *c) {
|
||||
int ret = -1, i;
|
||||
int (*cb)(const BIO *, int, int) = NULL;
|
||||
int (*cb)(BIO *, int, int) = NULL;
|
||||
|
||||
if (c->info_callback != NULL) {
|
||||
cb = c->info_callback;
|
||||
@@ -305,10 +263,9 @@ static BIO_CONNECT *BIO_CONNECT_new(void) {
|
||||
}
|
||||
|
||||
static void BIO_CONNECT_free(BIO_CONNECT *c) {
|
||||
if (c == NULL) {
|
||||
if (c == nullptr) {
|
||||
return;
|
||||
}
|
||||
|
||||
OPENSSL_free(c->param_hostname);
|
||||
OPENSSL_free(c->param_port);
|
||||
OPENSSL_free(c);
|
||||
@@ -396,113 +353,81 @@ static int conn_write(BIO *bio, const char *in, int in_len) {
|
||||
}
|
||||
|
||||
static long conn_ctrl(BIO *bio, int cmd, long num, void *ptr) {
|
||||
int *ip;
|
||||
long ret = 1;
|
||||
BIO_CONNECT *data;
|
||||
|
||||
data = (BIO_CONNECT *)bio->ptr;
|
||||
|
||||
BIO_CONNECT *data = static_cast<BIO_CONNECT *>(bio->ptr);
|
||||
switch (cmd) {
|
||||
case BIO_CTRL_RESET:
|
||||
ret = 0;
|
||||
data->state = BIO_CONN_S_BEFORE;
|
||||
conn_close_socket(bio);
|
||||
bio->flags = 0;
|
||||
break;
|
||||
return 0;
|
||||
case BIO_C_DO_STATE_MACHINE:
|
||||
// use this one to start the connection
|
||||
if (data->state != BIO_CONN_S_OK) {
|
||||
ret = (long)conn_state(bio, data);
|
||||
return conn_state(bio, data);
|
||||
} else {
|
||||
ret = 1;
|
||||
return 1;
|
||||
}
|
||||
break;
|
||||
case BIO_C_SET_CONNECT:
|
||||
if (ptr != NULL) {
|
||||
bio->init = 1;
|
||||
if (num == 0) {
|
||||
OPENSSL_free(data->param_hostname);
|
||||
data->param_hostname =
|
||||
OPENSSL_strdup(reinterpret_cast<const char *>(ptr));
|
||||
if (data->param_hostname == NULL) {
|
||||
ret = 0;
|
||||
}
|
||||
} else if (num == 1) {
|
||||
OPENSSL_free(data->param_port);
|
||||
data->param_port =
|
||||
OPENSSL_strdup(reinterpret_cast<const char *>(ptr));
|
||||
if (data->param_port == NULL) {
|
||||
ret = 0;
|
||||
}
|
||||
} else {
|
||||
ret = 0;
|
||||
}
|
||||
if (ptr == nullptr) {
|
||||
return 0;
|
||||
}
|
||||
break;
|
||||
bio->init = 1;
|
||||
if (num == 0) {
|
||||
OPENSSL_free(data->param_hostname);
|
||||
data->param_hostname =
|
||||
OPENSSL_strdup(reinterpret_cast<const char *>(ptr));
|
||||
if (data->param_hostname == nullptr) {
|
||||
return 0;
|
||||
}
|
||||
} else if (num == 1) {
|
||||
OPENSSL_free(data->param_port);
|
||||
data->param_port = OPENSSL_strdup(reinterpret_cast<const char *>(ptr));
|
||||
if (data->param_port == nullptr) {
|
||||
return 0;
|
||||
}
|
||||
} else {
|
||||
return 0;
|
||||
}
|
||||
return 1;
|
||||
case BIO_C_SET_NBIO:
|
||||
data->nbio = (int)num;
|
||||
break;
|
||||
data->nbio = static_cast<int>(num);
|
||||
return 1;
|
||||
case BIO_C_GET_FD:
|
||||
if (bio->init) {
|
||||
ip = (int *)ptr;
|
||||
if (ip != NULL) {
|
||||
*ip = bio->num;
|
||||
int *out = static_cast<int *>(ptr);
|
||||
if (out != nullptr) {
|
||||
*out = bio->num;
|
||||
}
|
||||
ret = bio->num;
|
||||
return bio->num;
|
||||
} else {
|
||||
ret = -1;
|
||||
return -1;
|
||||
}
|
||||
break;
|
||||
case BIO_CTRL_GET_CLOSE:
|
||||
ret = bio->shutdown;
|
||||
break;
|
||||
return bio->shutdown;
|
||||
case BIO_CTRL_SET_CLOSE:
|
||||
bio->shutdown = (int)num;
|
||||
break;
|
||||
case BIO_CTRL_PENDING:
|
||||
case BIO_CTRL_WPENDING:
|
||||
ret = 0;
|
||||
break;
|
||||
bio->shutdown = static_cast<int>(num);
|
||||
return 1;
|
||||
case BIO_CTRL_FLUSH:
|
||||
break;
|
||||
return 1;
|
||||
case BIO_CTRL_GET_CALLBACK: {
|
||||
int (**fptr)(const BIO *bio, int state, int xret);
|
||||
fptr = reinterpret_cast<decltype(fptr)>(ptr);
|
||||
*fptr = data->info_callback;
|
||||
} break;
|
||||
auto out = reinterpret_cast<int (**)(BIO *bio, int state, int xret)>(ptr);
|
||||
*out = data->info_callback;
|
||||
return 1;
|
||||
}
|
||||
default:
|
||||
ret = 0;
|
||||
break;
|
||||
return 0;
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
static long conn_callback_ctrl(BIO *bio, int cmd, bio_info_cb fp) {
|
||||
long ret = 1;
|
||||
BIO_CONNECT *data;
|
||||
|
||||
data = (BIO_CONNECT *)bio->ptr;
|
||||
|
||||
static long conn_callback_ctrl(BIO *bio, int cmd, BIO_info_cb *fp) {
|
||||
BIO_CONNECT *data = static_cast<BIO_CONNECT *>(bio->ptr);
|
||||
switch (cmd) {
|
||||
case BIO_CTRL_SET_CALLBACK:
|
||||
// This is the actual type signature of |fp|. The caller is expected to
|
||||
// cast it to |bio_info_cb| due to the |BIO_callback_ctrl| calling
|
||||
// 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;
|
||||
data->info_callback = fp;
|
||||
return 1;
|
||||
default:
|
||||
ret = 0;
|
||||
break;
|
||||
return 0;
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
BIO *BIO_new_connect(const char *hostname) {
|
||||
@@ -520,9 +445,9 @@ BIO *BIO_new_connect(const char *hostname) {
|
||||
}
|
||||
|
||||
static const BIO_METHOD methods_connectp = {
|
||||
BIO_TYPE_CONNECT, "socket connect", conn_write, conn_read,
|
||||
NULL /* puts */, NULL /* gets */, conn_ctrl, conn_new,
|
||||
conn_free, conn_callback_ctrl,
|
||||
BIO_TYPE_CONNECT, "socket connect", conn_write,
|
||||
conn_read, /*gets=*/nullptr, conn_ctrl,
|
||||
conn_new, conn_free, conn_callback_ctrl,
|
||||
};
|
||||
|
||||
const BIO_METHOD *BIO_s_connect(void) { return &methods_connectp; }
|
||||
|
||||
@@ -1,58 +1,16 @@
|
||||
/* 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.] */
|
||||
// Copyright 1995-2016 The OpenSSL Project Authors. All Rights Reserved.
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// https://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
#include <CCryptoBoringSSL_bio.h>
|
||||
|
||||
|
||||
@@ -1,58 +1,16 @@
|
||||
/* 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.] */
|
||||
// Copyright 1995-2016 The OpenSSL Project Authors. All Rights Reserved.
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// https://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
#include <CCryptoBoringSSL_bio.h>
|
||||
|
||||
@@ -138,62 +96,47 @@ static int fd_write(BIO *b, const char *in, int inl) {
|
||||
}
|
||||
|
||||
static long fd_ctrl(BIO *b, int cmd, long num, void *ptr) {
|
||||
long ret = 1;
|
||||
int *ip;
|
||||
|
||||
switch (cmd) {
|
||||
case BIO_CTRL_RESET:
|
||||
num = 0;
|
||||
OPENSSL_FALLTHROUGH;
|
||||
[[fallthrough]];
|
||||
case BIO_C_FILE_SEEK:
|
||||
ret = 0;
|
||||
if (b->init) {
|
||||
ret = (long)BORINGSSL_LSEEK(b->num, num, SEEK_SET);
|
||||
return (long)BORINGSSL_LSEEK(b->num, num, SEEK_SET);
|
||||
}
|
||||
break;
|
||||
return 0;
|
||||
case BIO_C_FILE_TELL:
|
||||
case BIO_CTRL_INFO:
|
||||
ret = 0;
|
||||
if (b->init) {
|
||||
ret = (long)BORINGSSL_LSEEK(b->num, 0, SEEK_CUR);
|
||||
return (long)BORINGSSL_LSEEK(b->num, 0, SEEK_CUR);
|
||||
}
|
||||
break;
|
||||
return 0;
|
||||
case BIO_C_SET_FD:
|
||||
fd_free(b);
|
||||
b->num = *((int *)ptr);
|
||||
b->shutdown = (int)num;
|
||||
b->num = *static_cast<int *>(ptr);
|
||||
b->shutdown = static_cast<int>(num);
|
||||
b->init = 1;
|
||||
break;
|
||||
return 1;
|
||||
case BIO_C_GET_FD:
|
||||
if (b->init) {
|
||||
ip = (int *)ptr;
|
||||
if (ip != NULL) {
|
||||
*ip = b->num;
|
||||
int *out = static_cast<int *>(ptr);
|
||||
if (out != nullptr) {
|
||||
*out = b->num;
|
||||
}
|
||||
return b->num;
|
||||
} else {
|
||||
ret = -1;
|
||||
return -1;
|
||||
}
|
||||
break;
|
||||
case BIO_CTRL_GET_CLOSE:
|
||||
ret = b->shutdown;
|
||||
break;
|
||||
return b->shutdown;
|
||||
case BIO_CTRL_SET_CLOSE:
|
||||
b->shutdown = (int)num;
|
||||
break;
|
||||
case BIO_CTRL_PENDING:
|
||||
case BIO_CTRL_WPENDING:
|
||||
ret = 0;
|
||||
break;
|
||||
b->shutdown = static_cast<int>(num);
|
||||
return 1;
|
||||
case BIO_CTRL_FLUSH:
|
||||
ret = 1;
|
||||
break;
|
||||
return 1;
|
||||
default:
|
||||
ret = 0;
|
||||
break;
|
||||
return 0;
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
static int fd_gets(BIO *bp, char *buf, int size) {
|
||||
@@ -218,8 +161,9 @@ static int fd_gets(BIO *bp, char *buf, int size) {
|
||||
}
|
||||
|
||||
static const BIO_METHOD methods_fdp = {
|
||||
BIO_TYPE_FD, "file descriptor", fd_write, fd_read, NULL /* puts */,
|
||||
fd_gets, fd_ctrl, fd_new, fd_free, NULL /* callback_ctrl */,
|
||||
BIO_TYPE_FD, "file descriptor", fd_write,
|
||||
fd_read, fd_gets, fd_ctrl,
|
||||
fd_new, fd_free, /*callback_ctrl=*/nullptr,
|
||||
};
|
||||
|
||||
const BIO_METHOD *BIO_s_fd(void) { return &methods_fdp; }
|
||||
|
||||
@@ -1,58 +1,16 @@
|
||||
/* 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.] */
|
||||
// Copyright 1995-2016 The OpenSSL Project Authors. All Rights Reserved.
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// https://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
#if defined(__linux) || defined(__sun) || defined(__hpux)
|
||||
// Following definition aliases fopen to fopen64 on above mentioned
|
||||
@@ -82,6 +40,7 @@
|
||||
#include <CCryptoBoringSSL_mem.h>
|
||||
|
||||
#include "../internal.h"
|
||||
#include "internal.h"
|
||||
|
||||
#if defined(OPENSSL_WINDOWS)
|
||||
#include <fcntl.h>
|
||||
@@ -180,24 +139,18 @@ static int file_write(BIO *b, const char *in, int inl) {
|
||||
}
|
||||
|
||||
static long file_ctrl(BIO *b, int cmd, long num, void *ptr) {
|
||||
long ret = 1;
|
||||
FILE *fp = (FILE *)b->ptr;
|
||||
FILE **fpp;
|
||||
|
||||
FILE *fp = static_cast<FILE *>(b->ptr);
|
||||
switch (cmd) {
|
||||
case BIO_CTRL_RESET:
|
||||
num = 0;
|
||||
OPENSSL_FALLTHROUGH;
|
||||
[[fallthrough]];
|
||||
case BIO_C_FILE_SEEK:
|
||||
ret = (long)fseek(fp, num, 0);
|
||||
break;
|
||||
return fseek(fp, num, 0);
|
||||
case BIO_CTRL_EOF:
|
||||
ret = (long)feof(fp);
|
||||
break;
|
||||
return feof(fp);
|
||||
case BIO_C_FILE_TELL:
|
||||
case BIO_CTRL_INFO:
|
||||
ret = ftell(fp);
|
||||
break;
|
||||
return ftell(fp);
|
||||
case BIO_C_SET_FILE_PTR:
|
||||
file_free(b);
|
||||
static_assert((BIO_CLOSE & BIO_FP_TEXT) == 0,
|
||||
@@ -211,13 +164,13 @@ static long file_ctrl(BIO *b, int cmd, long num, void *ptr) {
|
||||
_setmode(_fileno(reinterpret_cast<FILE *>(ptr)), _O_TEXT);
|
||||
}
|
||||
#endif
|
||||
b->shutdown = (int)num & BIO_CLOSE;
|
||||
b->shutdown = static_cast<int>(num) & BIO_CLOSE;
|
||||
b->ptr = ptr;
|
||||
b->init = 1;
|
||||
break;
|
||||
return 1;
|
||||
case BIO_C_SET_FILENAME:
|
||||
file_free(b);
|
||||
b->shutdown = (int)num & BIO_CLOSE;
|
||||
b->shutdown = static_cast<int>(num) & BIO_CLOSE;
|
||||
const char *mode;
|
||||
if (num & BIO_FP_APPEND) {
|
||||
if (num & BIO_FP_READ) {
|
||||
@@ -233,43 +186,35 @@ static long file_ctrl(BIO *b, int cmd, long num, void *ptr) {
|
||||
mode = "rb";
|
||||
} else {
|
||||
OPENSSL_PUT_ERROR(BIO, BIO_R_BAD_FOPEN_MODE);
|
||||
ret = 0;
|
||||
break;
|
||||
return 0;
|
||||
}
|
||||
fp = fopen_if_available(reinterpret_cast<const char *>(ptr), mode);
|
||||
if (fp == NULL) {
|
||||
if (fp == nullptr) {
|
||||
OPENSSL_PUT_SYSTEM_ERROR();
|
||||
ERR_add_error_data(5, "fopen('", ptr, "','", mode, "')");
|
||||
OPENSSL_PUT_ERROR(BIO, ERR_R_SYS_LIB);
|
||||
ret = 0;
|
||||
break;
|
||||
return 0;
|
||||
}
|
||||
b->ptr = fp;
|
||||
b->init = 1;
|
||||
break;
|
||||
return 1;
|
||||
case BIO_C_GET_FILE_PTR:
|
||||
// the ptr parameter is actually a FILE ** in this case.
|
||||
if (ptr != NULL) {
|
||||
fpp = (FILE **)ptr;
|
||||
*fpp = (FILE *)b->ptr;
|
||||
if (ptr != nullptr) {
|
||||
FILE **out = static_cast<FILE **>(ptr);
|
||||
*out = fp;
|
||||
}
|
||||
break;
|
||||
return 1;
|
||||
case BIO_CTRL_GET_CLOSE:
|
||||
ret = (long)b->shutdown;
|
||||
break;
|
||||
return b->shutdown;
|
||||
case BIO_CTRL_SET_CLOSE:
|
||||
b->shutdown = (int)num;
|
||||
break;
|
||||
b->shutdown = static_cast<int>(num);
|
||||
return 1;
|
||||
case BIO_CTRL_FLUSH:
|
||||
ret = 0 == fflush((FILE *)b->ptr);
|
||||
break;
|
||||
case BIO_CTRL_WPENDING:
|
||||
case BIO_CTRL_PENDING:
|
||||
return fflush(fp) == 0;
|
||||
default:
|
||||
ret = 0;
|
||||
break;
|
||||
return 0;
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
static int file_gets(BIO *bp, char *buf, int size) {
|
||||
@@ -288,11 +233,9 @@ static int file_gets(BIO *bp, char *buf, int size) {
|
||||
}
|
||||
|
||||
static const BIO_METHOD methods_filep = {
|
||||
BIO_TYPE_FILE, "FILE pointer",
|
||||
file_write, file_read,
|
||||
NULL /* puts */, file_gets,
|
||||
file_ctrl, NULL /* create */,
|
||||
file_free, NULL /* callback_ctrl */,
|
||||
BIO_TYPE_FILE, "FILE pointer", file_write,
|
||||
file_read, file_gets, file_ctrl,
|
||||
/*create=*/nullptr, file_free, /*callback_ctrl=*/nullptr,
|
||||
};
|
||||
|
||||
const BIO_METHOD *BIO_s_file(void) { return &methods_filep; }
|
||||
|
||||
@@ -1,58 +1,16 @@
|
||||
/* 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.] */
|
||||
// Copyright 1995-2016 The OpenSSL Project Authors. All Rights Reserved.
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// https://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
#include <CCryptoBoringSSL_bio.h>
|
||||
|
||||
@@ -62,6 +20,7 @@
|
||||
#include "../internal.h"
|
||||
|
||||
|
||||
namespace {
|
||||
// hexdump_ctx contains the state of a hexdump.
|
||||
struct hexdump_ctx {
|
||||
BIO *bio;
|
||||
@@ -70,16 +29,17 @@ struct hexdump_ctx {
|
||||
size_t n; // number of bytes total.
|
||||
unsigned indent;
|
||||
};
|
||||
} // namespace
|
||||
|
||||
static void hexbyte(char *out, uint8_t b) {
|
||||
static const char hextable[] = "0123456789abcdef";
|
||||
out[0] = hextable[b>>4];
|
||||
out[1] = hextable[b&0x0f];
|
||||
out[0] = hextable[b >> 4];
|
||||
out[1] = hextable[b & 0x0f];
|
||||
}
|
||||
|
||||
static char to_char(uint8_t b) {
|
||||
if (b < 32 || b > 126) {
|
||||
return '.';
|
||||
return '.';
|
||||
}
|
||||
return b;
|
||||
}
|
||||
|
||||
@@ -1,63 +1,25 @@
|
||||
/* 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.] */
|
||||
// Copyright 1995-2016 The OpenSSL Project Authors. All Rights Reserved.
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// https://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
#ifndef OPENSSL_HEADER_BIO_INTERNAL_H
|
||||
#define OPENSSL_HEADER_BIO_INTERNAL_H
|
||||
#ifndef OPENSSL_HEADER_CRYPTO_BIO_INTERNAL_H
|
||||
#define OPENSSL_HEADER_CRYPTO_BIO_INTERNAL_H
|
||||
|
||||
#include <CCryptoBoringSSL_base.h>
|
||||
#include <CCryptoBoringSSL_bio.h>
|
||||
|
||||
#include <CCryptoBoringSSL_ex_data.h>
|
||||
|
||||
#include "../internal.h"
|
||||
|
||||
#if !defined(OPENSSL_NO_SOCK)
|
||||
#if !defined(OPENSSL_WINDOWS)
|
||||
@@ -68,9 +30,7 @@ typedef unsigned short u_short;
|
||||
#include <sys/types.h>
|
||||
#include <sys/socket.h>
|
||||
#else
|
||||
OPENSSL_MSVC_PRAGMA(warning(push, 3))
|
||||
#include <winsock2.h>
|
||||
OPENSSL_MSVC_PRAGMA(warning(pop))
|
||||
typedef int socklen_t;
|
||||
#endif
|
||||
#endif // !OPENSSL_NO_SOCK
|
||||
@@ -80,6 +40,45 @@ extern "C" {
|
||||
#endif
|
||||
|
||||
|
||||
struct bio_method_st {
|
||||
int type;
|
||||
const char *name;
|
||||
int (*bwrite)(BIO *, const char *, int);
|
||||
int (*bread)(BIO *, char *, int);
|
||||
int (*bgets)(BIO *, char *, int);
|
||||
long (*ctrl)(BIO *, int, long, void *);
|
||||
int (*create)(BIO *);
|
||||
int (*destroy)(BIO *);
|
||||
long (*callback_ctrl)(BIO *, int, BIO_info_cb *);
|
||||
};
|
||||
|
||||
struct bio_st {
|
||||
const BIO_METHOD *method;
|
||||
CRYPTO_EX_DATA ex_data;
|
||||
|
||||
// TODO(crbug.com/412269080): |init| and |shutdown| could be bitfields, or
|
||||
// integrated into |flags|, to save memory.
|
||||
|
||||
// init is non-zero if this |BIO| has been initialised.
|
||||
int init;
|
||||
// shutdown is often used by specific |BIO_METHOD|s to determine whether
|
||||
// they own some underlying resource. This flag can often be controlled by
|
||||
// |BIO_set_close|. For example, whether an fd BIO closes the underlying fd
|
||||
// when it, itself, is closed.
|
||||
int shutdown;
|
||||
int flags;
|
||||
int retry_reason;
|
||||
// num is a BIO-specific value. For example, in fd BIOs it's used to store a
|
||||
// file descriptor.
|
||||
int num;
|
||||
CRYPTO_refcount_t references;
|
||||
void *ptr;
|
||||
// next_bio points to the next |BIO| in a chain. This |BIO| owns a reference
|
||||
// to |next_bio|.
|
||||
BIO *next_bio; // used by filter BIOs
|
||||
uint64_t num_read, num_write;
|
||||
};
|
||||
|
||||
#if !defined(OPENSSL_NO_SOCK)
|
||||
|
||||
// bio_ip_and_port_to_socket_and_addr creates a socket and fills in |*out_addr|
|
||||
@@ -118,4 +117,4 @@ int bio_errno_should_retry(int return_value);
|
||||
} // extern C
|
||||
#endif
|
||||
|
||||
#endif // OPENSSL_HEADER_BIO_INTERNAL_H
|
||||
#endif // OPENSSL_HEADER_CRYPTO_BIO_INTERNAL_H
|
||||
@@ -1,54 +1,16 @@
|
||||
/* ====================================================================
|
||||
* Copyright (c) 1998-2003 The OpenSSL Project. All rights reserved.
|
||||
*
|
||||
* 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 above 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 acknowledgment:
|
||||
* "This product includes software developed by the OpenSSL Project
|
||||
* for use in the OpenSSL Toolkit. (http://www.openssl.org/)"
|
||||
*
|
||||
* 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
|
||||
* endorse or promote products derived from this software without
|
||||
* prior written permission. For written permission, please contact
|
||||
* openssl-core@openssl.org.
|
||||
*
|
||||
* 5. Products derived from this software may not be called "OpenSSL"
|
||||
* nor may "OpenSSL" appear in their names without prior written
|
||||
* permission of the OpenSSL Project.
|
||||
*
|
||||
* 6. Redistributions of any form whatsoever must retain the following
|
||||
* acknowledgment:
|
||||
* "This product includes software developed by the OpenSSL Project
|
||||
* for use in the OpenSSL Toolkit (http://www.openssl.org/)"
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
|
||||
* EXPRESSED 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 OpenSSL PROJECT OR
|
||||
* ITS 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.
|
||||
* ====================================================================
|
||||
*
|
||||
* This product includes cryptographic software written by Eric Young
|
||||
* (eay@cryptsoft.com). This product includes software written by Tim
|
||||
* Hudson (tjh@cryptsoft.com). */
|
||||
// Copyright 1999-2016 The OpenSSL Project Authors. All Rights Reserved.
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// https://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
#include <CCryptoBoringSSL_bio.h>
|
||||
|
||||
@@ -59,8 +21,10 @@
|
||||
#include <CCryptoBoringSSL_mem.h>
|
||||
|
||||
#include "../internal.h"
|
||||
#include "internal.h"
|
||||
|
||||
|
||||
namespace {
|
||||
struct bio_bio_st {
|
||||
BIO *peer; // NULL if buf == NULL.
|
||||
// If peer != NULL, then peer->ptr is also a bio_bio_st,
|
||||
@@ -79,6 +43,7 @@ struct bio_bio_st {
|
||||
// it (unsuccessfully) tried to read,
|
||||
// never more than buffer space (size-len) warrants.
|
||||
};
|
||||
} // namespace
|
||||
|
||||
static int bio_new(BIO *bio) {
|
||||
struct bio_bio_st *b =
|
||||
@@ -349,33 +314,32 @@ static int bio_make_pair(BIO *bio1, BIO *bio2, size_t writebuf1_len,
|
||||
}
|
||||
|
||||
static long bio_ctrl(BIO *bio, int cmd, long num, void *ptr) {
|
||||
long ret;
|
||||
struct bio_bio_st *b = reinterpret_cast<bio_bio_st *>(bio->ptr);
|
||||
|
||||
assert(b != NULL);
|
||||
|
||||
assert(b != nullptr);
|
||||
switch (cmd) {
|
||||
// Specific control codes first:
|
||||
case BIO_C_GET_WRITE_BUF_SIZE:
|
||||
ret = (long)b->size;
|
||||
break;
|
||||
// TODO(crbug.com/412584975): This can overflow on 64-bit Windows. Do we
|
||||
// need it? It implements |BIO_get_write_buf_size|, but we don't have the
|
||||
// wrapper.
|
||||
return static_cast<long>(b->size);
|
||||
|
||||
case BIO_C_GET_WRITE_GUARANTEE:
|
||||
// How many bytes can the caller feed to the next write
|
||||
// without having to keep any?
|
||||
if (b->peer == NULL || b->closed) {
|
||||
ret = 0;
|
||||
} else {
|
||||
ret = (long)b->size - b->len;
|
||||
if (b->peer == nullptr || b->closed) {
|
||||
return 0;
|
||||
}
|
||||
break;
|
||||
// TODO(crbug.com/412584975): This can overflow on 64-bit Windows.
|
||||
return static_cast<long>(b->size - b->len);
|
||||
|
||||
case BIO_C_GET_READ_REQUEST:
|
||||
// If the peer unsuccessfully tried to read, how many bytes
|
||||
// were requested? (As with BIO_CTRL_PENDING, that number
|
||||
// can usually be treated as boolean.)
|
||||
ret = (long)b->request;
|
||||
break;
|
||||
//
|
||||
// TODO(crbug.com/412584975): This can overflow on 64-bit Windows.
|
||||
return static_cast<long>(b->request);
|
||||
|
||||
case BIO_C_RESET_READ_REQUEST:
|
||||
// Reset request. (Can be useful after read attempts
|
||||
@@ -383,70 +347,65 @@ static long bio_ctrl(BIO *bio, int cmd, long num, void *ptr) {
|
||||
// e.g. when probing SSL_read to see if any data is
|
||||
// available.)
|
||||
b->request = 0;
|
||||
ret = 1;
|
||||
break;
|
||||
return 1;
|
||||
|
||||
case BIO_C_SHUTDOWN_WR:
|
||||
// similar to shutdown(..., SHUT_WR)
|
||||
b->closed = 1;
|
||||
ret = 1;
|
||||
break;
|
||||
|
||||
return 1;
|
||||
|
||||
// Standard control codes:
|
||||
case BIO_CTRL_GET_CLOSE:
|
||||
ret = bio->shutdown;
|
||||
break;
|
||||
return bio->shutdown;
|
||||
|
||||
case BIO_CTRL_SET_CLOSE:
|
||||
bio->shutdown = (int)num;
|
||||
ret = 1;
|
||||
break;
|
||||
bio->shutdown = static_cast<int>(num);
|
||||
return 1;
|
||||
|
||||
case BIO_CTRL_PENDING:
|
||||
if (b->peer != NULL) {
|
||||
if (b->peer != nullptr) {
|
||||
struct bio_bio_st *peer_b =
|
||||
reinterpret_cast<bio_bio_st *>(b->peer->ptr);
|
||||
ret = (long)peer_b->len;
|
||||
} else {
|
||||
ret = 0;
|
||||
// TODO(crbug.com/412584975): This can overflow on 64-bit Windows.
|
||||
return static_cast<long>(peer_b->len);
|
||||
}
|
||||
break;
|
||||
return 0;
|
||||
|
||||
case BIO_CTRL_WPENDING:
|
||||
ret = 0;
|
||||
if (b->buf != NULL) {
|
||||
ret = (long)b->len;
|
||||
if (b->buf == nullptr) {
|
||||
return 0;
|
||||
}
|
||||
break;
|
||||
// TODO(crbug.com/412584975): This can overflow on 64-bit Windows.
|
||||
return static_cast<long>(b->len);
|
||||
|
||||
case BIO_CTRL_FLUSH:
|
||||
ret = 1;
|
||||
break;
|
||||
return 1;
|
||||
|
||||
case BIO_CTRL_EOF: {
|
||||
BIO *other_bio = reinterpret_cast<BIO *>(ptr);
|
||||
|
||||
if (other_bio) {
|
||||
struct bio_bio_st *other_b =
|
||||
reinterpret_cast<bio_bio_st *>(other_bio->ptr);
|
||||
assert(other_b != NULL);
|
||||
ret = other_b->len == 0 && other_b->closed;
|
||||
} else {
|
||||
ret = 1;
|
||||
if (b->peer) {
|
||||
auto *peer_b = reinterpret_cast<bio_bio_st *>(b->peer->ptr);
|
||||
assert(peer_b != nullptr);
|
||||
return peer_b->len == 0 && peer_b->closed;
|
||||
}
|
||||
} break;
|
||||
return 1;
|
||||
}
|
||||
|
||||
default:
|
||||
ret = 0;
|
||||
return 0;
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
||||
static const BIO_METHOD methods_biop = {
|
||||
BIO_TYPE_BIO, "BIO pair", bio_write, bio_read, NULL /* puts */,
|
||||
NULL /* gets */, bio_ctrl, bio_new, bio_free, NULL /* callback_ctrl */,
|
||||
BIO_TYPE_BIO,
|
||||
"BIO pair",
|
||||
bio_write,
|
||||
bio_read,
|
||||
/*gets=*/nullptr,
|
||||
bio_ctrl,
|
||||
bio_new,
|
||||
bio_free,
|
||||
/*callback_ctrl=*/nullptr,
|
||||
};
|
||||
|
||||
static const BIO_METHOD *bio_s_bio(void) { return &methods_biop; }
|
||||
|
||||
@@ -1,58 +1,16 @@
|
||||
/* 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.] */
|
||||
// Copyright 1995-2016 The OpenSSL Project Authors. All Rights Reserved.
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// https://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
#include <CCryptoBoringSSL_bio.h>
|
||||
|
||||
@@ -76,10 +34,9 @@ int BIO_printf(BIO *bio, const char *format, ...) {
|
||||
}
|
||||
|
||||
if ((size_t)out_len >= sizeof(buf)) {
|
||||
const int requested_len = out_len;
|
||||
// The output was truncated. Note that vsnprintf's return value
|
||||
// does not include a trailing NUL, but the buffer must be sized
|
||||
// for it.
|
||||
const size_t requested_len = (size_t)out_len;
|
||||
// The output was truncated. Note that vsnprintf's return value does not
|
||||
// include a trailing NUL, but the buffer must be sized for it.
|
||||
out = reinterpret_cast<char *>(OPENSSL_malloc(requested_len + 1));
|
||||
out_malloced = 1;
|
||||
if (out == NULL) {
|
||||
@@ -88,7 +45,7 @@ int BIO_printf(BIO *bio, const char *format, ...) {
|
||||
va_start(args, format);
|
||||
out_len = vsnprintf(out, requested_len + 1, format, args);
|
||||
va_end(args);
|
||||
assert(out_len == requested_len);
|
||||
assert(out_len == (int)requested_len);
|
||||
} else {
|
||||
out = buf;
|
||||
}
|
||||
|
||||
@@ -1,58 +1,16 @@
|
||||
/* 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.] */
|
||||
// Copyright 1995-2016 The OpenSSL Project Authors. All Rights Reserved.
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// https://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
#include <CCryptoBoringSSL_bio.h>
|
||||
|
||||
@@ -64,10 +22,7 @@
|
||||
#if !defined(OPENSSL_WINDOWS)
|
||||
#include <unistd.h>
|
||||
#else
|
||||
OPENSSL_MSVC_PRAGMA(warning(push, 3))
|
||||
#include <winsock2.h>
|
||||
OPENSSL_MSVC_PRAGMA(warning(pop))
|
||||
|
||||
OPENSSL_MSVC_PRAGMA(comment(lib, "Ws2_32.lib"))
|
||||
#endif
|
||||
|
||||
@@ -128,49 +83,44 @@ static int sock_write(BIO *b, const char *in, int inl) {
|
||||
}
|
||||
|
||||
static long sock_ctrl(BIO *b, int cmd, long num, void *ptr) {
|
||||
long ret = 1;
|
||||
int *ip;
|
||||
|
||||
switch (cmd) {
|
||||
case BIO_C_SET_FD:
|
||||
sock_free(b);
|
||||
b->num = *((int *)ptr);
|
||||
b->shutdown = (int)num;
|
||||
b->num = *static_cast<int *>(ptr);
|
||||
b->shutdown = static_cast<int>(num);
|
||||
b->init = 1;
|
||||
break;
|
||||
return 1;
|
||||
case BIO_C_GET_FD:
|
||||
if (b->init) {
|
||||
ip = (int *)ptr;
|
||||
if (ip != NULL) {
|
||||
*ip = b->num;
|
||||
int *out = static_cast<int*>(ptr);
|
||||
if (out != nullptr) {
|
||||
*out = b->num;
|
||||
}
|
||||
ret = b->num;
|
||||
} else {
|
||||
ret = -1;
|
||||
return b->num;
|
||||
}
|
||||
break;
|
||||
return -1;
|
||||
case BIO_CTRL_GET_CLOSE:
|
||||
ret = b->shutdown;
|
||||
break;
|
||||
return b->shutdown;
|
||||
case BIO_CTRL_SET_CLOSE:
|
||||
b->shutdown = (int)num;
|
||||
break;
|
||||
b->shutdown = static_cast<int>(num);
|
||||
return 1;
|
||||
case BIO_CTRL_FLUSH:
|
||||
ret = 1;
|
||||
break;
|
||||
return 1;
|
||||
default:
|
||||
ret = 0;
|
||||
break;
|
||||
return 0;
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
static const BIO_METHOD methods_sockp = {
|
||||
BIO_TYPE_SOCKET, "socket",
|
||||
sock_write, sock_read,
|
||||
NULL /* puts */, NULL /* gets, */,
|
||||
sock_ctrl, NULL /* create */,
|
||||
sock_free, NULL /* callback_ctrl */,
|
||||
BIO_TYPE_SOCKET,
|
||||
"socket",
|
||||
sock_write,
|
||||
sock_read,
|
||||
nullptr /* gets, */,
|
||||
sock_ctrl,
|
||||
nullptr /* create */,
|
||||
sock_free,
|
||||
nullptr /* callback_ctrl */,
|
||||
};
|
||||
|
||||
const BIO_METHOD *BIO_s_socket(void) { return &methods_sockp; }
|
||||
@@ -186,4 +136,75 @@ BIO *BIO_new_socket(int fd, int close_flag) {
|
||||
return ret;
|
||||
}
|
||||
|
||||
// These functions are provided solely for compatibility with software that
|
||||
// tries to copy and then modify |BIO_s_socket|. See bio.h for details.
|
||||
// PostgreSQL's use makes several fragile assumptions on |BIO_s_socket|:
|
||||
//
|
||||
// - We do not store anything in |BIO_set_data|. (Broken in upstream OpenSSL,
|
||||
// which broke PostgreSQL.)
|
||||
// - We do not store anything in |BIO_set_app_data|.
|
||||
// - |BIO_s_socket| is implemented internally using the non-|size_t|-clean
|
||||
// I/O functions rather than the |size_t|-clean ones.
|
||||
// - |BIO_METHOD| never gains another function pointer that is used in concert
|
||||
// with any of the functions here.
|
||||
//
|
||||
// Some other projects doing similar things use |BIO_meth_get_read| and
|
||||
// |BIO_meth_get_write| and in turn assume that |BIO_s_socket| has not been
|
||||
// ported to the |size_t|-clean |BIO_read_ex| and |BIO_write_ex|. (Not yet
|
||||
// implemented in BoringSSL.)
|
||||
//
|
||||
// This is hopelessly fragile. PostgreSQL 18 will include a fix to stop using
|
||||
// these APIs, but older versions and other software remain impacted, so we
|
||||
// implement these functions, but only support |BIO_s_socket|. For now they just
|
||||
// return the underlying functions, but if we ever need to break the above
|
||||
// assumptions, we can return an older, frozen version of |BIO_s_socket|.
|
||||
// Limiting to exactly one allowed |BIO_METHOD| lets us do this.
|
||||
//
|
||||
// These functions are also deprecated in upstream OpenSSL. See
|
||||
// https://github.com/openssl/openssl/issues/26047
|
||||
//
|
||||
// TODO(davidben): Once Folly and all versions of PostgreSQL we care about are
|
||||
// updated or patched, remove these functions.
|
||||
|
||||
int (*BIO_meth_get_write(const BIO_METHOD *method))(BIO *, const char *, int) {
|
||||
BSSL_CHECK(method == BIO_s_socket());
|
||||
return method->bwrite;
|
||||
}
|
||||
|
||||
int (*BIO_meth_get_read(const BIO_METHOD *method))(BIO *, char *, int) {
|
||||
BSSL_CHECK(method == BIO_s_socket());
|
||||
return method->bread;
|
||||
}
|
||||
|
||||
int (*BIO_meth_get_gets(const BIO_METHOD *method))(BIO *, char *, int) {
|
||||
BSSL_CHECK(method == BIO_s_socket());
|
||||
return method->bgets;
|
||||
}
|
||||
|
||||
int (*BIO_meth_get_puts(const BIO_METHOD *method))(BIO *, const char *) {
|
||||
BSSL_CHECK(method == BIO_s_socket());
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
long (*BIO_meth_get_ctrl(const BIO_METHOD *method))(BIO *, int, long, void *) {
|
||||
BSSL_CHECK(method == BIO_s_socket());
|
||||
return method->ctrl;
|
||||
}
|
||||
|
||||
int (*BIO_meth_get_create(const BIO_METHOD *method))(BIO *) {
|
||||
BSSL_CHECK(method == BIO_s_socket());
|
||||
return method->create;
|
||||
}
|
||||
|
||||
int (*BIO_meth_get_destroy(const BIO_METHOD *method))(BIO *) {
|
||||
BSSL_CHECK(method == BIO_s_socket());
|
||||
return method->destroy;
|
||||
}
|
||||
|
||||
long (*BIO_meth_get_callback_ctrl(const BIO_METHOD *method))(BIO *, int,
|
||||
bio_info_cb) {
|
||||
BSSL_CHECK(method == BIO_s_socket());
|
||||
return method->callback_ctrl;
|
||||
}
|
||||
|
||||
#endif // OPENSSL_NO_SOCK
|
||||
@@ -1,16 +1,16 @@
|
||||
/* Copyright 2014 The BoringSSL Authors
|
||||
*
|
||||
* 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. */
|
||||
// Copyright 2014 The BoringSSL Authors
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// https://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
#if defined(__linux__)
|
||||
#undef _POSIX_C_SOURCE
|
||||
@@ -30,10 +30,8 @@
|
||||
#include <netdb.h>
|
||||
#include <unistd.h>
|
||||
#else
|
||||
OPENSSL_MSVC_PRAGMA(warning(push, 3))
|
||||
#include <winsock2.h>
|
||||
#include <ws2tcpip.h>
|
||||
OPENSSL_MSVC_PRAGMA(warning(pop))
|
||||
#endif
|
||||
|
||||
#include "internal.h"
|
||||
|
||||
@@ -1,16 +1,16 @@
|
||||
/* Copyright 2021 The BoringSSL Authors
|
||||
*
|
||||
* 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. */
|
||||
// Copyright 2021 The BoringSSL Authors
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// https://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
#include <CCryptoBoringSSL_blake2.h>
|
||||
|
||||
@@ -64,7 +64,7 @@ static void blake2b_transform(BLAKE2B_CTX *b2b,
|
||||
size_t num_bytes, int is_final_block) {
|
||||
// https://tools.ietf.org/html/rfc7693#section-3.2
|
||||
uint64_t v[16];
|
||||
static_assert(sizeof(v) == sizeof(b2b->h) + sizeof(kIV), "");
|
||||
static_assert(sizeof(v) == sizeof(b2b->h) + sizeof(kIV));
|
||||
OPENSSL_memcpy(v, b2b->h, sizeof(b2b->h));
|
||||
OPENSSL_memcpy(&v[8], kIV, sizeof(kIV));
|
||||
|
||||
@@ -108,7 +108,7 @@ static void blake2b_transform(BLAKE2B_CTX *b2b,
|
||||
void BLAKE2B256_Init(BLAKE2B_CTX *b2b) {
|
||||
OPENSSL_memset(b2b, 0, sizeof(BLAKE2B_CTX));
|
||||
|
||||
static_assert(sizeof(kIV) == sizeof(b2b->h), "");
|
||||
static_assert(sizeof(kIV) == sizeof(b2b->h));
|
||||
OPENSSL_memcpy(&b2b->h, kIV, sizeof(kIV));
|
||||
|
||||
// https://tools.ietf.org/html/rfc7693#section-2.5
|
||||
@@ -156,7 +156,7 @@ void BLAKE2B256_Final(uint8_t out[BLAKE2B256_DIGEST_LENGTH], BLAKE2B_CTX *b2b) {
|
||||
sizeof(b2b->block) - b2b->block_used);
|
||||
blake2b_transform(b2b, b2b->block, b2b->block_used,
|
||||
/*is_final_block=*/1);
|
||||
static_assert(BLAKE2B256_DIGEST_LENGTH <= sizeof(b2b->h), "");
|
||||
static_assert(BLAKE2B256_DIGEST_LENGTH <= sizeof(b2b->h));
|
||||
memcpy(out, b2b->h, BLAKE2B256_DIGEST_LENGTH);
|
||||
}
|
||||
|
||||
|
||||
+13
-13
@@ -1,16 +1,16 @@
|
||||
/* Copyright 2015 The BoringSSL Authors
|
||||
*
|
||||
* 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. */
|
||||
// Copyright 2015 The BoringSSL Authors
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// https://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
#include <CCryptoBoringSSL_bn.h>
|
||||
|
||||
+44
-102
@@ -1,58 +1,16 @@
|
||||
/* 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.] */
|
||||
// Copyright 1995-2016 The OpenSSL Project Authors. All Rights Reserved.
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// https://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
#include <CCryptoBoringSSL_bn.h>
|
||||
|
||||
@@ -61,6 +19,8 @@
|
||||
#include <limits.h>
|
||||
#include <stdio.h>
|
||||
|
||||
#include <algorithm>
|
||||
|
||||
#include <CCryptoBoringSSL_bio.h>
|
||||
#include <CCryptoBoringSSL_bytestring.h>
|
||||
#include <CCryptoBoringSSL_err.h>
|
||||
@@ -238,33 +198,32 @@ int BN_hex2bn(BIGNUM **outp, const char *in) {
|
||||
char *BN_bn2dec(const BIGNUM *a) {
|
||||
// It is easier to print strings little-endian, so we assemble it in reverse
|
||||
// and fix at the end.
|
||||
BIGNUM *copy = NULL;
|
||||
CBB cbb;
|
||||
if (!CBB_init(&cbb, 16) || //
|
||||
!CBB_add_u8(&cbb, 0 /* trailing NUL */)) {
|
||||
goto err;
|
||||
bssl::ScopedCBB cbb;
|
||||
if (!CBB_init(cbb.get(), 16) || //
|
||||
!CBB_add_u8(cbb.get(), 0 /* trailing NUL */)) {
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
if (BN_is_zero(a)) {
|
||||
if (!CBB_add_u8(&cbb, '0')) {
|
||||
goto err;
|
||||
if (!CBB_add_u8(cbb.get(), '0')) {
|
||||
return nullptr;
|
||||
}
|
||||
} else {
|
||||
copy = BN_dup(a);
|
||||
if (copy == NULL) {
|
||||
goto err;
|
||||
bssl::UniquePtr<BIGNUM> copy(BN_dup(a));
|
||||
if (copy == nullptr) {
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
while (!BN_is_zero(copy)) {
|
||||
BN_ULONG word = BN_div_word(copy, BN_DEC_CONV);
|
||||
while (!BN_is_zero(copy.get())) {
|
||||
BN_ULONG word = BN_div_word(copy.get(), BN_DEC_CONV);
|
||||
if (word == (BN_ULONG)-1) {
|
||||
goto err;
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
const int add_leading_zeros = !BN_is_zero(copy);
|
||||
const int add_leading_zeros = !BN_is_zero(copy.get());
|
||||
for (int i = 0; i < BN_DEC_NUM && (add_leading_zeros || word != 0); i++) {
|
||||
if (!CBB_add_u8(&cbb, '0' + word % 10)) {
|
||||
goto err;
|
||||
if (!CBB_add_u8(cbb.get(), '0' + word % 10)) {
|
||||
return nullptr;
|
||||
}
|
||||
word /= 10;
|
||||
}
|
||||
@@ -273,30 +232,18 @@ char *BN_bn2dec(const BIGNUM *a) {
|
||||
}
|
||||
|
||||
if (BN_is_negative(a) && //
|
||||
!CBB_add_u8(&cbb, '-')) {
|
||||
goto err;
|
||||
!CBB_add_u8(cbb.get(), '-')) {
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
uint8_t *data;
|
||||
size_t len;
|
||||
if (!CBB_finish(&cbb, &data, &len)) {
|
||||
goto err;
|
||||
if (!CBB_finish(cbb.get(), &data, &len)) {
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
// Reverse the buffer.
|
||||
for (size_t i = 0; i < len / 2; i++) {
|
||||
uint8_t tmp = data[i];
|
||||
data[i] = data[len - 1 - i];
|
||||
data[len - 1 - i] = tmp;
|
||||
}
|
||||
|
||||
BN_free(copy);
|
||||
return (char *)data;
|
||||
|
||||
err:
|
||||
BN_free(copy);
|
||||
CBB_cleanup(&cbb);
|
||||
return NULL;
|
||||
std::reverse(data, data + len);
|
||||
return reinterpret_cast<char *>(data);
|
||||
}
|
||||
|
||||
int BN_dec2bn(BIGNUM **outp, const char *in) {
|
||||
@@ -327,33 +274,28 @@ int BN_asc2bn(BIGNUM **outp, const char *in) {
|
||||
}
|
||||
|
||||
int BN_print(BIO *bp, const BIGNUM *a) {
|
||||
int i, j, v, z = 0;
|
||||
int ret = 0;
|
||||
|
||||
if (a->neg && BIO_write(bp, "-", 1) != 1) {
|
||||
goto end;
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (BN_is_zero(a) && BIO_write(bp, "0", 1) != 1) {
|
||||
goto end;
|
||||
return 0;
|
||||
}
|
||||
|
||||
for (i = bn_minimal_width(a) - 1; i >= 0; i--) {
|
||||
for (j = BN_BITS2 - 4; j >= 0; j -= 4) {
|
||||
int z = 0;
|
||||
for (int i = bn_minimal_width(a) - 1; i >= 0; i--) {
|
||||
for (int j = BN_BITS2 - 4; j >= 0; j -= 4) {
|
||||
// strip leading zeros
|
||||
v = ((int)(a->d[i] >> (long)j)) & 0x0f;
|
||||
int v = ((int)(a->d[i] >> (long)j)) & 0x0f;
|
||||
if (z || v != 0) {
|
||||
if (BIO_write(bp, &hextable[v], 1) != 1) {
|
||||
goto end;
|
||||
return 0;
|
||||
}
|
||||
z = 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
ret = 1;
|
||||
|
||||
end:
|
||||
return ret;
|
||||
return 1;
|
||||
}
|
||||
|
||||
int BN_print_fp(FILE *fp, const BIGNUM *a) {
|
||||
@@ -0,0 +1,100 @@
|
||||
// Copyright 1995-2016 The OpenSSL Project Authors. All Rights Reserved.
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// https://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
#include <CCryptoBoringSSL_bn.h>
|
||||
|
||||
#include <CCryptoBoringSSL_err.h>
|
||||
|
||||
#include "../fipsmodule/bn/internal.h"
|
||||
#include "../internal.h"
|
||||
|
||||
|
||||
int BN_mod_pow2(BIGNUM *r, const BIGNUM *a, size_t e) {
|
||||
if (e == 0 || a->width == 0) {
|
||||
BN_zero(r);
|
||||
return 1;
|
||||
}
|
||||
|
||||
size_t num_words = 1 + ((e - 1) / BN_BITS2);
|
||||
|
||||
// If |a| definitely has less than |e| bits, just BN_copy.
|
||||
if ((size_t)a->width < num_words) {
|
||||
return BN_copy(r, a) != NULL;
|
||||
}
|
||||
|
||||
// Otherwise, first make sure we have enough space in |r|.
|
||||
// Note that this will fail if num_words > INT_MAX.
|
||||
if (!bn_wexpand(r, num_words)) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
// Copy the content of |a| into |r|.
|
||||
OPENSSL_memcpy(r->d, a->d, num_words * sizeof(BN_ULONG));
|
||||
|
||||
// If |e| isn't word-aligned, we have to mask off some of our bits.
|
||||
size_t top_word_exponent = e % (sizeof(BN_ULONG) * 8);
|
||||
if (top_word_exponent != 0) {
|
||||
r->d[num_words - 1] &= (((BN_ULONG)1) << top_word_exponent) - 1;
|
||||
}
|
||||
|
||||
// Fill in the remaining fields of |r|.
|
||||
r->neg = a->neg;
|
||||
r->width = (int)num_words;
|
||||
bn_set_minimal_width(r);
|
||||
return 1;
|
||||
}
|
||||
|
||||
int BN_nnmod_pow2(BIGNUM *r, const BIGNUM *a, size_t e) {
|
||||
if (!BN_mod_pow2(r, a, e)) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
// If the returned value was non-negative, we're done.
|
||||
if (BN_is_zero(r) || !r->neg) {
|
||||
return 1;
|
||||
}
|
||||
|
||||
size_t num_words = 1 + (e - 1) / BN_BITS2;
|
||||
|
||||
// Expand |r| to the size of our modulus.
|
||||
if (!bn_wexpand(r, num_words)) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
// Clear the upper words of |r|.
|
||||
OPENSSL_memset(&r->d[r->width], 0, (num_words - r->width) * BN_BYTES);
|
||||
|
||||
// Set parameters of |r|.
|
||||
r->neg = 0;
|
||||
r->width = (int)num_words;
|
||||
|
||||
// Now, invert every word. The idea here is that we want to compute 2^e-|x|,
|
||||
// which is actually equivalent to the twos-complement representation of |x|
|
||||
// in |e| bits, which is -x = ~x + 1.
|
||||
for (int i = 0; i < r->width; i++) {
|
||||
r->d[i] = ~r->d[i];
|
||||
}
|
||||
|
||||
// If our exponent doesn't span the top word, we have to mask the rest.
|
||||
size_t top_word_exponent = e % BN_BITS2;
|
||||
if (top_word_exponent != 0) {
|
||||
r->d[r->width - 1] &= (((BN_ULONG)1) << top_word_exponent) - 1;
|
||||
}
|
||||
|
||||
// Keep the minimal-width invariant for |BIGNUM|.
|
||||
bn_set_minimal_width(r);
|
||||
|
||||
// Finally, add one, for the reason described above.
|
||||
return BN_add(r, r, BN_value_one());
|
||||
}
|
||||
@@ -0,0 +1,166 @@
|
||||
// Copyright 1995-2016 The OpenSSL Project Authors. All Rights Reserved.
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// https://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
#include <CCryptoBoringSSL_bn.h>
|
||||
|
||||
#include <assert.h>
|
||||
|
||||
#include <CCryptoBoringSSL_err.h>
|
||||
|
||||
#include "../fipsmodule/bn/internal.h"
|
||||
|
||||
|
||||
int BN_exp(BIGNUM *r, const BIGNUM *a, const BIGNUM *p, BN_CTX *ctx) {
|
||||
bssl::BN_CTXScope scope(ctx);
|
||||
BIGNUM *rr;
|
||||
if (r == a || r == p) {
|
||||
rr = BN_CTX_get(ctx);
|
||||
} else {
|
||||
rr = r;
|
||||
}
|
||||
|
||||
BIGNUM *v = BN_CTX_get(ctx);
|
||||
if (rr == NULL || v == NULL) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (BN_copy(v, a) == NULL) {
|
||||
return 0;
|
||||
}
|
||||
int bits = BN_num_bits(p);
|
||||
|
||||
if (BN_is_odd(p)) {
|
||||
if (BN_copy(rr, a) == NULL) {
|
||||
return 0;
|
||||
}
|
||||
} else {
|
||||
if (!BN_one(rr)) {
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
for (int i = 1; i < bits; i++) {
|
||||
if (!BN_sqr(v, v, ctx)) {
|
||||
return 0;
|
||||
}
|
||||
if (BN_is_bit_set(p, i)) {
|
||||
if (!BN_mul(rr, rr, v, ctx)) {
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (r != rr && !BN_copy(r, rr)) {
|
||||
return 0;
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
|
||||
static int mod_exp_even(BIGNUM *r, const BIGNUM *a, const BIGNUM *p,
|
||||
const BIGNUM *m, BN_CTX *ctx) {
|
||||
// No cryptographic operations require modular exponentiation with an even
|
||||
// modulus. We support it for backwards compatibility with any applications
|
||||
// that may have relied on the operation, but optimize for simplicity over
|
||||
// performance with straightforward square-and-multiply routine.
|
||||
int bits = BN_num_bits(p);
|
||||
if (bits == 0) {
|
||||
return BN_one(r);
|
||||
}
|
||||
|
||||
// Make a copy of |a|, in case it aliases |r|.
|
||||
bssl::BN_CTXScope scope(ctx);
|
||||
BIGNUM *tmp = BN_CTX_get(ctx);
|
||||
if (tmp == nullptr || !BN_copy(tmp, a)) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
assert(BN_is_bit_set(p, bits - 1));
|
||||
if (!BN_copy(r, tmp)) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
for (int i = bits - 2; i >= 0; i--) {
|
||||
if (!BN_mod_sqr(r, r, m, ctx) ||
|
||||
(BN_is_bit_set(p, i) && !BN_mod_mul(r, r, tmp, m, ctx))) {
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
int BN_mod_exp(BIGNUM *r, const BIGNUM *a, const BIGNUM *p, const BIGNUM *m,
|
||||
BN_CTX *ctx) {
|
||||
if (m->neg) {
|
||||
OPENSSL_PUT_ERROR(BN, BN_R_NEGATIVE_NUMBER);
|
||||
return 0;
|
||||
}
|
||||
if (a->neg || BN_ucmp(a, m) >= 0) {
|
||||
if (!BN_nnmod(r, a, m, ctx)) {
|
||||
return 0;
|
||||
}
|
||||
a = r;
|
||||
}
|
||||
|
||||
if (BN_is_odd(m)) {
|
||||
return BN_mod_exp_mont(r, a, p, m, ctx, NULL);
|
||||
}
|
||||
|
||||
return mod_exp_even(r, a, p, m, ctx);
|
||||
}
|
||||
|
||||
int BN_mod_exp_mont_word(BIGNUM *rr, BN_ULONG a, const BIGNUM *p,
|
||||
const BIGNUM *m, BN_CTX *ctx,
|
||||
const BN_MONT_CTX *mont) {
|
||||
// BN_mod_exp_mont requires reduced inputs.
|
||||
if (bn_minimal_width(m) == 1) {
|
||||
a %= m->d[0];
|
||||
}
|
||||
|
||||
bssl::UniquePtr<BIGNUM> a_bignum(BN_new());
|
||||
if (a_bignum == nullptr || !BN_set_word(a_bignum.get(), a)) {
|
||||
OPENSSL_PUT_ERROR(BN, ERR_R_INTERNAL_ERROR);
|
||||
return 0;
|
||||
}
|
||||
|
||||
return BN_mod_exp_mont(rr, a_bignum.get(), p, m, ctx, mont);
|
||||
}
|
||||
|
||||
int BN_mod_exp2_mont(BIGNUM *rr, const BIGNUM *a1, const BIGNUM *p1,
|
||||
const BIGNUM *a2, const BIGNUM *p2, const BIGNUM *m,
|
||||
BN_CTX *ctx, const BN_MONT_CTX *mont) {
|
||||
// Allocate a montgomery context if it was not supplied by the caller.
|
||||
bssl::UniquePtr<BN_MONT_CTX> new_mont;
|
||||
if (mont == nullptr) {
|
||||
new_mont.reset(BN_MONT_CTX_new_for_modulus(m, ctx));
|
||||
if (new_mont == nullptr) {
|
||||
return 0;
|
||||
}
|
||||
mont = new_mont.get();
|
||||
}
|
||||
|
||||
// BN_mod_mul_montgomery removes one Montgomery factor, so passing one
|
||||
// Montgomery-encoded and one non-Montgomery-encoded value gives a
|
||||
// non-Montgomery-encoded result.
|
||||
bssl::UniquePtr<BIGNUM> tmp(BN_new());
|
||||
if (tmp == nullptr || //
|
||||
!BN_mod_exp_mont(rr, a1, p1, m, ctx, mont) ||
|
||||
!BN_mod_exp_mont(tmp.get(), a2, p2, m, ctx, mont) ||
|
||||
!BN_to_montgomery(rr, rr, mont, ctx) ||
|
||||
!BN_mod_mul_montgomery(rr, rr, tmp.get(), mont, ctx)) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
return 1;
|
||||
}
|
||||
@@ -0,0 +1,93 @@
|
||||
// Copyright 2000-2016 The OpenSSL Project Authors. All Rights Reserved.
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// https://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
#include <CCryptoBoringSSL_bn.h>
|
||||
|
||||
#include <CCryptoBoringSSL_err.h>
|
||||
|
||||
|
||||
int BN_sqrt(BIGNUM *out_sqrt, const BIGNUM *in, BN_CTX *ctx) {
|
||||
BIGNUM *estimate, *tmp, *delta, *last_delta, *tmp2;
|
||||
int ok = 0, last_delta_valid = 0;
|
||||
|
||||
if (in->neg) {
|
||||
OPENSSL_PUT_ERROR(BN, BN_R_NEGATIVE_NUMBER);
|
||||
return 0;
|
||||
}
|
||||
if (BN_is_zero(in)) {
|
||||
BN_zero(out_sqrt);
|
||||
return 1;
|
||||
}
|
||||
|
||||
bssl::BN_CTXScope scope(ctx);
|
||||
if (out_sqrt == in) {
|
||||
estimate = BN_CTX_get(ctx);
|
||||
} else {
|
||||
estimate = out_sqrt;
|
||||
}
|
||||
tmp = BN_CTX_get(ctx);
|
||||
last_delta = BN_CTX_get(ctx);
|
||||
delta = BN_CTX_get(ctx);
|
||||
if (estimate == NULL || tmp == NULL || last_delta == NULL || delta == NULL) {
|
||||
goto err;
|
||||
}
|
||||
|
||||
// We estimate that the square root of an n-bit number is 2^{n/2}.
|
||||
if (!BN_lshift(estimate, BN_value_one(), BN_num_bits(in)/2)) {
|
||||
goto err;
|
||||
}
|
||||
|
||||
// This is Newton's method for finding a root of the equation |estimate|^2 -
|
||||
// |in| = 0.
|
||||
for (;;) {
|
||||
// |estimate| = 1/2 * (|estimate| + |in|/|estimate|)
|
||||
if (!BN_div(tmp, NULL, in, estimate, ctx) ||
|
||||
!BN_add(tmp, tmp, estimate) ||
|
||||
!BN_rshift1(estimate, tmp) ||
|
||||
// |tmp| = |estimate|^2
|
||||
!BN_sqr(tmp, estimate, ctx) ||
|
||||
// |delta| = |in| - |tmp|
|
||||
!BN_sub(delta, in, tmp)) {
|
||||
OPENSSL_PUT_ERROR(BN, ERR_R_BN_LIB);
|
||||
goto err;
|
||||
}
|
||||
|
||||
delta->neg = 0;
|
||||
// The difference between |in| and |estimate| squared is required to always
|
||||
// decrease. This ensures that the loop always terminates, but I don't have
|
||||
// a proof that it always finds the square root for a given square.
|
||||
if (last_delta_valid && BN_cmp(delta, last_delta) >= 0) {
|
||||
break;
|
||||
}
|
||||
|
||||
last_delta_valid = 1;
|
||||
|
||||
tmp2 = last_delta;
|
||||
last_delta = delta;
|
||||
delta = tmp2;
|
||||
}
|
||||
|
||||
if (BN_cmp(tmp, in) != 0) {
|
||||
OPENSSL_PUT_ERROR(BN, BN_R_NOT_A_SQUARE);
|
||||
goto err;
|
||||
}
|
||||
|
||||
ok = 1;
|
||||
|
||||
err:
|
||||
if (ok && out_sqrt == in && !BN_copy(out_sqrt, estimate)) {
|
||||
ok = 0;
|
||||
}
|
||||
return ok;
|
||||
}
|
||||
@@ -1,58 +1,16 @@
|
||||
/* 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.] */
|
||||
// Copyright 1995-2016 The OpenSSL Project Authors. All Rights Reserved.
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// https://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
#include <CCryptoBoringSSL_buf.h>
|
||||
|
||||
@@ -69,10 +27,9 @@ BUF_MEM *BUF_MEM_new(void) {
|
||||
}
|
||||
|
||||
void BUF_MEM_free(BUF_MEM *buf) {
|
||||
if (buf == NULL) {
|
||||
if (buf == nullptr) {
|
||||
return;
|
||||
}
|
||||
|
||||
OPENSSL_free(buf->data);
|
||||
OPENSSL_free(buf);
|
||||
}
|
||||
|
||||
@@ -1,16 +1,16 @@
|
||||
/* Copyright 2016 The BoringSSL Authors
|
||||
*
|
||||
* 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. */
|
||||
// Copyright 2016 The BoringSSL Authors
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// https://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
|
||||
#include <CCryptoBoringSSL_bytestring.h>
|
||||
|
||||
@@ -1,16 +1,16 @@
|
||||
/* Copyright 2014 The BoringSSL Authors
|
||||
*
|
||||
* 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. */
|
||||
// Copyright 2014 The BoringSSL Authors
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// https://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
#include <CCryptoBoringSSL_bytestring.h>
|
||||
|
||||
|
||||
@@ -1,16 +1,16 @@
|
||||
/* Copyright 2014 The BoringSSL Authors
|
||||
*
|
||||
* 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. */
|
||||
// Copyright 2014 The BoringSSL Authors
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// https://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
#include <CCryptoBoringSSL_bytestring.h>
|
||||
|
||||
@@ -468,6 +468,13 @@ int CBB_add_u64le(CBB *cbb, uint64_t value) {
|
||||
return CBB_add_u64(cbb, CRYPTO_bswap8(value));
|
||||
}
|
||||
|
||||
void CBB_discard(CBB *cbb, size_t len) {
|
||||
BSSL_CHECK(cbb->child == nullptr);
|
||||
BSSL_CHECK(len <= CBB_len(cbb));
|
||||
struct cbb_buffer_st *base = cbb_get_base(cbb);
|
||||
base->len -= len;
|
||||
}
|
||||
|
||||
void CBB_discard_child(CBB *cbb) {
|
||||
if (cbb->child == NULL) {
|
||||
return;
|
||||
@@ -481,6 +488,19 @@ void CBB_discard_child(CBB *cbb) {
|
||||
cbb->child = NULL;
|
||||
}
|
||||
|
||||
int CBB_add_asn1_element(CBB *cbb, CBS_ASN1_TAG tag, const uint8_t *data,
|
||||
size_t data_len) {
|
||||
CBB child;
|
||||
if (!CBB_add_asn1(cbb, &child, tag) ||
|
||||
!CBB_add_bytes(&child, data, data_len) || //
|
||||
!CBB_flush(cbb)) {
|
||||
cbb_on_error(cbb);
|
||||
return 0;
|
||||
}
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
int CBB_add_asn1_uint64(CBB *cbb, uint64_t value) {
|
||||
return CBB_add_asn1_uint64_with_tag(cbb, value, CBS_ASN1_INTEGER);
|
||||
}
|
||||
@@ -557,14 +577,7 @@ err:
|
||||
}
|
||||
|
||||
int CBB_add_asn1_octet_string(CBB *cbb, const uint8_t *data, size_t data_len) {
|
||||
CBB child;
|
||||
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;
|
||||
}
|
||||
|
||||
return 1;
|
||||
return CBB_add_asn1_element(cbb, CBS_ASN1_OCTETSTRING, data, data_len);
|
||||
}
|
||||
|
||||
int CBB_add_asn1_bool(CBB *cbb, int value) {
|
||||
|
||||
@@ -1,16 +1,16 @@
|
||||
/* Copyright 2014 The BoringSSL Authors
|
||||
*
|
||||
* 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. */
|
||||
// Copyright 2014 The BoringSSL Authors
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// https://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
#include <CCryptoBoringSSL_asn1.h>
|
||||
#include <CCryptoBoringSSL_bytestring.h>
|
||||
@@ -410,7 +410,7 @@ int CBS_get_any_asn1(CBS *cbs, CBS *out, CBS_ASN1_TAG *out_tag) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (!CBS_skip(out, header_len)) {
|
||||
if (out && !CBS_skip(out, header_len)) {
|
||||
assert(0);
|
||||
return 0;
|
||||
}
|
||||
@@ -472,8 +472,12 @@ int CBS_peek_asn1_tag(const CBS *cbs, CBS_ASN1_TAG tag_value) {
|
||||
}
|
||||
|
||||
int CBS_get_asn1_uint64(CBS *cbs, uint64_t *out) {
|
||||
return CBS_get_asn1_uint64_with_tag(cbs, out, CBS_ASN1_INTEGER);
|
||||
}
|
||||
|
||||
int CBS_get_asn1_uint64_with_tag(CBS *cbs, uint64_t *out, CBS_ASN1_TAG tag) {
|
||||
CBS bytes;
|
||||
if (!CBS_get_asn1(cbs, &bytes, CBS_ASN1_INTEGER) ||
|
||||
if (!CBS_get_asn1(cbs, &bytes, tag) ||
|
||||
!CBS_is_unsigned_asn1_integer(&bytes)) {
|
||||
return 0;
|
||||
}
|
||||
@@ -494,9 +498,13 @@ int CBS_get_asn1_uint64(CBS *cbs, uint64_t *out) {
|
||||
}
|
||||
|
||||
int CBS_get_asn1_int64(CBS *cbs, int64_t *out) {
|
||||
return CBS_get_asn1_int64_with_tag(cbs, out, CBS_ASN1_INTEGER);
|
||||
}
|
||||
|
||||
int CBS_get_asn1_int64_with_tag(CBS *cbs, int64_t *out, CBS_ASN1_TAG tag) {
|
||||
int is_negative;
|
||||
CBS bytes;
|
||||
if (!CBS_get_asn1(cbs, &bytes, CBS_ASN1_INTEGER) ||
|
||||
if (!CBS_get_asn1(cbs, &bytes, tag) ||
|
||||
!CBS_is_valid_asn1_integer(&bytes, &is_negative)) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -1,19 +1,19 @@
|
||||
/* Copyright 2014 The BoringSSL Authors
|
||||
*
|
||||
* 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. */
|
||||
// Copyright 2014 The BoringSSL Authors
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// https://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
#ifndef OPENSSL_HEADER_BYTESTRING_INTERNAL_H
|
||||
#define OPENSSL_HEADER_BYTESTRING_INTERNAL_H
|
||||
#ifndef OPENSSL_HEADER_CRYPTO_BYTESTRING_INTERNAL_H
|
||||
#define OPENSSL_HEADER_CRYPTO_BYTESTRING_INTERNAL_H
|
||||
|
||||
#include <CCryptoBoringSSL_base.h>
|
||||
|
||||
@@ -71,4 +71,4 @@ int CBB_finish_i2d(CBB *cbb, uint8_t **outp);
|
||||
} // extern C
|
||||
#endif
|
||||
|
||||
#endif // OPENSSL_HEADER_BYTESTRING_INTERNAL_H
|
||||
#endif // OPENSSL_HEADER_CRYPTO_BYTESTRING_INTERNAL_H
|
||||
@@ -1,16 +1,16 @@
|
||||
/* Copyright 2018 The BoringSSL Authors
|
||||
*
|
||||
* 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. */
|
||||
// Copyright 2018 The BoringSSL Authors
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// https://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
#include <CCryptoBoringSSL_bytestring.h>
|
||||
|
||||
|
||||
@@ -1,16 +1,16 @@
|
||||
/* Copyright 2014 The BoringSSL Authors
|
||||
*
|
||||
* 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. */
|
||||
// Copyright 2014 The BoringSSL Authors
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// https://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
// Adapted from the public domain, estream code by D. Bernstein.
|
||||
|
||||
|
||||
@@ -1,19 +1,19 @@
|
||||
/* Copyright 2018 The BoringSSL Authors
|
||||
*
|
||||
* 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. */
|
||||
// Copyright 2018 The BoringSSL Authors
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// https://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
#ifndef OPENSSL_HEADER_CHACHA_INTERNAL
|
||||
#define OPENSSL_HEADER_CHACHA_INTERNAL
|
||||
#ifndef OPENSSL_HEADER_CRYPTO_CHACHA_INTERNAL_H
|
||||
#define OPENSSL_HEADER_CRYPTO_CHACHA_INTERNAL_H
|
||||
|
||||
#include <CCryptoBoringSSL_base.h>
|
||||
|
||||
@@ -34,10 +34,10 @@ void CRYPTO_hchacha20(uint8_t out[32], const uint8_t key[32],
|
||||
#define CHACHA20_ASM_NOHW
|
||||
|
||||
#define CHACHA20_ASM_SSSE3
|
||||
OPENSSL_INLINE int ChaCha20_ctr32_ssse3_capable(size_t len) {
|
||||
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();
|
||||
return len > 0 && 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]);
|
||||
@@ -48,7 +48,7 @@ void ChaCha20_ctr32_ssse3(uint8_t *out, const uint8_t *in, size_t in_len,
|
||||
#define CHACHA20_ASM_NOHW
|
||||
|
||||
#define CHACHA20_ASM_NEON
|
||||
OPENSSL_INLINE int ChaCha20_ctr32_neon_capable(size_t len) {
|
||||
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,
|
||||
@@ -57,14 +57,14 @@ void ChaCha20_ctr32_neon(uint8_t *out, const uint8_t *in, size_t in_len,
|
||||
#define CHACHA20_ASM_NOHW
|
||||
|
||||
#define CHACHA20_ASM_AVX2
|
||||
OPENSSL_INLINE int ChaCha20_ctr32_avx2_capable(size_t len) {
|
||||
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) {
|
||||
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;
|
||||
@@ -73,7 +73,7 @@ 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) {
|
||||
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,
|
||||
@@ -99,4 +99,4 @@ void ChaCha20_ctr32_nohw(uint8_t *out, const uint8_t *in, size_t in_len,
|
||||
} // extern C
|
||||
#endif
|
||||
|
||||
#endif // OPENSSL_HEADER_CHACHA_INTERNAL
|
||||
#endif // OPENSSL_HEADER_CRYPTO_CHACHA_INTERNAL_H
|
||||
@@ -0,0 +1,106 @@
|
||||
// Copyright 1995-2016 The OpenSSL Project Authors. All Rights Reserved.
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// https://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
#include <CCryptoBoringSSL_cipher.h>
|
||||
|
||||
#include <assert.h>
|
||||
|
||||
#include <CCryptoBoringSSL_digest.h>
|
||||
#include <CCryptoBoringSSL_mem.h>
|
||||
|
||||
|
||||
int EVP_BytesToKey(const EVP_CIPHER *type, const EVP_MD *md,
|
||||
const uint8_t salt[8], const uint8_t *data, size_t data_len,
|
||||
unsigned count, uint8_t *key, uint8_t *iv) {
|
||||
uint8_t md_buf[EVP_MAX_MD_SIZE];
|
||||
unsigned addmd = 0;
|
||||
unsigned mds = 0, i;
|
||||
int rv = 0;
|
||||
|
||||
unsigned nkey = EVP_CIPHER_key_length(type);
|
||||
unsigned niv = EVP_CIPHER_iv_length(type);
|
||||
|
||||
assert(nkey <= EVP_MAX_KEY_LENGTH);
|
||||
assert(niv <= EVP_MAX_IV_LENGTH);
|
||||
|
||||
if (data == nullptr) {
|
||||
return nkey;
|
||||
}
|
||||
|
||||
bssl::ScopedEVP_MD_CTX c;
|
||||
for (;;) {
|
||||
if (!EVP_DigestInit_ex(c.get(), md, nullptr)) {
|
||||
goto err;
|
||||
}
|
||||
if (addmd++) {
|
||||
if (!EVP_DigestUpdate(c.get(), md_buf, mds)) {
|
||||
goto err;
|
||||
}
|
||||
}
|
||||
if (!EVP_DigestUpdate(c.get(), data, data_len)) {
|
||||
goto err;
|
||||
}
|
||||
if (salt != nullptr) {
|
||||
if (!EVP_DigestUpdate(c.get(), salt, 8)) {
|
||||
goto err;
|
||||
}
|
||||
}
|
||||
if (!EVP_DigestFinal_ex(c.get(), md_buf, &mds)) {
|
||||
goto err;
|
||||
}
|
||||
|
||||
for (i = 1; i < count; i++) {
|
||||
if (!EVP_DigestInit_ex(c.get(), md, nullptr) ||
|
||||
!EVP_DigestUpdate(c.get(), md_buf, mds) ||
|
||||
!EVP_DigestFinal_ex(c.get(), md_buf, &mds)) {
|
||||
goto err;
|
||||
}
|
||||
}
|
||||
|
||||
i = 0;
|
||||
if (nkey) {
|
||||
for (;;) {
|
||||
if (nkey == 0 || i == mds) {
|
||||
break;
|
||||
}
|
||||
if (key != nullptr) {
|
||||
*(key++) = md_buf[i];
|
||||
}
|
||||
nkey--;
|
||||
i++;
|
||||
}
|
||||
}
|
||||
|
||||
if (niv && i != mds) {
|
||||
for (;;) {
|
||||
if (niv == 0 || i == mds) {
|
||||
break;
|
||||
}
|
||||
if (iv != nullptr) {
|
||||
*(iv++) = md_buf[i];
|
||||
}
|
||||
niv--;
|
||||
i++;
|
||||
}
|
||||
}
|
||||
if (nkey == 0 && niv == 0) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
rv = EVP_CIPHER_key_length(type);
|
||||
|
||||
err:
|
||||
OPENSSL_cleanse(md_buf, EVP_MAX_MD_SIZE);
|
||||
return rv;
|
||||
}
|
||||
+18
-23
@@ -1,16 +1,16 @@
|
||||
/* Copyright 2017 The BoringSSL Authors
|
||||
*
|
||||
* 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. */
|
||||
// Copyright 2017 The BoringSSL Authors
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// https://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
#include <CCryptoBoringSSL_aead.h>
|
||||
|
||||
@@ -21,6 +21,7 @@
|
||||
#include <CCryptoBoringSSL_err.h>
|
||||
#include <CCryptoBoringSSL_sha.h>
|
||||
|
||||
#include "../fipsmodule/aes/internal.h"
|
||||
#include "../fipsmodule/cipher/internal.h"
|
||||
|
||||
|
||||
@@ -154,7 +155,7 @@ static void aead_aes_ctr_hmac_sha256_crypt(
|
||||
const struct aead_aes_ctr_hmac_sha256_ctx *aes_ctx, uint8_t *out,
|
||||
const uint8_t *in, size_t len, const uint8_t *nonce) {
|
||||
// Since the AEAD operation is one-shot, keeping a buffer of unused keystream
|
||||
// bytes is pointless. However, |CRYPTO_ctr128_encrypt| requires it.
|
||||
// bytes is pointless. However, |CRYPTO_ctr128_encrypt_ctr32| requires it.
|
||||
uint8_t partial_block_buffer[AES_BLOCK_SIZE];
|
||||
unsigned partial_block_offset = 0;
|
||||
OPENSSL_memset(partial_block_buffer, 0, sizeof(partial_block_buffer));
|
||||
@@ -163,15 +164,9 @@ static void aead_aes_ctr_hmac_sha256_crypt(
|
||||
OPENSSL_memcpy(counter, nonce, EVP_AEAD_AES_CTR_HMAC_SHA256_NONCE_LEN);
|
||||
OPENSSL_memset(counter + EVP_AEAD_AES_CTR_HMAC_SHA256_NONCE_LEN, 0, 4);
|
||||
|
||||
if (aes_ctx->ctr) {
|
||||
CRYPTO_ctr128_encrypt_ctr32(in, out, len, &aes_ctx->ks.ks, counter,
|
||||
partial_block_buffer, &partial_block_offset,
|
||||
aes_ctx->ctr);
|
||||
} else {
|
||||
CRYPTO_ctr128_encrypt(in, out, len, &aes_ctx->ks.ks, counter,
|
||||
partial_block_buffer, &partial_block_offset,
|
||||
aes_ctx->block);
|
||||
}
|
||||
CRYPTO_ctr128_encrypt_ctr32(in, out, len, &aes_ctx->ks.ks, counter,
|
||||
partial_block_buffer, &partial_block_offset,
|
||||
aes_ctx->ctr);
|
||||
}
|
||||
|
||||
static int aead_aes_ctr_hmac_sha256_seal_scatter(
|
||||
@@ -0,0 +1,289 @@
|
||||
// Copyright 2025 The BoringSSL Authors
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// https://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
#include <CCryptoBoringSSL_aead.h>
|
||||
|
||||
#include <assert.h>
|
||||
#include <stddef.h>
|
||||
#include <stdint.h>
|
||||
#include <sys/types.h>
|
||||
|
||||
#include <CCryptoBoringSSL_aes.h>
|
||||
#include <CCryptoBoringSSL_base.h>
|
||||
#include <CCryptoBoringSSL_cipher.h>
|
||||
#include <CCryptoBoringSSL_crypto.h>
|
||||
#include <CCryptoBoringSSL_err.h>
|
||||
#include <CCryptoBoringSSL_mem.h>
|
||||
|
||||
#include "../fipsmodule/cipher/internal.h"
|
||||
#include "../internal.h"
|
||||
|
||||
// Implementation of AES-EAX defined in
|
||||
// https://www.iacr.org/archive/fse2004/30170391/30170391.pdf.
|
||||
|
||||
#define EVP_AEAD_AES_EAX_TAG_LEN AES_BLOCK_SIZE
|
||||
|
||||
struct aead_aes_eax_ctx {
|
||||
union {
|
||||
double align;
|
||||
AES_KEY ks;
|
||||
} ks;
|
||||
uint8_t b[AES_BLOCK_SIZE];
|
||||
uint8_t p[AES_BLOCK_SIZE];
|
||||
};
|
||||
|
||||
static void mult_by_X(uint8_t out[AES_BLOCK_SIZE],
|
||||
const uint8_t in[AES_BLOCK_SIZE]) {
|
||||
const crypto_word_t in_hi = CRYPTO_load_word_be(in);
|
||||
for (size_t i = 0; i < AES_BLOCK_SIZE - 1; ++i) {
|
||||
out[i] = (in[i] << 1) | (in[i + 1] >> 7);
|
||||
}
|
||||
// Carry over 0x87 if msb is 1, 0x00 if msb is 0.
|
||||
out[AES_BLOCK_SIZE - 1] = in[AES_BLOCK_SIZE - 1] << 1;
|
||||
const uint8_t p = 0x87;
|
||||
constant_time_conditional_memxor(out + AES_BLOCK_SIZE - 1, &p, /*n=*/1,
|
||||
constant_time_msb_w(in_hi));
|
||||
}
|
||||
|
||||
static int aead_aes_eax_init(EVP_AEAD_CTX *ctx, const uint8_t *key,
|
||||
size_t key_len, size_t tag_len) {
|
||||
struct aead_aes_eax_ctx *aes_ctx = (struct aead_aes_eax_ctx *)&ctx->state;
|
||||
|
||||
if (key_len != 16 && key_len != 32) {
|
||||
OPENSSL_PUT_ERROR(CIPHER, CIPHER_R_BAD_KEY_LENGTH);
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (tag_len == EVP_AEAD_DEFAULT_TAG_LENGTH) {
|
||||
tag_len = EVP_AEAD_AES_EAX_TAG_LEN;
|
||||
}
|
||||
|
||||
if (tag_len != EVP_AEAD_AES_EAX_TAG_LEN) {
|
||||
OPENSSL_PUT_ERROR(CIPHER, CIPHER_R_UNSUPPORTED_TAG_SIZE);
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (AES_set_encrypt_key(key, /*bits=*/key_len * 8, &aes_ctx->ks.ks) != 0) {
|
||||
OPENSSL_PUT_ERROR(CIPHER, CIPHER_R_AES_KEY_SETUP_FAILED);
|
||||
return 0;
|
||||
}
|
||||
ctx->tag_len = tag_len;
|
||||
|
||||
// L <- Ek(0^n).
|
||||
OPENSSL_memset(aes_ctx->b, 0, sizeof(aes_ctx->b));
|
||||
AES_encrypt(aes_ctx->b, aes_ctx->b, &aes_ctx->ks.ks);
|
||||
// B <- 2L.
|
||||
mult_by_X(aes_ctx->b, aes_ctx->b);
|
||||
// P <- 4L = 2B.
|
||||
mult_by_X(aes_ctx->p, aes_ctx->b);
|
||||
return 1;
|
||||
}
|
||||
|
||||
static void aead_aes_eax_cleanup(EVP_AEAD_CTX *ctx) {}
|
||||
|
||||
// Implements the CBK function in the paper.
|
||||
static void cbk_block(const struct aead_aes_eax_ctx *aes_ctx,
|
||||
const uint8_t in[AES_BLOCK_SIZE],
|
||||
uint8_t out[AES_BLOCK_SIZE]) {
|
||||
CRYPTO_xor16(out, in, out);
|
||||
AES_encrypt(out, out, &aes_ctx->ks.ks);
|
||||
}
|
||||
|
||||
// Precondition: in_len <= AES_BLOCK_SIZE.
|
||||
static void pad(const struct aead_aes_eax_ctx *aes_ctx,
|
||||
uint8_t out[AES_BLOCK_SIZE], const uint8_t *in, size_t in_len) {
|
||||
assert(in_len <= AES_BLOCK_SIZE);
|
||||
if (in_len == AES_BLOCK_SIZE) {
|
||||
CRYPTO_xor16(out, aes_ctx->b, in);
|
||||
return;
|
||||
}
|
||||
OPENSSL_memset(out, 0, AES_BLOCK_SIZE);
|
||||
OPENSSL_memcpy(out, in, in_len);
|
||||
out[in_len] = 0x80;
|
||||
CRYPTO_xor16(out, aes_ctx->p, out);
|
||||
}
|
||||
|
||||
static void omac(const struct aead_aes_eax_ctx *aes_ctx,
|
||||
uint8_t out[AES_BLOCK_SIZE], const uint8_t *in,
|
||||
size_t in_len) {
|
||||
if (in_len == 0) {
|
||||
// CBK(pad(M;B,P)) = CBK(B). Avoiding padding to skip a copy.
|
||||
cbk_block(aes_ctx, aes_ctx->b, out);
|
||||
return;
|
||||
}
|
||||
// CBK(M1) = Ek(M1 ^ 0^n)
|
||||
AES_encrypt(out, out, &aes_ctx->ks.ks);
|
||||
while (in_len > AES_BLOCK_SIZE) {
|
||||
// Full blocks, no padding needed.
|
||||
cbk_block(aes_ctx, in, out);
|
||||
in += AES_BLOCK_SIZE;
|
||||
in_len -= AES_BLOCK_SIZE;
|
||||
}
|
||||
// Last block to be padded.
|
||||
uint8_t padded_block[AES_BLOCK_SIZE];
|
||||
pad(aes_ctx, padded_block, in, in_len);
|
||||
cbk_block(aes_ctx, padded_block, out);
|
||||
}
|
||||
|
||||
static void omac_with_tag(const struct aead_aes_eax_ctx *aes_ctx,
|
||||
uint8_t out[AES_BLOCK_SIZE], const uint8_t *in,
|
||||
size_t in_len, int tag) {
|
||||
OPENSSL_memset(out, 0, AES_BLOCK_SIZE);
|
||||
out[AES_BLOCK_SIZE - 1] = tag;
|
||||
omac(aes_ctx, out, in, in_len);
|
||||
}
|
||||
|
||||
// Encrypts/decrypts |in_len| bytes from |in| to |out| using AES-CTR with |n| as
|
||||
// the IV.
|
||||
static void aes_ctr(const struct aead_aes_eax_ctx *aes_ctx, uint8_t *out,
|
||||
const uint8_t n[AES_BLOCK_SIZE], const uint8_t *in,
|
||||
size_t in_len) {
|
||||
uint8_t ivec[AES_BLOCK_SIZE];
|
||||
OPENSSL_memcpy(ivec, n, AES_BLOCK_SIZE);
|
||||
|
||||
uint8_t unused_ecount_buf[AES_BLOCK_SIZE];
|
||||
unsigned int unused_num = 0;
|
||||
AES_ctr128_encrypt(in, out, in_len, &aes_ctx->ks.ks, ivec, unused_ecount_buf,
|
||||
&unused_num);
|
||||
}
|
||||
|
||||
static int aead_aes_eax_seal_scatter(
|
||||
const EVP_AEAD_CTX *ctx, uint8_t *out, uint8_t *out_tag,
|
||||
size_t *out_tag_len, size_t max_out_tag_len, const uint8_t *nonce,
|
||||
size_t nonce_len, const uint8_t *in, size_t in_len, const uint8_t *extra_in,
|
||||
size_t extra_in_len, const uint8_t *ad, size_t ad_len) {
|
||||
assert(extra_in_len == 0);
|
||||
// We use the full 128 bits of the nonce as counter, so no need to check the
|
||||
// plaintext size.
|
||||
|
||||
if (max_out_tag_len < ctx->tag_len) {
|
||||
OPENSSL_PUT_ERROR(CIPHER, CIPHER_R_BUFFER_TOO_SMALL);
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (nonce_len != 12 && nonce_len != 16) {
|
||||
OPENSSL_PUT_ERROR(CIPHER, CIPHER_R_UNSUPPORTED_NONCE_SIZE);
|
||||
return 0;
|
||||
}
|
||||
|
||||
const struct aead_aes_eax_ctx *aes_ctx =
|
||||
(struct aead_aes_eax_ctx *)&ctx->state;
|
||||
|
||||
// N <- OMAC(0 || nonce)
|
||||
uint8_t n[AES_BLOCK_SIZE];
|
||||
omac_with_tag(aes_ctx, n, nonce, nonce_len, /*tag=*/0);
|
||||
// H <- OMAC(1 || ad)
|
||||
uint8_t h[AES_BLOCK_SIZE];
|
||||
omac_with_tag(aes_ctx, h, ad, ad_len, /*tag=*/1);
|
||||
|
||||
// C <- CTR^{N}_{K}(M)
|
||||
aes_ctr(aes_ctx, out, n, in, in_len);
|
||||
|
||||
// MAC <- OMAC(2 || C)
|
||||
omac_with_tag(aes_ctx, out_tag, out, in_len, /*tag=*/2);
|
||||
// MAC <- N ^ C ^ H
|
||||
CRYPTO_xor16(out_tag, n, out_tag);
|
||||
CRYPTO_xor16(out_tag, h, out_tag);
|
||||
|
||||
*out_tag_len = ctx->tag_len;
|
||||
return 1;
|
||||
}
|
||||
|
||||
static int aead_aes_eax_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) {
|
||||
const uint64_t ad_len_64 = ad_len;
|
||||
if (ad_len_64 >= (UINT64_C(1) << 61)) {
|
||||
OPENSSL_PUT_ERROR(CIPHER, CIPHER_R_TOO_LARGE);
|
||||
return 0;
|
||||
}
|
||||
|
||||
const uint64_t in_len_64 = in_len;
|
||||
if (in_tag_len != EVP_AEAD_AES_EAX_TAG_LEN ||
|
||||
in_len_64 > (UINT64_C(1) << 36) + AES_BLOCK_SIZE) {
|
||||
OPENSSL_PUT_ERROR(CIPHER, CIPHER_R_BAD_DECRYPT);
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (nonce_len != 12 && nonce_len != 16) {
|
||||
OPENSSL_PUT_ERROR(CIPHER, CIPHER_R_UNSUPPORTED_NONCE_SIZE);
|
||||
return 0;
|
||||
}
|
||||
|
||||
const struct aead_aes_eax_ctx *aes_ctx =
|
||||
(struct aead_aes_eax_ctx *)&ctx->state;
|
||||
|
||||
// N <- OMAC(0 || nonce)
|
||||
uint8_t n[AES_BLOCK_SIZE];
|
||||
omac_with_tag(aes_ctx, n, nonce, nonce_len, /*tag=*/0);
|
||||
// H <- OMAC(1 || ad)
|
||||
uint8_t h[AES_BLOCK_SIZE];
|
||||
omac_with_tag(aes_ctx, h, ad, ad_len, /*tag=*/1);
|
||||
|
||||
// MAC <- OMAC(2 || C)
|
||||
uint8_t mac[AES_BLOCK_SIZE];
|
||||
omac_with_tag(aes_ctx, mac, in, in_len, /*tag=*/2);
|
||||
// MAC <- N ^ C ^ H
|
||||
CRYPTO_xor16(mac, n, mac);
|
||||
CRYPTO_xor16(mac, h, mac);
|
||||
|
||||
if (CRYPTO_memcmp(mac, in_tag, in_tag_len) != 0) {
|
||||
OPENSSL_PUT_ERROR(CIPHER, CIPHER_R_BAD_DECRYPT);
|
||||
return 0;
|
||||
}
|
||||
|
||||
// M <- CTR^{N}_{K}(C)
|
||||
aes_ctr(aes_ctx, out, n, in, in_len);
|
||||
return 1;
|
||||
}
|
||||
|
||||
static const EVP_AEAD aead_aes_128_eax = {
|
||||
16, // AES key size
|
||||
16, // nonce length
|
||||
EVP_AEAD_AES_EAX_TAG_LEN, // overhead
|
||||
EVP_AEAD_AES_EAX_TAG_LEN, // max tag length
|
||||
0, // seal_scatter_supports_extra_in
|
||||
|
||||
aead_aes_eax_init,
|
||||
NULL, // init_with_direction
|
||||
aead_aes_eax_cleanup,
|
||||
NULL, // open
|
||||
aead_aes_eax_seal_scatter,
|
||||
aead_aes_eax_open_gather,
|
||||
NULL, // get_iv
|
||||
NULL, // tag_len
|
||||
};
|
||||
|
||||
static const EVP_AEAD aead_aes_256_eax = {
|
||||
32, // AES key size
|
||||
16, // nonce length
|
||||
EVP_AEAD_AES_EAX_TAG_LEN, // overhead
|
||||
EVP_AEAD_AES_EAX_TAG_LEN, // max tag length
|
||||
0, // seal_scatter_supports_extra_in
|
||||
|
||||
aead_aes_eax_init,
|
||||
NULL, // init_with_direction
|
||||
aead_aes_eax_cleanup,
|
||||
NULL, // open
|
||||
aead_aes_eax_seal_scatter,
|
||||
aead_aes_eax_open_gather,
|
||||
NULL, // get_iv
|
||||
NULL, // tag_len
|
||||
};
|
||||
|
||||
const EVP_AEAD *EVP_aead_aes_128_eax(void) { return &aead_aes_128_eax; }
|
||||
|
||||
const EVP_AEAD *EVP_aead_aes_256_eax(void) { return &aead_aes_256_eax; }
|
||||
+193
-109
@@ -1,16 +1,16 @@
|
||||
/* Copyright 2017 The BoringSSL Authors
|
||||
*
|
||||
* 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. */
|
||||
// Copyright 2017 The BoringSSL Authors
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// https://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
#include <CCryptoBoringSSL_aead.h>
|
||||
|
||||
@@ -20,6 +20,7 @@
|
||||
#include <CCryptoBoringSSL_crypto.h>
|
||||
#include <CCryptoBoringSSL_err.h>
|
||||
|
||||
#include "../fipsmodule/aes/internal.h"
|
||||
#include "../fipsmodule/cipher/internal.h"
|
||||
#include "../internal.h"
|
||||
|
||||
@@ -27,6 +28,7 @@
|
||||
#define EVP_AEAD_AES_GCM_SIV_NONCE_LEN 12
|
||||
#define EVP_AEAD_AES_GCM_SIV_TAG_LEN 16
|
||||
|
||||
namespace {
|
||||
// TODO(davidben): AES-GCM-SIV assembly is not correct for Windows. It must save
|
||||
// and restore xmm6 through xmm15.
|
||||
#if defined(OPENSSL_X86_64) && !defined(OPENSSL_NO_ASM) && \
|
||||
@@ -48,15 +50,6 @@ static_assert(sizeof(((EVP_AEAD_CTX *)NULL)->state) + 8 >=
|
||||
static_assert(alignof(union evp_aead_ctx_st_state) >= 8,
|
||||
"AEAD state has insufficient alignment");
|
||||
|
||||
// asm_ctx_from_ctx returns a 16-byte aligned context pointer from |ctx|.
|
||||
static struct aead_aes_gcm_siv_asm_ctx *asm_ctx_from_ctx(
|
||||
const EVP_AEAD_CTX *ctx) {
|
||||
// ctx->state must already be 8-byte aligned. Thus, at most, we may need to
|
||||
// add eight to align it to 16 bytes.
|
||||
const uintptr_t offset = ((uintptr_t)&ctx->state) & 8;
|
||||
return (struct aead_aes_gcm_siv_asm_ctx *)(&ctx->state.opaque[offset]);
|
||||
}
|
||||
|
||||
extern "C" {
|
||||
// aes128gcmsiv_aes_ks writes an AES-128 key schedule for |key| to
|
||||
// |out_expanded_key|.
|
||||
@@ -67,45 +60,7 @@ extern void aes128gcmsiv_aes_ks(const uint8_t key[16],
|
||||
// |out_expanded_key|.
|
||||
extern void aes256gcmsiv_aes_ks(const uint8_t key[32],
|
||||
uint8_t out_expanded_key[16 * 15]);
|
||||
}
|
||||
|
||||
static int aead_aes_gcm_siv_asm_init(EVP_AEAD_CTX *ctx, const uint8_t *key,
|
||||
size_t key_len, size_t tag_len) {
|
||||
const size_t key_bits = key_len * 8;
|
||||
|
||||
if (key_bits != 128 && key_bits != 256) {
|
||||
OPENSSL_PUT_ERROR(CIPHER, CIPHER_R_BAD_KEY_LENGTH);
|
||||
return 0; // EVP_AEAD_CTX_init should catch this.
|
||||
}
|
||||
|
||||
if (tag_len == EVP_AEAD_DEFAULT_TAG_LENGTH) {
|
||||
tag_len = EVP_AEAD_AES_GCM_SIV_TAG_LEN;
|
||||
}
|
||||
|
||||
if (tag_len != EVP_AEAD_AES_GCM_SIV_TAG_LEN) {
|
||||
OPENSSL_PUT_ERROR(CIPHER, CIPHER_R_TAG_TOO_LARGE);
|
||||
return 0;
|
||||
}
|
||||
|
||||
struct aead_aes_gcm_siv_asm_ctx *gcm_siv_ctx = asm_ctx_from_ctx(ctx);
|
||||
assert((((uintptr_t)gcm_siv_ctx) & 15) == 0);
|
||||
|
||||
if (key_bits == 128) {
|
||||
aes128gcmsiv_aes_ks(key, &gcm_siv_ctx->key[0]);
|
||||
gcm_siv_ctx->is_128_bit = 1;
|
||||
} else {
|
||||
aes256gcmsiv_aes_ks(key, &gcm_siv_ctx->key[0]);
|
||||
gcm_siv_ctx->is_128_bit = 0;
|
||||
}
|
||||
|
||||
ctx->tag_len = tag_len;
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
static void aead_aes_gcm_siv_asm_cleanup(EVP_AEAD_CTX *ctx) {}
|
||||
|
||||
extern "C" {
|
||||
// aesgcmsiv_polyval_horner updates the POLYVAL value in |in_out_poly| to
|
||||
// include a number (|in_blocks|) of 16-byte blocks of data from |in|, given
|
||||
// the POLYVAL key in |key|.
|
||||
@@ -222,12 +177,55 @@ extern void aes256gcmsiv_enc_msg_x8(const uint8_t *in, uint8_t *out,
|
||||
size_t in_len);
|
||||
}
|
||||
|
||||
// asm_ctx_from_ctx returns a 16-byte aligned context pointer from |ctx|.
|
||||
struct aead_aes_gcm_siv_asm_ctx *asm_ctx_from_ctx(const EVP_AEAD_CTX *ctx) {
|
||||
// ctx->state must already be 8-byte aligned. Thus, at most, we may need to
|
||||
// add eight to align it to 16 bytes.
|
||||
const uintptr_t offset = ((uintptr_t)&ctx->state) & 8;
|
||||
return (struct aead_aes_gcm_siv_asm_ctx *)(&ctx->state.opaque[offset]);
|
||||
}
|
||||
|
||||
int aead_aes_gcm_siv_asm_init(EVP_AEAD_CTX *ctx, const uint8_t *key,
|
||||
size_t key_len, size_t tag_len) {
|
||||
const size_t key_bits = key_len * 8;
|
||||
|
||||
if (key_bits != 128 && key_bits != 256) {
|
||||
OPENSSL_PUT_ERROR(CIPHER, CIPHER_R_BAD_KEY_LENGTH);
|
||||
return 0; // EVP_AEAD_CTX_init should catch this.
|
||||
}
|
||||
|
||||
if (tag_len == EVP_AEAD_DEFAULT_TAG_LENGTH) {
|
||||
tag_len = EVP_AEAD_AES_GCM_SIV_TAG_LEN;
|
||||
}
|
||||
|
||||
if (tag_len != EVP_AEAD_AES_GCM_SIV_TAG_LEN) {
|
||||
OPENSSL_PUT_ERROR(CIPHER, CIPHER_R_TAG_TOO_LARGE);
|
||||
return 0;
|
||||
}
|
||||
|
||||
struct aead_aes_gcm_siv_asm_ctx *gcm_siv_ctx = asm_ctx_from_ctx(ctx);
|
||||
assert((((uintptr_t)gcm_siv_ctx) & 15) == 0);
|
||||
|
||||
if (key_bits == 128) {
|
||||
aes128gcmsiv_aes_ks(key, &gcm_siv_ctx->key[0]);
|
||||
gcm_siv_ctx->is_128_bit = 1;
|
||||
} else {
|
||||
aes256gcmsiv_aes_ks(key, &gcm_siv_ctx->key[0]);
|
||||
gcm_siv_ctx->is_128_bit = 0;
|
||||
}
|
||||
|
||||
ctx->tag_len = tag_len;
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
void aead_aes_gcm_siv_asm_cleanup(EVP_AEAD_CTX *ctx) {}
|
||||
|
||||
// gcm_siv_asm_polyval evaluates POLYVAL at |auth_key| on the given plaintext
|
||||
// and AD. The result is written to |out_tag|.
|
||||
static void gcm_siv_asm_polyval(uint8_t out_tag[16], const uint8_t *in,
|
||||
size_t in_len, const uint8_t *ad, size_t ad_len,
|
||||
const uint8_t auth_key[16],
|
||||
const uint8_t nonce[12]) {
|
||||
void gcm_siv_asm_polyval(uint8_t out_tag[16], const uint8_t *in, size_t in_len,
|
||||
const uint8_t *ad, size_t ad_len,
|
||||
const uint8_t auth_key[16], const uint8_t nonce[12]) {
|
||||
OPENSSL_memset(out_tag, 0, 16);
|
||||
const size_t ad_blocks = ad_len / 16;
|
||||
const size_t in_blocks = in_len / 16;
|
||||
@@ -280,7 +278,7 @@ static void gcm_siv_asm_polyval(uint8_t out_tag[16], const uint8_t *in,
|
||||
// (same thing in CTR mode) of the final block of a plaintext/ciphertext. It
|
||||
// writes |in_len| & 15 bytes to |out| + |in_len|, based on an initial counter
|
||||
// derived from |tag|.
|
||||
static void aead_aes_gcm_siv_asm_crypt_last_block(
|
||||
void aead_aes_gcm_siv_asm_crypt_last_block(
|
||||
int is_128_bit, uint8_t *out, const uint8_t *in, size_t in_len,
|
||||
const uint8_t tag[16],
|
||||
const struct aead_aes_gcm_siv_asm_ctx *enc_key_expanded) {
|
||||
@@ -306,10 +304,11 @@ static void aead_aes_gcm_siv_asm_crypt_last_block(
|
||||
|
||||
// aead_aes_gcm_siv_kdf calculates the record encryption and authentication
|
||||
// keys given the |nonce|.
|
||||
static void aead_aes_gcm_siv_kdf(
|
||||
int is_128_bit, const struct aead_aes_gcm_siv_asm_ctx *gcm_siv_ctx,
|
||||
uint64_t out_record_auth_key[2], uint64_t out_record_enc_key[4],
|
||||
const uint8_t nonce[12]) {
|
||||
void aead_aes_gcm_siv_kdf(int is_128_bit,
|
||||
const struct aead_aes_gcm_siv_asm_ctx *gcm_siv_ctx,
|
||||
uint64_t out_record_auth_key[2],
|
||||
uint64_t out_record_enc_key[4],
|
||||
const uint8_t nonce[12]) {
|
||||
alignas(16) uint8_t padded_nonce[16];
|
||||
OPENSSL_memcpy(padded_nonce, nonce, 12);
|
||||
|
||||
@@ -330,7 +329,7 @@ static void aead_aes_gcm_siv_kdf(
|
||||
out_record_auth_key[1] = key_material[2];
|
||||
}
|
||||
|
||||
static int aead_aes_gcm_siv_asm_seal_scatter(
|
||||
int aead_aes_gcm_siv_asm_seal_scatter(
|
||||
const EVP_AEAD_CTX *ctx, uint8_t *out, uint8_t *out_tag,
|
||||
size_t *out_tag_len, size_t max_out_tag_len, const uint8_t *nonce,
|
||||
size_t nonce_len, const uint8_t *in, size_t in_len, const uint8_t *extra_in,
|
||||
@@ -396,10 +395,11 @@ 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) {
|
||||
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) {
|
||||
const uint64_t ad_len_64 = ad_len;
|
||||
if (ad_len_64 >= (UINT64_C(1) << 61)) {
|
||||
OPENSSL_PUT_ERROR(CIPHER, CIPHER_R_TOO_LARGE);
|
||||
@@ -496,7 +496,7 @@ static int aead_aes_gcm_siv_asm_open_gather(
|
||||
return 1;
|
||||
}
|
||||
|
||||
static const EVP_AEAD aead_aes_128_gcm_siv_asm = {
|
||||
const EVP_AEAD aead_aes_128_gcm_siv_asm = {
|
||||
16, // key length
|
||||
EVP_AEAD_AES_GCM_SIV_NONCE_LEN, // nonce length
|
||||
EVP_AEAD_AES_GCM_SIV_TAG_LEN, // overhead
|
||||
@@ -513,7 +513,7 @@ static const EVP_AEAD aead_aes_128_gcm_siv_asm = {
|
||||
NULL /* tag_len */,
|
||||
};
|
||||
|
||||
static const EVP_AEAD aead_aes_256_gcm_siv_asm = {
|
||||
const EVP_AEAD aead_aes_256_gcm_siv_asm = {
|
||||
32, // key length
|
||||
EVP_AEAD_AES_GCM_SIV_NONCE_LEN, // nonce length
|
||||
EVP_AEAD_AES_GCM_SIV_TAG_LEN, // overhead
|
||||
@@ -532,6 +532,7 @@ static const EVP_AEAD aead_aes_256_gcm_siv_asm = {
|
||||
|
||||
#endif // X86_64 && !NO_ASM && !WINDOWS
|
||||
|
||||
|
||||
struct aead_aes_gcm_siv_ctx {
|
||||
union {
|
||||
double align;
|
||||
@@ -548,8 +549,8 @@ static_assert(alignof(union evp_aead_ctx_st_state) >=
|
||||
alignof(struct aead_aes_gcm_siv_ctx),
|
||||
"AEAD state has insufficient alignment");
|
||||
|
||||
static int aead_aes_gcm_siv_init(EVP_AEAD_CTX *ctx, const uint8_t *key,
|
||||
size_t key_len, size_t tag_len) {
|
||||
int aead_aes_gcm_siv_init(EVP_AEAD_CTX *ctx, const uint8_t *key, size_t key_len,
|
||||
size_t tag_len) {
|
||||
const size_t key_bits = key_len * 8;
|
||||
|
||||
if (key_bits != 128 && key_bits != 256) {
|
||||
@@ -577,7 +578,7 @@ static int aead_aes_gcm_siv_init(EVP_AEAD_CTX *ctx, const uint8_t *key,
|
||||
return 1;
|
||||
}
|
||||
|
||||
static void aead_aes_gcm_siv_cleanup(EVP_AEAD_CTX *ctx) {}
|
||||
void aead_aes_gcm_siv_cleanup(EVP_AEAD_CTX *ctx) {}
|
||||
|
||||
// gcm_siv_crypt encrypts (or decrypts—it's the same thing) |in_len| bytes from
|
||||
// |in| to |out|, using the block function |enc_block| with |key| in counter
|
||||
@@ -586,9 +587,9 @@ static void aead_aes_gcm_siv_cleanup(EVP_AEAD_CTX *ctx) {}
|
||||
// first four bytes are used and the GCM-SIV tweak to the final byte is
|
||||
// applied. The |in| and |out| pointers may be equal but otherwise must not
|
||||
// alias.
|
||||
static void gcm_siv_crypt(uint8_t *out, const uint8_t *in, size_t in_len,
|
||||
const uint8_t initial_counter[AES_BLOCK_SIZE],
|
||||
block128_f enc_block, const AES_KEY *key) {
|
||||
void gcm_siv_crypt(uint8_t *out, const uint8_t *in, size_t in_len,
|
||||
const uint8_t initial_counter[AES_BLOCK_SIZE],
|
||||
block128_f enc_block, const AES_KEY *key) {
|
||||
uint8_t counter[16];
|
||||
|
||||
OPENSSL_memcpy(counter, initial_counter, AES_BLOCK_SIZE);
|
||||
@@ -612,38 +613,119 @@ static void gcm_siv_crypt(uint8_t *out, const uint8_t *in, size_t in_len,
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// POLYVAL.
|
||||
//
|
||||
// POLYVAL is a polynomial authenticator that operates over a field very
|
||||
// similar to the one that GHASH uses. See
|
||||
// https://www.rfc-editor.org/rfc/rfc8452.html#section-3.
|
||||
|
||||
// POLYVAL(H, X_1, ..., X_n) =
|
||||
// ByteReverse(GHASH(mulX_GHASH(ByteReverse(H)), ByteReverse(X_1), ...,
|
||||
// ByteReverse(X_n))).
|
||||
//
|
||||
// See https://www.rfc-editor.org/rfc/rfc8452.html#appendix-A.
|
||||
|
||||
struct polyval_ctx {
|
||||
uint8_t S[16];
|
||||
u128 Htable[16];
|
||||
gmult_func gmult;
|
||||
ghash_func ghash;
|
||||
};
|
||||
|
||||
// byte_reverse reverses the order of the bytes in |b->c|.
|
||||
void byte_reverse(uint8_t b[16]) {
|
||||
uint64_t hi = CRYPTO_load_u64_le(b);
|
||||
uint64_t lo = CRYPTO_load_u64_le(b + 8);
|
||||
CRYPTO_store_u64_le(b, CRYPTO_bswap8(lo));
|
||||
CRYPTO_store_u64_le(b + 8, CRYPTO_bswap8(hi));
|
||||
}
|
||||
|
||||
// reverse_and_mulX_ghash interprets |b| as a reversed element of the GHASH
|
||||
// field, multiplies that by 'x' and serialises the result back into |b|, but
|
||||
// with GHASH's backwards bit ordering.
|
||||
void reverse_and_mulX_ghash(uint8_t b[16]) {
|
||||
uint64_t hi = CRYPTO_load_u64_le(b);
|
||||
uint64_t lo = CRYPTO_load_u64_le(b + 8);
|
||||
const crypto_word_t carry = constant_time_eq_w(hi & 1, 1);
|
||||
hi >>= 1;
|
||||
hi |= lo << 63;
|
||||
lo >>= 1;
|
||||
lo ^= ((uint64_t)constant_time_select_w(carry, 0xe1, 0)) << 56;
|
||||
|
||||
CRYPTO_store_u64_le(b, CRYPTO_bswap8(lo));
|
||||
CRYPTO_store_u64_le(b + 8, CRYPTO_bswap8(hi));
|
||||
}
|
||||
|
||||
void crypto_polyval_init(struct polyval_ctx *ctx, const uint8_t key[16]) {
|
||||
alignas(8) uint8_t H[16];
|
||||
OPENSSL_memcpy(H, key, 16);
|
||||
reverse_and_mulX_ghash(H);
|
||||
|
||||
CRYPTO_ghash_init(&ctx->gmult, &ctx->ghash, ctx->Htable, H);
|
||||
OPENSSL_memset(&ctx->S, 0, sizeof(ctx->S));
|
||||
}
|
||||
|
||||
void crypto_polyval_update_blocks(struct polyval_ctx *ctx, const uint8_t *in,
|
||||
size_t in_len) {
|
||||
assert((in_len & 15) == 0);
|
||||
alignas(8) uint8_t buf[32 * 16];
|
||||
|
||||
while (in_len > 0) {
|
||||
size_t todo = in_len;
|
||||
if (todo > sizeof(buf)) {
|
||||
todo = sizeof(buf);
|
||||
}
|
||||
OPENSSL_memcpy(buf, in, todo);
|
||||
in += todo;
|
||||
in_len -= todo;
|
||||
|
||||
size_t blocks = todo / 16;
|
||||
for (size_t i = 0; i < blocks; i++) {
|
||||
byte_reverse(buf + 16 * i);
|
||||
}
|
||||
|
||||
ctx->ghash(ctx->S, ctx->Htable, buf, todo);
|
||||
}
|
||||
}
|
||||
|
||||
void crypto_polyval_finish(const struct polyval_ctx *ctx, uint8_t out[16]) {
|
||||
OPENSSL_memcpy(out, &ctx->S, 16);
|
||||
byte_reverse(out);
|
||||
}
|
||||
|
||||
// gcm_siv_polyval evaluates POLYVAL at |auth_key| on the given plaintext and
|
||||
// AD. The result is written to |out_tag|.
|
||||
static void gcm_siv_polyval(
|
||||
uint8_t out_tag[16], const uint8_t *in, size_t in_len, const uint8_t *ad,
|
||||
size_t ad_len, const uint8_t auth_key[16],
|
||||
const uint8_t nonce[EVP_AEAD_AES_GCM_SIV_NONCE_LEN]) {
|
||||
void gcm_siv_polyval(uint8_t out_tag[16], const uint8_t *in, size_t in_len,
|
||||
const uint8_t *ad, size_t ad_len,
|
||||
const uint8_t auth_key[16],
|
||||
const uint8_t nonce[EVP_AEAD_AES_GCM_SIV_NONCE_LEN]) {
|
||||
struct polyval_ctx polyval_ctx;
|
||||
CRYPTO_POLYVAL_init(&polyval_ctx, auth_key);
|
||||
crypto_polyval_init(&polyval_ctx, auth_key);
|
||||
|
||||
CRYPTO_POLYVAL_update_blocks(&polyval_ctx, ad, ad_len & ~15);
|
||||
crypto_polyval_update_blocks(&polyval_ctx, ad, ad_len & ~15);
|
||||
|
||||
uint8_t scratch[16];
|
||||
if (ad_len & 15) {
|
||||
OPENSSL_memset(scratch, 0, sizeof(scratch));
|
||||
OPENSSL_memcpy(scratch, &ad[ad_len & ~15], ad_len & 15);
|
||||
CRYPTO_POLYVAL_update_blocks(&polyval_ctx, scratch, sizeof(scratch));
|
||||
crypto_polyval_update_blocks(&polyval_ctx, scratch, sizeof(scratch));
|
||||
}
|
||||
|
||||
CRYPTO_POLYVAL_update_blocks(&polyval_ctx, in, in_len & ~15);
|
||||
crypto_polyval_update_blocks(&polyval_ctx, in, in_len & ~15);
|
||||
if (in_len & 15) {
|
||||
OPENSSL_memset(scratch, 0, sizeof(scratch));
|
||||
OPENSSL_memcpy(scratch, &in[in_len & ~15], in_len & 15);
|
||||
CRYPTO_POLYVAL_update_blocks(&polyval_ctx, scratch, sizeof(scratch));
|
||||
crypto_polyval_update_blocks(&polyval_ctx, scratch, sizeof(scratch));
|
||||
}
|
||||
|
||||
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_POLYVAL_update_blocks(&polyval_ctx, length_block,
|
||||
crypto_polyval_update_blocks(&polyval_ctx, length_block,
|
||||
sizeof(length_block));
|
||||
|
||||
CRYPTO_POLYVAL_finish(&polyval_ctx, out_tag);
|
||||
crypto_polyval_finish(&polyval_ctx, out_tag);
|
||||
for (size_t i = 0; i < EVP_AEAD_AES_GCM_SIV_NONCE_LEN; i++) {
|
||||
out_tag[i] ^= nonce[i];
|
||||
}
|
||||
@@ -662,9 +744,9 @@ struct gcm_siv_record_keys {
|
||||
|
||||
// gcm_siv_keys calculates the keys for a specific GCM-SIV record with the
|
||||
// given nonce and writes them to |*out_keys|.
|
||||
static void gcm_siv_keys(const struct aead_aes_gcm_siv_ctx *gcm_siv_ctx,
|
||||
struct gcm_siv_record_keys *out_keys,
|
||||
const uint8_t nonce[EVP_AEAD_AES_GCM_SIV_NONCE_LEN]) {
|
||||
void gcm_siv_keys(const struct aead_aes_gcm_siv_ctx *gcm_siv_ctx,
|
||||
struct gcm_siv_record_keys *out_keys,
|
||||
const uint8_t nonce[EVP_AEAD_AES_GCM_SIV_NONCE_LEN]) {
|
||||
const AES_KEY *const key = &gcm_siv_ctx->ks.ks;
|
||||
uint8_t key_material[(128 /* POLYVAL key */ + 256 /* max AES key */) / 8];
|
||||
const size_t blocks_needed = gcm_siv_ctx->is_256 ? 6 : 4;
|
||||
@@ -694,11 +776,13 @@ static void gcm_siv_keys(const struct aead_aes_gcm_siv_ctx *gcm_siv_ctx,
|
||||
key_material + 16, gcm_siv_ctx->is_256 ? 32 : 16);
|
||||
}
|
||||
|
||||
static int aead_aes_gcm_siv_seal_scatter(
|
||||
const EVP_AEAD_CTX *ctx, uint8_t *out, uint8_t *out_tag,
|
||||
size_t *out_tag_len, size_t max_out_tag_len, const uint8_t *nonce,
|
||||
size_t nonce_len, const uint8_t *in, size_t in_len, const uint8_t *extra_in,
|
||||
size_t extra_in_len, const uint8_t *ad, size_t ad_len) {
|
||||
int aead_aes_gcm_siv_seal_scatter(const EVP_AEAD_CTX *ctx, uint8_t *out,
|
||||
uint8_t *out_tag, size_t *out_tag_len,
|
||||
size_t max_out_tag_len, const uint8_t *nonce,
|
||||
size_t nonce_len, const uint8_t *in,
|
||||
size_t in_len, const uint8_t *extra_in,
|
||||
size_t extra_in_len, const uint8_t *ad,
|
||||
size_t ad_len) {
|
||||
const struct aead_aes_gcm_siv_ctx *gcm_siv_ctx =
|
||||
(struct aead_aes_gcm_siv_ctx *)&ctx->state;
|
||||
const uint64_t in_len_64 = in_len;
|
||||
@@ -735,12 +819,11 @@ static int aead_aes_gcm_siv_seal_scatter(
|
||||
return 1;
|
||||
}
|
||||
|
||||
static int aead_aes_gcm_siv_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) {
|
||||
int aead_aes_gcm_siv_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) {
|
||||
const uint64_t ad_len_64 = ad_len;
|
||||
if (ad_len_64 >= (UINT64_C(1) << 61)) {
|
||||
OPENSSL_PUT_ERROR(CIPHER, CIPHER_R_TOO_LARGE);
|
||||
@@ -779,7 +862,7 @@ static int aead_aes_gcm_siv_open_gather(const EVP_AEAD_CTX *ctx, uint8_t *out,
|
||||
return 1;
|
||||
}
|
||||
|
||||
static const EVP_AEAD aead_aes_128_gcm_siv = {
|
||||
const EVP_AEAD aead_aes_128_gcm_siv = {
|
||||
16, // key length
|
||||
EVP_AEAD_AES_GCM_SIV_NONCE_LEN, // nonce length
|
||||
EVP_AEAD_AES_GCM_SIV_TAG_LEN, // overhead
|
||||
@@ -796,7 +879,7 @@ static const EVP_AEAD aead_aes_128_gcm_siv = {
|
||||
NULL /* tag_len */,
|
||||
};
|
||||
|
||||
static const EVP_AEAD aead_aes_256_gcm_siv = {
|
||||
const EVP_AEAD aead_aes_256_gcm_siv = {
|
||||
32, // key length
|
||||
EVP_AEAD_AES_GCM_SIV_NONCE_LEN, // nonce length
|
||||
EVP_AEAD_AES_GCM_SIV_TAG_LEN, // overhead
|
||||
@@ -812,6 +895,7 @@ static const EVP_AEAD aead_aes_256_gcm_siv = {
|
||||
NULL /* get_iv */,
|
||||
NULL /* tag_len */,
|
||||
};
|
||||
} // namespace
|
||||
|
||||
#if defined(AES_GCM_SIV_ASM)
|
||||
|
||||
+13
-13
@@ -1,16 +1,16 @@
|
||||
/* Copyright 2014 The BoringSSL Authors
|
||||
*
|
||||
* 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. */
|
||||
// Copyright 2014 The BoringSSL Authors
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// https://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
#include <CCryptoBoringSSL_aead.h>
|
||||
|
||||
+13
-55
@@ -1,58 +1,16 @@
|
||||
/* 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.] */
|
||||
// Copyright 1995-2016 The OpenSSL Project Authors. All Rights Reserved.
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// https://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
#include <CCryptoBoringSSL_cipher.h>
|
||||
#include <CCryptoBoringSSL_des.h>
|
||||
@@ -0,0 +1,51 @@
|
||||
// Copyright 1995-2016 The OpenSSL Project Authors. All Rights Reserved.
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// https://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
#include <CCryptoBoringSSL_cipher.h>
|
||||
|
||||
#include <string.h>
|
||||
|
||||
#include <CCryptoBoringSSL_nid.h>
|
||||
|
||||
#include "../fipsmodule/cipher/internal.h"
|
||||
#include "../internal.h"
|
||||
|
||||
|
||||
static int null_init_key(EVP_CIPHER_CTX *ctx, const uint8_t *key,
|
||||
const uint8_t *iv, int enc) {
|
||||
return 1;
|
||||
}
|
||||
|
||||
static int null_cipher(EVP_CIPHER_CTX *ctx, uint8_t *out, const uint8_t *in,
|
||||
size_t in_len) {
|
||||
if (in != out) {
|
||||
OPENSSL_memcpy(out, in, in_len);
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
|
||||
static const EVP_CIPHER n_cipher = {
|
||||
/*nid=*/NID_undef,
|
||||
/*block_size=*/1,
|
||||
/*key_len=*/0,
|
||||
/*iv_len=*/0,
|
||||
/*ctx_size=*/0,
|
||||
/*flags=*/0,
|
||||
/*init=*/null_init_key,
|
||||
/*cipher=*/null_cipher,
|
||||
/*cleanup=*/nullptr,
|
||||
/*ctrl=*/nullptr,
|
||||
};
|
||||
|
||||
const EVP_CIPHER *EVP_enc_null(void) { return &n_cipher; }
|
||||
+27
-69
@@ -1,58 +1,16 @@
|
||||
/* 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.] */
|
||||
// Copyright 1995-2016 The OpenSSL Project Authors. All Rights Reserved.
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// https://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
#include <CCryptoBoringSSL_cipher.h>
|
||||
#include <CCryptoBoringSSL_nid.h>
|
||||
@@ -76,25 +34,25 @@
|
||||
switch (n) { \
|
||||
case 8: \
|
||||
(l2) = ((uint32_t)(*(--(c)))) << 24L; \
|
||||
OPENSSL_FALLTHROUGH; \
|
||||
[[fallthrough]]; \
|
||||
case 7: \
|
||||
(l2) |= ((uint32_t)(*(--(c)))) << 16L; \
|
||||
OPENSSL_FALLTHROUGH; \
|
||||
[[fallthrough]]; \
|
||||
case 6: \
|
||||
(l2) |= ((uint32_t)(*(--(c)))) << 8L; \
|
||||
OPENSSL_FALLTHROUGH; \
|
||||
[[fallthrough]]; \
|
||||
case 5: \
|
||||
(l2) |= ((uint32_t)(*(--(c)))); \
|
||||
OPENSSL_FALLTHROUGH; \
|
||||
[[fallthrough]]; \
|
||||
case 4: \
|
||||
(l1) = ((uint32_t)(*(--(c)))) << 24L; \
|
||||
OPENSSL_FALLTHROUGH; \
|
||||
[[fallthrough]]; \
|
||||
case 3: \
|
||||
(l1) |= ((uint32_t)(*(--(c)))) << 16L; \
|
||||
OPENSSL_FALLTHROUGH; \
|
||||
[[fallthrough]]; \
|
||||
case 2: \
|
||||
(l1) |= ((uint32_t)(*(--(c)))) << 8L; \
|
||||
OPENSSL_FALLTHROUGH; \
|
||||
[[fallthrough]]; \
|
||||
case 1: \
|
||||
(l1) |= ((uint32_t)(*(--(c)))); \
|
||||
} \
|
||||
@@ -114,25 +72,25 @@
|
||||
switch (n) { \
|
||||
case 8: \
|
||||
*(--(c)) = (uint8_t)(((l2) >> 24L) & 0xff); \
|
||||
OPENSSL_FALLTHROUGH; \
|
||||
[[fallthrough]]; \
|
||||
case 7: \
|
||||
*(--(c)) = (uint8_t)(((l2) >> 16L) & 0xff); \
|
||||
OPENSSL_FALLTHROUGH; \
|
||||
[[fallthrough]]; \
|
||||
case 6: \
|
||||
*(--(c)) = (uint8_t)(((l2) >> 8L) & 0xff); \
|
||||
OPENSSL_FALLTHROUGH; \
|
||||
[[fallthrough]]; \
|
||||
case 5: \
|
||||
*(--(c)) = (uint8_t)(((l2)) & 0xff); \
|
||||
OPENSSL_FALLTHROUGH; \
|
||||
[[fallthrough]]; \
|
||||
case 4: \
|
||||
*(--(c)) = (uint8_t)(((l1) >> 24L) & 0xff); \
|
||||
OPENSSL_FALLTHROUGH; \
|
||||
[[fallthrough]]; \
|
||||
case 3: \
|
||||
*(--(c)) = (uint8_t)(((l1) >> 16L) & 0xff); \
|
||||
OPENSSL_FALLTHROUGH; \
|
||||
[[fallthrough]]; \
|
||||
case 2: \
|
||||
*(--(c)) = (uint8_t)(((l1) >> 8L) & 0xff); \
|
||||
OPENSSL_FALLTHROUGH; \
|
||||
[[fallthrough]]; \
|
||||
case 1: \
|
||||
*(--(c)) = (uint8_t)(((l1)) & 0xff); \
|
||||
} \
|
||||
@@ -0,0 +1,54 @@
|
||||
// Copyright 1995-2016 The OpenSSL Project Authors. All Rights Reserved.
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// https://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
#include <assert.h>
|
||||
#include <string.h>
|
||||
|
||||
#include <CCryptoBoringSSL_cipher.h>
|
||||
#include <CCryptoBoringSSL_nid.h>
|
||||
#include <CCryptoBoringSSL_rc4.h>
|
||||
|
||||
#include "../fipsmodule/cipher/internal.h"
|
||||
|
||||
|
||||
static int rc4_init_key(EVP_CIPHER_CTX *ctx, const uint8_t *key,
|
||||
const uint8_t *iv, int enc) {
|
||||
RC4_KEY *rc4key = (RC4_KEY *)ctx->cipher_data;
|
||||
|
||||
RC4_set_key(rc4key, EVP_CIPHER_CTX_key_length(ctx), key);
|
||||
return 1;
|
||||
}
|
||||
|
||||
static int rc4_cipher(EVP_CIPHER_CTX *ctx, uint8_t *out, const uint8_t *in,
|
||||
size_t in_len) {
|
||||
RC4_KEY *rc4key = (RC4_KEY *)ctx->cipher_data;
|
||||
|
||||
RC4(rc4key, in_len, in, out);
|
||||
return 1;
|
||||
}
|
||||
|
||||
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,
|
||||
/*cleanup=*/nullptr,
|
||||
/*ctrl=*/nullptr,
|
||||
};
|
||||
|
||||
const EVP_CIPHER *EVP_rc4(void) { return &rc4; }
|
||||
+13
-13
@@ -1,16 +1,16 @@
|
||||
/* Copyright 2014 The BoringSSL Authors
|
||||
*
|
||||
* 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. */
|
||||
// Copyright 2014 The BoringSSL Authors
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// https://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
#include <assert.h>
|
||||
#include <limits.h>
|
||||
@@ -0,0 +1,85 @@
|
||||
// Copyright 1995-2016 The OpenSSL Project Authors. All Rights Reserved.
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// https://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
#include <CCryptoBoringSSL_cipher.h>
|
||||
|
||||
#include <assert.h>
|
||||
#include <string.h>
|
||||
|
||||
#include <CCryptoBoringSSL_err.h>
|
||||
#include <CCryptoBoringSSL_mem.h>
|
||||
#include <CCryptoBoringSSL_nid.h>
|
||||
|
||||
#include "internal.h"
|
||||
#include "../internal.h"
|
||||
|
||||
|
||||
static const struct {
|
||||
int nid;
|
||||
const char *name;
|
||||
const EVP_CIPHER *(*func)(void);
|
||||
} kCiphers[] = {
|
||||
{NID_aes_128_cbc, "aes-128-cbc", EVP_aes_128_cbc},
|
||||
{NID_aes_128_ctr, "aes-128-ctr", EVP_aes_128_ctr},
|
||||
{NID_aes_128_ecb, "aes-128-ecb", EVP_aes_128_ecb},
|
||||
{NID_aes_128_gcm, "aes-128-gcm", EVP_aes_128_gcm},
|
||||
{NID_aes_128_ofb128, "aes-128-ofb", EVP_aes_128_ofb},
|
||||
{NID_aes_192_cbc, "aes-192-cbc", EVP_aes_192_cbc},
|
||||
{NID_aes_192_ctr, "aes-192-ctr", EVP_aes_192_ctr},
|
||||
{NID_aes_192_ecb, "aes-192-ecb", EVP_aes_192_ecb},
|
||||
{NID_aes_192_gcm, "aes-192-gcm", EVP_aes_192_gcm},
|
||||
{NID_aes_192_ofb128, "aes-192-ofb", EVP_aes_192_ofb},
|
||||
{NID_aes_256_cbc, "aes-256-cbc", EVP_aes_256_cbc},
|
||||
{NID_aes_256_ctr, "aes-256-ctr", EVP_aes_256_ctr},
|
||||
{NID_aes_256_ecb, "aes-256-ecb", EVP_aes_256_ecb},
|
||||
{NID_aes_256_gcm, "aes-256-gcm", EVP_aes_256_gcm},
|
||||
{NID_aes_256_ofb128, "aes-256-ofb", EVP_aes_256_ofb},
|
||||
{NID_des_cbc, "des-cbc", EVP_des_cbc},
|
||||
{NID_des_ecb, "des-ecb", EVP_des_ecb},
|
||||
{NID_des_ede_cbc, "des-ede-cbc", EVP_des_ede_cbc},
|
||||
{NID_des_ede_ecb, "des-ede", EVP_des_ede},
|
||||
{NID_des_ede3_cbc, "des-ede3-cbc", EVP_des_ede3_cbc},
|
||||
{NID_rc2_cbc, "rc2-cbc", EVP_rc2_cbc},
|
||||
{NID_rc4, "rc4", EVP_rc4},
|
||||
};
|
||||
|
||||
const EVP_CIPHER *EVP_get_cipherbynid(int nid) {
|
||||
for (size_t i = 0; i < OPENSSL_ARRAY_SIZE(kCiphers); i++) {
|
||||
if (kCiphers[i].nid == nid) {
|
||||
return kCiphers[i].func();
|
||||
}
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
||||
const EVP_CIPHER *EVP_get_cipherbyname(const char *name) {
|
||||
if (name == NULL) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
// This is not a name used by OpenSSL, but tcpdump registers it with
|
||||
// |EVP_add_cipher_alias|. Our |EVP_add_cipher_alias| is a no-op, so we
|
||||
// support the name here.
|
||||
if (OPENSSL_strcasecmp(name, "3des") == 0) {
|
||||
name = "des-ede3-cbc";
|
||||
}
|
||||
|
||||
for (size_t i = 0; i < OPENSSL_ARRAY_SIZE(kCiphers); i++) {
|
||||
if (OPENSSL_strcasecmp(kCiphers[i].name, name) == 0) {
|
||||
return kCiphers[i].func();
|
||||
}
|
||||
}
|
||||
|
||||
return NULL;
|
||||
}
|
||||
+32
-72
@@ -1,61 +1,19 @@
|
||||
/* 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.] */
|
||||
// Copyright 1995-2016 The OpenSSL Project Authors. All Rights Reserved.
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// https://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
#ifndef OPENSSL_HEADER_CIPHER_EXTRA_INTERNAL_H
|
||||
#define OPENSSL_HEADER_CIPHER_EXTRA_INTERNAL_H
|
||||
#ifndef OPENSSL_HEADER_CRYPTO_CIPHER_INTERNAL_H
|
||||
#define OPENSSL_HEADER_CRYPTO_CIPHER_INTERNAL_H
|
||||
|
||||
#include <assert.h>
|
||||
#include <stdlib.h>
|
||||
@@ -179,7 +137,7 @@ static_assert(sizeof(union chacha20_poly1305_open_data) == 48,
|
||||
static_assert(sizeof(union chacha20_poly1305_seal_data) == 48 + 8 + 8,
|
||||
"wrong chacha20_poly1305_seal_data size");
|
||||
|
||||
OPENSSL_INLINE int chacha20_poly1305_asm_capable(void) {
|
||||
inline int chacha20_poly1305_asm_capable(void) {
|
||||
#if defined(OPENSSL_X86_64)
|
||||
return CRYPTO_is_SSE4_1_capable();
|
||||
#elif defined(OPENSSL_AARCH64)
|
||||
@@ -193,13 +151,13 @@ OPENSSL_INLINE int chacha20_poly1305_asm_capable(void) {
|
||||
// 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(
|
||||
extern void chacha20_poly1305_open_sse41(
|
||||
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,
|
||||
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,
|
||||
@@ -208,8 +166,8 @@ OPENSSL_INLINE void chacha20_poly1305_open(uint8_t *out_plaintext,
|
||||
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);
|
||||
chacha20_poly1305_open_sse41(out_plaintext, ciphertext, plaintext_len, ad,
|
||||
ad_len, data);
|
||||
}
|
||||
}
|
||||
#else
|
||||
@@ -226,21 +184,23 @@ extern void chacha20_poly1305_open(uint8_t *out_plaintext,
|
||||
// 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(
|
||||
extern void chacha20_poly1305_seal_sse41(
|
||||
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) {
|
||||
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);
|
||||
chacha20_poly1305_seal_sse41(out_ciphertext, plaintext, plaintext_len, ad,
|
||||
ad_len, data);
|
||||
}
|
||||
}
|
||||
#else
|
||||
@@ -253,9 +213,9 @@ extern void chacha20_poly1305_seal(uint8_t *out_ciphertext,
|
||||
|
||||
#else
|
||||
|
||||
OPENSSL_INLINE int chacha20_poly1305_asm_capable(void) { return 0; }
|
||||
inline int chacha20_poly1305_asm_capable(void) { return 0; }
|
||||
|
||||
OPENSSL_INLINE void chacha20_poly1305_open(uint8_t *out_plaintext,
|
||||
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,
|
||||
@@ -263,7 +223,7 @@ OPENSSL_INLINE void chacha20_poly1305_open(uint8_t *out_plaintext,
|
||||
abort();
|
||||
}
|
||||
|
||||
OPENSSL_INLINE void chacha20_poly1305_seal(uint8_t *out_ciphertext,
|
||||
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,
|
||||
@@ -277,4 +237,4 @@ OPENSSL_INLINE void chacha20_poly1305_seal(uint8_t *out_ciphertext,
|
||||
} // extern C
|
||||
#endif
|
||||
|
||||
#endif // OPENSSL_HEADER_CIPHER_EXTRA_INTERNAL_H
|
||||
#endif // OPENSSL_HEADER_CRYPTO_CIPHER_INTERNAL_H
|
||||
+13
-51
@@ -1,54 +1,16 @@
|
||||
/* ====================================================================
|
||||
* Copyright (c) 2012 The OpenSSL Project. All rights reserved.
|
||||
*
|
||||
* 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 above 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 acknowledgment:
|
||||
* "This product includes software developed by the OpenSSL Project
|
||||
* for use in the OpenSSL Toolkit. (http://www.openssl.org/)"
|
||||
*
|
||||
* 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
|
||||
* endorse or promote products derived from this software without
|
||||
* prior written permission. For written permission, please contact
|
||||
* openssl-core@openssl.org.
|
||||
*
|
||||
* 5. Products derived from this software may not be called "OpenSSL"
|
||||
* nor may "OpenSSL" appear in their names without prior written
|
||||
* permission of the OpenSSL Project.
|
||||
*
|
||||
* 6. Redistributions of any form whatsoever must retain the following
|
||||
* acknowledgment:
|
||||
* "This product includes software developed by the OpenSSL Project
|
||||
* for use in the OpenSSL Toolkit (http://www.openssl.org/)"
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
|
||||
* EXPRESSED 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 OpenSSL PROJECT OR
|
||||
* ITS 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.
|
||||
* ====================================================================
|
||||
*
|
||||
* This product includes cryptographic software written by Eric Young
|
||||
* (eay@cryptsoft.com). This product includes software written by Tim
|
||||
* Hudson (tjh@cryptsoft.com). */
|
||||
// Copyright 2012-2016 The OpenSSL Project Authors. All Rights Reserved.
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// https://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
#include <assert.h>
|
||||
#include <string.h>
|
||||
@@ -1,127 +0,0 @@
|
||||
/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
|
||||
* All rights reserved.
|
||||
*
|
||||
* This package is an SSL implementation written
|
||||
* by Eric Young (eay@cryptsoft.com).
|
||||
* The implementation was written so as to conform with Netscapes SSL.
|
||||
*
|
||||
* This library is free for commercial and non-commercial use as long as
|
||||
* the following conditions are aheared to. The following conditions
|
||||
* apply to all code found in this distribution, be it the RC4, RSA,
|
||||
* lhash, DES, etc., code; not just the SSL code. The SSL documentation
|
||||
* included with this distribution is covered by the same copyright terms
|
||||
* except that the holder is Tim Hudson (tjh@cryptsoft.com).
|
||||
*
|
||||
* Copyright remains Eric Young's, and as such any Copyright notices in
|
||||
* the code are not to be removed.
|
||||
* If this package is used in a product, Eric Young should be given attribution
|
||||
* as the author of the parts of the library used.
|
||||
* This can be in the form of a textual message at program startup or
|
||||
* in documentation (online or textual) provided with the package.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
* 1. Redistributions of source code must retain the copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
* 3. All advertising materials mentioning features or use of this software
|
||||
* must display the following acknowledgement:
|
||||
* "This product includes cryptographic software written by
|
||||
* Eric Young (eay@cryptsoft.com)"
|
||||
* The word 'cryptographic' can be left out if the rouines from the library
|
||||
* being used are not cryptographic related :-).
|
||||
* 4. If you include any Windows specific code (or a derivative thereof) from
|
||||
* the apps directory (application code) you must include an acknowledgement:
|
||||
* "This product includes software written by Tim Hudson (tjh@cryptsoft.com)"
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND
|
||||
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
* ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
|
||||
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
||||
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
||||
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
||||
* SUCH DAMAGE.
|
||||
*
|
||||
* The licence and distribution terms for any publically available version or
|
||||
* derivative of this code cannot be changed. i.e. this code cannot simply be
|
||||
* copied and put under another distribution licence
|
||||
* [including the GNU Public Licence.] */
|
||||
|
||||
#include <CCryptoBoringSSL_cipher.h>
|
||||
|
||||
#include <assert.h>
|
||||
#include <string.h>
|
||||
|
||||
#include <CCryptoBoringSSL_err.h>
|
||||
#include <CCryptoBoringSSL_mem.h>
|
||||
#include <CCryptoBoringSSL_nid.h>
|
||||
|
||||
#include "internal.h"
|
||||
#include "../internal.h"
|
||||
|
||||
|
||||
static const struct {
|
||||
int nid;
|
||||
const char *name;
|
||||
const EVP_CIPHER *(*func)(void);
|
||||
} kCiphers[] = {
|
||||
{NID_aes_128_cbc, "aes-128-cbc", EVP_aes_128_cbc},
|
||||
{NID_aes_128_ctr, "aes-128-ctr", EVP_aes_128_ctr},
|
||||
{NID_aes_128_ecb, "aes-128-ecb", EVP_aes_128_ecb},
|
||||
{NID_aes_128_gcm, "aes-128-gcm", EVP_aes_128_gcm},
|
||||
{NID_aes_128_ofb128, "aes-128-ofb", EVP_aes_128_ofb},
|
||||
{NID_aes_192_cbc, "aes-192-cbc", EVP_aes_192_cbc},
|
||||
{NID_aes_192_ctr, "aes-192-ctr", EVP_aes_192_ctr},
|
||||
{NID_aes_192_ecb, "aes-192-ecb", EVP_aes_192_ecb},
|
||||
{NID_aes_192_gcm, "aes-192-gcm", EVP_aes_192_gcm},
|
||||
{NID_aes_192_ofb128, "aes-192-ofb", EVP_aes_192_ofb},
|
||||
{NID_aes_256_cbc, "aes-256-cbc", EVP_aes_256_cbc},
|
||||
{NID_aes_256_ctr, "aes-256-ctr", EVP_aes_256_ctr},
|
||||
{NID_aes_256_ecb, "aes-256-ecb", EVP_aes_256_ecb},
|
||||
{NID_aes_256_gcm, "aes-256-gcm", EVP_aes_256_gcm},
|
||||
{NID_aes_256_ofb128, "aes-256-ofb", EVP_aes_256_ofb},
|
||||
{NID_des_cbc, "des-cbc", EVP_des_cbc},
|
||||
{NID_des_ecb, "des-ecb", EVP_des_ecb},
|
||||
{NID_des_ede_cbc, "des-ede-cbc", EVP_des_ede_cbc},
|
||||
{NID_des_ede_ecb, "des-ede", EVP_des_ede},
|
||||
{NID_des_ede3_cbc, "des-ede3-cbc", EVP_des_ede3_cbc},
|
||||
{NID_rc2_cbc, "rc2-cbc", EVP_rc2_cbc},
|
||||
{NID_rc4, "rc4", EVP_rc4},
|
||||
};
|
||||
|
||||
const EVP_CIPHER *EVP_get_cipherbynid(int nid) {
|
||||
for (size_t i = 0; i < OPENSSL_ARRAY_SIZE(kCiphers); i++) {
|
||||
if (kCiphers[i].nid == nid) {
|
||||
return kCiphers[i].func();
|
||||
}
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
||||
const EVP_CIPHER *EVP_get_cipherbyname(const char *name) {
|
||||
if (name == NULL) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
// This is not a name used by OpenSSL, but tcpdump registers it with
|
||||
// |EVP_add_cipher_alias|. Our |EVP_add_cipher_alias| is a no-op, so we
|
||||
// support the name here.
|
||||
if (OPENSSL_strcasecmp(name, "3des") == 0) {
|
||||
name = "des-ede3-cbc";
|
||||
}
|
||||
|
||||
for (size_t i = 0; i < OPENSSL_ARRAY_SIZE(kCiphers); i++) {
|
||||
if (OPENSSL_strcasecmp(kCiphers[i].name, name) == 0) {
|
||||
return kCiphers[i].func();
|
||||
}
|
||||
}
|
||||
|
||||
return NULL;
|
||||
}
|
||||
@@ -1,152 +0,0 @@
|
||||
/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
|
||||
* All rights reserved.
|
||||
*
|
||||
* This package is an SSL implementation written
|
||||
* by Eric Young (eay@cryptsoft.com).
|
||||
* The implementation was written so as to conform with Netscapes SSL.
|
||||
*
|
||||
* This library is free for commercial and non-commercial use as long as
|
||||
* the following conditions are aheared to. The following conditions
|
||||
* apply to all code found in this distribution, be it the RC4, RSA,
|
||||
* lhash, DES, etc., code; not just the SSL code. The SSL documentation
|
||||
* included with this distribution is covered by the same copyright terms
|
||||
* except that the holder is Tim Hudson (tjh@cryptsoft.com).
|
||||
*
|
||||
* Copyright remains Eric Young's, and as such any Copyright notices in
|
||||
* the code are not to be removed.
|
||||
* If this package is used in a product, Eric Young should be given attribution
|
||||
* as the author of the parts of the library used.
|
||||
* This can be in the form of a textual message at program startup or
|
||||
* in documentation (online or textual) provided with the package.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
* 1. Redistributions of source code must retain the copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
* 3. All advertising materials mentioning features or use of this software
|
||||
* must display the following acknowledgement:
|
||||
* "This product includes cryptographic software written by
|
||||
* Eric Young (eay@cryptsoft.com)"
|
||||
* The word 'cryptographic' can be left out if the rouines from the library
|
||||
* being used are not cryptographic related :-).
|
||||
* 4. If you include any Windows specific code (or a derivative thereof) from
|
||||
* the apps directory (application code) you must include an acknowledgement:
|
||||
* "This product includes software written by Tim Hudson (tjh@cryptsoft.com)"
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND
|
||||
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
* ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
|
||||
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
||||
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
||||
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
||||
* SUCH DAMAGE.
|
||||
*
|
||||
* The licence and distribution terms for any publically available version or
|
||||
* derivative of this code cannot be changed. i.e. this code cannot simply be
|
||||
* copied and put under another distribution licence
|
||||
* [including the GNU Public Licence.] */
|
||||
|
||||
#include <CCryptoBoringSSL_cipher.h>
|
||||
|
||||
#include <assert.h>
|
||||
|
||||
#include <CCryptoBoringSSL_digest.h>
|
||||
#include <CCryptoBoringSSL_mem.h>
|
||||
|
||||
|
||||
#define PKCS5_SALT_LEN 8
|
||||
|
||||
int EVP_BytesToKey(const EVP_CIPHER *type, const EVP_MD *md,
|
||||
const uint8_t *salt, const uint8_t *data, size_t data_len,
|
||||
unsigned count, uint8_t *key, uint8_t *iv) {
|
||||
EVP_MD_CTX c;
|
||||
uint8_t md_buf[EVP_MAX_MD_SIZE];
|
||||
unsigned addmd = 0;
|
||||
unsigned mds = 0, i;
|
||||
int rv = 0;
|
||||
|
||||
unsigned nkey = EVP_CIPHER_key_length(type);
|
||||
unsigned niv = EVP_CIPHER_iv_length(type);
|
||||
|
||||
assert(nkey <= EVP_MAX_KEY_LENGTH);
|
||||
assert(niv <= EVP_MAX_IV_LENGTH);
|
||||
|
||||
if (data == NULL) {
|
||||
return nkey;
|
||||
}
|
||||
|
||||
EVP_MD_CTX_init(&c);
|
||||
for (;;) {
|
||||
if (!EVP_DigestInit_ex(&c, md, NULL)) {
|
||||
goto err;
|
||||
}
|
||||
if (addmd++) {
|
||||
if (!EVP_DigestUpdate(&c, md_buf, mds)) {
|
||||
goto err;
|
||||
}
|
||||
}
|
||||
if (!EVP_DigestUpdate(&c, data, data_len)) {
|
||||
goto err;
|
||||
}
|
||||
if (salt != NULL) {
|
||||
if (!EVP_DigestUpdate(&c, salt, PKCS5_SALT_LEN)) {
|
||||
goto err;
|
||||
}
|
||||
}
|
||||
if (!EVP_DigestFinal_ex(&c, md_buf, &mds)) {
|
||||
goto err;
|
||||
}
|
||||
|
||||
for (i = 1; i < count; i++) {
|
||||
if (!EVP_DigestInit_ex(&c, md, NULL) ||
|
||||
!EVP_DigestUpdate(&c, md_buf, mds) ||
|
||||
!EVP_DigestFinal_ex(&c, md_buf, &mds)) {
|
||||
goto err;
|
||||
}
|
||||
}
|
||||
|
||||
i = 0;
|
||||
if (nkey) {
|
||||
for (;;) {
|
||||
if (nkey == 0 || i == mds) {
|
||||
break;
|
||||
}
|
||||
if (key != NULL) {
|
||||
*(key++) = md_buf[i];
|
||||
}
|
||||
nkey--;
|
||||
i++;
|
||||
}
|
||||
}
|
||||
|
||||
if (niv && i != mds) {
|
||||
for (;;) {
|
||||
if (niv == 0 || i == mds) {
|
||||
break;
|
||||
}
|
||||
if (iv != NULL) {
|
||||
*(iv++) = md_buf[i];
|
||||
}
|
||||
niv--;
|
||||
i++;
|
||||
}
|
||||
}
|
||||
if (nkey == 0 && niv == 0) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
rv = EVP_CIPHER_key_length(type);
|
||||
|
||||
err:
|
||||
EVP_MD_CTX_cleanup(&c);
|
||||
OPENSSL_cleanse(md_buf, EVP_MAX_MD_SIZE);
|
||||
return rv;
|
||||
}
|
||||
@@ -1,93 +0,0 @@
|
||||
/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
|
||||
* All rights reserved.
|
||||
*
|
||||
* This package is an SSL implementation written
|
||||
* by Eric Young (eay@cryptsoft.com).
|
||||
* The implementation was written so as to conform with Netscapes SSL.
|
||||
*
|
||||
* This library is free for commercial and non-commercial use as long as
|
||||
* the following conditions are aheared to. The following conditions
|
||||
* apply to all code found in this distribution, be it the RC4, RSA,
|
||||
* lhash, DES, etc., code; not just the SSL code. The SSL documentation
|
||||
* included with this distribution is covered by the same copyright terms
|
||||
* except that the holder is Tim Hudson (tjh@cryptsoft.com).
|
||||
*
|
||||
* Copyright remains Eric Young's, and as such any Copyright notices in
|
||||
* the code are not to be removed.
|
||||
* If this package is used in a product, Eric Young should be given attribution
|
||||
* as the author of the parts of the library used.
|
||||
* This can be in the form of a textual message at program startup or
|
||||
* in documentation (online or textual) provided with the package.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
* 1. Redistributions of source code must retain the copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
* 3. All advertising materials mentioning features or use of this software
|
||||
* must display the following acknowledgement:
|
||||
* "This product includes cryptographic software written by
|
||||
* Eric Young (eay@cryptsoft.com)"
|
||||
* The word 'cryptographic' can be left out if the rouines from the library
|
||||
* being used are not cryptographic related :-).
|
||||
* 4. If you include any Windows specific code (or a derivative thereof) from
|
||||
* the apps directory (application code) you must include an acknowledgement:
|
||||
* "This product includes software written by Tim Hudson (tjh@cryptsoft.com)"
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND
|
||||
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
* ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
|
||||
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
||||
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
||||
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
||||
* SUCH DAMAGE.
|
||||
*
|
||||
* The licence and distribution terms for any publically available version or
|
||||
* derivative of this code cannot be changed. i.e. this code cannot simply be
|
||||
* copied and put under another distribution licence
|
||||
* [including the GNU Public Licence.] */
|
||||
|
||||
#include <CCryptoBoringSSL_cipher.h>
|
||||
|
||||
#include <string.h>
|
||||
|
||||
#include <CCryptoBoringSSL_nid.h>
|
||||
|
||||
#include "../fipsmodule/cipher/internal.h"
|
||||
#include "../internal.h"
|
||||
|
||||
|
||||
static int null_init_key(EVP_CIPHER_CTX *ctx, const uint8_t *key,
|
||||
const uint8_t *iv, int enc) {
|
||||
return 1;
|
||||
}
|
||||
|
||||
static int null_cipher(EVP_CIPHER_CTX *ctx, uint8_t *out, const uint8_t *in,
|
||||
size_t in_len) {
|
||||
if (in != out) {
|
||||
OPENSSL_memcpy(out, in, in_len);
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
|
||||
static const EVP_CIPHER n_cipher = {
|
||||
/*nid=*/NID_undef,
|
||||
/*block_size=*/1,
|
||||
/*key_len=*/0,
|
||||
/*iv_len=*/0,
|
||||
/*ctx_size=*/0,
|
||||
/*flags=*/0,
|
||||
/*init=*/null_init_key,
|
||||
/*cipher=*/null_cipher,
|
||||
/*cleanup=*/nullptr,
|
||||
/*ctrl=*/nullptr,
|
||||
};
|
||||
|
||||
const EVP_CIPHER *EVP_enc_null(void) { return &n_cipher; }
|
||||
@@ -1,96 +0,0 @@
|
||||
/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
|
||||
* All rights reserved.
|
||||
*
|
||||
* This package is an SSL implementation written
|
||||
* by Eric Young (eay@cryptsoft.com).
|
||||
* The implementation was written so as to conform with Netscapes SSL.
|
||||
*
|
||||
* This library is free for commercial and non-commercial use as long as
|
||||
* the following conditions are aheared to. The following conditions
|
||||
* apply to all code found in this distribution, be it the RC4, RSA,
|
||||
* lhash, DES, etc., code; not just the SSL code. The SSL documentation
|
||||
* included with this distribution is covered by the same copyright terms
|
||||
* except that the holder is Tim Hudson (tjh@cryptsoft.com).
|
||||
*
|
||||
* Copyright remains Eric Young's, and as such any Copyright notices in
|
||||
* the code are not to be removed.
|
||||
* If this package is used in a product, Eric Young should be given attribution
|
||||
* as the author of the parts of the library used.
|
||||
* This can be in the form of a textual message at program startup or
|
||||
* in documentation (online or textual) provided with the package.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
* 1. Redistributions of source code must retain the copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
* 3. All advertising materials mentioning features or use of this software
|
||||
* must display the following acknowledgement:
|
||||
* "This product includes cryptographic software written by
|
||||
* Eric Young (eay@cryptsoft.com)"
|
||||
* The word 'cryptographic' can be left out if the rouines from the library
|
||||
* being used are not cryptographic related :-).
|
||||
* 4. If you include any Windows specific code (or a derivative thereof) from
|
||||
* the apps directory (application code) you must include an acknowledgement:
|
||||
* "This product includes software written by Tim Hudson (tjh@cryptsoft.com)"
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND
|
||||
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
* ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
|
||||
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
||||
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
||||
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
||||
* SUCH DAMAGE.
|
||||
*
|
||||
* The licence and distribution terms for any publically available version or
|
||||
* derivative of this code cannot be changed. i.e. this code cannot simply be
|
||||
* copied and put under another distribution licence
|
||||
* [including the GNU Public Licence.] */
|
||||
|
||||
#include <assert.h>
|
||||
#include <string.h>
|
||||
|
||||
#include <CCryptoBoringSSL_cipher.h>
|
||||
#include <CCryptoBoringSSL_nid.h>
|
||||
#include <CCryptoBoringSSL_rc4.h>
|
||||
|
||||
#include "../fipsmodule/cipher/internal.h"
|
||||
|
||||
|
||||
static int rc4_init_key(EVP_CIPHER_CTX *ctx, const uint8_t *key,
|
||||
const uint8_t *iv, int enc) {
|
||||
RC4_KEY *rc4key = (RC4_KEY *)ctx->cipher_data;
|
||||
|
||||
RC4_set_key(rc4key, EVP_CIPHER_CTX_key_length(ctx), key);
|
||||
return 1;
|
||||
}
|
||||
|
||||
static int rc4_cipher(EVP_CIPHER_CTX *ctx, uint8_t *out, const uint8_t *in,
|
||||
size_t in_len) {
|
||||
RC4_KEY *rc4key = (RC4_KEY *)ctx->cipher_data;
|
||||
|
||||
RC4(rc4key, in_len, in, out);
|
||||
return 1;
|
||||
}
|
||||
|
||||
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,
|
||||
/*cleanup=*/nullptr,
|
||||
/*ctrl=*/nullptr,
|
||||
};
|
||||
|
||||
const EVP_CIPHER *EVP_rc4(void) { return &rc4; }
|
||||
@@ -0,0 +1,172 @@
|
||||
// Copyright 2025 The BoringSSL Authors
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// https://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
#include <CCryptoBoringSSL_cms.h>
|
||||
|
||||
#include <CCryptoBoringSSL_bio.h>
|
||||
#include <CCryptoBoringSSL_err.h>
|
||||
#include <CCryptoBoringSSL_evp.h>
|
||||
#include <CCryptoBoringSSL_mem.h>
|
||||
#include <CCryptoBoringSSL_x509.h>
|
||||
|
||||
#include "../pkcs7/internal.h"
|
||||
|
||||
|
||||
// TODO(davidben): Should we move the core PKCS#7 / CMS implementation into
|
||||
// crypto/cms instead of crypto/pkcs7? CMS is getting new features while PKCS#7
|
||||
// is not.
|
||||
OPENSSL_DECLARE_ERROR_REASON(CMS, CERTIFICATE_HAS_NO_KEYID)
|
||||
|
||||
struct CMS_SignerInfo_st {
|
||||
X509 *signcert = nullptr;
|
||||
EVP_PKEY *pkey = nullptr;
|
||||
const EVP_MD *md = nullptr;
|
||||
bool use_key_id = false;
|
||||
};
|
||||
|
||||
struct CMS_ContentInfo_st {
|
||||
bool has_signer_info = false;
|
||||
CMS_SignerInfo signer_info;
|
||||
uint8_t *der = nullptr;
|
||||
size_t der_len = 0;
|
||||
};
|
||||
|
||||
CMS_ContentInfo *CMS_sign(X509 *signcert, EVP_PKEY *pkey, STACK_OF(X509) *certs,
|
||||
BIO *data, uint32_t flags) {
|
||||
// We only support external signatures and do not support embedding
|
||||
// certificates in SignedData.
|
||||
if ((flags & CMS_DETACHED) == 0 || sk_X509_num(certs) != 0) {
|
||||
OPENSSL_PUT_ERROR(CMS, ERR_R_SHOULD_NOT_HAVE_BEEN_CALLED);
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
bssl::UniquePtr<CMS_ContentInfo> cms(
|
||||
static_cast<CMS_ContentInfo *>(OPENSSL_zalloc(sizeof(CMS_ContentInfo))));
|
||||
if (cms == nullptr) {
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
if (pkey != nullptr &&
|
||||
!CMS_add1_signer(cms.get(), signcert, pkey, /*md=*/nullptr, flags)) {
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
// We don't actually use streaming mode, but Linux passes |CMS_STREAM| to
|
||||
// |CMS_sign| and OpenSSL interprets it as an alias for |CMS_PARTIAL| in this
|
||||
// context.
|
||||
if ((flags & (CMS_PARTIAL | CMS_STREAM)) == 0 &&
|
||||
!CMS_final(cms.get(), data, NULL, flags)) {
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
return cms.release();
|
||||
}
|
||||
|
||||
void CMS_ContentInfo_free(CMS_ContentInfo *cms) {
|
||||
if (cms == nullptr) {
|
||||
return;
|
||||
}
|
||||
X509_free(cms->signer_info.signcert);
|
||||
EVP_PKEY_free(cms->signer_info.pkey);
|
||||
OPENSSL_free(cms->der);
|
||||
OPENSSL_free(cms);
|
||||
}
|
||||
|
||||
CMS_SignerInfo *CMS_add1_signer(CMS_ContentInfo *cms, X509 *signcert,
|
||||
EVP_PKEY *pkey, const EVP_MD *md,
|
||||
uint32_t flags) {
|
||||
if ( // Already finalized.
|
||||
cms->der_len != 0 ||
|
||||
// We only support one signer.
|
||||
cms->has_signer_info ||
|
||||
// We do not support configuring a signer in multiple steps. (In OpenSSL,
|
||||
// this is used to configure attributes.
|
||||
(flags & CMS_PARTIAL) != 0 ||
|
||||
// We do not support embedding certificates in SignedData.
|
||||
(flags & CMS_NOCERTS) == 0 ||
|
||||
// We do not support attributes in SignedData.
|
||||
(flags & CMS_NOATTR) == 0) {
|
||||
OPENSSL_PUT_ERROR(CMS, ERR_R_SHOULD_NOT_HAVE_BEEN_CALLED);
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
if (signcert == nullptr || pkey == nullptr) {
|
||||
OPENSSL_PUT_ERROR(CMS, ERR_R_PASSED_NULL_PARAMETER);
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
if (!X509_check_private_key(signcert, pkey)) {
|
||||
OPENSSL_PUT_ERROR(CMS, CMS_R_PRIVATE_KEY_DOES_NOT_MATCH_CERTIFICATE);
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
// Default to SHA-256.
|
||||
if (md == nullptr) {
|
||||
md = EVP_sha256();
|
||||
}
|
||||
|
||||
// Save information for later.
|
||||
cms->has_signer_info = true;
|
||||
cms->signer_info.signcert = bssl::UpRef(signcert).release();
|
||||
cms->signer_info.pkey = bssl::UpRef(pkey).release();
|
||||
cms->signer_info.md = md;
|
||||
cms->signer_info.use_key_id = (flags & CMS_USE_KEYID) != 0;
|
||||
return &cms->signer_info;
|
||||
}
|
||||
|
||||
int CMS_final(CMS_ContentInfo *cms, BIO *data, BIO *dcont, uint32_t flags) {
|
||||
if ( // Already finalized.
|
||||
cms->der_len != 0 ||
|
||||
// Require a SignerInfo. We do not support signature-less SignedDatas.
|
||||
!cms->has_signer_info ||
|
||||
// We only support the straightforward passthrough mode, without S/MIME
|
||||
// translations.
|
||||
(flags & CMS_BINARY) == 0 ||
|
||||
// We do not support |dcont|. It is unclear what it does.
|
||||
dcont != nullptr) {
|
||||
OPENSSL_PUT_ERROR(CMS, ERR_R_SHOULD_NOT_HAVE_BEEN_CALLED);
|
||||
return 0;
|
||||
}
|
||||
|
||||
bssl::ScopedCBB cbb;
|
||||
if (!CBB_init(cbb.get(), 2048) ||
|
||||
!pkcs7_add_external_signature(cbb.get(), cms->signer_info.signcert,
|
||||
cms->signer_info.pkey, cms->signer_info.md,
|
||||
data, cms->signer_info.use_key_id) ||
|
||||
!CBB_finish(cbb.get(), &cms->der, &cms->der_len)) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
int i2d_CMS_bio(BIO *out, CMS_ContentInfo *cms) {
|
||||
if (cms->der_len == 0) {
|
||||
// Not yet finalized.
|
||||
OPENSSL_PUT_ERROR(CMS, ERR_R_SHOULD_NOT_HAVE_BEEN_CALLED);
|
||||
return 0;
|
||||
}
|
||||
|
||||
return BIO_write_all(out, cms->der, cms->der_len);
|
||||
}
|
||||
|
||||
int i2d_CMS_bio_stream(BIO *out, CMS_ContentInfo *cms, BIO *in, int flags) {
|
||||
// We do not support streaming mode.
|
||||
if ((flags & CMS_STREAM) != 0 || in != nullptr) {
|
||||
OPENSSL_PUT_ERROR(CMS, ERR_R_SHOULD_NOT_HAVE_BEEN_CALLED);
|
||||
return 0;
|
||||
}
|
||||
|
||||
return i2d_CMS_bio(out, cms);
|
||||
}
|
||||
@@ -1,58 +1,16 @@
|
||||
/* 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.] */
|
||||
// Copyright 1995-2016 The OpenSSL Project Authors. All Rights Reserved.
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// https://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
#include <CCryptoBoringSSL_conf.h>
|
||||
|
||||
@@ -63,7 +21,6 @@
|
||||
#include <CCryptoBoringSSL_bio.h>
|
||||
#include <CCryptoBoringSSL_buf.h>
|
||||
#include <CCryptoBoringSSL_err.h>
|
||||
#include <CCryptoBoringSSL_lhash.h>
|
||||
#include <CCryptoBoringSSL_mem.h>
|
||||
|
||||
#include "../internal.h"
|
||||
@@ -417,7 +374,6 @@ int NCONF_load_bio(CONF *conf, BIO *in, long *out_error_line) {
|
||||
char *s, *p, *end;
|
||||
int again;
|
||||
long eline = 0;
|
||||
char btmp[DECIMAL_SIZE(eline) + 1];
|
||||
CONF_VALUE *v = NULL;
|
||||
CONF_SECTION *sv = NULL;
|
||||
char *section = NULL, *buf;
|
||||
@@ -598,8 +554,7 @@ err:
|
||||
if (out_error_line != NULL) {
|
||||
*out_error_line = eline;
|
||||
}
|
||||
snprintf(btmp, sizeof btmp, "%ld", eline);
|
||||
ERR_add_error_data(2, "line ", btmp);
|
||||
ERR_add_error_dataf("line %ld", eline);
|
||||
value_free(v);
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -1,16 +1,16 @@
|
||||
/* Copyright 2015 The BoringSSL Authors
|
||||
*
|
||||
* 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. */
|
||||
// Copyright 2015 The BoringSSL Authors
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// https://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
#ifndef OPENSSL_HEADER_CRYPTO_CONF_INTERNAL_H
|
||||
#define OPENSSL_HEADER_CRYPTO_CONF_INTERNAL_H
|
||||
|
||||
@@ -1,16 +1,16 @@
|
||||
/* Copyright 2021 The BoringSSL Authors
|
||||
*
|
||||
* 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. */
|
||||
// Copyright 2021 The BoringSSL Authors
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// https://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
#include "internal.h"
|
||||
|
||||
@@ -20,8 +20,6 @@
|
||||
#include <sys/sysctl.h>
|
||||
#include <sys/types.h>
|
||||
|
||||
#include <CCryptoBoringSSL_arm_arch.h>
|
||||
|
||||
|
||||
static int has_hw_feature(const char *name) {
|
||||
int value;
|
||||
|
||||
@@ -1,16 +1,16 @@
|
||||
/* Copyright 2018 The BoringSSL Authors
|
||||
*
|
||||
* 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. */
|
||||
// Copyright 2018 The BoringSSL Authors
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// https://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
#include "internal.h"
|
||||
|
||||
@@ -21,8 +21,6 @@
|
||||
#include <zircon/syscalls.h>
|
||||
#include <zircon/types.h>
|
||||
|
||||
#include <CCryptoBoringSSL_arm_arch.h>
|
||||
|
||||
|
||||
void OPENSSL_cpuid_setup(void) {
|
||||
uint32_t hwcap;
|
||||
|
||||
@@ -1,16 +1,16 @@
|
||||
/* Copyright 2016 The BoringSSL Authors
|
||||
*
|
||||
* 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. */
|
||||
// Copyright 2016 The BoringSSL Authors
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// https://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
#include "internal.h"
|
||||
|
||||
@@ -19,8 +19,6 @@
|
||||
|
||||
#include <sys/auxv.h>
|
||||
|
||||
#include <CCryptoBoringSSL_arm_arch.h>
|
||||
|
||||
|
||||
void OPENSSL_cpuid_setup(void) {
|
||||
unsigned long hwcap = getauxval(AT_HWCAP);
|
||||
|
||||
@@ -1,16 +1,16 @@
|
||||
/* Copyright (c) 2022, Robert Nagy <robert.nagy@gmail.com>
|
||||
*
|
||||
* 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. */
|
||||
// Copyright (c) 2022, Robert Nagy <robert.nagy@gmail.com>
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// https://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
#include <CCryptoBoringSSL_cpu.h>
|
||||
|
||||
@@ -21,8 +21,6 @@
|
||||
#include <machine/cpu.h>
|
||||
#include <sys/sysctl.h>
|
||||
|
||||
#include <CCryptoBoringSSL_arm_arch.h>
|
||||
|
||||
#include "internal.h"
|
||||
|
||||
|
||||
|
||||
@@ -1,16 +1,16 @@
|
||||
/* Copyright 2023 The BoringSSL Authors
|
||||
*
|
||||
* 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. */
|
||||
// Copyright 2023 The BoringSSL Authors
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// https://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
#include "internal.h"
|
||||
|
||||
@@ -21,8 +21,6 @@
|
||||
(defined(ANDROID_BAREMETAL) || defined(OPENSSL_FREEBSD)) && \
|
||||
!defined(OPENSSL_NO_ASM)
|
||||
|
||||
#include <CCryptoBoringSSL_arm_arch.h>
|
||||
|
||||
#define ID_AA64PFR0_EL1_ADVSIMD 5
|
||||
|
||||
#define ID_AA64ISAR0_EL1_AES 1
|
||||
|
||||
@@ -1,17 +1,17 @@
|
||||
/* Copyright 2018 The BoringSSL Authors
|
||||
* Copyright (c) 2020, Arm Ltd.
|
||||
*
|
||||
* Permission to use, copy, modify, and/or distribute this software for any
|
||||
* purpose with or without fee is hereby granted, provided that the above
|
||||
* copyright notice and this permission notice appear in all copies.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
|
||||
* WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
|
||||
* MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
|
||||
* SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
|
||||
* WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION
|
||||
* OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
|
||||
* CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. */
|
||||
// Copyright 2018 The BoringSSL Authors
|
||||
// Copyright (c) 2020, Arm Ltd.
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// https://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
#include "internal.h"
|
||||
|
||||
@@ -20,8 +20,6 @@
|
||||
|
||||
#include <windows.h>
|
||||
|
||||
#include <CCryptoBoringSSL_arm_arch.h>
|
||||
|
||||
|
||||
void OPENSSL_cpuid_setup(void) {
|
||||
// We do not need to check for the presence of NEON, as Armv8-A always has it
|
||||
|
||||
@@ -1,16 +1,16 @@
|
||||
/* Copyright 2022 The BoringSSL Authors
|
||||
*
|
||||
* 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. */
|
||||
// Copyright 2022 The BoringSSL Authors
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// https://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
#include "internal.h"
|
||||
|
||||
@@ -19,7 +19,6 @@
|
||||
#include <sys/auxv.h>
|
||||
#include <sys/types.h>
|
||||
|
||||
#include <CCryptoBoringSSL_arm_arch.h>
|
||||
#include <CCryptoBoringSSL_mem.h>
|
||||
|
||||
|
||||
|
||||
@@ -1,16 +1,16 @@
|
||||
/* Copyright 2016 The BoringSSL Authors
|
||||
*
|
||||
* 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. */
|
||||
// Copyright 2016 The BoringSSL Authors
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// https://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
#include "internal.h"
|
||||
|
||||
@@ -22,7 +22,6 @@
|
||||
#include <sys/types.h>
|
||||
#include <unistd.h>
|
||||
|
||||
#include <CCryptoBoringSSL_arm_arch.h>
|
||||
#include <CCryptoBoringSSL_mem.h>
|
||||
|
||||
#include "cpu_arm_linux.h"
|
||||
@@ -110,7 +109,11 @@ void OPENSSL_cpuid_setup(void) {
|
||||
|
||||
// Matching OpenSSL, only report other features if NEON is present.
|
||||
unsigned long hwcap = getauxval(AT_HWCAP);
|
||||
if (hwcap & HWCAP_NEON) {
|
||||
if (hwcap & CRYPTO_HWCAP_NEON) {
|
||||
#if defined(HWCAP_ARM_NEON)
|
||||
static_assert(HWCAP_ARM_NEON == CRYPTO_HWCAP_NEON,
|
||||
"CRYPTO_HWCAP values must match Linux");
|
||||
#endif
|
||||
OPENSSL_armcap_P |= ARMV7_NEON;
|
||||
|
||||
// Some ARMv8 Android devices don't expose AT_HWCAP2. Fall back to
|
||||
@@ -124,16 +127,35 @@ void OPENSSL_cpuid_setup(void) {
|
||||
g_needs_hwcap2_workaround = hwcap2 != 0;
|
||||
}
|
||||
|
||||
if (hwcap2 & HWCAP2_AES) {
|
||||
// HWCAP2_* values, without the "CRYPTO_" prefix, are exposed through
|
||||
// <sys/auxv.h> in some versions of glibc(>= 2.41). Assert that we don't
|
||||
// diverge from those values.
|
||||
if (hwcap2 & CRYPTO_HWCAP2_AES) {
|
||||
#if defined(HWCAP2_AES)
|
||||
static_assert(HWCAP2_AES == CRYPTO_HWCAP2_AES,
|
||||
"CRYPTO_HWCAP2 values must match Linux");
|
||||
#endif
|
||||
OPENSSL_armcap_P |= ARMV8_AES;
|
||||
}
|
||||
if (hwcap2 & HWCAP2_PMULL) {
|
||||
if (hwcap2 & CRYPTO_HWCAP2_PMULL) {
|
||||
#if defined(HWCAP2_PMULL)
|
||||
static_assert(HWCAP2_PMULL == CRYPTO_HWCAP2_PMULL,
|
||||
"CRYPTO_HWCAP2 values must match Linux");
|
||||
#endif
|
||||
OPENSSL_armcap_P |= ARMV8_PMULL;
|
||||
}
|
||||
if (hwcap2 & HWCAP2_SHA1) {
|
||||
if (hwcap2 & CRYPTO_HWCAP2_SHA1) {
|
||||
#if defined(HWCAP2_SHA1)
|
||||
static_assert(HWCAP2_SHA1 == CRYPTO_HWCAP2_SHA1,
|
||||
"CRYPTO_HWCAP2 values must match Linux");
|
||||
#endif
|
||||
OPENSSL_armcap_P |= ARMV8_SHA1;
|
||||
}
|
||||
if (hwcap2 & HWCAP2_SHA2) {
|
||||
if (hwcap2 & CRYPTO_HWCAP2_SHA2) {
|
||||
#if defined(HWCAP2_SHA2)
|
||||
static_assert(HWCAP2_SHA2 == CRYPTO_HWCAP2_SHA2,
|
||||
"CRYPTO_HWCAP2 values must match Linux");
|
||||
#endif
|
||||
OPENSSL_armcap_P |= ARMV8_SHA256;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,16 +1,16 @@
|
||||
/* Copyright 2018 The BoringSSL Authors
|
||||
*
|
||||
* 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. */
|
||||
// Copyright 2018 The BoringSSL Authors
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// https://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
#ifndef OPENSSL_HEADER_CRYPTO_CPU_ARM_LINUX_H
|
||||
#define OPENSSL_HEADER_CRYPTO_CPU_ARM_LINUX_H
|
||||
@@ -29,14 +29,16 @@ extern "C" {
|
||||
// The cpuinfo parser lives in a header file so it may be accessible from
|
||||
// cross-platform fuzzers without adding code to those platforms normally.
|
||||
|
||||
#define HWCAP_NEON (1 << 12)
|
||||
#define CRYPTO_HWCAP_NEON (1 << 12)
|
||||
|
||||
// See /usr/include/asm/hwcap.h on an ARM installation for the source of
|
||||
// these values.
|
||||
#define HWCAP2_AES (1 << 0)
|
||||
#define HWCAP2_PMULL (1 << 1)
|
||||
#define HWCAP2_SHA1 (1 << 2)
|
||||
#define HWCAP2_SHA2 (1 << 3)
|
||||
// We add the prefix "CRYPTO_" to the definitions so as not to collide with
|
||||
// some versions of glibc (>= 2.41) that expose them through <sys/auxv.h>.
|
||||
#define CRYPTO_HWCAP2_AES (1 << 0)
|
||||
#define CRYPTO_HWCAP2_PMULL (1 << 1)
|
||||
#define CRYPTO_HWCAP2_SHA1 (1 << 2)
|
||||
#define CRYPTO_HWCAP2_SHA2 (1 << 3)
|
||||
|
||||
typedef struct {
|
||||
const char *data;
|
||||
@@ -141,16 +143,16 @@ static unsigned long crypto_get_arm_hwcap2_from_cpuinfo(
|
||||
|
||||
unsigned long ret = 0;
|
||||
if (has_list_item(&features, "aes")) {
|
||||
ret |= HWCAP2_AES;
|
||||
ret |= CRYPTO_HWCAP2_AES;
|
||||
}
|
||||
if (has_list_item(&features, "pmull")) {
|
||||
ret |= HWCAP2_PMULL;
|
||||
ret |= CRYPTO_HWCAP2_PMULL;
|
||||
}
|
||||
if (has_list_item(&features, "sha1")) {
|
||||
ret |= HWCAP2_SHA1;
|
||||
ret |= CRYPTO_HWCAP2_SHA1;
|
||||
}
|
||||
if (has_list_item(&features, "sha2")) {
|
||||
ret |= HWCAP2_SHA2;
|
||||
ret |= CRYPTO_HWCAP2_SHA2;
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
@@ -1,74 +1,31 @@
|
||||
/* 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.] */
|
||||
// Copyright 1995-2016 The OpenSSL Project Authors. All Rights Reserved.
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// https://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
#include <CCryptoBoringSSL_base.h>
|
||||
|
||||
#if !defined(OPENSSL_NO_ASM) && \
|
||||
(defined(OPENSSL_X86) || defined(OPENSSL_X86_64))
|
||||
|
||||
#include <errno.h>
|
||||
#include <inttypes.h>
|
||||
#include <stdio.h>
|
||||
#include <limits.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
#if defined(_MSC_VER)
|
||||
OPENSSL_MSVC_PRAGMA(warning(push, 3))
|
||||
#include <immintrin.h>
|
||||
#include <intrin.h>
|
||||
OPENSSL_MSVC_PRAGMA(warning(pop))
|
||||
#endif
|
||||
|
||||
#include "internal.h"
|
||||
@@ -134,22 +91,25 @@ static bool os_supports_avx512(uint64_t xcr0) {
|
||||
}
|
||||
|
||||
// handle_cpu_env applies the value from |in| to the CPUID values in |out[0]|
|
||||
// and |out[1]|. See the comment in |OPENSSL_cpuid_setup| about this.
|
||||
static void handle_cpu_env(uint32_t *out, const char *in) {
|
||||
// and |out[1]|. See the comment in |OPENSSL_cpuid_setup| about this. The
|
||||
// |is_last| argument specifies whether the value is at the end of the string.
|
||||
// Otherwise it may be followed by a colon.
|
||||
static void handle_cpu_env(uint32_t out[2], const char *in, bool is_last) {
|
||||
const int invert_op = in[0] == '~';
|
||||
const int or_op = in[0] == '|';
|
||||
const int skip_first_byte = invert_op || or_op;
|
||||
const int hex = in[skip_first_byte] == '0' && in[skip_first_byte + 1] == 'x';
|
||||
const int base = hex ? 16 : 10;
|
||||
|
||||
int sscanf_result;
|
||||
uint64_t v;
|
||||
if (hex) {
|
||||
sscanf_result = sscanf(in + invert_op + 2, "%" PRIx64, &v);
|
||||
} else {
|
||||
sscanf_result = sscanf(in + invert_op, "%" PRIu64, &v);
|
||||
}
|
||||
const char *start = in + skip_first_byte;
|
||||
char *end;
|
||||
errno = 0;
|
||||
// We need to parse 64-bit values with `strtoull`.
|
||||
static_assert(sizeof(unsigned long long) == sizeof(uint64_t));
|
||||
unsigned long long v = strtoull(start, &end, base);
|
||||
|
||||
if (!sscanf_result) {
|
||||
if (end == start || (*end != '\0' && (is_last || *end != ':')) ||
|
||||
(v == ULLONG_MAX && errno == ERANGE)) {
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -165,6 +125,27 @@ static void handle_cpu_env(uint32_t *out, const char *in) {
|
||||
}
|
||||
}
|
||||
|
||||
void OPENSSL_adjust_ia32cap(uint32_t cap[4], const char *env) {
|
||||
// OPENSSL_ia32cap can contain zero, one or two values, separated with a ':'.
|
||||
// Each value is a 64-bit, unsigned value which may start with "0x" to
|
||||
// indicate a hex value. Prior to the 64-bit value, a '~' or '|' may be given.
|
||||
//
|
||||
// If the '~' prefix is present:
|
||||
// the value is inverted and ANDed with the probed CPUID result
|
||||
// If the '|' prefix is present:
|
||||
// the value is ORed with the probed CPUID result
|
||||
// Otherwise:
|
||||
// the value is taken as the result of the CPUID
|
||||
//
|
||||
// The first value determines OPENSSL_ia32cap_P[0] and [1]. The second [2]
|
||||
// and [3].
|
||||
handle_cpu_env(cap, env, /*is_last=*/false);
|
||||
env = strchr(env, ':');
|
||||
if (env != nullptr) {
|
||||
handle_cpu_env(cap + 2, env + 1, /*is_last=*/true);
|
||||
}
|
||||
}
|
||||
|
||||
void OPENSSL_cpuid_setup(void) {
|
||||
// Determine the vendor and maximum input value.
|
||||
uint32_t eax, ebx, ecx, edx;
|
||||
@@ -172,11 +153,11 @@ void OPENSSL_cpuid_setup(void) {
|
||||
|
||||
uint32_t num_ids = eax;
|
||||
|
||||
int is_intel = ebx == 0x756e6547 /* Genu */ && //
|
||||
edx == 0x49656e69 /* ineI */ && //
|
||||
int is_intel = ebx == 0x756e6547 /* Genu */ && //
|
||||
edx == 0x49656e69 /* ineI */ && //
|
||||
ecx == 0x6c65746e /* ntel */;
|
||||
int is_amd = ebx == 0x68747541 /* Auth */ && //
|
||||
edx == 0x69746e65 /* enti */ && //
|
||||
int is_amd = ebx == 0x68747541 /* Auth */ && //
|
||||
edx == 0x69746e65 /* enti */ && //
|
||||
ecx == 0x444d4163 /* cAMD */;
|
||||
|
||||
uint32_t extended_features[2] = {0};
|
||||
@@ -213,14 +194,6 @@ void OPENSSL_cpuid_setup(void) {
|
||||
}
|
||||
}
|
||||
|
||||
// Force the hyper-threading bit so that the more conservative path is always
|
||||
// chosen.
|
||||
edx |= 1u << 28;
|
||||
|
||||
// Reserved bit #20 was historically repurposed to control the in-memory
|
||||
// representation of RC4 state. Always set it to zero.
|
||||
edx &= ~(1u << 20);
|
||||
|
||||
// Reserved bit #30 is repurposed to signal an Intel CPU.
|
||||
if (is_intel) {
|
||||
edx |= (1u << 30);
|
||||
@@ -228,10 +201,6 @@ void OPENSSL_cpuid_setup(void) {
|
||||
edx &= ~(1u << 30);
|
||||
}
|
||||
|
||||
// The SDBG bit is repurposed to denote AMD XOP support. Don't ever use AMD
|
||||
// XOP code paths.
|
||||
ecx &= ~(1u << 11);
|
||||
|
||||
uint64_t xcr0 = 0;
|
||||
if (ecx & (1u << 27)) {
|
||||
// XCR0 may only be queried if the OSXSAVE bit is set.
|
||||
@@ -261,10 +230,6 @@ void OPENSSL_cpuid_setup(void) {
|
||||
// 128-bit or 256-bit vectors, and also volume 2a section 2.7.11 ("#UD
|
||||
// Equations for EVEX") which says that all EVEX-coded instructions raise an
|
||||
// undefined-instruction exception if any of these XCR0 bits is zero.
|
||||
//
|
||||
// AVX10 fixes this by reorganizing the features that used to be part of
|
||||
// "AVX512" and allowing them to be used independently of 512-bit support.
|
||||
// TODO: add AVX10 detection.
|
||||
extended_features[0] &= ~(1u << 16); // AVX512F
|
||||
extended_features[0] &= ~(1u << 17); // AVX512DQ
|
||||
extended_features[0] &= ~(1u << 21); // AVX512IFMA
|
||||
@@ -311,30 +276,9 @@ void OPENSSL_cpuid_setup(void) {
|
||||
OPENSSL_ia32cap_P[2] = extended_features[0];
|
||||
OPENSSL_ia32cap_P[3] = extended_features[1];
|
||||
|
||||
const char *env1, *env2;
|
||||
env1 = getenv("OPENSSL_ia32cap");
|
||||
if (env1 == NULL) {
|
||||
return;
|
||||
}
|
||||
|
||||
// OPENSSL_ia32cap can contain zero, one or two values, separated with a ':'.
|
||||
// Each value is a 64-bit, unsigned value which may start with "0x" to
|
||||
// indicate a hex value. Prior to the 64-bit value, a '~' or '|' may be given.
|
||||
//
|
||||
// If the '~' prefix is present:
|
||||
// the value is inverted and ANDed with the probed CPUID result
|
||||
// If the '|' prefix is present:
|
||||
// the value is ORed with the probed CPUID result
|
||||
// Otherwise:
|
||||
// the value is taken as the result of the CPUID
|
||||
//
|
||||
// The first value determines OPENSSL_ia32cap_P[0] and [1]. The second [2]
|
||||
// and [3].
|
||||
|
||||
handle_cpu_env(&OPENSSL_ia32cap_P[0], env1);
|
||||
env2 = strchr(env1, ':');
|
||||
if (env2 != NULL) {
|
||||
handle_cpu_env(&OPENSSL_ia32cap_P[2], env2 + 1);
|
||||
const char *env = getenv("OPENSSL_ia32cap");
|
||||
if (env != nullptr) {
|
||||
OPENSSL_adjust_ia32cap(OPENSSL_ia32cap_P, env);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1,16 +1,16 @@
|
||||
/* Copyright 2014 The BoringSSL Authors
|
||||
*
|
||||
* 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. */
|
||||
// Copyright 2014 The BoringSSL Authors
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// https://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
#include <CCryptoBoringSSL_crypto.h>
|
||||
|
||||
@@ -67,54 +67,19 @@ uint32_t OPENSSL_get_ia32cap(int idx) {
|
||||
return OPENSSL_ia32cap_P[idx];
|
||||
}
|
||||
|
||||
#elif defined(OPENSSL_ARM) || defined(OPENSSL_AARCH64)
|
||||
|
||||
#include <CCryptoBoringSSL_arm_arch.h>
|
||||
|
||||
#if defined(OPENSSL_STATIC_ARMCAP)
|
||||
|
||||
// See ARM ACLE for the definitions of these macros. Note |__ARM_FEATURE_AES|
|
||||
// covers both AES and PMULL and |__ARM_FEATURE_SHA2| covers SHA-1 and SHA-256.
|
||||
// https://developer.arm.com/architectures/system-architectures/software-standards/acle
|
||||
// https://github.com/ARM-software/acle/issues/152
|
||||
//
|
||||
// TODO(davidben): Do we still need |OPENSSL_STATIC_ARMCAP_*| or are the
|
||||
// standard flags and -march sufficient?
|
||||
HIDDEN uint32_t OPENSSL_armcap_P =
|
||||
#if defined(OPENSSL_STATIC_ARMCAP_NEON) || defined(__ARM_NEON)
|
||||
ARMV7_NEON |
|
||||
#endif
|
||||
#if defined(OPENSSL_STATIC_ARMCAP_AES) || defined(__ARM_FEATURE_AES)
|
||||
ARMV8_AES |
|
||||
#endif
|
||||
#if defined(OPENSSL_STATIC_ARMCAP_PMULL) || defined(__ARM_FEATURE_AES)
|
||||
ARMV8_PMULL |
|
||||
#endif
|
||||
#if defined(OPENSSL_STATIC_ARMCAP_SHA1) || defined(__ARM_FEATURE_SHA2)
|
||||
ARMV8_SHA1 |
|
||||
#endif
|
||||
#if defined(OPENSSL_STATIC_ARMCAP_SHA256) || defined(__ARM_FEATURE_SHA2)
|
||||
ARMV8_SHA256 |
|
||||
#endif
|
||||
#if defined(__ARM_FEATURE_SHA512)
|
||||
ARMV8_SHA512 |
|
||||
#endif
|
||||
0;
|
||||
|
||||
#else
|
||||
#elif (defined(OPENSSL_ARM) || defined(OPENSSL_AARCH64)) && \
|
||||
!defined(OPENSSL_STATIC_ARMCAP)
|
||||
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(NEED_CPUID)
|
||||
|
||||
@@ -1,22 +1,22 @@
|
||||
#define BORINGSSL_PREFIX CCryptoBoringSSL
|
||||
#if defined(__arm__) && defined(__linux__)
|
||||
/* Copyright 2015 The BoringSSL Authors
|
||||
*
|
||||
* 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. */
|
||||
// Copyright 2015 The BoringSSL Authors
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// https://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
/* This file is taken from crypto_scalarmult/curve25519/neon2/scalarmult.s in
|
||||
* SUPERCOP 20141124 (http://bench.cr.yp.to/supercop.html). That code is public
|
||||
* domain licensed but the standard ISC license is included above to keep
|
||||
* domain licensed but the standard Apache 2.0 license is included above to keep
|
||||
* licensing simple. */
|
||||
|
||||
#include <CCryptoBoringSSL_asm_base.h>
|
||||
|
||||
Loaded 100 of 774 files, more files were not shown because too many files have changed in this diff.
Show more
Reference in new issue
Block a user