-
Notifications
You must be signed in to change notification settings - Fork 49
Static libs and jar artifact for boringssl #298
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
garyschulte
wants to merge
4
commits into
hyperledger:main
Choose a base branch
from
garyschulte:poc/static-libs-for-boringssl
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
a9e32b3
squash commit of gnark and secp256k1 static libs
garyschulte c0b9e1a
static artifacts for boringssl p256_verify
garyschulte 33e68ce
fix packaging problems with boringssl and gnark
garyschulte 6ed554a
fix boringssl libcrypto build for riscv64
garyschulte File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
109 changes: 109 additions & 0 deletions
109
...sl/src/main/java/org/hyperledger/besu/nativelib/boringssl/BoringSSLPrecompilesCommon.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,109 @@ | ||
| /* | ||
| * Copyright contributors to Besu. | ||
| * | ||
| * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with | ||
| * the License. You may obtain a copy of the License at | ||
| * | ||
| * http://www.apache.org/licenses/LICENSE-2.0 | ||
| * | ||
| * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on | ||
| * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the | ||
| * specific language governing permissions and limitations under the License. | ||
| * | ||
| * SPDX-License-Identifier: Apache-2.0 | ||
| * | ||
| */ | ||
| package org.hyperledger.besu.nativelib.boringssl; | ||
|
|
||
| import java.math.BigInteger; | ||
| import java.nio.charset.StandardCharsets; | ||
| import java.util.Optional; | ||
|
|
||
| /** | ||
| * Common logic shared between JNA and GraalVM implementations of BoringSSL precompiles | ||
| */ | ||
| public class BoringSSLPrecompilesCommon { | ||
|
|
||
| public static final int STATUS_SUCCESS = 0; | ||
| public static final int STATUS_FAIL = 1; | ||
| public static final int STATUS_ERROR = 2; | ||
|
|
||
| public static final int ERROR_BUF_SIZE = 256; | ||
|
|
||
| // secp256r1 curve order | ||
| public static final BigInteger SECP256R1_ORDER = | ||
| new BigInteger("FFFFFFFF00000000FFFFFFFFFFFFFFFFBCE6FAADA7179E84F3B9CAC2FC632551", 16); | ||
|
|
||
| // Wrapper result classes | ||
| public static class P256VerifyResult { | ||
| public final int status; | ||
| public final String error; | ||
|
|
||
| public P256VerifyResult(final int status, final String message) { | ||
| this.status = status; | ||
| this.error = message; | ||
| } | ||
| } | ||
|
|
||
| public record ECRecoverResult( | ||
| int status, | ||
| Optional<byte[]> publicKey, | ||
| Optional<String> error) {} | ||
|
|
||
| /** | ||
| * Validates ecrecover input parameters | ||
| * @return Optional containing error result if validation fails, empty if valid | ||
| */ | ||
| public static Optional<ECRecoverResult> validateEcrecoverInput( | ||
| final byte[] hash, final byte[] sig, final int recovery_id) { | ||
|
|
||
| // Validate signature length | ||
| if (sig == null || sig.length != 64) { | ||
| return Optional.of(new ECRecoverResult(STATUS_ERROR, Optional.empty(), | ||
| Optional.of("invalid signature length"))); | ||
| } | ||
|
|
||
| if (hash == null || hash.length != 32) { | ||
| return Optional.of(new ECRecoverResult(STATUS_ERROR, Optional.empty(), | ||
| Optional.of("invalid hash length"))); | ||
| } | ||
|
|
||
| // Extract r and s values | ||
| byte[] rBytes = new byte[32]; | ||
| byte[] sBytes = new byte[32]; | ||
| System.arraycopy(sig, 0, rBytes, 0, 32); | ||
| System.arraycopy(sig, 32, sBytes, 0, 32); | ||
|
|
||
| BigInteger r = new BigInteger(1, rBytes); | ||
| BigInteger s = new BigInteger(1, sBytes); | ||
|
|
||
| // Validate r and s are in range [1, n-1] before calling native method | ||
| if (r.equals(BigInteger.ZERO) || r.compareTo(SECP256R1_ORDER) >= 0) { | ||
| return Optional.of(new ECRecoverResult(STATUS_ERROR, Optional.empty(), | ||
| Optional.of("invalid signature r value"))); | ||
| } | ||
|
|
||
| if (s.equals(BigInteger.ZERO) || s.compareTo(SECP256R1_ORDER) >= 0) { | ||
| return Optional.of(new ECRecoverResult(STATUS_ERROR, Optional.empty(), | ||
| Optional.of("invalid signature s value"))); | ||
| } | ||
|
|
||
| if (recovery_id < 0 || recovery_id > 1) { | ||
| return Optional.of(new ECRecoverResult(STATUS_ERROR, Optional.empty(), | ||
| Optional.of("invalid recovery id " + recovery_id + " is not 0 or 1"))); | ||
| } | ||
|
|
||
| return Optional.empty(); | ||
| } | ||
|
|
||
| /** | ||
| * Converts a null-terminated byte buffer to a Java String | ||
| */ | ||
| public static String bytesToNullTermString(final byte[] buffer) { | ||
| int nullTerminator = 0; | ||
| while (nullTerminator < buffer.length && buffer[nullTerminator] != 0) { | ||
| nullTerminator++; | ||
| } | ||
| return new String(buffer, 0, nullTerminator, StandardCharsets.UTF_8); | ||
| } | ||
| } |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Check notice
Code scanning / CodeQL
Class has same name as super class Note