{"record":{"id":"37cf0b5fceb4a322","repo":"peass-ng/PEASS-ng","slug":"threefish-tweak-must-be-bytes","errorCode":null,"errorMessage":"Threefish tweak must be  bytes","messagePattern":"Threefish tweak must be  bytes","errorType":"exception","errorClass":"ArgumentException","httpStatus":null,"severity":"error","filePath":"winPEAS/winPEASexe/winPEAS/3rdParty/BouncyCastle/crypto/engines/ThreefishEngine.cs","lineNumber":198,"sourceCode":"\n\t\t\tif (keyBytes != null)\n\t\t\t{\n\t\t\t\tif (keyBytes.Length != this.blocksizeBytes)\n\t\t\t\t{\n\t\t\t\t\tthrow new ArgumentException(\"Threefish key must be same size as block (\" + blocksizeBytes\n\t\t\t\t\t\t\t\t\t\t\t\t+ \" bytes)\");\n\t\t\t\t}\n\t\t\t\tkeyWords = new ulong[blocksizeWords];\n\t\t\t\tfor (int i = 0; i < keyWords.Length; i++)\n\t\t\t\t{\n\t\t\t\t\tkeyWords[i] = BytesToWord(keyBytes, i * 8);\n\t\t\t\t}\n\t\t\t}\n\t\t\tif (tweakBytes != null)\n\t\t\t{\n\t\t\t\tif (tweakBytes.Length != TWEAK_SIZE_BYTES)\n\t\t\t\t{\n\t\t\t\t\tthrow new ArgumentException(\"Threefish tweak must be \" + TWEAK_SIZE_BYTES + \" bytes\");\n\t\t\t\t}\n\t\t\t\ttweakWords = new ulong[] { BytesToWord(tweakBytes, 0), BytesToWord(tweakBytes, 8) };\n\t\t\t}\n\t\t\tInit(forEncryption, keyWords, tweakWords);\n\t\t}\n\n\t\t/// <summary>\n\t\t/// Initialise the engine, specifying the key and tweak directly.\n\t\t/// </summary>\n\t\t/// <param name=\"forEncryption\">the cipher mode.</param>\n\t\t/// <param name=\"key\">the words of the key, or <code>null</code> to use the current key.</param>\n\t\t/// <param name=\"tweak\">the 2 word (128 bit) tweak, or <code>null</code> to use the current tweak.</param>\n\t\tinternal void Init(bool forEncryption, ulong[] key, ulong[] tweak)\n\t\t{\n\t\t\tthis.forEncryption = forEncryption;\n\t\t\tif (key != null)\n\t\t\t{\n\t\t\t\tSetKey(key);","sourceCodeStart":180,"sourceCodeEnd":216,"githubUrl":"https://github.com/peass-ng/PEASS-ng/blob/53fb989abc2219826385683a6fee826bd6cd38d6/winPEAS/winPEASexe/winPEAS/3rdParty/BouncyCastle/crypto/engines/ThreefishEngine.cs#L180-L216","documentation":"An argument validation in ThreefishEngine.Init: when a tweak byte array is supplied its length must equal TWEAK_SIZE_BYTES (16, i.e. two 64-bit words); any other length is rejected because the tweak schedule is built from exactly two words. The message interpolates the required size, so it reads with a missing number only when the constant is elided in formatting.","triggerScenarios":"Calling Init with ParametersWithTweak whose tweak array is not 16 bytes (e.g. 8-byte counter, 32-byte tweak, null-padded value).","commonSituations":"Feeding an AES-GCM-style 12-byte IV as a Threefish tweak; hashing a tweak to 32 bytes instead of 16; forgetting that Threefish's tweak is 128 bits.","solutions":["Supply exactly 16 bytes of tweak material","If the tweak source is longer/shorter, derive 16 bytes via SHA-256 truncation or a dedicated KDF","Construct tweak as two 8-byte little-endian words when building it manually"],"exampleFix":"// before\nbyte[] tweak = new byte[8];\nengine.Init(true, new ParametersWithTweak(new KeyParameter(key), tweak));\n// after\nbyte[] tweak = new byte[16];\nengine.Init(true, new ParametersWithTweak(new KeyParameter(key), tweak));","handlingStrategy":"validation","validationCode":"const int TweakSizeBytes = 16;\nif (tweak == null || tweak.Length != TweakSizeBytes)\n    throw new ArgumentException(\"Threefish tweak must be exactly 16 bytes\");\nengine.Init(forEncryption, new ParametersWithTweak(new KeyParameter(key), tweak));","typeGuard":"bool IsValidThreefishTweak(byte[] tweak) => tweak != null && tweak.Length == 16;","tryCatchPattern":"try { engine.Init(forEnc, new ParametersWithTweak(keyParam, tweak)); }\ncatch (ArgumentException) { /* normalize tweak to 16 bytes and retry once */ }","preventionTips":["Remember the Threefish tweak is 128 bits (two 64-bit words)","Hash/truncate external tweak sources to exactly 16 bytes","Reuse a single helper to build ParametersWithTweak consistently"],"tags":["csharp","cryptography","threefish","tweak"],"backgroundTag":"invalid-cipher-tweak-size","analyzedSha":"53fb989abc2219826385683a6fee826bd6cd38d6","analyzedAt":"2026-09-02T04:25:09.259Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-09T11:17:12.671Z"}