os/security/crypto/weakcrypto/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 * Abstract base class for RC2 encipherment.
    54 *
    55 */
    56 class CRC2 : public CBlockTransformation
    57 {
    58 public:	
    59 	virtual void Reset();
    60 	virtual TInt BlockSize() const;
    61 	virtual TInt KeySize() const;
    62 protected:
    63 	/** @internalAll */
    64 	CRC2(void);
    65 	virtual void SetKey(const TDesC8& aKey, TInt aEffectiveKeyLenBits);
    66 protected:
    67 	/**
    68 	 * The expanded key buffer.
    69 	 *
    70 	 * Each iK[i] is a 16-bit word.
    71 	 */
    72 	TUint16 iK[KRC2ExpandedKeyLen];	//	128 bytes
    73 	/** 
    74 	 * The input key
    75 	 * 
    76 	 * The key length must fall between 1 and KRC2MaxKeySizeBytes (=128) bytes inclusive.
    77 	 */
    78 	TBuf8<KRC2MaxKeySizeBytes> iKey;
    79 	/** The effective key length in bits */
    80 	TInt iEffectiveKeyLenBits;
    81 };
    82 
    83 /**
    84 * Concrete class for RC2 encryption.
    85 *
    86 */
    87 class CRC2Encryptor : public CRC2
    88 {
    89 public:
    90 	/**
    91 	* Creates an instance of this class.
    92 	*
    93 	* @param aKey					The key to be used for encryption. The key length must fall between 
    94 	*								1 and KRC2MaxKeySizeBytes (=128) bytes inclusive.
    95 	* @param aEffectiveKeyLenBits	Effective key length bits
    96 	*								(defaults KSSLCompatibilityBits = 1024).
    97 	*
    98 	* @leave KErrKeyNotWeakEnough	If the key size is larger than that allowed by the
    99 	*								cipher strength restrictions of the crypto library.
   100 	*								See TCrypto::IsSymmetricWeakEnoughL()
   101 	*/
   102 	IMPORT_C static CRC2Encryptor* NewL(const TDesC8& aKey, 
   103 		TInt aEffectiveKeyLenBits = KSSLCompatibilityBits);
   104 	/**
   105 	* Creates an instance of this class and leaves it on the cleanup stack.
   106 	*
   107 	* @param aKey					The key to be used for encryption. The key length must fall between 
   108 	*								1 and KRC2MaxKeySizeBytes (=128) bytes inclusive.
   109 	* @param aEffectiveKeyLenBits	Effective key length bits 
   110 	*								(defaults KSSLCompatibilityBits = 1024).
   111 	*
   112 	* @leave KErrKeyNotWeakEnough	If the key size is larger than that allowed by the
   113 	*								cipher strength restrictions of the crypto library.
   114 	*								See TCrypto::IsSymmetricWeakEnoughL()
   115 	*/
   116 	IMPORT_C static CRC2Encryptor* NewLC(const TDesC8& aKey, 
   117 		TInt aEffectiveKeyLenBits = KSSLCompatibilityBits);
   118 	virtual void Transform(TDes8& aBlock);
   119 protected:
   120 	/** @internalAll */
   121 	CRC2Encryptor(void);
   122 };
   123 
   124 /**
   125 * Concrete class for RC2 decryption.
   126 *
   127 */
   128 class CRC2Decryptor : public CRC2
   129 {
   130 public:
   131 	/**
   132 	* Creates an instance of this class.
   133 	*
   134 	* @param aKey					The key to be used for decryption. The key length must fall between 
   135 	*								1 and KRC2MaxKeySizeBytes (=128) bytes inclusive.
   136 	* @param aEffectiveKeyLenBits	Effective key length bits 
   137 	*								(defaults KSSLCompatibilityBits = 1024).
   138 	*
   139 	* @leave KErrKeyNotWeakEnough	If the key size is larger than that allowed by the
   140 	*								cipher strength restrictions of the crypto library.
   141 	*								See TCrypto::IsSymmetricWeakEnoughL()
   142 	*/
   143 	IMPORT_C static CRC2Decryptor* NewL(const TDesC8& aKey, 
   144 		TInt aEffectiveKeyLenBits = KSSLCompatibilityBits);
   145 
   146 	/**
   147 	* Creates an instance of this class and leaves it on the cleanup stack.
   148 	*
   149 	* @param aKey					The key to be used for decryption. The key length must fall between 
   150 	*								1 and KRC2MaxKeySizeBytes (=128) bytes inclusive.
   151 	* @param aEffectiveKeyLenBits	Effective key length bits 
   152 	*								(defaults KSSLCompatibilityBits = 1024).
   153 	*
   154 	* @leave KErrKeyNotWeakEnough	If the key size is larger than that allowed by the
   155 	*								cipher strength restrictions of the crypto library.
   156 	*								See TCrypto::IsSymmetricWeakEnoughL()
   157 	*/
   158 	IMPORT_C static CRC2Decryptor* NewLC(const TDesC8& aKey, 
   159 		TInt aEffectiveKeyLenBits = KSSLCompatibilityBits);
   160 	virtual void Transform(TDes8& aBlock);
   161 protected:
   162 	/** @internalAll */
   163 	CRC2Decryptor(void);
   164 
   165 };
   166 
   167 #endif	//	__RC2_H__