1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
1.2 +++ b/os/security/cryptoplugins/cryptospiplugins/source/softwarecrypto/rsafunction.h Fri Jun 15 03:10:57 2012 +0200
1.3 @@ -0,0 +1,85 @@
1.4 +/*
1.5 +* Copyright (c) 2003-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 +*
1.19 +*/
1.20 +
1.21 +
1.22 +/**
1.23 + @file
1.24 + @internalComponent
1.25 + @released
1.26 +*/
1.27 +
1.28 +#ifndef __RSAFUNCTION_H__
1.29 +#define __RSAFUNCTION_H__
1.30 +
1.31 +#include <e32base.h>
1.32 +#include "keys.h"
1.33 +
1.34 +using namespace CryptoSpi;
1.35 +
1.36 +class TInteger;
1.37 +
1.38 +class RSAFunction
1.39 + {
1.40 +public:
1.41 + static inline TBool IsInputValid(const TInteger& aInput,
1.42 + const TInteger& aModulus);
1.43 + static inline void IsInputValidL(const TInteger& aInput,
1.44 + const TInteger& aModulus);
1.45 + static void EncryptL(const CKey& aPublicKey,
1.46 + const TInteger& aInput, RInteger& aOutput);
1.47 + static void DecryptL(const CKey& aPrivateKey,
1.48 + const TInteger& aInput, RInteger& aOutput);
1.49 + static void SignL(const CKey& aPrivateKey,
1.50 + const TInteger& aInput, RInteger& aOutput);
1.51 + static void VerifyL(const CKey& aPublicKey,
1.52 + const TInteger& aInput, RInteger& aOutput);
1.53 +private:
1.54 + static void FunctionL(const TInteger& aModulus, const TInteger& aExponent,
1.55 + const TInteger& aBase, RInteger& aOutput);
1.56 + static void FunctionCRTL(const CKey& aPrivateKey,
1.57 + const TInteger& aInput, RInteger& aOutput);
1.58 +private:
1.59 + RSAFunction(void);
1.60 + };
1.61 +
1.62 +/** Computes whether a given message representative is within the valid bounds
1.63 + * for a given modulus, i.e. whether the message is representative within [0,n-1].
1.64 + * @param aInput The message representative.
1.65 + * @param aModulus The modulus.
1.66 + * @return TBool representing whether or not the message representative is
1.67 + * valid.
1.68 + */
1.69 +TBool RSAFunction::IsInputValid(const TInteger& aInput,
1.70 + const TInteger& aModulus)
1.71 + {
1.72 + //See HAC 8.3 1.b
1.73 + //Message (input) must be in the interval [0,n-1] (inclusive)
1.74 + if( aInput.IsNegative() || aInput >= aModulus )
1.75 + return EFalse;
1.76 + else
1.77 + return ETrue;
1.78 + }
1.79 +
1.80 +void RSAFunction::IsInputValidL(const TInteger& aInput,
1.81 + const TInteger& aModulus)
1.82 + {
1.83 + if(!IsInputValid(aInput, aModulus))
1.84 + User::Leave(KErrArgument);
1.85 + }
1.86 +
1.87 +#endif
1.88 +