Skip to content

Commit

Permalink
move hpke to provider impl
Browse files Browse the repository at this point in the history
  • Loading branch information
yngrtc committed Aug 21, 2023
1 parent 2148cd7 commit fe2fc3f
Show file tree
Hide file tree
Showing 8 changed files with 75 additions and 9 deletions.
1 change: 0 additions & 1 deletion src/crypto/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ use crate::error::*;

use bytes::{Buf, BufMut, Bytes, BytesMut};

pub mod hpke;
pub mod provider;

pub(crate) type HpkePublicKey = Bytes;
Expand Down
8 changes: 4 additions & 4 deletions src/crypto/provider/ring.rs
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
mod hash;

mod hpke;
mod signature;

use self::hash::HashScheme;
use self::signature::SignatureScheme;
use super::*;
use crate::crypto::hpke::{
use self::hpke::{
algs::{Aead, Kdf, Kem},
HpkeSuite,
};
use self::signature::SignatureScheme;
use super::*;

pub struct RingCryptoProvider;

Expand Down
File renamed without changes.
File renamed without changes.
2 changes: 1 addition & 1 deletion src/crypto/provider/ring/signature.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use bytes::Bytes;
use ring::signature::{Ed25519KeyPair, VerificationAlgorithm, ED25519};
use signature::{Signer, Verifier};
use signature::{Signer, Verifier}; //TODO(yngrtc): use ring library only in RingCryptoProvider

use crate::error::*;

Expand Down
7 changes: 4 additions & 3 deletions src/crypto/provider/rust.rs
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
mod hash;
mod hpke;
mod signature;

use self::hash::HashScheme;
use self::signature::SignatureScheme;
use super::*;
use crate::crypto::hpke::{
use self::hpke::{
algs::{Aead, Kdf, Kem},
HpkeSuite,
};
use self::signature::SignatureScheme;
use super::*;

pub struct RustCryptoProvider;

Expand Down
19 changes: 19 additions & 0 deletions src/crypto/provider/rust/hpke.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
pub mod algs;

use algs::*;

// Suite is an HPKE cipher suite consisting of a KEM, KDF, and AEAD algorithm.
#[derive(Default, Debug, Clone, Eq, PartialEq)]
pub struct HpkeSuite {
kem: Kem,
kdf: Kdf,
aead: Aead,
}

impl HpkeSuite {
pub fn new(kem: Kem, kdf: Kdf, aead: Aead) -> Self {
HpkeSuite { kem, kdf, aead }
}
}

impl crate::crypto::provider::Hpke for HpkeSuite {}
47 changes: 47 additions & 0 deletions src/crypto/provider/rust/hpke/algs.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
#[allow(non_camel_case_types)]
#[derive(Default, Debug, Copy, Clone, Eq, PartialEq)]
#[repr(u16)]
pub enum Kem {
#[default]
// KEM_P256_HKDF_SHA256 is a KEM using P256 curve and HKDF with SHA-256.
KEM_P256_HKDF_SHA256 = 0x10,
// KEM_P384_HKDF_SHA384 is a KEM using P384 curve and HKDF with SHA-384.
KEM_P384_HKDF_SHA384 = 0x11,
// KEM_P521_HKDF_SHA512 is a KEM using P521 curve and HKDF with SHA-512.
KEM_P521_HKDF_SHA512 = 0x12,
// KEM_X25519_HKDF_SHA256 is a KEM using X25519 Diffie-Hellman function
// and HKDF with SHA-256.
KEM_X25519_HKDF_SHA256 = 0x20,
// KEM_X448_HKDF_SHA512 is a KEM using X448 Diffie-Hellman function and
// HKDF with SHA-512.
KEM_X448_HKDF_SHA512 = 0x21,
// KEM_X25519_KYBER768_DRAFT00 is a hybrid KEM built on DHKEM(X25519, HKDF-SHA256)
// and Kyber768Draft00
KEM_X25519_KYBER768_DRAFT00 = 0x30,
}

#[allow(non_camel_case_types)]
#[derive(Default, Debug, Copy, Clone, Eq, PartialEq)]
#[repr(u16)]
pub enum Kdf {
#[default]
// KDF_HKDF_SHA256 is a KDF using HKDF with SHA-256.
KDF_HKDF_SHA256 = 0x01,
// KDF_HKDF_SHA384 is a KDF using HKDF with SHA-384.
KDF_HKDF_SHA384 = 0x02,
// KDF_HKDF_SHA512 is a KDF using HKDF with SHA-512.
KDF_HKDF_SHA512 = 0x03,
}

#[allow(non_camel_case_types)]
#[derive(Default, Debug, Copy, Clone, Eq, PartialEq)]
#[repr(u16)]
pub enum Aead {
#[default]
// AEAD_AES128GCM is AES-128 block cipher in Galois Counter Mode (GCM).
AEAD_AES128GCM = 0x01,
// AEAD_AES256GCM is AES-256 block cipher in Galois Counter Mode (GCM).
AEAD_AES256GCM = 0x02,
// AEAD_ChaCha20Poly1305 is ChaCha20 stream cipher and Poly1305 MAC.
AEAD_ChaCha20Poly1305 = 0x03,
}

0 comments on commit fe2fc3f

Please sign in to comment.