Update contrib.
2 * Copyright (c) 2002-2009 Nokia Corporation and/or its subsidiary(-ies).
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".
9 * Initial Contributors:
10 * Nokia Corporation - initial contribution.
21 #include "cbcmodeshim.h"
22 #include "../common/inlines.h"
24 void CBlockChainingMode::Reset()
30 TInt CBlockChainingMode::BlockSize() const
32 return (iBT->BlockSize());
35 TInt CBlockChainingMode::KeySize() const
37 return (iBT->KeySize());
40 void CBlockChainingMode::SetIV(const TDesC8& aIV)
42 //We are making the stipulation that anybody calling SetIV is not setting it
43 //to a longer IV than they originally did. Otherwise SetIV needs to leave.
44 assert(aIV.Size() <= iIV.Size());
49 EXPORT_C CBlockChainingMode::CBlockChainingMode()
50 : iBT(NULL), iRegister(0,0,0), iIV(0,0,0)
54 EXPORT_C CBlockChainingMode::~CBlockChainingMode()
61 EXPORT_C void CBlockChainingMode::ConstructL(CBlockTransformation* aBT, const TDesC8& aIV)
63 iRegisterBuf = aIV.AllocL();
64 iRegister.Set(iRegisterBuf->Des());
65 iIVBuf = aIV.AllocL();
66 iIV.Set(iIVBuf->Des());
68 // Take ownership last - doesn't take ownership if we leave
72 /* CModeCBCEncryptor */
73 EXPORT_C CModeCBCEncryptor* CModeCBCEncryptor::NewL(CBlockTransformation* aBT,
76 CModeCBCEncryptor* self = CModeCBCEncryptorShim::NewL(aBT, aIV);
79 // not able to use CryptoSpi, possibly due to an exterally
80 // derived legacy class so fallback to old implementation.
81 self = NewLC(aBT,aIV);
82 CleanupStack::Pop(self);
87 EXPORT_C CModeCBCEncryptor* CModeCBCEncryptor::NewLC(CBlockTransformation* aBT,
90 CModeCBCEncryptor* self = new (ELeave)CModeCBCEncryptor();
91 CleanupStack::PushL(self);
92 self->ConstructL(aBT, aIV);
96 CModeCBCEncryptor::CModeCBCEncryptor()
100 void CModeCBCEncryptor::Transform(TDes8& aBlock)
102 assert(aBlock.Size() == iBT->BlockSize());
103 assert(iRegister.Size() == aBlock.Size());
105 XorBuf(const_cast<TUint8*>(iRegister.Ptr()), aBlock.Ptr(), aBlock.Size());
106 iBT->Transform(iRegister);
107 aBlock.Copy(iRegister);
110 /* CModeCBCDecryptor */
111 EXPORT_C CModeCBCDecryptor* CModeCBCDecryptor::NewL(CBlockTransformation* aBT,
114 CModeCBCDecryptor* self = CModeCBCDecryptorShim::NewL(aBT, aIV);
117 // not able to use CryptoSpi, possibly due to an exterally
118 // derived legacy class so fallback to old implementation.
119 self = NewLC(aBT,aIV);
120 CleanupStack::Pop(self);
125 EXPORT_C CModeCBCDecryptor* CModeCBCDecryptor::NewLC(CBlockTransformation* aBT,
128 CModeCBCDecryptor* self = new (ELeave)CModeCBCDecryptor();
129 CleanupStack::PushL(self);
130 self->ConstructL(aBT, aIV);
134 void CModeCBCDecryptor::ConstructL(CBlockTransformation* aBT, const TDesC8& aIV)
136 iIVBakBuf = aIV.AllocL();
137 iIVBak.Set(iIVBakBuf->Des());
138 CBlockChainingMode::ConstructL(aBT, aIV);
141 CModeCBCDecryptor::~CModeCBCDecryptor(void)
146 CModeCBCDecryptor::CModeCBCDecryptor()
151 void CModeCBCDecryptor::Transform(TDes8& aBlock)
153 assert(aBlock.Size() == iBT->BlockSize());
154 assert(iRegister.Size() == aBlock.Size());
155 assert(iIVBak.Size() == aBlock.Size());
157 // Take a copy of incoming block
160 // transform the block
161 iBT->Transform(aBlock);
163 // xor the output with the register
164 XorBuf(const_cast<TUint8*>(aBlock.Ptr()), iRegister.Ptr(),
167 // Update the register to be the original block
168 iRegister.Copy(iIVBak);