]> git.saurik.com Git - apple/securityd.git/blob - src/localdatabase.h
7e1f53fe13f5ee22eb1eaef1981bcb6d5558b677
[apple/securityd.git] / src / localdatabase.h
1 /*
2 * Copyright (c) 2004 Apple Computer, Inc. All Rights Reserved.
3 *
4 * @APPLE_LICENSE_HEADER_START@
5 *
6 * This file contains Original Code and/or Modifications of Original Code
7 * as defined in and that are subject to the Apple Public Source License
8 * Version 2.0 (the 'License'). You may not use this file except in
9 * compliance with the License. Please obtain a copy of the License at
10 * http://www.opensource.apple.com/apsl/ and read it before using this
11 * file.
12 *
13 * The Original Code and all software distributed under the License are
14 * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
15 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
16 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
17 * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
18 * Please see the License for the specific language governing rights and
19 * limitations under the License.
20 *
21 * @APPLE_LICENSE_HEADER_END@
22 */
23
24
25 //
26 // localdatabase - locally implemented database using internal CSP cryptography
27 //
28 // A LocalDatabase manages keys with a locally resident AppleCSP.
29 // This is an abstract class useful for subclassing.
30 //
31 #ifndef _H_LOCALDATABASE
32 #define _H_LOCALDATABASE
33
34 #include "database.h"
35
36 class LocalKey;
37
38
39 //
40 // A Database object represents an Apple CSP/DL open database (DL/DB) object.
41 // It maintains its protected semantic state (including keys) and provides controlled
42 // access.
43 //
44 class LocalDatabase : public Database {
45 public:
46 LocalDatabase(Process &proc);
47
48 public:
49 //void releaseKey(Key &key);
50 void queryKeySizeInBits(Key &key, CssmKeySize &result);
51
52 // service calls
53 void generateSignature(const Context &context, Key &key, CSSM_ALGORITHMS signOnlyAlgorithm,
54 const CssmData &data, CssmData &signature);
55 void verifySignature(const Context &context, Key &key, CSSM_ALGORITHMS verifyOnlyAlgorithm,
56 const CssmData &data, const CssmData &signature);
57 void generateMac(const Context &context, Key &key,
58 const CssmData &data, CssmData &mac);
59 void verifyMac(const Context &context, Key &key,
60 const CssmData &data, const CssmData &mac);
61
62 void encrypt(const Context &context, Key &key, const CssmData &clear, CssmData &cipher);
63 void decrypt(const Context &context, Key &key, const CssmData &cipher, CssmData &clear);
64
65 void generateKey(const Context &context,
66 const AccessCredentials *cred, const AclEntryPrototype *owner,
67 CSSM_KEYUSE usage, CSSM_KEYATTR_FLAGS attrs, RefPointer<Key> &newKey);
68 void generateKey(const Context &context,
69 const AccessCredentials *cred, const AclEntryPrototype *owner,
70 CSSM_KEYUSE pubUsage, CSSM_KEYATTR_FLAGS pubAttrs,
71 CSSM_KEYUSE privUsage, CSSM_KEYATTR_FLAGS privAttrs,
72 RefPointer<Key> &publicKey, RefPointer<Key> &privateKey);
73 void deriveKey(const Context &context, Key *key,
74 const AccessCredentials *cred, const AclEntryPrototype *owner,
75 CssmData *param, uint32 usage, uint32 attrs, RefPointer<Key> &derivedKey);
76
77 void wrapKey(const Context &context, const AccessCredentials *cred,
78 Key *wrappingKey, Key &keyToBeWrapped,
79 const CssmData &descriptiveData, CssmKey &wrappedKey);
80 void unwrapKey(const Context &context,
81 const AccessCredentials *cred, const AclEntryPrototype *owner,
82 Key *wrappingKey, Key *publicKey, CSSM_KEYUSE usage, CSSM_KEYATTR_FLAGS attrs,
83 const CssmKey wrappedKey, RefPointer<Key> &unwrappedKey, CssmData &descriptiveData);
84
85 void getOutputSize(const Context &context, Key &key, uint32 inputSize, bool encrypt, uint32 &result);
86
87 protected:
88 virtual RefPointer<Key> makeKey(const CssmKey &newKey, uint32 moreAttributes,
89 const AclEntryPrototype *owner) = 0;
90 };
91
92 #endif //_H_LOCALDATABASE