]>
git.saurik.com Git - apple/security.git/blob - SecurityServer/dbcrypto.h
2 * Copyright (c) 2000-2001 Apple Computer, Inc. All Rights Reserved.
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
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.
20 // dbcrypto - cryptographic core for database and key blob cryptography
25 #include "securityserver.h"
26 #include <Security/cspclient.h>
27 #include <Security/keyclient.h>
31 // A DatabaseCryptoCore object encapsulates the secret state of a database.
32 // It provides for encoding and decoding of database blobs and key blobs,
33 // and holds all state related to the database secrets.
35 class DatabaseCryptoCore
{
38 virtual ~DatabaseCryptoCore();
40 bool isValid() const { return mIsValid
; }
41 bool hasMaster() const { return mHaveMaster
; }
44 void generateNewSecrets();
45 CssmClient::Key
masterKey();
47 void setup(const DbBlob
*blob
, const CssmData
&passphrase
);
48 void setup(const DbBlob
*blob
, CssmClient::Key master
);
50 void decodeCore(DbBlob
*blob
, void **privateAclBlob
= NULL
);
51 DbBlob
*encodeCore(const DbBlob
&blobTemplate
,
52 const CssmData
&publicAcl
, const CssmData
&privateAcl
) const;
54 KeyBlob
*encodeKeyCore(const CssmKey
&key
,
55 const CssmData
&publicAcl
, const CssmData
&privateAcl
) const;
56 void decodeKeyCore(KeyBlob
*blob
,
57 CssmKey
&key
, void * &pubAcl
, void * &privAcl
) const;
59 static const uint32 managedAttributes
= KeyBlob::managedAttributes
;
60 static const uint32 forcedAttributes
= KeyBlob::forcedAttributes
;
63 bool validatePassphrase(const CssmData
&passphrase
);
66 bool mHaveMaster
; // master key has been entered (setup)
67 bool mIsValid
; // master secrets are valid (decode or generateNew)
69 CssmClient::Key mMasterKey
; // database master key
70 uint8 mSalt
[20]; // salt for master key derivation from passphrase (only)
72 CssmClient::Key mEncryptionKey
; // master encryption key
73 CssmClient::Key mSigningKey
; // master signing key
75 CssmClient::Key
deriveDbMasterKey(const CssmData
&passphrase
) const;
76 CssmClient::Key
makeRawKey(void *data
, size_t length
,
77 CSSM_ALGORITHMS algid
, CSSM_KEYUSE usage
);