4 <script src=
"../../../resources/js-test.js"></script>
5 <script src=
"../resources/common.js"></script>
8 <p id=
"description"></p>
9 <div id=
"console"></div>
12 description("Tests bad algorithm inputs for AES-GCM");
16 var keyData
= hexStringToUint8Array("2b7e151628aed2a6abf7158809cf4f3c");
17 var data
= asciiToUint8Array("hello");
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
) {
30 debug('\nencrypt() without iv...');
31 return crypto
.subtle
.encrypt({name
: 'AES-gcm'}, key
, data
);
32 }).then(failAndFinishJSTest
, function(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
) {
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
) {
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
) {
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
) {
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
) {
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
) {
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
) {
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
) {
74 }).then(finishJSTest
, failAndFinishJSTest
);