sl@0: /* sl@0: * Copyright (c) 2006-2009 Nokia Corporation and/or its subsidiary(-ies). sl@0: * All rights reserved. sl@0: * This component and the accompanying materials are made available sl@0: * under the terms of the License "Eclipse Public License v1.0" sl@0: * which accompanies this distribution, and is available sl@0: * at the URL "http://www.eclipse.org/legal/epl-v10.html". sl@0: * sl@0: * Initial Contributors: sl@0: * Nokia Corporation - initial contribution. sl@0: * sl@0: * Contributors: sl@0: * sl@0: * Description: sl@0: * RSA shim classes definition sl@0: * sl@0: */ sl@0: sl@0: sl@0: /** sl@0: @file sl@0: @internalComponent sl@0: @released sl@0: */ sl@0: sl@0: #ifndef __RSASHIM_H__ sl@0: #define __RSASHIM_H__ sl@0: sl@0: #include sl@0: sl@0: namespace CryptoSpi sl@0: { sl@0: class CAsymmetricCipher; sl@0: class CKey; sl@0: class CSigner; sl@0: class CVerifier; sl@0: } sl@0: sl@0: NONSHARABLE_CLASS(CRSAPKCS1v15EncryptorShim) : public CRSAPKCS1v15Encryptor sl@0: { sl@0: public: sl@0: /** sl@0: Creates an RSAPKCS1v15EncryptorShim object which has the same interface sl@0: as CRSAPKCS1v15Encryptor but delegates all work to a Crypto SPI plug-in. sl@0: sl@0: @param aKey The encryption key sl@0: @return A pointer to a CRSAPKCS1v15EncryptorShim instance sl@0: */ sl@0: static CRSAPKCS1v15EncryptorShim* NewL(const CRSAPublicKey& aKey); sl@0: sl@0: /** sl@0: Creates an RSAPKCS1v15EncryptorShim object which has the same interface sl@0: as CRSAPKCS1v15Encryptor but delegates all work to a Crypto SPI plug-in. sl@0: sl@0: A pointer to the new object is placed on the cleanup stack sl@0: sl@0: @param aKey The encryption key sl@0: @return A pointer to a CRSAPKCS1v15EncryptorShim instance sl@0: */ sl@0: static CRSAPKCS1v15EncryptorShim* NewLC(const CRSAPublicKey& aKey); sl@0: sl@0: // From CRSAPKCS1v15Encryptor sl@0: void EncryptL(const TDesC8& aInput, TDes8& aOutput) const; sl@0: TInt MaxInputLength(void) const; sl@0: TInt MaxOutputLength(void) const; sl@0: sl@0: /// Destructor sl@0: ~CRSAPKCS1v15EncryptorShim(); sl@0: sl@0: private: sl@0: /// Constructor sl@0: CRSAPKCS1v15EncryptorShim(const CRSAPublicKey& aKey); sl@0: void ConstructL(const CRSAPublicKey& aKey); sl@0: sl@0: private: sl@0: /// SPI delegate sl@0: CryptoSpi::CAsymmetricCipher* iAsymmetricCipherImpl; sl@0: sl@0: /// SPI requires all key to passed as key-objects sl@0: CryptoSpi::CKey* iKey; sl@0: }; sl@0: sl@0: NONSHARABLE_CLASS(CRSAPKCS1v15DecryptorShim) : public CRSAPKCS1v15Decryptor sl@0: { sl@0: public: sl@0: /** sl@0: Creates an RSAPKCS1v15DecryptorShim object which has the same interface sl@0: as CRSAPKCS1v15Decryptor but delegates all work to a Crypto SPI plug-in. sl@0: sl@0: @param aKey The decryption key sl@0: @return A pointer to a CRSAPKCS1v15DecryptorShim instance sl@0: */ sl@0: static CRSAPKCS1v15DecryptorShim* NewL(const CRSAPrivateKey& aKey); sl@0: sl@0: /** sl@0: Creates an RSAPKCS1v15EncryptorShim object which has the same interface sl@0: as CRSAPKCS1v15Decryptor but delegates all work to a Crypto SPI plug-in. sl@0: sl@0: A pointer to the new object is placed on the cleanup stack sl@0: sl@0: @param aKey The decryption key sl@0: @return A pointer to a CRSAPKCS1v15DecryptorShim instance sl@0: */ sl@0: static CRSAPKCS1v15DecryptorShim* NewLC(const CRSAPrivateKey& aKey); sl@0: sl@0: // From CRSAPKCS1v15Decryptor sl@0: void DecryptL(const TDesC8& aInput, TDes8& aOutput) const; sl@0: TInt MaxInputLength(void) const; sl@0: TInt MaxOutputLength(void) const; sl@0: sl@0: /// Destructor sl@0: ~CRSAPKCS1v15DecryptorShim(); sl@0: sl@0: private: sl@0: /// Constructor sl@0: CRSAPKCS1v15DecryptorShim(const CRSAPrivateKey& aKey); sl@0: void ConstructL(const CRSAPrivateKey& aKey); sl@0: sl@0: private: sl@0: /// SPI delegate sl@0: CryptoSpi::CAsymmetricCipher* iAsymmetricCipherImpl; sl@0: sl@0: /// SPI requires all key to passed as key-objects sl@0: CryptoSpi::CKey* iKey; sl@0: }; sl@0: sl@0: NONSHARABLE_CLASS(CRSAPKCS1v15SignerShim) : public CRSAPKCS1v15Signer sl@0: { sl@0: public: sl@0: /** sl@0: Creates a new CRSAPKCS1v15SignerShim object which has the same interface sl@0: as CRSAPKCS1v15Signer but delegates all work to a Crypto SPI plug-in. sl@0: sl@0: @param aKey The RSA private key to be used for signing sl@0: @return A pointer to a CRSAPKCS1v15SignerShim instance sl@0: @leave KErrKeySize If the key length is too small sl@0: */ sl@0: static CRSAPKCS1v15SignerShim* NewL(const CRSAPrivateKey& aKey); sl@0: sl@0: /** sl@0: Creates a new CRSAPKCS1v15SignerShim object which has the same interface sl@0: as CRSAPKCS1v15Signer but delegates all work to a Crypto SPI plug-in. sl@0: sl@0: @param aKey The RSA private key to be used for signing sl@0: @return A pointer to a CRSAPKCS1v15SignerShim instance sl@0: @leave KErrKeySize If the key length is too small sl@0: */ sl@0: static CRSAPKCS1v15SignerShim* NewLC(const CRSAPrivateKey& aKey); sl@0: sl@0: // From CRSAPKCS1v15Signer sl@0: virtual CRSASignature* SignL(const TDesC8& aInput) const; sl@0: virtual TInt MaxInputLength(void) const; sl@0: virtual TInt MaxOutputLength(void) const; sl@0: /** The destructor frees all resources owned by the object, prior to its destruction.*/ sl@0: ~CRSAPKCS1v15SignerShim(void); sl@0: protected: sl@0: sl@0: CRSAPKCS1v15SignerShim(const CRSAPrivateKey& aKey); sl@0: void ConstructL(const CRSAPrivateKey& aKey); sl@0: sl@0: protected: sl@0: /// SPI delegate sl@0: CryptoSpi::CSigner* iSignerImpl; sl@0: sl@0: /// SPI requires all key to passed as key-objects sl@0: CryptoSpi::CKey* iKey; sl@0: private: sl@0: CRSAPKCS1v15SignerShim(const CRSAPKCS1v15SignerShim&); sl@0: CRSAPKCS1v15SignerShim& operator=(const CRSAPKCS1v15SignerShim&); sl@0: }; sl@0: sl@0: /** sl@0: * This class verifies RSA signatures given a message and its supposed sl@0: * signature. It follows the RSA PKCS#1 v1.5 with PKCS#1 v1.5 padding specification sl@0: * with the following exception: the VerifyL() function does not hash or sl@0: * in any way manipulate the input data before checking. Thus in order to verify sl@0: * RSA signatures in PKCS#1 v1.5 format, the input data needs to follow PKCS#1 v1.5 sl@0: * specification, i.e. be ASN.1 encoded and prefixed by ASN.1 encoded digestId. sl@0: * sl@0: * @internalComponent sl@0: * @released sl@0: */ sl@0: NONSHARABLE_CLASS(CRSAPKCS1v15VerifierShim) : public CRSAPKCS1v15Verifier sl@0: { sl@0: public: sl@0: /** sl@0: @internalComponent sl@0: sl@0: Creates a new CRSAPKCS1v15VerifierShim object which has the same interface sl@0: as CRSAPKCS1v15Verifier but delegates all work to a Crypto SPI plug-in. sl@0: sl@0: @param aKey The RSA public key to be used for verifying sl@0: @return A pointer to a CRSAPKCS1v15VerifierShim instance sl@0: @leave KErrKeySize If the key length is too small sl@0: */ sl@0: static CRSAPKCS1v15VerifierShim* NewL(const CRSAPublicKey& aKey); sl@0: sl@0: /** sl@0: @internalComponent sl@0: sl@0: Creates a new CRSAPKCS1v15VerifierShim object which has the same interface sl@0: as CRSAPKCS1v15Verifier but delegates all work to a Crypto SPI plug-in. sl@0: sl@0: The returned pointer is put onto the cleanup stack. sl@0: sl@0: @param aKey The RSA public key to be used for verifying sl@0: @return A pointer to a CRSAPKCS1v15VerifierShim instance sl@0: sl@0: @leave KErrKeySize If the key length is too small sl@0: */ sl@0: static CRSAPKCS1v15VerifierShim* NewLC(const CRSAPublicKey& aKey); sl@0: sl@0: // CRSAPKCS1v15Verifier sl@0: virtual TInt MaxInputLength(void) const; sl@0: virtual TInt MaxOutputLength(void) const; sl@0: sl@0: // RSAVerifier sl@0: virtual TBool VerifyL(const TDesC8& aInput, const CRSASignature& aSignature) const; sl@0: virtual HBufC8* InverseSignLC(const CRSASignature& aSignature) const; sl@0: sl@0: /** The destructor frees all resources owned by the object, prior to its destruction. */ sl@0: virtual ~CRSAPKCS1v15VerifierShim(void); sl@0: protected: sl@0: CRSAPKCS1v15VerifierShim(const CRSAPublicKey& aKey); sl@0: void ConstructL(const CRSAPublicKey& aKey); sl@0: sl@0: protected: sl@0: /// SPI delegate sl@0: CryptoSpi::CVerifier* iVerifierImpl; sl@0: sl@0: /// SPI requires all key to passed as key-objects sl@0: CryptoSpi::CKey* iKey; sl@0: private: sl@0: CRSAPKCS1v15VerifierShim(const CRSAPKCS1v15VerifierShim&); sl@0: CRSAPKCS1v15VerifierShim& operator=(const CRSAPKCS1v15VerifierShim&); sl@0: }; sl@0: sl@0: #endif // __RSASHIM_H__