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

cms: ECC KeyAgreementRecipientInfo initial support #1579

Draft
wants to merge 24 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
d1c0b38
cms: ecc-kari support - add kari and utils modules
nemynm Oct 11, 2024
6d4ddfa
cms: ecc-kari support - add EccCmsSharedInfo
nemynm Oct 11, 2024
12e5cfa
cms: ecc-kari support - add KeyAgreementAlgorithm
nemynm Oct 12, 2024
0957437
cms: ecc-kari support - add RFC details for KeyAgreementAlgorithm
nemynm Oct 12, 2024
2d892d9
cms: ecc-kari support - add KeyWrapAlgorithm
nemynm Oct 12, 2024
225f93a
cms: ecc-kari support - add elliptic-curve dependency
nemynm Oct 12, 2024
2cc7157
cms: ecc-kari support - add aes-kw dependency
nemynm Oct 13, 2024
6ca4f53
cms: ecc-kari support - move KeyWrapAlgorithm to kw module
nemynm Oct 13, 2024
177acc5
cms: ecc-kari support - add EcKeyEncryptionInfo
nemynm Oct 13, 2024
3d0b733
cms: ecc-kari support - add kdf dependency
nemynm Oct 14, 2024
c1fd8dd
cms: ecc-kari support - move KeyAgreeRecipientInfoBuilder to sub-module
nemynm Oct 19, 2024
a75f49d
cms: ecc-kari support - add elliptic-curve/pkcs8
nemynm Oct 19, 2024
03bd180
cms: ecc-kari support - add KDF utilities
nemynm Oct 20, 2024
bbeb02a
cms: ecc-kari support - add key wrap utilities
nemynm Oct 20, 2024
977f8ae
cms: ecc-kari support - add p256-priv.der corresponding public key
nemynm Oct 20, 2024
7eda981
cms: ecc-kari support - add comments and exports
nemynm Oct 20, 2024
84fcd6b
cms: ecc-kari support - add kari test module
nemynm Oct 20, 2024
d95f368
cms: ecc-kari support - add test for kari builder
nemynm Oct 20, 2024
32abf3b
cms: ecc-kari support
nemynm Oct 20, 2024
011f5b7
cms: ecc-kari support - remove default builder
nemynm Oct 20, 2024
b91079c
cms: ecc-kari support - add From<ContentEncryptionAlgorithm> for KeyW…
nemynm Oct 20, 2024
ef64bb3
cms: ecc-kari support - add From<KeyWrapAlgorithm> for WrappingKey test
nemynm Oct 20, 2024
8dc49c1
cms: ecc-kari support - bring EnvelopedData in scope for doc
nemynm Oct 20, 2024
aca8958
cms: use aes-kw pre-release
baloo Oct 21, 2024
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
30 changes: 30 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 8 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -58,3 +58,11 @@ tls_codec_derive = { path = "./tls_codec/derive" }
x509-tsp = { path = "./x509-tsp" }
x509-cert = { path = "./x509-cert" }
x509-ocsp = { path = "./x509-ocsp" }

# https://github.com/RustCrypto/key-wraps/pull/34
# https://github.com/RustCrypto/key-wraps/pull/35
aes-kw = { git = "https://github.com/RustCrypto/key-wraps.git" }

# https://github.com/RustCrypto/KDFs/pull/102
ansi-x963-kdf = { git = "https://github.com/RustCrypto/KDFs.git" }

7 changes: 7 additions & 0 deletions cms/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,12 @@ x509-cert = { version = "=0.3.0-pre.0", default-features = false }

# optional dependencies
aes = { version = "=0.9.0-pre.2", optional = true }
aes-kw = { version ="=0.3.0-pre", optional = true }
ansi-x963-kdf = { version = "0.1.0", optional = true }
async-signature = { version = "=0.6.0-pre.4", features = ["digest", "rand_core"], optional = true }
cbc = { version = "=0.2.0-pre.2", optional = true }
cipher = { version = "=0.5.0-pre.7", features = ["alloc", "block-padding", "rand_core"], optional = true }
elliptic-curve = { version = "=0.14.0-rc.1", optional = true }
rsa = { version = "=0.10.0-pre.3", optional = true }
sha1 = { version = "=0.11.0-pre.4", optional = true }
sha2 = { version = "=0.11.0-pre.4", optional = true }
Expand All @@ -50,9 +53,13 @@ x509-cert = { version = "=0.3.0-pre.0", features = ["pem"] }
std = ["der/std", "spki/std"]
builder = [
"dep:aes",
"dep:aes-kw",
"dep:ansi-x963-kdf",
"dep:async-signature",
"dep:cbc",
"dep:cipher",
"elliptic-curve/ecdh",
"elliptic-curve/pkcs8",
"dep:rsa",
"dep:sha1",
"dep:sha2",
Expand Down
66 changes: 8 additions & 58 deletions cms/src/builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,14 @@ use x509_cert::attr::{Attribute, AttributeValue, Attributes};
use x509_cert::builder::{self, AsyncBuilder, Builder};
use zeroize::Zeroize;

// Modules
mod kari;
mod utils;

// Exports
pub use kari::{EcKeyEncryptionInfo, KeyAgreeRecipientInfoBuilder, KeyAgreementAlgorithm};
pub use utils::kw::KeyWrapAlgorithm;

/// Error type
#[derive(Debug)]
#[non_exhaustive]
Expand Down Expand Up @@ -695,64 +703,6 @@ where
}
}

/// Builds a `KeyAgreeRecipientInfo` according to RFC 5652 § 6.
/// This type uses key agreement: the recipient's public key and the sender's
/// private key are used to generate a pairwise symmetric key, then
/// the content-encryption key is encrypted in the pairwise symmetric key.
pub struct KeyAgreeRecipientInfoBuilder<R> {
/// A CHOICE with three alternatives specifying the sender's key agreement public key.
pub originator: OriginatorIdentifierOrKey,
/// Optional information which helps generating different keys every time.
pub ukm: Option<UserKeyingMaterial>,
/// Encryption algorithm to be used for key encryption
pub key_enc_alg: AlgorithmIdentifierOwned,
_rng: PhantomData<R>,
}

impl<R> KeyAgreeRecipientInfoBuilder<R> {
/// Creates a `KeyAgreeRecipientInfoBuilder`
pub fn new(
originator: OriginatorIdentifierOrKey,
ukm: Option<UserKeyingMaterial>,
key_enc_alg: AlgorithmIdentifierOwned,
) -> Result<Self> {
Ok(KeyAgreeRecipientInfoBuilder {
originator,
ukm,
key_enc_alg,
_rng: PhantomData,
})
}
}

impl<R> RecipientInfoBuilder for KeyAgreeRecipientInfoBuilder<R>
where
R: CryptoRngCore,
{
type Rng = R;

/// Returns the RecipientInfoType
fn recipient_info_type(&self) -> RecipientInfoType {
RecipientInfoType::Kari
}

/// Returns the `CMSVersion` for this `RecipientInfo`
fn recipient_info_version(&self) -> CmsVersion {
CmsVersion::V3
}

/// Build a `KeyAgreeRecipientInfoBuilder`. See RFC 5652 § 6.2.1
fn build_with_rng(
&mut self,
_content_encryption_key: &[u8],
_rng: &mut Self::Rng,
) -> Result<RecipientInfo> {
Err(Error::Builder(String::from(
"Building KeyAgreeRecipientInfo is not implemented, yet.",
)))
}
}

/// Builds a `KekRecipientInfo` according to RFC 5652 § 6.
/// Uses symmetric key-encryption keys: the content-encryption key is
/// encrypted in a previously distributed symmetric key-encryption key.
Expand Down
Loading
Loading