MYCrypto_Private.h
author snej@snej-mbp.mtv.corp.google.com
Wed Apr 08 16:30:52 2009 -0700 (2009-04-08)
changeset 3 1dfe820d7ebe
parent 2 8982b8fada63
child 4 f4709533c816
permissions -rw-r--r--
* Replaced MYKeyPair with MYPrivateKey.
* Changed config files.
     1 //
     2 //  MYCrypto_Private.h
     3 //  MYCrypto
     4 //
     5 //  Created by Jens Alfke on 3/23/09.
     6 //  Copyright 2009 Jens Alfke. All rights reserved.
     7 //
     8 
     9 #import "MYCryptoConfig.h"
    10 #import "MYKeychain.h"
    11 #import "MYKey.h"
    12 #import "MYSymmetricKey.h"
    13 #import "MYPublicKey.h"
    14 #import "MYPrivateKey.h"
    15 #import "MYCertificate.h"
    16 #import "Test.h"
    17 #import <Security/Security.h>
    18 
    19 
    20 #if MYCRYPTO_USE_IPHONE_API
    21 typedef CFTypeRef SecKeychainAttrType;
    22 typedef CFTypeRef SecKeychainItemRef;
    23 typedef CFTypeRef SecKeychainRef;
    24 typedef CFTypeRef SecExternalItemType;
    25 #endif
    26 
    27 
    28 #if TARGET_OS_IPHONE && !MYCRYPTO_USE_IPHONE_API
    29 @interface MYKeychain (Private)
    30 - (id) initWithKeychainRef: (SecKeychainRef)keychainRef;
    31 @property (readonly) SecKeychainRef keychainRef, keychainRefOrDefault;
    32 @property (readonly) CSSM_CSP_HANDLE CSPHandle;
    33 @property (readonly) NSString* path;
    34 @end
    35 #endif
    36 
    37 
    38 @interface MYKeychainItem (Private);
    39 - (id) initWithKeychainItemRef: (MYKeychainItemRef)itemRef;
    40 - (NSData*) _getContents: (OSStatus*)outError;
    41 - (NSString*) stringValueOfAttribute: (SecKeychainAttrType)attr;
    42 - (BOOL) setValue: (NSString*)valueStr ofAttribute: (SecKeychainAttrType)attr;
    43 + (NSData*) _getAttribute: (SecKeychainAttrType)attr ofItem: (MYKeychainItemRef)item;
    44 - (id) _attribute: (SecKeychainAttrType)attribute;
    45 + (NSString*) _getStringAttribute: (SecKeychainAttrType)attr ofItem: (MYKeychainItemRef)item;
    46 + (BOOL) _setAttribute: (SecKeychainAttrType)attr ofItem: (MYKeychainItemRef)item
    47            stringValue: (NSString*)stringValue;
    48 @end      
    49 
    50 
    51 @interface MYKey (Private)
    52 - (id) initWithKeyData: (NSData*)data;
    53 - (id) _initWithKeyData: (NSData*)data
    54             forKeychain: (SecKeychainRef)keychain;
    55 @property (readonly) SecExternalItemType keyType;
    56 @property (readonly) MYSHA1Digest* _keyDigest;
    57 - (NSData*) _crypt: (NSData *)data operation: (BOOL) op;    // YES to encrypt, NO to decrypt
    58 #if !MYCRYPTO_USE_IPHONE_API
    59 @property (readonly) const CSSM_KEY* cssmKey;
    60 - (NSData*) exportKeyInFormat: (SecExternalFormat)format withPEM: (BOOL)withPEM;
    61 - (CSSM_CC_HANDLE) _createSignatureContext: (CSSM_ALGORITHMS)algorithm;
    62 - (CSSM_CC_HANDLE) _createPassThroughContext;
    63 #endif
    64 @property (readonly) NSArray* _itemList;
    65 @end
    66 
    67 
    68 @interface MYSymmetricKey (Private)
    69 + (MYSymmetricKey*) _generateSymmetricKeyOfSize: (unsigned)keySizeInBits
    70                                       algorithm: (CCAlgorithm)algorithm
    71                                      inKeychain: (MYKeychain*)keychain;
    72 @end
    73 
    74 
    75 @interface MYPublicKey (Private)
    76 - (BOOL) setValue: (NSString*)valueStr ofAttribute: (SecKeychainAttrType)attr;
    77 @end
    78 
    79 
    80 @interface MYPrivateKey (Private)
    81 + (MYPrivateKey*) _generateRSAKeyPairOfSize: (unsigned)keySize
    82                                  inKeychain: (MYKeychain*)keychain;
    83 - (id) _initWithKeyData: (NSData*)privKeyData 
    84           publicKeyData: (NSData*)pubKeyData
    85             forKeychain: (SecKeychainRef)keychain 
    86              alertTitle: (NSString*)title
    87             alertPrompt: (NSString*)prompt;
    88 - (id) _initWithKeyData: (NSData*)privKeyData 
    89           publicKeyData: (NSData*)pubKeyData
    90             forKeychain: (SecKeychainRef)keychain 
    91              passphrase: (NSString*)passphrase;
    92 #if !TARGET_OS_IPHONE
    93 - (NSData*) _exportKeyInFormat: (SecExternalFormat)format
    94                        withPEM: (BOOL)withPEM
    95                     passphrase: (NSString*)passphrase;
    96 #endif
    97 @end
    98 
    99 
   100 #if TARGET_OS_IPHONE && !MYCRYPTO_USE_IPHONE_API
   101 @interface MYCertificate (Private)
   102 - (id) initWithCertificateData: (NSData*)data
   103                           type: (CSSM_CERT_TYPE) type
   104                       encoding: (CSSM_CERT_ENCODING) encoding;
   105 @end
   106 #endif
   107 
   108 
   109 #undef check
   110 BOOL check(OSStatus err, NSString *what);
   111 
   112 #if !MYCRYPTO_USE_IPHONE_API
   113 BOOL checkcssm(CSSM_RETURN err, NSString *what);
   114 
   115 SecKeyRef importKey(NSData *data, 
   116                     SecExternalItemType type,
   117                     SecKeychainRef keychain,
   118                     SecKeyImportExportParameters *params /*non-null*/);
   119 #endif