cyberchef 11.1.0 → 11.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/AGENTS.md +75 -0
- package/CHANGELOG.md +173 -2
- package/Dockerfile +2 -2
- package/Gruntfile.js +1 -0
- package/README.md +7 -6
- package/SECURITY.md +3 -1
- package/package.json +22 -21
- package/src/core/Chef.mjs +2 -0
- package/src/core/Dish.mjs +1 -5
- package/src/core/Ingredient.mjs +92 -0
- package/src/core/Operation.mjs +19 -0
- package/src/core/Recipe.mjs +4 -0
- package/src/core/Utils.mjs +48 -0
- package/src/core/config/Categories.json +22 -6
- package/src/core/config/OperationConfig.json +4774 -1228
- package/src/core/config/modules/Ciphers.mjs +20 -0
- package/src/core/config/modules/Crypto.mjs +10 -0
- package/src/core/config/modules/Default.mjs +8 -0
- package/src/core/config/modules/File.mjs +16 -0
- package/src/core/config/modules/OpModules.mjs +2 -0
- package/src/core/config/scripts/generateHTMLEntities.mjs +139 -0
- package/src/core/config/scripts/htmlEntityOverrides.mjs +86 -0
- package/src/core/dishTypes/DishType.mjs +1 -1
- package/src/core/errors/ExcludedOperationError.mjs +1 -1
- package/src/core/lib/Arithmetic.mjs +21 -5
- package/src/core/lib/BigIntUtils.mjs +0 -1
- package/src/core/lib/COBS.mjs +86 -0
- package/src/core/lib/Charts.mjs +3 -3
- package/src/core/lib/Decimal.mjs +5 -5
- package/src/core/lib/HTMLEntities.mjs +2068 -0
- package/src/core/lib/Present.mjs +422 -0
- package/src/core/lib/Protocol.mjs +8 -6
- package/src/core/lib/TEA.mjs +494 -0
- package/src/core/lib/TLVParser.mjs +16 -7
- package/src/core/lib/Twofish.mjs +608 -0
- package/src/core/operations/AsconDecrypt.mjs +112 -0
- package/src/core/operations/AsconEncrypt.mjs +108 -0
- package/src/core/operations/AsconHash.mjs +49 -0
- package/src/core/operations/AsconMAC.mjs +68 -0
- package/src/core/operations/AutomatedValidationTestOp.mjs +84 -0
- package/src/core/operations/AvroToJSON.mjs +1 -1
- package/src/core/operations/BLAKE3.mjs +5 -1
- package/src/core/operations/BcryptCompare.mjs +11 -5
- package/src/core/operations/BitShiftLeft.mjs +4 -1
- package/src/core/operations/Bzip2Compress.mjs +1 -1
- package/src/core/operations/DechunkHTTPResponse.mjs +4 -1
- package/src/core/operations/ExtendedGCD.mjs +101 -0
- package/src/core/operations/FromBase.mjs +2 -1
- package/src/core/operations/FromCOBS.mjs +38 -0
- package/src/core/operations/FromDecimal.mjs +6 -1
- package/src/core/operations/FromHTMLEntity.mjs +2 -1458
- package/src/core/operations/GenerateDeBruijnSequence.mjs +8 -0
- package/src/core/operations/GenerateHOTP.mjs +21 -6
- package/src/core/operations/GenerateImage.mjs +22 -10
- package/src/core/operations/GeneratePrime.mjs +154 -0
- package/src/core/operations/GenerateTOTP.mjs +24 -7
- package/src/core/operations/Gzip.mjs +1 -3
- package/src/core/operations/Jsonata.mjs +12 -0
- package/src/core/operations/MIMEDecoding.mjs +1 -1
- package/src/core/operations/MOD.mjs +62 -0
- package/src/core/operations/ModularInverse.mjs +107 -0
- package/src/core/operations/PRESENTDecrypt.mjs +94 -0
- package/src/core/operations/PRESENTEncrypt.mjs +94 -0
- package/src/core/operations/ParityBit.mjs +1 -1
- package/src/core/operations/ParseIPv4Header.mjs +1 -1
- package/src/core/operations/ParseURI.mjs +18 -5
- package/src/core/operations/PseudoRandomNumberGenerator.mjs +2 -1
- package/src/core/operations/RandomPrime.mjs +154 -0
- package/src/core/operations/RenderPDF.mjs +100 -0
- package/src/core/operations/SHA2.mjs +1 -1
- package/src/core/operations/SM4Encrypt.mjs +1 -1
- package/src/core/operations/SetDifference.mjs +8 -1
- package/src/core/operations/SetIntersection.mjs +8 -1
- package/src/core/operations/ShowOnMap.mjs +14 -2
- package/src/core/operations/TEADecrypt.mjs +98 -0
- package/src/core/operations/TEAEncrypt.mjs +98 -0
- package/src/core/operations/ToBase.mjs +4 -4
- package/src/core/operations/ToBase32.mjs +20 -4
- package/src/core/operations/ToBinary.mjs +4 -1
- package/src/core/operations/ToCOBS.mjs +38 -0
- package/src/core/operations/ToHTMLEntity.mjs +7 -1430
- package/src/core/operations/ToHexdump.mjs +7 -1
- package/src/core/operations/TwofishDecrypt.mjs +94 -0
- package/src/core/operations/TwofishEncrypt.mjs +94 -0
- package/src/core/operations/URLEncode.mjs +22 -18
- package/src/core/operations/UnescapeUnicodeCharacters.mjs +2 -1
- package/src/core/operations/ViewBitPlane.mjs +9 -3
- package/src/core/operations/Wrap.mjs +5 -0
- package/src/core/operations/XORBruteForce.mjs +4 -1
- package/src/core/operations/XORChecksum.mjs +10 -3
- package/src/core/operations/XTEADecrypt.mjs +110 -0
- package/src/core/operations/XTEAEncrypt.mjs +110 -0
- package/src/core/operations/index.mjs +42 -0
- package/src/core/vendor/ascon.mjs +162 -0
- package/src/core/vendor/htmlEntities/entity.json +2233 -0
- package/src/core/vendor/htmlEntities/entity.txt +14 -0
- package/src/node/api.mjs +4 -1
- package/src/node/index.mjs +105 -0
- package/src/web/HTMLOperation.mjs +2 -1
- package/src/web/stylesheets/layout/_io.css +8 -0
- package/tests/browser/00_nightwatch.js +26 -0
- package/tests/browser/02_ops.js +20 -4
- package/tests/node/index.mjs +2 -0
- package/tests/node/tests/Dish.mjs +19 -0
- package/tests/node/tests/NodeDish.mjs +36 -0
- package/tests/node/tests/ToHTMLEntity.mjs +82 -0
- package/tests/node/tests/Utils.mjs +77 -0
- package/tests/node/tests/lib/ChartsProtocolPrototypePollution.mjs +90 -0
- package/tests/node/tests/nodeApi.mjs +33 -1
- package/tests/node/tests/operations.mjs +26 -1
- package/tests/operations/index.mjs +17 -0
- package/tests/operations/tests/Arithmetic.mjs +33 -0
- package/tests/operations/tests/Ascon.mjs +501 -0
- package/tests/operations/tests/AutomatedValidation.mjs +154 -0
- package/tests/operations/tests/BLAKE3.mjs +39 -1
- package/tests/operations/tests/Base32.mjs +22 -0
- package/tests/operations/tests/COBS.mjs +476 -0
- package/tests/operations/tests/CharEnc.mjs +2 -2
- package/tests/operations/tests/DechunkHTTPResponse.mjs +66 -0
- package/tests/operations/tests/ExtendedGCD.mjs +78 -0
- package/tests/operations/tests/FromBase.mjs +66 -0
- package/tests/operations/tests/FromDecimal.mjs +55 -0
- package/tests/operations/tests/GenerateLoremIpsum.mjs +2 -2
- package/tests/operations/tests/Gzip.mjs +60 -0
- package/tests/operations/tests/HTMLEntity.mjs +126 -0
- package/tests/operations/tests/Hash.mjs +44 -0
- package/tests/operations/tests/Hexdump.mjs +11 -0
- package/tests/operations/tests/Image.mjs +26 -0
- package/tests/operations/tests/Jsonata.mjs +23 -0
- package/tests/operations/tests/MIMEDecoding.mjs +33 -0
- package/tests/operations/tests/MOD.mjs +208 -0
- package/tests/operations/tests/Median.mjs +33 -0
- package/tests/operations/tests/ModularInverse.mjs +78 -0
- package/tests/operations/tests/OTP.mjs +167 -2
- package/tests/operations/tests/PRESENT.mjs +465 -0
- package/tests/operations/tests/ParseIPv4Header.mjs +11 -0
- package/tests/operations/tests/ParseTLV.mjs +41 -0
- package/tests/operations/tests/RenderPDF.mjs +55 -0
- package/tests/operations/tests/SM2.mjs +1 -1
- package/tests/operations/tests/SetDifference.mjs +22 -0
- package/tests/operations/tests/SetIntersection.mjs +23 -1
- package/tests/operations/tests/ShowOnMap.mjs +61 -0
- package/tests/operations/tests/TEA.mjs +566 -0
- package/tests/operations/tests/Twofish.mjs +486 -0
- package/tests/operations/tests/URLEncodeDecode.mjs +26 -0
- package/tests/operations/tests/UnescapeUnicodeCharacters.mjs +88 -0
- package/tests/operations/tests/Wrap.mjs +44 -0
- package/webpack.config.js +3 -3
|
@@ -25,7 +25,12 @@ import AnalyseHash from "./AnalyseHash.mjs";
|
|
|
25
25
|
import AnalyseUUID from "./AnalyseUUID.mjs";
|
|
26
26
|
import Argon2 from "./Argon2.mjs";
|
|
27
27
|
import Argon2Compare from "./Argon2Compare.mjs";
|
|
28
|
+
import AsconDecrypt from "./AsconDecrypt.mjs";
|
|
29
|
+
import AsconEncrypt from "./AsconEncrypt.mjs";
|
|
30
|
+
import AsconHash from "./AsconHash.mjs";
|
|
31
|
+
import AsconMAC from "./AsconMAC.mjs";
|
|
28
32
|
import AtbashCipher from "./AtbashCipher.mjs";
|
|
33
|
+
import AutomatedValidationTestOp from "./AutomatedValidationTestOp.mjs";
|
|
29
34
|
import AvroToJSON from "./AvroToJSON.mjs";
|
|
30
35
|
import BLAKE2b from "./BLAKE2b.mjs";
|
|
31
36
|
import BLAKE2s from "./BLAKE2s.mjs";
|
|
@@ -118,6 +123,7 @@ import EscapeSmartCharacters from "./EscapeSmartCharacters.mjs";
|
|
|
118
123
|
import EscapeString from "./EscapeString.mjs";
|
|
119
124
|
import EscapeUnicodeCharacters from "./EscapeUnicodeCharacters.mjs";
|
|
120
125
|
import ExpandAlphabetRange from "./ExpandAlphabetRange.mjs";
|
|
126
|
+
import ExtendedGCD from "./ExtendedGCD.mjs";
|
|
121
127
|
import ExtractAudioMetadata from "./ExtractAudioMetadata.mjs";
|
|
122
128
|
import ExtractDates from "./ExtractDates.mjs";
|
|
123
129
|
import ExtractDomains from "./ExtractDomains.mjs";
|
|
@@ -161,6 +167,7 @@ import FromBase92 from "./FromBase92.mjs";
|
|
|
161
167
|
import FromBech32 from "./FromBech32.mjs";
|
|
162
168
|
import FromBinary from "./FromBinary.mjs";
|
|
163
169
|
import FromBraille from "./FromBraille.mjs";
|
|
170
|
+
import FromCOBS from "./FromCOBS.mjs";
|
|
164
171
|
import FromCaseInsensitiveRegex from "./FromCaseInsensitiveRegex.mjs";
|
|
165
172
|
import FromCharcode from "./FromCharcode.mjs";
|
|
166
173
|
import FromDecimal from "./FromDecimal.mjs";
|
|
@@ -192,6 +199,7 @@ import GenerateHOTP from "./GenerateHOTP.mjs";
|
|
|
192
199
|
import GenerateImage from "./GenerateImage.mjs";
|
|
193
200
|
import GenerateLoremIpsum from "./GenerateLoremIpsum.mjs";
|
|
194
201
|
import GeneratePGPKeyPair from "./GeneratePGPKeyPair.mjs";
|
|
202
|
+
import GeneratePrime from "./GeneratePrime.mjs";
|
|
195
203
|
import GenerateQRCode from "./GenerateQRCode.mjs";
|
|
196
204
|
import GenerateRSAKeyPair from "./GenerateRSAKeyPair.mjs";
|
|
197
205
|
import GenerateTOTP from "./GenerateTOTP.mjs";
|
|
@@ -261,11 +269,13 @@ import MD4 from "./MD4.mjs";
|
|
|
261
269
|
import MD5 from "./MD5.mjs";
|
|
262
270
|
import MD6 from "./MD6.mjs";
|
|
263
271
|
import MIMEDecoding from "./MIMEDecoding.mjs";
|
|
272
|
+
import MOD from "./MOD.mjs";
|
|
264
273
|
import Magic from "./Magic.mjs";
|
|
265
274
|
import Mean from "./Mean.mjs";
|
|
266
275
|
import Median from "./Median.mjs";
|
|
267
276
|
import Merge from "./Merge.mjs";
|
|
268
277
|
import MicrosoftScriptDecoder from "./MicrosoftScriptDecoder.mjs";
|
|
278
|
+
import ModularInverse from "./ModularInverse.mjs";
|
|
269
279
|
import MultipleBombe from "./MultipleBombe.mjs";
|
|
270
280
|
import Multiply from "./Multiply.mjs";
|
|
271
281
|
import MurmurHash3 from "./MurmurHash3.mjs";
|
|
@@ -289,6 +299,8 @@ import PGPVerify from "./PGPVerify.mjs";
|
|
|
289
299
|
import PHPDeserialize from "./PHPDeserialize.mjs";
|
|
290
300
|
import PHPSerialize from "./PHPSerialize.mjs";
|
|
291
301
|
import PLISTViewer from "./PLISTViewer.mjs";
|
|
302
|
+
import PRESENTDecrypt from "./PRESENTDecrypt.mjs";
|
|
303
|
+
import PRESENTEncrypt from "./PRESENTEncrypt.mjs";
|
|
292
304
|
import PadLines from "./PadLines.mjs";
|
|
293
305
|
import ParityBit from "./ParityBit.mjs";
|
|
294
306
|
import ParseASN1HexString from "./ParseASN1HexString.mjs";
|
|
@@ -340,6 +352,7 @@ import RSAVerify from "./RSAVerify.mjs";
|
|
|
340
352
|
import Rabbit from "./Rabbit.mjs";
|
|
341
353
|
import RailFenceCipherDecode from "./RailFenceCipherDecode.mjs";
|
|
342
354
|
import RailFenceCipherEncode from "./RailFenceCipherEncode.mjs";
|
|
355
|
+
import RandomPrime from "./RandomPrime.mjs";
|
|
343
356
|
import RandomizeColourPalette from "./RandomizeColourPalette.mjs";
|
|
344
357
|
import RawDeflate from "./RawDeflate.mjs";
|
|
345
358
|
import RawInflate from "./RawInflate.mjs";
|
|
@@ -353,6 +366,7 @@ import RemoveNullBytes from "./RemoveNullBytes.mjs";
|
|
|
353
366
|
import RemoveWhitespace from "./RemoveWhitespace.mjs";
|
|
354
367
|
import RenderImage from "./RenderImage.mjs";
|
|
355
368
|
import RenderMarkdown from "./RenderMarkdown.mjs";
|
|
369
|
+
import RenderPDF from "./RenderPDF.mjs";
|
|
356
370
|
import ResizeImage from "./ResizeImage.mjs";
|
|
357
371
|
import Return from "./Return.mjs";
|
|
358
372
|
import Reverse from "./Reverse.mjs";
|
|
@@ -410,6 +424,8 @@ import SwapEndianness from "./SwapEndianness.mjs";
|
|
|
410
424
|
import SymmetricDifference from "./SymmetricDifference.mjs";
|
|
411
425
|
import SyntaxHighlighter from "./SyntaxHighlighter.mjs";
|
|
412
426
|
import TCPIPChecksum from "./TCPIPChecksum.mjs";
|
|
427
|
+
import TEADecrypt from "./TEADecrypt.mjs";
|
|
428
|
+
import TEAEncrypt from "./TEAEncrypt.mjs";
|
|
413
429
|
import Tail from "./Tail.mjs";
|
|
414
430
|
import TakeBytes from "./TakeBytes.mjs";
|
|
415
431
|
import TakeNthBytes from "./TakeNthBytes.mjs";
|
|
@@ -429,6 +445,7 @@ import ToBase92 from "./ToBase92.mjs";
|
|
|
429
445
|
import ToBech32 from "./ToBech32.mjs";
|
|
430
446
|
import ToBinary from "./ToBinary.mjs";
|
|
431
447
|
import ToBraille from "./ToBraille.mjs";
|
|
448
|
+
import ToCOBS from "./ToCOBS.mjs";
|
|
432
449
|
import ToCamelCase from "./ToCamelCase.mjs";
|
|
433
450
|
import ToCaseInsensitiveRegex from "./ToCaseInsensitiveRegex.mjs";
|
|
434
451
|
import ToCharcode from "./ToCharcode.mjs";
|
|
@@ -453,6 +470,8 @@ import ToUpperCase from "./ToUpperCase.mjs";
|
|
|
453
470
|
import TranslateDateTimeFormat from "./TranslateDateTimeFormat.mjs";
|
|
454
471
|
import TripleDESDecrypt from "./TripleDESDecrypt.mjs";
|
|
455
472
|
import TripleDESEncrypt from "./TripleDESEncrypt.mjs";
|
|
473
|
+
import TwofishDecrypt from "./TwofishDecrypt.mjs";
|
|
474
|
+
import TwofishEncrypt from "./TwofishEncrypt.mjs";
|
|
456
475
|
import Typex from "./Typex.mjs";
|
|
457
476
|
import UNIXTimestampToWindowsFiletime from "./UNIXTimestampToWindowsFiletime.mjs";
|
|
458
477
|
import URLDecode from "./URLDecode.mjs";
|
|
@@ -479,6 +498,8 @@ import XORBruteForce from "./XORBruteForce.mjs";
|
|
|
479
498
|
import XORChecksum from "./XORChecksum.mjs";
|
|
480
499
|
import XPathExpression from "./XPathExpression.mjs";
|
|
481
500
|
import XSalsa20 from "./XSalsa20.mjs";
|
|
501
|
+
import XTEADecrypt from "./XTEADecrypt.mjs";
|
|
502
|
+
import XTEAEncrypt from "./XTEAEncrypt.mjs";
|
|
482
503
|
import XXTEADecrypt from "./XXTEADecrypt.mjs";
|
|
483
504
|
import XXTEAEncrypt from "./XXTEAEncrypt.mjs";
|
|
484
505
|
import YAMLToJSON from "./YAMLToJSON.mjs";
|
|
@@ -508,7 +529,12 @@ export {
|
|
|
508
529
|
AnalyseUUID,
|
|
509
530
|
Argon2,
|
|
510
531
|
Argon2Compare,
|
|
532
|
+
AsconDecrypt,
|
|
533
|
+
AsconEncrypt,
|
|
534
|
+
AsconHash,
|
|
535
|
+
AsconMAC,
|
|
511
536
|
AtbashCipher,
|
|
537
|
+
AutomatedValidationTestOp,
|
|
512
538
|
AvroToJSON,
|
|
513
539
|
BLAKE2b,
|
|
514
540
|
BLAKE2s,
|
|
@@ -601,6 +627,7 @@ export {
|
|
|
601
627
|
EscapeString,
|
|
602
628
|
EscapeUnicodeCharacters,
|
|
603
629
|
ExpandAlphabetRange,
|
|
630
|
+
ExtendedGCD,
|
|
604
631
|
ExtractAudioMetadata,
|
|
605
632
|
ExtractDates,
|
|
606
633
|
ExtractDomains,
|
|
@@ -644,6 +671,7 @@ export {
|
|
|
644
671
|
FromBech32,
|
|
645
672
|
FromBinary,
|
|
646
673
|
FromBraille,
|
|
674
|
+
FromCOBS,
|
|
647
675
|
FromCaseInsensitiveRegex,
|
|
648
676
|
FromCharcode,
|
|
649
677
|
FromDecimal,
|
|
@@ -675,6 +703,7 @@ export {
|
|
|
675
703
|
GenerateImage,
|
|
676
704
|
GenerateLoremIpsum,
|
|
677
705
|
GeneratePGPKeyPair,
|
|
706
|
+
GeneratePrime,
|
|
678
707
|
GenerateQRCode,
|
|
679
708
|
GenerateRSAKeyPair,
|
|
680
709
|
GenerateTOTP,
|
|
@@ -744,11 +773,13 @@ export {
|
|
|
744
773
|
MD5,
|
|
745
774
|
MD6,
|
|
746
775
|
MIMEDecoding,
|
|
776
|
+
MOD,
|
|
747
777
|
Magic,
|
|
748
778
|
Mean,
|
|
749
779
|
Median,
|
|
750
780
|
Merge,
|
|
751
781
|
MicrosoftScriptDecoder,
|
|
782
|
+
ModularInverse,
|
|
752
783
|
MultipleBombe,
|
|
753
784
|
Multiply,
|
|
754
785
|
MurmurHash3,
|
|
@@ -772,6 +803,8 @@ export {
|
|
|
772
803
|
PHPDeserialize,
|
|
773
804
|
PHPSerialize,
|
|
774
805
|
PLISTViewer,
|
|
806
|
+
PRESENTDecrypt,
|
|
807
|
+
PRESENTEncrypt,
|
|
775
808
|
PadLines,
|
|
776
809
|
ParityBit,
|
|
777
810
|
ParseASN1HexString,
|
|
@@ -823,6 +856,7 @@ export {
|
|
|
823
856
|
Rabbit,
|
|
824
857
|
RailFenceCipherDecode,
|
|
825
858
|
RailFenceCipherEncode,
|
|
859
|
+
RandomPrime,
|
|
826
860
|
RandomizeColourPalette,
|
|
827
861
|
RawDeflate,
|
|
828
862
|
RawInflate,
|
|
@@ -836,6 +870,7 @@ export {
|
|
|
836
870
|
RemoveWhitespace,
|
|
837
871
|
RenderImage,
|
|
838
872
|
RenderMarkdown,
|
|
873
|
+
RenderPDF,
|
|
839
874
|
ResizeImage,
|
|
840
875
|
Return,
|
|
841
876
|
Reverse,
|
|
@@ -893,6 +928,8 @@ export {
|
|
|
893
928
|
SymmetricDifference,
|
|
894
929
|
SyntaxHighlighter,
|
|
895
930
|
TCPIPChecksum,
|
|
931
|
+
TEADecrypt,
|
|
932
|
+
TEAEncrypt,
|
|
896
933
|
Tail,
|
|
897
934
|
TakeBytes,
|
|
898
935
|
TakeNthBytes,
|
|
@@ -912,6 +949,7 @@ export {
|
|
|
912
949
|
ToBech32,
|
|
913
950
|
ToBinary,
|
|
914
951
|
ToBraille,
|
|
952
|
+
ToCOBS,
|
|
915
953
|
ToCamelCase,
|
|
916
954
|
ToCaseInsensitiveRegex,
|
|
917
955
|
ToCharcode,
|
|
@@ -936,6 +974,8 @@ export {
|
|
|
936
974
|
TranslateDateTimeFormat,
|
|
937
975
|
TripleDESDecrypt,
|
|
938
976
|
TripleDESEncrypt,
|
|
977
|
+
TwofishDecrypt,
|
|
978
|
+
TwofishEncrypt,
|
|
939
979
|
Typex,
|
|
940
980
|
UNIXTimestampToWindowsFiletime,
|
|
941
981
|
URLDecode,
|
|
@@ -962,6 +1002,8 @@ export {
|
|
|
962
1002
|
XORChecksum,
|
|
963
1003
|
XPathExpression,
|
|
964
1004
|
XSalsa20,
|
|
1005
|
+
XTEADecrypt,
|
|
1006
|
+
XTEAEncrypt,
|
|
965
1007
|
XXTEADecrypt,
|
|
966
1008
|
XXTEAEncrypt,
|
|
967
1009
|
YAMLToJSON,
|
|
@@ -0,0 +1,162 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Ascon MAC implementation following NIST SP 800-232
|
|
3
|
+
* Vendor file for CyberChef
|
|
4
|
+
*
|
|
5
|
+
* @author Medjedtxm
|
|
6
|
+
* @copyright Crown Copyright 2025
|
|
7
|
+
* @license Apache-2.0
|
|
8
|
+
*/
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* NIST SP 800-232 compliant Ascon-Mac implementation
|
|
12
|
+
* Uses little-endian byte ordering as per NIST specification
|
|
13
|
+
*/
|
|
14
|
+
class AsconMac {
|
|
15
|
+
// NIST SP 800-232 constants
|
|
16
|
+
static ASCON_MAC_IV = 0x0010200080cc0005n;
|
|
17
|
+
static ASCON_PRF_IN_RATE = 32; // 4 * 8 bytes
|
|
18
|
+
static ASCON_PRF_OUT_RATE = 16; // 2 * 8 bytes
|
|
19
|
+
|
|
20
|
+
/**
|
|
21
|
+
* Compute Ascon-Mac tag
|
|
22
|
+
* @param {Uint8Array} key - 16-byte key
|
|
23
|
+
* @param {Uint8Array} message - Message to authenticate
|
|
24
|
+
* @param {number} tagLength - Output tag length (default 16)
|
|
25
|
+
* @returns {Uint8Array} - MAC tag
|
|
26
|
+
*/
|
|
27
|
+
static mac(key, message, tagLength = 16) {
|
|
28
|
+
if (key.length !== 16) {
|
|
29
|
+
throw new Error(`Invalid key length: ${key.length} bytes. Ascon-Mac requires exactly 16 bytes.`);
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
// Initialise state
|
|
33
|
+
const state = new BigUint64Array(5);
|
|
34
|
+
|
|
35
|
+
// Load key as two 64-bit words (little-endian per NIST SP 800-232)
|
|
36
|
+
const K0 = AsconMac.loadBytes(key, 0, 8);
|
|
37
|
+
const K1 = AsconMac.loadBytes(key, 8, 8);
|
|
38
|
+
|
|
39
|
+
// Set initial value per NIST SP 800-232
|
|
40
|
+
state[0] = AsconMac.ASCON_MAC_IV;
|
|
41
|
+
state[1] = K0;
|
|
42
|
+
state[2] = K1;
|
|
43
|
+
state[3] = 0n;
|
|
44
|
+
state[4] = 0n;
|
|
45
|
+
|
|
46
|
+
// Initial permutation P12
|
|
47
|
+
AsconMac.permutation(state, 12);
|
|
48
|
+
|
|
49
|
+
// Absorb message in 8-byte chunks, cycling through state[0..3]
|
|
50
|
+
let pos = 0;
|
|
51
|
+
let wordIdx = 0;
|
|
52
|
+
|
|
53
|
+
while (pos + 8 <= message.length) {
|
|
54
|
+
state[wordIdx] ^= AsconMac.loadBytes(message, pos, 8);
|
|
55
|
+
wordIdx++;
|
|
56
|
+
if (wordIdx === 4) {
|
|
57
|
+
wordIdx = 0;
|
|
58
|
+
AsconMac.permutation(state, 12);
|
|
59
|
+
}
|
|
60
|
+
pos += 8;
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
// Absorb final partial block with padding
|
|
64
|
+
const remaining = message.length - pos;
|
|
65
|
+
if (remaining > 0) {
|
|
66
|
+
state[wordIdx] ^= AsconMac.loadBytes(message, pos, remaining);
|
|
67
|
+
}
|
|
68
|
+
// PAD(remaining) = 0x01 << (8 * remaining)
|
|
69
|
+
state[wordIdx] ^= 0x01n << BigInt(8 * remaining);
|
|
70
|
+
|
|
71
|
+
// Domain separation: DSEP() = 0x80 << 56 = 0x8000000000000000
|
|
72
|
+
state[4] ^= 0x8000000000000000n;
|
|
73
|
+
|
|
74
|
+
// Finalisation permutation P12
|
|
75
|
+
AsconMac.permutation(state, 12);
|
|
76
|
+
|
|
77
|
+
// Squeeze output
|
|
78
|
+
const tag = new Uint8Array(tagLength);
|
|
79
|
+
let outPos = 0;
|
|
80
|
+
wordIdx = 0;
|
|
81
|
+
|
|
82
|
+
while (outPos < tagLength) {
|
|
83
|
+
const toCopy = Math.min(8, tagLength - outPos);
|
|
84
|
+
AsconMac.storeBytes(tag, outPos, state[wordIdx], toCopy);
|
|
85
|
+
outPos += toCopy;
|
|
86
|
+
wordIdx++;
|
|
87
|
+
if (wordIdx === 2 && outPos < tagLength) {
|
|
88
|
+
wordIdx = 0;
|
|
89
|
+
AsconMac.permutation(state, 12);
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
return tag;
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
/**
|
|
97
|
+
* Load n bytes as little-endian 64-bit integer (NIST SP 800-232 byte order)
|
|
98
|
+
* LOADBYTES: bytes[i] goes to position i (byte 0 = LSB)
|
|
99
|
+
*/
|
|
100
|
+
static loadBytes(arr, offset, n) {
|
|
101
|
+
let result = 0n;
|
|
102
|
+
for (let i = 0; i < n && offset + i < arr.length; i++) {
|
|
103
|
+
result |= BigInt(arr[offset + i]) << BigInt(i * 8);
|
|
104
|
+
}
|
|
105
|
+
return result;
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
/**
|
|
109
|
+
* Store n bytes from 64-bit integer in little-endian order
|
|
110
|
+
* STOREBYTES: position i goes to bytes[i] (LSB = byte 0)
|
|
111
|
+
*/
|
|
112
|
+
static storeBytes(arr, offset, val, n) {
|
|
113
|
+
for (let i = 0; i < n; i++) {
|
|
114
|
+
arr[offset + i] = Number((val >> BigInt(i * 8)) & 0xFFn);
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
/**
|
|
119
|
+
* Ascon permutation
|
|
120
|
+
*/
|
|
121
|
+
static permutation(state, rounds) {
|
|
122
|
+
for (let r = 12 - rounds; r < 12; r++) {
|
|
123
|
+
// Add round constant
|
|
124
|
+
state[2] ^= BigInt(0xf0 - r * 0x10 + r);
|
|
125
|
+
|
|
126
|
+
// Substitution layer
|
|
127
|
+
state[0] ^= state[4];
|
|
128
|
+
state[4] ^= state[3];
|
|
129
|
+
state[2] ^= state[1];
|
|
130
|
+
|
|
131
|
+
const t0 = state[0] ^ (~state[1] & state[2]);
|
|
132
|
+
const t1 = state[1] ^ (~state[2] & state[3]);
|
|
133
|
+
const t2 = state[2] ^ (~state[3] & state[4]);
|
|
134
|
+
const t3 = state[3] ^ (~state[4] & state[0]);
|
|
135
|
+
const t4 = state[4] ^ (~state[0] & state[1]);
|
|
136
|
+
|
|
137
|
+
state[0] = t0 ^ t4;
|
|
138
|
+
state[1] = t1 ^ t0;
|
|
139
|
+
state[2] = ~t2;
|
|
140
|
+
state[3] = t3 ^ t2;
|
|
141
|
+
state[4] = t4;
|
|
142
|
+
|
|
143
|
+
// Linear diffusion layer
|
|
144
|
+
state[0] ^= AsconMac.rotr64(state[0], 19n) ^ AsconMac.rotr64(state[0], 28n);
|
|
145
|
+
state[1] ^= AsconMac.rotr64(state[1], 61n) ^ AsconMac.rotr64(state[1], 39n);
|
|
146
|
+
state[2] ^= AsconMac.rotr64(state[2], 1n) ^ AsconMac.rotr64(state[2], 6n);
|
|
147
|
+
state[3] ^= AsconMac.rotr64(state[3], 10n) ^ AsconMac.rotr64(state[3], 17n);
|
|
148
|
+
state[4] ^= AsconMac.rotr64(state[4], 7n) ^ AsconMac.rotr64(state[4], 41n);
|
|
149
|
+
}
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
/**
|
|
153
|
+
* 64-bit rotate right
|
|
154
|
+
*/
|
|
155
|
+
static rotr64(val, n) {
|
|
156
|
+
const mask = 0xFFFFFFFFFFFFFFFFn;
|
|
157
|
+
val = val & mask;
|
|
158
|
+
return ((val >> n) | (val << (64n - n))) & mask;
|
|
159
|
+
}
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
export default AsconMac;
|