Add Salsa20 tests

This commit is contained in:
Andy Wang 2020-01-13 23:02:48 +00:00
parent 4df8606f7b
commit f5049d6707
3 changed files with 125 additions and 0 deletions

View file

@ -828,6 +828,20 @@ pCGTErs=
assert.strictEqual(result.toString().length, 4582);
}),
it("Salsa20 Encrypt", () => {
const result = chef.salsa20Encrypt("Don't mention the Scottish play", {
key: {
string: "0011223344556677001122334455667700112233445566770011223344556677",
option: "hex",
},
nonce: {
string: "Macbeth!",
option: "utf8"
},
});
assert.strictEqual(result.toString(), "baaabfa62278b718790c893046d2cf24c4ae5d3930755faf0dd9506235064e");
}),
it("Scan for embedded files", () => {
const result = chef.scanForEmbeddedFiles(fs.readFileSync("src/web/static/images/cook_male-32x32.png"));
const expected = "Scanning data for 'magic bytes' which may indicate embedded files.";

View file

@ -70,6 +70,7 @@ import "./tests/Regex.mjs";
import "./tests/Register.mjs";
import "./tests/RemoveDiacritics.mjs";
import "./tests/Rotate.mjs";
import "./tests/Salsa20.mjs";
import "./tests/SeqUtils.mjs";
import "./tests/SetDifference.mjs";
import "./tests/SetIntersection.mjs";

View file

@ -0,0 +1,110 @@
import TestRegister from "../../lib/TestRegister.mjs";
TestRegister.addTests([
// The following Python script, using PyCryptoDome, was used to generate the test vectors
/*
from Crypto.Cipher import Salsa20
import binascii
input_data = b"The quick brown fox jumps over the lazy dog."
keyHex = "0000000000000000000000000000000000000000000000000000000000000000"
nonceHex = "0000000000000000"
key = binascii.unhexlify(keyHex)
nonce = binascii.unhexlify(nonceHex)
cipher = Salsa20.new(key, nonce)
cipher_text = cipher.encrypt(input_data)
cipher_text = binascii.hexlify(cipher_text).decode("UTF-8")
print("Key: {}\nNonce: {}\nCiphertext: {}".format(keyHex, nonceHex, cipher_text))
*/
{
name: "Salsa20 Encrypt: 128 bit key, ASCII",
input: "The quick brown fox jumps over the lazy dog.",
expectedOutput: "317bc88ebe9e7b2f779e09a8801e656f9d6fc8dcc6965198755944c271f239ec5cda91a3bc732122a286390b",
recipeConfig: [
{
"op": "Salsa20 Encrypt",
"args": [
{"option": "Hex", "string": "00000000000000000000000000000000"},
{"option": "Hex", "string": "0000000000000000"},
"Raw", "Hex"
]
}
],
},
{
name: "Salsa20 Decrypt: 128 bit key, ASCII",
input: "317bc88ebe9e7b2f779e09a8801e656f9d6fc8dcc6965198755944c271f239ec5cda91a3bc732122a286390b",
expectedOutput: "The quick brown fox jumps over the lazy dog.",
recipeConfig: [
{
"op": "Salsa20 Decrypt",
"args": [
{"option": "Hex", "string": "00000000000000000000000000000000"},
{"option": "Hex", "string": "0000000000000000"},
"Hex", "Raw"
]
}
],
},
{
name: "Salsa20 Encrypt: 256 bit key, ASCII",
input: "The quick brown fox jumps over the lazy dog.",
expectedOutput: "ceff937bea391b78fd2a05532a8bc6f485411fd97b6bc409bdbc2750e518ce92558ce0b64aad803ed8dd04b5",
recipeConfig: [
{
"op": "Salsa20 Encrypt",
"args": [
{"option": "Hex", "string": "0000000000000000000000000000000000000000000000000000000000000000"},
{"option": "Hex", "string": "0000000000000000"},
"Raw", "Hex"
]
}
],
},
{
name: "Salsa20 Decrypt: 256 bit key, ASCII",
input: "ceff937bea391b78fd2a05532a8bc6f485411fd97b6bc409bdbc2750e518ce92558ce0b64aad803ed8dd04b5",
expectedOutput: "The quick brown fox jumps over the lazy dog.",
recipeConfig: [
{
"op": "Salsa20 Decrypt",
"args": [
{"option": "Hex", "string": "0000000000000000000000000000000000000000000000000000000000000000"},
{"option": "Hex", "string": "0000000000000000"},
"Hex", "Raw"
]
}
],
},
{
name: "Salsa20 Encrypt: 256 bit key, Hex",
input: "8ad48372ec567a31c045cec2076b4ce9da3d121c05167a6e0da55097ba83da13c949aaea0192d793",
expectedOutput: "4d92211d0fe3d6e1af3f0367f2220c915ede3420fe407faaa501e6c15ed5d8dc7b60bc877c82588f",
recipeConfig: [
{
"op": "Salsa20 Encrypt",
"args": [
{"option": "Hex", "string": "17719ee20528b23779a0c87a4fc321b69d8917b4ecf5273bf2464dc0cfe23399"},
{"option": "Hex", "string": "69df3240cae9fb69"},
"Hex", "Hex"
]
}
],
},
{
name: "Salsa20 Decrypt: 256 bit key, Hex",
input: "4d92211d0fe3d6e1af3f0367f2220c915ede3420fe407faaa501e6c15ed5d8dc7b60bc877c82588f",
expectedOutput: "8ad48372ec567a31c045cec2076b4ce9da3d121c05167a6e0da55097ba83da13c949aaea0192d793",
recipeConfig: [
{
"op": "Salsa20 Decrypt",
"args": [
{"option": "Hex", "string": "17719ee20528b23779a0c87a4fc321b69d8917b4ecf5273bf2464dc0cfe23399"},
{"option": "Hex", "string": "69df3240cae9fb69"},
"Hex", "Hex"
]
}
],
}
]);