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