Skip to content

Commit

Permalink
Merge pull request #2 from OtaK/xyber768d00
Browse files Browse the repository at this point in the history
fix: Serde impls for kyber
  • Loading branch information
bwesterb authored Jul 7, 2023
2 parents 71efb5c + 5408f64 commit e5ffd22
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 3 deletions.
6 changes: 4 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ p384 = ["dep:p384"]
p256 = ["dep:p256"]
xyber768d00 = ["dep:pqc_kyber", "x25519"]
# Include serde Serialize/Deserialize impls for all relevant types
serde_impls = ["serde", "generic-array/serde"]
serde_impls = ["dep:serde", "dep:serde-big-array", "generic-array/serde"]
# Include allocating methods like open() and seal()
alloc = []
# Includes an implementation of `std::error::Error` for `HpkeError`. Also does what `alloc` does.
Expand All @@ -42,6 +42,7 @@ p256 = { version = "0.13", default-features = false, features = ["arithmetic", "
p384 = { version = "0.13", default-features = false, features = ["arithmetic", "ecdh"], optional = true}
sha2 = { version = "0.10", default-features = false }
serde = { version = "1.0", default-features = false, optional = true }
serde-big-array = { version = "0.5", optional = true }
subtle = { version = "2.4", default-features = false }
zeroize = { version = "1", default-features = false, features = ["zeroize_derive"] }

Expand All @@ -60,7 +61,8 @@ optional = true
# https://github.com/Argyle-Software/kyber/issues/73
# https://github.com/Argyle-Software/kyber/issues/75
# https://github.com/Argyle-Software/kyber/issues/77
git="https://github.com/bwesterb/argyle-kyber"
git = "https://github.com/bwesterb/argyle-kyber"
package = "safe_pqc_kyber"
default-features = false
features = ["kyber768", "std"] # TODO get rid of std dep
optional = true
Expand Down
2 changes: 1 addition & 1 deletion src/kem.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
//! Traits and structs for key encapsulation mechanisms
#![allow(ambiguous_glob_reexports)]

use crate::{Deserializable, HpkeError, Serializable};

Expand All @@ -13,7 +14,6 @@ pub use dhkem::*;

#[cfg(feature = "xyber768d00")]
pub mod xyber768d00;

#[cfg(feature = "xyber768d00")]
pub use xyber768d00::*;

Expand Down
6 changes: 6 additions & 0 deletions src/kem/xyber768d00.rs
Original file line number Diff line number Diff line change
Expand Up @@ -92,20 +92,26 @@ impl Deserializable for PrivateKey {
}

#[derive(Debug, PartialEq, Eq, Clone)]
#[cfg_attr(feature = "serde_impls", derive(serde::Serialize, serde::Deserialize))]
pub struct PublicKey {
x: <X25519HkdfSha256 as KemTrait>::PublicKey,
#[cfg_attr(feature = "serde_impls", serde(with = "serde_big_array::BigArray"))]
k: pqc_kyber::PublicKey,
}

#[derive(Clone)]
#[cfg_attr(feature = "serde_impls", derive(serde::Serialize, serde::Deserialize))]
pub struct PrivateKey {
x: <X25519HkdfSha256 as KemTrait>::PrivateKey,
#[cfg_attr(feature = "serde_impls", serde(with = "serde_big_array::BigArray"))]
k: pqc_kyber::SecretKey,
}

#[derive(Clone)]
#[cfg_attr(feature = "serde_impls", derive(serde::Serialize, serde::Deserialize))]
pub struct EncappedKey {
x: <X25519HkdfSha256 as KemTrait>::EncappedKey,
#[cfg_attr(feature = "serde_impls", serde(with = "serde_big_array::BigArray"))]
k: [u8; 1088],
}

Expand Down

0 comments on commit e5ffd22

Please sign in to comment.