From 3ff3c106044ff6c130a8e6328136d1614bae42c3 Mon Sep 17 00:00:00 2001 From: dignifiedquire Date: Thu, 7 Nov 2024 00:07:21 +0100 Subject: [PATCH] fixup benchmark code --- benches/key.rs | 66 +++++++++++++------------------------------------- 1 file changed, 17 insertions(+), 49 deletions(-) diff --git a/benches/key.rs b/benches/key.rs index bc1e4bca..f08df76f 100644 --- a/benches/key.rs +++ b/benches/key.rs @@ -3,8 +3,8 @@ extern crate test; use base64ct::{Base64, Encoding}; -use num_bigint::BigUint; -use num_traits::{FromPrimitive, Num}; +use crypto_bigint::{BoxedUint, Odd}; +use hex_literal::hex; use rand_chacha::{rand_core::SeedableRng, ChaCha8Rng}; use rsa::{Pkcs1v15Encrypt, Pkcs1v15Sign, RsaPrivateKey}; use sha2::{Digest, Sha256}; @@ -19,55 +19,23 @@ const DECRYPT_VAL: &str = "\ rLgZ5Gxv5DM4BtV7Z4m85w=="; fn get_key() -> RsaPrivateKey { + // 2048 bits + + let n = hex!("7163c842b2190a8970942b2764aed42d4124647b6f30e09a2da1c0e256aa2ee24e790c40c96a4bd66d75c371a915e0703c476b4e1a06f1bd38c5a3c10ae3bd30f4ef62a5aa4f512ad145a06c48e96469a22ce8e621e052f0669a8c34155512d82e55447f0b7e18da94bd911ac7b3aabe706843668964593ee71b2e5e484bcf0c7834101ab5d61bba1e63e6237af40489ce36a260dab70add4fbec24d659db0f7cac099b0a3aa4549acde7fc858a793a975e6cf65ca276b743525f0883980f6ad069bec346d787797386d50fe0c9734be967c7d84ae5b8f349b094079457c0c0c6fee34c42a0b832603804f71e49f3320081637512c6cbf2bb81b6f6be239846d"); + let d = hex!("4b97dad7216607064b0d721a431f381e2b6d98524a2095bc1e6bd5ec39c6c9ec3450b2d5db9c328ef3a3d7a11b63eaf57d84f2341159f67e25d917d607427e20a34a41c3c6df8b71e0d9159d85f0ed9bc17345eec140374aef11b2cd638e0c901ee382ff5cfebb3c63290b672fcd1c7ef59ad799b0ed90d49a121ee98587df5cc161c584bc5887ae2a15e787e86ab1e803366150561e0b3b3ae28ebdcf32cd46dff317ed3e1b7590cc300d1d57c9288462d06d9fbe097e52b70dc4fca313ae09906e5fab0c24729b54fe35cc38fe1496419a902f35f08460952bd4783e0e930ba8b520f83eafe6fa6589bbab6e4f4bc5c285672c99f5055eec6a2a30b06e786b"); + + let primes = [ + hex!("ba69948f830c296242da6bf9ae3fddb76a63dbf0761ed3f644bca96a2e1eb75fd1bbd9cd93c72330bcc2a97cfafd12ee27bfde0fb6ac152df2ec4ab12b11265b41bcb531e39f347fdf09e9562a6e5a7c020c6534df61c955dd772cc7b9d461fdeea2f3b83663302cfe5656c235d4ac94c81658ad179919cded8ab1be1e9aa369"), + hex!("9bb7d344184526d29c689eddf0141bf65f013477e36b260e32ae42c680b2c5ada9181bff32b9f1bfbdd3c29f59fcc3f4b9ee4ce6766d18ca2fa4fe5c19d24b436c39a781f7a2972e59e616f58cabbb6132084008fe10ff4dddd054fd2e91cd7d043b8f9795a078816cdb5f2e895394e29c37c3e12de41d4f67f17e64baf92c65"), + ]; + RsaPrivateKey::from_components( - 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( - "9542755287494004433998723259516013739278699355114572217325597900\ - 8894161634588095013041324875556428118881509373920138246214487098\ - 3614288600665329602509394141862899264842979828212730370495727384\ - 5127141852309016655778568546006839666463451542076964744073572349\ - 7055386317422819318582194809859072719758847734823729668476398538\ - 9789061545660559807108818983867672883683301225406598325963853810\ - 7719766738032720239892094196108713378822882383694456030043492571\ - 0634419438471959395497732716946476575496586033656294586102738212\ - 9223264633471761267451999753390105279033427966175417649059304194\ - 1863932308687197618671528035670452762731", - 10, - ) - .unwrap(), + Odd::new(BoxedUint::from_be_slice(&n, 2048).unwrap()).unwrap(), + BoxedUint::from(3u32), + BoxedUint::from_be_slice(&d, 2048).unwrap(), vec![ - BigUint::from_str_radix( - "1309032551829967224267716136060777552955833291350673401529471728\ - 6841580902753737630619317962429887421560827080205434760983677647\ - 3930072411958753044562214537013874103802006369634761074377213995\ - 9838767887180338501537194216954687042766949830326444169308790939\ - 14927146648402139231293035971427838068945045019075433", - 10, - ) - .unwrap(), - BigUint::from_str_radix( - "1093489456104854535775747676525274729242892295382866496612409389\ - 8802036700547572798825343864756095857350615944953879354047282981\ - 5903949343191091817779240101054552748665267574271163617694640513\ - 5496938413378206027265967563510061495188309322612466987663553478\ - 98158548465400674856021497190430791824869615170301029", - 10, - ) - .unwrap(), + BoxedUint::from_be_slice(&primes[0], 1024).unwrap(), + BoxedUint::from_be_slice(&primes[1], 1024).unwrap(), ], ) .unwrap()