mirror of
https://github.com/apple/swift-crypto
synced 2026-11-22 04:30:39 +00:00
Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
deb49b961e | ||
|
|
0f6f68df04 | ||
|
|
1c80d3aff5 | ||
|
|
25847ff705 | ||
|
|
8c018d0882 | ||
|
|
a629920495 | ||
|
|
a9d1d5ab89 | ||
|
|
da9d28d69e | ||
|
|
f79a3ffbc0 | ||
|
|
fa2832e44b | ||
|
|
315a799ccc | ||
|
|
3ed653865a | ||
|
|
47d3869a72 | ||
|
|
c3d9fc8938 | ||
|
|
1ca42a1885 | ||
|
|
1b6b2e274e | ||
|
|
2d37b1192f | ||
|
|
c5b1d7f0cb | ||
|
|
476538ccb8 | ||
|
|
5ef6059b2b | ||
|
|
bb4ba815da | ||
|
|
fa308c07a6 | ||
|
|
a5a71cfcbc | ||
|
|
31611736b0 | ||
|
|
6f70fa9eab | ||
|
|
e8ed8867ec | ||
|
|
87a9e066d9 | ||
|
|
781478b4e0 | ||
|
|
bcd2b89f2a | ||
|
+6 |
431013afaf | ||
|
|
95ba0316a9 | ||
|
|
527fef6228 | ||
|
|
b1f7679f29 | ||
|
|
c661debfc2 | ||
|
|
141f5b4e17 | ||
|
|
9552067c74 | ||
|
|
c46250209e | ||
|
|
d1c6b70f7c | ||
|
|
b7c303d97b | ||
|
|
c066b057ed | ||
|
|
2347f20e24 | ||
|
|
334e682869 | ||
|
|
c68a7a7c7f | ||
|
|
8c9d27a339 | ||
|
|
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 | ||
|
|
a6ce32a18b | ||
|
|
67e54ae1db | ||
|
|
a8a02ac79a | ||
|
|
fca04734d7 | ||
|
|
4ac764398d | ||
|
|
a98e4be0dd | ||
|
|
f4c4efd424 | ||
|
|
7ba43666c5 | ||
|
|
45305d32cf | ||
|
|
b6049c0b2e | ||
|
|
b81059d507 | ||
|
|
06fc9b0a09 | ||
|
|
472de789e9 | ||
|
|
75a3eca905 | ||
|
|
b828ba476a | ||
|
|
f2f3774fd1 | ||
|
|
a84771015f | ||
|
|
2934bb4cf8 | ||
|
|
0bf9f479b8 | ||
|
|
bce1725222 | ||
|
|
555b9f1dab | ||
|
|
600eda380a | ||
|
|
865068322c | ||
|
|
dc4c2c14e7 | ||
|
|
0ec5ca1e3f | ||
|
|
bd94260799 | ||
|
|
ff0f781cf7 | ||
|
|
a3b7196be9 | ||
|
|
b6a32eb851 | ||
|
|
e14f4bb065 | ||
|
|
06dc63c6d8 | ||
|
|
62958ed575 | ||
|
|
e9d46e7bf9 | ||
|
|
8fa345c208 | ||
|
|
7cb61135cb | ||
|
|
4518e5e680 | ||
|
|
4324b40570 | ||
|
|
f98e46e42a | ||
|
|
ae321d29be | ||
|
|
21f7878f2b | ||
|
|
735a29ccf7 | ||
|
|
b639b5bd1f | ||
|
|
ffca28be3c | ||
|
|
35703579f6 | ||
|
|
a24950b8aa | ||
|
|
e8f2ddd49e | ||
|
|
55201a8f83 | ||
|
|
81bee98e70 | ||
|
|
ce204da6f6 | ||
|
|
9f95b4d033 | ||
|
|
a53a7e8f85 | ||
|
|
8dafe0fdce | ||
|
|
e2dd5a547b | ||
|
|
46072478ca |
No files matched your search
@@ -0,0 +1,28 @@
|
||||
{
|
||||
"name": "swift-crypto",
|
||||
"image": "swift:latest",
|
||||
"features": {
|
||||
"ghcr.io/devcontainers/features/common-utils:2": {
|
||||
"installZsh": "false",
|
||||
"username": "vscode",
|
||||
"upgradePackages": "false"
|
||||
},
|
||||
"ghcr.io/devcontainers/features/git:1": {
|
||||
"version": "latest"
|
||||
}
|
||||
},
|
||||
"capAdd": ["CAP_SYS_PTRACE"],
|
||||
"securityOpt": ["seccomp=unconfined"],
|
||||
"customizations": {
|
||||
"vscode": {
|
||||
"settings": {
|
||||
"swift.path": "/usr/bin",
|
||||
"lldb.library": "/usr/lib/liblldb.so"
|
||||
},
|
||||
"extensions": [
|
||||
"swiftlang.swift-vscode"
|
||||
]
|
||||
}
|
||||
},
|
||||
"remoteUser": "vscode"
|
||||
}
|
||||
@@ -0,0 +1,8 @@
|
||||
root = true
|
||||
|
||||
[*]
|
||||
indent_style = space
|
||||
indent_size = 4
|
||||
end_of_line = lf
|
||||
insert_final_newline = true
|
||||
trim_trailing_whitespace = true
|
||||
@@ -9,7 +9,7 @@ about: If something isn't working as expected
|
||||
### New Issue Checklist
|
||||
|
||||
- [ ] I'm using the latest version of Swift Crypto (`main` branch)
|
||||
- [ ] I read the [Contribution Guidelines](https://github.com/apple/swift-crypto/blob/master/CONTRIBUTING.md)
|
||||
- [ ] I read the [Contribution Guidelines](https://github.com/apple/swift-crypto/blob/main/CONTRIBUTING.md)
|
||||
- [ ] I searched for [existing GitHub issues](https://github.com/apple/swift-crypto/issues)
|
||||
|
||||
### Expected behavior
|
||||
|
||||
@@ -6,8 +6,8 @@ about: Not sure how something works or how to implement some functionality? Ask
|
||||
|
||||
### Question Checklist
|
||||
|
||||
- [ ] I'm using the latest version of Swift Crypto (master branch)
|
||||
- [ ] I read the [Contribution Guidelines](https://github.com/apple/swift-crypto/blob/master/CONTRIBUTING.md)
|
||||
- [ ] I'm using the latest version of Swift Crypto (main branch)
|
||||
- [ ] I read the [Contribution Guidelines](https://github.com/apple/swift-crypto/blob/main/CONTRIBUTING.md)
|
||||
- [ ] I searched for [existing GitHub issues](https://github.com/apple/swift-crypto/issues)
|
||||
|
||||
### Question Subject
|
||||
|
||||
@@ -8,8 +8,8 @@ about: If a recent release broke a feature (Please make sure you know the last k
|
||||
|
||||
### New Regression Checklist
|
||||
|
||||
- [ ] I'm using the latest version of Swift Crypto (master branch)
|
||||
- [ ] I read the [Contribution Guidelines](https://github.com/apple/swift-crypto/blob/master/CONTRIBUTING.md)
|
||||
- [ ] I'm using the latest version of Swift Crypto (main branch)
|
||||
- [ ] I read the [Contribution Guidelines](https://github.com/apple/swift-crypto/blob/main/CONTRIBUTING.md)
|
||||
- [ ] I searched for [existing GitHub issues](https://github.com/apple/swift-crypto/issues)
|
||||
|
||||
### Regression Information
|
||||
|
||||
@@ -9,7 +9,7 @@ _[One line description of your change]_
|
||||
- [ ] I've updated the documentation if necessary
|
||||
|
||||
#### If you've made changes to `gyb` files
|
||||
- [ ] I've run `.script/generate_boilerplate_files_with_gyb` and included updated generated files in a commit of this pull request
|
||||
- [ ] I've run `./scripts/generate_boilerplate_files_with_gyb.sh` and included updated generated files in a commit of this pull request
|
||||
|
||||
### Motivation:
|
||||
|
||||
@@ -21,4 +21,4 @@ _[Describe the modifications you've done.]_
|
||||
|
||||
### Result:
|
||||
|
||||
_[After your change, what will change.]_
|
||||
_[After your change, what will change.]_
|
||||
@@ -0,0 +1,14 @@
|
||||
changelog:
|
||||
categories:
|
||||
- title: SemVer Major
|
||||
labels:
|
||||
- ⚠️ semver/major
|
||||
- title: SemVer Minor
|
||||
labels:
|
||||
- 🆕 semver/minor
|
||||
- title: SemVer Patch
|
||||
labels:
|
||||
- 🔨 semver/patch
|
||||
- title: Other Changes
|
||||
labels:
|
||||
- semver/none
|
||||
@@ -0,0 +1,58 @@
|
||||
name: Main
|
||||
|
||||
permissions:
|
||||
contents: read
|
||||
|
||||
on:
|
||||
push:
|
||||
branches: [main]
|
||||
schedule:
|
||||
- cron: "0 8,20 * * *"
|
||||
|
||||
jobs:
|
||||
unit-tests:
|
||||
name: Unit tests
|
||||
uses: apple/swift-nio/.github/workflows/unit_tests.yml@main
|
||||
with:
|
||||
linux_5_10_arguments_override: "--explicit-target-dependency-import-check error"
|
||||
linux_6_1_arguments_override: "--explicit-target-dependency-import-check error"
|
||||
linux_6_2_arguments_override: "--explicit-target-dependency-import-check error"
|
||||
linux_6_3_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_1_enabled: true
|
||||
windows_6_2_enabled: true
|
||||
windows_6_3_enabled: true
|
||||
windows_nightly_next_enabled: true
|
||||
windows_nightly_main_enabled: true
|
||||
windows_6_1_arguments_override: "--explicit-target-dependency-import-check error"
|
||||
windows_6_2_arguments_override: "--explicit-target-dependency-import-check error"
|
||||
windows_6_3_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"
|
||||
|
||||
release-builds:
|
||||
name: Release builds
|
||||
uses: apple/swift-nio/.github/workflows/release_builds.yml@main
|
||||
with:
|
||||
windows_6_1_enabled: true
|
||||
windows_6_2_enabled: true
|
||||
windows_6_3_enabled: true
|
||||
windows_nightly_next_enabled: true
|
||||
windows_nightly_main_enabled: true
|
||||
|
||||
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
|
||||
swift_6_1_enabled: false
|
||||
@@ -0,0 +1,76 @@
|
||||
name: PR
|
||||
|
||||
permissions:
|
||||
contents: read
|
||||
|
||||
on:
|
||||
pull_request:
|
||||
types: [opened, reopened, synchronize]
|
||||
|
||||
jobs:
|
||||
soundness:
|
||||
name: Soundness
|
||||
uses: swiftlang/github-workflows/.github/workflows/soundness.yml@0.0.13
|
||||
with:
|
||||
license_header_check_project_name: "SwiftCrypto"
|
||||
docs_check_enabled: false
|
||||
|
||||
unit-tests:
|
||||
name: Unit tests
|
||||
uses: apple/swift-nio/.github/workflows/unit_tests.yml@main
|
||||
with:
|
||||
linux_6_2_arguments_override: "-Xswiftc -warnings-as-errors -Xswiftc -Wwarning -Xswiftc ImplementationOnlyDeprecated --explicit-target-dependency-import-check error"
|
||||
linux_6_3_arguments_override: "-Xswiftc -warnings-as-errors -Xswiftc -Wwarning -Xswiftc ImplementationOnlyDeprecated --explicit-target-dependency-import-check error"
|
||||
linux_nightly_next_arguments_override: "-Xswiftc -warnings-as-errors -Xswiftc -Wwarning -Xswiftc ImplementationOnlyDeprecated --explicit-target-dependency-import-check error"
|
||||
linux_nightly_main_arguments_override: "--explicit-target-dependency-import-check error"
|
||||
windows_6_2_enabled: true
|
||||
windows_6_3_enabled: true
|
||||
windows_nightly_next_enabled: true
|
||||
windows_nightly_main_enabled: true
|
||||
windows_6_2_arguments_override: "-Xswiftc -warnings-as-errors -Xswiftc -Wwarning -Xswiftc ImplementationOnlyDeprecated --explicit-target-dependency-import-check error"
|
||||
windows_6_3_arguments_override: "-Xswiftc -warnings-as-errors -Xswiftc -Wwarning -Xswiftc ImplementationOnlyDeprecated --explicit-target-dependency-import-check error"
|
||||
windows_nightly_next_arguments_override: "-Xswiftc -warnings-as-errors -Xswiftc -Wwarning -Xswiftc ImplementationOnlyDeprecated --explicit-target-dependency-import-check error"
|
||||
windows_nightly_main_arguments_override: "--explicit-target-dependency-import-check error"
|
||||
|
||||
release-builds:
|
||||
name: Release builds
|
||||
uses: apple/swift-nio/.github/workflows/release_builds.yml@main
|
||||
with:
|
||||
windows_6_2_enabled: true
|
||||
windows_6_3_enabled: true
|
||||
windows_nightly_next_enabled: true
|
||||
windows_nightly_main_enabled: true
|
||||
|
||||
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": "CryptoBoringWrapper", "type": "source", "exceptions": [] },
|
||||
{ "name": "CXKCP", "type": "source", "exceptions": [] },
|
||||
{ "name": "CXKCPShims", "type": "source", "exceptions": [] },
|
||||
{ "name": "Crypto", "type": "source", "exceptions": [] },
|
||||
{ "name": "CryptoExtras", "type": "source", "exceptions": [] },
|
||||
{ "name": "CCryptoBoringSSL", "type": "assembly", "exceptions": [ "*/AES/*.swift" ] }
|
||||
]
|
||||
}
|
||||
image: swift:6.2
|
||||
|
||||
macos-tests:
|
||||
name: macOS tests
|
||||
uses: apple/swift-nio/.github/workflows/macos_tests.yml@main
|
||||
with:
|
||||
runner_pool: general
|
||||
build_scheme: swift-crypto-Package
|
||||
swift_6_1_enabled: false
|
||||
|
||||
static-sdk:
|
||||
name: Static SDK
|
||||
uses: apple/swift-nio/.github/workflows/static_sdk.yml@main
|
||||
@@ -0,0 +1,21 @@
|
||||
name: PR label
|
||||
|
||||
permissions:
|
||||
contents: read
|
||||
|
||||
on:
|
||||
pull_request:
|
||||
types: [labeled, unlabeled, opened, reopened, synchronize]
|
||||
|
||||
jobs:
|
||||
semver-label-check:
|
||||
name: Semantic version label check
|
||||
runs-on: ubuntu-latest
|
||||
timeout-minutes: 1
|
||||
steps:
|
||||
- name: Checkout repository
|
||||
uses: actions/checkout@v6
|
||||
with:
|
||||
persist-credentials: false
|
||||
- name: Check for Semantic Version label
|
||||
uses: apple/swift-nio/.github/actions/pull_request_semver_label_checker@main
|
||||
+2
-1
@@ -1,5 +1,5 @@
|
||||
.DS_Store
|
||||
/.build
|
||||
.build
|
||||
/out
|
||||
/Packages
|
||||
/*.xcodeproj
|
||||
@@ -12,6 +12,7 @@ Package.resolved
|
||||
DerivedData
|
||||
.swiftpm
|
||||
**/gyb.pyc
|
||||
scripts/__pycache__/
|
||||
|
||||
.*.sw[nop]
|
||||
|
||||
|
||||
@@ -0,0 +1,50 @@
|
||||
.gitignore
|
||||
**/.gitignore
|
||||
.licenseignore
|
||||
.unacceptablelanguageignore
|
||||
.swiftformatignore
|
||||
.gitattributes
|
||||
.git-blame-ignore-revs
|
||||
.mailfilter
|
||||
.mailmap
|
||||
.spi.yml
|
||||
.swift-format
|
||||
.editorconfig
|
||||
.github/*
|
||||
*.md
|
||||
*.txt
|
||||
*.yml
|
||||
*.yaml
|
||||
*.json
|
||||
Package.swift
|
||||
**/Package.swift
|
||||
Package@-*.swift
|
||||
**/Package@-*.swift
|
||||
Package.resolved
|
||||
**/Package.resolved
|
||||
Makefile
|
||||
*.modulemap
|
||||
**/*.modulemap
|
||||
**/*.docc/*
|
||||
*.xcprivacy
|
||||
**/*.xcprivacy
|
||||
*.symlink
|
||||
**/*.symlink
|
||||
Dockerfile
|
||||
**/Dockerfile
|
||||
Snippets/*
|
||||
dev/git.commit.template
|
||||
dev/update-benchmark-thresholds
|
||||
*.crt
|
||||
**/*.crt
|
||||
*.pem
|
||||
**/*.pem
|
||||
*.der
|
||||
**/*.der
|
||||
.swiftformat
|
||||
Sources/CCryptoBoringSSL/*
|
||||
Sources/CXKCP/*
|
||||
**/*.swift.gyb
|
||||
scripts/*.patch
|
||||
scripts/gyb
|
||||
scripts/gyb.py
|
||||
@@ -0,0 +1,5 @@
|
||||
version: 1
|
||||
builder:
|
||||
configs:
|
||||
- documentation_targets: [Crypto, CryptoExtras]
|
||||
platform: linux
|
||||
@@ -0,0 +1,62 @@
|
||||
{
|
||||
"version" : 1,
|
||||
"indentation" : {
|
||||
"spaces" : 4
|
||||
},
|
||||
"tabWidth" : 4,
|
||||
"fileScopedDeclarationPrivacy" : {
|
||||
"accessLevel" : "private"
|
||||
},
|
||||
"spacesAroundRangeFormationOperators" : false,
|
||||
"indentConditionalCompilationBlocks" : false,
|
||||
"indentSwitchCaseLabels" : false,
|
||||
"lineBreakAroundMultilineExpressionChainComponents" : false,
|
||||
"lineBreakBeforeControlFlowKeywords" : false,
|
||||
"lineBreakBeforeEachArgument" : true,
|
||||
"lineBreakBeforeEachGenericRequirement" : true,
|
||||
"lineLength" : 120,
|
||||
"maximumBlankLines" : 1,
|
||||
"respectsExistingLineBreaks" : true,
|
||||
"prioritizeKeepingFunctionOutputTogether" : true,
|
||||
"rules" : {
|
||||
"AllPublicDeclarationsHaveDocumentation" : false,
|
||||
"AlwaysUseLiteralForEmptyCollectionInit" : false,
|
||||
"AlwaysUseLowerCamelCase" : false,
|
||||
"AmbiguousTrailingClosureOverload" : true,
|
||||
"BeginDocumentationCommentWithOneLineSummary" : false,
|
||||
"DoNotUseSemicolons" : true,
|
||||
"DontRepeatTypeInStaticProperties" : true,
|
||||
"FileScopedDeclarationPrivacy" : true,
|
||||
"FullyIndirectEnum" : true,
|
||||
"GroupNumericLiterals" : true,
|
||||
"IdentifiersMustBeASCII" : true,
|
||||
"NeverForceUnwrap" : false,
|
||||
"NeverUseForceTry" : false,
|
||||
"NeverUseImplicitlyUnwrappedOptionals" : false,
|
||||
"NoAccessLevelOnExtensionDeclaration" : true,
|
||||
"NoAssignmentInExpressions" : true,
|
||||
"NoBlockComments" : true,
|
||||
"NoCasesWithOnlyFallthrough" : true,
|
||||
"NoEmptyTrailingClosureParentheses" : true,
|
||||
"NoLabelsInCasePatterns" : true,
|
||||
"NoLeadingUnderscores" : false,
|
||||
"NoParensAroundConditions" : true,
|
||||
"NoVoidReturnOnFunctionSignature" : true,
|
||||
"OmitExplicitReturns" : true,
|
||||
"OneCasePerLine" : true,
|
||||
"OneVariableDeclarationPerLine" : true,
|
||||
"OnlyOneTrailingClosureArgument" : true,
|
||||
"OrderedImports" : true,
|
||||
"ReplaceForEachWithForLoop" : true,
|
||||
"ReturnVoidInsteadOfEmptyTuple" : true,
|
||||
"UseEarlyExits" : false,
|
||||
"UseExplicitNilCheckInConditions" : false,
|
||||
"UseLetInEveryBoundCaseVariable" : false,
|
||||
"UseShorthandTypeNames" : true,
|
||||
"UseSingleLinePropertyGetter" : false,
|
||||
"UseSynthesizedInitializer" : false,
|
||||
"UseTripleSlashForDocumentationComments" : true,
|
||||
"UseWhereClausesInForLoops" : false,
|
||||
"ValidateDocumentationComments" : false
|
||||
}
|
||||
}
|
||||
@@ -1,13 +0,0 @@
|
||||
# file options
|
||||
|
||||
--swiftversion 5.4
|
||||
--exclude .build
|
||||
|
||||
# format options
|
||||
|
||||
--self insert
|
||||
--patternlet inline
|
||||
--stripunusedargs unnamed-only
|
||||
--ifdef no-indent
|
||||
|
||||
# rules
|
||||
@@ -0,0 +1,174 @@
|
||||
Package.swift
|
||||
Sources/Crypto/AEADs/AES/GCM/AES-GCM.swift
|
||||
Sources/Crypto/AEADs/ChachaPoly/ChaChaPoly.swift
|
||||
Sources/Crypto/AEADs/Cipher.swift
|
||||
Sources/Crypto/AEADs/Nonces.swift
|
||||
Sources/Crypto/ASN1/ASN1.swift
|
||||
Sources/Crypto/ASN1/Basic ASN1 Types/ASN1Any.swift
|
||||
Sources/Crypto/ASN1/Basic ASN1 Types/ASN1BitString.swift
|
||||
Sources/Crypto/ASN1/Basic ASN1 Types/ASN1Boolean.swift
|
||||
Sources/Crypto/ASN1/Basic ASN1 Types/ASN1Identifier.swift
|
||||
Sources/Crypto/ASN1/Basic ASN1 Types/ASN1Integer.swift
|
||||
Sources/Crypto/ASN1/Basic ASN1 Types/ASN1Null.swift
|
||||
Sources/Crypto/ASN1/Basic ASN1 Types/ASN1OctetString.swift
|
||||
Sources/Crypto/ASN1/Basic ASN1 Types/ASN1Strings.swift
|
||||
Sources/Crypto/ASN1/Basic ASN1 Types/ArraySliceBigint.swift
|
||||
Sources/Crypto/ASN1/Basic ASN1 Types/GeneralizedTime.swift
|
||||
Sources/Crypto/ASN1/Basic ASN1 Types/ObjectIdentifier.swift
|
||||
Sources/Crypto/ASN1/ECDSASignature.swift
|
||||
Sources/Crypto/ASN1/PEMDocument.swift
|
||||
Sources/Crypto/ASN1/PKCS8PrivateKey.swift
|
||||
Sources/Crypto/ASN1/SEC1PrivateKey.swift
|
||||
Sources/Crypto/ASN1/SubjectPublicKeyInfo.swift
|
||||
Sources/Crypto/CryptoKitErrors.swift
|
||||
Sources/Crypto/Digests/Digest.swift
|
||||
Sources/Crypto/Digests/Digests.swift
|
||||
Sources/Crypto/Digests/HashFunctions.swift
|
||||
Sources/Crypto/Digests/HashFunctions_SHA2.swift
|
||||
Sources/Crypto/Digests/HashFunctions_SHA3.swift
|
||||
Sources/Crypto/HPKE/Ciphersuite/HPKE-AEAD.swift
|
||||
Sources/Crypto/HPKE/Ciphersuite/HPKE-Ciphersuite.swift
|
||||
Sources/Crypto/HPKE/Ciphersuite/HPKE-KDF.swift
|
||||
Sources/Crypto/HPKE/Ciphersuite/HPKE-KexKeyDerivation.swift
|
||||
Sources/Crypto/HPKE/Ciphersuite/HPKE-LabeledExtract.swift
|
||||
Sources/Crypto/HPKE/Ciphersuite/HPKE-Utils.swift
|
||||
Sources/Crypto/HPKE/Ciphersuite/KEM/Conformances/DHKEM.swift
|
||||
Sources/Crypto/HPKE/Ciphersuite/KEM/Conformances/HPKE-KEM-Curve25519.swift
|
||||
Sources/Crypto/HPKE/Ciphersuite/KEM/Conformances/HPKE-NIST-EC-KEMs.swift
|
||||
Sources/Crypto/HPKE/Ciphersuite/KEM/HPKE-KEM.swift
|
||||
Sources/Crypto/HPKE/HPKE-Errors.swift
|
||||
Sources/Crypto/HPKE/HPKE.swift
|
||||
Sources/Crypto/HPKE/Key Schedule/HPKE-Context.swift
|
||||
Sources/Crypto/HPKE/Key Schedule/HPKE-KeySchedule.swift
|
||||
Sources/Crypto/HPKE/Modes/HPKE-Modes.swift
|
||||
Sources/Crypto/Insecure/Insecure.swift
|
||||
Sources/Crypto/Insecure/Insecure_HashFunctions.swift
|
||||
Sources/Crypto/KEM/KEM.swift
|
||||
Sources/Crypto/KEM/KEM-Errors.swift
|
||||
Sources/Crypto/KEM/MLKEM.swift
|
||||
Sources/Crypto/KEM/XWing.swift
|
||||
Sources/Crypto/Key Agreement/DH.swift
|
||||
Sources/Crypto/Key Agreement/ECDH.swift
|
||||
Sources/Crypto/Key Derivation/ANSIx963.swift
|
||||
Sources/Crypto/Key Derivation/HKDF.swift
|
||||
Sources/Crypto/Key Wrapping/AESWrap.swift
|
||||
Sources/Crypto/Keys/EC/Curve25519.swift
|
||||
Sources/Crypto/Keys/EC/Ed25519Keys.swift
|
||||
Sources/Crypto/Keys/EC/NISTCurvesKeys.swift
|
||||
Sources/Crypto/Keys/EC/X25519Keys.swift
|
||||
Sources/Crypto/Keys/Symmetric/SymmetricKeys.swift
|
||||
Sources/Crypto/Message Authentication Codes/HMAC/HMAC.swift
|
||||
Sources/Crypto/Message Authentication Codes/MACFunctions.swift
|
||||
Sources/Crypto/Message Authentication Codes/MessageAuthenticationCode.swift
|
||||
Sources/Crypto/PRF/AES.swift
|
||||
Sources/Crypto/Signatures/ECDSA.swift
|
||||
Sources/Crypto/Signatures/Ed25519.swift
|
||||
Sources/Crypto/Signatures/MLDSA.swift
|
||||
Sources/Crypto/Signatures/Signature.swift
|
||||
Sources/Crypto/Util/ArraySpanHelpers.swift
|
||||
Sources/Crypto/Util/Data+ArraySpan.swift
|
||||
Sources/Crypto/Util/PrettyBytes.swift
|
||||
Sources/Crypto/Util/SafeCompare.swift
|
||||
Sources/Crypto/Util/SecureBytes.swift
|
||||
Sources/Crypto/Util/Zeroization.swift
|
||||
Sources/CryptoExtras/AES/AES_CBC.swift
|
||||
Sources/CryptoExtras/AES/AES_CFB.swift
|
||||
Sources/CryptoExtras/AES/AES_CTR.swift
|
||||
Sources/CryptoExtras/AES/AES_GCM_SIV.swift
|
||||
Sources/CryptoExtras/AES/Block Function.swift
|
||||
Sources/CryptoExtras/ARC/ARC+API.swift
|
||||
Sources/CryptoExtras/ARC/ARC.swift
|
||||
Sources/CryptoExtras/ARC/ARCCredential.swift
|
||||
Sources/CryptoExtras/ARC/ARCEncoding.swift
|
||||
Sources/CryptoExtras/ARC/ARCPrecredential.swift
|
||||
Sources/CryptoExtras/ARC/ARCPresentation.swift
|
||||
Sources/CryptoExtras/ARC/ARCRequest.swift
|
||||
Sources/CryptoExtras/ARC/ARCResponse.swift
|
||||
Sources/CryptoExtras/ARC/ARCServer.swift
|
||||
Sources/CryptoExtras/ZKPs/Prover.swift
|
||||
Sources/CryptoExtras/ZKPs/Verifier.swift
|
||||
Sources/CryptoExtras/ZKPs/ZKPToolbox.swift
|
||||
Sources/CryptoExtras/ChaCha20CTR/ChaCha20CTR.swift
|
||||
Sources/CryptoExtras/ECToolbox/ECToolbox.swift
|
||||
Sources/CryptoExtras/H2G/HashToField.swift
|
||||
Sources/CryptoExtras/Key Derivation/KDF.swift
|
||||
Sources/CryptoExtras/Key Derivation/PBKDF2/PBKDF2.swift
|
||||
Sources/CryptoExtras/Key Derivation/Scrypt/Scrypt.swift
|
||||
Sources/CryptoExtras/OPRFs/OPRF.swift
|
||||
Sources/CryptoExtras/OPRFs/OPRFClient.swift
|
||||
Sources/CryptoExtras/OPRFs/OPRFServer.swift
|
||||
Sources/CryptoExtras/OPRFs/VOPRF+API.swift
|
||||
Sources/CryptoExtras/OPRFs/VOPRFClient.swift
|
||||
Sources/CryptoExtras/OPRFs/VOPRFServer.swift
|
||||
Sources/CryptoExtras/RSA/RSA+BlindSigning.swift
|
||||
Sources/CryptoExtras/RSA/RSA.swift
|
||||
Sources/CryptoExtras/Util/BoringSSLHelpers.swift
|
||||
Sources/CryptoExtras/Util/DigestType.swift
|
||||
Sources/CryptoExtras/Util/Error.swift
|
||||
Sources/CryptoExtras/Util/I2OSP.swift
|
||||
Sources/CryptoExtras/Util/IntegerEncoding.swift
|
||||
Sources/CryptoExtras/Util/PEMDocument.swift
|
||||
Sources/CryptoExtras/Util/PrettyBytes.swift
|
||||
Sources/CryptoExtras/Util/SubjectPublicKeyInfo.swift
|
||||
Sources/CryptoExtras/ZKPs/DLEQ.swift
|
||||
Sources/crypto-shasum/main.swift
|
||||
Tests/CryptoTests/ASN1/ASN1Tests.swift
|
||||
Tests/CryptoTests/ASN1/GeneralizedTimeTests.swift
|
||||
Tests/CryptoTests/Authenticated Encryption/AES-GCM-Runner.swift
|
||||
Tests/CryptoTests/Authenticated Encryption/ChaChaPoly-Runner.swift
|
||||
Tests/CryptoTests/Digests/DigestsTests.swift
|
||||
Tests/CryptoTests/ECDH/X25519-Runner.swift
|
||||
Tests/CryptoTests/ECDH/secpECDH_Runner.swift
|
||||
Tests/CryptoTests/Encodings/DERTests.swift
|
||||
Tests/CryptoTests/Encodings/ECKeyEncodingsTests.swift
|
||||
Tests/CryptoTests/HPKE/HPKETests-TestVectors.swift
|
||||
Tests/CryptoTests/HPKE/HPKETests.swift
|
||||
Tests/CryptoTests/KEM/MLKEMKeyGenTests.swift
|
||||
Tests/CryptoTests/KEM/MLKEMTests.swift
|
||||
Tests/CryptoTests/KEM/XWingTests.swift
|
||||
Tests/CryptoTests/Key Derivation/ECprivateKeysFromSeeds.swift
|
||||
Tests/CryptoTests/Key Derivation/HKDFTests.swift
|
||||
Tests/CryptoTests/Key Derivation/SharedSecretTests.swift
|
||||
Tests/CryptoTests/Key Derivation/X963KDFTests.swift
|
||||
Tests/CryptoTests/Key Wrapping/KeyWrapping.swift
|
||||
Tests/CryptoTests/MAC/HMACTests.swift
|
||||
Tests/CryptoTests/SecureBytes/SecureBytesTests.swift
|
||||
Tests/CryptoTests/Signatures/ECDSA/ECDSASignatureTests.swift
|
||||
Tests/CryptoTests/Signatures/ECDSA/RawECDSASignaturesTests.swift
|
||||
Tests/CryptoTests/Signatures/EdDSA/Ed25519-Runner.swift
|
||||
Tests/CryptoTests/Signatures/MLDSA/MLDSAKeyGenTests.swift
|
||||
Tests/CryptoTests/Signatures/MLDSA/MLDSATests.swift
|
||||
Tests/CryptoTests/SymmetricKeyTests/SymmetricKeyTests.swift
|
||||
Tests/CryptoTests/Utils/PrettyBytes.swift
|
||||
Tests/CryptoTests/Utils/RFCVector.swift
|
||||
Tests/CryptoTests/Utils/SplitData.swift
|
||||
Tests/CryptoTests/Utils/Wycheproof.swift
|
||||
Tests/CryptoTests/Utils/XCTestUtils.swift
|
||||
Tests/CryptoExtrasTests/AES Block Function Tests.swift
|
||||
Tests/CryptoExtrasTests/AES-GCM-SIV-Runner.swift
|
||||
Tests/CryptoExtrasTests/AES_CBCTests.swift
|
||||
Tests/CryptoExtrasTests/AES_CFBTests.swift
|
||||
Tests/CryptoExtrasTests/AES_CTRTests.swift
|
||||
Tests/CryptoExtrasTests/ARC/ARCAPITests.swift
|
||||
Tests/CryptoExtrasTests/ARC/ARCEncodingTests.swift
|
||||
Tests/CryptoExtrasTests/ARC/ARCPublicAPITests.swift
|
||||
Tests/CryptoExtrasTests/ARC/ARCTestVectors.swift
|
||||
Tests/CryptoExtrasTests/ARC/ARCTests.swift
|
||||
Tests/CryptoExtrasTests/ChaCha20CTRTests.swift
|
||||
Tests/CryptoExtrasTests/ECToolbox/HashToCurveTests.swift
|
||||
Tests/CryptoExtrasTests/OPRFs/ECVOPRFTests.swift
|
||||
Tests/CryptoExtrasTests/OPRFs/VOPRFAPITests.swift
|
||||
Tests/CryptoExtrasTests/OPRFs/VOPRFPublicAPITests.swift
|
||||
Tests/CryptoExtrasTests/PBKDF2Tests.swift
|
||||
Tests/CryptoExtrasTests/ScryptTests.swift
|
||||
Tests/CryptoExtrasTests/TestRSABlindSigning.swift
|
||||
Tests/CryptoExtrasTests/TestRSABlindSigningAPI.swift
|
||||
Tests/CryptoExtrasTests/TestRSAEncryption.swift
|
||||
Tests/CryptoExtrasTests/TestRSASigning.swift
|
||||
Tests/CryptoExtrasTests/Util/IntegerEncodingTests.swift
|
||||
Tests/CryptoExtrasTests/Utils/BytesUtil.swift
|
||||
Tests/CryptoExtrasTests/Utils/RFCVector.swift
|
||||
Tests/CryptoExtrasTests/Utils/SplitData.swift
|
||||
Tests/CryptoExtrasTests/Utils/Wycheproof.swift
|
||||
Tests/CryptoExtrasTests/Utils/XCTestUtils.swift
|
||||
Tests/CryptoExtrasTests/ZKPs/ZKPToolbox.swift
|
||||
@@ -0,0 +1,2 @@
|
||||
Sources/CCryptoBoringSSL/*
|
||||
Sources/CXKCP/*
|
||||
@@ -1,5 +0,0 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
|
||||
<plist version="1.0">
|
||||
<array/>
|
||||
</plist>
|
||||
@@ -0,0 +1,211 @@
|
||||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// 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 CryptoExtras
|
||||
|
||||
#if canImport(FoundationEssentials)
|
||||
import FoundationEssentials
|
||||
#else
|
||||
import Foundation
|
||||
#endif
|
||||
|
||||
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:6.2
|
||||
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")
|
||||
]
|
||||
)
|
||||
]
|
||||
)
|
||||
+33
-2
@@ -6,7 +6,7 @@
|
||||
## Licensed under Apache License v2.0
|
||||
##
|
||||
## See LICENSE.txt for license information
|
||||
## See CONTRIBUTORS.md for the list of SwiftCrypto project authors
|
||||
## See CONTRIBUTORS.txt for the list of SwiftCrypto project authors
|
||||
##
|
||||
## SPDX-License-Identifier: Apache-2.0
|
||||
##
|
||||
@@ -14,8 +14,12 @@
|
||||
|
||||
cmake_minimum_required(VERSION 3.15.1)
|
||||
|
||||
if(POLICY CMP0157)
|
||||
cmake_policy(SET CMP0157 NEW)
|
||||
endif()
|
||||
|
||||
project(SwiftCrypto
|
||||
LANGUAGES ASM C Swift)
|
||||
LANGUAGES ASM C CXX Swift)
|
||||
|
||||
list(APPEND CMAKE_MODULE_PATH ${CMAKE_CURRENT_SOURCE_DIR}/cmake/modules)
|
||||
|
||||
@@ -31,6 +35,11 @@ endif()
|
||||
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin)
|
||||
set(CMAKE_Swift_MODULE_DIRECTORY ${CMAKE_BINARY_DIR}/swift)
|
||||
|
||||
set(SWIFT_CRYPTO_COMPILE_OPTIONS
|
||||
-package-name com.apple.swift-crypto
|
||||
-enable-experimental-feature Lifetimes
|
||||
)
|
||||
|
||||
option(BUILD_SHARED_LIBS "Build shared libraries by default" YES)
|
||||
|
||||
if(BUILD_SHARED_LIBS)
|
||||
@@ -43,10 +52,32 @@ 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)
|
||||
endif()
|
||||
|
||||
include(FetchContent)
|
||||
find_package(SwiftASN1 CONFIG)
|
||||
if(NOT SwiftASN1_FOUND)
|
||||
message("-- Vending swift-asn1")
|
||||
FetchContent_Declare(ASN1
|
||||
GIT_REPOSITORY https://github.com/apple/swift-asn1
|
||||
GIT_TAG 1.3.1)
|
||||
FetchContent_MakeAvailable(ASN1)
|
||||
endif()
|
||||
|
||||
add_subdirectory(Sources)
|
||||
add_subdirectory(cmake/modules)
|
||||
@@ -1,3 +0,0 @@
|
||||
# Code of Conduct
|
||||
|
||||
The code of conduct for this project can be found at https://swift.org/code-of-conduct.
|
||||
+42
-8
@@ -5,6 +5,18 @@ your contribution to Apple and the community, and agree by submitting the patch
|
||||
that your contributions are licensed under the Apache 2.0 license (see
|
||||
`LICENSE.txt`).
|
||||
|
||||
## AI tools
|
||||
|
||||
Human discourse is an essential part of open source development. To encourage
|
||||
productive collaboration between contributors and maintainers, please refrain
|
||||
from using AI tools for the following:
|
||||
|
||||
- Issues: titles, bodies, and comments.
|
||||
- Pull requests: titles, descriptions, and comments.
|
||||
|
||||
Contributors who feel more comfortable writing in another language may use
|
||||
automated translation tools, but must include their original content in their
|
||||
preferred language.
|
||||
|
||||
## How to submit a bug report
|
||||
|
||||
@@ -44,19 +56,41 @@ $ uname -a
|
||||
Linux beefy.machine 4.4.0-101-generic #124-Ubuntu SMP Fri Nov 10 18:29:59 UTC 2017 x86_64 x86_64 x86_64 GNU/Linux
|
||||
```
|
||||
|
||||
## Writing a Patch
|
||||
## Contributing a pull request
|
||||
|
||||
A good swift-crypto patch is:
|
||||
> [!IMPORTANT]
|
||||
> To ensure productive use of contributor and maintainer time and resources,
|
||||
> contributors must first agree their proposed change with a maintainer in an
|
||||
> issue. Pull requests opened without prior discussion may be closed without
|
||||
> review.
|
||||
|
||||
1. Concise, and contains as few changes as needed to achieve the end result.
|
||||
2. Tested, ensuring that any tests provided failed before the patch and pass after it.
|
||||
3. Documented, adding API documentation as needed to cover new functions and properties.
|
||||
4. Accompanied by a great commit message, using our commit message template.
|
||||
If there is no issue already tracking the problem or feature request, please
|
||||
file a new one using your own voice (see "AI tools" usage above).
|
||||
|
||||
Once an issue is assigned to you, follow these steps:
|
||||
|
||||
## How to contribute your work
|
||||
- Prepare your change, keeping in mind that a good patch is:
|
||||
- Concise, and contains as few changes as needed to achieve the end result.
|
||||
- Tested, ensuring that any tests provided failed before the patch and pass
|
||||
after it.
|
||||
- Documented, adding API documentation as needed to cover new functions and
|
||||
properties.
|
||||
- Accompanied by a great commit message.
|
||||
- Open a pull request and wait for code review by the maintainers.
|
||||
|
||||
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":"CryptoBoringWrapper","type":"source","exceptions":[]},{"name":"Crypto","type":"source","exceptions":[]},{"name":"CryptoExtras","type":"source","exceptions":[]},{"name":"CCryptoBoringSSL","type":"assembly","exceptions":["*/AES/*.swift"]}]}' bash
|
||||
```
|
||||
|
||||
## API Evolution
|
||||
|
||||
|
||||
File renamed without changes.
+2
-2
@@ -28,13 +28,13 @@ components that this product depends on.
|
||||
This product contains test vectors from Google's wycheproof project.
|
||||
|
||||
* LICENSE (Apache License 2.0):
|
||||
* https://github.com/google/wycheproof/blob/master/LICENSE
|
||||
* https://github.com/C2SP/wycheproof/blob/31387e2cd596587c859c611027b6a44d2e2b65ff/LICENSE
|
||||
* HOMEPAGE:
|
||||
* https://github.com/google/wycheproof
|
||||
|
||||
---
|
||||
|
||||
This product contains a derivation of various scripts from SwiftNIO.
|
||||
This product contains a derivation of various files from SwiftNIO.
|
||||
|
||||
* LICENSE (Apache License 2.0):
|
||||
* https://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
+151
-80
@@ -1,4 +1,4 @@
|
||||
// swift-tools-version:5.8
|
||||
// swift-tools-version:6.2
|
||||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// This source file is part of the SwiftCrypto open source project
|
||||
@@ -7,7 +7,7 @@
|
||||
// Licensed under Apache License v2.0
|
||||
//
|
||||
// See LICENSE.txt for license information
|
||||
// See CONTRIBUTORS.md for the list of SwiftCrypto project authors
|
||||
// See CONTRIBUTORS.txt for the list of SwiftCrypto project authors
|
||||
//
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
//
|
||||
@@ -20,77 +20,76 @@
|
||||
// Sources/CCryptoBoringSSL directory. The source repository is at
|
||||
// https://boringssl.googlesource.com/boringssl.
|
||||
//
|
||||
// BoringSSL Commit: dbad745811195c00b729efd0ee0a09b7d9fce1d2
|
||||
// BoringSSL Commit: 0226f30467f540a3f62ef48d453f93927da199b6
|
||||
|
||||
import PackageDescription
|
||||
|
||||
// To develop this on Apple platforms, set this to true
|
||||
let development = false
|
||||
import class Foundation.ProcessInfo
|
||||
|
||||
let swiftSettings: [SwiftSetting]
|
||||
let dependencies: [Target.Dependency]
|
||||
if development {
|
||||
swiftSettings = [
|
||||
.define("CRYPTO_IN_SWIFTPM"),
|
||||
.define("CRYPTO_IN_SWIFTPM_FORCE_BUILD_API"),
|
||||
]
|
||||
dependencies = [
|
||||
"CCryptoBoringSSL",
|
||||
"CCryptoBoringSSLShims",
|
||||
"CryptoBoringWrapper"
|
||||
]
|
||||
} else {
|
||||
let platforms: [Platform] = [
|
||||
Platform.linux,
|
||||
Platform.android,
|
||||
Platform.windows,
|
||||
Platform.wasi,
|
||||
]
|
||||
swiftSettings = [
|
||||
.define("CRYPTO_IN_SWIFTPM"),
|
||||
.define("CRYPTO_IN_SWIFTPM_FORCE_BUILD_API", .when(platforms: platforms)),
|
||||
]
|
||||
dependencies = [
|
||||
.target(name: "CCryptoBoringSSL", condition: .when(platforms: platforms)),
|
||||
.target(name: "CCryptoBoringSSLShims", condition: .when(platforms: platforms)),
|
||||
.target(name: "CryptoBoringWrapper", condition: .when(platforms: platforms))
|
||||
]
|
||||
}
|
||||
// NOTE: To develop the the non-Darwin Crypto target on macOS, use a Dev Container.
|
||||
let nonDarwinPlatforms: [Platform] = [
|
||||
.linux,
|
||||
.android,
|
||||
.windows,
|
||||
.wasi,
|
||||
.openbsd,
|
||||
// The SwiftPM Platform symbol is not yet public but the underlying platform name is set.
|
||||
// -- https://github.com/swiftlang/swift-package-manager/blob/swift-6.2.3-RELEASE/Sources/PackageDescription/SupportedPlatforms.swift#L75
|
||||
.custom("freebsd"),
|
||||
]
|
||||
|
||||
var swiftSettings: [SwiftSetting] = [
|
||||
.define("CRYPTO_IN_SWIFTPM"),
|
||||
.enableExperimentalFeature("Lifetimes"),
|
||||
.enableExperimentalFeature("SourceWarningControl"),
|
||||
]
|
||||
|
||||
// Only enable CheckImplementationOnly on 6.4 -- 6.3 has the feature, but produces many false positives.
|
||||
#if compiler(>=6.4)
|
||||
swiftSettings.append(.enableExperimentalFeature("CheckImplementationOnly"))
|
||||
#endif
|
||||
|
||||
// This doesn't work when cross-compiling: the privacy manifest will be included in the Bundle and
|
||||
// Foundation will be linked. This is, however, strictly better than unconditionally adding the
|
||||
// resource.
|
||||
#if canImport(Darwin)
|
||||
let privacyManifestExclude: [String] = []
|
||||
let privacyManifestResource: [PackageDescription.Resource] = [.copy("PrivacyInfo.xcprivacy")]
|
||||
#else
|
||||
// Exclude on other platforms to avoid build warnings.
|
||||
let privacyManifestExclude: [String] = ["PrivacyInfo.xcprivacy"]
|
||||
let privacyManifestResource: [PackageDescription.Resource] = []
|
||||
#endif
|
||||
|
||||
let package = Package(
|
||||
name: "swift-crypto",
|
||||
platforms: [
|
||||
.macOS(.v10_15),
|
||||
.iOS(.v13),
|
||||
.watchOS(.v6),
|
||||
.tvOS(.v13),
|
||||
],
|
||||
products: [
|
||||
.library(name: "Crypto", targets: ["Crypto"]),
|
||||
// Kept for backward compatibility
|
||||
.library(name: "_CryptoExtras", targets: ["_CryptoExtras"]),
|
||||
.library(name: "CryptoExtras", targets: ["CryptoExtras"]),
|
||||
/* This target is used only for symbol mangling. It's added and removed automatically because it emits build warnings. MANGLE_START
|
||||
.library(name: "CCryptoBoringSSL", type: .static, targets: ["CCryptoBoringSSL"]),
|
||||
MANGLE_END */
|
||||
],
|
||||
dependencies: [],
|
||||
dependencies: [
|
||||
// Dependencies are added below so that they can be switched between local and absolute URLs
|
||||
],
|
||||
targets: [
|
||||
.target(
|
||||
name: "CCryptoBoringSSL",
|
||||
exclude: [
|
||||
exclude: privacyManifestExclude + [
|
||||
"hash.txt",
|
||||
"include/boringssl_prefix_symbols_nasm.inc",
|
||||
"CMakeLists.txt",
|
||||
/*
|
||||
* These files are excluded to support WASI libc which doesn't provide <netdb.h>.
|
||||
* This is safe for all platforms as we do not rely on networking features.
|
||||
*/
|
||||
"crypto/bio/connect.c",
|
||||
"crypto/bio/socket_helper.c",
|
||||
"crypto/bio/socket.c"
|
||||
],
|
||||
resources: [
|
||||
.copy("PrivacyInfo.xcprivacy"),
|
||||
"crypto/bio/connect.cc",
|
||||
"crypto/bio/socket_helper.cc",
|
||||
"crypto/bio/socket.cc",
|
||||
],
|
||||
resources: privacyManifestResource,
|
||||
cSettings: [
|
||||
// These defines come from BoringSSL's build system
|
||||
.define("_HAS_EXCEPTIONS", to: "0", .when(platforms: [Platform.windows])),
|
||||
@@ -100,48 +99,76 @@ let package = Package(
|
||||
/*
|
||||
* These defines are required on Wasm/WASI, to disable use of pthread.
|
||||
*/
|
||||
.define("OPENSSL_NO_THREADS_CORRUPT_MEMORY_AND_LEAK_SECRETS_IF_THREADED", .when(platforms: [Platform.wasi])),
|
||||
.define(
|
||||
"OPENSSL_NO_THREADS_CORRUPT_MEMORY_AND_LEAK_SECRETS_IF_THREADED",
|
||||
.when(platforms: [Platform.wasi])
|
||||
),
|
||||
.define("OPENSSL_NO_ASM", .when(platforms: [Platform.wasi])),
|
||||
// BoringSSL is vendored verbatim; we don't fix its warnings. Xcode enables
|
||||
// -Wshorten-64-to-32 by default (SwiftPM does not), which produces dozens
|
||||
// of warnings. Silence that group here.
|
||||
.disableWarning("shorten-64-to-32"),
|
||||
]
|
||||
),
|
||||
.target(
|
||||
name: "CCryptoBoringSSLShims",
|
||||
dependencies: ["CCryptoBoringSSL"],
|
||||
name: "CXKCP",
|
||||
exclude: [
|
||||
"CMakeLists.txt"
|
||||
],
|
||||
resources: [
|
||||
.copy("PrivacyInfo.xcprivacy"),
|
||||
cSettings: [
|
||||
.define("XKCP_has_KeccakP1600"),
|
||||
.headerSearchPath("include"),
|
||||
.headerSearchPath("high"),
|
||||
.headerSearchPath("low"),
|
||||
.headerSearchPath("low/KeccakP-1600"),
|
||||
.headerSearchPath("low/common"),
|
||||
.headerSearchPath("common"),
|
||||
.disableWarning("macro-redefined"),
|
||||
]
|
||||
),
|
||||
.target(
|
||||
name: "CXKCPShims",
|
||||
dependencies: ["CXKCP"],
|
||||
exclude: privacyManifestExclude + [
|
||||
"CMakeLists.txt"
|
||||
],
|
||||
resources: privacyManifestResource
|
||||
),
|
||||
.target(
|
||||
name: "Crypto",
|
||||
dependencies: dependencies,
|
||||
exclude: [
|
||||
dependencies: [
|
||||
.target(name: "CCryptoBoringSSL", condition: .when(platforms: nonDarwinPlatforms)),
|
||||
.target(name: "CryptoBoringWrapper", condition: .when(platforms: nonDarwinPlatforms)),
|
||||
.target(name: "CXKCP", condition: .when(platforms: nonDarwinPlatforms)),
|
||||
.target(name: "CXKCPShims", condition: .when(platforms: nonDarwinPlatforms)),
|
||||
],
|
||||
exclude: privacyManifestExclude + [
|
||||
"vendored-sources.txt",
|
||||
"CMakeLists.txt",
|
||||
"AEADs/Nonces.swift.gyb",
|
||||
"Digests/Digests.swift.gyb",
|
||||
"Key Agreement/ECDH.swift.gyb",
|
||||
"Signatures/ECDSA.swift.gyb",
|
||||
"Signatures/BoringSSL/MLDSA_boring.swift.gyb",
|
||||
"KEM/BoringSSL/MLKEM_boring.swift.gyb",
|
||||
],
|
||||
resources: [
|
||||
.copy("PrivacyInfo.xcprivacy"),
|
||||
resources: privacyManifestResource,
|
||||
swiftSettings: swiftSettings
|
||||
),
|
||||
.target(
|
||||
name: "CryptoExtras",
|
||||
dependencies: [
|
||||
"CCryptoBoringSSL",
|
||||
"CryptoBoringWrapper",
|
||||
"Crypto",
|
||||
.product(name: "SwiftASN1", package: "swift-asn1"),
|
||||
],
|
||||
exclude: privacyManifestExclude + [
|
||||
"CMakeLists.txt"
|
||||
],
|
||||
resources: privacyManifestResource,
|
||||
swiftSettings: swiftSettings
|
||||
),
|
||||
.target(
|
||||
name: "_CryptoExtras",
|
||||
dependencies: [
|
||||
"CCryptoBoringSSL",
|
||||
"CCryptoBoringSSLShims",
|
||||
"CryptoBoringWrapper",
|
||||
"Crypto"
|
||||
],
|
||||
exclude: [
|
||||
"CMakeLists.txt",
|
||||
],
|
||||
resources: [
|
||||
.copy("PrivacyInfo.xcprivacy"),
|
||||
"CryptoExtras",
|
||||
],
|
||||
swiftSettings: swiftSettings
|
||||
),
|
||||
@@ -149,14 +176,12 @@ let package = Package(
|
||||
name: "CryptoBoringWrapper",
|
||||
dependencies: [
|
||||
"CCryptoBoringSSL",
|
||||
"CCryptoBoringSSLShims"
|
||||
],
|
||||
exclude: [
|
||||
"CMakeLists.txt",
|
||||
exclude: privacyManifestExclude + [
|
||||
"CMakeLists.txt"
|
||||
],
|
||||
resources: [
|
||||
.copy("PrivacyInfo.xcprivacy"),
|
||||
]
|
||||
resources: privacyManifestResource,
|
||||
swiftSettings: swiftSettings
|
||||
),
|
||||
.executableTarget(name: "crypto-shasum", dependencies: ["Crypto"]),
|
||||
.testTarget(
|
||||
@@ -164,11 +189,57 @@ let package = Package(
|
||||
dependencies: ["Crypto"],
|
||||
resources: [
|
||||
.copy("HPKE/hpke-test-vectors.json"),
|
||||
.copy("KEM/MLKEM768_BSSLKAT.json"),
|
||||
.copy("KEM/MLKEM768KAT.json"),
|
||||
.copy("KEM/MLKEM1024_BSSLKAT.json"),
|
||||
.copy("KEM/MLKEM1024KAT.json"),
|
||||
.copy("KEM/test-vectors.json"),
|
||||
.copy("Signatures/MLDSA/MLDSA65_KeyGen_KAT.json"),
|
||||
.copy("Signatures/MLDSA/MLDSA87_KeyGen_KAT.json"),
|
||||
],
|
||||
swiftSettings: swiftSettings
|
||||
),
|
||||
.testTarget(
|
||||
name: "CryptoExtrasTests",
|
||||
dependencies: ["CryptoExtras"],
|
||||
resources: [
|
||||
.copy("ECToolbox/H2CVectors/P256_XMD-SHA-256_SSWU_RO_.json"),
|
||||
.copy("ECToolbox/H2CVectors/P384_XMD-SHA-384_SSWU_RO_.json"),
|
||||
.copy("OPRFs/OPRFVectors/OPRFVectors-VOPRFDraft8.json"),
|
||||
.copy("OPRFs/OPRFVectors/OPRFVectors-VOPRFDraft19.json"),
|
||||
.copy("OPRFs/OPRFVectors/OPRFVectors-edgecases.json"),
|
||||
],
|
||||
swiftSettings: swiftSettings
|
||||
),
|
||||
.testTarget(name: "_CryptoExtrasTests", dependencies: ["_CryptoExtras"]),
|
||||
.testTarget(name: "CryptoBoringWrapperTests", dependencies: ["CryptoBoringWrapper"]),
|
||||
.testTarget(name: "CXKCPTests", dependencies: ["CXKCP"]),
|
||||
],
|
||||
cxxLanguageStandard: .cxx11
|
||||
cxxLanguageStandard: .cxx17
|
||||
)
|
||||
|
||||
// Switch between local and remote dependencies depending on an environment variable
|
||||
if ProcessInfo.processInfo.environment["SWIFTCI_USE_LOCAL_DEPS"] == nil {
|
||||
package.dependencies += [
|
||||
.package(url: "https://github.com/apple/swift-asn1.git", from: "1.2.0")
|
||||
]
|
||||
} else {
|
||||
package.dependencies += [
|
||||
.package(path: "../swift-asn1")
|
||||
]
|
||||
}
|
||||
|
||||
// --- STANDARD CROSS-REPO SETTINGS DO NOT EDIT --- //
|
||||
for target in package.targets {
|
||||
switch target.type {
|
||||
case .regular, .test, .executable:
|
||||
var settings = target.swiftSettings ?? []
|
||||
// https://github.com/swiftlang/swift-evolution/blob/main/proposals/0444-member-import-visibility.md
|
||||
settings.append(.enableUpcomingFeature("MemberImportVisibility"))
|
||||
target.swiftSettings = settings
|
||||
case .macro, .plugin, .system, .binary:
|
||||
() // not applicable
|
||||
@unknown default:
|
||||
() // we don't know what to do here, do nothing
|
||||
}
|
||||
}
|
||||
// --- END: STANDARD CROSS-REPO SETTINGS DO NOT EDIT --- //
|
||||
@@ -1,15 +1,15 @@
|
||||
# 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
|
||||
|
||||
Swift Crypto is available as a Swift Package Manager package. To use it, add the following dependency in your `Package.swift`:
|
||||
|
||||
```swift
|
||||
// swift-crypto 1.x, 2.x and 3.x are almost API compatible, so most clients
|
||||
// swift-crypto 1.x, 2.x, 3.x, 4.x, and 5.x are almost API compatible, so most clients
|
||||
// should allow any of them
|
||||
.package(url: "https://github.com/apple/swift-crypto.git", "1.0.0" ..< "4.0.0"),
|
||||
.package(url: "https://github.com/apple/swift-crypto.git", "1.0.0" ..< "6.0.0"),
|
||||
```
|
||||
|
||||
and to your target, add `Crypto` to your dependencies. You can then `import Crypto` to get access to Swift Crypto's functionality.
|
||||
@@ -28,13 +28,14 @@ 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 other platforms, 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.
|
||||
3. The backing implementation of this common API, which calls into BoringSSL.
|
||||
2. A vendored copy of XKCP's libXKCP.
|
||||
3. The common API of Swift Crypto and CryptoKit.
|
||||
4. The backing implementation of this common API, which calls into BoringSSL or XKCP.
|
||||
|
||||
The API code, and some cryptographic primitives which are directly implemented in Swift, are exactly the same for both Apple CryptoKit and Swift Crypto. The backing BoringSSL-based implementation is unique to Swift Crypto.
|
||||
The API code, and some cryptographic primitives which are directly implemented in Swift, are exactly the same for both Apple CryptoKit and Swift Crypto. The BoringSSL/XKCP backing implementation is unique to Swift Crypto. In addition, there is another product, `CryptoExtras`, which provides additional functionality that is not offered in CryptoKit, which contains cryptographic APIs predominantly useful in the server ecosystem. **Note**: if you depend on CryptoExtras you'll bundle the BoringSSL/XKCP implementation of the library in your application, no matter the platform.
|
||||
|
||||
## Evolution
|
||||
|
||||
@@ -48,11 +49,11 @@ Note that Swift Crypto does not intend to support all possible cryptographic pri
|
||||
|
||||
### Code Organisation
|
||||
|
||||
Files in this repository are divided into two groups, based on whether they have a name that ends in `_boring` or are in a `BoringSSL` directory, or if they are not.
|
||||
Files in this repository are divided into two groups, based on whether they have a name that ends in `_boring`/`_xkcp` or are in a `BoringSSL`/`XKCP` directory, or if they are not.
|
||||
|
||||
Files that meet the above criteria are specific to the Swift Crypto implementation. Changes to these files can be made fairly easily, so long as they meet the criteria below. If your file needs to `import CCryptoBoringSSL` or access a BoringSSL API, it needs to be marked this way.
|
||||
Files that meet the above criteria are specific to the Swift Crypto implementation. Changes to these files can be made fairly easily, so long as they meet the criteria below. If your file needs to `import CCryptoBoringSSL` or `import CXKCP` or access a BoringSSL or XKCP API, it needs to be marked this way.
|
||||
|
||||
Files that do not have the `_boring` suffix are part of the public API of CryptoKit. Changing these requires passing a higher bar, as any change in these files must be accompanied by a change in CryptoKit itself.
|
||||
Files that do not have the `_boring` or `_xkcp` suffix are part of the public API of CryptoKit. Changing these requires passing a higher bar, as any change in these files must be accompanied by a change in CryptoKit itself.
|
||||
|
||||
## Contributing
|
||||
|
||||
@@ -108,16 +109,21 @@ If you believe you have identified a vulnerability in Swift Crypto, please [repo
|
||||
|
||||
### Swift versions
|
||||
|
||||
The most recent versions of Swift Crypto support Swift 5.7 and newer. The minimum Swift version supported by Swift Crypto releases are detailed below:
|
||||
The most recent versions of Swift Crypto support Swift 6.2 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 ...` | 5.8
|
||||
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 ..< 4.0.0` | 5.10
|
||||
`4.0.0 ..< 4.4.0` | 6.0
|
||||
`4.4.0 ..< 5.0.0` | 6.1
|
||||
`5.0.0 ...` | 6.2
|
||||
|
||||
### Compatibility
|
||||
|
||||
@@ -127,15 +133,25 @@ 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.
|
||||
|
||||
Swift Crypto 3.0.0 was released in September 2023. Again the only breaking change was the addition of new cases in the `CryptoError` enumeration, so most users can safely depend on the 1.0.0, 2.0.0, or 3.0.0 series of releases.
|
||||
|
||||
Swift Crypto 4.0.0 was released in September 2025. Again the only breaking change was the addition of new cases in the `CryptoError` enumeration, so most users can safely depend on the 1.0.0, 2.0.0, 3.0.0, or 4.0.0 series of releases. Note that in this release `_CryptoExtras` was renamed to `CryptoExtras`. The old products and targets have been kept around for compatibility reasons, but users depending only on new code should use `CryptoExtras` not `_CryptoExtras`.
|
||||
|
||||
Swift Crypto 5.0.0 was released in September 2026. Because this version is only supported on Swift versions that support extensible enums, this release has mechanically marked all non-frozen public enums in CryptoKit as `@nonexhaustive`, which should mitigate the need for any future major releases of Swift Crypto. Most users will be able to depend on the 1.0.0, 2.0.0, 3.0.0, 4.0.0 or 5.0.0 series of releases.
|
||||
|
||||
To do so, please use the following dependency in your `Package.swift`:
|
||||
|
||||
```swift
|
||||
.package(url: "https://github.com/apple/swift-crypto.git", "1.0.0" ..< "3.0.0"),
|
||||
.package(url: "https://github.com/apple/swift-crypto.git", "1.0.0" ..< "6.0.0"),
|
||||
```
|
||||
|
||||
### Developing Swift Crypto on macOS
|
||||
|
||||
Swift Crypto normally defers to the OS implementation of CryptoKit on macOS. Naturally, this makes developing Swift Crypto on macOS tricky. To get Swift Crypto to build the open source implementation on macOS, in `Package.swift`, change `let development = false` to `let development = true`, as this will force Swift Crypto to build its public API.
|
||||
Swift Crypto normally defers to the OS implementation of CryptoKit on macOS. Naturally, this makes developing Swift Crypto on macOS tricky. To get Swift Crypto to build the open source implementation on macOS, in `Package.swift`, use a Linux container. A Dev Container config is provided in the repo to make this easier.
|
||||
|
||||
|
||||
## Acknowledgements
|
||||
|
||||
This project contains source code from the BoringSSL and XKCP projects.
|
||||
+347
-374
@@ -6,393 +6,362 @@
|
||||
## Licensed under Apache License v2.0
|
||||
##
|
||||
## See LICENSE.txt for license information
|
||||
## See CONTRIBUTORS.md for the list of SwiftCrypto project authors
|
||||
## See CONTRIBUTORS.txt for the list of SwiftCrypto project authors
|
||||
##
|
||||
## SPDX-License-Identifier: Apache-2.0
|
||||
##
|
||||
##===----------------------------------------------------------------------===##
|
||||
|
||||
add_library(CCryptoBoringSSL STATIC
|
||||
"crypto/asn1/a_bitstr.c"
|
||||
"crypto/asn1/a_bool.c"
|
||||
"crypto/asn1/a_d2i_fp.c"
|
||||
"crypto/asn1/a_dup.c"
|
||||
"crypto/asn1/a_gentm.c"
|
||||
"crypto/asn1/a_i2d_fp.c"
|
||||
"crypto/asn1/a_int.c"
|
||||
"crypto/asn1/a_mbstr.c"
|
||||
"crypto/asn1/a_object.c"
|
||||
"crypto/asn1/a_octet.c"
|
||||
"crypto/asn1/a_strex.c"
|
||||
"crypto/asn1/a_strnid.c"
|
||||
"crypto/asn1/a_time.c"
|
||||
"crypto/asn1/a_type.c"
|
||||
"crypto/asn1/a_utctm.c"
|
||||
"crypto/asn1/asn1_lib.c"
|
||||
"crypto/asn1/asn1_par.c"
|
||||
"crypto/asn1/asn_pack.c"
|
||||
"crypto/asn1/f_int.c"
|
||||
"crypto/asn1/f_string.c"
|
||||
"crypto/asn1/posix_time.c"
|
||||
"crypto/asn1/tasn_dec.c"
|
||||
"crypto/asn1/tasn_enc.c"
|
||||
"crypto/asn1/tasn_fre.c"
|
||||
"crypto/asn1/tasn_new.c"
|
||||
"crypto/asn1/tasn_typ.c"
|
||||
"crypto/asn1/tasn_utl.c"
|
||||
"crypto/base64/base64.c"
|
||||
"crypto/bio/bio.c"
|
||||
"crypto/bio/bio_mem.c"
|
||||
"crypto/bio/connect.c"
|
||||
"crypto/bio/errno.c"
|
||||
"crypto/bio/fd.c"
|
||||
"crypto/bio/file.c"
|
||||
"crypto/bio/hexdump.c"
|
||||
"crypto/bio/pair.c"
|
||||
"crypto/bio/printf.c"
|
||||
"crypto/bio/socket.c"
|
||||
"crypto/bio/socket_helper.c"
|
||||
"crypto/blake2/blake2.c"
|
||||
"crypto/bn_extra/bn_asn1.c"
|
||||
"crypto/bn_extra/convert.c"
|
||||
"crypto/buf/buf.c"
|
||||
"crypto/bytestring/asn1_compat.c"
|
||||
"crypto/bytestring/ber.c"
|
||||
"crypto/bytestring/cbb.c"
|
||||
"crypto/bytestring/cbs.c"
|
||||
"crypto/bytestring/unicode.c"
|
||||
"crypto/chacha/chacha.c"
|
||||
"crypto/cipher_extra/cipher_extra.c"
|
||||
"crypto/cipher_extra/derive_key.c"
|
||||
"crypto/cipher_extra/e_aesctrhmac.c"
|
||||
"crypto/cipher_extra/e_aesgcmsiv.c"
|
||||
"crypto/cipher_extra/e_chacha20poly1305.c"
|
||||
"crypto/cipher_extra/e_des.c"
|
||||
"crypto/cipher_extra/e_null.c"
|
||||
"crypto/cipher_extra/e_rc2.c"
|
||||
"crypto/cipher_extra/e_rc4.c"
|
||||
"crypto/cipher_extra/e_tls.c"
|
||||
"crypto/cipher_extra/tls_cbc.c"
|
||||
"crypto/conf/conf.c"
|
||||
"crypto/cpu_aarch64_apple.c"
|
||||
"crypto/cpu_aarch64_fuchsia.c"
|
||||
"crypto/cpu_aarch64_linux.c"
|
||||
"crypto/cpu_aarch64_openbsd.c"
|
||||
"crypto/cpu_aarch64_sysreg.c"
|
||||
"crypto/cpu_aarch64_win.c"
|
||||
"crypto/cpu_arm_freebsd.c"
|
||||
"crypto/cpu_arm_linux.c"
|
||||
"crypto/cpu_intel.c"
|
||||
"crypto/crypto.c"
|
||||
"crypto/curve25519/curve25519.c"
|
||||
"crypto/curve25519/curve25519_64_adx.c"
|
||||
"crypto/curve25519/spake25519.c"
|
||||
"crypto/des/des.c"
|
||||
"crypto/dh_extra/dh_asn1.c"
|
||||
"crypto/dh_extra/params.c"
|
||||
"crypto/digest_extra/digest_extra.c"
|
||||
"crypto/dsa/dsa.c"
|
||||
"crypto/dsa/dsa_asn1.c"
|
||||
"crypto/ec_extra/ec_asn1.c"
|
||||
"crypto/ec_extra/ec_derive.c"
|
||||
"crypto/ec_extra/hash_to_curve.c"
|
||||
"crypto/ecdh_extra/ecdh_extra.c"
|
||||
"crypto/ecdsa_extra/ecdsa_asn1.c"
|
||||
"crypto/engine/engine.c"
|
||||
"crypto/err/err.c"
|
||||
"crypto/err/err_data.c"
|
||||
"crypto/evp/evp.c"
|
||||
"crypto/evp/evp_asn1.c"
|
||||
"crypto/evp/evp_ctx.c"
|
||||
"crypto/evp/p_dsa_asn1.c"
|
||||
"crypto/evp/p_ec.c"
|
||||
"crypto/evp/p_ec_asn1.c"
|
||||
"crypto/evp/p_ed25519.c"
|
||||
"crypto/evp/p_ed25519_asn1.c"
|
||||
"crypto/evp/p_hkdf.c"
|
||||
"crypto/evp/p_rsa.c"
|
||||
"crypto/evp/p_rsa_asn1.c"
|
||||
"crypto/evp/p_x25519.c"
|
||||
"crypto/evp/p_x25519_asn1.c"
|
||||
"crypto/evp/pbkdf.c"
|
||||
"crypto/evp/print.c"
|
||||
"crypto/evp/scrypt.c"
|
||||
"crypto/evp/sign.c"
|
||||
"crypto/ex_data.c"
|
||||
"crypto/fipsmodule/aes/aes.c"
|
||||
"crypto/fipsmodule/aes/aes_nohw.c"
|
||||
"crypto/fipsmodule/aes/key_wrap.c"
|
||||
"crypto/fipsmodule/aes/mode_wrappers.c"
|
||||
"crypto/fipsmodule/bn/add.c"
|
||||
"crypto/fipsmodule/bn/asm/x86_64-gcc.c"
|
||||
"crypto/fipsmodule/bn/bn.c"
|
||||
"crypto/fipsmodule/bn/bytes.c"
|
||||
"crypto/fipsmodule/bn/cmp.c"
|
||||
"crypto/fipsmodule/bn/ctx.c"
|
||||
"crypto/fipsmodule/bn/div.c"
|
||||
"crypto/fipsmodule/bn/div_extra.c"
|
||||
"crypto/fipsmodule/bn/exponentiation.c"
|
||||
"crypto/fipsmodule/bn/gcd.c"
|
||||
"crypto/fipsmodule/bn/gcd_extra.c"
|
||||
"crypto/fipsmodule/bn/generic.c"
|
||||
"crypto/fipsmodule/bn/jacobi.c"
|
||||
"crypto/fipsmodule/bn/montgomery.c"
|
||||
"crypto/fipsmodule/bn/montgomery_inv.c"
|
||||
"crypto/fipsmodule/bn/mul.c"
|
||||
"crypto/fipsmodule/bn/prime.c"
|
||||
"crypto/fipsmodule/bn/random.c"
|
||||
"crypto/fipsmodule/bn/rsaz_exp.c"
|
||||
"crypto/fipsmodule/bn/shift.c"
|
||||
"crypto/fipsmodule/bn/sqrt.c"
|
||||
"crypto/fipsmodule/cipher/aead.c"
|
||||
"crypto/fipsmodule/cipher/cipher.c"
|
||||
"crypto/fipsmodule/cipher/e_aes.c"
|
||||
"crypto/fipsmodule/cipher/e_aesccm.c"
|
||||
"crypto/fipsmodule/cmac/cmac.c"
|
||||
"crypto/fipsmodule/dh/check.c"
|
||||
"crypto/fipsmodule/dh/dh.c"
|
||||
"crypto/fipsmodule/digest/digest.c"
|
||||
"crypto/fipsmodule/digest/digests.c"
|
||||
"crypto/fipsmodule/digestsign/digestsign.c"
|
||||
"crypto/fipsmodule/ec/ec.c"
|
||||
"crypto/fipsmodule/ec/ec_key.c"
|
||||
"crypto/fipsmodule/ec/ec_montgomery.c"
|
||||
"crypto/fipsmodule/ec/felem.c"
|
||||
"crypto/fipsmodule/ec/oct.c"
|
||||
"crypto/fipsmodule/ec/p224-64.c"
|
||||
"crypto/fipsmodule/ec/p256-nistz.c"
|
||||
"crypto/fipsmodule/ec/p256.c"
|
||||
"crypto/fipsmodule/ec/scalar.c"
|
||||
"crypto/fipsmodule/ec/simple.c"
|
||||
"crypto/fipsmodule/ec/simple_mul.c"
|
||||
"crypto/fipsmodule/ec/util.c"
|
||||
"crypto/fipsmodule/ec/wnaf.c"
|
||||
"crypto/fipsmodule/ecdh/ecdh.c"
|
||||
"crypto/fipsmodule/ecdsa/ecdsa.c"
|
||||
"crypto/fipsmodule/fips_shared_support.c"
|
||||
"crypto/fipsmodule/hkdf/hkdf.c"
|
||||
"crypto/fipsmodule/hmac/hmac.c"
|
||||
"crypto/fipsmodule/md4/md4.c"
|
||||
"crypto/fipsmodule/md5/md5.c"
|
||||
"crypto/fipsmodule/modes/cbc.c"
|
||||
"crypto/fipsmodule/modes/cfb.c"
|
||||
"crypto/fipsmodule/modes/ctr.c"
|
||||
"crypto/fipsmodule/modes/gcm.c"
|
||||
"crypto/fipsmodule/modes/gcm_nohw.c"
|
||||
"crypto/fipsmodule/modes/ofb.c"
|
||||
"crypto/fipsmodule/modes/polyval.c"
|
||||
"crypto/fipsmodule/rand/ctrdrbg.c"
|
||||
"crypto/fipsmodule/rand/fork_detect.c"
|
||||
"crypto/fipsmodule/rand/rand.c"
|
||||
"crypto/fipsmodule/rand/urandom.c"
|
||||
"crypto/fipsmodule/rsa/blinding.c"
|
||||
"crypto/fipsmodule/rsa/padding.c"
|
||||
"crypto/fipsmodule/rsa/rsa.c"
|
||||
"crypto/fipsmodule/rsa/rsa_impl.c"
|
||||
"crypto/fipsmodule/self_check/fips.c"
|
||||
"crypto/fipsmodule/self_check/self_check.c"
|
||||
"crypto/fipsmodule/service_indicator/service_indicator.c"
|
||||
"crypto/fipsmodule/sha/sha1.c"
|
||||
"crypto/fipsmodule/sha/sha256.c"
|
||||
"crypto/fipsmodule/sha/sha512.c"
|
||||
"crypto/fipsmodule/tls/kdf.c"
|
||||
"crypto/hpke/hpke.c"
|
||||
"crypto/hrss/hrss.c"
|
||||
"crypto/keccak/keccak.c"
|
||||
"crypto/kyber/kyber.c"
|
||||
"crypto/lhash/lhash.c"
|
||||
"crypto/mem.c"
|
||||
"crypto/obj/obj.c"
|
||||
"crypto/obj/obj_xref.c"
|
||||
"crypto/pem/pem_all.c"
|
||||
"crypto/pem/pem_info.c"
|
||||
"crypto/pem/pem_lib.c"
|
||||
"crypto/pem/pem_oth.c"
|
||||
"crypto/pem/pem_pk8.c"
|
||||
"crypto/pem/pem_pkey.c"
|
||||
"crypto/pem/pem_x509.c"
|
||||
"crypto/pem/pem_xaux.c"
|
||||
"crypto/pkcs7/pkcs7.c"
|
||||
"crypto/pkcs7/pkcs7_x509.c"
|
||||
"crypto/pkcs8/p5_pbev2.c"
|
||||
"crypto/pkcs8/pkcs8.c"
|
||||
"crypto/pkcs8/pkcs8_x509.c"
|
||||
"crypto/poly1305/poly1305.c"
|
||||
"crypto/poly1305/poly1305_arm.c"
|
||||
"crypto/poly1305/poly1305_vec.c"
|
||||
"crypto/pool/pool.c"
|
||||
"crypto/rand_extra/deterministic.c"
|
||||
"crypto/rand_extra/forkunsafe.c"
|
||||
"crypto/rand_extra/getentropy.c"
|
||||
"crypto/rand_extra/ios.c"
|
||||
"crypto/rand_extra/passive.c"
|
||||
"crypto/rand_extra/rand_extra.c"
|
||||
"crypto/rand_extra/trusty.c"
|
||||
"crypto/rand_extra/windows.c"
|
||||
"crypto/rc4/rc4.c"
|
||||
"crypto/refcount.c"
|
||||
"crypto/rsa_extra/rsa_asn1.c"
|
||||
"crypto/rsa_extra/rsa_crypt.c"
|
||||
"crypto/rsa_extra/rsa_print.c"
|
||||
"crypto/siphash/siphash.c"
|
||||
"crypto/spx/address.c"
|
||||
"crypto/spx/fors.c"
|
||||
"crypto/spx/merkle.c"
|
||||
"crypto/spx/spx.c"
|
||||
"crypto/spx/spx_util.c"
|
||||
"crypto/spx/thash.c"
|
||||
"crypto/spx/wots.c"
|
||||
"crypto/stack/stack.c"
|
||||
"crypto/thread.c"
|
||||
"crypto/thread_none.c"
|
||||
"crypto/thread_pthread.c"
|
||||
"crypto/thread_win.c"
|
||||
"crypto/trust_token/pmbtoken.c"
|
||||
"crypto/trust_token/trust_token.c"
|
||||
"crypto/trust_token/voprf.c"
|
||||
"crypto/x509/a_digest.c"
|
||||
"crypto/x509/a_sign.c"
|
||||
"crypto/x509/a_verify.c"
|
||||
"crypto/x509/algorithm.c"
|
||||
"crypto/x509/asn1_gen.c"
|
||||
"crypto/x509/by_dir.c"
|
||||
"crypto/x509/by_file.c"
|
||||
"crypto/x509/i2d_pr.c"
|
||||
"crypto/x509/name_print.c"
|
||||
"crypto/x509/policy.c"
|
||||
"crypto/x509/rsa_pss.c"
|
||||
"crypto/x509/t_crl.c"
|
||||
"crypto/x509/t_req.c"
|
||||
"crypto/x509/t_x509.c"
|
||||
"crypto/x509/t_x509a.c"
|
||||
"crypto/x509/v3_akey.c"
|
||||
"crypto/x509/v3_akeya.c"
|
||||
"crypto/x509/v3_alt.c"
|
||||
"crypto/x509/v3_bcons.c"
|
||||
"crypto/x509/v3_bitst.c"
|
||||
"crypto/x509/v3_conf.c"
|
||||
"crypto/x509/v3_cpols.c"
|
||||
"crypto/x509/v3_crld.c"
|
||||
"crypto/x509/v3_enum.c"
|
||||
"crypto/x509/v3_extku.c"
|
||||
"crypto/x509/v3_genn.c"
|
||||
"crypto/x509/v3_ia5.c"
|
||||
"crypto/x509/v3_info.c"
|
||||
"crypto/x509/v3_int.c"
|
||||
"crypto/x509/v3_lib.c"
|
||||
"crypto/x509/v3_ncons.c"
|
||||
"crypto/x509/v3_ocsp.c"
|
||||
"crypto/x509/v3_pcons.c"
|
||||
"crypto/x509/v3_pmaps.c"
|
||||
"crypto/x509/v3_prn.c"
|
||||
"crypto/x509/v3_purp.c"
|
||||
"crypto/x509/v3_skey.c"
|
||||
"crypto/x509/v3_utl.c"
|
||||
"crypto/x509/x509.c"
|
||||
"crypto/x509/x509_att.c"
|
||||
"crypto/x509/x509_cmp.c"
|
||||
"crypto/x509/x509_d2.c"
|
||||
"crypto/x509/x509_def.c"
|
||||
"crypto/x509/x509_ext.c"
|
||||
"crypto/x509/x509_lu.c"
|
||||
"crypto/x509/x509_obj.c"
|
||||
"crypto/x509/x509_req.c"
|
||||
"crypto/x509/x509_set.c"
|
||||
"crypto/x509/x509_trs.c"
|
||||
"crypto/x509/x509_txt.c"
|
||||
"crypto/x509/x509_v3.c"
|
||||
"crypto/x509/x509_vfy.c"
|
||||
"crypto/x509/x509_vpm.c"
|
||||
"crypto/x509/x509cset.c"
|
||||
"crypto/x509/x509name.c"
|
||||
"crypto/x509/x509rset.c"
|
||||
"crypto/x509/x509spki.c"
|
||||
"crypto/x509/x_algor.c"
|
||||
"crypto/x509/x_all.c"
|
||||
"crypto/x509/x_attrib.c"
|
||||
"crypto/x509/x_crl.c"
|
||||
"crypto/x509/x_exten.c"
|
||||
"crypto/x509/x_name.c"
|
||||
"crypto/x509/x_pubkey.c"
|
||||
"crypto/x509/x_req.c"
|
||||
"crypto/x509/x_sig.c"
|
||||
"crypto/x509/x_spki.c"
|
||||
"crypto/x509/x_val.c"
|
||||
"crypto/x509/x_x509.c"
|
||||
"crypto/x509/x_x509a.c")
|
||||
"crypto/aes/aes.cc"
|
||||
"crypto/asn1/a_bitstr.cc"
|
||||
"crypto/asn1/a_bool.cc"
|
||||
"crypto/asn1/a_d2i_fp.cc"
|
||||
"crypto/asn1/a_dup.cc"
|
||||
"crypto/asn1/a_gentm.cc"
|
||||
"crypto/asn1/a_i2d_fp.cc"
|
||||
"crypto/asn1/a_int.cc"
|
||||
"crypto/asn1/a_mbstr.cc"
|
||||
"crypto/asn1/a_object.cc"
|
||||
"crypto/asn1/a_octet.cc"
|
||||
"crypto/asn1/a_strex.cc"
|
||||
"crypto/asn1/a_strnid.cc"
|
||||
"crypto/asn1/a_time.cc"
|
||||
"crypto/asn1/a_type.cc"
|
||||
"crypto/asn1/a_utctm.cc"
|
||||
"crypto/asn1/asn1_lib.cc"
|
||||
"crypto/asn1/asn1_par.cc"
|
||||
"crypto/asn1/asn_pack.cc"
|
||||
"crypto/asn1/f_int.cc"
|
||||
"crypto/asn1/f_string.cc"
|
||||
"crypto/asn1/posix_time.cc"
|
||||
"crypto/asn1/tasn_dec.cc"
|
||||
"crypto/asn1/tasn_enc.cc"
|
||||
"crypto/asn1/tasn_fre.cc"
|
||||
"crypto/asn1/tasn_new.cc"
|
||||
"crypto/asn1/tasn_typ.cc"
|
||||
"crypto/asn1/tasn_utl.cc"
|
||||
"crypto/base64/base64.cc"
|
||||
"crypto/bio/bio.cc"
|
||||
"crypto/bio/bio_mem.cc"
|
||||
"crypto/bio/connect.cc"
|
||||
"crypto/bio/errno.cc"
|
||||
"crypto/bio/fd.cc"
|
||||
"crypto/bio/file.cc"
|
||||
"crypto/bio/hexdump.cc"
|
||||
"crypto/bio/pair.cc"
|
||||
"crypto/bio/printf.cc"
|
||||
"crypto/bio/socket.cc"
|
||||
"crypto/bio/socket_helper.cc"
|
||||
"crypto/blake2/blake2.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"
|
||||
"crypto/bytestring/cbb.cc"
|
||||
"crypto/bytestring/cbs.cc"
|
||||
"crypto/bytestring/unicode.cc"
|
||||
"crypto/chacha/chacha.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"
|
||||
"crypto/cpu_aarch64_linux.cc"
|
||||
"crypto/cpu_aarch64_openbsd.cc"
|
||||
"crypto/cpu_aarch64_sysreg.cc"
|
||||
"crypto/cpu_aarch64_win.cc"
|
||||
"crypto/cpu_arm_freebsd.cc"
|
||||
"crypto/cpu_arm_linux.cc"
|
||||
"crypto/cpu_intel.cc"
|
||||
"crypto/crypto.cc"
|
||||
"crypto/curve25519/curve25519.cc"
|
||||
"crypto/curve25519/curve25519_64_adx.cc"
|
||||
"crypto/curve25519/spake25519.cc"
|
||||
"crypto/des/des.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/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"
|
||||
"crypto/evp/evp_asn1.cc"
|
||||
"crypto/evp/evp_ctx.cc"
|
||||
"crypto/evp/p_dh.cc"
|
||||
"crypto/evp/p_dh_asn1.cc"
|
||||
"crypto/evp/p_dsa_asn1.cc"
|
||||
"crypto/evp/p_ec.cc"
|
||||
"crypto/evp/p_ec_asn1.cc"
|
||||
"crypto/evp/p_ed25519.cc"
|
||||
"crypto/evp/p_ed25519_asn1.cc"
|
||||
"crypto/evp/p_hkdf.cc"
|
||||
"crypto/evp/p_rsa.cc"
|
||||
"crypto/evp/p_rsa_asn1.cc"
|
||||
"crypto/evp/p_x25519.cc"
|
||||
"crypto/evp/p_x25519_asn1.cc"
|
||||
"crypto/evp/pbkdf.cc"
|
||||
"crypto/evp/print.cc"
|
||||
"crypto/evp/scrypt.cc"
|
||||
"crypto/evp/sign.cc"
|
||||
"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"
|
||||
"crypto/lhash/lhash.cc"
|
||||
"crypto/md4/md4.cc"
|
||||
"crypto/md5/md5.cc"
|
||||
"crypto/mem.cc"
|
||||
"crypto/mldsa/mldsa.cc"
|
||||
"crypto/mlkem/mlkem.cc"
|
||||
"crypto/obj/obj.cc"
|
||||
"crypto/obj/obj_xref.cc"
|
||||
"crypto/pem/pem_all.cc"
|
||||
"crypto/pem/pem_info.cc"
|
||||
"crypto/pem/pem_lib.cc"
|
||||
"crypto/pem/pem_oth.cc"
|
||||
"crypto/pem/pem_pk8.cc"
|
||||
"crypto/pem/pem_pkey.cc"
|
||||
"crypto/pem/pem_x509.cc"
|
||||
"crypto/pem/pem_xaux.cc"
|
||||
"crypto/pkcs7/pkcs7.cc"
|
||||
"crypto/pkcs7/pkcs7_x509.cc"
|
||||
"crypto/pkcs8/p5_pbev2.cc"
|
||||
"crypto/pkcs8/pkcs8.cc"
|
||||
"crypto/pkcs8/pkcs8_x509.cc"
|
||||
"crypto/poly1305/poly1305.cc"
|
||||
"crypto/poly1305/poly1305_arm.cc"
|
||||
"crypto/poly1305/poly1305_vec.cc"
|
||||
"crypto/pool/pool.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/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/slhdsa.cc"
|
||||
"crypto/spake2plus/spake2plus.cc"
|
||||
"crypto/stack/stack.cc"
|
||||
"crypto/thread.cc"
|
||||
"crypto/thread_none.cc"
|
||||
"crypto/thread_pthread.cc"
|
||||
"crypto/thread_win.cc"
|
||||
"crypto/trust_token/pmbtoken.cc"
|
||||
"crypto/trust_token/trust_token.cc"
|
||||
"crypto/trust_token/voprf.cc"
|
||||
"crypto/x509/a_digest.cc"
|
||||
"crypto/x509/a_sign.cc"
|
||||
"crypto/x509/a_verify.cc"
|
||||
"crypto/x509/algorithm.cc"
|
||||
"crypto/x509/asn1_gen.cc"
|
||||
"crypto/x509/by_dir.cc"
|
||||
"crypto/x509/by_file.cc"
|
||||
"crypto/x509/i2d_pr.cc"
|
||||
"crypto/x509/name_print.cc"
|
||||
"crypto/x509/policy.cc"
|
||||
"crypto/x509/rsa_pss.cc"
|
||||
"crypto/x509/t_crl.cc"
|
||||
"crypto/x509/t_req.cc"
|
||||
"crypto/x509/t_x509.cc"
|
||||
"crypto/x509/t_x509a.cc"
|
||||
"crypto/x509/v3_akey.cc"
|
||||
"crypto/x509/v3_akeya.cc"
|
||||
"crypto/x509/v3_alt.cc"
|
||||
"crypto/x509/v3_bcons.cc"
|
||||
"crypto/x509/v3_bitst.cc"
|
||||
"crypto/x509/v3_conf.cc"
|
||||
"crypto/x509/v3_cpols.cc"
|
||||
"crypto/x509/v3_crld.cc"
|
||||
"crypto/x509/v3_enum.cc"
|
||||
"crypto/x509/v3_extku.cc"
|
||||
"crypto/x509/v3_genn.cc"
|
||||
"crypto/x509/v3_ia5.cc"
|
||||
"crypto/x509/v3_info.cc"
|
||||
"crypto/x509/v3_int.cc"
|
||||
"crypto/x509/v3_lib.cc"
|
||||
"crypto/x509/v3_ncons.cc"
|
||||
"crypto/x509/v3_ocsp.cc"
|
||||
"crypto/x509/v3_pcons.cc"
|
||||
"crypto/x509/v3_pmaps.cc"
|
||||
"crypto/x509/v3_prn.cc"
|
||||
"crypto/x509/v3_purp.cc"
|
||||
"crypto/x509/v3_skey.cc"
|
||||
"crypto/x509/v3_utl.cc"
|
||||
"crypto/x509/x509.cc"
|
||||
"crypto/x509/x509_att.cc"
|
||||
"crypto/x509/x509_cmp.cc"
|
||||
"crypto/x509/x509_d2.cc"
|
||||
"crypto/x509/x509_def.cc"
|
||||
"crypto/x509/x509_ext.cc"
|
||||
"crypto/x509/x509_lu.cc"
|
||||
"crypto/x509/x509_obj.cc"
|
||||
"crypto/x509/x509_req.cc"
|
||||
"crypto/x509/x509_set.cc"
|
||||
"crypto/x509/x509_trs.cc"
|
||||
"crypto/x509/x509_txt.cc"
|
||||
"crypto/x509/x509_v3.cc"
|
||||
"crypto/x509/x509_vfy.cc"
|
||||
"crypto/x509/x509_vpm.cc"
|
||||
"crypto/x509/x509cset.cc"
|
||||
"crypto/x509/x509name.cc"
|
||||
"crypto/x509/x509rset.cc"
|
||||
"crypto/x509/x509spki.cc"
|
||||
"crypto/x509/x_algor.cc"
|
||||
"crypto/x509/x_all.cc"
|
||||
"crypto/x509/x_attrib.cc"
|
||||
"crypto/x509/x_crl.cc"
|
||||
"crypto/x509/x_exten.cc"
|
||||
"crypto/x509/x_name.cc"
|
||||
"crypto/x509/x_pubkey.cc"
|
||||
"crypto/x509/x_req.cc"
|
||||
"crypto/x509/x_sig.cc"
|
||||
"crypto/x509/x_spki.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>"
|
||||
"$<$<NOT:$<PLATFORM_ID:Windows>>:third_party/fiat/asm/fiat_curve25519_adx_square.S>"
|
||||
"$<$<NOT:$<PLATFORM_ID:Windows>>:third_party/fiat/asm/fiat_p256_adx_mul.S>"
|
||||
"$<$<NOT:$<PLATFORM_ID:Windows>>:third_party/fiat/asm/fiat_p256_adx_sqr.S>")
|
||||
|
||||
if(CMAKE_SYSTEM_NAME STREQUAL Darwin AND CMAKE_SYSTEM_PROCESSOR MATCHES "amd64|x86_64")
|
||||
target_sources(CCryptoBoringSSL PRIVATE
|
||||
crypto/chacha/chacha-x86_64-mac.mac.x86_64.S
|
||||
crypto/cipher_extra/aes128gcmsiv-x86_64-mac.mac.x86_64.S
|
||||
crypto/cipher_extra/chacha20_poly1305_x86_64-mac.mac.x86_64.S
|
||||
crypto/fipsmodule/aesni-gcm-x86_64-mac.mac.x86_64.S
|
||||
crypto/fipsmodule/aesni-x86_64-mac.mac.x86_64.S
|
||||
crypto/fipsmodule/ghash-ssse3-x86_64-mac.mac.x86_64.S
|
||||
crypto/fipsmodule/ghash-x86_64-mac.mac.x86_64.S
|
||||
crypto/fipsmodule/md5-x86_64-mac.mac.x86_64.S
|
||||
crypto/fipsmodule/p256-x86_64-asm-mac.mac.x86_64.S
|
||||
crypto/fipsmodule/p256_beeu-x86_64-asm-mac.mac.x86_64.S
|
||||
crypto/fipsmodule/rdrand-x86_64-mac.mac.x86_64.S
|
||||
crypto/fipsmodule/rsaz-avx2-mac.mac.x86_64.S
|
||||
crypto/fipsmodule/sha1-x86_64-mac.mac.x86_64.S
|
||||
crypto/fipsmodule/sha256-x86_64-mac.mac.x86_64.S
|
||||
crypto/fipsmodule/sha512-x86_64-mac.mac.x86_64.S
|
||||
crypto/fipsmodule/vpaes-x86_64-mac.mac.x86_64.S
|
||||
crypto/fipsmodule/x86_64-mont-mac.mac.x86_64.S
|
||||
crypto/fipsmodule/x86_64-mont5-mac.mac.x86_64.S)
|
||||
elseif(CMAKE_SYSTEM_NAME MATCHES "Linux|Android" AND CMAKE_SYSTEM_PROCESSOR MATCHES "amd64|x86_64")
|
||||
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
|
||||
gen/bcm/ghash-x86_64-apple.S
|
||||
gen/bcm/p256-x86_64-asm-apple.S
|
||||
gen/bcm/p256_beeu-x86_64-asm-apple.S
|
||||
gen/bcm/rdrand-x86_64-apple.S
|
||||
gen/bcm/rsaz-avx2-apple.S
|
||||
gen/bcm/sha1-x86_64-apple.S
|
||||
gen/bcm/sha256-x86_64-apple.S
|
||||
gen/bcm/sha512-x86_64-apple.S
|
||||
gen/bcm/vpaes-x86_64-apple.S
|
||||
gen/bcm/x86_64-mont-apple.S
|
||||
gen/bcm/x86_64-mont5-apple.S
|
||||
gen/crypto/aes128gcmsiv-x86_64-apple.S
|
||||
gen/crypto/chacha-x86_64-apple.S
|
||||
gen/crypto/chacha20_poly1305_x86_64-apple.S
|
||||
gen/crypto/md5-x86_64-apple.S)
|
||||
elseif(CMAKE_SYSTEM_NAME MATCHES "Linux|Android|FreeBSD|OpenBSD" AND CMAKE_SYSTEM_PROCESSOR MATCHES "amd64|x86_64")
|
||||
target_sources(CCryptoBoringSSL PRIVATE
|
||||
crypto/chacha/chacha-x86_64-linux.linux.x86_64.S
|
||||
crypto/cipher_extra/aes128gcmsiv-x86_64-linux.linux.x86_64.S
|
||||
crypto/cipher_extra/chacha20_poly1305_x86_64-linux.linux.x86_64.S
|
||||
crypto/fipsmodule/aesni-gcm-x86_64-linux.linux.x86_64.S
|
||||
crypto/fipsmodule/aesni-x86_64-linux.linux.x86_64.S
|
||||
crypto/fipsmodule/ghash-ssse3-x86_64-linux.linux.x86_64.S
|
||||
crypto/fipsmodule/ghash-x86_64-linux.linux.x86_64.S
|
||||
crypto/fipsmodule/md5-x86_64-linux.linux.x86_64.S
|
||||
crypto/fipsmodule/p256-x86_64-asm-linux.linux.x86_64.S
|
||||
crypto/fipsmodule/p256_beeu-x86_64-asm-linux.linux.x86_64.S
|
||||
crypto/fipsmodule/rdrand-x86_64-linux.linux.x86_64.S
|
||||
crypto/fipsmodule/rsaz-avx2-linux.linux.x86_64.S
|
||||
crypto/fipsmodule/sha1-x86_64-linux.linux.x86_64.S
|
||||
crypto/fipsmodule/sha256-x86_64-linux.linux.x86_64.S
|
||||
crypto/fipsmodule/sha512-x86_64-linux.linux.x86_64.S
|
||||
crypto/fipsmodule/vpaes-x86_64-linux.linux.x86_64.S
|
||||
crypto/fipsmodule/x86_64-mont-linux.linux.x86_64.S
|
||||
crypto/fipsmodule/x86_64-mont5-linux.linux.x86_64.S)
|
||||
gen/bcm/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
|
||||
gen/bcm/ghash-x86_64-linux.S
|
||||
gen/bcm/p256-x86_64-asm-linux.S
|
||||
gen/bcm/p256_beeu-x86_64-asm-linux.S
|
||||
gen/bcm/rdrand-x86_64-linux.S
|
||||
gen/bcm/rsaz-avx2-linux.S
|
||||
gen/bcm/sha1-x86_64-linux.S
|
||||
gen/bcm/sha256-x86_64-linux.S
|
||||
gen/bcm/sha512-x86_64-linux.S
|
||||
gen/bcm/vpaes-x86_64-linux.S
|
||||
gen/bcm/x86_64-mont-linux.S
|
||||
gen/bcm/x86_64-mont5-linux.S
|
||||
gen/crypto/aes128gcmsiv-x86_64-linux.S
|
||||
gen/crypto/chacha-x86_64-linux.S
|
||||
gen/crypto/chacha20_poly1305_x86_64-linux.S
|
||||
gen/crypto/md5-x86_64-linux.S)
|
||||
elseif(CMAKE_SYSTEM_NAME STREQUAL Darwin AND CMAKE_SYSTEM_PROCESSOR MATCHES "arm64|aarch64")
|
||||
target_sources(CCryptoBoringSSL PRIVATE
|
||||
crypto/chacha/chacha-armv8-ios.ios.aarch64.S
|
||||
crypto/cipher_extra/chacha20_poly1305_armv8-ios.ios.aarch64.S
|
||||
crypto/fipsmodule/aesv8-armv8-ios.ios.aarch64.S
|
||||
crypto/fipsmodule/aesv8-gcm-armv8-ios.ios.aarch64.S
|
||||
crypto/fipsmodule/armv8-mont-ios.ios.aarch64.S
|
||||
crypto/fipsmodule/bn-armv8-ios.ios.aarch64.S
|
||||
crypto/fipsmodule/ghash-neon-armv8-ios.ios.aarch64.S
|
||||
crypto/fipsmodule/ghashv8-armv8-ios.ios.aarch64.S
|
||||
crypto/fipsmodule/p256-armv8-asm-ios.ios.aarch64.S
|
||||
crypto/fipsmodule/p256_beeu-armv8-asm-ios.ios.aarch64.S
|
||||
crypto/fipsmodule/sha1-armv8-ios.ios.aarch64.S
|
||||
crypto/fipsmodule/sha256-armv8-ios.ios.aarch64.S
|
||||
crypto/fipsmodule/sha512-armv8-ios.ios.aarch64.S
|
||||
crypto/fipsmodule/vpaes-armv8-ios.ios.aarch64.S)
|
||||
elseif(CMAKE_SYSTEM_NAME MATCHES "Linux|Android" AND CMAKE_SYSTEM_PROCESSOR MATCHES "arm64|aarch64")
|
||||
gen/bcm/aesv8-armv8-apple.S
|
||||
gen/bcm/aesv8-gcm-armv8-apple.S
|
||||
gen/bcm/armv8-mont-apple.S
|
||||
gen/bcm/bn-armv8-apple.S
|
||||
gen/bcm/ghash-neon-armv8-apple.S
|
||||
gen/bcm/ghashv8-armv8-apple.S
|
||||
gen/bcm/p256-armv8-asm-apple.S
|
||||
gen/bcm/p256_beeu-armv8-asm-apple.S
|
||||
gen/bcm/sha1-armv8-apple.S
|
||||
gen/bcm/sha256-armv8-apple.S
|
||||
gen/bcm/sha512-armv8-apple.S
|
||||
gen/bcm/vpaes-armv8-apple.S
|
||||
gen/crypto/chacha-armv8-apple.S
|
||||
gen/crypto/chacha20_poly1305_armv8-apple.S)
|
||||
elseif(CMAKE_SYSTEM_NAME MATCHES "Linux|Android|FreeBSD|OpenBSD" AND CMAKE_SYSTEM_PROCESSOR MATCHES "arm64|aarch64")
|
||||
target_sources(CCryptoBoringSSL PRIVATE
|
||||
crypto/chacha/chacha-armv8-linux.linux.aarch64.S
|
||||
crypto/cipher_extra/chacha20_poly1305_armv8-linux.linux.aarch64.S
|
||||
crypto/fipsmodule/aesv8-armv8-linux.linux.aarch64.S
|
||||
crypto/fipsmodule/aesv8-gcm-armv8-linux.linux.aarch64.S
|
||||
crypto/fipsmodule/armv8-mont-linux.linux.aarch64.S
|
||||
crypto/fipsmodule/bn-armv8-linux.linux.aarch64.S
|
||||
crypto/fipsmodule/ghash-neon-armv8-linux.linux.aarch64.S
|
||||
crypto/fipsmodule/ghashv8-armv8-linux.linux.aarch64.S
|
||||
crypto/fipsmodule/p256-armv8-asm-linux.linux.aarch64.S
|
||||
crypto/fipsmodule/p256_beeu-armv8-asm-linux.linux.aarch64.S
|
||||
crypto/fipsmodule/sha1-armv8-linux.linux.aarch64.S
|
||||
crypto/fipsmodule/sha256-armv8-linux.linux.aarch64.S
|
||||
crypto/fipsmodule/sha512-armv8-linux.linux.aarch64.S
|
||||
crypto/fipsmodule/vpaes-armv8-linux.linux.aarch64.S)
|
||||
gen/bcm/aesv8-armv8-linux.S
|
||||
gen/bcm/aesv8-gcm-armv8-linux.S
|
||||
gen/bcm/armv8-mont-linux.S
|
||||
gen/bcm/bn-armv8-linux.S
|
||||
gen/bcm/ghash-neon-armv8-linux.S
|
||||
gen/bcm/ghashv8-armv8-linux.S
|
||||
gen/bcm/p256-armv8-asm-linux.S
|
||||
gen/bcm/p256_beeu-armv8-asm-linux.S
|
||||
gen/bcm/sha1-armv8-linux.S
|
||||
gen/bcm/sha256-armv8-linux.S
|
||||
gen/bcm/sha512-armv8-linux.S
|
||||
gen/bcm/vpaes-armv8-linux.S
|
||||
gen/crypto/chacha-armv8-linux.S
|
||||
gen/crypto/chacha20_poly1305_armv8-linux.S)
|
||||
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
|
||||
@@ -400,6 +369,10 @@ target_include_directories(CCryptoBoringSSL PUBLIC
|
||||
|
||||
target_compile_definitions(CCryptoBoringSSL PRIVATE
|
||||
$<$<PLATFORM_ID:Windows>:WIN32_LEAN_AND_MEAN>)
|
||||
target_link_libraries(CCryptoBoringSSL PUBLIC
|
||||
$<$<NOT:$<PLATFORM_ID:Darwin>>:dispatch>
|
||||
$<$<NOT:$<PLATFORM_ID:Darwin>>:Foundation>
|
||||
SwiftASN1)
|
||||
set_target_properties(CCryptoBoringSSL PROPERTIES
|
||||
INTERFACE_INCLUDE_DIRECTORIES "${CMAKE_CURRENT_SOURCE_DIR}/include;${CMAKE_Swift_MODULE_DIRECTORY}")
|
||||
|
||||
|
||||
@@ -1 +0,0 @@
|
||||
../../.PrivacyInfo.xcprivacy
|
||||
+15
@@ -0,0 +1,15 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
|
||||
<plist version="1.0">
|
||||
<dict>
|
||||
<key>NSPrivacyTracking</key>
|
||||
<false/>
|
||||
<key>NSPrivacyAccessedAPITypes</key>
|
||||
<array/>
|
||||
<key>NSPrivacyCollectedDataTypes</key>
|
||||
<array/>
|
||||
<key>NSPrivacyTrackingDomains</key>
|
||||
<array/>
|
||||
</dict>
|
||||
</plist>
|
||||
|
||||
@@ -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,284 +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_asn1.h>
|
||||
|
||||
#include <limits.h>
|
||||
#include <string.h>
|
||||
|
||||
#include <CCryptoBoringSSL_err.h>
|
||||
#include <CCryptoBoringSSL_mem.h>
|
||||
|
||||
#include "../internal.h"
|
||||
#include "internal.h"
|
||||
|
||||
|
||||
int ASN1_BIT_STRING_set(ASN1_BIT_STRING *x, const unsigned char *d,
|
||||
ossl_ssize_t len) {
|
||||
return ASN1_STRING_set(x, d, len);
|
||||
}
|
||||
|
||||
int asn1_bit_string_length(const ASN1_BIT_STRING *str,
|
||||
uint8_t *out_padding_bits) {
|
||||
int len = str->length;
|
||||
if (str->flags & ASN1_STRING_FLAG_BITS_LEFT) {
|
||||
// If the string is already empty, it cannot have padding bits.
|
||||
*out_padding_bits = len == 0 ? 0 : str->flags & 0x07;
|
||||
return len;
|
||||
}
|
||||
|
||||
// TODO(https://crbug.com/boringssl/447): If we move this logic to
|
||||
// |ASN1_BIT_STRING_set_bit|, can we remove this representation?
|
||||
while (len > 0 && str->data[len - 1] == 0) {
|
||||
len--;
|
||||
}
|
||||
uint8_t padding_bits = 0;
|
||||
if (len > 0) {
|
||||
uint8_t last = str->data[len - 1];
|
||||
assert(last != 0);
|
||||
for (; padding_bits < 7; padding_bits++) {
|
||||
if (last & (1 << padding_bits)) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
*out_padding_bits = padding_bits;
|
||||
return len;
|
||||
}
|
||||
|
||||
int ASN1_BIT_STRING_num_bytes(const ASN1_BIT_STRING *str, size_t *out) {
|
||||
uint8_t padding_bits;
|
||||
int len = asn1_bit_string_length(str, &padding_bits);
|
||||
if (padding_bits != 0) {
|
||||
return 0;
|
||||
}
|
||||
*out = len;
|
||||
return 1;
|
||||
}
|
||||
|
||||
int i2c_ASN1_BIT_STRING(const ASN1_BIT_STRING *a, unsigned char **pp) {
|
||||
if (a == NULL) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
uint8_t bits;
|
||||
int len = asn1_bit_string_length(a, &bits);
|
||||
if (len > INT_MAX - 1) {
|
||||
OPENSSL_PUT_ERROR(ASN1, ERR_R_OVERFLOW);
|
||||
return 0;
|
||||
}
|
||||
int ret = 1 + len;
|
||||
if (pp == NULL) {
|
||||
return ret;
|
||||
}
|
||||
|
||||
uint8_t *p = *pp;
|
||||
*(p++) = bits;
|
||||
OPENSSL_memcpy(p, a->data, len);
|
||||
if (len > 0) {
|
||||
p[len - 1] &= (0xff << bits);
|
||||
}
|
||||
p += len;
|
||||
*pp = p;
|
||||
return ret;
|
||||
}
|
||||
|
||||
ASN1_BIT_STRING *c2i_ASN1_BIT_STRING(ASN1_BIT_STRING **a,
|
||||
const unsigned char **pp, long len) {
|
||||
ASN1_BIT_STRING *ret = NULL;
|
||||
const unsigned char *p;
|
||||
unsigned char *s;
|
||||
int padding;
|
||||
|
||||
if (len < 1) {
|
||||
OPENSSL_PUT_ERROR(ASN1, ASN1_R_STRING_TOO_SHORT);
|
||||
goto err;
|
||||
}
|
||||
|
||||
if (len > INT_MAX) {
|
||||
OPENSSL_PUT_ERROR(ASN1, ASN1_R_STRING_TOO_LONG);
|
||||
goto err;
|
||||
}
|
||||
|
||||
if ((a == NULL) || ((*a) == NULL)) {
|
||||
if ((ret = ASN1_BIT_STRING_new()) == NULL) {
|
||||
return NULL;
|
||||
}
|
||||
} else {
|
||||
ret = (*a);
|
||||
}
|
||||
|
||||
p = *pp;
|
||||
padding = *(p++);
|
||||
len--;
|
||||
if (padding > 7) {
|
||||
OPENSSL_PUT_ERROR(ASN1, ASN1_R_INVALID_BIT_STRING_BITS_LEFT);
|
||||
goto err;
|
||||
}
|
||||
|
||||
// Unused bits in a BIT STRING must be zero.
|
||||
uint8_t padding_mask = (1 << padding) - 1;
|
||||
if (padding != 0 && (len < 1 || (p[len - 1] & padding_mask) != 0)) {
|
||||
OPENSSL_PUT_ERROR(ASN1, ASN1_R_INVALID_BIT_STRING_PADDING);
|
||||
goto err;
|
||||
}
|
||||
|
||||
// We do this to preserve the settings. If we modify the settings, via
|
||||
// the _set_bit function, we will recalculate on output
|
||||
ret->flags &= ~(ASN1_STRING_FLAG_BITS_LEFT | 0x07); // clear
|
||||
ret->flags |= (ASN1_STRING_FLAG_BITS_LEFT | padding); // set
|
||||
|
||||
if (len > 0) {
|
||||
s = OPENSSL_memdup(p, len);
|
||||
if (s == NULL) {
|
||||
goto err;
|
||||
}
|
||||
p += len;
|
||||
} else {
|
||||
s = NULL;
|
||||
}
|
||||
|
||||
ret->length = (int)len;
|
||||
OPENSSL_free(ret->data);
|
||||
ret->data = s;
|
||||
ret->type = V_ASN1_BIT_STRING;
|
||||
if (a != NULL) {
|
||||
(*a) = ret;
|
||||
}
|
||||
*pp = p;
|
||||
return ret;
|
||||
err:
|
||||
if ((ret != NULL) && ((a == NULL) || (*a != ret))) {
|
||||
ASN1_BIT_STRING_free(ret);
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
||||
// These next 2 functions from Goetz Babin-Ebell <babinebell@trustcenter.de>
|
||||
int ASN1_BIT_STRING_set_bit(ASN1_BIT_STRING *a, int n, int value) {
|
||||
int w, v, iv;
|
||||
unsigned char *c;
|
||||
|
||||
w = n / 8;
|
||||
v = 1 << (7 - (n & 0x07));
|
||||
iv = ~v;
|
||||
if (!value) {
|
||||
v = 0;
|
||||
}
|
||||
|
||||
if (a == NULL) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
a->flags &= ~(ASN1_STRING_FLAG_BITS_LEFT | 0x07); // clear, set on write
|
||||
|
||||
if ((a->length < (w + 1)) || (a->data == NULL)) {
|
||||
if (!value) {
|
||||
return 1; // Don't need to set
|
||||
}
|
||||
if (a->data == NULL) {
|
||||
c = (unsigned char *)OPENSSL_malloc(w + 1);
|
||||
} else {
|
||||
c = (unsigned char *)OPENSSL_realloc(a->data, w + 1);
|
||||
}
|
||||
if (c == NULL) {
|
||||
return 0;
|
||||
}
|
||||
if (w + 1 - a->length > 0) {
|
||||
OPENSSL_memset(c + a->length, 0, w + 1 - a->length);
|
||||
}
|
||||
a->data = c;
|
||||
a->length = w + 1;
|
||||
}
|
||||
a->data[w] = ((a->data[w]) & iv) | v;
|
||||
while ((a->length > 0) && (a->data[a->length - 1] == 0)) {
|
||||
a->length--;
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
|
||||
int ASN1_BIT_STRING_get_bit(const ASN1_BIT_STRING *a, int n) {
|
||||
int w, v;
|
||||
|
||||
w = n / 8;
|
||||
v = 1 << (7 - (n & 0x07));
|
||||
if ((a == NULL) || (a->length < (w + 1)) || (a->data == NULL)) {
|
||||
return 0;
|
||||
}
|
||||
return ((a->data[w] & v) != 0);
|
||||
}
|
||||
|
||||
// Checks if the given bit string contains only bits specified by
|
||||
// the flags vector. Returns 0 if there is at least one bit set in 'a'
|
||||
// which is not specified in 'flags', 1 otherwise.
|
||||
// 'len' is the length of 'flags'.
|
||||
int ASN1_BIT_STRING_check(const ASN1_BIT_STRING *a, const unsigned char *flags,
|
||||
int flags_len) {
|
||||
int i, ok;
|
||||
// Check if there is one bit set at all.
|
||||
if (!a || !a->data) {
|
||||
return 1;
|
||||
}
|
||||
|
||||
// Check each byte of the internal representation of the bit string.
|
||||
ok = 1;
|
||||
for (i = 0; i < a->length && ok; ++i) {
|
||||
unsigned char mask = i < flags_len ? ~flags[i] : 0xff;
|
||||
// We are done if there is an unneeded bit set.
|
||||
ok = (a->data[i] & mask) == 0;
|
||||
}
|
||||
return ok;
|
||||
}
|
||||
@@ -0,0 +1,280 @@
|
||||
// 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>
|
||||
#include <CCryptoBoringSSL_span.h>
|
||||
|
||||
#include "../internal.h"
|
||||
#include "internal.h"
|
||||
|
||||
|
||||
int ASN1_BIT_STRING_set(ASN1_BIT_STRING *x, const unsigned char *d,
|
||||
ossl_ssize_t len) {
|
||||
return ASN1_STRING_set(x, d, len);
|
||||
}
|
||||
|
||||
int asn1_bit_string_length(const ASN1_BIT_STRING *str,
|
||||
uint8_t *out_padding_bits) {
|
||||
int len = str->length;
|
||||
if (str->flags & ASN1_STRING_FLAG_BITS_LEFT) {
|
||||
// If the string is already empty, it cannot have padding bits.
|
||||
*out_padding_bits = len == 0 ? 0 : str->flags & 0x07;
|
||||
return len;
|
||||
}
|
||||
|
||||
// TODO(https://crbug.com/boringssl/447): If we move this logic to
|
||||
// |ASN1_BIT_STRING_set_bit|, can we remove this representation?
|
||||
while (len > 0 && str->data[len - 1] == 0) {
|
||||
len--;
|
||||
}
|
||||
uint8_t padding_bits = 0;
|
||||
if (len > 0) {
|
||||
uint8_t last = str->data[len - 1];
|
||||
assert(last != 0);
|
||||
for (; padding_bits < 7; padding_bits++) {
|
||||
if (last & (1 << padding_bits)) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
*out_padding_bits = padding_bits;
|
||||
return len;
|
||||
}
|
||||
|
||||
int ASN1_BIT_STRING_num_bytes(const ASN1_BIT_STRING *str, size_t *out) {
|
||||
uint8_t padding_bits;
|
||||
int len = asn1_bit_string_length(str, &padding_bits);
|
||||
if (padding_bits != 0) {
|
||||
return 0;
|
||||
}
|
||||
*out = len;
|
||||
return 1;
|
||||
}
|
||||
|
||||
int i2c_ASN1_BIT_STRING(const ASN1_BIT_STRING *a, unsigned char **pp) {
|
||||
if (a == NULL) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
uint8_t bits;
|
||||
int len = asn1_bit_string_length(a, &bits);
|
||||
if (len > INT_MAX - 1) {
|
||||
OPENSSL_PUT_ERROR(ASN1, ERR_R_OVERFLOW);
|
||||
return 0;
|
||||
}
|
||||
int ret = 1 + len;
|
||||
if (pp == NULL) {
|
||||
return ret;
|
||||
}
|
||||
|
||||
uint8_t *p = *pp;
|
||||
*(p++) = bits;
|
||||
OPENSSL_memcpy(p, a->data, len);
|
||||
if (len > 0) {
|
||||
p[len - 1] &= (0xff << bits);
|
||||
}
|
||||
p += len;
|
||||
*pp = p;
|
||||
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);
|
||||
}
|
||||
|
||||
static int asn1_parse_bit_string_contents(bssl::Span<const uint8_t> in,
|
||||
ASN1_BIT_STRING *out) {
|
||||
CBS cbs = in;
|
||||
uint8_t padding;
|
||||
if (!CBS_get_u8(&cbs, &padding)) {
|
||||
OPENSSL_PUT_ERROR(ASN1, ASN1_R_STRING_TOO_SHORT);
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (padding > 7) {
|
||||
OPENSSL_PUT_ERROR(ASN1, ASN1_R_INVALID_BIT_STRING_BITS_LEFT);
|
||||
return 0;
|
||||
}
|
||||
|
||||
// Unused bits in a BIT STRING must be zero.
|
||||
uint8_t padding_mask = (1 << padding) - 1;
|
||||
if (padding != 0) {
|
||||
CBS copy = cbs;
|
||||
uint8_t last;
|
||||
if (!CBS_get_last_u8(©, &last) || (last & padding_mask) != 0) {
|
||||
OPENSSL_PUT_ERROR(ASN1, ASN1_R_INVALID_BIT_STRING_PADDING);
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
if (!ASN1_STRING_set(out, CBS_data(&cbs), CBS_len(&cbs))) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
out->type = V_ASN1_BIT_STRING;
|
||||
// |ASN1_STRING_FLAG_BITS_LEFT| and the bottom 3 bits encode |padding|.
|
||||
out->flags &= ~0x07;
|
||||
out->flags |= ASN1_STRING_FLAG_BITS_LEFT | padding;
|
||||
return 1;
|
||||
}
|
||||
|
||||
ASN1_BIT_STRING *c2i_ASN1_BIT_STRING(ASN1_BIT_STRING **a,
|
||||
const unsigned char **pp, long len) {
|
||||
if (len < 0) {
|
||||
OPENSSL_PUT_ERROR(ASN1, ASN1_R_STRING_TOO_SHORT);
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
ASN1_BIT_STRING *ret = nullptr;
|
||||
if (a == nullptr || *a == nullptr) {
|
||||
if ((ret = ASN1_BIT_STRING_new()) == nullptr) {
|
||||
return nullptr;
|
||||
}
|
||||
} else {
|
||||
ret = *a;
|
||||
}
|
||||
|
||||
if (!asn1_parse_bit_string_contents(bssl::Span(*pp, len), ret)) {
|
||||
if (ret != nullptr && (a == nullptr || *a != ret)) {
|
||||
ASN1_BIT_STRING_free(ret);
|
||||
}
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
if (a != nullptr) {
|
||||
*a = ret;
|
||||
}
|
||||
*pp += len;
|
||||
return ret;
|
||||
}
|
||||
|
||||
int asn1_parse_bit_string(CBS *cbs, ASN1_BIT_STRING *out, CBS_ASN1_TAG tag) {
|
||||
tag = tag == 0 ? CBS_ASN1_BITSTRING : tag;
|
||||
CBS child;
|
||||
if (!CBS_get_asn1(cbs, &child, tag)) {
|
||||
OPENSSL_PUT_ERROR(ASN1, ASN1_R_DECODE_ERROR);
|
||||
return 0;
|
||||
}
|
||||
return asn1_parse_bit_string_contents(child, out);
|
||||
}
|
||||
|
||||
int asn1_parse_bit_string_with_bad_length(CBS *cbs, ASN1_BIT_STRING *out) {
|
||||
CBS child;
|
||||
CBS_ASN1_TAG tag;
|
||||
size_t header_len;
|
||||
int indefinite;
|
||||
if (!CBS_get_any_ber_asn1_element(cbs, &child, &tag, &header_len,
|
||||
/*out_ber_found=*/nullptr,
|
||||
&indefinite) ||
|
||||
tag != CBS_ASN1_BITSTRING || indefinite || //
|
||||
!CBS_skip(&child, header_len)) {
|
||||
OPENSSL_PUT_ERROR(ASN1, ASN1_R_DECODE_ERROR);
|
||||
return 0;
|
||||
}
|
||||
return asn1_parse_bit_string_contents(child, out);
|
||||
}
|
||||
|
||||
// These next 2 functions from Goetz Babin-Ebell <babinebell@trustcenter.de>
|
||||
int ASN1_BIT_STRING_set_bit(ASN1_BIT_STRING *a, int n, int value) {
|
||||
int w, v, iv;
|
||||
unsigned char *c;
|
||||
|
||||
w = n / 8;
|
||||
v = 1 << (7 - (n & 0x07));
|
||||
iv = ~v;
|
||||
if (!value) {
|
||||
v = 0;
|
||||
}
|
||||
|
||||
if (a == NULL) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
a->flags &= ~(ASN1_STRING_FLAG_BITS_LEFT | 0x07); // clear, set on write
|
||||
|
||||
if ((a->length < (w + 1)) || (a->data == NULL)) {
|
||||
if (!value) {
|
||||
return 1; // Don't need to set
|
||||
}
|
||||
if (a->data == NULL) {
|
||||
c = (unsigned char *)OPENSSL_malloc(w + 1);
|
||||
} else {
|
||||
c = (unsigned char *)OPENSSL_realloc(a->data, w + 1);
|
||||
}
|
||||
if (c == NULL) {
|
||||
return 0;
|
||||
}
|
||||
if (w + 1 - a->length > 0) {
|
||||
OPENSSL_memset(c + a->length, 0, w + 1 - a->length);
|
||||
}
|
||||
a->data = c;
|
||||
a->length = w + 1;
|
||||
}
|
||||
a->data[w] = ((a->data[w]) & iv) | v;
|
||||
while ((a->length > 0) && (a->data[a->length - 1] == 0)) {
|
||||
a->length--;
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
|
||||
int ASN1_BIT_STRING_get_bit(const ASN1_BIT_STRING *a, int n) {
|
||||
int w, v;
|
||||
|
||||
w = n / 8;
|
||||
v = 1 << (7 - (n & 0x07));
|
||||
if ((a == NULL) || (a->length < (w + 1)) || (a->data == NULL)) {
|
||||
return 0;
|
||||
}
|
||||
return ((a->data[w] & v) != 0);
|
||||
}
|
||||
|
||||
// Checks if the given bit string contains only bits specified by
|
||||
// the flags vector. Returns 0 if there is at least one bit set in 'a'
|
||||
// which is not specified in 'flags', 1 otherwise.
|
||||
// 'len' is the length of 'flags'.
|
||||
int ASN1_BIT_STRING_check(const ASN1_BIT_STRING *a, const unsigned char *flags,
|
||||
int flags_len) {
|
||||
int i, ok;
|
||||
// Check if there is one bit set at all.
|
||||
if (!a || !a->data) {
|
||||
return 1;
|
||||
}
|
||||
|
||||
// Check each byte of the internal representation of the bit string.
|
||||
ok = 1;
|
||||
for (i = 0; i < a->length && ok; ++i) {
|
||||
unsigned char mask = i < flags_len ? ~flags[i] : 0xff;
|
||||
// We are done if there is an unneeded bit set.
|
||||
ok = (a->data[i] & mask) == 0;
|
||||
}
|
||||
return ok;
|
||||
}
|
||||
@@ -1,95 +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_asn1.h>
|
||||
|
||||
#include <CCryptoBoringSSL_bytestring.h>
|
||||
#include <CCryptoBoringSSL_err.h>
|
||||
|
||||
#include "../bytestring/internal.h"
|
||||
|
||||
|
||||
int i2d_ASN1_BOOLEAN(ASN1_BOOLEAN a, unsigned char **outp) {
|
||||
CBB cbb;
|
||||
if (!CBB_init(&cbb, 3) || //
|
||||
!CBB_add_asn1_bool(&cbb, a != ASN1_BOOLEAN_FALSE)) {
|
||||
CBB_cleanup(&cbb);
|
||||
return -1;
|
||||
}
|
||||
return CBB_finish_i2d(&cbb, outp);
|
||||
}
|
||||
|
||||
ASN1_BOOLEAN d2i_ASN1_BOOLEAN(ASN1_BOOLEAN *out, const unsigned char **inp,
|
||||
long len) {
|
||||
if (len < 0) {
|
||||
return ASN1_BOOLEAN_NONE;
|
||||
}
|
||||
|
||||
CBS cbs;
|
||||
CBS_init(&cbs, *inp, (size_t)len);
|
||||
int val;
|
||||
if (!CBS_get_asn1_bool(&cbs, &val)) {
|
||||
OPENSSL_PUT_ERROR(ASN1, ASN1_R_DECODE_ERROR);
|
||||
return ASN1_BOOLEAN_NONE;
|
||||
}
|
||||
|
||||
ASN1_BOOLEAN ret = val ? ASN1_BOOLEAN_TRUE : ASN1_BOOLEAN_FALSE;
|
||||
if (out != NULL) {
|
||||
*out = ret;
|
||||
}
|
||||
*inp = CBS_data(&cbs);
|
||||
return ret;
|
||||
}
|
||||
@@ -0,0 +1,50 @@
|
||||
// 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>
|
||||
#include <CCryptoBoringSSL_err.h>
|
||||
|
||||
#include "../bytestring/internal.h"
|
||||
|
||||
|
||||
int i2d_ASN1_BOOLEAN(ASN1_BOOLEAN a, unsigned char **outp) {
|
||||
return bssl::I2DFromCBB(
|
||||
/*initial_capacity=*/3, outp, [&](CBB *cbb) -> bool {
|
||||
return CBB_add_asn1_bool(cbb, a != ASN1_BOOLEAN_FALSE);
|
||||
});
|
||||
}
|
||||
|
||||
ASN1_BOOLEAN d2i_ASN1_BOOLEAN(ASN1_BOOLEAN *out, const unsigned char **inp,
|
||||
long len) {
|
||||
if (len < 0) {
|
||||
return ASN1_BOOLEAN_NONE;
|
||||
}
|
||||
|
||||
CBS cbs;
|
||||
CBS_init(&cbs, *inp, (size_t)len);
|
||||
int val;
|
||||
if (!CBS_get_asn1_bool(&cbs, &val)) {
|
||||
OPENSSL_PUT_ERROR(ASN1, ASN1_R_DECODE_ERROR);
|
||||
return ASN1_BOOLEAN_NONE;
|
||||
}
|
||||
|
||||
ASN1_BOOLEAN ret = val ? ASN1_BOOLEAN_TRUE : ASN1_BOOLEAN_FALSE;
|
||||
if (out != NULL) {
|
||||
*out = ret;
|
||||
}
|
||||
*inp = CBS_data(&cbs);
|
||||
return ret;
|
||||
}
|
||||
@@ -1,89 +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_asn1.h>
|
||||
|
||||
#include <limits.h>
|
||||
|
||||
#include <CCryptoBoringSSL_bio.h>
|
||||
#include <CCryptoBoringSSL_err.h>
|
||||
#include <CCryptoBoringSSL_mem.h>
|
||||
|
||||
|
||||
void *ASN1_item_d2i_bio(const ASN1_ITEM *it, BIO *in, void *x) {
|
||||
uint8_t *data;
|
||||
size_t len;
|
||||
// Historically, this function did not impose a limit in OpenSSL and is used
|
||||
// to read CRLs, so we leave this without an external bound.
|
||||
if (!BIO_read_asn1(in, &data, &len, INT_MAX)) {
|
||||
return NULL;
|
||||
}
|
||||
const uint8_t *ptr = data;
|
||||
void *ret = ASN1_item_d2i(x, &ptr, len, it);
|
||||
OPENSSL_free(data);
|
||||
return ret;
|
||||
}
|
||||
|
||||
void *ASN1_item_d2i_fp(const ASN1_ITEM *it, FILE *in, void *x) {
|
||||
BIO *b = BIO_new_fp(in, BIO_NOCLOSE);
|
||||
if (b == NULL) {
|
||||
OPENSSL_PUT_ERROR(ASN1, ERR_R_BUF_LIB);
|
||||
return NULL;
|
||||
}
|
||||
void *ret = ASN1_item_d2i_bio(it, b, x);
|
||||
BIO_free(b);
|
||||
return ret;
|
||||
}
|
||||
@@ -0,0 +1,47 @@
|
||||
// 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 <CCryptoBoringSSL_bio.h>
|
||||
#include <CCryptoBoringSSL_err.h>
|
||||
#include <CCryptoBoringSSL_mem.h>
|
||||
|
||||
|
||||
void *ASN1_item_d2i_bio(const ASN1_ITEM *it, BIO *in, void *x) {
|
||||
uint8_t *data;
|
||||
size_t len;
|
||||
// Historically, this function did not impose a limit in OpenSSL and is used
|
||||
// to read CRLs, so we leave this without an external bound.
|
||||
if (!BIO_read_asn1(in, &data, &len, INT_MAX)) {
|
||||
return NULL;
|
||||
}
|
||||
const uint8_t *ptr = data;
|
||||
void *ret = ASN1_item_d2i(reinterpret_cast<ASN1_VALUE **>(x), &ptr, len, it);
|
||||
OPENSSL_free(data);
|
||||
return ret;
|
||||
}
|
||||
|
||||
void *ASN1_item_d2i_fp(const ASN1_ITEM *it, FILE *in, void *x) {
|
||||
BIO *b = BIO_new_fp(in, BIO_NOCLOSE);
|
||||
if (b == NULL) {
|
||||
OPENSSL_PUT_ERROR(ASN1, ERR_R_BUF_LIB);
|
||||
return NULL;
|
||||
}
|
||||
void *ret = ASN1_item_d2i_bio(it, b, x);
|
||||
BIO_free(b);
|
||||
return ret;
|
||||
}
|
||||
@@ -1,84 +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_asn1.h>
|
||||
|
||||
#include <CCryptoBoringSSL_err.h>
|
||||
#include <CCryptoBoringSSL_mem.h>
|
||||
|
||||
// ASN1_ITEM version of dup: this follows the model above except we don't
|
||||
// need to allocate the buffer. At some point this could be rewritten to
|
||||
// directly dup the underlying structure instead of doing and encode and
|
||||
// decode.
|
||||
void *ASN1_item_dup(const ASN1_ITEM *it, void *x) {
|
||||
unsigned char *b = NULL;
|
||||
const unsigned char *p;
|
||||
long i;
|
||||
void *ret;
|
||||
|
||||
if (x == NULL) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
i = ASN1_item_i2d(x, &b, it);
|
||||
if (b == NULL) {
|
||||
return NULL;
|
||||
}
|
||||
p = b;
|
||||
ret = ASN1_item_d2i(NULL, &p, i, it);
|
||||
OPENSSL_free(b);
|
||||
return ret;
|
||||
}
|
||||
@@ -0,0 +1,42 @@
|
||||
// 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_err.h>
|
||||
#include <CCryptoBoringSSL_mem.h>
|
||||
|
||||
// ASN1_ITEM version of dup: this follows the model above except we don't
|
||||
// need to allocate the buffer. At some point this could be rewritten to
|
||||
// directly dup the underlying structure instead of doing and encode and
|
||||
// decode.
|
||||
void *ASN1_item_dup(const ASN1_ITEM *it, void *x) {
|
||||
unsigned char *b = NULL;
|
||||
const unsigned char *p;
|
||||
long i;
|
||||
void *ret;
|
||||
|
||||
if (x == NULL) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
i = ASN1_item_i2d(reinterpret_cast<ASN1_VALUE *>(x), &b, it);
|
||||
if (b == NULL) {
|
||||
return NULL;
|
||||
}
|
||||
p = b;
|
||||
ret = ASN1_item_d2i(NULL, &p, i, it);
|
||||
OPENSSL_free(b);
|
||||
return ret;
|
||||
}
|
||||
@@ -1,151 +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_asn1.h>
|
||||
#include <CCryptoBoringSSL_bytestring.h>
|
||||
#include <CCryptoBoringSSL_err.h>
|
||||
#include <CCryptoBoringSSL_mem.h>
|
||||
#include <CCryptoBoringSSL_posix_time.h>
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <time.h>
|
||||
|
||||
#include "internal.h"
|
||||
|
||||
int asn1_generalizedtime_to_tm(struct tm *tm, const ASN1_GENERALIZEDTIME *d) {
|
||||
if (d->type != V_ASN1_GENERALIZEDTIME) {
|
||||
return 0;
|
||||
}
|
||||
CBS cbs;
|
||||
CBS_init(&cbs, d->data, (size_t)d->length);
|
||||
if (!CBS_parse_generalized_time(&cbs, tm, /*allow_timezone_offset=*/0)) {
|
||||
return 0;
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
|
||||
int ASN1_GENERALIZEDTIME_check(const ASN1_GENERALIZEDTIME *d) {
|
||||
return asn1_generalizedtime_to_tm(NULL, d);
|
||||
}
|
||||
|
||||
int ASN1_GENERALIZEDTIME_set_string(ASN1_GENERALIZEDTIME *s, const char *str) {
|
||||
size_t len = strlen(str);
|
||||
CBS cbs;
|
||||
CBS_init(&cbs, (const uint8_t *)str, len);
|
||||
if (!CBS_parse_generalized_time(&cbs, /*out_tm=*/NULL,
|
||||
/*allow_timezone_offset=*/0)) {
|
||||
return 0;
|
||||
}
|
||||
if (s != NULL) {
|
||||
if (!ASN1_STRING_set(s, str, len)) {
|
||||
return 0;
|
||||
}
|
||||
s->type = V_ASN1_GENERALIZEDTIME;
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
|
||||
ASN1_GENERALIZEDTIME *ASN1_GENERALIZEDTIME_set(ASN1_GENERALIZEDTIME *s,
|
||||
int64_t posix_time) {
|
||||
return ASN1_GENERALIZEDTIME_adj(s, posix_time, 0, 0);
|
||||
}
|
||||
|
||||
ASN1_GENERALIZEDTIME *ASN1_GENERALIZEDTIME_adj(ASN1_GENERALIZEDTIME *s,
|
||||
int64_t posix_time, int offset_day,
|
||||
long offset_sec) {
|
||||
struct tm data;
|
||||
if (!OPENSSL_posix_to_tm(posix_time, &data)) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
if (offset_day || offset_sec) {
|
||||
if (!OPENSSL_gmtime_adj(&data, offset_day, offset_sec)) {
|
||||
return NULL;
|
||||
}
|
||||
}
|
||||
|
||||
if (data.tm_year < 0 - 1900 || data.tm_year > 9999 - 1900) {
|
||||
OPENSSL_PUT_ERROR(ASN1, ASN1_R_ILLEGAL_TIME_VALUE);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
char buf[16];
|
||||
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.
|
||||
}
|
||||
|
||||
int free_s = 0;
|
||||
if (s == NULL) {
|
||||
free_s = 1;
|
||||
s = ASN1_UTCTIME_new();
|
||||
if (s == NULL) {
|
||||
return NULL;
|
||||
}
|
||||
}
|
||||
|
||||
if (!ASN1_STRING_set(s, buf, strlen(buf))) {
|
||||
if (free_s) {
|
||||
ASN1_UTCTIME_free(s);
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
s->type = V_ASN1_GENERALIZEDTIME;
|
||||
return s;
|
||||
}
|
||||
@@ -0,0 +1,126 @@
|
||||
// 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>
|
||||
#include <CCryptoBoringSSL_err.h>
|
||||
#include <CCryptoBoringSSL_mem.h>
|
||||
#include <CCryptoBoringSSL_posix_time.h>
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <time.h>
|
||||
|
||||
#include "internal.h"
|
||||
|
||||
int asn1_generalizedtime_to_tm(struct tm *tm, const ASN1_GENERALIZEDTIME *d) {
|
||||
if (d->type != V_ASN1_GENERALIZEDTIME) {
|
||||
return 0;
|
||||
}
|
||||
CBS cbs;
|
||||
CBS_init(&cbs, d->data, (size_t)d->length);
|
||||
if (!CBS_parse_generalized_time(&cbs, tm, /*allow_timezone_offset=*/0)) {
|
||||
return 0;
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
|
||||
int asn1_parse_generalized_time(CBS *cbs, ASN1_GENERALIZEDTIME *out,
|
||||
CBS_ASN1_TAG tag) {
|
||||
tag = tag == 0 ? CBS_ASN1_GENERALIZEDTIME : tag;
|
||||
CBS child;
|
||||
if (!CBS_get_asn1(cbs, &child, tag) ||
|
||||
!CBS_parse_generalized_time(&child, nullptr,
|
||||
/*allow_timezone_offset=*/0)) {
|
||||
OPENSSL_PUT_ERROR(ASN1, ASN1_R_DECODE_ERROR);
|
||||
return 0;
|
||||
}
|
||||
if (!ASN1_STRING_set(out, CBS_data(&child), CBS_len(&child))) {
|
||||
return 0;
|
||||
}
|
||||
out->type = V_ASN1_GENERALIZEDTIME;
|
||||
return 1;
|
||||
}
|
||||
|
||||
int ASN1_GENERALIZEDTIME_check(const ASN1_GENERALIZEDTIME *d) {
|
||||
return asn1_generalizedtime_to_tm(NULL, d);
|
||||
}
|
||||
|
||||
int ASN1_GENERALIZEDTIME_set_string(ASN1_GENERALIZEDTIME *s, const char *str) {
|
||||
size_t len = strlen(str);
|
||||
CBS cbs;
|
||||
CBS_init(&cbs, (const uint8_t *)str, len);
|
||||
if (!CBS_parse_generalized_time(&cbs, /*out_tm=*/NULL,
|
||||
/*allow_timezone_offset=*/0)) {
|
||||
return 0;
|
||||
}
|
||||
if (s != NULL) {
|
||||
if (!ASN1_STRING_set(s, str, len)) {
|
||||
return 0;
|
||||
}
|
||||
s->type = V_ASN1_GENERALIZEDTIME;
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
|
||||
ASN1_GENERALIZEDTIME *ASN1_GENERALIZEDTIME_set(ASN1_GENERALIZEDTIME *s,
|
||||
int64_t posix_time) {
|
||||
return ASN1_GENERALIZEDTIME_adj(s, posix_time, 0, 0);
|
||||
}
|
||||
|
||||
ASN1_GENERALIZEDTIME *ASN1_GENERALIZEDTIME_adj(ASN1_GENERALIZEDTIME *s,
|
||||
int64_t posix_time,
|
||||
int offset_day,
|
||||
long offset_sec) {
|
||||
struct tm data;
|
||||
if (!OPENSSL_posix_to_tm(posix_time, &data)) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
if (offset_day || offset_sec) {
|
||||
if (!OPENSSL_gmtime_adj(&data, offset_day, offset_sec)) {
|
||||
return NULL;
|
||||
}
|
||||
}
|
||||
|
||||
if (data.tm_year < 0 - 1900 || data.tm_year > 9999 - 1900) {
|
||||
OPENSSL_PUT_ERROR(ASN1, ASN1_R_ILLEGAL_TIME_VALUE);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
char buf[16];
|
||||
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);
|
||||
// |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) {
|
||||
free_s = 1;
|
||||
s = ASN1_UTCTIME_new();
|
||||
if (s == NULL) {
|
||||
return NULL;
|
||||
}
|
||||
}
|
||||
|
||||
if (!ASN1_STRING_set(s, buf, strlen(buf))) {
|
||||
if (free_s) {
|
||||
ASN1_UTCTIME_free(s);
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
s->type = V_ASN1_GENERALIZEDTIME;
|
||||
return s;
|
||||
}
|
||||
@@ -1,85 +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_asn1.h>
|
||||
|
||||
#include <CCryptoBoringSSL_bio.h>
|
||||
#include <CCryptoBoringSSL_err.h>
|
||||
#include <CCryptoBoringSSL_mem.h>
|
||||
|
||||
|
||||
int ASN1_item_i2d_fp(const ASN1_ITEM *it, FILE *out, void *x) {
|
||||
BIO *b = BIO_new_fp(out, BIO_NOCLOSE);
|
||||
if (b == NULL) {
|
||||
OPENSSL_PUT_ERROR(ASN1, ERR_R_BUF_LIB);
|
||||
return 0;
|
||||
}
|
||||
int ret = ASN1_item_i2d_bio(it, b, x);
|
||||
BIO_free(b);
|
||||
return ret;
|
||||
}
|
||||
|
||||
int ASN1_item_i2d_bio(const ASN1_ITEM *it, BIO *out, void *x) {
|
||||
unsigned char *b = NULL;
|
||||
int n = ASN1_item_i2d(x, &b, it);
|
||||
if (b == NULL) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
int ret = BIO_write_all(out, b, n);
|
||||
OPENSSL_free(b);
|
||||
return ret;
|
||||
}
|
||||
@@ -0,0 +1,43 @@
|
||||
// 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_bio.h>
|
||||
#include <CCryptoBoringSSL_err.h>
|
||||
#include <CCryptoBoringSSL_mem.h>
|
||||
|
||||
|
||||
int ASN1_item_i2d_fp(const ASN1_ITEM *it, FILE *out, void *x) {
|
||||
BIO *b = BIO_new_fp(out, BIO_NOCLOSE);
|
||||
if (b == NULL) {
|
||||
OPENSSL_PUT_ERROR(ASN1, ERR_R_BUF_LIB);
|
||||
return 0;
|
||||
}
|
||||
int ret = ASN1_item_i2d_bio(it, b, x);
|
||||
BIO_free(b);
|
||||
return ret;
|
||||
}
|
||||
|
||||
int ASN1_item_i2d_bio(const ASN1_ITEM *it, BIO *out, void *x) {
|
||||
unsigned char *b = NULL;
|
||||
int n = ASN1_item_i2d(reinterpret_cast<ASN1_VALUE *>(x), &b, it);
|
||||
if (b == NULL) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
int ret = BIO_write_all(out, b, n);
|
||||
OPENSSL_free(b);
|
||||
return ret;
|
||||
}
|
||||
+90
-92
@@ -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>
|
||||
|
||||
@@ -63,8 +21,10 @@
|
||||
#include <CCryptoBoringSSL_bytestring.h>
|
||||
#include <CCryptoBoringSSL_err.h>
|
||||
#include <CCryptoBoringSSL_mem.h>
|
||||
#include <CCryptoBoringSSL_span.h>
|
||||
|
||||
#include "../internal.h"
|
||||
#include "internal.h"
|
||||
|
||||
|
||||
ASN1_INTEGER *ASN1_INTEGER_dup(const ASN1_INTEGER *x) {
|
||||
@@ -114,6 +74,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;
|
||||
@@ -173,32 +147,13 @@ int i2c_ASN1_INTEGER(const ASN1_INTEGER *in, unsigned char **outp) {
|
||||
return len;
|
||||
}
|
||||
|
||||
ASN1_INTEGER *c2i_ASN1_INTEGER(ASN1_INTEGER **out, const unsigned char **inp,
|
||||
long len) {
|
||||
// This function can handle lengths up to INT_MAX - 1, but the rest of the
|
||||
// legacy ASN.1 code mixes integer types, so avoid exposing it to
|
||||
// ASN1_INTEGERS with larger lengths.
|
||||
if (len < 0 || len > INT_MAX / 2) {
|
||||
OPENSSL_PUT_ERROR(ASN1, ASN1_R_TOO_LONG);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
CBS cbs;
|
||||
CBS_init(&cbs, *inp, (size_t)len);
|
||||
static int asn1_parse_integer_contents(bssl::Span<const uint8_t> in,
|
||||
ASN1_INTEGER *out) {
|
||||
CBS cbs = in;
|
||||
int is_negative;
|
||||
if (!CBS_is_valid_asn1_integer(&cbs, &is_negative)) {
|
||||
OPENSSL_PUT_ERROR(ASN1, ASN1_R_INVALID_INTEGER);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
ASN1_INTEGER *ret = NULL;
|
||||
if (out == NULL || *out == NULL) {
|
||||
ret = ASN1_INTEGER_new();
|
||||
if (ret == NULL) {
|
||||
return NULL;
|
||||
}
|
||||
} else {
|
||||
ret = *out;
|
||||
return 0;
|
||||
}
|
||||
|
||||
// Convert to |ASN1_INTEGER|'s sign-and-magnitude representation. First,
|
||||
@@ -219,33 +174,75 @@ ASN1_INTEGER *c2i_ASN1_INTEGER(ASN1_INTEGER **out, const unsigned char **inp,
|
||||
}
|
||||
}
|
||||
|
||||
if (!ASN1_STRING_set(ret, CBS_data(&cbs), CBS_len(&cbs))) {
|
||||
goto err;
|
||||
if (!ASN1_STRING_set(out, CBS_data(&cbs), CBS_len(&cbs))) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (is_negative) {
|
||||
ret->type = V_ASN1_NEG_INTEGER;
|
||||
negate_twos_complement(ret->data, ret->length);
|
||||
out->type = V_ASN1_NEG_INTEGER;
|
||||
negate_twos_complement(out->data, out->length);
|
||||
} else {
|
||||
ret->type = V_ASN1_INTEGER;
|
||||
out->type = V_ASN1_INTEGER;
|
||||
}
|
||||
|
||||
// The value should be minimally-encoded.
|
||||
assert(ret->length == 0 || ret->data[0] != 0);
|
||||
assert(out->length == 0 || out->data[0] != 0);
|
||||
// Zero is not negative.
|
||||
assert(!is_negative || ret->length > 0);
|
||||
assert(!is_negative || out->length > 0);
|
||||
return 1;
|
||||
}
|
||||
|
||||
int asn1_parse_integer(CBS *cbs, ASN1_INTEGER *out, CBS_ASN1_TAG tag) {
|
||||
tag = tag == 0 ? CBS_ASN1_INTEGER : tag;
|
||||
CBS child;
|
||||
if (!CBS_get_asn1(cbs, &child, tag)) {
|
||||
OPENSSL_PUT_ERROR(ASN1, ASN1_R_DECODE_ERROR);
|
||||
return 0;
|
||||
}
|
||||
return asn1_parse_integer_contents(child, out);
|
||||
}
|
||||
|
||||
int asn1_parse_enumerated(CBS *cbs, ASN1_ENUMERATED *out, CBS_ASN1_TAG tag) {
|
||||
tag = tag == 0 ? CBS_ASN1_ENUMERATED : tag;
|
||||
if (!asn1_parse_integer(cbs, out, tag)) {
|
||||
return 0;
|
||||
}
|
||||
// Fix the type value.
|
||||
out->type =
|
||||
(out->type & V_ASN1_NEG) ? V_ASN1_NEG_ENUMERATED : V_ASN1_ENUMERATED;
|
||||
return 1;
|
||||
}
|
||||
|
||||
ASN1_INTEGER *c2i_ASN1_INTEGER(ASN1_INTEGER **out, const unsigned char **inp,
|
||||
long len) {
|
||||
if (len < 0) {
|
||||
OPENSSL_PUT_ERROR(ASN1, ASN1_R_STRING_TOO_SHORT);
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
ASN1_INTEGER *ret = nullptr;
|
||||
if (out == nullptr || *out == nullptr) {
|
||||
ret = ASN1_INTEGER_new();
|
||||
if (ret == nullptr) {
|
||||
return nullptr;
|
||||
}
|
||||
} else {
|
||||
ret = *out;
|
||||
}
|
||||
|
||||
if (!asn1_parse_integer_contents(bssl::Span(*inp, len), ret)) {
|
||||
if (ret != nullptr && (out == nullptr || *out != ret)) {
|
||||
ASN1_INTEGER_free(ret);
|
||||
}
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
*inp += len;
|
||||
if (out != NULL) {
|
||||
if (out != nullptr) {
|
||||
*out = ret;
|
||||
}
|
||||
return ret;
|
||||
|
||||
err:
|
||||
if (ret != NULL && (out == NULL || *out != ret)) {
|
||||
ASN1_INTEGER_free(ret);
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
||||
int ASN1_INTEGER_set_int64(ASN1_INTEGER *a, int64_t v) {
|
||||
@@ -408,6 +405,7 @@ static ASN1_STRING *bn_to_asn1_string(const BIGNUM *bn, ASN1_STRING *ai,
|
||||
} else {
|
||||
ret = ai;
|
||||
}
|
||||
int len;
|
||||
if (ret == NULL) {
|
||||
OPENSSL_PUT_ERROR(ASN1, ASN1_R_NESTED_ASN1_ERROR);
|
||||
goto err;
|
||||
@@ -419,7 +417,7 @@ static ASN1_STRING *bn_to_asn1_string(const BIGNUM *bn, ASN1_STRING *ai,
|
||||
ret->type = type;
|
||||
}
|
||||
|
||||
int len = BN_num_bytes(bn);
|
||||
len = BN_num_bytes(bn);
|
||||
if (!ASN1_STRING_set(ret, NULL, len) ||
|
||||
!BN_bn2bin_padded(ret->data, len, bn)) {
|
||||
goto err;
|
||||
+22
-62
@@ -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>
|
||||
|
||||
@@ -226,6 +184,8 @@ int ASN1_mbstring_ncopy(ASN1_STRING **out, const unsigned char *in,
|
||||
CBB cbb;
|
||||
CBB_zero(&cbb);
|
||||
// If both the same type just copy across
|
||||
uint8_t *data = NULL;
|
||||
size_t data_len = 0;
|
||||
if (inform == outform) {
|
||||
if (!ASN1_STRING_set(dest, in, len)) {
|
||||
goto err;
|
||||
@@ -245,12 +205,12 @@ int ASN1_mbstring_ncopy(ASN1_STRING **out, const unsigned char *in,
|
||||
goto err;
|
||||
}
|
||||
}
|
||||
uint8_t *data = NULL;
|
||||
size_t data_len;
|
||||
if (// OpenSSL historically NUL-terminated this value with a single byte,
|
||||
// even for |MBSTRING_BMP| and |MBSTRING_UNIV|.
|
||||
!CBB_add_u8(&cbb, 0) || !CBB_finish(&cbb, &data, &data_len) ||
|
||||
data_len < 1 || data_len > INT_MAX) {
|
||||
if (/* OpenSSL historically NUL-terminated this value with a single byte,
|
||||
* even for |MBSTRING_BMP| and |MBSTRING_UNIV|. */
|
||||
!CBB_add_u8(&cbb, 0) || //
|
||||
!CBB_finish(&cbb, &data, &data_len) || //
|
||||
data_len < 1 || //
|
||||
data_len > INT_MAX) {
|
||||
OPENSSL_PUT_ERROR(ASN1, ERR_R_INTERNAL_ERROR);
|
||||
OPENSSL_free(data);
|
||||
goto err;
|
||||
@@ -272,7 +232,7 @@ int asn1_is_printable(uint32_t value) {
|
||||
if (value > 0x7f) {
|
||||
return 0;
|
||||
}
|
||||
return OPENSSL_isalnum(value) || //
|
||||
return OPENSSL_isalnum(value) || //
|
||||
value == ' ' || value == '\'' || value == '(' || value == ')' ||
|
||||
value == '+' || value == ',' || value == '-' || value == '.' ||
|
||||
value == '/' || value == ':' || value == '=' || value == '?';
|
||||
@@ -1,235 +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_asn1.h>
|
||||
|
||||
#include <limits.h>
|
||||
#include <string.h>
|
||||
|
||||
#include <CCryptoBoringSSL_bytestring.h>
|
||||
#include <CCryptoBoringSSL_err.h>
|
||||
#include <CCryptoBoringSSL_mem.h>
|
||||
#include <CCryptoBoringSSL_obj.h>
|
||||
|
||||
#include "../bytestring/internal.h"
|
||||
#include "../internal.h"
|
||||
#include "internal.h"
|
||||
|
||||
|
||||
int i2d_ASN1_OBJECT(const ASN1_OBJECT *in, unsigned char **outp) {
|
||||
if (in == NULL) {
|
||||
OPENSSL_PUT_ERROR(ASN1, ERR_R_PASSED_NULL_PARAMETER);
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (in->length <= 0) {
|
||||
OPENSSL_PUT_ERROR(ASN1, ASN1_R_ILLEGAL_OBJECT);
|
||||
return -1;
|
||||
}
|
||||
|
||||
CBB cbb, child;
|
||||
if (!CBB_init(&cbb, (size_t)in->length + 2) ||
|
||||
!CBB_add_asn1(&cbb, &child, CBS_ASN1_OBJECT) ||
|
||||
!CBB_add_bytes(&child, in->data, in->length)) {
|
||||
CBB_cleanup(&cbb);
|
||||
return -1;
|
||||
}
|
||||
|
||||
return CBB_finish_i2d(&cbb, outp);
|
||||
}
|
||||
|
||||
int i2t_ASN1_OBJECT(char *buf, int buf_len, const ASN1_OBJECT *a) {
|
||||
return OBJ_obj2txt(buf, buf_len, a, 0);
|
||||
}
|
||||
|
||||
static int write_str(BIO *bp, const char *str) {
|
||||
size_t len = strlen(str);
|
||||
if (len > INT_MAX) {
|
||||
OPENSSL_PUT_ERROR(ASN1, ERR_R_OVERFLOW);
|
||||
return -1;
|
||||
}
|
||||
return BIO_write(bp, str, (int)len) == (int)len ? (int)len : -1;
|
||||
}
|
||||
|
||||
int i2a_ASN1_OBJECT(BIO *bp, const ASN1_OBJECT *a) {
|
||||
if (a == NULL || a->data == NULL) {
|
||||
return write_str(bp, "NULL");
|
||||
}
|
||||
|
||||
char buf[80], *allocated = NULL;
|
||||
const char *str = buf;
|
||||
int len = i2t_ASN1_OBJECT(buf, sizeof(buf), a);
|
||||
if (len > (int)sizeof(buf) - 1) {
|
||||
// The input was truncated. Allocate a buffer that fits.
|
||||
allocated = OPENSSL_malloc(len + 1);
|
||||
if (allocated == NULL) {
|
||||
return -1;
|
||||
}
|
||||
len = i2t_ASN1_OBJECT(allocated, len + 1, a);
|
||||
str = allocated;
|
||||
}
|
||||
if (len <= 0) {
|
||||
str = "<INVALID>";
|
||||
}
|
||||
|
||||
int ret = write_str(bp, str);
|
||||
OPENSSL_free(allocated);
|
||||
return ret;
|
||||
}
|
||||
|
||||
ASN1_OBJECT *d2i_ASN1_OBJECT(ASN1_OBJECT **out, const unsigned char **inp,
|
||||
long len) {
|
||||
if (len < 0) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
CBS cbs, child;
|
||||
CBS_init(&cbs, *inp, (size_t)len);
|
||||
if (!CBS_get_asn1(&cbs, &child, CBS_ASN1_OBJECT)) {
|
||||
OPENSSL_PUT_ERROR(ASN1, ASN1_R_DECODE_ERROR);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
const uint8_t *contents = CBS_data(&child);
|
||||
ASN1_OBJECT *ret = c2i_ASN1_OBJECT(out, &contents, CBS_len(&child));
|
||||
if (ret != NULL) {
|
||||
// |c2i_ASN1_OBJECT| should have consumed the entire input.
|
||||
assert(CBS_data(&cbs) == contents);
|
||||
*inp = CBS_data(&cbs);
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
ASN1_OBJECT *c2i_ASN1_OBJECT(ASN1_OBJECT **out, const unsigned char **inp,
|
||||
long len) {
|
||||
if (len < 0) {
|
||||
OPENSSL_PUT_ERROR(ASN1, ASN1_R_INVALID_OBJECT_ENCODING);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
CBS cbs;
|
||||
CBS_init(&cbs, *inp, (size_t)len);
|
||||
if (!CBS_is_valid_asn1_oid(&cbs)) {
|
||||
OPENSSL_PUT_ERROR(ASN1, ASN1_R_INVALID_OBJECT_ENCODING);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
ASN1_OBJECT *ret = ASN1_OBJECT_create(NID_undef, *inp, (size_t)len,
|
||||
/*sn=*/NULL, /*ln=*/NULL);
|
||||
if (ret == NULL) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
if (out != NULL) {
|
||||
ASN1_OBJECT_free(*out);
|
||||
*out = ret;
|
||||
}
|
||||
*inp += len; // All bytes were consumed.
|
||||
return ret;
|
||||
}
|
||||
|
||||
ASN1_OBJECT *ASN1_OBJECT_new(void) {
|
||||
ASN1_OBJECT *ret;
|
||||
|
||||
ret = (ASN1_OBJECT *)OPENSSL_malloc(sizeof(ASN1_OBJECT));
|
||||
if (ret == NULL) {
|
||||
return NULL;
|
||||
}
|
||||
ret->length = 0;
|
||||
ret->data = NULL;
|
||||
ret->nid = 0;
|
||||
ret->sn = NULL;
|
||||
ret->ln = NULL;
|
||||
ret->flags = ASN1_OBJECT_FLAG_DYNAMIC;
|
||||
return ret;
|
||||
}
|
||||
|
||||
void ASN1_OBJECT_free(ASN1_OBJECT *a) {
|
||||
if (a == NULL) {
|
||||
return;
|
||||
}
|
||||
if (a->flags & ASN1_OBJECT_FLAG_DYNAMIC_STRINGS) {
|
||||
OPENSSL_free((void *)a->sn);
|
||||
OPENSSL_free((void *)a->ln);
|
||||
a->sn = a->ln = NULL;
|
||||
}
|
||||
if (a->flags & ASN1_OBJECT_FLAG_DYNAMIC_DATA) {
|
||||
OPENSSL_free((void *)a->data);
|
||||
a->data = NULL;
|
||||
a->length = 0;
|
||||
}
|
||||
if (a->flags & ASN1_OBJECT_FLAG_DYNAMIC) {
|
||||
OPENSSL_free(a);
|
||||
}
|
||||
}
|
||||
|
||||
ASN1_OBJECT *ASN1_OBJECT_create(int nid, const unsigned char *data, size_t len,
|
||||
const char *sn, const char *ln) {
|
||||
if (len > INT_MAX) {
|
||||
OPENSSL_PUT_ERROR(ASN1, ASN1_R_STRING_TOO_LONG);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
ASN1_OBJECT o;
|
||||
o.sn = sn;
|
||||
o.ln = ln;
|
||||
o.data = data;
|
||||
o.nid = nid;
|
||||
o.length = (int)len;
|
||||
o.flags = ASN1_OBJECT_FLAG_DYNAMIC | ASN1_OBJECT_FLAG_DYNAMIC_STRINGS |
|
||||
ASN1_OBJECT_FLAG_DYNAMIC_DATA;
|
||||
return OBJ_dup(&o);
|
||||
}
|
||||
@@ -0,0 +1,189 @@
|
||||
// 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>
|
||||
#include <CCryptoBoringSSL_obj.h>
|
||||
|
||||
#include "../bytestring/internal.h"
|
||||
#include "../internal.h"
|
||||
#include "internal.h"
|
||||
|
||||
|
||||
int asn1_marshal_object(CBB *out, const ASN1_OBJECT *in, CBS_ASN1_TAG tag) {
|
||||
if (in == NULL) {
|
||||
OPENSSL_PUT_ERROR(ASN1, ERR_R_PASSED_NULL_PARAMETER);
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (in->length <= 0) {
|
||||
OPENSSL_PUT_ERROR(ASN1, ASN1_R_ILLEGAL_OBJECT);
|
||||
return 0;
|
||||
}
|
||||
|
||||
tag = tag == 0 ? CBS_ASN1_OBJECT : tag;
|
||||
return CBB_add_asn1_element(out, tag, in->data, in->length);
|
||||
}
|
||||
|
||||
int i2d_ASN1_OBJECT(const ASN1_OBJECT *in, unsigned char **outp) {
|
||||
return bssl::I2DFromCBB(
|
||||
/*initial_capacity=*/static_cast<size_t>(in->length) + 2, outp,
|
||||
[&](CBB *cbb) -> bool {
|
||||
return asn1_marshal_object(cbb, in, /*tag=*/0);
|
||||
});
|
||||
}
|
||||
|
||||
int i2t_ASN1_OBJECT(char *buf, int buf_len, const ASN1_OBJECT *a) {
|
||||
return OBJ_obj2txt(buf, buf_len, a, 0);
|
||||
}
|
||||
|
||||
static int write_str(BIO *bp, const char *str) {
|
||||
size_t len = strlen(str);
|
||||
if (len > INT_MAX) {
|
||||
OPENSSL_PUT_ERROR(ASN1, ERR_R_OVERFLOW);
|
||||
return -1;
|
||||
}
|
||||
return BIO_write(bp, str, (int)len) == (int)len ? (int)len : -1;
|
||||
}
|
||||
|
||||
int i2a_ASN1_OBJECT(BIO *bp, const ASN1_OBJECT *a) {
|
||||
if (a == NULL || a->data == NULL) {
|
||||
return write_str(bp, "NULL");
|
||||
}
|
||||
|
||||
char buf[80], *allocated = NULL;
|
||||
const char *str = buf;
|
||||
int len = i2t_ASN1_OBJECT(buf, sizeof(buf), a);
|
||||
if (len > (int)sizeof(buf) - 1) {
|
||||
// The input was truncated. Allocate a buffer that fits.
|
||||
allocated = reinterpret_cast<char *>(OPENSSL_malloc(len + 1));
|
||||
if (allocated == NULL) {
|
||||
return -1;
|
||||
}
|
||||
len = i2t_ASN1_OBJECT(allocated, len + 1, a);
|
||||
str = allocated;
|
||||
}
|
||||
if (len <= 0) {
|
||||
str = "<INVALID>";
|
||||
}
|
||||
|
||||
int ret = write_str(bp, str);
|
||||
OPENSSL_free(allocated);
|
||||
return ret;
|
||||
}
|
||||
|
||||
ASN1_OBJECT *d2i_ASN1_OBJECT(ASN1_OBJECT **out, const unsigned char **inp,
|
||||
long len) {
|
||||
return bssl::D2IFromCBS(out, inp, len, [](CBS *cbs) -> ASN1_OBJECT * {
|
||||
CBS child;
|
||||
if (!CBS_get_asn1(cbs, &child, CBS_ASN1_OBJECT)) {
|
||||
OPENSSL_PUT_ERROR(ASN1, ASN1_R_DECODE_ERROR);
|
||||
return nullptr;
|
||||
}
|
||||
const uint8_t *contents = CBS_data(&child);
|
||||
return c2i_ASN1_OBJECT(nullptr, &contents, CBS_len(&child));
|
||||
});
|
||||
}
|
||||
|
||||
ASN1_OBJECT *c2i_ASN1_OBJECT(ASN1_OBJECT **out, const unsigned char **inp,
|
||||
long len) {
|
||||
return bssl::D2IFromCBS(out, inp, len, [](CBS *cbs) -> ASN1_OBJECT * {
|
||||
if (!CBS_is_valid_asn1_oid(cbs)) {
|
||||
OPENSSL_PUT_ERROR(ASN1, ASN1_R_INVALID_OBJECT_ENCODING);
|
||||
return nullptr;
|
||||
}
|
||||
ASN1_OBJECT *ret =
|
||||
ASN1_OBJECT_create(NID_undef, CBS_data(cbs), CBS_len(cbs),
|
||||
/*sn=*/nullptr, /*ln=*/nullptr);
|
||||
if (ret != nullptr) {
|
||||
// |c2i_ASN1_OBJECT| consumes its whole input on success.
|
||||
BSSL_CHECK(CBS_skip(cbs, CBS_len(cbs)));
|
||||
}
|
||||
return ret;
|
||||
});
|
||||
}
|
||||
|
||||
ASN1_OBJECT *asn1_parse_object(CBS *cbs, CBS_ASN1_TAG tag) {
|
||||
tag = tag == 0 ? CBS_ASN1_OBJECT : tag;
|
||||
CBS child;
|
||||
if (!CBS_get_asn1(cbs, &child, tag)) {
|
||||
OPENSSL_PUT_ERROR(ASN1, ASN1_R_DECODE_ERROR);
|
||||
return nullptr;
|
||||
}
|
||||
if (!CBS_is_valid_asn1_oid(&child)) {
|
||||
OPENSSL_PUT_ERROR(ASN1, ASN1_R_INVALID_OBJECT_ENCODING);
|
||||
return nullptr;
|
||||
}
|
||||
return ASN1_OBJECT_create(NID_undef, CBS_data(&child), CBS_len(&child),
|
||||
/*sn=*/nullptr, /*ln=*/nullptr);
|
||||
}
|
||||
|
||||
ASN1_OBJECT *ASN1_OBJECT_new(void) {
|
||||
ASN1_OBJECT *ret;
|
||||
|
||||
ret = (ASN1_OBJECT *)OPENSSL_malloc(sizeof(ASN1_OBJECT));
|
||||
if (ret == NULL) {
|
||||
return NULL;
|
||||
}
|
||||
ret->length = 0;
|
||||
ret->data = NULL;
|
||||
ret->nid = 0;
|
||||
ret->sn = NULL;
|
||||
ret->ln = NULL;
|
||||
ret->flags = ASN1_OBJECT_FLAG_DYNAMIC;
|
||||
return ret;
|
||||
}
|
||||
|
||||
void ASN1_OBJECT_free(ASN1_OBJECT *a) {
|
||||
if (a == NULL) {
|
||||
return;
|
||||
}
|
||||
if (a->flags & ASN1_OBJECT_FLAG_DYNAMIC_STRINGS) {
|
||||
OPENSSL_free((void *)a->sn);
|
||||
OPENSSL_free((void *)a->ln);
|
||||
a->sn = a->ln = NULL;
|
||||
}
|
||||
if (a->flags & ASN1_OBJECT_FLAG_DYNAMIC_DATA) {
|
||||
OPENSSL_free((void *)a->data);
|
||||
a->data = NULL;
|
||||
a->length = 0;
|
||||
}
|
||||
if (a->flags & ASN1_OBJECT_FLAG_DYNAMIC) {
|
||||
OPENSSL_free(a);
|
||||
}
|
||||
}
|
||||
|
||||
ASN1_OBJECT *ASN1_OBJECT_create(int nid, const unsigned char *data, size_t len,
|
||||
const char *sn, const char *ln) {
|
||||
if (len > INT_MAX) {
|
||||
OPENSSL_PUT_ERROR(ASN1, ASN1_R_STRING_TOO_LONG);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
ASN1_OBJECT o;
|
||||
o.sn = sn;
|
||||
o.ln = ln;
|
||||
o.data = data;
|
||||
o.nid = nid;
|
||||
o.length = (int)len;
|
||||
o.flags = ASN1_OBJECT_FLAG_DYNAMIC | ASN1_OBJECT_FLAG_DYNAMIC_STRINGS |
|
||||
ASN1_OBJECT_FLAG_DYNAMIC_DATA;
|
||||
return OBJ_dup(&o);
|
||||
}
|
||||
@@ -1,74 +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_asn1.h>
|
||||
|
||||
#include <CCryptoBoringSSL_err.h>
|
||||
#include <CCryptoBoringSSL_mem.h>
|
||||
|
||||
ASN1_OCTET_STRING *ASN1_OCTET_STRING_dup(const ASN1_OCTET_STRING *x) {
|
||||
return ASN1_STRING_dup(x);
|
||||
}
|
||||
|
||||
int ASN1_OCTET_STRING_cmp(const ASN1_OCTET_STRING *a,
|
||||
const ASN1_OCTET_STRING *b) {
|
||||
return ASN1_STRING_cmp(a, b);
|
||||
}
|
||||
|
||||
int ASN1_OCTET_STRING_set(ASN1_OCTET_STRING *x, const unsigned char *d,
|
||||
int len) {
|
||||
return ASN1_STRING_set(x, d, len);
|
||||
}
|
||||
@@ -0,0 +1,32 @@
|
||||
// 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_err.h>
|
||||
#include <CCryptoBoringSSL_mem.h>
|
||||
|
||||
ASN1_OCTET_STRING *ASN1_OCTET_STRING_dup(const ASN1_OCTET_STRING *x) {
|
||||
return ASN1_STRING_dup(x);
|
||||
}
|
||||
|
||||
int ASN1_OCTET_STRING_cmp(const ASN1_OCTET_STRING *a,
|
||||
const ASN1_OCTET_STRING *b) {
|
||||
return ASN1_STRING_cmp(a, b);
|
||||
}
|
||||
|
||||
int ASN1_OCTET_STRING_set(ASN1_OCTET_STRING *x, const unsigned char *d,
|
||||
int len) {
|
||||
return ASN1_STRING_set(x, d, len);
|
||||
}
|
||||
+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 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>
|
||||
|
||||
+24
-61
@@ -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>
|
||||
|
||||
@@ -60,6 +18,8 @@
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
#include <iterator>
|
||||
|
||||
#include <CCryptoBoringSSL_err.h>
|
||||
#include <CCryptoBoringSSL_mem.h>
|
||||
#include <CCryptoBoringSSL_obj.h>
|
||||
@@ -159,7 +119,8 @@ static int table_cmp(const ASN1_STRING_TABLE *a, const ASN1_STRING_TABLE *b) {
|
||||
}
|
||||
|
||||
static int table_cmp_void(const void *a, const void *b) {
|
||||
return table_cmp(a, b);
|
||||
return table_cmp(reinterpret_cast<const ASN1_STRING_TABLE *>(a),
|
||||
reinterpret_cast<const ASN1_STRING_TABLE *>(b));
|
||||
}
|
||||
|
||||
static uint32_t table_hash(const ASN1_STRING_TABLE *tbl) {
|
||||
@@ -169,9 +130,9 @@ static uint32_t table_hash(const ASN1_STRING_TABLE *tbl) {
|
||||
static const ASN1_STRING_TABLE *asn1_string_table_get(int nid) {
|
||||
ASN1_STRING_TABLE key;
|
||||
key.nid = nid;
|
||||
const ASN1_STRING_TABLE *tbl =
|
||||
bsearch(&key, tbl_standard, OPENSSL_ARRAY_SIZE(tbl_standard),
|
||||
sizeof(ASN1_STRING_TABLE), table_cmp_void);
|
||||
const ASN1_STRING_TABLE *tbl = reinterpret_cast<ASN1_STRING_TABLE *>(
|
||||
bsearch(&key, tbl_standard, std::size(tbl_standard),
|
||||
sizeof(ASN1_STRING_TABLE), table_cmp_void));
|
||||
if (tbl != NULL) {
|
||||
return tbl;
|
||||
}
|
||||
@@ -198,6 +159,7 @@ int ASN1_STRING_TABLE_add(int nid, long minsize, long maxsize,
|
||||
int ret = 0;
|
||||
CRYPTO_MUTEX_lock_write(&string_tables_lock);
|
||||
|
||||
ASN1_STRING_TABLE *tbl = NULL;
|
||||
if (string_tables == NULL) {
|
||||
string_tables = lh_ASN1_STRING_TABLE_new(table_hash, table_cmp);
|
||||
if (string_tables == NULL) {
|
||||
@@ -214,7 +176,8 @@ int ASN1_STRING_TABLE_add(int nid, long minsize, long maxsize,
|
||||
}
|
||||
}
|
||||
|
||||
ASN1_STRING_TABLE *tbl = OPENSSL_malloc(sizeof(ASN1_STRING_TABLE));
|
||||
tbl = reinterpret_cast<ASN1_STRING_TABLE *>(
|
||||
OPENSSL_malloc(sizeof(ASN1_STRING_TABLE)));
|
||||
if (tbl == NULL) {
|
||||
goto err;
|
||||
}
|
||||
@@ -241,5 +204,5 @@ void ASN1_STRING_TABLE_cleanup(void) {}
|
||||
void asn1_get_string_table_for_testing(const ASN1_STRING_TABLE **out_ptr,
|
||||
size_t *out_len) {
|
||||
*out_ptr = tbl_standard;
|
||||
*out_len = OPENSSL_ARRAY_SIZE(tbl_standard);
|
||||
*out_len = std::size(tbl_standard);
|
||||
}
|
||||
+57
-76
@@ -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
|
||||
@@ -257,3 +222,19 @@ int ASN1_TIME_to_posix(const ASN1_TIME *t, int64_t *out_time) {
|
||||
}
|
||||
return OPENSSL_tm_to_posix(&tm, out_time);
|
||||
}
|
||||
|
||||
int asn1_parse_time(CBS *cbs, ASN1_TIME *out, int allow_utc_timezone_offset) {
|
||||
if (CBS_peek_asn1_tag(cbs, CBS_ASN1_UTCTIME)) {
|
||||
return asn1_parse_utc_time(cbs, out, /*tag=*/0, allow_utc_timezone_offset);
|
||||
}
|
||||
return asn1_parse_generalized_time(cbs, out, /*tag=*/0);
|
||||
}
|
||||
|
||||
int asn1_marshal_time(CBB *cbb, const ASN1_TIME *in) {
|
||||
if (in->type != V_ASN1_UTCTIME && in->type != V_ASN1_GENERALIZEDTIME) {
|
||||
OPENSSL_PUT_ERROR(ASN1, ASN1_R_WRONG_TYPE);
|
||||
return 0;
|
||||
}
|
||||
return asn1_marshal_octet_string(cbb, in,
|
||||
static_cast<CBS_ASN1_TAG>(in->type));
|
||||
}
|
||||
@@ -1,214 +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_asn1.h>
|
||||
|
||||
#include <assert.h>
|
||||
|
||||
#include <CCryptoBoringSSL_err.h>
|
||||
#include <CCryptoBoringSSL_mem.h>
|
||||
#include <CCryptoBoringSSL_obj.h>
|
||||
|
||||
#include "internal.h"
|
||||
|
||||
|
||||
int ASN1_TYPE_get(const ASN1_TYPE *a) {
|
||||
switch (a->type) {
|
||||
case V_ASN1_NULL:
|
||||
case V_ASN1_BOOLEAN:
|
||||
return a->type;
|
||||
case V_ASN1_OBJECT:
|
||||
return a->value.object != NULL ? a->type : 0;
|
||||
default:
|
||||
return a->value.asn1_string != NULL ? a->type : 0;
|
||||
}
|
||||
}
|
||||
|
||||
const void *asn1_type_value_as_pointer(const ASN1_TYPE *a) {
|
||||
switch (a->type) {
|
||||
case V_ASN1_NULL:
|
||||
return NULL;
|
||||
case V_ASN1_BOOLEAN:
|
||||
return a->value.boolean ? (void *)0xff : NULL;
|
||||
case V_ASN1_OBJECT:
|
||||
return a->value.object;
|
||||
default:
|
||||
return a->value.asn1_string;
|
||||
}
|
||||
}
|
||||
|
||||
void asn1_type_set0_string(ASN1_TYPE *a, ASN1_STRING *str) {
|
||||
// |ASN1_STRING| types are almost the same as |ASN1_TYPE| types, except that
|
||||
// the negative flag is not reflected into |ASN1_TYPE|.
|
||||
int type = str->type;
|
||||
if (type == V_ASN1_NEG_INTEGER) {
|
||||
type = V_ASN1_INTEGER;
|
||||
} else if (type == V_ASN1_NEG_ENUMERATED) {
|
||||
type = V_ASN1_ENUMERATED;
|
||||
}
|
||||
|
||||
// These types are not |ASN1_STRING| types and use a different
|
||||
// representation when stored in |ASN1_TYPE|.
|
||||
assert(type != V_ASN1_NULL && type != V_ASN1_OBJECT &&
|
||||
type != V_ASN1_BOOLEAN);
|
||||
ASN1_TYPE_set(a, type, str);
|
||||
}
|
||||
|
||||
void asn1_type_cleanup(ASN1_TYPE *a) {
|
||||
switch (a->type) {
|
||||
case V_ASN1_NULL:
|
||||
a->value.ptr = NULL;
|
||||
break;
|
||||
case V_ASN1_BOOLEAN:
|
||||
a->value.boolean = ASN1_BOOLEAN_NONE;
|
||||
break;
|
||||
case V_ASN1_OBJECT:
|
||||
ASN1_OBJECT_free(a->value.object);
|
||||
a->value.object = NULL;
|
||||
break;
|
||||
default:
|
||||
ASN1_STRING_free(a->value.asn1_string);
|
||||
a->value.asn1_string = NULL;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
void ASN1_TYPE_set(ASN1_TYPE *a, int type, void *value) {
|
||||
asn1_type_cleanup(a);
|
||||
a->type = type;
|
||||
switch (type) {
|
||||
case V_ASN1_NULL:
|
||||
a->value.ptr = NULL;
|
||||
break;
|
||||
case V_ASN1_BOOLEAN:
|
||||
a->value.boolean = value ? ASN1_BOOLEAN_TRUE : ASN1_BOOLEAN_FALSE;
|
||||
break;
|
||||
case V_ASN1_OBJECT:
|
||||
a->value.object = value;
|
||||
break;
|
||||
default:
|
||||
a->value.asn1_string = value;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
int ASN1_TYPE_set1(ASN1_TYPE *a, int type, const void *value) {
|
||||
if (!value || (type == V_ASN1_BOOLEAN)) {
|
||||
void *p = (void *)value;
|
||||
ASN1_TYPE_set(a, type, p);
|
||||
} else if (type == V_ASN1_OBJECT) {
|
||||
ASN1_OBJECT *odup;
|
||||
odup = OBJ_dup(value);
|
||||
if (!odup) {
|
||||
return 0;
|
||||
}
|
||||
ASN1_TYPE_set(a, type, odup);
|
||||
} else {
|
||||
ASN1_STRING *sdup;
|
||||
sdup = ASN1_STRING_dup(value);
|
||||
if (!sdup) {
|
||||
return 0;
|
||||
}
|
||||
ASN1_TYPE_set(a, type, sdup);
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
|
||||
// Returns 0 if they are equal, != 0 otherwise.
|
||||
int ASN1_TYPE_cmp(const ASN1_TYPE *a, const ASN1_TYPE *b) {
|
||||
int result = -1;
|
||||
|
||||
if (!a || !b || a->type != b->type) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
switch (a->type) {
|
||||
case V_ASN1_OBJECT:
|
||||
result = OBJ_cmp(a->value.object, b->value.object);
|
||||
break;
|
||||
case V_ASN1_NULL:
|
||||
result = 0; // They do not have content.
|
||||
break;
|
||||
case V_ASN1_BOOLEAN:
|
||||
result = a->value.boolean - b->value.boolean;
|
||||
break;
|
||||
case V_ASN1_INTEGER:
|
||||
case V_ASN1_ENUMERATED:
|
||||
case V_ASN1_BIT_STRING:
|
||||
case V_ASN1_OCTET_STRING:
|
||||
case V_ASN1_SEQUENCE:
|
||||
case V_ASN1_SET:
|
||||
case V_ASN1_NUMERICSTRING:
|
||||
case V_ASN1_PRINTABLESTRING:
|
||||
case V_ASN1_T61STRING:
|
||||
case V_ASN1_VIDEOTEXSTRING:
|
||||
case V_ASN1_IA5STRING:
|
||||
case V_ASN1_UTCTIME:
|
||||
case V_ASN1_GENERALIZEDTIME:
|
||||
case V_ASN1_GRAPHICSTRING:
|
||||
case V_ASN1_VISIBLESTRING:
|
||||
case V_ASN1_GENERALSTRING:
|
||||
case V_ASN1_UNIVERSALSTRING:
|
||||
case V_ASN1_BMPSTRING:
|
||||
case V_ASN1_UTF8STRING:
|
||||
case V_ASN1_OTHER:
|
||||
default:
|
||||
result = ASN1_STRING_cmp(a->value.asn1_string, b->value.asn1_string);
|
||||
break;
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
@@ -0,0 +1,390 @@
|
||||
// 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 <assert.h>
|
||||
|
||||
#include <CCryptoBoringSSL_bytestring.h>
|
||||
#include <CCryptoBoringSSL_err.h>
|
||||
#include <CCryptoBoringSSL_mem.h>
|
||||
#include <CCryptoBoringSSL_obj.h>
|
||||
|
||||
#include "internal.h"
|
||||
|
||||
|
||||
int ASN1_TYPE_get(const ASN1_TYPE *a) {
|
||||
switch (a->type) {
|
||||
case V_ASN1_NULL:
|
||||
case V_ASN1_BOOLEAN:
|
||||
return a->type;
|
||||
case V_ASN1_OBJECT:
|
||||
return a->value.object != NULL ? a->type : 0;
|
||||
default:
|
||||
return a->value.asn1_string != NULL ? a->type : 0;
|
||||
}
|
||||
}
|
||||
|
||||
const void *asn1_type_value_as_pointer(const ASN1_TYPE *a) {
|
||||
switch (a->type) {
|
||||
case V_ASN1_NULL:
|
||||
return NULL;
|
||||
case V_ASN1_BOOLEAN:
|
||||
return a->value.boolean ? (void *)0xff : NULL;
|
||||
case V_ASN1_OBJECT:
|
||||
return a->value.object;
|
||||
default:
|
||||
return a->value.asn1_string;
|
||||
}
|
||||
}
|
||||
|
||||
void asn1_type_set0_string(ASN1_TYPE *a, ASN1_STRING *str) {
|
||||
// |ASN1_STRING| types are almost the same as |ASN1_TYPE| types, except that
|
||||
// the negative flag is not reflected into |ASN1_TYPE|.
|
||||
int type = str->type;
|
||||
if (type == V_ASN1_NEG_INTEGER) {
|
||||
type = V_ASN1_INTEGER;
|
||||
} else if (type == V_ASN1_NEG_ENUMERATED) {
|
||||
type = V_ASN1_ENUMERATED;
|
||||
}
|
||||
|
||||
// These types are not |ASN1_STRING| types and use a different
|
||||
// representation when stored in |ASN1_TYPE|.
|
||||
assert(type != V_ASN1_NULL && type != V_ASN1_OBJECT &&
|
||||
type != V_ASN1_BOOLEAN);
|
||||
ASN1_TYPE_set(a, type, str);
|
||||
}
|
||||
|
||||
void asn1_type_cleanup(ASN1_TYPE *a) {
|
||||
switch (a->type) {
|
||||
case V_ASN1_NULL:
|
||||
a->value.ptr = NULL;
|
||||
break;
|
||||
case V_ASN1_BOOLEAN:
|
||||
a->value.boolean = ASN1_BOOLEAN_NONE;
|
||||
break;
|
||||
case V_ASN1_OBJECT:
|
||||
ASN1_OBJECT_free(a->value.object);
|
||||
a->value.object = NULL;
|
||||
break;
|
||||
default:
|
||||
ASN1_STRING_free(a->value.asn1_string);
|
||||
a->value.asn1_string = NULL;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
void ASN1_TYPE_set(ASN1_TYPE *a, int type, void *value) {
|
||||
asn1_type_cleanup(a);
|
||||
a->type = type;
|
||||
switch (type) {
|
||||
case V_ASN1_NULL:
|
||||
a->value.ptr = NULL;
|
||||
break;
|
||||
case V_ASN1_BOOLEAN:
|
||||
a->value.boolean = value ? ASN1_BOOLEAN_TRUE : ASN1_BOOLEAN_FALSE;
|
||||
break;
|
||||
case V_ASN1_OBJECT:
|
||||
a->value.object = reinterpret_cast<ASN1_OBJECT *>(value);
|
||||
break;
|
||||
default:
|
||||
a->value.asn1_string = reinterpret_cast<ASN1_STRING *>(value);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
int ASN1_TYPE_set1(ASN1_TYPE *a, int type, const void *value) {
|
||||
if (!value || (type == V_ASN1_BOOLEAN)) {
|
||||
void *p = (void *)value;
|
||||
ASN1_TYPE_set(a, type, p);
|
||||
} else if (type == V_ASN1_OBJECT) {
|
||||
ASN1_OBJECT *odup;
|
||||
odup = OBJ_dup(reinterpret_cast<const ASN1_OBJECT *>(value));
|
||||
if (!odup) {
|
||||
return 0;
|
||||
}
|
||||
ASN1_TYPE_set(a, type, odup);
|
||||
} else {
|
||||
ASN1_STRING *sdup;
|
||||
sdup = ASN1_STRING_dup(reinterpret_cast<const ASN1_STRING *>(value));
|
||||
if (!sdup) {
|
||||
return 0;
|
||||
}
|
||||
ASN1_TYPE_set(a, type, sdup);
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
|
||||
// Returns 0 if they are equal, != 0 otherwise.
|
||||
int ASN1_TYPE_cmp(const ASN1_TYPE *a, const ASN1_TYPE *b) {
|
||||
int result = -1;
|
||||
|
||||
if (!a || !b || a->type != b->type) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
switch (a->type) {
|
||||
case V_ASN1_OBJECT:
|
||||
result = OBJ_cmp(a->value.object, b->value.object);
|
||||
break;
|
||||
case V_ASN1_NULL:
|
||||
result = 0; // They do not have content.
|
||||
break;
|
||||
case V_ASN1_BOOLEAN:
|
||||
result = a->value.boolean - b->value.boolean;
|
||||
break;
|
||||
case V_ASN1_INTEGER:
|
||||
case V_ASN1_ENUMERATED:
|
||||
case V_ASN1_BIT_STRING:
|
||||
case V_ASN1_OCTET_STRING:
|
||||
case V_ASN1_SEQUENCE:
|
||||
case V_ASN1_SET:
|
||||
case V_ASN1_NUMERICSTRING:
|
||||
case V_ASN1_PRINTABLESTRING:
|
||||
case V_ASN1_T61STRING:
|
||||
case V_ASN1_VIDEOTEXSTRING:
|
||||
case V_ASN1_IA5STRING:
|
||||
case V_ASN1_UTCTIME:
|
||||
case V_ASN1_GENERALIZEDTIME:
|
||||
case V_ASN1_GRAPHICSTRING:
|
||||
case V_ASN1_VISIBLESTRING:
|
||||
case V_ASN1_GENERALSTRING:
|
||||
case V_ASN1_UNIVERSALSTRING:
|
||||
case V_ASN1_BMPSTRING:
|
||||
case V_ASN1_UTF8STRING:
|
||||
case V_ASN1_OTHER:
|
||||
default:
|
||||
result = ASN1_STRING_cmp(a->value.asn1_string, b->value.asn1_string);
|
||||
break;
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
int asn1_parse_any(CBS *cbs, ASN1_TYPE *out) {
|
||||
CBS_ASN1_TAG tag;
|
||||
CBS elem;
|
||||
size_t header_len;
|
||||
if (!CBS_get_any_asn1_element(cbs, &elem, &tag, &header_len)) {
|
||||
OPENSSL_PUT_ERROR(ASN1, ASN1_R_DECODE_ERROR);
|
||||
return 0;
|
||||
}
|
||||
|
||||
// Handle the non-string types.
|
||||
if (tag == CBS_ASN1_OBJECT) {
|
||||
bssl::UniquePtr<ASN1_OBJECT> obj(asn1_parse_object(&elem, /*tag=*/0));
|
||||
if (obj == nullptr) {
|
||||
return 0;
|
||||
}
|
||||
ASN1_TYPE_set(out, V_ASN1_OBJECT, obj.release());
|
||||
return 1;
|
||||
}
|
||||
if (tag == CBS_ASN1_NULL) {
|
||||
if (CBS_len(&elem) != header_len) {
|
||||
OPENSSL_PUT_ERROR(ASN1, ASN1_R_DECODE_ERROR);
|
||||
return 0;
|
||||
}
|
||||
ASN1_TYPE_set(out, V_ASN1_NULL, nullptr);
|
||||
return 1;
|
||||
}
|
||||
if (tag == CBS_ASN1_BOOLEAN) {
|
||||
int b;
|
||||
if (!CBS_get_asn1_bool(&elem, &b)) {
|
||||
OPENSSL_PUT_ERROR(ASN1, ASN1_R_DECODE_ERROR);
|
||||
return 0;
|
||||
}
|
||||
// V_ASN1_BOOLEAN will interpret the pointer as null for false and any
|
||||
// arbitrary non-null pointer for true.
|
||||
ASN1_TYPE_set(out, V_ASN1_BOOLEAN, b ? out : nullptr);
|
||||
return 1;
|
||||
}
|
||||
|
||||
// All other cases are handled identically to the string-based ANY parser.
|
||||
bssl::UniquePtr<ASN1_STRING> str(ASN1_STRING_new());
|
||||
if (str == nullptr || !asn1_parse_any_as_string(&elem, str.get())) {
|
||||
return 0;
|
||||
}
|
||||
asn1_type_set0_string(out, str.release());
|
||||
return 1;
|
||||
}
|
||||
|
||||
int asn1_parse_any_as_string(CBS *cbs, ASN1_STRING *out) {
|
||||
CBS_ASN1_TAG tag;
|
||||
CBS elem;
|
||||
size_t header_len;
|
||||
if (!CBS_get_any_asn1_element(cbs, &elem, &tag, &header_len)) {
|
||||
OPENSSL_PUT_ERROR(ASN1, ASN1_R_DECODE_ERROR);
|
||||
return 0;
|
||||
}
|
||||
|
||||
// Reject unexpectedly constructed or primitive universal types, rather than
|
||||
// encoding them as an opaque |V_ASN1_OTHER|. As of X.680 (02/2021), tag
|
||||
// numbers 0-36 have been allocated, except 15. Of these, only 8 (EXTERNAL),
|
||||
// 11 (EMBEDDED PDV), 16 (SEQUENCE), 17 (SET), and 29 (CHARACTER STRING) are
|
||||
// constructed.
|
||||
const CBS_ASN1_TAG tag_class = (tag & CBS_ASN1_CLASS_MASK);
|
||||
const CBS_ASN1_TAG number = tag & CBS_ASN1_TAG_NUMBER_MASK;
|
||||
if (tag_class == CBS_ASN1_UNIVERSAL && number <= 36 && number != 15) {
|
||||
const bool is_constructed = (tag & CBS_ASN1_CONSTRUCTED) != 0;
|
||||
if (number == V_ASN1_EXTERNAL || number == 11 /* EMBEDDED PDV */ ||
|
||||
number == V_ASN1_SEQUENCE || number == V_ASN1_SET ||
|
||||
number == 29 /* CHARACTER STRING*/) {
|
||||
if (!is_constructed) {
|
||||
OPENSSL_PUT_ERROR(ASN1, ASN1_R_TYPE_NOT_CONSTRUCTED);
|
||||
return 0;
|
||||
}
|
||||
} else {
|
||||
if (is_constructed) {
|
||||
OPENSSL_PUT_ERROR(ASN1, ASN1_R_TYPE_NOT_PRIMITIVE);
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Historically, parsing high universal tag numbers made OpenSSL's
|
||||
// |ASN1_STRING| representation ambiguous. We've since fixed this with
|
||||
// |V_ASN1_OTHER| but, for now, continue to enforce the limit.
|
||||
if (tag_class == CBS_ASN1_UNIVERSAL && number > V_ASN1_MAX_UNIVERSAL) {
|
||||
OPENSSL_PUT_ERROR(ASN1, ASN1_R_DECODE_ERROR);
|
||||
return 0;
|
||||
}
|
||||
|
||||
// These types are just parsed as |V_ASN1_OTHER| here. Check the contents
|
||||
// before the generic |V_ASN1_OTHER| path.
|
||||
CBS body = elem;
|
||||
BSSL_CHECK(CBS_skip(&body, header_len));
|
||||
switch (tag) {
|
||||
case CBS_ASN1_OBJECT:
|
||||
if (!CBS_is_valid_asn1_oid(&body)) {
|
||||
OPENSSL_PUT_ERROR(ASN1, ASN1_R_INVALID_OBJECT_ENCODING);
|
||||
return 0;
|
||||
}
|
||||
break;
|
||||
case CBS_ASN1_NULL:
|
||||
if (CBS_len(&body) != 0) {
|
||||
OPENSSL_PUT_ERROR(ASN1, ASN1_R_NULL_IS_WRONG_LENGTH);
|
||||
return 0;
|
||||
}
|
||||
break;
|
||||
case CBS_ASN1_BOOLEAN: {
|
||||
uint8_t v;
|
||||
if (!CBS_get_u8(&body, &v) || CBS_len(&body) != 0) {
|
||||
OPENSSL_PUT_ERROR(ASN1, ASN1_R_BOOLEAN_IS_WRONG_LENGTH);
|
||||
return 0;
|
||||
}
|
||||
if (v != 0 && v != 0xff) {
|
||||
OPENSSL_PUT_ERROR(ASN1, ASN1_R_DECODE_ERROR);
|
||||
return 0;
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
switch (tag) {
|
||||
case CBS_ASN1_INTEGER:
|
||||
return asn1_parse_integer(&elem, out, tag);
|
||||
case CBS_ASN1_ENUMERATED:
|
||||
return asn1_parse_enumerated(&elem, out, tag);
|
||||
case CBS_ASN1_BITSTRING:
|
||||
return asn1_parse_bit_string(&elem, out, tag);
|
||||
case CBS_ASN1_UNIVERSALSTRING:
|
||||
return asn1_parse_universal_string(&elem, out, tag);
|
||||
case CBS_ASN1_BMPSTRING:
|
||||
return asn1_parse_bmp_string(&elem, out, tag);
|
||||
case CBS_ASN1_UTF8STRING:
|
||||
return asn1_parse_utf8_string(&elem, out, tag);
|
||||
case CBS_ASN1_UTCTIME:
|
||||
// TODO(crbug.com/42290221): Reject timezone offsets here. We have no
|
||||
// known cases where UTCTime inside ANY needs accept invalid timezones.
|
||||
return asn1_parse_utc_time(&elem, out, tag, /*allow_timezone_offset=*/1);
|
||||
case CBS_ASN1_GENERALIZEDTIME:
|
||||
return asn1_parse_generalized_time(&elem, out, tag);
|
||||
case CBS_ASN1_OCTETSTRING:
|
||||
case CBS_ASN1_T61STRING:
|
||||
case CBS_ASN1_IA5STRING:
|
||||
case CBS_ASN1_NUMERICSTRING:
|
||||
case CBS_ASN1_PRINTABLESTRING:
|
||||
case CBS_ASN1_VIDEOTEXSTRING:
|
||||
case CBS_ASN1_GRAPHICSTRING:
|
||||
case CBS_ASN1_VISIBLESTRING:
|
||||
case CBS_ASN1_GENERALSTRING:
|
||||
// T61String is parsed as Latin-1, so all byte strings are valid. The
|
||||
// others we currently do not enforce.
|
||||
//
|
||||
// TODO(crbug.com/42290290): Enforce the encoding of the other string
|
||||
// types.
|
||||
if (!asn1_parse_octet_string(&elem, out, tag)) {
|
||||
return 0;
|
||||
}
|
||||
out->type = static_cast<int>(tag);
|
||||
return 1;
|
||||
default:
|
||||
// All unrecognized types, or types that cannot be represented as
|
||||
// |ASN1_STRING|, are represented as the whole element.
|
||||
if (!ASN1_STRING_set(out, CBS_data(&elem), CBS_len(&elem))) {
|
||||
return 0;
|
||||
}
|
||||
if (tag == CBS_ASN1_SEQUENCE) {
|
||||
out->type = V_ASN1_SEQUENCE;
|
||||
} else if (tag == CBS_ASN1_SET) {
|
||||
out->type = V_ASN1_SET;
|
||||
} else {
|
||||
out->type = V_ASN1_OTHER;
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
|
||||
int asn1_marshal_any(CBB *out, const ASN1_TYPE *in) {
|
||||
switch (in->type) {
|
||||
case V_ASN1_OBJECT:
|
||||
return asn1_marshal_object(out, in->value.object, /*tag=*/0);
|
||||
case V_ASN1_NULL:
|
||||
return CBB_add_asn1_element(out, CBS_ASN1_NULL, nullptr, 0);
|
||||
case V_ASN1_BOOLEAN:
|
||||
return CBB_add_asn1_bool(out, in->value.boolean != ASN1_BOOLEAN_FALSE);
|
||||
case V_ASN1_INTEGER:
|
||||
case V_ASN1_ENUMERATED:
|
||||
return asn1_marshal_integer(out, in->value.integer,
|
||||
static_cast<CBS_ASN1_TAG>(in->type));
|
||||
case V_ASN1_BIT_STRING:
|
||||
return asn1_marshal_bit_string(out, in->value.bit_string, /*tag=*/0);
|
||||
case V_ASN1_OCTET_STRING:
|
||||
case V_ASN1_NUMERICSTRING:
|
||||
case V_ASN1_PRINTABLESTRING:
|
||||
case V_ASN1_T61STRING:
|
||||
case V_ASN1_VIDEOTEXSTRING:
|
||||
case V_ASN1_IA5STRING:
|
||||
case V_ASN1_UTCTIME:
|
||||
case V_ASN1_GENERALIZEDTIME:
|
||||
case V_ASN1_GRAPHICSTRING:
|
||||
case V_ASN1_VISIBLESTRING:
|
||||
case V_ASN1_GENERALSTRING:
|
||||
case V_ASN1_UNIVERSALSTRING:
|
||||
case V_ASN1_BMPSTRING:
|
||||
case V_ASN1_UTF8STRING:
|
||||
return asn1_marshal_octet_string(out, in->value.asn1_string,
|
||||
static_cast<CBS_ASN1_TAG>(in->type));
|
||||
case V_ASN1_SEQUENCE:
|
||||
case V_ASN1_SET:
|
||||
case V_ASN1_OTHER:
|
||||
// These three types store the whole TLV as contents.
|
||||
return CBB_add_bytes(out, ASN1_STRING_get0_data(in->value.asn1_string),
|
||||
ASN1_STRING_length(in->value.asn1_string));
|
||||
default:
|
||||
// |ASN1_TYPE|s can have type -1 when default-constructed.
|
||||
OPENSSL_PUT_ERROR(ASN1, ASN1_R_WRONG_TYPE);
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
@@ -1,183 +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_asn1.h>
|
||||
#include <CCryptoBoringSSL_bytestring.h>
|
||||
#include <CCryptoBoringSSL_err.h>
|
||||
#include <CCryptoBoringSSL_mem.h>
|
||||
#include <CCryptoBoringSSL_posix_time.h>
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <time.h>
|
||||
|
||||
#include "internal.h"
|
||||
|
||||
int asn1_utctime_to_tm(struct tm *tm, const ASN1_UTCTIME *d,
|
||||
int allow_timezone_offset) {
|
||||
if (d->type != V_ASN1_UTCTIME) {
|
||||
return 0;
|
||||
}
|
||||
CBS cbs;
|
||||
CBS_init(&cbs, d->data, (size_t)d->length);
|
||||
if (!CBS_parse_utc_time(&cbs, tm, allow_timezone_offset)) {
|
||||
return 0;
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
|
||||
int ASN1_UTCTIME_check(const ASN1_UTCTIME *d) {
|
||||
return asn1_utctime_to_tm(NULL, d, /*allow_timezone_offset=*/1);
|
||||
}
|
||||
|
||||
int ASN1_UTCTIME_set_string(ASN1_UTCTIME *s, const char *str) {
|
||||
// Although elsewhere we allow timezone offsets with UTCTime, to be compatible
|
||||
// with some existing misissued certificates, this function is used to
|
||||
// construct new certificates and can be stricter.
|
||||
size_t len = strlen(str);
|
||||
CBS cbs;
|
||||
CBS_init(&cbs, (const uint8_t *)str, len);
|
||||
if (!CBS_parse_utc_time(&cbs, /*out_tm=*/NULL,
|
||||
/*allow_timezone_offset=*/0)) {
|
||||
return 0;
|
||||
}
|
||||
if (s != NULL) {
|
||||
if (!ASN1_STRING_set(s, str, len)) {
|
||||
return 0;
|
||||
}
|
||||
s->type = V_ASN1_UTCTIME;
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
|
||||
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) {
|
||||
struct tm data;
|
||||
if (!OPENSSL_posix_to_tm(posix_time, &data)) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
if (offset_day || offset_sec) {
|
||||
if (!OPENSSL_gmtime_adj(&data, offset_day, offset_sec)) {
|
||||
return NULL;
|
||||
}
|
||||
}
|
||||
|
||||
if (data.tm_year < 50 || data.tm_year >= 150) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
char buf[14];
|
||||
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.
|
||||
}
|
||||
|
||||
int free_s = 0;
|
||||
if (s == NULL) {
|
||||
free_s = 1;
|
||||
s = ASN1_UTCTIME_new();
|
||||
if (s == NULL) {
|
||||
return NULL;
|
||||
}
|
||||
}
|
||||
|
||||
if (!ASN1_STRING_set(s, buf, strlen(buf))) {
|
||||
if (free_s) {
|
||||
ASN1_UTCTIME_free(s);
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
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;
|
||||
}
|
||||
@@ -0,0 +1,125 @@
|
||||
// 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>
|
||||
#include <CCryptoBoringSSL_err.h>
|
||||
#include <CCryptoBoringSSL_mem.h>
|
||||
#include <CCryptoBoringSSL_posix_time.h>
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <time.h>
|
||||
|
||||
#include "internal.h"
|
||||
|
||||
int asn1_utctime_to_tm(struct tm *tm, const ASN1_UTCTIME *d,
|
||||
int allow_timezone_offset) {
|
||||
if (d->type != V_ASN1_UTCTIME) {
|
||||
return 0;
|
||||
}
|
||||
CBS cbs;
|
||||
CBS_init(&cbs, d->data, (size_t)d->length);
|
||||
if (!CBS_parse_utc_time(&cbs, tm, allow_timezone_offset)) {
|
||||
return 0;
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
|
||||
int asn1_parse_utc_time(CBS *cbs, ASN1_UTCTIME *out, CBS_ASN1_TAG tag,
|
||||
int allow_timezone_offset) {
|
||||
tag = tag == 0 ? CBS_ASN1_UTCTIME : tag;
|
||||
CBS child;
|
||||
if (!CBS_get_asn1(cbs, &child, tag) ||
|
||||
!CBS_parse_utc_time(&child, nullptr, allow_timezone_offset)) {
|
||||
OPENSSL_PUT_ERROR(ASN1, ASN1_R_DECODE_ERROR);
|
||||
return 0;
|
||||
}
|
||||
if (!ASN1_STRING_set(out, CBS_data(&child), CBS_len(&child))) {
|
||||
return 0;
|
||||
}
|
||||
out->type = V_ASN1_UTCTIME;
|
||||
return 1;
|
||||
}
|
||||
|
||||
int ASN1_UTCTIME_check(const ASN1_UTCTIME *d) {
|
||||
return asn1_utctime_to_tm(NULL, d, /*allow_timezone_offset=*/1);
|
||||
}
|
||||
|
||||
int ASN1_UTCTIME_set_string(ASN1_UTCTIME *s, const char *str) {
|
||||
// Although elsewhere we allow timezone offsets with UTCTime, to be compatible
|
||||
// with some existing misissued certificates, this function is used to
|
||||
// construct new certificates and can be stricter.
|
||||
size_t len = strlen(str);
|
||||
CBS cbs;
|
||||
CBS_init(&cbs, (const uint8_t *)str, len);
|
||||
if (!CBS_parse_utc_time(&cbs, /*out_tm=*/NULL,
|
||||
/*allow_timezone_offset=*/0)) {
|
||||
return 0;
|
||||
}
|
||||
if (s != NULL) {
|
||||
if (!ASN1_STRING_set(s, str, len)) {
|
||||
return 0;
|
||||
}
|
||||
s->type = V_ASN1_UTCTIME;
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
|
||||
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) {
|
||||
struct tm data;
|
||||
if (!OPENSSL_posix_to_tm(posix_time, &data)) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
if (offset_day || offset_sec) {
|
||||
if (!OPENSSL_gmtime_adj(&data, offset_day, offset_sec)) {
|
||||
return NULL;
|
||||
}
|
||||
}
|
||||
|
||||
if (data.tm_year < 50 || data.tm_year >= 150) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
char buf[14];
|
||||
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);
|
||||
// |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) {
|
||||
free_s = 1;
|
||||
s = ASN1_UTCTIME_new();
|
||||
if (s == NULL) {
|
||||
return NULL;
|
||||
}
|
||||
}
|
||||
|
||||
if (!ASN1_STRING_set(s, buf, strlen(buf))) {
|
||||
if (free_s) {
|
||||
ASN1_UTCTIME_free(s);
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
s->type = V_ASN1_UTCTIME;
|
||||
return s;
|
||||
}
|
||||
+95
-60
@@ -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>
|
||||
|
||||
@@ -271,7 +229,7 @@ ASN1_STRING *ASN1_STRING_dup(const ASN1_STRING *str) {
|
||||
}
|
||||
|
||||
int ASN1_STRING_set(ASN1_STRING *str, const void *_data, ossl_ssize_t len_s) {
|
||||
const char *data = _data;
|
||||
const char *data = reinterpret_cast<const char *>(_data);
|
||||
size_t len;
|
||||
if (len_s < 0) {
|
||||
if (data == NULL) {
|
||||
@@ -291,9 +249,9 @@ int ASN1_STRING_set(ASN1_STRING *str, const void *_data, ossl_ssize_t len_s) {
|
||||
if (str->length <= (int)len || str->data == NULL) {
|
||||
unsigned char *c = str->data;
|
||||
if (c == NULL) {
|
||||
str->data = OPENSSL_malloc(len + 1);
|
||||
str->data = reinterpret_cast<uint8_t *>(OPENSSL_malloc(len + 1));
|
||||
} else {
|
||||
str->data = OPENSSL_realloc(c, len + 1);
|
||||
str->data = reinterpret_cast<uint8_t *>(OPENSSL_realloc(c, len + 1));
|
||||
}
|
||||
|
||||
if (str->data == NULL) {
|
||||
@@ -315,7 +273,7 @@ int ASN1_STRING_set(ASN1_STRING *str, const void *_data, ossl_ssize_t len_s) {
|
||||
|
||||
void ASN1_STRING_set0(ASN1_STRING *str, void *data, int len) {
|
||||
OPENSSL_free(str->data);
|
||||
str->data = data;
|
||||
str->data = reinterpret_cast<uint8_t *>(data);
|
||||
str->length = len;
|
||||
}
|
||||
|
||||
@@ -337,11 +295,21 @@ ASN1_STRING *ASN1_STRING_type_new(int type) {
|
||||
return ret;
|
||||
}
|
||||
|
||||
void asn1_string_init(ASN1_STRING *str, int type) {
|
||||
OPENSSL_memset(str, 0, sizeof(ASN1_STRING));
|
||||
str->type = type;
|
||||
}
|
||||
|
||||
void asn1_string_cleanup(ASN1_STRING *str) {
|
||||
OPENSSL_free(str->data);
|
||||
str->data = nullptr;
|
||||
}
|
||||
|
||||
void ASN1_STRING_free(ASN1_STRING *str) {
|
||||
if (str == NULL) {
|
||||
return;
|
||||
}
|
||||
OPENSSL_free(str->data);
|
||||
asn1_string_cleanup(str);
|
||||
OPENSSL_free(str);
|
||||
}
|
||||
|
||||
@@ -395,3 +363,70 @@ unsigned char *ASN1_STRING_data(ASN1_STRING *str) { return str->data; }
|
||||
const unsigned char *ASN1_STRING_get0_data(const ASN1_STRING *str) {
|
||||
return str->data;
|
||||
}
|
||||
|
||||
int asn1_parse_octet_string(CBS *cbs, ASN1_STRING *out, CBS_ASN1_TAG tag) {
|
||||
tag = tag == 0 ? CBS_ASN1_OCTETSTRING : tag;
|
||||
CBS child;
|
||||
if (!CBS_get_asn1(cbs, &child, tag)) {
|
||||
OPENSSL_PUT_ERROR(ASN1, ASN1_R_DECODE_ERROR);
|
||||
return 0;
|
||||
}
|
||||
if (!ASN1_STRING_set(out, CBS_data(&child), CBS_len(&child))) {
|
||||
return 0;
|
||||
}
|
||||
out->type = V_ASN1_OCTET_STRING;
|
||||
return 1;
|
||||
}
|
||||
|
||||
int asn1_marshal_octet_string(CBB *out, const ASN1_STRING *in,
|
||||
CBS_ASN1_TAG tag) {
|
||||
tag = tag == 0 ? CBS_ASN1_OCTETSTRING : tag;
|
||||
return CBB_add_asn1_element(out, tag, ASN1_STRING_get0_data(in),
|
||||
ASN1_STRING_length(in));
|
||||
}
|
||||
|
||||
static int asn1_parse_character_string(CBS *cbs, ASN1_STRING *out,
|
||||
CBS_ASN1_TAG tag, int str_type,
|
||||
int (*get_char)(CBS *cbs, uint32_t *),
|
||||
int bad_char_err) {
|
||||
CBS child;
|
||||
if (!CBS_get_asn1(cbs, &child, tag)) {
|
||||
OPENSSL_PUT_ERROR(ASN1, ASN1_R_DECODE_ERROR);
|
||||
return 0;
|
||||
}
|
||||
CBS copy = child;
|
||||
while (CBS_len(©) != 0) {
|
||||
uint32_t c;
|
||||
if (!get_char(©, &c)) {
|
||||
OPENSSL_PUT_ERROR(ASN1, bad_char_err);
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
if (!ASN1_STRING_set(out, CBS_data(&child), CBS_len(&child))) {
|
||||
return 0;
|
||||
}
|
||||
out->type = str_type;
|
||||
return 1;
|
||||
}
|
||||
|
||||
int asn1_parse_bmp_string(CBS *cbs, ASN1_BMPSTRING *out, CBS_ASN1_TAG tag) {
|
||||
tag = tag == 0 ? CBS_ASN1_BMPSTRING : tag;
|
||||
return asn1_parse_character_string(cbs, out, tag, V_ASN1_BMPSTRING,
|
||||
&CBS_get_ucs2_be,
|
||||
ASN1_R_INVALID_BMPSTRING);
|
||||
}
|
||||
|
||||
int asn1_parse_universal_string(CBS *cbs, ASN1_UNIVERSALSTRING *out,
|
||||
CBS_ASN1_TAG tag) {
|
||||
tag = tag == 0 ? CBS_ASN1_UNIVERSALSTRING : tag;
|
||||
return asn1_parse_character_string(cbs, out, tag, V_ASN1_UNIVERSALSTRING,
|
||||
&CBS_get_utf32_be,
|
||||
ASN1_R_INVALID_UNIVERSALSTRING);
|
||||
}
|
||||
|
||||
int asn1_parse_utf8_string(CBS *cbs, ASN1_UNIVERSALSTRING *out,
|
||||
CBS_ASN1_TAG tag) {
|
||||
tag = tag == 0 ? CBS_ASN1_UTF8STRING : tag;
|
||||
return asn1_parse_character_string(cbs, out, tag, V_ASN1_UTF8STRING,
|
||||
&CBS_get_utf8, ASN1_R_INVALID_UTF8STRING);
|
||||
}
|
||||
@@ -1,103 +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_asn1.h>
|
||||
|
||||
|
||||
const char *ASN1_tag2str(int tag) {
|
||||
static const char *const tag2str[] = {
|
||||
"EOC",
|
||||
"BOOLEAN",
|
||||
"INTEGER",
|
||||
"BIT STRING",
|
||||
"OCTET STRING",
|
||||
"NULL",
|
||||
"OBJECT",
|
||||
"OBJECT DESCRIPTOR",
|
||||
"EXTERNAL",
|
||||
"REAL",
|
||||
"ENUMERATED",
|
||||
"<ASN1 11>",
|
||||
"UTF8STRING",
|
||||
"<ASN1 13>",
|
||||
"<ASN1 14>",
|
||||
"<ASN1 15>",
|
||||
"SEQUENCE",
|
||||
"SET",
|
||||
"NUMERICSTRING",
|
||||
"PRINTABLESTRING",
|
||||
"T61STRING",
|
||||
"VIDEOTEXSTRING",
|
||||
"IA5STRING",
|
||||
"UTCTIME",
|
||||
"GENERALIZEDTIME",
|
||||
"GRAPHICSTRING",
|
||||
"VISIBLESTRING",
|
||||
"GENERALSTRING",
|
||||
"UNIVERSALSTRING",
|
||||
"<ASN1 29>",
|
||||
"BMPSTRING",
|
||||
};
|
||||
|
||||
if ((tag == V_ASN1_NEG_INTEGER) || (tag == V_ASN1_NEG_ENUMERATED)) {
|
||||
tag &= ~V_ASN1_NEG;
|
||||
}
|
||||
|
||||
if (tag < 0 || tag > 30) {
|
||||
return "(unknown)";
|
||||
}
|
||||
return tag2str[tag];
|
||||
}
|
||||
@@ -0,0 +1,61 @@
|
||||
// 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>
|
||||
|
||||
|
||||
const char *ASN1_tag2str(int tag) {
|
||||
static const char *const tag2str[] = {
|
||||
"EOC",
|
||||
"BOOLEAN",
|
||||
"INTEGER",
|
||||
"BIT STRING",
|
||||
"OCTET STRING",
|
||||
"NULL",
|
||||
"OBJECT",
|
||||
"OBJECT DESCRIPTOR",
|
||||
"EXTERNAL",
|
||||
"REAL",
|
||||
"ENUMERATED",
|
||||
"<ASN1 11>",
|
||||
"UTF8STRING",
|
||||
"<ASN1 13>",
|
||||
"<ASN1 14>",
|
||||
"<ASN1 15>",
|
||||
"SEQUENCE",
|
||||
"SET",
|
||||
"NUMERICSTRING",
|
||||
"PRINTABLESTRING",
|
||||
"T61STRING",
|
||||
"VIDEOTEXSTRING",
|
||||
"IA5STRING",
|
||||
"UTCTIME",
|
||||
"GENERALIZEDTIME",
|
||||
"GRAPHICSTRING",
|
||||
"VISIBLESTRING",
|
||||
"GENERALSTRING",
|
||||
"UNIVERSALSTRING",
|
||||
"<ASN1 29>",
|
||||
"BMPSTRING",
|
||||
};
|
||||
|
||||
if ((tag == V_ASN1_NEG_INTEGER) || (tag == V_ASN1_NEG_ENUMERATED)) {
|
||||
tag &= ~V_ASN1_NEG;
|
||||
}
|
||||
|
||||
if (tag < 0 || tag > 30) {
|
||||
return "(unknown)";
|
||||
}
|
||||
return tag2str[tag];
|
||||
}
|
||||
@@ -1,98 +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_asn1.h>
|
||||
|
||||
#include <CCryptoBoringSSL_err.h>
|
||||
#include <CCryptoBoringSSL_mem.h>
|
||||
|
||||
|
||||
ASN1_STRING *ASN1_item_pack(void *obj, const ASN1_ITEM *it, ASN1_STRING **out) {
|
||||
uint8_t *new_data = NULL;
|
||||
int len = ASN1_item_i2d(obj, &new_data, it);
|
||||
if (len <= 0) {
|
||||
OPENSSL_PUT_ERROR(ASN1, ASN1_R_ENCODE_ERROR);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
ASN1_STRING *ret = NULL;
|
||||
if (out == NULL || *out == NULL) {
|
||||
ret = ASN1_STRING_new();
|
||||
if (ret == NULL) {
|
||||
OPENSSL_free(new_data);
|
||||
return NULL;
|
||||
}
|
||||
} else {
|
||||
ret = *out;
|
||||
}
|
||||
|
||||
ASN1_STRING_set0(ret, new_data, len);
|
||||
if (out != NULL) {
|
||||
*out = ret;
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
void *ASN1_item_unpack(const ASN1_STRING *oct, const ASN1_ITEM *it) {
|
||||
const unsigned char *p = oct->data;
|
||||
void *ret = ASN1_item_d2i(NULL, &p, oct->length, it);
|
||||
if (ret == NULL || p != oct->data + oct->length) {
|
||||
OPENSSL_PUT_ERROR(ASN1, ASN1_R_DECODE_ERROR);
|
||||
ASN1_item_free(ret, it);
|
||||
return NULL;
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
@@ -0,0 +1,56 @@
|
||||
// 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_err.h>
|
||||
#include <CCryptoBoringSSL_mem.h>
|
||||
|
||||
|
||||
ASN1_STRING *ASN1_item_pack(void *obj, const ASN1_ITEM *it, ASN1_STRING **out) {
|
||||
uint8_t *new_data = NULL;
|
||||
int len = ASN1_item_i2d(reinterpret_cast<ASN1_VALUE *>(obj), &new_data, it);
|
||||
if (len <= 0) {
|
||||
OPENSSL_PUT_ERROR(ASN1, ASN1_R_ENCODE_ERROR);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
ASN1_STRING *ret = NULL;
|
||||
if (out == NULL || *out == NULL) {
|
||||
ret = ASN1_STRING_new();
|
||||
if (ret == NULL) {
|
||||
OPENSSL_free(new_data);
|
||||
return NULL;
|
||||
}
|
||||
} else {
|
||||
ret = *out;
|
||||
}
|
||||
|
||||
ASN1_STRING_set0(ret, new_data, len);
|
||||
if (out != NULL) {
|
||||
*out = ret;
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
void *ASN1_item_unpack(const ASN1_STRING *oct, const ASN1_ITEM *it) {
|
||||
const unsigned char *p = oct->data;
|
||||
void *ret = ASN1_item_d2i(NULL, &p, oct->length, it);
|
||||
if (ret == NULL || p != oct->data + oct->length) {
|
||||
OPENSSL_PUT_ERROR(ASN1, ASN1_R_DECODE_ERROR);
|
||||
ASN1_item_free(reinterpret_cast<ASN1_VALUE *>(ret), it);
|
||||
return NULL;
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
@@ -1,105 +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_asn1.h>
|
||||
|
||||
#include <CCryptoBoringSSL_bio.h>
|
||||
|
||||
int i2a_ASN1_INTEGER(BIO *bp, const ASN1_INTEGER *a) {
|
||||
int i, n = 0;
|
||||
static const char *h = "0123456789ABCDEF";
|
||||
char buf[2];
|
||||
|
||||
if (a == NULL) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (a->type & V_ASN1_NEG) {
|
||||
if (BIO_write(bp, "-", 1) != 1) {
|
||||
goto err;
|
||||
}
|
||||
n = 1;
|
||||
}
|
||||
|
||||
if (a->length == 0) {
|
||||
if (BIO_write(bp, "00", 2) != 2) {
|
||||
goto err;
|
||||
}
|
||||
n += 2;
|
||||
} else {
|
||||
for (i = 0; i < a->length; i++) {
|
||||
if ((i != 0) && (i % 35 == 0)) {
|
||||
if (BIO_write(bp, "\\\n", 2) != 2) {
|
||||
goto err;
|
||||
}
|
||||
n += 2;
|
||||
}
|
||||
buf[0] = h[((unsigned char)a->data[i] >> 4) & 0x0f];
|
||||
buf[1] = h[((unsigned char)a->data[i]) & 0x0f];
|
||||
if (BIO_write(bp, buf, 2) != 2) {
|
||||
goto err;
|
||||
}
|
||||
n += 2;
|
||||
}
|
||||
}
|
||||
return n;
|
||||
err:
|
||||
return -1;
|
||||
}
|
||||
|
||||
int i2a_ASN1_ENUMERATED(BIO *bp, const ASN1_ENUMERATED *a) {
|
||||
return i2a_ASN1_INTEGER(bp, a);
|
||||
}
|
||||
@@ -0,0 +1,63 @@
|
||||
// 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_bio.h>
|
||||
|
||||
int i2a_ASN1_INTEGER(BIO *bp, const ASN1_INTEGER *a) {
|
||||
int i, n = 0;
|
||||
static const char *h = "0123456789ABCDEF";
|
||||
char buf[2];
|
||||
|
||||
if (a == NULL) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (a->type & V_ASN1_NEG) {
|
||||
if (BIO_write(bp, "-", 1) != 1) {
|
||||
goto err;
|
||||
}
|
||||
n = 1;
|
||||
}
|
||||
|
||||
if (a->length == 0) {
|
||||
if (BIO_write(bp, "00", 2) != 2) {
|
||||
goto err;
|
||||
}
|
||||
n += 2;
|
||||
} else {
|
||||
for (i = 0; i < a->length; i++) {
|
||||
if ((i != 0) && (i % 35 == 0)) {
|
||||
if (BIO_write(bp, "\\\n", 2) != 2) {
|
||||
goto err;
|
||||
}
|
||||
n += 2;
|
||||
}
|
||||
buf[0] = h[((unsigned char)a->data[i] >> 4) & 0x0f];
|
||||
buf[1] = h[((unsigned char)a->data[i]) & 0x0f];
|
||||
if (BIO_write(bp, buf, 2) != 2) {
|
||||
goto err;
|
||||
}
|
||||
n += 2;
|
||||
}
|
||||
}
|
||||
return n;
|
||||
err:
|
||||
return -1;
|
||||
}
|
||||
|
||||
int i2a_ASN1_ENUMERATED(BIO *bp, const ASN1_ENUMERATED *a) {
|
||||
return i2a_ASN1_INTEGER(bp, a);
|
||||
}
|
||||
@@ -1,94 +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_asn1.h>
|
||||
|
||||
#include <CCryptoBoringSSL_bio.h>
|
||||
|
||||
int i2a_ASN1_STRING(BIO *bp, const ASN1_STRING *a, int type) {
|
||||
int i, n = 0;
|
||||
static const char *h = "0123456789ABCDEF";
|
||||
char buf[2];
|
||||
|
||||
if (a == NULL) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (a->length == 0) {
|
||||
if (BIO_write(bp, "0", 1) != 1) {
|
||||
goto err;
|
||||
}
|
||||
n = 1;
|
||||
} else {
|
||||
for (i = 0; i < a->length; i++) {
|
||||
if ((i != 0) && (i % 35 == 0)) {
|
||||
if (BIO_write(bp, "\\\n", 2) != 2) {
|
||||
goto err;
|
||||
}
|
||||
n += 2;
|
||||
}
|
||||
buf[0] = h[((unsigned char)a->data[i] >> 4) & 0x0f];
|
||||
buf[1] = h[((unsigned char)a->data[i]) & 0x0f];
|
||||
if (BIO_write(bp, buf, 2) != 2) {
|
||||
goto err;
|
||||
}
|
||||
n += 2;
|
||||
}
|
||||
}
|
||||
return n;
|
||||
err:
|
||||
return -1;
|
||||
}
|
||||
@@ -0,0 +1,52 @@
|
||||
// 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_bio.h>
|
||||
|
||||
int i2a_ASN1_STRING(BIO *bp, const ASN1_STRING *a, int type) {
|
||||
int i, n = 0;
|
||||
static const char *h = "0123456789ABCDEF";
|
||||
char buf[2];
|
||||
|
||||
if (a == NULL) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (a->length == 0) {
|
||||
if (BIO_write(bp, "0", 1) != 1) {
|
||||
goto err;
|
||||
}
|
||||
n = 1;
|
||||
} else {
|
||||
for (i = 0; i < a->length; i++) {
|
||||
if ((i != 0) && (i % 35 == 0)) {
|
||||
if (BIO_write(bp, "\\\n", 2) != 2) {
|
||||
goto err;
|
||||
}
|
||||
n += 2;
|
||||
}
|
||||
buf[0] = h[((unsigned char)a->data[i] >> 4) & 0x0f];
|
||||
buf[1] = h[((unsigned char)a->data[i]) & 0x0f];
|
||||
if (BIO_write(bp, buf, 2) != 2) {
|
||||
goto err;
|
||||
}
|
||||
n += 2;
|
||||
}
|
||||
}
|
||||
return n;
|
||||
err:
|
||||
return -1;
|
||||
}
|
||||
@@ -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>
|
||||
|
||||
@@ -92,7 +48,8 @@ OPENSSL_EXPORT int OPENSSL_gmtime_diff(int *out_days, int *out_secs,
|
||||
const struct tm *from,
|
||||
const struct tm *to);
|
||||
|
||||
// Internal ASN1 structures and functions: not for application use
|
||||
|
||||
// Object identifiers.
|
||||
|
||||
// These are used internally in the ASN1_OBJECT to keep track of
|
||||
// whether the names and data need to be free()ed
|
||||
@@ -116,6 +73,130 @@ struct asn1_object_st {
|
||||
|
||||
ASN1_OBJECT *ASN1_OBJECT_new(void);
|
||||
|
||||
// asn1_parse_object parses a DER-encoded ASN.1 OBJECT IDENTIFIER from |cbs| and
|
||||
// write the result to |out|. If |tag| is non-zero, the value is implicitly
|
||||
// tagged with |tag|. On success, it returns a newly-allocated |ASN1_OBJECT|
|
||||
// with the result and advances |cbs| past the parsed element.
|
||||
//
|
||||
// TODO(crbug.com/boringssl/414361735): This should return a bssl::UniquePtr,
|
||||
// but cannot until it is made C++ linkage.
|
||||
ASN1_OBJECT *asn1_parse_object(CBS *cbs, CBS_ASN1_TAG tag);
|
||||
|
||||
// asn1_marshal_object marshals |in| as a DER-encoded, ASN.1 OBJECT IDENTIFIER
|
||||
// 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_object(CBB *out, const ASN1_OBJECT *in, CBS_ASN1_TAG tag);
|
||||
|
||||
|
||||
// Strings.
|
||||
|
||||
// asn1_is_printable returns one if |value| is a valid Unicode codepoint for an
|
||||
// ASN.1 PrintableString, and zero otherwise.
|
||||
int asn1_is_printable(uint32_t value);
|
||||
|
||||
// asn1_string_init initializes |str|, which may be uninitialized, with type
|
||||
// |type|.
|
||||
void asn1_string_init(ASN1_STRING *str, int type);
|
||||
|
||||
// asn1_string_cleanup releases memory associated with |str|'s value, without
|
||||
// freeing |str| itself.
|
||||
void asn1_string_cleanup(ASN1_STRING *str);
|
||||
|
||||
// asn1_bit_string_length returns the number of bytes in |str| and sets
|
||||
// |*out_padding_bits| to the number of padding bits.
|
||||
//
|
||||
// This function should be used instead of |ASN1_STRING_length| to correctly
|
||||
// handle the non-|ASN1_STRING_FLAG_BITS_LEFT| case.
|
||||
int asn1_bit_string_length(const ASN1_BIT_STRING *str,
|
||||
uint8_t *out_padding_bits);
|
||||
|
||||
// The following functions parse a DER-encoded ASN.1 value of the specified
|
||||
// type from |cbs| and write the result to |*out|. If |tag| is non-zero, the
|
||||
// value is implicitly tagged with |tag|. On success, they return one and
|
||||
// advance |cbs| past the parsed element. On entry, |*out| must contain an
|
||||
// |ASN1_STRING| in some valid state.
|
||||
int asn1_parse_bit_string(CBS *cbs, ASN1_BIT_STRING *out, CBS_ASN1_TAG tag);
|
||||
int asn1_parse_integer(CBS *cbs, ASN1_INTEGER *out, CBS_ASN1_TAG tag);
|
||||
int asn1_parse_enumerated(CBS *cbs, ASN1_ENUMERATED *out, CBS_ASN1_TAG tag);
|
||||
int asn1_parse_octet_string(CBS *cbs, ASN1_STRING *out, CBS_ASN1_TAG tag);
|
||||
int asn1_parse_bmp_string(CBS *cbs, ASN1_BMPSTRING *out, CBS_ASN1_TAG tag);
|
||||
int asn1_parse_universal_string(CBS *cbs, ASN1_UNIVERSALSTRING *out,
|
||||
CBS_ASN1_TAG tag);
|
||||
int asn1_parse_utf8_string(CBS *cbs, ASN1_UNIVERSALSTRING *out,
|
||||
CBS_ASN1_TAG tag);
|
||||
int asn1_parse_generalized_time(CBS *cbs, ASN1_GENERALIZEDTIME *out,
|
||||
CBS_ASN1_TAG tag);
|
||||
int asn1_parse_utc_time(CBS *cbs, ASN1_UTCTIME *out, CBS_ASN1_TAG tag,
|
||||
int allow_timezone_offset);
|
||||
|
||||
// asn1_parse_bit_string_with_bad_length behaves like |asn1_parse_bit_string|
|
||||
// but tolerates BER non-minimal, definite lengths.
|
||||
int asn1_parse_bit_string_with_bad_length(CBS *cbs, ASN1_BIT_STRING *out);
|
||||
|
||||
// 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|. This can also be used to marshal an
|
||||
// ASN.1 ENUMERATED value by overriding the tag.
|
||||
int asn1_marshal_integer(CBB *out, const ASN1_INTEGER *in, CBS_ASN1_TAG tag);
|
||||
|
||||
// asn1_marshal_octet_string marshals |in| as a DER-encoded, ASN.1 OCTET 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|.
|
||||
//
|
||||
// This function may be used to marshal other string-based universal types whose
|
||||
// encoding is that of an implicitly-tagged OCTET STRING, e.g. UTF8String.
|
||||
int asn1_marshal_octet_string(CBB *out, const ASN1_STRING *in,
|
||||
CBS_ASN1_TAG tag);
|
||||
|
||||
OPENSSL_EXPORT int asn1_utctime_to_tm(struct tm *tm, const ASN1_UTCTIME *d,
|
||||
int allow_timezone_offset);
|
||||
OPENSSL_EXPORT int asn1_generalizedtime_to_tm(struct tm *tm,
|
||||
const ASN1_GENERALIZEDTIME *d);
|
||||
|
||||
int asn1_parse_time(CBS *cbs, ASN1_TIME *out, int allow_utc_timezone_offset);
|
||||
int asn1_marshal_time(CBB *cbb, const ASN1_TIME *in);
|
||||
|
||||
|
||||
// The ASN.1 ANY type.
|
||||
|
||||
// asn1_type_value_as_pointer returns |a|'s value in pointer form. This is
|
||||
// usually the value object but, for BOOLEAN values, is 0 or 0xff cast to
|
||||
// a pointer.
|
||||
const void *asn1_type_value_as_pointer(const ASN1_TYPE *a);
|
||||
|
||||
// asn1_type_set0_string sets |a|'s value to the object represented by |str| and
|
||||
// takes ownership of |str|.
|
||||
void asn1_type_set0_string(ASN1_TYPE *a, ASN1_STRING *str);
|
||||
|
||||
// asn1_type_cleanup releases memory associated with |a|'s value, without
|
||||
// freeing |a| itself.
|
||||
void asn1_type_cleanup(ASN1_TYPE *a);
|
||||
|
||||
// asn1_parse_any parses a DER-encoded ASN.1 value of any type from |cbs| and
|
||||
// writes the result to |*out|. On success, it advances |cbs| past the parsed
|
||||
// element and returns one. On entry, |*out| must contain an |ASN1_TYPE| in some
|
||||
// valid state.
|
||||
int asn1_parse_any(CBS *cbs, ASN1_TYPE *out);
|
||||
|
||||
// asn1_parse_any_as_string behaves like |asn1_parse_any| but represents the
|
||||
// value as an |ASN1_STRING|. Types which are not represented with
|
||||
// |ASN1_STRING|, such as |ASN1_OBJECT|, are represented with type
|
||||
// |V_ASN1_OTHER|.
|
||||
int asn1_parse_any_as_string(CBS *cbs, ASN1_STRING *out);
|
||||
|
||||
// asn1_marshal_any marshals |in| as a DER-encoded ASN.1 value and writes the
|
||||
// result to |out|. It returns one on success and zeron on error.
|
||||
int asn1_marshal_any(CBB *out, const ASN1_TYPE *in);
|
||||
|
||||
|
||||
// Support structures for the template-based encoder.
|
||||
|
||||
// ASN1_ENCODING is used to save the received encoding of an ASN.1 type. This
|
||||
// avoids problems with invalid encodings that break signatures.
|
||||
typedef struct ASN1_ENCODING_st {
|
||||
@@ -123,16 +204,8 @@ typedef struct ASN1_ENCODING_st {
|
||||
uint8_t *enc;
|
||||
// len is the length of |enc|. If zero, there is no saved encoding.
|
||||
size_t len;
|
||||
// buf, if non-NULL, is the |CRYPTO_BUFFER| that |enc| points into. If NULL,
|
||||
// |enc| must be released with |OPENSSL_free|.
|
||||
CRYPTO_BUFFER *buf;
|
||||
} ASN1_ENCODING;
|
||||
|
||||
OPENSSL_EXPORT int asn1_utctime_to_tm(struct tm *tm, const ASN1_UTCTIME *d,
|
||||
int allow_timezone_offset);
|
||||
OPENSSL_EXPORT int asn1_generalizedtime_to_tm(struct tm *tm,
|
||||
const ASN1_GENERALIZEDTIME *d);
|
||||
|
||||
int ASN1_item_ex_new(ASN1_VALUE **pval, const ASN1_ITEM *it);
|
||||
void ASN1_item_ex_free(ASN1_VALUE **pval, const ASN1_ITEM *it);
|
||||
|
||||
@@ -141,14 +214,12 @@ void ASN1_template_free(ASN1_VALUE **pval, const ASN1_TEMPLATE *tt);
|
||||
// ASN1_item_ex_d2i parses |len| bytes from |*in| as a structure of type |it|
|
||||
// and writes the result to |*pval|. If |tag| is non-negative, |it| is
|
||||
// implicitly tagged with the tag specified by |tag| and |aclass|. If |opt| is
|
||||
// non-zero, the value is optional. If |buf| is non-NULL, |*in| must point into
|
||||
// |buf|.
|
||||
// non-zero, the value is optional.
|
||||
//
|
||||
// This function returns one and advances |*in| if an object was successfully
|
||||
// parsed, -1 if an optional value was successfully skipped, and zero on error.
|
||||
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);
|
||||
const ASN1_ITEM *it, int tag, int aclass, char opt);
|
||||
|
||||
// ASN1_item_ex_i2d encodes |*pval| as a value of type |it| to |out| under the
|
||||
// i2d output convention. It returns a non-zero length on success and -1 on
|
||||
@@ -194,36 +265,11 @@ int asn1_enc_restore(int *len, unsigned char **out, ASN1_VALUE **pval,
|
||||
// returns one on success and zero on error. If |buf| is non-NULL, |in| must
|
||||
// point into |buf|.
|
||||
int asn1_enc_save(ASN1_VALUE **pval, const uint8_t *in, size_t inlen,
|
||||
const ASN1_ITEM *it, CRYPTO_BUFFER *buf);
|
||||
const ASN1_ITEM *it);
|
||||
|
||||
// asn1_encoding_clear clears the cached encoding in |enc|.
|
||||
void asn1_encoding_clear(ASN1_ENCODING *enc);
|
||||
|
||||
// asn1_type_value_as_pointer returns |a|'s value in pointer form. This is
|
||||
// usually the value object but, for BOOLEAN values, is 0 or 0xff cast to
|
||||
// a pointer.
|
||||
const void *asn1_type_value_as_pointer(const ASN1_TYPE *a);
|
||||
|
||||
// asn1_type_set0_string sets |a|'s value to the object represented by |str| and
|
||||
// takes ownership of |str|.
|
||||
void asn1_type_set0_string(ASN1_TYPE *a, ASN1_STRING *str);
|
||||
|
||||
// asn1_type_cleanup releases memory associated with |a|'s value, without
|
||||
// freeing |a| itself.
|
||||
void asn1_type_cleanup(ASN1_TYPE *a);
|
||||
|
||||
// asn1_is_printable returns one if |value| is a valid Unicode codepoint for an
|
||||
// ASN.1 PrintableString, and zero otherwise.
|
||||
int asn1_is_printable(uint32_t value);
|
||||
|
||||
// asn1_bit_string_length returns the number of bytes in |str| and sets
|
||||
// |*out_padding_bits| to the number of padding bits.
|
||||
//
|
||||
// This function should be used instead of |ASN1_STRING_length| to correctly
|
||||
// handle the non-|ASN1_STRING_FLAG_BITS_LEFT| case.
|
||||
int asn1_bit_string_length(const ASN1_BIT_STRING *str,
|
||||
uint8_t *out_padding_bits);
|
||||
|
||||
typedef struct {
|
||||
int nid;
|
||||
long minsize;
|
||||
@@ -243,8 +289,18 @@ typedef ASN1_VALUE *ASN1_d2i_func(ASN1_VALUE **a, const unsigned char **in,
|
||||
long length);
|
||||
typedef int ASN1_i2d_func(ASN1_VALUE *a, unsigned char **in);
|
||||
|
||||
typedef int ASN1_ex_d2i(ASN1_VALUE **pval, const unsigned char **in, long len,
|
||||
const ASN1_ITEM *it, int opt, ASN1_TLC *ctx);
|
||||
// An ASN1_ex_parse function should parse a value from |cbs| and set |*pval| to
|
||||
// the result. It should return one on success and zero on failure. If |opt| is
|
||||
// non-zero, the field may be optional. If an optional element is missing, the
|
||||
// function should return one and consume zero bytes from |cbs|.
|
||||
//
|
||||
// If |opt| is non-zero, the function can assume that |*pval| is nullptr on
|
||||
// entry. Otherwise, |*pval| may either be nullptr, or the result of
|
||||
// |ASN1_ex_new_func|. The function may either write into the existing object,
|
||||
// if any, or unconditionally make a new one. (The existing object comes from
|
||||
// tasn_new.cc recursively filling in objects before parsing into them.)
|
||||
typedef int ASN1_ex_parse(ASN1_VALUE **pval, CBS *cbs, const ASN1_ITEM *it,
|
||||
int opt);
|
||||
|
||||
typedef int ASN1_ex_i2d(ASN1_VALUE **pval, unsigned char **out,
|
||||
const ASN1_ITEM *it);
|
||||
@@ -254,13 +310,65 @@ typedef void ASN1_ex_free_func(ASN1_VALUE **pval, const ASN1_ITEM *it);
|
||||
typedef struct ASN1_EXTERN_FUNCS_st {
|
||||
ASN1_ex_new_func *asn1_ex_new;
|
||||
ASN1_ex_free_func *asn1_ex_free;
|
||||
ASN1_ex_d2i *asn1_ex_d2i;
|
||||
ASN1_ex_parse *asn1_ex_parse;
|
||||
ASN1_ex_i2d *asn1_ex_i2d;
|
||||
} ASN1_EXTERN_FUNCS;
|
||||
|
||||
#define IMPLEMENT_EXTERN_ASN1_SIMPLE(name, new_func, free_func, parse_func, \
|
||||
i2d_func) \
|
||||
static int name##_new_cb(ASN1_VALUE **pval, const ASN1_ITEM *it) { \
|
||||
*pval = (ASN1_VALUE *)new_func(); \
|
||||
return *pval != nullptr; \
|
||||
} \
|
||||
\
|
||||
static void name##_free_cb(ASN1_VALUE **pval, const ASN1_ITEM *it) { \
|
||||
free_func((name *)*pval); \
|
||||
*pval = nullptr; \
|
||||
} \
|
||||
\
|
||||
static int name##_parse_cb(ASN1_VALUE **pval, CBS *cbs, const ASN1_ITEM *it, \
|
||||
int opt) { \
|
||||
if (opt && !CBS_peek_asn1_tag(cbs, CBS_ASN1_SEQUENCE)) { \
|
||||
return 1; \
|
||||
} \
|
||||
\
|
||||
if ((*pval == nullptr && !name##_new_cb(pval, it)) || \
|
||||
!parse_func(cbs, (name *)*pval)) { \
|
||||
return 0; \
|
||||
} \
|
||||
return 1; \
|
||||
} \
|
||||
\
|
||||
static int name##_i2d_cb(ASN1_VALUE **pval, unsigned char **out, \
|
||||
const ASN1_ITEM *it) { \
|
||||
return i2d_func((name *)*pval, out); \
|
||||
} \
|
||||
\
|
||||
static const ASN1_EXTERN_FUNCS name##_extern_funcs = { \
|
||||
name##_new_cb, name##_free_cb, name##_parse_cb, name##_i2d_cb}; \
|
||||
\
|
||||
IMPLEMENT_EXTERN_ASN1(name, name##_extern_funcs)
|
||||
|
||||
// ASN1_TIME is an |ASN1_ITEM| whose ASN.1 type is X.509 Time (RFC 5280) and C
|
||||
// type is |ASN1_TIME*|.
|
||||
DECLARE_ASN1_ITEM(ASN1_TIME)
|
||||
|
||||
// DIRECTORYSTRING is an |ASN1_ITEM| whose ASN.1 type is X.509 DirectoryString
|
||||
// (RFC 5280) and C type is |ASN1_STRING*|.
|
||||
DECLARE_ASN1_ITEM(DIRECTORYSTRING)
|
||||
|
||||
// DISPLAYTEXT is an |ASN1_ITEM| whose ASN.1 type is X.509 DisplayText (RFC
|
||||
// 5280) and C type is |ASN1_STRING*|.
|
||||
DECLARE_ASN1_ITEM(DISPLAYTEXT)
|
||||
|
||||
// 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
|
||||
+14
-14
@@ -1,16 +1,16 @@
|
||||
/* Copyright (c) 2022, Google Inc.
|
||||
*
|
||||
* Permission to use, copy, modify, and/or distribute this software for any
|
||||
* purpose with or without fee is hereby granted, provided that the above
|
||||
* copyright notice and this permission notice appear in all copies.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
|
||||
* WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
|
||||
* MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
|
||||
* SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
|
||||
* WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION
|
||||
* OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
|
||||
* CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. */
|
||||
// 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
|
||||
@@ -154,7 +154,7 @@ int OPENSSL_tm_to_posix(const struct tm *tm, int64_t *out) {
|
||||
}
|
||||
|
||||
int OPENSSL_posix_to_tm(int64_t time, struct tm *out_tm) {
|
||||
struct tm tmp_tm = {0};
|
||||
struct tm tmp_tm = {};
|
||||
if (!utc_from_posix_time(time, &tmp_tm.tm_year, &tmp_tm.tm_mon,
|
||||
&tmp_tm.tm_mday, &tmp_tm.tm_hour, &tmp_tm.tm_min,
|
||||
&tmp_tm.tm_sec)) {
|
||||
+241
-360
@@ -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>
|
||||
@@ -81,80 +39,56 @@ static int asn1_check_tlen(long *olen, int *otag, unsigned char *oclass,
|
||||
|
||||
static int asn1_template_ex_d2i(ASN1_VALUE **pval, const unsigned char **in,
|
||||
long len, const ASN1_TEMPLATE *tt, char opt,
|
||||
CRYPTO_BUFFER *buf, int depth);
|
||||
int depth);
|
||||
static int asn1_template_noexp_d2i(ASN1_VALUE **val, const unsigned char **in,
|
||||
long len, const ASN1_TEMPLATE *tt, char opt,
|
||||
CRYPTO_BUFFER *buf, int depth);
|
||||
static int asn1_ex_c2i(ASN1_VALUE **pval, const unsigned char *cont, long len,
|
||||
int utype, const ASN1_ITEM *it);
|
||||
int depth);
|
||||
static int asn1_d2i_ex_primitive(ASN1_VALUE **pval, const unsigned char **in,
|
||||
long len, const ASN1_ITEM *it, int tag,
|
||||
int aclass, char opt);
|
||||
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,
|
||||
};
|
||||
char opt, int depth);
|
||||
|
||||
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) {
|
||||
if (aclass != V_ASN1_UNIVERSAL) {
|
||||
return 0;
|
||||
}
|
||||
return tag == V_ASN1_OBJECT || tag == V_ASN1_NULL || tag == V_ASN1_BOOLEAN ||
|
||||
tag == V_ASN1_BIT_STRING || tag == V_ASN1_INTEGER ||
|
||||
tag == V_ASN1_ENUMERATED || tag == V_ASN1_OCTET_STRING ||
|
||||
tag == V_ASN1_NUMERICSTRING || tag == V_ASN1_PRINTABLESTRING ||
|
||||
tag == V_ASN1_T61STRING || tag == V_ASN1_VIDEOTEXSTRING ||
|
||||
tag == V_ASN1_IA5STRING || tag == V_ASN1_UTCTIME ||
|
||||
tag == V_ASN1_GENERALIZEDTIME || tag == V_ASN1_GRAPHICSTRING ||
|
||||
tag == V_ASN1_VISIBLESTRING || tag == V_ASN1_GENERALSTRING ||
|
||||
tag == V_ASN1_UNIVERSALSTRING || tag == V_ASN1_BMPSTRING ||
|
||||
tag == V_ASN1_UTF8STRING || tag == V_ASN1_SET ||
|
||||
tag == V_ASN1_SEQUENCE;
|
||||
}
|
||||
|
||||
// Macro to initialize and invalidate the cache
|
||||
|
||||
// Decode an ASN1 item, this currently behaves just like a standard 'd2i'
|
||||
// function. 'in' points to a buffer to read the data from, in future we
|
||||
// will have more advanced versions that can input data a piece at a time and
|
||||
@@ -164,7 +98,7 @@ ASN1_VALUE *ASN1_item_d2i(ASN1_VALUE **pval, const unsigned char **in, long len,
|
||||
const ASN1_ITEM *it) {
|
||||
ASN1_VALUE *ret = NULL;
|
||||
if (asn1_item_ex_d2i(&ret, in, len, it, /*tag=*/-1, /*aclass=*/0, /*opt=*/0,
|
||||
/*buf=*/NULL, /*depth=*/0) <= 0) {
|
||||
/*depth=*/0) <= 0) {
|
||||
// Clean up, in case the caller left a partial object.
|
||||
//
|
||||
// TODO(davidben): I don't think it can leave one, but the codepaths below
|
||||
@@ -194,7 +128,7 @@ ASN1_VALUE *ASN1_item_d2i(ASN1_VALUE **pval, const unsigned char **in, long len,
|
||||
|
||||
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) {
|
||||
char opt, int depth) {
|
||||
const ASN1_TEMPLATE *tt, *errtt = NULL;
|
||||
const unsigned char *p = NULL, *q;
|
||||
unsigned char oclass;
|
||||
@@ -206,10 +140,9 @@ static int asn1_item_ex_d2i(ASN1_VALUE **pval, const unsigned char **in,
|
||||
if (!pval) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (buf != NULL) {
|
||||
assert(CRYPTO_BUFFER_data(buf) <= *in &&
|
||||
*in + len <= CRYPTO_BUFFER_data(buf) + CRYPTO_BUFFER_len(buf));
|
||||
if (len < 0) {
|
||||
OPENSSL_PUT_ERROR(ASN1, ASN1_R_BUFFER_TOO_SMALL);
|
||||
goto err;
|
||||
}
|
||||
|
||||
// Bound |len| to comfortably fit in an int. Lengths in this module often
|
||||
@@ -234,11 +167,9 @@ static int asn1_item_ex_d2i(ASN1_VALUE **pval, const unsigned char **in,
|
||||
OPENSSL_PUT_ERROR(ASN1, ASN1_R_ILLEGAL_OPTIONS_ON_ITEM_TEMPLATE);
|
||||
goto err;
|
||||
}
|
||||
return asn1_template_ex_d2i(pval, in, len, it->templates, opt, buf,
|
||||
depth);
|
||||
return asn1_template_ex_d2i(pval, in, len, it->templates, opt, depth);
|
||||
}
|
||||
return asn1_d2i_ex_primitive(pval, in, len, it, tag, aclass, opt);
|
||||
break;
|
||||
|
||||
case ASN1_ITYPE_MSTRING:
|
||||
// It never makes sense for multi-strings to have implicit tagging, so
|
||||
@@ -282,8 +213,20 @@ static int asn1_item_ex_d2i(ASN1_VALUE **pval, const unsigned char **in,
|
||||
OPENSSL_PUT_ERROR(ASN1, ASN1_R_BAD_TEMPLATE);
|
||||
goto err;
|
||||
}
|
||||
const ASN1_EXTERN_FUNCS *ef = it->funcs;
|
||||
return ef->asn1_ex_d2i(pval, in, len, it, opt, NULL);
|
||||
const ASN1_EXTERN_FUNCS *ef =
|
||||
reinterpret_cast<const ASN1_EXTERN_FUNCS *>(it->funcs);
|
||||
CBS cbs;
|
||||
CBS_init(&cbs, *in, len);
|
||||
CBS copy = cbs;
|
||||
if (!ef->asn1_ex_parse(pval, &cbs, it, opt)) {
|
||||
goto err;
|
||||
}
|
||||
*in = CBS_data(&cbs);
|
||||
// Check whether the function skipped an optional element.
|
||||
//
|
||||
// TODO(crbug.com/42290418): Switch the rest of this function to
|
||||
// |asn1_ex_parse|'s calling convention.
|
||||
return CBS_len(&cbs) == CBS_len(©) ? -1 : 1;
|
||||
}
|
||||
|
||||
case ASN1_ITYPE_CHOICE: {
|
||||
@@ -294,7 +237,7 @@ static int asn1_item_ex_d2i(ASN1_VALUE **pval, const unsigned char **in,
|
||||
goto err;
|
||||
}
|
||||
|
||||
const ASN1_AUX *aux = it->funcs;
|
||||
const ASN1_AUX *aux = reinterpret_cast<const ASN1_AUX *>(it->funcs);
|
||||
ASN1_aux_cb *asn1_cb = aux != NULL ? aux->asn1_cb : NULL;
|
||||
if (asn1_cb && !asn1_cb(ASN1_OP_D2I_PRE, pval, it, NULL)) {
|
||||
goto auxerr;
|
||||
@@ -318,7 +261,7 @@ static int asn1_item_ex_d2i(ASN1_VALUE **pval, const unsigned char **in,
|
||||
for (i = 0, tt = it->templates; i < it->tcount; i++, tt++) {
|
||||
pchptr = asn1_get_field_ptr(pval, tt);
|
||||
// We mark field as OPTIONAL so its absence can be recognised.
|
||||
ret = asn1_template_ex_d2i(pchptr, &p, len, tt, 1, buf, depth);
|
||||
ret = asn1_template_ex_d2i(pchptr, &p, len, tt, 1, depth);
|
||||
// If field not present, try the next one
|
||||
if (ret == -1) {
|
||||
continue;
|
||||
@@ -379,7 +322,7 @@ static int asn1_item_ex_d2i(ASN1_VALUE **pval, const unsigned char **in,
|
||||
goto err;
|
||||
}
|
||||
|
||||
const ASN1_AUX *aux = it->funcs;
|
||||
const ASN1_AUX *aux = reinterpret_cast<const ASN1_AUX *>(it->funcs);
|
||||
ASN1_aux_cb *asn1_cb = aux != NULL ? aux->asn1_cb : NULL;
|
||||
if (asn1_cb && !asn1_cb(ASN1_OP_D2I_PRE, pval, it, NULL)) {
|
||||
goto auxerr;
|
||||
@@ -424,7 +367,7 @@ static int asn1_item_ex_d2i(ASN1_VALUE **pval, const unsigned char **in,
|
||||
}
|
||||
// attempt to read in field, allowing each to be OPTIONAL
|
||||
|
||||
ret = asn1_template_ex_d2i(pseqval, &p, len, seqtt, isopt, buf, depth);
|
||||
ret = asn1_template_ex_d2i(pseqval, &p, len, seqtt, isopt, depth);
|
||||
if (!ret) {
|
||||
errtt = seqtt;
|
||||
goto err;
|
||||
@@ -463,7 +406,7 @@ static int asn1_item_ex_d2i(ASN1_VALUE **pval, const unsigned char **in,
|
||||
}
|
||||
}
|
||||
// Save encoding
|
||||
if (!asn1_enc_save(pval, *in, p - *in, it, buf)) {
|
||||
if (!asn1_enc_save(pval, *in, p - *in, it)) {
|
||||
goto auxerr;
|
||||
}
|
||||
if (asn1_cb && !asn1_cb(ASN1_OP_D2I_POST, pval, it, NULL)) {
|
||||
@@ -489,10 +432,8 @@ err:
|
||||
}
|
||||
|
||||
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) {
|
||||
return asn1_item_ex_d2i(pval, in, len, it, tag, aclass, opt, buf,
|
||||
/*depth=*/0);
|
||||
const ASN1_ITEM *it, int tag, int aclass, char opt) {
|
||||
return asn1_item_ex_d2i(pval, in, len, it, tag, aclass, opt, /*depth=*/0);
|
||||
}
|
||||
|
||||
// Templates are handled with two separate functions. One handles any
|
||||
@@ -500,7 +441,7 @@ int ASN1_item_ex_d2i(ASN1_VALUE **pval, const unsigned char **in, long len,
|
||||
|
||||
static int asn1_template_ex_d2i(ASN1_VALUE **val, const unsigned char **in,
|
||||
long inlen, const ASN1_TEMPLATE *tt, char opt,
|
||||
CRYPTO_BUFFER *buf, int depth) {
|
||||
int depth) {
|
||||
int aclass;
|
||||
int ret;
|
||||
long len;
|
||||
@@ -532,7 +473,7 @@ static int asn1_template_ex_d2i(ASN1_VALUE **val, const unsigned char **in,
|
||||
return 0;
|
||||
}
|
||||
// We've found the field so it can't be OPTIONAL now
|
||||
ret = asn1_template_noexp_d2i(val, &p, len, tt, /*opt=*/0, buf, depth);
|
||||
ret = asn1_template_noexp_d2i(val, &p, len, tt, /*opt=*/0, depth);
|
||||
if (!ret) {
|
||||
OPENSSL_PUT_ERROR(ASN1, ASN1_R_NESTED_ASN1_ERROR);
|
||||
return 0;
|
||||
@@ -545,7 +486,7 @@ static int asn1_template_ex_d2i(ASN1_VALUE **val, const unsigned char **in,
|
||||
goto err;
|
||||
}
|
||||
} else {
|
||||
return asn1_template_noexp_d2i(val, in, inlen, tt, opt, buf, depth);
|
||||
return asn1_template_noexp_d2i(val, in, inlen, tt, opt, depth);
|
||||
}
|
||||
|
||||
*in = p;
|
||||
@@ -558,7 +499,7 @@ err:
|
||||
|
||||
static int asn1_template_noexp_d2i(ASN1_VALUE **val, const unsigned char **in,
|
||||
long len, const ASN1_TEMPLATE *tt, char opt,
|
||||
CRYPTO_BUFFER *buf, int depth) {
|
||||
int depth) {
|
||||
int aclass;
|
||||
int ret;
|
||||
const unsigned char *p;
|
||||
@@ -616,7 +557,8 @@ static int asn1_template_noexp_d2i(ASN1_VALUE **val, const unsigned char **in,
|
||||
const unsigned char *q = p;
|
||||
skfield = NULL;
|
||||
if (!asn1_item_ex_d2i(&skfield, &p, len, ASN1_ITEM_ptr(tt->item),
|
||||
/*tag=*/-1, /*aclass=*/0, /*opt=*/0, buf, depth)) {
|
||||
/*tag=*/-1, /*aclass=*/0, /*opt=*/0, depth)) {
|
||||
ASN1_item_ex_free(&skfield, ASN1_ITEM_ptr(tt->item));
|
||||
OPENSSL_PUT_ERROR(ASN1, ASN1_R_NESTED_ASN1_ERROR);
|
||||
goto err;
|
||||
}
|
||||
@@ -629,7 +571,7 @@ static int asn1_template_noexp_d2i(ASN1_VALUE **val, const unsigned char **in,
|
||||
} else if (flags & ASN1_TFLG_IMPTAG) {
|
||||
// IMPLICIT tagging
|
||||
ret = asn1_item_ex_d2i(val, &p, len, ASN1_ITEM_ptr(tt->item), tt->tag,
|
||||
aclass, opt, buf, depth);
|
||||
aclass, opt, depth);
|
||||
if (!ret) {
|
||||
OPENSSL_PUT_ERROR(ASN1, ASN1_R_NESTED_ASN1_ERROR);
|
||||
goto err;
|
||||
@@ -639,7 +581,7 @@ static int asn1_template_noexp_d2i(ASN1_VALUE **val, const unsigned char **in,
|
||||
} else {
|
||||
// Nothing special
|
||||
ret = asn1_item_ex_d2i(val, &p, len, ASN1_ITEM_ptr(tt->item), /*tag=*/-1,
|
||||
/*aclass=*/0, opt, buf, depth);
|
||||
/*aclass=*/0, opt, depth);
|
||||
if (!ret) {
|
||||
OPENSSL_PUT_ERROR(ASN1, ASN1_R_NESTED_ASN1_ERROR);
|
||||
goto err;
|
||||
@@ -656,272 +598,211 @@ err:
|
||||
return 0;
|
||||
}
|
||||
|
||||
// TODO(crbug.com/42290418): Switch the whole file to use a CBS-based calling
|
||||
// convention.
|
||||
static int asn1_d2i_ex_primitive_cbs(ASN1_VALUE **pval, CBS *cbs,
|
||||
const ASN1_ITEM *it, int tag, int aclass,
|
||||
char opt);
|
||||
|
||||
// asn1_d2i_ex_primitive returns one on success, zero on error, and -1 if an
|
||||
// optional value was skipped.
|
||||
static int asn1_d2i_ex_primitive(ASN1_VALUE **pval, const unsigned char **in,
|
||||
long inlen, const ASN1_ITEM *it, int tag,
|
||||
int aclass, char opt) {
|
||||
int ret = 0, utype;
|
||||
long plen;
|
||||
char cst;
|
||||
const unsigned char *p;
|
||||
const unsigned char *cont = NULL;
|
||||
long len;
|
||||
if (!pval) {
|
||||
OPENSSL_PUT_ERROR(ASN1, ASN1_R_ILLEGAL_NULL);
|
||||
return 0; // Should never happen
|
||||
CBS cbs;
|
||||
CBS_init(&cbs, *in, inlen);
|
||||
int ret = asn1_d2i_ex_primitive_cbs(pval, &cbs, it, tag, aclass, opt);
|
||||
if (ret <= 0) {
|
||||
return ret;
|
||||
}
|
||||
*in = CBS_data(&cbs);
|
||||
return 1;
|
||||
}
|
||||
|
||||
static ASN1_STRING *ensure_string(ASN1_VALUE **pval) {
|
||||
if (*pval) {
|
||||
return (ASN1_STRING *)*pval;
|
||||
}
|
||||
ASN1_STRING *str = ASN1_STRING_new();
|
||||
if (str == nullptr) {
|
||||
return nullptr;
|
||||
}
|
||||
*pval = (ASN1_VALUE *)str;
|
||||
return str;
|
||||
}
|
||||
|
||||
static int asn1_d2i_ex_primitive_cbs(ASN1_VALUE **pval, CBS *cbs,
|
||||
const ASN1_ITEM *it, int tag, int aclass,
|
||||
char opt) {
|
||||
// Historically, |it->funcs| for primitive types contained an
|
||||
// |ASN1_PRIMITIVE_FUNCS| table of callbacks.
|
||||
assert(it->funcs == NULL);
|
||||
|
||||
int utype;
|
||||
assert(it->itype == ASN1_ITYPE_PRIMITIVE || it->itype == ASN1_ITYPE_MSTRING);
|
||||
if (it->itype == ASN1_ITYPE_MSTRING) {
|
||||
// MSTRING passes utype in |tag|, normally used for implicit tagging.
|
||||
utype = tag;
|
||||
tag = -1;
|
||||
} else {
|
||||
utype = it->utype;
|
||||
}
|
||||
|
||||
if (utype == V_ASN1_ANY) {
|
||||
// If type is ANY need to figure out type from tag
|
||||
unsigned char oclass;
|
||||
// Handle ANY types.
|
||||
if (utype == V_ASN1_ANY || utype == V_ASN1_ANY_AS_STRING) {
|
||||
if (tag >= 0) {
|
||||
OPENSSL_PUT_ERROR(ASN1, ASN1_R_ILLEGAL_TAGGED_ANY);
|
||||
return 0;
|
||||
}
|
||||
if (opt) {
|
||||
OPENSSL_PUT_ERROR(ASN1, ASN1_R_ILLEGAL_OPTIONAL_ANY);
|
||||
return 0;
|
||||
}
|
||||
p = *in;
|
||||
ret = asn1_check_tlen(NULL, &utype, &oclass, NULL, &p, inlen, -1, 0, 0);
|
||||
if (!ret) {
|
||||
OPENSSL_PUT_ERROR(ASN1, ASN1_R_NESTED_ASN1_ERROR);
|
||||
return 0;
|
||||
}
|
||||
if (!is_supported_universal_type(utype, oclass)) {
|
||||
utype = V_ASN1_OTHER;
|
||||
if (opt && CBS_len(cbs) == 0) {
|
||||
return -1; // Omitted OPTIONAL value.
|
||||
}
|
||||
}
|
||||
if (tag == -1) {
|
||||
tag = utype;
|
||||
aclass = V_ASN1_UNIVERSAL;
|
||||
}
|
||||
p = *in;
|
||||
// Check header
|
||||
ret = asn1_check_tlen(&plen, NULL, NULL, &cst, &p, inlen, tag, aclass, opt);
|
||||
if (!ret) {
|
||||
OPENSSL_PUT_ERROR(ASN1, ASN1_R_NESTED_ASN1_ERROR);
|
||||
return 0;
|
||||
} else if (ret == -1) {
|
||||
return -1;
|
||||
}
|
||||
ret = 0;
|
||||
// SEQUENCE, SET and "OTHER" are left in encoded form
|
||||
if ((utype == V_ASN1_SEQUENCE) || (utype == V_ASN1_SET) ||
|
||||
(utype == V_ASN1_OTHER)) {
|
||||
// SEQUENCE and SET must be constructed
|
||||
if (utype != V_ASN1_OTHER && !cst) {
|
||||
OPENSSL_PUT_ERROR(ASN1, ASN1_R_TYPE_NOT_CONSTRUCTED);
|
||||
return 0;
|
||||
}
|
||||
|
||||
cont = *in;
|
||||
len = p - cont + plen;
|
||||
p += plen;
|
||||
} else if (cst) {
|
||||
// This parser historically supported BER constructed strings. We no
|
||||
// longer do and will gradually tighten this parser into a DER
|
||||
// parser. BER types should use |CBS_asn1_ber_to_der|.
|
||||
OPENSSL_PUT_ERROR(ASN1, ASN1_R_TYPE_NOT_PRIMITIVE);
|
||||
return 0;
|
||||
} else {
|
||||
cont = p;
|
||||
len = plen;
|
||||
p += plen;
|
||||
}
|
||||
|
||||
// We now have content length and type: translate into a structure
|
||||
if (!asn1_ex_c2i(pval, cont, len, utype, it)) {
|
||||
goto err;
|
||||
}
|
||||
|
||||
*in = p;
|
||||
ret = 1;
|
||||
err:
|
||||
return ret;
|
||||
}
|
||||
|
||||
// Translate ASN1 content octets into a structure
|
||||
|
||||
static int asn1_ex_c2i(ASN1_VALUE **pval, const unsigned char *cont, long len,
|
||||
int utype, const ASN1_ITEM *it) {
|
||||
ASN1_VALUE **opval = NULL;
|
||||
ASN1_STRING *stmp;
|
||||
ASN1_TYPE *typ = NULL;
|
||||
int ret = 0;
|
||||
ASN1_INTEGER **tint;
|
||||
|
||||
// Historically, |it->funcs| for primitive types contained an
|
||||
// |ASN1_PRIMITIVE_FUNCS| table of callbacks.
|
||||
assert(it->funcs == NULL);
|
||||
|
||||
// If ANY type clear type and set pointer to internal value
|
||||
if (it->utype == V_ASN1_ANY) {
|
||||
if (utype == V_ASN1_ANY) {
|
||||
ASN1_TYPE *typ;
|
||||
if (!*pval) {
|
||||
typ = ASN1_TYPE_new();
|
||||
if (typ == NULL) {
|
||||
goto err;
|
||||
return 0;
|
||||
}
|
||||
*pval = (ASN1_VALUE *)typ;
|
||||
} else {
|
||||
typ = (ASN1_TYPE *)*pval;
|
||||
}
|
||||
|
||||
if (utype != typ->type) {
|
||||
ASN1_TYPE_set(typ, utype, NULL);
|
||||
}
|
||||
opval = pval;
|
||||
pval = &typ->value.asn1_value;
|
||||
return asn1_parse_any(cbs, typ);
|
||||
}
|
||||
if (utype == V_ASN1_ANY_AS_STRING) {
|
||||
ASN1_STRING *str = ensure_string(pval);
|
||||
if (str == nullptr) {
|
||||
return 0;
|
||||
}
|
||||
return asn1_parse_any_as_string(cbs, str);
|
||||
}
|
||||
switch (utype) {
|
||||
case V_ASN1_OBJECT:
|
||||
if (!c2i_ASN1_OBJECT((ASN1_OBJECT **)pval, &cont, len)) {
|
||||
goto err;
|
||||
}
|
||||
break;
|
||||
|
||||
case V_ASN1_NULL:
|
||||
if (len) {
|
||||
// Convert the crypto/asn1 tag into a CBS one.
|
||||
if (tag == -1) {
|
||||
tag = utype;
|
||||
aclass = V_ASN1_UNIVERSAL;
|
||||
}
|
||||
|
||||
// All edge cases of |utype| should have been handled already. |utype| is now
|
||||
// either a primitive |ASN1_ITEM|, handled by |DECLARE_ASN1_ITEM|, or a
|
||||
// multistring option with a corresponding |B_ASN1_*| constant.
|
||||
assert(utype >= 0 && utype <= V_ASN1_MAX_UNIVERSAL);
|
||||
CBS_ASN1_TAG cbs_tag =
|
||||
(static_cast<CBS_ASN1_TAG>(aclass) << CBS_ASN1_TAG_SHIFT) |
|
||||
static_cast<CBS_ASN1_TAG>(tag);
|
||||
if (utype == V_ASN1_SEQUENCE || utype == V_ASN1_SET) {
|
||||
cbs_tag |= CBS_ASN1_CONSTRUCTED;
|
||||
}
|
||||
|
||||
if (opt && !CBS_peek_asn1_tag(cbs, cbs_tag)) {
|
||||
return -1; // Omitted OPTIONAL value.
|
||||
}
|
||||
|
||||
// Handle non-|ASN1_STRING| types.
|
||||
switch (utype) {
|
||||
case V_ASN1_OBJECT: {
|
||||
bssl::UniquePtr<ASN1_OBJECT> obj(asn1_parse_object(cbs, cbs_tag));
|
||||
if (obj == nullptr) {
|
||||
return 0;
|
||||
}
|
||||
ASN1_OBJECT_free((ASN1_OBJECT *)*pval);
|
||||
*pval = (ASN1_VALUE *)obj.release();
|
||||
return 1;
|
||||
}
|
||||
case V_ASN1_NULL: {
|
||||
CBS null;
|
||||
if (!CBS_get_asn1(cbs, &null, cbs_tag)) {
|
||||
OPENSSL_PUT_ERROR(ASN1, ASN1_R_DECODE_ERROR);
|
||||
return 0;
|
||||
}
|
||||
if (CBS_len(&null) != 0) {
|
||||
OPENSSL_PUT_ERROR(ASN1, ASN1_R_NULL_IS_WRONG_LENGTH);
|
||||
goto err;
|
||||
return 0;
|
||||
}
|
||||
*pval = (ASN1_VALUE *)1;
|
||||
break;
|
||||
|
||||
case V_ASN1_BOOLEAN:
|
||||
if (len != 1) {
|
||||
return 1;
|
||||
}
|
||||
case V_ASN1_BOOLEAN: {
|
||||
CBS child;
|
||||
if (!CBS_get_asn1(cbs, &child, cbs_tag)) {
|
||||
OPENSSL_PUT_ERROR(ASN1, ASN1_R_DECODE_ERROR);
|
||||
return 0;
|
||||
}
|
||||
// TODO(crbug.com/42290221): Reject invalid BOOLEAN encodings and just
|
||||
// call |CBS_get_asn1_bool|.
|
||||
if (CBS_len(&child) != 1) {
|
||||
OPENSSL_PUT_ERROR(ASN1, ASN1_R_BOOLEAN_IS_WRONG_LENGTH);
|
||||
goto err;
|
||||
} else {
|
||||
ASN1_BOOLEAN *tbool;
|
||||
tbool = (ASN1_BOOLEAN *)pval;
|
||||
*tbool = *cont;
|
||||
return 0;
|
||||
}
|
||||
break;
|
||||
ASN1_BOOLEAN *tbool;
|
||||
tbool = (ASN1_BOOLEAN *)pval;
|
||||
*tbool = CBS_data(&child)[0];
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
|
||||
// All other types as an |ASN1_STRING| representation.
|
||||
ASN1_STRING *str = ensure_string(pval);
|
||||
if (str == nullptr) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
switch (utype) {
|
||||
case V_ASN1_BIT_STRING:
|
||||
if (!c2i_ASN1_BIT_STRING((ASN1_BIT_STRING **)pval, &cont, len)) {
|
||||
goto err;
|
||||
}
|
||||
break;
|
||||
|
||||
return asn1_parse_bit_string(cbs, str, cbs_tag);
|
||||
case V_ASN1_INTEGER:
|
||||
return asn1_parse_integer(cbs, str, cbs_tag);
|
||||
case V_ASN1_ENUMERATED:
|
||||
tint = (ASN1_INTEGER **)pval;
|
||||
if (!c2i_ASN1_INTEGER(tint, &cont, len)) {
|
||||
goto err;
|
||||
}
|
||||
// Fixup type to match the expected form
|
||||
(*tint)->type = utype | ((*tint)->type & V_ASN1_NEG);
|
||||
break;
|
||||
|
||||
return asn1_parse_enumerated(cbs, str, cbs_tag);
|
||||
case V_ASN1_UNIVERSALSTRING:
|
||||
return asn1_parse_universal_string(cbs, str, cbs_tag);
|
||||
case V_ASN1_BMPSTRING:
|
||||
return asn1_parse_bmp_string(cbs, str, cbs_tag);
|
||||
case V_ASN1_UTF8STRING:
|
||||
return asn1_parse_utf8_string(cbs, str, cbs_tag);
|
||||
case V_ASN1_UTCTIME:
|
||||
// TODO(crbug.com/42290221): Reject timezone offsets. We need to parse
|
||||
// invalid timestamps in |X509| objects, but that parser no longer uses
|
||||
// this code.
|
||||
return asn1_parse_utc_time(cbs, str, cbs_tag,
|
||||
/*allow_timezone_offset=*/1);
|
||||
case V_ASN1_GENERALIZEDTIME:
|
||||
return asn1_parse_generalized_time(cbs, str, cbs_tag);
|
||||
case V_ASN1_OCTET_STRING:
|
||||
case V_ASN1_NUMERICSTRING:
|
||||
case V_ASN1_PRINTABLESTRING:
|
||||
case V_ASN1_T61STRING:
|
||||
case V_ASN1_VIDEOTEXSTRING:
|
||||
case V_ASN1_IA5STRING:
|
||||
case V_ASN1_UTCTIME:
|
||||
case V_ASN1_GENERALIZEDTIME:
|
||||
case V_ASN1_GRAPHICSTRING:
|
||||
case V_ASN1_VISIBLESTRING:
|
||||
case V_ASN1_GENERALSTRING:
|
||||
case V_ASN1_UNIVERSALSTRING:
|
||||
case V_ASN1_BMPSTRING:
|
||||
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: {
|
||||
CBS cbs;
|
||||
CBS_init(&cbs, cont, (size_t)len);
|
||||
if (utype == V_ASN1_BMPSTRING) {
|
||||
while (CBS_len(&cbs) != 0) {
|
||||
uint32_t c;
|
||||
if (!CBS_get_ucs2_be(&cbs, &c)) {
|
||||
OPENSSL_PUT_ERROR(ASN1, ASN1_R_INVALID_BMPSTRING);
|
||||
goto err;
|
||||
}
|
||||
}
|
||||
// T61String is parsed as Latin-1, so all byte strings are valid. The
|
||||
// others we currently do not enforce.
|
||||
//
|
||||
// TODO(crbug.com/42290290): Enforce the encoding of the other string
|
||||
// types.
|
||||
if (!asn1_parse_octet_string(cbs, str, cbs_tag)) {
|
||||
return 0;
|
||||
}
|
||||
if (utype == V_ASN1_UNIVERSALSTRING) {
|
||||
while (CBS_len(&cbs) != 0) {
|
||||
uint32_t c;
|
||||
if (!CBS_get_utf32_be(&cbs, &c)) {
|
||||
OPENSSL_PUT_ERROR(ASN1, ASN1_R_INVALID_UNIVERSALSTRING);
|
||||
goto err;
|
||||
}
|
||||
}
|
||||
str->type = utype;
|
||||
return 1;
|
||||
case V_ASN1_SEQUENCE: {
|
||||
// Save the entire element in the string.
|
||||
CBS elem;
|
||||
if (!CBS_get_asn1_element(cbs, &elem, cbs_tag)) {
|
||||
OPENSSL_PUT_ERROR(ASN1, ASN1_R_DECODE_ERROR);
|
||||
return 0;
|
||||
}
|
||||
if (utype == V_ASN1_UTF8STRING) {
|
||||
while (CBS_len(&cbs) != 0) {
|
||||
uint32_t c;
|
||||
if (!CBS_get_utf8(&cbs, &c)) {
|
||||
OPENSSL_PUT_ERROR(ASN1, ASN1_R_INVALID_UTF8STRING);
|
||||
goto err;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (utype == V_ASN1_UTCTIME) {
|
||||
if (!CBS_parse_utc_time(&cbs, NULL, /*allow_timezone_offset=*/1)) {
|
||||
OPENSSL_PUT_ERROR(ASN1, ASN1_R_INVALID_TIME_FORMAT);
|
||||
goto err;
|
||||
}
|
||||
}
|
||||
if (utype == V_ASN1_GENERALIZEDTIME) {
|
||||
if (!CBS_parse_generalized_time(&cbs, NULL,
|
||||
/*allow_timezone_offset=*/0)) {
|
||||
OPENSSL_PUT_ERROR(ASN1, ASN1_R_INVALID_TIME_FORMAT);
|
||||
goto err;
|
||||
}
|
||||
}
|
||||
// TODO(https://crbug.com/boringssl/427): Check other string types.
|
||||
|
||||
// All based on ASN1_STRING and handled the same
|
||||
if (!*pval) {
|
||||
stmp = ASN1_STRING_type_new(utype);
|
||||
if (!stmp) {
|
||||
goto err;
|
||||
}
|
||||
*pval = (ASN1_VALUE *)stmp;
|
||||
} else {
|
||||
stmp = (ASN1_STRING *)*pval;
|
||||
stmp->type = utype;
|
||||
}
|
||||
if (!ASN1_STRING_set(stmp, cont, len)) {
|
||||
ASN1_STRING_free(stmp);
|
||||
*pval = NULL;
|
||||
goto err;
|
||||
}
|
||||
break;
|
||||
str->type = V_ASN1_SEQUENCE;
|
||||
return ASN1_STRING_set(str, CBS_data(&elem), CBS_len(&elem));
|
||||
}
|
||||
}
|
||||
// If ASN1_ANY and NULL type fix up value
|
||||
if (typ && (utype == V_ASN1_NULL)) {
|
||||
typ->value.ptr = NULL;
|
||||
}
|
||||
|
||||
ret = 1;
|
||||
err:
|
||||
if (!ret) {
|
||||
ASN1_TYPE_free(typ);
|
||||
if (opval) {
|
||||
*opval = NULL;
|
||||
default:
|
||||
OPENSSL_PUT_ERROR(ASN1, ASN1_R_BAD_TEMPLATE);
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
// Check an ASN1 tag and length: a bit like ASN1_get_object but it
|
||||
+33
-80
@@ -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>
|
||||
|
||||
@@ -90,7 +48,7 @@ int ASN1_item_i2d(ASN1_VALUE *val, unsigned char **out, const ASN1_ITEM *it) {
|
||||
if (len <= 0) {
|
||||
return len;
|
||||
}
|
||||
buf = OPENSSL_malloc(len);
|
||||
buf = reinterpret_cast<uint8_t *>(OPENSSL_malloc(len));
|
||||
if (!buf) {
|
||||
return -1;
|
||||
}
|
||||
@@ -191,7 +149,8 @@ int asn1_item_ex_i2d_opt(ASN1_VALUE **pval, unsigned char **out,
|
||||
OPENSSL_PUT_ERROR(ASN1, ASN1_R_BAD_TEMPLATE);
|
||||
return -1;
|
||||
}
|
||||
const ASN1_EXTERN_FUNCS *ef = it->funcs;
|
||||
const ASN1_EXTERN_FUNCS *ef =
|
||||
reinterpret_cast<const ASN1_EXTERN_FUNCS *>(it->funcs);
|
||||
int ret = ef->asn1_ex_i2d(pval, out, it);
|
||||
if (ret == 0) {
|
||||
// |asn1_ex_i2d| should never return zero. We have already checked
|
||||
@@ -424,7 +383,8 @@ typedef struct {
|
||||
} DER_ENC;
|
||||
|
||||
static int der_cmp(const void *a, const void *b) {
|
||||
const DER_ENC *d1 = a, *d2 = b;
|
||||
const DER_ENC *d1 = reinterpret_cast<const DER_ENC *>(a),
|
||||
*d2 = reinterpret_cast<const DER_ENC *>(b);
|
||||
int cmplen, i;
|
||||
cmplen = (d1->length < d2->length) ? d1->length : d2->length;
|
||||
i = OPENSSL_memcmp(d1->data, d2->data, cmplen);
|
||||
@@ -453,14 +413,15 @@ static int asn1_set_seq_out(STACK_OF(ASN1_VALUE) *sk, unsigned char **out,
|
||||
}
|
||||
|
||||
int ret = 0;
|
||||
unsigned char *const buf = OPENSSL_malloc(skcontlen);
|
||||
DER_ENC *encoded = OPENSSL_calloc(sk_ASN1_VALUE_num(sk), sizeof(*encoded));
|
||||
uint8_t *const buf = reinterpret_cast<uint8_t *>(OPENSSL_malloc(skcontlen));
|
||||
DER_ENC *encoded = reinterpret_cast<DER_ENC *>(
|
||||
OPENSSL_calloc(sk_ASN1_VALUE_num(sk), sizeof(*encoded)));
|
||||
uint8_t *p = buf;
|
||||
if (encoded == NULL || buf == NULL) {
|
||||
goto err;
|
||||
}
|
||||
|
||||
// Encode all the elements into |buf| and populate |encoded|.
|
||||
unsigned char *p = buf;
|
||||
for (size_t i = 0; i < sk_ASN1_VALUE_num(sk); i++) {
|
||||
ASN1_VALUE *skitem = sk_ASN1_VALUE_value(sk, i);
|
||||
encoded[i].data = p;
|
||||
@@ -566,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;
|
||||
@@ -589,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) {
|
||||
@@ -688,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,212 +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_asn1.h>
|
||||
|
||||
#include <assert.h>
|
||||
|
||||
#include <CCryptoBoringSSL_asn1t.h>
|
||||
#include <CCryptoBoringSSL_mem.h>
|
||||
|
||||
#include "internal.h"
|
||||
|
||||
// Free up an ASN1 structure
|
||||
|
||||
void ASN1_item_free(ASN1_VALUE *val, const ASN1_ITEM *it) {
|
||||
ASN1_item_ex_free(&val, it);
|
||||
}
|
||||
|
||||
void ASN1_item_ex_free(ASN1_VALUE **pval, const ASN1_ITEM *it) {
|
||||
const ASN1_TEMPLATE *tt = NULL, *seqtt;
|
||||
const ASN1_EXTERN_FUNCS *ef;
|
||||
int i;
|
||||
if (!pval) {
|
||||
return;
|
||||
}
|
||||
if ((it->itype != ASN1_ITYPE_PRIMITIVE) && !*pval) {
|
||||
return;
|
||||
}
|
||||
|
||||
switch (it->itype) {
|
||||
case ASN1_ITYPE_PRIMITIVE:
|
||||
if (it->templates) {
|
||||
ASN1_template_free(pval, it->templates);
|
||||
} else {
|
||||
ASN1_primitive_free(pval, it);
|
||||
}
|
||||
break;
|
||||
|
||||
case ASN1_ITYPE_MSTRING:
|
||||
ASN1_primitive_free(pval, it);
|
||||
break;
|
||||
|
||||
case ASN1_ITYPE_CHOICE: {
|
||||
const ASN1_AUX *aux = it->funcs;
|
||||
ASN1_aux_cb *asn1_cb = aux != NULL ? aux->asn1_cb : NULL;
|
||||
if (asn1_cb) {
|
||||
i = asn1_cb(ASN1_OP_FREE_PRE, pval, it, NULL);
|
||||
if (i == 2) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
i = asn1_get_choice_selector(pval, it);
|
||||
if ((i >= 0) && (i < it->tcount)) {
|
||||
ASN1_VALUE **pchval;
|
||||
tt = it->templates + i;
|
||||
pchval = asn1_get_field_ptr(pval, tt);
|
||||
ASN1_template_free(pchval, tt);
|
||||
}
|
||||
if (asn1_cb) {
|
||||
asn1_cb(ASN1_OP_FREE_POST, pval, it, NULL);
|
||||
}
|
||||
OPENSSL_free(*pval);
|
||||
*pval = NULL;
|
||||
break;
|
||||
}
|
||||
|
||||
case ASN1_ITYPE_EXTERN:
|
||||
ef = it->funcs;
|
||||
if (ef && ef->asn1_ex_free) {
|
||||
ef->asn1_ex_free(pval, it);
|
||||
}
|
||||
break;
|
||||
|
||||
case ASN1_ITYPE_SEQUENCE: {
|
||||
if (!asn1_refcount_dec_and_test_zero(pval, it)) {
|
||||
return;
|
||||
}
|
||||
const ASN1_AUX *aux = it->funcs;
|
||||
ASN1_aux_cb *asn1_cb = aux != NULL ? aux->asn1_cb : NULL;
|
||||
if (asn1_cb) {
|
||||
i = asn1_cb(ASN1_OP_FREE_PRE, pval, it, NULL);
|
||||
if (i == 2) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
asn1_enc_free(pval, it);
|
||||
// If we free up as normal we will invalidate any ANY DEFINED BY
|
||||
// field and we wont be able to determine the type of the field it
|
||||
// defines. So free up in reverse order.
|
||||
tt = it->templates + it->tcount - 1;
|
||||
for (i = 0; i < it->tcount; tt--, i++) {
|
||||
ASN1_VALUE **pseqval;
|
||||
seqtt = asn1_do_adb(pval, tt, 0);
|
||||
if (!seqtt) {
|
||||
continue;
|
||||
}
|
||||
pseqval = asn1_get_field_ptr(pval, seqtt);
|
||||
ASN1_template_free(pseqval, seqtt);
|
||||
}
|
||||
if (asn1_cb) {
|
||||
asn1_cb(ASN1_OP_FREE_POST, pval, it, NULL);
|
||||
}
|
||||
OPENSSL_free(*pval);
|
||||
*pval = NULL;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void ASN1_template_free(ASN1_VALUE **pval, const ASN1_TEMPLATE *tt) {
|
||||
if (tt->flags & ASN1_TFLG_SK_MASK) {
|
||||
STACK_OF(ASN1_VALUE) *sk = (STACK_OF(ASN1_VALUE) *)*pval;
|
||||
for (size_t i = 0; i < sk_ASN1_VALUE_num(sk); i++) {
|
||||
ASN1_VALUE *vtmp = sk_ASN1_VALUE_value(sk, i);
|
||||
ASN1_item_ex_free(&vtmp, ASN1_ITEM_ptr(tt->item));
|
||||
}
|
||||
sk_ASN1_VALUE_free(sk);
|
||||
*pval = NULL;
|
||||
} else {
|
||||
ASN1_item_ex_free(pval, ASN1_ITEM_ptr(tt->item));
|
||||
}
|
||||
}
|
||||
|
||||
void ASN1_primitive_free(ASN1_VALUE **pval, const ASN1_ITEM *it) {
|
||||
// Historically, |it->funcs| for primitive types contained an
|
||||
// |ASN1_PRIMITIVE_FUNCS| table of calbacks.
|
||||
assert(it->funcs == NULL);
|
||||
|
||||
int utype = it->itype == ASN1_ITYPE_MSTRING ? -1 : it->utype;
|
||||
switch (utype) {
|
||||
case V_ASN1_OBJECT:
|
||||
ASN1_OBJECT_free((ASN1_OBJECT *)*pval);
|
||||
break;
|
||||
|
||||
case V_ASN1_BOOLEAN:
|
||||
if (it) {
|
||||
*(ASN1_BOOLEAN *)pval = (ASN1_BOOLEAN)it->size;
|
||||
} else {
|
||||
*(ASN1_BOOLEAN *)pval = ASN1_BOOLEAN_NONE;
|
||||
}
|
||||
return;
|
||||
|
||||
case V_ASN1_NULL:
|
||||
break;
|
||||
|
||||
case V_ASN1_ANY:
|
||||
if (*pval != NULL) {
|
||||
asn1_type_cleanup((ASN1_TYPE *)*pval);
|
||||
OPENSSL_free(*pval);
|
||||
}
|
||||
break;
|
||||
|
||||
default:
|
||||
ASN1_STRING_free((ASN1_STRING *)*pval);
|
||||
*pval = NULL;
|
||||
break;
|
||||
}
|
||||
*pval = NULL;
|
||||
}
|
||||
@@ -0,0 +1,164 @@
|
||||
// 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 <assert.h>
|
||||
|
||||
#include <CCryptoBoringSSL_asn1t.h>
|
||||
#include <CCryptoBoringSSL_mem.h>
|
||||
|
||||
#include "internal.h"
|
||||
|
||||
// Free up an ASN1 structure
|
||||
|
||||
void ASN1_item_free(ASN1_VALUE *val, const ASN1_ITEM *it) {
|
||||
ASN1_item_ex_free(&val, it);
|
||||
}
|
||||
|
||||
void ASN1_item_ex_free(ASN1_VALUE **pval, const ASN1_ITEM *it) {
|
||||
if (!pval) {
|
||||
return;
|
||||
}
|
||||
if ((it->itype != ASN1_ITYPE_PRIMITIVE) && !*pval) {
|
||||
return;
|
||||
}
|
||||
|
||||
switch (it->itype) {
|
||||
case ASN1_ITYPE_PRIMITIVE:
|
||||
if (it->templates) {
|
||||
ASN1_template_free(pval, it->templates);
|
||||
} else {
|
||||
ASN1_primitive_free(pval, it);
|
||||
}
|
||||
break;
|
||||
|
||||
case ASN1_ITYPE_MSTRING:
|
||||
ASN1_primitive_free(pval, it);
|
||||
break;
|
||||
|
||||
case ASN1_ITYPE_CHOICE: {
|
||||
const ASN1_AUX *aux = reinterpret_cast<const ASN1_AUX *>(it->funcs);
|
||||
ASN1_aux_cb *asn1_cb = aux != NULL ? aux->asn1_cb : NULL;
|
||||
if (asn1_cb) {
|
||||
if (asn1_cb(ASN1_OP_FREE_PRE, pval, it, NULL) == 2) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
int i = asn1_get_choice_selector(pval, it);
|
||||
if ((i >= 0) && (i < it->tcount)) {
|
||||
const ASN1_TEMPLATE *tt = it->templates + i;
|
||||
ASN1_VALUE **pchval = asn1_get_field_ptr(pval, tt);
|
||||
ASN1_template_free(pchval, tt);
|
||||
}
|
||||
if (asn1_cb) {
|
||||
asn1_cb(ASN1_OP_FREE_POST, pval, it, NULL);
|
||||
}
|
||||
OPENSSL_free(*pval);
|
||||
*pval = NULL;
|
||||
break;
|
||||
}
|
||||
|
||||
case ASN1_ITYPE_EXTERN: {
|
||||
const ASN1_EXTERN_FUNCS *ef =
|
||||
reinterpret_cast<const ASN1_EXTERN_FUNCS *>(it->funcs);
|
||||
if (ef && ef->asn1_ex_free) {
|
||||
ef->asn1_ex_free(pval, it);
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
case ASN1_ITYPE_SEQUENCE: {
|
||||
if (!asn1_refcount_dec_and_test_zero(pval, it)) {
|
||||
return;
|
||||
}
|
||||
const ASN1_AUX *aux = reinterpret_cast<const ASN1_AUX *>(it->funcs);
|
||||
ASN1_aux_cb *asn1_cb = aux != NULL ? aux->asn1_cb : NULL;
|
||||
if (asn1_cb) {
|
||||
if (asn1_cb(ASN1_OP_FREE_PRE, pval, it, NULL) == 2) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
asn1_enc_free(pval, it);
|
||||
// If we free up as normal we will invalidate any ANY DEFINED BY
|
||||
// field and we wont be able to determine the type of the field it
|
||||
// defines. So free up in reverse order.
|
||||
for (int i = it->tcount - 1; i >= 0; i--) {
|
||||
const ASN1_TEMPLATE *seqtt = asn1_do_adb(pval, &it->templates[i], 0);
|
||||
if (!seqtt) {
|
||||
continue;
|
||||
}
|
||||
ASN1_VALUE **pseqval = asn1_get_field_ptr(pval, seqtt);
|
||||
ASN1_template_free(pseqval, seqtt);
|
||||
}
|
||||
if (asn1_cb) {
|
||||
asn1_cb(ASN1_OP_FREE_POST, pval, it, NULL);
|
||||
}
|
||||
OPENSSL_free(*pval);
|
||||
*pval = NULL;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void ASN1_template_free(ASN1_VALUE **pval, const ASN1_TEMPLATE *tt) {
|
||||
if (tt->flags & ASN1_TFLG_SK_MASK) {
|
||||
STACK_OF(ASN1_VALUE) *sk = (STACK_OF(ASN1_VALUE) *)*pval;
|
||||
for (size_t i = 0; i < sk_ASN1_VALUE_num(sk); i++) {
|
||||
ASN1_VALUE *vtmp = sk_ASN1_VALUE_value(sk, i);
|
||||
ASN1_item_ex_free(&vtmp, ASN1_ITEM_ptr(tt->item));
|
||||
}
|
||||
sk_ASN1_VALUE_free(sk);
|
||||
*pval = NULL;
|
||||
} else {
|
||||
ASN1_item_ex_free(pval, ASN1_ITEM_ptr(tt->item));
|
||||
}
|
||||
}
|
||||
|
||||
void ASN1_primitive_free(ASN1_VALUE **pval, const ASN1_ITEM *it) {
|
||||
// Historically, |it->funcs| for primitive types contained an
|
||||
// |ASN1_PRIMITIVE_FUNCS| table of calbacks.
|
||||
assert(it->funcs == NULL);
|
||||
|
||||
int utype = it->itype == ASN1_ITYPE_MSTRING ? -1 : it->utype;
|
||||
switch (utype) {
|
||||
case V_ASN1_OBJECT:
|
||||
ASN1_OBJECT_free((ASN1_OBJECT *)*pval);
|
||||
break;
|
||||
|
||||
case V_ASN1_BOOLEAN:
|
||||
if (it) {
|
||||
*(ASN1_BOOLEAN *)pval = (ASN1_BOOLEAN)it->size;
|
||||
} else {
|
||||
*(ASN1_BOOLEAN *)pval = ASN1_BOOLEAN_NONE;
|
||||
}
|
||||
return;
|
||||
|
||||
case V_ASN1_NULL:
|
||||
break;
|
||||
|
||||
case V_ASN1_ANY:
|
||||
if (*pval != NULL) {
|
||||
asn1_type_cleanup((ASN1_TYPE *)*pval);
|
||||
OPENSSL_free(*pval);
|
||||
}
|
||||
break;
|
||||
|
||||
default:
|
||||
ASN1_STRING_free((ASN1_STRING *)*pval);
|
||||
*pval = NULL;
|
||||
break;
|
||||
}
|
||||
*pval = NULL;
|
||||
}
|
||||
+20
-61
@@ -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>
|
||||
|
||||
@@ -91,7 +49,7 @@ int ASN1_item_ex_new(ASN1_VALUE **pval, const ASN1_ITEM *it) {
|
||||
|
||||
switch (it->itype) {
|
||||
case ASN1_ITYPE_EXTERN:
|
||||
ef = it->funcs;
|
||||
ef = reinterpret_cast<const ASN1_EXTERN_FUNCS *>(it->funcs);
|
||||
if (ef && ef->asn1_ex_new) {
|
||||
if (!ef->asn1_ex_new(pval, it)) {
|
||||
goto memerr;
|
||||
@@ -116,7 +74,7 @@ int ASN1_item_ex_new(ASN1_VALUE **pval, const ASN1_ITEM *it) {
|
||||
break;
|
||||
|
||||
case ASN1_ITYPE_CHOICE: {
|
||||
const ASN1_AUX *aux = it->funcs;
|
||||
const ASN1_AUX *aux = reinterpret_cast<const ASN1_AUX *>(it->funcs);
|
||||
ASN1_aux_cb *asn1_cb = aux != NULL ? aux->asn1_cb : NULL;
|
||||
if (asn1_cb) {
|
||||
i = asn1_cb(ASN1_OP_NEW_PRE, pval, it, NULL);
|
||||
@@ -127,7 +85,7 @@ int ASN1_item_ex_new(ASN1_VALUE **pval, const ASN1_ITEM *it) {
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
*pval = OPENSSL_zalloc(it->size);
|
||||
*pval = reinterpret_cast<ASN1_VALUE *>(OPENSSL_zalloc(it->size));
|
||||
if (!*pval) {
|
||||
goto memerr;
|
||||
}
|
||||
@@ -139,7 +97,7 @@ int ASN1_item_ex_new(ASN1_VALUE **pval, const ASN1_ITEM *it) {
|
||||
}
|
||||
|
||||
case ASN1_ITYPE_SEQUENCE: {
|
||||
const ASN1_AUX *aux = it->funcs;
|
||||
const ASN1_AUX *aux = reinterpret_cast<const ASN1_AUX *>(it->funcs);
|
||||
ASN1_aux_cb *asn1_cb = aux != NULL ? aux->asn1_cb : NULL;
|
||||
if (asn1_cb) {
|
||||
i = asn1_cb(ASN1_OP_NEW_PRE, pval, it, NULL);
|
||||
@@ -150,7 +108,7 @@ int ASN1_item_ex_new(ASN1_VALUE **pval, const ASN1_ITEM *it) {
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
*pval = OPENSSL_zalloc(it->size);
|
||||
*pval = reinterpret_cast<ASN1_VALUE *>(OPENSSL_zalloc(it->size));
|
||||
if (!*pval) {
|
||||
goto memerr;
|
||||
}
|
||||
@@ -279,7 +237,8 @@ static int ASN1_primitive_new(ASN1_VALUE **pval, const ASN1_ITEM *it) {
|
||||
return 1;
|
||||
|
||||
case V_ASN1_ANY: {
|
||||
ASN1_TYPE *typ = OPENSSL_malloc(sizeof(ASN1_TYPE));
|
||||
ASN1_TYPE *typ =
|
||||
reinterpret_cast<ASN1_TYPE *>(OPENSSL_malloc(sizeof(ASN1_TYPE)));
|
||||
if (!typ) {
|
||||
return 0;
|
||||
}
|
||||
@@ -1,126 +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_asn1.h>
|
||||
|
||||
#include <CCryptoBoringSSL_asn1t.h>
|
||||
|
||||
// Declarations for string types
|
||||
|
||||
#define IMPLEMENT_ASN1_STRING_FUNCTIONS(sname) \
|
||||
IMPLEMENT_ASN1_TYPE(sname) \
|
||||
IMPLEMENT_ASN1_ENCODE_FUNCTIONS_const_fname(sname, sname, sname) \
|
||||
sname *sname##_new(void) { return ASN1_STRING_type_new(V_##sname); } \
|
||||
void sname##_free(sname *x) { ASN1_STRING_free(x); }
|
||||
|
||||
IMPLEMENT_ASN1_STRING_FUNCTIONS(ASN1_OCTET_STRING)
|
||||
IMPLEMENT_ASN1_STRING_FUNCTIONS(ASN1_INTEGER)
|
||||
IMPLEMENT_ASN1_STRING_FUNCTIONS(ASN1_ENUMERATED)
|
||||
IMPLEMENT_ASN1_STRING_FUNCTIONS(ASN1_BIT_STRING)
|
||||
IMPLEMENT_ASN1_STRING_FUNCTIONS(ASN1_UTF8STRING)
|
||||
IMPLEMENT_ASN1_STRING_FUNCTIONS(ASN1_PRINTABLESTRING)
|
||||
IMPLEMENT_ASN1_STRING_FUNCTIONS(ASN1_T61STRING)
|
||||
IMPLEMENT_ASN1_STRING_FUNCTIONS(ASN1_IA5STRING)
|
||||
IMPLEMENT_ASN1_STRING_FUNCTIONS(ASN1_GENERALSTRING)
|
||||
IMPLEMENT_ASN1_STRING_FUNCTIONS(ASN1_UTCTIME)
|
||||
IMPLEMENT_ASN1_STRING_FUNCTIONS(ASN1_GENERALIZEDTIME)
|
||||
IMPLEMENT_ASN1_STRING_FUNCTIONS(ASN1_VISIBLESTRING)
|
||||
IMPLEMENT_ASN1_STRING_FUNCTIONS(ASN1_UNIVERSALSTRING)
|
||||
IMPLEMENT_ASN1_STRING_FUNCTIONS(ASN1_BMPSTRING)
|
||||
|
||||
IMPLEMENT_ASN1_TYPE(ASN1_NULL)
|
||||
IMPLEMENT_ASN1_FUNCTIONS_const(ASN1_NULL)
|
||||
|
||||
IMPLEMENT_ASN1_TYPE(ASN1_OBJECT)
|
||||
|
||||
IMPLEMENT_ASN1_TYPE(ASN1_ANY)
|
||||
|
||||
// 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)
|
||||
|
||||
IMPLEMENT_ASN1_MSTRING(DIRECTORYSTRING, B_ASN1_DIRECTORYSTRING)
|
||||
IMPLEMENT_ASN1_FUNCTIONS_const_fname(ASN1_STRING, DIRECTORYSTRING,
|
||||
DIRECTORYSTRING)
|
||||
|
||||
// Three separate BOOLEAN type: normal, DEFAULT TRUE and DEFAULT FALSE
|
||||
IMPLEMENT_ASN1_TYPE_ex(ASN1_BOOLEAN, ASN1_BOOLEAN, ASN1_BOOLEAN_NONE)
|
||||
IMPLEMENT_ASN1_TYPE_ex(ASN1_TBOOLEAN, ASN1_BOOLEAN, ASN1_BOOLEAN_TRUE)
|
||||
IMPLEMENT_ASN1_TYPE_ex(ASN1_FBOOLEAN, ASN1_BOOLEAN, ASN1_BOOLEAN_FALSE)
|
||||
|
||||
ASN1_ITEM_TEMPLATE(ASN1_SEQUENCE_ANY) =
|
||||
ASN1_EX_TEMPLATE_TYPE(ASN1_TFLG_SEQUENCE_OF, 0, ASN1_SEQUENCE_ANY, ASN1_ANY)
|
||||
ASN1_ITEM_TEMPLATE_END(ASN1_SEQUENCE_ANY)
|
||||
|
||||
ASN1_ITEM_TEMPLATE(ASN1_SET_ANY) = ASN1_EX_TEMPLATE_TYPE(ASN1_TFLG_SET_OF, 0,
|
||||
ASN1_SET_ANY, ASN1_ANY)
|
||||
ASN1_ITEM_TEMPLATE_END(ASN1_SET_ANY)
|
||||
|
||||
IMPLEMENT_ASN1_ENCODE_FUNCTIONS_const_fname(ASN1_SEQUENCE_ANY,
|
||||
ASN1_SEQUENCE_ANY,
|
||||
ASN1_SEQUENCE_ANY)
|
||||
IMPLEMENT_ASN1_ENCODE_FUNCTIONS_const_fname(ASN1_SEQUENCE_ANY, ASN1_SET_ANY,
|
||||
ASN1_SET_ANY)
|
||||
@@ -0,0 +1,83 @@
|
||||
// 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>
|
||||
|
||||
#include "internal.h"
|
||||
|
||||
|
||||
// TODO(crbug.com/42290417): While we need |ASN1_ITEM|s, the exposed new, free,
|
||||
// i2d, and d2i functions should call the underlying implementations directly.
|
||||
|
||||
#define IMPLEMENT_ASN1_STRING_FUNCTIONS(sname) \
|
||||
IMPLEMENT_ASN1_TYPE(sname) \
|
||||
IMPLEMENT_ASN1_ENCODE_FUNCTIONS_const_fname(sname, sname, sname) \
|
||||
sname *sname##_new(void) { return ASN1_STRING_type_new(V_##sname); } \
|
||||
void sname##_free(sname *x) { ASN1_STRING_free(x); }
|
||||
|
||||
IMPLEMENT_ASN1_STRING_FUNCTIONS(ASN1_OCTET_STRING)
|
||||
IMPLEMENT_ASN1_STRING_FUNCTIONS(ASN1_INTEGER)
|
||||
IMPLEMENT_ASN1_STRING_FUNCTIONS(ASN1_ENUMERATED)
|
||||
IMPLEMENT_ASN1_STRING_FUNCTIONS(ASN1_BIT_STRING)
|
||||
IMPLEMENT_ASN1_STRING_FUNCTIONS(ASN1_UTF8STRING)
|
||||
IMPLEMENT_ASN1_STRING_FUNCTIONS(ASN1_PRINTABLESTRING)
|
||||
IMPLEMENT_ASN1_STRING_FUNCTIONS(ASN1_T61STRING)
|
||||
IMPLEMENT_ASN1_STRING_FUNCTIONS(ASN1_IA5STRING)
|
||||
IMPLEMENT_ASN1_STRING_FUNCTIONS(ASN1_GENERALSTRING)
|
||||
IMPLEMENT_ASN1_STRING_FUNCTIONS(ASN1_UTCTIME)
|
||||
IMPLEMENT_ASN1_STRING_FUNCTIONS(ASN1_GENERALIZEDTIME)
|
||||
IMPLEMENT_ASN1_STRING_FUNCTIONS(ASN1_VISIBLESTRING)
|
||||
IMPLEMENT_ASN1_STRING_FUNCTIONS(ASN1_UNIVERSALSTRING)
|
||||
IMPLEMENT_ASN1_STRING_FUNCTIONS(ASN1_BMPSTRING)
|
||||
|
||||
IMPLEMENT_ASN1_TYPE(ASN1_NULL)
|
||||
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)
|
||||
|
||||
IMPLEMENT_ASN1_MSTRING(DISPLAYTEXT, B_ASN1_DISPLAYTEXT)
|
||||
IMPLEMENT_ASN1_FUNCTIONS_const_fname(ASN1_STRING, DISPLAYTEXT, DISPLAYTEXT)
|
||||
|
||||
IMPLEMENT_ASN1_MSTRING(DIRECTORYSTRING, B_ASN1_DIRECTORYSTRING)
|
||||
IMPLEMENT_ASN1_FUNCTIONS_const_fname(ASN1_STRING, DIRECTORYSTRING,
|
||||
DIRECTORYSTRING)
|
||||
|
||||
// Three separate BOOLEAN type: normal, DEFAULT TRUE and DEFAULT FALSE
|
||||
IMPLEMENT_ASN1_TYPE_ex(ASN1_BOOLEAN, ASN1_BOOLEAN, ASN1_BOOLEAN_NONE)
|
||||
IMPLEMENT_ASN1_TYPE_ex(ASN1_TBOOLEAN, ASN1_BOOLEAN, ASN1_BOOLEAN_TRUE)
|
||||
IMPLEMENT_ASN1_TYPE_ex(ASN1_FBOOLEAN, ASN1_BOOLEAN, ASN1_BOOLEAN_FALSE)
|
||||
|
||||
ASN1_ITEM_TEMPLATE(ASN1_SEQUENCE_ANY) =
|
||||
ASN1_EX_TEMPLATE_TYPE(ASN1_TFLG_SEQUENCE_OF, 0, ASN1_SEQUENCE_ANY, ASN1_ANY)
|
||||
ASN1_ITEM_TEMPLATE_END(ASN1_SEQUENCE_ANY)
|
||||
|
||||
ASN1_ITEM_TEMPLATE(ASN1_SET_ANY) = ASN1_EX_TEMPLATE_TYPE(ASN1_TFLG_SET_OF, 0,
|
||||
ASN1_SET_ANY, ASN1_ANY)
|
||||
ASN1_ITEM_TEMPLATE_END(ASN1_SET_ANY)
|
||||
|
||||
IMPLEMENT_ASN1_ENCODE_FUNCTIONS_const_fname(ASN1_SEQUENCE_ANY,
|
||||
ASN1_SEQUENCE_ANY,
|
||||
ASN1_SEQUENCE_ANY)
|
||||
IMPLEMENT_ASN1_ENCODE_FUNCTIONS_const_fname(ASN1_SEQUENCE_ANY, ASN1_SET_ANY,
|
||||
ASN1_SET_ANY)
|
||||
+30
-84
@@ -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"
|
||||
@@ -77,7 +34,7 @@
|
||||
|
||||
// Given an ASN1_ITEM CHOICE type return the selector value
|
||||
int asn1_get_choice_selector(ASN1_VALUE **pval, const ASN1_ITEM *it) {
|
||||
int *sel = offset2ptr(*pval, it->utype);
|
||||
int *sel = reinterpret_cast<int *>(offset2ptr(*pval, it->utype));
|
||||
return *sel;
|
||||
}
|
||||
|
||||
@@ -85,7 +42,7 @@ int asn1_get_choice_selector(ASN1_VALUE **pval, const ASN1_ITEM *it) {
|
||||
int asn1_set_choice_selector(ASN1_VALUE **pval, int value,
|
||||
const ASN1_ITEM *it) {
|
||||
int *sel, ret;
|
||||
sel = offset2ptr(*pval, it->utype);
|
||||
sel = reinterpret_cast<int *>(offset2ptr(*pval, it->utype));
|
||||
ret = *sel;
|
||||
*sel = value;
|
||||
return ret;
|
||||
@@ -96,11 +53,12 @@ static CRYPTO_refcount_t *asn1_get_references(ASN1_VALUE **pval,
|
||||
if (it->itype != ASN1_ITYPE_SEQUENCE) {
|
||||
return NULL;
|
||||
}
|
||||
const ASN1_AUX *aux = it->funcs;
|
||||
const ASN1_AUX *aux = reinterpret_cast<const ASN1_AUX *>(it->funcs);
|
||||
if (!aux || !(aux->flags & ASN1_AFLG_REFCOUNT)) {
|
||||
return NULL;
|
||||
}
|
||||
return offset2ptr(*pval, aux->ref_offset);
|
||||
return reinterpret_cast<CRYPTO_refcount_t *>(
|
||||
offset2ptr(*pval, aux->ref_offset));
|
||||
}
|
||||
|
||||
void asn1_refcount_set_one(ASN1_VALUE **pval, const ASN1_ITEM *it) {
|
||||
@@ -124,11 +82,11 @@ static ASN1_ENCODING *asn1_get_enc_ptr(ASN1_VALUE **pval, const ASN1_ITEM *it) {
|
||||
if (!pval || !*pval) {
|
||||
return NULL;
|
||||
}
|
||||
aux = it->funcs;
|
||||
aux = reinterpret_cast<const ASN1_AUX *>(it->funcs);
|
||||
if (!aux || !(aux->flags & ASN1_AFLG_ENCODING)) {
|
||||
return NULL;
|
||||
}
|
||||
return offset2ptr(*pval, aux->enc_offset);
|
||||
return reinterpret_cast<ASN1_ENCODING *>(offset2ptr(*pval, aux->enc_offset));
|
||||
}
|
||||
|
||||
void asn1_enc_init(ASN1_VALUE **pval, const ASN1_ITEM *it) {
|
||||
@@ -136,7 +94,6 @@ void asn1_enc_init(ASN1_VALUE **pval, const ASN1_ITEM *it) {
|
||||
if (enc) {
|
||||
enc->enc = NULL;
|
||||
enc->len = 0;
|
||||
enc->buf = NULL;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -148,7 +105,7 @@ void asn1_enc_free(ASN1_VALUE **pval, const ASN1_ITEM *it) {
|
||||
}
|
||||
|
||||
int asn1_enc_save(ASN1_VALUE **pval, const uint8_t *in, size_t in_len,
|
||||
const ASN1_ITEM *it, CRYPTO_BUFFER *buf) {
|
||||
const ASN1_ITEM *it) {
|
||||
ASN1_ENCODING *enc;
|
||||
enc = asn1_get_enc_ptr(pval, it);
|
||||
if (!enc) {
|
||||
@@ -156,17 +113,9 @@ int asn1_enc_save(ASN1_VALUE **pval, const uint8_t *in, size_t in_len,
|
||||
}
|
||||
|
||||
asn1_encoding_clear(enc);
|
||||
if (buf != NULL) {
|
||||
assert(CRYPTO_BUFFER_data(buf) <= in &&
|
||||
in + in_len <= CRYPTO_BUFFER_data(buf) + CRYPTO_BUFFER_len(buf));
|
||||
CRYPTO_BUFFER_up_ref(buf);
|
||||
enc->buf = buf;
|
||||
enc->enc = (uint8_t *)in;
|
||||
} else {
|
||||
enc->enc = OPENSSL_memdup(in, in_len);
|
||||
if (!enc->enc) {
|
||||
return 0;
|
||||
}
|
||||
enc->enc = reinterpret_cast<uint8_t *>(OPENSSL_memdup(in, in_len));
|
||||
if (!enc->enc) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
enc->len = in_len;
|
||||
@@ -174,14 +123,9 @@ int asn1_enc_save(ASN1_VALUE **pval, const uint8_t *in, size_t in_len,
|
||||
}
|
||||
|
||||
void asn1_encoding_clear(ASN1_ENCODING *enc) {
|
||||
if (enc->buf != NULL) {
|
||||
CRYPTO_BUFFER_free(enc->buf);
|
||||
} else {
|
||||
OPENSSL_free(enc->enc);
|
||||
}
|
||||
OPENSSL_free(enc->enc);
|
||||
enc->enc = NULL;
|
||||
enc->len = 0;
|
||||
enc->buf = NULL;
|
||||
}
|
||||
|
||||
int asn1_enc_restore(int *len, unsigned char **out, ASN1_VALUE **pval,
|
||||
@@ -202,7 +146,8 @@ int asn1_enc_restore(int *len, unsigned char **out, ASN1_VALUE **pval,
|
||||
|
||||
// Given an ASN1_TEMPLATE get a pointer to a field
|
||||
ASN1_VALUE **asn1_get_field_ptr(ASN1_VALUE **pval, const ASN1_TEMPLATE *tt) {
|
||||
ASN1_VALUE **pvaltmp = offset2ptr(*pval, tt->offset);
|
||||
ASN1_VALUE **pvaltmp =
|
||||
reinterpret_cast<ASN1_VALUE **>(offset2ptr(*pval, tt->offset));
|
||||
// NOTE for BOOLEAN types the field is just a plain int so we can't return
|
||||
// int **, so settle for (int *).
|
||||
return pvaltmp;
|
||||
@@ -224,9 +169,10 @@ const ASN1_TEMPLATE *asn1_do_adb(ASN1_VALUE **pval, const ASN1_TEMPLATE *tt,
|
||||
adb = ASN1_ADB_ptr(tt->item);
|
||||
|
||||
// Get the selector field
|
||||
sfld = offset2ptr(*pval, adb->offset);
|
||||
sfld = reinterpret_cast<ASN1_VALUE **>(offset2ptr(*pval, adb->offset));
|
||||
|
||||
// Check if NULL
|
||||
int selector;
|
||||
if (*sfld == NULL) {
|
||||
if (!adb->null_tt) {
|
||||
goto err;
|
||||
@@ -238,7 +184,7 @@ const ASN1_TEMPLATE *asn1_do_adb(ASN1_VALUE **pval, const ASN1_TEMPLATE *tt,
|
||||
// NB: don't check for NID_undef here because it
|
||||
// might be a legitimate value in the table
|
||||
assert(tt->flags & ASN1_TFLG_ADB_OID);
|
||||
int selector = OBJ_obj2nid((ASN1_OBJECT *)*sfld);
|
||||
selector = OBJ_obj2nid((ASN1_OBJECT *)*sfld);
|
||||
|
||||
// Try to find matching entry in table Maybe should check application types
|
||||
// first to allow application override? Might also be useful to have a flag
|
||||
+26
-67
@@ -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>
|
||||
|
||||
@@ -121,12 +79,11 @@ int EVP_EncodedLength(size_t *out_len, size_t len) {
|
||||
}
|
||||
|
||||
EVP_ENCODE_CTX *EVP_ENCODE_CTX_new(void) {
|
||||
return OPENSSL_zalloc(sizeof(EVP_ENCODE_CTX));
|
||||
return reinterpret_cast<EVP_ENCODE_CTX *>(
|
||||
OPENSSL_zalloc(sizeof(EVP_ENCODE_CTX)));
|
||||
}
|
||||
|
||||
void EVP_ENCODE_CTX_free(EVP_ENCODE_CTX *ctx) {
|
||||
OPENSSL_free(ctx);
|
||||
}
|
||||
void EVP_ENCODE_CTX_free(EVP_ENCODE_CTX *ctx) { OPENSSL_free(ctx); }
|
||||
|
||||
void EVP_EncodeInit(EVP_ENCODE_CTX *ctx) {
|
||||
OPENSSL_memset(ctx, 0, sizeof(EVP_ENCODE_CTX));
|
||||
@@ -302,11 +259,15 @@ static int base64_decode_quad(uint8_t *out, size_t *out_num_bytes,
|
||||
const uint32_t v = ((uint32_t)a) << 18 | ((uint32_t)b) << 12 |
|
||||
((uint32_t)c) << 6 | (uint32_t)d;
|
||||
|
||||
const unsigned padding_pattern = (in[0] == '=') << 3 |
|
||||
(in[1] == '=') << 2 |
|
||||
(in[2] == '=') << 1 |
|
||||
const unsigned padding_pattern = (in[0] == '=') << 3 | //
|
||||
(in[1] == '=') << 2 | //
|
||||
(in[2] == '=') << 1 | //
|
||||
(in[3] == '=');
|
||||
|
||||
// In presence of padding, the lowest bits of v are unused. Canonical encoding
|
||||
// (RFC 4648, section 3.5) requires that these bits all be set to zero. Common
|
||||
// PEM parsers accept noncanonical base64, adding to the malleability of the
|
||||
// format. This decoder follows OpenSSL's and Go's PEM parsers and accepts it.
|
||||
switch (padding_pattern) {
|
||||
case 0:
|
||||
// The common case of no padding.
|
||||
@@ -408,8 +369,7 @@ int EVP_DecodeBase64(uint8_t *out, size_t *out_len, size_t max_out,
|
||||
}
|
||||
|
||||
size_t max_len;
|
||||
if (!EVP_DecodedLength(&max_len, in_len) ||
|
||||
max_out < max_len) {
|
||||
if (!EVP_DecodedLength(&max_len, in_len) || max_out < max_len) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -445,7 +405,7 @@ int EVP_DecodeBlock(uint8_t *dst, const uint8_t *src, size_t src_len) {
|
||||
|
||||
// Trim newlines, spaces and tabs from the end of the line.
|
||||
while (src_len > 0) {
|
||||
switch (src[src_len-1]) {
|
||||
switch (src[src_len - 1]) {
|
||||
case ' ':
|
||||
case '\t':
|
||||
case '\r':
|
||||
@@ -458,8 +418,7 @@ int EVP_DecodeBlock(uint8_t *dst, const uint8_t *src, size_t src_len) {
|
||||
}
|
||||
|
||||
size_t dst_len;
|
||||
if (!EVP_DecodedLength(&dst_len, src_len) ||
|
||||
dst_len > INT_MAX ||
|
||||
if (!EVP_DecodedLength(&dst_len, src_len) || dst_len > INT_MAX ||
|
||||
!EVP_DecodeBase64(dst, &dst_len, dst_len, src, src_len)) {
|
||||
return -1;
|
||||
}
|
||||
@@ -0,0 +1,84 @@
|
||||
// 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
|
||||
|
||||
#include <CCryptoBoringSSL_base.h>
|
||||
|
||||
#include <stdio.h>
|
||||
|
||||
// Provided by libcrypto, called from BCM
|
||||
|
||||
#if defined(__cplusplus)
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
// Provided by libcrypto, called from BCM
|
||||
|
||||
// CRYPTO_init_sysrand initializes long-lived resources needed to draw entropy
|
||||
// from the operating system, if the operating system requires initialization.
|
||||
void CRYPTO_init_sysrand(void);
|
||||
|
||||
// CRYPTO_sysrand fills |len| bytes at |buf| with entropy from the operating
|
||||
// system.
|
||||
void CRYPTO_sysrand(uint8_t *buf, size_t len);
|
||||
|
||||
// CRYPTO_sysrand_if_available fills |len| bytes at |buf| with entropy from the
|
||||
// operating system, or early /dev/urandom data, and returns 1, _if_ the entropy
|
||||
// pool is initialized or if getrandom() is not available and not in FIPS mode.
|
||||
// Otherwise it will not block and will instead fill |buf| with all zeros and
|
||||
// return 0.
|
||||
int CRYPTO_sysrand_if_available(uint8_t *buf, size_t len);
|
||||
|
||||
// CRYPTO_sysrand_for_seed fills |len| bytes at |buf| with entropy from the
|
||||
// operating system. It may draw from the |GRND_RANDOM| pool on Android,
|
||||
// depending on the vendor's configuration.
|
||||
void CRYPTO_sysrand_for_seed(uint8_t *buf, size_t len);
|
||||
|
||||
// RAND_need_entropy is called whenever the BCM module has stopped because it
|
||||
// has run out of entropy.
|
||||
void RAND_need_entropy(size_t bytes_needed);
|
||||
|
||||
// crypto_get_fork_generation returns the fork generation number for the current
|
||||
// process, or zero if not supported on the platform. The fork generation number
|
||||
// is a non-zero, strictly-monotonic counter with the property that, if queried
|
||||
// in an address space and then again in a subsequently forked copy, the forked
|
||||
// address space will observe a greater value.
|
||||
//
|
||||
// This function may be used to clear cached values across a fork. When
|
||||
// initializing a cache, record the fork generation. Before using the cache,
|
||||
// check if the fork generation has changed. If so, drop the cache and update
|
||||
// the save fork generation. Note this logic transparently handles platforms
|
||||
// which always return zero.
|
||||
//
|
||||
// This is not reliably supported on all platforms which implement |fork|, so it
|
||||
// should only be used as a hardening measure.
|
||||
OPENSSL_EXPORT uint64_t CRYPTO_get_fork_generation(void);
|
||||
|
||||
// CRYPTO_fork_detect_force_madv_wipeonfork_for_testing is an internal detail
|
||||
// used for testing purposes.
|
||||
OPENSSL_EXPORT void CRYPTO_fork_detect_force_madv_wipeonfork_for_testing(
|
||||
int on);
|
||||
|
||||
// CRYPTO_get_stderr returns stderr. This function exists to avoid BCM needing
|
||||
// a data dependency on libc.
|
||||
FILE *CRYPTO_get_stderr(void);
|
||||
|
||||
|
||||
#if defined(__cplusplus)
|
||||
} // extern C
|
||||
#endif
|
||||
|
||||
#endif // OPENSSL_HEADER_CRYPTO_BCM_SUPPORT_H
|
||||
+65
-126
@@ -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,16 +22,16 @@
|
||||
#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 =
|
||||
CRYPTO_EX_DATA_CLASS_INIT_WITH_APP_DATA;
|
||||
|
||||
BIO *BIO_new(const BIO_METHOD *method) {
|
||||
BIO *ret = OPENSSL_zalloc(sizeof(BIO));
|
||||
BIO *ret = reinterpret_cast<BIO *>(OPENSSL_zalloc(sizeof(BIO)));
|
||||
if (ret == NULL) {
|
||||
return NULL;
|
||||
}
|
||||
@@ -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;
|
||||
@@ -116,13 +74,9 @@ int BIO_up_ref(BIO *bio) {
|
||||
return 1;
|
||||
}
|
||||
|
||||
void BIO_vfree(BIO *bio) {
|
||||
BIO_free(bio);
|
||||
}
|
||||
void BIO_vfree(BIO *bio) { BIO_free(bio); }
|
||||
|
||||
void BIO_free_all(BIO *bio) {
|
||||
BIO_free(bio);
|
||||
}
|
||||
void BIO_free_all(BIO *bio) { BIO_free(bio); }
|
||||
|
||||
int BIO_read(BIO *bio, void *buf, int len) {
|
||||
if (bio == NULL || bio->method == NULL || bio->method->bread == NULL) {
|
||||
@@ -136,7 +90,7 @@ int BIO_read(BIO *bio, void *buf, int len) {
|
||||
if (len <= 0) {
|
||||
return 0;
|
||||
}
|
||||
int ret = bio->method->bread(bio, buf, len);
|
||||
int ret = bio->method->bread(bio, reinterpret_cast<char *>(buf), len);
|
||||
if (ret > 0) {
|
||||
bio->num_read += ret;
|
||||
}
|
||||
@@ -174,7 +128,7 @@ int BIO_write(BIO *bio, const void *in, int inl) {
|
||||
if (inl <= 0) {
|
||||
return 0;
|
||||
}
|
||||
int ret = bio->method->bwrite(bio, in, inl);
|
||||
int ret = bio->method->bwrite(bio, reinterpret_cast<const char *>(in), inl);
|
||||
if (ret > 0) {
|
||||
bio->num_write += ret;
|
||||
}
|
||||
@@ -182,7 +136,7 @@ int BIO_write(BIO *bio, const void *in, int inl) {
|
||||
}
|
||||
|
||||
int BIO_write_all(BIO *bio, const void *data, size_t len) {
|
||||
const uint8_t *data_u8 = data;
|
||||
const uint8_t *data_u8 = reinterpret_cast<const uint8_t *>(data);
|
||||
while (len > 0) {
|
||||
int ret = BIO_write(bio, data_u8, len > INT_MAX ? INT_MAX : (int)len);
|
||||
if (ret <= 0) {
|
||||
@@ -204,9 +158,7 @@ int BIO_puts(BIO *bio, const char *in) {
|
||||
return BIO_write(bio, in, (int)len);
|
||||
}
|
||||
|
||||
int BIO_flush(BIO *bio) {
|
||||
return (int)BIO_ctrl(bio, BIO_CTRL_FLUSH, 0, NULL);
|
||||
}
|
||||
int BIO_flush(BIO *bio) { return (int)BIO_ctrl(bio, BIO_CTRL_FLUSH, 0, NULL); }
|
||||
|
||||
long BIO_ctrl(BIO *bio, int cmd, long larg, void *parg) {
|
||||
if (bio == NULL) {
|
||||
@@ -237,21 +189,13 @@ long BIO_int_ctrl(BIO *b, int cmd, long larg, int iarg) {
|
||||
return BIO_ctrl(b, cmd, larg, (void *)&i);
|
||||
}
|
||||
|
||||
int BIO_reset(BIO *bio) {
|
||||
return (int)BIO_ctrl(bio, BIO_CTRL_RESET, 0, NULL);
|
||||
}
|
||||
int BIO_reset(BIO *bio) { return (int)BIO_ctrl(bio, BIO_CTRL_RESET, 0, NULL); }
|
||||
|
||||
int BIO_eof(BIO *bio) {
|
||||
return (int)BIO_ctrl(bio, BIO_CTRL_EOF, 0, NULL);
|
||||
}
|
||||
int BIO_eof(BIO *bio) { return (int)BIO_ctrl(bio, BIO_CTRL_EOF, 0, NULL); }
|
||||
|
||||
void BIO_set_flags(BIO *bio, int flags) {
|
||||
bio->flags |= flags;
|
||||
}
|
||||
void BIO_set_flags(BIO *bio, int flags) { bio->flags |= flags; }
|
||||
|
||||
int BIO_test_flags(const BIO *bio, int flags) {
|
||||
return bio->flags & flags;
|
||||
}
|
||||
int BIO_test_flags(const BIO *bio, int flags) { return bio->flags & flags; }
|
||||
|
||||
int BIO_should_read(const BIO *bio) {
|
||||
return BIO_test_flags(bio, BIO_FLAGS_READ);
|
||||
@@ -273,9 +217,7 @@ int BIO_get_retry_reason(const BIO *bio) { return bio->retry_reason; }
|
||||
|
||||
void BIO_set_retry_reason(BIO *bio, int reason) { bio->retry_reason = reason; }
|
||||
|
||||
void BIO_clear_flags(BIO *bio, int flags) {
|
||||
bio->flags &= ~flags;
|
||||
}
|
||||
void BIO_clear_flags(BIO *bio, int flags) { bio->flags &= ~flags; }
|
||||
|
||||
void BIO_set_retry_read(BIO *bio) {
|
||||
bio->flags |= BIO_FLAGS_READ | BIO_FLAGS_SHOULD_RETRY;
|
||||
@@ -287,9 +229,7 @@ void BIO_set_retry_write(BIO *bio) {
|
||||
|
||||
static const int kRetryFlags = BIO_FLAGS_RWS | BIO_FLAGS_SHOULD_RETRY;
|
||||
|
||||
int BIO_get_retry_flags(BIO *bio) {
|
||||
return bio->flags & kRetryFlags;
|
||||
}
|
||||
int BIO_get_retry_flags(BIO *bio) { return bio->flags & kRetryFlags; }
|
||||
|
||||
void BIO_clear_retry_flags(BIO *bio) {
|
||||
bio->flags &= ~kRetryFlags;
|
||||
@@ -304,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;
|
||||
}
|
||||
@@ -318,7 +258,7 @@ long BIO_callback_ctrl(BIO *bio, int cmd, bio_info_cb fp) {
|
||||
}
|
||||
|
||||
size_t BIO_pending(const BIO *bio) {
|
||||
const long r = BIO_ctrl((BIO *) bio, BIO_CTRL_PENDING, 0, NULL);
|
||||
const long r = BIO_ctrl((BIO *)bio, BIO_CTRL_PENDING, 0, NULL);
|
||||
assert(r >= 0);
|
||||
|
||||
if (r < 0) {
|
||||
@@ -327,12 +267,10 @@ size_t BIO_pending(const BIO *bio) {
|
||||
return r;
|
||||
}
|
||||
|
||||
size_t BIO_ctrl_pending(const BIO *bio) {
|
||||
return BIO_pending(bio);
|
||||
}
|
||||
size_t BIO_ctrl_pending(const BIO *bio) { return BIO_pending(bio); }
|
||||
|
||||
size_t BIO_wpending(const BIO *bio) {
|
||||
const long r = BIO_ctrl((BIO *) bio, BIO_CTRL_WPENDING, 0, NULL);
|
||||
const long r = BIO_ctrl((BIO *)bio, BIO_CTRL_WPENDING, 0, NULL);
|
||||
assert(r >= 0);
|
||||
|
||||
if (r < 0) {
|
||||
@@ -430,9 +368,7 @@ static int print_bio(const char *str, size_t len, void *bio) {
|
||||
return BIO_write_all((BIO *)bio, str, len);
|
||||
}
|
||||
|
||||
void ERR_print_errors(BIO *bio) {
|
||||
ERR_print_errors_cb(print_bio, bio);
|
||||
}
|
||||
void ERR_print_errors(BIO *bio) { ERR_print_errors_cb(print_bio, bio); }
|
||||
|
||||
// bio_read_all reads everything from |bio| and prepends |prefix| to it. On
|
||||
// success, |*out| is set to an allocated buffer (which should be freed with
|
||||
@@ -454,7 +390,7 @@ static int bio_read_all(BIO *bio, uint8_t **out, size_t *out_len,
|
||||
if (len < prefix_len) {
|
||||
return 0;
|
||||
}
|
||||
*out = OPENSSL_malloc(len);
|
||||
*out = reinterpret_cast<uint8_t *>(OPENSSL_malloc(len));
|
||||
if (*out == NULL) {
|
||||
return 0;
|
||||
}
|
||||
@@ -485,7 +421,8 @@ static int bio_read_all(BIO *bio, uint8_t **out, size_t *out_len,
|
||||
if (len < kChunkSize || len > max_len) {
|
||||
len = max_len;
|
||||
}
|
||||
uint8_t *new_buf = OPENSSL_realloc(*out, len);
|
||||
uint8_t *new_buf =
|
||||
reinterpret_cast<uint8_t *>(OPENSSL_realloc(*out, len));
|
||||
if (new_buf == NULL) {
|
||||
OPENSSL_free(*out);
|
||||
return 0;
|
||||
@@ -594,7 +531,7 @@ int BIO_read_asn1(BIO *bio, uint8_t **out, size_t *out_len, size_t max_len) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
if ((len32 >> ((num_bytes-1)*8)) == 0) {
|
||||
if ((len32 >> ((num_bytes - 1) * 8)) == 0) {
|
||||
// Length should have been at least one byte shorter.
|
||||
OPENSSL_PUT_ERROR(ASN1, ASN1_R_DECODE_ERROR);
|
||||
return 0;
|
||||
@@ -603,16 +540,14 @@ int BIO_read_asn1(BIO *bio, uint8_t **out, size_t *out_len, size_t max_len) {
|
||||
len = len32;
|
||||
}
|
||||
|
||||
if (len + header_len < len ||
|
||||
len + header_len > max_len ||
|
||||
len > INT_MAX) {
|
||||
if (len + header_len < len || len + header_len > max_len || len > INT_MAX) {
|
||||
OPENSSL_PUT_ERROR(ASN1, ASN1_R_TOO_LONG);
|
||||
return 0;
|
||||
}
|
||||
len += header_len;
|
||||
*out_len = len;
|
||||
|
||||
*out = OPENSSL_malloc(len);
|
||||
*out = reinterpret_cast<uint8_t *>(OPENSSL_malloc(len));
|
||||
if (*out == NULL) {
|
||||
return 0;
|
||||
}
|
||||
@@ -644,7 +579,8 @@ int BIO_get_new_index(void) {
|
||||
}
|
||||
|
||||
BIO_METHOD *BIO_meth_new(int type, const char *name) {
|
||||
BIO_METHOD *method = OPENSSL_zalloc(sizeof(BIO_METHOD));
|
||||
BIO_METHOD *method =
|
||||
reinterpret_cast<BIO_METHOD *>(OPENSSL_zalloc(sizeof(BIO_METHOD)));
|
||||
if (method == NULL) {
|
||||
return NULL;
|
||||
}
|
||||
@@ -653,43 +589,46 @@ BIO_METHOD *BIO_meth_new(int type, const char *name) {
|
||||
return method;
|
||||
}
|
||||
|
||||
void BIO_meth_free(BIO_METHOD *method) {
|
||||
OPENSSL_free(method);
|
||||
}
|
||||
void BIO_meth_free(BIO_METHOD *method) { OPENSSL_free(method); }
|
||||
|
||||
int BIO_meth_set_create(BIO_METHOD *method,
|
||||
int (*create)(BIO *)) {
|
||||
method->create = create;
|
||||
int BIO_meth_set_create(BIO_METHOD *method, int (*create_func)(BIO *)) {
|
||||
method->create = create_func;
|
||||
return 1;
|
||||
}
|
||||
|
||||
int BIO_meth_set_destroy(BIO_METHOD *method,
|
||||
int (*destroy)(BIO *)) {
|
||||
method->destroy = destroy;
|
||||
int BIO_meth_set_destroy(BIO_METHOD *method, int (*destroy_func)(BIO *)) {
|
||||
method->destroy = destroy_func;
|
||||
return 1;
|
||||
}
|
||||
|
||||
int BIO_meth_set_write(BIO_METHOD *method,
|
||||
int (*write)(BIO *, const char *, int)) {
|
||||
method->bwrite = write;
|
||||
int (*write_func)(BIO *, const char *, int)) {
|
||||
method->bwrite = write_func;
|
||||
return 1;
|
||||
}
|
||||
|
||||
int BIO_meth_set_read(BIO_METHOD *method,
|
||||
int (*read)(BIO *, char *, int)) {
|
||||
method->bread = read;
|
||||
int (*read_func)(BIO *, char *, int)) {
|
||||
method->bread = read_func;
|
||||
return 1;
|
||||
}
|
||||
|
||||
int BIO_meth_set_gets(BIO_METHOD *method,
|
||||
int (*gets)(BIO *, char *, int)) {
|
||||
method->bgets = gets;
|
||||
int (*gets_func)(BIO *, char *, int)) {
|
||||
method->bgets = gets_func;
|
||||
return 1;
|
||||
}
|
||||
|
||||
int BIO_meth_set_ctrl(BIO_METHOD *method,
|
||||
long (*ctrl)(BIO *, int, long, void *)) {
|
||||
method->ctrl = ctrl;
|
||||
long (*ctrl_func)(BIO *, int, long, void *)) {
|
||||
method->ctrl = ctrl_func;
|
||||
return 1;
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
@@ -710,10 +649,10 @@ int BIO_meth_set_puts(BIO_METHOD *method, int (*puts)(BIO *, const char *)) {
|
||||
return 1;
|
||||
}
|
||||
|
||||
int BIO_get_ex_new_index(long argl, void *argp,
|
||||
CRYPTO_EX_unused *unused,
|
||||
CRYPTO_EX_dup *dup_unused,
|
||||
CRYPTO_EX_free *free_func) {
|
||||
int BIO_get_ex_new_index(long argl, void *argp, //
|
||||
CRYPTO_EX_unused *unused, //
|
||||
CRYPTO_EX_dup *dup_unused, //
|
||||
CRYPTO_EX_free *free_func) {
|
||||
return CRYPTO_get_ex_new_index_ex(&g_ex_data_class, argl, argp, free_func);
|
||||
}
|
||||
|
||||
+47
-98
@@ -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) {
|
||||
@@ -83,7 +42,7 @@ BIO *BIO_new_mem_buf(const void *buf, ossl_ssize_t len) {
|
||||
|
||||
b = (BUF_MEM *)ret->ptr;
|
||||
// BIO_FLAGS_MEM_RDONLY ensures |b->data| is not written to.
|
||||
b->data = (void *)buf;
|
||||
b->data = reinterpret_cast<char *>(const_cast<void *>(buf));
|
||||
b->length = size;
|
||||
b->max = size;
|
||||
|
||||
@@ -135,7 +94,7 @@ static int mem_read(BIO *bio, char *out, int outl) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
BUF_MEM *b = bio->ptr;
|
||||
BUF_MEM *b = reinterpret_cast<BUF_MEM *>(bio->ptr);
|
||||
int ret = outl;
|
||||
if ((size_t)ret > b->length) {
|
||||
ret = (int)b->length;
|
||||
@@ -169,7 +128,7 @@ static int mem_write(BIO *bio, const char *in, int inl) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
BUF_MEM *b = bio->ptr;
|
||||
BUF_MEM *b = reinterpret_cast<BUF_MEM *>(bio->ptr);
|
||||
if (!BUF_MEM_append(b, in, inl)) {
|
||||
return -1;
|
||||
}
|
||||
@@ -185,14 +144,15 @@ static int mem_gets(BIO *bio, char *buf, int size) {
|
||||
|
||||
// The buffer size includes space for the trailing NUL, so we can read at most
|
||||
// one fewer byte.
|
||||
BUF_MEM *b = bio->ptr;
|
||||
BUF_MEM *b = reinterpret_cast<BUF_MEM *>(bio->ptr);
|
||||
int ret = size - 1;
|
||||
if ((size_t)ret > b->length) {
|
||||
ret = (int)b->length;
|
||||
}
|
||||
|
||||
// Stop at the first newline.
|
||||
const char *newline = OPENSSL_memchr(b->data, '\n', ret);
|
||||
const char *newline =
|
||||
reinterpret_cast<char *>(OPENSSL_memchr(b->data, '\n', ret));
|
||||
if (newline != NULL) {
|
||||
ret = (int)(newline - b->data + 1);
|
||||
}
|
||||
@@ -205,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) {
|
||||
@@ -221,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 = 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 = 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; }
|
||||
+79
-146
@@ -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>
|
||||
|
||||
@@ -63,22 +21,20 @@
|
||||
#include <string.h>
|
||||
|
||||
#if !defined(OPENSSL_WINDOWS)
|
||||
#include <sys/socket.h>
|
||||
#include <netinet/in.h>
|
||||
#include <arpa/inet.h>
|
||||
#include <netinet/in.h>
|
||||
#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>
|
||||
#include <CCryptoBoringSSL_mem.h>
|
||||
|
||||
#include "internal.h"
|
||||
#include "../internal.h"
|
||||
#include "internal.h"
|
||||
|
||||
|
||||
enum {
|
||||
@@ -87,6 +43,7 @@ enum {
|
||||
BIO_CONN_S_OK,
|
||||
};
|
||||
|
||||
namespace {
|
||||
typedef struct bio_connect_st {
|
||||
int state;
|
||||
|
||||
@@ -105,13 +62,12 @@ 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);
|
||||
}
|
||||
static int closesocket(int sock) { return close(sock); }
|
||||
#endif
|
||||
|
||||
// split_host_and_port sets |*out_host| and |*out_port| to the host and port
|
||||
@@ -168,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;
|
||||
@@ -231,7 +187,7 @@ static int conn_state(BIO *bio, BIO_CONNECT *c) {
|
||||
}
|
||||
|
||||
BIO_clear_retry_flags(bio);
|
||||
ret = connect(bio->num, (struct sockaddr*) &c->them, c->them_length);
|
||||
ret = connect(bio->num, (struct sockaddr *)&c->them, c->them_length);
|
||||
if (ret < 0) {
|
||||
if (bio_socket_should_retry(ret)) {
|
||||
BIO_set_flags(bio, (BIO_FLAGS_IO_SPECIAL | BIO_FLAGS_SHOULD_RETRY));
|
||||
@@ -261,7 +217,8 @@ static int conn_state(BIO *bio, BIO_CONNECT *c) {
|
||||
BIO_clear_retry_flags(bio);
|
||||
OPENSSL_PUT_SYSTEM_ERROR();
|
||||
OPENSSL_PUT_ERROR(BIO, BIO_R_NBIO_CONNECT_ERROR);
|
||||
ERR_add_error_data(4, "host=", c->param_hostname, ":", c->param_port);
|
||||
ERR_add_error_data(4, "host=", c->param_hostname, ":",
|
||||
c->param_port);
|
||||
ret = 0;
|
||||
}
|
||||
goto exit_loop;
|
||||
@@ -296,7 +253,8 @@ end:
|
||||
}
|
||||
|
||||
static BIO_CONNECT *BIO_CONNECT_new(void) {
|
||||
BIO_CONNECT *ret = OPENSSL_zalloc(sizeof(BIO_CONNECT));
|
||||
BIO_CONNECT *ret =
|
||||
reinterpret_cast<BIO_CONNECT *>(OPENSSL_zalloc(sizeof(BIO_CONNECT)));
|
||||
if (ret == NULL) {
|
||||
return NULL;
|
||||
}
|
||||
@@ -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);
|
||||
@@ -323,7 +280,7 @@ static int conn_new(BIO *bio) {
|
||||
}
|
||||
|
||||
static void conn_close_socket(BIO *bio) {
|
||||
BIO_CONNECT *c = (BIO_CONNECT *) bio->ptr;
|
||||
BIO_CONNECT *c = (BIO_CONNECT *)bio->ptr;
|
||||
|
||||
if (bio->num == -1) {
|
||||
return;
|
||||
@@ -342,7 +299,7 @@ static int conn_free(BIO *bio) {
|
||||
conn_close_socket(bio);
|
||||
}
|
||||
|
||||
BIO_CONNECT_free((BIO_CONNECT*) bio->ptr);
|
||||
BIO_CONNECT_free((BIO_CONNECT *)bio->ptr);
|
||||
|
||||
return 1;
|
||||
}
|
||||
@@ -396,105 +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(ptr);
|
||||
if (data->param_hostname == NULL) {
|
||||
ret = 0;
|
||||
}
|
||||
} else if (num == 1) {
|
||||
OPENSSL_free(data->param_port);
|
||||
data->param_port = OPENSSL_strdup(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) = 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))
|
||||
data->info_callback = (int (*)(const struct bio_st *, int, int))fp;
|
||||
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) {
|
||||
@@ -512,19 +445,19 @@ 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; }
|
||||
|
||||
int BIO_set_conn_hostname(BIO *bio, const char *name) {
|
||||
return (int)BIO_ctrl(bio, BIO_C_SET_CONNECT, 0, (void*) name);
|
||||
return (int)BIO_ctrl(bio, BIO_C_SET_CONNECT, 0, (void *)name);
|
||||
}
|
||||
|
||||
int BIO_set_conn_port(BIO *bio, const char *port_str) {
|
||||
return (int)BIO_ctrl(bio, BIO_C_SET_CONNECT, 1, (void*) port_str);
|
||||
return (int)BIO_ctrl(bio, BIO_C_SET_CONNECT, 1, (void *)port_str);
|
||||
}
|
||||
|
||||
int BIO_set_conn_int_port(BIO *bio, const int *port) {
|
||||
@@ -1,92 +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_bio.h>
|
||||
|
||||
#include <errno.h>
|
||||
|
||||
#include "internal.h"
|
||||
|
||||
|
||||
int bio_errno_should_retry(int return_value) {
|
||||
if (return_value != -1) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
return
|
||||
#ifdef EWOULDBLOCK
|
||||
errno == EWOULDBLOCK ||
|
||||
#endif
|
||||
#ifdef ENOTCONN
|
||||
errno == ENOTCONN ||
|
||||
#endif
|
||||
#ifdef EINTR
|
||||
errno == EINTR ||
|
||||
#endif
|
||||
#ifdef EAGAIN
|
||||
errno == EAGAIN ||
|
||||
#endif
|
||||
#ifdef EPROTO
|
||||
errno == EPROTO ||
|
||||
#endif
|
||||
#ifdef EINPROGRESS
|
||||
errno == EINPROGRESS ||
|
||||
#endif
|
||||
#ifdef EALREADY
|
||||
errno == EALREADY ||
|
||||
#endif
|
||||
0;
|
||||
}
|
||||
@@ -0,0 +1,50 @@
|
||||
// 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>
|
||||
|
||||
#include <errno.h>
|
||||
|
||||
#include "internal.h"
|
||||
|
||||
|
||||
int bio_errno_should_retry(int return_value) {
|
||||
if (return_value != -1) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
return
|
||||
#ifdef EWOULDBLOCK
|
||||
errno == EWOULDBLOCK ||
|
||||
#endif
|
||||
#ifdef ENOTCONN
|
||||
errno == ENOTCONN ||
|
||||
#endif
|
||||
#ifdef EINTR
|
||||
errno == EINTR ||
|
||||
#endif
|
||||
#ifdef EAGAIN
|
||||
errno == EAGAIN ||
|
||||
#endif
|
||||
#ifdef EPROTO
|
||||
errno == EPROTO ||
|
||||
#endif
|
||||
#ifdef EINPROGRESS
|
||||
errno == EINPROGRESS ||
|
||||
#endif
|
||||
#ifdef EALREADY
|
||||
errno == EALREADY ||
|
||||
#endif
|
||||
0;
|
||||
}
|
||||
@@ -1,235 +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_bio.h>
|
||||
|
||||
#if !defined(OPENSSL_NO_POSIX_IO)
|
||||
|
||||
#include <errno.h>
|
||||
#include <string.h>
|
||||
|
||||
#if !defined(OPENSSL_WINDOWS)
|
||||
#include <unistd.h>
|
||||
#else
|
||||
#include <io.h>
|
||||
#endif
|
||||
|
||||
#include <CCryptoBoringSSL_err.h>
|
||||
#include <CCryptoBoringSSL_mem.h>
|
||||
|
||||
#include "internal.h"
|
||||
#include "../internal.h"
|
||||
|
||||
|
||||
#if defined(OPENSSL_WINDOWS)
|
||||
#define BORINGSSL_CLOSE _close
|
||||
#define BORINGSSL_LSEEK _lseek
|
||||
#define BORINGSSL_READ _read
|
||||
#define BORINGSSL_WRITE _write
|
||||
#else
|
||||
#define BORINGSSL_CLOSE close
|
||||
#define BORINGSSL_LSEEK lseek
|
||||
#define BORINGSSL_READ read
|
||||
#define BORINGSSL_WRITE write
|
||||
#endif
|
||||
|
||||
BIO *BIO_new_fd(int fd, int close_flag) {
|
||||
BIO *ret = BIO_new(BIO_s_fd());
|
||||
if (ret == NULL) {
|
||||
return NULL;
|
||||
}
|
||||
BIO_set_fd(ret, fd, close_flag);
|
||||
return ret;
|
||||
}
|
||||
|
||||
static int fd_new(BIO *bio) {
|
||||
// num is used to store the file descriptor.
|
||||
bio->num = -1;
|
||||
return 1;
|
||||
}
|
||||
|
||||
static int fd_free(BIO *bio) {
|
||||
if (bio->shutdown) {
|
||||
if (bio->init) {
|
||||
BORINGSSL_CLOSE(bio->num);
|
||||
}
|
||||
bio->init = 0;
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
|
||||
static int fd_read(BIO *b, char *out, int outl) {
|
||||
int ret = 0;
|
||||
|
||||
ret = (int)BORINGSSL_READ(b->num, out, outl);
|
||||
BIO_clear_retry_flags(b);
|
||||
if (ret <= 0) {
|
||||
if (bio_errno_should_retry(ret)) {
|
||||
BIO_set_retry_read(b);
|
||||
}
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
static int fd_write(BIO *b, const char *in, int inl) {
|
||||
int ret = (int)BORINGSSL_WRITE(b->num, in, inl);
|
||||
BIO_clear_retry_flags(b);
|
||||
if (ret <= 0) {
|
||||
if (bio_errno_should_retry(ret)) {
|
||||
BIO_set_retry_write(b);
|
||||
}
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
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;
|
||||
case BIO_C_FILE_SEEK:
|
||||
ret = 0;
|
||||
if (b->init) {
|
||||
ret = (long)BORINGSSL_LSEEK(b->num, num, SEEK_SET);
|
||||
}
|
||||
break;
|
||||
case BIO_C_FILE_TELL:
|
||||
case BIO_CTRL_INFO:
|
||||
ret = 0;
|
||||
if (b->init) {
|
||||
ret = (long)BORINGSSL_LSEEK(b->num, 0, SEEK_CUR);
|
||||
}
|
||||
break;
|
||||
case BIO_C_SET_FD:
|
||||
fd_free(b);
|
||||
b->num = *((int *)ptr);
|
||||
b->shutdown = (int)num;
|
||||
b->init = 1;
|
||||
break;
|
||||
case BIO_C_GET_FD:
|
||||
if (b->init) {
|
||||
ip = (int *)ptr;
|
||||
if (ip != NULL) {
|
||||
*ip = b->num;
|
||||
}
|
||||
return b->num;
|
||||
} else {
|
||||
ret = -1;
|
||||
}
|
||||
break;
|
||||
case BIO_CTRL_GET_CLOSE:
|
||||
ret = b->shutdown;
|
||||
break;
|
||||
case BIO_CTRL_SET_CLOSE:
|
||||
b->shutdown = (int)num;
|
||||
break;
|
||||
case BIO_CTRL_PENDING:
|
||||
case BIO_CTRL_WPENDING:
|
||||
ret = 0;
|
||||
break;
|
||||
case BIO_CTRL_FLUSH:
|
||||
ret = 1;
|
||||
break;
|
||||
default:
|
||||
ret = 0;
|
||||
break;
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
static int fd_gets(BIO *bp, char *buf, int size) {
|
||||
if (size <= 0) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
char *ptr = buf;
|
||||
char *end = buf + size - 1;
|
||||
while (ptr < end && fd_read(bp, ptr, 1) > 0) {
|
||||
char c = ptr[0];
|
||||
ptr++;
|
||||
if (c == '\n') {
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
ptr[0] = '\0';
|
||||
|
||||
// The output length is bounded by |size|.
|
||||
return (int)(ptr - buf);
|
||||
}
|
||||
|
||||
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 */,
|
||||
};
|
||||
|
||||
const BIO_METHOD *BIO_s_fd(void) { return &methods_fdp; }
|
||||
|
||||
#endif // OPENSSL_NO_POSIX_IO
|
||||
|
||||
int BIO_set_fd(BIO *bio, int fd, int close_flag) {
|
||||
return (int)BIO_int_ctrl(bio, BIO_C_SET_FD, close_flag, fd);
|
||||
}
|
||||
|
||||
int BIO_get_fd(BIO *bio, int *out_fd) {
|
||||
return (int)BIO_ctrl(bio, BIO_C_GET_FD, 0, (char *) out_fd);
|
||||
}
|
||||
@@ -0,0 +1,179 @@
|
||||
// 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>
|
||||
|
||||
#if !defined(OPENSSL_NO_POSIX_IO)
|
||||
|
||||
#include <errno.h>
|
||||
#include <string.h>
|
||||
|
||||
#if !defined(OPENSSL_WINDOWS)
|
||||
#include <unistd.h>
|
||||
#else
|
||||
#include <io.h>
|
||||
#endif
|
||||
|
||||
#include <CCryptoBoringSSL_err.h>
|
||||
#include <CCryptoBoringSSL_mem.h>
|
||||
|
||||
#include "internal.h"
|
||||
#include "../internal.h"
|
||||
|
||||
|
||||
#if defined(OPENSSL_WINDOWS)
|
||||
#define BORINGSSL_CLOSE _close
|
||||
#define BORINGSSL_LSEEK _lseek
|
||||
#define BORINGSSL_READ _read
|
||||
#define BORINGSSL_WRITE _write
|
||||
#else
|
||||
#define BORINGSSL_CLOSE close
|
||||
#define BORINGSSL_LSEEK lseek
|
||||
#define BORINGSSL_READ read
|
||||
#define BORINGSSL_WRITE write
|
||||
#endif
|
||||
|
||||
BIO *BIO_new_fd(int fd, int close_flag) {
|
||||
BIO *ret = BIO_new(BIO_s_fd());
|
||||
if (ret == NULL) {
|
||||
return NULL;
|
||||
}
|
||||
BIO_set_fd(ret, fd, close_flag);
|
||||
return ret;
|
||||
}
|
||||
|
||||
static int fd_new(BIO *bio) {
|
||||
// num is used to store the file descriptor.
|
||||
bio->num = -1;
|
||||
return 1;
|
||||
}
|
||||
|
||||
static int fd_free(BIO *bio) {
|
||||
if (bio->shutdown) {
|
||||
if (bio->init) {
|
||||
BORINGSSL_CLOSE(bio->num);
|
||||
}
|
||||
bio->init = 0;
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
|
||||
static int fd_read(BIO *b, char *out, int outl) {
|
||||
int ret = 0;
|
||||
|
||||
ret = (int)BORINGSSL_READ(b->num, out, outl);
|
||||
BIO_clear_retry_flags(b);
|
||||
if (ret <= 0) {
|
||||
if (bio_errno_should_retry(ret)) {
|
||||
BIO_set_retry_read(b);
|
||||
}
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
static int fd_write(BIO *b, const char *in, int inl) {
|
||||
int ret = (int)BORINGSSL_WRITE(b->num, in, inl);
|
||||
BIO_clear_retry_flags(b);
|
||||
if (ret <= 0) {
|
||||
if (bio_errno_should_retry(ret)) {
|
||||
BIO_set_retry_write(b);
|
||||
}
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
static long fd_ctrl(BIO *b, int cmd, long num, void *ptr) {
|
||||
switch (cmd) {
|
||||
case BIO_CTRL_RESET:
|
||||
num = 0;
|
||||
[[fallthrough]];
|
||||
case BIO_C_FILE_SEEK:
|
||||
if (b->init) {
|
||||
return (long)BORINGSSL_LSEEK(b->num, num, SEEK_SET);
|
||||
}
|
||||
return 0;
|
||||
case BIO_C_FILE_TELL:
|
||||
case BIO_CTRL_INFO:
|
||||
if (b->init) {
|
||||
return (long)BORINGSSL_LSEEK(b->num, 0, SEEK_CUR);
|
||||
}
|
||||
return 0;
|
||||
case BIO_C_SET_FD:
|
||||
fd_free(b);
|
||||
b->num = *static_cast<int *>(ptr);
|
||||
b->shutdown = static_cast<int>(num);
|
||||
b->init = 1;
|
||||
return 1;
|
||||
case BIO_C_GET_FD:
|
||||
if (b->init) {
|
||||
int *out = static_cast<int *>(ptr);
|
||||
if (out != nullptr) {
|
||||
*out = b->num;
|
||||
}
|
||||
return b->num;
|
||||
} else {
|
||||
return -1;
|
||||
}
|
||||
case BIO_CTRL_GET_CLOSE:
|
||||
return b->shutdown;
|
||||
case BIO_CTRL_SET_CLOSE:
|
||||
b->shutdown = static_cast<int>(num);
|
||||
return 1;
|
||||
case BIO_CTRL_FLUSH:
|
||||
return 1;
|
||||
default:
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
static int fd_gets(BIO *bp, char *buf, int size) {
|
||||
if (size <= 0) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
char *ptr = buf;
|
||||
char *end = buf + size - 1;
|
||||
while (ptr < end && fd_read(bp, ptr, 1) > 0) {
|
||||
char c = ptr[0];
|
||||
ptr++;
|
||||
if (c == '\n') {
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
ptr[0] = '\0';
|
||||
|
||||
// The output length is bounded by |size|.
|
||||
return (int)(ptr - buf);
|
||||
}
|
||||
|
||||
static const BIO_METHOD methods_fdp = {
|
||||
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; }
|
||||
|
||||
#endif // OPENSSL_NO_POSIX_IO
|
||||
|
||||
int BIO_set_fd(BIO *bio, int fd, int close_flag) {
|
||||
return (int)BIO_int_ctrl(bio, BIO_C_SET_FD, close_flag, fd);
|
||||
}
|
||||
|
||||
int BIO_get_fd(BIO *bio, int *out_fd) {
|
||||
return (int)BIO_ctrl(bio, BIO_C_GET_FD, 0, (char *) out_fd);
|
||||
}
|
||||
+41
-98
@@ -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>
|
||||
@@ -143,7 +102,7 @@ static int file_free(BIO *bio) {
|
||||
}
|
||||
|
||||
if (bio->init && bio->ptr != NULL) {
|
||||
fclose(bio->ptr);
|
||||
fclose(reinterpret_cast<FILE *>(bio->ptr));
|
||||
bio->ptr = NULL;
|
||||
}
|
||||
bio->init = 0;
|
||||
@@ -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,
|
||||
@@ -208,16 +161,16 @@ static long file_ctrl(BIO *b, int cmd, long num, void *ptr) {
|
||||
// tested under POSIX will inadvertently change the state of |FILE|
|
||||
// objects when wrapping them in a |BIO|.
|
||||
if (num & BIO_FP_TEXT) {
|
||||
_setmode(_fileno(ptr), _O_TEXT);
|
||||
_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(ptr, mode);
|
||||
if (fp == NULL) {
|
||||
fp = fopen_if_available(reinterpret_cast<const char *>(ptr), mode);
|
||||
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,192 +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_bio.h>
|
||||
|
||||
#include <limits.h>
|
||||
#include <string.h>
|
||||
|
||||
#include "../internal.h"
|
||||
|
||||
|
||||
// hexdump_ctx contains the state of a hexdump.
|
||||
struct hexdump_ctx {
|
||||
BIO *bio;
|
||||
char right_chars[18]; // the contents of the right-hand side, ASCII dump.
|
||||
unsigned used; // number of bytes in the current line.
|
||||
size_t n; // number of bytes total.
|
||||
unsigned indent;
|
||||
};
|
||||
|
||||
static void hexbyte(char *out, uint8_t b) {
|
||||
static const char hextable[] = "0123456789abcdef";
|
||||
out[0] = hextable[b>>4];
|
||||
out[1] = hextable[b&0x0f];
|
||||
}
|
||||
|
||||
static char to_char(uint8_t b) {
|
||||
if (b < 32 || b > 126) {
|
||||
return '.';
|
||||
}
|
||||
return b;
|
||||
}
|
||||
|
||||
// hexdump_write adds |len| bytes of |data| to the current hex dump described by
|
||||
// |ctx|.
|
||||
static int hexdump_write(struct hexdump_ctx *ctx, const uint8_t *data,
|
||||
size_t len) {
|
||||
char buf[10];
|
||||
unsigned l;
|
||||
|
||||
// Output lines look like:
|
||||
// 00000010 2e 2f 30 31 32 33 34 35 36 37 38 ... 3c 3d // |./0123456789:;<=|
|
||||
// ^ offset ^ extra space ^ ASCII of line
|
||||
|
||||
for (size_t i = 0; i < len; i++) {
|
||||
if (ctx->used == 0) {
|
||||
// The beginning of a line.
|
||||
BIO_indent(ctx->bio, ctx->indent, UINT_MAX);
|
||||
|
||||
hexbyte(&buf[0], ctx->n >> 24);
|
||||
hexbyte(&buf[2], ctx->n >> 16);
|
||||
hexbyte(&buf[4], ctx->n >> 8);
|
||||
hexbyte(&buf[6], ctx->n);
|
||||
buf[8] = buf[9] = ' ';
|
||||
if (BIO_write(ctx->bio, buf, 10) < 0) {
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
hexbyte(buf, data[i]);
|
||||
buf[2] = ' ';
|
||||
l = 3;
|
||||
if (ctx->used == 7) {
|
||||
// There's an additional space after the 8th byte.
|
||||
buf[3] = ' ';
|
||||
l = 4;
|
||||
} else if (ctx->used == 15) {
|
||||
// At the end of the line there's an extra space and the bar for the
|
||||
// right column.
|
||||
buf[3] = ' ';
|
||||
buf[4] = '|';
|
||||
l = 5;
|
||||
}
|
||||
|
||||
if (BIO_write(ctx->bio, buf, l) < 0) {
|
||||
return 0;
|
||||
}
|
||||
ctx->right_chars[ctx->used] = to_char(data[i]);
|
||||
ctx->used++;
|
||||
ctx->n++;
|
||||
if (ctx->used == 16) {
|
||||
ctx->right_chars[16] = '|';
|
||||
ctx->right_chars[17] = '\n';
|
||||
if (BIO_write(ctx->bio, ctx->right_chars, sizeof(ctx->right_chars)) < 0) {
|
||||
return 0;
|
||||
}
|
||||
ctx->used = 0;
|
||||
}
|
||||
}
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
// finish flushes any buffered data in |ctx|.
|
||||
static int finish(struct hexdump_ctx *ctx) {
|
||||
// See the comments in |hexdump| for the details of this format.
|
||||
const unsigned n_bytes = ctx->used;
|
||||
unsigned l;
|
||||
char buf[5];
|
||||
|
||||
if (n_bytes == 0) {
|
||||
return 1;
|
||||
}
|
||||
|
||||
OPENSSL_memset(buf, ' ', 4);
|
||||
buf[4] = '|';
|
||||
|
||||
for (; ctx->used < 16; ctx->used++) {
|
||||
l = 3;
|
||||
if (ctx->used == 7) {
|
||||
l = 4;
|
||||
} else if (ctx->used == 15) {
|
||||
l = 5;
|
||||
}
|
||||
if (BIO_write(ctx->bio, buf, l) < 0) {
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
ctx->right_chars[n_bytes] = '|';
|
||||
ctx->right_chars[n_bytes + 1] = '\n';
|
||||
if (BIO_write(ctx->bio, ctx->right_chars, n_bytes + 2) < 0) {
|
||||
return 0;
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
|
||||
int BIO_hexdump(BIO *bio, const uint8_t *data, size_t len, unsigned indent) {
|
||||
struct hexdump_ctx ctx;
|
||||
OPENSSL_memset(&ctx, 0, sizeof(ctx));
|
||||
ctx.bio = bio;
|
||||
ctx.indent = indent;
|
||||
|
||||
if (!hexdump_write(&ctx, data, len) || !finish(&ctx)) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
return 1;
|
||||
}
|
||||
@@ -0,0 +1,152 @@
|
||||
// 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>
|
||||
|
||||
#include <limits.h>
|
||||
#include <string.h>
|
||||
|
||||
#include "../internal.h"
|
||||
|
||||
|
||||
namespace {
|
||||
// hexdump_ctx contains the state of a hexdump.
|
||||
struct hexdump_ctx {
|
||||
BIO *bio;
|
||||
char right_chars[18]; // the contents of the right-hand side, ASCII dump.
|
||||
unsigned used; // number of bytes in the current line.
|
||||
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];
|
||||
}
|
||||
|
||||
static char to_char(uint8_t b) {
|
||||
if (b < 32 || b > 126) {
|
||||
return '.';
|
||||
}
|
||||
return b;
|
||||
}
|
||||
|
||||
// hexdump_write adds |len| bytes of |data| to the current hex dump described by
|
||||
// |ctx|.
|
||||
static int hexdump_write(struct hexdump_ctx *ctx, const uint8_t *data,
|
||||
size_t len) {
|
||||
char buf[10];
|
||||
unsigned l;
|
||||
|
||||
// Output lines look like:
|
||||
// 00000010 2e 2f 30 31 32 33 34 35 36 37 38 ... 3c 3d // |./0123456789:;<=|
|
||||
// ^ offset ^ extra space ^ ASCII of line
|
||||
|
||||
for (size_t i = 0; i < len; i++) {
|
||||
if (ctx->used == 0) {
|
||||
// The beginning of a line.
|
||||
BIO_indent(ctx->bio, ctx->indent, UINT_MAX);
|
||||
|
||||
hexbyte(&buf[0], ctx->n >> 24);
|
||||
hexbyte(&buf[2], ctx->n >> 16);
|
||||
hexbyte(&buf[4], ctx->n >> 8);
|
||||
hexbyte(&buf[6], ctx->n);
|
||||
buf[8] = buf[9] = ' ';
|
||||
if (BIO_write(ctx->bio, buf, 10) < 0) {
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
hexbyte(buf, data[i]);
|
||||
buf[2] = ' ';
|
||||
l = 3;
|
||||
if (ctx->used == 7) {
|
||||
// There's an additional space after the 8th byte.
|
||||
buf[3] = ' ';
|
||||
l = 4;
|
||||
} else if (ctx->used == 15) {
|
||||
// At the end of the line there's an extra space and the bar for the
|
||||
// right column.
|
||||
buf[3] = ' ';
|
||||
buf[4] = '|';
|
||||
l = 5;
|
||||
}
|
||||
|
||||
if (BIO_write(ctx->bio, buf, l) < 0) {
|
||||
return 0;
|
||||
}
|
||||
ctx->right_chars[ctx->used] = to_char(data[i]);
|
||||
ctx->used++;
|
||||
ctx->n++;
|
||||
if (ctx->used == 16) {
|
||||
ctx->right_chars[16] = '|';
|
||||
ctx->right_chars[17] = '\n';
|
||||
if (BIO_write(ctx->bio, ctx->right_chars, sizeof(ctx->right_chars)) < 0) {
|
||||
return 0;
|
||||
}
|
||||
ctx->used = 0;
|
||||
}
|
||||
}
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
// finish flushes any buffered data in |ctx|.
|
||||
static int finish(struct hexdump_ctx *ctx) {
|
||||
// See the comments in |hexdump| for the details of this format.
|
||||
const unsigned n_bytes = ctx->used;
|
||||
unsigned l;
|
||||
char buf[5];
|
||||
|
||||
if (n_bytes == 0) {
|
||||
return 1;
|
||||
}
|
||||
|
||||
OPENSSL_memset(buf, ' ', 4);
|
||||
buf[4] = '|';
|
||||
|
||||
for (; ctx->used < 16; ctx->used++) {
|
||||
l = 3;
|
||||
if (ctx->used == 7) {
|
||||
l = 4;
|
||||
} else if (ctx->used == 15) {
|
||||
l = 5;
|
||||
}
|
||||
if (BIO_write(ctx->bio, buf, l) < 0) {
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
ctx->right_chars[n_bytes] = '|';
|
||||
ctx->right_chars[n_bytes + 1] = '\n';
|
||||
if (BIO_write(ctx->bio, ctx->right_chars, n_bytes + 2) < 0) {
|
||||
return 0;
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
|
||||
int BIO_hexdump(BIO *bio, const uint8_t *data, size_t len, unsigned indent) {
|
||||
struct hexdump_ctx ctx;
|
||||
OPENSSL_memset(&ctx, 0, sizeof(ctx));
|
||||
ctx.bio = bio;
|
||||
ctx.indent = indent;
|
||||
|
||||
if (!hexdump_write(&ctx, data, len) || !finish(&ctx)) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
return 1;
|
||||
}
|
||||
@@ -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
|
||||
+77
-116
@@ -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,9 +43,11 @@ 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 = OPENSSL_zalloc(sizeof *b);
|
||||
struct bio_bio_st *b =
|
||||
reinterpret_cast<bio_bio_st *>(OPENSSL_zalloc(sizeof *b));
|
||||
if (b == NULL) {
|
||||
return 0;
|
||||
}
|
||||
@@ -92,7 +58,7 @@ static int bio_new(BIO *bio) {
|
||||
}
|
||||
|
||||
static void bio_destroy_pair(BIO *bio) {
|
||||
struct bio_bio_st *b = bio->ptr;
|
||||
struct bio_bio_st *b = reinterpret_cast<bio_bio_st *>(bio->ptr);
|
||||
BIO *peer_bio;
|
||||
struct bio_bio_st *peer_b;
|
||||
|
||||
@@ -105,7 +71,7 @@ static void bio_destroy_pair(BIO *bio) {
|
||||
return;
|
||||
}
|
||||
|
||||
peer_b = peer_bio->ptr;
|
||||
peer_b = reinterpret_cast<bio_bio_st *>(peer_bio->ptr);
|
||||
|
||||
assert(peer_b != NULL);
|
||||
assert(peer_b->peer == bio);
|
||||
@@ -124,7 +90,7 @@ static void bio_destroy_pair(BIO *bio) {
|
||||
}
|
||||
|
||||
static int bio_free(BIO *bio) {
|
||||
struct bio_bio_st *b = bio->ptr;
|
||||
struct bio_bio_st *b = reinterpret_cast<bio_bio_st *>(bio->ptr);
|
||||
|
||||
assert(b != NULL);
|
||||
|
||||
@@ -149,10 +115,10 @@ static int bio_read(BIO *bio, char *buf, int size_) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
b = bio->ptr;
|
||||
b = reinterpret_cast<bio_bio_st *>(bio->ptr);
|
||||
assert(b != NULL);
|
||||
assert(b->peer != NULL);
|
||||
peer_b = b->peer->ptr;
|
||||
peer_b = reinterpret_cast<bio_bio_st *>(b->peer->ptr);
|
||||
assert(peer_b != NULL);
|
||||
assert(peer_b->buf != NULL);
|
||||
|
||||
@@ -233,7 +199,7 @@ static int bio_write(BIO *bio, const char *buf, int num_) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
b = bio->ptr;
|
||||
b = reinterpret_cast<bio_bio_st *>(bio->ptr);
|
||||
assert(b != NULL);
|
||||
assert(b->peer != NULL);
|
||||
assert(b->buf != NULL);
|
||||
@@ -302,8 +268,8 @@ static int bio_make_pair(BIO *bio1, BIO *bio2, size_t writebuf1_len,
|
||||
assert(bio1 != NULL);
|
||||
assert(bio2 != NULL);
|
||||
|
||||
b1 = bio1->ptr;
|
||||
b2 = bio2->ptr;
|
||||
b1 = reinterpret_cast<bio_bio_st *>(bio1->ptr);
|
||||
b2 = reinterpret_cast<bio_bio_st *>(bio2->ptr);
|
||||
|
||||
if (b1->peer != NULL || b2->peer != NULL) {
|
||||
OPENSSL_PUT_ERROR(BIO, BIO_R_IN_USE);
|
||||
@@ -314,7 +280,7 @@ static int bio_make_pair(BIO *bio1, BIO *bio2, size_t writebuf1_len,
|
||||
if (writebuf1_len) {
|
||||
b1->size = writebuf1_len;
|
||||
}
|
||||
b1->buf = OPENSSL_malloc(b1->size);
|
||||
b1->buf = reinterpret_cast<uint8_t *>(OPENSSL_malloc(b1->size));
|
||||
if (b1->buf == NULL) {
|
||||
return 0;
|
||||
}
|
||||
@@ -326,7 +292,7 @@ static int bio_make_pair(BIO *bio1, BIO *bio2, size_t writebuf1_len,
|
||||
if (writebuf2_len) {
|
||||
b2->size = writebuf2_len;
|
||||
}
|
||||
b2->buf = OPENSSL_malloc(b2->size);
|
||||
b2->buf = reinterpret_cast<uint8_t *>(OPENSSL_malloc(b2->size));
|
||||
if (b2->buf == NULL) {
|
||||
return 0;
|
||||
}
|
||||
@@ -348,34 +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 = bio->ptr;
|
||||
|
||||
assert(b != NULL);
|
||||
|
||||
struct bio_bio_st *b = reinterpret_cast<bio_bio_st *>(bio->ptr);
|
||||
assert(b != nullptr);
|
||||
switch (cmd) {
|
||||
// specific CTRL codes
|
||||
|
||||
// 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,74 +347,71 @@ 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;
|
||||
|
||||
// standard CTRL codes follow
|
||||
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) {
|
||||
struct bio_bio_st *peer_b = b->peer->ptr;
|
||||
ret = (long)peer_b->len;
|
||||
} else {
|
||||
ret = 0;
|
||||
if (b->peer != nullptr) {
|
||||
struct bio_bio_st *peer_b =
|
||||
reinterpret_cast<bio_bio_st *>(b->peer->ptr);
|
||||
// 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 = ptr;
|
||||
|
||||
if (other_bio) {
|
||||
struct bio_bio_st *other_b = 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; }
|
||||
|
||||
int BIO_new_bio_pair(BIO** bio1_p, size_t writebuf1_len,
|
||||
BIO** bio2_p, size_t writebuf2_len) {
|
||||
int BIO_new_bio_pair(BIO **bio1_p, size_t writebuf1_len, BIO **bio2_p,
|
||||
size_t writebuf2_len) {
|
||||
BIO *bio1 = BIO_new(bio_s_bio());
|
||||
BIO *bio2 = BIO_new(bio_s_bio());
|
||||
if (bio1 == NULL || bio2 == NULL ||
|
||||
@@ -1,102 +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_bio.h>
|
||||
|
||||
#include <assert.h>
|
||||
#include <stdarg.h>
|
||||
#include <stdio.h>
|
||||
|
||||
#include <CCryptoBoringSSL_err.h>
|
||||
#include <CCryptoBoringSSL_mem.h>
|
||||
|
||||
int BIO_printf(BIO *bio, const char *format, ...) {
|
||||
va_list args;
|
||||
char buf[256], *out, out_malloced = 0;
|
||||
int out_len, ret;
|
||||
|
||||
va_start(args, format);
|
||||
out_len = vsnprintf(buf, sizeof(buf), format, args);
|
||||
va_end(args);
|
||||
if (out_len < 0) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
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.
|
||||
out = OPENSSL_malloc(requested_len + 1);
|
||||
out_malloced = 1;
|
||||
if (out == NULL) {
|
||||
return -1;
|
||||
}
|
||||
va_start(args, format);
|
||||
out_len = vsnprintf(out, requested_len + 1, format, args);
|
||||
va_end(args);
|
||||
assert(out_len == requested_len);
|
||||
} else {
|
||||
out = buf;
|
||||
}
|
||||
|
||||
ret = BIO_write(bio, out, out_len);
|
||||
if (out_malloced) {
|
||||
OPENSSL_free(out);
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
@@ -0,0 +1,59 @@
|
||||
// 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>
|
||||
|
||||
#include <assert.h>
|
||||
#include <stdarg.h>
|
||||
#include <stdio.h>
|
||||
|
||||
#include <CCryptoBoringSSL_err.h>
|
||||
#include <CCryptoBoringSSL_mem.h>
|
||||
|
||||
int BIO_printf(BIO *bio, const char *format, ...) {
|
||||
va_list args;
|
||||
char buf[256], *out, out_malloced = 0;
|
||||
int out_len, ret;
|
||||
|
||||
va_start(args, format);
|
||||
out_len = vsnprintf(buf, sizeof(buf), format, args);
|
||||
va_end(args);
|
||||
if (out_len < 0) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
if ((size_t)out_len >= sizeof(buf)) {
|
||||
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) {
|
||||
return -1;
|
||||
}
|
||||
va_start(args, format);
|
||||
out_len = vsnprintf(out, requested_len + 1, format, args);
|
||||
va_end(args);
|
||||
assert(out_len == (int)requested_len);
|
||||
} else {
|
||||
out = buf;
|
||||
}
|
||||
|
||||
ret = BIO_write(bio, out, out_len);
|
||||
if (out_malloced) {
|
||||
OPENSSL_free(out);
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
@@ -1,189 +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_bio.h>
|
||||
|
||||
#if !defined(OPENSSL_NO_SOCK)
|
||||
|
||||
#include <fcntl.h>
|
||||
#include <string.h>
|
||||
|
||||
#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
|
||||
|
||||
#include "internal.h"
|
||||
|
||||
|
||||
#if !defined(OPENSSL_WINDOWS)
|
||||
static int closesocket(int sock) {
|
||||
return close(sock);
|
||||
}
|
||||
#endif
|
||||
|
||||
static int sock_free(BIO *bio) {
|
||||
if (bio->shutdown) {
|
||||
if (bio->init) {
|
||||
closesocket(bio->num);
|
||||
}
|
||||
bio->init = 0;
|
||||
bio->flags = 0;
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
|
||||
static int sock_read(BIO *b, char *out, int outl) {
|
||||
if (out == NULL) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
bio_clear_socket_error();
|
||||
#if defined(OPENSSL_WINDOWS)
|
||||
int ret = recv(b->num, out, outl, 0);
|
||||
#else
|
||||
int ret = (int)read(b->num, out, outl);
|
||||
#endif
|
||||
BIO_clear_retry_flags(b);
|
||||
if (ret <= 0) {
|
||||
if (bio_socket_should_retry(ret)) {
|
||||
BIO_set_retry_read(b);
|
||||
}
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
static int sock_write(BIO *b, const char *in, int inl) {
|
||||
bio_clear_socket_error();
|
||||
#if defined(OPENSSL_WINDOWS)
|
||||
int ret = send(b->num, in, inl, 0);
|
||||
#else
|
||||
int ret = (int)write(b->num, in, inl);
|
||||
#endif
|
||||
BIO_clear_retry_flags(b);
|
||||
if (ret <= 0) {
|
||||
if (bio_socket_should_retry(ret)) {
|
||||
BIO_set_retry_write(b);
|
||||
}
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
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->init = 1;
|
||||
break;
|
||||
case BIO_C_GET_FD:
|
||||
if (b->init) {
|
||||
ip = (int *)ptr;
|
||||
if (ip != NULL) {
|
||||
*ip = b->num;
|
||||
}
|
||||
ret = b->num;
|
||||
} else {
|
||||
ret = -1;
|
||||
}
|
||||
break;
|
||||
case BIO_CTRL_GET_CLOSE:
|
||||
ret = b->shutdown;
|
||||
break;
|
||||
case BIO_CTRL_SET_CLOSE:
|
||||
b->shutdown = (int)num;
|
||||
break;
|
||||
case BIO_CTRL_FLUSH:
|
||||
ret = 1;
|
||||
break;
|
||||
default:
|
||||
ret = 0;
|
||||
break;
|
||||
}
|
||||
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 */,
|
||||
};
|
||||
|
||||
const BIO_METHOD *BIO_s_socket(void) { return &methods_sockp; }
|
||||
|
||||
BIO *BIO_new_socket(int fd, int close_flag) {
|
||||
BIO *ret;
|
||||
|
||||
ret = BIO_new(BIO_s_socket());
|
||||
if (ret == NULL) {
|
||||
return NULL;
|
||||
}
|
||||
BIO_set_fd(ret, fd, close_flag);
|
||||
return ret;
|
||||
}
|
||||
|
||||
#endif // OPENSSL_NO_SOCK
|
||||
@@ -0,0 +1,210 @@
|
||||
// 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>
|
||||
|
||||
#if !defined(OPENSSL_NO_SOCK)
|
||||
|
||||
#include <fcntl.h>
|
||||
#include <string.h>
|
||||
|
||||
#if !defined(OPENSSL_WINDOWS)
|
||||
#include <unistd.h>
|
||||
#else
|
||||
#include <winsock2.h>
|
||||
OPENSSL_MSVC_PRAGMA(comment(lib, "Ws2_32.lib"))
|
||||
#endif
|
||||
|
||||
#include "internal.h"
|
||||
|
||||
|
||||
#if !defined(OPENSSL_WINDOWS)
|
||||
static int closesocket(int sock) {
|
||||
return close(sock);
|
||||
}
|
||||
#endif
|
||||
|
||||
static int sock_free(BIO *bio) {
|
||||
if (bio->shutdown) {
|
||||
if (bio->init) {
|
||||
closesocket(bio->num);
|
||||
}
|
||||
bio->init = 0;
|
||||
bio->flags = 0;
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
|
||||
static int sock_read(BIO *b, char *out, int outl) {
|
||||
if (out == NULL) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
bio_clear_socket_error();
|
||||
#if defined(OPENSSL_WINDOWS)
|
||||
int ret = recv(b->num, out, outl, 0);
|
||||
#else
|
||||
int ret = (int)read(b->num, out, outl);
|
||||
#endif
|
||||
BIO_clear_retry_flags(b);
|
||||
if (ret <= 0) {
|
||||
if (bio_socket_should_retry(ret)) {
|
||||
BIO_set_retry_read(b);
|
||||
}
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
static int sock_write(BIO *b, const char *in, int inl) {
|
||||
bio_clear_socket_error();
|
||||
#if defined(OPENSSL_WINDOWS)
|
||||
int ret = send(b->num, in, inl, 0);
|
||||
#else
|
||||
int ret = (int)write(b->num, in, inl);
|
||||
#endif
|
||||
BIO_clear_retry_flags(b);
|
||||
if (ret <= 0) {
|
||||
if (bio_socket_should_retry(ret)) {
|
||||
BIO_set_retry_write(b);
|
||||
}
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
static long sock_ctrl(BIO *b, int cmd, long num, void *ptr) {
|
||||
switch (cmd) {
|
||||
case BIO_C_SET_FD:
|
||||
sock_free(b);
|
||||
b->num = *static_cast<int *>(ptr);
|
||||
b->shutdown = static_cast<int>(num);
|
||||
b->init = 1;
|
||||
return 1;
|
||||
case BIO_C_GET_FD:
|
||||
if (b->init) {
|
||||
int *out = static_cast<int*>(ptr);
|
||||
if (out != nullptr) {
|
||||
*out = b->num;
|
||||
}
|
||||
return b->num;
|
||||
}
|
||||
return -1;
|
||||
case BIO_CTRL_GET_CLOSE:
|
||||
return b->shutdown;
|
||||
case BIO_CTRL_SET_CLOSE:
|
||||
b->shutdown = static_cast<int>(num);
|
||||
return 1;
|
||||
case BIO_CTRL_FLUSH:
|
||||
return 1;
|
||||
default:
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
static const BIO_METHOD methods_sockp = {
|
||||
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; }
|
||||
|
||||
BIO *BIO_new_socket(int fd, int close_flag) {
|
||||
BIO *ret;
|
||||
|
||||
ret = BIO_new(BIO_s_socket());
|
||||
if (ret == NULL) {
|
||||
return NULL;
|
||||
}
|
||||
BIO_set_fd(ret, fd, 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
|
||||
+13
-15
@@ -1,16 +1,16 @@
|
||||
/* Copyright (c) 2014, Google Inc.
|
||||
*
|
||||
* Permission to use, copy, modify, and/or distribute this software for any
|
||||
* purpose with or without fee is hereby granted, provided that the above
|
||||
* copyright notice and this permission notice appear in all copies.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
|
||||
* WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
|
||||
* MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
|
||||
* SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
|
||||
* WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION
|
||||
* OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
|
||||
* CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. */
|
||||
// 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"
|
||||
+20
-18
@@ -1,21 +1,23 @@
|
||||
/* Copyright (c) 2021, Google Inc.
|
||||
*
|
||||
* Permission to use, copy, modify, and/or distribute this software for any
|
||||
* purpose with or without fee is hereby granted, provided that the above
|
||||
* copyright notice and this permission notice appear in all copies.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
|
||||
* WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
|
||||
* MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
|
||||
* SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
|
||||
* WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION
|
||||
* OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
|
||||
* CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. */
|
||||
// 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>
|
||||
|
||||
#include <assert.h>
|
||||
|
||||
#include <iterator>
|
||||
|
||||
#include "../internal.h"
|
||||
|
||||
// https://tools.ietf.org/html/rfc7693#section-2.6
|
||||
@@ -64,7 +66,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));
|
||||
|
||||
@@ -99,7 +101,7 @@ static void blake2b_transform(BLAKE2B_CTX *b2b,
|
||||
blake2b_load(block, s[15]));
|
||||
}
|
||||
|
||||
for (size_t i = 0; i < OPENSSL_ARRAY_SIZE(b2b->h); i++) {
|
||||
for (size_t i = 0; i < std::size(b2b->h); i++) {
|
||||
b2b->h[i] ^= v[i];
|
||||
b2b->h[i] ^= v[i + 8];
|
||||
}
|
||||
@@ -108,7 +110,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
|
||||
@@ -121,7 +123,7 @@ void BLAKE2B256_Update(BLAKE2B_CTX *b2b, const void *in_data, size_t len) {
|
||||
return;
|
||||
}
|
||||
|
||||
const uint8_t *data = in_data;
|
||||
const uint8_t *data = reinterpret_cast<const uint8_t *>(in_data);
|
||||
size_t todo = sizeof(b2b->block) - b2b->block_used;
|
||||
if (todo > len) {
|
||||
todo = len;
|
||||
@@ -156,7 +158,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 (c) 2015, Google Inc.
|
||||
*
|
||||
* Permission to use, copy, modify, and/or distribute this software for any
|
||||
* purpose with or without fee is hereby granted, provided that the above
|
||||
* copyright notice and this permission notice appear in all copies.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
|
||||
* WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
|
||||
* MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
|
||||
* SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
|
||||
* WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION
|
||||
* OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
|
||||
* CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. */
|
||||
// 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>
|
||||
|
||||
+63
-121
@@ -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>
|
||||
@@ -78,8 +38,9 @@ static const char hextable[] = "0123456789abcdef";
|
||||
|
||||
char *BN_bn2hex(const BIGNUM *bn) {
|
||||
int width = bn_minimal_width(bn);
|
||||
char *buf = OPENSSL_malloc(1 /* leading '-' */ + 1 /* zero is non-empty */ +
|
||||
width * BN_BYTES * 2 + 1 /* trailing NUL */);
|
||||
char *buf = reinterpret_cast<char *>(
|
||||
OPENSSL_malloc(1 /* leading '-' */ + 1 /* zero is non-empty */ +
|
||||
width * BN_BYTES * 2 + 1 /* trailing NUL */));
|
||||
if (buf == NULL) {
|
||||
return NULL;
|
||||
}
|
||||
@@ -112,7 +73,7 @@ char *BN_bn2hex(const BIGNUM *bn) {
|
||||
|
||||
// decode_hex decodes |in_len| bytes of hex data from |in| and updates |bn|.
|
||||
static int decode_hex(BIGNUM *bn, const char *in, int in_len) {
|
||||
if (in_len > INT_MAX/4) {
|
||||
if (in_len > INT_MAX / 4) {
|
||||
OPENSSL_PUT_ERROR(BN, BN_R_BIGNUM_TOO_LONG);
|
||||
return 0;
|
||||
}
|
||||
@@ -163,8 +124,7 @@ static int decode_dec(BIGNUM *bn, const char *in, int in_len) {
|
||||
l *= 10;
|
||||
l += in[i] - '0';
|
||||
if (++j == BN_DEC_NUM) {
|
||||
if (!BN_mul_word(bn, BN_DEC_CONV) ||
|
||||
!BN_add_word(bn, l)) {
|
||||
if (!BN_mul_word(bn, BN_DEC_CONV) || !BN_add_word(bn, l)) {
|
||||
return 0;
|
||||
}
|
||||
l = 0;
|
||||
@@ -174,10 +134,11 @@ static int decode_dec(BIGNUM *bn, const char *in, int in_len) {
|
||||
return 1;
|
||||
}
|
||||
|
||||
typedef int (*decode_func) (BIGNUM *bn, const char *in, int in_len);
|
||||
typedef int (*char_test_func) (int c);
|
||||
typedef int (*decode_func)(BIGNUM *bn, const char *in, int in_len);
|
||||
typedef int (*char_test_func)(int c);
|
||||
|
||||
static int bn_x2bn(BIGNUM **outp, const char *in, decode_func decode, char_test_func want_char) {
|
||||
static int bn_x2bn(BIGNUM **outp, const char *in, decode_func decode,
|
||||
char_test_func want_char) {
|
||||
BIGNUM *ret = NULL;
|
||||
int neg = 0, i;
|
||||
int num;
|
||||
@@ -191,7 +152,8 @@ static int bn_x2bn(BIGNUM **outp, const char *in, decode_func decode, char_test_
|
||||
in++;
|
||||
}
|
||||
|
||||
for (i = 0; want_char((unsigned char)in[i]) && i + neg < INT_MAX; i++) {}
|
||||
for (i = 0; want_char((unsigned char)in[i]) && i + neg < INT_MAX; i++) {
|
||||
}
|
||||
|
||||
num = i + neg;
|
||||
if (outp == NULL) {
|
||||
@@ -236,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;
|
||||
}
|
||||
@@ -270,31 +231,19 @@ char *BN_bn2dec(const BIGNUM *a) {
|
||||
}
|
||||
}
|
||||
|
||||
if (BN_is_negative(a) &&
|
||||
!CBB_add_u8(&cbb, '-')) {
|
||||
goto err;
|
||||
if (BN_is_negative(a) && //
|
||||
!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) {
|
||||
@@ -308,7 +257,7 @@ int BN_asc2bn(BIGNUM **outp, const char *in) {
|
||||
}
|
||||
|
||||
if (in[0] == '0' && (in[1] == 'X' || in[1] == 'x')) {
|
||||
if (!BN_hex2bn(outp, in+2)) {
|
||||
if (!BN_hex2bn(outp, in + 2)) {
|
||||
return 0;
|
||||
}
|
||||
} else {
|
||||
@@ -325,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) {
|
||||
@@ -377,9 +321,7 @@ size_t BN_bn2mpi(const BIGNUM *in, uint8_t *out) {
|
||||
}
|
||||
|
||||
const size_t len = bytes + extend;
|
||||
if (len < bytes ||
|
||||
4 + len < len ||
|
||||
(len & 0xffffffff) != len) {
|
||||
if (len < bytes || 4 + len < len || (len & 0xffffffff) != len) {
|
||||
// If we cannot represent the number then we emit zero as the interface
|
||||
// doesn't allow an error to be signalled.
|
||||
if (out) {
|
||||
@@ -411,9 +353,9 @@ BIGNUM *BN_mpi2bn(const uint8_t *in, size_t len, BIGNUM *out) {
|
||||
OPENSSL_PUT_ERROR(BN, BN_R_BAD_ENCODING);
|
||||
return NULL;
|
||||
}
|
||||
const size_t in_len = ((size_t)in[0] << 24) |
|
||||
((size_t)in[1] << 16) |
|
||||
((size_t)in[2] << 8) |
|
||||
const size_t in_len = ((size_t)in[0] << 24) | //
|
||||
((size_t)in[1] << 16) | //
|
||||
((size_t)in[2] << 8) | //
|
||||
((size_t)in[3]);
|
||||
if (in_len != len - 4) {
|
||||
OPENSSL_PUT_ERROR(BN, BN_R_BAD_ENCODING);
|
||||
@@ -449,7 +391,7 @@ BIGNUM *BN_mpi2bn(const uint8_t *in, size_t len, BIGNUM *out) {
|
||||
}
|
||||
|
||||
int BN_bn2binpad(const BIGNUM *in, uint8_t *out, int len) {
|
||||
if (len < 0 ||
|
||||
if (len < 0 || //
|
||||
!BN_bn2bin_padded(out, (size_t)len, in)) {
|
||||
return -1;
|
||||
}
|
||||
@@ -457,7 +399,7 @@ int BN_bn2binpad(const BIGNUM *in, uint8_t *out, int len) {
|
||||
}
|
||||
|
||||
int BN_bn2lebinpad(const BIGNUM *in, uint8_t *out, int len) {
|
||||
if (len < 0 ||
|
||||
if (len < 0 || //
|
||||
!BN_bn2le_padded(out, (size_t)len, in)) {
|
||||
return -1;
|
||||
}
|
||||
@@ -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;
|
||||
}
|
||||
Loaded 100 of 1191 files, more files were not shown because too many files have changed in this diff.
Show more
Reference in new issue
Block a user