Skip to content

Truly independent web browser

7.5 KB
Raw Blame
<!DOCTYPE html>
<script src="../include.js"></script>
<script>
    promiseTest(async () => {

        const keyBytes = new Uint8Array([
            222, 192, 212, 252, 191, 60, 71, 65, 200, 146, 218, 189, 28, 212, 192, 78
        ]);

        var iv = new Uint8Array([
            58, 146, 115, 42, 166, 234, 57, 191, 57, 134, 224, 199, 108, 116, 46
        ]);

        const additionalData = new Uint8Array([
            84, 104, 101, 114, 101, 32, 97, 114, 101, 32, 55, 32, 102, 117, 114, 116,
            104, 101, 114, 32, 101, 100, 105, 116, 111, 114, 105, 97, 108, 32, 110, 111,
            116, 101, 115, 32, 105, 110, 32, 116, 104, 101, 32, 100, 111, 99, 117, 109,
            101, 110, 116, 46
        ]);

        const plaintext = new Uint8Array([
            84, 104, 105, 115, 32, 115, 112, 101, 99, 105, 102, 105, 99, 97, 116, 105,
            111, 110, 32, 100, 101, 115, 99, 114, 105, 98, 101, 115, 32, 97, 32, 74, 97,
            118, 97, 83, 99, 114, 105, 112, 116, 32, 65, 80, 73, 32, 102, 111, 114, 32,
            112, 101, 114, 102, 111, 114, 109, 105, 110, 103, 32, 98, 97, 115, 105, 99,
            32, 99, 114, 121, 112, 116, 111, 103, 114, 97, 112, 104, 105, 99, 32, 111,
            112, 101, 114, 97, 116, 105, 111, 110, 115, 32, 105, 110, 32, 119, 101, 98,
            32, 97, 112, 112, 108, 105, 99, 97, 116, 105, 111, 110, 115, 44, 32, 115,
            117, 99, 104, 32, 97, 115, 32, 104, 97, 115, 104, 105, 110, 103, 44, 32,
            115, 105, 103, 110, 97, 116, 117, 114, 101, 32, 103, 101, 110, 101, 114, 97,
            116, 105, 111, 110, 32, 97, 110, 100, 32, 118, 101, 114, 105, 102, 105, 99,
            97, 116, 105, 111, 110, 44, 32, 97, 110, 100, 32, 101, 110, 99, 114, 121,
            112, 116, 105, 111, 110, 32, 97, 110, 100, 32, 100, 101, 99, 114, 121, 112,
            116, 105, 111, 110, 46, 32, 65, 100, 100, 105, 116, 105, 111, 110, 97, 108,
            108, 121, 44, 32, 105, 116, 32, 100, 101, 115, 99, 114, 105, 98, 101, 115,
            32, 97, 110, 32, 65, 80, 73, 32, 102, 111, 114, 32, 97, 112, 112, 108, 105,
            99, 97, 116, 105, 111, 110, 115, 32, 116, 111, 32, 103, 101, 110, 101, 114,
            97, 116, 101, 32, 97, 110, 100, 47, 111, 114, 32, 109, 97, 110, 97, 103,
            101, 32, 116, 104, 101, 32, 107, 101, 121, 105, 110, 103, 32, 109, 97, 116,
            101, 114, 105, 97, 108, 32, 110, 101, 99, 101, 115, 115, 97, 114, 121, 32,
            116, 111, 32, 112, 101, 114, 102, 111, 114, 109, 32, 116, 104, 101, 115,
            101, 32, 111, 112, 101, 114, 97, 116, 105, 111, 110, 115, 46, 32, 85, 115,
            101, 115, 32, 102, 111, 114, 32, 116, 104, 105, 115, 32, 65, 80, 73, 32,
            114, 97, 110, 103, 101, 32, 102, 114, 111, 109, 32, 117, 115, 101, 114, 32,
            111, 114, 32, 115, 101, 114, 118, 105, 99, 101, 32, 97, 117, 116, 104, 101,
            110, 116, 105, 99, 97, 116, 105, 111, 110, 44, 32, 100, 111, 99, 117, 109,
            101, 110, 116, 32, 111, 114, 32, 99, 111, 100, 101, 32, 115, 105, 103, 110,
            105, 110, 103, 44, 32, 97, 110, 100, 32, 116, 104, 101, 32, 99, 111, 110,
            102, 105, 100, 101, 110, 116, 105, 97, 108, 105, 116, 121, 32, 97, 110, 100,
            32, 105, 110, 116, 101, 103, 114, 105, 116, 121, 32, 111, 102, 32, 99, 111,
            109, 109, 117, 110, 105, 99, 97, 116, 105, 111, 110, 115, 46
        ]);

        const expectedCiphertext = new Uint8Array([
            65, 221, 187, 210, 119, 207, 141, 109, 144, 97, 82, 124, 60, 189, 176,
            2, 250, 48, 64, 29, 197, 22, 59, 96, 246, 211, 155, 184, 126, 116, 79,
            37, 168, 109, 191, 38, 77, 90, 74, 112, 222, 105, 173, 190, 182, 226,
            244, 47, 130, 191, 207, 190, 105, 186, 153, 58, 132, 212, 108, 156, 108,
            30, 56, 180, 7, 133, 144, 169, 249, 120, 191, 16, 40, 13, 157, 127, 170,
            134, 193, 12, 39, 84, 117, 13, 68, 26, 4, 52, 188, 51, 30, 55, 171, 181,
            255, 252, 12, 238, 46, 197, 114, 255, 125, 171, 6, 162, 40, 42, 217,
            221, 127, 164, 14, 171, 249, 105, 12, 133, 246, 205, 161, 97, 238, 208,
            179, 30, 161, 182, 134, 100, 112, 205, 93, 101, 69, 254, 253, 201, 244,
            67, 2, 87, 172, 247, 144, 141, 88, 80, 236, 188, 190, 73, 179, 253, 211,
            142, 98, 141, 16, 97, 166, 2, 71, 224, 232, 44, 238, 82, 33, 16, 32,
            224, 111, 191, 89, 157, 99, 127, 28, 95, 175, 15, 86, 10, 44, 180, 127,
            200, 162, 37, 138, 69, 78, 119, 165, 96, 98, 107, 211, 122, 21, 49, 124,
            60, 156, 38, 20, 22, 196, 86, 20, 182, 173, 23, 42, 42, 26, 213, 84, 21,
            160, 156, 96, 20, 234, 208, 177, 44, 112, 110, 165, 233, 20, 56, 123,
            110, 129, 57, 158, 148, 98, 241, 47, 148, 113, 198, 10, 80, 16, 221, 91,
            8, 192, 194, 190, 183, 113, 67, 134, 234, 239, 20, 108, 150, 83, 106,
            209, 112, 93, 196, 12, 135, 2, 177, 151, 168, 46, 202, 197, 22, 24, 48,
            105, 76, 218, 21, 229, 45, 127, 109, 93, 38, 189, 215, 123, 110, 23,
            110, 94, 232, 46, 167, 50, 5, 212, 120, 69, 230, 35, 149, 228, 24, 115,
            134, 10, 187, 73, 79, 197, 47, 5, 200, 142, 166, 159, 51, 154, 199, 178,
            88, 127, 240, 228, 141, 20, 122, 191, 173, 66, 120, 130, 223, 180, 218,
            107, 134, 224, 251, 127, 180, 17, 196, 223, 182, 230, 5, 217, 23, 146,
            3, 251, 129, 27, 162, 223, 19, 72, 108, 117, 51, 77, 53, 21, 158, 135,
            114, 157, 8, 166, 80, 246, 162, 103, 61, 116, 188, 30, 201, 112, 239,
            13, 244, 46, 123, 193, 206, 91, 17, 188, 78, 81, 21, 226, 218, 56, 177,
            139, 17, 4, 94, 165, 250, 207, 170, 141, 211, 247, 201, 101, 122, 198,
            121, 99, 24, 177, 98, 188, 192, 252, 96, 181, 110, 111, 154, 144, 57,
            141, 114, 50, 228, 192, 154, 123, 241, 143, 78, 250, 156, 140, 128, 195,
            151, 145, 153, 130, 43, 154, 34, 187, 242, 243, 55, 91, 154, 149, 193,
            214, 82, 249, 212, 79, 131, 230, 179, 4, 251, 6, 135, 210,
            // Tag (64-bit = 8 bytes)
            85, 92, 121, 149, 117, 105, 131, 236
        ]);

        try {
            const key = await window.crypto.subtle.importKey(
                "raw-secret",
                keyBytes,
                { name: "AES-OCB" },
                false,
                ["encrypt", "decrypt"]
            );
            const result = await window.crypto.subtle.encrypt(
                {
                    name: "AES-OCB",
                    iv: iv,
                    additionalData: additionalData,
                    tagLength: 64
                },
                key,
                plaintext
            );

            const resultArray = new Uint8Array(result);

            let match = resultArray.byteLength === expectedCiphertext.byteLength;
            if (match) {
                for (let i = 0; i < resultArray.byteLength; i++) {
                    if (resultArray[i] !== expectedCiphertext[i]) {
                        match = false;
                        println(`Mismatch at byte ${i}: got ${resultArray[i]}, expected ${expectedCiphertext[i]}`);
                        break;
                    }
                }
            } else {
                println(`Length mismatch: got ${resultArray.byteLength}, expected ${expectedCiphertext.byteLength}`);
            }

            if (match) {
                println("PASS: Encryption result matches expected value");
            } else {
                println("FAIL: Encryption result does not match expected value");
            }

        } catch (e) {
            println(`ERROR: ${e.message}`);
        }
    });
</script>