-
-
Notifications
You must be signed in to change notification settings - Fork 647
/
qunit-do-crypto-mac.html
executable file
·155 lines (122 loc) · 5.21 KB
/
qunit-do-crypto-mac.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
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title>QUnit for Cryptographic Provider Class 'crypto.js' HMAC test</title>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>
<script type="text/javascript" src="jquery-1.4.2.min.js"></script>
<script type="text/javascript" src="qunit.js"></script>
<link rel="stylesheet" href="qunit.css" type="text/css" media="screen" />
<script src="../ext/cj/cryptojs-312-core-fix.js"></script>
<script src="../ext/cj/x64-core.js"></script>
<script src="../ext/cj/cipher-core_min.js"></script>
<script src="../ext/cj/aes_min.js"></script>
<script src="../ext/cj/tripledes_min.js"></script>
<script src="../ext/cj/enc-base64_min.js"></script>
<script src="../ext/cj/md5_min.js"></script>
<script src="../ext/cj/sha1_min.js"></script>
<script src="../ext/cj/sha256_min.js"></script>
<script src="../ext/cj/sha224_min.js"></script>
<script src="../ext/cj/sha512_min.js"></script>
<script src="../ext/cj/sha384_min.js"></script>
<script src="../ext/cj/ripemd160_min.js"></script>
<script src="../ext/cj/hmac_min.js"></script>
<script src="../ext/cj/pbkdf2_min.js"></script>
<script src="../ext/jsbn.js"></script>
<script src="../ext/jsbn2.js"></script>
<script src="../ext/prng4.js"></script>
<script src="../ext/rng.js"></script>
<script src="../ext/base64.js"></script>
<script src="../src/crypto-1.1.js"></script>
<script src="../src/base64x-1.1.js"></script>
<script type="text/javascript">
<!--
$(document).ready(function(){
// openssl dgst -sha1 -hmac pass aaa.txt
var HMACSHA1AAAPASS = "3839089182c6a0443adaa168460c466fdd822a24";
// openssl dgst -sha224 -hmac pass aaa.txt
var HMACSHA224AAAPASS = "2a03bb43a8494be72687dfd78f3be5f384477ef4fb76180188c4e808";
// openssl dgst -sha256 -hmac pass aaa.txt
var HMACSHA256AAAPASS = "5737da4a87c0bda19ddb8898f87fb11b4680ca56f061580c046011cafc41e2ee";
// openssl dgst -sha384 -hmac pass aaa.txt
var HMACSHA384AAAPASS = "221bc1de17da49fe1aaaed4dca81cb271aa792cd4775e3c89b55f4b62ada0d0e5e585acbcbc7523d742c8e86455c4fd8";
// openssl dgst -sha512 -hmac pass aaa.txt
var HMACSHA512AAAPASS = "4ff71cce35012ba0054de832b69c29f0b29d965e6e31cf70a3cc118dd34082a54a7a9f0d9469877576892d142be8e0f48ce997fa159492bc36c1caf9b454f48f";
// openssl dgst -md5 -hmac pass aaa.txt
var HMACMD5AAAPASS = "a705d13b50d78edfee5bd1f2fa37cdd5";
// openssl dgst -ripemd160 -hmac pass aaa.txt
var HMACRIPEMD160AAAPASS = "61ff05af52b509f60dc2fdd61d378dab745fa7eb";
test("HMAC HmacSHA1(aaa,pass)", function() {
expect(1);
var mac1 = new KJUR.crypto.Mac({"alg": "HmacSHA1", "prov": "cryptojs", "pass": "pass"});
mac1.updateString("aaa");
equal(mac1.doFinal(), HMACSHA1AAAPASS, "hmac(aaa,pass)");
});
test("HMAC HmacSHA224(aaa,pass) - fix with patched CryptoJS core.js", function() {
expect(1);
var mac1 = new KJUR.crypto.Mac({"alg": "HmacSHA224", "prov": "cryptojs", "pass": "pass"});
mac1.updateString("aaa");
equal(mac1.doFinal(), HMACSHA224AAAPASS, "hmac(aaa,pass)");
});
test("HMAC HmacSHA256(aaa,pass)", function() {
expect(1);
var mac1 = new KJUR.crypto.Mac({"alg": "HmacSHA256", "prov": "cryptojs", "pass": "pass"});
mac1.updateString("aaa");
equal(mac1.doFinal(), HMACSHA256AAAPASS, "hmac(aaa,pass)");
});
test("HMAC HmacSHA384(aaa,pass) - fixed with patched CryptoJS core.js", function() {
expect(1);
var mac1 = new KJUR.crypto.Mac({"alg": "HmacSHA384", "prov": "cryptojs", "pass": "pass"});
mac1.updateString("aaa");
equal(mac1.doFinal(), HMACSHA384AAAPASS, "hmac(aaa,pass)");
});
test("HMAC HmacSHA512(aaa,pass)", function() {
expect(1);
var mac1 = new KJUR.crypto.Mac({"alg": "HmacSHA512", "prov": "cryptojs", "pass": "pass"});
mac1.updateString("aaa");
equal(mac1.doFinal(), HMACSHA512AAAPASS, "hmac(aaa,pass)");
});
test("HMAC HmacMD5(aaa,pass)", function() {
expect(1);
var mac1 = new KJUR.crypto.Mac({"alg": "HmacMD5", "prov": "cryptojs", "pass": "pass"});
mac1.updateString("aaa");
equal(mac1.doFinal(), HMACMD5AAAPASS, "hmac(aaa,pass)");
});
test("HMAC HmacRIPEMD160(aaa,pass)", function() {
expect(1);
var mac1 = new KJUR.crypto.Mac({"alg": "HmacRIPEMD160", "prov": "cryptojs", "pass": "pass"});
mac1.updateString("aaa");
equal(mac1.doFinal(), HMACRIPEMD160AAAPASS, "hmac(aaa,pass)");
});
test("Crypto-JS HmacSHA224 bug test", function() {
expect(1);
var hash1 = CryptoJS.HmacSHA224("aaa", "pass");
var hmac2 = CryptoJS.algo.HMAC.create(CryptoJS.algo.SHA224, "pass");
hmac2.update("aaa");
var hash2 = hmac2.finalize();
equal(hash1.toString(CryptoJS.enc.Hex), hash2.toString(CryptoJS.enc.Hex), "224");
});
test("Crypto-JS HmacSHA384 bug test", function() {
expect(1);
var hash1 = CryptoJS.HmacSHA384("aaa", "pass");
var hmac2 = CryptoJS.algo.HMAC.create(CryptoJS.algo.SHA384, "pass");
hmac2.update("aaa");
var hash2 = hmac2.finalize();
equal(hash1.toString(CryptoJS.enc.Hex), hash2.toString(CryptoJS.enc.Hex), "384");
});
});
-->
</script>
</head>
<body>
<div id="qunit"></div>
<div id="qunit-fixture">test markup</div>
<p>
<a href="../">TOP</a> |
<a href="index.html">TEST INDEX</a> |
<a href="qunit-do-crypto.html">crypto</a> |
<a href="qunit-do-crypto-mac.html">crypto-mac</a> |
<a href="qunit-do-crypto-mac2.html">crypto-mac2</a> |
</p>
</body>
</html>