]> git.saurik.com Git - apple/security.git/blob - AppleCSP/MiscCSPAlgs/MacContext.h
Security-29.tar.gz
[apple/security.git] / AppleCSP / MiscCSPAlgs / MacContext.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 * MacContext.h - AppleCSPContext for HMACSHA1
20 */
21
22 #ifndef _MAC_CONTEXT_H_
23 #define _MAC_CONTEXT_H_
24
25 #include <AppleCSP/AppleCSPContext.h>
26 #include <PBKDF2/HMACSHA1.h>
27
28 #define HMAC_MIN_KEY_SIZE 20 /* in bytes */
29 #define HMAC_MAX_KEY_SIZE 2048
30
31
32 class MacContext : public AppleCSPContext {
33 public:
34 MacContext(
35 AppleCSPSession &session) :
36 AppleCSPContext(session), mHmac(NULL) { }
37 ~MacContext();
38
39 /* called out from CSPFullPluginSession....
40 * both generate and verify: */
41 void init(const Context &context, bool isSigning);
42 void update(const CssmData &data);
43
44 /* generate only */
45 void final(CssmData &out);
46
47 /* verify only */
48 void final(const CssmData &in);
49
50 size_t outputSize(bool final, size_t inSize);
51
52 private:
53 hmacContextRef mHmac;
54 };
55
56 #ifdef CRYPTKIT_CSP_ENABLE
57 #include <CryptKit/HmacSha1Legacy.h>
58
59 /* This version is bug-for-bug compatible with a legacy implementation */
60
61 class MacLegacyContext : public AppleCSPContext {
62 public:
63 MacLegacyContext(
64 AppleCSPSession &session) :
65 AppleCSPContext(session), mHmac(NULL) { }
66 ~MacLegacyContext();
67
68 /* called out from CSPFullPluginSession....
69 * both generate and verify: */
70 void init(const Context &context, bool isSigning);
71 void update(const CssmData &data);
72
73 /* generate only */
74 void final(CssmData &out);
75
76 /* verify only */
77 void final(const CssmData &in);
78
79 size_t outputSize(bool final, size_t inSize);
80
81 private:
82 hmacLegacyContextRef mHmac;
83 };
84
85 #endif /* CRYPTKIT_CSP_ENABLE */
86
87 #endif /* _MAC_CONTEXT_H_ */