Skip to content

Commit 5f63cc0

Browse files
nemynmbaloo
andauthored
cms: ECC KeyAgreementRecipientInfo initial support (#1579)
* cms: ecc-kari support - add kari and utils modules * cms: ecc-kari support - add EccCmsSharedInfo * cms: ecc-kari support - add KeyAgreementAlgorithm * cms: ecc-kari support - add RFC details for KeyAgreementAlgorithm * cms: ecc-kari support - add KeyWrapAlgorithm * cms: ecc-kari support - add aes-kw dependency * cms: ecc-kari support - move KeyWrapAlgorithm to kw module * cms: ecc-kari support - add EcKeyEncryptionInfo * cms: ecc-kari support - add kdf dependency * cms: ecc-kari support - move KeyAgreeRecipientInfoBuilder to sub-module * cms: ecc-kari support - add elliptic-curve/pkcs8 * cms: ecc-kari support - add KDF utilities * cms: ecc-kari support - add key wrap utilities * cms: ecc-kari support - add p256-priv.der corresponding public key * cms: ecc-kari support - add comments and exports * cms: ecc-kari support - add kari test module * cms: ecc-kari support - add test for kari builder * cms: ecc-kari support - Re-organize imports - Adjust comments - Add KeyAgreeRecipientInfoBuilder build logic - Add tests for KeyAgreementAlgorithm and EcKeyEncryptionInfo * cms: ecc-kari support - add From<ContentEncryptionAlgorithm> for KeyWrapAlgorithm * cms: ecc-kari support - add From<KeyWrapAlgorithm> for WrappingKey test * cms: ecc-kari support - bring EnvelopedData in scope for doc * cms: use aes-kw pre-release * cms: make KeyAgreementAlgorithm a trait * Switch to build_with_rng * Remove unused dependency * Fix clippy and error message in KeyAgreementAlgorithm implementation * cms: ecc-kari support - make KeyWrapAlgorithm a trait --------- Co-authored-by: Arthur Gautier <arthur.gautier@arista.com> * cms: ecc-kari support - adjust CryptoRng * cms: ecc-kari support - adjust dependencies versions * cms: ecc-kari support - adjust patch & cargo lock file * cms: ecc-kari support - fix cargo fmt * cms: ecc-kari support - remove deprecated async-signature * cms: ecc-kari support - remove unused old tests --------- Co-authored-by: Arthur Gautier <arthur.gautier@arista.com>
1 parent d933c0d commit 5f63cc0

10 files changed

Lines changed: 795 additions & 60 deletions

File tree

Cargo.lock

Lines changed: 31 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,14 @@ x509-ocsp = { path = "./x509-ocsp" }
6767
# https://github.com/RustCrypto/signatures/pull/923
6868
ecdsa = { git = "https://github.com/RustCrypto/signatures.git" }
6969
rfc6979 = { git = "https://github.com/RustCrypto/signatures.git" }
70+
# https://github.com/RustCrypto/key-wraps/pull/34
71+
# https://github.com/RustCrypto/key-wraps/pull/35
72+
# https://github.com/RustCrypto/key-wraps/pull/39
73+
aes-kw = { git = "https://github.com/RustCrypto/key-wraps.git" }
74+
75+
76+
# https://github.com/RustCrypto/KDFs/pull/102
77+
ansi-x963-kdf = { git = "https://github.com/RustCrypto/KDFs.git" }
7078

7179

7280
# https://github.com/RustCrypto/traits/pull/1777

cms/Cargo.toml

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,12 @@ x509-cert = { version = "=0.3.0-pre.0", default-features = false }
2222

2323
# optional dependencies
2424
aes = { version = "=0.9.0-pre.3", optional = true }
25+
aes-kw = { version ="=0.3.0-pre", optional = true }
26+
ansi-x963-kdf = { version = "0.0.1", optional = true }
2527
cbc = { version = "=0.2.0-pre.2", optional = true }
2628
cipher = { version = "=0.5.0-pre.8", features = ["alloc", "block-padding", "rand_core"], optional = true }
29+
digest = { version = "0.11.0-pre.10", optional = true }
30+
elliptic-curve = { version = "=0.14.0-rc.1", optional = true }
2731
rsa = { version = "=0.10.0-pre.4", optional = true }
2832
sha1 = { version = "=0.11.0-pre.5", optional = true }
2933
sha2 = { version = "=0.11.0-pre.5", optional = true }
@@ -49,8 +53,13 @@ x509-cert = { version = "=0.3.0-pre.0", features = ["pem"] }
4953
std = ["der/std", "spki/std"]
5054
builder = [
5155
"dep:aes",
56+
"dep:aes-kw",
57+
"dep:ansi-x963-kdf",
5258
"dep:cbc",
5359
"dep:cipher",
60+
"dep:digest",
61+
"elliptic-curve/ecdh",
62+
"elliptic-curve/pkcs8",
5463
"dep:rsa",
5564
"dep:sha1",
5665
"dep:sha2",

cms/src/builder.rs

Lines changed: 12 additions & 60 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@ use crate::cert::CertificateChoices;
66
use crate::content_info::{CmsVersion, ContentInfo};
77
use crate::enveloped_data::{
88
EncryptedContentInfo, EncryptedKey, EnvelopedData, KekIdentifier, KeyTransRecipientInfo,
9-
OriginatorIdentifierOrKey, OriginatorInfo, PasswordRecipientInfo, RecipientIdentifier,
10-
RecipientInfo, RecipientInfos, UserKeyingMaterial,
9+
OriginatorInfo, PasswordRecipientInfo, RecipientIdentifier, RecipientInfo, RecipientInfos,
10+
UserKeyingMaterial,
1111
};
1212
use crate::revocation::{RevocationInfoChoice, RevocationInfoChoices};
1313
use crate::signed_data::{
@@ -45,6 +45,16 @@ use x509_cert::attr::{Attribute, AttributeValue, Attributes};
4545
use x509_cert::builder::{self, AsyncBuilder, Builder};
4646
use zeroize::Zeroize;
4747

48+
// Modules
49+
mod kari;
50+
mod utils;
51+
52+
// Exports
53+
pub use kari::{
54+
DhSinglePassStdDhKdf, EcKeyEncryptionInfo, KeyAgreeRecipientInfoBuilder, KeyAgreementAlgorithm,
55+
};
56+
pub use utils::kw::KeyWrapAlgorithm;
57+
4858
/// Error type
4959
#[derive(Debug)]
5060
#[non_exhaustive]
@@ -689,64 +699,6 @@ where
689699
}
690700
}
691701

692-
/// Builds a `KeyAgreeRecipientInfo` according to RFC 5652 § 6.
693-
/// This type uses key agreement: the recipient's public key and the sender's
694-
/// private key are used to generate a pairwise symmetric key, then
695-
/// the content-encryption key is encrypted in the pairwise symmetric key.
696-
pub struct KeyAgreeRecipientInfoBuilder<R: ?Sized> {
697-
/// A CHOICE with three alternatives specifying the sender's key agreement public key.
698-
pub originator: OriginatorIdentifierOrKey,
699-
/// Optional information which helps generating different keys every time.
700-
pub ukm: Option<UserKeyingMaterial>,
701-
/// Encryption algorithm to be used for key encryption
702-
pub key_enc_alg: AlgorithmIdentifierOwned,
703-
_rng: PhantomData<R>,
704-
}
705-
706-
impl<R> KeyAgreeRecipientInfoBuilder<R> {
707-
/// Creates a `KeyAgreeRecipientInfoBuilder`
708-
pub fn new(
709-
originator: OriginatorIdentifierOrKey,
710-
ukm: Option<UserKeyingMaterial>,
711-
key_enc_alg: AlgorithmIdentifierOwned,
712-
) -> Result<Self> {
713-
Ok(KeyAgreeRecipientInfoBuilder {
714-
originator,
715-
ukm,
716-
key_enc_alg,
717-
_rng: PhantomData,
718-
})
719-
}
720-
}
721-
722-
impl<R: ?Sized> RecipientInfoBuilder for KeyAgreeRecipientInfoBuilder<R>
723-
where
724-
R: CryptoRng,
725-
{
726-
type Rng = R;
727-
728-
/// Returns the RecipientInfoType
729-
fn recipient_info_type(&self) -> RecipientInfoType {
730-
RecipientInfoType::Kari
731-
}
732-
733-
/// Returns the `CMSVersion` for this `RecipientInfo`
734-
fn recipient_info_version(&self) -> CmsVersion {
735-
CmsVersion::V3
736-
}
737-
738-
/// Build a `KeyAgreeRecipientInfoBuilder`. See RFC 5652 § 6.2.1
739-
fn build_with_rng(
740-
&mut self,
741-
_content_encryption_key: &[u8],
742-
_rng: &mut Self::Rng,
743-
) -> Result<RecipientInfo> {
744-
Err(Error::Builder(String::from(
745-
"Building KeyAgreeRecipientInfo is not implemented, yet.",
746-
)))
747-
}
748-
}
749-
750702
/// Builds a `KekRecipientInfo` according to RFC 5652 § 6.
751703
/// Uses symmetric key-encryption keys: the content-encryption key is
752704
/// encrypted in a previously distributed symmetric key-encryption key.

0 commit comments

Comments
 (0)