-
Notifications
You must be signed in to change notification settings - Fork 276
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add feature based on aws-lc-rs cryptographic library instead of ring
- Loading branch information
Kiril Nikolov
committed
Mar 15, 2024
1 parent
193eb8d
commit 6126206
Showing
8 changed files
with
72 additions
and
10 deletions.
There are no files selected for viewing
This file contains 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 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 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 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 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 |
---|---|---|
@@ -1,23 +1,27 @@ | ||
use ring::signature; | ||
#[cfg(feature = "fips")] | ||
use aws_lc_rs as ring; | ||
|
||
#[cfg(not(feature = "fips"))] | ||
use ring; | ||
|
||
use crate::algorithms::Algorithm; | ||
use crate::errors::Result; | ||
use crate::serialization::b64_encode; | ||
|
||
/// Only used internally when signing or validating EdDSA, to map from our enum to the Ring EdDSAParameters structs. | ||
pub(crate) fn alg_to_ec_verification(alg: Algorithm) -> &'static signature::EdDSAParameters { | ||
pub(crate) fn alg_to_ec_verification(alg: Algorithm) -> &'static ring::signature::EdDSAParameters { | ||
// To support additional key subtypes, like Ed448, we would need to match on the JWK's ("crv") | ||
// parameter. | ||
match alg { | ||
Algorithm::EdDSA => &signature::ED25519, | ||
Algorithm::EdDSA => &ring::signature::ED25519, | ||
_ => unreachable!("Tried to get EdDSA alg for a non-EdDSA algorithm"), | ||
} | ||
} | ||
|
||
/// The actual EdDSA signing + encoding | ||
/// The key needs to be in PKCS8 format | ||
pub fn sign(key: &[u8], message: &[u8]) -> Result<String> { | ||
let signing_key = signature::Ed25519KeyPair::from_pkcs8_maybe_unchecked(key)?; | ||
let signing_key = ring::signature::Ed25519KeyPair::from_pkcs8_maybe_unchecked(key)?; | ||
let out = signing_key.sign(message); | ||
Ok(b64_encode(out)) | ||
} |
This file contains 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 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 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