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 * NullCryptor.h - null symmetric encryptor for measurement only
21 * Written by Doug Mitchell 12/17/2001
22 */
23#ifndef _NULL_CRYPTOR_H_
24#define _NULL_CRYPTOR_H_
25
26/*
27 * DO NOT DEFINE THIS SYMBOL TRUE FOR CODE CHECKED IN TO CVS
28 */
29#define NULL_CRYPT_ENABLE			0
30
31#if		NULL_CRYPT_ENABLE
32
33#include <security_cdsa_plugin/CSPsession.h>
34#include "AppleCSP.h"
35#include "AppleCSPContext.h"
36#include "AppleCSPSession.h"
37#include "BlockCryptor.h"
38
39#define NULL_CRYPT_BLOCK_SIZE		16
40
41class NullCryptor : public BlockCryptor {
42public:
43	NullCryptor(AppleCSPSession &session) :
44		BlockCryptor(session),
45		mInitFlag(false)	{ }
46	~NullCryptor() { }
47
48	// called by CSPFullPluginSession
49	void init(const Context &context, bool encoding = true)
50	{
51		if(mInitFlag && !opStarted()) {
52			return;
53		}
54		/* Just have BlockCryptor do its setup */
55		setup(NULL_CRYPT_BLOCK_SIZE, context);
56		mInitFlag = true;
57	}
58
59	// called by BlockCryptor
60	void encryptBlock(
61		const void		*plainText,			// length implied (one block)
62		size_t			plainTextLen,
63		void			*cipherText,
64		size_t			&cipherTextLen,		// in/out, throws on overflow
65		bool			final)
66	{
67		memmove(cipherText, plainText, NULL_CRYPT_BLOCK_SIZE);
68		cipherTextLen = NULL_CRYPT_BLOCK_SIZE;
69	}
70
71	void decryptBlock(
72		const void		*cipherText,		// length implied (one cipher block)
73		size_t			cipherTextLen,
74		void			*plainText,
75		size_t			&plainTextLen,		// in/out, throws on overflow
76		bool			final)
77	{
78		memmove(plainText, cipherText, NULL_CRYPT_BLOCK_SIZE);
79		plainTextLen = NULL_CRYPT_BLOCK_SIZE;
80	}
81
82private:
83	bool				mInitFlag;			// for easy reuse
84
85};	/* NullCryptor */
86
87#endif	/* NULL_CRYPT_ENABLE */
88
89#endif //_NULL_CRYPTOR_H_
90