]>
git.saurik.com Git - apple/security.git/blob - SecurityTests/cspxutils/utilLib/common.h
1 /* Copyright (c) 1997,2003,2005-2006,2008 Apple Inc.
3 * common.h - Common CSP test code
7 * 12 Aug 1997 Doug Mitchell at Apple
11 #ifndef _UTIL_LIB_COMMON_H_
12 #define _UTIL_LIB_COMMON_H_
14 #include <Security/cssm.h>
20 #undef COMMON_CSSM_MEMORY
21 #define COMMON_CSSM_MEMORY 0
23 #if COMMON_CSSM_MEMORY
24 #define CSSM_MALLOC(size) CSSM_Malloc(size)
25 #define CSSM_FREE(ptr) CSSM_Free(ptr)
26 #define CSSM_CALLOC(num, size) CSSM_Calloc(num, size)
27 #define CSSM_REALLOC(ptr, newSize) CSSM_Realloc(ptr, newSize)
28 /* used in cspwrap when allocating memory on app's behalf */
29 #define appMalloc(size, allocRef) CSSM_Malloc(size)
31 #else /* !COMMON_CSSM_MEMORY */
33 void * appMalloc (CSSM_SIZE size
, void *allocRef
);
34 void appFree (void *mem_ptr
, void *allocRef
);
35 void * appRealloc (void *ptr
, CSSM_SIZE size
, void *allocRef
);
36 void * appCalloc (uint32 num
, CSSM_SIZE size
, void *allocRef
);
38 #define CSSM_MALLOC(size) appMalloc(size, NULL)
39 #define CSSM_FREE(ptr) appFree(ptr, NULL)
40 #define CSSM_CALLOC(num, size) appCalloc(num, size, NULL)
41 #define CSSM_REALLOC(ptr, newSize) appRealloc(ptr, newSize, NULL)
43 #endif /* COMMON_CSSM_MEMORY */
46 * As of 23 March 1999, there is no longer a "default DB" available for
47 * generating keys. This is the standard DB handle created when
48 * calling cspStartup().
50 extern CSSM_DB_HANDLE commonDb
;
53 * Init CSSM; returns CSSM_FALSE on error. Reusable.
55 extern CSSM_BOOL
cssmStartup();
57 /* various flavors of "start up the CSP with optional DB open" */
58 CSSM_CSP_HANDLE
cspStartup(); // bare bones CSP
59 CSSM_CSP_HANDLE
cspDbStartup( // bare bones CSP, DB open
60 CSSM_DB_HANDLE
*dbHandPtr
);
61 CSSM_DL_HANDLE
dlStartup();
62 CSSM_CSP_HANDLE
cspDlDbStartup( // one size fits all
63 CSSM_BOOL bareCsp
, // true ==> CSP, false ==> CSP/DL
64 CSSM_DB_HANDLE
*dbHandPtr
); // optional
65 CSSM_RETURN
cspShutdown(
66 CSSM_CSP_HANDLE cspHand
,
67 CSSM_BOOL bareCsp
); // true ==> CSP, false ==> CSP/DL
69 CSSM_DL_HANDLE dlHand
, // from dlStartup()
71 CSSM_DB_HANDLE
dbStartup(
72 CSSM_DL_HANDLE dlHand
, // from dlStartup()
74 CSSM_RETURN
dbCreateOpen(
75 CSSM_DL_HANDLE dlHand
, // from dlStartup()
77 CSSM_BOOL doCreate
, // if false, must already exist
78 CSSM_BOOL deleteExist
,
79 const char *pwd
, // optional
80 CSSM_DB_HANDLE
*dbHand
);
82 extern void intToBytes(unsigned i
, unsigned char *buf
);
83 void shortToBytes(unsigned short s
, unsigned char *buf
);
84 unsigned bytesToInt(const unsigned char *buf
);
85 unsigned short bytesToShort(const unsigned char *buf
);
87 /* specify either 32-bit integer or a pointer as an added attribute value */
93 CSSM_RETURN
AddContextAttribute(CSSM_CC_HANDLE CCHandle
,
95 uint32 AttributeLength
,
96 ContextAttrType attrType
,
97 /* specify exactly one of these */
98 const void *AttributePtr
,
100 void printError(const char *op
, CSSM_RETURN err
);
101 CSSM_RETURN
appSetupCssmData(
104 void appFreeCssmData(CSSM_DATA_PTR data
,
105 CSSM_BOOL freeStruct
);
106 CSSM_RETURN
appCopyCssmData(const CSSM_DATA
*src
,
108 /* copy raw data to a CSSM_DATAm mallocing dst. */
109 CSSM_RETURN
appCopyData(const void *src
,
113 /* returns CSSM_TRUE on success, else CSSM_FALSE */
114 CSSM_BOOL
appCompareCssmData(const CSSM_DATA
*d1
,
115 const CSSM_DATA
*d2
);
117 const char *cssmErrToStr(CSSM_RETURN err
);
120 * Calculate random data size, fill dataPool with that many random bytes.
129 unsigned genData(unsigned char *dataPool
,
133 void simpleGenData(CSSM_DATA_PTR dbuf
, unsigned minBufSize
, unsigned maxBufSize
);
134 unsigned genRand(unsigned min
, unsigned max
);
135 extern void appGetRandomBytes(void *buf
, unsigned len
);
138 const char *bufName
, // optional
142 int testError(CSSM_BOOL quiet
);
144 void testStartBanner(
145 const char *testName
,
153 #endif /* _UTIL_LIB_COMMON_H_*/