blob: 3701458c716d195077ede5cd3970256433631c39 [file] [log] [blame]
<!DOCTYPE html>
<html>
<head>
<script src="../../resources/js-test-pre.js"></script>
<script src="../resources/common.js"></script>
</head>
<body>
<p id="description"></p>
<div id="console"></div>
<script>
description("Test encrypting using AES-CTR with an imported 128bit key");
jsTestIsAsync = true;
var extractable = false;
var plainText = asciiToUint8Array("Hello, World!Hello, World!Hello, World!Hello, World!");
var aesCtrParams1 = {
name: "aes-ctr",
counter: asciiToUint8Array("jnOw99oOZFLIEPMr"),
length: 8,
}
var aesCtrParams2 = {
name: "aes-ctr",
counter: asciiToUint8Array("jnOw99oOZFLIEPMr"),
length: 64,
}
var aesCtrParams3 = {
name: "aes-ctr",
counter: asciiToUint8Array("jnOw99oOZFLIEPMr"),
length: 65,
}
var aesCtrParams4= {
name: "aes-ctr",
counter: asciiToUint8Array("jnOw99oOZFLIEPMr"),
length: 2,
}
var aesCtrParams5= {
name: "aes-ctr",
counter: hexStringToUint8Array("6a6e4f7739396f4f5a464c4945504dff"),
length: 8,
}
var rawKey = asciiToUint8Array("jnOw99oOZFLIEPMr");
var expectedCipherText = "a5f940e93406d4bd9b7318e653d4cb9d1af497f52fcbb659a038e711e8bd61fb4863931d25911e2e9ff30cf37ec27dd813a62830";
var expectedCipherText4 = "a5f940e93406d4bd9b7318e653d4cb9d1af497f52fcbb659a038e711e8bd61fb96fed7fa5bf75d282a5477583b970b171740a2fa";
var expectedCipherText5 = "6a461eb3f64ef4c466597ba877a9512bf224051c88ae885c565a7ada56843f3b84ec7596df67cbfdcfbeb275768f4d7270ce7ddf";
crypto.subtle.importKey("raw", rawKey, "aes-ctr", extractable, ["encrypt"]).then(function(result) {
key = result;
debug("Length < 64");
return crypto.subtle.encrypt(aesCtrParams1, key, plainText);
}).then(function(result) {
cipherText = result;
shouldBe("bytesToHexString(cipherText)", "expectedCipherText");
debug("Length = 64");
return crypto.subtle.encrypt(aesCtrParams2, key, plainText);
}).then(function(result) {
cipherText = result;
shouldBe("bytesToHexString(cipherText)", "expectedCipherText");
debug("Length = 65");
return crypto.subtle.encrypt(aesCtrParams3, key, plainText);
}).then(function(result) {
cipherText = result;
shouldBe("bytesToHexString(cipherText)", "expectedCipherText");
debug("Length = 2, overflow");
return crypto.subtle.encrypt(aesCtrParams4, key, plainText);
}).then(function(result) {
cipherText = result;
shouldBe("bytesToHexString(cipherText)", "expectedCipherText4");
debug("Length = 8, overflow");
return crypto.subtle.encrypt(aesCtrParams5, key, plainText);
}).then(function(result) {
cipherText = result;
shouldBe("bytesToHexString(cipherText)", "expectedCipherText5");
finishJSTest();
});
</script>
<script src="../../resources/js-test-post.js"></script>
</body>
</html>