| OLD | NEW |
| 1 <!DOCTYPE html> | 1 <!DOCTYPE html> |
| 2 <html> | 2 <html> |
| 3 <head> | 3 <head> |
| 4 <script src="../resources/js-test.js"></script> | 4 <script src="../resources/js-test.js"></script> |
| 5 <script src="resources/common.js"></script> | 5 <script src="resources/common.js"></script> |
| 6 </head> | 6 </head> |
| 7 <body> | 7 <body> |
| 8 <p id="description"></p> | 8 <p id="description"></p> |
| 9 <div id="console"></div> | 9 <div id="console"></div> |
| 10 | 10 |
| 11 <script> | 11 <script> |
| 12 description("Tests wrapping and unwrapping of AES-CBC keys using AES-KW and raw
format"); | 12 description("Tests wrapping and unwrapping of AES-CBC keys using AES-KW and raw
format"); |
| 13 | 13 |
| 14 jsTestIsAsync = true; | 14 jsTestIsAsync = true; |
| 15 | 15 |
| 16 var kWrappingTestCases = [ | 16 var kWrappingTestCases = [ |
| 17 // AES-KW test vectors from http://www.ietf.org/rfc/rfc3394.txt | 17 // AES-KW test vectors from http://www.ietf.org/rfc/rfc3394.txt |
| 18 // 4.1 Wrap 128 bits of Key Data with a 128-bit KEK | 18 // 4.1 Wrap 128 bits of Key Data with a 128-bit KEK |
| 19 { | 19 { |
| 20 "wrappingKey": "000102030405060708090A0B0C0D0E0F", | 20 "wrappingKey": "000102030405060708090A0B0C0D0E0F", |
| 21 "key": "00112233445566778899AABBCCDDEEFF", | 21 "key": "00112233445566778899AABBCCDDEEFF", |
| 22 "ciphertext": "1FA68B0A8112B447AEF34BD8FB5A7B829D3E862371D2CFE5" | 22 "ciphertext": "1FA68B0A8112B447AEF34BD8FB5A7B829D3E862371D2CFE5" |
| 23 }, | 23 }, |
| 24 // 4.2 Wrap 128 bits of Key Data with a 192-bit KEK | |
| 25 { | |
| 26 "wrappingKey": "000102030405060708090A0B0C0D0E0F1011121314151617", | |
| 27 "key": "00112233445566778899AABBCCDDEEFF", | |
| 28 "ciphertext": "96778B25AE6CA435F92B5B97C050AED2468AB8A17AD84E5D" | |
| 29 }, | |
| 30 // 4.3 Wrap 128 bits of Key Data with a 256-bit KEK | 24 // 4.3 Wrap 128 bits of Key Data with a 256-bit KEK |
| 31 { | 25 { |
| 32 "wrappingKey": "000102030405060708090A0B0C0D0E0F101112131415161718191A1B1C1D
1E1F", | 26 "wrappingKey": "000102030405060708090A0B0C0D0E0F101112131415161718191A1B1C1D
1E1F", |
| 33 "key": "00112233445566778899AABBCCDDEEFF", | 27 "key": "00112233445566778899AABBCCDDEEFF", |
| 34 "ciphertext": "64E8C3F9CE0F5BA263E9777905818A2A93C8191E7D6E8AE7" | 28 "ciphertext": "64E8C3F9CE0F5BA263E9777905818A2A93C8191E7D6E8AE7" |
| 35 }, | 29 }, |
| 36 // 4.4 Wrap 192 bits of Key Data with a 192-bit KEK | |
| 37 { | |
| 38 "wrappingKey": "000102030405060708090A0B0C0D0E0F1011121314151617", | |
| 39 "key": "00112233445566778899AABBCCDDEEFF0001020304050607", | |
| 40 "ciphertext": "031D33264E15D33268F24EC260743EDCE1C6C7DDEE725A936BA814915C676
2D2" | |
| 41 }, | |
| 42 // 4.5 Wrap 192 bits of Key Data with a 256-bit KEK | 30 // 4.5 Wrap 192 bits of Key Data with a 256-bit KEK |
| 43 { | 31 { |
| 44 "wrappingKey": "000102030405060708090A0B0C0D0E0F101112131415161718191A1B1C1D
1E1F", | 32 "wrappingKey": "000102030405060708090A0B0C0D0E0F101112131415161718191A1B1C1D
1E1F", |
| 45 "key": "00112233445566778899AABBCCDDEEFF0001020304050607", | 33 "key": "00112233445566778899AABBCCDDEEFF0001020304050607", |
| 46 "ciphertext": "A8F9BC1612C68B3FF6E6F4FBE30E71E4769C8B80A32CB8958CD5D17D6B254
DA1" | 34 "ciphertext": "A8F9BC1612C68B3FF6E6F4FBE30E71E4769C8B80A32CB8958CD5D17D6B254
DA1" |
| 47 }, | 35 }, |
| 48 // 4.6 Wrap 256 bits of Key Data with a 256-bit KEK | 36 // 4.6 Wrap 256 bits of Key Data with a 256-bit KEK |
| 49 { | 37 { |
| 50 "wrappingKey": "000102030405060708090A0B0C0D0E0F101112131415161718191A1B1C1D
1E1F", | 38 "wrappingKey": "000102030405060708090A0B0C0D0E0F101112131415161718191A1B1C1D
1E1F", |
| 51 "key": "00112233445566778899AABBCCDDEEFF000102030405060708090A0B0C0D0E0F", | 39 "key": "00112233445566778899AABBCCDDEEFF000102030405060708090A0B0C0D0E0F", |
| (...skipping 11 matching lines...) Expand all Loading... |
| 63 var importAlgorithm = {name: 'aes-kw'}; | 51 var importAlgorithm = {name: 'aes-kw'}; |
| 64 var keyData = hexStringToUint8Array(testCase.wrappingKey); | 52 var keyData = hexStringToUint8Array(testCase.wrappingKey); |
| 65 var usages = ['wrapKey', 'unwrapKey']; | 53 var usages = ['wrapKey', 'unwrapKey']; |
| 66 var extractable = false; | 54 var extractable = false; |
| 67 | 55 |
| 68 return crypto.subtle.importKey('raw', keyData, importAlgorithm, extracta
ble, usages); | 56 return crypto.subtle.importKey('raw', keyData, importAlgorithm, extracta
ble, usages); |
| 69 }).then(function(result) { | 57 }).then(function(result) { |
| 70 wrappingKey = result; | 58 wrappingKey = result; |
| 71 | 59 |
| 72 // Import the key to be wrapped. | 60 // Import the key to be wrapped. |
| 73 var importAlgorithm = {name: 'aes-cbc'}; | 61 var importAlgorithm = {name: 'HMAC', hash: {name: 'sha-1'}}; |
| 74 var keyData = hexStringToUint8Array(testCase.key); | 62 var keyData = hexStringToUint8Array(testCase.key); |
| 75 var usages = ['encrypt', 'decrypt']; | 63 var usages = ['sign', 'verify']; |
| 76 var extractable = true; | 64 var extractable = true; |
| 77 | 65 |
| 78 return crypto.subtle.importKey('raw', keyData, importAlgorithm, extracta
ble, usages); | 66 return crypto.subtle.importKey('raw', keyData, importAlgorithm, extracta
ble, usages); |
| 79 }).then(function(result) { | 67 }).then(function(result) { |
| 80 key = result; | 68 key = result; |
| 81 | 69 |
| 82 // Wrap the key. | 70 // Wrap the key. |
| 83 var wrapAlgorithm = {name: 'aes-kw'}; | 71 var wrapAlgorithm = {name: 'aes-kw'}; |
| 84 return crypto.subtle.wrapKey('raw', key, wrappingKey, wrapAlgorithm); | 72 return crypto.subtle.wrapKey('raw', key, wrappingKey, wrapAlgorithm); |
| 85 }).then(function(result) { | 73 }).then(function(result) { |
| 86 bytesShouldMatchHexString("Wrapped key data", testCase.ciphertext, resul
t); | 74 bytesShouldMatchHexString("Wrapped key data", testCase.ciphertext, resul
t); |
| 87 | 75 |
| 88 // Unwrap the key. | 76 // Unwrap the key. |
| 89 var wrappedKeyData = hexStringToUint8Array(testCase.ciphertext); | 77 var wrappedKeyData = hexStringToUint8Array(testCase.ciphertext); |
| 90 var unwrapAlgorithm = {name: 'aes-kw'}; | 78 var unwrapAlgorithm = {name: 'aes-kw'}; |
| 91 var unwrappedKeyAlgorithm = {name: 'aes-cbc'}; | 79 var unwrappedKeyAlgorithm = {name: 'HMAC', hash: {name: 'sha-1'}}; |
| 92 var extractable = true; | 80 var extractable = true; |
| 93 var usages = ['decrypt']; | 81 var usages = ['sign']; |
| 94 return crypto.subtle.unwrapKey('raw', wrappedKeyData, wrappingKey, unwra
pAlgorithm, unwrappedKeyAlgorithm, extractable, usages); | 82 return crypto.subtle.unwrapKey('raw', wrappedKeyData, wrappingKey, unwra
pAlgorithm, unwrappedKeyAlgorithm, extractable, usages); |
| 95 }).then(function(result) { | 83 }).then(function(result) { |
| 96 unwrappedKey = result; | 84 unwrappedKey = result; |
| 97 | 85 |
| 98 shouldEvaluateAs("unwrappedKey.algorithm.name", "AES-CBC"); | 86 shouldEvaluateAs("unwrappedKey.algorithm.name", "HMAC"); |
| 87 shouldEvaluateAs("unwrappedKey.algorithm.hash.name", "SHA-1"); |
| 99 shouldEvaluateAs("unwrappedKey.algorithm.length", testCase.key.length *
4); | 88 shouldEvaluateAs("unwrappedKey.algorithm.length", testCase.key.length *
4); |
| 100 shouldEvaluateAs("unwrappedKey.extractable", true); | 89 shouldEvaluateAs("unwrappedKey.extractable", true); |
| 101 shouldEvaluateAs("unwrappedKey.usages.join(',')", "decrypt"); | 90 shouldEvaluateAs("unwrappedKey.usages.join(',')", "sign"); |
| 102 | 91 |
| 103 return crypto.subtle.exportKey('raw', unwrappedKey); | 92 return crypto.subtle.exportKey('raw', unwrappedKey); |
| 104 }).then(function(result) { | 93 }).then(function(result) { |
| 105 bytesShouldMatchHexString("Unwrapped key data", testCase.key, result); | 94 bytesShouldMatchHexString("Unwrapped key data", testCase.key, result); |
| 106 }); | 95 }); |
| 107 } | 96 } |
| 108 | 97 |
| 109 var lastPromise = Promise.resolve(null); | 98 var lastPromise = Promise.resolve(null); |
| 110 | 99 |
| 111 kWrappingTestCases.forEach(function(test) { | 100 kWrappingTestCases.forEach(function(test) { |
| 112 lastPromise = lastPromise.then(runTestCase.bind(null, test)); | 101 lastPromise = lastPromise.then(runTestCase.bind(null, test)); |
| 113 }); | 102 }); |
| 114 | 103 |
| 115 lastPromise.then(finishJSTest, failAndFinishJSTest); | 104 lastPromise.then(finishJSTest, failAndFinishJSTest); |
| 116 | 105 |
| 117 </script> | 106 </script> |
| 118 | 107 |
| 119 </body> | 108 </body> |
| 120 </html> | 109 </html> |
| OLD | NEW |