Skip to content

Commit

Permalink
remove some warnings and update ci
Browse files Browse the repository at this point in the history
  • Loading branch information
franziskuskiefer committed Jan 16, 2024
1 parent 23f663d commit e8fc3cd
Show file tree
Hide file tree
Showing 9 changed files with 57 additions and 70 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/hax.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,13 @@ name: hax

on:
push:
branches: ["dev"]
branches: ["dev", "main"]
paths:
- 'specs/kyber/src/**'
- 'src/kem/kyber/**'

pull_request:
branches: ["dev"]
branches: ["dev", "main"]
paths:
- 'specs/kyber/src/**'
- 'src/kem/kyber/**'
Expand Down
22 changes: 11 additions & 11 deletions src/ecdh.rs
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ pub(crate) mod x25519 {

impl From<&[u8; 32]> for PublicKey {
fn from(value: &[u8; 32]) -> Self {
Self(value.clone())
Self(*value)
}
}

Expand All @@ -81,7 +81,7 @@ pub(crate) mod x25519 {

impl From<&[u8; 32]> for PrivateKey {
fn from(value: &[u8; 32]) -> Self {
Self(value.clone())
Self(*value)
}
}

Expand Down Expand Up @@ -177,7 +177,7 @@ pub(crate) mod x25519 {

curve25519::ecdh(s, p)
.map_err(|e| Error::Custom(format!("HACL Error {:?}", e)))
.map(|p| PublicKey(p))
.map(PublicKey)
}

// XXX: libjade's secret to public is broken on Windows (overflows the stack).
Expand Down Expand Up @@ -208,9 +208,9 @@ pub(crate) mod x25519 {
}

// We clamp the key already to make sure it can't be misused.
out[0] = out[0] & 248u8;
out[31] = out[31] & 127u8;
out[31] = out[31] | 64u8;
out[0] &= 248u8;
out[31] &= 127u8;
out[31] |= 64u8;

return Ok(PrivateKey(out));
}
Expand Down Expand Up @@ -242,7 +242,7 @@ pub(crate) mod p256 {

impl From<&[u8; 64]> for PublicKey {
fn from(value: &[u8; 64]) -> Self {
Self(value.clone())
Self(*value)
}
}

Expand All @@ -256,7 +256,7 @@ pub(crate) mod p256 {

impl From<&[u8; 32]> for PrivateKey {
fn from(value: &[u8; 32]) -> Self {
Self(value.clone())
Self(*value)
}
}

Expand Down Expand Up @@ -296,14 +296,14 @@ pub(crate) mod p256 {
// We assume that the private key has been validated.
p256::ecdh(s, p)
.map_err(|e| Error::Custom(format!("HACL Error {:?}", e)))
.map(|p| PublicKey(p))
.map(PublicKey)
}

pub(super) fn secret_to_public(s: &PrivateKey) -> Result<PublicKey, Error> {
p256::validate_scalar(s).map_err(|e| Error::Custom(format!("HACL Error {:?}", e)))?;
p256::secret_to_public(s)
.map_err(|e| Error::Custom(format!("HACL Error {:?}", e)))
.map(|p| PublicKey(p))
.map(PublicKey)
}

pub fn validate_scalar(s: &PrivateKey) -> Result<(), Error> {
Expand Down Expand Up @@ -397,7 +397,7 @@ pub(crate) fn p256_derive(
p256::validate_point(point)?;
p256::validate_scalar(scalar)?;

p256::derive(&point, &scalar)
p256::derive(point, scalar)
}

/// Derive the public key for the provided secret key `scalar`.
Expand Down
30 changes: 15 additions & 15 deletions src/hacl.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,32 +32,32 @@ pub enum Error {
Hkdf(hkdf::Error),
}

impl Into<Error> for chacha20_poly1305::Error {
fn into(self) -> Error {
Error::ChaCha20Poly1305(self)
impl From<chacha20_poly1305::Error> for Error {
fn from(val: chacha20_poly1305::Error) -> Self {
Error::ChaCha20Poly1305(val)
}
}

impl Into<Error> for curve25519::Error {
fn into(self) -> Error {
Error::Curve25519(self)
impl From<curve25519::Error> for Error {
fn from(val: curve25519::Error) -> Self {
Error::Curve25519(val)
}
}

impl Into<Error> for p256::Error {
fn into(self) -> Error {
Error::P256(self)
impl From<p256::Error> for Error {
fn from(val: p256::Error) -> Self {
Error::P256(val)
}
}

impl Into<Error> for hkdf::Error {
fn into(self) -> Error {
Error::Hkdf(self)
impl From<hkdf::Error> for Error {
fn from(val: hkdf::Error) -> Self {
Error::Hkdf(val)
}
}

impl Into<Error> for ed25519::Error {
fn into(self) -> Error {
Error::Ed25519(self)
impl From<ed25519::Error> for Error {
fn from(val: ed25519::Error) -> Self {
Error::Ed25519(val)
}
}
3 changes: 0 additions & 3 deletions src/hacl/chacha20_poly1305.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@ pub fn encrypt(key: &Chacha20Key, msg_ctxt: &mut [u8], iv: Iv, aad: &[u8]) -> Ta
/// Portable 32-bit in-place decrypt.
///
/// There are no special hardware requirements to call this function.
#[must_use]
pub fn decrypt(
key: &Chacha20Key,
ctxt_msg: &mut [u8],
Expand Down Expand Up @@ -103,7 +102,6 @@ pub mod simd128 {
/// * x86_64: AVX, SSE2, SSE3, SSE4.1
/// * ARM: Arm64, NEON
/// * s390x: z14
#[must_use]
#[inline(always)]
pub fn decrypt(
key: &Chacha20Key,
Expand Down Expand Up @@ -165,7 +163,6 @@ pub mod simd256 {
///
/// This function requires
/// * x86_64: AVX, AVX2
#[must_use]
#[inline(always)]
pub fn decrypt(
key: &Chacha20Key,
Expand Down
5 changes: 0 additions & 5 deletions src/hacl/curve25519.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,6 @@ pub enum Error {
/// Compute the ECDH with the `private_key` and `public_key`.
///
/// Returns the 32 bytes shared key.

#[must_use]
#[inline(always)]
pub fn ecdh(
private_key: impl AsRef<[u8; 32]>,
Expand All @@ -34,7 +32,6 @@ pub fn ecdh(
/// with the base point).
///
/// Returns the 32 bytes shared key.

#[must_use]
#[inline(always)]
pub fn secret_to_public(private_key: impl AsRef<[u8; 32]>) -> [u8; 32] {
Expand All @@ -53,8 +50,6 @@ pub mod vale {
/// Compute the ECDH with the `private_key` and `public_key`.
///
/// Returns the 32 bytes shared key.

#[must_use]
#[inline(always)]
pub fn ecdh(
private_key: impl AsRef<[u8; 32]>,
Expand Down
7 changes: 0 additions & 7 deletions src/hacl/p256.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ pub enum Error {

/// Parse an uncompressed P256 point and return the 64 byte array with the
/// concatenation of X||Y
#[must_use]
pub fn uncompressed_to_coordinates(point: &[u8]) -> Result<[u8; 64], Error> {
let mut concat_point = [0u8; 64];
if point.len() >= 65 {
Expand All @@ -37,7 +36,6 @@ pub fn uncompressed_to_coordinates(point: &[u8]) -> Result<[u8; 64], Error> {

/// Parse an compressed P256 point and return the 64 byte array with the
/// concatenation of `X` and `Y`.
#[must_use]
pub fn compressed_to_coordinates(point: &[u8]) -> Result<[u8; 64], Error> {
let mut concat_point = [0u8; 64];
if point.len() >= 33 {
Expand All @@ -57,7 +55,6 @@ pub fn compressed_to_coordinates(point: &[u8]) -> Result<[u8; 64], Error> {
/// concatenation of `X` and `Y`.
///
/// Returns [`Error::InvalidPoint`] if the `point` is not valid.
#[must_use]
pub fn validate_point(point: impl AsRef<[u8; 64]>) -> Result<(), Error> {
if unsafe { Hacl_P256_validate_public_key(point.as_ref().as_ptr() as _) } {
Ok(())
Expand Down Expand Up @@ -108,7 +105,6 @@ pub fn validate_scalar_slice(scalar: &[u8]) -> Result<PrivateKey, Error> {
/// Compute the ECDH with the `private_key` and `public_key`.
///
/// Returns the 64 bytes shared key.
#[must_use]
pub fn ecdh(
private_key: impl AsRef<[u8; 32]>,
public_key: impl AsRef<[u8; 64]>,
Expand All @@ -131,7 +127,6 @@ pub fn ecdh(
/// Compute the public key for the provided `private_key`.
///
/// Returns the 64 bytes public key.
#[must_use]
pub fn secret_to_public(s: impl AsRef<[u8; 32]>) -> Result<[u8; 64], Error> {
validate_scalar(&s)?;

Expand All @@ -157,7 +152,6 @@ pub mod ecdsa {
/// Sign
///
/// * private key validation must be performed before calling this function
#[must_use]
pub fn $sign(
payload: &[u8],
private_key: &[u8; 32],
Expand All @@ -182,7 +176,6 @@ pub mod ecdsa {
/// Verification
///
/// * public key validation must be performed before calling this function
#[must_use]
pub fn $verify(
payload: &[u8],
public_key: &[u8; 64],
Expand Down
Loading

0 comments on commit e8fc3cd

Please sign in to comment.