MYCrypto_Private.h
author snej@snej.local
Thu Apr 09 22:46:48 2009 -0700 (2009-04-09)
changeset 6 2d7692f9b6b4
parent 3 1dfe820d7ebe
child 8 4c0eafa7b233
permissions -rw-r--r--
Updated the README for the 0.1 release.
     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 #if !TARGET_OS_IPHONE
    78 - (CSSM_WRAP_KEY*) _unwrappedCSSMKey;
    79 #endif
    80 @end
    81 
    82 
    83 @interface MYPrivateKey (Private)
    84 + (MYPrivateKey*) _generateRSAKeyPairOfSize: (unsigned)keySize
    85                                  inKeychain: (MYKeychain*)keychain;
    86 - (id) _initWithKeyRef: (SecKeyRef)privateKey
    87              publicKey: (MYPublicKey*)publicKey;
    88 - (id) _initWithKeyData: (NSData*)privKeyData 
    89           publicKeyData: (NSData*)pubKeyData
    90             forKeychain: (SecKeychainRef)keychain 
    91              alertTitle: (NSString*)title
    92             alertPrompt: (NSString*)prompt;
    93 - (id) _initWithKeyData: (NSData*)privKeyData 
    94           publicKeyData: (NSData*)pubKeyData
    95             forKeychain: (SecKeychainRef)keychain 
    96              passphrase: (NSString*)passphrase;
    97 #if !TARGET_OS_IPHONE
    98 - (NSData*) _exportKeyInFormat: (SecExternalFormat)format
    99                        withPEM: (BOOL)withPEM
   100                     passphrase: (NSString*)passphrase;
   101 #endif
   102 @end
   103 
   104 
   105 #if TARGET_OS_IPHONE && !MYCRYPTO_USE_IPHONE_API
   106 @interface MYCertificate (Private)
   107 - (id) initWithCertificateData: (NSData*)data
   108                           type: (CSSM_CERT_TYPE) type
   109                       encoding: (CSSM_CERT_ENCODING) encoding;
   110 @end
   111 #endif
   112 
   113 
   114 #undef check
   115 BOOL check(OSStatus err, NSString *what);
   116 
   117 #if !MYCRYPTO_USE_IPHONE_API
   118 BOOL checkcssm(CSSM_RETURN err, NSString *what);
   119 
   120 SecKeyRef importKey(NSData *data, 
   121                     SecExternalItemType type,
   122                     SecKeychainRef keychain,
   123                     SecKeyImportExportParameters *params /*non-null*/);
   124 #endif