mirror of
https://github.com/apple/swift-crypto
synced 2026-11-22 04:30:39 +00:00
Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
9b9d186860 | ||
|
|
0a0b1d50e9 | ||
|
|
cce48362a4 | ||
|
|
d67ac68d09 | ||
|
|
0473010f58 | ||
|
|
20053871fa | ||
|
|
b6b60c3938 | ||
|
|
64a1a98e47 | ||
|
|
3be1b8cbd4 | ||
|
|
77b30226ac | ||
|
|
de232cbd67 | ||
|
|
36ea42cbb3 | ||
|
|
5000bef967 | ||
|
|
d237bf149c | ||
|
|
94930a7edf | ||
|
|
12e6f9ef3a | ||
|
|
132b8e5fd1 | ||
|
|
fced1f801f | ||
|
|
bfb37dfb92 |
No files matched your search
@@ -0,0 +1 @@
|
||||
Sources/CCryptoBoringSSL/* linguist-vendored
|
||||
@@ -1,20 +0,0 @@
|
||||
### Expected behavior
|
||||
_[what you expected to happen]_
|
||||
|
||||
### Actual behavior
|
||||
_[what actually happened]_
|
||||
|
||||
### Steps to reproduce
|
||||
|
||||
1. ...
|
||||
2. ...
|
||||
|
||||
### If possible, minimal yet complete reproducer code (or URL to code)
|
||||
|
||||
_[anything to help us reproducing the issue]_
|
||||
|
||||
### SwiftLog version/commit hash
|
||||
|
||||
_[the SwiftLog tag/commit hash]_
|
||||
|
||||
### Swift & OS version (output of `swift --version && uname -a`)
|
||||
Executable
+40
@@ -0,0 +1,40 @@
|
||||
---
|
||||
name: 🐛 Bug Report
|
||||
about: If something isn't working as expected
|
||||
|
||||
---
|
||||
|
||||
<!-- Thanks for contributing to Swift Crypto! Before you submit your issue, please make sure you followed our checklist and check the appropriate boxes by putting an x in the [ ]: [x] -->
|
||||
|
||||
### New Issue 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 searched for [existing GitHub issues](https://github.com/apple/swift-crypto/issues)
|
||||
|
||||
### Expected behavior
|
||||
_[what you expected to happen]_
|
||||
|
||||
### Actual behavior
|
||||
_[what actually happened]_
|
||||
|
||||
### Steps to reproduce
|
||||
|
||||
1. ...
|
||||
2. ...
|
||||
|
||||
### If possible, minimal yet complete reproducer code (or URL to code)
|
||||
|
||||
_[anything to help us reproducing the issue]_
|
||||
|
||||
### Swift Crypto version/commit hash
|
||||
|
||||
_[the Swift Crypto tag/commit hash]_
|
||||
|
||||
### Environment
|
||||
|
||||
Stand in the root of the repo and run `./scripts/environments.sh` and paste the output below
|
||||
|
||||
<details>
|
||||
<pre>PLEASE_REPLACE_THIS_STIRNG_WITH_OUTPUT_OF_script_environments_THAT_IS_IN_YOUR_PASTEBOARD</pre>
|
||||
</details>
|
||||
Executable
+15
@@ -0,0 +1,15 @@
|
||||
---
|
||||
name: 💡 Feature Request
|
||||
about: A suggestion for a new feature
|
||||
|
||||
---
|
||||
|
||||
### New API Proposal: <Feature Name>
|
||||
|
||||
#### Motivation:
|
||||
|
||||
<What use-case is this API proposal trying to serve? Are there any protocols in existence that require this API? If so, which? Please provide links to specifications where applicable, or peer implementations when attempting to perform interop work.>
|
||||
|
||||
#### Importance:
|
||||
|
||||
<Does this API unlock entirely new use-cases, or is it possible to achieve the same functionality with existing API, but in easier ways?>
|
||||
Executable
+18
@@ -0,0 +1,18 @@
|
||||
---
|
||||
name: ❓ Support Question
|
||||
about: Not sure how something works or how to implement some functionality? Ask us here! (But please check the docs first)
|
||||
|
||||
---
|
||||
|
||||
### 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 searched for [existing GitHub issues](https://github.com/apple/swift-crypto/issues)
|
||||
|
||||
### Question Subject
|
||||
<!-- What tool/action do you have a question about? -->
|
||||
<!-- Is this a question about documentation? -->
|
||||
|
||||
#### Question Description
|
||||
<!-- Please include expected behavior and any relevant code samples with your question if possible -->
|
||||
Executable
+33
@@ -0,0 +1,33 @@
|
||||
---
|
||||
name: 😱 Regression
|
||||
about: If a recent release broke a feature (Please make sure you know the last known working release version)
|
||||
|
||||
---
|
||||
|
||||
<!-- Thanks for contributing to Swift Crypto! Before you submit your issue, please make sure you followed our checklist and check the appropriate boxes by putting an x in the [ ]: [x] -->
|
||||
|
||||
### 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 searched for [existing GitHub issues](https://github.com/apple/swift-crypto/issues)
|
||||
|
||||
### Regression Information
|
||||
<!-- Knowing the breaking versions and last working versions helps us track down the regression easier -->
|
||||
- Breaking version: [e.g. `2.x.x`]
|
||||
- Last working version: [e.g. `2.x.x`]
|
||||
|
||||
### Regression Description
|
||||
<!-- Please include what's happening, expected behavior, and any relevant code samples -->
|
||||
|
||||
### Swift Crypto version/commit hash
|
||||
|
||||
_[the Swift Crypto tag/commit hash]_
|
||||
|
||||
### Environment
|
||||
|
||||
Stand in the root of the repo and run `./scripts/environments.sh` and paste the output below
|
||||
|
||||
<details>
|
||||
<pre>PLEASE_REPLACE_THIS_STIRNG_WITH_OUTPUT_OF_script_environments_THAT_IS_IN_YOUR_PASTEBOARD</pre>
|
||||
</details>
|
||||
@@ -1,5 +1,16 @@
|
||||
_[One line description of your change]_
|
||||
|
||||
<!-- Thanks for contributing to Swift Crypto! Before you submit your issue, please make sure you followed our checklist and check the appropriate boxes by putting an x in the [ ]: [x] -->
|
||||
|
||||
### Checklist
|
||||
- [ ] I've run tests to see all new and existing tests pass
|
||||
- [ ] I've followed the code style of the rest of the project
|
||||
- [ ] I've read the [Contribution Guidelines](CONTRIBUTING.md)
|
||||
- [ ] 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
|
||||
|
||||
### Motivation:
|
||||
|
||||
_[Explain here the context, and why you're making that change. What is the problem you're trying to solve.]_
|
||||
@@ -10,4 +21,4 @@ _[Describe the modifications you've done.]_
|
||||
|
||||
### Result:
|
||||
|
||||
_[After your change, what will change.]_
|
||||
_[After your change, what will change.]_
|
||||
@@ -10,3 +10,4 @@ Package.resolved
|
||||
.podspecs
|
||||
DerivedData
|
||||
.swiftpm
|
||||
**/gyb.pyc
|
||||
@@ -0,0 +1,2 @@
|
||||
Alexander Cyon <alex.cyon@gmail.com> <Sajjon@users.noreply.github.com>
|
||||
Tomer Doron <tomer@apple.com>
|
||||
+1
-1
@@ -1,5 +1,6 @@
|
||||
# file options
|
||||
|
||||
--swiftversion 5.0
|
||||
--exclude .build
|
||||
|
||||
# format options
|
||||
@@ -7,7 +8,6 @@
|
||||
--self insert
|
||||
--patternlet inline
|
||||
--stripunusedargs unnamed-only
|
||||
--comments ignore
|
||||
--ifdef no-indent
|
||||
|
||||
# rules
|
||||
@@ -0,0 +1,5 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
|
||||
<plist version="1.0">
|
||||
<array/>
|
||||
</plist>
|
||||
@@ -11,8 +11,13 @@ needs to be listed here.
|
||||
|
||||
### Contributors
|
||||
|
||||
- Alexander Cyon <alex.cyon@gmail.com>
|
||||
- Austin Conlon <austinconlon@icloud.com>
|
||||
- Cory Benfield <lukasa@apple.com>
|
||||
- George Barnett <gbrntt@gmail.com>
|
||||
- Tomer Doron <tomer@apple.com>
|
||||
|
||||
**Updating this list**
|
||||
## Updating this list
|
||||
|
||||
Please do not edit this file manually. It is generated using `./scripts/generate_contributors_list.sh`. If a name is misspelled or appearing multiple times: add an entry in `./.mailmap`
|
||||
Please do not edit this file manually. It is generated using `./scripts/generate_contributors_list.sh`.
|
||||
If a name is misspelled or appearing multiple times: add an entry in `./.mailmap` (see [docs](https://git-scm.com/docs/git-shortlog#_mapping_authors))
|
||||
+2
-2
@@ -7,7 +7,7 @@
|
||||
// Licensed under Apache License v2.0
|
||||
//
|
||||
// See LICENSE.txt for license information
|
||||
// See CONTRIBUTORS.txt for the list of SwiftCrypto project authors
|
||||
// See CONTRIBUTORS.md for the list of SwiftCrypto project authors
|
||||
//
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
//
|
||||
@@ -20,7 +20,7 @@
|
||||
// Sources/CCryptoBoringSSL directory. The source repository is at
|
||||
// https://boringssl.googlesource.com/boringssl.
|
||||
//
|
||||
// BoringSSL Commit: 0416e8c3055c7fcfd6c3eab4c127a36df1e6097b
|
||||
// BoringSSL Commit: 53a17f55247101105ae35767d5c5a6c311843a8e
|
||||
|
||||
import PackageDescription
|
||||
|
||||
|
||||
@@ -1,84 +1,112 @@
|
||||
# SwiftCrypto
|
||||
# Swift Crypto
|
||||
|
||||
SwiftCrypto 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 platforms. It enables cross-platform or server applications with the advantages of CryptoKit.
|
||||
|
||||
## Functionality
|
||||
|
||||
SwiftCrypto exposes the portions of the CryptoKit API that do not rely on specialised hardware to any Swift application. It provides safe APIs that abstract over the complexity of many cryptographic primitives that need to be used in modern applications. These APIs encourage safe usages of the underlying primitives, follow cryptographic best practices, and should be the first choice for building applications that need to use cryptography.
|
||||
Swift Crypto exposes the portions of the CryptoKit API that do not rely on specialised hardware to any Swift application. It provides safe APIs that abstract over the complexity of many cryptographic primitives that need to be used in modern applications. These APIs encourage safe usages of the underlying primitives, follow cryptographic best practices, and should be the first choice for building applications that need to use cryptography.
|
||||
|
||||
The current features of SwiftCrypto cover key exchange, key derivation, encryption and decryption, hashing, message authentication, and more.
|
||||
The current features of Swift Crypto cover key exchange, key derivation, encryption and decryption, hashing, message authentication, and more.
|
||||
|
||||
For specific API documentation, please see our documentation.
|
||||
|
||||
## Implementation
|
||||
|
||||
SwiftCrypto compiles in two distinct modes depending on the platform for which it is being built.
|
||||
Swift Crypto compiles in two distinct modes depending on the platform for which it is being built.
|
||||
|
||||
When building SwiftCrypto for use on an Apple platform where CryptoKit is already available, SwiftCrypto compiles its entire API surface down to nothing and simply re-exports the API of CryptoKit. This means that when using Apple platforms SwiftCrypto simply delegates all work to the core implementation of CryptoKit, as though SwiftCrypto was not even there.
|
||||
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 SwiftCrypto for use on Linux, SwiftCrypto builds substantially more code. In particular, we build:
|
||||
When building Swift Crypto for use on Linux, Swift Crypto builds substantially more code. In particular, we build:
|
||||
|
||||
1. A vendored copy of BoringSSL's libcrypto.
|
||||
2. The common API of SwiftCrypto and CryptoKit.
|
||||
2. The common API of Swift Crypto and CryptoKit.
|
||||
3. The backing implementation of this common API, which calls into BoringSSL.
|
||||
|
||||
The API code, and some cryptographic primitives which are directly implemented in Swift, are exactly the same for both Apple CryptoKit and SwiftCrypto. The backing BoringSSL-based implementation is unique to SwiftCrypto.
|
||||
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.
|
||||
|
||||
## Evolution
|
||||
|
||||
The vast majority of the SwiftCrypto code is intended to remain in lockstep with the current version of Apple CryptoKit. For this reason, patches that extend the API of SwiftCrypto will be evaluated cautiously. For any such extension there are two possible outcomes for adding the API.
|
||||
The vast majority of the Swift Crypto code is intended to remain in lockstep with the current version of Apple CryptoKit. For this reason, patches that extend the API of Swift Crypto will be evaluated cautiously. For any such extension there are two possible outcomes for adding the API.
|
||||
|
||||
Firstly, if the API is judged to be generally valuable and suitable for contribution to Apple CryptoKit, the API will be merged into a Staging namespace in SwiftCrypto. This Staging namespace is a temporary home for any API that is expected to become available in Apple CryptoKit but that is not available today. This enables users to use the API soon after merging. When the API is generally available in CryptoKit the API will be deprecated in the Staging namespace and made available in the main SwiftCrypto namespace.
|
||||
Firstly, if the API is judged to be generally valuable and suitable for contribution to Apple CryptoKit, the API will be merged into a Staging namespace in Swift Crypto. This Staging namespace is a temporary home for any API that is expected to become available in Apple CryptoKit but that is not available today. This enables users to use the API soon after merging. When the API is generally available in CryptoKit the API will be deprecated in the Staging namespace and made available in the main Swift Crypto namespace.
|
||||
|
||||
Secondly, if the API is judged not to meet the criteria for acceptance in general CryptoKit but is sufficiently important to have available for server use-cases, it will be merged into a Server namespace. APIs are not expected to leave this namespace, as it indicates that they are not generally available but can only be accessed when using SwiftCrypto.
|
||||
Secondly, if the API is judged not to meet the criteria for acceptance in general CryptoKit but is sufficiently important to have available for server use-cases, it will be merged into a Server namespace. APIs are not expected to leave this namespace, as it indicates that they are not generally available but can only be accessed when using Swift Crypto.
|
||||
|
||||
Note that SwiftCrypto does not intend to support all possible cryptographic primitives. SwiftCrypto will focus on safe, modern cryptographic primitives that are broadly useful and that do not easily lend themselves to misuse. This means that some cryptographic algorithms may never be supported: for example, 3DES is highly unlikely to ever be supported by SwiftCrypto due to the difficulty of safely deploying it and its legacy status. Please be aware when proposing the addition of new primitives to SwiftCrypto that the proposal may be refused for this reason.
|
||||
Note that Swift Crypto does not intend to support all possible cryptographic primitives. Swift Crypto will focus on safe, modern cryptographic primitives that are broadly useful and that do not easily lend themselves to misuse. This means that some cryptographic algorithms may never be supported: for example, 3DES is highly unlikely to ever be supported by Swift Crypto due to the difficulty of safely deploying it and its legacy status. Please be aware when proposing the addition of new primitives to Swift Crypto that the proposal may be refused for this reason.
|
||||
|
||||
### 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 that meet the above criteria are specific to the SwiftCrypto 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 access a BoringSSL 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.
|
||||
|
||||
### Contributing New Primitives
|
||||
## Contributing
|
||||
|
||||
To contribute a new cryptographic primitive to SwiftCrypto, you should address the following questions:
|
||||
Before contributing please read [CONTRIBUTING.md](CONTRIBUTING.md), also make sure to read the two following sections.
|
||||
|
||||
#### Contributing new primitives
|
||||
|
||||
To contribute a new cryptographic primitive to Swift Crypto, you should address the following questions:
|
||||
|
||||
1. What is the new primitive for?
|
||||
2. How widely is it deployed?
|
||||
3. Is it specified in any public specifications or used by any such specification?
|
||||
4. How easy is it to misuse?
|
||||
5. In what way does SwiftCrypto fail to satisfy that use-case today?
|
||||
5. In what way does Swift Crypto fail to satisfy that use-case today?
|
||||
|
||||
In addition, new primitive implementations will only be accepted in cases where the implementation is thoroughly tested, including being tested with all currently available test vectors. If the [Wycheproof](https://github.com/google/wycheproof) project provides vectors for the algorithm those should be tested as well. It must be possible to ensure that we can appropriately regression test our implementations.
|
||||
|
||||
### Contributing bug fixes
|
||||
#### Contributing bug fixes
|
||||
|
||||
If you discover a bug with SwiftCrypto, please report it via GitHub.
|
||||
If you discover a bug with Swift Crypto, please report it via GitHub.
|
||||
|
||||
If you are interested in fixing a bug, feel free to open a pull request. Please also submit regression tests with bug fixes to ensure that they are not regressed in future.
|
||||
|
||||
If you have issues with CryptoKit, instead of Swift Crypto, please use Feedback Assistant to file those issues as you normally would.
|
||||
If you have issues with CryptoKit, instead of Swift Crypto, please use [Feedback Assistant](https://feedbackassistant.apple.com) to file those issues as you normally would.
|
||||
|
||||
### Get started contributing
|
||||
|
||||
#### `gyb`
|
||||
|
||||
Some of the files in this project are autogenerated (metaprogramming) using the Swift Utils tools called [gyb](https://github.com/apple/swift/blob/master/utils/gyb.py) (_"generate your boilerplate"_). `gyb` is included in [`./scripts/gyb`](scripts/gyb).
|
||||
|
||||
`gyb` will generate some `Foobar.swift` Swift file from some `Foobar.swift.gyb` _template_ file. **You should not edit `Foobar.swift` directly**, since all manual edits in that generated file will be overwritten the next time `gyb` is run.
|
||||
|
||||
You run `gyb` for a single file like so:
|
||||
|
||||
```bash
|
||||
./scripts/gyb --line-directive "" Sources/Foobar.swift.gyb -o Sources/Foobar.swift
|
||||
```
|
||||
|
||||
More conveniently you can run the bash script `./scripts/generate_boilerplate_files_with_gyb.sh` to generate all Swift files from their corresponding gyb template.
|
||||
|
||||
**If you add a new `.gyb` file, you should append a `// MARK: - Generated file, do NOT edit` warning** inside it, e.g.
|
||||
|
||||
```swift
|
||||
// MARK: - Generated file, do NOT edit
|
||||
// any edits of this file WILL be overwritten and thus discarded
|
||||
// see section `gyb` in `README` for details.
|
||||
```
|
||||
|
||||
### Security
|
||||
|
||||
If you believe you have identified a vulnerability in swift-crypto, please [report that vulnerability to Apple through the usual channel](https://support.apple.com/en-us/HT201220).
|
||||
If you believe you have identified a vulnerability in Swift Crypto, please [report that vulnerability to Apple through the usual channel](https://support.apple.com/en-us/HT201220).
|
||||
|
||||
### Swift versions
|
||||
|
||||
SwiftCrypto supports Swift 5.1 and later.
|
||||
Swift Crypto supports Swift 5.1 and later.
|
||||
|
||||
### Compatibility
|
||||
|
||||
SwiftCrypto follows [SemVer 2.0.0](https://semver.org/#semantic-versioning-200). Our public API is the same as that of CryptoKit (except where we lack an implementation entirely), as well as everything in the Server and Staging namespaces. We do not maintain a stable ABI, as SwiftCrypto is a source-only distribution.
|
||||
Swift Crypto follows [SemVer 2.0.0](https://semver.org/#semantic-versioning-200). Our public API is the same as that of CryptoKit (except where we lack an implementation entirely), as well as everything in the Server and Staging namespaces. We do not maintain a stable ABI, as Swift Crypto is a source-only distribution.
|
||||
|
||||
What this means for you is that you should depend on SwiftCrypto with a version range that covers everything from the minimum SwiftCrypto version you require up to the next major version.
|
||||
In SwiftPM that can be easily done specifying for example `from: "1.0.0"` meaning that you support SwiftCrypto in every version starting from 1.0.0 up to (excluding) 2.0.0.
|
||||
SemVer and SwiftCrypto's Public API guarantees should result in a working program without having to worry about testing every single version for compatibility.
|
||||
What this means for you is that you should depend on Swift Crypto with a version range that covers everything from the minimum Swift Crypto version you require up to the next major 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.
|
||||
|
||||
### Developing SwiftCrypto on macOS
|
||||
### Developing Swift Crypto on macOS
|
||||
|
||||
SwiftCrypto normally defers to the OS implementation of CryptoKit on macOS. Naturally, this makes developing SwiftCrypto on macOS tricky. To get SwiftCrypto to build the open source implementation on macOS, uncomment the line that reads: `//.define("CRYPTO_IN_SWIFTPM_FORCE_BUILD_API")`, as this will force SwiftCrypto 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, uncomment the line that reads: `//.define("CRYPTO_IN_SWIFTPM_FORCE_BUILD_API")`, as this will force Swift Crypto to build its public API.
|
||||
|
||||
@@ -447,6 +447,10 @@ int CBB_add_u16(CBB *cbb, uint16_t value) {
|
||||
return cbb_buffer_add_u(cbb->base, value, 2);
|
||||
}
|
||||
|
||||
int CBB_add_u16le(CBB *cbb, uint16_t value) {
|
||||
return CBB_add_u16(cbb, CRYPTO_bswap2(value));
|
||||
}
|
||||
|
||||
int CBB_add_u24(CBB *cbb, uint32_t value) {
|
||||
if (!CBB_flush(cbb)) {
|
||||
return 0;
|
||||
@@ -463,6 +467,10 @@ int CBB_add_u32(CBB *cbb, uint32_t value) {
|
||||
return cbb_buffer_add_u(cbb->base, value, 4);
|
||||
}
|
||||
|
||||
int CBB_add_u32le(CBB *cbb, uint32_t value) {
|
||||
return CBB_add_u32(cbb, CRYPTO_bswap4(value));
|
||||
}
|
||||
|
||||
int CBB_add_u64(CBB *cbb, uint64_t value) {
|
||||
if (!CBB_flush(cbb)) {
|
||||
return 0;
|
||||
@@ -470,6 +478,10 @@ int CBB_add_u64(CBB *cbb, uint64_t value) {
|
||||
return cbb_buffer_add_u(cbb->base, value, 8);
|
||||
}
|
||||
|
||||
int CBB_add_u64le(CBB *cbb, uint64_t value) {
|
||||
return CBB_add_u64(cbb, CRYPTO_bswap8(value));
|
||||
}
|
||||
|
||||
void CBB_discard_child(CBB *cbb) {
|
||||
if (cbb->child == NULL) {
|
||||
return;
|
||||
|
||||
@@ -120,6 +120,14 @@ int CBS_get_u16(CBS *cbs, uint16_t *out) {
|
||||
return 1;
|
||||
}
|
||||
|
||||
int CBS_get_u16le(CBS *cbs, uint16_t *out) {
|
||||
if (!CBS_get_u16(cbs, out)) {
|
||||
return 0;
|
||||
}
|
||||
*out = CRYPTO_bswap2(*out);
|
||||
return 1;
|
||||
}
|
||||
|
||||
int CBS_get_u24(CBS *cbs, uint32_t *out) {
|
||||
uint64_t v;
|
||||
if (!cbs_get_u(cbs, &v, 3)) {
|
||||
@@ -138,10 +146,26 @@ int CBS_get_u32(CBS *cbs, uint32_t *out) {
|
||||
return 1;
|
||||
}
|
||||
|
||||
int CBS_get_u32le(CBS *cbs, uint32_t *out) {
|
||||
if (!CBS_get_u32(cbs, out)) {
|
||||
return 0;
|
||||
}
|
||||
*out = CRYPTO_bswap4(*out);
|
||||
return 1;
|
||||
}
|
||||
|
||||
int CBS_get_u64(CBS *cbs, uint64_t *out) {
|
||||
return cbs_get_u(cbs, out, 8);
|
||||
}
|
||||
|
||||
int CBS_get_u64le(CBS *cbs, uint64_t *out) {
|
||||
if (!cbs_get_u(cbs, out, 8)) {
|
||||
return 0;
|
||||
}
|
||||
*out = CRYPTO_bswap8(*out);
|
||||
return 1;
|
||||
}
|
||||
|
||||
int CBS_get_last_u8(CBS *cbs, uint8_t *out) {
|
||||
if (cbs->len == 0) {
|
||||
return 0;
|
||||
|
||||
+1
-1
@@ -3937,7 +3937,7 @@ do_length_block:
|
||||
popq %rbp
|
||||
.cfi_adjust_cfa_offset -8
|
||||
.byte 0xf3,0xc3
|
||||
.cfi_adjust_cfa_offset (8 * 6) + 288 + 32
|
||||
.cfi_adjust_cfa_offset (8 * 7) + 288 + 32
|
||||
|
||||
seal_sse_128:
|
||||
movdqu .chacha20_consts(%rip),%xmm0
|
||||
|
||||
@@ -86,7 +86,7 @@ int EVP_BytesToKey(const EVP_CIPHER *type, const EVP_MD *md,
|
||||
EVP_MD_CTX_init(&c);
|
||||
for (;;) {
|
||||
if (!EVP_DigestInit_ex(&c, md, NULL)) {
|
||||
return 0;
|
||||
goto err;
|
||||
}
|
||||
if (addmd++) {
|
||||
if (!EVP_DigestUpdate(&c, md_buf, mds)) {
|
||||
|
||||
@@ -146,11 +146,13 @@ extern uint32_t OPENSSL_armcap_P;
|
||||
static int g_has_broken_neon, g_needs_hwcap2_workaround;
|
||||
|
||||
void OPENSSL_cpuid_setup(void) {
|
||||
char *cpuinfo_data;
|
||||
size_t cpuinfo_len;
|
||||
if (!read_file(&cpuinfo_data, &cpuinfo_len, "/proc/cpuinfo")) {
|
||||
return;
|
||||
}
|
||||
// We ignore the return value of |read_file| and proceed with an empty
|
||||
// /proc/cpuinfo on error. If |getauxval| works, we will still detect
|
||||
// capabilities. There may be a false positive due to
|
||||
// |crypto_cpuinfo_has_broken_neon|, but this is now rare.
|
||||
char *cpuinfo_data = NULL;
|
||||
size_t cpuinfo_len = 0;
|
||||
read_file(&cpuinfo_data, &cpuinfo_len, "/proc/cpuinfo");
|
||||
STRING_PIECE cpuinfo;
|
||||
cpuinfo.data = cpuinfo_data;
|
||||
cpuinfo.len = cpuinfo_len;
|
||||
|
||||
@@ -123,7 +123,9 @@ static uint64_t OPENSSL_xgetbv(uint32_t xcr) {
|
||||
// and |out[1]|. See the comment in |OPENSSL_cpuid_setup| about this.
|
||||
static void handle_cpu_env(uint32_t *out, const char *in) {
|
||||
const int invert = in[0] == '~';
|
||||
const int hex = in[invert] == '0' && in[invert+1] == 'x';
|
||||
const int or = in[0] == '|';
|
||||
const int skip_first_byte = invert || or;
|
||||
const int hex = in[skip_first_byte] == '0' && in[skip_first_byte+1] == 'x';
|
||||
|
||||
int sscanf_result;
|
||||
uint64_t v;
|
||||
@@ -140,6 +142,9 @@ static void handle_cpu_env(uint32_t *out, const char *in) {
|
||||
if (invert) {
|
||||
out[0] &= ~v;
|
||||
out[1] &= ~(v >> 32);
|
||||
} else if (or) {
|
||||
out[0] |= v;
|
||||
out[1] |= (v >> 32);
|
||||
} else {
|
||||
out[0] = v;
|
||||
out[1] = v >> 32;
|
||||
@@ -264,10 +269,14 @@ void OPENSSL_cpuid_setup(void) {
|
||||
|
||||
// OPENSSL_ia32cap can contain zero, one or two values, separated with a ':'.
|
||||
// Each value is a 64-bit, unsigned value which may start with "0x" to
|
||||
// indicate a hex value. Prior to the 64-bit value, a '~' may be given.
|
||||
// indicate a hex value. Prior to the 64-bit value, a '~' or '|' may be given.
|
||||
//
|
||||
// If '~' isn't present, then the value is taken as the result of the CPUID.
|
||||
// Otherwise the value is inverted and ANDed with the probed CPUID result.
|
||||
// If the '~' prefix is present:
|
||||
// the value is inverted and ANDed with the probed CPUID result
|
||||
// If the '|' prefix is present:
|
||||
// the value is ORed with the probed CPUID result
|
||||
// Otherwise:
|
||||
// the value is taken as the result of the CPUID
|
||||
//
|
||||
// The first value determines OPENSSL_ia32cap_P[0] and [1]. The second [2]
|
||||
// and [3].
|
||||
|
||||
@@ -16,6 +16,8 @@
|
||||
|
||||
#include <CCryptoBoringSSL_cpu.h>
|
||||
|
||||
#include "fipsmodule/rand/fork_detect.h"
|
||||
#include "fipsmodule/rand/internal.h"
|
||||
#include "internal.h"
|
||||
|
||||
|
||||
@@ -174,6 +176,15 @@ int CRYPTO_has_asm(void) {
|
||||
#endif
|
||||
}
|
||||
|
||||
void CRYPTO_pre_sandbox_init(void) {
|
||||
// Read from /proc/cpuinfo if needed.
|
||||
CRYPTO_library_init();
|
||||
// Open /dev/urandom if needed.
|
||||
CRYPTO_init_sysrand();
|
||||
// Set up MADV_WIPEONFORK state if needed.
|
||||
CRYPTO_get_fork_generation();
|
||||
}
|
||||
|
||||
const char *SSLeay_version(int which) { return OpenSSL_version(which); }
|
||||
|
||||
const char *OpenSSL_version(int which) {
|
||||
|
||||
+18
-26
@@ -1,29 +1,21 @@
|
||||
// The MIT License (MIT)
|
||||
//
|
||||
// Copyright (c) 2015-2016 the fiat-crypto authors (see the AUTHORS file).
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
// of this software and associated documentation files (the "Software"), to deal
|
||||
// in the Software without restriction, including without limitation the rights
|
||||
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
// copies of the Software, and to permit persons to whom the Software is
|
||||
// furnished to do so, subject to the following conditions:
|
||||
//
|
||||
// The above copyright notice and this permission notice shall be included in all
|
||||
// copies or substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
// SOFTWARE.
|
||||
/* Copyright (c) 2020, Google Inc.
|
||||
*
|
||||
* Permission to use, copy, modify, and/or distribute this software for any
|
||||
* purpose with or without fee is hereby granted, provided that the above
|
||||
* copyright notice and this permission notice appear in all copies.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
|
||||
* WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
|
||||
* MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
|
||||
* SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
|
||||
* WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION
|
||||
* OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
|
||||
* CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. */
|
||||
|
||||
// Some of this code is taken from the ref10 version of Ed25519 in SUPERCOP
|
||||
// 20141124 (http://bench.cr.yp.to/supercop.html). That code is released as
|
||||
// public domain but parts have been replaced with code generated by Fiat
|
||||
// (https://github.com/mit-plv/fiat-crypto), which is MIT licensed.
|
||||
// public domain. Other parts have been replaced to call into code generated by
|
||||
// Fiat (https://github.com/mit-plv/fiat-crypto) in //third_party/fiat.
|
||||
//
|
||||
// The field functions are shared by Ed25519 and X25519 where possible.
|
||||
|
||||
@@ -39,16 +31,16 @@
|
||||
#include <CCryptoBoringSSL_type_check.h>
|
||||
|
||||
#include "internal.h"
|
||||
#include "../../crypto/internal.h"
|
||||
#include "../internal.h"
|
||||
|
||||
|
||||
// Various pre-computed constants.
|
||||
#include "./curve25519_tables.h"
|
||||
|
||||
#if defined(BORINGSSL_CURVE25519_64BIT)
|
||||
#include "./curve25519_64.h"
|
||||
#include "../../third_party/fiat/curve25519_64.h"
|
||||
#else
|
||||
#include "./curve25519_32.h"
|
||||
#include "../../third_party/fiat/curve25519_32.h"
|
||||
#endif // BORINGSSL_CURVE25519_64BIT
|
||||
|
||||
|
||||
+13
-21
@@ -1,24 +1,16 @@
|
||||
// The MIT License (MIT)
|
||||
//
|
||||
// Copyright (c) 2015-2016 the fiat-crypto authors (see the AUTHORS file).
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
// of this software and associated documentation files (the "Software"), to deal
|
||||
// in the Software without restriction, including without limitation the rights
|
||||
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
// copies of the Software, and to permit persons to whom the Software is
|
||||
// furnished to do so, subject to the following conditions:
|
||||
//
|
||||
// The above copyright notice and this permission notice shall be included in
|
||||
// all copies or substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
// SOFTWARE.
|
||||
/* Copyright (c) 2020, Google Inc.
|
||||
*
|
||||
* Permission to use, copy, modify, and/or distribute this software for any
|
||||
* purpose with or without fee is hereby granted, provided that the above
|
||||
* copyright notice and this permission notice appear in all copies.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
|
||||
* WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
|
||||
* MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
|
||||
* SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
|
||||
* WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION
|
||||
* OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
|
||||
* CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. */
|
||||
|
||||
// This file is generated from
|
||||
// ./make_curve25519_tables.py > curve25519_tables.h
|
||||
+14
-22
@@ -1,24 +1,16 @@
|
||||
// The MIT License (MIT)
|
||||
//
|
||||
// Copyright (c) 2015-2016 the fiat-crypto authors (see the AUTHORS file).
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
// of this software and associated documentation files (the "Software"), to deal
|
||||
// in the Software without restriction, including without limitation the rights
|
||||
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
// copies of the Software, and to permit persons to whom the Software is
|
||||
// furnished to do so, subject to the following conditions:
|
||||
//
|
||||
// The above copyright notice and this permission notice shall be included in all
|
||||
// copies or substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
// SOFTWARE.
|
||||
/* Copyright (c) 2020, Google Inc.
|
||||
*
|
||||
* Permission to use, copy, modify, and/or distribute this software for any
|
||||
* purpose with or without fee is hereby granted, provided that the above
|
||||
* copyright notice and this permission notice appear in all copies.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
|
||||
* WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
|
||||
* MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
|
||||
* SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
|
||||
* WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION
|
||||
* OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
|
||||
* CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. */
|
||||
|
||||
#ifndef OPENSSL_HEADER_CURVE25519_INTERNAL_H
|
||||
#define OPENSSL_HEADER_CURVE25519_INTERNAL_H
|
||||
@@ -29,7 +21,7 @@ extern "C" {
|
||||
|
||||
#include <CCryptoBoringSSL_base.h>
|
||||
|
||||
#include "../../crypto/internal.h"
|
||||
#include "../internal.h"
|
||||
|
||||
|
||||
#if defined(OPENSSL_ARM) && !defined(OPENSSL_NO_ASM) && !defined(OPENSSL_APPLE)
|
||||
@@ -23,7 +23,7 @@
|
||||
#include <CCryptoBoringSSL_sha.h>
|
||||
|
||||
#include "../internal.h"
|
||||
#include "../../third_party/fiat/internal.h"
|
||||
#include "./internal.h"
|
||||
|
||||
|
||||
// The following precomputation tables are for the following
|
||||
|
||||
@@ -113,6 +113,16 @@ void DH_free(DH *dh) {
|
||||
OPENSSL_free(dh);
|
||||
}
|
||||
|
||||
const BIGNUM *DH_get0_pub_key(const DH *dh) { return dh->pub_key; }
|
||||
|
||||
const BIGNUM *DH_get0_priv_key(const DH *dh) { return dh->priv_key; }
|
||||
|
||||
const BIGNUM *DH_get0_p(const DH *dh) { return dh->p; }
|
||||
|
||||
const BIGNUM *DH_get0_q(const DH *dh) { return dh->q; }
|
||||
|
||||
const BIGNUM *DH_get0_g(const DH *dh) { return dh->g; }
|
||||
|
||||
void DH_get0_key(const DH *dh, const BIGNUM **out_pub_key,
|
||||
const BIGNUM **out_priv_key) {
|
||||
if (out_pub_key != NULL) {
|
||||
@@ -174,6 +184,11 @@ int DH_set0_pqg(DH *dh, BIGNUM *p, BIGNUM *q, BIGNUM *g) {
|
||||
return 1;
|
||||
}
|
||||
|
||||
int DH_set_length(DH *dh, unsigned priv_length) {
|
||||
dh->priv_length = priv_length;
|
||||
return 1;
|
||||
}
|
||||
|
||||
int DH_generate_parameters_ex(DH *dh, int prime_bits, int generator, BN_GENCB *cb) {
|
||||
// We generate DH parameters as follows
|
||||
// find a prime q which is prime_bits/2 bits long.
|
||||
|
||||
@@ -131,6 +131,16 @@ int DSA_up_ref(DSA *dsa) {
|
||||
return 1;
|
||||
}
|
||||
|
||||
const BIGNUM *DSA_get0_pub_key(const DSA *dsa) { return dsa->pub_key; }
|
||||
|
||||
const BIGNUM *DSA_get0_priv_key(const DSA *dsa) { return dsa->priv_key; }
|
||||
|
||||
const BIGNUM *DSA_get0_p(const DSA *dsa) { return dsa->p; }
|
||||
|
||||
const BIGNUM *DSA_get0_q(const DSA *dsa) { return dsa->q; }
|
||||
|
||||
const BIGNUM *DSA_get0_g(const DSA *dsa) { return dsa->g; }
|
||||
|
||||
void DSA_get0_key(const DSA *dsa, const BIGNUM **out_pub_key,
|
||||
const BIGNUM **out_priv_key) {
|
||||
if (out_pub_key != NULL) {
|
||||
|
||||
@@ -0,0 +1,425 @@
|
||||
/* Copyright (c) 2020, Google Inc.
|
||||
*
|
||||
* Permission to use, copy, modify, and/or distribute this software for any
|
||||
* purpose with or without fee is hereby granted, provided that the above
|
||||
* copyright notice and this permission notice appear in all copies.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
|
||||
* WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
|
||||
* MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
|
||||
* SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
|
||||
* WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION
|
||||
* OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
|
||||
* CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. */
|
||||
|
||||
#include <CCryptoBoringSSL_ec.h>
|
||||
|
||||
#include <CCryptoBoringSSL_digest.h>
|
||||
#include <CCryptoBoringSSL_err.h>
|
||||
#include <CCryptoBoringSSL_nid.h>
|
||||
#include <CCryptoBoringSSL_type_check.h>
|
||||
|
||||
#include <assert.h>
|
||||
|
||||
#include "internal.h"
|
||||
#include "../fipsmodule/bn/internal.h"
|
||||
#include "../fipsmodule/ec/internal.h"
|
||||
#include "../internal.h"
|
||||
|
||||
|
||||
// This file implements hash-to-curve, as described in
|
||||
// draft-irtf-cfrg-hash-to-curve-07.
|
||||
//
|
||||
// This hash-to-curve implementation is written generically with the
|
||||
// expectation that we will eventually wish to support other curves. If it
|
||||
// becomes a performance bottleneck, some possible optimizations by
|
||||
// specializing it to the curve:
|
||||
//
|
||||
// - Rather than using a generic |felem_exp|, specialize the exponentation to
|
||||
// c2 with a faster addition chain.
|
||||
//
|
||||
// - |felem_mul| and |felem_sqr| are indirect calls to generic Montgomery
|
||||
// code. Given the few curves, we could specialize
|
||||
// |map_to_curve_simple_swu|. But doing this reasonably without duplicating
|
||||
// code in C is difficult. (C++ templates would be useful here.)
|
||||
//
|
||||
// - P-521's Z and c2 have small power-of-two absolute values. We could save
|
||||
// two multiplications in SSWU. (Other curves have reasonable values of Z
|
||||
// and inconvenient c2.) This is unlikely to be worthwhile without C++
|
||||
// templates to make specializing more convenient.
|
||||
|
||||
// expand_message_xmd implements the operation described in section 5.3.1 of
|
||||
// draft-irtf-cfrg-hash-to-curve-07. It returns one on success and zero on
|
||||
// allocation failure or if |out_len| was too large. If |is_draft06| is one, it
|
||||
// implements the operation from draft-irtf-cfrg-hash-to-curve-06 instead.
|
||||
static int expand_message_xmd(const EVP_MD *md, uint8_t *out, size_t out_len,
|
||||
const uint8_t *msg, size_t msg_len,
|
||||
const uint8_t *dst, size_t dst_len,
|
||||
int is_draft06) {
|
||||
int ret = 0;
|
||||
const size_t block_size = EVP_MD_block_size(md);
|
||||
const size_t md_size = EVP_MD_size(md);
|
||||
EVP_MD_CTX ctx;
|
||||
EVP_MD_CTX_init(&ctx);
|
||||
|
||||
// Long DSTs are hashed down to size. See section 5.3.3.
|
||||
OPENSSL_STATIC_ASSERT(EVP_MAX_MD_SIZE < 256, "hashed DST still too large");
|
||||
uint8_t dst_buf[EVP_MAX_MD_SIZE];
|
||||
if (dst_len >= 256) {
|
||||
static const char kPrefix[] = "H2C-OVERSIZE-DST-";
|
||||
if (!EVP_DigestInit_ex(&ctx, md, NULL) ||
|
||||
!EVP_DigestUpdate(&ctx, kPrefix, sizeof(kPrefix) - 1) ||
|
||||
!EVP_DigestUpdate(&ctx, dst, dst_len) ||
|
||||
!EVP_DigestFinal_ex(&ctx, dst_buf, NULL)) {
|
||||
goto err;
|
||||
}
|
||||
dst = dst_buf;
|
||||
dst_len = md_size;
|
||||
}
|
||||
uint8_t dst_len_u8 = (uint8_t)dst_len;
|
||||
|
||||
// Compute b_0.
|
||||
static const uint8_t kZeros[EVP_MAX_MD_BLOCK_SIZE] = {0};
|
||||
// If |out_len| exceeds 16 bits then |i| will wrap below causing an error to
|
||||
// be returned. This depends on the static assert above.
|
||||
uint8_t l_i_b_str_zero[3] = {out_len >> 8, out_len, 0};
|
||||
uint8_t b_0[EVP_MAX_MD_SIZE];
|
||||
if (!EVP_DigestInit_ex(&ctx, md, NULL) ||
|
||||
!EVP_DigestUpdate(&ctx, kZeros, block_size) ||
|
||||
!EVP_DigestUpdate(&ctx, msg, msg_len) ||
|
||||
!EVP_DigestUpdate(&ctx, l_i_b_str_zero, sizeof(l_i_b_str_zero)) ||
|
||||
(is_draft06 && !EVP_DigestUpdate(&ctx, &dst_len_u8, 1)) ||
|
||||
!EVP_DigestUpdate(&ctx, dst, dst_len) ||
|
||||
(!is_draft06 && !EVP_DigestUpdate(&ctx, &dst_len_u8, 1)) ||
|
||||
!EVP_DigestFinal_ex(&ctx, b_0, NULL)) {
|
||||
goto err;
|
||||
}
|
||||
|
||||
uint8_t b_i[EVP_MAX_MD_SIZE];
|
||||
uint8_t i = 1;
|
||||
while (out_len > 0) {
|
||||
if (i == 0) {
|
||||
// Input was too large.
|
||||
OPENSSL_PUT_ERROR(EC, ERR_R_INTERNAL_ERROR);
|
||||
goto err;
|
||||
}
|
||||
if (i > 1) {
|
||||
for (size_t j = 0; j < md_size; j++) {
|
||||
b_i[j] ^= b_0[j];
|
||||
}
|
||||
} else {
|
||||
OPENSSL_memcpy(b_i, b_0, md_size);
|
||||
}
|
||||
|
||||
if (!EVP_DigestInit_ex(&ctx, md, NULL) ||
|
||||
!EVP_DigestUpdate(&ctx, b_i, md_size) ||
|
||||
!EVP_DigestUpdate(&ctx, &i, 1) ||
|
||||
(is_draft06 && !EVP_DigestUpdate(&ctx, &dst_len_u8, 1)) ||
|
||||
!EVP_DigestUpdate(&ctx, dst, dst_len) ||
|
||||
(!is_draft06 && !EVP_DigestUpdate(&ctx, &dst_len_u8, 1)) ||
|
||||
!EVP_DigestFinal_ex(&ctx, b_i, NULL)) {
|
||||
goto err;
|
||||
}
|
||||
|
||||
size_t todo = out_len >= md_size ? md_size : out_len;
|
||||
OPENSSL_memcpy(out, b_i, todo);
|
||||
out += todo;
|
||||
out_len -= todo;
|
||||
i++;
|
||||
}
|
||||
|
||||
ret = 1;
|
||||
|
||||
err:
|
||||
EVP_MD_CTX_cleanup(&ctx);
|
||||
return ret;
|
||||
}
|
||||
|
||||
// num_bytes_to_derive determines the number of bytes to derive when hashing to
|
||||
// a number modulo |modulus|. See the hash_to_field operation defined in
|
||||
// section 5.2 of draft-irtf-cfrg-hash-to-curve-07.
|
||||
static int num_bytes_to_derive(size_t *out, const BIGNUM *modulus, unsigned k) {
|
||||
size_t bits = BN_num_bits(modulus);
|
||||
size_t L = (bits + k + 7) / 8;
|
||||
// We require 2^(8*L) < 2^(2*bits - 2) <= n^2 so to fit in bounds for
|
||||
// |felem_reduce| and |ec_scalar_reduce|. All defined hash-to-curve suites
|
||||
// define |k| to be well under this bound. (|k| is usually around half of
|
||||
// |p_bits|.)
|
||||
if (L * 8 >= 2 * bits - 2 ||
|
||||
L > 2 * EC_MAX_BYTES) {
|
||||
assert(0);
|
||||
OPENSSL_PUT_ERROR(EC, ERR_R_INTERNAL_ERROR);
|
||||
return 0;
|
||||
}
|
||||
|
||||
*out = L;
|
||||
return 1;
|
||||
}
|
||||
|
||||
// big_endian_to_words decodes |in| as a big-endian integer and writes the
|
||||
// result to |out|. |num_words| must be large enough to contain the output.
|
||||
static void big_endian_to_words(BN_ULONG *out, size_t num_words,
|
||||
const uint8_t *in, size_t len) {
|
||||
assert(len <= num_words * sizeof(BN_ULONG));
|
||||
// Ensure any excess bytes are zeroed.
|
||||
OPENSSL_memset(out, 0, num_words * sizeof(BN_ULONG));
|
||||
uint8_t *out_u8 = (uint8_t *)out;
|
||||
for (size_t i = 0; i < len; i++) {
|
||||
out_u8[len - 1 - i] = in[i];
|
||||
}
|
||||
}
|
||||
|
||||
// hash_to_field implements the operation described in section 5.2
|
||||
// of draft-irtf-cfrg-hash-to-curve-07, with count = 2. |k| is the security
|
||||
// factor.
|
||||
static int hash_to_field2(const EC_GROUP *group, const EVP_MD *md,
|
||||
EC_FELEM *out1, EC_FELEM *out2, const uint8_t *dst,
|
||||
size_t dst_len, unsigned k, const uint8_t *msg,
|
||||
size_t msg_len, int is_draft06) {
|
||||
size_t L;
|
||||
uint8_t buf[4 * EC_MAX_BYTES];
|
||||
if (!num_bytes_to_derive(&L, &group->field, k) ||
|
||||
!expand_message_xmd(md, buf, 2 * L, msg, msg_len, dst, dst_len,
|
||||
is_draft06)) {
|
||||
return 0;
|
||||
}
|
||||
BN_ULONG words[2 * EC_MAX_WORDS];
|
||||
size_t num_words = 2 * group->field.width;
|
||||
big_endian_to_words(words, num_words, buf, L);
|
||||
group->meth->felem_reduce(group, out1, words, num_words);
|
||||
big_endian_to_words(words, num_words, buf + L, L);
|
||||
group->meth->felem_reduce(group, out2, words, num_words);
|
||||
return 1;
|
||||
}
|
||||
|
||||
// hash_to_scalar behaves like |hash_to_field2| but returns a value modulo the
|
||||
// group order rather than a field element. |k| is the security factor.
|
||||
static int hash_to_scalar(const EC_GROUP *group, const EVP_MD *md,
|
||||
EC_SCALAR *out, const uint8_t *dst, size_t dst_len,
|
||||
unsigned k, const uint8_t *msg, size_t msg_len,
|
||||
int is_draft06) {
|
||||
size_t L;
|
||||
uint8_t buf[EC_MAX_BYTES * 2];
|
||||
if (!num_bytes_to_derive(&L, &group->order, k) ||
|
||||
!expand_message_xmd(md, buf, L, msg, msg_len, dst, dst_len, is_draft06)) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
BN_ULONG words[2 * EC_MAX_WORDS];
|
||||
size_t num_words = 2 * group->order.width;
|
||||
big_endian_to_words(words, num_words, buf, L);
|
||||
ec_scalar_reduce(group, out, words, num_words);
|
||||
return 1;
|
||||
}
|
||||
|
||||
static inline void mul_A(const EC_GROUP *group, EC_FELEM *out,
|
||||
const EC_FELEM *in) {
|
||||
assert(group->a_is_minus3);
|
||||
EC_FELEM tmp;
|
||||
ec_felem_add(group, &tmp, in, in); // tmp = 2*in
|
||||
ec_felem_add(group, &tmp, &tmp, &tmp); // tmp = 4*in
|
||||
ec_felem_sub(group, out, in, &tmp); // out = -3*in
|
||||
}
|
||||
|
||||
static inline void mul_minus_A(const EC_GROUP *group, EC_FELEM *out,
|
||||
const EC_FELEM *in) {
|
||||
assert(group->a_is_minus3);
|
||||
EC_FELEM tmp;
|
||||
ec_felem_add(group, &tmp, in, in); // tmp = 2*in
|
||||
ec_felem_add(group, out, &tmp, in); // out = 3*in
|
||||
}
|
||||
|
||||
// sgn0_le implements the operation described in section 4.1.2 of
|
||||
// draft-irtf-cfrg-hash-to-curve-07.
|
||||
static BN_ULONG sgn0_le(const EC_GROUP *group, const EC_FELEM *a) {
|
||||
uint8_t buf[EC_MAX_BYTES];
|
||||
size_t len;
|
||||
ec_felem_to_bytes(group, buf, &len, a);
|
||||
return buf[len - 1] & 1;
|
||||
}
|
||||
|
||||
// map_to_curve_simple_swu implements the operation described in section 6.6.2
|
||||
// of draft-irtf-cfrg-hash-to-curve-07, using the optimization in appendix
|
||||
// D.2.1. It returns one on success and zero on error.
|
||||
static int map_to_curve_simple_swu(const EC_GROUP *group, const EC_FELEM *Z,
|
||||
const BN_ULONG *c1, size_t num_c1,
|
||||
const EC_FELEM *c2, EC_RAW_POINT *out,
|
||||
const EC_FELEM *u) {
|
||||
void (*const felem_mul)(const EC_GROUP *, EC_FELEM *r, const EC_FELEM *a,
|
||||
const EC_FELEM *b) = group->meth->felem_mul;
|
||||
void (*const felem_sqr)(const EC_GROUP *, EC_FELEM *r, const EC_FELEM *a) =
|
||||
group->meth->felem_sqr;
|
||||
|
||||
// This function requires the prime be 3 mod 4, and that A = -3.
|
||||
if (group->field.width == 0 || (group->field.d[0] & 3) != 3 ||
|
||||
!group->a_is_minus3) {
|
||||
OPENSSL_PUT_ERROR(EC, ERR_R_INTERNAL_ERROR);
|
||||
return 0;
|
||||
}
|
||||
|
||||
EC_FELEM tv1, tv2, tv3, tv4, xd, x1n, x2n, tmp, gxd, gx1, y1, y2;
|
||||
felem_sqr(group, &tv1, u); // tv1 = u^2
|
||||
felem_mul(group, &tv3, Z, &tv1); // tv3 = Z * tv1
|
||||
felem_sqr(group, &tv2, &tv3); // tv2 = tv3^2
|
||||
ec_felem_add(group, &xd, &tv2, &tv3); // xd = tv2 + tv3
|
||||
ec_felem_add(group, &x1n, &xd, &group->one); // x1n = xd + 1
|
||||
felem_mul(group, &x1n, &x1n, &group->b); // x1n = x1n * B
|
||||
mul_minus_A(group, &xd, &xd); // xd = -A * xd
|
||||
BN_ULONG e1 = ec_felem_non_zero_mask(group, &xd); // e1 = xd == 0 [flipped]
|
||||
mul_A(group, &tmp, Z);
|
||||
ec_felem_select(group, &xd, e1, &xd, &tmp); // xd = CMOV(xd, Z * A, e1)
|
||||
felem_sqr(group, &tv2, &xd); // tv2 = xd^2
|
||||
felem_mul(group, &gxd, &tv2, &xd); // gxd = tv2 * xd = xd^3
|
||||
mul_A(group, &tv2, &tv2); // tv2 = A * tv2
|
||||
felem_sqr(group, &gx1, &x1n); // gx1 = x1n^2
|
||||
ec_felem_add(group, &gx1, &gx1, &tv2); // gx1 = gx1 + tv2
|
||||
felem_mul(group, &gx1, &gx1, &x1n); // gx1 = gx1 * x1n
|
||||
felem_mul(group, &tv2, &group->b, &gxd); // tv2 = B * gxd
|
||||
ec_felem_add(group, &gx1, &gx1, &tv2); // gx1 = gx1 + tv2
|
||||
felem_sqr(group, &tv4, &gxd); // tv4 = gxd^2
|
||||
felem_mul(group, &tv2, &gx1, &gxd); // tv2 = gx1 * gxd
|
||||
felem_mul(group, &tv4, &tv4, &tv2); // tv4 = tv4 * tv2
|
||||
group->meth->felem_exp(group, &y1, &tv4, c1, num_c1); // y1 = tv4^c1
|
||||
felem_mul(group, &y1, &y1, &tv2); // y1 = y1 * tv2
|
||||
felem_mul(group, &x2n, &tv3, &x1n); // x2n = tv3 * x1n
|
||||
felem_mul(group, &y2, &y1, c2); // y2 = y1 * c2
|
||||
felem_mul(group, &y2, &y2, &tv1); // y2 = y2 * tv1
|
||||
felem_mul(group, &y2, &y2, u); // y2 = y2 * u
|
||||
felem_sqr(group, &tv2, &y1); // tv2 = y1^2
|
||||
felem_mul(group, &tv2, &tv2, &gxd); // tv2 = tv2 * gxd
|
||||
ec_felem_sub(group, &tv3, &tv2, &gx1);
|
||||
BN_ULONG e2 =
|
||||
ec_felem_non_zero_mask(group, &tv3); // e2 = tv2 == gx1 [flipped]
|
||||
ec_felem_select(group, &x1n, e2, &x2n, &x1n); // xn = CMOV(x2n, x1n, e2)
|
||||
ec_felem_select(group, &y1, e2, &y2, &y1); // y = CMOV(y2, y1, e2)
|
||||
BN_ULONG sgn0_u = sgn0_le(group, u);
|
||||
BN_ULONG sgn0_y = sgn0_le(group, &y1);
|
||||
BN_ULONG e3 = sgn0_u ^ sgn0_y;
|
||||
e3 = ((BN_ULONG)0) - e3; // e3 = sgn0(u) == sgn0(y) [flipped]
|
||||
ec_felem_neg(group, &y2, &y1);
|
||||
ec_felem_select(group, &y1, e3, &y2, &y1); // y = CMOV(-y, y, e3)
|
||||
|
||||
// Appendix D.1 describes how to convert (x1n, xd, y1, 1) to Jacobian
|
||||
// coordinates. Note yd = 1. Also note that gxd computed above is xd^3.
|
||||
felem_mul(group, &out->X, &x1n, &xd); // X = xn * xd
|
||||
felem_mul(group, &out->Y, &y1, &gxd); // Y = yn * gxd = yn * xd^3
|
||||
out->Z = xd; // Z = xd
|
||||
return 1;
|
||||
}
|
||||
|
||||
static int hash_to_curve(const EC_GROUP *group, const EVP_MD *md,
|
||||
const EC_FELEM *Z, const EC_FELEM *c2, unsigned k,
|
||||
EC_RAW_POINT *out, const uint8_t *dst, size_t dst_len,
|
||||
const uint8_t *msg, size_t msg_len, int is_draft06) {
|
||||
EC_FELEM u0, u1;
|
||||
if (!hash_to_field2(group, md, &u0, &u1, dst, dst_len, k, msg, msg_len,
|
||||
is_draft06)) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
// Compute |c1| = (p - 3) / 4.
|
||||
BN_ULONG c1[EC_MAX_WORDS];
|
||||
size_t num_c1 = group->field.width;
|
||||
if (!bn_copy_words(c1, num_c1, &group->field)) {
|
||||
return 0;
|
||||
}
|
||||
bn_rshift_words(c1, c1, /*shift=*/2, /*num=*/num_c1);
|
||||
|
||||
EC_RAW_POINT Q0, Q1;
|
||||
if (!map_to_curve_simple_swu(group, Z, c1, num_c1, c2, &Q0, &u0) ||
|
||||
!map_to_curve_simple_swu(group, Z, c1, num_c1, c2, &Q1, &u1)) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
group->meth->add(group, out, &Q0, &Q1); // R = Q0 + Q1
|
||||
// All our curves have cofactor one, so |clear_cofactor| is a no-op.
|
||||
return 1;
|
||||
}
|
||||
|
||||
static int felem_from_u8(const EC_GROUP *group, EC_FELEM *out, uint8_t a) {
|
||||
uint8_t bytes[EC_MAX_BYTES] = {0};
|
||||
size_t len = BN_num_bytes(&group->field);
|
||||
bytes[len - 1] = a;
|
||||
return ec_felem_from_bytes(group, out, bytes, len);
|
||||
}
|
||||
|
||||
int ec_hash_to_curve_p384_xmd_sha512_sswu_draft07(
|
||||
const EC_GROUP *group, EC_RAW_POINT *out, const uint8_t *dst,
|
||||
size_t dst_len, const uint8_t *msg, size_t msg_len) {
|
||||
// See section 8.3 of draft-irtf-cfrg-hash-to-curve-07.
|
||||
if (EC_GROUP_get_curve_name(group) != NID_secp384r1) {
|
||||
OPENSSL_PUT_ERROR(EC, EC_R_GROUP_MISMATCH);
|
||||
return 0;
|
||||
}
|
||||
|
||||
// kSqrt1728 was computed as follows in python3:
|
||||
//
|
||||
// p = 2**384 - 2**128 - 2**96 + 2**32 - 1
|
||||
// z3 = 12**3
|
||||
// c2 = pow(z3, (p+1)//4, p)
|
||||
// assert z3 == pow(c2, 2, p)
|
||||
// ", ".join("0x%02x" % b for b in c2.to_bytes(384//8, 'big')
|
||||
|
||||
static const uint8_t kSqrt1728[] = {
|
||||
0x01, 0x98, 0x77, 0xcc, 0x10, 0x41, 0xb7, 0x55, 0x57, 0x43, 0xc0, 0xae,
|
||||
0x2e, 0x3a, 0x3e, 0x61, 0xfb, 0x2a, 0xaa, 0x2e, 0x0e, 0x87, 0xea, 0x55,
|
||||
0x7a, 0x56, 0x3d, 0x8b, 0x59, 0x8a, 0x09, 0x40, 0xd0, 0xa6, 0x97, 0xa9,
|
||||
0xe0, 0xb9, 0xe9, 0x2c, 0xfa, 0xa3, 0x14, 0xf5, 0x83, 0xc9, 0xd0, 0x66
|
||||
};
|
||||
|
||||
// Z = -12, c2 = sqrt(1728)
|
||||
EC_FELEM Z, c2;
|
||||
if (!felem_from_u8(group, &Z, 12) ||
|
||||
!ec_felem_from_bytes(group, &c2, kSqrt1728, sizeof(kSqrt1728))) {
|
||||
return 0;
|
||||
}
|
||||
ec_felem_neg(group, &Z, &Z);
|
||||
|
||||
return hash_to_curve(group, EVP_sha512(), &Z, &c2, /*k=*/192, out, dst,
|
||||
dst_len, msg, msg_len, /*is_draft06=*/0);
|
||||
}
|
||||
|
||||
int ec_hash_to_scalar_p384_xmd_sha512_draft07(
|
||||
const EC_GROUP *group, EC_SCALAR *out, const uint8_t *dst, size_t dst_len,
|
||||
const uint8_t *msg, size_t msg_len) {
|
||||
if (EC_GROUP_get_curve_name(group) != NID_secp384r1) {
|
||||
OPENSSL_PUT_ERROR(EC, EC_R_GROUP_MISMATCH);
|
||||
return 0;
|
||||
}
|
||||
|
||||
return hash_to_scalar(group, EVP_sha512(), out, dst, dst_len, /*k=*/192, msg,
|
||||
msg_len, /*is_draft06=*/0);
|
||||
}
|
||||
|
||||
int ec_hash_to_curve_p521_xmd_sha512_sswu_draft06(
|
||||
const EC_GROUP *group, EC_RAW_POINT *out, const uint8_t *dst,
|
||||
size_t dst_len, const uint8_t *msg, size_t msg_len) {
|
||||
// See section 8.3 of draft-irtf-cfrg-hash-to-curve-06.
|
||||
if (EC_GROUP_get_curve_name(group) != NID_secp521r1) {
|
||||
OPENSSL_PUT_ERROR(EC, EC_R_GROUP_MISMATCH);
|
||||
return 0;
|
||||
}
|
||||
|
||||
// Z = -4, c2 = 8.
|
||||
EC_FELEM Z, c2;
|
||||
if (!felem_from_u8(group, &Z, 4) ||
|
||||
!felem_from_u8(group, &c2, 8)) {
|
||||
return 0;
|
||||
}
|
||||
ec_felem_neg(group, &Z, &Z);
|
||||
|
||||
return hash_to_curve(group, EVP_sha512(), &Z, &c2, /*k=*/256, out, dst,
|
||||
dst_len, msg, msg_len, /*is_draft06=*/1);
|
||||
}
|
||||
|
||||
int ec_hash_to_scalar_p521_xmd_sha512_draft06(
|
||||
const EC_GROUP *group, EC_SCALAR *out, const uint8_t *dst, size_t dst_len,
|
||||
const uint8_t *msg, size_t msg_len) {
|
||||
if (EC_GROUP_get_curve_name(group) != NID_secp521r1) {
|
||||
OPENSSL_PUT_ERROR(EC, EC_R_GROUP_MISMATCH);
|
||||
return 0;
|
||||
}
|
||||
|
||||
return hash_to_scalar(group, EVP_sha512(), out, dst, dst_len, /*k=*/256, msg,
|
||||
msg_len, /*is_draft06=*/1);
|
||||
}
|
||||
@@ -0,0 +1,78 @@
|
||||
/* Copyright (c) 2020, Google Inc.
|
||||
*
|
||||
* Permission to use, copy, modify, and/or distribute this software for any
|
||||
* purpose with or without fee is hereby granted, provided that the above
|
||||
* copyright notice and this permission notice appear in all copies.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
|
||||
* WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
|
||||
* MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
|
||||
* SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
|
||||
* WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION
|
||||
* OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
|
||||
* CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. */
|
||||
|
||||
#ifndef OPENSSL_HEADER_EC_EXTRA_INTERNAL_H
|
||||
#define OPENSSL_HEADER_EC_EXTRA_INTERNAL_H
|
||||
|
||||
#include <CCryptoBoringSSL_ec.h>
|
||||
|
||||
#include "../fipsmodule/ec/internal.h"
|
||||
|
||||
#if defined(__cplusplus)
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
|
||||
// Hash-to-curve.
|
||||
//
|
||||
// The following functions implement primitives from
|
||||
// draft-irtf-cfrg-hash-to-curve. The |dst| parameter in each function is the
|
||||
// domain separation tag and must be unique for each protocol and between the
|
||||
// |hash_to_curve| and |hash_to_scalar| variants. See section 3.1 of the spec
|
||||
// for additional guidance on this parameter.
|
||||
|
||||
// ec_hash_to_curve_p384_xmd_sha512_sswu_draft07 hashes |msg| to a point on
|
||||
// |group| and writes the result to |out|, implementing the
|
||||
// P384_XMD:SHA-512_SSWU_RO_ suite from draft-irtf-cfrg-hash-to-curve-07. It
|
||||
// returns one on success and zero on error.
|
||||
OPENSSL_EXPORT int ec_hash_to_curve_p384_xmd_sha512_sswu_draft07(
|
||||
const EC_GROUP *group, EC_RAW_POINT *out, const uint8_t *dst,
|
||||
size_t dst_len, const uint8_t *msg, size_t msg_len);
|
||||
|
||||
// ec_hash_to_scalar_p384_xmd_sha512_draft07 hashes |msg| to a scalar on |group|
|
||||
// and writes the result to |out|, using the hash_to_field operation from the
|
||||
// P384_XMD:SHA-512_SSWU_RO_ suite from draft-irtf-cfrg-hash-to-curve-07, but
|
||||
// generating a value modulo the group order rather than a field element.
|
||||
OPENSSL_EXPORT int ec_hash_to_scalar_p384_xmd_sha512_draft07(
|
||||
const EC_GROUP *group, EC_SCALAR *out, const uint8_t *dst, size_t dst_len,
|
||||
const uint8_t *msg, size_t msg_len);
|
||||
|
||||
// ec_hash_to_curve_p521_xmd_sha512_sswu_draft06 hashes |msg| to a point on
|
||||
// |group| and writes the result to |out|, implementing the
|
||||
// P521_XMD:SHA-512_SSWU_RO_ suite from draft-irtf-cfrg-hash-to-curve-06. It
|
||||
// returns one on success and zero on error.
|
||||
//
|
||||
// This function implements an older version of the draft and should not be used
|
||||
// in new code.
|
||||
OPENSSL_EXPORT int ec_hash_to_curve_p521_xmd_sha512_sswu_draft06(
|
||||
const EC_GROUP *group, EC_RAW_POINT *out, const uint8_t *dst,
|
||||
size_t dst_len, const uint8_t *msg, size_t msg_len);
|
||||
|
||||
// ec_hash_to_scalar_p521_xmd_sha512_draft06 hashes |msg| to a scalar on |group|
|
||||
// and writes the result to |out|, using the hash_to_field operation from the
|
||||
// P521_XMD:SHA-512_SSWU_RO_ suite from draft-irtf-cfrg-hash-to-curve-06, but
|
||||
// generating a value modulo the group order rather than a field element.
|
||||
//
|
||||
// This function implements an older version of the draft and should not be used
|
||||
// in new code.
|
||||
OPENSSL_EXPORT int ec_hash_to_scalar_p521_xmd_sha512_draft06(
|
||||
const EC_GROUP *group, EC_SCALAR *out, const uint8_t *dst, size_t dst_len,
|
||||
const uint8_t *msg, size_t msg_len);
|
||||
|
||||
|
||||
#if defined(__cplusplus)
|
||||
} // extern C
|
||||
#endif
|
||||
|
||||
#endif // OPENSSL_HEADER_EC_EXTRA_INTERNAL_H
|
||||
@@ -96,8 +96,8 @@ int ECDH_compute_key(void *out, size_t out_len, const EC_POINT *pub_key,
|
||||
uint8_t buf[EC_MAX_BYTES];
|
||||
size_t buf_len;
|
||||
if (!ec_point_mul_scalar(group, &shared_point, &pub_key->raw, priv) ||
|
||||
!ec_point_get_affine_coordinate_bytes(group, buf, NULL, &buf_len,
|
||||
sizeof(buf), &shared_point)) {
|
||||
!ec_get_x_coordinate_as_bytes(group, buf, &buf_len, sizeof(buf),
|
||||
&shared_point)) {
|
||||
OPENSSL_PUT_ERROR(ECDH, ECDH_R_POINT_ARITHMETIC_FAILURE);
|
||||
return -1;
|
||||
}
|
||||
|
||||
@@ -495,38 +495,39 @@ static const char *err_string_lookup(uint32_t lib, uint32_t key,
|
||||
|
||||
static const char *const kLibraryNames[ERR_NUM_LIBS] = {
|
||||
"invalid library (0)",
|
||||
"unknown library", // ERR_LIB_NONE
|
||||
"system library", // ERR_LIB_SYS
|
||||
"bignum routines", // ERR_LIB_BN
|
||||
"RSA routines", // ERR_LIB_RSA
|
||||
"Diffie-Hellman routines", // ERR_LIB_DH
|
||||
"public key routines", // ERR_LIB_EVP
|
||||
"memory buffer routines", // ERR_LIB_BUF
|
||||
"object identifier routines", // ERR_LIB_OBJ
|
||||
"PEM routines", // ERR_LIB_PEM
|
||||
"DSA routines", // ERR_LIB_DSA
|
||||
"X.509 certificate routines", // ERR_LIB_X509
|
||||
"ASN.1 encoding routines", // ERR_LIB_ASN1
|
||||
"configuration file routines", // ERR_LIB_CONF
|
||||
"common libcrypto routines", // ERR_LIB_CRYPTO
|
||||
"elliptic curve routines", // ERR_LIB_EC
|
||||
"SSL routines", // ERR_LIB_SSL
|
||||
"BIO routines", // ERR_LIB_BIO
|
||||
"PKCS7 routines", // ERR_LIB_PKCS7
|
||||
"PKCS8 routines", // ERR_LIB_PKCS8
|
||||
"X509 V3 routines", // ERR_LIB_X509V3
|
||||
"random number generator", // ERR_LIB_RAND
|
||||
"ENGINE routines", // ERR_LIB_ENGINE
|
||||
"OCSP routines", // ERR_LIB_OCSP
|
||||
"UI routines", // ERR_LIB_UI
|
||||
"COMP routines", // ERR_LIB_COMP
|
||||
"ECDSA routines", // ERR_LIB_ECDSA
|
||||
"ECDH routines", // ERR_LIB_ECDH
|
||||
"HMAC routines", // ERR_LIB_HMAC
|
||||
"Digest functions", // ERR_LIB_DIGEST
|
||||
"Cipher functions", // ERR_LIB_CIPHER
|
||||
"HKDF functions", // ERR_LIB_HKDF
|
||||
"User defined functions", // ERR_LIB_USER
|
||||
"unknown library", // ERR_LIB_NONE
|
||||
"system library", // ERR_LIB_SYS
|
||||
"bignum routines", // ERR_LIB_BN
|
||||
"RSA routines", // ERR_LIB_RSA
|
||||
"Diffie-Hellman routines", // ERR_LIB_DH
|
||||
"public key routines", // ERR_LIB_EVP
|
||||
"memory buffer routines", // ERR_LIB_BUF
|
||||
"object identifier routines", // ERR_LIB_OBJ
|
||||
"PEM routines", // ERR_LIB_PEM
|
||||
"DSA routines", // ERR_LIB_DSA
|
||||
"X.509 certificate routines", // ERR_LIB_X509
|
||||
"ASN.1 encoding routines", // ERR_LIB_ASN1
|
||||
"configuration file routines", // ERR_LIB_CONF
|
||||
"common libcrypto routines", // ERR_LIB_CRYPTO
|
||||
"elliptic curve routines", // ERR_LIB_EC
|
||||
"SSL routines", // ERR_LIB_SSL
|
||||
"BIO routines", // ERR_LIB_BIO
|
||||
"PKCS7 routines", // ERR_LIB_PKCS7
|
||||
"PKCS8 routines", // ERR_LIB_PKCS8
|
||||
"X509 V3 routines", // ERR_LIB_X509V3
|
||||
"random number generator", // ERR_LIB_RAND
|
||||
"ENGINE routines", // ERR_LIB_ENGINE
|
||||
"OCSP routines", // ERR_LIB_OCSP
|
||||
"UI routines", // ERR_LIB_UI
|
||||
"COMP routines", // ERR_LIB_COMP
|
||||
"ECDSA routines", // ERR_LIB_ECDSA
|
||||
"ECDH routines", // ERR_LIB_ECDH
|
||||
"HMAC routines", // ERR_LIB_HMAC
|
||||
"Digest functions", // ERR_LIB_DIGEST
|
||||
"Cipher functions", // ERR_LIB_CIPHER
|
||||
"HKDF functions", // ERR_LIB_HKDF
|
||||
"Trust Token functions", // ERR_LIB_TRUST_TOKEN
|
||||
"User defined functions", // ERR_LIB_USER
|
||||
};
|
||||
|
||||
const char *ERR_lib_error_string(uint32_t packed_error) {
|
||||
|
||||
@@ -50,8 +50,9 @@ OPENSSL_STATIC_ASSERT(ERR_LIB_HMAC == 28, "library value changed");
|
||||
OPENSSL_STATIC_ASSERT(ERR_LIB_DIGEST == 29, "library value changed");
|
||||
OPENSSL_STATIC_ASSERT(ERR_LIB_CIPHER == 30, "library value changed");
|
||||
OPENSSL_STATIC_ASSERT(ERR_LIB_HKDF == 31, "library value changed");
|
||||
OPENSSL_STATIC_ASSERT(ERR_LIB_USER == 32, "library value changed");
|
||||
OPENSSL_STATIC_ASSERT(ERR_NUM_LIBS == 33, "number of libraries changed");
|
||||
OPENSSL_STATIC_ASSERT(ERR_LIB_TRUST_TOKEN == 32, "library value changed");
|
||||
OPENSSL_STATIC_ASSERT(ERR_LIB_USER == 33, "library value changed");
|
||||
OPENSSL_STATIC_ASSERT(ERR_NUM_LIBS == 34, "number of libraries changed");
|
||||
|
||||
const uint32_t kOpenSSLReasonValues[] = {
|
||||
0xc32083a,
|
||||
@@ -190,44 +191,44 @@ const uint32_t kOpenSSLReasonValues[] = {
|
||||
0x283480ac,
|
||||
0x283500ea,
|
||||
0x28358c6c,
|
||||
0x2c322f0c,
|
||||
0x2c323012,
|
||||
0x2c3292e8,
|
||||
0x2c332f1a,
|
||||
0x2c33af2c,
|
||||
0x2c342f40,
|
||||
0x2c34af52,
|
||||
0x2c352f6d,
|
||||
0x2c35af7f,
|
||||
0x2c362f92,
|
||||
0x2c333020,
|
||||
0x2c33b032,
|
||||
0x2c343046,
|
||||
0x2c34b058,
|
||||
0x2c353073,
|
||||
0x2c35b085,
|
||||
0x2c363098,
|
||||
0x2c36832d,
|
||||
0x2c372f9f,
|
||||
0x2c37afb1,
|
||||
0x2c382fd6,
|
||||
0x2c38afed,
|
||||
0x2c392ffb,
|
||||
0x2c39b00b,
|
||||
0x2c3a301d,
|
||||
0x2c3ab031,
|
||||
0x2c3b3042,
|
||||
0x2c3bb061,
|
||||
0x2c3730a5,
|
||||
0x2c37b0b7,
|
||||
0x2c3830dc,
|
||||
0x2c38b0f3,
|
||||
0x2c393101,
|
||||
0x2c39b111,
|
||||
0x2c3a3123,
|
||||
0x2c3ab137,
|
||||
0x2c3b3148,
|
||||
0x2c3bb167,
|
||||
0x2c3c12fa,
|
||||
0x2c3c9310,
|
||||
0x2c3d3075,
|
||||
0x2c3d317b,
|
||||
0x2c3d9329,
|
||||
0x2c3e3092,
|
||||
0x2c3eb0a0,
|
||||
0x2c3f30b8,
|
||||
0x2c3fb0d0,
|
||||
0x2c4030fa,
|
||||
0x2c3e3198,
|
||||
0x2c3eb1a6,
|
||||
0x2c3f31be,
|
||||
0x2c3fb1d6,
|
||||
0x2c403200,
|
||||
0x2c4091fb,
|
||||
0x2c41310b,
|
||||
0x2c41b11e,
|
||||
0x2c413211,
|
||||
0x2c41b224,
|
||||
0x2c4211c1,
|
||||
0x2c42b12f,
|
||||
0x2c42b235,
|
||||
0x2c430722,
|
||||
0x2c43b053,
|
||||
0x2c442fc4,
|
||||
0x2c44b0dd,
|
||||
0x2c43b159,
|
||||
0x2c4430ca,
|
||||
0x2c44b1e3,
|
||||
0x30320000,
|
||||
0x30328015,
|
||||
0x3033001f,
|
||||
@@ -384,219 +385,221 @@ const uint32_t kOpenSSLReasonValues[] = {
|
||||
0x403b9ad8,
|
||||
0x403c0064,
|
||||
0x403c8083,
|
||||
0x403d1b5c,
|
||||
0x403d9b72,
|
||||
0x403e1b81,
|
||||
0x403e9bb9,
|
||||
0x403f1bd3,
|
||||
0x403f9bfb,
|
||||
0x40401c10,
|
||||
0x40409c24,
|
||||
0x40411c41,
|
||||
0x40419c5c,
|
||||
0x40421c75,
|
||||
0x40429c88,
|
||||
0x40431c9c,
|
||||
0x40439cb4,
|
||||
0x40441ccb,
|
||||
0x403d1b39,
|
||||
0x403d9b4f,
|
||||
0x403e1b5e,
|
||||
0x403e9b96,
|
||||
0x403f1bb0,
|
||||
0x403f9bd8,
|
||||
0x40401bed,
|
||||
0x40409c01,
|
||||
0x40411c3c,
|
||||
0x40419c57,
|
||||
0x40421c70,
|
||||
0x40429c83,
|
||||
0x40431c97,
|
||||
0x40439caf,
|
||||
0x40441cc6,
|
||||
0x404480ac,
|
||||
0x40451ce0,
|
||||
0x40459cf2,
|
||||
0x40461d16,
|
||||
0x40469d36,
|
||||
0x40471d44,
|
||||
0x40479d6b,
|
||||
0x40481ddc,
|
||||
0x40489e0f,
|
||||
0x40491e26,
|
||||
0x40499e40,
|
||||
0x404a1e57,
|
||||
0x404a9e75,
|
||||
0x404b1e8d,
|
||||
0x404b9ea4,
|
||||
0x404c1eba,
|
||||
0x404c9ecc,
|
||||
0x404d1eed,
|
||||
0x404d9f26,
|
||||
0x404e1f3a,
|
||||
0x404e9f47,
|
||||
0x404f1f8e,
|
||||
0x404f9fd4,
|
||||
0x4050202b,
|
||||
0x4050a03f,
|
||||
0x40512072,
|
||||
0x40522082,
|
||||
0x4052a0a6,
|
||||
0x405320be,
|
||||
0x4053a0d1,
|
||||
0x405420e6,
|
||||
0x4054a109,
|
||||
0x40552117,
|
||||
0x4055a154,
|
||||
0x40562161,
|
||||
0x4056a17a,
|
||||
0x40572192,
|
||||
0x4057a1a5,
|
||||
0x405821ba,
|
||||
0x4058a1e1,
|
||||
0x40592210,
|
||||
0x4059a23d,
|
||||
0x405a2251,
|
||||
0x405aa261,
|
||||
0x405b2279,
|
||||
0x405ba28a,
|
||||
0x405c229d,
|
||||
0x405ca2dc,
|
||||
0x405d22e9,
|
||||
0x405da30e,
|
||||
0x405e234c,
|
||||
0x40451cdb,
|
||||
0x40459ced,
|
||||
0x40461d11,
|
||||
0x40469d31,
|
||||
0x40471d3f,
|
||||
0x40479d66,
|
||||
0x40481dd7,
|
||||
0x40489e0a,
|
||||
0x40491e21,
|
||||
0x40499e3b,
|
||||
0x404a1e52,
|
||||
0x404a9e70,
|
||||
0x404b1e88,
|
||||
0x404b9eb5,
|
||||
0x404c1ecb,
|
||||
0x404c9edd,
|
||||
0x404d1efe,
|
||||
0x404d9f37,
|
||||
0x404e1f4b,
|
||||
0x404e9f58,
|
||||
0x404f1f9f,
|
||||
0x404f9fe5,
|
||||
0x4050203c,
|
||||
0x4050a050,
|
||||
0x40512083,
|
||||
0x40522093,
|
||||
0x4052a0b7,
|
||||
0x405320cf,
|
||||
0x4053a0e2,
|
||||
0x405420f7,
|
||||
0x4054a11a,
|
||||
0x40552128,
|
||||
0x4055a165,
|
||||
0x40562172,
|
||||
0x4056a18b,
|
||||
0x405721a3,
|
||||
0x4057a1b6,
|
||||
0x405821cb,
|
||||
0x4058a1f2,
|
||||
0x40592221,
|
||||
0x4059a24e,
|
||||
0x405a2262,
|
||||
0x405aa272,
|
||||
0x405b228a,
|
||||
0x405ba29b,
|
||||
0x405c22ae,
|
||||
0x405ca2ed,
|
||||
0x405d22fa,
|
||||
0x405da31f,
|
||||
0x405e235d,
|
||||
0x405e8ab3,
|
||||
0x405f236d,
|
||||
0x405fa37a,
|
||||
0x40602388,
|
||||
0x4060a3aa,
|
||||
0x4061240b,
|
||||
0x4061a443,
|
||||
0x4062245a,
|
||||
0x4062a46b,
|
||||
0x40632490,
|
||||
0x4063a4a5,
|
||||
0x406424bc,
|
||||
0x4064a4e8,
|
||||
0x40652503,
|
||||
0x4065a51a,
|
||||
0x40662532,
|
||||
0x4066a55c,
|
||||
0x40672587,
|
||||
0x4067a5cc,
|
||||
0x40682614,
|
||||
0x4068a635,
|
||||
0x40692667,
|
||||
0x4069a695,
|
||||
0x406a26b6,
|
||||
0x406aa6d6,
|
||||
0x406b285e,
|
||||
0x406ba881,
|
||||
0x406c2897,
|
||||
0x406cab3a,
|
||||
0x406d2b69,
|
||||
0x406dab91,
|
||||
0x406e2bbf,
|
||||
0x406eac0c,
|
||||
0x406f2c47,
|
||||
0x406fac7f,
|
||||
0x40702c92,
|
||||
0x4070acaf,
|
||||
0x405f237e,
|
||||
0x405fa38b,
|
||||
0x40602399,
|
||||
0x4060a3bb,
|
||||
0x4061241c,
|
||||
0x4061a454,
|
||||
0x4062246b,
|
||||
0x4062a47c,
|
||||
0x406324c9,
|
||||
0x4063a4de,
|
||||
0x406424f5,
|
||||
0x4064a521,
|
||||
0x4065253c,
|
||||
0x4065a553,
|
||||
0x4066256b,
|
||||
0x4066a595,
|
||||
0x406725c0,
|
||||
0x4067a605,
|
||||
0x4068264d,
|
||||
0x4068a66e,
|
||||
0x406926a0,
|
||||
0x4069a6ce,
|
||||
0x406a26ef,
|
||||
0x406aa70f,
|
||||
0x406b2897,
|
||||
0x406ba8ba,
|
||||
0x406c28d0,
|
||||
0x406cab73,
|
||||
0x406d2ba2,
|
||||
0x406dabca,
|
||||
0x406e2bf8,
|
||||
0x406eac45,
|
||||
0x406f2c80,
|
||||
0x406facb8,
|
||||
0x40702ccb,
|
||||
0x4070ace8,
|
||||
0x40710802,
|
||||
0x4071acc1,
|
||||
0x40722cd4,
|
||||
0x4072ad0a,
|
||||
0x40732d22,
|
||||
0x4071acfa,
|
||||
0x40722d0d,
|
||||
0x4072ad43,
|
||||
0x40732d5b,
|
||||
0x407394fa,
|
||||
0x40742d36,
|
||||
0x4074ad50,
|
||||
0x40752d61,
|
||||
0x4075ad75,
|
||||
0x40762d83,
|
||||
0x40742d6f,
|
||||
0x4074ad89,
|
||||
0x40752d9a,
|
||||
0x4075adae,
|
||||
0x40762dbc,
|
||||
0x407692be,
|
||||
0x40772da8,
|
||||
0x4077adca,
|
||||
0x40782de5,
|
||||
0x4078ae1e,
|
||||
0x40792e35,
|
||||
0x4079ae4b,
|
||||
0x407a2e77,
|
||||
0x407aae8a,
|
||||
0x407b2e9f,
|
||||
0x407baeb1,
|
||||
0x407c2ee2,
|
||||
0x407caeeb,
|
||||
0x407d2650,
|
||||
0x407d9fe4,
|
||||
0x407e2dfa,
|
||||
0x407ea1f1,
|
||||
0x407f1d58,
|
||||
0x407f9afe,
|
||||
0x40801f9e,
|
||||
0x40809d80,
|
||||
0x40812094,
|
||||
0x40819f78,
|
||||
0x40822baa,
|
||||
0x40772de1,
|
||||
0x4077ae03,
|
||||
0x40782e1e,
|
||||
0x4078ae57,
|
||||
0x40792e6e,
|
||||
0x4079ae84,
|
||||
0x407a2eb0,
|
||||
0x407aaec3,
|
||||
0x407b2ed8,
|
||||
0x407baeea,
|
||||
0x407c2f1b,
|
||||
0x407caf24,
|
||||
0x407d2689,
|
||||
0x407d9ff5,
|
||||
0x407e2e33,
|
||||
0x407ea202,
|
||||
0x407f1d53,
|
||||
0x407f9e9f,
|
||||
0x40801faf,
|
||||
0x40809d7b,
|
||||
0x408120a5,
|
||||
0x40819f89,
|
||||
0x40822be3,
|
||||
0x40829ae4,
|
||||
0x408321cc,
|
||||
0x4083a4cd,
|
||||
0x40841d94,
|
||||
0x4084a229,
|
||||
0x408522ae,
|
||||
0x4085a3d2,
|
||||
0x4086232e,
|
||||
0x40869ffe,
|
||||
0x40872bf0,
|
||||
0x4087a420,
|
||||
0x40881b45,
|
||||
0x4088a5df,
|
||||
0x40891b94,
|
||||
0x40899b21,
|
||||
0x408a28cf,
|
||||
0x408321dd,
|
||||
0x4083a506,
|
||||
0x40841d8f,
|
||||
0x4084a23a,
|
||||
0x408522bf,
|
||||
0x4085a3e3,
|
||||
0x4086233f,
|
||||
0x4086a00f,
|
||||
0x40872c29,
|
||||
0x4087a431,
|
||||
0x40881b22,
|
||||
0x4088a618,
|
||||
0x40891b71,
|
||||
0x40899afe,
|
||||
0x408a2908,
|
||||
0x408a9912,
|
||||
0x408b2ec6,
|
||||
0x408bac5c,
|
||||
0x408c22be,
|
||||
0x408b2eff,
|
||||
0x408bac95,
|
||||
0x408c22cf,
|
||||
0x408c992e,
|
||||
0x408d1df5,
|
||||
0x408d9dc6,
|
||||
0x408e1f0f,
|
||||
0x408ea134,
|
||||
0x408f25f3,
|
||||
0x408fa3ee,
|
||||
0x409025a8,
|
||||
0x4090a300,
|
||||
0x409128b7,
|
||||
0x408d1df0,
|
||||
0x408d9dc1,
|
||||
0x408e1f20,
|
||||
0x408ea145,
|
||||
0x408f262c,
|
||||
0x408fa3ff,
|
||||
0x409025e1,
|
||||
0x4090a311,
|
||||
0x409128f0,
|
||||
0x40919954,
|
||||
0x40921be1,
|
||||
0x4092ac2b,
|
||||
0x40932ced,
|
||||
0x4093a00f,
|
||||
0x40941da8,
|
||||
0x4094a8e8,
|
||||
0x4095247c,
|
||||
0x4095ae57,
|
||||
0x40962bd7,
|
||||
0x40969fb7,
|
||||
0x4097205a,
|
||||
0x40979f5e,
|
||||
0x41f42789,
|
||||
0x41f9281b,
|
||||
0x41fe270e,
|
||||
0x41fea92b,
|
||||
0x41ff2a1c,
|
||||
0x420327a2,
|
||||
0x420827c4,
|
||||
0x4208a800,
|
||||
0x420926f2,
|
||||
0x4209a83a,
|
||||
0x420a2749,
|
||||
0x420aa729,
|
||||
0x420b2769,
|
||||
0x420ba7e2,
|
||||
0x420c2a38,
|
||||
0x420ca8f8,
|
||||
0x420d2912,
|
||||
0x420da949,
|
||||
0x42122963,
|
||||
0x421729ff,
|
||||
0x4217a9a5,
|
||||
0x421c29c7,
|
||||
0x421f2982,
|
||||
0x42212a4f,
|
||||
0x422629e2,
|
||||
0x422b2b1e,
|
||||
0x422baacc,
|
||||
0x422c2b06,
|
||||
0x422caa8b,
|
||||
0x422d2a6a,
|
||||
0x422daaeb,
|
||||
0x422e2ab1,
|
||||
0x40921bbe,
|
||||
0x4092ac64,
|
||||
0x40932d26,
|
||||
0x4093a020,
|
||||
0x40941da3,
|
||||
0x4094a921,
|
||||
0x4095248d,
|
||||
0x4095ae90,
|
||||
0x40962c10,
|
||||
0x40969fc8,
|
||||
0x4097206b,
|
||||
0x40979f6f,
|
||||
0x40981c1e,
|
||||
0x4098a4a1,
|
||||
0x41f427c2,
|
||||
0x41f92854,
|
||||
0x41fe2747,
|
||||
0x41fea964,
|
||||
0x41ff2a55,
|
||||
0x420327db,
|
||||
0x420827fd,
|
||||
0x4208a839,
|
||||
0x4209272b,
|
||||
0x4209a873,
|
||||
0x420a2782,
|
||||
0x420aa762,
|
||||
0x420b27a2,
|
||||
0x420ba81b,
|
||||
0x420c2a71,
|
||||
0x420ca931,
|
||||
0x420d294b,
|
||||
0x420da982,
|
||||
0x4212299c,
|
||||
0x42172a38,
|
||||
0x4217a9de,
|
||||
0x421c2a00,
|
||||
0x421f29bb,
|
||||
0x42212a88,
|
||||
0x42262a1b,
|
||||
0x422b2b57,
|
||||
0x422bab05,
|
||||
0x422c2b3f,
|
||||
0x422caac4,
|
||||
0x422d2aa3,
|
||||
0x422dab24,
|
||||
0x422e2aea,
|
||||
0x4432072d,
|
||||
0x4432873c,
|
||||
0x44330748,
|
||||
@@ -651,69 +654,69 @@ const uint32_t kOpenSSLReasonValues[] = {
|
||||
0x4c411557,
|
||||
0x4c4193da,
|
||||
0x4c421543,
|
||||
0x50323141,
|
||||
0x5032b150,
|
||||
0x5033315b,
|
||||
0x5033b16b,
|
||||
0x50343184,
|
||||
0x5034b19e,
|
||||
0x503531ac,
|
||||
0x5035b1c2,
|
||||
0x503631d4,
|
||||
0x5036b1ea,
|
||||
0x50373203,
|
||||
0x5037b216,
|
||||
0x5038322e,
|
||||
0x5038b23f,
|
||||
0x50393254,
|
||||
0x5039b268,
|
||||
0x503a3288,
|
||||
0x503ab29e,
|
||||
0x503b32b6,
|
||||
0x503bb2c8,
|
||||
0x503c32e4,
|
||||
0x503cb2fb,
|
||||
0x503d3314,
|
||||
0x503db32a,
|
||||
0x503e3337,
|
||||
0x503eb34d,
|
||||
0x503f335f,
|
||||
0x50323247,
|
||||
0x5032b256,
|
||||
0x50333261,
|
||||
0x5033b271,
|
||||
0x5034328a,
|
||||
0x5034b2a4,
|
||||
0x503532b2,
|
||||
0x5035b2c8,
|
||||
0x503632da,
|
||||
0x5036b2f0,
|
||||
0x50373309,
|
||||
0x5037b31c,
|
||||
0x50383334,
|
||||
0x5038b345,
|
||||
0x5039335a,
|
||||
0x5039b36e,
|
||||
0x503a338e,
|
||||
0x503ab3a4,
|
||||
0x503b33bc,
|
||||
0x503bb3ce,
|
||||
0x503c33ea,
|
||||
0x503cb401,
|
||||
0x503d341a,
|
||||
0x503db430,
|
||||
0x503e343d,
|
||||
0x503eb453,
|
||||
0x503f3465,
|
||||
0x503f837b,
|
||||
0x50403372,
|
||||
0x5040b382,
|
||||
0x5041339c,
|
||||
0x5041b3ab,
|
||||
0x504233c5,
|
||||
0x5042b3e2,
|
||||
0x504333f2,
|
||||
0x5043b402,
|
||||
0x50443411,
|
||||
0x50403478,
|
||||
0x5040b488,
|
||||
0x504134a2,
|
||||
0x5041b4b1,
|
||||
0x504234cb,
|
||||
0x5042b4e8,
|
||||
0x504334f8,
|
||||
0x5043b508,
|
||||
0x50443517,
|
||||
0x50448431,
|
||||
0x50453425,
|
||||
0x5045b443,
|
||||
0x50463456,
|
||||
0x5046b46c,
|
||||
0x5047347e,
|
||||
0x5047b493,
|
||||
0x504834b9,
|
||||
0x5048b4c7,
|
||||
0x504934da,
|
||||
0x5049b4ef,
|
||||
0x504a3505,
|
||||
0x504ab515,
|
||||
0x504b3535,
|
||||
0x504bb548,
|
||||
0x504c356b,
|
||||
0x504cb599,
|
||||
0x504d35ab,
|
||||
0x504db5c8,
|
||||
0x504e35e3,
|
||||
0x504eb5ff,
|
||||
0x504f3611,
|
||||
0x504fb628,
|
||||
0x50503637,
|
||||
0x5045352b,
|
||||
0x5045b549,
|
||||
0x5046355c,
|
||||
0x5046b572,
|
||||
0x50473584,
|
||||
0x5047b599,
|
||||
0x504835bf,
|
||||
0x5048b5cd,
|
||||
0x504935e0,
|
||||
0x5049b5f5,
|
||||
0x504a360b,
|
||||
0x504ab61b,
|
||||
0x504b363b,
|
||||
0x504bb64e,
|
||||
0x504c3671,
|
||||
0x504cb69f,
|
||||
0x504d36b1,
|
||||
0x504db6ce,
|
||||
0x504e36e9,
|
||||
0x504eb705,
|
||||
0x504f3717,
|
||||
0x504fb72e,
|
||||
0x5050373d,
|
||||
0x505086f1,
|
||||
0x5051364a,
|
||||
0x50513750,
|
||||
0x58320f65,
|
||||
0x68320f27,
|
||||
0x68328c7f,
|
||||
@@ -755,6 +758,21 @@ const uint32_t kOpenSSLReasonValues[] = {
|
||||
0x783e0aa2,
|
||||
0x783e8a54,
|
||||
0x7c3211d7,
|
||||
0x803213ed,
|
||||
0x80328083,
|
||||
0x80332fe1,
|
||||
0x803380ac,
|
||||
0x80342ff0,
|
||||
0x8034af58,
|
||||
0x80352f76,
|
||||
0x8035b004,
|
||||
0x80362fb8,
|
||||
0x8036af67,
|
||||
0x80372faa,
|
||||
0x8037af45,
|
||||
0x80382fcb,
|
||||
0x8038af87,
|
||||
0x80392f9c,
|
||||
};
|
||||
|
||||
const size_t kOpenSSLReasonValuesLen = sizeof(kOpenSSLReasonValues) / sizeof(kOpenSSLReasonValues[0]);
|
||||
@@ -1109,7 +1127,6 @@ const char kOpenSSLReasonStringData[] =
|
||||
"BAD_WRITE_RETRY\0"
|
||||
"BIO_NOT_SET\0"
|
||||
"BLOCK_CIPHER_PAD_IS_WRONG\0"
|
||||
"BUFFERED_MESSAGES_ON_CIPHER_CHANGE\0"
|
||||
"CANNOT_HAVE_BOTH_PRIVKEY_AND_METHOD\0"
|
||||
"CANNOT_PARSE_LEAF_CERT\0"
|
||||
"CA_DN_LENGTH_MISMATCH\0"
|
||||
@@ -1122,6 +1139,7 @@ const char kOpenSSLReasonStringData[] =
|
||||
"CERT_LENGTH_MISMATCH\0"
|
||||
"CHANNEL_ID_NOT_P256\0"
|
||||
"CHANNEL_ID_SIGNATURE_INVALID\0"
|
||||
"CIPHER_MISMATCH_ON_EARLY_DATA\0"
|
||||
"CIPHER_OR_HASH_UNAVAILABLE\0"
|
||||
"CLIENTHELLO_PARSE_FAILED\0"
|
||||
"CLIENTHELLO_TLSEXT\0"
|
||||
@@ -1148,6 +1166,7 @@ const char kOpenSSLReasonStringData[] =
|
||||
"ERROR_IN_RECEIVED_CIPHER_LIST\0"
|
||||
"ERROR_PARSING_EXTENSION\0"
|
||||
"EXCESSIVE_MESSAGE_SIZE\0"
|
||||
"EXCESS_HANDSHAKE_DATA\0"
|
||||
"EXTRA_DATA_IN_MESSAGE\0"
|
||||
"FRAGMENT_MISMATCH\0"
|
||||
"GOT_NEXT_PROTO_WITHOUT_EXTENSION\0"
|
||||
@@ -1215,6 +1234,7 @@ const char kOpenSSLReasonStringData[] =
|
||||
"PSK_NO_CLIENT_CB\0"
|
||||
"PSK_NO_SERVER_CB\0"
|
||||
"QUIC_INTERNAL_ERROR\0"
|
||||
"QUIC_TRANSPORT_PARAMETERS_MISCONFIGURED\0"
|
||||
"READ_TIMEOUT_EXPIRED\0"
|
||||
"RECORD_LENGTH_MISMATCH\0"
|
||||
"RECORD_TOO_LARGE\0"
|
||||
@@ -1313,6 +1333,18 @@ const char kOpenSSLReasonStringData[] =
|
||||
"WRONG_VERSION_ON_EARLY_DATA\0"
|
||||
"X509_LIB\0"
|
||||
"X509_VERIFICATION_SETUP_PROBLEMS\0"
|
||||
"BAD_VALIDITY_CHECK\0"
|
||||
"DECODE_FAILURE\0"
|
||||
"INVALID_KEY_ID\0"
|
||||
"INVALID_METADATA\0"
|
||||
"INVALID_METADATA_KEY\0"
|
||||
"INVALID_PROOF\0"
|
||||
"INVALID_TOKEN\0"
|
||||
"NO_KEYS_CONFIGURED\0"
|
||||
"NO_SRR_KEY_CONFIGURED\0"
|
||||
"OVER_BATCHSIZE\0"
|
||||
"SRR_SIGNATURE_ERROR\0"
|
||||
"TOO_MANY_KEYS\0"
|
||||
"AKID_MISMATCH\0"
|
||||
"BAD_X509_FILETYPE\0"
|
||||
"BASE64_DECODE_ERROR\0"
|
||||
|
||||
@@ -472,7 +472,7 @@ static void aes_nohw_transpose(AES_NOHW_BATCH *batch) {
|
||||
// |num_blocks| must be at most |AES_NOHW_BATCH|.
|
||||
static void aes_nohw_to_batch(AES_NOHW_BATCH *out, const uint8_t *in,
|
||||
size_t num_blocks) {
|
||||
// Don't leave unused blocks unitialized.
|
||||
// Don't leave unused blocks uninitialized.
|
||||
memset(out, 0, sizeof(AES_NOHW_BATCH));
|
||||
assert(num_blocks <= AES_NOHW_BATCH_SIZE);
|
||||
for (size_t i = 0; i < num_blocks; i++) {
|
||||
|
||||
@@ -57,7 +57,23 @@
|
||||
void AES_ctr128_encrypt(const uint8_t *in, uint8_t *out, size_t len,
|
||||
const AES_KEY *key, uint8_t ivec[AES_BLOCK_SIZE],
|
||||
uint8_t ecount_buf[AES_BLOCK_SIZE], unsigned int *num) {
|
||||
CRYPTO_ctr128_encrypt(in, out, len, key, ivec, ecount_buf, num, AES_encrypt);
|
||||
if (hwaes_capable()) {
|
||||
CRYPTO_ctr128_encrypt_ctr32(in, out, len, key, ivec, ecount_buf, num,
|
||||
aes_hw_ctr32_encrypt_blocks);
|
||||
} else if (vpaes_capable()) {
|
||||
#if defined(VPAES_CTR32)
|
||||
// TODO(davidben): On ARM, where |BSAES| is additionally defined, this could
|
||||
// use |vpaes_ctr32_encrypt_blocks_with_bsaes|.
|
||||
CRYPTO_ctr128_encrypt_ctr32(in, out, len, key, ivec, ecount_buf, num,
|
||||
vpaes_ctr32_encrypt_blocks);
|
||||
#else
|
||||
CRYPTO_ctr128_encrypt(in, out, len, key, ivec, ecount_buf, num,
|
||||
vpaes_encrypt);
|
||||
#endif
|
||||
} else {
|
||||
CRYPTO_ctr128_encrypt_ctr32(in, out, len, key, ivec, ecount_buf, num,
|
||||
aes_nohw_ctr32_encrypt_blocks);
|
||||
}
|
||||
}
|
||||
|
||||
void AES_ecb_encrypt(const uint8_t *in, uint8_t *out, const AES_KEY *key,
|
||||
|
||||
@@ -995,553 +995,6 @@ bn_sub_words:
|
||||
popl %ebp
|
||||
ret
|
||||
.size bn_sub_words,.-.L_bn_sub_words_begin
|
||||
.globl bn_sub_part_words
|
||||
.hidden bn_sub_part_words
|
||||
.type bn_sub_part_words,@function
|
||||
.align 16
|
||||
bn_sub_part_words:
|
||||
.L_bn_sub_part_words_begin:
|
||||
pushl %ebp
|
||||
pushl %ebx
|
||||
pushl %esi
|
||||
pushl %edi
|
||||
|
||||
movl 20(%esp),%ebx
|
||||
movl 24(%esp),%esi
|
||||
movl 28(%esp),%edi
|
||||
movl 32(%esp),%ebp
|
||||
xorl %eax,%eax
|
||||
andl $4294967288,%ebp
|
||||
jz .L029aw_finish
|
||||
.L030aw_loop:
|
||||
|
||||
movl (%esi),%ecx
|
||||
movl (%edi),%edx
|
||||
subl %eax,%ecx
|
||||
movl $0,%eax
|
||||
adcl %eax,%eax
|
||||
subl %edx,%ecx
|
||||
adcl $0,%eax
|
||||
movl %ecx,(%ebx)
|
||||
|
||||
movl 4(%esi),%ecx
|
||||
movl 4(%edi),%edx
|
||||
subl %eax,%ecx
|
||||
movl $0,%eax
|
||||
adcl %eax,%eax
|
||||
subl %edx,%ecx
|
||||
adcl $0,%eax
|
||||
movl %ecx,4(%ebx)
|
||||
|
||||
movl 8(%esi),%ecx
|
||||
movl 8(%edi),%edx
|
||||
subl %eax,%ecx
|
||||
movl $0,%eax
|
||||
adcl %eax,%eax
|
||||
subl %edx,%ecx
|
||||
adcl $0,%eax
|
||||
movl %ecx,8(%ebx)
|
||||
|
||||
movl 12(%esi),%ecx
|
||||
movl 12(%edi),%edx
|
||||
subl %eax,%ecx
|
||||
movl $0,%eax
|
||||
adcl %eax,%eax
|
||||
subl %edx,%ecx
|
||||
adcl $0,%eax
|
||||
movl %ecx,12(%ebx)
|
||||
|
||||
movl 16(%esi),%ecx
|
||||
movl 16(%edi),%edx
|
||||
subl %eax,%ecx
|
||||
movl $0,%eax
|
||||
adcl %eax,%eax
|
||||
subl %edx,%ecx
|
||||
adcl $0,%eax
|
||||
movl %ecx,16(%ebx)
|
||||
|
||||
movl 20(%esi),%ecx
|
||||
movl 20(%edi),%edx
|
||||
subl %eax,%ecx
|
||||
movl $0,%eax
|
||||
adcl %eax,%eax
|
||||
subl %edx,%ecx
|
||||
adcl $0,%eax
|
||||
movl %ecx,20(%ebx)
|
||||
|
||||
movl 24(%esi),%ecx
|
||||
movl 24(%edi),%edx
|
||||
subl %eax,%ecx
|
||||
movl $0,%eax
|
||||
adcl %eax,%eax
|
||||
subl %edx,%ecx
|
||||
adcl $0,%eax
|
||||
movl %ecx,24(%ebx)
|
||||
|
||||
movl 28(%esi),%ecx
|
||||
movl 28(%edi),%edx
|
||||
subl %eax,%ecx
|
||||
movl $0,%eax
|
||||
adcl %eax,%eax
|
||||
subl %edx,%ecx
|
||||
adcl $0,%eax
|
||||
movl %ecx,28(%ebx)
|
||||
|
||||
addl $32,%esi
|
||||
addl $32,%edi
|
||||
addl $32,%ebx
|
||||
subl $8,%ebp
|
||||
jnz .L030aw_loop
|
||||
.L029aw_finish:
|
||||
movl 32(%esp),%ebp
|
||||
andl $7,%ebp
|
||||
jz .L031aw_end
|
||||
|
||||
movl (%esi),%ecx
|
||||
movl (%edi),%edx
|
||||
subl %eax,%ecx
|
||||
movl $0,%eax
|
||||
adcl %eax,%eax
|
||||
subl %edx,%ecx
|
||||
adcl $0,%eax
|
||||
movl %ecx,(%ebx)
|
||||
addl $4,%esi
|
||||
addl $4,%edi
|
||||
addl $4,%ebx
|
||||
decl %ebp
|
||||
jz .L031aw_end
|
||||
|
||||
movl (%esi),%ecx
|
||||
movl (%edi),%edx
|
||||
subl %eax,%ecx
|
||||
movl $0,%eax
|
||||
adcl %eax,%eax
|
||||
subl %edx,%ecx
|
||||
adcl $0,%eax
|
||||
movl %ecx,(%ebx)
|
||||
addl $4,%esi
|
||||
addl $4,%edi
|
||||
addl $4,%ebx
|
||||
decl %ebp
|
||||
jz .L031aw_end
|
||||
|
||||
movl (%esi),%ecx
|
||||
movl (%edi),%edx
|
||||
subl %eax,%ecx
|
||||
movl $0,%eax
|
||||
adcl %eax,%eax
|
||||
subl %edx,%ecx
|
||||
adcl $0,%eax
|
||||
movl %ecx,(%ebx)
|
||||
addl $4,%esi
|
||||
addl $4,%edi
|
||||
addl $4,%ebx
|
||||
decl %ebp
|
||||
jz .L031aw_end
|
||||
|
||||
movl (%esi),%ecx
|
||||
movl (%edi),%edx
|
||||
subl %eax,%ecx
|
||||
movl $0,%eax
|
||||
adcl %eax,%eax
|
||||
subl %edx,%ecx
|
||||
adcl $0,%eax
|
||||
movl %ecx,(%ebx)
|
||||
addl $4,%esi
|
||||
addl $4,%edi
|
||||
addl $4,%ebx
|
||||
decl %ebp
|
||||
jz .L031aw_end
|
||||
|
||||
movl (%esi),%ecx
|
||||
movl (%edi),%edx
|
||||
subl %eax,%ecx
|
||||
movl $0,%eax
|
||||
adcl %eax,%eax
|
||||
subl %edx,%ecx
|
||||
adcl $0,%eax
|
||||
movl %ecx,(%ebx)
|
||||
addl $4,%esi
|
||||
addl $4,%edi
|
||||
addl $4,%ebx
|
||||
decl %ebp
|
||||
jz .L031aw_end
|
||||
|
||||
movl (%esi),%ecx
|
||||
movl (%edi),%edx
|
||||
subl %eax,%ecx
|
||||
movl $0,%eax
|
||||
adcl %eax,%eax
|
||||
subl %edx,%ecx
|
||||
adcl $0,%eax
|
||||
movl %ecx,(%ebx)
|
||||
addl $4,%esi
|
||||
addl $4,%edi
|
||||
addl $4,%ebx
|
||||
decl %ebp
|
||||
jz .L031aw_end
|
||||
|
||||
movl (%esi),%ecx
|
||||
movl (%edi),%edx
|
||||
subl %eax,%ecx
|
||||
movl $0,%eax
|
||||
adcl %eax,%eax
|
||||
subl %edx,%ecx
|
||||
adcl $0,%eax
|
||||
movl %ecx,(%ebx)
|
||||
addl $4,%esi
|
||||
addl $4,%edi
|
||||
addl $4,%ebx
|
||||
.L031aw_end:
|
||||
cmpl $0,36(%esp)
|
||||
je .L032pw_end
|
||||
movl 36(%esp),%ebp
|
||||
cmpl $0,%ebp
|
||||
je .L032pw_end
|
||||
jge .L033pw_pos
|
||||
|
||||
movl $0,%edx
|
||||
subl %ebp,%edx
|
||||
movl %edx,%ebp
|
||||
andl $4294967288,%ebp
|
||||
jz .L034pw_neg_finish
|
||||
.L035pw_neg_loop:
|
||||
|
||||
movl $0,%ecx
|
||||
movl (%edi),%edx
|
||||
subl %eax,%ecx
|
||||
movl $0,%eax
|
||||
adcl %eax,%eax
|
||||
subl %edx,%ecx
|
||||
adcl $0,%eax
|
||||
movl %ecx,(%ebx)
|
||||
|
||||
movl $0,%ecx
|
||||
movl 4(%edi),%edx
|
||||
subl %eax,%ecx
|
||||
movl $0,%eax
|
||||
adcl %eax,%eax
|
||||
subl %edx,%ecx
|
||||
adcl $0,%eax
|
||||
movl %ecx,4(%ebx)
|
||||
|
||||
movl $0,%ecx
|
||||
movl 8(%edi),%edx
|
||||
subl %eax,%ecx
|
||||
movl $0,%eax
|
||||
adcl %eax,%eax
|
||||
subl %edx,%ecx
|
||||
adcl $0,%eax
|
||||
movl %ecx,8(%ebx)
|
||||
|
||||
movl $0,%ecx
|
||||
movl 12(%edi),%edx
|
||||
subl %eax,%ecx
|
||||
movl $0,%eax
|
||||
adcl %eax,%eax
|
||||
subl %edx,%ecx
|
||||
adcl $0,%eax
|
||||
movl %ecx,12(%ebx)
|
||||
|
||||
movl $0,%ecx
|
||||
movl 16(%edi),%edx
|
||||
subl %eax,%ecx
|
||||
movl $0,%eax
|
||||
adcl %eax,%eax
|
||||
subl %edx,%ecx
|
||||
adcl $0,%eax
|
||||
movl %ecx,16(%ebx)
|
||||
|
||||
movl $0,%ecx
|
||||
movl 20(%edi),%edx
|
||||
subl %eax,%ecx
|
||||
movl $0,%eax
|
||||
adcl %eax,%eax
|
||||
subl %edx,%ecx
|
||||
adcl $0,%eax
|
||||
movl %ecx,20(%ebx)
|
||||
|
||||
movl $0,%ecx
|
||||
movl 24(%edi),%edx
|
||||
subl %eax,%ecx
|
||||
movl $0,%eax
|
||||
adcl %eax,%eax
|
||||
subl %edx,%ecx
|
||||
adcl $0,%eax
|
||||
movl %ecx,24(%ebx)
|
||||
|
||||
movl $0,%ecx
|
||||
movl 28(%edi),%edx
|
||||
subl %eax,%ecx
|
||||
movl $0,%eax
|
||||
adcl %eax,%eax
|
||||
subl %edx,%ecx
|
||||
adcl $0,%eax
|
||||
movl %ecx,28(%ebx)
|
||||
|
||||
addl $32,%edi
|
||||
addl $32,%ebx
|
||||
subl $8,%ebp
|
||||
jnz .L035pw_neg_loop
|
||||
.L034pw_neg_finish:
|
||||
movl 36(%esp),%edx
|
||||
movl $0,%ebp
|
||||
subl %edx,%ebp
|
||||
andl $7,%ebp
|
||||
jz .L032pw_end
|
||||
|
||||
movl $0,%ecx
|
||||
movl (%edi),%edx
|
||||
subl %eax,%ecx
|
||||
movl $0,%eax
|
||||
adcl %eax,%eax
|
||||
subl %edx,%ecx
|
||||
adcl $0,%eax
|
||||
decl %ebp
|
||||
movl %ecx,(%ebx)
|
||||
jz .L032pw_end
|
||||
|
||||
movl $0,%ecx
|
||||
movl 4(%edi),%edx
|
||||
subl %eax,%ecx
|
||||
movl $0,%eax
|
||||
adcl %eax,%eax
|
||||
subl %edx,%ecx
|
||||
adcl $0,%eax
|
||||
decl %ebp
|
||||
movl %ecx,4(%ebx)
|
||||
jz .L032pw_end
|
||||
|
||||
movl $0,%ecx
|
||||
movl 8(%edi),%edx
|
||||
subl %eax,%ecx
|
||||
movl $0,%eax
|
||||
adcl %eax,%eax
|
||||
subl %edx,%ecx
|
||||
adcl $0,%eax
|
||||
decl %ebp
|
||||
movl %ecx,8(%ebx)
|
||||
jz .L032pw_end
|
||||
|
||||
movl $0,%ecx
|
||||
movl 12(%edi),%edx
|
||||
subl %eax,%ecx
|
||||
movl $0,%eax
|
||||
adcl %eax,%eax
|
||||
subl %edx,%ecx
|
||||
adcl $0,%eax
|
||||
decl %ebp
|
||||
movl %ecx,12(%ebx)
|
||||
jz .L032pw_end
|
||||
|
||||
movl $0,%ecx
|
||||
movl 16(%edi),%edx
|
||||
subl %eax,%ecx
|
||||
movl $0,%eax
|
||||
adcl %eax,%eax
|
||||
subl %edx,%ecx
|
||||
adcl $0,%eax
|
||||
decl %ebp
|
||||
movl %ecx,16(%ebx)
|
||||
jz .L032pw_end
|
||||
|
||||
movl $0,%ecx
|
||||
movl 20(%edi),%edx
|
||||
subl %eax,%ecx
|
||||
movl $0,%eax
|
||||
adcl %eax,%eax
|
||||
subl %edx,%ecx
|
||||
adcl $0,%eax
|
||||
decl %ebp
|
||||
movl %ecx,20(%ebx)
|
||||
jz .L032pw_end
|
||||
|
||||
movl $0,%ecx
|
||||
movl 24(%edi),%edx
|
||||
subl %eax,%ecx
|
||||
movl $0,%eax
|
||||
adcl %eax,%eax
|
||||
subl %edx,%ecx
|
||||
adcl $0,%eax
|
||||
movl %ecx,24(%ebx)
|
||||
jmp .L032pw_end
|
||||
.L033pw_pos:
|
||||
andl $4294967288,%ebp
|
||||
jz .L036pw_pos_finish
|
||||
.L037pw_pos_loop:
|
||||
|
||||
movl (%esi),%ecx
|
||||
subl %eax,%ecx
|
||||
movl %ecx,(%ebx)
|
||||
jnc .L038pw_nc0
|
||||
|
||||
movl 4(%esi),%ecx
|
||||
subl %eax,%ecx
|
||||
movl %ecx,4(%ebx)
|
||||
jnc .L039pw_nc1
|
||||
|
||||
movl 8(%esi),%ecx
|
||||
subl %eax,%ecx
|
||||
movl %ecx,8(%ebx)
|
||||
jnc .L040pw_nc2
|
||||
|
||||
movl 12(%esi),%ecx
|
||||
subl %eax,%ecx
|
||||
movl %ecx,12(%ebx)
|
||||
jnc .L041pw_nc3
|
||||
|
||||
movl 16(%esi),%ecx
|
||||
subl %eax,%ecx
|
||||
movl %ecx,16(%ebx)
|
||||
jnc .L042pw_nc4
|
||||
|
||||
movl 20(%esi),%ecx
|
||||
subl %eax,%ecx
|
||||
movl %ecx,20(%ebx)
|
||||
jnc .L043pw_nc5
|
||||
|
||||
movl 24(%esi),%ecx
|
||||
subl %eax,%ecx
|
||||
movl %ecx,24(%ebx)
|
||||
jnc .L044pw_nc6
|
||||
|
||||
movl 28(%esi),%ecx
|
||||
subl %eax,%ecx
|
||||
movl %ecx,28(%ebx)
|
||||
jnc .L045pw_nc7
|
||||
|
||||
addl $32,%esi
|
||||
addl $32,%ebx
|
||||
subl $8,%ebp
|
||||
jnz .L037pw_pos_loop
|
||||
.L036pw_pos_finish:
|
||||
movl 36(%esp),%ebp
|
||||
andl $7,%ebp
|
||||
jz .L032pw_end
|
||||
|
||||
movl (%esi),%ecx
|
||||
subl %eax,%ecx
|
||||
movl %ecx,(%ebx)
|
||||
jnc .L046pw_tail_nc0
|
||||
decl %ebp
|
||||
jz .L032pw_end
|
||||
|
||||
movl 4(%esi),%ecx
|
||||
subl %eax,%ecx
|
||||
movl %ecx,4(%ebx)
|
||||
jnc .L047pw_tail_nc1
|
||||
decl %ebp
|
||||
jz .L032pw_end
|
||||
|
||||
movl 8(%esi),%ecx
|
||||
subl %eax,%ecx
|
||||
movl %ecx,8(%ebx)
|
||||
jnc .L048pw_tail_nc2
|
||||
decl %ebp
|
||||
jz .L032pw_end
|
||||
|
||||
movl 12(%esi),%ecx
|
||||
subl %eax,%ecx
|
||||
movl %ecx,12(%ebx)
|
||||
jnc .L049pw_tail_nc3
|
||||
decl %ebp
|
||||
jz .L032pw_end
|
||||
|
||||
movl 16(%esi),%ecx
|
||||
subl %eax,%ecx
|
||||
movl %ecx,16(%ebx)
|
||||
jnc .L050pw_tail_nc4
|
||||
decl %ebp
|
||||
jz .L032pw_end
|
||||
|
||||
movl 20(%esi),%ecx
|
||||
subl %eax,%ecx
|
||||
movl %ecx,20(%ebx)
|
||||
jnc .L051pw_tail_nc5
|
||||
decl %ebp
|
||||
jz .L032pw_end
|
||||
|
||||
movl 24(%esi),%ecx
|
||||
subl %eax,%ecx
|
||||
movl %ecx,24(%ebx)
|
||||
jnc .L052pw_tail_nc6
|
||||
movl $1,%eax
|
||||
jmp .L032pw_end
|
||||
.L053pw_nc_loop:
|
||||
movl (%esi),%ecx
|
||||
movl %ecx,(%ebx)
|
||||
.L038pw_nc0:
|
||||
movl 4(%esi),%ecx
|
||||
movl %ecx,4(%ebx)
|
||||
.L039pw_nc1:
|
||||
movl 8(%esi),%ecx
|
||||
movl %ecx,8(%ebx)
|
||||
.L040pw_nc2:
|
||||
movl 12(%esi),%ecx
|
||||
movl %ecx,12(%ebx)
|
||||
.L041pw_nc3:
|
||||
movl 16(%esi),%ecx
|
||||
movl %ecx,16(%ebx)
|
||||
.L042pw_nc4:
|
||||
movl 20(%esi),%ecx
|
||||
movl %ecx,20(%ebx)
|
||||
.L043pw_nc5:
|
||||
movl 24(%esi),%ecx
|
||||
movl %ecx,24(%ebx)
|
||||
.L044pw_nc6:
|
||||
movl 28(%esi),%ecx
|
||||
movl %ecx,28(%ebx)
|
||||
.L045pw_nc7:
|
||||
|
||||
addl $32,%esi
|
||||
addl $32,%ebx
|
||||
subl $8,%ebp
|
||||
jnz .L053pw_nc_loop
|
||||
movl 36(%esp),%ebp
|
||||
andl $7,%ebp
|
||||
jz .L054pw_nc_end
|
||||
movl (%esi),%ecx
|
||||
movl %ecx,(%ebx)
|
||||
.L046pw_tail_nc0:
|
||||
decl %ebp
|
||||
jz .L054pw_nc_end
|
||||
movl 4(%esi),%ecx
|
||||
movl %ecx,4(%ebx)
|
||||
.L047pw_tail_nc1:
|
||||
decl %ebp
|
||||
jz .L054pw_nc_end
|
||||
movl 8(%esi),%ecx
|
||||
movl %ecx,8(%ebx)
|
||||
.L048pw_tail_nc2:
|
||||
decl %ebp
|
||||
jz .L054pw_nc_end
|
||||
movl 12(%esi),%ecx
|
||||
movl %ecx,12(%ebx)
|
||||
.L049pw_tail_nc3:
|
||||
decl %ebp
|
||||
jz .L054pw_nc_end
|
||||
movl 16(%esi),%ecx
|
||||
movl %ecx,16(%ebx)
|
||||
.L050pw_tail_nc4:
|
||||
decl %ebp
|
||||
jz .L054pw_nc_end
|
||||
movl 20(%esi),%ecx
|
||||
movl %ecx,20(%ebx)
|
||||
.L051pw_tail_nc5:
|
||||
decl %ebp
|
||||
jz .L054pw_nc_end
|
||||
movl 24(%esi),%ecx
|
||||
movl %ecx,24(%ebx)
|
||||
.L052pw_tail_nc6:
|
||||
.L054pw_nc_end:
|
||||
movl $0,%eax
|
||||
.L032pw_end:
|
||||
popl %edi
|
||||
popl %esi
|
||||
popl %ebx
|
||||
popl %ebp
|
||||
ret
|
||||
.size bn_sub_part_words,.-.L_bn_sub_part_words_begin
|
||||
#endif
|
||||
.section .note.GNU-stack,"",@progbits
|
||||
#endif // defined(__i386__) && defined(__linux__)
|
||||
|
||||
@@ -732,7 +732,7 @@ void bn_mod_exp_mont_small(BN_ULONG *r, const BN_ULONG *a, size_t num,
|
||||
num_p--;
|
||||
}
|
||||
if (num_p == 0) {
|
||||
bn_from_montgomery_small(r, mont->RR.d, num, mont);
|
||||
bn_from_montgomery_small(r, num, mont->RR.d, num, mont);
|
||||
return;
|
||||
}
|
||||
unsigned bits = BN_num_bits_word(p[num_p - 1]) + (num_p - 1) * BN_BITS2;
|
||||
@@ -809,8 +809,8 @@ void bn_mod_exp_mont_small(BN_ULONG *r, const BN_ULONG *a, size_t num,
|
||||
OPENSSL_cleanse(val, sizeof(val));
|
||||
}
|
||||
|
||||
void bn_mod_inverse_prime_mont_small(BN_ULONG *r, const BN_ULONG *a, size_t num,
|
||||
const BN_MONT_CTX *mont) {
|
||||
void bn_mod_inverse0_prime_mont_small(BN_ULONG *r, const BN_ULONG *a,
|
||||
size_t num, const BN_MONT_CTX *mont) {
|
||||
if (num != (size_t)mont->N.width || num > BN_SMALL_MAX_WORDS) {
|
||||
abort();
|
||||
}
|
||||
|
||||
@@ -647,10 +647,13 @@ void bn_to_montgomery_small(BN_ULONG *r, const BN_ULONG *a, size_t num,
|
||||
const BN_MONT_CTX *mont);
|
||||
|
||||
// bn_from_montgomery_small sets |r| to |a| translated out of the Montgomery
|
||||
// domain. |r| and |a| are |num| words long, which must be |mont->N.width|. |a|
|
||||
// must be fully-reduced and may alias |r|.
|
||||
void bn_from_montgomery_small(BN_ULONG *r, const BN_ULONG *a, size_t num,
|
||||
const BN_MONT_CTX *mont);
|
||||
// domain. |r| and |a| are |num_r| and |num_a| words long, respectively. |num_r|
|
||||
// must be |mont->N.width|. |a| must be at most |mont->N|^2 and may alias |r|.
|
||||
//
|
||||
// Unlike most of these functions, only |num_r| is bounded by
|
||||
// |BN_SMALL_MAX_WORDS|. |num_a| may exceed it, but must be at most 2 * |num_r|.
|
||||
void bn_from_montgomery_small(BN_ULONG *r, size_t num_r, const BN_ULONG *a,
|
||||
size_t num_a, const BN_MONT_CTX *mont);
|
||||
|
||||
// bn_mod_mul_montgomery_small sets |r| to |a| * |b| mod |mont->N|. Both inputs
|
||||
// and outputs are in the Montgomery domain. Each array is |num| words long,
|
||||
@@ -675,13 +678,13 @@ void bn_mod_exp_mont_small(BN_ULONG *r, const BN_ULONG *a, size_t num,
|
||||
const BN_ULONG *p, size_t num_p,
|
||||
const BN_MONT_CTX *mont);
|
||||
|
||||
// bn_mod_inverse_prime_mont_small sets |r| to |a|^-1 mod |mont->N|. |mont->N|
|
||||
// must be a prime. |r| and |a| are |num| words long, which must be
|
||||
// |mont->N.width| and at most |BN_SMALL_MAX_WORDS|. |a| must be fully-reduced
|
||||
// and may alias |r|. This function runs in time independent of |a|, but
|
||||
// |mont->N| is a public value.
|
||||
void bn_mod_inverse_prime_mont_small(BN_ULONG *r, const BN_ULONG *a, size_t num,
|
||||
const BN_MONT_CTX *mont);
|
||||
// bn_mod_inverse0_prime_mont_small sets |r| to |a|^-1 mod |mont->N|. If |a| is
|
||||
// zero, |r| is set to zero. |mont->N| must be a prime. |r| and |a| are |num|
|
||||
// words long, which must be |mont->N.width| and at most |BN_SMALL_MAX_WORDS|.
|
||||
// |a| must be fully-reduced and may alias |r|. This function runs in time
|
||||
// independent of |a|, but |mont->N| is a public value.
|
||||
void bn_mod_inverse0_prime_mont_small(BN_ULONG *r, const BN_ULONG *a,
|
||||
size_t num, const BN_MONT_CTX *mont);
|
||||
|
||||
|
||||
#if defined(__cplusplus)
|
||||
|
||||
@@ -455,18 +455,18 @@ void bn_to_montgomery_small(BN_ULONG *r, const BN_ULONG *a, size_t num,
|
||||
bn_mod_mul_montgomery_small(r, a, mont->RR.d, num, mont);
|
||||
}
|
||||
|
||||
void bn_from_montgomery_small(BN_ULONG *r, const BN_ULONG *a, size_t num,
|
||||
const BN_MONT_CTX *mont) {
|
||||
if (num != (size_t)mont->N.width || num > BN_SMALL_MAX_WORDS) {
|
||||
void bn_from_montgomery_small(BN_ULONG *r, size_t num_r, const BN_ULONG *a,
|
||||
size_t num_a, const BN_MONT_CTX *mont) {
|
||||
if (num_r != (size_t)mont->N.width || num_r > BN_SMALL_MAX_WORDS ||
|
||||
num_a > 2 * num_r) {
|
||||
abort();
|
||||
}
|
||||
BN_ULONG tmp[BN_SMALL_MAX_WORDS * 2];
|
||||
OPENSSL_memcpy(tmp, a, num * sizeof(BN_ULONG));
|
||||
OPENSSL_memset(tmp + num, 0, num * sizeof(BN_ULONG));
|
||||
if (!bn_from_montgomery_in_place(r, num, tmp, 2 * num, mont)) {
|
||||
BN_ULONG tmp[BN_SMALL_MAX_WORDS * 2] = {0};
|
||||
OPENSSL_memcpy(tmp, a, num_a * sizeof(BN_ULONG));
|
||||
if (!bn_from_montgomery_in_place(r, num_r, tmp, 2 * num_r, mont)) {
|
||||
abort();
|
||||
}
|
||||
OPENSSL_cleanse(tmp, 2 * num * sizeof(BN_ULONG));
|
||||
OPENSSL_cleanse(tmp, 2 * num_r * sizeof(BN_ULONG));
|
||||
}
|
||||
|
||||
void bn_mod_mul_montgomery_small(BN_ULONG *r, const BN_ULONG *a,
|
||||
|
||||
@@ -119,26 +119,20 @@ static void bn_mul_normal(BN_ULONG *r, const BN_ULONG *a, size_t na,
|
||||
}
|
||||
}
|
||||
|
||||
#if !defined(OPENSSL_X86) || defined(OPENSSL_NO_ASM)
|
||||
// Here follows specialised variants of bn_add_words() and bn_sub_words(). They
|
||||
// have the property performing operations on arrays of different sizes. The
|
||||
// sizes of those arrays is expressed through cl, which is the common length (
|
||||
// basicall, min(len(a),len(b)) ), and dl, which is the delta between the two
|
||||
// lengths, calculated as len(a)-len(b). All lengths are the number of
|
||||
// BN_ULONGs... For the operations that require a result array as parameter,
|
||||
// it must have the length cl+abs(dl). These functions should probably end up
|
||||
// in bn_asm.c as soon as there are assembler counterparts for the systems that
|
||||
// use assembler files.
|
||||
|
||||
// bn_sub_part_words sets |r| to |a| - |b|. It returns the borrow bit, which is
|
||||
// one if the operation underflowed and zero otherwise. |cl| is the common
|
||||
// length, that is, the shorter of len(a) or len(b). |dl| is the delta length,
|
||||
// that is, len(a) - len(b). |r|'s length matches the larger of |a| and |b|, or
|
||||
// cl + abs(dl).
|
||||
//
|
||||
// TODO(davidben): Make this take |size_t|. The |cl| + |dl| calling convention
|
||||
// is confusing.
|
||||
static BN_ULONG bn_sub_part_words(BN_ULONG *r, const BN_ULONG *a,
|
||||
const BN_ULONG *b, int cl, int dl) {
|
||||
BN_ULONG c, t;
|
||||
|
||||
assert(cl >= 0);
|
||||
c = bn_sub_words(r, a, b, cl);
|
||||
|
||||
BN_ULONG borrow = bn_sub_words(r, a, b, cl);
|
||||
if (dl == 0) {
|
||||
return c;
|
||||
return borrow;
|
||||
}
|
||||
|
||||
r += cl;
|
||||
@@ -146,147 +140,26 @@ static BN_ULONG bn_sub_part_words(BN_ULONG *r, const BN_ULONG *a,
|
||||
b += cl;
|
||||
|
||||
if (dl < 0) {
|
||||
for (;;) {
|
||||
t = b[0];
|
||||
r[0] = 0 - t - c;
|
||||
if (t != 0) {
|
||||
c = 1;
|
||||
}
|
||||
if (++dl >= 0) {
|
||||
break;
|
||||
}
|
||||
|
||||
t = b[1];
|
||||
r[1] = 0 - t - c;
|
||||
if (t != 0) {
|
||||
c = 1;
|
||||
}
|
||||
if (++dl >= 0) {
|
||||
break;
|
||||
}
|
||||
|
||||
t = b[2];
|
||||
r[2] = 0 - t - c;
|
||||
if (t != 0) {
|
||||
c = 1;
|
||||
}
|
||||
if (++dl >= 0) {
|
||||
break;
|
||||
}
|
||||
|
||||
t = b[3];
|
||||
r[3] = 0 - t - c;
|
||||
if (t != 0) {
|
||||
c = 1;
|
||||
}
|
||||
if (++dl >= 0) {
|
||||
break;
|
||||
}
|
||||
|
||||
b += 4;
|
||||
r += 4;
|
||||
// |a| is shorter than |b|. Complete the subtraction as if the excess words
|
||||
// in |a| were zeros.
|
||||
dl = -dl;
|
||||
for (int i = 0; i < dl; i++) {
|
||||
r[i] = 0u - b[i] - borrow;
|
||||
borrow |= r[i] != 0;
|
||||
}
|
||||
} else {
|
||||
int save_dl = dl;
|
||||
while (c) {
|
||||
t = a[0];
|
||||
r[0] = t - c;
|
||||
if (t != 0) {
|
||||
c = 0;
|
||||
}
|
||||
if (--dl <= 0) {
|
||||
break;
|
||||
}
|
||||
|
||||
t = a[1];
|
||||
r[1] = t - c;
|
||||
if (t != 0) {
|
||||
c = 0;
|
||||
}
|
||||
if (--dl <= 0) {
|
||||
break;
|
||||
}
|
||||
|
||||
t = a[2];
|
||||
r[2] = t - c;
|
||||
if (t != 0) {
|
||||
c = 0;
|
||||
}
|
||||
if (--dl <= 0) {
|
||||
break;
|
||||
}
|
||||
|
||||
t = a[3];
|
||||
r[3] = t - c;
|
||||
if (t != 0) {
|
||||
c = 0;
|
||||
}
|
||||
if (--dl <= 0) {
|
||||
break;
|
||||
}
|
||||
|
||||
save_dl = dl;
|
||||
a += 4;
|
||||
r += 4;
|
||||
}
|
||||
if (dl > 0) {
|
||||
if (save_dl > dl) {
|
||||
switch (save_dl - dl) {
|
||||
case 1:
|
||||
r[1] = a[1];
|
||||
if (--dl <= 0) {
|
||||
break;
|
||||
}
|
||||
OPENSSL_FALLTHROUGH;
|
||||
case 2:
|
||||
r[2] = a[2];
|
||||
if (--dl <= 0) {
|
||||
break;
|
||||
}
|
||||
OPENSSL_FALLTHROUGH;
|
||||
case 3:
|
||||
r[3] = a[3];
|
||||
if (--dl <= 0) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
a += 4;
|
||||
r += 4;
|
||||
}
|
||||
}
|
||||
|
||||
if (dl > 0) {
|
||||
for (;;) {
|
||||
r[0] = a[0];
|
||||
if (--dl <= 0) {
|
||||
break;
|
||||
}
|
||||
r[1] = a[1];
|
||||
if (--dl <= 0) {
|
||||
break;
|
||||
}
|
||||
r[2] = a[2];
|
||||
if (--dl <= 0) {
|
||||
break;
|
||||
}
|
||||
r[3] = a[3];
|
||||
if (--dl <= 0) {
|
||||
break;
|
||||
}
|
||||
|
||||
a += 4;
|
||||
r += 4;
|
||||
}
|
||||
// |b| is shorter than |a|. Complete the subtraction as if the excess words
|
||||
// in |b| were zeros.
|
||||
for (int i = 0; i < dl; i++) {
|
||||
// |r| and |a| may alias, so use a temporary.
|
||||
BN_ULONG tmp = a[i];
|
||||
r[i] = a[i] - borrow;
|
||||
borrow = tmp < r[i];
|
||||
}
|
||||
}
|
||||
|
||||
return c;
|
||||
return borrow;
|
||||
}
|
||||
#else
|
||||
// On other platforms the function is defined in asm.
|
||||
BN_ULONG bn_sub_part_words(BN_ULONG *r, const BN_ULONG *a, const BN_ULONG *b,
|
||||
int cl, int dl);
|
||||
#endif
|
||||
|
||||
// bn_abs_sub_part_words computes |r| = |a| - |b|, storing the absolute value
|
||||
// and returning a mask of all ones if the result was negative and all zeros if
|
||||
@@ -294,8 +167,7 @@ BN_ULONG bn_sub_part_words(BN_ULONG *r, const BN_ULONG *a, const BN_ULONG *b,
|
||||
// convention.
|
||||
//
|
||||
// TODO(davidben): Make this take |size_t|. The |cl| + |dl| calling convention
|
||||
// is confusing. The trouble is 32-bit x86 implements |bn_sub_part_words| in
|
||||
// assembly, but we can probably just delete it?
|
||||
// is confusing.
|
||||
static BN_ULONG bn_abs_sub_part_words(BN_ULONG *r, const BN_ULONG *a,
|
||||
const BN_ULONG *b, int cl, int dl,
|
||||
BN_ULONG *tmp) {
|
||||
@@ -583,7 +455,7 @@ static int bn_mul_impl(BIGNUM *r, const BIGNUM *a, const BIGNUM *b,
|
||||
static const int kMulNormalSize = 16;
|
||||
if (al >= kMulNormalSize && bl >= kMulNormalSize) {
|
||||
if (-1 <= i && i <= 1) {
|
||||
// Find the larger power of two less than or equal to the larger length.
|
||||
// Find the largest power of two less than or equal to the larger length.
|
||||
int j;
|
||||
if (i >= 0) {
|
||||
j = BN_num_bits_word((BN_ULONG)al);
|
||||
@@ -599,6 +471,10 @@ static int bn_mul_impl(BIGNUM *r, const BIGNUM *a, const BIGNUM *b,
|
||||
if (al > j || bl > j) {
|
||||
// We know |al| and |bl| are at most one from each other, so if al > j,
|
||||
// bl >= j, and vice versa. Thus we can use |bn_mul_part_recursive|.
|
||||
//
|
||||
// TODO(davidben): This codepath is almost unused in standard
|
||||
// algorithms. Is this optimization necessary? See notes in
|
||||
// https://boringssl-review.googlesource.com/q/I0bd604e2cd6a75c266f64476c23a730ca1721ea6
|
||||
assert(al >= j && bl >= j);
|
||||
if (!bn_wexpand(t, j * 8) ||
|
||||
!bn_wexpand(rr, j * 4)) {
|
||||
|
||||
@@ -243,6 +243,22 @@ DEFINE_METHOD_FUNCTION(EVP_MD, EVP_sha512) {
|
||||
}
|
||||
|
||||
|
||||
static void sha512_256_init(EVP_MD_CTX *ctx) {
|
||||
CHECK(SHA512_256_Init(ctx->md_data));
|
||||
}
|
||||
|
||||
DEFINE_METHOD_FUNCTION(EVP_MD, EVP_sha512_256) {
|
||||
out->type = NID_sha512_256;
|
||||
out->md_size = SHA512_256_DIGEST_LENGTH;
|
||||
out->flags = 0;
|
||||
out->init = sha512_256_init;
|
||||
out->update = sha512_update;
|
||||
out->final = sha512_final;
|
||||
out->block_size = 128;
|
||||
out->ctx_size = sizeof(SHA512_CTX);
|
||||
}
|
||||
|
||||
|
||||
typedef struct {
|
||||
MD5_CTX md5;
|
||||
SHA_CTX sha1;
|
||||
|
||||
@@ -84,7 +84,7 @@
|
||||
static void ec_point_free(EC_POINT *point, int free_group);
|
||||
|
||||
static const uint8_t kP224Params[6 * 28] = {
|
||||
// p
|
||||
// p = 2^224 - 2^96 + 1
|
||||
0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF,
|
||||
0xFF, 0xFF, 0xFF, 0xFF, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x01,
|
||||
@@ -111,7 +111,7 @@ static const uint8_t kP224Params[6 * 28] = {
|
||||
};
|
||||
|
||||
static const uint8_t kP256Params[6 * 32] = {
|
||||
// p
|
||||
// p = 2^256 - 2^224 + 2^192 + 2^96 - 1
|
||||
0xFF, 0xFF, 0xFF, 0xFF, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xFF, 0xFF, 0xFF, 0xFF,
|
||||
0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF,
|
||||
@@ -138,7 +138,7 @@ static const uint8_t kP256Params[6 * 32] = {
|
||||
};
|
||||
|
||||
static const uint8_t kP384Params[6 * 48] = {
|
||||
// p
|
||||
// p = 2^384 - 2^128 - 2^96 + 2^32 - 1
|
||||
0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF,
|
||||
0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF,
|
||||
0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFE, 0xFF, 0xFF, 0xFF, 0xFF,
|
||||
@@ -171,7 +171,7 @@ static const uint8_t kP384Params[6 * 48] = {
|
||||
};
|
||||
|
||||
static const uint8_t kP521Params[6 * 66] = {
|
||||
// p
|
||||
// p = 2^521 - 1
|
||||
0x01, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF,
|
||||
0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF,
|
||||
0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF,
|
||||
@@ -301,17 +301,49 @@ EC_GROUP *ec_group_new(const EC_METHOD *meth) {
|
||||
return ret;
|
||||
}
|
||||
|
||||
static void ec_group_set0_generator(EC_GROUP *group, EC_POINT *generator) {
|
||||
static int ec_group_set_generator(EC_GROUP *group, const EC_AFFINE *generator,
|
||||
const BIGNUM *order) {
|
||||
assert(group->generator == NULL);
|
||||
assert(group == generator->group);
|
||||
|
||||
if (!BN_copy(&group->order, order)) {
|
||||
return 0;
|
||||
}
|
||||
// Store the order in minimal form, so it can be used with |BN_ULONG| arrays.
|
||||
bn_set_minimal_width(&group->order);
|
||||
|
||||
BN_MONT_CTX_free(group->order_mont);
|
||||
group->order_mont = BN_MONT_CTX_new_for_modulus(&group->order, NULL);
|
||||
if (group->order_mont == NULL) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
group->field_greater_than_order = BN_cmp(&group->field, order) > 0;
|
||||
if (group->field_greater_than_order) {
|
||||
BIGNUM tmp;
|
||||
BN_init(&tmp);
|
||||
int ok =
|
||||
BN_sub(&tmp, &group->field, order) &&
|
||||
bn_copy_words(group->field_minus_order.words, group->field.width, &tmp);
|
||||
BN_free(&tmp);
|
||||
if (!ok) {
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
group->generator = EC_POINT_new(group);
|
||||
if (group->generator == NULL) {
|
||||
return 0;
|
||||
}
|
||||
ec_affine_to_jacobian(group, &group->generator->raw, generator);
|
||||
assert(ec_felem_equal(group, &group->one, &group->generator->raw.Z));
|
||||
|
||||
// Avoid a reference cycle. |group->generator| does not maintain an owning
|
||||
// pointer to |group|.
|
||||
group->generator = generator;
|
||||
int is_zero = CRYPTO_refcount_dec_and_test_zero(&group->references);
|
||||
|
||||
assert(!is_zero);
|
||||
(void)is_zero;
|
||||
return 1;
|
||||
}
|
||||
|
||||
EC_GROUP *EC_GROUP_new_curve_GFp(const BIGNUM *p, const BIGNUM *a,
|
||||
@@ -321,20 +353,37 @@ EC_GROUP *EC_GROUP_new_curve_GFp(const BIGNUM *p, const BIGNUM *a,
|
||||
return NULL;
|
||||
}
|
||||
|
||||
EC_GROUP *ret = ec_group_new(EC_GFp_mont_method());
|
||||
if (ret == NULL) {
|
||||
return NULL;
|
||||
BN_CTX *new_ctx = NULL;
|
||||
if (ctx == NULL) {
|
||||
ctx = new_ctx = BN_CTX_new();
|
||||
if (ctx == NULL) {
|
||||
return NULL;
|
||||
}
|
||||
}
|
||||
|
||||
if (ret->meth->group_set_curve == NULL) {
|
||||
OPENSSL_PUT_ERROR(EC, ERR_R_SHOULD_NOT_HAVE_BEEN_CALLED);
|
||||
EC_GROUP_free(ret);
|
||||
return NULL;
|
||||
// Historically, |a| and |b| were not required to be fully reduced.
|
||||
// TODO(davidben): Can this be removed?
|
||||
EC_GROUP *ret = NULL;
|
||||
BN_CTX_start(ctx);
|
||||
BIGNUM *a_reduced = BN_CTX_get(ctx);
|
||||
BIGNUM *b_reduced = BN_CTX_get(ctx);
|
||||
if (a_reduced == NULL || b_reduced == NULL ||
|
||||
!BN_nnmod(a_reduced, a, p, ctx) ||
|
||||
!BN_nnmod(b_reduced, b, p, ctx)) {
|
||||
goto err;
|
||||
}
|
||||
if (!ret->meth->group_set_curve(ret, p, a, b, ctx)) {
|
||||
|
||||
ret = ec_group_new(EC_GFp_mont_method());
|
||||
if (ret == NULL ||
|
||||
!ret->meth->group_set_curve(ret, p, a_reduced, b_reduced, ctx)) {
|
||||
EC_GROUP_free(ret);
|
||||
return NULL;
|
||||
ret = NULL;
|
||||
goto err;
|
||||
}
|
||||
|
||||
err:
|
||||
BN_CTX_end(ctx);
|
||||
BN_CTX_free(new_ctx);
|
||||
return ret;
|
||||
}
|
||||
|
||||
@@ -367,7 +416,6 @@ int EC_GROUP_set_generator(EC_GROUP *group, const EC_POINT *generator,
|
||||
// tiny prime (less than 17). See the proof in |field_element_to_scalar| in
|
||||
// the ECDSA implementation.
|
||||
int ret = 0;
|
||||
EC_POINT *copy = NULL;
|
||||
BIGNUM *tmp = BN_new();
|
||||
if (tmp == NULL ||
|
||||
!BN_lshift1(tmp, order)) {
|
||||
@@ -378,44 +426,22 @@ int EC_GROUP_set_generator(EC_GROUP *group, const EC_POINT *generator,
|
||||
goto err;
|
||||
}
|
||||
|
||||
copy = EC_POINT_new(group);
|
||||
if (copy == NULL ||
|
||||
!EC_POINT_copy(copy, generator) ||
|
||||
!BN_copy(&group->order, order)) {
|
||||
goto err;
|
||||
}
|
||||
// Store the order in minimal form, so it can be used with |BN_ULONG| arrays.
|
||||
bn_set_minimal_width(&group->order);
|
||||
|
||||
BN_MONT_CTX_free(group->order_mont);
|
||||
group->order_mont = BN_MONT_CTX_new_for_modulus(&group->order, NULL);
|
||||
if (group->order_mont == NULL) {
|
||||
EC_AFFINE affine;
|
||||
if (!ec_jacobian_to_affine(group, &affine, &generator->raw) ||
|
||||
!ec_group_set_generator(group, &affine, order)) {
|
||||
goto err;
|
||||
}
|
||||
|
||||
group->field_greater_than_order = BN_cmp(&group->field, &group->order) > 0;
|
||||
if (group->field_greater_than_order) {
|
||||
if (!BN_sub(tmp, &group->field, &group->order) ||
|
||||
!bn_copy_words(group->field_minus_order.words, group->field.width,
|
||||
tmp)) {
|
||||
goto err;
|
||||
}
|
||||
}
|
||||
|
||||
ec_group_set0_generator(group, copy);
|
||||
copy = NULL;
|
||||
ret = 1;
|
||||
|
||||
err:
|
||||
EC_POINT_free(copy);
|
||||
BN_free(tmp);
|
||||
return ret;
|
||||
}
|
||||
|
||||
static EC_GROUP *ec_group_new_from_data(const struct built_in_curve *curve) {
|
||||
EC_GROUP *group = NULL;
|
||||
EC_POINT *P = NULL;
|
||||
BIGNUM *p = NULL, *a = NULL, *b = NULL, *x = NULL, *y = NULL;
|
||||
BIGNUM *p = NULL, *a = NULL, *b = NULL, *order = NULL;
|
||||
int ok = 0;
|
||||
|
||||
BN_CTX *ctx = BN_CTX_new();
|
||||
@@ -429,7 +455,8 @@ static EC_GROUP *ec_group_new_from_data(const struct built_in_curve *curve) {
|
||||
|
||||
if (!(p = BN_bin2bn(params + 0 * param_len, param_len, NULL)) ||
|
||||
!(a = BN_bin2bn(params + 1 * param_len, param_len, NULL)) ||
|
||||
!(b = BN_bin2bn(params + 2 * param_len, param_len, NULL))) {
|
||||
!(b = BN_bin2bn(params + 2 * param_len, param_len, NULL)) ||
|
||||
!(order = BN_bin2bn(params + 5 * param_len, param_len, NULL))) {
|
||||
OPENSSL_PUT_ERROR(EC, ERR_R_BN_LIB);
|
||||
goto err;
|
||||
}
|
||||
@@ -441,42 +468,18 @@ static EC_GROUP *ec_group_new_from_data(const struct built_in_curve *curve) {
|
||||
goto err;
|
||||
}
|
||||
|
||||
if ((P = EC_POINT_new(group)) == NULL) {
|
||||
OPENSSL_PUT_ERROR(EC, ERR_R_EC_LIB);
|
||||
EC_AFFINE G;
|
||||
EC_FELEM x, y;
|
||||
if (!ec_felem_from_bytes(group, &x, params + 3 * param_len, param_len) ||
|
||||
!ec_felem_from_bytes(group, &y, params + 4 * param_len, param_len) ||
|
||||
!ec_point_set_affine_coordinates(group, &G, &x, &y)) {
|
||||
goto err;
|
||||
}
|
||||
|
||||
if (!(x = BN_bin2bn(params + 3 * param_len, param_len, NULL)) ||
|
||||
!(y = BN_bin2bn(params + 4 * param_len, param_len, NULL))) {
|
||||
OPENSSL_PUT_ERROR(EC, ERR_R_BN_LIB);
|
||||
if (!ec_group_set_generator(group, &G, order)) {
|
||||
goto err;
|
||||
}
|
||||
|
||||
if (!EC_POINT_set_affine_coordinates_GFp(group, P, x, y, ctx)) {
|
||||
OPENSSL_PUT_ERROR(EC, ERR_R_EC_LIB);
|
||||
goto err;
|
||||
}
|
||||
if (!BN_bin2bn(params + 5 * param_len, param_len, &group->order)) {
|
||||
OPENSSL_PUT_ERROR(EC, ERR_R_BN_LIB);
|
||||
goto err;
|
||||
}
|
||||
|
||||
group->field_greater_than_order = BN_cmp(&group->field, &group->order) > 0;
|
||||
if (group->field_greater_than_order) {
|
||||
if (!BN_sub(p, &group->field, &group->order) ||
|
||||
!bn_copy_words(group->field_minus_order.words, group->field.width, p)) {
|
||||
goto err;
|
||||
}
|
||||
}
|
||||
|
||||
group->order_mont = BN_MONT_CTX_new_for_modulus(&group->order, ctx);
|
||||
if (group->order_mont == NULL) {
|
||||
OPENSSL_PUT_ERROR(EC, ERR_R_BN_LIB);
|
||||
goto err;
|
||||
}
|
||||
|
||||
ec_group_set0_generator(group, P);
|
||||
P = NULL;
|
||||
ok = 1;
|
||||
|
||||
err:
|
||||
@@ -484,13 +487,11 @@ err:
|
||||
EC_GROUP_free(group);
|
||||
group = NULL;
|
||||
}
|
||||
EC_POINT_free(P);
|
||||
BN_CTX_free(ctx);
|
||||
BN_free(p);
|
||||
BN_free(a);
|
||||
BN_free(b);
|
||||
BN_free(x);
|
||||
BN_free(y);
|
||||
BN_free(order);
|
||||
return group;
|
||||
}
|
||||
|
||||
@@ -606,7 +607,7 @@ int EC_GROUP_cmp(const EC_GROUP *a, const EC_GROUP *b, BN_CTX *ignored) {
|
||||
BN_cmp(&a->field, &b->field) != 0 ||
|
||||
!ec_felem_equal(a, &a->a, &b->a) ||
|
||||
!ec_felem_equal(a, &a->b, &b->b) ||
|
||||
ec_GFp_simple_cmp(a, &a->generator->raw, &b->generator->raw) != 0;
|
||||
!ec_GFp_simple_points_equal(a, &a->generator->raw, &b->generator->raw);
|
||||
}
|
||||
|
||||
const EC_POINT *EC_GROUP_get0_generator(const EC_GROUP *group) {
|
||||
@@ -769,7 +770,9 @@ int EC_POINT_cmp(const EC_GROUP *group, const EC_POINT *a, const EC_POINT *b,
|
||||
OPENSSL_PUT_ERROR(EC, EC_R_INCOMPATIBLE_OBJECTS);
|
||||
return -1;
|
||||
}
|
||||
return ec_GFp_simple_cmp(group, &a->raw, &b->raw);
|
||||
|
||||
// Note |EC_POINT_cmp| returns zero for equality and non-zero for inequality.
|
||||
return ec_GFp_simple_points_equal(group, &a->raw, &b->raw) ? 0 : 1;
|
||||
}
|
||||
|
||||
int EC_POINT_get_affine_coordinates_GFp(const EC_GROUP *group,
|
||||
@@ -787,13 +790,67 @@ int EC_POINT_get_affine_coordinates_GFp(const EC_GROUP *group,
|
||||
if (!group->meth->point_get_affine_coordinates(group, &point->raw,
|
||||
x == NULL ? NULL : &x_felem,
|
||||
y == NULL ? NULL : &y_felem) ||
|
||||
(x != NULL && !bn_set_words(x, x_felem.words, group->field.width)) ||
|
||||
(y != NULL && !bn_set_words(y, y_felem.words, group->field.width))) {
|
||||
(x != NULL && !ec_felem_to_bignum(group, x, &x_felem)) ||
|
||||
(y != NULL && !ec_felem_to_bignum(group, y, &y_felem))) {
|
||||
return 0;
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
|
||||
void ec_affine_to_jacobian(const EC_GROUP *group, EC_RAW_POINT *out,
|
||||
const EC_AFFINE *p) {
|
||||
out->X = p->X;
|
||||
out->Y = p->Y;
|
||||
out->Z = group->one;
|
||||
}
|
||||
|
||||
int ec_jacobian_to_affine(const EC_GROUP *group, EC_AFFINE *out,
|
||||
const EC_RAW_POINT *p) {
|
||||
return group->meth->point_get_affine_coordinates(group, p, &out->X, &out->Y);
|
||||
}
|
||||
|
||||
int ec_jacobian_to_affine_batch(const EC_GROUP *group, EC_AFFINE *out,
|
||||
const EC_RAW_POINT *in, size_t num) {
|
||||
if (group->meth->jacobian_to_affine_batch == NULL) {
|
||||
OPENSSL_PUT_ERROR(EC, ERR_R_SHOULD_NOT_HAVE_BEEN_CALLED);
|
||||
return 0;
|
||||
}
|
||||
return group->meth->jacobian_to_affine_batch(group, out, in, num);
|
||||
}
|
||||
|
||||
int ec_point_set_affine_coordinates(const EC_GROUP *group, EC_AFFINE *out,
|
||||
const EC_FELEM *x, const EC_FELEM *y) {
|
||||
void (*const felem_mul)(const EC_GROUP *, EC_FELEM *r, const EC_FELEM *a,
|
||||
const EC_FELEM *b) = group->meth->felem_mul;
|
||||
void (*const felem_sqr)(const EC_GROUP *, EC_FELEM *r, const EC_FELEM *a) =
|
||||
group->meth->felem_sqr;
|
||||
|
||||
// Check if the point is on the curve.
|
||||
EC_FELEM lhs, rhs;
|
||||
felem_sqr(group, &lhs, y); // lhs = y^2
|
||||
felem_sqr(group, &rhs, x); // rhs = x^2
|
||||
ec_felem_add(group, &rhs, &rhs, &group->a); // rhs = x^2 + a
|
||||
felem_mul(group, &rhs, &rhs, x); // rhs = x^3 + ax
|
||||
ec_felem_add(group, &rhs, &rhs, &group->b); // rhs = x^3 + ax + b
|
||||
if (!ec_felem_equal(group, &lhs, &rhs)) {
|
||||
OPENSSL_PUT_ERROR(EC, EC_R_POINT_IS_NOT_ON_CURVE);
|
||||
// In the event of an error, defend against the caller not checking the
|
||||
// return value by setting a known safe value. Note this may not be possible
|
||||
// if the caller is in the process of constructing an arbitrary group and
|
||||
// the generator is missing.
|
||||
if (group->generator != NULL) {
|
||||
assert(ec_felem_equal(group, &group->one, &group->generator->raw.Z));
|
||||
out->X = group->generator->raw.X;
|
||||
out->Y = group->generator->raw.Y;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
out->X = *x;
|
||||
out->Y = *y;
|
||||
return 1;
|
||||
}
|
||||
|
||||
int EC_POINT_set_affine_coordinates_GFp(const EC_GROUP *group, EC_POINT *point,
|
||||
const BIGNUM *x, const BIGNUM *y,
|
||||
BN_CTX *ctx) {
|
||||
@@ -801,24 +858,24 @@ int EC_POINT_set_affine_coordinates_GFp(const EC_GROUP *group, EC_POINT *point,
|
||||
OPENSSL_PUT_ERROR(EC, EC_R_INCOMPATIBLE_OBJECTS);
|
||||
return 0;
|
||||
}
|
||||
if (!ec_GFp_simple_point_set_affine_coordinates(group, &point->raw, x, y)) {
|
||||
|
||||
if (x == NULL || y == NULL) {
|
||||
OPENSSL_PUT_ERROR(EC, ERR_R_PASSED_NULL_PARAMETER);
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (!EC_POINT_is_on_curve(group, point, ctx)) {
|
||||
EC_FELEM x_felem, y_felem;
|
||||
EC_AFFINE affine;
|
||||
if (!ec_bignum_to_felem(group, &x_felem, x) ||
|
||||
!ec_bignum_to_felem(group, &y_felem, y) ||
|
||||
!ec_point_set_affine_coordinates(group, &affine, &x_felem, &y_felem)) {
|
||||
// In the event of an error, defend against the caller not checking the
|
||||
// return value by setting a known safe value: the base point.
|
||||
const EC_POINT *generator = EC_GROUP_get0_generator(group);
|
||||
// The generator can be missing if the caller is in the process of
|
||||
// constructing an arbitrary group. In this, we give up and hope they're
|
||||
// checking the return value.
|
||||
if (generator) {
|
||||
ec_GFp_simple_point_copy(&point->raw, &generator->raw);
|
||||
}
|
||||
OPENSSL_PUT_ERROR(EC, EC_R_POINT_IS_NOT_ON_CURVE);
|
||||
// return value by setting a known safe value.
|
||||
ec_set_to_safe_point(group, &point->raw);
|
||||
return 0;
|
||||
}
|
||||
|
||||
ec_affine_to_jacobian(group, &point->raw, &affine);
|
||||
return 1;
|
||||
}
|
||||
|
||||
@@ -949,10 +1006,27 @@ int ec_point_mul_scalar_public(const EC_GROUP *group, EC_RAW_POINT *r,
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (group->meth->mul_public == NULL) {
|
||||
return group->meth->mul_public_batch(group, r, g_scalar, p, p_scalar, 1);
|
||||
}
|
||||
|
||||
group->meth->mul_public(group, r, g_scalar, p, p_scalar);
|
||||
return 1;
|
||||
}
|
||||
|
||||
int ec_point_mul_scalar_public_batch(const EC_GROUP *group, EC_RAW_POINT *r,
|
||||
const EC_SCALAR *g_scalar,
|
||||
const EC_RAW_POINT *points,
|
||||
const EC_SCALAR *scalars, size_t num) {
|
||||
if (group->meth->mul_public_batch == NULL) {
|
||||
OPENSSL_PUT_ERROR(EC, ERR_R_SHOULD_NOT_HAVE_BEEN_CALLED);
|
||||
return 0;
|
||||
}
|
||||
|
||||
return group->meth->mul_public_batch(group, r, g_scalar, points, scalars,
|
||||
num);
|
||||
}
|
||||
|
||||
int ec_point_mul_scalar(const EC_GROUP *group, EC_RAW_POINT *r,
|
||||
const EC_RAW_POINT *p, const EC_SCALAR *scalar) {
|
||||
if (p == NULL || scalar == NULL) {
|
||||
@@ -961,6 +1035,14 @@ int ec_point_mul_scalar(const EC_GROUP *group, EC_RAW_POINT *r,
|
||||
}
|
||||
|
||||
group->meth->mul(group, r, p, scalar);
|
||||
|
||||
// Check the result is on the curve to defend against fault attacks or bugs.
|
||||
// This has negligible cost compared to the multiplication.
|
||||
if (!ec_GFp_simple_is_on_curve(group, r)) {
|
||||
OPENSSL_PUT_ERROR(EC, ERR_R_INTERNAL_ERROR);
|
||||
return 0;
|
||||
}
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
@@ -972,9 +1054,93 @@ int ec_point_mul_scalar_base(const EC_GROUP *group, EC_RAW_POINT *r,
|
||||
}
|
||||
|
||||
group->meth->mul_base(group, r, scalar);
|
||||
|
||||
// Check the result is on the curve to defend against fault attacks or bugs.
|
||||
// This has negligible cost compared to the multiplication.
|
||||
if (!ec_GFp_simple_is_on_curve(group, r)) {
|
||||
OPENSSL_PUT_ERROR(EC, ERR_R_INTERNAL_ERROR);
|
||||
return 0;
|
||||
}
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
int ec_point_mul_scalar_batch(const EC_GROUP *group, EC_RAW_POINT *r,
|
||||
const EC_RAW_POINT *p0, const EC_SCALAR *scalar0,
|
||||
const EC_RAW_POINT *p1, const EC_SCALAR *scalar1,
|
||||
const EC_RAW_POINT *p2,
|
||||
const EC_SCALAR *scalar2) {
|
||||
if (group->meth->mul_batch == NULL) {
|
||||
OPENSSL_PUT_ERROR(EC, ERR_R_SHOULD_NOT_HAVE_BEEN_CALLED);
|
||||
return 0;
|
||||
}
|
||||
|
||||
group->meth->mul_batch(group, r, p0, scalar0, p1, scalar1, p2, scalar2);
|
||||
|
||||
// Check the result is on the curve to defend against fault attacks or bugs.
|
||||
// This has negligible cost compared to the multiplication.
|
||||
if (!ec_GFp_simple_is_on_curve(group, r)) {
|
||||
OPENSSL_PUT_ERROR(EC, ERR_R_INTERNAL_ERROR);
|
||||
return 0;
|
||||
}
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
int ec_init_precomp(const EC_GROUP *group, EC_PRECOMP *out,
|
||||
const EC_RAW_POINT *p) {
|
||||
if (group->meth->init_precomp == NULL) {
|
||||
OPENSSL_PUT_ERROR(EC, ERR_R_SHOULD_NOT_HAVE_BEEN_CALLED);
|
||||
return 0;
|
||||
}
|
||||
|
||||
return group->meth->init_precomp(group, out, p);
|
||||
}
|
||||
|
||||
int ec_point_mul_scalar_precomp(const EC_GROUP *group, EC_RAW_POINT *r,
|
||||
const EC_PRECOMP *p0, const EC_SCALAR *scalar0,
|
||||
const EC_PRECOMP *p1, const EC_SCALAR *scalar1,
|
||||
const EC_PRECOMP *p2,
|
||||
const EC_SCALAR *scalar2) {
|
||||
if (group->meth->mul_precomp == NULL) {
|
||||
OPENSSL_PUT_ERROR(EC, ERR_R_SHOULD_NOT_HAVE_BEEN_CALLED);
|
||||
return 0;
|
||||
}
|
||||
|
||||
group->meth->mul_precomp(group, r, p0, scalar0, p1, scalar1, p2, scalar2);
|
||||
|
||||
// Check the result is on the curve to defend against fault attacks or bugs.
|
||||
// This has negligible cost compared to the multiplication.
|
||||
if (!ec_GFp_simple_is_on_curve(group, r)) {
|
||||
OPENSSL_PUT_ERROR(EC, ERR_R_INTERNAL_ERROR);
|
||||
return 0;
|
||||
}
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
void ec_point_select(const EC_GROUP *group, EC_RAW_POINT *out, BN_ULONG mask,
|
||||
const EC_RAW_POINT *a, const EC_RAW_POINT *b) {
|
||||
ec_felem_select(group, &out->X, mask, &a->X, &b->X);
|
||||
ec_felem_select(group, &out->Y, mask, &a->Y, &b->Y);
|
||||
ec_felem_select(group, &out->Z, mask, &a->Z, &b->Z);
|
||||
}
|
||||
|
||||
void ec_affine_select(const EC_GROUP *group, EC_AFFINE *out, BN_ULONG mask,
|
||||
const EC_AFFINE *a, const EC_AFFINE *b) {
|
||||
ec_felem_select(group, &out->X, mask, &a->X, &b->X);
|
||||
ec_felem_select(group, &out->Y, mask, &a->Y, &b->Y);
|
||||
}
|
||||
|
||||
void ec_precomp_select(const EC_GROUP *group, EC_PRECOMP *out, BN_ULONG mask,
|
||||
const EC_PRECOMP *a, const EC_PRECOMP *b) {
|
||||
OPENSSL_STATIC_ASSERT(sizeof(out->comb) == sizeof(*out),
|
||||
"out->comb does not span the entire structure");
|
||||
for (size_t i = 0; i < OPENSSL_ARRAY_SIZE(out->comb); i++) {
|
||||
ec_affine_select(group, &out->comb[i], mask, &a->comb[i], &b->comb[i]);
|
||||
}
|
||||
}
|
||||
|
||||
int ec_cmp_x_coordinate(const EC_GROUP *group, const EC_RAW_POINT *p,
|
||||
const EC_SCALAR *r) {
|
||||
return group->meth->cmp_x_coordinate(group, p, r);
|
||||
@@ -982,14 +1148,19 @@ int ec_cmp_x_coordinate(const EC_GROUP *group, const EC_RAW_POINT *p,
|
||||
|
||||
int ec_get_x_coordinate_as_scalar(const EC_GROUP *group, EC_SCALAR *out,
|
||||
const EC_RAW_POINT *p) {
|
||||
EC_FELEM x;
|
||||
// For simplicity, in case of width mismatches between |group->field| and
|
||||
// |group->order|, zero any untouched words in |x|.
|
||||
OPENSSL_memset(&x, 0, sizeof(x));
|
||||
if (!group->meth->point_get_affine_coordinates(group, p, &x, NULL)) {
|
||||
uint8_t bytes[EC_MAX_BYTES];
|
||||
size_t len;
|
||||
if (!ec_get_x_coordinate_as_bytes(group, bytes, &len, sizeof(bytes), p)) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
// For simplicity, in case of width mismatches between |group->field| and
|
||||
// |group->order|, zero any untouched words in |out|.
|
||||
OPENSSL_memset(out, 0, sizeof(EC_SCALAR));
|
||||
for (size_t i = 0; i < len; i++) {
|
||||
out->bytes[len - i - 1] = bytes[i];
|
||||
}
|
||||
|
||||
// We must have p < 2×order, assuming p is not tiny (p >= 17). Thus rather we
|
||||
// can reduce by performing at most one subtraction.
|
||||
//
|
||||
@@ -1008,17 +1179,17 @@ int ec_get_x_coordinate_as_scalar(const EC_GROUP *group, EC_SCALAR *out,
|
||||
|
||||
// The above does not guarantee |group->field| is not one word larger than
|
||||
// |group->order|, so read one extra carry word.
|
||||
BN_ULONG tmp[EC_MAX_WORDS];
|
||||
BN_ULONG carry =
|
||||
group->order.width < EC_MAX_WORDS ? x.words[group->order.width] : 0;
|
||||
bn_reduce_once(out->words, x.words, carry, group->order.d,
|
||||
group->order.width);
|
||||
group->order.width < EC_MAX_WORDS ? out->words[group->order.width] : 0;
|
||||
bn_reduce_once_in_place(out->words, carry, group->order.d, tmp,
|
||||
group->order.width);
|
||||
return 1;
|
||||
}
|
||||
|
||||
int ec_point_get_affine_coordinate_bytes(const EC_GROUP *group, uint8_t *out_x,
|
||||
uint8_t *out_y, size_t *out_len,
|
||||
size_t max_out,
|
||||
const EC_RAW_POINT *p) {
|
||||
int ec_get_x_coordinate_as_bytes(const EC_GROUP *group, uint8_t *out,
|
||||
size_t *out_len, size_t max_out,
|
||||
const EC_RAW_POINT *p) {
|
||||
size_t len = BN_num_bytes(&group->field);
|
||||
assert(len <= EC_MAX_BYTES);
|
||||
if (max_out < len) {
|
||||
@@ -1026,26 +1197,27 @@ int ec_point_get_affine_coordinate_bytes(const EC_GROUP *group, uint8_t *out_x,
|
||||
return 0;
|
||||
}
|
||||
|
||||
EC_FELEM x, y;
|
||||
if (!group->meth->point_get_affine_coordinates(
|
||||
group, p, out_x == NULL ? NULL : &x, out_y == NULL ? NULL : &y)) {
|
||||
EC_FELEM x;
|
||||
if (!group->meth->point_get_affine_coordinates(group, p, &x, NULL)) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (out_x != NULL) {
|
||||
for (size_t i = 0; i < len; i++) {
|
||||
out_x[i] = x.bytes[len - i - 1];
|
||||
}
|
||||
}
|
||||
if (out_y != NULL) {
|
||||
for (size_t i = 0; i < len; i++) {
|
||||
out_y[i] = y.bytes[len - i - 1];
|
||||
}
|
||||
}
|
||||
ec_felem_to_bytes(group, out, out_len, &x);
|
||||
*out_len = len;
|
||||
return 1;
|
||||
}
|
||||
|
||||
void ec_set_to_safe_point(const EC_GROUP *group, EC_RAW_POINT *out) {
|
||||
if (group->generator != NULL) {
|
||||
ec_GFp_simple_point_copy(out, &group->generator->raw);
|
||||
} else {
|
||||
// The generator can be missing if the caller is in the process of
|
||||
// constructing an arbitrary group. In this case, we give up and use the
|
||||
// point at infinity.
|
||||
ec_GFp_simple_point_set_to_infinity(group, out);
|
||||
}
|
||||
}
|
||||
|
||||
void EC_GROUP_set_asn1_flag(EC_GROUP *group, int flag) {}
|
||||
|
||||
const EC_METHOD *EC_GROUP_method_of(const EC_GROUP *group) {
|
||||
|
||||
@@ -292,10 +292,6 @@ void EC_KEY_set_conv_form(EC_KEY *key, point_conversion_form_t cform) {
|
||||
}
|
||||
|
||||
int EC_KEY_check_key(const EC_KEY *eckey) {
|
||||
int ok = 0;
|
||||
BN_CTX *ctx = NULL;
|
||||
EC_POINT *point = NULL;
|
||||
|
||||
if (!eckey || !eckey->group || !eckey->pub_key) {
|
||||
OPENSSL_PUT_ERROR(EC, ERR_R_PASSED_NULL_PARAMETER);
|
||||
return 0;
|
||||
@@ -303,41 +299,31 @@ int EC_KEY_check_key(const EC_KEY *eckey) {
|
||||
|
||||
if (EC_POINT_is_at_infinity(eckey->group, eckey->pub_key)) {
|
||||
OPENSSL_PUT_ERROR(EC, EC_R_POINT_AT_INFINITY);
|
||||
goto err;
|
||||
return 0;
|
||||
}
|
||||
|
||||
ctx = BN_CTX_new();
|
||||
|
||||
if (ctx == NULL) {
|
||||
goto err;
|
||||
}
|
||||
|
||||
// testing whether the pub_key is on the elliptic curve
|
||||
if (!EC_POINT_is_on_curve(eckey->group, eckey->pub_key, ctx)) {
|
||||
// Test whether the public key is on the elliptic curve.
|
||||
if (!EC_POINT_is_on_curve(eckey->group, eckey->pub_key, NULL)) {
|
||||
OPENSSL_PUT_ERROR(EC, EC_R_POINT_IS_NOT_ON_CURVE);
|
||||
goto err;
|
||||
return 0;
|
||||
}
|
||||
// in case the priv_key is present :
|
||||
// check if generator * priv_key == pub_key
|
||||
|
||||
// Check the public and private keys match.
|
||||
if (eckey->priv_key != NULL) {
|
||||
point = EC_POINT_new(eckey->group);
|
||||
if (point == NULL ||
|
||||
!ec_point_mul_scalar_base(eckey->group, &point->raw,
|
||||
EC_RAW_POINT point;
|
||||
if (!ec_point_mul_scalar_base(eckey->group, &point,
|
||||
&eckey->priv_key->scalar)) {
|
||||
OPENSSL_PUT_ERROR(EC, ERR_R_EC_LIB);
|
||||
goto err;
|
||||
return 0;
|
||||
}
|
||||
if (EC_POINT_cmp(eckey->group, point, eckey->pub_key, ctx) != 0) {
|
||||
if (!ec_GFp_simple_points_equal(eckey->group, &point,
|
||||
&eckey->pub_key->raw)) {
|
||||
OPENSSL_PUT_ERROR(EC, EC_R_INVALID_PRIVATE_KEY);
|
||||
goto err;
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
ok = 1;
|
||||
|
||||
err:
|
||||
BN_CTX_free(ctx);
|
||||
EC_POINT_free(point);
|
||||
return ok;
|
||||
return 1;
|
||||
}
|
||||
|
||||
int EC_KEY_check_fips(const EC_KEY *key) {
|
||||
|
||||
@@ -92,35 +92,20 @@ void ec_GFp_mont_group_finish(EC_GROUP *group) {
|
||||
|
||||
int ec_GFp_mont_group_set_curve(EC_GROUP *group, const BIGNUM *p,
|
||||
const BIGNUM *a, const BIGNUM *b, BN_CTX *ctx) {
|
||||
BN_CTX *new_ctx = NULL;
|
||||
int ret = 0;
|
||||
|
||||
BN_MONT_CTX_free(group->mont);
|
||||
group->mont = NULL;
|
||||
|
||||
if (ctx == NULL) {
|
||||
ctx = new_ctx = BN_CTX_new();
|
||||
if (ctx == NULL) {
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
group->mont = BN_MONT_CTX_new_for_modulus(p, ctx);
|
||||
if (group->mont == NULL) {
|
||||
OPENSSL_PUT_ERROR(EC, ERR_R_BN_LIB);
|
||||
goto err;
|
||||
return 0;
|
||||
}
|
||||
|
||||
ret = ec_GFp_simple_group_set_curve(group, p, a, b, ctx);
|
||||
|
||||
if (!ret) {
|
||||
if (!ec_GFp_simple_group_set_curve(group, p, a, b, ctx)) {
|
||||
BN_MONT_CTX_free(group->mont);
|
||||
group->mont = NULL;
|
||||
return 0;
|
||||
}
|
||||
|
||||
err:
|
||||
BN_CTX_free(new_ctx);
|
||||
return ret;
|
||||
return 1;
|
||||
}
|
||||
|
||||
static void ec_GFp_mont_felem_to_montgomery(const EC_GROUP *group,
|
||||
@@ -132,14 +117,14 @@ static void ec_GFp_mont_felem_to_montgomery(const EC_GROUP *group,
|
||||
static void ec_GFp_mont_felem_from_montgomery(const EC_GROUP *group,
|
||||
EC_FELEM *out,
|
||||
const EC_FELEM *in) {
|
||||
bn_from_montgomery_small(out->words, in->words, group->field.width,
|
||||
group->mont);
|
||||
bn_from_montgomery_small(out->words, group->field.width, in->words,
|
||||
group->field.width, group->mont);
|
||||
}
|
||||
|
||||
static void ec_GFp_mont_felem_inv(const EC_GROUP *group, EC_FELEM *out,
|
||||
const EC_FELEM *a) {
|
||||
bn_mod_inverse_prime_mont_small(out->words, a->words, group->field.width,
|
||||
group->mont);
|
||||
static void ec_GFp_mont_felem_inv0(const EC_GROUP *group, EC_FELEM *out,
|
||||
const EC_FELEM *a) {
|
||||
bn_mod_inverse0_prime_mont_small(out->words, a->words, group->field.width,
|
||||
group->mont);
|
||||
}
|
||||
|
||||
void ec_GFp_mont_felem_mul(const EC_GROUP *group, EC_FELEM *r,
|
||||
@@ -154,30 +139,39 @@ void ec_GFp_mont_felem_sqr(const EC_GROUP *group, EC_FELEM *r,
|
||||
group->mont);
|
||||
}
|
||||
|
||||
int ec_GFp_mont_bignum_to_felem(const EC_GROUP *group, EC_FELEM *out,
|
||||
const BIGNUM *in) {
|
||||
if (group->mont == NULL) {
|
||||
OPENSSL_PUT_ERROR(EC, EC_R_NOT_INITIALIZED);
|
||||
void ec_GFp_mont_felem_to_bytes(const EC_GROUP *group, uint8_t *out,
|
||||
size_t *out_len, const EC_FELEM *in) {
|
||||
EC_FELEM tmp;
|
||||
ec_GFp_mont_felem_from_montgomery(group, &tmp, in);
|
||||
ec_GFp_simple_felem_to_bytes(group, out, out_len, &tmp);
|
||||
}
|
||||
|
||||
int ec_GFp_mont_felem_from_bytes(const EC_GROUP *group, EC_FELEM *out,
|
||||
const uint8_t *in, size_t len) {
|
||||
if (!ec_GFp_simple_felem_from_bytes(group, out, in, len)) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (!bn_copy_words(out->words, group->field.width, in)) {
|
||||
return 0;
|
||||
}
|
||||
ec_GFp_mont_felem_to_montgomery(group, out, out);
|
||||
return 1;
|
||||
}
|
||||
|
||||
int ec_GFp_mont_felem_to_bignum(const EC_GROUP *group, BIGNUM *out,
|
||||
const EC_FELEM *in) {
|
||||
if (group->mont == NULL) {
|
||||
OPENSSL_PUT_ERROR(EC, EC_R_NOT_INITIALIZED);
|
||||
return 0;
|
||||
}
|
||||
static void ec_GFp_mont_felem_reduce(const EC_GROUP *group, EC_FELEM *out,
|
||||
const BN_ULONG *words, size_t num) {
|
||||
// Convert "from" Montgomery form so the value is reduced mod p.
|
||||
bn_from_montgomery_small(out->words, group->field.width, words, num,
|
||||
group->mont);
|
||||
// Convert "to" Montgomery form to remove the R^-1 factor added.
|
||||
ec_GFp_mont_felem_to_montgomery(group, out, out);
|
||||
// Convert to Montgomery form to match this implementation's representation.
|
||||
ec_GFp_mont_felem_to_montgomery(group, out, out);
|
||||
}
|
||||
|
||||
EC_FELEM tmp;
|
||||
ec_GFp_mont_felem_from_montgomery(group, &tmp, in);
|
||||
return bn_set_words(out, tmp.words, group->field.width);
|
||||
static void ec_GFp_mont_felem_exp(const EC_GROUP *group, EC_FELEM *out,
|
||||
const EC_FELEM *a, const BN_ULONG *exp,
|
||||
size_t num_exp) {
|
||||
bn_mod_exp_mont_small(out->words, a->words, group->field.width, exp, num_exp,
|
||||
group->mont);
|
||||
}
|
||||
|
||||
static int ec_GFp_mont_point_get_affine_coordinates(const EC_GROUP *group,
|
||||
@@ -188,18 +182,12 @@ static int ec_GFp_mont_point_get_affine_coordinates(const EC_GROUP *group,
|
||||
return 0;
|
||||
}
|
||||
|
||||
// Transform (X, Y, Z) into (x, y) := (X/Z^2, Y/Z^3).
|
||||
|
||||
// Transform (X, Y, Z) into (x, y) := (X/Z^2, Y/Z^3). Note the check above
|
||||
// ensures |point->Z| is non-zero, so the inverse always exists.
|
||||
EC_FELEM z1, z2;
|
||||
ec_GFp_mont_felem_inv(group, &z2, &point->Z);
|
||||
ec_GFp_mont_felem_inv0(group, &z2, &point->Z);
|
||||
ec_GFp_mont_felem_sqr(group, &z1, &z2);
|
||||
|
||||
// Instead of using |ec_GFp_mont_felem_from_montgomery| to convert the |x|
|
||||
// coordinate and then calling |ec_GFp_mont_felem_from_montgomery| again to
|
||||
// convert the |y| coordinate below, convert the common factor |z1| once now,
|
||||
// saving one reduction.
|
||||
ec_GFp_mont_felem_from_montgomery(group, &z1, &z1);
|
||||
|
||||
if (x != NULL) {
|
||||
ec_GFp_mont_felem_mul(group, x, &point->X, &z1);
|
||||
}
|
||||
@@ -212,6 +200,52 @@ static int ec_GFp_mont_point_get_affine_coordinates(const EC_GROUP *group,
|
||||
return 1;
|
||||
}
|
||||
|
||||
static int ec_GFp_mont_jacobian_to_affine_batch(const EC_GROUP *group,
|
||||
EC_AFFINE *out,
|
||||
const EC_RAW_POINT *in,
|
||||
size_t num) {
|
||||
if (num == 0) {
|
||||
return 1;
|
||||
}
|
||||
|
||||
// Compute prefix products of all Zs. Use |out[i].X| as scratch space
|
||||
// to store these values.
|
||||
out[0].X = in[0].Z;
|
||||
for (size_t i = 1; i < num; i++) {
|
||||
ec_GFp_mont_felem_mul(group, &out[i].X, &out[i - 1].X, &in[i].Z);
|
||||
}
|
||||
|
||||
// Some input was infinity iff the product of all Zs is zero.
|
||||
if (ec_felem_non_zero_mask(group, &out[num - 1].X) == 0) {
|
||||
OPENSSL_PUT_ERROR(EC, EC_R_POINT_AT_INFINITY);
|
||||
return 0;
|
||||
}
|
||||
|
||||
// Invert the product of all Zs.
|
||||
EC_FELEM zinvprod;
|
||||
ec_GFp_mont_felem_inv0(group, &zinvprod, &out[num - 1].X);
|
||||
for (size_t i = num - 1; i < num; i--) {
|
||||
// Our loop invariant is that |zinvprod| is Z0^-1 * Z1^-1 * ... * Zi^-1.
|
||||
// Recover Zi^-1 by multiplying by the previous product.
|
||||
EC_FELEM zinv, zinv2;
|
||||
if (i == 0) {
|
||||
zinv = zinvprod;
|
||||
} else {
|
||||
ec_GFp_mont_felem_mul(group, &zinv, &zinvprod, &out[i - 1].X);
|
||||
// Maintain the loop invariant for the next iteration.
|
||||
ec_GFp_mont_felem_mul(group, &zinvprod, &zinvprod, &in[i].Z);
|
||||
}
|
||||
|
||||
// Compute affine coordinates: x = X * Z^-2 and y = Y * Z^-3.
|
||||
ec_GFp_mont_felem_sqr(group, &zinv2, &zinv);
|
||||
ec_GFp_mont_felem_mul(group, &out[i].X, &in[i].X, &zinv2);
|
||||
ec_GFp_mont_felem_mul(group, &out[i].Y, &in[i].Y, &zinv2);
|
||||
ec_GFp_mont_felem_mul(group, &out[i].Y, &out[i].Y, &zinv);
|
||||
}
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
void ec_GFp_mont_add(const EC_GROUP *group, EC_RAW_POINT *out,
|
||||
const EC_RAW_POINT *a, const EC_RAW_POINT *b) {
|
||||
if (a == b) {
|
||||
@@ -468,16 +502,23 @@ DEFINE_METHOD_FUNCTION(EC_METHOD, EC_GFp_mont_method) {
|
||||
out->group_finish = ec_GFp_mont_group_finish;
|
||||
out->group_set_curve = ec_GFp_mont_group_set_curve;
|
||||
out->point_get_affine_coordinates = ec_GFp_mont_point_get_affine_coordinates;
|
||||
out->jacobian_to_affine_batch = ec_GFp_mont_jacobian_to_affine_batch;
|
||||
out->add = ec_GFp_mont_add;
|
||||
out->dbl = ec_GFp_mont_dbl;
|
||||
out->mul = ec_GFp_mont_mul;
|
||||
out->mul_base = ec_GFp_mont_mul_base;
|
||||
out->mul_public = ec_GFp_mont_mul_public;
|
||||
out->mul_batch = ec_GFp_mont_mul_batch;
|
||||
out->mul_public_batch = ec_GFp_mont_mul_public_batch;
|
||||
out->init_precomp = ec_GFp_mont_init_precomp;
|
||||
out->mul_precomp = ec_GFp_mont_mul_precomp;
|
||||
out->felem_mul = ec_GFp_mont_felem_mul;
|
||||
out->felem_sqr = ec_GFp_mont_felem_sqr;
|
||||
out->bignum_to_felem = ec_GFp_mont_bignum_to_felem;
|
||||
out->felem_to_bignum = ec_GFp_mont_felem_to_bignum;
|
||||
out->scalar_inv_montgomery = ec_simple_scalar_inv_montgomery;
|
||||
out->scalar_inv_montgomery_vartime = ec_GFp_simple_mont_inv_mod_ord_vartime;
|
||||
out->felem_to_bytes = ec_GFp_mont_felem_to_bytes;
|
||||
out->felem_from_bytes = ec_GFp_mont_felem_from_bytes;
|
||||
out->felem_reduce = ec_GFp_mont_felem_reduce;
|
||||
out->felem_exp = ec_GFp_mont_felem_exp;
|
||||
out->scalar_inv0_montgomery = ec_simple_scalar_inv0_montgomery;
|
||||
out->scalar_to_montgomery_inv_vartime =
|
||||
ec_simple_scalar_to_montgomery_inv_vartime;
|
||||
out->cmp_x_coordinate = ec_GFp_mont_cmp_x_coordinate;
|
||||
}
|
||||
@@ -14,6 +14,7 @@
|
||||
|
||||
#include <CCryptoBoringSSL_ec.h>
|
||||
#include <CCryptoBoringSSL_err.h>
|
||||
#include <CCryptoBoringSSL_mem.h>
|
||||
|
||||
#include <assert.h>
|
||||
|
||||
@@ -23,15 +24,34 @@
|
||||
|
||||
|
||||
int ec_bignum_to_felem(const EC_GROUP *group, EC_FELEM *out, const BIGNUM *in) {
|
||||
if (BN_is_negative(in) || BN_cmp(in, &group->field) >= 0) {
|
||||
uint8_t bytes[EC_MAX_BYTES];
|
||||
size_t len = BN_num_bytes(&group->field);
|
||||
assert(sizeof(bytes) >= len);
|
||||
if (BN_is_negative(in) ||
|
||||
BN_cmp(in, &group->field) >= 0 ||
|
||||
!BN_bn2bin_padded(bytes, len, in)) {
|
||||
OPENSSL_PUT_ERROR(EC, EC_R_COORDINATES_OUT_OF_RANGE);
|
||||
return 0;
|
||||
}
|
||||
return group->meth->bignum_to_felem(group, out, in);
|
||||
|
||||
return ec_felem_from_bytes(group, out, bytes, len);
|
||||
}
|
||||
|
||||
int ec_felem_to_bignum(const EC_GROUP *group, BIGNUM *out, const EC_FELEM *in) {
|
||||
return group->meth->felem_to_bignum(group, out, in);
|
||||
uint8_t bytes[EC_MAX_BYTES];
|
||||
size_t len;
|
||||
ec_felem_to_bytes(group, bytes, &len, in);
|
||||
return BN_bin2bn(bytes, len, out) != NULL;
|
||||
}
|
||||
|
||||
void ec_felem_to_bytes(const EC_GROUP *group, uint8_t *out, size_t *out_len,
|
||||
const EC_FELEM *in) {
|
||||
group->meth->felem_to_bytes(group, out, out_len, in);
|
||||
}
|
||||
|
||||
int ec_felem_from_bytes(const EC_GROUP *group, EC_FELEM *out, const uint8_t *in,
|
||||
size_t len) {
|
||||
return group->meth->felem_from_bytes(group, out, in, len);
|
||||
}
|
||||
|
||||
void ec_felem_neg(const EC_GROUP *group, EC_FELEM *out, const EC_FELEM *a) {
|
||||
@@ -75,8 +95,6 @@ void ec_felem_select(const EC_GROUP *group, EC_FELEM *out, BN_ULONG mask,
|
||||
|
||||
int ec_felem_equal(const EC_GROUP *group, const EC_FELEM *a,
|
||||
const EC_FELEM *b) {
|
||||
// Note this function is variable-time. Constant-time operations should use
|
||||
// |ec_felem_non_zero_mask|.
|
||||
return OPENSSL_memcmp(a->words, b->words,
|
||||
group->field.width * sizeof(BN_ULONG)) == 0;
|
||||
return CRYPTO_memcmp(a->words, b->words,
|
||||
group->field.width * sizeof(BN_ULONG)) == 0;
|
||||
}
|
||||
@@ -71,8 +71,8 @@
|
||||
#include <CCryptoBoringSSL_base.h>
|
||||
|
||||
#include <CCryptoBoringSSL_bn.h>
|
||||
#include <CCryptoBoringSSL_ec.h>
|
||||
#include <CCryptoBoringSSL_ex_data.h>
|
||||
#include <CCryptoBoringSSL_thread.h>
|
||||
#include <CCryptoBoringSSL_type_check.h>
|
||||
|
||||
#include "../bn/internal.h"
|
||||
@@ -82,6 +82,9 @@ extern "C" {
|
||||
#endif
|
||||
|
||||
|
||||
// EC internals.
|
||||
|
||||
|
||||
// Cap the size of all field elements and scalars, including custom curves, to
|
||||
// 66 bytes, large enough to fit secp521r1 and brainpoolP512r1, which appear to
|
||||
// be the largest fields anyone plausibly uses.
|
||||
@@ -91,6 +94,9 @@ extern "C" {
|
||||
OPENSSL_STATIC_ASSERT(EC_MAX_WORDS <= BN_SMALL_MAX_WORDS,
|
||||
"bn_*_small functions not usable");
|
||||
|
||||
|
||||
// Scalars.
|
||||
|
||||
// An EC_SCALAR is an integer fully reduced modulo the order. Only the first
|
||||
// |order->width| words are used. An |EC_SCALAR| is specific to an |EC_GROUP|
|
||||
// and must not be mixed between groups.
|
||||
@@ -100,6 +106,88 @@ typedef union {
|
||||
BN_ULONG words[EC_MAX_WORDS];
|
||||
} EC_SCALAR;
|
||||
|
||||
// ec_bignum_to_scalar converts |in| to an |EC_SCALAR| and writes it to
|
||||
// |*out|. It returns one on success and zero if |in| is out of range.
|
||||
OPENSSL_EXPORT int ec_bignum_to_scalar(const EC_GROUP *group, EC_SCALAR *out,
|
||||
const BIGNUM *in);
|
||||
|
||||
// ec_scalar_to_bytes serializes |in| as a big-endian bytestring to |out| and
|
||||
// sets |*out_len| to the number of bytes written. The number of bytes written
|
||||
// is |BN_num_bytes(&group->order)|, which is at most |EC_MAX_BYTES|.
|
||||
OPENSSL_EXPORT void ec_scalar_to_bytes(const EC_GROUP *group, uint8_t *out,
|
||||
size_t *out_len, const EC_SCALAR *in);
|
||||
|
||||
// ec_scalar_from_bytes deserializes |in| and stores the resulting scalar over
|
||||
// group |group| to |out|. It returns one on success and zero if |in| is
|
||||
// invalid.
|
||||
int ec_scalar_from_bytes(const EC_GROUP *group, EC_SCALAR *out,
|
||||
const uint8_t *in, size_t len);
|
||||
|
||||
// ec_scalar_reduce sets |out| to |words|, reduced modulo the group order.
|
||||
// |words| must be less than order^2. |num| must be at most twice the width of
|
||||
// group order. This function treats |words| as secret.
|
||||
void ec_scalar_reduce(const EC_GROUP *group, EC_SCALAR *out,
|
||||
const BN_ULONG *words, size_t num);
|
||||
|
||||
// ec_random_nonzero_scalar sets |out| to a uniformly selected random value from
|
||||
// 1 to |group->order| - 1. It returns one on success and zero on error.
|
||||
int ec_random_nonzero_scalar(const EC_GROUP *group, EC_SCALAR *out,
|
||||
const uint8_t additional_data[32]);
|
||||
|
||||
// ec_scalar_equal_vartime returns one if |a| and |b| are equal and zero
|
||||
// otherwise. Both values are treated as public.
|
||||
int ec_scalar_equal_vartime(const EC_GROUP *group, const EC_SCALAR *a,
|
||||
const EC_SCALAR *b);
|
||||
|
||||
// ec_scalar_is_zero returns one if |a| is zero and zero otherwise.
|
||||
int ec_scalar_is_zero(const EC_GROUP *group, const EC_SCALAR *a);
|
||||
|
||||
// ec_scalar_add sets |r| to |a| + |b|.
|
||||
void ec_scalar_add(const EC_GROUP *group, EC_SCALAR *r, const EC_SCALAR *a,
|
||||
const EC_SCALAR *b);
|
||||
|
||||
// ec_scalar_sub sets |r| to |a| - |b|.
|
||||
void ec_scalar_sub(const EC_GROUP *group, EC_SCALAR *r, const EC_SCALAR *a,
|
||||
const EC_SCALAR *b);
|
||||
|
||||
// ec_scalar_neg sets |r| to -|a|.
|
||||
void ec_scalar_neg(const EC_GROUP *group, EC_SCALAR *r, const EC_SCALAR *a);
|
||||
|
||||
// ec_scalar_to_montgomery sets |r| to |a| in Montgomery form.
|
||||
void ec_scalar_to_montgomery(const EC_GROUP *group, EC_SCALAR *r,
|
||||
const EC_SCALAR *a);
|
||||
|
||||
// ec_scalar_to_montgomery sets |r| to |a| converted from Montgomery form.
|
||||
void ec_scalar_from_montgomery(const EC_GROUP *group, EC_SCALAR *r,
|
||||
const EC_SCALAR *a);
|
||||
|
||||
// ec_scalar_mul_montgomery sets |r| to |a| * |b| where inputs and outputs are
|
||||
// in Montgomery form.
|
||||
void ec_scalar_mul_montgomery(const EC_GROUP *group, EC_SCALAR *r,
|
||||
const EC_SCALAR *a, const EC_SCALAR *b);
|
||||
|
||||
// ec_scalar_inv0_montgomery sets |r| to |a|^-1 where inputs and outputs are in
|
||||
// Montgomery form. If |a| is zero, |r| is set to zero.
|
||||
void ec_scalar_inv0_montgomery(const EC_GROUP *group, EC_SCALAR *r,
|
||||
const EC_SCALAR *a);
|
||||
|
||||
// ec_scalar_to_montgomery_inv_vartime sets |r| to |a|^-1 R. That is, it takes
|
||||
// in |a| not in Montgomery form and computes the inverse in Montgomery form. It
|
||||
// returns one on success and zero if |a| has no inverse. This function assumes
|
||||
// |a| is public and may leak information about it via timing.
|
||||
//
|
||||
// Note this is not the same operation as |ec_scalar_inv0_montgomery|.
|
||||
int ec_scalar_to_montgomery_inv_vartime(const EC_GROUP *group, EC_SCALAR *r,
|
||||
const EC_SCALAR *a);
|
||||
|
||||
// ec_scalar_select, in constant time, sets |out| to |a| if |mask| is all ones
|
||||
// and |b| if |mask| is all zeros.
|
||||
void ec_scalar_select(const EC_GROUP *group, EC_SCALAR *out, BN_ULONG mask,
|
||||
const EC_SCALAR *a, const EC_SCALAR *b);
|
||||
|
||||
|
||||
// Field elements.
|
||||
|
||||
// An EC_FELEM represents a field element. Only the first |field->width| words
|
||||
// are used. An |EC_FELEM| is specific to an |EC_GROUP| and must not be mixed
|
||||
// between groups. Additionally, the representation (whether or not elements are
|
||||
@@ -110,15 +198,268 @@ typedef union {
|
||||
BN_ULONG words[EC_MAX_WORDS];
|
||||
} EC_FELEM;
|
||||
|
||||
// An EC_RAW_POINT represents an elliptic curve point. Unlike |EC_POINT|, it is
|
||||
// a plain struct which can be stack-allocated and needs no cleanup. It is
|
||||
// specific to an |EC_GROUP| and must not be mixed between groups.
|
||||
// ec_bignum_to_felem converts |in| to an |EC_FELEM|. It returns one on success
|
||||
// and zero if |in| is out of range.
|
||||
int ec_bignum_to_felem(const EC_GROUP *group, EC_FELEM *out, const BIGNUM *in);
|
||||
|
||||
// ec_felem_to_bignum converts |in| to a |BIGNUM|. It returns one on success and
|
||||
// zero on allocation failure.
|
||||
int ec_felem_to_bignum(const EC_GROUP *group, BIGNUM *out, const EC_FELEM *in);
|
||||
|
||||
// ec_felem_to_bytes serializes |in| as a big-endian bytestring to |out| and
|
||||
// sets |*out_len| to the number of bytes written. The number of bytes written
|
||||
// is |BN_num_bytes(&group->order)|, which is at most |EC_MAX_BYTES|.
|
||||
void ec_felem_to_bytes(const EC_GROUP *group, uint8_t *out, size_t *out_len,
|
||||
const EC_FELEM *in);
|
||||
|
||||
// ec_felem_from_bytes deserializes |in| and stores the resulting field element
|
||||
// to |out|. It returns one on success and zero if |in| is invalid.
|
||||
int ec_felem_from_bytes(const EC_GROUP *group, EC_FELEM *out, const uint8_t *in,
|
||||
size_t len);
|
||||
|
||||
// ec_felem_neg sets |out| to -|a|.
|
||||
void ec_felem_neg(const EC_GROUP *group, EC_FELEM *out, const EC_FELEM *a);
|
||||
|
||||
// ec_felem_add sets |out| to |a| + |b|.
|
||||
void ec_felem_add(const EC_GROUP *group, EC_FELEM *out, const EC_FELEM *a,
|
||||
const EC_FELEM *b);
|
||||
|
||||
// ec_felem_add sets |out| to |a| - |b|.
|
||||
void ec_felem_sub(const EC_GROUP *group, EC_FELEM *out, const EC_FELEM *a,
|
||||
const EC_FELEM *b);
|
||||
|
||||
// ec_felem_non_zero_mask returns all ones if |a| is non-zero and all zeros
|
||||
// otherwise.
|
||||
BN_ULONG ec_felem_non_zero_mask(const EC_GROUP *group, const EC_FELEM *a);
|
||||
|
||||
// ec_felem_select, in constant time, sets |out| to |a| if |mask| is all ones
|
||||
// and |b| if |mask| is all zeros.
|
||||
void ec_felem_select(const EC_GROUP *group, EC_FELEM *out, BN_ULONG mask,
|
||||
const EC_FELEM *a, const EC_FELEM *b);
|
||||
|
||||
// ec_felem_equal returns one if |a| and |b| are equal and zero otherwise.
|
||||
int ec_felem_equal(const EC_GROUP *group, const EC_FELEM *a, const EC_FELEM *b);
|
||||
|
||||
|
||||
// Points.
|
||||
//
|
||||
// Points may represented in affine coordinates as |EC_AFFINE| or Jacobian
|
||||
// coordinates as |EC_RAW_POINT|. Affine coordinates directly represent a
|
||||
// point on the curve, but point addition over affine coordinates requires
|
||||
// costly field inversions, so arithmetic is done in Jacobian coordinates.
|
||||
// Converting from affine to Jacobian is cheap, while converting from Jacobian
|
||||
// to affine costs a field inversion. (Jacobian coordinates amortize the field
|
||||
// inversions needed in a sequence of point operations.)
|
||||
//
|
||||
// TODO(davidben): Rename |EC_RAW_POINT| to |EC_JACOBIAN|.
|
||||
|
||||
// An EC_RAW_POINT represents an elliptic curve point in Jacobian coordinates.
|
||||
// Unlike |EC_POINT|, it is a plain struct which can be stack-allocated and
|
||||
// needs no cleanup. It is specific to an |EC_GROUP| and must not be mixed
|
||||
// between groups.
|
||||
typedef struct {
|
||||
EC_FELEM X, Y, Z;
|
||||
// X, Y, and Z are Jacobian projective coordinates. They represent
|
||||
// (X/Z^2, Y/Z^3) if Z != 0 and the point at infinity otherwise.
|
||||
EC_FELEM X, Y, Z;
|
||||
} EC_RAW_POINT;
|
||||
|
||||
// An EC_AFFINE represents an elliptic curve point in affine coordinates.
|
||||
// coordinates. Note the point at infinity cannot be represented in affine
|
||||
// coordinates.
|
||||
typedef struct {
|
||||
EC_FELEM X, Y;
|
||||
} EC_AFFINE;
|
||||
|
||||
// ec_affine_to_jacobian converts |p| to Jacobian form and writes the result to
|
||||
// |*out|. This operation is very cheap and only costs a few copies.
|
||||
void ec_affine_to_jacobian(const EC_GROUP *group, EC_RAW_POINT *out,
|
||||
const EC_AFFINE *p);
|
||||
|
||||
// ec_jacobian_to_affine converts |p| to affine form and writes the result to
|
||||
// |*out|. It returns one on success and zero if |p| was the point at infinity.
|
||||
// This operation performs a field inversion and should only be done once per
|
||||
// point.
|
||||
//
|
||||
// If only extracting the x-coordinate, use |ec_get_x_coordinate_*| which is
|
||||
// slightly faster.
|
||||
int ec_jacobian_to_affine(const EC_GROUP *group, EC_AFFINE *out,
|
||||
const EC_RAW_POINT *p);
|
||||
|
||||
// ec_jacobian_to_affine_batch converts |num| points in |in| from Jacobian
|
||||
// coordinates to affine coordinates and writes the results to |out|. It returns
|
||||
// one on success and zero if any of the input points were infinity.
|
||||
//
|
||||
// This function is not implemented for all curves. Add implementations as
|
||||
// needed.
|
||||
int ec_jacobian_to_affine_batch(const EC_GROUP *group, EC_AFFINE *out,
|
||||
const EC_RAW_POINT *in, size_t num);
|
||||
|
||||
// ec_point_set_affine_coordinates sets |out|'s to a point with affine
|
||||
// coordinates |x| and |y|. It returns one if the point is on the curve and
|
||||
// zero otherwise. If the point is not on the curve, the value of |out| is
|
||||
// undefined.
|
||||
int ec_point_set_affine_coordinates(const EC_GROUP *group, EC_AFFINE *out,
|
||||
const EC_FELEM *x, const EC_FELEM *y);
|
||||
|
||||
// ec_point_mul_scalar sets |r| to |p| * |scalar|. Both inputs are considered
|
||||
// secret.
|
||||
int ec_point_mul_scalar(const EC_GROUP *group, EC_RAW_POINT *r,
|
||||
const EC_RAW_POINT *p, const EC_SCALAR *scalar);
|
||||
|
||||
// ec_point_mul_scalar_base sets |r| to generator * |scalar|. |scalar| is
|
||||
// treated as secret.
|
||||
int ec_point_mul_scalar_base(const EC_GROUP *group, EC_RAW_POINT *r,
|
||||
const EC_SCALAR *scalar);
|
||||
|
||||
// ec_point_mul_scalar_batch sets |r| to |p0| * |scalar0| + |p1| * |scalar1| +
|
||||
// |p2| * |scalar2|. |p2| may be NULL to skip that term.
|
||||
//
|
||||
// The inputs are treated as secret, however, this function leaks information
|
||||
// about whether intermediate computations add a point to itself. Callers must
|
||||
// ensure that discrete logs between |p0|, |p1|, and |p2| are uniformly
|
||||
// distributed and independent of the scalars, which should be uniformly
|
||||
// selected and not under the attackers control. This ensures the doubling case
|
||||
// will occur with negligible probability.
|
||||
//
|
||||
// This function is not implemented for all curves. Add implementations as
|
||||
// needed.
|
||||
//
|
||||
// TODO(davidben): This function does not use base point tables. For now, it is
|
||||
// only used with the generic |EC_GFp_mont_method| implementation which has
|
||||
// none. If generalizing to tuned curves, this may be useful. However, we still
|
||||
// must double up to the least efficient input, so precomputed tables can only
|
||||
// save table setup and allow a wider window size.
|
||||
int ec_point_mul_scalar_batch(const EC_GROUP *group, EC_RAW_POINT *r,
|
||||
const EC_RAW_POINT *p0, const EC_SCALAR *scalar0,
|
||||
const EC_RAW_POINT *p1, const EC_SCALAR *scalar1,
|
||||
const EC_RAW_POINT *p2, const EC_SCALAR *scalar2);
|
||||
|
||||
#define EC_MONT_PRECOMP_COMB_SIZE 5
|
||||
|
||||
// An |EC_PRECOMP| stores precomputed information about a point, to optimize
|
||||
// repeated multiplications involving it. It is a union so different
|
||||
// |EC_METHOD|s can store different information in it.
|
||||
typedef union {
|
||||
EC_AFFINE comb[(1 << EC_MONT_PRECOMP_COMB_SIZE) - 1];
|
||||
} EC_PRECOMP;
|
||||
|
||||
// ec_init_precomp precomputes multiples of |p| and writes the result to |out|.
|
||||
// It returns one on success and zero on error. The resulting table may be used
|
||||
// with |ec_point_mul_scalar_precomp|. This function will fail if |p| is the
|
||||
// point at infinity.
|
||||
//
|
||||
// This function is not implemented for all curves. Add implementations as
|
||||
// needed.
|
||||
int ec_init_precomp(const EC_GROUP *group, EC_PRECOMP *out,
|
||||
const EC_RAW_POINT *p);
|
||||
|
||||
// ec_point_mul_scalar_precomp sets |r| to |p0| * |scalar0| + |p1| * |scalar1| +
|
||||
// |p2| * |scalar2|. |p1| or |p2| may be NULL to skip the corresponding term.
|
||||
// The points are represented as |EC_PRECOMP| and must be initialized with
|
||||
// |ec_init_precomp|. This function runs faster than |ec_point_mul_scalar_batch|
|
||||
// but requires setup work per input point, so it is only appropriate for points
|
||||
// which are used frequently.
|
||||
//
|
||||
// The inputs are treated as secret, however, this function leaks information
|
||||
// about whether intermediate computations add a point to itself. Callers must
|
||||
// ensure that discrete logs between |p0|, |p1|, and |p2| are uniformly
|
||||
// distributed and independent of the scalars, which should be uniformly
|
||||
// selected and not under the attackers control. This ensures the doubling case
|
||||
// will occur with negligible probability.
|
||||
//
|
||||
// This function is not implemented for all curves. Add implementations as
|
||||
// needed.
|
||||
//
|
||||
// TODO(davidben): This function does not use base point tables. For now, it is
|
||||
// only used with the generic |EC_GFp_mont_method| implementation which has
|
||||
// none. If generalizing to tuned curves, we should add a parameter for the base
|
||||
// point and arrange for the generic implementation to have base point tables
|
||||
// available.
|
||||
int ec_point_mul_scalar_precomp(const EC_GROUP *group, EC_RAW_POINT *r,
|
||||
const EC_PRECOMP *p0, const EC_SCALAR *scalar0,
|
||||
const EC_PRECOMP *p1, const EC_SCALAR *scalar1,
|
||||
const EC_PRECOMP *p2, const EC_SCALAR *scalar2);
|
||||
|
||||
// ec_point_mul_scalar_public sets |r| to
|
||||
// generator * |g_scalar| + |p| * |p_scalar|. It assumes that the inputs are
|
||||
// public so there is no concern about leaking their values through timing.
|
||||
OPENSSL_EXPORT int ec_point_mul_scalar_public(const EC_GROUP *group,
|
||||
EC_RAW_POINT *r,
|
||||
const EC_SCALAR *g_scalar,
|
||||
const EC_RAW_POINT *p,
|
||||
const EC_SCALAR *p_scalar);
|
||||
|
||||
// ec_point_mul_scalar_public_batch sets |r| to the sum of generator *
|
||||
// |g_scalar| and |points[i]| * |scalars[i]| where |points| and |scalars| have
|
||||
// |num| elements. It assumes that the inputs are public so there is no concern
|
||||
// about leaking their values through timing. |g_scalar| may be NULL to skip
|
||||
// that term.
|
||||
//
|
||||
// This function is not implemented for all curves. Add implementations as
|
||||
// needed.
|
||||
int ec_point_mul_scalar_public_batch(const EC_GROUP *group, EC_RAW_POINT *r,
|
||||
const EC_SCALAR *g_scalar,
|
||||
const EC_RAW_POINT *points,
|
||||
const EC_SCALAR *scalars, size_t num);
|
||||
|
||||
// ec_point_select, in constant time, sets |out| to |a| if |mask| is all ones
|
||||
// and |b| if |mask| is all zeros.
|
||||
void ec_point_select(const EC_GROUP *group, EC_RAW_POINT *out, BN_ULONG mask,
|
||||
const EC_RAW_POINT *a, const EC_RAW_POINT *b);
|
||||
|
||||
// ec_affine_select behaves like |ec_point_select| but acts on affine points.
|
||||
void ec_affine_select(const EC_GROUP *group, EC_AFFINE *out, BN_ULONG mask,
|
||||
const EC_AFFINE *a, const EC_AFFINE *b);
|
||||
|
||||
// ec_precomp_select behaves like |ec_point_select| but acts on |EC_PRECOMP|.
|
||||
void ec_precomp_select(const EC_GROUP *group, EC_PRECOMP *out, BN_ULONG mask,
|
||||
const EC_PRECOMP *a, const EC_PRECOMP *b);
|
||||
|
||||
// ec_cmp_x_coordinate compares the x (affine) coordinate of |p|, mod the group
|
||||
// order, with |r|. It returns one if the values match and zero if |p| is the
|
||||
// point at infinity of the values do not match.
|
||||
int ec_cmp_x_coordinate(const EC_GROUP *group, const EC_RAW_POINT *p,
|
||||
const EC_SCALAR *r);
|
||||
|
||||
// ec_get_x_coordinate_as_scalar sets |*out| to |p|'s x-coordinate, modulo
|
||||
// |group->order|. It returns one on success and zero if |p| is the point at
|
||||
// infinity.
|
||||
int ec_get_x_coordinate_as_scalar(const EC_GROUP *group, EC_SCALAR *out,
|
||||
const EC_RAW_POINT *p);
|
||||
|
||||
// ec_get_x_coordinate_as_bytes writes |p|'s affine x-coordinate to |out|, which
|
||||
// must have at must |max_out| bytes. It sets |*out_len| to the number of bytes
|
||||
// written. The value is written big-endian and zero-padded to the size of the
|
||||
// field. This function returns one on success and zero on failure.
|
||||
int ec_get_x_coordinate_as_bytes(const EC_GROUP *group, uint8_t *out,
|
||||
size_t *out_len, size_t max_out,
|
||||
const EC_RAW_POINT *p);
|
||||
|
||||
// ec_point_to_bytes behaves like |EC_POINT_point2oct| but takes an
|
||||
// |EC_AFFINE|.
|
||||
size_t ec_point_to_bytes(const EC_GROUP *group, const EC_AFFINE *point,
|
||||
point_conversion_form_t form, uint8_t *buf,
|
||||
size_t len);
|
||||
|
||||
// ec_point_from_uncompressed parses |in| as a point in uncompressed form and
|
||||
// sets the result to |out|. It returns one on success and zero if the input was
|
||||
// invalid.
|
||||
int ec_point_from_uncompressed(const EC_GROUP *group, EC_AFFINE *out,
|
||||
const uint8_t *in, size_t len);
|
||||
|
||||
// ec_set_to_safe_point sets |out| to an arbitrary point on |group|, either the
|
||||
// generator or the point at infinity. This is used to guard against callers of
|
||||
// external APIs not checking the return value.
|
||||
void ec_set_to_safe_point(const EC_GROUP *group, EC_RAW_POINT *out);
|
||||
|
||||
// ec_affine_jacobian_equal returns one if |a| and |b| represent the same point
|
||||
// and zero otherwise. It treats both inputs as secret.
|
||||
int ec_affine_jacobian_equal(const EC_GROUP *group, const EC_AFFINE *a,
|
||||
const EC_RAW_POINT *b);
|
||||
|
||||
|
||||
// Implementation details.
|
||||
|
||||
struct ec_method_st {
|
||||
int (*group_init)(EC_GROUP *);
|
||||
void (*group_finish)(EC_GROUP *);
|
||||
@@ -128,12 +469,13 @@ struct ec_method_st {
|
||||
// point_get_affine_coordinates sets |*x| and |*y| to the affine coordinates
|
||||
// of |p|. Either |x| or |y| may be NULL to omit it. It returns one on success
|
||||
// and zero if |p| is the point at infinity.
|
||||
//
|
||||
// Note: unlike |EC_FELEM|s used as intermediate values internal to the
|
||||
// |EC_METHOD|, |*x| and |*y| are not encoded in Montgomery form.
|
||||
int (*point_get_affine_coordinates)(const EC_GROUP *, const EC_RAW_POINT *p,
|
||||
EC_FELEM *x, EC_FELEM *y);
|
||||
|
||||
// jacobian_to_affine_batch implements |ec_jacobian_to_affine_batch|.
|
||||
int (*jacobian_to_affine_batch)(const EC_GROUP *group, EC_AFFINE *out,
|
||||
const EC_RAW_POINT *in, size_t num);
|
||||
|
||||
// add sets |r| to |a| + |b|.
|
||||
void (*add)(const EC_GROUP *group, EC_RAW_POINT *r, const EC_RAW_POINT *a,
|
||||
const EC_RAW_POINT *b);
|
||||
@@ -146,12 +488,32 @@ struct ec_method_st {
|
||||
// mul_base sets |r| to |scalar|*generator.
|
||||
void (*mul_base)(const EC_GROUP *group, EC_RAW_POINT *r,
|
||||
const EC_SCALAR *scalar);
|
||||
// mul_batch implements |ec_mul_scalar_batch|.
|
||||
void (*mul_batch)(const EC_GROUP *group, EC_RAW_POINT *r,
|
||||
const EC_RAW_POINT *p0, const EC_SCALAR *scalar0,
|
||||
const EC_RAW_POINT *p1, const EC_SCALAR *scalar1,
|
||||
const EC_RAW_POINT *p2, const EC_SCALAR *scalar2);
|
||||
// mul_public sets |r| to |g_scalar|*generator + |p_scalar|*|p|. It assumes
|
||||
// that the inputs are public so there is no concern about leaking their
|
||||
// values through timing.
|
||||
//
|
||||
// This function may be omitted if |mul_public_batch| is provided.
|
||||
void (*mul_public)(const EC_GROUP *group, EC_RAW_POINT *r,
|
||||
const EC_SCALAR *g_scalar, const EC_RAW_POINT *p,
|
||||
const EC_SCALAR *p_scalar);
|
||||
// mul_public_batch implements |ec_point_mul_scalar_public_batch|.
|
||||
int (*mul_public_batch)(const EC_GROUP *group, EC_RAW_POINT *r,
|
||||
const EC_SCALAR *g_scalar, const EC_RAW_POINT *points,
|
||||
const EC_SCALAR *scalars, size_t num);
|
||||
|
||||
// init_precomp implements |ec_init_precomp|.
|
||||
int (*init_precomp)(const EC_GROUP *group, EC_PRECOMP *out,
|
||||
const EC_RAW_POINT *p);
|
||||
// mul_precomp implements |ec_point_mul_scalar_precomp|.
|
||||
void (*mul_precomp)(const EC_GROUP *group, EC_RAW_POINT *r,
|
||||
const EC_PRECOMP *p0, const EC_SCALAR *scalar0,
|
||||
const EC_PRECOMP *p1, const EC_SCALAR *scalar1,
|
||||
const EC_PRECOMP *p2, const EC_SCALAR *scalar2);
|
||||
|
||||
// felem_mul and felem_sqr implement multiplication and squaring,
|
||||
// respectively, so that the generic |EC_POINT_add| and |EC_POINT_dbl|
|
||||
@@ -168,21 +530,36 @@ struct ec_method_st {
|
||||
const EC_FELEM *b);
|
||||
void (*felem_sqr)(const EC_GROUP *, EC_FELEM *r, const EC_FELEM *a);
|
||||
|
||||
int (*bignum_to_felem)(const EC_GROUP *group, EC_FELEM *out,
|
||||
const BIGNUM *in);
|
||||
int (*felem_to_bignum)(const EC_GROUP *group, BIGNUM *out,
|
||||
void (*felem_to_bytes)(const EC_GROUP *group, uint8_t *out, size_t *out_len,
|
||||
const EC_FELEM *in);
|
||||
int (*felem_from_bytes)(const EC_GROUP *group, EC_FELEM *out,
|
||||
const uint8_t *in, size_t len);
|
||||
|
||||
// scalar_inv_montgomery sets |out| to |in|^-1, where both input and output
|
||||
// are in Montgomery form.
|
||||
void (*scalar_inv_montgomery)(const EC_GROUP *group, EC_SCALAR *out,
|
||||
const EC_SCALAR *in);
|
||||
// felem_reduce sets |out| to |words|, reduced modulo the field size, p.
|
||||
// |words| must be less than p^2. |num| must be at most twice the width of p.
|
||||
// This function treats |words| as secret.
|
||||
//
|
||||
// This function is only used in hash-to-curve and may be omitted in curves
|
||||
// that do not support it.
|
||||
void (*felem_reduce)(const EC_GROUP *group, EC_FELEM *out,
|
||||
const BN_ULONG *words, size_t num);
|
||||
|
||||
// scalar_inv_montgomery_vartime performs the same computation as
|
||||
// |scalar_inv_montgomery|. It further assumes that the inputs are public so
|
||||
// there is no concern about leaking their values through timing.
|
||||
int (*scalar_inv_montgomery_vartime)(const EC_GROUP *group, EC_SCALAR *out,
|
||||
const EC_SCALAR *in);
|
||||
// felem_exp sets |out| to |a|^|exp|. It treats |a| is secret but |exp| as
|
||||
// public.
|
||||
//
|
||||
// This function is used in hash-to-curve and may be NULL in curves not used
|
||||
// with hash-to-curve.
|
||||
void (*felem_exp)(const EC_GROUP *group, EC_FELEM *out, const EC_FELEM *a,
|
||||
const BN_ULONG *exp, size_t num_exp);
|
||||
|
||||
// scalar_inv0_montgomery implements |ec_scalar_inv0_montgomery|.
|
||||
void (*scalar_inv0_montgomery)(const EC_GROUP *group, EC_SCALAR *out,
|
||||
const EC_SCALAR *in);
|
||||
|
||||
// scalar_to_montgomery_inv_vartime implements
|
||||
// |ec_scalar_to_montgomery_inv_vartime|.
|
||||
int (*scalar_to_montgomery_inv_vartime)(const EC_GROUP *group, EC_SCALAR *out,
|
||||
const EC_SCALAR *in);
|
||||
|
||||
// cmp_x_coordinate compares the x (affine) coordinate of |p|, mod the group
|
||||
// order, with |r|. It returns one if the values match and zero if |p| is the
|
||||
@@ -197,7 +574,8 @@ struct ec_group_st {
|
||||
const EC_METHOD *meth;
|
||||
|
||||
// Unlike all other |EC_POINT|s, |generator| does not own |generator->group|
|
||||
// to avoid a reference cycle.
|
||||
// to avoid a reference cycle. Additionally, Z is guaranteed to be one, so X
|
||||
// and Y are suitable for use as an |EC_AFFINE|.
|
||||
EC_POINT *generator;
|
||||
BIGNUM order;
|
||||
|
||||
@@ -247,133 +625,20 @@ struct ec_point_st {
|
||||
|
||||
EC_GROUP *ec_group_new(const EC_METHOD *meth);
|
||||
|
||||
// ec_bignum_to_felem converts |in| to an |EC_FELEM|. It returns one on success
|
||||
// and zero if |in| is out of range.
|
||||
int ec_bignum_to_felem(const EC_GROUP *group, EC_FELEM *out, const BIGNUM *in);
|
||||
|
||||
// ec_felem_to_bignum converts |in| to a |BIGNUM|. It returns one on success and
|
||||
// zero on allocation failure.
|
||||
int ec_felem_to_bignum(const EC_GROUP *group, BIGNUM *out, const EC_FELEM *in);
|
||||
|
||||
// ec_felem_neg sets |out| to -|a|.
|
||||
void ec_felem_neg(const EC_GROUP *group, EC_FELEM *out, const EC_FELEM *a);
|
||||
|
||||
// ec_felem_add sets |out| to |a| + |b|.
|
||||
void ec_felem_add(const EC_GROUP *group, EC_FELEM *out, const EC_FELEM *a,
|
||||
const EC_FELEM *b);
|
||||
|
||||
// ec_felem_add sets |out| to |a| - |b|.
|
||||
void ec_felem_sub(const EC_GROUP *group, EC_FELEM *out, const EC_FELEM *a,
|
||||
const EC_FELEM *b);
|
||||
|
||||
// ec_felem_non_zero_mask returns all ones if |a| is non-zero and all zeros
|
||||
// otherwise.
|
||||
BN_ULONG ec_felem_non_zero_mask(const EC_GROUP *group, const EC_FELEM *a);
|
||||
|
||||
// ec_felem_select, in constant time, sets |out| to |a| if |mask| is all ones
|
||||
// and |b| if |mask| is all zeros.
|
||||
void ec_felem_select(const EC_GROUP *group, EC_FELEM *out, BN_ULONG mask,
|
||||
const EC_FELEM *a, const EC_FELEM *b);
|
||||
|
||||
// ec_felem_equal returns one if |a| and |b| are equal and zero otherwise. It
|
||||
// treats |a| and |b| as public and does *not* run in constant time.
|
||||
int ec_felem_equal(const EC_GROUP *group, const EC_FELEM *a, const EC_FELEM *b);
|
||||
|
||||
// ec_bignum_to_scalar converts |in| to an |EC_SCALAR| and writes it to
|
||||
// |*out|. It returns one on success and zero if |in| is out of range.
|
||||
OPENSSL_EXPORT int ec_bignum_to_scalar(const EC_GROUP *group, EC_SCALAR *out,
|
||||
const BIGNUM *in);
|
||||
|
||||
// ec_random_nonzero_scalar sets |out| to a uniformly selected random value from
|
||||
// 1 to |group->order| - 1. It returns one on success and zero on error.
|
||||
int ec_random_nonzero_scalar(const EC_GROUP *group, EC_SCALAR *out,
|
||||
const uint8_t additional_data[32]);
|
||||
|
||||
// ec_scalar_equal_vartime returns one if |a| and |b| are equal and zero
|
||||
// otherwise. Both values are treated as public.
|
||||
int ec_scalar_equal_vartime(const EC_GROUP *group, const EC_SCALAR *a,
|
||||
const EC_SCALAR *b);
|
||||
|
||||
// ec_scalar_is_zero returns one if |a| is zero and zero otherwise.
|
||||
int ec_scalar_is_zero(const EC_GROUP *group, const EC_SCALAR *a);
|
||||
|
||||
// ec_scalar_add sets |r| to |a| + |b|.
|
||||
void ec_scalar_add(const EC_GROUP *group, EC_SCALAR *r, const EC_SCALAR *a,
|
||||
const EC_SCALAR *b);
|
||||
|
||||
// ec_scalar_to_montgomery sets |r| to |a| in Montgomery form.
|
||||
void ec_scalar_to_montgomery(const EC_GROUP *group, EC_SCALAR *r,
|
||||
const EC_SCALAR *a);
|
||||
|
||||
// ec_scalar_to_montgomery sets |r| to |a| converted from Montgomery form.
|
||||
void ec_scalar_from_montgomery(const EC_GROUP *group, EC_SCALAR *r,
|
||||
const EC_SCALAR *a);
|
||||
|
||||
// ec_scalar_mul_montgomery sets |r| to |a| * |b| where inputs and outputs are
|
||||
// in Montgomery form.
|
||||
void ec_scalar_mul_montgomery(const EC_GROUP *group, EC_SCALAR *r,
|
||||
const EC_SCALAR *a, const EC_SCALAR *b);
|
||||
|
||||
// ec_scalar_mul_montgomery sets |r| to |a|^-1 where inputs and outputs are in
|
||||
// Montgomery form.
|
||||
void ec_scalar_inv_montgomery(const EC_GROUP *group, EC_SCALAR *r,
|
||||
const EC_SCALAR *a);
|
||||
|
||||
// ec_scalar_inv_montgomery_vartime performs the same actions as
|
||||
// |ec_scalar_inv_montgomery|, but in variable time.
|
||||
int ec_scalar_inv_montgomery_vartime(const EC_GROUP *group, EC_SCALAR *r,
|
||||
const EC_SCALAR *a);
|
||||
|
||||
// ec_point_mul_scalar sets |r| to |p| * |scalar|. Both inputs are considered
|
||||
// secret.
|
||||
int ec_point_mul_scalar(const EC_GROUP *group, EC_RAW_POINT *r,
|
||||
const EC_RAW_POINT *p, const EC_SCALAR *scalar);
|
||||
|
||||
// ec_point_mul_scalar_base sets |r| to generator * |scalar|. |scalar| is
|
||||
// treated as secret.
|
||||
int ec_point_mul_scalar_base(const EC_GROUP *group, EC_RAW_POINT *r,
|
||||
const EC_SCALAR *scalar);
|
||||
|
||||
// ec_point_mul_scalar_public performs the same computation as
|
||||
// ec_point_mul_scalar. It further assumes that the inputs are public so
|
||||
// there is no concern about leaking their values through timing.
|
||||
OPENSSL_EXPORT int ec_point_mul_scalar_public(const EC_GROUP *group,
|
||||
EC_RAW_POINT *r,
|
||||
const EC_SCALAR *g_scalar,
|
||||
const EC_RAW_POINT *p,
|
||||
const EC_SCALAR *p_scalar);
|
||||
|
||||
// ec_cmp_x_coordinate compares the x (affine) coordinate of |p|, mod the group
|
||||
// order, with |r|. It returns one if the values match and zero if |p| is the
|
||||
// point at infinity of the values do not match.
|
||||
int ec_cmp_x_coordinate(const EC_GROUP *group, const EC_RAW_POINT *p,
|
||||
const EC_SCALAR *r);
|
||||
|
||||
// ec_get_x_coordinate_as_scalar sets |*out| to |p|'s x-coordinate, modulo
|
||||
// |group->order|. It returns one on success and zero if |p| is the point at
|
||||
// infinity.
|
||||
int ec_get_x_coordinate_as_scalar(const EC_GROUP *group, EC_SCALAR *out,
|
||||
const EC_RAW_POINT *p);
|
||||
|
||||
// ec_point_get_affine_coordinate_bytes writes |p|'s affine coordinates to
|
||||
// |out_x| and |out_y|, each of which must have at must |max_out| bytes. It sets
|
||||
// |*out_len| to the number of bytes written in each buffer. Coordinates are
|
||||
// written big-endian and zero-padded to the size of the field.
|
||||
//
|
||||
// Either of |out_x| or |out_y| may be NULL to omit that coordinate. This
|
||||
// function returns one on success and zero on failure.
|
||||
int ec_point_get_affine_coordinate_bytes(const EC_GROUP *group, uint8_t *out_x,
|
||||
uint8_t *out_y, size_t *out_len,
|
||||
size_t max_out, const EC_RAW_POINT *p);
|
||||
|
||||
// ec_field_element_to_scalar reduces |r| modulo |group->order|. |r| must
|
||||
// previously have been reduced modulo |group->field|.
|
||||
int ec_field_element_to_scalar(const EC_GROUP *group, BIGNUM *r);
|
||||
|
||||
void ec_GFp_mont_mul(const EC_GROUP *group, EC_RAW_POINT *r,
|
||||
const EC_RAW_POINT *p, const EC_SCALAR *scalar);
|
||||
void ec_GFp_mont_mul_base(const EC_GROUP *group, EC_RAW_POINT *r,
|
||||
const EC_SCALAR *scalar);
|
||||
void ec_GFp_mont_mul_batch(const EC_GROUP *group, EC_RAW_POINT *r,
|
||||
const EC_RAW_POINT *p0, const EC_SCALAR *scalar0,
|
||||
const EC_RAW_POINT *p1, const EC_SCALAR *scalar1,
|
||||
const EC_RAW_POINT *p2, const EC_SCALAR *scalar2);
|
||||
int ec_GFp_mont_init_precomp(const EC_GROUP *group, EC_PRECOMP *out,
|
||||
const EC_RAW_POINT *p);
|
||||
void ec_GFp_mont_mul_precomp(const EC_GROUP *group, EC_RAW_POINT *r,
|
||||
const EC_PRECOMP *p0, const EC_SCALAR *scalar0,
|
||||
const EC_PRECOMP *p1, const EC_SCALAR *scalar1,
|
||||
const EC_PRECOMP *p2, const EC_SCALAR *scalar2);
|
||||
|
||||
// ec_compute_wNAF writes the modified width-(w+1) Non-Adjacent Form (wNAF) of
|
||||
// |scalar| to |out|. |out| must have room for |bits| + 1 elements, each of
|
||||
@@ -386,9 +651,10 @@ void ec_GFp_mont_mul_base(const EC_GROUP *group, EC_RAW_POINT *r,
|
||||
void ec_compute_wNAF(const EC_GROUP *group, int8_t *out,
|
||||
const EC_SCALAR *scalar, size_t bits, int w);
|
||||
|
||||
void ec_GFp_mont_mul_public(const EC_GROUP *group, EC_RAW_POINT *r,
|
||||
const EC_SCALAR *g_scalar, const EC_RAW_POINT *p,
|
||||
const EC_SCALAR *p_scalar);
|
||||
int ec_GFp_mont_mul_public_batch(const EC_GROUP *group, EC_RAW_POINT *r,
|
||||
const EC_SCALAR *g_scalar,
|
||||
const EC_RAW_POINT *points,
|
||||
const EC_SCALAR *scalars, size_t num);
|
||||
|
||||
// method functions in simple.c
|
||||
int ec_GFp_simple_group_init(EC_GROUP *);
|
||||
@@ -400,26 +666,29 @@ int ec_GFp_simple_group_get_curve(const EC_GROUP *, BIGNUM *p, BIGNUM *a,
|
||||
void ec_GFp_simple_point_init(EC_RAW_POINT *);
|
||||
void ec_GFp_simple_point_copy(EC_RAW_POINT *, const EC_RAW_POINT *);
|
||||
void ec_GFp_simple_point_set_to_infinity(const EC_GROUP *, EC_RAW_POINT *);
|
||||
int ec_GFp_simple_point_set_affine_coordinates(const EC_GROUP *, EC_RAW_POINT *,
|
||||
const BIGNUM *x,
|
||||
const BIGNUM *y);
|
||||
void ec_GFp_mont_add(const EC_GROUP *, EC_RAW_POINT *r, const EC_RAW_POINT *a,
|
||||
const EC_RAW_POINT *b);
|
||||
void ec_GFp_mont_dbl(const EC_GROUP *, EC_RAW_POINT *r, const EC_RAW_POINT *a);
|
||||
void ec_GFp_simple_invert(const EC_GROUP *, EC_RAW_POINT *);
|
||||
int ec_GFp_simple_is_at_infinity(const EC_GROUP *, const EC_RAW_POINT *);
|
||||
int ec_GFp_simple_is_on_curve(const EC_GROUP *, const EC_RAW_POINT *);
|
||||
int ec_GFp_simple_cmp(const EC_GROUP *, const EC_RAW_POINT *a,
|
||||
const EC_RAW_POINT *b);
|
||||
void ec_simple_scalar_inv_montgomery(const EC_GROUP *group, EC_SCALAR *r,
|
||||
const EC_SCALAR *a);
|
||||
int ec_GFp_simple_points_equal(const EC_GROUP *, const EC_RAW_POINT *a,
|
||||
const EC_RAW_POINT *b);
|
||||
void ec_simple_scalar_inv0_montgomery(const EC_GROUP *group, EC_SCALAR *r,
|
||||
const EC_SCALAR *a);
|
||||
|
||||
int ec_GFp_simple_mont_inv_mod_ord_vartime(const EC_GROUP *group, EC_SCALAR *r,
|
||||
const EC_SCALAR *a);
|
||||
int ec_simple_scalar_to_montgomery_inv_vartime(const EC_GROUP *group,
|
||||
EC_SCALAR *r,
|
||||
const EC_SCALAR *a);
|
||||
|
||||
int ec_GFp_simple_cmp_x_coordinate(const EC_GROUP *group, const EC_RAW_POINT *p,
|
||||
const EC_SCALAR *r);
|
||||
|
||||
void ec_GFp_simple_felem_to_bytes(const EC_GROUP *group, uint8_t *out,
|
||||
size_t *out_len, const EC_FELEM *in);
|
||||
int ec_GFp_simple_felem_from_bytes(const EC_GROUP *group, EC_FELEM *out,
|
||||
const uint8_t *in, size_t len);
|
||||
|
||||
// method functions in montgomery.c
|
||||
int ec_GFp_mont_group_init(EC_GROUP *);
|
||||
int ec_GFp_mont_group_set_curve(EC_GROUP *, const BIGNUM *p, const BIGNUM *a,
|
||||
@@ -429,10 +698,10 @@ void ec_GFp_mont_felem_mul(const EC_GROUP *, EC_FELEM *r, const EC_FELEM *a,
|
||||
const EC_FELEM *b);
|
||||
void ec_GFp_mont_felem_sqr(const EC_GROUP *, EC_FELEM *r, const EC_FELEM *a);
|
||||
|
||||
int ec_GFp_mont_bignum_to_felem(const EC_GROUP *group, EC_FELEM *out,
|
||||
const BIGNUM *in);
|
||||
int ec_GFp_mont_felem_to_bignum(const EC_GROUP *group, BIGNUM *out,
|
||||
const EC_FELEM *in);
|
||||
void ec_GFp_mont_felem_to_bytes(const EC_GROUP *group, uint8_t *out,
|
||||
size_t *out_len, const EC_FELEM *in);
|
||||
int ec_GFp_mont_felem_from_bytes(const EC_GROUP *group, EC_FELEM *out,
|
||||
const uint8_t *in, size_t len);
|
||||
|
||||
void ec_GFp_nistp_recode_scalar_bits(uint8_t *sign, uint8_t *digit, uint8_t in);
|
||||
|
||||
@@ -453,6 +722,9 @@ typedef struct {
|
||||
struct ec_key_st {
|
||||
EC_GROUP *group;
|
||||
|
||||
// Ideally |pub_key| would be an |EC_AFFINE| so serializing it does not pay an
|
||||
// inversion each time, but the |EC_KEY_get0_public_key| API implies public
|
||||
// keys are stored in an |EC_POINT|-compatible form.
|
||||
EC_POINT *pub_key;
|
||||
EC_WRAPPED_SCALAR *priv_key;
|
||||
|
||||
|
||||
@@ -73,21 +73,15 @@
|
||||
#include "internal.h"
|
||||
|
||||
|
||||
static size_t ec_GFp_simple_point2oct(const EC_GROUP *group,
|
||||
const EC_RAW_POINT *point,
|
||||
point_conversion_form_t form,
|
||||
uint8_t *buf, size_t len) {
|
||||
size_t ec_point_to_bytes(const EC_GROUP *group, const EC_AFFINE *point,
|
||||
point_conversion_form_t form, uint8_t *buf,
|
||||
size_t len) {
|
||||
if (form != POINT_CONVERSION_COMPRESSED &&
|
||||
form != POINT_CONVERSION_UNCOMPRESSED) {
|
||||
OPENSSL_PUT_ERROR(EC, EC_R_INVALID_FORM);
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (ec_GFp_simple_is_at_infinity(group, point)) {
|
||||
OPENSSL_PUT_ERROR(EC, EC_R_POINT_AT_INFINITY);
|
||||
return 0;
|
||||
}
|
||||
|
||||
const size_t field_len = BN_num_bytes(&group->field);
|
||||
size_t output_len = 1 /* type byte */ + field_len;
|
||||
if (form == POINT_CONVERSION_UNCOMPRESSED) {
|
||||
@@ -102,79 +96,89 @@ static size_t ec_GFp_simple_point2oct(const EC_GROUP *group,
|
||||
return 0;
|
||||
}
|
||||
|
||||
uint8_t y_buf[EC_MAX_BYTES];
|
||||
size_t field_len_out;
|
||||
if (!ec_point_get_affine_coordinate_bytes(
|
||||
group, buf + 1 /* x */,
|
||||
form == POINT_CONVERSION_COMPRESSED ? y_buf : buf + 1 + field_len,
|
||||
&field_len_out, field_len, point)) {
|
||||
return 0;
|
||||
}
|
||||
ec_felem_to_bytes(group, buf + 1, &field_len_out, &point->X);
|
||||
assert(field_len_out == field_len);
|
||||
|
||||
if (field_len_out != field_len) {
|
||||
OPENSSL_PUT_ERROR(EC, ERR_R_INTERNAL_ERROR);
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (form == POINT_CONVERSION_COMPRESSED) {
|
||||
buf[0] = form + (y_buf[field_len - 1] & 1);
|
||||
} else {
|
||||
if (form == POINT_CONVERSION_UNCOMPRESSED) {
|
||||
ec_felem_to_bytes(group, buf + 1 + field_len, &field_len_out, &point->Y);
|
||||
assert(field_len_out == field_len);
|
||||
buf[0] = form;
|
||||
} else {
|
||||
uint8_t y_buf[EC_MAX_BYTES];
|
||||
ec_felem_to_bytes(group, y_buf, &field_len_out, &point->Y);
|
||||
buf[0] = form + (y_buf[field_len_out - 1] & 1);
|
||||
}
|
||||
}
|
||||
|
||||
return output_len;
|
||||
}
|
||||
|
||||
int ec_point_from_uncompressed(const EC_GROUP *group, EC_AFFINE *out,
|
||||
const uint8_t *in, size_t len) {
|
||||
const size_t field_len = BN_num_bytes(&group->field);
|
||||
if (len != 1 + 2 * field_len || in[0] != POINT_CONVERSION_UNCOMPRESSED) {
|
||||
OPENSSL_PUT_ERROR(EC, EC_R_INVALID_ENCODING);
|
||||
return 0;
|
||||
}
|
||||
|
||||
EC_FELEM x, y;
|
||||
if (!ec_felem_from_bytes(group, &x, in + 1, field_len) ||
|
||||
!ec_felem_from_bytes(group, &y, in + 1 + field_len, field_len) ||
|
||||
!ec_point_set_affine_coordinates(group, out, &x, &y)) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
static int ec_GFp_simple_oct2point(const EC_GROUP *group, EC_POINT *point,
|
||||
const uint8_t *buf, size_t len,
|
||||
BN_CTX *ctx) {
|
||||
BN_CTX *new_ctx = NULL;
|
||||
int ret = 0, used_ctx = 0;
|
||||
|
||||
if (len == 0) {
|
||||
OPENSSL_PUT_ERROR(EC, EC_R_BUFFER_TOO_SMALL);
|
||||
goto err;
|
||||
return 0;
|
||||
}
|
||||
|
||||
point_conversion_form_t form = buf[0];
|
||||
const int y_bit = form & 1;
|
||||
form = form & ~1U;
|
||||
if ((form != POINT_CONVERSION_COMPRESSED &&
|
||||
form != POINT_CONVERSION_UNCOMPRESSED) ||
|
||||
(form == POINT_CONVERSION_UNCOMPRESSED && y_bit)) {
|
||||
OPENSSL_PUT_ERROR(EC, EC_R_INVALID_ENCODING);
|
||||
goto err;
|
||||
}
|
||||
|
||||
const size_t field_len = BN_num_bytes(&group->field);
|
||||
size_t enc_len = 1 /* type byte */ + field_len;
|
||||
if (form == POINT_CONVERSION_UNCOMPRESSED) {
|
||||
// Uncompressed points have a second coordinate.
|
||||
enc_len += field_len;
|
||||
EC_AFFINE affine;
|
||||
if (!ec_point_from_uncompressed(group, &affine, buf, len)) {
|
||||
// In the event of an error, defend against the caller not checking the
|
||||
// return value by setting a known safe value.
|
||||
ec_set_to_safe_point(group, &point->raw);
|
||||
return 0;
|
||||
}
|
||||
ec_affine_to_jacobian(group, &point->raw, &affine);
|
||||
return 1;
|
||||
}
|
||||
|
||||
if (len != enc_len) {
|
||||
const int y_bit = form & 1;
|
||||
const size_t field_len = BN_num_bytes(&group->field);
|
||||
form = form & ~1u;
|
||||
if (form != POINT_CONVERSION_COMPRESSED ||
|
||||
len != 1 /* type byte */ + field_len) {
|
||||
OPENSSL_PUT_ERROR(EC, EC_R_INVALID_ENCODING);
|
||||
goto err;
|
||||
return 0;
|
||||
}
|
||||
|
||||
// TODO(davidben): Integrate compressed coordinates with the lower-level EC
|
||||
// abstractions. This requires a way to compute square roots, which is tricky
|
||||
// for primes which are not 3 (mod 4), namely P-224 and custom curves. P-224's
|
||||
// prime is particularly inconvenient for compressed coordinates. See
|
||||
// https://cr.yp.to/papers/sqroot.pdf
|
||||
BN_CTX *new_ctx = NULL;
|
||||
if (ctx == NULL) {
|
||||
ctx = new_ctx = BN_CTX_new();
|
||||
if (ctx == NULL) {
|
||||
goto err;
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
int ret = 0;
|
||||
BN_CTX_start(ctx);
|
||||
used_ctx = 1;
|
||||
BIGNUM *x = BN_CTX_get(ctx);
|
||||
BIGNUM *y = BN_CTX_get(ctx);
|
||||
if (x == NULL || y == NULL) {
|
||||
goto err;
|
||||
}
|
||||
|
||||
if (!BN_bin2bn(buf + 1, field_len, x)) {
|
||||
if (x == NULL || !BN_bin2bn(buf + 1, field_len, x)) {
|
||||
goto err;
|
||||
}
|
||||
if (BN_ucmp(x, &group->field) >= 0) {
|
||||
@@ -182,30 +186,14 @@ static int ec_GFp_simple_oct2point(const EC_GROUP *group, EC_POINT *point,
|
||||
goto err;
|
||||
}
|
||||
|
||||
if (form == POINT_CONVERSION_COMPRESSED) {
|
||||
if (!EC_POINT_set_compressed_coordinates_GFp(group, point, x, y_bit, ctx)) {
|
||||
goto err;
|
||||
}
|
||||
} else {
|
||||
if (!BN_bin2bn(buf + 1 + field_len, field_len, y)) {
|
||||
goto err;
|
||||
}
|
||||
if (BN_ucmp(y, &group->field) >= 0) {
|
||||
OPENSSL_PUT_ERROR(EC, EC_R_INVALID_ENCODING);
|
||||
goto err;
|
||||
}
|
||||
|
||||
if (!EC_POINT_set_affine_coordinates_GFp(group, point, x, y, ctx)) {
|
||||
goto err;
|
||||
}
|
||||
if (!EC_POINT_set_compressed_coordinates_GFp(group, point, x, y_bit, ctx)) {
|
||||
goto err;
|
||||
}
|
||||
|
||||
ret = 1;
|
||||
|
||||
err:
|
||||
if (used_ctx) {
|
||||
BN_CTX_end(ctx);
|
||||
}
|
||||
BN_CTX_end(ctx);
|
||||
BN_CTX_free(new_ctx);
|
||||
return ret;
|
||||
}
|
||||
@@ -226,7 +214,11 @@ size_t EC_POINT_point2oct(const EC_GROUP *group, const EC_POINT *point,
|
||||
OPENSSL_PUT_ERROR(EC, EC_R_INCOMPATIBLE_OBJECTS);
|
||||
return 0;
|
||||
}
|
||||
return ec_GFp_simple_point2oct(group, &point->raw, form, buf, len);
|
||||
EC_AFFINE affine;
|
||||
if (!ec_jacobian_to_affine(group, &affine, &point->raw)) {
|
||||
return 0;
|
||||
}
|
||||
return ec_point_to_bytes(group, &affine, form, buf, len);
|
||||
}
|
||||
|
||||
int EC_POINT_set_compressed_coordinates_GFp(const EC_GROUP *group,
|
||||
|
||||
@@ -1154,16 +1154,6 @@ static void ec_GFp_nistp224_felem_sqr(const EC_GROUP *group, EC_FELEM *r,
|
||||
p224_felem_to_generic(r, felem);
|
||||
}
|
||||
|
||||
static int ec_GFp_nistp224_bignum_to_felem(const EC_GROUP *group, EC_FELEM *out,
|
||||
const BIGNUM *in) {
|
||||
return bn_copy_words(out->words, group->field.width, in);
|
||||
}
|
||||
|
||||
static int ec_GFp_nistp224_felem_to_bignum(const EC_GROUP *group, BIGNUM *out,
|
||||
const EC_FELEM *in) {
|
||||
return bn_set_words(out, in->words, group->field.width);
|
||||
}
|
||||
|
||||
DEFINE_METHOD_FUNCTION(EC_METHOD, EC_GFp_nistp224_method) {
|
||||
out->group_init = ec_GFp_simple_group_init;
|
||||
out->group_finish = ec_GFp_simple_group_finish;
|
||||
@@ -1177,10 +1167,11 @@ DEFINE_METHOD_FUNCTION(EC_METHOD, EC_GFp_nistp224_method) {
|
||||
out->mul_public = ec_GFp_nistp224_point_mul_public;
|
||||
out->felem_mul = ec_GFp_nistp224_felem_mul;
|
||||
out->felem_sqr = ec_GFp_nistp224_felem_sqr;
|
||||
out->bignum_to_felem = ec_GFp_nistp224_bignum_to_felem;
|
||||
out->felem_to_bignum = ec_GFp_nistp224_felem_to_bignum;
|
||||
out->scalar_inv_montgomery = ec_simple_scalar_inv_montgomery;
|
||||
out->scalar_inv_montgomery_vartime = ec_GFp_simple_mont_inv_mod_ord_vartime;
|
||||
out->felem_to_bytes = ec_GFp_simple_felem_to_bytes;
|
||||
out->felem_from_bytes = ec_GFp_simple_felem_from_bytes;
|
||||
out->scalar_inv0_montgomery = ec_simple_scalar_inv0_montgomery;
|
||||
out->scalar_to_montgomery_inv_vartime =
|
||||
ec_simple_scalar_to_montgomery_inv_vartime;
|
||||
out->cmp_x_coordinate = ec_GFp_simple_cmp_x_coordinate;
|
||||
}
|
||||
|
||||
|
||||
File diff suppressed because it is too large.
Load diff
@@ -119,86 +119,73 @@ static BN_ULONG is_not_zero(BN_ULONG in) {
|
||||
return in;
|
||||
}
|
||||
|
||||
// ecp_nistz256_mod_inverse_mont sets |r| to (|in| * 2^-256)^-1 * 2^256 mod p.
|
||||
// That is, |r| is the modular inverse of |in| for input and output in the
|
||||
// Montgomery domain.
|
||||
static void ecp_nistz256_mod_inverse_mont(BN_ULONG r[P256_LIMBS],
|
||||
const BN_ULONG in[P256_LIMBS]) {
|
||||
/* The poly is ffffffff 00000001 00000000 00000000 00000000 ffffffff ffffffff
|
||||
ffffffff
|
||||
We use FLT and used poly-2 as exponent */
|
||||
BN_ULONG p2[P256_LIMBS];
|
||||
BN_ULONG p4[P256_LIMBS];
|
||||
BN_ULONG p8[P256_LIMBS];
|
||||
BN_ULONG p16[P256_LIMBS];
|
||||
BN_ULONG p32[P256_LIMBS];
|
||||
BN_ULONG res[P256_LIMBS];
|
||||
int i;
|
||||
// ecp_nistz256_mod_inverse_sqr_mont sets |r| to (|in| * 2^-256)^-2 * 2^256 mod
|
||||
// p. That is, |r| is the modular inverse square of |in| for input and output in
|
||||
// the Montgomery domain.
|
||||
static void ecp_nistz256_mod_inverse_sqr_mont(BN_ULONG r[P256_LIMBS],
|
||||
const BN_ULONG in[P256_LIMBS]) {
|
||||
// This implements the addition chain described in
|
||||
// https://briansmith.org/ecc-inversion-addition-chains-01#p256_field_inversion
|
||||
BN_ULONG x2[P256_LIMBS], x3[P256_LIMBS], x6[P256_LIMBS], x12[P256_LIMBS],
|
||||
x15[P256_LIMBS], x30[P256_LIMBS], x32[P256_LIMBS];
|
||||
ecp_nistz256_sqr_mont(x2, in); // 2^2 - 2^1
|
||||
ecp_nistz256_mul_mont(x2, x2, in); // 2^2 - 2^0
|
||||
|
||||
ecp_nistz256_sqr_mont(res, in);
|
||||
ecp_nistz256_mul_mont(p2, res, in); // 3*p
|
||||
ecp_nistz256_sqr_mont(x3, x2); // 2^3 - 2^1
|
||||
ecp_nistz256_mul_mont(x3, x3, in); // 2^3 - 2^0
|
||||
|
||||
ecp_nistz256_sqr_mont(res, p2);
|
||||
ecp_nistz256_sqr_mont(res, res);
|
||||
ecp_nistz256_mul_mont(p4, res, p2); // f*p
|
||||
ecp_nistz256_sqr_mont(x6, x3);
|
||||
for (int i = 1; i < 3; i++) {
|
||||
ecp_nistz256_sqr_mont(x6, x6);
|
||||
} // 2^6 - 2^3
|
||||
ecp_nistz256_mul_mont(x6, x6, x3); // 2^6 - 2^0
|
||||
|
||||
ecp_nistz256_sqr_mont(res, p4);
|
||||
ecp_nistz256_sqr_mont(res, res);
|
||||
ecp_nistz256_sqr_mont(res, res);
|
||||
ecp_nistz256_sqr_mont(res, res);
|
||||
ecp_nistz256_mul_mont(p8, res, p4); // ff*p
|
||||
ecp_nistz256_sqr_mont(x12, x6);
|
||||
for (int i = 1; i < 6; i++) {
|
||||
ecp_nistz256_sqr_mont(x12, x12);
|
||||
} // 2^12 - 2^6
|
||||
ecp_nistz256_mul_mont(x12, x12, x6); // 2^12 - 2^0
|
||||
|
||||
ecp_nistz256_sqr_mont(res, p8);
|
||||
for (i = 0; i < 7; i++) {
|
||||
ecp_nistz256_sqr_mont(res, res);
|
||||
}
|
||||
ecp_nistz256_mul_mont(p16, res, p8); // ffff*p
|
||||
ecp_nistz256_sqr_mont(x15, x12);
|
||||
for (int i = 1; i < 3; i++) {
|
||||
ecp_nistz256_sqr_mont(x15, x15);
|
||||
} // 2^15 - 2^3
|
||||
ecp_nistz256_mul_mont(x15, x15, x3); // 2^15 - 2^0
|
||||
|
||||
ecp_nistz256_sqr_mont(res, p16);
|
||||
for (i = 0; i < 15; i++) {
|
||||
ecp_nistz256_sqr_mont(res, res);
|
||||
}
|
||||
ecp_nistz256_mul_mont(p32, res, p16); // ffffffff*p
|
||||
ecp_nistz256_sqr_mont(x30, x15);
|
||||
for (int i = 1; i < 15; i++) {
|
||||
ecp_nistz256_sqr_mont(x30, x30);
|
||||
} // 2^30 - 2^15
|
||||
ecp_nistz256_mul_mont(x30, x30, x15); // 2^30 - 2^0
|
||||
|
||||
ecp_nistz256_sqr_mont(res, p32);
|
||||
for (i = 0; i < 31; i++) {
|
||||
ecp_nistz256_sqr_mont(res, res);
|
||||
}
|
||||
ecp_nistz256_mul_mont(res, res, in);
|
||||
ecp_nistz256_sqr_mont(x32, x30);
|
||||
ecp_nistz256_sqr_mont(x32, x32); // 2^32 - 2^2
|
||||
ecp_nistz256_mul_mont(x32, x32, x2); // 2^32 - 2^0
|
||||
|
||||
for (i = 0; i < 32 * 4; i++) {
|
||||
ecp_nistz256_sqr_mont(res, res);
|
||||
}
|
||||
ecp_nistz256_mul_mont(res, res, p32);
|
||||
BN_ULONG ret[P256_LIMBS];
|
||||
ecp_nistz256_sqr_mont(ret, x32);
|
||||
for (int i = 1; i < 31 + 1; i++) {
|
||||
ecp_nistz256_sqr_mont(ret, ret);
|
||||
} // 2^64 - 2^32
|
||||
ecp_nistz256_mul_mont(ret, ret, in); // 2^64 - 2^32 + 2^0
|
||||
|
||||
for (i = 0; i < 32; i++) {
|
||||
ecp_nistz256_sqr_mont(res, res);
|
||||
}
|
||||
ecp_nistz256_mul_mont(res, res, p32);
|
||||
for (int i = 0; i < 96 + 32; i++) {
|
||||
ecp_nistz256_sqr_mont(ret, ret);
|
||||
} // 2^192 - 2^160 + 2^128
|
||||
ecp_nistz256_mul_mont(ret, ret, x32); // 2^192 - 2^160 + 2^128 + 2^32 - 2^0
|
||||
|
||||
for (i = 0; i < 16; i++) {
|
||||
ecp_nistz256_sqr_mont(res, res);
|
||||
}
|
||||
ecp_nistz256_mul_mont(res, res, p16);
|
||||
for (int i = 0; i < 32; i++) {
|
||||
ecp_nistz256_sqr_mont(ret, ret);
|
||||
} // 2^224 - 2^192 + 2^160 + 2^64 - 2^32
|
||||
ecp_nistz256_mul_mont(ret, ret, x32); // 2^224 - 2^192 + 2^160 + 2^64 - 2^0
|
||||
|
||||
for (i = 0; i < 8; i++) {
|
||||
ecp_nistz256_sqr_mont(res, res);
|
||||
}
|
||||
ecp_nistz256_mul_mont(res, res, p8);
|
||||
for (int i = 0; i < 30; i++) {
|
||||
ecp_nistz256_sqr_mont(ret, ret);
|
||||
} // 2^254 - 2^222 + 2^190 + 2^94 - 2^30
|
||||
ecp_nistz256_mul_mont(ret, ret, x30); // 2^254 - 2^222 + 2^190 + 2^94 - 2^0
|
||||
|
||||
ecp_nistz256_sqr_mont(res, res);
|
||||
ecp_nistz256_sqr_mont(res, res);
|
||||
ecp_nistz256_sqr_mont(res, res);
|
||||
ecp_nistz256_sqr_mont(res, res);
|
||||
ecp_nistz256_mul_mont(res, res, p4);
|
||||
|
||||
ecp_nistz256_sqr_mont(res, res);
|
||||
ecp_nistz256_sqr_mont(res, res);
|
||||
ecp_nistz256_mul_mont(res, res, p2);
|
||||
|
||||
ecp_nistz256_sqr_mont(res, res);
|
||||
ecp_nistz256_sqr_mont(res, res);
|
||||
ecp_nistz256_mul_mont(r, res, in);
|
||||
ecp_nistz256_sqr_mont(ret, ret);
|
||||
ecp_nistz256_sqr_mont(r, ret); // 2^256 - 2^224 + 2^192 + 2^96 - 2^2
|
||||
}
|
||||
|
||||
// r = p * p_scalar
|
||||
@@ -442,24 +429,17 @@ static int ecp_nistz256_get_affine(const EC_GROUP *group,
|
||||
}
|
||||
|
||||
BN_ULONG z_inv2[P256_LIMBS];
|
||||
BN_ULONG z_inv3[P256_LIMBS];
|
||||
assert(group->field.width == P256_LIMBS);
|
||||
ecp_nistz256_mod_inverse_mont(z_inv3, point->Z.words);
|
||||
ecp_nistz256_sqr_mont(z_inv2, z_inv3);
|
||||
|
||||
// Instead of using |ecp_nistz256_from_mont| to convert the |x| coordinate
|
||||
// and then calling |ecp_nistz256_from_mont| again to convert the |y|
|
||||
// coordinate below, convert the common factor |z_inv2| once now, saving one
|
||||
// reduction.
|
||||
ecp_nistz256_from_mont(z_inv2, z_inv2);
|
||||
ecp_nistz256_mod_inverse_sqr_mont(z_inv2, point->Z.words);
|
||||
|
||||
if (x != NULL) {
|
||||
ecp_nistz256_mul_mont(x->words, z_inv2, point->X.words);
|
||||
}
|
||||
|
||||
if (y != NULL) {
|
||||
ecp_nistz256_mul_mont(z_inv3, z_inv3, z_inv2);
|
||||
ecp_nistz256_mul_mont(y->words, z_inv3, point->Y.words);
|
||||
ecp_nistz256_sqr_mont(z_inv2, z_inv2); // z^-4
|
||||
ecp_nistz256_mul_mont(y->words, point->Y.words, point->Z.words); // y * z
|
||||
ecp_nistz256_mul_mont(y->words, y->words, z_inv2); // y * z^-3
|
||||
}
|
||||
|
||||
return 1;
|
||||
@@ -492,8 +472,8 @@ static void ecp_nistz256_dbl(const EC_GROUP *group, EC_RAW_POINT *r,
|
||||
OPENSSL_memcpy(r->Z.words, a.Z, P256_LIMBS * sizeof(BN_ULONG));
|
||||
}
|
||||
|
||||
static void ecp_nistz256_inv_mod_ord(const EC_GROUP *group, EC_SCALAR *out,
|
||||
const EC_SCALAR *in) {
|
||||
static void ecp_nistz256_inv0_mod_ord(const EC_GROUP *group, EC_SCALAR *out,
|
||||
const EC_SCALAR *in) {
|
||||
// table[i] stores a power of |in| corresponding to the matching enum value.
|
||||
enum {
|
||||
// The following indices specify the power in binary.
|
||||
@@ -573,12 +553,12 @@ static void ecp_nistz256_inv_mod_ord(const EC_GROUP *group, EC_SCALAR *out,
|
||||
}
|
||||
}
|
||||
|
||||
static int ecp_nistz256_mont_inv_mod_ord_vartime(const EC_GROUP *group,
|
||||
static int ecp_nistz256_scalar_to_montgomery_inv_vartime(const EC_GROUP *group,
|
||||
EC_SCALAR *out,
|
||||
const EC_SCALAR *in) {
|
||||
if ((OPENSSL_ia32cap_get()[1] & (1 << 28)) == 0) {
|
||||
// No AVX support; fallback to generic code.
|
||||
return ec_GFp_simple_mont_inv_mod_ord_vartime(group, out, in);
|
||||
return ec_simple_scalar_to_montgomery_inv_vartime(group, out, in);
|
||||
}
|
||||
|
||||
assert(group->order.width == P256_LIMBS);
|
||||
@@ -642,10 +622,11 @@ DEFINE_METHOD_FUNCTION(EC_METHOD, EC_GFp_nistz256_method) {
|
||||
out->mul_public = ecp_nistz256_points_mul_public;
|
||||
out->felem_mul = ec_GFp_mont_felem_mul;
|
||||
out->felem_sqr = ec_GFp_mont_felem_sqr;
|
||||
out->bignum_to_felem = ec_GFp_mont_bignum_to_felem;
|
||||
out->felem_to_bignum = ec_GFp_mont_felem_to_bignum;
|
||||
out->scalar_inv_montgomery = ecp_nistz256_inv_mod_ord;
|
||||
out->scalar_inv_montgomery_vartime = ecp_nistz256_mont_inv_mod_ord_vartime;
|
||||
out->felem_to_bytes = ec_GFp_mont_felem_to_bytes;
|
||||
out->felem_from_bytes = ec_GFp_mont_felem_from_bytes;
|
||||
out->scalar_inv0_montgomery = ecp_nistz256_inv0_mod_ord;
|
||||
out->scalar_to_montgomery_inv_vartime =
|
||||
ecp_nistz256_scalar_to_montgomery_inv_vartime;
|
||||
out->cmp_x_coordinate = ecp_nistz256_cmp_x_coordinate;
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,736 @@
|
||||
/* Copyright (c) 2020, Google Inc.
|
||||
*
|
||||
* Permission to use, copy, modify, and/or distribute this software for any
|
||||
* purpose with or without fee is hereby granted, provided that the above
|
||||
* copyright notice and this permission notice appear in all copies.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
|
||||
* WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
|
||||
* MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
|
||||
* SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
|
||||
* WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION
|
||||
* OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
|
||||
* CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. */
|
||||
|
||||
// An implementation of the NIST P-256 elliptic curve point multiplication.
|
||||
// 256-bit Montgomery form for 64 and 32-bit. Field operations are generated by
|
||||
// Fiat, which lives in //third_party/fiat.
|
||||
|
||||
#include <CCryptoBoringSSL_base.h>
|
||||
|
||||
#include <CCryptoBoringSSL_bn.h>
|
||||
#include <CCryptoBoringSSL_ec.h>
|
||||
#include <CCryptoBoringSSL_err.h>
|
||||
#include <CCryptoBoringSSL_mem.h>
|
||||
#include <CCryptoBoringSSL_type_check.h>
|
||||
|
||||
#include <assert.h>
|
||||
#include <string.h>
|
||||
|
||||
#include "../../internal.h"
|
||||
#include "../delocate.h"
|
||||
#include "./internal.h"
|
||||
|
||||
|
||||
// MSVC does not implement uint128_t, and crashes with intrinsics
|
||||
#if defined(BORINGSSL_HAS_UINT128)
|
||||
#define BORINGSSL_NISTP256_64BIT 1
|
||||
#include "../../../third_party/fiat/p256_64.h"
|
||||
#else
|
||||
#include "../../../third_party/fiat/p256_32.h"
|
||||
#endif
|
||||
|
||||
|
||||
// utility functions, handwritten
|
||||
|
||||
#if defined(BORINGSSL_NISTP256_64BIT)
|
||||
#define FIAT_P256_NLIMBS 4
|
||||
typedef uint64_t fiat_p256_limb_t;
|
||||
typedef uint64_t fiat_p256_felem[FIAT_P256_NLIMBS];
|
||||
static const fiat_p256_felem fiat_p256_one = {0x1, 0xffffffff00000000,
|
||||
0xffffffffffffffff, 0xfffffffe};
|
||||
#else // 64BIT; else 32BIT
|
||||
#define FIAT_P256_NLIMBS 8
|
||||
typedef uint32_t fiat_p256_limb_t;
|
||||
typedef uint32_t fiat_p256_felem[FIAT_P256_NLIMBS];
|
||||
static const fiat_p256_felem fiat_p256_one = {
|
||||
0x1, 0x0, 0x0, 0xffffffff, 0xffffffff, 0xffffffff, 0xfffffffe, 0x0};
|
||||
#endif // 64BIT
|
||||
|
||||
|
||||
static fiat_p256_limb_t fiat_p256_nz(
|
||||
const fiat_p256_limb_t in1[FIAT_P256_NLIMBS]) {
|
||||
fiat_p256_limb_t ret;
|
||||
fiat_p256_nonzero(&ret, in1);
|
||||
return ret;
|
||||
}
|
||||
|
||||
static void fiat_p256_copy(fiat_p256_limb_t out[FIAT_P256_NLIMBS],
|
||||
const fiat_p256_limb_t in1[FIAT_P256_NLIMBS]) {
|
||||
for (int i = 0; i < FIAT_P256_NLIMBS; i++) {
|
||||
out[i] = in1[i];
|
||||
}
|
||||
}
|
||||
|
||||
static void fiat_p256_cmovznz(fiat_p256_limb_t out[FIAT_P256_NLIMBS],
|
||||
fiat_p256_limb_t t,
|
||||
const fiat_p256_limb_t z[FIAT_P256_NLIMBS],
|
||||
const fiat_p256_limb_t nz[FIAT_P256_NLIMBS]) {
|
||||
fiat_p256_selectznz(out, !!t, z, nz);
|
||||
}
|
||||
|
||||
static void fiat_p256_from_generic(fiat_p256_felem out, const EC_FELEM *in) {
|
||||
fiat_p256_from_bytes(out, in->bytes);
|
||||
}
|
||||
|
||||
static void fiat_p256_to_generic(EC_FELEM *out, const fiat_p256_felem in) {
|
||||
// This works because 256 is a multiple of 64, so there are no excess bytes to
|
||||
// zero when rounding up to |BN_ULONG|s.
|
||||
OPENSSL_STATIC_ASSERT(
|
||||
256 / 8 == sizeof(BN_ULONG) * ((256 + BN_BITS2 - 1) / BN_BITS2),
|
||||
"fiat_p256_to_bytes leaves bytes uninitialized");
|
||||
fiat_p256_to_bytes(out->bytes, in);
|
||||
}
|
||||
|
||||
// fiat_p256_inv_square calculates |out| = |in|^{-2}
|
||||
//
|
||||
// Based on Fermat's Little Theorem:
|
||||
// a^p = a (mod p)
|
||||
// a^{p-1} = 1 (mod p)
|
||||
// a^{p-3} = a^{-2} (mod p)
|
||||
static void fiat_p256_inv_square(fiat_p256_felem out,
|
||||
const fiat_p256_felem in) {
|
||||
// This implements the addition chain described in
|
||||
// https://briansmith.org/ecc-inversion-addition-chains-01#p256_field_inversion
|
||||
fiat_p256_felem x2, x3, x6, x12, x15, x30, x32;
|
||||
fiat_p256_square(x2, in); // 2^2 - 2^1
|
||||
fiat_p256_mul(x2, x2, in); // 2^2 - 2^0
|
||||
|
||||
fiat_p256_square(x3, x2); // 2^3 - 2^1
|
||||
fiat_p256_mul(x3, x3, in); // 2^3 - 2^0
|
||||
|
||||
fiat_p256_square(x6, x3);
|
||||
for (int i = 1; i < 3; i++) {
|
||||
fiat_p256_square(x6, x6);
|
||||
} // 2^6 - 2^3
|
||||
fiat_p256_mul(x6, x6, x3); // 2^6 - 2^0
|
||||
|
||||
fiat_p256_square(x12, x6);
|
||||
for (int i = 1; i < 6; i++) {
|
||||
fiat_p256_square(x12, x12);
|
||||
} // 2^12 - 2^6
|
||||
fiat_p256_mul(x12, x12, x6); // 2^12 - 2^0
|
||||
|
||||
fiat_p256_square(x15, x12);
|
||||
for (int i = 1; i < 3; i++) {
|
||||
fiat_p256_square(x15, x15);
|
||||
} // 2^15 - 2^3
|
||||
fiat_p256_mul(x15, x15, x3); // 2^15 - 2^0
|
||||
|
||||
fiat_p256_square(x30, x15);
|
||||
for (int i = 1; i < 15; i++) {
|
||||
fiat_p256_square(x30, x30);
|
||||
} // 2^30 - 2^15
|
||||
fiat_p256_mul(x30, x30, x15); // 2^30 - 2^0
|
||||
|
||||
fiat_p256_square(x32, x30);
|
||||
fiat_p256_square(x32, x32); // 2^32 - 2^2
|
||||
fiat_p256_mul(x32, x32, x2); // 2^32 - 2^0
|
||||
|
||||
fiat_p256_felem ret;
|
||||
fiat_p256_square(ret, x32);
|
||||
for (int i = 1; i < 31 + 1; i++) {
|
||||
fiat_p256_square(ret, ret);
|
||||
} // 2^64 - 2^32
|
||||
fiat_p256_mul(ret, ret, in); // 2^64 - 2^32 + 2^0
|
||||
|
||||
for (int i = 0; i < 96 + 32; i++) {
|
||||
fiat_p256_square(ret, ret);
|
||||
} // 2^192 - 2^160 + 2^128
|
||||
fiat_p256_mul(ret, ret, x32); // 2^192 - 2^160 + 2^128 + 2^32 - 2^0
|
||||
|
||||
for (int i = 0; i < 32; i++) {
|
||||
fiat_p256_square(ret, ret);
|
||||
} // 2^224 - 2^192 + 2^160 + 2^64 - 2^32
|
||||
fiat_p256_mul(ret, ret, x32); // 2^224 - 2^192 + 2^160 + 2^64 - 2^0
|
||||
|
||||
for (int i = 0; i < 30; i++) {
|
||||
fiat_p256_square(ret, ret);
|
||||
} // 2^254 - 2^222 + 2^190 + 2^94 - 2^30
|
||||
fiat_p256_mul(ret, ret, x30); // 2^254 - 2^222 + 2^190 + 2^94 - 2^0
|
||||
|
||||
fiat_p256_square(ret, ret);
|
||||
fiat_p256_square(out, ret); // 2^256 - 2^224 + 2^192 + 2^96 - 2^2
|
||||
}
|
||||
|
||||
// Group operations
|
||||
// ----------------
|
||||
//
|
||||
// Building on top of the field operations we have the operations on the
|
||||
// elliptic curve group itself. Points on the curve are represented in Jacobian
|
||||
// coordinates.
|
||||
//
|
||||
// Both operations were transcribed to Coq and proven to correspond to naive
|
||||
// implementations using Affine coordinates, for all suitable fields. In the
|
||||
// Coq proofs, issues of constant-time execution and memory layout (aliasing)
|
||||
// conventions were not considered. Specification of affine coordinates:
|
||||
// <https://github.com/mit-plv/fiat-crypto/blob/79f8b5f39ed609339f0233098dee1a3c4e6b3080/src/Spec/WeierstrassCurve.v#L28>
|
||||
// As a sanity check, a proof that these points form a commutative group:
|
||||
// <https://github.com/mit-plv/fiat-crypto/blob/79f8b5f39ed609339f0233098dee1a3c4e6b3080/src/Curves/Weierstrass/AffineProofs.v#L33>
|
||||
|
||||
// fiat_p256_point_double calculates 2*(x_in, y_in, z_in)
|
||||
//
|
||||
// The method is taken from:
|
||||
// http://hyperelliptic.org/EFD/g1p/auto-shortw-jacobian-3.html#doubling-dbl-2001-b
|
||||
//
|
||||
// Coq transcription and correctness proof:
|
||||
// <https://github.com/mit-plv/fiat-crypto/blob/79f8b5f39ed609339f0233098dee1a3c4e6b3080/src/Curves/Weierstrass/Jacobian.v#L93>
|
||||
// <https://github.com/mit-plv/fiat-crypto/blob/79f8b5f39ed609339f0233098dee1a3c4e6b3080/src/Curves/Weierstrass/Jacobian.v#L201>
|
||||
//
|
||||
// Outputs can equal corresponding inputs, i.e., x_out == x_in is allowed.
|
||||
// while x_out == y_in is not (maybe this works, but it's not tested).
|
||||
static void fiat_p256_point_double(fiat_p256_felem x_out, fiat_p256_felem y_out,
|
||||
fiat_p256_felem z_out,
|
||||
const fiat_p256_felem x_in,
|
||||
const fiat_p256_felem y_in,
|
||||
const fiat_p256_felem z_in) {
|
||||
fiat_p256_felem delta, gamma, beta, ftmp, ftmp2, tmptmp, alpha, fourbeta;
|
||||
// delta = z^2
|
||||
fiat_p256_square(delta, z_in);
|
||||
// gamma = y^2
|
||||
fiat_p256_square(gamma, y_in);
|
||||
// beta = x*gamma
|
||||
fiat_p256_mul(beta, x_in, gamma);
|
||||
|
||||
// alpha = 3*(x-delta)*(x+delta)
|
||||
fiat_p256_sub(ftmp, x_in, delta);
|
||||
fiat_p256_add(ftmp2, x_in, delta);
|
||||
|
||||
fiat_p256_add(tmptmp, ftmp2, ftmp2);
|
||||
fiat_p256_add(ftmp2, ftmp2, tmptmp);
|
||||
fiat_p256_mul(alpha, ftmp, ftmp2);
|
||||
|
||||
// x' = alpha^2 - 8*beta
|
||||
fiat_p256_square(x_out, alpha);
|
||||
fiat_p256_add(fourbeta, beta, beta);
|
||||
fiat_p256_add(fourbeta, fourbeta, fourbeta);
|
||||
fiat_p256_add(tmptmp, fourbeta, fourbeta);
|
||||
fiat_p256_sub(x_out, x_out, tmptmp);
|
||||
|
||||
// z' = (y + z)^2 - gamma - delta
|
||||
fiat_p256_add(delta, gamma, delta);
|
||||
fiat_p256_add(ftmp, y_in, z_in);
|
||||
fiat_p256_square(z_out, ftmp);
|
||||
fiat_p256_sub(z_out, z_out, delta);
|
||||
|
||||
// y' = alpha*(4*beta - x') - 8*gamma^2
|
||||
fiat_p256_sub(y_out, fourbeta, x_out);
|
||||
fiat_p256_add(gamma, gamma, gamma);
|
||||
fiat_p256_square(gamma, gamma);
|
||||
fiat_p256_mul(y_out, alpha, y_out);
|
||||
fiat_p256_add(gamma, gamma, gamma);
|
||||
fiat_p256_sub(y_out, y_out, gamma);
|
||||
}
|
||||
|
||||
// fiat_p256_point_add calculates (x1, y1, z1) + (x2, y2, z2)
|
||||
//
|
||||
// The method is taken from:
|
||||
// http://hyperelliptic.org/EFD/g1p/auto-shortw-jacobian-3.html#addition-add-2007-bl,
|
||||
// adapted for mixed addition (z2 = 1, or z2 = 0 for the point at infinity).
|
||||
//
|
||||
// Coq transcription and correctness proof:
|
||||
// <https://github.com/mit-plv/fiat-crypto/blob/79f8b5f39ed609339f0233098dee1a3c4e6b3080/src/Curves/Weierstrass/Jacobian.v#L135>
|
||||
// <https://github.com/mit-plv/fiat-crypto/blob/79f8b5f39ed609339f0233098dee1a3c4e6b3080/src/Curves/Weierstrass/Jacobian.v#L205>
|
||||
//
|
||||
// This function includes a branch for checking whether the two input points
|
||||
// are equal, (while not equal to the point at infinity). This case never
|
||||
// happens during single point multiplication, so there is no timing leak for
|
||||
// ECDH or ECDSA signing.
|
||||
static void fiat_p256_point_add(fiat_p256_felem x3, fiat_p256_felem y3,
|
||||
fiat_p256_felem z3, const fiat_p256_felem x1,
|
||||
const fiat_p256_felem y1,
|
||||
const fiat_p256_felem z1, const int mixed,
|
||||
const fiat_p256_felem x2,
|
||||
const fiat_p256_felem y2,
|
||||
const fiat_p256_felem z2) {
|
||||
fiat_p256_felem x_out, y_out, z_out;
|
||||
fiat_p256_limb_t z1nz = fiat_p256_nz(z1);
|
||||
fiat_p256_limb_t z2nz = fiat_p256_nz(z2);
|
||||
|
||||
// z1z1 = z1z1 = z1**2
|
||||
fiat_p256_felem z1z1;
|
||||
fiat_p256_square(z1z1, z1);
|
||||
|
||||
fiat_p256_felem u1, s1, two_z1z2;
|
||||
if (!mixed) {
|
||||
// z2z2 = z2**2
|
||||
fiat_p256_felem z2z2;
|
||||
fiat_p256_square(z2z2, z2);
|
||||
|
||||
// u1 = x1*z2z2
|
||||
fiat_p256_mul(u1, x1, z2z2);
|
||||
|
||||
// two_z1z2 = (z1 + z2)**2 - (z1z1 + z2z2) = 2z1z2
|
||||
fiat_p256_add(two_z1z2, z1, z2);
|
||||
fiat_p256_square(two_z1z2, two_z1z2);
|
||||
fiat_p256_sub(two_z1z2, two_z1z2, z1z1);
|
||||
fiat_p256_sub(two_z1z2, two_z1z2, z2z2);
|
||||
|
||||
// s1 = y1 * z2**3
|
||||
fiat_p256_mul(s1, z2, z2z2);
|
||||
fiat_p256_mul(s1, s1, y1);
|
||||
} else {
|
||||
// We'll assume z2 = 1 (special case z2 = 0 is handled later).
|
||||
|
||||
// u1 = x1*z2z2
|
||||
fiat_p256_copy(u1, x1);
|
||||
// two_z1z2 = 2z1z2
|
||||
fiat_p256_add(two_z1z2, z1, z1);
|
||||
// s1 = y1 * z2**3
|
||||
fiat_p256_copy(s1, y1);
|
||||
}
|
||||
|
||||
// u2 = x2*z1z1
|
||||
fiat_p256_felem u2;
|
||||
fiat_p256_mul(u2, x2, z1z1);
|
||||
|
||||
// h = u2 - u1
|
||||
fiat_p256_felem h;
|
||||
fiat_p256_sub(h, u2, u1);
|
||||
|
||||
fiat_p256_limb_t xneq = fiat_p256_nz(h);
|
||||
|
||||
// z_out = two_z1z2 * h
|
||||
fiat_p256_mul(z_out, h, two_z1z2);
|
||||
|
||||
// z1z1z1 = z1 * z1z1
|
||||
fiat_p256_felem z1z1z1;
|
||||
fiat_p256_mul(z1z1z1, z1, z1z1);
|
||||
|
||||
// s2 = y2 * z1**3
|
||||
fiat_p256_felem s2;
|
||||
fiat_p256_mul(s2, y2, z1z1z1);
|
||||
|
||||
// r = (s2 - s1)*2
|
||||
fiat_p256_felem r;
|
||||
fiat_p256_sub(r, s2, s1);
|
||||
fiat_p256_add(r, r, r);
|
||||
|
||||
fiat_p256_limb_t yneq = fiat_p256_nz(r);
|
||||
|
||||
fiat_p256_limb_t is_nontrivial_double = constant_time_is_zero_w(xneq | yneq) &
|
||||
~constant_time_is_zero_w(z1nz) &
|
||||
~constant_time_is_zero_w(z2nz);
|
||||
if (is_nontrivial_double) {
|
||||
fiat_p256_point_double(x3, y3, z3, x1, y1, z1);
|
||||
return;
|
||||
}
|
||||
|
||||
// I = (2h)**2
|
||||
fiat_p256_felem i;
|
||||
fiat_p256_add(i, h, h);
|
||||
fiat_p256_square(i, i);
|
||||
|
||||
// J = h * I
|
||||
fiat_p256_felem j;
|
||||
fiat_p256_mul(j, h, i);
|
||||
|
||||
// V = U1 * I
|
||||
fiat_p256_felem v;
|
||||
fiat_p256_mul(v, u1, i);
|
||||
|
||||
// x_out = r**2 - J - 2V
|
||||
fiat_p256_square(x_out, r);
|
||||
fiat_p256_sub(x_out, x_out, j);
|
||||
fiat_p256_sub(x_out, x_out, v);
|
||||
fiat_p256_sub(x_out, x_out, v);
|
||||
|
||||
// y_out = r(V-x_out) - 2 * s1 * J
|
||||
fiat_p256_sub(y_out, v, x_out);
|
||||
fiat_p256_mul(y_out, y_out, r);
|
||||
fiat_p256_felem s1j;
|
||||
fiat_p256_mul(s1j, s1, j);
|
||||
fiat_p256_sub(y_out, y_out, s1j);
|
||||
fiat_p256_sub(y_out, y_out, s1j);
|
||||
|
||||
fiat_p256_cmovznz(x_out, z1nz, x2, x_out);
|
||||
fiat_p256_cmovznz(x3, z2nz, x1, x_out);
|
||||
fiat_p256_cmovznz(y_out, z1nz, y2, y_out);
|
||||
fiat_p256_cmovznz(y3, z2nz, y1, y_out);
|
||||
fiat_p256_cmovznz(z_out, z1nz, z2, z_out);
|
||||
fiat_p256_cmovznz(z3, z2nz, z1, z_out);
|
||||
}
|
||||
|
||||
#include "./p256_table.h"
|
||||
|
||||
// fiat_p256_select_point_affine selects the |idx-1|th point from a
|
||||
// precomputation table and copies it to out. If |idx| is zero, the output is
|
||||
// the point at infinity.
|
||||
static void fiat_p256_select_point_affine(
|
||||
const fiat_p256_limb_t idx, size_t size,
|
||||
const fiat_p256_felem pre_comp[/*size*/][2], fiat_p256_felem out[3]) {
|
||||
OPENSSL_memset(out, 0, sizeof(fiat_p256_felem) * 3);
|
||||
for (size_t i = 0; i < size; i++) {
|
||||
fiat_p256_limb_t mismatch = i ^ (idx - 1);
|
||||
fiat_p256_cmovznz(out[0], mismatch, pre_comp[i][0], out[0]);
|
||||
fiat_p256_cmovznz(out[1], mismatch, pre_comp[i][1], out[1]);
|
||||
}
|
||||
fiat_p256_cmovznz(out[2], idx, out[2], fiat_p256_one);
|
||||
}
|
||||
|
||||
// fiat_p256_select_point selects the |idx|th point from a precomputation table
|
||||
// and copies it to out.
|
||||
static void fiat_p256_select_point(const fiat_p256_limb_t idx, size_t size,
|
||||
const fiat_p256_felem pre_comp[/*size*/][3],
|
||||
fiat_p256_felem out[3]) {
|
||||
OPENSSL_memset(out, 0, sizeof(fiat_p256_felem) * 3);
|
||||
for (size_t i = 0; i < size; i++) {
|
||||
fiat_p256_limb_t mismatch = i ^ idx;
|
||||
fiat_p256_cmovznz(out[0], mismatch, pre_comp[i][0], out[0]);
|
||||
fiat_p256_cmovznz(out[1], mismatch, pre_comp[i][1], out[1]);
|
||||
fiat_p256_cmovznz(out[2], mismatch, pre_comp[i][2], out[2]);
|
||||
}
|
||||
}
|
||||
|
||||
// fiat_p256_get_bit returns the |i|th bit in |in|
|
||||
static char fiat_p256_get_bit(const uint8_t *in, int i) {
|
||||
if (i < 0 || i >= 256) {
|
||||
return 0;
|
||||
}
|
||||
return (in[i >> 3] >> (i & 7)) & 1;
|
||||
}
|
||||
|
||||
// OPENSSL EC_METHOD FUNCTIONS
|
||||
|
||||
// Takes the Jacobian coordinates (X, Y, Z) of a point and returns (X', Y') =
|
||||
// (X/Z^2, Y/Z^3).
|
||||
static int ec_GFp_nistp256_point_get_affine_coordinates(
|
||||
const EC_GROUP *group, const EC_RAW_POINT *point, EC_FELEM *x_out,
|
||||
EC_FELEM *y_out) {
|
||||
if (ec_GFp_simple_is_at_infinity(group, point)) {
|
||||
OPENSSL_PUT_ERROR(EC, EC_R_POINT_AT_INFINITY);
|
||||
return 0;
|
||||
}
|
||||
|
||||
fiat_p256_felem z1, z2;
|
||||
fiat_p256_from_generic(z1, &point->Z);
|
||||
fiat_p256_inv_square(z2, z1);
|
||||
|
||||
if (x_out != NULL) {
|
||||
fiat_p256_felem x;
|
||||
fiat_p256_from_generic(x, &point->X);
|
||||
fiat_p256_mul(x, x, z2);
|
||||
fiat_p256_to_generic(x_out, x);
|
||||
}
|
||||
|
||||
if (y_out != NULL) {
|
||||
fiat_p256_felem y;
|
||||
fiat_p256_from_generic(y, &point->Y);
|
||||
fiat_p256_square(z2, z2); // z^-4
|
||||
fiat_p256_mul(y, y, z1); // y * z
|
||||
fiat_p256_mul(y, y, z2); // y * z^-3
|
||||
fiat_p256_to_generic(y_out, y);
|
||||
}
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
static void ec_GFp_nistp256_add(const EC_GROUP *group, EC_RAW_POINT *r,
|
||||
const EC_RAW_POINT *a, const EC_RAW_POINT *b) {
|
||||
fiat_p256_felem x1, y1, z1, x2, y2, z2;
|
||||
fiat_p256_from_generic(x1, &a->X);
|
||||
fiat_p256_from_generic(y1, &a->Y);
|
||||
fiat_p256_from_generic(z1, &a->Z);
|
||||
fiat_p256_from_generic(x2, &b->X);
|
||||
fiat_p256_from_generic(y2, &b->Y);
|
||||
fiat_p256_from_generic(z2, &b->Z);
|
||||
fiat_p256_point_add(x1, y1, z1, x1, y1, z1, 0 /* both Jacobian */, x2, y2,
|
||||
z2);
|
||||
fiat_p256_to_generic(&r->X, x1);
|
||||
fiat_p256_to_generic(&r->Y, y1);
|
||||
fiat_p256_to_generic(&r->Z, z1);
|
||||
}
|
||||
|
||||
static void ec_GFp_nistp256_dbl(const EC_GROUP *group, EC_RAW_POINT *r,
|
||||
const EC_RAW_POINT *a) {
|
||||
fiat_p256_felem x, y, z;
|
||||
fiat_p256_from_generic(x, &a->X);
|
||||
fiat_p256_from_generic(y, &a->Y);
|
||||
fiat_p256_from_generic(z, &a->Z);
|
||||
fiat_p256_point_double(x, y, z, x, y, z);
|
||||
fiat_p256_to_generic(&r->X, x);
|
||||
fiat_p256_to_generic(&r->Y, y);
|
||||
fiat_p256_to_generic(&r->Z, z);
|
||||
}
|
||||
|
||||
static void ec_GFp_nistp256_point_mul(const EC_GROUP *group, EC_RAW_POINT *r,
|
||||
const EC_RAW_POINT *p,
|
||||
const EC_SCALAR *scalar) {
|
||||
fiat_p256_felem p_pre_comp[17][3];
|
||||
OPENSSL_memset(&p_pre_comp, 0, sizeof(p_pre_comp));
|
||||
// Precompute multiples.
|
||||
fiat_p256_from_generic(p_pre_comp[1][0], &p->X);
|
||||
fiat_p256_from_generic(p_pre_comp[1][1], &p->Y);
|
||||
fiat_p256_from_generic(p_pre_comp[1][2], &p->Z);
|
||||
for (size_t j = 2; j <= 16; ++j) {
|
||||
if (j & 1) {
|
||||
fiat_p256_point_add(p_pre_comp[j][0], p_pre_comp[j][1], p_pre_comp[j][2],
|
||||
p_pre_comp[1][0], p_pre_comp[1][1], p_pre_comp[1][2],
|
||||
0, p_pre_comp[j - 1][0], p_pre_comp[j - 1][1],
|
||||
p_pre_comp[j - 1][2]);
|
||||
} else {
|
||||
fiat_p256_point_double(p_pre_comp[j][0], p_pre_comp[j][1],
|
||||
p_pre_comp[j][2], p_pre_comp[j / 2][0],
|
||||
p_pre_comp[j / 2][1], p_pre_comp[j / 2][2]);
|
||||
}
|
||||
}
|
||||
|
||||
// Set nq to the point at infinity.
|
||||
fiat_p256_felem nq[3] = {{0}, {0}, {0}}, ftmp, tmp[3];
|
||||
|
||||
// Loop over |scalar| msb-to-lsb, incorporating |p_pre_comp| every 5th round.
|
||||
int skip = 1; // Save two point operations in the first round.
|
||||
for (size_t i = 255; i < 256; i--) {
|
||||
// double
|
||||
if (!skip) {
|
||||
fiat_p256_point_double(nq[0], nq[1], nq[2], nq[0], nq[1], nq[2]);
|
||||
}
|
||||
|
||||
// do other additions every 5 doublings
|
||||
if (i % 5 == 0) {
|
||||
uint64_t bits = fiat_p256_get_bit(scalar->bytes, i + 4) << 5;
|
||||
bits |= fiat_p256_get_bit(scalar->bytes, i + 3) << 4;
|
||||
bits |= fiat_p256_get_bit(scalar->bytes, i + 2) << 3;
|
||||
bits |= fiat_p256_get_bit(scalar->bytes, i + 1) << 2;
|
||||
bits |= fiat_p256_get_bit(scalar->bytes, i) << 1;
|
||||
bits |= fiat_p256_get_bit(scalar->bytes, i - 1);
|
||||
uint8_t sign, digit;
|
||||
ec_GFp_nistp_recode_scalar_bits(&sign, &digit, bits);
|
||||
|
||||
// select the point to add or subtract, in constant time.
|
||||
fiat_p256_select_point(digit, 17, (const fiat_p256_felem(*)[3])p_pre_comp,
|
||||
tmp);
|
||||
fiat_p256_opp(ftmp, tmp[1]); // (X, -Y, Z) is the negative point.
|
||||
fiat_p256_cmovznz(tmp[1], sign, tmp[1], ftmp);
|
||||
|
||||
if (!skip) {
|
||||
fiat_p256_point_add(nq[0], nq[1], nq[2], nq[0], nq[1], nq[2],
|
||||
0 /* mixed */, tmp[0], tmp[1], tmp[2]);
|
||||
} else {
|
||||
fiat_p256_copy(nq[0], tmp[0]);
|
||||
fiat_p256_copy(nq[1], tmp[1]);
|
||||
fiat_p256_copy(nq[2], tmp[2]);
|
||||
skip = 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fiat_p256_to_generic(&r->X, nq[0]);
|
||||
fiat_p256_to_generic(&r->Y, nq[1]);
|
||||
fiat_p256_to_generic(&r->Z, nq[2]);
|
||||
}
|
||||
|
||||
static void ec_GFp_nistp256_point_mul_base(const EC_GROUP *group,
|
||||
EC_RAW_POINT *r,
|
||||
const EC_SCALAR *scalar) {
|
||||
// Set nq to the point at infinity.
|
||||
fiat_p256_felem nq[3] = {{0}, {0}, {0}}, tmp[3];
|
||||
|
||||
int skip = 1; // Save two point operations in the first round.
|
||||
for (size_t i = 31; i < 32; i--) {
|
||||
if (!skip) {
|
||||
fiat_p256_point_double(nq[0], nq[1], nq[2], nq[0], nq[1], nq[2]);
|
||||
}
|
||||
|
||||
// First, look 32 bits upwards.
|
||||
uint64_t bits = fiat_p256_get_bit(scalar->bytes, i + 224) << 3;
|
||||
bits |= fiat_p256_get_bit(scalar->bytes, i + 160) << 2;
|
||||
bits |= fiat_p256_get_bit(scalar->bytes, i + 96) << 1;
|
||||
bits |= fiat_p256_get_bit(scalar->bytes, i + 32);
|
||||
// Select the point to add, in constant time.
|
||||
fiat_p256_select_point_affine(bits, 15, fiat_p256_g_pre_comp[1], tmp);
|
||||
|
||||
if (!skip) {
|
||||
fiat_p256_point_add(nq[0], nq[1], nq[2], nq[0], nq[1], nq[2],
|
||||
1 /* mixed */, tmp[0], tmp[1], tmp[2]);
|
||||
} else {
|
||||
fiat_p256_copy(nq[0], tmp[0]);
|
||||
fiat_p256_copy(nq[1], tmp[1]);
|
||||
fiat_p256_copy(nq[2], tmp[2]);
|
||||
skip = 0;
|
||||
}
|
||||
|
||||
// Second, look at the current position.
|
||||
bits = fiat_p256_get_bit(scalar->bytes, i + 192) << 3;
|
||||
bits |= fiat_p256_get_bit(scalar->bytes, i + 128) << 2;
|
||||
bits |= fiat_p256_get_bit(scalar->bytes, i + 64) << 1;
|
||||
bits |= fiat_p256_get_bit(scalar->bytes, i);
|
||||
// Select the point to add, in constant time.
|
||||
fiat_p256_select_point_affine(bits, 15, fiat_p256_g_pre_comp[0], tmp);
|
||||
fiat_p256_point_add(nq[0], nq[1], nq[2], nq[0], nq[1], nq[2], 1 /* mixed */,
|
||||
tmp[0], tmp[1], tmp[2]);
|
||||
}
|
||||
|
||||
fiat_p256_to_generic(&r->X, nq[0]);
|
||||
fiat_p256_to_generic(&r->Y, nq[1]);
|
||||
fiat_p256_to_generic(&r->Z, nq[2]);
|
||||
}
|
||||
|
||||
static void ec_GFp_nistp256_point_mul_public(const EC_GROUP *group,
|
||||
EC_RAW_POINT *r,
|
||||
const EC_SCALAR *g_scalar,
|
||||
const EC_RAW_POINT *p,
|
||||
const EC_SCALAR *p_scalar) {
|
||||
#define P256_WSIZE_PUBLIC 4
|
||||
// Precompute multiples of |p|. p_pre_comp[i] is (2*i+1) * |p|.
|
||||
fiat_p256_felem p_pre_comp[1 << (P256_WSIZE_PUBLIC - 1)][3];
|
||||
fiat_p256_from_generic(p_pre_comp[0][0], &p->X);
|
||||
fiat_p256_from_generic(p_pre_comp[0][1], &p->Y);
|
||||
fiat_p256_from_generic(p_pre_comp[0][2], &p->Z);
|
||||
fiat_p256_felem p2[3];
|
||||
fiat_p256_point_double(p2[0], p2[1], p2[2], p_pre_comp[0][0],
|
||||
p_pre_comp[0][1], p_pre_comp[0][2]);
|
||||
for (size_t i = 1; i < OPENSSL_ARRAY_SIZE(p_pre_comp); i++) {
|
||||
fiat_p256_point_add(p_pre_comp[i][0], p_pre_comp[i][1], p_pre_comp[i][2],
|
||||
p_pre_comp[i - 1][0], p_pre_comp[i - 1][1],
|
||||
p_pre_comp[i - 1][2], 0 /* not mixed */, p2[0], p2[1],
|
||||
p2[2]);
|
||||
}
|
||||
|
||||
// Set up the coefficients for |p_scalar|.
|
||||
int8_t p_wNAF[257];
|
||||
ec_compute_wNAF(group, p_wNAF, p_scalar, 256, P256_WSIZE_PUBLIC);
|
||||
|
||||
// Set |ret| to the point at infinity.
|
||||
int skip = 1; // Save some point operations.
|
||||
fiat_p256_felem ret[3] = {{0}, {0}, {0}};
|
||||
for (int i = 256; i >= 0; i--) {
|
||||
if (!skip) {
|
||||
fiat_p256_point_double(ret[0], ret[1], ret[2], ret[0], ret[1], ret[2]);
|
||||
}
|
||||
|
||||
// For the |g_scalar|, we use the precomputed table without the
|
||||
// constant-time lookup.
|
||||
if (i <= 31) {
|
||||
// First, look 32 bits upwards.
|
||||
uint64_t bits = fiat_p256_get_bit(g_scalar->bytes, i + 224) << 3;
|
||||
bits |= fiat_p256_get_bit(g_scalar->bytes, i + 160) << 2;
|
||||
bits |= fiat_p256_get_bit(g_scalar->bytes, i + 96) << 1;
|
||||
bits |= fiat_p256_get_bit(g_scalar->bytes, i + 32);
|
||||
if (bits != 0) {
|
||||
fiat_p256_point_add(ret[0], ret[1], ret[2], ret[0], ret[1], ret[2],
|
||||
1 /* mixed */, fiat_p256_g_pre_comp[1][bits - 1][0],
|
||||
fiat_p256_g_pre_comp[1][bits - 1][1],
|
||||
fiat_p256_one);
|
||||
skip = 0;
|
||||
}
|
||||
|
||||
// Second, look at the current position.
|
||||
bits = fiat_p256_get_bit(g_scalar->bytes, i + 192) << 3;
|
||||
bits |= fiat_p256_get_bit(g_scalar->bytes, i + 128) << 2;
|
||||
bits |= fiat_p256_get_bit(g_scalar->bytes, i + 64) << 1;
|
||||
bits |= fiat_p256_get_bit(g_scalar->bytes, i);
|
||||
if (bits != 0) {
|
||||
fiat_p256_point_add(ret[0], ret[1], ret[2], ret[0], ret[1], ret[2],
|
||||
1 /* mixed */, fiat_p256_g_pre_comp[0][bits - 1][0],
|
||||
fiat_p256_g_pre_comp[0][bits - 1][1],
|
||||
fiat_p256_one);
|
||||
skip = 0;
|
||||
}
|
||||
}
|
||||
|
||||
int digit = p_wNAF[i];
|
||||
if (digit != 0) {
|
||||
assert(digit & 1);
|
||||
int idx = digit < 0 ? (-digit) >> 1 : digit >> 1;
|
||||
fiat_p256_felem *y = &p_pre_comp[idx][1], tmp;
|
||||
if (digit < 0) {
|
||||
fiat_p256_opp(tmp, p_pre_comp[idx][1]);
|
||||
y = &tmp;
|
||||
}
|
||||
if (!skip) {
|
||||
fiat_p256_point_add(ret[0], ret[1], ret[2], ret[0], ret[1], ret[2],
|
||||
0 /* not mixed */, p_pre_comp[idx][0], *y,
|
||||
p_pre_comp[idx][2]);
|
||||
} else {
|
||||
fiat_p256_copy(ret[0], p_pre_comp[idx][0]);
|
||||
fiat_p256_copy(ret[1], *y);
|
||||
fiat_p256_copy(ret[2], p_pre_comp[idx][2]);
|
||||
skip = 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fiat_p256_to_generic(&r->X, ret[0]);
|
||||
fiat_p256_to_generic(&r->Y, ret[1]);
|
||||
fiat_p256_to_generic(&r->Z, ret[2]);
|
||||
}
|
||||
|
||||
static int ec_GFp_nistp256_cmp_x_coordinate(const EC_GROUP *group,
|
||||
const EC_RAW_POINT *p,
|
||||
const EC_SCALAR *r) {
|
||||
if (ec_GFp_simple_is_at_infinity(group, p)) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
// We wish to compare X/Z^2 with r. This is equivalent to comparing X with
|
||||
// r*Z^2. Note that X and Z are represented in Montgomery form, while r is
|
||||
// not.
|
||||
fiat_p256_felem Z2_mont;
|
||||
fiat_p256_from_generic(Z2_mont, &p->Z);
|
||||
fiat_p256_mul(Z2_mont, Z2_mont, Z2_mont);
|
||||
|
||||
fiat_p256_felem r_Z2;
|
||||
fiat_p256_from_bytes(r_Z2, r->bytes); // r < order < p, so this is valid.
|
||||
fiat_p256_mul(r_Z2, r_Z2, Z2_mont);
|
||||
|
||||
fiat_p256_felem X;
|
||||
fiat_p256_from_generic(X, &p->X);
|
||||
fiat_p256_from_montgomery(X, X);
|
||||
|
||||
if (OPENSSL_memcmp(&r_Z2, &X, sizeof(r_Z2)) == 0) {
|
||||
return 1;
|
||||
}
|
||||
|
||||
// During signing the x coefficient is reduced modulo the group order.
|
||||
// Therefore there is a small possibility, less than 1/2^128, that group_order
|
||||
// < p.x < P. in that case we need not only to compare against |r| but also to
|
||||
// compare against r+group_order.
|
||||
assert(group->field.width == group->order.width);
|
||||
if (bn_less_than_words(r->words, group->field_minus_order.words,
|
||||
group->field.width)) {
|
||||
// We can ignore the carry because: r + group_order < p < 2^256.
|
||||
EC_FELEM tmp;
|
||||
bn_add_words(tmp.words, r->words, group->order.d, group->order.width);
|
||||
fiat_p256_from_generic(r_Z2, &tmp);
|
||||
fiat_p256_mul(r_Z2, r_Z2, Z2_mont);
|
||||
if (OPENSSL_memcmp(&r_Z2, &X, sizeof(r_Z2)) == 0) {
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
DEFINE_METHOD_FUNCTION(EC_METHOD, EC_GFp_nistp256_method) {
|
||||
out->group_init = ec_GFp_mont_group_init;
|
||||
out->group_finish = ec_GFp_mont_group_finish;
|
||||
out->group_set_curve = ec_GFp_mont_group_set_curve;
|
||||
out->point_get_affine_coordinates =
|
||||
ec_GFp_nistp256_point_get_affine_coordinates;
|
||||
out->add = ec_GFp_nistp256_add;
|
||||
out->dbl = ec_GFp_nistp256_dbl;
|
||||
out->mul = ec_GFp_nistp256_point_mul;
|
||||
out->mul_base = ec_GFp_nistp256_point_mul_base;
|
||||
out->mul_public = ec_GFp_nistp256_point_mul_public;
|
||||
out->felem_mul = ec_GFp_mont_felem_mul;
|
||||
out->felem_sqr = ec_GFp_mont_felem_sqr;
|
||||
out->felem_to_bytes = ec_GFp_mont_felem_to_bytes;
|
||||
out->felem_from_bytes = ec_GFp_mont_felem_from_bytes;
|
||||
out->scalar_inv0_montgomery = ec_simple_scalar_inv0_montgomery;
|
||||
out->scalar_to_montgomery_inv_vartime =
|
||||
ec_simple_scalar_to_montgomery_inv_vartime;
|
||||
out->cmp_x_coordinate = ec_GFp_nistp256_cmp_x_coordinate;
|
||||
}
|
||||
|
||||
#undef BORINGSSL_NISTP256_64BIT
|
||||
@@ -0,0 +1,297 @@
|
||||
/* Copyright (c) 2020, Google Inc.
|
||||
*
|
||||
* Permission to use, copy, modify, and/or distribute this software for any
|
||||
* purpose with or without fee is hereby granted, provided that the above
|
||||
* copyright notice and this permission notice appear in all copies.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
|
||||
* WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
|
||||
* MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
|
||||
* SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
|
||||
* WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION
|
||||
* OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
|
||||
* CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. */
|
||||
|
||||
// This file is generated by make_tables.go.
|
||||
|
||||
// Base point pre computation
|
||||
// --------------------------
|
||||
//
|
||||
// Two different sorts of precomputed tables are used in the following code.
|
||||
// Each contain various points on the curve, where each point is three field
|
||||
// elements (x, y, z).
|
||||
//
|
||||
// For the base point table, z is usually 1 (0 for the point at infinity).
|
||||
// This table has 2 * 16 elements, starting with the following:
|
||||
// index | bits | point
|
||||
// ------+---------+------------------------------
|
||||
// 0 | 0 0 0 0 | 0G
|
||||
// 1 | 0 0 0 1 | 1G
|
||||
// 2 | 0 0 1 0 | 2^64G
|
||||
// 3 | 0 0 1 1 | (2^64 + 1)G
|
||||
// 4 | 0 1 0 0 | 2^128G
|
||||
// 5 | 0 1 0 1 | (2^128 + 1)G
|
||||
// 6 | 0 1 1 0 | (2^128 + 2^64)G
|
||||
// 7 | 0 1 1 1 | (2^128 + 2^64 + 1)G
|
||||
// 8 | 1 0 0 0 | 2^192G
|
||||
// 9 | 1 0 0 1 | (2^192 + 1)G
|
||||
// 10 | 1 0 1 0 | (2^192 + 2^64)G
|
||||
// 11 | 1 0 1 1 | (2^192 + 2^64 + 1)G
|
||||
// 12 | 1 1 0 0 | (2^192 + 2^128)G
|
||||
// 13 | 1 1 0 1 | (2^192 + 2^128 + 1)G
|
||||
// 14 | 1 1 1 0 | (2^192 + 2^128 + 2^64)G
|
||||
// 15 | 1 1 1 1 | (2^192 + 2^128 + 2^64 + 1)G
|
||||
// followed by a copy of this with each element multiplied by 2^32.
|
||||
//
|
||||
// The reason for this is so that we can clock bits into four different
|
||||
// locations when doing simple scalar multiplies against the base point,
|
||||
// and then another four locations using the second 16 elements.
|
||||
//
|
||||
// Tables for other points have table[i] = iG for i in 0 .. 16.
|
||||
|
||||
// fiat_p256_g_pre_comp is the table of precomputed base points
|
||||
#if defined(BORINGSSL_NISTP256_64BIT)
|
||||
static const fiat_p256_felem fiat_p256_g_pre_comp[2][15][2] = {
|
||||
{{{0x79e730d418a9143c, 0x75ba95fc5fedb601, 0x79fb732b77622510,
|
||||
0x18905f76a53755c6},
|
||||
{0xddf25357ce95560a, 0x8b4ab8e4ba19e45c, 0xd2e88688dd21f325,
|
||||
0x8571ff1825885d85}},
|
||||
{{0x4f922fc516a0d2bb, 0x0d5cc16c1a623499, 0x9241cf3a57c62c8b,
|
||||
0x2f5e6961fd1b667f},
|
||||
{0x5c15c70bf5a01797, 0x3d20b44d60956192, 0x04911b37071fdb52,
|
||||
0xf648f9168d6f0f7b}},
|
||||
{{0x9e566847e137bbbc, 0xe434469e8a6a0bec, 0xb1c4276179d73463,
|
||||
0x5abe0285133d0015},
|
||||
{0x92aa837cc04c7dab, 0x573d9f4c43260c07, 0x0c93156278e6cc37,
|
||||
0x94bb725b6b6f7383}},
|
||||
{{0x62a8c244bfe20925, 0x91c19ac38fdce867, 0x5a96a5d5dd387063,
|
||||
0x61d587d421d324f6},
|
||||
{0xe87673a2a37173ea, 0x2384800853778b65, 0x10f8441e05bab43e,
|
||||
0xfa11fe124621efbe}},
|
||||
{{0x1c891f2b2cb19ffd, 0x01ba8d5bb1923c23, 0xb6d03d678ac5ca8e,
|
||||
0x586eb04c1f13bedc},
|
||||
{0x0c35c6e527e8ed09, 0x1e81a33c1819ede2, 0x278fd6c056c652fa,
|
||||
0x19d5ac0870864f11}},
|
||||
{{0x62577734d2b533d5, 0x673b8af6a1bdddc0, 0x577e7c9aa79ec293,
|
||||
0xbb6de651c3b266b1},
|
||||
{0xe7e9303ab65259b3, 0xd6a0afd3d03a7480, 0xc5ac83d19b3cfc27,
|
||||
0x60b4619a5d18b99b}},
|
||||
{{0xbd6a38e11ae5aa1c, 0xb8b7652b49e73658, 0x0b130014ee5f87ed,
|
||||
0x9d0f27b2aeebffcd},
|
||||
{0xca9246317a730a55, 0x9c955b2fddbbc83a, 0x07c1dfe0ac019a71,
|
||||
0x244a566d356ec48d}},
|
||||
{{0x56f8410ef4f8b16a, 0x97241afec47b266a, 0x0a406b8e6d9c87c1,
|
||||
0x803f3e02cd42ab1b},
|
||||
{0x7f0309a804dbec69, 0xa83b85f73bbad05f, 0xc6097273ad8e197f,
|
||||
0xc097440e5067adc1}},
|
||||
{{0x846a56f2c379ab34, 0xa8ee068b841df8d1, 0x20314459176c68ef,
|
||||
0xf1af32d5915f1f30},
|
||||
{0x99c375315d75bd50, 0x837cffbaf72f67bc, 0x0613a41848d7723f,
|
||||
0x23d0f130e2d41c8b}},
|
||||
{{0xed93e225d5be5a2b, 0x6fe799835934f3c6, 0x4314092622626ffc,
|
||||
0x50bbb4d97990216a},
|
||||
{0x378191c6e57ec63e, 0x65422c40181dcdb2, 0x41a8099b0236e0f6,
|
||||
0x2b10011801fe49c3}},
|
||||
{{0xfc68b5c59b391593, 0xc385f5a2598270fc, 0x7144f3aad19adcbb,
|
||||
0xdd55899983fbae0c},
|
||||
{0x93b88b8e74b82ff4, 0xd2e03c4071e734c9, 0x9a7a9eaf43c0322a,
|
||||
0xe6e4c551149d6041}},
|
||||
{{0x5fe14bfe80ec21fe, 0xf6ce116ac255be82, 0x98bc5a072f4a5d67,
|
||||
0xfad27148db7e63af},
|
||||
{0x90c0b6ac29ab05b3, 0x37a9a83c4e251ae6, 0x0a7dc875c2aade7d,
|
||||
0x77387de39f0e1a84}},
|
||||
{{0x1e9ecc49a56c0dd7, 0xa5cffcd846086c74, 0x8f7a1408f505aece,
|
||||
0xb37b85c0bef0c47e},
|
||||
{0x3596b6e4cc0e6a8f, 0xfd6d4bbf6b388f23, 0xaba453fac39cef4e,
|
||||
0x9c135ac8f9f628d5}},
|
||||
{{0x0a1c729495c8f8be, 0x2961c4803bf362bf, 0x9e418403df63d4ac,
|
||||
0xc109f9cb91ece900},
|
||||
{0xc2d095d058945705, 0xb9083d96ddeb85c0, 0x84692b8d7a40449b,
|
||||
0x9bc3344f2eee1ee1}},
|
||||
{{0x0d5ae35642913074, 0x55491b2748a542b1, 0x469ca665b310732a,
|
||||
0x29591d525f1a4cc1},
|
||||
{0xe76f5b6bb84f983f, 0xbe7eef419f5f84e1, 0x1200d49680baa189,
|
||||
0x6376551f18ef332c}}},
|
||||
{{{0x202886024147519a, 0xd0981eac26b372f0, 0xa9d4a7caa785ebc8,
|
||||
0xd953c50ddbdf58e9},
|
||||
{0x9d6361ccfd590f8f, 0x72e9626b44e6c917, 0x7fd9611022eb64cf,
|
||||
0x863ebb7e9eb288f3}},
|
||||
{{0x4fe7ee31b0e63d34, 0xf4600572a9e54fab, 0xc0493334d5e7b5a4,
|
||||
0x8589fb9206d54831},
|
||||
{0xaa70f5cc6583553a, 0x0879094ae25649e5, 0xcc90450710044652,
|
||||
0xebb0696d02541c4f}},
|
||||
{{0xabbaa0c03b89da99, 0xa6f2d79eb8284022, 0x27847862b81c05e8,
|
||||
0x337a4b5905e54d63},
|
||||
{0x3c67500d21f7794a, 0x207005b77d6d7f61, 0x0a5a378104cfd6e8,
|
||||
0x0d65e0d5f4c2fbd6}},
|
||||
{{0xd433e50f6d3549cf, 0x6f33696ffacd665e, 0x695bfdacce11fcb4,
|
||||
0x810ee252af7c9860},
|
||||
{0x65450fe17159bb2c, 0xf7dfbebe758b357b, 0x2b057e74d69fea72,
|
||||
0xd485717a92731745}},
|
||||
{{0xce1f69bbe83f7669, 0x09f8ae8272877d6b, 0x9548ae543244278d,
|
||||
0x207755dee3c2c19c},
|
||||
{0x87bd61d96fef1945, 0x18813cefb12d28c3, 0x9fbcd1d672df64aa,
|
||||
0x48dc5ee57154b00d}},
|
||||
{{0xef0f469ef49a3154, 0x3e85a5956e2b2e9a, 0x45aaec1eaa924a9c,
|
||||
0xaa12dfc8a09e4719},
|
||||
{0x26f272274df69f1d, 0xe0e4c82ca2ff5e73, 0xb9d8ce73b7a9dd44,
|
||||
0x6c036e73e48ca901}},
|
||||
{{0xe1e421e1a47153f0, 0xb86c3b79920418c9, 0x93bdce87705d7672,
|
||||
0xf25ae793cab79a77},
|
||||
{0x1f3194a36d869d0c, 0x9d55c8824986c264, 0x49fb5ea3096e945e,
|
||||
0x39b8e65313db0a3e}},
|
||||
{{0xe3417bc035d0b34a, 0x440b386b8327c0a7, 0x8fb7262dac0362d1,
|
||||
0x2c41114ce0cdf943},
|
||||
{0x2ba5cef1ad95a0b1, 0xc09b37a867d54362, 0x26d6cdd201e486c9,
|
||||
0x20477abf42ff9297}},
|
||||
{{0x0f121b41bc0a67d2, 0x62d4760a444d248a, 0x0e044f1d659b4737,
|
||||
0x08fde365250bb4a8},
|
||||
{0xaceec3da848bf287, 0xc2a62182d3369d6e, 0x3582dfdc92449482,
|
||||
0x2f7e2fd2565d6cd7}},
|
||||
{{0x0a0122b5178a876b, 0x51ff96ff085104b4, 0x050b31ab14f29f76,
|
||||
0x84abb28b5f87d4e6},
|
||||
{0xd5ed439f8270790a, 0x2d6cb59d85e3f46b, 0x75f55c1b6c1e2212,
|
||||
0xe5436f6717655640}},
|
||||
{{0xc2965ecc9aeb596d, 0x01ea03e7023c92b4, 0x4704b4b62e013961,
|
||||
0x0ca8fd3f905ea367},
|
||||
{0x92523a42551b2b61, 0x1eb7a89c390fcd06, 0xe7f1d2be0392a63e,
|
||||
0x96dca2644ddb0c33}},
|
||||
{{0x231c210e15339848, 0xe87a28e870778c8d, 0x9d1de6616956e170,
|
||||
0x4ac3c9382bb09c0b},
|
||||
{0x19be05516998987d, 0x8b2376c4ae09f4d6, 0x1de0b7651a3f933d,
|
||||
0x380d94c7e39705f4}},
|
||||
{{0x3685954b8c31c31d, 0x68533d005bf21a0c, 0x0bd7626e75c79ec9,
|
||||
0xca17754742c69d54},
|
||||
{0xcc6edafff6d2dbb2, 0xfd0d8cbd174a9d18, 0x875e8793aa4578e8,
|
||||
0xa976a7139cab2ce6}},
|
||||
{{0xce37ab11b43ea1db, 0x0a7ff1a95259d292, 0x851b02218f84f186,
|
||||
0xa7222beadefaad13},
|
||||
{0xa2ac78ec2b0a9144, 0x5a024051f2fa59c5, 0x91d1eca56147ce38,
|
||||
0xbe94d523bc2ac690}},
|
||||
{{0x2d8daefd79ec1a0f, 0x3bbcd6fdceb39c97, 0xf5575ffc58f61a95,
|
||||
0xdbd986c4adf7b420},
|
||||
{0x81aa881415f39eb7, 0x6ee2fcf5b98d976c, 0x5465475dcf2f717d,
|
||||
0x8e24d3c46860bbd0}}}};
|
||||
#else
|
||||
static const fiat_p256_felem fiat_p256_g_pre_comp[2][15][2] = {
|
||||
{{{0x18a9143c, 0x79e730d4, 0x5fedb601, 0x75ba95fc, 0x77622510, 0x79fb732b,
|
||||
0xa53755c6, 0x18905f76},
|
||||
{0xce95560a, 0xddf25357, 0xba19e45c, 0x8b4ab8e4, 0xdd21f325, 0xd2e88688,
|
||||
0x25885d85, 0x8571ff18}},
|
||||
{{0x16a0d2bb, 0x4f922fc5, 0x1a623499, 0x0d5cc16c, 0x57c62c8b, 0x9241cf3a,
|
||||
0xfd1b667f, 0x2f5e6961},
|
||||
{0xf5a01797, 0x5c15c70b, 0x60956192, 0x3d20b44d, 0x071fdb52, 0x04911b37,
|
||||
0x8d6f0f7b, 0xf648f916}},
|
||||
{{0xe137bbbc, 0x9e566847, 0x8a6a0bec, 0xe434469e, 0x79d73463, 0xb1c42761,
|
||||
0x133d0015, 0x5abe0285},
|
||||
{0xc04c7dab, 0x92aa837c, 0x43260c07, 0x573d9f4c, 0x78e6cc37, 0x0c931562,
|
||||
0x6b6f7383, 0x94bb725b}},
|
||||
{{0xbfe20925, 0x62a8c244, 0x8fdce867, 0x91c19ac3, 0xdd387063, 0x5a96a5d5,
|
||||
0x21d324f6, 0x61d587d4},
|
||||
{0xa37173ea, 0xe87673a2, 0x53778b65, 0x23848008, 0x05bab43e, 0x10f8441e,
|
||||
0x4621efbe, 0xfa11fe12}},
|
||||
{{0x2cb19ffd, 0x1c891f2b, 0xb1923c23, 0x01ba8d5b, 0x8ac5ca8e, 0xb6d03d67,
|
||||
0x1f13bedc, 0x586eb04c},
|
||||
{0x27e8ed09, 0x0c35c6e5, 0x1819ede2, 0x1e81a33c, 0x56c652fa, 0x278fd6c0,
|
||||
0x70864f11, 0x19d5ac08}},
|
||||
{{0xd2b533d5, 0x62577734, 0xa1bdddc0, 0x673b8af6, 0xa79ec293, 0x577e7c9a,
|
||||
0xc3b266b1, 0xbb6de651},
|
||||
{0xb65259b3, 0xe7e9303a, 0xd03a7480, 0xd6a0afd3, 0x9b3cfc27, 0xc5ac83d1,
|
||||
0x5d18b99b, 0x60b4619a}},
|
||||
{{0x1ae5aa1c, 0xbd6a38e1, 0x49e73658, 0xb8b7652b, 0xee5f87ed, 0x0b130014,
|
||||
0xaeebffcd, 0x9d0f27b2},
|
||||
{0x7a730a55, 0xca924631, 0xddbbc83a, 0x9c955b2f, 0xac019a71, 0x07c1dfe0,
|
||||
0x356ec48d, 0x244a566d}},
|
||||
{{0xf4f8b16a, 0x56f8410e, 0xc47b266a, 0x97241afe, 0x6d9c87c1, 0x0a406b8e,
|
||||
0xcd42ab1b, 0x803f3e02},
|
||||
{0x04dbec69, 0x7f0309a8, 0x3bbad05f, 0xa83b85f7, 0xad8e197f, 0xc6097273,
|
||||
0x5067adc1, 0xc097440e}},
|
||||
{{0xc379ab34, 0x846a56f2, 0x841df8d1, 0xa8ee068b, 0x176c68ef, 0x20314459,
|
||||
0x915f1f30, 0xf1af32d5},
|
||||
{0x5d75bd50, 0x99c37531, 0xf72f67bc, 0x837cffba, 0x48d7723f, 0x0613a418,
|
||||
0xe2d41c8b, 0x23d0f130}},
|
||||
{{0xd5be5a2b, 0xed93e225, 0x5934f3c6, 0x6fe79983, 0x22626ffc, 0x43140926,
|
||||
0x7990216a, 0x50bbb4d9},
|
||||
{0xe57ec63e, 0x378191c6, 0x181dcdb2, 0x65422c40, 0x0236e0f6, 0x41a8099b,
|
||||
0x01fe49c3, 0x2b100118}},
|
||||
{{0x9b391593, 0xfc68b5c5, 0x598270fc, 0xc385f5a2, 0xd19adcbb, 0x7144f3aa,
|
||||
0x83fbae0c, 0xdd558999},
|
||||
{0x74b82ff4, 0x93b88b8e, 0x71e734c9, 0xd2e03c40, 0x43c0322a, 0x9a7a9eaf,
|
||||
0x149d6041, 0xe6e4c551}},
|
||||
{{0x80ec21fe, 0x5fe14bfe, 0xc255be82, 0xf6ce116a, 0x2f4a5d67, 0x98bc5a07,
|
||||
0xdb7e63af, 0xfad27148},
|
||||
{0x29ab05b3, 0x90c0b6ac, 0x4e251ae6, 0x37a9a83c, 0xc2aade7d, 0x0a7dc875,
|
||||
0x9f0e1a84, 0x77387de3}},
|
||||
{{0xa56c0dd7, 0x1e9ecc49, 0x46086c74, 0xa5cffcd8, 0xf505aece, 0x8f7a1408,
|
||||
0xbef0c47e, 0xb37b85c0},
|
||||
{0xcc0e6a8f, 0x3596b6e4, 0x6b388f23, 0xfd6d4bbf, 0xc39cef4e, 0xaba453fa,
|
||||
0xf9f628d5, 0x9c135ac8}},
|
||||
{{0x95c8f8be, 0x0a1c7294, 0x3bf362bf, 0x2961c480, 0xdf63d4ac, 0x9e418403,
|
||||
0x91ece900, 0xc109f9cb},
|
||||
{0x58945705, 0xc2d095d0, 0xddeb85c0, 0xb9083d96, 0x7a40449b, 0x84692b8d,
|
||||
0x2eee1ee1, 0x9bc3344f}},
|
||||
{{0x42913074, 0x0d5ae356, 0x48a542b1, 0x55491b27, 0xb310732a, 0x469ca665,
|
||||
0x5f1a4cc1, 0x29591d52},
|
||||
{0xb84f983f, 0xe76f5b6b, 0x9f5f84e1, 0xbe7eef41, 0x80baa189, 0x1200d496,
|
||||
0x18ef332c, 0x6376551f}}},
|
||||
{{{0x4147519a, 0x20288602, 0x26b372f0, 0xd0981eac, 0xa785ebc8, 0xa9d4a7ca,
|
||||
0xdbdf58e9, 0xd953c50d},
|
||||
{0xfd590f8f, 0x9d6361cc, 0x44e6c917, 0x72e9626b, 0x22eb64cf, 0x7fd96110,
|
||||
0x9eb288f3, 0x863ebb7e}},
|
||||
{{0xb0e63d34, 0x4fe7ee31, 0xa9e54fab, 0xf4600572, 0xd5e7b5a4, 0xc0493334,
|
||||
0x06d54831, 0x8589fb92},
|
||||
{0x6583553a, 0xaa70f5cc, 0xe25649e5, 0x0879094a, 0x10044652, 0xcc904507,
|
||||
0x02541c4f, 0xebb0696d}},
|
||||
{{0x3b89da99, 0xabbaa0c0, 0xb8284022, 0xa6f2d79e, 0xb81c05e8, 0x27847862,
|
||||
0x05e54d63, 0x337a4b59},
|
||||
{0x21f7794a, 0x3c67500d, 0x7d6d7f61, 0x207005b7, 0x04cfd6e8, 0x0a5a3781,
|
||||
0xf4c2fbd6, 0x0d65e0d5}},
|
||||
{{0x6d3549cf, 0xd433e50f, 0xfacd665e, 0x6f33696f, 0xce11fcb4, 0x695bfdac,
|
||||
0xaf7c9860, 0x810ee252},
|
||||
{0x7159bb2c, 0x65450fe1, 0x758b357b, 0xf7dfbebe, 0xd69fea72, 0x2b057e74,
|
||||
0x92731745, 0xd485717a}},
|
||||
{{0xe83f7669, 0xce1f69bb, 0x72877d6b, 0x09f8ae82, 0x3244278d, 0x9548ae54,
|
||||
0xe3c2c19c, 0x207755de},
|
||||
{0x6fef1945, 0x87bd61d9, 0xb12d28c3, 0x18813cef, 0x72df64aa, 0x9fbcd1d6,
|
||||
0x7154b00d, 0x48dc5ee5}},
|
||||
{{0xf49a3154, 0xef0f469e, 0x6e2b2e9a, 0x3e85a595, 0xaa924a9c, 0x45aaec1e,
|
||||
0xa09e4719, 0xaa12dfc8},
|
||||
{0x4df69f1d, 0x26f27227, 0xa2ff5e73, 0xe0e4c82c, 0xb7a9dd44, 0xb9d8ce73,
|
||||
0xe48ca901, 0x6c036e73}},
|
||||
{{0xa47153f0, 0xe1e421e1, 0x920418c9, 0xb86c3b79, 0x705d7672, 0x93bdce87,
|
||||
0xcab79a77, 0xf25ae793},
|
||||
{0x6d869d0c, 0x1f3194a3, 0x4986c264, 0x9d55c882, 0x096e945e, 0x49fb5ea3,
|
||||
0x13db0a3e, 0x39b8e653}},
|
||||
{{0x35d0b34a, 0xe3417bc0, 0x8327c0a7, 0x440b386b, 0xac0362d1, 0x8fb7262d,
|
||||
0xe0cdf943, 0x2c41114c},
|
||||
{0xad95a0b1, 0x2ba5cef1, 0x67d54362, 0xc09b37a8, 0x01e486c9, 0x26d6cdd2,
|
||||
0x42ff9297, 0x20477abf}},
|
||||
{{0xbc0a67d2, 0x0f121b41, 0x444d248a, 0x62d4760a, 0x659b4737, 0x0e044f1d,
|
||||
0x250bb4a8, 0x08fde365},
|
||||
{0x848bf287, 0xaceec3da, 0xd3369d6e, 0xc2a62182, 0x92449482, 0x3582dfdc,
|
||||
0x565d6cd7, 0x2f7e2fd2}},
|
||||
{{0x178a876b, 0x0a0122b5, 0x085104b4, 0x51ff96ff, 0x14f29f76, 0x050b31ab,
|
||||
0x5f87d4e6, 0x84abb28b},
|
||||
{0x8270790a, 0xd5ed439f, 0x85e3f46b, 0x2d6cb59d, 0x6c1e2212, 0x75f55c1b,
|
||||
0x17655640, 0xe5436f67}},
|
||||
{{0x9aeb596d, 0xc2965ecc, 0x023c92b4, 0x01ea03e7, 0x2e013961, 0x4704b4b6,
|
||||
0x905ea367, 0x0ca8fd3f},
|
||||
{0x551b2b61, 0x92523a42, 0x390fcd06, 0x1eb7a89c, 0x0392a63e, 0xe7f1d2be,
|
||||
0x4ddb0c33, 0x96dca264}},
|
||||
{{0x15339848, 0x231c210e, 0x70778c8d, 0xe87a28e8, 0x6956e170, 0x9d1de661,
|
||||
0x2bb09c0b, 0x4ac3c938},
|
||||
{0x6998987d, 0x19be0551, 0xae09f4d6, 0x8b2376c4, 0x1a3f933d, 0x1de0b765,
|
||||
0xe39705f4, 0x380d94c7}},
|
||||
{{0x8c31c31d, 0x3685954b, 0x5bf21a0c, 0x68533d00, 0x75c79ec9, 0x0bd7626e,
|
||||
0x42c69d54, 0xca177547},
|
||||
{0xf6d2dbb2, 0xcc6edaff, 0x174a9d18, 0xfd0d8cbd, 0xaa4578e8, 0x875e8793,
|
||||
0x9cab2ce6, 0xa976a713}},
|
||||
{{0xb43ea1db, 0xce37ab11, 0x5259d292, 0x0a7ff1a9, 0x8f84f186, 0x851b0221,
|
||||
0xdefaad13, 0xa7222bea},
|
||||
{0x2b0a9144, 0xa2ac78ec, 0xf2fa59c5, 0x5a024051, 0x6147ce38, 0x91d1eca5,
|
||||
0xbc2ac690, 0xbe94d523}},
|
||||
{{0x79ec1a0f, 0x2d8daefd, 0xceb39c97, 0x3bbcd6fd, 0x58f61a95, 0xf5575ffc,
|
||||
0xadf7b420, 0xdbd986c4},
|
||||
{0x15f39eb7, 0x81aa8814, 0xb98d976c, 0x6ee2fcf5, 0xcf2f717d, 0x5465475d,
|
||||
0x6860bbd0, 0x8e24d3c4}}}};
|
||||
#endif
|
||||
@@ -51,6 +51,45 @@ int ec_random_nonzero_scalar(const EC_GROUP *group, EC_SCALAR *out,
|
||||
additional_data);
|
||||
}
|
||||
|
||||
void ec_scalar_to_bytes(const EC_GROUP *group, uint8_t *out, size_t *out_len,
|
||||
const EC_SCALAR *in) {
|
||||
size_t len = BN_num_bytes(&group->order);
|
||||
for (size_t i = 0; i < len; i++) {
|
||||
out[len - i - 1] = in->bytes[i];
|
||||
}
|
||||
*out_len = len;
|
||||
}
|
||||
|
||||
int ec_scalar_from_bytes(const EC_GROUP *group, EC_SCALAR *out,
|
||||
const uint8_t *in, size_t len) {
|
||||
if (len != BN_num_bytes(&group->order)) {
|
||||
OPENSSL_PUT_ERROR(EC, EC_R_INVALID_SCALAR);
|
||||
return 0;
|
||||
}
|
||||
|
||||
OPENSSL_memset(out, 0, sizeof(EC_SCALAR));
|
||||
|
||||
for (size_t i = 0; i < len; i++) {
|
||||
out->bytes[i] = in[len - i - 1];
|
||||
}
|
||||
|
||||
if (!bn_less_than_words(out->words, group->order.d, group->order.width)) {
|
||||
OPENSSL_PUT_ERROR(EC, EC_R_INVALID_SCALAR);
|
||||
return 0;
|
||||
}
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
void ec_scalar_reduce(const EC_GROUP *group, EC_SCALAR *out,
|
||||
const BN_ULONG *words, size_t num) {
|
||||
// Convert "from" Montgomery form so the value is reduced modulo the order.
|
||||
bn_from_montgomery_small(out->words, group->order.width, words, num,
|
||||
group->order_mont);
|
||||
// Convert "to" Montgomery form to remove the R^-1 factor added.
|
||||
ec_scalar_to_montgomery(group, out, out);
|
||||
}
|
||||
|
||||
void ec_scalar_add(const EC_GROUP *group, EC_SCALAR *r, const EC_SCALAR *a,
|
||||
const EC_SCALAR *b) {
|
||||
const BIGNUM *order = &group->order;
|
||||
@@ -59,6 +98,26 @@ void ec_scalar_add(const EC_GROUP *group, EC_SCALAR *r, const EC_SCALAR *a,
|
||||
OPENSSL_cleanse(tmp, sizeof(tmp));
|
||||
}
|
||||
|
||||
void ec_scalar_sub(const EC_GROUP *group, EC_SCALAR *r, const EC_SCALAR *a,
|
||||
const EC_SCALAR *b) {
|
||||
const BIGNUM *order = &group->order;
|
||||
BN_ULONG tmp[EC_MAX_WORDS];
|
||||
bn_mod_sub_words(r->words, a->words, b->words, order->d, tmp, order->width);
|
||||
OPENSSL_cleanse(tmp, sizeof(tmp));
|
||||
}
|
||||
|
||||
void ec_scalar_neg(const EC_GROUP *group, EC_SCALAR *r, const EC_SCALAR *a) {
|
||||
EC_SCALAR zero;
|
||||
OPENSSL_memset(&zero, 0, sizeof(EC_SCALAR));
|
||||
ec_scalar_sub(group, r, &zero, a);
|
||||
}
|
||||
|
||||
void ec_scalar_select(const EC_GROUP *group, EC_SCALAR *out, BN_ULONG mask,
|
||||
const EC_SCALAR *a, const EC_SCALAR *b) {
|
||||
const BIGNUM *order = &group->order;
|
||||
bn_select_words(out->words, mask, a->words, b->words, order->width);
|
||||
}
|
||||
|
||||
void ec_scalar_to_montgomery(const EC_GROUP *group, EC_SCALAR *r,
|
||||
const EC_SCALAR *a) {
|
||||
const BIGNUM *order = &group->order;
|
||||
@@ -68,7 +127,8 @@ void ec_scalar_to_montgomery(const EC_GROUP *group, EC_SCALAR *r,
|
||||
void ec_scalar_from_montgomery(const EC_GROUP *group, EC_SCALAR *r,
|
||||
const EC_SCALAR *a) {
|
||||
const BIGNUM *order = &group->order;
|
||||
bn_from_montgomery_small(r->words, a->words, order->width, group->order_mont);
|
||||
bn_from_montgomery_small(r->words, order->width, a->words, order->width,
|
||||
group->order_mont);
|
||||
}
|
||||
|
||||
void ec_scalar_mul_montgomery(const EC_GROUP *group, EC_SCALAR *r,
|
||||
@@ -78,19 +138,38 @@ void ec_scalar_mul_montgomery(const EC_GROUP *group, EC_SCALAR *r,
|
||||
group->order_mont);
|
||||
}
|
||||
|
||||
void ec_simple_scalar_inv_montgomery(const EC_GROUP *group, EC_SCALAR *r,
|
||||
const EC_SCALAR *a) {
|
||||
void ec_simple_scalar_inv0_montgomery(const EC_GROUP *group, EC_SCALAR *r,
|
||||
const EC_SCALAR *a) {
|
||||
const BIGNUM *order = &group->order;
|
||||
bn_mod_inverse_prime_mont_small(r->words, a->words, order->width,
|
||||
group->order_mont);
|
||||
bn_mod_inverse0_prime_mont_small(r->words, a->words, order->width,
|
||||
group->order_mont);
|
||||
}
|
||||
|
||||
void ec_scalar_inv_montgomery(const EC_GROUP *group, EC_SCALAR *r,
|
||||
const EC_SCALAR *a) {
|
||||
group->meth->scalar_inv_montgomery(group, r, a);
|
||||
int ec_simple_scalar_to_montgomery_inv_vartime(const EC_GROUP *group,
|
||||
EC_SCALAR *r,
|
||||
const EC_SCALAR *a) {
|
||||
if (ec_scalar_is_zero(group, a)) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
// This implementation (in fact) runs in constant time,
|
||||
// even though for this interface it is not mandatory.
|
||||
|
||||
// r = a^-1 in the Montgomery domain. This is
|
||||
// |ec_scalar_to_montgomery| followed by |ec_scalar_inv0_montgomery|, but
|
||||
// |ec_scalar_inv0_montgomery| followed by |ec_scalar_from_montgomery| is
|
||||
// equivalent and slightly more efficient.
|
||||
ec_scalar_inv0_montgomery(group, r, a);
|
||||
ec_scalar_from_montgomery(group, r, r);
|
||||
return 1;
|
||||
}
|
||||
|
||||
int ec_scalar_inv_montgomery_vartime(const EC_GROUP *group, EC_SCALAR *r,
|
||||
const EC_SCALAR *a) {
|
||||
return group->meth->scalar_inv_montgomery_vartime(group, r, a);
|
||||
void ec_scalar_inv0_montgomery(const EC_GROUP *group, EC_SCALAR *r,
|
||||
const EC_SCALAR *a) {
|
||||
group->meth->scalar_inv0_montgomery(group, r, a);
|
||||
}
|
||||
|
||||
int ec_scalar_to_montgomery_inv_vartime(const EC_GROUP *group, EC_SCALAR *r,
|
||||
const EC_SCALAR *a) {
|
||||
return group->meth->scalar_to_montgomery_inv_vartime(group, r, a);
|
||||
}
|
||||
@@ -101,22 +101,13 @@ void ec_GFp_simple_group_finish(EC_GROUP *group) {
|
||||
int ec_GFp_simple_group_set_curve(EC_GROUP *group, const BIGNUM *p,
|
||||
const BIGNUM *a, const BIGNUM *b,
|
||||
BN_CTX *ctx) {
|
||||
int ret = 0;
|
||||
BN_CTX *new_ctx = NULL;
|
||||
|
||||
// p must be a prime > 3
|
||||
if (BN_num_bits(p) <= 2 || !BN_is_odd(p)) {
|
||||
OPENSSL_PUT_ERROR(EC, EC_R_INVALID_FIELD);
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (ctx == NULL) {
|
||||
ctx = new_ctx = BN_CTX_new();
|
||||
if (ctx == NULL) {
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
int ret = 0;
|
||||
BN_CTX_start(ctx);
|
||||
BIGNUM *tmp = BN_CTX_get(ctx);
|
||||
if (tmp == NULL) {
|
||||
@@ -131,33 +122,23 @@ int ec_GFp_simple_group_set_curve(EC_GROUP *group, const BIGNUM *p,
|
||||
// Store the field in minimal form, so it can be used with |BN_ULONG| arrays.
|
||||
bn_set_minimal_width(&group->field);
|
||||
|
||||
// group->a
|
||||
if (!BN_nnmod(tmp, a, &group->field, ctx) ||
|
||||
!ec_bignum_to_felem(group, &group->a, tmp)) {
|
||||
if (!ec_bignum_to_felem(group, &group->a, a) ||
|
||||
!ec_bignum_to_felem(group, &group->b, b) ||
|
||||
!ec_bignum_to_felem(group, &group->one, BN_value_one())) {
|
||||
goto err;
|
||||
}
|
||||
|
||||
// group->a_is_minus3
|
||||
if (!BN_add_word(tmp, 3)) {
|
||||
if (!BN_copy(tmp, a) ||
|
||||
!BN_add_word(tmp, 3)) {
|
||||
goto err;
|
||||
}
|
||||
group->a_is_minus3 = (0 == BN_cmp(tmp, &group->field));
|
||||
|
||||
// group->b
|
||||
if (!BN_nnmod(tmp, b, &group->field, ctx) ||
|
||||
!ec_bignum_to_felem(group, &group->b, tmp)) {
|
||||
goto err;
|
||||
}
|
||||
|
||||
if (!ec_bignum_to_felem(group, &group->one, BN_value_one())) {
|
||||
goto err;
|
||||
}
|
||||
|
||||
ret = 1;
|
||||
|
||||
err:
|
||||
BN_CTX_end(ctx);
|
||||
BN_CTX_free(new_ctx);
|
||||
return ret;
|
||||
}
|
||||
|
||||
@@ -190,24 +171,6 @@ void ec_GFp_simple_point_set_to_infinity(const EC_GROUP *group,
|
||||
ec_GFp_simple_point_init(point);
|
||||
}
|
||||
|
||||
int ec_GFp_simple_point_set_affine_coordinates(const EC_GROUP *group,
|
||||
EC_RAW_POINT *point,
|
||||
const BIGNUM *x,
|
||||
const BIGNUM *y) {
|
||||
if (x == NULL || y == NULL) {
|
||||
OPENSSL_PUT_ERROR(EC, ERR_R_PASSED_NULL_PARAMETER);
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (!ec_bignum_to_felem(group, &point->X, x) ||
|
||||
!ec_bignum_to_felem(group, &point->Y, y)) {
|
||||
return 0;
|
||||
}
|
||||
OPENSSL_memcpy(&point->Z, &group->one, sizeof(EC_FELEM));
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
void ec_GFp_simple_invert(const EC_GROUP *group, EC_RAW_POINT *point) {
|
||||
ec_felem_neg(group, &point->Y, &point->Y);
|
||||
}
|
||||
@@ -219,10 +182,6 @@ int ec_GFp_simple_is_at_infinity(const EC_GROUP *group,
|
||||
|
||||
int ec_GFp_simple_is_on_curve(const EC_GROUP *group,
|
||||
const EC_RAW_POINT *point) {
|
||||
if (ec_GFp_simple_is_at_infinity(group, point)) {
|
||||
return 1;
|
||||
}
|
||||
|
||||
// We have a curve defined by a Weierstrass equation
|
||||
// y^2 = x^3 + a*x + b.
|
||||
// The point to consider is given in Jacobian projective coordinates
|
||||
@@ -231,6 +190,9 @@ int ec_GFp_simple_is_on_curve(const EC_GROUP *group,
|
||||
// into
|
||||
// Y^2 = X^3 + a*X*Z^4 + b*Z^6.
|
||||
// To test this, we add up the right-hand side in 'rh'.
|
||||
//
|
||||
// This function may be used when double-checking the secret result of a point
|
||||
// multiplication, so we proceed in constant-time.
|
||||
|
||||
void (*const felem_mul)(const EC_GROUP *, EC_FELEM *r, const EC_FELEM *a,
|
||||
const EC_FELEM *b) = group->meth->felem_mul;
|
||||
@@ -242,128 +204,114 @@ int ec_GFp_simple_is_on_curve(const EC_GROUP *group,
|
||||
felem_sqr(group, &rh, &point->X);
|
||||
|
||||
EC_FELEM tmp, Z4, Z6;
|
||||
if (!ec_felem_equal(group, &point->Z, &group->one)) {
|
||||
felem_sqr(group, &tmp, &point->Z);
|
||||
felem_sqr(group, &Z4, &tmp);
|
||||
felem_mul(group, &Z6, &Z4, &tmp);
|
||||
felem_sqr(group, &tmp, &point->Z);
|
||||
felem_sqr(group, &Z4, &tmp);
|
||||
felem_mul(group, &Z6, &Z4, &tmp);
|
||||
|
||||
// rh := (rh + a*Z^4)*X
|
||||
if (group->a_is_minus3) {
|
||||
ec_felem_add(group, &tmp, &Z4, &Z4);
|
||||
ec_felem_add(group, &tmp, &tmp, &Z4);
|
||||
ec_felem_sub(group, &rh, &rh, &tmp);
|
||||
felem_mul(group, &rh, &rh, &point->X);
|
||||
} else {
|
||||
felem_mul(group, &tmp, &Z4, &group->a);
|
||||
ec_felem_add(group, &rh, &rh, &tmp);
|
||||
felem_mul(group, &rh, &rh, &point->X);
|
||||
}
|
||||
|
||||
// rh := rh + b*Z^6
|
||||
felem_mul(group, &tmp, &group->b, &Z6);
|
||||
ec_felem_add(group, &rh, &rh, &tmp);
|
||||
// rh := rh + a*Z^4
|
||||
if (group->a_is_minus3) {
|
||||
ec_felem_add(group, &tmp, &Z4, &Z4);
|
||||
ec_felem_add(group, &tmp, &tmp, &Z4);
|
||||
ec_felem_sub(group, &rh, &rh, &tmp);
|
||||
} else {
|
||||
// rh := (rh + a)*X
|
||||
ec_felem_add(group, &rh, &rh, &group->a);
|
||||
felem_mul(group, &rh, &rh, &point->X);
|
||||
// rh := rh + b
|
||||
ec_felem_add(group, &rh, &rh, &group->b);
|
||||
felem_mul(group, &tmp, &Z4, &group->a);
|
||||
ec_felem_add(group, &rh, &rh, &tmp);
|
||||
}
|
||||
|
||||
// rh := (rh + a*Z^4)*X
|
||||
felem_mul(group, &rh, &rh, &point->X);
|
||||
|
||||
// rh := rh + b*Z^6
|
||||
felem_mul(group, &tmp, &group->b, &Z6);
|
||||
ec_felem_add(group, &rh, &rh, &tmp);
|
||||
|
||||
// 'lh' := Y^2
|
||||
felem_sqr(group, &tmp, &point->Y);
|
||||
return ec_felem_equal(group, &tmp, &rh);
|
||||
|
||||
ec_felem_sub(group, &tmp, &tmp, &rh);
|
||||
BN_ULONG not_equal = ec_felem_non_zero_mask(group, &tmp);
|
||||
|
||||
// If Z = 0, the point is infinity, which is always on the curve.
|
||||
BN_ULONG not_infinity = ec_felem_non_zero_mask(group, &point->Z);
|
||||
|
||||
return 1 & ~(not_infinity & not_equal);
|
||||
}
|
||||
|
||||
int ec_GFp_simple_cmp(const EC_GROUP *group, const EC_RAW_POINT *a,
|
||||
const EC_RAW_POINT *b) {
|
||||
// Note this function returns zero if |a| and |b| are equal and 1 if they are
|
||||
// not equal.
|
||||
if (ec_GFp_simple_is_at_infinity(group, a)) {
|
||||
return ec_GFp_simple_is_at_infinity(group, b) ? 0 : 1;
|
||||
}
|
||||
int ec_GFp_simple_points_equal(const EC_GROUP *group, const EC_RAW_POINT *a,
|
||||
const EC_RAW_POINT *b) {
|
||||
// This function is implemented in constant-time for two reasons. First,
|
||||
// although EC points are usually public, their Jacobian Z coordinates may be
|
||||
// secret, or at least are not obviously public. Second, more complex
|
||||
// protocols will sometimes manipulate secret points.
|
||||
//
|
||||
// This does mean that we pay a 6M+2S Jacobian comparison when comparing two
|
||||
// publicly affine points costs no field operations at all. If needed, we can
|
||||
// restore this optimization by keeping better track of affine vs. Jacobian
|
||||
// forms. See https://crbug.com/boringssl/326.
|
||||
|
||||
if (ec_GFp_simple_is_at_infinity(group, b)) {
|
||||
return 1;
|
||||
}
|
||||
|
||||
int a_Z_is_one = ec_felem_equal(group, &a->Z, &group->one);
|
||||
int b_Z_is_one = ec_felem_equal(group, &b->Z, &group->one);
|
||||
|
||||
if (a_Z_is_one && b_Z_is_one) {
|
||||
return !ec_felem_equal(group, &a->X, &b->X) ||
|
||||
!ec_felem_equal(group, &a->Y, &b->Y);
|
||||
}
|
||||
// If neither |a| or |b| is infinity, we have to decide whether
|
||||
// (X_a/Z_a^2, Y_a/Z_a^3) = (X_b/Z_b^2, Y_b/Z_b^3),
|
||||
// or equivalently, whether
|
||||
// (X_a*Z_b^2, Y_a*Z_b^3) = (X_b*Z_a^2, Y_b*Z_a^3).
|
||||
|
||||
void (*const felem_mul)(const EC_GROUP *, EC_FELEM *r, const EC_FELEM *a,
|
||||
const EC_FELEM *b) = group->meth->felem_mul;
|
||||
void (*const felem_sqr)(const EC_GROUP *, EC_FELEM *r, const EC_FELEM *a) =
|
||||
group->meth->felem_sqr;
|
||||
|
||||
// We have to decide whether
|
||||
// (X_a/Z_a^2, Y_a/Z_a^3) = (X_b/Z_b^2, Y_b/Z_b^3),
|
||||
// or equivalently, whether
|
||||
// (X_a*Z_b^2, Y_a*Z_b^3) = (X_b*Z_a^2, Y_b*Z_a^3).
|
||||
|
||||
EC_FELEM tmp1, tmp2, Za23, Zb23;
|
||||
const EC_FELEM *tmp1_, *tmp2_;
|
||||
if (!b_Z_is_one) {
|
||||
felem_sqr(group, &Zb23, &b->Z);
|
||||
felem_mul(group, &tmp1, &a->X, &Zb23);
|
||||
tmp1_ = &tmp1;
|
||||
} else {
|
||||
tmp1_ = &a->X;
|
||||
}
|
||||
if (!a_Z_is_one) {
|
||||
felem_sqr(group, &Za23, &a->Z);
|
||||
felem_mul(group, &tmp2, &b->X, &Za23);
|
||||
tmp2_ = &tmp2;
|
||||
} else {
|
||||
tmp2_ = &b->X;
|
||||
}
|
||||
felem_sqr(group, &Zb23, &b->Z); // Zb23 = Z_b^2
|
||||
felem_mul(group, &tmp1, &a->X, &Zb23); // tmp1 = X_a * Z_b^2
|
||||
felem_sqr(group, &Za23, &a->Z); // Za23 = Z_a^2
|
||||
felem_mul(group, &tmp2, &b->X, &Za23); // tmp2 = X_b * Z_a^2
|
||||
ec_felem_sub(group, &tmp1, &tmp1, &tmp2);
|
||||
const BN_ULONG x_not_equal = ec_felem_non_zero_mask(group, &tmp1);
|
||||
|
||||
// Compare X_a*Z_b^2 with X_b*Z_a^2.
|
||||
if (!ec_felem_equal(group, tmp1_, tmp2_)) {
|
||||
return 1; // The points differ.
|
||||
}
|
||||
felem_mul(group, &Zb23, &Zb23, &b->Z); // Zb23 = Z_b^3
|
||||
felem_mul(group, &tmp1, &a->Y, &Zb23); // tmp1 = Y_a * Z_b^3
|
||||
felem_mul(group, &Za23, &Za23, &a->Z); // Za23 = Z_a^3
|
||||
felem_mul(group, &tmp2, &b->Y, &Za23); // tmp2 = Y_b * Z_a^3
|
||||
ec_felem_sub(group, &tmp1, &tmp1, &tmp2);
|
||||
const BN_ULONG y_not_equal = ec_felem_non_zero_mask(group, &tmp1);
|
||||
const BN_ULONG x_and_y_equal = ~(x_not_equal | y_not_equal);
|
||||
|
||||
if (!b_Z_is_one) {
|
||||
felem_mul(group, &Zb23, &Zb23, &b->Z);
|
||||
felem_mul(group, &tmp1, &a->Y, &Zb23);
|
||||
// tmp1_ = &tmp1
|
||||
} else {
|
||||
tmp1_ = &a->Y;
|
||||
}
|
||||
if (!a_Z_is_one) {
|
||||
felem_mul(group, &Za23, &Za23, &a->Z);
|
||||
felem_mul(group, &tmp2, &b->Y, &Za23);
|
||||
// tmp2_ = &tmp2
|
||||
} else {
|
||||
tmp2_ = &b->Y;
|
||||
}
|
||||
const BN_ULONG a_not_infinity = ec_felem_non_zero_mask(group, &a->Z);
|
||||
const BN_ULONG b_not_infinity = ec_felem_non_zero_mask(group, &b->Z);
|
||||
const BN_ULONG a_and_b_infinity = ~(a_not_infinity | b_not_infinity);
|
||||
|
||||
// Compare Y_a*Z_b^3 with Y_b*Z_a^3.
|
||||
if (!ec_felem_equal(group, tmp1_, tmp2_)) {
|
||||
return 1; // The points differ.
|
||||
}
|
||||
|
||||
// The points are equal.
|
||||
return 0;
|
||||
const BN_ULONG equal =
|
||||
a_and_b_infinity | (a_not_infinity & b_not_infinity & x_and_y_equal);
|
||||
return equal & 1;
|
||||
}
|
||||
|
||||
int ec_GFp_simple_mont_inv_mod_ord_vartime(const EC_GROUP *group,
|
||||
EC_SCALAR *out,
|
||||
const EC_SCALAR *in) {
|
||||
// This implementation (in fact) runs in constant time,
|
||||
// even though for this interface it is not mandatory.
|
||||
int ec_affine_jacobian_equal(const EC_GROUP *group, const EC_AFFINE *a,
|
||||
const EC_RAW_POINT *b) {
|
||||
// If |b| is not infinity, we have to decide whether
|
||||
// (X_a, Y_a) = (X_b/Z_b^2, Y_b/Z_b^3),
|
||||
// or equivalently, whether
|
||||
// (X_a*Z_b^2, Y_a*Z_b^3) = (X_b, Y_b).
|
||||
|
||||
// out = in^-1 in the Montgomery domain. This is
|
||||
// |ec_scalar_to_montgomery| followed by |ec_scalar_inv_montgomery|, but
|
||||
// |ec_scalar_inv_montgomery| followed by |ec_scalar_from_montgomery| is
|
||||
// equivalent and slightly more efficient.
|
||||
ec_scalar_inv_montgomery(group, out, in);
|
||||
ec_scalar_from_montgomery(group, out, out);
|
||||
return 1;
|
||||
void (*const felem_mul)(const EC_GROUP *, EC_FELEM *r, const EC_FELEM *a,
|
||||
const EC_FELEM *b) = group->meth->felem_mul;
|
||||
void (*const felem_sqr)(const EC_GROUP *, EC_FELEM *r, const EC_FELEM *a) =
|
||||
group->meth->felem_sqr;
|
||||
|
||||
EC_FELEM tmp, Zb2;
|
||||
felem_sqr(group, &Zb2, &b->Z); // Zb2 = Z_b^2
|
||||
felem_mul(group, &tmp, &a->X, &Zb2); // tmp = X_a * Z_b^2
|
||||
ec_felem_sub(group, &tmp, &tmp, &b->X);
|
||||
const BN_ULONG x_not_equal = ec_felem_non_zero_mask(group, &tmp);
|
||||
|
||||
felem_mul(group, &tmp, &a->Y, &Zb2); // tmp = Y_a * Z_b^2
|
||||
felem_mul(group, &tmp, &tmp, &b->Z); // tmp = Y_a * Z_b^3
|
||||
ec_felem_sub(group, &tmp, &tmp, &b->Y);
|
||||
const BN_ULONG y_not_equal = ec_felem_non_zero_mask(group, &tmp);
|
||||
const BN_ULONG x_and_y_equal = ~(x_not_equal | y_not_equal);
|
||||
|
||||
const BN_ULONG b_not_infinity = ec_felem_non_zero_mask(group, &b->Z);
|
||||
|
||||
const BN_ULONG equal = b_not_infinity & x_and_y_equal;
|
||||
return equal & 1;
|
||||
}
|
||||
|
||||
int ec_GFp_simple_cmp_x_coordinate(const EC_GROUP *group, const EC_RAW_POINT *p,
|
||||
@@ -378,3 +326,32 @@ int ec_GFp_simple_cmp_x_coordinate(const EC_GROUP *group, const EC_RAW_POINT *p,
|
||||
return ec_get_x_coordinate_as_scalar(group, &x, p) &&
|
||||
ec_scalar_equal_vartime(group, &x, r);
|
||||
}
|
||||
|
||||
void ec_GFp_simple_felem_to_bytes(const EC_GROUP *group, uint8_t *out,
|
||||
size_t *out_len, const EC_FELEM *in) {
|
||||
size_t len = BN_num_bytes(&group->field);
|
||||
for (size_t i = 0; i < len; i++) {
|
||||
out[i] = in->bytes[len - 1 - i];
|
||||
}
|
||||
*out_len = len;
|
||||
}
|
||||
|
||||
int ec_GFp_simple_felem_from_bytes(const EC_GROUP *group, EC_FELEM *out,
|
||||
const uint8_t *in, size_t len) {
|
||||
if (len != BN_num_bytes(&group->field)) {
|
||||
OPENSSL_PUT_ERROR(EC, EC_R_DECODE_ERROR);
|
||||
return 0;
|
||||
}
|
||||
|
||||
OPENSSL_memset(out, 0, sizeof(EC_FELEM));
|
||||
for (size_t i = 0; i < len; i++) {
|
||||
out->bytes[i] = in[len - 1 - i];
|
||||
}
|
||||
|
||||
if (!bn_less_than_words(out->words, group->field.d, group->field.width)) {
|
||||
OPENSSL_PUT_ERROR(EC, EC_R_DECODE_ERROR);
|
||||
return 0;
|
||||
}
|
||||
|
||||
return 1;
|
||||
}
|
||||
@@ -60,9 +60,7 @@ void ec_GFp_mont_mul(const EC_GROUP *group, EC_RAW_POINT *r,
|
||||
OPENSSL_memset(&tmp, 0, sizeof(EC_RAW_POINT));
|
||||
for (size_t j = 0; j < OPENSSL_ARRAY_SIZE(precomp); j++) {
|
||||
BN_ULONG mask = constant_time_eq_w(j, window);
|
||||
ec_felem_select(group, &tmp.X, mask, &precomp[j].X, &tmp.X);
|
||||
ec_felem_select(group, &tmp.Y, mask, &precomp[j].Y, &tmp.Y);
|
||||
ec_felem_select(group, &tmp.Z, mask, &precomp[j].Z, &tmp.Z);
|
||||
ec_point_select(group, &tmp, mask, &precomp[j], &tmp);
|
||||
}
|
||||
|
||||
if (r_is_at_infinity) {
|
||||
@@ -82,3 +80,191 @@ void ec_GFp_mont_mul_base(const EC_GROUP *group, EC_RAW_POINT *r,
|
||||
const EC_SCALAR *scalar) {
|
||||
ec_GFp_mont_mul(group, r, &group->generator->raw, scalar);
|
||||
}
|
||||
|
||||
static void ec_GFp_mont_batch_precomp(const EC_GROUP *group, EC_RAW_POINT *out,
|
||||
size_t num, const EC_RAW_POINT *p) {
|
||||
assert(num > 1);
|
||||
ec_GFp_simple_point_set_to_infinity(group, &out[0]);
|
||||
ec_GFp_simple_point_copy(&out[1], p);
|
||||
for (size_t j = 2; j < num; j++) {
|
||||
if (j & 1) {
|
||||
ec_GFp_mont_add(group, &out[j], &out[1], &out[j - 1]);
|
||||
} else {
|
||||
ec_GFp_mont_dbl(group, &out[j], &out[j / 2]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static void ec_GFp_mont_batch_get_window(const EC_GROUP *group,
|
||||
EC_RAW_POINT *out,
|
||||
const EC_RAW_POINT precomp[17],
|
||||
const EC_SCALAR *scalar, unsigned i) {
|
||||
const size_t width = group->order.width;
|
||||
uint8_t window = bn_is_bit_set_words(scalar->words, width, i + 4) << 5;
|
||||
window |= bn_is_bit_set_words(scalar->words, width, i + 3) << 4;
|
||||
window |= bn_is_bit_set_words(scalar->words, width, i + 2) << 3;
|
||||
window |= bn_is_bit_set_words(scalar->words, width, i + 1) << 2;
|
||||
window |= bn_is_bit_set_words(scalar->words, width, i) << 1;
|
||||
if (i > 0) {
|
||||
window |= bn_is_bit_set_words(scalar->words, width, i - 1);
|
||||
}
|
||||
uint8_t sign, digit;
|
||||
ec_GFp_nistp_recode_scalar_bits(&sign, &digit, window);
|
||||
|
||||
// Select the entry in constant-time.
|
||||
OPENSSL_memset(out, 0, sizeof(EC_RAW_POINT));
|
||||
for (size_t j = 0; j < 17; j++) {
|
||||
BN_ULONG mask = constant_time_eq_w(j, digit);
|
||||
ec_point_select(group, out, mask, &precomp[j], out);
|
||||
}
|
||||
|
||||
// Negate if necessary.
|
||||
EC_FELEM neg_Y;
|
||||
ec_felem_neg(group, &neg_Y, &out->Y);
|
||||
BN_ULONG sign_mask = sign;
|
||||
sign_mask = 0u - sign_mask;
|
||||
ec_felem_select(group, &out->Y, sign_mask, &neg_Y, &out->Y);
|
||||
}
|
||||
|
||||
void ec_GFp_mont_mul_batch(const EC_GROUP *group, EC_RAW_POINT *r,
|
||||
const EC_RAW_POINT *p0, const EC_SCALAR *scalar0,
|
||||
const EC_RAW_POINT *p1, const EC_SCALAR *scalar1,
|
||||
const EC_RAW_POINT *p2, const EC_SCALAR *scalar2) {
|
||||
EC_RAW_POINT precomp[3][17];
|
||||
ec_GFp_mont_batch_precomp(group, precomp[0], 17, p0);
|
||||
ec_GFp_mont_batch_precomp(group, precomp[1], 17, p1);
|
||||
if (p2 != NULL) {
|
||||
ec_GFp_mont_batch_precomp(group, precomp[2], 17, p2);
|
||||
}
|
||||
|
||||
// Divide bits in |scalar| into windows.
|
||||
unsigned bits = BN_num_bits(&group->order);
|
||||
int r_is_at_infinity = 1;
|
||||
for (unsigned i = bits; i <= bits; i--) {
|
||||
if (!r_is_at_infinity) {
|
||||
ec_GFp_mont_dbl(group, r, r);
|
||||
}
|
||||
if (i % 5 == 0) {
|
||||
EC_RAW_POINT tmp;
|
||||
ec_GFp_mont_batch_get_window(group, &tmp, precomp[0], scalar0, i);
|
||||
if (r_is_at_infinity) {
|
||||
ec_GFp_simple_point_copy(r, &tmp);
|
||||
r_is_at_infinity = 0;
|
||||
} else {
|
||||
ec_GFp_mont_add(group, r, r, &tmp);
|
||||
}
|
||||
|
||||
ec_GFp_mont_batch_get_window(group, &tmp, precomp[1], scalar1, i);
|
||||
ec_GFp_mont_add(group, r, r, &tmp);
|
||||
|
||||
if (p2 != NULL) {
|
||||
ec_GFp_mont_batch_get_window(group, &tmp, precomp[2], scalar2, i);
|
||||
ec_GFp_mont_add(group, r, r, &tmp);
|
||||
}
|
||||
}
|
||||
}
|
||||
if (r_is_at_infinity) {
|
||||
ec_GFp_simple_point_set_to_infinity(group, r);
|
||||
}
|
||||
}
|
||||
|
||||
static unsigned ec_GFp_mont_comb_stride(const EC_GROUP *group) {
|
||||
return (BN_num_bits(&group->field) + EC_MONT_PRECOMP_COMB_SIZE - 1) /
|
||||
EC_MONT_PRECOMP_COMB_SIZE;
|
||||
}
|
||||
|
||||
int ec_GFp_mont_init_precomp(const EC_GROUP *group, EC_PRECOMP *out,
|
||||
const EC_RAW_POINT *p) {
|
||||
// comb[i - 1] stores the ith element of the comb. That is, if i is
|
||||
// b4 * 2^4 + b3 * 2^3 + ... + b0 * 2^0, it stores k * |p|, where k is
|
||||
// b4 * 2^(4*stride) + b3 * 2^(3*stride) + ... + b0 * 2^(0*stride). stride
|
||||
// here is |ec_GFp_mont_comb_stride|. We store at index i - 1 because the 0th
|
||||
// comb entry is always infinity.
|
||||
EC_RAW_POINT comb[(1 << EC_MONT_PRECOMP_COMB_SIZE) - 1];
|
||||
unsigned stride = ec_GFp_mont_comb_stride(group);
|
||||
|
||||
// We compute the comb sequentially by the highest set bit. Initially, all
|
||||
// entries up to 2^0 are filled.
|
||||
comb[(1 << 0) - 1] = *p;
|
||||
for (unsigned i = 1; i < EC_MONT_PRECOMP_COMB_SIZE; i++) {
|
||||
// Compute entry 2^i by doubling the entry for 2^(i-1) |stride| times.
|
||||
unsigned bit = 1 << i;
|
||||
ec_GFp_mont_dbl(group, &comb[bit - 1], &comb[bit / 2 - 1]);
|
||||
for (unsigned j = 1; j < stride; j++) {
|
||||
ec_GFp_mont_dbl(group, &comb[bit - 1], &comb[bit - 1]);
|
||||
}
|
||||
// Compute entries from 2^i + 1 to 2^i + (2^i - 1) by adding entry 2^i to
|
||||
// a previous entry.
|
||||
for (unsigned j = 1; j < bit; j++) {
|
||||
ec_GFp_mont_add(group, &comb[bit + j - 1], &comb[bit - 1], &comb[j - 1]);
|
||||
}
|
||||
}
|
||||
|
||||
// Store the comb in affine coordinates to shrink the table. (This reduces
|
||||
// cache pressure and makes the constant-time selects faster.)
|
||||
OPENSSL_STATIC_ASSERT(
|
||||
OPENSSL_ARRAY_SIZE(comb) == OPENSSL_ARRAY_SIZE(out->comb),
|
||||
"comb sizes did not match");
|
||||
return ec_jacobian_to_affine_batch(group, out->comb, comb,
|
||||
OPENSSL_ARRAY_SIZE(comb));
|
||||
}
|
||||
|
||||
static void ec_GFp_mont_get_comb_window(const EC_GROUP *group,
|
||||
EC_RAW_POINT *out,
|
||||
const EC_PRECOMP *precomp,
|
||||
const EC_SCALAR *scalar, unsigned i) {
|
||||
const size_t width = group->order.width;
|
||||
unsigned stride = ec_GFp_mont_comb_stride(group);
|
||||
// Select the bits corresponding to the comb shifted up by |i|.
|
||||
unsigned window = 0;
|
||||
for (unsigned j = 0; j < EC_MONT_PRECOMP_COMB_SIZE; j++) {
|
||||
window |= bn_is_bit_set_words(scalar->words, width, j * stride + i)
|
||||
<< j;
|
||||
}
|
||||
|
||||
// Select precomp->comb[window - 1]. If |window| is zero, |match| will always
|
||||
// be zero, which will leave |out| at infinity.
|
||||
OPENSSL_memset(out, 0, sizeof(EC_RAW_POINT));
|
||||
for (unsigned j = 0; j < OPENSSL_ARRAY_SIZE(precomp->comb); j++) {
|
||||
BN_ULONG match = constant_time_eq_w(window, j + 1);
|
||||
ec_felem_select(group, &out->X, match, &precomp->comb[j].X, &out->X);
|
||||
ec_felem_select(group, &out->Y, match, &precomp->comb[j].Y, &out->Y);
|
||||
}
|
||||
BN_ULONG is_infinity = constant_time_is_zero_w(window);
|
||||
ec_felem_select(group, &out->Z, is_infinity, &out->Z, &group->one);
|
||||
}
|
||||
|
||||
void ec_GFp_mont_mul_precomp(const EC_GROUP *group, EC_RAW_POINT *r,
|
||||
const EC_PRECOMP *p0, const EC_SCALAR *scalar0,
|
||||
const EC_PRECOMP *p1, const EC_SCALAR *scalar1,
|
||||
const EC_PRECOMP *p2, const EC_SCALAR *scalar2) {
|
||||
unsigned stride = ec_GFp_mont_comb_stride(group);
|
||||
int r_is_at_infinity = 1;
|
||||
for (unsigned i = stride - 1; i < stride; i--) {
|
||||
if (!r_is_at_infinity) {
|
||||
ec_GFp_mont_dbl(group, r, r);
|
||||
}
|
||||
|
||||
EC_RAW_POINT tmp;
|
||||
ec_GFp_mont_get_comb_window(group, &tmp, p0, scalar0, i);
|
||||
if (r_is_at_infinity) {
|
||||
ec_GFp_simple_point_copy(r, &tmp);
|
||||
r_is_at_infinity = 0;
|
||||
} else {
|
||||
ec_GFp_mont_add(group, r, r, &tmp);
|
||||
}
|
||||
|
||||
if (p1 != NULL) {
|
||||
ec_GFp_mont_get_comb_window(group, &tmp, p1, scalar1, i);
|
||||
ec_GFp_mont_add(group, r, r, &tmp);
|
||||
}
|
||||
|
||||
if (p2 != NULL) {
|
||||
ec_GFp_mont_get_comb_window(group, &tmp, p2, scalar2, i);
|
||||
ec_GFp_mont_add(group, r, r, &tmp);
|
||||
}
|
||||
}
|
||||
if (r_is_at_infinity) {
|
||||
ec_GFp_simple_point_set_to_infinity(group, r);
|
||||
}
|
||||
}
|
||||
@@ -72,6 +72,7 @@
|
||||
|
||||
#include <CCryptoBoringSSL_bn.h>
|
||||
#include <CCryptoBoringSSL_err.h>
|
||||
#include <CCryptoBoringSSL_mem.h>
|
||||
#include <CCryptoBoringSSL_thread.h>
|
||||
|
||||
#include "internal.h"
|
||||
@@ -174,24 +175,57 @@ static void lookup_precomp(const EC_GROUP *group, EC_RAW_POINT *out,
|
||||
// EC_WNAF_TABLE_SIZE is the table size to use for |ec_GFp_mont_mul_public|.
|
||||
#define EC_WNAF_TABLE_SIZE (1 << (EC_WNAF_WINDOW_BITS - 1))
|
||||
|
||||
void ec_GFp_mont_mul_public(const EC_GROUP *group, EC_RAW_POINT *r,
|
||||
const EC_SCALAR *g_scalar, const EC_RAW_POINT *p,
|
||||
const EC_SCALAR *p_scalar) {
|
||||
// EC_WNAF_STACK is the number of points worth of data to stack-allocate and
|
||||
// avoid a malloc.
|
||||
#define EC_WNAF_STACK 3
|
||||
|
||||
int ec_GFp_mont_mul_public_batch(const EC_GROUP *group, EC_RAW_POINT *r,
|
||||
const EC_SCALAR *g_scalar,
|
||||
const EC_RAW_POINT *points,
|
||||
const EC_SCALAR *scalars, size_t num) {
|
||||
size_t bits = BN_num_bits(&group->order);
|
||||
size_t wNAF_len = bits + 1;
|
||||
|
||||
int ret = 0;
|
||||
int8_t wNAF_stack[EC_WNAF_STACK][EC_MAX_BYTES * 8 + 1];
|
||||
int8_t (*wNAF_alloc)[EC_MAX_BYTES * 8 + 1] = NULL;
|
||||
int8_t (*wNAF)[EC_MAX_BYTES * 8 + 1];
|
||||
EC_RAW_POINT precomp_stack[EC_WNAF_STACK][EC_WNAF_TABLE_SIZE];
|
||||
EC_RAW_POINT (*precomp_alloc)[EC_WNAF_TABLE_SIZE] = NULL;
|
||||
EC_RAW_POINT (*precomp)[EC_WNAF_TABLE_SIZE];
|
||||
if (num <= EC_WNAF_STACK) {
|
||||
wNAF = wNAF_stack;
|
||||
precomp = precomp_stack;
|
||||
} else {
|
||||
if (num >= ((size_t)-1) / sizeof(wNAF_alloc[0]) ||
|
||||
num >= ((size_t)-1) / sizeof(precomp_alloc[0])) {
|
||||
OPENSSL_PUT_ERROR(EC, ERR_R_OVERFLOW);
|
||||
goto err;
|
||||
}
|
||||
wNAF_alloc = OPENSSL_malloc(num * sizeof(wNAF_alloc[0]));
|
||||
precomp_alloc = OPENSSL_malloc(num * sizeof(precomp_alloc[0]));
|
||||
if (wNAF_alloc == NULL || precomp_alloc == NULL) {
|
||||
OPENSSL_PUT_ERROR(EC, ERR_R_MALLOC_FAILURE);
|
||||
goto err;
|
||||
}
|
||||
wNAF = wNAF_alloc;
|
||||
precomp = precomp_alloc;
|
||||
}
|
||||
|
||||
int8_t g_wNAF[EC_MAX_BYTES * 8 + 1];
|
||||
EC_RAW_POINT g_precomp[EC_WNAF_TABLE_SIZE];
|
||||
assert(wNAF_len <= OPENSSL_ARRAY_SIZE(g_wNAF));
|
||||
const EC_RAW_POINT *g = &group->generator->raw;
|
||||
ec_compute_wNAF(group, g_wNAF, g_scalar, bits, EC_WNAF_WINDOW_BITS);
|
||||
compute_precomp(group, g_precomp, g, EC_WNAF_TABLE_SIZE);
|
||||
if (g_scalar != NULL) {
|
||||
ec_compute_wNAF(group, g_wNAF, g_scalar, bits, EC_WNAF_WINDOW_BITS);
|
||||
compute_precomp(group, g_precomp, g, EC_WNAF_TABLE_SIZE);
|
||||
}
|
||||
|
||||
int8_t p_wNAF[EC_MAX_BYTES * 8 + 1];
|
||||
EC_RAW_POINT p_precomp[EC_WNAF_TABLE_SIZE];
|
||||
assert(wNAF_len <= OPENSSL_ARRAY_SIZE(p_wNAF));
|
||||
ec_compute_wNAF(group, p_wNAF, p_scalar, bits, EC_WNAF_WINDOW_BITS);
|
||||
compute_precomp(group, p_precomp, p, EC_WNAF_TABLE_SIZE);
|
||||
for (size_t i = 0; i < num; i++) {
|
||||
assert(wNAF_len <= OPENSSL_ARRAY_SIZE(wNAF[i]));
|
||||
ec_compute_wNAF(group, wNAF[i], &scalars[i], bits, EC_WNAF_WINDOW_BITS);
|
||||
compute_precomp(group, precomp[i], &points[i], EC_WNAF_TABLE_SIZE);
|
||||
}
|
||||
|
||||
EC_RAW_POINT tmp;
|
||||
int r_is_at_infinity = 1;
|
||||
@@ -200,7 +234,7 @@ void ec_GFp_mont_mul_public(const EC_GROUP *group, EC_RAW_POINT *r,
|
||||
ec_GFp_mont_dbl(group, r, r);
|
||||
}
|
||||
|
||||
if (g_wNAF[k] != 0) {
|
||||
if (g_scalar != NULL && g_wNAF[k] != 0) {
|
||||
lookup_precomp(group, &tmp, g_precomp, g_wNAF[k]);
|
||||
if (r_is_at_infinity) {
|
||||
ec_GFp_simple_point_copy(r, &tmp);
|
||||
@@ -210,13 +244,15 @@ void ec_GFp_mont_mul_public(const EC_GROUP *group, EC_RAW_POINT *r,
|
||||
}
|
||||
}
|
||||
|
||||
if (p_wNAF[k] != 0) {
|
||||
lookup_precomp(group, &tmp, p_precomp, p_wNAF[k]);
|
||||
if (r_is_at_infinity) {
|
||||
ec_GFp_simple_point_copy(r, &tmp);
|
||||
r_is_at_infinity = 0;
|
||||
} else {
|
||||
ec_GFp_mont_add(group, r, r, &tmp);
|
||||
for (size_t i = 0; i < num; i++) {
|
||||
if (wNAF[i][k] != 0) {
|
||||
lookup_precomp(group, &tmp, precomp[i], wNAF[i][k]);
|
||||
if (r_is_at_infinity) {
|
||||
ec_GFp_simple_point_copy(r, &tmp);
|
||||
r_is_at_infinity = 0;
|
||||
} else {
|
||||
ec_GFp_mont_add(group, r, r, &tmp);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -224,4 +260,11 @@ void ec_GFp_mont_mul_public(const EC_GROUP *group, EC_RAW_POINT *r,
|
||||
if (r_is_at_infinity) {
|
||||
ec_GFp_simple_point_set_to_infinity(group, r);
|
||||
}
|
||||
|
||||
ret = 1;
|
||||
|
||||
err:
|
||||
OPENSSL_free(wNAF_alloc);
|
||||
OPENSSL_free(precomp_alloc);
|
||||
return ret;
|
||||
}
|
||||
@@ -94,8 +94,8 @@ int ECDH_compute_key_fips(uint8_t *out, size_t out_len, const EC_POINT *pub_key,
|
||||
uint8_t buf[EC_MAX_BYTES];
|
||||
size_t buflen;
|
||||
if (!ec_point_mul_scalar(group, &shared_point, &pub_key->raw, priv) ||
|
||||
!ec_point_get_affine_coordinate_bytes(group, buf, NULL, &buflen,
|
||||
sizeof(buf), &shared_point)) {
|
||||
!ec_get_x_coordinate_as_bytes(group, buf, &buflen, sizeof(buf),
|
||||
&shared_point)) {
|
||||
OPENSSL_PUT_ERROR(ECDH, ECDH_R_POINT_ARITHMETIC_FAILURE);
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -122,6 +122,14 @@ void ECDSA_SIG_free(ECDSA_SIG *sig) {
|
||||
OPENSSL_free(sig);
|
||||
}
|
||||
|
||||
const BIGNUM *ECDSA_SIG_get0_r(const ECDSA_SIG *sig) {
|
||||
return sig->r;
|
||||
}
|
||||
|
||||
const BIGNUM *ECDSA_SIG_get0_s(const ECDSA_SIG *sig) {
|
||||
return sig->s;
|
||||
}
|
||||
|
||||
void ECDSA_SIG_get0(const ECDSA_SIG *sig, const BIGNUM **out_r,
|
||||
const BIGNUM **out_s) {
|
||||
if (out_r != NULL) {
|
||||
@@ -161,8 +169,11 @@ int ECDSA_do_verify(const uint8_t *digest, size_t digest_len,
|
||||
return 0;
|
||||
}
|
||||
|
||||
// s_inv_mont = s^-1 in the Montgomery domain. This is
|
||||
ec_scalar_inv_montgomery_vartime(group, &s_inv_mont, &s);
|
||||
// s_inv_mont = s^-1 in the Montgomery domain.
|
||||
if (!ec_scalar_to_montgomery_inv_vartime(group, &s_inv_mont, &s)) {
|
||||
OPENSSL_PUT_ERROR(ECDSA, ERR_R_INTERNAL_ERROR);
|
||||
return 0;
|
||||
}
|
||||
|
||||
// u1 = m * s^-1 mod order
|
||||
// u2 = r * s^-1 mod order
|
||||
@@ -208,6 +219,10 @@ static int ecdsa_sign_setup(const EC_KEY *eckey, EC_SCALAR *out_kinv_mont,
|
||||
if (!ec_bignum_to_scalar(group, &k, eckey->fixed_k)) {
|
||||
goto err;
|
||||
}
|
||||
if (ec_scalar_is_zero(group, &k)) {
|
||||
OPENSSL_PUT_ERROR(ECDSA, ERR_R_INTERNAL_ERROR);
|
||||
goto err;
|
||||
}
|
||||
} else {
|
||||
// Pass a SHA512 hash of the private key and digest as additional data
|
||||
// into the RBG. This is a hardening measure against entropy failure.
|
||||
@@ -225,10 +240,10 @@ static int ecdsa_sign_setup(const EC_KEY *eckey, EC_SCALAR *out_kinv_mont,
|
||||
}
|
||||
|
||||
// Compute k^-1 in the Montgomery domain. This is |ec_scalar_to_montgomery|
|
||||
// followed by |ec_scalar_inv_montgomery|, but |ec_scalar_inv_montgomery|
|
||||
// followed by |ec_scalar_inv0_montgomery|, but |ec_scalar_inv0_montgomery|
|
||||
// followed by |ec_scalar_from_montgomery| is equivalent and slightly more
|
||||
// efficient.
|
||||
ec_scalar_inv_montgomery(group, out_kinv_mont, &k);
|
||||
// efficient. Note k is non-zero, so the inverse must exist.
|
||||
ec_scalar_inv0_montgomery(group, out_kinv_mont, &k);
|
||||
ec_scalar_from_montgomery(group, out_kinv_mont, out_kinv_mont);
|
||||
|
||||
// Compute r, the x-coordinate of generator * k.
|
||||
|
||||
@@ -1121,8 +1121,6 @@ gcm_ghash_avx:
|
||||
.byte 1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0xc2
|
||||
.L7_mask:
|
||||
.long 7,0,7,0
|
||||
.L7_mask_poly:
|
||||
.long 7,0,450,0
|
||||
.align 64
|
||||
|
||||
.byte 71,72,65,83,72,32,102,111,114,32,120,56,54,95,54,52,44,32,67,82,89,80,84,79,71,65,77,83,32,98,121,32,60,97,112,112,114,111,64,111,112,101,110,115,115,108,46,111,114,103,62,0
|
||||
|
||||
@@ -1120,8 +1120,6 @@ L$0x1c2_polynomial:
|
||||
.byte 1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0xc2
|
||||
L$7_mask:
|
||||
.long 7,0,7,0
|
||||
L$7_mask_poly:
|
||||
.long 7,0,450,0
|
||||
.p2align 6
|
||||
|
||||
.byte 71,72,65,83,72,32,102,111,114,32,120,56,54,95,54,52,44,32,67,82,89,80,84,79,71,65,77,83,32,98,121,32,60,97,112,112,114,111,64,111,112,101,110,115,115,108,46,111,114,103,62,0
|
||||
|
||||
@@ -0,0 +1,137 @@
|
||||
/* Copyright (c) 2020, Google Inc.
|
||||
*
|
||||
* Permission to use, copy, modify, and/or distribute this software for any
|
||||
* purpose with or without fee is hereby granted, provided that the above
|
||||
* copyright notice and this permission notice appear in all copies.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
|
||||
* WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
|
||||
* MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
|
||||
* SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
|
||||
* WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION
|
||||
* OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
|
||||
* CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. */
|
||||
|
||||
#if !defined(_GNU_SOURCE)
|
||||
#define _GNU_SOURCE // needed for madvise() and MAP_ANONYMOUS on Linux.
|
||||
#endif
|
||||
|
||||
#include <CCryptoBoringSSL_base.h>
|
||||
|
||||
#include "fork_detect.h"
|
||||
|
||||
#if defined(OPENSSL_LINUX)
|
||||
#include <sys/mman.h>
|
||||
#include <unistd.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
#include <CCryptoBoringSSL_type_check.h>
|
||||
|
||||
#include "../delocate.h"
|
||||
#include "../../internal.h"
|
||||
|
||||
|
||||
#if defined(MADV_WIPEONFORK)
|
||||
OPENSSL_STATIC_ASSERT(MADV_WIPEONFORK == 18, "MADV_WIPEONFORK is not 18");
|
||||
#else
|
||||
#define MADV_WIPEONFORK 18
|
||||
#endif
|
||||
|
||||
DEFINE_STATIC_ONCE(g_fork_detect_once);
|
||||
DEFINE_STATIC_MUTEX(g_fork_detect_lock);
|
||||
DEFINE_BSS_GET(volatile char *, g_fork_detect_addr);
|
||||
DEFINE_BSS_GET(uint64_t, g_fork_generation);
|
||||
DEFINE_BSS_GET(int, g_ignore_madv_wipeonfork);
|
||||
|
||||
static void init_fork_detect(void) {
|
||||
if (*g_ignore_madv_wipeonfork_bss_get()) {
|
||||
return;
|
||||
}
|
||||
|
||||
long page_size = sysconf(_SC_PAGESIZE);
|
||||
if (page_size <= 0) {
|
||||
return;
|
||||
}
|
||||
|
||||
void *addr = mmap(NULL, (size_t)page_size, PROT_READ | PROT_WRITE,
|
||||
MAP_PRIVATE | MAP_ANONYMOUS, -1, 0);
|
||||
if (addr == MAP_FAILED) {
|
||||
return;
|
||||
}
|
||||
|
||||
// Some versions of qemu (up to at least 5.0.0-rc4, see linux-user/syscall.c)
|
||||
// ignore |madvise| calls and just return zero (i.e. success). But we need to
|
||||
// know whether MADV_WIPEONFORK actually took effect. Therefore try an invalid
|
||||
// call to check that the implementation of |madvise| is actually rejecting
|
||||
// unknown |advice| values.
|
||||
if (madvise(addr, (size_t)page_size, -1) == 0 ||
|
||||
madvise(addr, (size_t)page_size, MADV_WIPEONFORK) != 0) {
|
||||
munmap(addr, (size_t)page_size);
|
||||
return;
|
||||
}
|
||||
|
||||
*((volatile char *) addr) = 1;
|
||||
*g_fork_detect_addr_bss_get() = addr;
|
||||
*g_fork_generation_bss_get() = 1;
|
||||
}
|
||||
|
||||
uint64_t CRYPTO_get_fork_generation(void) {
|
||||
// In a single-threaded process, there are obviously no races because there's
|
||||
// only a single mutator in the address space.
|
||||
//
|
||||
// In a multi-threaded environment, |CRYPTO_once| ensures that the flag byte
|
||||
// is initialised atomically, even if multiple threads enter this function
|
||||
// concurrently.
|
||||
//
|
||||
// In the limit, the kernel may clear WIPEONFORK pages while a multi-threaded
|
||||
// process is running. (For example, because a VM was cloned.) Therefore a
|
||||
// lock is used below to synchronise the potentially multiple threads that may
|
||||
// concurrently observe the cleared flag.
|
||||
|
||||
CRYPTO_once(g_fork_detect_once_bss_get(), init_fork_detect);
|
||||
// This pointer is |volatile| because the value pointed to may be changed by
|
||||
// external forces (i.e. the kernel wiping the page) thus the compiler must
|
||||
// not assume that it has exclusive access to it.
|
||||
volatile char *const flag_ptr = *g_fork_detect_addr_bss_get();
|
||||
if (flag_ptr == NULL) {
|
||||
// Our kernel is too old to support |MADV_WIPEONFORK|.
|
||||
return 0;
|
||||
}
|
||||
|
||||
struct CRYPTO_STATIC_MUTEX *const lock = g_fork_detect_lock_bss_get();
|
||||
uint64_t *const generation_ptr = g_fork_generation_bss_get();
|
||||
|
||||
CRYPTO_STATIC_MUTEX_lock_read(lock);
|
||||
uint64_t current_generation = *generation_ptr;
|
||||
if (*flag_ptr) {
|
||||
CRYPTO_STATIC_MUTEX_unlock_read(lock);
|
||||
return current_generation;
|
||||
}
|
||||
|
||||
CRYPTO_STATIC_MUTEX_unlock_read(lock);
|
||||
CRYPTO_STATIC_MUTEX_lock_write(lock);
|
||||
current_generation = *generation_ptr;
|
||||
if (*flag_ptr == 0) {
|
||||
// A fork has occurred.
|
||||
*flag_ptr = 1;
|
||||
|
||||
current_generation++;
|
||||
if (current_generation == 0) {
|
||||
current_generation = 1;
|
||||
}
|
||||
*generation_ptr = current_generation;
|
||||
}
|
||||
CRYPTO_STATIC_MUTEX_unlock_write(lock);
|
||||
|
||||
return current_generation;
|
||||
}
|
||||
|
||||
void CRYPTO_fork_detect_ignore_madv_wipeonfork_for_testing(void) {
|
||||
*g_ignore_madv_wipeonfork_bss_get() = 1;
|
||||
}
|
||||
|
||||
#else // !OPENSSL_LINUX
|
||||
|
||||
uint64_t CRYPTO_get_fork_generation(void) { return 0; }
|
||||
|
||||
#endif // OPENSSL_LINUX
|
||||
@@ -0,0 +1,49 @@
|
||||
/* Copyright (c) 2020, Google Inc.
|
||||
*
|
||||
* Permission to use, copy, modify, and/or distribute this software for any
|
||||
* purpose with or without fee is hereby granted, provided that the above
|
||||
* copyright notice and this permission notice appear in all copies.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
|
||||
* WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
|
||||
* MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
|
||||
* SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
|
||||
* WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION
|
||||
* OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
|
||||
* CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. */
|
||||
|
||||
#ifndef OPENSSL_HEADER_CRYPTO_FORK_DETECT_H
|
||||
#define OPENSSL_HEADER_CRYPTO_FORK_DETECT_H
|
||||
|
||||
#include <CCryptoBoringSSL_base.h>
|
||||
|
||||
#if defined(__cplusplus)
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
|
||||
// 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_ignore_madv_wipeonfork_for_testing is an internal detail
|
||||
// used for testing purposes.
|
||||
OPENSSL_EXPORT void CRYPTO_fork_detect_ignore_madv_wipeonfork_for_testing(void);
|
||||
|
||||
#if defined(__cplusplus)
|
||||
} // extern C
|
||||
#endif
|
||||
|
||||
#endif // OPENSSL_HEADER_CRYPTO_FORK_DETECT_H
|
||||
@@ -0,0 +1,64 @@
|
||||
/* Copyright (c) 2020, Google Inc.
|
||||
*
|
||||
* Permission to use, copy, modify, and/or distribute this software for any
|
||||
* purpose with or without fee is hereby granted, provided that the above
|
||||
* copyright notice and this permission notice appear in all copies.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
|
||||
* WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
|
||||
* MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
|
||||
* SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
|
||||
* WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION
|
||||
* OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
|
||||
* CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. */
|
||||
|
||||
#ifndef OPENSSL_HEADER_CRYPTO_RAND_GETRANDOM_FILLIN_H
|
||||
#define OPENSSL_HEADER_CRYPTO_RAND_GETRANDOM_FILLIN_H
|
||||
|
||||
#include <CCryptoBoringSSL_base.h>
|
||||
|
||||
|
||||
#if defined(OPENSSL_LINUX)
|
||||
|
||||
#include <sys/syscall.h>
|
||||
|
||||
#if defined(OPENSSL_X86_64)
|
||||
#define EXPECTED_NR_getrandom 318
|
||||
#elif defined(OPENSSL_X86)
|
||||
#define EXPECTED_NR_getrandom 355
|
||||
#elif defined(OPENSSL_AARCH64)
|
||||
#define EXPECTED_NR_getrandom 278
|
||||
#elif defined(OPENSSL_ARM)
|
||||
#define EXPECTED_NR_getrandom 384
|
||||
#elif defined(OPENSSL_PPC64LE)
|
||||
#define EXPECTED_NR_getrandom 359
|
||||
#endif
|
||||
|
||||
#if defined(EXPECTED_NR_getrandom)
|
||||
#define USE_NR_getrandom
|
||||
|
||||
#if defined(__NR_getrandom)
|
||||
|
||||
#if __NR_getrandom != EXPECTED_NR_getrandom
|
||||
#error "system call number for getrandom is not the expected value"
|
||||
#endif
|
||||
|
||||
#else // __NR_getrandom
|
||||
|
||||
#define __NR_getrandom EXPECTED_NR_getrandom
|
||||
|
||||
#endif // __NR_getrandom
|
||||
|
||||
#endif // EXPECTED_NR_getrandom
|
||||
|
||||
#if !defined(GRND_NONBLOCK)
|
||||
#define GRND_NONBLOCK 1
|
||||
#endif
|
||||
#if !defined(GRND_RANDOM)
|
||||
#define GRND_RANDOM 2
|
||||
#endif
|
||||
|
||||
#endif // OPENSSL_LINUX
|
||||
|
||||
|
||||
#endif // OPENSSL_HEADER_CRYPTO_RAND_GETRANDOM_FILLIN_H
|
||||
@@ -40,17 +40,33 @@ void RAND_bytes_with_additional_data(uint8_t *out, size_t out_len,
|
||||
// system.
|
||||
void CRYPTO_sysrand(uint8_t *buf, size_t len);
|
||||
|
||||
#if defined(OPENSSL_URANDOM) || defined(BORINGSSL_UNSAFE_DETERMINISTIC_MODE)
|
||||
#if defined(OPENSSL_URANDOM)
|
||||
// CRYPTO_init_sysrand initializes long-lived resources needed to draw entropy
|
||||
// from the operating system.
|
||||
void CRYPTO_init_sysrand(void);
|
||||
|
||||
// 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);
|
||||
|
||||
// CRYPTO_sysrand_if_available fills |len| bytes at |buf| with entropy from the
|
||||
// operating system, if the entropy pool is initialized. If it is uninitialized,
|
||||
// it will not block and will instead fill |buf| with all zeros or early
|
||||
// /dev/urandom output.
|
||||
void CRYPTO_sysrand_if_available(uint8_t *buf, size_t len);
|
||||
// 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);
|
||||
#else
|
||||
OPENSSL_INLINE void CRYPTO_init_sysrand(void) {}
|
||||
|
||||
OPENSSL_INLINE void CRYPTO_sysrand_for_seed(uint8_t *buf, size_t len) {
|
||||
CRYPTO_sysrand(buf, len);
|
||||
}
|
||||
|
||||
OPENSSL_INLINE int CRYPTO_sysrand_if_available(uint8_t *buf, size_t len) {
|
||||
CRYPTO_sysrand(buf, len);
|
||||
return 1;
|
||||
}
|
||||
#endif
|
||||
|
||||
// rand_fork_unsafe_buffering_enabled returns whether fork-unsafe buffering has
|
||||
@@ -105,10 +121,19 @@ OPENSSL_EXPORT void CTR_DRBG_clear(CTR_DRBG_STATE *drbg);
|
||||
|
||||
|
||||
#if defined(OPENSSL_X86_64) && !defined(OPENSSL_NO_ASM)
|
||||
|
||||
OPENSSL_INLINE int have_rdrand(void) {
|
||||
return (OPENSSL_ia32cap_get()[1] & (1u << 30)) != 0;
|
||||
}
|
||||
|
||||
// have_fast_rdrand returns true if RDRAND is supported and it's reasonably
|
||||
// fast. Concretely the latter is defined by whether the chip is Intel (fast) or
|
||||
// not (assumed slow).
|
||||
OPENSSL_INLINE int have_fast_rdrand(void) {
|
||||
const uint32_t *const ia32cap = OPENSSL_ia32cap_get();
|
||||
return (ia32cap[1] & (1u << 30)) && (ia32cap[0] & (1u << 30));
|
||||
}
|
||||
|
||||
// CRYPTO_rdrand writes eight bytes of random data from the hardware RNG to
|
||||
// |out|. It returns one on success or zero on hardware failure.
|
||||
int CRYPTO_rdrand(uint8_t out[8]);
|
||||
@@ -117,6 +142,17 @@ int CRYPTO_rdrand(uint8_t out[8]);
|
||||
// the hardware RNG. The |len| argument must be a multiple of eight. It returns
|
||||
// one on success and zero on hardware failure.
|
||||
int CRYPTO_rdrand_multiple8_buf(uint8_t *buf, size_t len);
|
||||
|
||||
#else // OPENSSL_X86_64 && !OPENSSL_NO_ASM
|
||||
|
||||
OPENSSL_INLINE int have_rdrand(void) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
OPENSSL_INLINE int have_fast_rdrand(void) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
#endif // OPENSSL_X86_64 && !OPENSSL_NO_ASM
|
||||
|
||||
|
||||
|
||||
@@ -27,6 +27,7 @@
|
||||
#include <CCryptoBoringSSL_mem.h>
|
||||
|
||||
#include "internal.h"
|
||||
#include "fork_detect.h"
|
||||
#include "../../internal.h"
|
||||
#include "../delocate.h"
|
||||
|
||||
@@ -57,6 +58,7 @@ static const unsigned kReseedInterval = 4096;
|
||||
// rand_thread_state contains the per-thread state for the RNG.
|
||||
struct rand_thread_state {
|
||||
CTR_DRBG_STATE drbg;
|
||||
uint64_t fork_generation;
|
||||
// calls is the number of generate calls made on |drbg| since it was last
|
||||
// (re)seeded. This is bound by |kReseedInterval|.
|
||||
unsigned calls;
|
||||
@@ -125,11 +127,9 @@ static void rand_thread_state_free(void *state_in) {
|
||||
|
||||
#if defined(OPENSSL_X86_64) && !defined(OPENSSL_NO_ASM) && \
|
||||
!defined(BORINGSSL_UNSAFE_DETERMINISTIC_MODE)
|
||||
static int hwrand(uint8_t *buf, const size_t len) {
|
||||
if (!have_rdrand()) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
// rdrand should only be called if either |have_rdrand| or |have_fast_rdrand|
|
||||
// returned true.
|
||||
static int rdrand(uint8_t *buf, const size_t len) {
|
||||
const size_t len_multiple8 = len & ~7;
|
||||
if (!CRYPTO_rdrand_multiple8_buf(buf, len_multiple8)) {
|
||||
return 0;
|
||||
@@ -157,7 +157,7 @@ static int hwrand(uint8_t *buf, const size_t len) {
|
||||
|
||||
#else
|
||||
|
||||
static int hwrand(uint8_t *buf, size_t len) {
|
||||
static int rdrand(uint8_t *buf, size_t len) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -168,7 +168,8 @@ static int hwrand(uint8_t *buf, size_t len) {
|
||||
static void rand_get_seed(struct rand_thread_state *state,
|
||||
uint8_t seed[CTR_DRBG_ENTROPY_LEN]) {
|
||||
if (!state->last_block_valid) {
|
||||
if (!hwrand(state->last_block, sizeof(state->last_block))) {
|
||||
if (!have_rdrand() ||
|
||||
!rdrand(state->last_block, sizeof(state->last_block))) {
|
||||
CRYPTO_sysrand_for_seed(state->last_block, sizeof(state->last_block));
|
||||
}
|
||||
state->last_block_valid = 1;
|
||||
@@ -179,8 +180,8 @@ static void rand_get_seed(struct rand_thread_state *state,
|
||||
#define FIPS_OVERREAD 10
|
||||
uint8_t entropy[CTR_DRBG_ENTROPY_LEN * FIPS_OVERREAD];
|
||||
|
||||
int used_hwrand = hwrand(entropy, sizeof(entropy));
|
||||
if (!used_hwrand) {
|
||||
int used_rdrand = have_rdrand() && rdrand(entropy, sizeof(entropy));
|
||||
if (!used_rdrand) {
|
||||
CRYPTO_sysrand_for_seed(entropy, sizeof(entropy));
|
||||
}
|
||||
|
||||
@@ -215,7 +216,7 @@ static void rand_get_seed(struct rand_thread_state *state,
|
||||
#if defined(OPENSSL_URANDOM)
|
||||
// If we used RDRAND, also opportunistically read from the system. This avoids
|
||||
// solely relying on the hardware once the entropy pool has been initialized.
|
||||
if (used_hwrand) {
|
||||
if (used_rdrand) {
|
||||
CRYPTO_sysrand_if_available(entropy, CTR_DRBG_ENTROPY_LEN);
|
||||
for (size_t i = 0; i < CTR_DRBG_ENTROPY_LEN; i++) {
|
||||
seed[i] ^= entropy[i];
|
||||
@@ -241,20 +242,31 @@ void RAND_bytes_with_additional_data(uint8_t *out, size_t out_len,
|
||||
return;
|
||||
}
|
||||
|
||||
const uint64_t fork_generation = CRYPTO_get_fork_generation();
|
||||
|
||||
// Additional data is mixed into every CTR-DRBG call to protect, as best we
|
||||
// can, against forks & VM clones. We do not over-read this information and
|
||||
// don't reseed with it so, from the point of view of FIPS, this doesn't
|
||||
// provide “prediction resistance”. But, in practice, it does.
|
||||
uint8_t additional_data[32];
|
||||
if (!hwrand(additional_data, sizeof(additional_data))) {
|
||||
// Intel chips have fast RDRAND instructions while, in other cases, RDRAND can
|
||||
// be _slower_ than a system call.
|
||||
if (!have_fast_rdrand() ||
|
||||
!rdrand(additional_data, sizeof(additional_data))) {
|
||||
// Without a hardware RNG to save us from address-space duplication, the OS
|
||||
// entropy is used. This can be expensive (one read per |RAND_bytes| call)
|
||||
// and so can be disabled by applications that we have ensured don't fork
|
||||
// and aren't at risk of VM cloning.
|
||||
if (!rand_fork_unsafe_buffering_enabled()) {
|
||||
CRYPTO_sysrand(additional_data, sizeof(additional_data));
|
||||
} else {
|
||||
// and so is disabled when we have fork detection, or if the application has
|
||||
// promised not to fork.
|
||||
if (fork_generation != 0 || rand_fork_unsafe_buffering_enabled()) {
|
||||
OPENSSL_memset(additional_data, 0, sizeof(additional_data));
|
||||
} else if (!have_rdrand()) {
|
||||
// No alternative so block for OS entropy.
|
||||
CRYPTO_sysrand(additional_data, sizeof(additional_data));
|
||||
} else if (!CRYPTO_sysrand_if_available(additional_data,
|
||||
sizeof(additional_data)) &&
|
||||
!rdrand(additional_data, sizeof(additional_data))) {
|
||||
// RDRAND failed: block for OS entropy.
|
||||
CRYPTO_sysrand(additional_data, sizeof(additional_data));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -283,6 +295,7 @@ void RAND_bytes_with_additional_data(uint8_t *out, size_t out_len,
|
||||
abort();
|
||||
}
|
||||
state->calls = 0;
|
||||
state->fork_generation = fork_generation;
|
||||
|
||||
#if defined(BORINGSSL_FIPS)
|
||||
if (state != &stack_state) {
|
||||
@@ -299,7 +312,8 @@ void RAND_bytes_with_additional_data(uint8_t *out, size_t out_len,
|
||||
#endif
|
||||
}
|
||||
|
||||
if (state->calls >= kReseedInterval) {
|
||||
if (state->calls >= kReseedInterval ||
|
||||
state->fork_generation != fork_generation) {
|
||||
uint8_t seed[CTR_DRBG_ENTROPY_LEN];
|
||||
rand_get_seed(state, seed);
|
||||
#if defined(BORINGSSL_FIPS)
|
||||
@@ -317,6 +331,7 @@ void RAND_bytes_with_additional_data(uint8_t *out, size_t out_len,
|
||||
abort();
|
||||
}
|
||||
state->calls = 0;
|
||||
state->fork_generation = fork_generation;
|
||||
} else {
|
||||
#if defined(BORINGSSL_FIPS)
|
||||
CRYPTO_STATIC_MUTEX_lock_read(thread_states_list_lock_bss_get());
|
||||
|
||||
@@ -65,38 +65,12 @@
|
||||
#include <CCryptoBoringSSL_thread.h>
|
||||
#include <CCryptoBoringSSL_mem.h>
|
||||
|
||||
#include "getrandom_fillin.h"
|
||||
#include "../delocate.h"
|
||||
#include "../../internal.h"
|
||||
|
||||
|
||||
#if defined(OPENSSL_LINUX)
|
||||
|
||||
#if defined(OPENSSL_X86_64)
|
||||
#define EXPECTED_NR_getrandom 318
|
||||
#elif defined(OPENSSL_X86)
|
||||
#define EXPECTED_NR_getrandom 355
|
||||
#elif defined(OPENSSL_AARCH64)
|
||||
#define EXPECTED_NR_getrandom 278
|
||||
#elif defined(OPENSSL_ARM)
|
||||
#define EXPECTED_NR_getrandom 384
|
||||
#elif defined(OPENSSL_PPC64LE)
|
||||
#define EXPECTED_NR_getrandom 359
|
||||
#endif
|
||||
|
||||
#if defined(EXPECTED_NR_getrandom)
|
||||
#define USE_NR_getrandom
|
||||
|
||||
#if defined(__NR_getrandom)
|
||||
|
||||
#if __NR_getrandom != EXPECTED_NR_getrandom
|
||||
#error "system call number for getrandom is not the expected value"
|
||||
#endif
|
||||
|
||||
#else // __NR_getrandom
|
||||
|
||||
#define __NR_getrandom EXPECTED_NR_getrandom
|
||||
|
||||
#endif // __NR_getrandom
|
||||
#if defined(USE_NR_getrandom)
|
||||
|
||||
#if defined(OPENSSL_MSAN)
|
||||
void __msan_unpoison(void *, size_t);
|
||||
@@ -119,28 +93,12 @@ static ssize_t boringssl_getrandom(void *buf, size_t buf_len, unsigned flags) {
|
||||
return ret;
|
||||
}
|
||||
|
||||
#endif // EXPECTED_NR_getrandom
|
||||
#endif // USE_NR_getrandom
|
||||
|
||||
#if !defined(GRND_NONBLOCK)
|
||||
#define GRND_NONBLOCK 1
|
||||
#endif
|
||||
#if !defined(GRND_RANDOM)
|
||||
#define GRND_RANDOM 2
|
||||
#endif
|
||||
|
||||
#endif // OPENSSL_LINUX
|
||||
|
||||
// rand_lock is used to protect the |*_requested| variables.
|
||||
DEFINE_STATIC_MUTEX(rand_lock)
|
||||
|
||||
// The following constants are magic values of |urandom_fd|.
|
||||
static const int kUnset = 0;
|
||||
// kHaveGetrandom in |urandom_fd| signals that |getrandom| or |getentropy| is
|
||||
// available and should be used instead.
|
||||
static const int kHaveGetrandom = -3;
|
||||
|
||||
// urandom_fd_requested is set by |RAND_set_urandom_fd|. It's protected by
|
||||
// |rand_lock|.
|
||||
DEFINE_BSS_GET(int, urandom_fd_requested)
|
||||
|
||||
// urandom_fd is a file descriptor to /dev/urandom. It's protected by |once|.
|
||||
DEFINE_BSS_GET(int, urandom_fd)
|
||||
|
||||
@@ -179,14 +137,9 @@ static void maybe_set_extra_getrandom_flags(void) {
|
||||
DEFINE_STATIC_ONCE(rand_once)
|
||||
|
||||
// init_once initializes the state of this module to values previously
|
||||
// requested. This is the only function that modifies |urandom_fd| and
|
||||
// |urandom_buffering|, whose values may be read safely after calling the
|
||||
// once.
|
||||
// requested. This is the only function that modifies |urandom_fd|, which may be
|
||||
// read safely after calling the once.
|
||||
static void init_once(void) {
|
||||
CRYPTO_STATIC_MUTEX_lock_read(rand_lock_bss_get());
|
||||
int fd = *urandom_fd_requested_bss_get();
|
||||
CRYPTO_STATIC_MUTEX_unlock_read(rand_lock_bss_get());
|
||||
|
||||
#if defined(USE_NR_getrandom)
|
||||
int have_getrandom;
|
||||
uint8_t dummy;
|
||||
@@ -229,31 +182,16 @@ static void init_once(void) {
|
||||
abort();
|
||||
#endif
|
||||
|
||||
if (fd == kUnset) {
|
||||
do {
|
||||
fd = open("/dev/urandom", O_RDONLY);
|
||||
} while (fd == -1 && errno == EINTR);
|
||||
}
|
||||
int fd;
|
||||
do {
|
||||
fd = open("/dev/urandom", O_RDONLY);
|
||||
} while (fd == -1 && errno == EINTR);
|
||||
|
||||
if (fd < 0) {
|
||||
perror("failed to open /dev/urandom");
|
||||
abort();
|
||||
}
|
||||
|
||||
assert(kUnset == 0);
|
||||
if (fd == kUnset) {
|
||||
// Because we want to keep |urandom_fd| in the BSS, we have to initialise
|
||||
// it to zero. But zero is a valid file descriptor too. Thus if open
|
||||
// returns zero for /dev/urandom, we dup it to get a non-zero number.
|
||||
fd = dup(fd);
|
||||
close(kUnset);
|
||||
|
||||
if (fd <= 0) {
|
||||
perror("failed to dup /dev/urandom fd");
|
||||
abort();
|
||||
}
|
||||
}
|
||||
|
||||
int flags = fcntl(fd, F_GETFD);
|
||||
if (flags == -1) {
|
||||
// Native Client doesn't implement |fcntl|.
|
||||
@@ -342,40 +280,6 @@ static void wait_for_entropy(void) {
|
||||
#endif // BORINGSSL_FIPS
|
||||
}
|
||||
|
||||
void RAND_set_urandom_fd(int fd) {
|
||||
fd = dup(fd);
|
||||
if (fd < 0) {
|
||||
perror("failed to dup supplied urandom fd");
|
||||
abort();
|
||||
}
|
||||
|
||||
assert(kUnset == 0);
|
||||
if (fd == kUnset) {
|
||||
// Because we want to keep |urandom_fd| in the BSS, we have to initialise
|
||||
// it to zero. But zero is a valid file descriptor too. Thus if dup
|
||||
// returned zero we dup it again to get a non-zero number.
|
||||
fd = dup(fd);
|
||||
close(kUnset);
|
||||
|
||||
if (fd <= 0) {
|
||||
perror("failed to dup supplied urandom fd");
|
||||
abort();
|
||||
}
|
||||
}
|
||||
|
||||
CRYPTO_STATIC_MUTEX_lock_write(rand_lock_bss_get());
|
||||
*urandom_fd_requested_bss_get() = fd;
|
||||
CRYPTO_STATIC_MUTEX_unlock_write(rand_lock_bss_get());
|
||||
|
||||
CRYPTO_once(rand_once_bss_get(), init_once);
|
||||
if (*urandom_fd_bss_get() == kHaveGetrandom) {
|
||||
close(fd);
|
||||
} else if (*urandom_fd_bss_get() != fd) {
|
||||
fprintf(stderr, "RAND_set_urandom_fd called after initialisation.\n");
|
||||
abort();
|
||||
}
|
||||
}
|
||||
|
||||
// fill_with_entropy writes |len| bytes of entropy into |out|. It returns one
|
||||
// on success and zero on error. If |block| is one, this function will block
|
||||
// until the entropy pool is initialized. Otherwise, this function may fail,
|
||||
@@ -397,7 +301,7 @@ static int fill_with_entropy(uint8_t *out, size_t len, int block, int seed) {
|
||||
}
|
||||
#endif
|
||||
|
||||
CRYPTO_once(rand_once_bss_get(), init_once);
|
||||
CRYPTO_init_sysrand();
|
||||
if (block) {
|
||||
CRYPTO_once(wait_for_entropy_once_bss_get(), wait_for_entropy);
|
||||
}
|
||||
@@ -452,6 +356,10 @@ void CRYPTO_sysrand(uint8_t *out, size_t requested) {
|
||||
}
|
||||
}
|
||||
|
||||
void CRYPTO_init_sysrand(void) {
|
||||
CRYPTO_once(rand_once_bss_get(), init_once);
|
||||
}
|
||||
|
||||
#if defined(BORINGSSL_FIPS)
|
||||
void CRYPTO_sysrand_for_seed(uint8_t *out, size_t requested) {
|
||||
if (!fill_with_entropy(out, requested, /*block=*/1, /*seed=*/1)) {
|
||||
@@ -466,16 +374,18 @@ void CRYPTO_sysrand_for_seed(uint8_t *out, size_t requested) {
|
||||
#endif
|
||||
}
|
||||
|
||||
void CRYPTO_sysrand_if_available(uint8_t *out, size_t requested) {
|
||||
// Return all zeros if |fill_with_entropy| fails.
|
||||
OPENSSL_memset(out, 0, requested);
|
||||
#endif // BORINGSSL_FIPS
|
||||
|
||||
if (!fill_with_entropy(out, requested, /*block=*/0, /*seed=*/0) &&
|
||||
errno != EAGAIN) {
|
||||
int CRYPTO_sysrand_if_available(uint8_t *out, size_t requested) {
|
||||
if (fill_with_entropy(out, requested, /*block=*/0, /*seed=*/0)) {
|
||||
return 1;
|
||||
} else if (errno == EAGAIN) {
|
||||
OPENSSL_memset(out, 0, requested);
|
||||
return 0;
|
||||
} else {
|
||||
perror("opportunistic entropy fill failed");
|
||||
abort();
|
||||
}
|
||||
}
|
||||
#endif // BORINGSSL_FIPS
|
||||
|
||||
#endif // OPENSSL_URANDOM
|
||||
@@ -167,6 +167,10 @@ void BN_BLINDING_free(BN_BLINDING *r) {
|
||||
OPENSSL_free(r);
|
||||
}
|
||||
|
||||
void BN_BLINDING_invalidate(BN_BLINDING *b) {
|
||||
b->counter = BN_BLINDING_COUNTER - 1;
|
||||
}
|
||||
|
||||
static int bn_blinding_update(BN_BLINDING *b, const BIGNUM *e,
|
||||
const BN_MONT_CTX *mont, BN_CTX *ctx) {
|
||||
if (++b->counter == BN_BLINDING_COUNTER) {
|
||||
|
||||
@@ -83,6 +83,7 @@ int rsa_default_private_transform(RSA *rsa, uint8_t *out, const uint8_t *in,
|
||||
|
||||
BN_BLINDING *BN_BLINDING_new(void);
|
||||
void BN_BLINDING_free(BN_BLINDING *b);
|
||||
void BN_BLINDING_invalidate(BN_BLINDING *b);
|
||||
int BN_BLINDING_convert(BIGNUM *n, BN_BLINDING *b, const BIGNUM *e,
|
||||
const BN_MONT_CTX *mont_ctx, BN_CTX *ctx);
|
||||
int BN_BLINDING_invert(BIGNUM *n, const BN_BLINDING *b, BN_MONT_CTX *mont_ctx,
|
||||
|
||||
@@ -167,6 +167,22 @@ int RSA_up_ref(RSA *rsa) {
|
||||
|
||||
unsigned RSA_bits(const RSA *rsa) { return BN_num_bits(rsa->n); }
|
||||
|
||||
const BIGNUM *RSA_get0_n(const RSA *rsa) { return rsa->n; }
|
||||
|
||||
const BIGNUM *RSA_get0_e(const RSA *rsa) { return rsa->e; }
|
||||
|
||||
const BIGNUM *RSA_get0_d(const RSA *rsa) { return rsa->d; }
|
||||
|
||||
const BIGNUM *RSA_get0_p(const RSA *rsa) { return rsa->p; }
|
||||
|
||||
const BIGNUM *RSA_get0_q(const RSA *rsa) { return rsa->q; }
|
||||
|
||||
const BIGNUM *RSA_get0_dmp1(const RSA *rsa) { return rsa->dmp1; }
|
||||
|
||||
const BIGNUM *RSA_get0_dmq1(const RSA *rsa) { return rsa->dmq1; }
|
||||
|
||||
const BIGNUM *RSA_get0_iqmp(const RSA *rsa) { return rsa->iqmp; }
|
||||
|
||||
void RSA_get0_key(const RSA *rsa, const BIGNUM **out_n, const BIGNUM **out_e,
|
||||
const BIGNUM **out_d) {
|
||||
if (out_n != NULL) {
|
||||
@@ -639,7 +655,12 @@ err:
|
||||
}
|
||||
|
||||
static int check_mod_inverse(int *out_ok, const BIGNUM *a, const BIGNUM *ainv,
|
||||
const BIGNUM *m, int check_reduced, BN_CTX *ctx) {
|
||||
const BIGNUM *m, BN_CTX *ctx) {
|
||||
if (BN_is_negative(ainv) || BN_cmp(ainv, m) >= 0) {
|
||||
*out_ok = 0;
|
||||
return 1;
|
||||
}
|
||||
|
||||
BN_CTX_start(ctx);
|
||||
BIGNUM *tmp = BN_CTX_get(ctx);
|
||||
int ret = tmp != NULL &&
|
||||
@@ -647,19 +668,12 @@ static int check_mod_inverse(int *out_ok, const BIGNUM *a, const BIGNUM *ainv,
|
||||
bn_div_consttime(NULL, tmp, tmp, m, ctx);
|
||||
if (ret) {
|
||||
*out_ok = BN_is_one(tmp);
|
||||
if (check_reduced && (BN_is_negative(ainv) || BN_cmp(ainv, m) >= 0)) {
|
||||
*out_ok = 0;
|
||||
}
|
||||
}
|
||||
BN_CTX_end(ctx);
|
||||
return ret;
|
||||
}
|
||||
|
||||
int RSA_check_key(const RSA *key) {
|
||||
BIGNUM n, pm1, qm1, lcm, dmp1, dmq1, iqmp_times_q;
|
||||
BN_CTX *ctx;
|
||||
int ok = 0, has_crt_values;
|
||||
|
||||
if (RSA_is_opaque(key)) {
|
||||
// Opaque keys can't be checked.
|
||||
return 1;
|
||||
@@ -681,50 +695,53 @@ int RSA_check_key(const RSA *key) {
|
||||
return 1;
|
||||
}
|
||||
|
||||
ctx = BN_CTX_new();
|
||||
BN_CTX *ctx = BN_CTX_new();
|
||||
if (ctx == NULL) {
|
||||
OPENSSL_PUT_ERROR(RSA, ERR_R_MALLOC_FAILURE);
|
||||
return 0;
|
||||
}
|
||||
|
||||
BN_init(&n);
|
||||
BIGNUM tmp, de, pm1, qm1, dmp1, dmq1;
|
||||
int ok = 0;
|
||||
BN_init(&tmp);
|
||||
BN_init(&de);
|
||||
BN_init(&pm1);
|
||||
BN_init(&qm1);
|
||||
BN_init(&lcm);
|
||||
BN_init(&dmp1);
|
||||
BN_init(&dmq1);
|
||||
BN_init(&iqmp_times_q);
|
||||
|
||||
int d_ok;
|
||||
if (!bn_mul_consttime(&n, key->p, key->q, ctx) ||
|
||||
// lcm = lcm(p, q)
|
||||
!bn_usub_consttime(&pm1, key->p, BN_value_one()) ||
|
||||
!bn_usub_consttime(&qm1, key->q, BN_value_one()) ||
|
||||
!bn_lcm_consttime(&lcm, &pm1, &qm1, ctx) ||
|
||||
// Other implementations use the Euler totient rather than the Carmichael
|
||||
// totient, so allow unreduced |key->d|.
|
||||
!check_mod_inverse(&d_ok, key->e, key->d, &lcm,
|
||||
0 /* don't require reduced */, ctx)) {
|
||||
if (!bn_mul_consttime(&tmp, key->p, key->q, ctx)) {
|
||||
OPENSSL_PUT_ERROR(RSA, ERR_LIB_BN);
|
||||
goto out;
|
||||
}
|
||||
|
||||
if (BN_cmp(&n, key->n) != 0) {
|
||||
if (BN_cmp(&tmp, key->n) != 0) {
|
||||
OPENSSL_PUT_ERROR(RSA, RSA_R_N_NOT_EQUAL_P_Q);
|
||||
goto out;
|
||||
}
|
||||
|
||||
if (!d_ok) {
|
||||
OPENSSL_PUT_ERROR(RSA, RSA_R_D_E_NOT_CONGRUENT_TO_1);
|
||||
goto out;
|
||||
}
|
||||
|
||||
if (BN_is_negative(key->d) || BN_cmp(key->d, key->n) >= 0) {
|
||||
OPENSSL_PUT_ERROR(RSA, RSA_R_D_OUT_OF_RANGE);
|
||||
goto out;
|
||||
}
|
||||
|
||||
has_crt_values = key->dmp1 != NULL;
|
||||
// d must be an inverse of e mod the Carmichael totient, lcm(p-1, q-1), but it
|
||||
// may be unreduced because other implementations use the Euler totient. We
|
||||
// simply check that d * e is one mod p-1 and mod q-1.
|
||||
if (!bn_usub_consttime(&pm1, key->p, BN_value_one()) ||
|
||||
!bn_usub_consttime(&qm1, key->q, BN_value_one()) ||
|
||||
!bn_mul_consttime(&de, key->d, key->e, ctx) ||
|
||||
!bn_div_consttime(NULL, &tmp, &de, &pm1, ctx) ||
|
||||
!bn_div_consttime(NULL, &de, &de, &qm1, ctx)) {
|
||||
OPENSSL_PUT_ERROR(RSA, ERR_LIB_BN);
|
||||
goto out;
|
||||
}
|
||||
|
||||
if (!BN_is_one(&tmp) || !BN_is_one(&de)) {
|
||||
OPENSSL_PUT_ERROR(RSA, RSA_R_D_E_NOT_CONGRUENT_TO_1);
|
||||
goto out;
|
||||
}
|
||||
|
||||
int has_crt_values = key->dmp1 != NULL;
|
||||
if (has_crt_values != (key->dmq1 != NULL) ||
|
||||
has_crt_values != (key->iqmp != NULL)) {
|
||||
OPENSSL_PUT_ERROR(RSA, RSA_R_INCONSISTENT_SET_OF_CRT_VALUES);
|
||||
@@ -733,12 +750,9 @@ int RSA_check_key(const RSA *key) {
|
||||
|
||||
if (has_crt_values) {
|
||||
int dmp1_ok, dmq1_ok, iqmp_ok;
|
||||
if (!check_mod_inverse(&dmp1_ok, key->e, key->dmp1, &pm1,
|
||||
1 /* check reduced */, ctx) ||
|
||||
!check_mod_inverse(&dmq1_ok, key->e, key->dmq1, &qm1,
|
||||
1 /* check reduced */, ctx) ||
|
||||
!check_mod_inverse(&iqmp_ok, key->q, key->iqmp, key->p,
|
||||
1 /* check reduced */, ctx)) {
|
||||
if (!check_mod_inverse(&dmp1_ok, key->e, key->dmp1, &pm1, ctx) ||
|
||||
!check_mod_inverse(&dmq1_ok, key->e, key->dmq1, &qm1, ctx) ||
|
||||
!check_mod_inverse(&iqmp_ok, key->q, key->iqmp, key->p, ctx)) {
|
||||
OPENSSL_PUT_ERROR(RSA, ERR_LIB_BN);
|
||||
goto out;
|
||||
}
|
||||
@@ -752,13 +766,12 @@ int RSA_check_key(const RSA *key) {
|
||||
ok = 1;
|
||||
|
||||
out:
|
||||
BN_free(&n);
|
||||
BN_free(&tmp);
|
||||
BN_free(&de);
|
||||
BN_free(&pm1);
|
||||
BN_free(&qm1);
|
||||
BN_free(&lcm);
|
||||
BN_free(&dmp1);
|
||||
BN_free(&dmq1);
|
||||
BN_free(&iqmp_times_q);
|
||||
BN_CTX_free(ctx);
|
||||
|
||||
return ok;
|
||||
|
||||
@@ -70,6 +70,7 @@
|
||||
#include "../bn/internal.h"
|
||||
#include "../../internal.h"
|
||||
#include "../delocate.h"
|
||||
#include "../rand/fork_detect.h"
|
||||
|
||||
|
||||
static int check_modulus_and_exponent_sizes(const RSA *rsa) {
|
||||
@@ -345,7 +346,7 @@ err:
|
||||
// MAX_BLINDINGS_PER_RSA defines the maximum number of cached BN_BLINDINGs per
|
||||
// RSA*. Then this limit is exceeded, BN_BLINDING objects will be created and
|
||||
// destroyed as needed.
|
||||
#if defined(OPNESSL_TSAN)
|
||||
#if defined(OPENSSL_TSAN)
|
||||
// Smaller under TSAN so that the edge case can be hit with fewer threads.
|
||||
#define MAX_BLINDINGS_PER_RSA 2
|
||||
#else
|
||||
@@ -365,10 +366,23 @@ static BN_BLINDING *rsa_blinding_get(RSA *rsa, unsigned *index_used,
|
||||
assert(rsa->mont_n != NULL);
|
||||
|
||||
BN_BLINDING *ret = NULL;
|
||||
const uint64_t fork_generation = CRYPTO_get_fork_generation();
|
||||
CRYPTO_MUTEX_lock_write(&rsa->lock);
|
||||
|
||||
// Wipe the blinding cache on |fork|.
|
||||
if (rsa->blinding_fork_generation != fork_generation) {
|
||||
for (unsigned i = 0; i < rsa->num_blindings; i++) {
|
||||
// The inuse flag must be zero unless we were forked from a
|
||||
// multi-threaded process, in which case calling back into BoringSSL is
|
||||
// forbidden.
|
||||
assert(rsa->blindings_inuse[i] == 0);
|
||||
BN_BLINDING_invalidate(rsa->blindings[i]);
|
||||
}
|
||||
rsa->blinding_fork_generation = fork_generation;
|
||||
}
|
||||
|
||||
uint8_t *const free_inuse_flag =
|
||||
memchr(rsa->blindings_inuse, 0, rsa->num_blindings);
|
||||
OPENSSL_memchr(rsa->blindings_inuse, 0, rsa->num_blindings);
|
||||
if (free_inuse_flag != NULL) {
|
||||
*free_inuse_flag = 1;
|
||||
*index_used = free_inuse_flag - rsa->blindings_inuse;
|
||||
|
||||
@@ -105,6 +105,23 @@ int SHA512_Init(SHA512_CTX *sha) {
|
||||
return 1;
|
||||
}
|
||||
|
||||
int SHA512_256_Init(SHA512_CTX *sha) {
|
||||
sha->h[0] = UINT64_C(0x22312194fc2bf72c);
|
||||
sha->h[1] = UINT64_C(0x9f555fa3c84c64c2);
|
||||
sha->h[2] = UINT64_C(0x2393b86b6f53b151);
|
||||
sha->h[3] = UINT64_C(0x963877195940eabd);
|
||||
sha->h[4] = UINT64_C(0x96283ee2a88effe3);
|
||||
sha->h[5] = UINT64_C(0xbe5e1e2553863992);
|
||||
sha->h[6] = UINT64_C(0x2b0199fc2c85b8aa);
|
||||
sha->h[7] = UINT64_C(0x0eb72ddc81c52ca2);
|
||||
|
||||
sha->Nl = 0;
|
||||
sha->Nh = 0;
|
||||
sha->num = 0;
|
||||
sha->md_len = SHA512_256_DIGEST_LENGTH;
|
||||
return 1;
|
||||
}
|
||||
|
||||
uint8_t *SHA384(const uint8_t *data, size_t len,
|
||||
uint8_t out[SHA384_DIGEST_LENGTH]) {
|
||||
SHA512_CTX ctx;
|
||||
@@ -125,6 +142,16 @@ uint8_t *SHA512(const uint8_t *data, size_t len,
|
||||
return out;
|
||||
}
|
||||
|
||||
uint8_t *SHA512_256(const uint8_t *data, size_t len,
|
||||
uint8_t out[SHA512_256_DIGEST_LENGTH]) {
|
||||
SHA512_CTX ctx;
|
||||
SHA512_256_Init(&ctx);
|
||||
SHA512_Update(&ctx, data, len);
|
||||
SHA512_Final(out, &ctx);
|
||||
OPENSSL_cleanse(&ctx, sizeof(ctx));
|
||||
return out;
|
||||
}
|
||||
|
||||
#if !defined(SHA512_ASM)
|
||||
static void sha512_block_data_order(uint64_t *state, const uint8_t *in,
|
||||
size_t num_blocks);
|
||||
@@ -141,6 +168,17 @@ int SHA384_Update(SHA512_CTX *sha, const void *data, size_t len) {
|
||||
return SHA512_Update(sha, data, len);
|
||||
}
|
||||
|
||||
int SHA512_256_Update(SHA512_CTX *sha, const void *data, size_t len) {
|
||||
return SHA512_Update(sha, data, len);
|
||||
}
|
||||
|
||||
int SHA512_256_Final(uint8_t out[SHA512_256_DIGEST_LENGTH],
|
||||
SHA512_CTX *sha) {
|
||||
// |SHA512_256_Init| sets |sha->md_len| to |SHA512_256_DIGEST_LENGTH|, so this
|
||||
// has a |smaller output.
|
||||
return SHA512_Final(out, sha);
|
||||
}
|
||||
|
||||
void SHA512_Transform(SHA512_CTX *c, const uint8_t block[SHA512_CBLOCK]) {
|
||||
sha512_block_data_order(c->h, block, 1);
|
||||
}
|
||||
@@ -231,41 +269,12 @@ int SHA512_Final(uint8_t out[SHA512_DIGEST_LENGTH], SHA512_CTX *sha) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
switch (sha->md_len) {
|
||||
// Let compiler decide if it's appropriate to unroll...
|
||||
case SHA384_DIGEST_LENGTH:
|
||||
for (n = 0; n < SHA384_DIGEST_LENGTH / 8; n++) {
|
||||
uint64_t t = sha->h[n];
|
||||
|
||||
*(out++) = (uint8_t)(t >> 56);
|
||||
*(out++) = (uint8_t)(t >> 48);
|
||||
*(out++) = (uint8_t)(t >> 40);
|
||||
*(out++) = (uint8_t)(t >> 32);
|
||||
*(out++) = (uint8_t)(t >> 24);
|
||||
*(out++) = (uint8_t)(t >> 16);
|
||||
*(out++) = (uint8_t)(t >> 8);
|
||||
*(out++) = (uint8_t)(t);
|
||||
}
|
||||
break;
|
||||
case SHA512_DIGEST_LENGTH:
|
||||
for (n = 0; n < SHA512_DIGEST_LENGTH / 8; n++) {
|
||||
uint64_t t = sha->h[n];
|
||||
|
||||
*(out++) = (uint8_t)(t >> 56);
|
||||
*(out++) = (uint8_t)(t >> 48);
|
||||
*(out++) = (uint8_t)(t >> 40);
|
||||
*(out++) = (uint8_t)(t >> 32);
|
||||
*(out++) = (uint8_t)(t >> 24);
|
||||
*(out++) = (uint8_t)(t >> 16);
|
||||
*(out++) = (uint8_t)(t >> 8);
|
||||
*(out++) = (uint8_t)(t);
|
||||
}
|
||||
break;
|
||||
// ... as well as make sure md_len is not abused.
|
||||
default:
|
||||
// TODO(davidben): This bad |md_len| case is one of the few places a
|
||||
// low-level hash 'final' function can fail. This should never happen.
|
||||
return 0;
|
||||
assert(sha->md_len % 8 == 0);
|
||||
const size_t out_words = sha->md_len / 8;
|
||||
for (size_t i = 0; i < out_words; i++) {
|
||||
const uint64_t t = CRYPTO_bswap8(sha->h[i]);
|
||||
memcpy(out, &t, sizeof(t));
|
||||
out += sizeof(t);
|
||||
}
|
||||
|
||||
return 1;
|
||||
|
||||
File diff suppressed because it is too large.
Load diff
File diff suppressed because it is too large.
Load diff
@@ -689,6 +689,10 @@ OPENSSL_EXPORT void CRYPTO_free_ex_data(CRYPTO_EX_DATA_CLASS *ex_data_class,
|
||||
// Endianness conversions.
|
||||
|
||||
#if defined(__GNUC__) && __GNUC__ >= 2
|
||||
static inline uint16_t CRYPTO_bswap2(uint16_t x) {
|
||||
return __builtin_bswap16(x);
|
||||
}
|
||||
|
||||
static inline uint32_t CRYPTO_bswap4(uint32_t x) {
|
||||
return __builtin_bswap32(x);
|
||||
}
|
||||
@@ -700,7 +704,11 @@ static inline uint64_t CRYPTO_bswap8(uint64_t x) {
|
||||
OPENSSL_MSVC_PRAGMA(warning(push, 3))
|
||||
#include <stdlib.h>
|
||||
OPENSSL_MSVC_PRAGMA(warning(pop))
|
||||
#pragma intrinsic(_byteswap_uint64, _byteswap_ulong)
|
||||
#pragma intrinsic(_byteswap_uint64, _byteswap_ulong, _byteswap_ushort)
|
||||
static inline uint16_t CRYPTO_bswap2(uint16_t x) {
|
||||
return _byteswap_ushort(x);
|
||||
}
|
||||
|
||||
static inline uint32_t CRYPTO_bswap4(uint32_t x) {
|
||||
return _byteswap_ulong(x);
|
||||
}
|
||||
@@ -709,6 +717,10 @@ static inline uint64_t CRYPTO_bswap8(uint64_t x) {
|
||||
return _byteswap_uint64(x);
|
||||
}
|
||||
#else
|
||||
static inline uint16_t CRYPTO_bswap2(uint16_t x) {
|
||||
return (x >> 8) | (x << 8);
|
||||
}
|
||||
|
||||
static inline uint32_t CRYPTO_bswap4(uint32_t x) {
|
||||
x = (x >> 16) | (x << 16);
|
||||
x = ((x & 0xff00ff00) >> 8) | ((x & 0x00ff00ff) << 8);
|
||||
|
||||
@@ -84,27 +84,34 @@ static void __asan_unpoison_memory_region(const void *addr, size_t size) {}
|
||||
// Windows doesn't really support weak symbols as of May 2019, and Clang on
|
||||
// Windows will emit strong symbols instead. See
|
||||
// https://bugs.llvm.org/show_bug.cgi?id=37598
|
||||
#if defined(__GNUC__) || (defined(__clang__) && !defined(_MSC_VER))
|
||||
#if defined(__ELF__) && defined(__GNUC__)
|
||||
#define WEAK_SYMBOL_FUNC(rettype, name, args) \
|
||||
rettype name args __attribute__((weak));
|
||||
#else
|
||||
#define WEAK_SYMBOL_FUNC(rettype, name, args) static rettype(*name) args = NULL;
|
||||
#endif
|
||||
|
||||
// sdallocx is a sized |free| function. By passing the size (which we happen to
|
||||
// always know in BoringSSL), the malloc implementation can save work. We cannot
|
||||
// depend on |sdallocx| being available so we declare a wrapper that falls back
|
||||
// to |free| as a weak symbol.
|
||||
// depend on |sdallocx| being available, however, so it's a weak symbol.
|
||||
//
|
||||
// This will always be safe, but will only be overridden if the malloc
|
||||
// implementation is statically linked with BoringSSL. So, if |sdallocx| is
|
||||
// provided in, say, libc.so, we still won't use it because that's dynamically
|
||||
// linked. This isn't an ideal result, but its helps in some cases.
|
||||
void sdallocx(void *ptr, size_t size, int flags);
|
||||
WEAK_SYMBOL_FUNC(void, sdallocx, (void *ptr, size_t size, int flags));
|
||||
|
||||
__attribute((weak, noinline))
|
||||
#else
|
||||
static
|
||||
#endif
|
||||
void sdallocx(void *ptr, size_t size, int flags) {
|
||||
free(ptr);
|
||||
}
|
||||
// The following two functions are for memory tracking. They are no-ops by
|
||||
// default but can be overridden at link time if the application needs to
|
||||
// observe heap operations.
|
||||
WEAK_SYMBOL_FUNC(void, OPENSSL_track_memory_alloc, (void *ptr, size_t size));
|
||||
WEAK_SYMBOL_FUNC(void, OPENSSL_track_memory_free, (void *ptr, size_t size));
|
||||
|
||||
void *OPENSSL_malloc(size_t size) {
|
||||
if (size + OPENSSL_MALLOC_PREFIX < size) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
void *ptr = malloc(size + OPENSSL_MALLOC_PREFIX);
|
||||
if (ptr == NULL) {
|
||||
return NULL;
|
||||
@@ -113,6 +120,9 @@ void *OPENSSL_malloc(size_t size) {
|
||||
*(size_t *)ptr = size;
|
||||
|
||||
__asan_poison_memory_region(ptr, OPENSSL_MALLOC_PREFIX);
|
||||
if (OPENSSL_track_memory_alloc) {
|
||||
OPENSSL_track_memory_alloc(ptr, size + OPENSSL_MALLOC_PREFIX);
|
||||
}
|
||||
return ((uint8_t *)ptr) + OPENSSL_MALLOC_PREFIX;
|
||||
}
|
||||
|
||||
@@ -125,8 +135,15 @@ void OPENSSL_free(void *orig_ptr) {
|
||||
__asan_unpoison_memory_region(ptr, OPENSSL_MALLOC_PREFIX);
|
||||
|
||||
size_t size = *(size_t *)ptr;
|
||||
if (OPENSSL_track_memory_free) {
|
||||
OPENSSL_track_memory_free(ptr, size + OPENSSL_MALLOC_PREFIX);
|
||||
}
|
||||
OPENSSL_cleanse(ptr, size + OPENSSL_MALLOC_PREFIX);
|
||||
sdallocx(ptr, size + OPENSSL_MALLOC_PREFIX, 0 /* flags */);
|
||||
if (sdallocx) {
|
||||
sdallocx(ptr, size + OPENSSL_MALLOC_PREFIX, 0 /* flags */);
|
||||
} else {
|
||||
free(ptr);
|
||||
}
|
||||
}
|
||||
|
||||
void *OPENSSL_realloc(void *orig_ptr, size_t new_size) {
|
||||
|
||||
@@ -57,7 +57,7 @@
|
||||
/* This file is generated by crypto/obj/objects.go. */
|
||||
|
||||
|
||||
#define NUM_NID 961
|
||||
#define NUM_NID 963
|
||||
|
||||
static const uint8_t kObjectData[] = {
|
||||
/* NID_rsadsi */
|
||||
@@ -7111,6 +7111,10 @@ static const uint8_t kObjectData[] = {
|
||||
0x01,
|
||||
0x0e,
|
||||
0x03,
|
||||
/* NID_X25519 */
|
||||
0x2b,
|
||||
0x65,
|
||||
0x6e,
|
||||
/* NID_ED25519 */
|
||||
0x2b,
|
||||
0x65,
|
||||
@@ -7119,6 +7123,20 @@ static const uint8_t kObjectData[] = {
|
||||
0x2b,
|
||||
0x65,
|
||||
0x71,
|
||||
/* NID_X448 */
|
||||
0x2b,
|
||||
0x65,
|
||||
0x6f,
|
||||
/* NID_sha512_256 */
|
||||
0x60,
|
||||
0x86,
|
||||
0x48,
|
||||
0x01,
|
||||
0x65,
|
||||
0x03,
|
||||
0x04,
|
||||
0x02,
|
||||
0x06,
|
||||
};
|
||||
|
||||
static const ASN1_OBJECT kObjects[NUM_NID] = {
|
||||
@@ -8747,8 +8765,8 @@ static const ASN1_OBJECT kObjects[NUM_NID] = {
|
||||
NID_dhSinglePass_cofactorDH_sha512kdf_scheme, 6, &kObjectData[6169], 0},
|
||||
{"dh-std-kdf", "dh-std-kdf", NID_dh_std_kdf, 0, NULL, 0},
|
||||
{"dh-cofactor-kdf", "dh-cofactor-kdf", NID_dh_cofactor_kdf, 0, NULL, 0},
|
||||
{"X25519", "X25519", NID_X25519, 0, NULL, 0},
|
||||
{"ED25519", "ED25519", NID_ED25519, 3, &kObjectData[6175], 0},
|
||||
{"X25519", "X25519", NID_X25519, 3, &kObjectData[6175], 0},
|
||||
{"ED25519", "ED25519", NID_ED25519, 3, &kObjectData[6178], 0},
|
||||
{"ChaCha20-Poly1305", "chacha20-poly1305", NID_chacha20_poly1305, 0, NULL,
|
||||
0},
|
||||
{"KxRSA", "kx-rsa", NID_kx_rsa, 0, NULL, 0},
|
||||
@@ -8760,7 +8778,9 @@ static const ASN1_OBJECT kObjects[NUM_NID] = {
|
||||
{"KxANY", "kx-any", NID_kx_any, 0, NULL, 0},
|
||||
{"AuthANY", "auth-any", NID_auth_any, 0, NULL, 0},
|
||||
{"CECPQ2", "CECPQ2", NID_CECPQ2, 0, NULL, 0},
|
||||
{"ED448", "ED448", NID_ED448, 3, &kObjectData[6178], 0},
|
||||
{"ED448", "ED448", NID_ED448, 3, &kObjectData[6181], 0},
|
||||
{"X448", "X448", NID_X448, 3, &kObjectData[6184], 0},
|
||||
{"SHA512-256", "sha512-256", NID_sha512_256, 9, &kObjectData[6187], 0},
|
||||
};
|
||||
|
||||
static const uint16_t kNIDsInShortNameOrder[] = {
|
||||
@@ -8950,6 +8970,7 @@ static const uint16_t kNIDsInShortNameOrder[] = {
|
||||
672 /* SHA256 */,
|
||||
673 /* SHA384 */,
|
||||
674 /* SHA512 */,
|
||||
962 /* SHA512-256 */,
|
||||
188 /* SMIME */,
|
||||
167 /* SMIME-CAPS */,
|
||||
100 /* SN */,
|
||||
@@ -8958,6 +8979,7 @@ static const uint16_t kNIDsInShortNameOrder[] = {
|
||||
458 /* UID */,
|
||||
0 /* UNDEF */,
|
||||
948 /* X25519 */,
|
||||
961 /* X448 */,
|
||||
11 /* X500 */,
|
||||
378 /* X500algorithms */,
|
||||
12 /* X509 */,
|
||||
@@ -9828,6 +9850,7 @@ static const uint16_t kNIDsInLongNameOrder[] = {
|
||||
133 /* Time Stamping */,
|
||||
375 /* Trust Root */,
|
||||
948 /* X25519 */,
|
||||
961 /* X448 */,
|
||||
12 /* X509 */,
|
||||
402 /* X509v3 AC Targeting */,
|
||||
746 /* X509v3 Any Policy */,
|
||||
@@ -10621,6 +10644,7 @@ static const uint16_t kNIDsInLongNameOrder[] = {
|
||||
673 /* sha384 */,
|
||||
669 /* sha384WithRSAEncryption */,
|
||||
674 /* sha512 */,
|
||||
962 /* sha512-256 */,
|
||||
670 /* sha512WithRSAEncryption */,
|
||||
42 /* shaWithRSAEncryption */,
|
||||
52 /* signingTime */,
|
||||
@@ -10674,8 +10698,8 @@ static const uint16_t kNIDsInLongNameOrder[] = {
|
||||
static const uint16_t kNIDsInOIDOrder[] = {
|
||||
434 /* 0.9 (OBJ_data) */,
|
||||
182 /* 1.2 (OBJ_member_body) */,
|
||||
676 /* 1.3 (OBJ_identified_organization) */,
|
||||
379 /* 1.3 (OBJ_org) */,
|
||||
676 /* 1.3 (OBJ_identified_organization) */,
|
||||
11 /* 2.5 (OBJ_X500) */,
|
||||
647 /* 2.23 (OBJ_international_organizations) */,
|
||||
380 /* 1.3.6 (OBJ_dod) */,
|
||||
@@ -10687,6 +10711,8 @@ static const uint16_t kNIDsInOIDOrder[] = {
|
||||
435 /* 0.9.2342 (OBJ_pss) */,
|
||||
183 /* 1.2.840 (OBJ_ISO_US) */,
|
||||
381 /* 1.3.6.1 (OBJ_iana) */,
|
||||
948 /* 1.3.101.110 (OBJ_X25519) */,
|
||||
961 /* 1.3.101.111 (OBJ_X448) */,
|
||||
949 /* 1.3.101.112 (OBJ_ED25519) */,
|
||||
960 /* 1.3.101.113 (OBJ_ED448) */,
|
||||
677 /* 1.3.132 (OBJ_certicom_arc) */,
|
||||
@@ -11378,6 +11404,7 @@ static const uint16_t kNIDsInOIDOrder[] = {
|
||||
673 /* 2.16.840.1.101.3.4.2.2 (OBJ_sha384) */,
|
||||
674 /* 2.16.840.1.101.3.4.2.3 (OBJ_sha512) */,
|
||||
675 /* 2.16.840.1.101.3.4.2.4 (OBJ_sha224) */,
|
||||
962 /* 2.16.840.1.101.3.4.2.6 (OBJ_sha512_256) */,
|
||||
802 /* 2.16.840.1.101.3.4.3.1 (OBJ_dsa_with_SHA224) */,
|
||||
803 /* 2.16.840.1.101.3.4.3.2 (OBJ_dsa_with_SHA256) */,
|
||||
71 /* 2.16.840.1.113730.1.1 (OBJ_netscape_cert_type) */,
|
||||
|
||||
@@ -30,27 +30,23 @@
|
||||
// multi-threaded program, replace this with a thread-local. (A mutex would not
|
||||
// be deterministic.)
|
||||
static uint64_t g_num_calls = 0;
|
||||
static struct CRYPTO_STATIC_MUTEX g_num_calls_lock = CRYPTO_STATIC_MUTEX_INIT;
|
||||
|
||||
void RAND_reset_for_fuzzing(void) { g_num_calls = 0; }
|
||||
|
||||
void CRYPTO_sysrand(uint8_t *out, size_t requested) {
|
||||
static const uint8_t kZeroKey[32];
|
||||
|
||||
CRYPTO_STATIC_MUTEX_lock_write(&g_num_calls_lock);
|
||||
uint64_t num_calls = g_num_calls++;
|
||||
CRYPTO_STATIC_MUTEX_unlock_write(&g_num_calls_lock);
|
||||
|
||||
uint8_t nonce[12];
|
||||
OPENSSL_memset(nonce, 0, sizeof(nonce));
|
||||
OPENSSL_memcpy(nonce, &g_num_calls, sizeof(g_num_calls));
|
||||
OPENSSL_memcpy(nonce, &num_calls, sizeof(num_calls));
|
||||
|
||||
OPENSSL_memset(out, 0, requested);
|
||||
CRYPTO_chacha_20(out, out, requested, kZeroKey, nonce, 0);
|
||||
g_num_calls++;
|
||||
}
|
||||
|
||||
void CRYPTO_sysrand_for_seed(uint8_t *out, size_t requested) {
|
||||
CRYPTO_sysrand(out, requested);
|
||||
}
|
||||
|
||||
void CRYPTO_sysrand_if_available(uint8_t *out, size_t requested) {
|
||||
CRYPTO_sysrand(out, requested);
|
||||
}
|
||||
|
||||
#endif // BORINGSSL_UNSAFE_DETERMINISTIC_MODE
|
||||
@@ -23,12 +23,18 @@ OPENSSL_MSVC_PRAGMA(warning(push, 3))
|
||||
|
||||
#include <windows.h>
|
||||
|
||||
#if WINAPI_FAMILY_PARTITION(WINAPI_PARTITION_APP) && \
|
||||
!WINAPI_FAMILY_PARTITION(WINAPI_PARTITION_DESKTOP)
|
||||
#include <bcrypt.h>
|
||||
OPENSSL_MSVC_PRAGMA(comment(lib, "bcrypt.lib"))
|
||||
#else
|
||||
// #define needed to link in RtlGenRandom(), a.k.a. SystemFunction036. See the
|
||||
// "Community Additions" comment on MSDN here:
|
||||
// http://msdn.microsoft.com/en-us/library/windows/desktop/aa387694.aspx
|
||||
#define SystemFunction036 NTAPI SystemFunction036
|
||||
#include <ntsecapi.h>
|
||||
#undef SystemFunction036
|
||||
#endif // WINAPI_PARTITION_APP && !WINAPI_PARTITION_DESKTOP
|
||||
|
||||
OPENSSL_MSVC_PRAGMA(warning(pop))
|
||||
|
||||
@@ -41,7 +47,17 @@ void CRYPTO_sysrand(uint8_t *out, size_t requested) {
|
||||
if (requested < output_bytes_this_pass) {
|
||||
output_bytes_this_pass = (ULONG)requested;
|
||||
}
|
||||
// On non-UWP configurations, use RtlGenRandom instead of BCryptGenRandom
|
||||
// to avoid accessing resources that may be unavailable inside the
|
||||
// Chromium sandbox. See https://crbug.com/boringssl/307
|
||||
#if WINAPI_FAMILY_PARTITION(WINAPI_PARTITION_APP) && \
|
||||
!WINAPI_FAMILY_PARTITION(WINAPI_PARTITION_DESKTOP)
|
||||
if (!BCRYPT_SUCCESS(BCryptGenRandom(
|
||||
/*hAlgorithm=*/NULL, out, output_bytes_this_pass,
|
||||
BCRYPT_USE_SYSTEM_PREFERRED_RNG))) {
|
||||
#else
|
||||
if (RtlGenRandom(out, output_bytes_this_pass) == FALSE) {
|
||||
#endif // WINAPI_PARTITION_APP && !WINAPI_PARTITION_DESKTOP
|
||||
abort();
|
||||
}
|
||||
requested -= output_bytes_this_pass;
|
||||
|
||||
@@ -26,6 +26,10 @@
|
||||
|
||||
OPENSSL_STATIC_ASSERT(sizeof(CRYPTO_MUTEX) >= sizeof(pthread_rwlock_t),
|
||||
"CRYPTO_MUTEX is too small");
|
||||
#if defined(__GNUC__) || defined(__clang__)
|
||||
OPENSSL_STATIC_ASSERT(alignof(CRYPTO_MUTEX) >= alignof(pthread_rwlock_t),
|
||||
"CRYPTO_MUTEX has insufficient alignment");
|
||||
#endif
|
||||
|
||||
void CRYPTO_MUTEX_init(CRYPTO_MUTEX *lock) {
|
||||
if (pthread_rwlock_init((pthread_rwlock_t *) lock, NULL) != 0) {
|
||||
|
||||
@@ -29,6 +29,10 @@ OPENSSL_MSVC_PRAGMA(warning(pop))
|
||||
|
||||
OPENSSL_STATIC_ASSERT(sizeof(CRYPTO_MUTEX) >= sizeof(SRWLOCK),
|
||||
"CRYPTO_MUTEX is too small");
|
||||
#if defined(__GNUC__) || defined(__clang__)
|
||||
OPENSSL_STATIC_ASSERT(alignof(CRYPTO_MUTEX) >= alignof(SRWLOCK),
|
||||
"CRYPTO_MUTEX has insufficient alignment");
|
||||
#endif
|
||||
|
||||
static BOOL CALLBACK call_once_init(INIT_ONCE *once, void *arg, void **out) {
|
||||
void (**init)(void) = (void (**)(void))arg;
|
||||
|
||||
@@ -0,0 +1,278 @@
|
||||
/* Copyright (c) 2019, Google Inc.
|
||||
*
|
||||
* Permission to use, copy, modify, and/or distribute this software for any
|
||||
* purpose with or without fee is hereby granted, provided that the above
|
||||
* copyright notice and this permission notice appear in all copies.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
|
||||
* WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
|
||||
* MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
|
||||
* SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
|
||||
* WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION
|
||||
* OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
|
||||
* CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. */
|
||||
|
||||
#ifndef OPENSSL_HEADER_TRUST_TOKEN_INTERNAL_H
|
||||
#define OPENSSL_HEADER_TRUST_TOKEN_INTERNAL_H
|
||||
|
||||
#include <CCryptoBoringSSL_base.h>
|
||||
#include <CCryptoBoringSSL_ec.h>
|
||||
#include <CCryptoBoringSSL_ec_key.h>
|
||||
#include <CCryptoBoringSSL_nid.h>
|
||||
|
||||
#include "../fipsmodule/ec/internal.h"
|
||||
|
||||
#include <CCryptoBoringSSL_trust_token.h>
|
||||
|
||||
|
||||
#if defined(__cplusplus)
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
|
||||
// PMBTokens.
|
||||
//
|
||||
// PMBTokens is described in https://eprint.iacr.org/2020/072/20200324:214215
|
||||
// and provides anonymous tokens with private metadata. We implement the
|
||||
// construction with validity verification, described in appendix H,
|
||||
// construction 6.
|
||||
|
||||
// PMBTOKEN_NONCE_SIZE is the size of nonces used as part of the PMBToken
|
||||
// protocol.
|
||||
#define PMBTOKEN_NONCE_SIZE 64
|
||||
|
||||
typedef struct {
|
||||
// TODO(https://crbug.com/boringssl/334): These should store |EC_PRECOMP| so
|
||||
// that |TRUST_TOKEN_finish_issuance| can use |ec_point_mul_scalar_precomp|.
|
||||
EC_AFFINE pub0;
|
||||
EC_AFFINE pub1;
|
||||
EC_AFFINE pubs;
|
||||
} PMBTOKEN_CLIENT_KEY;
|
||||
|
||||
typedef struct {
|
||||
EC_SCALAR x0;
|
||||
EC_SCALAR y0;
|
||||
EC_SCALAR x1;
|
||||
EC_SCALAR y1;
|
||||
EC_SCALAR xs;
|
||||
EC_SCALAR ys;
|
||||
EC_AFFINE pub0;
|
||||
EC_PRECOMP pub0_precomp;
|
||||
EC_AFFINE pub1;
|
||||
EC_PRECOMP pub1_precomp;
|
||||
EC_AFFINE pubs;
|
||||
EC_PRECOMP pubs_precomp;
|
||||
} PMBTOKEN_ISSUER_KEY;
|
||||
|
||||
// PMBTOKEN_PRETOKEN represents the intermediate state a client keeps during a
|
||||
// PMBToken issuance operation.
|
||||
typedef struct pmb_pretoken_st {
|
||||
uint8_t t[PMBTOKEN_NONCE_SIZE];
|
||||
EC_SCALAR r;
|
||||
EC_AFFINE Tp;
|
||||
} PMBTOKEN_PRETOKEN;
|
||||
|
||||
// PMBTOKEN_PRETOKEN_free releases the memory associated with |token|.
|
||||
OPENSSL_EXPORT void PMBTOKEN_PRETOKEN_free(PMBTOKEN_PRETOKEN *token);
|
||||
|
||||
DEFINE_STACK_OF(PMBTOKEN_PRETOKEN)
|
||||
|
||||
// The following functions implement the corresponding |TRUST_TOKENS_METHOD|
|
||||
// functions for |TRUST_TOKENS_experiment_v0|'s PMBTokens construction which
|
||||
// uses P-521.
|
||||
int pmbtoken_exp0_generate_key(CBB *out_private, CBB *out_public);
|
||||
int pmbtoken_exp0_client_key_from_bytes(PMBTOKEN_CLIENT_KEY *key,
|
||||
const uint8_t *in, size_t len);
|
||||
int pmbtoken_exp0_issuer_key_from_bytes(PMBTOKEN_ISSUER_KEY *key,
|
||||
const uint8_t *in, size_t len);
|
||||
STACK_OF(PMBTOKEN_PRETOKEN) * pmbtoken_exp0_blind(CBB *cbb, size_t count);
|
||||
int pmbtoken_exp0_sign(const PMBTOKEN_ISSUER_KEY *key, CBB *cbb, CBS *cbs,
|
||||
size_t num_requested, size_t num_to_issue,
|
||||
uint8_t private_metadata);
|
||||
STACK_OF(TRUST_TOKEN) *
|
||||
pmbtoken_exp0_unblind(const PMBTOKEN_CLIENT_KEY *key,
|
||||
const STACK_OF(PMBTOKEN_PRETOKEN) * pretokens,
|
||||
CBS *cbs, size_t count, uint32_t key_id);
|
||||
int pmbtoken_exp0_read(const PMBTOKEN_ISSUER_KEY *key,
|
||||
uint8_t out_nonce[PMBTOKEN_NONCE_SIZE],
|
||||
uint8_t *out_private_metadata, const uint8_t *token,
|
||||
size_t token_len);
|
||||
|
||||
// The following functions implement the corresponding |TRUST_TOKENS_METHOD|
|
||||
// functions for |TRUST_TOKENS_experiment_v1|'s PMBTokens construction which
|
||||
// uses P-384.
|
||||
//
|
||||
// We use P-384 instead of our usual choice of P-256. See Appendix I which
|
||||
// describes two attacks which may affect smaller curves. In particular, p-1 for
|
||||
// P-256 is smooth, giving a low complexity for the p-1 attack. P-384's p-1 has
|
||||
// a 281-bit prime factor,
|
||||
// 3055465788140352002733946906144561090641249606160407884365391979704929268480326390471.
|
||||
// This lower-bounds the p-1 attack at O(2^140). The p+1 attack is lower-bounded
|
||||
// by O(p^(1/3)) or O(2^128), so we do not need to check the smoothness of p+1.
|
||||
int pmbtoken_exp1_generate_key(CBB *out_private, CBB *out_public);
|
||||
int pmbtoken_exp1_client_key_from_bytes(PMBTOKEN_CLIENT_KEY *key,
|
||||
const uint8_t *in, size_t len);
|
||||
int pmbtoken_exp1_issuer_key_from_bytes(PMBTOKEN_ISSUER_KEY *key,
|
||||
const uint8_t *in, size_t len);
|
||||
STACK_OF(PMBTOKEN_PRETOKEN) * pmbtoken_exp1_blind(CBB *cbb, size_t count);
|
||||
int pmbtoken_exp1_sign(const PMBTOKEN_ISSUER_KEY *key, CBB *cbb, CBS *cbs,
|
||||
size_t num_requested, size_t num_to_issue,
|
||||
uint8_t private_metadata);
|
||||
STACK_OF(TRUST_TOKEN) *
|
||||
pmbtoken_exp1_unblind(const PMBTOKEN_CLIENT_KEY *key,
|
||||
const STACK_OF(PMBTOKEN_PRETOKEN) * pretokens,
|
||||
CBS *cbs, size_t count, uint32_t key_id);
|
||||
int pmbtoken_exp1_read(const PMBTOKEN_ISSUER_KEY *key,
|
||||
uint8_t out_nonce[PMBTOKEN_NONCE_SIZE],
|
||||
uint8_t *out_private_metadata, const uint8_t *token,
|
||||
size_t token_len);
|
||||
|
||||
// pmbtoken_exp1_get_h_for_testing returns H in uncompressed coordinates. This
|
||||
// function is used to confirm H was computed as expected.
|
||||
OPENSSL_EXPORT int pmbtoken_exp1_get_h_for_testing(uint8_t out[97]);
|
||||
|
||||
|
||||
// Trust Tokens internals.
|
||||
|
||||
struct trust_token_method_st {
|
||||
// generate_key generates a fresh keypair and writes their serialized
|
||||
// forms into |out_private| and |out_public|. It returns one on success and
|
||||
// zero on failure.
|
||||
int (*generate_key)(CBB *out_private, CBB *out_public);
|
||||
|
||||
// client_key_from_bytes decodes a client key from |in| and sets |key|
|
||||
// to the resulting key. It returns one on success and zero
|
||||
// on failure.
|
||||
int (*client_key_from_bytes)(PMBTOKEN_CLIENT_KEY *key, const uint8_t *in,
|
||||
size_t len);
|
||||
|
||||
// issuer_key_from_bytes decodes a issuer key from |in| and sets |key|
|
||||
// to the resulting key. It returns one on success and zero
|
||||
// on failure.
|
||||
int (*issuer_key_from_bytes)(PMBTOKEN_ISSUER_KEY *key, const uint8_t *in,
|
||||
size_t len);
|
||||
|
||||
// blind generates a new issuance request for |count| tokens. On
|
||||
// success, it returns a newly-allocated |STACK_OF(PMBTOKEN_PRETOKEN)| and
|
||||
// writes a request to the issuer to |cbb|. On failure, it returns NULL. The
|
||||
// |STACK_OF(PMBTOKEN_PRETOKEN)|s should be passed to |pmbtoken_unblind| when
|
||||
// the server responds.
|
||||
//
|
||||
// This function implements the AT.Usr0 operation.
|
||||
STACK_OF(PMBTOKEN_PRETOKEN) *(*blind)(CBB *cbb, size_t count);
|
||||
|
||||
// sign parses a request for |num_requested| tokens from |cbs| and
|
||||
// issues |num_to_issue| tokens with |key| and a private metadata value of
|
||||
// |private_metadata|. It then writes the response to |cbb|. It returns one on
|
||||
// success and zero on failure.
|
||||
//
|
||||
// This function implements the AT.Sig operation.
|
||||
int (*sign)(const PMBTOKEN_ISSUER_KEY *key, CBB *cbb, CBS *cbs,
|
||||
size_t num_requested, size_t num_to_issue,
|
||||
uint8_t private_metadata);
|
||||
|
||||
// unblind processes an issuance response for |count| tokens from |cbs|
|
||||
// and unblinds the signed tokens. |pretokens| are the pre-tokens returned
|
||||
// from the corresponding |blind| call. On success, the function returns a
|
||||
// newly-allocated |STACK_OF(TRUST_TOKEN)| containing the resulting tokens.
|
||||
// Each token's serialization will have |key_id| prepended. Otherwise, it
|
||||
// returns NULL.
|
||||
//
|
||||
// This function implements the AT.Usr1 operation.
|
||||
STACK_OF(TRUST_TOKEN) *
|
||||
(*unblind)(const PMBTOKEN_CLIENT_KEY *key,
|
||||
const STACK_OF(PMBTOKEN_PRETOKEN) * pretokens, CBS *cbs,
|
||||
size_t count, uint32_t key_id);
|
||||
|
||||
// read parses a PMBToken from |token| and verifies it using |key|. On
|
||||
// success, it returns one and stores the nonce and private metadata bit in
|
||||
// |out_nonce| and |*out_private_metadata|. Otherwise, it returns zero. Note
|
||||
// that, unlike the output of |unblind|, |token| does not have a
|
||||
// four-byte key ID prepended.
|
||||
int (*read)(const PMBTOKEN_ISSUER_KEY *key,
|
||||
uint8_t out_nonce[PMBTOKEN_NONCE_SIZE],
|
||||
uint8_t *out_private_metadata, const uint8_t *token,
|
||||
size_t token_len);
|
||||
|
||||
// use_token_hash determines whether to include the token hash in the SRR and
|
||||
// private metadata encryption.
|
||||
int use_token_hash : 1;
|
||||
|
||||
// batched_proof determines whether PMBToken uses a batched DLEQOR proof when
|
||||
// signing tokens.
|
||||
int batched_proof : 1;
|
||||
};
|
||||
|
||||
// Structure representing a single Trust Token public key with the specified ID.
|
||||
struct trust_token_client_key_st {
|
||||
uint32_t id;
|
||||
PMBTOKEN_CLIENT_KEY key;
|
||||
};
|
||||
|
||||
// Structure representing a single Trust Token private key with the specified
|
||||
// ID.
|
||||
struct trust_token_issuer_key_st {
|
||||
uint32_t id;
|
||||
PMBTOKEN_ISSUER_KEY key;
|
||||
};
|
||||
|
||||
struct trust_token_client_st {
|
||||
const TRUST_TOKEN_METHOD *method;
|
||||
|
||||
// max_batchsize is the maximum supported batchsize.
|
||||
uint16_t max_batchsize;
|
||||
|
||||
// keys is the set of public keys that are supported by the client for
|
||||
// issuance/redemptions.
|
||||
struct trust_token_client_key_st keys[3];
|
||||
|
||||
// num_keys is the number of keys currently configured.
|
||||
size_t num_keys;
|
||||
|
||||
// pretokens is the intermediate state during an active issuance.
|
||||
STACK_OF(PMBTOKEN_PRETOKEN)* pretokens;
|
||||
|
||||
// srr_key is the public key used to verify the signature of the SRR.
|
||||
EVP_PKEY *srr_key;
|
||||
};
|
||||
|
||||
|
||||
struct trust_token_issuer_st {
|
||||
const TRUST_TOKEN_METHOD *method;
|
||||
|
||||
// max_batchsize is the maximum supported batchsize.
|
||||
uint16_t max_batchsize;
|
||||
|
||||
// keys is the set of private keys that are supported by the issuer for
|
||||
// issuance/redemptions. The public metadata is an index into this list of
|
||||
// keys.
|
||||
struct trust_token_issuer_key_st keys[3];
|
||||
|
||||
// num_keys is the number of keys currently configured.
|
||||
size_t num_keys;
|
||||
|
||||
// srr_key is the private key used to sign the SRR.
|
||||
EVP_PKEY *srr_key;
|
||||
|
||||
// metadata_key is the secret material used to encode the private metadata bit
|
||||
// in the SRR.
|
||||
uint8_t *metadata_key;
|
||||
size_t metadata_key_len;
|
||||
};
|
||||
|
||||
|
||||
#if defined(__cplusplus)
|
||||
} // extern C
|
||||
|
||||
extern "C++" {
|
||||
|
||||
BSSL_NAMESPACE_BEGIN
|
||||
|
||||
BORINGSSL_MAKE_DELETER(PMBTOKEN_PRETOKEN, PMBTOKEN_PRETOKEN_free)
|
||||
|
||||
BSSL_NAMESPACE_END
|
||||
|
||||
} // extern C++
|
||||
#endif
|
||||
|
||||
#endif // OPENSSL_HEADER_TRUST_TOKEN_INTERNAL_H
|
||||
File diff suppressed because it is too large.
Load diff
@@ -0,0 +1,720 @@
|
||||
/* Copyright (c) 2019, Google Inc.
|
||||
*
|
||||
* Permission to use, copy, modify, and/or distribute this software for any
|
||||
* purpose with or without fee is hereby granted, provided that the above
|
||||
* copyright notice and this permission notice appear in all copies.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
|
||||
* WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
|
||||
* MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
|
||||
* SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
|
||||
* WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION
|
||||
* OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
|
||||
* CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. */
|
||||
|
||||
#include <CCryptoBoringSSL_bytestring.h>
|
||||
#include <CCryptoBoringSSL_err.h>
|
||||
#include <CCryptoBoringSSL_evp.h>
|
||||
#include <CCryptoBoringSSL_mem.h>
|
||||
#include <CCryptoBoringSSL_sha.h>
|
||||
#include <CCryptoBoringSSL_trust_token.h>
|
||||
|
||||
#include "internal.h"
|
||||
|
||||
|
||||
// The Trust Token API is described in
|
||||
// https://github.com/WICG/trust-token-api/blob/master/README.md and provides a
|
||||
// protocol for issuing and redeeming tokens built on top of the PMBTokens
|
||||
// construction.
|
||||
|
||||
const TRUST_TOKEN_METHOD *TRUST_TOKEN_experiment_v0(void) {
|
||||
static const TRUST_TOKEN_METHOD kMethod = {
|
||||
pmbtoken_exp0_generate_key,
|
||||
pmbtoken_exp0_client_key_from_bytes,
|
||||
pmbtoken_exp0_issuer_key_from_bytes,
|
||||
pmbtoken_exp0_blind,
|
||||
pmbtoken_exp0_sign,
|
||||
pmbtoken_exp0_unblind,
|
||||
pmbtoken_exp0_read,
|
||||
0 /* don't use token hash */,
|
||||
0 /* don't use batched proof */,
|
||||
};
|
||||
return &kMethod;
|
||||
}
|
||||
|
||||
const TRUST_TOKEN_METHOD *TRUST_TOKEN_experiment_v1(void) {
|
||||
static const TRUST_TOKEN_METHOD kMethod = {
|
||||
pmbtoken_exp1_generate_key,
|
||||
pmbtoken_exp1_client_key_from_bytes,
|
||||
pmbtoken_exp1_issuer_key_from_bytes,
|
||||
pmbtoken_exp1_blind,
|
||||
pmbtoken_exp1_sign,
|
||||
pmbtoken_exp1_unblind,
|
||||
pmbtoken_exp1_read,
|
||||
1 /* use token hash */,
|
||||
1 /* use batched proof */,
|
||||
};
|
||||
return &kMethod;
|
||||
}
|
||||
|
||||
TRUST_TOKEN *TRUST_TOKEN_new(const uint8_t *data, size_t len) {
|
||||
TRUST_TOKEN *ret = OPENSSL_malloc(sizeof(TRUST_TOKEN));
|
||||
if (ret == NULL) {
|
||||
OPENSSL_PUT_ERROR(TRUST_TOKEN, ERR_R_MALLOC_FAILURE);
|
||||
return NULL;
|
||||
}
|
||||
OPENSSL_memset(ret, 0, sizeof(TRUST_TOKEN));
|
||||
ret->data = OPENSSL_memdup(data, len);
|
||||
if (len != 0 && ret->data == NULL) {
|
||||
OPENSSL_PUT_ERROR(TRUST_TOKEN, ERR_R_MALLOC_FAILURE);
|
||||
OPENSSL_free(ret);
|
||||
return NULL;
|
||||
}
|
||||
ret->len = len;
|
||||
return ret;
|
||||
}
|
||||
|
||||
void TRUST_TOKEN_free(TRUST_TOKEN *token) {
|
||||
if (token == NULL) {
|
||||
return;
|
||||
}
|
||||
OPENSSL_free(token->data);
|
||||
OPENSSL_free(token);
|
||||
}
|
||||
|
||||
int TRUST_TOKEN_generate_key(const TRUST_TOKEN_METHOD *method,
|
||||
uint8_t *out_priv_key, size_t *out_priv_key_len,
|
||||
size_t max_priv_key_len, uint8_t *out_pub_key,
|
||||
size_t *out_pub_key_len, size_t max_pub_key_len,
|
||||
uint32_t id) {
|
||||
// Prepend the key ID in front of the PMBTokens format.
|
||||
int ret = 0;
|
||||
CBB priv_cbb, pub_cbb;
|
||||
CBB_zero(&priv_cbb);
|
||||
CBB_zero(&pub_cbb);
|
||||
if (!CBB_init_fixed(&priv_cbb, out_priv_key, max_priv_key_len) ||
|
||||
!CBB_init_fixed(&pub_cbb, out_pub_key, max_pub_key_len) ||
|
||||
!CBB_add_u32(&priv_cbb, id) ||
|
||||
!CBB_add_u32(&pub_cbb, id)) {
|
||||
OPENSSL_PUT_ERROR(TRUST_TOKEN, TRUST_TOKEN_R_BUFFER_TOO_SMALL);
|
||||
goto err;
|
||||
}
|
||||
|
||||
if (!method->generate_key(&priv_cbb, &pub_cbb)) {
|
||||
goto err;
|
||||
}
|
||||
|
||||
if (!CBB_finish(&priv_cbb, NULL, out_priv_key_len) ||
|
||||
!CBB_finish(&pub_cbb, NULL, out_pub_key_len)) {
|
||||
OPENSSL_PUT_ERROR(TRUST_TOKEN, TRUST_TOKEN_R_BUFFER_TOO_SMALL);
|
||||
goto err;
|
||||
}
|
||||
|
||||
ret = 1;
|
||||
|
||||
err:
|
||||
CBB_cleanup(&priv_cbb);
|
||||
CBB_cleanup(&pub_cbb);
|
||||
return ret;
|
||||
}
|
||||
|
||||
TRUST_TOKEN_CLIENT *TRUST_TOKEN_CLIENT_new(const TRUST_TOKEN_METHOD *method,
|
||||
size_t max_batchsize) {
|
||||
if (max_batchsize > 0xffff) {
|
||||
// The protocol supports only two-byte token counts.
|
||||
OPENSSL_PUT_ERROR(TRUST_TOKEN, ERR_R_OVERFLOW);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
TRUST_TOKEN_CLIENT *ret = OPENSSL_malloc(sizeof(TRUST_TOKEN_CLIENT));
|
||||
if (ret == NULL) {
|
||||
OPENSSL_PUT_ERROR(TRUST_TOKEN, ERR_R_MALLOC_FAILURE);
|
||||
return NULL;
|
||||
}
|
||||
OPENSSL_memset(ret, 0, sizeof(TRUST_TOKEN_CLIENT));
|
||||
ret->method = method;
|
||||
ret->max_batchsize = (uint16_t)max_batchsize;
|
||||
return ret;
|
||||
}
|
||||
|
||||
void TRUST_TOKEN_CLIENT_free(TRUST_TOKEN_CLIENT *ctx) {
|
||||
if (ctx == NULL) {
|
||||
return;
|
||||
}
|
||||
EVP_PKEY_free(ctx->srr_key);
|
||||
sk_PMBTOKEN_PRETOKEN_pop_free(ctx->pretokens, PMBTOKEN_PRETOKEN_free);
|
||||
OPENSSL_free(ctx);
|
||||
}
|
||||
|
||||
int TRUST_TOKEN_CLIENT_add_key(TRUST_TOKEN_CLIENT *ctx, size_t *out_key_index,
|
||||
const uint8_t *key, size_t key_len) {
|
||||
if (ctx->num_keys == OPENSSL_ARRAY_SIZE(ctx->keys)) {
|
||||
OPENSSL_PUT_ERROR(TRUST_TOKEN, TRUST_TOKEN_R_TOO_MANY_KEYS);
|
||||
return 0;
|
||||
}
|
||||
|
||||
struct trust_token_client_key_st *key_s = &ctx->keys[ctx->num_keys];
|
||||
CBS cbs;
|
||||
CBS_init(&cbs, key, key_len);
|
||||
uint32_t key_id;
|
||||
if (!CBS_get_u32(&cbs, &key_id) ||
|
||||
!ctx->method->client_key_from_bytes(&key_s->key, CBS_data(&cbs),
|
||||
CBS_len(&cbs))) {
|
||||
OPENSSL_PUT_ERROR(TRUST_TOKEN, TRUST_TOKEN_R_DECODE_FAILURE);
|
||||
return 0;
|
||||
}
|
||||
key_s->id = key_id;
|
||||
*out_key_index = ctx->num_keys;
|
||||
ctx->num_keys += 1;
|
||||
return 1;
|
||||
}
|
||||
|
||||
int TRUST_TOKEN_CLIENT_set_srr_key(TRUST_TOKEN_CLIENT *ctx, EVP_PKEY *key) {
|
||||
EVP_PKEY_free(ctx->srr_key);
|
||||
EVP_PKEY_up_ref(key);
|
||||
ctx->srr_key = key;
|
||||
return 1;
|
||||
}
|
||||
|
||||
int TRUST_TOKEN_CLIENT_begin_issuance(TRUST_TOKEN_CLIENT *ctx, uint8_t **out,
|
||||
size_t *out_len, size_t count) {
|
||||
if (count > ctx->max_batchsize) {
|
||||
count = ctx->max_batchsize;
|
||||
}
|
||||
|
||||
int ret = 0;
|
||||
CBB request;
|
||||
STACK_OF(PMBTOKEN_PRETOKEN) *pretokens = NULL;
|
||||
if (!CBB_init(&request, 0) ||
|
||||
!CBB_add_u16(&request, count)) {
|
||||
OPENSSL_PUT_ERROR(TRUST_TOKEN, ERR_R_MALLOC_FAILURE);
|
||||
goto err;
|
||||
}
|
||||
|
||||
pretokens = ctx->method->blind(&request, count);
|
||||
if (pretokens == NULL) {
|
||||
goto err;
|
||||
}
|
||||
|
||||
if (!CBB_finish(&request, out, out_len)) {
|
||||
OPENSSL_PUT_ERROR(TRUST_TOKEN, ERR_R_MALLOC_FAILURE);
|
||||
goto err;
|
||||
}
|
||||
|
||||
sk_PMBTOKEN_PRETOKEN_pop_free(ctx->pretokens, PMBTOKEN_PRETOKEN_free);
|
||||
ctx->pretokens = pretokens;
|
||||
pretokens = NULL;
|
||||
ret = 1;
|
||||
|
||||
err:
|
||||
CBB_cleanup(&request);
|
||||
sk_PMBTOKEN_PRETOKEN_pop_free(pretokens, PMBTOKEN_PRETOKEN_free);
|
||||
return ret;
|
||||
}
|
||||
|
||||
STACK_OF(TRUST_TOKEN) *
|
||||
TRUST_TOKEN_CLIENT_finish_issuance(TRUST_TOKEN_CLIENT *ctx,
|
||||
size_t *out_key_index,
|
||||
const uint8_t *response,
|
||||
size_t response_len) {
|
||||
CBS in;
|
||||
CBS_init(&in, response, response_len);
|
||||
uint16_t count;
|
||||
uint32_t key_id;
|
||||
if (!CBS_get_u16(&in, &count) ||
|
||||
!CBS_get_u32(&in, &key_id)) {
|
||||
OPENSSL_PUT_ERROR(TRUST_TOKEN, TRUST_TOKEN_R_DECODE_FAILURE);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
size_t key_index = 0;
|
||||
const struct trust_token_client_key_st *key = NULL;
|
||||
for (size_t i = 0; i < ctx->num_keys; i++) {
|
||||
if (ctx->keys[i].id == key_id) {
|
||||
key_index = i;
|
||||
key = &ctx->keys[i];
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (key == NULL) {
|
||||
OPENSSL_PUT_ERROR(TRUST_TOKEN, TRUST_TOKEN_R_INVALID_KEY_ID);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
if (count > sk_PMBTOKEN_PRETOKEN_num(ctx->pretokens)) {
|
||||
OPENSSL_PUT_ERROR(TRUST_TOKEN, TRUST_TOKEN_R_DECODE_FAILURE);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
STACK_OF(TRUST_TOKEN) *tokens =
|
||||
ctx->method->unblind(&key->key, ctx->pretokens, &in, count, key_id);
|
||||
if (tokens == NULL) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
if (CBS_len(&in) != 0) {
|
||||
OPENSSL_PUT_ERROR(TRUST_TOKEN, TRUST_TOKEN_R_DECODE_FAILURE);
|
||||
sk_TRUST_TOKEN_pop_free(tokens, TRUST_TOKEN_free);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
sk_PMBTOKEN_PRETOKEN_pop_free(ctx->pretokens, PMBTOKEN_PRETOKEN_free);
|
||||
ctx->pretokens = NULL;
|
||||
|
||||
*out_key_index = key_index;
|
||||
return tokens;
|
||||
}
|
||||
|
||||
int TRUST_TOKEN_CLIENT_begin_redemption(TRUST_TOKEN_CLIENT *ctx, uint8_t **out,
|
||||
size_t *out_len,
|
||||
const TRUST_TOKEN *token,
|
||||
const uint8_t *data, size_t data_len,
|
||||
uint64_t time) {
|
||||
CBB request, token_inner, inner;
|
||||
if (!CBB_init(&request, 0) ||
|
||||
!CBB_add_u16_length_prefixed(&request, &token_inner) ||
|
||||
!CBB_add_bytes(&token_inner, token->data, token->len) ||
|
||||
!CBB_add_u16_length_prefixed(&request, &inner) ||
|
||||
!CBB_add_bytes(&inner, data, data_len) ||
|
||||
!CBB_add_u64(&request, time) ||
|
||||
!CBB_finish(&request, out, out_len)) {
|
||||
OPENSSL_PUT_ERROR(TRUST_TOKEN, ERR_R_MALLOC_FAILURE);
|
||||
CBB_cleanup(&request);
|
||||
return 0;
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
|
||||
int TRUST_TOKEN_CLIENT_finish_redemption(TRUST_TOKEN_CLIENT *ctx,
|
||||
uint8_t **out_srr, size_t *out_srr_len,
|
||||
uint8_t **out_sig, size_t *out_sig_len,
|
||||
const uint8_t *response,
|
||||
size_t response_len) {
|
||||
if (ctx->srr_key == NULL) {
|
||||
OPENSSL_PUT_ERROR(TRUST_TOKEN, TRUST_TOKEN_R_NO_SRR_KEY_CONFIGURED);
|
||||
return 0;
|
||||
}
|
||||
|
||||
CBS in, srr, sig;
|
||||
CBS_init(&in, response, response_len);
|
||||
if (!CBS_get_u16_length_prefixed(&in, &srr) ||
|
||||
!CBS_get_u16_length_prefixed(&in, &sig)) {
|
||||
OPENSSL_PUT_ERROR(TRUST_TOKEN, TRUST_TOKEN_R_DECODE_ERROR);
|
||||
return 0;
|
||||
}
|
||||
|
||||
EVP_MD_CTX md_ctx;
|
||||
EVP_MD_CTX_init(&md_ctx);
|
||||
int sig_ok = EVP_DigestVerifyInit(&md_ctx, NULL, NULL, NULL, ctx->srr_key) &&
|
||||
EVP_DigestVerify(&md_ctx, CBS_data(&sig), CBS_len(&sig),
|
||||
CBS_data(&srr), CBS_len(&srr));
|
||||
EVP_MD_CTX_cleanup(&md_ctx);
|
||||
|
||||
if (!sig_ok) {
|
||||
OPENSSL_PUT_ERROR(TRUST_TOKEN, TRUST_TOKEN_R_SRR_SIGNATURE_ERROR);
|
||||
return 0;
|
||||
}
|
||||
|
||||
uint8_t *srr_buf = NULL, *sig_buf = NULL;
|
||||
size_t srr_len, sig_len;
|
||||
if (!CBS_stow(&srr, &srr_buf, &srr_len) ||
|
||||
!CBS_stow(&sig, &sig_buf, &sig_len)) {
|
||||
OPENSSL_PUT_ERROR(TRUST_TOKEN, ERR_R_MALLOC_FAILURE);
|
||||
OPENSSL_free(srr_buf);
|
||||
OPENSSL_free(sig_buf);
|
||||
return 0;
|
||||
}
|
||||
|
||||
*out_srr = srr_buf;
|
||||
*out_srr_len = srr_len;
|
||||
*out_sig = sig_buf;
|
||||
*out_sig_len = sig_len;
|
||||
return 1;
|
||||
}
|
||||
|
||||
TRUST_TOKEN_ISSUER *TRUST_TOKEN_ISSUER_new(const TRUST_TOKEN_METHOD *method,
|
||||
size_t max_batchsize) {
|
||||
if (max_batchsize > 0xffff) {
|
||||
// The protocol supports only two-byte token counts.
|
||||
OPENSSL_PUT_ERROR(TRUST_TOKEN, ERR_R_OVERFLOW);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
TRUST_TOKEN_ISSUER *ret = OPENSSL_malloc(sizeof(TRUST_TOKEN_ISSUER));
|
||||
if (ret == NULL) {
|
||||
OPENSSL_PUT_ERROR(TRUST_TOKEN, ERR_R_MALLOC_FAILURE);
|
||||
return NULL;
|
||||
}
|
||||
OPENSSL_memset(ret, 0, sizeof(TRUST_TOKEN_ISSUER));
|
||||
ret->method = method;
|
||||
ret->max_batchsize = (uint16_t)max_batchsize;
|
||||
return ret;
|
||||
}
|
||||
|
||||
void TRUST_TOKEN_ISSUER_free(TRUST_TOKEN_ISSUER *ctx) {
|
||||
if (ctx == NULL) {
|
||||
return;
|
||||
}
|
||||
EVP_PKEY_free(ctx->srr_key);
|
||||
OPENSSL_free(ctx->metadata_key);
|
||||
OPENSSL_free(ctx);
|
||||
}
|
||||
|
||||
int TRUST_TOKEN_ISSUER_add_key(TRUST_TOKEN_ISSUER *ctx, const uint8_t *key,
|
||||
size_t key_len) {
|
||||
if (ctx->num_keys == OPENSSL_ARRAY_SIZE(ctx->keys)) {
|
||||
OPENSSL_PUT_ERROR(TRUST_TOKEN, TRUST_TOKEN_R_TOO_MANY_KEYS);
|
||||
return 0;
|
||||
}
|
||||
|
||||
struct trust_token_issuer_key_st *key_s = &ctx->keys[ctx->num_keys];
|
||||
CBS cbs;
|
||||
CBS_init(&cbs, key, key_len);
|
||||
uint32_t key_id;
|
||||
if (!CBS_get_u32(&cbs, &key_id) ||
|
||||
!ctx->method->issuer_key_from_bytes(&key_s->key, CBS_data(&cbs),
|
||||
CBS_len(&cbs))) {
|
||||
OPENSSL_PUT_ERROR(TRUST_TOKEN, TRUST_TOKEN_R_DECODE_FAILURE);
|
||||
return 0;
|
||||
}
|
||||
|
||||
key_s->id = key_id;
|
||||
ctx->num_keys += 1;
|
||||
return 1;
|
||||
}
|
||||
|
||||
int TRUST_TOKEN_ISSUER_set_srr_key(TRUST_TOKEN_ISSUER *ctx, EVP_PKEY *key) {
|
||||
EVP_PKEY_free(ctx->srr_key);
|
||||
EVP_PKEY_up_ref(key);
|
||||
ctx->srr_key = key;
|
||||
return 1;
|
||||
}
|
||||
|
||||
int TRUST_TOKEN_ISSUER_set_metadata_key(TRUST_TOKEN_ISSUER *ctx,
|
||||
const uint8_t *key, size_t len) {
|
||||
if (len < 32) {
|
||||
OPENSSL_PUT_ERROR(TRUST_TOKEN, TRUST_TOKEN_R_INVALID_METADATA_KEY);
|
||||
}
|
||||
OPENSSL_free(ctx->metadata_key);
|
||||
ctx->metadata_key_len = 0;
|
||||
ctx->metadata_key = OPENSSL_memdup(key, len);
|
||||
if (ctx->metadata_key == NULL) {
|
||||
OPENSSL_PUT_ERROR(TRUST_TOKEN, ERR_R_MALLOC_FAILURE);
|
||||
return 0;
|
||||
}
|
||||
ctx->metadata_key_len = len;
|
||||
return 1;
|
||||
}
|
||||
|
||||
static const struct trust_token_issuer_key_st *trust_token_issuer_get_key(
|
||||
const TRUST_TOKEN_ISSUER *ctx, uint32_t key_id) {
|
||||
for (size_t i = 0; i < ctx->num_keys; i++) {
|
||||
if (ctx->keys[i].id == key_id) {
|
||||
return &ctx->keys[i];
|
||||
}
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
||||
int TRUST_TOKEN_ISSUER_issue(const TRUST_TOKEN_ISSUER *ctx, uint8_t **out,
|
||||
size_t *out_len, size_t *out_tokens_issued,
|
||||
const uint8_t *request, size_t request_len,
|
||||
uint32_t public_metadata, uint8_t private_metadata,
|
||||
size_t max_issuance) {
|
||||
if (max_issuance > ctx->max_batchsize) {
|
||||
max_issuance = ctx->max_batchsize;
|
||||
}
|
||||
|
||||
const struct trust_token_issuer_key_st *key =
|
||||
trust_token_issuer_get_key(ctx, public_metadata);
|
||||
if (key == NULL || private_metadata > 1) {
|
||||
OPENSSL_PUT_ERROR(TRUST_TOKEN, TRUST_TOKEN_R_INVALID_METADATA);
|
||||
return 0;
|
||||
}
|
||||
|
||||
CBS in;
|
||||
uint16_t num_requested;
|
||||
CBS_init(&in, request, request_len);
|
||||
if (!CBS_get_u16(&in, &num_requested)) {
|
||||
OPENSSL_PUT_ERROR(TRUST_TOKEN, TRUST_TOKEN_R_DECODE_FAILURE);
|
||||
return 0;
|
||||
}
|
||||
|
||||
size_t num_to_issue = num_requested;
|
||||
if (num_to_issue > max_issuance) {
|
||||
num_to_issue = max_issuance;
|
||||
}
|
||||
|
||||
int ret = 0;
|
||||
CBB response;
|
||||
if (!CBB_init(&response, 0) ||
|
||||
!CBB_add_u16(&response, num_to_issue) ||
|
||||
!CBB_add_u32(&response, public_metadata)) {
|
||||
OPENSSL_PUT_ERROR(TRUST_TOKEN, ERR_R_MALLOC_FAILURE);
|
||||
goto err;
|
||||
}
|
||||
|
||||
if (!ctx->method->sign(&key->key, &response, &in, num_requested, num_to_issue,
|
||||
private_metadata)) {
|
||||
goto err;
|
||||
}
|
||||
|
||||
if (CBS_len(&in) != 0) {
|
||||
OPENSSL_PUT_ERROR(TRUST_TOKEN, TRUST_TOKEN_R_DECODE_FAILURE);
|
||||
goto err;
|
||||
}
|
||||
|
||||
if (!CBB_finish(&response, out, out_len)) {
|
||||
OPENSSL_PUT_ERROR(TRUST_TOKEN, ERR_R_MALLOC_FAILURE);
|
||||
goto err;
|
||||
}
|
||||
|
||||
*out_tokens_issued = num_to_issue;
|
||||
ret = 1;
|
||||
|
||||
err:
|
||||
CBB_cleanup(&response);
|
||||
return ret;
|
||||
}
|
||||
|
||||
// https://tools.ietf.org/html/rfc7049#section-2.1
|
||||
static int add_cbor_int_with_type(CBB *cbb, uint8_t major_type,
|
||||
uint64_t value) {
|
||||
if (value <= 23) {
|
||||
return CBB_add_u8(cbb, value | major_type);
|
||||
}
|
||||
if (value <= 0xff) {
|
||||
return CBB_add_u8(cbb, 0x18 | major_type) && CBB_add_u8(cbb, value);
|
||||
}
|
||||
if (value <= 0xffff) {
|
||||
return CBB_add_u8(cbb, 0x19 | major_type) && CBB_add_u16(cbb, value);
|
||||
}
|
||||
if (value <= 0xffffffff) {
|
||||
return CBB_add_u8(cbb, 0x1a | major_type) && CBB_add_u32(cbb, value);
|
||||
}
|
||||
if (value <= 0xffffffffffffffff) {
|
||||
return CBB_add_u8(cbb, 0x1b | major_type) && CBB_add_u64(cbb, value);
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
// https://tools.ietf.org/html/rfc7049#section-2.1
|
||||
static int add_cbor_int(CBB *cbb, uint64_t value) {
|
||||
return add_cbor_int_with_type(cbb, 0, value);
|
||||
}
|
||||
|
||||
// https://tools.ietf.org/html/rfc7049#section-2.1
|
||||
static int add_cbor_bytes(CBB *cbb, const uint8_t *data, size_t len) {
|
||||
return add_cbor_int_with_type(cbb, 0x40, len) &&
|
||||
CBB_add_bytes(cbb, data, len);
|
||||
}
|
||||
|
||||
// https://tools.ietf.org/html/rfc7049#section-2.1
|
||||
static int add_cbor_text(CBB *cbb, const char *data, size_t len) {
|
||||
return add_cbor_int_with_type(cbb, 0x60, len) &&
|
||||
CBB_add_bytes(cbb, (const uint8_t *)data, len);
|
||||
}
|
||||
|
||||
// https://tools.ietf.org/html/rfc7049#section-2.1
|
||||
static int add_cbor_map(CBB *cbb, uint8_t size) {
|
||||
return add_cbor_int_with_type(cbb, 0xa0, size);
|
||||
}
|
||||
|
||||
static uint8_t get_metadata_obfuscator(const uint8_t *key, size_t key_len,
|
||||
const uint8_t *client_data,
|
||||
size_t client_data_len) {
|
||||
uint8_t metadata_obfuscator[SHA256_DIGEST_LENGTH];
|
||||
SHA256_CTX sha_ctx;
|
||||
SHA256_Init(&sha_ctx);
|
||||
SHA256_Update(&sha_ctx, key, key_len);
|
||||
SHA256_Update(&sha_ctx, client_data, client_data_len);
|
||||
SHA256_Final(metadata_obfuscator, &sha_ctx);
|
||||
return metadata_obfuscator[0] >> 7;
|
||||
}
|
||||
|
||||
int TRUST_TOKEN_ISSUER_redeem(const TRUST_TOKEN_ISSUER *ctx, uint8_t **out,
|
||||
size_t *out_len, TRUST_TOKEN **out_token,
|
||||
uint8_t **out_client_data,
|
||||
size_t *out_client_data_len,
|
||||
uint64_t *out_redemption_time,
|
||||
const uint8_t *request, size_t request_len,
|
||||
uint64_t lifetime) {
|
||||
CBS request_cbs, token_cbs;
|
||||
CBS_init(&request_cbs, request, request_len);
|
||||
if (!CBS_get_u16_length_prefixed(&request_cbs, &token_cbs)) {
|
||||
OPENSSL_PUT_ERROR(TRUST_TOKEN, TRUST_TOKEN_R_DECODE_ERROR);
|
||||
return 0;
|
||||
}
|
||||
|
||||
uint32_t public_metadata = 0;
|
||||
uint8_t private_metadata = 0;
|
||||
|
||||
CBS token_copy = token_cbs;
|
||||
|
||||
// Parse the token. If there is an error, treat it as an invalid token.
|
||||
if (!CBS_get_u32(&token_cbs, &public_metadata)) {
|
||||
OPENSSL_PUT_ERROR(TRUST_TOKEN, TRUST_TOKEN_R_INVALID_TOKEN);
|
||||
return 0;
|
||||
}
|
||||
|
||||
const struct trust_token_issuer_key_st *key =
|
||||
trust_token_issuer_get_key(ctx, public_metadata);
|
||||
uint8_t nonce[PMBTOKEN_NONCE_SIZE];
|
||||
if (key == NULL ||
|
||||
!ctx->method->read(&key->key, nonce, &private_metadata,
|
||||
CBS_data(&token_cbs), CBS_len(&token_cbs))) {
|
||||
OPENSSL_PUT_ERROR(TRUST_TOKEN, TRUST_TOKEN_R_INVALID_TOKEN);
|
||||
return 0;
|
||||
}
|
||||
|
||||
int ok = 0;
|
||||
CBB response, srr;
|
||||
uint8_t *srr_buf = NULL, *sig_buf = NULL, *client_data_buf = NULL;
|
||||
size_t srr_len = 0, sig_len = 0, client_data_len = 0;
|
||||
EVP_MD_CTX md_ctx;
|
||||
EVP_MD_CTX_init(&md_ctx);
|
||||
CBB_zero(&srr);
|
||||
if (!CBB_init(&response, 0)) {
|
||||
OPENSSL_PUT_ERROR(TRUST_TOKEN, ERR_R_MALLOC_FAILURE);
|
||||
goto err;
|
||||
}
|
||||
|
||||
CBS client_data;
|
||||
uint64_t redemption_time;
|
||||
if (!CBS_get_u16_length_prefixed(&request_cbs, &client_data) ||
|
||||
!CBS_get_u64(&request_cbs, &redemption_time)) {
|
||||
OPENSSL_PUT_ERROR(TRUST_TOKEN, TRUST_TOKEN_R_DECODE_ERROR);
|
||||
goto err;
|
||||
}
|
||||
|
||||
const uint8_t kTokenHashDSTLabel[] = "TrustTokenV0 TokenHash";
|
||||
uint8_t token_hash[SHA256_DIGEST_LENGTH];
|
||||
SHA256_CTX sha_ctx;
|
||||
SHA256_Init(&sha_ctx);
|
||||
SHA256_Update(&sha_ctx, kTokenHashDSTLabel, sizeof(kTokenHashDSTLabel));
|
||||
SHA256_Update(&sha_ctx, CBS_data(&token_copy), CBS_len(&token_copy));
|
||||
SHA256_Final(token_hash, &sha_ctx);
|
||||
|
||||
uint8_t metadata_obfuscator;
|
||||
if (ctx->method->use_token_hash) {
|
||||
metadata_obfuscator =
|
||||
get_metadata_obfuscator(ctx->metadata_key, ctx->metadata_key_len,
|
||||
token_hash, sizeof(token_hash));
|
||||
} else {
|
||||
metadata_obfuscator =
|
||||
get_metadata_obfuscator(ctx->metadata_key, ctx->metadata_key_len,
|
||||
CBS_data(&client_data), CBS_len(&client_data));
|
||||
}
|
||||
|
||||
// The SRR is constructed as per the format described in
|
||||
// https://docs.google.com/document/d/1TNnya6B8pyomDK2F1R9CL3dY10OAmqWlnCxsWyOBDVQ/edit#heading=h.7mkzvhpqb8l5
|
||||
|
||||
static const char kClientDataLabel[] = "client-data";
|
||||
static const char kExpiryTimestampLabel[] = "expiry-timestamp";
|
||||
static const char kMetadataLabel[] = "metadata";
|
||||
static const char kPrivateLabel[] = "private";
|
||||
static const char kPublicLabel[] = "public";
|
||||
static const char kTokenHashLabel[] = "token-hash";
|
||||
|
||||
// CBOR requires map keys to be sorted by length then sorted lexically.
|
||||
// https://tools.ietf.org/html/rfc7049#section-3.9
|
||||
assert(strlen(kMetadataLabel) < strlen(kTokenHashLabel));
|
||||
assert(strlen(kTokenHashLabel) < strlen(kClientDataLabel));
|
||||
assert(strlen(kClientDataLabel) < strlen(kExpiryTimestampLabel));
|
||||
assert(strlen(kPublicLabel) < strlen(kPrivateLabel));
|
||||
|
||||
size_t map_entries = 3;
|
||||
if (ctx->method->use_token_hash) {
|
||||
map_entries = 4;
|
||||
}
|
||||
|
||||
if (!CBB_init(&srr, 0) ||
|
||||
!add_cbor_map(&srr, map_entries) || // SRR map
|
||||
!add_cbor_text(&srr, kMetadataLabel, strlen(kMetadataLabel)) ||
|
||||
!add_cbor_map(&srr, 2) || // Metadata map
|
||||
!add_cbor_text(&srr, kPublicLabel, strlen(kPublicLabel)) ||
|
||||
!add_cbor_int(&srr, public_metadata) ||
|
||||
!add_cbor_text(&srr, kPrivateLabel, strlen(kPrivateLabel)) ||
|
||||
!add_cbor_int(&srr, private_metadata ^ metadata_obfuscator)) {
|
||||
OPENSSL_PUT_ERROR(TRUST_TOKEN, ERR_R_MALLOC_FAILURE);
|
||||
goto err;
|
||||
}
|
||||
|
||||
if (ctx->method->use_token_hash) {
|
||||
if (!add_cbor_text(&srr, kTokenHashLabel, strlen(kTokenHashLabel)) ||
|
||||
!add_cbor_bytes(&srr, token_hash, sizeof(token_hash))) {
|
||||
OPENSSL_PUT_ERROR(TRUST_TOKEN, ERR_R_MALLOC_FAILURE);
|
||||
goto err;
|
||||
}
|
||||
}
|
||||
|
||||
if (!add_cbor_text(&srr, kClientDataLabel, strlen(kClientDataLabel)) ||
|
||||
!CBB_add_bytes(&srr, CBS_data(&client_data), CBS_len(&client_data)) ||
|
||||
!add_cbor_text(&srr, kExpiryTimestampLabel,
|
||||
strlen(kExpiryTimestampLabel)) ||
|
||||
!add_cbor_int(&srr, redemption_time + lifetime) ||
|
||||
!CBB_finish(&srr, &srr_buf, &srr_len)) {
|
||||
OPENSSL_PUT_ERROR(TRUST_TOKEN, ERR_R_MALLOC_FAILURE);
|
||||
goto err;
|
||||
}
|
||||
|
||||
if (!EVP_DigestSignInit(&md_ctx, NULL, NULL, NULL, ctx->srr_key) ||
|
||||
!EVP_DigestSign(&md_ctx, NULL, &sig_len, srr_buf, srr_len)) {
|
||||
OPENSSL_PUT_ERROR(TRUST_TOKEN, TRUST_TOKEN_R_SRR_SIGNATURE_ERROR);
|
||||
goto err;
|
||||
}
|
||||
|
||||
CBB child;
|
||||
uint8_t *ptr;
|
||||
if (!CBB_add_u16_length_prefixed(&response, &child) ||
|
||||
!CBB_add_bytes(&child, srr_buf, srr_len) ||
|
||||
!CBB_add_u16_length_prefixed(&response, &child) ||
|
||||
!CBB_reserve(&child, &ptr, sig_len) ||
|
||||
!EVP_DigestSign(&md_ctx, ptr, &sig_len, srr_buf, srr_len) ||
|
||||
!CBB_did_write(&child, sig_len)) {
|
||||
OPENSSL_PUT_ERROR(TRUST_TOKEN, ERR_R_MALLOC_FAILURE);
|
||||
goto err;
|
||||
}
|
||||
|
||||
if (!CBS_stow(&client_data, &client_data_buf, &client_data_len) ||
|
||||
!CBB_finish(&response, out, out_len)) {
|
||||
OPENSSL_PUT_ERROR(TRUST_TOKEN, ERR_R_MALLOC_FAILURE);
|
||||
goto err;
|
||||
}
|
||||
|
||||
TRUST_TOKEN *token = TRUST_TOKEN_new(nonce, PMBTOKEN_NONCE_SIZE);
|
||||
if (token == NULL) {
|
||||
OPENSSL_PUT_ERROR(TRUST_TOKEN, ERR_R_MALLOC_FAILURE);
|
||||
goto err;
|
||||
}
|
||||
*out_token = token;
|
||||
*out_client_data = client_data_buf;
|
||||
*out_client_data_len = client_data_len;
|
||||
*out_redemption_time = redemption_time;
|
||||
|
||||
ok = 1;
|
||||
|
||||
err:
|
||||
CBB_cleanup(&response);
|
||||
CBB_cleanup(&srr);
|
||||
OPENSSL_free(srr_buf);
|
||||
OPENSSL_free(sig_buf);
|
||||
EVP_MD_CTX_cleanup(&md_ctx);
|
||||
if (!ok) {
|
||||
OPENSSL_free(client_data_buf);
|
||||
}
|
||||
return ok;
|
||||
}
|
||||
|
||||
int TRUST_TOKEN_decode_private_metadata(const TRUST_TOKEN_METHOD *method,
|
||||
uint8_t *out_value, const uint8_t *key,
|
||||
size_t key_len, const uint8_t *nonce,
|
||||
size_t nonce_len,
|
||||
uint8_t encrypted_bit) {
|
||||
uint8_t metadata_obfuscator =
|
||||
get_metadata_obfuscator(key, key_len, nonce, nonce_len);
|
||||
*out_value = encrypted_bit ^ metadata_obfuscator;
|
||||
return 1;
|
||||
}
|
||||
@@ -129,6 +129,14 @@ const ASN1_TIME *X509_get0_notBefore(const X509 *x)
|
||||
return x->cert_info->validity->notBefore;
|
||||
}
|
||||
|
||||
ASN1_TIME *X509_getm_notBefore(X509 *x)
|
||||
{
|
||||
// Note this function takes a const |X509| pointer in OpenSSL. We require
|
||||
// non-const as this allows mutating |x|. If it comes up for compatibility,
|
||||
// we can relax this.
|
||||
return x->cert_info->validity->notBefore;
|
||||
}
|
||||
|
||||
int X509_set_notAfter(X509 *x, const ASN1_TIME *tm)
|
||||
{
|
||||
ASN1_TIME *in;
|
||||
@@ -151,6 +159,14 @@ const ASN1_TIME *X509_get0_notAfter(const X509 *x)
|
||||
return x->cert_info->validity->notAfter;
|
||||
}
|
||||
|
||||
ASN1_TIME *X509_getm_notAfter(X509 *x)
|
||||
{
|
||||
// Note this function takes a const |X509| pointer in OpenSSL. We require
|
||||
// non-const as this allows mutating |x|. If it comes up for compatibility,
|
||||
// we can relax this.
|
||||
return x->cert_info->validity->notAfter;
|
||||
}
|
||||
|
||||
int X509_set_pubkey(X509 *x, EVP_PKEY *pkey)
|
||||
{
|
||||
if ((x == NULL) || (x->cert_info == NULL))
|
||||
|
||||
@@ -2148,6 +2148,11 @@ STACK_OF(X509) *X509_STORE_CTX_get_chain(X509_STORE_CTX *ctx)
|
||||
return ctx->chain;
|
||||
}
|
||||
|
||||
STACK_OF(X509) *X509_STORE_CTX_get0_chain(X509_STORE_CTX *ctx)
|
||||
{
|
||||
return ctx->chain;
|
||||
}
|
||||
|
||||
STACK_OF(X509) *X509_STORE_CTX_get1_chain(X509_STORE_CTX *ctx)
|
||||
{
|
||||
if (!ctx->chain)
|
||||
|
||||
@@ -177,7 +177,7 @@ X509_NAME_ENTRY *X509_NAME_delete_entry(X509_NAME *name, int loc)
|
||||
}
|
||||
|
||||
int X509_NAME_add_entry_by_OBJ(X509_NAME *name, ASN1_OBJECT *obj, int type,
|
||||
unsigned char *bytes, int len, int loc,
|
||||
const unsigned char *bytes, int len, int loc,
|
||||
int set)
|
||||
{
|
||||
X509_NAME_ENTRY *ne;
|
||||
@@ -191,7 +191,7 @@ int X509_NAME_add_entry_by_OBJ(X509_NAME *name, ASN1_OBJECT *obj, int type,
|
||||
}
|
||||
|
||||
int X509_NAME_add_entry_by_NID(X509_NAME *name, int nid, int type,
|
||||
unsigned char *bytes, int len, int loc,
|
||||
const unsigned char *bytes, int len, int loc,
|
||||
int set)
|
||||
{
|
||||
X509_NAME_ENTRY *ne;
|
||||
@@ -298,7 +298,8 @@ X509_NAME_ENTRY *X509_NAME_ENTRY_create_by_txt(X509_NAME_ENTRY **ne,
|
||||
}
|
||||
|
||||
X509_NAME_ENTRY *X509_NAME_ENTRY_create_by_NID(X509_NAME_ENTRY **ne, int nid,
|
||||
int type, unsigned char *bytes,
|
||||
int type,
|
||||
const unsigned char *bytes,
|
||||
int len)
|
||||
{
|
||||
const ASN1_OBJECT *obj = OBJ_nid2obj(nid);
|
||||
|
||||
Vendored
+1
-1
@@ -1 +1 @@
|
||||
This directory is derived from BoringSSL cloned from https://boringssl.googlesource.com/boringssl at revision 0416e8c3055c7fcfd6c3eab4c127a36df1e6097b
|
||||
This directory is derived from BoringSSL cloned from https://boringssl.googlesource.com/boringssl at revision 53a17f55247101105ae35767d5c5a6c311843a8e
|
||||
@@ -6,7 +6,7 @@
|
||||
// Licensed under Apache License v2.0
|
||||
//
|
||||
// See LICENSE.txt for license information
|
||||
// See CONTRIBUTORS.txt for the list of SwiftCrypto project authors
|
||||
// See CONTRIBUTORS.md for the list of SwiftCrypto project authors
|
||||
//
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
//
|
||||
@@ -56,6 +56,7 @@
|
||||
#include "CCryptoBoringSSL_safestack.h"
|
||||
#include "CCryptoBoringSSL_sha.h"
|
||||
#include "CCryptoBoringSSL_siphash.h"
|
||||
#include "CCryptoBoringSSL_trust_token.h"
|
||||
#include "CCryptoBoringSSL_x509v3.h"
|
||||
|
||||
#endif // C_CRYPTO_BORINGSSL_H
|
||||
@@ -189,7 +189,7 @@ extern "C" {
|
||||
// A consumer may use this symbol in the preprocessor to temporarily build
|
||||
// against multiple revisions of BoringSSL at the same time. It is not
|
||||
// recommended to do so for longer than is necessary.
|
||||
#define BORINGSSL_API_VERSION 9
|
||||
#define BORINGSSL_API_VERSION 10
|
||||
|
||||
#if defined(BORINGSSL_SHARED_LIBRARY)
|
||||
|
||||
@@ -427,6 +427,10 @@ typedef struct ssl_session_st SSL_SESSION;
|
||||
typedef struct ssl_st SSL;
|
||||
typedef struct ssl_ticket_aead_method_st SSL_TICKET_AEAD_METHOD;
|
||||
typedef struct st_ERR_FNS ERR_FNS;
|
||||
typedef struct trust_token_st TRUST_TOKEN;
|
||||
typedef struct trust_token_client_st TRUST_TOKEN_CLIENT;
|
||||
typedef struct trust_token_issuer_st TRUST_TOKEN_ISSUER;
|
||||
typedef struct trust_token_method_st TRUST_TOKEN_METHOD;
|
||||
typedef struct v3_ext_ctx X509V3_CTX;
|
||||
typedef struct x509_attributes_st X509_ATTRIBUTE;
|
||||
typedef struct x509_cert_aux_st X509_CERT_AUX;
|
||||
|
||||
@@ -306,6 +306,7 @@
|
||||
#define BIO_write_filename BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, BIO_write_filename)
|
||||
#define BN_BLINDING_convert BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, BN_BLINDING_convert)
|
||||
#define BN_BLINDING_free BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, BN_BLINDING_free)
|
||||
#define BN_BLINDING_invalidate BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, BN_BLINDING_invalidate)
|
||||
#define BN_BLINDING_invert BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, BN_BLINDING_invert)
|
||||
#define BN_BLINDING_new BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, BN_BLINDING_new)
|
||||
#define BN_CTX_end BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, BN_CTX_end)
|
||||
@@ -454,10 +455,13 @@
|
||||
#define CBB_add_space BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, CBB_add_space)
|
||||
#define CBB_add_u16 BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, CBB_add_u16)
|
||||
#define CBB_add_u16_length_prefixed BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, CBB_add_u16_length_prefixed)
|
||||
#define CBB_add_u16le BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, CBB_add_u16le)
|
||||
#define CBB_add_u24 BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, CBB_add_u24)
|
||||
#define CBB_add_u24_length_prefixed BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, CBB_add_u24_length_prefixed)
|
||||
#define CBB_add_u32 BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, CBB_add_u32)
|
||||
#define CBB_add_u32le BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, CBB_add_u32le)
|
||||
#define CBB_add_u64 BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, CBB_add_u64)
|
||||
#define CBB_add_u64le BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, CBB_add_u64le)
|
||||
#define CBB_add_u8 BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, CBB_add_u8)
|
||||
#define CBB_add_u8_length_prefixed BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, CBB_add_u8_length_prefixed)
|
||||
#define CBB_cleanup BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, CBB_cleanup)
|
||||
@@ -496,10 +500,13 @@
|
||||
#define CBS_get_optional_asn1_uint64 BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, CBS_get_optional_asn1_uint64)
|
||||
#define CBS_get_u16 BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, CBS_get_u16)
|
||||
#define CBS_get_u16_length_prefixed BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, CBS_get_u16_length_prefixed)
|
||||
#define CBS_get_u16le BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, CBS_get_u16le)
|
||||
#define CBS_get_u24 BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, CBS_get_u24)
|
||||
#define CBS_get_u24_length_prefixed BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, CBS_get_u24_length_prefixed)
|
||||
#define CBS_get_u32 BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, CBS_get_u32)
|
||||
#define CBS_get_u32le BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, CBS_get_u32le)
|
||||
#define CBS_get_u64 BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, CBS_get_u64)
|
||||
#define CBS_get_u64le BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, CBS_get_u64le)
|
||||
#define CBS_get_u8 BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, CBS_get_u8)
|
||||
#define CBS_get_u8_length_prefixed BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, CBS_get_u8_length_prefixed)
|
||||
#define CBS_init BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, CBS_init)
|
||||
@@ -563,6 +570,7 @@
|
||||
#define CRYPTO_cleanup_all_ex_data BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, CRYPTO_cleanup_all_ex_data)
|
||||
#define CRYPTO_ctr128_encrypt BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, CRYPTO_ctr128_encrypt)
|
||||
#define CRYPTO_ctr128_encrypt_ctr32 BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, CRYPTO_ctr128_encrypt_ctr32)
|
||||
#define CRYPTO_fork_detect_ignore_madv_wipeonfork_for_testing BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, CRYPTO_fork_detect_ignore_madv_wipeonfork_for_testing)
|
||||
#define CRYPTO_free_ex_data BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, CRYPTO_free_ex_data)
|
||||
#define CRYPTO_gcm128_aad BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, CRYPTO_gcm128_aad)
|
||||
#define CRYPTO_gcm128_decrypt BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, CRYPTO_gcm128_decrypt)
|
||||
@@ -578,12 +586,14 @@
|
||||
#define CRYPTO_get_dynlock_lock_callback BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, CRYPTO_get_dynlock_lock_callback)
|
||||
#define CRYPTO_get_ex_data BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, CRYPTO_get_ex_data)
|
||||
#define CRYPTO_get_ex_new_index BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, CRYPTO_get_ex_new_index)
|
||||
#define CRYPTO_get_fork_generation BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, CRYPTO_get_fork_generation)
|
||||
#define CRYPTO_get_lock_name BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, CRYPTO_get_lock_name)
|
||||
#define CRYPTO_get_locking_callback BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, CRYPTO_get_locking_callback)
|
||||
#define CRYPTO_get_thread_local BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, CRYPTO_get_thread_local)
|
||||
#define CRYPTO_ghash_init BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, CRYPTO_ghash_init)
|
||||
#define CRYPTO_has_asm BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, CRYPTO_has_asm)
|
||||
#define CRYPTO_hchacha20 BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, CRYPTO_hchacha20)
|
||||
#define CRYPTO_init_sysrand BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, CRYPTO_init_sysrand)
|
||||
#define CRYPTO_is_ARMv8_AES_capable BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, CRYPTO_is_ARMv8_AES_capable)
|
||||
#define CRYPTO_is_ARMv8_PMULL_capable BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, CRYPTO_is_ARMv8_PMULL_capable)
|
||||
#define CRYPTO_is_NEON_capable_at_runtime BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, CRYPTO_is_NEON_capable_at_runtime)
|
||||
@@ -598,6 +608,7 @@
|
||||
#define CRYPTO_poly1305_finish BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, CRYPTO_poly1305_finish)
|
||||
#define CRYPTO_poly1305_init BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, CRYPTO_poly1305_init)
|
||||
#define CRYPTO_poly1305_update BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, CRYPTO_poly1305_update)
|
||||
#define CRYPTO_pre_sandbox_init BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, CRYPTO_pre_sandbox_init)
|
||||
#define CRYPTO_rdrand BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, CRYPTO_rdrand)
|
||||
#define CRYPTO_rdrand_multiple8_buf BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, CRYPTO_rdrand_multiple8_buf)
|
||||
#define CRYPTO_refcount_dec_and_test_zero BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, CRYPTO_refcount_dec_and_test_zero)
|
||||
@@ -611,6 +622,7 @@
|
||||
#define CRYPTO_set_locking_callback BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, CRYPTO_set_locking_callback)
|
||||
#define CRYPTO_set_thread_local BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, CRYPTO_set_thread_local)
|
||||
#define CRYPTO_sysrand BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, CRYPTO_sysrand)
|
||||
#define CRYPTO_sysrand_if_available BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, CRYPTO_sysrand_if_available)
|
||||
#define CRYPTO_tls1_prf BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, CRYPTO_tls1_prf)
|
||||
#define CTR_DRBG_clear BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, CTR_DRBG_clear)
|
||||
#define CTR_DRBG_generate BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, CTR_DRBG_generate)
|
||||
@@ -633,8 +645,13 @@
|
||||
#define DH_free BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, DH_free)
|
||||
#define DH_generate_key BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, DH_generate_key)
|
||||
#define DH_generate_parameters_ex BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, DH_generate_parameters_ex)
|
||||
#define DH_get0_g BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, DH_get0_g)
|
||||
#define DH_get0_key BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, DH_get0_key)
|
||||
#define DH_get0_p BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, DH_get0_p)
|
||||
#define DH_get0_pqg BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, DH_get0_pqg)
|
||||
#define DH_get0_priv_key BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, DH_get0_priv_key)
|
||||
#define DH_get0_pub_key BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, DH_get0_pub_key)
|
||||
#define DH_get0_q BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, DH_get0_q)
|
||||
#define DH_get_ex_data BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, DH_get_ex_data)
|
||||
#define DH_get_ex_new_index BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, DH_get_ex_new_index)
|
||||
#define DH_marshal_parameters BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, DH_marshal_parameters)
|
||||
@@ -644,6 +661,7 @@
|
||||
#define DH_set0_key BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, DH_set0_key)
|
||||
#define DH_set0_pqg BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, DH_set0_pqg)
|
||||
#define DH_set_ex_data BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, DH_set_ex_data)
|
||||
#define DH_set_length BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, DH_set_length)
|
||||
#define DH_size BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, DH_size)
|
||||
#define DH_up_ref BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, DH_up_ref)
|
||||
#define DHparams_dup BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, DHparams_dup)
|
||||
@@ -672,8 +690,13 @@
|
||||
#define DSA_free BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, DSA_free)
|
||||
#define DSA_generate_key BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, DSA_generate_key)
|
||||
#define DSA_generate_parameters_ex BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, DSA_generate_parameters_ex)
|
||||
#define DSA_get0_g BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, DSA_get0_g)
|
||||
#define DSA_get0_key BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, DSA_get0_key)
|
||||
#define DSA_get0_p BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, DSA_get0_p)
|
||||
#define DSA_get0_pqg BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, DSA_get0_pqg)
|
||||
#define DSA_get0_priv_key BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, DSA_get0_priv_key)
|
||||
#define DSA_get0_pub_key BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, DSA_get0_pub_key)
|
||||
#define DSA_get0_q BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, DSA_get0_q)
|
||||
#define DSA_get_ex_data BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, DSA_get_ex_data)
|
||||
#define DSA_get_ex_new_index BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, DSA_get_ex_new_index)
|
||||
#define DSA_marshal_parameters BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, DSA_marshal_parameters)
|
||||
@@ -696,6 +719,8 @@
|
||||
#define ECDSA_SIG_free BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, ECDSA_SIG_free)
|
||||
#define ECDSA_SIG_from_bytes BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, ECDSA_SIG_from_bytes)
|
||||
#define ECDSA_SIG_get0 BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, ECDSA_SIG_get0)
|
||||
#define ECDSA_SIG_get0_r BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, ECDSA_SIG_get0_r)
|
||||
#define ECDSA_SIG_get0_s BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, ECDSA_SIG_get0_s)
|
||||
#define ECDSA_SIG_marshal BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, ECDSA_SIG_marshal)
|
||||
#define ECDSA_SIG_max_len BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, ECDSA_SIG_max_len)
|
||||
#define ECDSA_SIG_new BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, ECDSA_SIG_new)
|
||||
@@ -1100,6 +1125,7 @@
|
||||
#define EVP_sha256 BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, EVP_sha256)
|
||||
#define EVP_sha384 BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, EVP_sha384)
|
||||
#define EVP_sha512 BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, EVP_sha512)
|
||||
#define EVP_sha512_256 BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, EVP_sha512_256)
|
||||
#define EVP_tls_cbc_copy_mac BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, EVP_tls_cbc_copy_mac)
|
||||
#define EVP_tls_cbc_digest_record BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, EVP_tls_cbc_digest_record)
|
||||
#define EVP_tls_cbc_record_digest_supported BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, EVP_tls_cbc_record_digest_supported)
|
||||
@@ -1378,6 +1404,7 @@
|
||||
#define PKEY_USAGE_PERIOD_free BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, PKEY_USAGE_PERIOD_free)
|
||||
#define PKEY_USAGE_PERIOD_it BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, PKEY_USAGE_PERIOD_it)
|
||||
#define PKEY_USAGE_PERIOD_new BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, PKEY_USAGE_PERIOD_new)
|
||||
#define PMBTOKEN_PRETOKEN_free BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, PMBTOKEN_PRETOKEN_free)
|
||||
#define POLICYINFO_free BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, POLICYINFO_free)
|
||||
#define POLICYINFO_it BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, POLICYINFO_it)
|
||||
#define POLICYINFO_new BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, POLICYINFO_new)
|
||||
@@ -1411,7 +1438,6 @@
|
||||
#define RAND_pseudo_bytes BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, RAND_pseudo_bytes)
|
||||
#define RAND_seed BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, RAND_seed)
|
||||
#define RAND_set_rand_method BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, RAND_set_rand_method)
|
||||
#define RAND_set_urandom_fd BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, RAND_set_urandom_fd)
|
||||
#define RAND_status BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, RAND_status)
|
||||
#define RC4 BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, RC4)
|
||||
#define RC4_set_key BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, RC4_set_key)
|
||||
@@ -1434,8 +1460,16 @@
|
||||
#define RSA_generate_key_ex BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, RSA_generate_key_ex)
|
||||
#define RSA_generate_key_fips BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, RSA_generate_key_fips)
|
||||
#define RSA_get0_crt_params BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, RSA_get0_crt_params)
|
||||
#define RSA_get0_d BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, RSA_get0_d)
|
||||
#define RSA_get0_dmp1 BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, RSA_get0_dmp1)
|
||||
#define RSA_get0_dmq1 BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, RSA_get0_dmq1)
|
||||
#define RSA_get0_e BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, RSA_get0_e)
|
||||
#define RSA_get0_factors BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, RSA_get0_factors)
|
||||
#define RSA_get0_iqmp BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, RSA_get0_iqmp)
|
||||
#define RSA_get0_key BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, RSA_get0_key)
|
||||
#define RSA_get0_n BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, RSA_get0_n)
|
||||
#define RSA_get0_p BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, RSA_get0_p)
|
||||
#define RSA_get0_q BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, RSA_get0_q)
|
||||
#define RSA_get_ex_data BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, RSA_get_ex_data)
|
||||
#define RSA_get_ex_new_index BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, RSA_get_ex_new_index)
|
||||
#define RSA_is_opaque BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, RSA_is_opaque)
|
||||
@@ -1496,6 +1530,10 @@
|
||||
#define SHA384_Init BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, SHA384_Init)
|
||||
#define SHA384_Update BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, SHA384_Update)
|
||||
#define SHA512 BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, SHA512)
|
||||
#define SHA512_256 BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, SHA512_256)
|
||||
#define SHA512_256_Final BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, SHA512_256_Final)
|
||||
#define SHA512_256_Init BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, SHA512_256_Init)
|
||||
#define SHA512_256_Update BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, SHA512_256_Update)
|
||||
#define SHA512_Final BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, SHA512_Final)
|
||||
#define SHA512_Init BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, SHA512_Init)
|
||||
#define SHA512_Transform BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, SHA512_Transform)
|
||||
@@ -1519,6 +1557,27 @@
|
||||
#define SXNET_get_id_ulong BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, SXNET_get_id_ulong)
|
||||
#define SXNET_it BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, SXNET_it)
|
||||
#define SXNET_new BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, SXNET_new)
|
||||
#define TRUST_TOKEN_CLIENT_add_key BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, TRUST_TOKEN_CLIENT_add_key)
|
||||
#define TRUST_TOKEN_CLIENT_begin_issuance BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, TRUST_TOKEN_CLIENT_begin_issuance)
|
||||
#define TRUST_TOKEN_CLIENT_begin_redemption BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, TRUST_TOKEN_CLIENT_begin_redemption)
|
||||
#define TRUST_TOKEN_CLIENT_finish_issuance BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, TRUST_TOKEN_CLIENT_finish_issuance)
|
||||
#define TRUST_TOKEN_CLIENT_finish_redemption BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, TRUST_TOKEN_CLIENT_finish_redemption)
|
||||
#define TRUST_TOKEN_CLIENT_free BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, TRUST_TOKEN_CLIENT_free)
|
||||
#define TRUST_TOKEN_CLIENT_new BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, TRUST_TOKEN_CLIENT_new)
|
||||
#define TRUST_TOKEN_CLIENT_set_srr_key BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, TRUST_TOKEN_CLIENT_set_srr_key)
|
||||
#define TRUST_TOKEN_ISSUER_add_key BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, TRUST_TOKEN_ISSUER_add_key)
|
||||
#define TRUST_TOKEN_ISSUER_free BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, TRUST_TOKEN_ISSUER_free)
|
||||
#define TRUST_TOKEN_ISSUER_issue BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, TRUST_TOKEN_ISSUER_issue)
|
||||
#define TRUST_TOKEN_ISSUER_new BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, TRUST_TOKEN_ISSUER_new)
|
||||
#define TRUST_TOKEN_ISSUER_redeem BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, TRUST_TOKEN_ISSUER_redeem)
|
||||
#define TRUST_TOKEN_ISSUER_set_metadata_key BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, TRUST_TOKEN_ISSUER_set_metadata_key)
|
||||
#define TRUST_TOKEN_ISSUER_set_srr_key BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, TRUST_TOKEN_ISSUER_set_srr_key)
|
||||
#define TRUST_TOKEN_decode_private_metadata BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, TRUST_TOKEN_decode_private_metadata)
|
||||
#define TRUST_TOKEN_experiment_v0 BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, TRUST_TOKEN_experiment_v0)
|
||||
#define TRUST_TOKEN_experiment_v1 BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, TRUST_TOKEN_experiment_v1)
|
||||
#define TRUST_TOKEN_free BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, TRUST_TOKEN_free)
|
||||
#define TRUST_TOKEN_generate_key BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, TRUST_TOKEN_generate_key)
|
||||
#define TRUST_TOKEN_new BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, TRUST_TOKEN_new)
|
||||
#define USERNOTICE_free BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, USERNOTICE_free)
|
||||
#define USERNOTICE_it BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, USERNOTICE_it)
|
||||
#define USERNOTICE_new BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, USERNOTICE_new)
|
||||
@@ -1794,6 +1853,7 @@
|
||||
#define X509_STORE_CTX_cleanup BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, X509_STORE_CTX_cleanup)
|
||||
#define X509_STORE_CTX_free BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, X509_STORE_CTX_free)
|
||||
#define X509_STORE_CTX_get0_cert BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, X509_STORE_CTX_get0_cert)
|
||||
#define X509_STORE_CTX_get0_chain BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, X509_STORE_CTX_get0_chain)
|
||||
#define X509_STORE_CTX_get0_current_crl BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, X509_STORE_CTX_get0_current_crl)
|
||||
#define X509_STORE_CTX_get0_current_issuer BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, X509_STORE_CTX_get0_current_issuer)
|
||||
#define X509_STORE_CTX_get0_param BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, X509_STORE_CTX_get0_param)
|
||||
@@ -1968,6 +2028,8 @@
|
||||
#define X509_get_serialNumber BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, X509_get_serialNumber)
|
||||
#define X509_get_signature_nid BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, X509_get_signature_nid)
|
||||
#define X509_get_subject_name BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, X509_get_subject_name)
|
||||
#define X509_getm_notAfter BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, X509_getm_notAfter)
|
||||
#define X509_getm_notBefore BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, X509_getm_notBefore)
|
||||
#define X509_gmtime_adj BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, X509_gmtime_adj)
|
||||
#define X509_issuer_and_serial_cmp BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, X509_issuer_and_serial_cmp)
|
||||
#define X509_issuer_and_serial_hash BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, X509_issuer_and_serial_hash)
|
||||
@@ -2123,9 +2185,9 @@
|
||||
#define bn_mod_add_words BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, bn_mod_add_words)
|
||||
#define bn_mod_exp_base_2_consttime BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, bn_mod_exp_base_2_consttime)
|
||||
#define bn_mod_exp_mont_small BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, bn_mod_exp_mont_small)
|
||||
#define bn_mod_inverse0_prime_mont_small BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, bn_mod_inverse0_prime_mont_small)
|
||||
#define bn_mod_inverse_consttime BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, bn_mod_inverse_consttime)
|
||||
#define bn_mod_inverse_prime BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, bn_mod_inverse_prime)
|
||||
#define bn_mod_inverse_prime_mont_small BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, bn_mod_inverse_prime_mont_small)
|
||||
#define bn_mod_inverse_secret_prime BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, bn_mod_inverse_secret_prime)
|
||||
#define bn_mod_lshift1_consttime BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, bn_mod_lshift1_consttime)
|
||||
#define bn_mod_lshift_consttime BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, bn_mod_lshift_consttime)
|
||||
@@ -2310,20 +2372,24 @@
|
||||
#define d2i_X509_fp BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, d2i_X509_fp)
|
||||
#define dsa_asn1_meth BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, dsa_asn1_meth)
|
||||
#define ec_GFp_mont_add BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, ec_GFp_mont_add)
|
||||
#define ec_GFp_mont_bignum_to_felem BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, ec_GFp_mont_bignum_to_felem)
|
||||
#define ec_GFp_mont_dbl BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, ec_GFp_mont_dbl)
|
||||
#define ec_GFp_mont_felem_from_bytes BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, ec_GFp_mont_felem_from_bytes)
|
||||
#define ec_GFp_mont_felem_mul BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, ec_GFp_mont_felem_mul)
|
||||
#define ec_GFp_mont_felem_sqr BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, ec_GFp_mont_felem_sqr)
|
||||
#define ec_GFp_mont_felem_to_bignum BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, ec_GFp_mont_felem_to_bignum)
|
||||
#define ec_GFp_mont_felem_to_bytes BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, ec_GFp_mont_felem_to_bytes)
|
||||
#define ec_GFp_mont_group_finish BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, ec_GFp_mont_group_finish)
|
||||
#define ec_GFp_mont_group_init BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, ec_GFp_mont_group_init)
|
||||
#define ec_GFp_mont_group_set_curve BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, ec_GFp_mont_group_set_curve)
|
||||
#define ec_GFp_mont_init_precomp BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, ec_GFp_mont_init_precomp)
|
||||
#define ec_GFp_mont_mul BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, ec_GFp_mont_mul)
|
||||
#define ec_GFp_mont_mul_base BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, ec_GFp_mont_mul_base)
|
||||
#define ec_GFp_mont_mul_public BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, ec_GFp_mont_mul_public)
|
||||
#define ec_GFp_mont_mul_batch BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, ec_GFp_mont_mul_batch)
|
||||
#define ec_GFp_mont_mul_precomp BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, ec_GFp_mont_mul_precomp)
|
||||
#define ec_GFp_mont_mul_public_batch BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, ec_GFp_mont_mul_public_batch)
|
||||
#define ec_GFp_nistp_recode_scalar_bits BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, ec_GFp_nistp_recode_scalar_bits)
|
||||
#define ec_GFp_simple_cmp BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, ec_GFp_simple_cmp)
|
||||
#define ec_GFp_simple_cmp_x_coordinate BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, ec_GFp_simple_cmp_x_coordinate)
|
||||
#define ec_GFp_simple_felem_from_bytes BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, ec_GFp_simple_felem_from_bytes)
|
||||
#define ec_GFp_simple_felem_to_bytes BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, ec_GFp_simple_felem_to_bytes)
|
||||
#define ec_GFp_simple_group_finish BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, ec_GFp_simple_group_finish)
|
||||
#define ec_GFp_simple_group_get_curve BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, ec_GFp_simple_group_get_curve)
|
||||
#define ec_GFp_simple_group_init BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, ec_GFp_simple_group_init)
|
||||
@@ -2331,11 +2397,13 @@
|
||||
#define ec_GFp_simple_invert BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, ec_GFp_simple_invert)
|
||||
#define ec_GFp_simple_is_at_infinity BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, ec_GFp_simple_is_at_infinity)
|
||||
#define ec_GFp_simple_is_on_curve BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, ec_GFp_simple_is_on_curve)
|
||||
#define ec_GFp_simple_mont_inv_mod_ord_vartime BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, ec_GFp_simple_mont_inv_mod_ord_vartime)
|
||||
#define ec_GFp_simple_point_copy BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, ec_GFp_simple_point_copy)
|
||||
#define ec_GFp_simple_point_init BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, ec_GFp_simple_point_init)
|
||||
#define ec_GFp_simple_point_set_affine_coordinates BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, ec_GFp_simple_point_set_affine_coordinates)
|
||||
#define ec_GFp_simple_point_set_to_infinity BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, ec_GFp_simple_point_set_to_infinity)
|
||||
#define ec_GFp_simple_points_equal BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, ec_GFp_simple_points_equal)
|
||||
#define ec_affine_jacobian_equal BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, ec_affine_jacobian_equal)
|
||||
#define ec_affine_select BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, ec_affine_select)
|
||||
#define ec_affine_to_jacobian BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, ec_affine_to_jacobian)
|
||||
#define ec_asn1_meth BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, ec_asn1_meth)
|
||||
#define ec_bignum_to_felem BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, ec_bignum_to_felem)
|
||||
#define ec_bignum_to_scalar BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, ec_bignum_to_scalar)
|
||||
@@ -2343,28 +2411,53 @@
|
||||
#define ec_compute_wNAF BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, ec_compute_wNAF)
|
||||
#define ec_felem_add BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, ec_felem_add)
|
||||
#define ec_felem_equal BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, ec_felem_equal)
|
||||
#define ec_felem_from_bytes BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, ec_felem_from_bytes)
|
||||
#define ec_felem_neg BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, ec_felem_neg)
|
||||
#define ec_felem_non_zero_mask BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, ec_felem_non_zero_mask)
|
||||
#define ec_felem_select BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, ec_felem_select)
|
||||
#define ec_felem_sub BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, ec_felem_sub)
|
||||
#define ec_felem_to_bignum BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, ec_felem_to_bignum)
|
||||
#define ec_felem_to_bytes BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, ec_felem_to_bytes)
|
||||
#define ec_get_x_coordinate_as_bytes BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, ec_get_x_coordinate_as_bytes)
|
||||
#define ec_get_x_coordinate_as_scalar BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, ec_get_x_coordinate_as_scalar)
|
||||
#define ec_group_new BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, ec_group_new)
|
||||
#define ec_hash_to_curve_p384_xmd_sha512_sswu_draft07 BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, ec_hash_to_curve_p384_xmd_sha512_sswu_draft07)
|
||||
#define ec_hash_to_curve_p521_xmd_sha512_sswu_draft06 BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, ec_hash_to_curve_p521_xmd_sha512_sswu_draft06)
|
||||
#define ec_hash_to_scalar_p384_xmd_sha512_draft07 BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, ec_hash_to_scalar_p384_xmd_sha512_draft07)
|
||||
#define ec_hash_to_scalar_p521_xmd_sha512_draft06 BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, ec_hash_to_scalar_p521_xmd_sha512_draft06)
|
||||
#define ec_init_precomp BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, ec_init_precomp)
|
||||
#define ec_jacobian_to_affine BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, ec_jacobian_to_affine)
|
||||
#define ec_jacobian_to_affine_batch BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, ec_jacobian_to_affine_batch)
|
||||
#define ec_pkey_meth BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, ec_pkey_meth)
|
||||
#define ec_point_get_affine_coordinate_bytes BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, ec_point_get_affine_coordinate_bytes)
|
||||
#define ec_point_from_uncompressed BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, ec_point_from_uncompressed)
|
||||
#define ec_point_mul_scalar BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, ec_point_mul_scalar)
|
||||
#define ec_point_mul_scalar_base BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, ec_point_mul_scalar_base)
|
||||
#define ec_point_mul_scalar_batch BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, ec_point_mul_scalar_batch)
|
||||
#define ec_point_mul_scalar_precomp BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, ec_point_mul_scalar_precomp)
|
||||
#define ec_point_mul_scalar_public BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, ec_point_mul_scalar_public)
|
||||
#define ec_point_mul_scalar_public_batch BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, ec_point_mul_scalar_public_batch)
|
||||
#define ec_point_select BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, ec_point_select)
|
||||
#define ec_point_set_affine_coordinates BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, ec_point_set_affine_coordinates)
|
||||
#define ec_point_to_bytes BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, ec_point_to_bytes)
|
||||
#define ec_precomp_select BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, ec_precomp_select)
|
||||
#define ec_random_nonzero_scalar BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, ec_random_nonzero_scalar)
|
||||
#define ec_scalar_add BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, ec_scalar_add)
|
||||
#define ec_scalar_equal_vartime BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, ec_scalar_equal_vartime)
|
||||
#define ec_scalar_from_bytes BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, ec_scalar_from_bytes)
|
||||
#define ec_scalar_from_montgomery BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, ec_scalar_from_montgomery)
|
||||
#define ec_scalar_inv_montgomery BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, ec_scalar_inv_montgomery)
|
||||
#define ec_scalar_inv_montgomery_vartime BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, ec_scalar_inv_montgomery_vartime)
|
||||
#define ec_scalar_inv0_montgomery BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, ec_scalar_inv0_montgomery)
|
||||
#define ec_scalar_is_zero BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, ec_scalar_is_zero)
|
||||
#define ec_scalar_mul_montgomery BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, ec_scalar_mul_montgomery)
|
||||
#define ec_scalar_neg BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, ec_scalar_neg)
|
||||
#define ec_scalar_reduce BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, ec_scalar_reduce)
|
||||
#define ec_scalar_select BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, ec_scalar_select)
|
||||
#define ec_scalar_sub BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, ec_scalar_sub)
|
||||
#define ec_scalar_to_bytes BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, ec_scalar_to_bytes)
|
||||
#define ec_scalar_to_montgomery BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, ec_scalar_to_montgomery)
|
||||
#define ec_simple_scalar_inv_montgomery BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, ec_simple_scalar_inv_montgomery)
|
||||
#define ec_scalar_to_montgomery_inv_vartime BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, ec_scalar_to_montgomery_inv_vartime)
|
||||
#define ec_set_to_safe_point BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, ec_set_to_safe_point)
|
||||
#define ec_simple_scalar_inv0_montgomery BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, ec_simple_scalar_inv0_montgomery)
|
||||
#define ec_simple_scalar_to_montgomery_inv_vartime BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, ec_simple_scalar_to_montgomery_inv_vartime)
|
||||
#define ecp_nistz256_avx2_select_w7 BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, ecp_nistz256_avx2_select_w7)
|
||||
#define ecp_nistz256_mul_mont BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, ecp_nistz256_mul_mont)
|
||||
#define ecp_nistz256_neg BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, ecp_nistz256_neg)
|
||||
@@ -2566,6 +2659,21 @@
|
||||
#define pkcs7_bundle BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, pkcs7_bundle)
|
||||
#define pkcs7_parse_header BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, pkcs7_parse_header)
|
||||
#define pkcs8_pbe_decrypt BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, pkcs8_pbe_decrypt)
|
||||
#define pmbtoken_exp0_blind BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, pmbtoken_exp0_blind)
|
||||
#define pmbtoken_exp0_client_key_from_bytes BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, pmbtoken_exp0_client_key_from_bytes)
|
||||
#define pmbtoken_exp0_generate_key BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, pmbtoken_exp0_generate_key)
|
||||
#define pmbtoken_exp0_issuer_key_from_bytes BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, pmbtoken_exp0_issuer_key_from_bytes)
|
||||
#define pmbtoken_exp0_read BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, pmbtoken_exp0_read)
|
||||
#define pmbtoken_exp0_sign BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, pmbtoken_exp0_sign)
|
||||
#define pmbtoken_exp0_unblind BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, pmbtoken_exp0_unblind)
|
||||
#define pmbtoken_exp1_blind BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, pmbtoken_exp1_blind)
|
||||
#define pmbtoken_exp1_client_key_from_bytes BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, pmbtoken_exp1_client_key_from_bytes)
|
||||
#define pmbtoken_exp1_generate_key BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, pmbtoken_exp1_generate_key)
|
||||
#define pmbtoken_exp1_get_h_for_testing BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, pmbtoken_exp1_get_h_for_testing)
|
||||
#define pmbtoken_exp1_issuer_key_from_bytes BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, pmbtoken_exp1_issuer_key_from_bytes)
|
||||
#define pmbtoken_exp1_read BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, pmbtoken_exp1_read)
|
||||
#define pmbtoken_exp1_sign BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, pmbtoken_exp1_sign)
|
||||
#define pmbtoken_exp1_unblind BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, pmbtoken_exp1_unblind)
|
||||
#define policy_cache_find_data BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, policy_cache_find_data)
|
||||
#define policy_cache_free BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, policy_cache_free)
|
||||
#define policy_cache_set BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, policy_cache_set)
|
||||
@@ -2698,6 +2806,29 @@
|
||||
#define sk_ASN1_STRING_TABLE_is_sorted BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, sk_ASN1_STRING_TABLE_is_sorted)
|
||||
#define sk_ASN1_STRING_TABLE_set_cmp_func BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, sk_ASN1_STRING_TABLE_set_cmp_func)
|
||||
#define sk_ASN1_STRING_TABLE_deep_copy BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, sk_ASN1_STRING_TABLE_deep_copy)
|
||||
#define sk_PMBTOKEN_PRETOKEN_call_free_func BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, sk_PMBTOKEN_PRETOKEN_call_free_func)
|
||||
#define sk_PMBTOKEN_PRETOKEN_call_copy_func BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, sk_PMBTOKEN_PRETOKEN_call_copy_func)
|
||||
#define sk_PMBTOKEN_PRETOKEN_call_cmp_func BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, sk_PMBTOKEN_PRETOKEN_call_cmp_func)
|
||||
#define sk_PMBTOKEN_PRETOKEN_new BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, sk_PMBTOKEN_PRETOKEN_new)
|
||||
#define sk_PMBTOKEN_PRETOKEN_new_null BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, sk_PMBTOKEN_PRETOKEN_new_null)
|
||||
#define sk_PMBTOKEN_PRETOKEN_num BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, sk_PMBTOKEN_PRETOKEN_num)
|
||||
#define sk_PMBTOKEN_PRETOKEN_zero BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, sk_PMBTOKEN_PRETOKEN_zero)
|
||||
#define sk_PMBTOKEN_PRETOKEN_value BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, sk_PMBTOKEN_PRETOKEN_value)
|
||||
#define sk_PMBTOKEN_PRETOKEN_set BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, sk_PMBTOKEN_PRETOKEN_set)
|
||||
#define sk_PMBTOKEN_PRETOKEN_free BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, sk_PMBTOKEN_PRETOKEN_free)
|
||||
#define sk_PMBTOKEN_PRETOKEN_pop_free BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, sk_PMBTOKEN_PRETOKEN_pop_free)
|
||||
#define sk_PMBTOKEN_PRETOKEN_insert BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, sk_PMBTOKEN_PRETOKEN_insert)
|
||||
#define sk_PMBTOKEN_PRETOKEN_delete BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, sk_PMBTOKEN_PRETOKEN_delete)
|
||||
#define sk_PMBTOKEN_PRETOKEN_delete_ptr BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, sk_PMBTOKEN_PRETOKEN_delete_ptr)
|
||||
#define sk_PMBTOKEN_PRETOKEN_find BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, sk_PMBTOKEN_PRETOKEN_find)
|
||||
#define sk_PMBTOKEN_PRETOKEN_shift BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, sk_PMBTOKEN_PRETOKEN_shift)
|
||||
#define sk_PMBTOKEN_PRETOKEN_push BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, sk_PMBTOKEN_PRETOKEN_push)
|
||||
#define sk_PMBTOKEN_PRETOKEN_pop BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, sk_PMBTOKEN_PRETOKEN_pop)
|
||||
#define sk_PMBTOKEN_PRETOKEN_dup BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, sk_PMBTOKEN_PRETOKEN_dup)
|
||||
#define sk_PMBTOKEN_PRETOKEN_sort BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, sk_PMBTOKEN_PRETOKEN_sort)
|
||||
#define sk_PMBTOKEN_PRETOKEN_is_sorted BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, sk_PMBTOKEN_PRETOKEN_is_sorted)
|
||||
#define sk_PMBTOKEN_PRETOKEN_set_cmp_func BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, sk_PMBTOKEN_PRETOKEN_set_cmp_func)
|
||||
#define sk_PMBTOKEN_PRETOKEN_deep_copy BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, sk_PMBTOKEN_PRETOKEN_deep_copy)
|
||||
#define sk_CRYPTO_EX_DATA_FUNCS_call_free_func BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, sk_CRYPTO_EX_DATA_FUNCS_call_free_func)
|
||||
#define sk_CRYPTO_EX_DATA_FUNCS_call_copy_func BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, sk_CRYPTO_EX_DATA_FUNCS_call_copy_func)
|
||||
#define sk_CRYPTO_EX_DATA_FUNCS_call_cmp_func BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, sk_CRYPTO_EX_DATA_FUNCS_call_cmp_func)
|
||||
@@ -3595,6 +3726,29 @@
|
||||
#define sk_OPENSSL_STRING_is_sorted BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, sk_OPENSSL_STRING_is_sorted)
|
||||
#define sk_OPENSSL_STRING_set_cmp_func BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, sk_OPENSSL_STRING_set_cmp_func)
|
||||
#define sk_OPENSSL_STRING_deep_copy BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, sk_OPENSSL_STRING_deep_copy)
|
||||
#define sk_TRUST_TOKEN_call_free_func BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, sk_TRUST_TOKEN_call_free_func)
|
||||
#define sk_TRUST_TOKEN_call_copy_func BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, sk_TRUST_TOKEN_call_copy_func)
|
||||
#define sk_TRUST_TOKEN_call_cmp_func BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, sk_TRUST_TOKEN_call_cmp_func)
|
||||
#define sk_TRUST_TOKEN_new BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, sk_TRUST_TOKEN_new)
|
||||
#define sk_TRUST_TOKEN_new_null BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, sk_TRUST_TOKEN_new_null)
|
||||
#define sk_TRUST_TOKEN_num BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, sk_TRUST_TOKEN_num)
|
||||
#define sk_TRUST_TOKEN_zero BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, sk_TRUST_TOKEN_zero)
|
||||
#define sk_TRUST_TOKEN_value BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, sk_TRUST_TOKEN_value)
|
||||
#define sk_TRUST_TOKEN_set BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, sk_TRUST_TOKEN_set)
|
||||
#define sk_TRUST_TOKEN_free BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, sk_TRUST_TOKEN_free)
|
||||
#define sk_TRUST_TOKEN_pop_free BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, sk_TRUST_TOKEN_pop_free)
|
||||
#define sk_TRUST_TOKEN_insert BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, sk_TRUST_TOKEN_insert)
|
||||
#define sk_TRUST_TOKEN_delete BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, sk_TRUST_TOKEN_delete)
|
||||
#define sk_TRUST_TOKEN_delete_ptr BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, sk_TRUST_TOKEN_delete_ptr)
|
||||
#define sk_TRUST_TOKEN_find BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, sk_TRUST_TOKEN_find)
|
||||
#define sk_TRUST_TOKEN_shift BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, sk_TRUST_TOKEN_shift)
|
||||
#define sk_TRUST_TOKEN_push BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, sk_TRUST_TOKEN_push)
|
||||
#define sk_TRUST_TOKEN_pop BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, sk_TRUST_TOKEN_pop)
|
||||
#define sk_TRUST_TOKEN_dup BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, sk_TRUST_TOKEN_dup)
|
||||
#define sk_TRUST_TOKEN_sort BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, sk_TRUST_TOKEN_sort)
|
||||
#define sk_TRUST_TOKEN_is_sorted BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, sk_TRUST_TOKEN_is_sorted)
|
||||
#define sk_TRUST_TOKEN_set_cmp_func BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, sk_TRUST_TOKEN_set_cmp_func)
|
||||
#define sk_TRUST_TOKEN_deep_copy BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, sk_TRUST_TOKEN_deep_copy)
|
||||
#define sk_ASN1_VALUE_call_free_func BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, sk_ASN1_VALUE_call_free_func)
|
||||
#define sk_ASN1_VALUE_call_copy_func BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, sk_ASN1_VALUE_call_copy_func)
|
||||
#define sk_ASN1_VALUE_call_cmp_func BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, sk_ASN1_VALUE_call_cmp_func)
|
||||
|
||||
@@ -311,6 +311,7 @@
|
||||
#define _BIO_write_filename BORINGSSL_ADD_PREFIX_MAC_ASM(BORINGSSL_PREFIX, BIO_write_filename)
|
||||
#define _BN_BLINDING_convert BORINGSSL_ADD_PREFIX_MAC_ASM(BORINGSSL_PREFIX, BN_BLINDING_convert)
|
||||
#define _BN_BLINDING_free BORINGSSL_ADD_PREFIX_MAC_ASM(BORINGSSL_PREFIX, BN_BLINDING_free)
|
||||
#define _BN_BLINDING_invalidate BORINGSSL_ADD_PREFIX_MAC_ASM(BORINGSSL_PREFIX, BN_BLINDING_invalidate)
|
||||
#define _BN_BLINDING_invert BORINGSSL_ADD_PREFIX_MAC_ASM(BORINGSSL_PREFIX, BN_BLINDING_invert)
|
||||
#define _BN_BLINDING_new BORINGSSL_ADD_PREFIX_MAC_ASM(BORINGSSL_PREFIX, BN_BLINDING_new)
|
||||
#define _BN_CTX_end BORINGSSL_ADD_PREFIX_MAC_ASM(BORINGSSL_PREFIX, BN_CTX_end)
|
||||
@@ -459,10 +460,13 @@
|
||||
#define _CBB_add_space BORINGSSL_ADD_PREFIX_MAC_ASM(BORINGSSL_PREFIX, CBB_add_space)
|
||||
#define _CBB_add_u16 BORINGSSL_ADD_PREFIX_MAC_ASM(BORINGSSL_PREFIX, CBB_add_u16)
|
||||
#define _CBB_add_u16_length_prefixed BORINGSSL_ADD_PREFIX_MAC_ASM(BORINGSSL_PREFIX, CBB_add_u16_length_prefixed)
|
||||
#define _CBB_add_u16le BORINGSSL_ADD_PREFIX_MAC_ASM(BORINGSSL_PREFIX, CBB_add_u16le)
|
||||
#define _CBB_add_u24 BORINGSSL_ADD_PREFIX_MAC_ASM(BORINGSSL_PREFIX, CBB_add_u24)
|
||||
#define _CBB_add_u24_length_prefixed BORINGSSL_ADD_PREFIX_MAC_ASM(BORINGSSL_PREFIX, CBB_add_u24_length_prefixed)
|
||||
#define _CBB_add_u32 BORINGSSL_ADD_PREFIX_MAC_ASM(BORINGSSL_PREFIX, CBB_add_u32)
|
||||
#define _CBB_add_u32le BORINGSSL_ADD_PREFIX_MAC_ASM(BORINGSSL_PREFIX, CBB_add_u32le)
|
||||
#define _CBB_add_u64 BORINGSSL_ADD_PREFIX_MAC_ASM(BORINGSSL_PREFIX, CBB_add_u64)
|
||||
#define _CBB_add_u64le BORINGSSL_ADD_PREFIX_MAC_ASM(BORINGSSL_PREFIX, CBB_add_u64le)
|
||||
#define _CBB_add_u8 BORINGSSL_ADD_PREFIX_MAC_ASM(BORINGSSL_PREFIX, CBB_add_u8)
|
||||
#define _CBB_add_u8_length_prefixed BORINGSSL_ADD_PREFIX_MAC_ASM(BORINGSSL_PREFIX, CBB_add_u8_length_prefixed)
|
||||
#define _CBB_cleanup BORINGSSL_ADD_PREFIX_MAC_ASM(BORINGSSL_PREFIX, CBB_cleanup)
|
||||
@@ -501,10 +505,13 @@
|
||||
#define _CBS_get_optional_asn1_uint64 BORINGSSL_ADD_PREFIX_MAC_ASM(BORINGSSL_PREFIX, CBS_get_optional_asn1_uint64)
|
||||
#define _CBS_get_u16 BORINGSSL_ADD_PREFIX_MAC_ASM(BORINGSSL_PREFIX, CBS_get_u16)
|
||||
#define _CBS_get_u16_length_prefixed BORINGSSL_ADD_PREFIX_MAC_ASM(BORINGSSL_PREFIX, CBS_get_u16_length_prefixed)
|
||||
#define _CBS_get_u16le BORINGSSL_ADD_PREFIX_MAC_ASM(BORINGSSL_PREFIX, CBS_get_u16le)
|
||||
#define _CBS_get_u24 BORINGSSL_ADD_PREFIX_MAC_ASM(BORINGSSL_PREFIX, CBS_get_u24)
|
||||
#define _CBS_get_u24_length_prefixed BORINGSSL_ADD_PREFIX_MAC_ASM(BORINGSSL_PREFIX, CBS_get_u24_length_prefixed)
|
||||
#define _CBS_get_u32 BORINGSSL_ADD_PREFIX_MAC_ASM(BORINGSSL_PREFIX, CBS_get_u32)
|
||||
#define _CBS_get_u32le BORINGSSL_ADD_PREFIX_MAC_ASM(BORINGSSL_PREFIX, CBS_get_u32le)
|
||||
#define _CBS_get_u64 BORINGSSL_ADD_PREFIX_MAC_ASM(BORINGSSL_PREFIX, CBS_get_u64)
|
||||
#define _CBS_get_u64le BORINGSSL_ADD_PREFIX_MAC_ASM(BORINGSSL_PREFIX, CBS_get_u64le)
|
||||
#define _CBS_get_u8 BORINGSSL_ADD_PREFIX_MAC_ASM(BORINGSSL_PREFIX, CBS_get_u8)
|
||||
#define _CBS_get_u8_length_prefixed BORINGSSL_ADD_PREFIX_MAC_ASM(BORINGSSL_PREFIX, CBS_get_u8_length_prefixed)
|
||||
#define _CBS_init BORINGSSL_ADD_PREFIX_MAC_ASM(BORINGSSL_PREFIX, CBS_init)
|
||||
@@ -568,6 +575,7 @@
|
||||
#define _CRYPTO_cleanup_all_ex_data BORINGSSL_ADD_PREFIX_MAC_ASM(BORINGSSL_PREFIX, CRYPTO_cleanup_all_ex_data)
|
||||
#define _CRYPTO_ctr128_encrypt BORINGSSL_ADD_PREFIX_MAC_ASM(BORINGSSL_PREFIX, CRYPTO_ctr128_encrypt)
|
||||
#define _CRYPTO_ctr128_encrypt_ctr32 BORINGSSL_ADD_PREFIX_MAC_ASM(BORINGSSL_PREFIX, CRYPTO_ctr128_encrypt_ctr32)
|
||||
#define _CRYPTO_fork_detect_ignore_madv_wipeonfork_for_testing BORINGSSL_ADD_PREFIX_MAC_ASM(BORINGSSL_PREFIX, CRYPTO_fork_detect_ignore_madv_wipeonfork_for_testing)
|
||||
#define _CRYPTO_free_ex_data BORINGSSL_ADD_PREFIX_MAC_ASM(BORINGSSL_PREFIX, CRYPTO_free_ex_data)
|
||||
#define _CRYPTO_gcm128_aad BORINGSSL_ADD_PREFIX_MAC_ASM(BORINGSSL_PREFIX, CRYPTO_gcm128_aad)
|
||||
#define _CRYPTO_gcm128_decrypt BORINGSSL_ADD_PREFIX_MAC_ASM(BORINGSSL_PREFIX, CRYPTO_gcm128_decrypt)
|
||||
@@ -583,12 +591,14 @@
|
||||
#define _CRYPTO_get_dynlock_lock_callback BORINGSSL_ADD_PREFIX_MAC_ASM(BORINGSSL_PREFIX, CRYPTO_get_dynlock_lock_callback)
|
||||
#define _CRYPTO_get_ex_data BORINGSSL_ADD_PREFIX_MAC_ASM(BORINGSSL_PREFIX, CRYPTO_get_ex_data)
|
||||
#define _CRYPTO_get_ex_new_index BORINGSSL_ADD_PREFIX_MAC_ASM(BORINGSSL_PREFIX, CRYPTO_get_ex_new_index)
|
||||
#define _CRYPTO_get_fork_generation BORINGSSL_ADD_PREFIX_MAC_ASM(BORINGSSL_PREFIX, CRYPTO_get_fork_generation)
|
||||
#define _CRYPTO_get_lock_name BORINGSSL_ADD_PREFIX_MAC_ASM(BORINGSSL_PREFIX, CRYPTO_get_lock_name)
|
||||
#define _CRYPTO_get_locking_callback BORINGSSL_ADD_PREFIX_MAC_ASM(BORINGSSL_PREFIX, CRYPTO_get_locking_callback)
|
||||
#define _CRYPTO_get_thread_local BORINGSSL_ADD_PREFIX_MAC_ASM(BORINGSSL_PREFIX, CRYPTO_get_thread_local)
|
||||
#define _CRYPTO_ghash_init BORINGSSL_ADD_PREFIX_MAC_ASM(BORINGSSL_PREFIX, CRYPTO_ghash_init)
|
||||
#define _CRYPTO_has_asm BORINGSSL_ADD_PREFIX_MAC_ASM(BORINGSSL_PREFIX, CRYPTO_has_asm)
|
||||
#define _CRYPTO_hchacha20 BORINGSSL_ADD_PREFIX_MAC_ASM(BORINGSSL_PREFIX, CRYPTO_hchacha20)
|
||||
#define _CRYPTO_init_sysrand BORINGSSL_ADD_PREFIX_MAC_ASM(BORINGSSL_PREFIX, CRYPTO_init_sysrand)
|
||||
#define _CRYPTO_is_ARMv8_AES_capable BORINGSSL_ADD_PREFIX_MAC_ASM(BORINGSSL_PREFIX, CRYPTO_is_ARMv8_AES_capable)
|
||||
#define _CRYPTO_is_ARMv8_PMULL_capable BORINGSSL_ADD_PREFIX_MAC_ASM(BORINGSSL_PREFIX, CRYPTO_is_ARMv8_PMULL_capable)
|
||||
#define _CRYPTO_is_NEON_capable_at_runtime BORINGSSL_ADD_PREFIX_MAC_ASM(BORINGSSL_PREFIX, CRYPTO_is_NEON_capable_at_runtime)
|
||||
@@ -603,6 +613,7 @@
|
||||
#define _CRYPTO_poly1305_finish BORINGSSL_ADD_PREFIX_MAC_ASM(BORINGSSL_PREFIX, CRYPTO_poly1305_finish)
|
||||
#define _CRYPTO_poly1305_init BORINGSSL_ADD_PREFIX_MAC_ASM(BORINGSSL_PREFIX, CRYPTO_poly1305_init)
|
||||
#define _CRYPTO_poly1305_update BORINGSSL_ADD_PREFIX_MAC_ASM(BORINGSSL_PREFIX, CRYPTO_poly1305_update)
|
||||
#define _CRYPTO_pre_sandbox_init BORINGSSL_ADD_PREFIX_MAC_ASM(BORINGSSL_PREFIX, CRYPTO_pre_sandbox_init)
|
||||
#define _CRYPTO_rdrand BORINGSSL_ADD_PREFIX_MAC_ASM(BORINGSSL_PREFIX, CRYPTO_rdrand)
|
||||
#define _CRYPTO_rdrand_multiple8_buf BORINGSSL_ADD_PREFIX_MAC_ASM(BORINGSSL_PREFIX, CRYPTO_rdrand_multiple8_buf)
|
||||
#define _CRYPTO_refcount_dec_and_test_zero BORINGSSL_ADD_PREFIX_MAC_ASM(BORINGSSL_PREFIX, CRYPTO_refcount_dec_and_test_zero)
|
||||
@@ -616,6 +627,7 @@
|
||||
#define _CRYPTO_set_locking_callback BORINGSSL_ADD_PREFIX_MAC_ASM(BORINGSSL_PREFIX, CRYPTO_set_locking_callback)
|
||||
#define _CRYPTO_set_thread_local BORINGSSL_ADD_PREFIX_MAC_ASM(BORINGSSL_PREFIX, CRYPTO_set_thread_local)
|
||||
#define _CRYPTO_sysrand BORINGSSL_ADD_PREFIX_MAC_ASM(BORINGSSL_PREFIX, CRYPTO_sysrand)
|
||||
#define _CRYPTO_sysrand_if_available BORINGSSL_ADD_PREFIX_MAC_ASM(BORINGSSL_PREFIX, CRYPTO_sysrand_if_available)
|
||||
#define _CRYPTO_tls1_prf BORINGSSL_ADD_PREFIX_MAC_ASM(BORINGSSL_PREFIX, CRYPTO_tls1_prf)
|
||||
#define _CTR_DRBG_clear BORINGSSL_ADD_PREFIX_MAC_ASM(BORINGSSL_PREFIX, CTR_DRBG_clear)
|
||||
#define _CTR_DRBG_generate BORINGSSL_ADD_PREFIX_MAC_ASM(BORINGSSL_PREFIX, CTR_DRBG_generate)
|
||||
@@ -638,8 +650,13 @@
|
||||
#define _DH_free BORINGSSL_ADD_PREFIX_MAC_ASM(BORINGSSL_PREFIX, DH_free)
|
||||
#define _DH_generate_key BORINGSSL_ADD_PREFIX_MAC_ASM(BORINGSSL_PREFIX, DH_generate_key)
|
||||
#define _DH_generate_parameters_ex BORINGSSL_ADD_PREFIX_MAC_ASM(BORINGSSL_PREFIX, DH_generate_parameters_ex)
|
||||
#define _DH_get0_g BORINGSSL_ADD_PREFIX_MAC_ASM(BORINGSSL_PREFIX, DH_get0_g)
|
||||
#define _DH_get0_key BORINGSSL_ADD_PREFIX_MAC_ASM(BORINGSSL_PREFIX, DH_get0_key)
|
||||
#define _DH_get0_p BORINGSSL_ADD_PREFIX_MAC_ASM(BORINGSSL_PREFIX, DH_get0_p)
|
||||
#define _DH_get0_pqg BORINGSSL_ADD_PREFIX_MAC_ASM(BORINGSSL_PREFIX, DH_get0_pqg)
|
||||
#define _DH_get0_priv_key BORINGSSL_ADD_PREFIX_MAC_ASM(BORINGSSL_PREFIX, DH_get0_priv_key)
|
||||
#define _DH_get0_pub_key BORINGSSL_ADD_PREFIX_MAC_ASM(BORINGSSL_PREFIX, DH_get0_pub_key)
|
||||
#define _DH_get0_q BORINGSSL_ADD_PREFIX_MAC_ASM(BORINGSSL_PREFIX, DH_get0_q)
|
||||
#define _DH_get_ex_data BORINGSSL_ADD_PREFIX_MAC_ASM(BORINGSSL_PREFIX, DH_get_ex_data)
|
||||
#define _DH_get_ex_new_index BORINGSSL_ADD_PREFIX_MAC_ASM(BORINGSSL_PREFIX, DH_get_ex_new_index)
|
||||
#define _DH_marshal_parameters BORINGSSL_ADD_PREFIX_MAC_ASM(BORINGSSL_PREFIX, DH_marshal_parameters)
|
||||
@@ -649,6 +666,7 @@
|
||||
#define _DH_set0_key BORINGSSL_ADD_PREFIX_MAC_ASM(BORINGSSL_PREFIX, DH_set0_key)
|
||||
#define _DH_set0_pqg BORINGSSL_ADD_PREFIX_MAC_ASM(BORINGSSL_PREFIX, DH_set0_pqg)
|
||||
#define _DH_set_ex_data BORINGSSL_ADD_PREFIX_MAC_ASM(BORINGSSL_PREFIX, DH_set_ex_data)
|
||||
#define _DH_set_length BORINGSSL_ADD_PREFIX_MAC_ASM(BORINGSSL_PREFIX, DH_set_length)
|
||||
#define _DH_size BORINGSSL_ADD_PREFIX_MAC_ASM(BORINGSSL_PREFIX, DH_size)
|
||||
#define _DH_up_ref BORINGSSL_ADD_PREFIX_MAC_ASM(BORINGSSL_PREFIX, DH_up_ref)
|
||||
#define _DHparams_dup BORINGSSL_ADD_PREFIX_MAC_ASM(BORINGSSL_PREFIX, DHparams_dup)
|
||||
@@ -677,8 +695,13 @@
|
||||
#define _DSA_free BORINGSSL_ADD_PREFIX_MAC_ASM(BORINGSSL_PREFIX, DSA_free)
|
||||
#define _DSA_generate_key BORINGSSL_ADD_PREFIX_MAC_ASM(BORINGSSL_PREFIX, DSA_generate_key)
|
||||
#define _DSA_generate_parameters_ex BORINGSSL_ADD_PREFIX_MAC_ASM(BORINGSSL_PREFIX, DSA_generate_parameters_ex)
|
||||
#define _DSA_get0_g BORINGSSL_ADD_PREFIX_MAC_ASM(BORINGSSL_PREFIX, DSA_get0_g)
|
||||
#define _DSA_get0_key BORINGSSL_ADD_PREFIX_MAC_ASM(BORINGSSL_PREFIX, DSA_get0_key)
|
||||
#define _DSA_get0_p BORINGSSL_ADD_PREFIX_MAC_ASM(BORINGSSL_PREFIX, DSA_get0_p)
|
||||
#define _DSA_get0_pqg BORINGSSL_ADD_PREFIX_MAC_ASM(BORINGSSL_PREFIX, DSA_get0_pqg)
|
||||
#define _DSA_get0_priv_key BORINGSSL_ADD_PREFIX_MAC_ASM(BORINGSSL_PREFIX, DSA_get0_priv_key)
|
||||
#define _DSA_get0_pub_key BORINGSSL_ADD_PREFIX_MAC_ASM(BORINGSSL_PREFIX, DSA_get0_pub_key)
|
||||
#define _DSA_get0_q BORINGSSL_ADD_PREFIX_MAC_ASM(BORINGSSL_PREFIX, DSA_get0_q)
|
||||
#define _DSA_get_ex_data BORINGSSL_ADD_PREFIX_MAC_ASM(BORINGSSL_PREFIX, DSA_get_ex_data)
|
||||
#define _DSA_get_ex_new_index BORINGSSL_ADD_PREFIX_MAC_ASM(BORINGSSL_PREFIX, DSA_get_ex_new_index)
|
||||
#define _DSA_marshal_parameters BORINGSSL_ADD_PREFIX_MAC_ASM(BORINGSSL_PREFIX, DSA_marshal_parameters)
|
||||
@@ -701,6 +724,8 @@
|
||||
#define _ECDSA_SIG_free BORINGSSL_ADD_PREFIX_MAC_ASM(BORINGSSL_PREFIX, ECDSA_SIG_free)
|
||||
#define _ECDSA_SIG_from_bytes BORINGSSL_ADD_PREFIX_MAC_ASM(BORINGSSL_PREFIX, ECDSA_SIG_from_bytes)
|
||||
#define _ECDSA_SIG_get0 BORINGSSL_ADD_PREFIX_MAC_ASM(BORINGSSL_PREFIX, ECDSA_SIG_get0)
|
||||
#define _ECDSA_SIG_get0_r BORINGSSL_ADD_PREFIX_MAC_ASM(BORINGSSL_PREFIX, ECDSA_SIG_get0_r)
|
||||
#define _ECDSA_SIG_get0_s BORINGSSL_ADD_PREFIX_MAC_ASM(BORINGSSL_PREFIX, ECDSA_SIG_get0_s)
|
||||
#define _ECDSA_SIG_marshal BORINGSSL_ADD_PREFIX_MAC_ASM(BORINGSSL_PREFIX, ECDSA_SIG_marshal)
|
||||
#define _ECDSA_SIG_max_len BORINGSSL_ADD_PREFIX_MAC_ASM(BORINGSSL_PREFIX, ECDSA_SIG_max_len)
|
||||
#define _ECDSA_SIG_new BORINGSSL_ADD_PREFIX_MAC_ASM(BORINGSSL_PREFIX, ECDSA_SIG_new)
|
||||
@@ -1105,6 +1130,7 @@
|
||||
#define _EVP_sha256 BORINGSSL_ADD_PREFIX_MAC_ASM(BORINGSSL_PREFIX, EVP_sha256)
|
||||
#define _EVP_sha384 BORINGSSL_ADD_PREFIX_MAC_ASM(BORINGSSL_PREFIX, EVP_sha384)
|
||||
#define _EVP_sha512 BORINGSSL_ADD_PREFIX_MAC_ASM(BORINGSSL_PREFIX, EVP_sha512)
|
||||
#define _EVP_sha512_256 BORINGSSL_ADD_PREFIX_MAC_ASM(BORINGSSL_PREFIX, EVP_sha512_256)
|
||||
#define _EVP_tls_cbc_copy_mac BORINGSSL_ADD_PREFIX_MAC_ASM(BORINGSSL_PREFIX, EVP_tls_cbc_copy_mac)
|
||||
#define _EVP_tls_cbc_digest_record BORINGSSL_ADD_PREFIX_MAC_ASM(BORINGSSL_PREFIX, EVP_tls_cbc_digest_record)
|
||||
#define _EVP_tls_cbc_record_digest_supported BORINGSSL_ADD_PREFIX_MAC_ASM(BORINGSSL_PREFIX, EVP_tls_cbc_record_digest_supported)
|
||||
@@ -1383,6 +1409,7 @@
|
||||
#define _PKEY_USAGE_PERIOD_free BORINGSSL_ADD_PREFIX_MAC_ASM(BORINGSSL_PREFIX, PKEY_USAGE_PERIOD_free)
|
||||
#define _PKEY_USAGE_PERIOD_it BORINGSSL_ADD_PREFIX_MAC_ASM(BORINGSSL_PREFIX, PKEY_USAGE_PERIOD_it)
|
||||
#define _PKEY_USAGE_PERIOD_new BORINGSSL_ADD_PREFIX_MAC_ASM(BORINGSSL_PREFIX, PKEY_USAGE_PERIOD_new)
|
||||
#define _PMBTOKEN_PRETOKEN_free BORINGSSL_ADD_PREFIX_MAC_ASM(BORINGSSL_PREFIX, PMBTOKEN_PRETOKEN_free)
|
||||
#define _POLICYINFO_free BORINGSSL_ADD_PREFIX_MAC_ASM(BORINGSSL_PREFIX, POLICYINFO_free)
|
||||
#define _POLICYINFO_it BORINGSSL_ADD_PREFIX_MAC_ASM(BORINGSSL_PREFIX, POLICYINFO_it)
|
||||
#define _POLICYINFO_new BORINGSSL_ADD_PREFIX_MAC_ASM(BORINGSSL_PREFIX, POLICYINFO_new)
|
||||
@@ -1416,7 +1443,6 @@
|
||||
#define _RAND_pseudo_bytes BORINGSSL_ADD_PREFIX_MAC_ASM(BORINGSSL_PREFIX, RAND_pseudo_bytes)
|
||||
#define _RAND_seed BORINGSSL_ADD_PREFIX_MAC_ASM(BORINGSSL_PREFIX, RAND_seed)
|
||||
#define _RAND_set_rand_method BORINGSSL_ADD_PREFIX_MAC_ASM(BORINGSSL_PREFIX, RAND_set_rand_method)
|
||||
#define _RAND_set_urandom_fd BORINGSSL_ADD_PREFIX_MAC_ASM(BORINGSSL_PREFIX, RAND_set_urandom_fd)
|
||||
#define _RAND_status BORINGSSL_ADD_PREFIX_MAC_ASM(BORINGSSL_PREFIX, RAND_status)
|
||||
#define _RC4 BORINGSSL_ADD_PREFIX_MAC_ASM(BORINGSSL_PREFIX, RC4)
|
||||
#define _RC4_set_key BORINGSSL_ADD_PREFIX_MAC_ASM(BORINGSSL_PREFIX, RC4_set_key)
|
||||
@@ -1439,8 +1465,16 @@
|
||||
#define _RSA_generate_key_ex BORINGSSL_ADD_PREFIX_MAC_ASM(BORINGSSL_PREFIX, RSA_generate_key_ex)
|
||||
#define _RSA_generate_key_fips BORINGSSL_ADD_PREFIX_MAC_ASM(BORINGSSL_PREFIX, RSA_generate_key_fips)
|
||||
#define _RSA_get0_crt_params BORINGSSL_ADD_PREFIX_MAC_ASM(BORINGSSL_PREFIX, RSA_get0_crt_params)
|
||||
#define _RSA_get0_d BORINGSSL_ADD_PREFIX_MAC_ASM(BORINGSSL_PREFIX, RSA_get0_d)
|
||||
#define _RSA_get0_dmp1 BORINGSSL_ADD_PREFIX_MAC_ASM(BORINGSSL_PREFIX, RSA_get0_dmp1)
|
||||
#define _RSA_get0_dmq1 BORINGSSL_ADD_PREFIX_MAC_ASM(BORINGSSL_PREFIX, RSA_get0_dmq1)
|
||||
#define _RSA_get0_e BORINGSSL_ADD_PREFIX_MAC_ASM(BORINGSSL_PREFIX, RSA_get0_e)
|
||||
#define _RSA_get0_factors BORINGSSL_ADD_PREFIX_MAC_ASM(BORINGSSL_PREFIX, RSA_get0_factors)
|
||||
#define _RSA_get0_iqmp BORINGSSL_ADD_PREFIX_MAC_ASM(BORINGSSL_PREFIX, RSA_get0_iqmp)
|
||||
#define _RSA_get0_key BORINGSSL_ADD_PREFIX_MAC_ASM(BORINGSSL_PREFIX, RSA_get0_key)
|
||||
#define _RSA_get0_n BORINGSSL_ADD_PREFIX_MAC_ASM(BORINGSSL_PREFIX, RSA_get0_n)
|
||||
#define _RSA_get0_p BORINGSSL_ADD_PREFIX_MAC_ASM(BORINGSSL_PREFIX, RSA_get0_p)
|
||||
#define _RSA_get0_q BORINGSSL_ADD_PREFIX_MAC_ASM(BORINGSSL_PREFIX, RSA_get0_q)
|
||||
#define _RSA_get_ex_data BORINGSSL_ADD_PREFIX_MAC_ASM(BORINGSSL_PREFIX, RSA_get_ex_data)
|
||||
#define _RSA_get_ex_new_index BORINGSSL_ADD_PREFIX_MAC_ASM(BORINGSSL_PREFIX, RSA_get_ex_new_index)
|
||||
#define _RSA_is_opaque BORINGSSL_ADD_PREFIX_MAC_ASM(BORINGSSL_PREFIX, RSA_is_opaque)
|
||||
@@ -1501,6 +1535,10 @@
|
||||
#define _SHA384_Init BORINGSSL_ADD_PREFIX_MAC_ASM(BORINGSSL_PREFIX, SHA384_Init)
|
||||
#define _SHA384_Update BORINGSSL_ADD_PREFIX_MAC_ASM(BORINGSSL_PREFIX, SHA384_Update)
|
||||
#define _SHA512 BORINGSSL_ADD_PREFIX_MAC_ASM(BORINGSSL_PREFIX, SHA512)
|
||||
#define _SHA512_256 BORINGSSL_ADD_PREFIX_MAC_ASM(BORINGSSL_PREFIX, SHA512_256)
|
||||
#define _SHA512_256_Final BORINGSSL_ADD_PREFIX_MAC_ASM(BORINGSSL_PREFIX, SHA512_256_Final)
|
||||
#define _SHA512_256_Init BORINGSSL_ADD_PREFIX_MAC_ASM(BORINGSSL_PREFIX, SHA512_256_Init)
|
||||
#define _SHA512_256_Update BORINGSSL_ADD_PREFIX_MAC_ASM(BORINGSSL_PREFIX, SHA512_256_Update)
|
||||
#define _SHA512_Final BORINGSSL_ADD_PREFIX_MAC_ASM(BORINGSSL_PREFIX, SHA512_Final)
|
||||
#define _SHA512_Init BORINGSSL_ADD_PREFIX_MAC_ASM(BORINGSSL_PREFIX, SHA512_Init)
|
||||
#define _SHA512_Transform BORINGSSL_ADD_PREFIX_MAC_ASM(BORINGSSL_PREFIX, SHA512_Transform)
|
||||
@@ -1524,6 +1562,27 @@
|
||||
#define _SXNET_get_id_ulong BORINGSSL_ADD_PREFIX_MAC_ASM(BORINGSSL_PREFIX, SXNET_get_id_ulong)
|
||||
#define _SXNET_it BORINGSSL_ADD_PREFIX_MAC_ASM(BORINGSSL_PREFIX, SXNET_it)
|
||||
#define _SXNET_new BORINGSSL_ADD_PREFIX_MAC_ASM(BORINGSSL_PREFIX, SXNET_new)
|
||||
#define _TRUST_TOKEN_CLIENT_add_key BORINGSSL_ADD_PREFIX_MAC_ASM(BORINGSSL_PREFIX, TRUST_TOKEN_CLIENT_add_key)
|
||||
#define _TRUST_TOKEN_CLIENT_begin_issuance BORINGSSL_ADD_PREFIX_MAC_ASM(BORINGSSL_PREFIX, TRUST_TOKEN_CLIENT_begin_issuance)
|
||||
#define _TRUST_TOKEN_CLIENT_begin_redemption BORINGSSL_ADD_PREFIX_MAC_ASM(BORINGSSL_PREFIX, TRUST_TOKEN_CLIENT_begin_redemption)
|
||||
#define _TRUST_TOKEN_CLIENT_finish_issuance BORINGSSL_ADD_PREFIX_MAC_ASM(BORINGSSL_PREFIX, TRUST_TOKEN_CLIENT_finish_issuance)
|
||||
#define _TRUST_TOKEN_CLIENT_finish_redemption BORINGSSL_ADD_PREFIX_MAC_ASM(BORINGSSL_PREFIX, TRUST_TOKEN_CLIENT_finish_redemption)
|
||||
#define _TRUST_TOKEN_CLIENT_free BORINGSSL_ADD_PREFIX_MAC_ASM(BORINGSSL_PREFIX, TRUST_TOKEN_CLIENT_free)
|
||||
#define _TRUST_TOKEN_CLIENT_new BORINGSSL_ADD_PREFIX_MAC_ASM(BORINGSSL_PREFIX, TRUST_TOKEN_CLIENT_new)
|
||||
#define _TRUST_TOKEN_CLIENT_set_srr_key BORINGSSL_ADD_PREFIX_MAC_ASM(BORINGSSL_PREFIX, TRUST_TOKEN_CLIENT_set_srr_key)
|
||||
#define _TRUST_TOKEN_ISSUER_add_key BORINGSSL_ADD_PREFIX_MAC_ASM(BORINGSSL_PREFIX, TRUST_TOKEN_ISSUER_add_key)
|
||||
#define _TRUST_TOKEN_ISSUER_free BORINGSSL_ADD_PREFIX_MAC_ASM(BORINGSSL_PREFIX, TRUST_TOKEN_ISSUER_free)
|
||||
#define _TRUST_TOKEN_ISSUER_issue BORINGSSL_ADD_PREFIX_MAC_ASM(BORINGSSL_PREFIX, TRUST_TOKEN_ISSUER_issue)
|
||||
#define _TRUST_TOKEN_ISSUER_new BORINGSSL_ADD_PREFIX_MAC_ASM(BORINGSSL_PREFIX, TRUST_TOKEN_ISSUER_new)
|
||||
#define _TRUST_TOKEN_ISSUER_redeem BORINGSSL_ADD_PREFIX_MAC_ASM(BORINGSSL_PREFIX, TRUST_TOKEN_ISSUER_redeem)
|
||||
#define _TRUST_TOKEN_ISSUER_set_metadata_key BORINGSSL_ADD_PREFIX_MAC_ASM(BORINGSSL_PREFIX, TRUST_TOKEN_ISSUER_set_metadata_key)
|
||||
#define _TRUST_TOKEN_ISSUER_set_srr_key BORINGSSL_ADD_PREFIX_MAC_ASM(BORINGSSL_PREFIX, TRUST_TOKEN_ISSUER_set_srr_key)
|
||||
#define _TRUST_TOKEN_decode_private_metadata BORINGSSL_ADD_PREFIX_MAC_ASM(BORINGSSL_PREFIX, TRUST_TOKEN_decode_private_metadata)
|
||||
#define _TRUST_TOKEN_experiment_v0 BORINGSSL_ADD_PREFIX_MAC_ASM(BORINGSSL_PREFIX, TRUST_TOKEN_experiment_v0)
|
||||
#define _TRUST_TOKEN_experiment_v1 BORINGSSL_ADD_PREFIX_MAC_ASM(BORINGSSL_PREFIX, TRUST_TOKEN_experiment_v1)
|
||||
#define _TRUST_TOKEN_free BORINGSSL_ADD_PREFIX_MAC_ASM(BORINGSSL_PREFIX, TRUST_TOKEN_free)
|
||||
#define _TRUST_TOKEN_generate_key BORINGSSL_ADD_PREFIX_MAC_ASM(BORINGSSL_PREFIX, TRUST_TOKEN_generate_key)
|
||||
#define _TRUST_TOKEN_new BORINGSSL_ADD_PREFIX_MAC_ASM(BORINGSSL_PREFIX, TRUST_TOKEN_new)
|
||||
#define _USERNOTICE_free BORINGSSL_ADD_PREFIX_MAC_ASM(BORINGSSL_PREFIX, USERNOTICE_free)
|
||||
#define _USERNOTICE_it BORINGSSL_ADD_PREFIX_MAC_ASM(BORINGSSL_PREFIX, USERNOTICE_it)
|
||||
#define _USERNOTICE_new BORINGSSL_ADD_PREFIX_MAC_ASM(BORINGSSL_PREFIX, USERNOTICE_new)
|
||||
@@ -1799,6 +1858,7 @@
|
||||
#define _X509_STORE_CTX_cleanup BORINGSSL_ADD_PREFIX_MAC_ASM(BORINGSSL_PREFIX, X509_STORE_CTX_cleanup)
|
||||
#define _X509_STORE_CTX_free BORINGSSL_ADD_PREFIX_MAC_ASM(BORINGSSL_PREFIX, X509_STORE_CTX_free)
|
||||
#define _X509_STORE_CTX_get0_cert BORINGSSL_ADD_PREFIX_MAC_ASM(BORINGSSL_PREFIX, X509_STORE_CTX_get0_cert)
|
||||
#define _X509_STORE_CTX_get0_chain BORINGSSL_ADD_PREFIX_MAC_ASM(BORINGSSL_PREFIX, X509_STORE_CTX_get0_chain)
|
||||
#define _X509_STORE_CTX_get0_current_crl BORINGSSL_ADD_PREFIX_MAC_ASM(BORINGSSL_PREFIX, X509_STORE_CTX_get0_current_crl)
|
||||
#define _X509_STORE_CTX_get0_current_issuer BORINGSSL_ADD_PREFIX_MAC_ASM(BORINGSSL_PREFIX, X509_STORE_CTX_get0_current_issuer)
|
||||
#define _X509_STORE_CTX_get0_param BORINGSSL_ADD_PREFIX_MAC_ASM(BORINGSSL_PREFIX, X509_STORE_CTX_get0_param)
|
||||
@@ -1973,6 +2033,8 @@
|
||||
#define _X509_get_serialNumber BORINGSSL_ADD_PREFIX_MAC_ASM(BORINGSSL_PREFIX, X509_get_serialNumber)
|
||||
#define _X509_get_signature_nid BORINGSSL_ADD_PREFIX_MAC_ASM(BORINGSSL_PREFIX, X509_get_signature_nid)
|
||||
#define _X509_get_subject_name BORINGSSL_ADD_PREFIX_MAC_ASM(BORINGSSL_PREFIX, X509_get_subject_name)
|
||||
#define _X509_getm_notAfter BORINGSSL_ADD_PREFIX_MAC_ASM(BORINGSSL_PREFIX, X509_getm_notAfter)
|
||||
#define _X509_getm_notBefore BORINGSSL_ADD_PREFIX_MAC_ASM(BORINGSSL_PREFIX, X509_getm_notBefore)
|
||||
#define _X509_gmtime_adj BORINGSSL_ADD_PREFIX_MAC_ASM(BORINGSSL_PREFIX, X509_gmtime_adj)
|
||||
#define _X509_issuer_and_serial_cmp BORINGSSL_ADD_PREFIX_MAC_ASM(BORINGSSL_PREFIX, X509_issuer_and_serial_cmp)
|
||||
#define _X509_issuer_and_serial_hash BORINGSSL_ADD_PREFIX_MAC_ASM(BORINGSSL_PREFIX, X509_issuer_and_serial_hash)
|
||||
@@ -2128,9 +2190,9 @@
|
||||
#define _bn_mod_add_words BORINGSSL_ADD_PREFIX_MAC_ASM(BORINGSSL_PREFIX, bn_mod_add_words)
|
||||
#define _bn_mod_exp_base_2_consttime BORINGSSL_ADD_PREFIX_MAC_ASM(BORINGSSL_PREFIX, bn_mod_exp_base_2_consttime)
|
||||
#define _bn_mod_exp_mont_small BORINGSSL_ADD_PREFIX_MAC_ASM(BORINGSSL_PREFIX, bn_mod_exp_mont_small)
|
||||
#define _bn_mod_inverse0_prime_mont_small BORINGSSL_ADD_PREFIX_MAC_ASM(BORINGSSL_PREFIX, bn_mod_inverse0_prime_mont_small)
|
||||
#define _bn_mod_inverse_consttime BORINGSSL_ADD_PREFIX_MAC_ASM(BORINGSSL_PREFIX, bn_mod_inverse_consttime)
|
||||
#define _bn_mod_inverse_prime BORINGSSL_ADD_PREFIX_MAC_ASM(BORINGSSL_PREFIX, bn_mod_inverse_prime)
|
||||
#define _bn_mod_inverse_prime_mont_small BORINGSSL_ADD_PREFIX_MAC_ASM(BORINGSSL_PREFIX, bn_mod_inverse_prime_mont_small)
|
||||
#define _bn_mod_inverse_secret_prime BORINGSSL_ADD_PREFIX_MAC_ASM(BORINGSSL_PREFIX, bn_mod_inverse_secret_prime)
|
||||
#define _bn_mod_lshift1_consttime BORINGSSL_ADD_PREFIX_MAC_ASM(BORINGSSL_PREFIX, bn_mod_lshift1_consttime)
|
||||
#define _bn_mod_lshift_consttime BORINGSSL_ADD_PREFIX_MAC_ASM(BORINGSSL_PREFIX, bn_mod_lshift_consttime)
|
||||
@@ -2315,20 +2377,24 @@
|
||||
#define _d2i_X509_fp BORINGSSL_ADD_PREFIX_MAC_ASM(BORINGSSL_PREFIX, d2i_X509_fp)
|
||||
#define _dsa_asn1_meth BORINGSSL_ADD_PREFIX_MAC_ASM(BORINGSSL_PREFIX, dsa_asn1_meth)
|
||||
#define _ec_GFp_mont_add BORINGSSL_ADD_PREFIX_MAC_ASM(BORINGSSL_PREFIX, ec_GFp_mont_add)
|
||||
#define _ec_GFp_mont_bignum_to_felem BORINGSSL_ADD_PREFIX_MAC_ASM(BORINGSSL_PREFIX, ec_GFp_mont_bignum_to_felem)
|
||||
#define _ec_GFp_mont_dbl BORINGSSL_ADD_PREFIX_MAC_ASM(BORINGSSL_PREFIX, ec_GFp_mont_dbl)
|
||||
#define _ec_GFp_mont_felem_from_bytes BORINGSSL_ADD_PREFIX_MAC_ASM(BORINGSSL_PREFIX, ec_GFp_mont_felem_from_bytes)
|
||||
#define _ec_GFp_mont_felem_mul BORINGSSL_ADD_PREFIX_MAC_ASM(BORINGSSL_PREFIX, ec_GFp_mont_felem_mul)
|
||||
#define _ec_GFp_mont_felem_sqr BORINGSSL_ADD_PREFIX_MAC_ASM(BORINGSSL_PREFIX, ec_GFp_mont_felem_sqr)
|
||||
#define _ec_GFp_mont_felem_to_bignum BORINGSSL_ADD_PREFIX_MAC_ASM(BORINGSSL_PREFIX, ec_GFp_mont_felem_to_bignum)
|
||||
#define _ec_GFp_mont_felem_to_bytes BORINGSSL_ADD_PREFIX_MAC_ASM(BORINGSSL_PREFIX, ec_GFp_mont_felem_to_bytes)
|
||||
#define _ec_GFp_mont_group_finish BORINGSSL_ADD_PREFIX_MAC_ASM(BORINGSSL_PREFIX, ec_GFp_mont_group_finish)
|
||||
#define _ec_GFp_mont_group_init BORINGSSL_ADD_PREFIX_MAC_ASM(BORINGSSL_PREFIX, ec_GFp_mont_group_init)
|
||||
#define _ec_GFp_mont_group_set_curve BORINGSSL_ADD_PREFIX_MAC_ASM(BORINGSSL_PREFIX, ec_GFp_mont_group_set_curve)
|
||||
#define _ec_GFp_mont_init_precomp BORINGSSL_ADD_PREFIX_MAC_ASM(BORINGSSL_PREFIX, ec_GFp_mont_init_precomp)
|
||||
#define _ec_GFp_mont_mul BORINGSSL_ADD_PREFIX_MAC_ASM(BORINGSSL_PREFIX, ec_GFp_mont_mul)
|
||||
#define _ec_GFp_mont_mul_base BORINGSSL_ADD_PREFIX_MAC_ASM(BORINGSSL_PREFIX, ec_GFp_mont_mul_base)
|
||||
#define _ec_GFp_mont_mul_public BORINGSSL_ADD_PREFIX_MAC_ASM(BORINGSSL_PREFIX, ec_GFp_mont_mul_public)
|
||||
#define _ec_GFp_mont_mul_batch BORINGSSL_ADD_PREFIX_MAC_ASM(BORINGSSL_PREFIX, ec_GFp_mont_mul_batch)
|
||||
#define _ec_GFp_mont_mul_precomp BORINGSSL_ADD_PREFIX_MAC_ASM(BORINGSSL_PREFIX, ec_GFp_mont_mul_precomp)
|
||||
#define _ec_GFp_mont_mul_public_batch BORINGSSL_ADD_PREFIX_MAC_ASM(BORINGSSL_PREFIX, ec_GFp_mont_mul_public_batch)
|
||||
#define _ec_GFp_nistp_recode_scalar_bits BORINGSSL_ADD_PREFIX_MAC_ASM(BORINGSSL_PREFIX, ec_GFp_nistp_recode_scalar_bits)
|
||||
#define _ec_GFp_simple_cmp BORINGSSL_ADD_PREFIX_MAC_ASM(BORINGSSL_PREFIX, ec_GFp_simple_cmp)
|
||||
#define _ec_GFp_simple_cmp_x_coordinate BORINGSSL_ADD_PREFIX_MAC_ASM(BORINGSSL_PREFIX, ec_GFp_simple_cmp_x_coordinate)
|
||||
#define _ec_GFp_simple_felem_from_bytes BORINGSSL_ADD_PREFIX_MAC_ASM(BORINGSSL_PREFIX, ec_GFp_simple_felem_from_bytes)
|
||||
#define _ec_GFp_simple_felem_to_bytes BORINGSSL_ADD_PREFIX_MAC_ASM(BORINGSSL_PREFIX, ec_GFp_simple_felem_to_bytes)
|
||||
#define _ec_GFp_simple_group_finish BORINGSSL_ADD_PREFIX_MAC_ASM(BORINGSSL_PREFIX, ec_GFp_simple_group_finish)
|
||||
#define _ec_GFp_simple_group_get_curve BORINGSSL_ADD_PREFIX_MAC_ASM(BORINGSSL_PREFIX, ec_GFp_simple_group_get_curve)
|
||||
#define _ec_GFp_simple_group_init BORINGSSL_ADD_PREFIX_MAC_ASM(BORINGSSL_PREFIX, ec_GFp_simple_group_init)
|
||||
@@ -2336,11 +2402,13 @@
|
||||
#define _ec_GFp_simple_invert BORINGSSL_ADD_PREFIX_MAC_ASM(BORINGSSL_PREFIX, ec_GFp_simple_invert)
|
||||
#define _ec_GFp_simple_is_at_infinity BORINGSSL_ADD_PREFIX_MAC_ASM(BORINGSSL_PREFIX, ec_GFp_simple_is_at_infinity)
|
||||
#define _ec_GFp_simple_is_on_curve BORINGSSL_ADD_PREFIX_MAC_ASM(BORINGSSL_PREFIX, ec_GFp_simple_is_on_curve)
|
||||
#define _ec_GFp_simple_mont_inv_mod_ord_vartime BORINGSSL_ADD_PREFIX_MAC_ASM(BORINGSSL_PREFIX, ec_GFp_simple_mont_inv_mod_ord_vartime)
|
||||
#define _ec_GFp_simple_point_copy BORINGSSL_ADD_PREFIX_MAC_ASM(BORINGSSL_PREFIX, ec_GFp_simple_point_copy)
|
||||
#define _ec_GFp_simple_point_init BORINGSSL_ADD_PREFIX_MAC_ASM(BORINGSSL_PREFIX, ec_GFp_simple_point_init)
|
||||
#define _ec_GFp_simple_point_set_affine_coordinates BORINGSSL_ADD_PREFIX_MAC_ASM(BORINGSSL_PREFIX, ec_GFp_simple_point_set_affine_coordinates)
|
||||
#define _ec_GFp_simple_point_set_to_infinity BORINGSSL_ADD_PREFIX_MAC_ASM(BORINGSSL_PREFIX, ec_GFp_simple_point_set_to_infinity)
|
||||
#define _ec_GFp_simple_points_equal BORINGSSL_ADD_PREFIX_MAC_ASM(BORINGSSL_PREFIX, ec_GFp_simple_points_equal)
|
||||
#define _ec_affine_jacobian_equal BORINGSSL_ADD_PREFIX_MAC_ASM(BORINGSSL_PREFIX, ec_affine_jacobian_equal)
|
||||
#define _ec_affine_select BORINGSSL_ADD_PREFIX_MAC_ASM(BORINGSSL_PREFIX, ec_affine_select)
|
||||
#define _ec_affine_to_jacobian BORINGSSL_ADD_PREFIX_MAC_ASM(BORINGSSL_PREFIX, ec_affine_to_jacobian)
|
||||
#define _ec_asn1_meth BORINGSSL_ADD_PREFIX_MAC_ASM(BORINGSSL_PREFIX, ec_asn1_meth)
|
||||
#define _ec_bignum_to_felem BORINGSSL_ADD_PREFIX_MAC_ASM(BORINGSSL_PREFIX, ec_bignum_to_felem)
|
||||
#define _ec_bignum_to_scalar BORINGSSL_ADD_PREFIX_MAC_ASM(BORINGSSL_PREFIX, ec_bignum_to_scalar)
|
||||
@@ -2348,28 +2416,53 @@
|
||||
#define _ec_compute_wNAF BORINGSSL_ADD_PREFIX_MAC_ASM(BORINGSSL_PREFIX, ec_compute_wNAF)
|
||||
#define _ec_felem_add BORINGSSL_ADD_PREFIX_MAC_ASM(BORINGSSL_PREFIX, ec_felem_add)
|
||||
#define _ec_felem_equal BORINGSSL_ADD_PREFIX_MAC_ASM(BORINGSSL_PREFIX, ec_felem_equal)
|
||||
#define _ec_felem_from_bytes BORINGSSL_ADD_PREFIX_MAC_ASM(BORINGSSL_PREFIX, ec_felem_from_bytes)
|
||||
#define _ec_felem_neg BORINGSSL_ADD_PREFIX_MAC_ASM(BORINGSSL_PREFIX, ec_felem_neg)
|
||||
#define _ec_felem_non_zero_mask BORINGSSL_ADD_PREFIX_MAC_ASM(BORINGSSL_PREFIX, ec_felem_non_zero_mask)
|
||||
#define _ec_felem_select BORINGSSL_ADD_PREFIX_MAC_ASM(BORINGSSL_PREFIX, ec_felem_select)
|
||||
#define _ec_felem_sub BORINGSSL_ADD_PREFIX_MAC_ASM(BORINGSSL_PREFIX, ec_felem_sub)
|
||||
#define _ec_felem_to_bignum BORINGSSL_ADD_PREFIX_MAC_ASM(BORINGSSL_PREFIX, ec_felem_to_bignum)
|
||||
#define _ec_felem_to_bytes BORINGSSL_ADD_PREFIX_MAC_ASM(BORINGSSL_PREFIX, ec_felem_to_bytes)
|
||||
#define _ec_get_x_coordinate_as_bytes BORINGSSL_ADD_PREFIX_MAC_ASM(BORINGSSL_PREFIX, ec_get_x_coordinate_as_bytes)
|
||||
#define _ec_get_x_coordinate_as_scalar BORINGSSL_ADD_PREFIX_MAC_ASM(BORINGSSL_PREFIX, ec_get_x_coordinate_as_scalar)
|
||||
#define _ec_group_new BORINGSSL_ADD_PREFIX_MAC_ASM(BORINGSSL_PREFIX, ec_group_new)
|
||||
#define _ec_hash_to_curve_p384_xmd_sha512_sswu_draft07 BORINGSSL_ADD_PREFIX_MAC_ASM(BORINGSSL_PREFIX, ec_hash_to_curve_p384_xmd_sha512_sswu_draft07)
|
||||
#define _ec_hash_to_curve_p521_xmd_sha512_sswu_draft06 BORINGSSL_ADD_PREFIX_MAC_ASM(BORINGSSL_PREFIX, ec_hash_to_curve_p521_xmd_sha512_sswu_draft06)
|
||||
#define _ec_hash_to_scalar_p384_xmd_sha512_draft07 BORINGSSL_ADD_PREFIX_MAC_ASM(BORINGSSL_PREFIX, ec_hash_to_scalar_p384_xmd_sha512_draft07)
|
||||
#define _ec_hash_to_scalar_p521_xmd_sha512_draft06 BORINGSSL_ADD_PREFIX_MAC_ASM(BORINGSSL_PREFIX, ec_hash_to_scalar_p521_xmd_sha512_draft06)
|
||||
#define _ec_init_precomp BORINGSSL_ADD_PREFIX_MAC_ASM(BORINGSSL_PREFIX, ec_init_precomp)
|
||||
#define _ec_jacobian_to_affine BORINGSSL_ADD_PREFIX_MAC_ASM(BORINGSSL_PREFIX, ec_jacobian_to_affine)
|
||||
#define _ec_jacobian_to_affine_batch BORINGSSL_ADD_PREFIX_MAC_ASM(BORINGSSL_PREFIX, ec_jacobian_to_affine_batch)
|
||||
#define _ec_pkey_meth BORINGSSL_ADD_PREFIX_MAC_ASM(BORINGSSL_PREFIX, ec_pkey_meth)
|
||||
#define _ec_point_get_affine_coordinate_bytes BORINGSSL_ADD_PREFIX_MAC_ASM(BORINGSSL_PREFIX, ec_point_get_affine_coordinate_bytes)
|
||||
#define _ec_point_from_uncompressed BORINGSSL_ADD_PREFIX_MAC_ASM(BORINGSSL_PREFIX, ec_point_from_uncompressed)
|
||||
#define _ec_point_mul_scalar BORINGSSL_ADD_PREFIX_MAC_ASM(BORINGSSL_PREFIX, ec_point_mul_scalar)
|
||||
#define _ec_point_mul_scalar_base BORINGSSL_ADD_PREFIX_MAC_ASM(BORINGSSL_PREFIX, ec_point_mul_scalar_base)
|
||||
#define _ec_point_mul_scalar_batch BORINGSSL_ADD_PREFIX_MAC_ASM(BORINGSSL_PREFIX, ec_point_mul_scalar_batch)
|
||||
#define _ec_point_mul_scalar_precomp BORINGSSL_ADD_PREFIX_MAC_ASM(BORINGSSL_PREFIX, ec_point_mul_scalar_precomp)
|
||||
#define _ec_point_mul_scalar_public BORINGSSL_ADD_PREFIX_MAC_ASM(BORINGSSL_PREFIX, ec_point_mul_scalar_public)
|
||||
#define _ec_point_mul_scalar_public_batch BORINGSSL_ADD_PREFIX_MAC_ASM(BORINGSSL_PREFIX, ec_point_mul_scalar_public_batch)
|
||||
#define _ec_point_select BORINGSSL_ADD_PREFIX_MAC_ASM(BORINGSSL_PREFIX, ec_point_select)
|
||||
#define _ec_point_set_affine_coordinates BORINGSSL_ADD_PREFIX_MAC_ASM(BORINGSSL_PREFIX, ec_point_set_affine_coordinates)
|
||||
#define _ec_point_to_bytes BORINGSSL_ADD_PREFIX_MAC_ASM(BORINGSSL_PREFIX, ec_point_to_bytes)
|
||||
#define _ec_precomp_select BORINGSSL_ADD_PREFIX_MAC_ASM(BORINGSSL_PREFIX, ec_precomp_select)
|
||||
#define _ec_random_nonzero_scalar BORINGSSL_ADD_PREFIX_MAC_ASM(BORINGSSL_PREFIX, ec_random_nonzero_scalar)
|
||||
#define _ec_scalar_add BORINGSSL_ADD_PREFIX_MAC_ASM(BORINGSSL_PREFIX, ec_scalar_add)
|
||||
#define _ec_scalar_equal_vartime BORINGSSL_ADD_PREFIX_MAC_ASM(BORINGSSL_PREFIX, ec_scalar_equal_vartime)
|
||||
#define _ec_scalar_from_bytes BORINGSSL_ADD_PREFIX_MAC_ASM(BORINGSSL_PREFIX, ec_scalar_from_bytes)
|
||||
#define _ec_scalar_from_montgomery BORINGSSL_ADD_PREFIX_MAC_ASM(BORINGSSL_PREFIX, ec_scalar_from_montgomery)
|
||||
#define _ec_scalar_inv_montgomery BORINGSSL_ADD_PREFIX_MAC_ASM(BORINGSSL_PREFIX, ec_scalar_inv_montgomery)
|
||||
#define _ec_scalar_inv_montgomery_vartime BORINGSSL_ADD_PREFIX_MAC_ASM(BORINGSSL_PREFIX, ec_scalar_inv_montgomery_vartime)
|
||||
#define _ec_scalar_inv0_montgomery BORINGSSL_ADD_PREFIX_MAC_ASM(BORINGSSL_PREFIX, ec_scalar_inv0_montgomery)
|
||||
#define _ec_scalar_is_zero BORINGSSL_ADD_PREFIX_MAC_ASM(BORINGSSL_PREFIX, ec_scalar_is_zero)
|
||||
#define _ec_scalar_mul_montgomery BORINGSSL_ADD_PREFIX_MAC_ASM(BORINGSSL_PREFIX, ec_scalar_mul_montgomery)
|
||||
#define _ec_scalar_neg BORINGSSL_ADD_PREFIX_MAC_ASM(BORINGSSL_PREFIX, ec_scalar_neg)
|
||||
#define _ec_scalar_reduce BORINGSSL_ADD_PREFIX_MAC_ASM(BORINGSSL_PREFIX, ec_scalar_reduce)
|
||||
#define _ec_scalar_select BORINGSSL_ADD_PREFIX_MAC_ASM(BORINGSSL_PREFIX, ec_scalar_select)
|
||||
#define _ec_scalar_sub BORINGSSL_ADD_PREFIX_MAC_ASM(BORINGSSL_PREFIX, ec_scalar_sub)
|
||||
#define _ec_scalar_to_bytes BORINGSSL_ADD_PREFIX_MAC_ASM(BORINGSSL_PREFIX, ec_scalar_to_bytes)
|
||||
#define _ec_scalar_to_montgomery BORINGSSL_ADD_PREFIX_MAC_ASM(BORINGSSL_PREFIX, ec_scalar_to_montgomery)
|
||||
#define _ec_simple_scalar_inv_montgomery BORINGSSL_ADD_PREFIX_MAC_ASM(BORINGSSL_PREFIX, ec_simple_scalar_inv_montgomery)
|
||||
#define _ec_scalar_to_montgomery_inv_vartime BORINGSSL_ADD_PREFIX_MAC_ASM(BORINGSSL_PREFIX, ec_scalar_to_montgomery_inv_vartime)
|
||||
#define _ec_set_to_safe_point BORINGSSL_ADD_PREFIX_MAC_ASM(BORINGSSL_PREFIX, ec_set_to_safe_point)
|
||||
#define _ec_simple_scalar_inv0_montgomery BORINGSSL_ADD_PREFIX_MAC_ASM(BORINGSSL_PREFIX, ec_simple_scalar_inv0_montgomery)
|
||||
#define _ec_simple_scalar_to_montgomery_inv_vartime BORINGSSL_ADD_PREFIX_MAC_ASM(BORINGSSL_PREFIX, ec_simple_scalar_to_montgomery_inv_vartime)
|
||||
#define _ecp_nistz256_avx2_select_w7 BORINGSSL_ADD_PREFIX_MAC_ASM(BORINGSSL_PREFIX, ecp_nistz256_avx2_select_w7)
|
||||
#define _ecp_nistz256_mul_mont BORINGSSL_ADD_PREFIX_MAC_ASM(BORINGSSL_PREFIX, ecp_nistz256_mul_mont)
|
||||
#define _ecp_nistz256_neg BORINGSSL_ADD_PREFIX_MAC_ASM(BORINGSSL_PREFIX, ecp_nistz256_neg)
|
||||
@@ -2571,6 +2664,21 @@
|
||||
#define _pkcs7_bundle BORINGSSL_ADD_PREFIX_MAC_ASM(BORINGSSL_PREFIX, pkcs7_bundle)
|
||||
#define _pkcs7_parse_header BORINGSSL_ADD_PREFIX_MAC_ASM(BORINGSSL_PREFIX, pkcs7_parse_header)
|
||||
#define _pkcs8_pbe_decrypt BORINGSSL_ADD_PREFIX_MAC_ASM(BORINGSSL_PREFIX, pkcs8_pbe_decrypt)
|
||||
#define _pmbtoken_exp0_blind BORINGSSL_ADD_PREFIX_MAC_ASM(BORINGSSL_PREFIX, pmbtoken_exp0_blind)
|
||||
#define _pmbtoken_exp0_client_key_from_bytes BORINGSSL_ADD_PREFIX_MAC_ASM(BORINGSSL_PREFIX, pmbtoken_exp0_client_key_from_bytes)
|
||||
#define _pmbtoken_exp0_generate_key BORINGSSL_ADD_PREFIX_MAC_ASM(BORINGSSL_PREFIX, pmbtoken_exp0_generate_key)
|
||||
#define _pmbtoken_exp0_issuer_key_from_bytes BORINGSSL_ADD_PREFIX_MAC_ASM(BORINGSSL_PREFIX, pmbtoken_exp0_issuer_key_from_bytes)
|
||||
#define _pmbtoken_exp0_read BORINGSSL_ADD_PREFIX_MAC_ASM(BORINGSSL_PREFIX, pmbtoken_exp0_read)
|
||||
#define _pmbtoken_exp0_sign BORINGSSL_ADD_PREFIX_MAC_ASM(BORINGSSL_PREFIX, pmbtoken_exp0_sign)
|
||||
#define _pmbtoken_exp0_unblind BORINGSSL_ADD_PREFIX_MAC_ASM(BORINGSSL_PREFIX, pmbtoken_exp0_unblind)
|
||||
#define _pmbtoken_exp1_blind BORINGSSL_ADD_PREFIX_MAC_ASM(BORINGSSL_PREFIX, pmbtoken_exp1_blind)
|
||||
#define _pmbtoken_exp1_client_key_from_bytes BORINGSSL_ADD_PREFIX_MAC_ASM(BORINGSSL_PREFIX, pmbtoken_exp1_client_key_from_bytes)
|
||||
#define _pmbtoken_exp1_generate_key BORINGSSL_ADD_PREFIX_MAC_ASM(BORINGSSL_PREFIX, pmbtoken_exp1_generate_key)
|
||||
#define _pmbtoken_exp1_get_h_for_testing BORINGSSL_ADD_PREFIX_MAC_ASM(BORINGSSL_PREFIX, pmbtoken_exp1_get_h_for_testing)
|
||||
#define _pmbtoken_exp1_issuer_key_from_bytes BORINGSSL_ADD_PREFIX_MAC_ASM(BORINGSSL_PREFIX, pmbtoken_exp1_issuer_key_from_bytes)
|
||||
#define _pmbtoken_exp1_read BORINGSSL_ADD_PREFIX_MAC_ASM(BORINGSSL_PREFIX, pmbtoken_exp1_read)
|
||||
#define _pmbtoken_exp1_sign BORINGSSL_ADD_PREFIX_MAC_ASM(BORINGSSL_PREFIX, pmbtoken_exp1_sign)
|
||||
#define _pmbtoken_exp1_unblind BORINGSSL_ADD_PREFIX_MAC_ASM(BORINGSSL_PREFIX, pmbtoken_exp1_unblind)
|
||||
#define _policy_cache_find_data BORINGSSL_ADD_PREFIX_MAC_ASM(BORINGSSL_PREFIX, policy_cache_find_data)
|
||||
#define _policy_cache_free BORINGSSL_ADD_PREFIX_MAC_ASM(BORINGSSL_PREFIX, policy_cache_free)
|
||||
#define _policy_cache_set BORINGSSL_ADD_PREFIX_MAC_ASM(BORINGSSL_PREFIX, policy_cache_set)
|
||||
|
||||
@@ -102,6 +102,10 @@ OPENSSL_EXPORT int CBS_get_u8(CBS *cbs, uint8_t *out);
|
||||
// advances |cbs|. It returns one on success and zero on error.
|
||||
OPENSSL_EXPORT int CBS_get_u16(CBS *cbs, uint16_t *out);
|
||||
|
||||
// CBS_get_u16le sets |*out| to the next, little-endian uint16_t from |cbs| and
|
||||
// advances |cbs|. It returns one on success and zero on error.
|
||||
OPENSSL_EXPORT int CBS_get_u16le(CBS *cbs, uint16_t *out);
|
||||
|
||||
// CBS_get_u24 sets |*out| to the next, big-endian 24-bit value from |cbs| and
|
||||
// advances |cbs|. It returns one on success and zero on error.
|
||||
OPENSSL_EXPORT int CBS_get_u24(CBS *cbs, uint32_t *out);
|
||||
@@ -110,10 +114,18 @@ OPENSSL_EXPORT int CBS_get_u24(CBS *cbs, uint32_t *out);
|
||||
// and advances |cbs|. It returns one on success and zero on error.
|
||||
OPENSSL_EXPORT int CBS_get_u32(CBS *cbs, uint32_t *out);
|
||||
|
||||
// CBS_get_u32le sets |*out| to the next, little-endian uint32_t value from
|
||||
// |cbs| and advances |cbs|. It returns one on success and zero on error.
|
||||
OPENSSL_EXPORT int CBS_get_u32le(CBS *cbs, uint32_t *out);
|
||||
|
||||
// CBS_get_u64 sets |*out| to the next, big-endian uint64_t value from |cbs|
|
||||
// and advances |cbs|. It returns one on success and zero on error.
|
||||
OPENSSL_EXPORT int CBS_get_u64(CBS *cbs, uint64_t *out);
|
||||
|
||||
// CBS_get_u64le sets |*out| to the next, little-endian uint64_t value from
|
||||
// |cbs| and advances |cbs|. It returns one on success and zero on error.
|
||||
OPENSSL_EXPORT int CBS_get_u64le(CBS *cbs, uint64_t *out);
|
||||
|
||||
// CBS_get_last_u8 sets |*out| to the last uint8_t from |cbs| and shortens
|
||||
// |cbs|. It returns one on success and zero on error.
|
||||
OPENSSL_EXPORT int CBS_get_last_u8(CBS *cbs, uint8_t *out);
|
||||
@@ -460,6 +472,10 @@ OPENSSL_EXPORT int CBB_add_u8(CBB *cbb, uint8_t value);
|
||||
// returns one on success and zero otherwise.
|
||||
OPENSSL_EXPORT int CBB_add_u16(CBB *cbb, uint16_t value);
|
||||
|
||||
// CBB_add_u16le appends a 16-bit, little-endian number from |value| to |cbb|.
|
||||
// It returns one on success and zero otherwise.
|
||||
OPENSSL_EXPORT int CBB_add_u16le(CBB *cbb, uint16_t value);
|
||||
|
||||
// CBB_add_u24 appends a 24-bit, big-endian number from |value| to |cbb|. It
|
||||
// returns one on success and zero otherwise.
|
||||
OPENSSL_EXPORT int CBB_add_u24(CBB *cbb, uint32_t value);
|
||||
@@ -468,10 +484,18 @@ OPENSSL_EXPORT int CBB_add_u24(CBB *cbb, uint32_t value);
|
||||
// returns one on success and zero otherwise.
|
||||
OPENSSL_EXPORT int CBB_add_u32(CBB *cbb, uint32_t value);
|
||||
|
||||
// CBB_add_u32le appends a 32-bit, little-endian number from |value| to |cbb|.
|
||||
// It returns one on success and zero otherwise.
|
||||
OPENSSL_EXPORT int CBB_add_u32le(CBB *cbb, uint32_t value);
|
||||
|
||||
// CBB_add_u64 appends a 64-bit, big-endian number from |value| to |cbb|. It
|
||||
// returns one on success and zero otherwise.
|
||||
OPENSSL_EXPORT int CBB_add_u64(CBB *cbb, uint64_t value);
|
||||
|
||||
// CBB_add_u64le appends a 64-bit, little-endian number from |value| to |cbb|.
|
||||
// It returns one on success and zero otherwise.
|
||||
OPENSSL_EXPORT int CBB_add_u64le(CBB *cbb, uint64_t value);
|
||||
|
||||
// CBB_discard_child discards the current unflushed child of |cbb|. Neither the
|
||||
// child's contents nor the length prefix will be included in the output.
|
||||
OPENSSL_EXPORT void CBB_discard_child(CBB *cbb);
|
||||
|
||||
@@ -60,12 +60,17 @@ OPENSSL_EXPORT int CRYPTO_has_asm(void);
|
||||
OPENSSL_EXPORT int FIPS_mode(void);
|
||||
|
||||
// BORINGSSL_self_test triggers the FIPS KAT-based self tests. It returns one on
|
||||
// success and zero on error. The argument is the integrity hash of the FIPS
|
||||
// module and may be used to check and write flag files to suppress duplicate
|
||||
// self-tests. If it is all zeros, no flag file will be checked nor written and
|
||||
// tests will always be run.
|
||||
// success and zero on error.
|
||||
OPENSSL_EXPORT int BORINGSSL_self_test(void);
|
||||
|
||||
// CRYPTO_pre_sandbox_init initializes the crypto library, pre-acquiring some
|
||||
// unusual resources to aid running in sandboxed environments. It is safe to
|
||||
// call this function multiple times and concurrently from multiple threads.
|
||||
//
|
||||
// For more details on using BoringSSL in a sandboxed environment, see
|
||||
// SANDBOXING.md in the source tree.
|
||||
OPENSSL_EXPORT void CRYPTO_pre_sandbox_init(void);
|
||||
|
||||
|
||||
// Deprecated functions.
|
||||
|
||||
|
||||
@@ -86,6 +86,21 @@ OPENSSL_EXPORT int DH_up_ref(DH *dh);
|
||||
|
||||
// Properties.
|
||||
|
||||
// DH_get0_pub_key returns |dh|'s public key.
|
||||
OPENSSL_EXPORT const BIGNUM *DH_get0_pub_key(const DH *dh);
|
||||
|
||||
// DH_get0_priv_key returns |dh|'s private key, or NULL if |dh| is a public key.
|
||||
OPENSSL_EXPORT const BIGNUM *DH_get0_priv_key(const DH *dh);
|
||||
|
||||
// DH_get0_p returns |dh|'s group modulus.
|
||||
OPENSSL_EXPORT const BIGNUM *DH_get0_p(const DH *dh);
|
||||
|
||||
// DH_get0_q returns the size of |dh|'s subgroup, or NULL if it is unset.
|
||||
OPENSSL_EXPORT const BIGNUM *DH_get0_q(const DH *dh);
|
||||
|
||||
// DH_get0_g returns |dh|'s group generator.
|
||||
OPENSSL_EXPORT const BIGNUM *DH_get0_g(const DH *dh);
|
||||
|
||||
// DH_get0_key sets |*out_pub_key| and |*out_priv_key|, if non-NULL, to |dh|'s
|
||||
// public and private key, respectively. If |dh| is a public key, the private
|
||||
// key will be set to NULL.
|
||||
@@ -108,6 +123,11 @@ OPENSSL_EXPORT void DH_get0_pqg(const DH *dh, const BIGNUM **out_p,
|
||||
// |p| and |g| must either be specified or already configured on |dh|.
|
||||
OPENSSL_EXPORT int DH_set0_pqg(DH *dh, BIGNUM *p, BIGNUM *q, BIGNUM *g);
|
||||
|
||||
// DH_set_length sets the number of bits to use for the secret exponent when
|
||||
// calling |DH_generate_key| on |dh| and returns one. If unset,
|
||||
// |DH_generate_key| will use the bit length of p.
|
||||
OPENSSL_EXPORT int DH_set_length(DH *dh, unsigned priv_length);
|
||||
|
||||
|
||||
// Standard parameters.
|
||||
|
||||
|
||||
@@ -83,6 +83,7 @@ OPENSSL_EXPORT const EVP_MD *EVP_sha224(void);
|
||||
OPENSSL_EXPORT const EVP_MD *EVP_sha256(void);
|
||||
OPENSSL_EXPORT const EVP_MD *EVP_sha384(void);
|
||||
OPENSSL_EXPORT const EVP_MD *EVP_sha512(void);
|
||||
OPENSSL_EXPORT const EVP_MD *EVP_sha512_256(void);
|
||||
|
||||
// EVP_md5_sha1 is a TLS-specific |EVP_MD| which computes the concatenation of
|
||||
// MD5 and SHA-1, as used in TLS 1.1 and below.
|
||||
|
||||
@@ -94,6 +94,22 @@ OPENSSL_EXPORT int DSA_up_ref(DSA *dsa);
|
||||
|
||||
// Properties.
|
||||
|
||||
// DSA_get0_pub_key returns |dsa|'s public key.
|
||||
OPENSSL_EXPORT const BIGNUM *DSA_get0_pub_key(const DSA *dsa);
|
||||
|
||||
// DSA_get0_priv_key returns |dsa|'s private key, or NULL if |dsa| is a public
|
||||
// key.
|
||||
OPENSSL_EXPORT const BIGNUM *DSA_get0_priv_key(const DSA *dsa);
|
||||
|
||||
// DSA_get0_p returns |dsa|'s group modulus.
|
||||
OPENSSL_EXPORT const BIGNUM *DSA_get0_p(const DSA *dsa);
|
||||
|
||||
// DSA_get0_q returns the size of |dsa|'s subgroup.
|
||||
OPENSSL_EXPORT const BIGNUM *DSA_get0_q(const DSA *dsa);
|
||||
|
||||
// DSA_get0_g returns |dsa|'s group generator.
|
||||
OPENSSL_EXPORT const BIGNUM *DSA_get0_g(const DSA *dsa);
|
||||
|
||||
// DSA_get0_key sets |*out_pub_key| and |*out_priv_key|, if non-NULL, to |dsa|'s
|
||||
// public and private key, respectively. If |dsa| is a public key, the private
|
||||
// key will be set to NULL.
|
||||
|
||||
@@ -106,6 +106,12 @@ OPENSSL_EXPORT ECDSA_SIG *ECDSA_SIG_new(void);
|
||||
// ECDSA_SIG_free frees |sig| its member |BIGNUM|s.
|
||||
OPENSSL_EXPORT void ECDSA_SIG_free(ECDSA_SIG *sig);
|
||||
|
||||
// ECDSA_SIG_get0_r returns the r component of |sig|.
|
||||
OPENSSL_EXPORT const BIGNUM *ECDSA_SIG_get0_r(const ECDSA_SIG *sig);
|
||||
|
||||
// ECDSA_SIG_get0_s returns the s component of |sig|.
|
||||
OPENSSL_EXPORT const BIGNUM *ECDSA_SIG_get0_s(const ECDSA_SIG *sig);
|
||||
|
||||
// ECDSA_SIG_get0 sets |*out_r| and |*out_s|, if non-NULL, to the two
|
||||
// components of |sig|.
|
||||
OPENSSL_EXPORT void ECDSA_SIG_get0(const ECDSA_SIG *sig, const BIGNUM **out_r,
|
||||
|
||||
@@ -319,6 +319,7 @@ enum {
|
||||
ERR_LIB_DIGEST,
|
||||
ERR_LIB_CIPHER,
|
||||
ERR_LIB_HKDF,
|
||||
ERR_LIB_TRUST_TOKEN,
|
||||
ERR_LIB_USER,
|
||||
ERR_NUM_LIBS
|
||||
};
|
||||
@@ -362,6 +363,7 @@ enum {
|
||||
#define ERR_R_DIGEST_LIB ERR_LIB_DIGEST
|
||||
#define ERR_R_CIPHER_LIB ERR_LIB_CIPHER
|
||||
#define ERR_R_HKDF_LIB ERR_LIB_HKDF
|
||||
#define ERR_R_TRUST_TOKEN_LIB ERR_LIB_TRUST_TOKEN
|
||||
|
||||
// The following values are global reason codes. They may occur in any library.
|
||||
#define ERR_R_FATAL 64
|
||||
|
||||
@@ -812,6 +812,14 @@ OPENSSL_EXPORT int EVP_PKEY_CTX_set_ec_paramgen_curve_nid(EVP_PKEY_CTX *ctx,
|
||||
// 2.5.8.1.1), but is no longer accepted.
|
||||
#define EVP_PKEY_RSA2 NID_rsa
|
||||
|
||||
// EVP_PKEY_X448 is defined for OpenSSL compatibility, but we do not support
|
||||
// X448 and attempts to create keys will fail.
|
||||
#define EVP_PKEY_X448 NID_X448
|
||||
|
||||
// EVP_PKEY_ED448 is defined for OpenSSL compatibility, but we do not support
|
||||
// Ed448 and attempts to create keys will fail.
|
||||
#define EVP_PKEY_ED448 NID_ED448
|
||||
|
||||
// OpenSSL_add_all_algorithms does nothing.
|
||||
OPENSSL_EXPORT void OpenSSL_add_all_algorithms(void);
|
||||
|
||||
|
||||
@@ -4193,6 +4193,7 @@ extern "C" {
|
||||
|
||||
#define SN_X25519 "X25519"
|
||||
#define NID_X25519 948
|
||||
#define OBJ_X25519 1L, 3L, 101L, 110L
|
||||
|
||||
#define SN_ED25519 "ED25519"
|
||||
#define NID_ED25519 949
|
||||
@@ -4241,6 +4242,15 @@ extern "C" {
|
||||
#define NID_ED448 960
|
||||
#define OBJ_ED448 1L, 3L, 101L, 113L
|
||||
|
||||
#define SN_X448 "X448"
|
||||
#define NID_X448 961
|
||||
#define OBJ_X448 1L, 3L, 101L, 111L
|
||||
|
||||
#define SN_sha512_256 "SHA512-256"
|
||||
#define LN_sha512_256 "sha512-256"
|
||||
#define NID_sha512_256 962
|
||||
#define OBJ_sha512_256 2L, 16L, 840L, 1L, 101L, 3L, 4L, 2L, 6L
|
||||
|
||||
|
||||
#if defined(__cplusplus)
|
||||
} /* extern C */
|
||||
|
||||
@@ -36,26 +36,12 @@ OPENSSL_EXPORT void RAND_cleanup(void);
|
||||
// Obscure functions.
|
||||
|
||||
#if !defined(OPENSSL_WINDOWS)
|
||||
// RAND_set_urandom_fd causes the module to use a copy of |fd| for system
|
||||
// randomness rather opening /dev/urandom internally. The caller retains
|
||||
// ownership of |fd| and is at liberty to close it at any time. This is useful
|
||||
// if, due to a sandbox, /dev/urandom isn't available. If used, it must be
|
||||
// called before the first call to |RAND_bytes|, and it is mutually exclusive
|
||||
// with |RAND_enable_fork_unsafe_buffering|.
|
||||
//
|
||||
// |RAND_set_urandom_fd| does not buffer any entropy, so it is safe to call
|
||||
// |fork| at any time after calling |RAND_set_urandom_fd|.
|
||||
OPENSSL_EXPORT void RAND_set_urandom_fd(int fd);
|
||||
|
||||
// RAND_enable_fork_unsafe_buffering enables efficient buffered reading of
|
||||
// /dev/urandom. It adds an overhead of a few KB of memory per thread. It must
|
||||
// be called before the first call to |RAND_bytes| and it is mutually exclusive
|
||||
// with calls to |RAND_set_urandom_fd|.
|
||||
// be called before the first call to |RAND_bytes|.
|
||||
//
|
||||
// If |fd| is non-negative then a copy of |fd| will be used rather than opening
|
||||
// /dev/urandom internally. Like |RAND_set_urandom_fd|, the caller retains
|
||||
// ownership of |fd|. If |fd| is negative then /dev/urandom will be opened and
|
||||
// any error from open(2) crashes the address space.
|
||||
// |fd| must be -1. We no longer support setting the file descriptor with this
|
||||
// function.
|
||||
//
|
||||
// It has an unusual name because the buffer is unsafe across calls to |fork|.
|
||||
// Hence, this function should never be called by libraries.
|
||||
|
||||
Loaded 100 of 205 files, more files were not shown because too many files have changed in this diff.
Show more
Reference in new issue
Block a user