OLD | NEW |
1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file |
2 // for details. All rights reserved. Use of this source code is governed by a | 2 // for details. All rights reserved. Use of this source code is governed by a |
3 // BSD-style license that can be found in the LICENSE file. | 3 // BSD-style license that can be found in the LICENSE file. |
4 | 4 |
5 // Library tag to allow the test to run on Dartium. | 5 // Library tag to allow the test to run on Dartium. |
6 library hmac_md5_test; | 6 library hmac_md5_test; |
7 | 7 |
8 import 'dart:crypto'; | 8 import 'dart:crypto'; |
9 | 9 |
10 // Data from http://tools.ietf.org/html/rfc2202. | 10 // Data from http://tools.ietf.org/html/rfc2202. |
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
64 const [ 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, | 64 const [ 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, |
65 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, | 65 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, |
66 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, | 66 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, |
67 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, | 67 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, |
68 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, | 68 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, |
69 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, | 69 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, |
70 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, | 70 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, |
71 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, | 71 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, |
72 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa ] ]; | 72 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa ] ]; |
73 | 73 |
74 var hmac_md5_macs = | 74 var hmac_md5_string_macs = |
75 const [ '9294727a3638bb1c13f48ef8158bfc9d', | 75 const [ '9294727a3638bb1c13f48ef8158bfc9d', |
76 '750c783e6ab0b503eaa86e310a5db738', | 76 '750c783e6ab0b503eaa86e310a5db738', |
77 '56be34521d144c88dbb8c733f0e8b3f6', | 77 '56be34521d144c88dbb8c733f0e8b3f6', |
78 '697eaf0aca3a3aea3a75164746ffaa79', | 78 '697eaf0aca3a3aea3a75164746ffaa79', |
79 '56461ef2342edc00f9bab995690efd4c', | 79 '56461ef2342edc00f9bab995690efd4c', |
80 '6b1ab7fe4bd7bf8f0b62e6ce61b9d0cd', | 80 '6b1ab7fe4bd7bf8f0b62e6ce61b9d0cd', |
81 '6f630fad67cda0ee1fb1f562db3aa53e' ]; | 81 '6f630fad67cda0ee1fb1f562db3aa53e' ]; |
82 | 82 |
83 void testStandardVectors(inputs, keys, macs) { | 83 var hmac_md5_macs = |
| 84 const [ const [0x92, 0x94, 0x72, 0x7a, 0x36, 0x38, 0xbb, 0x1c, 0x13, 0xf4, |
| 85 0x8e, 0xf8, 0x15, 0x8b, 0xfc, 0x9d], |
| 86 const [0x75, 0x0c, 0x78, 0x3e, 0x6a, 0xb0, 0xb5, 0x03, 0xea, 0xa8, |
| 87 0x6e, 0x31, 0x0a, 0x5d, 0xb7, 0x38], |
| 88 const [0x56, 0xbe, 0x34, 0x52, 0x1d, 0x14, 0x4c, 0x88, 0xdb, 0xb8, |
| 89 0xc7, 0x33, 0xf0, 0xe8, 0xb3, 0xf6], |
| 90 const [0x69, 0x7e, 0xaf, 0x0a, 0xca, 0x3a, 0x3a, 0xea, 0x3a, 0x75, |
| 91 0x16, 0x47, 0x46, 0xff, 0xaa, 0x79], |
| 92 const [0x56, 0x46, 0x1e, 0xf2, 0x34, 0x2e, 0xdc, 0x00, 0xf9, 0xba, |
| 93 0xb9, 0x95, 0x69, 0x0e, 0xfd, 0x4c], |
| 94 const [0x6b, 0x1a, 0xb7, 0xfe, 0x4b, 0xd7, 0xbf, 0x8f, 0x0b, 0x62, |
| 95 0xe6, 0xce, 0x61, 0xb9, 0xd0, 0xcd], |
| 96 const [0x6f, 0x63, 0x0f, 0xad, 0x67, 0xcd, 0xa0, 0xee, 0x1f, 0xb1, |
| 97 0xf5, 0x62, 0xdb, 0x3a, 0xa5, 0x3e]]; |
| 98 |
| 99 void testStandardVectors(inputs, keys, string_macs, macs) { |
84 for (var i = 0; i < inputs.length; i++) { | 100 for (var i = 0; i < inputs.length; i++) { |
85 var d = new HMAC(new MD5(), keys[i]).update(inputs[i]).digest(); | 101 var h = new HMAC(new MD5(), keys[i]); |
86 Expect.isTrue(CryptoUtils.bytesToHex(d).startsWith(macs[i]), '$i'); | 102 var d = h.update(inputs[i]).digest(); |
| 103 Expect.isTrue(CryptoUtils.bytesToHex(d).startsWith(string_macs[i]), '$i'); |
| 104 Expect.isTrue(h.verify(macs[i])); |
| 105 Expect.isFalse(h.verify(macs[(i+1)%macs.length])); |
| 106 Expect.throws(() => h.verify([])); |
87 } | 107 } |
88 } | 108 } |
89 | 109 |
90 void main() { | 110 void main() { |
91 testStandardVectors(hmac_md5_inputs, hmac_md5_keys, hmac_md5_macs); | 111 testStandardVectors(hmac_md5_inputs, hmac_md5_keys, |
| 112 hmac_md5_string_macs, hmac_md5_macs); |
92 } | 113 } |
OLD | NEW |