First public contribution.
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.
25 #ifndef __RSAFUNCTION_H__
26 #define __RSAFUNCTION_H__
31 using namespace CryptoSpi;
38 static inline TBool IsInputValid(const TInteger& aInput,
39 const TInteger& aModulus);
40 static inline void IsInputValidL(const TInteger& aInput,
41 const TInteger& aModulus);
42 static void EncryptL(const CKey& aPublicKey,
43 const TInteger& aInput, RInteger& aOutput);
44 static void DecryptL(const CKey& aPrivateKey,
45 const TInteger& aInput, RInteger& aOutput);
46 static void SignL(const CKey& aPrivateKey,
47 const TInteger& aInput, RInteger& aOutput);
48 static void VerifyL(const CKey& aPublicKey,
49 const TInteger& aInput, RInteger& aOutput);
51 static void FunctionL(const TInteger& aModulus, const TInteger& aExponent,
52 const TInteger& aBase, RInteger& aOutput);
53 static void FunctionCRTL(const CKey& aPrivateKey,
54 const TInteger& aInput, RInteger& aOutput);
59 /** Computes whether a given message representative is within the valid bounds
60 * for a given modulus, i.e. whether the message is representative within [0,n-1].
61 * @param aInput The message representative.
62 * @param aModulus The modulus.
63 * @return TBool representing whether or not the message representative is
66 TBool RSAFunction::IsInputValid(const TInteger& aInput,
67 const TInteger& aModulus)
70 //Message (input) must be in the interval [0,n-1] (inclusive)
71 if( aInput.IsNegative() || aInput >= aModulus )
77 void RSAFunction::IsInputValidL(const TInteger& aInput,
78 const TInteger& aModulus)
80 if(!IsInputValid(aInput, aModulus))
81 User::Leave(KErrArgument);