]> git.saurik.com Git - apple/security.git/blob - OSX/sec/Security/Regressions/secitem/si-90-emcs.m
Security-59306.41.2.tar.gz
[apple/security.git] / OSX / sec / Security / Regressions / secitem / si-90-emcs.m
1 #define __KEYCHAINCORE__ 1
2
3 #include <Foundation/Foundation.h>
4 #include <Security/Security.h>
5
6 #include "SecEMCSPriv.h"
7 #include "Security_regressions.h"
8
9 static void tests(void)
10 {
11
12 @autoreleasepool {
13 NSDictionary *idmsData = SecEMCSCreateNewiDMSKey(NULL, NULL, @"1234", NULL, NULL);
14 ok(idmsData);
15
16 NSData *emcsKey = SecEMCSCreateDerivedEMCSKey(idmsData, @"1234", NULL);
17 ok(emcsKey, "emcs key");
18 if (!emcsKey) @throw @"emacsKey missing";
19
20 /*
21 * change password
22 */
23
24 NSDictionary *newIdmsData = SecEMCSCreateNewiDMSKey(NULL, emcsKey, @"4321", NULL, NULL);
25
26 NSData *newEmcsKey = SecEMCSCreateDerivedEMCSKey(newIdmsData, @"4321", NULL);
27 ok(newEmcsKey, "new emcs key");
28
29 ok([newEmcsKey isEqualToData:emcsKey], "key same");
30 }
31
32 @autoreleasepool {
33
34 NSDictionary *fakeIdmsData = @{
35 @"iter" : @1000,
36 @"salt" : [NSData dataWithBytes:"\x7b\x30\x67\x4c\x01\x34\xae\xda\xaf\x4a\x34\xda\x68\x5b\x0b\x75" length:16],
37 @"wkey" : [NSData dataWithBytes:"\xa1\x15\xee\x24\xdf\x39\xd6\x96\xb9\x57\x65\xa0\xec\x7d\x80\x4c\xd1\xb3\xc0\x31\x38\xc0\x3a\x38" length: 24],
38 };
39
40 NSData *data = SecEMCSCreateDerivedEMCSKey(fakeIdmsData, @"1234", NULL);
41 ok(data, "KDF1");
42
43 ok([data isEqualToData:[NSData dataWithBytes:"\xa4\x42\x8b\xb0\xb8\x20\xdb\xfa\x58\x84\xab\xe3\x52\x93\xeb\x10" length:16]], "same");
44
45 data = SecEMCSCreateDerivedEMCSKey(fakeIdmsData, @"4321", NULL);
46 ok(!data, "KFD2");
47 }
48 }
49
50 int si_90_emcs(int argc, char *const *argv)
51 {
52 plan_tests(7);
53
54 tests();
55
56 return 0;
57 }