First public contribution.
1 #ifndef __CRYPTO_SHACOMMON_H_
2 #define __CRYPTO_SHACOMMON_H_
5 * Copyright (c) 2007-2009 Nokia Corporation and/or its subsidiary(-ies).
7 * This component and the accompanying materials are made available
8 * under the terms of the License "Eclipse Public License v1.0"
9 * which accompanies this distribution, and is available
10 * at the URL "http://www.eclipse.org/legal/epl-v10.html".
12 * Initial Contributors:
13 * Nokia Corporation - initial contribution.
18 * Same as used in SHA1
21 * SHA_Parity > CSHA1_G
22 * The following definitions are equivalent and potentially faster.
23 * #define SHA_Ch(x, y, z) (((x) & ((y) ^ (z))) ^ (z))
24 * #define SHA_Maj(x, y, z) (((x) & ((y) | (z))) | ((y) & (z)))
25 * These functions are defined in FIPS 180-2 Section 4.1
26 * Equation 4.1, 4.2, 4.3, 4.8, 4.9
39 inline T SHA_Ch(T aX, T aY, T aZ)
41 return ((aX & aY) ^ ((~aX) & aZ));
45 inline T SHA_Maj(T aX, T aY, T aZ)
47 return ((aX & aY) ^ (aX & aZ) ^ (aY & aZ));
51 inline T SHA_Parity(T aX, T aY, T aZ)
53 return (aX ^ aY ^ aZ);
57 * Define the SHA shift, and rotate right macro
58 * Defined in FIPS 180-2 Section 3.2
61 * SHA Right Shift operation: The right shift operation SHR^n(x),
62 * where x is a w-bit word and n is an integer with 0 <= n < w,
63 * is defined by SHR^n(x) = x >> n.
66 inline T SHA_SHR(T aBits, T aWord)
68 return (aWord >> aBits);
72 * SHA Rotate Right Operation: The rotate right (circular right shift) operation
73 * ROTR^n(x), where x is a w-bit word and n is an integer with 0 <= n < w,
74 * is defined by ROTR n(x)=(x >> n) || (x << w - n).
77 inline T SHA_ROTR(T aBits, T aWord)
79 TInt totalBits = sizeof(T) << 3;
80 return ((aWord >> aBits) | (aWord << (totalBits-aBits)));
83 NONSHARABLE_CLASS(MSHA2Impl)
87 * This function will reset the state of hash.
89 virtual void Reset(const TAny*) = 0;
91 * This function will finalize the hash and return
92 * the calculated hash.
95 virtual const TDesC8& Final() = 0;
97 * This function will add the message to the internal
98 * buffer and if the block size is reached then calcualte
99 * the hash till that point.
100 * @param aMessage Message to be updated.
101 * @param aLength Length of the message to be updated.
103 virtual void Update(const TUint8* aMessage, TUint aLength) = 0;
105 * This function will save the internal state of the hash.
107 virtual void StoreState() = 0;
109 * This function will retrieve the saved the internal state
112 virtual void RestoreState() = 0;
114 * virtual distructor.
116 virtual ~MSHA2Impl(){}
119 #endif //__CRYPTO_SHACOMMON_H_