19
|
1 |
/*
|
|
2 |
* Copyright (c) 2008-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 |
* Cipher MAC plugin implementation
|
|
16 |
*
|
|
17 |
*/
|
|
18 |
|
|
19 |
|
|
20 |
/**
|
|
21 |
@file
|
|
22 |
@internalComponent
|
|
23 |
@released
|
|
24 |
*/
|
|
25 |
|
|
26 |
#ifndef __CRYPTOAPI_SOFTWARECIPHERMACIMPL_H__
|
|
27 |
#define __CRYPTOAPI_SOFTWARECIPHERMACIMPL_H__
|
|
28 |
|
|
29 |
#include "cryptosymmetriccipherapi.h"
|
|
30 |
#include "keys.h"
|
|
31 |
|
|
32 |
|
|
33 |
namespace SoftwareCrypto
|
|
34 |
{
|
|
35 |
using namespace CryptoSpi;
|
|
36 |
|
|
37 |
/**
|
|
38 |
* This is the maximum block size in bytes currently supported by CMAC implementation.
|
|
39 |
*
|
|
40 |
* The cipher based algorithms currently supported are
|
|
41 |
* AES-XCBC-MAC-96 and AES-XCBC-PRF-128.
|
|
42 |
*/
|
|
43 |
const TInt KMacBlockSize = 16;
|
|
44 |
|
|
45 |
/**
|
|
46 |
* The class is created from following substance classes
|
|
47 |
* 1. MMac
|
|
48 |
* 2. CSymmetricCipher
|
|
49 |
* Using the methods of the above classes we will transform/mould the Cipher methods in
|
|
50 |
* a way as to be inline with the MMac interface methods. The MMac methods will
|
|
51 |
* serve as the wrapper internal to which Cipher methods will work to provide the MAC value.
|
|
52 |
*
|
|
53 |
* The class was created to provide consistency/similarity HMAC and CMAC works.
|
|
54 |
* Also for future extensibility of other Cipher algorithms.
|
|
55 |
*/
|
|
56 |
NONSHARABLE_CLASS(CCMacImpl) : public CBase
|
|
57 |
{
|
|
58 |
public:
|
|
59 |
/**
|
|
60 |
* Cipher MAC implementation instance creation methods
|
|
61 |
*
|
|
62 |
*The owneship of 'aSymmetricCipher' is imparted to instance of this class.
|
|
63 |
*/
|
|
64 |
static CCMacImpl* NewL(const CKey& aKey,
|
|
65 |
CSymmetricCipher* aSymmetricCipher,
|
|
66 |
TInt32 aAlgorithmUid);
|
|
67 |
|
|
68 |
static CCMacImpl* NewLC(const CKey& aKey,
|
|
69 |
CSymmetricCipher* aSymmetricCipher,
|
|
70 |
TInt32 aAlgorithmUid);
|
|
71 |
/**
|
|
72 |
* Simulating Methods from MPlugin
|
|
73 |
*/
|
|
74 |
const CExtendedCharacteristics* GetExtendedCharacteristicsL();
|
|
75 |
|
|
76 |
// We will call CSymmetricBlockCipherImpl::Reset();
|
|
77 |
void Reset();
|
|
78 |
|
|
79 |
/**
|
|
80 |
* Simulating MAC interfaces (Software based)
|
|
81 |
*/
|
|
82 |
TPtrC8 MacL(const TDesC8& aMessage);
|
|
83 |
void UpdateL(const TDesC8& aMessage);
|
|
84 |
TPtrC8 FinalL(const TDesC8& aMessage);
|
|
85 |
void ReInitialiseAndSetKeyL(const CKey& aKey);
|
|
86 |
void SetKeyL(const CKey& aKey);
|
|
87 |
~CCMacImpl();
|
|
88 |
CCMacImpl* CopyL();
|
|
89 |
CCMacImpl* ReplicateL();
|
|
90 |
|
|
91 |
private:
|
|
92 |
/**
|
|
93 |
* Constructors
|
|
94 |
*/
|
|
95 |
CCMacImpl(CryptoSpi::CSymmetricCipher* aSymmetricCipher);
|
|
96 |
CCMacImpl(const CCMacImpl&);
|
|
97 |
|
|
98 |
/**
|
|
99 |
* Initialize the 'iCipherImpl' instances.
|
|
100 |
*/
|
|
101 |
void ConstructL(const CKey& aKey, TInt32 aAlgorithmUid);
|
|
102 |
void DoUpdateL(const TDesC8& aMessage);
|
|
103 |
TPtrC8 DoFinalL();
|
|
104 |
void PadMessage();
|
|
105 |
void ProcessBlockL();
|
|
106 |
void XORKeyWithData(const TDesC8& aKey, TDes8& aOutput);
|
|
107 |
CKey* Create128bitKeyL(const CKey& aKey);
|
|
108 |
|
|
109 |
private:
|
|
110 |
TInt32 iImplementationUid;
|
|
111 |
CKey* iKey;
|
|
112 |
CryptoSpi::CSymmetricCipher* iCipherImpl;
|
|
113 |
|
|
114 |
TBuf8<KMacBlockSize> iKey1;
|
|
115 |
TBuf8<KMacBlockSize> iKey2;
|
|
116 |
TBuf8<KMacBlockSize> iKey3;
|
|
117 |
TBuf8<KMacBlockSize> iMacValue;
|
|
118 |
|
|
119 |
TUint8 iE[KMacBlockSize];
|
|
120 |
TUint8 iData[KMacBlockSize];
|
|
121 |
TInt iCurrentTotalLength;
|
|
122 |
// Resets the cipher with iE(128 zero bits) the next time MacL,
|
|
123 |
// UpdateL or FinalL are called. This was introduced as we cannot leave from the
|
|
124 |
// non-leaving CCMacImpl::Reset() implementation of the MPlugin::Reset() pure
|
|
125 |
// virtual. To prevent behavioral break.
|
|
126 |
TInt iDelayedReset;
|
|
127 |
};
|
|
128 |
}
|
|
129 |
|
|
130 |
#endif // __CRYPTOAPI_SOFTWARECIPHERMACIMPL_H__
|
|
131 |
|
|
132 |
|