-
Notifications
You must be signed in to change notification settings - Fork 17
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
move hacl-rs algorithms to individual crates and make composite crate…
…s use these
- Loading branch information
Showing
39 changed files
with
7,796 additions
and
268 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,21 @@ | ||
[package] | ||
name = "libcrux-curve25519" | ||
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:krml"] | ||
|
||
[dependencies] | ||
libcrux-hacl-rs = { path = "../libcrux-hacl-rs/", optional = true } | ||
libcrux-sha2 = { path = "../libcrux-sha2", optional = true, features = [ | ||
"hacl", | ||
] } | ||
krml = { package = "libcrux-hacl-rs-krml", path = "../libcrux-hacl-rs-krml", 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,18 @@ | ||
use super::*; | ||
|
||
/// Implementation of Curve25519 backed by Hacl. | ||
pub struct HaclCurve25519; | ||
|
||
impl Curve25519 for HaclCurve25519 { | ||
fn secret_to_public(pk: &mut [u8; PK_LEN], sk: &[u8; SK_LEN]) { | ||
crate::hacl::secret_to_public(pk, sk) | ||
} | ||
|
||
fn ecdh(out: &mut [u8; SHK_LEN], pk: &[u8; PK_LEN], sk: &[u8; SK_LEN]) -> Result<(), Error> { | ||
if crate::hacl::ecdh(out, sk, pk) { | ||
Ok(()) | ||
} else { | ||
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,37 @@ | ||
#[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 { | ||
fn secret_to_public(pk: &mut [u8; PK_LEN], sk: &[u8; SK_LEN]); | ||
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
Oops, something went wrong.