Update contrib.
2 * Copyright (c) 2003-2009 Nokia Corporation and/or its subsidiary(-ies).
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".
9 * Initial Contributors:
10 * Nokia Corporation - initial contribution.
19 #include <asymmetric.h>
20 #include <asymmetrickeys.h>
23 EXPORT_C CDSAVerifier* CDSAVerifier::NewL(const CDSAPublicKey& aKey)
25 CDSAVerifier* self = new(ELeave)CDSAVerifier(aKey);
29 EXPORT_C CDSAVerifier* CDSAVerifier::NewLC(const CDSAPublicKey& aKey)
31 CDSAVerifier* self = NewL(aKey);
32 CleanupStack::PushL(self);
36 TInt CDSAVerifier::MaxInputLength(void) const
38 // return CSHA1::DIGESTBYTES
42 TBool CDSAVerifier::VerifyL(const TDesC8& aInput,
43 const CDSASignature& aSignature) const
45 //see HAC 11.56 or DSS section 6
46 //I'll follow HAC as I like the description better
48 // a) Obtain A's authenticate public key
50 // b) Verify that 0 < r < q and 0 < s < q; if not reject signature
51 if (aSignature.R() <= 0 || aSignature.R() >= iPublicKey.Q())
55 if (aSignature.S() <= 0 || aSignature.S() >= iPublicKey.Q())
60 TBool result = EFalse;
62 // c) Compute w = s^(-1) mod q and h(m)
63 RInteger w = aSignature.S().InverseModL(iPublicKey.Q());
64 CleanupStack::PushL(w);
65 // Note that in order to be interoperable, compliant with the DSS, and
66 // secure, aInput must be the result of a SHA-1 hash
67 RInteger hm = RInteger::NewL(aInput);
68 CleanupStack::PushL(hm);
70 // d) Compute u1 = w * hm mod q and u2 = r * w mod q
71 RInteger u1 = TInteger::ModularMultiplyL(w, hm, iPublicKey.Q());
72 CleanupStack::PushL(u1);
74 RInteger u2 = TInteger::ModularMultiplyL(aSignature.R(), w, iPublicKey.Q());
75 CleanupStack::PushL(u2);
77 // e) Compute v = ((g^u1 * y^u2) mod p) mod q
78 RInteger temp = TInteger::ModularExponentiateL(iPublicKey.G(), u1,
80 CleanupStack::PushL(temp);
81 RInteger temp1 = TInteger::ModularExponentiateL(iPublicKey.Y(), u2,
83 CleanupStack::PushL(temp1);
84 RInteger v = TInteger::ModularMultiplyL(temp, temp1, iPublicKey.P());
85 CleanupStack::PushL(v);
88 // f) Accept the signature iff v == r
89 if(v == aSignature.R())
94 CleanupStack::PopAndDestroy(&v);
95 CleanupStack::PopAndDestroy(&temp1);
96 CleanupStack::PopAndDestroy(&temp);
97 CleanupStack::PopAndDestroy(&u2);
98 CleanupStack::PopAndDestroy(&u1);
99 CleanupStack::PopAndDestroy(&hm);
100 CleanupStack::PopAndDestroy(&w);
105 CDSAVerifier::CDSAVerifier(const CDSAPublicKey& aKey)