Skip to content

Commit

Permalink
Fix ChaCha operation Raw output
Browse files Browse the repository at this point in the history
Previously, an array type error prevented any output when selecting
the 'Raw' output option for the ChaCha operation. This did not
show up in tests, as they all compared to hex values.

This also adds a test (relying on the 'To Hex' operation) that
catches this.
  • Loading branch information
joostrijneveld committed Jul 30, 2023
1 parent 6ed9d45 commit cb98672
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/core/operations/ChaCha.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,7 @@ ChaCha uses a nonce of 8 or 12 bytes (64 or 96 bits).`);
if (outputType === "Hex") {
return toHex(output);
} else {
return Utils.arrayBufferToStr(output);
return Utils.arrayBufferToStr(Uint8Array.from(output).buffer);
}
}

Expand Down
19 changes: 19 additions & 0 deletions tests/operations/tests/ChaCha.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,25 @@ ChaCha uses a nonce of 8 or 12 bytes (64 or 96 bits).`,
}
],
},
{
name: "ChaCha: RFC8439 Raw output",
input: "Ladies and Gentlemen of the class of '99: If I could offer you only one tip for the future, sunscreen would be it.",
expectedOutput: "6e 2e 35 9a 25 68 f9 80 41 ba 07 28 dd 0d 69 81 e9 7e 7a ec 1d 43 60 c2 0a 27 af cc fd 9f ae 0b f9 1b 65 c5 52 47 33 ab 8f 59 3d ab cd 62 b3 57 16 39 d6 24 e6 51 52 ab 8f 53 0c 35 9f 08 61 d8 07 ca 0d bf 50 0d 6a 61 56 a3 8e 08 8a 22 b6 5e 52 bc 51 4d 16 cc f8 06 81 8c e9 1a b7 79 37 36 5a f9 0b bf 74 a3 5b e6 b4 0b 8e ed f2 78 5e 42 87 4d",
recipeConfig: [
{
"op": "ChaCha",
"args": [
{"option": "Hex", "string": "00:01:02:03:04:05:06:07:08:09:0a:0b:0c:0d:0e:0f:10:11:12:13:14:15:16:17:18:19:1a:1b:1c:1d:1e:1f"},
{"option": "Hex", "string": "00:00:00:00:00:00:00:4a:00:00:00:00"},
1, "20", "Raw", "Raw",
]
},
{
"op": "To Hex",
"args": []
},
],
},
{
name: "ChaCha: draft-strombergson-chacha-test-vectors-01 TC7.1",
input: "00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00",
Expand Down

0 comments on commit cb98672

Please sign in to comment.