]> git.saurik.com Git - apple/security.git/blob - keychain/TrustedPeersHelper/TPHObjcTranslation.m
Security-59754.41.1.tar.gz
[apple/security.git] / keychain / TrustedPeersHelper / TPHObjcTranslation.m
1 #import "keychain/TrustedPeersHelper/TPHObjcTranslation.h"
2
3 #import <Security/SecKey.h>
4 #import <Security/SecKeyPriv.h>
5
6 #import <SecurityFoundation/SFKey.h>
7 #import <SecurityFoundation/SFKey_Private.h>
8 #import <corecrypto/ccsha2.h>
9 #import <corecrypto/ccrng.h>
10
11 @implementation TPHObjectiveC : NSObject
12
13 + (SFECKeyPair* _Nullable)fetchKeyPairWithPrivateKeyPersistentRef:(NSData *)persistentRef error:(NSError**)error
14 {
15 SecKeyRef seckey = NULL;
16 OSStatus status = SecKeyFindWithPersistentRef((__bridge CFDataRef)persistentRef, &seckey);
17
18 if(status) {
19 if(error) {
20 *error = [NSError errorWithDomain:NSOSStatusErrorDomain
21 code:status
22 userInfo:nil];
23 }
24 return nil;
25 }
26
27 return [[SFECKeyPair alloc] initWithSecKey: seckey];
28 }
29
30 + (ccec_full_ctx_t)ccec384Context
31 {
32 ccec_const_cp_t cp = ccec_cp_384();
33 size_t size = ccec_full_ctx_size(ccec_ccn_size(cp));
34 ccec_full_ctx_t heapContext = (ccec_full_ctx_t)malloc(size);
35 ccec_ctx_init(cp, heapContext);
36 return heapContext;
37 }
38
39 + (void)contextFree:(void*) context
40 {
41 free(context);
42 }
43
44 + (size_t) ccsha384_diSize{
45 return ccsha384_di()->output_size;
46 }
47
48 + (SFAESKeyBitSize)aes256BitSize{
49 return SFAESKeyBitSize256;
50 }
51
52 + (NSString*)digestUsingSha384:(NSData*) data {
53 const struct ccdigest_info *di = ccsha384_di();
54 NSMutableData* result = [[NSMutableData alloc] initWithLength:ccsha384_di()->output_size];
55
56 ccdigest(di, [data length], [data bytes], [result mutableBytes]);
57
58 return [result base64EncodedStringWithOptions:0];
59 }
60
61 @end