diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 74188db1..fde31fd0 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -48,16 +48,6 @@ jobs: - run: cargo test --release --features getrandom - run: cargo test --release --features serde - doc: - runs-on: ubuntu-latest - steps: - - uses: actions/checkout@v4 - - uses: RustCrypto/actions/cargo-cache@master - - uses: dtolnay/rust-toolchain@master - with: - toolchain: stable - - run: cargo doc --all-features - minimal-versions: runs-on: ubuntu-latest steps: diff --git a/.github/workflows/workspace.yml b/.github/workflows/workspace.yml new file mode 100644 index 00000000..c67ebc50 --- /dev/null +++ b/.github/workflows/workspace.yml @@ -0,0 +1,47 @@ +name: Workspace + +on: + pull_request: + paths-ignore: + - README.md + push: + branches: master + paths-ignore: + - README.md + +jobs: + clippy: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + - uses: RustCrypto/actions/cargo-cache@master + - uses: dtolnay/rust-toolchain@master + with: + toolchain: 1.79.0 + components: clippy + - run: cargo clippy --all -- -D warnings + + fmt: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + - uses: RustCrypto/actions/cargo-cache@master + - uses: dtolnay/rust-toolchain@master + with: + toolchain: stable + components: rustfmt + - run: cargo fmt --all -- --check + + doc: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + - uses: RustCrypto/actions/cargo-cache@master + - uses: dtolnay/rust-toolchain@master + with: + # We need Nightly for doc_auto_cfg + toolchain: nightly-2024-06-25 + - uses: Swatinem/rust-cache@v2 + - env: + RUSTDOCFLAGS: "-Dwarnings --cfg docsrs" + run: cargo doc --no-deps --features std,pem,serde,hazmat,sha2 diff --git a/benches/key.rs b/benches/key.rs index 39260388..bc1e4bca 100644 --- a/benches/key.rs +++ b/benches/key.rs @@ -10,19 +10,67 @@ use rsa::{Pkcs1v15Encrypt, Pkcs1v15Sign, RsaPrivateKey}; use sha2::{Digest, Sha256}; use test::Bencher; -const DECRYPT_VAL: &'static str = - "XW4qfrpQDarEMBfPyIYE9UvuOFkbBi0tiGYbIOJPLMNe/LWuPD0BQ7ceqlOlPPcKLinYz0DlnqW3It/V7ae59zw9afA3YIWdq0Ut2BnYL+aJixnqaP+PjsQNcHg6axCF11iNQ4jpXrZDiQcI+q9EEzZDTMsiMxtjfgBQUd8LHT87YoQXDWaFPCVpliACMc8aUk442kH1tc4jEuXwjEjFErvAM/J7VizCdU/dnKrlq2mBDzvZ6hxY9TYHFB/zY6DZPJAgEMUxYWCR9xPJ7X256DV1Kt0Ht33DWoFcgh/pPLM1q9pK0HVxCdclXfZOeCqlrLgZ5Gxv5DM4BtV7Z4m85w=="; +const DECRYPT_VAL: &str = "\ + XW4qfrpQDarEMBfPyIYE9UvuOFkbBi0tiGYbIOJPLMNe/LWuPD0BQ7ceqlOlPPcK\ + LinYz0DlnqW3It/V7ae59zw9afA3YIWdq0Ut2BnYL+aJixnqaP+PjsQNcHg6axCF\ + 11iNQ4jpXrZDiQcI+q9EEzZDTMsiMxtjfgBQUd8LHT87YoQXDWaFPCVpliACMc8a\ + Uk442kH1tc4jEuXwjEjFErvAM/J7VizCdU/dnKrlq2mBDzvZ6hxY9TYHFB/zY6DZ\ + PJAgEMUxYWCR9xPJ7X256DV1Kt0Ht33DWoFcgh/pPLM1q9pK0HVxCdclXfZOeCql\ + rLgZ5Gxv5DM4BtV7Z4m85w=="; fn get_key() -> RsaPrivateKey { RsaPrivateKey::from_components( - BigUint::from_str_radix("14314132931241006650998084889274020608918049032671858325988396851334124245188214251956198731333464217832226406088020736932173064754214329009979944037640912127943488972644697423190955557435910767690712778463524983667852819010259499695177313115447116110358524558307947613422897787329221478860907963827160223559690523660574329011927531289655711860504630573766609239332569210831325633840174683944553667352219670930408593321661375473885147973879086994006440025257225431977751512374815915392249179976902953721486040787792801849818254465486633791826766873076617116727073077821584676715609985777563958286637185868165868520557", 10).unwrap(), + BigUint::from_str_radix( + "1431413293124100665099808488927402060891804903267185832598839685\ + 1334124245188214251956198731333464217832226406088020736932173064\ + 7542143290099799440376409121279434889726446974231909555574359107\ + 6769071277846352498366785281901025949969517731311544711611035852\ + 4558307947613422897787329221478860907963827160223559690523660574\ + 3290119275312896557118605046305737666092393325692108313256338401\ + 7468394455366735221967093040859332166137547388514797387908699400\ + 6440025257225431977751512374815915392249179976902953721486040787\ + 7928018498182544654866337918267668730766171167270730778215846767\ + 15609985777563958286637185868165868520557", + 10, + ) + .unwrap(), BigUint::from_u32(3).unwrap(), - BigUint::from_str_radix("9542755287494004433998723259516013739278699355114572217325597900889416163458809501304132487555642811888150937392013824621448709836142886006653296025093941418628992648429798282127303704957273845127141852309016655778568546006839666463451542076964744073572349705538631742281931858219480985907271975884773482372966847639853897890615456605598071088189838676728836833012254065983259638538107719766738032720239892094196108713378822882383694456030043492571063441943847195939549773271694647657549658603365629458610273821292232646334717612674519997533901052790334279661754176490593041941863932308687197618671528035670452762731", 10).unwrap(), + BigUint::from_str_radix( + "9542755287494004433998723259516013739278699355114572217325597900\ + 8894161634588095013041324875556428118881509373920138246214487098\ + 3614288600665329602509394141862899264842979828212730370495727384\ + 5127141852309016655778568546006839666463451542076964744073572349\ + 7055386317422819318582194809859072719758847734823729668476398538\ + 9789061545660559807108818983867672883683301225406598325963853810\ + 7719766738032720239892094196108713378822882383694456030043492571\ + 0634419438471959395497732716946476575496586033656294586102738212\ + 9223264633471761267451999753390105279033427966175417649059304194\ + 1863932308687197618671528035670452762731", + 10, + ) + .unwrap(), vec![ - BigUint::from_str_radix("130903255182996722426771613606077755295583329135067340152947172868415809027537376306193179624298874215608270802054347609836776473930072411958753044562214537013874103802006369634761074377213995983876788718033850153719421695468704276694983032644416930879093914927146648402139231293035971427838068945045019075433",10).unwrap(), - BigUint::from_str_radix("109348945610485453577574767652527472924289229538286649661240938988020367005475727988253438647560958573506159449538793540472829815903949343191091817779240101054552748665267574271163617694640513549693841337820602726596756351006149518830932261246698766355347898158548465400674856021497190430791824869615170301029", 10).unwrap() + BigUint::from_str_radix( + "1309032551829967224267716136060777552955833291350673401529471728\ + 6841580902753737630619317962429887421560827080205434760983677647\ + 3930072411958753044562214537013874103802006369634761074377213995\ + 9838767887180338501537194216954687042766949830326444169308790939\ + 14927146648402139231293035971427838068945045019075433", + 10, + ) + .unwrap(), + BigUint::from_str_radix( + "1093489456104854535775747676525274729242892295382866496612409389\ + 8802036700547572798825343864756095857350615944953879354047282981\ + 5903949343191091817779240101054552748665267574271163617694640513\ + 5496938413378206027265967563510061495188309322612466987663553478\ + 98158548465400674856021497190430791824869615170301029", + 10, + ) + .unwrap(), ], - ).unwrap() + ) + .unwrap() } #[bench] diff --git a/src/algorithms/mgf.rs b/src/algorithms/mgf.rs index 5dc6eff9..009a5030 100644 --- a/src/algorithms/mgf.rs +++ b/src/algorithms/mgf.rs @@ -9,7 +9,7 @@ pub(crate) fn mgf1_xor(out: &mut [u8], digest: &mut dyn DynDigest, seed: &[u8]) let mut counter = [0u8; 4]; let mut i = 0; - const MAX_LEN: u64 = core::u32::MAX as u64 + 1; + const MAX_LEN: u64 = u32::MAX as u64 + 1; assert!(out.len() as u64 <= MAX_LEN); while i < out.len() { @@ -43,7 +43,7 @@ where let mut counter = [0u8; 4]; let mut i = 0; - const MAX_LEN: u64 = core::u32::MAX as u64 + 1; + const MAX_LEN: u64 = u32::MAX as u64 + 1; assert!(out.len() as u64 <= MAX_LEN); while i < out.len() { diff --git a/src/encoding.rs b/src/encoding.rs index 3151791d..51d5032d 100644 --- a/src/encoding.rs +++ b/src/encoding.rs @@ -17,7 +17,9 @@ use zeroize::Zeroizing; pub const ID_RSASSA_PSS: ObjectIdentifier = ObjectIdentifier::new_unwrap("1.2.840.113549.1.1.10"); /// Verify that the `AlgorithmIdentifier` for a key is correct. -pub(crate) fn verify_algorithm_id(algorithm: &pkcs8::AlgorithmIdentifierRef) -> pkcs8::spki::Result<()> { +pub(crate) fn verify_algorithm_id( + algorithm: &pkcs8::AlgorithmIdentifierRef, +) -> pkcs8::spki::Result<()> { match algorithm.oid { pkcs1::ALGORITHM_OID => { if algorithm.parameters_any()? != pkcs8::der::asn1::Null.into() { @@ -25,7 +27,7 @@ pub(crate) fn verify_algorithm_id(algorithm: &pkcs8::AlgorithmIdentifierRef) -> } } ID_RSASSA_PSS => { - if !algorithm.parameters.is_none() { + if algorithm.parameters.is_some() { return Err(pkcs8::spki::Error::KeyMalformed); } } diff --git a/src/key.rs b/src/key.rs index 03931dab..b7747d6f 100644 --- a/src/key.rs +++ b/src/key.rs @@ -9,9 +9,9 @@ use rand_core::CryptoRngCore; use zeroize::{Zeroize, ZeroizeOnDrop}; #[cfg(feature = "serde")] use { + pkcs8::{DecodePrivateKey, EncodePrivateKey}, serdect::serde::{de, ser, Deserialize, Serialize}, - spki::{EncodePublicKey, DecodePublicKey}, - pkcs8::{EncodePrivateKey, DecodePrivateKey} + spki::{DecodePublicKey, EncodePublicKey}, }; use crate::algorithms::generate::generate_multi_prime_key_with_exp; @@ -690,9 +690,11 @@ mod tests { let mut rng = ChaCha8Rng::from_seed([42; 32]); let priv_key = RsaPrivateKey::new(&mut rng, 64).expect("failed to generate key"); - let priv_tokens = [ - Token::Str("3054020100300d06092a864886f70d01010105000440303e020100020900cc6c6130e35b46bf0203010001020863de1ac858580019020500f65cff5d020500d46b68cb02046d9a09f102047b4e3a4f020500f45065cc") - ]; + let priv_tokens = [Token::Str( + "3054020100300d06092a864886f70d01010105000440303e020100020900cc6c\ + 6130e35b46bf0203010001020863de1ac858580019020500f65cff5d020500d4\ + 6b68cb02046d9a09f102047b4e3a4f020500f45065cc", + )]; assert_tokens(&priv_key.clone().readable(), &priv_tokens); let priv_tokens = [Token::Str( @@ -708,15 +710,81 @@ mod tests { fn invalid_coeff_private_key_regression() { use base64ct::{Base64, Encoding}; - let n = Base64::decode_vec("wC8GyQvTCZOK+iiBR5fGQCmzRCTWX9TQ3aRG5gGFk0wB6EFoLMAyEEqeG3gS8xhAm2rSWYx9kKufvNat3iWlbSRVqkcbpVAYlj2vTrpqDpJl+6u+zxFYoUEBevlJJkAhl8EuCccOA30fVpcfRvXPTtvRd3yFT9E9EwZljtgSI02w7gZwg7VIxaGeajh5Euz6ZVQZ+qNRKgXrRC7gPRqVyI6Dt0Jc+Su5KBGNn0QcPDzOahWha1ieaeMkFisZ9mdpsJoZ4tw5eicLaUomKzALHXQVt+/rcZSrCd6/7uUo11B/CYBM4UfSpwXaL88J9AE6A5++no9hmJzaF2LLp+Qwx4yY3j9TDutxSAjsraxxJOGZ3XyA9nG++Ybt3cxZ5fP7ROjxCfROBmVv5dYn0O9OBIqYeCH6QraNpZMadlLNIhyMv8Y+P3r5l/PaK4VJaEi5pPosnEPawp0W0yZDzmjk2z1LthaRx0aZVrAjlH0Rb/6goLUQ9qu1xsDtQVVpN4A89ZUmtTWORnnJr0+595eHHxssd2gpzqf4bPjNITdAEuOCCtpvyi4ls23zwuzryUYjcUOEnsXNQ+DrZpLKxdtsD/qNV/j1hfeyBoPllC3cV+6bcGOFcVGbjYqb+Kw1b0+jL69RSKQqgmS+qYqr8c48nDRxyq3QXhR8qtzUwBFSLVk=").unwrap(); + let n = Base64::decode_vec( + "wC8GyQvTCZOK+iiBR5fGQCmzRCTWX9TQ3aRG5gGFk0wB6EFoLMAyEEqeG3gS8xhA\ + m2rSWYx9kKufvNat3iWlbSRVqkcbpVAYlj2vTrpqDpJl+6u+zxFYoUEBevlJJkAh\ + l8EuCccOA30fVpcfRvXPTtvRd3yFT9E9EwZljtgSI02w7gZwg7VIxaGeajh5Euz6\ + ZVQZ+qNRKgXrRC7gPRqVyI6Dt0Jc+Su5KBGNn0QcPDzOahWha1ieaeMkFisZ9mdp\ + sJoZ4tw5eicLaUomKzALHXQVt+/rcZSrCd6/7uUo11B/CYBM4UfSpwXaL88J9AE6\ + A5++no9hmJzaF2LLp+Qwx4yY3j9TDutxSAjsraxxJOGZ3XyA9nG++Ybt3cxZ5fP7\ + ROjxCfROBmVv5dYn0O9OBIqYeCH6QraNpZMadlLNIhyMv8Y+P3r5l/PaK4VJaEi5\ + pPosnEPawp0W0yZDzmjk2z1LthaRx0aZVrAjlH0Rb/6goLUQ9qu1xsDtQVVpN4A8\ + 9ZUmtTWORnnJr0+595eHHxssd2gpzqf4bPjNITdAEuOCCtpvyi4ls23zwuzryUYj\ + cUOEnsXNQ+DrZpLKxdtsD/qNV/j1hfeyBoPllC3cV+6bcGOFcVGbjYqb+Kw1b0+j\ + L69RSKQqgmS+qYqr8c48nDRxyq3QXhR8qtzUwBFSLVk=", + ) + .unwrap(); let e = Base64::decode_vec("AQAB").unwrap(); - let d = Base64::decode_vec("qQazSQ+FRN7nVK1bRsROMRB8AmsDwLVEHivlz1V3Td2Dr+oW3YUMgxedhztML1IdQJPq/ad6qErJ6yRFNySVIjDaxzBTOEoB1eHa1btOnBJWb8rVvvjaorixvJ6Tn3i4EuhsvVy9DoR1k4rGj3qSIiFjUVvLRDAbLyhpGgEfsr0Z577yJmTC5E8JLRMOKX8Tmxsk3jPVpsgd65Hu1s8S/ZmabwuHCf9SkdMeY/1bd/9i7BqqJeeDLE4B5x1xcC3z3scqDUTzqGO+vZPhjgprPDRlBamVwgenhr7KwCn8iaLamFinRVwOAag8BeBqOJj7lURiOsKQa9FIX1kdFUS1QMQxgtPycLjkbvCJjriqT7zWKsmJ7l8YLs6Wmm9/+QJRwNCEVdMTXKfCP1cJjudaiskEQThfUldtgu8gUDNYbQ/Filb2eKfiX4h1TiMxZqUZHVZyb9nShbQoXJ3vj/MGVF0QM8TxhXM8r2Lv9gDYU5t9nQlUMLhs0jVjai48jHABbFNyH3sEcOmJOIwJrCXw1dzG7AotwyaEVUHOmL04TffmwCFfnyrLjbFgnyOeoyIIBYjcY7QFRm/9nupXMTH5hZ2qrHfCJIp0KK4tNBdQqmnHapFl5l6Le1s4qBS5bEIzjitobLvAFm9abPlDGfxmY6mlrMK4+nytwF9Ct7wc1AE=").unwrap(); - let primes = vec![ - Base64::decode_vec("9kQWEAzsbzOcdPa+s5wFfw4XDd7bB1q9foZ31b1+TNjGNxbSBCFlDF1q98vwpV6nM8bWDh/wtbNoETSQDgpEnYOQ26LWEw6YY1+q1Q2GGEFceYUf+Myk8/vTc8TN6Zw0bKZBWy10Qo8h7xk4JpzuI7NcxvjJYTkS9aErFxi3vVH0aiZC0tmfaCqr8a2rJxyVwqreRpOjwAWrotMsf2wGsF4ofx5ScoFy5GB5fJkkdOrW1LyTvZAUCX3cstPr19+TNC5zZOk7WzZatnCkN5H5WzalWtZuu0oVL205KPOa3R8V2yv5e6fm0v5fTmqSuvjmaMJLXCN4QJkmIzojO99ckQ==").unwrap(), - Base64::decode_vec("x8exdMjVA2CiI+Thx7loHtVcevoeE2sZ7btRVAvmBqo+lkHwxb7FHRnWvuj6eJSlD2f0T50EewIhhiW3R9BmktCk7hXjbSCnC1u9Oxc1IAUm/7azRqyfCMx43XhLxpD+xkBCpWkKDLxGczsRwTuaP3lKS3bSdBrNlGmdblubvVBIq4YZ2vXVlnYtza0cS+dgCK7BGTqUsrCUd/ZbIvwcwZkZtpkhj1KQfto9X/0OMurBzAqbkeq1cyRHXHkOfN/qbUIIRqr9Ii7Eswf9Vk8xp2O1Nt8nzcYS9PFD12M5eyaeFEkEYfpNMNGuTzp/31oqVjbpoCxS6vuWAZyADxhISQ==").unwrap(), - Base64::decode_vec("is7d0LY4HoXszlC2NO7gejkq7XqL4p1W6hZJPYTNx+r37t1CC2n3Vvzg6kNdpRixDhIpXVTLjN9O7UO/XuqSumYKJIKoP52eb4Tg+a3hw5Iz2Zsb5lUTNSLgkQSBPAf71LHxbL82JL4g1nBUog8ae60BwnVArThKY4EwlJguGNw09BAU4lwf6csDl/nX2vfVwiAloYpeZkHL+L8m+bueGZM5KE2jEz+7ztZCI+T+E5i69rZEYDjx0lfLKlEhQlCW3HbCPELqXgNJJkRfi6MP9kXa9lSfnZmoT081RMvqonB/FUa4HOcKyCrw9XZEtnbNCIdbitfDVEX+pSSD7596wQ==").unwrap(), - Base64::decode_vec("GPs0injugfycacaeIP5jMa/WX55VEnKLDHom4k6WlfDF4L4gIGoJdekcPEUfxOI5faKvHyFwRP1wObkPoRBDM0qZxRfBl4zEtpvjHrd5MibSyJkM8+J0BIKk/nSjbRIGeb3hV5O56PvGB3S0dKhCUnuVObiC+ne7izplsD4OTG70l1Yud33UFntyoMxrxGYLUSqhBMmZfHquJg4NOWOzKNY/K+EcHDLj1Kjvkcgv9Vf7ocsVxvpFdD9uGPceQ6kwRDdEl6mb+6FDgWuXVyqR9+904oanEIkbJ7vfkthagLbEf57dyG6nJlqh5FBZWxGIR72YGypPuAh7qnnqXXjY2Q==").unwrap(), - Base64::decode_vec("CUWC+hRWOT421kwRllgVjy6FYv6jQUcgDNHeAiYZnf5HjS9iK2ki7v8G5dL/0f+Yf+NhE/4q8w4m8go51hACrVpP1p8GJDjiT09+RsOzITsHwl+ceEKoe56ZW6iDHBLlrNw5/MtcYhKpjNU9KJ2udm5J/c9iislcjgckrZG2IB8ADgXHMEByZ5DgaMl4AKZ1Gx8/q6KftTvmOT5rNTMLi76VN5KWQcDWK/DqXiOiZHM7Nr4dX4me3XeRgABJyNR8Fqxj3N1+HrYLe/zs7LOaK0++F9Ul3tLelhrhsvLxei3oCZkF9A/foD3on3luYA+1cRcxWpSY3h2J4/22+yo4+Q==").unwrap(), + let d = Base64::decode_vec( + "qQazSQ+FRN7nVK1bRsROMRB8AmsDwLVEHivlz1V3Td2Dr+oW3YUMgxedhztML1Id\ + QJPq/ad6qErJ6yRFNySVIjDaxzBTOEoB1eHa1btOnBJWb8rVvvjaorixvJ6Tn3i4\ + EuhsvVy9DoR1k4rGj3qSIiFjUVvLRDAbLyhpGgEfsr0Z577yJmTC5E8JLRMOKX8T\ + mxsk3jPVpsgd65Hu1s8S/ZmabwuHCf9SkdMeY/1bd/9i7BqqJeeDLE4B5x1xcC3z\ + 3scqDUTzqGO+vZPhjgprPDRlBamVwgenhr7KwCn8iaLamFinRVwOAag8BeBqOJj7\ + lURiOsKQa9FIX1kdFUS1QMQxgtPycLjkbvCJjriqT7zWKsmJ7l8YLs6Wmm9/+QJR\ + wNCEVdMTXKfCP1cJjudaiskEQThfUldtgu8gUDNYbQ/Filb2eKfiX4h1TiMxZqUZ\ + HVZyb9nShbQoXJ3vj/MGVF0QM8TxhXM8r2Lv9gDYU5t9nQlUMLhs0jVjai48jHAB\ + bFNyH3sEcOmJOIwJrCXw1dzG7AotwyaEVUHOmL04TffmwCFfnyrLjbFgnyOeoyII\ + BYjcY7QFRm/9nupXMTH5hZ2qrHfCJIp0KK4tNBdQqmnHapFl5l6Le1s4qBS5bEIz\ + jitobLvAFm9abPlDGfxmY6mlrMK4+nytwF9Ct7wc1AE=", + ) + .unwrap(); + let primes = [ + Base64::decode_vec( + "9kQWEAzsbzOcdPa+s5wFfw4XDd7bB1q9foZ31b1+TNjGNxbSBCFlDF1q98vwpV6n\ + M8bWDh/wtbNoETSQDgpEnYOQ26LWEw6YY1+q1Q2GGEFceYUf+Myk8/vTc8TN6Zw0\ + bKZBWy10Qo8h7xk4JpzuI7NcxvjJYTkS9aErFxi3vVH0aiZC0tmfaCqr8a2rJxyV\ + wqreRpOjwAWrotMsf2wGsF4ofx5ScoFy5GB5fJkkdOrW1LyTvZAUCX3cstPr19+T\ + NC5zZOk7WzZatnCkN5H5WzalWtZuu0oVL205KPOa3R8V2yv5e6fm0v5fTmqSuvjm\ + aMJLXCN4QJkmIzojO99ckQ==", + ) + .unwrap(), + Base64::decode_vec( + "x8exdMjVA2CiI+Thx7loHtVcevoeE2sZ7btRVAvmBqo+lkHwxb7FHRnWvuj6eJSl\ + D2f0T50EewIhhiW3R9BmktCk7hXjbSCnC1u9Oxc1IAUm/7azRqyfCMx43XhLxpD+\ + xkBCpWkKDLxGczsRwTuaP3lKS3bSdBrNlGmdblubvVBIq4YZ2vXVlnYtza0cS+dg\ + CK7BGTqUsrCUd/ZbIvwcwZkZtpkhj1KQfto9X/0OMurBzAqbkeq1cyRHXHkOfN/q\ + bUIIRqr9Ii7Eswf9Vk8xp2O1Nt8nzcYS9PFD12M5eyaeFEkEYfpNMNGuTzp/31oq\ + VjbpoCxS6vuWAZyADxhISQ==", + ) + .unwrap(), + Base64::decode_vec( + "is7d0LY4HoXszlC2NO7gejkq7XqL4p1W6hZJPYTNx+r37t1CC2n3Vvzg6kNdpRix\ + DhIpXVTLjN9O7UO/XuqSumYKJIKoP52eb4Tg+a3hw5Iz2Zsb5lUTNSLgkQSBPAf7\ + 1LHxbL82JL4g1nBUog8ae60BwnVArThKY4EwlJguGNw09BAU4lwf6csDl/nX2vfV\ + wiAloYpeZkHL+L8m+bueGZM5KE2jEz+7ztZCI+T+E5i69rZEYDjx0lfLKlEhQlCW\ + 3HbCPELqXgNJJkRfi6MP9kXa9lSfnZmoT081RMvqonB/FUa4HOcKyCrw9XZEtnbN\ + CIdbitfDVEX+pSSD7596wQ==", + ) + .unwrap(), + Base64::decode_vec( + "GPs0injugfycacaeIP5jMa/WX55VEnKLDHom4k6WlfDF4L4gIGoJdekcPEUfxOI5\ + faKvHyFwRP1wObkPoRBDM0qZxRfBl4zEtpvjHrd5MibSyJkM8+J0BIKk/nSjbRIG\ + eb3hV5O56PvGB3S0dKhCUnuVObiC+ne7izplsD4OTG70l1Yud33UFntyoMxrxGYL\ + USqhBMmZfHquJg4NOWOzKNY/K+EcHDLj1Kjvkcgv9Vf7ocsVxvpFdD9uGPceQ6kw\ + RDdEl6mb+6FDgWuXVyqR9+904oanEIkbJ7vfkthagLbEf57dyG6nJlqh5FBZWxGI\ + R72YGypPuAh7qnnqXXjY2Q==", + ) + .unwrap(), + Base64::decode_vec( + "CUWC+hRWOT421kwRllgVjy6FYv6jQUcgDNHeAiYZnf5HjS9iK2ki7v8G5dL/0f+Y\ + f+NhE/4q8w4m8go51hACrVpP1p8GJDjiT09+RsOzITsHwl+ceEKoe56ZW6iDHBLl\ + rNw5/MtcYhKpjNU9KJ2udm5J/c9iislcjgckrZG2IB8ADgXHMEByZ5DgaMl4AKZ1\ + Gx8/q6KftTvmOT5rNTMLi76VN5KWQcDWK/DqXiOiZHM7Nr4dX4me3XeRgABJyNR8\ + Fqxj3N1+HrYLe/zs7LOaK0++F9Ul3tLelhrhsvLxei3oCZkF9A/foD3on3luYA+1\ + cRcxWpSY3h2J4/22+yo4+Q==", + ) + .unwrap(), ]; RsaPrivateKey::from_components( @@ -757,39 +825,38 @@ mod tests { // -----END PUBLIC KEY----- let n = BigUint::from_bytes_be(&hex!( - " - 90c06207caac3555c0b0947a5e8b681f5af6aed665ff1cd42b6b487f2f7d68f1 - 38f3dbbee6d2f10908507fe6bcf75e7cbd20e9af6ff1c202bcc3dbb45e9bb69b - b5d12a354c4b463a50820d16879373ceeb5574fdd9272be3b90d55c1a64855de - cf80520e94be2caa56c1737ed0042ef9c99c7ddb6cc76f3ada211ba90beae0fc - 0a19024e74e474ca5747f0ee327892bf6eebc83974478dbfbebed40d0ffc626c - 518071df5626abda386eed72585b676efb99b3ba111fb2f4b8fb0323bccb0c9b - 5aa35e1da54f1cccac3e14fb1d4588d7b9b9f62d4ea6e570c049efcc34101147 - fd7798549a42d86f9a90cee7fa0dd9f1ff4e10242280824872afd09782757abc - 46773cab6989c08747193b7aa4c49a0065830a87e6f7e54455758b2c10317267 - b9187358e41a5e5fef6fcbf81c8bc5e136ad1192aa7f3a5bc9270b22261b3c40 - 211d729d64c776cd8f219126e27227de3c0a40666b8da40c71243673a6187baf - 8943eadf0c3d3fd150076dad97e286a68185db8523a61e548cba7a6834e4ce98 - 5af954c9eafb9d819a3d14b526a0f8d2fef13ad99ee48f10c3a00f8853d7853a - 812b7a1c72bed38066f75779690bc12af9eb0d1eb8e2f7c4757c84e415725629 - d15c4d68c18213f18a86d4ccc08552b3c80c97165de073ac0440af253e8578c4 - 8857f396e5eba6cd01ed1250feb2c32d77939f8be8bd47874151daed87e8c963 - 32f697ea7950bee7a2c12bb484200bcbd08de5aeae6f22ff9922e38075b56026 - 2472f039de08e9362cfdd19c0f0cd0749ebd85bddc3882fb887f9789ed8e388e - 7e2eb2455399f166d5c9767ff378f8ebea465a0be2d2e3326fe6ed80e5e3050b - fb6c6a9dc8731ce4baa4e5b17b131113c79d6f290318095e37e7571a4ba697ab - 5ea56190131e06d300310064776ba0330907e1cc41acdef4eeaa53964ef30c71 - 023c3cf71af2d1d9e83900ffc80e07ec2442a3dbd50e957686a22f1d8f512364 - fb71e936f24990a4abcdbef2bea2f98cd77f1d1ca5625942c79347c146dee6e3 - 043eb622f63e627f4ebf20d6056133a4bd0f55dd13dcf429e0e73830969f543c - b31d86d9a878ca79d841444359cc0e31c0283fa6dd27b702b7ee05dad12c30f7 - f84bf1309678efb8da108efcedc423da8587bd127ca082d417c8726f7889fb80 - 326c3fa6fddd507ac7841b2f2e5c8780d486a0d68229ee2957a8ec24e00e4ab4 - de3fc811a4b5047c2b7920d071e9f2f9b61638dc15fb84cca46cad28e1ef539d - bcf249876f2647757b9a5e4f0b2ea6e7aabdf47dae826e9e259428bdb07e5a2a - 68b98f141f5537be7a590cb3ba15b0bb15824652e8da8f70eb847240058a336a - 1b6db7f88268aaf89f0b33b905d72c25338b13e61a51873c2d427021a3f29207 - 179ad32f423793f0c090dda025ce41df0e94afbc80ab5eda9b1a268aa2553a99" + "90c06207caac3555c0b0947a5e8b681f5af6aed665ff1cd42b6b487f2f7d68f1" + "38f3dbbee6d2f10908507fe6bcf75e7cbd20e9af6ff1c202bcc3dbb45e9bb69b" + "b5d12a354c4b463a50820d16879373ceeb5574fdd9272be3b90d55c1a64855de" + "cf80520e94be2caa56c1737ed0042ef9c99c7ddb6cc76f3ada211ba90beae0fc" + "0a19024e74e474ca5747f0ee327892bf6eebc83974478dbfbebed40d0ffc626c" + "518071df5626abda386eed72585b676efb99b3ba111fb2f4b8fb0323bccb0c9b" + "5aa35e1da54f1cccac3e14fb1d4588d7b9b9f62d4ea6e570c049efcc34101147" + "fd7798549a42d86f9a90cee7fa0dd9f1ff4e10242280824872afd09782757abc" + "46773cab6989c08747193b7aa4c49a0065830a87e6f7e54455758b2c10317267" + "b9187358e41a5e5fef6fcbf81c8bc5e136ad1192aa7f3a5bc9270b22261b3c40" + "211d729d64c776cd8f219126e27227de3c0a40666b8da40c71243673a6187baf" + "8943eadf0c3d3fd150076dad97e286a68185db8523a61e548cba7a6834e4ce98" + "5af954c9eafb9d819a3d14b526a0f8d2fef13ad99ee48f10c3a00f8853d7853a" + "812b7a1c72bed38066f75779690bc12af9eb0d1eb8e2f7c4757c84e415725629" + "d15c4d68c18213f18a86d4ccc08552b3c80c97165de073ac0440af253e8578c4" + "8857f396e5eba6cd01ed1250feb2c32d77939f8be8bd47874151daed87e8c963" + "32f697ea7950bee7a2c12bb484200bcbd08de5aeae6f22ff9922e38075b56026" + "2472f039de08e9362cfdd19c0f0cd0749ebd85bddc3882fb887f9789ed8e388e" + "7e2eb2455399f166d5c9767ff378f8ebea465a0be2d2e3326fe6ed80e5e3050b" + "fb6c6a9dc8731ce4baa4e5b17b131113c79d6f290318095e37e7571a4ba697ab" + "5ea56190131e06d300310064776ba0330907e1cc41acdef4eeaa53964ef30c71" + "023c3cf71af2d1d9e83900ffc80e07ec2442a3dbd50e957686a22f1d8f512364" + "fb71e936f24990a4abcdbef2bea2f98cd77f1d1ca5625942c79347c146dee6e3" + "043eb622f63e627f4ebf20d6056133a4bd0f55dd13dcf429e0e73830969f543c" + "b31d86d9a878ca79d841444359cc0e31c0283fa6dd27b702b7ee05dad12c30f7" + "f84bf1309678efb8da108efcedc423da8587bd127ca082d417c8726f7889fb80" + "326c3fa6fddd507ac7841b2f2e5c8780d486a0d68229ee2957a8ec24e00e4ab4" + "de3fc811a4b5047c2b7920d071e9f2f9b61638dc15fb84cca46cad28e1ef539d" + "bcf249876f2647757b9a5e4f0b2ea6e7aabdf47dae826e9e259428bdb07e5a2a" + "68b98f141f5537be7a590cb3ba15b0bb15824652e8da8f70eb847240058a336a" + "1b6db7f88268aaf89f0b33b905d72c25338b13e61a51873c2d427021a3f29207" + "179ad32f423793f0c090dda025ce41df0e94afbc80ab5eda9b1a268aa2553a99" )); let e = BigUint::from_u64(65537).unwrap(); diff --git a/src/oaep/encrypting_key.rs b/src/oaep/encrypting_key.rs index 1565e467..9a9ae290 100644 --- a/src/oaep/encrypting_key.rs +++ b/src/oaep/encrypting_key.rs @@ -102,9 +102,13 @@ mod tests { Token::Str("label"), Token::None, Token::Str("phantom"), - Token::UnitStruct { name: "PhantomData", }, + Token::UnitStruct { + name: "PhantomData", + }, Token::Str("mg_phantom"), - Token::UnitStruct { name: "PhantomData", }, + Token::UnitStruct { + name: "PhantomData", + }, Token::StructEnd, ]; assert_tokens(&encrypting_key.readable(), &tokens); diff --git a/src/pkcs1v15/encrypting_key.rs b/src/pkcs1v15/encrypting_key.rs index f1ff3fd3..2850f79d 100644 --- a/src/pkcs1v15/encrypting_key.rs +++ b/src/pkcs1v15/encrypting_key.rs @@ -1,9 +1,9 @@ use super::encrypt; use crate::{traits::RandomizedEncryptor, Result, RsaPublicKey}; use alloc::vec::Vec; +use rand_core::CryptoRngCore; #[cfg(feature = "serde")] use serde::{Deserialize, Serialize}; -use rand_core::CryptoRngCore; /// Encryption key for PKCS#1 v1.5 encryption as described in [RFC8017 ยง 7.2]. /// @@ -45,11 +45,16 @@ mod tests { let encrypting_key = EncryptingKey::new(priv_key.to_public_key()); let tokens = [ - Token::Struct { name: "EncryptingKey", len: 1 }, + Token::Struct { + name: "EncryptingKey", + len: 1, + }, Token::Str("inner"), - Token::Str("3024300d06092a864886f70d01010105000313003010020900cc6c6130e35b46bf0203010001"), + Token::Str( + "3024300d06092a864886f70d01010105000313003010020900cc6c6130e35b46bf0203010001", + ), Token::StructEnd, ]; assert_tokens(&encrypting_key.clone().readable(), &tokens); } -} \ No newline at end of file +} diff --git a/src/pkcs1v15/signature.rs b/src/pkcs1v15/signature.rs index d8fd2708..679911fc 100644 --- a/src/pkcs1v15/signature.rs +++ b/src/pkcs1v15/signature.rs @@ -3,10 +3,10 @@ use crate::algorithms::pad::uint_to_be_pad; use ::signature::SignatureEncoding; use alloc::{boxed::Box, string::ToString}; -#[cfg(feature = "serde")] -use serdect::serde::{de, Deserialize, Serialize}; use core::fmt::{Debug, Display, Formatter, LowerHex, UpperHex}; use num_bigint::BigUint; +#[cfg(feature = "serde")] +use serdect::serde::{de, Deserialize, Serialize}; use spki::{ der::{asn1::BitString, Result as DerResult}, SignatureBitStringEncoding, @@ -98,7 +98,10 @@ impl<'de> Deserialize<'de> for Signature { where D: serdect::serde::Deserializer<'de>, { - serdect::slice::deserialize_hex_or_bin_vec(deserializer)?.as_slice().try_into().map_err(de::Error::custom) + serdect::slice::deserialize_hex_or_bin_vec(deserializer)? + .as_slice() + .try_into() + .map_err(de::Error::custom) } } @@ -114,9 +117,7 @@ mod tests { len: 1, }; - let tokens = [ - Token::Str("2a"), - ]; + let tokens = [Token::Str("2a")]; assert_tokens(&signature.readable(), &tokens); } -} \ No newline at end of file +} diff --git a/src/pkcs1v15/signing_key.rs b/src/pkcs1v15/signing_key.rs index ac6fa3e7..8914479d 100644 --- a/src/pkcs1v15/signing_key.rs +++ b/src/pkcs1v15/signing_key.rs @@ -7,7 +7,8 @@ use pkcs8::{ spki::{ der::AnyRef, AlgorithmIdentifierRef, AssociatedAlgorithmIdentifier, SignatureAlgorithmIdentifier, - }, AssociatedOid, EncodePrivateKey, SecretDocument + }, + AssociatedOid, EncodePrivateKey, SecretDocument, }; use rand_core::CryptoRngCore; #[cfg(feature = "serde")] @@ -262,7 +263,10 @@ where impl ZeroizeOnDrop for SigningKey where D: Digest {} -impl PartialEq for SigningKey where D: Digest { +impl PartialEq for SigningKey +where + D: Digest, +{ fn eq(&self, other: &Self) -> bool { self.inner == other.inner && self.prefix == other.prefix } @@ -316,4 +320,4 @@ mod tests { assert_tokens(&signing_key.readable(), &tokens); } -} \ No newline at end of file +} diff --git a/src/pkcs1v15/verifying_key.rs b/src/pkcs1v15/verifying_key.rs index baa77c98..fa23e8f7 100644 --- a/src/pkcs1v15/verifying_key.rs +++ b/src/pkcs1v15/verifying_key.rs @@ -264,9 +264,9 @@ mod tests { let pub_key = priv_key.to_public_key(); let verifying_key = VerifyingKey::::new(pub_key); - let tokens = [ - Token::Str("3024300d06092a864886f70d01010105000313003010020900cc6c6130e35b46bf0203010001") - ]; + let tokens = [Token::Str( + "3024300d06092a864886f70d01010105000313003010020900cc6c6130e35b46bf0203010001", + )]; assert_tokens(&verifying_key.readable(), &tokens); } diff --git a/src/pss.rs b/src/pss.rs index 6d4fae8c..0ae5a7e5 100644 --- a/src/pss.rs +++ b/src/pss.rs @@ -275,14 +275,35 @@ mod test { // -----END RSA PRIVATE KEY----- RsaPrivateKey::from_components( - BigUint::from_str_radix("9353930466774385905609975137998169297361893554149986716853295022578535724979677252958524466350471210367835187480748268864277464700638583474144061408845077", 10).unwrap(), + BigUint::from_str_radix( + "9353930466774385905609975137998169297361893554149986716853295022\ + 5785357249796772529585244663504712103678351874807482688642774647\ + 00638583474144061408845077", + 10, + ) + .unwrap(), BigUint::from_u64(65537).unwrap(), - BigUint::from_str_radix("7266398431328116344057699379749222532279343923819063639497049039389899328538543087657733766554155839834519529439851673014800261285757759040931985506583861", 10).unwrap(), + BigUint::from_str_radix( + "7266398431328116344057699379749222532279343923819063639497049039\ + 3898993285385430876577337665541558398345195294398516730148002612\ + 85757759040931985506583861", + 10, + ) + .unwrap(), vec![ - BigUint::from_str_radix("98920366548084643601728869055592650835572950932266967461790948584315647051443",10).unwrap(), - BigUint::from_str_radix("94560208308847015747498523884063394671606671904944666360068158221458669711639", 10).unwrap() + BigUint::from_str_radix( + "98920366548084643601728869055592650835572950932266967461790948584315647051443", + 10, + ) + .unwrap(), + BigUint::from_str_radix( + "94560208308847015747498523884063394671606671904944666360068158221458669711639", + 10, + ) + .unwrap(), ], - ).unwrap() + ) + .unwrap() } #[test] @@ -565,10 +586,10 @@ mod test { for test in &tests { let sig = signing_key - .sign_prehash_with_rng(&mut rng, &test) + .sign_prehash_with_rng(&mut rng, test) .expect("failed to sign"); verifying_key - .verify_prehash(&test, &sig) + .verify_prehash(test, &sig) .expect("failed to verify"); } } @@ -584,10 +605,10 @@ mod test { for test in &tests { let sig = signing_key - .sign_prehash_with_rng(&mut rng, &test) + .sign_prehash_with_rng(&mut rng, test) .expect("failed to sign"); verifying_key - .verify_prehash(&test, &sig) + .verify_prehash(test, &sig) .expect("failed to verify"); } } diff --git a/src/pss/blinded_signing_key.rs b/src/pss/blinded_signing_key.rs index 5d46d5a8..9f990125 100644 --- a/src/pss/blinded_signing_key.rs +++ b/src/pss/blinded_signing_key.rs @@ -17,8 +17,8 @@ use signature::{ use zeroize::ZeroizeOnDrop; #[cfg(feature = "serde")] use { - serdect::serde::{de, ser, Deserialize, Serialize}, pkcs8::DecodePrivateKey, + serdect::serde::{de, ser, Deserialize, Serialize}, }; /// Signing key for producing "blinded" RSASSA-PSS signatures as described in /// [draft-irtf-cfrg-rsa-blind-signatures](https://datatracker.ietf.org/doc/draft-irtf-cfrg-rsa-blind-signatures/). diff --git a/src/pss/signature.rs b/src/pss/signature.rs index d7d32ae8..ea3d1ce9 100644 --- a/src/pss/signature.rs +++ b/src/pss/signature.rs @@ -111,9 +111,7 @@ mod tests { len: 1, }; - let tokens = [ - Token::Str("2a"), - ]; + let tokens = [Token::Str("2a")]; assert_tokens(&signature.readable(), &tokens); } -} \ No newline at end of file +} diff --git a/src/pss/verifying_key.rs b/src/pss/verifying_key.rs index b1ea02e6..2fd62d37 100644 --- a/src/pss/verifying_key.rs +++ b/src/pss/verifying_key.rs @@ -170,7 +170,7 @@ where type Error = pkcs8::spki::Error; fn try_from(spki: pkcs8::SubjectPublicKeyInfoRef<'_>) -> pkcs8::spki::Result { - match spki.algorithm.oid { + match spki.algorithm.oid { ID_RSASSA_PSS | pkcs1::ALGORITHM_OID => (), _ => { return Err(spki::Error::OidUnknown { @@ -235,9 +235,9 @@ mod tests { let pub_key = priv_key.to_public_key(); let verifying_key = VerifyingKey::::new(pub_key); - let tokens = [ - Token::Str("3024300d06092a864886f70d01010105000313003010020900cc6c6130e35b46bf0203010001") - ]; + let tokens = [Token::Str( + "3024300d06092a864886f70d01010105000313003010020900cc6c6130e35b46bf0203010001", + )]; assert_tokens(&verifying_key.readable(), &tokens); } diff --git a/tests/pkcs1.rs b/tests/pkcs1.rs index eff97f6d..6790e137 100644 --- a/tests/pkcs1.rs +++ b/tests/pkcs1.rs @@ -50,11 +50,51 @@ fn decode_rsa2048_priv_der() { // Extracted using: // $ openssl asn1parse -in tests/examples/pkcs1/rsa2048-priv.pem - assert_eq!(&key.n().to_bytes_be(), &hex!("B6C42C515F10A6AAF282C63EDBE24243A170F3FA2633BD4833637F47CA4F6F36E03A5D29EFC3191AC80F390D874B39E30F414FCEC1FCA0ED81E547EDC2CD382C76F61C9018973DB9FA537972A7C701F6B77E0982DFC15FC01927EE5E7CD94B4F599FF07013A7C8281BDF22DCBC9AD7CABB7C4311C982F58EDB7213AD4558B332266D743AED8192D1884CADB8B14739A8DADA66DC970806D9C7AC450CB13D0D7C575FB198534FC61BC41BC0F0574E0E0130C7BBBFBDFDC9F6A6E2E3E2AFF1CBEAC89BA57884528D55CFB08327A1E8C89F4E003CF2888E933241D9D695BCBBACDC90B44E3E095FA37058EA25B13F5E295CBEAC6DE838AB8C50AF61E298975B872F")); + assert_eq!( + &key.n().to_bytes_be(), + &hex!( + "B6C42C515F10A6AAF282C63EDBE24243A170F3FA2633BD4833637F47CA4F6F36" + "E03A5D29EFC3191AC80F390D874B39E30F414FCEC1FCA0ED81E547EDC2CD382C" + "76F61C9018973DB9FA537972A7C701F6B77E0982DFC15FC01927EE5E7CD94B4F" + "599FF07013A7C8281BDF22DCBC9AD7CABB7C4311C982F58EDB7213AD4558B332" + "266D743AED8192D1884CADB8B14739A8DADA66DC970806D9C7AC450CB13D0D7C" + "575FB198534FC61BC41BC0F0574E0E0130C7BBBFBDFDC9F6A6E2E3E2AFF1CBEA" + "C89BA57884528D55CFB08327A1E8C89F4E003CF2888E933241D9D695BCBBACDC" + "90B44E3E095FA37058EA25B13F5E295CBEAC6DE838AB8C50AF61E298975B872F" + ) + ); assert_eq!(&key.e().to_bytes_be(), &hex!("010001")); - assert_eq!(&key.d().to_bytes_be(), &hex!("7ECC8362C0EDB0741164215E22F74AB9D91BA06900700CF63690E5114D8EE6BDCFBB2E3F9614692A677A083F168A5E52E5968E6407B9D97C6E0E4064F82DA0B758A14F17B9B7D41F5F48E28D6551704F56E69E7AA9FA630FC76428C06D25E455DCFC55B7AC2B4F76643FDED3FE15FF78ABB27E65ACC4AAD0BDF6DB27EF60A6910C5C4A085ED43275AB19C1D997A32C6EFFCE7DF2D1935F6E601EEDE161A12B5CC27CA21F81D2C99C3D1EA08E90E3053AB09BEFA724DEF0D0C3A3C1E9740C0D9F76126A149EC0AA7D8078205484254D951DB07C4CF91FB6454C096588FD5924DBABEB359CA2025268D004F9D66EB3D6F7ADC1139BAD40F16DDE639E11647376C1")); - assert_eq!(&key.primes()[0].to_bytes_be(), &hex!("DCC061242D4E92AFAEE72AC513CA65B9F77036F9BD7E0E6E61461A7EF7654225EC153C7E5C31A6157A6E5A13FF6E178E8758C1CB33D9D6BBE3179EF18998E422ECDCBED78F4ECFDBE5F4FCD8AEC2C9D0DC86473CA9BD16D9D238D21FB5DDEFBEB143CA61D0BD6AA8D91F33A097790E9640DBC91085DC5F26343BA3138F6B2D67")); - assert_eq!(&key.primes()[1].to_bytes_be(), &hex!("D3F314757E40E954836F92BE24236AF2F0DA04A34653C180AF67E960086D93FDE65CB23EFD9D09374762F5981E361849AF68CDD75394FF6A4E06EB69B209E4228DB2DFA70E40F7F9750A528176647B788D0E5777A2CB8B22E3CD267FF70B4F3B02D3AAFB0E18C590A564B03188B0AA5FC48156B07622214243BD1227EFA7F2F9")); + assert_eq!( + &key.d().to_bytes_be(), + &hex!( + "7ECC8362C0EDB0741164215E22F74AB9D91BA06900700CF63690E5114D8EE6BD" + "CFBB2E3F9614692A677A083F168A5E52E5968E6407B9D97C6E0E4064F82DA0B7" + "58A14F17B9B7D41F5F48E28D6551704F56E69E7AA9FA630FC76428C06D25E455" + "DCFC55B7AC2B4F76643FDED3FE15FF78ABB27E65ACC4AAD0BDF6DB27EF60A691" + "0C5C4A085ED43275AB19C1D997A32C6EFFCE7DF2D1935F6E601EEDE161A12B5C" + "C27CA21F81D2C99C3D1EA08E90E3053AB09BEFA724DEF0D0C3A3C1E9740C0D9F" + "76126A149EC0AA7D8078205484254D951DB07C4CF91FB6454C096588FD5924DB" + "ABEB359CA2025268D004F9D66EB3D6F7ADC1139BAD40F16DDE639E11647376C1" + ) + ); + assert_eq!( + &key.primes()[0].to_bytes_be(), + &hex!( + "DCC061242D4E92AFAEE72AC513CA65B9F77036F9BD7E0E6E61461A7EF7654225" + "EC153C7E5C31A6157A6E5A13FF6E178E8758C1CB33D9D6BBE3179EF18998E422" + "ECDCBED78F4ECFDBE5F4FCD8AEC2C9D0DC86473CA9BD16D9D238D21FB5DDEFBE" + "B143CA61D0BD6AA8D91F33A097790E9640DBC91085DC5F26343BA3138F6B2D67" + ) + ); + assert_eq!( + &key.primes()[1].to_bytes_be(), + &hex!( + "D3F314757E40E954836F92BE24236AF2F0DA04A34653C180AF67E960086D93FD" + "E65CB23EFD9D09374762F5981E361849AF68CDD75394FF6A4E06EB69B209E422" + "8DB2DFA70E40F7F9750A528176647B788D0E5777A2CB8B22E3CD267FF70B4F3B" + "02D3AAFB0E18C590A564B03188B0AA5FC48156B07622214243BD1227EFA7F2F9" + ) + ); } #[test] @@ -63,11 +103,75 @@ fn decode_rsa4096_priv_der() { // Extracted using: // $ openssl asn1parse -in tests/examples/pkcs1/rsa4096-priv.pem - assert_eq!(&key.n().to_bytes_be(), &hex!("A7A74572811EA2617E49E85BD730DDE30F103F7D88EE3F765E540D3DD993BBB0BA140002859D0B40897436637F58B828EA74DF8321634077F99D4AA2D54CA375852EF597661D3713CE1EF3B4FD6A8E220238E467668A2C7EE3861D2212AE6A1EBDDFA88B62DF10F6BCF79EFF4AC298FB2563DF1B8764381AF9B1FB0CCD085E026B0AD9F6721A235177D0396B48754AD4A75242250A873BF2F6E7EE3C75DD613E365BA4F3210A6CC66B90A2FA3F762CA6884087B6BF8161EB144819F0F572F21F6C8E273E70D45A365B8B2819CE734613CC23B01329A17901F17078403861F54C52A051E2A58C75C2D9D80091BB9808A106C1F7ECB4034E15058BEEC725C5F919D62EAA234B62628D346C60BB919E70851DAB38571E6F0ED7634129F994EA368FEE7373DFDEC04445EBCA47FA20ED1540A860C948BABC98DA591CA1DE2E2E25540EF9B7CB353F60213B814A45D359EFA9B811EEFF08C65993BF8A85C2BFEAAA7ED5E6B43E18AE604464CE5F96150136E7D09F8B24FAD43D7870118CFA7BC24875506EBBC321B977E0861AEA50128620121F0B394A9CDD0A42411A1350C0770D975D71B00A90436240C967A0C3A5C20A0F6DE77F3F2CAFDA94ED0143C1F6E34F73E0CAC279EEEB7C637723A2B026C82802E1A4AEBAA8846DF98E7919498773E0D4F319956F4DE3AAD00EFB9A147D66B3AC1A01D35B2CFB48D400B0E7A80DC97551")); + assert_eq!( + &key.n().to_bytes_be(), + &hex!( + "A7A74572811EA2617E49E85BD730DDE30F103F7D88EE3F765E540D3DD993BBB0" + "BA140002859D0B40897436637F58B828EA74DF8321634077F99D4AA2D54CA375" + "852EF597661D3713CE1EF3B4FD6A8E220238E467668A2C7EE3861D2212AE6A1E" + "BDDFA88B62DF10F6BCF79EFF4AC298FB2563DF1B8764381AF9B1FB0CCD085E02" + "6B0AD9F6721A235177D0396B48754AD4A75242250A873BF2F6E7EE3C75DD613E" + "365BA4F3210A6CC66B90A2FA3F762CA6884087B6BF8161EB144819F0F572F21F" + "6C8E273E70D45A365B8B2819CE734613CC23B01329A17901F17078403861F54C" + "52A051E2A58C75C2D9D80091BB9808A106C1F7ECB4034E15058BEEC725C5F919" + "D62EAA234B62628D346C60BB919E70851DAB38571E6F0ED7634129F994EA368F" + "EE7373DFDEC04445EBCA47FA20ED1540A860C948BABC98DA591CA1DE2E2E2554" + "0EF9B7CB353F60213B814A45D359EFA9B811EEFF08C65993BF8A85C2BFEAAA7E" + "D5E6B43E18AE604464CE5F96150136E7D09F8B24FAD43D7870118CFA7BC24875" + "506EBBC321B977E0861AEA50128620121F0B394A9CDD0A42411A1350C0770D97" + "5D71B00A90436240C967A0C3A5C20A0F6DE77F3F2CAFDA94ED0143C1F6E34F73" + "E0CAC279EEEB7C637723A2B026C82802E1A4AEBAA8846DF98E7919498773E0D4" + "F319956F4DE3AAD00EFB9A147D66B3AC1A01D35B2CFB48D400B0E7A80DC97551" + ) + ); assert_eq!(&key.e().to_bytes_be(), &hex!("010001")); - assert_eq!(&key.d().to_bytes_be(), &hex!("9FE3097B2322B90FAB6606C017A095EBE640C39C100BCEE02F238FA14DAFF38E9E57568F1127ED4436126B904631B127EC395BB3EE127EB82C88D2562A7FB55FED8D1450B7E4E2D2F37F5742636FCC6F289963522D5B5706082CADFA01C0EE99B4D0E9274D3A992E06974CBE01694686356962AC1959FD9BD447E5B9968C0543DF1BF134742AF345CDB2FA1F9371B0D4CF61C68D16D653D8E999D4FD3A16CF978A35AA40E860CDCE09655DD8B4CF19D4141B1E92AD5E51A8E4A5C27FA745611D90E49D0E9282222AB6F126643E1C77578816FCE3B98F321D2549F294A470DF8453446BF36F985DF25ED8FDE9FDF3073FB27727DF48E9E1FC7056BC78965090B7850126406462C8253051EF84E34EE3C3CEB8F96C658C38BE45558D2F64E29D223350555FC1EFA28EC1F4AFB5BA4080F09A86CDC3538C1AD7C972E6D7A3612E6845BA9AFBDF19F09060D1A779DE9635E2D2F8E0C510BA24C6C44B30C9BDFAF85BE917AEC5D43AFAB1AA3ADD33CC83DA93CAC69218F6A36EB47F199D5424C95FD9ED7B1E8BE2AEAA6433B227241316C20EE792650CEB48BFD634446B19D286B4EA1722498DA1A36973210EC3824751A5808D9AAEF59C449E19A5077CFECA126BD9A8DD4996561D4E27B3609FF82C5B1B21E627845D44961B33B875D5C4FA9FF357EF6BE3364969E1337C91B29A07B9A913CDE40CE2D5530C900E73751685E65431")); - assert_eq!(&key.primes()[0].to_bytes_be(), &hex!("D0213A79425B665B719118448893EC3275600F63DBF85B77F4E8E99EF302F6E82596048F6DCA772DE6BBF1124DB84B0AFE61B03A8604AB0079ED53F3304797AD01B38C44FE27A5A45E378483A804B56A4A967F48F01A866E721E67E4C9A1048AF68927FAA43D6A85D93E7BF7074DBA797563FCABE12309B76653C6DB614DC231CC556D9F25AC4841A02D31CDF3015B212307F9D0C79FEB5D3956CE53CC8FA1651BE60761F19F74672489EAF9F215409F39956E77A82183F1F72BB2FEDDF1B9FBFC4AD89EA445809DDBD5BD595277990C0BE9366FBB2ECF7B057CC1C3DC8FB77BF8456D07BBC95B3C1815F48E62B81468C3D4D9D96C0F48DAB04993BE8D91EDE5")); - assert_eq!(&key.primes()[1].to_bytes_be(), &hex!("CE36C6810522ABE5D6465F36EB137DA3B9EA4A5F1D27C6614729EB8E5E2E5CB88E3EF1A473A21944B66557B3DC2CE462E4BF3446CB4990037E5672B1705CBAE81B65BAF967A266DC18EFE80F4DBBFE1A59063205CE2943CADF421CCE74AF7063FD1A83AF3C39AF84525F59BDC1FF54815F52AFD1E8D4862B2C3654F6CFA83DC08E2A9D52B9F833C646AF7694467DFC5F7D7AD7B441895FCB7FFBED526324B0154A15823F5107C89548EDDCB61DA5308C6CC834D4A0C16DFA6CA1D67B61A65677EB1719CD125D0EF0DB8802FB76CFC17577BCB2510AE294E1BF8A9173A2B85C16A6B508C98F2D770B7F3DE48D9E720C53E263680B57E7109410015745570652FD")); + assert_eq!( + &key.d().to_bytes_be(), + &hex!( + "9FE3097B2322B90FAB6606C017A095EBE640C39C100BCEE02F238FA14DAFF38E" + "9E57568F1127ED4436126B904631B127EC395BB3EE127EB82C88D2562A7FB55F" + "ED8D1450B7E4E2D2F37F5742636FCC6F289963522D5B5706082CADFA01C0EE99" + "B4D0E9274D3A992E06974CBE01694686356962AC1959FD9BD447E5B9968C0543" + "DF1BF134742AF345CDB2FA1F9371B0D4CF61C68D16D653D8E999D4FD3A16CF97" + "8A35AA40E860CDCE09655DD8B4CF19D4141B1E92AD5E51A8E4A5C27FA745611D" + "90E49D0E9282222AB6F126643E1C77578816FCE3B98F321D2549F294A470DF84" + "53446BF36F985DF25ED8FDE9FDF3073FB27727DF48E9E1FC7056BC78965090B7" + "850126406462C8253051EF84E34EE3C3CEB8F96C658C38BE45558D2F64E29D22" + "3350555FC1EFA28EC1F4AFB5BA4080F09A86CDC3538C1AD7C972E6D7A3612E68" + "45BA9AFBDF19F09060D1A779DE9635E2D2F8E0C510BA24C6C44B30C9BDFAF85B" + "E917AEC5D43AFAB1AA3ADD33CC83DA93CAC69218F6A36EB47F199D5424C95FD9" + "ED7B1E8BE2AEAA6433B227241316C20EE792650CEB48BFD634446B19D286B4EA" + "1722498DA1A36973210EC3824751A5808D9AAEF59C449E19A5077CFECA126BD9" + "A8DD4996561D4E27B3609FF82C5B1B21E627845D44961B33B875D5C4FA9FF357" + "EF6BE3364969E1337C91B29A07B9A913CDE40CE2D5530C900E73751685E65431" + ) + ); + assert_eq!( + &key.primes()[0].to_bytes_be(), + &hex!( + "D0213A79425B665B719118448893EC3275600F63DBF85B77F4E8E99EF302F6E8" + "2596048F6DCA772DE6BBF1124DB84B0AFE61B03A8604AB0079ED53F3304797AD" + "01B38C44FE27A5A45E378483A804B56A4A967F48F01A866E721E67E4C9A1048A" + "F68927FAA43D6A85D93E7BF7074DBA797563FCABE12309B76653C6DB614DC231" + "CC556D9F25AC4841A02D31CDF3015B212307F9D0C79FEB5D3956CE53CC8FA165" + "1BE60761F19F74672489EAF9F215409F39956E77A82183F1F72BB2FEDDF1B9FB" + "FC4AD89EA445809DDBD5BD595277990C0BE9366FBB2ECF7B057CC1C3DC8FB77B" + "F8456D07BBC95B3C1815F48E62B81468C3D4D9D96C0F48DAB04993BE8D91EDE5" + ) + ); + assert_eq!( + &key.primes()[1].to_bytes_be(), + &hex!( + "CE36C6810522ABE5D6465F36EB137DA3B9EA4A5F1D27C6614729EB8E5E2E5CB8" + "8E3EF1A473A21944B66557B3DC2CE462E4BF3446CB4990037E5672B1705CBAE8" + "1B65BAF967A266DC18EFE80F4DBBFE1A59063205CE2943CADF421CCE74AF7063" + "FD1A83AF3C39AF84525F59BDC1FF54815F52AFD1E8D4862B2C3654F6CFA83DC0" + "8E2A9D52B9F833C646AF7694467DFC5F7D7AD7B441895FCB7FFBED526324B015" + "4A15823F5107C89548EDDCB61DA5308C6CC834D4A0C16DFA6CA1D67B61A65677" + "EB1719CD125D0EF0DB8802FB76CFC17577BCB2510AE294E1BF8A9173A2B85C16" + "A6B508C98F2D770B7F3DE48D9E720C53E263680B57E7109410015745570652FD" + ) + ); } #[test] @@ -76,7 +180,20 @@ fn decode_rsa2048_pub_der() { // Extracted using: // $ openssl asn1parse -in tests/examples/pkcs1/rsa2048-pub.pem - assert_eq!(&key.n().to_bytes_be(), &hex!("B6C42C515F10A6AAF282C63EDBE24243A170F3FA2633BD4833637F47CA4F6F36E03A5D29EFC3191AC80F390D874B39E30F414FCEC1FCA0ED81E547EDC2CD382C76F61C9018973DB9FA537972A7C701F6B77E0982DFC15FC01927EE5E7CD94B4F599FF07013A7C8281BDF22DCBC9AD7CABB7C4311C982F58EDB7213AD4558B332266D743AED8192D1884CADB8B14739A8DADA66DC970806D9C7AC450CB13D0D7C575FB198534FC61BC41BC0F0574E0E0130C7BBBFBDFDC9F6A6E2E3E2AFF1CBEAC89BA57884528D55CFB08327A1E8C89F4E003CF2888E933241D9D695BCBBACDC90B44E3E095FA37058EA25B13F5E295CBEAC6DE838AB8C50AF61E298975B872F")); + assert_eq!( + &key.n().to_bytes_be(), + &hex!( + "B6C42C515F10A6AAF282C63EDBE24243A170F3FA2633BD4833637F47CA4F6F36" + "E03A5D29EFC3191AC80F390D874B39E30F414FCEC1FCA0ED81E547EDC2CD382C" + "76F61C9018973DB9FA537972A7C701F6B77E0982DFC15FC01927EE5E7CD94B4F" + "599FF07013A7C8281BDF22DCBC9AD7CABB7C4311C982F58EDB7213AD4558B332" + "266D743AED8192D1884CADB8B14739A8DADA66DC970806D9C7AC450CB13D0D7C" + "575FB198534FC61BC41BC0F0574E0E0130C7BBBFBDFDC9F6A6E2E3E2AFF1CBEA" + "C89BA57884528D55CFB08327A1E8C89F4E003CF2888E933241D9D695BCBBACDC" + "90B44E3E095FA37058EA25B13F5E295CBEAC6DE838AB8C50AF61E298975B872F" + + ) + ); assert_eq!(&key.e().to_bytes_be(), &hex!("010001")); } @@ -86,7 +203,27 @@ fn decode_rsa4096_pub_der() { // Extracted using: // $ openssl asn1parse -in tests/examples/pkcs1/rsa4096-pub.pem - assert_eq!(&key.n().to_bytes_be(), &hex!("A7A74572811EA2617E49E85BD730DDE30F103F7D88EE3F765E540D3DD993BBB0BA140002859D0B40897436637F58B828EA74DF8321634077F99D4AA2D54CA375852EF597661D3713CE1EF3B4FD6A8E220238E467668A2C7EE3861D2212AE6A1EBDDFA88B62DF10F6BCF79EFF4AC298FB2563DF1B8764381AF9B1FB0CCD085E026B0AD9F6721A235177D0396B48754AD4A75242250A873BF2F6E7EE3C75DD613E365BA4F3210A6CC66B90A2FA3F762CA6884087B6BF8161EB144819F0F572F21F6C8E273E70D45A365B8B2819CE734613CC23B01329A17901F17078403861F54C52A051E2A58C75C2D9D80091BB9808A106C1F7ECB4034E15058BEEC725C5F919D62EAA234B62628D346C60BB919E70851DAB38571E6F0ED7634129F994EA368FEE7373DFDEC04445EBCA47FA20ED1540A860C948BABC98DA591CA1DE2E2E25540EF9B7CB353F60213B814A45D359EFA9B811EEFF08C65993BF8A85C2BFEAAA7ED5E6B43E18AE604464CE5F96150136E7D09F8B24FAD43D7870118CFA7BC24875506EBBC321B977E0861AEA50128620121F0B394A9CDD0A42411A1350C0770D975D71B00A90436240C967A0C3A5C20A0F6DE77F3F2CAFDA94ED0143C1F6E34F73E0CAC279EEEB7C637723A2B026C82802E1A4AEBAA8846DF98E7919498773E0D4F319956F4DE3AAD00EFB9A147D66B3AC1A01D35B2CFB48D400B0E7A80DC97551")); + assert_eq!( + &key.n().to_bytes_be(), + &hex!( + "A7A74572811EA2617E49E85BD730DDE30F103F7D88EE3F765E540D3DD993BBB0" + "BA140002859D0B40897436637F58B828EA74DF8321634077F99D4AA2D54CA375" + "852EF597661D3713CE1EF3B4FD6A8E220238E467668A2C7EE3861D2212AE6A1E" + "BDDFA88B62DF10F6BCF79EFF4AC298FB2563DF1B8764381AF9B1FB0CCD085E02" + "6B0AD9F6721A235177D0396B48754AD4A75242250A873BF2F6E7EE3C75DD613E" + "365BA4F3210A6CC66B90A2FA3F762CA6884087B6BF8161EB144819F0F572F21F" + "6C8E273E70D45A365B8B2819CE734613CC23B01329A17901F17078403861F54C" + "52A051E2A58C75C2D9D80091BB9808A106C1F7ECB4034E15058BEEC725C5F919" + "D62EAA234B62628D346C60BB919E70851DAB38571E6F0ED7634129F994EA368F" + "EE7373DFDEC04445EBCA47FA20ED1540A860C948BABC98DA591CA1DE2E2E2554" + "0EF9B7CB353F60213B814A45D359EFA9B811EEFF08C65993BF8A85C2BFEAAA7E" + "D5E6B43E18AE604464CE5F96150136E7D09F8B24FAD43D7870118CFA7BC24875" + "506EBBC321B977E0861AEA50128620121F0B394A9CDD0A42411A1350C0770D97" + "5D71B00A90436240C967A0C3A5C20A0F6DE77F3F2CAFDA94ED0143C1F6E34F73" + "E0CAC279EEEB7C637723A2B026C82802E1A4AEBAA8846DF98E7919498773E0D4" + "F319956F4DE3AAD00EFB9A147D66B3AC1A01D35B2CFB48D400B0E7A80DC97551" + ) + ); assert_eq!(&key.e().to_bytes_be(), &hex!("010001")); } @@ -125,11 +262,53 @@ fn decode_rsa2048_priv_pem() { // Extracted using: // $ openssl asn1parse -in tests/examples/pkcs1/rsa2048-priv.pem - assert_eq!(&key.n().to_bytes_be(), &hex!("B6C42C515F10A6AAF282C63EDBE24243A170F3FA2633BD4833637F47CA4F6F36E03A5D29EFC3191AC80F390D874B39E30F414FCEC1FCA0ED81E547EDC2CD382C76F61C9018973DB9FA537972A7C701F6B77E0982DFC15FC01927EE5E7CD94B4F599FF07013A7C8281BDF22DCBC9AD7CABB7C4311C982F58EDB7213AD4558B332266D743AED8192D1884CADB8B14739A8DADA66DC970806D9C7AC450CB13D0D7C575FB198534FC61BC41BC0F0574E0E0130C7BBBFBDFDC9F6A6E2E3E2AFF1CBEAC89BA57884528D55CFB08327A1E8C89F4E003CF2888E933241D9D695BCBBACDC90B44E3E095FA37058EA25B13F5E295CBEAC6DE838AB8C50AF61E298975B872F")); + assert_eq!( + &key.n().to_bytes_be(), + &hex!( + "B6C42C515F10A6AAF282C63EDBE24243A170F3FA2633BD4833637F47CA4F6F36" + "E03A5D29EFC3191AC80F390D874B39E30F414FCEC1FCA0ED81E547EDC2CD382C" + "76F61C9018973DB9FA537972A7C701F6B77E0982DFC15FC01927EE5E7CD94B4F" + "599FF07013A7C8281BDF22DCBC9AD7CABB7C4311C982F58EDB7213AD4558B332" + "266D743AED8192D1884CADB8B14739A8DADA66DC970806D9C7AC450CB13D0D7C" + "575FB198534FC61BC41BC0F0574E0E0130C7BBBFBDFDC9F6A6E2E3E2AFF1CBEA" + "C89BA57884528D55CFB08327A1E8C89F4E003CF2888E933241D9D695BCBBACDC" + "90B44E3E095FA37058EA25B13F5E295CBEAC6DE838AB8C50AF61E298975B872F" + ) + ); assert_eq!(&key.e().to_bytes_be(), &hex!("010001")); - assert_eq!(&key.d().to_bytes_be(), &hex!("7ECC8362C0EDB0741164215E22F74AB9D91BA06900700CF63690E5114D8EE6BDCFBB2E3F9614692A677A083F168A5E52E5968E6407B9D97C6E0E4064F82DA0B758A14F17B9B7D41F5F48E28D6551704F56E69E7AA9FA630FC76428C06D25E455DCFC55B7AC2B4F76643FDED3FE15FF78ABB27E65ACC4AAD0BDF6DB27EF60A6910C5C4A085ED43275AB19C1D997A32C6EFFCE7DF2D1935F6E601EEDE161A12B5CC27CA21F81D2C99C3D1EA08E90E3053AB09BEFA724DEF0D0C3A3C1E9740C0D9F76126A149EC0AA7D8078205484254D951DB07C4CF91FB6454C096588FD5924DBABEB359CA2025268D004F9D66EB3D6F7ADC1139BAD40F16DDE639E11647376C1")); - assert_eq!(&key.primes()[0].to_bytes_be(), &hex!("DCC061242D4E92AFAEE72AC513CA65B9F77036F9BD7E0E6E61461A7EF7654225EC153C7E5C31A6157A6E5A13FF6E178E8758C1CB33D9D6BBE3179EF18998E422ECDCBED78F4ECFDBE5F4FCD8AEC2C9D0DC86473CA9BD16D9D238D21FB5DDEFBEB143CA61D0BD6AA8D91F33A097790E9640DBC91085DC5F26343BA3138F6B2D67")); - assert_eq!(&key.primes()[1].to_bytes_be(), &hex!("D3F314757E40E954836F92BE24236AF2F0DA04A34653C180AF67E960086D93FDE65CB23EFD9D09374762F5981E361849AF68CDD75394FF6A4E06EB69B209E4228DB2DFA70E40F7F9750A528176647B788D0E5777A2CB8B22E3CD267FF70B4F3B02D3AAFB0E18C590A564B03188B0AA5FC48156B07622214243BD1227EFA7F2F9")); + assert_eq!( + &key.d().to_bytes_be(), + &hex!( + "7ECC8362C0EDB0741164215E22F74AB9D91BA06900700CF63690E5114D8EE6BD" + "CFBB2E3F9614692A677A083F168A5E52E5968E6407B9D97C6E0E4064F82DA0B7" + "58A14F17B9B7D41F5F48E28D6551704F56E69E7AA9FA630FC76428C06D25E455" + "DCFC55B7AC2B4F76643FDED3FE15FF78ABB27E65ACC4AAD0BDF6DB27EF60A691" + "0C5C4A085ED43275AB19C1D997A32C6EFFCE7DF2D1935F6E601EEDE161A12B5C" + "C27CA21F81D2C99C3D1EA08E90E3053AB09BEFA724DEF0D0C3A3C1E9740C0D9F" + "76126A149EC0AA7D8078205484254D951DB07C4CF91FB6454C096588FD5924DB" + "ABEB359CA2025268D004F9D66EB3D6F7ADC1139BAD40F16DDE639E11647376C1" + ) + ); + assert_eq!( + &key.primes()[0].to_bytes_be(), + &hex!( + "DCC061242D4E92AFAEE72AC513CA65B9F77036F9BD7E0E6E61461A7EF7654225" + "EC153C7E5C31A6157A6E5A13FF6E178E8758C1CB33D9D6BBE3179EF18998E422" + "ECDCBED78F4ECFDBE5F4FCD8AEC2C9D0DC86473CA9BD16D9D238D21FB5DDEFBE" + "B143CA61D0BD6AA8D91F33A097790E9640DBC91085DC5F26343BA3138F6B2D67" + + ) + ); + assert_eq!( + &key.primes()[1].to_bytes_be(), + &hex!( + "D3F314757E40E954836F92BE24236AF2F0DA04A34653C180AF67E960086D93FD" + "E65CB23EFD9D09374762F5981E361849AF68CDD75394FF6A4E06EB69B209E422" + "8DB2DFA70E40F7F9750A528176647B788D0E5777A2CB8B22E3CD267FF70B4F3B" + "02D3AAFB0E18C590A564B03188B0AA5FC48156B07622214243BD1227EFA7F2F9" + + ) + ); } #[test] @@ -139,11 +318,76 @@ fn decode_rsa4096_priv_pem() { // Extracted using: // $ openssl asn1parse -in tests/examples/pkcs1/rsa4096-priv.pem - assert_eq!(&key.n().to_bytes_be(), &hex!("A7A74572811EA2617E49E85BD730DDE30F103F7D88EE3F765E540D3DD993BBB0BA140002859D0B40897436637F58B828EA74DF8321634077F99D4AA2D54CA375852EF597661D3713CE1EF3B4FD6A8E220238E467668A2C7EE3861D2212AE6A1EBDDFA88B62DF10F6BCF79EFF4AC298FB2563DF1B8764381AF9B1FB0CCD085E026B0AD9F6721A235177D0396B48754AD4A75242250A873BF2F6E7EE3C75DD613E365BA4F3210A6CC66B90A2FA3F762CA6884087B6BF8161EB144819F0F572F21F6C8E273E70D45A365B8B2819CE734613CC23B01329A17901F17078403861F54C52A051E2A58C75C2D9D80091BB9808A106C1F7ECB4034E15058BEEC725C5F919D62EAA234B62628D346C60BB919E70851DAB38571E6F0ED7634129F994EA368FEE7373DFDEC04445EBCA47FA20ED1540A860C948BABC98DA591CA1DE2E2E25540EF9B7CB353F60213B814A45D359EFA9B811EEFF08C65993BF8A85C2BFEAAA7ED5E6B43E18AE604464CE5F96150136E7D09F8B24FAD43D7870118CFA7BC24875506EBBC321B977E0861AEA50128620121F0B394A9CDD0A42411A1350C0770D975D71B00A90436240C967A0C3A5C20A0F6DE77F3F2CAFDA94ED0143C1F6E34F73E0CAC279EEEB7C637723A2B026C82802E1A4AEBAA8846DF98E7919498773E0D4F319956F4DE3AAD00EFB9A147D66B3AC1A01D35B2CFB48D400B0E7A80DC97551")); + assert_eq!( + &key.n().to_bytes_be(), + &hex!( + "A7A74572811EA2617E49E85BD730DDE30F103F7D88EE3F765E540D3DD993BBB0" + "BA140002859D0B40897436637F58B828EA74DF8321634077F99D4AA2D54CA375" + "852EF597661D3713CE1EF3B4FD6A8E220238E467668A2C7EE3861D2212AE6A1E" + "BDDFA88B62DF10F6BCF79EFF4AC298FB2563DF1B8764381AF9B1FB0CCD085E02" + "6B0AD9F6721A235177D0396B48754AD4A75242250A873BF2F6E7EE3C75DD613E" + "365BA4F3210A6CC66B90A2FA3F762CA6884087B6BF8161EB144819F0F572F21F" + "6C8E273E70D45A365B8B2819CE734613CC23B01329A17901F17078403861F54C" + "52A051E2A58C75C2D9D80091BB9808A106C1F7ECB4034E15058BEEC725C5F919" + "D62EAA234B62628D346C60BB919E70851DAB38571E6F0ED7634129F994EA368F" + "EE7373DFDEC04445EBCA47FA20ED1540A860C948BABC98DA591CA1DE2E2E2554" + "0EF9B7CB353F60213B814A45D359EFA9B811EEFF08C65993BF8A85C2BFEAAA7E" + "D5E6B43E18AE604464CE5F96150136E7D09F8B24FAD43D7870118CFA7BC24875" + "506EBBC321B977E0861AEA50128620121F0B394A9CDD0A42411A1350C0770D97" + "5D71B00A90436240C967A0C3A5C20A0F6DE77F3F2CAFDA94ED0143C1F6E34F73" + "E0CAC279EEEB7C637723A2B026C82802E1A4AEBAA8846DF98E7919498773E0D4" + "F319956F4DE3AAD00EFB9A147D66B3AC1A01D35B2CFB48D400B0E7A80DC97551" + + ) + ); assert_eq!(&key.e().to_bytes_be(), &hex!("010001")); - assert_eq!(&key.d().to_bytes_be(), &hex!("9FE3097B2322B90FAB6606C017A095EBE640C39C100BCEE02F238FA14DAFF38E9E57568F1127ED4436126B904631B127EC395BB3EE127EB82C88D2562A7FB55FED8D1450B7E4E2D2F37F5742636FCC6F289963522D5B5706082CADFA01C0EE99B4D0E9274D3A992E06974CBE01694686356962AC1959FD9BD447E5B9968C0543DF1BF134742AF345CDB2FA1F9371B0D4CF61C68D16D653D8E999D4FD3A16CF978A35AA40E860CDCE09655DD8B4CF19D4141B1E92AD5E51A8E4A5C27FA745611D90E49D0E9282222AB6F126643E1C77578816FCE3B98F321D2549F294A470DF8453446BF36F985DF25ED8FDE9FDF3073FB27727DF48E9E1FC7056BC78965090B7850126406462C8253051EF84E34EE3C3CEB8F96C658C38BE45558D2F64E29D223350555FC1EFA28EC1F4AFB5BA4080F09A86CDC3538C1AD7C972E6D7A3612E6845BA9AFBDF19F09060D1A779DE9635E2D2F8E0C510BA24C6C44B30C9BDFAF85BE917AEC5D43AFAB1AA3ADD33CC83DA93CAC69218F6A36EB47F199D5424C95FD9ED7B1E8BE2AEAA6433B227241316C20EE792650CEB48BFD634446B19D286B4EA1722498DA1A36973210EC3824751A5808D9AAEF59C449E19A5077CFECA126BD9A8DD4996561D4E27B3609FF82C5B1B21E627845D44961B33B875D5C4FA9FF357EF6BE3364969E1337C91B29A07B9A913CDE40CE2D5530C900E73751685E65431")); - assert_eq!(&key.primes()[0].to_bytes_be(), &hex!("D0213A79425B665B719118448893EC3275600F63DBF85B77F4E8E99EF302F6E82596048F6DCA772DE6BBF1124DB84B0AFE61B03A8604AB0079ED53F3304797AD01B38C44FE27A5A45E378483A804B56A4A967F48F01A866E721E67E4C9A1048AF68927FAA43D6A85D93E7BF7074DBA797563FCABE12309B76653C6DB614DC231CC556D9F25AC4841A02D31CDF3015B212307F9D0C79FEB5D3956CE53CC8FA1651BE60761F19F74672489EAF9F215409F39956E77A82183F1F72BB2FEDDF1B9FBFC4AD89EA445809DDBD5BD595277990C0BE9366FBB2ECF7B057CC1C3DC8FB77BF8456D07BBC95B3C1815F48E62B81468C3D4D9D96C0F48DAB04993BE8D91EDE5")); - assert_eq!(&key.primes()[1].to_bytes_be(), &hex!("CE36C6810522ABE5D6465F36EB137DA3B9EA4A5F1D27C6614729EB8E5E2E5CB88E3EF1A473A21944B66557B3DC2CE462E4BF3446CB4990037E5672B1705CBAE81B65BAF967A266DC18EFE80F4DBBFE1A59063205CE2943CADF421CCE74AF7063FD1A83AF3C39AF84525F59BDC1FF54815F52AFD1E8D4862B2C3654F6CFA83DC08E2A9D52B9F833C646AF7694467DFC5F7D7AD7B441895FCB7FFBED526324B0154A15823F5107C89548EDDCB61DA5308C6CC834D4A0C16DFA6CA1D67B61A65677EB1719CD125D0EF0DB8802FB76CFC17577BCB2510AE294E1BF8A9173A2B85C16A6B508C98F2D770B7F3DE48D9E720C53E263680B57E7109410015745570652FD")); + assert_eq!( + &key.d().to_bytes_be(), + &hex!( + "9FE3097B2322B90FAB6606C017A095EBE640C39C100BCEE02F238FA14DAFF38E" + "9E57568F1127ED4436126B904631B127EC395BB3EE127EB82C88D2562A7FB55F" + "ED8D1450B7E4E2D2F37F5742636FCC6F289963522D5B5706082CADFA01C0EE99" + "B4D0E9274D3A992E06974CBE01694686356962AC1959FD9BD447E5B9968C0543" + "DF1BF134742AF345CDB2FA1F9371B0D4CF61C68D16D653D8E999D4FD3A16CF97" + "8A35AA40E860CDCE09655DD8B4CF19D4141B1E92AD5E51A8E4A5C27FA745611D" + "90E49D0E9282222AB6F126643E1C77578816FCE3B98F321D2549F294A470DF84" + "53446BF36F985DF25ED8FDE9FDF3073FB27727DF48E9E1FC7056BC78965090B7" + "850126406462C8253051EF84E34EE3C3CEB8F96C658C38BE45558D2F64E29D22" + "3350555FC1EFA28EC1F4AFB5BA4080F09A86CDC3538C1AD7C972E6D7A3612E68" + "45BA9AFBDF19F09060D1A779DE9635E2D2F8E0C510BA24C6C44B30C9BDFAF85B" + "E917AEC5D43AFAB1AA3ADD33CC83DA93CAC69218F6A36EB47F199D5424C95FD9" + "ED7B1E8BE2AEAA6433B227241316C20EE792650CEB48BFD634446B19D286B4EA" + "1722498DA1A36973210EC3824751A5808D9AAEF59C449E19A5077CFECA126BD9" + "A8DD4996561D4E27B3609FF82C5B1B21E627845D44961B33B875D5C4FA9FF357" + "EF6BE3364969E1337C91B29A07B9A913CDE40CE2D5530C900E73751685E65431" + ) + ); + assert_eq!( + &key.primes()[0].to_bytes_be(), + &hex!( + "D0213A79425B665B719118448893EC3275600F63DBF85B77F4E8E99EF302F6E8" + "2596048F6DCA772DE6BBF1124DB84B0AFE61B03A8604AB0079ED53F3304797AD" + "01B38C44FE27A5A45E378483A804B56A4A967F48F01A866E721E67E4C9A1048A" + "F68927FAA43D6A85D93E7BF7074DBA797563FCABE12309B76653C6DB614DC231" + "CC556D9F25AC4841A02D31CDF3015B212307F9D0C79FEB5D3956CE53CC8FA165" + "1BE60761F19F74672489EAF9F215409F39956E77A82183F1F72BB2FEDDF1B9FB" + "FC4AD89EA445809DDBD5BD595277990C0BE9366FBB2ECF7B057CC1C3DC8FB77B" + "F8456D07BBC95B3C1815F48E62B81468C3D4D9D96C0F48DAB04993BE8D91EDE5" + ) + ); + assert_eq!( + &key.primes()[1].to_bytes_be(), + &hex!( + "CE36C6810522ABE5D6465F36EB137DA3B9EA4A5F1D27C6614729EB8E5E2E5CB8" + "8E3EF1A473A21944B66557B3DC2CE462E4BF3446CB4990037E5672B1705CBAE8" + "1B65BAF967A266DC18EFE80F4DBBFE1A59063205CE2943CADF421CCE74AF7063" + "FD1A83AF3C39AF84525F59BDC1FF54815F52AFD1E8D4862B2C3654F6CFA83DC0" + "8E2A9D52B9F833C646AF7694467DFC5F7D7AD7B441895FCB7FFBED526324B015" + "4A15823F5107C89548EDDCB61DA5308C6CC834D4A0C16DFA6CA1D67B61A65677" + "EB1719CD125D0EF0DB8802FB76CFC17577BCB2510AE294E1BF8A9173A2B85C16" + "A6B508C98F2D770B7F3DE48D9E720C53E263680B57E7109410015745570652FD" + ) + ); } #[test] @@ -153,7 +397,19 @@ fn decode_rsa2048_pub_pem() { // Extracted using: // $ openssl asn1parse -in tests/examples/pkcs1/rsa2048-pub.pem - assert_eq!(&key.n().to_bytes_be(), &hex!("B6C42C515F10A6AAF282C63EDBE24243A170F3FA2633BD4833637F47CA4F6F36E03A5D29EFC3191AC80F390D874B39E30F414FCEC1FCA0ED81E547EDC2CD382C76F61C9018973DB9FA537972A7C701F6B77E0982DFC15FC01927EE5E7CD94B4F599FF07013A7C8281BDF22DCBC9AD7CABB7C4311C982F58EDB7213AD4558B332266D743AED8192D1884CADB8B14739A8DADA66DC970806D9C7AC450CB13D0D7C575FB198534FC61BC41BC0F0574E0E0130C7BBBFBDFDC9F6A6E2E3E2AFF1CBEAC89BA57884528D55CFB08327A1E8C89F4E003CF2888E933241D9D695BCBBACDC90B44E3E095FA37058EA25B13F5E295CBEAC6DE838AB8C50AF61E298975B872F")); + assert_eq!( + &key.n().to_bytes_be(), + &hex!( + "B6C42C515F10A6AAF282C63EDBE24243A170F3FA2633BD4833637F47CA4F6F36" + "E03A5D29EFC3191AC80F390D874B39E30F414FCEC1FCA0ED81E547EDC2CD382C" + "76F61C9018973DB9FA537972A7C701F6B77E0982DFC15FC01927EE5E7CD94B4F" + "599FF07013A7C8281BDF22DCBC9AD7CABB7C4311C982F58EDB7213AD4558B332" + "266D743AED8192D1884CADB8B14739A8DADA66DC970806D9C7AC450CB13D0D7C" + "575FB198534FC61BC41BC0F0574E0E0130C7BBBFBDFDC9F6A6E2E3E2AFF1CBEA" + "C89BA57884528D55CFB08327A1E8C89F4E003CF2888E933241D9D695BCBBACDC" + "90B44E3E095FA37058EA25B13F5E295CBEAC6DE838AB8C50AF61E298975B872F" + ) + ); assert_eq!(&key.e().to_bytes_be(), &hex!("010001")); } @@ -164,7 +420,27 @@ fn decode_rsa4096_pub_pem() { // Extracted using: // $ openssl asn1parse -in tests/examples/pkcs1/rsa4096-pub.pem - assert_eq!(&key.n().to_bytes_be(), &hex!("A7A74572811EA2617E49E85BD730DDE30F103F7D88EE3F765E540D3DD993BBB0BA140002859D0B40897436637F58B828EA74DF8321634077F99D4AA2D54CA375852EF597661D3713CE1EF3B4FD6A8E220238E467668A2C7EE3861D2212AE6A1EBDDFA88B62DF10F6BCF79EFF4AC298FB2563DF1B8764381AF9B1FB0CCD085E026B0AD9F6721A235177D0396B48754AD4A75242250A873BF2F6E7EE3C75DD613E365BA4F3210A6CC66B90A2FA3F762CA6884087B6BF8161EB144819F0F572F21F6C8E273E70D45A365B8B2819CE734613CC23B01329A17901F17078403861F54C52A051E2A58C75C2D9D80091BB9808A106C1F7ECB4034E15058BEEC725C5F919D62EAA234B62628D346C60BB919E70851DAB38571E6F0ED7634129F994EA368FEE7373DFDEC04445EBCA47FA20ED1540A860C948BABC98DA591CA1DE2E2E25540EF9B7CB353F60213B814A45D359EFA9B811EEFF08C65993BF8A85C2BFEAAA7ED5E6B43E18AE604464CE5F96150136E7D09F8B24FAD43D7870118CFA7BC24875506EBBC321B977E0861AEA50128620121F0B394A9CDD0A42411A1350C0770D975D71B00A90436240C967A0C3A5C20A0F6DE77F3F2CAFDA94ED0143C1F6E34F73E0CAC279EEEB7C637723A2B026C82802E1A4AEBAA8846DF98E7919498773E0D4F319956F4DE3AAD00EFB9A147D66B3AC1A01D35B2CFB48D400B0E7A80DC97551")); + assert_eq!( + &key.n().to_bytes_be(), + &hex!( + "A7A74572811EA2617E49E85BD730DDE30F103F7D88EE3F765E540D3DD993BBB0" + "BA140002859D0B40897436637F58B828EA74DF8321634077F99D4AA2D54CA375" + "852EF597661D3713CE1EF3B4FD6A8E220238E467668A2C7EE3861D2212AE6A1E" + "BDDFA88B62DF10F6BCF79EFF4AC298FB2563DF1B8764381AF9B1FB0CCD085E02" + "6B0AD9F6721A235177D0396B48754AD4A75242250A873BF2F6E7EE3C75DD613E" + "365BA4F3210A6CC66B90A2FA3F762CA6884087B6BF8161EB144819F0F572F21F" + "6C8E273E70D45A365B8B2819CE734613CC23B01329A17901F17078403861F54C" + "52A051E2A58C75C2D9D80091BB9808A106C1F7ECB4034E15058BEEC725C5F919" + "D62EAA234B62628D346C60BB919E70851DAB38571E6F0ED7634129F994EA368F" + "EE7373DFDEC04445EBCA47FA20ED1540A860C948BABC98DA591CA1DE2E2E2554" + "0EF9B7CB353F60213B814A45D359EFA9B811EEFF08C65993BF8A85C2BFEAAA7E" + "D5E6B43E18AE604464CE5F96150136E7D09F8B24FAD43D7870118CFA7BC24875" + "506EBBC321B977E0861AEA50128620121F0B394A9CDD0A42411A1350C0770D97" + "5D71B00A90436240C967A0C3A5C20A0F6DE77F3F2CAFDA94ED0143C1F6E34F73" + "E0CAC279EEEB7C637723A2B026C82802E1A4AEBAA8846DF98E7919498773E0D4" + "F319956F4DE3AAD00EFB9A147D66B3AC1A01D35B2CFB48D400B0E7A80DC97551" + ) + ); assert_eq!(&key.e().to_bytes_be(), &hex!("010001")); } diff --git a/tests/pkcs8.rs b/tests/pkcs8.rs index 17a0f00c..8f500728 100644 --- a/tests/pkcs8.rs +++ b/tests/pkcs8.rs @@ -38,11 +38,51 @@ fn decode_rsa2048_priv_der() { let key = RsaPrivateKey::from_pkcs8_der(RSA_2048_PRIV_DER).unwrap(); // Note: matches PKCS#1 test vectors - assert_eq!(&key.n().to_bytes_be(), &hex!("B6C42C515F10A6AAF282C63EDBE24243A170F3FA2633BD4833637F47CA4F6F36E03A5D29EFC3191AC80F390D874B39E30F414FCEC1FCA0ED81E547EDC2CD382C76F61C9018973DB9FA537972A7C701F6B77E0982DFC15FC01927EE5E7CD94B4F599FF07013A7C8281BDF22DCBC9AD7CABB7C4311C982F58EDB7213AD4558B332266D743AED8192D1884CADB8B14739A8DADA66DC970806D9C7AC450CB13D0D7C575FB198534FC61BC41BC0F0574E0E0130C7BBBFBDFDC9F6A6E2E3E2AFF1CBEAC89BA57884528D55CFB08327A1E8C89F4E003CF2888E933241D9D695BCBBACDC90B44E3E095FA37058EA25B13F5E295CBEAC6DE838AB8C50AF61E298975B872F")); + assert_eq!( + &key.n().to_bytes_be(), + &hex!( + "B6C42C515F10A6AAF282C63EDBE24243A170F3FA2633BD4833637F47CA4F6F36" + "E03A5D29EFC3191AC80F390D874B39E30F414FCEC1FCA0ED81E547EDC2CD382C" + "76F61C9018973DB9FA537972A7C701F6B77E0982DFC15FC01927EE5E7CD94B4F" + "599FF07013A7C8281BDF22DCBC9AD7CABB7C4311C982F58EDB7213AD4558B332" + "266D743AED8192D1884CADB8B14739A8DADA66DC970806D9C7AC450CB13D0D7C" + "575FB198534FC61BC41BC0F0574E0E0130C7BBBFBDFDC9F6A6E2E3E2AFF1CBEA" + "C89BA57884528D55CFB08327A1E8C89F4E003CF2888E933241D9D695BCBBACDC" + "90B44E3E095FA37058EA25B13F5E295CBEAC6DE838AB8C50AF61E298975B872F" + ) + ); assert_eq!(&key.e().to_bytes_be(), &hex!("010001")); - assert_eq!(&key.d().to_bytes_be(), &hex!("7ECC8362C0EDB0741164215E22F74AB9D91BA06900700CF63690E5114D8EE6BDCFBB2E3F9614692A677A083F168A5E52E5968E6407B9D97C6E0E4064F82DA0B758A14F17B9B7D41F5F48E28D6551704F56E69E7AA9FA630FC76428C06D25E455DCFC55B7AC2B4F76643FDED3FE15FF78ABB27E65ACC4AAD0BDF6DB27EF60A6910C5C4A085ED43275AB19C1D997A32C6EFFCE7DF2D1935F6E601EEDE161A12B5CC27CA21F81D2C99C3D1EA08E90E3053AB09BEFA724DEF0D0C3A3C1E9740C0D9F76126A149EC0AA7D8078205484254D951DB07C4CF91FB6454C096588FD5924DBABEB359CA2025268D004F9D66EB3D6F7ADC1139BAD40F16DDE639E11647376C1")); - assert_eq!(&key.primes()[0].to_bytes_be(), &hex!("DCC061242D4E92AFAEE72AC513CA65B9F77036F9BD7E0E6E61461A7EF7654225EC153C7E5C31A6157A6E5A13FF6E178E8758C1CB33D9D6BBE3179EF18998E422ECDCBED78F4ECFDBE5F4FCD8AEC2C9D0DC86473CA9BD16D9D238D21FB5DDEFBEB143CA61D0BD6AA8D91F33A097790E9640DBC91085DC5F26343BA3138F6B2D67")); - assert_eq!(&key.primes()[1].to_bytes_be(), &hex!("D3F314757E40E954836F92BE24236AF2F0DA04A34653C180AF67E960086D93FDE65CB23EFD9D09374762F5981E361849AF68CDD75394FF6A4E06EB69B209E4228DB2DFA70E40F7F9750A528176647B788D0E5777A2CB8B22E3CD267FF70B4F3B02D3AAFB0E18C590A564B03188B0AA5FC48156B07622214243BD1227EFA7F2F9")); + assert_eq!( + &key.d().to_bytes_be(), + &hex!( + "7ECC8362C0EDB0741164215E22F74AB9D91BA06900700CF63690E5114D8EE6BD" + "CFBB2E3F9614692A677A083F168A5E52E5968E6407B9D97C6E0E4064F82DA0B7" + "58A14F17B9B7D41F5F48E28D6551704F56E69E7AA9FA630FC76428C06D25E455" + "DCFC55B7AC2B4F76643FDED3FE15FF78ABB27E65ACC4AAD0BDF6DB27EF60A691" + "0C5C4A085ED43275AB19C1D997A32C6EFFCE7DF2D1935F6E601EEDE161A12B5C" + "C27CA21F81D2C99C3D1EA08E90E3053AB09BEFA724DEF0D0C3A3C1E9740C0D9F" + "76126A149EC0AA7D8078205484254D951DB07C4CF91FB6454C096588FD5924DB" + "ABEB359CA2025268D004F9D66EB3D6F7ADC1139BAD40F16DDE639E11647376C1" + ) + ); + assert_eq!( + &key.primes()[0].to_bytes_be(), + &hex!( + "DCC061242D4E92AFAEE72AC513CA65B9F77036F9BD7E0E6E61461A7EF7654225" + "EC153C7E5C31A6157A6E5A13FF6E178E8758C1CB33D9D6BBE3179EF18998E422" + "ECDCBED78F4ECFDBE5F4FCD8AEC2C9D0DC86473CA9BD16D9D238D21FB5DDEFBE" + "B143CA61D0BD6AA8D91F33A097790E9640DBC91085DC5F26343BA3138F6B2D67" + ) + ); + assert_eq!( + &key.primes()[1].to_bytes_be(), + &hex!( + "D3F314757E40E954836F92BE24236AF2F0DA04A34653C180AF67E960086D93FD" + "E65CB23EFD9D09374762F5981E361849AF68CDD75394FF6A4E06EB69B209E422" + "8DB2DFA70E40F7F9750A528176647B788D0E5777A2CB8B22E3CD267FF70B4F3B" + "02D3AAFB0E18C590A564B03188B0AA5FC48156B07622214243BD1227EFA7F2F9" + ) + ); let _ = pkcs1v15::SigningKey::::from_pkcs8_der(RSA_2048_PRIV_DER).unwrap(); } @@ -52,7 +92,19 @@ fn decode_rsa2048_pub_der() { let key = RsaPublicKey::from_public_key_der(RSA_2048_PUB_DER).unwrap(); // Note: matches PKCS#1 test vectors - assert_eq!(&key.n().to_bytes_be(), &hex!("B6C42C515F10A6AAF282C63EDBE24243A170F3FA2633BD4833637F47CA4F6F36E03A5D29EFC3191AC80F390D874B39E30F414FCEC1FCA0ED81E547EDC2CD382C76F61C9018973DB9FA537972A7C701F6B77E0982DFC15FC01927EE5E7CD94B4F599FF07013A7C8281BDF22DCBC9AD7CABB7C4311C982F58EDB7213AD4558B332266D743AED8192D1884CADB8B14739A8DADA66DC970806D9C7AC450CB13D0D7C575FB198534FC61BC41BC0F0574E0E0130C7BBBFBDFDC9F6A6E2E3E2AFF1CBEAC89BA57884528D55CFB08327A1E8C89F4E003CF2888E933241D9D695BCBBACDC90B44E3E095FA37058EA25B13F5E295CBEAC6DE838AB8C50AF61E298975B872F")); + assert_eq!( + &key.n().to_bytes_be(), + &hex!( + "B6C42C515F10A6AAF282C63EDBE24243A170F3FA2633BD4833637F47CA4F6F36" + "E03A5D29EFC3191AC80F390D874B39E30F414FCEC1FCA0ED81E547EDC2CD382C" + "76F61C9018973DB9FA537972A7C701F6B77E0982DFC15FC01927EE5E7CD94B4F" + "599FF07013A7C8281BDF22DCBC9AD7CABB7C4311C982F58EDB7213AD4558B332" + "266D743AED8192D1884CADB8B14739A8DADA66DC970806D9C7AC450CB13D0D7C" + "575FB198534FC61BC41BC0F0574E0E0130C7BBBFBDFDC9F6A6E2E3E2AFF1CBEA" + "C89BA57884528D55CFB08327A1E8C89F4E003CF2888E933241D9D695BCBBACDC" + "90B44E3E095FA37058EA25B13F5E295CBEAC6DE838AB8C50AF61E298975B872F" + ) + ); assert_eq!(&key.e().to_bytes_be(), &hex!("010001")); let _ = pkcs1v15::VerifyingKey::::from_public_key_der(RSA_2048_PUB_DER).unwrap(); @@ -62,11 +114,53 @@ fn decode_rsa2048_pub_der() { fn decode_rsa2048_pss_priv_der() { let key = RsaPrivateKey::from_pkcs8_der(RSA_2048_PSS_PRIV_DER).unwrap(); - assert_eq!(&key.n().to_bytes_be(), &hex!("AF8B669B7AF6D1677F3DBAAF3F5B36F9012DBE9B91695F18AB8D208D447CCB6463C5AE9DA46D865C76CF7EF32CF1CB7E2E1D461F8E71DBC470DD1CB9DE69BEA005E3C90F3A3A70E467937C9586E0803E0EDF0E8CEA902F2E4864F79027753AE27DB2053CD53C3CF30EECECAB1401EA803B339E33C59933AD08470DD99D45A5681C870B982CF2FE5A892A96D775D67AAACE2F9B27D72F48A00361D50000DE5652DCDDA62CBA2DB4E04B13FBA1C894E139F483923A683649EC0F0BCE8D0A4B2658A00E3CE66A9C3B419501D570F65AB868E4FDBFA77E9DBE1B9CD91056494B4377D502F266FB17433A9F4B08D08DE3C576A670CE90557AF94F67579A3273A5C8DB")); + assert_eq!( + &key.n().to_bytes_be(), + &hex!( + "AF8B669B7AF6D1677F3DBAAF3F5B36F9012DBE9B91695F18AB8D208D447CCB64" + "63C5AE9DA46D865C76CF7EF32CF1CB7E2E1D461F8E71DBC470DD1CB9DE69BEA0" + "05E3C90F3A3A70E467937C9586E0803E0EDF0E8CEA902F2E4864F79027753AE2" + "7DB2053CD53C3CF30EECECAB1401EA803B339E33C59933AD08470DD99D45A568" + "1C870B982CF2FE5A892A96D775D67AAACE2F9B27D72F48A00361D50000DE5652" + "DCDDA62CBA2DB4E04B13FBA1C894E139F483923A683649EC0F0BCE8D0A4B2658" + "A00E3CE66A9C3B419501D570F65AB868E4FDBFA77E9DBE1B9CD91056494B4377" + "D502F266FB17433A9F4B08D08DE3C576A670CE90557AF94F67579A3273A5C8DB" + + ) + ); assert_eq!(&key.e().to_bytes_be(), &hex!("010001")); - assert_eq!(&key.d().to_bytes_be(), &hex!("9407C8A9FA426289954A17C02A7C1FDA50FD234C0A8E41EC0AD64289FE24025C10AAA5BA37EB482F76DD391F9559FD10D590480EDA4EF7552B1BBA5A9ECCAB3C445B36B44994F8981323D31E4093D670FE9768ACBA2C862CD04D9C5A0A7C1800E0A01B3C96506AD14857D0A7DF82521E7A4DE7ED9E86B7860581ED9301C5B659B3785DF2BB96EA45CA8E871F25918981CC3004505CB25E3927539F968C04FD0F3B86D0CA4E4E4714D449E39C88F254164B501E4BC66F29BB2ABC847F01FC4E4B342FB5A1CF23FAD0F2F7C52F4534E262F66FB3CEDC1821718342E28CD860EC213783DA6236A07A0F332003D30748EC1C12556D7CA7587E8E07DCE1D95EC4A611")); - assert_eq!(&key.primes()[0].to_bytes_be(), &hex!("E55FBA212239C846821579BE7E4D44336C700167A478F542032BEBF506D3945382670B7D5B08D48E1B4A46EB22E54ABE21867FB6AD96444E00B386FF14710CB69D80111E3721CBE65CFA8A141A1492D5434BB7538481EBB27462D54EDD1EA55DC2230431EE63C4A3609EC28BA67ABEE0DCA1A12E8E796BB5485A331BD27DC509")); - assert_eq!(&key.primes()[1].to_bytes_be(), &hex!("C3EC0875ED7B5B96340A9869DD9674B8CF0E52AD4092B57620A6AEA981DA0F1013DF610CE1C8B630C111DA7214128E20FF8DA55B4CD8A2E145A8E370BF4F87C8EB203E9752A8A442E562E09F455769B8DA35CCBA2A134F5DE274020B6A7620F03DE276FCBFDE2B0356438DD17DD40152AB80C1277B4849A643CB158AA07ADBC3")); + assert_eq!( + &key.d().to_bytes_be(), + &hex!( + "9407C8A9FA426289954A17C02A7C1FDA50FD234C0A8E41EC0AD64289FE24025C" + "10AAA5BA37EB482F76DD391F9559FD10D590480EDA4EF7552B1BBA5A9ECCAB3C" + "445B36B44994F8981323D31E4093D670FE9768ACBA2C862CD04D9C5A0A7C1800" + "E0A01B3C96506AD14857D0A7DF82521E7A4DE7ED9E86B7860581ED9301C5B659" + "B3785DF2BB96EA45CA8E871F25918981CC3004505CB25E3927539F968C04FD0F" + "3B86D0CA4E4E4714D449E39C88F254164B501E4BC66F29BB2ABC847F01FC4E4B" + "342FB5A1CF23FAD0F2F7C52F4534E262F66FB3CEDC1821718342E28CD860EC21" + "3783DA6236A07A0F332003D30748EC1C12556D7CA7587E8E07DCE1D95EC4A611" + ) + ); + assert_eq!( + &key.primes()[0].to_bytes_be(), + &hex!( + "E55FBA212239C846821579BE7E4D44336C700167A478F542032BEBF506D39453" + "82670B7D5B08D48E1B4A46EB22E54ABE21867FB6AD96444E00B386FF14710CB6" + "9D80111E3721CBE65CFA8A141A1492D5434BB7538481EBB27462D54EDD1EA55D" + "C2230431EE63C4A3609EC28BA67ABEE0DCA1A12E8E796BB5485A331BD27DC509" + + ) + ); + assert_eq!( + &key.primes()[1].to_bytes_be(), + &hex!( + "C3EC0875ED7B5B96340A9869DD9674B8CF0E52AD4092B57620A6AEA981DA0F10" + "13DF610CE1C8B630C111DA7214128E20FF8DA55B4CD8A2E145A8E370BF4F87C8" + "EB203E9752A8A442E562E09F455769B8DA35CCBA2A134F5DE274020B6A7620F0" + "3DE276FCBFDE2B0356438DD17DD40152AB80C1277B4849A643CB158AA07ADBC3" + ) + ); let _ = pss::SigningKey::::from_pkcs8_der(RSA_2048_PSS_PRIV_DER).unwrap(); } @@ -75,7 +169,19 @@ fn decode_rsa2048_pss_priv_der() { fn decode_rsa2048_pss_pub_der() { let key = RsaPublicKey::from_public_key_der(RSA_2048_PSS_PUB_DER).unwrap(); - assert_eq!(&key.n().to_bytes_be(), &hex!("AF8B669B7AF6D1677F3DBAAF3F5B36F9012DBE9B91695F18AB8D208D447CCB6463C5AE9DA46D865C76CF7EF32CF1CB7E2E1D461F8E71DBC470DD1CB9DE69BEA005E3C90F3A3A70E467937C9586E0803E0EDF0E8CEA902F2E4864F79027753AE27DB2053CD53C3CF30EECECAB1401EA803B339E33C59933AD08470DD99D45A5681C870B982CF2FE5A892A96D775D67AAACE2F9B27D72F48A00361D50000DE5652DCDDA62CBA2DB4E04B13FBA1C894E139F483923A683649EC0F0BCE8D0A4B2658A00E3CE66A9C3B419501D570F65AB868E4FDBFA77E9DBE1B9CD91056494B4377D502F266FB17433A9F4B08D08DE3C576A670CE90557AF94F67579A3273A5C8DB")); + assert_eq!( + &key.n().to_bytes_be(), + &hex!( + "AF8B669B7AF6D1677F3DBAAF3F5B36F9012DBE9B91695F18AB8D208D447CCB64" + "63C5AE9DA46D865C76CF7EF32CF1CB7E2E1D461F8E71DBC470DD1CB9DE69BEA0" + "05E3C90F3A3A70E467937C9586E0803E0EDF0E8CEA902F2E4864F79027753AE2" + "7DB2053CD53C3CF30EECECAB1401EA803B339E33C59933AD08470DD99D45A568" + "1C870B982CF2FE5A892A96D775D67AAACE2F9B27D72F48A00361D50000DE5652" + "DCDDA62CBA2DB4E04B13FBA1C894E139F483923A683649EC0F0BCE8D0A4B2658" + "A00E3CE66A9C3B419501D570F65AB868E4FDBFA77E9DBE1B9CD91056494B4377" + "D502F266FB17433A9F4B08D08DE3C576A670CE90557AF94F67579A3273A5C8DB" + ) + ); assert_eq!(&key.e().to_bytes_be(), &hex!("010001")); let _ = pss::VerifyingKey::::from_public_key_der(RSA_2048_PSS_PUB_DER).unwrap(); @@ -110,11 +216,51 @@ fn decode_rsa2048_priv_pem() { let key = RsaPrivateKey::from_pkcs8_pem(RSA_2048_PRIV_PEM).unwrap(); // Note: matches PKCS#1 test vectors - assert_eq!(&key.n().to_bytes_be(), &hex!("B6C42C515F10A6AAF282C63EDBE24243A170F3FA2633BD4833637F47CA4F6F36E03A5D29EFC3191AC80F390D874B39E30F414FCEC1FCA0ED81E547EDC2CD382C76F61C9018973DB9FA537972A7C701F6B77E0982DFC15FC01927EE5E7CD94B4F599FF07013A7C8281BDF22DCBC9AD7CABB7C4311C982F58EDB7213AD4558B332266D743AED8192D1884CADB8B14739A8DADA66DC970806D9C7AC450CB13D0D7C575FB198534FC61BC41BC0F0574E0E0130C7BBBFBDFDC9F6A6E2E3E2AFF1CBEAC89BA57884528D55CFB08327A1E8C89F4E003CF2888E933241D9D695BCBBACDC90B44E3E095FA37058EA25B13F5E295CBEAC6DE838AB8C50AF61E298975B872F")); + assert_eq!( + &key.n().to_bytes_be(), + &hex!( + "B6C42C515F10A6AAF282C63EDBE24243A170F3FA2633BD4833637F47CA4F6F36" + "E03A5D29EFC3191AC80F390D874B39E30F414FCEC1FCA0ED81E547EDC2CD382C" + "76F61C9018973DB9FA537972A7C701F6B77E0982DFC15FC01927EE5E7CD94B4F" + "599FF07013A7C8281BDF22DCBC9AD7CABB7C4311C982F58EDB7213AD4558B332" + "266D743AED8192D1884CADB8B14739A8DADA66DC970806D9C7AC450CB13D0D7C" + "575FB198534FC61BC41BC0F0574E0E0130C7BBBFBDFDC9F6A6E2E3E2AFF1CBEA" + "C89BA57884528D55CFB08327A1E8C89F4E003CF2888E933241D9D695BCBBACDC" + "90B44E3E095FA37058EA25B13F5E295CBEAC6DE838AB8C50AF61E298975B872F" + ) + ); assert_eq!(&key.e().to_bytes_be(), &hex!("010001")); - assert_eq!(&key.d().to_bytes_be(), &hex!("7ECC8362C0EDB0741164215E22F74AB9D91BA06900700CF63690E5114D8EE6BDCFBB2E3F9614692A677A083F168A5E52E5968E6407B9D97C6E0E4064F82DA0B758A14F17B9B7D41F5F48E28D6551704F56E69E7AA9FA630FC76428C06D25E455DCFC55B7AC2B4F76643FDED3FE15FF78ABB27E65ACC4AAD0BDF6DB27EF60A6910C5C4A085ED43275AB19C1D997A32C6EFFCE7DF2D1935F6E601EEDE161A12B5CC27CA21F81D2C99C3D1EA08E90E3053AB09BEFA724DEF0D0C3A3C1E9740C0D9F76126A149EC0AA7D8078205484254D951DB07C4CF91FB6454C096588FD5924DBABEB359CA2025268D004F9D66EB3D6F7ADC1139BAD40F16DDE639E11647376C1")); - assert_eq!(&key.primes()[0].to_bytes_be(), &hex!("DCC061242D4E92AFAEE72AC513CA65B9F77036F9BD7E0E6E61461A7EF7654225EC153C7E5C31A6157A6E5A13FF6E178E8758C1CB33D9D6BBE3179EF18998E422ECDCBED78F4ECFDBE5F4FCD8AEC2C9D0DC86473CA9BD16D9D238D21FB5DDEFBEB143CA61D0BD6AA8D91F33A097790E9640DBC91085DC5F26343BA3138F6B2D67")); - assert_eq!(&key.primes()[1].to_bytes_be(), &hex!("D3F314757E40E954836F92BE24236AF2F0DA04A34653C180AF67E960086D93FDE65CB23EFD9D09374762F5981E361849AF68CDD75394FF6A4E06EB69B209E4228DB2DFA70E40F7F9750A528176647B788D0E5777A2CB8B22E3CD267FF70B4F3B02D3AAFB0E18C590A564B03188B0AA5FC48156B07622214243BD1227EFA7F2F9")); + assert_eq!( + &key.d().to_bytes_be(), + &hex!( + "7ECC8362C0EDB0741164215E22F74AB9D91BA06900700CF63690E5114D8EE6BD" + "CFBB2E3F9614692A677A083F168A5E52E5968E6407B9D97C6E0E4064F82DA0B7" + "58A14F17B9B7D41F5F48E28D6551704F56E69E7AA9FA630FC76428C06D25E455" + "DCFC55B7AC2B4F76643FDED3FE15FF78ABB27E65ACC4AAD0BDF6DB27EF60A691" + "0C5C4A085ED43275AB19C1D997A32C6EFFCE7DF2D1935F6E601EEDE161A12B5C" + "C27CA21F81D2C99C3D1EA08E90E3053AB09BEFA724DEF0D0C3A3C1E9740C0D9F" + "76126A149EC0AA7D8078205484254D951DB07C4CF91FB6454C096588FD5924DB" + "ABEB359CA2025268D004F9D66EB3D6F7ADC1139BAD40F16DDE639E11647376C1" + ) + ); + assert_eq!( + &key.primes()[0].to_bytes_be(), + &hex!( + "DCC061242D4E92AFAEE72AC513CA65B9F77036F9BD7E0E6E61461A7EF7654225" + "EC153C7E5C31A6157A6E5A13FF6E178E8758C1CB33D9D6BBE3179EF18998E422" + "ECDCBED78F4ECFDBE5F4FCD8AEC2C9D0DC86473CA9BD16D9D238D21FB5DDEFBE" + "B143CA61D0BD6AA8D91F33A097790E9640DBC91085DC5F26343BA3138F6B2D67" + ) + ); + assert_eq!( + &key.primes()[1].to_bytes_be(), + &hex!( + "D3F314757E40E954836F92BE24236AF2F0DA04A34653C180AF67E960086D93FD" + "E65CB23EFD9D09374762F5981E361849AF68CDD75394FF6A4E06EB69B209E422" + "8DB2DFA70E40F7F9750A528176647B788D0E5777A2CB8B22E3CD267FF70B4F3B" + "02D3AAFB0E18C590A564B03188B0AA5FC48156B07622214243BD1227EFA7F2F9" + ) + ); let _ = pkcs1v15::SigningKey::::from_pkcs8_pem(RSA_2048_PRIV_PEM).unwrap(); } @@ -125,7 +271,19 @@ fn decode_rsa2048_pub_pem() { let key = RsaPublicKey::from_public_key_pem(RSA_2048_PUB_PEM).unwrap(); // Note: matches PKCS#1 test vectors - assert_eq!(&key.n().to_bytes_be(), &hex!("B6C42C515F10A6AAF282C63EDBE24243A170F3FA2633BD4833637F47CA4F6F36E03A5D29EFC3191AC80F390D874B39E30F414FCEC1FCA0ED81E547EDC2CD382C76F61C9018973DB9FA537972A7C701F6B77E0982DFC15FC01927EE5E7CD94B4F599FF07013A7C8281BDF22DCBC9AD7CABB7C4311C982F58EDB7213AD4558B332266D743AED8192D1884CADB8B14739A8DADA66DC970806D9C7AC450CB13D0D7C575FB198534FC61BC41BC0F0574E0E0130C7BBBFBDFDC9F6A6E2E3E2AFF1CBEAC89BA57884528D55CFB08327A1E8C89F4E003CF2888E933241D9D695BCBBACDC90B44E3E095FA37058EA25B13F5E295CBEAC6DE838AB8C50AF61E298975B872F")); + assert_eq!( + &key.n().to_bytes_be(), + &hex!( + "B6C42C515F10A6AAF282C63EDBE24243A170F3FA2633BD4833637F47CA4F6F36" + "E03A5D29EFC3191AC80F390D874B39E30F414FCEC1FCA0ED81E547EDC2CD382C" + "76F61C9018973DB9FA537972A7C701F6B77E0982DFC15FC01927EE5E7CD94B4F" + "599FF07013A7C8281BDF22DCBC9AD7CABB7C4311C982F58EDB7213AD4558B332" + "266D743AED8192D1884CADB8B14739A8DADA66DC970806D9C7AC450CB13D0D7C" + "575FB198534FC61BC41BC0F0574E0E0130C7BBBFBDFDC9F6A6E2E3E2AFF1CBEA" + "C89BA57884528D55CFB08327A1E8C89F4E003CF2888E933241D9D695BCBBACDC" + "90B44E3E095FA37058EA25B13F5E295CBEAC6DE838AB8C50AF61E298975B872F" + ) + ); assert_eq!(&key.e().to_bytes_be(), &hex!("010001")); let _ = pkcs1v15::VerifyingKey::::from_public_key_pem(RSA_2048_PUB_PEM).unwrap();