From b0a8f622cc2982e4ac23978c84185ce9d04a7e9b Mon Sep 17 00:00:00 2001 From: Rob Napier Date: Fri, 10 Jan 2014 08:41:38 -0500 Subject: [PATCH] Auto-generate kdf_short vector tests --- RNCryptor.xcodeproj/project.pbxproj | 50 +++---- .../xcshareddata/RNCryptor.xccheckout | 26 +++- RNCryptorTests/GenVectorTests | 43 +++--- .../Generated/RNCryptorGeneratedVectorTests.m | 132 ++++++++++++++++++ ...ts.h => XCTestCase+RNCryptorVectorTests.h} | 5 +- ...ts.m => XCTestCase+RNCryptorVectorTests.m} | 34 +++-- Spec | 2 +- 7 files changed, 222 insertions(+), 70 deletions(-) create mode 100644 RNCryptorTests/Generated/RNCryptorGeneratedVectorTests.m rename RNCryptorTests/{RNCryptorVectorTests.h => XCTestCase+RNCryptorVectorTests.h} (62%) rename RNCryptorTests/{RNCryptorVectorTests.m => XCTestCase+RNCryptorVectorTests.m} (66%) diff --git a/RNCryptor.xcodeproj/project.pbxproj b/RNCryptor.xcodeproj/project.pbxproj index 0f7e00d6..12031dc5 100644 --- a/RNCryptor.xcodeproj/project.pbxproj +++ b/RNCryptor.xcodeproj/project.pbxproj @@ -25,12 +25,11 @@ AB13429515E0FC4600456914 /* RNCryptor.m in Sources */ = {isa = PBXBuildFile; fileRef = FB75651B1512D3E9007B806B /* RNCryptor.m */; }; AB13429715E0FC4E00456914 /* Security.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = AB13429615E0FC4E00456914 /* Security.framework */; }; AB13429915E0FD1D00456914 /* Foundation.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = AB13429815E0FD1D00456914 /* Foundation.framework */; }; + FB30216118802ED900BF8F3C /* RNCryptorGeneratedVectorTests.m in Sources */ = {isa = PBXBuildFile; fileRef = FB30216018802ED900BF8F3C /* RNCryptorGeneratedVectorTests.m */; }; FB53C180187EE93900952674 /* kdf in CopyFiles */ = {isa = PBXBuildFile; fileRef = FB53C17C187EE90400952674 /* kdf */; }; FB53C181187EE93900952674 /* key in CopyFiles */ = {isa = PBXBuildFile; fileRef = FB53C17D187EE90400952674 /* key */; }; FB53C182187EE93900952674 /* password in CopyFiles */ = {isa = PBXBuildFile; fileRef = FB53C17E187EE90400952674 /* password */; }; - FB53C183187EE93900952674 /* password-short in CopyFiles */ = {isa = PBXBuildFile; fileRef = FB53C17F187EE90400952674 /* password-short */; }; - FB53C187187EEDB600952674 /* kdf-short in CopyFiles */ = {isa = PBXBuildFile; fileRef = FB53C186187EEDA900952674 /* kdf-short */; }; - FB53C196187F6AB300952674 /* RNCryptorVectorTests.m in Sources */ = {isa = PBXBuildFile; fileRef = FB53C195187F6AB300952674 /* RNCryptorVectorTests.m */; }; + FB53C196187F6AB300952674 /* XCTestCase+RNCryptorVectorTests.m in Sources */ = {isa = PBXBuildFile; fileRef = FB53C195187F6AB300952674 /* XCTestCase+RNCryptorVectorTests.m */; }; FB6AC68D16F6704200CA0C0A /* Foundation.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = FB7564F31512D3C4007B806B /* Foundation.framework */; }; FB6AC69016F6704200CA0C0A /* main.m in Sources */ = {isa = PBXBuildFile; fileRef = FB6AC68F16F6704200CA0C0A /* main.m */; }; FB6AC69D16F672F700CA0C0A /* RNCryptor.m in Sources */ = {isa = PBXBuildFile; fileRef = FB75651B1512D3E9007B806B /* RNCryptor.m */; }; @@ -62,7 +61,6 @@ FB7565241512D9BE007B808D /* RNOpenSSLEncryptor.h in Headers */ = {isa = PBXBuildFile; fileRef = FB7565241512D9BE007B808C /* RNOpenSSLEncryptor.h */; }; FB7565241512D9BE007B808F /* RNOpenSSLDecryptor.h in Headers */ = {isa = PBXBuildFile; fileRef = FB7565241512D9BE007B808E /* RNOpenSSLDecryptor.h */; }; FB7565241512D9BE007B8091 /* RNOpenSSLDecryptor.m in Sources */ = {isa = PBXBuildFile; fileRef = FB7565241512D9BE007B8090 /* RNOpenSSLDecryptor.m */; }; - FB799107187F7EE00069BEB4 /* RNCryptorGeneratedVectorTests.m in Sources */ = {isa = PBXBuildFile; fileRef = FB799106187F7EE00069BEB4 /* RNCryptorGeneratedVectorTests.m */; }; FBF7D58E167E5031004B6F0F /* Foundation.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = FB7564F31512D3C4007B806B /* Foundation.framework */; }; FBF7D591167E5032004B6F0F /* rncryptorvectors.m in Sources */ = {isa = PBXBuildFile; fileRef = FBF7D590167E5032004B6F0F /* rncryptorvectors.m */; }; FBF7D5A9167E515D004B6F0F /* RNCryptor.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = AB13427A15E0FC2300456914 /* RNCryptor.framework */; }; @@ -94,11 +92,9 @@ dstPath = vectors/v3; dstSubfolderSpec = 16; files = ( - FB53C187187EEDB600952674 /* kdf-short in CopyFiles */, FB53C180187EE93900952674 /* kdf in CopyFiles */, FB53C181187EE93900952674 /* key in CopyFiles */, FB53C182187EE93900952674 /* password in CopyFiles */, - FB53C183187EE93900952674 /* password-short in CopyFiles */, ); runOnlyForDeploymentPostprocessing = 0; }; @@ -114,13 +110,14 @@ AB13428715E0FC2300456914 /* RNCryptor OS X-Prefix.pch */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = "RNCryptor OS X-Prefix.pch"; sourceTree = ""; }; AB13429615E0FC4E00456914 /* Security.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = Security.framework; path = Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.8.sdk/System/Library/Frameworks/Security.framework; sourceTree = DEVELOPER_DIR; }; AB13429815E0FD1D00456914 /* Foundation.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = Foundation.framework; path = Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.7.sdk/System/Library/Frameworks/Foundation.framework; sourceTree = DEVELOPER_DIR; }; + FB30216018802ED900BF8F3C /* RNCryptorGeneratedVectorTests.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = RNCryptorGeneratedVectorTests.m; sourceTree = ""; }; + FB30216218802F5000BF8F3C /* kdf_short */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; path = kdf_short; sourceTree = ""; }; + FB30216318802F5000BF8F3C /* password_short */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; path = password_short; sourceTree = ""; }; FB53C17C187EE90400952674 /* kdf */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; path = kdf; sourceTree = ""; }; FB53C17D187EE90400952674 /* key */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; path = key; sourceTree = ""; }; FB53C17E187EE90400952674 /* password */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; path = password; sourceTree = ""; }; - FB53C17F187EE90400952674 /* password-short */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; path = "password-short"; sourceTree = ""; }; - FB53C186187EEDA900952674 /* kdf-short */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; path = "kdf-short"; sourceTree = ""; }; - FB53C195187F6AB300952674 /* RNCryptorVectorTests.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = RNCryptorVectorTests.m; sourceTree = ""; }; - FB53C197187F6C6500952674 /* RNCryptorVectorTests.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = RNCryptorVectorTests.h; sourceTree = ""; }; + FB53C195187F6AB300952674 /* XCTestCase+RNCryptorVectorTests.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = "XCTestCase+RNCryptorVectorTests.m"; sourceTree = ""; }; + FB53C197187F6C6500952674 /* XCTestCase+RNCryptorVectorTests.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = "XCTestCase+RNCryptorVectorTests.h"; sourceTree = ""; }; FB6AC68C16F6704100CA0C0A /* rncrypt */ = {isa = PBXFileReference; explicitFileType = "compiled.mach-o.executable"; includeInIndex = 0; path = rncrypt; sourceTree = BUILT_PRODUCTS_DIR; }; FB6AC68F16F6704200CA0C0A /* main.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = main.m; sourceTree = ""; }; FB6AC69216F6704200CA0C0A /* rncrypt-Prefix.pch */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = "rncrypt-Prefix.pch"; sourceTree = ""; }; @@ -152,7 +149,6 @@ FB7565241512D9BE007B808E /* RNOpenSSLDecryptor.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = RNOpenSSLDecryptor.h; sourceTree = ""; }; FB7565241512D9BE007B8090 /* RNOpenSSLDecryptor.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = RNOpenSSLDecryptor.m; sourceTree = ""; }; FB7565241512D9BE007B8092 /* README.md */ = {isa = PBXFileReference; lastKnownFileType = file.md; path = README.md; sourceTree = ""; }; - FB799106187F7EE00069BEB4 /* RNCryptorGeneratedVectorTests.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = RNCryptorGeneratedVectorTests.m; path = "RNCryptorGeneratedVectorTests.m"; sourceTree = BUILT_PRODUCTS_DIR; }; FBE1F73A16A899D800C90463 /* RNCryptorV1.enc */ = {isa = PBXFileReference; lastKnownFileType = file; path = RNCryptorV1.enc; sourceTree = SOURCE_ROOT; }; FBF7D58C167E5031004B6F0F /* rncryptorvectors */ = {isa = PBXFileReference; explicitFileType = "compiled.mach-o.executable"; includeInIndex = 0; path = rncryptorvectors; sourceTree = BUILT_PRODUCTS_DIR; }; FBF7D590167E5032004B6F0F /* rncryptorvectors.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = rncryptorvectors.m; sourceTree = ""; }; @@ -236,6 +232,14 @@ name = "Supporting Files"; sourceTree = ""; }; + FB30215F18802E9700BF8F3C /* Generated */ = { + isa = PBXGroup; + children = ( + FB30216018802ED900BF8F3C /* RNCryptorGeneratedVectorTests.m */, + ); + path = Generated; + sourceTree = ""; + }; FB53C175187EE90400952674 /* vectors */ = { isa = PBXGroup; children = ( @@ -248,11 +252,11 @@ FB53C17B187EE90400952674 /* v3 */ = { isa = PBXGroup; children = ( + FB30216218802F5000BF8F3C /* kdf_short */, + FB30216318802F5000BF8F3C /* password_short */, FB53C17C187EE90400952674 /* kdf */, - FB53C186187EEDA900952674 /* kdf-short */, FB53C17D187EE90400952674 /* key */, FB53C17E187EE90400952674 /* password */, - FB53C17F187EE90400952674 /* password-short */, ); path = v3; sourceTree = ""; @@ -354,14 +358,14 @@ FB7565091512D3C4007B806B /* RNCryptorTests */ = { isa = PBXGroup; children = ( - FB799108187F7F900069BEB4 /* Generated Files */, + FB30215F18802E9700BF8F3C /* Generated */, + FB53C197187F6C6500952674 /* XCTestCase+RNCryptorVectorTests.h */, + FB53C195187F6AB300952674 /* XCTestCase+RNCryptorVectorTests.m */, FB7565101512D3C5007B806B /* RNCryptorTests.m */, FB6C9617185A0F1700CC2098 /* RNOpenSSLTests.m */, FB6C9619185A0F7600CC2098 /* RNCryptorTestHelpers.h */, FB6C961A185A0F7600CC2098 /* RNCryptorTestHelpers.m */, FB75650A1512D3C4007B806B /* Supporting Files */, - FB53C197187F6C6500952674 /* RNCryptorVectorTests.h */, - FB53C195187F6AB300952674 /* RNCryptorVectorTests.m */, ); path = RNCryptorTests; sourceTree = ""; @@ -376,14 +380,6 @@ name = "Supporting Files"; sourceTree = ""; }; - FB799108187F7F900069BEB4 /* Generated Files */ = { - isa = PBXGroup; - children = ( - FB799106187F7EE00069BEB4 /* RNCryptorGeneratedVectorTests.m */, - ); - name = "Generated Files"; - sourceTree = ""; - }; FBF7D58F167E5031004B6F0F /* RNCryptorVectors */ = { isa = PBXGroup; children = ( @@ -597,7 +593,7 @@ ); runOnlyForDeploymentPostprocessing = 0; shellPath = "/bin/sh -e -x"; - shellScript = "export LANG=en_US.UTF-8\nexport LANGUAGE=en_US.UTF-8\nexport LC_ALL=en_US.UTF-8\n\n${SRCROOT}/${TARGETNAME}/GenVectorTests -o ${BUILT_PRODUCTS_DIR}/RNCryptorGeneratedVectorTests.m -3 ${SRCROOT}/Spec/vectors/v3\n"; + shellScript = "export LANG=en_US.UTF-8\nexport LANGUAGE=en_US.UTF-8\nexport LC_ALL=en_US.UTF-8\n\n${SRCROOT}/${TARGETNAME}/GenVectorTests -o ${SRCROOT}/RNCryptorTests/Generated/RNCryptorGeneratedVectorTests.m -3 ${SRCROOT}/Spec/vectors/v3\n"; showEnvVarsInLog = 0; }; FB7564FE1512D3C4007B806B /* ShellScript */ = { @@ -660,10 +656,10 @@ isa = PBXSourcesBuildPhase; buildActionMask = 2147483647; files = ( - FB799107187F7EE00069BEB4 /* RNCryptorGeneratedVectorTests.m in Sources */, + FB30216118802ED900BF8F3C /* RNCryptorGeneratedVectorTests.m in Sources */, FB6C9618185A0F1700CC2098 /* RNOpenSSLTests.m in Sources */, FB7565111512D3C5007B806B /* RNCryptorTests.m in Sources */, - FB53C196187F6AB300952674 /* RNCryptorVectorTests.m in Sources */, + FB53C196187F6AB300952674 /* XCTestCase+RNCryptorVectorTests.m in Sources */, FB6C961B185A0F7600CC2098 /* RNCryptorTestHelpers.m in Sources */, ); runOnlyForDeploymentPostprocessing = 0; diff --git a/RNCryptor.xcodeproj/project.xcworkspace/xcshareddata/RNCryptor.xccheckout b/RNCryptor.xcodeproj/project.xcworkspace/xcshareddata/RNCryptor.xccheckout index 628581cb..224789c0 100644 --- a/RNCryptor.xcodeproj/project.xcworkspace/xcshareddata/RNCryptor.xccheckout +++ b/RNCryptor.xcodeproj/project.xcworkspace/xcshareddata/RNCryptor.xccheckout @@ -5,37 +5,49 @@ IDESourceControlProjectFavoriteDictionaryKey IDESourceControlProjectIdentifier - 57325159-086D-4DB3-936B-D4FEFABDF4DB + 3ABD3F64-A1E8-41CD-8789-63CBB720A99A IDESourceControlProjectName RNCryptor IDESourceControlProjectOriginsDictionary - 1D1067EB-8A1B-4368-9F17-F3953E22ACE9 - ssh://github.com/rnapier/RNCryptor.git + AB89CCB2-8938-48E0-92DF-EE3DD2C75CCB + ssh://github.com/RNCryptor/RNCryptor-Spec.git + D68E4317-45C0-46EA-86CB-15B52B489B23 + ssh://github.com/RNCryptor/RNCryptor.git IDESourceControlProjectPath RNCryptor.xcodeproj/project.xcworkspace IDESourceControlProjectRelativeInstallPathDictionary - 1D1067EB-8A1B-4368-9F17-F3953E22ACE9 + AB89CCB2-8938-48E0-92DF-EE3DD2C75CCB + ../../Spec + D68E4317-45C0-46EA-86CB-15B52B489B23 ../.. IDESourceControlProjectURL - ssh://github.com/rnapier/RNCryptor.git + ssh://github.com/RNCryptor/RNCryptor.git IDESourceControlProjectVersion 110 IDESourceControlProjectWCCIdentifier - 1D1067EB-8A1B-4368-9F17-F3953E22ACE9 + D68E4317-45C0-46EA-86CB-15B52B489B23 IDESourceControlProjectWCConfigurations IDESourceControlRepositoryExtensionIdentifierKey public.vcs.git IDESourceControlWCCIdentifierKey - 1D1067EB-8A1B-4368-9F17-F3953E22ACE9 + D68E4317-45C0-46EA-86CB-15B52B489B23 IDESourceControlWCCName RNCryptor + + IDESourceControlRepositoryExtensionIdentifierKey + public.vcs.git + IDESourceControlWCCIdentifierKey + AB89CCB2-8938-48E0-92DF-EE3DD2C75CCB + IDESourceControlWCCName + Spec + diff --git a/RNCryptorTests/GenVectorTests b/RNCryptorTests/GenVectorTests index b8a98b85..c0b08a5f 100755 --- a/RNCryptorTests/GenVectorTests +++ b/RNCryptorTests/GenVectorTests @@ -3,47 +3,54 @@ require 'optparse' require File.join(File.dirname(__FILE__), '../Spec/vectors', 'vectorparser') +@options = {} + + def NSDictionaryForHash(hash) "@{\n" + hash.collect { |key, value| %Q( @"#{key}": @"#{value}") }.join(",\n") + "}" end -options = {} +def outputTestsForFile(output, name) + + VectorParser.new(@options[:v3_directory] + "/" + name).vectors.each do |vector| + output << <<-TEST_CASE + +- (void)test_#{name}_#{vector["title"].gsub(' ', '_')} { + [self verify_#{name}:#{NSDictionaryForHash(vector)}]; +} + +TEST_CASE + + end +end opt_parser = OptionParser.new do |opt| opt.banner = "Usage: GenVectorTest -o VectorTests.m -3 v3_directory" opt.separator "" opt.on("-o","--output PATH","path to output code") do |output_path| - options[:output_path] = output_path + @options[:output_path] = output_path end opt.on("-3", "-3 PATH", "path to v3 directory") do |v3_directory| - options[:v3_directory] = v3_directory + @options[:v3_directory] = v3_directory end end opt_parser.parse! -raise OptionParser::MissingArgument if options[:output_path].nil? -raise OptionParser::MissingArgument if options[:v3_directory].nil? +raise OptionParser::MissingArgument if @options[:output_path].nil? +raise OptionParser::MissingArgument if @options[:v3_directory].nil? -File.open(options[:output_path], "w") do |output| +File.open(@options[:output_path], "w") do |output| output << <<-HEADER // Automatically Generated by GenVectorTests -#import "RNCryptorVectorTests.h" -@interface RNCryptorGeneratedVectorTests : RNCryptorVectorTests +#import "XCTestCase+RNCryptorVectorTests.h" +@interface RNCryptorGeneratedVectorTests : XCTestCase @end @implementation RNCryptorGeneratedVectorTests HEADER - VectorParser.new(options[:v3_directory] + "/kdf").vectors.each do |vector| - output << <<-TEST_CASE - -- (void)test_kdf_#{vector["title"].gsub(' ', '_')} { - [self verifyKDFVector:#{NSDictionaryForHash(vector)}]; -} - -TEST_CASE - - end + outputTestsForFile(output, "kdf"); + outputTestsForFile(output, "kdf_short"); output<< <<-FOOTER @end diff --git a/RNCryptorTests/Generated/RNCryptorGeneratedVectorTests.m b/RNCryptorTests/Generated/RNCryptorGeneratedVectorTests.m new file mode 100644 index 00000000..05fe671b --- /dev/null +++ b/RNCryptorTests/Generated/RNCryptorGeneratedVectorTests.m @@ -0,0 +1,132 @@ +// Automatically Generated by GenVectorTests +#import "XCTestCase+RNCryptorVectorTests.h" +@interface RNCryptorGeneratedVectorTests : XCTestCase +@end +@implementation RNCryptorGeneratedVectorTests + +- (void)test_kdf_One_byte { + [self verify_kdf:@{ + @"title": @"One byte", + @"version": @"3", + @"password": @"a", + @"salt_hex": @"0102030405060708", + @"key_hex": @"fc632b0c a6b23eff 9a9dc3e0 e585167f 5a328916 ed19f835 58be3ba9 828797cd"}]; +} + + +- (void)test_kdf_Short_password { + [self verify_kdf:@{ + @"title": @"Short password", + @"version": @"3", + @"password": @"thepassword", + @"salt_hex": @"0203040506070801", + @"key_hex": @"0ea84f52 52310dc3 e3a7607c 33bfd1eb 580805fb 68293005 da21037c cf499626"}]; +} + + +- (void)test_kdf_Passphrase { + [self 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"}]; +} + + +- (void)test_kdf_Long_passphrase { + [self 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"}]; +} + + +- (void)test_kdf_Multibyte { + [self verify_kdf:@{ + @"title": @"Multibyte", + @"version": @"3", + @"password": @"中文密码", + @"salt_hex": @"0506070801020304", + @"key_hex": @"d2fc3237 d4a69668 ca83d969 c2cda1ac 6c368479 2b6644b1 a90b2052 007215dd"}]; +} + + +- (void)test_kdf_Mixed_language { + [self 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"}]; +} + + +- (void)test_kdf_short_One_byte { + [self 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"}]; +} + + +- (void)test_kdf_short_Short_password { + [self 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"}]; +} + + +- (void)test_kdf_short_Passphrase { + [self 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"}]; +} + + +- (void)test_kdf_short_Long_passphrase { + [self 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"}]; +} + + +- (void)test_kdf_short_Multibyte { + [self verify_kdf_short:@{ + @"title": @"Multibyte", + @"version": @"3", + @"password": @"中文密码", + @"iterations": @"1000", + @"salt_hex": @"0506070801020304", + @"key_hex": @"10ac6088 7fce25a3 5cb96b41 86e85fde 088f2cb5 5bdac89c 5deffad6 95ba8a20"}]; +} + + +- (void)test_kdf_short_Mixed_language { + [self 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"}]; +} + +@end diff --git a/RNCryptorTests/RNCryptorVectorTests.h b/RNCryptorTests/XCTestCase+RNCryptorVectorTests.h similarity index 62% rename from RNCryptorTests/RNCryptorVectorTests.h rename to RNCryptorTests/XCTestCase+RNCryptorVectorTests.h index c1b84d86..25fbd435 100644 --- a/RNCryptorTests/RNCryptorVectorTests.h +++ b/RNCryptorTests/XCTestCase+RNCryptorVectorTests.h @@ -11,6 +11,7 @@ #import "RNEncryptor.h" #import "RNDecryptor.h" -@interface RNCryptorVectorTests : XCTestCase -- (void)verifyKDFVector:(NSDictionary *)vector; +@interface XCTestCase (RNCryptorVectorTests) +- (void)verify_kdf:(NSDictionary *)vector; +- (void)verify_kdf_short:(NSDictionary *)vector; @end diff --git a/RNCryptorTests/RNCryptorVectorTests.m b/RNCryptorTests/XCTestCase+RNCryptorVectorTests.m similarity index 66% rename from RNCryptorTests/RNCryptorVectorTests.m rename to RNCryptorTests/XCTestCase+RNCryptorVectorTests.m index bb7009cd..4d013a70 100644 --- a/RNCryptorTests/RNCryptorVectorTests.m +++ b/RNCryptorTests/XCTestCase+RNCryptorVectorTests.m @@ -6,7 +6,7 @@ // Copyright (c) 2014 Rob Napier. All rights reserved. // -#import "RNCryptorVectorTests.h" +#import "XCTestCase+RNCryptorVectorTests.h" NSData *GetDataForHex(NSString *hex) { NSString *hexNoSpaces = [[[hex stringByReplacingOccurrencesOfString:@" " withString:@""] @@ -26,25 +26,13 @@ return data; } -@implementation RNCryptorVectorTests - -- (void)setUp -{ - [super setUp]; - // Put setup code here; it will be run once, before the first test case. -} - -- (void)tearDown -{ - // Put teardown code here; it will be run once, after the last test case. - [super tearDown]; -} +@implementation XCTestCase (RNCryptorVectorTests) - (void)verifyVector:(NSDictionary *)vector key:(NSString *)key equals:(NSData *)actual title:(NSString*)title { XCTAssertEqualObjects(actual, GetDataForHex(vector[key]), @"Failed %@ test (v%d): %s\n", title, [vector[@"version"] intValue], [vector[@"title"] UTF8String]); } -- (void)verifyKDFVector:(NSDictionary *)vector { +- (void)verify_kdf:(NSDictionary *)vector { NSCParameterAssert(vector[@"title"]); NSCParameterAssert(vector[@"version"]); NSCParameterAssert(vector[@"password"]); @@ -57,6 +45,22 @@ - (void)verifyKDFVector:(NSDictionary *)vector { [self verifyVector:vector key:@"key_hex" equals:key title:@"kdf"]; } +- (void)verify_kdf_short:(NSDictionary *)vector { + NSCParameterAssert(vector[@"title"]); + NSCParameterAssert(vector[@"version"]); + NSCParameterAssert(vector[@"password"]); + NSCParameterAssert(vector[@"iterations"]); + NSCParameterAssert(vector[@"salt_hex"]); + NSCParameterAssert(vector[@"key_hex"]); + + RNCryptorKeyDerivationSettings settings = kRNCryptorAES256Settings.keySettings; + settings.rounds = 1000; + + NSData *key = [RNCryptor keyForPassword:vector[@"password"] + salt:GetDataForHex(vector[@"salt_hex"]) + settings:settings]; + [self verifyVector:vector key:@"key_hex" equals:key title:@"short kdf"]; +} @end diff --git a/Spec b/Spec index 1da6d751..b4b73c65 160000 --- a/Spec +++ b/Spec @@ -1 +1 @@ -Subproject commit 1da6d7514cb4f5015dbe2516477649ea92a54b95 +Subproject commit b4b73c65065ed8fe4f94c9ceec2d0b55a5845dd7