Closed ghost closed 7 years ago
For anyone else who comes across this, I've temporarily solved this problem by switching to GCM over CCM
@Dacnomanie I formatted your code for better readability.
@Nilos Thanks, how do I do that next time?
See https://guides.github.com/features/mastering-markdown/#examples just select the code example. Basically add three backticks (`) before and after your code example.
Should have seen this earlier but after some digging I now know what happens :)
The problem is in your usage of aes/ccm mode. CCM Mode requires at least one full block but you are not giving it one, which from my point of view is the reason it fails.
If you change the code to:
var aesCipher = new sjcl.cipher.aes(sjcl.hash.sha256.hash([1,2,3,4]));
var encryptedECKey = sjcl.codec.base64.fromBits(sjcl.mode.ccm.encrypt(aesCipher, sjcl.codec.base32hex.toBits("AAAAAAAA"), Array.from([1,2,3,4])));
console.log(sjcl.mode.ccm.decrypt(aesCipher, sjcl.codec.base64.toBits(encryptedECKey), Array.from([1,2,3,4])));
it works (I just increased the value from AAAA
to AAAAAAAA
)
This simple code:
Returns the error: "ccm: tag doesn't match", despite having the exact same input for all fields