]> git.saurik.com Git - apple/security.git/blob - libsecurity_apple_csp/lib/bfContext.h
Security-55163.44.tar.gz
[apple/security.git] / libsecurity_apple_csp / lib / bfContext.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 * bfContext.h - glue between BlockCrytpor and ssleay Blowfish
21 * implementation
22 * Written by Doug Mitchell 4/23/2003
23 */
24
25 #ifndef _BF_CONTEXT_H_
26 #define _BF_CONTEXT_H_
27
28 #include "AppleCSPContext.h"
29 #include "BlockCryptor.h"
30 #include <CoreServices/../Frameworks/CarbonCore.framework/Headers/MacTypes.h>
31 #include <openssl/blowfish.h>
32
33 class BlowfishContext : public BlockCryptor {
34 public:
35 BlowfishContext(AppleCSPSession &session) :
36 BlockCryptor(session),
37 mInitFlag(false),
38 mRawKeySize(0) { }
39 ~BlowfishContext();
40
41 // called by CSPFullPluginSession
42 void init(const Context &context, bool encoding = true);
43
44 // As an optimization, we allow reuse of a modified context.
45 // The main thing we avoid is a redundant key scheduling. We
46 // save the current raw keys bits in mRawKey and compare on
47 // re-init.
48 bool changed(const Context &context) { return true; }
49
50 // called by BlockCryptor
51 void encryptBlock(
52 const void *plainText, // length implied (one block)
53 size_t plainTextLen,
54 void *cipherText,
55 size_t &cipherTextLen, // in/out, throws on overflow
56 bool final);
57 void decryptBlock(
58 const void *cipherText, // length implied (one cipher block)
59 size_t cipherTextLen,
60 void *plainText,
61 size_t &plainTextLen, // in/out, throws on overflow
62 bool final);
63
64 private:
65 void deleteKey();
66
67 /* scheduled key */
68 BF_KEY mBfKey;
69 bool mInitFlag; // for easy reuse
70
71 /*
72 * Raw key bits saved here and checked on re-init to avoid
73 * extra key schedule
74 */
75 uint8 mRawKey[BF_MAX_KEY_SIZE_BYTES];
76 uint32 mRawKeySize;
77
78
79 }; /* BlowfishContext */
80
81 #endif //_BF_CONTEXT_H_