Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Serde impls for kyber #2

Merged
merged 1 commit into from
Jul 7, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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