]> git.saurik.com Git - apple/security.git/blob - SecurityTests/cspxutils/utilLib/bsafeUtils.h
Security-57740.31.2.tar.gz
[apple/security.git] / SecurityTests / cspxutils / utilLib / bsafeUtils.h
1 /*
2 * bsafeUtils.h - common routines for CDSA/BSAFE compatibility testing
3 */
4
5 /*
6 * Clients of this module do not need to know about or see anything from the
7 * BSAFE headers.
8 */
9 #ifndef _BSAFE_UTILS_H_
10 #define _BSAFE_UTILS_H_
11 #include <Security/cssmtype.h>
12
13 #ifdef __cplusplus
14 extern "C" {
15 #endif
16
17 /* Actually the same as a B_KEY_OBJ, but our callers don't need to know that */
18 typedef void *BU_KEY;
19
20 /*
21 * Create a symmetric key.
22 */
23 CSSM_RETURN buGenSymKey(
24 uint32 keySizeInBits,
25 const CSSM_DATA *keyData,
26 BU_KEY *key); // RETURNED
27
28 /*
29 * Create asymmetric key pair.
30 * FIXME - additional params (e.g. DSA params, RSA exponent)?
31 */
32 CSSM_RETURN buGenKeyPair(
33 uint32 keySizeInBits,
34 CSSM_ALGORITHMS keyAlg, // CSSM_ALGID_{RSA,DSA}
35 BU_KEY *pubKey, // RETURNED
36 BU_KEY *privKey); // RETURNED
37
38 /*
39 * Free a key created in buGenSymKey or buGenKeyPair
40 */
41 CSSM_RETURN buFreeKey(
42 BU_KEY key);
43
44 /*
45 * encrypt/decrypt
46 */
47 CSSM_RETURN buEncryptDecrypt(
48 BU_KEY key,
49 CSSM_BOOL forEncrypt,
50 CSSM_ALGORITHMS encrAlg,
51 CSSM_ENCRYPT_MODE mode, // CSSM_ALGMODE_CBC, etc.
52 const CSSM_DATA *iv, //ĂŠoptional per mode
53 uint32 effectiveKeyBits, // optional per key alg (actually just RC2)
54 // for RSA, key size in bits
55 uint32 rounds, // optional, RC5 only
56 const CSSM_DATA *inData,
57 CSSM_DATA_PTR outData); // mallocd and RETURNED
58
59 /*
60 * Sign/verify
61 */
62 CSSM_RETURN buSign(
63 BU_KEY key,
64 CSSM_ALGORITHMS sigAlg,
65 const CSSM_DATA *ptext,
66 uint32 keySizeInBits, // to set up sig
67 CSSM_DATA_PTR sig); // mallocd and RETURNED
68
69 CSSM_RETURN buVerify(
70 BU_KEY key,
71 CSSM_ALGORITHMS sigAlg,
72 const CSSM_DATA *ptext,
73 const CSSM_DATA *sig); // mallocd and RETURNED
74
75 /*
76 * generate MAC either one update (updateSizes == NULL) or
77 * specified set of update sizes.
78 */
79 CSSM_RETURN buGenMac(
80 BU_KEY key, // any key, any size
81 CSSM_ALGORITHMS macAlg, // only CSSM_ALGID_SHA1HMAC for now
82 const CSSM_DATA *ptext,
83 unsigned *updateSizes, // NULL --> random updates
84 // else null-terminated list of sizes
85 CSSM_DATA_PTR mac); // mallocd and RETURNED
86
87 /* generate digest */
88 CSSM_RETURN buGenDigest(
89 CSSM_ALGORITHMS macAlg, // CSSM_ALGID_SHA1, etc. */
90 const CSSM_DATA *ptext,
91 CSSM_DATA_PTR digest); // mallocd and RETURNED
92
93 /*
94 * Convert between BSAFE and CDSA private keys
95 */
96 CSSM_RETURN buBsafePrivKeyToCdsa(
97 CSSM_ALGORITHMS keyAlg,
98 uint32 keySizeInBits,
99 BU_KEY bsafePrivKey,
100 CSSM_KEY_PTR cdsaPrivKey);
101 CSSM_RETURN buCdsaPrivKeyToBsafe(
102 CSSM_KEY_PTR cdsaPrivKey,
103 BU_KEY *bsafePrivKey);
104
105 #ifdef __cplusplus
106 }
107 #endif
108
109 #endif /* _BSAFE_UTILS_H_ */