]> git.saurik.com Git - apple/security.git/blob - cdsa/cdsa_client/cryptoclient.h
Security-54.1.tar.gz
[apple/security.git] / cdsa / cdsa_client / cryptoclient.h
1 /*
2 * Copyright (c) 2000-2001 Apple Computer, Inc. All Rights Reserved.
3 *
4 * The contents of this file constitute Original Code as defined in and are
5 * subject to the Apple Public Source License Version 1.2 (the 'License').
6 * You may not use this file except in compliance with the License. Please obtain
7 * a copy of the License at http://www.apple.com/publicsource and read it before
8 * using this file.
9 *
10 * This Original Code and all software distributed under the License are
11 * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESS
12 * OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES, INCLUDING WITHOUT
13 * LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
14 * PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT. Please see the License for the
15 * specific language governing rights and limitations under the License.
16 */
17
18
19 //
20 // cryptoclient - client interface to CSSM CSP encryption/decryption operations
21 //
22 #ifndef _H_CDSA_CLIENT_CRYPTOCLIENT
23 #define _H_CDSA_CLIENT_CRYPTOCLIENT 1
24
25 #include <Security/cspclient.h>
26 #include <Security/keyclient.h>
27
28 namespace Security
29 {
30
31 namespace CssmClient
32 {
33
34 class Crypt : public Context
35 {
36 public:
37 Crypt(const CSP &csp, CSSM_ALGORITHMS alg);
38
39 public:
40 // Context attributes
41 CSSM_ENCRYPT_MODE mode() const { return mMode; }
42 void mode(CSSM_ENCRYPT_MODE m) { mMode = m; set(CSSM_ATTRIBUTE_MODE, m); }
43 const AccessCredentials *cred() const { return mCred; }
44 void cred(const AccessCredentials *c);
45 Key key() const { return mKey; }
46 void key(const Key &k) { mKey = k; set(CSSM_ATTRIBUTE_KEY, k); }
47 const CssmData &initVector() const { return *mInitVector; }
48 void initVector(const CssmData &v) { mInitVector = &v; set(CSSM_ATTRIBUTE_INIT_VECTOR, v); }
49 CSSM_PADDING padding() const { return mPadding; }
50 void padding(CSSM_PADDING p) { mPadding = p; set(CSSM_ATTRIBUTE_PADDING, p); }
51
52 // Other attributes
53 AclEntryInput aclEntry() const { return mAclEntry; }
54 void aclEntry(AclEntryInput &aclEntry) { mAclEntry = aclEntry; }
55
56 protected:
57 void activate();
58
59 protected:
60 CSSM_ENCRYPT_MODE mMode;
61 Key mKey;
62 const CssmData *mInitVector;
63 CSSM_PADDING mPadding;
64
65 protected:
66 const AccessCredentials *mCred;
67 AclEntryInput mAclEntry;
68 };
69
70
71
72 //
73 // An encryption context
74 //
75 class Encrypt : public Crypt
76 {
77 public:
78 Encrypt(const CSP &csp, CSSM_ALGORITHMS alg) : Crypt(csp, alg) {};
79
80
81 public:
82 // integrated
83 uint32 encrypt(const CssmData *in, uint32 inCount, CssmData *out, uint32 outCount,
84 CssmData &remData);
85 uint32 encrypt(const CssmData &in, CssmData &out, CssmData &remData)
86 { return encrypt(&in, 1, &out, 1, remData); }
87
88 // staged update
89 void init(); // Optional
90 uint32 encrypt(const CssmData *in, uint32 inCount, CssmData *out, uint32 outCount);
91 uint32 encrypt(const CssmData &in, CssmData &out)
92 { return encrypt(&in, 1, &out, 1); }
93 // staged final
94 void final(CssmData &remData);
95
96 };
97
98 //
99 // An Decryption context
100 //
101 class Decrypt : public Crypt
102 {
103 public:
104 Decrypt(const CSP &csp, CSSM_ALGORITHMS alg) : Crypt(csp, alg) {};
105
106 public:
107 // integrated
108 uint32 decrypt(const CssmData *in, uint32 inCount, CssmData *out, uint32 outCount,
109 CssmData &remData);
110 uint32 decrypt(const CssmData &in, CssmData &out, CssmData &remData)
111 { return decrypt(&in, 1, &out, 1, remData); }
112
113 // staged update
114 void init(); // Optional
115 uint32 decrypt(const CssmData *in, uint32 inCount, CssmData *out, uint32 outCount);
116 uint32 decrypt(const CssmData &in, CssmData &out)
117 { return decrypt(&in, 1, &out, 1); }
118 // staged final
119 void final(CssmData &remData);
120 };
121
122
123 } // end namespace CssmClient
124
125 } // end namespace Security
126
127 #endif // _H_CDSA_CLIENT_CRYPTOCLIENT