LibWeb/Crypto: Fix sizes being passed into generate_aes_key()

Previously, callers were passing the size in bytes, but the method
expected bits. This caused a crash in LibCrypto when verifying the key
size later on.

Also make the naming of local variables and parameters a little more
clear between the different AES algorithms :^)
This commit is contained in:
rmg-x 2024-11-03 13:53:00 -06:00 committed by Andreas Kling
commit 0db171c36e
Notes: github-actions[bot] 2024-11-03 20:56:39 +00:00
3 changed files with 39 additions and 14 deletions

View file

@ -0,0 +1,22 @@
<!DOCTYPE html>
<script src="../include.js"></script>
<script>
asyncTest(async (done) => {
const algorithm = "AES-GCM";
// Generate keys and export them, verify length
const aesGcm128bitKey = await crypto.subtle.generateKey({ name: algorithm, length: 128 }, true, ["encrypt"]);
const aesGcm192bitKey = await crypto.subtle.generateKey({ name: algorithm, length: 192 }, true, ["encrypt"]);
const aesGcm256bitKey = await crypto.subtle.generateKey({ name: algorithm, length: 256 }, true, ["encrypt"]);
const exported128bitKey = await crypto.subtle.exportKey("raw", aesGcm128bitKey);
const exported192bitKey = await crypto.subtle.exportKey("raw", aesGcm192bitKey);
const exported256bitKey = await crypto.subtle.exportKey("raw", aesGcm256bitKey);
println("exported 128 bit key length: " + exported128bitKey.byteLength);
println("exported 192 bit key length: " + exported192bitKey.byteLength);
println("exported 256 bit key length: " + exported256bitKey.byteLength);
done();
});
</script>