-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathaes-cbc-decrypt-failure.html
executable file
·119 lines (101 loc) · 4.73 KB
/
aes-cbc-decrypt-failure.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
<html>
<head>
<script type="text/javascript" src="DJS/encoding.js"></script>
<script type="text/javascript" src="DJS/hashing.js"></script>
<script type="text/javascript" src="DJS/aes.js"></script>
<script type="text/javascript" src="DJS/rsa.js"></script>
<script type="text/javascript" src="asn1JS.js"></script>
<script type="text/javascript" src="functions.js"></script>
<script type="text/javascript" src="algorithms.js"></script>
<script type="text/javascript" src="Key.js"></script>
<script type="text/javascript" src="generateKey.js"></script>
<script type="text/javascript" src="sign.js"></script>
<script type="text/javascript" src="decrypt.js"></script>
<script type="text/javascript" src="encrypt.js"></script>
<script type="text/javascript" src="exportKey.js"></script>
<script type="text/javascript" src="importKey.js"></script>
<script type="text/javascript" src="verify.js"></script>
<script type="text/javascript" src="digest.js"></script>
<script type="text/javascript" src="deriveKey.js"></script>
<script type="text/javascript" src="wrapKey.js"></script>
<script type="text/javascript" src="unwrapKey.js"></script>
<script type="text/javascript" src="resources/common.js"></script>
<script type="text/javascript" src="resources/js-test.js"></script>
<script type="text/javascript" src="subtleinriacrypto.js"></script>
<script type="text/javascript">
function init(){
var a,b,c,d;
var start = new Date().getTime();
window.crypto = inriacrypto;
// 128-bit key with plaintext that is an exact multiple of block size.
// Derived from [1] F.2.1 (CBC-AES128.Encrypt), by adding padding block.
var iv = hexStringToUint8Array("000102030405060708090a0b0c0d0e0f");
var keyData = hexStringToUint8Array("2b7e151628aed2a6abf7158809cf4f3c");
var cipherText = hexStringToUint8Array("7649abac8119b246cee98e9b12e9197d5086cb9b507219ee95db113a917678b273bed6b8e3c1743b7116e69e222295163ff1caa1681fac09120eca307586e1a78cb82807230e1321d3fae00d18cc2012");
var key = null;
var usages = ['encrypt', 'decrypt'];
var extractable = false;
var algorithm = {name: 'AES-CBC', iv: iv};
function verifyDecryptionFails(newCipherTextLength)
{
var newCipherText = cipherText.subarray(0, newCipherTextLength);
var description = "ciphertext length: " + newCipherText.byteLength;
return inriacrypto.subtle.decrypt(algorithm, key, newCipherText).then(function(result) {
debug("FAIL: decrypting succeeded. " + description);
}, function(result) {
logError(result);
debug("PASS: decrypting failed. " + description);
});
}
a=keyData;
b=algorithm;
c=extractable;
d=usages;
inriacrypto.subtle.importKey('raw', keyData, algorithm, extractable, usages).then(function(result) {
key = result;
// Verify that decryption works with the original ciphertext.
return inriacrypto.subtle.decrypt(algorithm, key, cipherText);
}).then(function(result) {
console.log(result);
debug("PASS: Decryption succeeded");
// Try a number of bad ciphertexts.
var badLengths = [
0,
cipherText.byteLength - 1,
// Stripped a whole block. This new final block will result in a
// padding error.
cipherText.byteLength - 16,
1,
15,
16,
17
];
var lastPromise = Promise.resolve(null);
badLengths.forEach(function(badLength) {
lastPromise = lastPromise.then(verifyDecryptionFails.bind(null, badLength));
});
return lastPromise;
}).then(finishJSTest, failAndFinishJSTest);
function cryptOp(keyData, algorithm, extractable, usages){
var o ={
oncomplete: function(){
console.log("Uninitialized");
return "Uninitialized";
},
};
inriacrypto.subtle.importKey('raw', keyData, algorithm, extractable, usages).then(function(result) {
//console.log(result);
o.oncomplete(result);
});
return o;
}
var p = cryptOp(a,b,c,d);
p.oncomplete = function(result){
//console.log(result);
}
}
</script>
</head>
<body onload="init()">
</body>
</html>