os/security/crypto/weakcryptospi/inc/bufferedtransformation.h
author sl
Tue, 10 Jun 2014 14:32:02 +0200
changeset 1 260cb5ec6c19
permissions -rw-r--r--
Update contrib.
sl@0
     1
/*
sl@0
     2
* Copyright (c) 2002-2009 Nokia Corporation and/or its subsidiary(-ies).
sl@0
     3
* All rights reserved.
sl@0
     4
* This component and the accompanying materials are made available
sl@0
     5
* under the terms of the License "Eclipse Public License v1.0"
sl@0
     6
* which accompanies this distribution, and is available
sl@0
     7
* at the URL "http://www.eclipse.org/legal/epl-v10.html".
sl@0
     8
*
sl@0
     9
* Initial Contributors:
sl@0
    10
* Nokia Corporation - initial contribution.
sl@0
    11
*
sl@0
    12
* Contributors:
sl@0
    13
*
sl@0
    14
* Description: 
sl@0
    15
* ** IMPORTANT ** PublishedPartner API's in this file are published to 3rd party developers via the 
sl@0
    16
* Symbian website. Changes to these API's should be treated as PublishedAll API changes and the Security TA should be consulted.
sl@0
    17
*
sl@0
    18
*/
sl@0
    19
sl@0
    20
sl@0
    21
/**
sl@0
    22
 @file 
sl@0
    23
 @publishedPartner
sl@0
    24
 @released
sl@0
    25
*/
sl@0
    26
 
sl@0
    27
#ifndef __BUFFEREDTRANSFORMATION_H__
sl@0
    28
#define __BUFFEREDTRANSFORMATION_H__
sl@0
    29
sl@0
    30
#include <e32std.h>
sl@0
    31
#include <msymmetriccipher.h>
sl@0
    32
#include <blocktransformation.h>
sl@0
    33
sl@0
    34
class CPadding;
sl@0
    35
sl@0
    36
/**
sl@0
    37
 * Abstract class, deriving from CSymmetricCipher, encapsulating the buffering
sl@0
    38
 * logic for block ciphers.
sl@0
    39
 *
sl@0
    40
 * It is responsible for feeding complete blocks of plaintext or ciphertext to
sl@0
    41
 * the underlying encryptor or decryptor.  Since the only difference between
sl@0
    42
 * block cipher encryption and decryption is the ProcessFinalL() call,
sl@0
    43
 * CBufferedTransformation implements all functions (by buffering and/or
sl@0
    44
 * forwarding to the encryptor/decryptor) except ProcessFinalL() and
sl@0
    45
 * MaxFinalOutputLength().
sl@0
    46
 *
sl@0
    47
 * See the Cryptography api-guide documentation for the rules that this class
sl@0
    48
 * and derived classes must follow.
sl@0
    49
 *
sl@0
    50
 */
sl@0
    51
class CBufferedTransformation : public CSymmetricCipher
sl@0
    52
{
sl@0
    53
public:
sl@0
    54
	/** The destructor frees all resources owned by the object, prior to its destruction. */
sl@0
    55
	IMPORT_C virtual ~CBufferedTransformation();
sl@0
    56
public:
sl@0
    57
	/**
sl@0
    58
	 * Encrypts or decrypts the input using the underlying block cipher, buffering
sl@0
    59
	 * the input as necessary. 
sl@0
    60
	 *
sl@0
    61
	 * See the Cryptography api-guide documentation.
sl@0
    62
	 *
sl@0
    63
	 * @param aInput	The input is appended to the internal buffer (initially empty),
sl@0
    64
	 *					then all whole blocks are encrypted using the underlying block
sl@0
    65
	 *					transformation and written into aOutput. Any leftover bytes will
sl@0
    66
	 *					be buffered.
sl@0
    67
	 * @param aOutput	The resulting processed data appended to aOutput.  aOutput must
sl@0
    68
	 *					have at least MaxOutputLength() empty bytes remaining in its length.
sl@0
    69
	 */
sl@0
    70
	virtual void Process(const TDesC8& aInput, TDes8& aOutput);
sl@0
    71
	virtual TInt MaxOutputLength(TInt aInputLength) const;
sl@0
    72
	virtual void Reset();
sl@0
    73
	virtual TInt BlockSize() const;
sl@0
    74
	virtual TInt KeySize() const;
sl@0
    75
public:
sl@0
    76
	/** 
sl@0
    77
	 * Gets the underlying block transform.
sl@0
    78
	 *
sl@0
    79
	 * @return	A pointer to the CBlockTransformation object
sl@0
    80
	 */
sl@0
    81
	 IMPORT_C CBlockTransformation* BlockTransformer() const;
sl@0
    82
protected:
sl@0
    83
	/** @internalAll */
sl@0
    84
	CBufferedTransformation();
sl@0
    85
	/** @internalAll */
sl@0
    86
	void ConstructL(CBlockTransformation* aBT, CPadding* aPadding);
sl@0
    87
protected:
sl@0
    88
	/** A block transformation object */
sl@0
    89
	CBlockTransformation* iBT;
sl@0
    90
	/** A descriptor which provides a buffer the length of the block size of iBT */
sl@0
    91
	HBufC8* iInputStoreBuf;
sl@0
    92
	/** A pointer to iInputStoreBuf */
sl@0
    93
	TPtr8 iInputStore;
sl@0
    94
	/** The padding */
sl@0
    95
	CPadding* iPadding;
sl@0
    96
};
sl@0
    97
sl@0
    98
/**
sl@0
    99
 * Subclass of CBufferedTransformation for buffered encryption.
sl@0
   100
 *
sl@0
   101
 * Objects of this class are intialised with, and subsequently own, an encryptor
sl@0
   102
 * derived from CBlockTransformation and a subclass of CPadding.
sl@0
   103
 *
sl@0
   104
 */
sl@0
   105
class CBufferedEncryptor : public CBufferedTransformation
sl@0
   106
{
sl@0
   107
public:
sl@0
   108
	/**
sl@0
   109
	 * Creates a CBufferedEncryptor object taking ownership of aBT and aPadding.
sl@0
   110
	 *
sl@0
   111
	 * @param aBT		Block transformation object (encryptor)
sl@0
   112
	 * @param aPadding	Padding object (deriving from CPadding)
sl@0
   113
	 * @return			A pointer to the new CBufferedEncryptor object
sl@0
   114
	 */
sl@0
   115
	IMPORT_C static CBufferedEncryptor* NewL(CBlockTransformation* aBT, 
sl@0
   116
		CPadding* aPadding);
sl@0
   117
sl@0
   118
	/**
sl@0
   119
	 * Creates a CBufferedEncryptor object taking ownership of aBT and aPadding.
sl@0
   120
	 *
sl@0
   121
	 * The returned pointer is put onto the cleanup stack.
sl@0
   122
	 *
sl@0
   123
	 * @param aBT		Block transformation object (encryptor)
sl@0
   124
	 * @param aPadding	Padding object (deriving from CPadding)
sl@0
   125
	 * @return			A pointer to the new CBufferedEncryptor object
sl@0
   126
	 */
sl@0
   127
	IMPORT_C static CBufferedEncryptor* NewLC(CBlockTransformation* aBT, 
sl@0
   128
		CPadding* aPadding);
sl@0
   129
public:
sl@0
   130
	/**
sl@0
   131
	 * Completes an encryption operation using the underlying block transformation, but
sl@0
   132
	 * first ensuring that input data is block aligned using the previously supplied
sl@0
   133
	 * CPadding object.  
sl@0
   134
	 *
sl@0
   135
	 * See the Cryptography api-guide documentation.
sl@0
   136
	 *
sl@0
   137
	 * @param aInput	The final input data to be processed.
sl@0
   138
	 * @param aOutput	The resulting processed data appended to aOutput.  aOutput must
sl@0
   139
	 *					have at least MaxFinalOutputLength() empty bytes remaining in its
sl@0
   140
	 *					length.
sl@0
   141
	 */
sl@0
   142
	virtual void ProcessFinalL(const TDesC8& aInput, TDes8& aOutput);
sl@0
   143
	virtual TInt MaxFinalOutputLength(TInt aInputLength) const;
sl@0
   144
protected:
sl@0
   145
	/** @internalComponent */
sl@0
   146
	void ConstructL(CBlockTransformation* aBT, CPadding* aPadding);
sl@0
   147
sl@0
   148
	/** @internalAll */
sl@0
   149
	CBufferedEncryptor();
sl@0
   150
};
sl@0
   151
sl@0
   152
/**
sl@0
   153
 * Subclass of CBufferedTransformation for buffered decryption.
sl@0
   154
 *
sl@0
   155
 * Objects of this class are intialised with, and subsequently own, a decryptor
sl@0
   156
 * derived from CBlockTransformation and a subclass of CPadding.
sl@0
   157
 *
sl@0
   158
 */
sl@0
   159
class CBufferedDecryptor : public CBufferedTransformation
sl@0
   160
{
sl@0
   161
public:
sl@0
   162
	/**
sl@0
   163
	 * Creates a CBufferedDecryptor object taking ownership of aBT and aPadding.
sl@0
   164
	 *
sl@0
   165
	 * @param aBT		Block transformation object (decryptor)
sl@0
   166
	 * @param aPadding	Padding object (deriving from CPadding)
sl@0
   167
	 * @return			A pointer to the CBufferedDecryptor object.
sl@0
   168
	 */
sl@0
   169
	IMPORT_C static CBufferedDecryptor* NewL(CBlockTransformation* aBT, 
sl@0
   170
		CPadding* aPadding);
sl@0
   171
sl@0
   172
	/**
sl@0
   173
	 * Creates a CBufferedDecryptor object taking ownership of aBT and aPadding.
sl@0
   174
	 *
sl@0
   175
	 * The returned pointer is put onto the cleanup stack.
sl@0
   176
	 *
sl@0
   177
	 * @param aBT		Block transformation object (decryptor)
sl@0
   178
	 * @param aPadding	Padding object (deriving from CPadding)
sl@0
   179
	 * @return			A pointer to the new CBufferedDecryptor object
sl@0
   180
	 */
sl@0
   181
	IMPORT_C static CBufferedDecryptor* NewLC(CBlockTransformation* aBT, 
sl@0
   182
		CPadding* aPadding);
sl@0
   183
public:
sl@0
   184
	/**
sl@0
   185
	 * Completes a decryption operation using the underlying block transformation and
sl@0
   186
	 * unpads the decrypted data.
sl@0
   187
	 *
sl@0
   188
	 * @param aInput	The data to be processed and unpadded.  
sl@0
   189
	 *					aInput must be a whole number of blocks.
sl@0
   190
	 * @param aOutput	The resulting processed and unpadded data appened to aOutput.
sl@0
   191
	 *					aOutput must have at least MaxFinalOutputLength() empty bytes
sl@0
   192
	 *					remaining in its length.
sl@0
   193
	 */
sl@0
   194
	virtual void ProcessFinalL(const TDesC8& aInput, TDes8& aOutput);
sl@0
   195
	virtual TInt MaxFinalOutputLength(TInt aInputLength) const;
sl@0
   196
protected:
sl@0
   197
	/** @internalComponent */
sl@0
   198
	void ConstructL(CBlockTransformation* aBT, CPadding* aPadding);
sl@0
   199
sl@0
   200
	/** @internalAll */
sl@0
   201
	CBufferedDecryptor();
sl@0
   202
};
sl@0
   203
sl@0
   204
#endif	//	__CBUFFEREDTRANSFORMATION_H__