| 1 |
// Copyright 2012 The Closure Library Authors. All Rights Reserved. |
| 2 |
// |
| 3 |
// Licensed under the Apache License, Version 2.0 (the "License"); |
| 4 |
// you may not use this file except in compliance with the License. |
| 5 |
// You may obtain a copy of the License at |
| 6 |
// |
| 7 |
// http://www.apache.org/licenses/LICENSE-2.0 |
| 8 |
// |
| 9 |
// Unless required by applicable law or agreed to in writing, software |
| 10 |
// distributed under the License is distributed on an "AS-IS" BASIS, |
| 11 |
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 12 |
// See the License for the specific language governing permissions and |
| 13 |
// limitations under the License. |
| 14 |
|
| 15 |
goog.provide('goog.crypt.pbkdf2Test'); |
| 16 |
goog.setTestOnly('goog.crypt.pbkdf2Test'); |
| 17 |
|
| 18 |
goog.require('goog.crypt'); |
| 19 |
goog.require('goog.crypt.pbkdf2'); |
| 20 |
goog.require('goog.testing.jsunit'); |
| 21 |
goog.require('goog.userAgent'); |
| 22 |
|
| 23 |
function testPBKDF2() { |
| 24 |
// PBKDF2 test vectors from: |
| 25 |
// http://tools.ietf.org/html/rfc6070 |
| 26 |
|
| 27 |
if (goog.userAgent.IE && goog.userAgent.isVersionOrHigher('7')) { |
| 28 |
return; |
| 29 |
} |
| 30 |
|
| 31 |
var testPassword = goog.crypt.stringToByteArray('password'); |
| 32 |
var testSalt = goog.crypt.stringToByteArray('salt'); |
| 33 |
|
| 34 |
assertElementsEquals( |
| 35 |
goog.crypt.hexToByteArray('0c60c80f961f0e71f3a9b524af6012062fe037a6'), |
| 36 |
goog.crypt.pbkdf2.deriveKeySha1(testPassword, testSalt, 1, 160)); |
| 37 |
|
| 38 |
assertElementsEquals( |
| 39 |
goog.crypt.hexToByteArray('ea6c014dc72d6f8ccd1ed92ace1d41f0d8de8957'), |
| 40 |
goog.crypt.pbkdf2.deriveKeySha1(testPassword, testSalt, 2, 160)); |
| 41 |
|
| 42 |
assertElementsEquals( |
| 43 |
goog.crypt.hexToByteArray('4b007901b765489abead49d926f721d065a429c1'), |
| 44 |
goog.crypt.pbkdf2.deriveKeySha1(testPassword, testSalt, 4096, 160)); |
| 45 |
|
| 46 |
testPassword = goog.crypt.stringToByteArray('passwordPASSWORDpassword'); |
| 47 |
testSalt = |
| 48 |
goog.crypt.stringToByteArray('saltSALTsaltSALTsaltSALTsaltSALTsalt'); |
| 49 |
|
| 50 |
assertElementsEquals( |
| 51 |
goog.crypt.hexToByteArray( |
| 52 |
'3d2eec4fe41c849b80c8d83662c0e44a8b291a964cf2f07038'), |
| 53 |
goog.crypt.pbkdf2.deriveKeySha1(testPassword, testSalt, 4096, 200)); |
| 54 |
|
| 55 |
testPassword = goog.crypt.stringToByteArray('pass\0word'); |
| 56 |
testSalt = goog.crypt.stringToByteArray('sa\0lt'); |
| 57 |
|
| 58 |
assertElementsEquals( |
| 59 |
goog.crypt.hexToByteArray('56fa6aa75548099dcc37d7f03425e0c3'), |
| 60 |
goog.crypt.pbkdf2.deriveKeySha1(testPassword, testSalt, 4096, 128)); |
| 61 |
} |