Skip to content

cms: ECC KeyAgreementRecipientInfo initial support #1579

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

Merged
merged 33 commits into from
Apr 21, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
33 commits
Select commit Hold shift + click to select a range
baf6a74
cms: ecc-kari support - add kari and utils modules
nemynm Oct 11, 2024
5e1a1b5
cms: ecc-kari support - add EccCmsSharedInfo
nemynm Oct 11, 2024
f112255
cms: ecc-kari support - add KeyAgreementAlgorithm
nemynm Oct 12, 2024
f2ff105
cms: ecc-kari support - add RFC details for KeyAgreementAlgorithm
nemynm Oct 12, 2024
8dd5f9f
cms: ecc-kari support - add KeyWrapAlgorithm
nemynm Oct 12, 2024
70506c3
cms: ecc-kari support - add aes-kw dependency
nemynm Oct 13, 2024
b2938fb
cms: ecc-kari support - move KeyWrapAlgorithm to kw module
nemynm Oct 13, 2024
ea47fd2
cms: ecc-kari support - add EcKeyEncryptionInfo
nemynm Oct 13, 2024
20eb4f2
cms: ecc-kari support - add kdf dependency
nemynm Oct 14, 2024
46937ea
cms: ecc-kari support - move KeyAgreeRecipientInfoBuilder to sub-module
nemynm Oct 19, 2024
576e89e
cms: ecc-kari support - add elliptic-curve/pkcs8
nemynm Oct 19, 2024
81d3456
cms: ecc-kari support - add KDF utilities
nemynm Oct 20, 2024
5e0da85
cms: ecc-kari support - add key wrap utilities
nemynm Oct 20, 2024
abffecb
cms: ecc-kari support - add p256-priv.der corresponding public key
nemynm Oct 20, 2024
6a261bf
cms: ecc-kari support - add comments and exports
nemynm Oct 20, 2024
4c944c7
cms: ecc-kari support - add kari test module
nemynm Oct 20, 2024
627d24d
cms: ecc-kari support - add test for kari builder
nemynm Oct 20, 2024
3d91f37
cms: ecc-kari support
nemynm Oct 20, 2024
e584fe9
cms: ecc-kari support - add From<ContentEncryptionAlgorithm> for KeyW…
nemynm Oct 20, 2024
5112ff0
cms: ecc-kari support - add From<KeyWrapAlgorithm> for WrappingKey test
nemynm Oct 20, 2024
6d0ea70
cms: ecc-kari support - bring EnvelopedData in scope for doc
nemynm Oct 20, 2024
e8c1464
cms: use aes-kw pre-release
baloo Oct 21, 2024
a9dcdbd
cms: make KeyAgreementAlgorithm a trait
baloo Oct 21, 2024
314030f
Switch to build_with_rng
nemynm Feb 11, 2025
b0b8eaf
Remove unused dependency
nemynm Feb 11, 2025
9ac2ab5
Fix clippy and error message in KeyAgreementAlgorithm implementation
nemynm Feb 11, 2025
00e154e
cms: ecc-kari support - make KeyWrapAlgorithm a trait
nemynm Feb 18, 2025
c1984b7
cms: ecc-kari support - adjust CryptoRng
nemynm Apr 20, 2025
dcf266b
cms: ecc-kari support - adjust dependencies versions
nemynm Apr 20, 2025
2cabbff
cms: ecc-kari support - adjust patch & cargo lock file
nemynm Apr 20, 2025
8c9a91e
cms: ecc-kari support - fix cargo fmt
nemynm Apr 20, 2025
5196460
cms: ecc-kari support - remove deprecated async-signature
nemynm Apr 21, 2025
59501e5
cms: ecc-kari support - remove unused old tests
nemynm Apr 21, 2025
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
31 changes: 31 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 @@ -67,6 +67,14 @@ x509-ocsp = { path = "./x509-ocsp" }
# https://github.com/RustCrypto/signatures/pull/923
ecdsa = { git = "https://github.com/RustCrypto/signatures.git" }
rfc6979 = { git = "https://github.com/RustCrypto/signatures.git" }
# https://github.com/RustCrypto/key-wraps/pull/34
# https://github.com/RustCrypto/key-wraps/pull/35
# https://github.com/RustCrypto/key-wraps/pull/39
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" }


# https://github.com/RustCrypto/traits/pull/1777
Expand Down
9 changes: 9 additions & 0 deletions cms/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,12 @@ x509-cert = { version = "=0.3.0-pre.0", default-features = false }

# optional dependencies
aes = { version = "=0.9.0-pre.3", optional = true }
aes-kw = { version ="=0.3.0-pre", optional = true }
ansi-x963-kdf = { version = "0.0.1", optional = true }
cbc = { version = "=0.2.0-pre.2", optional = true }
cipher = { version = "=0.5.0-pre.8", features = ["alloc", "block-padding", "rand_core"], optional = true }
digest = { version = "0.11.0-pre.10", optional = true }
elliptic-curve = { version = "=0.14.0-rc.1", optional = true }
rsa = { version = "=0.10.0-pre.4", optional = true }
sha1 = { version = "=0.11.0-pre.5", optional = true }
sha2 = { version = "=0.11.0-pre.5", optional = true }
Expand All @@ -49,8 +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:cbc",
"dep:cipher",
"dep:digest",
"elliptic-curve/ecdh",
"elliptic-curve/pkcs8",
"dep:rsa",
"dep:sha1",
"dep:sha2",
Expand Down
72 changes: 12 additions & 60 deletions cms/src/builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ use crate::cert::CertificateChoices;
use crate::content_info::{CmsVersion, ContentInfo};
use crate::enveloped_data::{
EncryptedContentInfo, EncryptedKey, EnvelopedData, KekIdentifier, KeyTransRecipientInfo,
OriginatorIdentifierOrKey, OriginatorInfo, PasswordRecipientInfo, RecipientIdentifier,
RecipientInfo, RecipientInfos, UserKeyingMaterial,
OriginatorInfo, PasswordRecipientInfo, RecipientIdentifier, RecipientInfo, RecipientInfos,
UserKeyingMaterial,
};
use crate::revocation::{RevocationInfoChoice, RevocationInfoChoices};
use crate::signed_data::{
Expand Down Expand Up @@ -45,6 +45,16 @@ 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::{
DhSinglePassStdDhKdf, EcKeyEncryptionInfo, KeyAgreeRecipientInfoBuilder, KeyAgreementAlgorithm,
};
pub use utils::kw::KeyWrapAlgorithm;

/// Error type
#[derive(Debug)]
#[non_exhaustive]
Expand Down Expand Up @@ -689,64 +699,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: ?Sized> {
/// 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: ?Sized> RecipientInfoBuilder for KeyAgreeRecipientInfoBuilder<R>
where
R: CryptoRng,
{
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