]>
Commit | Line | Data |
---|---|---|
b1ab9ed8 A |
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" | |
b1ab9ed8 A |
30 | #include <openssl/blowfish.h> |
31 | ||
32 | class BlowfishContext : public BlockCryptor { | |
33 | public: | |
34 | BlowfishContext(AppleCSPSession &session) : | |
35 | BlockCryptor(session), | |
36 | mInitFlag(false), | |
37 | mRawKeySize(0) { } | |
38 | ~BlowfishContext(); | |
39 | ||
40 | // called by CSPFullPluginSession | |
41 | void init(const Context &context, bool encoding = true); | |
42 | ||
43 | // As an optimization, we allow reuse of a modified context. | |
44 | // The main thing we avoid is a redundant key scheduling. We | |
45 | // save the current raw keys bits in mRawKey and compare on | |
46 | // re-init. | |
47 | bool changed(const Context &context) { return true; } | |
48 | ||
49 | // called by BlockCryptor | |
50 | void encryptBlock( | |
51 | const void *plainText, // length implied (one block) | |
52 | size_t plainTextLen, | |
53 | void *cipherText, | |
54 | size_t &cipherTextLen, // in/out, throws on overflow | |
55 | bool final); | |
56 | void decryptBlock( | |
57 | const void *cipherText, // length implied (one cipher block) | |
58 | size_t cipherTextLen, | |
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_ |