Skip to content

Commit

Permalink
Switch to 10,000 PBKDF2 iterations (should be compatible with standar…
Browse files Browse the repository at this point in the history
…d v3)
  • Loading branch information
rnapier committed Feb 2, 2014
1 parent ad39c6a commit 6ba58d6
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 16 deletions.
2 changes: 1 addition & 1 deletion rncryptor.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ RNCryptor.KeyForPassword = function(password, salt) {
return hasher.encrypt.apply(hasher, arguments);
};
};
return sjcl.misc.pbkdf2(password, salt, 1000, 32 * 8, hmacSHA1);
return sjcl.misc.pbkdf2(password, salt, 10000, 32 * 8, hmacSHA1);
}

/*
Expand Down
2 changes: 1 addition & 1 deletion tests/GenVectorTests
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ require 'json'

require File.join(File.dirname(__FILE__), '../Spec/vectors', 'vectorparser')

@test_files = ["kdf_short", "password_short"]
@test_files = ["kdf", "password"]

@options = {}

Expand Down
24 changes: 12 additions & 12 deletions tests/Generated/rncryptor-vectors.js
Original file line number Diff line number Diff line change
@@ -1,61 +1,61 @@
// Automatically Generated by GenVectorTests

test("One byte", function() {
verify_kdf_short({"title":"One byte","version":"3","password":"a","iterations":"1000","salt_hex":"0102030405060708","key_hex":"d48f10b7 ae39bd25 2bb68e1f af12acea 3474d7d7 702a15b2 ede3246e 82dbb2fd"});
verify_kdf({"title":"One byte","version":"3","password":"a","salt_hex":"0102030405060708","key_hex":"fc632b0c a6b23eff 9a9dc3e0 e585167f 5a328916 ed19f835 58be3ba9 828797cd"});
});


test("Short password", function() {
verify_kdf_short({"title":"Short password","version":"3","password":"thepassword","iterations":"1000","salt_hex":"0203040506070801","key_hex":"3d3f64cd 31d8057b 5624567a 2caeace4 84adcfda 3fbf6401 a1f03a09 5cee6dd1"});
verify_kdf({"title":"Short password","version":"3","password":"thepassword","salt_hex":"0203040506070801","key_hex":"0ea84f52 52310dc3 e3a7607c 33bfd1eb 580805fb 68293005 da21037c cf499626"});
});


test("Passphrase", function() {
verify_kdf_short({"title":"Passphrase","version":"3","password":"this is a bit longer password","iterations":"1000","salt_hex":"0304050607080102","key_hex":"18d42ea5 900f9a94 932a6a5f 10e8f89d 5222ad47 8328ecde f7ba7fe9 1b08240c"});
verify_kdf({"title":"Passphrase","version":"3","password":"this is a bit longer password","salt_hex":"0304050607080102","key_hex":"71343acb 1e9675b0 16ac65dc fe5ddac2 e57ed9c3 5565fdbb 2dd6d2ce fe263d5b"});
});


test("Long passphrase", function() {
verify_kdf_short({"title":"Long passphrase","version":"3","password":"$$$it was the epoch of belief, it was the epoch of incredulity; it was the season of Light, it was the season of Darkness; it was the spring of hope, it was the winter of despair; we had everything before us, we had nothing before us; we were all going directly to Heaven, we were all going the other way.","iterations":"1000","salt_hex":"0405060708010203","key_hex":"7a7d41ca 9eb92999 23b47d63 6ff18068 1ca5449d f77b7568 2a09fa25 001618db"});
verify_kdf({"title":"Long passphrase","version":"3","password":"$$$it was the epoch of belief, it was the epoch of incredulity; it was the season of Light, it was the season of Darkness; it was the spring of hope, it was the winter of despair; we had everything before us, we had nothing before us; we were all going directly to Heaven, we were all going the other way.","salt_hex":"0405060708010203","key_hex":"11b52c50 cbf45be6 a636a314 2b8c30b8 5a624481 4a7d43e3 7457f38d e46c6735"});
});


test("Multibyte", function() {
verify_kdf_short({"title":"Multibyte","version":"3","password":"中文密码","iterations":"1000","salt_hex":"0506070801020304","key_hex":"10ac6088 7fce25a3 5cb96b41 86e85fde 088f2cb5 5bdac89c 5deffad6 95ba8a20"});
verify_kdf({"title":"Multibyte","version":"3","password":"中文密码","salt_hex":"0506070801020304","key_hex":"d2fc3237 d4a69668 ca83d969 c2cda1ac 6c368479 2b6644b1 a90b2052 007215dd"});
});


test("Mixed language", function() {
verify_kdf_short({"title":"Mixed language","version":"3","password":"中文密码 with a little English, too.","iterations":"1000","salt_hex":"0607080102030405","key_hex":"1aecc100 8bf00812 1b6bbb30 201b4d62 22cf472c 3f438bcd fc52c0a0 fa03f659"});
verify_kdf({"title":"Mixed language","version":"3","password":"中文密码 with a little English, too.","salt_hex":"0607080102030405","key_hex":"46bda5f4 65982a47 40c728bc 14c5de5c c7fc4eea f0aa41bb 9b9e8495 452dafff"});
});


test("All fields empty or zero (with one-byte password)", function() {
verify_password_short({"title":"All fields empty or zero (with one-byte password)","version":"3","password":"a","iterations":"1000","enc_salt_hex":"0000000000000000","hmac_salt_hex":"0000000000000000","iv_hex":"00000000000000000000000000000000","plaintext_hex":"","ciphertext_hex":"03010000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 0000be42 dc470392 a3cf1106 3ffcc247 e2161363 d415cfd9 5c5f03b1 542426f8 b3cd2660 642fbcf4 7252e199 43204ed2 23a0"});
verify_password({"title":"All fields empty or zero (with one-byte password)","version":"3","password":"a","enc_salt_hex":"0000000000000000","hmac_salt_hex":"0000000000000000","iv_hex":"00000000000000000000000000000000","plaintext_hex":"","ciphertext_hex":"03010000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 0000b303 9be31cd7 ece5e754 f5c8da17 00366631 3ae8a89d dcf8e3cb 41fdc130 b2329dbe 07d6f4d3 2c34e050 c8bd7e93 3b12"});
});


test("One byte", function() {
verify_password_short({"title":"One byte","version":"3","password":"thepassword","iterations":"1000","enc_salt_hex":"0001020304050607","hmac_salt_hex":"0102030405060708","iv_hex":"02030405060708090a0b0c0d0e0f0001","plaintext_hex":"01","ciphertext_hex":"03010001 02030405 06070102 03040506 07080203 04050607 08090a0b 0c0d0e0f 00013b5c 7ec811da d8e794d7 9bf5a113 67e7a9df a9f5613c b896edab c8ce6dcf a28416b0 da31ed4a 608aecb0 a9d0e387 a86c"});
verify_password({"title":"One byte","version":"3","password":"thepassword","enc_salt_hex":"0001020304050607","hmac_salt_hex":"0102030405060708","iv_hex":"02030405060708090a0b0c0d0e0f0001","plaintext_hex":"01","ciphertext_hex":"03010001 02030405 06070102 03040506 07080203 04050607 08090a0b 0c0d0e0f 0001a1f8 730e0bf4 80eb7b70 f690abf2 1e029514 164ad3c4 74a51b30 c7eaa1ca 545b7de3 de5b010a cbad0a9a 13857df6 96a8"});
});


test("Exactly one block", function() {
verify_password_short({"title":"Exactly one block","version":"3","password":"thepassword","iterations":"1000","enc_salt_hex":"0102030405060700","hmac_salt_hex":"0203040506070801","iv_hex":"030405060708090a0b0c0d0e0f000102","plaintext_hex":"0123456789abcdef","ciphertext_hex":"03010102 03040506 07000203 04050607 08010304 05060708 090a0b0c 0d0e0f00 0102cfae 082f48a6 4274eaa9 7c227c0f f1cdbd9d e91dd8be 65256932 5ba7b748 66bc9ea1 3aeeb460 6ccbf34f feee44c0 88b7"});
verify_password({"title":"Exactly one block","version":"3","password":"thepassword","enc_salt_hex":"0102030405060700","hmac_salt_hex":"0203040506070801","iv_hex":"030405060708090a0b0c0d0e0f000102","plaintext_hex":"0123456789abcdef","ciphertext_hex":"03010102 03040506 07000203 04050607 08010304 05060708 090a0b0c 0d0e0f00 01020e43 7fe80930 9c03fd53 a475131e 9a1978b8 eaef576f 60adb8ce 2320849b a32d7429 00438ba8 97d22210 c76c35c8 49df"});
});


test("More than one block", function() {
verify_password_short({"title":"More than one block","version":"3","password":"thepassword","iterations":"1000","enc_salt_hex":"0203040506070001","hmac_salt_hex":"0304050607080102","iv_hex":"0405060708090a0b0c0d0e0f00010203","plaintext_hex":"0123456789abcdef 01234567","ciphertext_hex":"03010203 04050607 00010304 05060708 01020405 06070809 0a0b0c0d 0e0f0001 0203e6fa 1522aa8b 0312ca18 63d8d69c 0e8b3371 509bc42e 412a4b86 e44441a3 b41eca2a 22bad8fb 5cbebb81 d310b7ee b9cb"});
verify_password({"title":"More than one block","version":"3","password":"thepassword","enc_salt_hex":"0203040506070001","hmac_salt_hex":"0304050607080102","iv_hex":"0405060708090a0b0c0d0e0f00010203","plaintext_hex":"0123456789abcdef 01234567","ciphertext_hex":"03010203 04050607 00010304 05060708 01020405 06070809 0a0b0c0d 0e0f0001 0203e01b bda5df2c a8adace3 8f6c588d 291e03f9 51b78d34 17bc2816 581dc6b7 67f1a2e5 7597512b 18e1638f 21235fa5 928c"});
});


test("Multibyte password", function() {
verify_password_short({"title":"Multibyte password","version":"3","password":"中文密码","iterations":"1000","enc_salt_hex":"0304050607000102","hmac_salt_hex":"0405060708010203","iv_hex":"05060708090a0b0c0d0e0f0001020304","plaintext_hex":"23456789abcdef 0123456701","ciphertext_hex":"03010304 05060700 01020405 06070801 02030506 0708090a 0b0c0d0e 0f000102 03049bec 58c6184f 78fbfc7c d6f05618 e5f228b6 d62386ba f3d50ebb aeabdf92 d2b6a897 e7371de3 e8fdb68b 8c568360 73ff"});
verify_password({"title":"Multibyte password","version":"3","password":"中文密码","enc_salt_hex":"0304050607000102","hmac_salt_hex":"0405060708010203","iv_hex":"05060708090a0b0c0d0e0f0001020304","plaintext_hex":"23456789abcdef 0123456701","ciphertext_hex":"03010304 05060700 01020405 06070801 02030506 0708090a 0b0c0d0e 0f000102 03048a9e 08bdec1c 4bfe13e8 1fb85f00 9ab3ddb9 1387e809 c4ad86d9 e8a60145 57716657 bd317d4b b6a76446 15b3de40 2341"});
});


test("Longer text and password", function() {
verify_password_short({"title":"Longer text and password","version":"3","password":"It was the best of times, it was the worst of times; it was the age of wisdom, it was the age of foolishness;","iterations":"1000","enc_salt_hex":"0405060700010203","hmac_salt_hex":"0506070801020304","iv_hex":"060708090a0b0c0d0e0f000102030405","plaintext_hex":"69 74 20 77 61 73 20 74 68 65 20 65 70 6f 63 68 20 6f 66 20 62 65 6c 69 65 66 2c 20 69 74 20 77 61 73 20 74 68 65 20 65 70 6f 63 68 20 6f 66 20 69 6e 63 72 65 64 75 6c 69 74 79 3b 20 69 74 20 77 61 73 20 74 68 65 20 73 65 61 73 6f 6e 20 6f 66 20 4c 69 67 68 74 2c 20 69 74 20 77 61 73 20 74 68 65 20 73 65 61 73 6f 6e 20 6f 66 20 44 61 72 6b 6e 65 73 73 3b 20 69 74 20 77 61 73 20 74 68 65 20 73 70 72 69 6e 67 20 6f 66 20 68 6f 70 65 2c 20 69 74 20 77 61 73 20 74 68 65 20 77 69 6e 74 65 72 20 6f 66 20 64 65 73 70 61 69 72 3b 20 77 65 20 68 61 64 20 65 76 65 72 79 74 68 69 6e 67 20 62 65 66 6f 72 65 20 75 73 2c 20 77 65 20 68 61 64 20 6e 6f 74 68 69 6e 67 20 62 65 66 6f 72 65 20 75 73 3b 20 77 65 20 77 65 72 65 20 61 6c 6c 20 67 6f 69 6e 67 20 64 69 72 65 63 74 6c 79 20 74 6f 20 48 65 61 76 65 6e 2c 20 77 65 20 77 65 72 65 20 61 6c 6c 20 67 6f 69 6e 67 20 74 68 65 20 6f 74 68 65 72 20 77 61 79 2e 0a 0a","ciphertext_hex":"03010405 06070001 02030506 07080102 03040607 08090a0b 0c0d0e0f 00010203 0405c678 0c8a41db 7f8b2d36 d337093e 483e780b 5b53c16a 8c705e87 383ab1b3 597902d8 251b8be2 c81c969a 643b7e3f c87b2714 074a0a72 7b396c26 9956de30 ff67b014 3a1c3225 e2a61ec4 5a60503b cc042167 d72defed a950385b 34d3c2ce 4af05029 23302c05 ee6849e0 ad383b9f 564bca8d 12f3e4c4 47988f09 8b5a08f9 f5f6d3f7 e0181ca6 2e0083c9 8b81fa7a 74b91e17 55981304 8f93901d eaa02c11 beae201f f5d10e0d 908288bc 72dc2056 cade79ec 9dd2cc77 7481db41 368fde8b 56c8c044 bb05a81e bd33adcb ec55e71d 9f16e14a bd2491e9 f2ffe156 4c26dfb5 c30aa2fb e7ab8614 c8a70d75 d48d2060 8aa44b8e f5987530 9274e538 318f69cb 8172328c 2016f712 2e1cd9dc 37c708d2 787b6027 38f86439 b32d0334 f1ab232c 2b4ac0dc 4f307315 c7670c3a 040ca9d5 cfaab19d b125e676 3854b104 f3717e9e 561233cf a1181c46 ea893eb1 36b68756 d5a3e775 ff0b3ce9 d5a4bb3a 61c43273 60e2"});
verify_password({"title":"Longer text and password","version":"3","password":"It was the best of times, it was the worst of times; it was the age of wisdom, it was the age of foolishness;","enc_salt_hex":"0405060700010203","hmac_salt_hex":"0506070801020304","iv_hex":"060708090a0b0c0d0e0f000102030405","plaintext_hex":"69 74 20 77 61 73 20 74 68 65 20 65 70 6f 63 68 20 6f 66 20 62 65 6c 69 65 66 2c 20 69 74 20 77 61 73 20 74 68 65 20 65 70 6f 63 68 20 6f 66 20 69 6e 63 72 65 64 75 6c 69 74 79 3b 20 69 74 20 77 61 73 20 74 68 65 20 73 65 61 73 6f 6e 20 6f 66 20 4c 69 67 68 74 2c 20 69 74 20 77 61 73 20 74 68 65 20 73 65 61 73 6f 6e 20 6f 66 20 44 61 72 6b 6e 65 73 73 3b 20 69 74 20 77 61 73 20 74 68 65 20 73 70 72 69 6e 67 20 6f 66 20 68 6f 70 65 2c 20 69 74 20 77 61 73 20 74 68 65 20 77 69 6e 74 65 72 20 6f 66 20 64 65 73 70 61 69 72 3b 20 77 65 20 68 61 64 20 65 76 65 72 79 74 68 69 6e 67 20 62 65 66 6f 72 65 20 75 73 2c 20 77 65 20 68 61 64 20 6e 6f 74 68 69 6e 67 20 62 65 66 6f 72 65 20 75 73 3b 20 77 65 20 77 65 72 65 20 61 6c 6c 20 67 6f 69 6e 67 20 64 69 72 65 63 74 6c 79 20 74 6f 20 48 65 61 76 65 6e 2c 20 77 65 20 77 65 72 65 20 61 6c 6c 20 67 6f 69 6e 67 20 74 68 65 20 6f 74 68 65 72 20 77 61 79 2e 0a 0a","ciphertext_hex":"03010405 06070001 02030506 07080102 03040607 08090a0b 0c0d0e0f 00010203 0405d564 c7a99da9 21a6e7c4 078a8264 1d954795 51283167 a2c81f31 ab80c9d7 d8beb770 111decd3 e3d29bbd f7ebbfc5 f10ac87e 7e55bfb5 a7f487bc d3983570 5e83b9c0 49c6d695 2be011f8 ddb1a14f c0c92573 8de017e6 2b1d621c cdb75f29 37d0a1a7 0e44d843 b9c61037 dee2998b 2bbd740b 910232ee a7196116 8838f699 5b996417 3b34c0bc d311a2c8 7e271630 928bae30 1a8f4703 ac2ae469 9f3c285a bf1c55ac 324b073a 958ae52e e8c3bd68 f919c09e b1cd2814 2a1996a9 e6cbff5f 4f4e1dba 07d29ff6 6860db98 95a48233 140ca249 419d6304 6448db1b 0f4252a6 e4edb947 fd0071d1 e52bc156 00622fa5 48a67739 63618150 797a8a80 e592446d f5926d0b fd32b544 b796f335 9567394f 77e7b171 b2f9bc5f 2caf7a0f ac0da7d0 4d6a8674 4d6e06d0 2fbe15d0 f580a1d5 bd16ad91 34800361 1358dcb4 ac999095 5f6cbbbf b185941d 4b4b71ce 7f9ba6ef c1270b78 08838b6c 7b7ef17e 8db919b3 4fac"});
});

4 changes: 2 additions & 2 deletions tests/rncryptor-test.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
var verify_kdf_short = function(vector) {
var verify_kdf = function(vector) {
var key = RNCryptor.KeyForPassword(vector["password"], sjcl.codec.hex.toBits(vector["salt_hex"]));
equal(sjcl.codec.hex.fromBits(key), vector["key_hex"].replace(/\s/g,''));
}

var verify_password_short = function(vector) {
var verify_password = function(vector) {
var ciphertext = RNCryptor.Encrypt(vector["password"],
sjcl.codec.hex.toBits(vector["plaintext_hex"].replace(/\s/g,'')),
{ "encryption_salt": sjcl.codec.hex.toBits(vector["enc_salt_hex"].replace(/\s/g,'')),
Expand Down

0 comments on commit 6ba58d6

Please sign in to comment.