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

misc.hmacSha1 in sjcl.js is broken for keys longer than 16 #390

Closed
andreasdamm opened this issue Jan 13, 2023 · 1 comment
Closed

misc.hmacSha1 in sjcl.js is broken for keys longer than 16 #390

andreasdamm opened this issue Jan 13, 2023 · 1 comment

Comments

@andreasdamm
Copy link

When trying to read an AES encrypted zip file in an environment that does not expose importKey, an exception is encountered when using a password whose length when converted to bits exceeds a block size of 16.

Exception: TypeError: Hash.hash is not a function

Fix:

diff --git a/lib/core/streams/codecs/sjcl.js b/lib/core/streams/codecs/sjcl.js
index 24544dbee63df2f1b0b95740c641af550c9f24c5..abd44b705d7bb61c9e2c090c6057e0a2a7c02e99 100644
--- a/lib/core/streams/codecs/sjcl.js
+++ b/lib/core/streams/codecs/sjcl.js
@@ -774,7 +774,7 @@ misc.hmacSha1 = class {
 		const bs = hmac._baseHash[0].blockSize / 32;
 
 		if (key.length > bs) {
-			key = Hash.hash(key);
+			key = new Hash().update(key).finalize();
 		}
 
 		for (let i = 0; i < bs; i++) {
@gildas-lormeau
Copy link
Owner

Thank you very much for the bug report, I have integrated your fix in the version 2.6.62 that I have just published.

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

No branches or pull requests

2 participants