os/security/crypto/weakcryptospi/source/symmetric/arc4shim.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) 2006-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
* ARC4 shim classes definition
sl@0
    16
*
sl@0
    17
*/
sl@0
    18
sl@0
    19
sl@0
    20
/**
sl@0
    21
 @file
sl@0
    22
 @internalComponent
sl@0
    23
 @released
sl@0
    24
*/
sl@0
    25
sl@0
    26
#ifndef ARC4SHIM_H
sl@0
    27
#define ARC4SHIM_H
sl@0
    28
sl@0
    29
#include <arc4.h>
sl@0
    30
sl@0
    31
namespace CryptoSpi
sl@0
    32
	{
sl@0
    33
	class CCryptoParams;
sl@0
    34
	class CSymmetricCipher;
sl@0
    35
	class CKey;
sl@0
    36
	}
sl@0
    37
	
sl@0
    38
NONSHARABLE_CLASS(CArc4Shim) : public CARC4
sl@0
    39
{
sl@0
    40
public:
sl@0
    41
	/**
sl@0
    42
	Creates a CArc4Shim object which has the same interface as CARC4 
sl@0
    43
	but delegates all work to a Crypto SPI plug-in.
sl@0
    44
	@param aKey					The key to use. aKey must be less 
sl@0
    45
								than or equal to KRC4MaxKeySizeBytes.  
sl@0
    46
	@param aDiscardBytes		The number of bytes to drop from the 
sl@0
    47
								beginning of the key stream.
sl@0
    48
	@return						A pointer to a CArc4Shim instance
sl@0
    49
	@leave KErrKeyNotWeakEnough	If the key size is larger than that 
sl@0
    50
								allowed by the cipher strength 
sl@0
    51
								restrictions of the crypto library.
sl@0
    52
								See TCrypto::IsSymmetricWeakEnoughL()
sl@0
    53
	*/
sl@0
    54
	static CArc4Shim* NewL(const TDesC8& aKey, TUint aDiscardBytes);
sl@0
    55
	
sl@0
    56
	/**
sl@0
    57
	Creates a CArc4Shim object which has the same interface as CARC4,
sl@0
    58
	and leave it on the cleanup stack. but delegates all work to a 
sl@0
    59
	Crypto SPI plug-in.
sl@0
    60
	@param aKey					The key to use. aKey must be less 
sl@0
    61
								than or equal to KRC4MaxKeySizeBytes.  
sl@0
    62
	@param aDiscardBytes		The number of bytes to drop from the 
sl@0
    63
								beginning of the key stream.
sl@0
    64
	@return						A pointer to a CArc4Shim instance
sl@0
    65
	@leave KErrKeyNotWeakEnough	If the key size is larger than that 
sl@0
    66
								allowed by the cipher strength 
sl@0
    67
								restrictions of the crypto library.
sl@0
    68
								See TCrypto::IsSymmetricWeakEnoughL()
sl@0
    69
	*/
sl@0
    70
	static CArc4Shim* NewLC(const TDesC8& aKey, TUint aDiscardBytes);
sl@0
    71
sl@0
    72
	/**
sl@0
    73
	Destructor
sl@0
    74
	*/
sl@0
    75
	~CArc4Shim();
sl@0
    76
sl@0
    77
	// From CSymmetricCipher class
sl@0
    78
	void Reset();
sl@0
    79
	TInt BlockSize() const;
sl@0
    80
	TInt KeySize() const;		
sl@0
    81
	void Process(const TDesC8& aInput, TDes8& aOutput);
sl@0
    82
	void ProcessFinalL(const TDesC8& aInput, TDes8& aOutput);
sl@0
    83
	TInt MaxOutputLength(TInt aInputLength) const;
sl@0
    84
	TInt MaxFinalOutputLength(TInt aInputLength) const;
sl@0
    85
sl@0
    86
private:
sl@0
    87
	/** 
sl@0
    88
	Constructor
sl@0
    89
	*/
sl@0
    90
	CArc4Shim();
sl@0
    91
sl@0
    92
	/**
sl@0
    93
	Second Phase Constructor
sl@0
    94
	*/
sl@0
    95
	void ConstructL(const TDesC8& aKey, TUint aDiscardBytes);
sl@0
    96
		
sl@0
    97
private:
sl@0
    98
	/// SPI delegate
sl@0
    99
	CryptoSpi::CSymmetricCipher* iSymmetricCipherImpl;
sl@0
   100
		
sl@0
   101
	/// SPI requires all key to passed as key-objects
sl@0
   102
	CryptoSpi::CKey* iKey;
sl@0
   103
	
sl@0
   104
	CryptoSpi::CCryptoParams* iAlgorithmParams;
sl@0
   105
};
sl@0
   106
sl@0
   107
#endif // ARC4SHIM_H