Merge Chromium + Blink git repositories
[chromium-blink-merge.git] / third_party / WebKit / LayoutTests / crypto / subtle / aes-gcm / failures.html
blobb5be4fc595ea093036da9c2187a0ecc60cedac91
1 <!DOCTYPE html>
2 <html>
3 <head>
4 <script src="../../../resources/js-test.js"></script>
5 <script src="../resources/common.js"></script>
6 </head>
7 <body>
8 <p id="description"></p>
9 <div id="console"></div>
11 <script>
12 description("Tests bad algorithm inputs for AES-GCM");
14 jsTestIsAsync = true;
16 var keyData = hexStringToUint8Array("2b7e151628aed2a6abf7158809cf4f3c");
17 var data = asciiToUint8Array("hello");
18 var key = null;
20 Promise.resolve(null).then(function(result) {
21 var usages = ['encrypt', 'decrypt'];
22 var extractable = false;
23 var algorithm = {name: 'aes-gcm'};
25 debug('\nImporting AES-GCM key...');
26 return crypto.subtle.importKey('raw', keyData, algorithm, extractable, usages);
27 }).then(function(result) {
28 key = result;
30 debug('\nencrypt() without iv...');
31 return crypto.subtle.encrypt({name: 'AES-gcm'}, key, data);
32 }).then(failAndFinishJSTest, function(result) {
33 logError(result);
35 debug('\nencrypt() with iv that is a number...');
36 return crypto.subtle.encrypt({name: 'AES-gcm', iv: 3}, key, data);
37 }).then(failAndFinishJSTest, function(result) {
38 logError(result);
40 debug('\nencrypt() with iv that is a string...');
41 return crypto.subtle.encrypt({name: 'AES-gcm', iv: 'foo'}, key, data);
42 }).then(failAndFinishJSTest, function(result) {
43 logError(result);
45 debug('\nencrypt() with additionalData that is a string...');
46 return crypto.subtle.encrypt({name: 'AeS-gcm', iv: new Uint8Array(16), additionalData: '5'}, key, data);
47 }).then(failAndFinishJSTest, function(result) {
48 logError(result);
50 debug('\nencrypt() with tagLength that is a string...');
51 return crypto.subtle.encrypt({name: 'AES-gcm', iv: new Uint8Array(16), additionalData: new Uint8Array(1), tagLength: 'foo'}, key, data);
52 }).then(failAndFinishJSTest, function(result) {
53 logError(result);
55 debug('\nencrypt() with negative tagLength...');
56 return crypto.subtle.encrypt({name: 'AES-gcm', iv: new Uint8Array(16), additionalData: new Uint8Array(1), tagLength: -1}, key, data);
57 }).then(failAndFinishJSTest, function(result) {
58 logError(result);
60 debug('\nencrypt() with tagLength larger than an octet...');
61 return crypto.subtle.encrypt({name: 'AES-gcm', iv: new Uint8Array(16), additionalData: new Uint8Array(1), tagLength: 8000}, key, data);
62 }).then(failAndFinishJSTest, function(result) {
63 logError(result);
65 debug('\nencrypt() with tagLength that is 0...');
66 return crypto.subtle.encrypt({name: 'AES-gcm', iv: new Uint8Array(16), additionalData: new Uint8Array(1), tagLength: 0}, key, data);
67 }).then(failAndFinishJSTest, function(result) {
68 logError(result);
70 debug('\nencrypt() with tagLength that is 130...');
71 return crypto.subtle.encrypt({name: 'AES-gcm', iv: new Uint8Array(16), additionalData: new Uint8Array(1), tagLength: 130}, key, data);
72 }).then(failAndFinishJSTest, function(result) {
73 logError(result);
74 }).then(finishJSTest, failAndFinishJSTest);
76 </script>
78 </body>
79 </html>