17
|
1 |
/*
|
|
2 |
* Copyright (c) 2005-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 |
* (c) 1999-2003 Symbian Ltd. All rights reserved
|
|
16 |
*
|
|
17 |
*/
|
|
18 |
|
|
19 |
|
|
20 |
/**
|
|
21 |
@file
|
|
22 |
*/
|
|
23 |
|
|
24 |
#include <e32std.h>
|
|
25 |
#include <hash.h>
|
|
26 |
#define EXPANDLOOP
|
|
27 |
|
|
28 |
EXPORT_C CMessageDigest::CMessageDigest(void):CBase()
|
|
29 |
{}
|
|
30 |
|
|
31 |
EXPORT_C CMessageDigest::CMessageDigest(const CMessageDigest& /*aMD*/):CBase()
|
|
32 |
{}
|
|
33 |
|
|
34 |
EXPORT_C CMessageDigest::~CMessageDigest(void)
|
|
35 |
{}
|
|
36 |
|
|
37 |
/* Note that the shifts here are NOT guaranteed to work if s == 0, and it is
|
|
38 |
* assumed in R() (and hence in all inline) that a is unsigned. */
|
|
39 |
// CMD_R - rotate a left by n bits; the main bottleneck of the algorithm
|
|
40 |
// implementation
|
|
41 |
/*
|
|
42 |
C++ version compiles to:
|
|
43 |
|
|
44 |
CMD_R__FUiUi:
|
|
45 |
add r3, r0, #0
|
|
46 |
lsl r3, r3, r1
|
|
47 |
mov r2, #32
|
|
48 |
sub r2, r2, r1
|
|
49 |
lsr r0, r0, r2
|
|
50 |
add r3, r3, r0
|
|
51 |
add r0, r3, #0
|
|
52 |
bx lr
|
|
53 |
|
|
54 |
*/
|
|
55 |
|
|
56 |
TInt CMessageDigest::GetExtension(TUint aExtensionId, TAny*& a0, TAny* a1)
|
|
57 |
{
|
|
58 |
return Extension_(aExtensionId, a0, a1);
|
|
59 |
}
|
|
60 |
|
|
61 |
|
|
62 |
//////////////////////////////////////////////////////////////////
|
|
63 |
// Factory class to create CMessageDigest derived objects
|
|
64 |
//////////////////////////////////////////////////////////////////
|
|
65 |
EXPORT_C CMessageDigest* CMessageDigestFactory::NewDigestL(CMessageDigest::THashId aHashId)
|
|
66 |
{
|
|
67 |
CMessageDigest* hash = NULL;
|
|
68 |
switch (aHashId)
|
|
69 |
{
|
|
70 |
case (CMessageDigest::EMD2):
|
|
71 |
{
|
|
72 |
hash = CMD2::NewL();
|
|
73 |
break;
|
|
74 |
}
|
|
75 |
case (CMessageDigest::EMD5):
|
|
76 |
{
|
|
77 |
hash = CMD5::NewL();
|
|
78 |
break;
|
|
79 |
}
|
|
80 |
case (CMessageDigest::ESHA1):
|
|
81 |
{
|
|
82 |
hash = CSHA1::NewL();
|
|
83 |
break;
|
|
84 |
}
|
|
85 |
case (CMessageDigest::EMD4):
|
|
86 |
{
|
|
87 |
hash = CMD4::NewL();
|
|
88 |
break;
|
|
89 |
}
|
|
90 |
case (CMessageDigest::ESHA224):
|
|
91 |
{
|
|
92 |
hash = CSHA2::NewL(E224Bit);
|
|
93 |
break;
|
|
94 |
}
|
|
95 |
case (CMessageDigest::ESHA256):
|
|
96 |
{
|
|
97 |
hash = CSHA2::NewL(E256Bit);
|
|
98 |
break;
|
|
99 |
}
|
|
100 |
case (CMessageDigest::ESHA384):
|
|
101 |
{
|
|
102 |
hash = CSHA2::NewL(E384Bit);
|
|
103 |
break;
|
|
104 |
}
|
|
105 |
case (CMessageDigest::ESHA512):
|
|
106 |
{
|
|
107 |
hash = CSHA2::NewL(E512Bit);
|
|
108 |
break;
|
|
109 |
}
|
|
110 |
case (CMessageDigest::HMAC):
|
|
111 |
default:
|
|
112 |
User::Leave(KErrNotSupported);
|
|
113 |
}
|
|
114 |
|
|
115 |
return (hash);
|
|
116 |
}
|
|
117 |
|
|
118 |
EXPORT_C CMessageDigest* CMessageDigestFactory::NewDigestLC(CMessageDigest::THashId aHashId)
|
|
119 |
{
|
|
120 |
CMessageDigest* hash = CMessageDigestFactory::NewDigestL(aHashId);
|
|
121 |
CleanupStack::PushL(hash);
|
|
122 |
return (hash);
|
|
123 |
}
|
|
124 |
|
|
125 |
EXPORT_C CMessageDigest* CMessageDigestFactory::NewHMACL(CMessageDigest::THashId aHashId, const TDesC8& aKey)
|
|
126 |
{
|
|
127 |
CMessageDigest* hash = CMessageDigestFactory::NewDigestLC(aHashId);
|
|
128 |
CMessageDigest* hmac = CHMAC::NewL(aKey, hash);
|
|
129 |
CleanupStack::Pop(hash); // Now owned by hmac
|
|
130 |
return (hmac);
|
|
131 |
}
|
|
132 |
|
|
133 |
EXPORT_C CMessageDigest* CMessageDigestFactory::NewHMACLC(CMessageDigest::THashId aHashId, const TDesC8& aKey)
|
|
134 |
{
|
|
135 |
CMessageDigest* hmac = CMessageDigestFactory::NewHMACL(aHashId, aKey);
|
|
136 |
CleanupStack::PushL(hmac);
|
|
137 |
return (hmac);
|
|
138 |
}
|