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.
20 #include "../common/inlines.h"
22 void CBlockChainingMode::Reset()
28 TInt CBlockChainingMode::BlockSize() const
30 return (iBT->BlockSize());
33 TInt CBlockChainingMode::KeySize() const
35 return (iBT->KeySize());
38 void CBlockChainingMode::SetIV(const TDesC8& aIV)
40 //We are making the stipulation that anybody calling SetIV is not setting it
41 //to a longer IV than they originally did. Otherwise SetIV needs to leave.
42 assert(aIV.Size() <= iIV.Size());
47 EXPORT_C CBlockChainingMode::CBlockChainingMode()
48 : iBT(NULL), iRegister(0,0,0), iIV(0,0,0)
52 EXPORT_C CBlockChainingMode::~CBlockChainingMode()
59 EXPORT_C void CBlockChainingMode::ConstructL(CBlockTransformation* aBT, const TDesC8& aIV)
61 iRegisterBuf = aIV.AllocL();
62 iRegister.Set(iRegisterBuf->Des());
63 iIVBuf = aIV.AllocL();
64 iIV.Set(iIVBuf->Des());
66 // Take ownership last - doesn't take ownership if we leave
70 /* CModeCBCEncryptor */
71 EXPORT_C CModeCBCEncryptor* CModeCBCEncryptor::NewL(CBlockTransformation* aBT,
74 CModeCBCEncryptor* self = NewLC(aBT, aIV);
75 CleanupStack::Pop(self);
79 EXPORT_C CModeCBCEncryptor* CModeCBCEncryptor::NewLC(CBlockTransformation* aBT,
82 CModeCBCEncryptor* self = new (ELeave)CModeCBCEncryptor();
83 CleanupStack::PushL(self);
84 self->ConstructL(aBT, aIV);
88 CModeCBCEncryptor::CModeCBCEncryptor()
92 void CModeCBCEncryptor::Transform(TDes8& aBlock)
94 assert(aBlock.Size() == iBT->BlockSize());
95 assert(iRegister.Size() == aBlock.Size());
97 XorBuf(const_cast<TUint8*>(iRegister.Ptr()), aBlock.Ptr(), aBlock.Size());
98 iBT->Transform(iRegister);
99 aBlock.Copy(iRegister);
102 /* CModeCBCDecryptor */
103 EXPORT_C CModeCBCDecryptor* CModeCBCDecryptor::NewL(CBlockTransformation* aBT,
106 CModeCBCDecryptor* self = NewLC(aBT, aIV);
107 CleanupStack::Pop(self);
111 EXPORT_C CModeCBCDecryptor* CModeCBCDecryptor::NewLC(CBlockTransformation* aBT,
114 CModeCBCDecryptor* self = new (ELeave)CModeCBCDecryptor();
115 CleanupStack::PushL(self);
116 self->ConstructL(aBT, aIV);
120 void CModeCBCDecryptor::ConstructL(CBlockTransformation* aBT, const TDesC8& aIV)
122 iIVBakBuf = aIV.AllocL();
123 iIVBak.Set(iIVBakBuf->Des());
124 CBlockChainingMode::ConstructL(aBT, aIV);
127 CModeCBCDecryptor::~CModeCBCDecryptor(void)
132 CModeCBCDecryptor::CModeCBCDecryptor()
137 void CModeCBCDecryptor::Transform(TDes8& aBlock)
139 assert(aBlock.Size() == iBT->BlockSize());
140 assert(iRegister.Size() == aBlock.Size());
141 assert(iIVBak.Size() == aBlock.Size());
143 // Take a copy of incoming block
146 // transform the block
147 iBT->Transform(aBlock);
149 // xor the output with the register
150 XorBuf(const_cast<TUint8*>(aBlock.Ptr()), iRegister.Ptr(),
153 // Update the register to be the original block
154 iRegister.Copy(iIVBak);