72
|
1 |
/*
|
|
2 |
* Copyright (c) 2003-2009 Nokia Corporation and/or its subsidiary(-ies).
|
|
3 |
* All rights reserved.
|
|
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".
|
|
8 |
*
|
|
9 |
* Initial Contributors:
|
|
10 |
* Nokia Corporation - initial contribution.
|
|
11 |
*
|
|
12 |
* Contributors:
|
|
13 |
*
|
|
14 |
* Description:
|
|
15 |
* RSAFunction class implementation
|
|
16 |
*
|
|
17 |
*/
|
|
18 |
|
|
19 |
|
|
20 |
/**
|
|
21 |
@file
|
|
22 |
@internalTechnology
|
|
23 |
*/
|
|
24 |
|
|
25 |
#ifndef __RSAFUNCTION_H__
|
|
26 |
#define __RSAFUNCTION_H__
|
|
27 |
|
|
28 |
#include <e32base.h>
|
|
29 |
|
|
30 |
class TInteger;
|
|
31 |
|
|
32 |
class CRSAPublicKey;
|
|
33 |
class CRSAPrivateKey;
|
|
34 |
class CRSAPrivateKeyCRT;
|
|
35 |
|
|
36 |
class RSAFunction
|
|
37 |
{
|
|
38 |
public:
|
|
39 |
static inline TBool IsInputValid(const TInteger& aInput,
|
|
40 |
const TInteger& aModulus);
|
|
41 |
static inline void IsInputValidL(const TInteger& aInput,
|
|
42 |
const TInteger& aModulus);
|
|
43 |
static void EncryptL(const CRSAPublicKey& aPublicKey,
|
|
44 |
const TInteger& aInput, RInteger& aOutput);
|
|
45 |
static void DecryptL(const CRSAPrivateKey& aPrivateKey,
|
|
46 |
const TInteger& aInput, RInteger& aOutput);
|
|
47 |
static void SignL(const CRSAPrivateKey& aPrivateKey,
|
|
48 |
const TInteger& aInput, RInteger& aOutput);
|
|
49 |
static void VerifyL(const CRSAPublicKey& aPublicKey,
|
|
50 |
const TInteger& aInput, RInteger& aOutput);
|
|
51 |
private:
|
|
52 |
static void FunctionL(const TInteger& aModulus, const TInteger& aExponent,
|
|
53 |
const TInteger& aBase, RInteger& aOutput);
|
|
54 |
static void FunctionCRTL(const CRSAPrivateKeyCRT& aPrivateKey,
|
|
55 |
const TInteger& aInput, RInteger& aOutput);
|
|
56 |
private:
|
|
57 |
RSAFunction(void);
|
|
58 |
};
|
|
59 |
|
|
60 |
/** Computes whether a given message representative is within the valid bounds
|
|
61 |
* for a given modulus, i.e. whether the message is representative within [0,n-1].
|
|
62 |
* @param aInput The message representative.
|
|
63 |
* @param aModulus The modulus.
|
|
64 |
* @return TBool representing whether or not the message representative is
|
|
65 |
* valid.
|
|
66 |
*/
|
|
67 |
TBool RSAFunction::IsInputValid(const TInteger& aInput,
|
|
68 |
const TInteger& aModulus)
|
|
69 |
{
|
|
70 |
//See HAC 8.3 1.b
|
|
71 |
//Message (input) must be in the interval [0,n-1] (inclusive)
|
|
72 |
if( aInput.IsNegative() || aInput >= aModulus )
|
|
73 |
return EFalse;
|
|
74 |
else
|
|
75 |
return ETrue;
|
|
76 |
}
|
|
77 |
|
|
78 |
void RSAFunction::IsInputValidL(const TInteger& aInput,
|
|
79 |
const TInteger& aModulus)
|
|
80 |
{
|
|
81 |
if(!IsInputValid(aInput, aModulus))
|
|
82 |
User::Leave(KErrArgument);
|
|
83 |
}
|
|
84 |
|
|
85 |
#endif
|
|
86 |
|