os/security/crypto/weakcryptospi/source/symmetric/arc4shim.cpp
author sl
Tue, 10 Jun 2014 14:32:02 +0200
changeset 1 260cb5ec6c19
permissions -rw-r--r--
Update contrib.
     1 /*
     2 * Copyright (c) 2006-2010 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 *
    16 */
    17 
    18 
    19 
    20 #include "arc4shim.h"
    21 
    22 #include <cryptospi/cryptosymmetriccipherapi.h>
    23 #include <cryptospi/cryptospidef.h>
    24 #include <cryptospi/plugincharacteristics.h>
    25 #include <cryptostrength.h>
    26 #include "../common/inlines.h"
    27 #include <cryptospi/keys.h>
    28 
    29 using namespace CryptoSpi;
    30 
    31 CArc4Shim* CArc4Shim::NewL(const TDesC8& aKey, TUint aDiscardBytes)
    32 	{
    33 	CArc4Shim* self = NewLC(aKey, aDiscardBytes);
    34 	CleanupStack::Pop(self);
    35 	return self;
    36 	}
    37 
    38 CArc4Shim* CArc4Shim::NewLC(const TDesC8& aKey, TUint aDiscardBytes)
    39 	{
    40 	CArc4Shim* self = new (ELeave) CArc4Shim();
    41 	CleanupStack::PushL(self);
    42 	self->ConstructL(aKey, aDiscardBytes);
    43 	TCrypto::IsSymmetricWeakEnoughL(BytesToBits(aKey.Size()));
    44 	return self;
    45 	}
    46 
    47 void CArc4Shim::ConstructL(const TDesC8& aKey, TUint aDiscardBytes)
    48 	{
    49 	TKeyProperty keyProperty = {KArc4Uid, KNullUid, KSymmetricKey, KNonEmbeddedKeyUid};
    50 	CCryptoParams* keyParam =CCryptoParams::NewLC();
    51 	keyParam->AddL(aKey, KSymmetricKeyParameterUid);
    52 	iKey=CKey::NewL(keyProperty, *keyParam);
    53 	CleanupStack::PopAndDestroy(keyParam);
    54 	
    55 	iAlgorithmParams = CCryptoParams::NewL();
    56 	iAlgorithmParams->AddL(aDiscardBytes, KARC4DiscardBytes);
    57 
    58 	CSymmetricCipherFactory::CreateSymmetricCipherL(
    59 												iSymmetricCipherImpl,
    60 												KArc4Uid,
    61 												*iKey,
    62 												KCryptoModeNoneUid,
    63 												KOperationModeNoneUid,
    64 												KPaddingModeNoneUid,
    65 												iAlgorithmParams);
    66 	}
    67 
    68 CArc4Shim::~CArc4Shim()
    69 	{
    70 	delete iSymmetricCipherImpl;
    71 	delete iKey;	
    72 	delete iAlgorithmParams;
    73 	}
    74 
    75 void CArc4Shim::Reset()
    76 	{
    77 	iSymmetricCipherImpl->Reset();
    78 	}
    79 
    80 TInt CArc4Shim::BlockSize() const
    81 	{
    82 	return iSymmetricCipherImpl->BlockSize() >> 3; // Convert to bits
    83 	}
    84 
    85 TInt CArc4Shim::KeySize() const
    86 	{
    87 	return iSymmetricCipherImpl->KeySize();
    88 	}
    89 
    90 void CArc4Shim::Process(const TDesC8& aInput, TDes8& aOutput)
    91 	{
    92 	TRAP_IGNORE(iSymmetricCipherImpl->ProcessL(aInput, aOutput);)
    93 	}
    94 
    95 void CArc4Shim::ProcessFinalL(const TDesC8& aInput, TDes8& aOutput)
    96 	{
    97 	iSymmetricCipherImpl->ProcessFinalL(aInput, aOutput);
    98 	}
    99 
   100 TInt CArc4Shim::MaxOutputLength(TInt aInputLength) const
   101 	{
   102 	return iSymmetricCipherImpl->MaxOutputLength(aInputLength);
   103 	}
   104 
   105 TInt CArc4Shim::MaxFinalOutputLength(TInt aInputLength) const
   106 	{
   107 	return iSymmetricCipherImpl->MaxFinalOutputLength(aInputLength);
   108 	}
   109 
   110 CArc4Shim::CArc4Shim()
   111 	{		
   112 	}
   113