Skip to content

Truly independent web browser

1.1 KB
Raw Blame
<!DOCTYPE html>
<script src="../include.js"></script>
<script>
    promiseTest(async () => {
        const algorithms = [
            { name: "HMAC", hash: "SHA-256" },
            { name: "KMAC128" },
        ];

        for (const algorithm of algorithms) {
            for (const length of [12, 4096, 4104, 65536, 65544]) {
                let key;
                try {
                    key = await crypto.subtle.generateKey({ ...algorithm, length }, true, ["sign"]);
                } catch (error) {
                    println(`${algorithm.name} length ${length}: ${error.name}`);
                    continue;
                }
                const bytes = new Uint8Array(await crypto.subtle.exportKey("raw-secret", key));
                let unusedBitsAreZero = "n/a";
                if (length % 8 && bytes.length === Math.ceil(length / 8))
                    unusedBitsAreZero = (bytes[bytes.length - 1] & (0xff >> length % 8)) === 0;
                println(`${algorithm.name} length ${length}: ${bytes.length} bytes, algorithm.length ${key.algorithm.length}, unused bits zero: ${unusedBitsAreZero}`);
            }
        }
    });
</script>