]> git.saurik.com Git - apple/security.git/blob - OSX/sec/Security/Regressions/secitem/si-90-emcs.m
Security-57740.31.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
19 /*
20 * change password
21 */
22
23 NSDictionary *newIdmsData = SecEMCSCreateNewiDMSKey(NULL, emcsKey, @"4321", NULL, NULL);
24
25 NSData *newEmcsKey = SecEMCSCreateDerivedEMCSKey(newIdmsData, @"4321", NULL);
26 ok(newEmcsKey, "new emcs key");
27
28 ok([newEmcsKey isEqualToData:emcsKey], "key same");
29 }
30
31 @autoreleasepool {
32
33 NSDictionary *fakeIdmsData = @{
34 @"iter" : @1000,
35 @"salt" : [NSData dataWithBytes:"\x7b\x30\x67\x4c\x01\x34\xae\xda\xaf\x4a\x34\xda\x68\x5b\x0b\x75" length:16],
36 @"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],
37 };
38
39 NSData *data = SecEMCSCreateDerivedEMCSKey(fakeIdmsData, @"1234", NULL);
40 ok(data, "KDF1");
41
42 ok([data isEqualToData:[NSData dataWithBytes:"\xa4\x42\x8b\xb0\xb8\x20\xdb\xfa\x58\x84\xab\xe3\x52\x93\xeb\x10" length:16]], "same");
43
44 data = SecEMCSCreateDerivedEMCSKey(fakeIdmsData, @"4321", NULL);
45 ok(!data, "KFD2");
46 }
47 }
48
49 int si_90_emcs(int argc, char *const *argv)
50 {
51 plan_tests(7);
52
53 tests();
54
55 return 0;
56 }