Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix Ciphersaber2 key concatenation #1765

Merged
merged 1 commit into from
Apr 1, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/core/lib/CipherSaber2.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
* @license Apache-2.0
*/
export function encode(tempIVP, key, rounds, input) {
const ivp = new Uint8Array(key.concat(tempIVP));
const ivp = new Uint8Array([...key, ...tempIVP]);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

key is a number[] and tempIVP is a Buffer, so I was initially surprised that they can't be concatenated, but a quick test shows it's true:

> const tempIVP = Buffer.from([1, 2])
undefined
> const key = [3, 4]
undefined
> key.concat(tempIVP)
[ 3, 4, <Buffer 01 02> ]

An alternative seems to be spreading just the buffer (e.g. key.concat(...tempIVP)), but explicitly spreading both seems like a nicer solution anyway. Nice catch!

const state = new Array(256).fill(0);
let j = 0, i = 0;
const result = [];
Expand Down
9 changes: 6 additions & 3 deletions tests/operations/tests/CipherSaber2.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,16 @@ TestRegister.addTests([
],
},
{
// input taken from https://ciphersaber.gurus.org/
name: "CipherSaber2 Decrypt",
input: "\x5d\xd9\x7f\xeb\x77\x3c\x42\x9d\xfe\x9c\x3b\x21\x63\xbd\x53\x38\x18\x7c\x36\x37",
expectedOutput: "helloworld",
input: "\x6f\x6d\x0b\xab\xf3\xaa\x67\x19\x03\x15\x30\xed\xb6\x77" +
"\xca\x74\xe0\x08\x9d\xd0\xe7\xb8\x85\x43\x56\xbb\x14\x48\xe3" +
"\x7c\xdb\xef\xe7\xf3\xa8\x4f\x4f\x5f\xb3\xfd",
expectedOutput: "This is a test of CipherSaber.",
recipeConfig: [
{
op: "CipherSaber2 Decrypt",
args: [{ "option": "Latin1", "string": "test" }, 20],
args: [{ "option": "Latin1", "string": "asdfg" }, 1],
},
],
},
Expand Down
Loading