os/security/crypto/weakcryptospi/source/asymmetric/rsashim.h
changeset 0 bde4ae8d615e
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/os/security/crypto/weakcryptospi/source/asymmetric/rsashim.h	Fri Jun 15 03:10:57 2012 +0200
     1.3 @@ -0,0 +1,238 @@
     1.4 +/*
     1.5 +* Copyright (c) 2006-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 +* RSA shim classes definition
    1.19 +*
    1.20 +*/
    1.21 +
    1.22 +
    1.23 +/**
    1.24 + @file
    1.25 + @internalComponent
    1.26 + @released
    1.27 +*/
    1.28 +
    1.29 +#ifndef __RSASHIM_H__
    1.30 +#define __RSASHIM_H__
    1.31 +
    1.32 +#include <asymmetric.h>
    1.33 +
    1.34 +namespace CryptoSpi
    1.35 +	{
    1.36 +	class CAsymmetricCipher;
    1.37 +	class CKey;
    1.38 +	class CSigner;
    1.39 +	class CVerifier;
    1.40 +	}
    1.41 +	
    1.42 +NONSHARABLE_CLASS(CRSAPKCS1v15EncryptorShim) : public CRSAPKCS1v15Encryptor
    1.43 +{
    1.44 +public:
    1.45 +	/**
    1.46 +	Creates an RSAPKCS1v15EncryptorShim object which has the same interface
    1.47 +	as CRSAPKCS1v15Encryptor but delegates all work to a Crypto SPI plug-in.
    1.48 +	
    1.49 +	@param aKey The encryption key
    1.50 +	@return A pointer to a CRSAPKCS1v15EncryptorShim instance
    1.51 +	*/
    1.52 +	static CRSAPKCS1v15EncryptorShim* NewL(const CRSAPublicKey& aKey);
    1.53 +
    1.54 +	/**
    1.55 +	Creates an RSAPKCS1v15EncryptorShim object which has the same interface
    1.56 +	as CRSAPKCS1v15Encryptor but delegates all work to a Crypto SPI plug-in.
    1.57 +	
    1.58 +	A pointer to the new object is placed on the cleanup stack
    1.59 +	
    1.60 +	@param aKey The encryption key
    1.61 +	@return A pointer to a CRSAPKCS1v15EncryptorShim instance
    1.62 +	*/
    1.63 +	static CRSAPKCS1v15EncryptorShim* NewLC(const CRSAPublicKey& aKey);
    1.64 +	
    1.65 +	// From CRSAPKCS1v15Encryptor
    1.66 +	void EncryptL(const TDesC8& aInput, TDes8& aOutput) const;
    1.67 +	TInt MaxInputLength(void) const;
    1.68 +	TInt MaxOutputLength(void) const;
    1.69 +	
    1.70 +	/// Destructor
    1.71 +	~CRSAPKCS1v15EncryptorShim();
    1.72 +	
    1.73 +private:
    1.74 +	/// Constructor
    1.75 +	CRSAPKCS1v15EncryptorShim(const CRSAPublicKey& aKey);
    1.76 +	void ConstructL(const CRSAPublicKey& aKey);
    1.77 +	
    1.78 +private:
    1.79 +	/// SPI delegate
    1.80 +	CryptoSpi::CAsymmetricCipher* iAsymmetricCipherImpl;
    1.81 +		
    1.82 +	/// SPI requires all key to passed as key-objects
    1.83 +	CryptoSpi::CKey* iKey;
    1.84 +};
    1.85 +
    1.86 +NONSHARABLE_CLASS(CRSAPKCS1v15DecryptorShim) : public CRSAPKCS1v15Decryptor
    1.87 +{
    1.88 +public:
    1.89 +	/**
    1.90 +	Creates an RSAPKCS1v15DecryptorShim object which has the same interface
    1.91 +	as CRSAPKCS1v15Decryptor but delegates all work to a Crypto SPI plug-in.
    1.92 +	
    1.93 +	@param aKey The decryption key
    1.94 +	@return A pointer to a CRSAPKCS1v15DecryptorShim instance
    1.95 +	*/
    1.96 +	static CRSAPKCS1v15DecryptorShim* NewL(const CRSAPrivateKey& aKey);
    1.97 +	
    1.98 +	/**
    1.99 +	Creates an RSAPKCS1v15EncryptorShim object which has the same interface
   1.100 +	as CRSAPKCS1v15Decryptor but delegates all work to a Crypto SPI plug-in.
   1.101 +	
   1.102 +	A pointer to the new object is placed on the cleanup stack
   1.103 +	
   1.104 +	@param aKey The decryption key
   1.105 +	@return A pointer to a CRSAPKCS1v15DecryptorShim instance
   1.106 +	*/
   1.107 +	static CRSAPKCS1v15DecryptorShim* NewLC(const CRSAPrivateKey& aKey);
   1.108 +	
   1.109 +	// From CRSAPKCS1v15Decryptor
   1.110 +	void DecryptL(const TDesC8& aInput, TDes8& aOutput) const;
   1.111 +	TInt MaxInputLength(void) const;
   1.112 +	TInt MaxOutputLength(void) const;
   1.113 +	
   1.114 +	/// Destructor
   1.115 +	~CRSAPKCS1v15DecryptorShim();
   1.116 +	
   1.117 +private:
   1.118 +	/// Constructor
   1.119 +	CRSAPKCS1v15DecryptorShim(const CRSAPrivateKey& aKey);
   1.120 +	void ConstructL(const CRSAPrivateKey& aKey);
   1.121 +	
   1.122 +private:
   1.123 +	/// SPI delegate
   1.124 +	CryptoSpi::CAsymmetricCipher* iAsymmetricCipherImpl;
   1.125 +	
   1.126 +	/// SPI requires all key to passed as key-objects
   1.127 +	CryptoSpi::CKey* iKey;
   1.128 +};
   1.129 +
   1.130 +NONSHARABLE_CLASS(CRSAPKCS1v15SignerShim) : public CRSAPKCS1v15Signer
   1.131 +	{
   1.132 +public:
   1.133 +	/**
   1.134 +	Creates a new CRSAPKCS1v15SignerShim object which has the same interface
   1.135 +	as CRSAPKCS1v15Signer but delegates all work to a Crypto SPI plug-in.
   1.136 +
   1.137 +	 @param aKey	The RSA private key to be used for signing
   1.138 +	 @return A pointer to a CRSAPKCS1v15SignerShim instance
   1.139 +	 @leave KErrKeySize	If the key length is too small
   1.140 +	 */
   1.141 +	static CRSAPKCS1v15SignerShim* NewL(const CRSAPrivateKey& aKey);
   1.142 +
   1.143 +	/**
   1.144 +	Creates a new CRSAPKCS1v15SignerShim object which has the same interface
   1.145 +	as CRSAPKCS1v15Signer but delegates all work to a Crypto SPI plug-in.
   1.146 +
   1.147 +	 @param aKey	The RSA private key to be used for signing
   1.148 +	 @return A pointer to a CRSAPKCS1v15SignerShim instance
   1.149 +	 @leave KErrKeySize	If the key length is too small
   1.150 +	 */
   1.151 +	static CRSAPKCS1v15SignerShim* NewLC(const CRSAPrivateKey& aKey);
   1.152 +
   1.153 +	// From CRSAPKCS1v15Signer
   1.154 +	virtual CRSASignature* SignL(const TDesC8& aInput) const;
   1.155 +	virtual TInt MaxInputLength(void) const;
   1.156 +	virtual TInt MaxOutputLength(void) const;
   1.157 +	/** The destructor frees all resources owned by the object, prior to its destruction.*/
   1.158 +	~CRSAPKCS1v15SignerShim(void);
   1.159 +protected:
   1.160 +	
   1.161 +	CRSAPKCS1v15SignerShim(const CRSAPrivateKey& aKey);
   1.162 +	void ConstructL(const CRSAPrivateKey& aKey);
   1.163 +
   1.164 +protected:
   1.165 +	/// SPI delegate
   1.166 +	CryptoSpi::CSigner* iSignerImpl;
   1.167 +
   1.168 +	/// SPI requires all key to passed as key-objects
   1.169 +	CryptoSpi::CKey* iKey;
   1.170 +private:
   1.171 +	CRSAPKCS1v15SignerShim(const CRSAPKCS1v15SignerShim&);
   1.172 +	CRSAPKCS1v15SignerShim& operator=(const CRSAPKCS1v15SignerShim&);
   1.173 +	};
   1.174 +
   1.175 +/**
   1.176 +* This class verifies RSA signatures given a message and its supposed
   1.177 +* signature.  It follows the RSA PKCS#1 v1.5 with PKCS#1 v1.5 padding specification
   1.178 +* with the following exception: the VerifyL() function does <b>not</b> hash or
   1.179 +* in any way manipulate the input data before checking.  Thus in order to verify
   1.180 +* RSA signatures in PKCS#1 v1.5 format, the input data needs to follow PKCS#1 v1.5 
   1.181 +* specification, i.e. be ASN.1 encoded and prefixed  by ASN.1 encoded digestId.
   1.182 +* 
   1.183 +* @internalComponent
   1.184 +* @released 
   1.185 +*/
   1.186 +NONSHARABLE_CLASS(CRSAPKCS1v15VerifierShim) : public CRSAPKCS1v15Verifier
   1.187 +	{
   1.188 +public:
   1.189 +	/**
   1.190 +	@internalComponent
   1.191 +	
   1.192 +	Creates a new CRSAPKCS1v15VerifierShim object which has the same interface
   1.193 +	as CRSAPKCS1v15Verifier but delegates all work to a Crypto SPI plug-in.
   1.194 +	
   1.195 +	@param aKey	The RSA public key to be used for verifying
   1.196 +	@return A pointer to a CRSAPKCS1v15VerifierShim instance
   1.197 +	@leave KErrKeySize	If the key length is too small
   1.198 +	 */
   1.199 +	static CRSAPKCS1v15VerifierShim* NewL(const CRSAPublicKey& aKey);
   1.200 +
   1.201 +	/**
   1.202 +	@internalComponent
   1.203 +	
   1.204 +	Creates a new CRSAPKCS1v15VerifierShim object which has the same interface
   1.205 +	as CRSAPKCS1v15Verifier but delegates all work to a Crypto SPI plug-in.
   1.206 +
   1.207 +	 The returned pointer is put onto the cleanup stack.
   1.208 +
   1.209 +	 @param aKey	The RSA public key to be used for verifying
   1.210 +	 @return A pointer to a CRSAPKCS1v15VerifierShim instance
   1.211 +
   1.212 +	 @leave KErrKeySize	If the key length is too small
   1.213 +	 */
   1.214 +	static CRSAPKCS1v15VerifierShim* NewLC(const CRSAPublicKey& aKey);
   1.215 +	
   1.216 +	// CRSAPKCS1v15Verifier
   1.217 +	virtual TInt MaxInputLength(void) const;
   1.218 +	virtual TInt MaxOutputLength(void) const;
   1.219 +
   1.220 +	// RSAVerifier
   1.221 +	virtual TBool VerifyL(const TDesC8& aInput, const CRSASignature& aSignature) const;
   1.222 +	virtual HBufC8* InverseSignLC(const CRSASignature& aSignature) const;
   1.223 +
   1.224 +	/** The destructor frees all resources owned by the object, prior to its destruction. */
   1.225 +	virtual ~CRSAPKCS1v15VerifierShim(void);
   1.226 +protected:
   1.227 +	CRSAPKCS1v15VerifierShim(const CRSAPublicKey& aKey);
   1.228 +	void ConstructL(const CRSAPublicKey& aKey);
   1.229 +
   1.230 +protected:
   1.231 +	/// SPI delegate
   1.232 +	CryptoSpi::CVerifier* iVerifierImpl;
   1.233 +
   1.234 +	/// SPI requires all key to passed as key-objects
   1.235 +	CryptoSpi::CKey* iKey;
   1.236 +private:
   1.237 +	CRSAPKCS1v15VerifierShim(const CRSAPKCS1v15VerifierShim&);
   1.238 +	CRSAPKCS1v15VerifierShim& operator=(const CRSAPKCS1v15VerifierShim&);
   1.239 +	};
   1.240 +
   1.241 +#endif // __RSASHIM_H__