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

Open
wants to merge 26 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
fe7367b
cms: ecc-kari support - add kari and utils modules
nemynm Oct 11, 2024
c2a837b
cms: ecc-kari support - add EccCmsSharedInfo
nemynm Oct 11, 2024
d9d4a24
cms: ecc-kari support - add KeyAgreementAlgorithm
nemynm Oct 12, 2024
7e335e1
cms: ecc-kari support - add RFC details for KeyAgreementAlgorithm
nemynm Oct 12, 2024
4d2034a
cms: ecc-kari support - add KeyWrapAlgorithm
nemynm Oct 12, 2024
78ecc1a
cms: ecc-kari support - add elliptic-curve dependency
nemynm Oct 12, 2024
03e599a
cms: ecc-kari support - add aes-kw dependency
nemynm Oct 13, 2024
914ed59
cms: ecc-kari support - move KeyWrapAlgorithm to kw module
nemynm Oct 13, 2024
0fbe363
cms: ecc-kari support - add EcKeyEncryptionInfo
nemynm Oct 13, 2024
dd3b09d
cms: ecc-kari support - add kdf dependency
nemynm Oct 14, 2024
92cc970
cms: ecc-kari support - move KeyAgreeRecipientInfoBuilder to sub-module
nemynm Oct 19, 2024
5a053ea
cms: ecc-kari support - add elliptic-curve/pkcs8
nemynm Oct 19, 2024
139828e
cms: ecc-kari support - add KDF utilities
nemynm Oct 20, 2024
885d934
cms: ecc-kari support - add key wrap utilities
nemynm Oct 20, 2024
8105d27
cms: ecc-kari support - add p256-priv.der corresponding public key
nemynm Oct 20, 2024
066d0a7
cms: ecc-kari support - add comments and exports
nemynm Oct 20, 2024
804ebf4
cms: ecc-kari support - add kari test module
nemynm Oct 20, 2024
d3015cb
cms: ecc-kari support - add test for kari builder
nemynm Oct 20, 2024
9bce42a
cms: ecc-kari support
nemynm Oct 20, 2024
a042e2c
cms: ecc-kari support - remove default builder
nemynm Oct 20, 2024
457281c
cms: ecc-kari support - add From<ContentEncryptionAlgorithm> for KeyW…
nemynm Oct 20, 2024
4901a07
cms: ecc-kari support - add From<KeyWrapAlgorithm> for WrappingKey test
nemynm Oct 20, 2024
fa50632
cms: ecc-kari support - bring EnvelopedData in scope for doc
nemynm Oct 20, 2024
73b0b44
cms: use aes-kw pre-release
baloo Oct 21, 2024
8dde07b
Merge pull request #1 from baloo/baloo/cms/aes-kw-pre
nemynm Nov 1, 2024
1bcc5b6
Merge branch 'RustCrypto:master' into cms-ecc-kari
nemynm Nov 7, 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
32 changes: 31 additions & 1 deletion 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 @@ -48,9 +51,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
58 changes: 9 additions & 49 deletions cms/src/builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,7 @@ use crate::cert::CertificateChoices;
use crate::content_info::{CmsVersion, ContentInfo};
use crate::enveloped_data::{
EncryptedContentInfo, EncryptedKey, EnvelopedData, KekIdentifier, KeyTransRecipientInfo,
OriginatorIdentifierOrKey, OriginatorInfo, RecipientIdentifier, RecipientInfo, RecipientInfos,
UserKeyingMaterial,
OriginatorInfo, RecipientIdentifier, RecipientInfo, RecipientInfos, UserKeyingMaterial,
};
use crate::revocation::{RevocationInfoChoice, RevocationInfoChoices};
use crate::signed_data::{
Expand Down Expand Up @@ -47,6 +46,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 @@ -693,53 +700,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 {
/// 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,
}

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

impl RecipientInfoBuilder for KeyAgreeRecipientInfoBuilder {
/// 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(&mut self, _content_encryption_key: &[u8]) -> 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