Skip to content

Commit

Permalink
Fix clippy and fmt issues
Browse files Browse the repository at this point in the history
  • Loading branch information
Fethbita committed Dec 1, 2024
1 parent 5402e8c commit ec599ee
Show file tree
Hide file tree
Showing 3 changed files with 157 additions and 102 deletions.
2 changes: 1 addition & 1 deletion src/algorithms/rsa.rs
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,7 @@ fn blind<R: CryptoRngCore, K: PublicKeyParts>(

let blinded = {
// r^e (mod n)
let mut rpowe = pow_mod_params(&r, &key.e(), n_params.clone());
let mut rpowe = pow_mod_params(&r, key.e(), n_params.clone());
// c * r^e (mod n)
let c = mul_mod_params(c, &rpowe, n_params.clone());
rpowe.zeroize();
Expand Down
161 changes: 96 additions & 65 deletions tests/pkcs1.rs
Original file line number Diff line number Diff line change
Expand Up @@ -83,20 +83,28 @@ fn decode_rsa2048_priv_der() {
"ABEB359CA2025268D004F9D66EB3D6F7ADC1139BAD40F16DDE639E11647376C1"
)
);
let expected_prime = BoxedUint::from_be_slice(&hex!(
"DCC061242D4E92AFAEE72AC513CA65B9F77036F9BD7E0E6E61461A7EF7654225"
"EC153C7E5C31A6157A6E5A13FF6E178E8758C1CB33D9D6BBE3179EF18998E422"
"ECDCBED78F4ECFDBE5F4FCD8AEC2C9D0DC86473CA9BD16D9D238D21FB5DDEFBE"
"B143CA61D0BD6AA8D91F33A097790E9640DBC91085DC5F26343BA3138F6B2D67"
), 1024).unwrap();
let expected_prime = BoxedUint::from_be_slice(
&hex!(
"DCC061242D4E92AFAEE72AC513CA65B9F77036F9BD7E0E6E61461A7EF7654225"
"EC153C7E5C31A6157A6E5A13FF6E178E8758C1CB33D9D6BBE3179EF18998E422"
"ECDCBED78F4ECFDBE5F4FCD8AEC2C9D0DC86473CA9BD16D9D238D21FB5DDEFBE"
"B143CA61D0BD6AA8D91F33A097790E9640DBC91085DC5F26343BA3138F6B2D67"
),
1024,
)
.unwrap();
assert!(bool::from(key.primes()[0].ct_eq(&expected_prime)));

let expected_prime = BoxedUint::from_be_slice(&hex!(
"D3F314757E40E954836F92BE24236AF2F0DA04A34653C180AF67E960086D93FD"
"E65CB23EFD9D09374762F5981E361849AF68CDD75394FF6A4E06EB69B209E422"
"8DB2DFA70E40F7F9750A528176647B788D0E5777A2CB8B22E3CD267FF70B4F3B"
"02D3AAFB0E18C590A564B03188B0AA5FC48156B07622214243BD1227EFA7F2F9"
), 1024).unwrap();
let expected_prime = BoxedUint::from_be_slice(
&hex!(
"D3F314757E40E954836F92BE24236AF2F0DA04A34653C180AF67E960086D93FD"
"E65CB23EFD9D09374762F5981E361849AF68CDD75394FF6A4E06EB69B209E422"
"8DB2DFA70E40F7F9750A528176647B788D0E5777A2CB8B22E3CD267FF70B4F3B"
"02D3AAFB0E18C590A564B03188B0AA5FC48156B07622214243BD1227EFA7F2F9"
),
1024,
)
.unwrap();
assert!(bool::from(key.primes()[1].ct_eq(&expected_prime)));
}

Expand Down Expand Up @@ -150,28 +158,36 @@ fn decode_rsa4096_priv_der() {
"EF6BE3364969E1337C91B29A07B9A913CDE40CE2D5530C900E73751685E65431"
)
);
let expected_prime = BoxedUint::from_be_slice(&hex!(
"D0213A79425B665B719118448893EC3275600F63DBF85B77F4E8E99EF302F6E8"
"2596048F6DCA772DE6BBF1124DB84B0AFE61B03A8604AB0079ED53F3304797AD"
"01B38C44FE27A5A45E378483A804B56A4A967F48F01A866E721E67E4C9A1048A"
"F68927FAA43D6A85D93E7BF7074DBA797563FCABE12309B76653C6DB614DC231"
"CC556D9F25AC4841A02D31CDF3015B212307F9D0C79FEB5D3956CE53CC8FA165"
"1BE60761F19F74672489EAF9F215409F39956E77A82183F1F72BB2FEDDF1B9FB"
"FC4AD89EA445809DDBD5BD595277990C0BE9366FBB2ECF7B057CC1C3DC8FB77B"
"F8456D07BBC95B3C1815F48E62B81468C3D4D9D96C0F48DAB04993BE8D91EDE5"
), 2048).unwrap();
let expected_prime = BoxedUint::from_be_slice(
&hex!(
"D0213A79425B665B719118448893EC3275600F63DBF85B77F4E8E99EF302F6E8"
"2596048F6DCA772DE6BBF1124DB84B0AFE61B03A8604AB0079ED53F3304797AD"
"01B38C44FE27A5A45E378483A804B56A4A967F48F01A866E721E67E4C9A1048A"
"F68927FAA43D6A85D93E7BF7074DBA797563FCABE12309B76653C6DB614DC231"
"CC556D9F25AC4841A02D31CDF3015B212307F9D0C79FEB5D3956CE53CC8FA165"
"1BE60761F19F74672489EAF9F215409F39956E77A82183F1F72BB2FEDDF1B9FB"
"FC4AD89EA445809DDBD5BD595277990C0BE9366FBB2ECF7B057CC1C3DC8FB77B"
"F8456D07BBC95B3C1815F48E62B81468C3D4D9D96C0F48DAB04993BE8D91EDE5"
),
2048,
)
.unwrap();
assert!(bool::from(key.primes()[0].ct_eq(&expected_prime)));

let expected_prime = BoxedUint::from_be_slice(&hex!(
"CE36C6810522ABE5D6465F36EB137DA3B9EA4A5F1D27C6614729EB8E5E2E5CB8"
"8E3EF1A473A21944B66557B3DC2CE462E4BF3446CB4990037E5672B1705CBAE8"
"1B65BAF967A266DC18EFE80F4DBBFE1A59063205CE2943CADF421CCE74AF7063"
"FD1A83AF3C39AF84525F59BDC1FF54815F52AFD1E8D4862B2C3654F6CFA83DC0"
"8E2A9D52B9F833C646AF7694467DFC5F7D7AD7B441895FCB7FFBED526324B015"
"4A15823F5107C89548EDDCB61DA5308C6CC834D4A0C16DFA6CA1D67B61A65677"
"EB1719CD125D0EF0DB8802FB76CFC17577BCB2510AE294E1BF8A9173A2B85C16"
"A6B508C98F2D770B7F3DE48D9E720C53E263680B57E7109410015745570652FD"
), 2048).unwrap();
let expected_prime = BoxedUint::from_be_slice(
&hex!(
"CE36C6810522ABE5D6465F36EB137DA3B9EA4A5F1D27C6614729EB8E5E2E5CB8"
"8E3EF1A473A21944B66557B3DC2CE462E4BF3446CB4990037E5672B1705CBAE8"
"1B65BAF967A266DC18EFE80F4DBBFE1A59063205CE2943CADF421CCE74AF7063"
"FD1A83AF3C39AF84525F59BDC1FF54815F52AFD1E8D4862B2C3654F6CFA83DC0"
"8E2A9D52B9F833C646AF7694467DFC5F7D7AD7B441895FCB7FFBED526324B015"
"4A15823F5107C89548EDDCB61DA5308C6CC834D4A0C16DFA6CA1D67B61A65677"
"EB1719CD125D0EF0DB8802FB76CFC17577BCB2510AE294E1BF8A9173A2B85C16"
"A6B508C98F2D770B7F3DE48D9E720C53E263680B57E7109410015745570652FD"
),
2048,
)
.unwrap();
assert!(bool::from(key.primes()[1].ct_eq(&expected_prime)));
}

Expand Down Expand Up @@ -293,22 +309,29 @@ fn decode_rsa2048_priv_pem() {
"ABEB359CA2025268D004F9D66EB3D6F7ADC1139BAD40F16DDE639E11647376C1"
)
);
let expected_prime = BoxedUint::from_be_slice(&hex!(
"DCC061242D4E92AFAEE72AC513CA65B9F77036F9BD7E0E6E61461A7EF7654225"
"EC153C7E5C31A6157A6E5A13FF6E178E8758C1CB33D9D6BBE3179EF18998E422"
"ECDCBED78F4ECFDBE5F4FCD8AEC2C9D0DC86473CA9BD16D9D238D21FB5DDEFBE"
"B143CA61D0BD6AA8D91F33A097790E9640DBC91085DC5F26343BA3138F6B2D67"
), 1024).unwrap();
let expected_prime = BoxedUint::from_be_slice(
&hex!(
"DCC061242D4E92AFAEE72AC513CA65B9F77036F9BD7E0E6E61461A7EF7654225"
"EC153C7E5C31A6157A6E5A13FF6E178E8758C1CB33D9D6BBE3179EF18998E422"
"ECDCBED78F4ECFDBE5F4FCD8AEC2C9D0DC86473CA9BD16D9D238D21FB5DDEFBE"
"B143CA61D0BD6AA8D91F33A097790E9640DBC91085DC5F26343BA3138F6B2D67"
),
1024,
)
.unwrap();
assert!(bool::from(key.primes()[0].ct_eq(&expected_prime)));

let expected_prime = BoxedUint::from_be_slice(&hex!(
"D3F314757E40E954836F92BE24236AF2F0DA04A34653C180AF67E960086D93FD"
"E65CB23EFD9D09374762F5981E361849AF68CDD75394FF6A4E06EB69B209E422"
"8DB2DFA70E40F7F9750A528176647B788D0E5777A2CB8B22E3CD267FF70B4F3B"
"02D3AAFB0E18C590A564B03188B0AA5FC48156B07622214243BD1227EFA7F2F9"
), 1024).unwrap();
let expected_prime = BoxedUint::from_be_slice(
&hex!(
"D3F314757E40E954836F92BE24236AF2F0DA04A34653C180AF67E960086D93FD"
"E65CB23EFD9D09374762F5981E361849AF68CDD75394FF6A4E06EB69B209E422"
"8DB2DFA70E40F7F9750A528176647B788D0E5777A2CB8B22E3CD267FF70B4F3B"
"02D3AAFB0E18C590A564B03188B0AA5FC48156B07622214243BD1227EFA7F2F9"
),
1024,
)
.unwrap();
assert!(bool::from(key.primes()[1].ct_eq(&expected_prime)));

}

#[test]
Expand Down Expand Up @@ -363,28 +386,36 @@ fn decode_rsa4096_priv_pem() {
"EF6BE3364969E1337C91B29A07B9A913CDE40CE2D5530C900E73751685E65431"
)
);
let expected_prime = BoxedUint::from_be_slice(&hex!(
"D0213A79425B665B719118448893EC3275600F63DBF85B77F4E8E99EF302F6E8"
"2596048F6DCA772DE6BBF1124DB84B0AFE61B03A8604AB0079ED53F3304797AD"
"01B38C44FE27A5A45E378483A804B56A4A967F48F01A866E721E67E4C9A1048A"
"F68927FAA43D6A85D93E7BF7074DBA797563FCABE12309B76653C6DB614DC231"
"CC556D9F25AC4841A02D31CDF3015B212307F9D0C79FEB5D3956CE53CC8FA165"
"1BE60761F19F74672489EAF9F215409F39956E77A82183F1F72BB2FEDDF1B9FB"
"FC4AD89EA445809DDBD5BD595277990C0BE9366FBB2ECF7B057CC1C3DC8FB77B"
"F8456D07BBC95B3C1815F48E62B81468C3D4D9D96C0F48DAB04993BE8D91EDE5"
), 2048).unwrap();
let expected_prime = BoxedUint::from_be_slice(
&hex!(
"D0213A79425B665B719118448893EC3275600F63DBF85B77F4E8E99EF302F6E8"
"2596048F6DCA772DE6BBF1124DB84B0AFE61B03A8604AB0079ED53F3304797AD"
"01B38C44FE27A5A45E378483A804B56A4A967F48F01A866E721E67E4C9A1048A"
"F68927FAA43D6A85D93E7BF7074DBA797563FCABE12309B76653C6DB614DC231"
"CC556D9F25AC4841A02D31CDF3015B212307F9D0C79FEB5D3956CE53CC8FA165"
"1BE60761F19F74672489EAF9F215409F39956E77A82183F1F72BB2FEDDF1B9FB"
"FC4AD89EA445809DDBD5BD595277990C0BE9366FBB2ECF7B057CC1C3DC8FB77B"
"F8456D07BBC95B3C1815F48E62B81468C3D4D9D96C0F48DAB04993BE8D91EDE5"
),
2048,
)
.unwrap();
assert!(bool::from(key.primes()[0].ct_eq(&expected_prime)));

let expected_prime = BoxedUint::from_be_slice(&hex!(
"CE36C6810522ABE5D6465F36EB137DA3B9EA4A5F1D27C6614729EB8E5E2E5CB8"
"8E3EF1A473A21944B66557B3DC2CE462E4BF3446CB4990037E5672B1705CBAE8"
"1B65BAF967A266DC18EFE80F4DBBFE1A59063205CE2943CADF421CCE74AF7063"
"FD1A83AF3C39AF84525F59BDC1FF54815F52AFD1E8D4862B2C3654F6CFA83DC0"
"8E2A9D52B9F833C646AF7694467DFC5F7D7AD7B441895FCB7FFBED526324B015"
"4A15823F5107C89548EDDCB61DA5308C6CC834D4A0C16DFA6CA1D67B61A65677"
"EB1719CD125D0EF0DB8802FB76CFC17577BCB2510AE294E1BF8A9173A2B85C16"
"A6B508C98F2D770B7F3DE48D9E720C53E263680B57E7109410015745570652FD"
), 2048).unwrap();
let expected_prime = BoxedUint::from_be_slice(
&hex!(
"CE36C6810522ABE5D6465F36EB137DA3B9EA4A5F1D27C6614729EB8E5E2E5CB8"
"8E3EF1A473A21944B66557B3DC2CE462E4BF3446CB4990037E5672B1705CBAE8"
"1B65BAF967A266DC18EFE80F4DBBFE1A59063205CE2943CADF421CCE74AF7063"
"FD1A83AF3C39AF84525F59BDC1FF54815F52AFD1E8D4862B2C3654F6CFA83DC0"
"8E2A9D52B9F833C646AF7694467DFC5F7D7AD7B441895FCB7FFBED526324B015"
"4A15823F5107C89548EDDCB61DA5308C6CC834D4A0C16DFA6CA1D67B61A65677"
"EB1719CD125D0EF0DB8802FB76CFC17577BCB2510AE294E1BF8A9173A2B85C16"
"A6B508C98F2D770B7F3DE48D9E720C53E263680B57E7109410015745570652FD"
),
2048,
)
.unwrap();
assert!(bool::from(key.primes()[1].ct_eq(&expected_prime)));
}

Expand Down
96 changes: 60 additions & 36 deletions tests/pkcs8.rs
Original file line number Diff line number Diff line change
Expand Up @@ -71,20 +71,28 @@ fn decode_rsa2048_priv_der() {
"ABEB359CA2025268D004F9D66EB3D6F7ADC1139BAD40F16DDE639E11647376C1"
)
);
let expected_prime = BoxedUint::from_be_slice(&hex!(
"DCC061242D4E92AFAEE72AC513CA65B9F77036F9BD7E0E6E61461A7EF7654225"
"EC153C7E5C31A6157A6E5A13FF6E178E8758C1CB33D9D6BBE3179EF18998E422"
"ECDCBED78F4ECFDBE5F4FCD8AEC2C9D0DC86473CA9BD16D9D238D21FB5DDEFBE"
"B143CA61D0BD6AA8D91F33A097790E9640DBC91085DC5F26343BA3138F6B2D67"
), 1024).unwrap();
let expected_prime = BoxedUint::from_be_slice(
&hex!(
"DCC061242D4E92AFAEE72AC513CA65B9F77036F9BD7E0E6E61461A7EF7654225"
"EC153C7E5C31A6157A6E5A13FF6E178E8758C1CB33D9D6BBE3179EF18998E422"
"ECDCBED78F4ECFDBE5F4FCD8AEC2C9D0DC86473CA9BD16D9D238D21FB5DDEFBE"
"B143CA61D0BD6AA8D91F33A097790E9640DBC91085DC5F26343BA3138F6B2D67"
),
1024,
)
.unwrap();
assert!(bool::from(key.primes()[0].ct_eq(&expected_prime)));

let expected_prime = BoxedUint::from_be_slice(&hex!(
"D3F314757E40E954836F92BE24236AF2F0DA04A34653C180AF67E960086D93FD"
"E65CB23EFD9D09374762F5981E361849AF68CDD75394FF6A4E06EB69B209E422"
"8DB2DFA70E40F7F9750A528176647B788D0E5777A2CB8B22E3CD267FF70B4F3B"
"02D3AAFB0E18C590A564B03188B0AA5FC48156B07622214243BD1227EFA7F2F9"
), 1024).unwrap();
let expected_prime = BoxedUint::from_be_slice(
&hex!(
"D3F314757E40E954836F92BE24236AF2F0DA04A34653C180AF67E960086D93FD"
"E65CB23EFD9D09374762F5981E361849AF68CDD75394FF6A4E06EB69B209E422"
"8DB2DFA70E40F7F9750A528176647B788D0E5777A2CB8B22E3CD267FF70B4F3B"
"02D3AAFB0E18C590A564B03188B0AA5FC48156B07622214243BD1227EFA7F2F9"
),
1024,
)
.unwrap();
assert!(bool::from(key.primes()[1].ct_eq(&expected_prime)));

let _ = pkcs1v15::SigningKey::<Sha256>::from_pkcs8_der(RSA_2048_PRIV_DER).unwrap();
Expand Down Expand Up @@ -147,20 +155,28 @@ fn decode_rsa2048_pss_priv_der() {
"3783DA6236A07A0F332003D30748EC1C12556D7CA7587E8E07DCE1D95EC4A611"
)
);
let expected_prime = BoxedUint::from_be_slice(&hex!(
"E55FBA212239C846821579BE7E4D44336C700167A478F542032BEBF506D39453"
"82670B7D5B08D48E1B4A46EB22E54ABE21867FB6AD96444E00B386FF14710CB6"
"9D80111E3721CBE65CFA8A141A1492D5434BB7538481EBB27462D54EDD1EA55D"
"C2230431EE63C4A3609EC28BA67ABEE0DCA1A12E8E796BB5485A331BD27DC509"
), 1024).unwrap();
let expected_prime = BoxedUint::from_be_slice(
&hex!(
"E55FBA212239C846821579BE7E4D44336C700167A478F542032BEBF506D39453"
"82670B7D5B08D48E1B4A46EB22E54ABE21867FB6AD96444E00B386FF14710CB6"
"9D80111E3721CBE65CFA8A141A1492D5434BB7538481EBB27462D54EDD1EA55D"
"C2230431EE63C4A3609EC28BA67ABEE0DCA1A12E8E796BB5485A331BD27DC509"
),
1024,
)
.unwrap();
assert!(bool::from(key.primes()[0].ct_eq(&expected_prime)));

let expected_prime = BoxedUint::from_be_slice(&hex!(
"C3EC0875ED7B5B96340A9869DD9674B8CF0E52AD4092B57620A6AEA981DA0F10"
"13DF610CE1C8B630C111DA7214128E20FF8DA55B4CD8A2E145A8E370BF4F87C8"
"EB203E9752A8A442E562E09F455769B8DA35CCBA2A134F5DE274020B6A7620F0"
"3DE276FCBFDE2B0356438DD17DD40152AB80C1277B4849A643CB158AA07ADBC3"
), 1024).unwrap();
let expected_prime = BoxedUint::from_be_slice(
&hex!(
"C3EC0875ED7B5B96340A9869DD9674B8CF0E52AD4092B57620A6AEA981DA0F10"
"13DF610CE1C8B630C111DA7214128E20FF8DA55B4CD8A2E145A8E370BF4F87C8"
"EB203E9752A8A442E562E09F455769B8DA35CCBA2A134F5DE274020B6A7620F0"
"3DE276FCBFDE2B0356438DD17DD40152AB80C1277B4849A643CB158AA07ADBC3"
),
1024,
)
.unwrap();
assert!(bool::from(key.primes()[1].ct_eq(&expected_prime)));

let _ = pss::SigningKey::<Sha256>::from_pkcs8_der(RSA_2048_PSS_PRIV_DER).unwrap();
Expand Down Expand Up @@ -246,20 +262,28 @@ fn decode_rsa2048_priv_pem() {
"ABEB359CA2025268D004F9D66EB3D6F7ADC1139BAD40F16DDE639E11647376C1"
)
);
let expected_prime = BoxedUint::from_be_slice(&hex!(
"DCC061242D4E92AFAEE72AC513CA65B9F77036F9BD7E0E6E61461A7EF7654225"
"EC153C7E5C31A6157A6E5A13FF6E178E8758C1CB33D9D6BBE3179EF18998E422"
"ECDCBED78F4ECFDBE5F4FCD8AEC2C9D0DC86473CA9BD16D9D238D21FB5DDEFBE"
"B143CA61D0BD6AA8D91F33A097790E9640DBC91085DC5F26343BA3138F6B2D67"
), 1024).unwrap();
let expected_prime = BoxedUint::from_be_slice(
&hex!(
"DCC061242D4E92AFAEE72AC513CA65B9F77036F9BD7E0E6E61461A7EF7654225"
"EC153C7E5C31A6157A6E5A13FF6E178E8758C1CB33D9D6BBE3179EF18998E422"
"ECDCBED78F4ECFDBE5F4FCD8AEC2C9D0DC86473CA9BD16D9D238D21FB5DDEFBE"
"B143CA61D0BD6AA8D91F33A097790E9640DBC91085DC5F26343BA3138F6B2D67"
),
1024,
)
.unwrap();
assert!(bool::from(key.primes()[0].ct_eq(&expected_prime)));

let expected_prime = BoxedUint::from_be_slice(&hex!(
"D3F314757E40E954836F92BE24236AF2F0DA04A34653C180AF67E960086D93FD"
"E65CB23EFD9D09374762F5981E361849AF68CDD75394FF6A4E06EB69B209E422"
"8DB2DFA70E40F7F9750A528176647B788D0E5777A2CB8B22E3CD267FF70B4F3B"
"02D3AAFB0E18C590A564B03188B0AA5FC48156B07622214243BD1227EFA7F2F9"
), 1024).unwrap();
let expected_prime = BoxedUint::from_be_slice(
&hex!(
"D3F314757E40E954836F92BE24236AF2F0DA04A34653C180AF67E960086D93FD"
"E65CB23EFD9D09374762F5981E361849AF68CDD75394FF6A4E06EB69B209E422"
"8DB2DFA70E40F7F9750A528176647B788D0E5777A2CB8B22E3CD267FF70B4F3B"
"02D3AAFB0E18C590A564B03188B0AA5FC48156B07622214243BD1227EFA7F2F9"
),
1024,
)
.unwrap();
assert!(bool::from(key.primes()[1].ct_eq(&expected_prime)));

let _ = pkcs1v15::SigningKey::<Sha256>::from_pkcs8_pem(RSA_2048_PRIV_PEM).unwrap();
Expand Down

0 comments on commit ec599ee

Please sign in to comment.