Split the encryption test suite into two parts, to help reduce the cost of the test suite.
This commit is contained in:
@@ -91,6 +91,34 @@ fn rsa_decryption_tests()
|
|||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
#[ignore]
|
#[ignore]
|
||||||
|
fn rsa_long_decryption_tests()
|
||||||
|
{
|
||||||
|
run_test("tests/rsa/encryption.ext.test", 6, |case| {
|
||||||
|
let (neg1, dbytes) = case.get("d").unwrap();
|
||||||
|
let (neg2, nbytes) = case.get("n").unwrap();
|
||||||
|
let (neg3, hbytes) = case.get("h").unwrap();
|
||||||
|
let (neg4, lbytes) = case.get("l").unwrap();
|
||||||
|
let (neg5, msg) = case.get("m").unwrap();
|
||||||
|
let (neg6, cphtxt) = case.get("c").unwrap();
|
||||||
|
|
||||||
|
assert!(!neg1 & !neg2 & !neg3 & !neg4 & !neg5 & !neg6);
|
||||||
|
let label = String::from_utf8(lbytes.clone()).unwrap();
|
||||||
|
let key = RSAPrivate::new(UCN::from_bytes(nbytes),
|
||||||
|
UCN::from_bytes(dbytes));
|
||||||
|
let wrapped = match usize::from(UCN::from_bytes(hbytes)) {
|
||||||
|
0x1 => key.decrypt(&OAEPParams::new(Sha1::default(), label),cphtxt),
|
||||||
|
0x224 => key.decrypt(&OAEPParams::new(Sha224::default(),label),cphtxt),
|
||||||
|
0x256 => key.decrypt(&OAEPParams::new(Sha256::default(),label),cphtxt),
|
||||||
|
0x384 => key.decrypt(&OAEPParams::new(Sha384::default(),label),cphtxt),
|
||||||
|
0x512 => key.decrypt(&OAEPParams::new(Sha512::default(),label),cphtxt),
|
||||||
|
_ => panic!("Unacceptable hash")
|
||||||
|
};
|
||||||
|
let mymsg = wrapped.unwrap();
|
||||||
|
assert_eq!(msg, &mymsg);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
fn rsa_encryption_tests()
|
fn rsa_encryption_tests()
|
||||||
{
|
{
|
||||||
run_test("tests/rsa/encryption.test", 6, |case| {
|
run_test("tests/rsa/encryption.test", 6, |case| {
|
||||||
@@ -133,3 +161,48 @@ fn rsa_encryption_tests()
|
|||||||
assert_eq!(msg, &message);
|
assert_eq!(msg, &message);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
#[ignore]
|
||||||
|
fn rsa_long_encryption_tests()
|
||||||
|
{
|
||||||
|
run_test("tests/rsa/encryption.ext.test", 6, |case| {
|
||||||
|
let (neg1, dbytes) = case.get("d").unwrap();
|
||||||
|
let (neg2, nbytes) = case.get("n").unwrap();
|
||||||
|
let (neg3, hbytes) = case.get("h").unwrap();
|
||||||
|
let (neg4, lbytes) = case.get("l").unwrap();
|
||||||
|
let (neg5, msg) = case.get("m").unwrap();
|
||||||
|
|
||||||
|
// This one's a little tricky, because there's randomness in the
|
||||||
|
// encryption phase. So we can't just encrypt and see if we get the
|
||||||
|
// same value. Instead, we just use this as a test vector to round
|
||||||
|
// trip, and trust that the decryption test above makes sure we're
|
||||||
|
// not going off into la la land.
|
||||||
|
assert!(!neg1 & !neg2 & !neg3 & !neg4 & !neg5);
|
||||||
|
let label = String::from_utf8(lbytes.clone()).unwrap();
|
||||||
|
let private = RSAPrivate::new(UCN::from_bytes(nbytes),
|
||||||
|
UCN::from_bytes(dbytes));
|
||||||
|
let public = RSAPublic::new(UCN::from_bytes(nbytes),
|
||||||
|
UCN::from(65537u64));
|
||||||
|
let wrappedc = match usize::from(UCN::from_bytes(hbytes)) {
|
||||||
|
0x1 => public.encrypt(&OAEPParams::new(Sha1::default(), label.clone()), &msg),
|
||||||
|
0x224 => public.encrypt(&OAEPParams::new(Sha224::default(),label.clone()), &msg),
|
||||||
|
0x256 => public.encrypt(&OAEPParams::new(Sha256::default(),label.clone()), &msg),
|
||||||
|
0x384 => public.encrypt(&OAEPParams::new(Sha384::default(),label.clone()), &msg),
|
||||||
|
0x512 => public.encrypt(&OAEPParams::new(Sha512::default(),label.clone()), &msg),
|
||||||
|
_ => panic!("Unacceptable hash")
|
||||||
|
};
|
||||||
|
let ciphertext = wrappedc.unwrap();
|
||||||
|
let wrappedm = match usize::from(UCN::from_bytes(hbytes)) {
|
||||||
|
0x1 => private.decrypt(&OAEPParams::new(Sha1::default(), label), &ciphertext),
|
||||||
|
0x224 => private.decrypt(&OAEPParams::new(Sha224::default(),label), &ciphertext),
|
||||||
|
0x256 => private.decrypt(&OAEPParams::new(Sha256::default(),label), &ciphertext),
|
||||||
|
0x384 => private.decrypt(&OAEPParams::new(Sha384::default(),label), &ciphertext),
|
||||||
|
0x512 => private.decrypt(&OAEPParams::new(Sha512::default(),label), &ciphertext),
|
||||||
|
_ => panic!("Unacceptable hash")
|
||||||
|
};
|
||||||
|
let message = wrappedm.unwrap();
|
||||||
|
|
||||||
|
assert_eq!(msg, &message);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|||||||
@@ -17,9 +17,6 @@ import System.ProgressBar
|
|||||||
import System.Random
|
import System.Random
|
||||||
import Debug.Trace
|
import Debug.Trace
|
||||||
|
|
||||||
numThreads :: Int
|
|
||||||
numThreads = 4
|
|
||||||
|
|
||||||
keySizes :: [Int]
|
keySizes :: [Int]
|
||||||
keySizes = [512,1024,2048,3072,4096,7680,8192,15360]
|
keySizes = [512,1024,2048,3072,4096,7680,8192,15360]
|
||||||
|
|
||||||
@@ -160,10 +157,12 @@ runEncryptionGenerator inputs outputs =
|
|||||||
("c", showBinary (BSL.toStrict c))]
|
("c", showBinary (BSL.toStrict c))]
|
||||||
go Nothing g5
|
go Nothing g5
|
||||||
|
|
||||||
writeData :: Chan [(String,String)] -> (Progress -> IO ()) -> Handle -> IO ()
|
writeData :: Chan [(String,String)] -> Int -> (Progress -> IO ()) ->
|
||||||
writeData outputChan progressBar hndl = go 0
|
Handle ->
|
||||||
|
IO ()
|
||||||
|
writeData outputChan countInt progressBar hndl = go 0
|
||||||
where
|
where
|
||||||
count = fromIntegral (length keyIterations)
|
count = fromIntegral countInt
|
||||||
go x | x == count = return ()
|
go x | x == count = return ()
|
||||||
| otherwise = do output <- readChan outputChan
|
| otherwise = do output <- readChan outputChan
|
||||||
dump hndl output
|
dump hndl output
|
||||||
@@ -175,6 +174,8 @@ main :: IO ()
|
|||||||
main =
|
main =
|
||||||
do sizeChan <- newChan
|
do sizeChan <- newChan
|
||||||
outputChan <- newChan
|
outputChan <- newChan
|
||||||
|
let count = length keyIterations
|
||||||
|
numThreads <- getNumCapabilities
|
||||||
--
|
--
|
||||||
unless (all (`elem` keySizes) keyIterations) $
|
unless (all (`elem` keySizes) keyIterations) $
|
||||||
fail "System setup failure."
|
fail "System setup failure."
|
||||||
@@ -183,14 +184,26 @@ main =
|
|||||||
forkIO $ runSignatureGenerator sizeChan outputChan
|
forkIO $ runSignatureGenerator sizeChan outputChan
|
||||||
let bar = autoProgressBar (msg "Generating signature tests") percentage 60
|
let bar = autoProgressBar (msg "Generating signature tests") percentage 60
|
||||||
writeList2Chan sizeChan keyIterations
|
writeList2Chan sizeChan keyIterations
|
||||||
g1 <- withFile "signature.test" WriteMode (writeData outputChan bar)
|
g1 <- withFile "signature.test" WriteMode $
|
||||||
|
writeData outputChan count bar
|
||||||
mapM_ killThread sigthrs
|
mapM_ killThread sigthrs
|
||||||
--
|
--
|
||||||
|
encthrs <- replicateM numThreads $
|
||||||
|
forkIO $ runEncryptionGenerator sizeChan outputChan
|
||||||
|
let bar = autoProgressBar (msg "Generating encryption tests") percentage 60
|
||||||
|
writeList2Chan sizeChan (take 1000 keyIterations)
|
||||||
|
g2 <- withFile "encryption.test" WriteMode $
|
||||||
|
writeData outputChan 1000 bar
|
||||||
|
mapM_ killThread encthrs
|
||||||
|
--
|
||||||
replicateM_ numThreads $
|
replicateM_ numThreads $
|
||||||
void $ forkIO $ runEncryptionGenerator sizeChan outputChan
|
void $ forkIO $ runEncryptionGenerator sizeChan outputChan
|
||||||
let bar = autoProgressBar (msg "Generating encryption tests") percentage 60
|
let bar = autoProgressBar (msg "Generating encryption tests") percentage 60
|
||||||
writeList2Chan sizeChan keyIterations
|
writeList2Chan sizeChan (drop 1000 keyIterations)
|
||||||
g2 <- withFile "encryption.test" WriteMode (writeData outputChan bar)
|
let i = length keyIterations - 1
|
||||||
|
g2 <- withFile "encryption.ext.test" WriteMode $
|
||||||
|
writeData outputChan (count - 1000) bar
|
||||||
|
--
|
||||||
return ()
|
return ()
|
||||||
|
|
||||||
randomElement :: CryptoRandomGen g => g -> [a] -> (a, g)
|
randomElement :: CryptoRandomGen g => g -> [a] -> (a, g)
|
||||||
|
|||||||
2598
tests/rsa/encryption.ext.test
Normal file
2598
tests/rsa/encryption.ext.test
Normal file
File diff suppressed because it is too large
Load Diff
File diff suppressed because one or more lines are too long
Reference in New Issue
Block a user