os/security/crypto/weakcryptospi/inc/rc2.h
author sl@SLION-WIN7.fritz.box
Fri, 15 Jun 2012 03:10:57 +0200
changeset 0 bde4ae8d615e
permissions -rw-r--r--
First public contribution.
     1 /*
     2 * Copyright (c) 2002-2009 Nokia Corporation and/or its subsidiary(-ies).
     3 * All rights reserved.
     4 * This component and the accompanying materials are made available
     5 * under the terms of the License "Eclipse Public License v1.0"
     6 * which accompanies this distribution, and is available
     7 * at the URL "http://www.eclipse.org/legal/epl-v10.html".
     8 *
     9 * Initial Contributors:
    10 * Nokia Corporation - initial contribution.
    11 *
    12 * Contributors:
    13 *
    14 * Description: 
    15 * ** IMPORTANT ** PublishedPartner API's in this file are published to 3rd party developers via the 
    16 * Symbian website. Changes to these API's should be treated as PublishedAll API changes and the Security TA should be consulted.
    17 * RC2 implementation
    18 *
    19 */
    20 
    21 
    22 /**
    23  @file 
    24  @publishedPartner
    25  @released 
    26 */
    27  
    28 #ifndef __RC2_H__
    29 #define __RC2_H__
    30 
    31 #include <blocktransformation.h>
    32 
    33 #ifndef SYMBIAN_ENABLE_SPLIT_HEADERS
    34 
    35 /** OpenSSL PKCS8 Effective Key Length Compatibility.*/
    36 const TUint KPkcs8CompatibilityBits = 128;
    37 
    38 /** PKCS12 PBE Effective Key Length Compatibility.*/
    39 const TUint KPkcs12CompatibilityBits = 40;
    40 
    41 #endif
    42 
    43 /** The expanded key length of an RC2 key.*/
    44 const TUint KRC2ExpandedKeyLen = 64;
    45 
    46 /** SSL Effective Key Length Compatibility.*/
    47 const TUint KSSLCompatibilityBits = 1024;
    48 
    49 /** The maximum size in bytes for a RC2 key.*/
    50 const TUint KRC2MaxKeySizeBytes = 128;	//	Max key size in this implementation = 128 bytes
    51 
    52 
    53 /**
    54 * Abstract base class for RC2 encipherment.
    55 *
    56 */
    57 class CRC2 : public CBlockTransformation
    58 {
    59 public:	
    60 	virtual void Reset();
    61 	virtual TInt BlockSize() const;
    62 	virtual TInt KeySize() const;
    63 protected:
    64 	/** @internalAll */
    65 	CRC2(void);
    66 	virtual void SetKey(const TDesC8& aKey, TInt aEffectiveKeyLenBits);
    67 protected:
    68 	/**
    69 	 * The expanded key buffer.
    70 	 *
    71 	 * Each iK[i] is a 16-bit word.
    72 	 */
    73 	TUint16 iK[KRC2ExpandedKeyLen];	//	128 bytes
    74 	/** 
    75 	 * The input key
    76 	 * 
    77 	 * The key length must fall between 1 and KRC2MaxKeySizeBytes (=128) bytes inclusive.
    78 	 */
    79 	TBuf8<KRC2MaxKeySizeBytes> iKey;
    80 	/** The effective key length in bits */
    81 	TInt iEffectiveKeyLenBits;
    82 };
    83 
    84 /**
    85 * Concrete class for RC2 encryption.
    86 *
    87 */
    88 class CRC2Encryptor : public CRC2
    89 {
    90 public:
    91 	/**
    92 	* Creates an instance of this class.
    93 	*
    94 	* @param aKey					The key to be used for encryption. The key length must fall between 
    95 	*								1 and KRC2MaxKeySizeBytes (=128) bytes inclusive.
    96 	* @param aEffectiveKeyLenBits	Effective key length bits
    97 	*								(defaults KSSLCompatibilityBits = 1024).
    98 	*
    99 	* @leave KErrKeyNotWeakEnough	If the key size is larger than that allowed by the
   100 	*								cipher strength restrictions of the crypto library.
   101 	*								See TCrypto::IsSymmetricWeakEnoughL()
   102 	*/
   103 	IMPORT_C static CRC2Encryptor* NewL(const TDesC8& aKey, 
   104 		TInt aEffectiveKeyLenBits = KSSLCompatibilityBits);
   105 	/**
   106 	* Creates an instance of this class and leaves it on the cleanup stack.
   107 	*
   108 	* @param aKey					The key to be used for encryption. The key length must fall between 
   109 	*								1 and KRC2MaxKeySizeBytes (=128) bytes inclusive.
   110 	* @param aEffectiveKeyLenBits	Effective key length bits 
   111 	*								(defaults KSSLCompatibilityBits = 1024).
   112 	*
   113 	* @leave KErrKeyNotWeakEnough	If the key size is larger than that allowed by the
   114 	*								cipher strength restrictions of the crypto library.
   115 	*								See TCrypto::IsSymmetricWeakEnoughL()
   116 	*/
   117 	IMPORT_C static CRC2Encryptor* NewLC(const TDesC8& aKey, 
   118 		TInt aEffectiveKeyLenBits = KSSLCompatibilityBits);
   119 	virtual void Transform(TDes8& aBlock);
   120 protected:
   121 	/** @internalAll */
   122 	CRC2Encryptor(void);
   123 };
   124 
   125 /**
   126 * Concrete class for RC2 decryption.
   127 *
   128 */
   129 class CRC2Decryptor : public CRC2
   130 {
   131 public:
   132 	/**
   133 	* Creates an instance of this class.
   134 	*
   135 	* @param aKey					The key to be used for decryption. The key length must fall between 
   136 	*								1 and KRC2MaxKeySizeBytes (=128) bytes inclusive.
   137 	* @param aEffectiveKeyLenBits	Effective key length bits 
   138 	*								(defaults KSSLCompatibilityBits = 1024).
   139 	*
   140 	* @leave KErrKeyNotWeakEnough	If the key size is larger than that allowed by the
   141 	*								cipher strength restrictions of the crypto library.
   142 	*								See TCrypto::IsSymmetricWeakEnoughL()
   143 	*/
   144 	IMPORT_C static CRC2Decryptor* NewL(const TDesC8& aKey, 
   145 		TInt aEffectiveKeyLenBits = KSSLCompatibilityBits);
   146 
   147 	/**
   148 	* Creates an instance of this class and leaves it on the cleanup stack.
   149 	*
   150 	* @param aKey					The key to be used for decryption. The key length must fall between 
   151 	*								1 and KRC2MaxKeySizeBytes (=128) bytes inclusive.
   152 	* @param aEffectiveKeyLenBits	Effective key length bits 
   153 	*								(defaults KSSLCompatibilityBits = 1024).
   154 	*
   155 	* @leave KErrKeyNotWeakEnough	If the key size is larger than that allowed by the
   156 	*								cipher strength restrictions of the crypto library.
   157 	*								See TCrypto::IsSymmetricWeakEnoughL()
   158 	*/
   159 	IMPORT_C static CRC2Decryptor* NewLC(const TDesC8& aKey, 
   160 		TInt aEffectiveKeyLenBits = KSSLCompatibilityBits);
   161 	virtual void Transform(TDes8& aBlock);
   162 protected:
   163 	/** @internalAll */
   164 	CRC2Decryptor(void);
   165 
   166 };
   167 
   168 #endif	//	__RC2_H__