1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
1.2 +++ b/os/security/crypto/weakcryptospi/source/hash/hash.cpp Fri Jun 15 03:10:57 2012 +0200
1.3 @@ -0,0 +1,138 @@
1.4 +/*
1.5 +* Copyright (c) 2005-2009 Nokia Corporation and/or its subsidiary(-ies).
1.6 +* All rights reserved.
1.7 +* This component and the accompanying materials are made available
1.8 +* under the terms of the License "Eclipse Public License v1.0"
1.9 +* which accompanies this distribution, and is available
1.10 +* at the URL "http://www.eclipse.org/legal/epl-v10.html".
1.11 +*
1.12 +* Initial Contributors:
1.13 +* Nokia Corporation - initial contribution.
1.14 +*
1.15 +* Contributors:
1.16 +*
1.17 +* Description:
1.18 +* (c) 1999-2003 Symbian Ltd. All rights reserved
1.19 +*
1.20 +*/
1.21 +
1.22 +
1.23 +/**
1.24 + @file
1.25 +*/
1.26 +
1.27 +#include <e32std.h>
1.28 +#include <hash.h>
1.29 +#define EXPANDLOOP
1.30 +
1.31 +EXPORT_C CMessageDigest::CMessageDigest(void):CBase()
1.32 +{}
1.33 +
1.34 +EXPORT_C CMessageDigest::CMessageDigest(const CMessageDigest& /*aMD*/):CBase()
1.35 +{}
1.36 +
1.37 +EXPORT_C CMessageDigest::~CMessageDigest(void)
1.38 +{}
1.39 +
1.40 +/* Note that the shifts here are NOT guaranteed to work if s == 0, and it is
1.41 + * assumed in R() (and hence in all inline) that a is unsigned. */
1.42 +// CMD_R - rotate a left by n bits; the main bottleneck of the algorithm
1.43 +// implementation
1.44 +/*
1.45 +C++ version compiles to:
1.46 +
1.47 +CMD_R__FUiUi:
1.48 + add r3, r0, #0
1.49 + lsl r3, r3, r1
1.50 + mov r2, #32
1.51 + sub r2, r2, r1
1.52 + lsr r0, r0, r2
1.53 + add r3, r3, r0
1.54 + add r0, r3, #0
1.55 + bx lr
1.56 +
1.57 +*/
1.58 +
1.59 +TInt CMessageDigest::GetExtension(TUint aExtensionId, TAny*& a0, TAny* a1)
1.60 + {
1.61 + return Extension_(aExtensionId, a0, a1);
1.62 + }
1.63 +
1.64 +
1.65 +//////////////////////////////////////////////////////////////////
1.66 +// Factory class to create CMessageDigest derived objects
1.67 +//////////////////////////////////////////////////////////////////
1.68 +EXPORT_C CMessageDigest* CMessageDigestFactory::NewDigestL(CMessageDigest::THashId aHashId)
1.69 +{
1.70 + CMessageDigest* hash = NULL;
1.71 + switch (aHashId)
1.72 + {
1.73 + case (CMessageDigest::EMD2):
1.74 + {
1.75 + hash = CMD2::NewL();
1.76 + break;
1.77 + }
1.78 + case (CMessageDigest::EMD5):
1.79 + {
1.80 + hash = CMD5::NewL();
1.81 + break;
1.82 + }
1.83 + case (CMessageDigest::ESHA1):
1.84 + {
1.85 + hash = CSHA1::NewL();
1.86 + break;
1.87 + }
1.88 + case (CMessageDigest::EMD4):
1.89 + {
1.90 + hash = CMD4::NewL();
1.91 + break;
1.92 + }
1.93 + case (CMessageDigest::ESHA224):
1.94 + {
1.95 + hash = CSHA2::NewL(E224Bit);
1.96 + break;
1.97 + }
1.98 + case (CMessageDigest::ESHA256):
1.99 + {
1.100 + hash = CSHA2::NewL(E256Bit);
1.101 + break;
1.102 + }
1.103 + case (CMessageDigest::ESHA384):
1.104 + {
1.105 + hash = CSHA2::NewL(E384Bit);
1.106 + break;
1.107 + }
1.108 + case (CMessageDigest::ESHA512):
1.109 + {
1.110 + hash = CSHA2::NewL(E512Bit);
1.111 + break;
1.112 + }
1.113 + case (CMessageDigest::HMAC):
1.114 + default:
1.115 + User::Leave(KErrNotSupported);
1.116 + }
1.117 +
1.118 + return (hash);
1.119 +}
1.120 +
1.121 +EXPORT_C CMessageDigest* CMessageDigestFactory::NewDigestLC(CMessageDigest::THashId aHashId)
1.122 +{
1.123 + CMessageDigest* hash = CMessageDigestFactory::NewDigestL(aHashId);
1.124 + CleanupStack::PushL(hash);
1.125 + return (hash);
1.126 +}
1.127 +
1.128 +EXPORT_C CMessageDigest* CMessageDigestFactory::NewHMACL(CMessageDigest::THashId aHashId, const TDesC8& aKey)
1.129 +{
1.130 + CMessageDigest* hash = CMessageDigestFactory::NewDigestLC(aHashId);
1.131 + CMessageDigest* hmac = CHMAC::NewL(aKey, hash);
1.132 + CleanupStack::Pop(hash); // Now owned by hmac
1.133 + return (hmac);
1.134 +}
1.135 +
1.136 +EXPORT_C CMessageDigest* CMessageDigestFactory::NewHMACLC(CMessageDigest::THashId aHashId, const TDesC8& aKey)
1.137 +{
1.138 + CMessageDigest* hmac = CMessageDigestFactory::NewHMACL(aHashId, aKey);
1.139 + CleanupStack::PushL(hmac);
1.140 + return (hmac);
1.141 +}