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

Conversation

zb3
Copy link
Contributor

@zb3 zb3 commented Apr 1, 2024

Previously the generated key was invalid because an Uint8Array was concatenated into a normal array but that wasn't supported by the concat function.

Effectively the IV was discarded so the cipher did not work :)
This should fix #1723

The concat method does not handle typed arrays as arguments.
@@ -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!

@a3957273 a3957273 merged commit 8a17aba into gchq:master Apr 1, 2024
4 checks passed
This pull request was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Bug report: CipherSaber2 decrypt fails the tests on http://ciphersaber.gurus.org/
2 participants