-
Notifications
You must be signed in to change notification settings - Fork 16
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #659 from cryspen/keks/hacl-rs
Back implementations of SHA2, HMAC-SHA1, HMAC-SHA2 and HKDF-SHA2 by hacl-rs
- Loading branch information
Showing
72 changed files
with
18,414 additions
and
654 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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 |
---|---|---|
@@ -0,0 +1,23 @@ | ||
[package] | ||
name = "libcrux-curve25519" | ||
description = "Formally verified curve25519 ECDH library" | ||
|
||
version.workspace = true | ||
authors.workspace = true | ||
license.workspace = true | ||
homepage.workspace = true | ||
edition.workspace = true | ||
repository.workspace = true | ||
readme.workspace = true | ||
|
||
[features] | ||
default = ["portable_hacl"] | ||
portable_hacl = ["hacl"] | ||
hacl = ["dep:libcrux-sha2", "dep:libcrux-hacl-rs", "dep:libcrux-macros"] | ||
|
||
[dependencies] | ||
libcrux-hacl-rs = { version = "=0.0.2-beta.2", path = "../hacl-rs/", optional = true } | ||
libcrux-sha2 = { version = "=0.0.2-beta.2", path = "../sha2", optional = true, features = [ | ||
"hacl", | ||
] } | ||
libcrux-macros = { version = "=0.0.2-beta.2", path = "../macros", optional = true } |
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 |
---|---|---|
@@ -0,0 +1,21 @@ | ||
use super::*; | ||
|
||
/// Implementation of Curve25519 backed by Hacl. | ||
pub struct HaclCurve25519; | ||
|
||
impl Curve25519 for HaclCurve25519 { | ||
// The hacl::ecdh function requires all parameters to be 32 byte long, which we enforce using | ||
// types. | ||
fn secret_to_public(pk: &mut [u8; PK_LEN], sk: &[u8; SK_LEN]) { | ||
crate::hacl::secret_to_public(pk, sk) | ||
} | ||
|
||
// The hacl::ecdh function requires all parameters to be 32 byte long, which we enforce using | ||
// types. | ||
fn ecdh(out: &mut [u8; SHK_LEN], pk: &[u8; PK_LEN], sk: &[u8; SK_LEN]) -> Result<(), Error> { | ||
match crate::hacl::ecdh(out, sk, pk) { | ||
true => Ok(()), | ||
false => Err(Error), | ||
} | ||
} | ||
} |
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 |
---|---|---|
@@ -0,0 +1,41 @@ | ||
#[cfg(feature = "hacl")] | ||
pub use libcrux_hacl_rs::curve25519_51 as hacl; | ||
|
||
#[cfg(feature = "hacl")] | ||
mod impl_hacl; | ||
|
||
#[cfg(feature = "portable_hacl")] | ||
pub use impl_hacl::HaclCurve25519 as Impl; | ||
|
||
/// The length of Curve25519 secret keys. | ||
pub const SK_LEN: usize = 32; | ||
|
||
/// The length of Curve25519 public keys. | ||
pub const PK_LEN: usize = 32; | ||
|
||
/// The length of Curve25519 shared keys. | ||
pub const SHK_LEN: usize = 32; | ||
|
||
/// Indicates that an error occurred | ||
pub struct Error; | ||
|
||
/// This trait is implemented by the backing implementations. | ||
/// Only used for implementation agility. | ||
trait Curve25519 { | ||
/// Computes a public key from a secret key. | ||
fn secret_to_public(pk: &mut [u8; PK_LEN], sk: &[u8; SK_LEN]); | ||
|
||
/// Computes the scalar multiplication between the provided public and secret keys. Returns an | ||
/// error if the result is 0. | ||
fn ecdh(out: &mut [u8; SHK_LEN], pk: &[u8; PK_LEN], sk: &[u8; SK_LEN]) -> Result<(), Error>; | ||
} | ||
|
||
/// Computes and writes the public key from the secret key `sk` and writes it into `pk`. | ||
pub fn secret_to_public(pk: &mut [u8; PK_LEN], sk: &[u8; SK_LEN]) { | ||
Impl::secret_to_public(pk, sk) | ||
} | ||
|
||
/// Performs the ECDH computation and writes the key shared betweem `pk` and `sk` into `shk`. | ||
pub fn ecdh(out: &mut [u8; SHK_LEN], pk: &[u8; PK_LEN], sk: &[u8; SK_LEN]) -> Result<(), Error> { | ||
Impl::ecdh(out, pk, sk) | ||
} |
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 |
---|---|---|
@@ -0,0 +1,23 @@ | ||
[package] | ||
name = "libcrux-ed25519" | ||
description = "Formally verified ed25519 signature library" | ||
|
||
version.workspace = true | ||
authors.workspace = true | ||
license.workspace = true | ||
homepage.workspace = true | ||
edition.workspace = true | ||
repository.workspace = true | ||
readme.workspace = true | ||
|
||
[features] | ||
default = ["portable_hacl"] | ||
portable_hacl = ["hacl"] | ||
hacl = ["dep:libcrux-sha2", "dep:libcrux-hacl-rs", "dep:libcrux-macros"] | ||
|
||
[dependencies] | ||
libcrux-hacl-rs = { version = "=0.0.2-beta.2", path = "../hacl-rs/", optional = true } | ||
libcrux-sha2 = { version = "=0.0.2-beta.2", path = "../sha2", optional = true, features = [ | ||
"hacl", | ||
] } | ||
libcrux-macros = { version = "=0.0.2-beta.2", path = "../macros", optional = true } |
Oops, something went wrong.