]> git.saurik.com Git - apple/security.git/blob - AppleCSP/MiscCSPAlgs/bfContext.h
Security-163.tar.gz
[apple/security.git] / AppleCSP / MiscCSPAlgs / 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 void *plainText,
60 size_t &plainTextLen, // in/out, throws on overflow
61 bool final);
62
63 private:
64 void deleteKey();
65
66 /* scheduled key */
67 BF_KEY mBfKey;
68 bool mInitFlag; // for easy reuse
69
70 /*
71 * Raw key bits saved here and checked on re-init to avoid
72 * extra key schedule
73 */
74 uint8 mRawKey[BF_MAX_KEY_SIZE_BYTES];
75 uint32 mRawKeySize;
76
77
78 }; /* BlowfishContext */
79
80 #endif //_BF_CONTEXT_H_