First public contribution.
1 #ifndef __CRYPTOAPI_SOFTWARESHACOMMON_H_
2 #define __CRYPTOAPI_SOFTWARESHACOMMON_H_/*
3 * Copyright (c) 2007-2009 Nokia Corporation and/or its subsidiary(-ies).
5 * This component and the accompanying materials are made available
6 * under the terms of the License "Eclipse Public License v1.0"
7 * which accompanies this distribution, and is available
8 * at the URL "http://www.eclipse.org/legal/epl-v10.html".
10 * Initial Contributors:
11 * Nokia Corporation - initial contribution.
17 * Same as used in SHA1
20 * SHA_Parity > CSHA1_G
21 * The following definitions are equivalent and potentially faster.
22 * #define SHA_Ch(x, y, z) (((x) & ((y) ^ (z))) ^ (z))
23 * #define SHA_Maj(x, y, z) (((x) & ((y) | (z))) | ((y) & (z)))
24 * These functions are defined in FIPS 180-2 Section 4.1
25 * Equation 4.1, 4.2, 4.3, 4.8, 4.9
38 inline T SHA_Ch(T aX, T aY, T aZ)
40 return ((aX & aY) ^ ((~aX) & aZ));
44 inline T SHA_Maj(T aX, T aY, T aZ)
46 return ((aX & aY) ^ (aX & aZ) ^ (aY & aZ));
50 inline T SHA_Parity(T aX, T aY, T aZ)
52 return (aX ^ aY ^ aZ);
56 * Define the SHA shift, and rotate right macro
57 * Defined in FIPS 180-2 Section 3.2
60 * SHA Right Shift operation: The right shift operation SHR^n(x),
61 * where x is a w-bit word and n is an integer with 0 <= n < w,
62 * is defined by SHR^n(x) = x >> n.
65 inline T SHA_SHR(T aBits, T aWord)
67 return (aWord >> aBits);
71 * SHA Rotate Right Operation: The rotate right (circular right shift) operation
72 * ROTR^n(x), where x is a w-bit word and n is an integer with 0 <= n < w,
73 * is defined by ROTR n(x)=(x >> n) || (x << w - n).
76 inline T SHA_ROTR(T aBits, T aWord)
78 TInt totalBits = sizeof(T) << 3;
79 return ((aWord >> aBits) | (aWord << (totalBits-aBits)));
82 namespace SoftwareCrypto
85 NONSHARABLE_CLASS(MSHA2Impl)
89 * This function will reset the state of hash.
91 virtual void Reset(const TAny*) = 0;
93 * This function will finalize the hash and return
94 * the calculated hash.
97 virtual const TDesC8& Final() = 0;
99 * This function will add the message to the internal
100 * buffer and if the block size is reached then calcualte
101 * the hash till that point.
102 * @param aMessage Message to be updated.
103 * @param aLength Length of the message to be updated.
105 virtual void Update(const TUint8* aMessage, TUint aLength) = 0;
107 * This function will save the internal state of the hash.
109 virtual void StoreState() = 0;
111 * This function will retrieve the saved the internal state
114 virtual void RestoreState() = 0;
116 * virtual distructor.
118 virtual ~MSHA2Impl(){}
121 }//namespace SoftwareCrypto
123 #endif //__CRYPTOAPI_SOFTWARESHACOMMON_H_