# HG changeset patch # User MattD # Date 1259665924 0 # Node ID f9c11be8c0b376864b375909caf9eac419379805 # Parent f3b0b5725c587aef9ff1443caae3d9f208736657# Parent 7e3f204e6c81a0387be84929cb4285a54a6ccc1a Merge Tags diff -r 7e3f204e6c81 -r f9c11be8c0b3 authorisation/userpromptservice/group/bld.inf --- a/authorisation/userpromptservice/group/bld.inf Thu Nov 12 16:07:39 2009 +0000 +++ b/authorisation/userpromptservice/group/bld.inf Tue Dec 01 11:12:04 2009 +0000 @@ -24,7 +24,7 @@ #include "../examples/bld.inf" PRJ_EXPORTS -../inc/ups.hrh SYMBIAN_OS_LAYER_PUBLIC_EXPORT_PATH(ups/ups.hrh) +../inc/ups.hrh /epoc32/include/ups/ups.hrh ../inc/upsconst.h SYMBIAN_OS_LAYER_PUBLIC_EXPORT_PATH(ups/upsconst.h) ../inc/upserr.h SYMBIAN_OS_LAYER_PUBLIC_EXPORT_PATH(ups/upserr.h) ../inc/upstypes.h SYMBIAN_OS_LAYER_PUBLIC_EXPORT_PATH(ups/upstypes.h) diff -r 7e3f204e6c81 -r f9c11be8c0b3 contentmgmt/cafrecogniserconfig/ABLD.BAT --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/contentmgmt/cafrecogniserconfig/ABLD.BAT Tue Dec 01 11:12:04 2009 +0000 @@ -0,0 +1,15 @@ +@ECHO OFF + +REM Bldmake-generated batch file - ABLD.BAT +REM ** DO NOT EDIT ** + +perl -S ABLD.PL "\sf\os\security\contentmgmt\cafrecogniserconfig\\" %1 %2 %3 %4 %5 %6 %7 %8 %9 +if errorlevel==1 goto CheckPerl +goto End + +:CheckPerl +perl -v >NUL +if errorlevel==1 echo Is Perl, version 5.003_07 or later, installed? +goto End + +:End diff -r 7e3f204e6c81 -r f9c11be8c0b3 contentmgmt/contentaccessfwfordrm/group/bld.inf --- a/contentmgmt/contentaccessfwfordrm/group/bld.inf Thu Nov 12 16:07:39 2009 +0000 +++ b/contentmgmt/contentaccessfwfordrm/group/bld.inf Tue Dec 01 11:12:04 2009 +0000 @@ -123,7 +123,7 @@ ../../referencedrmagent/tcaf/scripts/contentstep.ini z:/tcaf/contentstep.ini ../../referencedrmagent/tcaf/scripts/oom.script z:/tcaf/oom.script ../../referencedrmagent/tcaf/scripts/oom.ini z:/tcaf/oom.ini -#ifndef SYMBIAN_DISABLE_UPWARD_DEPENDENCY +#ifdef INTERNALLY_ENABLE_UPWARD_DEPENDENCY ../../referencedrmagent/tcaf/scripts/supply.script z:/tcaf/supply.script #else ../../referencedrmagent/tcaf/scripts/supply_without_http.script z:/tcaf/supply.script diff -r 7e3f204e6c81 -r f9c11be8c0b3 contentmgmt/contentaccessfwfordrm/group/tcaf.mmp --- a/contentmgmt/contentaccessfwfordrm/group/tcaf.mmp Thu Nov 12 16:07:39 2009 +0000 +++ b/contentmgmt/contentaccessfwfordrm/group/tcaf.mmp Tue Dec 01 11:12:04 2009 +0000 @@ -68,7 +68,7 @@ LIBRARY apgrfx.lib LIBRARY hal.lib -#ifndef SYMBIAN_DISABLE_UPWARD_DEPENDENCY +#ifdef INTERNALLY_ENABLE_UPWARD_DEPENDENCY LIBRARY http.lib #endif diff -r 7e3f204e6c81 -r f9c11be8c0b3 contentmgmt/contentaccessfwfordrm/group/testagent.mmp --- a/contentmgmt/contentaccessfwfordrm/group/testagent.mmp Thu Nov 12 16:07:39 2009 +0000 +++ b/contentmgmt/contentaccessfwfordrm/group/testagent.mmp Tue Dec 01 11:12:04 2009 +0000 @@ -51,7 +51,7 @@ LIBRARY bafl.lib LIBRARY estor.lib -#ifndef SYMBIAN_DISABLE_UPWARD_DEPENDENCY +#ifdef INTERNALLY_ENABLE_UPWARD_DEPENDENCY LIBRARY http.lib #endif diff -r 7e3f204e6c81 -r f9c11be8c0b3 contentmgmt/referencedrmagent/RefTestAgent/RefTestAgent/Reftestagentmanager.cpp --- a/contentmgmt/referencedrmagent/RefTestAgent/RefTestAgent/Reftestagentmanager.cpp Thu Nov 12 16:07:39 2009 +0000 +++ b/contentmgmt/referencedrmagent/RefTestAgent/RefTestAgent/Reftestagentmanager.cpp Tue Dec 01 11:12:04 2009 +0000 @@ -17,8 +17,10 @@ #include +#ifdef INTERNALLY_ENABLE_UPWARD_DEPENDENCY #include #include +#endif #include #include "Reftestagentmanager.h" @@ -332,7 +334,7 @@ // make leavescan happy, the options are: 1. TRAP leave calls // and ignore the errors. 2. Panic. Both options could potentially // break RTA clients' testcases. Hence just leave it the way it is. -#ifndef SYMBIAN_DISABLE_UPWARD_DEPENDENCY +#ifdef INTERNALLY_ENABLE_UPWARD_DEPENDENCY void CRefTestAgentManager::PrepareHTTPRequestHeaders(RStringPool& aStringPool, RHTTPHeaders& aRequestHeaders) const { // Add the accept header for the reference test agent diff -r 7e3f204e6c81 -r f9c11be8c0b3 contentmgmt/referencedrmagent/RefTestAgent/group/ABLD.BAT --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/contentmgmt/referencedrmagent/RefTestAgent/group/ABLD.BAT Tue Dec 01 11:12:04 2009 +0000 @@ -0,0 +1,15 @@ +@ECHO OFF + +REM Bldmake-generated batch file - ABLD.BAT +REM ** DO NOT EDIT ** + +perl -S ABLD.PL "\sf\os\security\contentmgmt\referencedrmagent\RefTestAgent\group\\" %1 %2 %3 %4 %5 %6 %7 %8 %9 +if errorlevel==1 goto CheckPerl +goto End + +:CheckPerl +perl -v >NUL +if errorlevel==1 echo Is Perl, version 5.003_07 or later, installed? +goto End + +:End diff -r 7e3f204e6c81 -r f9c11be8c0b3 contentmgmt/referencedrmagent/RefTestAgent/group/reftestagent.mmp --- a/contentmgmt/referencedrmagent/RefTestAgent/group/reftestagent.mmp Thu Nov 12 16:07:39 2009 +0000 +++ b/contentmgmt/referencedrmagent/RefTestAgent/group/reftestagent.mmp Tue Dec 01 11:12:04 2009 +0000 @@ -59,7 +59,7 @@ LIBRARY rtaclient.lib LIBRARY bafl.lib -#ifndef SYMBIAN_DISABLE_UPWARD_DEPENDENCY +#ifdef INTERNALLY_ENABLE_UPWARD_DEPENDENCY LIBRARY http.lib #endif diff -r 7e3f204e6c81 -r f9c11be8c0b3 contentmgmt/referencedrmagent/RefTestAgent/group/sraclient.mmp --- a/contentmgmt/referencedrmagent/RefTestAgent/group/sraclient.mmp Thu Nov 12 16:07:39 2009 +0000 +++ b/contentmgmt/referencedrmagent/RefTestAgent/group/sraclient.mmp Tue Dec 01 11:12:04 2009 +0000 @@ -36,7 +36,9 @@ LIBRARY euser.lib LIBRARY estor.lib LIBRARY cafutils.lib +#ifdef INTERNALLY_ENABLE_UPWARD_DEPENDENCY LIBRARY sdpcodec.lib +#endif LIBRARY streamingcaf.lib LIBRARY efsrv.lib SMPSAFE diff -r 7e3f204e6c81 -r f9c11be8c0b3 contentmgmt/referencedrmagent/RefTestAgent/group/sraplugin.mmp --- a/contentmgmt/referencedrmagent/RefTestAgent/group/sraplugin.mmp Thu Nov 12 16:07:39 2009 +0000 +++ b/contentmgmt/referencedrmagent/RefTestAgent/group/sraplugin.mmp Tue Dec 01 11:12:04 2009 +0000 @@ -39,7 +39,9 @@ LIBRARY euser.lib LIBRARY streamingcaf.lib +#ifdef INTERNALLY_ENABLE_UPWARD_DEPENDENCY LIBRARY sdpcodec.lib +#endif LIBRARY sraclient.lib srautils.lib START RESOURCE 10285A34.rss diff -r 7e3f204e6c81 -r f9c11be8c0b3 contentmgmt/referencedrmagent/RefTestAgent/group/sraserver.mmp --- a/contentmgmt/referencedrmagent/RefTestAgent/group/sraserver.mmp Thu Nov 12 16:07:39 2009 +0000 +++ b/contentmgmt/referencedrmagent/RefTestAgent/group/sraserver.mmp Tue Dec 01 11:12:04 2009 +0000 @@ -40,7 +40,9 @@ LIBRARY efsrv.lib LIBRARY cafutils.lib LIBRARY estor.lib +#ifdef INTERNALLY_ENABLE_UPWARD_DEPENDENCY LIBRARY sdpcodec.lib +#endif LIBRARY bafl.lib LIBRARY streamingcaf.lib LIBRARY srautils.lib diff -r 7e3f204e6c81 -r f9c11be8c0b3 contentmgmt/referencedrmagent/RefTestAgent/group/srautils.mmp --- a/contentmgmt/referencedrmagent/RefTestAgent/group/srautils.mmp Thu Nov 12 16:07:39 2009 +0000 +++ b/contentmgmt/referencedrmagent/RefTestAgent/group/srautils.mmp Tue Dec 01 11:12:04 2009 +0000 @@ -41,7 +41,9 @@ LIBRARY euser.lib LIBRARY estor.lib LIBRARY streamingcaf.lib +#ifdef INTERNALLY_ENABLE_UPWARD_DEPENDENCY LIBRARY sdpcodec.lib +#endif LIBRARY efsrv.lib LIBRARY bafl.lib SMPSAFE diff -r 7e3f204e6c81 -r f9c11be8c0b3 contentmgmt/referencedrmagent/RefTestAgent/streamingrefagent/inc/sraclient.h --- a/contentmgmt/referencedrmagent/RefTestAgent/streamingrefagent/inc/sraclient.h Thu Nov 12 16:07:39 2009 +0000 +++ b/contentmgmt/referencedrmagent/RefTestAgent/streamingrefagent/inc/sraclient.h Tue Dec 01 11:12:04 2009 +0000 @@ -32,7 +32,9 @@ //Forward declarations class CRightsObject; - +class CSdpMediaField; +class CSdpDocument; + NONSHARABLE_CLASS(RSraClient) : public RSessionBase /** The Key Stream Decoder uses this class to establish a connection with the Streaming Reference diff -r 7e3f204e6c81 -r f9c11be8c0b3 contentmgmt/referencedrmagent/RefTestAgent/streamingrefagent/inc/sracommon.h --- a/contentmgmt/referencedrmagent/RefTestAgent/streamingrefagent/inc/sracommon.h Thu Nov 12 16:07:39 2009 +0000 +++ b/contentmgmt/referencedrmagent/RefTestAgent/streamingrefagent/inc/sracommon.h Tue Dec 01 11:12:04 2009 +0000 @@ -33,12 +33,15 @@ #include #include #include + +#ifdef INTERNALLY_ENABLE_UPWARD_DEPENDENCY #include #include #include #include #include #include +#endif #include #include diff -r 7e3f204e6c81 -r f9c11be8c0b3 contentmgmt/referencedrmagent/RefTestAgent/streamingrefagent/inc/sraserver.h --- a/contentmgmt/referencedrmagent/RefTestAgent/streamingrefagent/inc/sraserver.h Thu Nov 12 16:07:39 2009 +0000 +++ b/contentmgmt/referencedrmagent/RefTestAgent/streamingrefagent/inc/sraserver.h Tue Dec 01 11:12:04 2009 +0000 @@ -96,9 +96,11 @@ private: CSraProcessor* iProcessor; CKeyStreamSink* iKeyStreamSink; + CSraRightsObject* iRo; +#ifdef INTERNALLY_ENABLE_UPWARD_DEPENDENCY CSdpMediaField* iSdp; - CSraRightsObject* iRo; CSdpDocument* iSdpDoc; +#endif /** A handle to a mutex which is used to signal the client that the key has been implemented. Not necessary in real-life agents and is present here only for testing. diff -r 7e3f204e6c81 -r f9c11be8c0b3 contentmgmt/referencedrmagent/RefTestAgent/streamingrefagent/inc/srautils.h --- a/contentmgmt/referencedrmagent/RefTestAgent/streamingrefagent/inc/srautils.h Thu Nov 12 16:07:39 2009 +0000 +++ b/contentmgmt/referencedrmagent/RefTestAgent/streamingrefagent/inc/srautils.h Tue Dec 01 11:12:04 2009 +0000 @@ -27,9 +27,14 @@ #define SRAUTILS_H #include "srarightsobject.h" +#ifdef INTERNALLY_ENABLE_UPWARD_DEPENDENCY #include +#else +class CSdpMediaField; +#endif #include + IMPORT_C TBool CheckKeyStreamSupportedL(const CSdpMediaField& aSdpKeyStream, const TDesC8& aSupportedKmsIds); IMPORT_C void DoSetSdpMediaFieldL(RFs& aFs, CSdpMediaField*& aSdp, CSraRightsObject*& aRo, const TDesC8& aSdpData, const TDesC& aPrivateFolder); IMPORT_C void DoSetRightsObjectL(RFs& aFs, CSdpMediaField& aSdp, CSraRightsObject*& aRo, const TDesC& aPrivateFolder); diff -r 7e3f204e6c81 -r f9c11be8c0b3 contentmgmt/referencedrmagent/RefTestAgent/streamingrefagent/source/client/sraclient.cpp --- a/contentmgmt/referencedrmagent/RefTestAgent/streamingrefagent/source/client/sraclient.cpp Thu Nov 12 16:07:39 2009 +0000 +++ b/contentmgmt/referencedrmagent/RefTestAgent/streamingrefagent/source/client/sraclient.cpp Tue Dec 01 11:12:04 2009 +0000 @@ -185,11 +185,14 @@ @param aKey An SDP object data. */ { +#ifdef INTERNALLY_ENABLE_UPWARD_DEPENDENCY HBufC8* sdpBuf(0); TPtr8 ptr(EncodeLC(aSdp, sdpBuf)); - User::LeaveIfError(RSessionBase::SendReceive(ESetSdpKeyStream, TIpcArgs(&ptr))); CleanupStack::PopAndDestroy(sdpBuf); +#else + (void) aSdp; +#endif } EXPORT_C void RSraClient::SendSdpDocumentL(const CSdpDocument& aSdpDoc) const @@ -198,9 +201,13 @@ @param aKey An SDP object data. */ { +#ifdef INTERNALLY_ENABLE_UPWARD_DEPENDENCY HBufC8* sdpDocBuf(0); TPtr8 ptr(EncodeLC(aSdpDoc, sdpDocBuf)); - User::LeaveIfError(RSessionBase::SendReceive(ESetSdpDocument, TIpcArgs(&ptr))); CleanupStack::PopAndDestroy(sdpDocBuf); +#else + (void) aSdpDoc; +#endif + } diff -r 7e3f204e6c81 -r f9c11be8c0b3 contentmgmt/referencedrmagent/RefTestAgent/streamingrefagent/source/server/sraserver.cpp --- a/contentmgmt/referencedrmagent/RefTestAgent/streamingrefagent/source/server/sraserver.cpp Thu Nov 12 16:07:39 2009 +0000 +++ b/contentmgmt/referencedrmagent/RefTestAgent/streamingrefagent/source/server/sraserver.cpp Tue Dec 01 11:12:04 2009 +0000 @@ -61,7 +61,9 @@ delete iShutdownTimer; iFs.Close(); +#ifdef INTERNALLY_ENABLE_UPWARD_DEPENDENCY SdpCodecStringPool::Close(); +#endif } @@ -79,7 +81,9 @@ User::LeaveIfError(iFs.Connect()); User::LeaveIfError(iFs.ShareProtected()); User::LeaveIfError(iFs.CreatePrivatePath(iFs.GetSystemDrive())); +#ifdef INTERNALLY_ENABLE_UPWARD_DEPENDENCY SdpCodecStringPool::OpenL(); +#endif StartL(KSraName); iShutdownTimer = CShutdownTimer::NewL(KSraShutdownPeriod); iShutdownTimer->Restart(); diff -r 7e3f204e6c81 -r f9c11be8c0b3 contentmgmt/referencedrmagent/RefTestAgent/streamingrefagent/source/server/srasession.cpp --- a/contentmgmt/referencedrmagent/RefTestAgent/streamingrefagent/source/server/srasession.cpp Thu Nov 12 16:07:39 2009 +0000 +++ b/contentmgmt/referencedrmagent/RefTestAgent/streamingrefagent/source/server/srasession.cpp Tue Dec 01 11:12:04 2009 +0000 @@ -23,7 +23,9 @@ #include "sraprocessor.h" #include "srautils.h" #include +#ifdef INTERNALLY_ENABLE_UPWARD_DEPENDENCY #include +#endif CSraSession::CSraSession() //constructor @@ -40,8 +42,10 @@ delete iKeyStreamSink; delete iRo; +#ifdef INTERNALLY_ENABLE_UPWARD_DEPENDENCY delete iSdp; delete iSdpDoc; +#endif delete iProcessor; iMutex.Close(); } @@ -327,6 +331,7 @@ @param aMessage Standard server-side handle to message. */ { +#ifdef INTERNALLY_ENABLE_UPWARD_DEPENDENCY TInt len = aMessage.GetDesMaxLengthL(0); HBufC8* des = HBufC8::NewLC(len); TPtr8 ptr(des->Des()); @@ -350,6 +355,10 @@ } StartProcessorL(); aMessage.Complete(KErrNone); +#else + (void) aMessage; + User::Leave(KErrCANoRights); +#endif } @@ -360,6 +369,7 @@ @param aMessage Standard server-side handle to message. */ { +#ifdef INTERNALLY_ENABLE_UPWARD_DEPENDENCY TInt len = aMessage.GetDesMaxLengthL(0); HBufC8* des = HBufC8::NewLC(len); TPtr8 ptr(des->Des()); @@ -374,6 +384,9 @@ CleanupStack::PopAndDestroy(des); aMessage.Complete(KErrNone); +#else + (void) aMessage; +#endif } @@ -383,6 +396,7 @@ and then process that by using the key stream sink. */ { +#ifdef INTERNALLY_ENABLE_UPWARD_DEPENDENCY // Mutex is used to synchronise the agent with the test harness. // A real-life agent should not need to use a mutex object. User::LeaveIfError(iMutex.CreateGlobal(KSraMutexName)); @@ -419,4 +433,5 @@ // Launch the processor iProcessor->StartProcessing(); +#endif } diff -r 7e3f204e6c81 -r f9c11be8c0b3 contentmgmt/referencedrmagent/RefTestAgent/streamingrefagent/source/utils/srautils.cpp --- a/contentmgmt/referencedrmagent/RefTestAgent/streamingrefagent/source/utils/srautils.cpp Thu Nov 12 16:07:39 2009 +0000 +++ b/contentmgmt/referencedrmagent/RefTestAgent/streamingrefagent/source/utils/srautils.cpp Tue Dec 01 11:12:04 2009 +0000 @@ -19,9 +19,11 @@ #include "srautils.h" #include +#ifdef INTERNALLY_ENABLE_UPWARD_DEPENDENCY #include #include #include +#endif HBufC8* ExtractKmsIdLC(const TDesC8& aValue) /** @@ -72,6 +74,8 @@ @return EFalse if the test stream agent fails to recognize the SDP format or is unable to decode the key stream. */ { + TBool supported = EFalse; +#ifdef INTERNALLY_ENABLE_UPWARD_DEPENDENCY //FormatAttributeFields method is not constant. So create a new instance. CSdpMediaField* sdp = aSdpKeyStream.CloneL(); CleanupStack::PushL(sdp); @@ -83,7 +87,6 @@ return EFalse; } - TBool supported = EFalse; HBufC8* kmsid(0); for(TInt i=0; iValue(), aPrivateFolder, aRo); } +#else + (void) aFs; + (void) aSdp; + (void) aRo; + (void) aPrivateFolder; +#endif } EXPORT_C void DoSetSdpMediaFieldL(RFs& aFs, CSdpMediaField*& aSdp, CSraRightsObject*& aRo, const TDesC8& aSdpData, const TDesC& aPrivateFolder) @@ -215,9 +228,17 @@ @param aPrivateFolder The private folder of the agent. */ { +#ifdef INTERNALLY_ENABLE_UPWARD_DEPENDENCY ASSERT(!aSdp); // Decode the received message into an SDP object aSdp = CSdpMediaField::DecodeL(aSdpData,ETrue); // Set the specified RO DoSetRightsObjectL(aFs, *aSdp, aRo, aPrivateFolder); +#else + (void) aFs; + (void) aSdp; + (void) aRo; + (void) aSdpData; + (void) aPrivateFolder; +#endif } diff -r 7e3f204e6c81 -r f9c11be8c0b3 contentmgmt/referencedrmagent/TestAgent/testagentmanager.cpp --- a/contentmgmt/referencedrmagent/TestAgent/testagentmanager.cpp Thu Nov 12 16:07:39 2009 +0000 +++ b/contentmgmt/referencedrmagent/TestAgent/testagentmanager.cpp Tue Dec 01 11:12:04 2009 +0000 @@ -23,8 +23,10 @@ #include "TestAgentFile.h" #include "TestAgentDrmContent.h" #include +#ifdef INTERNALLY_ENABLE_UPWARD_DEPENDENCY #include #include +#endif #include using namespace ContentAccess; @@ -404,7 +406,7 @@ // make leavescan happy, the options are: 1. TRAP leave calls // and ignore the errors. 2. Panic. Both options could potentially // break RTA clients' testcases. Hence just leave it the way it is. -#ifndef SYMBIAN_DISABLE_UPWARD_DEPENDENCY +#ifdef INTERNALLY_ENABLE_UPWARD_DEPENDENCY void CTestAgentManager::PrepareHTTPRequestHeaders(RStringPool& aStringPool, RHTTPHeaders& aRequestHeaders) const { TBuf8 mimeType; diff -r 7e3f204e6c81 -r f9c11be8c0b3 contentmgmt/referencedrmagent/tcaf/source/SupplierStep.cpp --- a/contentmgmt/referencedrmagent/tcaf/source/SupplierStep.cpp Thu Nov 12 16:07:39 2009 +0000 +++ b/contentmgmt/referencedrmagent/tcaf/source/SupplierStep.cpp Tue Dec 01 11:12:04 2009 +0000 @@ -29,7 +29,7 @@ #include "bitset.h" #include -#ifndef SYMBIAN_DISABLE_UPWARD_DEPENDENCY +#ifdef INTERNALLY_ENABLE_UPWARD_DEPENDENCY #include #include #include @@ -602,7 +602,7 @@ return TestStepResult(); } -#ifndef SYMBIAN_DISABLE_UPWARD_DEPENDENCY +#ifdef INTERNALLY_ENABLE_UPWARD_DEPENDENCY /* * Check that applications can retrieve the HTTP request headers diff -r 7e3f204e6c81 -r f9c11be8c0b3 contentmgmt/referencedrmagent/tcaf/source/SupplierStep.h --- a/contentmgmt/referencedrmagent/tcaf/source/SupplierStep.h Thu Nov 12 16:07:39 2009 +0000 +++ b/contentmgmt/referencedrmagent/tcaf/source/SupplierStep.h Tue Dec 01 11:12:04 2009 +0000 @@ -25,7 +25,7 @@ #include "cafstep.h" #include "importfile.h" -#ifndef SYMBIAN_DISABLE_UPWARD_DEPENDENCY +#ifdef INTERNALLY_ENABLE_UPWARD_DEPENDENCY #include #endif @@ -34,7 +34,7 @@ _LIT(KCAFSupplierAsyncStep,"CAFSupplierAsyncStep"); _LIT(KCAFSupplierSerializeStep,"CAFSupplierSerializeStep"); _LIT(KCAFClientOutputSupplierStep,"CAFClientOutputSupplierStep"); -#ifndef SYMBIAN_DISABLE_UPWARD_DEPENDENCY +#ifdef INTERNALLY_ENABLE_UPWARD_DEPENDENCY _LIT(KCAFHTTPRequestHeadersStep,"CAFHTTPRequestHeaders"); #endif class CCAFServer; @@ -105,7 +105,7 @@ }; -#ifndef SYMBIAN_DISABLE_UPWARD_DEPENDENCY +#ifdef INTERNALLY_ENABLE_UPWARD_DEPENDENCY /* * Used to test that an application can retrieve HTTP request headers * @internalComponent Exposure internally diff -r 7e3f204e6c81 -r f9c11be8c0b3 contentmgmt/referencedrmagent/tcaf/source/cafserver.cpp --- a/contentmgmt/referencedrmagent/tcaf/source/cafserver.cpp Thu Nov 12 16:07:39 2009 +0000 +++ b/contentmgmt/referencedrmagent/tcaf/source/cafserver.cpp Tue Dec 01 11:12:04 2009 +0000 @@ -258,7 +258,7 @@ testStep = new CCafRightsInfoStep(*this); else if(aStepName == KCAFStreamablePtrArrayStep) testStep = new CCafStreamablePtrArrayStep(*this); -#ifndef SYMBIAN_DISABLE_UPWARD_DEPENDENCY +#ifdef INTERNALLY_ENABLE_UPWARD_DEPENDENCY else if(aStepName == KCAFHTTPRequestHeadersStep) testStep = new CCAFHTTPRequestHeadersStep(*this); #endif diff -r 7e3f204e6c81 -r f9c11be8c0b3 crypto/weakcryptospi/group/ABLD.BAT --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/crypto/weakcryptospi/group/ABLD.BAT Tue Dec 01 11:12:04 2009 +0000 @@ -0,0 +1,15 @@ +@ECHO OFF + +REM Bldmake-generated batch file - ABLD.BAT +REM ** DO NOT EDIT ** + +perl -S ABLD.PL "\sf\os\security\crypto\weakcryptospi\group\\" %1 %2 %3 %4 %5 %6 %7 %8 %9 +if errorlevel==1 goto CheckPerl +goto End + +:CheckPerl +perl -v >NUL +if errorlevel==1 echo Is Perl, version 5.003_07 or later, installed? +goto End + +:End diff -r 7e3f204e6c81 -r f9c11be8c0b3 crypto/weakcryptospi/group/bld.inf --- a/crypto/weakcryptospi/group/bld.inf Thu Nov 12 16:07:39 2009 +0000 +++ b/crypto/weakcryptospi/group/bld.inf Tue Dec 01 11:12:04 2009 +0000 @@ -82,7 +82,6 @@ ../inc/hash.h SYMBIAN_OS_LAYER_PUBLIC_EXPORT_PATH(hash.h) ../inc/random.h SYMBIAN_OS_LAYER_PUBLIC_EXPORT_PATH(random.h) ../inc/keyidentifierutil.h SYMBIAN_OS_LAYER_PLATFORM_EXPORT_PATH(keyidentifierutil.h) -../inc/randsvr.h SYMBIAN_OS_LAYER_PLATFORM_EXPORT_PATH(randsvr.h) ../inc/randcliserv.h SYMBIAN_OS_LAYER_PLATFORM_EXPORT_PATH(randcliserv.h) ../inc/pkcs5kdf.h SYMBIAN_OS_LAYER_PLATFORM_EXPORT_PATH(pkcs5kdf.h) ../inc/pkcs12kdf.h SYMBIAN_OS_LAYER_PLATFORM_EXPORT_PATH(pkcs12kdf.h) diff -r 7e3f204e6c81 -r f9c11be8c0b3 crypto/weakcryptospi/group/randsvr.mmp --- a/crypto/weakcryptospi/group/randsvr.mmp Thu Nov 12 16:07:39 2009 +0000 +++ b/crypto/weakcryptospi/group/randsvr.mmp Tue Dec 01 11:12:04 2009 +0000 @@ -24,10 +24,10 @@ TARGET randsvr.exe CAPABILITY ProtServ -TARGETTYPE EXEXP +TARGETTYPE EXE UNPAGED -UID 0x1000008d 0x100066dc +UID 0x0 0x100066dc VENDORID 0x70000001 SOURCEPATH ../source/random diff -r 7e3f204e6c81 -r f9c11be8c0b3 crypto/weakcryptospi/inc/randsvr.h --- a/crypto/weakcryptospi/inc/randsvr.h Thu Nov 12 16:07:39 2009 +0000 +++ b/crypto/weakcryptospi/inc/randsvr.h Tue Dec 01 11:12:04 2009 +0000 @@ -19,7 +19,7 @@ /** @file - @publishedPartner + @internalComponent @released */ @@ -33,6 +33,6 @@ #include #endif -IMPORT_C TInt RunRandomServer(TAny* /*someParameters*/); +TInt RunRandomServer(TAny* /*someParameters*/); #endif // __RANDSVR_H__ diff -r 7e3f204e6c81 -r f9c11be8c0b3 crypto/weakcryptospi/source/asymmetric/asymmetric.cpp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/crypto/weakcryptospi/source/asymmetric/asymmetric.cpp Tue Dec 01 11:12:04 2009 +0000 @@ -0,0 +1,124 @@ +/* +* Copyright (c) 2003-2009 Nokia Corporation and/or its subsidiary(-ies). +* All rights reserved. +* This component and the accompanying materials are made available +* under the terms of the License "Eclipse Public License v1.0" +* which accompanies this distribution, and is available +* at the URL "http://www.eclipse.org/legal/epl-v10.html". +* +* Initial Contributors: +* Nokia Corporation - initial contribution. +* +* Contributors: +* +* Description: +* +*/ + + +#include +#include + +/* MCryptoSystem */ + +EXPORT_C MCryptoSystem::MCryptoSystem(void) + { + } + +/* CEncryptor */ + +EXPORT_C CEncryptor::CEncryptor(void) + { + } + +/* CDecryptor */ + +EXPORT_C CDecryptor::CDecryptor(void) + { + } + +/* MSignatureSystem */ + +EXPORT_C MSignatureSystem::MSignatureSystem(void) + { + } + +/* CRSASignature */ + +EXPORT_C CRSASignature* CRSASignature::NewL(RInteger& aS) + { + CRSASignature* self = new(ELeave)CRSASignature(aS); + return self; + } + +EXPORT_C CRSASignature* CRSASignature::NewLC(RInteger& aS) + { + CRSASignature* self = NewL(aS); + CleanupStack::PushL(self); + return self; + } + +EXPORT_C const TInteger& CRSASignature::S(void) const + { + return iS; + } + +EXPORT_C TBool CRSASignature::operator==(const CRSASignature& aSig) const + { + return ( S() == aSig.S() ); + } + +EXPORT_C CRSASignature::~CRSASignature(void) + { + iS.Close(); + } + +EXPORT_C CRSASignature::CRSASignature(RInteger& aS) : iS(aS) + { + } + +/* CDSASignature */ + +EXPORT_C CDSASignature* CDSASignature::NewL(RInteger& aR, RInteger& aS) + { + CDSASignature* self = new(ELeave)CDSASignature(aR, aS); + return self; + } + +EXPORT_C CDSASignature* CDSASignature::NewLC(RInteger& aR, RInteger& aS) + { + CDSASignature* self = NewL(aR, aS); + CleanupStack::PushL(self); + return self; + } + +EXPORT_C const TInteger& CDSASignature::R(void) const + { + return iR; + } + +EXPORT_C const TInteger& CDSASignature::S(void) const + { + return iS; + } + +EXPORT_C TBool CDSASignature::operator==(const CDSASignature& aSig) const + { + return ( R() == aSig.R() && S() == aSig.S() ); + } + +EXPORT_C CDSASignature::~CDSASignature(void) + { + iR.Close(); + iS.Close(); + } + +EXPORT_C CDSASignature::CDSASignature() + { + } + +EXPORT_C CDSASignature::CDSASignature(RInteger& aR, RInteger& aS) + : iR(aR), iS(aS) + { + } + diff -r 7e3f204e6c81 -r f9c11be8c0b3 crypto/weakcryptospi/source/asymmetric/dh.cpp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/crypto/weakcryptospi/source/asymmetric/dh.cpp Tue Dec 01 11:12:04 2009 +0000 @@ -0,0 +1,107 @@ +/* +* Copyright (c) 2003-2009 Nokia Corporation and/or its subsidiary(-ies). +* All rights reserved. +* This component and the accompanying materials are made available +* under the terms of the License "Eclipse Public License v1.0" +* which accompanies this distribution, and is available +* at the URL "http://www.eclipse.org/legal/epl-v10.html". +* +* Initial Contributors: +* Nokia Corporation - initial contribution. +* +* Contributors: +* +* Description: +* +*/ + + +#include +#include +#include "keys.h" +#include "keyconverter.h" +#include "cryptokeyagreementapi.h" +#include + +using namespace CryptoSpi; + +CKeyAgreement* GetKeyAgreementCryptoInterfaceLC(TUid aKeyAgreementAlgoUid, + CKey& aPrivateKey, CCryptoParams* aParams) + { + CKeyAgreement* keyAgreementImpl = 0; + CKeyAgreementFactory::CreateKeyAgreementL(keyAgreementImpl, + aKeyAgreementAlgoUid, aPrivateKey, + aParams); + CleanupStack::PushL(keyAgreementImpl); + return keyAgreementImpl; + } + +EXPORT_C CDH* CDH::NewL(const CDHPrivateKey& aPrivateKey) + { + CDH* self = CDH::NewLC(aPrivateKey); + CleanupStack::Pop(self); + return self; + } + +EXPORT_C CDH* CDH::NewLC(const CDHPrivateKey& aPrivateKey) + { + CDH* self = new (ELeave) CDH(aPrivateKey); + CleanupStack::PushL(self); + return self; + } + +EXPORT_C HBufC8* CDH::AgreeL(const CDHPublicKey& aPublicKey) const + { + /* + * both DH keys (ie our private and their public keys) must use the same N and G parameters + */ + if ((aPublicKey.N() != iPrivateKey.N()) || (aPublicKey.G() != iPrivateKey.G())) + { + User::Leave(KErrArgument); + } + + CKey* privateKey = KeyConverter::CreateKeyL(iPrivateKey); + CleanupStack::PushL(privateKey); + + /* + * package the common parameters N and G into a crypto params array + * we've already checked that both the private and public keys have the + * same N and G so we only need build this array once for both creating + * and calling the interface + */ + CCryptoParams* keyParameters = CCryptoParams::NewLC(); + keyParameters->AddL(aPublicKey.N(), KDhKeyParameterNUid); + keyParameters->AddL(aPublicKey.G(), KDhKeyParameterGUid); + + /* + * get a DH key agreement interface + */ + CKeyAgreement* keyAgreementImpl = GetKeyAgreementCryptoInterfaceLC(KDHAgreementUid, *privateKey, keyParameters); + + /* + * call the api to get a DH agreed key + */ + CKey* publicKey = KeyConverter::CreateKeyL(aPublicKey); + CleanupStack::PushL(publicKey); + + CKey* agreedKey = keyAgreementImpl->AgreeL(*publicKey, keyParameters); + CleanupStack::PushL(agreedKey); + + /* + * extract the agreed key + */ + const TInteger& agreedKeyData = agreedKey->GetBigIntL(KSymmetricKeyParameterUid); + HBufC8 *agreedKeyToReturn = agreedKeyData.BufferLC(); + CleanupStack::Pop(agreedKeyToReturn); + + /* + * cleanup stack - it should contain privateKey, keyAgreementImpl, publicKey, keyParameters and agreedKey + */ + CleanupStack::PopAndDestroy(5, privateKey); + + return agreedKeyToReturn; + } + +EXPORT_C CDH::CDH(const CDHPrivateKey& aPrivateKey) : iPrivateKey(aPrivateKey) + { + } diff -r 7e3f204e6c81 -r f9c11be8c0b3 crypto/weakcryptospi/source/asymmetric/dhkeypairshim.cpp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/crypto/weakcryptospi/source/asymmetric/dhkeypairshim.cpp Tue Dec 01 11:12:04 2009 +0000 @@ -0,0 +1,153 @@ +/* +* Copyright (c) 2007-2009 Nokia Corporation and/or its subsidiary(-ies). +* All rights reserved. +* This component and the accompanying materials are made available +* under the terms of the License "Eclipse Public License v1.0" +* which accompanies this distribution, and is available +* at the URL "http://www.eclipse.org/legal/epl-v10.html". +* +* Initial Contributors: +* Nokia Corporation - initial contribution. +* +* Contributors: +* +* Description: +* +*/ + + +#include "dhkeypairshim.h" +#include +#include "cryptokeypairgeneratorapi.h" +#include "keypair.h" +#include +#include + + +using namespace CryptoSpi; + + +/* CDHKeyPair */ +CDHKeyPairShim* CDHKeyPairShim::NewLC(RInteger& aN, RInteger& aG) + { + CDHKeyPairShim* self = new(ELeave) CDHKeyPairShim(); + CleanupStack::PushL(self); + self->ConstructL(aN, aG); + return self; + } + +CDHKeyPairShim* CDHKeyPairShim::NewLC(RInteger& aN, RInteger& aG, RInteger& ax) + { + CDHKeyPairShim* self = new(ELeave) CDHKeyPairShim(); + CleanupStack::PushL(self); + self->ConstructL(aN, aG, ax); + return self; + } + +CDHKeyPairShim::~CDHKeyPairShim(void) + { + } + +CDHKeyPairShim::CDHKeyPairShim(void) + { + } + +void CDHKeyPairShim::ConstructL(RInteger& aN, RInteger& aG) + { + RInteger x = RInteger::NewL(); + CleanupClosePushL(x); + KeyConstructorL(aN, aG, x, EFalse); + CleanupStack::PopAndDestroy(1, &x); + } + +void CDHKeyPairShim::ConstructL(RInteger& aN, RInteger& aG, RInteger& ax) + { + KeyConstructorL(aN, aG, ax, ETrue); + } + +void CDHKeyPairShim::KeyConstructorL(RInteger& aN, RInteger& aG, RInteger& ax, TBool xIncluded) + { + RInteger& nminus2 = aN; + + /* + * do some sanity checks + */ + --nminus2; + --nminus2; + if( aG < TInteger::Two() || aG > nminus2 ) + { + User::Leave(KErrArgument); + } + + if (xIncluded) + { + if( ax < TInteger::One() || ax > nminus2 ) + { + User::Leave(KErrArgument); + } + } + + /* + *find out how big the key should be - the key must be in the range x | 1 <= x <= n-2 + * nminus2 is the largest the key can be so get the number of bits required to represent that number + */ + const TInt keySize = nminus2.BitCount(); + + // increment aN back to its original value + ++nminus2; + ++nminus2; + + // obtain an RSA key pair generator interface + + CKeyPairGenerator* keyPairGeneratorImpl=NULL; + CKeyPairGeneratorFactory::CreateKeyPairGeneratorL( + keyPairGeneratorImpl, + KDHKeyPairGeneratorUid, + NULL); + CleanupStack::PushL(keyPairGeneratorImpl); + + /* + * put the DH parameters into an array + */ + CCryptoParams* keyParameters = CCryptoParams::NewLC(); + keyParameters->AddL(aN, KDhKeyParameterNUid); + keyParameters->AddL(aG, KDhKeyParameterGUid); + if (xIncluded) + { + // the private key x has been supplied so add it to the params array so the key generator algo can use it + keyParameters->AddL(ax, KDhKeyParameterxUid); + ax.Close(); + } + + /* + * call the api to create a DH key pair + */ + CKeyPair* keyPair = 0; + keyPairGeneratorImpl->GenerateKeyPairL(keySize, *keyParameters, keyPair); + CleanupStack::PushL(keyPair); + + /* + * for compatibility convert the CKeyPair to CDHPrivateKey and CDHPublicKey + */ + + // create new RInteger copies of aN, aG and x so the private key can own them + RInteger NCopy = RInteger::NewL(aN); + CleanupClosePushL(NCopy); + RInteger GCopy = RInteger::NewL(aG); + CleanupClosePushL(GCopy); + RInteger x = RInteger::NewL(keyPair->PrivateKey().GetBigIntL(KDhKeyParameterxUid)); + CleanupClosePushL(x); + iPrivate = CDHPrivateKey::NewL(NCopy, GCopy, x); + CleanupStack::Pop(3, &NCopy); + + // the public key becomes the owner of aN, aG and X + RInteger X = RInteger::NewL(keyPair->PublicKey().GetBigIntL(KDhKeyParameterXUid)); + CleanupClosePushL(X); + iPublic = CDHPublicKey::NewL(aN, aG, X); + CleanupStack::Pop(&X); + + /* + * cleanup stack - it should contain keyPairGeneratorImpl, keyParameters, keyPair, X, NCopy, GCopy and x + */ + CleanupStack::PopAndDestroy(3, keyPairGeneratorImpl); + } diff -r 7e3f204e6c81 -r f9c11be8c0b3 crypto/weakcryptospi/source/asymmetric/dhkeypairshim.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/crypto/weakcryptospi/source/asymmetric/dhkeypairshim.h Tue Dec 01 11:12:04 2009 +0000 @@ -0,0 +1,103 @@ +/* +* Copyright (c) 2006-2009 Nokia Corporation and/or its subsidiary(-ies). +* All rights reserved. +* This component and the accompanying materials are made available +* under the terms of the License "Eclipse Public License v1.0" +* which accompanies this distribution, and is available +* at the URL "http://www.eclipse.org/legal/epl-v10.html". +* +* Initial Contributors: +* Nokia Corporation - initial contribution. +* +* Contributors: +* +* Description: +* +*/ + + +/** + @file + @internalComponent + @released +*/ + +#ifndef __DHKEYPAIRSHIM_H__ +#define __DHKEYPAIRSHIM_H__ + +#include "asymmetrickeys.h" + + +/** +* This class is capable of generating a Diffie-Hellman (DH) public/private key pair using the new crypto SPI interface. +*/ +NONSHARABLE_CLASS(CDHKeyPairShim) : public CDHKeyPair + { +public: + /** + * Creates a new DH key pair from a random large integer, + * and a specified large prime and generator. + * + * The returned pointer is put onto the cleanup stack. + * + * @param aN The DH parameter, n (a large prime) + * @param aG The DH parameter, g (the generator) + * @return A pointer to a CDHKeyPairShim instance + * + * @leave KErrArgument If aG is out of bounds + */ + static CDHKeyPairShim* NewLC(RInteger& aN, RInteger& aG); + + /** + * Creates a new DH key pair from a specified + * large prime, generator, and random large integer. + * + * The returned pointer is put onto the cleanup stack. + * + * @param aN The DH parameter, n (a large prime) + * @param aG The DH parameter, g (the generator) + * @param ax The DH value, x (a random large integer) + * @return A pointer to a CDHKeyPairShim instance + * + * @leave KErrArgument If either aG or ax are out of bounds + */ + static CDHKeyPairShim* NewLC(RInteger& aN, RInteger& aG, RInteger& ax); + + /** The destructor frees all resources owned by the object, prior to its destruction. */ + ~CDHKeyPairShim(void); +protected: + /** Default constructor */ + CDHKeyPairShim(void); + + /** + * Constructor + * + * @param aN The DH parameter, n (a large prime) + * @param aG The DH parameter, g (the generator) + */ + void ConstructL(RInteger& aN, RInteger& aG); + + /** + * Constructor + * + * @param aN The DH parameter, n (a large prime) + * @param aG The DH parameter, g (the generator) + * @param ax The DH value, x (a random large integer) + */ + void ConstructL(RInteger& aN, RInteger& aG, RInteger& ax); + + /** + Creates the DH keypair from the given parameters + @param aN The DH parameter, n (a large prime) + @param aG The DH parameter, g (the generator) + @param ax The DH value, x (a random large integer) + @param xIncluded if the x is included or not. + */ + void KeyConstructorL(RInteger& aN, RInteger& aG, RInteger& ax, TBool xIncluded); + +private: + CDHKeyPairShim(const CDHKeyPairShim&); + CDHKeyPairShim& operator=(const CDHKeyPairShim&); + }; + +#endif // __DHKEYPAIRSHIM_H__ diff -r 7e3f204e6c81 -r f9c11be8c0b3 crypto/weakcryptospi/source/asymmetric/dhkeys.cpp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/crypto/weakcryptospi/source/asymmetric/dhkeys.cpp Tue Dec 01 11:12:04 2009 +0000 @@ -0,0 +1,225 @@ +/* +* Copyright (c) 2003-2009 Nokia Corporation and/or its subsidiary(-ies). +* All rights reserved. +* This component and the accompanying materials are made available +* under the terms of the License "Eclipse Public License v1.0" +* which accompanies this distribution, and is available +* at the URL "http://www.eclipse.org/legal/epl-v10.html". +* +* Initial Contributors: +* Nokia Corporation - initial contribution. +* +* Contributors: +* +* Description: +* +*/ + + +#include +#include "dhkeypairshim.h" + + +/* CDHParameters */ +EXPORT_C const TInteger& CDHParameters::N(void) const + { + return iN; + } + +EXPORT_C const TInteger& CDHParameters::G(void) const + { + return iG; + } + +EXPORT_C CDHParameters::~CDHParameters(void) + { + iN.Close(); + iG.Close(); + } + +EXPORT_C CDHParameters::CDHParameters(RInteger& aN, RInteger& aG) : iN(aN), iG(aG) + { + } + +/* CDHPublicKey */ +EXPORT_C CDHPublicKey* CDHPublicKey::NewL(RInteger& aN, RInteger& aG, + RInteger& aX) + { + CDHPublicKey* self = new(ELeave) CDHPublicKey(aN, aG, aX); + return self; + } + +EXPORT_C CDHPublicKey* CDHPublicKey::NewLC(RInteger& aN, RInteger& aG, + RInteger& aX) + { + CDHPublicKey* self = NewL(aN, aG, aX); + CleanupStack::PushL(self); + return self; + } + +EXPORT_C const TInteger& CDHPublicKey::X(void) const + { + return iX; + } + +EXPORT_C CDHPublicKey::CDHPublicKey(RInteger& aN, RInteger& aG, RInteger& aX) + : CDHParameters(aN, aG), iX(aX) + { + } + +EXPORT_C CDHPublicKey::~CDHPublicKey(void) + { + iX.Close(); + } + +/* CDHPrivateKey */ +EXPORT_C CDHPrivateKey* CDHPrivateKey::NewL(RInteger& aN, RInteger& aG, + RInteger& ax) + { + CDHPrivateKey* self = new(ELeave) CDHPrivateKey(aN, aG, ax); + return self; + } + +EXPORT_C CDHPrivateKey* CDHPrivateKey::NewLC(RInteger& aN, RInteger& aG, + RInteger& ax) + { + CDHPrivateKey* self = NewL(aN, aG, ax); + CleanupStack::PushL(self); + return self; + } + +EXPORT_C const TInteger& CDHPrivateKey::x(void) const + { + return ix; + } + +EXPORT_C CDHPrivateKey::CDHPrivateKey(RInteger& aN, RInteger& aG, RInteger& ax) + : CDHParameters(aN, aG), ix(ax) + { + } + +EXPORT_C CDHPrivateKey::~CDHPrivateKey(void) + { + ix.Close(); + } + +/* CDHKeyPair */ + +EXPORT_C CDHKeyPair* CDHKeyPair::NewL(RInteger& aN, RInteger& aG) + { + CDHKeyPairShim* self = CDHKeyPairShim::NewLC(aN, aG); + CleanupStack::Pop(self); + return self; + } + +EXPORT_C CDHKeyPair* CDHKeyPair::NewLC(RInteger& aN, RInteger& aG) + { + CDHKeyPairShim* self = CDHKeyPairShim::NewLC(aN, aG); + return self; + } + +EXPORT_C CDHKeyPair* CDHKeyPair::NewL(RInteger& aN, RInteger& aG, RInteger& ax) + { + CDHKeyPairShim* self = CDHKeyPairShim::NewLC(aN, aG, ax); + CleanupStack::Pop(self); + return self; + } + +EXPORT_C CDHKeyPair* CDHKeyPair::NewLC(RInteger& aN, RInteger& aG, RInteger& ax) + { + CDHKeyPairShim* self = CDHKeyPairShim::NewLC(aN, aG, ax); + return self; + } + +EXPORT_C const CDHPublicKey& CDHKeyPair::PublicKey(void) const + { + return *iPublic; + } + +EXPORT_C const CDHPrivateKey& CDHKeyPair::PrivateKey(void) const + { + return *iPrivate; + } + +EXPORT_C CDHKeyPair::~CDHKeyPair(void) + { + delete iPublic; + delete iPrivate; + } + +EXPORT_C CDHKeyPair::CDHKeyPair(void) + { + } + +// Excluded from coverage due to shim replacements. +#ifdef _BullseyeCoverage +#pragma suppress_warnings on +#pragma BullseyeCoverage off +#pragma suppress_warnings off +#endif +EXPORT_C void CDHKeyPair::ConstructL(RInteger& aN, RInteger& aG) + { + //declaring a reference just for clarity in NewRandomL statement + RInteger& nminus2 = aN; + --nminus2; + --nminus2; + + //find a random x | 1 <= x <= n-2 + RInteger x = RInteger::NewRandomL(TInteger::One(), nminus2); + CleanupStack::PushL(x); + ++nminus2; + ++nminus2; // reincrement aN + + ConstructL(aN, aG, x); + + CleanupStack::Pop(&x); + } + +EXPORT_C void CDHKeyPair::ConstructL(RInteger& aN, RInteger& aG, RInteger& ax) + { + //declaring a reference just for clarity in if statements + RInteger& nminus2 = aN; + --nminus2; + --nminus2; + + if( aG < TInteger::Two() || aG > nminus2 ) + { + User::Leave(KErrArgument); + } + //In the case of the other ConstructL calling this function this if + //statement is redundant. However, we need to check as this is can be + //called without going through the other api. + if( ax < TInteger::One() || ax > nminus2 ) + { + User::Leave(KErrArgument); + } + + ++nminus2; + ++nminus2; // reincrement aN + + // Calculate X = g^(x) mod n; (note the case sensitivity) + RInteger X = TInteger::ModularExponentiateL(aG, ax, aN); + CleanupStack::PushL(X); + + RInteger n1 = RInteger::NewL(aN); + CleanupStack::PushL(n1); + RInteger g1 = RInteger::NewL(aG); + CleanupStack::PushL(g1); + iPublic = CDHPublicKey::NewL(n1, g1, X); + CleanupStack::Pop(3, &X); // g1, n1, X all owned by iPublic + + iPrivate = CDHPrivateKey::NewL(aN, aG, ax); + } + +// Unused exported and protected members. So, exclude them from coverage. +EXPORT_C CDHParameters::CDHParameters(void) + { + } + +EXPORT_C CDHPrivateKey::CDHPrivateKey(void) + { + } + +EXPORT_C CDHPublicKey::CDHPublicKey(void) + { + } diff -r 7e3f204e6c81 -r f9c11be8c0b3 crypto/weakcryptospi/source/asymmetric/dsakeypairshim.cpp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/crypto/weakcryptospi/source/asymmetric/dsakeypairshim.cpp Tue Dec 01 11:12:04 2009 +0000 @@ -0,0 +1,112 @@ +/* +* Copyright (c) 2007-2009 Nokia Corporation and/or its subsidiary(-ies). +* All rights reserved. +* This component and the accompanying materials are made available +* under the terms of the License "Eclipse Public License v1.0" +* which accompanies this distribution, and is available +* at the URL "http://www.eclipse.org/legal/epl-v10.html". +* +* Initial Contributors: +* Nokia Corporation - initial contribution. +* +* Contributors: +* +* Description: +* +*/ + + +#include "dsakeypairshim.h" +#include "cryptokeypairgeneratorapi.h" +#include "keypair.h" +#include +#include + + +using namespace CryptoSpi; + + +/* CDSAKeyPair */ +CDSAKeyPairShim* CDSAKeyPairShim::NewLC(TUint aKeyBits) + { + CDSAKeyPairShim* self = new(ELeave) CDSAKeyPairShim(); + CleanupStack::PushL(self); + self->ConstructL(aKeyBits); + return self; + } + +CDSAKeyPairShim::~CDSAKeyPairShim() + { + } + +CDSAKeyPairShim::CDSAKeyPairShim() + { + } + +void CDSAKeyPairShim::ConstructL(TUint aKeyBits) + { + CKeyPairGenerator* keyPairGeneratorImpl=NULL; + CKeyPairGeneratorFactory::CreateKeyPairGeneratorL( + keyPairGeneratorImpl, + KDSAKeyPairGeneratorUid, + NULL); + CleanupStack::PushL(keyPairGeneratorImpl); + + + + + // put the DSA parameters into an array + CCryptoParams* keyParameters = CCryptoParams::NewLC(); + + // call the api to create an DSA key pair + CKeyPair* keyPair = 0; + keyPairGeneratorImpl->GenerateKeyPairL(aKeyBits, *keyParameters, keyPair); + CleanupStack::PushL(keyPair); + + //Just to keep BC + if (keyParameters->IsPresent(KDsaKeyGenerationSeedUid)) + { + const TDesC8& seed = keyParameters->GetTDesC8L(KDsaKeyGenerationSeedUid); + TInt counter=keyParameters->GetTIntL(KDsaKeyGenerationCounterUid); + iPrimeCertificate=CDSAPrimeCertificate::NewL(seed, counter); + } + + // + //for compatibility convert the CKeyPair to CDSAPrivateKey and CDSAPublicKey + // + // the public key becomes the owner of P,Q,G,Y + const CKey& publicKey = keyPair->PublicKey(); + RInteger P = RInteger::NewL(publicKey.GetBigIntL(KDsaKeyParameterPUid)); + CleanupClosePushL(P); + + RInteger Q = RInteger::NewL(publicKey.GetBigIntL(KDsaKeyParameterQUid)); + CleanupClosePushL(Q); + + RInteger G = RInteger::NewL(publicKey.GetBigIntL(KDsaKeyParameterGUid)); + CleanupClosePushL(G); + + RInteger Y = RInteger::NewL(publicKey.GetBigIntL(KDsaKeyParameterYUid)); + CleanupClosePushL(Y); + + iPublic = CDSAPublicKey::NewL(P, Q, G, Y); + CleanupStack::Pop(4, &P); //Y,G,Q,P + + // the private key becomes the owner of P1,Q1,G1,X + const CKey& privateKey = keyPair->PrivateKey(); + RInteger P1 = RInteger::NewL(privateKey.GetBigIntL(KDsaKeyParameterPUid)); + CleanupClosePushL(P1); + + RInteger Q1 = RInteger::NewL(privateKey.GetBigIntL(KDsaKeyParameterQUid)); + CleanupClosePushL(Q1); + + RInteger G1 = RInteger::NewL(privateKey.GetBigIntL(KDsaKeyParameterGUid)); + CleanupClosePushL(G1); + + RInteger X = RInteger::NewL(privateKey.GetBigIntL(KDsaKeyParameterXUid)); + CleanupClosePushL(X); + + iPrivate = CDSAPrivateKey::NewL(P1, Q1, G1, X); + CleanupStack::Pop(4, &P1); //X,G1,Q1,P1 + + CleanupStack::PopAndDestroy(3, keyPairGeneratorImpl); // keyPair, keyParameters, keyPairGeneratorImpl + } diff -r 7e3f204e6c81 -r f9c11be8c0b3 crypto/weakcryptospi/source/asymmetric/dsakeypairshim.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/crypto/weakcryptospi/source/asymmetric/dsakeypairshim.h Tue Dec 01 11:12:04 2009 +0000 @@ -0,0 +1,58 @@ +/* +* Copyright (c) 2007-2009 Nokia Corporation and/or its subsidiary(-ies). +* All rights reserved. +* This component and the accompanying materials are made available +* under the terms of the License "Eclipse Public License v1.0" +* which accompanies this distribution, and is available +* at the URL "http://www.eclipse.org/legal/epl-v10.html". +* +* Initial Contributors: +* Nokia Corporation - initial contribution. +* +* Contributors: +* +* Description: +* +*/ + + +/** + @file + @internalComponent + @released +*/ + +#ifndef __DSAKEYPAIRSHIM_H__ +#define __DSAKEYPAIRSHIM_H__ + +#include "asymmetrickeys.h" + +/** +* This class generates an DSA public/private key pair via CryptoSPI +*/ + +NONSHARABLE_CLASS(CDSAKeyPairShim) : public CDSAKeyPair + { +public: + /** + * Creates a new DSA key pair + */ + static CDSAKeyPairShim* NewLC(TUint aKeyBits); + + ~CDSAKeyPairShim(void); + +protected: + /** Constructor */ + CDSAKeyPairShim(void); + + /** + * 2nd stage constructor + */ + void ConstructL(TUint aKeyBits); + +private: + CDSAKeyPairShim(const CDSAKeyPairShim&); + CDSAKeyPairShim& operator=(const CDSAKeyPairShim&); + }; + +#endif // __DSAKEYPAIRSHIM_H__ diff -r 7e3f204e6c81 -r f9c11be8c0b3 crypto/weakcryptospi/source/asymmetric/dsakeys.cpp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/crypto/weakcryptospi/source/asymmetric/dsakeys.cpp Tue Dec 01 11:12:04 2009 +0000 @@ -0,0 +1,403 @@ +/* +* Copyright (c) 2003-2009 Nokia Corporation and/or its subsidiary(-ies). +* All rights reserved. +* This component and the accompanying materials are made available +* under the terms of the License "Eclipse Public License v1.0" +* which accompanies this distribution, and is available +* at the URL "http://www.eclipse.org/legal/epl-v10.html". +* +* Initial Contributors: +* Nokia Corporation - initial contribution. +* +* Contributors: +* +* Description: +* +*/ + + +#include +#include +#include +#include +#include "../common/inlines.h" +#include "../bigint/mont.h" +#include "dsakeypairshim.h" + +const TUint SHASIZE = 20; +const TUint KMinPrimeLength = 512; +const TUint KMaxPrimeLength = 1024; +const TUint KPrimeLengthMultiple = 64; + +/* CDSAParameters */ + +EXPORT_C const TInteger& CDSAParameters::P(void) const + { + return iP; + } + +EXPORT_C const TInteger& CDSAParameters::Q(void) const + { + return iQ; + } + +EXPORT_C const TInteger& CDSAParameters::G(void) const + { + return iG; + } + +EXPORT_C CDSAParameters::~CDSAParameters(void) + { + iP.Close(); + iQ.Close(); + iG.Close(); + } + +EXPORT_C CDSAParameters* CDSAParameters::NewL(RInteger& aP, RInteger& aQ, + RInteger& aG) + { + CDSAParameters* me = new (ELeave) CDSAParameters(aP, aQ, aG); + return (me); + } + +EXPORT_C TBool CDSAParameters::ValidatePrimesL(const CDSAPrimeCertificate& aCert) + const + { + TBool result = EFalse; + RInteger p; + RInteger q; + //Regenerate primes using aCert's seed and counter + TUint counter = aCert.Counter(); + if(!CDSAParameters::GeneratePrimesL(aCert.Seed(), counter, p, + P().BitCount(), q, ETrue)) + { + return result; + } + //this doesn't leave, no need to push p and q + if(p == P() && q == Q() && counter == aCert.Counter()) + { + result = ETrue; + } + p.Close(); + q.Close(); + return result; + } + +EXPORT_C TBool CDSAParameters::ValidPrimeLength(TUint aPrimeBits) + { + return (aPrimeBits >= KMinPrimeLength && + aPrimeBits <= KMaxPrimeLength && + aPrimeBits % KPrimeLengthMultiple == 0); + } + +EXPORT_C CDSAParameters::CDSAParameters(RInteger& aP, RInteger& aQ, + RInteger& aG) : iP(aP), iQ(aQ), iG(aG) + { + } + +EXPORT_C CDSAParameters::CDSAParameters(void) + { + } + +TBool CDSAParameters::GeneratePrimesL(const TDesC8& aSeed, TUint& aCounter, + RInteger& aP, TUint aL, RInteger& aQ, TBool aUseInputCounter) + { + //This follows the steps in FIPS 186-2 + //See DSS Appendix 2.2 + //Note. Step 1 is performed prior to calling GeneratePrimesL, so that this + //routine can be used for both generation and validation. + //Step 1. Choose an arbitrary sequence of at least 160 bits and call it + //SEED. Let g be the length of SEED in bits. + + if(!CDSAParameters::ValidPrimeLength(aL)) + { + User::Leave(KErrNotSupported); + } + + CSHA1* sha1 = CSHA1::NewL(); + CleanupStack::PushL(sha1); + + HBufC8* seedBuf = aSeed.AllocLC(); + TPtr8 seed = seedBuf->Des(); + TUint gBytes = aSeed.Size(); + //Note that the DSS's g = BytesToBits(gBytes) ie. the number of random bits + //in the seed. + //This function has made the assumption (for ease of computation) that g%8 + //is 0. Ie the seed is a whole number of random bytes. + TBuf8 U; + TBuf8 temp; + const TUint n = (aL-1)/160; + const TUint b = (aL-1)%160; + HBufC8* Wbuf = HBufC8::NewMaxLC((n+1) * SHASIZE); + TUint8* W = const_cast(Wbuf->Ptr()); + + U.Copy(sha1->Final(seed)); + + //Step 2. U = SHA-1[SEED] XOR SHA-1[(SEED+1) mod 2^g] + for(TInt i=gBytes - 1, carry=ETrue; i>=0 && carry; i--) + { + //!++(TUint) adds one to the current word which if it overflows to zero + //sets carry to 1 thus letting the loop continue. It's a poor man's + //multi-word addition. Swift eh? + carry = !++(seed[i]); + } + + temp.Copy(sha1->Final(seed)); + XorBuf(const_cast(U.Ptr()), temp.Ptr(), SHASIZE); + + //Step 3. Form q from U by setting the most significant bit (2^159) + //and the least significant bit to 1. + U[0] |= 0x80; + U[SHASIZE-1] |= 1; + + aQ = RInteger::NewL(U); + CleanupStack::PushL(aQ); + + //Step 4. Use a robust primality testing algo to test if q is prime + //The robust part is the calling codes problem. This will use whatever + //random number generator you set for the thread. To attempt FIPS 186-2 + //compliance, set a FIPS 186-2 compliant RNG. + if( !aQ.IsPrimeL() ) + { + //Step 5. If not exit and get a new seed + CleanupStack::PopAndDestroy(&aQ); + CleanupStack::PopAndDestroy(Wbuf); + CleanupStack::PopAndDestroy(seedBuf); + CleanupStack::PopAndDestroy(sha1); + return EFalse; + } + + TUint counterEnd = aUseInputCounter ? aCounter+1 : 4096; + + //Step 6. Let counter = 0 and offset = 2 + //Note 1. that the DSS speaks of SEED + offset + k because they always + //refer to a constant SEED. We update our seed as we go so the offset + //variable has already been added to seed in the previous iterations. + //Note 2. We've already added 1 to our seed, so the first time through this + //the offset in DSS speak will be 2. + for(TUint counter=0; counter < counterEnd; counter++) + { + //Step 7. For k=0, ..., n let + // Vk = SHA-1[(SEED + offset + k) mod 2^g] + //I'm storing the Vk's inside of a big W buffer. + for(TUint k=0; k<=n; k++) + { + for(TInt i=gBytes-1, carry=ETrue; i>=0 && carry; i--) + { + carry = !++(seed[i]); + } + if(!aUseInputCounter || counter == aCounter) + { + TPtr8 Wptr(W+(n-k)*SHASIZE, gBytes); + Wptr.Copy(sha1->Final(seed)); + } + } + if(!aUseInputCounter || counter == aCounter) + { + //Step 8. Let W be the integer... and let X = W + 2^(L-1) + const_cast((*Wbuf)[SHASIZE - 1 - b/8]) |= 0x80; + TPtr8 Wptr(W + SHASIZE - 1 - b/8, aL/8, aL/8); + RInteger X = RInteger::NewL(Wptr); + CleanupStack::PushL(X); + //Step 9. Let c = X mod 2q and set p = X - (c-1) + RInteger twoQ = aQ.TimesL(TInteger::Two()); + CleanupStack::PushL(twoQ); + RInteger c = X.ModuloL(twoQ); + CleanupStack::PushL(c); + --c; + aP = X.MinusL(c); + CleanupStack::PopAndDestroy(3, &X); //twoQ, c, X + CleanupStack::PushL(aP); + + //Step 10 and 11: if p >= 2^(L-1) and p is prime + if( aP.Bit(aL-1) && aP.IsPrimeL() ) + { + aCounter = counter; + CleanupStack::Pop(&aP); + CleanupStack::Pop(&aQ); + CleanupStack::PopAndDestroy(Wbuf); + CleanupStack::PopAndDestroy(seedBuf); + CleanupStack::PopAndDestroy(sha1); + return ETrue; + } + CleanupStack::PopAndDestroy(&aP); + } + } + CleanupStack::PopAndDestroy(&aQ); + CleanupStack::PopAndDestroy(Wbuf); + CleanupStack::PopAndDestroy(seedBuf); + CleanupStack::PopAndDestroy(sha1); + return EFalse; + } + +/* CDSAPublicKey */ + +EXPORT_C CDSAPublicKey* CDSAPublicKey::NewL(RInteger& aP, RInteger& aQ, + RInteger& aG, RInteger& aY) + { + CDSAPublicKey* self = new(ELeave) CDSAPublicKey(aP, aQ, aG, aY); + return self; + } + +EXPORT_C CDSAPublicKey* CDSAPublicKey::NewLC(RInteger& aP, RInteger& aQ, + RInteger& aG, RInteger& aY) + { + CDSAPublicKey* self = NewL(aP, aQ, aG, aY); + CleanupStack::PushL(self); + return self; + } + +EXPORT_C const TInteger& CDSAPublicKey::Y(void) const + { + return iY; + } + +EXPORT_C CDSAPublicKey::CDSAPublicKey(void) + { + } + +EXPORT_C CDSAPublicKey::CDSAPublicKey(RInteger& aP, RInteger& aQ, RInteger& aG, + RInteger& aY) : CDSAParameters(aP, aQ, aG), iY(aY) + { + } + +EXPORT_C CDSAPublicKey::~CDSAPublicKey(void) + { + iY.Close(); + } + +/* CDSAPrivateKey */ + +EXPORT_C CDSAPrivateKey* CDSAPrivateKey::NewL(RInteger& aP, RInteger& aQ, + RInteger& aG, RInteger& aX) + { + CDSAPrivateKey* self = new(ELeave) CDSAPrivateKey(aP, aQ, aG, aX); + return self; + } + +EXPORT_C CDSAPrivateKey* CDSAPrivateKey::NewLC(RInteger& aP, RInteger& aQ, + RInteger& aG, RInteger& aX) + { + CDSAPrivateKey* self = NewL(aP, aQ, aG, aX); + CleanupStack::PushL(self); + return self; + } + +EXPORT_C const TInteger& CDSAPrivateKey::X(void) const + { + return iX; + } + +EXPORT_C CDSAPrivateKey::CDSAPrivateKey(RInteger& aP, RInteger& aQ, RInteger& aG, + RInteger& aX) : CDSAParameters(aP, aQ, aG), iX(aX) + { + } + +EXPORT_C CDSAPrivateKey::~CDSAPrivateKey(void) + { + iX.Close(); + } + +/* CDSAKeyPair */ + +EXPORT_C CDSAKeyPair* CDSAKeyPair::NewL(TUint aKeyBits) + { + CDSAKeyPairShim* self = CDSAKeyPairShim::NewLC(aKeyBits); + CleanupStack::Pop(); + return self; + } + +EXPORT_C CDSAKeyPair* CDSAKeyPair::NewLC(TUint aKeyBits) + { + CDSAKeyPairShim* self = CDSAKeyPairShim::NewLC(aKeyBits); + return self; + } + +EXPORT_C const CDSAPublicKey& CDSAKeyPair::PublicKey(void) const + { + return *iPublic; + } + +EXPORT_C const CDSAPrivateKey& CDSAKeyPair::PrivateKey(void) const + { + return *iPrivate; + } + +EXPORT_C CDSAKeyPair::~CDSAKeyPair(void) + { + delete iPublic; + delete iPrivate; + delete iPrimeCertificate; + } + +EXPORT_C CDSAKeyPair::CDSAKeyPair(void) + { + } + +EXPORT_C const CDSAPrimeCertificate& CDSAKeyPair::PrimeCertificate(void) const + { + return *iPrimeCertificate; + } + +/* CDSAPrimeCertificate */ + +EXPORT_C CDSAPrimeCertificate* CDSAPrimeCertificate::NewL(const TDesC8& aSeed, + TUint aCounter) + { + CDSAPrimeCertificate* self = NewLC(aSeed, aCounter); + CleanupStack::Pop(); + return self; + } + +EXPORT_C CDSAPrimeCertificate* CDSAPrimeCertificate::NewLC(const TDesC8& aSeed, + TUint aCounter) + { + CDSAPrimeCertificate* self = new(ELeave) CDSAPrimeCertificate(aCounter); + CleanupStack::PushL(self); + self->ConstructL(aSeed); + return self; + } + +EXPORT_C const TDesC8& CDSAPrimeCertificate::Seed(void) const + { + return *iSeed; + } + +EXPORT_C TUint CDSAPrimeCertificate::Counter(void) const + { + return iCounter; + } + +EXPORT_C CDSAPrimeCertificate::~CDSAPrimeCertificate(void) + { + delete const_cast(iSeed); + } + +void CDSAPrimeCertificate::ConstructL(const TDesC8& aSeed) + { + iSeed = aSeed.AllocL(); + } + +EXPORT_C CDSAPrimeCertificate::CDSAPrimeCertificate(TUint aCounter) + : iCounter(aCounter) + { + } + +// Over taken by shim version. so, exclude it from coverage. +#ifdef _BullseyeCoverage +#pragma suppress_warnings on +#pragma BullseyeCoverage off +#pragma suppress_warnings off +#endif +void CDSAKeyPair::ConstructL(TUint /*aPBits*/) + { + } + +// Unused exported and protected method can be excluded from coverage. +EXPORT_C CDSAPrimeCertificate::CDSAPrimeCertificate(void) + { + } + +EXPORT_C CDSAPrivateKey::CDSAPrivateKey(void) + { + } diff -r 7e3f204e6c81 -r f9c11be8c0b3 crypto/weakcryptospi/source/asymmetric/dsashim.cpp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/crypto/weakcryptospi/source/asymmetric/dsashim.cpp Tue Dec 01 11:12:04 2009 +0000 @@ -0,0 +1,182 @@ +/* +* Copyright (c) 2007-2009 Nokia Corporation and/or its subsidiary(-ies). +* All rights reserved. +* This component and the accompanying materials are made available +* under the terms of the License "Eclipse Public License v1.0" +* which accompanies this distribution, and is available +* at the URL "http://www.eclipse.org/legal/epl-v10.html". +* +* Initial Contributors: +* Nokia Corporation - initial contribution. +* +* Contributors: +* +* Description: +* +*/ + + +#include "dsashim.h" +#include "cryptosignatureapi.h" +#include +#include "keys.h" +#include "keyconverter.h" + +#include "../common/inlines.h" + + +using namespace CryptoSpi; + +// CDsaSignerShim //////////////////////////////////////////////////////// + +CDsaSignerShim* CDsaSignerShim::NewL(const CDSAPrivateKey& aKey) + { + CDsaSignerShim* self = CDsaSignerShim::NewLC(aKey); + CleanupStack::Pop(self); + return self; + } + +CDsaSignerShim* CDsaSignerShim::NewLC(const CDSAPrivateKey& aKey) + { + CDsaSignerShim* self = new (ELeave) CDsaSignerShim(aKey); + CleanupStack::PushL(self); + self->ConstructL(aKey); + return self; + } + +CDsaSignerShim::CDsaSignerShim(const CDSAPrivateKey& aKey) + : CDSASigner(aKey) + { + } + +CDsaSignerShim::~CDsaSignerShim() + { + delete iSignerImpl; + delete iKey; + } + +void CDsaSignerShim::ConstructL(const CDSAPrivateKey& aKey) + { + iKey = KeyConverter::CreateKeyL(aKey); + CSignatureFactory::CreateSignerL( + iSignerImpl, + KDsaSignerUid, + *iKey, + KPaddingModeNoneUid, + NULL); + } + + +CDSASignature* CDsaSignerShim::SignL(const TDesC8& aInput) const + { + //Sign the input data + CCryptoParams* signature = CCryptoParams::NewLC(); + iSignerImpl->SignL(aInput, *signature); + + //Retrieve the R&S in DSA signature from the array + const TInteger& cR=signature->GetBigIntL(KDsaSignatureParameterRUid); + const TInteger& cS=signature->GetBigIntL(KDsaSignatureParameterSUid); + + + //Make copies of the DSA signature + RInteger r=RInteger::NewL(cR); + CleanupClosePushL(r); + RInteger s=RInteger::NewL(cS); + CleanupClosePushL(s); + + //Create the DSA signature object, the ownership of r&s is transfered to dsaSig + CDSASignature* dsaSig=CDSASignature::NewL(r, s); + + //Cleanup + CleanupStack::Pop(2, &r); + CleanupStack::PopAndDestroy(signature); + + return dsaSig; + } + +TInt CDsaSignerShim::MaxInputLength() const + { + TInt maxInputLength=0; + TRAPD(err, maxInputLength=iSignerImpl->GetMaximumInputLengthL()) + if (err==KErrNone) + { + return maxInputLength; + } + else + { + return err; + } + } + + +// CDsaVerifierShim //////////////////////////////////////////////////////// +CDsaVerifierShim* CDsaVerifierShim::NewL(const CDSAPublicKey& aKey) + { + CDsaVerifierShim* self = CDsaVerifierShim::NewLC(aKey); + CleanupStack::Pop(self); + return self; + } + +CDsaVerifierShim* CDsaVerifierShim::NewLC(const CDSAPublicKey& aKey) + { + CDsaVerifierShim* self = new (ELeave) CDsaVerifierShim(aKey); + CleanupStack::PushL(self); + self->ConstructL(aKey); + return self; + } + +CDsaVerifierShim::CDsaVerifierShim(const CDSAPublicKey& aKey) + : CDSAVerifier(aKey) + { + } + +CDsaVerifierShim::~CDsaVerifierShim() + { + delete iVerifierImpl; + delete iKey; + } + +void CDsaVerifierShim::ConstructL(const CDSAPublicKey& aKey) + { + iKey = KeyConverter::CreateKeyL(aKey); + CSignatureFactory::CreateVerifierL( + iVerifierImpl, + KDsaVerifierUid, + *iKey, + KPaddingModeNoneUid, + NULL); + + } + +TBool CDsaVerifierShim::VerifyL(const TDesC8& aInput, const CDSASignature& aSignature) const + { + //create the array format dsa signature for the new crypto spi + CCryptoParams* dsaSig = CCryptoParams::NewLC(); + + dsaSig->AddL(aSignature.R(), KDsaSignatureParameterRUid); + dsaSig->AddL(aSignature.S(), KDsaSignatureParameterSUid); + + //pass the signature and input to the new crypto spi to be verified + TBool verificationResult=EFalse; + iVerifierImpl->VerifyL(aInput, *dsaSig, verificationResult); + + //Cleanup the array + CleanupStack::PopAndDestroy(dsaSig); + + return verificationResult; + } + +TInt CDsaVerifierShim::MaxInputLength() const + { + TInt maxInputLength=0; + TRAPD(err, maxInputLength=iVerifierImpl->GetMaximumInputLengthL()) + if (err==KErrNone) + { + return maxInputLength; + } + else + { + return err; + } + } + diff -r 7e3f204e6c81 -r f9c11be8c0b3 crypto/weakcryptospi/source/asymmetric/dsashim.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/crypto/weakcryptospi/source/asymmetric/dsashim.h Tue Dec 01 11:12:04 2009 +0000 @@ -0,0 +1,138 @@ +/* +* Copyright (c) 2006-2009 Nokia Corporation and/or its subsidiary(-ies). +* All rights reserved. +* This component and the accompanying materials are made available +* under the terms of the License "Eclipse Public License v1.0" +* which accompanies this distribution, and is available +* at the URL "http://www.eclipse.org/legal/epl-v10.html". +* +* Initial Contributors: +* Nokia Corporation - initial contribution. +* +* Contributors: +* +* Description: +* DSA shim classes definition +* +*/ + + +/** + @file + @internalComponent + @released +*/ + +#ifndef __DSASHIM_H__ +#define __DSASHIM_H__ + +#include + +namespace CryptoSpi + { + class CSigner; + class CVerifier; + class CKey; + } + +NONSHARABLE_CLASS(CDsaSignerShim) : public CDSASigner +{ +public: + /** + Creates an CDsaSignerShim object which has the same interface + as CDSASigner but delegates all work to a Crypto SPI plug-in. + + @param aKey The signing key + @return A pointer to a CDsaSignerShim instance + */ + static CDsaSignerShim* NewL(const CDSAPrivateKey& aKey); + + /** + Creates an CDsaSignerShim object which has the same interface + as CDSASigner but delegates all work to a Crypto SPI plug-in. + + A pointer to the new object is placed on the cleanup stack + + @param aKey The signing key + @return A pointer to a CDsaSignerShim instance + */ + static CDsaSignerShim* NewLC(const CDSAPrivateKey& aKey); + + /** + Digitally signs the specified input message + Note that in order to be interoperable and compliant with the DSS, aInput + must be the result of a SHA-1 hash. + + @param aInput A SHA-1 hash of the message to sign + @return A pointer to a new CSignature object + @panic ECryptoPanicInputTooLarge If aInput is larger than MaxInputLength(), + which is likely to happen if the caller + has passed in something that has not been hashed. + */ + virtual CDSASignature* SignL(const TDesC8& aInput) const; + + //From MSignatureSystem + virtual TInt MaxInputLength() const; + + /// Destructor + ~CDsaSignerShim(); + +private: + /// Constructor + CDsaSignerShim(const CDSAPrivateKey& aKey); + void ConstructL(const CDSAPrivateKey& aKey); + +private: + /// SPI delegate + CryptoSpi::CSigner* iSignerImpl; + + /// SPI requires all key to passed as key-objects + CryptoSpi::CKey* iKey; +}; + +NONSHARABLE_CLASS(CDsaVerifierShim) : public CDSAVerifier +{ +public: + /** + Creates an CDsaVerifierShim object which has the same interface + as CDSAVerifier but delegates all work to a Crypto SPI plug-in. + + @param aKey The verification key + @return A pointer to a CDsaVerifierShim instance + */ + static CDsaVerifierShim* NewL(const CDSAPublicKey& aKey); + + /** + Creates an CDsaVerifierShim object which has the same interface + as CDSAVerifier but delegates all work to a Crypto SPI plug-in. + + A pointer to the new object is placed on the cleanup stack + + @param aKey The verification key + @return A pointer to a CDsaVerifierShim instance + */ + static CDsaVerifierShim* NewLC(const CDSAPublicKey& aKey); + + //From CVerifier + virtual TBool VerifyL(const TDesC8& aInput, const CDSASignature& aSignature) const; + + //From MSignatureSystem + virtual TInt MaxInputLength() const; + + // Destructor + ~CDsaVerifierShim(); + +private: + // Constructor + CDsaVerifierShim(const CDSAPublicKey& aKey); + void ConstructL(const CDSAPublicKey& aKey); + +private: + /// SPI delegate + CryptoSpi::CVerifier* iVerifierImpl; + + /// SPI requires all key to passed as key-objects + CryptoSpi::CKey* iKey; +}; + +#endif // __DSASHIM_H__ diff -r 7e3f204e6c81 -r f9c11be8c0b3 crypto/weakcryptospi/source/asymmetric/dsasigner.cpp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/crypto/weakcryptospi/source/asymmetric/dsasigner.cpp Tue Dec 01 11:12:04 2009 +0000 @@ -0,0 +1,54 @@ +/* +* Copyright (c) 2003-2009 Nokia Corporation and/or its subsidiary(-ies). +* All rights reserved. +* This component and the accompanying materials are made available +* under the terms of the License "Eclipse Public License v1.0" +* which accompanies this distribution, and is available +* at the URL "http://www.eclipse.org/legal/epl-v10.html". +* +* Initial Contributors: +* Nokia Corporation - initial contribution. +* +* Contributors: +* +* Description: +* +*/ + + +#include "dsashim.h" + +EXPORT_C CDSASigner* CDSASigner::NewL(const CDSAPrivateKey& aKey) + { + return CDsaSignerShim::NewL(aKey); + } + +EXPORT_C CDSASigner* CDSASigner::NewLC(const CDSAPrivateKey& aKey) + { + return CDsaSignerShim::NewLC(aKey); + } + +CDSASigner::CDSASigner(const CDSAPrivateKey& aKey) + : iPrivateKey(aKey) + { + } + +// All these methods have been replaced by the shim +#ifdef _BullseyeCoverage +#pragma suppress_warnings on +#pragma BullseyeCoverage off +#pragma suppress_warnings off +#endif +TInt CDSASigner::MaxInputLength(void) const + { + // Method replaced by shim + ASSERT(EFalse); + return 0; + } + +CDSASignature* CDSASigner::SignL(const TDesC8& /*aInput*/) const + { + // Method replaced by shim + User::Leave(KErrNotSupported); + return 0; + } diff -r 7e3f204e6c81 -r f9c11be8c0b3 crypto/weakcryptospi/source/asymmetric/dsaverifier.cpp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/crypto/weakcryptospi/source/asymmetric/dsaverifier.cpp Tue Dec 01 11:12:04 2009 +0000 @@ -0,0 +1,54 @@ +/* +* Copyright (c) 2003-2009 Nokia Corporation and/or its subsidiary(-ies). +* All rights reserved. +* This component and the accompanying materials are made available +* under the terms of the License "Eclipse Public License v1.0" +* which accompanies this distribution, and is available +* at the URL "http://www.eclipse.org/legal/epl-v10.html". +* +* Initial Contributors: +* Nokia Corporation - initial contribution. +* +* Contributors: +* +* Description: +* +*/ + + +#include "dsashim.h" + +EXPORT_C CDSAVerifier* CDSAVerifier::NewL(const CDSAPublicKey& aKey) + { + return CDsaVerifierShim::NewL(aKey); + } + +EXPORT_C CDSAVerifier* CDSAVerifier::NewLC(const CDSAPublicKey& aKey) + { + return CDsaVerifierShim::NewLC(aKey); + } + +CDSAVerifier::CDSAVerifier(const CDSAPublicKey& aKey) + : iPublicKey(aKey) + { + } + +// All these methods have been replaced by the shim +#ifdef _BullseyeCoverage +#pragma suppress_warnings on +#pragma BullseyeCoverage off +#pragma suppress_warnings off +#endif +TInt CDSAVerifier::MaxInputLength(void) const + { + // Method replaced by shim + ASSERT(EFalse); + return 0; + } + +TBool CDSAVerifier::VerifyL(const TDesC8& /*aInput*/, const CDSASignature& /*aSignature*/) const + { + // Method replaced by shim + User::Leave(KErrNotSupported); + return EFalse; + } diff -r 7e3f204e6c81 -r f9c11be8c0b3 crypto/weakcryptospi/source/asymmetric/rsadecryptor.cpp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/crypto/weakcryptospi/source/asymmetric/rsadecryptor.cpp Tue Dec 01 11:12:04 2009 +0000 @@ -0,0 +1,75 @@ +/* +* Copyright (c) 2003-2009 Nokia Corporation and/or its subsidiary(-ies). +* All rights reserved. +* This component and the accompanying materials are made available +* under the terms of the License "Eclipse Public License v1.0" +* which accompanies this distribution, and is available +* at the URL "http://www.eclipse.org/legal/epl-v10.html". +* +* Initial Contributors: +* Nokia Corporation - initial contribution. +* +* Contributors: +* +* Description: +* +*/ + + +#include "rsashim.h" + + +/* CRSAPKCS1v15Decryptor */ + +EXPORT_C CRSAPKCS1v15Decryptor* CRSAPKCS1v15Decryptor::NewL( + const CRSAPrivateKey& aKey) + { + return CRSAPKCS1v15DecryptorShim::NewL(aKey); + } + +EXPORT_C CRSAPKCS1v15Decryptor* CRSAPKCS1v15Decryptor::NewLC( + const CRSAPrivateKey& aKey) + { + return CRSAPKCS1v15DecryptorShim::NewLC(aKey); + } + +CRSAPKCS1v15Decryptor::CRSAPKCS1v15Decryptor(const CRSAPrivateKey& aKey) + : iPrivateKey(aKey) + { + } + +CRSAPKCS1v15Decryptor::~CRSAPKCS1v15Decryptor(void) + { + } + +// All these methods have been replaced by the shim +#ifdef _BullseyeCoverage +#pragma suppress_warnings on +#pragma BullseyeCoverage off +#pragma suppress_warnings off +#endif +TInt CRSAPKCS1v15Decryptor::MaxInputLength(void) const + { + // Method replaced by shim + ASSERT(EFalse); + return 0; + } + +TInt CRSAPKCS1v15Decryptor::MaxOutputLength(void) const + { + // Method replaced by shim + ASSERT(EFalse); + return 0; + } + +void CRSAPKCS1v15Decryptor::DecryptL(const TDesC8& /*aInput*/, TDes8& /*aOutput*/) const + { + // Method replaced by shim + ASSERT(EFalse); + } + +void CRSAPKCS1v15Decryptor::ConstructL(void) + { + // Method replaced by shim + ASSERT(EFalse); + } diff -r 7e3f204e6c81 -r f9c11be8c0b3 crypto/weakcryptospi/source/asymmetric/rsaencryptor.cpp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/crypto/weakcryptospi/source/asymmetric/rsaencryptor.cpp Tue Dec 01 11:12:04 2009 +0000 @@ -0,0 +1,72 @@ +/* +* Copyright (c) 2003-2009 Nokia Corporation and/or its subsidiary(-ies). +* All rights reserved. +* This component and the accompanying materials are made available +* under the terms of the License "Eclipse Public License v1.0" +* which accompanies this distribution, and is available +* at the URL "http://www.eclipse.org/legal/epl-v10.html". +* +* Initial Contributors: +* Nokia Corporation - initial contribution. +* +* Contributors: +* +* Description: +* +*/ + + +#include "rsashim.h" + +EXPORT_C CRSAPKCS1v15Encryptor* CRSAPKCS1v15Encryptor::NewL( + const CRSAPublicKey& aKey) + { + return CRSAPKCS1v15EncryptorShim::NewL(aKey); + } + +EXPORT_C CRSAPKCS1v15Encryptor* CRSAPKCS1v15Encryptor::NewLC( + const CRSAPublicKey& aKey) + { + return CRSAPKCS1v15EncryptorShim::NewLC(aKey); + } + +CRSAPKCS1v15Encryptor::CRSAPKCS1v15Encryptor(const CRSAPublicKey& aKey) + : iPublicKey(aKey) + { + } + +CRSAPKCS1v15Encryptor::~CRSAPKCS1v15Encryptor(void) + { + } + +// All these methods have been replaced by the shim +#ifdef _BullseyeCoverage +#pragma suppress_warnings on +#pragma BullseyeCoverage off +#pragma suppress_warnings off +#endif +TInt CRSAPKCS1v15Encryptor::MaxInputLength(void) const + { + // Method replaced by shim + ASSERT(EFalse); + return 0; + } + +TInt CRSAPKCS1v15Encryptor::MaxOutputLength() const + { + // Method replaced by shim + ASSERT(EFalse); + return 0; + } + +void CRSAPKCS1v15Encryptor::EncryptL(const TDesC8& /*aInput*/, TDes8& /*aOutput*/) const + { + // Method replaced by shim + ASSERT(EFalse); + } + +void CRSAPKCS1v15Encryptor::ConstructL(void) + { + // Method replaced by shim + ASSERT(EFalse); + } diff -r 7e3f204e6c81 -r f9c11be8c0b3 crypto/weakcryptospi/source/asymmetric/rsakeypairshim.cpp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/crypto/weakcryptospi/source/asymmetric/rsakeypairshim.cpp Tue Dec 01 11:12:04 2009 +0000 @@ -0,0 +1,115 @@ +/* +* Copyright (c) 2007-2009 Nokia Corporation and/or its subsidiary(-ies). +* All rights reserved. +* This component and the accompanying materials are made available +* under the terms of the License "Eclipse Public License v1.0" +* which accompanies this distribution, and is available +* at the URL "http://www.eclipse.org/legal/epl-v10.html". +* +* Initial Contributors: +* Nokia Corporation - initial contribution. +* +* Contributors: +* +* Description: +* +*/ + + +#include "rsakeypairshim.h" +#include "cryptokeypairgeneratorapi.h" +#include "keypair.h" +#include +#include + +using namespace CryptoSpi; + +/* CRSAKeyPair */ + +const TUint KFermat4 = 65537; + +CRSAKeyPairShim* CRSAKeyPairShim::NewLC(TUint aModulusBits, TRSAPrivateKeyType aKeyType) + { + CRSAKeyPairShim* self = new(ELeave) CRSAKeyPairShim(); + CleanupStack::PushL(self); + self->ConstructL(aModulusBits, aKeyType, KFermat4); + return self; + } + +CRSAKeyPairShim::~CRSAKeyPairShim(void) + { + } + +CRSAKeyPairShim::CRSAKeyPairShim(void) + { + } + +void CRSAKeyPairShim::ConstructL(TUint aModulusBits, TRSAPrivateKeyType aKeyType, TInt aPublicExponent) + { + CKeyPairGenerator* keyPairGeneratorImpl=NULL; + CKeyPairGeneratorFactory::CreateKeyPairGeneratorL( + keyPairGeneratorImpl, + KRSAKeyPairGeneratorUid, + NULL); + CleanupStack::PushL(keyPairGeneratorImpl); + + // put the RSA parameters into an array + CCryptoParams* keyParameters = CCryptoParams::NewLC(); + keyParameters->AddL(aPublicExponent, KRsaKeyParameterEUid); + if (aKeyType == EStandard) + { + keyParameters->AddL(KRsaPrivateKeyStandard, KRsaKeyTypeUid); + } + else if (aKeyType == EStandardCRT) + { + keyParameters->AddL(KRsaPrivateKeyCRT, KRsaKeyTypeUid); + } + + // call the api to create an RSA key pair + CKeyPair* keyPair = 0; + keyPairGeneratorImpl->GenerateKeyPairL(aModulusBits, *keyParameters, keyPair); + + CleanupStack::PushL(keyPair); + + /* + * Convert the CKeyPair to CRSAPrivateKey{CRT/Standard} and CRSAPublicKey + * The public key becomes the owner of n and e RIntegers + */ + RInteger n = RInteger::NewL(keyPair->PublicKey().GetBigIntL(KRsaKeyParameterNUid)); + CleanupClosePushL(n); + RInteger e = RInteger::NewL(keyPair->PublicKey().GetBigIntL(KRsaKeyParameterEUid)); + CleanupClosePushL(e); + iPublic = CRSAPublicKey::NewL(n, e); + + if (aKeyType == EStandard) + { + RInteger n = RInteger::NewL(keyPair->PrivateKey().GetBigIntL(KRsaKeyParameterNUid)); + CleanupClosePushL(n); + RInteger d = RInteger::NewL(keyPair->PrivateKey().GetBigIntL(KRsaKeyParameterDUid)); + CleanupClosePushL(d); + iPrivate = CRSAPrivateKeyStandard::NewL(n, d); + CleanupStack::Pop(2, &n); + } + else if (aKeyType == EStandardCRT) + { + RInteger n = RInteger::NewL(keyPair->PrivateKey().GetBigIntL(KRsaKeyParameterNUid)); + CleanupClosePushL(n); + RInteger p = RInteger::NewL(keyPair->PrivateKey().GetBigIntL(KRsaKeyParameterPUid)); + CleanupClosePushL(p); + RInteger q = RInteger::NewL(keyPair->PrivateKey().GetBigIntL(KRsaKeyParameterQUid)); + CleanupClosePushL(q); + RInteger dp = RInteger::NewL(keyPair->PrivateKey().GetBigIntL(KRsaKeyParameterDPUid)); + CleanupClosePushL(p); + RInteger dq = RInteger::NewL(keyPair->PrivateKey().GetBigIntL(KRsaKeyParameterDQUid)); + CleanupClosePushL(q); + RInteger qinv = RInteger::NewL(keyPair->PrivateKey().GetBigIntL(KRsaKeyParameterQInvUid)); + CleanupClosePushL(qinv); + iPrivate = CRSAPrivateKeyCRT::NewL(n, p, q, dp, dq, qinv); + CleanupStack::Pop(6, &n); + } + /* + * cleanup stack - it should contain keyPairGeneratorImpl, keyParameters, keyPair, n, e + */ + CleanupStack::Pop(2, &n); + CleanupStack::PopAndDestroy(3, keyPairGeneratorImpl); + } diff -r 7e3f204e6c81 -r f9c11be8c0b3 crypto/weakcryptospi/source/asymmetric/rsakeypairshim.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/crypto/weakcryptospi/source/asymmetric/rsakeypairshim.h Tue Dec 01 11:12:04 2009 +0000 @@ -0,0 +1,58 @@ +/* +* Copyright (c) 2006-2009 Nokia Corporation and/or its subsidiary(-ies). +* All rights reserved. +* This component and the accompanying materials are made available +* under the terms of the License "Eclipse Public License v1.0" +* which accompanies this distribution, and is available +* at the URL "http://www.eclipse.org/legal/epl-v10.html". +* +* Initial Contributors: +* Nokia Corporation - initial contribution. +* +* Contributors: +* +* Description: +* +*/ + + +/** + @file + @internalComponent + @released +*/ + +#ifndef __RSAKEYPAIRSHIM_H__ +#define __RSAKEYPAIRSHIM_H__ + +#include "asymmetrickeys.h" + +/** +* This class generates an RSA public/private key pair via CryptoSPI +*/ + +NONSHARABLE_CLASS(CRSAKeyPairShim) : public CRSAKeyPair + { +public: + /** + * Creates a new RSA key pair + */ + static CRSAKeyPairShim* NewLC(TUint aModulusBits, TRSAPrivateKeyType aKeyType); + + ~CRSAKeyPairShim(void); + +protected: + /** Constructor */ + CRSAKeyPairShim(void); + + /** + * 2nd stage constructor + */ + void ConstructL(TUint aModulusBits, TRSAPrivateKeyType aKeyType, TInt aPublicExponent); + +private: + CRSAKeyPairShim(const CRSAKeyPairShim&); + CRSAKeyPairShim& operator=(const CRSAKeyPairShim&); + }; + +#endif // __RSAKEYPAIRSHIM_H__ diff -r 7e3f204e6c81 -r f9c11be8c0b3 crypto/weakcryptospi/source/asymmetric/rsakeys.cpp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/crypto/weakcryptospi/source/asymmetric/rsakeys.cpp Tue Dec 01 11:12:04 2009 +0000 @@ -0,0 +1,271 @@ +/* +* Copyright (c) 2003-2009 Nokia Corporation and/or its subsidiary(-ies). +* All rights reserved. +* This component and the accompanying materials are made available +* under the terms of the License "Eclipse Public License v1.0" +* which accompanies this distribution, and is available +* at the URL "http://www.eclipse.org/legal/epl-v10.html". +* +* Initial Contributors: +* Nokia Corporation - initial contribution. +* +* Contributors: +* +* Description: +* +*/ + + +#include +#include "rsakeypairshim.h" +#include "../common/inlines.h" + +/* CRSAParameters */ + +EXPORT_C const TInteger& CRSAParameters::N(void) const + { + return iN; + } + +EXPORT_C CRSAParameters::~CRSAParameters(void) + { + iN.Close(); + } + +EXPORT_C CRSAParameters::CRSAParameters(RInteger& aN) : iN(aN) + { + } + +EXPORT_C CRSAParameters::CRSAParameters(void) + { + } + +/* CRSAPublicKey */ + +EXPORT_C CRSAPublicKey* CRSAPublicKey::NewL(RInteger& aN, RInteger& aE) + { + CRSAPublicKey* self = NewLC(aN, aE); + CleanupStack::Pop(); + return self; + } + +EXPORT_C CRSAPublicKey* CRSAPublicKey::NewLC(RInteger& aN, RInteger& aE) + { + CRSAPublicKey* self = new(ELeave) CRSAPublicKey(aN, aE); + CleanupStack::PushL(self); + self->ConstructL(); + return self; + } + + +void CRSAPublicKey::ConstructL() + { + // Check that the modulus and exponent are positive integers + // as specified by RSA + if(!N().IsPositive() || !E().IsPositive() || (E() <= 1)) + { + // If we need to leave during construction we must release ownership + // of the RInteger parameters that were passed in. + // These parameters should be on the cleanup stack so if we don't + // release ownership they will be deleted twice, causing a panic + iN = RInteger(); + iE = RInteger(); + User::Leave(KErrArgument); + } + } + + +EXPORT_C const TInteger& CRSAPublicKey::E(void) const + { + return iE; + } + +EXPORT_C CRSAPublicKey::CRSAPublicKey() + { + } + +EXPORT_C CRSAPublicKey::CRSAPublicKey(RInteger& aN, RInteger& aE) + : CRSAParameters(aN), iE(aE) + { + } + +EXPORT_C CRSAPublicKey::~CRSAPublicKey(void) + { + iE.Close(); + } + +/* CRSAPrivateKeyType */ + +CRSAPrivateKey::CRSAPrivateKey(const TRSAPrivateKeyType aKeyType, RInteger& aN) +: CRSAParameters(aN), iKeyType(aKeyType) +{} + + +/* CRSAPrivateKeyStandard */ + +EXPORT_C CRSAPrivateKeyStandard* CRSAPrivateKeyStandard::NewL(RInteger& aN, + RInteger& aD) + { + CRSAPrivateKeyStandard* self = NewLC(aN, aD); + CleanupStack::Pop(); + return self; + } + +EXPORT_C CRSAPrivateKeyStandard* CRSAPrivateKeyStandard::NewLC(RInteger& aN, + RInteger& aD) + { + CRSAPrivateKeyStandard* self = new(ELeave) CRSAPrivateKeyStandard(aN, aD); + CleanupStack::PushL(self); + self->ConstructL(); + return self; + } + +void CRSAPrivateKeyStandard::ConstructL() + { + // Check that the modulus and exponent are positive integers + if(!N().IsPositive() || !D().IsPositive() || (D() <= 1)) + { + // If we need to leave during construction we must release ownership + // of the RInteger parameters that were passed in. + // These parameters should be on the cleanup stack so if we don't + // release ownership they will be deleted twice, causing a panic + iN = RInteger(); + iD = RInteger(); + User::Leave(KErrArgument); + } + } + +EXPORT_C const TInteger& CRSAPrivateKeyStandard::D(void) const + { + return iD; + } + +EXPORT_C CRSAPrivateKeyStandard::CRSAPrivateKeyStandard(RInteger& aN, + RInteger& aD) : CRSAPrivateKey(EStandard, aN), iD(aD) + { + } + +EXPORT_C CRSAPrivateKeyStandard::~CRSAPrivateKeyStandard() + { + iD.Close(); + } + +/* CRSAPrivateKeyCRT */ + +EXPORT_C CRSAPrivateKeyCRT* CRSAPrivateKeyCRT::NewL(RInteger& aN, RInteger& aP, + RInteger& aQ, RInteger& aDP, RInteger& aDQ, RInteger& aQInv) + { + CRSAPrivateKeyCRT* self = NewLC(aN, aP, aQ, aDP, aDQ, aQInv); + CleanupStack::Pop(); + return self; + } + +EXPORT_C CRSAPrivateKeyCRT* CRSAPrivateKeyCRT::NewLC(RInteger& aN, RInteger& aP, + RInteger& aQ, RInteger& aDP, RInteger& aDQ, RInteger& aQInv) + { + CRSAPrivateKeyCRT* self = new(ELeave) CRSAPrivateKeyCRT(aN, aP, aQ, + aDP, aDQ, aQInv); + CleanupStack::PushL(self); + self->ConstructL(); + return self; + } + +EXPORT_C CRSAPrivateKeyCRT::CRSAPrivateKeyCRT(RInteger& aN, RInteger& aP, + RInteger& aQ, RInteger& aDP, RInteger& aDQ, RInteger& aQInv) + : CRSAPrivateKey(EStandardCRT, aN), iP(aP), iQ(aQ), iDP(aDP), iDQ(aDQ), + iQInv(aQInv) + { + } + +void CRSAPrivateKeyCRT::ConstructL() + { + // Check that all parameters are positive integers + if(!P().IsPositive() || !Q().IsPositive() || !DP().IsPositive() + || !DQ().IsPositive() || !QInv().IsPositive()) + { + // If we need to leave during construction we must release ownership + // of the RInteger parameters that were passed in. + // These parameters should be on the cleanup stack so if we don't + // release ownership they will be deleted twice, causing a panic + iN = RInteger(); + iP = RInteger(); + iQ = RInteger(); + iDP = RInteger(); + iDQ = RInteger(); + iQInv = RInteger(); + User::Leave(KErrArgument); + } + } + + +EXPORT_C CRSAPrivateKeyCRT::~CRSAPrivateKeyCRT() + { + iP.Close(); + iQ.Close(); + iDP.Close(); + iDQ.Close(); + iQInv.Close(); + } + +EXPORT_C const TInteger& CRSAPrivateKeyCRT::P(void) const + { + return iP; + } + +EXPORT_C const TInteger& CRSAPrivateKeyCRT::Q(void) const + { + return iQ; + } + +EXPORT_C const TInteger& CRSAPrivateKeyCRT::DP(void) const + { + return iDP; + } + +EXPORT_C const TInteger& CRSAPrivateKeyCRT::DQ(void) const + { + return iDQ; + } + +EXPORT_C const TInteger& CRSAPrivateKeyCRT::QInv(void) const + { + return iQInv; + } + +/* CRSAKeyPair */ + +EXPORT_C CRSAKeyPair* CRSAKeyPair::NewL(TUint aModulusBits, + TRSAPrivateKeyType aKeyType /*= EStandardCRT*/) + { + CRSAKeyPairShim* self = CRSAKeyPairShim::NewLC(aModulusBits, aKeyType); + CleanupStack::Pop(); + return self; + } + +EXPORT_C CRSAKeyPair* CRSAKeyPair::NewLC(TUint aModulusBits, + TRSAPrivateKeyType aKeyType /*= EStandardCRT*/) + { + CRSAKeyPairShim* self = CRSAKeyPairShim::NewLC(aModulusBits, aKeyType); + return self; + } + +EXPORT_C const CRSAPublicKey& CRSAKeyPair::PublicKey(void) const + { + return *iPublic; + } + +EXPORT_C const CRSAPrivateKey& CRSAKeyPair::PrivateKey(void) const + { + return *iPrivate; + } + +EXPORT_C CRSAKeyPair::~CRSAKeyPair(void) + { + delete iPublic; + delete iPrivate; + } + +EXPORT_C CRSAKeyPair::CRSAKeyPair(void) + { + } + diff -r 7e3f204e6c81 -r f9c11be8c0b3 crypto/weakcryptospi/source/asymmetric/rsashim.cpp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/crypto/weakcryptospi/source/asymmetric/rsashim.cpp Tue Dec 01 11:12:04 2009 +0000 @@ -0,0 +1,365 @@ +/* +* Copyright (c) 2006-2009 Nokia Corporation and/or its subsidiary(-ies). +* All rights reserved. +* This component and the accompanying materials are made available +* under the terms of the License "Eclipse Public License v1.0" +* which accompanies this distribution, and is available +* at the URL "http://www.eclipse.org/legal/epl-v10.html". +* +* Initial Contributors: +* Nokia Corporation - initial contribution. +* +* Contributors: +* +* Description: +* +*/ + + +#include "rsashim.h" +#include "cryptoasymmetriccipherapi.h" +#include "cryptosignatureapi.h" +#include +#include "keyconverter.h" +#include "keys.h" + +#include "../common/inlines.h" + + +using namespace CryptoSpi; + +// CRSAPKCS1v15EncryptorShim //////////////////////////////////////////////////////// + +CRSAPKCS1v15EncryptorShim* CRSAPKCS1v15EncryptorShim::NewL(const CRSAPublicKey& aKey) + { + CRSAPKCS1v15EncryptorShim* self = CRSAPKCS1v15EncryptorShim::NewLC(aKey); + CleanupStack::Pop(self); + return self; + } + +CRSAPKCS1v15EncryptorShim* CRSAPKCS1v15EncryptorShim::NewLC(const CRSAPublicKey& aKey) + { + CRSAPKCS1v15EncryptorShim* self = new (ELeave) CRSAPKCS1v15EncryptorShim(aKey); + CleanupStack::PushL(self); + self->ConstructL(aKey); + return self; + } + +CRSAPKCS1v15EncryptorShim::CRSAPKCS1v15EncryptorShim(const CRSAPublicKey& aKey) + : CRSAPKCS1v15Encryptor(aKey) + { + } + +CRSAPKCS1v15EncryptorShim::~CRSAPKCS1v15EncryptorShim() + { + delete iAsymmetricCipherImpl; + delete iKey; + } + +void CRSAPKCS1v15EncryptorShim::ConstructL(const CRSAPublicKey& aKey) + { + iKey = KeyConverter::CreateKeyL(aKey); + CAsymmetricCipherFactory::CreateAsymmetricCipherL( + iAsymmetricCipherImpl, + KRsaCipherUid, + *iKey, + KCryptoModeEncryptUid, + KPaddingModePkcs1_v1_5_EncryptionUid, + NULL); + } + +void CRSAPKCS1v15EncryptorShim::EncryptL(const TDesC8& aInput, TDes8& aOutput) const + { + iAsymmetricCipherImpl->ProcessL(aInput, aOutput); + } + +TInt CRSAPKCS1v15EncryptorShim::MaxInputLength(void) const + { + TInt maxInputLength=0; + TRAPD(err, maxInputLength=iAsymmetricCipherImpl->GetMaximumInputLengthL()) + if (err==KErrNone) + { + return maxInputLength; + } + else + { + return err; + } + } + +TInt CRSAPKCS1v15EncryptorShim::MaxOutputLength(void) const + { + TInt maxOutputLength=0; + TRAPD(err, maxOutputLength=iAsymmetricCipherImpl->GetMaximumOutputLengthL()) + if (err==KErrNone) + { + return maxOutputLength; + } + else + { + return err; + } + } + +// CRSAPKCS1v15DecryptorShim //////////////////////////////////////////////////////// +CRSAPKCS1v15DecryptorShim* CRSAPKCS1v15DecryptorShim::NewL(const CRSAPrivateKey& aKey) + { + CRSAPKCS1v15DecryptorShim* self = CRSAPKCS1v15DecryptorShim::NewLC(aKey); + CleanupStack::Pop(self); + return self; + } + + +CRSAPKCS1v15DecryptorShim* CRSAPKCS1v15DecryptorShim::NewLC(const CRSAPrivateKey& aKey) + { + CRSAPKCS1v15DecryptorShim* self = new (ELeave) CRSAPKCS1v15DecryptorShim(aKey); + CleanupStack::PushL(self); + self->ConstructL(aKey); + return self; + } + +CRSAPKCS1v15DecryptorShim::CRSAPKCS1v15DecryptorShim(const CRSAPrivateKey& aKey) + : CRSAPKCS1v15Decryptor(aKey) + { + } + +CRSAPKCS1v15DecryptorShim::~CRSAPKCS1v15DecryptorShim() + { + delete iAsymmetricCipherImpl; + delete iKey; + } + +void CRSAPKCS1v15DecryptorShim::ConstructL(const CRSAPrivateKey& aKey) + { + iKey = KeyConverter::CreateKeyL(aKey); + CAsymmetricCipherFactory::CreateAsymmetricCipherL( + iAsymmetricCipherImpl, + KRsaCipherUid, + *iKey, + KCryptoModeDecryptUid, + KPaddingModePkcs1_v1_5_EncryptionUid, + NULL); + } + +void CRSAPKCS1v15DecryptorShim::DecryptL(const TDesC8& aInput, TDes8& aOutput) const + { + iAsymmetricCipherImpl->ProcessL(aInput, aOutput); + } + +TInt CRSAPKCS1v15DecryptorShim::MaxInputLength(void) const + { + TInt maxInputLength=0; + TRAPD(err, maxInputLength=iAsymmetricCipherImpl->GetMaximumInputLengthL()) + if (err==KErrNone) + { + return maxInputLength; + } + else + { + return err; + } + } + +TInt CRSAPKCS1v15DecryptorShim::MaxOutputLength(void) const + { + TInt maxOutputLength=0; + TRAPD(err, maxOutputLength=iAsymmetricCipherImpl->GetMaximumOutputLengthL()) + if (err==KErrNone) + { + return maxOutputLength; + } + else + { + return err; + } + } + +// CRSAPKCS1v15SignerShim //////////////////////////////////////////////////////// +CRSAPKCS1v15SignerShim* CRSAPKCS1v15SignerShim::NewL(const CRSAPrivateKey& aKey) + { + CRSAPKCS1v15SignerShim* self = CRSAPKCS1v15SignerShim::NewLC(aKey); + CleanupStack::Pop(self); + return self; + } + +CRSAPKCS1v15SignerShim* CRSAPKCS1v15SignerShim::NewLC(const CRSAPrivateKey& aKey) + { + CRSAPKCS1v15SignerShim* self = new (ELeave) CRSAPKCS1v15SignerShim(aKey); + CleanupStack::PushL(self); + self->ConstructL(aKey); + return self; + } + +CRSASignature* CRSAPKCS1v15SignerShim::SignL(const TDesC8& aInput) const + { + //Sign the input data + CCryptoParams* signature = CCryptoParams::NewLC(); + iSignerImpl->SignL(aInput, *signature); + + //Retrieve the S in RSA signature from the array + const TInteger& cS=signature->GetBigIntL(KRsaSignatureParameterSUid); + + //Make copies of the RSA signature + RInteger s=RInteger::NewL(cS); + CleanupClosePushL(s); + + //Create the RSA signature object, the ownership of s is transfered to rsaSig + CRSASignature* rsaSig=CRSASignature::NewL(s); + + //Cleanup + CleanupStack::Pop(&s); + CleanupStack::PopAndDestroy(signature); + return rsaSig; + } + +TInt CRSAPKCS1v15SignerShim::MaxInputLength(void) const + { + TInt maxInputLength=0; + TRAPD(err, maxInputLength=iSignerImpl->GetMaximumInputLengthL()) + if (err==KErrNone) + { + return maxInputLength; + } + else + { + return err; + } + } + +TInt CRSAPKCS1v15SignerShim::MaxOutputLength(void) const + { + TInt maxOutputLength=0; + TRAPD(err, maxOutputLength=iSignerImpl->GetMaximumOutputLengthL()) + if (err==KErrNone) + { + return maxOutputLength; + } + else + { + return err; + } + } + +CRSAPKCS1v15SignerShim::~CRSAPKCS1v15SignerShim(void) + { + delete iSignerImpl; + delete iKey; + } + +CRSAPKCS1v15SignerShim::CRSAPKCS1v15SignerShim(const CRSAPrivateKey& aKey) + : CRSAPKCS1v15Signer(aKey) + { + } + +void CRSAPKCS1v15SignerShim::ConstructL(const CRSAPrivateKey& aKey) + { + iKey = KeyConverter::CreateKeyL(aKey); + CSignatureFactory::CreateSignerL( + iSignerImpl, + KRsaSignerUid, + *iKey, + KPaddingModePkcs1_v1_5_SignatureUid, + NULL); + } + +// CRSAPKCS1v15VerifierShim //////////////////////////////////////////////////////// +CRSAPKCS1v15VerifierShim* CRSAPKCS1v15VerifierShim::NewL(const CRSAPublicKey& aKey) + { + CRSAPKCS1v15VerifierShim* self = CRSAPKCS1v15VerifierShim::NewLC(aKey); + CleanupStack::Pop(self); + return self; + } + +CRSAPKCS1v15VerifierShim* CRSAPKCS1v15VerifierShim::NewLC(const CRSAPublicKey& aKey) + { + CRSAPKCS1v15VerifierShim* self = new (ELeave) CRSAPKCS1v15VerifierShim(aKey); + CleanupStack::PushL(self); + self->ConstructL(aKey); + return self; + } + +TBool CRSAPKCS1v15VerifierShim::VerifyL(const TDesC8& aInput, const CRSASignature& aSignature) const + { + //create the array format rsa signature for the new crypto spi + CCryptoParams* rsaSig = CCryptoParams::NewLC(); + + rsaSig->AddL(aSignature.S(), KRsaSignatureParameterSUid); + + //pass the signature and input to crypto spi to be verified + TBool verificationResult = EFalse; + iVerifierImpl->VerifyL(aInput, *rsaSig, verificationResult); + + //Cleanup the array + CleanupStack::PopAndDestroy(rsaSig); + return verificationResult; + } + +HBufC8* CRSAPKCS1v15VerifierShim::InverseSignLC(const CRSASignature& aSignature) const + { + //create the array format rsa signature for the new crypto spi + CCryptoParams* rsaSig = CCryptoParams::NewLC(); + + rsaSig->AddL(aSignature.S(), KRsaSignatureParameterSUid); + + //pass the signature and input to crypto spi to be verified + HBufC8* output = NULL; + iVerifierImpl->InverseSignL(output, *rsaSig); + + //Cleanup the array + CleanupStack::PopAndDestroy(rsaSig); + + // leave output on the cleanup stack + CleanupStack::PushL(output); + return output; + } + +TInt CRSAPKCS1v15VerifierShim::MaxInputLength(void) const + { + TInt maxInputLength=0; + TRAPD(err, maxInputLength=iVerifierImpl->GetMaximumInputLengthL()) + if (err==KErrNone) + { + return maxInputLength; + } + else + { + return err; + } + } + +TInt CRSAPKCS1v15VerifierShim::MaxOutputLength(void) const + { + TInt maxOutputLength=0; + TRAPD(err, maxOutputLength=iVerifierImpl->GetMaximumOutputLengthL()) + if (err==KErrNone) + { + return maxOutputLength; + } + else + { + return err; + } + } + +CRSAPKCS1v15VerifierShim::~CRSAPKCS1v15VerifierShim(void) + { + delete iVerifierImpl; + delete iKey; + } + +CRSAPKCS1v15VerifierShim::CRSAPKCS1v15VerifierShim(const CRSAPublicKey& aKey) + : CRSAPKCS1v15Verifier(aKey) + { + } + +void CRSAPKCS1v15VerifierShim::ConstructL(const CRSAPublicKey& aKey) + { + iKey = KeyConverter::CreateKeyL(aKey); + CSignatureFactory::CreateVerifierL( + iVerifierImpl, + KRsaVerifierUid, + *iKey, + KPaddingModePkcs1_v1_5_SignatureUid, + NULL); + } + diff -r 7e3f204e6c81 -r f9c11be8c0b3 crypto/weakcryptospi/source/asymmetric/rsashim.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/crypto/weakcryptospi/source/asymmetric/rsashim.h Tue Dec 01 11:12:04 2009 +0000 @@ -0,0 +1,238 @@ +/* +* Copyright (c) 2006-2009 Nokia Corporation and/or its subsidiary(-ies). +* All rights reserved. +* This component and the accompanying materials are made available +* under the terms of the License "Eclipse Public License v1.0" +* which accompanies this distribution, and is available +* at the URL "http://www.eclipse.org/legal/epl-v10.html". +* +* Initial Contributors: +* Nokia Corporation - initial contribution. +* +* Contributors: +* +* Description: +* RSA shim classes definition +* +*/ + + +/** + @file + @internalComponent + @released +*/ + +#ifndef __RSASHIM_H__ +#define __RSASHIM_H__ + +#include + +namespace CryptoSpi + { + class CAsymmetricCipher; + class CKey; + class CSigner; + class CVerifier; + } + +NONSHARABLE_CLASS(CRSAPKCS1v15EncryptorShim) : public CRSAPKCS1v15Encryptor +{ +public: + /** + Creates an RSAPKCS1v15EncryptorShim object which has the same interface + as CRSAPKCS1v15Encryptor but delegates all work to a Crypto SPI plug-in. + + @param aKey The encryption key + @return A pointer to a CRSAPKCS1v15EncryptorShim instance + */ + static CRSAPKCS1v15EncryptorShim* NewL(const CRSAPublicKey& aKey); + + /** + Creates an RSAPKCS1v15EncryptorShim object which has the same interface + as CRSAPKCS1v15Encryptor but delegates all work to a Crypto SPI plug-in. + + A pointer to the new object is placed on the cleanup stack + + @param aKey The encryption key + @return A pointer to a CRSAPKCS1v15EncryptorShim instance + */ + static CRSAPKCS1v15EncryptorShim* NewLC(const CRSAPublicKey& aKey); + + // From CRSAPKCS1v15Encryptor + void EncryptL(const TDesC8& aInput, TDes8& aOutput) const; + TInt MaxInputLength(void) const; + TInt MaxOutputLength(void) const; + + /// Destructor + ~CRSAPKCS1v15EncryptorShim(); + +private: + /// Constructor + CRSAPKCS1v15EncryptorShim(const CRSAPublicKey& aKey); + void ConstructL(const CRSAPublicKey& aKey); + +private: + /// SPI delegate + CryptoSpi::CAsymmetricCipher* iAsymmetricCipherImpl; + + /// SPI requires all key to passed as key-objects + CryptoSpi::CKey* iKey; +}; + +NONSHARABLE_CLASS(CRSAPKCS1v15DecryptorShim) : public CRSAPKCS1v15Decryptor +{ +public: + /** + Creates an RSAPKCS1v15DecryptorShim object which has the same interface + as CRSAPKCS1v15Decryptor but delegates all work to a Crypto SPI plug-in. + + @param aKey The decryption key + @return A pointer to a CRSAPKCS1v15DecryptorShim instance + */ + static CRSAPKCS1v15DecryptorShim* NewL(const CRSAPrivateKey& aKey); + + /** + Creates an RSAPKCS1v15EncryptorShim object which has the same interface + as CRSAPKCS1v15Decryptor but delegates all work to a Crypto SPI plug-in. + + A pointer to the new object is placed on the cleanup stack + + @param aKey The decryption key + @return A pointer to a CRSAPKCS1v15DecryptorShim instance + */ + static CRSAPKCS1v15DecryptorShim* NewLC(const CRSAPrivateKey& aKey); + + // From CRSAPKCS1v15Decryptor + void DecryptL(const TDesC8& aInput, TDes8& aOutput) const; + TInt MaxInputLength(void) const; + TInt MaxOutputLength(void) const; + + /// Destructor + ~CRSAPKCS1v15DecryptorShim(); + +private: + /// Constructor + CRSAPKCS1v15DecryptorShim(const CRSAPrivateKey& aKey); + void ConstructL(const CRSAPrivateKey& aKey); + +private: + /// SPI delegate + CryptoSpi::CAsymmetricCipher* iAsymmetricCipherImpl; + + /// SPI requires all key to passed as key-objects + CryptoSpi::CKey* iKey; +}; + +NONSHARABLE_CLASS(CRSAPKCS1v15SignerShim) : public CRSAPKCS1v15Signer + { +public: + /** + Creates a new CRSAPKCS1v15SignerShim object which has the same interface + as CRSAPKCS1v15Signer but delegates all work to a Crypto SPI plug-in. + + @param aKey The RSA private key to be used for signing + @return A pointer to a CRSAPKCS1v15SignerShim instance + @leave KErrKeySize If the key length is too small + */ + static CRSAPKCS1v15SignerShim* NewL(const CRSAPrivateKey& aKey); + + /** + Creates a new CRSAPKCS1v15SignerShim object which has the same interface + as CRSAPKCS1v15Signer but delegates all work to a Crypto SPI plug-in. + + @param aKey The RSA private key to be used for signing + @return A pointer to a CRSAPKCS1v15SignerShim instance + @leave KErrKeySize If the key length is too small + */ + static CRSAPKCS1v15SignerShim* NewLC(const CRSAPrivateKey& aKey); + + // From CRSAPKCS1v15Signer + virtual CRSASignature* SignL(const TDesC8& aInput) const; + virtual TInt MaxInputLength(void) const; + virtual TInt MaxOutputLength(void) const; + /** The destructor frees all resources owned by the object, prior to its destruction.*/ + ~CRSAPKCS1v15SignerShim(void); +protected: + + CRSAPKCS1v15SignerShim(const CRSAPrivateKey& aKey); + void ConstructL(const CRSAPrivateKey& aKey); + +protected: + /// SPI delegate + CryptoSpi::CSigner* iSignerImpl; + + /// SPI requires all key to passed as key-objects + CryptoSpi::CKey* iKey; +private: + CRSAPKCS1v15SignerShim(const CRSAPKCS1v15SignerShim&); + CRSAPKCS1v15SignerShim& operator=(const CRSAPKCS1v15SignerShim&); + }; + +/** +* This class verifies RSA signatures given a message and its supposed +* signature. It follows the RSA PKCS#1 v1.5 with PKCS#1 v1.5 padding specification +* with the following exception: the VerifyL() function does not hash or +* in any way manipulate the input data before checking. Thus in order to verify +* RSA signatures in PKCS#1 v1.5 format, the input data needs to follow PKCS#1 v1.5 +* specification, i.e. be ASN.1 encoded and prefixed by ASN.1 encoded digestId. +* +* @internalComponent +* @released +*/ +NONSHARABLE_CLASS(CRSAPKCS1v15VerifierShim) : public CRSAPKCS1v15Verifier + { +public: + /** + @internalComponent + + Creates a new CRSAPKCS1v15VerifierShim object which has the same interface + as CRSAPKCS1v15Verifier but delegates all work to a Crypto SPI plug-in. + + @param aKey The RSA public key to be used for verifying + @return A pointer to a CRSAPKCS1v15VerifierShim instance + @leave KErrKeySize If the key length is too small + */ + static CRSAPKCS1v15VerifierShim* NewL(const CRSAPublicKey& aKey); + + /** + @internalComponent + + Creates a new CRSAPKCS1v15VerifierShim object which has the same interface + as CRSAPKCS1v15Verifier but delegates all work to a Crypto SPI plug-in. + + The returned pointer is put onto the cleanup stack. + + @param aKey The RSA public key to be used for verifying + @return A pointer to a CRSAPKCS1v15VerifierShim instance + + @leave KErrKeySize If the key length is too small + */ + static CRSAPKCS1v15VerifierShim* NewLC(const CRSAPublicKey& aKey); + + // CRSAPKCS1v15Verifier + virtual TInt MaxInputLength(void) const; + virtual TInt MaxOutputLength(void) const; + + // RSAVerifier + virtual TBool VerifyL(const TDesC8& aInput, const CRSASignature& aSignature) const; + virtual HBufC8* InverseSignLC(const CRSASignature& aSignature) const; + + /** The destructor frees all resources owned by the object, prior to its destruction. */ + virtual ~CRSAPKCS1v15VerifierShim(void); +protected: + CRSAPKCS1v15VerifierShim(const CRSAPublicKey& aKey); + void ConstructL(const CRSAPublicKey& aKey); + +protected: + /// SPI delegate + CryptoSpi::CVerifier* iVerifierImpl; + + /// SPI requires all key to passed as key-objects + CryptoSpi::CKey* iKey; +private: + CRSAPKCS1v15VerifierShim(const CRSAPKCS1v15VerifierShim&); + CRSAPKCS1v15VerifierShim& operator=(const CRSAPKCS1v15VerifierShim&); + }; + +#endif // __RSASHIM_H__ diff -r 7e3f204e6c81 -r f9c11be8c0b3 crypto/weakcryptospi/source/asymmetric/rsasigner.cpp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/crypto/weakcryptospi/source/asymmetric/rsasigner.cpp Tue Dec 01 11:12:04 2009 +0000 @@ -0,0 +1,78 @@ +/* +* Copyright (c) 2003-2009 Nokia Corporation and/or its subsidiary(-ies). +* All rights reserved. +* This component and the accompanying materials are made available +* under the terms of the License "Eclipse Public License v1.0" +* which accompanies this distribution, and is available +* at the URL "http://www.eclipse.org/legal/epl-v10.html". +* +* Initial Contributors: +* Nokia Corporation - initial contribution. +* +* Contributors: +* +* Description: +* +*/ + + +#include "rsashim.h" + +/* CRSASigner */ + +EXPORT_C CRSASigner::CRSASigner(void) + { + } + +/* CRSAPKCS1v15Signer */ +EXPORT_C CRSAPKCS1v15Signer* CRSAPKCS1v15Signer::NewL(const CRSAPrivateKey& aKey) + { + return CRSAPKCS1v15SignerShim::NewL(aKey); + } + +EXPORT_C CRSAPKCS1v15Signer* CRSAPKCS1v15Signer::NewLC(const CRSAPrivateKey& aKey) + { + return CRSAPKCS1v15SignerShim::NewLC(aKey); + } + +CRSAPKCS1v15Signer::CRSAPKCS1v15Signer(const CRSAPrivateKey& aKey) + : iPrivateKey(aKey) + { + } + +CRSAPKCS1v15Signer::~CRSAPKCS1v15Signer(void) + { + } + +// All these methods have been replaced by the shim +#ifdef _BullseyeCoverage +#pragma suppress_warnings on +#pragma BullseyeCoverage off +#pragma suppress_warnings off +#endif +TInt CRSAPKCS1v15Signer::MaxInputLength(void) const + { + // Method replaced by shim + ASSERT(EFalse); + return 0; + } + +TInt CRSAPKCS1v15Signer::MaxOutputLength(void) const + { + // Method replaced by shim + ASSERT(EFalse); + return 0; + } + +CRSASignature* CRSAPKCS1v15Signer::SignL(const TDesC8& /*aInput*/) const + { + // Method replaced by shim + User::Leave(KErrNotSupported); + return 0; + } + +void CRSAPKCS1v15Signer::ConstructL(void) + { + // Method replaced by shim + User::Leave(KErrNotSupported); + } diff -r 7e3f204e6c81 -r f9c11be8c0b3 crypto/weakcryptospi/source/asymmetric/rsaverifier.cpp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/crypto/weakcryptospi/source/asymmetric/rsaverifier.cpp Tue Dec 01 11:12:04 2009 +0000 @@ -0,0 +1,92 @@ +/* +* Copyright (c) 2003-2009 Nokia Corporation and/or its subsidiary(-ies). +* All rights reserved. +* This component and the accompanying materials are made available +* under the terms of the License "Eclipse Public License v1.0" +* which accompanies this distribution, and is available +* at the URL "http://www.eclipse.org/legal/epl-v10.html". +* +* Initial Contributors: +* Nokia Corporation - initial contribution. +* +* Contributors: +* +* Description: +* +*/ + + +#include "rsashim.h" + +/* CRSAVerifier */ + +EXPORT_C CRSAVerifier::CRSAVerifier(void) + { + } + +/* CRSAPKCS1v15Verifier */ +EXPORT_C CRSAPKCS1v15Verifier* CRSAPKCS1v15Verifier::NewL(const CRSAPublicKey& aKey) + { + return CRSAPKCS1v15VerifierShim::NewL(aKey); + } + +EXPORT_C CRSAPKCS1v15Verifier* CRSAPKCS1v15Verifier::NewLC(const CRSAPublicKey& aKey) + { + return CRSAPKCS1v15VerifierShim::NewLC(aKey); + } + +CRSAPKCS1v15Verifier::~CRSAPKCS1v15Verifier(void) + { + } + +CRSAPKCS1v15Verifier::CRSAPKCS1v15Verifier(const CRSAPublicKey& aKey) + : iPublicKey(aKey) + { + } + +// All these methods have been replaced by the shim +#ifdef _BullseyeCoverage +#pragma suppress_warnings on +#pragma BullseyeCoverage off +#pragma suppress_warnings off +#endif +TInt CRSAPKCS1v15Verifier::MaxInputLength(void) const + { + // Method replaced by shim + ASSERT(EFalse); + return 0; + } + +TInt CRSAPKCS1v15Verifier::MaxOutputLength(void) const + { + // Method replaced by shim + ASSERT(EFalse); + return 0; + } + +HBufC8* CRSAPKCS1v15Verifier::InverseSignLC(const CRSASignature& /*aSignature*/) const + { + // Method replaced by shim + ASSERT(EFalse); + return 0; + } + +void CRSAPKCS1v15Verifier::ConstructL(void) + { + // Method replaced by shim + ASSERT(EFalse); + } + +// InverseSignLC is replaced by shim. So, VerifyL also can not be used properly, hence excluded from coverage. +EXPORT_C TBool CRSAVerifier::VerifyL(const TDesC8& aInput, const CRSASignature& aSignature) const + { + TBool retval = EFalse; + HBufC8* inverseSign = InverseSignLC(aSignature); + + if (inverseSign->Compare(aInput)==0) + { + retval = ETrue; + } + CleanupStack::PopAndDestroy(inverseSign); + return retval; + } diff -r 7e3f204e6c81 -r f9c11be8c0b3 crypto/weakcryptospi/source/bigint/algorithms.cpp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/crypto/weakcryptospi/source/bigint/algorithms.cpp Tue Dec 01 11:12:04 2009 +0000 @@ -0,0 +1,1160 @@ +/* +* Copyright (c) 2003-2009 Nokia Corporation and/or its subsidiary(-ies). +* All rights reserved. +* This component and the accompanying materials are made available +* under the terms of the License "Eclipse Public License v1.0" +* which accompanies this distribution, and is available +* at the URL "http://www.eclipse.org/legal/epl-v10.html". +* +* Initial Contributors: +* Nokia Corporation - initial contribution. +* +* Contributors: +* +* Description: +* +*/ + + +#include "words.h" +#include "algorithms.h" + +word Add(word *C, const word *A, const word *B, unsigned int N) +{ + assert (N%2 == 0); + word carry = 0; + for (unsigned int i = 0; i < N; i+=2) + { + dword u = (dword) carry + A[i] + B[i]; + C[i] = LOW_WORD(u); + u = (dword) HIGH_WORD(u) + A[i+1] + B[i+1]; + C[i+1] = LOW_WORD(u); + carry = HIGH_WORD(u); + } + return carry; +} + +word Subtract(word *C, const word *A, const word *B, unsigned int N) +{ + assert (N%2 == 0); + word borrow=0; + for (unsigned i = 0; i < N; i+=2) + { + dword u = (dword) A[i] - B[i] - borrow; + C[i] = LOW_WORD(u); + u = (dword) A[i+1] - B[i+1] - (word)(0-HIGH_WORD(u)); + C[i+1] = LOW_WORD(u); + borrow = 0-HIGH_WORD(u); + } + return borrow; +} + +int Compare(const word *A, const word *B, unsigned int N) +{ + while (N--) + if (A[N] > B[N]) + return 1; + else if (A[N] < B[N]) + return -1; + + return 0; +} + +// It is the job of the calling code to ensure that this won't carry. +// If you aren't sure, use the next version that will tell you if you need to +// grow your integer. +// Having two of these creates ever so slightly more code but avoids having +// ifdefs all over the rest of the code checking the following type stuff which +// causes warnings in certain compilers about unused parameters in release +// builds. We can't have that can we! +/* +Allows avoid this all over bigint.cpp and primes.cpp +ifdef _DEBUG + TUint carry = Increment(Ptr(), Size()); + assert(!carry); +else + Increment(Ptr(), Size()) +endif +*/ +void IncrementNoCarry(word *A, unsigned int N, word B) +{ + assert(N); + word t = A[0]; + A[0] = t+B; + if (A[0] >= t) + return; + for (unsigned i=1; i= t) + return 0; + for (unsigned i=1; i= A0) + if (B0 >= B1) + { + s = 0; + d = (dword)(A1-A0)*(B0-B1); + } + else + { + s = (A1-A0); + d = (dword)s*(word)(B0-B1); + } + else + if (B0 > B1) + { + s = (B0-B1); + d = (word)(A1-A0)*(dword)s; + } + else + { + s = 0; + d = (dword)(A0-A1)*(B1-B0); + } +*/ + // this segment is the branchless equivalent of above + word D[4] = {A[1]-A[0], A[0]-A[1], B[0]-B[1], B[1]-B[0]}; + unsigned int ai = A[1] < A[0]; + unsigned int bi = B[0] < B[1]; + unsigned int di = ai & bi; + dword d = (dword)D[di]*D[di+2]; + D[1] = D[3] = 0; + unsigned int si = ai + !bi; + word s = D[si]; + + dword A0B0 = (dword)A[0]*B[0]; + C[0] = LOW_WORD(A0B0); + + dword A1B1 = (dword)A[1]*B[1]; + dword t = (dword) HIGH_WORD(A0B0) + LOW_WORD(A0B0) + LOW_WORD(d) + LOW_WORD(A1B1); + C[1] = LOW_WORD(t); + + t = A1B1 + HIGH_WORD(t) + HIGH_WORD(A0B0) + HIGH_WORD(d) + HIGH_WORD(A1B1) - s; + C[2] = LOW_WORD(t); + C[3] = HIGH_WORD(t); +} + +static word AtomicMultiplyAdd(word *C, const word *A, const word *B) +{ + word D[4] = {A[1]-A[0], A[0]-A[1], B[0]-B[1], B[1]-B[0]}; + unsigned int ai = A[1] < A[0]; + unsigned int bi = B[0] < B[1]; + unsigned int di = ai & bi; + dword d = (dword)D[di]*D[di+2]; + D[1] = D[3] = 0; + unsigned int si = ai + !bi; + word s = D[si]; + + dword A0B0 = (dword)A[0]*B[0]; + dword t = A0B0 + C[0]; + C[0] = LOW_WORD(t); + + dword A1B1 = (dword)A[1]*B[1]; + t = (dword) HIGH_WORD(t) + LOW_WORD(A0B0) + LOW_WORD(d) + LOW_WORD(A1B1) + C[1]; + C[1] = LOW_WORD(t); + + t = (dword) HIGH_WORD(t) + LOW_WORD(A1B1) + HIGH_WORD(A0B0) + HIGH_WORD(d) + HIGH_WORD(A1B1) - s + C[2]; + C[2] = LOW_WORD(t); + + t = (dword) HIGH_WORD(t) + HIGH_WORD(A1B1) + C[3]; + C[3] = LOW_WORD(t); + return HIGH_WORD(t); +} + +static inline void AtomicMultiplyBottom(word *C, const word *A, const word *B) +{ + dword t = (dword)A[0]*B[0]; + C[0] = LOW_WORD(t); + C[1] = HIGH_WORD(t) + A[0]*B[1] + A[1]*B[0]; +} + +#define MulAcc(x, y) \ + p = (dword)A[x] * B[y] + c; \ + c = LOW_WORD(p); \ + p = (dword)d + HIGH_WORD(p); \ + d = LOW_WORD(p); \ + e += HIGH_WORD(p); + +#define SaveMulAcc(s, x, y) \ + R[s] = c; \ + p = (dword)A[x] * B[y] + d; \ + c = LOW_WORD(p); \ + p = (dword)e + HIGH_WORD(p); \ + d = LOW_WORD(p); \ + e = HIGH_WORD(p); + +#define MulAcc1(x, y) \ + p = (dword)A[x] * A[y] + c; \ + c = LOW_WORD(p); \ + p = (dword)d + HIGH_WORD(p); \ + d = LOW_WORD(p); \ + e += HIGH_WORD(p); + +#define SaveMulAcc1(s, x, y) \ + R[s] = c; \ + p = (dword)A[x] * A[y] + d; \ + c = LOW_WORD(p); \ + p = (dword)e + HIGH_WORD(p); \ + d = LOW_WORD(p); \ + e = HIGH_WORD(p); + +#define SquAcc(x, y) \ + p = (dword)A[x] * A[y]; \ + p = p + p + c; \ + c = LOW_WORD(p); \ + p = (dword)d + HIGH_WORD(p); \ + d = LOW_WORD(p); \ + e += HIGH_WORD(p); + +#define SaveSquAcc(s, x, y) \ + R[s] = c; \ + p = (dword)A[x] * A[y]; \ + p = p + p + d; \ + c = LOW_WORD(p); \ + p = (dword)e + HIGH_WORD(p); \ + d = LOW_WORD(p); \ + e = HIGH_WORD(p); + +// VC60 workaround: MSVC 6.0 has an optimization problem that makes +// (dword)A*B where either A or B has been cast to a dword before +// very expensive. Revisit a CombaSquare4() function when this +// problem is fixed. + +// WARNING: KeithR. 05/08/03 This routine doesn't work with gcc on hardware +// either. I've completely removed it. It may be worth looking into sometime +// in the future. +/*#ifndef __WINS__ +static void CombaSquare4(word *R, const word *A) +{ + dword p; + word c, d, e; + + p = (dword)A[0] * A[0]; + R[0] = LOW_WORD(p); + c = HIGH_WORD(p); + d = e = 0; + + SquAcc(0, 1); + + SaveSquAcc(1, 2, 0); + MulAcc1(1, 1); + + SaveSquAcc(2, 0, 3); + SquAcc(1, 2); + + SaveSquAcc(3, 3, 1); + MulAcc1(2, 2); + + SaveSquAcc(4, 2, 3); + + R[5] = c; + p = (dword)A[3] * A[3] + d; + R[6] = LOW_WORD(p); + R[7] = e + HIGH_WORD(p); +} +#endif */ + +static void CombaMultiply4(word *R, const word *A, const word *B) +{ + dword p; + word c, d, e; + + p = (dword)A[0] * B[0]; + R[0] = LOW_WORD(p); + c = HIGH_WORD(p); + d = e = 0; + + MulAcc(0, 1); + MulAcc(1, 0); + + SaveMulAcc(1, 2, 0); + MulAcc(1, 1); + MulAcc(0, 2); + + SaveMulAcc(2, 0, 3); + MulAcc(1, 2); + MulAcc(2, 1); + MulAcc(3, 0); + + SaveMulAcc(3, 3, 1); + MulAcc(2, 2); + MulAcc(1, 3); + + SaveMulAcc(4, 2, 3); + MulAcc(3, 2); + + R[5] = c; + p = (dword)A[3] * B[3] + d; + R[6] = LOW_WORD(p); + R[7] = e + HIGH_WORD(p); +} + +static void CombaMultiply8(word *R, const word *A, const word *B) +{ + dword p; + word c, d, e; + + p = (dword)A[0] * B[0]; + R[0] = LOW_WORD(p); + c = HIGH_WORD(p); + d = e = 0; + + MulAcc(0, 1); + MulAcc(1, 0); + + SaveMulAcc(1, 2, 0); + MulAcc(1, 1); + MulAcc(0, 2); + + SaveMulAcc(2, 0, 3); + MulAcc(1, 2); + MulAcc(2, 1); + MulAcc(3, 0); + + SaveMulAcc(3, 0, 4); + MulAcc(1, 3); + MulAcc(2, 2); + MulAcc(3, 1); + MulAcc(4, 0); + + SaveMulAcc(4, 0, 5); + MulAcc(1, 4); + MulAcc(2, 3); + MulAcc(3, 2); + MulAcc(4, 1); + MulAcc(5, 0); + + SaveMulAcc(5, 0, 6); + MulAcc(1, 5); + MulAcc(2, 4); + MulAcc(3, 3); + MulAcc(4, 2); + MulAcc(5, 1); + MulAcc(6, 0); + + SaveMulAcc(6, 0, 7); + MulAcc(1, 6); + MulAcc(2, 5); + MulAcc(3, 4); + MulAcc(4, 3); + MulAcc(5, 2); + MulAcc(6, 1); + MulAcc(7, 0); + + SaveMulAcc(7, 1, 7); + MulAcc(2, 6); + MulAcc(3, 5); + MulAcc(4, 4); + MulAcc(5, 3); + MulAcc(6, 2); + MulAcc(7, 1); + + SaveMulAcc(8, 2, 7); + MulAcc(3, 6); + MulAcc(4, 5); + MulAcc(5, 4); + MulAcc(6, 3); + MulAcc(7, 2); + + SaveMulAcc(9, 3, 7); + MulAcc(4, 6); + MulAcc(5, 5); + MulAcc(6, 4); + MulAcc(7, 3); + + SaveMulAcc(10, 4, 7); + MulAcc(5, 6); + MulAcc(6, 5); + MulAcc(7, 4); + + SaveMulAcc(11, 5, 7); + MulAcc(6, 6); + MulAcc(7, 5); + + SaveMulAcc(12, 6, 7); + MulAcc(7, 6); + + R[13] = c; + p = (dword)A[7] * B[7] + d; + R[14] = LOW_WORD(p); + R[15] = e + HIGH_WORD(p); +} + +static void CombaMultiplyBottom4(word *R, const word *A, const word *B) +{ + dword p; + word c, d, e; + + p = (dword)A[0] * B[0]; + R[0] = LOW_WORD(p); + c = HIGH_WORD(p); + d = e = 0; + + MulAcc(0, 1); + MulAcc(1, 0); + + SaveMulAcc(1, 2, 0); + MulAcc(1, 1); + MulAcc(0, 2); + + R[2] = c; + R[3] = d + A[0] * B[3] + A[1] * B[2] + A[2] * B[1] + A[3] * B[0]; +} + +static void CombaMultiplyBottom8(word *R, const word *A, const word *B) +{ + dword p; + word c, d, e; + + p = (dword)A[0] * B[0]; + R[0] = LOW_WORD(p); + c = HIGH_WORD(p); + d = e = 0; + + MulAcc(0, 1); + MulAcc(1, 0); + + SaveMulAcc(1, 2, 0); + MulAcc(1, 1); + MulAcc(0, 2); + + SaveMulAcc(2, 0, 3); + MulAcc(1, 2); + MulAcc(2, 1); + MulAcc(3, 0); + + SaveMulAcc(3, 0, 4); + MulAcc(1, 3); + MulAcc(2, 2); + MulAcc(3, 1); + MulAcc(4, 0); + + SaveMulAcc(4, 0, 5); + MulAcc(1, 4); + MulAcc(2, 3); + MulAcc(3, 2); + MulAcc(4, 1); + MulAcc(5, 0); + + SaveMulAcc(5, 0, 6); + MulAcc(1, 5); + MulAcc(2, 4); + MulAcc(3, 3); + MulAcc(4, 2); + MulAcc(5, 1); + MulAcc(6, 0); + + R[6] = c; + R[7] = d + A[0] * B[7] + A[1] * B[6] + A[2] * B[5] + A[3] * B[4] + + A[4] * B[3] + A[5] * B[2] + A[6] * B[1] + A[7] * B[0]; +} + +#undef MulAcc +#undef SaveMulAcc +static void AtomicInverseModPower2(word *C, word A0, word A1) +{ + assert(A0%2==1); + + dword A=MAKE_DWORD(A0, A1), R=A0%8; + + for (unsigned i=3; i<2*WORD_BITS; i*=2) + R = R*(2-R*A); + + assert(R*A==1); + + C[0] = LOW_WORD(R); + C[1] = HIGH_WORD(R); +} +// ******************************************************** + +#define A0 A +#define A1 (A+N2) +#define B0 B +#define B1 (B+N2) + +#define T0 T +#define T1 (T+N2) +#define T2 (T+N) +#define T3 (T+N+N2) + +#define R0 R +#define R1 (R+N2) +#define R2 (R+N) +#define R3 (R+N+N2) + +// R[2*N] - result = A*B +// T[2*N] - temporary work space +// A[N] --- multiplier +// B[N] --- multiplicant + +void RecursiveMultiply(word *R, word *T, const word *A, const word *B, unsigned int N) +{ + assert(N>=2 && N%2==0); + + if (N==2) + AtomicMultiply(R, A, B); + else if (N==4) + CombaMultiply4(R, A, B); + else if (N==8) + CombaMultiply8(R, A, B); + else + { + const unsigned int N2 = N/2; + int carry; + + int aComp = Compare(A0, A1, N2); + int bComp = Compare(B0, B1, N2); + + switch (2*aComp + aComp + bComp) + { + case -4: + Subtract(R0, A1, A0, N2); + Subtract(R1, B0, B1, N2); + RecursiveMultiply(T0, T2, R0, R1, N2); + Subtract(T1, T1, R0, N2); + carry = -1; + break; + case -2: + Subtract(R0, A1, A0, N2); + Subtract(R1, B0, B1, N2); + RecursiveMultiply(T0, T2, R0, R1, N2); + carry = 0; + break; + case 2: + Subtract(R0, A0, A1, N2); + Subtract(R1, B1, B0, N2); + RecursiveMultiply(T0, T2, R0, R1, N2); + carry = 0; + break; + case 4: + Subtract(R0, A1, A0, N2); + Subtract(R1, B0, B1, N2); + RecursiveMultiply(T0, T2, R0, R1, N2); + Subtract(T1, T1, R1, N2); + carry = -1; + break; + default: + SetWords(T0, 0, N); + carry = 0; + } + + RecursiveMultiply(R0, T2, A0, B0, N2); + RecursiveMultiply(R2, T2, A1, B1, N2); + + // now T[01] holds (A1-A0)*(B0-B1), R[01] holds A0*B0, R[23] holds A1*B1 + + carry += Add(T0, T0, R0, N); + carry += Add(T0, T0, R2, N); + carry += Add(R1, R1, T0, N); + + assert (carry >= 0 && carry <= 2); + Increment(R3, N2, carry); + } +} + +// R[2*N] - result = A*A +// T[2*N] - temporary work space +// A[N] --- number to be squared + +void RecursiveSquare(word *R, word *T, const word *A, unsigned int N) +{ + assert(N && N%2==0); + + if (N==2) + AtomicMultiply(R, A, A); + else if (N==4) + { + // VC60 workaround: MSVC 6.0 has an optimization problem that makes + // (dword)A*B where either A or B has been cast to a dword before + // very expensive. Revisit a CombaSquare4() function when this + // problem is fixed. + +// WARNING: KeithR. 05/08/03 This routine doesn't work with gcc on hardware +// either. I've completely removed it. It may be worth looking into sometime +// in the future. Therefore, we use the CombaMultiply4 on all targets. +//#ifdef __WINS__ + CombaMultiply4(R, A, A); +/*#else + CombaSquare4(R, A); +#endif*/ + } + else + { + const unsigned int N2 = N/2; + + RecursiveSquare(R0, T2, A0, N2); + RecursiveSquare(R2, T2, A1, N2); + RecursiveMultiply(T0, T2, A0, A1, N2); + + word carry = Add(R1, R1, T0, N); + carry += Add(R1, R1, T0, N); + Increment(R3, N2, carry); + } +} +// R[N] - bottom half of A*B +// T[N] - temporary work space +// A[N] - multiplier +// B[N] - multiplicant + +void RecursiveMultiplyBottom(word *R, word *T, const word *A, const word *B, unsigned int N) +{ + assert(N>=2 && N%2==0); + + if (N==2) + AtomicMultiplyBottom(R, A, B); + else if (N==4) + CombaMultiplyBottom4(R, A, B); + else if (N==8) + CombaMultiplyBottom8(R, A, B); + else + { + const unsigned int N2 = N/2; + + RecursiveMultiply(R, T, A0, B0, N2); + RecursiveMultiplyBottom(T0, T1, A1, B0, N2); + Add(R1, R1, T0, N2); + RecursiveMultiplyBottom(T0, T1, A0, B1, N2); + Add(R1, R1, T0, N2); + } +} + +// R[N] --- upper half of A*B +// T[2*N] - temporary work space +// L[N] --- lower half of A*B +// A[N] --- multiplier +// B[N] --- multiplicant + +void RecursiveMultiplyTop(word *R, word *T, const word *L, const word *A, const word *B, unsigned int N) +{ + assert(N>=2 && N%2==0); + + if (N==2) + { + AtomicMultiply(T, A, B); + ((dword *)R)[0] = ((dword *)T)[1]; + } + else if (N==4) + { + CombaMultiply4(T, A, B); + ((dword *)R)[0] = ((dword *)T)[2]; + ((dword *)R)[1] = ((dword *)T)[3]; + } + else + { + const unsigned int N2 = N/2; + int carry; + + int aComp = Compare(A0, A1, N2); + int bComp = Compare(B0, B1, N2); + + switch (2*aComp + aComp + bComp) + { + case -4: + Subtract(R0, A1, A0, N2); + Subtract(R1, B0, B1, N2); + RecursiveMultiply(T0, T2, R0, R1, N2); + Subtract(T1, T1, R0, N2); + carry = -1; + break; + case -2: + Subtract(R0, A1, A0, N2); + Subtract(R1, B0, B1, N2); + RecursiveMultiply(T0, T2, R0, R1, N2); + carry = 0; + break; + case 2: + Subtract(R0, A0, A1, N2); + Subtract(R1, B1, B0, N2); + RecursiveMultiply(T0, T2, R0, R1, N2); + carry = 0; + break; + case 4: + Subtract(R0, A1, A0, N2); + Subtract(R1, B0, B1, N2); + RecursiveMultiply(T0, T2, R0, R1, N2); + Subtract(T1, T1, R1, N2); + carry = -1; + break; + default: + SetWords(T0, 0, N); + carry = 0; + } + + RecursiveMultiply(T2, R0, A1, B1, N2); + + // now T[01] holds (A1-A0)*(B0-B1), T[23] holds A1*B1 + + CopyWords(R0, L+N2, N2); + word c2 = Subtract(R0, R0, L, N2); + c2 += Subtract(R0, R0, T0, N2); + word t = (Compare(R0, T2, N2) == -1); + + carry += t; + carry += Increment(R0, N2, c2+t); + carry += Add(R0, R0, T1, N2); + carry += Add(R0, R0, T3, N2); + + CopyWords(R1, T3, N2); + assert (carry >= 0 && carry <= 2); + Increment(R1, N2, carry); + } +} + +// R[NA+NB] - result = A*B +// T[NA+NB] - temporary work space +// A[NA] ---- multiplier +// B[NB] ---- multiplicant + +void AsymmetricMultiply(word *R, word *T, const word *A, unsigned int NA, const word *B, unsigned int NB) +{ + if (NA == NB) + { + if (A == B) + RecursiveSquare(R, T, A, NA); + else + RecursiveMultiply(R, T, A, B, NA); + + return; + } + + if (NA > NB) + { + TClassSwap(A, B); + TClassSwap(NA, NB); + //std::swap(A, B); + //std::swap(NA, NB); + } + + assert(NB % NA == 0); + assert((NB/NA)%2 == 0); // NB is an even multiple of NA + + if (NA==2 && !A[1]) + { + switch (A[0]) + { + case 0: + SetWords(R, 0, NB+2); + return; + case 1: + CopyWords(R, B, NB); + R[NB] = R[NB+1] = 0; + return; + default: + R[NB] = LinearMultiply(R, B, A[0], NB); + R[NB+1] = 0; + return; + } + } + + RecursiveMultiply(R, T, A, B, NA); + CopyWords(T+2*NA, R+NA, NA); + + unsigned i; + + for (i=2*NA; i B1 || (A[1]==B1 && A[0]>=B0)) + { + u = (dword) A[0] - B0; + A[0] = LOW_WORD(u); + u = (dword) A[1] - B1 - (word)(0-HIGH_WORD(u)); + A[1] = LOW_WORD(u); + A[2] += HIGH_WORD(u); + Q++; + assert(Q); // shouldn't overflow + } + + return Q; +} + +// do a 4 word by 2 word divide, returns 2 word quotient in Q0 and Q1 +static inline void AtomicDivide(word *Q, const word *A, const word *B) +{ + if (!B[0] && !B[1]) // if divisor is 0, we assume divisor==2**(2*WORD_BITS) + { + Q[0] = A[2]; + Q[1] = A[3]; + } + else + { + word T[4]; + T[0] = A[0]; T[1] = A[1]; T[2] = A[2]; T[3] = A[3]; + Q[1] = SubatomicDivide(T+1, B[0], B[1]); + Q[0] = SubatomicDivide(T, B[0], B[1]); + +#ifdef _DEBUG + // multiply quotient and divisor and add remainder, make sure it equals dividend + assert(!T[2] && !T[3] && (T[1] < B[1] || (T[1]==B[1] && T[0]= 0) + { + R[N] -= Subtract(R, R, B, N); + Q[1] += (++Q[0]==0); + assert(Q[0] || Q[1]); // no overflow + } +} + +// R[NB] -------- remainder = A%B +// Q[NA-NB+2] --- quotient = A/B +// T[NA+2*NB+4] - temp work space +// A[NA] -------- dividend +// B[NB] -------- divisor + +void Divide(word *R, word *Q, word *T, const word *A, unsigned int NA, const word *B, unsigned int NB) +{ + assert(NA && NB && NA%2==0 && NB%2==0); + assert(B[NB-1] || B[NB-2]); + assert(NB <= NA); + + // set up temporary work space + word *const TA=T; + word *const TB=T+NA+2; + word *const TP=T+NA+2+NB; + + // copy B into TB and normalize it so that TB has highest bit set to 1 + unsigned shiftWords = (B[NB-1]==0); + TB[0] = TB[NB-1] = 0; + CopyWords(TB+shiftWords, B, NB-shiftWords); + unsigned shiftBits = WORD_BITS - BitPrecision(TB[NB-1]); + assert(shiftBits < WORD_BITS); + ShiftWordsLeftByBits(TB, NB, shiftBits); + + // copy A into TA and normalize it + TA[0] = TA[NA] = TA[NA+1] = 0; + CopyWords(TA+shiftWords, A, NA); + ShiftWordsLeftByBits(TA, NA+2, shiftBits); + + if (TA[NA+1]==0 && TA[NA] <= 1) + { + Q[NA-NB+1] = Q[NA-NB] = 0; + while (TA[NA] || Compare(TA+NA-NB, TB, NB) >= 0) + { + TA[NA] -= Subtract(TA+NA-NB, TA+NA-NB, TB, NB); + ++Q[NA-NB]; + } + } + else + { + NA+=2; + assert(Compare(TA+NA-NB, TB, NB) < 0); + } + + word BT[2]; + BT[0] = TB[NB-2] + 1; + BT[1] = TB[NB-1] + (BT[0]==0); + + // start reducing TA mod TB, 2 words at a time + for (unsigned i=NA-2; i>=NB; i-=2) + { + AtomicDivide(Q+i-NB, TA+i-2, BT); + CorrectQuotientEstimate(TA+i-NB, TP, Q+i-NB, TB, NB); + } + + // copy TA into R, and denormalize it + CopyWords(R, TA+shiftWords, NB); + ShiftWordsRightByBits(R, NB, shiftBits); +} + +static inline unsigned int EvenWordCount(const word *X, unsigned int N) +{ + while (N && X[N-2]==0 && X[N-1]==0) + N-=2; + return N; +} + +// return k +// R[N] --- result = A^(-1) * 2^k mod M +// T[4*N] - temporary work space +// A[NA] -- number to take inverse of +// M[N] --- modulus + +unsigned int AlmostInverse(word *R, word *T, const word *A, unsigned int NA, const word *M, unsigned int N) +{ + assert(NA<=N && N && N%2==0); + + word *b = T; + word *c = T+N; + word *f = T+2*N; + word *g = T+3*N; + unsigned int bcLen=2, fgLen=EvenWordCount(M, N); + unsigned int k=0, s=0; + + SetWords(T, 0, 3*N); + b[0]=1; + CopyWords(f, A, NA); + CopyWords(g, M, N); + + FOREVER + { + word t=f[0]; + while (!t) + { + if (EvenWordCount(f, fgLen)==0) + { + SetWords(R, 0, N); + return 0; + } + + ShiftWordsRightByWords(f, fgLen, 1); + if (c[bcLen-1]) bcLen+=2; + assert(bcLen <= N); + ShiftWordsLeftByWords(c, bcLen, 1); + k+=WORD_BITS; + t=f[0]; + } + + unsigned int i=0; + while (t%2 == 0) + { + t>>=1; + i++; + } + k+=i; + + if (t==1 && f[1]==0 && EvenWordCount(f, fgLen)==2) + { + if (s%2==0) + CopyWords(R, b, N); + else + Subtract(R, M, b, N); + return k; + } + + ShiftWordsRightByBits(f, fgLen, i); + t=ShiftWordsLeftByBits(c, bcLen, i); + if (t) + { + c[bcLen] = t; + bcLen+=2; + assert(bcLen <= N); + } + + if (f[fgLen-2]==0 && g[fgLen-2]==0 && f[fgLen-1]==0 && g[fgLen-1]==0) + fgLen-=2; + + if (Compare(f, g, fgLen)==-1) + { + TClassSwap(f,g); + TClassSwap(b,c); + s++; + } + + Subtract(f, f, g, fgLen); + + if (Add(b, b, c, bcLen)) + { + b[bcLen] = 1; + bcLen+=2; + assert(bcLen <= N); + } + } +} + +// R[N] - result = A/(2^k) mod M +// A[N] - input +// M[N] - modulus + +void DivideByPower2Mod(word *R, const word *A, unsigned int k, const word *M, unsigned int N) +{ + CopyWords(R, A, N); + + while (k--) + { + if (R[0]%2==0) + ShiftWordsRightByBits(R, N, 1); + else + { + word carry = Add(R, R, M, N); + ShiftWordsRightByBits(R, N, 1); + R[N-1] += carry<<(WORD_BITS-1); + } + } +} + diff -r 7e3f204e6c81 -r f9c11be8c0b3 crypto/weakcryptospi/source/bigint/algorithms.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/crypto/weakcryptospi/source/bigint/algorithms.h Tue Dec 01 11:12:04 2009 +0000 @@ -0,0 +1,51 @@ +/* +* Copyright (c) 2003-2009 Nokia Corporation and/or its subsidiary(-ies). +* All rights reserved. +* This component and the accompanying materials are made available +* under the terms of the License "Eclipse Public License v1.0" +* which accompanies this distribution, and is available +* at the URL "http://www.eclipse.org/legal/epl-v10.html". +* +* Initial Contributors: +* Nokia Corporation - initial contribution. +* +* Contributors: +* +* Description: +* Bigint algorithms header file +* +*/ + + +/** + @file + @internalTechnology +*/ + +#ifndef __ALGORITHMS_H__ +#define __ALGORITHMS_H__ + +#include "../common/inlines.h" + +word Add(word* C, const word* A, const word* B, unsigned int N); +word Subtract(word* C, const word* A, const word* B, unsigned int N); +int Compare(const word *A, const word *B, unsigned int N); +void IncrementNoCarry(word *A, unsigned int N, word B=1); +word Increment(word *A, unsigned int N, word B=1); +void DecrementNoCarry(word *A, unsigned int N, word B=1); +word Decrement(word *A, unsigned int N, word B=1); +void TwosComplement(word *A, unsigned int N); +void Divide(word* R, word* Q, word* T, const word* A, unsigned int NA, + const word* B, unsigned int NB); +unsigned int AlmostInverse(word *R, word *T, const word *A, unsigned int NA, + const word *M, unsigned int N); +void DivideByPower2Mod(word *R, const word *A, unsigned int k, const word *M, + unsigned int N); +void RecursiveInverseModPower2(word *R, word *T, const word *A, unsigned int N); +void AsymmetricMultiply(word *R, word *T, const word *A, unsigned int NA, + const word *B, unsigned int NB); +void MontgomeryReduce(word *R, word *T, const word *X, const word *M, + const word *U, unsigned int N); +void RecursiveSquare(word *R, word *T, const word *A, unsigned int N); + +#endif diff -r 7e3f204e6c81 -r f9c11be8c0b3 crypto/weakcryptospi/source/bigint/bigint.cpp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/crypto/weakcryptospi/source/bigint/bigint.cpp Tue Dec 01 11:12:04 2009 +0000 @@ -0,0 +1,1174 @@ +/* +* Copyright (c) 2003-2009 Nokia Corporation and/or its subsidiary(-ies). +* All rights reserved. +* This component and the accompanying materials are made available +* under the terms of the License "Eclipse Public License v1.0" +* which accompanies this distribution, and is available +* at the URL "http://www.eclipse.org/legal/epl-v10.html". +* +* Initial Contributors: +* Nokia Corporation - initial contribution. +* +* Contributors: +* +* Description: +* +*/ + + +#include +#include +#include +#include +#include +#include "words.h" +#include "algorithms.h" +#include "windowslider.h" +#include "stackinteger.h" +#include "mont.h" + + +/** +* Creates a new buffer containing the big-endian binary representation of this +* integer. +* +* Note that it does not support the exporting of negative integers. +* +* @return The new buffer. +* +* @leave KErrNegativeExportNotSupported If this instance is a negative integer. +* +*/ +EXPORT_C HBufC8* TInteger::BufferLC() const + { + if(IsNegative()) + { + User::Leave(KErrNegativeExportNotSupported); + } + TUint bytes = ByteCount(); + HBufC8* buf = HBufC8::NewMaxLC(bytes); + TUint8* bufPtr = (TUint8*)(buf->Ptr()); + TUint8* regPtr = (TUint8*)Ptr(); + + // we internally store the number little endian, as a string we want it big + // endian + for(TUint i=0,j=bytes-1; iPtr()); + TUint8* regPtr = (TUint8*)Ptr(); + for(TUint i=0,j=bytes-1; i(KBigintZero); + } + +/** + * Gets the TInteger that represents one + * + * @return The TInteger representing one + */ +EXPORT_C const TInteger& TInteger::One(void) + { + return *reinterpret_cast(KBigintOne); + } + +/** + * Gets the TInteger that represents two + * + * @return The TInteger representing two + */ +EXPORT_C const TInteger& TInteger::Two(void) + { + return *reinterpret_cast(KBigintTwo); + } + +EXPORT_C RInteger TInteger::PlusL(const TInteger& aOperand) const + { + RInteger sum; + if (NotNegative()) + { + if (aOperand.NotNegative()) + sum = PositiveAddL(*this, aOperand); + else + sum = PositiveSubtractL(*this, aOperand); + } + else + { + if (aOperand.NotNegative()) + sum = PositiveSubtractL(aOperand, *this); + else + { + sum = PositiveAddL(*this, aOperand); + sum.SetSign(TInteger::ENegative); + } + } + return sum; + } + +EXPORT_C RInteger TInteger::MinusL(const TInteger& aOperand) const + { + RInteger diff; + if (NotNegative()) + { + if (aOperand.NotNegative()) + diff = PositiveSubtractL(*this, aOperand); + else + diff = PositiveAddL(*this, aOperand); + } + else + { + if (aOperand.NotNegative()) + { + diff = PositiveAddL(*this, aOperand); + diff.SetSign(TInteger::ENegative); + } + else + diff = PositiveSubtractL(aOperand, *this); + } + return diff; + } + +EXPORT_C RInteger TInteger::TimesL(const TInteger& aOperand) const + { + RInteger product = PositiveMultiplyL(*this, aOperand); + + if (NotNegative() != aOperand.NotNegative()) + { + product.Negate(); + } + return product; + } + +EXPORT_C RInteger TInteger::DividedByL(const TInteger& aOperand) const + { + RInteger quotient; + RInteger remainder; + DivideL(remainder, quotient, *this, aOperand); + remainder.Close(); + return quotient; + } + +EXPORT_C RInteger TInteger::ModuloL(const TInteger& aOperand) const + { + RInteger remainder; + RInteger quotient; + DivideL(remainder, quotient, *this, aOperand); + quotient.Close(); + return remainder; + } + +EXPORT_C TUint TInteger::ModuloL(TUint aOperand) const + { + if(!aOperand) + { + User::Leave(KErrDivideByZero); + } + return Modulo(*this, aOperand); + } + +EXPORT_C RInteger TInteger::ModularMultiplyL(const TInteger& aA, const TInteger& aB, + const TInteger& aMod) + { + RInteger product = aA.TimesL(aB); + CleanupStack::PushL(product); + RInteger reduced = product.ModuloL(aMod); + CleanupStack::PopAndDestroy(&product); + return reduced; + } + +EXPORT_C RInteger TInteger::ModularExponentiateL(const TInteger& aBase, + const TInteger& aExp, const TInteger& aMod) + { + CMontgomeryStructure* mont = CMontgomeryStructure::NewLC(aMod); + RInteger result = RInteger::NewL(mont->ExponentiateL(aBase, aExp)); + CleanupStack::PopAndDestroy(mont); + return result; + } + +EXPORT_C RInteger TInteger::GCDL(const TInteger& aOperand) const + { + //Binary GCD algorithm -- see HAC 14.4.1 + //with a slight variation -- our g counts shifts rather than actually + //shifting. We then do one shift at the end. + assert(NotNegative()); + assert(aOperand.NotNegative()); + + RInteger x = RInteger::NewL(*this); + CleanupStack::PushL(x); + RInteger y = RInteger::NewL(aOperand); + CleanupStack::PushL(y); + + // 1 Ensure x >= y + if( x < y ) + { + TClassSwap(x, y); + } + + TUint g = 0; + // 2 while x and y even x <- x/2, y <- y/2 + while( x.IsEven() && y.IsEven() ) + { + x >>= 1; + y >>= 1; + ++g; + } + // 3 while x != 0 + while( x.NotZero() ) + { + // 3.1 while x even x <- x/2 + while( x.IsEven() ) + { + x >>= 1; + } + // 3.2 while y even y <- y/2 + while( y.IsEven() ) + { + y >>= 1; + } + // 3.3 t <- abs(x-y)/2 + RInteger t = x.MinusL(y); + t >>= 1; + t.SetSign(TInteger::EPositive); + + // 3.4 If x>=y then x <- t else y <- t + if( x >= y ) + { + x.Set(t); + } + else + { + y.Set(t); + } + } + + // 4 Return (g*y) (equiv to y<<=g as our g was counting shifts not actually + //shifting) + y <<= g; + CleanupStack::Pop(&y); + CleanupStack::PopAndDestroy(&x); + return y; + } + +EXPORT_C RInteger TInteger::InverseModL(const TInteger& aMod) const + { + assert(aMod.NotNegative()); + + RInteger result; + if(IsNegative() || *this>=aMod) + { + RInteger temp = ModuloL(aMod); + CleanupClosePushL(temp); + result = temp.InverseModL(aMod); + CleanupStack::PopAndDestroy(&temp); + return result; + } + + if(aMod.IsEven()) + { + if( !aMod || IsEven() ) + { + return RInteger::NewL(Zero()); + } + if( *this == One() ) + { + return RInteger::NewL(One()); + } + RInteger u = aMod.InverseModL(*this); + CleanupClosePushL(u); + if(!u) + { + result = RInteger::NewL(Zero()); + } + else + { + //calculates (aMod*(*this-u)+1)/(*this) + result = MinusL(u); + CleanupClosePushL(result); + result *= aMod; + ++result; + result /= *this; + CleanupStack::Pop(&result); + } + CleanupStack::PopAndDestroy(&u); + return result; + } + + result = RInteger::NewEmptyL(aMod.Size()); + CleanupClosePushL(result); + RInteger workspace = RInteger::NewEmptyL(aMod.Size() * 4); + TUint k = AlmostInverse(result.Ptr(), workspace.Ptr(), Ptr(), Size(), + aMod.Ptr(), aMod.Size()); + DivideByPower2Mod(result.Ptr(), result.Ptr(), k, aMod.Ptr(), aMod.Size()); + workspace.Close(); + CleanupStack::Pop(&result); + + return result; + } + +EXPORT_C TInteger& TInteger::operator+=(const TInteger& aOperand) + { + this->Set(PlusL(aOperand)); + return *this; + } + +EXPORT_C TInteger& TInteger::operator-=(const TInteger& aOperand) + { + this->Set(MinusL(aOperand)); + return *this; + } + +EXPORT_C TInteger& TInteger::operator*=(const TInteger& aOperand) + { + this->Set(TimesL(aOperand)); + return *this; + } + +EXPORT_C TInteger& TInteger::operator/=(const TInteger& aOperand) + { + this->Set(DividedByL(aOperand)); + return *this; + } + +EXPORT_C TInteger& TInteger::operator%=(const TInteger& aOperand) + { + this->Set(ModuloL(aOperand)); + return *this; + } + +EXPORT_C TInteger& TInteger::operator+=(TInt aOperand) + { + TStackInteger64 operand(aOperand); + *this += operand; + return *this; + } + +EXPORT_C TInteger& TInteger::operator-=(TInt aOperand) + { + TStackInteger64 operand(aOperand); + *this -= operand; + return *this; + } + +EXPORT_C TInteger& TInteger::operator*=(TInt aOperand) + { + TStackInteger64 operand(aOperand); + *this *= operand; + return *this; + } + +EXPORT_C TInteger& TInteger::operator--() + { + if (IsNegative()) + { + if (Increment(Ptr(), Size())) + { + CleanGrowL(2*Size()); + (Ptr())[Size()/2]=1; + } + } + else + { + if (Decrement(Ptr(), Size())) + { + this->CopyL(-1); + } + } + return *this; + } + +EXPORT_C TInteger& TInteger::operator++() + { + if(NotNegative()) + { + if(Increment(Ptr(), Size())) + { + CleanGrowL(2*Size()); + (Ptr())[Size()/2]=1; + } + } + else + { + DecrementNoCarry(Ptr(), Size()); + if(WordCount()==0) + { + this->CopyL(Zero()); + } + } + return *this; + } + +EXPORT_C TInteger& TInteger::operator <<=(TUint aBits) + { + const TUint wordCount = WordCount(); + const TUint shiftWords = aBits / WORD_BITS; + const TUint shiftBits = aBits % WORD_BITS; + + CleanGrowL(wordCount+BitsToWords(aBits)); + ShiftWordsLeftByWords(Ptr(), wordCount + shiftWords, shiftWords); + ShiftWordsLeftByBits(Ptr()+shiftWords, wordCount + BitsToWords(shiftBits), + shiftBits); + return *this; + } + +EXPORT_C TInteger& TInteger::operator >>=(TUint aBits) + { + const TUint wordCount = WordCount(); + const TUint shiftWords = aBits / WORD_BITS; + const TUint shiftBits = aBits % WORD_BITS; + + ShiftWordsRightByWords(Ptr(), wordCount, shiftWords); + if(wordCount > shiftWords) + { + ShiftWordsRightByBits(Ptr(), wordCount - shiftWords, shiftBits); + } + if(IsNegative() && WordCount()==0) // avoid negative 0 + { + SetSign(EPositive); + } + return *this; + } + +EXPORT_C TInt TInteger::UnsignedCompare(const TInteger& aThat) const + { + TUint size = WordCount(); + TUint thatSize = aThat.WordCount(); + + if( size == thatSize ) + return Compare(Ptr(), aThat.Ptr(), size); + else + return size > thatSize ? 1 : -1; + } + +EXPORT_C TInt TInteger::SignedCompare(const TInteger& aThat) const + { + if (NotNegative()) + { + if (aThat.NotNegative()) + return UnsignedCompare(aThat); + else + return 1; + } + else + { + if (aThat.NotNegative()) + return -1; + else + return -UnsignedCompare(aThat); + } + } + +EXPORT_C TBool TInteger::operator!() const + { + //Ptr()[0] is just a quick way of weeding out non-zero numbers without + //doing a full WordCount() == 0. Very good odds that a non-zero number + //will have a bit set in the least significant word + return IsNegative() ? EFalse : (Ptr()[0]==0 && WordCount()==0); + } + +EXPORT_C TInt TInteger::SignedCompare(TInt aInteger) const + { + TStackInteger64 temp(aInteger); + return SignedCompare(temp); + } + +/* TBool IsPrimeL(void) const + * and all primality related functions are implemented in primes.cpp */ + +EXPORT_C TBool TInteger::Bit(TUint aBitPos) const + { + if( aBitPos/WORD_BITS >= Size() ) + { + return 0; + } + else + { + return (((Ptr())[aBitPos/WORD_BITS] >> (aBitPos % WORD_BITS)) & 1); + } + } + +EXPORT_C void TInteger::SetBit(TUint aBitPos) + { + if( aBitPos/WORD_BITS < Size() ) + { + ArraySetBit(Ptr(), aBitPos); + } + } + +EXPORT_C void TInteger::Negate() + { + if(!!(*this)) //don't flip sign if *this==0 + { + SetSign(TSign((~Sign())&KSignMask)); + } + } + +EXPORT_C void TInteger::CopyL(const TInteger& aInteger, TBool aAllowShrink) + { + if(aAllowShrink) + { + CleanResizeL(aInteger.Size()); + } + else + { + CleanGrowL(aInteger.Size()); + } + Construct(aInteger); + } + +EXPORT_C void TInteger::CopyL(TInt aInteger, TBool aAllowShrink) + { + if(aAllowShrink) + { + CleanResizeL(2); + } + else + { + CleanGrowL(2); + } + Construct(aInteger); + } + +EXPORT_C void TInteger::Set(const RInteger& aInteger) + { + assert(IsHeapBased()); + Mem::FillZ(Ptr(), WordsToBytes(Size())); + User::Free(Ptr()); + iPtr = aInteger.iPtr; + iSize = aInteger.iSize; + } + +RInteger TInteger::PositiveAddL(const TInteger &aA, const TInteger& aB) const + { + RInteger sum = RInteger::NewEmptyL(CryptoMax(aA.Size(), aB.Size())); + const word aSize = aA.Size(); + const word bSize = aB.Size(); + const word* const aReg = aA.Ptr(); + const word* const bReg = aB.Ptr(); + word* const sumReg = sum.Ptr(); + + word carry; + if (aSize == bSize) + carry = Add(sumReg, aReg, bReg, aSize); + else if (aSize > bSize) + { + carry = Add(sumReg, aReg, bReg, bSize); + CopyWords(sumReg+bSize, aReg+bSize, aSize-bSize); + carry = Increment(sumReg+bSize, aSize-bSize, carry); + } + else + { + carry = Add(sumReg, aReg, bReg, aSize); + CopyWords(sumReg+aSize, bReg+aSize, bSize-aSize); + carry = Increment(sumReg+aSize, bSize-aSize, carry); + } + + if (carry) + { + CleanupStack::PushL(sum); + sum.CleanGrowL(2*sum.Size()); + CleanupStack::Pop(&sum); + sum.Ptr()[sum.Size()/2] = 1; + } + sum.SetSign(TInteger::EPositive); + return sum; + } + +RInteger TInteger::PositiveSubtractL(const TInteger &aA, const TInteger& aB) const + { + RInteger diff = RInteger::NewEmptyL(CryptoMax(aA.Size(), aB.Size())); + unsigned aSize = aA.WordCount(); + aSize += aSize%2; + unsigned bSize = aB.WordCount(); + bSize += bSize%2; + const word* const aReg = aA.Ptr(); + const word* const bReg = aB.Ptr(); + word* const diffReg = diff.Ptr(); + + if (aSize == bSize) + { + if (Compare(aReg, bReg, aSize) >= 0) + { + Subtract(diffReg, aReg, bReg, aSize); + diff.SetSign(TInteger::EPositive); + } + else + { + Subtract(diffReg, bReg, aReg, aSize); + diff.SetSign(TInteger::ENegative); + } + } + else if (aSize > bSize) + { + word borrow = Subtract(diffReg, aReg, bReg, bSize); + CopyWords(diffReg+bSize, aReg+bSize, aSize-bSize); + borrow = Decrement(diffReg+bSize, aSize-bSize, borrow); + assert(!borrow); + diff.SetSign(TInteger::EPositive); + } + else + { + word borrow = Subtract(diffReg, bReg, aReg, aSize); + CopyWords(diffReg+aSize, bReg+aSize, bSize-aSize); + borrow = Decrement(diffReg+aSize, bSize-aSize, borrow); + assert(!borrow); + diff.SetSign(TInteger::ENegative); + } + return diff; + } + +RInteger TInteger::PositiveMultiplyL(const TInteger &aA, const TInteger &aB) const + { + unsigned aSize = RoundupSize(aA.WordCount()); + unsigned bSize = RoundupSize(aB.WordCount()); + + RInteger product = RInteger::NewEmptyL(aSize+bSize); + CleanupClosePushL(product); + + RInteger workspace = RInteger::NewEmptyL(aSize + bSize); + AsymmetricMultiply(product.Ptr(), workspace.Ptr(), aA.Ptr(), aSize, aB.Ptr(), + bSize); + workspace.Close(); + CleanupStack::Pop(&product); + return product; + } + +TUint TInteger::Modulo(const TInteger& aDividend, TUint aDivisor) const + { + assert(aDivisor); + TUint i = aDividend.WordCount(); + TUint remainder = 0; + while(i--) + { + remainder = TUint(MAKE_DWORD(aDividend.Ptr()[i], remainder) % aDivisor); + } + return remainder; + } + +void TInteger::PositiveDivideL(RInteger &aRemainder, RInteger &aQuotient, + const TInteger &aDividend, const TInteger &aDivisor) const + { + unsigned dividendSize = aDividend.WordCount(); + unsigned divisorSize = aDivisor.WordCount(); + + if (!divisorSize) + { + User::Leave(KErrDivideByZero); + } + + if (aDividend.UnsignedCompare(aDivisor) == -1) + { + aRemainder.CreateNewL(aDividend.Size()); + CleanupStack::PushL(aRemainder); + aRemainder.CopyL(aDividend); //set remainder to a + aRemainder.SetSign(TInteger::EPositive); + aQuotient.CleanNewL(2); //Set quotient to zero + CleanupStack::Pop(&aRemainder); + return; + } + + dividendSize += dividendSize%2; // round up to next even number + divisorSize += divisorSize%2; + + aRemainder.CleanNewL(divisorSize); + CleanupStack::PushL(aRemainder); + aQuotient.CleanNewL(dividendSize-divisorSize+2); + CleanupStack::PushL(aQuotient); + + RInteger T = RInteger::NewEmptyL(dividendSize+2*divisorSize+4); + Divide(aRemainder.Ptr(), aQuotient.Ptr(), T.Ptr(), aDividend.Ptr(), + dividendSize, aDivisor.Ptr(), divisorSize); + T.Close(); + CleanupStack::Pop(2, &aRemainder); //aQuotient, aRemainder + } + +void TInteger::DivideL(RInteger& aRemainder, RInteger& aQuotient, + const TInteger& aDividend, const TInteger& aDivisor) const + { + PositiveDivideL(aRemainder, aQuotient, aDividend, aDivisor); + + if (aDividend.IsNegative()) + { + aQuotient.Negate(); + if (aRemainder.NotZero()) + { + --aQuotient; + assert(aRemainder.Size() <= aDivisor.Size()); + Subtract(aRemainder.Ptr(), aDivisor.Ptr(), aRemainder.Ptr(), + aRemainder.Size()); + } + } + + if (aDivisor.IsNegative()) + aQuotient.Negate(); + } + +void TInteger::RandomizeL(TUint aBits, TRandomAttribute aAttr) + { + if(!aBits) + { + return; + } + const TUint bytes = BitsToBytes(aBits); + const TUint words = BitsToWords(aBits); + CleanGrowL(words); + TPtr8 buf((TUint8*)(Ptr()), bytes, WordsToBytes(Size())); + TUint bitpos = aBits % BYTE_BITS; + GenerateRandomBytesL(buf); + //mask with 0 all bits above the num requested in the most significant byte + if(bitpos) + { + buf[bytes-1] = TUint8( buf[bytes-1] & ((1L << bitpos) - 1) ); + } + //set most significant (top) bit + if(aAttr == ETopBitSet || aAttr == ETop2BitsSet) + { + SetBit(aBits-1); //Set bit counts from 0 + assert(BitCount() == aBits); + assert(Bit(aBits-1)); + } + //set 2nd bit from top + if(aAttr == ETop2BitsSet) + { + SetBit(aBits-2); //Set bit counts from 0 + assert(BitCount() == aBits); + assert(Bit(aBits-1)); + assert(Bit(aBits-2)); + } + } + +void TInteger::RandomizeL(const TInteger& aMin, const TInteger& aMax) + { + assert(aMax > aMin); + assert(aMin.NotNegative()); + RInteger range = RInteger::NewL(aMax); + CleanupStack::PushL(range); + range -= aMin; + const TUint bits = range.BitCount(); + + //if we find a number < range then aMin+range < aMax + do + { + RandomizeL(bits, EAllBitsRandom); + } + while(*this > range); + + *this += aMin; + CleanupStack::PopAndDestroy(&range); + } + +/* void PrimeRandomizeL(TUint aBits, TRandomAttribute aAttr) + * and all primality related functions are implemented in primes.cpp */ + +void TInteger::CreateNewL(TUint aNewSize) + { + //should only be called on construction + assert(!iPtr); + + TUint newSize = RoundupSize(aNewSize); + SetPtr((TUint*)User::AllocL(WordsToBytes(newSize))); + SetSize(newSize); + SetHeapBased(); + } + +void TInteger::CleanNewL(TUint aNewSize) + { + CreateNewL(aNewSize); + Mem::FillZ(Ptr(), WordsToBytes(Size())); //clear integer storage + } + +void TInteger::CleanGrowL(TUint aNewSize) + { + assert(IsHeapBased()); + TUint newSize = RoundupSize(aNewSize); + TUint oldSize = Size(); + if(newSize > oldSize) + { + TUint* oldPtr = Ptr(); + //1) allocate new memory and set ptr and size + SetPtr((TUint*)User::AllocL(WordsToBytes(newSize))); + SetSize(newSize); + //2) copy old mem to new mem + Mem::Copy(Ptr(), oldPtr, WordsToBytes(oldSize)); + //3) zero all old memory + Mem::FillZ(oldPtr, WordsToBytes(oldSize)); + //4) give back old memory + User::Free(oldPtr); + //5) zero new memory from end of copy to end of growth + Mem::FillZ(Ptr() + oldSize, WordsToBytes(newSize-oldSize)); + } + } + +void TInteger::CleanResizeL(TUint aNewSize) + { + assert(IsHeapBased()); + TUint newSize = RoundupSize(aNewSize); + TUint oldSize = Size(); + if(newSize > oldSize) + { + CleanGrowL(aNewSize); + } + else if(newSize < oldSize) + { + TUint* oldPtr = Ptr(); + //1) zero memory above newsize + Mem::FillZ(oldPtr+WordsToBytes(aNewSize),WordsToBytes(oldSize-newSize)); + //2) ReAlloc cell. Since our newsize is less than oldsize, it is + //guarenteed not to move. Thus this is just freeing part of our old + //cell to the heap for other uses. + SetPtr((TUint*)User::ReAllocL(Ptr(), WordsToBytes(newSize))); + SetSize(newSize); + } + } + +EXPORT_C TInteger::TInteger() : iSize(0), iPtr(0) + { + } + +void TInteger::Construct(const TDesC8& aValue) + { + assert(Size() >= BytesToWords(aValue.Size())); + if(aValue.Size() > 0) + { + //People write numbers with the most significant digits first (big + //endian) but we store our numbers in little endian. Hence we need to + //reverse the string by bytes. + + TUint bytes = aValue.Size(); + TUint8* i = (TUint8*)Ptr(); + TUint8* j = (TUint8*)aValue.Ptr() + bytes; + + //Swap the endianess of the number itself + // (msb) 01 02 03 04 05 06 (lsb) becomes -> + // (lsb) 06 05 04 03 02 01 (msb) + while( j != (TUint8*)aValue.Ptr() ) + { + *i++ = *--j; + } + Mem::FillZ((TUint8*)Ptr() + bytes, WordsToBytes(Size()) - bytes); + } + else + { + //if size is zero, we zero the whole register + Mem::FillZ((TUint8*)Ptr(), WordsToBytes(Size())); + } + SetSign(EPositive); + } + +void TInteger::Construct(const TInteger& aInteger) + { + assert(Size() >= aInteger.Size()); + CopyWords(Ptr(), aInteger.Ptr(), aInteger.Size()); + if(Size() > aInteger.Size()) + { + Mem::FillZ(Ptr()+aInteger.Size(), WordsToBytes(Size()-aInteger.Size())); + } + SetSign(aInteger.Sign()); + } + +void TInteger::Construct(TInt aInteger) + { + Construct((TUint)aInteger); + if(aInteger < 0) + { + SetSign(ENegative); + Ptr()[0] = -aInteger; + } + } + +void TInteger::Construct(TUint aInteger) + { + assert(Size() >= 2); + SetSign(EPositive); + Ptr()[0] = aInteger; + Mem::FillZ(Ptr()+1, WordsToBytes(Size()-1)); + } + +void TInteger::ConstructStack(TUint aWords, TUint aInteger) + { + SetPtr((TUint*)(this)+2); + //SetStackBased(); //Not strictly needed as stackbased is a 0 at bit 1 + SetSize(aWords); + assert(Size() >= 2); + Ptr()[0] = aInteger; + Mem::FillZ(&(Ptr()[1]), WordsToBytes(Size()-1)); + } + +void TInteger::ConstructStack(TUint aWords, const TInteger& aInteger) + { + SetPtr((TUint*)(this)+2); + //SetStackBased(); //Not strictly needed as stackbased is a 0 at bit 1 + SetSize(aWords); + assert( Size() >= RoundupSize(aInteger.WordCount()) ); + CopyWords(Ptr(), aInteger.Ptr(), aInteger.Size()); + Mem::FillZ(Ptr()+aInteger.Size(), WordsToBytes(Size()-aInteger.Size())); + } + +// Methods are excluded from coverage due to the problem with BullsEye on ONB. +// Manually verified that these methods are functionally covered. +#ifdef _BullseyeCoverage +#pragma suppress_warnings on +#pragma BullseyeCoverage off +#pragma suppress_warnings off +#endif + +EXPORT_C TInteger& TInteger::operator/=(TInt aOperand) + { + TStackInteger64 operand(aOperand); + *this /= operand; + return *this; + } + +EXPORT_C TInteger& TInteger::operator%=(TInt aOperand) + { + TStackInteger64 operand(aOperand); + assert(operand.NotNegative()); + *this %= operand; + return *this; + } + +EXPORT_C TInt TInteger::ConvertToLongL(void) const + { + if(!IsConvertableToLong()) + { + User::Leave(KErrTotalLossOfPrecision); + } + return ConvertToLong(); + } + +TInt TInteger::ConvertToLong(void) const + { + TUint value = ConvertToUnsignedLong(); + return Sign() == EPositive ? value : -(static_cast(value)); + } + +TBool TInteger::IsConvertableToLong(void) const + { + if(WordCount() > 1) + { + return EFalse; + } + TUint value = (Ptr())[0]; + if(Sign() == EPositive) + { + return static_cast(value) >= 0; + } + else + { + return -(static_cast(value)) < 0; + } + } + +EXPORT_C RInteger TInteger::SquaredL() const + { + //PositiveMultiplyL optimises for the squaring case already + //Any number squared is positive, no need for negative handling in TimesL + return PositiveMultiplyL(*this, *this); + } + +EXPORT_C RInteger TInteger::DividedByL(TUint aOperand) const + { + TUint remainder; + RInteger quotient; + DivideL(remainder, quotient, *this, aOperand); + return quotient; + } + +EXPORT_C RInteger TInteger::ExponentiateL(const TInteger& aExponent) const + { + //See HAC 14.85 + + // 1.1 Precomputation + // g1 <- g + // g2 <- g^2 + RInteger g2 = SquaredL(); + CleanupStack::PushL(g2); + RInteger g1 = RInteger::NewL(*this); + CleanupStack::PushL(g1); + TWindowSlider slider(aExponent); + + // 1.2 + // For i from 1 to (2^(k-1) -1) do g2i+1 <- g2i-1 * g2 + TUint count = (1 << (slider.WindowSize()-1)) - 1; //2^(k-1) -1 + RRArray powerArray(count+1); //+1 because we append g1 + User::LeaveIfError(powerArray.Append(g1)); + CleanupStack::Pop(); //g1 + CleanupClosePushL(powerArray); + for(TUint k=1; k <= count; k++) + { + RInteger g2iplus1 = g2.TimesL(powerArray[k-1]); + //This append can't fail as the granularity is set high enough + //plus we've already called Append once which will alloc to the + //set granularity + powerArray.Append(g2iplus1); + } + + // 2 A <- 1, i <- t + RInteger A = RInteger::NewL(One()); + CleanupStack::PushL(A); + TInt i = aExponent.BitCount() - 1; + + // 3 While i>=0 do: + while( i>=0 ) + { + // 3.1 If ei == 0 then A <- A^2 + if(!aExponent.Bit(i)) + { + A *= A; + i--; + } + // 3.2 Find longest bitstring ei,ei-1,...,el s.t. i-l+1<=k and el==1 + // and do: + // A <- (A^2^(i-l+1)) * g[the index indicated by the bitstring value] + else + { + slider.FindNextWindow(i); + assert(slider.Length() >= 1); + for(TUint j=0; j>1]; + i -= slider.Length(); + } + } + CleanupStack::Pop(&A); + CleanupStack::PopAndDestroy(2, &g2); //powerArray, g2 + return A; + } + +void TInteger::DivideL(TUint& aRemainder, RInteger& aQuotient, + const TInteger& aDividend, TUint aDivisor) const + { + if(!aDivisor) + { + User::Leave(KErrDivideByZero); + } + + TUint i = aDividend.WordCount(); + aQuotient.CleanNewL(RoundupSize(i)); + PositiveDivide(aRemainder, aQuotient, aDividend, aDivisor); + + if(aDividend.NotNegative()) + { + aQuotient.SetSign(TInteger::EPositive); + } + else + { + aQuotient.SetSign(TInteger::ENegative); + if(aRemainder) + { + --aQuotient; + aRemainder = aDivisor = aRemainder; + } + } + } + +void TInteger::PositiveDivide(TUint& aRemainder, TInteger& aQuotient, + const TInteger& aDividend, TUint aDivisor) const + { + assert(aDivisor); + + TUint i = aDividend.WordCount(); + assert(aQuotient.Size() >= RoundupSize(i)); + assert(aQuotient.Sign() == TInteger::EPositive); + aRemainder = 0; + while(i--) + { + aQuotient.Ptr()[i] = + TUint(MAKE_DWORD(aDividend.Ptr()[i], aRemainder) / aDivisor); + aRemainder = + TUint(MAKE_DWORD(aDividend.Ptr()[i], aRemainder) % aDivisor); + } + } diff -r 7e3f204e6c81 -r f9c11be8c0b3 crypto/weakcryptospi/source/bigint/gcchelp.cpp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/crypto/weakcryptospi/source/bigint/gcchelp.cpp Tue Dec 01 11:12:04 2009 +0000 @@ -0,0 +1,395 @@ +/* +* Copyright (c) 2005-2009 Nokia Corporation and/or its subsidiary(-ies). +* All rights reserved. +* This component and the accompanying materials are made available +* under the terms of the License "Eclipse Public License v1.0" +* which accompanies this distribution, and is available +* at the URL "http://www.eclipse.org/legal/epl-v10.html". +* +* Initial Contributors: +* Nokia Corporation - initial contribution. +* +* Contributors: +* +* Description: +* +*/ + + +/** + @file +*/ + + +#include // need this for __NAKED__, __JUMP and __POPRET + +extern "C" { +#ifdef __GCC32__ +__NAKED__ long long __divdi3(long long /*dividend*/, long long /*divisor*/) +// +// Dividend in r1:r0, divisor in r3:r2, Return quotient in r1:r0 +// + { + asm("stmfd sp!, {r4-r8,lr} "); + asm("eor r8, r1, r3 "); // sign of result into r8 + asm("movs r1, r1 "); + asm("bpl 1f "); + asm("rsbs r0, r0, #0 "); // ABS(dividend) + asm("rsc r1, r1, #0 "); + asm("1: "); + asm("movs r3, r3 "); + asm("bpl 2f "); + asm("rsbs r2, r2, #0 "); // ABS(divisor) + asm("rsc r3, r3, #0 "); + asm("2: "); + asm("bl UDiv01 "); // do the division, result in r4,r5 + asm("eors r0, r4, r8, asr #32 "); // quotient into r1:r0, inverted if quotient -ve + asm("eors r1, r5, r8, asr #32 "); + asm("adcs r0, r0, #0 "); // if quotient -ve, add 1 + asm("adcs r1, r1, #0 "); + __POPRET("r4-r8,"); + } + +__NAKED__ long long __moddi3(long long /*dividend*/, long long /*divisor*/) /* signed */ + { + asm("stmfd sp!, {r4-r8,lr} "); + asm("movs r8, r1 "); // sign of remainder (=sign of dividend) into r8 + asm("bpl 1f "); + asm("rsbs r0, r0, #0 "); // ABS(dividend) + asm("rsc r1, r1, #0 "); + asm("1: "); + asm("movs r3, r3 "); + asm("bpl 2f "); + asm("rsbs r2, r2, #0 "); // ABS(divisor) + asm("rsc r3, r3, #0 "); + asm("2: "); + asm("bl UDiv01 "); // do the division, remainder in r3,r6 + asm("eors r0, r3, r8, asr #32 "); // remainder into r1:r0, inverted if dividend -ve + asm("eors r1, r6, r8, asr #32 "); + asm("adcs r0, r0, #0 "); // if dividend -ve, add 1 + asm("adcs r1, r1, #0 "); + __POPRET("r4-r8,"); + } + +__NAKED__ long long __umoddi3(unsigned long long /*dividend*/, unsigned long long /*divisor*/) /* unsigned */ + { + asm("stmfd sp!, {r4-r7,lr} "); + asm("bl UDiv01 "); // do the division, remainder in r6:r3 + asm("mov r0, r3 "); + asm("mov r1, r6 "); + __POPRET("r4-r7,"); + } + +__NAKED__ long long __ashrdi3(long long /*value*/, unsigned int /*count*/) + { + asm("cmp r2, #63 "); + asm("movhi r2, #63 "); // count>63 same as count=63 + asm("cmp r2, #32 "); + asm("bcs Asr01 "); // jump if shift count >=32 + asm("rsb r12, r2, #32 "); // r12=32-shift count + asm("mov r0, r0, lsr r2 "); // shift ls word right + asm("orr r0, r0, r1, lsl r12 "); // or in bits shifted out of ms word + asm("mov r1, r1, asr r2 "); // shift ms word right + __JUMP(,lr); + asm("Asr01: "); + asm("sub r2, r2, #32 "); // r2=shift count-32 + asm("mov r0, r1, asr r2 "); // ls word = ms word >> (count-32) + asm("mov r1, r1, asr #32 "); // ms word of result=sign extension of r1 + __JUMP(,lr); + } + +__NAKED__ long long __ashldi3(long long /*value*/, unsigned int /*count*/) + { + asm("cmp r2, #63 "); + asm("movhi r2, #64 "); // count>63 same as count=64 + asm("cmp r2, #32 "); + asm("bcs Asl01 "); // jump if shift count >=32 + asm("rsb r12, r2, #32 "); // r12=32-shift count + asm("mov r1, r1, asl r2 "); // shift ms word left + asm("orr r1, r1, r0, lsr r12 "); // or in bits shifted out of ls word + asm("mov r0, r0, asl r2 "); // shift ls word left + __JUMP(,lr); + asm("Asl01: "); + asm("sub r2, r2, #32 "); // r2=shift count-32 + asm("mov r1, r0, asl r2 "); // result ms word = ls word << (count-32) + asm("mov r0, #0 "); // ls word of result is zero + __JUMP(,lr); + } + +__NAKED__ unsigned long long __lshrdi3(unsigned long long /*value*/, unsigned int /*count*/) + { + asm("cmp r2, #63 "); + asm("movhi r2, #64 "); // count>63 same as count=64 + asm("cmp r2, #32 "); + asm("bcs Lsr01 "); // jump if shift count >=32 + asm("rsb r12, r2, #32 "); // r12=32-shift count + asm("mov r0, r0, lsr r2 "); // shift ls word right + asm("orr r0, r0, r1, lsl r12 "); // or in bits shifted out of ms word + asm("mov r1, r1, lsr r2 "); // shift ms word right + __JUMP(,lr); + asm("Lsr01: "); + asm("sub r2, r2, #32 "); // r2=shift count-32 + asm("mov r0, r1, lsr r2 "); // ls word = ms word >> (count-32) + asm("mov r1, #0 "); // ms word of result = 0 + __JUMP(,lr); + } + +__NAKED__ long long __muldi3(long long /*multiplicand*/, long long /*multiplier*/) + { + asm("mul r1, r2, r1 "); // r1=low2*high1 + asm("mov ip, r0 "); // ip=low1 + asm("mla r1, r0, r3, r1 "); // r1+=low1*high2 + asm("mov r0, #0 "); + asm("umlal r0, r1, r2, ip "); // r1:r0 += high1*low1 + __JUMP(,lr); + } + +__NAKED__ long long __negdi2(long long /*argument*/) + { + asm("rsbs r0, r0, #0 "); // r0=0-r0, set carry + asm("rscs r1, r1, #0 "); // r1=0-r1-(1-C) + __JUMP(,lr); + } + +__NAKED__ unsigned long long __udivmoddi4 (unsigned long long /*dividend*/, + unsigned long long /*divisor*/, + unsigned long long* /*p_remainder*/) + { + asm("stmfd sp!, {r4-r7,lr} "); + asm("bl UDiv01 "); // do the division, quotient in r5:r4 remainder in r6:r3 + asm("ldr r7, [sp, #20] "); // r7=p_remainder + asm("mov r0, r4 "); // r0=quotient low + asm("stmia r7, {r3,r6} "); // store remainder + asm("mov r1, r5 "); // r0=quotient high + __POPRET("r4-r7,"); + } + +__NAKED__ int __cmpdi2(long long /*a*/, long long /*b*/) + { + // return 0 if ab + asm("subs r0, r2, r0 "); + asm("sbcs r1, r3, r1 "); // r1:r0 = b-a, set flags + asm("movlt r0, #2 "); // if bb + asm("cmp r1, r3 "); + asm("cmpeq r0, r2 "); // compare r1:r0 - r3:r2 + asm("movhi r0, #2 "); // r0=2 if a>b + asm("moveq r0, #1 "); // r0=1 if a=b + asm("movlo r0, #0 "); // r0=0 if a= 2^32, so quotient < 2^32 + // Use 64 bit accumulator, 32 bit quotient + asm("udiv64a: "); + asm("mov r4, #0 "); // quotient in r4, use r1, r6 as accumulator + asm("mov r6, #0 "); + asm("mov r5, #8 "); // do 32 iterations + asm("udiv64d: "); + asm("adds r0, r0, r0 "); // shift dividend left into acc + asm("adcs r1, r1, r1 "); + asm("adcs r6, r6, r6 "); + asm("subs r7, r1, r2 "); // subtract divisor from acc, result into r7,r12 + asm("sbcs r12, r6, r3 "); + asm("adc r4, r4, r4 "); // shift result bit left into quotient + asm("movcs r1, r7 "); // if no borrow, update acc + asm("movcs r6, r12 "); + asm("adds r0, r0, r0 "); // shift dividend left into acc + asm("adcs r1, r1, r1 "); + asm("adcs r6, r6, r6 "); + asm("subs r7, r1, r2 "); // subtract divisor from acc, result into r7,r12 + asm("sbcs r12, r6, r3 "); + asm("adc r4, r4, r4 "); // shift result bit left into quotient + asm("movcs r1, r7 "); // if no borrow, update acc + asm("movcs r6, r12 "); + asm("adds r0, r0, r0 "); // shift dividend left into acc + asm("adcs r1, r1, r1 "); + asm("adcs r6, r6, r6 "); + asm("subs r7, r1, r2 "); // subtract divisor from acc, result into r7,r12 + asm("sbcs r12, r6, r3 "); + asm("adc r4, r4, r4 "); // shift result bit left into quotient + asm("movcs r1, r7 "); // if no borrow, update acc + asm("movcs r6, r12 "); + asm("adds r0, r0, r0 "); // shift dividend left into acc + asm("adcs r1, r1, r1 "); + asm("adcs r6, r6, r6 "); + asm("subs r7, r1, r2 "); // subtract divisor from acc, result into r7,r12 + asm("sbcs r12, r6, r3 "); + asm("adc r4, r4, r4 "); // shift result bit left into quotient + asm("movcs r1, r7 "); // if no borrow, update acc + asm("movcs r6, r12 "); + asm("subs r5, r5, #1 "); // loop + asm("bne udiv64d "); + asm("mov r3, r1 "); // remainder in r3,r6 + __JUMP(,lr); + + asm("udiv64_divby0: "); + asm("str lr, [sp, #-4]! "); + asm("bl " DIV_BY_ZERO); + __POPRET(""); + } + +} + diff -r 7e3f204e6c81 -r f9c11be8c0b3 crypto/weakcryptospi/source/bigint/mont.cpp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/crypto/weakcryptospi/source/bigint/mont.cpp Tue Dec 01 11:12:04 2009 +0000 @@ -0,0 +1,243 @@ +/* +* Copyright (c) 2003-2009 Nokia Corporation and/or its subsidiary(-ies). +* All rights reserved. +* This component and the accompanying materials are made available +* under the terms of the License "Eclipse Public License v1.0" +* which accompanies this distribution, and is available +* at the URL "http://www.eclipse.org/legal/epl-v10.html". +* +* Initial Contributors: +* Nokia Corporation - initial contribution. +* +* Contributors: +* +* Description: +* +*/ + + +#include +#include +#include "algorithms.h" +#include "words.h" +#include "windowslider.h" +#include "mont.h" + +EXPORT_C CMontgomeryStructure* CMontgomeryStructure::NewLC( + const TInteger& aModulus) + { + CMontgomeryStructure* self = new(ELeave) CMontgomeryStructure; + CleanupStack::PushL(self); + self->ConstructL(aModulus); + return self; + } + +CMontgomeryStructure::~CMontgomeryStructure() + { + iModulus.Close(); + iModulusInv.Close(); + iWorkspace.Close(); + iResult.Close(); + } + +void CMontgomeryStructure::ConstructL(const TInteger& aModulus) + { + User::LeaveIfError(aModulus.IsOdd() ? KErrNone : KErrArgument); + + iModulusInv = RInteger::NewEmptyL(aModulus.Size()); + iWorkspace = RInteger::NewEmptyL(5*aModulus.Size()); + iModulus = RInteger::NewL(aModulus); + iResult = RInteger::NewEmptyL(aModulus.Size()); + RecursiveInverseModPower2(iModulusInv.Ptr(), iWorkspace.Ptr(), + iModulus.Ptr(), iModulus.Size()); + } + +CMontgomeryStructure::CMontgomeryStructure() + { + } + +TInteger& CMontgomeryStructure::ConvertIn(TInteger& aInteger) const + { + aInteger <<= WordsToBits(iModulus.Size()); + aInteger %= iModulus; + return aInteger; + } + +TInteger& CMontgomeryStructure::ConvertOutL(TInteger& aInteger) const + { + TUint* const T = iWorkspace.Ptr(); + TUint* const R = aInteger.Ptr(); + const TUint N = iModulus.Size(); + User::LeaveIfError((aInteger.Size() <= N) ? KErrNone : KErrArgument); + + CopyWords(T, aInteger.Ptr(), aInteger.Size()); + SetWords(T + aInteger.Size(), 0, 2*N - aInteger.Size()); + MontgomeryReduce(R, T+2*N, T, iModulus.Ptr(), iModulusInv.Ptr(), N); + return aInteger; + } + +void CMontgomeryStructure::DoMultiplyL(TInteger& aResult, const TInteger& aA, + const TInteger& aB) const + { + User::LeaveIfError((aResult.Size() == iModulus.Size()) ? KErrNone : KErrArgument); + + TUint* const T = iWorkspace.Ptr(); + TUint* const R = aResult.Ptr(); + const TUint N = iModulus.Size(); + const TUint* const aReg = aA.Ptr(); + const TUint* const bReg = aB.Ptr(); + const TUint aSize = aA.Size(); + const TUint bSize = aB.Size(); + User::LeaveIfError((aSize <= N && bSize <= N) ? KErrNone : KErrArgument); + + AsymmetricMultiply(T, T+2*N, aReg, aSize, bReg, bSize); + SetWords(T+aSize+bSize, 0, 2*N - aSize - bSize); + MontgomeryReduce(R, T+2*N, T, iModulus.Ptr(), iModulusInv.Ptr(), N); + } + +const TInteger& CMontgomeryStructure::SquareL(const TInteger& aA) const + { + RInteger a = RInteger::NewL(aA); + CleanupStack::PushL(a); + DoSquareL(iResult, ConvertIn(a)); + ConvertOutL(iResult); + CleanupStack::PopAndDestroy(&a); + return iResult; + } + +void CMontgomeryStructure::DoSquareL(TInteger& aResult, const TInteger& aA) const + { + User::LeaveIfError((aResult.Size() == iModulus.Size()) ? KErrNone : KErrArgument); + TUint* const T = iWorkspace.Ptr(); + TUint* const R = aResult.Ptr(); + const TUint N = iModulus.Size(); + const TUint* const aReg = aA.Ptr(); + const TUint aSize = aA.Size(); + + User::LeaveIfError((aSize <= N) ? KErrNone : KErrArgument); + + RecursiveSquare(T, T+2*N, aReg, aSize); + SetWords(T+2*aSize, 0, 2*N-2*aSize); + MontgomeryReduce(R, T+2*N, T, iModulus.Ptr(), iModulusInv.Ptr(), N); + } + +EXPORT_C const TInteger& CMontgomeryStructure::ExponentiateL( + const TInteger& aBase, const TInteger& aExponent) const + { + //See HAC 14.85 + if ((iResult.Size() != iModulus.Size()) || + (aBase >= iModulus) || + (!aBase.IsPositive()) || + (!aExponent.IsPositive())) + { + User::Leave(KErrArgument); + } + + // 1.1 Precomputation + // g1 <- g + // g2 <- g^2 + RInteger g2 = RInteger::NewL(aBase); + CleanupStack::PushL(g2); + ConvertIn(g2); + //ConvertIn can shrink g2, because we call DoSquare on g2, g2 must be the same size as the modulus + g2.CleanGrowL(iModulus.Size()); + RInteger g1 = RInteger::NewL(g2); + CleanupStack::PushL(g1); + DoSquareL(g2, g2); + + TWindowSlider slider(aExponent); + + // 1.2 + // For i from 1 to (2^(k-1) -1) do g2i+1 <- g2i-1 * g2 + TUint count = (1 << (slider.WindowSize()-1)) - 1; //2^(k-1) -1 + RRArray powerArray(count+1); //+1 because we append g1 + User::LeaveIfError(powerArray.Append(g1)); + CleanupStack::Pop(&g1); + CleanupClosePushL(powerArray); + for(TUint k=1; k <= count; k++) + { + RInteger gi = RInteger::NewEmptyL(iModulus.Size()); + DoMultiplyL(gi, g2, powerArray[k-1]); + User::LeaveIfError(powerArray.Append(gi)); + } + + // 2 A <- 1, i <- t + RInteger temp = RInteger::NewL(TInteger::One()); + CleanupStack::PushL(temp); + ConvertIn(temp); + + RInteger& A = iResult; + //Set A to one converted in for this modulus without changing the memory size of A (iResult) + A.CopyL(temp, EFalse); + CleanupStack::PopAndDestroy(&temp); + + TInt i = aExponent.BitCount() - 1; + + // 3 While i>=0 do: + while( i>=0 ) + { + // 3.1 If ei == 0 then A <- A^2 + if(!aExponent.Bit(i)) + { + DoSquareL(A, A); + i--; + } + // 3.2 Find longest bitstring ei,ei-1,...,el s.t. i-l+1<=k and el==1 + // and do: + // A <- (A^2^(i-l+1)) * g[the index indicated by the bitstring value] + else + { + slider.FindNextWindow(i); + assert(slider.Length() >= 1); + for(TUint j=0; j>1]); + i -= slider.Length(); + } + } + CleanupStack::PopAndDestroy(2, &g2); //powerArray, g2 + return ConvertOutL(A); // A == iResult + } + +// Methods are excluded from coverage due to the problem with BullsEye on ONB. +// Manually verified that these methods are functionally covered. +#ifdef _BullseyeCoverage +#pragma suppress_warnings on +#pragma BullseyeCoverage off +#pragma suppress_warnings off +#endif + +const TInteger& CMontgomeryStructure::ReduceL( + const TInteger& aInteger) const + { + RInteger temp = RInteger::NewL(aInteger); + CleanupStack::PushL(temp); + ConvertIn(temp); + iResult.CopyL(ConvertOutL(temp), EFalse); + CleanupStack::PopAndDestroy(&temp); + return iResult; + } + +CMontgomeryStructure* CMontgomeryStructure::NewL( + const TInteger& aModulus) + { + CMontgomeryStructure* self = CMontgomeryStructure::NewLC(aModulus); + CleanupStack::Pop(self); + return self; + } + +const TInteger& CMontgomeryStructure::MultiplyL(const TInteger& aA, + const TInteger& aB) const + { + RInteger a = RInteger::NewL(aA); + CleanupStack::PushL(a); + RInteger b = RInteger::NewL(aB); + CleanupStack::PushL(b); + DoMultiplyL(iResult, ConvertIn(a), ConvertIn(b)); + ConvertOutL(iResult); + CleanupStack::PopAndDestroy(&b); + CleanupStack::PopAndDestroy(&a); + return iResult; + } diff -r 7e3f204e6c81 -r f9c11be8c0b3 crypto/weakcryptospi/source/bigint/mont.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/crypto/weakcryptospi/source/bigint/mont.h Tue Dec 01 11:12:04 2009 +0000 @@ -0,0 +1,59 @@ +/* +* Copyright (c) 2003-2009 Nokia Corporation and/or its subsidiary(-ies). +* All rights reserved. +* This component and the accompanying materials are made available +* under the terms of the License "Eclipse Public License v1.0" +* which accompanies this distribution, and is available +* at the URL "http://www.eclipse.org/legal/epl-v10.html". +* +* Initial Contributors: +* Nokia Corporation - initial contribution. +* +* Contributors: +* +* Description: +* CMontgomeryStructure class implementation +* +*/ + + +/** + @file + @internalComponent +*/ + +#ifndef __MONT_H__ +#define __MONT_H__ + +class TInteger; +class RInteger; + +/** A special representation of integers allowing efficient multiplication + * and exponentiation under special conditions. + * @internalComponent + */ +class CMontgomeryStructure : public CBase + { +public: + static CMontgomeryStructure* NewL(const TInteger& aModulus); + IMPORT_C static CMontgomeryStructure* NewLC(const TInteger& aModulus); + ~CMontgomeryStructure(); + const TInteger& ReduceL(const TInteger& aInteger) const; + const TInteger& MultiplyL(const TInteger& aA, const TInteger& aB) const; + IMPORT_C const TInteger& ExponentiateL(const TInteger& aBase, const TInteger& aExponent) const; + const TInteger& SquareL(const TInteger& aA) const; +protected: + void DoMultiplyL(TInteger& aResult, const TInteger& aA, const TInteger& aB) const; + void DoSquareL(TInteger& aResult, const TInteger& aA) const; + TInteger& ConvertIn(TInteger& aInteger) const; + TInteger& ConvertOutL(TInteger& aInteger) const; + CMontgomeryStructure(); +private: + void ConstructL(const TInteger& aModulus); + RInteger iModulus; + RInteger iModulusInv; + RInteger iWorkspace; + mutable RInteger iResult; + }; + +#endif // __MONT_H__ diff -r 7e3f204e6c81 -r f9c11be8c0b3 crypto/weakcryptospi/source/bigint/primes.cpp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/crypto/weakcryptospi/source/bigint/primes.cpp Tue Dec 01 11:12:04 2009 +0000 @@ -0,0 +1,450 @@ +/* +* Copyright (c) 2003-2009 Nokia Corporation and/or its subsidiary(-ies). +* All rights reserved. +* This component and the accompanying materials are made available +* under the terms of the License "Eclipse Public License v1.0" +* which accompanies this distribution, and is available +* at the URL "http://www.eclipse.org/legal/epl-v10.html". +* +* Initial Contributors: +* Nokia Corporation - initial contribution. +* +* Contributors: +* +* Description: +* +*/ + + +#include +#include +#include +#include "words.h" +#include "primes.h" +#include "algorithms.h" +#include "mont.h" +#include "stackinteger.h" + +static TBool IsSmallPrime(TUint aK); + +static inline void EliminateComposites(TUint* aS, TUint aPrime, TUint aJ, + TUint aMaxIndex) + { + for(; aJ>=16, i+=16; + if( aX << 24 == 0 ) aX>>=8, i+=8; + if( aX << 28 == 0 ) aX>>=4, i+=4; + if( aX << 30 == 0 ) aX>>=2, i+=2; + if( aX << 31 == 0 ) ++i; + return i; + } + +static inline TInt FindFirstPrimeCandidate(TUint* aS, TUint aBitLength) + { + assert(aBitLength % WORD_BITS == 0); + TUint i=0; + //The empty statement at the end of this is stop warnings in all compilers + for(; aS[i] == KMaxTUint && i= 0 ); + assert( FindLeastSignificantZero((TUint)(aS[i])) <= 31 ); + return i*WORD_BITS + FindLeastSignificantZero((TUint32)(aS[i])); + } + } + +static inline TUint FindSmallestIndex(TUint aPrime, TUint aRemainder) + { + TUint& j = aRemainder; + if(j) + { + j = aPrime - aRemainder; + if( j & 0x1L ) + { + //if j is odd then this + j is even so we actually want + //the next number for which (this + j % p == 0) st this + j is odd + //that is: this + j + p == 0 mod p + j += aPrime; + } + //Turn j into an index for a bit array representing odd numbers only + j>>=1; + } + return j; + } + +static inline TUint RabinMillerRounds(TUint aBits) + { + //See HAC Table 4.4 + if(aBits > 1300) + return 2; + if (aBits > 850) + return 3; + if (aBits > 650) + return 4; + if (aBits > 550) + return 5; + if (aBits > 450) + return 6; + if (aBits > 400) + return 7; + if (aBits > 350) + return 8; + if (aBits > 300) + return 9; + if (aBits > 250) + return 12; + if (aBits > 200) + return 15; + if (aBits > 150) + return 18; + if (aBits > 100) + return 27; + //All of the above are optimisations on the worst case. The worst case + //chance of odd composite integers being declared prime by Rabin-Miller is + //(1/4)^t where t is the number of rounds. Thus, t = 40 means that the + //chance of declaring a composite integer prime is less than 2^(-80). See + //HAC Fact 4.25 and most of chapter 4 for more details. + return 40; + } + +static TBool HasSmallDivisorL(const TInteger& aPossiblePrime) + { + assert(aPossiblePrime.IsOdd()); + //Start checking at the first odd prime, whether it is even should have + //already been checked + for( TUint i=1; i < KPrimeTableSize; i++ ) + { + if( aPossiblePrime.ModuloL(KPrimeTable[i]) == 0 ) + { + return ETrue; + } + } + return EFalse; + } + +static TBool RabinMillerIterationL(const CMontgomeryStructure& aMont, + const TInteger& aProbablePrime, const TInteger& aBase) + { + //see HAC 4.24 + const TInteger& n = aProbablePrime; + assert(n > KLastSmallPrimeSquared); + assert(n.IsOdd()); + assert(aBase > TInteger::One()); + + RInteger nminus1 = n.MinusL(TInteger::One()); + CleanupStack::PushL(nminus1); + assert(aBase < nminus1); + + // 1) find (s | 2^s*r == n-1) where r is odd + // we want the largest power of 2 that divides n-1 + TUint s=0; + for(;;s++) + { + if(nminus1.Bit(s)) + { + break; + } + } + // (r = (n-1) / 2^s) which is equiv to (n-1 >>= s) + RInteger r = RInteger::NewL(nminus1); + CleanupStack::PushL(r); + r >>= s; + + //At no point do we own y, aMont owns it + const TInteger* y = &(aMont.ExponentiateL(aBase, r)); + + TBool probablePrime = EFalse; + + TUint j=1; + if( *y == TInteger::One() || *y == nminus1 ) + { + probablePrime = ETrue; + } + else + { + for(j=1; j KLastSmallPrimeSquared); + + RInteger nminus2 = n.MinusL(TInteger::Two()); + CleanupStack::PushL(nminus2); + + for(TUint i=0; i= KLastSmallPrimeSquared and return EFalse and lets the normal + * prime generation routines handle the situation. In the case where it is + * smaller, it generates a provable prime and returns ETrue. The algorithm for + * finding a provable prime < KLastPrimeSquared is not the most efficient in the + * world, but two points come to mind + * 1) The two if statements hardly _ever_ evaluate to ETrue in real life. + * 2) Even when it is, the distribution of primes < KLastPrimeSquared is pretty + * dense, so you aren't going to have check many. + * This function is essentially here for two reasons: + * 1) Ensures that it is possible to generate primes < KLastPrimeSquared (the + * test code does this) + * 2) Ensures that if you request a prime of a large bit size that there is an + * even probability distribution across all integers < 2^aBits + */ +TBool TInteger::SmallPrimeRandomizeL(void) + { + TBool foundPrime = EFalse; + //If the random number we've chosen is less than KLastSmallPrime, + //testing for primality is easy. + if(*this <= KLastSmallPrime) + { + //If Zero or One, or two, next prime number is two + if(IsZero() || *this == One() || *this == Two()) + { + CopyL(TInteger::Two()); + foundPrime = ETrue; + } + else + { + //Make sure any number we bother testing is at least odd + SetBit(0); + //Binary search the small primes. + while(!IsSmallPrime(ConvertToUnsignedLong())) + { + //If not prime, add two and try the next odd number. + + //will never carry as the minimum size of an RInteger is 2 + //words. Much bigger than KLastSmallPrime on 32bit + //architectures. + IncrementNoCarry(Ptr(), Size(), 2); + } + assert(IsSmallPrime(ConvertToUnsignedLong())); + foundPrime = ETrue; + } + } + else if(*this <= KLastSmallPrimeSquared) + { + //Make sure any number we bother testing is at least odd + SetBit(0); + + while(HasSmallDivisorL(*this) && *this <= KLastSmallPrimeSquared) + { + //If not prime, add two and try the next odd number. + + //will never carry as the minimum size of an RInteger is 2 + //words. Much bigger than KLastSmallPrime on 32bit + //architectures. + IncrementNoCarry(Ptr(), Size(), 2); + } + //If we exited while loop because it had no small divisor then it is + //prime. Otherwise, we've exceeded the limit of what we can provably + //generate. Therefore the normal prime gen routines will be run on it + //now. + if(*this < KLastSmallPrimeSquared) + { + foundPrime = ETrue; + } + } + //This doesn't mean there is no such prime, simply means that the number + //wasn't less than KSmallPrimeSquared and needs to be handled by the normal + //prime generation routines. + return foundPrime; + } + +void TInteger::PrimeRandomizeL(TUint aBits, TRandomAttribute aAttr) + { + assert(aBits > 1); + + //"this" is "empty" currently. Consists of Size() words of 0's. This is just + //checking that sign flag is positive as we don't set it later. + assert(NotNegative()); + + //Flag for the whole function saying if we've found a prime + TBool foundProbablePrime = EFalse; + + //Find 2^aBits + 1 -- any prime we find must be less than this. + RInteger max = RInteger::NewEmptyL(BitsToWords(aBits)+1); + CleanupStack::PushL(max); + max.SetBit(aBits); + assert(max.BitCount()-1 == aBits); + + // aBits | approx number of odd numbers you must try to have a 50% + // chance of finding a prime + //--------------------------------------------------------- + // 512 | 122 + // 1024 | 245 + // 2048 | 1023 + //Therefore if we are generating larger than 1024 bit numbers we'll use a + //bigger bit array to have a better chance of avoiding re-generating it. + TUint sLength = aBits > 1024 ? 1024 : 512; + RInteger S = RInteger::NewEmptyL(BitsToWords(sLength)); + CleanupStack::PushL(S); + + while(!foundProbablePrime) + { + //Randomly choose aBits + RandomizeL(aBits, aAttr); + + //If the random number chosen is less than KSmallPrimeSquared, we have a + //special set of routines. + if(SmallPrimeRandomizeL()) + { + foundProbablePrime = ETrue; + } + else + { + //if it was <= KLastSmallPrimeSquared then it would have been + //handled by SmallPrimeRandomizeL() + assert(*this > KLastSmallPrimeSquared); + + //Make sure any number we bother testing is at least odd + SetBit(0); + + //Ensure that this + 2*sLength < max + RInteger temp = max.MinusL(*this); + CleanupStack::PushL(temp); + ++temp; + temp >>=1; + if(temp < sLength) + { + //if this + 2*sLength >= max then we use a smaller sLength to + //ensure we don't find a number that is outside of our bounds + //(and bigger than our allocated memory for this) + + //temp must be less than KMaxTUint as sLength is a TUint + sLength = temp.ConvertToUnsignedLong(); + } + CleanupStack::PopAndDestroy(&temp); + + //Start at 1 as no point in checking against 2 (all odd numbers) + for(TUint i=1; i=0; j=FindFirstPrimeCandidate(S.Ptr(), sLength)) + { + ArraySetBit(S.Ptr(), j); + + //should never carry as we earlier made sure that 2*j + this < max + //where max is 1 bit more than we asked for. + IncrementNoCarry(Ptr(), Size(), 2*(j-prev)); + + assert(*this < max); + assert(!HasSmallDivisorL(*this)); + + prev = j; + + if( IsStrongProbablePrimeL(*this) ) + { + foundProbablePrime = ETrue; + break; + } + } + //This clears the memory + S.CopyL(0, EFalse); + } + } + CleanupStack::PopAndDestroy(2, &max); + } + +EXPORT_C TBool TInteger::IsPrimeL(void) const + { + if( NotPositive() ) + { + return EFalse; + } + else if( IsEven() ) + { + return *this == Two(); + } + else if( *this <= KLastSmallPrime ) + { + assert(KLastSmallPrime < KMaxTUint); + return IsSmallPrime(this->ConvertToUnsignedLong()); + } + else if( *this <= KLastSmallPrimeSquared ) + { + return !HasSmallDivisorL(*this); + } + else + { + return !HasSmallDivisorL(*this) && IsStrongProbablePrimeL(*this); + } + } + +// Method is excluded from coverage due to the problem with BullsEye on ONB. +// Manually verified that this method is functionally covered. +#ifdef _BullseyeCoverage +#pragma suppress_warnings on +#pragma BullseyeCoverage off +#pragma suppress_warnings off +#endif + +static TBool IsSmallPrime(TUint aK) + { + //This is just a binary search of our small prime table. + TUint l = 0; + TUint u = KPrimeTableSize; + while( u > l ) + { + TUint m = (l+u)>>1; + TUint p = KPrimeTable[m]; + if(aK < p) + u = m; + else if (aK > p) + l = m + 1; + else + return ETrue; + } + return EFalse; + } diff -r 7e3f204e6c81 -r f9c11be8c0b3 crypto/weakcryptospi/source/bigint/primes.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/crypto/weakcryptospi/source/bigint/primes.h Tue Dec 01 11:12:04 2009 +0000 @@ -0,0 +1,297 @@ +/* +* Copyright (c) 2003-2009 Nokia Corporation and/or its subsidiary(-ies). +* All rights reserved. +* This component and the accompanying materials are made available +* under the terms of the License "Eclipse Public License v1.0" +* which accompanies this distribution, and is available +* at the URL "http://www.eclipse.org/legal/epl-v10.html". +* +* Initial Contributors: +* Nokia Corporation - initial contribution. +* +* Contributors: +* +* Description: Table of prime numbers. +* +*/ + + +/** + @file + @internalComponent +*/ + +#ifndef __BIGINT_PRIMES_H__ +#define __BIGINT_PRIMES_H__ + +#include + +const TUint16 KPrimeTable[] = + { + 2, 3, 5, 7, 11, 13, 17, 19, + 23, 29, 31, 37, 41, 43, 47, 53, + 59, 61, 67, 71, 73, 79, 83, 89, + 97, 101, 103, 107, 109, 113, 127, 131, + 137, 139, 149, 151, 157, 163, 167, 173, + 179, 181, 191, 193, 197, 199, 211, 223, + 227, 229, 233, 239, 241, 251, 257, 263, + 269, 271, 277, 281, 283, 293, 307, 311, + 313, 317, 331, 337, 347, 349, 353, 359, + 367, 373, 379, 383, 389, 397, 401, 409, + 419, 421, 431, 433, 439, 443, 449, 457, + 461, 463, 467, 479, 487, 491, 499, 503, + 509, 521, 523, 541, 547, 557, 563, 569, + 571, 577, 587, 593, 599, 601, 607, 613, + 617, 619, 631, 641, 643, 647, 653, 659, + 661, 673, 677, 683, 691, 701, 709, 719, + 727, 733, 739, 743, 751, 757, 761, 769, + 773, 787, 797, 809, 811, 821, 823, 827, + 829, 839, 853, 857, 859, 863, 877, 881, + 883, 887, 907, 911, 919, 929, 937, 941, + 947, 953, 967, 971, 977, 983, 991, 997, + 1009, 1013, 1019, 1021, 1031, 1033, 1039, 1049, + 1051, 1061, 1063, 1069, 1087, 1091, 1093, 1097, + 1103, 1109, 1117, 1123, 1129, 1151, 1153, 1163, + 1171, 1181, 1187, 1193, 1201, 1213, 1217, 1223, + 1229, 1231, 1237, 1249, 1259, 1277, 1279, 1283, + 1289, 1291, 1297, 1301, 1303, 1307, 1319, 1321, + 1327, 1361, 1367, 1373, 1381, 1399, 1409, 1423, + 1427, 1429, 1433, 1439, 1447, 1451, 1453, 1459, + 1471, 1481, 1483, 1487, 1489, 1493, 1499, 1511, + 1523, 1531, 1543, 1549, 1553, 1559, 1567, 1571, + 1579, 1583, 1597, 1601, 1607, 1609, 1613, 1619, + 1621, 1627, 1637, 1657, 1663, 1667, 1669, 1693, + 1697, 1699, 1709, 1721, 1723, 1733, 1741, 1747, + 1753, 1759, 1777, 1783, 1787, 1789, 1801, 1811, + 1823, 1831, 1847, 1861, 1867, 1871, 1873, 1877, + 1879, 1889, 1901, 1907, 1913, 1931, 1933, 1949, + 1951, 1973, 1979, 1987, 1993, 1997, 1999, 2003, + 2011, 2017, 2027, 2029, 2039, 2053, 2063, 2069, + 2081, 2083, 2087, 2089, 2099, 2111, 2113, 2129, + 2131, 2137, 2141, 2143, 2153, 2161, 2179, 2203, + 2207, 2213, 2221, 2237, 2239, 2243, 2251, 2267, + 2269, 2273, 2281, 2287, 2293, 2297, 2309, 2311, + 2333, 2339, 2341, 2347, 2351, 2357, 2371, 2377, + 2381, 2383, 2389, 2393, 2399, 2411, 2417, 2423, + 2437, 2441, 2447, 2459, 2467, 2473, 2477, 2503, + 2521, 2531, 2539, 2543, 2549, 2551, 2557, 2579, + 2591, 2593, 2609, 2617, 2621, 2633, 2647, 2657, + 2659, 2663, 2671, 2677, 2683, 2687, 2689, 2693, + 2699, 2707, 2711, 2713, 2719, 2729, 2731, 2741, + 2749, 2753, 2767, 2777, 2789, 2791, 2797, 2801, + 2803, 2819, 2833, 2837, 2843, 2851, 2857, 2861, + 2879, 2887, 2897, 2903, 2909, 2917, 2927, 2939, + 2953, 2957, 2963, 2969, 2971, 2999, 3001, 3011, + 3019, 3023, 3037, 3041, 3049, 3061, 3067, 3079, + 3083, 3089, 3109, 3119, 3121, 3137, 3163, 3167, + 3169, 3181, 3187, 3191, 3203, 3209, 3217, 3221, + 3229, 3251, 3253, 3257, 3259, 3271, 3299, 3301, + 3307, 3313, 3319, 3323, 3329, 3331, 3343, 3347, + 3359, 3361, 3371, 3373, 3389, 3391, 3407, 3413, + 3433, 3449, 3457, 3461, 3463, 3467, 3469, 3491, + 3499, 3511, 3517, 3527, 3529, 3533, 3539, 3541, + 3547, 3557, 3559, 3571, 3581, 3583, 3593, 3607, + 3613, 3617, 3623, 3631, 3637, 3643, 3659, 3671, + 3673, 3677, 3691, 3697, 3701, 3709, 3719, 3727, + 3733, 3739, 3761, 3767, 3769, 3779, 3793, 3797, + 3803, 3821, 3823, 3833, 3847, 3851, 3853, 3863, + 3877, 3881, 3889, 3907, 3911, 3917, 3919, 3923, + 3929, 3931, 3943, 3947, 3967, 3989, 4001, 4003, + 4007, 4013, 4019, 4021, 4027, 4049, 4051, 4057, + 4073, 4079, 4091, 4093, 4099, 4111, 4127, 4129, + 4133, 4139, 4153, 4157, 4159, 4177, 4201, 4211, + 4217, 4219, 4229, 4231, 4241, 4243, 4253, 4259, + 4261, 4271, 4273, 4283, 4289, 4297, 4327, 4337, + 4339, 4349, 4357, 4363, 4373, 4391, 4397, 4409, + 4421, 4423, 4441, 4447, 4451, 4457, 4463, 4481, + 4483, 4493, 4507, 4513, 4517, 4519, 4523, 4547, + 4549, 4561, 4567, 4583, 4591, 4597, 4603, 4621, + 4637, 4639, 4643, 4649, 4651, 4657, 4663, 4673, + 4679, 4691, 4703, 4721, 4723, 4729, 4733, 4751, + 4759, 4783, 4787, 4789, 4793, 4799, 4801, 4813, + 4817, 4831, 4861, 4871, 4877, 4889, 4903, 4909, + 4919, 4931, 4933, 4937, 4943, 4951, 4957, 4967, + 4969, 4973, 4987, 4993, 4999, 5003, 5009, 5011, + 5021, 5023, 5039, 5051, 5059, 5077, 5081, 5087, + 5099, 5101, 5107, 5113, 5119, 5147, 5153, 5167, + 5171, 5179, 5189, 5197, 5209, 5227, 5231, 5233, + 5237, 5261, 5273, 5279, 5281, 5297, 5303, 5309, + 5323, 5333, 5347, 5351, 5381, 5387, 5393, 5399, + 5407, 5413, 5417, 5419, 5431, 5437, 5441, 5443, + 5449, 5471, 5477, 5479, 5483, 5501, 5503, 5507, + 5519, 5521, 5527, 5531, 5557, 5563, 5569, 5573, + 5581, 5591, 5623, 5639, 5641, 5647, 5651, 5653, + 5657, 5659, 5669, 5683, 5689, 5693, 5701, 5711, + 5717, 5737, 5741, 5743, 5749, 5779, 5783, 5791, + 5801, 5807, 5813, 5821, 5827, 5839, 5843, 5849, + 5851, 5857, 5861, 5867, 5869, 5879, 5881, 5897, + 5903, 5923, 5927, 5939, 5953, 5981, 5987, 6007, + 6011, 6029, 6037, 6043, 6047, 6053, 6067, 6073, + 6079, 6089, 6091, 6101, 6113, 6121, 6131, 6133, + 6143, 6151, 6163, 6173, 6197, 6199, 6203, 6211, + 6217, 6221, 6229, 6247, 6257, 6263, 6269, 6271, + 6277, 6287, 6299, 6301, 6311, 6317, 6323, 6329, + 6337, 6343, 6353, 6359, 6361, 6367, 6373, 6379, + 6389, 6397, 6421, 6427, 6449, 6451, 6469, 6473, + 6481, 6491, 6521, 6529, 6547, 6551, 6553, 6563, + 6569, 6571, 6577, 6581, 6599, 6607, 6619, 6637, + 6653, 6659, 6661, 6673, 6679, 6689, 6691, 6701, + 6703, 6709, 6719, 6733, 6737, 6761, 6763, 6779, + 6781, 6791, 6793, 6803, 6823, 6827, 6829, 6833, + 6841, 6857, 6863, 6869, 6871, 6883, 6899, 6907, + 6911, 6917, 6947, 6949, 6959, 6961, 6967, 6971, + 6977, 6983, 6991, 6997, 7001, 7013, 7019, 7027, + 7039, 7043, 7057, 7069, 7079, 7103, 7109, 7121, + 7127, 7129, 7151, 7159, 7177, 7187, 7193, 7207, + 7211, 7213, 7219, 7229, 7237, 7243, 7247, 7253, + 7283, 7297, 7307, 7309, 7321, 7331, 7333, 7349, + 7351, 7369, 7393, 7411, 7417, 7433, 7451, 7457, + 7459, 7477, 7481, 7487, 7489, 7499, 7507, 7517, + 7523, 7529, 7537, 7541, 7547, 7549, 7559, 7561, + 7573, 7577, 7583, 7589, 7591, 7603, 7607, 7621, + 7639, 7643, 7649, 7669, 7673, 7681, 7687, 7691, + 7699, 7703, 7717, 7723, 7727, 7741, 7753, 7757, + 7759, 7789, 7793, 7817, 7823, 7829, 7841, 7853, + 7867, 7873, 7877, 7879, 7883, 7901, 7907, 7919, + 7927, 7933, 7937, 7949, 7951, 7963, 7993, 8009, + 8011, 8017, 8039, 8053, 8059, 8069, 8081, 8087, + 8089, 8093, 8101, 8111, 8117, 8123, 8147, 8161, + 8167, 8171, 8179, 8191, 8209, 8219, 8221, 8231, + 8233, 8237, 8243, 8263, 8269, 8273, 8287, 8291, + 8293, 8297, 8311, 8317, 8329, 8353, 8363, 8369, + 8377, 8387, 8389, 8419, 8423, 8429, 8431, 8443, + 8447, 8461, 8467, 8501, 8513, 8521, 8527, 8537, + 8539, 8543, 8563, 8573, 8581, 8597, 8599, 8609, + 8623, 8627, 8629, 8641, 8647, 8663, 8669, 8677, + 8681, 8689, 8693, 8699, 8707, 8713, 8719, 8731, + 8737, 8741, 8747, 8753, 8761, 8779, 8783, 8803, + 8807, 8819, 8821, 8831, 8837, 8839, 8849, 8861, + 8863, 8867, 8887, 8893, 8923, 8929, 8933, 8941, + 8951, 8963, 8969, 8971, 8999, 9001, 9007, 9011, + 9013, 9029, 9041, 9043, 9049, 9059, 9067, 9091, + 9103, 9109, 9127, 9133, 9137, 9151, 9157, 9161, + 9173, 9181, 9187, 9199, 9203, 9209, 9221, 9227, + 9239, 9241, 9257, 9277, 9281, 9283, 9293, 9311, + 9319, 9323, 9337, 9341, 9343, 9349, 9371, 9377, + 9391, 9397, 9403, 9413, 9419, 9421, 9431, 9433, + 9437, 9439, 9461, 9463, 9467, 9473, 9479, 9491, + 9497, 9511, 9521, 9533, 9539, 9547, 9551, 9587, + 9601, 9613, 9619, 9623, 9629, 9631, 9643, 9649, + 9661, 9677, 9679, 9689, 9697, 9719, 9721, 9733, + 9739, 9743, 9749, 9767, 9769, 9781, 9787, 9791, + 9803, 9811, 9817, 9829, 9833, 9839, 9851, 9857, + 9859, 9871, 9883, 9887, 9901, 9907, 9923, 9929, + 9931, 9941, 9949, 9967, 9973, 10007, 10009, 10037, + 10039, 10061, 10067, 10069, 10079, 10091, 10093, 10099, + 10103, 10111, 10133, 10139, 10141, 10151, 10159, 10163, + 10169, 10177, 10181, 10193, 10211, 10223, 10243, 10247, + 10253, 10259, 10267, 10271, 10273, 10289, 10301, 10303, + 10313, 10321, 10331, 10333, 10337, 10343, 10357, 10369, + 10391, 10399, 10427, 10429, 10433, 10453, 10457, 10459, + 10463, 10477, 10487, 10499, 10501, 10513, 10529, 10531, + 10559, 10567, 10589, 10597, 10601, 10607, 10613, 10627, + 10631, 10639, 10651, 10657, 10663, 10667, 10687, 10691, + 10709, 10711, 10723, 10729, 10733, 10739, 10753, 10771, + 10781, 10789, 10799, 10831, 10837, 10847, 10853, 10859, + 10861, 10867, 10883, 10889, 10891, 10903, 10909, 10937, + 10939, 10949, 10957, 10973, 10979, 10987, 10993, 11003, + 11027, 11047, 11057, 11059, 11069, 11071, 11083, 11087, + 11093, 11113, 11117, 11119, 11131, 11149, 11159, 11161, + 11171, 11173, 11177, 11197, 11213, 11239, 11243, 11251, + 11257, 11261, 11273, 11279, 11287, 11299, 11311, 11317, + 11321, 11329, 11351, 11353, 11369, 11383, 11393, 11399, + 11411, 11423, 11437, 11443, 11447, 11467, 11471, 11483, + 11489, 11491, 11497, 11503, 11519, 11527, 11549, 11551, + 11579, 11587, 11593, 11597, 11617, 11621, 11633, 11657, + 11677, 11681, 11689, 11699, 11701, 11717, 11719, 11731, + 11743, 11777, 11779, 11783, 11789, 11801, 11807, 11813, + 11821, 11827, 11831, 11833, 11839, 11863, 11867, 11887, + 11897, 11903, 11909, 11923, 11927, 11933, 11939, 11941, + 11953, 11959, 11969, 11971, 11981, 11987, 12007, 12011, + 12037, 12041, 12043, 12049, 12071, 12073, 12097, 12101, + 12107, 12109, 12113, 12119, 12143, 12149, 12157, 12161, + 12163, 12197, 12203, 12211, 12227, 12239, 12241, 12251, + 12253, 12263, 12269, 12277, 12281, 12289, 12301, 12323, + 12329, 12343, 12347, 12373, 12377, 12379, 12391, 12401, + 12409, 12413, 12421, 12433, 12437, 12451, 12457, 12473, + 12479, 12487, 12491, 12497, 12503, 12511, 12517, 12527, + 12539, 12541, 12547, 12553, 12569, 12577, 12583, 12589, + 12601, 12611, 12613, 12619, 12637, 12641, 12647, 12653, + 12659, 12671, 12689, 12697, 12703, 12713, 12721, 12739, + 12743, 12757, 12763, 12781, 12791, 12799, 12809, 12821, + 12823, 12829, 12841, 12853, 12889, 12893, 12899, 12907, + 12911, 12917, 12919, 12923, 12941, 12953, 12959, 12967, + 12973, 12979, 12983, 13001, 13003, 13007, 13009, 13033, + 13037, 13043, 13049, 13063, 13093, 13099, 13103, 13109, + 13121, 13127, 13147, 13151, 13159, 13163, 13171, 13177, + 13183, 13187, 13217, 13219, 13229, 13241, 13249, 13259, + 13267, 13291, 13297, 13309, 13313, 13327, 13331, 13337, + 13339, 13367, 13381, 13397, 13399, 13411, 13417, 13421, + 13441, 13451, 13457, 13463, 13469, 13477, 13487, 13499, + 13513, 13523, 13537, 13553, 13567, 13577, 13591, 13597, + 13613, 13619, 13627, 13633, 13649, 13669, 13679, 13681, + 13687, 13691, 13693, 13697, 13709, 13711, 13721, 13723, + 13729, 13751, 13757, 13759, 13763, 13781, 13789, 13799, + 13807, 13829, 13831, 13841, 13859, 13873, 13877, 13879, + 13883, 13901, 13903, 13907, 13913, 13921, 13931, 13933, + 13963, 13967, 13997, 13999, 14009, 14011, 14029, 14033, + 14051, 14057, 14071, 14081, 14083, 14087, 14107, 14143, + 14149, 14153, 14159, 14173, 14177, 14197, 14207, 14221, + 14243, 14249, 14251, 14281, 14293, 14303, 14321, 14323, + 14327, 14341, 14347, 14369, 14387, 14389, 14401, 14407, + 14411, 14419, 14423, 14431, 14437, 14447, 14449, 14461, + 14479, 14489, 14503, 14519, 14533, 14537, 14543, 14549, + 14551, 14557, 14561, 14563, 14591, 14593, 14621, 14627, + 14629, 14633, 14639, 14653, 14657, 14669, 14683, 14699, + 14713, 14717, 14723, 14731, 14737, 14741, 14747, 14753, + 14759, 14767, 14771, 14779, 14783, 14797, 14813, 14821, + 14827, 14831, 14843, 14851, 14867, 14869, 14879, 14887, + 14891, 14897, 14923, 14929, 14939, 14947, 14951, 14957, + 14969, 14983, 15013, 15017, 15031, 15053, 15061, 15073, + 15077, 15083, 15091, 15101, 15107, 15121, 15131, 15137, + 15139, 15149, 15161, 15173, 15187, 15193, 15199, 15217, + 15227, 15233, 15241, 15259, 15263, 15269, 15271, 15277, + 15287, 15289, 15299, 15307, 15313, 15319, 15329, 15331, + 15349, 15359, 15361, 15373, 15377, 15383, 15391, 15401, + 15413, 15427, 15439, 15443, 15451, 15461, 15467, 15473, + 15493, 15497, 15511, 15527, 15541, 15551, 15559, 15569, + 15581, 15583, 15601, 15607, 15619, 15629, 15641, 15643, + 15647, 15649, 15661, 15667, 15671, 15679, 15683, 15727, + 15731, 15733, 15737, 15739, 15749, 15761, 15767, 15773, + 15787, 15791, 15797, 15803, 15809, 15817, 15823, 15859, + 15877, 15881, 15887, 15889, 15901, 15907, 15913, 15919, + 15923, 15937, 15959, 15971, 15973, 15991, 16001, 16007, + 16033, 16057, 16061, 16063, 16067, 16069, 16073, 16087, + 16091, 16097, 16103, 16111, 16127, 16139, 16141, 16183, + 16187, 16189, 16193, 16217, 16223, 16229, 16231, 16249, + 16253, 16267, 16273, 16301, 16319, 16333, 16339, 16349, + 16361, 16363, 16369, 16381, 16411, 16417, 16421, 16427, + 16433, 16447, 16451, 16453, 16477, 16481, 16487, 16493, + 16519, 16529, 16547, 16553, 16561, 16567, 16573, 16603, + 16607, 16619, 16631, 16633, 16649, 16651, 16657, 16661, + 16673, 16691, 16693, 16699, 16703, 16729, 16741, 16747, + 16759, 16763, 16787, 16811, 16823, 16829, 16831, 16843, + 16871, 16879, 16883, 16889, 16901, 16903, 16921, 16927, + 16931, 16937, 16943, 16963, 16979, 16981, 16987, 16993, + 17011, 17021, 17027, 17029, 17033, 17041, 17047, 17053, + 17077, 17093, 17099, 17107, 17117, 17123, 17137, 17159, + 17167, 17183, 17189, 17191, 17203, 17207, 17209, 17231, + 17239, 17257, 17291, 17293, 17299, 17317, 17321, 17327, + 17333, 17341, 17351, 17359, 17377, 17383, 17387, 17389, + 17393, 17401, 17417, 17419, 17431, 17443, 17449, 17467, + 17471, 17477, 17483, 17489, 17491, 17497, 17509, 17519, + 17539, 17551, 17569, 17573, 17579, 17581, 17597, 17599, + 17609, 17623, 17627, 17657, 17659, 17669, 17681, 17683, + 17707, 17713, 17729, 17737, 17747, 17749, 17761, 17783, + 17789, 17791, 17807, 17827, 17837, 17839, 17851, 17863 +}; + +const TUint KPrimeTableSize = sizeof(KPrimeTable)/sizeof(TUint16); +const TUint KLastSmallPrime = 17863; +//Next line doesn't work on arm4 as it doesn't make this calculation at compile +//time but leaves it for runtime. Therefore we would have uninitialised const +//data. +//const TUint KLastSmallPrime = KPrimeTable[KPrimeTableSize-1]; +const TUint KLastSmallPrimeSquared = KLastSmallPrime*KLastSmallPrime; + +#endif diff -r 7e3f204e6c81 -r f9c11be8c0b3 crypto/weakcryptospi/source/bigint/rinteger.cpp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/crypto/weakcryptospi/source/bigint/rinteger.cpp Tue Dec 01 11:12:04 2009 +0000 @@ -0,0 +1,262 @@ +/* +* Copyright (c) 2003-2009 Nokia Corporation and/or its subsidiary(-ies). +* All rights reserved. +* This component and the accompanying materials are made available +* under the terms of the License "Eclipse Public License v1.0" +* which accompanies this distribution, and is available +* at the URL "http://www.eclipse.org/legal/epl-v10.html". +* +* Initial Contributors: +* Nokia Corporation - initial contribution. +* +* Contributors: +* +* Description: +* +*/ + + +#include +#include +#include +#include "../common/inlines.h" + + +/** + * Copy constructor + * + * This function performs a shallow copy, + * i.e. the memory holding the integer is not copied. + */ +EXPORT_C RInteger::RInteger(const RInteger& aInteger) + { + *this = aInteger; + } + +/** + * Assignment operator + * + * This function performs a shallow copy, + * i.e. the memory holding the integer is not copied. + */ +EXPORT_C RInteger& RInteger::operator=(const RInteger& aInteger) + { + iSize = aInteger.iSize; + iPtr = aInteger.iPtr; + return *this; + } + + +/** + * Creates a new integer representing 0. + * + * @return An RInteger by value. + */ +EXPORT_C RInteger RInteger::NewL(void) + { + return NewL(TInteger::Zero()); + } + +/** + * Creates a new integer object representing a specified value. + * + * @param aValue A descriptor containing the big-endian binary + * representation of the value. + * @return An RInteger object representing the value. + */ +EXPORT_C RInteger RInteger::NewL(const TDesC8& aValue) + { + RInteger self; + //Construct zero's memory beyond the size of aValue after construction + self.CreateNewL(BytesToWords(aValue.Size())); + self.Construct(aValue); + return self; + } + +/** + * Creates an exact copy of an \c aInteger object. + * + * @param aInteger The integer you wish to copy + * @return An RInteger object representing an exact copy of + * aInteger by value. + */ +EXPORT_C RInteger RInteger::NewL(const TInteger& aInteger) + { + RInteger self; + //don't need to CleanNewL as we'll copy straight from aInteger + self.CreateNewL(aInteger.Size()); + self.Construct(aInteger); + return self; + } + +/** + * Creates a random integer uniformly distributed over [0, 2^aBits]. + * + * @param aBits The number of bits you wish to randomly select. + * @param aAttr Enum specifying whether specific bits in the random number should + * be set. See TRandomAttribute for more information. + * @return A random RInteger object in the range specified. + */ +EXPORT_C RInteger RInteger::NewRandomL(TUint aBits, TRandomAttribute aAttr) + { + RInteger self; + self.CleanNewL(BitsToWords(aBits)); + CleanupStack::PushL(self); + self.RandomizeL(aBits, aAttr); + CleanupStack::Pop(&self); + return self; + } + +/** + * Creates a random integer uniformly distributed over [x | min <= x <= max]. + * + * @param aMin The smallest possible value for the random integer (inclusive). + * @param aMax The largest possible value for the random integer (inclusive). + * @return A random RInteger object in the range specified. + */ +EXPORT_C RInteger RInteger::NewRandomL(const TInteger& aMin, + const TInteger& aMax) + { + RInteger self; + self.CleanNewL(aMax.Size()); + CleanupStack::PushL(self); + self.RandomizeL(aMin, aMax); + CleanupStack::Pop(&self); + return self; + } + +/** + * Finds a random prime integer in the range of [2, 2^aBits]. + * + * This is done by picking a random integer and using that as a starting point + * for a sequential search for a prime. To verify the primality of number, + * this algorithm uses a probablistic primality test. This means that it is + * possible, although extremely improbable, that the number returned is a pseudoprime. + * + * @param aBits The number of bits you wish to randomly select your prime from. + * @param aAttr Enum specifying whether specific bits in the random number should + * be set. See TRandomAttribute for more information. + * @return A random RInteger representing a probable prime (with very high + * probablity) in the range specified. + */ +EXPORT_C RInteger RInteger::NewPrimeL(TUint aBits, TRandomAttribute aAttr) + { + RInteger self; + self.CleanNewL(BitsToWords(aBits)); + CleanupStack::PushL(self); + self.PrimeRandomizeL(aBits, aAttr); + CleanupStack::Pop(&self); + return self; + } + +/** + * Creates a new integer from the value represented by \c aInteger. + * + * @param aInteger A signed word sized integer. + * @return An RInteger representation of aInteger by value. + */ +EXPORT_C RInteger RInteger::NewL(TInt aInteger) + { + RInteger self; + self.CreateNewL(2); + self.Construct(aInteger); + return self; + } + +/** + * Creates a new integer with a preallocated internal storage of \c aNumWords all + * initialised to zero. + * + * The resulting RInteger object is logically equivalent to RInteger::NewL(0). + * The only difference is that the internal storage requirements have been + * specified to be larger than the default. This is useful if you are about + * to perform an operation on this integer, that you know the resulting size + * requirements of, and wish to avoid a heap resize. + * + * @param aNumWords The number of words for to preallocated and zero fill. + * @return An RInteger object representing 0 with a preallocated + * zero-filled internal storage of aNumWords. + */ +EXPORT_C RInteger RInteger::NewEmptyL(TUint aNumWords) + { + RInteger self; + self.CleanNewL(aNumWords); + //There's no construct as there isn't anything to do + return self; + } + +/** + * Creates an RInteger object with no associated internal (heap) storage. + * + * All data members are initialised to zero. It is safe (although not strictly necessary) + * to push such an RInteger object onto the CleanupStack. This is useful, for example, if + * you want to pass an RInteger object by reference into a function and have it create + * the representation of the actual integer for you. + * + * Note that performing any operation on such an RInteger object other than the default + * assignment operator or copy constructor will panic your code. + * + * @return A stack based class that has no associated internal storage and thus + * does not represent any number. + */ +EXPORT_C RInteger::RInteger(void) + { + } + +/** + * An overloaded TCleanupItem() allowing the RIntegers to be pushed, + * popped, and destroyed via the CleanupStack like any other CBase derived object. + */ +EXPORT_C RInteger::operator TCleanupItem(void) + { + return TCleanupItem(&RInteger::CallClose, this); + } + +/** + * Helper function registered with the cleanup stack that just calls Close() for + * this RInteger object. + * + * @param aPtr A pointer to the object for which clean-up is to be performed. + */ +EXPORT_C void RInteger::CallClose(TAny* aPtr) + { + ((RInteger*)aPtr)->Close(); + } + +/** + * Zeros and then frees any memory owned by this RInteger object. + * + * An RInteger object that has been closed can safely fall off the stack. + */ +EXPORT_C void RInteger::Close(void) + { + if (iPtr) + { + Mem::FillZ(Ptr(), Size()*4); + User::Free(Ptr()); + iSize = 0; + iPtr = NULL; + } + } + +// Method is excluded from coverage due to the problem with BullsEye on ONB. +// Manually verified that this method is functionally covered. +#ifdef _BullseyeCoverage +#pragma suppress_warnings on +#pragma BullseyeCoverage off +#pragma suppress_warnings off +#endif + +/** + * Creates a new integer from the value represented by \c aInteger. + * + * @param aInteger An unsigned word sized integer. + * @return An RInteger representation of aInteger by value. + */ +EXPORT_C RInteger RInteger::NewL(TUint aInteger) + { + RInteger self; + self.CreateNewL(2); + self.Construct(aInteger); + return self; + } diff -r 7e3f204e6c81 -r f9c11be8c0b3 crypto/weakcryptospi/source/bigint/stackinteger.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/crypto/weakcryptospi/source/bigint/stackinteger.h Tue Dec 01 11:12:04 2009 +0000 @@ -0,0 +1,59 @@ +/* +* Copyright (c) 2003-2009 Nokia Corporation and/or its subsidiary(-ies). +* All rights reserved. +* This component and the accompanying materials are made available +* under the terms of the License "Eclipse Public License v1.0" +* which accompanies this distribution, and is available +* at the URL "http://www.eclipse.org/legal/epl-v10.html". +* +* Initial Contributors: +* Nokia Corporation - initial contribution. +* +* Contributors: +* +* Description: +* TStackInteger class implementation +* +*/ + + +/** + @file + @internalComponent +*/ + +#ifndef __STACK_INTEGER_H__ +#define __STACK_INTEGER_H__ + +#include "bigint.h" + +/** An integer that can be created on the stack.\n\n + * The resulting integers are + * fixed in size and any code that tries to modify their memory allocation + * will panic. Stack based integers may be modified as long as you can + * guarantee that the resulting integer will fit in the current amount of + * allocated memory. + * If you are not sure which integer you want, you want an RInteger. + * @internalComponent + * @prototype + * @see RInteger + */ +template +class TStackInteger : public TInteger + { +public: + inline TStackInteger(TUint aInteger) {ConstructStack(W, aInteger);} + inline TStackInteger(const TInteger& aInteger) {ConstructStack(W, aInteger);} +protected: + TUint32 iBuf[W]; + }; + +typedef TStackInteger<2> TStackInteger64; +typedef TStackInteger<4> TStackInteger128; +typedef TStackInteger<8> TStackInteger256; +typedef TStackInteger<16> TStackInteger512; +typedef TStackInteger<32> TStackInteger1024; +typedef TStackInteger<64> TStackInteger2048; +//Don't make them any bigger than this :). The last one is 66 words (264 bytes) + +#endif // __STACK_INTEGER_H__ diff -r 7e3f204e6c81 -r f9c11be8c0b3 crypto/weakcryptospi/source/bigint/vchelp.cpp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/crypto/weakcryptospi/source/bigint/vchelp.cpp Tue Dec 01 11:12:04 2009 +0000 @@ -0,0 +1,351 @@ +/* +* Copyright (c) 1995-2009 Nokia Corporation and/or its subsidiary(-ies). +* All rights reserved. +* This component and the accompanying materials are made available +* under the terms of the License "Eclipse Public License v1.0" +* which accompanies this distribution, and is available +* at the URL "http://www.eclipse.org/legal/epl-v10.html". +* +* Initial Contributors: +* Nokia Corporation - initial contribution. +* +* Contributors: +* +* Description: +* e32\nklib\x86\vchelp.cpp +* +*/ + + +#ifndef __NAKED__ +#define __NAKED__ __declspec(naked) +#endif + +#include + +#pragma warning ( disable : 4414 ) // short jump to function converted to near + +extern "C" { +__NAKED__ void _allmul() +// +// Multiply two 64 bit integers returning a 64 bit result +// On entry: +// [esp+4], [esp+8] = arg 1 +// [esp+12], [esp+16] = arg 1 +// Return result in edx:eax +// Remove arguments from stack +// + { + _asm mov eax, [esp+4] // eax = low1 + _asm mul dword ptr [esp+16] // edx:eax = low1*high2 + _asm mov ecx, eax // keep low 32 bits of product + _asm mov eax, [esp+8] // eax = high1 + _asm mul dword ptr [esp+12] // edx:eax = high1*low2 + _asm add ecx, eax // accumulate low 32 bits of product + _asm mov eax, [esp+4] // eax = low1 + _asm mul dword ptr [esp+12] // edx:eax = low1*low2 + _asm add edx, ecx // add cross terms to high 32 bits + _asm ret 16 + } + +void udiv64_divby0() + { + _asm int 0 // division by zero exception + _asm ret + } + +__NAKED__ void UDiv64() + { + // unsigned divide edx:eax by edi:esi + // quotient in ebx:eax, remainder in edi:edx + // ecx, ebp, esi also modified + _asm test edi, edi + _asm jnz short UDiv64a // branch if divisor >= 2^32 + _asm test esi, esi +// _ASM_j(z,DivisionByZero) // if divisor=0, branch to error routine + _asm jz udiv64_divby0 + _asm mov ebx, eax // ebx=dividend low + _asm mov eax, edx // eax=dividend high + _asm xor edx, edx // edx=0 + _asm div esi // quotient high now in eax + _asm xchg eax, ebx // quotient high in ebx, dividend low in eax + _asm div esi // quotient now in ebx:eax, remainder in edi:edx + _asm ret + UDiv64e: + _asm xor eax, eax // set result to 0xFFFFFFFF + _asm dec eax + _asm jmp short UDiv64f + UDiv64a: + _asm js short UDiv64b // skip if divisor msb set + _asm bsr ecx, edi // ecx=bit number of divisor msb - 32 + _asm inc cl + _asm push edi // save divisor high + _asm push esi // save divisor low + _asm shrd esi, edi, cl // shift divisor right so that msb is bit 31 + _asm mov ebx, edx // dividend into ebx:ebp + _asm mov ebp, eax + _asm shrd eax, edx, cl // shift dividend right same number of bits + _asm shr edx, cl + _asm cmp edx, esi // check if approx quotient will be 2^32 + _asm jae short UDiv64e // if so, true result must be 0xFFFFFFFF + _asm div esi // approximate quotient now in eax + UDiv64f: + _asm mov ecx, eax // into ecx + _asm mul edi // multiply approx. quotient by divisor high + _asm mov esi, eax // ls dword into esi, ms into edi + _asm mov edi, edx + _asm mov eax, ecx // approx. quotient into eax + _asm mul dword ptr [esp] // multiply approx. quotient by divisor low + _asm add edx, esi // edi:edx:eax now equals approx. quotient * divisor + _asm adc edi, 0 + _asm xor esi, esi + _asm sub ebp, eax // subtract dividend - approx. quotient *divisor + _asm sbb ebx, edx + _asm sbb esi, edi + _asm jnc short UDiv64c // if no borrow, result OK + _asm dec ecx // else result is one too big + _asm add ebp, [esp] // and add divisor to get correct remainder + _asm adc ebx, [esp+4] + UDiv64c: + _asm mov eax, ecx // result into ebx:eax, remainder into edi:edx + _asm mov edi, ebx + _asm mov edx, ebp + _asm xor ebx, ebx + _asm add esp, 8 // remove temporary values from stack + _asm ret + UDiv64b: + _asm mov ebx, 1 + _asm sub eax, esi // subtract divisor from dividend + _asm sbb edx, edi + _asm jnc short UDiv64d // if no borrow, result=1, remainder in edx:eax + _asm add eax, esi // else add back + _asm adc edx, edi + _asm dec ebx // and decrement quotient + UDiv64d: + _asm mov edi, edx // remainder into edi:edx + _asm mov edx, eax + _asm mov eax, ebx // result in ebx:eax + _asm xor ebx, ebx + _asm ret + } + +__NAKED__ void _aulldiv() +// +// Divide two 64 bit unsigned integers returning a 64 bit result +// On entry: +// [esp+4], [esp+8] = dividend +// [esp+12], [esp+16] = divisor +// Return result in edx:eax +// Remove arguments from stack +// + { + _asm push ebp + _asm push edi + _asm push esi + _asm push ebx + _asm mov eax, [esp+20] + _asm mov edx, [esp+24] + _asm mov esi, [esp+28] + _asm mov edi, [esp+32] + _asm call UDiv64 + _asm mov edx, ebx + _asm pop ebx + _asm pop esi + _asm pop edi + _asm pop ebp + _asm ret 16 + } + +__NAKED__ void _alldiv() +// +// Divide two 64 bit signed integers returning a 64 bit result +// On entry: +// [esp+4], [esp+8] = dividend +// [esp+12], [esp+16] = divisor +// Return result in edx:eax +// Remove arguments from stack +// + { + _asm push ebp + _asm push edi + _asm push esi + _asm push ebx + _asm mov eax, [esp+20] + _asm mov edx, [esp+24] + _asm mov esi, [esp+28] + _asm mov edi, [esp+32] + _asm test edx, edx + _asm jns dividend_nonnegative + _asm neg edx + _asm neg eax + _asm sbb edx, 0 + dividend_nonnegative: + _asm test edi, edi + _asm jns divisor_nonnegative + _asm neg edi + _asm neg esi + _asm sbb edi, 0 + divisor_nonnegative: + _asm call UDiv64 + _asm mov ecx, [esp+24] + _asm mov edx, ebx + _asm xor ecx, [esp+32] + _asm jns quotient_nonnegative + _asm neg edx + _asm neg eax + _asm sbb edx, 0 + quotient_nonnegative: + _asm pop ebx + _asm pop esi + _asm pop edi + _asm pop ebp + _asm ret 16 + } + +__NAKED__ void _aullrem() +// +// Divide two 64 bit unsigned integers and return 64 bit remainder +// On entry: +// [esp+4], [esp+8] = dividend +// [esp+12], [esp+16] = divisor +// Return result in edx:eax +// Remove arguments from stack +// + { + _asm push ebp + _asm push edi + _asm push esi + _asm push ebx + _asm mov eax, [esp+20] + _asm mov edx, [esp+24] + _asm mov esi, [esp+28] + _asm mov edi, [esp+32] + _asm call UDiv64 + _asm mov eax, edx + _asm mov edx, edi + _asm pop ebx + _asm pop esi + _asm pop edi + _asm pop ebp + _asm ret 16 + } + +__NAKED__ void _allrem() +// +// Divide two 64 bit signed integers and return 64 bit remainder +// On entry: +// [esp+4], [esp+8] = dividend +// [esp+12], [esp+16] = divisor +// Return result in edx:eax +// Remove arguments from stack +// + { + _asm push ebp + _asm push edi + _asm push esi + _asm push ebx + _asm mov eax, [esp+20] + _asm mov edx, [esp+24] + _asm mov esi, [esp+28] + _asm mov edi, [esp+32] + _asm test edx, edx + _asm jns dividend_nonnegative + _asm neg edx + _asm neg eax + _asm sbb edx, 0 + dividend_nonnegative: + _asm test edi, edi + _asm jns divisor_nonnegative + _asm neg edi + _asm neg esi + _asm sbb edi, 0 + divisor_nonnegative: + _asm call UDiv64 + _asm mov eax, edx + _asm mov edx, edi + _asm cmp dword ptr [esp+24], 0 + _asm jns rem_nonnegative + _asm neg edx + _asm neg eax + _asm sbb edx, 0 + rem_nonnegative: + _asm pop ebx + _asm pop esi + _asm pop edi + _asm pop ebp + _asm ret 16 + } + +__NAKED__ void _allshr() +// +// Arithmetic shift right EDX:EAX by ECX +// + { + _asm cmp ecx, 64 + _asm jae asr_count_ge_64 + _asm cmp cl, 32 + _asm jae asr_count_ge_32 + _asm shrd eax, edx, cl + _asm sar edx, cl + _asm ret + asr_count_ge_32: + _asm sub cl, 32 + _asm mov eax, edx + _asm cdq + _asm sar eax, cl + _asm ret + asr_count_ge_64: + _asm sar edx, 32 + _asm mov eax, edx + _asm ret + } + +__NAKED__ void _allshl() +// +// shift left EDX:EAX by ECX +// + { + _asm cmp ecx, 64 + _asm jae lsl_count_ge_64 + _asm cmp cl, 32 + _asm jae lsl_count_ge_32 + _asm shld edx, eax, cl + _asm shl eax, cl + _asm ret + lsl_count_ge_32: + _asm sub cl, 32 + _asm mov edx, eax + _asm xor eax, eax + _asm shl edx, cl + _asm ret + lsl_count_ge_64: + _asm xor edx, edx + _asm xor eax, eax + _asm ret + } + +__NAKED__ void _aullshr() +// +// Logical shift right EDX:EAX by ECX +// + { + _asm cmp ecx, 64 + _asm jae lsr_count_ge_64 + _asm cmp cl, 32 + _asm jae lsr_count_ge_32 + _asm shrd eax, edx, cl + _asm shr edx, cl + _asm ret + lsr_count_ge_32: + _asm sub cl, 32 + _asm mov eax, edx + _asm xor edx, edx + _asm shr eax, cl + _asm ret + lsr_count_ge_64: + _asm xor edx, edx + _asm xor eax, eax + _asm ret + } +} + diff -r 7e3f204e6c81 -r f9c11be8c0b3 crypto/weakcryptospi/source/bigint/windowslider.cpp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/crypto/weakcryptospi/source/bigint/windowslider.cpp Tue Dec 01 11:12:04 2009 +0000 @@ -0,0 +1,73 @@ +/* +* Copyright (c) 2003-2009 Nokia Corporation and/or its subsidiary(-ies). +* All rights reserved. +* This component and the accompanying materials are made available +* under the terms of the License "Eclipse Public License v1.0" +* which accompanies this distribution, and is available +* at the URL "http://www.eclipse.org/legal/epl-v10.html". +* +* Initial Contributors: +* Nokia Corporation - initial contribution. +* +* Contributors: +* +* Description: +* +*/ + + +#include +#include "windowslider.h" +#include "../common/inlines.h" + +TWindowSlider::TWindowSlider(const TInteger& aExp, TUint aWindowSize) + : iExp(aExp), iSize(aWindowSize) + { + if(iSize == 0) + { + TUint expLen = iExp.BitCount(); + //These numbers are more or less arbitrary and can be tuned for empirical + //performance results if desired. It's a trade off between amount of + //precomputation (more if larger iSize) and number of iterations + //(more if smaller iSize). The current defaults were obtained + //from crypto++ + if( expLen <= 17 ) + iSize = 1; + else if( expLen <= 24 ) + iSize = 2; + else if( expLen <= 70 ) + iSize = 3; + else if( expLen <= 197 ) + iSize = 4; + else if( expLen <= 539 ) + iSize = 5; + else if( expLen <= 1434 ) + iSize = 6; + else + iSize = 7; + } + assert(iSize>=1 && iSize<=7); + } + +void TWindowSlider::FindNextWindow(TUint aBegin) + { + assert(iExp.Bit(aBegin)); //initial bit must be 1 + TInt end = aBegin; + TUint temp = 0; + iValue = 0; + TUint j = 0; + for(TInt i=aBegin; i>=0 && j>= (WORD_BITS - iLength); + } + diff -r 7e3f204e6c81 -r f9c11be8c0b3 crypto/weakcryptospi/source/bigint/windowslider.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/crypto/weakcryptospi/source/bigint/windowslider.h Tue Dec 01 11:12:04 2009 +0000 @@ -0,0 +1,62 @@ +/* +* Copyright (c) 2003-2009 Nokia Corporation and/or its subsidiary(-ies). +* All rights reserved. +* This component and the accompanying materials are made available +* under the terms of the License "Eclipse Public License v1.0" +* which accompanies this distribution, and is available +* at the URL "http://www.eclipse.org/legal/epl-v10.html". +* +* Initial Contributors: +* Nokia Corporation - initial contribution. +* +* Contributors: +* +* Description: +* TWindowSlider class implementation +* +*/ + + +/** + @file + @internalComponent +*/ + +#ifndef __WINDOWSLIDER_H__ +#define __WINDOWSLIDER_H__ + +#include + +class TInteger; +/** Utility class used by our fast exponentiation routines.\n\n + * See HAC 14.85 for an explanation of how window sliding helps speed things up. + * @internalComponent + */ +class TWindowSlider +{ +public: + /** + * @param aExp The exponent you are using. + * @param aWindowSize The window size. Leave as default value for the + * constructor to pick a window size appropriate for the given aExp + * @internalComponent + */ + TWindowSlider(const TInteger& aExp, TUint aWindowSize=0); + /** + * Finds the next "window" as defined by HAC 14.85. The actual bitstring + * value is in iValue and it's length in iLength. These remain valid until + * the next call to FindNextWindow() + */ + void FindNextWindow(TUint aBegin); + inline TUint WindowSize(void) {return iSize;} + inline TUint Value(void) {return iValue;} + inline TUint Length(void) {return iLength;} + +private: + const TInteger& iExp; ///the exponent all this is being calculated on + TUint iSize; ///The size of the sliding window + TUint iValue; ///the value found by the most recent FindNextWindow() call + TUint iLength;///the bit length of the iValue +}; + +#endif diff -r 7e3f204e6c81 -r f9c11be8c0b3 crypto/weakcryptospi/source/bigint/words.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/crypto/weakcryptospi/source/bigint/words.h Tue Dec 01 11:12:04 2009 +0000 @@ -0,0 +1,147 @@ +/* +* Copyright (c) 2003-2009 Nokia Corporation and/or its subsidiary(-ies). +* All rights reserved. +* This component and the accompanying materials are made available +* under the terms of the License "Eclipse Public License v1.0" +* which accompanies this distribution, and is available +* at the URL "http://www.eclipse.org/legal/epl-v10.html". +* +* Initial Contributors: +* Nokia Corporation - initial contribution. +* +* Contributors: +* +* Description: +* +*/ + + +/** + @file + @internalComponent +*/ + +#ifndef __BIGINT_WORDS_H__ +#define __BIGINT_WORDS_H__ + +#include "../common/inlines.h" + +inline void ArraySetBit(TUint* aS, TUint aJ) + { + aS[aJ/WORD_BITS] |= (1L << (aJ%WORD_BITS)); + } + +inline TUint CountWords(const TUint *X, TUint N) + { + while (N && X[N-1]==0) + N--; + return N; + } + +inline void SetWords(TUint *r, TUint a, TUint n) + { + Mem::Fill(r, WordsToBytes(n), a); + } + +inline void CopyWords(TUint *r, const TUint *a, TUint n) + { + Mem::Copy(r, a, WordsToBytes(n)); + } + +inline TUint ShiftWordsLeftByBits(TUint *r, TUint n, TUint shiftBits) + { + assert (shiftBits> (WORD_BITS-shiftBits); + } + return carry; + } + +inline TUint ShiftWordsRightByBits(TUint *r, TUint n, TUint shiftBits) +{ + assert (shiftBits=0; i--) + { + u = r[i]; + r[i] = (u >> shiftBits) | carry; + carry = u << (WORD_BITS-shiftBits); + } + return carry; + } + +inline TUint CryptoMin(TUint aLeft, TUint aRight) + { + return(aLeft=shiftWords; i--) + r[i] = r[i-shiftWords]; + SetWords(r, 0, shiftWords); + } + } + +inline void ShiftWordsRightByWords(TUint *r, TUint n, TUint shiftWords) + { + shiftWords = CryptoMin(shiftWords, n); + if (shiftWords) + { + for (TUint i=0; i+shiftWords +#include "cryptostrength.h" +#include + +#ifdef CRYPTO_STRONG_BUILD +const TInt KDTIMaxSymmetricKeyBits = KMaxTInt; +const TInt KDTIMaxAsymmetricKeyBits = KMaxTInt; +const TCrypto::TStrength KCryptoStrength=TCrypto::EStrong; +#else //CRYPTO_WEAK_BUILD +const TInt KDTIMaxSymmetricKeyBits = 56; +const TInt KDTIMaxAsymmetricKeyBits = 512; +const TCrypto::TStrength KCryptoStrength=TCrypto::EWeak; +#endif //CRYPTO_STRONG_BUILD + +EXPORT_C TCrypto::TStrength TCrypto::Strength(void) + { + return (KCryptoStrength); + } + +EXPORT_C TBool TCrypto::IsSymmetricWeakEnoughL(TInt aSymmetricKeyBits) + { + if(aSymmetricKeyBits > KDTIMaxSymmetricKeyBits) + { + User::Leave(KErrKeyNotWeakEnough); + } + return ETrue; + } + +EXPORT_C TBool TCrypto::IsAsymmetricWeakEnoughL(TInt aAsymmetricKeyBits) + { + if(aAsymmetricKeyBits > KDTIMaxAsymmetricKeyBits) + { + User::Leave(KErrKeyNotWeakEnough); + } + return ETrue; + } + diff -r 7e3f204e6c81 -r f9c11be8c0b3 crypto/weakcryptospi/source/common/inlines.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/crypto/weakcryptospi/source/common/inlines.h Tue Dec 01 11:12:04 2009 +0000 @@ -0,0 +1,272 @@ +/* +* Copyright (c) 2003-2009 Nokia Corporation and/or its subsidiary(-ies). +* All rights reserved. +* This component and the accompanying materials are made available +* under the terms of the License "Eclipse Public License v1.0" +* which accompanies this distribution, and is available +* at the URL "http://www.eclipse.org/legal/epl-v10.html". +* +* Initial Contributors: +* Nokia Corporation - initial contribution. +* +* Contributors: +* +* Description: +* +*/ + + +/** + @file + @internalTechnology +*/ + +#ifndef __INLINES_H__ +#define __INLINES_H__ + +#include + +#define assert(x) __ASSERT_DEBUG((x), User::Panic(_L("crypto.dll"), 1)) + +#if defined(__GCC32__) +typedef long long Int64; +typedef unsigned long long Uint64; +#elif defined(__VC32__) +typedef __int64 Int64; +typedef unsigned __int64 Uint64; +#elif defined(__CW32__) +#pragma longlong on +typedef long long Int64; +typedef unsigned long long Uint64; +#endif + +typedef Uint64 dword; +typedef TUint word; +typedef TUint32 word32; + +const TUint WORD_SIZE = sizeof(TUint); +const TUint WORD_BYTES = WORD_SIZE; +const TUint BYTE_BITS = 8; +const TUint WORD_BITS = WORD_SIZE*BYTE_BITS; + +//These next two versions of GETBYTE compile to LDR's of words and then shifts +//and ands to get it down to a byte. +//#define GETBYTE(x, y) (TUint)(((x)>>(8*(y)))&255) +//#define GETBYTE(x, y) (TUint)TUint8((x)>>(8*(y))) + +//This next version gets the best assembler on gcc and armv4 (it uses LDRB +//rather than shifts and ands +#define GETBYTE(x, y) (((TUint8 *)&(x))[y]) + +#define MAKE_DWORD(lowWord, highWord) ((dword(highWord)<>WORD_BITS) + +template inline void TClassSwap(T& a, T& b) + { + T temp(a); + a = b; + b = temp; + } + +// Returns log2 of aNum where aNum is a power +// of two +inline TUint8 CryptoLog2(TUint8 aNum) + { + switch (aNum) + { + case 1: + return 0; + case 1 << 1: + return 1; + case 1 << 2: + return 2; + case 1 << 3: + return 3; + case 1 << 4: + return 4; + case 1 << 5: + return 5; + case 1 << 6: + return 6; + case 1 << 7: + return 7; + default: + ASSERT(EFalse); + } + return 0; + } + +inline TUint BitsToBytes(TUint bitCount) + { + return ((bitCount+7)/(BYTE_BITS)); + } + +inline TUint BytesToWords(TUint byteCount) + { + return ((byteCount+WORD_SIZE-1)/WORD_SIZE); + } + +inline TUint BitsToWords(TUint bitCount) + { + return ((bitCount+WORD_BITS-1)/(WORD_BITS)); + } + +inline TUint WordsToBits(TUint wordCount) + { + return wordCount * WORD_BITS; + } + +inline TUint BytesToBits(TUint byteCount) + { + return byteCount * BYTE_BITS; + } + +inline TUint WordsToBytes(TUint wordCount) + { + return wordCount * WORD_BYTES; + } + +inline void XorWords(TUint32* r, const TUint32* a, TUint n) + { + assert(((TUint32)r & 3) == 0); // Catch alignment problems + + for (TUint i=0; i inline T rotlFixed(T x, TUint y) + { + assert(y < sizeof(T)*8); + return ( (T)((x<>(sizeof(T)*8-y))) ); + } + +template inline T rotrFixed(T x, TUint y) + { + assert(y < sizeof(T)*8); + return ((T)((x>>y) | (x<<(sizeof(T)*8-y)))); + } + +inline TUint32 byteReverse(TUint32 value) + { + value = ((value & 0xFF00FF00) >> 8) | ((value & 0x00FF00FF) << 8); + return rotlFixed(value, 16U); + } + +template +void byteReverse(T* out, const T* in, TUint32 byteCount) + { + TUint count = (byteCount+sizeof(T)-1)/sizeof(T); + for (TUint i=0; i +inline void GetUserKeyLittleEndian(T *out, TUint32 outlen, const TUint8* in, TUint32 inlen) + { + const TUint U = sizeof(T); + assert(inlen <= outlen*U); + Mem::Copy(out, in, inlen); + Mem::FillZ((TUint8*)out+inlen, outlen*U-inlen); + } + +template +inline void GetUserKeyBigEndian(T *out, TUint32 outlen, const TUint8* in, TUint32 inlen) + { + const TUint U = sizeof(T); + assert(inlen <= outlen*U); + Mem::Copy(out, in, inlen); + Mem::FillZ((TUint8*)out+inlen, outlen*U-inlen); + byteReverse(out, out, inlen); + } + +// The following methods have be changed to use byte rather than word accesses, +// as if the input pointer is not be word aligned a fault occurs on arm +// hardware. This isn't optimal from a performance point of view, but it is +// neccessary because the crypto interfaces (CSymmetricCipher, +// CBlockTransformation) allow clients to pass non-aligned data. + +// Fetch 4 words from user's buffer into "a", "b", "c", "d" in LITTLE-endian order +inline void GetBlockLittleEndian(const TUint8* block, TUint16 &a, TUint16 &b, TUint16 &c, TUint16 &d) + { + a = (TUint16)(block[0] | block[1] << 8); + b = (TUint16)(block[2] | block[3] << 8); + c = (TUint16)(block[4] | block[5] << 8); + d = (TUint16)(block[6] | block[7] << 8); + } + +// Put 4 words back into user's buffer in LITTLE-endian order +inline void PutBlockLittleEndian(TUint8* block, TUint16 a, TUint16 b, TUint16 c, TUint16 d) + { + block[0] = (TUint8)(a & 0xff); + block[1] = (TUint8)(a >> 8); + block[2] = (TUint8)(b & 0xff); + block[3] = (TUint8)(b >> 8); + block[4] = (TUint8)(c & 0xff); + block[5] = (TUint8)(c >> 8); + block[6] = (TUint8)(d & 0xff); + block[7] = (TUint8)(d >> 8); + } + +// Fetch 1 word from user's buffer in BIG-endian order +inline void GetWordBigEndian(const TUint8* block, TUint32 &a) + { + a = block[0] << 24 | block[1] << 16 | block[2] << 8 | block[3]; + } + +// Put 1 word back into user's buffer in BIG-endian order +inline void PutWordBigEndian(TUint8* block, TUint32 a) + { + block[0] = (TUint8)(a >> 24); + block[1] = (TUint8)((a >> 16) & 0xff); + block[2] = (TUint8)((a >> 8) & 0xff); + block[3] = (TUint8)(a & 0xff); + } + +// Fetch 2 words from user's buffer into "a", "b" in BIG-endian order +inline void GetBlockBigEndian(const TUint8* block, TUint32 &a, TUint32& b) + { + GetWordBigEndian(block, a); + GetWordBigEndian(block + 4, b); + } + +// Put 2 words back into user's buffer in BIG-endian order +inline void PutBlockBigEndian(TUint8* block, TUint32 a, TUint32 b) + { + PutWordBigEndian(block, a); + PutWordBigEndian(block + 4, b); + } + +// Fetch 4 words from user's buffer into "a", "b", "c", "d" in BIG-endian order +inline void GetBlockBigEndian(const TUint8* block, TUint32& a, TUint32& b, TUint32& c, TUint32& d) + { + GetWordBigEndian(block, a); + GetWordBigEndian(block + 4, b); + GetWordBigEndian(block + 8, c); + GetWordBigEndian(block + 12, d); + } + +// Put 4 words back into user's buffer in BIG-endian order +inline void PutBlockBigEndian(TUint8* block, TUint32 a, TUint32 b, TUint32 c, TUint32 d) + { + PutWordBigEndian(block, a); + PutWordBigEndian(block + 4, b); + PutWordBigEndian(block + 8, c); + PutWordBigEndian(block + 12, d); + } + +#endif // __INLINES_H__ diff -r 7e3f204e6c81 -r f9c11be8c0b3 crypto/weakcryptospi/source/common/keyconverter.cpp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/crypto/weakcryptospi/source/common/keyconverter.cpp Tue Dec 01 11:12:04 2009 +0000 @@ -0,0 +1,210 @@ +/* +* Copyright (c) 2007-2009 Nokia Corporation and/or its subsidiary(-ies). +* All rights reserved. +* This component and the accompanying materials are made available +* under the terms of the License "Eclipse Public License v1.0" +* which accompanies this distribution, and is available +* at the URL "http://www.eclipse.org/legal/epl-v10.html". +* +* Initial Contributors: +* Nokia Corporation - initial contribution. +* +* Contributors: +* +* Description: +* +*/ + + +#include "keyconverter.h" +#include +#include +#include "keys.h" +#include "keypair.h" + +using namespace CryptoSpi; + +/* CKeyConverter */ + +CKey* KeyConverter::CreateKeyL(const CDHPrivateKey& aPrivateKey) + { + /* + * setup key attributes + */ + TKeyProperty keyProperty; + keyProperty.iAlgorithmUid = KDHAgreementUid; + + /* + * extract key parameters from the compatibility dh key object + */ + CCryptoParams* keyParameters = CCryptoParams::NewLC(); + keyParameters->AddL(aPrivateKey.N(), KDhKeyParameterNUid); + keyParameters->AddL(aPrivateKey.G(), KDhKeyParameterGUid); + keyParameters->AddL(aPrivateKey.x(), KDhKeyParameterxUid); + + /* + * create a CKey from the parameters + */ + CKey* newPrivateKey = CKey::NewL(keyProperty, *keyParameters); + + CleanupStack::PopAndDestroy(1, keyParameters); + return newPrivateKey; + } + +CKey* KeyConverter::CreateKeyL(const CDHPublicKey& aPublicKey) + { + /* + * setup key attributes + */ + TKeyProperty keyProperty; + keyProperty.iAlgorithmUid = KDHAgreementUid; + + /* + * extract key parameters from the compatibility dh key object + */ + CCryptoParams* keyParameters = CCryptoParams::NewLC(); + keyParameters->AddL(aPublicKey.N(), KDhKeyParameterNUid); + keyParameters->AddL(aPublicKey.G(), KDhKeyParameterGUid); + keyParameters->AddL(aPublicKey.X(), KDhKeyParameterXUid); + + /* + * create a CKey from the parameters + */ + CKey* newPublicKey = CKey::NewL(keyProperty, *keyParameters); + + CleanupStack::PopAndDestroy(1, keyParameters); + return newPublicKey; + } + +CKey* KeyConverter::CreateKeyL(const CDSAPrivateKey& aPrivateKey) + { + TKeyProperty keyProperty = {KDsaSignerUid, KNullUid, KDsaPrivateKeyUid, KNonEmbeddedKeyUid}; + + CCryptoParams* keyParameters = CCryptoParams::NewLC(); + keyParameters->AddL(aPrivateKey.P(), KDsaKeyParameterPUid); + keyParameters->AddL(aPrivateKey.Q(), KDsaKeyParameterQUid); + keyParameters->AddL(aPrivateKey.G(), KDsaKeyParameterGUid); + keyParameters->AddL(aPrivateKey.X(), KDsaKeyParameterXUid); + + CKey* newPrivateKey = CKey::NewL(keyProperty, *keyParameters); + CleanupStack::PopAndDestroy(keyParameters); + return newPrivateKey; + } + +CKey* KeyConverter::CreateKeyL(const CDSAPublicKey& aPublicKey) + { + TKeyProperty keyProperty = {KDsaSignerUid, KNullUid, KDsaPublicKeyUid, KNonEmbeddedKeyUid}; + + CCryptoParams* keyParameters = CCryptoParams::NewLC(); + keyParameters->AddL(aPublicKey.P(), KDsaKeyParameterPUid); + keyParameters->AddL(aPublicKey.Q(), KDsaKeyParameterQUid); + keyParameters->AddL(aPublicKey.G(), KDsaKeyParameterGUid); + keyParameters->AddL(aPublicKey.Y(), KDsaKeyParameterYUid); + + CKey* newPublicKey = CKey::NewL(keyProperty, *keyParameters); + CleanupStack::PopAndDestroy(keyParameters); + return newPublicKey; + } + +// RSA convertors /////////////////////////////////////////////////////////////////////////// +CKey* KeyConverter::CreateKeyL(const CRSAPrivateKeyCRT& aPrivateKey) + { + TKeyProperty keyProperty = {KRsaCipherUid, + NULL, + KRsaPrivateKeyCRTUid, + KNonEmbeddedKeyUid }; + + CCryptoParams* keyParameters = CCryptoParams::NewLC(); + keyParameters->AddL(aPrivateKey.N(), KRsaKeyParameterNUid); + keyParameters->AddL(aPrivateKey.P(), KRsaKeyParameterPUid); + keyParameters->AddL(aPrivateKey.Q(), KRsaKeyParameterQUid); + keyParameters->AddL(aPrivateKey.QInv(), KRsaKeyParameterQInvUid); + keyParameters->AddL(aPrivateKey.DP(), KRsaKeyParameterDPUid); + keyParameters->AddL(aPrivateKey.DQ(), KRsaKeyParameterDQUid); + + CKey* newPrivateKey = CKey::NewL(keyProperty, *keyParameters); + CleanupStack::PopAndDestroy(keyParameters); + return newPrivateKey; + } + +CKey* KeyConverter::CreateKeyL(const CRSAPrivateKeyStandard& aPrivateKey) + { + TKeyProperty keyProperty = {KRsaCipherUid, + NULL, + KRsaPrivateKeyStandardUid, + KNonEmbeddedKeyUid }; + + CCryptoParams* keyParameters = CCryptoParams::NewLC(); + keyParameters->AddL(aPrivateKey.N(), KRsaKeyParameterNUid); + keyParameters->AddL(aPrivateKey.D(), KRsaKeyParameterDUid); + + CKey* newPrivateKey = CKey::NewL(keyProperty, *keyParameters); + CleanupStack::PopAndDestroy(keyParameters); + return newPrivateKey; + } + +CKey* KeyConverter::CreateKeyL(const CRSAPublicKey& aPublicKey) + { + TKeyProperty keyProperty = {KRsaCipherUid, + NULL, + KRsaPublicKeyUid, + KNonEmbeddedKeyUid }; + + CCryptoParams* keyParameters = CCryptoParams::NewLC(); + keyParameters->AddL(aPublicKey.N(), KRsaKeyParameterNUid); + keyParameters->AddL(aPublicKey.E(), KRsaKeyParameterEUid); + + CKey* newPublicKey = CKey::NewL(keyProperty, *keyParameters); + CleanupStack::PopAndDestroy(keyParameters); + return newPublicKey; + } + +CKey* KeyConverter::CreateKeyL(const CRSAPrivateKey& aPrivateKey) + { + // Determine which type of private key + if (aPrivateKey.PrivateKeyType() == EStandard) + { + const CRSAPrivateKeyStandard* stdKey = static_cast(&aPrivateKey); + return KeyConverter::CreateKeyL(*stdKey); + } + else if (aPrivateKey.PrivateKeyType() == EStandardCRT) + { + const CRSAPrivateKeyCRT* crtKey = static_cast(&aPrivateKey); + return KeyConverter::CreateKeyL(*crtKey); + } + return NULL; // Keep the compiler happy + } + +// Methods which are not supported or not exposed out of library can be excluded from the coverage. +#ifdef _BullseyeCoverage +#pragma suppress_warnings on +#pragma BullseyeCoverage off +#pragma suppress_warnings off +#endif + +CKeyPair* KeyConverter::CreateKeyPairL(const CDSAKeyPair& /*aKeyPair*/) + { + return NULL; + } + +CKeyPair* KeyConverter::CreateKeyPairL(const CRSAKeyPair& aKeyPair) + { + CKey* newPrivateKey = KeyConverter::CreateKeyL(aKeyPair.PrivateKey()); + CleanupStack::PushL(newPrivateKey); + CKey* newPublicKey = KeyConverter::CreateKeyL(aKeyPair.PublicKey()); + CleanupStack::PushL(newPublicKey); + CKeyPair* newKeyPair = CKeyPair::NewL(newPublicKey, newPrivateKey); + CleanupStack::Pop(2, newPrivateKey); + return newKeyPair; + } + +CKeyPair* KeyConverter::CreateKeyPairL(const CDHKeyPair& aKeyPair) + { + CKey* newPrivateKey = KeyConverter::CreateKeyL(aKeyPair.PrivateKey()); + CleanupStack::PushL(newPrivateKey); + CKey* newPublicKey = KeyConverter::CreateKeyL(aKeyPair.PublicKey()); + CleanupStack::PushL(newPublicKey); + CKeyPair* newKeyPair = CKeyPair::NewL(newPublicKey, newPrivateKey); + CleanupStack::Pop(2, newPrivateKey); + return newKeyPair; + } diff -r 7e3f204e6c81 -r f9c11be8c0b3 crypto/weakcryptospi/source/common/keyidentifierutil.cpp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/crypto/weakcryptospi/source/common/keyidentifierutil.cpp Tue Dec 01 11:12:04 2009 +0000 @@ -0,0 +1,68 @@ +/* +* Copyright (c) 2003-2009 Nokia Corporation and/or its subsidiary(-ies). +* All rights reserved. +* This component and the accompanying materials are made available +* under the terms of the License "Eclipse Public License v1.0" +* which accompanies this distribution, and is available +* at the URL "http://www.eclipse.org/legal/epl-v10.html". +* +* Initial Contributors: +* Nokia Corporation - initial contribution. +* +* Contributors: +* +* Description: +* +*/ + + +#include "keyidentifierutil.h" +#include "hash.h" +#include "asymmetrickeys.h" + +EXPORT_C void KeyIdentifierUtil::RSAKeyIdentifierL( + const CRSAPublicKey& aKey, TKeyIdentifier& aIdentifier) + { + aIdentifier.FillZ(); + + // Generate a hash of the appropriate data (for TKeyIdentifier) + const TInteger& keyModulus = aKey.N(); + HBufC8* modulusData = keyModulus.BufferLC(); + CSHA1* sha1 = CSHA1::NewL(); + CleanupStack::PushL(sha1); + TPtrC8 hash = sha1->Final(*modulusData); + aIdentifier.Copy(hash); + CleanupStack::PopAndDestroy(2); // sha1, modulusData + } + +EXPORT_C void KeyIdentifierUtil::DSAKeyIdentifierL( + const CDSAPublicKey& aKey, TKeyIdentifier& aIdentifier) + { + aIdentifier.FillZ(); + + // Generate a hash of the appropriate data (for TKeyIdentifier) + const TInteger& Y = aKey.Y(); + HBufC8* YData = Y.BufferLC(); + CSHA1* sha1 = CSHA1::NewL(); + CleanupStack::PushL(sha1); + TPtrC8 hash = sha1->Final(*YData); + aIdentifier.Copy(hash); + CleanupStack::PopAndDestroy(2); // sha1, YData + } + +EXPORT_C void KeyIdentifierUtil::DHKeyIdentifierL( + const RInteger& aKey, TKeyIdentifier& aIdentifier) + { + if (aKey.IsZero()) + User::Leave(KErrArgument); + + aIdentifier.FillZ(); + + // Generate a hash of the appropriate data (for TKeyIdentifier) + HBufC8* XData = aKey.BufferLC(); + CSHA1* sha1 = CSHA1::NewL(); + CleanupStack::PushL(sha1); + TPtrC8 hash = sha1->Final(*XData); + aIdentifier.Copy(hash); + CleanupStack::PopAndDestroy(2); // sha1, XData + } diff -r 7e3f204e6c81 -r f9c11be8c0b3 crypto/weakcryptospi/source/cryptoswitch/cryptography_stubs.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/crypto/weakcryptospi/source/cryptoswitch/cryptography_stubs.h Tue Dec 01 11:12:04 2009 +0000 @@ -0,0 +1,2613 @@ +/* +* Copyright (c) 2005-2009 Nokia Corporation and/or its subsidiary(-ies). +* All rights reserved. +* This component and the accompanying materials are made available +* under the terms of the License "Eclipse Public License v1.0" +* which accompanies this distribution, and is available +* at the URL "http://www.eclipse.org/legal/epl-v10.html". +* +* Initial Contributors: +* Nokia Corporation - initial contribution. +* +* Contributors: +* +* Description: +* Generated from cryptographyU.def +* +*/ + + + + +/** + @file + @internalComponent +*/ + +extern "C" { + +void common_dispatch(); + + +__declspec(dllexport) +__declspec(naked) +void call_vector_1 () + { + // ; protected: __thiscall CBlockChainingMode::CBlockChainingMode(void) + _asm mov eax, 1 + _asm jmp common_dispatch + } + + +__declspec(dllexport) +__declspec(naked) +void call_vector_2 () + { + // ; protected: __thiscall CDH::CDH(class CDHPrivateKey const &) + _asm mov eax, 2 + _asm jmp common_dispatch + } + + +__declspec(dllexport) +__declspec(naked) +void call_vector_3 () + { + // ; protected: __thiscall CDHKeyPair::CDHKeyPair(void) + _asm mov eax, 3 + _asm jmp common_dispatch + } + + +__declspec(dllexport) +__declspec(naked) +void call_vector_4 () + { + // ; protected: __thiscall CDHParameters::CDHParameters(class RInteger &,class RInteger &) + _asm mov eax, 4 + _asm jmp common_dispatch + } + + +__declspec(dllexport) +__declspec(naked) +void call_vector_5 () + { + // ; protected: __thiscall CDHParameters::CDHParameters(void) + _asm mov eax, 5 + _asm jmp common_dispatch + } + + +__declspec(dllexport) +__declspec(naked) +void call_vector_6 () + { + // ; protected: __thiscall CDHPrivateKey::CDHPrivateKey(class RInteger &,class RInteger &,class RInteger &) + _asm mov eax, 6 + _asm jmp common_dispatch + } + + +__declspec(dllexport) +__declspec(naked) +void call_vector_7 () + { + // ; protected: __thiscall CDHPrivateKey::CDHPrivateKey(void) + _asm mov eax, 7 + _asm jmp common_dispatch + } + + +__declspec(dllexport) +__declspec(naked) +void call_vector_8 () + { + // ; protected: __thiscall CDHPublicKey::CDHPublicKey(class RInteger &,class RInteger &,class RInteger &) + _asm mov eax, 8 + _asm jmp common_dispatch + } + + +__declspec(dllexport) +__declspec(naked) +void call_vector_9 () + { + // ; protected: __thiscall CDHPublicKey::CDHPublicKey(void) + _asm mov eax, 9 + _asm jmp common_dispatch + } + + +__declspec(dllexport) +__declspec(naked) +void call_vector_10 () + { + // ; protected: __thiscall CDSAKeyPair::CDSAKeyPair(void) + _asm mov eax, 10 + _asm jmp common_dispatch + } + + +__declspec(dllexport) +__declspec(naked) +void call_vector_11 () + { + // ; protected: __thiscall CDSAParameters::CDSAParameters(class RInteger &,class RInteger &,class RInteger &) + _asm mov eax, 11 + _asm jmp common_dispatch + } + + +__declspec(dllexport) +__declspec(naked) +void call_vector_12 () + { + // ; protected: __thiscall CDSAParameters::CDSAParameters(void) + _asm mov eax, 12 + _asm jmp common_dispatch + } + + +__declspec(dllexport) +__declspec(naked) +void call_vector_13 () + { + // ; protected: __thiscall CDSAPrimeCertificate::CDSAPrimeCertificate(unsigned int) + _asm mov eax, 13 + _asm jmp common_dispatch + } + + +__declspec(dllexport) +__declspec(naked) +void call_vector_14 () + { + // ; protected: __thiscall CDSAPrimeCertificate::CDSAPrimeCertificate(void) + _asm mov eax, 14 + _asm jmp common_dispatch + } + + +__declspec(dllexport) +__declspec(naked) +void call_vector_15 () + { + // ; protected: __thiscall CDSAPrivateKey::CDSAPrivateKey(class RInteger &,class RInteger &,class RInteger &,class RInteger &) + _asm mov eax, 15 + _asm jmp common_dispatch + } + + +__declspec(dllexport) +__declspec(naked) +void call_vector_16 () + { + // ; protected: __thiscall CDSAPrivateKey::CDSAPrivateKey(void) + _asm mov eax, 16 + _asm jmp common_dispatch + } + + +__declspec(dllexport) +__declspec(naked) +void call_vector_17 () + { + // ; protected: __thiscall CDSAPublicKey::CDSAPublicKey(class RInteger &,class RInteger &,class RInteger &,class RInteger &) + _asm mov eax, 17 + _asm jmp common_dispatch + } + + +__declspec(dllexport) +__declspec(naked) +void call_vector_18 () + { + // ; protected: __thiscall CDSAPublicKey::CDSAPublicKey(void) + _asm mov eax, 18 + _asm jmp common_dispatch + } + + +__declspec(dllexport) +__declspec(naked) +void call_vector_19 () + { + // ; protected: __thiscall CDSASignature::CDSASignature(class RInteger &,class RInteger &) + _asm mov eax, 19 + _asm jmp common_dispatch + } + + +__declspec(dllexport) +__declspec(naked) +void call_vector_20 () + { + // ; protected: __thiscall CDSASignature::CDSASignature(void) + _asm mov eax, 20 + _asm jmp common_dispatch + } + + +__declspec(dllexport) +__declspec(naked) +void call_vector_21 () + { + // ; protected: __thiscall CPadding::CPadding(int) + _asm mov eax, 21 + _asm jmp common_dispatch + } + + +__declspec(dllexport) +__declspec(naked) +void call_vector_22 () + { + // ; protected: __thiscall CPaddingNone::CPaddingNone(int) + _asm mov eax, 22 + _asm jmp common_dispatch + } + + +__declspec(dllexport) +__declspec(naked) +void call_vector_23 () + { + // ; protected: __thiscall CPaddingPKCS1Encryption::CPaddingPKCS1Encryption(int) + _asm mov eax, 23 + _asm jmp common_dispatch + } + + +__declspec(dllexport) +__declspec(naked) +void call_vector_24 () + { + // ; protected: __thiscall CPaddingPKCS1Signature::CPaddingPKCS1Signature(int) + _asm mov eax, 24 + _asm jmp common_dispatch + } + + +__declspec(dllexport) +__declspec(naked) +void call_vector_25 () + { + // ; protected: __thiscall CPaddingSSLv3::CPaddingSSLv3(int) + _asm mov eax, 25 + _asm jmp common_dispatch + } + + +__declspec(dllexport) +__declspec(naked) +void call_vector_26 () + { + // ; protected: __thiscall CRSAKeyPair::CRSAKeyPair(void) + _asm mov eax, 26 + _asm jmp common_dispatch + } + + +__declspec(dllexport) +__declspec(naked) +void call_vector_27 () + { + // ; protected: __thiscall CRSAParameters::CRSAParameters(class RInteger &) + _asm mov eax, 27 + _asm jmp common_dispatch + } + + +__declspec(dllexport) +__declspec(naked) +void call_vector_28 () + { + // ; protected: __thiscall CRSAParameters::CRSAParameters(void) + _asm mov eax, 28 + _asm jmp common_dispatch + } + + +__declspec(dllexport) +__declspec(naked) +void call_vector_29 () + { + // ; protected: __thiscall CRSAPrivateKeyCRT::CRSAPrivateKeyCRT(class RInteger &,class RInteger &,class RInteger &,class RInteger &,class RInteger &,class RInteger &) + _asm mov eax, 29 + _asm jmp common_dispatch + } + + +__declspec(dllexport) +__declspec(naked) +void call_vector_30 () + { + // ; protected: __thiscall CRSAPrivateKeyStandard::CRSAPrivateKeyStandard(class RInteger &,class RInteger &) + _asm mov eax, 30 + _asm jmp common_dispatch + } + + +__declspec(dllexport) +__declspec(naked) +void call_vector_31 () + { + // ; protected: __thiscall CRSAPublicKey::CRSAPublicKey(class RInteger &,class RInteger &) + _asm mov eax, 31 + _asm jmp common_dispatch + } + + +__declspec(dllexport) +__declspec(naked) +void call_vector_32 () + { + // ; protected: __thiscall CRSAPublicKey::CRSAPublicKey(void) + _asm mov eax, 32 + _asm jmp common_dispatch + } + + +__declspec(dllexport) +__declspec(naked) +void call_vector_33 () + { + // ; protected: __thiscall CRSASignature::CRSASignature(class RInteger &) + _asm mov eax, 33 + _asm jmp common_dispatch + } + + +__declspec(dllexport) +__declspec(naked) +void call_vector_34 () + { + // ; protected: __thiscall CRijndael::CRijndael(void) + _asm mov eax, 34 + _asm jmp common_dispatch + } + + +__declspec(dllexport) +__declspec(naked) +void call_vector_35 () + { + // ; protected: __thiscall MCryptoSystem::MCryptoSystem(void) + _asm mov eax, 35 + _asm jmp common_dispatch + } + + +__declspec(dllexport) +__declspec(naked) +void call_vector_36 () + { + // ; protected: __thiscall CDecryptor::CDecryptor(void) + _asm mov eax, 36 + _asm jmp common_dispatch + } + + +__declspec(dllexport) +__declspec(naked) +void call_vector_37 () + { + // ; protected: __thiscall CEncryptor::CEncryptor(void) + _asm mov eax, 37 + _asm jmp common_dispatch + } + + +__declspec(dllexport) +__declspec(naked) +void call_vector_38 () + { + // ; protected: __thiscall MSignatureSystem::MSignatureSystem(void) + _asm mov eax, 38 + _asm jmp common_dispatch + } + + +__declspec(dllexport) +__declspec(naked) +void call_vector_39 () + { + // ; public: __thiscall RInteger::RInteger(void) + _asm mov eax, 39 + _asm jmp common_dispatch + } + + +__declspec(dllexport) +__declspec(naked) +void call_vector_40 () + { + // ; protected: __thiscall TInteger::TInteger(void) + _asm mov eax, 40 + _asm jmp common_dispatch + } + + +__declspec(dllexport) +__declspec(naked) +void call_vector_41 () + { + // ; protected: virtual __thiscall CBlockChainingMode::~CBlockChainingMode(void) + _asm mov eax, 41 + _asm jmp common_dispatch + } + + +__declspec(dllexport) +__declspec(naked) +void call_vector_42 () + { + // ; public: virtual __thiscall CBufferedTransformation::~CBufferedTransformation(void) + _asm mov eax, 42 + _asm jmp common_dispatch + } + + +__declspec(dllexport) +__declspec(naked) +void call_vector_43 () + { + // ; public: virtual __thiscall CDHKeyPair::~CDHKeyPair(void) + _asm mov eax, 43 + _asm jmp common_dispatch + } + + +__declspec(dllexport) +__declspec(naked) +void call_vector_44 () + { + // ; public: virtual __thiscall CDHParameters::~CDHParameters(void) + _asm mov eax, 44 + _asm jmp common_dispatch + } + + +__declspec(dllexport) +__declspec(naked) +void call_vector_45 () + { + // ; public: virtual __thiscall CDHPrivateKey::~CDHPrivateKey(void) + _asm mov eax, 45 + _asm jmp common_dispatch + } + + +__declspec(dllexport) +__declspec(naked) +void call_vector_46 () + { + // ; public: virtual __thiscall CDHPublicKey::~CDHPublicKey(void) + _asm mov eax, 46 + _asm jmp common_dispatch + } + + +__declspec(dllexport) +__declspec(naked) +void call_vector_47 () + { + // ; public: virtual __thiscall CDSAKeyPair::~CDSAKeyPair(void) + _asm mov eax, 47 + _asm jmp common_dispatch + } + + +__declspec(dllexport) +__declspec(naked) +void call_vector_48 () + { + // ; public: virtual __thiscall CDSAParameters::~CDSAParameters(void) + _asm mov eax, 48 + _asm jmp common_dispatch + } + + +__declspec(dllexport) +__declspec(naked) +void call_vector_49 () + { + // ; public: virtual __thiscall CDSAPrimeCertificate::~CDSAPrimeCertificate(void) + _asm mov eax, 49 + _asm jmp common_dispatch + } + + +__declspec(dllexport) +__declspec(naked) +void call_vector_50 () + { + // ; public: virtual __thiscall CDSAPrivateKey::~CDSAPrivateKey(void) + _asm mov eax, 50 + _asm jmp common_dispatch + } + + +__declspec(dllexport) +__declspec(naked) +void call_vector_51 () + { + // ; public: virtual __thiscall CDSAPublicKey::~CDSAPublicKey(void) + _asm mov eax, 51 + _asm jmp common_dispatch + } + + +__declspec(dllexport) +__declspec(naked) +void call_vector_52 () + { + // ; public: virtual __thiscall CDSASignature::~CDSASignature(void) + _asm mov eax, 52 + _asm jmp common_dispatch + } + + +__declspec(dllexport) +__declspec(naked) +void call_vector_53 () + { + // ; public: virtual __thiscall CRSAKeyPair::~CRSAKeyPair(void) + _asm mov eax, 53 + _asm jmp common_dispatch + } + + +__declspec(dllexport) +__declspec(naked) +void call_vector_54 () + { + // ; public: virtual __thiscall CRSAParameters::~CRSAParameters(void) + _asm mov eax, 54 + _asm jmp common_dispatch + } + + +__declspec(dllexport) +__declspec(naked) +void call_vector_55 () + { + // ; public: virtual __thiscall CRSAPrivateKeyCRT::~CRSAPrivateKeyCRT(void) + _asm mov eax, 55 + _asm jmp common_dispatch + } + + +__declspec(dllexport) +__declspec(naked) +void call_vector_56 () + { + // ; public: virtual __thiscall CRSAPrivateKeyStandard::~CRSAPrivateKeyStandard(void) + _asm mov eax, 56 + _asm jmp common_dispatch + } + + +__declspec(dllexport) +__declspec(naked) +void call_vector_57 () + { + // ; public: virtual __thiscall CRSAPublicKey::~CRSAPublicKey(void) + _asm mov eax, 57 + _asm jmp common_dispatch + } + + +__declspec(dllexport) +__declspec(naked) +void call_vector_58 () + { + // ; public: virtual __thiscall CRSASignature::~CRSASignature(void) + _asm mov eax, 58 + _asm jmp common_dispatch + } + + +__declspec(dllexport) +__declspec(naked) +void call_vector_59 () + { + // ; public: virtual __thiscall CRijndael::~CRijndael(void) + _asm mov eax, 59 + _asm jmp common_dispatch + } + + +__declspec(dllexport) +__declspec(naked) +void call_vector_60 () + { + // ; public: int __thiscall TInteger::operator!(void)const + _asm mov eax, 60 + _asm jmp common_dispatch + } + + +__declspec(dllexport) +__declspec(naked) +void call_vector_61 () + { + // ; public: int __thiscall CDSASignature::operator==(class CDSASignature const &)const + _asm mov eax, 61 + _asm jmp common_dispatch + } + + +__declspec(dllexport) +__declspec(naked) +void call_vector_62 () + { + // ; public: int __thiscall CRSASignature::operator==(class CRSASignature const &)const + _asm mov eax, 62 + _asm jmp common_dispatch + } + + +__declspec(dllexport) +__declspec(naked) +void call_vector_63 () + { + // ; public: __thiscall RInteger::operator class TCleanupItem(void) + _asm mov eax, 63 + _asm jmp common_dispatch + } + + +__declspec(dllexport) +__declspec(naked) +void call_vector_64 () + { + // ; public: class HBufC8 const * __thiscall CDH::AgreeL(class CDHPublicKey const &)const + _asm mov eax, 64 + _asm jmp common_dispatch + } + + +__declspec(dllexport) +__declspec(naked) +void call_vector_65 () + { + // ; public: unsigned int __thiscall TInteger::BitCount(void)const + _asm mov eax, 65 + _asm jmp common_dispatch + } + + +__declspec(dllexport) +__declspec(naked) +void call_vector_66 () + { + // ; public: int __thiscall CPadding::BlockSize(void)const + _asm mov eax, 66 + _asm jmp common_dispatch + } + + +__declspec(dllexport) +__declspec(naked) +void call_vector_67 () + { + // ; public: virtual int __thiscall CStreamCipher::BlockSize(void)const + _asm mov eax, 67 + _asm jmp common_dispatch + } + + +__declspec(dllexport) +__declspec(naked) +void call_vector_68 () + { + // ; public: class CBlockTransformation * __thiscall CBufferedTransformation::BlockTransformer(void)const + _asm mov eax, 68 + _asm jmp common_dispatch + } + + +__declspec(dllexport) +__declspec(naked) +void call_vector_69 () + { + // ; public: class HBufC8 * __thiscall TInteger::BufferLC(void)const + _asm mov eax, 69 + _asm jmp common_dispatch + } + + +__declspec(dllexport) +__declspec(naked) +void call_vector_70 () + { + // ; public: unsigned int __thiscall TInteger::ByteCount(void)const + _asm mov eax, 70 + _asm jmp common_dispatch + } + + +__declspec(dllexport) +__declspec(naked) +void call_vector_71 () + { + // ; public: static void __cdecl RInteger::CallClose(void *) + _asm mov eax, 71 + _asm jmp common_dispatch + } + + +__declspec(dllexport) +__declspec(naked) +void call_vector_72 () + { + // ; public: void __thiscall RInteger::Close(void) + _asm mov eax, 72 + _asm jmp common_dispatch + } + + +__declspec(dllexport) +__declspec(naked) +void call_vector_73 () + { + // ; protected: void __thiscall CBlockChainingMode::ConstructL(class CBlockTransformation *,class TDesC8 const &) + _asm mov eax, 73 + _asm jmp common_dispatch + } + + +__declspec(dllexport) +__declspec(naked) +void call_vector_74 () + { + // ; protected: void __thiscall CDHKeyPair::ConstructL(class RInteger &,class RInteger &,class RInteger &) + _asm mov eax, 74 + _asm jmp common_dispatch + } + + +__declspec(dllexport) +__declspec(naked) +void call_vector_75 () + { + // ; protected: void __thiscall CDHKeyPair::ConstructL(class RInteger &,class RInteger &) + _asm mov eax, 75 + _asm jmp common_dispatch + } + + +__declspec(dllexport) +__declspec(naked) +void call_vector_76 () + { + // ; public: unsigned int __thiscall CDSAPrimeCertificate::Counter(void)const + _asm mov eax, 76 + _asm jmp common_dispatch + } + + +__declspec(dllexport) +__declspec(naked) +void call_vector_77 () + { + // ; public: class TInteger const & __thiscall CRSAPrivateKeyStandard::D(void)const + _asm mov eax, 77 + _asm jmp common_dispatch + } + + +__declspec(dllexport) +__declspec(naked) +void call_vector_78 () + { + // ; public: class TInteger const & __thiscall CRSAPrivateKeyCRT::DP(void)const + _asm mov eax, 78 + _asm jmp common_dispatch + } + + +__declspec(dllexport) +__declspec(naked) +void call_vector_79 () + { + // ; public: class TInteger const & __thiscall CRSAPrivateKeyCRT::DQ(void)const + _asm mov eax, 79 + _asm jmp common_dispatch + } + + +__declspec(dllexport) +__declspec(naked) +void call_vector_80 () + { + // ; public: class TInteger const & __thiscall CRSAPublicKey::E(void)const + _asm mov eax, 80 + _asm jmp common_dispatch + } + + +__declspec(dllexport) +__declspec(naked) +void call_vector_81 () + { + // ; public: class TInteger const & __thiscall CDHParameters::G(void)const + _asm mov eax, 81 + _asm jmp common_dispatch + } + + +__declspec(dllexport) +__declspec(naked) +void call_vector_82 () + { + // ; public: class TInteger const & __thiscall CDSAParameters::G(void)const + _asm mov eax, 82 + _asm jmp common_dispatch + } + + +__declspec(dllexport) +__declspec(naked) +void call_vector_83 () + { + // ; protected: __thiscall CRSASigner::CRSASigner(void) + _asm mov eax, 83 + _asm jmp common_dispatch + } + + +__declspec(dllexport) +__declspec(naked) +void call_vector_84 () + { + // ; public: virtual int __thiscall CStreamCipher::MaxFinalOutputLength(int)const + _asm mov eax, 84 + _asm jmp common_dispatch + } + + +__declspec(dllexport) +__declspec(naked) +void call_vector_85 () + { + // ; protected: __thiscall CRSAVerifier::CRSAVerifier(void) + _asm mov eax, 85 + _asm jmp common_dispatch + } + + +__declspec(dllexport) +__declspec(naked) +void call_vector_86 () + { + // ; public virtual int CRSAVerifer::VerifyL(class TDesC8 const &,class CRSASignature const &)const + _asm mov eax, 86 + _asm jmp common_dispatch + } + + +__declspec(dllexport) +__declspec(naked) +void call_vector_87 () + { + // ; public: virtual int __thiscall CStreamCipher::MaxOutputLength(int)const + _asm mov eax, 87 + _asm jmp common_dispatch + } + + +__declspec(dllexport) +__declspec(naked) +void call_vector_88 () + { + // ; public: virtual int __thiscall CPadding::MaxPaddedLength(int)const + _asm mov eax, 88 + _asm jmp common_dispatch + } + + +__declspec(dllexport) +__declspec(naked) +void call_vector_89 () + { + // ; public: virtual int __thiscall CPadding::MaxUnPaddedLength(int)const + _asm mov eax, 89 + _asm jmp common_dispatch + } + + +__declspec(dllexport) +__declspec(naked) +void call_vector_90 () + { + // ; public: static class RInteger __cdecl TInteger::ModularExponentiateL(class TInteger const &,class TInteger const &,class TInteger const &) + _asm mov eax, 90 + _asm jmp common_dispatch + } + + +__declspec(dllexport) +__declspec(naked) +void call_vector_91 () + { + // ; public: class TInteger const & __thiscall CDHParameters::N(void)const + _asm mov eax, 91 + _asm jmp common_dispatch + } + + +__declspec(dllexport) +__declspec(naked) +void call_vector_92 () + { + // ; public: class TInteger const & __thiscall CRSAParameters::N(void)const + _asm mov eax, 92 + _asm jmp common_dispatch + } + + +__declspec(dllexport) +__declspec(naked) +void call_vector_93 () + { + // ; public: static class RInteger __cdecl RInteger::NewEmptyL(unsigned int) + _asm mov eax, 93 + _asm jmp common_dispatch + } + + +__declspec(dllexport) +__declspec(naked) +void call_vector_94 () + { + // ; public: static class C3DESDecryptor * __cdecl C3DESDecryptor::NewL(class TDesC8 const &) + _asm mov eax, 94 + _asm jmp common_dispatch + } + + +__declspec(dllexport) +__declspec(naked) +void call_vector_95 () + { + // ; public: static class C3DESEncryptor * __cdecl C3DESEncryptor::NewL(class TDesC8 const &) + _asm mov eax, 95 + _asm jmp common_dispatch + } + + +__declspec(dllexport) +__declspec(naked) +void call_vector_96 () + { + // ; public: static class CAESDecryptor * __cdecl CAESDecryptor::NewL(class TDesC8 const &) + _asm mov eax, 96 + _asm jmp common_dispatch + } + + +__declspec(dllexport) +__declspec(naked) +void call_vector_97 () + { + // ; public: static class CAESEncryptor * __cdecl CAESEncryptor::NewL(class TDesC8 const &) + _asm mov eax, 97 + _asm jmp common_dispatch + } + + +__declspec(dllexport) +__declspec(naked) +void call_vector_98 () + { + // ; public: static class CARC4 * __cdecl CARC4::NewL(class TDesC8 const &,unsigned int) + _asm mov eax, 98 + _asm jmp common_dispatch + } + + +__declspec(dllexport) +__declspec(naked) +void call_vector_99 () + { + // ; public: static class CBufferedDecryptor * __cdecl CBufferedDecryptor::NewL(class CBlockTransformation *,class CPadding *) + _asm mov eax, 99 + _asm jmp common_dispatch + } + + +__declspec(dllexport) +__declspec(naked) +void call_vector_100 () + { + // ; public: static class CBufferedEncryptor * __cdecl CBufferedEncryptor::NewL(class CBlockTransformation *,class CPadding *) + _asm mov eax, 100 + _asm jmp common_dispatch + } + + +__declspec(dllexport) +__declspec(naked) +void call_vector_101 () + { + // ; public: static class CDESDecryptor * __cdecl CDESDecryptor::NewL(class TDesC8 const &,int) + _asm mov eax, 101 + _asm jmp common_dispatch + } + + +__declspec(dllexport) +__declspec(naked) +void call_vector_102 () + { + // ; public: static class CDESEncryptor * __cdecl CDESEncryptor::NewL(class TDesC8 const &,int) + _asm mov eax, 102 + _asm jmp common_dispatch + } + + +__declspec(dllexport) +__declspec(naked) +void call_vector_103 () + { + // ; public: static class CDH * __cdecl CDH::NewL(class CDHPrivateKey const &) + _asm mov eax, 103 + _asm jmp common_dispatch + } + + +__declspec(dllexport) +__declspec(naked) +void call_vector_104 () + { + // ; public: static class CDHKeyPair * __cdecl CDHKeyPair::NewL(class RInteger &,class RInteger &,class RInteger &) + _asm mov eax, 104 + _asm jmp common_dispatch + } + + +__declspec(dllexport) +__declspec(naked) +void call_vector_105 () + { + // ; public: static class CDHKeyPair * __cdecl CDHKeyPair::NewL(class RInteger &,class RInteger &) + _asm mov eax, 105 + _asm jmp common_dispatch + } + + +__declspec(dllexport) +__declspec(naked) +void call_vector_106 () + { + // ; public: static class CDHPrivateKey * __cdecl CDHPrivateKey::NewL(class RInteger &,class RInteger &,class RInteger &) + _asm mov eax, 106 + _asm jmp common_dispatch + } + + +__declspec(dllexport) +__declspec(naked) +void call_vector_107 () + { + // ; public: static class CDHPublicKey * __cdecl CDHPublicKey::NewL(class RInteger &,class RInteger &,class RInteger &) + _asm mov eax, 107 + _asm jmp common_dispatch + } + + +__declspec(dllexport) +__declspec(naked) +void call_vector_108 () + { + // ; public: static class CDSAKeyPair * __cdecl CDSAKeyPair::NewL(unsigned int) + _asm mov eax, 108 + _asm jmp common_dispatch + } + + +__declspec(dllexport) +__declspec(naked) +void call_vector_109 () + { + // ; public: static class CDSAParameters * __cdecl CDSAParameters::NewL(class RInteger &,class RInteger &,class RInteger &) + _asm mov eax, 109 + _asm jmp common_dispatch + } + + +__declspec(dllexport) +__declspec(naked) +void call_vector_110 () + { + // ; public: static class CDSAPrimeCertificate * __cdecl CDSAPrimeCertificate::NewL(class TDesC8 const &,unsigned int) + _asm mov eax, 110 + _asm jmp common_dispatch + } + + +__declspec(dllexport) +__declspec(naked) +void call_vector_111 () + { + // ; public: static class CDSAPrivateKey * __cdecl CDSAPrivateKey::NewL(class RInteger &,class RInteger &,class RInteger &,class RInteger &) + _asm mov eax, 111 + _asm jmp common_dispatch + } + + +__declspec(dllexport) +__declspec(naked) +void call_vector_112 () + { + // ; public: static class CDSAPublicKey * __cdecl CDSAPublicKey::NewL(class RInteger &,class RInteger &,class RInteger &,class RInteger &) + _asm mov eax, 112 + _asm jmp common_dispatch + } + + +__declspec(dllexport) +__declspec(naked) +void call_vector_113 () + { + // ; public: static class CDSASignature * __cdecl CDSASignature::NewL(class RInteger &,class RInteger &) + _asm mov eax, 113 + _asm jmp common_dispatch + } + + +__declspec(dllexport) +__declspec(naked) +void call_vector_114 () + { + // ; public: static class CDSASigner * __cdecl CDSASigner::NewL(class CDSAPrivateKey const &) + _asm mov eax, 114 + _asm jmp common_dispatch + } + + +__declspec(dllexport) +__declspec(naked) +void call_vector_115 () + { + // ; public: static class CDSAVerifier * __cdecl CDSAVerifier::NewL(class CDSAPublicKey const &) + _asm mov eax, 115 + _asm jmp common_dispatch + } + + +__declspec(dllexport) +__declspec(naked) +void call_vector_116 () + { + // ; public: static class CModeCBCDecryptor * __cdecl CModeCBCDecryptor::NewL(class CBlockTransformation *,class TDesC8 const &) + _asm mov eax, 116 + _asm jmp common_dispatch + } + + +__declspec(dllexport) +__declspec(naked) +void call_vector_117 () + { + // ; public: static class CModeCBCEncryptor * __cdecl CModeCBCEncryptor::NewL(class CBlockTransformation *,class TDesC8 const &) + _asm mov eax, 117 + _asm jmp common_dispatch + } + + +__declspec(dllexport) +__declspec(naked) +void call_vector_118 () + { + // ; public: static class CNullCipher * __cdecl CNullCipher::NewL(void) + _asm mov eax, 118 + _asm jmp common_dispatch + } + + +__declspec(dllexport) +__declspec(naked) +void call_vector_119 () + { + // ; public: static class CPaddingNone * __cdecl CPaddingNone::NewL(int) + _asm mov eax, 119 + _asm jmp common_dispatch + } + + +__declspec(dllexport) +__declspec(naked) +void call_vector_120 () + { + // ; public: static class CPaddingPKCS1Encryption * __cdecl CPaddingPKCS1Encryption::NewL(int) + _asm mov eax, 120 + _asm jmp common_dispatch + } + + +__declspec(dllexport) +__declspec(naked) +void call_vector_121 () + { + // ; public: static class CPaddingPKCS1Signature * __cdecl CPaddingPKCS1Signature::NewL(int) + _asm mov eax, 121 + _asm jmp common_dispatch + } + + +__declspec(dllexport) +__declspec(naked) +void call_vector_122 () + { + // ; public: static class CPaddingSSLv3 * __cdecl CPaddingSSLv3::NewL(int) + _asm mov eax, 122 + _asm jmp common_dispatch + } + + +__declspec(dllexport) +__declspec(naked) +void call_vector_123 () + { + // ; public: static class CRC2Decryptor * __cdecl CRC2Decryptor::NewL(class TDesC8 const &,int) + _asm mov eax, 123 + _asm jmp common_dispatch + } + + +__declspec(dllexport) +__declspec(naked) +void call_vector_124 () + { + // ; public: static class CRC2Encryptor * __cdecl CRC2Encryptor::NewL(class TDesC8 const &,int) + _asm mov eax, 124 + _asm jmp common_dispatch + } + + +__declspec(dllexport) +__declspec(naked) +void call_vector_125 () + { + // ; public: static class CRSAKeyPair * __cdecl CRSAKeyPair::NewL(unsigned int,enum TRSAPrivateKeyType) + _asm mov eax, 125 + _asm jmp common_dispatch + } + + +__declspec(dllexport) +__declspec(naked) +void call_vector_126 () + { + // ; public: static class CRSAPKCS1v15Decryptor * __cdecl CRSAPKCS1v15Decryptor::NewL(class CRSAPrivateKey const &) + _asm mov eax, 126 + _asm jmp common_dispatch + } + + +__declspec(dllexport) +__declspec(naked) +void call_vector_127 () + { + // ; public: static class CRSAPKCS1v15Encryptor * __cdecl CRSAPKCS1v15Encryptor::NewL(class CRSAPublicKey const &) + _asm mov eax, 127 + _asm jmp common_dispatch + } + + +__declspec(dllexport) +__declspec(naked) +void call_vector_128 () + { + // ; public: static class CRSAPKCS1v15Signer * __cdecl CRSAPKCS1v15Signer::NewL(class CRSAPrivateKey const &) + _asm mov eax, 128 + _asm jmp common_dispatch + } + + +__declspec(dllexport) +__declspec(naked) +void call_vector_129 () + { + // ; public: static class CRSAPKCS1v15Verifier * __cdecl CRSAPKCS1v15Verifier::NewL(class CRSAPublicKey const &) + _asm mov eax, 129 + _asm jmp common_dispatch + } + + +__declspec(dllexport) +__declspec(naked) +void call_vector_130 () + { + // ; public: static class CRSAPrivateKeyCRT * __cdecl CRSAPrivateKeyCRT::NewL(class RInteger &,class RInteger &,class RInteger &,class RInteger &,class RInteger &,class RInteger &) + _asm mov eax, 130 + _asm jmp common_dispatch + } + + +__declspec(dllexport) +__declspec(naked) +void call_vector_131 () + { + // ; public: static class CRSAPrivateKeyStandard * __cdecl CRSAPrivateKeyStandard::NewL(class RInteger &,class RInteger &) + _asm mov eax, 131 + _asm jmp common_dispatch + } + + +__declspec(dllexport) +__declspec(naked) +void call_vector_132 () + { + // ; public: static class CRSAPublicKey * __cdecl CRSAPublicKey::NewL(class RInteger &,class RInteger &) + _asm mov eax, 132 + _asm jmp common_dispatch + } + + +__declspec(dllexport) +__declspec(naked) +void call_vector_133 () + { + // ; public: static class CRSASignature * __cdecl CRSASignature::NewL(class RInteger &) + _asm mov eax, 133 + _asm jmp common_dispatch + } + + +__declspec(dllexport) +__declspec(naked) +void call_vector_134 () + { + // ; public: static class RInteger __cdecl RInteger::NewL(class TDesC8 const &) + _asm mov eax, 134 + _asm jmp common_dispatch + } + + +__declspec(dllexport) +__declspec(naked) +void call_vector_135 () + { + // ; public: static class RInteger __cdecl RInteger::NewL(class TInteger const &) + _asm mov eax, 135 + _asm jmp common_dispatch + } + + +__declspec(dllexport) +__declspec(naked) +void call_vector_136 () + { + // ; public: static class RInteger __cdecl RInteger::NewL(int) + _asm mov eax, 136 + _asm jmp common_dispatch + } + + +__declspec(dllexport) +__declspec(naked) +void call_vector_137 () + { + // ; public: static class RInteger __cdecl RInteger::NewL(unsigned int) + _asm mov eax, 137 + _asm jmp common_dispatch + } + + +__declspec(dllexport) +__declspec(naked) +void call_vector_138 () + { + // ; public: static class RInteger __cdecl RInteger::NewL(void) + _asm mov eax, 138 + _asm jmp common_dispatch + } + + +__declspec(dllexport) +__declspec(naked) +void call_vector_139 () + { + // ; public: static class C3DESDecryptor * __cdecl C3DESDecryptor::NewLC(class TDesC8 const &) + _asm mov eax, 139 + _asm jmp common_dispatch + } + + +__declspec(dllexport) +__declspec(naked) +void call_vector_140 () + { + // ; public: static class C3DESEncryptor * __cdecl C3DESEncryptor::NewLC(class TDesC8 const &) + _asm mov eax, 140 + _asm jmp common_dispatch + } + + +__declspec(dllexport) +__declspec(naked) +void call_vector_141 () + { + // ; public: static class CAESDecryptor * __cdecl CAESDecryptor::NewLC(class TDesC8 const &) + _asm mov eax, 141 + _asm jmp common_dispatch + } + + +__declspec(dllexport) +__declspec(naked) +void call_vector_142 () + { + // ; public: static class CAESEncryptor * __cdecl CAESEncryptor::NewLC(class TDesC8 const &) + _asm mov eax, 142 + _asm jmp common_dispatch + } + + +__declspec(dllexport) +__declspec(naked) +void call_vector_143 () + { + // ; public: static class CARC4 * __cdecl CARC4::NewLC(class TDesC8 const &,unsigned int) + _asm mov eax, 143 + _asm jmp common_dispatch + } + + +__declspec(dllexport) +__declspec(naked) +void call_vector_144 () + { + // ; public: static class CBufferedDecryptor * __cdecl CBufferedDecryptor::NewLC(class CBlockTransformation *,class CPadding *) + _asm mov eax, 144 + _asm jmp common_dispatch + } + + +__declspec(dllexport) +__declspec(naked) +void call_vector_145 () + { + // ; public: static class CBufferedEncryptor * __cdecl CBufferedEncryptor::NewLC(class CBlockTransformation *,class CPadding *) + _asm mov eax, 145 + _asm jmp common_dispatch + } + + +__declspec(dllexport) +__declspec(naked) +void call_vector_146 () + { + // ; public: static class CDESDecryptor * __cdecl CDESDecryptor::NewLC(class TDesC8 const &,int) + _asm mov eax, 146 + _asm jmp common_dispatch + } + + +__declspec(dllexport) +__declspec(naked) +void call_vector_147 () + { + // ; public: static class CDESEncryptor * __cdecl CDESEncryptor::NewLC(class TDesC8 const &,int) + _asm mov eax, 147 + _asm jmp common_dispatch + } + + +__declspec(dllexport) +__declspec(naked) +void call_vector_148 () + { + // ; public: static class CDH * __cdecl CDH::NewLC(class CDHPrivateKey const &) + _asm mov eax, 148 + _asm jmp common_dispatch + } + + +__declspec(dllexport) +__declspec(naked) +void call_vector_149 () + { + // ; public: static class CDHKeyPair * __cdecl CDHKeyPair::NewLC(class RInteger &,class RInteger &,class RInteger &) + _asm mov eax, 149 + _asm jmp common_dispatch + } + + +__declspec(dllexport) +__declspec(naked) +void call_vector_150 () + { + // ; public: static class CDHKeyPair * __cdecl CDHKeyPair::NewLC(class RInteger &,class RInteger &) + _asm mov eax, 150 + _asm jmp common_dispatch + } + + +__declspec(dllexport) +__declspec(naked) +void call_vector_151 () + { + // ; public: static class CDHPrivateKey * __cdecl CDHPrivateKey::NewLC(class RInteger &,class RInteger &,class RInteger &) + _asm mov eax, 151 + _asm jmp common_dispatch + } + + +__declspec(dllexport) +__declspec(naked) +void call_vector_152 () + { + // ; public: static class CDHPublicKey * __cdecl CDHPublicKey::NewLC(class RInteger &,class RInteger &,class RInteger &) + _asm mov eax, 152 + _asm jmp common_dispatch + } + + +__declspec(dllexport) +__declspec(naked) +void call_vector_153 () + { + // ; public: static class CDSAKeyPair * __cdecl CDSAKeyPair::NewLC(unsigned int) + _asm mov eax, 153 + _asm jmp common_dispatch + } + + +__declspec(dllexport) +__declspec(naked) +void call_vector_154 () + { + // ; public: static class CDSAPrimeCertificate * __cdecl CDSAPrimeCertificate::NewLC(class TDesC8 const &,unsigned int) + _asm mov eax, 154 + _asm jmp common_dispatch + } + + +__declspec(dllexport) +__declspec(naked) +void call_vector_155 () + { + // ; public: static class CDSAPrivateKey * __cdecl CDSAPrivateKey::NewLC(class RInteger &,class RInteger &,class RInteger &,class RInteger &) + _asm mov eax, 155 + _asm jmp common_dispatch + } + + +__declspec(dllexport) +__declspec(naked) +void call_vector_156 () + { + // ; public: static class CDSAPublicKey * __cdecl CDSAPublicKey::NewLC(class RInteger &,class RInteger &,class RInteger &,class RInteger &) + _asm mov eax, 156 + _asm jmp common_dispatch + } + + +__declspec(dllexport) +__declspec(naked) +void call_vector_157 () + { + // ; public: static class CDSASignature * __cdecl CDSASignature::NewLC(class RInteger &,class RInteger &) + _asm mov eax, 157 + _asm jmp common_dispatch + } + + +__declspec(dllexport) +__declspec(naked) +void call_vector_158 () + { + // ; public: static class CDSASigner * __cdecl CDSASigner::NewLC(class CDSAPrivateKey const &) + _asm mov eax, 158 + _asm jmp common_dispatch + } + + +__declspec(dllexport) +__declspec(naked) +void call_vector_159 () + { + // ; public: static class CDSAVerifier * __cdecl CDSAVerifier::NewLC(class CDSAPublicKey const &) + _asm mov eax, 159 + _asm jmp common_dispatch + } + + +__declspec(dllexport) +__declspec(naked) +void call_vector_160 () + { + // ; public: static class CModeCBCDecryptor * __cdecl CModeCBCDecryptor::NewLC(class CBlockTransformation *,class TDesC8 const &) + _asm mov eax, 160 + _asm jmp common_dispatch + } + + +__declspec(dllexport) +__declspec(naked) +void call_vector_161 () + { + // ; public: static class CModeCBCEncryptor * __cdecl CModeCBCEncryptor::NewLC(class CBlockTransformation *,class TDesC8 const &) + _asm mov eax, 161 + _asm jmp common_dispatch + } + + +__declspec(dllexport) +__declspec(naked) +void call_vector_162 () + { + // ; public: static class CNullCipher * __cdecl CNullCipher::NewLC(void) + _asm mov eax, 162 + _asm jmp common_dispatch + } + + +__declspec(dllexport) +__declspec(naked) +void call_vector_163 () + { + // ; public: static class CPaddingNone * __cdecl CPaddingNone::NewLC(int) + _asm mov eax, 163 + _asm jmp common_dispatch + } + + +__declspec(dllexport) +__declspec(naked) +void call_vector_164 () + { + // ; public: static class CPaddingPKCS1Encryption * __cdecl CPaddingPKCS1Encryption::NewLC(int) + _asm mov eax, 164 + _asm jmp common_dispatch + } + + +__declspec(dllexport) +__declspec(naked) +void call_vector_165 () + { + // ; public: static class CPaddingPKCS1Signature * __cdecl CPaddingPKCS1Signature::NewLC(int) + _asm mov eax, 165 + _asm jmp common_dispatch + } + + +__declspec(dllexport) +__declspec(naked) +void call_vector_166 () + { + // ; public: static class CPaddingSSLv3 * __cdecl CPaddingSSLv3::NewLC(int) + _asm mov eax, 166 + _asm jmp common_dispatch + } + + +__declspec(dllexport) +__declspec(naked) +void call_vector_167 () + { + // ; public: static class CRC2Decryptor * __cdecl CRC2Decryptor::NewLC(class TDesC8 const &,int) + _asm mov eax, 167 + _asm jmp common_dispatch + } + + +__declspec(dllexport) +__declspec(naked) +void call_vector_168 () + { + // ; public: static class CRC2Encryptor * __cdecl CRC2Encryptor::NewLC(class TDesC8 const &,int) + _asm mov eax, 168 + _asm jmp common_dispatch + } + + +__declspec(dllexport) +__declspec(naked) +void call_vector_169 () + { + // ; public: static class CRSAKeyPair * __cdecl CRSAKeyPair::NewLC(unsigned int,enum TRSAPrivateKeyType) + _asm mov eax, 169 + _asm jmp common_dispatch + } + + +__declspec(dllexport) +__declspec(naked) +void call_vector_170 () + { + // ; public: static class CRSAPKCS1v15Decryptor * __cdecl CRSAPKCS1v15Decryptor::NewLC(class CRSAPrivateKey const &) + _asm mov eax, 170 + _asm jmp common_dispatch + } + + +__declspec(dllexport) +__declspec(naked) +void call_vector_171 () + { + // ; public: static class CRSAPKCS1v15Encryptor * __cdecl CRSAPKCS1v15Encryptor::NewLC(class CRSAPublicKey const &) + _asm mov eax, 171 + _asm jmp common_dispatch + } + + +__declspec(dllexport) +__declspec(naked) +void call_vector_172 () + { + // ; public: static class CRSAPKCS1v15Signer * __cdecl CRSAPKCS1v15Signer::NewLC(class CRSAPrivateKey const &) + _asm mov eax, 172 + _asm jmp common_dispatch + } + + +__declspec(dllexport) +__declspec(naked) +void call_vector_173 () + { + // ; public: static class CRSAPKCS1v15Verifier * __cdecl CRSAPKCS1v15Verifier::NewLC(class CRSAPublicKey const &) + _asm mov eax, 173 + _asm jmp common_dispatch + } + + +__declspec(dllexport) +__declspec(naked) +void call_vector_174 () + { + // ; public: static class CRSAPrivateKeyCRT * __cdecl CRSAPrivateKeyCRT::NewLC(class RInteger &,class RInteger &,class RInteger &,class RInteger &,class RInteger &,class RInteger &) + _asm mov eax, 174 + _asm jmp common_dispatch + } + + +__declspec(dllexport) +__declspec(naked) +void call_vector_175 () + { + // ; public: static class CRSAPrivateKeyStandard * __cdecl CRSAPrivateKeyStandard::NewLC(class RInteger &,class RInteger &) + _asm mov eax, 175 + _asm jmp common_dispatch + } + + +__declspec(dllexport) +__declspec(naked) +void call_vector_176 () + { + // ; public: static class CRSAPublicKey * __cdecl CRSAPublicKey::NewLC(class RInteger &,class RInteger &) + _asm mov eax, 176 + _asm jmp common_dispatch + } + + +__declspec(dllexport) +__declspec(naked) +void call_vector_177 () + { + // ; public: static class CRSASignature * __cdecl CRSASignature::NewLC(class RInteger &) + _asm mov eax, 177 + _asm jmp common_dispatch + } + + +__declspec(dllexport) +__declspec(naked) +void call_vector_178 () + { + // ; public: static class RInteger __cdecl RInteger::NewPrimeL(unsigned int,int) + _asm mov eax, 178 + _asm jmp common_dispatch + } + + +__declspec(dllexport) +__declspec(naked) +void call_vector_179 () + { + // ; public: static class RInteger __cdecl RInteger::NewRandomL(class TInteger const &,class TInteger const &) + _asm mov eax, 179 + _asm jmp common_dispatch + } + + +__declspec(dllexport) +__declspec(naked) +void call_vector_180 () + { + // ; public: static class RInteger __cdecl RInteger::NewRandomL(unsigned int,int) + _asm mov eax, 180 + _asm jmp common_dispatch + } + + +__declspec(dllexport) +__declspec(naked) +void call_vector_181 () + { + // ; public: class TInteger const & __thiscall CDSAParameters::P(void)const + _asm mov eax, 181 + _asm jmp common_dispatch + } + + +__declspec(dllexport) +__declspec(naked) +void call_vector_182 () + { + // ; public: class TInteger const & __thiscall CRSAPrivateKeyCRT::P(void)const + _asm mov eax, 182 + _asm jmp common_dispatch + } + + +__declspec(dllexport) +__declspec(naked) +void call_vector_183 () + { + // ; public: void __thiscall CPadding::PadL(class TDesC8 const &,class TDes8 &) + _asm mov eax, 183 + _asm jmp common_dispatch + } + + +__declspec(dllexport) +__declspec(naked) +void call_vector_184 () + { + // ; public: class CDSAPrimeCertificate const & __thiscall CDSAKeyPair::PrimeCertificate(void)const + _asm mov eax, 184 + _asm jmp common_dispatch + } + + +__declspec(dllexport) +__declspec(naked) +void call_vector_185 () + { + // ; public: class CDHPrivateKey const & __thiscall CDHKeyPair::PrivateKey(void)const + _asm mov eax, 185 + _asm jmp common_dispatch + } + + +__declspec(dllexport) +__declspec(naked) +void call_vector_186 () + { + // ; public: class CDSAPrivateKey const & __thiscall CDSAKeyPair::PrivateKey(void)const + _asm mov eax, 186 + _asm jmp common_dispatch + } + + +__declspec(dllexport) +__declspec(naked) +void call_vector_187 () + { + // ; public: class CRSAPrivateKey const & __thiscall CRSAKeyPair::PrivateKey(void)const + _asm mov eax, 187 + _asm jmp common_dispatch + } + + +__declspec(dllexport) +__declspec(naked) +void call_vector_188 () + { + // ; public: virtual void __thiscall CStreamCipher::Process(class TDesC8 const &,class TDes8 &) + _asm mov eax, 188 + _asm jmp common_dispatch + } + + +__declspec(dllexport) +__declspec(naked) +void call_vector_189 () + { + // ; public: virtual void __thiscall CStreamCipher::ProcessFinalL(class TDesC8 const &,class TDes8 &) + _asm mov eax, 189 + _asm jmp common_dispatch + } + + +__declspec(dllexport) +__declspec(naked) +void call_vector_190 () + { + // ; public: class CDHPublicKey const & __thiscall CDHKeyPair::PublicKey(void)const + _asm mov eax, 190 + _asm jmp common_dispatch + } + + +__declspec(dllexport) +__declspec(naked) +void call_vector_191 () + { + // ; public: class CDSAPublicKey const & __thiscall CDSAKeyPair::PublicKey(void)const + _asm mov eax, 191 + _asm jmp common_dispatch + } + + +__declspec(dllexport) +__declspec(naked) +void call_vector_192 () + { + // ; public: class CRSAPublicKey const & __thiscall CRSAKeyPair::PublicKey(void)const + _asm mov eax, 192 + _asm jmp common_dispatch + } + + +__declspec(dllexport) +__declspec(naked) +void call_vector_193 () + { + // ; public: class TInteger const & __thiscall CDSAParameters::Q(void)const + _asm mov eax, 193 + _asm jmp common_dispatch + } + + +__declspec(dllexport) +__declspec(naked) +void call_vector_194 () + { + // ; public: class TInteger const & __thiscall CRSAPrivateKeyCRT::Q(void)const + _asm mov eax, 194 + _asm jmp common_dispatch + } + + +__declspec(dllexport) +__declspec(naked) +void call_vector_195 () + { + // ; public: class TInteger const & __thiscall CRSAPrivateKeyCRT::QInv(void)const + _asm mov eax, 195 + _asm jmp common_dispatch + } + + +__declspec(dllexport) +__declspec(naked) +void call_vector_196 () + { + // ; public: class TInteger const & __thiscall CDSASignature::R(void)const + _asm mov eax, 196 + _asm jmp common_dispatch + } + + +__declspec(dllexport) +__declspec(naked) +void call_vector_197 () + { + // ; public: class TInteger const & __thiscall CDSASignature::S(void)const + _asm mov eax, 197 + _asm jmp common_dispatch + } + + +__declspec(dllexport) +__declspec(naked) +void call_vector_198 () + { + // ; public: class TInteger const & __thiscall CRSASignature::S(void)const + _asm mov eax, 198 + _asm jmp common_dispatch + } + + +__declspec(dllexport) +__declspec(naked) +void call_vector_199 () + { + // ; public: class TDesC8 const & __thiscall CDSAPrimeCertificate::Seed(void)const + _asm mov eax, 199 + _asm jmp common_dispatch + } + + +__declspec(dllexport) +__declspec(naked) +void call_vector_200 () + { + // ; public: void __thiscall CPadding::SetBlockSize(int) + _asm mov eax, 200 + _asm jmp common_dispatch + } + + +__declspec(dllexport) +__declspec(naked) +void call_vector_201 () + { + // ; public: static enum TCrypto::TStrength __cdecl TCrypto::Strength(void) + _asm mov eax, 201 + _asm jmp common_dispatch + } + + +__declspec(dllexport) +__declspec(naked) +void call_vector_202 () + { + // ; public: static int __cdecl CDSAParameters::ValidPrimeLength(unsigned int) + _asm mov eax, 202 + _asm jmp common_dispatch + } + + +__declspec(dllexport) +__declspec(naked) +void call_vector_203 () + { + // ; public: int __thiscall CDSAParameters::ValidatePrimesL(class CDSAPrimeCertificate const &)const + _asm mov eax, 203 + _asm jmp common_dispatch + } + + +__declspec(dllexport) +__declspec(naked) +void call_vector_204 () + { + // ; public: unsigned int __thiscall TInteger::WordCount(void)const + _asm mov eax, 204 + _asm jmp common_dispatch + } + + +__declspec(dllexport) +__declspec(naked) +void call_vector_205 () + { + // ; public: class TInteger const & __thiscall CDHPublicKey::X(void)const + _asm mov eax, 205 + _asm jmp common_dispatch + } + + +__declspec(dllexport) +__declspec(naked) +void call_vector_206 () + { + // ; public: class TInteger const & __thiscall CDSAPrivateKey::X(void)const + _asm mov eax, 206 + _asm jmp common_dispatch + } + + +__declspec(dllexport) +__declspec(naked) +void call_vector_207 () + { + // ; public: class TInteger const & __thiscall CDSAPublicKey::Y(void)const + _asm mov eax, 207 + _asm jmp common_dispatch + } + + +__declspec(dllexport) +__declspec(naked) +void call_vector_208 () + { + // ; public: class TInteger const & __thiscall CDHPrivateKey::x(void)const + _asm mov eax, 208 + _asm jmp common_dispatch + } + + +__declspec(dllexport) +__declspec(naked) +void call_vector_209 () + { + // ; public: static int __cdecl TCrypto::IsAsymmetricWeakEnoughL(int) + _asm mov eax, 209 + _asm jmp common_dispatch + } + + +__declspec(dllexport) +__declspec(naked) +void call_vector_210 () + { + // ; public: static int __cdecl TCrypto::IsSymmetricWeakEnoughL(int) + _asm mov eax, 210 + _asm jmp common_dispatch + } + + +__declspec(dllexport) +__declspec(naked) +void call_vector_211 () + { + // ; CPaddingPKCS7::CPaddingPKCS7(int) + _asm mov eax, 211 + _asm jmp common_dispatch + } + + +__declspec(dllexport) +__declspec(naked) +void call_vector_212 () + { + // ; class CPaddingPKCS7 * CPaddingPKCS7::NewL(int) + _asm mov eax, 212 + _asm jmp common_dispatch + } + + +__declspec(dllexport) +__declspec(naked) +void call_vector_213 () + { + // ; class CPaddingPKCS7 * CPaddingPKCS7::NewLC(int) + _asm mov eax, 213 + _asm jmp common_dispatch + } + + +__declspec(dllexport) +__declspec(naked) +void call_vector_214 () + { + // ; void KeyIdentifierUtil::DHKeyIdentifierL(class RInteger const &, class TBuf8<20> &) + _asm mov eax, 214 + _asm jmp common_dispatch + } + + +__declspec(dllexport) +__declspec(naked) +void call_vector_215 () + { + // ; void KeyIdentifierUtil::DSAKeyIdentifierL(class CDSAPublicKey const &, class TBuf8<20> &) + _asm mov eax, 215 + _asm jmp common_dispatch + } + + +__declspec(dllexport) +__declspec(naked) +void call_vector_216 () + { + // ; void KeyIdentifierUtil::RSAKeyIdentifierL(class CRSAPublicKey const &, class TBuf8<20> &) + _asm mov eax, 216 + _asm jmp common_dispatch + } + + +__declspec(dllexport) +__declspec(naked) +void call_vector_217 () + { + // ; class TInteger & TInteger::operator++(void) + _asm mov eax, 217 + _asm jmp common_dispatch + } + + +__declspec(dllexport) +__declspec(naked) +void call_vector_218 () + { + // ; class TInteger & TInteger::operator--(void) + _asm mov eax, 218 + _asm jmp common_dispatch + } + + +__declspec(dllexport) +__declspec(naked) +void call_vector_219 () + { + // ; class RInteger TInteger::InverseModL(class TInteger const &) const + _asm mov eax, 219 + _asm jmp common_dispatch + } + + +__declspec(dllexport) +__declspec(naked) +void call_vector_220 () + { + // ; class RInteger TInteger::TimesL(class TInteger const &) const + _asm mov eax, 220 + _asm jmp common_dispatch + } + + +__declspec(dllexport) +__declspec(naked) +void call_vector_221 () + { + // ; public: __thiscall RInteger::RInteger(class RInteger const &) + _asm mov eax, 221 + _asm jmp common_dispatch + } + + +__declspec(dllexport) +__declspec(naked) +void call_vector_222 () + { + // ; public: class RInteger & __thiscall RInteger::operator=(class RInteger const &) + _asm mov eax, 222 + _asm jmp common_dispatch + } + +__declspec(dllexport) +__declspec(naked) +void call_vector_223 () + { + // ; public: class TInteger & __thiscall TInteger::operator*=(class TInteger const &) + _asm mov eax, 223 + _asm jmp common_dispatch + } + +__declspec(dllexport) +__declspec(naked) +void call_vector_224 () + { + // ; public: class TInteger & __thiscall TInteger::operator*=(int) + _asm mov eax, 224 + _asm jmp common_dispatch + } + +__declspec(dllexport) +__declspec(naked) +void call_vector_225 () + { + // ; public: class TInteger & __thiscall TInteger::operator+=(class TInteger const &) + _asm mov eax, 225 + _asm jmp common_dispatch + } + +__declspec(dllexport) +__declspec(naked) +void call_vector_226 () + { + // ; public: class TInteger & __thiscall TInteger::operator+=(int) + _asm mov eax, 226 + _asm jmp common_dispatch + } + +__declspec(dllexport) +__declspec(naked) +void call_vector_227 () + { + // ; public: class TInteger & __thiscall TInteger::operator-=(class TInteger const &) + _asm mov eax, 227 + _asm jmp common_dispatch + } + +__declspec(dllexport) +__declspec(naked) +void call_vector_228 () + { + // ; public: class TInteger & __thiscall TInteger::operator-=(int) + _asm mov eax, 228 + _asm jmp common_dispatch + } + +__declspec(dllexport) +__declspec(naked) +void call_vector_229 () + { + // ; public: class TInteger & __thiscall TInteger::operator/=(class TInteger const &) + _asm mov eax, 229 + _asm jmp common_dispatch + } + +__declspec(dllexport) +__declspec(naked) +void call_vector_230 () + { + // ; public: class TInteger & __thiscall TInteger::operator/=(int) + _asm mov eax, 230 + _asm jmp common_dispatch + } + +__declspec(dllexport) +__declspec(naked) +void call_vector_231 () + { + // ; public: class TInteger & __thiscall TInteger::operator%=(class TInteger const &) + _asm mov eax, 231 + _asm jmp common_dispatch + } + +__declspec(dllexport) +__declspec(naked) +void call_vector_232 () + { + // ; public: class TInteger & __thiscall TInteger::operator%=(int) + _asm mov eax, 232 + _asm jmp common_dispatch + } + +__declspec(dllexport) +__declspec(naked) +void call_vector_233 () + { + // ; public: class TInteger & __thiscall TInteger::operator>>=(unsigned int) + _asm mov eax, 233 + _asm jmp common_dispatch + } + +__declspec(dllexport) +__declspec(naked) +void call_vector_234 () + { + // ; public: class TInteger & __thiscall TInteger::operator<<=(unsigned int) + _asm mov eax, 234 + _asm jmp common_dispatch + } + +__declspec(dllexport) +__declspec(naked) +void call_vector_235 () + { + // ; public: int __thiscall TInteger::Bit(unsigned int)const + _asm mov eax, 235 + _asm jmp common_dispatch + } + +__declspec(dllexport) +__declspec(naked) +void call_vector_236 () + { + // ; public: int __thiscall TInteger::ConvertToLongL(void)const + _asm mov eax, 236 + _asm jmp common_dispatch + } + +__declspec(dllexport) +__declspec(naked) +void call_vector_237 () + { + // ; public: class RInteger __thiscall TInteger::DividedByL(class TInteger const &)const + _asm mov eax, 237 + _asm jmp common_dispatch + } + +__declspec(dllexport) +__declspec(naked) +void call_vector_238 () + { + // ; public: class RInteger __thiscall TInteger::DividedByL(unsigned int)const + _asm mov eax, 238 + _asm jmp common_dispatch + } + +__declspec(dllexport) +__declspec(naked) +void call_vector_239 () + { + // ; public: class RInteger __thiscall TInteger::ExponentiateL(class TInteger const &)const + _asm mov eax, 239 + _asm jmp common_dispatch + } + +__declspec(dllexport) +__declspec(naked) +void call_vector_240 () + { + // ; public: class RInteger __thiscall TInteger::GCDL(class TInteger const &)const + _asm mov eax, 240 + _asm jmp common_dispatch + } + +__declspec(dllexport) +__declspec(naked) +void call_vector_241 () + { + // ; public: int __thiscall TInteger::IsPrimeL(void)const + _asm mov eax, 241 + _asm jmp common_dispatch + } + +__declspec(dllexport) +__declspec(naked) +void call_vector_242 () + { + // ; public: class RInteger __thiscall TInteger::MinusL(class TInteger const &)const + _asm mov eax, 242 + _asm jmp common_dispatch + } + +__declspec(dllexport) +__declspec(naked) +void call_vector_243 () + { + // ; public: static class RInteger __cdecl TInteger::ModularMultiplyL(class TInteger const &,class TInteger const &,class TInteger const &) + _asm mov eax, 243 + _asm jmp common_dispatch + } + +__declspec(dllexport) +__declspec(naked) +void call_vector_244 () + { + // ; public: class RInteger __thiscall TInteger::ModuloL(class TInteger const &)const + _asm mov eax, 244 + _asm jmp common_dispatch + } + +__declspec(dllexport) +__declspec(naked) +void call_vector_245 () + { + // ; public: unsigned int __thiscall TInteger::ModuloL(unsigned int)const + _asm mov eax, 245 + _asm jmp common_dispatch + } + +__declspec(dllexport) +__declspec(naked) +void call_vector_246 () + { + // ; public: void __thiscall TInteger::Negate(void) + _asm mov eax, 246 + _asm jmp common_dispatch + } + +__declspec(dllexport) +__declspec(naked) +void call_vector_247 () + { + // ; public: static class TInteger const & __cdecl TInteger::One(void) + _asm mov eax, 247 + _asm jmp common_dispatch + } + +__declspec(dllexport) +__declspec(naked) +void call_vector_248 () + { + // ; public: class RInteger __thiscall TInteger::PlusL(class TInteger const &)const + _asm mov eax, 248 + _asm jmp common_dispatch + } + +__declspec(dllexport) +__declspec(naked) +void call_vector_249 () + { + // ; public: void __thiscall TInteger::SetBit(unsigned int) + _asm mov eax, 249 + _asm jmp common_dispatch + } + +__declspec(dllexport) +__declspec(naked) +void call_vector_250 () + { + // ; public: int __thiscall TInteger::SignedCompare(class TInteger const &)const + _asm mov eax, 250 + _asm jmp common_dispatch + } + +__declspec(dllexport) +__declspec(naked) +void call_vector_251 () + { + // ; public: int __thiscall TInteger::SignedCompare(int)const + _asm mov eax, 251 + _asm jmp common_dispatch + } + +__declspec(dllexport) +__declspec(naked) +void call_vector_252 () + { + // ; public: class RInteger __thiscall TInteger::SquaredL(void)const + _asm mov eax, 252 + _asm jmp common_dispatch + } + +__declspec(dllexport) +__declspec(naked) +void call_vector_253 () + { + // ; public: static class TInteger const & __cdecl TInteger::Two(void) + _asm mov eax, 253 + _asm jmp common_dispatch + } + +__declspec(dllexport) +__declspec(naked) +void call_vector_254 () + { + // ; public: int __thiscall TInteger::UnsignedCompare(class TInteger const &)const + _asm mov eax, 254 + _asm jmp common_dispatch + } + +__declspec(dllexport) +__declspec(naked) +void call_vector_255 () + { + // ; public: static class TInteger const & __cdecl TInteger::Zero(void) + _asm mov eax, 255 + _asm jmp common_dispatch + } + +__declspec(dllexport) +__declspec(naked) +void call_vector_256 () + { + // ; public: void __thiscall TInteger::CopyL(class TInteger const &,int) + _asm mov eax, 256 + _asm jmp common_dispatch + } + +__declspec(dllexport) +__declspec(naked) +void call_vector_257 () + { + // ; public: void __thiscall TInteger::CopyL(int,int) + _asm mov eax, 257 + _asm jmp common_dispatch + } + +__declspec(dllexport) +__declspec(naked) +void call_vector_258 () + { + // ; public: void __thiscall TInteger::Set(class RInteger const &) + _asm mov eax, 258 + _asm jmp common_dispatch + } + +__declspec(dllexport) +__declspec(naked) +void call_vector_259 () + { + // ; public: TBool __thiscall CDES::IsWeakKey(const TDesC8& aKey) + _asm mov eax, 259 + _asm jmp common_dispatch + } + +__declspec(dllexport) +__declspec(naked) +void call_vector_260 () + { + // ; public: class HBufC8 * __thiscall TInteger::BufferWithNoTruncationLC(void)const + _asm mov eax, 260 + _asm jmp common_dispatch + } + + +__declspec(dllexport) +__declspec(naked) +void call_vector_261 () + { + // ; public: void __thiscall CMontgomeryStructure::NewLC(const TInteger&) + _asm mov eax, 261 + _asm jmp common_dispatch + } + +__declspec(dllexport) +__declspec(naked) +void call_vector_262 () + { + // ; public: void __thiscall CMontgomeryStructure::ExponentiateL(const TInteger&, const TInteger&) const + // + _asm mov eax, 262 + _asm jmp common_dispatch + } +} +#define MAX_ORDINAL 262 diff -r 7e3f204e6c81 -r f9c11be8c0b3 crypto/weakcryptospi/source/cryptoswitch/cryptoswitch.cpp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/crypto/weakcryptospi/source/cryptoswitch/cryptoswitch.cpp Tue Dec 01 11:12:04 2009 +0000 @@ -0,0 +1,83 @@ +/* +* Copyright (c) 2004-2009 Nokia Corporation and/or its subsidiary(-ies). +* All rights reserved. +* This component and the accompanying materials are made available +* under the terms of the License "Eclipse Public License v1.0" +* which accompanies this distribution, and is available +* at the URL "http://www.eclipse.org/legal/epl-v10.html". +* +* Initial Contributors: +* Nokia Corporation - initial contribution. +* +* Contributors: +* +* Description: +* +*/ + + +#include + + +extern "C" { + +#include "cryptography_stubs.h" + +FARPROC vector[MAX_ORDINAL+1]; + +void fill_vector(HINSTANCE aDll) + { + int i; + for (i=1;i<=MAX_ORDINAL;i++) + { + vector[i] = GetProcAddress(aDll, (LPCSTR)i); + } + vector[0] = (FARPROC)1; // initialised + } + +void init_vector() + { + __LOCK_HOST; // prevent deadlock with EKA2 scheduler + + HINSTANCE instance; + + // Try for strong cryptography + // + instance = LoadLibraryA("strong_cryptography.dll"); + if (instance != NULL) + { + fill_vector(instance); + return; + } + + // Try for weak cryptography + // + instance = LoadLibraryA("weak_cryptography.dll"); + if (instance != NULL) + { + fill_vector(instance); + return; + } + + // die + // + OutputDebugStringA("Unable to load cryptography implementation"); + _asm int 3; + } + +__declspec(naked) void common_dispatch() + { + _asm cmp dword ptr vector,0 // initialised? + _asm jne call_though_vector + _asm push eax + _asm push ecx + _asm push edx + _asm call init_vector + _asm pop edx + _asm pop ecx + _asm pop eax +call_though_vector: + _asm jmp [vector+eax*4] + } + +} diff -r 7e3f204e6c81 -r f9c11be8c0b3 crypto/weakcryptospi/source/hash/hash.cpp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/crypto/weakcryptospi/source/hash/hash.cpp Tue Dec 01 11:12:04 2009 +0000 @@ -0,0 +1,138 @@ +/* +* Copyright (c) 2005-2009 Nokia Corporation and/or its subsidiary(-ies). +* All rights reserved. +* This component and the accompanying materials are made available +* under the terms of the License "Eclipse Public License v1.0" +* which accompanies this distribution, and is available +* at the URL "http://www.eclipse.org/legal/epl-v10.html". +* +* Initial Contributors: +* Nokia Corporation - initial contribution. +* +* Contributors: +* +* Description: +* (c) 1999-2003 Symbian Ltd. All rights reserved +* +*/ + + +/** + @file +*/ + +#include +#include +#define EXPANDLOOP + +EXPORT_C CMessageDigest::CMessageDigest(void):CBase() +{} + +EXPORT_C CMessageDigest::CMessageDigest(const CMessageDigest& /*aMD*/):CBase() +{} + +EXPORT_C CMessageDigest::~CMessageDigest(void) +{} + +/* Note that the shifts here are NOT guaranteed to work if s == 0, and it is + * assumed in R() (and hence in all inline) that a is unsigned. */ +// CMD_R - rotate a left by n bits; the main bottleneck of the algorithm +// implementation +/* +C++ version compiles to: + +CMD_R__FUiUi: + add r3, r0, #0 + lsl r3, r3, r1 + mov r2, #32 + sub r2, r2, r1 + lsr r0, r0, r2 + add r3, r3, r0 + add r0, r3, #0 + bx lr + +*/ + +TInt CMessageDigest::GetExtension(TUint aExtensionId, TAny*& a0, TAny* a1) + { + return Extension_(aExtensionId, a0, a1); + } + + +////////////////////////////////////////////////////////////////// +// Factory class to create CMessageDigest derived objects +////////////////////////////////////////////////////////////////// +EXPORT_C CMessageDigest* CMessageDigestFactory::NewDigestL(CMessageDigest::THashId aHashId) +{ + CMessageDigest* hash = NULL; + switch (aHashId) + { + case (CMessageDigest::EMD2): + { + hash = CMD2::NewL(); + break; + } + case (CMessageDigest::EMD5): + { + hash = CMD5::NewL(); + break; + } + case (CMessageDigest::ESHA1): + { + hash = CSHA1::NewL(); + break; + } + case (CMessageDigest::EMD4): + { + hash = CMD4::NewL(); + break; + } + case (CMessageDigest::ESHA224): + { + hash = CSHA2::NewL(E224Bit); + break; + } + case (CMessageDigest::ESHA256): + { + hash = CSHA2::NewL(E256Bit); + break; + } + case (CMessageDigest::ESHA384): + { + hash = CSHA2::NewL(E384Bit); + break; + } + case (CMessageDigest::ESHA512): + { + hash = CSHA2::NewL(E512Bit); + break; + } + case (CMessageDigest::HMAC): + default: + User::Leave(KErrNotSupported); + } + + return (hash); +} + +EXPORT_C CMessageDigest* CMessageDigestFactory::NewDigestLC(CMessageDigest::THashId aHashId) +{ + CMessageDigest* hash = CMessageDigestFactory::NewDigestL(aHashId); + CleanupStack::PushL(hash); + return (hash); +} + +EXPORT_C CMessageDigest* CMessageDigestFactory::NewHMACL(CMessageDigest::THashId aHashId, const TDesC8& aKey) +{ + CMessageDigest* hash = CMessageDigestFactory::NewDigestLC(aHashId); + CMessageDigest* hmac = CHMAC::NewL(aKey, hash); + CleanupStack::Pop(hash); // Now owned by hmac + return (hmac); +} + +EXPORT_C CMessageDigest* CMessageDigestFactory::NewHMACLC(CMessageDigest::THashId aHashId, const TDesC8& aKey) +{ + CMessageDigest* hmac = CMessageDigestFactory::NewHMACL(aHashId, aKey); + CleanupStack::PushL(hmac); + return (hmac); +} diff -r 7e3f204e6c81 -r f9c11be8c0b3 crypto/weakcryptospi/source/hash/hashshim.cpp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/crypto/weakcryptospi/source/hash/hashshim.cpp Tue Dec 01 11:12:04 2009 +0000 @@ -0,0 +1,856 @@ +/* +* Copyright (c) 2006-2009 Nokia Corporation and/or its subsidiary(-ies). +* All rights reserved. +* This component and the accompanying materials are made available +* under the terms of the License "Eclipse Public License v1.0" +* which accompanies this distribution, and is available +* at the URL "http://www.eclipse.org/legal/epl-v10.html". +* +* Initial Contributors: +* Nokia Corporation - initial contribution. +* +* Contributors: +* +* Description: +* hash shim implementation +* hash shim implementation +* +*/ + + +/** + @file +*/ + +#include "hashshim.h" +#include +#include +#include "keys.h" + + +using namespace CryptoSpi; + +// +// MD2 shim implementation +// +CMD2Shim* CMD2Shim::NewL() + { + CMD2Shim* self=CMD2Shim::NewLC(); + CleanupStack::Pop(); + return self; + } + +CMD2Shim* CMD2Shim::NewLC() + { + CMD2Shim* self=new(ELeave) CMD2Shim(); + CleanupStack::PushL(self); + self->ConstructL(); + return self; + } + +TInt CMD2Shim::Extension_(TUint aExtensionId, TAny*& a0, TAny* /*a1*/) + { + TInt ret(KErrNotSupported); + + if (KHashInterfaceUid.iUid==aExtensionId && iHashImpl) + { + a0=iHashImpl; + ret=KErrNone; + } + + return ret; + } + +CMD2Shim::CMD2Shim() + { + } + +CMD2Shim::~CMD2Shim() + { + delete iHashImpl; + } + + +void CMD2Shim::ConstructL() + { + CHashFactory::CreateHashL(iHashImpl, + KMd2Uid, + KHashModeUid, + NULL, NULL); + } + +CMessageDigest* CMD2Shim::CopyL() + { + CMD2Shim* copy=new(ELeave) CMD2Shim(); + CleanupStack::PushL(copy); + copy->iHashImpl=iHashImpl->CopyL(); + CleanupStack::Pop(); + return copy; + } + +CMessageDigest* CMD2Shim::ReplicateL() + { + CMD2Shim* copy=new(ELeave) CMD2Shim(); + CleanupStack::PushL(copy); + copy->iHashImpl=iHashImpl->ReplicateL(); + CleanupStack::Pop(); + return copy; + } + + +TInt CMD2Shim::BlockSize() + { + const TCharacteristics* ptr(NULL); + TRAPD(err, iHashImpl->GetCharacteristicsL(ptr);) + + if (err) + { + return ((err>0)? KErrGeneral : err); + } + const THashCharacteristics* hashPtr=static_cast(ptr); + return hashPtr->iBlockSize/8; + } + +TInt CMD2Shim::HashSize() + { + const TCharacteristics* ptr(NULL); + TRAPD(err, iHashImpl->GetCharacteristicsL(ptr);) + if (err) + { + return ((err>0)? KErrGeneral : err); + } + const THashCharacteristics* hashPtr=static_cast(ptr); + return hashPtr->iOutputSize/8; + } + +void CMD2Shim::Update(const TDesC8& aMessage) + { + iHashImpl->Update(aMessage); + } + + +TPtrC8 CMD2Shim::Final(const TDesC8& aMessage) + { + return iHashImpl->Final(aMessage); + } + +TPtrC8 CMD2Shim::Final() + { + TPtrC8 ptr(KNullDesC8()); + return iHashImpl->Final(ptr); + } + +void CMD2Shim::Reset() + { + iHashImpl->Reset(); + } + + +TPtrC8 CMD2Shim::Hash(const TDesC8& aMessage) + { + return iHashImpl->Hash(aMessage); + } + +// +// Implementation of MD5 shim +// +CMD5Shim* CMD5Shim::NewL() + { + CMD5Shim* self=CMD5Shim::NewLC(); + CleanupStack::Pop(); + return self; + } + +CMD5Shim* CMD5Shim::NewLC() + { + + CMD5Shim* self=new(ELeave) CMD5Shim(); + CleanupStack::PushL(self); + self->ConstructL(); + return self; + + } + +CMD5Shim::CMD5Shim() + { + } + +TInt CMD5Shim::Extension_(TUint aExtensionId, TAny*& a0, TAny* /*a1*/) + { + TInt ret(KErrNotSupported); + + if (KHashInterfaceUid.iUid==aExtensionId && iHashImpl) + { + a0=iHashImpl; + ret=KErrNone; + } + + return ret; + } + +CMD5Shim::~CMD5Shim() + { + delete iHashImpl; + } + + +void CMD5Shim::ConstructL() + { + CHashFactory::CreateHashL(iHashImpl, + KMd5Uid, + KHashModeUid, + NULL, + NULL); + } + +CMessageDigest* CMD5Shim::CopyL() + { + CMD5Shim* copy=new(ELeave) CMD5Shim(); + CleanupStack::PushL(copy); + copy->iHashImpl=iHashImpl->CopyL(); + CleanupStack::Pop(); + return copy; + } + +CMessageDigest* CMD5Shim::ReplicateL() + { + CMD5Shim* copy=new(ELeave) CMD5Shim(); + CleanupStack::PushL(copy); + copy->iHashImpl=iHashImpl->ReplicateL(); + CleanupStack::Pop(); + return copy; + } + +TInt CMD5Shim::BlockSize() + { + const TCharacteristics* ptr(NULL); + TRAPD(err, iHashImpl->GetCharacteristicsL(ptr);) + if (err) + { + return ((err>0)? KErrGeneral : err); + } + const THashCharacteristics* hashPtr=static_cast(ptr); + return hashPtr->iBlockSize/8; + } + +TInt CMD5Shim::HashSize() + { + const TCharacteristics* ptr(NULL); + TRAPD(err, iHashImpl->GetCharacteristicsL(ptr);) + if (err) + { + return ((err>0)? KErrGeneral : err); + } + const THashCharacteristics* hashPtr=static_cast(ptr); + return hashPtr->iOutputSize/8; + } + +void CMD5Shim::Update(const TDesC8& aMessage) + { + iHashImpl->Update(aMessage); + } + +TPtrC8 CMD5Shim::Final(const TDesC8& aMessage) + { + return iHashImpl->Final(aMessage); + } + +TPtrC8 CMD5Shim::Final() + { + TPtrC8 ptr(KNullDesC8()); + return iHashImpl->Final(ptr); + } + +void CMD5Shim::Reset() + { + iHashImpl->Reset(); + } + + +TPtrC8 CMD5Shim::Hash(const TDesC8& aMessage) + { + return iHashImpl->Hash(aMessage); + } + +// +// Implementation of SHA1 shim +// + +CSHA1Shim* CSHA1Shim::NewL() + { + CSHA1Shim* self=CSHA1Shim::NewLC(); + CleanupStack::Pop(); + return self; + } + +CSHA1Shim* CSHA1Shim::NewLC() + { + + CSHA1Shim* self=new(ELeave) CSHA1Shim(); + CleanupStack::PushL(self); + self->ConstructL(); + return self; + + } + +CSHA1Shim::CSHA1Shim() + { + } + + +TInt CSHA1Shim::Extension_(TUint aExtensionId, TAny*& a0, TAny* /*a1*/) + { + TInt ret(KErrNotSupported); + + if (KHashInterfaceUid.iUid==aExtensionId && iHashImpl) + { + a0=iHashImpl; + ret=KErrNone; + } + + return ret; + } + +CSHA1Shim::~CSHA1Shim() + { + delete iHashImpl; + } + + +void CSHA1Shim::ConstructL() + { + CHashFactory::CreateHashL(iHashImpl, + KSha1Uid, + KHashModeUid, + NULL, + NULL); + } + +CMessageDigest* CSHA1Shim::CopyL() + { + CSHA1Shim* copy=new(ELeave) CSHA1Shim(); + CleanupStack::PushL(copy); + copy->iHashImpl=iHashImpl->CopyL(); + CleanupStack::Pop(); + return copy; + } + +CMessageDigest* CSHA1Shim::ReplicateL() + { + CSHA1Shim* copy=new(ELeave) CSHA1Shim(); + CleanupStack::PushL(copy); + copy->iHashImpl=iHashImpl->ReplicateL(); + CleanupStack::Pop(); + return copy; + } + +TInt CSHA1Shim::BlockSize() + { + const TCharacteristics* ptr(NULL); + TRAPD(err, iHashImpl->GetCharacteristicsL(ptr);) + if (err) + { + return ((err>0)? KErrGeneral : err); + } + const THashCharacteristics* hashPtr=static_cast(ptr); + return hashPtr->iBlockSize/8; + } + +TInt CSHA1Shim::HashSize() + { + const TCharacteristics* ptr(NULL); + TRAPD(err, iHashImpl->GetCharacteristicsL(ptr);) + if (err) + { + return ((err>0)? KErrGeneral : err); + } + const THashCharacteristics* hashPtr=static_cast(ptr); + return hashPtr->iOutputSize/8; + } + +void CSHA1Shim::Update(const TDesC8& aMessage) + { + iHashImpl->Update(aMessage); + } + +TPtrC8 CSHA1Shim::Final(const TDesC8& aMessage) + { + return iHashImpl->Final(aMessage); + } + +TPtrC8 CSHA1Shim::Final() + { + TPtrC8 ptr(KNullDesC8()); + return iHashImpl->Final(ptr); + } + +void CSHA1Shim::Reset() + { + iHashImpl->Reset(); + } + +TPtrC8 CSHA1Shim::Hash(const TDesC8& aMessage) + { + return iHashImpl->Hash(aMessage); + } + + +// +// Implementation of SHA2 shim +// + +CSHA2Shim* CSHA2Shim::NewL(TSH2Algo aAlgorithmId) + { + CSHA2Shim* self=CSHA2Shim::NewLC(aAlgorithmId); + CleanupStack::Pop(); + return self; + } + +CSHA2Shim* CSHA2Shim::NewLC(TSH2Algo aAlgorithmId) + { + + CSHA2Shim* self=new(ELeave) CSHA2Shim(); + CleanupStack::PushL(self); + self->ConstructL(aAlgorithmId); + return self; + } + +CSHA2Shim::CSHA2Shim() + { + } + +TInt CSHA2Shim::Extension_(TUint aExtensionId, TAny*& a0, TAny* /*a1*/) + { + TInt ret(KErrNotSupported); + + if (KHashInterfaceUid.iUid==aExtensionId && iHashImpl) + { + a0=iHashImpl; + ret=KErrNone; + } + return ret; + } + +CSHA2Shim::~CSHA2Shim() + { + delete iHashImpl; + } + +void CSHA2Shim::ConstructL(TSH2Algo aAlgorithmId) + { + TUid algoId = {0}; + switch(aAlgorithmId) + { + case E224Bit: + { + algoId = KSha224Uid; + break; + } + case E256Bit: + { + algoId = KSha256Uid; + break; + } + case E384Bit: + { + algoId = KSha384Uid; + break; + } + case E512Bit: + { + algoId = KSha512Uid; + break; + } + default: + User::Leave(KErrNotSupported); + } + + CHashFactory::CreateHashL(iHashImpl, + algoId, + KHashModeUid, + NULL, + NULL); + } + +CMessageDigest* CSHA2Shim::CopyL() + { + CSHA2Shim* copy=new(ELeave) CSHA2Shim(); + CleanupStack::PushL(copy); + copy->iHashImpl=iHashImpl->CopyL(); + CleanupStack::Pop(); + return copy; + } + +CMessageDigest* CSHA2Shim::ReplicateL() + { + CSHA2Shim* copy=new(ELeave) CSHA2Shim(); + CleanupStack::PushL(copy); + copy->iHashImpl=iHashImpl->ReplicateL(); + CleanupStack::Pop(); + return copy; + } + +TInt CSHA2Shim::BlockSize() + { + const TCharacteristics* ptr(NULL); + TRAPD(err, iHashImpl->GetCharacteristicsL(ptr);) + if (err) + { + return ((err>0)? KErrGeneral : err); + } + const THashCharacteristics* hashPtr=static_cast(ptr); + return hashPtr->iBlockSize/8; + } + +TInt CSHA2Shim::HashSize() + { + const TCharacteristics* ptr(NULL); + TRAPD(err, iHashImpl->GetCharacteristicsL(ptr);) + if (err) + { + return ((err>0)? KErrGeneral : err); + } + const THashCharacteristics* hashPtr=static_cast(ptr); + return hashPtr->iOutputSize/8; + } + +void CSHA2Shim::Update(const TDesC8& aMessage) + { + iHashImpl->Update(aMessage); + } + +TPtrC8 CSHA2Shim::Final(const TDesC8& aMessage) + { + return iHashImpl->Final(aMessage); + } + +TPtrC8 CSHA2Shim::Final() + { + TPtrC8 ptr(KNullDesC8()); + return iHashImpl->Final(ptr); + } + +void CSHA2Shim::Reset() + { + iHashImpl->Reset(); + } + +TPtrC8 CSHA2Shim::Hash(const TDesC8& aMessage) + { + return iHashImpl->Hash(aMessage); + } + +// +// Implementation of HMAC shim +// + +CHMACShim* CHMACShim::NewL(const TDesC8& aKey, CMessageDigest* aDigest) + { + CHMACShim* self(0); + + // Check whether the hash contains an SPI plug-in + TAny* implPtr(0); + TInt err = aDigest->GetExtension(CryptoSpi::KHashInterface, implPtr, NULL); + if (err == KErrNone && implPtr) + { + CryptoSpi::CHash* impl(static_cast(implPtr)); + const CryptoSpi::TCharacteristics* c(0); + impl->GetCharacteristicsL(c); + const CryptoSpi::THashCharacteristics* hashCharacteristics(static_cast(c)); + + + // Verify that the plug-in supports Hmac mode + if (hashCharacteristics->IsOperationModeSupported(CryptoSpi::KHmacModeUid)) + { + + #ifndef SYMBIAN_SDP_IPSEC_VOIP_SUPPORT + // Make an own copy + CHash* myHash=impl->ReplicateL(); + CleanupStack::PushL(myHash); + #endif + // Set the key + TKeyProperty keyProperty = {KHmacModeUid, KNullUid, KSymmetricKey, KNonEmbeddedKeyUid}; + CCryptoParams* keyParam =CCryptoParams::NewLC(); + keyParam->AddL(aKey, KHmacKeyParameterUid); + CKey* uniKey= CKey::NewLC(keyProperty, *keyParam); + #ifndef SYMBIAN_SDP_IPSEC_VOIP_SUPPORT + myHash->SetKeyL(*uniKey); + CleanupStack::PopAndDestroy(2, keyParam); + // Set hash to Hmac mode + myHash->SetOperationModeL(CryptoSpi::KHmacModeUid); + self = new(ELeave) CHMACShim(myHash, aDigest); + CleanupStack::Pop(myHash); + #else + TUid algorithmUID = algorithmUID.Uid(hashCharacteristics->cmn.iAlgorithmUID); + //Create a pointer for the Mac Implementation Object + CMac* macImpl = NULL; + CMacFactory::CreateMacL(macImpl,algorithmUID,*uniKey, NULL); + CleanupStack::PushL(macImpl); + self = new(ELeave) CHMACShim(macImpl, aDigest,uniKey, algorithmUID); + CleanupStack::Pop(macImpl); + CleanupStack::Pop(uniKey); + CleanupStack::PopAndDestroy(keyParam); + #endif + } + } + return self; + } + +#ifdef SYMBIAN_SDP_IPSEC_VOIP_SUPPORT + +CHMACShim::CHMACShim(CryptoSpi::CMac* aImpl, CMessageDigest* aDigest, CryptoSpi::CKey* aKey, TUid aAlgorithmUid) + : CHMAC(aDigest), iMacImpl(aImpl), iKey(aKey), iAlgorithmUid(aAlgorithmUid) + { + } + +#else + +CHMACShim::CHMACShim(CryptoSpi::CHash* aImpl, CMessageDigest* aDigest) + : CHMAC(aDigest), iMacImpl(aImpl) + { + } + +#endif + +CHMACShim::CHMACShim() + { + } + +CHMACShim::~CHMACShim() + { + delete iMacImpl; +#ifdef SYMBIAN_SDP_IPSEC_VOIP_SUPPORT + delete iKey; +#endif + } + +TInt CHMACShim::BlockSize() + { + const TCharacteristics* ptr(NULL); + TRAPD(err, iMacImpl->GetCharacteristicsL(ptr)); + + if (err) + { + return ((err>0)? KErrGeneral : err); + } + +#ifndef SYMBIAN_SDP_IPSEC_VOIP_SUPPORT + const THashCharacteristics* hashPtr=static_cast(ptr); + return hashPtr->iBlockSize/8; +#else + const TMacCharacteristics* macPtr=static_cast(ptr); + return macPtr->iHashAlgorithmChar->iBlockSize/8; +#endif + } + +TInt CHMACShim::HashSize() + { + const TCharacteristics* ptr(NULL); + TRAPD(err, iMacImpl->GetCharacteristicsL(ptr)); + if (err) + { + return ((err>0)? KErrGeneral : err); + } + +#ifndef SYMBIAN_SDP_IPSEC_VOIP_SUPPORT + const THashCharacteristics* hashPtr=static_cast(ptr); + return hashPtr->iOutputSize/8; +#else + const TMacCharacteristics* macPtr=static_cast(ptr); + return macPtr->iHashAlgorithmChar->iOutputSize/8; +#endif + } + +void CHMACShim::Update(const TDesC8& aMessage) + { +#ifdef SYMBIAN_SDP_IPSEC_VOIP_SUPPORT + // The error is ignored as the legacy code methods are non-leaving and they call + // the new MAC interfaces which uses leaving methods for processing MAC value. + // This call always call the non-leaving legacy method. + TRAP_IGNORE(iMacImpl->UpdateL(aMessage)); +#else + iMacImpl->Update(aMessage); +#endif + } + +TPtrC8 CHMACShim::Final(const TDesC8& aMessage) + { +#ifdef SYMBIAN_SDP_IPSEC_VOIP_SUPPORT + TPtrC8 macPtr(KNullDesC8()); + // The error is ignored as the legacy code methods are non-leaving and they call + // the new MAC interfaces which uses leaving methods for processing MAC value. + // This call always call the non-leaving legacy method. + TRAP_IGNORE(macPtr.Set(iMacImpl->FinalL(aMessage))); + return macPtr; +#else + return iMacImpl->Final(aMessage); +#endif + } + +TPtrC8 CHMACShim::Final() + { + TPtrC8 ptr(KNullDesC8()); +#ifdef SYMBIAN_SDP_IPSEC_VOIP_SUPPORT + TPtrC8 macPtr(KNullDesC8()); + // The error is ignored as the legacy code methods are non-leaving and they call + // the new MAC interfaces which uses leaving methods for processing MAC value. + // This call always call the non-leaving legacy method. + TRAP_IGNORE(macPtr.Set(iMacImpl->FinalL(ptr))); + return macPtr; +#else + return iMacImpl->Final(ptr); +#endif + } + +void CHMACShim::Reset() + { + iMacImpl->Reset(); + } + +TPtrC8 CHMACShim::Hash(const TDesC8& aMessage) + { +#ifdef SYMBIAN_SDP_IPSEC_VOIP_SUPPORT + TPtrC8 macPtr(KNullDesC8()); + // The error is ignored as the legacy code methods are non-leaving and they call + // the new MAC interfaces which uses leaving methods for processing MAC value. + // This call always call the non-leaving legacy method. + TRAP_IGNORE(macPtr.Set(iMacImpl->MacL(aMessage))); + return macPtr; +#else + return iMacImpl->Hash(aMessage); +#endif + } + +CMessageDigest* CHMACShim::ReplicateL() + { + CHMACShim* copy=new(ELeave) CHMACShim(); + CleanupStack::PushL(copy); + copy->iMacImpl=iMacImpl->ReplicateL(); + CleanupStack::Pop(copy); + return copy; + } + +CMessageDigest* CHMACShim::CopyL() + { + CHMACShim* copy=new(ELeave) CHMACShim(); + CleanupStack::PushL(copy); + copy->iMacImpl=iMacImpl->CopyL(); + CleanupStack::Pop(copy); + return copy; + } + +// +// Implemetation of MD4 shim +// +CMD4Shim* CMD4Shim::NewL() + { + CMD4Shim* self=CMD4Shim::NewLC(); + CleanupStack::Pop(); + return self; + } + +CMD4Shim* CMD4Shim::NewLC() + { + CMD4Shim* self=new(ELeave) CMD4Shim(); + CleanupStack::PushL(self); + self->ConstructL(); + return self; + } + +CMD4Shim::CMD4Shim() + { + } + +TInt CMD4Shim::Extension_(TUint aExtensionId, TAny*& a0, TAny* /*a1*/) + { + TInt ret(KErrNotSupported); + + if (KHashInterfaceUid.iUid==aExtensionId && iHashImpl) + { + a0=iHashImpl; + ret=KErrNone; + } + + return ret; + } + +CMD4Shim::~CMD4Shim() + { + delete iHashImpl; + } + + +void CMD4Shim::ConstructL() + { + CHashFactory::CreateHashL(iHashImpl,KMd4Uid,KHashModeUid,NULL,NULL); + } + +CMessageDigest* CMD4Shim::CopyL() + { + CMD4Shim* copy=new(ELeave) CMD4Shim(); + CleanupStack::PushL(copy); + copy->iHashImpl=iHashImpl->CopyL(); + CleanupStack::Pop(); + return copy; + } + +CMessageDigest* CMD4Shim::ReplicateL() + { + CMD4Shim* copy=new(ELeave) CMD4Shim(); + CleanupStack::PushL(copy); + copy->iHashImpl=iHashImpl->ReplicateL(); + CleanupStack::Pop(); + return copy; + } + +TInt CMD4Shim::BlockSize() + { + const TCharacteristics* ptr(NULL); + TRAPD(err, iHashImpl->GetCharacteristicsL(ptr);) + if (err) + { + return ((err>0)? KErrGeneral : err); + } + const THashCharacteristics* hashPtr=static_cast(ptr); + return hashPtr->iBlockSize/8; + } + +TInt CMD4Shim::HashSize() + { + const TCharacteristics* ptr(NULL); + TRAPD(err, iHashImpl->GetCharacteristicsL(ptr);) + if (err) + { + return ((err>0)? KErrGeneral : err); + } + const THashCharacteristics* hashPtr=static_cast(ptr); + return hashPtr->iOutputSize/8; + } + +void CMD4Shim::Update(const TDesC8& aMessage) + { + iHashImpl->Update(aMessage); + } + +TPtrC8 CMD4Shim::Final(const TDesC8& aMessage) + { + return iHashImpl->Final(aMessage); + } + +TPtrC8 CMD4Shim::Final() + { + TPtrC8 ptr(KNullDesC8()); + return iHashImpl->Final(ptr); + } + +void CMD4Shim::Reset() + { + iHashImpl->Reset(); + } + + +TPtrC8 CMD4Shim::Hash(const TDesC8& aMessage) + { + return iHashImpl->Hash(aMessage); + } + diff -r 7e3f204e6c81 -r f9c11be8c0b3 crypto/weakcryptospi/source/hash/hashshim.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/crypto/weakcryptospi/source/hash/hashshim.h Tue Dec 01 11:12:04 2009 +0000 @@ -0,0 +1,244 @@ +/* +* Copyright (c) 2006-2009 Nokia Corporation and/or its subsidiary(-ies). +* All rights reserved. +* This component and the accompanying materials are made available +* under the terms of the License "Eclipse Public License v1.0" +* which accompanies this distribution, and is available +* at the URL "http://www.eclipse.org/legal/epl-v10.html". +* +* Initial Contributors: +* Nokia Corporation - initial contribution. +* +* Contributors: +* +* Description: +* hash shim classes definition +* +*/ + + +/** + @file + @internalComponent + @released +*/ + +#ifndef __HASHSHIM_H__ +#define __HASHSHIM_H__ + +#include +#include +#include +#include "keys.h" + +#ifdef SYMBIAN_SDP_IPSEC_VOIP_SUPPORT + #include +#endif + +// +// MD2 shim class +// +NONSHARABLE_CLASS(CMD2Shim) : public CMD2 + { +public: + + static CMD2Shim* NewL(); + static CMD2Shim* NewLC(); + ~CMD2Shim(); + CMessageDigest* CopyL(); + TInt BlockSize(); + TInt HashSize() ; + void Update(const TDesC8& aMessage); + TPtrC8 Final(const TDesC8& aMessage); + TPtrC8 Final(); + void Reset(); + TPtrC8 Hash(const TDesC8& aMessage); + CMessageDigest* ReplicateL(); + +protected: + //virtual from CBase + virtual TInt Extension_(TUint aExtensionId, TAny*& a0, TAny* a1); + +private: + CMD2Shim(); + void ConstructL(); + +private: + CryptoSpi::CHash* iHashImpl; + }; + + +// +// MD5 shim class +// + +NONSHARABLE_CLASS(CMD5Shim) : public CMD5 + { +public: + static CMD5Shim* NewL(); + static CMD5Shim* NewLC(); + ~CMD5Shim(); + CMessageDigest* CopyL(); + TInt BlockSize(); + TInt HashSize() ; + void Update(const TDesC8& aMessage); + TPtrC8 Final(const TDesC8& aMessage); + TPtrC8 Final(); + void Reset(); + TPtrC8 Hash(const TDesC8& aMessage); + CMessageDigest* ReplicateL(); + +protected: + //virtual from CBase + virtual TInt Extension_(TUint aExtensionId, TAny*& a0, TAny* a1); + +private: + CMD5Shim(); + void ConstructL(); + +private: + CryptoSpi::CHash* iHashImpl; + }; + + + +// +// SHA1 shim class +// + +NONSHARABLE_CLASS(CSHA1Shim) : public CSHA1 + { +public: + static CSHA1Shim* NewL(); + static CSHA1Shim* NewLC(); + ~CSHA1Shim(); + CMessageDigest* CopyL(); + TInt BlockSize(); + TInt HashSize() ; + void Update(const TDesC8& aMessage); + TPtrC8 Final(const TDesC8& aMessage); + TPtrC8 Final(); + void Reset(); + TPtrC8 Hash(const TDesC8& aMessage); + CMessageDigest* ReplicateL(); + +protected: + //virtual from CBase + virtual TInt Extension_(TUint aExtensionId, TAny*& a0, TAny* a1); + +private: + CSHA1Shim(); + void ConstructL(); + +private: + CryptoSpi::CHash* iHashImpl; + }; + +// +// SHA2 shim class +// + +NONSHARABLE_CLASS(CSHA2Shim) : public CSHA2 + { +public: + static CSHA2Shim* NewL(TSH2Algo aAlgorithmId); + static CSHA2Shim* NewLC(TSH2Algo aAlgorithmId); + ~CSHA2Shim(); + CMessageDigest* CopyL(); + TInt BlockSize(); + TInt HashSize() ; + void Update(const TDesC8& aMessage); + TPtrC8 Final(const TDesC8& aMessage); + TPtrC8 Final(); + void Reset(); + TPtrC8 Hash(const TDesC8& aMessage); + CMessageDigest* ReplicateL(); + +protected: + //virtual from CBase + virtual TInt Extension_(TUint aExtensionId, TAny*& a0, TAny* a1); + +private: + CSHA2Shim(); + void ConstructL(TSH2Algo aAlgorithmId); + +private: + CryptoSpi::CHash* iHashImpl; + }; + + + +// +// HMac shim class +// + +NONSHARABLE_CLASS(CHMACShim) : public CHMAC + { +public: + static CHMACShim* NewL(const TDesC8& aKey, CMessageDigest* aDigest); + static CHMACShim* NewLC(const TDesC8& aKey, CMessageDigest* aDigest); + ~CHMACShim(); + CMessageDigest* CopyL(); + TInt BlockSize(); + TInt HashSize() ; + void Update(const TDesC8& aMessage); + TPtrC8 Final(const TDesC8& aMessage); + TPtrC8 Final(); + void Reset(); + TPtrC8 Hash(const TDesC8& aMessage); + CMessageDigest* ReplicateL(); + +private: + +#ifdef SYMBIAN_SDP_IPSEC_VOIP_SUPPORT + CHMACShim(CryptoSpi::CMac* aImpl, CMessageDigest* aDigest, CryptoSpi::CKey* aKey, TUid aAlgorithmUid); +#else + CHMACShim(CryptoSpi::CHash* aImpl, CMessageDigest* aDigest); +#endif + CHMACShim(); + void ConstructL(const TDesC8& aKey, TUid aAlgorithmUid, CMessageDigest* aDigest); + +private: + +#ifdef SYMBIAN_SDP_IPSEC_VOIP_SUPPORT + CryptoSpi::CMac* iMacImpl; + CryptoSpi::CKey* iKey; + TUid iAlgorithmUid; +#else + CryptoSpi::CHash* iMacImpl; +#endif + }; + +// +// MD4 shim class +// + +NONSHARABLE_CLASS(CMD4Shim) : public CMD4 + { +public: + static CMD4Shim* NewL(); + static CMD4Shim* NewLC(); + ~CMD4Shim(); + CMessageDigest* CopyL(); + TInt BlockSize(); + TInt HashSize(); + void Update(const TDesC8& aMessage); + TPtrC8 Final(const TDesC8& aMessage); + TPtrC8 Final(); + void Reset(); + TPtrC8 Hash(const TDesC8& aMessage); + CMessageDigest* ReplicateL(); + +protected: + //virtual from CBase + virtual TInt Extension_(TUint aExtensionId, TAny*& a0, TAny* a1); + +private: + CMD4Shim(); + void ConstructL(); + +private: + CryptoSpi::CHash* iHashImpl; + }; + +#endif // __HASHSHIM_H__ diff -r 7e3f204e6c81 -r f9c11be8c0b3 crypto/weakcryptospi/source/hash/hmac.cpp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/crypto/weakcryptospi/source/hash/hmac.cpp Tue Dec 01 11:12:04 2009 +0000 @@ -0,0 +1,256 @@ +/* +* Copyright (c) 2005-2009 Nokia Corporation and/or its subsidiary(-ies). +* All rights reserved. +* This component and the accompanying materials are made available +* under the terms of the License "Eclipse Public License v1.0" +* which accompanies this distribution, and is available +* at the URL "http://www.eclipse.org/legal/epl-v10.html". +* +* Initial Contributors: +* Nokia Corporation - initial contribution. +* +* Contributors: +* +* Description: +* +*/ + + + +#include +#include +#include +#include +#include +#include "hashshim.h" + + +#define EXPANDLOOP + +// +// HMAC implementation +// + +CHMAC::CHMAC() + { + } + + +CHMAC::CHMAC(CMessageDigest* aDigest) + :CMessageDigest(), + iDigest(aDigest), + iInnerPad(KMaxBlockSize), + iOuterPad(KMaxBlockSize) + { + } + +CHMAC::CHMAC(const CHMAC& aMD) + :CMessageDigest(aMD), + iDigest(NULL), + iInnerPad(aMD.iInnerPad), + iOuterPad(aMD.iOuterPad), + iBlockSize(aMD.iBlockSize) + { + } + +EXPORT_C CHMAC::~CHMAC(void) + { + delete iDigest; + } + +EXPORT_C CHMAC* CHMAC::NewL(const TDesC8& aKey,CMessageDigest* aDigest) + { + CHMAC* self = CHMACShim::NewL(aKey, aDigest); + if (! self) + { + // not able to use CryptoSpi, possibly due to an exterally + // derived legacy class so fallback to old implementation. + self=new(ELeave) CHMAC(aDigest); + CleanupStack::PushL(self); + self->InitialiseL(aKey); + CleanupStack::Pop(self); + } + return self; + } + + +// These methods are now deprecated. This is because hashes and HMACs +// should be implemented as plugins to the SPI framework. However, for +// binary compatibility reasons, these methods must be left here. +// There are no tests (hence no coverage) for HMACs outside the plugin +// framework, but this original code is left unmodified. +// +#ifdef _BullseyeCoverage +#pragma suppress_warnings on +#pragma BullseyeCoverage off +#pragma suppress_warnings off +#endif + + +void CHMAC::InitialiseL(const TDesC8& aKey) + { + InitBlockSizeL(); + // initialisation + if (iDigest) + { + iDigest->Reset(); + if( (TUint32)aKey.Size() > iBlockSize) + { + iInnerPad = iDigest->Final(aKey); + } + else + { + iInnerPad = aKey; + } + + TUint i; + for (i=iInnerPad.Size();iHash(iInnerPad); + } + } + +void CHMAC::InitBlockSizeL() + { + if (iDigest) + { + iBlockSize = iDigest->BlockSize(); + } + if(iBlockSize > KMaxBlockSize) + { + User::Leave(KErrNotSupported); + } + + iInnerPad.SetLength(iBlockSize); + iOuterPad.SetLength(iBlockSize); + iInnerPadCopy.SetLength(iBlockSize); + iOuterPadCopy.SetLength(iBlockSize); + } + +EXPORT_C CMessageDigest* CHMAC::CopyL(void) + { + CHMAC* that=new(ELeave) CHMAC(*this); + CleanupStack::PushL(that); + that->iDigest=iDigest ? iDigest->CopyL() : NULL; + CleanupStack::Pop(); + return that; + } + +EXPORT_C CMessageDigest* CHMAC::ReplicateL(void) + { + CHMAC* that=new(ELeave) CHMAC(*this); + CleanupStack::PushL(that); + that->iDigest=iDigest ? iDigest->ReplicateL() : NULL; + that->Reset(); + CleanupStack::Pop(); + return that; + } + +EXPORT_C TInt CHMAC::BlockSize(void) + { + return iBlockSize; + } + +EXPORT_C TInt CHMAC::HashSize(void) + { + return iDigest ? iDigest->HashSize() : 0; + } + +EXPORT_C void CHMAC::Reset(void) + { + if (iDigest) + { + iDigest->Reset(); + iDigest->Update(iInnerPad); + } + } + +// JCS, There may be a more efficient method but I can't find it +// because using the DoFinal/DoUpdate functions directly calls +// Store/Restore at inappropriate times and scribbles over stored +// data +// This is the only way I've found to both generate a hash value +// and get this in the correctly updated state +EXPORT_C TPtrC8 CHMAC::Hash(const TDesC8& aMessage) + { + TPtrC8 ptr(KNullDesC8()); + TPtrC8 finalPtr(KNullDesC8()); + StoreState(); + if (iDigest) + { + ptr.Set(iDigest->Final(aMessage)); + iDigest->Update(iOuterPad); + finalPtr.Set(iDigest->Final(ptr)); + } + + RestoreState(); + + if(iDigest) + { + iDigest->Update(aMessage); + } + + return (finalPtr); + } + +EXPORT_C void CHMAC::Update(const TDesC8& aMessage) + { + if(iDigest) + { + iDigest->Update(aMessage); + } + } + +EXPORT_C TPtrC8 CHMAC::Final(const TDesC8& aMessage) + { + TPtrC8 ptr(KNullDesC8()); + if(iDigest) + { + ptr.Set(iDigest->Final(aMessage)); + iDigest->Update(iOuterPad); + iDigest->Final(ptr); + Reset(); + } + return (ptr); + } + +EXPORT_C TPtrC8 CHMAC::Final() + { + TPtrC8 ptr(KNullDesC8()); + if(iDigest) + { + ptr.Set(iDigest->Final()); + iDigest->Update(iOuterPad); + iDigest->Final(ptr); + Reset(); + } + return (ptr); + } + +void CHMAC::RestoreState() + { + iOuterPad.Copy(iOuterPadCopy); + iInnerPad.Copy(iInnerPadCopy); + if (iDigest) + iDigest->RestoreState(); + } + +void CHMAC::StoreState() + { + iOuterPadCopy.Copy(iOuterPad); + iInnerPadCopy.Copy(iInnerPad); + if (iDigest) + iDigest->StoreState(); + } + + diff -r 7e3f204e6c81 -r f9c11be8c0b3 crypto/weakcryptospi/source/hash/md2.cpp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/crypto/weakcryptospi/source/hash/md2.cpp Tue Dec 01 11:12:04 2009 +0000 @@ -0,0 +1,118 @@ +/* +* Copyright (c) 2003-2009 Nokia Corporation and/or its subsidiary(-ies). +* All rights reserved. +* This component and the accompanying materials are made available +* under the terms of the License "Eclipse Public License v1.0" +* which accompanies this distribution, and is available +* at the URL "http://www.eclipse.org/legal/epl-v10.html". +* +* Initial Contributors: +* Nokia Corporation - initial contribution. +* +* Contributors: +* +* Description: +* +*/ + + +#include +#include +#include "hashshim.h" + +#define EXPANDLOOP + +// +// 32bit endianness independent MD2 implementation +// +CMD2::CMD2() + { + } + +EXPORT_C CMD2* CMD2::NewL(void) + { + return CMD2Shim::NewL(); + } + +EXPORT_C CMD2::~CMD2(void) + { + } + +// All these methods have been replaced by the shim +#ifdef _BullseyeCoverage +#pragma suppress_warnings on +#pragma BullseyeCoverage off +#pragma suppress_warnings off +#endif +EXPORT_C CMessageDigest* CMD2::ReplicateL(void) + { + // Method replaced by shim + ASSERT(EFalse); + return NULL; + } + +EXPORT_C TPtrC8 CMD2::Hash(const TDesC8& /*aMessage*/) + { + // Method replaced by shim + ASSERT(EFalse); + return KNullDesC8(); + } + +EXPORT_C CMessageDigest* CMD2::CopyL(void) + { + // Method replaced by shim + ASSERT(EFalse); + return NULL; + } + +EXPORT_C TInt CMD2::BlockSize(void) + { + // Method replaced by shim + ASSERT(EFalse); + return KErrNotSupported; + } + +EXPORT_C TInt CMD2::HashSize(void) + { + // Method replaced by shim + ASSERT(EFalse); + return KErrNotSupported; + } + +EXPORT_C void CMD2::Reset(void) + { + // Method replaced by shim + ASSERT(EFalse); + } + +EXPORT_C void CMD2::Update(const TDesC8& /*aMessage*/) + { + // Method replaced by shim + ASSERT(EFalse); + } + +EXPORT_C TPtrC8 CMD2::Final(const TDesC8& /*aMessage*/) + { + // Method replaced by shim + ASSERT(EFalse); + return KNullDesC8(); + } + +EXPORT_C TPtrC8 CMD2::Final() + { + // Method replaced by shim + ASSERT(EFalse); + return KNullDesC8(); + } + +void CMD2::RestoreState() + { + // Method replaced by shim + ASSERT(EFalse); + } + +void CMD2::StoreState() + { + // Method replaced by shim + ASSERT(EFalse); + } diff -r 7e3f204e6c81 -r f9c11be8c0b3 crypto/weakcryptospi/source/hash/md4.cpp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/crypto/weakcryptospi/source/hash/md4.cpp Tue Dec 01 11:12:04 2009 +0000 @@ -0,0 +1,123 @@ +/* +* Copyright (c) 2007-2009 Nokia Corporation and/or its subsidiary(-ies). +* All rights reserved. +* This component and the accompanying materials are made available +* under the terms of the License "Eclipse Public License v1.0" +* which accompanies this distribution, and is available +* at the URL "http://www.eclipse.org/legal/epl-v10.html". +* +* Initial Contributors: +* Nokia Corporation - initial contribution. +* +* Contributors: +* +* Description: +* +*/ + + +#include +#include +#include "hashshim.h" + +#define EXPANDLOOP + + +CMD4::CMD4() + { + } + +EXPORT_C CMD4* CMD4::NewL(void) + { + CMD4Shim* self=CMD4Shim::NewL(); + self->Reset(); + return self; + } + +EXPORT_C CMD4::~CMD4(void) + { + } + +// All these methods have been replaced by the shim +#ifdef _BullseyeCoverage +#pragma suppress_warnings on +#pragma BullseyeCoverage off +#pragma suppress_warnings off +#endif + + +EXPORT_C CMessageDigest* CMD4::ReplicateL(void) + { + // Method replaced by shim + ASSERT(EFalse); + + return NULL; + } + + +EXPORT_C TPtrC8 CMD4::Hash(const TDesC8& /*aMessage*/) + { + // Method replaced by shim + ASSERT(EFalse); + return KNullDesC8(); + } + +EXPORT_C CMessageDigest* CMD4::CopyL(void) + { + // Method replaced by shim + ASSERT(EFalse); + return NULL; + } + +EXPORT_C TInt CMD4::BlockSize(void) + { + // Method replaced by shim + ASSERT(EFalse); + return KErrNotSupported; + } + +EXPORT_C TInt CMD4::HashSize(void) + { + // Method replaced by shim + ASSERT(EFalse); + return KErrNotSupported; + } + +EXPORT_C void CMD4::Reset(void) + { + // Method replaced by shim + ASSERT(EFalse); + } + +EXPORT_C void CMD4::Update(const TDesC8& /*aMessage*/) + { + // Method replaced by shim + ASSERT(EFalse); + } + +EXPORT_C TPtrC8 CMD4::Final(const TDesC8& /*aMessage*/) + { + // Method replaced by shim + ASSERT(EFalse); + return KNullDesC8(); + } + +EXPORT_C TPtrC8 CMD4::Final() + { + // Method replaced by shim + ASSERT(EFalse); + return KNullDesC8(); + } + +void CMD4::RestoreState() + { + // Method replaced by shim + ASSERT(EFalse); + } + +void CMD4::StoreState() + { + // Method replaced by shim + ASSERT(EFalse); + } + diff -r 7e3f204e6c81 -r f9c11be8c0b3 crypto/weakcryptospi/source/hash/md5.cpp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/crypto/weakcryptospi/source/hash/md5.cpp Tue Dec 01 11:12:04 2009 +0000 @@ -0,0 +1,120 @@ +/* +* Copyright (c) 2003-2009 Nokia Corporation and/or its subsidiary(-ies). +* All rights reserved. +* This component and the accompanying materials are made available +* under the terms of the License "Eclipse Public License v1.0" +* which accompanies this distribution, and is available +* at the URL "http://www.eclipse.org/legal/epl-v10.html". +* +* Initial Contributors: +* Nokia Corporation - initial contribution. +* +* Contributors: +* +* Description: +* +*/ + + +#include +#include +#include "hashshim.h" + +#define EXPANDLOOP + +// +// 32bit endianness independent MD5 implementation +// +CMD5::CMD5() + { + } + +EXPORT_C CMD5* CMD5::NewL(void) + { + CMD5Shim* self=CMD5Shim::NewL(); + self->Reset(); + return self; + } + +EXPORT_C CMD5::~CMD5(void) + { + } + +// All these methods have been replaced by the shim +#ifdef _BullseyeCoverage +#pragma suppress_warnings on +#pragma BullseyeCoverage off +#pragma suppress_warnings off +#endif +EXPORT_C CMessageDigest* CMD5::ReplicateL(void) + { + // Method replaced by shim + ASSERT(EFalse); + return NULL; + } + +EXPORT_C TPtrC8 CMD5::Hash(const TDesC8& /*aMessage*/) + { + // Method replaced by shim + ASSERT(EFalse); + return KNullDesC8(); + } + +EXPORT_C CMessageDigest* CMD5::CopyL(void) + { + // Method replaced by shim + ASSERT(EFalse); + return NULL; + } + +EXPORT_C TInt CMD5::BlockSize(void) + { + // Method replaced by shim + ASSERT(EFalse); + return KErrNotSupported; + } + +EXPORT_C TInt CMD5::HashSize(void) + { + // Method replaced by shim + ASSERT(EFalse); + return KErrNotSupported; + } + +EXPORT_C void CMD5::Reset(void) + { + // Method replaced by shim + ASSERT(EFalse); + } + +EXPORT_C void CMD5::Update(const TDesC8& /*aMessage*/) + { + // Method replaced by shim + ASSERT(EFalse); + } + +EXPORT_C TPtrC8 CMD5::Final(const TDesC8& /*aMessage*/) + { + // Method replaced by shim + ASSERT(EFalse); + return KNullDesC8(); + } + +EXPORT_C TPtrC8 CMD5::Final() + { + // Method replaced by shim + ASSERT(EFalse); + return KNullDesC8(); + } + +void CMD5::RestoreState() + { + // Method replaced by shim + ASSERT(EFalse); + } + +void CMD5::StoreState() + { + // Method replaced by shim + ASSERT(EFalse); + } diff -r 7e3f204e6c81 -r f9c11be8c0b3 crypto/weakcryptospi/source/hash/sha1.cpp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/crypto/weakcryptospi/source/hash/sha1.cpp Tue Dec 01 11:12:04 2009 +0000 @@ -0,0 +1,190 @@ +/* +* Copyright (c) 2003-2009 Nokia Corporation and/or its subsidiary(-ies). +* All rights reserved. +* This component and the accompanying materials are made available +* under the terms of the License "Eclipse Public License v1.0" +* which accompanies this distribution, and is available +* at the URL "http://www.eclipse.org/legal/epl-v10.html". +* +* Initial Contributors: +* Nokia Corporation - initial contribution. +* +* Contributors: +* +* Description: +* +*/ + + +#include +#include +#include "hashshim.h" + +#define EXPANDLOOP + +// +// 32bit endian-independent SHA-1 implementation +// +CSHA1::CSHA1() + { + } + +EXPORT_C CSHA1* CSHA1::NewL(void) + { + CSHA1* self=CSHA1Shim::NewL(); + self->Reset(); + return self; + } + +EXPORT_C CSHA1::~CSHA1(void) + { + } + +// All these methods have been replaced by the shim +#ifdef _BullseyeCoverage +#pragma suppress_warnings on +#pragma BullseyeCoverage off +#pragma suppress_warnings off +#endif +EXPORT_C CMessageDigest* CSHA1::ReplicateL(void) + { + // Method replaced by shim + ASSERT(EFalse); + return NULL; + } + +EXPORT_C TPtrC8 CSHA1::Hash(const TDesC8& /*aMessage*/) + { + // Method replaced by shim + ASSERT(EFalse); + return KNullDesC8(); + } + +EXPORT_C CMessageDigest* CSHA1::CopyL(void) + { + // Method replaced by shim + ASSERT(EFalse); + return NULL; + } + +EXPORT_C TInt CSHA1::BlockSize(void) + { + ASSERT(EFalse); + return KErrNotSupported; + } + +EXPORT_C TInt CSHA1::HashSize(void) + { + ASSERT(EFalse); + return KErrNotSupported; + } + +EXPORT_C void CSHA1::Reset(void) + { + ASSERT(EFalse); + } + +EXPORT_C void CSHA1::Update(const TDesC8& /*aMessage*/) + { + ASSERT(EFalse); + } + +EXPORT_C TPtrC8 CSHA1::Final(const TDesC8& /*aMessage*/) + { + ASSERT(EFalse); + return KNullDesC8(); + } + +EXPORT_C TPtrC8 CSHA1::Final() + { + ASSERT(EFalse); + return KNullDesC8(); + } + +void CSHA1::RestoreState() + { + ASSERT(EFalse); + } + +void CSHA1::StoreState() + { + ASSERT(EFalse); + } + +/////////////////////////////////////////////////////////////////////////////////////// +// CSHA code is deprecated +/////////////////////////////////////////////////////////////////////////////////////// + +_LIT(KSHA, "HASH::CSHA"); + +EXPORT_C CSHA* CSHA::NewL(void) +{ + User::Panic(KSHA, KErrNotSupported); + return (NULL); // Shut compiler up +} + +EXPORT_C CSHA::~CSHA(void) +{ + User::Panic(KSHA, KErrNotSupported); +} + +EXPORT_C TPtrC8 CSHA::Hash(const TDesC8& /*aMessage*/) +{ + User::Panic(KSHA, KErrNotSupported); + return (KNullDesC8()); // Shut compiler up +} + +EXPORT_C TInt CSHA::HashSize(void) +{ + User::Panic(KSHA, KErrNotSupported); + return (-1); // Shut compiler up +} + +EXPORT_C TInt CSHA::BlockSize(void) +{ + User::Panic(KSHA, KErrNotSupported); + return (-1); // Shut compiler up +} + +EXPORT_C CMessageDigest* CSHA::CopyL(void) +{ + User::Panic(KSHA, KErrNotSupported); + return (NULL); // Shut compiler up +} + +EXPORT_C CMessageDigest* CSHA::ReplicateL(void) +{ + User::Panic(KSHA, KErrNotSupported); + return (NULL); // Shut compiler up +} + +EXPORT_C void CSHA::Reset(void) +{ + User::Panic(KSHA, KErrNotSupported); +} + +EXPORT_C void CSHA::Update(const TDesC8& /*aMessage*/) +{ + User::Panic(KSHA, KErrNotSupported); +} + +EXPORT_C TPtrC8 CSHA::Final(const TDesC8& /*aMessage*/) +{ + User::Panic(KSHA, KErrNotSupported); + return (KNullDesC8()); // Shut compiler up +} + +EXPORT_C TPtrC8 CSHA::Final() +{ + User::Panic(KSHA, KErrNotSupported); + return (KNullDesC8()); // Shut compiler up +} + +void CSHA::RestoreState() +{ + User::Panic(KSHA, KErrNotSupported); +} +void CSHA::StoreState() +{ + User::Panic(KSHA, KErrNotSupported); +} diff -r 7e3f204e6c81 -r f9c11be8c0b3 crypto/weakcryptospi/source/hash/sha2.cpp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/crypto/weakcryptospi/source/hash/sha2.cpp Tue Dec 01 11:12:04 2009 +0000 @@ -0,0 +1,63 @@ +/* +* Copyright (c) 2007-2009 Nokia Corporation and/or its subsidiary(-ies). +* All rights reserved. +* This component and the accompanying materials are made available +* under the terms of the License "Eclipse Public License v1.0" +* which accompanies this distribution, and is available +* at the URL "http://www.eclipse.org/legal/epl-v10.html". +* +* Initial Contributors: +* Nokia Corporation - initial contribution. +* +* Contributors: +* +* Description: +* +*/ + + +#include +#include +#include "hashshim.h" + +// +// SHA-2 implementation +// +CSHA2::CSHA2() + { + } + +EXPORT_C CSHA2* CSHA2::NewL(TSH2Algo aAlgorithmId) + { + CSHA2* self = CSHA2::NewLC(aAlgorithmId); + CleanupStack::Pop(self); + return self; + } + +EXPORT_C CSHA2* CSHA2::NewLC(TSH2Algo aAlgorithmId) + { + CSHA2* self =CSHA2Shim::NewLC(aAlgorithmId); + self->Reset(); + return self; + } + +EXPORT_C CSHA2::~CSHA2(void) + { + } + +// All these methods have been replaced by the shim +#ifdef _BullseyeCoverage +#pragma suppress_warnings on +#pragma BullseyeCoverage off +#pragma suppress_warnings off +#endif + +void CSHA2::RestoreState() + { + ASSERT(EFalse); + } + +void CSHA2::StoreState() + { + ASSERT(EFalse); + } diff -r 7e3f204e6c81 -r f9c11be8c0b3 crypto/weakcryptospi/source/padding/padding.cpp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/crypto/weakcryptospi/source/padding/padding.cpp Tue Dec 01 11:12:04 2009 +0000 @@ -0,0 +1,370 @@ +/* +* Copyright (c) 1999-2009 Nokia Corporation and/or its subsidiary(-ies). +* All rights reserved. +* This component and the accompanying materials are made available +* under the terms of the License "Eclipse Public License v1.0" +* which accompanies this distribution, and is available +* at the URL "http://www.eclipse.org/legal/epl-v10.html". +* +* Initial Contributors: +* Nokia Corporation - initial contribution. +* +* Contributors: +* +* Description: +* +*/ + + +#include +#include +#include +#include +#include + +#include "paddingshim.h" + +/* CPadding */ +CPadding::CPadding(void) : iBlockBytes(-1) + { + } + +EXPORT_C CPadding::CPadding(TInt aBlockBytes) : iBlockBytes(aBlockBytes) + { + __ASSERT_ALWAYS(aBlockBytes > 0, User::Invariant()); + } + +EXPORT_C void CPadding::SetBlockSize(TInt aBlockBytes) + { + __ASSERT_ALWAYS(aBlockBytes > 0, User::Invariant()); + iBlockBytes = aBlockBytes; + } + +EXPORT_C TInt CPadding::BlockSize(void) const + { + return iBlockBytes; + } + +EXPORT_C TInt CPadding::MaxPaddedLength(TInt /*aInputBytes*/) const + { + return BlockSize(); + } + +EXPORT_C TInt CPadding::MaxUnPaddedLength(TInt aInputBytes) const + { + return aInputBytes - MinPaddingLength(); + } + +EXPORT_C void CPadding::PadL(const TDesC8& aInput, TDes8& aOutput) + { + // Check that the input is small enough to fit inside one padded block + // Won't leave if input text is equal to blocksize. Let DoPadL handle such situations + if(aInput.Length() > BlockSize() - MinPaddingLength() + && aInput.Length() != BlockSize()) + User::Leave(KErrArgument); + + // Check that the output descriptor supplied is large enough to store the result + if(aOutput.MaxLength() < MaxPaddedLength(aInput.Length())) + User::Leave(KErrOverflow); + + // Call the virtual function, implemented by derived classes + DoPadL(aInput, aOutput); + } + +TInt CPadding::GetExtension(TUint aExtensionId, TAny*& a0, TAny* a1) + { + return Extension_(aExtensionId, a0, a1); + } + +/* CPaddingNone */ +EXPORT_C CPaddingNone* CPaddingNone::NewL(TInt aBlockBytes) + { + __ASSERT_ALWAYS(aBlockBytes > 0, User::Leave(KErrArgument)); + return CPaddingNoneShim::NewL(aBlockBytes); + } + +EXPORT_C CPaddingNone* CPaddingNone::NewLC(TInt aBlockBytes) + { + CPaddingNone* self = CPaddingNone::NewL(aBlockBytes); + CleanupStack::PushL(self); + return self; + } + +EXPORT_C CPaddingNone::CPaddingNone(TInt aBlockBytes):CPadding(aBlockBytes) + { + } + +void CPaddingNone::DoPadL(const TDesC8& aInput,TDes8& aOutput) + { + aOutput.Append(aInput); + } + +void CPaddingNone::UnPadL(const TDesC8& aInput,TDes8& aOutput) + { + __ASSERT_DEBUG(aOutput.MaxLength() >= MaxPaddedLength(aInput.Length()), User::Panic(KCryptoPanic, ECryptoPanicOutputDescriptorOverflow)); + aOutput.Append(aInput); + } + +TInt CPaddingNone::MinPaddingLength(void) const + { + return 0; + } + +TInt CPaddingNone::MaxPaddedLength(TInt aInputSize) const + { + return aInputSize; + } + +/* CPaddingSSLv3 */ +EXPORT_C CPaddingSSLv3* CPaddingSSLv3::NewL(TInt aBlockBytes) + { + __ASSERT_ALWAYS(aBlockBytes > 0, User::Leave(KErrArgument)); + return CPaddingSSLv3Shim::NewL(aBlockBytes); + } + +EXPORT_C CPaddingSSLv3* CPaddingSSLv3::NewLC(TInt aBlockBytes) + { + CPaddingSSLv3* self = CPaddingSSLv3::NewL(aBlockBytes); + CleanupStack::PushL(self); + return self; + } + +EXPORT_C CPaddingSSLv3::CPaddingSSLv3(TInt aBlockBytes):CPadding(aBlockBytes) + { + } + +void CPaddingSSLv3::DoPadL(const TDesC8& aInput,TDes8& aOutput) + { + TInt paddingBytes=BlockSize()-(aInput.Length()%BlockSize()); + aOutput.Append(aInput); + aOutput.SetLength(aOutput.Length()+paddingBytes); + for (TInt i=1;i<=paddingBytes;i++) + { + aOutput[aOutput.Length()-i]=(TUint8)(paddingBytes-1); + } + } + +void CPaddingSSLv3::UnPadL(const TDesC8& aInput,TDes8& aOutput) + { + TInt paddingLen = aInput[aInput.Length()-1] + 1; + + if (paddingLen > aInput.Length()) + { + User::Leave(KErrInvalidPadding); + } + + TInt outlen = aInput.Length() - paddingLen; + + __ASSERT_DEBUG(aOutput.MaxLength() >= outlen, User::Panic(KCryptoPanic, ECryptoPanicOutputDescriptorOverflow)); + + aOutput.Append(aInput.Left(outlen)); + } + +TInt CPaddingSSLv3::MinPaddingLength(void) const + { + //if aInputBytes is 1 less than the blocksize then we get 1 byte of padding + return 1; + } + +TInt CPaddingSSLv3::MaxPaddedLength(TInt aInputBytes) const + { + TUint padBytes = BlockSize() - (aInputBytes % BlockSize()); + return padBytes + aInputBytes; + } + +/* CPaddingPKCS1Signature */ +EXPORT_C CPaddingPKCS1Signature* CPaddingPKCS1Signature::NewL(TInt aBlockBytes) + { + return CPaddingPKCS1SignatureShim::NewL(aBlockBytes); + } + +EXPORT_C CPaddingPKCS1Signature* CPaddingPKCS1Signature::NewLC(TInt aBlockBytes) + { + CPaddingPKCS1Signature* self = CPaddingPKCS1Signature::NewL(aBlockBytes); + CleanupStack::PushL(self); + return self; + } + +EXPORT_C CPaddingPKCS1Signature::CPaddingPKCS1Signature(TInt aBlockBytes) + : CPadding(aBlockBytes) + { + } + +void CPaddingPKCS1Signature::DoPadL(const TDesC8& aInput,TDes8& aOutput) + { + aOutput.SetLength(BlockSize()); + TInt i; + TInt j; + aOutput[0]=0; + TInt startOfData=BlockSize()-aInput.Length(); + // PKCS1 also specifies a block type 0 for private key operations but + // does not recommend its use. This block type (0) is compatible with + // unpadded data though so you can create PKCS1 type 0 blocks using + // CPaddingNone. + aOutput[1]=1; // Block type 1 (private key operation) + for (i=2;i<(startOfData-1);i++) + { + aOutput[i]=0xff; + } + j=0; + aOutput[startOfData-1]=0; // separator + for (i=startOfData;i= len, User::Panic(KCryptoPanic, ECryptoPanicOutputDescriptorOverflow)); + + aOutput.SetLength(len); + TInt i=0; + while (dataStart , 0x00 + } + +/* CPaddingPKCS1Encryption */ +EXPORT_C CPaddingPKCS1Encryption* CPaddingPKCS1Encryption::NewL( + TInt aBlockBytes) + { + return CPaddingPKCS1EncryptionShim::NewL(aBlockBytes); + } + +EXPORT_C CPaddingPKCS1Encryption* CPaddingPKCS1Encryption::NewLC( + TInt aBlockBytes) + { + CPaddingPKCS1Encryption* self = CPaddingPKCS1Encryption::NewL(aBlockBytes); + CleanupStack::PushL(self); + return self; + } + +EXPORT_C CPaddingPKCS1Encryption::CPaddingPKCS1Encryption(TInt aBlockBytes) + : CPadding(aBlockBytes) + { + } + +void CPaddingPKCS1Encryption::DoPadL(const TDesC8& aInput,TDes8& aOutput) + { + aOutput.SetLength(BlockSize()); + + aOutput[0]=0; + TInt startOfData=BlockSize()-aInput.Length(); + aOutput[1]=2; // Block type 2 (public key operation) + TBuf8<256> rnd(256); + GenerateRandomBytesL(rnd); + + TInt i = 2; + TInt j = 0; + for (; i<(startOfData-1);) + { + if (rnd[j]) + { + aOutput[i++]=rnd[j]; + } + if (++j==256) + { + GenerateRandomBytesL(rnd); + j=0; + } + } + + j=0; + aOutput[startOfData-1]=0; // separator + for (i=startOfData;i= len, User::Panic(KCryptoPanic, ECryptoPanicOutputDescriptorOverflow)); + + aOutput.SetLength(len); + TInt i=0; + while (dataStart, 0x00 + } diff -r 7e3f204e6c81 -r f9c11be8c0b3 crypto/weakcryptospi/source/padding/paddingshim.cpp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/crypto/weakcryptospi/source/padding/paddingshim.cpp Tue Dec 01 11:12:04 2009 +0000 @@ -0,0 +1,190 @@ +/* +* Copyright (c) 2006-2009 Nokia Corporation and/or its subsidiary(-ies). +* All rights reserved. +* This component and the accompanying materials are made available +* under the terms of the License "Eclipse Public License v1.0" +* which accompanies this distribution, and is available +* at the URL "http://www.eclipse.org/legal/epl-v10.html". +* +* Initial Contributors: +* Nokia Corporation - initial contribution. +* +* Contributors: +* +* Description: +* +*/ + + +#include "paddingshim.h" +#include + +// CPaddingNoneShim +CPaddingNoneShim* CPaddingNoneShim::NewL(TInt aBlockBytes) + { + CPaddingNoneShim* self = CPaddingNoneShim::NewLC(aBlockBytes); + CleanupStack::Pop(self); + return self; + } +CPaddingNoneShim* CPaddingNoneShim::NewLC(TInt aBlockBytes) + { + CPaddingNoneShim* self = new(ELeave) CPaddingNoneShim(aBlockBytes); + CleanupStack::PushL(self); + return self; + } + +TInt CPaddingNoneShim::Extension_(TUint aExtensionId, TAny*& a0, TAny* /*a1*/) + { + TInt err(KErrNone); + if (aExtensionId == CryptoSpi::KPaddingInterface) + { + TUid* uid(static_cast(a0)); + *uid = CryptoSpi::KPaddingModeNoneUid; + } + else + { + err = KErrExtensionNotSupported; + } + return err; + } + +CPaddingNoneShim::CPaddingNoneShim(TInt aBlockBytes) : + CPaddingNone(aBlockBytes) + { + } + +// CPaddingPKCS1SignatureShim +CPaddingPKCS1SignatureShim* CPaddingPKCS1SignatureShim::NewL(TInt aBlockBytes) + { + CPaddingPKCS1SignatureShim* self = CPaddingPKCS1SignatureShim::NewLC(aBlockBytes); + CleanupStack::Pop(self); + return self; + } +CPaddingPKCS1SignatureShim* CPaddingPKCS1SignatureShim::NewLC(TInt aBlockBytes) + { + CPaddingPKCS1SignatureShim* self = new(ELeave) CPaddingPKCS1SignatureShim(aBlockBytes); + CleanupStack::PushL(self); + return self; + } + +TInt CPaddingPKCS1SignatureShim::Extension_(TUint aExtensionId, TAny*& a0, TAny* /*a1*/) + { + TInt err(KErrNone); + if (aExtensionId == CryptoSpi::KPaddingInterface) + { + TUid* uid(static_cast(a0)); + *uid = CryptoSpi::KPaddingModePkcs1_v1_5_SignatureUid; + } + else + { + err = KErrExtensionNotSupported; + } + return err; + } + +CPaddingPKCS1SignatureShim::CPaddingPKCS1SignatureShim(TInt aBlockBytes) : + CPaddingPKCS1Signature(aBlockBytes) + { + } + +// CPaddingPKCS1EncryptionShim +CPaddingPKCS1EncryptionShim* CPaddingPKCS1EncryptionShim::NewL(TInt aBlockBytes) + { + CPaddingPKCS1EncryptionShim* self = CPaddingPKCS1EncryptionShim::NewLC(aBlockBytes); + CleanupStack::Pop(self); + return self; + } +CPaddingPKCS1EncryptionShim* CPaddingPKCS1EncryptionShim::NewLC(TInt aBlockBytes) + { + CPaddingPKCS1EncryptionShim* self = new(ELeave) CPaddingPKCS1EncryptionShim(aBlockBytes); + CleanupStack::PushL(self); + return self; + } + +TInt CPaddingPKCS1EncryptionShim::Extension_(TUint aExtensionId, TAny*& a0, TAny* /*a1*/) + { + TInt err(KErrNone); + if (aExtensionId == CryptoSpi::KPaddingInterface) + { + TUid* uid(static_cast(a0)); + *uid = CryptoSpi::KPaddingModePkcs1_v1_5_EncryptionUid; + } + else + { + err = KErrExtensionNotSupported; + } + return err; + } + +CPaddingPKCS1EncryptionShim::CPaddingPKCS1EncryptionShim(TInt aBlockBytes) : + CPaddingPKCS1Encryption(aBlockBytes) + { + } + +// CPaddingSSLv3Shim +CPaddingSSLv3Shim* CPaddingSSLv3Shim::NewL(TInt aBlockBytes) + { + CPaddingSSLv3Shim* self = CPaddingSSLv3Shim::NewLC(aBlockBytes); + CleanupStack::Pop(self); + return self; + } +CPaddingSSLv3Shim* CPaddingSSLv3Shim::NewLC(TInt aBlockBytes) + { + CPaddingSSLv3Shim* self = new(ELeave) CPaddingSSLv3Shim(aBlockBytes); + CleanupStack::PushL(self); + return self; + } + +TInt CPaddingSSLv3Shim::Extension_(TUint aExtensionId, TAny*& a0, TAny* /*a1*/) + { + TInt err(KErrNone); + if (aExtensionId == CryptoSpi::KPaddingInterface) + { + TUid* uid(static_cast(a0)); + *uid = CryptoSpi::KPaddingModeSSLv3Uid; + } + else + { + err = KErrExtensionNotSupported; + } + return err; + } + +CPaddingSSLv3Shim::CPaddingSSLv3Shim(TInt aBlockBytes) : + CPaddingSSLv3(aBlockBytes) + { + } + +// CPaddingPKCS7Shim +CPaddingPKCS7Shim* CPaddingPKCS7Shim::NewL(TInt aBlockBytes) + { + CPaddingPKCS7Shim* self = CPaddingPKCS7Shim::NewLC(aBlockBytes); + CleanupStack::Pop(self); + return self; + } +CPaddingPKCS7Shim* CPaddingPKCS7Shim::NewLC(TInt aBlockBytes) + { + CPaddingPKCS7Shim* self = new(ELeave) CPaddingPKCS7Shim(aBlockBytes); + CleanupStack::PushL(self); + return self; + } + +TInt CPaddingPKCS7Shim::Extension_(TUint aExtensionId, TAny*& a0, TAny* /*a1*/) + { + TInt err(KErrNone); + if (aExtensionId == CryptoSpi::KPaddingInterface) + { + TUid* uid(static_cast(a0)); + *uid = CryptoSpi::KPaddingModePKCS7Uid; + } + else + { + err = KErrExtensionNotSupported; + } + return err; + } + +CPaddingPKCS7Shim::CPaddingPKCS7Shim(TInt aBlockBytes) : + CPaddingPKCS7(aBlockBytes) + { + } diff -r 7e3f204e6c81 -r f9c11be8c0b3 crypto/weakcryptospi/source/padding/paddingshim.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/crypto/weakcryptospi/source/padding/paddingshim.h Tue Dec 01 11:12:04 2009 +0000 @@ -0,0 +1,169 @@ +/* +* Copyright (c) 2006-2009 Nokia Corporation and/or its subsidiary(-ies). +* All rights reserved. +* This component and the accompanying materials are made available +* under the terms of the License "Eclipse Public License v1.0" +* which accompanies this distribution, and is available +* at the URL "http://www.eclipse.org/legal/epl-v10.html". +* +* Initial Contributors: +* Nokia Corporation - initial contribution. +* +* Contributors: +* +* Description: +* +*/ + + +#ifndef __PADDINGSHIM_H__ +#define __PADDINGSHIM_H__ + +/** +@file +@internalComponent +@released +*/ + +#include + +/** +Shim class for CPaddingNone. This should only be created by CPaddingNone. +*/ +NONSHARABLE_CLASS(CPaddingNoneShim) : public CPaddingNone + { +public: + static CPaddingNoneShim* NewL(TInt aBlockBytes); + static CPaddingNoneShim* NewLC(TInt aBlockBytes); + +protected: + // From CBase + /** + Used by the CBufferedTransformShim class to determine the type of + the padding mode selected. The SPI plug-in is then configured to use + the selected padding mdoe. + + @param aExtensionId The requested interface + @param a0 Not used. This function does NOT return a real interface. + @param a1 Not used. + @return KErrNone if aExtensionId is CryptoSpi::KPaddingModeNoneUid; + otherwise, KErrNotFound is returned. + */ + TInt Extension_(TUint aExtensionId, TAny*& a0, TAny* a1); +private: + CPaddingNoneShim(TInt aBlockBytes); + }; + +/** +Shim class for CPaddingPKCS1Signature. This should only be created by +CPaddingPKCS1Signature. +*/ +NONSHARABLE_CLASS(CPaddingPKCS1SignatureShim) : public CPaddingPKCS1Signature + { +public: + static CPaddingPKCS1SignatureShim* NewL(TInt aBlockBytes); + static CPaddingPKCS1SignatureShim* NewLC(TInt aBlockBytes); + +protected: + // From CBase + /** + Used by the CBufferedTransformShim class to determine the type of + the padding mode selected. The SPI plug-in is then configured to use + the selected padding mdoe. + + @param aExtensionId The requested interface + @param a0 Not used. This function does NOT return a real interface. + @param a1 Not used. + @return KErrNone if aExtensionId is CryptoSpi::KPaddingModeNoneUid; + otherwise, KErrNotFound is returned. + */ + TInt Extension_(TUint aExtensionId, TAny*& a0, TAny* a1); +private: + CPaddingPKCS1SignatureShim(TInt aBlockBytes); + }; + +/** +Shim class for CPaddingPKCS1Encryption. This should only be created by +CPaddingPKCS1Encryption. +*/ +NONSHARABLE_CLASS(CPaddingPKCS1EncryptionShim) : public CPaddingPKCS1Encryption + { +public: + static CPaddingPKCS1EncryptionShim* NewL(TInt aBlockBytes); + static CPaddingPKCS1EncryptionShim* NewLC(TInt aBlockBytes); + +protected: + // From CBase + /** + Used by the CBufferedTransformShim class to determine the type of + the padding mode selected. The SPI plug-in is then configured to use + the selected padding mdoe. + + @param aExtensionId The requested interface + @param a0 Not used. This function does NOT return a real interface. + @param a1 Not used. + @return KErrNone if aExtensionId is CryptoSpi::KPaddingModeNoneUid; + otherwise, KErrNotFound is returned. + */ + TInt Extension_(TUint aExtensionId, TAny*& a0, TAny* a1); +private: + CPaddingPKCS1EncryptionShim(TInt aBlockBytes); + }; + +/** +Shim class for CPaddingSSLv3. This should only be created by +CPaddingSSLv3. +*/ +NONSHARABLE_CLASS(CPaddingSSLv3Shim) : public CPaddingSSLv3 + { +public: + static CPaddingSSLv3Shim* NewL(TInt aBlockBytes); + static CPaddingSSLv3Shim* NewLC(TInt aBlockBytes); + +protected: + // From CBase + /** + Used by the CBufferedTransformShim class to determine the type of + the padding mode selected. The SPI plug-in is then configured to use + the selected padding mdoe. + + @param aExtensionId The requested interface + @param a0 Not used. This function does NOT return a real interface. + @param a1 Not used. + @return KErrNone if aExtensionId is CryptoSpi::KPaddingModeNoneUid; + otherwise, KErrNotFound is returned. + */ + TInt Extension_(TUint aExtensionId, TAny*& a0, TAny* a1); +private: + CPaddingSSLv3Shim(TInt aBlockBytes); + }; + +/** +Shim class for CPaddingPKCS7. This should only be created by +CPaddingPKCS7. +*/ +NONSHARABLE_CLASS(CPaddingPKCS7Shim) : public CPaddingPKCS7 + { +public: + static CPaddingPKCS7Shim* NewL(TInt aBlockBytes); + static CPaddingPKCS7Shim* NewLC(TInt aBlockBytes); + +protected: + // From CBase + /** + Used by the CBufferedTransformShim class to determine the type of + the padding mode selected. The SPI plug-in is then configured to use + the selected padding mdoe. + + @param aExtensionId The requested interface + @param a0 Not used. This function does NOT return a real interface. + @param a1 Not used. + @return KErrNone if aExtensionId is CryptoSpi::KPaddingModeNoneUid; + otherwise, KErrNotFound is returned. + */ + TInt Extension_(TUint aExtensionId, TAny*& a0, TAny* a1); +private: + CPaddingPKCS7Shim(TInt aBlockBytes); + }; + +#endif // __PADDINGSHIM_H__ diff -r 7e3f204e6c81 -r f9c11be8c0b3 crypto/weakcryptospi/source/padding/pkcs7.cpp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/crypto/weakcryptospi/source/padding/pkcs7.cpp Tue Dec 01 11:12:04 2009 +0000 @@ -0,0 +1,91 @@ +/* +* Copyright (c) 2003-2009 Nokia Corporation and/or its subsidiary(-ies). +* All rights reserved. +* This component and the accompanying materials are made available +* under the terms of the License "Eclipse Public License v1.0" +* which accompanies this distribution, and is available +* at the URL "http://www.eclipse.org/legal/epl-v10.html". +* +* Initial Contributors: +* Nokia Corporation - initial contribution. +* +* Contributors: +* +* Description: +* +*/ + + +#include +#include +#include +#include + +#include "paddingshim.h" + +/* CPaddingPKCS7 */ +EXPORT_C CPaddingPKCS7* CPaddingPKCS7::NewL(TInt aBlockBytes) + { + __ASSERT_ALWAYS(aBlockBytes > 0, User::Leave(KErrArgument)); + return CPaddingPKCS7Shim::NewL(aBlockBytes); + } + +EXPORT_C CPaddingPKCS7* CPaddingPKCS7::NewLC(TInt aBlockBytes) + { + CPaddingPKCS7* self = CPaddingPKCS7::NewL(aBlockBytes); + CleanupStack::PushL(self); + return self; + } + +EXPORT_C CPaddingPKCS7::CPaddingPKCS7(TInt aBlockBytes):CPadding(aBlockBytes) + { + } + +void CPaddingPKCS7::DoPadL(const TDesC8& aInput,TDes8& aOutput) + { + TInt paddingBytes = BlockSize()-(aInput.Length()%BlockSize()); + aOutput.Append(aInput); + aOutput.SetLength(aOutput.Length()+paddingBytes); + for (TInt i=1;i<=paddingBytes;i++) + { + aOutput[aOutput.Length()-i]=(TUint8)(paddingBytes); + } + } + +void CPaddingPKCS7::UnPadL(const TDesC8& aInput,TDes8& aOutput) + { + TUint inputLen = aInput.Length(); + TUint paddingLen = (TUint)(aInput[inputLen - 1]); + + if (paddingLen > inputLen) + { + User::Leave(KErrInvalidPadding); + } + + TInt outlen = aInput.Length() - paddingLen; + + __ASSERT_DEBUG(aOutput.MaxLength() >= outlen, User::Panic(KCryptoPanic, ECryptoPanicOutputDescriptorOverflow)); + + aOutput.Append(aInput.Left(outlen)); + for (TInt i=outlen;i +#include +#include +#include +#include +#include "pkcs5kdf.h" +#include "pbe.h" +#include +#include "pbesymmetricfactory.h" + +EXPORT_C CPBEncryptElement* CPBEncryptElement::NewL(const TPBPassword& aPassword) + { + CPBEncryptElement* self = NewLC(aPassword); + CleanupStack::Pop(); + return self; + } + +EXPORT_C CPBEncryptElement* CPBEncryptElement::NewLC(const TPBPassword& aPassword) + { + CPBEncryptElement* self = new(ELeave) CPBEncryptElement; + CleanupStack::PushL(self); + self->ConstructL(aPassword.Password()); + return self; + } + +EXPORT_C CPBEncryptElement* CPBEncryptElement::NewL(const TPBPassword& aPassword, + const TPBECipher aCipher) + { + CPBEncryptElement* self = NewLC(aPassword, aCipher); + CleanupStack::Pop(); + return self; + } + +EXPORT_C CPBEncryptElement* CPBEncryptElement::NewLC(const TPBPassword& aPassword, + const TPBECipher aCipher) + { + CPBEncryptElement* self = new(ELeave) CPBEncryptElement; + CleanupStack::PushL(self); + self->ConstructL(aPassword.Password(), aCipher); + return self; + } + +EXPORT_C CPBEncryptElement* CPBEncryptElement::NewL(const TPBPassword& aPassword, + const CPBEncryptParms& aParms) + { + CPBEncryptElement* self = NewLC(aPassword, aParms); + CleanupStack::Pop(); + return self; + } + +EXPORT_C CPBEncryptElement* CPBEncryptElement::NewLC(const TPBPassword& aPassword, + const CPBEncryptParms& aParms) + { + CPBEncryptElement* self = new(ELeave) CPBEncryptElement; + CleanupStack::PushL(self); + self->ConstructL(aPassword.Password(), aParms); + return self; + } + +EXPORT_C CPBEncryptElement* CPBEncryptElement::NewL( + const CPBEncryptionData& aData, const TPBPassword& aPassword) + { + CPBEncryptElement* self = CPBEncryptElement::NewLC(aData, aPassword); + CleanupStack::Pop(); + return self; + } + +EXPORT_C CPBEncryptElement* CPBEncryptElement::NewLC( + const CPBEncryptionData& aData, const TPBPassword& aPassword) + { + CPBEncryptElement* self = new(ELeave) CPBEncryptElement; + CleanupStack::PushL(self); + self->ConstructL(aData, aPassword); + return self; + } + +CPBEncryptElement::CPBEncryptElement(void) + { + } + +CPBEncryptElement::~CPBEncryptElement(void) + { + delete iData; + delete iEncryptKey; + } + +void CPBEncryptElement::ConstructL(const TDesC8& aPassword) + { + // Construct based on cryptography strength + if (TCrypto::Strength() == TCrypto::EStrong) + { + ConstructL(aPassword, KPBEDefaultStrongCipher); + } + else + { + ConstructL(aPassword, KPBEDefaultWeakCipher); + } + } + +void CPBEncryptElement::ConstructL(const TDesC8& aPassword, TPBECipher aCipher) + { + TBuf8 iv(KPBEMaxCipherIVBytes); + iv.SetLength(PBE::GetBlockBytes(aCipher)); + TRandom::RandomL(iv); + + TBuf8 encryptSalt(KPBEDefaultSaltBytes); + TRandom::RandomL(encryptSalt); + + TBuf8 authSalt(KPBEDefaultSaltBytes); + TRandom::RandomL(authSalt); + + iData = CPBEncryptionData::NewL(aPassword, aCipher, authSalt, encryptSalt, + iv, KDefaultIterations); + + MakeEncryptKeyL(PBE::GetKeyBytes(aCipher), aPassword); + } + +void CPBEncryptElement::ConstructL(const CPBEncryptionData& aData, + const TPBPassword& aPassword) + { + iData = CPBEncryptionData::NewL(aData); + if(!AuthenticateL(aPassword)) + { + User::Leave(KErrBadPassphrase); + } + } + +void CPBEncryptElement::ConstructL(const TDesC8& aPassword, + const CPBEncryptParms& aParms) + { + TUint keySize = PBE::GetKeyBytes(aParms.Cipher()); + + TBuf8 authSalt(KPBEDefaultSaltBytes); + TRandom::RandomL(authSalt); + + //Recreate parms with given data and create a totally new auth + iData = CPBEncryptionData::NewL(aPassword, authSalt, aParms); + MakeEncryptKeyL(keySize, aPassword); + } + +const CPBEncryptionData& CPBEncryptElement::EncryptionData(void) const + { + return *iData; + } + +CPBEncryptor* CPBEncryptElement::NewEncryptL() const + { + CPBEncryptor* encryptor = NewEncryptLC(); + CleanupStack::Pop(); + return encryptor; + } + +CPBEncryptor* CPBEncryptElement::NewEncryptLC() const + { + CPBEncryptor* encryptor = CPBEncryptorElement::NewLC( + iData->EncryptParms().Cipher(), *iEncryptKey, + iData->EncryptParms().IV()); + return encryptor; + } + +TBool CPBEncryptElement::AuthenticateL(const TPBPassword& aPassword) + { + TBool retval = EFalse; + + //create a new auth to test against the existing one + //therefore we use the same key size, and salt as the current one + CPBAuthData* auth = CPBAuthData::NewLC(aPassword.Password(), + iData->AuthData().Salt(), iData->AuthData().Key().Size(), + iData->AuthData().Iterations()); + if(*auth==iData->AuthData()) + { + //We've got a valid password, regenerate the key so they can decrypt + //stuff. We don't the change the length of iEncryptKey as we assume the + //previous key size is appropriate for the new one + MakeEncryptKeyL(PBE::GetKeyBytes(iData->EncryptParms().Cipher()), + aPassword.Password()); + retval = ETrue; + } + CleanupStack::PopAndDestroy(auth); + return retval; + } + +CPBDecryptor* CPBEncryptElement::NewDecryptL() const + { + CPBDecryptor* decryptor = NewDecryptLC(); + CleanupStack::Pop(); + return decryptor; + } + +CPBDecryptor* CPBEncryptElement::NewDecryptLC() const + { + CPBDecryptor* decryptor = CPBDecryptorElement::NewLC( + iData->EncryptParms().Cipher(), *iEncryptKey, + iData->EncryptParms().IV()); + return decryptor; + } + +// Warning: This function is only valid BEFORE you call NewEncryptL +// After creating the cipher, ask it about itself, not me! +// This is _very_ dodgy as I assume all sorts of things about the encryptor. +// 1) That it uses SSLv3 or similar style padding +// 2) That it stores the IV for that stream at the front. +// This is here for specific application that requires this and aren't able to +// actually construct the cipher and ask it. In almost all other cases you +// should construct the cipher and ask it. +TInt CPBEncryptElement::MaxCiphertextLength(TInt aPlaintextLength) const + { + TUint blocksize = PBE::GetBlockBytes(iData->EncryptParms().Cipher()); + TUint padding = blocksize - aPlaintextLength % blocksize; + //len = inputLength + padding + return aPlaintextLength + padding; + } + +// Warning: This function is only valid BEFORE you call NewDecryptL +// After creating the cipher, ask it about itself, not me! +TInt CPBEncryptElement::MaxPlaintextLength(TInt aCiphertextLength) const + { + /*It's impossible to determine anything about how much padding will be + * removed. So we'll return a max length that is longer than will + * ever happen by at most a blocksize - 1. + */ + //totallength = inputlength - 1 byte of padding min + return aCiphertextLength - 1; + } + +void CPBEncryptElement::MakeEncryptKeyL(TUint aKeySize, const TDesC8& aPassword) + { + iEncryptKey = HBufC8::NewMaxL(aKeySize); + TPtr8 encryptKeyBuf = iEncryptKey->Des(); + iData->EncryptParms().DeriveKeyL(aPassword, encryptKeyBuf); + } + +EXPORT_C TPBPassword::TPBPassword(const TDesC8& aPassword) + { + iPassword.Set(aPassword); + } + +EXPORT_C TPBPassword::TPBPassword(const TDesC16& aPassword) + { + iPassword.Set(reinterpret_cast(aPassword.Ptr()), aPassword.Size()); + } + +EXPORT_C const TDesC8& TPBPassword::Password(void) const + { + return iPassword; + } + + diff -r 7e3f204e6c81 -r f9c11be8c0b3 crypto/weakcryptospi/source/pbe/pbedata.cpp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/crypto/weakcryptospi/source/pbe/pbedata.cpp Tue Dec 01 11:12:04 2009 +0000 @@ -0,0 +1,482 @@ +/* +* Copyright (c) 2002-2009 Nokia Corporation and/or its subsidiary(-ies). +* All rights reserved. +* This component and the accompanying materials are made available +* under the terms of the License "Eclipse Public License v1.0" +* which accompanies this distribution, and is available +* at the URL "http://www.eclipse.org/legal/epl-v10.html". +* +* Initial Contributors: +* Nokia Corporation - initial contribution. +* +* Contributors: +* +* Description: +* +*/ + + + +#include "pkcs5kdf.h" +#include "pkcs12kdf.h" +#include "pbedata.h" +#include "pbesymmetricfactory.h" +#include "cryptostrength.h" + +EXPORT_C CPBEncryptionData* CPBEncryptionData::NewL(const TDesC8& aPassword, + TPBECipher aCipher, const TDesC8& aAuthSalt, + const TDesC8& aEncryptSalt, const TDesC8& aIV, TUint aIterations) + { + CPBEncryptionData* self = NewLC(aPassword, aCipher, aAuthSalt, aEncryptSalt, + aIV, aIterations); + CleanupStack::Pop(self); + return self; + } + +EXPORT_C CPBEncryptionData* CPBEncryptionData::NewLC(const TDesC8& aPassword, + TPBECipher aCipher, const TDesC8& aAuthSalt, + const TDesC8& aEncryptSalt, const TDesC8& aIV, TUint aIterations) + { + CPBEncryptionData* self = new(ELeave)CPBEncryptionData(); + CleanupStack::PushL(self); + self->ConstructL(aPassword, aCipher, aAuthSalt, aEncryptSalt, aIV, + aIterations); + return self; + } + +EXPORT_C CPBEncryptionData* CPBEncryptionData::NewL( + const CPBEncryptionData& aData) + { + CPBEncryptionData* self = NewLC(aData); + CleanupStack::Pop(self); + return self; + } + +EXPORT_C CPBEncryptionData* CPBEncryptionData::NewLC( + const CPBEncryptionData& aData) + { + CPBEncryptionData* self = new(ELeave)CPBEncryptionData(); + CleanupStack::PushL(self); + self->ConstructL(aData); + return self; + } + +EXPORT_C CPBEncryptionData* CPBEncryptionData::NewL( + const TDesC8& aPassword, const TDesC8& aAuthSalt, + const CPBEncryptParms& aParms) +/** + This factory function takes the user-supplied password + and the randomly-generated authentication salt, along + with the encryption paramaters. It is provided so the + encryption parameters can be extended without having to + provide multiple factory functions. + + @param aPassword User-supplied password. This + password is not transformed so + if it needs to be in a particular + format, e.g. for PKCS#12, the + transformation must be applied before + this function is called. + @param aAuthSalt The salt is used to derive the + authentication key; not the encryption + key. + @param aParms Encryption parameters describe how the + data is encrypted. + @return New instance of CPBEncryptionData. + */ + { + CPBEncryptionData* self = new(ELeave) CPBEncryptionData; + CleanupStack::PushL(self); + self->ConstructL(aPassword, aAuthSalt, aParms); + CleanupStack::Pop(self); + return self; + } + +void CPBEncryptionData::ConstructL( + const TDesC8& aPassword, const TDesC8& aAuthSalt, + const CPBEncryptParms& aParms) +/** + Second-phase constructor for factory function with + same signature. + */ + { + iParms = CPBEncryptParms::NewL(aParms); + iAuth = CPBAuthData::NewL( + aPassword, + aAuthSalt, + PBE::GetKeyBytes(aParms.Cipher()), + aParms.Iterations()); + } + +// HPRE-5TDFK2: Remove Store/estor.dll dependency on Cryptography/pbe.dll +// This method is DUPLICATED in common/generic/syslibs/store/ucrypt/ue_strm.cpp +EXPORT_C CPBEncryptionData::CPBEncryptionData(void) + { + } + +// HPRE-5TDFK2: Remove Store/estor.dll dependency on Cryptography/pbe.dll +// This method is DUPLICATED in common/generic/syslibs/store/ucrypt/ue_strm.cpp +CPBEncryptionData::~CPBEncryptionData(void) + { + delete iParms; + delete iAuth; + } + +void CPBEncryptionData::ConstructL(const TDesC8& aPassword, + TPBECipher aCipher, const TDesC8& aAuthSalt, + const TDesC8& aEncryptSalt, const TDesC8& aIV, TUint aIterations) + { + iParms = CPBEncryptParms::NewL(aCipher, aEncryptSalt, aIV, aIterations); + iAuth = CPBAuthData::NewL(aPassword, aAuthSalt, + PBE::GetKeyBytes(aCipher), aIterations); + } + +void CPBEncryptionData::ConstructL(const CPBEncryptionData& aData) + { + iParms = CPBEncryptParms::NewL(aData.EncryptParms()); + iAuth = CPBAuthData::NewL(aData.AuthData()); + } + +EXPORT_C const CPBEncryptParms& CPBEncryptionData::EncryptParms(void) const + { + return *iParms; + } +EXPORT_C const CPBAuthData& CPBEncryptionData::AuthData(void) const + { + return *iAuth; + } + +/* CPBEncryptParms */ +EXPORT_C CPBEncryptParms* CPBEncryptParms::NewL() +/** + This factory function allocates an encryption + parameters object with default settings. The + individual settings can be retrieved and modified + with the accessor and mutator functions after + this object has been created. + + This factory function is provided so that individual + parameters can be modified without providing many + factory functions. + + @return New instance of CPBEncryptParms. + */ + { + CPBEncryptParms* self = NewLC(); + CleanupStack::Pop(self); + return self; + } + +EXPORT_C CPBEncryptParms* CPBEncryptParms::NewLC() +/** + Similar to the NewL overload which takes no + arguments, this function additionally puts the + allocated instance of CPBEncryptParms on the + cleanup stack. + + @return New instance of CPBEncryptParms. + */ + { + CPBEncryptParms* self = new(ELeave) CPBEncryptParms; + CleanupStack::PushL(self); + self->ConstructL(); + return self; + } + +void CPBEncryptParms::ConstructL() +/** + Initialize this object with default cipher, kdf (PKCS#5,) + salt length, iteration count, and IV. + */ + { + iData = new(ELeave) TParamsData; + iData->iKdf = EKdfPkcs5; + + iSalt = HBufC8::NewMaxL(KPBEDefaultSaltBytes); + TPtr8 saltDes = iSalt->Des(); + TRandom::RandomL(saltDes); + + iIterations = KDefaultIterations; + + iIV = HBufC8::NewMaxL(KPBEMaxCipherIVBytes); + + SetCipher( + (TCrypto::Strength() == TCrypto::EStrong) + ? KPBEDefaultStrongCipher : KPBEDefaultWeakCipher ); + } + +EXPORT_C CPBEncryptParms* CPBEncryptParms::NewL(TPBECipher aCipher, + const TDesC8& aSalt, const TDesC8& aIV, TUint aIterations) + { + CPBEncryptParms* self = NewLC(aCipher, aSalt, aIV, aIterations); + CleanupStack::Pop(self); + return self; + } + +EXPORT_C CPBEncryptParms* CPBEncryptParms::NewLC(TPBECipher aCipher, + const TDesC8& aSalt, const TDesC8& aIV, TUint aIterations) + { + CPBEncryptParms* self = new(ELeave)CPBEncryptParms(); + CleanupStack::PushL(self); + self->ConstructL(aCipher, aSalt, aIV, aIterations); + return self; + } + +EXPORT_C CPBEncryptParms* CPBEncryptParms::NewL(const CPBEncryptParms& aParms) + { + CPBEncryptParms* self = NewLC(aParms); + CleanupStack::Pop(self); + return self; + } + +EXPORT_C CPBEncryptParms* CPBEncryptParms::NewLC(const CPBEncryptParms& aParms) + { + CPBEncryptParms* self = new(ELeave)CPBEncryptParms(); + CleanupStack::PushL(self); + self->ConstructL(aParms); + return self; + } + +// HPRE-5TDFK2: Remove Store/estor.dll dependency on Cryptography/pbe.dll +// This method is DUPLICATED in common/generic/syslibs/store/ucrypt/ue_strm.cpp +EXPORT_C CPBEncryptParms::CPBEncryptParms() + { + } + +// HPRE-5TDFK2: Remove Store/estor.dll dependency on Cryptography/pbe.dll +// This method is DUPLICATED in common/generic/syslibs/store/ucrypt/ue_strm.cpp +CPBEncryptParms::~CPBEncryptParms() + { + delete iData; + delete iSalt; + delete iIV; + } + +void CPBEncryptParms::ConstructL(TPBECipher aCipher, const TDesC8& aSalt, + const TDesC8& aIV, TUint aIterations) + { + iData = new(ELeave) TParamsData; + iData->iCipher = aCipher; + iData->iKdf = EKdfPkcs5; + iSalt = aSalt.AllocL(); + iIV = aIV.AllocL(); + iIterations = aIterations; + } + +void CPBEncryptParms::ConstructL(const CPBEncryptParms& aParms) + { + iData = new(ELeave) TParamsData; + iData->iCipher = aParms.Cipher(); + iData->iKdf = aParms.iData->iKdf; + iSalt = aParms.Salt().AllocL(); + iIterations = aParms.Iterations(); + iIV = aParms.IV().AllocL(); + } + +EXPORT_C TPBECipher CPBEncryptParms::Cipher() const + { + return iData->iCipher; + } + +EXPORT_C void CPBEncryptParms::SetCipher(TPBECipher aCipher) + /** + * Replace the current cipher. This function resizes the + * IV and replaces its existing contents. + * + * @param aCipher New cipher. + * + * @deprecated Use SetCipherL instead. + * @see SetCipherL + */ + { + TPtr8 ivDes = iIV->Des(); + ivDes.SetLength(PBE::GetBlockBytes(aCipher)); + TRandom::RandomL(ivDes); + + iData->iCipher = aCipher; + } + +EXPORT_C CPBEncryptParms::TKdf CPBEncryptParms::Kdf() const +/** + Accessor function returns the key derivation function + (KDF) specified by this object. + + @return KDF specified by this object. + */ + { + return iData->iKdf; + } + +EXPORT_C void CPBEncryptParms::SetKdf(CPBEncryptParms::TKdf aKdf) +/** + Replace the current key derivation function. + + @param aKdf Key derivation function. + */ + { + iData->iKdf = aKdf; + } + +EXPORT_C TPtrC8 CPBEncryptParms::Salt() const + { + return TPtrC8(*iSalt); + } + +EXPORT_C void CPBEncryptParms::ResizeSaltL(TInt aNewLen) +/** + Resize the current salt and replace its contents. + + @param aNewLen New salt length. + */ + { + iSalt = iSalt->ReAllocL(aNewLen); + TPtr8 saltDes = iSalt->Des(); + TRandom::RandomL(saltDes); + } + +EXPORT_C TInt CPBEncryptParms::Iterations() const + { + return iIterations; + } + +EXPORT_C void CPBEncryptParms::SetIterations(TInt aIterCount) +/** + Replace the current iteration count with the supplied value. + + @param aIterCount Number of iterations to apply in + the KDF. + */ + { + ASSERT(aIterCount >= 0); + iIterations = aIterCount; + } + +EXPORT_C TPtrC8 CPBEncryptParms::IV() const + { + return TPtrC8(*iIV); + } + +EXPORT_C void CPBEncryptParms::SetIV(const TDesC8& aNewIv) +/** + Replace the initialization vector. + + @param aNewIv New initialization vector length. + This must have no more than + KPBEMaxCipherIVBytes bytes. + */ + { + iIV->Des().Copy(aNewIv); + } + +void CPBEncryptParms::DeriveKeyL(const TDesC8& aPassword, TDes8& aKeyBuf) const +/** + Derive a key from this object's kdf, salt, amd iteration count. + + @param aPassword User-supplied password used to generate key. + @param aKeyBuf Buffer to populate with new key. + On entry it must be set to the required + key length. + */ + { + switch (iData->iKdf) + { + case CPBEncryptParms::EKdfPkcs5: + TPKCS5KDF::DeriveKeyL(aKeyBuf, aPassword, *iSalt, iIterations); + break; + + case CPBEncryptParms::EKdfPkcs12: + PKCS12KDF::DeriveKeyL(aKeyBuf, PKCS12KDF::EIDByteEncryptKey, aPassword, *iSalt, iIterations); + break; + + default: + ASSERT(EFalse); + break; + } + } + +/* CPBAuthData */ + +EXPORT_C CPBAuthData* CPBAuthData::NewL(const TDesC8& aPassword, + const TDesC8& aSalt, TUint aKeySize, TUint aIterations) + { + CPBAuthData* self = NewLC(aPassword, aSalt, aKeySize, aIterations); + CleanupStack::Pop(self); + return self; + } + +EXPORT_C CPBAuthData* CPBAuthData::NewLC(const TDesC8& aPassword, + const TDesC8& aSalt, TUint aKeySize, TUint aIterations) + { + CPBAuthData* self = new(ELeave)CPBAuthData(); + CleanupStack::PushL(self); + self->ConstructL(aPassword, aSalt, aKeySize, aIterations); + return self; + } + +EXPORT_C CPBAuthData* CPBAuthData::NewL(const CPBAuthData& aData) + { + CPBAuthData* self = NewLC(aData); + CleanupStack::Pop(self); + return self; + } + +EXPORT_C CPBAuthData* CPBAuthData::NewLC(const CPBAuthData& aData) + { + CPBAuthData* self = new(ELeave)CPBAuthData(); + CleanupStack::PushL(self); + self->ConstructL(aData); + return self; + } + +// HPRE-5TDFK2: Remove Store/estor.dll dependency on Cryptography/pbe.dll +// This method is DUPLICATED in common/generic/syslibs/store/ucrypt/ue_strm.cpp +EXPORT_C CPBAuthData::CPBAuthData() + { + } + +// HPRE-5TDFK2: Remove Store/estor.dll dependency on Cryptography/pbe.dll +// This method is DUPLICATED in common/generic/syslibs/store/ucrypt/ue_strm.cpp +CPBAuthData::~CPBAuthData() + { + delete iAuthKey; + delete iSalt; + } + +void CPBAuthData::ConstructL(const TDesC8& aPassword, const TDesC8& aSalt, + TUint aKeySize, TUint aIterations) + { + iSalt = aSalt.AllocL(); + iIterations = aIterations; + iAuthKey = HBufC8::NewMaxL(aKeySize); + TPtr8 authKeyPtr = iAuthKey->Des(); + TPKCS5KDF::DeriveKeyL(authKeyPtr, aPassword, *iSalt, iIterations); + } + +void CPBAuthData::ConstructL(const CPBAuthData& aData) + { + iAuthKey = aData.Key().AllocL(); + iSalt = aData.Salt().AllocL(); + iIterations = aData.Iterations(); + } + +EXPORT_C TPtrC8 CPBAuthData::Key() const + { + return TPtrC8(*iAuthKey); + } + +EXPORT_C TPtrC8 CPBAuthData::Salt() const + { + return TPtrC8(*iSalt); + } + +EXPORT_C TInt CPBAuthData::Iterations() const + { + return iIterations; + } + +EXPORT_C TBool CPBAuthData::operator==(const CPBAuthData& aAuth) const + { + //if the key's are equal, the its true, as the other members are used in key derivation + return (*iAuthKey == aAuth.Key()); + } + diff -r 7e3f204e6c81 -r f9c11be8c0b3 crypto/weakcryptospi/source/pbe/pbefactory.cpp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/crypto/weakcryptospi/source/pbe/pbefactory.cpp Tue Dec 01 11:12:04 2009 +0000 @@ -0,0 +1,115 @@ +/* +* Copyright (c) 2005-2009 Nokia Corporation and/or its subsidiary(-ies). +* All rights reserved. +* This component and the accompanying materials are made available +* under the terms of the License "Eclipse Public License v1.0" +* which accompanies this distribution, and is available +* at the URL "http://www.eclipse.org/legal/epl-v10.html". +* +* Initial Contributors: +* Nokia Corporation - initial contribution. +* +* Contributors: +* +* Description: +* +*/ + + +/** + @file +*/ + +#include +#include + +EXPORT_C CPBEncryptElementBase* TPBEncryptionFactory::NewPBEncryptElementL( + const TDesC& aPassword) + { + CPBEncryptElementBase* encrypt = NewPBEncryptElementLC(aPassword); + CleanupStack::Pop(); + return encrypt; + } + +EXPORT_C CPBEncryptElementBase* TPBEncryptionFactory::NewPBEncryptElementLC( + const TDesC& aPassword) + { + CPBEncryptElement* encrypt = CPBEncryptElement::NewLC(aPassword); + return encrypt; + } + +EXPORT_C CPBEncryptElementBase* TPBEncryptionFactory::NewPBEncryptElementL( + const TDesC& aPassword, const TPBEncryptParms& aEncryptParms) + { + CPBEncryptElementBase* encrypt = NewPBEncryptElementLC(aPassword,aEncryptParms); + CleanupStack::Pop(); + return encrypt; + } + +EXPORT_C CPBEncryptElementBase* TPBEncryptionFactory::NewPBEncryptElementLC( + const TDesC& aPassword, const TPBEncryptParms& aEncryptParms) + { + CPBEncryptElement* encrypt = CPBEncryptElement::NewLC(aPassword, + aEncryptParms); + return encrypt; + } + +EXPORT_C CPBEncryptElementBase* TPBEncryptionFactory::NewPBEncryptElementL( + const TPBEncryptionData& aData) + { + CPBEncryptElementBase* encrypt = NewPBEncryptElementLC(aData); + CleanupStack::Pop(); + return encrypt; + } + +EXPORT_C CPBEncryptElementBase* TPBEncryptionFactory::NewPBEncryptElementLC( + const TPBEncryptionData& aData) + { + CPBEncryptElement* encrypt = CPBEncryptElement::NewLC(aData); + return encrypt; + } + +EXPORT_C CPBEncryptSetBase* TPBEncryptionFactory::NewPBEncryptSetL( + const TDesC& aPassword) + { + CPBEncryptSetBase* encrypt = NewPBEncryptSetLC(aPassword); + CleanupStack::Pop(); + return encrypt; + } + +EXPORT_C CPBEncryptSetBase* TPBEncryptionFactory::NewPBEncryptSetLC( + const TDesC& aPassword) + { + CPBEncryptSet* encrypt = CPBEncryptSet::NewLC(aPassword); + return encrypt; + } + +EXPORT_C CPBEncryptSetBase* TPBEncryptionFactory::NewPBEncryptSetL( + const TDesC& aPassword, const TPBEncryptParms& aEncryptParms) + { + CPBEncryptSetBase* encrypt = NewPBEncryptSetLC(aPassword, aEncryptParms); + CleanupStack::Pop(); + return encrypt; + } + +EXPORT_C CPBEncryptSetBase* TPBEncryptionFactory::NewPBEncryptSetLC( + const TDesC& aPassword, const TPBEncryptParms& aEncryptParms) + { + CPBEncryptSet* encrypt = CPBEncryptSet::NewLC(aPassword, aEncryptParms); + return encrypt; + } + +EXPORT_C CPBEncryptSetBase* TPBEncryptionFactory::NewPBEncryptSetL( + const TPBEncryptionData& aData, const TDesC8& aEncryptedMasterKey) + { + CPBEncryptSetBase* encrypt = NewPBEncryptSetLC(aData, aEncryptedMasterKey); + CleanupStack::Pop(); + return encrypt; + } + +EXPORT_C CPBEncryptSetBase* TPBEncryptionFactory::NewPBEncryptSetLC( + const TPBEncryptionData& aData, const TDesC8& aEncryptedMasterKey) + { + CPBEncryptSet* encrypt = CPBEncryptSet::NewLC(aData, aEncryptedMasterKey); + return encrypt; + } diff -r 7e3f204e6c81 -r f9c11be8c0b3 crypto/weakcryptospi/source/pbe/pbencryptor.cpp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/crypto/weakcryptospi/source/pbe/pbencryptor.cpp Tue Dec 01 11:12:04 2009 +0000 @@ -0,0 +1,126 @@ +/* +* Copyright (c) 2002-2009 Nokia Corporation and/or its subsidiary(-ies). +* All rights reserved. +* This component and the accompanying materials are made available +* under the terms of the License "Eclipse Public License v1.0" +* which accompanies this distribution, and is available +* at the URL "http://www.eclipse.org/legal/epl-v10.html". +* +* Initial Contributors: +* Nokia Corporation - initial contribution. +* +* Contributors: +* +* Description: +* +*/ + + +#include +#include +#include +#include "pbesymmetricfactory.h" + +EXPORT_C CPBEncryptorElement* CPBEncryptorElement::NewL( + const TPBECipher aCipher, const TDesC8& aKey, const TDesC8& aIV) + { + CPBEncryptorElement* self = NewLC(aCipher, aKey, aIV); + CleanupStack::Pop(); + return self; + } + +EXPORT_C CPBEncryptorElement* CPBEncryptorElement::NewLC( + const TPBECipher aCipher, const TDesC8& aKey, const TDesC8& aIV) + { + CPBEncryptorElement* self = new(ELeave) CPBEncryptorElement; + CleanupStack::PushL(self); + self->ConstructL(aCipher, aKey, aIV); + return self; + } + +void CPBEncryptorElement::Process(const TDesC8& aInput, TDes8& aOutput) + { + iCipher->Process(aInput, aOutput); + } + +void CPBEncryptorElement::ProcessFinalL(const TDesC8& aInput, TDes8& aOutput) + { + iCipher->ProcessFinalL(aInput, aOutput); + } + +void CPBEncryptorElement::ConstructL(const TPBECipher aCipher, + const TDesC8& aKey, const TDesC8& aIV) + { + iCipher = PBE::MakeEncryptorL(aCipher, aKey, aIV); + } + +CPBEncryptorElement::CPBEncryptorElement() + { + } + +CPBEncryptorElement::~CPBEncryptorElement() + { + delete iCipher; + } + +TInt CPBEncryptorElement::MaxOutputLength(TUint aMaxInputLength) const + { + return iCipher->MaxOutputLength(aMaxInputLength); + } + +TInt CPBEncryptorElement::MaxFinalOutputLength(TUint aMaxInputLength) const + { + return iCipher->MaxFinalOutputLength(aMaxInputLength); + } + +EXPORT_C CPBDecryptorElement* CPBDecryptorElement::NewL( + const TPBECipher aCipher, const TDesC8& aKey, const TDesC8& aIV) + { + CPBDecryptorElement* self = NewLC(aCipher, aKey, aIV); + CleanupStack::Pop(); + return self; + } + +EXPORT_C CPBDecryptorElement* CPBDecryptorElement::NewLC( + const TPBECipher aCipher, const TDesC8& aKey, const TDesC8& aIV) + { + CPBDecryptorElement* self = new(ELeave) CPBDecryptorElement; + CleanupStack::PushL(self); + self->ConstructL(aCipher, aKey, aIV); + return self; + } + +void CPBDecryptorElement::Process(const TDesC8& aInput, TDes8& aOutput) + { + iCipher->Process(aInput, aOutput); + } + +void CPBDecryptorElement::ProcessFinalL(const TDesC8& aInput, TDes8& aOutput) + { + iCipher->ProcessFinalL(aInput, aOutput); + } + +void CPBDecryptorElement::ConstructL(const TPBECipher aCipher, + const TDesC8& aKey, const TDesC8& aIV) + { + iCipher = PBE::MakeDecryptorL(aCipher, aKey, aIV); + } + +CPBDecryptorElement::CPBDecryptorElement() + { + } + +CPBDecryptorElement::~CPBDecryptorElement() + { + delete iCipher; + } + +TInt CPBDecryptorElement::MaxOutputLength(TUint aMaxInputLength) const + { + return iCipher->MaxOutputLength(aMaxInputLength); + } + +TInt CPBDecryptorElement::MaxFinalOutputLength(TUint aMaxInputLength) const + { + return iCipher->MaxFinalOutputLength(aMaxInputLength); + } diff -r 7e3f204e6c81 -r f9c11be8c0b3 crypto/weakcryptospi/source/pbe/pbencryptorset.cpp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/crypto/weakcryptospi/source/pbe/pbencryptorset.cpp Tue Dec 01 11:12:04 2009 +0000 @@ -0,0 +1,217 @@ +/* +* Copyright (c) 2002-2009 Nokia Corporation and/or its subsidiary(-ies). +* All rights reserved. +* This component and the accompanying materials are made available +* under the terms of the License "Eclipse Public License v1.0" +* which accompanies this distribution, and is available +* at the URL "http://www.eclipse.org/legal/epl-v10.html". +* +* Initial Contributors: +* Nokia Corporation - initial contribution. +* +* Contributors: +* +* Description: +* +*/ + + +#include +#include + +#include +#include "pbesymmetricfactory.h" + +#ifdef SYMBIAN_ENABLE_SPLIT_HEADERS +/** The maximum block size supported (in bytes) */ +const TUint KMaxBlockSizeSupported = 32; +#endif + +EXPORT_C CPBEncryptorSet* CPBEncryptorSet::NewL( + const TPBECipher aCipher, const TDesC8& aKey) + { + CPBEncryptorSet* self = NewLC(aCipher, aKey); + CleanupStack::Pop(); + return self; + } + +EXPORT_C CPBEncryptorSet* CPBEncryptorSet::NewLC( + const TPBECipher aCipher, const TDesC8& aKey) + { + CPBEncryptorSet* self = new(ELeave) CPBEncryptorSet; + CleanupStack::PushL(self); + + self->ConstructL(aCipher, aKey); + + return self; + } + +void CPBEncryptorSet::ConstructL(const TPBECipher aCipher,const TDesC8& aKey) + { + TInt blocksize = PBE::GetBlockBytes(aCipher); + iIV = HBufC8::NewMaxL(blocksize); + TPtr8 iv = iIV->Des(); + TRandom::RandomL(iv); + + iCipher = PBE::MakeEncryptorL(aCipher, aKey, iv); + } + +void CPBEncryptorSet::Process(const TDesC8& aInput, TDes8& aOutput) + { + if(!iIVSent) + { + aOutput.Append(*iIV); + iIVSent = ETrue; + } + iCipher->Process(aInput, aOutput); + } + +void CPBEncryptorSet::ProcessFinalL(const TDesC8& aInput, + TDes8& aOutput) + { + if(!iIVSent) + { + aOutput.Append(*iIV); + iIVSent = ETrue; + } + + iCipher->ProcessFinalL(aInput, aOutput); + } + + +CPBEncryptorSet::CPBEncryptorSet() : iIVSent(EFalse) + { + } + +CPBEncryptorSet::~CPBEncryptorSet() + { + delete iIV; + delete iCipher; // Don't delete iCBCDecryptor, this belongs to iCipher + } + +TInt CPBEncryptorSet::MaxOutputLength(TUint aMaxInputLength) const + { + if(iIVSent) + { + return (iCipher->MaxOutputLength(aMaxInputLength)); + } + else + {// If we've not sent the iv yet then its the length + // from the cipher plus a blocksize for the iv + return (iCipher->MaxOutputLength(aMaxInputLength + iCipher->BlockSize())); + } + } + +TInt CPBEncryptorSet::MaxFinalOutputLength(TUint aMaxInputLength) const + { + if(iIVSent) + { + return (iCipher->MaxFinalOutputLength(aMaxInputLength)); + } + else + {// If we've not sent the iv yet then its the length + // from the cipher plus a blocksize for the iv + return (iCipher->MaxFinalOutputLength(aMaxInputLength + iCipher->BlockSize())); + } + } + +EXPORT_C CPBDecryptorSet* CPBDecryptorSet::NewL(const TPBECipher aCipher, + const TDesC8& aKey) + { + CPBDecryptorSet* self = NewLC(aCipher, aKey); + CleanupStack::Pop(); + return self; + } + +EXPORT_C CPBDecryptorSet* CPBDecryptorSet::NewLC(const TPBECipher aCipher, + const TDesC8& aKey) + { + CPBDecryptorSet* self = new(ELeave) CPBDecryptorSet; + CleanupStack::PushL(self); + TBuf8 fakeIV; + fakeIV.SetLength(PBE::GetBlockBytes(aCipher)); + self->ConstructL(aCipher, aKey, fakeIV); + return self; + } + +void CPBDecryptorSet::ConstructL(const TPBECipher aCipher, + const TDesC8& aKey, const TDesC8& aIV) + { + iCipher = PBE::MakeDecryptorL(aCipher, aKey, aIV); + iIVBuf = HBufC8::NewL(PBE::GetBlockBytes(aCipher)); + } + +void CPBDecryptorSet::Process(const TDesC8& aInput, TDes8& aOutput) + { + TPtrC8 input = ProcessIV(aInput); + iCipher->Process(input, aOutput); + } + +void CPBDecryptorSet::ProcessFinalL(const TDesC8& aInput, TDes8& aOutput) + { + TPtrC8 input = ProcessIV(aInput); + iCipher->ProcessFinalL(input, aOutput); + } + +TPtrC8 CPBDecryptorSet::ProcessIV(const TDesC8& aInput) + { + if(!iIVSent) + { + TPtr8 iIVBufPtr(iIVBuf->Des()); + if(aInput.Length() + iIVBufPtr.Length() < iCipher->BlockSize()) + { + iIVBufPtr.Append(aInput); + return TPtrC8(); + } + else + { + TInt rem = iCipher->BlockSize() - iIVBufPtr.Length(); + iIVBufPtr.Append(aInput.Mid(0, rem)); + CBufferedDecryptor* blockDecryptor = static_cast(iCipher); + static_cast(blockDecryptor->BlockTransformer())->SetIV(iIVBufPtr); + iIVSent = ETrue; + return aInput.Mid(rem); + } + } + else + { + return aInput; + } + } + +CPBDecryptorSet::CPBDecryptorSet() : iIVSent(EFalse) + { + } + +CPBDecryptorSet::~CPBDecryptorSet() + { + delete iCipher; + //iCipher owns iCBCDecryptor we _don't_ need to delete it + delete iIVBuf; + } + +TInt CPBDecryptorSet::MaxOutputLength(TUint aMaxInputLength) const + { + if(iIVSent) + { + return (iCipher->MaxOutputLength(aMaxInputLength)); + } + else // if we haven't sent the iv yet, then the length the max length of the + { // cipher minus a BlockSize where the IV was sitting (as the iv would be part + // of the length they've sent us) + return (iCipher->MaxOutputLength(aMaxInputLength - iCipher->BlockSize())); + } + } + +TInt CPBDecryptorSet::MaxFinalOutputLength(TUint aMaxInputLength) const + { + if(iIVSent) + { + return (iCipher->MaxFinalOutputLength(aMaxInputLength)); + } + else // if we haven't sent the iv yet, then the length the max length of the + { // cipher minus a BlockSize where the IV was sitting (as the iv would be part + // of the length they've sent us) + return (iCipher->MaxFinalOutputLength(aMaxInputLength - iCipher->BlockSize())); + } + } diff -r 7e3f204e6c81 -r f9c11be8c0b3 crypto/weakcryptospi/source/pbe/pbeset.cpp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/crypto/weakcryptospi/source/pbe/pbeset.cpp Tue Dec 01 11:12:04 2009 +0000 @@ -0,0 +1,261 @@ +/* +* Copyright (c) 2002-2009 Nokia Corporation and/or its subsidiary(-ies). +* All rights reserved. +* This component and the accompanying materials are made available +* under the terms of the License "Eclipse Public License v1.0" +* which accompanies this distribution, and is available +* at the URL "http://www.eclipse.org/legal/epl-v10.html". +* +* Initial Contributors: +* Nokia Corporation - initial contribution. +* +* Contributors: +* +* Description: +* +*/ + + +#include +#include +#include +#include "pkcs5kdf.h" +#include +#include "pbe.h" +#include +#include "pbesymmetricfactory.h" + +EXPORT_C CPBEncryptSet* CPBEncryptSet::NewL(const TPBPassword& aPassword) + { + CPBEncryptSet* self = NewLC(aPassword); + CleanupStack::Pop(); + return self; + } + +EXPORT_C CPBEncryptSet* CPBEncryptSet::NewLC(const TPBPassword& aPassword) + { + CPBEncryptSet* self = new(ELeave) CPBEncryptSet; + CleanupStack::PushL(self); + self->ConstructL(aPassword.Password()); + return self; + } + +EXPORT_C CPBEncryptSet* CPBEncryptSet::NewL(const TPBPassword& aPassword, + const TPBECipher aCipher) + { + CPBEncryptSet* self = NewLC(aPassword, aCipher); + CleanupStack::Pop(); + return self; + } + +EXPORT_C CPBEncryptSet* CPBEncryptSet::NewLC(const TPBPassword& aPassword, + const TPBECipher aCipher) + { + CPBEncryptSet* self = new(ELeave) CPBEncryptSet; + CleanupStack::PushL(self); + self->ConstructL(aPassword.Password(), aCipher); + return self; + } + +EXPORT_C CPBEncryptSet* CPBEncryptSet::NewL(const TPBPassword& aPassword, + const CPBEncryptParms& aParms) + { + CPBEncryptSet* self = NewLC(aPassword, aParms); + CleanupStack::Pop(); + return self; + } + +EXPORT_C CPBEncryptSet* CPBEncryptSet::NewLC(const TPBPassword& aPassword, + const CPBEncryptParms& aParms) + { + CPBEncryptSet* self = new(ELeave) CPBEncryptSet; + CleanupStack::PushL(self); + self->ConstructL(aPassword.Password(), aParms); + return self; + } + +EXPORT_C CPBEncryptSet* CPBEncryptSet::NewL(const CPBEncryptionData& aData, + const TDesC8& aEncryptedKey, const TPBPassword& aPassword) + { + CPBEncryptSet* self = NewLC(aData, aEncryptedKey, aPassword); + CleanupStack::Pop(); + return self; + } + +EXPORT_C CPBEncryptSet* CPBEncryptSet::NewLC(const CPBEncryptionData& aData, + const TDesC8& aEncryptedKey, const TPBPassword& aPassword) + { + CPBEncryptSet* self = new(ELeave) CPBEncryptSet; + CleanupStack::PushL(self); + self->ConstructL(aData, aEncryptedKey, aPassword); + return self; + } + +void CPBEncryptSet::ConstructL(const TDesC8& aPassword) + { + CPBEncryptElement::ConstructL(aPassword); + ConstructMasterKeyL(); + } + +void CPBEncryptSet::ConstructL(const TDesC8& aPassword, + const TPBECipher aCipher) + { + CPBEncryptElement::ConstructL(aPassword, aCipher); + ConstructMasterKeyL(); + } + +void CPBEncryptSet::ConstructL(const TDesC8& aPassword, + const CPBEncryptParms& aParms) + { + CPBEncryptElement::ConstructL(aPassword, aParms); + ConstructMasterKeyL(); + } + +void CPBEncryptSet::ConstructMasterKeyL(void) + { + TBuf8 masterKey(KAESKeyBytes256); + TRandom::RandomL(masterKey); + iEncryptedMasterKey = HBufC8::NewL(KAESKeyBytes256); + EncryptMasterKeyL(masterKey); + } + +void CPBEncryptSet::ConstructL(const CPBEncryptionData& aData, + const TDesC8& aEncryptedMasterKey, const TPBPassword& aPassword) + { + CPBEncryptElement::ConstructL(aData, aPassword); + iEncryptedMasterKey = aEncryptedMasterKey.AllocL(); + } + +EXPORT_C void CPBEncryptSet::ChangePasswordL(const TPBPassword& aNewPassword) + { + //1) Decrypt master key with old encrypt key + TBuf8 masterKey; + DecryptMasterKeyL(masterKey); + + //2) create new encrypt parms + + TBuf8 authSalt(KPBEMaxSaltBytes); + TRandom::RandomL(authSalt); + + //3) create a totally new CPBEncryptionData representing the new password + CPBEncryptionData* newData = CPBEncryptionData::NewL( + aNewPassword.Password(), authSalt, iData->EncryptParms()); + + delete iData; + iData = newData; + + // regenerate the password using a maximum length salt. + CPBEncryptParms& epNonConst = + const_cast(iData->EncryptParms()); + epNonConst.ResizeSaltL(KPBEMaxSaltBytes); + + TPtr8 iEncryptKeyBuf(iEncryptKey->Des()); + iEncryptKeyBuf.SetLength(PBE::GetKeyBytes(iData->EncryptParms().Cipher())); + + iData->EncryptParms().DeriveKeyL(aNewPassword.Password(), iEncryptKeyBuf); + + //4) Encrypt master key with new encrypt key + EncryptMasterKeyL(masterKey); + } + +EXPORT_C const TDesC8& CPBEncryptSet::EncryptedMasterKey(void) const + { + return *iEncryptedMasterKey; + } + +CPBEncryptor* CPBEncryptSet::NewEncryptLC(void) const + { + CPBEncryptor* encryptor = NewEncryptL(); + CleanupStack::PushL(encryptor); + return encryptor; + } + +CPBEncryptor* CPBEncryptSet::NewEncryptL(void) const + { + TBuf8 masterKey; + DecryptMasterKeyL(masterKey); + + CPBEncryptor* encryptor = 0; + //make sure the masterkey we pass is exactly the right length for the cipher + encryptor = CPBEncryptorSet::NewL(iData->EncryptParms().Cipher(), + masterKey.Left(PBE::GetKeyBytes(iData->EncryptParms().Cipher()))); + return encryptor; + } + +CPBDecryptor* CPBEncryptSet::NewDecryptLC(void) const + { + CPBDecryptor* decryptor = NewDecryptL(); + CleanupStack::PushL(decryptor); + return decryptor; + } + +CPBDecryptor* CPBEncryptSet::NewDecryptL(void) const + { + TBuf8 masterKey; + DecryptMasterKeyL(masterKey); + + CPBDecryptor* decryptor = 0; + //make sure the masterkey we pass is exactly the right length for the cipher + decryptor = CPBDecryptorSet::NewL(iData->EncryptParms().Cipher(), + masterKey.Left(PBE::GetKeyBytes(iData->EncryptParms().Cipher()))); + return decryptor; + } + +void CPBEncryptSet::DecryptMasterKeyL(TDes8& aMasterKey) const + { + CPBDecryptorElement* decryptor = CPBDecryptorElement::NewLC( + iData->EncryptParms().Cipher(), *iEncryptKey, iData->EncryptParms().IV()); + aMasterKey.SetLength(0); + decryptor->Process(*iEncryptedMasterKey, aMasterKey); + CleanupStack::PopAndDestroy(decryptor); + } + +void CPBEncryptSet::EncryptMasterKeyL(const TDesC8& aMasterKey) + { + CPBEncryptorElement* encryptor = CPBEncryptorElement::NewLC( + iData->EncryptParms().Cipher(), *iEncryptKey, iData->EncryptParms().IV()); + TPtr8 encryptedMasterKeyBuf(iEncryptedMasterKey->Des()); + encryptedMasterKeyBuf.SetLength(0); + encryptor->Process(aMasterKey, encryptedMasterKeyBuf); + CleanupStack::PopAndDestroy(encryptor); + } + +CPBEncryptSet::CPBEncryptSet() + { + } + +CPBEncryptSet::~CPBEncryptSet() + { + delete iEncryptedMasterKey; + } + +// Warning: This function is only valid BEFORE you call NewEncryptL +// After creating the cipher, ask it about itself, not me! +// This is _very_ dodgy as I assume all sorts of things about the encryptor. +// 1) That it uses SSLv3 or similar style padding +// 2) That it stores the IV for that stream at the front. +// This is here for specific application that requires this and aren't able to +// actually construct the cipher and ask it. In almost all other cases you +// should construct the cipher and ask it. +TInt CPBEncryptSet::MaxCiphertextLength(TInt aPlaintextLength) const + { + TUint blocksize = PBE::GetBlockBytes(iData->EncryptParms().Cipher()); + TUint padding = blocksize - aPlaintextLength % blocksize; + //totallength = blocksize of iv hidden at beginning + inputLength + padding + return blocksize + aPlaintextLength + padding; + } + +// Warning: This function is only valid BEFORE you call NewDecryptL +// After creating the cipher, ask it about itself, not me! +TInt CPBEncryptSet::MaxPlaintextLength(TInt aCiphertextLength) const + { + /*It's impossible to determine anything about how much padding will be + * removed. So we'll return a max length that is longer than will ever + * happen by at most a blocksize - 1. + */ + //In all cases SSLv3 padding has at least one byte of padding. + TUint blocksize = PBE::GetBlockBytes(iData->EncryptParms().Cipher()); + //totallength = inputlength - iv hidden at beginning - 1 byte of padding + return aCiphertextLength - blocksize - 1; + } + diff -r 7e3f204e6c81 -r f9c11be8c0b3 crypto/weakcryptospi/source/pbe/pbesymmetricfactory.cpp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/crypto/weakcryptospi/source/pbe/pbesymmetricfactory.cpp Tue Dec 01 11:12:04 2009 +0000 @@ -0,0 +1,245 @@ +/* +* Copyright (c) 2002-2009 Nokia Corporation and/or its subsidiary(-ies). +* All rights reserved. +* This component and the accompanying materials are made available +* under the terms of the License "Eclipse Public License v1.0" +* which accompanies this distribution, and is available +* at the URL "http://www.eclipse.org/legal/epl-v10.html". +* +* Initial Contributors: +* Nokia Corporation - initial contribution. +* +* Contributors: +* +* Description: +* +*/ + + +#include +#include "pbesymmetricfactory.h" + +#ifdef SYMBIAN_ENABLE_SPLIT_HEADERS + +/** OpenSSL PKCS8 Effective Key Length Compatibility.*/ +const TUint KPkcs8CompatibilityBits = 128; + +/** PKCS12 PBE Effective Key Length Compatibility.*/ +const TUint KPkcs12CompatibilityBits = 40; + +#endif + +TUint PBE::GetBlockBytes(TPBECipher aCipher) + { + switch(aCipher) + { + case ECipherAES_CBC_128: + case ECipherAES_CBC_192: + case ECipherAES_CBC_256: + return KAESBlockBytes; + case ECipherDES_CBC: + case ECipher3DES_CBC: + + case ECipher2Key3DES_CBC: + + return KDESBlockBytes; + case ECipherRC2_CBC_128_16: + case ECipherRC2_CBC_40_16: + case ECipherRC2_CBC_128: + case ECipherRC2_CBC_40: + + case ECipherRC2_CBC_40_5: + + return KRC2BlockBytes; + + case ECipherARC4_128: + case ECipherARC4_40: + return 1; // 1 byte block for stream cipher + + default: + User::Panic(_L("Invalid PBE cipher"), 1); + } + return (KErrNone); // For the compiler + } + +TUint PBE::GetKeyBytes(TPBECipher aCipher) + { + switch(aCipher) + { + case ECipherAES_CBC_128: + return KAESKeyBytes128; + case ECipherAES_CBC_192: + return KAESKeyBytes192; + case ECipherAES_CBC_256: + return KAESKeyBytes256; + case ECipherDES_CBC: + return KDESKeyBytes; + case ECipher3DES_CBC: + return K3DESKeyBytes; + + case ECipher2Key3DES_CBC: + return K2Key3DESKeyBytes; + + case ECipherRC2_CBC_128: + case ECipherRC2_CBC_128_16: + return KRC2KeyBytes128; + case ECipherRC2_CBC_40: + case ECipherRC2_CBC_40_16: + + case ECipherRC2_CBC_40_5: + + return KRC2KeyBytes40; + + case ECipherARC4_128: + return KRC4KeyBytes128; + case ECipherARC4_40: + return KRC4KeyBytes40; + + default: + User::Panic(_L("Invalid PBE cipher"), 1); + } + return (KErrNone); // For the compiler + } + +CSymmetricCipher* PBE::MakeEncryptorL(TPBECipher aCipher, const TDesC8& aKey, + const TDesC8& aIV) + { + CSymmetricCipher* cipher = 0; + CBlockTransformation* block = 0; + switch(aCipher) + { + + // stream cipher + case ECipherARC4_40: + case ECipherARC4_128: + cipher = CARC4::NewL(aKey, 0); + break; + + // block cipher + case ECipherAES_CBC_128: + case ECipherAES_CBC_192: + case ECipherAES_CBC_256: + block = CAESEncryptor::NewLC(aKey); + break; + + case ECipherDES_CBC: + block = CDESEncryptor::NewLC(aKey); + break; + + case ECipher3DES_CBC: + block = C3DESEncryptor::NewLC(aKey); + break; + + case ECipher2Key3DES_CBC: + { + // Construct 3key from 2 key ( copy first key to 3rd key ) each key 8 bytes + TBuf8 encryptKey(aKey); + encryptKey.Append(aKey.Ptr(),KDESKeyBytes); + block = C3DESEncryptor::NewLC(encryptKey); + break; + } + + case ECipherRC2_CBC_40: + case ECipherRC2_CBC_128: + block = CRC2Encryptor::NewLC(aKey); + break; + + case ECipherRC2_CBC_40_16: + case ECipherRC2_CBC_128_16: + block = CRC2Encryptor::NewLC(aKey, KPkcs8CompatibilityBits); + break; + + case ECipherRC2_CBC_40_5: + block = CRC2Encryptor::NewLC(aKey, KPkcs12CompatibilityBits); + break; + + default: + User::Panic(_L("Invalid PBE encryptor"), 1); + } + + // if aCipher is not stream cipher, create block cipher object + if(aCipher != ECipherARC4_40 && aCipher != ECipherARC4_128) + { + block = CModeCBCEncryptor::NewL(block, aIV); + CleanupStack::Pop(); //1st block owned by 2nd + CleanupStack::PushL(block);//2nd block + CPadding* padding = CPaddingSSLv3::NewLC(GetBlockBytes(aCipher)); + cipher = CBufferedEncryptor::NewL(block, padding); + CleanupStack::Pop(padding); //owned by cipher + CleanupStack::Pop(block); //owned by cipher + } + + return cipher; + } + + +CSymmetricCipher* PBE::MakeDecryptorL(TPBECipher aCipher, const TDesC8& aKey, + const TDesC8& aIV) + { + CSymmetricCipher* cipher = 0; + CBlockTransformation* block = 0; + switch(aCipher) + { + // stream cipher + case ECipherARC4_40: + case ECipherARC4_128: + cipher = CARC4::NewL(aKey, 0); + break; + + // block cipher + case ECipherAES_CBC_128: + case ECipherAES_CBC_192: + case ECipherAES_CBC_256: + block = CAESDecryptor::NewLC(aKey); + break; + + case ECipherDES_CBC: + block = CDESDecryptor::NewLC(aKey); + break; + + case ECipher3DES_CBC: + block = C3DESDecryptor::NewLC(aKey); + break; + + case ECipher2Key3DES_CBC: + { + // Construct 3key from 2 key ( copy first key to 3rd key ) each key 8 bytes + TBuf8 encryptKey(aKey); + encryptKey.Append(aKey.Ptr(),KDESKeyBytes); + block = C3DESDecryptor::NewLC(encryptKey); + break; + } + + case ECipherRC2_CBC_40: + case ECipherRC2_CBC_128: + block = CRC2Decryptor::NewLC(aKey); + break; + + case ECipherRC2_CBC_40_16: + case ECipherRC2_CBC_128_16: + block = CRC2Decryptor::NewLC(aKey, KPkcs8CompatibilityBits); + break; + + case ECipherRC2_CBC_40_5: + block = CRC2Decryptor::NewLC(aKey, KPkcs12CompatibilityBits); + break; + + default: + User::Panic(_L("Invalid PBE decryptor"), 1); + } + + // if aCipher is not stream cipher, create block cipher object + if(aCipher != ECipherARC4_40 && aCipher != ECipherARC4_128) + { + block = CModeCBCDecryptor::NewL(block, aIV); + CleanupStack::Pop(); //1st block owned by 2nd + CleanupStack::PushL(block);//2nd block + + CPadding* padding = CPaddingSSLv3::NewLC(GetBlockBytes(aCipher)); + cipher = CBufferedDecryptor::NewL(block, padding); + CleanupStack::Pop(padding); //owned by cipher + CleanupStack::Pop(block); //owned by cipher + } + + return cipher; + } diff -r 7e3f204e6c81 -r f9c11be8c0b3 crypto/weakcryptospi/source/pbe/pbesymmetricfactory.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/crypto/weakcryptospi/source/pbe/pbesymmetricfactory.h Tue Dec 01 11:12:04 2009 +0000 @@ -0,0 +1,72 @@ +/* +* Copyright (c) 2003-2009 Nokia Corporation and/or its subsidiary(-ies). +* All rights reserved. +* This component and the accompanying materials are made available +* under the terms of the License "Eclipse Public License v1.0" +* which accompanies this distribution, and is available +* at the URL "http://www.eclipse.org/legal/epl-v10.html". +* +* Initial Contributors: +* Nokia Corporation - initial contribution. +* +* Contributors: +* +* Description: +* PBE symmetric factory +* +*/ + + +/** + @file + @internalComponent +*/ + +#ifndef __PBESYMMETRICFACTORY_H__ +#define __PBESYMMETRICFACTORY_H__ + +#include +#include + +const TUint KAESBlockBytes = 16; +const TUint KAESKeyBytes128 = 16; +const TUint KAESKeyBytes192 = 24; +const TUint KAESKeyBytes256 = 32; + +const TUint KDESBlockBytes = 8; +const TUint KDESKeyBytes = 8; +const TUint K3DESKeyBytes = 24; + +const TUint K2Key3DESKeyBytes = 16; +const TUint KRC4KeyBytes128 = 16; +const TUint KRC4KeyBytes40 = 5; + +const TUint KRC2BlockBytes = 8; +const TUint KRC2KeyBytes40 = 5; +const TUint KRC2KeyBytes128 = 16; + +const TPBECipher KPBEDefaultStrongCipher = ECipherAES_CBC_128; +const TPBECipher KPBEDefaultWeakCipher = ECipherDES_CBC; +const TUint KPBEDefaultSaltBytes = 16; //pkcs5 recommends min 64 bits (8 bytes); + +const TUint KPBEMaxCipherIVBytes = KAESBlockBytes; +const TUint KPBEMaxCipherKeyBytes = KAESKeyBytes256; +const TUint KPBEMaxSaltBytes = 16; //pkcs5 recommends min 64 bits (8 bytes); + +class PBE + { +public: + static TUint GetKeyBytes(TPBECipher aCipher); + static TUint GetBlockBytes(TPBECipher aCipher); + + static CSymmetricCipher* MakeEncryptorL(TPBECipher aCipher, + const TDesC8& aKey, const TDesC8& aIV); + static CSymmetricCipher* MakeDecryptorL(TPBECipher aCipher, + const TDesC8& aKey, const TDesC8& aIV); +private: + PBE(void); + PBE(const PBE&); + PBE& operator=(const PBE&); + }; + +#endif diff -r 7e3f204e6c81 -r f9c11be8c0b3 crypto/weakcryptospi/source/pkcs12kdf/GenTestDKs.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/crypto/weakcryptospi/source/pkcs12kdf/GenTestDKs.java Tue Dec 01 11:12:04 2009 +0000 @@ -0,0 +1,150 @@ +/* +* Copyright (c) 1998-2009 Nokia Corporation and/or its subsidiary(-ies). +* All rights reserved. +* This component and the accompanying materials are made available +* under the terms of the License "Eclipse Public License v1.0" +* which accompanies this distribution, and is available +* at the URL "http://www.eclipse.org/legal/epl-v10.html". +* +* Initial Contributors: +* Nokia Corporation - initial contribution. +* +* Contributors: +* +* Description: +* This program generates keys with Bouncy Castle for compatibility testing. +* +*/ + + +import java.security.SecureRandom; +import org.bouncycastle.crypto.PBEParametersGenerator; +import org.bouncycastle.crypto.digests.SHA1Digest; +import org.bouncycastle.crypto.generators.PKCS12ParametersGenerator; +import org.bouncycastle.crypto.params.KeyParameter; + +public class GenTestDKs +{ + public static void main(String[] args) + { + PKCS12ParametersGenerator pgen = new PKCS12ParametersGenerator(new SHA1Digest()); + + // SB.4: key lengths for defined OIDs + // (168 for triple DES will first exercise chaining.) + final int[] keyLens = {40, 128, 168, 368}; + + // SB.4 iteration count is recommended to be 1024 or more + final int[] iterCounts = {1, 2, 4, 8, 128, 1024, 1536, 2048}; + + // SB.4 salt should be same length as hash function output + // (=160 bits for SHA1.) + byte[][] salts = new byte[3][]; + salts[0] = new byte[] {'S', 'A', 'L', 'T'}; + System.out.println("4 byte salt"); + printByteArray(salts[0]); + + // calls to nextBytes() are only executed once +/* SecureRandom sr; + try { sr = SecureRandom.getInstance("SHA1PRNG", "SUN"); } + catch (Exception e) + { + System.err.println("UNABLE TO GET RANDOM SOURCE"); + return; + } +*/ +// salts[1] = new byte[160 / 8]; +// sr.nextBytes(salts[1]); + salts[1] = new byte[] + { + (byte) 0x1d, (byte) 0x56, (byte) 0x50, (byte) 0x78, + (byte) 0xc3, (byte) 0x50, (byte) 0x6f, (byte) 0x89, + (byte) 0xbd, (byte) 0xa7, (byte) 0x3b, (byte) 0xb6, + (byte) 0xe3, (byte) 0xe5, (byte) 0xb8, (byte) 0xa3, + (byte) 0x68, (byte) 0x3d, (byte) 0xd3, (byte) 0x62 + }; + System.out.println("20 byte salt (same size as SHA1 output)"); + printByteArray(salts[1]); + +// salts[2] = new byte[200 / 8]; +// sr.nextBytes(salts[2]); + salts[2] = new byte[] + { + (byte) 0xe2, (byte) 0x2c, (byte) 0x7b, (byte) 0x03, + (byte) 0x16, (byte) 0x3a, (byte) 0xe5, (byte) 0x47, + (byte) 0xf8, (byte) 0x23, (byte) 0x9d, (byte) 0xa4, + (byte) 0x0d, (byte) 0x6f, (byte) 0x46, (byte) 0xd7, + (byte) 0x9e, (byte) 0xa3, (byte) 0xc6, (byte) 0xff, + (byte) 0xb3, (byte) 0xf0, (byte) 0x4e, (byte) 0xbe, + (byte) 0x61 + }; + System.out.println("25 byte salt"); + printByteArray(salts[2]); + + final String passwds[] = {"0000", "0001", "PSWD", "password", "abcdefghijklmnopqrstuvwxyz"}; + + for (int keyLenIdx = 0; keyLenIdx < keyLens.length; ++keyLenIdx) + { + for (int iterIdx = 0; iterIdx < iterCounts.length; ++iterIdx) + { + for (int saltIdx = 0; saltIdx < salts.length; ++saltIdx) + { + for (int pwdIdx = 0; pwdIdx < passwds.length; ++pwdIdx) + { + testKey(pgen, keyLens[keyLenIdx], iterCounts[iterIdx], passwds[pwdIdx], salts[saltIdx]); + } // for (int pwdIdx = 0; pwdIdx < passwds.length; ++pwdIdx) + } // for (int saltIdx = 0; saltIdx < salts.length; ++saltIdx) + } // for (int iterIdx = 0; iterIdx < iterCounts.length; ++iterIdx) + } // for (int keyLenIdx = 0; keyLenIdx < keyLens.length; ++keyLenIdx) + } + + private static void testKey( + PKCS12ParametersGenerator pgen, + int keyLen, int iterCount, String password, byte[] salt) + { + System.out.println( + "key len = " + keyLen + ", iter count = " + iterCount + + ", password = \"" + password + "\", salt len = " + salt.length); + + char[] pwChars = password.toCharArray(); + byte[] pwBytes = PBEParametersGenerator.PKCS12PasswordToBytes(pwChars); + + pgen.init(pwBytes, salt, iterCount); + KeyParameter kp = (KeyParameter) pgen.generateDerivedParameters(keyLen); + printByteArray(kp.getKey()); + } + + private static void printByteArray(byte[] a) + { + final int BLOCK_SIZE = 16; + int keyLen = a.length; + int rowCount = keyLen / BLOCK_SIZE; + if ((keyLen % BLOCK_SIZE) != 0) + ++rowCount; + + for (int row = 0; row < rowCount; ++row) + { + int start = row * BLOCK_SIZE; + int end = Math.min(start + BLOCK_SIZE, keyLen); + + StringBuffer line = new StringBuffer("[" + hexStr(start, 4) + "]"); + + for (int i = start; i < end; ++i) + line.append(" " + hexStr(a[i], 2)); + System.out.println(line); + } + System.out.println(); + } + + private static String hexStr(int val, int width) + { + StringBuffer result = new StringBuffer(); + while (--width >= 0) + { + int bitPos = 4 * width; + int nybble = (val & (0xf << bitPos)) >> bitPos; + result.append(Integer.toHexString(nybble)); + } + + return result.toString(); + } +} diff -r 7e3f204e6c81 -r f9c11be8c0b3 crypto/weakcryptospi/source/pkcs12kdf/Pkcs12Pbe.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/crypto/weakcryptospi/source/pkcs12kdf/Pkcs12Pbe.java Tue Dec 01 11:12:04 2009 +0000 @@ -0,0 +1,130 @@ +/* +* Copyright (c) 2006-2009 Nokia Corporation and/or its subsidiary(-ies). +* All rights reserved. +* This component and the accompanying materials are made available +* under the terms of the License "Eclipse Public License v1.0" +* which accompanies this distribution, and is available +* at the URL "http://www.eclipse.org/legal/epl-v10.html". +* +* Initial Contributors: +* Nokia Corporation - initial contribution. +* +* Contributors: +* +* Description: +* This program uses the Bouncy Castle APIs PKCS#12 KDF to generate encryption keys + ivs +* and mac keys for use with compatibility testing. +* +*/ + + +package com.symbian.security; + +import java.math.BigInteger; +import java.security.SecureRandom; +import org.bouncycastle.crypto.PBEParametersGenerator; +import org.bouncycastle.crypto.digests.SHA1Digest; +import org.bouncycastle.crypto.generators.PKCS12ParametersGenerator; +import org.bouncycastle.crypto.CipherParameters; +import org.bouncycastle.crypto.params.KeyParameter; +import org.bouncycastle.crypto.params.ParametersWithIV; + +public class Pkcs12Pbe { + private PKCS12ParametersGenerator pgen; + + public Pkcs12Pbe() { + pgen = new PKCS12ParametersGenerator(new SHA1Digest()); + } + + public static void main(String args[]) { + try { + if (args.length < 5) { + usage(); + System.exit(-1); + + } + int keyLength = Integer.parseInt(args[0]); + int blockSize = Integer.parseInt(args[1]); + int iterations = Integer.parseInt(args[2]); + String salt = args[3]; + String password = args[4]; + byte[] saltBytes = hexToByteArray(salt); + + Pkcs12Pbe pbe = new Pkcs12Pbe(); + pbe.getKey(keyLength, blockSize, iterations, password, saltBytes); + } + catch (Exception e) { + System.exit(-1); + } + } + + private static byte[] hexToByteArray(String hex) throws Exception { + if (hex.length() % 2 != 0) { + throw new Exception("hexToByteArray: odd number of nibbles"); + } + StringBuffer hexBuffer = new StringBuffer(hex); + + byte[] byteBuffer = new byte[hexBuffer.length() / 2]; + for (int i = 0; i < hexBuffer.length(); i+=2) { + try { + byteBuffer[i / 2] = (byte) Integer.parseInt(hexBuffer.substring(i, i+2), 16); + } + catch (NumberFormatException e) { + System.err.println("hexToByteArray: invalid hex string: " + hex); + throw e; + } + } + return byteBuffer; + } + + private static void usage() { + System.err + .println("Usage: pkcs12pbe \n"); + } + + private void getKey(int keyLen, int ivLen, int iterCount, String password, + byte[] salt) { + System.out.print("key len = " + keyLen + ", iter count = " + + iterCount + ", password = \"" + password + "\", salt = "); + printUnformattedByteArray(salt); + + char[] pwChars = password.toCharArray(); + byte[] pwBytes = PBEParametersGenerator.PKCS12PasswordToBytes(pwChars); + + pgen.init(pwBytes, salt, iterCount); + CipherParameters cp = pgen.generateDerivedParameters(keyLen, ivLen); + + ParametersWithIV ivp = (ParametersWithIV) cp; + KeyParameter kp = (KeyParameter) ivp.getParameters(); + + System.out.print("key "); + printUnformattedByteArray((kp.getKey())); + System.out.print("iv "); + printUnformattedByteArray(ivp.getIV()); + + kp = (KeyParameter) pgen.generateDerivedMacParameters(160); + System.out.print("160bit hmac key "); + printUnformattedByteArray((kp.getKey())); + + } + + // unformatted hex strings that can be passed as arguments to openssl + private void printUnformattedByteArray(byte[] a) { + StringBuffer line = new StringBuffer(); + + for (int i = 0; i < a.length; i++) { + line.append(hexStr(a[i], 2)); + } + System.out.println(line); + } + + private String hexStr(int val, int width) { + StringBuffer result = new StringBuffer(); + while (--width >= 0) { + int bitPos = 4 * width; + int nybble = (val & (0xf << bitPos)) >> bitPos; + result.append(Integer.toHexString(nybble)); + } + return result.toString(); + } +} diff -r 7e3f204e6c81 -r f9c11be8c0b3 crypto/weakcryptospi/source/pkcs12kdf/pkcs12kdf.cpp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/crypto/weakcryptospi/source/pkcs12kdf/pkcs12kdf.cpp Tue Dec 01 11:12:04 2009 +0000 @@ -0,0 +1,274 @@ +/* +* Copyright (c) 2005-2009 Nokia Corporation and/or its subsidiary(-ies). +* All rights reserved. +* This component and the accompanying materials are made available +* under the terms of the License "Eclipse Public License v1.0" +* which accompanies this distribution, and is available +* at the URL "http://www.eclipse.org/legal/epl-v10.html". +* +* Initial Contributors: +* Nokia Corporation - initial contribution. +* +* Contributors: +* +* Description: +* +*/ + + +#include +#include +#include "pkcs12kdf.h" + + +EXPORT_C HBufC8* PKCS12KDF::GeneratePasswordLC(const TDesC& aDes) +/** + Convert the supplied string to a byte string, as described + in SB.1 of the PKCS 12 v1.0. + + Each character is converted to a big endian two-byte value, + and a terminating NULL character is appended to the end. + + @param aDes String to use as password. + */ + { + const TInt len = aDes.Length(); + HBufC8* pwdBytes = HBufC8::NewMaxLC((len + 1) * 2); + TPtr8 pbDes = pwdBytes->Des(); + + TInt i = 0; + while (i < len) + { + TUint16 ch = aDes[i]; + pbDes[i * 2] = ch >> 8; + pbDes[(i * 2) + 1] = ch; + ++i; + } + pbDes[i * 2] = pbDes[(i * 2) + 1] = 0; + + return pwdBytes; + } + +static TInt CeilDiv(TInt aNumerator, TInt aDenominator) +/** + Utility function returns ceil(aNumerator / aDenominator). + + @param aNumerator The numerator. + @param aDenominator Denominator, which cannot be zero. + @return ceil(aNumerator / aDenominator) + */ + { + TInt result = aNumerator / aDenominator; + if ((aNumerator % aDenominator) > 0) + ++result; + return result; + } + +EXPORT_C void PKCS12KDF::DeriveKeyL( + TDes8& aKey, TIDByteType aIDType, + const TDesC8& aPasswd, const TDesC8& aSalt, const TUint aIterations) +/** + Generate a key for the supplied password and salt. + This implementation uses SHA1 as the hashing algorithm. + + @param aKey Descriptor which will hold key. On entry + its length must be set to the expected key length. + @param aIDType Whether this function is being called to generate + an (en|de)cryption key, an initialization vector, + or a key for MAC-ing. See SB.3 of spec. + @param aPasswd Password string. To comply with PKCS#12 spec, + this must have 2-byte big-endian characters with + a terminating null character. + @param aSalt Used with aPasswd to generate key. + @param aIterations Number of times to call the hash function for + each block in the key. + + @panic PKCS#12 16 Password is empty (debug only.) + @panic PKCS#12 17 Password does not contain an even number of bytes, + and so can't use double-byte characters (debug only.) + @panic PKCS#12 18 The final two-byte character is not a null terminator, + or a null terminator occurs before the end (debug only.) + */ + { + __ASSERT_DEBUG(aPasswd.Length() >= 2, Panic(EDKEmptyPswd)); + __ASSERT_DEBUG((aPasswd.Length() % 2) == 0, Panic(EDKOddPswdByteCount)); + TInt useCharCount = aPasswd.Length() / 2; + TPtrC16 pswd16(reinterpret_cast(aPasswd.Ptr()), useCharCount); + TInt nullPos = pswd16.Locate(L'\0'); + __ASSERT_DEBUG(nullPos == (useCharCount - 1), Panic(EDKBadNullTerminator)); + + // use the same notation as the standard + const TUint8 ID = static_cast(aIDType); + const TInt u = 160; // chaining variable length for SHA-1 + const TInt v = 512; // message input length for SHA-1 + const TInt n = aKey.Length() * 8; // number of bits required in key + const TInt p = aPasswd.Length(); + const TInt s = aSalt.Length(); + const TInt r = aIterations; + + // (numbered steps are from the standard) + // 1. Construct a string, D (the "diversifier"), by concatenating + // v/8 copies of ID. + const TInt D_LEN = v / 8; + HBufC8* D_ = HBufC8::NewMaxLC(D_LEN); + TPtr8 D = D_->Des(); + D.Fill(ID); + + // 2. Concatenate copies of the salt together to create a string S + // of length v * ceil(s/v) bits (the final copy of the salt may be + // truncated to create S). Note that if the salt is the empty string, + // then so is S. + const TInt S_OVER_V_CEIL = CeilDiv(s, v); + const TInt S_LEN = (v * S_OVER_V_CEIL) / 8; + HBufC8* S_ = HBufC8::NewMaxLC(S_LEN); + TPtr8 S = S_->Des(); + S.Repeat(aSalt); + + // 3. Concatenate copies of the password together to create a string P + // of length v * ceil(p/v) bits (the final copy of the password may be + // truncated to create P). Note that if the password is the empty string + // then so is P. + const TInt P_OVER_V_CEIL = CeilDiv(p, v); + const TInt P_LEN = (v * P_OVER_V_CEIL) / 8; + HBufC8* P_ = HBufC8::NewMaxLC(P_LEN); + TPtr8 P = P_->Des(); + P.Repeat(aPasswd); + + // 4. Set I=S||P to be the concatenation of S and P. + const TInt I_LEN = S_LEN + P_LEN; + HBufC8* I_ = HBufC8::NewLC(I_LEN); + TPtr8 I = I_->Des(); + I.Copy(S); + I.Append(P); + + // 5. Set c=ceil(n/u). + const TInt c = CeilDiv(n, u); + + // ahead 7: allocate result buffer A + // (Each Ai has SHA1_HASH bytes.) + HBufC8* A_ = HBufC8::NewLC(c * SHA1_HASH); + TPtr8 A = A_->Des(); + + // 6. For i=1, 2, ..., c, do the following + + // pre-allocate SHA1 object, DI, and B buffers + CSHA1* sha1 = CSHA1::NewL(); + CleanupStack::PushL(sha1); + + const TInt DI_LEN = D_LEN + I_LEN; + HBufC8* DI_ = HBufC8::NewLC(DI_LEN); + TPtr8 DI = DI_->Des(); + + const TInt B_LEN = v / 8; + HBufC8* B_ = HBufC8::NewMaxLC(B_LEN); + TPtr8 B = B_->Des(); + + for (TInt i = 1; i <= c; ++i) + { + // 6a) Set Ai = H^r(D||I). (i.e. the rth hash of D||I, + // H(H(H(...H(D||I)))) + DI.Copy(D); + DI.Append(I); + + sha1->Reset(); + TBuf8 Ai(sha1->Final(DI)); + + for (TInt iterCount = 2; iterCount <= r; ++iterCount) + { + Ai.Copy(sha1->Final(Ai)); + } + + // 6b) Concatenate copies of Ai to create a string B of length + // v bits (the final copy of Ai may be truncated to create B). + B.Repeat(Ai); + + // 6c) Treating I as a concatenation I0, I1, ..., Ik-1 of + // v-bit blocks, where k=ceil(s/v)+ceil(p/v), modify I by + // setting Ij=(Ij+B+1) mod 2^v for each j. + + const TInt k = S_OVER_V_CEIL + P_OVER_V_CEIL; + for (TInt j = 0; j < k; ++j) + { + TPtr8 section = I.MidTPtr((v/8) * j, v/8); + Process6cL(section, B, v); + } + + // 7. Concatenate A1, A2, ..., Ac together to form a pseudo-random + // bit string, A. + A.Append(Ai); + + // stop building A if already have enough bits for key + if (A.Length() >= n / 8) + break; + } + + // Use the first n bits of A as the output of this entire process. + aKey.Copy(A.Left(n / 8)); + + CleanupStack::PopAndDestroy(8, D_); // B_, DI_, sha1, A_, I_, P_, S_, D_ + } + +void PKCS12KDF::Process6cL(TDes8& Ij, const TDesC8& B, TInt v) +/** + Helper function for DeriveKeyL modifies part of I, + as described in step 6c of SB.2. + + @param Ij Section of I (S || P). + @param B rth hash of D || I. + @param v Number of bits to preserve in result. + */ + { + // 6c) Treating I as a concatenation I0, I1, ..., Ik-1 of + // v-bit blocks, where k=ceil(s/v)+ceil(p/v), modify I by + // setting Ij=(Ij+B+1) mod 2^v for each j. + + RInteger RI_Ij = RInteger::NewL(Ij); + TCleanupItem ciIj = RI_Ij; + CleanupStack::PushL(ciIj); + + RInteger RI_B = RInteger::NewL(B); + TCleanupItem ciB = RI_B; + CleanupStack::PushL(ciB); + + // these additions can leave + RI_Ij += RI_B; + RI_Ij += 1; + + HBufC8* result = RI_Ij.BufferLC(); + + Ij.Zero(); + TInt resultLen = result->Length(); + + TInt bytesToPreserve = v / 8; + TInt leadingZeroes = bytesToPreserve - resultLen; + if (leadingZeroes <= 0) + Ij.Copy(result->Right(bytesToPreserve)); + else + { + Ij.FillZ(leadingZeroes); + Ij.Append(*result); + } + + CleanupStack::PopAndDestroy(3, &RI_Ij); // result, ciB, ciIj + } + +#ifdef _DEBUG + +void PKCS12KDF::Panic(PKCS12KDF::TPanic aPanic) +/** + This function is used in debug builds to halt + the current thread when a logic error is detected. + + The current thread is panicked with category "PKCS12KDF" + and the supplied reason. + + @param aPanic Converted to numeric value and + used for the panic reason. + */ + { + _LIT(KPanicCat, "PKCS12KDF"); + User::Panic(KPanicCat, aPanic); + } + +#endif + diff -r 7e3f204e6c81 -r f9c11be8c0b3 crypto/weakcryptospi/source/pkcs5kdf/pkcs5kdf.cpp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/crypto/weakcryptospi/source/pkcs5kdf/pkcs5kdf.cpp Tue Dec 01 11:12:04 2009 +0000 @@ -0,0 +1,115 @@ +/* +* Copyright (c) 2005-2009 Nokia Corporation and/or its subsidiary(-ies). +* All rights reserved. +* This component and the accompanying materials are made available +* under the terms of the License "Eclipse Public License v1.0" +* which accompanies this distribution, and is available +* at the URL "http://www.eclipse.org/legal/epl-v10.html". +* +* Initial Contributors: +* Nokia Corporation - initial contribution. +* +* Contributors: +* +* Description: +* +*/ + + +/** + @file +*/ + +#include "pkcs5kdf.h" + +/* Before complaining about the variable names in this file, + * read the pkcs5 spec and all will become clear. + */ + +EXPORT_C void TPKCS5KDF::DeriveKeyL(TDes8& aKey, const TDesC8& aPasswd, const TDesC8& aSalt, + const TUint aIterations) +{ + CSHA1* sha1 = CSHA1::NewL(); + CleanupStack::PushL(sha1); + CHMAC* hmac = CHMAC::NewL(aPasswd, sha1); + CleanupStack::Pop(sha1); //hmac now owns it + CleanupStack::PushL(hmac); + + TUint hashBytes = hmac->HashSize(); + TUint c = aIterations; + TUint l = aKey.Length() / hashBytes; + if(aKey.Length() % hashBytes != 0) //round up if mod !=0 + { + l+=1; + } + TUint r = aKey.Length() - (l-1) * hashBytes; //r == length of last block + + HBufC8* TiTemp = HBufC8::NewLC(hashBytes); + TUint32* Ti = (TUint32*)(TiTemp->Ptr()); + aKey.SetLength(0); //we've already saved the length we want + + HBufC8* STemp = HBufC8::NewLC(aSalt.Length() + sizeof(TUint32)); + TUint32* S = (TUint32*)(STemp->Ptr()); + + HBufC8* UiTemp = HBufC8::NewLC(hashBytes); + TUint32* Ui = (TUint32*)(UiTemp->Ptr()); + + const TUint32* salt = (TUint32*)(aSalt.Ptr()); + TUint saltBytes = aSalt.Length(); + + for(TUint i = 1; i<=l; i++) + { + F(*hmac, Ti, S, Ui, hashBytes, salt, saltBytes, c, i); + if(i == l) + aKey.Append((TUint8*)Ti, r); + else + aKey.Append((TUint8*)Ti, hashBytes); + } + + CleanupStack::PopAndDestroy(UiTemp); + CleanupStack::PopAndDestroy(STemp); + CleanupStack::PopAndDestroy(TiTemp); + CleanupStack::PopAndDestroy(hmac); + } + +void TPKCS5KDF::F(CMessageDigest& aDigest, TUint32* aAccumulator, + TUint32* S, TUint32* Ui, TUint aHashBytes, const TUint32* aSalt, + TUint aSaltBytes, TUint c, TUint i) + { + TUint8 itmp[4]; + itmp[0] = (TUint8)((i >> 24) & 0xff); + itmp[1] = (TUint8)((i >> 16) & 0xff); + itmp[2] = (TUint8)((i >> 8) & 0xff); + itmp[3] = (TUint8)(i & 0xff); + TUint8* endOfS = Mem::Copy(S, aSalt, aSaltBytes); + Mem::Copy((TUint32*)endOfS, (TUint32*)&itmp, 4); + + TPtr8 sptr((TUint8*)S, aSaltBytes+4); + sptr.SetLength(aSaltBytes+4); + Mem::Copy(aAccumulator, (TUint32*)((aDigest.Final(sptr)).Ptr()),aHashBytes); + Mem::Copy(Ui, aAccumulator, aHashBytes); + + for(TUint j=1; j +#include +#include "sha1shim.h" + +CMessageDigest::CMessageDigest(void):CBase() +{} + +CMessageDigest::CMessageDigest(const CMessageDigest& /*aMD*/):CBase() +{} + +CMessageDigest::~CMessageDigest(void) +{} + +TInt CMessageDigest::GetExtension(TUint aExtensionId, TAny*& a0, TAny* a1) + { + return Extension_(aExtensionId, a0, a1); + } + + +////////////////////////////////////////////////////////////////// +// Factory class to create CMessageDigest derived objects +////////////////////////////////////////////////////////////////// +CMessageDigest* CMessageDigestFactory::NewDigestL(CMessageDigest::THashId aHashId) +{ + CMessageDigest* hash = NULL; + switch (aHashId) + { + case (CMessageDigest::ESHA1): + { + hash = CSHA1Shim::NewL(); + break; + } + default: + User::Leave(KErrNotSupported); + } + + return (hash); +} + +CMessageDigest* CMessageDigestFactory::NewDigestLC(CMessageDigest::THashId aHashId) +{ + CMessageDigest* hash = CMessageDigestFactory::NewDigestL(aHashId); + CleanupStack::PushL(hash); + return (hash); +} + diff -r 7e3f204e6c81 -r f9c11be8c0b3 crypto/weakcryptospi/source/random/random.cpp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/crypto/weakcryptospi/source/random/random.cpp Tue Dec 01 11:12:04 2009 +0000 @@ -0,0 +1,117 @@ +/* +* Copyright (c) 2005-2009 Nokia Corporation and/or its subsidiary(-ies). +* All rights reserved. +* This component and the accompanying materials are made available +* under the terms of the License "Eclipse Public License v1.0" +* which accompanies this distribution, and is available +* at the URL "http://www.eclipse.org/legal/epl-v10.html". +* +* Initial Contributors: +* Nokia Corporation - initial contribution. +* +* Contributors: +* +* Description: +* +*/ + + +/** + @file +*/ + +#include +#include +#include +#include + +#include "randsvr.h" +#include "randcliserv.h" +#include "randomshim.h" + +extern "C" { +EXPORT_C void RAND_bytes(unsigned char* buf,int bytes) + { + TPtr8 ptr(buf,bytes,bytes); + buf[0]++; + TRandom::Random(ptr); + } +} + +EXPORT_C CRandom::CRandom(void) + { + } + +EXPORT_C CSystemRandom* CSystemRandom::NewL(void) + { + CSystemRandom* self = NewLC(); + CleanupStack::Pop(self); + return self; + } + +EXPORT_C CSystemRandom* CSystemRandom::NewLC(void) + { + CSystemRandom* self = new(ELeave)CSystemRandom(); + CleanupStack::PushL(self); + self->ConstructL(); + return self; + } + +void CSystemRandom::GenerateBytesL(TDes8& aDest) + { + iShim->GenerateBytesL(aDest); + } + +CSystemRandom::CSystemRandom(void) + { + } + +CSystemRandom::~CSystemRandom() + { + delete iShim; + } + +void CSystemRandom::ConstructL() + { + iShim = CRandomShim::NewL(); + } + +// Methods replace by shim are excluded from coverage. +#ifdef _BullseyeCoverage +#pragma suppress_warnings on +#pragma BullseyeCoverage off +#pragma suppress_warnings off +#endif +EXPORT_C void TRandom::Random(TDes8& aDestination) + { + // Method replaced by shim + TRandomShim::Random(aDestination); + } + +EXPORT_C void TRandom::RandomL(TDes8& aDestination) + { + // Method replaced by shim + TRandomShim::RandomL(aDestination); + } + +EXPORT_C RRandomSession::RRandomSession(void) + { + } + +EXPORT_C void RRandomSession::ConnectL(void) + { + // All of the ConnectL() code has moved to randomimpl.cpp + // in the new CryptoSPI pluggable framework. This is just + // a stub now that is retained for binary compatibility. + + // Method replaced by shim + ASSERT(EFalse); + } + +EXPORT_C TInt RRandomSession::GetRandom(TDes8& aDestination) + { + // Method replaced by shim + TRandomShim::Random(aDestination); + return KErrNone; + } + diff -r 7e3f204e6c81 -r f9c11be8c0b3 crypto/weakcryptospi/source/random/randomshim.cpp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/crypto/weakcryptospi/source/random/randomshim.cpp Tue Dec 01 11:12:04 2009 +0000 @@ -0,0 +1,105 @@ +/* +* Copyright (c) 2006-2009 Nokia Corporation and/or its subsidiary(-ies). +* All rights reserved. +* This component and the accompanying materials are made available +* under the terms of the License "Eclipse Public License v1.0" +* which accompanies this distribution, and is available +* at the URL "http://www.eclipse.org/legal/epl-v10.html". +* +* Initial Contributors: +* Nokia Corporation - initial contribution. +* +* Contributors: +* +* Description: +* random shim implementation +* random shim implementation +* +*/ + + +/** + @file +*/ + +#include "randomshim.h" +#include +#include +#include +#include "keys.h" +#include + + +using namespace CryptoSpi; + +_LIT(KRandomFail, "Cannot obtain randomness"); + +// +// Random shim implementation +// +CRandomShim* CRandomShim::NewL() + { + CRandomShim* self = CRandomShim::NewLC(); + CleanupStack::Pop(); + return self; + } + +CRandomShim* CRandomShim::NewLC() + { + CRandomShim* self = new(ELeave) CRandomShim(); + CleanupStack::PushL(self); + self->ConstructL(); + return self; + } + +void CRandomShim::GenerateBytesL(TDes8& aDest) + { + iRandomImpl->GenerateRandomBytesL(aDest); + } + +CRandomShim::CRandomShim() + { + } + +CRandomShim::~CRandomShim() + { + delete iRandomImpl; + } + +void CRandomShim::ConstructL() + { + CRandomFactory::CreateRandomL(iRandomImpl, KRandomUid, NULL); + } + +/** + * @deprecated Use RandomL() instead + * @panic This function can panic under low memory conditions + * See PDEF097319: TRandom::Random panics during OOM + * This method is preserved only for BC reasons + */ +void TRandomShim::Random(TDes8& aDest) + { + CRandomShim* rand = NULL; + TRAPD(ret, rand = CRandomShim::NewL()); + if (ret != KErrNone) + { + User::Panic(KRandomFail, ret); + } + TRAPD(ret2, rand->GenerateBytesL(aDest)); + delete rand; + if (ret2 != KErrNone) + { + // this method can't leave so the cleanup stack can't be used (because of PushL()) + // so we just delete the randon shim here if GenerateBytesL() leaves + User::Panic(KRandomFail, ret); + } + } + +void TRandomShim::RandomL(TDes8& aDest) + { + CRandomShim* rand = CRandomShim::NewL(); + CleanupStack::PushL(rand); + rand->GenerateBytesL(aDest); + CleanupStack::PopAndDestroy(rand); // Use a singleton, avoid new overhead? + } + diff -r 7e3f204e6c81 -r f9c11be8c0b3 crypto/weakcryptospi/source/random/randomshim.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/crypto/weakcryptospi/source/random/randomshim.h Tue Dec 01 11:12:04 2009 +0000 @@ -0,0 +1,61 @@ +/* +* Copyright (c) 2006-2009 Nokia Corporation and/or its subsidiary(-ies). +* All rights reserved. +* This component and the accompanying materials are made available +* under the terms of the License "Eclipse Public License v1.0" +* which accompanies this distribution, and is available +* at the URL "http://www.eclipse.org/legal/epl-v10.html". +* +* Initial Contributors: +* Nokia Corporation - initial contribution. +* +* Contributors: +* +* Description: +* random shim class definition +* +*/ + + +/** + @file + @internalComponent + @released +*/ + +#ifndef __RANDOMSHIM_H__ +#define __RANDOMSHIM_H__ + +#include +#include +#include + +// +// CRandom shim class +// +NONSHARABLE_CLASS(CRandomShim) : public CBase + { +public: + static CRandomShim* NewL(); + static CRandomShim* NewLC(); + ~CRandomShim(); + virtual void GenerateBytesL(TDes8& aDest); + +private: + CRandomShim(); + CRandomShim(const CRandomShim&); + CRandomShim& operator=(const CRandomShim&); + void ConstructL(); + +private: + CryptoSpi::CRandom* iRandomImpl; + }; + +class TRandomShim + { +public: + static void Random(TDes8& aDestination); + static void RandomL(TDes8& aDestination); + }; + +#endif // __RANDOMSHIM_H__ diff -r 7e3f204e6c81 -r f9c11be8c0b3 crypto/weakcryptospi/source/random/randsvr.cpp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/crypto/weakcryptospi/source/random/randsvr.cpp Tue Dec 01 11:12:04 2009 +0000 @@ -0,0 +1,255 @@ +/* +* Copyright (c) 2005-2009 Nokia Corporation and/or its subsidiary(-ies). +* All rights reserved. +* This component and the accompanying materials are made available +* under the terms of the License "Eclipse Public License v1.0" +* which accompanies this distribution, and is available +* at the URL "http://www.eclipse.org/legal/epl-v10.html". +* +* Initial Contributors: +* Nokia Corporation - initial contribution. +* +* Contributors: +* +* Description: +* +*/ + + +/** + @file +*/ + +#include "randsvr.h" +#include "randcliserv.h" +#include "sha1shim.h" +#include +#include "randsvrimpl.h" + +//const TInt KFastTickTimer=1000000; // These are testing numbers! +//const TInt KSlowTickTimer=30000000; +const TInt KThreshold=1024; + +const TInt KFastTickTimer=30000000; // These are the real numbers! +const TInt KSlowTickTimer=0x7fffffff; + +using namespace CryptoSpi; + +void SignalClient() +// +// Signal the owning thread that the server has started successfully +// This may itself fail +// + { + RProcess::Rendezvous(KErrNone); + } + + +TInt RunRandomServer(TAny* /*aUnused*/) + { + + __UHEAP_MARK; + + CTrapCleanup* cleanup=CTrapCleanup::New(); + if (!cleanup) + { + return KErrNoMemory; + } + + TInt ret = User::RenameThread(KRandomServerName); + + __ASSERT_ALWAYS(ret==KErrNone,User::Panic(KRandomServerName,KErrServerTerminated)); + + if (CRandomScheduler::New()) + return KErrNoMemory; + CRandomServer* random(0); + TRAP(ret, random = CRandomServer::NewL()); + if (ret != KErrNone) + return ret; + random->Start(KRandomServerName); + // Initialisation complete, now signal the client + SignalClient(); + + CRandomScheduler::Start(); + delete random; + delete cleanup; + + __UHEAP_MARKEND; + return KErrNone; + } + +TBool CRandomScheduler::New(void) + { + CRandomScheduler* rs; + rs=new CRandomScheduler; + CRandomScheduler::Install(rs); + return (rs == NULL); + } + +void CRandomScheduler::Error(TInt /*aError*/) const + { + User::Panic(KRandomServerName, 3); + } + +CRandomServer::CRandomServer(void) : CServer2(EPriorityLow) + { + } + +CRandomServer::~CRandomServer(void) + { + // This should never happen....but in case it does: + delete iHash; + delete iTicker; + delete iPool; + } + +CRandomServer* CRandomServer::NewL(void) + { + CRandomServer* self = new (ELeave) CRandomServer; + CleanupStack::PushL(self); + self->ConstructL(); + CleanupStack::Pop(self); + return self; + } + +void CRandomServer::ConstructL(void) + { + iPool=new (ELeave) TUint8[KRandomPoolSize]; + iHash=CSHA1Shim::NewL(); + iPoolIn=0; + iPoolOut=0; + iTicker=CPeriodic::NewL(EPriorityLow); + TCallBack callback(Tick,this); + iTicker->Start(KFastTickTimer,KFastTickTimer,callback); // **** these figures might need tweaking! + iQuality=0; + iFast=ETrue; + } + +TInt CRandomServer::Tick(TAny* aServer) + { + CRandomServer* svr=(CRandomServer*)aServer; + svr->Stir(); + svr->iQuality+=30; + if (svr->iFast) + { + if (svr->iQuality>KThreshold) + { + TCallBack callback(Tick,svr); + svr->iTicker->Cancel(); + svr->iTicker->Start(KSlowTickTimer,KSlowTickTimer,callback); // **** these figures might need tweaking! + svr->iFast=EFalse; + } + } + if (svr->iQuality>(KRandomPoolSize<<3)) + { + svr->iQuality=(KRandomPoolSize<<3); + } + return ETrue; + } + +CSession2* CRandomServer::NewSessionL(const TVersion& /*aVersion*/, const RMessage2& /*aMessage*/) const + { + return CRandomSession::NewL(const_cast(this)); + //CRandomSession::NewL(CONST_CAST(CRandomServer*,this),Message().Client()); + } + +TPtrC8 CRandomServer::GetRandom(void) + { + TPtr8 res(&iPool[iPoolOut],iHash->HashSize(),iHash->HashSize()); + iPoolOut+=iHash->HashSize(); + if ((iPoolOut+iHash->HashSize())>KRandomPoolSize) + { + iPoolOut=0; + } + return iHash->Hash(res); + } + +CMessageDigest* CRandomServer::Hash(void) const + { + return iHash; + } + +void CRandomServer::Stir(void) + { + TInt rnd; + rnd=Math::Random(); + TPtrC8 r((TUint8*)&rnd,sizeof(TInt)); + iHash->Hash(r); + TPtr8 dest(&iPool[iPoolIn],iHash->HashSize()); + dest.Copy(iHash->Hash(dest)); + iPoolIn+=iHash->HashSize(); + if ((iPoolIn+iHash->HashSize())>KRandomPoolSize) + { + iPoolIn=0; + } + } + +CRandomSession* CRandomSession::NewL(CRandomServer* aServer) + { + CRandomSession* self; + self=new (ELeave) CRandomSession(aServer); + return self; + } + +CRandomSession::CRandomSession(CRandomServer* aServer) : CSession2(), iServer(aServer) + { + } + +CRandomSession::~CRandomSession(void) + { + } + +void CRandomSession::ServiceL(const RMessage2& aMessage) + { + switch (aMessage.Function()) + { + case KRandomRequest: + { + TInt ret = FillBuffer(aMessage); + aMessage.Complete(ret); + break; + } + default: + aMessage.Complete(KErrNotSupported); + break; + }; + } + +TInt CRandomSession::FillBuffer(const RMessage2& aMessage) + { + TInt length = aMessage.Int1(); + iServer->iQuality -= length; + if (iServer->iQuality<0) + { + iServer->iQuality=0; + } + if (!iServer->iFast) + { + if (iServer->iQualityiTicker->Cancel(); + iServer->iTicker->Start(KFastTickTimer,KFastTickTimer,callback); // **** these figures might need tweaking! + iServer->iFast=ETrue; + } + } + TBuf8 buf(0); + iServer->Stir(); + TInt i; + TInt hashsize=iServer->Hash()->HashSize(); + for (i=0; i+hashsize < length; i+=hashsize) + { + buf.Append(iServer->GetRandom()); + iServer->Stir(); + } + TPtrC8 ptr(iServer->GetRandom().Ptr(), length-i); + buf.Append(ptr); + + TRAPD(ret, aMessage.WriteL(0, buf)); + return ret; + } + +GLDEF_C TInt E32Main(void) + { + return RunRandomServer(NULL); + } diff -r 7e3f204e6c81 -r f9c11be8c0b3 crypto/weakcryptospi/source/random/sha1impl.cpp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/crypto/weakcryptospi/source/random/sha1impl.cpp Tue Dec 01 11:12:04 2009 +0000 @@ -0,0 +1,743 @@ +/* +* Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies). +* All rights reserved. +* This component and the accompanying materials are made available +* under the terms of the License "Eclipse Public License v1.0" +* which accompanies this distribution, and is available +* at the URL "http://www.eclipse.org/legal/epl-v10.html". +* +* Initial Contributors: +* Nokia Corporation - initial contribution. +* +* Contributors: +* +* Description: +* software sha1 implementation +* software sha1 implementation +* +*/ + + +/** + @file +*/ + +#include "sha1impl.h" + +#include +#include "pluginconfig.h" +#define EXPANDLOOP + + +using namespace SoftwareCrypto; + +CSHA1Impl* CSHA1Impl::NewL() + { + CSHA1Impl* self=new (ELeave) CSHA1Impl(); + self->Reset(); + return self; + } + +CSHA1Impl::CSHA1Impl() : iHash(KSHA1HashSize) + { + } + +void CSHA1Impl::Reset() + { + iA=0x67452301; + iB=0xefcdab89; + iC=0x98badcfe; + iD=0x10325476; + iE=0xc3d2e1f0; + iNh=0; + iNl=0; + } + +TUid CSHA1Impl::ImplementationUid() + { + return KCryptoPluginSha1Uid; + } + +void CSHA1Impl::GetCharacteristicsL(const TCharacteristics*& aPluginCharacteristics) + { + aPluginCharacteristics=NULL; + TInt hashNum=sizeof(KHashCharacteristics)/sizeof(THashCharacteristics*); + for (TInt i=0;icmn.iImplementationUID == ImplementationUid().iUid) + { + aPluginCharacteristics = KHashCharacteristics[i]; + break; + } + } + } + +TPtrC8 CSHA1Impl::Hash(const TDesC8& aMessage) + { + TPtrC8 ptr(KNullDesC8()); + DoUpdate(aMessage.Ptr(),aMessage.Size()); + StoreState(); + DoFinal(); + ptr.Set(iHash); + RestoreState(); + return ptr; + } + +// This assumes a big-endian architecture +void CSHA1Impl::DoUpdate(const TUint8* aData,TUint aLength) + { + while((aLength / 4) > 0 && (iNl % 4 == 0)) + { + iData[iNl>>2] = aData[0] << 24 | aData[1] << 16 | aData[2] << 8 | aData[3]; + iNl+=4; + aData+=4; + aLength-=4; + if(iNl==64) + { + Block(); + iNh+=64; + iNl=0; + } + } + + while(aLength--) + { + switch (iNl&3) + { + case 0: + iData[iNl>>2]=((TUint)(*aData))<<24; + break; + case 1: + iData[iNl>>2]|=((TUint)(*aData))<<16; + break; + case 2: + iData[iNl>>2]|=((TUint)(*aData))<<8; + break; + case 3: + iData[iNl>>2]|=((TUint)(*aData)); + break; + default: + break; + }; + aData++; + iNl++; + if(iNl==64) + { + Block(); + iNh+=64; + iNl=0; + } + } + } + +static inline TUint CSHA1_F(const TUint x,const TUint y,const TUint z) + { + return (x&y) | (~x&z); + } + +static inline TUint CSHA1_G(const TUint x,const TUint y,const TUint z) + { + return x^y^z; + } + +static inline TUint CSHA1_H(const TUint x,const TUint y,const TUint z) + { + return (x&y) | (x&z) | (y&z); + } + +/*static inline TUint CSHA1_I(const TUint x,const TUint y,const TUint z) + { + return x^y^z; + }*/ + +#ifdef EXPANDLOOP + +#ifdef MACRO + +#define CSHA1_16(x,y,z,u,t,v,w) v=CMD_R(x,5)+CSHA1_F(y,z,u)+t+w+0x5a827999;\ + y=CMD_R(y,30);t=v; +#define CSHA1_20(x,y,z,u,t,v,w0,w3,w8,w14,w16) v=w3^w8^w14^w16;w0=CMD_R(v,1);\ + CSHA1_16(x,y,z,u,t,v,w0); +#define CSHA1_40(x,y,z,u,t,v,w0,w3,w8,w14,w16) v=w3^w8^w14^w16;w0=CMD_R(v,1);\ + v=CMD_R(x,5)+CSHA1_G(y,z,u)+t+w0+0x6ed9eba1;\ + y=CMD_R(y,30);t=v; +#define CSHA1_60(x,y,z,u,t,v,w0,w3,w8,w14,w16) v=w3^w8^w14^w16;w0=CMD_R(v,1);\ + v=CMD_R(x,5)+CSHA1_H(y,z,u)+t+w0+0x8f1bbcdc;\ + y=CMD_R(y,30);t=v; +#define CSHA1_80(x,y,z,u,t,v,w0,w3,w8,w14,w16) v=w3^w8^w14^w16;w0=CMD_R(v,1);\ + v=CMD_R(x,5)+CSHA1_G(y,z,u)+t+w0+0xca62c1d6;\ + y=CMD_R(y,30);t=v; +#else + +static inline void CSHA1_16(const TUint x, TUint& y, const TUint z, + const TUint u, TUint& t, TUint& v, const TUint w) + { + v = CMD_R(x,5) + CSHA1_F(y,z,u) + t + w + 0x5a827999; + y = CMD_R(y,30); + t = v; + } + +static inline void CSHA1_20(const TUint x,TUint& y,const TUint z, + const TUint u,TUint& t,TUint& v, + TUint& w0,const TUint w3,const TUint w8, + const TUint w14,const TUint w16) + { + v = w3 ^ w8 ^ w14 ^ w16; + w0 = CMD_R(v,1); + CSHA1_16(x,y,z,u,t,v,w0); + } + +static inline void CSHA1_40(const TUint x,TUint& y,const TUint z, + const TUint u,TUint& t,TUint& v, + TUint& w0,const TUint w3,const TUint w8, + const TUint w14,const TUint w16) + { + v = w3 ^ w8 ^ w14 ^ w16; + w0 = CMD_R(v,1); + v = CMD_R(x,5) + CSHA1_G(y,z,u) + t + w0 + 0x6ed9eba1; + y = CMD_R(y,30); + t = v; + } + +static inline void CSHA1_60(const TUint x,TUint& y,const TUint z, + const TUint u,TUint& t,TUint& v, + TUint& w0,const TUint w3,const TUint w8, + const TUint w14,const TUint w16) + { + v = w3 ^ w8 ^ w14 ^ w16; + w0 = CMD_R(v,1); + v = CMD_R(x,5) + CSHA1_H(y,z,u) + t + w0 + 0x8f1bbcdc; + y = CMD_R(y,30); + t = v; + } + +static inline void CSHA1_80(const TUint x,TUint& y,const TUint z, + const TUint u,TUint& t,TUint& v, + TUint& w0,const TUint w3,const TUint w8, + const TUint w14,const TUint w16) + { + v = w3 ^ w8 ^ w14 ^ w16; + w0 = CMD_R(v,1); + v = CMD_R(x,5) + CSHA1_G(y,z,u) + t + w0 + 0xca62c1d6; + y = CMD_R(y,30); + t = v; + } + +#endif // MACRO +#endif // EXPANDLOOP + +#ifdef WEIDAI + +template inline T rotlFixed(T x, unsigned int y) +{ + ASSERT(y < sizeof(T)*8); + return (x<>(sizeof(T)*8-y)); +} + +template<> inline TUint32 rotlFixed(TUint32 x, unsigned int y) +{ + ASSERT(y < 32); + return y ? CMD_R(x, y) : x; +} + +#define blk0(i) (W[i] = iData[i]) +#define blk1(i) (W[i&15] = rotlFixed(W[(i+13)&15]^W[(i+8)&15]^W[(i+2)&15]^W[i&15],1)) + +#define f1(x,y,z) (z^(x&(y^z))) +#define f2(x,y,z) (x^y^z) +#define f3(x,y,z) ((x&y)|(z&(x|y))) +#define f4(x,y,z) (x^y^z) + +/* (R0+R1), R2, R3, R4 are the different operations used in SHA1 */ +#define R0(v,w,x,y,z,i) z+=f1(w,x,y)+blk0(i)+0x5A827999+rotlFixed(v,5);w=rotlFixed(w,30); +#define R1(v,w,x,y,z,i) z+=f1(w,x,y)+blk1(i)+0x5A827999+rotlFixed(v,5);w=rotlFixed(w,30); +#define R2(v,w,x,y,z,i) z+=f2(w,x,y)+blk1(i)+0x6ED9EBA1+rotlFixed(v,5);w=rotlFixed(w,30); +#define R3(v,w,x,y,z,i) z+=f3(w,x,y)+blk1(i)+0x8F1BBCDC+rotlFixed(v,5);w=rotlFixed(w,30); +#define R4(v,w,x,y,z,i) z+=f4(w,x,y)+blk1(i)+0xCA62C1D6+rotlFixed(v,5);w=rotlFixed(w,30); + +#endif // WEIDAI + +void CSHA1Impl::Block() + { +#ifdef WEIDAI + TUint32 W[16]; + /* Copy context->state[] to working vars */ + TUint32 a = iA; + TUint32 b = iB; + TUint32 c = iC; + TUint32 d = iD; + TUint32 e = iE; + + /* 4 rounds of 20 operations each. Loop unrolled. */ + + R0(a,b,c,d,e, 0); + R0(e,a,b,c,d, 1); + R0(d,e,a,b,c, 2); + R0(c,d,e,a,b, 3); + R0(b,c,d,e,a, 4); + R0(a,b,c,d,e, 5); + R0(e,a,b,c,d, 6); + R0(d,e,a,b,c, 7); + R0(c,d,e,a,b, 8); + R0(b,c,d,e,a, 9); + R0(a,b,c,d,e,10); + R0(e,a,b,c,d,11); + R0(d,e,a,b,c,12); + R0(c,d,e,a,b,13); + R0(b,c,d,e,a,14); + R0(a,b,c,d,e,15); + + R1(e,a,b,c,d,16); + R1(d,e,a,b,c,17); + R1(c,d,e,a,b,18); + R1(b,c,d,e,a,19); + + R2(a,b,c,d,e,20); + R2(e,a,b,c,d,21); + R2(d,e,a,b,c,22); + R2(c,d,e,a,b,23); + R2(b,c,d,e,a,24); + R2(a,b,c,d,e,25); + R2(e,a,b,c,d,26); + R2(d,e,a,b,c,27); + R2(c,d,e,a,b,28); + R2(b,c,d,e,a,29); + R2(a,b,c,d,e,30); + R2(e,a,b,c,d,31); + R2(d,e,a,b,c,32); + R2(c,d,e,a,b,33); + R2(b,c,d,e,a,34); + R2(a,b,c,d,e,35); + R2(e,a,b,c,d,36); + R2(d,e,a,b,c,37); + R2(c,d,e,a,b,38); + R2(b,c,d,e,a,39); + + R3(a,b,c,d,e,40); + R3(e,a,b,c,d,41); + R3(d,e,a,b,c,42); + R3(c,d,e,a,b,43); + R3(b,c,d,e,a,44); + R3(a,b,c,d,e,45); + R3(e,a,b,c,d,46); + R3(d,e,a,b,c,47); + R3(c,d,e,a,b,48); + R3(b,c,d,e,a,49); + R3(a,b,c,d,e,50); + R3(e,a,b,c,d,51); + R3(d,e,a,b,c,52); + R3(c,d,e,a,b,53); + R3(b,c,d,e,a,54); + R3(a,b,c,d,e,55); + R3(e,a,b,c,d,56); + R3(d,e,a,b,c,57); + R3(c,d,e,a,b,58); + R3(b,c,d,e,a,59); + + R4(a,b,c,d,e,60); + R4(e,a,b,c,d,61); + R4(d,e,a,b,c,62); + R4(c,d,e,a,b,63); + R4(b,c,d,e,a,64); + R4(a,b,c,d,e,65); + R4(e,a,b,c,d,66); + R4(d,e,a,b,c,67); + R4(c,d,e,a,b,68); + R4(b,c,d,e,a,69); + R4(a,b,c,d,e,70); + R4(e,a,b,c,d,71); + R4(d,e,a,b,c,72); + R4(c,d,e,a,b,73); + R4(b,c,d,e,a,74); + R4(a,b,c,d,e,75); + R4(e,a,b,c,d,76); + R4(d,e,a,b,c,77); + R4(c,d,e,a,b,78); + R4(b,c,d,e,a,79); + + /* Add the working vars back into context.state[] */ + iA += a; + iB += b; + iC += c; + iD += d; + iE += e; + /* Wipe variables */ + a = b = c = d = e = 0; + Mem::FillZ(W, sizeof(W)); +#else + TUint tempA=iA; + TUint tempB=iB; + TUint tempC=iC; + TUint tempD=iD; + TUint tempE=iE; + TUint temp=0; + +#ifdef EXPANDLOOP + CSHA1_16(tempA,tempB,tempC,tempD,tempE,temp,iData[0]); + CSHA1_16(temp,tempA,tempB,tempC,tempD,tempE,iData[1]); + CSHA1_16(tempE,temp,tempA,tempB,tempC,tempD,iData[2]); + CSHA1_16(tempD,tempE,temp,tempA,tempB,tempC,iData[3]); + CSHA1_16(tempC,tempD,tempE,temp,tempA,tempB,iData[4]); + CSHA1_16(tempB,tempC,tempD,tempE,temp,tempA,iData[5]); + CSHA1_16(tempA,tempB,tempC,tempD,tempE,temp,iData[6]); + CSHA1_16(temp,tempA,tempB,tempC,tempD,tempE,iData[7]); + CSHA1_16(tempE,temp,tempA,tempB,tempC,tempD,iData[8]); + CSHA1_16(tempD,tempE,temp,tempA,tempB,tempC,iData[9]); + CSHA1_16(tempC,tempD,tempE,temp,tempA,tempB,iData[10]); + CSHA1_16(tempB,tempC,tempD,tempE,temp,tempA,iData[11]); + CSHA1_16(tempA,tempB,tempC,tempD,tempE,temp,iData[12]); + CSHA1_16(temp,tempA,tempB,tempC,tempD,tempE,iData[13]); + CSHA1_16(tempE,temp,tempA,tempB,tempC,tempD,iData[14]); + CSHA1_16(tempD,tempE,temp,tempA,tempB,tempC,iData[15]); + /* + i = 16; + TUint temp1 = tempA; + tempA = + */ +#else + TUint i=0; + while (i<16) + { + temp = CMD_R(tempA,5) + CSHA1_F(tempB,tempC,tempD) + tempE + iData[i++] + 0x5a827999; + tempE = tempD; + tempD = tempC; + tempC = CMD_R(tempB,30); + tempB = tempA; + tempA = temp; + } +#endif + +#ifdef EXPANDLOOP + CSHA1_20(tempC,tempD,tempE,temp,tempA,tempB,iData[16],iData[13],iData[8],iData[2],iData[0]); + CSHA1_20(tempB,tempC,tempD,tempE,temp,tempA,iData[17],iData[14],iData[9],iData[3],iData[1]); + CSHA1_20(tempA,tempB,tempC,tempD,tempE,temp,iData[18],iData[15],iData[10],iData[4],iData[2]); + CSHA1_20(temp,tempA,tempB,tempC,tempD,tempE,iData[19],iData[16],iData[11],iData[5],iData[3]); + //i = 20; +#else + while (i<20) + { + temp=iData[i-3] ^ iData[i-8] ^ iData[i-14] ^ iData[i-16]; + iData[i]=CMD_R(temp,1); + temp = CMD_R(tempA,5) + CSHA1_F(tempB,tempC,tempD) + tempE + iData[i++] + 0x5a827999; + tempE = tempD; + tempD = tempC; + tempC = CMD_R(tempB,30); + tempB = tempA; + tempA = temp; + } +#endif + +#ifdef EXPANDLOOP + CSHA1_40(tempE,temp,tempA,tempB,tempC,tempD,iData[20],iData[17],iData[12],iData[6],iData[4]); + CSHA1_40(tempD,tempE,temp,tempA,tempB,tempC,iData[21],iData[18],iData[13],iData[7],iData[5]); + CSHA1_40(tempC,tempD,tempE,temp,tempA,tempB,iData[22],iData[19],iData[14],iData[8],iData[6]); + CSHA1_40(tempB,tempC,tempD,tempE,temp,tempA,iData[23],iData[20],iData[15],iData[9],iData[7]); + CSHA1_40(tempA,tempB,tempC,tempD,tempE,temp,iData[24],iData[21],iData[16],iData[10],iData[8]); + CSHA1_40(temp,tempA,tempB,tempC,tempD,tempE,iData[25],iData[22],iData[17],iData[11],iData[9]); + CSHA1_40(tempE,temp,tempA,tempB,tempC,tempD,iData[26],iData[23],iData[18],iData[12],iData[10]); + CSHA1_40(tempD,tempE,temp,tempA,tempB,tempC,iData[27],iData[24],iData[19],iData[13],iData[11]); + CSHA1_40(tempC,tempD,tempE,temp,tempA,tempB,iData[28],iData[25],iData[20],iData[14],iData[12]); + CSHA1_40(tempB,tempC,tempD,tempE,temp,tempA,iData[29],iData[26],iData[21],iData[15],iData[13]); + CSHA1_40(tempA,tempB,tempC,tempD,tempE,temp,iData[30],iData[27],iData[22],iData[16],iData[14]); + CSHA1_40(temp,tempA,tempB,tempC,tempD,tempE,iData[31],iData[28],iData[23],iData[17],iData[15]); + CSHA1_40(tempE,temp,tempA,tempB,tempC,tempD,iData[32],iData[29],iData[24],iData[18],iData[16]); + CSHA1_40(tempD,tempE,temp,tempA,tempB,tempC,iData[33],iData[30],iData[25],iData[19],iData[17]); + CSHA1_40(tempC,tempD,tempE,temp,tempA,tempB,iData[34],iData[31],iData[26],iData[20],iData[18]); + CSHA1_40(tempB,tempC,tempD,tempE,temp,tempA,iData[35],iData[32],iData[27],iData[21],iData[19]); + CSHA1_40(tempA,tempB,tempC,tempD,tempE,temp,iData[36],iData[33],iData[28],iData[22],iData[20]); + CSHA1_40(temp,tempA,tempB,tempC,tempD,tempE,iData[37],iData[34],iData[29],iData[23],iData[21]); + CSHA1_40(tempE,temp,tempA,tempB,tempC,tempD,iData[38],iData[35],iData[30],iData[24],iData[22]); + CSHA1_40(tempD,tempE,temp,tempA,tempB,tempC,iData[39],iData[36],iData[31],iData[25],iData[23]); + //i = 40; +#else + while (i<40) + { + temp = iData[i-3] ^ iData[i-8] ^ iData[i-14] ^ iData[i-16]; + iData[i] = CMD_R(temp,1); + + temp = CMD_R(tempA,5) + CSHA1_G(tempB,tempC,tempD) + tempE + iData[i++] + 0x6ed9eba1; + tempE = tempD; + tempD = tempC; + tempC = CMD_R(tempB,30); + tempB = tempA; + tempA = temp; + } +#endif + +#ifdef EXPANDLOOP + CSHA1_60(tempC,tempD,tempE,temp,tempA,tempB,iData[40],iData[37],iData[32],iData[26],iData[24]); + CSHA1_60(tempB,tempC,tempD,tempE,temp,tempA,iData[41],iData[38],iData[33],iData[27],iData[25]); + CSHA1_60(tempA,tempB,tempC,tempD,tempE,temp,iData[42],iData[39],iData[34],iData[28],iData[26]); + CSHA1_60(temp,tempA,tempB,tempC,tempD,tempE,iData[43],iData[40],iData[35],iData[29],iData[27]); + CSHA1_60(tempE,temp,tempA,tempB,tempC,tempD,iData[44],iData[41],iData[36],iData[30],iData[28]); + CSHA1_60(tempD,tempE,temp,tempA,tempB,tempC,iData[45],iData[42],iData[37],iData[31],iData[29]); + CSHA1_60(tempC,tempD,tempE,temp,tempA,tempB,iData[46],iData[43],iData[38],iData[32],iData[30]); + CSHA1_60(tempB,tempC,tempD,tempE,temp,tempA,iData[47],iData[44],iData[39],iData[33],iData[31]); + CSHA1_60(tempA,tempB,tempC,tempD,tempE,temp,iData[48],iData[45],iData[40],iData[34],iData[32]); + CSHA1_60(temp,tempA,tempB,tempC,tempD,tempE,iData[49],iData[46],iData[41],iData[35],iData[33]); + CSHA1_60(tempE,temp,tempA,tempB,tempC,tempD,iData[50],iData[47],iData[42],iData[36],iData[34]); + CSHA1_60(tempD,tempE,temp,tempA,tempB,tempC,iData[51],iData[48],iData[43],iData[37],iData[35]); + CSHA1_60(tempC,tempD,tempE,temp,tempA,tempB,iData[52],iData[49],iData[44],iData[38],iData[36]); + CSHA1_60(tempB,tempC,tempD,tempE,temp,tempA,iData[53],iData[50],iData[45],iData[39],iData[37]); + CSHA1_60(tempA,tempB,tempC,tempD,tempE,temp,iData[54],iData[51],iData[46],iData[40],iData[38]); + CSHA1_60(temp,tempA,tempB,tempC,tempD,tempE,iData[55],iData[52],iData[47],iData[41],iData[39]); + CSHA1_60(tempE,temp,tempA,tempB,tempC,tempD,iData[56],iData[53],iData[48],iData[42],iData[40]); + CSHA1_60(tempD,tempE,temp,tempA,tempB,tempC,iData[57],iData[54],iData[49],iData[43],iData[41]); + CSHA1_60(tempC,tempD,tempE,temp,tempA,tempB,iData[58],iData[55],iData[50],iData[44],iData[42]); + CSHA1_60(tempB,tempC,tempD,tempE,temp,tempA,iData[59],iData[56],iData[51],iData[45],iData[43]); + //i = 60; +#else + while (i<60) + { + temp = iData[i-3] ^ iData[i-8] ^ iData[i-14] ^ iData[i-16]; + iData[i] = CMD_R(temp,1); + + temp = CMD_R(tempA,5) + CSHA1_H(tempB,tempC,tempD) + tempE + iData[i++] + 0x8f1bbcdc; + tempE = tempD; + tempD = tempC; + tempC = CMD_R(tempB,30); + tempB = tempA; + tempA = temp; + } +#endif + +#ifdef EXPANDLOOP + CSHA1_80(tempA,tempB,tempC,tempD,tempE,temp,iData[60],iData[57],iData[52],iData[46],iData[44]); + CSHA1_80(temp,tempA,tempB,tempC,tempD,tempE,iData[61],iData[58],iData[53],iData[47],iData[45]); + CSHA1_80(tempE,temp,tempA,tempB,tempC,tempD,iData[62],iData[59],iData[54],iData[48],iData[46]); + CSHA1_80(tempD,tempE,temp,tempA,tempB,tempC,iData[63],iData[60],iData[55],iData[49],iData[47]); + CSHA1_80(tempC,tempD,tempE,temp,tempA,tempB,iData[64],iData[61],iData[56],iData[50],iData[48]); + CSHA1_80(tempB,tempC,tempD,tempE,temp,tempA,iData[65],iData[62],iData[57],iData[51],iData[49]); + CSHA1_80(tempA,tempB,tempC,tempD,tempE,temp,iData[66],iData[63],iData[58],iData[52],iData[50]); + CSHA1_80(temp,tempA,tempB,tempC,tempD,tempE,iData[67],iData[64],iData[59],iData[53],iData[51]); + CSHA1_80(tempE,temp,tempA,tempB,tempC,tempD,iData[68],iData[65],iData[60],iData[54],iData[52]); + CSHA1_80(tempD,tempE,temp,tempA,tempB,tempC,iData[69],iData[66],iData[61],iData[55],iData[53]); + CSHA1_80(tempC,tempD,tempE,temp,tempA,tempB,iData[70],iData[67],iData[62],iData[56],iData[54]); + CSHA1_80(tempB,tempC,tempD,tempE,temp,tempA,iData[71],iData[68],iData[63],iData[57],iData[55]); + CSHA1_80(tempA,tempB,tempC,tempD,tempE,temp,iData[72],iData[69],iData[64],iData[58],iData[56]); + CSHA1_80(temp,tempA,tempB,tempC,tempD,tempE,iData[73],iData[70],iData[65],iData[59],iData[57]); + CSHA1_80(tempE,temp,tempA,tempB,tempC,tempD,iData[74],iData[71],iData[66],iData[60],iData[58]); + CSHA1_80(tempD,tempE,temp,tempA,tempB,tempC,iData[75],iData[72],iData[67],iData[61],iData[59]); + CSHA1_80(tempC,tempD,tempE,temp,tempA,tempB,iData[76],iData[73],iData[68],iData[62],iData[60]); + CSHA1_80(tempB,tempC,tempD,tempE,temp,tempA,iData[77],iData[74],iData[69],iData[63],iData[61]); + CSHA1_80(tempA,tempB,tempC,tempD,tempE,temp,iData[78],iData[75],iData[70],iData[64],iData[62]); + CSHA1_80(temp,tempA,tempB,tempC,tempD,tempE,iData[79],iData[76],iData[71],iData[65],iData[63]); +#else + const TUint total=KSHA1BlockSize*5; // 16 * 5 = 80 + while (i>2] = ul128<<24; + break; + case 1: + iData[iNl>>2] += ul128<<16; + break; + case 2: + iData[iNl>>2] += ul128<<8; + break; + case 3: + iData[iNl>>2] += ul128; + break; + default: + break; + }; + if (iNl>=56) + { + if (iNl<60) + iData[15]=0; + Block(); + Mem::FillZ(iData,14*sizeof(TUint)); + } + else + { + const TUint offset=(iNl+4)>>2; //+4 to account for the word added in the + //switch statement above + Mem::FillZ(iData+offset,(14-offset)*sizeof(TUint)); + } + + // this will fail if the total input length is longer than 2^32 in bits + //(2^31 in bytes) which is roughly half a gig. + iData[14]=0; + iData[15]=iNh<<3;//number in bits + Block(); + // + // Generate hash value into iHash + // + TUint tmp=iA; + iHash[3]=(TUint8)(tmp & 255); + iHash[2]=(TUint8)((tmp >>= 8) & 255); + iHash[1]=(TUint8)((tmp >>= 8) & 255); + iHash[0]=(TUint8)((tmp >>= 8) & 255); + + tmp=iB; + iHash[7]=(TUint8)(tmp & 255); + iHash[6]=(TUint8)((tmp >>= 8) & 255); + iHash[5]=(TUint8)((tmp >>= 8) & 255); + iHash[4]=(TUint8)((tmp >>= 8) & 255); + + tmp=iC; + iHash[11]=(TUint8)(tmp & 255); + iHash[10]=(TUint8)((tmp >>= 8) & 255); + iHash[9]=(TUint8)((tmp >>= 8) & 255); + iHash[8]=(TUint8)((tmp >>= 8) & 255); + + tmp=iD; + iHash[15]=(TUint8)(tmp & 255); + iHash[14]=(TUint8)((tmp >>= 8) & 255); + iHash[13]=(TUint8)((tmp >>= 8) & 255); + iHash[12]=(TUint8)((tmp >>= 8) & 255); + + tmp=iE; + iHash[19]=(TUint8)(tmp & 255); + iHash[18]=(TUint8)((tmp >>= 8) & 255); + iHash[17]=(TUint8)((tmp >>= 8) & 255); + iHash[16]=(TUint8)((tmp >>= 8) & 255); + } + +void CSHA1Impl::RestoreState() + { + iA = iACopy; + iB = iBCopy; + iC = iCCopy; + iD = iDCopy; + iE = iECopy; + iNl = iNlCopy; + iNh = iNhCopy; + Mem::Copy(&iData[0], &iDataCopy[0], KSHA1BlockSize*5*sizeof(TUint)); + } + +void CSHA1Impl::StoreState() + { + iACopy = iA; + iBCopy = iB; + iCCopy = iC; + iDCopy = iD; + iECopy = iE; + iNlCopy = iNl; + iNhCopy = iNh; + Mem::Copy(&iDataCopy[0], &iData[0], KSHA1BlockSize*5*sizeof(TUint)); + } + +// Implemented in hmacimpl.cpp or softwarehashbase.cpp +// but required as derived from MHash. No coverage here. +#ifdef _BullseyeCoverage +#pragma suppress_warnings on +#pragma BullseyeCoverage off +#pragma suppress_warnings off +#endif + +void CSHA1Impl::SetOperationModeL(TUid /*aOperationMode*/) + { + User::Leave(KErrNotSupported); + } + +void CSHA1Impl::SetKeyL(const CKey& /*aKey*/) + { + User::Leave(KErrNotSupported); + } + +TAny* CSHA1Impl::GetExtension(TUid /*aExtensionId*/) + { + return NULL; + } + +CExtendedCharacteristics* CSHA1Impl::CreateExtendedCharacteristicsL() + { + // Not supported + return NULL; + } + +// The following methods are kept for compatibility but are not used by +// randsvr.exe (via SHA1Shim). So, Turn off coverage for these. +MHash* CSHA1Impl::ReplicateL() + { + return CSHA1Impl::NewL(); + } + +MHash* CSHA1Impl::CopyL() + { + return new(ELeave) CSHA1Impl(*this); + } + +void CSHA1Impl::Update(const TDesC8& aMessage) + { + DoUpdate(aMessage.Ptr(),aMessage.Size()); + } + +TPtrC8 CSHA1Impl::Final(const TDesC8& aMessage) + { + TPtrC8 ptr(KNullDesC8()); + if (aMessage!=KNullDesC8()) + { + DoUpdate(aMessage.Ptr(),aMessage.Size()); + } + DoFinal(); + ptr.Set(iHash); + Reset(); + return ptr; + } + +// Since CreateExtendedCharacteristicsL is not supported, the method which using it also can not be supported. +const CExtendedCharacteristics* CSHA1Impl::GetExtendedCharacteristicsL() + { + return CSHA1Impl::CreateExtendedCharacteristicsL(); + } + +// These methods can only be covered from SHA1Shim, but not get covered because the +// SHA1Shim not get destroyed anywhere(may be a long runing service). So, these are excluded. +CSHA1Impl::CSHA1Impl(const CSHA1Impl& aSHA1Impl) + : iHash(aSHA1Impl.iHash),iA(aSHA1Impl.iA),iB(aSHA1Impl.iB),iC(aSHA1Impl.iC),iD(aSHA1Impl.iD),iE(aSHA1Impl.iE), + iNl(aSHA1Impl.iNl),iNh(aSHA1Impl.iNh) + { + (void)Mem::Copy(iData, aSHA1Impl.iData, KSHA1BlockSize*5); + } + +CSHA1Impl* CSHA1Impl::NewLC() + { + CSHA1Impl* self=NewL(); + CleanupStack::PushL(self); + return self; + } + +void CSHA1Impl::Close() + { + delete this; + } + +CSHA1Impl::~CSHA1Impl() + { + } diff -r 7e3f204e6c81 -r f9c11be8c0b3 crypto/weakcryptospi/source/random/sha1shim.cpp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/crypto/weakcryptospi/source/random/sha1shim.cpp Tue Dec 01 11:12:04 2009 +0000 @@ -0,0 +1,151 @@ +/* +* Copyright (c) 2006-2009 Nokia Corporation and/or its subsidiary(-ies). +* All rights reserved. +* This component and the accompanying materials are made available +* under the terms of the License "Eclipse Public License v1.0" +* which accompanies this distribution, and is available +* at the URL "http://www.eclipse.org/legal/epl-v10.html". +* +* Initial Contributors: +* Nokia Corporation - initial contribution. +* +* Contributors: +* +* Description: +* hashshim.cpp +* hash shim implementation +* hash shim implementation +* +*/ + + +/** + @file +*/ + +#include "sha1shim.h" +#include "sha1impl.h" +#include +#include + + +using namespace CryptoSpi; +using namespace SoftwareCrypto; + +// +// Implementation of SHA1 shim +// + +CSHA1Shim* CSHA1Shim::NewL() + { + CSHA1Shim* self=CSHA1Shim::NewLC(); + CleanupStack::Pop(); + return self; + } + +CSHA1Shim* CSHA1Shim::NewLC() + { + CSHA1Shim* self=new(ELeave) CSHA1Shim(); + CleanupStack::PushL(self); + self->ConstructL(); + return self; + } + +CSHA1Shim::CSHA1Shim() + { + } + +CSHA1Shim::~CSHA1Shim() + { + iHashImpl->Close(); + } + +void CSHA1Shim::ConstructL() + { + iHashImpl=CSHA1Impl::NewL(); + } + +TInt CSHA1Shim::HashSize() + { + const TCharacteristics* ptr(NULL); + TRAPD(err, iHashImpl->GetCharacteristicsL(ptr);) + if (err) + { + return err; + } + const THashCharacteristics* hashPtr=static_cast(ptr); + return hashPtr->iOutputSize/8; + } + +TPtrC8 CSHA1Shim::Hash(const TDesC8& aMessage) + { + return iHashImpl->Hash(aMessage); + } + +// The following methods are kept for linkage compatibility +// but are not used by randsvr.exe. Turn off coverage for these +#ifdef _BullseyeCoverage +#pragma suppress_warnings on +#pragma BullseyeCoverage off +#pragma suppress_warnings off +#endif + +void CSHA1Shim::Reset() + { + // Provide a stub for compatibility; not used in random server + ASSERT(EFalse); + } + +void CSHA1Shim::RestoreState() + { + // Provide a stub for compatibility; not used in random server + ASSERT(EFalse); + } + +void CSHA1Shim::StoreState() + { + // Provide a stub for compatibility; not used in random server + ASSERT(EFalse); + } + +CMessageDigest* CSHA1Shim::CopyL() + { + // Provide a stub for compatibility; not used in random server + User::Leave(KErrNotSupported); + return NULL; + } + +CMessageDigest* CSHA1Shim::ReplicateL() + { + // Provide a stub for compatibility; not used in random server + User::Leave(KErrNotSupported); + return NULL; + } + +TInt CSHA1Shim::BlockSize() + { + // Provide a stub for compatibility; not used in random server + ASSERT(EFalse); + return 0; + } + +TPtrC8 CSHA1Shim::Final(const TDesC8& /*aMessage*/) + { + // Provide a stub for compatibility; not used in random server + ASSERT(EFalse); + return NULL; + } + +TPtrC8 CSHA1Shim::Final() + { + // Provide a stub for compatibility; not used in random server + ASSERT(EFalse); + return NULL; + } + +void CSHA1Shim::Update(const TDesC8& /*aMessage*/) + { + // Provide a stub for compatibility; not used in random server + ASSERT(EFalse); + } + diff -r 7e3f204e6c81 -r f9c11be8c0b3 crypto/weakcryptospi/source/random/sha1shim.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/crypto/weakcryptospi/source/random/sha1shim.h Tue Dec 01 11:12:04 2009 +0000 @@ -0,0 +1,65 @@ +/* +* Copyright (c) 2006-2009 Nokia Corporation and/or its subsidiary(-ies). +* All rights reserved. +* This component and the accompanying materials are made available +* under the terms of the License "Eclipse Public License v1.0" +* which accompanies this distribution, and is available +* at the URL "http://www.eclipse.org/legal/epl-v10.html". +* +* Initial Contributors: +* Nokia Corporation - initial contribution. +* +* Contributors: +* +* Description: +* hashshim.h +* hash shim classes definition +* +*/ + + +/** + @file + @internalComponent + @released +*/ + +#ifndef __HASHSHIM_H__ +#define __HASHSHIM_H__ + +#include +#include +#include +#include "sha1impl.h" + +// +// SHA1 shim class +// + +NONSHARABLE_CLASS(CSHA1Shim) : public CMessageDigest + { +public: + static CSHA1Shim* NewL(); + static CSHA1Shim* NewLC(); + ~CSHA1Shim(); + CMessageDigest* CopyL(); + TInt BlockSize(); + TInt HashSize() ; + void Update(const TDesC8& aMessage); + TPtrC8 Final(const TDesC8& aMessage); + TPtrC8 Final(); + void Reset(); + TPtrC8 Hash(const TDesC8& aMessage); + CMessageDigest* ReplicateL(); + void RestoreState(); + void StoreState(); + +private: + CSHA1Shim(); + void ConstructL(); + +private: + SoftwareCrypto::CSHA1Impl* iHashImpl; + }; + +#endif diff -r 7e3f204e6c81 -r f9c11be8c0b3 crypto/weakcryptospi/source/random/threadrandom.cpp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/crypto/weakcryptospi/source/random/threadrandom.cpp Tue Dec 01 11:12:04 2009 +0000 @@ -0,0 +1,67 @@ +/* +* Copyright (c) 2003-2009 Nokia Corporation and/or its subsidiary(-ies). +* All rights reserved. +* This component and the accompanying materials are made available +* under the terms of the License "Eclipse Public License v1.0" +* which accompanies this distribution, and is available +* at the URL "http://www.eclipse.org/legal/epl-v10.html". +* +* Initial Contributors: +* Nokia Corporation - initial contribution. +* +* Contributors: +* +* Description: +* +*/ + + +#include +#include +#include "randomshim.h" + +_LIT(KThreadRandom, "threadrandom.cpp"); + +EXPORT_C void SetThreadRandomL(CRandom* aRNG) + { + User::LeaveIfError(Dll::SetTls(aRNG)); + } + +EXPORT_C void SetThreadRandomLC(CRandom* aRNG) + { + CleanupStack::PushL(aRNG); + SetThreadRandomL(aRNG); + //This pop before the push isn't a problem as the PushL can't fail. + //We just did a push before this and thus there is enough room on the + //cleanupstack such that OOM is not possible. + CleanupStack::Pop(aRNG); + CleanupStack::PushL(TCleanupItem(&DeleteThreadRandom, Dll::Tls())); + } + +void DeleteThreadRandom(TAny* aPtr) + { + CRandom* random = reinterpret_cast(aPtr); + delete random; + TInt result = Dll::SetTls(0); + __ASSERT_ALWAYS(result == 0, User::Panic(KThreadRandom, 1)); + } + +EXPORT_C void DestroyThreadRandom(void) + { + delete (CRandom*)(Dll::Tls()); + TInt result = Dll::SetTls(0); + __ASSERT_ALWAYS(result == 0, User::Panic(KThreadRandom, 1)); + } + +EXPORT_C void GenerateRandomBytesL(TDes8& aDest) + { + TAny* tls = Dll::Tls(); + if(tls) + { + ((CRandom*)tls)->GenerateBytesL(aDest); + } + else + { + TRandomShim::RandomL(aDest); + } + } diff -r 7e3f204e6c81 -r f9c11be8c0b3 crypto/weakcryptospi/source/symmetric/3des.cpp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/crypto/weakcryptospi/source/symmetric/3des.cpp Tue Dec 01 11:12:04 2009 +0000 @@ -0,0 +1,106 @@ +/* +* Copyright (c) 2002-2009 Nokia Corporation and/or its subsidiary(-ies). +* All rights reserved. +* This component and the accompanying materials are made available +* under the terms of the License "Eclipse Public License v1.0" +* which accompanies this distribution, and is available +* at the URL "http://www.eclipse.org/legal/epl-v10.html". +* +* Initial Contributors: +* Nokia Corporation - initial contribution. +* +* Contributors: +* +* Description: +* +*/ + + +#include "3des.h" +#include "3desshim.h" + +const TInt K3DESBlockBytes = 8; +const TInt K3DESKeyBytes = 24; + +C3DES::C3DES() + { + } + +/* C3DESEncryptor */ +EXPORT_C C3DESEncryptor* C3DESEncryptor::NewL(const TDesC8& aKey) + { + return C3DESEncryptorShim::NewL(aKey); + } + +EXPORT_C C3DESEncryptor* C3DESEncryptor::NewLC(const TDesC8& aKey) + { + return C3DESEncryptorShim::NewLC(aKey); + } + +/* C3DESDecryptor */ +EXPORT_C C3DESDecryptor* C3DESDecryptor::NewL(const TDesC8& aKey) + { + return C3DESDecryptorShim::NewL(aKey); + } + +EXPORT_C C3DESDecryptor* C3DESDecryptor::NewLC(const TDesC8& aKey) + { + return C3DESDecryptorShim::NewLC(aKey); + } + +// All these methods have been replaced by the shim +#ifdef _BullseyeCoverage +#pragma suppress_warnings on +#pragma BullseyeCoverage off +#pragma suppress_warnings off +#endif + +void C3DES::Transform(TDes8& /*aBlock*/) + { + // Method replaced by shim + ASSERT(EFalse); + } + +void C3DES::Reset() + { + // Method replaced by shim + ASSERT(EFalse); + } + +TInt C3DES::BlockSize() const + { + // Method replaced by shim + ASSERT(EFalse); + return K3DESBlockBytes; + } + +TInt C3DES::KeySize() const + { + // Method replaced by shim + ASSERT(EFalse); + return K3DESKeyBytes; + } + +void C3DES::DoSetKey(const TDesC8& /*aKey*/) + { + // Method replaced by shim + ASSERT(EFalse); + } + +void C3DES::ConstructL(const TDesC8& /*aKey*/) + { + // Method replaced by shim + ASSERT(EFalse); + } + +void C3DESEncryptor::DoSetKey(const TDesC8& /*aKey*/) + { + // Method replaced by shim + ASSERT(EFalse); + } + +void C3DESDecryptor::DoSetKey(const TDesC8& /*aKey*/) + { + // Method replaced by shim + ASSERT(EFalse); + } diff -r 7e3f204e6c81 -r f9c11be8c0b3 crypto/weakcryptospi/source/symmetric/3desshim.cpp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/crypto/weakcryptospi/source/symmetric/3desshim.cpp Tue Dec 01 11:12:04 2009 +0000 @@ -0,0 +1,191 @@ +/* +* Copyright (c) 2006-2009 Nokia Corporation and/or its subsidiary(-ies). +* All rights reserved. +* This component and the accompanying materials are made available +* under the terms of the License "Eclipse Public License v1.0" +* which accompanies this distribution, and is available +* at the URL "http://www.eclipse.org/legal/epl-v10.html". +* +* Initial Contributors: +* Nokia Corporation - initial contribution. +* +* Contributors: +* +* Description: +* +*/ + + +#include "3desshim.h" + +#include "cryptosymmetriccipherapi.h" +#include +#include +#include "keys.h" +#include +#include "../common/inlines.h" + +using namespace CryptoSpi; + +// C3DESEncryptorShim //////////////////////////////////////////////////////// +C3DESEncryptorShim* C3DESEncryptorShim::NewL(const TDesC8& aKey) + { + C3DESEncryptorShim* self = C3DESEncryptorShim::NewLC(aKey); + CleanupStack::Pop(self); + return self; + } + +C3DESEncryptorShim* C3DESEncryptorShim::NewLC(const TDesC8& aKey) + { + C3DESEncryptorShim* self = new (ELeave) C3DESEncryptorShim(); + CleanupStack::PushL(self); + self->ConstructL(aKey); + // DES only used 7 bits out of every key byte + TCrypto::IsSymmetricWeakEnoughL(BytesToBits(aKey.Size()) - aKey.Size()); + return self; + } + +C3DESEncryptorShim::C3DESEncryptorShim() + { + } + +C3DESEncryptorShim::~C3DESEncryptorShim() + { + delete iSymmetricCipherImpl; + delete iKey; + } + +void C3DESEncryptorShim::ConstructL(const TDesC8& aKey) + { + TKeyProperty keyProperty = {K3DesUid, KNullUid, KSymmetricKey, KNonEmbeddedKeyUid}; + CCryptoParams* keyParam =CCryptoParams::NewLC(); + keyParam->AddL(aKey, KSymmetricKeyParameterUid); + iKey=CKey::NewL(keyProperty, *keyParam); + CleanupStack::PopAndDestroy(keyParam); + + CSymmetricCipherFactory::CreateSymmetricCipherL( + iSymmetricCipherImpl, + K3DesUid, + *iKey, + KCryptoModeEncryptUid, + KOperationModeECBUid, + KPaddingModeNoneUid, + NULL); + } + +TInt C3DESEncryptorShim::BlockSize() const + { + // SPI returns block size in BITS + return iSymmetricCipherImpl->BlockSize() >> 3; + } + +TInt C3DESEncryptorShim::KeySize() const + { + return iSymmetricCipherImpl->KeySize(); + } + +void C3DESEncryptorShim::Transform(TDes8& aBlock) + { + iOutputBlock.Zero(); + TRAP_IGNORE(iSymmetricCipherImpl->ProcessL(aBlock, iOutputBlock);) + aBlock = iOutputBlock; + } + +void C3DESEncryptorShim::Reset() + { + iSymmetricCipherImpl->Reset(); + } + +TInt C3DESEncryptorShim::Extension_(TUint aExtensionId, TAny*& a0, TAny* /*a1*/) + { + TInt ret(KErrExtensionNotSupported); + + if (CryptoSpi::KSymmetricCipherInterface == aExtensionId && iSymmetricCipherImpl) + { + a0=iSymmetricCipherImpl; + ret=KErrNone; + } + return ret; + } + +// C3DESDecryptorShim //////////////////////////////////////////////////////// +C3DESDecryptorShim* C3DESDecryptorShim::NewL(const TDesC8& aKey) + { + C3DESDecryptorShim* self = C3DESDecryptorShim::NewLC(aKey); + CleanupStack::Pop(self); + return self; + } + + +C3DESDecryptorShim* C3DESDecryptorShim::NewLC(const TDesC8& aKey) + { + C3DESDecryptorShim* self = new (ELeave) C3DESDecryptorShim(); + CleanupStack::PushL(self); + self->ConstructL(aKey); + // DES only used 7 bits out of every key byte + TCrypto::IsSymmetricWeakEnoughL(BytesToBits(aKey.Size()) - aKey.Size()); + return self; + } + +C3DESDecryptorShim::C3DESDecryptorShim() + { + } + +C3DESDecryptorShim::~C3DESDecryptorShim() + { + delete iSymmetricCipherImpl; + delete iKey; + } + + +void C3DESDecryptorShim::ConstructL(const TDesC8& aKey) + { + TKeyProperty keyProperty = {K3DesUid, KNullUid, KSymmetricKey, KNonEmbeddedKeyUid}; + CCryptoParams* keyParam =CCryptoParams::NewLC(); + keyParam->AddL(aKey, KSymmetricKeyParameterUid); + iKey=CKey::NewL(keyProperty, *keyParam); + CleanupStack::PopAndDestroy(keyParam); + CSymmetricCipherFactory::CreateSymmetricCipherL( + iSymmetricCipherImpl, + K3DesUid, + *iKey, + KCryptoModeDecryptUid, + KOperationModeECBUid, + KPaddingModeNoneUid, + NULL); + } + +TInt C3DESDecryptorShim::BlockSize() const + { + // SPI returns block size in BITS + return BitsToBytes(iSymmetricCipherImpl->BlockSize()); + } + +TInt C3DESDecryptorShim::KeySize() const + { + return iSymmetricCipherImpl->KeySize(); + } + +void C3DESDecryptorShim::Transform(TDes8& aBlock) + { + iOutputBlock.Zero(); + TRAP_IGNORE(iSymmetricCipherImpl->ProcessL(aBlock, iOutputBlock);) + aBlock = iOutputBlock; + } + +void C3DESDecryptorShim::Reset() + { + iSymmetricCipherImpl->Reset(); + } + +TInt C3DESDecryptorShim::Extension_(TUint aExtensionId, TAny*& a0, TAny* /*a1*/) + { + TInt ret(KErrExtensionNotSupported); + + if (CryptoSpi::KSymmetricCipherInterface == aExtensionId && iSymmetricCipherImpl) + { + a0=iSymmetricCipherImpl; + ret=KErrNone; + } + return ret; + } diff -r 7e3f204e6c81 -r f9c11be8c0b3 crypto/weakcryptospi/source/symmetric/3desshim.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/crypto/weakcryptospi/source/symmetric/3desshim.h Tue Dec 01 11:12:04 2009 +0000 @@ -0,0 +1,145 @@ +/* +* Copyright (c) 2006-2009 Nokia Corporation and/or its subsidiary(-ies). +* All rights reserved. +* This component and the accompanying materials are made available +* under the terms of the License "Eclipse Public License v1.0" +* which accompanies this distribution, and is available +* at the URL "http://www.eclipse.org/legal/epl-v10.html". +* +* Initial Contributors: +* Nokia Corporation - initial contribution. +* +* Contributors: +* +* Description: +* 3DES shim classes definition +* +*/ + + +/** + @file + @internalComponent + @released +*/ + +#ifndef __3DESSHIM_H__ +#define __3DESSHIM_H__ + +#include <3des.h> + +namespace CryptoSpi + { + class CSymmetricCipher; + class CKey; + } + +NONSHARABLE_CLASS(C3DESEncryptorShim) : public C3DESEncryptor +{ +public: + /** + Creates an C3DESEncryptorShim object which has the same interface + as 3DESEncryptor but delegates all work to a Crypto SPI plug-in. + + @param aKey The encryption key + @return A pointer to a C3DESEncryptorShim instance + */ + static C3DESEncryptorShim* NewL(const TDesC8& aKey); + + /** + Creates an C3DESEncryptorShim object which has the same interface + as 3DESEncryptor but delegates all work to a Crypto SPI plug-in. + + A pointer to the new object is placed on the cleanup stack + + @param aKey The encryption key + @return A pointer to a C3DESEncryptorShim instance + */ + static C3DESEncryptorShim* NewLC(const TDesC8& aKey); + + // From CBlockTransform + TInt BlockSize() const; + void Transform(TDes8& aBlock); + void Reset(void); + TInt KeySize(void) const; + + /// Destructor + ~C3DESEncryptorShim(); + +private: + /// Constructor + C3DESEncryptorShim(); + void ConstructL(const TDesC8& aKey); + + // From CBase + TInt Extension_(TUint aExtensionId, TAny*& a0, TAny* a1); + +private: + /// SPI delegate + CryptoSpi::CSymmetricCipher* iSymmetricCipherImpl; + + /// SPI requires all key to passed as key-objects + CryptoSpi::CKey* iKey; + + /// Temporary output block, SPI does not overwrite input + /// 3DES uses 64bit blocks + TBuf8<16> iOutputBlock; +}; + +NONSHARABLE_CLASS(C3DESDecryptorShim) : public C3DESDecryptor +{ +public: + /** + Creates an C3DESDecryptorShim object which has the same interface + as 3DESDecryptor but delegates all work to a Crypto SPI plug-in. + + @param aKey The decryption key + @return A pointer to a C3DESDecryptorShim instance + */ + static C3DESDecryptorShim* NewL(const TDesC8& aKey); + + /** + Creates an C3DESDecryptorShim object which has the same interface + as 3DESDecryptor but delegates all work to a Crypto SPI plug-in. + + A pointer to the new object is placed on the cleanup stack + + @param aKey The decryption key + @return A pointer to a C3DESDecryptorShim instance + */ + static C3DESDecryptorShim* NewLC(const TDesC8& aKey); + + // From CBlockTransform + TInt BlockSize() const; + void Transform(TDes8& aBlock); + void Reset(void); + TInt KeySize(void) const; + + /// Destructor + ~C3DESDecryptorShim(); + +private: + /// Constructor + C3DESDecryptorShim(); + void ConstructL(const TDesC8& aKey); + + /** + From CBase, to allow CBufferedTransform & CBlockChainingMode + to determine whether the functionality may be delegated to + the SPI object. + */ + TInt Extension_(TUint aExtensionId, TAny*& a0, TAny* a1); + +private: + /// SPI delegate + CryptoSpi::CSymmetricCipher* iSymmetricCipherImpl; + + /// SPI requires all key to passed as key-objects + CryptoSpi::CKey* iKey; + + /// Temporary output block, SPI does not overwrite input + /// 3DES uses 64bit blocks + TBuf8<16> iOutputBlock; +}; + +#endif // __3DESSHIM_H__ diff -r 7e3f204e6c81 -r f9c11be8c0b3 crypto/weakcryptospi/source/symmetric/arc4.cpp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/crypto/weakcryptospi/source/symmetric/arc4.cpp Tue Dec 01 11:12:04 2009 +0000 @@ -0,0 +1,62 @@ +/* +* Copyright (c) 2002-2009 Nokia Corporation and/or its subsidiary(-ies). +* All rights reserved. +* This component and the accompanying materials are made available +* under the terms of the License "Eclipse Public License v1.0" +* which accompanies this distribution, and is available +* at the URL "http://www.eclipse.org/legal/epl-v10.html". +* +* Initial Contributors: +* Nokia Corporation - initial contribution. +* +* Contributors: +* +* Description: +* +*/ + + +#include "arc4.h" +#include "arc4shim.h" + + +EXPORT_C CARC4* CARC4::NewL(const TDesC8& aKey, TUint aDiscardBytes) + { + return CArc4Shim::NewL(aKey, aDiscardBytes); + } + +EXPORT_C CARC4* CARC4::NewLC(const TDesC8& aKey, TUint aDiscardBytes) + { + return CArc4Shim::NewLC(aKey, aDiscardBytes); + } + +CARC4::CARC4() + { + } + +// All these methods have been replaced by the shim +#ifdef _BullseyeCoverage +#pragma suppress_warnings on +#pragma BullseyeCoverage off +#pragma suppress_warnings off +#endif + +void CARC4::Reset() + { + // Method replaced by shim + ASSERT(EFalse); + } + +TInt CARC4::KeySize() const + { + // Method replaced by shim + ASSERT(EFalse); + return 0; + } + +void CARC4::DoProcess(TDes8& /*aData*/) + { + // Method replaced by shim + ASSERT(EFalse); + } + diff -r 7e3f204e6c81 -r f9c11be8c0b3 crypto/weakcryptospi/source/symmetric/arc4shim.cpp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/crypto/weakcryptospi/source/symmetric/arc4shim.cpp Tue Dec 01 11:12:04 2009 +0000 @@ -0,0 +1,113 @@ +/* +* Copyright (c) 2006-2009 Nokia Corporation and/or its subsidiary(-ies). +* All rights reserved. +* This component and the accompanying materials are made available +* under the terms of the License "Eclipse Public License v1.0" +* which accompanies this distribution, and is available +* at the URL "http://www.eclipse.org/legal/epl-v10.html". +* +* Initial Contributors: +* Nokia Corporation - initial contribution. +* +* Contributors: +* +* Description: +* +*/ + + + +#include "arc4shim.h" + +#include "cryptosymmetriccipherapi.h" +#include +#include +#include +#include "../common/inlines.h" +#include "keys.h" + +using namespace CryptoSpi; + +CArc4Shim* CArc4Shim::NewL(const TDesC8& aKey, TUint aDiscardBytes) + { + CArc4Shim* self = NewLC(aKey, aDiscardBytes); + CleanupStack::Pop(self); + return self; + } + +CArc4Shim* CArc4Shim::NewLC(const TDesC8& aKey, TUint aDiscardBytes) + { + CArc4Shim* self = new (ELeave) CArc4Shim(); + CleanupStack::PushL(self); + self->ConstructL(aKey, aDiscardBytes); + TCrypto::IsSymmetricWeakEnoughL(BytesToBits(aKey.Size())); + return self; + } + +void CArc4Shim::ConstructL(const TDesC8& aKey, TUint aDiscardBytes) + { + TKeyProperty keyProperty = {KArc4Uid, KNullUid, KSymmetricKey, KNonEmbeddedKeyUid}; + CCryptoParams* keyParam =CCryptoParams::NewLC(); + keyParam->AddL(aKey, KSymmetricKeyParameterUid); + iKey=CKey::NewL(keyProperty, *keyParam); + CleanupStack::PopAndDestroy(keyParam); + + iAlgorithmParams = CCryptoParams::NewL(); + iAlgorithmParams->AddL(aDiscardBytes, KARC4DiscardBytes); + + CSymmetricCipherFactory::CreateSymmetricCipherL( + iSymmetricCipherImpl, + KArc4Uid, + *iKey, + KCryptoModeNoneUid, + KOperationModeNoneUid, + KPaddingModeNoneUid, + iAlgorithmParams); + } + +CArc4Shim::~CArc4Shim() + { + delete iSymmetricCipherImpl; + delete iKey; + delete iAlgorithmParams; + } + +void CArc4Shim::Reset() + { + iSymmetricCipherImpl->Reset(); + } + +TInt CArc4Shim::BlockSize() const + { + return iSymmetricCipherImpl->BlockSize() >> 3; // Convert to bits + } + +TInt CArc4Shim::KeySize() const + { + return iSymmetricCipherImpl->KeySize(); + } + +void CArc4Shim::Process(const TDesC8& aInput, TDes8& aOutput) + { + TRAP_IGNORE(iSymmetricCipherImpl->ProcessL(aInput, aOutput);) + } + +void CArc4Shim::ProcessFinalL(const TDesC8& aInput, TDes8& aOutput) + { + iSymmetricCipherImpl->ProcessFinalL(aInput, aOutput); + } + +TInt CArc4Shim::MaxOutputLength(TInt aInputLength) const + { + return iSymmetricCipherImpl->MaxOutputLength(aInputLength); + } + +TInt CArc4Shim::MaxFinalOutputLength(TInt aInputLength) const + { + return iSymmetricCipherImpl->MaxFinalOutputLength(aInputLength); + } + +CArc4Shim::CArc4Shim() + { + } + diff -r 7e3f204e6c81 -r f9c11be8c0b3 crypto/weakcryptospi/source/symmetric/arc4shim.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/crypto/weakcryptospi/source/symmetric/arc4shim.h Tue Dec 01 11:12:04 2009 +0000 @@ -0,0 +1,107 @@ +/* +* Copyright (c) 2006-2009 Nokia Corporation and/or its subsidiary(-ies). +* All rights reserved. +* This component and the accompanying materials are made available +* under the terms of the License "Eclipse Public License v1.0" +* which accompanies this distribution, and is available +* at the URL "http://www.eclipse.org/legal/epl-v10.html". +* +* Initial Contributors: +* Nokia Corporation - initial contribution. +* +* Contributors: +* +* Description: +* ARC4 shim classes definition +* +*/ + + +/** + @file + @internalComponent + @released +*/ + +#ifndef ARC4SHIM_H +#define ARC4SHIM_H + +#include + +namespace CryptoSpi + { + class CCryptoParams; + class CSymmetricCipher; + class CKey; + } + +NONSHARABLE_CLASS(CArc4Shim) : public CARC4 +{ +public: + /** + Creates a CArc4Shim object which has the same interface as CARC4 + but delegates all work to a Crypto SPI plug-in. + @param aKey The key to use. aKey must be less + than or equal to KRC4MaxKeySizeBytes. + @param aDiscardBytes The number of bytes to drop from the + beginning of the key stream. + @return A pointer to a CArc4Shim instance + @leave KErrKeyNotWeakEnough If the key size is larger than that + allowed by the cipher strength + restrictions of the crypto library. + See TCrypto::IsSymmetricWeakEnoughL() + */ + static CArc4Shim* NewL(const TDesC8& aKey, TUint aDiscardBytes); + + /** + Creates a CArc4Shim object which has the same interface as CARC4, + and leave it on the cleanup stack. but delegates all work to a + Crypto SPI plug-in. + @param aKey The key to use. aKey must be less + than or equal to KRC4MaxKeySizeBytes. + @param aDiscardBytes The number of bytes to drop from the + beginning of the key stream. + @return A pointer to a CArc4Shim instance + @leave KErrKeyNotWeakEnough If the key size is larger than that + allowed by the cipher strength + restrictions of the crypto library. + See TCrypto::IsSymmetricWeakEnoughL() + */ + static CArc4Shim* NewLC(const TDesC8& aKey, TUint aDiscardBytes); + + /** + Destructor + */ + ~CArc4Shim(); + + // From CSymmetricCipher class + void Reset(); + TInt BlockSize() const; + TInt KeySize() const; + void Process(const TDesC8& aInput, TDes8& aOutput); + void ProcessFinalL(const TDesC8& aInput, TDes8& aOutput); + TInt MaxOutputLength(TInt aInputLength) const; + TInt MaxFinalOutputLength(TInt aInputLength) const; + +private: + /** + Constructor + */ + CArc4Shim(); + + /** + Second Phase Constructor + */ + void ConstructL(const TDesC8& aKey, TUint aDiscardBytes); + +private: + /// SPI delegate + CryptoSpi::CSymmetricCipher* iSymmetricCipherImpl; + + /// SPI requires all key to passed as key-objects + CryptoSpi::CKey* iKey; + + CryptoSpi::CCryptoParams* iAlgorithmParams; +}; + +#endif // ARC4SHIM_H diff -r 7e3f204e6c81 -r f9c11be8c0b3 crypto/weakcryptospi/source/symmetric/blocktransformation.cpp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/crypto/weakcryptospi/source/symmetric/blocktransformation.cpp Tue Dec 01 11:12:04 2009 +0000 @@ -0,0 +1,25 @@ +/* +* Copyright (c) 2006-2009 Nokia Corporation and/or its subsidiary(-ies). +* All rights reserved. +* This component and the accompanying materials are made available +* under the terms of the License "Eclipse Public License v1.0" +* which accompanies this distribution, and is available +* at the URL "http://www.eclipse.org/legal/epl-v10.html". +* +* Initial Contributors: +* Nokia Corporation - initial contribution. +* +* Contributors: +* +* Description: +* +*/ + + +#include "blocktransformation.h" + + +TInt CBlockTransformation::GetExtension(TUint aExtensionId, TAny*& a0, TAny* a1) + { + return Extension_(aExtensionId, a0, a1); + } diff -r 7e3f204e6c81 -r f9c11be8c0b3 crypto/weakcryptospi/source/symmetric/bufferedtransformation.cpp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/crypto/weakcryptospi/source/symmetric/bufferedtransformation.cpp Tue Dec 01 11:12:04 2009 +0000 @@ -0,0 +1,260 @@ +/* +* Copyright (c) 2002-2009 Nokia Corporation and/or its subsidiary(-ies). +* All rights reserved. +* This component and the accompanying materials are made available +* under the terms of the License "Eclipse Public License v1.0" +* which accompanies this distribution, and is available +* at the URL "http://www.eclipse.org/legal/epl-v10.html". +* +* Initial Contributors: +* Nokia Corporation - initial contribution. +* +* Contributors: +* +* Description: +* +*/ + + +#include "bufferedtransformation.h" + +#include +#include +#include +#include "symmetriccipherplugin.h" + +#include "blocktransformation.h" +#include "bufferedtransformationshim.h" +#include "padding.h" +#include "../common/inlines.h" + +EXPORT_C CBufferedTransformation::~CBufferedTransformation() + { + delete iBT; + delete iPadding; + delete iInputStoreBuf; + } + +void CBufferedTransformation::Process(const TDesC8& aInput, TDes8& aOutput) + { + __ASSERT_DEBUG(aOutput.MaxLength() >= MaxOutputLength(aInput.Length()), User::Panic(KCryptoPanic, ECryptoPanicOutputDescriptorOverflow)); + + TInt blockSize = iBT->BlockSize(); + + if ( (aInput.Size() + iInputStore.Size()) < blockSize ) + { + iInputStore.Append(aInput); + } + else + { + TInt outputIndex = aOutput.Size(); + aOutput.Append(iInputStore); + + TInt inputIndex = blockSize - iInputStore.Size(); + aOutput.Append(aInput.Mid(0, inputIndex)); + + TPtr8 transformBuf((TUint8*)(aOutput.Ptr()) + outputIndex, blockSize, + blockSize); + //This should read: + //TPtr8 transformBuf(aOutput.Mid(outputIndex, blockSize)); + //but in the wonderful world of descriptors, Mid returns a TPtrC8 even + //when called on a TPtr8. Fantastic eh? + iBT->Transform(transformBuf); + + outputIndex += blockSize; + + TInt len = aInput.Size() - blockSize; + + for (; inputIndex<=len; inputIndex+=blockSize) + { + aOutput.Append(aInput.Mid(inputIndex, blockSize)); + transformBuf.Set((TUint8*)(aOutput.Ptr()) + outputIndex, blockSize, + blockSize); + iBT->Transform(transformBuf); + outputIndex += blockSize; + } + + iInputStore.Zero(); + if (inputIndex < aInput.Size()) + iInputStore.Append(aInput.Mid(inputIndex)); + } + } + +TInt CBufferedTransformation::MaxOutputLength(TInt aInputLength) const + { + TInt rem = (aInputLength + iInputStore.Size()) % (iBT->BlockSize()); + return ((aInputLength + iInputStore.Size()) - rem); + } + +void CBufferedTransformation::Reset() + { + iBT->Reset(); + iInputStore.Zero(); + } + +TInt CBufferedTransformation::BlockSize() const + { + return (iBT->BlockSize()); + } + +TInt CBufferedTransformation::KeySize() const + { + return (iBT->KeySize()); + } + +EXPORT_C CBlockTransformation* CBufferedTransformation::BlockTransformer() const +{ + return (iBT); +} + +CBufferedTransformation::CBufferedTransformation() + : iInputStore(0,0,0) + { + } + +void CBufferedTransformation::ConstructL(CBlockTransformation* aBT, CPadding* aPadding) + { + iInputStoreBuf = HBufC8::NewL(aBT->BlockSize()); + iInputStore.Set(iInputStoreBuf->Des()); + + // Take ownership last - doesn't take ownership if we leave + iBT = aBT; + iPadding = aPadding; + } + + +// CBufferedEncryptor + +EXPORT_C CBufferedEncryptor* CBufferedEncryptor::NewL( + CBlockTransformation* aBT, CPadding* aPadding) + { + CBufferedEncryptor* self = CBufferedEncryptorShim::NewL(aBT, aPadding); + if (! self) + { + // not able to use CryptoSpi, possibly due to an exterally + // derived legacy class so fallback to old implementation. + self = NewLC(aBT,aPadding); + CleanupStack::Pop(self); + } + return self; + } + +EXPORT_C CBufferedEncryptor* CBufferedEncryptor::NewLC( + CBlockTransformation* aBT, CPadding* aPadding) + { + CBufferedEncryptor* self = new (ELeave) CBufferedEncryptor(); + CleanupStack::PushL(self); + self->ConstructL(aBT, aPadding); + return self; + } + +void CBufferedEncryptor::ConstructL(CBlockTransformation* aBT, CPadding* aPadding) + { + CBufferedTransformation::ConstructL(aBT, aPadding); + } + +CBufferedEncryptor::CBufferedEncryptor() + { + } + +void CBufferedEncryptor::ProcessFinalL(const TDesC8& aInput, TDes8& aOutput) + { + __ASSERT_DEBUG(aOutput.MaxLength() >= MaxFinalOutputLength(aInput.Length()), User::Panic(KCryptoPanic, ECryptoPanicOutputDescriptorOverflow)); + Process(aInput, aOutput); + + TInt outputIndex = aOutput.Size(); + iPadding->PadL(iInputStore, aOutput); + assert(aOutput.Size() % iBT->BlockSize() == 0); + + TUint blockSize = iBT->BlockSize(); + TInt len = aOutput.Size() - outputIndex; + + for(TInt i=len; i>0; i-=blockSize) + { + TPtr8 transformBuf((TUint8*)(aOutput.Ptr()) + outputIndex, blockSize, + blockSize); + iBT->Transform(transformBuf); + outputIndex+=blockSize; + } + + iInputStore.Zero(); + } + +TInt CBufferedEncryptor::MaxFinalOutputLength(TInt aInputLength) const + { + return iPadding->MaxPaddedLength(iInputStore.Size() + aInputLength); + } + +// CBufferedDecryptor + +EXPORT_C CBufferedDecryptor* CBufferedDecryptor::NewL( + CBlockTransformation* aBT, CPadding* aPadding) + { + CBufferedDecryptor* self = CBufferedDecryptorShim::NewL(aBT, aPadding); + if (! self) + { + // not able to use CryptoSpi, possibly due to an exterally + // derived legacy class so fallback to old implementation. + self = NewLC(aBT,aPadding); + CleanupStack::Pop(self); + } + return self; + } + +EXPORT_C CBufferedDecryptor* CBufferedDecryptor::NewLC( + CBlockTransformation* aBT, CPadding* aPadding) + { + CBufferedDecryptor* self = new (ELeave) CBufferedDecryptor(); + CleanupStack::PushL(self); + self->ConstructL(aBT, aPadding); + return self; + } + +CBufferedDecryptor::CBufferedDecryptor() + { + } + +void CBufferedDecryptor::ProcessFinalL(const TDesC8& aInput, TDes8& aOutput) + { + __ASSERT_DEBUG(aOutput.MaxLength() >= MaxFinalOutputLength(aInput.Length()), User::Panic(KCryptoPanic, ECryptoPanicOutputDescriptorOverflow)); + + assert((aInput.Size() + iInputStore.Size()) % iPadding->BlockSize()==0); + assert(aInput.Size() + iInputStore.Size() !=0 ); + assert(iPadding->BlockSize() % BlockSize() == 0); + //1) Decrypt into aOutput up till the last full _padding_ blocksize + //If this panics with descriptor problems, you've probably called + //ProcessFinalL with a non-_padding_ blocksized aligned amount of data. + TInt lenToDecrypt = aInput.Size() - iPadding->BlockSize(); + if(lenToDecrypt > 0) + { + Process(aInput.Left(lenToDecrypt), aOutput); + assert(iInputStore.Size()==0); + } + else + { + lenToDecrypt = 0; + } + + //2) Decrypt the last _padding_ blocksize into a new buffer + HBufC8* padBuf = HBufC8::NewLC(iPadding->BlockSize()); + TPtr8 padPtr = padBuf->Des(); + Process(aInput.Mid(lenToDecrypt), padPtr); + assert(iInputStore.Size()==0); + + //3) Unpad that last _padding_ blocksize into aOutput + // Note that padding systems must always, like everything else in crypto, + // _append_ data. + iPadding->UnPadL(padPtr, aOutput); + + CleanupStack::PopAndDestroy(padBuf); + } + +TInt CBufferedDecryptor::MaxFinalOutputLength(TInt aInputLength) const + { + return iPadding->MaxUnPaddedLength(aInputLength + iInputStore.Size()); + } + +void CBufferedDecryptor::ConstructL(CBlockTransformation* aBT, CPadding* aPadding) + { + CBufferedTransformation::ConstructL(aBT, aPadding); + } diff -r 7e3f204e6c81 -r f9c11be8c0b3 crypto/weakcryptospi/source/symmetric/bufferedtransformationshim.cpp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/crypto/weakcryptospi/source/symmetric/bufferedtransformationshim.cpp Tue Dec 01 11:12:04 2009 +0000 @@ -0,0 +1,189 @@ +/* +* Copyright (c) 2006-2009 Nokia Corporation and/or its subsidiary(-ies). +* All rights reserved. +* This component and the accompanying materials are made available +* under the terms of the License "Eclipse Public License v1.0" +* which accompanies this distribution, and is available +* at the URL "http://www.eclipse.org/legal/epl-v10.html". +* +* Initial Contributors: +* Nokia Corporation - initial contribution. +* +* Contributors: +* +* Description: +* blocktransformationshim.cpp +* +*/ + + +#include "bufferedtransformationshim.h" + +#include +#include +#include "cryptosymmetriccipherapi.h" +#include +#include "../common/inlines.h" + +// CBufferedEncryptorShim +CBufferedEncryptorShim::CBufferedEncryptorShim(CryptoSpi::CSymmetricCipher* aSymmetricCipherImpl) : + iSymmetricCipherImpl(aSymmetricCipherImpl) + { + } + +CBufferedEncryptorShim* CBufferedEncryptorShim::NewL(CBlockTransformation* aBT, CPadding* aPadding) + { + CBufferedEncryptorShim* self(0); + + // Check whether the block transform contains an SPI plug-in + TAny* implPtr(0); + TInt err = aBT->GetExtension(CryptoSpi::KSymmetricCipherInterface, implPtr, NULL); + if (err == KErrNone && implPtr) + { + CryptoSpi::CSymmetricCipher* impl(static_cast(implPtr)); + + const CryptoSpi::TCharacteristics* c(0); + impl->GetCharacteristicsL(c); + + const CryptoSpi::TSymmetricCipherCharacteristics* cipherCharacteristics( + static_cast(c)); + + // See if the padding mode is recognised by CryptoSpi and if so, check + // whether the plug-in supports that padding mode. + TUid paddingMode; + TAny* paddingPtr = &paddingMode; + err = aPadding->GetExtension(CryptoSpi::KPaddingInterface, paddingPtr, 0); + if (err == KErrNone && cipherCharacteristics->IsPaddingModeSupported(paddingMode)) + { + impl->SetCryptoModeL(CryptoSpi::KCryptoModeEncryptUid); + impl->SetPaddingModeL(paddingMode); + self = new(ELeave) CBufferedEncryptorShim(impl); + CleanupStack::PushL(self); + self->ConstructL(aBT, aPadding); + CleanupStack::Pop(self); + } + } + return self; + } + +void CBufferedEncryptorShim::ConstructL(CBlockTransformation* aBT, CPadding* aPadding) + { + CBufferedEncryptor::ConstructL(aBT, aPadding); + } + +void CBufferedEncryptorShim::Process(const TDesC8& aInput, TDes8& aOutput) + { + TRAP_IGNORE(iSymmetricCipherImpl->ProcessL(aInput, aOutput);) + } + +TInt CBufferedEncryptorShim::MaxOutputLength(TInt aInputLength) const + { + return iSymmetricCipherImpl->MaxOutputLength(aInputLength); + } + +void CBufferedEncryptorShim::Reset() + { + iSymmetricCipherImpl->Reset(); + } + +TInt CBufferedEncryptorShim::BlockSize() const + { + return BitsToBytes(iSymmetricCipherImpl->BlockSize()); + } + +TInt CBufferedEncryptorShim::KeySize() const + { + return iSymmetricCipherImpl->KeySize(); + } + +void CBufferedEncryptorShim::ProcessFinalL(const TDesC8& aInput, TDes8& aOutput) + { + iSymmetricCipherImpl->ProcessFinalL(aInput, aOutput); + } + +TInt CBufferedEncryptorShim::MaxFinalOutputLength(TInt aInputLength) const + { + return iSymmetricCipherImpl->MaxFinalOutputLength(aInputLength); + } + +// CBufferedDecryptorShim +CBufferedDecryptorShim::CBufferedDecryptorShim(CryptoSpi::CSymmetricCipher* aSymmetricCipherImpl) : + iSymmetricCipherImpl(aSymmetricCipherImpl) + { + } + +CBufferedDecryptorShim* CBufferedDecryptorShim::NewL(CBlockTransformation* aBT, CPadding* aPadding) + { + CBufferedDecryptorShim* self(0); + + // Check whether the block transform contains an SPI plug-in + TAny* implPtr(0); + TInt err = aBT->GetExtension(CryptoSpi::KSymmetricCipherInterface, implPtr, NULL); + if (err == KErrNone && implPtr) + { + CryptoSpi::CSymmetricCipher* impl(static_cast(implPtr)); + + const CryptoSpi::TCharacteristics* c(0); + impl->GetCharacteristicsL(c); + + const CryptoSpi::TSymmetricCipherCharacteristics* cipherCharacteristics( + static_cast(c)); + + // See if the padding mode is recognised by CryptoSpi and if so, check + // whether the plug-in supports that padding mode. + TUid paddingMode; + TAny* paddingPtr = &paddingMode; + err = aPadding->GetExtension(CryptoSpi::KPaddingInterface, paddingPtr, 0); + if (err == KErrNone && cipherCharacteristics->IsPaddingModeSupported(paddingMode)) + { + impl->SetCryptoModeL(CryptoSpi::KCryptoModeDecryptUid); + impl->SetPaddingModeL(paddingMode); + + self = new(ELeave) CBufferedDecryptorShim(impl); + CleanupStack::PushL(self); + self->ConstructL(aBT, aPadding); + CleanupStack::Pop(self); + } + } + return self; + } + +void CBufferedDecryptorShim::ConstructL(CBlockTransformation* aBT, CPadding* aPadding) + { + CBufferedDecryptor::ConstructL(aBT, aPadding); + } + +void CBufferedDecryptorShim::Process(const TDesC8& aInput, TDes8& aOutput) + { + TRAP_IGNORE(iSymmetricCipherImpl->ProcessL(aInput, aOutput);) + } + +TInt CBufferedDecryptorShim::MaxOutputLength(TInt aInputLength) const + { + return iSymmetricCipherImpl->MaxOutputLength(aInputLength); + } + +void CBufferedDecryptorShim::Reset() + { + iSymmetricCipherImpl->Reset(); + } + +TInt CBufferedDecryptorShim::BlockSize() const + { + return BitsToBytes(iSymmetricCipherImpl->BlockSize()); + } + +TInt CBufferedDecryptorShim::KeySize() const + { + return iSymmetricCipherImpl->KeySize(); + } + +void CBufferedDecryptorShim::ProcessFinalL(const TDesC8& aInput, TDes8& aOutput) + { + iSymmetricCipherImpl->ProcessFinalL(aInput, aOutput); + } + +TInt CBufferedDecryptorShim::MaxFinalOutputLength(TInt aInputLength) const + { + return iSymmetricCipherImpl->MaxFinalOutputLength(aInputLength); + } diff -r 7e3f204e6c81 -r f9c11be8c0b3 crypto/weakcryptospi/source/symmetric/bufferedtransformationshim.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/crypto/weakcryptospi/source/symmetric/bufferedtransformationshim.h Tue Dec 01 11:12:04 2009 +0000 @@ -0,0 +1,99 @@ +/* +* Copyright (c) 2006-2009 Nokia Corporation and/or its subsidiary(-ies). +* All rights reserved. +* This component and the accompanying materials are made available +* under the terms of the License "Eclipse Public License v1.0" +* which accompanies this distribution, and is available +* at the URL "http://www.eclipse.org/legal/epl-v10.html". +* +* Initial Contributors: +* Nokia Corporation - initial contribution. +* +* Contributors: +* +* Description: +* +*/ + + +#ifndef __BUFFEREDTRANSFORMATIONSHIM_H__ +#define __BUFFEREDTRANSFORMATIONSHIM_H__ + +#include + +/** +@file +@internalComponent +@released +*/ + +namespace CryptoSpi + { + class CSymmetricCipher; + } + +/** + Shim class that delegates all operations to an Crypto Spi object. + This object is constructed automatically by CBufferedEncryptorShim and should + not be used directly. + */ +NONSHARABLE_CLASS(CBufferedEncryptorShim) : public CBufferedEncryptor +{ +public: + /** + Creates a new CBufferedEncryptorShim. + N.B. It is the reponsiblity of the CALLER to check that block transform + object contains an SPI delegate and that the delegate supports the specified + padding mode. + */ + static CBufferedEncryptorShim* NewL(CBlockTransformation* aBT, CPadding* aPadding); + + // From CBufferedTransformation + void Process(const TDesC8& aInput, TDes8& aOutput); + TInt MaxOutputLength(TInt aInputLength) const; + void Reset(); + TInt BlockSize() const; + TInt KeySize() const; + void ProcessFinalL(const TDesC8& aInput, TDes8& aOutput); + TInt MaxFinalOutputLength(TInt aInputLength) const; +private: + CBufferedEncryptorShim(CryptoSpi::CSymmetricCipher* aSymmetricCipherImpl); + void ConstructL(CBlockTransformation* aBT, CPadding* aPadding); + + // owned by block transform - iBT + CryptoSpi::CSymmetricCipher* iSymmetricCipherImpl; +}; + +/** + Shim class that delegates all operations to an Crypto Spi object. + This object is constructed automatically by CBufferedEncryptorShim and should + not be used directly. + */ +NONSHARABLE_CLASS(CBufferedDecryptorShim) : public CBufferedDecryptor +{ +public: + /** + Creates a new CBufferedDecryptorShim. + N.B. It is the reponsiblity of the CALLER to check that block transform + object contains an SPI delegate and that the delegate supports the specified + padding mode. + */ + static CBufferedDecryptorShim* NewL(CBlockTransformation* aBT, CPadding* aPadding); + + // From CBufferedTransformation + void Process(const TDesC8& aInput, TDes8& aOutput); + TInt MaxOutputLength(TInt aInputLength) const; + void Reset(); + TInt BlockSize() const; + TInt KeySize() const; + void ProcessFinalL(const TDesC8& aInput, TDes8& aOutput); + TInt MaxFinalOutputLength(TInt aInputLength) const; +private: + CBufferedDecryptorShim(CryptoSpi::CSymmetricCipher* aSymmetricCipherImpl); + void ConstructL(CBlockTransformation* aBT, CPadding* aPadding); + + // owned by block transform - iBT + CryptoSpi::CSymmetricCipher* iSymmetricCipherImpl; +}; + +#endif // __BUFFEREDTRANSFORMATIONSHIM_H__ diff -r 7e3f204e6c81 -r f9c11be8c0b3 crypto/weakcryptospi/source/symmetric/cbcmode.cpp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/crypto/weakcryptospi/source/symmetric/cbcmode.cpp Tue Dec 01 11:12:04 2009 +0000 @@ -0,0 +1,170 @@ +/* +* Copyright (c) 2002-2009 Nokia Corporation and/or its subsidiary(-ies). +* All rights reserved. +* This component and the accompanying materials are made available +* under the terms of the License "Eclipse Public License v1.0" +* which accompanies this distribution, and is available +* at the URL "http://www.eclipse.org/legal/epl-v10.html". +* +* Initial Contributors: +* Nokia Corporation - initial contribution. +* +* Contributors: +* +* Description: +* +*/ + + +#include + +#include "cbcmodeshim.h" +#include "../common/inlines.h" + +void CBlockChainingMode::Reset() + { + iRegister.Copy(iIV); + iBT->Reset(); + } + +TInt CBlockChainingMode::BlockSize() const + { + return (iBT->BlockSize()); + } + +TInt CBlockChainingMode::KeySize() const + { + return (iBT->KeySize()); + } + +void CBlockChainingMode::SetIV(const TDesC8& aIV) + { + //We are making the stipulation that anybody calling SetIV is not setting it + //to a longer IV than they originally did. Otherwise SetIV needs to leave. + assert(aIV.Size() <= iIV.Size()); + iIV.Copy(aIV); + Reset(); + } + +EXPORT_C CBlockChainingMode::CBlockChainingMode() + : iBT(NULL), iRegister(0,0,0), iIV(0,0,0) + { + } + +EXPORT_C CBlockChainingMode::~CBlockChainingMode() + { + delete iBT; + delete iRegisterBuf; + delete iIVBuf; + } + +EXPORT_C void CBlockChainingMode::ConstructL(CBlockTransformation* aBT, const TDesC8& aIV) + { + iRegisterBuf = aIV.AllocL(); + iRegister.Set(iRegisterBuf->Des()); + iIVBuf = aIV.AllocL(); + iIV.Set(iIVBuf->Des()); + + // Take ownership last - doesn't take ownership if we leave + iBT = aBT; + } + +/* CModeCBCEncryptor */ +EXPORT_C CModeCBCEncryptor* CModeCBCEncryptor::NewL(CBlockTransformation* aBT, + const TDesC8& aIV) + { + CModeCBCEncryptor* self = CModeCBCEncryptorShim::NewL(aBT, aIV); + if (! self) + { + // not able to use CryptoSpi, possibly due to an exterally + // derived legacy class so fallback to old implementation. + self = NewLC(aBT,aIV); + CleanupStack::Pop(self); + } + return self; + } + +EXPORT_C CModeCBCEncryptor* CModeCBCEncryptor::NewLC(CBlockTransformation* aBT, + const TDesC8& aIV) + { + CModeCBCEncryptor* self = new (ELeave)CModeCBCEncryptor(); + CleanupStack::PushL(self); + self->ConstructL(aBT, aIV); + return self; + } + +CModeCBCEncryptor::CModeCBCEncryptor() + { + } + +void CModeCBCEncryptor::Transform(TDes8& aBlock) + { + assert(aBlock.Size() == iBT->BlockSize()); + assert(iRegister.Size() == aBlock.Size()); + + XorBuf(const_cast(iRegister.Ptr()), aBlock.Ptr(), aBlock.Size()); + iBT->Transform(iRegister); + aBlock.Copy(iRegister); + } + +/* CModeCBCDecryptor */ +EXPORT_C CModeCBCDecryptor* CModeCBCDecryptor::NewL(CBlockTransformation* aBT, + const TDesC8& aIV) + { + CModeCBCDecryptor* self = CModeCBCDecryptorShim::NewL(aBT, aIV); + if (! self) + { + // not able to use CryptoSpi, possibly due to an exterally + // derived legacy class so fallback to old implementation. + self = NewLC(aBT,aIV); + CleanupStack::Pop(self); + } + return self; + } + +EXPORT_C CModeCBCDecryptor* CModeCBCDecryptor::NewLC(CBlockTransformation* aBT, + const TDesC8& aIV) + { + CModeCBCDecryptor* self = new (ELeave)CModeCBCDecryptor(); + CleanupStack::PushL(self); + self->ConstructL(aBT, aIV); + return self; + } + +void CModeCBCDecryptor::ConstructL(CBlockTransformation* aBT, const TDesC8& aIV) + { + iIVBakBuf = aIV.AllocL(); + iIVBak.Set(iIVBakBuf->Des()); + CBlockChainingMode::ConstructL(aBT, aIV); + } + +CModeCBCDecryptor::~CModeCBCDecryptor(void) + { + delete iIVBakBuf; + } + +CModeCBCDecryptor::CModeCBCDecryptor() + : iIVBak(0,0,0) + { + } + +void CModeCBCDecryptor::Transform(TDes8& aBlock) + { + assert(aBlock.Size() == iBT->BlockSize()); + assert(iRegister.Size() == aBlock.Size()); + assert(iIVBak.Size() == aBlock.Size()); + + // Take a copy of incoming block + iIVBak.Copy(aBlock); + + // transform the block + iBT->Transform(aBlock); + + // xor the output with the register + XorBuf(const_cast(aBlock.Ptr()), iRegister.Ptr(), + aBlock.Size()); + + // Update the register to be the original block + iRegister.Copy(iIVBak); +} + diff -r 7e3f204e6c81 -r f9c11be8c0b3 crypto/weakcryptospi/source/symmetric/cbcmodeshim.cpp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/crypto/weakcryptospi/source/symmetric/cbcmodeshim.cpp Tue Dec 01 11:12:04 2009 +0000 @@ -0,0 +1,214 @@ +/* +* Copyright (c) 2006-2009 Nokia Corporation and/or its subsidiary(-ies). +* All rights reserved. +* This component and the accompanying materials are made available +* under the terms of the License "Eclipse Public License v1.0" +* which accompanies this distribution, and is available +* at the URL "http://www.eclipse.org/legal/epl-v10.html". +* +* Initial Contributors: +* Nokia Corporation - initial contribution. +* +* Contributors: +* +* Description: +* +*/ + + +#include "cbcmodeshim.h" + +#include +#include +#include +#include "cryptosymmetriccipherapi.h" +#include +#include "../common/inlines.h" + +// CModeCBCEncryptorShim +CModeCBCEncryptorShim::CModeCBCEncryptorShim(CryptoSpi::CSymmetricCipher* aSymmetricCipherImpl) : + iSymmetricCipherImpl(aSymmetricCipherImpl) + { + } + +CModeCBCEncryptorShim* CModeCBCEncryptorShim::NewL(CBlockTransformation* aBT, const TDesC8& aIv) + { + CModeCBCEncryptorShim* self(0); + + // Check whether the block transform contains an SPI plug-in + TAny* implPtr(0); + TInt err = aBT->GetExtension(CryptoSpi::KSymmetricCipherInterface, implPtr, NULL); + if (err == KErrNone && implPtr) + { + CryptoSpi::CSymmetricCipher* impl(static_cast(implPtr)); + + const CryptoSpi::TCharacteristics* c(0); + impl->GetCharacteristicsL(c); + + const CryptoSpi::TSymmetricCipherCharacteristics* cipherCharacteristics( + static_cast(c)); + + // Verify that the plug-in supports CBC mode + if (err == KErrNone && + cipherCharacteristics->IsOperationModeSupported(CryptoSpi::KOperationModeCBCUid)) + { + // Set block transform to encrypt-cbc + impl->SetCryptoModeL(CryptoSpi::KCryptoModeEncryptUid); + impl->SetOperationModeL(CryptoSpi::KOperationModeCBCUid); + impl->SetIvL(aIv); + self = new(ELeave) CModeCBCEncryptorShim(impl); + CleanupStack::PushL(self); + self->ConstructL(aBT, aIv); + CleanupStack::Pop(self); + } + } + return self; + } + +void CModeCBCEncryptorShim::ConstructL(CBlockTransformation* aBT, const TDesC8& aIv) + { + CModeCBCEncryptor::ConstructL(aBT, aIv); + } + +void CModeCBCEncryptorShim::Reset() + { + iSymmetricCipherImpl->Reset(); + } + +TInt CModeCBCEncryptorShim::BlockSize() const + { + return BitsToBytes(iSymmetricCipherImpl->BlockSize()); + } + +TInt CModeCBCEncryptorShim::KeySize() const + { + return iSymmetricCipherImpl->KeySize(); + } + +void CModeCBCEncryptorShim::Transform(TDes8& aBlock) + { + // This function will never get called if a buffered + // encryptor is used because Process and ProcessFinalL call + // iSymmetricCipherImpl directly + iBT->Transform(aBlock); + } + +void CModeCBCEncryptorShim::SetIV(const TDesC8& aIv) + { + TRAPD(err, iSymmetricCipherImpl->SetIvL(aIv)); + if (err == KErrOverflow) + { + User::Panic(KCryptoPanic, ECryptoPanicInputTooLarge); + } + else if (err != KErrNone) + { + // SetIvL should only leave if the aIv is incorrect + User::Panic(KCryptoPanic, KErrArgument); + } + } + +TInt CModeCBCEncryptorShim::Extension_(TUint aExtensionId, TAny*& a0, TAny* /*a1*/) + { + TInt ret(KErrExtensionNotSupported); + + if (CryptoSpi::KSymmetricCipherInterface == aExtensionId) + { + a0=iSymmetricCipherImpl; + ret=KErrNone; + } + return ret; + } + +// CModeCBCDecryptorShim +CModeCBCDecryptorShim::CModeCBCDecryptorShim(CryptoSpi::CSymmetricCipher* aSymmetricCipherImpl) : + iSymmetricCipherImpl(aSymmetricCipherImpl) + { + } + +CModeCBCDecryptorShim* CModeCBCDecryptorShim::NewL(CBlockTransformation* aBT, const TDesC8& aIv) + { + CModeCBCDecryptorShim* self(0); + + // Check whether the block transform contains an SPI plug-in + TAny* implPtr(0); + TInt err = aBT->GetExtension(CryptoSpi::KSymmetricCipherInterface, implPtr, NULL); + if (err == KErrNone && implPtr) + { + CryptoSpi::CSymmetricCipher* impl(static_cast(implPtr)); + + const CryptoSpi::TCharacteristics* c(0); + impl->GetCharacteristicsL(c); + + const CryptoSpi::TSymmetricCipherCharacteristics* cipherCharacteristics( + static_cast(c)); + + // Verify that the plug-in supports CBC mode + if (err == KErrNone && + cipherCharacteristics->IsOperationModeSupported(CryptoSpi::KOperationModeCBCUid)) + { + // Set block transform to encrypt-cbc + impl->SetCryptoModeL(CryptoSpi::KCryptoModeDecryptUid); + impl->SetOperationModeL(CryptoSpi::KOperationModeCBCUid); + impl->SetIvL(aIv); + self = new(ELeave) CModeCBCDecryptorShim(impl); + CleanupStack::PushL(self); + self->ConstructL(aBT, aIv); + CleanupStack::Pop(self); + } + } + return self; + } + +void CModeCBCDecryptorShim::ConstructL(CBlockTransformation* aBT, const TDesC8& aIv) + { + CModeCBCDecryptor::ConstructL(aBT, aIv); + } + +void CModeCBCDecryptorShim::Reset() + { + iSymmetricCipherImpl->Reset(); + } + +TInt CModeCBCDecryptorShim::BlockSize() const + { + return BitsToBytes(iSymmetricCipherImpl->BlockSize()); + } + +TInt CModeCBCDecryptorShim::KeySize() const + { + return iSymmetricCipherImpl->KeySize(); + } + +void CModeCBCDecryptorShim::Transform(TDes8& aBlock) + { + // This function will never get called if a buffered + // encryptor is used because Process and ProcessFinalL call + // iSymmetricCipherImpl directly + iBT->Transform(aBlock); + } + +void CModeCBCDecryptorShim::SetIV(const TDesC8& aIv) + { + TRAPD(err, iSymmetricCipherImpl->SetIvL(aIv)); + if (err == KErrOverflow) + { + User::Panic(KCryptoPanic, ECryptoPanicInputTooLarge); + } + else if (err != KErrNone) + { + // SetIvL should only leave if the aIv is incorrect + User::Panic(KCryptoPanic, KErrArgument); + } + } + +TInt CModeCBCDecryptorShim::Extension_(TUint aExtensionId, TAny*& a0, TAny* /*a1*/) + { + TInt ret(KErrExtensionNotSupported); + + if (CryptoSpi::KSymmetricCipherInterface == aExtensionId) + { + a0=iSymmetricCipherImpl; + ret=KErrNone; + } + return ret; + } diff -r 7e3f204e6c81 -r f9c11be8c0b3 crypto/weakcryptospi/source/symmetric/cbcmodeshim.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/crypto/weakcryptospi/source/symmetric/cbcmodeshim.h Tue Dec 01 11:12:04 2009 +0000 @@ -0,0 +1,113 @@ +/* +* Copyright (c) 2006-2009 Nokia Corporation and/or its subsidiary(-ies). +* All rights reserved. +* This component and the accompanying materials are made available +* under the terms of the License "Eclipse Public License v1.0" +* which accompanies this distribution, and is available +* at the URL "http://www.eclipse.org/legal/epl-v10.html". +* +* Initial Contributors: +* Nokia Corporation - initial contribution. +* +* Contributors: +* +* Description: +* +*/ + + +#ifndef __CBCMODESHIM_H__ +#define __CBCMODESHIM_H__ + +#include + +/** +@file +@internalComponent +@released +*/ + +namespace CryptoSpi + { + class CSymmetricCipher; + } + +/** +CBC mode encryptor shim class that delegates all work to CModeCBCEncryptor. +This should only be instantiated by CModeCBCEncryptor::NewLC +*/ +NONSHARABLE_CLASS(CModeCBCEncryptorShim) : public CModeCBCEncryptor +{ +public: + /** + Creates a new CModeCBCEncryptorShim. If the block transfer + @param aBT A pointer to the block transform object. + @param aIV The initialisation vector to use. + @return A pointer to a CModeCBCEncryptorShim instance or NULL if the block transform + does not support SPI or the SPI plug-in does not support CBC mode + */ + static CModeCBCEncryptorShim* NewL(CBlockTransformation* aBT, const TDesC8& aIV); + + // From CBase + TInt Extension_(TUint aExtensionId, TAny*& a0, TAny* a1); + + // From CBlockTransformation + void Reset(); + TInt BlockSize() const; + TInt KeySize() const; + void Transform(TDes8& aBlock); + + // From CBlockChainingMode + void SetIV(const TDesC8& aIv); + +private: + /// Constructor + CModeCBCEncryptorShim(CryptoSpi::CSymmetricCipher* aSymmetricCipherImpl); + + // Just invokes ContructL in super-class + void ConstructL(CBlockTransformation* aBT, const TDesC8& aIv); + + // owned by block transform - iBT + CryptoSpi::CSymmetricCipher* iSymmetricCipherImpl; +}; + +/** +CBC mode decryptor shim class that delegates all work to CModeCBCDecryptor. +This should only be instantiated by CModeCBCDecryptor::NewLC +*/ +NONSHARABLE_CLASS(CModeCBCDecryptorShim) : public CModeCBCDecryptor +{ +public: + /** + Creates a new CModeCBCEncryptorShim. + @param aBT A pointer to the block transform object. + @param aIV The initialisation vector to use. + @return A pointer to a CModeCBCDecryptorShim instance or NULL if the block transform + does not support SPI or the SPI plug-in does not support CBC mode + */ + static CModeCBCDecryptorShim* NewL(CBlockTransformation* aBT, const TDesC8& aIV); + + // From CBase + TInt Extension_(TUint aExtensionId, TAny*& a0, TAny* a1); + + // From CBlockTransformation + void Reset(); + TInt BlockSize() const; + TInt KeySize() const; + void Transform(TDes8& aBlock); + + // From CBlockChainingMode + void SetIV(const TDesC8& aIv); + +private: + /// Constructor + CModeCBCDecryptorShim(CryptoSpi::CSymmetricCipher* aSymmetricCipherImpl); + + // Just invokes ContructL in super-class + void ConstructL(CBlockTransformation* aBT, const TDesC8& aIv); + + // owned by block transform - iBT + CryptoSpi::CSymmetricCipher* iSymmetricCipherImpl; +}; + +#endif // __CBCMODESHIM_H__ diff -r 7e3f204e6c81 -r f9c11be8c0b3 crypto/weakcryptospi/source/symmetric/des.cpp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/crypto/weakcryptospi/source/symmetric/des.cpp Tue Dec 01 11:12:04 2009 +0000 @@ -0,0 +1,159 @@ +/* +* Copyright (c) 2002-2009 Nokia Corporation and/or its subsidiary(-ies). +* All rights reserved. +* This component and the accompanying materials are made available +* under the terms of the License "Eclipse Public License v1.0" +* which accompanies this distribution, and is available +* at the URL "http://www.eclipse.org/legal/epl-v10.html". +* +* Initial Contributors: +* Nokia Corporation - initial contribution. +* +* Contributors: +* +* Description: +* +*/ + + +#include +#include "desshim.h" + +const TInt KDESBlockBytes = 8; +const TInt KDESKeyBytes = 8; + +CDES::~CDES() + { + } + +CDES::CDES() + { + } + +typedef TUint8 TKeyDES[KDESKeyBytes]; +const TInt KKnownWeakKeysCount = 16; + +const TKeyDES weak_keys[KKnownWeakKeysCount] = + { + /* weak keys */ + {0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00}, + {0xFE,0xFE,0xFE,0xFE,0xFE,0xFE,0xFE,0xFE}, + {0x1E,0x1E,0x1E,0x1E,0x0E,0x0E,0x0E,0x0E}, + {0xE0,0xE0,0xE0,0xE0,0xF0,0xF0,0xF0,0xF0}, + {0x00,0xFE,0x00,0xFE,0x00,0xFE,0x00,0xFE}, + {0xFE,0x00,0xFE,0x00,0xFE,0x00,0xFE,0x00}, + {0x1E,0xE0,0x1E,0xE0,0x0E,0xF0,0x0E,0xF0}, + {0xE0,0x1E,0xE0,0x1E,0xF0,0x0E,0xF0,0x0E}, + {0x00,0xE0,0x00,0xE0,0x00,0xF0,0x00,0xF0}, + {0xE0,0x00,0xE0,0x00,0xF0,0x00,0xF0,0x00}, + {0x1E,0xFE,0x1E,0xFE,0x0E,0xFE,0x0E,0xFE}, + {0xFE,0x1E,0xFE,0x1E,0xFE,0x0E,0xFE,0x0E}, + {0x00,0x1E,0x00,0x1E,0x00,0x0E,0x00,0x0E}, + {0x1E,0x00,0x1E,0x00,0x0E,0x00,0x0E,0x00}, + {0xE0,0xFE,0xE0,0xFE,0xF0,0xFE,0xF0,0xFE}, + {0xFE,0xE0,0xFE,0xE0,0xFE,0xF0,0xFE,0xF0} + }; + +EXPORT_C TBool CDES::IsWeakKey(const TDesC8& aKey) + { + TKeyDES key; + TInt index = 0; + //Reset parity bits + for(; index < KDESKeyBytes; index++) + { + key[index] = aKey[index] & 0xFE; + } + + TBool weak = EFalse; + //Compare key with potential weak keys without parity + for (index=0; index < KKnownWeakKeysCount; index++) + { + if (Mem::Compare(weak_keys[index], KDESKeyBytes, &key[0], KDESKeyBytes)==0) + { + weak = ETrue; + break; + } + } + return weak; + } + +/* CDESEncryptor */ +EXPORT_C CDESEncryptor* CDESEncryptor::NewL(const TDesC8& aKey, TBool /*aCheckWeakKey*/) + { + return CDESEncryptorShim::NewL(aKey); + } + +EXPORT_C CDESEncryptor* CDESEncryptor::NewLC(const TDesC8& aKey, TBool /*aCheckWeakKey*/) + { + return CDESEncryptorShim::NewLC(aKey); + } + +CDESEncryptor::CDESEncryptor() + { + } + +/* CDESDecryptor */ +EXPORT_C CDESDecryptor* CDESDecryptor::NewL(const TDesC8& aKey, TBool /*aCheckWeakKey*/) + { + return CDESDecryptorShim::NewL(aKey); + } + +EXPORT_C CDESDecryptor* CDESDecryptor::NewLC(const TDesC8& aKey, TBool /*aCheckWeakKey*/) + { + return CDESDecryptorShim::NewLC(aKey); + } + +CDESDecryptor::CDESDecryptor() + { + } + +// All these methods have been replaced by the shim +#ifdef _BullseyeCoverage +#pragma suppress_warnings on +#pragma BullseyeCoverage off +#pragma suppress_warnings off +#endif + +void CDES::Transform(TDes8& /*aBlock*/) + { + // Method replaced by shim + ASSERT(EFalse); + } + +TInt CDES::BlockSize() const + { + // Method replaced by shim + ASSERT(EFalse); + return KDESBlockBytes; + } + +TInt CDES::KeySize() const + { + // Method replaced by shim + ASSERT(EFalse); + return KDESKeyBytes; + } + +void CDES::Reset() + { + // Method replaced by shim + ASSERT(EFalse); + } + +void CDES::SetKey(const TDesC8& /*aKey*/, TUint32* /*aKeyBuffer*/) + { + // Method replaced by shim + ASSERT(EFalse); + } + +void CDES::ConstructL(const TDesC8& /*aKey*/, TBool /*aCheckWeakKey*/) + { + // Method replaced by shim + ASSERT(EFalse); + } + +void CDESDecryptor::SetKey(const TDesC8& /*aKey*/, TUint32* /*aKeyBuffer*/) + { + // Method replaced by shim + ASSERT(EFalse); + } diff -r 7e3f204e6c81 -r f9c11be8c0b3 crypto/weakcryptospi/source/symmetric/desshim.cpp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/crypto/weakcryptospi/source/symmetric/desshim.cpp Tue Dec 01 11:12:04 2009 +0000 @@ -0,0 +1,191 @@ +/* +* Copyright (c) 2006-2009 Nokia Corporation and/or its subsidiary(-ies). +* All rights reserved. +* This component and the accompanying materials are made available +* under the terms of the License "Eclipse Public License v1.0" +* which accompanies this distribution, and is available +* at the URL "http://www.eclipse.org/legal/epl-v10.html". +* +* Initial Contributors: +* Nokia Corporation - initial contribution. +* +* Contributors: +* +* Description: +* +*/ + + +#include "desshim.h" + +#include "cryptosymmetriccipherapi.h" +#include +#include +#include "keys.h" +#include + +#include "../common/inlines.h" + +using namespace CryptoSpi; + +// CDESEncryptorShim //////////////////////////////////////////////////////// +CDESEncryptorShim* CDESEncryptorShim::NewL(const TDesC8& aKey) + { + CDESEncryptorShim* self = CDESEncryptorShim::NewLC(aKey); + CleanupStack::Pop(self); + return self; + } + +CDESEncryptorShim* CDESEncryptorShim::NewLC(const TDesC8& aKey) + { + CDESEncryptorShim* self = new (ELeave) CDESEncryptorShim(); + CleanupStack::PushL(self); + self->ConstructL(aKey); + // DES only used 7 bits out of every key byte + TCrypto::IsSymmetricWeakEnoughL(BytesToBits(aKey.Size()) - aKey.Size()); + return self; + } + +CDESEncryptorShim::CDESEncryptorShim() + { + } + +CDESEncryptorShim::~CDESEncryptorShim() + { + delete iSymmetricCipherImpl; + delete iKey; + } + +void CDESEncryptorShim::ConstructL(const TDesC8& aKey) + { + TKeyProperty keyProperty = {KDesUid, KNullUid, KSymmetricKey, KNonEmbeddedKeyUid}; + CCryptoParams* keyParam =CCryptoParams::NewLC(); + keyParam->AddL(aKey, KSymmetricKeyParameterUid); + iKey=CKey::NewL(keyProperty, *keyParam); + CleanupStack::PopAndDestroy(keyParam); + CSymmetricCipherFactory::CreateSymmetricCipherL( + iSymmetricCipherImpl, + KDesUid, + *iKey, + KCryptoModeEncryptUid, + KOperationModeECBUid, + KPaddingModeNoneUid, + NULL); + } + +TInt CDESEncryptorShim::BlockSize() const + { + // SPI returns block size in BITS + return BitsToBytes(iSymmetricCipherImpl->BlockSize()); + } + +TInt CDESEncryptorShim::KeySize() const + { + return iSymmetricCipherImpl->KeySize(); + } + +void CDESEncryptorShim::Transform(TDes8& aBlock) + { + iOutputBlock.Zero(); + TRAP_IGNORE(iSymmetricCipherImpl->ProcessL(aBlock, iOutputBlock);) + aBlock = iOutputBlock; + } + +void CDESEncryptorShim::Reset() + { + iSymmetricCipherImpl->Reset(); + } + +TInt CDESEncryptorShim::Extension_(TUint aExtensionId, TAny*& a0, TAny* /*a1*/) + { + TInt ret(KErrNotSupported); + + if (CryptoSpi::KSymmetricCipherInterface == aExtensionId && iSymmetricCipherImpl) + { + a0=iSymmetricCipherImpl; + ret=KErrNone; + } + return ret; + } + +// CDESDecryptorShim //////////////////////////////////////////////////////// +CDESDecryptorShim* CDESDecryptorShim::NewL(const TDesC8& aKey) + { + CDESDecryptorShim* self = CDESDecryptorShim::NewLC(aKey); + CleanupStack::Pop(self); + return self; + } + + +CDESDecryptorShim* CDESDecryptorShim::NewLC(const TDesC8& aKey) + { + CDESDecryptorShim* self = new (ELeave) CDESDecryptorShim(); + CleanupStack::PushL(self); + self->ConstructL(aKey); + // DES only used 7 bits out of every key byte + TCrypto::IsSymmetricWeakEnoughL(BytesToBits(aKey.Size()) - aKey.Size()); + return self; + } + +CDESDecryptorShim::CDESDecryptorShim() + { + } + +CDESDecryptorShim::~CDESDecryptorShim() + { + delete iSymmetricCipherImpl; + delete iKey; + } + + +void CDESDecryptorShim::ConstructL(const TDesC8& aKey) + { + TKeyProperty keyProperty = {KDesUid, KNullUid, KSymmetricKey, KNonEmbeddedKeyUid}; + CCryptoParams* keyParam =CCryptoParams::NewLC(); + keyParam->AddL(aKey, KSymmetricKeyParameterUid); + iKey=CKey::NewL(keyProperty, *keyParam); + CleanupStack::PopAndDestroy(keyParam); + CSymmetricCipherFactory::CreateSymmetricCipherL( + iSymmetricCipherImpl, + KDesUid, + *iKey, + KCryptoModeDecryptUid, + KOperationModeECBUid, + KPaddingModeNoneUid, + NULL); + } + +TInt CDESDecryptorShim::BlockSize() const + { + // SPI returns block size in BITS + return BitsToBytes(iSymmetricCipherImpl->BlockSize()); + } + +TInt CDESDecryptorShim::KeySize() const + { + return iSymmetricCipherImpl->KeySize(); + } + +void CDESDecryptorShim::Transform(TDes8& aBlock) + { + iOutputBlock.Zero(); + TRAP_IGNORE(iSymmetricCipherImpl->ProcessL(aBlock, iOutputBlock);) + aBlock = iOutputBlock; + } + +void CDESDecryptorShim::Reset() + { + iSymmetricCipherImpl->Reset(); + } + +TInt CDESDecryptorShim::Extension_(TUint aExtensionId, TAny*& a0, TAny* /*a1*/) + { + TInt ret(KErrNotSupported); + + if (CryptoSpi::KSymmetricCipherInterface == aExtensionId && iSymmetricCipherImpl) + { + a0=iSymmetricCipherImpl; + ret=KErrNone; + } + return ret; + } diff -r 7e3f204e6c81 -r f9c11be8c0b3 crypto/weakcryptospi/source/symmetric/desshim.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/crypto/weakcryptospi/source/symmetric/desshim.h Tue Dec 01 11:12:04 2009 +0000 @@ -0,0 +1,145 @@ +/* +* Copyright (c) 2006-2009 Nokia Corporation and/or its subsidiary(-ies). +* All rights reserved. +* This component and the accompanying materials are made available +* under the terms of the License "Eclipse Public License v1.0" +* which accompanies this distribution, and is available +* at the URL "http://www.eclipse.org/legal/epl-v10.html". +* +* Initial Contributors: +* Nokia Corporation - initial contribution. +* +* Contributors: +* +* Description: +* DES shim classes definition +* +*/ + + +/** + @file + @internalComponent + @released +*/ + +#ifndef __DESSHIM_H__ +#define __DESSHIM_H__ + +#include + +namespace CryptoSpi + { + class CSymmetricCipher; + class CKey; + } + +NONSHARABLE_CLASS(CDESEncryptorShim) : public CDESEncryptor +{ +public: + /** + Creates an CDESEncryptorShim object which has the same interface + as DESEncryptor but delegates all work to a Crypto SPI plug-in. + + @param aKey The encryption key + @return A pointer to a CDESEncryptorShim instance + */ + static CDESEncryptorShim* NewL(const TDesC8& aKey); + + /** + Creates an CDESEncryptorShim object which has the same interface + as DESEncryptor but delegates all work to a Crypto SPI plug-in. + + A pointer to the new object is placed on the cleanup stack + + @param aKey The encryption key + @return A pointer to a CDESEncryptorShim instance + */ + static CDESEncryptorShim* NewLC(const TDesC8& aKey); + + // From CBlockTransform + TInt BlockSize() const; + void Transform(TDes8& aBlock); + void Reset(void); + TInt KeySize(void) const; + + /// Destructor + ~CDESEncryptorShim(); + +private: + /// Constructor + CDESEncryptorShim(); + void ConstructL(const TDesC8& aKey); + + // From CBase + TInt Extension_(TUint aExtensionId, TAny*& a0, TAny* a1); + +private: + /// SPI delegate + CryptoSpi::CSymmetricCipher* iSymmetricCipherImpl; + + /// SPI requires all key to passed as key-objects + CryptoSpi::CKey* iKey; + + /// Temporary output block, SPI does not overwrite input + /// DES uses 64bit blocks + TBuf8<16> iOutputBlock; +}; + +NONSHARABLE_CLASS(CDESDecryptorShim) : public CDESDecryptor +{ +public: + /** + Creates an CDESDecryptorShim object which has the same interface + as DESDecryptor but delegates all work to a Crypto SPI plug-in. + + @param aKey The decryption key + @return A pointer to a CDESDecryptorShim instance + */ + static CDESDecryptorShim* NewL(const TDesC8& aKey); + + /** + Creates an CDESDecryptorShim object which has the same interface + as DESDecryptor but delegates all work to a Crypto SPI plug-in. + + A pointer to the new object is placed on the cleanup stack + + @param aKey The decryption key + @return A pointer to a CDESDecryptorShim instance + */ + static CDESDecryptorShim* NewLC(const TDesC8& aKey); + + // From CBlockTransform + TInt BlockSize() const; + void Transform(TDes8& aBlock); + void Reset(void); + TInt KeySize(void) const; + + /// Destructor + ~CDESDecryptorShim(); + +private: + /// Constructor + CDESDecryptorShim(); + void ConstructL(const TDesC8& aKey); + + /** + From CBase, to allow CBufferedTransform & CBlockChainingMode + to determine whether the functionality may be delegated to + the SPI object. + */ + TInt Extension_(TUint aExtensionId, TAny*& a0, TAny* a1); + +private: + /// SPI delegate + CryptoSpi::CSymmetricCipher* iSymmetricCipherImpl; + + /// SPI requires all key to passed as key-objects + CryptoSpi::CKey* iKey; + + /// Temporary output block, SPI does not overwrite input + /// DES uses 64bit blocks + TBuf8<16> iOutputBlock; +}; + +#endif // __DESSHIM_H__ diff -r 7e3f204e6c81 -r f9c11be8c0b3 crypto/weakcryptospi/source/symmetric/destables.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/crypto/weakcryptospi/source/symmetric/destables.h Tue Dec 01 11:12:04 2009 +0000 @@ -0,0 +1,184 @@ +/* +* Copyright (c) 2002-2009 Nokia Corporation and/or its subsidiary(-ies). +* All rights reserved. +* This component and the accompanying materials are made available +* under the terms of the License "Eclipse Public License v1.0" +* which accompanies this distribution, and is available +* at the URL "http://www.eclipse.org/legal/epl-v10.html". +* +* Initial Contributors: +* Nokia Corporation - initial contribution. +* +* Contributors: +* +* Description: +* DES Tables +* +*/ + + +/** + @file + @internalComponent +*/ + +#ifndef __DESTABLES_H__ +#define __DESTABLES_H__ + +#include + +namespace DES_TABLE +{ +/* initial permutation IP */ +const TUint8 ip[] = { + 58, 50, 42, 34, 26, 18, 10, 2, + 60, 52, 44, 36, 28, 20, 12, 4, + 62, 54, 46, 38, 30, 22, 14, 6, + 64, 56, 48, 40, 32, 24, 16, 8, + 57, 49, 41, 33, 25, 17, 9, 1, + 59, 51, 43, 35, 27, 19, 11, 3, + 61, 53, 45, 37, 29, 21, 13, 5, + 63, 55, 47, 39, 31, 23, 15, 7 +}; + +/* final permutation IP^-1 */ +const TUint8 fp[] = { + 40, 8, 48, 16, 56, 24, 64, 32, + 39, 7, 47, 15, 55, 23, 63, 31, + 38, 6, 46, 14, 54, 22, 62, 30, + 37, 5, 45, 13, 53, 21, 61, 29, + 36, 4, 44, 12, 52, 20, 60, 28, + 35, 3, 43, 11, 51, 19, 59, 27, + 34, 2, 42, 10, 50, 18, 58, 26, + 33, 1, 41, 9, 49, 17, 57, 25 +}; + +/* expansion operation matrix */ +const TUint8 ei[] = { + 32, 1, 2, 3, 4, 5, + 4, 5, 6, 7, 8, 9, + 8, 9, 10, 11, 12, 13, + 12, 13, 14, 15, 16, 17, + 16, 17, 18, 19, 20, 21, + 20, 21, 22, 23, 24, 25, + 24, 25, 26, 27, 28, 29, + 28, 29, 30, 31, 32, 1 +}; + +const TUint32 sbox[8][64] = { +{ +0x01010400,0x00000000,0x00010000,0x01010404, 0x01010004,0x00010404,0x00000004,0x00010000, +0x00000400,0x01010400,0x01010404,0x00000400, 0x01000404,0x01010004,0x01000000,0x00000004, +0x00000404,0x01000400,0x01000400,0x00010400, 0x00010400,0x01010000,0x01010000,0x01000404, +0x00010004,0x01000004,0x01000004,0x00010004, 0x00000000,0x00000404,0x00010404,0x01000000, +0x00010000,0x01010404,0x00000004,0x01010000, 0x01010400,0x01000000,0x01000000,0x00000400, +0x01010004,0x00010000,0x00010400,0x01000004, 0x00000400,0x00000004,0x01000404,0x00010404, +0x01010404,0x00010004,0x01010000,0x01000404, 0x01000004,0x00000404,0x00010404,0x01010400, +0x00000404,0x01000400,0x01000400,0x00000000, 0x00010004,0x00010400,0x00000000,0x01010004}, +{ +0x80108020,0x80008000,0x00008000,0x00108020, 0x00100000,0x00000020,0x80100020,0x80008020, +0x80000020,0x80108020,0x80108000,0x80000000, 0x80008000,0x00100000,0x00000020,0x80100020, +0x00108000,0x00100020,0x80008020,0x00000000, 0x80000000,0x00008000,0x00108020,0x80100000, +0x00100020,0x80000020,0x00000000,0x00108000, 0x00008020,0x80108000,0x80100000,0x00008020, +0x00000000,0x00108020,0x80100020,0x00100000, 0x80008020,0x80100000,0x80108000,0x00008000, +0x80100000,0x80008000,0x00000020,0x80108020, 0x00108020,0x00000020,0x00008000,0x80000000, +0x00008020,0x80108000,0x00100000,0x80000020, 0x00100020,0x80008020,0x80000020,0x00100020, +0x00108000,0x00000000,0x80008000,0x00008020, 0x80000000,0x80100020,0x80108020,0x00108000}, +{ +0x00000208,0x08020200,0x00000000,0x08020008, 0x08000200,0x00000000,0x00020208,0x08000200, +0x00020008,0x08000008,0x08000008,0x00020000, 0x08020208,0x00020008,0x08020000,0x00000208, +0x08000000,0x00000008,0x08020200,0x00000200, 0x00020200,0x08020000,0x08020008,0x00020208, +0x08000208,0x00020200,0x00020000,0x08000208, 0x00000008,0x08020208,0x00000200,0x08000000, +0x08020200,0x08000000,0x00020008,0x00000208, 0x00020000,0x08020200,0x08000200,0x00000000, +0x00000200,0x00020008,0x08020208,0x08000200, 0x08000008,0x00000200,0x00000000,0x08020008, +0x08000208,0x00020000,0x08000000,0x08020208, 0x00000008,0x00020208,0x00020200,0x08000008, +0x08020000,0x08000208,0x00000208,0x08020000, 0x00020208,0x00000008,0x08020008,0x00020200}, +{ +0x00802001,0x00002081,0x00002081,0x00000080, 0x00802080,0x00800081,0x00800001,0x00002001, +0x00000000,0x00802000,0x00802000,0x00802081, 0x00000081,0x00000000,0x00800080,0x00800001, +0x00000001,0x00002000,0x00800000,0x00802001, 0x00000080,0x00800000,0x00002001,0x00002080, +0x00800081,0x00000001,0x00002080,0x00800080, 0x00002000,0x00802080,0x00802081,0x00000081, +0x00800080,0x00800001,0x00802000,0x00802081, 0x00000081,0x00000000,0x00000000,0x00802000, +0x00002080,0x00800080,0x00800081,0x00000001, 0x00802001,0x00002081,0x00002081,0x00000080, +0x00802081,0x00000081,0x00000001,0x00002000, 0x00800001,0x00002001,0x00802080,0x00800081, +0x00002001,0x00002080,0x00800000,0x00802001, 0x00000080,0x00800000,0x00002000,0x00802080}, +{ +0x00000100,0x02080100,0x02080000,0x42000100, 0x00080000,0x00000100,0x40000000,0x02080000, +0x40080100,0x00080000,0x02000100,0x40080100, 0x42000100,0x42080000,0x00080100,0x40000000, +0x02000000,0x40080000,0x40080000,0x00000000, 0x40000100,0x42080100,0x42080100,0x02000100, +0x42080000,0x40000100,0x00000000,0x42000000, 0x02080100,0x02000000,0x42000000,0x00080100, +0x00080000,0x42000100,0x00000100,0x02000000, 0x40000000,0x02080000,0x42000100,0x40080100, +0x02000100,0x40000000,0x42080000,0x02080100, 0x40080100,0x00000100,0x02000000,0x42080000, +0x42080100,0x00080100,0x42000000,0x42080100, 0x02080000,0x00000000,0x40080000,0x42000000, +0x00080100,0x02000100,0x40000100,0x00080000, 0x00000000,0x40080000,0x02080100,0x40000100}, +{ +0x20000010,0x20400000,0x00004000,0x20404010, 0x20400000,0x00000010,0x20404010,0x00400000, +0x20004000,0x00404010,0x00400000,0x20000010, 0x00400010,0x20004000,0x20000000,0x00004010, +0x00000000,0x00400010,0x20004010,0x00004000, 0x00404000,0x20004010,0x00000010,0x20400010, +0x20400010,0x00000000,0x00404010,0x20404000, 0x00004010,0x00404000,0x20404000,0x20000000, +0x20004000,0x00000010,0x20400010,0x00404000, 0x20404010,0x00400000,0x00004010,0x20000010, +0x00400000,0x20004000,0x20000000,0x00004010, 0x20000010,0x20404010,0x00404000,0x20400000, +0x00404010,0x20404000,0x00000000,0x20400010, 0x00000010,0x00004000,0x20400000,0x00404010, +0x00004000,0x00400010,0x20004010,0x00000000, 0x20404000,0x20000000,0x00400010,0x20004010}, +{ +0x00200000,0x04200002,0x04000802,0x00000000, 0x00000800,0x04000802,0x00200802,0x04200800, +0x04200802,0x00200000,0x00000000,0x04000002, 0x00000002,0x04000000,0x04200002,0x00000802, +0x04000800,0x00200802,0x00200002,0x04000800, 0x04000002,0x04200000,0x04200800,0x00200002, +0x04200000,0x00000800,0x00000802,0x04200802, 0x00200800,0x00000002,0x04000000,0x00200800, +0x04000000,0x00200800,0x00200000,0x04000802, 0x04000802,0x04200002,0x04200002,0x00000002, +0x00200002,0x04000000,0x04000800,0x00200000, 0x04200800,0x00000802,0x00200802,0x04200800, +0x00000802,0x04000002,0x04200802,0x04200000, 0x00200800,0x00000000,0x00000002,0x04200802, +0x00000000,0x00200802,0x04200000,0x00000800, 0x04000002,0x04000800,0x00000800,0x00200002}, +{ +0x10001040,0x00001000,0x00040000,0x10041040, 0x10000000,0x10001040,0x00000040,0x10000000, +0x00040040,0x10040000,0x10041040,0x00041000, 0x10041000,0x00041040,0x00001000,0x00000040, +0x10040000,0x10000040,0x10001000,0x00001040, 0x00041000,0x00040040,0x10040040,0x10041000, +0x00001040,0x00000000,0x00000000,0x10040040, 0x10000040,0x10001000,0x00041040,0x00040000, +0x00041040,0x00040000,0x10041000,0x00001000, 0x00000040,0x10040040,0x00001000,0x00041040, +0x10001000,0x00000040,0x10000040,0x10040000, 0x10040040,0x10000000,0x00040000,0x10001040, +0x00000000,0x10041040,0x00040040,0x10000040, 0x10040000,0x10001000,0x10001040,0x00000000, +0x10041040,0x00041000,0x00041000,0x00001040, 0x00001040,0x00040040,0x10000000,0x10041000} +}; + + +/* 32-bit permutation function P used on the output of the S-boxes */ +const TUint8 p32i[] = { + 16, 7, 20, 21, + 29, 12, 28, 17, + 1, 15, 23, 26, + 5, 18, 31, 10, + 2, 8, 24, 14, + 32, 27, 3, 9, + 19, 13, 30, 6, + 22, 11, 4, 25 +}; + +/* permuted choice table (key) */ +const TUint8 pc1[] = { + 57, 49, 41, 33, 25, 17, 9, + 1, 58, 50, 42, 34, 26, 18, + 10, 2, 59, 51, 43, 35, 27, + 19, 11, 3, 60, 52, 44, 36, + + 63, 55, 47, 39, 31, 23, 15, + 7, 62, 54, 46, 38, 30, 22, + 14, 6, 61, 53, 45, 37, 29, + 21, 13, 5, 28, 20, 12, 4 +}; + +/* number left rotations of pc1 */ +const TUint8 totrot[] = {1,2,4,6,8,10,12,14,15,17,19,21,23,25,27,28}; + +/* permuted choice key (table) */ +const TUint8 pc2[] = { + 14, 17, 11, 24, 1, 5, + 3, 28, 15, 6, 21, 10, + 23, 19, 12, 4, 26, 8, + 16, 7, 27, 20, 13, 2, + 41, 52, 31, 37, 47, 55, + 30, 40, 51, 45, 33, 48, + 44, 49, 39, 56, 34, 53, + 46, 42, 50, 36, 29, 32 +}; +} // namespace DES_TABLE +#endif // __DESTABLES_H__ diff -r 7e3f204e6c81 -r f9c11be8c0b3 crypto/weakcryptospi/source/symmetric/mstreamcipher.cpp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/crypto/weakcryptospi/source/symmetric/mstreamcipher.cpp Tue Dec 01 11:12:04 2009 +0000 @@ -0,0 +1,57 @@ +/* +* Copyright (c) 2002-2009 Nokia Corporation and/or its subsidiary(-ies). +* All rights reserved. +* This component and the accompanying materials are made available +* under the terms of the License "Eclipse Public License v1.0" +* which accompanies this distribution, and is available +* at the URL "http://www.eclipse.org/legal/epl-v10.html". +* +* Initial Contributors: +* Nokia Corporation - initial contribution. +* +* Contributors: +* +* Description: +* streamcipher.cpp +* +*/ + + +#include "streamcipher.h" +#include + +EXPORT_C void CStreamCipher::ProcessFinalL(const TDesC8& aInput, TDes8& aOutput) + { + Process(aInput, aOutput); + } + +EXPORT_C void CStreamCipher::Process(const TDesC8& aInput, TDes8& aOutput) + { + TInt outputIndex = aOutput.Size(); + + // aOutput may already have outputIndex bytes of data in it + // check there will still be enough space to process the result + __ASSERT_DEBUG(aOutput.MaxLength() - outputIndex >= MaxOutputLength(aInput.Length()), User::Panic(KCryptoPanic, ECryptoPanicOutputDescriptorOverflow)); + + aOutput.Append(aInput); + + TPtr8 transformBuf((TUint8*)(aOutput.Ptr()) + outputIndex, aInput.Size(), + aInput.Size()); + DoProcess(transformBuf); + } + +EXPORT_C TInt CStreamCipher::BlockSize() const + { + return (1); + } + +EXPORT_C TInt CStreamCipher::MaxOutputLength(TInt aInputLength) const + { + return aInputLength; + } + +EXPORT_C TInt CStreamCipher::MaxFinalOutputLength(TInt aInputLength) const + { + return aInputLength; + } + diff -r 7e3f204e6c81 -r f9c11be8c0b3 crypto/weakcryptospi/source/symmetric/nullcipher.cpp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/crypto/weakcryptospi/source/symmetric/nullcipher.cpp Tue Dec 01 11:12:04 2009 +0000 @@ -0,0 +1,51 @@ +/* +* Copyright (c) 2002-2009 Nokia Corporation and/or its subsidiary(-ies). +* All rights reserved. +* This component and the accompanying materials are made available +* under the terms of the License "Eclipse Public License v1.0" +* which accompanies this distribution, and is available +* at the URL "http://www.eclipse.org/legal/epl-v10.html". +* +* Initial Contributors: +* Nokia Corporation - initial contribution. +* +* Contributors: +* +* Description: +* +*/ + + +#include "nullcipher.h" + +const TUint KNullKeyBytes = 0; + +EXPORT_C CNullCipher* CNullCipher::NewL(void) + { + CNullCipher* self = new(ELeave)CNullCipher; + return self; + } + +EXPORT_C CNullCipher* CNullCipher::NewLC(void) + { + CNullCipher *self = NewL(); + CleanupStack::PushL(self); + return self; + } + +void CNullCipher::Reset(void) + { + } + +TInt CNullCipher::KeySize(void) const + { + return KNullKeyBytes; + } + +void CNullCipher::DoProcess(TDes8& /*aData*/) + { + } + +CNullCipher::CNullCipher(void) + { + } diff -r 7e3f204e6c81 -r f9c11be8c0b3 crypto/weakcryptospi/source/symmetric/rc2.cpp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/crypto/weakcryptospi/source/symmetric/rc2.cpp Tue Dec 01 11:12:04 2009 +0000 @@ -0,0 +1,100 @@ +/* +* Copyright (c) 2002-2009 Nokia Corporation and/or its subsidiary(-ies). +* All rights reserved. +* This component and the accompanying materials are made available +* under the terms of the License "Eclipse Public License v1.0" +* which accompanies this distribution, and is available +* at the URL "http://www.eclipse.org/legal/epl-v10.html". +* +* Initial Contributors: +* Nokia Corporation - initial contribution. +* +* Contributors: +* +* Description: +* +*/ + + +#include +#include "rc2shim.h" + +CRC2::CRC2() + { + } + +/* CRC2Encryptor */ +EXPORT_C CRC2Encryptor* CRC2Encryptor::NewL(const TDesC8& aKey, TInt aEffectiveKeyLenBits) + { + return CRC2EncryptorShim::NewL(aKey, aEffectiveKeyLenBits); + } + +EXPORT_C CRC2Encryptor* CRC2Encryptor::NewLC(const TDesC8& aKey, TInt aEffectiveKeyLenBits) + { + return CRC2EncryptorShim::NewLC(aKey, aEffectiveKeyLenBits); + } + +CRC2Encryptor::CRC2Encryptor() + { + } + +/* CRC2Decryptor */ +EXPORT_C CRC2Decryptor* CRC2Decryptor::NewL(const TDesC8& aKey, TInt aEffectiveKeyLenBits) + { + return CRC2DecryptorShim::NewL(aKey, aEffectiveKeyLenBits); + } + +EXPORT_C CRC2Decryptor* CRC2Decryptor::NewLC(const TDesC8& aKey, TInt aEffectiveKeyLenBits) + { + return CRC2DecryptorShim::NewLC(aKey, aEffectiveKeyLenBits); + } + +CRC2Decryptor::CRC2Decryptor() + { + } + +// All these methods have been replaced by the shim +#ifdef _BullseyeCoverage +#pragma suppress_warnings on +#pragma BullseyeCoverage off +#pragma suppress_warnings off +#endif + +TInt CRC2::BlockSize() const + { + // Method replaced by shim + ASSERT(EFalse); + return 0; + } + +TInt CRC2::KeySize() const + { + // Method replaced by shim + ASSERT(EFalse); + return 0; + } + +void CRC2::Reset() + { + // Method replaced by shim + ASSERT(EFalse); + } + +void CRC2::SetKey(const TDesC8& /*aKey*/, TInt /*aEffectiveKeyLenBits*/) + { + // Method replaced by shim + ASSERT(EFalse); + } + +void CRC2Decryptor::Transform(TDes8& /*aBlock*/) + { + // Method replaced by shim + ASSERT(EFalse); + } + +void CRC2Encryptor::Transform(TDes8& /*aBlock*/) + { + // Method replaced by shim + ASSERT(EFalse); + } + diff -r 7e3f204e6c81 -r f9c11be8c0b3 crypto/weakcryptospi/source/symmetric/rc2shim.cpp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/crypto/weakcryptospi/source/symmetric/rc2shim.cpp Tue Dec 01 11:12:04 2009 +0000 @@ -0,0 +1,204 @@ +/* +* Copyright (c) 2006-2009 Nokia Corporation and/or its subsidiary(-ies). +* All rights reserved. +* This component and the accompanying materials are made available +* under the terms of the License "Eclipse Public License v1.0" +* which accompanies this distribution, and is available +* at the URL "http://www.eclipse.org/legal/epl-v10.html". +* +* Initial Contributors: +* Nokia Corporation - initial contribution. +* +* Contributors: +* +* Description: +* +*/ + + +#include "rc2shim.h" + +#include +#include "cryptosymmetriccipherapi.h" +#include +#include +#include "keys.h" +#include + +#include "../common/inlines.h" + +using namespace CryptoSpi; + +// CRC2EncryptorShim //////////////////////////////////////////////////////// +CRC2EncryptorShim* CRC2EncryptorShim::NewL(const TDesC8& aKey, TInt aEffectiveKeyLenBits) + { + CRC2EncryptorShim* self = CRC2EncryptorShim::NewLC(aKey, aEffectiveKeyLenBits); + CleanupStack::Pop(self); + return self; + } + +CRC2EncryptorShim* CRC2EncryptorShim::NewLC(const TDesC8& aKey, TInt aEffectiveKeyLenBits) + { + CRC2EncryptorShim* self = new (ELeave) CRC2EncryptorShim(); + CleanupStack::PushL(self); + self->ConstructL(aKey, aEffectiveKeyLenBits); + // weak enough if either aKey or aEffectiveKeyLenBits is weak + TInt minKeySize = Min(aEffectiveKeyLenBits, BytesToBits(aKey.Size())); + TCrypto::IsSymmetricWeakEnoughL(minKeySize); + return self; + } + +CRC2EncryptorShim::CRC2EncryptorShim() + { + } + +CRC2EncryptorShim::~CRC2EncryptorShim() + { + delete iSymmetricCipherImpl; + delete iKey; + delete iAlgorithmParams; + } + +void CRC2EncryptorShim::ConstructL(const TDesC8& aKey, TInt aEffectiveKeyLenBits) + { + TKeyProperty keyProperty = {KRc2Uid, KNullUid, KSymmetricKeyUid, KNonEmbeddedKeyUid}; + CCryptoParams* keyParam =CCryptoParams::NewLC(); + keyParam->AddL(aKey, KSymmetricKeyParameterUid); + iKey=CKey::NewL(keyProperty, *keyParam); + CleanupStack::PopAndDestroy(keyParam); + + iAlgorithmParams = CCryptoParams::NewL(); + iAlgorithmParams->AddL(aEffectiveKeyLenBits, KRC2EffectiveKeyLenBits); + + CSymmetricCipherFactory::CreateSymmetricCipherL( + iSymmetricCipherImpl, + KRc2Uid, + *iKey, + KCryptoModeEncryptUid, + KOperationModeECBUid, + KPaddingModeNoneUid, + iAlgorithmParams); + } + +TInt CRC2EncryptorShim::BlockSize() const + { + // SPI returns block size in BITS + return BitsToBytes(iSymmetricCipherImpl->BlockSize()); + } + +TInt CRC2EncryptorShim::KeySize() const + { + return iSymmetricCipherImpl->KeySize(); + } + +void CRC2EncryptorShim::Transform(TDes8& aBlock) + { + iOutputBlock.Zero(); + TRAP_IGNORE(iSymmetricCipherImpl->ProcessL(aBlock, iOutputBlock);) + aBlock = iOutputBlock; + } + +void CRC2EncryptorShim::Reset() + { + iSymmetricCipherImpl->Reset(); + } + +TInt CRC2EncryptorShim::Extension_(TUint aExtensionId, TAny*& a0, TAny* /*a1*/) + { + TInt ret(KErrExtensionNotSupported); + + if (KSymmetricCipherInterface == aExtensionId && iSymmetricCipherImpl) + { + a0=iSymmetricCipherImpl; + ret=KErrNone; + } + return ret; + } + +// CRC2DecryptorShim //////////////////////////////////////////////////////// +CRC2DecryptorShim* CRC2DecryptorShim::NewL(const TDesC8& aKey, TInt aEffectiveKeyLenBits) + { + CRC2DecryptorShim* self = CRC2DecryptorShim::NewLC(aKey, aEffectiveKeyLenBits); + CleanupStack::Pop(self); + return self; + } + + +CRC2DecryptorShim* CRC2DecryptorShim::NewLC(const TDesC8& aKey, TInt aEffectiveKeyLenBits) + { + CRC2DecryptorShim* self = new (ELeave) CRC2DecryptorShim(); + CleanupStack::PushL(self); + self->ConstructL(aKey, aEffectiveKeyLenBits); + // weak enough if either aKey or aEffectiveKeyLenBits is weak + TInt minKeySize = Min(aEffectiveKeyLenBits, BytesToBits(aKey.Size())); + TCrypto::IsSymmetricWeakEnoughL(minKeySize); + return self; + } + +CRC2DecryptorShim::CRC2DecryptorShim() + { + } + +CRC2DecryptorShim::~CRC2DecryptorShim() + { + delete iSymmetricCipherImpl; + delete iKey; + delete iAlgorithmParams; + } + + +void CRC2DecryptorShim::ConstructL(const TDesC8& aKey, TInt aEffectiveKeyLenBits) + { + TKeyProperty keyProperty = {KRc2Uid, KNullUid, KSymmetricKeyUid, KNonEmbeddedKeyUid}; + CCryptoParams* keyParam =CCryptoParams::NewLC(); + keyParam->AddL(aKey, KSymmetricKeyParameterUid); + iKey=CKey::NewL(keyProperty, *keyParam); + CleanupStack::PopAndDestroy(keyParam); + + iAlgorithmParams = CCryptoParams::NewL(); + iAlgorithmParams->AddL(aEffectiveKeyLenBits, KRC2EffectiveKeyLenBits); + + CSymmetricCipherFactory::CreateSymmetricCipherL( + iSymmetricCipherImpl, + KRc2Uid, + *iKey, + KCryptoModeDecryptUid, + KOperationModeECBUid, + KPaddingModeNoneUid, + iAlgorithmParams); + } + +TInt CRC2DecryptorShim::BlockSize() const + { + // SPI returns block size in BITS + return BitsToBytes(iSymmetricCipherImpl->BlockSize()); + } + +TInt CRC2DecryptorShim::KeySize() const + { + return iSymmetricCipherImpl->KeySize(); + } + +void CRC2DecryptorShim::Transform(TDes8& aBlock) + { + iOutputBlock.Zero(); + TRAP_IGNORE(iSymmetricCipherImpl->ProcessL(aBlock, iOutputBlock);) + aBlock = iOutputBlock; + } + +void CRC2DecryptorShim::Reset() + { + iSymmetricCipherImpl->Reset(); + } + +TInt CRC2DecryptorShim::Extension_(TUint aExtensionId, TAny*& a0, TAny* /*a1*/) + { + TInt ret(KErrExtensionNotSupported); + + if (CryptoSpi::KSymmetricCipherInterface == aExtensionId && iSymmetricCipherImpl) + { + a0=iSymmetricCipherImpl; + ret=KErrNone; + } + return ret; + } diff -r 7e3f204e6c81 -r f9c11be8c0b3 crypto/weakcryptospi/source/symmetric/rc2shim.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/crypto/weakcryptospi/source/symmetric/rc2shim.h Tue Dec 01 11:12:04 2009 +0000 @@ -0,0 +1,154 @@ +/* +* Copyright (c) 2006-2009 Nokia Corporation and/or its subsidiary(-ies). +* All rights reserved. +* This component and the accompanying materials are made available +* under the terms of the License "Eclipse Public License v1.0" +* which accompanies this distribution, and is available +* at the URL "http://www.eclipse.org/legal/epl-v10.html". +* +* Initial Contributors: +* Nokia Corporation - initial contribution. +* +* Contributors: +* +* Description: +* RC2 shim classes definition +* +*/ + + +/** + @file + @internalComponent + @released +*/ + +#ifndef __RC2SHIM_H__ +#define __RC2SHIM_H__ + +#include + +namespace CryptoSpi + { + class CCryptoParams; + class CSymmetricCipher; + class CKey; + } + +NONSHARABLE_CLASS(CRC2EncryptorShim) : public CRC2Encryptor +{ +public: + /** + Creates an CRC2EncryptorShim object which has the same interface + as RC2 Encryptor but delegates all work to a Crypto SPI plug-in. + + @param aKey The encryption key + @return A pointer to a CRC2EncryptorShim instance + */ + static CRC2EncryptorShim* NewL(const TDesC8& aKey, TInt aEffectiveKeyLenBits); + + /** + Creates an CRC2EncryptorShim object which has the same interface + as RC2 Encryptor but delegates all work to a Crypto SPI plug-in. + + A pointer to the new object is placed on the cleanup stack + + @param aKey The encryption key + @return A pointer to a CRC2EncryptorShim instance + */ + static CRC2EncryptorShim* NewLC(const TDesC8& aKey, TInt aEffectiveKeyLenBits); + + // From CBlockTransform + TInt BlockSize() const; + void Transform(TDes8& aBlock); + void Reset(void); + TInt KeySize(void) const; + + /// Destructor + ~CRC2EncryptorShim(); + +private: + /// Constructor + CRC2EncryptorShim(); + void ConstructL(const TDesC8& aKey, TInt aEffectiveKeyLenBits); + + // From CBase + TInt Extension_(TUint aExtensionId, TAny*& a0, TAny* a1); + +private: + /// SPI delegate + CryptoSpi::CSymmetricCipher* iSymmetricCipherImpl; + + /// SPI requires all key to passed as key-objects + CryptoSpi::CKey* iKey; + + /// Temporary output block, SPI does not overwrite input + /// RC2 uses 64bit blocks + TBuf8<16> iOutputBlock; + + /// The effective key length is passed as an algorithm + /// parameter. This allows it to be externalised. + CryptoSpi::CCryptoParams* iAlgorithmParams; +}; + +NONSHARABLE_CLASS(CRC2DecryptorShim) : public CRC2Decryptor +{ +public: + /** + Creates an CRC2DecryptorShim object which has the same interface + as RC2 Decryptor but delegates all work to a Crypto SPI plug-in. + + @param aKey The decryption key + @return A pointer to a CRC2DecryptorShim instance + */ + static CRC2DecryptorShim* NewL(const TDesC8& aKey, TInt aEffectiveKeyLenBits); + + /** + Creates an CRC2DecryptorShim object which has the same interface + as RC2 Decryptor but delegates all work to a Crypto SPI plug-in. + + A pointer to the new object is placed on the cleanup stack + + @param aKey The decryption key + @return A pointer to a CRC2DecryptorShim instance + */ + static CRC2DecryptorShim* NewLC(const TDesC8& aKey, TInt aEffectiveKeyLenBits); + + // From CBlockTransform + TInt BlockSize() const; + void Transform(TDes8& aBlock); + void Reset(void); + TInt KeySize(void) const; + + /// Destructor + ~CRC2DecryptorShim(); + +private: + /// Constructor + CRC2DecryptorShim(); + void ConstructL(const TDesC8& aKey, TInt aEffectiveKeyLenBits); + + /** + From CBase, to allow CBufferedTransform & CBlockChainingMode + to determine whether the functionality may be delegated to + the SPI object. + */ + TInt Extension_(TUint aExtensionId, TAny*& a0, TAny* a1); + +private: + /// SPI delegate + CryptoSpi::CSymmetricCipher* iSymmetricCipherImpl; + + /// SPI requires all key to passed as key-objects + CryptoSpi::CKey* iKey; + + /// Temporary output block, SPI does not overwrite input + /// RC2 uses 64bit blocks + TBuf8<16> iOutputBlock; + + /// The effective key length is passed as an algorithm + /// parameter. This allows it to be externalised. + CryptoSpi::CCryptoParams* iAlgorithmParams; +}; + +#endif // __RC2SHIM_H__ diff -r 7e3f204e6c81 -r f9c11be8c0b3 crypto/weakcryptospi/source/symmetric/rc2table.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/crypto/weakcryptospi/source/symmetric/rc2table.h Tue Dec 01 11:12:04 2009 +0000 @@ -0,0 +1,53 @@ +/* +* Copyright (c) 2002-2009 Nokia Corporation and/or its subsidiary(-ies). +* All rights reserved. +* This component and the accompanying materials are made available +* under the terms of the License "Eclipse Public License v1.0" +* which accompanies this distribution, and is available +* at the URL "http://www.eclipse.org/legal/epl-v10.html". +* +* Initial Contributors: +* Nokia Corporation - initial contribution. +* +* Contributors: +* +* Description: +* RC2 Table +* +*/ + + +/** + @file + @internalComponent +*/ + +#ifndef __RC2TABLES_H__ +#define __RC2TABLES_H__ + +#include + +namespace RC2_TABLE +{ + const TUint8 PITABLE[256] = + { + 217,120,249,196, 25,221,181,237, 40,233,253,121, 74,160,216,157, + 198,126, 55,131, 43,118, 83,142, 98, 76,100,136, 68,139,251,162, + 23,154, 89,245,135,179, 79, 19, 97, 69,109,141, 9,129,125, 50, + 189,143, 64,235,134,183,123, 11,240,149, 33, 34, 92,107, 78,130, + 84,214,101,147,206, 96,178, 28,115, 86,192, 20,167,140,241,220, + 18,117,202, 31, 59,190,228,209, 66, 61,212, 48,163, 60,182, 38, + 111,191, 14,218, 70,105, 7, 87, 39,242, 29,155,188,148, 67, 3, + 248, 17,199,246,144,239, 62,231, 6,195,213, 47,200,102, 30,215, + 8,232,234,222,128, 82,238,247,132,170,114,172, 53, 77,106, 42, + 150, 26,210,113, 90, 21, 73,116, 75,159,208, 94, 4, 24,164,236, + 194,224, 65,110, 15, 81,203,204, 36,145,175, 80,161,244,112, 57, + 153,124, 58,133, 35,184,180,122,252, 2, 54, 91, 37, 85,151, 49, + 45, 93,250,152,227,138,146,174, 5,223, 41, 16,103,108,186,201, + 211, 0,230,207,225,158,168, 44, 99, 22, 1, 63, 88,226,137,169, + 13, 56, 52, 27,171, 51,255,176,187, 72, 12, 95,185,177,205, 46, + 197,243,219, 71,229,165,156,119, 10,166, 32,104,254,127,193,173 + }; +} + // namespace RC2_TABLE +#endif // __RC2TABLES_H__ diff -r 7e3f204e6c81 -r f9c11be8c0b3 crypto/weakcryptospi/source/symmetric/rijndael.cpp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/crypto/weakcryptospi/source/symmetric/rijndael.cpp Tue Dec 01 11:12:04 2009 +0000 @@ -0,0 +1,225 @@ +/* +* Copyright (c) 2002-2009 Nokia Corporation and/or its subsidiary(-ies). +* All rights reserved. +* This component and the accompanying materials are made available +* under the terms of the License "Eclipse Public License v1.0" +* which accompanies this distribution, and is available +* at the URL "http://www.eclipse.org/legal/epl-v10.html". +* +* Initial Contributors: +* Nokia Corporation - initial contribution. +* +* Contributors: +* +* Description: +* +*/ + + +#include "rijndael.h" +#include "rijndaelshim.h" +#include "rijndaeltables.h" +#include "../common/inlines.h" +#include + +const TUint KAESKeyBytes128 = 16; +const TUint KAESKeyBytes192 = 24; +const TUint KAESKeyBytes256 = 32; +const TUint KAESBlockBytes = 16; + +/* CRijndael */ +EXPORT_C CRijndael::CRijndael(void) + { + } + +void CRijndael::Reset() + { + // CRijndael is externally derivable. Don't delete this code + SetKey(*iKey); + } + +TInt CRijndael::KeySize() const + { + // CRijndael is externally derivable. Don't delete this code + return (4*(iRounds+1)); + } + +EXPORT_C CRijndael::~CRijndael() + { + // CRijndael is externally derivable. Don't delete this code + delete iKey; + } + +void CRijndael::ConstructL(const TDesC8& aKey) + { + // CRijndael is externally derivable. Don't delete this code + TUint keySize = aKey.Size(); + assert((keySize==KAESKeyBytes128)||(keySize==KAESKeyBytes192)||(keySize==KAESKeyBytes256)); + iKey = aKey.AllocL(); + iRounds = keySize/4 + 6; + SetKey(aKey); + } + +void CRijndael::SetKey(const TDesC8& aKey) + { + // CRijndael is externally derivable. Don't delete this code + TUint keySize = aKey.Size(); + TUint32 temp; + TUint32* rk = &iK[0]; + + TUint i = 0; + + GetUserKeyBigEndian(rk, keySize/4, &aKey[0], keySize); + + switch(keySize) + { + case (KAESKeyBytes128): + { + FOREVER + { + temp = rk[3]; + rk[4] = rk[0] ^ + (RIJNDAEL_TABLE::Te4[GETBYTE(temp, 2)] & 0xff000000) ^ + (RIJNDAEL_TABLE::Te4[GETBYTE(temp, 1)] & 0x00ff0000) ^ + (RIJNDAEL_TABLE::Te4[GETBYTE(temp, 0)] & 0x0000ff00) ^ + (RIJNDAEL_TABLE::Te4[GETBYTE(temp, 3)] & 0x000000ff) ^ + RIJNDAEL_TABLE::rcon[i]; + rk[5] = rk[1] ^ rk[4]; + rk[6] = rk[2] ^ rk[5]; + rk[7] = rk[3] ^ rk[6]; + if (++i == 10) + break; + rk += 4; + } + } + break; + + case (KAESKeyBytes192): + { + FOREVER + { + temp = rk[ 5]; + rk[ 6] = rk[ 0] ^ + (RIJNDAEL_TABLE::Te4[GETBYTE(temp, 2)] & 0xff000000) ^ + (RIJNDAEL_TABLE::Te4[GETBYTE(temp, 1)] & 0x00ff0000) ^ + (RIJNDAEL_TABLE::Te4[GETBYTE(temp, 0)] & 0x0000ff00) ^ + (RIJNDAEL_TABLE::Te4[GETBYTE(temp, 3)] & 0x000000ff) ^ + RIJNDAEL_TABLE::rcon[i]; + rk[ 7] = rk[ 1] ^ rk[ 6]; + rk[ 8] = rk[ 2] ^ rk[ 7]; + rk[ 9] = rk[ 3] ^ rk[ 8]; + if (++i == 8) + break; + rk[10] = rk[ 4] ^ rk[ 9]; + rk[11] = rk[ 5] ^ rk[10]; + rk += 6; + } + } + break; + + case (KAESKeyBytes256): + { + FOREVER + { + temp = rk[ 7]; + rk[ 8] = rk[ 0] ^ + (RIJNDAEL_TABLE::Te4[GETBYTE(temp, 2)] & 0xff000000) ^ + (RIJNDAEL_TABLE::Te4[GETBYTE(temp, 1)] & 0x00ff0000) ^ + (RIJNDAEL_TABLE::Te4[GETBYTE(temp, 0)] & 0x0000ff00) ^ + (RIJNDAEL_TABLE::Te4[GETBYTE(temp, 3)] & 0x000000ff) ^ + RIJNDAEL_TABLE::rcon[i]; + rk[ 9] = rk[ 1] ^ rk[ 8]; + rk[10] = rk[ 2] ^ rk[ 9]; + rk[11] = rk[ 3] ^ rk[10]; + if (++i == 7) + break; + temp = rk[11]; + rk[12] = rk[ 4] ^ + (RIJNDAEL_TABLE::Te4[GETBYTE(temp, 3)] & 0xff000000) ^ + (RIJNDAEL_TABLE::Te4[GETBYTE(temp, 2)] & 0x00ff0000) ^ + (RIJNDAEL_TABLE::Te4[GETBYTE(temp, 1)] & 0x0000ff00) ^ + (RIJNDAEL_TABLE::Te4[GETBYTE(temp, 0)] & 0x000000ff); + rk[13] = rk[ 5] ^ rk[12]; + rk[14] = rk[ 6] ^ rk[13]; + rk[15] = rk[ 7] ^ rk[14]; + + rk += 8; + } + } + break; + + default: + assert(0); // Shouldn't get here, keeps compiler happy + } + } + + +/* CAESEncryptor */ +EXPORT_C CAESEncryptor* CAESEncryptor::NewL(const TDesC8& aKey) + { + return CAESEncryptorShim::NewL(aKey); + } + +EXPORT_C CAESEncryptor* CAESEncryptor::NewLC(const TDesC8& aKey) + { + return CAESEncryptorShim::NewLC(aKey); + } + +CAESEncryptor::CAESEncryptor() + { + } + +/* CAESDecryptor */ +EXPORT_C CAESDecryptor* CAESDecryptor::NewL(const TDesC8& aKey) + { + return CAESDecryptorShim::NewL(aKey); + } + +EXPORT_C CAESDecryptor* CAESDecryptor::NewLC(const TDesC8& aKey) + { + return CAESDecryptorShim::NewLC(aKey); + } + +CAESDecryptor::CAESDecryptor() + { + } + +// All these methods have been replaced by the shim +#ifdef _BullseyeCoverage +#pragma suppress_warnings on +#pragma BullseyeCoverage off +#pragma suppress_warnings off +#endif + +TInt CAESDecryptor::BlockSize() const + { + // Method replaced by shim + ASSERT(EFalse); + return 0; + } + +void CAESDecryptor::Transform(TDes8& /*aBlock*/) + { + // Method replaced by shim + ASSERT(EFalse); + } + +void CAESDecryptor::SetKey(const TDesC8& /*aKey*/) + { + // Method replaced by shim + ASSERT(EFalse); + } + +TInt CAESEncryptor::BlockSize() const + { + // Method replaced by shim + ASSERT(EFalse); + return KAESBlockBytes; + } + +void CAESEncryptor::Transform(TDes8& /*aBlock*/) + { + // Method replaced by shim + ASSERT(EFalse); + } + diff -r 7e3f204e6c81 -r f9c11be8c0b3 crypto/weakcryptospi/source/symmetric/rijndaelshim.cpp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/crypto/weakcryptospi/source/symmetric/rijndaelshim.cpp Tue Dec 01 11:12:04 2009 +0000 @@ -0,0 +1,187 @@ +/* +* Copyright (c) 2006-2009 Nokia Corporation and/or its subsidiary(-ies). +* All rights reserved. +* This component and the accompanying materials are made available +* under the terms of the License "Eclipse Public License v1.0" +* which accompanies this distribution, and is available +* at the URL "http://www.eclipse.org/legal/epl-v10.html". +* +* Initial Contributors: +* Nokia Corporation - initial contribution. +* +* Contributors: +* +* Description: +* +*/ + + +#include "rijndaelshim.h" + +#include "cryptosymmetriccipherapi.h" +#include +#include +#include "keys.h" +#include + +#include "../common/inlines.h" + +using namespace CryptoSpi; + +// CAESEncryptorShim //////////////////////////////////////////////////////// +CAESEncryptorShim* CAESEncryptorShim::NewL(const TDesC8& aKey) + { + CAESEncryptorShim* self = CAESEncryptorShim::NewLC(aKey); + CleanupStack::Pop(self); + return self; + } + +CAESEncryptorShim* CAESEncryptorShim::NewLC(const TDesC8& aKey) + { + CAESEncryptorShim* self = new (ELeave) CAESEncryptorShim(); + CleanupStack::PushL(self); + self->ConstructL(aKey); + TCrypto::IsSymmetricWeakEnoughL(BytesToBits(aKey.Size())); + return self; + } + +CAESEncryptorShim::CAESEncryptorShim() + { + } + +CAESEncryptorShim::~CAESEncryptorShim() + { + delete iSymmetricCipherImpl; + delete iKey; + } + +void CAESEncryptorShim::ConstructL(const TDesC8& aKey) + { + TKeyProperty keyProperty = {KAesUid, KNullUid, KSymmetricKeyUid, KNonEmbeddedKeyUid}; + CCryptoParams* keyParam =CCryptoParams::NewLC(); + keyParam->AddL(aKey, KSymmetricKeyParameterUid); + iKey=CKey::NewL(keyProperty, *keyParam); + CleanupStack::PopAndDestroy(keyParam); + CSymmetricCipherFactory::CreateSymmetricCipherL( + iSymmetricCipherImpl, + KAesUid, + *iKey, + KCryptoModeEncryptUid, + KOperationModeECBUid, + KPaddingModeNoneUid, + NULL); + } + +TInt CAESEncryptorShim::BlockSize() const + { + return BitsToBytes(iSymmetricCipherImpl->BlockSize()); + } + +TInt CAESEncryptorShim::KeySize() const + { + return iSymmetricCipherImpl->KeySize(); + } + +void CAESEncryptorShim::Transform(TDes8& aBlock) + { + iOutputBlock.Zero(); + TRAP_IGNORE(iSymmetricCipherImpl->ProcessL(aBlock, iOutputBlock);) + aBlock = iOutputBlock; + } + +void CAESEncryptorShim::Reset() + { + iSymmetricCipherImpl->Reset(); + } + +TInt CAESEncryptorShim::Extension_(TUint aExtensionId, TAny*& a0, TAny* /*a1*/) + { + TInt ret(KErrExtensionNotSupported); + + if (CryptoSpi::KSymmetricCipherInterface == aExtensionId && iSymmetricCipherImpl) + { + a0=iSymmetricCipherImpl; + ret=KErrNone; + } + return ret; + } + +// CAESDecryptorShim //////////////////////////////////////////////////////// + +CAESDecryptorShim* CAESDecryptorShim::NewL(const TDesC8& aKey) + { + CAESDecryptorShim* self = CAESDecryptorShim::NewLC(aKey); + CleanupStack::Pop(self); + return self; + } + + +CAESDecryptorShim* CAESDecryptorShim::NewLC(const TDesC8& aKey) + { + CAESDecryptorShim* self = new (ELeave) CAESDecryptorShim(); + CleanupStack::PushL(self); + self->ConstructL(aKey); + TCrypto::IsSymmetricWeakEnoughL(BytesToBits(aKey.Size())); + return self; + } + +CAESDecryptorShim::CAESDecryptorShim() + { + } + +CAESDecryptorShim::~CAESDecryptorShim() + { + delete iSymmetricCipherImpl; + delete iKey; + } + +void CAESDecryptorShim::ConstructL(const TDesC8& aKey) + { + TKeyProperty keyProperty = {KAesUid, KNullUid, KSymmetricKeyUid, KNonEmbeddedKeyUid}; + CCryptoParams* keyParam =CCryptoParams::NewLC(); + keyParam->AddL(aKey, KSymmetricKeyParameterUid); + iKey=CKey::NewL(keyProperty, *keyParam); + CleanupStack::PopAndDestroy(keyParam); + CSymmetricCipherFactory::CreateSymmetricCipherL( + iSymmetricCipherImpl, + KAesUid, + *iKey, + KCryptoModeDecryptUid, + KOperationModeECBUid, + KPaddingModeNoneUid, + NULL); + } + +TInt CAESDecryptorShim::BlockSize() const + { + return BitsToBytes(iSymmetricCipherImpl->BlockSize()); + } + +TInt CAESDecryptorShim::KeySize() const + { + return iSymmetricCipherImpl->KeySize(); + } + +void CAESDecryptorShim::Transform(TDes8& aBlock) + { + iOutputBlock.Zero(); + TRAP_IGNORE(iSymmetricCipherImpl->ProcessL(aBlock, iOutputBlock);) + aBlock = iOutputBlock; + } + +void CAESDecryptorShim::Reset() + { + iSymmetricCipherImpl->Reset(); + } + +TInt CAESDecryptorShim::Extension_(TUint aExtensionId, TAny*& a0, TAny* /*a1*/) + { + TInt ret(KErrExtensionNotSupported); + + if (CryptoSpi::KSymmetricCipherInterface == aExtensionId && iSymmetricCipherImpl) + { + a0=iSymmetricCipherImpl; + ret=KErrNone; + } + return ret; + } diff -r 7e3f204e6c81 -r f9c11be8c0b3 crypto/weakcryptospi/source/symmetric/rijndaelshim.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/crypto/weakcryptospi/source/symmetric/rijndaelshim.h Tue Dec 01 11:12:04 2009 +0000 @@ -0,0 +1,145 @@ +/* +* Copyright (c) 2006-2009 Nokia Corporation and/or its subsidiary(-ies). +* All rights reserved. +* This component and the accompanying materials are made available +* under the terms of the License "Eclipse Public License v1.0" +* which accompanies this distribution, and is available +* at the URL "http://www.eclipse.org/legal/epl-v10.html". +* +* Initial Contributors: +* Nokia Corporation - initial contribution. +* +* Contributors: +* +* Description: +* rijndael shim classes definition +* +*/ + + +/** + @file + @internalComponent + @released +*/ + +#ifndef __RIJNDAELSHIM_H__ +#define __RIJNDAELSHIM_H__ + +#include + +namespace CryptoSpi + { + class CSymmetricCipher; + class CKey; + } + +NONSHARABLE_CLASS(CAESEncryptorShim) : public CAESEncryptor +{ +public: + /** + Creates an CAESEncryptorShim object which has the same interface + as AESEncryptor but delegates all work to a Crypto SPI plug-in. + + @param aKey The encryption key + @return A pointer to a CAESEncryptorShim instance + */ + static CAESEncryptorShim* NewL(const TDesC8& aKey); + + /** + Creates an CAESEncryptorShim object which has the same interface + as AESEncryptor but delegates all work to a Crypto SPI plug-in. + + A pointer to the new object is placed on the cleanup stack + + @param aKey The encryption key + @return A pointer to a CAESEncryptorShim instance + */ + static CAESEncryptorShim* NewLC(const TDesC8& aKey); + + // From CBlockTransform + TInt BlockSize() const; + void Transform(TDes8& aBlock); + void Reset(void); + TInt KeySize(void) const; + + /// Destructor + ~CAESEncryptorShim(); + +private: + /// Constructor + CAESEncryptorShim(); + void ConstructL(const TDesC8& aKey); + + // From CBase + TInt Extension_(TUint aExtensionId, TAny*& a0, TAny* a1); + +private: + /// SPI delegate + CryptoSpi::CSymmetricCipher* iSymmetricCipherImpl; + + /// SPI requires all key to passed as key-objects + CryptoSpi::CKey* iKey; + + /// Temporary output block, SPI does not overwrite input + /// AES uses 64bit blocks + TBuf8<16> iOutputBlock; +}; + +NONSHARABLE_CLASS(CAESDecryptorShim) : public CAESDecryptor +{ +public: + /** + Creates an CAESDecryptorShim object which has the same interface + as AESDecryptor but delegates all work to a Crypto SPI plug-in. + + @param aKey The decryption key + @return A pointer to a CAESDecryptorShim instance + */ + static CAESDecryptorShim* NewL(const TDesC8& aKey); + + /** + Creates an CAESDecryptorShim object which has the same interface + as AESDecryptor but delegates all work to a Crypto SPI plug-in. + + A pointer to the new object is placed on the cleanup stack + + @param aKey The decryption key + @return A pointer to a CAESDecryptorShim instance + */ + static CAESDecryptorShim* NewLC(const TDesC8& aKey); + + // From CBlockTransform + TInt BlockSize() const; + void Transform(TDes8& aBlock); + void Reset(void); + TInt KeySize(void) const; + + /// Destructor + ~CAESDecryptorShim(); + +private: + /// Constructor + CAESDecryptorShim(); + void ConstructL(const TDesC8& aKey); + + /** + From CBase, to allow CBufferedTransform & CBlockChainingMode + to determine whether the functionality may be delegated to + the SPI object. + */ + TInt Extension_(TUint aExtensionId, TAny*& a0, TAny* a1); + +private: + /// SPI delegate + CryptoSpi::CSymmetricCipher* iSymmetricCipherImpl; + + /// SPI requires all key to passed as key-objects + CryptoSpi::CKey* iKey; + + /// Temporary output block, SPI does not overwrite input + /// AES uses 64bit blocks + TBuf8<16> iOutputBlock; +}; + +#endif // __RIJNDAELSHIM_H__ diff -r 7e3f204e6c81 -r f9c11be8c0b3 crypto/weakcryptospi/source/symmetric/rijndaeltables.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/crypto/weakcryptospi/source/symmetric/rijndaeltables.h Tue Dec 01 11:12:04 2009 +0000 @@ -0,0 +1,723 @@ +/* +* Copyright (c) 2002-2009 Nokia Corporation and/or its subsidiary(-ies). +* All rights reserved. +* This component and the accompanying materials are made available +* under the terms of the License "Eclipse Public License v1.0" +* which accompanies this distribution, and is available +* at the URL "http://www.eclipse.org/legal/epl-v10.html". +* +* Initial Contributors: +* Nokia Corporation - initial contribution. +* +* Contributors: +* +* Description: +* Rijndael Tables +* +*/ + + +/** + @file + @internalComponent +*/ + +#ifndef __RIJNDAELTABLES_H__ +#define __RIJNDAELTABLES_H__ + +#include + +namespace RIJNDAEL_TABLE +{ + +/* +Te0[x] = S [x].[02, 01, 01, 03]; +Te1[x] = S [x].[03, 02, 01, 01]; +Te2[x] = S [x].[01, 03, 02, 01]; +Te3[x] = S [x].[01, 01, 03, 02]; +Te4[x] = S [x].[01, 01, 01, 01]; + +Td0[x] = Si[x].[0e, 09, 0d, 0b]; +Td1[x] = Si[x].[0b, 0e, 09, 0d]; +Td2[x] = Si[x].[0d, 0b, 0e, 09]; +Td3[x] = Si[x].[09, 0d, 0b, 0e]; +Td4[x] = Si[x].[01, 01, 01, 01]; +*/ + +const TUint32 Te0[256] = { + 0xc66363a5U, 0xf87c7c84U, 0xee777799U, 0xf67b7b8dU, + 0xfff2f20dU, 0xd66b6bbdU, 0xde6f6fb1U, 0x91c5c554U, + 0x60303050U, 0x02010103U, 0xce6767a9U, 0x562b2b7dU, + 0xe7fefe19U, 0xb5d7d762U, 0x4dababe6U, 0xec76769aU, + 0x8fcaca45U, 0x1f82829dU, 0x89c9c940U, 0xfa7d7d87U, + 0xeffafa15U, 0xb25959ebU, 0x8e4747c9U, 0xfbf0f00bU, + 0x41adadecU, 0xb3d4d467U, 0x5fa2a2fdU, 0x45afafeaU, + 0x239c9cbfU, 0x53a4a4f7U, 0xe4727296U, 0x9bc0c05bU, + 0x75b7b7c2U, 0xe1fdfd1cU, 0x3d9393aeU, 0x4c26266aU, + 0x6c36365aU, 0x7e3f3f41U, 0xf5f7f702U, 0x83cccc4fU, + 0x6834345cU, 0x51a5a5f4U, 0xd1e5e534U, 0xf9f1f108U, + 0xe2717193U, 0xabd8d873U, 0x62313153U, 0x2a15153fU, + 0x0804040cU, 0x95c7c752U, 0x46232365U, 0x9dc3c35eU, + 0x30181828U, 0x379696a1U, 0x0a05050fU, 0x2f9a9ab5U, + 0x0e070709U, 0x24121236U, 0x1b80809bU, 0xdfe2e23dU, + 0xcdebeb26U, 0x4e272769U, 0x7fb2b2cdU, 0xea75759fU, + 0x1209091bU, 0x1d83839eU, 0x582c2c74U, 0x341a1a2eU, + 0x361b1b2dU, 0xdc6e6eb2U, 0xb45a5aeeU, 0x5ba0a0fbU, + 0xa45252f6U, 0x763b3b4dU, 0xb7d6d661U, 0x7db3b3ceU, + 0x5229297bU, 0xdde3e33eU, 0x5e2f2f71U, 0x13848497U, + 0xa65353f5U, 0xb9d1d168U, 0x00000000U, 0xc1eded2cU, + 0x40202060U, 0xe3fcfc1fU, 0x79b1b1c8U, 0xb65b5bedU, + 0xd46a6abeU, 0x8dcbcb46U, 0x67bebed9U, 0x7239394bU, + 0x944a4adeU, 0x984c4cd4U, 0xb05858e8U, 0x85cfcf4aU, + 0xbbd0d06bU, 0xc5efef2aU, 0x4faaaae5U, 0xedfbfb16U, + 0x864343c5U, 0x9a4d4dd7U, 0x66333355U, 0x11858594U, + 0x8a4545cfU, 0xe9f9f910U, 0x04020206U, 0xfe7f7f81U, + 0xa05050f0U, 0x783c3c44U, 0x259f9fbaU, 0x4ba8a8e3U, + 0xa25151f3U, 0x5da3a3feU, 0x804040c0U, 0x058f8f8aU, + 0x3f9292adU, 0x219d9dbcU, 0x70383848U, 0xf1f5f504U, + 0x63bcbcdfU, 0x77b6b6c1U, 0xafdada75U, 0x42212163U, + 0x20101030U, 0xe5ffff1aU, 0xfdf3f30eU, 0xbfd2d26dU, + 0x81cdcd4cU, 0x180c0c14U, 0x26131335U, 0xc3ecec2fU, + 0xbe5f5fe1U, 0x359797a2U, 0x884444ccU, 0x2e171739U, + 0x93c4c457U, 0x55a7a7f2U, 0xfc7e7e82U, 0x7a3d3d47U, + 0xc86464acU, 0xba5d5de7U, 0x3219192bU, 0xe6737395U, + 0xc06060a0U, 0x19818198U, 0x9e4f4fd1U, 0xa3dcdc7fU, + 0x44222266U, 0x542a2a7eU, 0x3b9090abU, 0x0b888883U, + 0x8c4646caU, 0xc7eeee29U, 0x6bb8b8d3U, 0x2814143cU, + 0xa7dede79U, 0xbc5e5ee2U, 0x160b0b1dU, 0xaddbdb76U, + 0xdbe0e03bU, 0x64323256U, 0x743a3a4eU, 0x140a0a1eU, + 0x924949dbU, 0x0c06060aU, 0x4824246cU, 0xb85c5ce4U, + 0x9fc2c25dU, 0xbdd3d36eU, 0x43acacefU, 0xc46262a6U, + 0x399191a8U, 0x319595a4U, 0xd3e4e437U, 0xf279798bU, + 0xd5e7e732U, 0x8bc8c843U, 0x6e373759U, 0xda6d6db7U, + 0x018d8d8cU, 0xb1d5d564U, 0x9c4e4ed2U, 0x49a9a9e0U, + 0xd86c6cb4U, 0xac5656faU, 0xf3f4f407U, 0xcfeaea25U, + 0xca6565afU, 0xf47a7a8eU, 0x47aeaee9U, 0x10080818U, + 0x6fbabad5U, 0xf0787888U, 0x4a25256fU, 0x5c2e2e72U, + 0x381c1c24U, 0x57a6a6f1U, 0x73b4b4c7U, 0x97c6c651U, + 0xcbe8e823U, 0xa1dddd7cU, 0xe874749cU, 0x3e1f1f21U, + 0x964b4bddU, 0x61bdbddcU, 0x0d8b8b86U, 0x0f8a8a85U, + 0xe0707090U, 0x7c3e3e42U, 0x71b5b5c4U, 0xcc6666aaU, + 0x904848d8U, 0x06030305U, 0xf7f6f601U, 0x1c0e0e12U, + 0xc26161a3U, 0x6a35355fU, 0xae5757f9U, 0x69b9b9d0U, + 0x17868691U, 0x99c1c158U, 0x3a1d1d27U, 0x279e9eb9U, + 0xd9e1e138U, 0xebf8f813U, 0x2b9898b3U, 0x22111133U, + 0xd26969bbU, 0xa9d9d970U, 0x078e8e89U, 0x339494a7U, + 0x2d9b9bb6U, 0x3c1e1e22U, 0x15878792U, 0xc9e9e920U, + 0x87cece49U, 0xaa5555ffU, 0x50282878U, 0xa5dfdf7aU, + 0x038c8c8fU, 0x59a1a1f8U, 0x09898980U, 0x1a0d0d17U, + 0x65bfbfdaU, 0xd7e6e631U, 0x844242c6U, 0xd06868b8U, + 0x824141c3U, 0x299999b0U, 0x5a2d2d77U, 0x1e0f0f11U, + 0x7bb0b0cbU, 0xa85454fcU, 0x6dbbbbd6U, 0x2c16163aU, +}; +const TUint32 Te1[256] = { + 0xa5c66363U, 0x84f87c7cU, 0x99ee7777U, 0x8df67b7bU, + 0x0dfff2f2U, 0xbdd66b6bU, 0xb1de6f6fU, 0x5491c5c5U, + 0x50603030U, 0x03020101U, 0xa9ce6767U, 0x7d562b2bU, + 0x19e7fefeU, 0x62b5d7d7U, 0xe64dababU, 0x9aec7676U, + 0x458fcacaU, 0x9d1f8282U, 0x4089c9c9U, 0x87fa7d7dU, + 0x15effafaU, 0xebb25959U, 0xc98e4747U, 0x0bfbf0f0U, + 0xec41adadU, 0x67b3d4d4U, 0xfd5fa2a2U, 0xea45afafU, + 0xbf239c9cU, 0xf753a4a4U, 0x96e47272U, 0x5b9bc0c0U, + 0xc275b7b7U, 0x1ce1fdfdU, 0xae3d9393U, 0x6a4c2626U, + 0x5a6c3636U, 0x417e3f3fU, 0x02f5f7f7U, 0x4f83ccccU, + 0x5c683434U, 0xf451a5a5U, 0x34d1e5e5U, 0x08f9f1f1U, + 0x93e27171U, 0x73abd8d8U, 0x53623131U, 0x3f2a1515U, + 0x0c080404U, 0x5295c7c7U, 0x65462323U, 0x5e9dc3c3U, + 0x28301818U, 0xa1379696U, 0x0f0a0505U, 0xb52f9a9aU, + 0x090e0707U, 0x36241212U, 0x9b1b8080U, 0x3ddfe2e2U, + 0x26cdebebU, 0x694e2727U, 0xcd7fb2b2U, 0x9fea7575U, + 0x1b120909U, 0x9e1d8383U, 0x74582c2cU, 0x2e341a1aU, + 0x2d361b1bU, 0xb2dc6e6eU, 0xeeb45a5aU, 0xfb5ba0a0U, + 0xf6a45252U, 0x4d763b3bU, 0x61b7d6d6U, 0xce7db3b3U, + 0x7b522929U, 0x3edde3e3U, 0x715e2f2fU, 0x97138484U, + 0xf5a65353U, 0x68b9d1d1U, 0x00000000U, 0x2cc1ededU, + 0x60402020U, 0x1fe3fcfcU, 0xc879b1b1U, 0xedb65b5bU, + 0xbed46a6aU, 0x468dcbcbU, 0xd967bebeU, 0x4b723939U, + 0xde944a4aU, 0xd4984c4cU, 0xe8b05858U, 0x4a85cfcfU, + 0x6bbbd0d0U, 0x2ac5efefU, 0xe54faaaaU, 0x16edfbfbU, + 0xc5864343U, 0xd79a4d4dU, 0x55663333U, 0x94118585U, + 0xcf8a4545U, 0x10e9f9f9U, 0x06040202U, 0x81fe7f7fU, + 0xf0a05050U, 0x44783c3cU, 0xba259f9fU, 0xe34ba8a8U, + 0xf3a25151U, 0xfe5da3a3U, 0xc0804040U, 0x8a058f8fU, + 0xad3f9292U, 0xbc219d9dU, 0x48703838U, 0x04f1f5f5U, + 0xdf63bcbcU, 0xc177b6b6U, 0x75afdadaU, 0x63422121U, + 0x30201010U, 0x1ae5ffffU, 0x0efdf3f3U, 0x6dbfd2d2U, + 0x4c81cdcdU, 0x14180c0cU, 0x35261313U, 0x2fc3ececU, + 0xe1be5f5fU, 0xa2359797U, 0xcc884444U, 0x392e1717U, + 0x5793c4c4U, 0xf255a7a7U, 0x82fc7e7eU, 0x477a3d3dU, + 0xacc86464U, 0xe7ba5d5dU, 0x2b321919U, 0x95e67373U, + 0xa0c06060U, 0x98198181U, 0xd19e4f4fU, 0x7fa3dcdcU, + 0x66442222U, 0x7e542a2aU, 0xab3b9090U, 0x830b8888U, + 0xca8c4646U, 0x29c7eeeeU, 0xd36bb8b8U, 0x3c281414U, + 0x79a7dedeU, 0xe2bc5e5eU, 0x1d160b0bU, 0x76addbdbU, + 0x3bdbe0e0U, 0x56643232U, 0x4e743a3aU, 0x1e140a0aU, + 0xdb924949U, 0x0a0c0606U, 0x6c482424U, 0xe4b85c5cU, + 0x5d9fc2c2U, 0x6ebdd3d3U, 0xef43acacU, 0xa6c46262U, + 0xa8399191U, 0xa4319595U, 0x37d3e4e4U, 0x8bf27979U, + 0x32d5e7e7U, 0x438bc8c8U, 0x596e3737U, 0xb7da6d6dU, + 0x8c018d8dU, 0x64b1d5d5U, 0xd29c4e4eU, 0xe049a9a9U, + 0xb4d86c6cU, 0xfaac5656U, 0x07f3f4f4U, 0x25cfeaeaU, + 0xafca6565U, 0x8ef47a7aU, 0xe947aeaeU, 0x18100808U, + 0xd56fbabaU, 0x88f07878U, 0x6f4a2525U, 0x725c2e2eU, + 0x24381c1cU, 0xf157a6a6U, 0xc773b4b4U, 0x5197c6c6U, + 0x23cbe8e8U, 0x7ca1ddddU, 0x9ce87474U, 0x213e1f1fU, + 0xdd964b4bU, 0xdc61bdbdU, 0x860d8b8bU, 0x850f8a8aU, + 0x90e07070U, 0x427c3e3eU, 0xc471b5b5U, 0xaacc6666U, + 0xd8904848U, 0x05060303U, 0x01f7f6f6U, 0x121c0e0eU, + 0xa3c26161U, 0x5f6a3535U, 0xf9ae5757U, 0xd069b9b9U, + 0x91178686U, 0x5899c1c1U, 0x273a1d1dU, 0xb9279e9eU, + 0x38d9e1e1U, 0x13ebf8f8U, 0xb32b9898U, 0x33221111U, + 0xbbd26969U, 0x70a9d9d9U, 0x89078e8eU, 0xa7339494U, + 0xb62d9b9bU, 0x223c1e1eU, 0x92158787U, 0x20c9e9e9U, + 0x4987ceceU, 0xffaa5555U, 0x78502828U, 0x7aa5dfdfU, + 0x8f038c8cU, 0xf859a1a1U, 0x80098989U, 0x171a0d0dU, + 0xda65bfbfU, 0x31d7e6e6U, 0xc6844242U, 0xb8d06868U, + 0xc3824141U, 0xb0299999U, 0x775a2d2dU, 0x111e0f0fU, + 0xcb7bb0b0U, 0xfca85454U, 0xd66dbbbbU, 0x3a2c1616U, +}; +const TUint32 Te2[256] = { + 0x63a5c663U, 0x7c84f87cU, 0x7799ee77U, 0x7b8df67bU, + 0xf20dfff2U, 0x6bbdd66bU, 0x6fb1de6fU, 0xc55491c5U, + 0x30506030U, 0x01030201U, 0x67a9ce67U, 0x2b7d562bU, + 0xfe19e7feU, 0xd762b5d7U, 0xabe64dabU, 0x769aec76U, + 0xca458fcaU, 0x829d1f82U, 0xc94089c9U, 0x7d87fa7dU, + 0xfa15effaU, 0x59ebb259U, 0x47c98e47U, 0xf00bfbf0U, + 0xadec41adU, 0xd467b3d4U, 0xa2fd5fa2U, 0xafea45afU, + 0x9cbf239cU, 0xa4f753a4U, 0x7296e472U, 0xc05b9bc0U, + 0xb7c275b7U, 0xfd1ce1fdU, 0x93ae3d93U, 0x266a4c26U, + 0x365a6c36U, 0x3f417e3fU, 0xf702f5f7U, 0xcc4f83ccU, + 0x345c6834U, 0xa5f451a5U, 0xe534d1e5U, 0xf108f9f1U, + 0x7193e271U, 0xd873abd8U, 0x31536231U, 0x153f2a15U, + 0x040c0804U, 0xc75295c7U, 0x23654623U, 0xc35e9dc3U, + 0x18283018U, 0x96a13796U, 0x050f0a05U, 0x9ab52f9aU, + 0x07090e07U, 0x12362412U, 0x809b1b80U, 0xe23ddfe2U, + 0xeb26cdebU, 0x27694e27U, 0xb2cd7fb2U, 0x759fea75U, + 0x091b1209U, 0x839e1d83U, 0x2c74582cU, 0x1a2e341aU, + 0x1b2d361bU, 0x6eb2dc6eU, 0x5aeeb45aU, 0xa0fb5ba0U, + 0x52f6a452U, 0x3b4d763bU, 0xd661b7d6U, 0xb3ce7db3U, + 0x297b5229U, 0xe33edde3U, 0x2f715e2fU, 0x84971384U, + 0x53f5a653U, 0xd168b9d1U, 0x00000000U, 0xed2cc1edU, + 0x20604020U, 0xfc1fe3fcU, 0xb1c879b1U, 0x5bedb65bU, + 0x6abed46aU, 0xcb468dcbU, 0xbed967beU, 0x394b7239U, + 0x4ade944aU, 0x4cd4984cU, 0x58e8b058U, 0xcf4a85cfU, + 0xd06bbbd0U, 0xef2ac5efU, 0xaae54faaU, 0xfb16edfbU, + 0x43c58643U, 0x4dd79a4dU, 0x33556633U, 0x85941185U, + 0x45cf8a45U, 0xf910e9f9U, 0x02060402U, 0x7f81fe7fU, + 0x50f0a050U, 0x3c44783cU, 0x9fba259fU, 0xa8e34ba8U, + 0x51f3a251U, 0xa3fe5da3U, 0x40c08040U, 0x8f8a058fU, + 0x92ad3f92U, 0x9dbc219dU, 0x38487038U, 0xf504f1f5U, + 0xbcdf63bcU, 0xb6c177b6U, 0xda75afdaU, 0x21634221U, + 0x10302010U, 0xff1ae5ffU, 0xf30efdf3U, 0xd26dbfd2U, + 0xcd4c81cdU, 0x0c14180cU, 0x13352613U, 0xec2fc3ecU, + 0x5fe1be5fU, 0x97a23597U, 0x44cc8844U, 0x17392e17U, + 0xc45793c4U, 0xa7f255a7U, 0x7e82fc7eU, 0x3d477a3dU, + 0x64acc864U, 0x5de7ba5dU, 0x192b3219U, 0x7395e673U, + 0x60a0c060U, 0x81981981U, 0x4fd19e4fU, 0xdc7fa3dcU, + 0x22664422U, 0x2a7e542aU, 0x90ab3b90U, 0x88830b88U, + 0x46ca8c46U, 0xee29c7eeU, 0xb8d36bb8U, 0x143c2814U, + 0xde79a7deU, 0x5ee2bc5eU, 0x0b1d160bU, 0xdb76addbU, + 0xe03bdbe0U, 0x32566432U, 0x3a4e743aU, 0x0a1e140aU, + 0x49db9249U, 0x060a0c06U, 0x246c4824U, 0x5ce4b85cU, + 0xc25d9fc2U, 0xd36ebdd3U, 0xacef43acU, 0x62a6c462U, + 0x91a83991U, 0x95a43195U, 0xe437d3e4U, 0x798bf279U, + 0xe732d5e7U, 0xc8438bc8U, 0x37596e37U, 0x6db7da6dU, + 0x8d8c018dU, 0xd564b1d5U, 0x4ed29c4eU, 0xa9e049a9U, + 0x6cb4d86cU, 0x56faac56U, 0xf407f3f4U, 0xea25cfeaU, + 0x65afca65U, 0x7a8ef47aU, 0xaee947aeU, 0x08181008U, + 0xbad56fbaU, 0x7888f078U, 0x256f4a25U, 0x2e725c2eU, + 0x1c24381cU, 0xa6f157a6U, 0xb4c773b4U, 0xc65197c6U, + 0xe823cbe8U, 0xdd7ca1ddU, 0x749ce874U, 0x1f213e1fU, + 0x4bdd964bU, 0xbddc61bdU, 0x8b860d8bU, 0x8a850f8aU, + 0x7090e070U, 0x3e427c3eU, 0xb5c471b5U, 0x66aacc66U, + 0x48d89048U, 0x03050603U, 0xf601f7f6U, 0x0e121c0eU, + 0x61a3c261U, 0x355f6a35U, 0x57f9ae57U, 0xb9d069b9U, + 0x86911786U, 0xc15899c1U, 0x1d273a1dU, 0x9eb9279eU, + 0xe138d9e1U, 0xf813ebf8U, 0x98b32b98U, 0x11332211U, + 0x69bbd269U, 0xd970a9d9U, 0x8e89078eU, 0x94a73394U, + 0x9bb62d9bU, 0x1e223c1eU, 0x87921587U, 0xe920c9e9U, + 0xce4987ceU, 0x55ffaa55U, 0x28785028U, 0xdf7aa5dfU, + 0x8c8f038cU, 0xa1f859a1U, 0x89800989U, 0x0d171a0dU, + 0xbfda65bfU, 0xe631d7e6U, 0x42c68442U, 0x68b8d068U, + 0x41c38241U, 0x99b02999U, 0x2d775a2dU, 0x0f111e0fU, + 0xb0cb7bb0U, 0x54fca854U, 0xbbd66dbbU, 0x163a2c16U, +}; + +const TUint32 Te3[256] = { + 0x6363a5c6U, 0x7c7c84f8U, 0x777799eeU, 0x7b7b8df6U, + 0xf2f20dffU, 0x6b6bbdd6U, 0x6f6fb1deU, 0xc5c55491U, + 0x30305060U, 0x01010302U, 0x6767a9ceU, 0x2b2b7d56U, + 0xfefe19e7U, 0xd7d762b5U, 0xababe64dU, 0x76769aecU, + 0xcaca458fU, 0x82829d1fU, 0xc9c94089U, 0x7d7d87faU, + 0xfafa15efU, 0x5959ebb2U, 0x4747c98eU, 0xf0f00bfbU, + 0xadadec41U, 0xd4d467b3U, 0xa2a2fd5fU, 0xafafea45U, + 0x9c9cbf23U, 0xa4a4f753U, 0x727296e4U, 0xc0c05b9bU, + 0xb7b7c275U, 0xfdfd1ce1U, 0x9393ae3dU, 0x26266a4cU, + 0x36365a6cU, 0x3f3f417eU, 0xf7f702f5U, 0xcccc4f83U, + 0x34345c68U, 0xa5a5f451U, 0xe5e534d1U, 0xf1f108f9U, + 0x717193e2U, 0xd8d873abU, 0x31315362U, 0x15153f2aU, + 0x04040c08U, 0xc7c75295U, 0x23236546U, 0xc3c35e9dU, + 0x18182830U, 0x9696a137U, 0x05050f0aU, 0x9a9ab52fU, + 0x0707090eU, 0x12123624U, 0x80809b1bU, 0xe2e23ddfU, + 0xebeb26cdU, 0x2727694eU, 0xb2b2cd7fU, 0x75759feaU, + 0x09091b12U, 0x83839e1dU, 0x2c2c7458U, 0x1a1a2e34U, + 0x1b1b2d36U, 0x6e6eb2dcU, 0x5a5aeeb4U, 0xa0a0fb5bU, + 0x5252f6a4U, 0x3b3b4d76U, 0xd6d661b7U, 0xb3b3ce7dU, + 0x29297b52U, 0xe3e33eddU, 0x2f2f715eU, 0x84849713U, + 0x5353f5a6U, 0xd1d168b9U, 0x00000000U, 0xeded2cc1U, + 0x20206040U, 0xfcfc1fe3U, 0xb1b1c879U, 0x5b5bedb6U, + 0x6a6abed4U, 0xcbcb468dU, 0xbebed967U, 0x39394b72U, + 0x4a4ade94U, 0x4c4cd498U, 0x5858e8b0U, 0xcfcf4a85U, + 0xd0d06bbbU, 0xefef2ac5U, 0xaaaae54fU, 0xfbfb16edU, + 0x4343c586U, 0x4d4dd79aU, 0x33335566U, 0x85859411U, + 0x4545cf8aU, 0xf9f910e9U, 0x02020604U, 0x7f7f81feU, + 0x5050f0a0U, 0x3c3c4478U, 0x9f9fba25U, 0xa8a8e34bU, + 0x5151f3a2U, 0xa3a3fe5dU, 0x4040c080U, 0x8f8f8a05U, + 0x9292ad3fU, 0x9d9dbc21U, 0x38384870U, 0xf5f504f1U, + 0xbcbcdf63U, 0xb6b6c177U, 0xdada75afU, 0x21216342U, + 0x10103020U, 0xffff1ae5U, 0xf3f30efdU, 0xd2d26dbfU, + 0xcdcd4c81U, 0x0c0c1418U, 0x13133526U, 0xecec2fc3U, + 0x5f5fe1beU, 0x9797a235U, 0x4444cc88U, 0x1717392eU, + 0xc4c45793U, 0xa7a7f255U, 0x7e7e82fcU, 0x3d3d477aU, + 0x6464acc8U, 0x5d5de7baU, 0x19192b32U, 0x737395e6U, + 0x6060a0c0U, 0x81819819U, 0x4f4fd19eU, 0xdcdc7fa3U, + 0x22226644U, 0x2a2a7e54U, 0x9090ab3bU, 0x8888830bU, + 0x4646ca8cU, 0xeeee29c7U, 0xb8b8d36bU, 0x14143c28U, + 0xdede79a7U, 0x5e5ee2bcU, 0x0b0b1d16U, 0xdbdb76adU, + 0xe0e03bdbU, 0x32325664U, 0x3a3a4e74U, 0x0a0a1e14U, + 0x4949db92U, 0x06060a0cU, 0x24246c48U, 0x5c5ce4b8U, + 0xc2c25d9fU, 0xd3d36ebdU, 0xacacef43U, 0x6262a6c4U, + 0x9191a839U, 0x9595a431U, 0xe4e437d3U, 0x79798bf2U, + 0xe7e732d5U, 0xc8c8438bU, 0x3737596eU, 0x6d6db7daU, + 0x8d8d8c01U, 0xd5d564b1U, 0x4e4ed29cU, 0xa9a9e049U, + 0x6c6cb4d8U, 0x5656faacU, 0xf4f407f3U, 0xeaea25cfU, + 0x6565afcaU, 0x7a7a8ef4U, 0xaeaee947U, 0x08081810U, + 0xbabad56fU, 0x787888f0U, 0x25256f4aU, 0x2e2e725cU, + 0x1c1c2438U, 0xa6a6f157U, 0xb4b4c773U, 0xc6c65197U, + 0xe8e823cbU, 0xdddd7ca1U, 0x74749ce8U, 0x1f1f213eU, + 0x4b4bdd96U, 0xbdbddc61U, 0x8b8b860dU, 0x8a8a850fU, + 0x707090e0U, 0x3e3e427cU, 0xb5b5c471U, 0x6666aaccU, + 0x4848d890U, 0x03030506U, 0xf6f601f7U, 0x0e0e121cU, + 0x6161a3c2U, 0x35355f6aU, 0x5757f9aeU, 0xb9b9d069U, + 0x86869117U, 0xc1c15899U, 0x1d1d273aU, 0x9e9eb927U, + 0xe1e138d9U, 0xf8f813ebU, 0x9898b32bU, 0x11113322U, + 0x6969bbd2U, 0xd9d970a9U, 0x8e8e8907U, 0x9494a733U, + 0x9b9bb62dU, 0x1e1e223cU, 0x87879215U, 0xe9e920c9U, + 0xcece4987U, 0x5555ffaaU, 0x28287850U, 0xdfdf7aa5U, + 0x8c8c8f03U, 0xa1a1f859U, 0x89898009U, 0x0d0d171aU, + 0xbfbfda65U, 0xe6e631d7U, 0x4242c684U, 0x6868b8d0U, + 0x4141c382U, 0x9999b029U, 0x2d2d775aU, 0x0f0f111eU, + 0xb0b0cb7bU, 0x5454fca8U, 0xbbbbd66dU, 0x16163a2cU, +}; + +const TUint32 Te4[256] = { + 0x63636363U, 0x7c7c7c7cU, 0x77777777U, 0x7b7b7b7bU, + 0xf2f2f2f2U, 0x6b6b6b6bU, 0x6f6f6f6fU, 0xc5c5c5c5U, + 0x30303030U, 0x01010101U, 0x67676767U, 0x2b2b2b2bU, + 0xfefefefeU, 0xd7d7d7d7U, 0xababababU, 0x76767676U, + 0xcacacacaU, 0x82828282U, 0xc9c9c9c9U, 0x7d7d7d7dU, + 0xfafafafaU, 0x59595959U, 0x47474747U, 0xf0f0f0f0U, + 0xadadadadU, 0xd4d4d4d4U, 0xa2a2a2a2U, 0xafafafafU, + 0x9c9c9c9cU, 0xa4a4a4a4U, 0x72727272U, 0xc0c0c0c0U, + 0xb7b7b7b7U, 0xfdfdfdfdU, 0x93939393U, 0x26262626U, + 0x36363636U, 0x3f3f3f3fU, 0xf7f7f7f7U, 0xccccccccU, + 0x34343434U, 0xa5a5a5a5U, 0xe5e5e5e5U, 0xf1f1f1f1U, + 0x71717171U, 0xd8d8d8d8U, 0x31313131U, 0x15151515U, + 0x04040404U, 0xc7c7c7c7U, 0x23232323U, 0xc3c3c3c3U, + 0x18181818U, 0x96969696U, 0x05050505U, 0x9a9a9a9aU, + 0x07070707U, 0x12121212U, 0x80808080U, 0xe2e2e2e2U, + 0xebebebebU, 0x27272727U, 0xb2b2b2b2U, 0x75757575U, + 0x09090909U, 0x83838383U, 0x2c2c2c2cU, 0x1a1a1a1aU, + 0x1b1b1b1bU, 0x6e6e6e6eU, 0x5a5a5a5aU, 0xa0a0a0a0U, + 0x52525252U, 0x3b3b3b3bU, 0xd6d6d6d6U, 0xb3b3b3b3U, + 0x29292929U, 0xe3e3e3e3U, 0x2f2f2f2fU, 0x84848484U, + 0x53535353U, 0xd1d1d1d1U, 0x00000000U, 0xededededU, + 0x20202020U, 0xfcfcfcfcU, 0xb1b1b1b1U, 0x5b5b5b5bU, + 0x6a6a6a6aU, 0xcbcbcbcbU, 0xbebebebeU, 0x39393939U, + 0x4a4a4a4aU, 0x4c4c4c4cU, 0x58585858U, 0xcfcfcfcfU, + 0xd0d0d0d0U, 0xefefefefU, 0xaaaaaaaaU, 0xfbfbfbfbU, + 0x43434343U, 0x4d4d4d4dU, 0x33333333U, 0x85858585U, + 0x45454545U, 0xf9f9f9f9U, 0x02020202U, 0x7f7f7f7fU, + 0x50505050U, 0x3c3c3c3cU, 0x9f9f9f9fU, 0xa8a8a8a8U, + 0x51515151U, 0xa3a3a3a3U, 0x40404040U, 0x8f8f8f8fU, + 0x92929292U, 0x9d9d9d9dU, 0x38383838U, 0xf5f5f5f5U, + 0xbcbcbcbcU, 0xb6b6b6b6U, 0xdadadadaU, 0x21212121U, + 0x10101010U, 0xffffffffU, 0xf3f3f3f3U, 0xd2d2d2d2U, + 0xcdcdcdcdU, 0x0c0c0c0cU, 0x13131313U, 0xececececU, + 0x5f5f5f5fU, 0x97979797U, 0x44444444U, 0x17171717U, + 0xc4c4c4c4U, 0xa7a7a7a7U, 0x7e7e7e7eU, 0x3d3d3d3dU, + 0x64646464U, 0x5d5d5d5dU, 0x19191919U, 0x73737373U, + 0x60606060U, 0x81818181U, 0x4f4f4f4fU, 0xdcdcdcdcU, + 0x22222222U, 0x2a2a2a2aU, 0x90909090U, 0x88888888U, + 0x46464646U, 0xeeeeeeeeU, 0xb8b8b8b8U, 0x14141414U, + 0xdedededeU, 0x5e5e5e5eU, 0x0b0b0b0bU, 0xdbdbdbdbU, + 0xe0e0e0e0U, 0x32323232U, 0x3a3a3a3aU, 0x0a0a0a0aU, + 0x49494949U, 0x06060606U, 0x24242424U, 0x5c5c5c5cU, + 0xc2c2c2c2U, 0xd3d3d3d3U, 0xacacacacU, 0x62626262U, + 0x91919191U, 0x95959595U, 0xe4e4e4e4U, 0x79797979U, + 0xe7e7e7e7U, 0xc8c8c8c8U, 0x37373737U, 0x6d6d6d6dU, + 0x8d8d8d8dU, 0xd5d5d5d5U, 0x4e4e4e4eU, 0xa9a9a9a9U, + 0x6c6c6c6cU, 0x56565656U, 0xf4f4f4f4U, 0xeaeaeaeaU, + 0x65656565U, 0x7a7a7a7aU, 0xaeaeaeaeU, 0x08080808U, + 0xbabababaU, 0x78787878U, 0x25252525U, 0x2e2e2e2eU, + 0x1c1c1c1cU, 0xa6a6a6a6U, 0xb4b4b4b4U, 0xc6c6c6c6U, + 0xe8e8e8e8U, 0xddddddddU, 0x74747474U, 0x1f1f1f1fU, + 0x4b4b4b4bU, 0xbdbdbdbdU, 0x8b8b8b8bU, 0x8a8a8a8aU, + 0x70707070U, 0x3e3e3e3eU, 0xb5b5b5b5U, 0x66666666U, + 0x48484848U, 0x03030303U, 0xf6f6f6f6U, 0x0e0e0e0eU, + 0x61616161U, 0x35353535U, 0x57575757U, 0xb9b9b9b9U, + 0x86868686U, 0xc1c1c1c1U, 0x1d1d1d1dU, 0x9e9e9e9eU, + 0xe1e1e1e1U, 0xf8f8f8f8U, 0x98989898U, 0x11111111U, + 0x69696969U, 0xd9d9d9d9U, 0x8e8e8e8eU, 0x94949494U, + 0x9b9b9b9bU, 0x1e1e1e1eU, 0x87878787U, 0xe9e9e9e9U, + 0xcecececeU, 0x55555555U, 0x28282828U, 0xdfdfdfdfU, + 0x8c8c8c8cU, 0xa1a1a1a1U, 0x89898989U, 0x0d0d0d0dU, + 0xbfbfbfbfU, 0xe6e6e6e6U, 0x42424242U, 0x68686868U, + 0x41414141U, 0x99999999U, 0x2d2d2d2dU, 0x0f0f0f0fU, + 0xb0b0b0b0U, 0x54545454U, 0xbbbbbbbbU, 0x16161616U, +}; + +const TUint32 Td0[256] = { + 0x51f4a750U, 0x7e416553U, 0x1a17a4c3U, 0x3a275e96U, + 0x3bab6bcbU, 0x1f9d45f1U, 0xacfa58abU, 0x4be30393U, + 0x2030fa55U, 0xad766df6U, 0x88cc7691U, 0xf5024c25U, + 0x4fe5d7fcU, 0xc52acbd7U, 0x26354480U, 0xb562a38fU, + 0xdeb15a49U, 0x25ba1b67U, 0x45ea0e98U, 0x5dfec0e1U, + 0xc32f7502U, 0x814cf012U, 0x8d4697a3U, 0x6bd3f9c6U, + 0x038f5fe7U, 0x15929c95U, 0xbf6d7aebU, 0x955259daU, + 0xd4be832dU, 0x587421d3U, 0x49e06929U, 0x8ec9c844U, + 0x75c2896aU, 0xf48e7978U, 0x99583e6bU, 0x27b971ddU, + 0xbee14fb6U, 0xf088ad17U, 0xc920ac66U, 0x7dce3ab4U, + 0x63df4a18U, 0xe51a3182U, 0x97513360U, 0x62537f45U, + 0xb16477e0U, 0xbb6bae84U, 0xfe81a01cU, 0xf9082b94U, + 0x70486858U, 0x8f45fd19U, 0x94de6c87U, 0x527bf8b7U, + 0xab73d323U, 0x724b02e2U, 0xe31f8f57U, 0x6655ab2aU, + 0xb2eb2807U, 0x2fb5c203U, 0x86c57b9aU, 0xd33708a5U, + 0x302887f2U, 0x23bfa5b2U, 0x02036abaU, 0xed16825cU, + 0x8acf1c2bU, 0xa779b492U, 0xf307f2f0U, 0x4e69e2a1U, + 0x65daf4cdU, 0x0605bed5U, 0xd134621fU, 0xc4a6fe8aU, + 0x342e539dU, 0xa2f355a0U, 0x058ae132U, 0xa4f6eb75U, + 0x0b83ec39U, 0x4060efaaU, 0x5e719f06U, 0xbd6e1051U, + 0x3e218af9U, 0x96dd063dU, 0xdd3e05aeU, 0x4de6bd46U, + 0x91548db5U, 0x71c45d05U, 0x0406d46fU, 0x605015ffU, + 0x1998fb24U, 0xd6bde997U, 0x894043ccU, 0x67d99e77U, + 0xb0e842bdU, 0x07898b88U, 0xe7195b38U, 0x79c8eedbU, + 0xa17c0a47U, 0x7c420fe9U, 0xf8841ec9U, 0x00000000U, + 0x09808683U, 0x322bed48U, 0x1e1170acU, 0x6c5a724eU, + 0xfd0efffbU, 0x0f853856U, 0x3daed51eU, 0x362d3927U, + 0x0a0fd964U, 0x685ca621U, 0x9b5b54d1U, 0x24362e3aU, + 0x0c0a67b1U, 0x9357e70fU, 0xb4ee96d2U, 0x1b9b919eU, + 0x80c0c54fU, 0x61dc20a2U, 0x5a774b69U, 0x1c121a16U, + 0xe293ba0aU, 0xc0a02ae5U, 0x3c22e043U, 0x121b171dU, + 0x0e090d0bU, 0xf28bc7adU, 0x2db6a8b9U, 0x141ea9c8U, + 0x57f11985U, 0xaf75074cU, 0xee99ddbbU, 0xa37f60fdU, + 0xf701269fU, 0x5c72f5bcU, 0x44663bc5U, 0x5bfb7e34U, + 0x8b432976U, 0xcb23c6dcU, 0xb6edfc68U, 0xb8e4f163U, + 0xd731dccaU, 0x42638510U, 0x13972240U, 0x84c61120U, + 0x854a247dU, 0xd2bb3df8U, 0xaef93211U, 0xc729a16dU, + 0x1d9e2f4bU, 0xdcb230f3U, 0x0d8652ecU, 0x77c1e3d0U, + 0x2bb3166cU, 0xa970b999U, 0x119448faU, 0x47e96422U, + 0xa8fc8cc4U, 0xa0f03f1aU, 0x567d2cd8U, 0x223390efU, + 0x87494ec7U, 0xd938d1c1U, 0x8ccaa2feU, 0x98d40b36U, + 0xa6f581cfU, 0xa57ade28U, 0xdab78e26U, 0x3fadbfa4U, + 0x2c3a9de4U, 0x5078920dU, 0x6a5fcc9bU, 0x547e4662U, + 0xf68d13c2U, 0x90d8b8e8U, 0x2e39f75eU, 0x82c3aff5U, + 0x9f5d80beU, 0x69d0937cU, 0x6fd52da9U, 0xcf2512b3U, + 0xc8ac993bU, 0x10187da7U, 0xe89c636eU, 0xdb3bbb7bU, + 0xcd267809U, 0x6e5918f4U, 0xec9ab701U, 0x834f9aa8U, + 0xe6956e65U, 0xaaffe67eU, 0x21bccf08U, 0xef15e8e6U, + 0xbae79bd9U, 0x4a6f36ceU, 0xea9f09d4U, 0x29b07cd6U, + 0x31a4b2afU, 0x2a3f2331U, 0xc6a59430U, 0x35a266c0U, + 0x744ebc37U, 0xfc82caa6U, 0xe090d0b0U, 0x33a7d815U, + 0xf104984aU, 0x41ecdaf7U, 0x7fcd500eU, 0x1791f62fU, + 0x764dd68dU, 0x43efb04dU, 0xccaa4d54U, 0xe49604dfU, + 0x9ed1b5e3U, 0x4c6a881bU, 0xc12c1fb8U, 0x4665517fU, + 0x9d5eea04U, 0x018c355dU, 0xfa877473U, 0xfb0b412eU, + 0xb3671d5aU, 0x92dbd252U, 0xe9105633U, 0x6dd64713U, + 0x9ad7618cU, 0x37a10c7aU, 0x59f8148eU, 0xeb133c89U, + 0xcea927eeU, 0xb761c935U, 0xe11ce5edU, 0x7a47b13cU, + 0x9cd2df59U, 0x55f2733fU, 0x1814ce79U, 0x73c737bfU, + 0x53f7cdeaU, 0x5ffdaa5bU, 0xdf3d6f14U, 0x7844db86U, + 0xcaaff381U, 0xb968c43eU, 0x3824342cU, 0xc2a3405fU, + 0x161dc372U, 0xbce2250cU, 0x283c498bU, 0xff0d9541U, + 0x39a80171U, 0x080cb3deU, 0xd8b4e49cU, 0x6456c190U, + 0x7bcb8461U, 0xd532b670U, 0x486c5c74U, 0xd0b85742U, +}; + +const TUint32 Td1[256] = { + 0x5051f4a7U, 0x537e4165U, 0xc31a17a4U, 0x963a275eU, + 0xcb3bab6bU, 0xf11f9d45U, 0xabacfa58U, 0x934be303U, + 0x552030faU, 0xf6ad766dU, 0x9188cc76U, 0x25f5024cU, + 0xfc4fe5d7U, 0xd7c52acbU, 0x80263544U, 0x8fb562a3U, + 0x49deb15aU, 0x6725ba1bU, 0x9845ea0eU, 0xe15dfec0U, + 0x02c32f75U, 0x12814cf0U, 0xa38d4697U, 0xc66bd3f9U, + 0xe7038f5fU, 0x9515929cU, 0xebbf6d7aU, 0xda955259U, + 0x2dd4be83U, 0xd3587421U, 0x2949e069U, 0x448ec9c8U, + 0x6a75c289U, 0x78f48e79U, 0x6b99583eU, 0xdd27b971U, + 0xb6bee14fU, 0x17f088adU, 0x66c920acU, 0xb47dce3aU, + 0x1863df4aU, 0x82e51a31U, 0x60975133U, 0x4562537fU, + 0xe0b16477U, 0x84bb6baeU, 0x1cfe81a0U, 0x94f9082bU, + 0x58704868U, 0x198f45fdU, 0x8794de6cU, 0xb7527bf8U, + 0x23ab73d3U, 0xe2724b02U, 0x57e31f8fU, 0x2a6655abU, + 0x07b2eb28U, 0x032fb5c2U, 0x9a86c57bU, 0xa5d33708U, + 0xf2302887U, 0xb223bfa5U, 0xba02036aU, 0x5ced1682U, + 0x2b8acf1cU, 0x92a779b4U, 0xf0f307f2U, 0xa14e69e2U, + 0xcd65daf4U, 0xd50605beU, 0x1fd13462U, 0x8ac4a6feU, + 0x9d342e53U, 0xa0a2f355U, 0x32058ae1U, 0x75a4f6ebU, + 0x390b83ecU, 0xaa4060efU, 0x065e719fU, 0x51bd6e10U, + 0xf93e218aU, 0x3d96dd06U, 0xaedd3e05U, 0x464de6bdU, + 0xb591548dU, 0x0571c45dU, 0x6f0406d4U, 0xff605015U, + 0x241998fbU, 0x97d6bde9U, 0xcc894043U, 0x7767d99eU, + 0xbdb0e842U, 0x8807898bU, 0x38e7195bU, 0xdb79c8eeU, + 0x47a17c0aU, 0xe97c420fU, 0xc9f8841eU, 0x00000000U, + 0x83098086U, 0x48322bedU, 0xac1e1170U, 0x4e6c5a72U, + 0xfbfd0effU, 0x560f8538U, 0x1e3daed5U, 0x27362d39U, + 0x640a0fd9U, 0x21685ca6U, 0xd19b5b54U, 0x3a24362eU, + 0xb10c0a67U, 0x0f9357e7U, 0xd2b4ee96U, 0x9e1b9b91U, + 0x4f80c0c5U, 0xa261dc20U, 0x695a774bU, 0x161c121aU, + 0x0ae293baU, 0xe5c0a02aU, 0x433c22e0U, 0x1d121b17U, + 0x0b0e090dU, 0xadf28bc7U, 0xb92db6a8U, 0xc8141ea9U, + 0x8557f119U, 0x4caf7507U, 0xbbee99ddU, 0xfda37f60U, + 0x9ff70126U, 0xbc5c72f5U, 0xc544663bU, 0x345bfb7eU, + 0x768b4329U, 0xdccb23c6U, 0x68b6edfcU, 0x63b8e4f1U, + 0xcad731dcU, 0x10426385U, 0x40139722U, 0x2084c611U, + 0x7d854a24U, 0xf8d2bb3dU, 0x11aef932U, 0x6dc729a1U, + 0x4b1d9e2fU, 0xf3dcb230U, 0xec0d8652U, 0xd077c1e3U, + 0x6c2bb316U, 0x99a970b9U, 0xfa119448U, 0x2247e964U, + 0xc4a8fc8cU, 0x1aa0f03fU, 0xd8567d2cU, 0xef223390U, + 0xc787494eU, 0xc1d938d1U, 0xfe8ccaa2U, 0x3698d40bU, + 0xcfa6f581U, 0x28a57adeU, 0x26dab78eU, 0xa43fadbfU, + 0xe42c3a9dU, 0x0d507892U, 0x9b6a5fccU, 0x62547e46U, + 0xc2f68d13U, 0xe890d8b8U, 0x5e2e39f7U, 0xf582c3afU, + 0xbe9f5d80U, 0x7c69d093U, 0xa96fd52dU, 0xb3cf2512U, + 0x3bc8ac99U, 0xa710187dU, 0x6ee89c63U, 0x7bdb3bbbU, + 0x09cd2678U, 0xf46e5918U, 0x01ec9ab7U, 0xa8834f9aU, + 0x65e6956eU, 0x7eaaffe6U, 0x0821bccfU, 0xe6ef15e8U, + 0xd9bae79bU, 0xce4a6f36U, 0xd4ea9f09U, 0xd629b07cU, + 0xaf31a4b2U, 0x312a3f23U, 0x30c6a594U, 0xc035a266U, + 0x37744ebcU, 0xa6fc82caU, 0xb0e090d0U, 0x1533a7d8U, + 0x4af10498U, 0xf741ecdaU, 0x0e7fcd50U, 0x2f1791f6U, + 0x8d764dd6U, 0x4d43efb0U, 0x54ccaa4dU, 0xdfe49604U, + 0xe39ed1b5U, 0x1b4c6a88U, 0xb8c12c1fU, 0x7f466551U, + 0x049d5eeaU, 0x5d018c35U, 0x73fa8774U, 0x2efb0b41U, + 0x5ab3671dU, 0x5292dbd2U, 0x33e91056U, 0x136dd647U, + 0x8c9ad761U, 0x7a37a10cU, 0x8e59f814U, 0x89eb133cU, + 0xeecea927U, 0x35b761c9U, 0xede11ce5U, 0x3c7a47b1U, + 0x599cd2dfU, 0x3f55f273U, 0x791814ceU, 0xbf73c737U, + 0xea53f7cdU, 0x5b5ffdaaU, 0x14df3d6fU, 0x867844dbU, + 0x81caaff3U, 0x3eb968c4U, 0x2c382434U, 0x5fc2a340U, + 0x72161dc3U, 0x0cbce225U, 0x8b283c49U, 0x41ff0d95U, + 0x7139a801U, 0xde080cb3U, 0x9cd8b4e4U, 0x906456c1U, + 0x617bcb84U, 0x70d532b6U, 0x74486c5cU, 0x42d0b857U, +}; + +const TUint32 Td2[256] = { + 0xa75051f4U, 0x65537e41U, 0xa4c31a17U, 0x5e963a27U, + 0x6bcb3babU, 0x45f11f9dU, 0x58abacfaU, 0x03934be3U, + 0xfa552030U, 0x6df6ad76U, 0x769188ccU, 0x4c25f502U, + 0xd7fc4fe5U, 0xcbd7c52aU, 0x44802635U, 0xa38fb562U, + 0x5a49deb1U, 0x1b6725baU, 0x0e9845eaU, 0xc0e15dfeU, + 0x7502c32fU, 0xf012814cU, 0x97a38d46U, 0xf9c66bd3U, + 0x5fe7038fU, 0x9c951592U, 0x7aebbf6dU, 0x59da9552U, + 0x832dd4beU, 0x21d35874U, 0x692949e0U, 0xc8448ec9U, + 0x896a75c2U, 0x7978f48eU, 0x3e6b9958U, 0x71dd27b9U, + 0x4fb6bee1U, 0xad17f088U, 0xac66c920U, 0x3ab47dceU, + 0x4a1863dfU, 0x3182e51aU, 0x33609751U, 0x7f456253U, + 0x77e0b164U, 0xae84bb6bU, 0xa01cfe81U, 0x2b94f908U, + 0x68587048U, 0xfd198f45U, 0x6c8794deU, 0xf8b7527bU, + 0xd323ab73U, 0x02e2724bU, 0x8f57e31fU, 0xab2a6655U, + 0x2807b2ebU, 0xc2032fb5U, 0x7b9a86c5U, 0x08a5d337U, + 0x87f23028U, 0xa5b223bfU, 0x6aba0203U, 0x825ced16U, + 0x1c2b8acfU, 0xb492a779U, 0xf2f0f307U, 0xe2a14e69U, + 0xf4cd65daU, 0xbed50605U, 0x621fd134U, 0xfe8ac4a6U, + 0x539d342eU, 0x55a0a2f3U, 0xe132058aU, 0xeb75a4f6U, + 0xec390b83U, 0xefaa4060U, 0x9f065e71U, 0x1051bd6eU, + + 0x8af93e21U, 0x063d96ddU, 0x05aedd3eU, 0xbd464de6U, + 0x8db59154U, 0x5d0571c4U, 0xd46f0406U, 0x15ff6050U, + 0xfb241998U, 0xe997d6bdU, 0x43cc8940U, 0x9e7767d9U, + 0x42bdb0e8U, 0x8b880789U, 0x5b38e719U, 0xeedb79c8U, + 0x0a47a17cU, 0x0fe97c42U, 0x1ec9f884U, 0x00000000U, + 0x86830980U, 0xed48322bU, 0x70ac1e11U, 0x724e6c5aU, + 0xfffbfd0eU, 0x38560f85U, 0xd51e3daeU, 0x3927362dU, + 0xd9640a0fU, 0xa621685cU, 0x54d19b5bU, 0x2e3a2436U, + 0x67b10c0aU, 0xe70f9357U, 0x96d2b4eeU, 0x919e1b9bU, + 0xc54f80c0U, 0x20a261dcU, 0x4b695a77U, 0x1a161c12U, + 0xba0ae293U, 0x2ae5c0a0U, 0xe0433c22U, 0x171d121bU, + 0x0d0b0e09U, 0xc7adf28bU, 0xa8b92db6U, 0xa9c8141eU, + 0x198557f1U, 0x074caf75U, 0xddbbee99U, 0x60fda37fU, + 0x269ff701U, 0xf5bc5c72U, 0x3bc54466U, 0x7e345bfbU, + 0x29768b43U, 0xc6dccb23U, 0xfc68b6edU, 0xf163b8e4U, + 0xdccad731U, 0x85104263U, 0x22401397U, 0x112084c6U, + 0x247d854aU, 0x3df8d2bbU, 0x3211aef9U, 0xa16dc729U, + 0x2f4b1d9eU, 0x30f3dcb2U, 0x52ec0d86U, 0xe3d077c1U, + 0x166c2bb3U, 0xb999a970U, 0x48fa1194U, 0x642247e9U, + 0x8cc4a8fcU, 0x3f1aa0f0U, 0x2cd8567dU, 0x90ef2233U, + 0x4ec78749U, 0xd1c1d938U, 0xa2fe8ccaU, 0x0b3698d4U, + 0x81cfa6f5U, 0xde28a57aU, 0x8e26dab7U, 0xbfa43fadU, + 0x9de42c3aU, 0x920d5078U, 0xcc9b6a5fU, 0x4662547eU, + 0x13c2f68dU, 0xb8e890d8U, 0xf75e2e39U, 0xaff582c3U, + 0x80be9f5dU, 0x937c69d0U, 0x2da96fd5U, 0x12b3cf25U, + 0x993bc8acU, 0x7da71018U, 0x636ee89cU, 0xbb7bdb3bU, + 0x7809cd26U, 0x18f46e59U, 0xb701ec9aU, 0x9aa8834fU, + 0x6e65e695U, 0xe67eaaffU, 0xcf0821bcU, 0xe8e6ef15U, + 0x9bd9bae7U, 0x36ce4a6fU, 0x09d4ea9fU, 0x7cd629b0U, + 0xb2af31a4U, 0x23312a3fU, 0x9430c6a5U, 0x66c035a2U, + 0xbc37744eU, 0xcaa6fc82U, 0xd0b0e090U, 0xd81533a7U, + 0x984af104U, 0xdaf741ecU, 0x500e7fcdU, 0xf62f1791U, + 0xd68d764dU, 0xb04d43efU, 0x4d54ccaaU, 0x04dfe496U, + 0xb5e39ed1U, 0x881b4c6aU, 0x1fb8c12cU, 0x517f4665U, + 0xea049d5eU, 0x355d018cU, 0x7473fa87U, 0x412efb0bU, + 0x1d5ab367U, 0xd25292dbU, 0x5633e910U, 0x47136dd6U, + 0x618c9ad7U, 0x0c7a37a1U, 0x148e59f8U, 0x3c89eb13U, + 0x27eecea9U, 0xc935b761U, 0xe5ede11cU, 0xb13c7a47U, + 0xdf599cd2U, 0x733f55f2U, 0xce791814U, 0x37bf73c7U, + 0xcdea53f7U, 0xaa5b5ffdU, 0x6f14df3dU, 0xdb867844U, + 0xf381caafU, 0xc43eb968U, 0x342c3824U, 0x405fc2a3U, + 0xc372161dU, 0x250cbce2U, 0x498b283cU, 0x9541ff0dU, + 0x017139a8U, 0xb3de080cU, 0xe49cd8b4U, 0xc1906456U, + 0x84617bcbU, 0xb670d532U, 0x5c74486cU, 0x5742d0b8U, +}; + +const TUint32 Td3[256] = { + 0xf4a75051U, 0x4165537eU, 0x17a4c31aU, 0x275e963aU, + 0xab6bcb3bU, 0x9d45f11fU, 0xfa58abacU, 0xe303934bU, + 0x30fa5520U, 0x766df6adU, 0xcc769188U, 0x024c25f5U, + 0xe5d7fc4fU, 0x2acbd7c5U, 0x35448026U, 0x62a38fb5U, + 0xb15a49deU, 0xba1b6725U, 0xea0e9845U, 0xfec0e15dU, + 0x2f7502c3U, 0x4cf01281U, 0x4697a38dU, 0xd3f9c66bU, + 0x8f5fe703U, 0x929c9515U, 0x6d7aebbfU, 0x5259da95U, + 0xbe832dd4U, 0x7421d358U, 0xe0692949U, 0xc9c8448eU, + 0xc2896a75U, 0x8e7978f4U, 0x583e6b99U, 0xb971dd27U, + 0xe14fb6beU, 0x88ad17f0U, 0x20ac66c9U, 0xce3ab47dU, + 0xdf4a1863U, 0x1a3182e5U, 0x51336097U, 0x537f4562U, + 0x6477e0b1U, 0x6bae84bbU, 0x81a01cfeU, 0x082b94f9U, + 0x48685870U, 0x45fd198fU, 0xde6c8794U, 0x7bf8b752U, + 0x73d323abU, 0x4b02e272U, 0x1f8f57e3U, 0x55ab2a66U, + 0xeb2807b2U, 0xb5c2032fU, 0xc57b9a86U, 0x3708a5d3U, + 0x2887f230U, 0xbfa5b223U, 0x036aba02U, 0x16825cedU, + 0xcf1c2b8aU, 0x79b492a7U, 0x07f2f0f3U, 0x69e2a14eU, + 0xdaf4cd65U, 0x05bed506U, 0x34621fd1U, 0xa6fe8ac4U, + 0x2e539d34U, 0xf355a0a2U, 0x8ae13205U, 0xf6eb75a4U, + 0x83ec390bU, 0x60efaa40U, 0x719f065eU, 0x6e1051bdU, + 0x218af93eU, 0xdd063d96U, 0x3e05aeddU, 0xe6bd464dU, + 0x548db591U, 0xc45d0571U, 0x06d46f04U, 0x5015ff60U, + 0x98fb2419U, 0xbde997d6U, 0x4043cc89U, 0xd99e7767U, + 0xe842bdb0U, 0x898b8807U, 0x195b38e7U, 0xc8eedb79U, + 0x7c0a47a1U, 0x420fe97cU, 0x841ec9f8U, 0x00000000U, + 0x80868309U, 0x2bed4832U, 0x1170ac1eU, 0x5a724e6cU, + 0x0efffbfdU, 0x8538560fU, 0xaed51e3dU, 0x2d392736U, + 0x0fd9640aU, 0x5ca62168U, 0x5b54d19bU, 0x362e3a24U, + 0x0a67b10cU, 0x57e70f93U, 0xee96d2b4U, 0x9b919e1bU, + 0xc0c54f80U, 0xdc20a261U, 0x774b695aU, 0x121a161cU, + 0x93ba0ae2U, 0xa02ae5c0U, 0x22e0433cU, 0x1b171d12U, + 0x090d0b0eU, 0x8bc7adf2U, 0xb6a8b92dU, 0x1ea9c814U, + 0xf1198557U, 0x75074cafU, 0x99ddbbeeU, 0x7f60fda3U, + 0x01269ff7U, 0x72f5bc5cU, 0x663bc544U, 0xfb7e345bU, + 0x4329768bU, 0x23c6dccbU, 0xedfc68b6U, 0xe4f163b8U, + 0x31dccad7U, 0x63851042U, 0x97224013U, 0xc6112084U, + 0x4a247d85U, 0xbb3df8d2U, 0xf93211aeU, 0x29a16dc7U, + 0x9e2f4b1dU, 0xb230f3dcU, 0x8652ec0dU, 0xc1e3d077U, + 0xb3166c2bU, 0x70b999a9U, 0x9448fa11U, 0xe9642247U, + 0xfc8cc4a8U, 0xf03f1aa0U, 0x7d2cd856U, 0x3390ef22U, + 0x494ec787U, 0x38d1c1d9U, 0xcaa2fe8cU, 0xd40b3698U, + 0xf581cfa6U, 0x7ade28a5U, 0xb78e26daU, 0xadbfa43fU, + 0x3a9de42cU, 0x78920d50U, 0x5fcc9b6aU, 0x7e466254U, + 0x8d13c2f6U, 0xd8b8e890U, 0x39f75e2eU, 0xc3aff582U, + 0x5d80be9fU, 0xd0937c69U, 0xd52da96fU, 0x2512b3cfU, + 0xac993bc8U, 0x187da710U, 0x9c636ee8U, 0x3bbb7bdbU, + 0x267809cdU, 0x5918f46eU, 0x9ab701ecU, 0x4f9aa883U, + 0x956e65e6U, 0xffe67eaaU, 0xbccf0821U, 0x15e8e6efU, + 0xe79bd9baU, 0x6f36ce4aU, 0x9f09d4eaU, 0xb07cd629U, + 0xa4b2af31U, 0x3f23312aU, 0xa59430c6U, 0xa266c035U, + 0x4ebc3774U, 0x82caa6fcU, 0x90d0b0e0U, 0xa7d81533U, + 0x04984af1U, 0xecdaf741U, 0xcd500e7fU, 0x91f62f17U, + 0x4dd68d76U, 0xefb04d43U, 0xaa4d54ccU, 0x9604dfe4U, + 0xd1b5e39eU, 0x6a881b4cU, 0x2c1fb8c1U, 0x65517f46U, + 0x5eea049dU, 0x8c355d01U, 0x877473faU, 0x0b412efbU, + 0x671d5ab3U, 0xdbd25292U, 0x105633e9U, 0xd647136dU, + 0xd7618c9aU, 0xa10c7a37U, 0xf8148e59U, 0x133c89ebU, + 0xa927eeceU, 0x61c935b7U, 0x1ce5ede1U, 0x47b13c7aU, + 0xd2df599cU, 0xf2733f55U, 0x14ce7918U, 0xc737bf73U, + 0xf7cdea53U, 0xfdaa5b5fU, 0x3d6f14dfU, 0x44db8678U, + 0xaff381caU, 0x68c43eb9U, 0x24342c38U, 0xa3405fc2U, + 0x1dc37216U, 0xe2250cbcU, 0x3c498b28U, 0x0d9541ffU, + 0xa8017139U, 0x0cb3de08U, 0xb4e49cd8U, 0x56c19064U, + 0xcb84617bU, 0x32b670d5U, 0x6c5c7448U, 0xb85742d0U, +}; + +const TUint32 Td4[256] = { + 0x52525252U, 0x09090909U, 0x6a6a6a6aU, 0xd5d5d5d5U, + 0x30303030U, 0x36363636U, 0xa5a5a5a5U, 0x38383838U, + 0xbfbfbfbfU, 0x40404040U, 0xa3a3a3a3U, 0x9e9e9e9eU, + 0x81818181U, 0xf3f3f3f3U, 0xd7d7d7d7U, 0xfbfbfbfbU, + 0x7c7c7c7cU, 0xe3e3e3e3U, 0x39393939U, 0x82828282U, + 0x9b9b9b9bU, 0x2f2f2f2fU, 0xffffffffU, 0x87878787U, + 0x34343434U, 0x8e8e8e8eU, 0x43434343U, 0x44444444U, + 0xc4c4c4c4U, 0xdedededeU, 0xe9e9e9e9U, 0xcbcbcbcbU, + 0x54545454U, 0x7b7b7b7bU, 0x94949494U, 0x32323232U, + 0xa6a6a6a6U, 0xc2c2c2c2U, 0x23232323U, 0x3d3d3d3dU, + 0xeeeeeeeeU, 0x4c4c4c4cU, 0x95959595U, 0x0b0b0b0bU, + 0x42424242U, 0xfafafafaU, 0xc3c3c3c3U, 0x4e4e4e4eU, + 0x08080808U, 0x2e2e2e2eU, 0xa1a1a1a1U, 0x66666666U, + 0x28282828U, 0xd9d9d9d9U, 0x24242424U, 0xb2b2b2b2U, + 0x76767676U, 0x5b5b5b5bU, 0xa2a2a2a2U, 0x49494949U, + 0x6d6d6d6dU, 0x8b8b8b8bU, 0xd1d1d1d1U, 0x25252525U, + 0x72727272U, 0xf8f8f8f8U, 0xf6f6f6f6U, 0x64646464U, + 0x86868686U, 0x68686868U, 0x98989898U, 0x16161616U, + 0xd4d4d4d4U, 0xa4a4a4a4U, 0x5c5c5c5cU, 0xccccccccU, + 0x5d5d5d5dU, 0x65656565U, 0xb6b6b6b6U, 0x92929292U, + 0x6c6c6c6cU, 0x70707070U, 0x48484848U, 0x50505050U, + 0xfdfdfdfdU, 0xededededU, 0xb9b9b9b9U, 0xdadadadaU, + 0x5e5e5e5eU, 0x15151515U, 0x46464646U, 0x57575757U, + 0xa7a7a7a7U, 0x8d8d8d8dU, 0x9d9d9d9dU, 0x84848484U, + 0x90909090U, 0xd8d8d8d8U, 0xababababU, 0x00000000U, + 0x8c8c8c8cU, 0xbcbcbcbcU, 0xd3d3d3d3U, 0x0a0a0a0aU, + 0xf7f7f7f7U, 0xe4e4e4e4U, 0x58585858U, 0x05050505U, + 0xb8b8b8b8U, 0xb3b3b3b3U, 0x45454545U, 0x06060606U, + 0xd0d0d0d0U, 0x2c2c2c2cU, 0x1e1e1e1eU, 0x8f8f8f8fU, + 0xcacacacaU, 0x3f3f3f3fU, 0x0f0f0f0fU, 0x02020202U, + 0xc1c1c1c1U, 0xafafafafU, 0xbdbdbdbdU, 0x03030303U, + 0x01010101U, 0x13131313U, 0x8a8a8a8aU, 0x6b6b6b6bU, + 0x3a3a3a3aU, 0x91919191U, 0x11111111U, 0x41414141U, + 0x4f4f4f4fU, 0x67676767U, 0xdcdcdcdcU, 0xeaeaeaeaU, + 0x97979797U, 0xf2f2f2f2U, 0xcfcfcfcfU, 0xcecececeU, + 0xf0f0f0f0U, 0xb4b4b4b4U, 0xe6e6e6e6U, 0x73737373U, + 0x96969696U, 0xacacacacU, 0x74747474U, 0x22222222U, + 0xe7e7e7e7U, 0xadadadadU, 0x35353535U, 0x85858585U, + 0xe2e2e2e2U, 0xf9f9f9f9U, 0x37373737U, 0xe8e8e8e8U, + 0x1c1c1c1cU, 0x75757575U, 0xdfdfdfdfU, 0x6e6e6e6eU, + 0x47474747U, 0xf1f1f1f1U, 0x1a1a1a1aU, 0x71717171U, + 0x1d1d1d1dU, 0x29292929U, 0xc5c5c5c5U, 0x89898989U, + 0x6f6f6f6fU, 0xb7b7b7b7U, 0x62626262U, 0x0e0e0e0eU, + 0xaaaaaaaaU, 0x18181818U, 0xbebebebeU, 0x1b1b1b1bU, + 0xfcfcfcfcU, 0x56565656U, 0x3e3e3e3eU, 0x4b4b4b4bU, + 0xc6c6c6c6U, 0xd2d2d2d2U, 0x79797979U, 0x20202020U, + 0x9a9a9a9aU, 0xdbdbdbdbU, 0xc0c0c0c0U, 0xfefefefeU, + 0x78787878U, 0xcdcdcdcdU, 0x5a5a5a5aU, 0xf4f4f4f4U, + 0x1f1f1f1fU, 0xddddddddU, 0xa8a8a8a8U, 0x33333333U, + 0x88888888U, 0x07070707U, 0xc7c7c7c7U, 0x31313131U, + 0xb1b1b1b1U, 0x12121212U, 0x10101010U, 0x59595959U, + 0x27272727U, 0x80808080U, 0xececececU, 0x5f5f5f5fU, + 0x60606060U, 0x51515151U, 0x7f7f7f7fU, 0xa9a9a9a9U, + 0x19191919U, 0xb5b5b5b5U, 0x4a4a4a4aU, 0x0d0d0d0dU, + 0x2d2d2d2dU, 0xe5e5e5e5U, 0x7a7a7a7aU, 0x9f9f9f9fU, + 0x93939393U, 0xc9c9c9c9U, 0x9c9c9c9cU, 0xefefefefU, + 0xa0a0a0a0U, 0xe0e0e0e0U, 0x3b3b3b3bU, 0x4d4d4d4dU, + 0xaeaeaeaeU, 0x2a2a2a2aU, 0xf5f5f5f5U, 0xb0b0b0b0U, + 0xc8c8c8c8U, 0xebebebebU, 0xbbbbbbbbU, 0x3c3c3c3cU, + 0x83838383U, 0x53535353U, 0x99999999U, 0x61616161U, + 0x17171717U, 0x2b2b2b2bU, 0x04040404U, 0x7e7e7e7eU, + 0xbabababaU, 0x77777777U, 0xd6d6d6d6U, 0x26262626U, + 0xe1e1e1e1U, 0x69696969U, 0x14141414U, 0x63636363U, + 0x55555555U, 0x21212121U, 0x0c0c0c0cU, 0x7d7d7d7dU, +}; + +const TUint32 rcon[] = { + 0x01000000, 0x02000000, 0x04000000, 0x08000000, + 0x10000000, 0x20000000, 0x40000000, 0x80000000, + 0x1B000000, 0x36000000, /* for 128-bit blocks, Rijndael never uses more than 10 rcon values */ +}; + +} // namespace RIJNDAEL_TABLE +#endif // __RIJNDAELTABLES_H__ diff -r 7e3f204e6c81 -r f9c11be8c0b3 crypto/weakcryptospi/strong/bld.inf --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/crypto/weakcryptospi/strong/bld.inf Tue Dec 01 11:12:04 2009 +0000 @@ -0,0 +1,61 @@ +/* +* Copyright (c) 2003-2009 Nokia Corporation and/or its subsidiary(-ies). +* All rights reserved. +* This component and the accompanying materials are made available +* under the terms of the License "Eclipse Public License v1.0" +* which accompanies this distribution, and is available +* at the URL "http://www.eclipse.org/legal/epl-v10.html". +* +* Initial Contributors: +* Nokia Corporation - initial contribution. +* +* Contributors: +* +* Description: +* Builds strong cryptography +* +*/ + + +/** + @file +*/ + +PRJ_PLATFORMS +default + +PRJ_EXPORTS +../inc/bigint.h SYMBIAN_OS_LAYER_PUBLIC_EXPORT_PATH(bigint.h) +../inc/asymmetric.h SYMBIAN_OS_LAYER_PUBLIC_EXPORT_PATH(asymmetric.h) +../inc/asymmetric.inl SYMBIAN_OS_LAYER_PUBLIC_EXPORT_PATH(asymmetric.inl) +../inc/asymmetrickeys.h SYMBIAN_OS_LAYER_PUBLIC_EXPORT_PATH(asymmetrickeys.h) +../inc/padding.h SYMBIAN_OS_LAYER_PUBLIC_EXPORT_PATH(padding.h) +../inc/pbebase.h SYMBIAN_OS_LAYER_PLATFORM_EXPORT_PATH(pbebase.h) +../inc/pbe.h SYMBIAN_OS_LAYER_PLATFORM_EXPORT_PATH(pbe.h) +../inc/pbedata.h SYMBIAN_OS_LAYER_PLATFORM_EXPORT_PATH(pbedata.h) +../inc/3des.h SYMBIAN_OS_LAYER_PLATFORM_EXPORT_PATH(3des.h) +../inc/arc4.h SYMBIAN_OS_LAYER_PLATFORM_EXPORT_PATH(arc4.h) +../inc/blocktransformation.h SYMBIAN_OS_LAYER_PLATFORM_EXPORT_PATH(blocktransformation.h) +../inc/bufferedtransformation.h SYMBIAN_OS_LAYER_PLATFORM_EXPORT_PATH(bufferedtransformation.h) +../inc/cbcmode.h SYMBIAN_OS_LAYER_PLATFORM_EXPORT_PATH(cbcmode.h) +../inc/des.h SYMBIAN_OS_LAYER_PLATFORM_EXPORT_PATH(des.h) +../inc/nullcipher.h SYMBIAN_OS_LAYER_PLATFORM_EXPORT_PATH(nullcipher.h) +../inc/rc2.h SYMBIAN_OS_LAYER_PLATFORM_EXPORT_PATH(rc2.h) +../inc/rijndael.h SYMBIAN_OS_LAYER_PLATFORM_EXPORT_PATH(rijndael.h) +../inc/streamcipher.h SYMBIAN_OS_LAYER_PLATFORM_EXPORT_PATH(streamcipher.h) +../inc/symmetric.h SYMBIAN_OS_LAYER_PLATFORM_EXPORT_PATH(symmetric.h) +../inc/msymmetriccipher.h SYMBIAN_OS_LAYER_PLATFORM_EXPORT_PATH(msymmetriccipher.h) +../inc/mode.h SYMBIAN_OS_LAYER_PLATFORM_EXPORT_PATH(mode.h) +../inc/cryptostrength.h SYMBIAN_OS_LAYER_PLATFORM_EXPORT_PATH(cryptostrength.h) +../inc/pbencryptor.h SYMBIAN_OS_LAYER_PLATFORM_EXPORT_PATH(pbencryptor.h) + +#ifndef TOOLS // Don't build anything for tools +#ifndef TOOLS2 // Don't build anything for tools2 + +PRJ_MMPFILES +#ifndef MARM_THUMB +strong_crypto.mmp BUILD_AS_ARM // Don't build for thumb +#endif + +#endif // TOOLS2 +#endif // TOOLS diff -r 7e3f204e6c81 -r f9c11be8c0b3 crypto/weakcryptospi/strong/strong_crypto.mmp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/crypto/weakcryptospi/strong/strong_crypto.mmp Tue Dec 01 11:12:04 2009 +0000 @@ -0,0 +1,33 @@ +/* +* Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies). +* All rights reserved. +* This component and the accompanying materials are made available +* under the terms of the License "Eclipse Public License v1.0" +* which accompanies this distribution, and is available +* at the URL "http://www.eclipse.org/legal/epl-v10.html". +* +* Initial Contributors: +* Nokia Corporation - initial contribution. +* +* Contributors: +* +* Description: +* +*/ + +/** +@file + +@SYMPurpose strong_cryptography.dll Implements strong cryptography. +*/ + +// Export-restricted version of cryptography.dll + +TARGET strong_cryptography.dll +MACRO CRYPTO_STRONG_BUILD +UNPAGED + +#include "../group/crypto.mmh" + +VENDORID 0x70000001 +SMPSAFE diff -r 7e3f204e6c81 -r f9c11be8c0b3 crypto/weakcryptospi/test/kms/driver/product/kmskext/kmskext.cpp --- a/crypto/weakcryptospi/test/kms/driver/product/kmskext/kmskext.cpp Thu Nov 12 16:07:39 2009 +0000 +++ b/crypto/weakcryptospi/test/kms/driver/product/kmskext/kmskext.cpp Tue Dec 01 11:12:04 2009 +0000 @@ -23,6 +23,7 @@ #include #include "kmskext.h" +#include // singleton keystore instance XKeyStore KeyStore; diff -r 7e3f204e6c81 -r f9c11be8c0b3 crypto/weakcryptospi/test/kms/private_include/test/kmslddtest.h --- a/crypto/weakcryptospi/test/kms/private_include/test/kmslddtest.h Thu Nov 12 16:07:39 2009 +0000 +++ b/crypto/weakcryptospi/test/kms/private_include/test/kmslddtest.h Tue Dec 01 11:12:04 2009 +0000 @@ -28,6 +28,7 @@ #include #include +#include #include "kmsldd.h" #include "kmsextrldd.h" diff -r 7e3f204e6c81 -r f9c11be8c0b3 crypto/weakcryptospi/test/kms/server/test/kmstest/kmstest.cpp --- a/crypto/weakcryptospi/test/kms/server/test/kmstest/kmstest.cpp Thu Nov 12 16:07:39 2009 +0000 +++ b/crypto/weakcryptospi/test/kms/server/test/kmstest/kmstest.cpp Tue Dec 01 11:12:04 2009 +0000 @@ -25,6 +25,7 @@ #include #include "kmsclient.h" #include "kmsservercommon.h" +#include #include "kmstest.h" diff -r 7e3f204e6c81 -r f9c11be8c0b3 cryptomgmtlibs/cryptotokenfw/group/bld.inf --- a/cryptomgmtlibs/cryptotokenfw/group/bld.inf Thu Nov 12 16:07:39 2009 +0000 +++ b/cryptomgmtlibs/cryptotokenfw/group/bld.inf Tue Dec 01 11:12:04 2009 +0000 @@ -38,7 +38,7 @@ ../inc/ct/TCTTokenTypeAttribute.h SYMBIAN_OS_LAYER_PLATFORM_EXPORT_PATH(ct/tcttokentypeattribute.h) ../inc/ct/TCTFindTokenTypesByInterface.h SYMBIAN_OS_LAYER_PLATFORM_EXPORT_PATH(ct/tctfindtokentypesbyinterface.h) ../inc/ct/TCTFindTokenTypesByInterfaceAndAttribute.h SYMBIAN_OS_LAYER_PLATFORM_EXPORT_PATH(ct/tctfindtokentypesbyinterfaceandattribute.h) -../inc/ct/InterfaceUID.hrh SYMBIAN_OS_LAYER_PLATFORM_EXPORT_PATH(ct/interfaceuid.hrh) +../inc/ct/InterfaceUID.hrh /epoc32/include/ct/interfaceuid.hrh ../inc/CryptoTokenRegistryInfo.rh SYMBIAN_OS_LAYER_PLATFORM_EXPORT_PATH(cryptotokenregistryinfo.rh) ../inc/ct/tcttokenhandle.h SYMBIAN_OS_LAYER_PUBLIC_EXPORT_PATH(ct/tcttokenhandle.h) ../inc/ct/RCPointerArray.h SYMBIAN_OS_LAYER_PUBLIC_EXPORT_PATH(ct/rcpointerarray.h) diff -r 7e3f204e6c81 -r f9c11be8c0b3 cryptomgmtlibs/securitycommonutils/test/source/scstest/scstest.cpp --- a/cryptomgmtlibs/securitycommonutils/test/source/scstest/scstest.cpp Thu Nov 12 16:07:39 2009 +0000 +++ b/cryptomgmtlibs/securitycommonutils/test/source/scstest/scstest.cpp Tue Dec 01 11:12:04 2009 +0000 @@ -22,9 +22,11 @@ @file */ + #include #include #include "rtestwrapper.h" +#include #include #include "scstestcommon.h" diff -r 7e3f204e6c81 -r f9c11be8c0b3 cryptomgmtlibs/securitytestfw/group/bld.inf --- a/cryptomgmtlibs/securitytestfw/group/bld.inf Thu Nov 12 16:07:39 2009 +0000 +++ b/cryptomgmtlibs/securitytestfw/group/bld.inf Tue Dec 01 11:12:04 2009 +0000 @@ -76,6 +76,7 @@ ../test/autotesting/testsecurity_9.4_mcs_vfuture.bat /epoc32/winscw/c/autohardware/testsecurity_9.4_mcs_vfuture.bat ../test/autotesting/testsecurity_9.4_nonmcs.bat /epoc32/winscw/c/autohardware/testsecurity_9.4_nonmcs.bat ../test/autotesting/runcertman_9.5.bat /epoc32/winscw/c/autohardware/runcertman_9.5.bat + ../test/autotesting/testsecurity_9.5_mcs.bat /epoc32/winscw/c/autohardware/testsecurity_9.5_mcs.bat ../test/autotesting/testsecurity_9.6_mcs.bat /epoc32/winscw/c/autohardware/testsecurity_9.6_mcs.bat ../test/autotesting/testsecurity_9.5_nonmcs.bat /epoc32/winscw/c/autohardware/testsecurity_9.5_nonmcs.bat diff -r 7e3f204e6c81 -r f9c11be8c0b3 cryptomgmtlibs/securitytestfw/inc/captestframework.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/cryptomgmtlibs/securitytestfw/inc/captestframework.h Tue Dec 01 11:12:04 2009 +0000 @@ -0,0 +1,77 @@ +/* +* Copyright (c) 2005-2009 Nokia Corporation and/or its subsidiary(-ies). +* All rights reserved. +* This component and the accompanying materials are made available +* under the terms of the License "Eclipse Public License v1.0" +* which accompanies this distribution, and is available +* at the URL "http://www.eclipse.org/legal/epl-v10.html". +* +* Initial Contributors: +* Nokia Corporation - initial contribution. +* +* Contributors: +* +* Description: +* +*/ + + + + +/** + @file +*/ + +#ifndef CAPTESTFRAMEWORK_H__ +#define CAPTESTFRAMEWORK_H__ + +// Used to transfer data to the helper +const TInt KDllNameTransferSlot=5; +const TInt KShouldPassTransferSlot=6; +const TInt KTestNumberTransferSlot=7; +const TInt KLogFileTransferSlot=8; +const TInt KFileSessionTransferSlot=9; +const TInt KLogFileNameTransferSlot=10; + + +// markers for the file used to transfer the results + +enum TFileMarker + { + ETestPassed, + ETestFailed, + ETestsEnded, + EFileEnd, + }; + + +class RFile; + +// classes to be implemented by the actaul test dll. +class MCapabilityTest + { +public: + virtual const TDesC& Name() const=0; + virtual const TDesC& SubName() const=0; + + virtual TCapabilitySet CapabilitiesRequired() const=0; + virtual TUid VidRequired() const=0; + virtual TUid SidRequired() const=0; + + virtual void RunTestL(RFile& aLogFile)=0; + virtual void SetExpectPermissionDenied(TBool aExpectPermissionDenied)=0; + virtual ~MCapabilityTest() {}; + }; + +class MCapabilityTestFactory + { +public: + virtual TInt NumberOfTests()=0; + virtual MCapabilityTest* Test(TInt aTestNumber)=0; + virtual ~MCapabilityTestFactory() {}; + }; + + + + +#endif // #ifndef CAPTESTFRAMEWORK_H__ diff -r 7e3f204e6c81 -r f9c11be8c0b3 cryptomgmtlibs/securitytestfw/inc/captestutility.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/cryptomgmtlibs/securitytestfw/inc/captestutility.h Tue Dec 01 11:12:04 2009 +0000 @@ -0,0 +1,95 @@ +/* +* Copyright (c) 2005-2009 Nokia Corporation and/or its subsidiary(-ies). +* All rights reserved. +* This component and the accompanying materials are made available +* under the terms of the License "Eclipse Public License v1.0" +* which accompanies this distribution, and is available +* at the URL "http://www.eclipse.org/legal/epl-v10.html". +* +* Initial Contributors: +* Nokia Corporation - initial contribution. +* +* Contributors: +* +* Description: +* Implements default base classes for captestframework +* +*/ + + + + +/** + @file +*/ + +#ifndef CAPTESTUTILITY_H__ +#define CAPTESTUTILITY_H__ + +#include +#include +#include + +// CDefaultCapabilityTest +class CDefaultCapabilityTest : public CBase, public MCapabilityTest + { +public: + IMPORT_C const TDesC& Name() const; + IMPORT_C const TDesC& SubName() const; + + IMPORT_C TCapabilitySet CapabilitiesRequired() const; + IMPORT_C TUid VidRequired() const; + IMPORT_C TUid SidRequired() const; + + IMPORT_C ~CDefaultCapabilityTest(); + +protected: + IMPORT_C void SetNameL(const TDesC& aName); + void SetExpectPermissionDenied(TBool aExpectPermissionDenied = ETrue); + + IMPORT_C void SetCapabilityRequired(const TCapability& aCapability); + IMPORT_C void SetSidRequired(const TUid& aSid); + IMPORT_C void SetVidRequired(const TUid& aVid); + + IMPORT_C TInt CheckFailL(TInt aResult, const TDesC& aTestName); + IMPORT_C void RunTestL(RFile& aLogFile); + + void SetFail() { iFail = ETrue;} + virtual void RunTestL() =0; +private: + HBufC* iTestName; + HBufC* iTestSubName; + + RFile* iLogFile; + RFileWriteStream* iLogWriteStream; + TBool iExpectPermissionDenied; + TCapabilitySet iCapabilitySet; + TUid iVidRequired; + TUid iSidRequired; + TBool iFail; + }; + +// CDefaultCapabilityTestFactory +class CDefaultCapabilityTestFactory : public CBase, public MCapabilityTestFactory + + { +public: + IMPORT_C virtual TInt NumberOfTests(); + IMPORT_C virtual MCapabilityTest* Test(TInt aTestNumber); + + IMPORT_C void AddTestL(CDefaultCapabilityTest* aTest); + + IMPORT_C ~CDefaultCapabilityTestFactory(); + +private: + RPointerArray iTests; + }; + +// inline functions from CSwiCapabilityTest + +inline void CDefaultCapabilityTest::SetExpectPermissionDenied(TBool aExpectPermissionDenied) + { + iExpectPermissionDenied = aExpectPermissionDenied; + } + +#endif //#ifndef CAPTESTUTILITY_H__ diff -r 7e3f204e6c81 -r f9c11be8c0b3 cryptomgmtlibs/securitytestfw/test/autotesting/runcertman_9.5.bat --- a/cryptomgmtlibs/securitytestfw/test/autotesting/runcertman_9.5.bat Thu Nov 12 16:07:39 2009 +0000 +++ b/cryptomgmtlibs/securitytestfw/test/autotesting/runcertman_9.5.bat Tue Dec 01 11:12:04 2009 +0000 @@ -30,6 +30,13 @@ copy z:\tcertstore\data\TestKeyStore.txt c:\system\data\testkeystore.txt del c:\system\data\cacerts.dat +del c:\system\data\certclients.dat +t_certstore c:\tcertstore\scripts\t_certstore_sha2.txt c:\testresults\t_certstore_sha2.txt +move c:\testresults\t_certstore_sha2.txt e:\testresults\t_certstore_sha2.txt + +t_certstore c:\tcertstore\scripts\t_certstore_sha2.script c:\testresults\t_certstore_sha2.htm +move c:\testresults\t_certstore_sha2.htm e:\testresults\t_certstore_sha2.htm + rem run tcertstore tests t_certstore c:\tcertstore\scripts\unifiedcertstore1-conf1.script c:\logs\testexecute\unifiedcertstore1-conf1.htm move c:\logs\testexecute\unifiedcertstore1-conf1.htm e:\testresults\unifiedcertstore1-conf1.htm diff -r 7e3f204e6c81 -r f9c11be8c0b3 cryptomgmtlibs/securitytestfw/test/autotesting/test_spec_sdp_9.5.txt --- a/cryptomgmtlibs/securitytestfw/test/autotesting/test_spec_sdp_9.5.txt Thu Nov 12 16:07:39 2009 +0000 +++ b/cryptomgmtlibs/securitytestfw/test/autotesting/test_spec_sdp_9.5.txt Tue Dec 01 11:12:04 2009 +0000 @@ -233,11 +233,16 @@ tocsp, \logs\testexecute\tocsp_httpinterface.htm,, -Dtextshell -- \system\tocsp\scripts\httpinterface.script \logs\testexecute\tocsp_httpinterface.htm, 300, UREL, \epoc32\winscw\c\tcertstore\scripts\batchfiles\pre_tocsp_backup.bat, \epoc32\winscw\c\tcertstore\scripts\batchfiles\post_httpinterface_restore.bat tocsp, \logs\testexecute\tocsp_logoom.htm,, -Dtextshell -- \system\tocsp\scripts\xcert-oom.script \logs\testexecute\tocsp_logoom.htm, 900, UDEB#UREL, \epoc32\winscw\c\tcertstore\scripts\batchfiles\pre_tocsp_backup.bat, \epoc32\winscw\c\tcertstore\scripts\batchfiles\post_tocsp_restore.bat + # TMS SUPPORT t_certstore, \logs\testexecute\tcertstore_conf1.1.htm,, -Dtextshell -- \tcertstore\scripts\unifiedcertstore1-conf1.script \logs\testexecute\tcertstore_conf1.1.htm, 300, UDEB#UREL, \epoc32\winscw\c\twtlscert\scripts\batchfiles\precert_backup.bat, \epoc32\winscw\c\twtlscert\scripts\batchfiles\postcert_restore.bat t_certstore, \logs\testexecute\tcertstore_conf1.2.htm,, -Dtextshell -- \tcertstore\scripts\unifiedcertstore2-conf1.script \logs\testexecute\tcertstore_conf1.2.htm, 300, UDEB#UREL, \epoc32\winscw\c\twtlscert\scripts\batchfiles\precert_backup.bat, \epoc32\winscw\c\twtlscert\scripts\batchfiles\postcert_restore.bat t_certstore, \logs\testexecute\tcertstore_conf1.3.htm,, -Dtextshell -- \tcertstore\scripts\unifiedcertstore3-conf1.script \logs\testexecute\tcertstore_conf1.3.htm, 300, UDEB#UREL, \epoc32\winscw\c\twtlscert\scripts\batchfiles\precert_backup.bat, \epoc32\winscw\c\twtlscert\scripts\batchfiles\postcert_restore.bat t_certstore, \logs\testexecute\t_handle_1.htm,, -Dtextshell -- \tcertstore\scripts\t_handle_1.script \logs\testexecute\t_handle_1.htm, 300, UDEB#UREL, \epoc32\winscw\c\twtlscert\scripts\batchfiles\precert_backup.bat, \epoc32\winscw\c\twtlscert\scripts\batchfiles\postcert_restore.bat +//As of now, not in TMS format. Should be changed to TEF. +t_certstore, \t_certstore_sha2.txt,, -Dtextshell -- \tcertstore\scripts\t_certstore_sha2.txt \t_certstore_sha2.txt, 300, UDEB#UREL, \epoc32\winscw\c\twtlscert\scripts\batchfiles\precert_backup.bat, \epoc32\winscw\c\twtlscert\scripts\batchfiles\postcert_restore.bat +//TEF Format +t_certstore, \logs\testexecute\t_certstore_sha2.htm,, -Dtextshell -- \tcertstore\scripts\t_certstore_sha2.script \logs\testexecute\t_certstore_sha2.htm, 300, UDEB#UREL, \epoc32\winscw\c\twtlscert\scripts\batchfiles\precert_backup.bat, \epoc32\winscw\c\twtlscert\scripts\batchfiles\postcert_restore.bat # TMS SUPPORT t_certstore, \logs\testexecute\tcertstore_oom.conf1.1.htm,, -Dtextshell -- \tcertstore\scripts\oom1.script \logs\testexecute\tcertstore_oom.conf1.1.htm, 300, UDEB#UREL, \epoc32\winscw\c\twtlscert\scripts\batchfiles\precert_backup.bat, \epoc32\winscw\c\twtlscert\scripts\batchfiles\postcert_restore.bat @@ -346,7 +351,6 @@ ######### Composite Certstore Testing################################################################################### - [SWI] # Requires the following additional components to be built: SisTools, Certman diff -r 7e3f204e6c81 -r f9c11be8c0b3 cryptoplugins/cryptospiplugins/source/softwarecrypto/3desimpl.cpp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/cryptoplugins/cryptospiplugins/source/softwarecrypto/3desimpl.cpp Tue Dec 01 11:12:04 2009 +0000 @@ -0,0 +1,190 @@ +/* +* Copyright (c) 2006-2009 Nokia Corporation and/or its subsidiary(-ies). +* All rights reserved. +* This component and the accompanying materials are made available +* under the terms of the License "Eclipse Public License v1.0" +* which accompanies this distribution, and is available +* at the URL "http://www.eclipse.org/legal/epl-v10.html". +* +* Initial Contributors: +* Nokia Corporation - initial contribution. +* +* Contributors: +* +* Description: +* +*/ + + +#include "3desimpl.h" + +#include "destables.h" +#include "common/inlines.h" +#include "des.inl" +#include "pluginconfig.h" +#include "symmetriccipherimpl.h" +#include + +using namespace SoftwareCrypto; + +/* C3DesImpl */ +C3DesImpl::C3DesImpl( + TUid aCryptoMode, + TUid aOperationMode, + TUid aPadding) : + CDesImpl(KDesBlockBytes, aCryptoMode, aOperationMode, aPadding) + { + } + +C3DesImpl* C3DesImpl::NewL(const CKey& aKey, TUid aCryptoMode, TUid aOperationMode, TUid aPadding) + { + C3DesImpl* self = C3DesImpl::NewLC(aKey, aCryptoMode, aOperationMode, aPadding); + CleanupStack::Pop(self); + return self; + } + +C3DesImpl* C3DesImpl::NewLC(const CKey& aKey, TUid aCryptoMode, TUid aOperationMode, TUid aPadding) + { + C3DesImpl* self = new(ELeave) C3DesImpl(aCryptoMode, aOperationMode, aPadding); + CleanupStack::PushL(self); + self->ConstructL(aKey); + + const TDesC8& keyContent = aKey.GetTDesC8L(KSymmetricKeyParameterUid); + TCrypto::IsSymmetricWeakEnoughL(BytesToBits(keyContent.Size()) - keyContent.Size()); + return self; + } + +C3DesImpl::~C3DesImpl() + { + // make sure key information isn't visible to other processes if the + // page is reused. + Mem::FillZ(&iK1, sizeof(iK1)); + Mem::FillZ(&iK2, sizeof(iK2)); + Mem::FillZ(&iK3, sizeof(iK3)); + } + +void C3DesImpl::ConstructL(const CKey& aKey) + { + CDesImpl::ConstructL(aKey); + SetKeySchedule(); + } + +CExtendedCharacteristics* C3DesImpl::CreateExtendedCharacteristicsL() + { + // All Symbian software plug-ins have unlimited concurrency, cannot be reserved + // for exclusive use and are not CERTIFIED to be standards compliant. + return CExtendedCharacteristics::NewL(KMaxTInt, EFalse); + } + +const CExtendedCharacteristics* C3DesImpl::GetExtendedCharacteristicsL() + { + return C3DesImpl::CreateExtendedCharacteristicsL(); + } + +TUid C3DesImpl::ImplementationUid() const + { + return KCryptoPlugin3DesUid; + } + +TBool C3DesImpl::IsValidKeyLength(TInt aKeyBytes) const + { + return (aKeyBytes == K3DesKeyBytes); + } + +TInt C3DesImpl::GetKeyStrength() const + { + // Exclude parity bits from each subkey + return BytesToBits(K3DesKeyBytes - (3 * 8)); + } + +void C3DesImpl::TransformEncrypt( + TUint8* aBuffer, + TUint aNumBlocks) + { + for (TInt i = 0; i < aNumBlocks; ++i) + { + ModeEncryptStart(aBuffer); + + TUint32 l, r; + // Split the block into 2 word-sized big endian portions + GetBlockBigEndian(aBuffer, l, r); + + IPerm(l,r); + // The mode is applied to the entire operation and NOT + // for each DES transform + TUid opMode = iOperationMode; + iOperationMode = KOperationModeECBUid; + DoTransform(l, r, iK1); + DoTransform(r, l, iK2); + DoTransform(l, r, iK3); + iOperationMode = opMode; + FPerm(l,r); + + // Put the portions back into the block as little endian + PutBlockBigEndian(aBuffer, r, l); + ModeEncryptEnd(aBuffer); + aBuffer += KDesBlockBytes; + } + } + +void C3DesImpl::TransformDecrypt( + TUint8* aBuffer, + const TUint aNumBlocks) + { + for (TInt i = 0; i < aNumBlocks; ++i) + { + ModeDecryptStart(aBuffer); + + TUint32 l, r; + // Split the block into 2 word-sized big endian portions + GetBlockBigEndian(aBuffer, l, r); + + IPerm(l,r); + + // The mode is applied to the entire operation and NOT + // for each DES transform + TUid opMode = iOperationMode; + iOperationMode = KOperationModeECBUid; + DoTransform(l, r, iK1); + DoTransform(r, l, iK2); + DoTransform(l, r, iK3); + iOperationMode = opMode; + FPerm(l,r); + + // Put the portions back into the block as little endian + PutBlockBigEndian(aBuffer, r, l); + ModeDecryptEnd(aBuffer); + aBuffer += K3DesBlockBytes; + } + } + +void C3DesImpl::SetKeySchedule() + { + if (iCryptoMode.iUid == KCryptoModeEncrypt) + { + // Encrypt -> Decrypt -> Encrypt + // Encryptor key + SetEncryptKeySchedule(iKey->Mid(0, KDesKeyBytes), iK1); + + // Decryptor key + SetDecryptKeySchedule(iKey->Mid(KDesKeyBytes, 2 * KDesKeyBytes), iK2); + + // Encryptor key + SetEncryptKeySchedule(iKey->Mid(2 * KDesKeyBytes), iK3); + } + else + { + // Decrypt -> Encrypt -> Decrypt + // Key order is reversed ! + + ASSERT(iCryptoMode.iUid == KCryptoModeDecrypt); + // Decryptor key + SetDecryptKeySchedule(iKey->Mid(0, KDesKeyBytes), iK3); + + // Encryptor key + SetEncryptKeySchedule(iKey->Mid(KDesKeyBytes, 2 * KDesKeyBytes), iK2); + + // Decryptor key + SetDecryptKeySchedule(iKey->Mid(2 * KDesKeyBytes), iK1); + } + } diff -r 7e3f204e6c81 -r f9c11be8c0b3 cryptoplugins/cryptospiplugins/source/softwarecrypto/3desimpl.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/cryptoplugins/cryptospiplugins/source/softwarecrypto/3desimpl.h Tue Dec 01 11:12:04 2009 +0000 @@ -0,0 +1,113 @@ +/* +* Copyright (c) 2006-2009 Nokia Corporation and/or its subsidiary(-ies). +* All rights reserved. +* This component and the accompanying materials are made available +* under the terms of the License "Eclipse Public License v1.0" +* which accompanies this distribution, and is available +* at the URL "http://www.eclipse.org/legal/epl-v10.html". +* +* Initial Contributors: +* Nokia Corporation - initial contribution. +* +* Contributors: +* +* Description: +* +*/ + + +#ifndef __3DESIMPL_H__ +#define __3DESIMPL_H__ + +/** +@file +@internalComponent +@released +*/ + +#include +#include +#include "keys.h" +#include "desimpl.h" + +/** +Plug-in class for 3DES block cipher +*/ +namespace SoftwareCrypto + { + using namespace CryptoSpi; + + NONSHARABLE_CLASS(C3DesImpl) : public CDesImpl + { + public: + /** + Creates an instance of a 3DES (Data Encryption Standard) symmetric cipher plug-in. + @param aKey The key + @param aCryptoMode Whether to encrypt or decrypt + @param aOperationMode The block cipher mode ECB, CBC, CTR etc + @param aPadding The padding scheme to use None, SSLv3, PKCS#7 + @return A pointer to a C3DesImpl instance + */ + static C3DesImpl* NewL(const CKey& aKey, + TUid aCryptoMode, TUid aOperationMode, TUid aPadding); + + /** + Creates an instance of a 3DES (Data Encryption Standard) symmetric cipher plug-in. + A pointer to the plug-in instance is placed on the cleanup stack. + @param aKey The key + @param aCryptoMode Whether to encrypt or decrypt + @param aOperationMode The block cipher mode ECB, CBC, CTR etc + @param aPadding The padding scheme to use None, SSLv3, PKCS#7 + @return A pointer to a C3DesImpl instance + */ + static C3DesImpl* NewLC(const CKey& aKey, + TUid aCryptoMode, TUid aOperationMode, TUid aPadding); + + // From CSymmetricCipherImpl + TBool IsValidKeyLength(TInt aKeyBytes) const; + TInt GetKeyStrength() const; + TUid ImplementationUid() const; + const CExtendedCharacteristics* GetExtendedCharacteristicsL(); + + static CExtendedCharacteristics* CreateExtendedCharacteristicsL(); + + /// 3Destructor + ~C3DesImpl(); + + private: + /** + Constructor + @param aOperationMode The mode of operation e.g. CBC + @param aCryptoMode Whether to encrypt or decrypt + @param aPaddingMode The padding mode to use. None, SSL, PKCS#7 + */ + C3DesImpl(TUid aOperationMode, TUid aCryptoMode, TUid aPaddingMode); + + /// second phase of construction + void ConstructL(const CKey& aKey); + + /** + Creates the key schedules iK1, iK2, iK3 from CBlockTransformationImpl::iKey. + This should be called from ConstructL and Reset + */ + void SetKeySchedule(); + + // From CSymmetricBlockCipherImpl + void TransformEncrypt(TUint8* aBuffer, TUint aNumBlocks); + void TransformDecrypt(TUint8* aBuffer, TUint aNumBlocks); + + private: + /// Size of the key schedule in words + static const TUint KKeyScheduleSize = 32; + + /// the key schedules + TUint32 iK1[KKeyScheduleSize]; + TUint32 iK2[KKeyScheduleSize]; + TUint32 iK3[KKeyScheduleSize]; + + static const TUint8 K3DesBlockBytes = 8; + static const TUint8 K3DesKeyBytes = 24; + }; + } + +#endif // __3DESIMPL_H__ diff -r 7e3f204e6c81 -r f9c11be8c0b3 cryptoplugins/cryptospiplugins/source/softwarecrypto/arc4impl.cpp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/cryptoplugins/cryptospiplugins/source/softwarecrypto/arc4impl.cpp Tue Dec 01 11:12:04 2009 +0000 @@ -0,0 +1,153 @@ +/* +* Copyright (c) 2006-2009 Nokia Corporation and/or its subsidiary(-ies). +* All rights reserved. +* This component and the accompanying materials are made available +* under the terms of the License "Eclipse Public License v1.0" +* which accompanies this distribution, and is available +* at the URL "http://www.eclipse.org/legal/epl-v10.html". +* +* Initial Contributors: +* Nokia Corporation - initial contribution. +* +* Contributors: +* +* Description: +* +*/ + + +#include "arc4impl.h" +#include "keys.h" +#include "pluginconfig.h" +#include "symmetriccipherimpl.h" +#include +#include "common/inlines.h" + + +using namespace SoftwareCrypto; + +CArc4Impl* CArc4Impl::NewL(const CKey& aKey, TInt aDiscardBytes) + { + CArc4Impl* self = CArc4Impl::NewLC(aKey, aDiscardBytes); + CleanupStack::Pop(self); + return self; + } + +CArc4Impl* CArc4Impl::NewLC(const CKey& aKey, TInt aDiscardBytes) + { + CArc4Impl* self = new(ELeave) CArc4Impl(aDiscardBytes); + CleanupStack::PushL(self); + self->ConstructL(aKey); + + const TDesC8& keyContent = aKey.GetTDesC8L(KSymmetricKeyParameterUid); + TCrypto::IsSymmetricWeakEnoughL(BytesToBits(keyContent.Size()) - keyContent.Size()); + + return self; + } + +CArc4Impl::CArc4Impl(TInt aDiscardBytes) +:ix(1), iy(0), iDiscardBytes(aDiscardBytes) + { + } + +CArc4Impl::~CArc4Impl() + { + } + +void CArc4Impl::ConstructL(const CKey& aKey) + { + CSymmetricStreamCipherImpl::ConstructL(aKey); + GenerateSBox(); + } + +CExtendedCharacteristics* CArc4Impl::CreateExtendedCharacteristicsL() + { + // All Symbian software plug-ins have unlimited concurrency, cannot be reserved + // for exclusive use and are not CERTIFIED to be standards compliant. + return CExtendedCharacteristics::NewL(KMaxTInt, EFalse); + } + +const CExtendedCharacteristics* CArc4Impl::GetExtendedCharacteristicsL() + { + return CArc4Impl::CreateExtendedCharacteristicsL(); + } + +void CArc4Impl::DoProcess(TDes8& aData) + { + TInt blockLen = aData.Size(); + + if (blockLen > 0) + { + TUint8* blockPtr = (TUint8*)&aData[0]; + do + { + *blockPtr++ ^= GenerateByte(); + } + while (--blockLen); + } + } + +TBool CArc4Impl::IsValidKeyLength(TInt aKeyBytes) const + { + return ((aKeyBytes > 0 && aKeyBytes <= KMaxARC4KeyBytes) ? ETrue : EFalse); + } + +void CArc4Impl::Reset() + { + ix = 1; + iy = 0; + GenerateSBox(); + } + +TUid CArc4Impl::ImplementationUid() const + { + return KCryptoPluginArc4Uid; + } + +TUint8 CArc4Impl::GenerateByte() + { + TUint8 a = iState[ix]; + iy = (TUint8)((iy + a) & 0xff); + TUint8 b = iState[iy]; + + iState[ix] = b; + iState[iy] = a; + ix = (TUint8)((ix + 1) & 0xff); + return (iState[(a + b) & 0xff]); + } + +void CArc4Impl::DiscardBytes(TInt aDiscardBytes) + { + if (aDiscardBytes > 0) + { + do + { + GenerateByte(); + } + while(--aDiscardBytes); + } + } + +void CArc4Impl::GenerateSBox(void) + { + TUint keyBytes = iKey->Size(); + + TInt i = 0; + for (; i < KSBoxSize; i++) + iState[i] = (TUint8)i; + + TUint keyIndex = 0, stateIndex = 0; + i = 0; + for (; i < KSBoxSize; i++) + { + TUint a = iState[i]; + stateIndex += (*iKey)[keyIndex] + a; + stateIndex &= 0xff; + iState[i] = iState[stateIndex]; + iState[stateIndex] = (TUint8)a; + if (++keyIndex >= (TUint)keyBytes) + keyIndex = 0; + } + + DiscardBytes(iDiscardBytes); + } diff -r 7e3f204e6c81 -r f9c11be8c0b3 cryptoplugins/cryptospiplugins/source/softwarecrypto/arc4impl.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/cryptoplugins/cryptospiplugins/source/softwarecrypto/arc4impl.h Tue Dec 01 11:12:04 2009 +0000 @@ -0,0 +1,117 @@ +/* +* Copyright (c) 2006-2009 Nokia Corporation and/or its subsidiary(-ies). +* All rights reserved. +* This component and the accompanying materials are made available +* under the terms of the License "Eclipse Public License v1.0" +* which accompanies this distribution, and is available +* at the URL "http://www.eclipse.org/legal/epl-v10.html". +* +* Initial Contributors: +* Nokia Corporation - initial contribution. +* +* Contributors: +* +* Description: +* +*/ + + +#ifndef ARC4IMPL_H +#define ARC4IMPL_H + +/** +@file +@internalComponent +@released +*/ + +#include "symmetriccipherimpl.h" +#include +#include +#include "keys.h" + + +/** +Plug-in class for ARC4 stream cipher +*/ +namespace SoftwareCrypto + { + using namespace CryptoSpi; + + NONSHARABLE_CLASS(CArc4Impl) : public CSymmetricStreamCipherImpl + { + public: + + /** + Number of bytes to discard by default from an ARC4 key stream. + */ + static const TUint KDefaultDiscardBytes = 768; + + /** + The size of the substitution box (i.e. lookup table) in bytes. + */ + static const TInt KSBoxSize = 256; + + /** + Maximum ARC4 key size in bytes.2048 bits + */ + static const TInt KMaxARC4KeyBytes = 256; + + /** + Creates an instance of an ARC4 symmetric cipher plug-in. + @param aKey The key + @param aDiscardBytes The number of bytes to drop from + the beginning of the key stream. + @return A pointer to a CArc4Impl instance + */ + static CArc4Impl* NewL(const CKey& aKey, TInt aDiscardBytes); + + /** + Creates an instance of an ARC4 symmetric cipher plug-in, + and leave it on the cleanup stack + @param aKey The key + @param aDiscardBytes The number of bytes to drop from + the beginning of the key stream. + @return A pointer to a CArc4Impl instance + */ + static CArc4Impl* NewLC(const CKey& aKey, TInt aDiscardBytes); + + //Destructor + ~CArc4Impl(); + + //Override MPlugin virtual function + void Reset(); + + //Override CSymmetricCipherImpl virtual functions + TUid ImplementationUid() const; + TBool IsValidKeyLength(TInt aKeyBytes) const; + const CExtendedCharacteristics* GetExtendedCharacteristicsL(); + + static CExtendedCharacteristics* CreateExtendedCharacteristicsL(); + + private: + //Constructor + CArc4Impl(TInt aDiscardBytes); + + //second phase of construction + void ConstructL(const CKey& aKey); + + //Override CSymmetricStreamCipherImpl virtual functions + void DoProcess(TDes8& aData); + + void GenerateSBox(); + TUint8 GenerateByte(); + void DiscardBytes(TInt aDiscardBytes); + + private: + TUint8 ix; + TUint8 iy; + TInt iDiscardBytes; + TUint8 iState[KSBoxSize]; + }; + } + +#endif //ARC4IMPL_H + + + diff -r 7e3f204e6c81 -r f9c11be8c0b3 cryptoplugins/cryptospiplugins/source/softwarecrypto/asymmetriccipherimpl.cpp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/cryptoplugins/cryptospiplugins/source/softwarecrypto/asymmetriccipherimpl.cpp Tue Dec 01 11:12:04 2009 +0000 @@ -0,0 +1,166 @@ +/* +* Copyright (c) 2006-2009 Nokia Corporation and/or its subsidiary(-ies). +* All rights reserved. +* This component and the accompanying materials are made available +* under the terms of the License "Eclipse Public License v1.0" +* which accompanies this distribution, and is available +* at the URL "http://www.eclipse.org/legal/epl-v10.html". +* +* Initial Contributors: +* Nokia Corporation - initial contribution. +* +* Contributors: +* +* Description: +* +*/ + + +#include +#include "keys.h" +#include "asymmetriccipherimpl.h" +#include +#include +#include +#include "pluginconfig.h" +#include "common/inlines.h" + +using namespace SoftwareCrypto; + +CAsymmetricCipherImpl::CAsymmetricCipherImpl( + TUid aCryptoMode, + TUid aPaddingMode) : + iCryptoMode(aCryptoMode), + iPaddingMode(aPaddingMode) + { + } + +void CAsymmetricCipherImpl::ConstructL(const CKey& aKey) + { + DoSetCryptoModeL(iCryptoMode); + DoSetKeyL(aKey); + DoSetPaddingModeL(iPaddingMode); + } + +CAsymmetricCipherImpl::~CAsymmetricCipherImpl() + { + delete iKey; + delete iPadding; + } + +void CAsymmetricCipherImpl::Close() + { + delete this; + } + +void CAsymmetricCipherImpl::Reset() + { + } + +TAny* CAsymmetricCipherImpl::GetExtension(TUid /*aExtensionId*/) + { + return 0; + } + +void CAsymmetricCipherImpl::GetCharacteristicsL(const TAny*& aPluginCharacteristics) + { + TInt numCiphers = sizeof(KAsymmetricCipherCharacteristics)/sizeof(TAsymmetricCipherCharacteristics*); + TInt32 implUid = ImplementationUid().iUid; + for (TInt i = 0; i < numCiphers; ++i) + { + if (KAsymmetricCipherCharacteristics[i]->cmn.iImplementationUID == implUid) + { + aPluginCharacteristics = KAsymmetricCipherCharacteristics[i]; + break; + } + } + } + +void CAsymmetricCipherImpl::SetKeyL(const CKey& aKey) + { + DoSetKeyL(aKey); + } + +void CAsymmetricCipherImpl::DoSetKeyL(const CKey& aKey) + { + delete iKey; // delete any previous key + iKey = CKey::NewL(aKey); + } + +void CAsymmetricCipherImpl::SetCryptoModeL(TUid aCryptoMode) + { + DoSetCryptoModeL(aCryptoMode); + Reset(); + } + +void CAsymmetricCipherImpl::DoSetCryptoModeL(TUid aCryptoMode) + { + switch (aCryptoMode.iUid) + { + case KCryptoModeEncrypt: + case KCryptoModeDecrypt: + break; + default: + User::Leave(KErrNotSupported); + } + iCryptoMode = aCryptoMode; + } + +void CAsymmetricCipherImpl::SetPaddingModeL(TUid aPaddingMode) + { + DoSetPaddingModeL(aPaddingMode); + Reset(); + } + +void CAsymmetricCipherImpl::DoSetPaddingModeL(TUid aPaddingMode) + { + CPadding* padding(0); + TInt padlength = 0; + + switch (iCryptoMode.iUid) + { + case KCryptoModeEncrypt: + padlength = GetMaximumOutputLengthL(); + break; + case KCryptoModeDecrypt: + padlength = GetMaximumInputLengthL(); + break; + } + + switch (aPaddingMode.iUid) + { + case KPaddingModeNone: + padding = CPaddingNone::NewL(padlength); + break; + case KPaddingModePkcs1_v1_5_Encryption: + padding = CPaddingPKCS1Encryption::NewL(padlength); + break; + default: + User::Leave(KErrNotSupported); + } + + delete iPadding; + iPadding = padding; + iPaddingMode = aPaddingMode; + } + +// Methods implemented in subclass. No coverage here. +#ifdef _BullseyeCoverage +#pragma suppress_warnings on +#pragma BullseyeCoverage off +#pragma suppress_warnings off +#endif +TInt CAsymmetricCipherImpl::GetMaximumOutputLengthL() const + { + // Override in subclass + User::Leave(KErrNotSupported); + return 0; + } + +TInt CAsymmetricCipherImpl::GetMaximumInputLengthL() const + { + // Override in subclass + User::Leave(KErrNotSupported); + return 0; + } + diff -r 7e3f204e6c81 -r f9c11be8c0b3 cryptoplugins/cryptospiplugins/source/softwarecrypto/asymmetriccipherimpl.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/cryptoplugins/cryptospiplugins/source/softwarecrypto/asymmetriccipherimpl.h Tue Dec 01 11:12:04 2009 +0000 @@ -0,0 +1,137 @@ +/* +* Copyright (c) 2007-2009 Nokia Corporation and/or its subsidiary(-ies). +* All rights reserved. +* This component and the accompanying materials are made available +* under the terms of the License "Eclipse Public License v1.0" +* which accompanies this distribution, and is available +* at the URL "http://www.eclipse.org/legal/epl-v10.html". +* +* Initial Contributors: +* Nokia Corporation - initial contribution. +* +* Contributors: +* +* Description: +* +*/ + + +#ifndef __ASYMMETRICCIPHERIMPL_H__ +#define __ASYMMETRICCIPHERIMPL_H__ + +/** +@file +@internalComponent +@released +*/ + +#include +#include +#include +#include "asymmetriccipherplugin.h" +#include "keys.h" +#include "common/inlines.h" + +/** + * Abstract base class for symmetric cipher plug-ins. + */ +namespace SoftwareCrypto + { + using namespace CryptoSpi; + + NONSHARABLE_CLASS(CAsymmetricCipherImpl) : public CBase, public MAsymmetricCipher + { + public: + + // Override MPlugin virtual functions + void Close(); + void Reset(); // Always call reset in super-class if you override this + TAny* GetExtension(TUid aExtensionId); + void GetCharacteristicsL(const TCharacteristics*& aPluginCharacteristics); + // End of MPlugin + + // Override MAsymmetricCipherBase virtual functions + void SetKeyL(const CKey& aKey); // override DoSetKeyL instead + void SetCryptoModeL(TUid aCryptoMode); // override DoSetCryptoModeL instead + void SetPaddingModeL(TUid aPaddingMode); // override DoSetPaddingModeL instead + virtual TInt GetMaximumInputLengthL() const; + virtual TInt GetMaximumOutputLengthL() const; + // End of MAsymmetricCipherBase + + // Override MAsymmetricCipher virtual functions + virtual void ProcessL(const TDesC8& aInput, TDes8& aOutput) = 0; + // End of MAsymmetricCipher + + /// Destructor + ~CAsymmetricCipherImpl(); + + protected: + /** + Constructor + @param aCryptoMode Whether to encrypt or decrypt + @param aPaddingMode The padding mode + */ + CAsymmetricCipherImpl(TUid aCryptoMode, TUid aPaddingMode); + + /** + Second phase of construction. Always call ConstructL in the super-class + if you override this method. + + @param aKey The key to initialise the cipher with. + */ + virtual void ConstructL(const CKey& aKey); + + /** + Implemented by each cipher subclass to determine whether the + specified key length is valid for that cipher. + This is called by ConstructL and SetKeyL + @param aKeyBytes The key length in bytes to verify. + @return ETrue if key length is acceptable + */ + virtual TBool IsValidKeyLengthL(TInt aKeyBytes) const = 0; + + /** + Helper function implemented by concrete cipher sub-class that allows + GetCharacteristicsL to return the correct characteristics object. + @return The implemention uid + */ + virtual TUid ImplementationUid() const = 0; + + /** + Validates and sets the crypto mode (iCryptoMode) + @param aCryptoMode The crypto mode + */ + virtual void DoSetCryptoModeL(TUid aCryptoMode); + + /** + Extracts the raw key from aKey and sets iKey and iKeyBytes + The key length is also checked to meet export restrictions and + to ensure that it is appropriate for the cipher. + @param aKey The key + */ + virtual void DoSetKeyL(const CKey& aKey); + + /** + Validates and sets the padding mode (iPaddingMode & iPadding) + @param aPadding The desired padding mode + */ + virtual void DoSetPaddingModeL(TUid aPadding); + + private: + + protected: + /// encryption or decryption + TUid iCryptoMode; + + /// the current padding scheme + TUid iPaddingMode; + + /// the key + CKey* iKey; + + /// current padding scheme implementation + CPadding* iPadding; + }; + } + +#endif // __ASYMMETRICCIPHERIMPL_H__ diff -r 7e3f204e6c81 -r f9c11be8c0b3 cryptoplugins/cryptospiplugins/source/softwarecrypto/cmacimpl.cpp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/cryptoplugins/cryptospiplugins/source/softwarecrypto/cmacimpl.cpp Tue Dec 01 11:12:04 2009 +0000 @@ -0,0 +1,416 @@ +/* +* Copyright (c) 2008-2009 Nokia Corporation and/or its subsidiary(-ies). +* All rights reserved. +* This component and the accompanying materials are made available +* under the terms of the License "Eclipse Public License v1.0" +* which accompanies this distribution, and is available +* at the URL "http://www.eclipse.org/legal/epl-v10.html". +* +* Initial Contributors: +* Nokia Corporation - initial contribution. +* +* Contributors: +* +* Description: +* Software Mac Implementation +* plugin-dll headers +* +*/ + + +/** + @file +*/ +#include "cmacimpl.h" +#include "pluginconfig.h" +#include + + +using namespace SoftwareCrypto; +using namespace CryptoSpi; + +/** + * Constants used to generate Key1, Key2 and Key3 + */ +const TUint8 K1Constant[] = {0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01}; +const TUint8 K2Constant[] = {0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02}; +const TUint8 K3Constant[] = {0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03}; + +const TInt KAesXcbcMac96Size = 12; + + +CCMacImpl* CCMacImpl::NewL(const CKey& aKey, CSymmetricCipher* aSymmetricCipher, TInt32 aAlgorithmUid) + { + CCMacImpl* self = CCMacImpl::NewLC(aKey, aSymmetricCipher, aAlgorithmUid); + CleanupStack::Pop(self); + return self; + } + +CCMacImpl* CCMacImpl::NewLC(const CKey& aKey, CSymmetricCipher* aSymmetricCipher, TInt32 aAlgorithmUid) + { + CCMacImpl* self = NULL; + TRAPD(err, self = new (ELeave) CCMacImpl(aSymmetricCipher)); + if(err!=KErrNone) + { + delete aSymmetricCipher; + User::Leave(err); + } + CleanupStack::PushL(self); + self->ConstructL(aKey, aAlgorithmUid); + return self; + } + +CKey* CCMacImpl::Create128bitKeyL(const CKey& aKey) + { + TBuf8 keybuffer; + CryptoSpi::CKey* key = NULL; + + const TDesC8& keyContent=aKey.GetTDesC8L(CryptoSpi::KSymmetricKeyParameterUid); + + if( (TUint32)keyContent.Size() > KMacBlockSize) + { + // Create key + CryptoSpi::CCryptoParams* keyParams = CryptoSpi::CCryptoParams::NewLC(); + keybuffer.SetLength(KMacBlockSize); + keybuffer.FillZ(); + // 'keybuffer' is the key with 128 zero bits. + keyParams->AddL(keybuffer, CryptoSpi::KSymmetricKeyParameterUid); + key=CryptoSpi::CKey::NewLC(aKey.KeyProperty(),*keyParams); + // evaluate final key data. + SetKeyL(*key); + CleanupStack::PopAndDestroy(2, keyParams); + keybuffer.Copy(FinalL(keyContent)); + // 'keybuffer' contains the final key data. + } + else + { + keybuffer.Copy(keyContent); + TUint i; + for (i=keybuffer.Size();iAddL(keybuffer, CryptoSpi::KSymmetricKeyParameterUid); + key=CryptoSpi::CKey::NewL(aKey.KeyProperty(),*keyParams); + CleanupStack::PopAndDestroy(keyParams); + + // 'key' will contain the final CKey instance. + return key; + } + +void CCMacImpl::SetKeyL(const CKey& aKey) + { + const TPtrC8 KeyConstant1(K1Constant, KMacBlockSize); + const TPtrC8 KeyConstant2(K2Constant, KMacBlockSize); + const TPtrC8 KeyConstant3(K3Constant, KMacBlockSize); + + // Initialize the cipher class to encrypt Keyconstants to generate additional keys. + if (iImplementationUid == CryptoSpi::KAlgorithmCipherAesXcbcPrf128) + { + // RFC 4434: keys that were not equal in length to 128 bits will no longer be + // rejected but instead will be made 128 bits for AES-XCBC-PRF-128 Algorithm only. + CryptoSpi::CKey* key = Create128bitKeyL(aKey); + CleanupStack::PushL(key); + iCipherImpl->SetKeyL(*key); + CleanupStack::PopAndDestroy(key); + } + else + { + iCipherImpl->SetKeyL(aKey); + } + iCipherImpl->SetCryptoModeL(CryptoSpi::KCryptoModeEncryptUid); + iCipherImpl->SetOperationModeL(CryptoSpi::KOperationModeNoneUid); + + // cipher class expects the output buffer to be empty. + iKey1.Zero(); + iKey2.Zero(); + iKey3.Zero(); + + // aKey is used to generate Key1, Key2 and Key3. + // Where Key1 = encrypt KeyConstant1 with aKey + // Where Key2 = encrypt KeyConstant2 with aKey + // Where Key3 = encrypt KeyConstant3 with aKey + + // Key1 is used to encrypt the data whereas + // Key2 and Key3 is used to XOR with the last + // block. + iCipherImpl->ProcessFinalL(KeyConstant1, iKey1); + iCipherImpl->ProcessFinalL(KeyConstant2, iKey2); + iCipherImpl->ProcessFinalL(KeyConstant3, iKey3); + + // Create CKey instance with key1 + CCryptoParams* keyParam =CCryptoParams::NewLC(); + keyParam->AddL(iKey1, CryptoSpi::KSymmetricKeyParameterUid); + + delete iKey; + iKey = NULL; + iKey=CKey::NewL(aKey.KeyProperty(), *keyParam); + // Initialize the cipher class for MAC calculation. + iCipherImpl->SetKeyL(*iKey); + iCipherImpl->SetOperationModeL(CryptoSpi::KOperationModeCBCUid); + Mem::FillZ(iE, sizeof(iE)); + iCipherImpl->SetIvL(TPtrC8(iE, KMacBlockSize)); + + CleanupStack::PopAndDestroy(keyParam); + } + +CCMacImpl::~CCMacImpl() + { + delete iKey; + delete iCipherImpl; + } + +CCMacImpl::CCMacImpl(const CCMacImpl& aCCMacImpl) + { + iImplementationUid = aCCMacImpl.iImplementationUid; + iKey1.Copy(aCCMacImpl.iKey1); + iKey2.Copy(aCCMacImpl.iKey2); + iKey3.Copy(aCCMacImpl.iKey3); + + (void)Mem::Copy(iE, aCCMacImpl.iE, sizeof(iE)); + (void)Mem::Copy(iData, aCCMacImpl.iData, sizeof(iData)); + + iCurrentTotalLength = aCCMacImpl.iCurrentTotalLength; + } + +const CExtendedCharacteristics* CCMacImpl::GetExtendedCharacteristicsL() + { + return iCipherImpl->GetExtendedCharacteristicsL(); + } + +CCMacImpl::CCMacImpl(CryptoSpi::CSymmetricCipher* aSymmetricCipher) + { + iCipherImpl = aSymmetricCipher; + aSymmetricCipher = NULL; + iMacValue.SetLength(KMacBlockSize); + } + +void CCMacImpl::ConstructL(const CKey& aKey, TInt32 aAlgorithmUid) + { + iImplementationUid = aAlgorithmUid; + + switch(aAlgorithmUid) + { + case CryptoSpi::KAlgorithmCipherAesXcbcMac96: + case CryptoSpi::KAlgorithmCipherAesXcbcPrf128: + { + SetKeyL(aKey); + break; + } + default: + { + User::Leave(KErrNotSupported); + } + } + } + +/** + * Takes the message and XOR it with iData. + * + * @param aKey 128bit key. This key will be XORed with iData. + * @param aOutput The result of the XOR operation will be copied to this. + * Its length should be 128bit (16bytes). + */ + +void CCMacImpl::XORKeyWithData(const TDesC8& aKey, TDes8& aOutput) + { + for (TInt i = 0; i < KMacBlockSize; ++i) + { + aOutput[i] = iData[i] ^ aKey[i]; + } + } + +/** + * This function is used to pad message M to make the total message + * length multiple of block size (128bit). The last block M[n] will be + * padded with a single "1" bit followed by the number of "0" bits required + * to increase M[n]'s size to 128 bits (Block Size). + * + * Used in AES-XCBC-MAC-96 and AES-XCBC-PRF-128 Mac algorithms. + */ +void CCMacImpl::PadMessage() + { + if(iCurrentTotalLength < KMacBlockSize) + { + iData[iCurrentTotalLength] = 0x80; + Mem::FillZ(iData + iCurrentTotalLength+1, KMacBlockSize - iCurrentTotalLength - 1); + } + } + +void CCMacImpl::Reset() + { + Mem::FillZ(iE,sizeof(iE)); + iCurrentTotalLength =0; + // record for Reset, for the next time MacL, UpdateL or FinalL is called as we + // cannot leave in Reset. + TRAP(iDelayedReset, iCipherImpl->SetIvL(TPtrC8(iE, KMacBlockSize))); + } + +TPtrC8 CCMacImpl::MacL(const TDesC8& aMessage) + { + // Reset the cipher with iE as 128 zero bits as it leaved in previous call to Reset. + if (iDelayedReset != KErrNone) + { + // iE was reset to 128 zero bits in previous call to Reset which leaved. + iCipherImpl->SetIvL(TPtrC8(iE, KMacBlockSize)); + iDelayedReset = KErrNone; + } + + if (aMessage!=KNullDesC8()) + { + DoUpdateL(aMessage); + } + + // Calculate MAC + TPtrC8 macPtr(KNullDesC8()); + macPtr.Set(DoFinalL()); + + // Restore the internal state. + // We don't want to save any state change happened in + // DoFinalL. + // iE is not updated in DoFinalL function and hence + // can be used to reset iCipherImpl to previous state. + iCipherImpl->SetIvL(TPtrC8(iE, KMacBlockSize)); + + return macPtr; + } + +TPtrC8 CCMacImpl::FinalL(const TDesC8& aMessage) + { + // Reset the cipher with iE as 128 zero bits as it leaved in previous call to Reset. + if (iDelayedReset == KErrNone) + { + // iE was reset to 128 zero bits in previous call to Reset which leaved. + iCipherImpl->SetIvL(TPtrC8(iE, KMacBlockSize)); + iDelayedReset = KErrNone; + } + + if (aMessage!=KNullDesC8()) + { + DoUpdateL(aMessage); + } + TPtrC8 macPtr(KNullDesC8()); + macPtr.Set(DoFinalL()); + Reset(); + return macPtr; + } + +void CCMacImpl::UpdateL(const TDesC8& aMessage) + { + // Reset the cipher with iE as 128 zero bits as it leaved in previous call to Reset. + if (iDelayedReset == KErrNone) + { + // iE was reset to 128 zero bits in previous call to Reset which leaved. + iCipherImpl->SetIvL(TPtrC8(iE, KMacBlockSize)); + iDelayedReset = KErrNone; + } + + if (aMessage!=KNullDesC8()) + { + DoUpdateL(aMessage); + } + } + +void CCMacImpl::ProcessBlockL() + { + TPtrC8 dataPtr(iData, KMacBlockSize); + TPtr8 intermediateCipherPtr(iE,0,KMacBlockSize); + // iData (Block) should be XORed with iE calculated + // from previoue processing. If it's the first processing + // then iE will be zero. + // Here we are not doing explicit XORing because iCpherImpl + // is set in CBC mode. Therefore this operation will be + // done by iCipherImpl + iCipherImpl->ProcessL(dataPtr, intermediateCipherPtr); + // After processing discard the block. + iCurrentTotalLength = 0; + } + +void CCMacImpl::DoUpdateL(const TDesC8& aMessage) + { + TInt curLength = aMessage.Length(); + const TUint8* msgPtr = aMessage.Ptr(); + + while(curLength > 0) + { + // If block is formed then process it. + if(iCurrentTotalLength == KMacBlockSize) + ProcessBlockL(); + + // Check the space left in the block. + TUint remainingLength = KMacBlockSize - iCurrentTotalLength; + // If unprocesed message length is less then remainingLength + // then copy the entire data to iData else copy till iData + // if full. + TUint length = Min(curLength, remainingLength); + + + // Discard the return value obtained from Mem::Copy( ) function. + (void)Mem::Copy(iData+iCurrentTotalLength, msgPtr, length); + // Update data offset + iCurrentTotalLength += length; + curLength -= length; + msgPtr += length; + } + } + +TPtrC8 CCMacImpl::DoFinalL() + { + TBuf8 finalBlock; + finalBlock.SetLength(KMacBlockSize); + + // If padding is required then use Key3 + // else use Key2. + if(iCurrentTotalLength < KMacBlockSize) + { + PadMessage(); + XORKeyWithData(iKey3, finalBlock); + } + else + { + XORKeyWithData(iKey2, finalBlock); + } + + // cipher class expects the output buffer to be empty. + iMacValue.Zero(); + + iCipherImpl->ProcessFinalL(finalBlock, iMacValue); + + return (iImplementationUid == CryptoSpi::KAlgorithmCipherAesXcbcMac96)? iMacValue.Left(KAesXcbcMac96Size): TPtrC8(iMacValue); + } + +void CCMacImpl::ReInitialiseAndSetKeyL(const CKey& aKey) + { + Reset(); + SetKeyL(aKey); + } + + +CCMacImpl* CCMacImpl::CopyL() + { + CCMacImpl* clone = new(ELeave) CCMacImpl(*this); + CleanupStack::PushL(clone); + clone->iKey = CKey::NewL(*iKey); + CryptoSpi::CSymmetricCipherFactory::CreateSymmetricCipherL(clone->iCipherImpl, + CryptoSpi::KAesUid, + *iKey, + CryptoSpi::KCryptoModeEncryptUid, + CryptoSpi::KOperationModeCBCUid, + CryptoSpi::KPaddingModeNoneUid, + NULL); + clone->iCipherImpl->SetIvL(TPtrC8(clone->iE, KMacBlockSize)); + CleanupStack::Pop(); + return clone; + } + +CCMacImpl* CCMacImpl::ReplicateL() + { + CCMacImpl* replica = CopyL(); + replica->Reset(); + return replica; + } diff -r 7e3f204e6c81 -r f9c11be8c0b3 cryptoplugins/cryptospiplugins/source/softwarecrypto/cmacimpl.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/cryptoplugins/cryptospiplugins/source/softwarecrypto/cmacimpl.h Tue Dec 01 11:12:04 2009 +0000 @@ -0,0 +1,132 @@ +/* +* Copyright (c) 2008-2009 Nokia Corporation and/or its subsidiary(-ies). +* All rights reserved. +* This component and the accompanying materials are made available +* under the terms of the License "Eclipse Public License v1.0" +* which accompanies this distribution, and is available +* at the URL "http://www.eclipse.org/legal/epl-v10.html". +* +* Initial Contributors: +* Nokia Corporation - initial contribution. +* +* Contributors: +* +* Description: +* Cipher MAC plugin implementation +* +*/ + + +/** + @file + @internalComponent + @released +*/ + +#ifndef __CRYPTOAPI_SOFTWARECIPHERMACIMPL_H__ +#define __CRYPTOAPI_SOFTWARECIPHERMACIMPL_H__ + +#include "cryptosymmetriccipherapi.h" +#include "keys.h" + + +namespace SoftwareCrypto + { + using namespace CryptoSpi; + + /** + * This is the maximum block size in bytes currently supported by CMAC implementation. + * + * The cipher based algorithms currently supported are + * AES-XCBC-MAC-96 and AES-XCBC-PRF-128. + */ + const TInt KMacBlockSize = 16; + + /** + * The class is created from following substance classes + * 1. MMac + * 2. CSymmetricCipher + * Using the methods of the above classes we will transform/mould the Cipher methods in + * a way as to be inline with the MMac interface methods. The MMac methods will + * serve as the wrapper internal to which Cipher methods will work to provide the MAC value. + * + * The class was created to provide consistency/similarity HMAC and CMAC works. + * Also for future extensibility of other Cipher algorithms. + */ + NONSHARABLE_CLASS(CCMacImpl) : public CBase + { + public: + /** + * Cipher MAC implementation instance creation methods + * + *The owneship of 'aSymmetricCipher' is imparted to instance of this class. + */ + static CCMacImpl* NewL(const CKey& aKey, + CSymmetricCipher* aSymmetricCipher, + TInt32 aAlgorithmUid); + + static CCMacImpl* NewLC(const CKey& aKey, + CSymmetricCipher* aSymmetricCipher, + TInt32 aAlgorithmUid); + /** + * Simulating Methods from MPlugin + */ + const CExtendedCharacteristics* GetExtendedCharacteristicsL(); + + // We will call CSymmetricBlockCipherImpl::Reset(); + void Reset(); + + /** + * Simulating MAC interfaces (Software based) + */ + TPtrC8 MacL(const TDesC8& aMessage); + void UpdateL(const TDesC8& aMessage); + TPtrC8 FinalL(const TDesC8& aMessage); + void ReInitialiseAndSetKeyL(const CKey& aKey); + void SetKeyL(const CKey& aKey); + ~CCMacImpl(); + CCMacImpl* CopyL(); + CCMacImpl* ReplicateL(); + + private: + /** + * Constructors + */ + CCMacImpl(CryptoSpi::CSymmetricCipher* aSymmetricCipher); + CCMacImpl(const CCMacImpl&); + + /** + * Initialize the 'iCipherImpl' instances. + */ + void ConstructL(const CKey& aKey, TInt32 aAlgorithmUid); + void DoUpdateL(const TDesC8& aMessage); + TPtrC8 DoFinalL(); + void PadMessage(); + void ProcessBlockL(); + void XORKeyWithData(const TDesC8& aKey, TDes8& aOutput); + CKey* Create128bitKeyL(const CKey& aKey); + + private: + TInt32 iImplementationUid; + CKey* iKey; + CryptoSpi::CSymmetricCipher* iCipherImpl; + + TBuf8 iKey1; + TBuf8 iKey2; + TBuf8 iKey3; + TBuf8 iMacValue; + + TUint8 iE[KMacBlockSize]; + TUint8 iData[KMacBlockSize]; + TInt iCurrentTotalLength; + // Resets the cipher with iE(128 zero bits) the next time MacL, + // UpdateL or FinalL are called. This was introduced as we cannot leave from the + // non-leaving CCMacImpl::Reset() implementation of the MPlugin::Reset() pure + // virtual. To prevent behavioral break. + TInt iDelayedReset; + }; + } + +#endif // __CRYPTOAPI_SOFTWARECIPHERMACIMPL_H__ + + diff -r 7e3f204e6c81 -r f9c11be8c0b3 cryptoplugins/cryptospiplugins/source/softwarecrypto/des.inl --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/cryptoplugins/cryptospiplugins/source/softwarecrypto/des.inl Tue Dec 01 11:12:04 2009 +0000 @@ -0,0 +1,76 @@ +/* +* Copyright (c) 2003-2009 Nokia Corporation and/or its subsidiary(-ies). +* All rights reserved. +* This component and the accompanying materials are made available +* under the terms of the License "Eclipse Public License v1.0" +* which accompanies this distribution, and is available +* at the URL "http://www.eclipse.org/legal/epl-v10.html". +* +* Initial Contributors: +* Nokia Corporation - initial contribution. +* +* Contributors: +* +* Description: +* +*/ + + +#ifndef __DES_INL__ +#define __DES_INL__ + +inline void IPerm(TUint32& left, TUint32& right) + { + TUint32 work; + + right = rotlFixed(right, 4U); + work = (left ^ right) & 0xf0f0f0f0; + left ^= work; + right = rotrFixed(right^work, 20U); + work = (left ^ right) & 0xffff0000; + left ^= work; + right = rotrFixed(right^work, 18U); + work = (left ^ right) & 0x33333333; + left ^= work; + right = rotrFixed(right^work, 6U); + work = (left ^ right) & 0x00ff00ff; + left ^= work; + right = rotlFixed(right^work, 9U); + work = (left ^ right) & 0xaaaaaaaa; + left = rotlFixed(left^work, 1U); + right ^= work; + } + +inline void FPerm(TUint32& left, TUint32& right) + { + TUint32 work; + + right = rotrFixed(right, 1U); + work = (left ^ right) & 0xaaaaaaaa; + right ^= work; + left = rotrFixed(left^work, 9U); + work = (left ^ right) & 0x00ff00ff; + right ^= work; + left = rotlFixed(left^work, 6U); + work = (left ^ right) & 0x33333333; + right ^= work; + left = rotlFixed(left^work, 18U); + work = (left ^ right) & 0xffff0000; + right ^= work; + left = rotlFixed(left^work, 20U); + work = (left ^ right) & 0xf0f0f0f0; + right ^= work; + left = rotrFixed(left^work, 4U); + } + +inline void ReverseKeySchedule(TUint32* aKey) + { + TInt i = 0; + for (; i<16; i+=2) + { + TClassSwap((*(aKey+i)), (*(aKey+(32-2-i)))); + TClassSwap((*(aKey+i+1)), (*(aKey+(32-1-i)))); + } + } + +#endif //__DES_INL__ diff -r 7e3f204e6c81 -r f9c11be8c0b3 cryptoplugins/cryptospiplugins/source/softwarecrypto/desimpl.cpp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/cryptoplugins/cryptospiplugins/source/softwarecrypto/desimpl.cpp Tue Dec 01 11:12:04 2009 +0000 @@ -0,0 +1,249 @@ +/* +* Copyright (c) 2006-2009 Nokia Corporation and/or its subsidiary(-ies). +* All rights reserved. +* This component and the accompanying materials are made available +* under the terms of the License "Eclipse Public License v1.0" +* which accompanies this distribution, and is available +* at the URL "http://www.eclipse.org/legal/epl-v10.html". +* +* Initial Contributors: +* Nokia Corporation - initial contribution. +* +* Contributors: +* +* Description: +* +*/ + + +#include "desimpl.h" + +#include "destables.h" +#include "common/inlines.h" +#include "des.inl" +#include "pluginconfig.h" +#include "symmetriccipherimpl.h" +#include + + +// bit 0 is left-most in byte +static const TInt bytebit[] = {0200,0100,040,020,010,04,02,01}; + +using namespace SoftwareCrypto; + +/* CDesImpl */ +CDesImpl::CDesImpl( + TUint8 aBlockBytes, + TUid aCryptoMode, + TUid aOperationMode, + TUid aPadding) : + CSymmetricBlockCipherImpl(aBlockBytes, aCryptoMode, aOperationMode, aPadding) + { + } + +CDesImpl* CDesImpl::NewL(const CKey& aKey, TUid aCryptoMode, TUid aOperationMode, TUid aPadding) + { + CDesImpl* self = CDesImpl::NewLC(aKey, aCryptoMode, aOperationMode, aPadding); + CleanupStack::Pop(self); + return self; + } + +CDesImpl* CDesImpl::NewLC(const CKey& aKey, TUid aCryptoMode, TUid aOperationMode, TUid aPadding) + { + CDesImpl* self = new(ELeave) CDesImpl(KDesBlockBytes, aCryptoMode, aOperationMode, aPadding); + CleanupStack::PushL(self); + self->ConstructL(aKey); + + const TDesC8& keyContent = aKey.GetTDesC8L(KSymmetricKeyParameterUid); + TCrypto::IsSymmetricWeakEnoughL(BytesToBits(keyContent.Size()) - keyContent.Size()); + return self; + } + +CDesImpl::~CDesImpl() + { + // make sure key information isn't visible to other processes if the + // page is reused. + Mem::FillZ(&iK, sizeof(iK)); + } + +void CDesImpl::ConstructL(const CKey& aKey) + { + CSymmetricBlockCipherImpl::ConstructL(aKey); + SetKeySchedule(); + } + +CExtendedCharacteristics* CDesImpl::CreateExtendedCharacteristicsL() + { + // All Symbian software plug-ins have unlimited concurrency, cannot be reserved + // for exclusive use and are not CERTIFIED to be standards compliant. + return CExtendedCharacteristics::NewL(KMaxTInt, EFalse); + } + +const CExtendedCharacteristics* CDesImpl::GetExtendedCharacteristicsL() + { + return CDesImpl::CreateExtendedCharacteristicsL(); + } + +TUid CDesImpl::ImplementationUid() const + { + return KCryptoPluginDesUid; + } + +TBool CDesImpl::IsValidKeyLength(TInt aKeyBytes) const + { + return (aKeyBytes == KDesKeyBytes); + } + +TInt CDesImpl::GetKeyStrength() const + { + // parity bits are excluded + return BytesToBits(KDesKeyBytes - 8); + } + +void CDesImpl::TransformEncrypt( + TUint8* aBuffer, + TUint aNumBlocks) + { + for (TInt i = 0; i < aNumBlocks; ++i) + { + ModeEncryptStart(aBuffer); + TUint32 l, r; + // Split the block into 2 word-sized big endian portions + GetBlockBigEndian(aBuffer, l, r); + IPerm(l,r); + DoTransform(l, r, iK); + FPerm(l,r); + + // Put the portions back into the block as little endian + PutBlockBigEndian(aBuffer, r, l); + + ModeEncryptEnd(aBuffer); + aBuffer += KDesBlockBytes; + } + } + +void CDesImpl::TransformDecrypt( + TUint8* aBuffer, + TUint aNumBlocks) + { + for (TInt i = 0; i < aNumBlocks; ++i) + { + ModeDecryptStart(aBuffer); + + TUint32 l, r; + // Split the block into 2 word-sized big endian portions + GetBlockBigEndian(aBuffer, l, r); + + IPerm(l,r); + DoTransform(l, r, iK); + FPerm(l,r); + + // Put the portions back into the block as little endian + PutBlockBigEndian(aBuffer, r, l); + + ModeDecryptEnd(aBuffer); + aBuffer += KDesBlockBytes; + } + } + +void CDesImpl::SetKeySchedule() + { + if (iCryptoMode.iUid == KCryptoModeEncrypt) + { + SetEncryptKeySchedule(*iKey, iK); + } + else + { + ASSERT(iCryptoMode.iUid == KCryptoModeDecrypt); + SetDecryptKeySchedule(*iKey, iK); + } + } + +void CDesImpl::DoTransform(TUint32& l, TUint32& r, const TUint32* aKeySchedule) + { + TInt i = 0; + for (; i<8; i++) + { + TUint32 work = rotrFixed(r, 4U) ^ aKeySchedule[4*i+0]; + l ^= DES_TABLE::sbox[6][(work) & 0x3f] + ^ DES_TABLE::sbox[4][(work >> 8) & 0x3f] + ^ DES_TABLE::sbox[2][(work >> 16) & 0x3f] + ^ DES_TABLE::sbox[0][(work >> 24) & 0x3f]; + work = r ^ aKeySchedule[4*i+1]; + l ^= DES_TABLE::sbox[7][(work) & 0x3f] + ^ DES_TABLE::sbox[5][(work >> 8) & 0x3f] + ^ DES_TABLE::sbox[3][(work >> 16) & 0x3f] + ^ DES_TABLE::sbox[1][(work >> 24) & 0x3f]; + + work = rotrFixed(l, 4U) ^ aKeySchedule[4*i+2]; + r ^= DES_TABLE::sbox[6][(work) & 0x3f] + ^ DES_TABLE::sbox[4][(work >> 8) & 0x3f] + ^ DES_TABLE::sbox[2][(work >> 16) & 0x3f] + ^ DES_TABLE::sbox[0][(work >> 24) & 0x3f]; + work = l ^ aKeySchedule[4*i+3]; + r ^= DES_TABLE::sbox[7][(work) & 0x3f] + ^ DES_TABLE::sbox[5][(work >> 8) & 0x3f] + ^ DES_TABLE::sbox[3][(work >> 16) & 0x3f] + ^ DES_TABLE::sbox[1][(work >> 24) & 0x3f]; + } + } + +void CDesImpl::SetEncryptKeySchedule(const TDesC8& aKey, TUint32* aKeySchedule) + { + TInt i=0, j=0, l=0, m=0; + +// Form a byte array from aKey, taking endianess into account (little->big) + TUint8 key[8]; // For big endian byte array + Mem::Copy(&key, &aKey[0], 8); + + TUint8 buffer[56+56+8]; + TUint8* const pc1m = &buffer[0]; /* place to modify pc1 into */ + TUint8* const pcr = pc1m + 56; /* place to rotate pc1 into */ + TUint8* const ks = pcr + 56; + + for (j=0; j<56; j++) + {/* convert pc1 to bits of key */ + l = DES_TABLE::pc1[j]-1; /* integer bit location */ + m = l & 07; /* find bit */ + pc1m[j]=(key[l>>3] & /* find which key byte l is in */ + bytebit[m]) /* and which bit of that byte */ + ? (TUint8)1 : (TUint8)0; /* and store 1-bit result */ + } + + for (i=0; i<16; i++) + {/* key chunk for each iteration */ + Mem::FillZ(ks,8); /* Clear key schedule */ + for (j=0; j<56; j++) + /* rotate pc1 the right amount */ + pcr[j] = pc1m[(l=j+DES_TABLE::totrot[i])<(j<28? 28 : 56) ? l: l-28]; + + /* rotate left and right halves independently */ + + for (j=0; j<48; j++) + {/* select bits individually */ + /* check bit that goes to ks[j] */ + if (pcr[DES_TABLE::pc2[j]-1]) + {/* mask it in if it's there */ + l= j % 6; + ks[j/6] |= bytebit[l] >> 2; + } + } + + /* Now convert to odd/even interleaved form for use in F */ + (*(aKeySchedule+(2*i))) = ((TUint32)ks[0] << 24) + | ((TUint32)ks[2] << 16) + | ((TUint32)ks[4] << 8) + | ((TUint32)ks[6]); + + (*(aKeySchedule+(2*i+1))) = ((TUint32)ks[1] << 24) + | ((TUint32)ks[3] << 16) + | ((TUint32)ks[5] << 8) + | ((TUint32)ks[7]); + } + } + +void CDesImpl::SetDecryptKeySchedule(const TDesC8& aKey, TUint32* aKeySchedule) + { + SetEncryptKeySchedule(aKey, aKeySchedule); + ReverseKeySchedule(aKeySchedule); + } diff -r 7e3f204e6c81 -r f9c11be8c0b3 cryptoplugins/cryptospiplugins/source/softwarecrypto/desimpl.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/cryptoplugins/cryptospiplugins/source/softwarecrypto/desimpl.h Tue Dec 01 11:12:04 2009 +0000 @@ -0,0 +1,140 @@ +/* +* Copyright (c) 2006-2009 Nokia Corporation and/or its subsidiary(-ies). +* All rights reserved. +* This component and the accompanying materials are made available +* under the terms of the License "Eclipse Public License v1.0" +* which accompanies this distribution, and is available +* at the URL "http://www.eclipse.org/legal/epl-v10.html". +* +* Initial Contributors: +* Nokia Corporation - initial contribution. +* +* Contributors: +* +* Description: +* +*/ + + +#ifndef __DESIMPL_H__ +#define __DESIMPL_H__ + +/** +@file +@internalComponent +@released +*/ + +#include +#include +#include "keys.h" +#include "symmetriccipherimpl.h" + +/** +Plug-in class for DES block cipher +*/ +namespace SoftwareCrypto + { + using namespace CryptoSpi; + + NONSHARABLE_CLASS(CDesImpl) : public CSymmetricBlockCipherImpl + { + public: + /** + Creates an instance of a DES (Data Encryption Standard) symmetric cipher plug-in. + @param aKey The key + @param aCryptoMode whether to encrypt or decrypt + @param aOperationMode The block cipher mode ECB, CBC, CTR etc + @param aPadding The padding scheme to use None, SSLv3, PKCS#7 + @return A pointer to a CDesImpl instance + */ + static CDesImpl* NewL(const CKey& aKey, + TUid aCryptoMode, TUid aOperationMode, TUid aPadding); + + /** + Creates an instance of a DES (Data Encryption Standard) symmetric cipher plug-in. + A pointer to the plug-in instance is placed on the cleanup stack. + @param aKey The key + @param aCryptoMode Whether to encrypt or decrypt + @param aOperationMode T block cipher mode ECB, CBC, CTR etc + @param aPadding The padding scheme to use None, SSLv3, PKCS#7 + @return A pointer to a CDesImpl instance + */ + static CDesImpl* NewLC(const CKey& aKey, + TUid aCryptoMode, TUid aOperationMode, TUid aPadding); + + // From CSymmetricCipherImpl + TInt GetKeyStrength() const; + TBool IsValidKeyLength(TInt aKeyBytes) const; + TUid ImplementationUid() const; + const CExtendedCharacteristics* GetExtendedCharacteristicsL(); + + static CExtendedCharacteristics* CreateExtendedCharacteristicsL(); + + /// Destructor + ~CDesImpl(); + protected: + /** + Constructor + @param aBlockBytes The block size in bytes (needed to allow + 3DES implementation to inherit from this class) + @param aOperationMode The mode of operation e.g. CBC + @param aCryptoMode Whether to encrypt or decrypt + @param aPaddingMode The padding mode to use. None, SSL, PKCS#7 + */ + CDesImpl(TUint8 aBlockBytes, TUid aOperationMode, TUid aCryptoMode, TUid aPaddingMode); + + /** + Second phase of construction + @param aKey The key object + */ + void ConstructL(const CKey& aKey); + + // These protected functions are re-used by 3DES + /** + Transforms a block of data + @param l The left half of the block to transform + @param r The right half of the block to transform + @param aKeySchedule The keyschedule to use for the transformation + */ + void DoTransform(TUint32& l, TUint32& r, const TUint32* aKeySchedule); + + /** + Setup the key schedule for encryption + @param aKey The input key + @param aKeySchedule A pointer to the key schedule buffer + */ + void SetEncryptKeySchedule(const TDesC8& aKey, TUint32* aKeySchedule); + + /** + Setup the key schedule for decryption + @param aKey The input key + @param aKeySchedule A pointer to the key schedule buffer + */ + void SetDecryptKeySchedule(const TDesC8& aKey, TUint32* aKeySchedule); + + static const TUint8 KDesBlockBytes = 8; + static const TUint8 KDesKeyBytes = 8; + + private: + + /** + Creates the key schedule iK from CBlockTransformationImpl::iKey. + This should be called from ConstructL and Reset + */ + void SetKeySchedule(); + + // From CSymmetricBlockCipherImpl + void TransformEncrypt(TUint8* aBuffer, TUint aNumBlocks); + void TransformDecrypt(TUint8* aBuffer, TUint aNumBlocks); + + private: + /// Size of the key schedule in words + static const TUint KKeyScheduleSize = 32; + + /// the key schedule + TUint32 iK[KKeyScheduleSize]; + }; + } + +#endif // __DESIMPL_H__ diff -r 7e3f204e6c81 -r f9c11be8c0b3 cryptoplugins/cryptospiplugins/source/softwarecrypto/destables.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/cryptoplugins/cryptospiplugins/source/softwarecrypto/destables.h Tue Dec 01 11:12:04 2009 +0000 @@ -0,0 +1,184 @@ +/* +* Copyright (c) 2002-2009 Nokia Corporation and/or its subsidiary(-ies). +* All rights reserved. +* This component and the accompanying materials are made available +* under the terms of the License "Eclipse Public License v1.0" +* which accompanies this distribution, and is available +* at the URL "http://www.eclipse.org/legal/epl-v10.html". +* +* Initial Contributors: +* Nokia Corporation - initial contribution. +* +* Contributors: +* +* Description: +* +*/ + + +/** + @file + @internalComponent + @released +*/ + +#ifndef __DESTABLES_H__ +#define __DESTABLES_H__ + +#include + +namespace DES_TABLE +{ +/* initial permutation IP */ +const TUint8 ip[] = { + 58, 50, 42, 34, 26, 18, 10, 2, + 60, 52, 44, 36, 28, 20, 12, 4, + 62, 54, 46, 38, 30, 22, 14, 6, + 64, 56, 48, 40, 32, 24, 16, 8, + 57, 49, 41, 33, 25, 17, 9, 1, + 59, 51, 43, 35, 27, 19, 11, 3, + 61, 53, 45, 37, 29, 21, 13, 5, + 63, 55, 47, 39, 31, 23, 15, 7 +}; + +/* final permutation IP^-1 */ +const TUint8 fp[] = { + 40, 8, 48, 16, 56, 24, 64, 32, + 39, 7, 47, 15, 55, 23, 63, 31, + 38, 6, 46, 14, 54, 22, 62, 30, + 37, 5, 45, 13, 53, 21, 61, 29, + 36, 4, 44, 12, 52, 20, 60, 28, + 35, 3, 43, 11, 51, 19, 59, 27, + 34, 2, 42, 10, 50, 18, 58, 26, + 33, 1, 41, 9, 49, 17, 57, 25 +}; + +/* expansion operation matrix */ +const TUint8 ei[] = { + 32, 1, 2, 3, 4, 5, + 4, 5, 6, 7, 8, 9, + 8, 9, 10, 11, 12, 13, + 12, 13, 14, 15, 16, 17, + 16, 17, 18, 19, 20, 21, + 20, 21, 22, 23, 24, 25, + 24, 25, 26, 27, 28, 29, + 28, 29, 30, 31, 32, 1 +}; + +const TUint32 sbox[8][64] = { +{ +0x01010400,0x00000000,0x00010000,0x01010404, 0x01010004,0x00010404,0x00000004,0x00010000, +0x00000400,0x01010400,0x01010404,0x00000400, 0x01000404,0x01010004,0x01000000,0x00000004, +0x00000404,0x01000400,0x01000400,0x00010400, 0x00010400,0x01010000,0x01010000,0x01000404, +0x00010004,0x01000004,0x01000004,0x00010004, 0x00000000,0x00000404,0x00010404,0x01000000, +0x00010000,0x01010404,0x00000004,0x01010000, 0x01010400,0x01000000,0x01000000,0x00000400, +0x01010004,0x00010000,0x00010400,0x01000004, 0x00000400,0x00000004,0x01000404,0x00010404, +0x01010404,0x00010004,0x01010000,0x01000404, 0x01000004,0x00000404,0x00010404,0x01010400, +0x00000404,0x01000400,0x01000400,0x00000000, 0x00010004,0x00010400,0x00000000,0x01010004}, +{ +0x80108020,0x80008000,0x00008000,0x00108020, 0x00100000,0x00000020,0x80100020,0x80008020, +0x80000020,0x80108020,0x80108000,0x80000000, 0x80008000,0x00100000,0x00000020,0x80100020, +0x00108000,0x00100020,0x80008020,0x00000000, 0x80000000,0x00008000,0x00108020,0x80100000, +0x00100020,0x80000020,0x00000000,0x00108000, 0x00008020,0x80108000,0x80100000,0x00008020, +0x00000000,0x00108020,0x80100020,0x00100000, 0x80008020,0x80100000,0x80108000,0x00008000, +0x80100000,0x80008000,0x00000020,0x80108020, 0x00108020,0x00000020,0x00008000,0x80000000, +0x00008020,0x80108000,0x00100000,0x80000020, 0x00100020,0x80008020,0x80000020,0x00100020, +0x00108000,0x00000000,0x80008000,0x00008020, 0x80000000,0x80100020,0x80108020,0x00108000}, +{ +0x00000208,0x08020200,0x00000000,0x08020008, 0x08000200,0x00000000,0x00020208,0x08000200, +0x00020008,0x08000008,0x08000008,0x00020000, 0x08020208,0x00020008,0x08020000,0x00000208, +0x08000000,0x00000008,0x08020200,0x00000200, 0x00020200,0x08020000,0x08020008,0x00020208, +0x08000208,0x00020200,0x00020000,0x08000208, 0x00000008,0x08020208,0x00000200,0x08000000, +0x08020200,0x08000000,0x00020008,0x00000208, 0x00020000,0x08020200,0x08000200,0x00000000, +0x00000200,0x00020008,0x08020208,0x08000200, 0x08000008,0x00000200,0x00000000,0x08020008, +0x08000208,0x00020000,0x08000000,0x08020208, 0x00000008,0x00020208,0x00020200,0x08000008, +0x08020000,0x08000208,0x00000208,0x08020000, 0x00020208,0x00000008,0x08020008,0x00020200}, +{ +0x00802001,0x00002081,0x00002081,0x00000080, 0x00802080,0x00800081,0x00800001,0x00002001, +0x00000000,0x00802000,0x00802000,0x00802081, 0x00000081,0x00000000,0x00800080,0x00800001, +0x00000001,0x00002000,0x00800000,0x00802001, 0x00000080,0x00800000,0x00002001,0x00002080, +0x00800081,0x00000001,0x00002080,0x00800080, 0x00002000,0x00802080,0x00802081,0x00000081, +0x00800080,0x00800001,0x00802000,0x00802081, 0x00000081,0x00000000,0x00000000,0x00802000, +0x00002080,0x00800080,0x00800081,0x00000001, 0x00802001,0x00002081,0x00002081,0x00000080, +0x00802081,0x00000081,0x00000001,0x00002000, 0x00800001,0x00002001,0x00802080,0x00800081, +0x00002001,0x00002080,0x00800000,0x00802001, 0x00000080,0x00800000,0x00002000,0x00802080}, +{ +0x00000100,0x02080100,0x02080000,0x42000100, 0x00080000,0x00000100,0x40000000,0x02080000, +0x40080100,0x00080000,0x02000100,0x40080100, 0x42000100,0x42080000,0x00080100,0x40000000, +0x02000000,0x40080000,0x40080000,0x00000000, 0x40000100,0x42080100,0x42080100,0x02000100, +0x42080000,0x40000100,0x00000000,0x42000000, 0x02080100,0x02000000,0x42000000,0x00080100, +0x00080000,0x42000100,0x00000100,0x02000000, 0x40000000,0x02080000,0x42000100,0x40080100, +0x02000100,0x40000000,0x42080000,0x02080100, 0x40080100,0x00000100,0x02000000,0x42080000, +0x42080100,0x00080100,0x42000000,0x42080100, 0x02080000,0x00000000,0x40080000,0x42000000, +0x00080100,0x02000100,0x40000100,0x00080000, 0x00000000,0x40080000,0x02080100,0x40000100}, +{ +0x20000010,0x20400000,0x00004000,0x20404010, 0x20400000,0x00000010,0x20404010,0x00400000, +0x20004000,0x00404010,0x00400000,0x20000010, 0x00400010,0x20004000,0x20000000,0x00004010, +0x00000000,0x00400010,0x20004010,0x00004000, 0x00404000,0x20004010,0x00000010,0x20400010, +0x20400010,0x00000000,0x00404010,0x20404000, 0x00004010,0x00404000,0x20404000,0x20000000, +0x20004000,0x00000010,0x20400010,0x00404000, 0x20404010,0x00400000,0x00004010,0x20000010, +0x00400000,0x20004000,0x20000000,0x00004010, 0x20000010,0x20404010,0x00404000,0x20400000, +0x00404010,0x20404000,0x00000000,0x20400010, 0x00000010,0x00004000,0x20400000,0x00404010, +0x00004000,0x00400010,0x20004010,0x00000000, 0x20404000,0x20000000,0x00400010,0x20004010}, +{ +0x00200000,0x04200002,0x04000802,0x00000000, 0x00000800,0x04000802,0x00200802,0x04200800, +0x04200802,0x00200000,0x00000000,0x04000002, 0x00000002,0x04000000,0x04200002,0x00000802, +0x04000800,0x00200802,0x00200002,0x04000800, 0x04000002,0x04200000,0x04200800,0x00200002, +0x04200000,0x00000800,0x00000802,0x04200802, 0x00200800,0x00000002,0x04000000,0x00200800, +0x04000000,0x00200800,0x00200000,0x04000802, 0x04000802,0x04200002,0x04200002,0x00000002, +0x00200002,0x04000000,0x04000800,0x00200000, 0x04200800,0x00000802,0x00200802,0x04200800, +0x00000802,0x04000002,0x04200802,0x04200000, 0x00200800,0x00000000,0x00000002,0x04200802, +0x00000000,0x00200802,0x04200000,0x00000800, 0x04000002,0x04000800,0x00000800,0x00200002}, +{ +0x10001040,0x00001000,0x00040000,0x10041040, 0x10000000,0x10001040,0x00000040,0x10000000, +0x00040040,0x10040000,0x10041040,0x00041000, 0x10041000,0x00041040,0x00001000,0x00000040, +0x10040000,0x10000040,0x10001000,0x00001040, 0x00041000,0x00040040,0x10040040,0x10041000, +0x00001040,0x00000000,0x00000000,0x10040040, 0x10000040,0x10001000,0x00041040,0x00040000, +0x00041040,0x00040000,0x10041000,0x00001000, 0x00000040,0x10040040,0x00001000,0x00041040, +0x10001000,0x00000040,0x10000040,0x10040000, 0x10040040,0x10000000,0x00040000,0x10001040, +0x00000000,0x10041040,0x00040040,0x10000040, 0x10040000,0x10001000,0x10001040,0x00000000, +0x10041040,0x00041000,0x00041000,0x00001040, 0x00001040,0x00040040,0x10000000,0x10041000} +}; + + +/* 32-bit permutation function P used on the output of the S-boxes */ +const TUint8 p32i[] = { + 16, 7, 20, 21, + 29, 12, 28, 17, + 1, 15, 23, 26, + 5, 18, 31, 10, + 2, 8, 24, 14, + 32, 27, 3, 9, + 19, 13, 30, 6, + 22, 11, 4, 25 +}; + +/* permuted choice table (key) */ +const TUint8 pc1[] = { + 57, 49, 41, 33, 25, 17, 9, + 1, 58, 50, 42, 34, 26, 18, + 10, 2, 59, 51, 43, 35, 27, + 19, 11, 3, 60, 52, 44, 36, + + 63, 55, 47, 39, 31, 23, 15, + 7, 62, 54, 46, 38, 30, 22, + 14, 6, 61, 53, 45, 37, 29, + 21, 13, 5, 28, 20, 12, 4 +}; + +/* number left rotations of pc1 */ +const TUint8 totrot[] = {1,2,4,6,8,10,12,14,15,17,19,21,23,25,27,28}; + +/* permuted choice key (table) */ +const TUint8 pc2[] = { + 14, 17, 11, 24, 1, 5, + 3, 28, 15, 6, 21, 10, + 23, 19, 12, 4, 26, 8, + 16, 7, 27, 20, 13, 2, + 41, 52, 31, 37, 47, 55, + 30, 40, 51, 45, 33, 48, + 44, 49, 39, 56, 34, 53, + 46, 42, 50, 36, 29, 32 +}; +} // namespace DES_TABLE +#endif // __DESTABLES_H__ diff -r 7e3f204e6c81 -r f9c11be8c0b3 cryptoplugins/cryptospiplugins/source/softwarecrypto/dhimpl.cpp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/cryptoplugins/cryptospiplugins/source/softwarecrypto/dhimpl.cpp Tue Dec 01 11:12:04 2009 +0000 @@ -0,0 +1,105 @@ +/* +* Copyright (c) 2006-2009 Nokia Corporation and/or its subsidiary(-ies). +* All rights reserved. +* This component and the accompanying materials are made available +* under the terms of the License "Eclipse Public License v1.0" +* which accompanies this distribution, and is available +* at the URL "http://www.eclipse.org/legal/epl-v10.html". +* +* Initial Contributors: +* Nokia Corporation - initial contribution. +* +* Contributors: +* +* Description: +* +*/ + + +#include "dhimpl.h" +#include "pluginconfig.h" + +using namespace SoftwareCrypto; +using namespace CryptoSpi; + +/* CDHImpl */ +CDHImpl::CDHImpl() + { + } + +CDHImpl::~CDHImpl() + { + } + +CDHImpl* CDHImpl::NewL(const CKey& aPrivateKey, const CCryptoParams* aParams) + { + CDHImpl* self = CDHImpl::NewLC(aPrivateKey, aParams); + CleanupStack::Pop(self); + return self; + } + +CDHImpl* CDHImpl::NewLC(const CKey& aPrivateKey, const CCryptoParams* aParams) + { + CDHImpl* self = new(ELeave) CDHImpl(); + CleanupStack::PushL(self); + self->ConstructL(aPrivateKey, aParams); + return self; + } + +CKey* CDHImpl::AgreeL(const CKey& aOtherPublicKey, const CCryptoParams* aParams) + { + /* + * unpack the parameters, we're expecting the N and G parameters + */ + const TInteger& N = aParams->GetBigIntL(KDhKeyParameterNUid); + const TInteger& G = aParams->GetBigIntL(KDhKeyParameterGUid); + const TInteger& privateN = iSharedParams->GetBigIntL(KDhKeyParameterNUid); + const TInteger& privateG = iSharedParams->GetBigIntL(KDhKeyParameterGUid); + const TInteger& X = aOtherPublicKey.GetBigIntL(KDhKeyParameterXUid); + const TInteger& x = iPrivateKey->GetBigIntL(KDhKeyParameterxUid); + + /* + * both DH keys (ie our private and their public keys) must use the same N and G parameters + */ + if ((N != privateN) || (G != privateG)) + { + User::Leave(KErrArgument); + } + + /* + * do the key agreement algo X ^ x mod N + */ + RInteger result = TInteger::ModularExponentiateL(X, x, N); + CleanupClosePushL(result); + + /* + * create the agreed key + */ + CCryptoParams* agreedKeyParameters = CCryptoParams::NewLC(); + agreedKeyParameters->AddL(result, KSymmetricKeyParameterUid); + TKeyProperty agreedKeyProperties = {KDHAgreementUid, KCryptoPluginDhKeyAgreementUid, + KDHAgreedKeyUid, KNonEmbeddedKeyUid }; + CKey* agreedKey = CKey::NewL(agreedKeyProperties, *agreedKeyParameters); + + // cleanup result, agreedKeyParameters + CleanupStack::PopAndDestroy(2, &result); + return agreedKey; + } + +TUid CDHImpl::ImplementationUid() const + { + return KCryptoPluginDhKeyAgreementUid; + } + +CExtendedCharacteristics* CDHImpl::CreateExtendedCharacteristicsL() + { + // All Symbian software plug-ins have unlimited concurrency, cannot be + // reserved for exclusive use and are not CERTIFIED to be standards compliant. + return CExtendedCharacteristics::NewL(KMaxTInt, EFalse); + } + +const CExtendedCharacteristics* CDHImpl::GetExtendedCharacteristicsL() + { + return CDHImpl::CreateExtendedCharacteristicsL(); + } + diff -r 7e3f204e6c81 -r f9c11be8c0b3 cryptoplugins/cryptospiplugins/source/softwarecrypto/dhimpl.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/cryptoplugins/cryptospiplugins/source/softwarecrypto/dhimpl.h Tue Dec 01 11:12:04 2009 +0000 @@ -0,0 +1,66 @@ +/* +* Copyright (c) 2006-2009 Nokia Corporation and/or its subsidiary(-ies). +* All rights reserved. +* This component and the accompanying materials are made available +* under the terms of the License "Eclipse Public License v1.0" +* which accompanies this distribution, and is available +* at the URL "http://www.eclipse.org/legal/epl-v10.html". +* +* Initial Contributors: +* Nokia Corporation - initial contribution. +* +* Contributors: +* +* Description: +* +*/ + + +#ifndef __DHIMPL_H__ +#define __DHIMPL_H__ + +/** +@file +@internalComponent +@released +*/ + +#include +#include "keyagreementimpl.h" +#include "dhimpl.h" + +/** + * Implementation of DH Key Agreement as described in PKCS#3. + */ +namespace SoftwareCrypto + { + using namespace CryptoSpi; + + NONSHARABLE_CLASS(CDHImpl) : public CKeyAgreementImpl + { + public: + + static CDHImpl* NewL(const CKey& aPrivateKey, const CCryptoParams* aParams); + static CDHImpl* NewLC(const CKey& aPrivateKey, const CCryptoParams* aParams); + + // Destructor + ~CDHImpl(); + + // from MKeyAgreement + CKey* AgreeL(const CKey& aOtherPublicKey, const CCryptoParams* aParams); + + // Override CKeyAgreementImpl virtual functions + TUid ImplementationUid() const; + + static CExtendedCharacteristics* CreateExtendedCharacteristicsL(); + const CExtendedCharacteristics* GetExtendedCharacteristicsL(); + + private: + /** + Constructor + */ + CDHImpl(); + }; + } + +#endif // __DHIMPL_H__ diff -r 7e3f204e6c81 -r f9c11be8c0b3 cryptoplugins/cryptospiplugins/source/softwarecrypto/dhkeypairgenimpl.cpp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/cryptoplugins/cryptospiplugins/source/softwarecrypto/dhkeypairgenimpl.cpp Tue Dec 01 11:12:04 2009 +0000 @@ -0,0 +1,154 @@ +/* +* Copyright (c) 2007-2009 Nokia Corporation and/or its subsidiary(-ies). +* All rights reserved. +* This component and the accompanying materials are made available +* under the terms of the License "Eclipse Public License v1.0" +* which accompanies this distribution, and is available +* at the URL "http://www.eclipse.org/legal/epl-v10.html". +* +* Initial Contributors: +* Nokia Corporation - initial contribution. +* +* Contributors: +* +* Description: +* +*/ + + +#include "dhkeypairgenimpl.h" +#include "pluginconfig.h" +#include "keypair.h" + +using namespace SoftwareCrypto; +using namespace CryptoSpi; + +/* CDHKeyPairGenImpl */ +CDHKeyPairGenImpl::CDHKeyPairGenImpl() + { + + } + +CDHKeyPairGenImpl::~CDHKeyPairGenImpl() + { + + } + +CDHKeyPairGenImpl* CDHKeyPairGenImpl::NewL(void) + { + CDHKeyPairGenImpl* self = CDHKeyPairGenImpl::NewLC(); + CleanupStack::Pop(self); + return self; + } + +CDHKeyPairGenImpl* CDHKeyPairGenImpl::NewLC(void) + { + CDHKeyPairGenImpl* self = new(ELeave) CDHKeyPairGenImpl(); + CleanupStack::PushL(self); + self->ConstructL(); + return self; + } + +void CDHKeyPairGenImpl::ConstructL(void) + { + CKeyPairGenImpl::ConstructL(); + } + +CExtendedCharacteristics* CDHKeyPairGenImpl::CreateExtendedCharacteristicsL() + { + // All Symbian software plug-ins have unlimited concurrency, cannot be reserved + // for exclusive use and are not CERTIFIED to be standards compliant. + return CExtendedCharacteristics::NewL(KMaxTInt, EFalse); + } + +const CExtendedCharacteristics* CDHKeyPairGenImpl::GetExtendedCharacteristicsL() + { + return CDHKeyPairGenImpl::CreateExtendedCharacteristicsL(); + } + +TUid CDHKeyPairGenImpl::ImplementationUid() const + { + return KCryptoPluginDhKeyPairGenUid; + } + +void CDHKeyPairGenImpl::Reset() + { + // does nothing in this plugin + } + +void CDHKeyPairGenImpl::GenerateKeyPairL(TInt /*aKeySize*/, const CCryptoParams& aKeyParameters, CKeyPair*& aKeyPair) + { + /* + * unpack the parameters, we're expecting the N and G parameters and if present the x parameter (aka private key) + */ + const TInteger& N = aKeyParameters.GetBigIntL(KDhKeyParameterNUid); + const TInteger& G = aKeyParameters.GetBigIntL(KDhKeyParameterGUid); + + /* + * do some sanity checking + */ + RInteger nminus2 = RInteger::NewL(N); + CleanupStack::PushL(nminus2); + --nminus2; + --nminus2; + + if ((G < TInteger::Two()) || (G > nminus2)) + { + User::Leave(KErrArgument); + } + + /* + * has a private key x been supplied? if not then generate it + */ + RInteger x; + if (aKeyParameters.IsPresent(KDhKeyParameterxUid)) + { + x = RInteger::NewL(aKeyParameters.GetBigIntL(KDhKeyParameterxUid)); + } + else + { + // find a random x | 1 <= x <= n-2 + x = RInteger::NewRandomL(TInteger::One(), nminus2); + } + CleanupClosePushL(x); + /* + * generate the public key with X = G^(x) mod N + */ + RInteger X = TInteger::ModularExponentiateL(G, x, N); + CleanupClosePushL(X); + + /* + * create the keys parameters + */ + CCryptoParams* publicKeyParameters = CCryptoParams::NewLC(); + publicKeyParameters->AddL(X, KDhKeyParameterXUid); + TKeyProperty publicKeyProperties = {KDHKeyPairGeneratorUid, KCryptoPluginDhKeyPairGenUid, + KDHPublicKeyUid, KNonEmbeddedKeyUid }; + CCryptoParams* privateKeyParameters = CCryptoParams::NewLC(); + privateKeyParameters->AddL(x, KDhKeyParameterxUid); + TKeyProperty privateKeyProperties = {KDHKeyPairGeneratorUid, KCryptoPluginDhKeyPairGenUid, + KDHPrivateKeyUid, KNonEmbeddedKeyUid }; + + /* + * create the public key + */ + CKey* publicKey = CKey::NewL(publicKeyProperties, *publicKeyParameters); + CleanupStack::PushL(publicKey); + + /* + * create the private key + */ + CKey* privateKey = CKey::NewL(privateKeyProperties, *privateKeyParameters); + CleanupStack::PushL(privateKey); + + /* + * create the key pair + */ + aKeyPair = CKeyPair::NewL(publicKey, privateKey); + + /* + * cleanup stack - it should contain nminus2, x (if allocated here), X, publicKeyParameters, privateKeyParameters, publicKey and privateKey + */ + CleanupStack::Pop(2, publicKey); + CleanupStack::PopAndDestroy(5, &nminus2); + } diff -r 7e3f204e6c81 -r f9c11be8c0b3 cryptoplugins/cryptospiplugins/source/softwarecrypto/dhkeypairgenimpl.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/cryptoplugins/cryptospiplugins/source/softwarecrypto/dhkeypairgenimpl.h Tue Dec 01 11:12:04 2009 +0000 @@ -0,0 +1,72 @@ +/* +* Copyright (c) 2007-2009 Nokia Corporation and/or its subsidiary(-ies). +* All rights reserved. +* This component and the accompanying materials are made available +* under the terms of the License "Eclipse Public License v1.0" +* which accompanies this distribution, and is available +* at the URL "http://www.eclipse.org/legal/epl-v10.html". +* +* Initial Contributors: +* Nokia Corporation - initial contribution. +* +* Contributors: +* +* Description: +* +*/ + + +#ifndef __DHKEYPAIRGENIMPL_H__ +#define __DHKEYPAIRGENIMPL_H__ + +/** +@file +@internalComponent +@released +*/ + +#include +#include +#include "keypairgenimpl.h" + +/** + * Implementation of DH Key Pair Generation as described in PKCS#3. + */ +namespace SoftwareCrypto + { +using namespace CryptoSpi; + + NONSHARABLE_CLASS(CDHKeyPairGenImpl) : public CKeyPairGenImpl + { + public: + + static CDHKeyPairGenImpl* NewL(void); + static CDHKeyPairGenImpl* NewLC(void); + + // Destructor + ~CDHKeyPairGenImpl(); + + // from MPlugin + void Reset(); + + // from MKeyPairGenerator + void GenerateKeyPairL(TInt aKeySize, const CCryptoParams& aKeyParameters, CKeyPair*& aKeyPair); + + // Override CKeyPairGenImpl virtual functions + TUid ImplementationUid() const; + + const CExtendedCharacteristics* GetExtendedCharacteristicsL(); + static CExtendedCharacteristics* CreateExtendedCharacteristicsL(); + + private: + /** + Constructor + */ + CDHKeyPairGenImpl(); + void ConstructL(void); + + private: + }; + } + +#endif // __DHKEYPAIRGENIMPL_H__ diff -r 7e3f204e6c81 -r f9c11be8c0b3 cryptoplugins/cryptospiplugins/source/softwarecrypto/dsakeypairgenimpl.cpp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/cryptoplugins/cryptospiplugins/source/softwarecrypto/dsakeypairgenimpl.cpp Tue Dec 01 11:12:04 2009 +0000 @@ -0,0 +1,383 @@ +/* +* Copyright (c) 2007-2009 Nokia Corporation and/or its subsidiary(-ies). +* All rights reserved. +* This component and the accompanying materials are made available +* under the terms of the License "Eclipse Public License v1.0" +* which accompanies this distribution, and is available +* at the URL "http://www.eclipse.org/legal/epl-v10.html". +* +* Initial Contributors: +* Nokia Corporation - initial contribution. +* +* Contributors: +* +* Description: +* DSA Keypair implementation +* DSA keypair generation implementation +* +*/ + + +/** + @file +*/ + +#include "dsakeypairgenimpl.h" +#include "pluginconfig.h" +#include "keypair.h" +#include "common/inlines.h" // For TClassSwap +#include "mont.h" +#include "sha1impl.h" +#include + + +const TUint KShaSize = 20; +const TUint KMinPrimeLength = 512; +const TUint KMaxPrimeLength = 1024; +const TUint KPrimeLengthMultiple = 64; + +using namespace SoftwareCrypto; + + +/* CDSAPrimeCertificate */ + +CDSAPrimeCertificate* CDSAPrimeCertificate::NewL(const TDesC8& aSeed, TUint aCounter) + { + CDSAPrimeCertificate* self = NewLC(aSeed, aCounter); + CleanupStack::Pop(); + return self; + } + +CDSAPrimeCertificate* CDSAPrimeCertificate::NewLC(const TDesC8& aSeed, TUint aCounter) + { + CDSAPrimeCertificate* self = new(ELeave) CDSAPrimeCertificate(aCounter); + CleanupStack::PushL(self); + self->ConstructL(aSeed); + return self; + } + +const TDesC8& CDSAPrimeCertificate::Seed() const + { + return *iSeed; + } + +TUint CDSAPrimeCertificate::Counter() const + { + return iCounter; + } + +CDSAPrimeCertificate::~CDSAPrimeCertificate() + { + delete const_cast(iSeed); + } + +void CDSAPrimeCertificate::ConstructL(const TDesC8& aSeed) + { + iSeed = aSeed.AllocL(); + } + +CDSAPrimeCertificate::CDSAPrimeCertificate(TUint aCounter) + : iCounter(aCounter) + { + } + +CDSAPrimeCertificate::CDSAPrimeCertificate() + { + } + + +/* CDSAKeyPairGenImpl */ +CDSAKeyPairGenImpl::CDSAKeyPairGenImpl() + { + } + +CDSAKeyPairGenImpl::~CDSAKeyPairGenImpl() + { + delete iPrimeCertificate; + } + +CDSAKeyPairGenImpl* CDSAKeyPairGenImpl::NewL() + { + CDSAKeyPairGenImpl* self = CDSAKeyPairGenImpl::NewLC(); + CleanupStack::Pop(self); + return self; + } + +CDSAKeyPairGenImpl* CDSAKeyPairGenImpl::NewLC() + { + CDSAKeyPairGenImpl* self = new(ELeave) CDSAKeyPairGenImpl(); + CleanupStack::PushL(self); + self->ConstructL(); + return self; + } + +void CDSAKeyPairGenImpl::ConstructL(void) + { + CKeyPairGenImpl::ConstructL(); + } + +CExtendedCharacteristics* CDSAKeyPairGenImpl::CreateExtendedCharacteristicsL() + { + // All Symbian software plug-ins have unlimited concurrency, cannot be reserved + // for exclusive use and are not CERTIFIED to be standards compliant. + return CExtendedCharacteristics::NewL(KMaxTInt, EFalse); + } + +const CExtendedCharacteristics* CDSAKeyPairGenImpl::GetExtendedCharacteristicsL() + { + return CDSAKeyPairGenImpl::CreateExtendedCharacteristicsL(); + } + +TUid CDSAKeyPairGenImpl::ImplementationUid() const + { + return KCryptoPluginDsaKeyPairGenUid; + } + +void CDSAKeyPairGenImpl::Reset() + { + // does nothing in this plugin + } + +TBool CDSAKeyPairGenImpl::ValidPrimeLength(TUint aPrimeBits) + { + return (aPrimeBits >= KMinPrimeLength && + aPrimeBits <= KMaxPrimeLength && + aPrimeBits % KPrimeLengthMultiple == 0); + } + +TBool CDSAKeyPairGenImpl::GeneratePrimesL(const TDesC8& aSeed, + TUint& aCounter, + RInteger& aP, + TUint aL, + RInteger& aQ, + TBool aUseInputCounter) + { + //This follows the steps in FIPS 186-2 + //See DSS Appendix 2.2 + //Note. Step 1 is performed prior to calling GeneratePrimesL, so that this + //routine can be used for both generation and validation. + //Step 1. Choose an arbitrary sequence of at least 160 bits and call it + //SEED. Let g be the length of SEED in bits. + + if(!ValidPrimeLength(aL)) + { + User::Leave(KErrNotSupported); + } + + CSHA1Impl* sha1 = CSHA1Impl::NewL(); + CleanupStack::PushL(sha1); + + HBufC8* seedBuf = aSeed.AllocLC(); + TPtr8 seed = seedBuf->Des(); + TUint gBytes = aSeed.Size(); + + //Note that the DSS's g = BytesToBits(gBytes) ie. the number of random bits + //in the seed. + //This function has made the assumption (for ease of computation) that g%8 + //is 0. Ie the seed is a whole number of random bytes. + TBuf8 U; + TBuf8 temp; + const TUint n = (aL-1)/160; + const TUint b = (aL-1)%160; + HBufC8* Wbuf = HBufC8::NewMaxLC((n+1) * KShaSize); + TUint8* W = const_cast(Wbuf->Ptr()); + + U.Copy(sha1->Final(seed)); + + //Step 2. U = SHA-1[SEED] XOR SHA-1[(SEED+1) mod 2^g] + for(TInt i=gBytes - 1, carry=ETrue; i>=0 && carry; i--) + { + //!++(TUint) adds one to the current word which if it overflows to zero + //sets carry to 1 thus letting the loop continue. It's a poor man's + //multi-word addition. Swift eh? + carry = !++(seed[i]); + } + + temp.Copy(sha1->Final(seed)); + XorBuf(const_cast(U.Ptr()), temp.Ptr(), KShaSize); + + //Step 3. Form q from U by setting the most significant bit (2^159) + //and the least significant bit to 1. + U[0] |= 0x80; + U[KShaSize-1] |= 1; + + aQ = RInteger::NewL(U); + CleanupStack::PushL(aQ); + + //Step 4. Use a robust primality testing algo to test if q is prime + //The robust part is the calling codes problem. This will use whatever + //random number generator you set for the thread. To attempt FIPS 186-2 + //compliance, set a FIPS 186-2 compliant RNG. + if( !aQ.IsPrimeL() ) + { + //Step 5. If not exit and get a new seed + CleanupStack::PopAndDestroy(4, sha1); + return EFalse; + } + + TUint counterEnd = aUseInputCounter ? aCounter+1 : 4096; + + //Step 6. Let counter = 0 and offset = 2 + //Note 1. that the DSS speaks of SEED + offset + k because they always + //refer to a constant SEED. We update our seed as we go so the offset + //variable has already been added to seed in the previous iterations. + //Note 2. We've already added 1 to our seed, so the first time through this + //the offset in DSS speak will be 2. + for(TUint counter=0; counter < counterEnd; counter++) + { + //Step 7. For k=0, ..., n let + // Vk = SHA-1[(SEED + offset + k) mod 2^g] + //I'm storing the Vk's inside of a big W buffer. + for(TUint k=0; k<=n; k++) + { + for(TInt i=gBytes-1, carry=ETrue; i>=0 && carry; i--) + { + carry = !++(seed[i]); + } + if(!aUseInputCounter || counter == aCounter) + { + TPtr8 Wptr(W+(n-k)*KShaSize, gBytes); + Wptr.Copy(sha1->Final(seed)); + } + } + if(!aUseInputCounter || counter == aCounter) + { + //Step 8. Let W be the integer... and let X = W + 2^(L-1) + const_cast((*Wbuf)[KShaSize - 1 - b/8]) |= 0x80; + TPtr8 Wptr(W + KShaSize - 1 - b/8, aL/8, aL/8); + RInteger X = RInteger::NewL(Wptr); + CleanupStack::PushL(X); + //Step 9. Let c = X mod 2q and set p = X - (c-1) + RInteger twoQ = aQ.TimesL(TInteger::Two()); + CleanupStack::PushL(twoQ); + RInteger c = X.ModuloL(twoQ); + CleanupStack::PushL(c); + --c; + aP = X.MinusL(c); + CleanupStack::PopAndDestroy(3, &X); //twoQ, c, X + CleanupStack::PushL(aP); + + //Step 10 and 11: if p >= 2^(L-1) and p is prime + if( aP.Bit(aL-1) && aP.IsPrimeL() ) + { + aCounter = counter; + CleanupStack::Pop(2, &aQ); + CleanupStack::PopAndDestroy(3, sha1); + return ETrue; + } + CleanupStack::PopAndDestroy(&aP); + } + } + CleanupStack::PopAndDestroy(4, &sha1); + return EFalse; + } + +void CDSAKeyPairGenImpl::GenerateKeyPairL(TInt aKeySize, + const CCryptoParams& aKeyParameters, + CKeyPair*& aKeyPair) + { + //This is the first step of DSA prime generation. The remaining steps are + //performed in CDSAParameters::GeneratePrimesL + //Step 1. Choose an arbitrary sequence of at least 160 bits and call it + //SEED. Let g be the length of SEED in bits. + TBuf8 seed(KShaSize); + TUint c; + RInteger p; + RInteger q; + + do + { + GenerateRandomBytesL(seed); + } + while(!GeneratePrimesL(seed, c, p, aKeySize, q)); + + //Double PushL will not fail as GeneratePrimesL uses the CleanupStack + //(at least one push and pop ;) + CleanupStack::PushL(p); + CleanupStack::PushL(q); + + iPrimeCertificate = CDSAPrimeCertificate::NewL(seed, c); + + // aKeyParameters isn't const here anymore + CCryptoParams& paramRef=const_cast(aKeyParameters); + paramRef.AddL(c, KDsaKeyGenerationCounterUid); + paramRef.AddL(seed, KDsaKeyGenerationSeedUid); + + CMontgomeryStructure* montP = CMontgomeryStructure::NewLC(p); + + --p; + + // e = (p-1)/q + RInteger e = p.DividedByL(q); + CleanupStack::PushL(e); + + --p; //now it's p-2 :) + + RInteger h; + const TInteger* g = 0; + do + { + // find a random h | 1 < h < p-1 + h = RInteger::NewRandomL(TInteger::Two(), p); + CleanupStack::PushL(h); + // g = h^e mod p + g = &(montP->ExponentiateL(h, e)); + CleanupStack::PopAndDestroy(&h); + } + while( *g <= TInteger::One() ); + CleanupStack::PopAndDestroy(&e); + + ++p; //reincrement p to original value + ++p; + + + RInteger g1 = RInteger::NewL(*g); //take a copy of montP's g + CleanupStack::PushL(g1); + --q; + // select random x | 0 < x < q + RInteger x = RInteger::NewRandomL(TInteger::One(), q); + CleanupStack::PushL(x); + ++q; + + // + // create the keys parameters + CCryptoParams* privateKeyParameters = CCryptoParams::NewLC(); + privateKeyParameters->AddL(p, KDsaKeyParameterPUid); + privateKeyParameters->AddL(q, KDsaKeyParameterQUid); + privateKeyParameters->AddL(g1, KDsaKeyParameterGUid); + privateKeyParameters->AddL(x, KDsaKeyParameterXUid); + TKeyProperty privateKeyProperties = {KDSAKeyPairGeneratorUid, + KCryptoPluginDsaKeyPairGenUid, + KDsaPrivateKeyUid, + KNonEmbeddedKeyUid}; + + CCryptoParams* publicKeyParameters = CCryptoParams::NewLC(); + publicKeyParameters->AddL(p, KDsaKeyParameterPUid); + publicKeyParameters->AddL(q, KDsaKeyParameterQUid); + publicKeyParameters->AddL(g1, KDsaKeyParameterGUid); + RInteger y = RInteger::NewL(montP->ExponentiateL(*g, x)); + CleanupStack::PushL(y); + publicKeyParameters->AddL(y, KDsaKeyParameterYUid); + TKeyProperty publicKeyProperties = {KDSAKeyPairGeneratorUid, + KCryptoPluginDsaKeyPairGenUid, + KDsaPublicKeyUid, + KNonEmbeddedKeyUid}; + + // + // create the private key + // + CKey* privateKey = CKey::NewL(privateKeyProperties, *privateKeyParameters); + CleanupStack::PushL(privateKey); + + // + // create the public key + // + CKey* publicKey = CKey::NewL(publicKeyProperties, *publicKeyParameters); + CleanupStack::PushL(publicKey); + + aKeyPair = CKeyPair::NewL(publicKey, privateKey); + + //publicKey, publicKeyParameters, y, privateKey, privateKeyParameters, x, g1, montP, q, p + CleanupStack::Pop(2, privateKey); + CleanupStack::PopAndDestroy(8, &p); + } diff -r 7e3f204e6c81 -r f9c11be8c0b3 cryptoplugins/cryptospiplugins/source/softwarecrypto/dsakeypairgenimpl.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/cryptoplugins/cryptospiplugins/source/softwarecrypto/dsakeypairgenimpl.h Tue Dec 01 11:12:04 2009 +0000 @@ -0,0 +1,153 @@ +/* +* Copyright (c) 2007-2009 Nokia Corporation and/or its subsidiary(-ies). +* All rights reserved. +* This component and the accompanying materials are made available +* under the terms of the License "Eclipse Public License v1.0" +* which accompanies this distribution, and is available +* at the URL "http://www.eclipse.org/legal/epl-v10.html". +* +* Initial Contributors: +* Nokia Corporation - initial contribution. +* +* Contributors: +* +* Description: +* +*/ + + +#ifndef __DSAKEYPAIRGENIMPL_H__ +#define __DSAKEYPAIRGENIMPL_H__ + +/** +@file +@internalComponent +@released +*/ + +#include +#include +#include "keypairgenimpl.h" +//#include + +/** + * Implementation of DSA key pair generation. + */ +namespace SoftwareCrypto + { + NONSHARABLE_CLASS(CDSAPrimeCertificate) : public CBase + { + public: + /** + Creates a new DSA prime certificate from a specified + seed and counter value. + + @param aSeed The seed from a DSA key generation process + @param aCounter The counter value from a DSA key generation process + @return A pointer to a CDSAPrimeCertificate instance + */ + static CDSAPrimeCertificate* NewL(const TDesC8& aSeed, TUint aCounter); + + /** + Creates a new DSA prime certificate from a specified + seed and counter value. + + The returned pointer is put onto the cleanup stack. + + @param aSeed The seed from a DSA key generation process + @param aCounter The counter value from a DSA key generation process + @return A pointer to a CDSAPrimeCertificate instance + */ + static CDSAPrimeCertificate* NewLC(const TDesC8& aSeed, TUint aCounter); + + /** + Gets the seed of the DSA prime certificate + @return The seed + */ + const TDesC8& Seed() const; + + /** + Gets the counter value of the DSA prime certificate + + @return The counter's value + */ + TUint Counter() const; + + /** + Destructor + */ + ~CDSAPrimeCertificate(); + + protected: + /** + Constructor + @param aCounter The DSA key generation counter + */ + CDSAPrimeCertificate(TUint aCounter); + + /** + Default constructor + */ + CDSAPrimeCertificate(); + + void ConstructL(const TDesC8& aSeed); + + protected: + /** + The DSA key generation seed + */ + const HBufC8* iSeed; + /** + The DSA key generation counter + */ + TUint iCounter; + private: + CDSAPrimeCertificate(const CDSAPrimeCertificate&); + CDSAPrimeCertificate& operator=(const CDSAPrimeCertificate&); + }; + + NONSHARABLE_CLASS(CDSAKeyPairGenImpl) : public CKeyPairGenImpl + { + public: + + static CDSAKeyPairGenImpl* NewL(); + static CDSAKeyPairGenImpl* NewLC(); + + // from MPlugin + void Reset(); + + // from MKeyPairGenerator + void GenerateKeyPairL(TInt aKeySize, const CCryptoParams& aKeyParameters, CKeyPair*& aKeyPair); + + // Override CKeyPairGenImpl virtual functions + TUid ImplementationUid() const; + + const CExtendedCharacteristics* GetExtendedCharacteristicsL(); + static CExtendedCharacteristics* CreateExtendedCharacteristicsL(); + + // Destructor + ~CDSAKeyPairGenImpl(); + + static TBool GeneratePrimesL(const TDesC8& aSeed, + TUint& aCounter, + RInteger& aP, + TUint aL, + RInteger& aQ, + TBool aUseInputCounter=EFalse); + + static TBool ValidPrimeLength(TUint aPrimeBits); + + private: + /** + Constructor + */ + CDSAKeyPairGenImpl(); + + /// second phase of construction + void ConstructL(); + + CDSAPrimeCertificate* iPrimeCertificate; + }; + } + +#endif // __DSAKEYPAIRGENIMPL_H__ diff -r 7e3f204e6c81 -r f9c11be8c0b3 cryptoplugins/cryptospiplugins/source/softwarecrypto/dsasignerimpl.cpp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/cryptoplugins/cryptospiplugins/source/softwarecrypto/dsasignerimpl.cpp Tue Dec 01 11:12:04 2009 +0000 @@ -0,0 +1,137 @@ +/* +* Copyright (c) 2006-2009 Nokia Corporation and/or its subsidiary(-ies). +* All rights reserved. +* This component and the accompanying materials are made available +* under the terms of the License "Eclipse Public License v1.0" +* which accompanies this distribution, and is available +* at the URL "http://www.eclipse.org/legal/epl-v10.html". +* +* Initial Contributors: +* Nokia Corporation - initial contribution. +* +* Contributors: +* +* Description: +* +*/ + + +#include "dsasignerimpl.h" +#include "pluginconfig.h" + +using namespace SoftwareCrypto; + +// Implementation of CDSASignerImpl +CDSASignerImpl* CDSASignerImpl::NewL(const CKey& aKey) + { + CDSASignerImpl* self = CDSASignerImpl::NewLC(aKey); + CleanupStack::Pop(self); + return self; + } + +CDSASignerImpl* CDSASignerImpl::NewLC(const CKey& aKey) + { + CDSASignerImpl* self = new(ELeave) CDSASignerImpl(); + CleanupStack::PushL(self); + self->ConstructL(aKey); + return self; + } + +CDSASignerImpl::CDSASignerImpl() + { + } + +CDSASignerImpl::~CDSASignerImpl() + { + } + +void CDSASignerImpl::ConstructL(const CKey& aKey) + { + CSignerImpl::ConstructL(aKey); + } + +CExtendedCharacteristics* CDSASignerImpl::CreateExtendedCharacteristicsL() + { + // All Symbian software plug-ins have unlimited concurrency, cannot be reserved + // for exclusive use and are not CERTIFIED to be standards compliant. + return CExtendedCharacteristics::NewL(KMaxTInt, EFalse); + } + +const CExtendedCharacteristics* CDSASignerImpl::GetExtendedCharacteristicsL() + { + return CDSASignerImpl::CreateExtendedCharacteristicsL(); + } + +TUid CDSASignerImpl::ImplementationUid() const + { + return KCryptoPluginDsaSignerUid; + } + +void CDSASignerImpl::SetKeyL(const CKey& aPrivateKey) + { + DoSetKeyL(aPrivateKey); + Reset(); + } + +TInt CDSASignerImpl::GetMaximumInputLengthL() const + { + return KSha1HashLength; + } + +void CDSASignerImpl::SignL(const TDesC8& aInput, CCryptoParams& aSignature) + { + + //see HAC 11.56 or DSS section 5 + //I'll follow HAC as I like its description better + //We don't check that r and s are non both non-null like the DSS + //states you _optionally_ can. The chances of this are _incredibly_ small. + //You've got a much better chance of a bit failure ocurring in the hardware + //than this. + + const TInteger& tQ=iKey->GetBigIntL(KDsaKeyParameterQUid); + + // a) Select a random secret integer (k | 0 < k < q) + RInteger qminus1 = RInteger::NewL(tQ); + CleanupStack::PushL(qminus1); + --qminus1; + RInteger k = RInteger::NewRandomL(TInteger::One(), qminus1); + CleanupStack::PopAndDestroy(&qminus1); + CleanupStack::PushL(k); + + + // b) compute r = (g^k mod p) mod q + + const TInteger& tG=iKey->GetBigIntL(KDsaKeyParameterGUid); + const TInteger& tP=iKey->GetBigIntL(KDsaKeyParameterPUid); + RInteger r = TInteger::ModularExponentiateL(tG, k, tP); + CleanupStack::PushL(r); + r %=tQ; + + + // c) compute k^(-1) mod q + + RInteger kinv = k.InverseModL(tQ); + CleanupStack::PushL(kinv); + + + // d) compute s = k^(-1) * {h(m) + xr} mod q + // Note that in order to be interoperable, compliant with the DSS, and + // secure, aInput must be the result of a SHA-1 hash + + RInteger hm = RInteger::NewL(aInput); + CleanupStack::PushL(hm); + + const TInteger& tX=iKey->GetBigIntL(KDsaKeyParameterXUid); + RInteger s = tX.TimesL(r); + CleanupStack::PushL(s); + s += hm; + s *= kinv; + s %= tQ; + + + // e) signature for m is the pair (r,s) + aSignature.AddL(r, KDsaSignatureParameterRUid); + aSignature.AddL(s, KDsaSignatureParameterSUid); + + CleanupStack::PopAndDestroy(5, &k); + } diff -r 7e3f204e6c81 -r f9c11be8c0b3 cryptoplugins/cryptospiplugins/source/softwarecrypto/dsasignerimpl.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/cryptoplugins/cryptospiplugins/source/softwarecrypto/dsasignerimpl.h Tue Dec 01 11:12:04 2009 +0000 @@ -0,0 +1,91 @@ +/* +* Copyright (c) 2006-2009 Nokia Corporation and/or its subsidiary(-ies). +* All rights reserved. +* This component and the accompanying materials are made available +* under the terms of the License "Eclipse Public License v1.0" +* which accompanies this distribution, and is available +* at the URL "http://www.eclipse.org/legal/epl-v10.html". +* +* Initial Contributors: +* Nokia Corporation - initial contribution. +* +* Contributors: +* +* Description: +* +*/ + + +#ifndef __DSASIGNERIMPL_H__ +#define __DSASIGNERIMPL_H__ + +/** +@file +@internalComponent +@released +*/ + +#include +#include +#include + +#include "signerimpl.h" +#include "common/inlines.h" + +/** + * Implementation of DSA signing + */ +namespace SoftwareCrypto + { + using namespace CryptoSpi; + + NONSHARABLE_CLASS(CDSASignerImpl) : public CSignerImpl + { + public: + /** + Creates an instance of a DSA signer plug-in. + @param aKey The private key used to sign. + @return A pointer to a CDSASignerImpl instance + */ + static CDSASignerImpl* NewL(const CKey& aKey); + + /** + Creates an instance of a DSA signer plug-in. + @param aKey The private key used to sign. + @return A pointer to a CDSASignerImpl instance + */ + static CDSASignerImpl* NewLC(const CKey& aKey); + + // Override CSignerImpl virtual functions + TUid ImplementationUid() const; + // End of CSignerImpl + + // Override MSignatureBase virtual functions + void SetKeyL(const CKey& aPrivateKey); + TInt GetMaximumInputLengthL() const; + // End of MSignatureBase + + // Override MSigner virtual functions + void SignL(const TDesC8& aInput, CCryptoParams& aSignature); + // End of MSigner + + const CExtendedCharacteristics* GetExtendedCharacteristicsL(); + static CExtendedCharacteristics* CreateExtendedCharacteristicsL(); + + /// Destructor + ~CDSASignerImpl(); + + protected: + /// Constructor + CDSASignerImpl(); + + protected: + /// second phase of construction + virtual void ConstructL(const CKey& aKey); + + private: + static const TUint KSha1HashLength = 20; + }; + } + +#endif // __DSASIGNERIMPL_H__ diff -r 7e3f204e6c81 -r f9c11be8c0b3 cryptoplugins/cryptospiplugins/source/softwarecrypto/dsaverifyimpl.cpp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/cryptoplugins/cryptospiplugins/source/softwarecrypto/dsaverifyimpl.cpp Tue Dec 01 11:12:04 2009 +0000 @@ -0,0 +1,160 @@ +/* +* Copyright (c) 2006-2009 Nokia Corporation and/or its subsidiary(-ies). +* All rights reserved. +* This component and the accompanying materials are made available +* under the terms of the License "Eclipse Public License v1.0" +* which accompanies this distribution, and is available +* at the URL "http://www.eclipse.org/legal/epl-v10.html". +* +* Initial Contributors: +* Nokia Corporation - initial contribution. +* +* Contributors: +* +* Description: +* +*/ + + +#include "dsaverifyimpl.h" +#include "pluginconfig.h" + +using namespace SoftwareCrypto; + +// Implementation of CDSAVerifierImpl +CDSAVerifierImpl* CDSAVerifierImpl::NewL(const CKey& aKey) + { + CDSAVerifierImpl* self = CDSAVerifierImpl::NewLC(aKey); + CleanupStack::Pop(self); + return self; + } + +CDSAVerifierImpl* CDSAVerifierImpl::NewLC(const CKey& aKey) + { + CDSAVerifierImpl* self = new(ELeave) CDSAVerifierImpl(); + CleanupStack::PushL(self); + self->ConstructL(aKey); + return self; + } + +CDSAVerifierImpl::CDSAVerifierImpl() + { + } + +CDSAVerifierImpl::~CDSAVerifierImpl() + { + } + +void CDSAVerifierImpl::ConstructL(const CKey& aKey) + { + CVerifierImpl::ConstructL(aKey); + } + +CExtendedCharacteristics* CDSAVerifierImpl::CreateExtendedCharacteristicsL() + { + // All Symbian software plug-ins have unlimited concurrency, cannot be reserved + // for exclusive use and are not CERTIFIED to be standards compliant. + return CExtendedCharacteristics::NewL(KMaxTInt, EFalse); + } + +const CExtendedCharacteristics* CDSAVerifierImpl::GetExtendedCharacteristicsL() + { + return CDSAVerifierImpl::CreateExtendedCharacteristicsL(); + } + +TUid CDSAVerifierImpl::ImplementationUid() const + { + return KCryptoPluginDsaVerifierUid; + } + +void CDSAVerifierImpl::SetKeyL(const CKey& aPublicKey) + { + DoSetKeyL(aPublicKey); + Reset(); + } + +TInt CDSAVerifierImpl::GetMaximumInputLengthL() const + { + return KSha1HashLength; + } + +void CDSAVerifierImpl::VerifyL(const TDesC8& aInput, const CCryptoParams& aSignature, TBool& aVerificationResult) + { + //Retrieve the parameter Q from the key + const TInteger& tQ=iKey->GetBigIntL(KDsaKeyParameterQUid); + + //see HAC 11.56 or DSS section 6 + //I'll follow HAC as I like the description better + + // a) Obtain A's authenticate public key + + // b) Verify that 0 < r < q and 0 < s < q; if not reject signature + + //Retrieve the R&S in DSA signature from the array + + const TInteger& tR=aSignature.GetBigIntL(KDsaSignatureParameterRUid); + const TInteger& tS=aSignature.GetBigIntL(KDsaSignatureParameterSUid); + + if (tR <= 0 || tR >= tQ) + { + aVerificationResult=EFalse; + return; + } + if (tS <= 0 || tS >= tQ) + { + aVerificationResult=EFalse; + return; + } + + + // c) Compute w = s^(-1) mod q and h(m) + RInteger w = tS.InverseModL(tQ); + CleanupStack::PushL(w); + // Note that in order to be interoperable, compliant with the DSS, and + // secure, aInput must be the result of a SHA-1 hash + RInteger hm = RInteger::NewL(aInput); + CleanupStack::PushL(hm); + + // d) Compute u1 = w * hm mod q and u2 = r * w mod q + RInteger u1 = TInteger::ModularMultiplyL(w, hm, tQ); + CleanupStack::PushL(u1); + + RInteger u2 = TInteger::ModularMultiplyL(tR, w, tQ); + CleanupStack::PushL(u2); + + // e) Compute v = ((g^u1 * y^u2) mod p) mod q + + const TInteger& tG=iKey->GetBigIntL(KDsaKeyParameterGUid); + const TInteger& tY=iKey->GetBigIntL(KDsaKeyParameterYUid); + const TInteger& tP=iKey->GetBigIntL(KDsaKeyParameterPUid); + + RInteger temp = TInteger::ModularExponentiateL(tG, u1, tP); + CleanupStack::PushL(temp); + RInteger temp1 = TInteger::ModularExponentiateL(tY, u2, tP); + CleanupStack::PushL(temp1); + RInteger v = TInteger::ModularMultiplyL(temp, temp1, tP); + CleanupStack::PushL(v); + v %= tQ; + + // f) Accept the signature if v == r + if(v == tR) + { + aVerificationResult = ETrue; + } + + CleanupStack::PopAndDestroy(7, &w); + } + + +// Methods which are not supported can be excluded from the coverage. +#ifdef _BullseyeCoverage +#pragma suppress_warnings on +#pragma BullseyeCoverage off +#pragma suppress_warnings off +#endif + +void CDSAVerifierImpl::InverseSignL(HBufC8*& /*aOutput*/, const CCryptoParams& /*aSignature*/) + { + // Override in subclass + User::Leave(KErrNotSupported); + } diff -r 7e3f204e6c81 -r f9c11be8c0b3 cryptoplugins/cryptospiplugins/source/softwarecrypto/dsaverifyimpl.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/cryptoplugins/cryptospiplugins/source/softwarecrypto/dsaverifyimpl.h Tue Dec 01 11:12:04 2009 +0000 @@ -0,0 +1,92 @@ +/* +* Copyright (c) 2006-2009 Nokia Corporation and/or its subsidiary(-ies). +* All rights reserved. +* This component and the accompanying materials are made available +* under the terms of the License "Eclipse Public License v1.0" +* which accompanies this distribution, and is available +* at the URL "http://www.eclipse.org/legal/epl-v10.html". +* +* Initial Contributors: +* Nokia Corporation - initial contribution. +* +* Contributors: +* +* Description: +* +*/ + + +#ifndef __DSAVERIFYIMPL_H__ +#define __DSAVERIFYIMPL_H__ + +/** +@file +@internalComponent +@released +*/ + +#include +#include +#include + +#include "verifierimpl.h" +#include "common/inlines.h" + +/** + * Implementation of DSA verification + */ +namespace SoftwareCrypto + { + using namespace CryptoSpi; + + NONSHARABLE_CLASS(CDSAVerifierImpl) : public CVerifierImpl + { + public: + /** + Creates an instance of a DSA verifier plug-in. + @param aKey The key + @return A pointer to a CDSAVerifierImpl instance + */ + static CDSAVerifierImpl* NewL(const CKey& aKey); + + /** + Creates an instance of a DSA verifier plug-in. + @param aKey The key + @return A pointer to a CDSAVerifierImpl instance + */ + static CDSAVerifierImpl* NewLC(const CKey& aKey); + + // Override CVerifierImpl virtual functions + TUid ImplementationUid() const; + // End of CVerifierImpl + + // Override MSignatureBase virtual functions + void SetKeyL(const CKey& aPublicKey); + virtual TInt GetMaximumInputLengthL() const; + + // End of MSignatureBase + + // Override MSigner virtual functions + void VerifyL(const TDesC8& aInput, const CCryptoParams& aSignature, TBool& aVerificationResult); + void InverseSignL(HBufC8*& aOutput, const CCryptoParams& aSignature); + // End of MSigner + + const CExtendedCharacteristics* GetExtendedCharacteristicsL(); + static CExtendedCharacteristics* CreateExtendedCharacteristicsL(); + + /// Destructor + ~CDSAVerifierImpl(); + + protected: + /// Constructor + CDSAVerifierImpl(); + + /// second phase of construction + virtual void ConstructL(const CKey& aKey); + + private: + static const TUint KSha1HashLength = 20; + }; + } + +#endif // __DSAVERIFYIMPL_H__ diff -r 7e3f204e6c81 -r f9c11be8c0b3 cryptoplugins/cryptospiplugins/source/softwarecrypto/hmacimpl.cpp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/cryptoplugins/cryptospiplugins/source/softwarecrypto/hmacimpl.cpp Tue Dec 01 11:12:04 2009 +0000 @@ -0,0 +1,276 @@ +/* +* Copyright (c) 2006-2009 Nokia Corporation and/or its subsidiary(-ies). +* All rights reserved. +* This component and the accompanying materials are made available +* under the terms of the License "Eclipse Public License v1.0" +* which accompanies this distribution, and is available +* at the URL "http://www.eclipse.org/legal/epl-v10.html". +* +* Initial Contributors: +* Nokia Corporation - initial contribution. +* +* Contributors: +* +* Description: +* software hmac implementation +* software hmac implementation +* +*/ + + +/** + @file +*/ + +#include "hmacimpl.h" +#include "pluginconfig.h" +#include "md2impl.h" +#include "md5impl.h" +#include "sha1impl.h" +#include "keys.h" +#include "md4impl.h" + + +using namespace SoftwareCrypto; + +CHMacImpl* CHMacImpl::NewL(const CKey& aKey, MSoftwareHash* aHash) + { + CHMacImpl* self=NewLC(aKey, aHash); + CleanupStack::Pop(); + return self; + } + +CHMacImpl* CHMacImpl::NewLC(const CKey& aKey, MSoftwareHash* aHash) + { + CHMacImpl* self=new(ELeave) CHMacImpl(); + CleanupStack::PushL(self); + self->ConstructL(aKey, aHash); + return self; + } + +CHMacImpl* CHMacImpl::NewL(MSoftwareHash* aHash) + { + CHMacImpl* self=NewLC(aHash); + CleanupStack::Pop(); + return self; + } + +CHMacImpl* CHMacImpl::NewLC(MSoftwareHash* aHash) + { + CHMacImpl* self=new(ELeave) CHMacImpl(); + CleanupStack::PushL(self); + self->ConstructL(aHash); + return self; + } + + +CHMacImpl::CHMacImpl() + { + } + +CHMacImpl::CHMacImpl(const CHMacImpl& aMD) + : iDigest(NULL), iInnerPad(aMD.iInnerPad), + iOuterPad(aMD.iOuterPad), iBlockSize(aMD.iBlockSize) + { + } + +CHMacImpl::~CHMacImpl() + { + if (iDigest) + { + iDigest->Close(); + } + } + +void CHMacImpl::ConstructL(const CKey& aKey, MSoftwareHash* aHash) + { + //Clone the hash implementation + iDigest=static_cast(aHash->ReplicateL()); + InitBlockSizeL(); + const TDesC8& keyContent=aKey.GetTDesC8L(KHmacKeyParameterUid); + Initialise(keyContent); + } + +void CHMacImpl::ConstructL(MSoftwareHash* aHash) + { + //Clone the hash implementation + iDigest=static_cast(aHash->ReplicateL()); + InitBlockSizeL(); + } + +void CHMacImpl::InitBlockSizeL() + { + const TCharacteristics* ptr(NULL); + iDigest->GetCharacteristicsL(ptr); + const THashCharacteristics* hashPtr=static_cast(ptr); + iBlockSize = hashPtr->iBlockSize/8; + + iInnerPad.SetLength(iBlockSize); + iOuterPad.SetLength(iBlockSize); + iInnerPadCopy.SetLength(iBlockSize); + iOuterPadCopy.SetLength(iBlockSize); + } + +void CHMacImpl::Initialise(const TDesC8& aKey) + { + // initialisation + if (iDigest) + { + iDigest->Reset(); + if( (TUint32)aKey.Size() > iBlockSize) + { + iInnerPad = iDigest->Final(aKey); + } + else + { + iInnerPad = aKey; + } + + TUint i; + for (i=iInnerPad.Size();iHash(iInnerPad); + } + } + +MHash* CHMacImpl::CopyL() + { + CHMacImpl* that=new(ELeave) CHMacImpl(*this); + CleanupStack::PushL(that); + that->iDigest=iDigest ? static_cast(iDigest->CopyL()) : NULL; + CleanupStack::Pop(); + return that; + } + +MHash* CHMacImpl::ReplicateL() + { + CHMacImpl* that=new(ELeave) CHMacImpl(*this); + CleanupStack::PushL(that); + that->iDigest=iDigest ? static_cast(iDigest->ReplicateL()) : NULL; + that->Reset(); + CleanupStack::Pop(); + return that; + } + +void CHMacImpl::Reset() + { + if (iDigest) + { + iDigest->Reset(); + iDigest->Update(iInnerPad); + } + } + +TPtrC8 CHMacImpl::Hash(const TDesC8& aMessage) + { + TPtrC8 ptr(KNullDesC8()); + TPtrC8 finalPtr(KNullDesC8()); + StoreState(); + if (iDigest) + { + ptr.Set(iDigest->Final(aMessage)); + iDigest->Update(iOuterPad); + finalPtr.Set(iDigest->Final(ptr)); + } + + RestoreState(); + + if(iDigest) + { + iDigest->Update(aMessage); + } + + + + return (finalPtr); + } + +void CHMacImpl::Update(const TDesC8& aMessage) + { + if(iDigest) + { + iDigest->Update(aMessage); + } + } + +TPtrC8 CHMacImpl::Final(const TDesC8& aMessage) + { + TPtrC8 ptr(KNullDesC8()); + if(iDigest) + { + ptr.Set(iDigest->Final(aMessage)); + iDigest->Update(iOuterPad); + iDigest->Final(ptr); + Reset(); + } + return (ptr); + } + +void CHMacImpl::RestoreState() + { + iOuterPad.Copy(iOuterPadCopy); + iInnerPad.Copy(iInnerPadCopy); + if (iDigest) + { + iDigest->RestoreState(); + } + } + +void CHMacImpl::StoreState() + { + iOuterPadCopy.Copy(iOuterPad); + iInnerPadCopy.Copy(iInnerPad); + if (iDigest) + { + iDigest->StoreState(); + } + } + +void CHMacImpl::SetKeyL(const CKey& aKey) + { + const TDesC8& keyContent=aKey.GetTDesC8L(KHmacKeyParameterUid); + Initialise(keyContent); + } + +void CHMacImpl::Close() + { + delete this; + } + +void CHMacImpl::GetCharacteristicsL(const TCharacteristics*& aPluginCharacteristics) + { + iDigest->GetCharacteristicsL(aPluginCharacteristics); + } + +const CExtendedCharacteristics* CHMacImpl::GetExtendedCharacteristicsL() + { + return iDigest->GetExtendedCharacteristicsL(); + } + +// Methods which are not supported can be excluded from the coverage. +#ifdef _BullseyeCoverage +#pragma suppress_warnings on +#pragma BullseyeCoverage off +#pragma suppress_warnings off +#endif + +TAny* CHMacImpl::GetExtension(TUid /*aExtensionId*/) + { + return NULL; + } + +void CHMacImpl::SetOperationModeL(TUid /*aOperationMode*/) + { + User::Leave(KErrNotSupported); + } + diff -r 7e3f204e6c81 -r f9c11be8c0b3 cryptoplugins/cryptospiplugins/source/softwarecrypto/hmacimpl.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/cryptoplugins/cryptospiplugins/source/softwarecrypto/hmacimpl.h Tue Dec 01 11:12:04 2009 +0000 @@ -0,0 +1,93 @@ +/* +* Copyright (c) 2006-2009 Nokia Corporation and/or its subsidiary(-ies). +* All rights reserved. +* This component and the accompanying materials are made available +* under the terms of the License "Eclipse Public License v1.0" +* which accompanies this distribution, and is available +* at the URL "http://www.eclipse.org/legal/epl-v10.html". +* +* Initial Contributors: +* Nokia Corporation - initial contribution. +* +* Contributors: +* +* Description: +* hmac implementation +* +*/ + + +/** + @file + @internalComponent + @released +*/ + +#ifndef __CRYPTOAPI_SOFTWAREHMACIMPL_H__ +#define __CRYPTOAPI_SOFTWAREHMACIMPL_H__ + +#include "softwarehashbase.h" +#include "keys.h" + +namespace SoftwareCrypto + { + using namespace CryptoSpi; + + /** + * This is the maximum block size currently supported by HMAC implementation. + */ + const TInt KMaxBlockSize = 128; + + NONSHARABLE_CLASS(CHMacImpl) : public CBase, public MSoftwareHash + { + public: + //NewL & NewLC + static CHMacImpl* NewL(MSoftwareHash* aHash); + static CHMacImpl* NewLC(MSoftwareHash* aHash); + static CHMacImpl* NewL(const CKey& aKey, MSoftwareHash* aHash); + static CHMacImpl* NewLC(const CKey& aKey, MSoftwareHash* aHash); + + //From MPlugin + void Reset(); + void Close(); + void GetCharacteristicsL(const TCharacteristics*& aPluginCharacteristics); + const CExtendedCharacteristics* GetExtendedCharacteristicsL(); + TAny* GetExtension(TUid aExtensionId); + + //From MHmac + TPtrC8 Hash(const TDesC8& aMessage); + void Update(const TDesC8& aMessage); + TPtrC8 Final(const TDesC8& aMessage); + void SetKeyL(const CKey& aKey); + void SetOperationModeL(TUid aOperationMode); + MHash* ReplicateL(); + MHash* CopyL(); + + private: + //Constructors + CHMacImpl(); + CHMacImpl(const CHMacImpl& aHMacImpl); + + //Destructor + ~CHMacImpl(); + void RestoreState(); + void StoreState(); + void ConstructL(const CKey& aKey, MSoftwareHash* aHash); + void ConstructL(MSoftwareHash* aHash); + void Initialise(const TDesC8& aKey); + void InitBlockSizeL(); + + private: + TUid iImplementationUid; + MSoftwareHash* iDigest; + + TBuf8 iInnerPad; + TBuf8 iOuterPad; + TBuf8 iInnerPadCopy; + TBuf8 iOuterPadCopy; + + TInt iBlockSize; + }; + } + +#endif // __CRYPTOAPI_SOFTWAREHMACIMPL_H__ diff -r 7e3f204e6c81 -r f9c11be8c0b3 cryptoplugins/cryptospiplugins/source/softwarecrypto/keyagreementimpl.cpp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/cryptoplugins/cryptospiplugins/source/softwarecrypto/keyagreementimpl.cpp Tue Dec 01 11:12:04 2009 +0000 @@ -0,0 +1,75 @@ +/* +* Copyright (c) 2006-2009 Nokia Corporation and/or its subsidiary(-ies). +* All rights reserved. +* This component and the accompanying materials are made available +* under the terms of the License "Eclipse Public License v1.0" +* which accompanies this distribution, and is available +* at the URL "http://www.eclipse.org/legal/epl-v10.html". +* +* Initial Contributors: +* Nokia Corporation - initial contribution. +* +* Contributors: +* +* Description: +* +*/ + + +#include "keyagreementimpl.h" +#include +#include "pluginconfig.h" + +using namespace SoftwareCrypto; + +CKeyAgreementImpl::CKeyAgreementImpl() + { + } + +void CKeyAgreementImpl::ConstructL(const CKey& aPrivateKey, const CCryptoParams* aParams) + { + SetKeyL(aPrivateKey, aParams); + } + +CKeyAgreementImpl::~CKeyAgreementImpl() + { + delete iSharedParams; + delete iPrivateKey; + } + +void CKeyAgreementImpl::Close() + { + delete this; + } + +void CKeyAgreementImpl::Reset() + { + } + +TAny* CKeyAgreementImpl::GetExtension(TUid /*aExtensionId*/) + { + return 0; + } + +void CKeyAgreementImpl::GetCharacteristicsL(const TAny*& aPluginCharacteristics) + { + TInt numCiphers = sizeof(KKeyAgreementCharacteristics)/sizeof(TKeyAgreementCharacteristics*); + TInt32 implUid = ImplementationUid().iUid; + for (TInt i = 0; i < numCiphers; ++i) + { + if (KKeyAgreementCharacteristics[i]->cmn.iImplementationUID == implUid) + { + aPluginCharacteristics = KKeyAgreementCharacteristics[i]; + break; + } + } + } + +void CKeyAgreementImpl::SetKeyL(const CKey& aSelfPrivateKey, const CCryptoParams* aSharedParams) + { + delete iPrivateKey; + iPrivateKey = CKey::NewL(aSelfPrivateKey); + delete iSharedParams; + iSharedParams = CCryptoParams::NewL(); + iSharedParams->CopyL(*aSharedParams); // copy contents of the object + } diff -r 7e3f204e6c81 -r f9c11be8c0b3 cryptoplugins/cryptospiplugins/source/softwarecrypto/keyagreementimpl.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/cryptoplugins/cryptospiplugins/source/softwarecrypto/keyagreementimpl.h Tue Dec 01 11:12:04 2009 +0000 @@ -0,0 +1,87 @@ +/* +* Copyright (c) 2006-2009 Nokia Corporation and/or its subsidiary(-ies). +* All rights reserved. +* This component and the accompanying materials are made available +* under the terms of the License "Eclipse Public License v1.0" +* which accompanies this distribution, and is available +* at the URL "http://www.eclipse.org/legal/epl-v10.html". +* +* Initial Contributors: +* Nokia Corporation - initial contribution. +* +* Contributors: +* +* Description: +* +*/ + + +#ifndef __KEYAGREEMENTIMPL_H__ +#define __KEYAGREEMENTIMPL_H__ + +/** +@file +@internalComponent +@released +*/ + +#include +#include +#include "keys.h" +#include "keyagreementplugin.h" + +/** + * Abstract base class for key agreement plug-ins. + */ +namespace SoftwareCrypto + { + using namespace CryptoSpi; + + NONSHARABLE_CLASS(CKeyAgreementImpl) : public CBase, public MKeyAgreement + { + public: + + // Override MPlugin virtual functions + void Close(); + void Reset(); // Always call reset in super-class if you override this + TAny* GetExtension(TUid aExtensionId); + void GetCharacteristicsL(const TCharacteristics*& aPluginCharacteristics); + // End of MPlugin + + // Override MKeyAgreement virtual functions + void SetKeyL(const CKey& aSelfPrivateKey, const CCryptoParams* aParams); + // End of MKeyAgreement + + /// Destructor + ~CKeyAgreementImpl(); + + protected: + /** + Constructor + */ + CKeyAgreementImpl(); + + /** + Second phase of construction. Always call ConstructL in the super-class + if your override this method. + @param aPrivateKey The private key of one of the parties + @param aParams The parameters shared between both parties + */ + virtual void ConstructL(const CKey& aPrivateKey, const CCryptoParams* aParams); + + /** + Helper function implemented by concrete cipher sub-class that allows + GetCharacteristicsL to return the correct characteristics object. + @return The implemention uid + */ + virtual TUid ImplementationUid() const = 0; + + private: + + protected: + CKey* iPrivateKey; + CCryptoParams* iSharedParams; // common parameters between our private key and their public key + }; + } + +#endif // __KEYAGREEMENTIMPL_H__ diff -r 7e3f204e6c81 -r f9c11be8c0b3 cryptoplugins/cryptospiplugins/source/softwarecrypto/keypairgenimpl.cpp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/cryptoplugins/cryptospiplugins/source/softwarecrypto/keypairgenimpl.cpp Tue Dec 01 11:12:04 2009 +0000 @@ -0,0 +1,67 @@ +/* +* Copyright (c) 2006-2009 Nokia Corporation and/or its subsidiary(-ies). +* All rights reserved. +* This component and the accompanying materials are made available +* under the terms of the License "Eclipse Public License v1.0" +* which accompanies this distribution, and is available +* at the URL "http://www.eclipse.org/legal/epl-v10.html". +* +* Initial Contributors: +* Nokia Corporation - initial contribution. +* +* Contributors: +* +* Description: +* +*/ + + +#include +#include +#include "keys.h" + +#include "keypairgenimpl.h" + +#include +#include +#include "pluginconfig.h" + +#include "common/inlines.h" + +using namespace SoftwareCrypto; + +CKeyPairGenImpl::CKeyPairGenImpl() + { + } + +void CKeyPairGenImpl::ConstructL() + { + } + +CKeyPairGenImpl::~CKeyPairGenImpl() + { + } + +void CKeyPairGenImpl::Close() + { + delete this; + } + +TAny* CKeyPairGenImpl::GetExtension(TUid /*aExtensionId*/) + { + return 0; + } + +void CKeyPairGenImpl::GetCharacteristicsL(const TAny*& aPluginCharacteristics) + { + TInt numCiphers = sizeof(KKeyPairGeneratorCharacteristics)/sizeof(TAsymmetricKeypairGeneratorCharacteristics*); + TInt32 implUid = ImplementationUid().iUid; + for (TInt i = 0; i < numCiphers; ++i) + { + if (KKeyPairGeneratorCharacteristics[i]->cmn.iImplementationUID == implUid) + { + aPluginCharacteristics = KKeyPairGeneratorCharacteristics[i]; + break; + } + } + } diff -r 7e3f204e6c81 -r f9c11be8c0b3 cryptoplugins/cryptospiplugins/source/softwarecrypto/keypairgenimpl.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/cryptoplugins/cryptospiplugins/source/softwarecrypto/keypairgenimpl.h Tue Dec 01 11:12:04 2009 +0000 @@ -0,0 +1,72 @@ +/* +* Copyright (c) 2007-2009 Nokia Corporation and/or its subsidiary(-ies). +* All rights reserved. +* This component and the accompanying materials are made available +* under the terms of the License "Eclipse Public License v1.0" +* which accompanies this distribution, and is available +* at the URL "http://www.eclipse.org/legal/epl-v10.html". +* +* Initial Contributors: +* Nokia Corporation - initial contribution. +* +* Contributors: +* +* Description: +* +*/ + + +#ifndef __KEYPAIRGENIMPL_H__ +#define __KEYPAIRGENIMPL_H__ + +/** +@file +@internalComponent +@released +*/ + +#include "cryptokeypairgeneratorapi.h" +#include "keypairgeneratorplugin.h" + +/** + * Key pair generator plugin base class + */ +namespace SoftwareCrypto + { + using namespace CryptoSpi; + + NONSHARABLE_CLASS(CKeyPairGenImpl) : public CBase, public MKeyPairGenerator + { + public: + + // Override MPlugin virtual functions + void Close(); + TAny* GetExtension(TUid aExtensionId); + void GetCharacteristicsL(const TCharacteristics*& aPluginCharacteristics); + // End of MPlugin + + // Destructor + ~CKeyPairGenImpl(); + + protected: + /** + Constructor + */ + CKeyPairGenImpl(); + + /** + Second phase of construction. Always call ConstructL in the super-class + if you override this method. + */ + virtual void ConstructL(); + + /** + Helper function implemented by concrete cipher sub-class that allows + GetCharacteristicsL to return the correct characteristics object. + @return The implemention uid + */ + virtual TUid ImplementationUid() const = 0; + }; + } + +#endif // __KEYPAIRGENIMPL_H__ diff -r 7e3f204e6c81 -r f9c11be8c0b3 cryptoplugins/cryptospiplugins/source/softwarecrypto/macimpl.cpp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/cryptoplugins/cryptospiplugins/source/softwarecrypto/macimpl.cpp Tue Dec 01 11:12:04 2009 +0000 @@ -0,0 +1,302 @@ +/* +* Copyright (c) 2008-2009 Nokia Corporation and/or its subsidiary(-ies). +* All rights reserved. +* This component and the accompanying materials are made available +* under the terms of the License "Eclipse Public License v1.0" +* which accompanies this distribution, and is available +* at the URL "http://www.eclipse.org/legal/epl-v10.html". +* +* Initial Contributors: +* Nokia Corporation - initial contribution. +* +* Contributors: +* +* Description: +* Software Mac Implementation +* Software Mac Implementation +* MAC plugin header +* +*/ + + +/** + @file +*/ +#include "macimpl.h" +#include "pluginconfig.h" + +/** + * HMAC plugin headers + */ +#include "md2impl.h" +#include "md4impl.h" +#include "md5impl.h" +#include "sha1impl.h" +#include "sha2impl.h" +#include "hmacimpl.h" + + +using namespace SoftwareCrypto; +using namespace CryptoSpi; + + +CMacImpl* CMacImpl::NewL(const CKey& aKey, const TUid aImplementationId, const CCryptoParams* aAlgorithmParams) + { + CMacImpl* self = new (ELeave) CMacImpl(); + CleanupStack::PushL(self); + self->ConstructL(aKey, aImplementationId, aAlgorithmParams); + CleanupStack::Pop(); + return self; + } + +CMacImpl::CMacImpl() + { + } + +void CMacImpl::ConstructL(const CKey& aKey, const TUid aImplementationId, const CCryptoParams* /*aAlgorithmParams*/) + { + iImplementationUid = aImplementationId; + iKey = CryptoSpi::CKey::NewL(aKey); + + MSoftwareHash* hashImpl = NULL; + + switch (aImplementationId.iUid) + { + case KCryptoPluginMacHashMd2: + { + hashImpl = CMD2Impl::NewL(); + CleanupClosePushL(*hashImpl); + iHmacImpl=CHMacImpl::NewL(*iKey, hashImpl); + iBase = EHashBased; + } + break; + case KCryptoPluginMacHashMd5: + { + hashImpl = CMD5Impl::NewL(); + CleanupClosePushL(*hashImpl); + iHmacImpl=CHMacImpl::NewL(*iKey, hashImpl); + iBase = EHashBased; + } + break; + case KCryptoPluginMacHashMd4: + { + hashImpl = CMD4Impl::NewL(); + CleanupClosePushL(*hashImpl); + iHmacImpl=CHMacImpl::NewL(*iKey, hashImpl); + iBase = EHashBased; + } + break; + case KCryptoPluginMacHashSha1: + { + hashImpl = CSHA1Impl::NewL(); + CleanupClosePushL(*hashImpl); + iHmacImpl=CHMacImpl::NewL(*iKey, hashImpl); + iBase = EHashBased; + } + break; + case KCryptoPluginMacHashSha224: + { + hashImpl = CSHA2Impl::NewL(KCryptoPluginSha224); + CleanupClosePushL(*hashImpl); + iHmacImpl=CHMacImpl::NewL(*iKey, hashImpl); + iBase = EHashBased; + } + break; + case KCryptoPluginMacHashSha256: + { + hashImpl = CSHA2Impl::NewL(KCryptoPluginSha256); + CleanupClosePushL(*hashImpl); + iHmacImpl=CHMacImpl::NewL(*iKey, hashImpl); + iBase = EHashBased; + } + break; + case KCryptoPluginMacHashSha384: + { + hashImpl = CSHA2Impl::NewL(KCryptoPluginSha384); + CleanupClosePushL(*hashImpl); + iHmacImpl=CHMacImpl::NewL(*iKey, hashImpl); + iBase = EHashBased; + } + break; + case KCryptoPluginMacHashSha512: + { + hashImpl = CSHA2Impl::NewL(KCryptoPluginSha512); + CleanupClosePushL(*hashImpl); + iHmacImpl=CHMacImpl::NewL(*iKey, hashImpl); + iBase = EHashBased; + } + break; + case KCryptoPluginMacAesXcbcMac96: + { + CSymmetricCipher* symmetricCipher = NULL; + CryptoSpi::CSymmetricCipherFactory::CreateSymmetricCipherL(symmetricCipher, + CryptoSpi::KAesUid, *iKey, + CryptoSpi::KCryptoModeEncryptUid, + CryptoSpi::KOperationModeCBCUid, + CryptoSpi::KPaddingModeNoneUid, + NULL); + + iCmacImpl= CCMacImpl::NewL(*iKey, symmetricCipher, CryptoSpi::KAlgorithmCipherAesXcbcMac96); + iBase = ECipherBased; + } + break; + case KCryptoPluginMacAesXcbcPrf128: + { + TBuf8<16> tempKey; + tempKey.SetLength(16); + + CryptoSpi::CCryptoParams* keyParams = CryptoSpi::CCryptoParams::NewLC(); + keyParams->AddL(tempKey, CryptoSpi::KSymmetricKeyParameterUid); + CryptoSpi::CKey* key = CryptoSpi::CKey::NewLC(aKey.KeyProperty(),*keyParams); + + CSymmetricCipher* symmetricCipher = NULL; + CryptoSpi::CSymmetricCipherFactory::CreateSymmetricCipherL(symmetricCipher, + CryptoSpi::KAesUid, *key, + CryptoSpi::KCryptoModeEncryptUid, + CryptoSpi::KOperationModeCBCUid, + CryptoSpi::KPaddingModeNoneUid, + NULL); + CleanupStack::PopAndDestroy(2, keyParams); //key and keyParams + + iCmacImpl= CCMacImpl::NewL(*iKey, symmetricCipher, CryptoSpi::KAlgorithmCipherAesXcbcPrf128); + iBase = ECipherBased; + } + break; + + default: + User::Leave(KErrNotSupported); + } + + if(iBase == EHashBased) + { + CleanupStack::PopAndDestroy(hashImpl); + } + } + +CMacImpl::~CMacImpl() + { + delete iKey; + if(iHmacImpl) + { + iHmacImpl->Close(); + } + delete iCmacImpl; + } + +void CMacImpl::Reset() + { + if (iBase == EHashBased) + { + iHmacImpl->Reset(); + } + else if (iBase == ECipherBased) + { + iCmacImpl->Reset(); + } + } + +void CMacImpl::Close() + { + delete this; + } + +void CMacImpl::GetCharacteristicsL(const TCharacteristics*& aPluginCharacteristics) + { + aPluginCharacteristics=NULL; + TInt macNum=sizeof(KMacCharacteristics)/sizeof(TMacCharacteristics*); + for (TInt i=0;iiMacChar.iImplementationUID==ImplementationUid().iUid) + { + aPluginCharacteristics = KMacCharacteristics[i]; + break; + } + } + } + +const CExtendedCharacteristics* CMacImpl::GetExtendedCharacteristicsL() + { + return (iBase == EHashBased) ? iHmacImpl->GetExtendedCharacteristicsL(): iCmacImpl->GetExtendedCharacteristicsL(); + } + +TAny* CMacImpl::GetExtension(TUid aExtensionId) + { + return (iBase == EHashBased) ? iHmacImpl->GetExtension(aExtensionId): NULL; + } + +TUid CMacImpl::ImplementationUid() const + { + return iImplementationUid; + } + +TPtrC8 CMacImpl::MacL(const TDesC8& aMessage) + { + return (iBase == EHashBased) ? iHmacImpl->Hash(aMessage):iCmacImpl->MacL(aMessage); + } + +void CMacImpl::UpdateL(const TDesC8& aMessage) + { + (iBase == EHashBased) ? iHmacImpl->Update(aMessage):iCmacImpl->UpdateL(aMessage); + } + +TPtrC8 CMacImpl::FinalL(const TDesC8& aMessage) + { + return (iBase == EHashBased) ? iHmacImpl->Final(aMessage):iCmacImpl->FinalL(aMessage); + } + +void CMacImpl::ReInitialiseAndSetKeyL(const CKey& aKey) + { + delete iKey; + iKey = NULL; + iKey = CryptoSpi::CKey::NewL(aKey); + + if (iBase == EHashBased) + { + iHmacImpl->SetKeyL(aKey); + iHmacImpl->Reset(); + } + else if (iBase == ECipherBased) + { + iCmacImpl->ReInitialiseAndSetKeyL(aKey); + } + } + +MMac* CMacImpl::ReplicateL() + { + CMacImpl* that= new(ELeave) CMacImpl(); + CleanupStack::PushL(that); + that->iImplementationUid = iImplementationUid; + that->iBase = iBase; + that->iKey=CKey::NewL(*iKey); + + if(iBase == EHashBased) + { + that->iHmacImpl=static_cast(iHmacImpl->ReplicateL()); + } + else if (iBase == ECipherBased) + { + that->iCmacImpl= iCmacImpl->ReplicateL(); + } + CleanupStack::Pop(that); + return that; + } + +MMac* CMacImpl::CopyL() + { + CMacImpl* that= new(ELeave) CMacImpl(); + CleanupStack::PushL(that); + that->iImplementationUid = iImplementationUid; + that->iBase = iBase; + that->iKey=CKey::NewL(*iKey); + + if(iBase == EHashBased) + { + that->iHmacImpl=static_cast(iHmacImpl->CopyL()); + } + else if (iBase == ECipherBased) + { + that->iCmacImpl= iCmacImpl->CopyL(); + } + CleanupStack::Pop(that); + return that; + } diff -r 7e3f204e6c81 -r f9c11be8c0b3 cryptoplugins/cryptospiplugins/source/softwarecrypto/macimpl.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/cryptoplugins/cryptospiplugins/source/softwarecrypto/macimpl.h Tue Dec 01 11:12:04 2009 +0000 @@ -0,0 +1,115 @@ +/* +* Copyright (c) 2008-2009 Nokia Corporation and/or its subsidiary(-ies). +* All rights reserved. +* This component and the accompanying materials are made available +* under the terms of the License "Eclipse Public License v1.0" +* which accompanies this distribution, and is available +* at the URL "http://www.eclipse.org/legal/epl-v10.html". +* +* Initial Contributors: +* Nokia Corporation - initial contribution. +* +* Contributors: +* +* Description: +* mac plugin implementation +* +*/ + + +/** + @file + @internalComponent + @released +*/ + +#ifndef __CRYPTOAPI_SOFTWAREMACIMPL_H__ +#define __CRYPTOAPI_SOFTWAREMACIMPL_H__ + +#include +#include "cryptosymmetriccipherapi.h" +#include "softwarehashbase.h" +#include "keys.h" +#include "cmacimpl.h" +#include "hmacimpl.h" + + +namespace SoftwareCrypto + { + using namespace CryptoSpi; + + NONSHARABLE_CLASS(CMacImpl) : public CBase, public MMac + { + public: + /** + * MAC implementation instance creation methods + */ + static CMacImpl* NewL(const CKey& aKey, + const TUid aImplementationId, + const CCryptoParams* aAlgorithmParams); + + /** + * Methods from MPlugin: Base class for all the plugins + */ + void GetCharacteristicsL(const TCharacteristics*& aPluginCharacteristics); + const CExtendedCharacteristics* GetExtendedCharacteristicsL(); + TAny* GetExtension(TUid aExtensionId); + void Reset(); + // this deletes the instance of this class. The method is called at the user side + // indirectly through the MPlugin pointer instance. + void Close(); + + /** + * From MMac: MAC interface (Software based) + */ + TPtrC8 MacL(const TDesC8& aMessage); + void UpdateL(const TDesC8& aMessage); + TPtrC8 FinalL(const TDesC8& aMessage); + void ReInitialiseAndSetKeyL(const CKey& aKey); + MMac* ReplicateL(); + MMac* CopyL(); + + private: + + /** + * Enumerators to recognize the type of algorithm used for MAC + */ + enum TMacBase {EHashBased, ECipherBased}; + + + /** + * Constructors and Destructors + */ + ~CMacImpl(); + CMacImpl(); + CMacImpl(const CMacImpl& aMacImpl); + + /** + * Initialize the 'iHmacImpl' and 'iCipherImpl' instances. + */ + void ConstructL(const CKey& aKey, const TUid aImplementationId,const CCryptoParams* aAlgorithmParams); + + /** + * This will return the Uid of the specific implementation + * used for the algorithm. + */ + TUid ImplementationUid() const; + + private: + TUid iImplementationUid; + TMacBase iBase; + CKey* iKey; + + /** + * The hash based MAC implementation. This is software based implementation. + */ + CHMacImpl* iHmacImpl; + + /** + * The symmetric cipher based MAC implementation. + */ + CCMacImpl* iCmacImpl; + }; + } + +#endif // __CRYPTOAPI_SOFTWAREMACIMPL_H__ diff -r 7e3f204e6c81 -r f9c11be8c0b3 cryptoplugins/cryptospiplugins/source/softwarecrypto/md2impl.cpp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/cryptoplugins/cryptospiplugins/source/softwarecrypto/md2impl.cpp Tue Dec 01 11:12:04 2009 +0000 @@ -0,0 +1,315 @@ +/* +* Copyright (c) 2006-2009 Nokia Corporation and/or its subsidiary(-ies). +* All rights reserved. +* This component and the accompanying materials are made available +* under the terms of the License "Eclipse Public License v1.0" +* which accompanies this distribution, and is available +* at the URL "http://www.eclipse.org/legal/epl-v10.html". +* +* Initial Contributors: +* Nokia Corporation - initial contribution. +* +* Contributors: +* +* Description: +* software md2 implementation +* software md2 implementation +* +*/ + + +/** + @file +*/ + +#include "md2impl.h" + +#include +#include "pluginconfig.h" + +using namespace SoftwareCrypto; + +CMD2Impl* CMD2Impl::NewL() + { + CMD2Impl* self=new (ELeave) CMD2Impl(); + return self; + } + +CMD2Impl* CMD2Impl::NewLC() + { + CMD2Impl* self=NewL(); + CleanupStack::PushL(self); + return self; + } + +CMD2Impl::CMD2Impl() : iHash(KMD2HashSize) + { + } + +CMD2Impl::CMD2Impl(const CMD2Impl& aCMD2Impl) +: iHash(aCMD2Impl.iHash),iNum(aCMD2Impl.iNum) + { + (void)Mem::Copy(iData, aCMD2Impl.iData, sizeof(iData)); + (void)Mem::Copy(iChecksum, aCMD2Impl.iChecksum, sizeof(iChecksum)); + (void)Mem::Copy(iState, aCMD2Impl.iState, sizeof(iState)); + } + +CMD2Impl::~CMD2Impl() + { + } + +void CMD2Impl::Reset() + { + Mem::FillZ(iData,sizeof(iData)); + Mem::FillZ(iChecksum,sizeof(iChecksum)); + Mem::FillZ(iState,sizeof(iState)); + iNum=0; + } + +void CMD2Impl::Close() + { + delete this; + } + +void CMD2Impl::GetCharacteristicsL(const TCharacteristics*& aPluginCharacteristics) + { + aPluginCharacteristics=NULL; + TInt hashNum=sizeof(KHashCharacteristics)/sizeof(THashCharacteristics*); + for (TInt i=0;icmn.iImplementationUID==ImplementationUid().iUid) + { + aPluginCharacteristics = KHashCharacteristics[i]; + break; + } + } + } + +CExtendedCharacteristics* CMD2Impl::CreateExtendedCharacteristicsL() + { + // All Symbian software plug-ins have unlimited concurrency, cannot be reserved + // for exclusive use and are not CERTIFIED to be standards compliant. + return CExtendedCharacteristics::NewL(KMaxTInt, EFalse); + } + +const CExtendedCharacteristics* CMD2Impl::GetExtendedCharacteristicsL() + { + return CMD2Impl::CreateExtendedCharacteristicsL(); + } + +TPtrC8 CMD2Impl::Hash(const TDesC8& aMessage) + { + TPtrC8 ptr(KNullDesC8()); + DoUpdate(aMessage.Ptr(),aMessage.Size()); + StoreState(); + DoFinal(); + ptr.Set(iHash); + RestoreState(); + return ptr; + } + +void CMD2Impl::Update(const TDesC8& aMessage) + { + DoUpdate(aMessage.Ptr(),aMessage.Size()); + } + +TPtrC8 CMD2Impl::Final(const TDesC8& aMessage) + { + TPtrC8 ptr(KNullDesC8()); + if (aMessage!=KNullDesC8()) + { + DoUpdate(aMessage.Ptr(),aMessage.Size()); + } + DoFinal(); + ptr.Set(iHash); + Reset(); + return ptr; + } + +MHash* CMD2Impl::ReplicateL() + { + return NewL(); + } + +MHash* CMD2Impl::CopyL() + { + return new(ELeave) CMD2Impl(*this); + } + +void CMD2Impl::RestoreState() + { + Mem::Copy(&iData[0], &iDataTemp[0], KMD2BlockSize); + Mem::Copy(&iChecksum[0], &iChecksumTemp[0], KMD2BlockSize*sizeof(TUint)); + Mem::Copy(&iState[0], &iStateTemp[0], KMD2BlockSize*sizeof(TUint)); + } + +void CMD2Impl::StoreState() + { + Mem::Copy(&iDataTemp[0], &iData[0], KMD2BlockSize); + Mem::Copy(&iChecksumTemp[0], &iChecksum[0], KMD2BlockSize*sizeof(TUint)); + Mem::Copy(&iStateTemp[0], &iState[0], KMD2BlockSize*sizeof(TUint)); + } + + +TUid CMD2Impl::ImplementationUid() + { + return KCryptoPluginMd2Uid; + } + +static inline TUint CMD2_S(TUint& elt,TUint8 val) + { + return elt^=val; + } + +void CMD2Impl::DoUpdate(const TUint8* aData,TUint aLength) + { + TBool carryOn=ETrue; + if (iNum) + { + if (iNum+aLength>=(TUint)KMD2BlockSize) + { + const TUint temp=KMD2BlockSize-iNum; + (void)Mem::Copy(iData+iNum,aData,temp); + Block(iData); + aData+=temp; + aLength-=temp; + iNum=0; + } + else + { + (void)Mem::Copy(iData+iNum,aData,aLength); + iNum+=aLength; + carryOn=EFalse; + } + } + // processing by block of KMD2BlockSize + if (carryOn) + { + while (aLength>=(TUint)KMD2BlockSize) + { + Block(aData); + aData+=KMD2BlockSize; + aLength-=KMD2BlockSize; + } + (void)Mem::Copy(iData,aData,aLength); + iNum=aLength; + } + } + +void CMD2Impl::DoFinal() + { + const TUint pad=KMD2BlockSize-iNum; + if (pad>0) + Mem::Fill(iData+iNum,(TUint8)pad,pad); + Block(iData); + + TUint8* pData=iData; + const TUint8* pEnd=iData+KMD2BlockSize; + const TUint* pChecksum=iChecksum; + while (pData iHash; + TInt iNum; + TUint8 iData[KMD2BlockSize]; + TUint iChecksum[KMD2BlockSize]; + TUint iState[KMD2BlockSize]; + TUint8 iDataTemp[KMD2BlockSize]; + TUint iChecksumTemp[KMD2BlockSize]; + TUint iStateTemp[KMD2BlockSize]; + }; + } + +#endif //__CRYPTOAPI_SOFTWAREMD2IMPL_H__ diff -r 7e3f204e6c81 -r f9c11be8c0b3 cryptoplugins/cryptospiplugins/source/softwarecrypto/md4impl.cpp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/cryptoplugins/cryptospiplugins/source/softwarecrypto/md4impl.cpp Tue Dec 01 11:12:04 2009 +0000 @@ -0,0 +1,538 @@ +/* +* Copyright (c) 2007-2009 Nokia Corporation and/or its subsidiary(-ies). +* All rights reserved. +* This component and the accompanying materials are made available +* under the terms of the License "Eclipse Public License v1.0" +* which accompanies this distribution, and is available +* at the URL "http://www.eclipse.org/legal/epl-v10.html". +* +* Initial Contributors: +* Nokia Corporation - initial contribution. +* +* Contributors: +* +* Description: +* software md4 implementation +* software md4 implementation +* +*/ + + +/** + @file +*/ + +#include "md4impl.h" +#include +#include "pluginconfig.h" + + +using namespace SoftwareCrypto; + + +CMD4Impl* CMD4Impl::NewL() + { + CMD4Impl* self=new (ELeave) CMD4Impl(); + self->Reset(); + return self; + } + +CMD4Impl* CMD4Impl::NewLC() + { + CMD4Impl* self=NewL(); + CleanupStack::PushL(self); + return self; + } + +CMD4Impl::CMD4Impl() : iHash(KMD4HashSize) + { + } + +CMD4Impl::CMD4Impl(const CMD4Impl& aCMD4Impl) +: iHash(aCMD4Impl.iHash),iA(aCMD4Impl.iA),iB(aCMD4Impl.iB),iC(aCMD4Impl.iC),iD(aCMD4Impl.iD), + iNl(aCMD4Impl.iNl),iNh(aCMD4Impl.iNh) + { + (void)Mem::Copy(iData, aCMD4Impl.iData, sizeof(iData)); + } + +CMD4Impl::~CMD4Impl() + { + } + +void CMD4Impl::Reset() + { + iA=0x67452301; + iB=0xefcdab89; + iC=0x98badcfe; + iD=0x10325476; + iNh=0; + iNl=0; + } + +void CMD4Impl::Close() + { + delete this; + } + +void CMD4Impl::GetCharacteristicsL(const TCharacteristics*& aPluginCharacteristics) + { + aPluginCharacteristics=NULL; + TInt hashNum=sizeof(KHashCharacteristics)/sizeof(THashCharacteristics*); + for (TInt i=0;icmn.iImplementationUID == ImplementationUid().iUid) + { + aPluginCharacteristics = KHashCharacteristics[i]; + break; + } + } + } + +CExtendedCharacteristics* CMD4Impl::CreateExtendedCharacteristicsL() + { + // All Symbian software plug-ins have unlimited concurrency, cannot be reserved + // for exclusive use and are not CERTIFIED to be standards compliant. + return CExtendedCharacteristics::NewL(KMaxTInt, EFalse); + } +const CExtendedCharacteristics* CMD4Impl::GetExtendedCharacteristicsL() + { + return CMD4Impl::CreateExtendedCharacteristicsL(); + } + +TPtrC8 CMD4Impl::Hash(const TDesC8& aMessage) + { + DoUpdate(aMessage.Ptr(),aMessage.Size()); + StoreState(); + DoFinal(); + RestoreState(); + return iHash; + } + +void CMD4Impl::Update(const TDesC8& aMessage) + { + DoUpdate(aMessage.Ptr(),aMessage.Size()); + } + +TPtrC8 CMD4Impl::Final(const TDesC8& aMessage) + { + if (aMessage!=KNullDesC8()) + { + DoUpdate(aMessage.Ptr(),aMessage.Size()); + } + DoFinal(); + Reset(); + return iHash; + } + +MHash* CMD4Impl::ReplicateL() + { + return CMD4Impl::NewL(); + } + +MHash* CMD4Impl::CopyL() + { + return new(ELeave) CMD4Impl(*this); + } + +TUid CMD4Impl::ImplementationUid() + { + return KCryptoPluginMd4Uid; + } + +void CMD4Impl::DoUpdate(const TUint8* aData,TUint aLength) + { + const TUint8* pend=aData+aLength; + for (const TUint8* paData=aData;paData>2]=byte; + break; + case 1: + iData[iNl>>2]|=byte<<8; + break; + case 2: + iData[iNl>>2]|=byte<<16; + break; + case 3: + iData[iNl>>2]|=byte<<24; + break; + default: + break; + }; + if(++iNl==64) + { + Block(); + iNh+=64; + iNl=0; + } + } + } + +static inline TUint CMD4_F(TUint x,TUint y,TUint z) + { + return (x&y) | (~x&z); + } +static inline TUint CMD4_G(TUint x,TUint y,TUint z) + { + return (x&y) | (x&z) | (y&z); + } +static inline TUint CMD4_H(TUint x,TUint y,TUint z) + { + return x^y^z; + } + + +#ifdef NOREFS +static inline TUint CMD4_FF(TUint a,const TUint b,const TUint c,const TUint d,const TUint x,const TUint s) + { + a+=CMD4_F(b,c,d) + x; + a=CMD_R(a,s); + return a; + } +static inline TUint CMD4_GG(TUint a,const TUint b,const TUint c,const TUint d,const TUint x,const TUint s) + { + a+=CMD4_G(b,c,d) + x + (TUint32)0x5a827999; + a=CMD_R(a,s); + return a; + } +static inline TUint CMD4_HH(TUint a,const TUint b,const TUint c,const TUint d,const TUint x,const TUint s) + { + a+=CMD4_H(b,c,d) + x + (TUint32)0x6ed9eba1; + a=CMD_R(a,s); + return a; + } + +void CMD4Impl::Block() + { + register TUint tempA=iA; + register TUint tempB=iB; + register TUint tempC=iC; + register TUint tempD=iD; + + tempA = CMD4_FF(tempA,tempB,tempC,tempD,iData[ 0],3); + tempD = CMD4_FF(tempD,tempA,tempB,tempC,iData[ 1],7); + tempC = CMD4_FF(tempC,tempD,tempA,tempB,iData[ 2],11); + tempB = CMD4_FF(tempB,tempC,tempD,tempA,iData[ 3],19); + tempA = CMD4_FF(tempA,tempB,tempC,tempD,iData[ 4],3); + tempD = CMD4_FF(tempD,tempA,tempB,tempC,iData[ 5],7); + tempC = CMD4_FF(tempC,tempD,tempA,tempB,iData[ 6],11); + tempB = CMD4_FF(tempB,tempC,tempD,tempA,iData[ 7],19); + tempA = CMD4_FF(tempA,tempB,tempC,tempD,iData[ 8],3); + tempD = CMD4_FF(tempD,tempA,tempB,tempC,iData[ 9],7); + tempC = CMD4_FF(tempC,tempD,tempA,tempB,iData[10],11); + tempB = CMD4_FF(tempB,tempC,tempD,tempA,iData[11],19); + tempA = CMD4_FF(tempA,tempB,tempC,tempD,iData[12],3); + tempD = CMD4_FF(tempD,tempA,tempB,tempC,iData[13],7); + tempC = CMD4_FF(tempC,tempD,tempA,tempB,iData[14],11); + tempB = CMD4_FF(tempB,tempC,tempD,tempA,iData[15],19); + + tempA = CMD4_GG(tempA,tempB,tempC,tempD,iData[ 0],3); + tempD = CMD4_GG(tempD,tempA,tempB,tempC,iData[ 4],5); + tempC = CMD4_GG(tempC,tempD,tempA,tempB,iData[ 8],9); + tempB = CMD4_GG(tempB,tempC,tempD,tempA,iData[12],13); + tempA = CMD4_GG(tempA,tempB,tempC,tempD,iData[ 1],3); + tempD = CMD4_GG(tempD,tempA,tempB,tempC,iData[ 5],5); + tempC = CMD4_GG(tempC,tempD,tempA,tempB,iData[ 9],9); + tempB = CMD4_GG(tempB,tempC,tempD,tempA,iData[13],13); + tempA = CMD4_GG(tempA,tempB,tempC,tempD,iData[ 2],3); + tempD = CMD4_GG(tempD,tempA,tempB,tempC,iData[ 6],5); + tempC = CMD4_GG(tempC,tempD,tempA,tempB,iData[10],9); + tempB = CMD4_GG(tempB,tempC,tempD,tempA,iData[14],13); + tempA = CMD4_GG(tempA,tempB,tempC,tempD,iData[ 3],3); + tempD = CMD4_GG(tempD,tempA,tempB,tempC,iData[ 7],5); + tempC = CMD4_GG(tempC,tempD,tempA,tempB,iData[11],9); + tempB = CMD4_GG(tempB,tempC,tempD,tempA,iData[15],13); + + tempA = CMD4_HH(tempA,tempB,tempC,tempD,iData[ 0],3); + tempD = CMD4_HH(tempD,tempA,tempB,tempC,iData[ 8],9); + tempC = CMD4_HH(tempC,tempD,tempA,tempB,iData[ 4],11); + tempB = CMD4_HH(tempB,tempC,tempD,tempA,iData[12],15); + tempA = CMD4_HH(tempA,tempB,tempC,tempD,iData[ 2],3); + tempD = CMD4_HH(tempD,tempA,tempB,tempC,iData[10],9); + tempC = CMD4_HH(tempC,tempD,tempA,tempB,iData[ 6],11); + tempB = CMD4_HH(tempB,tempC,tempD,tempA,iData[14],15); + tempA = CMD4_HH(tempA,tempB,tempC,tempD,iData[ 1],3); + tempD = CMD4_HH(tempD,tempA,tempB,tempC,iData[ 9],9); + tempC = CMD4_HH(tempC,tempD,tempA,tempB,iData[ 5],11); + tempB = CMD4_HH(tempB,tempC,tempD,tempA,iData[13],15); + tempA = CMD4_HH(tempA,tempB,tempC,tempD,iData[ 3],3); + tempD = CMD4_HH(tempD,tempA,tempB,tempC,iData[11],9); + tempC = CMD4_HH(tempC,tempD,tempA,tempB,iData[ 7],11); + tempB = CMD4_HH(tempB,tempC,tempD,tempA,iData[15],15); + + iA+=tempA; + iB+=tempB; + iC+=tempC; + iD+=tempD; + } +#else +#ifdef MACRO +#define CMD4_FF(a, b, c, d, x, s) (CMD_R(a += CMD4_F(b,c,d) + x, s)) +#define CMD4_GG(a, b, c, d, x, s) (CMD_R(a += CMD4_G(b,c,d) + x + (TUint32)0x5a827999, s)) +#define CMD4_HH(a, b, c, d, x, s) (CMD_R(a += CMD4_H(b,c,d) + x + (TUint32)0x6ed9eba1, s)) +void CMD4Impl::Block() + { + register TUint tempA=iA; + register TUint tempB=iB; + register TUint tempC=iC; + register TUint tempD=iD; + + tempA = CMD4_FF(tempA,tempB,tempC,tempD,iData[ 0],3); + tempD = CMD4_FF(tempD,tempA,tempB,tempC,iData[ 1],7); + tempC = CMD4_FF(tempC,tempD,tempA,tempB,iData[ 2],11); + tempB = CMD4_FF(tempB,tempC,tempD,tempA,iData[ 3],19); + tempA = CMD4_FF(tempA,tempB,tempC,tempD,iData[ 4],3); + tempD = CMD4_FF(tempD,tempA,tempB,tempC,iData[ 5],7); + tempC = CMD4_FF(tempC,tempD,tempA,tempB,iData[ 6],11); + tempB = CMD4_FF(tempB,tempC,tempD,tempA,iData[ 7],19); + tempA = CMD4_FF(tempA,tempB,tempC,tempD,iData[ 8],3); + tempD = CMD4_FF(tempD,tempA,tempB,tempC,iData[ 9],7); + tempC = CMD4_FF(tempC,tempD,tempA,tempB,iData[10],11); + tempB = CMD4_FF(tempB,tempC,tempD,tempA,iData[11],19); + tempA = CMD4_FF(tempA,tempB,tempC,tempD,iData[12],3); + tempD = CMD4_FF(tempD,tempA,tempB,tempC,iData[13],7); + tempC = CMD4_FF(tempC,tempD,tempA,tempB,iData[14],11); + tempB = CMD4_FF(tempB,tempC,tempD,tempA,iData[15],19); + + tempA = CMD4_GG(tempA,tempB,tempC,tempD,iData[ 0],3); + tempD = CMD4_GG(tempD,tempA,tempB,tempC,iData[ 4],5); + tempC = CMD4_GG(tempC,tempD,tempA,tempB,iData[ 8],9); + tempB = CMD4_GG(tempB,tempC,tempD,tempA,iData[12],13); + tempA = CMD4_GG(tempA,tempB,tempC,tempD,iData[ 1],3); + tempD = CMD4_GG(tempD,tempA,tempB,tempC,iData[ 5],5); + tempC = CMD4_GG(tempC,tempD,tempA,tempB,iData[ 9],9); + tempB = CMD4_GG(tempB,tempC,tempD,tempA,iData[13],13); + tempA = CMD4_GG(tempA,tempB,tempC,tempD,iData[ 2],3); + tempD = CMD4_GG(tempD,tempA,tempB,tempC,iData[ 6],5); + tempC = CMD4_GG(tempC,tempD,tempA,tempB,iData[10],9); + tempB = CMD4_GG(tempB,tempC,tempD,tempA,iData[14],13); + tempA = CMD4_GG(tempA,tempB,tempC,tempD,iData[ 3],3); + tempD = CMD4_GG(tempD,tempA,tempB,tempC,iData[ 7],5); + tempC = CMD4_GG(tempC,tempD,tempA,tempB,iData[11],9); + tempB = CMD4_GG(tempB,tempC,tempD,tempA,iData[15],13); + + tempA = CMD4_HH(tempA,tempB,tempC,tempD,iData[ 0],3); + tempD = CMD4_HH(tempD,tempA,tempB,tempC,iData[ 8],9); + tempC = CMD4_HH(tempC,tempD,tempA,tempB,iData[ 4],11); + tempB = CMD4_HH(tempB,tempC,tempD,tempA,iData[12],15); + tempA = CMD4_HH(tempA,tempB,tempC,tempD,iData[ 2],3); + tempD = CMD4_HH(tempD,tempA,tempB,tempC,iData[10],9); + tempC = CMD4_HH(tempC,tempD,tempA,tempB,iData[ 6],11); + tempB = CMD4_HH(tempB,tempC,tempD,tempA,iData[14],15); + tempA = CMD4_HH(tempA,tempB,tempC,tempD,iData[ 1],3); + tempD = CMD4_HH(tempD,tempA,tempB,tempC,iData[ 9],9); + tempC = CMD4_HH(tempC,tempD,tempA,tempB,iData[ 5],11); + tempB = CMD4_HH(tempB,tempC,tempD,tempA,iData[13],15); + tempA = CMD4_HH(tempA,tempB,tempC,tempD,iData[ 3],3); + tempD = CMD4_HH(tempD,tempA,tempB,tempC,iData[11],9); + tempC = CMD4_HH(tempC,tempD,tempA,tempB,iData[ 7],11); + tempB = CMD4_HH(tempB,tempC,tempD,tempA,iData[15],15); + + iA+=tempA; + iB+=tempB; + iC+=tempC; + iD+=tempD; + } +#else +static inline void CMD4_FF(TUint& a,const TUint b,const TUint c,const TUint d,const TUint x,const TUint s) + { + a+=CMD4_F(b,c,d) + x; + a=CMD_R(a,s); + } +static inline void CMD4_GG(TUint& a,const TUint b,const TUint c,const TUint d,const TUint x,const TUint s) + { + a+=CMD4_G(b,c,d) + x + (TUint32)0x5a827999; + a=CMD_R(a,s); + } +static inline void CMD4_HH(TUint& a,const TUint b,const TUint c,const TUint d,const TUint x,const TUint s) + { + a+=CMD4_H(b,c,d) + x + (TUint32)0x6ed9eba1; + a=CMD_R(a,s); + } + +void CMD4Impl::Block() + { + register TUint tempA=iA; + register TUint tempB=iB; + register TUint tempC=iC; + register TUint tempD=iD; + + CMD4_FF(tempA,tempB,tempC,tempD,iData[ 0],3); + CMD4_FF(tempD,tempA,tempB,tempC,iData[ 1],7); + CMD4_FF(tempC,tempD,tempA,tempB,iData[ 2],11); + CMD4_FF(tempB,tempC,tempD,tempA,iData[ 3],19); + CMD4_FF(tempA,tempB,tempC,tempD,iData[ 4],3); + CMD4_FF(tempD,tempA,tempB,tempC,iData[ 5],7); + CMD4_FF(tempC,tempD,tempA,tempB,iData[ 6],11); + CMD4_FF(tempB,tempC,tempD,tempA,iData[ 7],19); + CMD4_FF(tempA,tempB,tempC,tempD,iData[ 8],3); + CMD4_FF(tempD,tempA,tempB,tempC,iData[ 9],7); + CMD4_FF(tempC,tempD,tempA,tempB,iData[10],11); + CMD4_FF(tempB,tempC,tempD,tempA,iData[11],19); + CMD4_FF(tempA,tempB,tempC,tempD,iData[12],3); + CMD4_FF(tempD,tempA,tempB,tempC,iData[13],7); + CMD4_FF(tempC,tempD,tempA,tempB,iData[14],11); + CMD4_FF(tempB,tempC,tempD,tempA,iData[15],19); + + CMD4_GG(tempA,tempB,tempC,tempD,iData[ 0],3); + CMD4_GG(tempD,tempA,tempB,tempC,iData[ 4],5); + CMD4_GG(tempC,tempD,tempA,tempB,iData[ 8],9); + CMD4_GG(tempB,tempC,tempD,tempA,iData[12],13); + CMD4_GG(tempA,tempB,tempC,tempD,iData[ 1],3); + CMD4_GG(tempD,tempA,tempB,tempC,iData[ 5],5); + CMD4_GG(tempC,tempD,tempA,tempB,iData[ 9],9); + CMD4_GG(tempB,tempC,tempD,tempA,iData[13],13); + CMD4_GG(tempA,tempB,tempC,tempD,iData[ 2],3); + CMD4_GG(tempD,tempA,tempB,tempC,iData[ 6],5); + CMD4_GG(tempC,tempD,tempA,tempB,iData[10],9); + CMD4_GG(tempB,tempC,tempD,tempA,iData[14],13); + CMD4_GG(tempA,tempB,tempC,tempD,iData[ 3],3); + CMD4_GG(tempD,tempA,tempB,tempC,iData[ 7],5); + CMD4_GG(tempC,tempD,tempA,tempB,iData[11],9); + CMD4_GG(tempB,tempC,tempD,tempA,iData[15],13); + + CMD4_HH(tempA,tempB,tempC,tempD,iData[ 0],3); + CMD4_HH(tempD,tempA,tempB,tempC,iData[ 8],9); + CMD4_HH(tempC,tempD,tempA,tempB,iData[ 4],11); + CMD4_HH(tempB,tempC,tempD,tempA,iData[12],15); + CMD4_HH(tempA,tempB,tempC,tempD,iData[ 2],3); + CMD4_HH(tempD,tempA,tempB,tempC,iData[10],9); + CMD4_HH(tempC,tempD,tempA,tempB,iData[ 6],11); + CMD4_HH(tempB,tempC,tempD,tempA,iData[14],15); + CMD4_HH(tempA,tempB,tempC,tempD,iData[ 1],3); + CMD4_HH(tempD,tempA,tempB,tempC,iData[ 9],9); + CMD4_HH(tempC,tempD,tempA,tempB,iData[ 5],11); + CMD4_HH(tempB,tempC,tempD,tempA,iData[13],15); + CMD4_HH(tempA,tempB,tempC,tempD,iData[ 3],3); + CMD4_HH(tempD,tempA,tempB,tempC,iData[11],9); + CMD4_HH(tempC,tempD,tempA,tempB,iData[ 7],11); + CMD4_HH(tempB,tempC,tempD,tempA,iData[15],15); + + iA+=tempA; + iB+=tempB; + iC+=tempC; + iD+=tempD; + } +#endif +#endif + +void CMD4Impl::DoFinal(void) + { + iNh += iNl; + const TUint ul128=128; + switch (iNl&3) + { + case 0: + iData[iNl>>2] = ul128; + break; + case 1: + iData[iNl>>2] += ul128<<8; + break; + case 2: + iData[iNl>>2] += ul128<<16; + break; + case 3: + iData[iNl>>2] += ul128<<24; + break; + default: + break; + }; + if (iNl>=56) + { + if (iNl<60) + iData[15]=0; + Block(); + Mem::FillZ(iData,14*sizeof(TUint)); + } + else + { + const TUint offset=(iNl+4)>>2; + Mem::FillZ(iData+offset,(14-offset)*sizeof(TUint)); + } + + iData[14]=iNh<<3;//number in bits + // this will fail if the total input length is longer than 2^32 in bits + //(2^31 in bytes) which is roughly half a gig. + iData[15]=0; + + Block(); + // + // Generate hash value into iHash + // + TUint tmp=iA; + iHash[0]=(TUint8)(tmp & 255); + iHash[1]=(TUint8)((tmp >>= 8) & 255); + iHash[2]=(TUint8)((tmp >>= 8) & 255); + iHash[3]=(TUint8)((tmp >>= 8) & 255); + + tmp=iB; + iHash[4]=(TUint8)(tmp & 255); + iHash[5]=(TUint8)((tmp >>= 8) & 255); + iHash[6]=(TUint8)((tmp >>= 8) & 255); + iHash[7]=(TUint8)((tmp >>= 8) & 255); + + tmp=iC; + iHash[8] =(TUint8)(tmp & 255); + iHash[9] =(TUint8)((tmp >>= 8) & 255); + iHash[10]=(TUint8)((tmp >>= 8) & 255); + iHash[11]=(TUint8)((tmp >>= 8) & 255); + + tmp=iD; + iHash[12]=(TUint8)(tmp & 255); + iHash[13]=(TUint8)((tmp >>= 8) & 255); + iHash[14]=(TUint8)((tmp >>= 8) & 255); + iHash[15]=(TUint8)((tmp >>= 8) & 255); + } + +void CMD4Impl::RestoreState() + { + iA = iACopy; + iB = iBCopy; + iC = iCCopy; + iD = iDCopy; + iNl = iNlCopy; + iNh = iNhCopy; + Mem::Copy(&iData[0], &iDataCopy[0], KMD4BlockSize*sizeof(TUint)); + } + +void CMD4Impl::StoreState() + { + iACopy = iA; + iBCopy = iB; + iCCopy = iC; + iDCopy = iD; + iNlCopy = iNl; + iNhCopy = iNh; + Mem::Copy(&iDataCopy[0], &iData[0], KMD4BlockSize*sizeof(TUint)); + } + + +// Implemented in hmacimpl.cpp or softwarehashbase.cpp +// but required as derived from MHash. No coverage here. +#ifdef _BullseyeCoverage +#pragma suppress_warnings on +#pragma BullseyeCoverage off +#pragma suppress_warnings off +#endif + +TAny* CMD4Impl::GetExtension(TUid /*aExtensionId*/) + { + return NULL; + } + +void CMD4Impl::SetOperationModeL(TUid /*aOperationMode*/) + { + User::Leave(KErrNotSupported); + } + +void CMD4Impl::SetKeyL(const CKey& /*aKey*/) + { + User::Leave(KErrNotSupported); + } + + + + diff -r 7e3f204e6c81 -r f9c11be8c0b3 cryptoplugins/cryptospiplugins/source/softwarecrypto/md4impl.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/cryptoplugins/cryptospiplugins/source/softwarecrypto/md4impl.h Tue Dec 01 11:12:04 2009 +0000 @@ -0,0 +1,103 @@ +/* +* Copyright (c) 2007-2009 Nokia Corporation and/or its subsidiary(-ies). +* All rights reserved. +* This component and the accompanying materials are made available +* under the terms of the License "Eclipse Public License v1.0" +* which accompanies this distribution, and is available +* at the URL "http://www.eclipse.org/legal/epl-v10.html". +* +* Initial Contributors: +* Nokia Corporation - initial contribution. +* +* Contributors: +* +* Description: +* Software md4 implementation +* +*/ + + +/** + @file + @internalComponent + @released +*/ + +#ifndef __CRYPTOAPI_SOFTWAREMD4IMPL_H__ +#define __CRYPTOAPI_SOFTWAREMD4IMPL_H__ + +#include "softwarehashbase.h" + +namespace SoftwareCrypto + { + using namespace CryptoSpi; + + const TInt KMD4BlockSize = 16; + const TInt KMD4HashSize = 16; + + NONSHARABLE_CLASS(CMD4Impl) : public CBase, public MSoftwareHash + { + public: + //NewL & NewLC + static CMD4Impl* NewL(); + static CMD4Impl* NewLC(); + + //From MPlugin + void Reset(); + void Close(); + void GetCharacteristicsL(const TCharacteristics*& aPluginCharacteristics); + static CExtendedCharacteristics* CreateExtendedCharacteristicsL(); + const CExtendedCharacteristics* GetExtendedCharacteristicsL(); + TAny* GetExtension(TUid aExtensionId); + + //From MHash + TPtrC8 Hash(const TDesC8& aMessage); + void Update(const TDesC8& aMessage); + TPtrC8 Final(const TDesC8& aMessage); + MHash* ReplicateL(); + MHash* CopyL(); + void SetKeyL(const CKey& aKey); + void SetOperationModeL(TUid aOperationMode); + + //From MSoftwareHash + void RestoreState(); + void StoreState(); + + private: + //Constructors + CMD4Impl(); + CMD4Impl(const CMD4Impl& aCMD4Impl); + + //Destructor + ~CMD4Impl(); + + TUid ImplementationUid(); + + void DoUpdate(const TUint8* aData,TUint aLength); + void DoFinal(void); + void Block(); + + private: + TBuf8 iHash; + + TUint iA; + TUint iB; + TUint iC; + TUint iD; + TUint iNl; + TUint iNh; + TUint iData[KMD4BlockSize]; + + TUint iACopy; + TUint iBCopy; + TUint iCCopy; + TUint iDCopy; + TUint iNlCopy; + TUint iNhCopy; + TUint iDataCopy[KMD4BlockSize]; + + }; + } + +#endif // __CRYPTOAPI_SOFTWAREMD4IMPL_H__ + diff -r 7e3f204e6c81 -r f9c11be8c0b3 cryptoplugins/cryptospiplugins/source/softwarecrypto/md5impl.cpp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/cryptoplugins/cryptospiplugins/source/softwarecrypto/md5impl.cpp Tue Dec 01 11:12:04 2009 +0000 @@ -0,0 +1,604 @@ +/* +* Copyright (c) 2006-2009 Nokia Corporation and/or its subsidiary(-ies). +* All rights reserved. +* This component and the accompanying materials are made available +* under the terms of the License "Eclipse Public License v1.0" +* which accompanies this distribution, and is available +* at the URL "http://www.eclipse.org/legal/epl-v10.html". +* +* Initial Contributors: +* Nokia Corporation - initial contribution. +* +* Contributors: +* +* Description: +* software md5 implementation +* software md5 implementation +* +*/ + + +/** + @file +*/ + +#include "md5impl.h" +#include +#include "pluginconfig.h" + +using namespace SoftwareCrypto; + + +CMD5Impl* CMD5Impl::NewL() + { + CMD5Impl* self=new (ELeave) CMD5Impl(); + self->Reset(); + return self; + } + +CMD5Impl* CMD5Impl::NewLC() + { + CMD5Impl* self=NewL(); + CleanupStack::PushL(self); + return self; + } + +CMD5Impl::CMD5Impl() : iHash(KMD5HashSize) + { + } + +CMD5Impl::CMD5Impl(const CMD5Impl& aCMD5Impl) +: iHash(aCMD5Impl.iHash),iA(aCMD5Impl.iA),iB(aCMD5Impl.iB),iC(aCMD5Impl.iC),iD(aCMD5Impl.iD), + iNl(aCMD5Impl.iNl),iNh(aCMD5Impl.iNh) + { + (void)Mem::Copy(iData, aCMD5Impl.iData, sizeof(iData)); + } + +CMD5Impl::~CMD5Impl() + { + } + +void CMD5Impl::Reset() + { + iA=0x67452301; + iB=0xefcdab89; + iC=0x98badcfe; + iD=0x10325476; + iNh=0; + iNl=0; + } + +void CMD5Impl::Close() + { + delete this; + } + +void CMD5Impl::GetCharacteristicsL(const TCharacteristics*& aPluginCharacteristics) + { + aPluginCharacteristics=NULL; + TInt hashNum=sizeof(KHashCharacteristics)/sizeof(THashCharacteristics*); + for (TInt i=0;icmn.iImplementationUID == ImplementationUid().iUid) + { + aPluginCharacteristics = KHashCharacteristics[i]; + break; + } + } + } + +CExtendedCharacteristics* CMD5Impl::CreateExtendedCharacteristicsL() + { + // All Symbian software plug-ins have unlimited concurrency, cannot be reserved + // for exclusive use and are not CERTIFIED to be standards compliant. + return CExtendedCharacteristics::NewL(KMaxTInt, EFalse); + } + +const CExtendedCharacteristics* CMD5Impl::GetExtendedCharacteristicsL() + { + return CMD5Impl::CreateExtendedCharacteristicsL(); + } + +TPtrC8 CMD5Impl::Hash(const TDesC8& aMessage) + { + + TPtrC8 ptr(KNullDesC8()); + DoUpdate(aMessage.Ptr(),aMessage.Size()); + StoreState(); + DoFinal(); + ptr.Set(iHash); + RestoreState(); + return ptr; + } + +void CMD5Impl::Update(const TDesC8& aMessage) + { + DoUpdate(aMessage.Ptr(),aMessage.Size()); + } + +TPtrC8 CMD5Impl::Final(const TDesC8& aMessage) + { + TPtrC8 ptr(KNullDesC8()); + if (aMessage!=KNullDesC8()) + { + DoUpdate(aMessage.Ptr(),aMessage.Size()); + } + DoFinal(); + ptr.Set(iHash); + Reset(); + return ptr; + } + +MHash* CMD5Impl::ReplicateL() + { + return CMD5Impl::NewL(); + } + +MHash* CMD5Impl::CopyL() + { + return new(ELeave) CMD5Impl(*this); + } + +TUid CMD5Impl::ImplementationUid() + { + return KCryptoPluginMd5Uid; + } + +void CMD5Impl::DoUpdate(const TUint8* aData,TUint aLength) + { + const TUint8* pend=aData+aLength; + for (const TUint8* paData=aData;paData>2]=byte; + break; + case 1: + iData[iNl>>2]|=byte<<8; + break; + case 2: + iData[iNl>>2]|=byte<<16; + break; + case 3: + iData[iNl>>2]|=byte<<24; + break; + default: + break; + }; + if(++iNl==64) + { + Block(); + iNh+=64; + iNl=0; + } + } + } + +static inline TUint CMD5_F(TUint x,TUint y,TUint z) + { + return (x&y) | (~x&z); + } +static inline TUint CMD5_G(TUint x,TUint y,TUint z) + { + return (x&z) | (y&~z); + } +static inline TUint CMD5_H(TUint x,TUint y,TUint z) + { + return x^y^z; + } +static inline TUint CMD5_I(TUint x,TUint y,TUint z) + { + return y^(x|~z); + } + + +#ifdef NOREFS +static inline TUint CMD5_FF(TUint a,const TUint b,const TUint c,const TUint d,const TUint m,const TUint s,const TUint t) + { + a+=CMD5_F(b,c,d) + m + t; + a=b + CMD_R(a,s); + return a; + } +static inline TUint CMD5_GG(TUint a,const TUint b,const TUint c,const TUint d,const TUint m,const TUint s,const TUint t) + { + a+=CMD5_G(b,c,d) + m + t; + a=b + CMD_R(a,s); + return a; + } +static inline TUint CMD5_HH(TUint a,const TUint b,const TUint c,const TUint d,const TUint m,const TUint s,const TUint t) + { + a+=CMD5_H(b,c,d) + m + t; + a=b + CMD_R(a,s); + return a; + } +static inline TUint CMD5_II(TUint a,const TUint b,const TUint c,const TUint d,const TUint m,const TUint s,const TUint t) + { + a+=CMD5_I(b,c,d) + m + t; + a=b + CMD_R(a,s); + return a; + } +void CMD5Impl::Block() + { + register TUint tempA=iA; + register TUint tempB=iB; + register TUint tempC=iC; + register TUint tempD=iD; + + tempA = CMD5_FF(tempA,tempB,tempC,tempD,iData[ 0], 7, 0xd76aa478); + tempD = CMD5_FF(tempD,tempA,tempB,tempC,iData[ 1],12, 0xe8c7b756); + tempC = CMD5_FF(tempC,tempD,tempA,tempB,iData[ 2],17, 0x242070db); + tempB = CMD5_FF(tempB,tempC,tempD,tempA,iData[ 3],22, 0xc1bdceee); + tempA = CMD5_FF(tempA,tempB,tempC,tempD,iData[ 4], 7, 0xf57c0faf); + tempD = CMD5_FF(tempD,tempA,tempB,tempC,iData[ 5],12, 0x4787c62a); + tempC = CMD5_FF(tempC,tempD,tempA,tempB,iData[ 6],17, 0xa8304613); + tempB = CMD5_FF(tempB,tempC,tempD,tempA,iData[ 7],22, 0xfd469501); + tempA = CMD5_FF(tempA,tempB,tempC,tempD,iData[ 8], 7, 0x698098d8); + tempD = CMD5_FF(tempD,tempA,tempB,tempC,iData[ 9],12, 0x8b44f7af); + tempC = CMD5_FF(tempC,tempD,tempA,tempB,iData[10],17, 0xffff5bb1); + tempB = CMD5_FF(tempB,tempC,tempD,tempA,iData[11],22, 0x895cd7be); + tempA = CMD5_FF(tempA,tempB,tempC,tempD,iData[12], 7, 0x6b901122); + tempD = CMD5_FF(tempD,tempA,tempB,tempC,iData[13],12, 0xfd987193); + tempC = CMD5_FF(tempC,tempD,tempA,tempB,iData[14],17, 0xa679438e); + tempB = CMD5_FF(tempB,tempC,tempD,tempA,iData[15],22, 0x49b40821); + + tempA = CMD5_GG(tempA,tempB,tempC,tempD,iData[ 1], 5, 0xf61e2562); + tempD = CMD5_GG(tempD,tempA,tempB,tempC,iData[ 6], 9, 0xc040b340); + tempC = CMD5_GG(tempC,tempD,tempA,tempB,iData[11],14, 0x265e5a51); + tempB = CMD5_GG(tempB,tempC,tempD,tempA,iData[ 0],20, 0xe9b6c7aa); + tempA = CMD5_GG(tempA,tempB,tempC,tempD,iData[ 5], 5, 0xd62f105d); + tempD = CMD5_GG(tempD,tempA,tempB,tempC,iData[10], 9, 0x02441453); + tempC = CMD5_GG(tempC,tempD,tempA,tempB,iData[15],14, 0xd8a1e681); + tempB = CMD5_GG(tempB,tempC,tempD,tempA,iData[ 4],20, 0xe7d3fbc8); + tempA = CMD5_GG(tempA,tempB,tempC,tempD,iData[ 9], 5, 0x21e1cde6); + tempD = CMD5_GG(tempD,tempA,tempB,tempC,iData[14], 9, 0xc33707d6); + tempC = CMD5_GG(tempC,tempD,tempA,tempB,iData[ 3],14, 0xf4d50d87); + tempB = CMD5_GG(tempB,tempC,tempD,tempA,iData[ 8],20, 0x455a14ed); + tempA = CMD5_GG(tempA,tempB,tempC,tempD,iData[13], 5, 0xa9e3e905); + tempD = CMD5_GG(tempD,tempA,tempB,tempC,iData[ 2], 9, 0xfcefa3f8); + tempC = CMD5_GG(tempC,tempD,tempA,tempB,iData[ 7],14, 0x676f02d9); + tempB = CMD5_GG(tempB,tempC,tempD,tempA,iData[12],20, 0x8d2a4c8a); + + tempA = CMD5_HH(tempA,tempB,tempC,tempD,iData[ 5], 4, 0xfffa3942); + tempD = CMD5_HH(tempD,tempA,tempB,tempC,iData[ 8],11, 0x8771f681); + tempC = CMD5_HH(tempC,tempD,tempA,tempB,iData[11],16, 0x6d9d6122); + tempB = CMD5_HH(tempB,tempC,tempD,tempA,iData[14],23, 0xfde5380c); + tempA = CMD5_HH(tempA,tempB,tempC,tempD,iData[ 1], 4, 0xa4beea44); + tempD = CMD5_HH(tempD,tempA,tempB,tempC,iData[ 4],11, 0x4bdecfa9); + tempC = CMD5_HH(tempC,tempD,tempA,tempB,iData[ 7],16, 0xf6bb4b60); + tempB = CMD5_HH(tempB,tempC,tempD,tempA,iData[10],23, 0xbebfbc70); + tempA = CMD5_HH(tempA,tempB,tempC,tempD,iData[13], 4, 0x289b7ec6); + tempD = CMD5_HH(tempD,tempA,tempB,tempC,iData[ 0],11, 0xeaa127fa); + tempC = CMD5_HH(tempC,tempD,tempA,tempB,iData[ 3],16, 0xd4ef3085); + tempB = CMD5_HH(tempB,tempC,tempD,tempA,iData[ 6],23, 0x04881d05); + tempA = CMD5_HH(tempA,tempB,tempC,tempD,iData[ 9], 4, 0xd9d4d039); + tempD = CMD5_HH(tempD,tempA,tempB,tempC,iData[12],11, 0xe6db99e5); + tempC = CMD5_HH(tempC,tempD,tempA,tempB,iData[15],16, 0x1fa27cf8); + tempB = CMD5_HH(tempB,tempC,tempD,tempA,iData[ 2],23, 0xc4ac5665); + + tempA = CMD5_II(tempA,tempB,tempC,tempD,iData[ 0], 6, 0xf4292244); + tempD = CMD5_II(tempD,tempA,tempB,tempC,iData[ 7],10, 0x432aff97); + tempC = CMD5_II(tempC,tempD,tempA,tempB,iData[14],15, 0xab9423a7); + tempB = CMD5_II(tempB,tempC,tempD,tempA,iData[ 5],21, 0xfc93a039); + tempA = CMD5_II(tempA,tempB,tempC,tempD,iData[12], 6, 0x655b59c3); + tempD = CMD5_II(tempD,tempA,tempB,tempC,iData[ 3],10, 0x8f0ccc92); + tempC = CMD5_II(tempC,tempD,tempA,tempB,iData[10],15, 0xffeff47d); + tempB = CMD5_II(tempB,tempC,tempD,tempA,iData[ 1],21, 0x85845dd1); + tempA = CMD5_II(tempA,tempB,tempC,tempD,iData[ 8], 6, 0x6fa87e4f); + tempD = CMD5_II(tempD,tempA,tempB,tempC,iData[15],10, 0xfe2ce6e0); + tempC = CMD5_II(tempC,tempD,tempA,tempB,iData[ 6],15, 0xa3014314); + tempB = CMD5_II(tempB,tempC,tempD,tempA,iData[13],21, 0x4e0811a1); + tempA = CMD5_II(tempA,tempB,tempC,tempD,iData[ 4], 6, 0xf7537e82); + tempD = CMD5_II(tempD,tempA,tempB,tempC,iData[11],10, 0xbd3af235); + tempC = CMD5_II(tempC,tempD,tempA,tempB,iData[ 2],15, 0x2ad7d2bb); + tempB = CMD5_II(tempB,tempC,tempD,tempA,iData[ 9],21, 0xeb86d391); + + iA+=tempA; + iB+=tempB; + iC+=tempC; + iD+=tempD; + } +#else +#ifdef MACRO +#define CMD5_FF(a, b, c, d, m, s, t) (b + CMD_R(a += CMD5_F(b,c,d) + m + t, s)) +#define CMD5_GG(a, b, c, d, m, s, t) (b + CMD_R(a += CMD5_G(b,c,d) + m + t, s)) +#define CMD5_HH(a, b, c, d, m, s, t) (b + CMD_R(a += CMD5_H(b,c,d) + m + t, s)) +#define CMD5_II(a, b, c, d, m, s, t) (b + CMD_R(a += CMD5_I(b,c,d) + m + t, s)) +void CMD5Impl::Block() + { + register TUint tempA=iA; + register TUint tempB=iB; + register TUint tempC=iC; + register TUint tempD=iD; + + tempA = CMD5_FF(tempA,tempB,tempC,tempD,iData[ 0], 7, 0xd76aa478); + tempD = CMD5_FF(tempD,tempA,tempB,tempC,iData[ 1],12, 0xe8c7b756); + tempC = CMD5_FF(tempC,tempD,tempA,tempB,iData[ 2],17, 0x242070db); + tempB = CMD5_FF(tempB,tempC,tempD,tempA,iData[ 3],22, 0xc1bdceee); + tempA = CMD5_FF(tempA,tempB,tempC,tempD,iData[ 4], 7, 0xf57c0faf); + tempD = CMD5_FF(tempD,tempA,tempB,tempC,iData[ 5],12, 0x4787c62a); + tempC = CMD5_FF(tempC,tempD,tempA,tempB,iData[ 6],17, 0xa8304613); + tempB = CMD5_FF(tempB,tempC,tempD,tempA,iData[ 7],22, 0xfd469501); + tempA = CMD5_FF(tempA,tempB,tempC,tempD,iData[ 8], 7, 0x698098d8); + tempD = CMD5_FF(tempD,tempA,tempB,tempC,iData[ 9],12, 0x8b44f7af); + tempC = CMD5_FF(tempC,tempD,tempA,tempB,iData[10],17, 0xffff5bb1); + tempB = CMD5_FF(tempB,tempC,tempD,tempA,iData[11],22, 0x895cd7be); + tempA = CMD5_FF(tempA,tempB,tempC,tempD,iData[12], 7, 0x6b901122); + tempD = CMD5_FF(tempD,tempA,tempB,tempC,iData[13],12, 0xfd987193); + tempC = CMD5_FF(tempC,tempD,tempA,tempB,iData[14],17, 0xa679438e); + tempB = CMD5_FF(tempB,tempC,tempD,tempA,iData[15],22, 0x49b40821); + + tempA = CMD5_GG(tempA,tempB,tempC,tempD,iData[ 1], 5, 0xf61e2562); + tempD = CMD5_GG(tempD,tempA,tempB,tempC,iData[ 6], 9, 0xc040b340); + tempC = CMD5_GG(tempC,tempD,tempA,tempB,iData[11],14, 0x265e5a51); + tempB = CMD5_GG(tempB,tempC,tempD,tempA,iData[ 0],20, 0xe9b6c7aa); + tempA = CMD5_GG(tempA,tempB,tempC,tempD,iData[ 5], 5, 0xd62f105d); + tempD = CMD5_GG(tempD,tempA,tempB,tempC,iData[10], 9, 0x02441453); + tempC = CMD5_GG(tempC,tempD,tempA,tempB,iData[15],14, 0xd8a1e681); + tempB = CMD5_GG(tempB,tempC,tempD,tempA,iData[ 4],20, 0xe7d3fbc8); + tempA = CMD5_GG(tempA,tempB,tempC,tempD,iData[ 9], 5, 0x21e1cde6); + tempD = CMD5_GG(tempD,tempA,tempB,tempC,iData[14], 9, 0xc33707d6); + tempC = CMD5_GG(tempC,tempD,tempA,tempB,iData[ 3],14, 0xf4d50d87); + tempB = CMD5_GG(tempB,tempC,tempD,tempA,iData[ 8],20, 0x455a14ed); + tempA = CMD5_GG(tempA,tempB,tempC,tempD,iData[13], 5, 0xa9e3e905); + tempD = CMD5_GG(tempD,tempA,tempB,tempC,iData[ 2], 9, 0xfcefa3f8); + tempC = CMD5_GG(tempC,tempD,tempA,tempB,iData[ 7],14, 0x676f02d9); + tempB = CMD5_GG(tempB,tempC,tempD,tempA,iData[12],20, 0x8d2a4c8a); + + tempA = CMD5_HH(tempA,tempB,tempC,tempD,iData[ 5], 4, 0xfffa3942); + tempD = CMD5_HH(tempD,tempA,tempB,tempC,iData[ 8],11, 0x8771f681); + tempC = CMD5_HH(tempC,tempD,tempA,tempB,iData[11],16, 0x6d9d6122); + tempB = CMD5_HH(tempB,tempC,tempD,tempA,iData[14],23, 0xfde5380c); + tempA = CMD5_HH(tempA,tempB,tempC,tempD,iData[ 1], 4, 0xa4beea44); + tempD = CMD5_HH(tempD,tempA,tempB,tempC,iData[ 4],11, 0x4bdecfa9); + tempC = CMD5_HH(tempC,tempD,tempA,tempB,iData[ 7],16, 0xf6bb4b60); + tempB = CMD5_HH(tempB,tempC,tempD,tempA,iData[10],23, 0xbebfbc70); + tempA = CMD5_HH(tempA,tempB,tempC,tempD,iData[13], 4, 0x289b7ec6); + tempD = CMD5_HH(tempD,tempA,tempB,tempC,iData[ 0],11, 0xeaa127fa); + tempC = CMD5_HH(tempC,tempD,tempA,tempB,iData[ 3],16, 0xd4ef3085); + tempB = CMD5_HH(tempB,tempC,tempD,tempA,iData[ 6],23, 0x04881d05); + tempA = CMD5_HH(tempA,tempB,tempC,tempD,iData[ 9], 4, 0xd9d4d039); + tempD = CMD5_HH(tempD,tempA,tempB,tempC,iData[12],11, 0xe6db99e5); + tempC = CMD5_HH(tempC,tempD,tempA,tempB,iData[15],16, 0x1fa27cf8); + tempB = CMD5_HH(tempB,tempC,tempD,tempA,iData[ 2],23, 0xc4ac5665); + + tempA = CMD5_II(tempA,tempB,tempC,tempD,iData[ 0], 6, 0xf4292244); + tempD = CMD5_II(tempD,tempA,tempB,tempC,iData[ 7],10, 0x432aff97); + tempC = CMD5_II(tempC,tempD,tempA,tempB,iData[14],15, 0xab9423a7); + tempB = CMD5_II(tempB,tempC,tempD,tempA,iData[ 5],21, 0xfc93a039); + tempA = CMD5_II(tempA,tempB,tempC,tempD,iData[12], 6, 0x655b59c3); + tempD = CMD5_II(tempD,tempA,tempB,tempC,iData[ 3],10, 0x8f0ccc92); + tempC = CMD5_II(tempC,tempD,tempA,tempB,iData[10],15, 0xffeff47d); + tempB = CMD5_II(tempB,tempC,tempD,tempA,iData[ 1],21, 0x85845dd1); + tempA = CMD5_II(tempA,tempB,tempC,tempD,iData[ 8], 6, 0x6fa87e4f); + tempD = CMD5_II(tempD,tempA,tempB,tempC,iData[15],10, 0xfe2ce6e0); + tempC = CMD5_II(tempC,tempD,tempA,tempB,iData[ 6],15, 0xa3014314); + tempB = CMD5_II(tempB,tempC,tempD,tempA,iData[13],21, 0x4e0811a1); + tempA = CMD5_II(tempA,tempB,tempC,tempD,iData[ 4], 6, 0xf7537e82); + tempD = CMD5_II(tempD,tempA,tempB,tempC,iData[11],10, 0xbd3af235); + tempC = CMD5_II(tempC,tempD,tempA,tempB,iData[ 2],15, 0x2ad7d2bb); + tempB = CMD5_II(tempB,tempC,tempD,tempA,iData[ 9],21, 0xeb86d391); + + iA+=tempA; + iB+=tempB; + iC+=tempC; + iD+=tempD; + } +#else +static inline void CMD5_FF(TUint& a,const TUint b,const TUint c,const TUint d,const TUint m,const TUint s,const TUint t) + { + a+=CMD5_F(b,c,d) + m + t; + a=b + CMD_R(a,s); + } +static inline void CMD5_GG(TUint& a,const TUint b,const TUint c,const TUint d,const TUint m,const TUint s,const TUint t) + { + a+=CMD5_G(b,c,d) + m + t; + a=b + CMD_R(a,s); + } +static inline void CMD5_HH(TUint& a,const TUint b,const TUint c,const TUint d,const TUint m,const TUint s,const TUint t) + { + a+=CMD5_H(b,c,d) + m + t; + a=b + CMD_R(a,s); + } +static inline void CMD5_II(TUint& a,const TUint b,const TUint c,const TUint d,const TUint m,const TUint s,const TUint t) + { + a+=CMD5_I(b,c,d) + m + t; + a=b + CMD_R(a,s); + } +void CMD5Impl::Block() + { + register TUint tempA=iA; + register TUint tempB=iB; + register TUint tempC=iC; + register TUint tempD=iD; + + CMD5_FF(tempA,tempB,tempC,tempD,iData[ 0], 7, 0xd76aa478); + CMD5_FF(tempD,tempA,tempB,tempC,iData[ 1],12, 0xe8c7b756); + CMD5_FF(tempC,tempD,tempA,tempB,iData[ 2],17, 0x242070db); + CMD5_FF(tempB,tempC,tempD,tempA,iData[ 3],22, 0xc1bdceee); + CMD5_FF(tempA,tempB,tempC,tempD,iData[ 4], 7, 0xf57c0faf); + CMD5_FF(tempD,tempA,tempB,tempC,iData[ 5],12, 0x4787c62a); + CMD5_FF(tempC,tempD,tempA,tempB,iData[ 6],17, 0xa8304613); + CMD5_FF(tempB,tempC,tempD,tempA,iData[ 7],22, 0xfd469501); + CMD5_FF(tempA,tempB,tempC,tempD,iData[ 8], 7, 0x698098d8); + CMD5_FF(tempD,tempA,tempB,tempC,iData[ 9],12, 0x8b44f7af); + CMD5_FF(tempC,tempD,tempA,tempB,iData[10],17, 0xffff5bb1); + CMD5_FF(tempB,tempC,tempD,tempA,iData[11],22, 0x895cd7be); + CMD5_FF(tempA,tempB,tempC,tempD,iData[12], 7, 0x6b901122); + CMD5_FF(tempD,tempA,tempB,tempC,iData[13],12, 0xfd987193); + CMD5_FF(tempC,tempD,tempA,tempB,iData[14],17, 0xa679438e); + CMD5_FF(tempB,tempC,tempD,tempA,iData[15],22, 0x49b40821); + + CMD5_GG(tempA,tempB,tempC,tempD,iData[ 1], 5, 0xf61e2562); + CMD5_GG(tempD,tempA,tempB,tempC,iData[ 6], 9, 0xc040b340); + CMD5_GG(tempC,tempD,tempA,tempB,iData[11],14, 0x265e5a51); + CMD5_GG(tempB,tempC,tempD,tempA,iData[ 0],20, 0xe9b6c7aa); + CMD5_GG(tempA,tempB,tempC,tempD,iData[ 5], 5, 0xd62f105d); + CMD5_GG(tempD,tempA,tempB,tempC,iData[10], 9, 0x02441453); + CMD5_GG(tempC,tempD,tempA,tempB,iData[15],14, 0xd8a1e681); + CMD5_GG(tempB,tempC,tempD,tempA,iData[ 4],20, 0xe7d3fbc8); + CMD5_GG(tempA,tempB,tempC,tempD,iData[ 9], 5, 0x21e1cde6); + CMD5_GG(tempD,tempA,tempB,tempC,iData[14], 9, 0xc33707d6); + CMD5_GG(tempC,tempD,tempA,tempB,iData[ 3],14, 0xf4d50d87); + CMD5_GG(tempB,tempC,tempD,tempA,iData[ 8],20, 0x455a14ed); + CMD5_GG(tempA,tempB,tempC,tempD,iData[13], 5, 0xa9e3e905); + CMD5_GG(tempD,tempA,tempB,tempC,iData[ 2], 9, 0xfcefa3f8); + CMD5_GG(tempC,tempD,tempA,tempB,iData[ 7],14, 0x676f02d9); + CMD5_GG(tempB,tempC,tempD,tempA,iData[12],20, 0x8d2a4c8a); + + CMD5_HH(tempA,tempB,tempC,tempD,iData[ 5], 4, 0xfffa3942); + CMD5_HH(tempD,tempA,tempB,tempC,iData[ 8],11, 0x8771f681); + CMD5_HH(tempC,tempD,tempA,tempB,iData[11],16, 0x6d9d6122); + CMD5_HH(tempB,tempC,tempD,tempA,iData[14],23, 0xfde5380c); + CMD5_HH(tempA,tempB,tempC,tempD,iData[ 1], 4, 0xa4beea44); + CMD5_HH(tempD,tempA,tempB,tempC,iData[ 4],11, 0x4bdecfa9); + CMD5_HH(tempC,tempD,tempA,tempB,iData[ 7],16, 0xf6bb4b60); + CMD5_HH(tempB,tempC,tempD,tempA,iData[10],23, 0xbebfbc70); + CMD5_HH(tempA,tempB,tempC,tempD,iData[13], 4, 0x289b7ec6); + CMD5_HH(tempD,tempA,tempB,tempC,iData[ 0],11, 0xeaa127fa); + CMD5_HH(tempC,tempD,tempA,tempB,iData[ 3],16, 0xd4ef3085); + CMD5_HH(tempB,tempC,tempD,tempA,iData[ 6],23, 0x04881d05); + CMD5_HH(tempA,tempB,tempC,tempD,iData[ 9], 4, 0xd9d4d039); + CMD5_HH(tempD,tempA,tempB,tempC,iData[12],11, 0xe6db99e5); + CMD5_HH(tempC,tempD,tempA,tempB,iData[15],16, 0x1fa27cf8); + CMD5_HH(tempB,tempC,tempD,tempA,iData[ 2],23, 0xc4ac5665); + + CMD5_II(tempA,tempB,tempC,tempD,iData[ 0], 6, 0xf4292244); + CMD5_II(tempD,tempA,tempB,tempC,iData[ 7],10, 0x432aff97); + CMD5_II(tempC,tempD,tempA,tempB,iData[14],15, 0xab9423a7); + CMD5_II(tempB,tempC,tempD,tempA,iData[ 5],21, 0xfc93a039); + CMD5_II(tempA,tempB,tempC,tempD,iData[12], 6, 0x655b59c3); + CMD5_II(tempD,tempA,tempB,tempC,iData[ 3],10, 0x8f0ccc92); + CMD5_II(tempC,tempD,tempA,tempB,iData[10],15, 0xffeff47d); + CMD5_II(tempB,tempC,tempD,tempA,iData[ 1],21, 0x85845dd1); + CMD5_II(tempA,tempB,tempC,tempD,iData[ 8], 6, 0x6fa87e4f); + CMD5_II(tempD,tempA,tempB,tempC,iData[15],10, 0xfe2ce6e0); + CMD5_II(tempC,tempD,tempA,tempB,iData[ 6],15, 0xa3014314); + CMD5_II(tempB,tempC,tempD,tempA,iData[13],21, 0x4e0811a1); + CMD5_II(tempA,tempB,tempC,tempD,iData[ 4], 6, 0xf7537e82); + CMD5_II(tempD,tempA,tempB,tempC,iData[11],10, 0xbd3af235); + CMD5_II(tempC,tempD,tempA,tempB,iData[ 2],15, 0x2ad7d2bb); + CMD5_II(tempB,tempC,tempD,tempA,iData[ 9],21, 0xeb86d391); + + iA+=tempA; + iB+=tempB; + iC+=tempC; + iD+=tempD; + } +#endif +#endif + +void CMD5Impl::DoFinal(void) + { + iNh += iNl; + const TUint ul128=128; + switch (iNl&3) + { + case 0: + iData[iNl>>2] = ul128; + break; + case 1: + iData[iNl>>2] += ul128<<8; + break; + case 2: + iData[iNl>>2] += ul128<<16; + break; + case 3: + iData[iNl>>2] += ul128<<24; + break; + default: + break; + }; + if (iNl>=56) + { + if (iNl<60) + iData[15]=0; + Block(); + Mem::FillZ(iData,14*sizeof(TUint)); + } + else + { + const TUint offset=(iNl+4)>>2; + Mem::FillZ(iData+offset,(14-offset)*sizeof(TUint)); + } + + iData[14]=iNh<<3;//number in bits + // this will fail if the total input length is longer than 2^32 in bits + //(2^31 in bytes) which is roughly half a gig. + iData[15]=0; + Block(); + // + // Generate hash value into iHash + // + TUint tmp=iA; + iHash[0]=(TUint8)(tmp & 255); + iHash[1]=(TUint8)((tmp >>= 8) & 255); + iHash[2]=(TUint8)((tmp >>= 8) & 255); + iHash[3]=(TUint8)((tmp >>= 8) & 255); + + tmp=iB; + iHash[4]=(TUint8)(tmp & 255); + iHash[5]=(TUint8)((tmp >>= 8) & 255); + iHash[6]=(TUint8)((tmp >>= 8) & 255); + iHash[7]=(TUint8)((tmp >>= 8) & 255); + + tmp=iC; + iHash[8]=(TUint8)(tmp & 255); + iHash[9]=(TUint8)((tmp >>= 8) & 255); + iHash[10]=(TUint8)((tmp >>= 8) & 255); + iHash[11]=(TUint8)((tmp >>= 8) & 255); + + tmp=iD; + iHash[12]=(TUint8)(tmp & 255); + iHash[13]=(TUint8)((tmp >>= 8) & 255); + iHash[14]=(TUint8)((tmp >>= 8) & 255); + iHash[15]=(TUint8)((tmp >>= 8) & 255); + } + +void CMD5Impl::RestoreState() + { + iA = iACopy; + iB = iBCopy; + iC = iCCopy; + iD = iDCopy; + iNl = iNlCopy; + iNh = iNhCopy; + Mem::Copy(&iData[0], &iDataCopy[0], KMD5BlockSize*sizeof(TUint)); + } + +void CMD5Impl::StoreState() + { + iACopy = iA; + iBCopy = iB; + iCCopy = iC; + iDCopy = iD; + iNlCopy = iNl; + iNhCopy = iNh; + Mem::Copy(&iDataCopy[0], &iData[0], KMD5BlockSize*sizeof(TUint)); + } + + +// Implemented in hmacimpl.cpp or softwarehashbase.cpp +// but required as derived from MHash. No coverage here. +#ifdef _BullseyeCoverage +#pragma suppress_warnings on +#pragma BullseyeCoverage off +#pragma suppress_warnings off +#endif + +TAny* CMD5Impl::GetExtension(TUid /*aExtensionId*/) + { + return NULL; + } + +void CMD5Impl::SetOperationModeL(TUid /*aOperationMode*/) + { + User::Leave(KErrNotSupported); + } + +void CMD5Impl::SetKeyL(const CKey& /*aKey*/) + { + User::Leave(KErrNotSupported); + } + diff -r 7e3f204e6c81 -r f9c11be8c0b3 cryptoplugins/cryptospiplugins/source/softwarecrypto/md5impl.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/cryptoplugins/cryptospiplugins/source/softwarecrypto/md5impl.h Tue Dec 01 11:12:04 2009 +0000 @@ -0,0 +1,102 @@ +/* +* Copyright (c) 2006-2009 Nokia Corporation and/or its subsidiary(-ies). +* All rights reserved. +* This component and the accompanying materials are made available +* under the terms of the License "Eclipse Public License v1.0" +* which accompanies this distribution, and is available +* at the URL "http://www.eclipse.org/legal/epl-v10.html". +* +* Initial Contributors: +* Nokia Corporation - initial contribution. +* +* Contributors: +* +* Description: +* Software md5 implementation +* +*/ + + +/** + @file + @internalComponent + @released +*/ + +#ifndef __CRYPTOAPI_SOFTWAREMD5IMPL_H__ +#define __CRYPTOAPI_SOFTWAREMD5IMPL_H__ + +#include "softwarehashbase.h" + +namespace SoftwareCrypto + { + using namespace CryptoSpi; + + const TInt KMD5BlockSize = 16; + const TInt KMD5HashSize = 16; + + NONSHARABLE_CLASS(CMD5Impl) : public CBase, public MSoftwareHash + { + public: + //NewL & NewLC + static CMD5Impl* NewL(); + static CMD5Impl* NewLC(); + + //From MPlugin + void Reset(); + void Close(); + void GetCharacteristicsL(const TCharacteristics*& aPluginCharacteristics); + static CExtendedCharacteristics* CreateExtendedCharacteristicsL(); + const CExtendedCharacteristics* GetExtendedCharacteristicsL(); + TAny* GetExtension(TUid aExtensionId); + + //From MHash + TPtrC8 Hash(const TDesC8& aMessage); + void Update(const TDesC8& aMessage); + TPtrC8 Final(const TDesC8& aMessage); + MHash* ReplicateL(); + MHash* CopyL(); + void SetKeyL(const CKey& aKey); + void SetOperationModeL(TUid aOperationMode); + + //From MSoftwareHash + void RestoreState(); + void StoreState(); + + private: + //Constructors + CMD5Impl(); + CMD5Impl(const CMD5Impl& aCMD5Impl); + + //Destructor + ~CMD5Impl(); + + TUid ImplementationUid(); + + void DoUpdate(const TUint8* aData,TUint aLength); + void DoFinal(void); + void Block(); + + private: + TBuf8 iHash; + + TUint iA; + TUint iB; + TUint iC; + TUint iD; + TUint iNl; + TUint iNh; + TUint iData[KMD5BlockSize]; + + TUint iACopy; + TUint iBCopy; + TUint iCCopy; + TUint iDCopy; + TUint iNlCopy; + TUint iNhCopy; + TUint iDataCopy[KMD5BlockSize]; + }; + } + +#endif // __CRYPTOAPI_SOFTWAREMD5IMPL_H__ + diff -r 7e3f204e6c81 -r f9c11be8c0b3 cryptoplugins/cryptospiplugins/source/softwarecrypto/pluginconfig.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/cryptoplugins/cryptospiplugins/source/softwarecrypto/pluginconfig.h Tue Dec 01 11:12:04 2009 +0000 @@ -0,0 +1,538 @@ +/* +* Copyright (c) 2006-2009 Nokia Corporation and/or its subsidiary(-ies). +* All rights reserved. +* This component and the accompanying materials are made available +* under the terms of the License "Eclipse Public License v1.0" +* which accompanies this distribution, and is available +* at the URL "http://www.eclipse.org/legal/epl-v10.html". +* +* Initial Contributors: +* Nokia Corporation - initial contribution. +* +* Contributors: +* +* Description: +* +*/ + + +/** + @file + @@internalComponent + @released +*/ + +#ifndef __CRYPTOAPI_SOFTWAREPLUGINCONFIG_H__ +#define __CRYPTOAPI_SOFTWAREPLUGINCONFIG_H__ + +#include +#include +#include +#include + +namespace SoftwareCrypto + { + using namespace CryptoSpi; + + /** + Creator Name + */ + _ROMLIT16(KSymbian, "Symbian"); + + /** + implementation Name + */ + _ROMLIT16(KMd2Description, "Md2"); + _ROMLIT16(KMd4Description, "Md4"); + _ROMLIT16(KMd5Description, "Md5"); + _ROMLIT16(KSha1Description, "Sha1"); + _ROMLIT16(KSha224Description, "Sha224"); + _ROMLIT16(KSha256Description, "Sha256"); + _ROMLIT16(KSha384Description, "Sha384"); + _ROMLIT16(KSha512Description, "Sha512"); + + _ROMLIT16(KRandomDescription, "Random"); + _ROMLIT16(KDesDescription, "Des"); + _ROMLIT16(K3DesDescription, "3Des"); + _ROMLIT16(KAesDescription, "Aes"); + _ROMLIT16(KRC2Description, "RC2"); + _ROMLIT16(KARC4Description, "ARC4"); + _ROMLIT16(KRsaCipherDescription, "Rsa"); + _ROMLIT16(KRsaSignerDescription, "RsaSigner"); + _ROMLIT16(KDsaSignerDescription, "DsaSigner"); + _ROMLIT16(KRsaVerifierDescription, "RsaVerifier"); + _ROMLIT16(KDsaVerifierDescription, "DsaVerifier"); + _ROMLIT16(KDHDescription, "DH"); + _ROMLIT16(KSymmetricKeyGeneratorDescription, "Symmetric Key Generator"); + _ROMLIT16(KRsaKeyPairDescription, "Rsa Key Pair Generator"); + _ROMLIT16(KDsaKeyPairDescription, "Dsa Key Pair Generator"); + _ROMLIT16(KDhKeyPairDescription, "DH Key Pair Generator"); + /** + For each crypto algorithm implemented in this plugin define + a plugin-wide unique id to identify it + a UID that contains the above id + a table of characteristics + */ + + + /** + Md2 Characteristics + */ + static const TInt32 KCryptoPluginMd2 = 0x102831D0; + static const TUid KCryptoPluginMd2Uid={KCryptoPluginMd2}; + static const TInt32 KMd2OperationModes[]={KHashMode, KHmacMode}; + static const THashCharacteristics KMd2_1 = {KHashInterface, KAlgorithmHashMd2, KCryptoPluginMd2, &KSymbian, EFalse, EFalse, 6, &KMd2Description, 100, 90, 128, 128, KMd2OperationModes, sizeof(KMd2OperationModes)/sizeof(KMd2OperationModes[0])}; + + /** + Md5 Characteristics + */ + static const TInt32 KCryptoPluginMd5 = 0x102831D1; + static const TUid KCryptoPluginMd5Uid={KCryptoPluginMd5}; + static const TInt32 KMd5OperationModes[]={KHashMode, KHmacMode}; + static const THashCharacteristics KMd5_1 = {KHashInterface, KAlgorithmHashMd5, KCryptoPluginMd5, &KSymbian, EFalse, EFalse, 6, &KMd5Description, 100, 90, 512, 128, KMd5OperationModes, sizeof(KMd5OperationModes)/sizeof(KMd5OperationModes[0])}; + + /** + Sha1 Characteristics + */ + static const TInt32 KCryptoPluginSha1 = 0x102831D2; + static const TUid KCryptoPluginSha1Uid={KCryptoPluginSha1}; + static const TInt32 KSha1OperationModes[]={KHashMode, KHmacMode}; + static const THashCharacteristics KSha1_1 = {KHashInterface, KAlgorithmHashSha1, KCryptoPluginSha1, &KSymbian, EFalse, EFalse, 6, &KSha1Description, 100, 90, 512, 160, KSha1OperationModes, sizeof(KSha1OperationModes)/sizeof(KSha1OperationModes[0])}; + + /** + Md4 Characteristics + */ + static const TInt32 KCryptoPluginMd4 = 0x2000B340; + static const TUid KCryptoPluginMd4Uid={KCryptoPluginMd4}; + static const TInt32 KMd4OperationModes[]={KHashMode, KHmacMode}; + static const THashCharacteristics KMd4_1 = {KHashInterface, KAlgorithmHashMd4, KCryptoPluginMd4, &KSymbian, EFalse, EFalse, 6, &KMd4Description, 100, 90, 512, 128, KMd4OperationModes, sizeof(KMd4OperationModes)/sizeof(KMd4OperationModes[0])}; + + /** + Sha224 Characteristics + */ + static const TInt32 KCryptoPluginSha224 = 0x2000E25C; + static const TUid KCryptoPluginSha224Uid={KCryptoPluginSha224}; + static const TInt32 KSha224OperationModes[]={KHashMode, KHmacMode}; + static const THashCharacteristics KSha224_1 = {KHashInterface, KAlgorithmHashSha224, KCryptoPluginSha224, &KSymbian, EFalse, EFalse, 6, &KSha224Description, 100, 90, 512, 224, KSha224OperationModes, sizeof(KSha224OperationModes)/sizeof(KSha224OperationModes[0])}; + + /** + Sha256 Characteristics + */ + static const TInt32 KCryptoPluginSha256 = 0x2000E25D; + static const TUid KCryptoPluginSha256Uid={KCryptoPluginSha256}; + static const TInt32 KSha256OperationModes[]={KHashMode, KHmacMode}; + static const THashCharacteristics KSha256_1 = {KHashInterface, KAlgorithmHashSha256, KCryptoPluginSha256, &KSymbian, EFalse, EFalse, 6, &KSha256Description, 100, 90, 512, 256, KSha256OperationModes, sizeof(KSha256OperationModes)/sizeof(KSha256OperationModes[0])}; + + /** + Sha384 Characteristics + */ + static const TInt32 KCryptoPluginSha384 = 0x2000E25E; + static const TUid KCryptoPluginSha384Uid={KCryptoPluginSha384}; + static const TInt32 KSha384OperationModes[]={KHashMode, KHmacMode}; + static const THashCharacteristics KSha384_1 = {KHashInterface, KAlgorithmHashSha384, KCryptoPluginSha384, &KSymbian, EFalse, EFalse, 6, &KSha384Description, 100, 90, 1024, 384, KSha384OperationModes, sizeof(KSha384OperationModes)/sizeof(KSha384OperationModes[0])}; + + /** + Sha512 Characteristics + */ + static const TInt32 KCryptoPluginSha512 = 0x2000E25F; + static const TUid KCryptoPluginSha512Uid={KCryptoPluginSha512}; + static const TInt32 KSha512OperationModes[]={KHashMode, KHmacMode}; + static const THashCharacteristics KSha512_1 = {KHashInterface, KAlgorithmHashSha512, KCryptoPluginSha512, &KSymbian, EFalse, EFalse, 6, &KSha512Description, 100, 90, 1024, 512, KSha512OperationModes, sizeof(KSha512OperationModes)/sizeof(KSha512OperationModes[0])}; + + + /** + Random Characteristics + */ + static const TInt32 KCryptoPluginRandom = 0x102831D3; + static const TUid KCryptoPluginRandomUid={KCryptoPluginRandom}; + static const TRandomCharacteristics KRandom_1 = {KRandomInterface, KAlgorithmRandom, KCryptoPluginRandom, &KSymbian, EFalse, EFalse, 6, &KRandomDescription, 100, 90, 3}; + + + + /** + DES Characteristics + */ + static const TInt32 KCryptoPluginDes = 0x102831D4; + static const TUid KCryptoPluginDesUid={KCryptoPluginDes}; + static const TInt32 KDesPaddingModes[]={KPaddingModeNone, KPaddingModeSSLv3, KPaddingModePKCS7}; + static const TInt32 KDesCryptoModes[]={KOperationModeNone, KOperationModeECB, KOperationModeCBC, KOperationModeCTR}; + + static const TSymmetricCipherCharacteristics KDes_1 = {KSymmetricCipherInterface, KAlgorithmCipherDes, KCryptoPluginDes, &KSymbian, EFalse, EFalse, 6, &KDesDescription, 100, 90, + 64 /* max key bits */, 64 /* block bits */, KDesPaddingModes, sizeof(KDesPaddingModes)/sizeof(KDesPaddingModes[0]), KDesCryptoModes, sizeof(KDesCryptoModes)/sizeof(KDesCryptoModes[0]), 3}; + + /** + 3DES-EDE Characteristics + */ + static const TInt32 KCryptoPlugin3Des = 0x102831D5; + static const TUid KCryptoPlugin3DesUid={KCryptoPlugin3Des}; + static const TInt32 K3DesPaddingModes[]={KPaddingModeNone, KPaddingModeSSLv3, KPaddingModePKCS7}; + static const TInt32 K3DesCryptoModes[]={KOperationModeNone, KOperationModeECB, KOperationModeCBC, KOperationModeCTR}; + + static const TSymmetricCipherCharacteristics K3Des_1 = {KSymmetricCipherInterface, KAlgorithmCipher3Des, KCryptoPlugin3Des, &KSymbian, EFalse, EFalse, 6, &K3DesDescription, 100, 90, + 192 /* max key bits */, 64 /* block bits */, K3DesPaddingModes, sizeof(K3DesPaddingModes)/sizeof(K3DesPaddingModes[0]), K3DesCryptoModes, sizeof(K3DesCryptoModes)/sizeof(K3DesCryptoModes[0]), 3}; + + /** + AES Characteristics + */ + static const TInt32 KCryptoPluginAes = 0x102831D6; + static const TUid KCryptoPluginAesUid={KCryptoPluginAes}; + static const TInt32 KAesPaddingModes[]={KPaddingModeNone, KPaddingModeSSLv3, KPaddingModePKCS7}; + static const TInt32 KAesCryptoModes[]={KOperationModeNone, KOperationModeECB, KOperationModeCBC, KOperationModeCTR}; + + static const TSymmetricCipherCharacteristics KAes_1 = {KSymmetricCipherInterface, KAlgorithmCipherAes, KCryptoPluginAes, &KSymbian, EFalse, EFalse, 6, &KAesDescription, 100, 90, + 256 /* max key bits */, 128 /* block bits */, KAesPaddingModes, sizeof(KAesPaddingModes)/sizeof(KAesPaddingModes[0]), KAesCryptoModes, sizeof(KAesCryptoModes)/sizeof(KAesCryptoModes[0]), 3}; + + + /** + RC2 Characteristics + */ + static const TInt32 KCryptoPluginRc2 = 0x102831D7; + static const TUid KCryptoPluginRc2Uid={KCryptoPluginRc2}; + static const TInt32 KRc2PaddingModes[]={KPaddingModeNone, KPaddingModeSSLv3, KPaddingModePKCS7}; + static const TInt32 KRc2CryptoModes[]={KOperationModeNone, KOperationModeECB, KOperationModeCBC, KOperationModeCTR}; + + static const TSymmetricCipherCharacteristics KRc2_1 = {KSymmetricCipherInterface, KAlgorithmCipherRc2, KCryptoPluginRc2, &KSymbian, EFalse, EFalse, 6, &KRC2Description, 100, 90, + 1024 /* max key bits */, 64 /* block bits */, KRc2PaddingModes, sizeof(KRc2PaddingModes)/sizeof(KRc2PaddingModes[0]), KRc2CryptoModes, sizeof(KRc2CryptoModes)/sizeof(KRc2CryptoModes[0]), 3}; + + + /** + ARC4 Characteristics + */ + static const TInt32 KCryptoPluginArc4 = 0x102831D8; + static const TUid KCryptoPluginArc4Uid={KCryptoPluginArc4}; + static const TInt32 KArc4PaddingModes[]={KPaddingModeNone}; + static const TInt32 KArc4CryptoModes[]={KOperationModeNone}; + + static const TSymmetricCipherCharacteristics KArc4_1 = {KSymmetricCipherInterface, KAlgorithmCipherArc4, KCryptoPluginArc4, &KSymbian, EFalse, EFalse, 6, &KARC4Description, 100, 90, + 2048 /* max key bits */, 8 /* block bits */, KArc4PaddingModes, sizeof(KArc4PaddingModes)/sizeof(KArc4PaddingModes[0]), KArc4CryptoModes, sizeof(KArc4CryptoModes)/sizeof(KArc4CryptoModes[0]), 3}; + + + /** + RSA Cipher Characteristics + */ + static const TInt32 KCryptoPluginRsaCipher = 0x102831D9; + static const TUid KCryptoPluginRsaCipherUid={KCryptoPluginRsaCipher}; + static const TInt32 KRSACipherPaddingModes[]={KPaddingModeNone, KPaddingModePkcs1_v1_5_Encryption}; + + static const TAsymmetricCipherCharacteristics KRSA_1 = {KAsymmetricCipherInterface, KAlgorithmCipherRsa, KCryptoPluginRsaCipher, &KSymbian, EFalse, EFalse, 6, &KRsaCipherDescription, 100, 90, + 256, KRSACipherPaddingModes, sizeof(KRSACipherPaddingModes)/sizeof(KRSACipherPaddingModes[0]), 3}; + + + /** + RSA Signer Characteristics + */ + static const TInt32 KCryptoPluginRsaSigner = 0x102831DA; + static const TUid KCryptoPluginRsaSignerUid={KCryptoPluginRsaSigner}; + static const TInt32 KRSASignerPaddingModes[]={KPaddingModeNone, KPaddingModePkcs1_v1_5_Signature}; + + static const TAsymmetricSignatureCharacteristics KRSASigner_1 = {KSignerInterface, KAlgorithmSignerRsa, KCryptoPluginRsaSigner, &KSymbian, EFalse, EFalse, 6, &KRsaSignerDescription, 100, 90, + 256, KRSASignerPaddingModes, sizeof(KRSASignerPaddingModes)/sizeof(KRSASignerPaddingModes[0]), 3}; + + /** + DSA Signer Characteristics + */ + static const TInt32 KCryptoPluginDsaSigner = 0x102831DB; + static const TUid KCryptoPluginDsaSignerUid={KCryptoPluginDsaSigner}; + static const TInt32 KDSASignerPaddingModes[]={KPaddingModeNone}; + + static const TAsymmetricSignatureCharacteristics KDSASigner_1 = {KSignerInterface, KAlgorithmSignerDsa, KCryptoPluginDsaSigner, &KSymbian, EFalse, EFalse, 6, &KDsaSignerDescription, 100, 90, + 256, KDSASignerPaddingModes, sizeof(KDSASignerPaddingModes)/sizeof(KDSASignerPaddingModes[0]), 3}; + + + /** + RSA verifier Characteristics + */ + static const TInt32 KCryptoPluginRsaVerifier = 0x102831DC; + static const TUid KCryptoPluginRsaVerifierUid={KCryptoPluginRsaVerifier}; + static const TInt32 KRSAVerifierPaddingModes[]={KPaddingModeNone, KPaddingModePkcs1_v1_5_Signature}; + + static const TAsymmetricSignatureCharacteristics KRSAVerifier_1 = {KVerifierInterface, KAlgorithmVerifierRsa, KCryptoPluginRsaVerifier, &KSymbian, EFalse, EFalse, 6, &KRsaVerifierDescription, 100, 90, + 256, KRSAVerifierPaddingModes, sizeof(KRSAVerifierPaddingModes)/sizeof(KRSAVerifierPaddingModes[0]), 3}; + + /** + DSA verifier Characteristics + */ + static const TInt32 KCryptoPluginDsaVerifier = 0x102831DD; + static const TUid KCryptoPluginDsaVerifierUid={KCryptoPluginDsaVerifier}; + static const TInt32 KDSAVerifierPaddingModes[]={KPaddingModeNone}; + + static const TAsymmetricSignatureCharacteristics KDSAVerifier_1 = {KVerifierInterface, KAlgorithmVerifierDsa, KCryptoPluginDsaVerifier, &KSymbian, EFalse, EFalse, 6, &KDsaVerifierDescription, 100, 90, + 256, KDSAVerifierPaddingModes, sizeof(KDSAVerifierPaddingModes)/sizeof(KDSAVerifierPaddingModes[0]), 3}; + + /** + DH Key Agreement Characteristics + */ + static const TInt32 KCryptoPluginDhKeyAgreement = 0x102831DE; // used to identify the CKeyAgreementImpl derived class within the plugin to use + static const TUid KCryptoPluginDhKeyAgreementUid={KCryptoPluginDhKeyAgreement}; // returned by the CKeyAgreementImpl derived class + static const TKeyAgreementCharacteristics KDH_1 = {KKeyAgreementInterface, KAlgorithmKeyAgreementDH, KCryptoPluginDhKeyAgreement, &KSymbian, EFalse, EFalse, 6, &KDHDescription, 100, 90}; + + /** + DH Key Pair Generator Characteristics + */ + static const TInt32 KCryptoPluginDhKeyPairGen = 0x102831DF; + static const TUid KCryptoPluginDhKeyPairGenUid={KCryptoPluginDhKeyPairGen}; + static const TAsymmetricKeypairGeneratorCharacteristics KDHKeyPairGenerator_1 = {KKeypairGeneratorInterface, KAlgorithmDHKeyPairGenerator, KCryptoPluginDhKeyPairGen, &KSymbian, EFalse, EFalse, 6, &KDhKeyPairDescription, 100, 90, 1024}; + + /** + RSA Key Pair Generator Characteristics + */ + static const TInt32 KCryptoPluginRsaKeyPairGen = 0x102831E0; + static const TUid KCryptoPluginRsaKeyPairGenUid={KCryptoPluginRsaKeyPairGen}; + static const TAsymmetricKeypairGeneratorCharacteristics KRSAKeyPairGenerator_1 = {KKeypairGeneratorInterface, KAlgorithmRSAKeyPairGenerator, KCryptoPluginRsaKeyPairGen, &KSymbian, EFalse, EFalse, 6, &KRsaKeyPairDescription, 100, 90, 1024}; + + /** + DSA Key Pair Generator Characteristics + */ + static const TInt32 KCryptoPluginDsaKeyPairGen = 0x102831E1; + static const TUid KCryptoPluginDsaKeyPairGenUid={KCryptoPluginDsaKeyPairGen}; + static const TAsymmetricKeypairGeneratorCharacteristics KDSAKeyPairGenerator_1 = {KKeypairGeneratorInterface, KAlgorithmDSAKeyPairGenerator, KCryptoPluginDsaKeyPairGen, &KSymbian, EFalse, EFalse, 6, &KDsaKeyPairDescription, 100, 90, 1024}; + + +/******************************MAC INTERFACE PLUG-INS' CHARACTERISTICS***************************/ +#ifdef SYMBIAN_SDP_IPSEC_VOIP_SUPPORT + _ROMLIT16(KHmacMd2Description, "HmacMd2"); + _ROMLIT16(KHmacMd4Description, "HmacMd4"); + _ROMLIT16(KHmacMd5Description, "HmacMd5"); + _ROMLIT16(KHmacSha1Description, "HmacSha1"); + _ROMLIT16(KHmacSha224Description, "HmacSha224"); + _ROMLIT16(KHmacSha256Description, "HmacSha256"); + _ROMLIT16(KHmacSha384Description, "HmacSha384"); + _ROMLIT16(KHmacSha512Description, "HmacSha512"); + _ROMLIT16(KMacAesXcbcMac96Description, "AesXcbcMac96"); + _ROMLIT16(KMacAesXcbcPrf128Description, "AesXcbcPrf128"); + /** + * AES-XCBC-MAC-96 MAC Plugin Characteristics + */ + static const TInt32 KCryptoPluginMacAesXcbcMac96 = 0x2001EDA8; + static const TUid KCryptoPluginMacAesXcbcMac96Uid= {KCryptoPluginMacAesXcbcMac96}; + static const TMacCharacteristics KMac_1 = { + KMacInterface, + KAlgorithmCipherAesXcbcMac96, + KCryptoPluginMacAesXcbcMac96, + &KSymbian, + EFalse, EFalse, 6, + &KMacAesXcbcMac96Description, + 100, 90, KSymmetricCipherMode, + NULL,&KAes_1 + }; + /** + * AES-XCBC-PRF-128 MAC Plugin Characteristics + */ + static const TInt32 KCryptoPluginMacAesXcbcPrf128 = 0x2001EDA9; + static const TUid KCryptoPluginMacAesXcbcPrf128Uid = {KCryptoPluginMacAesXcbcPrf128}; + static const TMacCharacteristics KMac_2 = { + KMacInterface, + KAlgorithmCipherAesXcbcPrf128, + KCryptoPluginMacAesXcbcPrf128, + &KSymbian, + EFalse, EFalse, 6, + &KMacAesXcbcPrf128Description, + 100, 90, KSymmetricCipherMode, + NULL,&KAes_1 + }; + /** + * HASH-MD2 MAC Plugin Characteristics + */ + static const TInt32 KCryptoPluginMacHashMd2 = 0x2001EDA0; + static const TUid KCryptoPluginMacHashMd2Uid = {KCryptoPluginMacHashMd2}; + static const TMacCharacteristics KMac_3 = { + KMacInterface, + KAlgorithmHashMd2, + KCryptoPluginMacHashMd2, + &KSymbian, + EFalse, EFalse, 6, + &KHmacMd2Description, + 100, 90, KHmacMode, + &KMd2_1, NULL + }; + /** + * HASH-MD4 MAC Plugin Characteristics + */ + static const TInt32 KCryptoPluginMacHashMd4 = 0x2001EDA1; + static const TUid KCryptoPluginMacHashMd4Uid = {KCryptoPluginMacHashMd4}; + static const TMacCharacteristics KMac_4 = { + KMacInterface, + KAlgorithmHashMd4, + KCryptoPluginMacHashMd4, + &KSymbian, + EFalse, EFalse, 6, + &KHmacMd4Description, + 100, 90, KHmacMode, + &KMd4_1, NULL + }; + /** + * HASH-MD5 MAC Plugin Characteristics + */ + static const TInt32 KCryptoPluginMacHashMd5 = 0x2001EDA2; + static const TUid KCryptoPluginMacHashMd5Uid = {KCryptoPluginMacHashMd5}; + static const TMacCharacteristics KMac_5 = { + KMacInterface, + KAlgorithmHashMd5, + KCryptoPluginMacHashMd5, + &KSymbian, + EFalse, EFalse, 6, + &KHmacMd5Description, + 100, 90, KHmacMode, + &KMd5_1, NULL + }; + /** + * HASH-SHA1 MAC Plugin Characteristics + */ + static const TInt32 KCryptoPluginMacHashSha1 = 0x2001EDA3; + static const TUid KCryptoPluginMacHashSha1Uid = {KCryptoPluginMacHashSha1}; + static const TMacCharacteristics KMac_6 = { + KMacInterface, + KAlgorithmHashSha1, + KCryptoPluginMacHashSha1, + &KSymbian, + EFalse, EFalse, 6, + &KHmacSha1Description, + 100, 90, KHmacMode, + &KSha1_1, NULL + }; + /** + * HASH-SHA224 MAC Plugin Characteristics + */ + static const TInt32 KCryptoPluginMacHashSha224 = 0x2001EDA4; + static const TUid KCryptoPluginMacHashSha224Uid = {KCryptoPluginMacHashSha224}; + static const TMacCharacteristics KMac_7 = { + KMacInterface, + KAlgorithmHashSha224, + KCryptoPluginMacHashSha224, + &KSymbian, + EFalse, EFalse, 6, + &KHmacSha224Description, + 100, 90, KHmacMode, + &KSha224_1, NULL + }; + /** + * HASH-SHA256 MAC Plugin Characteristics + */ + static const TInt32 KCryptoPluginMacHashSha256 = 0x2001EDA5; + static const TUid KCryptoPluginMacHashSha256Uid = {KCryptoPluginMacHashSha256}; + static const TMacCharacteristics KMac_8 = { + KMacInterface, + KAlgorithmHashSha256, + KCryptoPluginMacHashSha256, + &KSymbian, + EFalse, EFalse, 6, + &KHmacSha256Description, + 100, 90, KHmacMode, + &KSha256_1, NULL + }; + /** + * HASH-SHA384 MAC Plugin Characteristics + */ + static const TInt32 KCryptoPluginMacHashSha384 = 0x2001EDA6; + static const TUid KCryptoPluginMacHashSha384Uid = {KCryptoPluginMacHashSha384}; + static const TMacCharacteristics KMac_9 = { + KMacInterface, + KAlgorithmHashSha384, + KCryptoPluginMacHashSha384, + &KSymbian, + EFalse, EFalse, 6, + &KHmacSha384Description, + 100, 90, KHmacMode, + &KSha384_1, NULL + }; + /** + * HASH-SHA512 MAC Plugin Characteristics + */ + static const TInt32 KCryptoPluginMacHashSha512 = 0x2001EDA7; + static const TUid KCryptoPluginMacHashSha512Uid = {KCryptoPluginMacHashSha512}; + static const TMacCharacteristics KMac_10 = { + KMacInterface, + KAlgorithmHashSha512, + KCryptoPluginMacHashSha512, + &KSymbian, + EFalse, EFalse, 6, + &KHmacSha512Description, + 100, 90, KHmacMode, + &KSha512_1, NULL + }; + /** + * Mac implementation characteristic table + */ + static const TMacCharacteristics* const KMacCharacteristics[] = { + &KMac_1, &KMac_2, &KMac_3, + &KMac_4, &KMac_5, &KMac_6, + &KMac_7, &KMac_8, &KMac_9, + &KMac_10 + }; + +#endif +/***********************************************************************************************/ + + /** + For each crypto algorithm type implemented in this plugin list the characteristics + */ + + /** + Hash implementation characteristic table + */ + static const THashCharacteristics* const KHashCharacteristics[] = + { + &KMd2_1, &KMd5_1, &KSha1_1, &KMd4_1, &KSha224_1, &KSha256_1, &KSha384_1, &KSha512_1 + }; + + /** + Random implementation characteristic table + */ + + static const TRandomCharacteristics* const KRandomCharacteristics[]= + { + &KRandom_1 + }; + + /** + Symmetric Cipher implementation characteristic table + */ + static const TSymmetricCipherCharacteristics* const KSymmetricCipherCharacteristics[]= + { + &KDes_1, &K3Des_1, &KAes_1, &KRc2_1, &KArc4_1 + }; + + + /** + Asymmetric Cipher implementation characteristic table + */ + static const TAsymmetricCipherCharacteristics* const KAsymmetricCipherCharacteristics[]= + { + &KRSA_1 + }; + + /** + Signer implementation characteristic table + */ + static const TAsymmetricSignatureCharacteristics* const KSignerCharacteristics[]= + { + &KRSASigner_1, &KDSASigner_1 + }; + + + /** + Verifier implementation characteristic table + */ + static const TAsymmetricSignatureCharacteristics* const KVerifierCharacteristics[]= + { + &KRSAVerifier_1, &KDSAVerifier_1 + }; + + /** + Key Agreement implementation characteristic table + */ + static const TKeyAgreementCharacteristics* const KKeyAgreementCharacteristics[]= + { + &KDH_1 + }; + + /** + Key pair generator implementation characteristic table + */ + static const TAsymmetricKeypairGeneratorCharacteristics* const KKeyPairGeneratorCharacteristics[]= + { + &KDHKeyPairGenerator_1, &KRSAKeyPairGenerator_1, &KDSAKeyPairGenerator_1 + }; + } + +#endif //__CRYPTOAPI_SOFTWAREPLUGINCONFIG_H__ diff -r 7e3f204e6c81 -r f9c11be8c0b3 cryptoplugins/cryptospiplugins/source/softwarecrypto/pluginentry.cpp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/cryptoplugins/cryptospiplugins/source/softwarecrypto/pluginentry.cpp Tue Dec 01 11:12:04 2009 +0000 @@ -0,0 +1,448 @@ +/* +* Copyright (c) 2006-2009 Nokia Corporation and/or its subsidiary(-ies). +* All rights reserved. +* This component and the accompanying materials are made available +* under the terms of the License "Eclipse Public License v1.0" +* which accompanies this distribution, and is available +* at the URL "http://www.eclipse.org/legal/epl-v10.html". +* +* Initial Contributors: +* Nokia Corporation - initial contribution. +* +* Contributors: +* +* Description: +* plugin entry implementation +* plugin entry implementation +* +*/ + + +/** + @file +*/ + +#include "pluginentry.h" +#include "keypair.h" +#include "pluginconfig.h" +#include "md2impl.h" +#include "md5impl.h" +#include "md4impl.h" +#include "sha1impl.h" +#include "hmacimpl.h" +#include "keys.h" +#include "3desimpl.h" +#include "desimpl.h" +#include "rc2impl.h" +#include "arc4impl.h" +#include "randomimpl.h" +#include "rijndaelimpl.h" +#include "randomimpl.h" +#include "rsaimpl.h" +#include "dhimpl.h" +#include "dhkeypairgenimpl.h" +#include "rsakeypairgenimpl.h" +#include "dsakeypairgenimpl.h" +#include "dsasignerimpl.h" +#include "dsaverifyimpl.h" +#include "rsasignerimpl.h" +#include "rsaverifyimpl.h" +#include + +#ifdef SYMBIAN_SDP_IPSEC_VOIP_SUPPORT + #include "macimpl.h" +#endif + + +using namespace SoftwareCrypto; + +EXPORT_C const TCharacteristics** CCryptoPluginEntry::Enumerate(TUid aInterface, TInt& aNumPlugins) + { + const TCharacteristics** ptr(0); + switch (aInterface.iUid) + { + case KHashInterface: + { + aNumPlugins=sizeof(KHashCharacteristics)/sizeof(THashCharacteristics*); + ptr = (const TCharacteristics**) &KHashCharacteristics[0]; + } + break; + +#ifdef SYMBIAN_SDP_IPSEC_VOIP_SUPPORT + + case KMacInterface: + { + aNumPlugins=sizeof(KMacCharacteristics)/sizeof(TMacCharacteristics*); + ptr = (const TCharacteristics**) &KMacCharacteristics[0]; + } + break; + +#endif + + case KRandomInterface: + { + aNumPlugins=sizeof(KRandomCharacteristics)/sizeof(TRandomCharacteristics*); + ptr= (const TCharacteristics**) &KRandomCharacteristics[0]; + } + break; + + case KSymmetricCipherInterface: + { + aNumPlugins=sizeof(KSymmetricCipherCharacteristics)/sizeof(TSymmetricCipherCharacteristics*); + ptr = (const TCharacteristics**) &KSymmetricCipherCharacteristics[0]; + } + break; + + case KAsymmetricCipherInterface: + { + aNumPlugins=sizeof(KAsymmetricCipherCharacteristics)/sizeof(TAsymmetricCipherCharacteristics*); + ptr = (const TCharacteristics**) &KAsymmetricCipherCharacteristics[0]; + } + break; + + case KSignerInterface: + { + aNumPlugins=sizeof(KSignerCharacteristics)/sizeof(TAsymmetricSignatureCharacteristics*); + ptr = (const TCharacteristics**) &KSignerCharacteristics[0]; + } + break; + + case KVerifierInterface: + { + aNumPlugins=sizeof(KVerifierCharacteristics)/sizeof(TAsymmetricSignatureCharacteristics*); + ptr = (const TCharacteristics**) &KVerifierCharacteristics[0]; + } + break; + + case KKeyAgreementInterface: + { + aNumPlugins=sizeof(KKeyAgreementCharacteristics)/sizeof(TKeyAgreementCharacteristics*); + ptr = (const TCharacteristics**) &KKeyAgreementCharacteristics[0]; + } + break; + + case KKeypairGeneratorInterface: + { + aNumPlugins=sizeof(KKeyPairGeneratorCharacteristics)/sizeof(TAsymmetricKeypairGeneratorCharacteristics*); + ptr = (const TCharacteristics**) &KKeyPairGeneratorCharacteristics[0]; + } + break; + + case KKeyGeneratorInterface: + break; + + default:; + } + + return ptr; + } + +EXPORT_C void CCryptoPluginEntry::GetExtendedCharacteristicsL(TUid aImplementationUid, CExtendedCharacteristics*& aExt) + { + switch (aImplementationUid.iUid) + { + +#ifdef SYMBIAN_SDP_IPSEC_VOIP_SUPPORT + case KCryptoPluginMacHashMd2: +#endif + + case KCryptoPluginMd2: + aExt = CMD2Impl::CreateExtendedCharacteristicsL(); + break; + +#ifdef SYMBIAN_SDP_IPSEC_VOIP_SUPPORT + case KCryptoPluginMacHashMd5: +#endif + + case KCryptoPluginMd5: + aExt = CMD5Impl::CreateExtendedCharacteristicsL(); + break; + +#ifdef SYMBIAN_SDP_IPSEC_VOIP_SUPPORT + case KCryptoPluginMacHashSha1: +#endif + + case KCryptoPluginSha1: + aExt = CSHA1Impl::CreateExtendedCharacteristicsL(); + break; + +#ifdef SYMBIAN_SDP_IPSEC_VOIP_SUPPORT + case KCryptoPluginMacHashMd4: +#endif + + case KCryptoPluginMd4: + aExt = CMD4Impl::CreateExtendedCharacteristicsL(); + break; + case KCryptoPluginRandom: + aExt = CRandomImpl::CreateExtendedCharacteristicsL(); + break; + case KCryptoPluginDes: + aExt = CDesImpl::CreateExtendedCharacteristicsL(); + break; + case KCryptoPlugin3Des: + aExt = C3DesImpl::CreateExtendedCharacteristicsL(); + break; + case KCryptoPluginRc2: + aExt = CRc2Impl::CreateExtendedCharacteristicsL(); + break; + case KCryptoPluginArc4: + aExt = CArc4Impl::CreateExtendedCharacteristicsL(); + break; + +#ifdef SYMBIAN_SDP_IPSEC_VOIP_SUPPORT + case KCryptoPluginMacAesXcbcMac96: + case KCryptoPluginMacAesXcbcPrf128: +#endif + + case KCryptoPluginAes: + aExt = CRijndaelImpl::CreateExtendedCharacteristicsL(); + break; + case KCryptoPluginRsaCipher: + aExt = CRSAImpl::CreateExtendedCharacteristicsL(); + break; + case KCryptoPluginRsaSigner: + aExt = CRSASignerImpl::CreateExtendedCharacteristicsL(); + break; + case KCryptoPluginDsaSigner: + aExt = CDSASignerImpl::CreateExtendedCharacteristicsL(); + break; + case KCryptoPluginRsaVerifier: + aExt = CRSAVerifierImpl::CreateExtendedCharacteristicsL(); + break; + case KCryptoPluginDsaVerifier: + aExt = CDSAVerifierImpl::CreateExtendedCharacteristicsL(); + break; + case KCryptoPluginDhKeyAgreement: + aExt = CDHImpl::CreateExtendedCharacteristicsL(); + break; + case KCryptoPluginDhKeyPairGen: + aExt = CDHKeyPairGenImpl::CreateExtendedCharacteristicsL(); + break; + case KCryptoPluginRsaKeyPairGen: + aExt = CRSAKeyPairGenImpl::CreateExtendedCharacteristicsL(); + break; + case KCryptoPluginDsaKeyPairGen: + aExt = CDSAKeyPairGenImpl::CreateExtendedCharacteristicsL(); + break; + default: + User::Leave(KErrNotSupported); + } + } + +EXPORT_C void CCryptoPluginEntry::CreateAsymmetricCipherL(MAsymmetricCipher*& aPlugin, + TUid aImplementationId, + const CKey& aKey, + TUid aCryptoMode, + TUid aPaddingMode, + const CCryptoParams* /*aAlgorithmParams*/) + { + switch (aImplementationId.iUid) + { + case KCryptoPluginRsaCipher: + { + aPlugin = CRSAImpl::NewL(aKey, aCryptoMode, aPaddingMode); + } + break; + + default: + User::Leave(KErrNotFound); + } + } + +EXPORT_C void CCryptoPluginEntry::CreateAsymmetricSignerL(MSigner*& aPlugin, + TUid aImplementationId, + const CKey& aKey, + TUid aPaddingMode, + const CCryptoParams* /*aAlgorithmParams*/) + { + switch (aImplementationId.iUid) + { + case KCryptoPluginRsaSigner: + { + aPlugin = CRSASignerImpl::NewL(aKey, aPaddingMode); + } + break; + + case KCryptoPluginDsaSigner: + { + aPlugin = CDSASignerImpl::NewL(aKey); + } + break; + + default: + User::Leave(KErrNotFound); + } + } + +EXPORT_C void CCryptoPluginEntry::CreateAsymmetricVerifierL(MVerifier*& aPlugin, + TUid aImplementationId, + const CKey& aKey, + TUid aPaddingMode, + const CCryptoParams* /*aAlgorithmParams*/) + { + switch (aImplementationId.iUid) + { + case KCryptoPluginRsaVerifier: + aPlugin = CRSAVerifierImpl::NewL(aKey, aPaddingMode); + break; + + case KCryptoPluginDsaVerifier: + { + aPlugin = CDSAVerifierImpl::NewL(aKey); + } + break; + + default: + User::Leave(KErrNotFound); + } + } + +EXPORT_C void CCryptoPluginEntry::CreateHashL(MHash*& aPlugin, + TUid aImplementationId, + TUid aOperationMode, + const CKey* aKey, + const CCryptoParams* /*aAlgorithmParams*/) + { + aPlugin=CSoftwareHash::NewL(aImplementationId, aOperationMode, aKey); + } + +#ifdef SYMBIAN_SDP_IPSEC_VOIP_SUPPORT + +EXPORT_C void CCryptoPluginEntry::CreateHashL(MHash*& aPlugin, + TUid aImplementationId, + const CCryptoParams* /*aAlgorithmParams*/) + { + aPlugin=CSoftwareHash::NewL(aImplementationId); + } + +EXPORT_C void CCryptoPluginEntry::CreateMacL(MMac*& aPlugin, + const TUid aImplementationId, + const CKey& aKey, + const CCryptoParams* aAlgorithmParams) + { + aPlugin=CMacImpl::NewL(aKey, aImplementationId, aAlgorithmParams); + } + +#endif + +EXPORT_C void CCryptoPluginEntry::CreateKeyAgreementL(MKeyAgreement*& aPlugin, + TUid aImplementationId, + const CKey& aPrivateKey, + const CCryptoParams* aAlgorithmParams) + { + // create requested key agreement implementation in this plugin + switch (aImplementationId.iUid) + { + case KCryptoPluginDhKeyAgreement: + { + aPlugin = CDHImpl::NewL(aPrivateKey, aAlgorithmParams); + } + break; + + default: + User::Leave(KErrNotFound); + } + } + +EXPORT_C void CCryptoPluginEntry::CreateKeyPairGeneratorL(MKeyPairGenerator*& aPlugin, + TUid aImplementationId, + const CCryptoParams* /*aAlgorithmParams*/) + { + // create requested key pair generator implementation in this plugin + switch (aImplementationId.iUid) + { + case KCryptoPluginDhKeyPairGen: + { + aPlugin = CDHKeyPairGenImpl::NewL(); + } + break; + + case KCryptoPluginRsaKeyPairGen: + { + aPlugin = CRSAKeyPairGenImpl::NewL(); + } + break; + + case KCryptoPluginDsaKeyPairGen: + { + aPlugin = CDSAKeyPairGenImpl::NewL(); + } + break; + + default: + User::Leave(KErrNotFound); + } + } + +EXPORT_C void CCryptoPluginEntry::CreateRandomL(MRandom*& aPlugin, + TUid /*aImplementationId*/, + const CCryptoParams* /*aAlgorithmParams*/) + { + aPlugin=CRandomImpl::NewL(); + } + +EXPORT_C void CCryptoPluginEntry::CreateSymmetricCipherL(MSymmetricCipher*& aPlugin, + TUid aImplementationId, + const CKey& aKey, + TUid aCryptoMode, + TUid aOperationMode, + TUid aPadding, + const CCryptoParams* aAlgorithmParams) + { + switch (aImplementationId.iUid) + { + case KCryptoPluginAes: + { + aPlugin=CRijndaelImpl::NewL( + aKey, aCryptoMode, aOperationMode, aPadding); + } + break; + case KCryptoPluginDes: + { + aPlugin=CDesImpl::NewL( + aKey, aCryptoMode, aOperationMode, aPadding); + } + break; + case KCryptoPlugin3Des: + { + aPlugin=C3DesImpl::NewL( + aKey, aCryptoMode, aOperationMode, aPadding); + } + break; + case KCryptoPluginRc2: + { + TInt effectiveKeyLenBits(CRc2Impl::KDefaultEffectiveKeyLenBits); + + if (aAlgorithmParams && aAlgorithmParams->IsPresent(KRC2EffectiveKeyLenBits)) + { + effectiveKeyLenBits = aAlgorithmParams->GetTIntL(KRC2EffectiveKeyLenBits); + if (effectiveKeyLenBits < 0) + { + User::Leave(KErrArgument); + } + } + aPlugin=CRc2Impl::NewL( + aKey, aCryptoMode, aOperationMode, aPadding, effectiveKeyLenBits); + } + break; + + case KCryptoPluginArc4: + { + TInt discardBytes(CArc4Impl::KDefaultDiscardBytes); + if (aAlgorithmParams && aAlgorithmParams->IsPresent(KARC4DiscardBytes)) + { + discardBytes = aAlgorithmParams->GetTIntL(KARC4DiscardBytes); + if (discardBytes < 0) + { + User::Leave(KErrArgument); + } + } + aPlugin=CArc4Impl::NewL(aKey, discardBytes); + } + break; + + default: + User::Leave(KErrNotFound); + } + } + diff -r 7e3f204e6c81 -r f9c11be8c0b3 cryptoplugins/cryptospiplugins/source/softwarecrypto/pluginentry.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/cryptoplugins/cryptospiplugins/source/softwarecrypto/pluginentry.h Tue Dec 01 11:12:04 2009 +0000 @@ -0,0 +1,414 @@ +/* +* Copyright (c) 2006-2009 Nokia Corporation and/or its subsidiary(-ies). +* All rights reserved. +* This component and the accompanying materials are made available +* under the terms of the License "Eclipse Public License v1.0" +* which accompanies this distribution, and is available +* at the URL "http://www.eclipse.org/legal/epl-v10.html". +* +* Initial Contributors: +* Nokia Corporation - initial contribution. +* +* Contributors: +* +* Description: +* +*/ + + +/** + @file + @internalComponent + @released +*/ + +#ifndef __PLUGINENTRY_H__ +#define __PLUGINENTRY_H__ + +#include +#include +#include +#include "keys.h" +#include +#include +#include "symmetriccipherplugin.h" +#include "asymmetriccipherplugin.h" +#include "signerplugin.h" +#include "verifierplugin.h" +#include "keypairgeneratorplugin.h" +#include "keyagreementplugin.h" + + +#ifdef SYMBIAN_SDP_IPSEC_VOIP_SUPPORT + #include +#endif + +using namespace CryptoSpi; + +class CCryptoPluginEntry + { +public: + + /** + * Enumerates the set of plug-ins supported by the module for a given interface + * e.g. all of the hash plug-ins. + * + * @param aInterface The UID of the plug-in interface type. If the UID is not recognised + * then the NULL pointer must be returned. + * @param aNumPlugins The number of plug-in characteristics objects in the result. + * @param A pointer to an array of characteristics objects. The SPI casts this to + * the expected sub-class of TCharacteristics for the specified interface UID. + */ + IMPORT_C static const TCharacteristics** Enumerate(TUid aInterface, TInt& aNumPlugins); + + /** + * Retrieves the extended characteristics about a given implementation of an + * algorithm within the current plug-in DLL. + * + * @param aImplementationUid The UID of the implementation requested + * @return A pointer to the extended characteristics, allocated on the heap, + * which should be deleted once the caller has finished with it. + */ + IMPORT_C static void GetExtendedCharacteristicsL(TUid aImplementationUid, CExtendedCharacteristics*&); + + /** + * Creates a new instance of an asymmetric cipher + * + * @param aPlugin A reference to a pointer that should be set to point to + * the new asymmetric cipher object. + * @param aImplementationId The UID of the asymmetric cipher plug-in to instantiate. + * @param aKey The encryption/decryption key. + * @param aAlgorithmParams The parameters that are specific to a particular + * algorithm. This is for extendibility and will normally be null. + * @return KErrNone if successful; otherwise, a system wide error code. + */ + IMPORT_C static void CreateAsymmetricCipherL(MAsymmetricCipher*& aPlugin, + TUid aImplementationId, + const CKey& aKey, + TUid aCryptoMode, + TUid aPaddingMode, + const CCryptoParams* aAlgorithmParams); + + /** + * Creates a new instance of an asymmetric signer. + * + * @param aPlugin A reference to a pointer that should be set to point to + * the new asymmetric signer object. + * @param aImplementationId The UID of the signer plug-in to instantiate. + * @param aKey The signing key. + * @param aAlgorithmParams The parameters that are specific to a particular + * algorithm. This is for extendibility and will normally be null. + * @return KErrNone if successful; otherwise, a system wide error code. + */ + IMPORT_C static void CreateAsymmetricSignerL(MSigner*& aPlugin, + TUid aImplementationId, + const CKey& aKey, + TUid aPaddingMode, + const CCryptoParams* aAlgorithmParams); + + /** + * Creates a new instance of an asymmetric verifier. + * + * @param aPlugin A reference to a pointer that should be set to point to + * the new asymmetric verifier object. + * @param aImplementationId The UID of the verifier plug-in to instantiate. + * @param aKey The key to verify the signature with. + * @param aAlgorithmParams The parameters that are specific to a particular + * algorithm. This is for extendibility and will normally be null. + * @return KErrNone if successful; otherwise, a system wide error code. + */ + IMPORT_C static void CreateAsymmetricVerifierL(MVerifier*& aPlugin, + TUid aImplementationId, + const CKey& aKey, + TUid aPaddingMode, + const CCryptoParams* aAlgorithmParams); + + /** + * @deprecated + * + * Creates a new instance of a Hash object. + * + * @param aPlugin A reference to a pointer that should be set to point to + * the new hash object. + * @param aImplementationId The UID of the hash plug-in to instantiate. + * @param aAlgorithmParams The parameters that are specific to a particular + * algorithm. This is for extendibility and will normally be null. + * @return KErrNone if successful; otherwise, a system wide error code. + */ + IMPORT_C static void CreateHashL(MHash*& aPlugin, + TUid aImplementationId, + TUid aOperationMode, + const CKey* aKey, + const CCryptoParams* aAlgorithmParams); + + /** + * Creates a new instance of a key agreement system. + * + * @param aPlugin A reference to a pointer that should be set to point to + * the new asymmetric key pair generator object. + * @param aImplementationId The UID of the key agreement plug-in to instantiate. + * @param aPrivateKey The private key to combine with the other parties public key + * during the agreement. + * @param aAlgorithmParams The parameters that are specific to a particular + * algorithm. This is for extendibility and will normally be null. + * @return KErrNone if successful; otherwise, a system wide error code. + */ + IMPORT_C static void CreateKeyAgreementL(MKeyAgreement*& aPlugin, + TUid aImplementationId, + const CKey& aPrivateKey, + const CCryptoParams* aAlgorithmParams); + + /** + * Creates a new instance of an asymmetric key pair generator. + * + * @param aPlugin A reference to a pointer that should be set to point to + * the new asymmetric key pair generator object. + * @param aImplementationId The UID of the verifier plug-in to instantiate. + * @param aAlgorithmParams The parameters that are specific to a particular + * algorithm. This is for extendibility and will normally be null. + * @return KErrNone if successful; otherwise, a system wide error code. + */ + IMPORT_C static void CreateKeyPairGeneratorL(MKeyPairGenerator*& aPlugin, + TUid aImplementationId, + const CCryptoParams* aAlgorithmParams); + + /** + * Creates a new instance of a Random object. + * + * @param aPlugin A reference to a pointer that should be set to point to the new random object. + * @param aImplementationId The UID of the random plug-in to instantiate. + * @param aAlgorithmParams The parameters that are specific to a particular + * algorithm. This is for extendibility and will normally be null. + * @return KErrNone if successful; otherwise, a system wide error code. + */ + IMPORT_C static void CreateRandomL(MRandom*& aPlugin, + TUid aImplementationId, + const CCryptoParams* aAlgorithmParams); + + /** + * Creates a new instance of a symmetric cipher + * + * @param aPlugin A reference to a pointer that should be set to point to + * the new asymmetric object. + * @param aImplementationId The UID of the symmetric cipher plug-in to instantiate. + * @param aKey The encryption/decryption key. + * @param aCryptoMode Encrypt or Decrypt. + * @param aOperationMode the block cipher mode to use ECB, CBC, CTR etc + * @param aPadding the padding scheme to use. + * @param aAlgorithmParams The parameters that are specific to a particular + * algorithm. This is for extendibility and will normally be null. + * @return KErrNone if successful; otherwise, a system wide error code. + */ + IMPORT_C static void CreateSymmetricCipherL(MSymmetricCipher*& aPlugin, + TUid aImplementationId, + const CKey& aKey, + TUid aCryptoMode, + TUid aOperationMode, + TUid aPadding, + const CCryptoParams* aAlgorithmParams); + + /** + * Creates a new instance of an asymmetric cipher + * + * @param aPlugin A reference to a pointer that should be set to point to + * the new asymmetric cipher object. + * @param aImplementationId The UID of the asymmetric cipher plug-in to instantiate. + * @param aKey The encryption/decryption key. + * @param aAlgorithmParams The parameters that are specific to a particular + * algorithm. This is for extendibility and will normally be null. + * @return KErrNone if successful; otherwise, a system wide error code. + + IMPORT_C static void CreateAsyncAsymmetricCipherL(MAsyncAsymmetricCipher*& aPlugin, + TUid aImplementationId, + const CKey& aKey, + const CCryptoParams* aAlgorithmParams); + */ + + /** + * Creates a new instance of an asymmetric signer. + * + * @param aPlugin A reference to a pointer that should be set to point to + * the new asymmetric signer object. + * @param aImplementationId The UID of the signer plug-in to instantiate. + * @param aKey The signing key. + * @param aAlgorithmParams The parameters that are specific to a particular + * algorithm. This is for extendibility and will normally be null. + * @return KErrNone if successful; otherwise, a system wide error code. + + IMPORT_C static void CreateAsyncAsymmetricSignerL(MAsyncSigner*& aPlugin, + TUid aImplementationId, + const CKey& aKey, + const CCryptoParams* aAlgorithmParams); + */ + + /** + * Creates a new instance of an asymmetric verifier. + * + * @param aPlugin A reference to a pointer that should be set to point to + * the new asymmetric verifier object. + * @param aImplementationId The UID of the verifier plug-in to instantiate. + * @param aKey The key to verify the signature with. + * @param aAlgorithmParams The parameters that are specific to a particular + * algorithm. This is for extendibility and will normally be null. + * @return KErrNone if successful; otherwise, a system wide error code. + + IMPORT_C static void CreateAsyncAsymmetricVerifierL(MAsyncVerifier*& aPlugin, + TUid aImplementationId, + const CKey& aKey, + const CCryptoParams* aAlgorithmParams); + */ + + /** + * @deprecated + * + * Creates a new instance of a Hash object. + * + * @param aPlugin A reference to a pointer that should be set to point to + * the new hash object. + * @param aImplementationId The UID of the hash plug-in to instantiate. + * @param aAlgorithmParams The parameters that are specific to a particular + * algorithm. This is for extendibility and will normally be null. + * @return KErrNone if successful; otherwise, a system wide error code. + + IMPORT_C static void CreateAsyncHashL(MAsyncHash*& aPlugin, + TUid aImplementationId, + TUid aOperationMode, + const CKey* aKey, + const CCryptoParams* aAlgorithmParams); + */ + + /** + * Creates a new instance of a key agreement system. + * + * @param aPlugin A reference to a pointer that should be set to point to + * the new asymmetric key pair generator object. + * @param aImplementationId The UID of the key agreement plug-in to instantiate. + * @param aKey The private key to combine with the other parties public key + * during the agreement. + * @param aAlgorithmParams The parameters that are specific to a particular + * algorithm. This is for extendibility and will normally be null. + * @return KErrNone if successful; otherwise, a system wide error code. + + IMPORT_C static void CreateAsyncKeyAgreementL(MAsyncKeyAgreement*& aPlugin, + TUid aImplementationId, + const CKey& aPrivateKey, + const CCryptoParams* aAlgorithmParams); + */ + + /** + * Creates a new instance of an asymmetric key pair generator. + * + * @param aPlugin A reference to a pointer that should be set to point to + * the new asymmetric key pair generator object. + * @param aImplementationId The UID of the verifier plug-in to instantiate. + * @param aAlgorithmParams The parameters that are specific to a particular + * algorithm. This is for extendibility and will normally be null. + * @return KErrNone if successful; otherwise, a system wide error code. + + IMPORT_C static void CreateAsyncKeyPairGeneratorL(MAsyncKeyPairGenerator*& aPlugin, + TUid aImplementationId, + const CCryptoParams* aAlgorithmParams); + */ + + /** + * Creates a new instance of a Random object. + * + * @param aPlugin A reference to a pointer that should be set to point to the new random object. + * @param aImplementationId The UID of the random plug-in to instantiate. + * @param aAlgorithmParams The parameters that are specific to a particular + * algorithm. This is for extendibility and will normally be null. + * @return KErrNone if successful; otherwise, a system wide error code. + + IMPORT_C static void CreateAsyncRandomL(MAsyncRandom*& aPlugin, + TUid aImplementationId, + const CCryptoParams* aAlgorithmParams); + */ + + /** + * Creates a new instance of a symmetric cipher + * + * @param aPlugin A reference to a pointer that should be set to point to + * the new asymmetric object. + * @param aImplementationId The UID of the symmetric cipher plug-in to instantiate. + * @param aKey The encryption/decryption key. + * @param aAlgorithmParams The parameters that are specific to a particular + * algorithm. This is for extendibility and will normally be null. + * @return KErrNone if successful; otherwise, a system wide error code. + + IMPORT_C static void CreateAsyncSymmetricCipherL(MAsyncSymmetricCipher*& aPlugin, + TUid aImplementationId, + const CKey& aKey, + TUid aMode, + TUid aPadding, + const CCryptoParams* aAlgorithmParams); + */ + +#ifdef SYMBIAN_SDP_IPSEC_VOIP_SUPPORT + + /** + * Creates a new instance of a Hash object. + * + * @param aPlugin A reference to a pointer that should be set to point to + * the new hash object. + * @param aImplementationId The UID of the hash plug-in to instantiate. + * @param aAlgorithmParams The parameters that are specific to a particular + * algorithm. This is for extendibility and will normally be null. + * @return KErrNone if successful; otherwise, a system wide error code. + */ + IMPORT_C static void CreateHashL(MHash*& aPlugin, + TUid aImplementationId, + const CCryptoParams* aAlgorithmParams); + /** + * Creates a new instance of a Hash object. + * + * @param aPlugin A reference to a pointer that should be set to point to + * the new hash object. + * @param aImplementationId The UID of the hash plug-in to instantiate. + * @param aAlgorithmParams The parameters that are specific to a particular + * algorithm. This is for extendibility and will normally be null. + * @return KErrNone if successful; otherwise, a system wide error code. + + IMPORT_C static void CreateAsyncHashL(MAsyncHash*& aPlugin, + TUid aImplementationId, + const CCryptoParams* aAlgorithmParams); + */ + + /** + * Create a CMac instance (if implementation is software based) + * + * @param aMac The pointer to CMac + * @param aImplementationId The specific hash or cipher plug-in to instantiate.. + * @param aKey The key for calculating message authentication code value. + * Based on the algorithm used we will define the properties of the key. + * @param aAlgorithmParams The parameters that are specific to a particular + * algorithm. This is for extendibility and will normally be null. + * @return KErrNone if successful; otherwise, a system wide error code. + */ + IMPORT_C static void CreateMacL(MMac*& aPlugin, + const TUid aImplementationId, + const CKey& aKey, + const CCryptoParams* aAlgorithmParams); + + /** + * Create a CAsyncMac instance + * + * @param aMac The pointer to CAsyncMac + * @param aImplementationId The specific hash or cipher plug-in to instantiate.. + * @param aKey The key for calculating message authentication code value. + * Based on the algorithm used we will define the properties of the key. + * @param aAlgorithmParams The parameters that are specific to a particular + * algorithm. This is for extendibility and will normally be null. + * @return KErrNone if successful; otherwise, a system wide error code. + + IMPORT_C static void CreateAsyncMacL(MAsyncMac*& aPlugin, + const TUid aImplementationId, + const CKey& aKey, + const CCryptoParams* aAlgorithmParams); + */ + +#endif + + }; + + +#endif // __PLUGINENTRY_H__ diff -r 7e3f204e6c81 -r f9c11be8c0b3 cryptoplugins/cryptospiplugins/source/softwarecrypto/randomimpl.cpp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/cryptoplugins/cryptospiplugins/source/softwarecrypto/randomimpl.cpp Tue Dec 01 11:12:04 2009 +0000 @@ -0,0 +1,212 @@ +/* +* Copyright (c) 2005-2009 Nokia Corporation and/or its subsidiary(-ies). +* All rights reserved. +* This component and the accompanying materials are made available +* under the terms of the License "Eclipse Public License v1.0" +* which accompanies this distribution, and is available +* at the URL "http://www.eclipse.org/legal/epl-v10.html". +* +* Initial Contributors: +* Nokia Corporation - initial contribution. +* +* Contributors: +* +* Description: +* +*/ + + +/** + @file +*/ + +#include +#include + +#include "randomimpl.h" +#include "pluginentry.h" +#include "pluginconfig.h" + +#include "randsvr.h" +#include "randcliserv.h" +#include "randsvrimpl.h" + +_LIT(KRandomServerImg,"z:\\sys\\bin\\randsvr.exe"); // DLL/EXE name +_LIT(KRandomServerConnect, "Randsvr connect"); +_LIT(KRandomServerGet, "Randsvr get"); + +const TUid KServerUid3={0x100066dc}; + + +using namespace SoftwareCrypto; + + +CRandomImpl* CRandomImpl::NewL(void) + { + CRandomImpl* self = new(ELeave)CRandomImpl(); + return self; + } + +CRandomImpl* CRandomImpl::NewLC(void) + { + CRandomImpl* self = NewL(); + CleanupStack::PushL(self); + return self; + } + +void CRandomImpl::GenerateRandomBytesL(TDes8& aDest) + { + TRandomImpl::Random(aDest); + } + +CRandomImpl::CRandomImpl(void) + { + } + +void TRandomImpl::Random(TDes8& aDestination) + { + RRandomSessionImpl rs; + TRAPD(ret,rs.ConnectL()); + if (ret != KErrNone) + { + User::Panic(KRandomServerConnect, ret); + } + TInt err=rs.GetRandom(aDestination); + if (err != KErrNone) + { + User::Panic(KRandomServerGet, err); + } + rs.Close(); + } + +void CRandomImpl::GetCharacteristicsL(const TCharacteristics*& aPluginCharacteristics) + { + TInt randomNum = sizeof(KRandomCharacteristics)/sizeof(TRandomCharacteristics*); + for (TInt i = 0; i < randomNum; i++) + { + if (KRandomCharacteristics[i]->cmn.iImplementationUID == ImplementationUid().iUid) + { + aPluginCharacteristics = KRandomCharacteristics[i]; + break; + } + } + } + +CExtendedCharacteristics* CRandomImpl::CreateExtendedCharacteristicsL() + { + // All Symbian software plug-ins have unlimited concurrency, cannot be reserved + // for exclusive use and are not CERTIFIED to be standards compliant. + return CExtendedCharacteristics::NewL(KMaxTInt, EFalse); + } + +const CExtendedCharacteristics* CRandomImpl::GetExtendedCharacteristicsL() + { + return CRandomImpl::CreateExtendedCharacteristicsL(); + } + +TUid CRandomImpl::ImplementationUid() const + { + return KCryptoPluginRandomUid; + } + +CRandomImpl::~CRandomImpl() + { + } + +void CRandomImpl::Close() + { + delete this; + } + +// All crypto plugins must implement this, to reset +// hardware if required. Do nothing in this version +void CRandomImpl::Reset() + { + } + +RRandomSessionImpl::RRandomSessionImpl(void) + { + } + +static TInt StartServer() +// Borrowed from AndrewT's server startup code. +// Start the server process/thread which lives in an EPOCEXE object +// + { + + const TUidType serverUid(KNullUid,KNullUid,KServerUid3); + + // + // EPOC and EKA2 is easy, we just create a new server process. Simultaneous + // launching of two such processes should be detected when the second one + // attempts to create the server object, failing with KErrAlreadyExists. + // + RProcess server; + TInt r=server.Create(KRandomServerImg, KNullDesC, serverUid); + + if (r!=KErrNone) + return r; + TRequestStatus stat; + server.Rendezvous(stat); + if (stat!=KRequestPending) + server.Kill(0); // abort startup + else + server.Resume(); // logon OK - start the server + User::WaitForRequest(stat); // wait for start or death + // we can't use the 'exit reason' if the server panicked as this + // is the panic 'reason' and may be '0' which cannot be distinguished + // from KErrNone + r=(server.ExitType()==EExitPanic) ? KErrGeneral : stat.Int(); + server.Close(); + return r; + + } + +void RRandomSessionImpl::ConnectL(void) + { + TInt retry=2; + for (;;) + { + // Magic number 1 below is the number of asynchronous message slots + TInt r = CreateSession(KRandomServerName,TVersion(0,0,0), 1); + if (r == KErrNone) return; + // We used to leave with KErrNone, but this is inefficient and + // provokes an emulator problem in User::Leave which causes tpbe to crash + // if (r == KErrNone) User::Leave(r); // Connected okay + if (r != KErrNotFound && r != KErrServerTerminated) + User::Leave(r); // Something else happened + if (--retry == 0) + User::Leave(r); // Give up after a while + r = StartServer(); // Try starting again + if (r != KErrNone && r != KErrAlreadyExists) + User::Leave(r); + } + } + +TInt RRandomSessionImpl::GetRandom(TDes8& aDestination) + { + TInt desclength = aDestination.Length(); + for ( TInt i = 0; i < desclength; i += KRandomBlockSize) + { + TInt getlen = Min(KRandomBlockSize, desclength - i); + TPtr8 buffer(&aDestination[i], KRandomBlockSize, KRandomBlockSize); + TInt err = SendReceive(CRandomSession::KRandomRequest, TIpcArgs(&buffer, getlen)); + if (err != KErrNone) + { + return err; + } + } + return KErrNone; + } + +// Methods which are not supported can be excluded from the coverage. +#ifdef _BullseyeCoverage +#pragma suppress_warnings on +#pragma BullseyeCoverage off +#pragma suppress_warnings off +#endif + +TAny* CRandomImpl::GetExtension(TUid /*aExtensionId*/) + { + return NULL; + } diff -r 7e3f204e6c81 -r f9c11be8c0b3 cryptoplugins/cryptospiplugins/source/softwarecrypto/randomimpl.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/cryptoplugins/cryptospiplugins/source/softwarecrypto/randomimpl.h Tue Dec 01 11:12:04 2009 +0000 @@ -0,0 +1,114 @@ +/* +* Copyright (c) 2006-2009 Nokia Corporation and/or its subsidiary(-ies). +* All rights reserved. +* This component and the accompanying materials are made available +* under the terms of the License "Eclipse Public License v1.0" +* which accompanies this distribution, and is available +* at the URL "http://www.eclipse.org/legal/epl-v10.html". +* +* Initial Contributors: +* Nokia Corporation - initial contribution. +* +* Contributors: +* +* Description: +* Software random implementation +* +*/ + + +/** + @file + @internalComponent + @released +*/ + +#ifndef __CRYPTOAPI_RANDOMIMPL_H__ +#define __CRYPTOAPI_RANDOMIMPL_H__ + +#include +#include + +namespace SoftwareCrypto + { + using namespace CryptoSpi; + + NONSHARABLE_CLASS(CRandomImpl): public CBase, public MRandom + { + public: + // NewL & NewLC + static CRandomImpl* NewL(); + static CRandomImpl* NewLC(); + + // From MPlugin + void Reset(); + void Close(); + void GetCharacteristicsL(const TCharacteristics*& aPluginCharacteristics); + const CExtendedCharacteristics* GetExtendedCharacteristicsL(); + TAny* GetExtension(TUid aExtensionId); + TUid ImplementationUid() const; + + // From MRandom + void GenerateRandomBytesL(TDes8& aDest); + + static CExtendedCharacteristics* CreateExtendedCharacteristicsL(); + + private: + //Constructor + CRandomImpl(); + + //Destructor + ~CRandomImpl(); + + private: + TUid iImplementationUid; + }; + + class TRandomImpl + /** + * The user interface to the system cryptographically + * secure random number generator. + * + * @internalComponent + * @released + */ + { + public: + + /** + * Fills the provided buffer with secure random data up to its + * current length, discarding any current content. + * + * @param aDestination The buffer in which to write the random data. + */ + static void Random(TDes8& aDestination); + }; + + class RRandomSessionImpl : public RSessionBase + /** + * The client interface to the system random number generator. End + * users should use TRandom instead of this interface. + * + * @internalAll + * @released + */ + { + public: + RRandomSessionImpl(); + + /** + * Fills the provided buffer with secure random data up to its + * current length, discarding any current content. + * + * @param aDestination The buffer in to which to write the random data + */ + TInt GetRandom(TDes8& aDestination); + + /** + * Opens a new session with the random number server. + */ + void ConnectL(); + }; + } + +#endif // __CRYPTOAPI_RANDOMIMPL_H__ diff -r 7e3f204e6c81 -r f9c11be8c0b3 cryptoplugins/cryptospiplugins/source/softwarecrypto/rc2impl.cpp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/cryptoplugins/cryptospiplugins/source/softwarecrypto/rc2impl.cpp Tue Dec 01 11:12:04 2009 +0000 @@ -0,0 +1,213 @@ +/* +* Copyright (c) 2006-2009 Nokia Corporation and/or its subsidiary(-ies). +* All rights reserved. +* This component and the accompanying materials are made available +* under the terms of the License "Eclipse Public License v1.0" +* which accompanies this distribution, and is available +* at the URL "http://www.eclipse.org/legal/epl-v10.html". +* +* Initial Contributors: +* Nokia Corporation - initial contribution. +* +* Contributors: +* +* Description: +* +*/ + + +#include "rc2impl.h" +#include "keys.h" + +#include "rc2table.h" +#include "common/inlines.h" +#include "pluginconfig.h" +#include "symmetriccipherimpl.h" +#include + +using namespace SoftwareCrypto; + +CRc2Impl::CRc2Impl( + TUid aCryptoMode, + TUid aOperationMode, + TUid aPadding) : + CSymmetricBlockCipherImpl(KRc2BlockBytes, aCryptoMode, aOperationMode, aPadding) + { + } + +CRc2Impl* CRc2Impl::NewL( + const CKey& aKey, + TUid aCryptoMode, + TUid aOperationMode, + TUid aPadding, + TInt aEffectiveKeyLenBits) + { + CRc2Impl* self = CRc2Impl::NewLC(aKey, aCryptoMode, aOperationMode, aPadding, aEffectiveKeyLenBits); + CleanupStack::Pop(self); + return self; + } + +CRc2Impl* CRc2Impl::NewLC( + const CKey& aKey, + TUid aCryptoMode, + TUid aOperationMode, + TUid aPadding, + TInt aEffectiveKeyLenBits) + { + CRc2Impl* self = new(ELeave) CRc2Impl(aCryptoMode, aOperationMode, aPadding); + CleanupStack::PushL(self); + self->ConstructL(aKey, aEffectiveKeyLenBits); + + const TDesC8& keyContent = aKey.GetTDesC8L(KSymmetricKeyParameterUid); + TCrypto::IsSymmetricWeakEnoughL(BytesToBits(keyContent.Size()) - keyContent.Size()); + return self; + } + +CRc2Impl::~CRc2Impl() + { + Mem::FillZ(&iK, sizeof(iK)); + } + +void CRc2Impl::ConstructL(const CKey& aKey, TInt aEffectiveKeyLenBits) + { + iEffectiveKeyLenBits = aEffectiveKeyLenBits; + CSymmetricBlockCipherImpl::ConstructL(aKey); + SetKeySchedule(); + } + +CExtendedCharacteristics* CRc2Impl::CreateExtendedCharacteristicsL() + { + // All Symbian software plug-ins have unlimited concurrency, cannot be reserved + // for exclusive use and are not CERTIFIED to be standards compliant. + return CExtendedCharacteristics::NewL(KMaxTInt, EFalse); + } + +const CExtendedCharacteristics* CRc2Impl::GetExtendedCharacteristicsL() + { + return CRc2Impl::CreateExtendedCharacteristicsL(); + } + +TUid CRc2Impl::ImplementationUid() const + { + return KCryptoPluginRc2Uid; + } + +TBool CRc2Impl::IsValidKeyLength(TInt aKeyBytes) const + { + return ((aKeyBytes > 0 && aKeyBytes <= KRc2MaxKeySizeBytes) ? ETrue : EFalse); + } + +TInt CRc2Impl::GetKeyStrength() const + { + return Min(iEffectiveKeyLenBits, BytesToBits(iKeyBytes)); + } + +void CRc2Impl::SetKeySchedule() + { + TUint keyLen = iKey->Length(); + + TUint8 L[KRc2MaxKeySizeBytes]; + Mem::Copy((TUint8*)&L[0], (TUint8*)&(*iKey)[0], keyLen); + + TInt i = keyLen; + for (; i < KRc2MaxKeySizeBytes; i++) + { + L[i] = RC2_TABLE::PITABLE[(L[i-1] + L[i-keyLen]) & 255]; + } + + TUint T8 = (iEffectiveKeyLenBits+7) / 8; + TUint8 TM = (TUint8)(255 >> ((8-(iEffectiveKeyLenBits%8))%8)); + L[128-T8] = RC2_TABLE::PITABLE[L[128-T8] & TM]; + + for (i=127-T8; i>=0; i--) + L[i] = RC2_TABLE::PITABLE[L[i+1] ^ L[i+T8]]; + + for (i=0; i < KRc2ExpandedKeyLen; i++) + iK[i] = (TUint16)(L[2*i] + (L[2*i+1] << 8)); + } + +#pragma warning (disable : 4244) // conversion from 'int' to 'unsigned short', possible loss of data +void CRc2Impl::TransformEncrypt( + TUint8* aBuffer, + TUint aNumBlocks) + { + for (TInt blockNum = 0; blockNum < aNumBlocks; ++blockNum) + { + ModeEncryptStart(aBuffer); + + TUint16 R0, R1, R2, R3; + GetBlockLittleEndian(aBuffer, R0, R1, R2, R3); + + TInt i = 0; + for (; i < 16; i++) + { + R0 += (R1 & ~R3) + (R2 & R3) + iK[4*i+0]; + R0 = rotlFixed(R0, 1); + + R1 += (R2 & ~R0) + (R3 & R0) + iK[4*i+1]; + R1 = rotlFixed(R1, 2); + + R2 += (R3 & ~R1) + (R0 & R1) + iK[4*i+2]; + R2 = rotlFixed(R2, 3); + + R3 += (R0 & ~R2) + (R1 & R2) + iK[4*i+3]; + R3 = rotlFixed(R3, 5); + + if (i == 4 || i == 10) + { + R0 += iK[R3 & 63]; + R1 += iK[R0 & 63]; + R2 += iK[R1 & 63]; + R3 += iK[R2 & 63]; + } + } + PutBlockLittleEndian(aBuffer, R0, R1, R2, R3); + ModeEncryptEnd(aBuffer); + aBuffer += KRc2BlockBytes; + } + } +#pragma warning (default : 4244) // conversion from 'int' to 'unsigned short', possible loss of data + + +#pragma warning (disable : 4244) // conversion from 'int' to 'unsigned short', possible loss of data +void CRc2Impl::TransformDecrypt( + TUint8* aBuffer, + TUint aNumBlocks) + { + for (TInt blockNum = 0; blockNum < aNumBlocks; ++blockNum) + { + ModeDecryptStart(aBuffer); + + TUint16 R0, R1, R2, R3; + GetBlockLittleEndian(aBuffer, R0, R1, R2, R3); + + TInt i = 15; + for (; i >= 0; i--) + { + if (i == 4 || i == 10) + { + R3 -= iK[R2 & 63]; + R2 -= iK[R1 & 63]; + R1 -= iK[R0 & 63]; + R0 -= iK[R3 & 63]; + } + + R3 = rotrFixed(R3, 5); + R3 -= (R0 & ~R2) + (R1 & R2) + iK[4*i+3]; + + R2 = rotrFixed(R2, 3); + R2 -= (R3 & ~R1) + (R0 & R1) + iK[4*i+2]; + + R1 = rotrFixed(R1, 2); + R1 -= (R2 & ~R0) + (R3 & R0) + iK[4*i+1]; + + R0 = rotrFixed(R0, 1); + R0 -= (R1 & ~R3) + (R2 & R3) + iK[4*i+0]; + } + + PutBlockLittleEndian(aBuffer, R0, R1, R2, R3); + ModeDecryptEnd(aBuffer); + aBuffer += KRc2BlockBytes; + } + } +#pragma warning (default : 4244) // conversion from 'int' to 'unsigned short', possible loss of data diff -r 7e3f204e6c81 -r f9c11be8c0b3 cryptoplugins/cryptospiplugins/source/softwarecrypto/rc2impl.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/cryptoplugins/cryptospiplugins/source/softwarecrypto/rc2impl.h Tue Dec 01 11:12:04 2009 +0000 @@ -0,0 +1,118 @@ +/* +* Copyright (c) 2006-2009 Nokia Corporation and/or its subsidiary(-ies). +* All rights reserved. +* This component and the accompanying materials are made available +* under the terms of the License "Eclipse Public License v1.0" +* which accompanies this distribution, and is available +* at the URL "http://www.eclipse.org/legal/epl-v10.html". +* +* Initial Contributors: +* Nokia Corporation - initial contribution. +* +* Contributors: +* +* Description: +* +*/ + + +#ifndef __RC2_H__ +#define __RC2_H__ + +/** +@file +@internalComponent +@released +*/ + +#include +#include +#include "keys.h" +#include "symmetriccipherimpl.h" + +/** +Plug-in class for RC2 block cipher +*/ +namespace SoftwareCrypto + { + using namespace CryptoSpi; + + NONSHARABLE_CLASS(CRc2Impl) : public CSymmetricBlockCipherImpl + { + public: + /** + Creates an instance of an RC2 symmetric cipher plug-in. + @param aKey The key + @param aCryptoMode Whether to encrypt or decrypt + @param aOperationMode The block cipher mode ECB, CBC, CTR etc + @param aPadding The padding scheme to use None, SSLv3, PKCS#7 + @param aEffectiveKeyLenBits The effective key length in bits + @return A pointer to a CRc2Impl instance + */ + static CRc2Impl* NewL(const CKey& aKey, + TUid aCryptoMode, TUid aOperationMode, TUid aPadding, TInt aEffectiveKeyLenBits); + + /** + Creates an instance of an RC2 symmetric cipher plug-in. + A pointer to the plug-in instance is placed on the cleanup stack. + @param aKey The key + @param aCryptoMode Whether to encrypt or decrypt + @param aOperationMode The block cipher mode ECB, CBC, CTR etc + @param aPadding The padding scheme to use None, SSLv3, PKCS#7 + @param aEffectiveKeyLenBits The effective key length in bits + @return A pointer to a CRc2Impl instance + */ + static CRc2Impl* NewLC(const CKey& aKey, + TUid aCryptoMode, TUid aOperationMode, TUid aPadding, TInt aEffectiveKeyLenBits); + + // From CSymmetricCipherImpl + TBool IsValidKeyLength(TInt aKeyBytes) const; + TUid ImplementationUid() const; + TInt GetKeyStrength() const; + const CExtendedCharacteristics* GetExtendedCharacteristicsL(); + + static CExtendedCharacteristics* CreateExtendedCharacteristicsL(); + + /// Destructor + ~CRc2Impl(); + + /** SSL Effective Key Length Compatibility - for compatibility with SSL */ + static const TUint KDefaultEffectiveKeyLenBits = 1024; + + private: + /** + Constructor + @param aOperationMode The mode of operation e.g. CBC + @param aCryptoMode Whether to encrypt or decrypt + @param aPaddingMode The padding mode to use. None, SSL, PKCS#7 + */ + CRc2Impl(TUid aOperationMode, TUid aCryptoMode, TUid aPaddingMode); + + /// second phase of construction + void ConstructL(const CKey& aKey, TInt aEffectiveKeyLenBits); + + /** + Expands the key (iKey) to iEffectiveKeyLenBits and stores the result in iK + */ + void SetKeySchedule(); + + // From CSymmetricBlockCipherImpl + void TransformEncrypt(TUint8* aBuffer, TUint aNumBlocks); + void TransformDecrypt(TUint8* aBuffer, TUint aNumBlocks); + + private: + static const TUint8 KRc2BlockBytes = 8; + static const TInt KRc2MaxKeySizeBytes = 128; + static const TInt KRc2ExpandedKeyLen = 64; + /** + The expanded key buffer. + Each iK[i] is a 16-bit word. + */ + TUint16 iK[KRc2ExpandedKeyLen]; // 128 bytes + + /** The effective key length in bits */ + TInt iEffectiveKeyLenBits; + }; + } + +#endif //__RC2_H__ diff -r 7e3f204e6c81 -r f9c11be8c0b3 cryptoplugins/cryptospiplugins/source/softwarecrypto/rc2table.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/cryptoplugins/cryptospiplugins/source/softwarecrypto/rc2table.h Tue Dec 01 11:12:04 2009 +0000 @@ -0,0 +1,53 @@ +/* +* Copyright (c) 2002-2009 Nokia Corporation and/or its subsidiary(-ies). +* All rights reserved. +* This component and the accompanying materials are made available +* under the terms of the License "Eclipse Public License v1.0" +* which accompanies this distribution, and is available +* at the URL "http://www.eclipse.org/legal/epl-v10.html". +* +* Initial Contributors: +* Nokia Corporation - initial contribution. +* +* Contributors: +* +* Description: +* +*/ + + +/** + @file + @internalComponent + @released +*/ + +#ifndef __RC2TABLES_H__ +#define __RC2TABLES_H__ + +#include + +namespace RC2_TABLE +{ + const TUint8 PITABLE[256] = + { + 217,120,249,196, 25,221,181,237, 40,233,253,121, 74,160,216,157, + 198,126, 55,131, 43,118, 83,142, 98, 76,100,136, 68,139,251,162, + 23,154, 89,245,135,179, 79, 19, 97, 69,109,141, 9,129,125, 50, + 189,143, 64,235,134,183,123, 11,240,149, 33, 34, 92,107, 78,130, + 84,214,101,147,206, 96,178, 28,115, 86,192, 20,167,140,241,220, + 18,117,202, 31, 59,190,228,209, 66, 61,212, 48,163, 60,182, 38, + 111,191, 14,218, 70,105, 7, 87, 39,242, 29,155,188,148, 67, 3, + 248, 17,199,246,144,239, 62,231, 6,195,213, 47,200,102, 30,215, + 8,232,234,222,128, 82,238,247,132,170,114,172, 53, 77,106, 42, + 150, 26,210,113, 90, 21, 73,116, 75,159,208, 94, 4, 24,164,236, + 194,224, 65,110, 15, 81,203,204, 36,145,175, 80,161,244,112, 57, + 153,124, 58,133, 35,184,180,122,252, 2, 54, 91, 37, 85,151, 49, + 45, 93,250,152,227,138,146,174, 5,223, 41, 16,103,108,186,201, + 211, 0,230,207,225,158,168, 44, 99, 22, 1, 63, 88,226,137,169, + 13, 56, 52, 27,171, 51,255,176,187, 72, 12, 95,185,177,205, 46, + 197,243,219, 71,229,165,156,119, 10,166, 32,104,254,127,193,173 + }; +} + // namespace RC2_TABLE +#endif // __RC2TABLES_H__ diff -r 7e3f204e6c81 -r f9c11be8c0b3 cryptoplugins/cryptospiplugins/source/softwarecrypto/rijndaelimpl.cpp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/cryptoplugins/cryptospiplugins/source/softwarecrypto/rijndaelimpl.cpp Tue Dec 01 11:12:04 2009 +0000 @@ -0,0 +1,484 @@ +/* +* Copyright (c) 2006-2009 Nokia Corporation and/or its subsidiary(-ies). +* All rights reserved. +* This component and the accompanying materials are made available +* under the terms of the License "Eclipse Public License v1.0" +* which accompanies this distribution, and is available +* at the URL "http://www.eclipse.org/legal/epl-v10.html". +* +* Initial Contributors: +* Nokia Corporation - initial contribution. +* +* Contributors: +* +* Description: +* +*/ + + +#include "rijndaelimpl.h" +#include "keys.h" + +#include "rijndaeltables.h" +#include "common/inlines.h" +#include "pluginconfig.h" +#include "symmetriccipherimpl.h" +#include + +using namespace SoftwareCrypto; + +const TUint KAESKeyBytes128 = 16; +const TUint KAESKeyBytes192 = 24; +const TUint KAESKeyBytes256 = 32; +const TUint KAESBlockBytes = 16; + +/* CRijndaelmpl*/ +CRijndaelImpl::CRijndaelImpl( + TUid aCryptoMode, + TUid aOperationMode, + TUid aPadding) : + CSymmetricBlockCipherImpl(KAESBlockBytes, aCryptoMode, aOperationMode, aPadding) + { + } + +CRijndaelImpl* CRijndaelImpl::NewL(const CKey& aKey, TUid aCryptoMode, TUid aOperationMode, TUid aPadding) + { + CRijndaelImpl* self = CRijndaelImpl::NewLC(aKey, aCryptoMode, aOperationMode, aPadding); + CleanupStack::Pop(self); + return self; + } + +CRijndaelImpl* CRijndaelImpl::NewLC(const CKey& aKey, TUid aCryptoMode, TUid aOperationMode, TUid aPadding) + { + CRijndaelImpl* self = new(ELeave) CRijndaelImpl(aCryptoMode, aOperationMode, aPadding); + CleanupStack::PushL(self); + self->ConstructL(aKey); + + const TDesC8& keyContent = aKey.GetTDesC8L(KSymmetricKeyParameterUid); + TCrypto::IsSymmetricWeakEnoughL(BytesToBits(keyContent.Size()) - keyContent.Size()); + return self; + } + +CRijndaelImpl::~CRijndaelImpl() + { + // make sure key information isn't visible to other processes if the + // page is reused. + Mem::FillZ(&iK, sizeof(iK)); + } + +void CRijndaelImpl::ConstructL(const CKey& aKey) + { + CSymmetricBlockCipherImpl::ConstructL(aKey); + SetKeySchedule(); + } + +CExtendedCharacteristics* CRijndaelImpl::CreateExtendedCharacteristicsL() + { + // All Symbian software plug-ins have unlimited concurrency, cannot be reserved + // for exclusive use and are not CERTIFIED to be standards compliant. + return CExtendedCharacteristics::NewL(KMaxTInt, EFalse); + } + +const CExtendedCharacteristics* CRijndaelImpl::GetExtendedCharacteristicsL() + { + return CRijndaelImpl::CreateExtendedCharacteristicsL(); + } + +TUid CRijndaelImpl::ImplementationUid() const + { + return KCryptoPluginAesUid; + } + +TBool CRijndaelImpl::IsValidKeyLength(TInt aKeyBytes) const + { + switch(aKeyBytes) + { + case KAESKeyBytes128: + case KAESKeyBytes192: + case KAESKeyBytes256: + return ETrue; + default: + return EFalse; + } + } + +void CRijndaelImpl::SetKeySchedule() + { + iRounds = iKeyBytes/4 + 6; + if (iCryptoMode.iUid == KCryptoModeEncrypt) + { + SetEncryptKeySchedule(*iKey, &iK[0]); + } + else + { + ASSERT(iCryptoMode.iUid == KCryptoModeDecrypt); + SetDecryptKeySchedule(*iKey, &iK[0]); + } + } + +void CRijndaelImpl::TransformEncrypt( + TUint8* aBuffer, + TUint aNumBlocks) + { + for (TInt i = 0; i < aNumBlocks; ++i) + { + ModeEncryptStart(aBuffer); + + TUint32 s0, s1, s2, s3, t0, t1, t2, t3; + const TUint32* rk = &iK[0]; + + /* + * map byte array block to cipher state + * and add initial round key: + */ + GetBlockBigEndian(aBuffer, s0, s1, s2, s3); + s0 ^= rk[0]; + s1 ^= rk[1]; + s2 ^= rk[2]; + s3 ^= rk[3]; + /* + * Nr - 1 full rounds: + */ + TUint r = iRounds >> 1; + FOREVER + { + t0 = + RIJNDAEL_TABLE::Te0[GETBYTE(s0, 3)] ^ + RIJNDAEL_TABLE::Te1[GETBYTE(s1, 2)] ^ + RIJNDAEL_TABLE::Te2[GETBYTE(s2, 1)] ^ + RIJNDAEL_TABLE::Te3[GETBYTE(s3, 0)] ^ + rk[4]; + t1 = + RIJNDAEL_TABLE::Te0[GETBYTE(s1, 3)] ^ + RIJNDAEL_TABLE::Te1[GETBYTE(s2, 2)] ^ + RIJNDAEL_TABLE::Te2[GETBYTE(s3, 1)] ^ + RIJNDAEL_TABLE::Te3[GETBYTE(s0, 0)] ^ + rk[5]; + t2 = + RIJNDAEL_TABLE::Te0[GETBYTE(s2, 3)] ^ + RIJNDAEL_TABLE::Te1[GETBYTE(s3, 2)] ^ + RIJNDAEL_TABLE::Te2[GETBYTE(s0, 1)] ^ + RIJNDAEL_TABLE::Te3[GETBYTE(s1, 0)] ^ + rk[6]; + t3 = + RIJNDAEL_TABLE::Te0[GETBYTE(s3, 3)] ^ + RIJNDAEL_TABLE::Te1[GETBYTE(s0, 2)] ^ + RIJNDAEL_TABLE::Te2[GETBYTE(s1, 1)] ^ + RIJNDAEL_TABLE::Te3[GETBYTE(s2, 0)] ^ + rk[7]; + + rk += 8; + if (--r == 0) + break; + + s0 = + RIJNDAEL_TABLE::Te0[GETBYTE(t0, 3)] ^ + RIJNDAEL_TABLE::Te1[GETBYTE(t1, 2)] ^ + RIJNDAEL_TABLE::Te2[GETBYTE(t2, 1)] ^ + RIJNDAEL_TABLE::Te3[GETBYTE(t3, 0)] ^ + rk[0]; + s1 = + RIJNDAEL_TABLE::Te0[GETBYTE(t1, 3)] ^ + RIJNDAEL_TABLE::Te1[GETBYTE(t2, 2)] ^ + RIJNDAEL_TABLE::Te2[GETBYTE(t3, 1)] ^ + RIJNDAEL_TABLE::Te3[GETBYTE(t0, 0)] ^ + rk[1]; + s2 = + RIJNDAEL_TABLE::Te0[GETBYTE(t2, 3)] ^ + RIJNDAEL_TABLE::Te1[GETBYTE(t3, 2)] ^ + RIJNDAEL_TABLE::Te2[GETBYTE(t0, 1)] ^ + RIJNDAEL_TABLE::Te3[GETBYTE(t1, 0)] ^ + rk[2]; + s3 = + RIJNDAEL_TABLE::Te0[GETBYTE(t3, 3)] ^ + RIJNDAEL_TABLE::Te1[GETBYTE(t0, 2)] ^ + RIJNDAEL_TABLE::Te2[GETBYTE(t1, 1)] ^ + RIJNDAEL_TABLE::Te3[GETBYTE(t2, 0)] ^ + rk[3]; + } + /* + * apply last round and + * map cipher state to byte array block: + */ + + s0 = + (RIJNDAEL_TABLE::Te4[GETBYTE(t0, 3)] & 0xff000000) ^ + (RIJNDAEL_TABLE::Te4[GETBYTE(t1, 2)] & 0x00ff0000) ^ + (RIJNDAEL_TABLE::Te4[GETBYTE(t2, 1)] & 0x0000ff00) ^ + (RIJNDAEL_TABLE::Te4[GETBYTE(t3, 0)] & 0x000000ff) ^ + rk[0]; + s1 = + (RIJNDAEL_TABLE::Te4[GETBYTE(t1, 3)] & 0xff000000) ^ + (RIJNDAEL_TABLE::Te4[GETBYTE(t2, 2)] & 0x00ff0000) ^ + (RIJNDAEL_TABLE::Te4[GETBYTE(t3, 1)] & 0x0000ff00) ^ + (RIJNDAEL_TABLE::Te4[GETBYTE(t0, 0)] & 0x000000ff) ^ + rk[1]; + s2 = + (RIJNDAEL_TABLE::Te4[GETBYTE(t2, 3)] & 0xff000000) ^ + (RIJNDAEL_TABLE::Te4[GETBYTE(t3, 2)] & 0x00ff0000) ^ + (RIJNDAEL_TABLE::Te4[GETBYTE(t0, 1)] & 0x0000ff00) ^ + (RIJNDAEL_TABLE::Te4[GETBYTE(t1, 0)] & 0x000000ff) ^ + rk[2]; + s3 = + (RIJNDAEL_TABLE::Te4[GETBYTE(t3, 3)] & 0xff000000) ^ + (RIJNDAEL_TABLE::Te4[GETBYTE(t0, 2)] & 0x00ff0000) ^ + (RIJNDAEL_TABLE::Te4[GETBYTE(t1, 1)] & 0x0000ff00) ^ + (RIJNDAEL_TABLE::Te4[GETBYTE(t2, 0)] & 0x000000ff) ^ + rk[3]; + + PutBlockBigEndian(aBuffer, s0, s1, s2, s3); + ModeEncryptEnd(aBuffer); + aBuffer += KAESBlockBytes; + } + } + +void CRijndaelImpl::TransformDecrypt( + TUint8* aBuffer, + TUint aNumBlocks) + { + for (TInt i = 0; i < aNumBlocks; ++i) + { + ModeDecryptStart(aBuffer); + + TUint32 s0, s1, s2, s3, t0, t1, t2, t3; + const TUint32* rk = &iK[0]; + + /* + * map byte array block to cipher state + * and add initial round key: + */ + GetBlockBigEndian(aBuffer, s0, s1, s2, s3); + + s0 ^= rk[0]; + s1 ^= rk[1]; + s2 ^= rk[2]; + s3 ^= rk[3]; + /* + * Nr - 1 full rounds: + */ + TUint r = iRounds >> 1; + FOREVER + { + t0 = + RIJNDAEL_TABLE::Td0[GETBYTE(s0, 3)] ^ + RIJNDAEL_TABLE::Td1[GETBYTE(s3, 2)] ^ + RIJNDAEL_TABLE::Td2[GETBYTE(s2, 1)] ^ + RIJNDAEL_TABLE::Td3[GETBYTE(s1, 0)] ^ + rk[4]; + t1 = + RIJNDAEL_TABLE::Td0[GETBYTE(s1, 3)] ^ + RIJNDAEL_TABLE::Td1[GETBYTE(s0, 2)] ^ + RIJNDAEL_TABLE::Td2[GETBYTE(s3, 1)] ^ + RIJNDAEL_TABLE::Td3[GETBYTE(s2, 0)] ^ + rk[5]; + t2 = + RIJNDAEL_TABLE::Td0[GETBYTE(s2, 3)] ^ + RIJNDAEL_TABLE::Td1[GETBYTE(s1, 2)] ^ + RIJNDAEL_TABLE::Td2[GETBYTE(s0, 1)] ^ + RIJNDAEL_TABLE::Td3[GETBYTE(s3, 0)] ^ + rk[6]; + t3 = + RIJNDAEL_TABLE::Td0[GETBYTE(s3, 3)] ^ + RIJNDAEL_TABLE::Td1[GETBYTE(s2, 2)] ^ + RIJNDAEL_TABLE::Td2[GETBYTE(s1, 1)] ^ + RIJNDAEL_TABLE::Td3[GETBYTE(s0, 0)] ^ + rk[7]; + + rk += 8; + if (--r == 0) + break; + + s0 = + RIJNDAEL_TABLE::Td0[GETBYTE(t0, 3)] ^ + RIJNDAEL_TABLE::Td1[GETBYTE(t3, 2)] ^ + RIJNDAEL_TABLE::Td2[GETBYTE(t2, 1)] ^ + RIJNDAEL_TABLE::Td3[GETBYTE(t1, 0)] ^ + rk[0]; + s1 = + RIJNDAEL_TABLE::Td0[GETBYTE(t1, 3)] ^ + RIJNDAEL_TABLE::Td1[GETBYTE(t0, 2)] ^ + RIJNDAEL_TABLE::Td2[GETBYTE(t3, 1)] ^ + RIJNDAEL_TABLE::Td3[GETBYTE(t2, 0)] ^ + rk[1]; + s2 = + RIJNDAEL_TABLE::Td0[GETBYTE(t2, 3)] ^ + RIJNDAEL_TABLE::Td1[GETBYTE(t1, 2)] ^ + RIJNDAEL_TABLE::Td2[GETBYTE(t0, 1)] ^ + RIJNDAEL_TABLE::Td3[GETBYTE(t3, 0)] ^ + rk[2]; + s3 = + RIJNDAEL_TABLE::Td0[GETBYTE(t3, 3)] ^ + RIJNDAEL_TABLE::Td1[GETBYTE(t2, 2)] ^ + RIJNDAEL_TABLE::Td2[GETBYTE(t1, 1)] ^ + RIJNDAEL_TABLE::Td3[GETBYTE(t0, 0)] ^ + rk[3]; + } + /* + * apply last round and + * map cipher state to byte array block: + */ + s0 = + (RIJNDAEL_TABLE::Td4[GETBYTE(t0, 3)] & 0xff000000) ^ + (RIJNDAEL_TABLE::Td4[GETBYTE(t3, 2)] & 0x00ff0000) ^ + (RIJNDAEL_TABLE::Td4[GETBYTE(t2, 1)] & 0x0000ff00) ^ + (RIJNDAEL_TABLE::Td4[GETBYTE(t1, 0)] & 0x000000ff) ^ + rk[0]; + s1 = + (RIJNDAEL_TABLE::Td4[GETBYTE(t1, 3)] & 0xff000000) ^ + (RIJNDAEL_TABLE::Td4[GETBYTE(t0, 2)] & 0x00ff0000) ^ + (RIJNDAEL_TABLE::Td4[GETBYTE(t3, 1)] & 0x0000ff00) ^ + (RIJNDAEL_TABLE::Td4[GETBYTE(t2, 0)] & 0x000000ff) ^ + rk[1]; + s2 = + (RIJNDAEL_TABLE::Td4[GETBYTE(t2, 3)] & 0xff000000) ^ + (RIJNDAEL_TABLE::Td4[GETBYTE(t1, 2)] & 0x00ff0000) ^ + (RIJNDAEL_TABLE::Td4[GETBYTE(t0, 1)] & 0x0000ff00) ^ + (RIJNDAEL_TABLE::Td4[GETBYTE(t3, 0)] & 0x000000ff) ^ + rk[2]; + s3 = + (RIJNDAEL_TABLE::Td4[GETBYTE(t3, 3)] & 0xff000000) ^ + (RIJNDAEL_TABLE::Td4[GETBYTE(t2, 2)] & 0x00ff0000) ^ + (RIJNDAEL_TABLE::Td4[GETBYTE(t1, 1)] & 0x0000ff00) ^ + (RIJNDAEL_TABLE::Td4[GETBYTE(t0, 0)] & 0x000000ff) ^ + rk[3]; + PutBlockBigEndian(aBuffer, s0, s1, s2, s3); + ModeDecryptEnd(aBuffer); + aBuffer += KAESBlockBytes; + } + } + +void CRijndaelImpl::SetEncryptKeySchedule(const TDesC8& aKey, TUint32* aKeySchedule) + { + TUint keySize = aKey.Length(); + TUint32 temp; + TUint32* rk = aKeySchedule; + + TUint i = 0; + + GetUserKeyBigEndian(rk, keySize/4, &aKey[0], keySize); + + switch(keySize) + { + case (KAESKeyBytes128): + { + FOREVER + { + temp = rk[3]; + rk[4] = rk[0] ^ + (RIJNDAEL_TABLE::Te4[GETBYTE(temp, 2)] & 0xff000000) ^ + (RIJNDAEL_TABLE::Te4[GETBYTE(temp, 1)] & 0x00ff0000) ^ + (RIJNDAEL_TABLE::Te4[GETBYTE(temp, 0)] & 0x0000ff00) ^ + (RIJNDAEL_TABLE::Te4[GETBYTE(temp, 3)] & 0x000000ff) ^ + RIJNDAEL_TABLE::rcon[i]; + rk[5] = rk[1] ^ rk[4]; + rk[6] = rk[2] ^ rk[5]; + rk[7] = rk[3] ^ rk[6]; + if (++i == 10) + break; + rk += 4; + } + } + break; + + case (KAESKeyBytes192): + { + FOREVER + { + temp = rk[ 5]; + rk[ 6] = rk[ 0] ^ + (RIJNDAEL_TABLE::Te4[GETBYTE(temp, 2)] & 0xff000000) ^ + (RIJNDAEL_TABLE::Te4[GETBYTE(temp, 1)] & 0x00ff0000) ^ + (RIJNDAEL_TABLE::Te4[GETBYTE(temp, 0)] & 0x0000ff00) ^ + (RIJNDAEL_TABLE::Te4[GETBYTE(temp, 3)] & 0x000000ff) ^ + RIJNDAEL_TABLE::rcon[i]; + rk[ 7] = rk[ 1] ^ rk[ 6]; + rk[ 8] = rk[ 2] ^ rk[ 7]; + rk[ 9] = rk[ 3] ^ rk[ 8]; + if (++i == 8) + break; + rk[10] = rk[ 4] ^ rk[ 9]; + rk[11] = rk[ 5] ^ rk[10]; + rk += 6; + } + } + break; + + case (KAESKeyBytes256): + { + FOREVER + { + temp = rk[ 7]; + rk[ 8] = rk[ 0] ^ + (RIJNDAEL_TABLE::Te4[GETBYTE(temp, 2)] & 0xff000000) ^ + (RIJNDAEL_TABLE::Te4[GETBYTE(temp, 1)] & 0x00ff0000) ^ + (RIJNDAEL_TABLE::Te4[GETBYTE(temp, 0)] & 0x0000ff00) ^ + (RIJNDAEL_TABLE::Te4[GETBYTE(temp, 3)] & 0x000000ff) ^ + RIJNDAEL_TABLE::rcon[i]; + rk[ 9] = rk[ 1] ^ rk[ 8]; + rk[10] = rk[ 2] ^ rk[ 9]; + rk[11] = rk[ 3] ^ rk[10]; + if (++i == 7) + break; + temp = rk[11]; + rk[12] = rk[ 4] ^ + (RIJNDAEL_TABLE::Te4[GETBYTE(temp, 3)] & 0xff000000) ^ + (RIJNDAEL_TABLE::Te4[GETBYTE(temp, 2)] & 0x00ff0000) ^ + (RIJNDAEL_TABLE::Te4[GETBYTE(temp, 1)] & 0x0000ff00) ^ + (RIJNDAEL_TABLE::Te4[GETBYTE(temp, 0)] & 0x000000ff); + rk[13] = rk[ 5] ^ rk[12]; + rk[14] = rk[ 6] ^ rk[13]; + rk[15] = rk[ 7] ^ rk[14]; + + rk += 8; + } + } + break; + + default: + assert(0); // Shouldn't get here, keeps compiler happy + } + } + +void CRijndaelImpl::SetDecryptKeySchedule(const TDesC8& aKey, TUint32* aKeySchedule) + { + SetEncryptKeySchedule(aKey, aKeySchedule); + + TUint i, j; + TUint32* rk = aKeySchedule; + TUint32 temp; + + // invert the order of the round keys + for (i = 0, j = 4*iRounds; i < j; i += 4, j -= 4) + { + temp = rk[i ]; rk[i ] = rk[j ]; rk[j ] = temp; + temp = rk[i + 1]; rk[i + 1] = rk[j + 1]; rk[j + 1] = temp; + temp = rk[i + 2]; rk[i + 2] = rk[j + 2]; rk[j + 2] = temp; + temp = rk[i + 3]; rk[i + 3] = rk[j + 3]; rk[j + 3] = temp; + } + + // apply the inverse MixColumn transform to all round keys but the first and the last + for (i = 1; i < iRounds; i++) + { + rk += 4; + rk[0] = + RIJNDAEL_TABLE::Td0[RIJNDAEL_TABLE::Te4[GETBYTE(rk[0], 3)] & 0xff] ^ + RIJNDAEL_TABLE::Td1[RIJNDAEL_TABLE::Te4[GETBYTE(rk[0], 2)] & 0xff] ^ + RIJNDAEL_TABLE::Td2[RIJNDAEL_TABLE::Te4[GETBYTE(rk[0], 1)] & 0xff] ^ + RIJNDAEL_TABLE::Td3[RIJNDAEL_TABLE::Te4[GETBYTE(rk[0], 0)] & 0xff]; + rk[1] = + RIJNDAEL_TABLE::Td0[RIJNDAEL_TABLE::Te4[GETBYTE(rk[1], 3)] & 0xff] ^ + RIJNDAEL_TABLE::Td1[RIJNDAEL_TABLE::Te4[GETBYTE(rk[1], 2)] & 0xff] ^ + RIJNDAEL_TABLE::Td2[RIJNDAEL_TABLE::Te4[GETBYTE(rk[1], 1)] & 0xff] ^ + RIJNDAEL_TABLE::Td3[RIJNDAEL_TABLE::Te4[GETBYTE(rk[1], 0)] & 0xff]; + rk[2] = + RIJNDAEL_TABLE::Td0[RIJNDAEL_TABLE::Te4[GETBYTE(rk[2], 3)] & 0xff] ^ + RIJNDAEL_TABLE::Td1[RIJNDAEL_TABLE::Te4[GETBYTE(rk[2], 2)] & 0xff] ^ + RIJNDAEL_TABLE::Td2[RIJNDAEL_TABLE::Te4[GETBYTE(rk[2], 1)] & 0xff] ^ + RIJNDAEL_TABLE::Td3[RIJNDAEL_TABLE::Te4[GETBYTE(rk[2], 0)] & 0xff]; + rk[3] = + RIJNDAEL_TABLE::Td0[RIJNDAEL_TABLE::Te4[GETBYTE(rk[3], 3)] & 0xff] ^ + RIJNDAEL_TABLE::Td1[RIJNDAEL_TABLE::Te4[GETBYTE(rk[3], 2)] & 0xff] ^ + RIJNDAEL_TABLE::Td2[RIJNDAEL_TABLE::Te4[GETBYTE(rk[3], 1)] & 0xff] ^ + RIJNDAEL_TABLE::Td3[RIJNDAEL_TABLE::Te4[GETBYTE(rk[3], 0)] & 0xff]; + } + } diff -r 7e3f204e6c81 -r f9c11be8c0b3 cryptoplugins/cryptospiplugins/source/softwarecrypto/rijndaelimpl.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/cryptoplugins/cryptospiplugins/source/softwarecrypto/rijndaelimpl.h Tue Dec 01 11:12:04 2009 +0000 @@ -0,0 +1,128 @@ +/* +* Copyright (c) 2006-2009 Nokia Corporation and/or its subsidiary(-ies). +* All rights reserved. +* This component and the accompanying materials are made available +* under the terms of the License "Eclipse Public License v1.0" +* which accompanies this distribution, and is available +* at the URL "http://www.eclipse.org/legal/epl-v10.html". +* +* Initial Contributors: +* Nokia Corporation - initial contribution. +* +* Contributors: +* +* Description: +* +*/ + + +#ifndef __RIJNDAELIMPL_H__ +#define __RIJNDAELIMPL_H__ + +/** +@file +@internalComponent +@released +*/ + +#include +#include +#include "keys.h" +#include "symmetriccipherimpl.h" + +/** +Plug-in class for AES (Rijndael) block cipher +*/ +namespace SoftwareCrypto + { + using namespace CryptoSpi; + + NONSHARABLE_CLASS(CRijndaelImpl) : public CSymmetricBlockCipherImpl + { + public: + /** + Creates an instance of an AES (Rijndael) symmetric cipher plug-in. + @param aKey The key + @param aCryptoMode Whether to encrypt or decrypt + @param aOperationMode The block cipher mode ECB, CBC, CTR etc + @param aPadding The padding scheme to use None, SSLv3, PKCS#7 + @return A pointer to a CRijndaelImpl instance + */ + static CRijndaelImpl* NewL(const CKey& aKey, + TUid aCryptoMode, TUid aOperationMode, TUid aPadding); + + /** + Creates an instance of an AES (Rijndael) symmetric cipher plug-in. + A pointer to the plug-in instance is placed on the cleanup stack. + @param aKey The key + @param aCryptoMode Whether to encrypt or decrypt + @param aOperationMode The block cipher mode ECB, CBC, CTR etc + @param aPadding The padding scheme to use None, SSLv3, PKCS#7 + @return A pointer to a CRijndaelImpl instance + */ + static CRijndaelImpl* NewLC(const CKey& aKey, + TUid aCryptoMode, TUid aOperationMode, TUid aPadding); + + // From CSymmetricCipherImpl + TBool IsValidKeyLength(TInt aKeyBytes) const; + TUid ImplementationUid() const; + const CExtendedCharacteristics* GetExtendedCharacteristicsL(); + + static CExtendedCharacteristics* CreateExtendedCharacteristicsL(); + + /// Destructor + ~CRijndaelImpl(); + + private: + /** + Constructor + @param aOperationMode The mode of operation e.g. CBC + @param aCryptoMode Whether to encrypt or decrypt + @param aPaddingMode The padding mode to use. None, SSL, PKCS#7 + */ + CRijndaelImpl(TUid aOperationMode, TUid aCryptoMode, TUid aPaddingMode); + + /// second phase of construction + void ConstructL(const CKey& aKey); + + /** + Creates the key schedule iK from CBlockTransformationImpl::iKey. + This should be called from ConstructL and Reset + */ + void SetKeySchedule(); + + /** + Setup the key schedule for encryption + @param aKey The input key + @param aKeySchedule The pointer to the key schedule buffer + */ + void SetEncryptKeySchedule(const TDesC8& aKey, TUint32* aKeySchedule); + + /** + Setup the key schedule for decryption + @param aKey The input key + @param aKeySchedule The pointer to the key schedule buffer + */ + void SetDecryptKeySchedule(const TDesC8& aKey, TUint32* aKeySchedule); + + // From CSymmetricBlockCipherImpl + void TransformEncrypt(TUint8* aBuffer, TUint aNumBlocks); + void TransformDecrypt(TUint8* aBuffer, TUint aNumBlocks); + + private: + + /** + The key-schedule size in WORDS + + The maximum size is (((KAESMaxBlockSize/4)+6)+1)*4 + */ + static const TUint32 KKeyScheduleSize = 60; + + /// the key schedule + TUint32 iK[KKeyScheduleSize]; + + TInt iRounds; + }; + } + +#endif //__RIJNDAELIMPL_H__ diff -r 7e3f204e6c81 -r f9c11be8c0b3 cryptoplugins/cryptospiplugins/source/softwarecrypto/rijndaeltables.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/cryptoplugins/cryptospiplugins/source/softwarecrypto/rijndaeltables.h Tue Dec 01 11:12:04 2009 +0000 @@ -0,0 +1,723 @@ +/* +* Copyright (c) 2002-2009 Nokia Corporation and/or its subsidiary(-ies). +* All rights reserved. +* This component and the accompanying materials are made available +* under the terms of the License "Eclipse Public License v1.0" +* which accompanies this distribution, and is available +* at the URL "http://www.eclipse.org/legal/epl-v10.html". +* +* Initial Contributors: +* Nokia Corporation - initial contribution. +* +* Contributors: +* +* Description: +* +*/ + + +/** + @file + @internalComponent + @released +*/ + +#ifndef __RIJNDAELTABLES_H__ +#define __RIJNDAELTABLES_H__ + +#include + +namespace RIJNDAEL_TABLE +{ + +/* +Te0[x] = S [x].[02, 01, 01, 03]; +Te1[x] = S [x].[03, 02, 01, 01]; +Te2[x] = S [x].[01, 03, 02, 01]; +Te3[x] = S [x].[01, 01, 03, 02]; +Te4[x] = S [x].[01, 01, 01, 01]; + +Td0[x] = Si[x].[0e, 09, 0d, 0b]; +Td1[x] = Si[x].[0b, 0e, 09, 0d]; +Td2[x] = Si[x].[0d, 0b, 0e, 09]; +Td3[x] = Si[x].[09, 0d, 0b, 0e]; +Td4[x] = Si[x].[01, 01, 01, 01]; +*/ + +const TUint32 Te0[256] = { + 0xc66363a5U, 0xf87c7c84U, 0xee777799U, 0xf67b7b8dU, + 0xfff2f20dU, 0xd66b6bbdU, 0xde6f6fb1U, 0x91c5c554U, + 0x60303050U, 0x02010103U, 0xce6767a9U, 0x562b2b7dU, + 0xe7fefe19U, 0xb5d7d762U, 0x4dababe6U, 0xec76769aU, + 0x8fcaca45U, 0x1f82829dU, 0x89c9c940U, 0xfa7d7d87U, + 0xeffafa15U, 0xb25959ebU, 0x8e4747c9U, 0xfbf0f00bU, + 0x41adadecU, 0xb3d4d467U, 0x5fa2a2fdU, 0x45afafeaU, + 0x239c9cbfU, 0x53a4a4f7U, 0xe4727296U, 0x9bc0c05bU, + 0x75b7b7c2U, 0xe1fdfd1cU, 0x3d9393aeU, 0x4c26266aU, + 0x6c36365aU, 0x7e3f3f41U, 0xf5f7f702U, 0x83cccc4fU, + 0x6834345cU, 0x51a5a5f4U, 0xd1e5e534U, 0xf9f1f108U, + 0xe2717193U, 0xabd8d873U, 0x62313153U, 0x2a15153fU, + 0x0804040cU, 0x95c7c752U, 0x46232365U, 0x9dc3c35eU, + 0x30181828U, 0x379696a1U, 0x0a05050fU, 0x2f9a9ab5U, + 0x0e070709U, 0x24121236U, 0x1b80809bU, 0xdfe2e23dU, + 0xcdebeb26U, 0x4e272769U, 0x7fb2b2cdU, 0xea75759fU, + 0x1209091bU, 0x1d83839eU, 0x582c2c74U, 0x341a1a2eU, + 0x361b1b2dU, 0xdc6e6eb2U, 0xb45a5aeeU, 0x5ba0a0fbU, + 0xa45252f6U, 0x763b3b4dU, 0xb7d6d661U, 0x7db3b3ceU, + 0x5229297bU, 0xdde3e33eU, 0x5e2f2f71U, 0x13848497U, + 0xa65353f5U, 0xb9d1d168U, 0x00000000U, 0xc1eded2cU, + 0x40202060U, 0xe3fcfc1fU, 0x79b1b1c8U, 0xb65b5bedU, + 0xd46a6abeU, 0x8dcbcb46U, 0x67bebed9U, 0x7239394bU, + 0x944a4adeU, 0x984c4cd4U, 0xb05858e8U, 0x85cfcf4aU, + 0xbbd0d06bU, 0xc5efef2aU, 0x4faaaae5U, 0xedfbfb16U, + 0x864343c5U, 0x9a4d4dd7U, 0x66333355U, 0x11858594U, + 0x8a4545cfU, 0xe9f9f910U, 0x04020206U, 0xfe7f7f81U, + 0xa05050f0U, 0x783c3c44U, 0x259f9fbaU, 0x4ba8a8e3U, + 0xa25151f3U, 0x5da3a3feU, 0x804040c0U, 0x058f8f8aU, + 0x3f9292adU, 0x219d9dbcU, 0x70383848U, 0xf1f5f504U, + 0x63bcbcdfU, 0x77b6b6c1U, 0xafdada75U, 0x42212163U, + 0x20101030U, 0xe5ffff1aU, 0xfdf3f30eU, 0xbfd2d26dU, + 0x81cdcd4cU, 0x180c0c14U, 0x26131335U, 0xc3ecec2fU, + 0xbe5f5fe1U, 0x359797a2U, 0x884444ccU, 0x2e171739U, + 0x93c4c457U, 0x55a7a7f2U, 0xfc7e7e82U, 0x7a3d3d47U, + 0xc86464acU, 0xba5d5de7U, 0x3219192bU, 0xe6737395U, + 0xc06060a0U, 0x19818198U, 0x9e4f4fd1U, 0xa3dcdc7fU, + 0x44222266U, 0x542a2a7eU, 0x3b9090abU, 0x0b888883U, + 0x8c4646caU, 0xc7eeee29U, 0x6bb8b8d3U, 0x2814143cU, + 0xa7dede79U, 0xbc5e5ee2U, 0x160b0b1dU, 0xaddbdb76U, + 0xdbe0e03bU, 0x64323256U, 0x743a3a4eU, 0x140a0a1eU, + 0x924949dbU, 0x0c06060aU, 0x4824246cU, 0xb85c5ce4U, + 0x9fc2c25dU, 0xbdd3d36eU, 0x43acacefU, 0xc46262a6U, + 0x399191a8U, 0x319595a4U, 0xd3e4e437U, 0xf279798bU, + 0xd5e7e732U, 0x8bc8c843U, 0x6e373759U, 0xda6d6db7U, + 0x018d8d8cU, 0xb1d5d564U, 0x9c4e4ed2U, 0x49a9a9e0U, + 0xd86c6cb4U, 0xac5656faU, 0xf3f4f407U, 0xcfeaea25U, + 0xca6565afU, 0xf47a7a8eU, 0x47aeaee9U, 0x10080818U, + 0x6fbabad5U, 0xf0787888U, 0x4a25256fU, 0x5c2e2e72U, + 0x381c1c24U, 0x57a6a6f1U, 0x73b4b4c7U, 0x97c6c651U, + 0xcbe8e823U, 0xa1dddd7cU, 0xe874749cU, 0x3e1f1f21U, + 0x964b4bddU, 0x61bdbddcU, 0x0d8b8b86U, 0x0f8a8a85U, + 0xe0707090U, 0x7c3e3e42U, 0x71b5b5c4U, 0xcc6666aaU, + 0x904848d8U, 0x06030305U, 0xf7f6f601U, 0x1c0e0e12U, + 0xc26161a3U, 0x6a35355fU, 0xae5757f9U, 0x69b9b9d0U, + 0x17868691U, 0x99c1c158U, 0x3a1d1d27U, 0x279e9eb9U, + 0xd9e1e138U, 0xebf8f813U, 0x2b9898b3U, 0x22111133U, + 0xd26969bbU, 0xa9d9d970U, 0x078e8e89U, 0x339494a7U, + 0x2d9b9bb6U, 0x3c1e1e22U, 0x15878792U, 0xc9e9e920U, + 0x87cece49U, 0xaa5555ffU, 0x50282878U, 0xa5dfdf7aU, + 0x038c8c8fU, 0x59a1a1f8U, 0x09898980U, 0x1a0d0d17U, + 0x65bfbfdaU, 0xd7e6e631U, 0x844242c6U, 0xd06868b8U, + 0x824141c3U, 0x299999b0U, 0x5a2d2d77U, 0x1e0f0f11U, + 0x7bb0b0cbU, 0xa85454fcU, 0x6dbbbbd6U, 0x2c16163aU, +}; +const TUint32 Te1[256] = { + 0xa5c66363U, 0x84f87c7cU, 0x99ee7777U, 0x8df67b7bU, + 0x0dfff2f2U, 0xbdd66b6bU, 0xb1de6f6fU, 0x5491c5c5U, + 0x50603030U, 0x03020101U, 0xa9ce6767U, 0x7d562b2bU, + 0x19e7fefeU, 0x62b5d7d7U, 0xe64dababU, 0x9aec7676U, + 0x458fcacaU, 0x9d1f8282U, 0x4089c9c9U, 0x87fa7d7dU, + 0x15effafaU, 0xebb25959U, 0xc98e4747U, 0x0bfbf0f0U, + 0xec41adadU, 0x67b3d4d4U, 0xfd5fa2a2U, 0xea45afafU, + 0xbf239c9cU, 0xf753a4a4U, 0x96e47272U, 0x5b9bc0c0U, + 0xc275b7b7U, 0x1ce1fdfdU, 0xae3d9393U, 0x6a4c2626U, + 0x5a6c3636U, 0x417e3f3fU, 0x02f5f7f7U, 0x4f83ccccU, + 0x5c683434U, 0xf451a5a5U, 0x34d1e5e5U, 0x08f9f1f1U, + 0x93e27171U, 0x73abd8d8U, 0x53623131U, 0x3f2a1515U, + 0x0c080404U, 0x5295c7c7U, 0x65462323U, 0x5e9dc3c3U, + 0x28301818U, 0xa1379696U, 0x0f0a0505U, 0xb52f9a9aU, + 0x090e0707U, 0x36241212U, 0x9b1b8080U, 0x3ddfe2e2U, + 0x26cdebebU, 0x694e2727U, 0xcd7fb2b2U, 0x9fea7575U, + 0x1b120909U, 0x9e1d8383U, 0x74582c2cU, 0x2e341a1aU, + 0x2d361b1bU, 0xb2dc6e6eU, 0xeeb45a5aU, 0xfb5ba0a0U, + 0xf6a45252U, 0x4d763b3bU, 0x61b7d6d6U, 0xce7db3b3U, + 0x7b522929U, 0x3edde3e3U, 0x715e2f2fU, 0x97138484U, + 0xf5a65353U, 0x68b9d1d1U, 0x00000000U, 0x2cc1ededU, + 0x60402020U, 0x1fe3fcfcU, 0xc879b1b1U, 0xedb65b5bU, + 0xbed46a6aU, 0x468dcbcbU, 0xd967bebeU, 0x4b723939U, + 0xde944a4aU, 0xd4984c4cU, 0xe8b05858U, 0x4a85cfcfU, + 0x6bbbd0d0U, 0x2ac5efefU, 0xe54faaaaU, 0x16edfbfbU, + 0xc5864343U, 0xd79a4d4dU, 0x55663333U, 0x94118585U, + 0xcf8a4545U, 0x10e9f9f9U, 0x06040202U, 0x81fe7f7fU, + 0xf0a05050U, 0x44783c3cU, 0xba259f9fU, 0xe34ba8a8U, + 0xf3a25151U, 0xfe5da3a3U, 0xc0804040U, 0x8a058f8fU, + 0xad3f9292U, 0xbc219d9dU, 0x48703838U, 0x04f1f5f5U, + 0xdf63bcbcU, 0xc177b6b6U, 0x75afdadaU, 0x63422121U, + 0x30201010U, 0x1ae5ffffU, 0x0efdf3f3U, 0x6dbfd2d2U, + 0x4c81cdcdU, 0x14180c0cU, 0x35261313U, 0x2fc3ececU, + 0xe1be5f5fU, 0xa2359797U, 0xcc884444U, 0x392e1717U, + 0x5793c4c4U, 0xf255a7a7U, 0x82fc7e7eU, 0x477a3d3dU, + 0xacc86464U, 0xe7ba5d5dU, 0x2b321919U, 0x95e67373U, + 0xa0c06060U, 0x98198181U, 0xd19e4f4fU, 0x7fa3dcdcU, + 0x66442222U, 0x7e542a2aU, 0xab3b9090U, 0x830b8888U, + 0xca8c4646U, 0x29c7eeeeU, 0xd36bb8b8U, 0x3c281414U, + 0x79a7dedeU, 0xe2bc5e5eU, 0x1d160b0bU, 0x76addbdbU, + 0x3bdbe0e0U, 0x56643232U, 0x4e743a3aU, 0x1e140a0aU, + 0xdb924949U, 0x0a0c0606U, 0x6c482424U, 0xe4b85c5cU, + 0x5d9fc2c2U, 0x6ebdd3d3U, 0xef43acacU, 0xa6c46262U, + 0xa8399191U, 0xa4319595U, 0x37d3e4e4U, 0x8bf27979U, + 0x32d5e7e7U, 0x438bc8c8U, 0x596e3737U, 0xb7da6d6dU, + 0x8c018d8dU, 0x64b1d5d5U, 0xd29c4e4eU, 0xe049a9a9U, + 0xb4d86c6cU, 0xfaac5656U, 0x07f3f4f4U, 0x25cfeaeaU, + 0xafca6565U, 0x8ef47a7aU, 0xe947aeaeU, 0x18100808U, + 0xd56fbabaU, 0x88f07878U, 0x6f4a2525U, 0x725c2e2eU, + 0x24381c1cU, 0xf157a6a6U, 0xc773b4b4U, 0x5197c6c6U, + 0x23cbe8e8U, 0x7ca1ddddU, 0x9ce87474U, 0x213e1f1fU, + 0xdd964b4bU, 0xdc61bdbdU, 0x860d8b8bU, 0x850f8a8aU, + 0x90e07070U, 0x427c3e3eU, 0xc471b5b5U, 0xaacc6666U, + 0xd8904848U, 0x05060303U, 0x01f7f6f6U, 0x121c0e0eU, + 0xa3c26161U, 0x5f6a3535U, 0xf9ae5757U, 0xd069b9b9U, + 0x91178686U, 0x5899c1c1U, 0x273a1d1dU, 0xb9279e9eU, + 0x38d9e1e1U, 0x13ebf8f8U, 0xb32b9898U, 0x33221111U, + 0xbbd26969U, 0x70a9d9d9U, 0x89078e8eU, 0xa7339494U, + 0xb62d9b9bU, 0x223c1e1eU, 0x92158787U, 0x20c9e9e9U, + 0x4987ceceU, 0xffaa5555U, 0x78502828U, 0x7aa5dfdfU, + 0x8f038c8cU, 0xf859a1a1U, 0x80098989U, 0x171a0d0dU, + 0xda65bfbfU, 0x31d7e6e6U, 0xc6844242U, 0xb8d06868U, + 0xc3824141U, 0xb0299999U, 0x775a2d2dU, 0x111e0f0fU, + 0xcb7bb0b0U, 0xfca85454U, 0xd66dbbbbU, 0x3a2c1616U, +}; +const TUint32 Te2[256] = { + 0x63a5c663U, 0x7c84f87cU, 0x7799ee77U, 0x7b8df67bU, + 0xf20dfff2U, 0x6bbdd66bU, 0x6fb1de6fU, 0xc55491c5U, + 0x30506030U, 0x01030201U, 0x67a9ce67U, 0x2b7d562bU, + 0xfe19e7feU, 0xd762b5d7U, 0xabe64dabU, 0x769aec76U, + 0xca458fcaU, 0x829d1f82U, 0xc94089c9U, 0x7d87fa7dU, + 0xfa15effaU, 0x59ebb259U, 0x47c98e47U, 0xf00bfbf0U, + 0xadec41adU, 0xd467b3d4U, 0xa2fd5fa2U, 0xafea45afU, + 0x9cbf239cU, 0xa4f753a4U, 0x7296e472U, 0xc05b9bc0U, + 0xb7c275b7U, 0xfd1ce1fdU, 0x93ae3d93U, 0x266a4c26U, + 0x365a6c36U, 0x3f417e3fU, 0xf702f5f7U, 0xcc4f83ccU, + 0x345c6834U, 0xa5f451a5U, 0xe534d1e5U, 0xf108f9f1U, + 0x7193e271U, 0xd873abd8U, 0x31536231U, 0x153f2a15U, + 0x040c0804U, 0xc75295c7U, 0x23654623U, 0xc35e9dc3U, + 0x18283018U, 0x96a13796U, 0x050f0a05U, 0x9ab52f9aU, + 0x07090e07U, 0x12362412U, 0x809b1b80U, 0xe23ddfe2U, + 0xeb26cdebU, 0x27694e27U, 0xb2cd7fb2U, 0x759fea75U, + 0x091b1209U, 0x839e1d83U, 0x2c74582cU, 0x1a2e341aU, + 0x1b2d361bU, 0x6eb2dc6eU, 0x5aeeb45aU, 0xa0fb5ba0U, + 0x52f6a452U, 0x3b4d763bU, 0xd661b7d6U, 0xb3ce7db3U, + 0x297b5229U, 0xe33edde3U, 0x2f715e2fU, 0x84971384U, + 0x53f5a653U, 0xd168b9d1U, 0x00000000U, 0xed2cc1edU, + 0x20604020U, 0xfc1fe3fcU, 0xb1c879b1U, 0x5bedb65bU, + 0x6abed46aU, 0xcb468dcbU, 0xbed967beU, 0x394b7239U, + 0x4ade944aU, 0x4cd4984cU, 0x58e8b058U, 0xcf4a85cfU, + 0xd06bbbd0U, 0xef2ac5efU, 0xaae54faaU, 0xfb16edfbU, + 0x43c58643U, 0x4dd79a4dU, 0x33556633U, 0x85941185U, + 0x45cf8a45U, 0xf910e9f9U, 0x02060402U, 0x7f81fe7fU, + 0x50f0a050U, 0x3c44783cU, 0x9fba259fU, 0xa8e34ba8U, + 0x51f3a251U, 0xa3fe5da3U, 0x40c08040U, 0x8f8a058fU, + 0x92ad3f92U, 0x9dbc219dU, 0x38487038U, 0xf504f1f5U, + 0xbcdf63bcU, 0xb6c177b6U, 0xda75afdaU, 0x21634221U, + 0x10302010U, 0xff1ae5ffU, 0xf30efdf3U, 0xd26dbfd2U, + 0xcd4c81cdU, 0x0c14180cU, 0x13352613U, 0xec2fc3ecU, + 0x5fe1be5fU, 0x97a23597U, 0x44cc8844U, 0x17392e17U, + 0xc45793c4U, 0xa7f255a7U, 0x7e82fc7eU, 0x3d477a3dU, + 0x64acc864U, 0x5de7ba5dU, 0x192b3219U, 0x7395e673U, + 0x60a0c060U, 0x81981981U, 0x4fd19e4fU, 0xdc7fa3dcU, + 0x22664422U, 0x2a7e542aU, 0x90ab3b90U, 0x88830b88U, + 0x46ca8c46U, 0xee29c7eeU, 0xb8d36bb8U, 0x143c2814U, + 0xde79a7deU, 0x5ee2bc5eU, 0x0b1d160bU, 0xdb76addbU, + 0xe03bdbe0U, 0x32566432U, 0x3a4e743aU, 0x0a1e140aU, + 0x49db9249U, 0x060a0c06U, 0x246c4824U, 0x5ce4b85cU, + 0xc25d9fc2U, 0xd36ebdd3U, 0xacef43acU, 0x62a6c462U, + 0x91a83991U, 0x95a43195U, 0xe437d3e4U, 0x798bf279U, + 0xe732d5e7U, 0xc8438bc8U, 0x37596e37U, 0x6db7da6dU, + 0x8d8c018dU, 0xd564b1d5U, 0x4ed29c4eU, 0xa9e049a9U, + 0x6cb4d86cU, 0x56faac56U, 0xf407f3f4U, 0xea25cfeaU, + 0x65afca65U, 0x7a8ef47aU, 0xaee947aeU, 0x08181008U, + 0xbad56fbaU, 0x7888f078U, 0x256f4a25U, 0x2e725c2eU, + 0x1c24381cU, 0xa6f157a6U, 0xb4c773b4U, 0xc65197c6U, + 0xe823cbe8U, 0xdd7ca1ddU, 0x749ce874U, 0x1f213e1fU, + 0x4bdd964bU, 0xbddc61bdU, 0x8b860d8bU, 0x8a850f8aU, + 0x7090e070U, 0x3e427c3eU, 0xb5c471b5U, 0x66aacc66U, + 0x48d89048U, 0x03050603U, 0xf601f7f6U, 0x0e121c0eU, + 0x61a3c261U, 0x355f6a35U, 0x57f9ae57U, 0xb9d069b9U, + 0x86911786U, 0xc15899c1U, 0x1d273a1dU, 0x9eb9279eU, + 0xe138d9e1U, 0xf813ebf8U, 0x98b32b98U, 0x11332211U, + 0x69bbd269U, 0xd970a9d9U, 0x8e89078eU, 0x94a73394U, + 0x9bb62d9bU, 0x1e223c1eU, 0x87921587U, 0xe920c9e9U, + 0xce4987ceU, 0x55ffaa55U, 0x28785028U, 0xdf7aa5dfU, + 0x8c8f038cU, 0xa1f859a1U, 0x89800989U, 0x0d171a0dU, + 0xbfda65bfU, 0xe631d7e6U, 0x42c68442U, 0x68b8d068U, + 0x41c38241U, 0x99b02999U, 0x2d775a2dU, 0x0f111e0fU, + 0xb0cb7bb0U, 0x54fca854U, 0xbbd66dbbU, 0x163a2c16U, +}; + +const TUint32 Te3[256] = { + 0x6363a5c6U, 0x7c7c84f8U, 0x777799eeU, 0x7b7b8df6U, + 0xf2f20dffU, 0x6b6bbdd6U, 0x6f6fb1deU, 0xc5c55491U, + 0x30305060U, 0x01010302U, 0x6767a9ceU, 0x2b2b7d56U, + 0xfefe19e7U, 0xd7d762b5U, 0xababe64dU, 0x76769aecU, + 0xcaca458fU, 0x82829d1fU, 0xc9c94089U, 0x7d7d87faU, + 0xfafa15efU, 0x5959ebb2U, 0x4747c98eU, 0xf0f00bfbU, + 0xadadec41U, 0xd4d467b3U, 0xa2a2fd5fU, 0xafafea45U, + 0x9c9cbf23U, 0xa4a4f753U, 0x727296e4U, 0xc0c05b9bU, + 0xb7b7c275U, 0xfdfd1ce1U, 0x9393ae3dU, 0x26266a4cU, + 0x36365a6cU, 0x3f3f417eU, 0xf7f702f5U, 0xcccc4f83U, + 0x34345c68U, 0xa5a5f451U, 0xe5e534d1U, 0xf1f108f9U, + 0x717193e2U, 0xd8d873abU, 0x31315362U, 0x15153f2aU, + 0x04040c08U, 0xc7c75295U, 0x23236546U, 0xc3c35e9dU, + 0x18182830U, 0x9696a137U, 0x05050f0aU, 0x9a9ab52fU, + 0x0707090eU, 0x12123624U, 0x80809b1bU, 0xe2e23ddfU, + 0xebeb26cdU, 0x2727694eU, 0xb2b2cd7fU, 0x75759feaU, + 0x09091b12U, 0x83839e1dU, 0x2c2c7458U, 0x1a1a2e34U, + 0x1b1b2d36U, 0x6e6eb2dcU, 0x5a5aeeb4U, 0xa0a0fb5bU, + 0x5252f6a4U, 0x3b3b4d76U, 0xd6d661b7U, 0xb3b3ce7dU, + 0x29297b52U, 0xe3e33eddU, 0x2f2f715eU, 0x84849713U, + 0x5353f5a6U, 0xd1d168b9U, 0x00000000U, 0xeded2cc1U, + 0x20206040U, 0xfcfc1fe3U, 0xb1b1c879U, 0x5b5bedb6U, + 0x6a6abed4U, 0xcbcb468dU, 0xbebed967U, 0x39394b72U, + 0x4a4ade94U, 0x4c4cd498U, 0x5858e8b0U, 0xcfcf4a85U, + 0xd0d06bbbU, 0xefef2ac5U, 0xaaaae54fU, 0xfbfb16edU, + 0x4343c586U, 0x4d4dd79aU, 0x33335566U, 0x85859411U, + 0x4545cf8aU, 0xf9f910e9U, 0x02020604U, 0x7f7f81feU, + 0x5050f0a0U, 0x3c3c4478U, 0x9f9fba25U, 0xa8a8e34bU, + 0x5151f3a2U, 0xa3a3fe5dU, 0x4040c080U, 0x8f8f8a05U, + 0x9292ad3fU, 0x9d9dbc21U, 0x38384870U, 0xf5f504f1U, + 0xbcbcdf63U, 0xb6b6c177U, 0xdada75afU, 0x21216342U, + 0x10103020U, 0xffff1ae5U, 0xf3f30efdU, 0xd2d26dbfU, + 0xcdcd4c81U, 0x0c0c1418U, 0x13133526U, 0xecec2fc3U, + 0x5f5fe1beU, 0x9797a235U, 0x4444cc88U, 0x1717392eU, + 0xc4c45793U, 0xa7a7f255U, 0x7e7e82fcU, 0x3d3d477aU, + 0x6464acc8U, 0x5d5de7baU, 0x19192b32U, 0x737395e6U, + 0x6060a0c0U, 0x81819819U, 0x4f4fd19eU, 0xdcdc7fa3U, + 0x22226644U, 0x2a2a7e54U, 0x9090ab3bU, 0x8888830bU, + 0x4646ca8cU, 0xeeee29c7U, 0xb8b8d36bU, 0x14143c28U, + 0xdede79a7U, 0x5e5ee2bcU, 0x0b0b1d16U, 0xdbdb76adU, + 0xe0e03bdbU, 0x32325664U, 0x3a3a4e74U, 0x0a0a1e14U, + 0x4949db92U, 0x06060a0cU, 0x24246c48U, 0x5c5ce4b8U, + 0xc2c25d9fU, 0xd3d36ebdU, 0xacacef43U, 0x6262a6c4U, + 0x9191a839U, 0x9595a431U, 0xe4e437d3U, 0x79798bf2U, + 0xe7e732d5U, 0xc8c8438bU, 0x3737596eU, 0x6d6db7daU, + 0x8d8d8c01U, 0xd5d564b1U, 0x4e4ed29cU, 0xa9a9e049U, + 0x6c6cb4d8U, 0x5656faacU, 0xf4f407f3U, 0xeaea25cfU, + 0x6565afcaU, 0x7a7a8ef4U, 0xaeaee947U, 0x08081810U, + 0xbabad56fU, 0x787888f0U, 0x25256f4aU, 0x2e2e725cU, + 0x1c1c2438U, 0xa6a6f157U, 0xb4b4c773U, 0xc6c65197U, + 0xe8e823cbU, 0xdddd7ca1U, 0x74749ce8U, 0x1f1f213eU, + 0x4b4bdd96U, 0xbdbddc61U, 0x8b8b860dU, 0x8a8a850fU, + 0x707090e0U, 0x3e3e427cU, 0xb5b5c471U, 0x6666aaccU, + 0x4848d890U, 0x03030506U, 0xf6f601f7U, 0x0e0e121cU, + 0x6161a3c2U, 0x35355f6aU, 0x5757f9aeU, 0xb9b9d069U, + 0x86869117U, 0xc1c15899U, 0x1d1d273aU, 0x9e9eb927U, + 0xe1e138d9U, 0xf8f813ebU, 0x9898b32bU, 0x11113322U, + 0x6969bbd2U, 0xd9d970a9U, 0x8e8e8907U, 0x9494a733U, + 0x9b9bb62dU, 0x1e1e223cU, 0x87879215U, 0xe9e920c9U, + 0xcece4987U, 0x5555ffaaU, 0x28287850U, 0xdfdf7aa5U, + 0x8c8c8f03U, 0xa1a1f859U, 0x89898009U, 0x0d0d171aU, + 0xbfbfda65U, 0xe6e631d7U, 0x4242c684U, 0x6868b8d0U, + 0x4141c382U, 0x9999b029U, 0x2d2d775aU, 0x0f0f111eU, + 0xb0b0cb7bU, 0x5454fca8U, 0xbbbbd66dU, 0x16163a2cU, +}; + +const TUint32 Te4[256] = { + 0x63636363U, 0x7c7c7c7cU, 0x77777777U, 0x7b7b7b7bU, + 0xf2f2f2f2U, 0x6b6b6b6bU, 0x6f6f6f6fU, 0xc5c5c5c5U, + 0x30303030U, 0x01010101U, 0x67676767U, 0x2b2b2b2bU, + 0xfefefefeU, 0xd7d7d7d7U, 0xababababU, 0x76767676U, + 0xcacacacaU, 0x82828282U, 0xc9c9c9c9U, 0x7d7d7d7dU, + 0xfafafafaU, 0x59595959U, 0x47474747U, 0xf0f0f0f0U, + 0xadadadadU, 0xd4d4d4d4U, 0xa2a2a2a2U, 0xafafafafU, + 0x9c9c9c9cU, 0xa4a4a4a4U, 0x72727272U, 0xc0c0c0c0U, + 0xb7b7b7b7U, 0xfdfdfdfdU, 0x93939393U, 0x26262626U, + 0x36363636U, 0x3f3f3f3fU, 0xf7f7f7f7U, 0xccccccccU, + 0x34343434U, 0xa5a5a5a5U, 0xe5e5e5e5U, 0xf1f1f1f1U, + 0x71717171U, 0xd8d8d8d8U, 0x31313131U, 0x15151515U, + 0x04040404U, 0xc7c7c7c7U, 0x23232323U, 0xc3c3c3c3U, + 0x18181818U, 0x96969696U, 0x05050505U, 0x9a9a9a9aU, + 0x07070707U, 0x12121212U, 0x80808080U, 0xe2e2e2e2U, + 0xebebebebU, 0x27272727U, 0xb2b2b2b2U, 0x75757575U, + 0x09090909U, 0x83838383U, 0x2c2c2c2cU, 0x1a1a1a1aU, + 0x1b1b1b1bU, 0x6e6e6e6eU, 0x5a5a5a5aU, 0xa0a0a0a0U, + 0x52525252U, 0x3b3b3b3bU, 0xd6d6d6d6U, 0xb3b3b3b3U, + 0x29292929U, 0xe3e3e3e3U, 0x2f2f2f2fU, 0x84848484U, + 0x53535353U, 0xd1d1d1d1U, 0x00000000U, 0xededededU, + 0x20202020U, 0xfcfcfcfcU, 0xb1b1b1b1U, 0x5b5b5b5bU, + 0x6a6a6a6aU, 0xcbcbcbcbU, 0xbebebebeU, 0x39393939U, + 0x4a4a4a4aU, 0x4c4c4c4cU, 0x58585858U, 0xcfcfcfcfU, + 0xd0d0d0d0U, 0xefefefefU, 0xaaaaaaaaU, 0xfbfbfbfbU, + 0x43434343U, 0x4d4d4d4dU, 0x33333333U, 0x85858585U, + 0x45454545U, 0xf9f9f9f9U, 0x02020202U, 0x7f7f7f7fU, + 0x50505050U, 0x3c3c3c3cU, 0x9f9f9f9fU, 0xa8a8a8a8U, + 0x51515151U, 0xa3a3a3a3U, 0x40404040U, 0x8f8f8f8fU, + 0x92929292U, 0x9d9d9d9dU, 0x38383838U, 0xf5f5f5f5U, + 0xbcbcbcbcU, 0xb6b6b6b6U, 0xdadadadaU, 0x21212121U, + 0x10101010U, 0xffffffffU, 0xf3f3f3f3U, 0xd2d2d2d2U, + 0xcdcdcdcdU, 0x0c0c0c0cU, 0x13131313U, 0xececececU, + 0x5f5f5f5fU, 0x97979797U, 0x44444444U, 0x17171717U, + 0xc4c4c4c4U, 0xa7a7a7a7U, 0x7e7e7e7eU, 0x3d3d3d3dU, + 0x64646464U, 0x5d5d5d5dU, 0x19191919U, 0x73737373U, + 0x60606060U, 0x81818181U, 0x4f4f4f4fU, 0xdcdcdcdcU, + 0x22222222U, 0x2a2a2a2aU, 0x90909090U, 0x88888888U, + 0x46464646U, 0xeeeeeeeeU, 0xb8b8b8b8U, 0x14141414U, + 0xdedededeU, 0x5e5e5e5eU, 0x0b0b0b0bU, 0xdbdbdbdbU, + 0xe0e0e0e0U, 0x32323232U, 0x3a3a3a3aU, 0x0a0a0a0aU, + 0x49494949U, 0x06060606U, 0x24242424U, 0x5c5c5c5cU, + 0xc2c2c2c2U, 0xd3d3d3d3U, 0xacacacacU, 0x62626262U, + 0x91919191U, 0x95959595U, 0xe4e4e4e4U, 0x79797979U, + 0xe7e7e7e7U, 0xc8c8c8c8U, 0x37373737U, 0x6d6d6d6dU, + 0x8d8d8d8dU, 0xd5d5d5d5U, 0x4e4e4e4eU, 0xa9a9a9a9U, + 0x6c6c6c6cU, 0x56565656U, 0xf4f4f4f4U, 0xeaeaeaeaU, + 0x65656565U, 0x7a7a7a7aU, 0xaeaeaeaeU, 0x08080808U, + 0xbabababaU, 0x78787878U, 0x25252525U, 0x2e2e2e2eU, + 0x1c1c1c1cU, 0xa6a6a6a6U, 0xb4b4b4b4U, 0xc6c6c6c6U, + 0xe8e8e8e8U, 0xddddddddU, 0x74747474U, 0x1f1f1f1fU, + 0x4b4b4b4bU, 0xbdbdbdbdU, 0x8b8b8b8bU, 0x8a8a8a8aU, + 0x70707070U, 0x3e3e3e3eU, 0xb5b5b5b5U, 0x66666666U, + 0x48484848U, 0x03030303U, 0xf6f6f6f6U, 0x0e0e0e0eU, + 0x61616161U, 0x35353535U, 0x57575757U, 0xb9b9b9b9U, + 0x86868686U, 0xc1c1c1c1U, 0x1d1d1d1dU, 0x9e9e9e9eU, + 0xe1e1e1e1U, 0xf8f8f8f8U, 0x98989898U, 0x11111111U, + 0x69696969U, 0xd9d9d9d9U, 0x8e8e8e8eU, 0x94949494U, + 0x9b9b9b9bU, 0x1e1e1e1eU, 0x87878787U, 0xe9e9e9e9U, + 0xcecececeU, 0x55555555U, 0x28282828U, 0xdfdfdfdfU, + 0x8c8c8c8cU, 0xa1a1a1a1U, 0x89898989U, 0x0d0d0d0dU, + 0xbfbfbfbfU, 0xe6e6e6e6U, 0x42424242U, 0x68686868U, + 0x41414141U, 0x99999999U, 0x2d2d2d2dU, 0x0f0f0f0fU, + 0xb0b0b0b0U, 0x54545454U, 0xbbbbbbbbU, 0x16161616U, +}; + +const TUint32 Td0[256] = { + 0x51f4a750U, 0x7e416553U, 0x1a17a4c3U, 0x3a275e96U, + 0x3bab6bcbU, 0x1f9d45f1U, 0xacfa58abU, 0x4be30393U, + 0x2030fa55U, 0xad766df6U, 0x88cc7691U, 0xf5024c25U, + 0x4fe5d7fcU, 0xc52acbd7U, 0x26354480U, 0xb562a38fU, + 0xdeb15a49U, 0x25ba1b67U, 0x45ea0e98U, 0x5dfec0e1U, + 0xc32f7502U, 0x814cf012U, 0x8d4697a3U, 0x6bd3f9c6U, + 0x038f5fe7U, 0x15929c95U, 0xbf6d7aebU, 0x955259daU, + 0xd4be832dU, 0x587421d3U, 0x49e06929U, 0x8ec9c844U, + 0x75c2896aU, 0xf48e7978U, 0x99583e6bU, 0x27b971ddU, + 0xbee14fb6U, 0xf088ad17U, 0xc920ac66U, 0x7dce3ab4U, + 0x63df4a18U, 0xe51a3182U, 0x97513360U, 0x62537f45U, + 0xb16477e0U, 0xbb6bae84U, 0xfe81a01cU, 0xf9082b94U, + 0x70486858U, 0x8f45fd19U, 0x94de6c87U, 0x527bf8b7U, + 0xab73d323U, 0x724b02e2U, 0xe31f8f57U, 0x6655ab2aU, + 0xb2eb2807U, 0x2fb5c203U, 0x86c57b9aU, 0xd33708a5U, + 0x302887f2U, 0x23bfa5b2U, 0x02036abaU, 0xed16825cU, + 0x8acf1c2bU, 0xa779b492U, 0xf307f2f0U, 0x4e69e2a1U, + 0x65daf4cdU, 0x0605bed5U, 0xd134621fU, 0xc4a6fe8aU, + 0x342e539dU, 0xa2f355a0U, 0x058ae132U, 0xa4f6eb75U, + 0x0b83ec39U, 0x4060efaaU, 0x5e719f06U, 0xbd6e1051U, + 0x3e218af9U, 0x96dd063dU, 0xdd3e05aeU, 0x4de6bd46U, + 0x91548db5U, 0x71c45d05U, 0x0406d46fU, 0x605015ffU, + 0x1998fb24U, 0xd6bde997U, 0x894043ccU, 0x67d99e77U, + 0xb0e842bdU, 0x07898b88U, 0xe7195b38U, 0x79c8eedbU, + 0xa17c0a47U, 0x7c420fe9U, 0xf8841ec9U, 0x00000000U, + 0x09808683U, 0x322bed48U, 0x1e1170acU, 0x6c5a724eU, + 0xfd0efffbU, 0x0f853856U, 0x3daed51eU, 0x362d3927U, + 0x0a0fd964U, 0x685ca621U, 0x9b5b54d1U, 0x24362e3aU, + 0x0c0a67b1U, 0x9357e70fU, 0xb4ee96d2U, 0x1b9b919eU, + 0x80c0c54fU, 0x61dc20a2U, 0x5a774b69U, 0x1c121a16U, + 0xe293ba0aU, 0xc0a02ae5U, 0x3c22e043U, 0x121b171dU, + 0x0e090d0bU, 0xf28bc7adU, 0x2db6a8b9U, 0x141ea9c8U, + 0x57f11985U, 0xaf75074cU, 0xee99ddbbU, 0xa37f60fdU, + 0xf701269fU, 0x5c72f5bcU, 0x44663bc5U, 0x5bfb7e34U, + 0x8b432976U, 0xcb23c6dcU, 0xb6edfc68U, 0xb8e4f163U, + 0xd731dccaU, 0x42638510U, 0x13972240U, 0x84c61120U, + 0x854a247dU, 0xd2bb3df8U, 0xaef93211U, 0xc729a16dU, + 0x1d9e2f4bU, 0xdcb230f3U, 0x0d8652ecU, 0x77c1e3d0U, + 0x2bb3166cU, 0xa970b999U, 0x119448faU, 0x47e96422U, + 0xa8fc8cc4U, 0xa0f03f1aU, 0x567d2cd8U, 0x223390efU, + 0x87494ec7U, 0xd938d1c1U, 0x8ccaa2feU, 0x98d40b36U, + 0xa6f581cfU, 0xa57ade28U, 0xdab78e26U, 0x3fadbfa4U, + 0x2c3a9de4U, 0x5078920dU, 0x6a5fcc9bU, 0x547e4662U, + 0xf68d13c2U, 0x90d8b8e8U, 0x2e39f75eU, 0x82c3aff5U, + 0x9f5d80beU, 0x69d0937cU, 0x6fd52da9U, 0xcf2512b3U, + 0xc8ac993bU, 0x10187da7U, 0xe89c636eU, 0xdb3bbb7bU, + 0xcd267809U, 0x6e5918f4U, 0xec9ab701U, 0x834f9aa8U, + 0xe6956e65U, 0xaaffe67eU, 0x21bccf08U, 0xef15e8e6U, + 0xbae79bd9U, 0x4a6f36ceU, 0xea9f09d4U, 0x29b07cd6U, + 0x31a4b2afU, 0x2a3f2331U, 0xc6a59430U, 0x35a266c0U, + 0x744ebc37U, 0xfc82caa6U, 0xe090d0b0U, 0x33a7d815U, + 0xf104984aU, 0x41ecdaf7U, 0x7fcd500eU, 0x1791f62fU, + 0x764dd68dU, 0x43efb04dU, 0xccaa4d54U, 0xe49604dfU, + 0x9ed1b5e3U, 0x4c6a881bU, 0xc12c1fb8U, 0x4665517fU, + 0x9d5eea04U, 0x018c355dU, 0xfa877473U, 0xfb0b412eU, + 0xb3671d5aU, 0x92dbd252U, 0xe9105633U, 0x6dd64713U, + 0x9ad7618cU, 0x37a10c7aU, 0x59f8148eU, 0xeb133c89U, + 0xcea927eeU, 0xb761c935U, 0xe11ce5edU, 0x7a47b13cU, + 0x9cd2df59U, 0x55f2733fU, 0x1814ce79U, 0x73c737bfU, + 0x53f7cdeaU, 0x5ffdaa5bU, 0xdf3d6f14U, 0x7844db86U, + 0xcaaff381U, 0xb968c43eU, 0x3824342cU, 0xc2a3405fU, + 0x161dc372U, 0xbce2250cU, 0x283c498bU, 0xff0d9541U, + 0x39a80171U, 0x080cb3deU, 0xd8b4e49cU, 0x6456c190U, + 0x7bcb8461U, 0xd532b670U, 0x486c5c74U, 0xd0b85742U, +}; + +const TUint32 Td1[256] = { + 0x5051f4a7U, 0x537e4165U, 0xc31a17a4U, 0x963a275eU, + 0xcb3bab6bU, 0xf11f9d45U, 0xabacfa58U, 0x934be303U, + 0x552030faU, 0xf6ad766dU, 0x9188cc76U, 0x25f5024cU, + 0xfc4fe5d7U, 0xd7c52acbU, 0x80263544U, 0x8fb562a3U, + 0x49deb15aU, 0x6725ba1bU, 0x9845ea0eU, 0xe15dfec0U, + 0x02c32f75U, 0x12814cf0U, 0xa38d4697U, 0xc66bd3f9U, + 0xe7038f5fU, 0x9515929cU, 0xebbf6d7aU, 0xda955259U, + 0x2dd4be83U, 0xd3587421U, 0x2949e069U, 0x448ec9c8U, + 0x6a75c289U, 0x78f48e79U, 0x6b99583eU, 0xdd27b971U, + 0xb6bee14fU, 0x17f088adU, 0x66c920acU, 0xb47dce3aU, + 0x1863df4aU, 0x82e51a31U, 0x60975133U, 0x4562537fU, + 0xe0b16477U, 0x84bb6baeU, 0x1cfe81a0U, 0x94f9082bU, + 0x58704868U, 0x198f45fdU, 0x8794de6cU, 0xb7527bf8U, + 0x23ab73d3U, 0xe2724b02U, 0x57e31f8fU, 0x2a6655abU, + 0x07b2eb28U, 0x032fb5c2U, 0x9a86c57bU, 0xa5d33708U, + 0xf2302887U, 0xb223bfa5U, 0xba02036aU, 0x5ced1682U, + 0x2b8acf1cU, 0x92a779b4U, 0xf0f307f2U, 0xa14e69e2U, + 0xcd65daf4U, 0xd50605beU, 0x1fd13462U, 0x8ac4a6feU, + 0x9d342e53U, 0xa0a2f355U, 0x32058ae1U, 0x75a4f6ebU, + 0x390b83ecU, 0xaa4060efU, 0x065e719fU, 0x51bd6e10U, + 0xf93e218aU, 0x3d96dd06U, 0xaedd3e05U, 0x464de6bdU, + 0xb591548dU, 0x0571c45dU, 0x6f0406d4U, 0xff605015U, + 0x241998fbU, 0x97d6bde9U, 0xcc894043U, 0x7767d99eU, + 0xbdb0e842U, 0x8807898bU, 0x38e7195bU, 0xdb79c8eeU, + 0x47a17c0aU, 0xe97c420fU, 0xc9f8841eU, 0x00000000U, + 0x83098086U, 0x48322bedU, 0xac1e1170U, 0x4e6c5a72U, + 0xfbfd0effU, 0x560f8538U, 0x1e3daed5U, 0x27362d39U, + 0x640a0fd9U, 0x21685ca6U, 0xd19b5b54U, 0x3a24362eU, + 0xb10c0a67U, 0x0f9357e7U, 0xd2b4ee96U, 0x9e1b9b91U, + 0x4f80c0c5U, 0xa261dc20U, 0x695a774bU, 0x161c121aU, + 0x0ae293baU, 0xe5c0a02aU, 0x433c22e0U, 0x1d121b17U, + 0x0b0e090dU, 0xadf28bc7U, 0xb92db6a8U, 0xc8141ea9U, + 0x8557f119U, 0x4caf7507U, 0xbbee99ddU, 0xfda37f60U, + 0x9ff70126U, 0xbc5c72f5U, 0xc544663bU, 0x345bfb7eU, + 0x768b4329U, 0xdccb23c6U, 0x68b6edfcU, 0x63b8e4f1U, + 0xcad731dcU, 0x10426385U, 0x40139722U, 0x2084c611U, + 0x7d854a24U, 0xf8d2bb3dU, 0x11aef932U, 0x6dc729a1U, + 0x4b1d9e2fU, 0xf3dcb230U, 0xec0d8652U, 0xd077c1e3U, + 0x6c2bb316U, 0x99a970b9U, 0xfa119448U, 0x2247e964U, + 0xc4a8fc8cU, 0x1aa0f03fU, 0xd8567d2cU, 0xef223390U, + 0xc787494eU, 0xc1d938d1U, 0xfe8ccaa2U, 0x3698d40bU, + 0xcfa6f581U, 0x28a57adeU, 0x26dab78eU, 0xa43fadbfU, + 0xe42c3a9dU, 0x0d507892U, 0x9b6a5fccU, 0x62547e46U, + 0xc2f68d13U, 0xe890d8b8U, 0x5e2e39f7U, 0xf582c3afU, + 0xbe9f5d80U, 0x7c69d093U, 0xa96fd52dU, 0xb3cf2512U, + 0x3bc8ac99U, 0xa710187dU, 0x6ee89c63U, 0x7bdb3bbbU, + 0x09cd2678U, 0xf46e5918U, 0x01ec9ab7U, 0xa8834f9aU, + 0x65e6956eU, 0x7eaaffe6U, 0x0821bccfU, 0xe6ef15e8U, + 0xd9bae79bU, 0xce4a6f36U, 0xd4ea9f09U, 0xd629b07cU, + 0xaf31a4b2U, 0x312a3f23U, 0x30c6a594U, 0xc035a266U, + 0x37744ebcU, 0xa6fc82caU, 0xb0e090d0U, 0x1533a7d8U, + 0x4af10498U, 0xf741ecdaU, 0x0e7fcd50U, 0x2f1791f6U, + 0x8d764dd6U, 0x4d43efb0U, 0x54ccaa4dU, 0xdfe49604U, + 0xe39ed1b5U, 0x1b4c6a88U, 0xb8c12c1fU, 0x7f466551U, + 0x049d5eeaU, 0x5d018c35U, 0x73fa8774U, 0x2efb0b41U, + 0x5ab3671dU, 0x5292dbd2U, 0x33e91056U, 0x136dd647U, + 0x8c9ad761U, 0x7a37a10cU, 0x8e59f814U, 0x89eb133cU, + 0xeecea927U, 0x35b761c9U, 0xede11ce5U, 0x3c7a47b1U, + 0x599cd2dfU, 0x3f55f273U, 0x791814ceU, 0xbf73c737U, + 0xea53f7cdU, 0x5b5ffdaaU, 0x14df3d6fU, 0x867844dbU, + 0x81caaff3U, 0x3eb968c4U, 0x2c382434U, 0x5fc2a340U, + 0x72161dc3U, 0x0cbce225U, 0x8b283c49U, 0x41ff0d95U, + 0x7139a801U, 0xde080cb3U, 0x9cd8b4e4U, 0x906456c1U, + 0x617bcb84U, 0x70d532b6U, 0x74486c5cU, 0x42d0b857U, +}; + +const TUint32 Td2[256] = { + 0xa75051f4U, 0x65537e41U, 0xa4c31a17U, 0x5e963a27U, + 0x6bcb3babU, 0x45f11f9dU, 0x58abacfaU, 0x03934be3U, + 0xfa552030U, 0x6df6ad76U, 0x769188ccU, 0x4c25f502U, + 0xd7fc4fe5U, 0xcbd7c52aU, 0x44802635U, 0xa38fb562U, + 0x5a49deb1U, 0x1b6725baU, 0x0e9845eaU, 0xc0e15dfeU, + 0x7502c32fU, 0xf012814cU, 0x97a38d46U, 0xf9c66bd3U, + 0x5fe7038fU, 0x9c951592U, 0x7aebbf6dU, 0x59da9552U, + 0x832dd4beU, 0x21d35874U, 0x692949e0U, 0xc8448ec9U, + 0x896a75c2U, 0x7978f48eU, 0x3e6b9958U, 0x71dd27b9U, + 0x4fb6bee1U, 0xad17f088U, 0xac66c920U, 0x3ab47dceU, + 0x4a1863dfU, 0x3182e51aU, 0x33609751U, 0x7f456253U, + 0x77e0b164U, 0xae84bb6bU, 0xa01cfe81U, 0x2b94f908U, + 0x68587048U, 0xfd198f45U, 0x6c8794deU, 0xf8b7527bU, + 0xd323ab73U, 0x02e2724bU, 0x8f57e31fU, 0xab2a6655U, + 0x2807b2ebU, 0xc2032fb5U, 0x7b9a86c5U, 0x08a5d337U, + 0x87f23028U, 0xa5b223bfU, 0x6aba0203U, 0x825ced16U, + 0x1c2b8acfU, 0xb492a779U, 0xf2f0f307U, 0xe2a14e69U, + 0xf4cd65daU, 0xbed50605U, 0x621fd134U, 0xfe8ac4a6U, + 0x539d342eU, 0x55a0a2f3U, 0xe132058aU, 0xeb75a4f6U, + 0xec390b83U, 0xefaa4060U, 0x9f065e71U, 0x1051bd6eU, + + 0x8af93e21U, 0x063d96ddU, 0x05aedd3eU, 0xbd464de6U, + 0x8db59154U, 0x5d0571c4U, 0xd46f0406U, 0x15ff6050U, + 0xfb241998U, 0xe997d6bdU, 0x43cc8940U, 0x9e7767d9U, + 0x42bdb0e8U, 0x8b880789U, 0x5b38e719U, 0xeedb79c8U, + 0x0a47a17cU, 0x0fe97c42U, 0x1ec9f884U, 0x00000000U, + 0x86830980U, 0xed48322bU, 0x70ac1e11U, 0x724e6c5aU, + 0xfffbfd0eU, 0x38560f85U, 0xd51e3daeU, 0x3927362dU, + 0xd9640a0fU, 0xa621685cU, 0x54d19b5bU, 0x2e3a2436U, + 0x67b10c0aU, 0xe70f9357U, 0x96d2b4eeU, 0x919e1b9bU, + 0xc54f80c0U, 0x20a261dcU, 0x4b695a77U, 0x1a161c12U, + 0xba0ae293U, 0x2ae5c0a0U, 0xe0433c22U, 0x171d121bU, + 0x0d0b0e09U, 0xc7adf28bU, 0xa8b92db6U, 0xa9c8141eU, + 0x198557f1U, 0x074caf75U, 0xddbbee99U, 0x60fda37fU, + 0x269ff701U, 0xf5bc5c72U, 0x3bc54466U, 0x7e345bfbU, + 0x29768b43U, 0xc6dccb23U, 0xfc68b6edU, 0xf163b8e4U, + 0xdccad731U, 0x85104263U, 0x22401397U, 0x112084c6U, + 0x247d854aU, 0x3df8d2bbU, 0x3211aef9U, 0xa16dc729U, + 0x2f4b1d9eU, 0x30f3dcb2U, 0x52ec0d86U, 0xe3d077c1U, + 0x166c2bb3U, 0xb999a970U, 0x48fa1194U, 0x642247e9U, + 0x8cc4a8fcU, 0x3f1aa0f0U, 0x2cd8567dU, 0x90ef2233U, + 0x4ec78749U, 0xd1c1d938U, 0xa2fe8ccaU, 0x0b3698d4U, + 0x81cfa6f5U, 0xde28a57aU, 0x8e26dab7U, 0xbfa43fadU, + 0x9de42c3aU, 0x920d5078U, 0xcc9b6a5fU, 0x4662547eU, + 0x13c2f68dU, 0xb8e890d8U, 0xf75e2e39U, 0xaff582c3U, + 0x80be9f5dU, 0x937c69d0U, 0x2da96fd5U, 0x12b3cf25U, + 0x993bc8acU, 0x7da71018U, 0x636ee89cU, 0xbb7bdb3bU, + 0x7809cd26U, 0x18f46e59U, 0xb701ec9aU, 0x9aa8834fU, + 0x6e65e695U, 0xe67eaaffU, 0xcf0821bcU, 0xe8e6ef15U, + 0x9bd9bae7U, 0x36ce4a6fU, 0x09d4ea9fU, 0x7cd629b0U, + 0xb2af31a4U, 0x23312a3fU, 0x9430c6a5U, 0x66c035a2U, + 0xbc37744eU, 0xcaa6fc82U, 0xd0b0e090U, 0xd81533a7U, + 0x984af104U, 0xdaf741ecU, 0x500e7fcdU, 0xf62f1791U, + 0xd68d764dU, 0xb04d43efU, 0x4d54ccaaU, 0x04dfe496U, + 0xb5e39ed1U, 0x881b4c6aU, 0x1fb8c12cU, 0x517f4665U, + 0xea049d5eU, 0x355d018cU, 0x7473fa87U, 0x412efb0bU, + 0x1d5ab367U, 0xd25292dbU, 0x5633e910U, 0x47136dd6U, + 0x618c9ad7U, 0x0c7a37a1U, 0x148e59f8U, 0x3c89eb13U, + 0x27eecea9U, 0xc935b761U, 0xe5ede11cU, 0xb13c7a47U, + 0xdf599cd2U, 0x733f55f2U, 0xce791814U, 0x37bf73c7U, + 0xcdea53f7U, 0xaa5b5ffdU, 0x6f14df3dU, 0xdb867844U, + 0xf381caafU, 0xc43eb968U, 0x342c3824U, 0x405fc2a3U, + 0xc372161dU, 0x250cbce2U, 0x498b283cU, 0x9541ff0dU, + 0x017139a8U, 0xb3de080cU, 0xe49cd8b4U, 0xc1906456U, + 0x84617bcbU, 0xb670d532U, 0x5c74486cU, 0x5742d0b8U, +}; + +const TUint32 Td3[256] = { + 0xf4a75051U, 0x4165537eU, 0x17a4c31aU, 0x275e963aU, + 0xab6bcb3bU, 0x9d45f11fU, 0xfa58abacU, 0xe303934bU, + 0x30fa5520U, 0x766df6adU, 0xcc769188U, 0x024c25f5U, + 0xe5d7fc4fU, 0x2acbd7c5U, 0x35448026U, 0x62a38fb5U, + 0xb15a49deU, 0xba1b6725U, 0xea0e9845U, 0xfec0e15dU, + 0x2f7502c3U, 0x4cf01281U, 0x4697a38dU, 0xd3f9c66bU, + 0x8f5fe703U, 0x929c9515U, 0x6d7aebbfU, 0x5259da95U, + 0xbe832dd4U, 0x7421d358U, 0xe0692949U, 0xc9c8448eU, + 0xc2896a75U, 0x8e7978f4U, 0x583e6b99U, 0xb971dd27U, + 0xe14fb6beU, 0x88ad17f0U, 0x20ac66c9U, 0xce3ab47dU, + 0xdf4a1863U, 0x1a3182e5U, 0x51336097U, 0x537f4562U, + 0x6477e0b1U, 0x6bae84bbU, 0x81a01cfeU, 0x082b94f9U, + 0x48685870U, 0x45fd198fU, 0xde6c8794U, 0x7bf8b752U, + 0x73d323abU, 0x4b02e272U, 0x1f8f57e3U, 0x55ab2a66U, + 0xeb2807b2U, 0xb5c2032fU, 0xc57b9a86U, 0x3708a5d3U, + 0x2887f230U, 0xbfa5b223U, 0x036aba02U, 0x16825cedU, + 0xcf1c2b8aU, 0x79b492a7U, 0x07f2f0f3U, 0x69e2a14eU, + 0xdaf4cd65U, 0x05bed506U, 0x34621fd1U, 0xa6fe8ac4U, + 0x2e539d34U, 0xf355a0a2U, 0x8ae13205U, 0xf6eb75a4U, + 0x83ec390bU, 0x60efaa40U, 0x719f065eU, 0x6e1051bdU, + 0x218af93eU, 0xdd063d96U, 0x3e05aeddU, 0xe6bd464dU, + 0x548db591U, 0xc45d0571U, 0x06d46f04U, 0x5015ff60U, + 0x98fb2419U, 0xbde997d6U, 0x4043cc89U, 0xd99e7767U, + 0xe842bdb0U, 0x898b8807U, 0x195b38e7U, 0xc8eedb79U, + 0x7c0a47a1U, 0x420fe97cU, 0x841ec9f8U, 0x00000000U, + 0x80868309U, 0x2bed4832U, 0x1170ac1eU, 0x5a724e6cU, + 0x0efffbfdU, 0x8538560fU, 0xaed51e3dU, 0x2d392736U, + 0x0fd9640aU, 0x5ca62168U, 0x5b54d19bU, 0x362e3a24U, + 0x0a67b10cU, 0x57e70f93U, 0xee96d2b4U, 0x9b919e1bU, + 0xc0c54f80U, 0xdc20a261U, 0x774b695aU, 0x121a161cU, + 0x93ba0ae2U, 0xa02ae5c0U, 0x22e0433cU, 0x1b171d12U, + 0x090d0b0eU, 0x8bc7adf2U, 0xb6a8b92dU, 0x1ea9c814U, + 0xf1198557U, 0x75074cafU, 0x99ddbbeeU, 0x7f60fda3U, + 0x01269ff7U, 0x72f5bc5cU, 0x663bc544U, 0xfb7e345bU, + 0x4329768bU, 0x23c6dccbU, 0xedfc68b6U, 0xe4f163b8U, + 0x31dccad7U, 0x63851042U, 0x97224013U, 0xc6112084U, + 0x4a247d85U, 0xbb3df8d2U, 0xf93211aeU, 0x29a16dc7U, + 0x9e2f4b1dU, 0xb230f3dcU, 0x8652ec0dU, 0xc1e3d077U, + 0xb3166c2bU, 0x70b999a9U, 0x9448fa11U, 0xe9642247U, + 0xfc8cc4a8U, 0xf03f1aa0U, 0x7d2cd856U, 0x3390ef22U, + 0x494ec787U, 0x38d1c1d9U, 0xcaa2fe8cU, 0xd40b3698U, + 0xf581cfa6U, 0x7ade28a5U, 0xb78e26daU, 0xadbfa43fU, + 0x3a9de42cU, 0x78920d50U, 0x5fcc9b6aU, 0x7e466254U, + 0x8d13c2f6U, 0xd8b8e890U, 0x39f75e2eU, 0xc3aff582U, + 0x5d80be9fU, 0xd0937c69U, 0xd52da96fU, 0x2512b3cfU, + 0xac993bc8U, 0x187da710U, 0x9c636ee8U, 0x3bbb7bdbU, + 0x267809cdU, 0x5918f46eU, 0x9ab701ecU, 0x4f9aa883U, + 0x956e65e6U, 0xffe67eaaU, 0xbccf0821U, 0x15e8e6efU, + 0xe79bd9baU, 0x6f36ce4aU, 0x9f09d4eaU, 0xb07cd629U, + 0xa4b2af31U, 0x3f23312aU, 0xa59430c6U, 0xa266c035U, + 0x4ebc3774U, 0x82caa6fcU, 0x90d0b0e0U, 0xa7d81533U, + 0x04984af1U, 0xecdaf741U, 0xcd500e7fU, 0x91f62f17U, + 0x4dd68d76U, 0xefb04d43U, 0xaa4d54ccU, 0x9604dfe4U, + 0xd1b5e39eU, 0x6a881b4cU, 0x2c1fb8c1U, 0x65517f46U, + 0x5eea049dU, 0x8c355d01U, 0x877473faU, 0x0b412efbU, + 0x671d5ab3U, 0xdbd25292U, 0x105633e9U, 0xd647136dU, + 0xd7618c9aU, 0xa10c7a37U, 0xf8148e59U, 0x133c89ebU, + 0xa927eeceU, 0x61c935b7U, 0x1ce5ede1U, 0x47b13c7aU, + 0xd2df599cU, 0xf2733f55U, 0x14ce7918U, 0xc737bf73U, + 0xf7cdea53U, 0xfdaa5b5fU, 0x3d6f14dfU, 0x44db8678U, + 0xaff381caU, 0x68c43eb9U, 0x24342c38U, 0xa3405fc2U, + 0x1dc37216U, 0xe2250cbcU, 0x3c498b28U, 0x0d9541ffU, + 0xa8017139U, 0x0cb3de08U, 0xb4e49cd8U, 0x56c19064U, + 0xcb84617bU, 0x32b670d5U, 0x6c5c7448U, 0xb85742d0U, +}; + +const TUint32 Td4[256] = { + 0x52525252U, 0x09090909U, 0x6a6a6a6aU, 0xd5d5d5d5U, + 0x30303030U, 0x36363636U, 0xa5a5a5a5U, 0x38383838U, + 0xbfbfbfbfU, 0x40404040U, 0xa3a3a3a3U, 0x9e9e9e9eU, + 0x81818181U, 0xf3f3f3f3U, 0xd7d7d7d7U, 0xfbfbfbfbU, + 0x7c7c7c7cU, 0xe3e3e3e3U, 0x39393939U, 0x82828282U, + 0x9b9b9b9bU, 0x2f2f2f2fU, 0xffffffffU, 0x87878787U, + 0x34343434U, 0x8e8e8e8eU, 0x43434343U, 0x44444444U, + 0xc4c4c4c4U, 0xdedededeU, 0xe9e9e9e9U, 0xcbcbcbcbU, + 0x54545454U, 0x7b7b7b7bU, 0x94949494U, 0x32323232U, + 0xa6a6a6a6U, 0xc2c2c2c2U, 0x23232323U, 0x3d3d3d3dU, + 0xeeeeeeeeU, 0x4c4c4c4cU, 0x95959595U, 0x0b0b0b0bU, + 0x42424242U, 0xfafafafaU, 0xc3c3c3c3U, 0x4e4e4e4eU, + 0x08080808U, 0x2e2e2e2eU, 0xa1a1a1a1U, 0x66666666U, + 0x28282828U, 0xd9d9d9d9U, 0x24242424U, 0xb2b2b2b2U, + 0x76767676U, 0x5b5b5b5bU, 0xa2a2a2a2U, 0x49494949U, + 0x6d6d6d6dU, 0x8b8b8b8bU, 0xd1d1d1d1U, 0x25252525U, + 0x72727272U, 0xf8f8f8f8U, 0xf6f6f6f6U, 0x64646464U, + 0x86868686U, 0x68686868U, 0x98989898U, 0x16161616U, + 0xd4d4d4d4U, 0xa4a4a4a4U, 0x5c5c5c5cU, 0xccccccccU, + 0x5d5d5d5dU, 0x65656565U, 0xb6b6b6b6U, 0x92929292U, + 0x6c6c6c6cU, 0x70707070U, 0x48484848U, 0x50505050U, + 0xfdfdfdfdU, 0xededededU, 0xb9b9b9b9U, 0xdadadadaU, + 0x5e5e5e5eU, 0x15151515U, 0x46464646U, 0x57575757U, + 0xa7a7a7a7U, 0x8d8d8d8dU, 0x9d9d9d9dU, 0x84848484U, + 0x90909090U, 0xd8d8d8d8U, 0xababababU, 0x00000000U, + 0x8c8c8c8cU, 0xbcbcbcbcU, 0xd3d3d3d3U, 0x0a0a0a0aU, + 0xf7f7f7f7U, 0xe4e4e4e4U, 0x58585858U, 0x05050505U, + 0xb8b8b8b8U, 0xb3b3b3b3U, 0x45454545U, 0x06060606U, + 0xd0d0d0d0U, 0x2c2c2c2cU, 0x1e1e1e1eU, 0x8f8f8f8fU, + 0xcacacacaU, 0x3f3f3f3fU, 0x0f0f0f0fU, 0x02020202U, + 0xc1c1c1c1U, 0xafafafafU, 0xbdbdbdbdU, 0x03030303U, + 0x01010101U, 0x13131313U, 0x8a8a8a8aU, 0x6b6b6b6bU, + 0x3a3a3a3aU, 0x91919191U, 0x11111111U, 0x41414141U, + 0x4f4f4f4fU, 0x67676767U, 0xdcdcdcdcU, 0xeaeaeaeaU, + 0x97979797U, 0xf2f2f2f2U, 0xcfcfcfcfU, 0xcecececeU, + 0xf0f0f0f0U, 0xb4b4b4b4U, 0xe6e6e6e6U, 0x73737373U, + 0x96969696U, 0xacacacacU, 0x74747474U, 0x22222222U, + 0xe7e7e7e7U, 0xadadadadU, 0x35353535U, 0x85858585U, + 0xe2e2e2e2U, 0xf9f9f9f9U, 0x37373737U, 0xe8e8e8e8U, + 0x1c1c1c1cU, 0x75757575U, 0xdfdfdfdfU, 0x6e6e6e6eU, + 0x47474747U, 0xf1f1f1f1U, 0x1a1a1a1aU, 0x71717171U, + 0x1d1d1d1dU, 0x29292929U, 0xc5c5c5c5U, 0x89898989U, + 0x6f6f6f6fU, 0xb7b7b7b7U, 0x62626262U, 0x0e0e0e0eU, + 0xaaaaaaaaU, 0x18181818U, 0xbebebebeU, 0x1b1b1b1bU, + 0xfcfcfcfcU, 0x56565656U, 0x3e3e3e3eU, 0x4b4b4b4bU, + 0xc6c6c6c6U, 0xd2d2d2d2U, 0x79797979U, 0x20202020U, + 0x9a9a9a9aU, 0xdbdbdbdbU, 0xc0c0c0c0U, 0xfefefefeU, + 0x78787878U, 0xcdcdcdcdU, 0x5a5a5a5aU, 0xf4f4f4f4U, + 0x1f1f1f1fU, 0xddddddddU, 0xa8a8a8a8U, 0x33333333U, + 0x88888888U, 0x07070707U, 0xc7c7c7c7U, 0x31313131U, + 0xb1b1b1b1U, 0x12121212U, 0x10101010U, 0x59595959U, + 0x27272727U, 0x80808080U, 0xececececU, 0x5f5f5f5fU, + 0x60606060U, 0x51515151U, 0x7f7f7f7fU, 0xa9a9a9a9U, + 0x19191919U, 0xb5b5b5b5U, 0x4a4a4a4aU, 0x0d0d0d0dU, + 0x2d2d2d2dU, 0xe5e5e5e5U, 0x7a7a7a7aU, 0x9f9f9f9fU, + 0x93939393U, 0xc9c9c9c9U, 0x9c9c9c9cU, 0xefefefefU, + 0xa0a0a0a0U, 0xe0e0e0e0U, 0x3b3b3b3bU, 0x4d4d4d4dU, + 0xaeaeaeaeU, 0x2a2a2a2aU, 0xf5f5f5f5U, 0xb0b0b0b0U, + 0xc8c8c8c8U, 0xebebebebU, 0xbbbbbbbbU, 0x3c3c3c3cU, + 0x83838383U, 0x53535353U, 0x99999999U, 0x61616161U, + 0x17171717U, 0x2b2b2b2bU, 0x04040404U, 0x7e7e7e7eU, + 0xbabababaU, 0x77777777U, 0xd6d6d6d6U, 0x26262626U, + 0xe1e1e1e1U, 0x69696969U, 0x14141414U, 0x63636363U, + 0x55555555U, 0x21212121U, 0x0c0c0c0cU, 0x7d7d7d7dU, +}; + +const TUint32 rcon[] = { + 0x01000000, 0x02000000, 0x04000000, 0x08000000, + 0x10000000, 0x20000000, 0x40000000, 0x80000000, + 0x1B000000, 0x36000000, /* for 128-bit blocks, Rijndael never uses more than 10 rcon values */ +}; + +} // namespace RIJNDAEL_TABLE +#endif // __RIJNDAELTABLES_H__ diff -r 7e3f204e6c81 -r f9c11be8c0b3 cryptoplugins/cryptospiplugins/source/softwarecrypto/rsafunction.cpp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/cryptoplugins/cryptospiplugins/source/softwarecrypto/rsafunction.cpp Tue Dec 01 11:12:04 2009 +0000 @@ -0,0 +1,138 @@ +/* +* Copyright (c) 2003-2009 Nokia Corporation and/or its subsidiary(-ies). +* All rights reserved. +* This component and the accompanying materials are made available +* under the terms of the License "Eclipse Public License v1.0" +* which accompanies this distribution, and is available +* at the URL "http://www.eclipse.org/legal/epl-v10.html". +* +* Initial Contributors: +* Nokia Corporation - initial contribution. +* +* Contributors: +* +* Description: +* +*/ + + +#include +#include "keys.h" +#include +#include +#include +#include "rsafunction.h" +#include "mont.h" + +using namespace CryptoSpi; + +// Public Encrypt +void RSAFunction::EncryptL(const CKey& aPublicKey, + const TInteger& aInput, RInteger& aOutput) + { + const TInteger& N = aPublicKey.GetBigIntL(KRsaKeyParameterNUid); + const TInteger& E = aPublicKey.GetBigIntL(KRsaKeyParameterEUid); + FunctionL(N, E, aInput, aOutput); + } + +// Private Decrypt +void RSAFunction::DecryptL(const CKey& aPrivateKey, const TInteger& aInput, RInteger& aOutput) + { + if (aPrivateKey.KeyProperty().iKeyType == KRsaPrivateKeyStandardUid) + { + const TInteger& N = aPrivateKey.GetBigIntL(KRsaKeyParameterNUid); + const TInteger& D = aPrivateKey.GetBigIntL(KRsaKeyParameterDUid); + FunctionL(N, D, aInput, aOutput); + } + else if (aPrivateKey.KeyProperty().iKeyType == KRsaPrivateKeyCRTUid) + { + FunctionCRTL(aPrivateKey, aInput, aOutput); + } + else + { + User::Leave(KErrNotSupported); + } + } + +// Private Encrypt +void RSAFunction::SignL(const CKey& aPrivateKey, const TInteger& aInput, RInteger& aOutput) + { + if (aPrivateKey.KeyProperty().iKeyType == KRsaPrivateKeyStandardUid) + { + const TInteger& N = aPrivateKey.GetBigIntL(KRsaKeyParameterNUid); + const TInteger& D = aPrivateKey.GetBigIntL(KRsaKeyParameterDUid); + FunctionL(N, D, aInput, aOutput); + } + else if (aPrivateKey.KeyProperty().iKeyType == KRsaPrivateKeyCRTUid) + { + FunctionCRTL(aPrivateKey, aInput, aOutput); + } + else + { + User::Leave(KErrNotSupported); + } +} + +// Public Decrypt +void RSAFunction::VerifyL(const CKey& aPublicKey, + const TInteger& aInput, RInteger& aOutput) + { + const TInteger& N = aPublicKey.GetBigIntL(KRsaKeyParameterNUid); + const TInteger& E = aPublicKey.GetBigIntL(KRsaKeyParameterEUid); + FunctionL(N, E, aInput, aOutput); + } + +// The RSA Trapdoor Function +void RSAFunction::FunctionL(const TInteger& aModulus, const TInteger& aExponent, + const TInteger& aBase, RInteger& aOutput) + { + IsInputValidL(aBase, aModulus); + + aOutput = TInteger::ModularExponentiateL(aBase, aExponent, aModulus); + } + +// The CRT version of the RSA Trapdoor Function +void RSAFunction::FunctionCRTL(const CKey& aPrivateKey, + const TInteger& aInput, RInteger& aOutput) + { + const TInteger& N = aPrivateKey.GetBigIntL(KRsaKeyParameterNUid); + IsInputValidL(aInput, N); + + const TInteger& P = aPrivateKey.GetBigIntL(KRsaKeyParameterPUid); + const TInteger& Q = aPrivateKey.GetBigIntL(KRsaKeyParameterQUid); + const TInteger& DP = aPrivateKey.GetBigIntL(KRsaKeyParameterDPUid); + const TInteger& DQ = aPrivateKey.GetBigIntL(KRsaKeyParameterDQUid); + const TInteger& QInv = aPrivateKey.GetBigIntL(KRsaKeyParameterQInvUid); + + CMontgomeryStructure* montP = CMontgomeryStructure::NewLC(P); + CMontgomeryStructure* montQ = CMontgomeryStructure::NewLC(Q); + + // m1 = c^(dP) mod(p) + RInteger inputReduced = aInput.ModuloL(P); + CleanupStack::PushL(inputReduced); + const TInteger& m1 = montP->ExponentiateL(inputReduced, DP); + CleanupStack::PopAndDestroy(&inputReduced); + + // m2 = c^(dQ) mod(Q) + inputReduced = aInput.ModuloL(Q); + CleanupStack::PushL(inputReduced); + const TInteger& m2 = montQ->ExponentiateL(inputReduced, DQ); + CleanupStack::PopAndDestroy(&inputReduced); + + // Calculate CRT + // h = (m1-m2) qInv mod(p) + RInteger h = m1.MinusL(m2); + CleanupStack::PushL(h); + h *= QInv; + h %= P; + + // m = m2 + q * h + h *= Q; + h += m2; + + aOutput = h; + CleanupStack::Pop(&h); + + CleanupStack::PopAndDestroy(montQ); + CleanupStack::PopAndDestroy(montP); + } diff -r 7e3f204e6c81 -r f9c11be8c0b3 cryptoplugins/cryptospiplugins/source/softwarecrypto/rsafunction.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/cryptoplugins/cryptospiplugins/source/softwarecrypto/rsafunction.h Tue Dec 01 11:12:04 2009 +0000 @@ -0,0 +1,85 @@ +/* +* Copyright (c) 2003-2009 Nokia Corporation and/or its subsidiary(-ies). +* All rights reserved. +* This component and the accompanying materials are made available +* under the terms of the License "Eclipse Public License v1.0" +* which accompanies this distribution, and is available +* at the URL "http://www.eclipse.org/legal/epl-v10.html". +* +* Initial Contributors: +* Nokia Corporation - initial contribution. +* +* Contributors: +* +* Description: +* +*/ + + +/** + @file + @internalComponent + @released +*/ + +#ifndef __RSAFUNCTION_H__ +#define __RSAFUNCTION_H__ + +#include +#include "keys.h" + +using namespace CryptoSpi; + +class TInteger; + +class RSAFunction + { +public: + static inline TBool IsInputValid(const TInteger& aInput, + const TInteger& aModulus); + static inline void IsInputValidL(const TInteger& aInput, + const TInteger& aModulus); + static void EncryptL(const CKey& aPublicKey, + const TInteger& aInput, RInteger& aOutput); + static void DecryptL(const CKey& aPrivateKey, + const TInteger& aInput, RInteger& aOutput); + static void SignL(const CKey& aPrivateKey, + const TInteger& aInput, RInteger& aOutput); + static void VerifyL(const CKey& aPublicKey, + const TInteger& aInput, RInteger& aOutput); +private: + static void FunctionL(const TInteger& aModulus, const TInteger& aExponent, + const TInteger& aBase, RInteger& aOutput); + static void FunctionCRTL(const CKey& aPrivateKey, + const TInteger& aInput, RInteger& aOutput); +private: + RSAFunction(void); + }; + +/** Computes whether a given message representative is within the valid bounds + * for a given modulus, i.e. whether the message is representative within [0,n-1]. + * @param aInput The message representative. + * @param aModulus The modulus. + * @return TBool representing whether or not the message representative is + * valid. + */ +TBool RSAFunction::IsInputValid(const TInteger& aInput, + const TInteger& aModulus) + { + //See HAC 8.3 1.b + //Message (input) must be in the interval [0,n-1] (inclusive) + if( aInput.IsNegative() || aInput >= aModulus ) + return EFalse; + else + return ETrue; + } + +void RSAFunction::IsInputValidL(const TInteger& aInput, + const TInteger& aModulus) + { + if(!IsInputValid(aInput, aModulus)) + User::Leave(KErrArgument); + } + +#endif + diff -r 7e3f204e6c81 -r f9c11be8c0b3 cryptoplugins/cryptospiplugins/source/softwarecrypto/rsaimpl.cpp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/cryptoplugins/cryptospiplugins/source/softwarecrypto/rsaimpl.cpp Tue Dec 01 11:12:04 2009 +0000 @@ -0,0 +1,178 @@ +/* +* Copyright (c) 2006-2009 Nokia Corporation and/or its subsidiary(-ies). +* All rights reserved. +* This component and the accompanying materials are made available +* under the terms of the License "Eclipse Public License v1.0" +* which accompanies this distribution, and is available +* at the URL "http://www.eclipse.org/legal/epl-v10.html". +* +* Initial Contributors: +* Nokia Corporation - initial contribution. +* +* Contributors: +* +* Description: +* +*/ + + +#include "rsaimpl.h" +#include "rsafunction.h" +#include "pluginconfig.h" +#include +#include +#include + +using namespace SoftwareCrypto; + +/* CRSAImpl */ +CRSAImpl::CRSAImpl( + TUid aCryptoMode, + TUid aPadding) : + CAsymmetricCipherImpl(aCryptoMode, aPadding) + { + } + +CRSAImpl* CRSAImpl::NewL(const CKey& aKey, TUid aCryptoMode, TUid aPadding) + { + CRSAImpl* self = CRSAImpl::NewLC(aKey, aCryptoMode, aPadding); + CleanupStack::Pop(self); + return self; + } + +CRSAImpl* CRSAImpl::NewLC(const CKey& aKey, TUid aCryptoMode, TUid aPadding) + { + CRSAImpl* self = new(ELeave) CRSAImpl(aCryptoMode, aPadding); + CleanupStack::PushL(self); + self->ConstructL(aKey); + return self; + } + +CRSAImpl::~CRSAImpl() + { + } + +TInt CRSAImpl::GetMaximumOutputLengthL() const + { + const TInteger& N = iKey->GetBigIntL(KRsaKeyParameterNUid); + + if (iCryptoMode.iUid == KCryptoModeDecrypt) + return N.ByteCount() - iPadding->MinPaddingLength(); + else + return N.ByteCount(); + } + +TInt CRSAImpl::GetMaximumInputLengthL() const + { + const TInteger& N = iKey->GetBigIntL(KRsaKeyParameterNUid); + + if (iCryptoMode.iUid == KCryptoModeEncrypt) + return N.ByteCount() - iPadding->MinPaddingLength(); + else + return N.ByteCount(); + } + +void CRSAImpl::ConstructL(const CKey& aKey) + { + const TInteger& N = aKey.GetBigIntL(KRsaKeyParameterNUid); + TCrypto::IsAsymmetricWeakEnoughL(N.BitCount()); + CAsymmetricCipherImpl::ConstructL(aKey); + + if (! IsValidKeyLengthL(N.ByteCount())) + { + User::Leave(KErrKeySize); + } + } + +CExtendedCharacteristics* CRSAImpl::CreateExtendedCharacteristicsL() + { + // All Symbian software plug-ins have unlimited concurrency, cannot be reserved + // for exclusive use and are not CERTIFIED to be standards compliant. + return CExtendedCharacteristics::NewL(KMaxTInt, EFalse); + } + +const CExtendedCharacteristics* CRSAImpl::GetExtendedCharacteristicsL() + { + return CRSAImpl::CreateExtendedCharacteristicsL(); + } + +TUid CRSAImpl::ImplementationUid() const + { + return KCryptoPluginRsaCipherUid; + } + +void CRSAImpl::EncryptL(const TDesC8& aInput, TDes8& aOutput) const + { + __ASSERT_DEBUG(aOutput.MaxLength() >= GetMaximumOutputLengthL(), User::Panic(KCryptoPanic, ECryptoPanicOutputDescriptorOverflow)); + __ASSERT_DEBUG(aInput.Length() <= GetMaximumInputLengthL(), User::Panic(KCryptoPanic, ECryptoPanicInputTooLarge)); + + HBufC8* buf = HBufC8::NewLC(GetMaximumOutputLengthL()); + TPtr8 ptr = buf->Des(); + + iPadding->PadL(aInput, ptr); + RInteger input = RInteger::NewL(ptr); + CleanupStack::PushL(input); + + RInteger output; + RSAFunction::EncryptL(*iKey, input, output); + CleanupStack::PushL(output); + + aOutput.Append(*(output.BufferLC())); + CleanupStack::PopAndDestroy(4, buf); //BufferLC, output, input, buf + } + +void CRSAImpl::DecryptL(const TDesC8& aInput, TDes8& aOutput) const + { + __ASSERT_DEBUG(aOutput.MaxLength() >= GetMaximumOutputLengthL(), User::Panic(KCryptoPanic, ECryptoPanicOutputDescriptorOverflow)); + __ASSERT_DEBUG(aInput.Length() <= GetMaximumInputLengthL(), User::Panic(KCryptoPanic, ECryptoPanicInputTooLarge)); + + RInteger input = RInteger::NewL(aInput); + CleanupStack::PushL(input); + + RInteger output; + + RSAFunction::DecryptL(*iKey, input, output); + CleanupStack::PushL(output); + + TPtrC8 ptr = *(output.BufferLC()); + iPadding->UnPadL(ptr, aOutput); + + CleanupStack::PopAndDestroy(3, &input); //BufferLC(), output, input + } + +void CRSAImpl::ProcessL(const TDesC8& aInput, TDes8& aOutput) + { + if (iCryptoMode.iUid == KCryptoModeEncrypt) + { + EncryptL(aInput, aOutput); + } + else + { + DecryptL(aInput, aOutput); + } + } + +TBool CRSAImpl::IsValidKeyLengthL(TInt aKeyBytes) const + { + if (aKeyBytes < 1) + return EFalse; + + switch (iCryptoMode.iUid) + { + case KCryptoModeEncrypt: + // Check if GetMaximumInputLengthL() makes sense, + // if not the key length must be too small + if (GetMaximumInputLengthL() <= 0) + return EFalse; + break; + + case KCryptoModeDecrypt: + // Check if GetMaximumOutputLengthL() makes sense, + // if not the key length must be too small + if (GetMaximumOutputLengthL() <= 0) + return EFalse; + break; + } + return ETrue; + } + diff -r 7e3f204e6c81 -r f9c11be8c0b3 cryptoplugins/cryptospiplugins/source/softwarecrypto/rsaimpl.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/cryptoplugins/cryptospiplugins/source/softwarecrypto/rsaimpl.h Tue Dec 01 11:12:04 2009 +0000 @@ -0,0 +1,96 @@ +/* +* Copyright (c) 2006-2009 Nokia Corporation and/or its subsidiary(-ies). +* All rights reserved. +* This component and the accompanying materials are made available +* under the terms of the License "Eclipse Public License v1.0" +* which accompanies this distribution, and is available +* at the URL "http://www.eclipse.org/legal/epl-v10.html". +* +* Initial Contributors: +* Nokia Corporation - initial contribution. +* +* Contributors: +* +* Description: +* +*/ + + +#ifndef __RSAIMPL_H__ +#define __RSAIMPL_H__ + +/** +@file +@internalComponent +@released +*/ + +#include +#include +#include "keys.h" +#include "asymmetriccipherimpl.h" + +/** + * Implementation of RSA encryption as described in PKCS#1 v1.5. + */ +namespace SoftwareCrypto + { + using namespace CryptoSpi; + + NONSHARABLE_CLASS(CRSAImpl) : public CAsymmetricCipherImpl + { + public: + /** + Creates an instance of an RSA asymmetric cipher plug-in. + @param aKey The key + @param aCryptoMode Whether to encrypt or decrypt + @param aPadding The padding scheme to use None, SSLv3, PKCS#7 + @return A pointer to a CRSAImpl instance + */ + static CRSAImpl* NewL(const CKey& aKey, + TUid aCryptoMode, TUid aPadding); + + /** + Creates an instance of an RSA asymmetric cipher plug-in. + A pointer to the plug-in instance is placed on the cleanup stack. + @param aKey The key + @param aCryptoMode Whether to encrypt or decrypt + @param aPadding The padding scheme to use None, SSLv3, PKCS#7 + @return A pointer to a CRSAImpl instance + */ + static CRSAImpl* NewLC(const CKey& aKey, + TUid aCryptoMode, TUid aPadding); + + // Override CAsymmetricCipherImpl virtual functions + TUid ImplementationUid() const; + TBool IsValidKeyLengthL(TInt aKeyBytes) const; + TInt GetMaximumInputLengthL() const; + TInt GetMaximumOutputLengthL() const; + void ProcessL(const TDesC8& aInput, TDes8& aOutput); + // End of CAsymmetricCipherImpl + + const CExtendedCharacteristics* GetExtendedCharacteristicsL(); + static CExtendedCharacteristics* CreateExtendedCharacteristicsL(); + + // Destructor + ~CRSAImpl(); + + private: + /** + Constructor + @param aCryptoMode Whether to encrypt or decrypt + @param aPaddingMode The padding mode to use. None, SSL, PKCS#7 + */ + CRSAImpl(TUid aCryptoMode, TUid aPaddingMode); + + /// second phase of construction + void ConstructL(const CKey& aKey); + + /// for internal usage, called from ProcessL + void EncryptL(const TDesC8& aInput, TDes8& aOutput) const; + void DecryptL(const TDesC8& aInput, TDes8& aOutput) const; + + }; + } + +#endif // __RSAIMPL_H__ diff -r 7e3f204e6c81 -r f9c11be8c0b3 cryptoplugins/cryptospiplugins/source/softwarecrypto/rsakeypairgenimpl.cpp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/cryptoplugins/cryptospiplugins/source/softwarecrypto/rsakeypairgenimpl.cpp Tue Dec 01 11:12:04 2009 +0000 @@ -0,0 +1,245 @@ +/* +* Copyright (c) 2006-2009 Nokia Corporation and/or its subsidiary(-ies). +* All rights reserved. +* This component and the accompanying materials are made available +* under the terms of the License "Eclipse Public License v1.0" +* which accompanies this distribution, and is available +* at the URL "http://www.eclipse.org/legal/epl-v10.html". +* +* Initial Contributors: +* Nokia Corporation - initial contribution. +* +* Contributors: +* +* Description: +* RSA Keypair implementation +* RSA keypair generation implementation +* +*/ + + +/** + @file +*/ + +#include "rsakeypairgenimpl.h" +#include "pluginconfig.h" + +#include "keypair.h" +#include + +#include "common/inlines.h" // For TClassSwap + +using namespace SoftwareCrypto; + +/* CRSAKeyPairGenImpl */ +CRSAKeyPairGenImpl::CRSAKeyPairGenImpl() + { + } + +CRSAKeyPairGenImpl::~CRSAKeyPairGenImpl() + { + } + +CRSAKeyPairGenImpl* CRSAKeyPairGenImpl::NewL(void) + { + CRSAKeyPairGenImpl* self = CRSAKeyPairGenImpl::NewLC(); + CleanupStack::Pop(self); + return self; + } + +CRSAKeyPairGenImpl* CRSAKeyPairGenImpl::NewLC(void) + { + CRSAKeyPairGenImpl* self = new(ELeave) CRSAKeyPairGenImpl(); + CleanupStack::PushL(self); + self->ConstructL(); + return self; + } + +void CRSAKeyPairGenImpl::ConstructL(void) + { + CKeyPairGenImpl::ConstructL(); + } + +CExtendedCharacteristics* CRSAKeyPairGenImpl::CreateExtendedCharacteristicsL() + { + // All Symbian software plug-ins have unlimited concurrency, cannot be reserved + // for exclusive use and are not CERTIFIED to be standards compliant. + return CExtendedCharacteristics::NewL(KMaxTInt, EFalse); +} + +const CExtendedCharacteristics* CRSAKeyPairGenImpl::GetExtendedCharacteristicsL() + { + return CRSAKeyPairGenImpl::CreateExtendedCharacteristicsL(); + } + +TUid CRSAKeyPairGenImpl::ImplementationUid() const + { + return KCryptoPluginRsaKeyPairGenUid; + } + +void CRSAKeyPairGenImpl::Reset() + { + // does nothing in this plugin + } + +void CRSAKeyPairGenImpl::GenerateKeyPairL(TInt aKeySize, const CCryptoParams& aKeyParameters, CKeyPair*& aKeyPair) + { + /* + * extract e + */ + const TInt aKeyType = aKeyParameters.GetTIntL(KRsaKeyTypeUid); + const TInt aPublicExponent = aKeyParameters.GetTIntL(KRsaKeyParameterEUid); + + RInteger e = RInteger::NewL(aPublicExponent); + CleanupStack::PushL(e); + + /* + * calculate p, q, n & d + */ + RInteger p; + RInteger q; + + //these make sure n is a least aKeySize long + TInt pbits=(aKeySize+1)/2; + TInt qbits=aKeySize-pbits; + + //generate a prime p such that GCD(e,p-1) == 1 + for (;;) + { + p = RInteger::NewPrimeL(pbits,TInteger::ETop2BitsSet); + CleanupStack::PushL(p); + --p; + + RInteger gcd = e.GCDL(p); + if( gcd == 1 ) + { + ++p; + gcd.Close(); + //p is still on cleanup stack + break; + } + CleanupStack::PopAndDestroy(&p); + gcd.Close(); + } + + //generate a prime q such that GCD(e,q-1) == 1 && (p != q) + for (;;) + { + q = RInteger::NewPrimeL(qbits,TInteger::ETop2BitsSet); + CleanupStack::PushL(q); + --q; + + RInteger gcd = e.GCDL(q); + if( gcd == 1 ) + { + ++q; + if( p != q ) + { + gcd.Close(); + //q is still on cleanup stack + break; + } + } + CleanupStack::PopAndDestroy(&q); + gcd.Close(); + } + + //make sure p > q + if ( p < q) + { + TClassSwap(p,q); + } + + //calculate n = p * q + RInteger n = p.TimesL(q); + CleanupStack::PushL(n); + + --p; + --q; + + //temp = (p-1)(q-1) + RInteger temp = p.TimesL(q); + CleanupStack::PushL(temp); + + //e * d = 1 mod ((p-1)(q-1)) + //d = e^(-1) mod ((p-1)(q-1)) + RInteger d = e.InverseModL(temp); + CleanupStack::PopAndDestroy(&temp); //temp + CleanupStack::PushL(d); + + /* + * create private key depending on aKeyType + */ + CCryptoParams* privateKeyParameters = CCryptoParams::NewLC(); + privateKeyParameters->AddL(n, KRsaKeyParameterNUid); + TKeyProperty* privateKeyProperties = NULL; + TKeyProperty privateKeyProperties_RsaPrivateKeyCRT = {KRSAKeyPairGeneratorUid, KCryptoPluginRsaKeyPairGenUid, + KRsaPrivateKeyCRTUid, KNonEmbeddedKeyUid }; + TKeyProperty privateKeyProperties_RsaPrivateKeyStandard = {KRSAKeyPairGeneratorUid, KCryptoPluginRsaKeyPairGenUid, + KRsaPrivateKeyStandardUid, KNonEmbeddedKeyUid }; + + CCryptoParams*publicKeyParameters = CCryptoParams::NewLC(); + publicKeyParameters->AddL(n, KRsaKeyParameterNUid); + publicKeyParameters->AddL(e, KRsaKeyParameterEUid); + TKeyProperty publicKeyProperties = {KRSAKeyPairGeneratorUid, KCryptoPluginRsaKeyPairGenUid, + KRsaPublicKeyUid, KNonEmbeddedKeyUid }; + + if (aKeyType == KRsaPrivateKeyCRT) // cleanup stack contains e, p, q, n, d and privateKeyParameters + { + + /* + * calculate dP, dQ and qInv + */ + //calculate dP = d mod (p-1) + RInteger dP = d.ModuloL(p); //p is still p-1 + CleanupStack::PushL(dP); + privateKeyParameters->AddL(dP, KRsaKeyParameterDPUid); + CleanupStack::PopAndDestroy(&dP); + + //calculate dQ = d mod (q-1) + RInteger dQ = d.ModuloL(q); //q is still q-1 + CleanupStack::PushL(dQ); + privateKeyParameters->AddL(dQ, KRsaKeyParameterDQUid); + CleanupStack::PopAndDestroy(&dQ); + + ++p; + ++q; + //calculate inverse of qInv = q^(-1)mod(p) + RInteger qInv = q.InverseModL(p); + CleanupStack::PushL(qInv); + privateKeyParameters->AddL(qInv, KRsaKeyParameterQInvUid); + CleanupStack::PopAndDestroy(&qInv); + + privateKeyParameters->AddL(p, KRsaKeyParameterPUid); + privateKeyParameters->AddL(q, KRsaKeyParameterQUid); + + privateKeyProperties = &privateKeyProperties_RsaPrivateKeyCRT; + } + else if (aKeyType == KRsaPrivateKeyStandard) + { + privateKeyParameters->AddL(d, KRsaKeyParameterDUid); + privateKeyProperties = &privateKeyProperties_RsaPrivateKeyStandard; + } + else + { + User::Leave(KErrNotSupported); + } + // cleanup stack contains e, p, q, n, d and privateKeyParameters + CKey* privateKey = CKey::NewL(*privateKeyProperties, *privateKeyParameters); + CleanupStack::PushL(privateKey); + + /* + * create public key + */ + CKey* publicKey = CKey::NewL(publicKeyProperties, *publicKeyParameters); + CleanupStack::PushL(publicKey); + + /* + * create the key pair + */ + aKeyPair = CKeyPair::NewL(publicKey, privateKey); + + CleanupStack::Pop(2, privateKey); //privateKey and publicKey + CleanupStack::PopAndDestroy(7, &e); //e, p, q, n, d, privateKeyParameters and publicKeyParameters + } diff -r 7e3f204e6c81 -r f9c11be8c0b3 cryptoplugins/cryptospiplugins/source/softwarecrypto/rsakeypairgenimpl.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/cryptoplugins/cryptospiplugins/source/softwarecrypto/rsakeypairgenimpl.h Tue Dec 01 11:12:04 2009 +0000 @@ -0,0 +1,70 @@ +/* +* Copyright (c) 2006-2009 Nokia Corporation and/or its subsidiary(-ies). +* All rights reserved. +* This component and the accompanying materials are made available +* under the terms of the License "Eclipse Public License v1.0" +* which accompanies this distribution, and is available +* at the URL "http://www.eclipse.org/legal/epl-v10.html". +* +* Initial Contributors: +* Nokia Corporation - initial contribution. +* +* Contributors: +* +* Description: +* +*/ + + +#ifndef __RSAKEYPAIRGENIMPL_H__ +#define __RSAKEYPAIRGENIMPL_H__ + +/** +@file +@internalComponent +@released +*/ + +#include +#include +#include "keypairgenimpl.h" + +/** + * Implementation of RSA key pair generation as described in PKCS#1 v1.5. + */ +namespace SoftwareCrypto + { + NONSHARABLE_CLASS(CRSAKeyPairGenImpl) : public CKeyPairGenImpl + { + public: + + static CRSAKeyPairGenImpl* NewL(); + static CRSAKeyPairGenImpl* NewLC(); + + // from MPlugin + void Reset(); + + // from MKeyPairGenerator + void GenerateKeyPairL(TInt aKeySize, const CCryptoParams& aKeyParameters, CKeyPair*& aKeyPair); + + // Override CKeyPairGenImpl virtual functions + TUid ImplementationUid() const; + + const CExtendedCharacteristics* GetExtendedCharacteristicsL(); + static CExtendedCharacteristics* CreateExtendedCharacteristicsL(); + + // Destructor + ~CRSAKeyPairGenImpl(); + + private: + /** + Constructor + */ + CRSAKeyPairGenImpl(); + + /// second phase of construction + void ConstructL(); + }; + } + +#endif // __RSAKEYPAIRGENIMPL_H__ diff -r 7e3f204e6c81 -r f9c11be8c0b3 cryptoplugins/cryptospiplugins/source/softwarecrypto/rsasignerimpl.cpp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/cryptoplugins/cryptospiplugins/source/softwarecrypto/rsasignerimpl.cpp Tue Dec 01 11:12:04 2009 +0000 @@ -0,0 +1,132 @@ +/* +* Copyright (c) 2006-2009 Nokia Corporation and/or its subsidiary(-ies). +* All rights reserved. +* This component and the accompanying materials are made available +* under the terms of the License "Eclipse Public License v1.0" +* which accompanies this distribution, and is available +* at the URL "http://www.eclipse.org/legal/epl-v10.html". +* +* Initial Contributors: +* Nokia Corporation - initial contribution. +* +* Contributors: +* +* Description: +* +*/ + + +#include "rsasignerimpl.h" +#include "pluginconfig.h" +#include "rsafunction.h" + +using namespace SoftwareCrypto; + +// Implementation of CRSASignerImpl +CRSASignerImpl* CRSASignerImpl::NewL(const CKey& aKey, TUid aPaddingMode) + { + CRSASignerImpl* self = CRSASignerImpl::NewLC(aKey, aPaddingMode); + CleanupStack::Pop(self); + return self; + } + +CRSASignerImpl* CRSASignerImpl::NewLC(const CKey& aKey, TUid aPaddingMode) + { + CRSASignerImpl* self = new(ELeave) CRSASignerImpl(aPaddingMode); + CleanupStack::PushL(self); + self->ConstructL(aKey); + return self; + } + +CRSASignerImpl::CRSASignerImpl(TUid aPaddingMode) + : iPaddingMode(aPaddingMode) + { + } + +CRSASignerImpl::~CRSASignerImpl() + { + delete iPadding; + } + +void CRSASignerImpl::ConstructL(const CKey& aKey) + { + CSignerImpl::ConstructL(aKey); + SetPaddingModeL(iPaddingMode); + } + +CExtendedCharacteristics* CRSASignerImpl::CreateExtendedCharacteristicsL() + { + // All Symbian software plug-ins have unlimited concurrency, cannot be reserved + // for exclusive use and are not CERTIFIED to be standards compliant. + return CExtendedCharacteristics::NewL(KMaxTInt, EFalse); + } + +const CExtendedCharacteristics* CRSASignerImpl::GetExtendedCharacteristicsL() + { + return CRSASignerImpl::CreateExtendedCharacteristicsL(); + } + +TUid CRSASignerImpl::ImplementationUid() const + { + return KCryptoPluginRsaSignerUid; + } + +void CRSASignerImpl::SetKeyL(const CKey& aPrivateKey) + { + DoSetKeyL(aPrivateKey); + Reset(); + } + +void CRSASignerImpl::SetPaddingModeL(TUid aPaddingMode) + { + CPadding* padding(0); + switch (aPaddingMode.iUid) + { + case KPaddingModeNone: + padding = CPaddingNone::NewL(GetMaximumOutputLengthL()); + break; + case KPaddingModePkcs1_v1_5_Signature: + padding = CPaddingPKCS1Signature::NewL(GetMaximumOutputLengthL()); + break; + default: + User::Leave(KErrNotSupported); + } + + delete iPadding; + iPadding = padding; + iPaddingMode = aPaddingMode; + Reset(); + } + +TInt CRSASignerImpl::GetMaximumInputLengthL() const + { + return GetMaximumOutputLengthL() - iPadding->MinPaddingLength(); + } + +TInt CRSASignerImpl::GetMaximumOutputLengthL() const + { + const TInteger& paramN = iKey->GetBigIntL(KRsaKeyParameterNUid); + return paramN.ByteCount(); + } + +void CRSASignerImpl::SignL(const TDesC8& aInput, CCryptoParams& aSignature) + { + HBufC8* buf = HBufC8::NewLC(GetMaximumOutputLengthL()); + TPtr8 ptr = buf->Des(); + + //The following will panic if aInput is larger than MaxOutputLength() It is + //likely that the caller has passed in something that has not been hashed. + //This is a programming, and likely a security error, in client code, not a + //problem here. + iPadding->PadL(aInput, ptr); + + RInteger input = RInteger::NewL(ptr); + CleanupClosePushL(input); + RInteger output; + + RSAFunction::SignL(*iKey, input, output); + CleanupClosePushL(output); + + aSignature.AddL(output, KRsaSignatureParameterSUid); + CleanupStack::PopAndDestroy(3, buf); //input, buf + } diff -r 7e3f204e6c81 -r f9c11be8c0b3 cryptoplugins/cryptospiplugins/source/softwarecrypto/rsasignerimpl.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/cryptoplugins/cryptospiplugins/source/softwarecrypto/rsasignerimpl.h Tue Dec 01 11:12:04 2009 +0000 @@ -0,0 +1,96 @@ +/* +* Copyright (c) 2006-2009 Nokia Corporation and/or its subsidiary(-ies). +* All rights reserved. +* This component and the accompanying materials are made available +* under the terms of the License "Eclipse Public License v1.0" +* which accompanies this distribution, and is available +* at the URL "http://www.eclipse.org/legal/epl-v10.html". +* +* Initial Contributors: +* Nokia Corporation - initial contribution. +* +* Contributors: +* +* Description: +* +*/ + + +#ifndef __RSASIGNERIMPL_H__ +#define __RSASIGNERIMPL_H__ + +/** +@file +@internalComponent +@released +*/ + +#include +#include +#include + +#include "signerimpl.h" +#include "common/inlines.h" + +/** + * Implementation of RSA signing + */ +namespace SoftwareCrypto + { + using namespace CryptoSpi; + + NONSHARABLE_CLASS(CRSASignerImpl) : public CSignerImpl + { + public: + /** + Creates an instance of an RSA signer plug-in. + @param aKey The private key used to sign. + @param aPaddingMode The padding mode + @return A pointer to a CRSASignerImpl instance + */ + static CRSASignerImpl* NewL(const CKey& aKey, TUid aPaddingMode); + + /** + Creates an instance of an RSA signer plug-in. + @param aKey The private key used to sign. + @param aPaddingMode The padding mode + @return A pointer to a CRSASignerImpl instance + */ + static CRSASignerImpl* NewLC(const CKey& aKey, TUid aPaddingMode); + + // Override CSignerImpl virtual functions + TUid ImplementationUid() const; + // End of CSignerImpl + + // Override MSignatureBase virtual functions + void SetKeyL(const CKey& aPrivateKey); + void SetPaddingModeL(TUid aPaddingMode); + TInt GetMaximumInputLengthL() const; + TInt GetMaximumOutputLengthL() const; + // End of MSignatureBase + + // Override MSigner virtual functions + void SignL(const TDesC8& aInput, CCryptoParams& aSignature); + // End of MSigner + + const CExtendedCharacteristics* GetExtendedCharacteristicsL(); + static CExtendedCharacteristics* CreateExtendedCharacteristicsL(); + + /// Destructor + ~CRSASignerImpl(); + + protected: + /// Constructor + CRSASignerImpl(TUid aPaddingMode); + + /// second phase of construction + virtual void ConstructL(const CKey& aKey); + + protected: + /// the current padding scheme + TUid iPaddingMode; + CPadding* iPadding; + }; + } + +#endif // __RSASIGNERIMPL_H__ diff -r 7e3f204e6c81 -r f9c11be8c0b3 cryptoplugins/cryptospiplugins/source/softwarecrypto/rsaverifyimpl.cpp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/cryptoplugins/cryptospiplugins/source/softwarecrypto/rsaverifyimpl.cpp Tue Dec 01 11:12:04 2009 +0000 @@ -0,0 +1,143 @@ +/* +* Copyright (c) 2006-2009 Nokia Corporation and/or its subsidiary(-ies). +* All rights reserved. +* This component and the accompanying materials are made available +* under the terms of the License "Eclipse Public License v1.0" +* which accompanies this distribution, and is available +* at the URL "http://www.eclipse.org/legal/epl-v10.html". +* +* Initial Contributors: +* Nokia Corporation - initial contribution. +* +* Contributors: +* +* Description: +* +*/ + + +#include "rsaverifyimpl.h" +#include "pluginconfig.h" +#include "rsafunction.h" + +using namespace SoftwareCrypto; + +// Implementation of CRSAVerifierImpl +CRSAVerifierImpl* CRSAVerifierImpl::NewL(const CKey& aKey, TUid aPaddingMode) + { + CRSAVerifierImpl* self = CRSAVerifierImpl::NewLC(aKey, aPaddingMode); + CleanupStack::Pop(self); + return self; + } + +CRSAVerifierImpl* CRSAVerifierImpl::NewLC(const CKey& aKey, TUid aPaddingMode) + { + CRSAVerifierImpl* self = new(ELeave) CRSAVerifierImpl(aPaddingMode); + CleanupStack::PushL(self); + self->ConstructL(aKey); + return self; + } + +CRSAVerifierImpl::CRSAVerifierImpl(TUid aPaddingMode) + : iPaddingMode(aPaddingMode) + { + } + +CRSAVerifierImpl::~CRSAVerifierImpl() + { + delete iPadding; + } + +void CRSAVerifierImpl::ConstructL(const CKey& aKey) + { + CVerifierImpl::ConstructL(aKey); + SetPaddingModeL(iPaddingMode); + } + +CExtendedCharacteristics* CRSAVerifierImpl::CreateExtendedCharacteristicsL() + { + // All Symbian software plug-ins have unlimited concurrency, cannot be reserved + // for exclusive use and are not CERTIFIED to be standards compliant. + return CExtendedCharacteristics::NewL(KMaxTInt, EFalse); + } + +const CExtendedCharacteristics* CRSAVerifierImpl::GetExtendedCharacteristicsL() + { + return CRSAVerifierImpl::CreateExtendedCharacteristicsL(); + } + +TUid CRSAVerifierImpl::ImplementationUid() const + { + return KCryptoPluginRsaVerifierUid; + } + +void CRSAVerifierImpl::SetPaddingModeL(TUid aPaddingMode) + { + CPadding* padding(0); + switch (aPaddingMode.iUid) + { + case KPaddingModeNone: + padding = CPaddingNone::NewL(GetMaximumOutputLengthL()); + break; + case KPaddingModePkcs1_v1_5_Signature: + padding = CPaddingPKCS1Signature::NewL(GetMaximumOutputLengthL()); + break; + default: + User::Leave(KErrNotSupported); + } + delete iPadding; + iPadding = padding; + iPaddingMode = aPaddingMode; + Reset(); + } + +void CRSAVerifierImpl::SetKeyL(const CKey& aPublicKey) + { + DoSetKeyL(aPublicKey); + Reset(); + } + +TInt CRSAVerifierImpl::GetMaximumInputLengthL() const + { + return GetMaximumOutputLengthL() - iPadding->MinPaddingLength(); + } + +TInt CRSAVerifierImpl::GetMaximumOutputLengthL() const + { + const TInteger& paramN = iKey->GetBigIntL(KRsaKeyParameterNUid); + return paramN.ByteCount(); + } + +void CRSAVerifierImpl::VerifyL(const TDesC8& aInput, const CCryptoParams& aSignature, TBool& aVerificationResult) + { + HBufC8* output = NULL; + InverseSignL(output, aSignature); + CleanupStack::PushL(output); + + // is the original hash the same as the hash extracted from the signature + aVerificationResult = EFalse; + if (!output->Compare(aInput)) + { + aVerificationResult = ETrue; + } + CleanupStack::PopAndDestroy(output); + } + +void CRSAVerifierImpl::InverseSignL(HBufC8*& aOutput, const CCryptoParams& aSignature) + { + // extract the original hash from the signature + const TInteger& signature = aSignature.GetBigIntL(KRsaSignatureParameterSUid); + RInteger output; + RSAFunction::VerifyL(*iKey, signature, output); + CleanupClosePushL(output); + + // format the extracted hash so it can be compared with the original hash + HBufC8* paddedHashPtr = output.BufferLC(); + aOutput = HBufC8::NewLC(GetMaximumOutputLengthL()); + TPtr8 unpaddedHash = aOutput->Des(); + + iPadding->UnPadL(*paddedHashPtr, unpaddedHash); + + CleanupStack::Pop(aOutput); + CleanupStack::PopAndDestroy(2, &output); + } diff -r 7e3f204e6c81 -r f9c11be8c0b3 cryptoplugins/cryptospiplugins/source/softwarecrypto/rsaverifyimpl.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/cryptoplugins/cryptospiplugins/source/softwarecrypto/rsaverifyimpl.h Tue Dec 01 11:12:04 2009 +0000 @@ -0,0 +1,97 @@ +/* +* Copyright (c) 2006-2009 Nokia Corporation and/or its subsidiary(-ies). +* All rights reserved. +* This component and the accompanying materials are made available +* under the terms of the License "Eclipse Public License v1.0" +* which accompanies this distribution, and is available +* at the URL "http://www.eclipse.org/legal/epl-v10.html". +* +* Initial Contributors: +* Nokia Corporation - initial contribution. +* +* Contributors: +* +* Description: +* +*/ + + +#ifndef __RSAVERIFYIMPL_H__ +#define __RSAVERIFYIMPL_H__ + +/** +@file +@internalComponent +@released +*/ + +#include +#include +#include + +#include "verifierimpl.h" +#include "common/inlines.h" + +/** + * Implementation of RSA verification + */ +namespace SoftwareCrypto + { + using namespace CryptoSpi; + + NONSHARABLE_CLASS(CRSAVerifierImpl) : public CVerifierImpl + { + public: + /** + Creates an instance of an RSA verifier plug-in. + @param aKey The key + @param aPaddingMode The padding mode + @return A pointer to a CRSAVerifierImpl instance + */ + static CRSAVerifierImpl* NewL(const CKey& aKey, TUid aPaddingMode); + + /** + Creates an instance of an RSA verifier plug-in. + @param aKey The key + @param aPaddingMode The padding mode + @return A pointer to a CRSAVerifierImpl instance + */ + static CRSAVerifierImpl* NewLC(const CKey& aKey, TUid aPaddingMode); + + // Override CVerifierImpl virtual functions + TUid ImplementationUid() const; + // End of CVerifierImpl + + // Override MSignatureBase virtual functions + void SetPaddingModeL(TUid aPaddingMode); + void SetKeyL(const CKey& aPublicKey); + TInt GetMaximumInputLengthL() const; + TInt GetMaximumOutputLengthL() const; + // End of MSignatureBase + + // Override MSigner virtual functions + void VerifyL(const TDesC8& aInput, const CCryptoParams& aSignature, TBool& aVerificationResult); + void InverseSignL(HBufC8*& aOutput, const CCryptoParams& aSignature); + // End of MSigner + + const CExtendedCharacteristics* GetExtendedCharacteristicsL(); + static CExtendedCharacteristics* CreateExtendedCharacteristicsL(); + + /// Destructor + ~CRSAVerifierImpl(); + + protected: + /// Constructor + CRSAVerifierImpl(TUid aPaddingMode); + + /// second phase of construction + virtual void ConstructL(const CKey& aKey); + + protected: + /// the current padding scheme + TUid iPaddingMode; + CPadding* iPadding; + }; + } + +#endif // __RSAVERIFYIMPL_H__ diff -r 7e3f204e6c81 -r f9c11be8c0b3 cryptoplugins/cryptospiplugins/source/softwarecrypto/sha1impl.cpp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/cryptoplugins/cryptospiplugins/source/softwarecrypto/sha1impl.cpp Tue Dec 01 11:12:04 2009 +0000 @@ -0,0 +1,741 @@ +/* +* Copyright (c) 2006-2009 Nokia Corporation and/or its subsidiary(-ies). +* All rights reserved. +* This component and the accompanying materials are made available +* under the terms of the License "Eclipse Public License v1.0" +* which accompanies this distribution, and is available +* at the URL "http://www.eclipse.org/legal/epl-v10.html". +* +* Initial Contributors: +* Nokia Corporation - initial contribution. +* +* Contributors: +* +* Description: +* software sha1 implementation +* software sha1 implementation +* +*/ + + +/** + @file +*/ + +#include "sha1impl.h" + +#include +#include "pluginconfig.h" +#define EXPANDLOOP + + +using namespace SoftwareCrypto; + +CSHA1Impl* CSHA1Impl::NewL() + { + CSHA1Impl* self=new (ELeave) CSHA1Impl(); + self->Reset(); + return self; + } + +CSHA1Impl* CSHA1Impl::NewLC() + { + CSHA1Impl* self=NewL(); + CleanupStack::PushL(self); + return self; + } + +CSHA1Impl::CSHA1Impl() : iHash(KSHA1HashSize) + { + } + +CSHA1Impl::CSHA1Impl(const CSHA1Impl& aSHA1Impl) +: iHash(aSHA1Impl.iHash),iA(aSHA1Impl.iA),iB(aSHA1Impl.iB),iC(aSHA1Impl.iC),iD(aSHA1Impl.iD),iE(aSHA1Impl.iE), + iNl(aSHA1Impl.iNl),iNh(aSHA1Impl.iNh) + { + (void)Mem::Copy(iData, aSHA1Impl.iData, KSHA1BlockSize*5); + } + +CSHA1Impl::~CSHA1Impl() + { + } + +void CSHA1Impl::Reset() + { + iA=0x67452301; + iB=0xefcdab89; + iC=0x98badcfe; + iD=0x10325476; + iE=0xc3d2e1f0; + iNh=0; + iNl=0; + } + +void CSHA1Impl::Close() + { + delete this; + } + +MHash* CSHA1Impl::ReplicateL() + { + return CSHA1Impl::NewL(); + } + +MHash* CSHA1Impl::CopyL() + { + return new(ELeave) CSHA1Impl(*this); + } + +TUid CSHA1Impl::ImplementationUid() + { + return KCryptoPluginSha1Uid; + } + +void CSHA1Impl::GetCharacteristicsL(const TCharacteristics*& aPluginCharacteristics) + { + aPluginCharacteristics=NULL; + TInt hashNum=sizeof(KHashCharacteristics)/sizeof(THashCharacteristics*); + for (TInt i=0;icmn.iImplementationUID == ImplementationUid().iUid) + { + aPluginCharacteristics = KHashCharacteristics[i]; + break; + } + } + } + +CExtendedCharacteristics* CSHA1Impl::CreateExtendedCharacteristicsL() + { + // All Symbian software plug-ins have unlimited concurrency, cannot be reserved + // for exclusive use and are not CERTIFIED to be standards compliant. + return CExtendedCharacteristics::NewL(KMaxTInt, EFalse); + } + +const CExtendedCharacteristics* CSHA1Impl::GetExtendedCharacteristicsL() + { + return CSHA1Impl::CreateExtendedCharacteristicsL(); + } + +TPtrC8 CSHA1Impl::Hash(const TDesC8& aMessage) + { + TPtrC8 ptr(KNullDesC8()); + DoUpdate(aMessage.Ptr(),aMessage.Size()); + StoreState(); + DoFinal(); + ptr.Set(iHash); + RestoreState(); + return ptr; + } + +void CSHA1Impl::Update(const TDesC8& aMessage) + { + DoUpdate(aMessage.Ptr(),aMessage.Size()); + } + +TPtrC8 CSHA1Impl::Final(const TDesC8& aMessage) + { + TPtrC8 ptr(KNullDesC8()); + if (aMessage!=KNullDesC8()) + { + DoUpdate(aMessage.Ptr(),aMessage.Size()); + } + DoFinal(); + ptr.Set(iHash); + Reset(); + return ptr; + } + + +// This assumes a big-endian architecture +void CSHA1Impl::DoUpdate(const TUint8* aData,TUint aLength) + { + while((aLength / 4) > 0 && (iNl % 4 == 0)) + { + iData[iNl>>2] = aData[0] << 24 | aData[1] << 16 | aData[2] << 8 | aData[3]; + iNl+=4; + aData+=4; + aLength-=4; + if(iNl==64) + { + Block(); + iNh+=64; + iNl=0; + } + } + + while(aLength--) + { + switch (iNl&3) + { + case 0: + iData[iNl>>2]=((TUint)(*aData))<<24; + break; + case 1: + iData[iNl>>2]|=((TUint)(*aData))<<16; + break; + case 2: + iData[iNl>>2]|=((TUint)(*aData))<<8; + break; + case 3: + iData[iNl>>2]|=((TUint)(*aData)); + break; + default: + break; + }; + aData++; + iNl++; + if(iNl==64) + { + Block(); + iNh+=64; + iNl=0; + } + } + } + +static inline TUint CSHA1_F(const TUint x,const TUint y,const TUint z) + { + return (x&y) | (~x&z); + } + +static inline TUint CSHA1_G(const TUint x,const TUint y,const TUint z) + { + return x^y^z; + } + +static inline TUint CSHA1_H(const TUint x,const TUint y,const TUint z) + { + return (x&y) | (x&z) | (y&z); + } + +/*static inline TUint CSHA1_I(const TUint x,const TUint y,const TUint z) + { + return x^y^z; + }*/ + +#ifdef EXPANDLOOP + +#ifdef MACRO + +#define CSHA1_16(x,y,z,u,t,v,w) v=CMD_R(x,5)+CSHA1_F(y,z,u)+t+w+0x5a827999;\ + y=CMD_R(y,30);t=v; +#define CSHA1_20(x,y,z,u,t,v,w0,w3,w8,w14,w16) v=w3^w8^w14^w16;w0=CMD_R(v,1);\ + CSHA1_16(x,y,z,u,t,v,w0); +#define CSHA1_40(x,y,z,u,t,v,w0,w3,w8,w14,w16) v=w3^w8^w14^w16;w0=CMD_R(v,1);\ + v=CMD_R(x,5)+CSHA1_G(y,z,u)+t+w0+0x6ed9eba1;\ + y=CMD_R(y,30);t=v; +#define CSHA1_60(x,y,z,u,t,v,w0,w3,w8,w14,w16) v=w3^w8^w14^w16;w0=CMD_R(v,1);\ + v=CMD_R(x,5)+CSHA1_H(y,z,u)+t+w0+0x8f1bbcdc;\ + y=CMD_R(y,30);t=v; +#define CSHA1_80(x,y,z,u,t,v,w0,w3,w8,w14,w16) v=w3^w8^w14^w16;w0=CMD_R(v,1);\ + v=CMD_R(x,5)+CSHA1_G(y,z,u)+t+w0+0xca62c1d6;\ + y=CMD_R(y,30);t=v; +#else + +static inline void CSHA1_16(const TUint x, TUint& y, const TUint z, + const TUint u, TUint& t, TUint& v, const TUint w) + { + v = CMD_R(x,5) + CSHA1_F(y,z,u) + t + w + 0x5a827999; + y = CMD_R(y,30); + t = v; + } + +static inline void CSHA1_20(const TUint x,TUint& y,const TUint z, + const TUint u,TUint& t,TUint& v, + TUint& w0,const TUint w3,const TUint w8, + const TUint w14,const TUint w16) + { + v = w3 ^ w8 ^ w14 ^ w16; + w0 = CMD_R(v,1); + CSHA1_16(x,y,z,u,t,v,w0); + } + +static inline void CSHA1_40(const TUint x,TUint& y,const TUint z, + const TUint u,TUint& t,TUint& v, + TUint& w0,const TUint w3,const TUint w8, + const TUint w14,const TUint w16) + { + v = w3 ^ w8 ^ w14 ^ w16; + w0 = CMD_R(v,1); + v = CMD_R(x,5) + CSHA1_G(y,z,u) + t + w0 + 0x6ed9eba1; + y = CMD_R(y,30); + t = v; + } + +static inline void CSHA1_60(const TUint x,TUint& y,const TUint z, + const TUint u,TUint& t,TUint& v, + TUint& w0,const TUint w3,const TUint w8, + const TUint w14,const TUint w16) + { + v = w3 ^ w8 ^ w14 ^ w16; + w0 = CMD_R(v,1); + v = CMD_R(x,5) + CSHA1_H(y,z,u) + t + w0 + 0x8f1bbcdc; + y = CMD_R(y,30); + t = v; + } + +static inline void CSHA1_80(const TUint x,TUint& y,const TUint z, + const TUint u,TUint& t,TUint& v, + TUint& w0,const TUint w3,const TUint w8, + const TUint w14,const TUint w16) + { + v = w3 ^ w8 ^ w14 ^ w16; + w0 = CMD_R(v,1); + v = CMD_R(x,5) + CSHA1_G(y,z,u) + t + w0 + 0xca62c1d6; + y = CMD_R(y,30); + t = v; + } + +#endif // MACRO +#endif // EXPANDLOOP + +#ifdef WEIDAI + +template inline T rotlFixed(T x, unsigned int y) +{ + ASSERT(y < sizeof(T)*8); + return (x<>(sizeof(T)*8-y)); +} + +template<> inline TUint32 rotlFixed(TUint32 x, unsigned int y) +{ + ASSERT(y < 32); + return y ? CMD_R(x, y) : x; +} + +#define blk0(i) (W[i] = iData[i]) +#define blk1(i) (W[i&15] = rotlFixed(W[(i+13)&15]^W[(i+8)&15]^W[(i+2)&15]^W[i&15],1)) + +#define f1(x,y,z) (z^(x&(y^z))) +#define f2(x,y,z) (x^y^z) +#define f3(x,y,z) ((x&y)|(z&(x|y))) +#define f4(x,y,z) (x^y^z) + +/* (R0+R1), R2, R3, R4 are the different operations used in SHA1 */ +#define R0(v,w,x,y,z,i) z+=f1(w,x,y)+blk0(i)+0x5A827999+rotlFixed(v,5);w=rotlFixed(w,30); +#define R1(v,w,x,y,z,i) z+=f1(w,x,y)+blk1(i)+0x5A827999+rotlFixed(v,5);w=rotlFixed(w,30); +#define R2(v,w,x,y,z,i) z+=f2(w,x,y)+blk1(i)+0x6ED9EBA1+rotlFixed(v,5);w=rotlFixed(w,30); +#define R3(v,w,x,y,z,i) z+=f3(w,x,y)+blk1(i)+0x8F1BBCDC+rotlFixed(v,5);w=rotlFixed(w,30); +#define R4(v,w,x,y,z,i) z+=f4(w,x,y)+blk1(i)+0xCA62C1D6+rotlFixed(v,5);w=rotlFixed(w,30); + +#endif // WEIDAI + +void CSHA1Impl::Block() + { +#ifdef WEIDAI + TUint32 W[16]; + /* Copy context->state[] to working vars */ + TUint32 a = iA; + TUint32 b = iB; + TUint32 c = iC; + TUint32 d = iD; + TUint32 e = iE; + + /* 4 rounds of 20 operations each. Loop unrolled. */ + + R0(a,b,c,d,e, 0); + R0(e,a,b,c,d, 1); + R0(d,e,a,b,c, 2); + R0(c,d,e,a,b, 3); + R0(b,c,d,e,a, 4); + R0(a,b,c,d,e, 5); + R0(e,a,b,c,d, 6); + R0(d,e,a,b,c, 7); + R0(c,d,e,a,b, 8); + R0(b,c,d,e,a, 9); + R0(a,b,c,d,e,10); + R0(e,a,b,c,d,11); + R0(d,e,a,b,c,12); + R0(c,d,e,a,b,13); + R0(b,c,d,e,a,14); + R0(a,b,c,d,e,15); + + R1(e,a,b,c,d,16); + R1(d,e,a,b,c,17); + R1(c,d,e,a,b,18); + R1(b,c,d,e,a,19); + + R2(a,b,c,d,e,20); + R2(e,a,b,c,d,21); + R2(d,e,a,b,c,22); + R2(c,d,e,a,b,23); + R2(b,c,d,e,a,24); + R2(a,b,c,d,e,25); + R2(e,a,b,c,d,26); + R2(d,e,a,b,c,27); + R2(c,d,e,a,b,28); + R2(b,c,d,e,a,29); + R2(a,b,c,d,e,30); + R2(e,a,b,c,d,31); + R2(d,e,a,b,c,32); + R2(c,d,e,a,b,33); + R2(b,c,d,e,a,34); + R2(a,b,c,d,e,35); + R2(e,a,b,c,d,36); + R2(d,e,a,b,c,37); + R2(c,d,e,a,b,38); + R2(b,c,d,e,a,39); + + R3(a,b,c,d,e,40); + R3(e,a,b,c,d,41); + R3(d,e,a,b,c,42); + R3(c,d,e,a,b,43); + R3(b,c,d,e,a,44); + R3(a,b,c,d,e,45); + R3(e,a,b,c,d,46); + R3(d,e,a,b,c,47); + R3(c,d,e,a,b,48); + R3(b,c,d,e,a,49); + R3(a,b,c,d,e,50); + R3(e,a,b,c,d,51); + R3(d,e,a,b,c,52); + R3(c,d,e,a,b,53); + R3(b,c,d,e,a,54); + R3(a,b,c,d,e,55); + R3(e,a,b,c,d,56); + R3(d,e,a,b,c,57); + R3(c,d,e,a,b,58); + R3(b,c,d,e,a,59); + + R4(a,b,c,d,e,60); + R4(e,a,b,c,d,61); + R4(d,e,a,b,c,62); + R4(c,d,e,a,b,63); + R4(b,c,d,e,a,64); + R4(a,b,c,d,e,65); + R4(e,a,b,c,d,66); + R4(d,e,a,b,c,67); + R4(c,d,e,a,b,68); + R4(b,c,d,e,a,69); + R4(a,b,c,d,e,70); + R4(e,a,b,c,d,71); + R4(d,e,a,b,c,72); + R4(c,d,e,a,b,73); + R4(b,c,d,e,a,74); + R4(a,b,c,d,e,75); + R4(e,a,b,c,d,76); + R4(d,e,a,b,c,77); + R4(c,d,e,a,b,78); + R4(b,c,d,e,a,79); + + /* Add the working vars back into context.state[] */ + iA += a; + iB += b; + iC += c; + iD += d; + iE += e; + /* Wipe variables */ + a = b = c = d = e = 0; + Mem::FillZ(W, sizeof(W)); +#else + TUint tempA=iA; + TUint tempB=iB; + TUint tempC=iC; + TUint tempD=iD; + TUint tempE=iE; + TUint temp=0; + +#ifdef EXPANDLOOP + CSHA1_16(tempA,tempB,tempC,tempD,tempE,temp,iData[0]); + CSHA1_16(temp,tempA,tempB,tempC,tempD,tempE,iData[1]); + CSHA1_16(tempE,temp,tempA,tempB,tempC,tempD,iData[2]); + CSHA1_16(tempD,tempE,temp,tempA,tempB,tempC,iData[3]); + CSHA1_16(tempC,tempD,tempE,temp,tempA,tempB,iData[4]); + CSHA1_16(tempB,tempC,tempD,tempE,temp,tempA,iData[5]); + CSHA1_16(tempA,tempB,tempC,tempD,tempE,temp,iData[6]); + CSHA1_16(temp,tempA,tempB,tempC,tempD,tempE,iData[7]); + CSHA1_16(tempE,temp,tempA,tempB,tempC,tempD,iData[8]); + CSHA1_16(tempD,tempE,temp,tempA,tempB,tempC,iData[9]); + CSHA1_16(tempC,tempD,tempE,temp,tempA,tempB,iData[10]); + CSHA1_16(tempB,tempC,tempD,tempE,temp,tempA,iData[11]); + CSHA1_16(tempA,tempB,tempC,tempD,tempE,temp,iData[12]); + CSHA1_16(temp,tempA,tempB,tempC,tempD,tempE,iData[13]); + CSHA1_16(tempE,temp,tempA,tempB,tempC,tempD,iData[14]); + CSHA1_16(tempD,tempE,temp,tempA,tempB,tempC,iData[15]); + /* + i = 16; + TUint temp1 = tempA; + tempA = + */ +#else + TUint i=0; + while (i<16) + { + temp = CMD_R(tempA,5) + CSHA1_F(tempB,tempC,tempD) + tempE + iData[i++] + 0x5a827999; + tempE = tempD; + tempD = tempC; + tempC = CMD_R(tempB,30); + tempB = tempA; + tempA = temp; + } +#endif + +#ifdef EXPANDLOOP + CSHA1_20(tempC,tempD,tempE,temp,tempA,tempB,iData[16],iData[13],iData[8],iData[2],iData[0]); + CSHA1_20(tempB,tempC,tempD,tempE,temp,tempA,iData[17],iData[14],iData[9],iData[3],iData[1]); + CSHA1_20(tempA,tempB,tempC,tempD,tempE,temp,iData[18],iData[15],iData[10],iData[4],iData[2]); + CSHA1_20(temp,tempA,tempB,tempC,tempD,tempE,iData[19],iData[16],iData[11],iData[5],iData[3]); + //i = 20; +#else + while (i<20) + { + temp=iData[i-3] ^ iData[i-8] ^ iData[i-14] ^ iData[i-16]; + iData[i]=CMD_R(temp,1); + temp = CMD_R(tempA,5) + CSHA1_F(tempB,tempC,tempD) + tempE + iData[i++] + 0x5a827999; + tempE = tempD; + tempD = tempC; + tempC = CMD_R(tempB,30); + tempB = tempA; + tempA = temp; + } +#endif + +#ifdef EXPANDLOOP + CSHA1_40(tempE,temp,tempA,tempB,tempC,tempD,iData[20],iData[17],iData[12],iData[6],iData[4]); + CSHA1_40(tempD,tempE,temp,tempA,tempB,tempC,iData[21],iData[18],iData[13],iData[7],iData[5]); + CSHA1_40(tempC,tempD,tempE,temp,tempA,tempB,iData[22],iData[19],iData[14],iData[8],iData[6]); + CSHA1_40(tempB,tempC,tempD,tempE,temp,tempA,iData[23],iData[20],iData[15],iData[9],iData[7]); + CSHA1_40(tempA,tempB,tempC,tempD,tempE,temp,iData[24],iData[21],iData[16],iData[10],iData[8]); + CSHA1_40(temp,tempA,tempB,tempC,tempD,tempE,iData[25],iData[22],iData[17],iData[11],iData[9]); + CSHA1_40(tempE,temp,tempA,tempB,tempC,tempD,iData[26],iData[23],iData[18],iData[12],iData[10]); + CSHA1_40(tempD,tempE,temp,tempA,tempB,tempC,iData[27],iData[24],iData[19],iData[13],iData[11]); + CSHA1_40(tempC,tempD,tempE,temp,tempA,tempB,iData[28],iData[25],iData[20],iData[14],iData[12]); + CSHA1_40(tempB,tempC,tempD,tempE,temp,tempA,iData[29],iData[26],iData[21],iData[15],iData[13]); + CSHA1_40(tempA,tempB,tempC,tempD,tempE,temp,iData[30],iData[27],iData[22],iData[16],iData[14]); + CSHA1_40(temp,tempA,tempB,tempC,tempD,tempE,iData[31],iData[28],iData[23],iData[17],iData[15]); + CSHA1_40(tempE,temp,tempA,tempB,tempC,tempD,iData[32],iData[29],iData[24],iData[18],iData[16]); + CSHA1_40(tempD,tempE,temp,tempA,tempB,tempC,iData[33],iData[30],iData[25],iData[19],iData[17]); + CSHA1_40(tempC,tempD,tempE,temp,tempA,tempB,iData[34],iData[31],iData[26],iData[20],iData[18]); + CSHA1_40(tempB,tempC,tempD,tempE,temp,tempA,iData[35],iData[32],iData[27],iData[21],iData[19]); + CSHA1_40(tempA,tempB,tempC,tempD,tempE,temp,iData[36],iData[33],iData[28],iData[22],iData[20]); + CSHA1_40(temp,tempA,tempB,tempC,tempD,tempE,iData[37],iData[34],iData[29],iData[23],iData[21]); + CSHA1_40(tempE,temp,tempA,tempB,tempC,tempD,iData[38],iData[35],iData[30],iData[24],iData[22]); + CSHA1_40(tempD,tempE,temp,tempA,tempB,tempC,iData[39],iData[36],iData[31],iData[25],iData[23]); + //i = 40; +#else + while (i<40) + { + temp = iData[i-3] ^ iData[i-8] ^ iData[i-14] ^ iData[i-16]; + iData[i] = CMD_R(temp,1); + + temp = CMD_R(tempA,5) + CSHA1_G(tempB,tempC,tempD) + tempE + iData[i++] + 0x6ed9eba1; + tempE = tempD; + tempD = tempC; + tempC = CMD_R(tempB,30); + tempB = tempA; + tempA = temp; + } +#endif + +#ifdef EXPANDLOOP + CSHA1_60(tempC,tempD,tempE,temp,tempA,tempB,iData[40],iData[37],iData[32],iData[26],iData[24]); + CSHA1_60(tempB,tempC,tempD,tempE,temp,tempA,iData[41],iData[38],iData[33],iData[27],iData[25]); + CSHA1_60(tempA,tempB,tempC,tempD,tempE,temp,iData[42],iData[39],iData[34],iData[28],iData[26]); + CSHA1_60(temp,tempA,tempB,tempC,tempD,tempE,iData[43],iData[40],iData[35],iData[29],iData[27]); + CSHA1_60(tempE,temp,tempA,tempB,tempC,tempD,iData[44],iData[41],iData[36],iData[30],iData[28]); + CSHA1_60(tempD,tempE,temp,tempA,tempB,tempC,iData[45],iData[42],iData[37],iData[31],iData[29]); + CSHA1_60(tempC,tempD,tempE,temp,tempA,tempB,iData[46],iData[43],iData[38],iData[32],iData[30]); + CSHA1_60(tempB,tempC,tempD,tempE,temp,tempA,iData[47],iData[44],iData[39],iData[33],iData[31]); + CSHA1_60(tempA,tempB,tempC,tempD,tempE,temp,iData[48],iData[45],iData[40],iData[34],iData[32]); + CSHA1_60(temp,tempA,tempB,tempC,tempD,tempE,iData[49],iData[46],iData[41],iData[35],iData[33]); + CSHA1_60(tempE,temp,tempA,tempB,tempC,tempD,iData[50],iData[47],iData[42],iData[36],iData[34]); + CSHA1_60(tempD,tempE,temp,tempA,tempB,tempC,iData[51],iData[48],iData[43],iData[37],iData[35]); + CSHA1_60(tempC,tempD,tempE,temp,tempA,tempB,iData[52],iData[49],iData[44],iData[38],iData[36]); + CSHA1_60(tempB,tempC,tempD,tempE,temp,tempA,iData[53],iData[50],iData[45],iData[39],iData[37]); + CSHA1_60(tempA,tempB,tempC,tempD,tempE,temp,iData[54],iData[51],iData[46],iData[40],iData[38]); + CSHA1_60(temp,tempA,tempB,tempC,tempD,tempE,iData[55],iData[52],iData[47],iData[41],iData[39]); + CSHA1_60(tempE,temp,tempA,tempB,tempC,tempD,iData[56],iData[53],iData[48],iData[42],iData[40]); + CSHA1_60(tempD,tempE,temp,tempA,tempB,tempC,iData[57],iData[54],iData[49],iData[43],iData[41]); + CSHA1_60(tempC,tempD,tempE,temp,tempA,tempB,iData[58],iData[55],iData[50],iData[44],iData[42]); + CSHA1_60(tempB,tempC,tempD,tempE,temp,tempA,iData[59],iData[56],iData[51],iData[45],iData[43]); + //i = 60; +#else + while (i<60) + { + temp = iData[i-3] ^ iData[i-8] ^ iData[i-14] ^ iData[i-16]; + iData[i] = CMD_R(temp,1); + + temp = CMD_R(tempA,5) + CSHA1_H(tempB,tempC,tempD) + tempE + iData[i++] + 0x8f1bbcdc; + tempE = tempD; + tempD = tempC; + tempC = CMD_R(tempB,30); + tempB = tempA; + tempA = temp; + } +#endif + +#ifdef EXPANDLOOP + CSHA1_80(tempA,tempB,tempC,tempD,tempE,temp,iData[60],iData[57],iData[52],iData[46],iData[44]); + CSHA1_80(temp,tempA,tempB,tempC,tempD,tempE,iData[61],iData[58],iData[53],iData[47],iData[45]); + CSHA1_80(tempE,temp,tempA,tempB,tempC,tempD,iData[62],iData[59],iData[54],iData[48],iData[46]); + CSHA1_80(tempD,tempE,temp,tempA,tempB,tempC,iData[63],iData[60],iData[55],iData[49],iData[47]); + CSHA1_80(tempC,tempD,tempE,temp,tempA,tempB,iData[64],iData[61],iData[56],iData[50],iData[48]); + CSHA1_80(tempB,tempC,tempD,tempE,temp,tempA,iData[65],iData[62],iData[57],iData[51],iData[49]); + CSHA1_80(tempA,tempB,tempC,tempD,tempE,temp,iData[66],iData[63],iData[58],iData[52],iData[50]); + CSHA1_80(temp,tempA,tempB,tempC,tempD,tempE,iData[67],iData[64],iData[59],iData[53],iData[51]); + CSHA1_80(tempE,temp,tempA,tempB,tempC,tempD,iData[68],iData[65],iData[60],iData[54],iData[52]); + CSHA1_80(tempD,tempE,temp,tempA,tempB,tempC,iData[69],iData[66],iData[61],iData[55],iData[53]); + CSHA1_80(tempC,tempD,tempE,temp,tempA,tempB,iData[70],iData[67],iData[62],iData[56],iData[54]); + CSHA1_80(tempB,tempC,tempD,tempE,temp,tempA,iData[71],iData[68],iData[63],iData[57],iData[55]); + CSHA1_80(tempA,tempB,tempC,tempD,tempE,temp,iData[72],iData[69],iData[64],iData[58],iData[56]); + CSHA1_80(temp,tempA,tempB,tempC,tempD,tempE,iData[73],iData[70],iData[65],iData[59],iData[57]); + CSHA1_80(tempE,temp,tempA,tempB,tempC,tempD,iData[74],iData[71],iData[66],iData[60],iData[58]); + CSHA1_80(tempD,tempE,temp,tempA,tempB,tempC,iData[75],iData[72],iData[67],iData[61],iData[59]); + CSHA1_80(tempC,tempD,tempE,temp,tempA,tempB,iData[76],iData[73],iData[68],iData[62],iData[60]); + CSHA1_80(tempB,tempC,tempD,tempE,temp,tempA,iData[77],iData[74],iData[69],iData[63],iData[61]); + CSHA1_80(tempA,tempB,tempC,tempD,tempE,temp,iData[78],iData[75],iData[70],iData[64],iData[62]); + CSHA1_80(temp,tempA,tempB,tempC,tempD,tempE,iData[79],iData[76],iData[71],iData[65],iData[63]); +#else + const TUint total=KSHA1BlockSize*5; // 16 * 5 = 80 + while (i>2] = ul128<<24; + break; + case 1: + iData[iNl>>2] += ul128<<16; + break; + case 2: + iData[iNl>>2] += ul128<<8; + break; + case 3: + iData[iNl>>2] += ul128; + break; + default: + break; + }; + if (iNl>=56) + { + if (iNl<60) + iData[15]=0; + Block(); + Mem::FillZ(iData,14*sizeof(TUint)); + } + else + { + const TUint offset=(iNl+4)>>2; //+4 to account for the word added in the + //switch statement above + Mem::FillZ(iData+offset,(14-offset)*sizeof(TUint)); + } + + // this will fail if the total input length is longer than 2^32 in bits + //(2^31 in bytes) which is roughly half a gig. + iData[14]=0; + iData[15]=iNh<<3;//number in bits + Block(); + // + // Generate hash value into iHash + // + TUint tmp=iA; + iHash[3]=(TUint8)(tmp & 255); + iHash[2]=(TUint8)((tmp >>= 8) & 255); + iHash[1]=(TUint8)((tmp >>= 8) & 255); + iHash[0]=(TUint8)((tmp >>= 8) & 255); + + tmp=iB; + iHash[7]=(TUint8)(tmp & 255); + iHash[6]=(TUint8)((tmp >>= 8) & 255); + iHash[5]=(TUint8)((tmp >>= 8) & 255); + iHash[4]=(TUint8)((tmp >>= 8) & 255); + + tmp=iC; + iHash[11]=(TUint8)(tmp & 255); + iHash[10]=(TUint8)((tmp >>= 8) & 255); + iHash[9]=(TUint8)((tmp >>= 8) & 255); + iHash[8]=(TUint8)((tmp >>= 8) & 255); + + tmp=iD; + iHash[15]=(TUint8)(tmp & 255); + iHash[14]=(TUint8)((tmp >>= 8) & 255); + iHash[13]=(TUint8)((tmp >>= 8) & 255); + iHash[12]=(TUint8)((tmp >>= 8) & 255); + + tmp=iE; + iHash[19]=(TUint8)(tmp & 255); + iHash[18]=(TUint8)((tmp >>= 8) & 255); + iHash[17]=(TUint8)((tmp >>= 8) & 255); + iHash[16]=(TUint8)((tmp >>= 8) & 255); + } + +void CSHA1Impl::RestoreState() + { + iA = iACopy; + iB = iBCopy; + iC = iCCopy; + iD = iDCopy; + iE = iECopy; + iNl = iNlCopy; + iNh = iNhCopy; + Mem::Copy(&iData[0], &iDataCopy[0], KSHA1BlockSize*5*sizeof(TUint)); + } + +void CSHA1Impl::StoreState() + { + iACopy = iA; + iBCopy = iB; + iCCopy = iC; + iDCopy = iD; + iECopy = iE; + iNlCopy = iNl; + iNhCopy = iNh; + Mem::Copy(&iDataCopy[0], &iData[0], KSHA1BlockSize*5*sizeof(TUint)); + } + +// Implemented in hmacimpl.cpp or softwarehashbase.cpp +// but required as derived from MHash. No coverage here. +#ifdef _BullseyeCoverage +#pragma suppress_warnings on +#pragma BullseyeCoverage off +#pragma suppress_warnings off +#endif + +TAny* CSHA1Impl::GetExtension(TUid /*aExtensionId*/) + { + return NULL; + } + +void CSHA1Impl::SetOperationModeL(TUid /*aOperationMode*/) + { + User::Leave(KErrNotSupported); + } + +void CSHA1Impl::SetKeyL(const CKey& /*aKey*/) + { + User::Leave(KErrNotSupported); + } + diff -r 7e3f204e6c81 -r f9c11be8c0b3 cryptoplugins/cryptospiplugins/source/softwarecrypto/sha1impl.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/cryptoplugins/cryptospiplugins/source/softwarecrypto/sha1impl.h Tue Dec 01 11:12:04 2009 +0000 @@ -0,0 +1,102 @@ +/* +* Copyright (c) 2006-2009 Nokia Corporation and/or its subsidiary(-ies). +* All rights reserved. +* This component and the accompanying materials are made available +* under the terms of the License "Eclipse Public License v1.0" +* which accompanies this distribution, and is available +* at the URL "http://www.eclipse.org/legal/epl-v10.html". +* +* Initial Contributors: +* Nokia Corporation - initial contribution. +* +* Contributors: +* +* Description: +* Software md2 implementation +* +*/ + + +/** + @file + @internalComponent + @released +*/ + +#ifndef __CRYPTOAPI_SOFTWARESHA1IMPL_H__ +#define __CRYPTOAPI_SOFTWARESHA1IMPL_H__ + +#include "softwarehashbase.h" + +namespace SoftwareCrypto + { + using namespace CryptoSpi; + + const TInt KSHA1BlockSize = 16; + const TInt KSHA1HashSize = 20; + + NONSHARABLE_CLASS(CSHA1Impl) : public CBase, public MSoftwareHash + { + public: + //NewL & NewLC + static CSHA1Impl* NewL(); + static CSHA1Impl* NewLC(); + + //From MPlugin + void Reset(); + void Close(); + void GetCharacteristicsL(const TCharacteristics*& aPluginCharacteristics); + static CExtendedCharacteristics* CreateExtendedCharacteristicsL(); + const CExtendedCharacteristics* GetExtendedCharacteristicsL(); + TAny* GetExtension(TUid aExtensionId); + + //From MHash + TPtrC8 Hash(const TDesC8& aMessage); + void Update(const TDesC8& aMessage); + TPtrC8 Final(const TDesC8& aMessage); + MHash* ReplicateL(); + MHash* CopyL(); + void SetKeyL(const CKey& aKey); + void SetOperationModeL(TUid aOperationMode); + + //From MSoftwareHash + void RestoreState(); + void StoreState(); + + private: + //Constructors + CSHA1Impl(); + CSHA1Impl(const CSHA1Impl& aSHA1Impl); + + //Destructor + ~CSHA1Impl(); + + TUid ImplementationUid(); + + void DoUpdate(const TUint8* aData,TUint aLength); + void DoFinal(void); + void Block(); + + + private: + TBuf8 iHash; + TUint iA; + TUint iB; + TUint iC; + TUint iD; + TUint iE; + TUint iNl; + TUint iNh; + TUint iData[KSHA1BlockSize*5]; + + TUint iACopy; + TUint iBCopy; + TUint iCCopy; + TUint iDCopy; + TUint iECopy; + TUint iNlCopy; + TUint iNhCopy; + TUint iDataCopy[KSHA1BlockSize*5]; + }; + } +#endif // __CRYPTOAPI_SOFTWARESHA1IMPL_H__ diff -r 7e3f204e6c81 -r f9c11be8c0b3 cryptoplugins/cryptospiplugins/source/softwarecrypto/sha224and256impl.cpp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/cryptoplugins/cryptospiplugins/source/softwarecrypto/sha224and256impl.cpp Tue Dec 01 11:12:04 2009 +0000 @@ -0,0 +1,499 @@ +/* +* Copyright (c) 2007-2009 Nokia Corporation and/or its subsidiary(-ies). +* All rights reserved. +* This component and the accompanying materials are made available +* under the terms of the License "Eclipse Public License v1.0" +* which accompanies this distribution, and is available +* at the URL "http://www.eclipse.org/legal/epl-v10.html". +* +* Initial Contributors: +* Nokia Corporation - initial contribution. +* +* Contributors: +* +* Description: +* Common implementation of SHA224 and SHA256 +* RFC 4634 (US Secure Hash Algorithms (SHA and HMAC-SHA)) +* +*/ + + +/** + @file +*/ + + +#include +#include "pluginconfig.h" +#include "sha224and256impl.h" + +using namespace SoftwareCrypto; + +/** + * SHA256 Constants + * + * SHA-256 uses a sequence of sixty-four constant 32-bit words. + * These words represent the first thirty-two bits of the fractional + * parts of the cube roots of the first sixtyfour prime numbers. + * + * FIPS 180-2 Section 4.2.2 + */ +const TUint K[64] = + { + 0x428a2f98, 0x71374491, 0xb5c0fbcf, 0xe9b5dba5, + 0x3956c25b, 0x59f111f1, 0x923f82a4, 0xab1c5ed5, + 0xd807aa98, 0x12835b01, 0x243185be, 0x550c7dc3, + 0x72be5d74, 0x80deb1fe, 0x9bdc06a7, 0xc19bf174, + 0xe49b69c1, 0xefbe4786, 0x0fc19dc6, 0x240ca1cc, + 0x2de92c6f, 0x4a7484aa, 0x5cb0a9dc, 0x76f988da, + 0x983e5152, 0xa831c66d, 0xb00327c8, 0xbf597fc7, + 0xc6e00bf3, 0xd5a79147, 0x06ca6351, 0x14292967, + 0x27b70a85, 0x2e1b2138, 0x4d2c6dfc, 0x53380d13, + 0x650a7354, 0x766a0abb, 0x81c2c92e, 0x92722c85, + 0xa2bfe8a1, 0xa81a664b, 0xc24b8b70, 0xc76c51a3, + 0xd192e819, 0xd6990624, 0xf40e3585, 0x106aa070, + 0x19a4c116, 0x1e376c08, 0x2748774c, 0x34b0bcb5, + 0x391c0cb3, 0x4ed8aa4a, 0x5b9cca4f, 0x682e6ff3, + 0x748f82ee, 0x78a5636f, 0x84c87814, 0x8cc70208, + 0x90befffa, 0xa4506ceb, 0xbef9a3f7, 0xc67178f2 + }; + +/** + * Define the SHA SIGMA and sigma macros + * + * FIPS 180-2 section 4.1.2 + */ +// Equation 4.4 +inline TUint SHA256_SIGMA0(TUint aWord) + { + return (SHA_ROTR( 2,aWord) ^ SHA_ROTR(13,aWord) ^ SHA_ROTR(22,aWord)); + } +// Equation 4.5 +inline TUint SHA256_SIGMA1(TUint aWord) + { + return (SHA_ROTR( 6,aWord) ^ SHA_ROTR(11,aWord) ^ SHA_ROTR(25,aWord)); + } +// Equation 4.6 +inline TUint SHA256_sigma0(TUint aWord) + { + return (SHA_ROTR( 7,aWord) ^ SHA_ROTR(18,aWord) ^ SHA_SHR( 3,aWord)); + } +// Equation 4.7 +inline TUint SHA256_sigma1(TUint aWord) + { + return (SHA_ROTR(17,aWord) ^ SHA_ROTR(19,aWord) ^ SHA_SHR(10,aWord)); + } + + +// Macros +inline TUint MakeWord(const TUint8* aData) + { + return (aData[0] << 24 | aData[1] << 16 | aData[2] << 8 | aData[3]); + } + + +CSHA224And256Impl* CSHA224And256Impl::NewL() + { + CSHA224And256Impl* self=new (ELeave) CSHA224And256Impl(); + return self; + } + +CSHA224And256Impl::CSHA224And256Impl() : iHash(KSHA256HashSize) + { + } + +CSHA224And256Impl::CSHA224And256Impl(const CSHA224And256Impl& aSHA256Impl) + : iHash(aSHA256Impl.iHash), + iA(aSHA256Impl.iA), + iB(aSHA256Impl.iB), + iC(aSHA256Impl.iC), + iD(aSHA256Impl.iD), + iE(aSHA256Impl.iE), + iF(aSHA256Impl.iF), + iG(aSHA256Impl.iG), + iH(aSHA256Impl.iH), + iNl(aSHA256Impl.iNl), + iNh(aSHA256Impl.iNh) + { + Mem::Copy(iData, aSHA256Impl.iData, KSHA256BlockSize*sizeof(TUint)); + } + +void CSHA224And256Impl::Reset(const TAny* aValArray) + { + const TUint* values = static_cast(aValArray); + /** + * Initial Hash Value + * + * These words were obtained by taking the first thirty-two bits + * of the fractional parts of the square roots of the first eight + * prime numbers. + * + * FIPS 180-2 Section 5.3.2 + */ + iA=values[0]; + iB=values[1]; + iC=values[2]; + iD=values[3]; + iE=values[4]; + iF=values[5]; + iG=values[6]; + iH=values[7]; + iNh=0; + iNl=0; + } + +// This assumes a big-endian architecture +void CSHA224And256Impl::Update(const TUint8* aData,TUint aLength) + { + while((aLength / 4) > 0 && (iNl % 4 == 0)) + { + iData[iNl>>2] = MakeWord(aData); + iNl+=4; + aData+=4; + aLength-=4; + if(iNl==KSHA256BlockSize) + { + Block(); + AddLength(KSHA256BlockSize); + } + } + + while(aLength--) + { + if(!(iNl&0x03)) + { + iData[iNl >> 2] = 0; + } + iData[iNl >> 2] |= *aData << ((3 - iNl&0x03) << 3) ; + ++aData; + ++iNl; + if(iNl==KSHA256BlockSize) + { + Block(); + AddLength(KSHA256BlockSize); + } + } + } + +//This function will panic if the total input length is longer than 2^64 in bits +_LIT(KPanicString, "Message length exceeds supported length"); +inline void CSHA224And256Impl::AddLength(const TUint aLength) + { + TUint64 temp = iNh; + iNh += aLength << 3; + __ASSERT_ALWAYS((temp <= iNh), User::Panic(KPanicString, KErrOverflow)); + } + + +static inline void CSHA256_16( const TUint aA, + const TUint aB, + const TUint aC, + TUint& aD, + const TUint aE, + const TUint aF, + const TUint aG, + TUint& aH, + TUint aTemp1, + TUint aTemp2, + const TUint aK, + const TUint aWord) + { + aTemp1 = aH + SHA256_SIGMA1(aE) + SHA_Ch(aE,aF,aG) + aK + aWord; + aTemp2 = SHA256_SIGMA0(aA) + SHA_Maj(aA,aB,aC); + aD = aD + aTemp1; + aH = aTemp1 + aTemp2; + } + +static inline void CSHA256_48( const TUint aA, + const TUint aB, + const TUint aC, + TUint& aD, + const TUint aE, + const TUint aF, + const TUint aG, + TUint& aH, + TUint aTemp1, + TUint aTemp2, + const TUint aK, + TUint& aWord0, + const TUint aWord2, + const TUint aWord7, + const TUint aWord15, + const TUint aWord16) + { + aWord0 = SHA256_sigma1(aWord2) + aWord7 + SHA256_sigma0(aWord15) + aWord16; + CSHA256_16(aA, aB, aC, aD, aE, aF, aG, aH, aTemp1, aTemp2, aK, aWord0); + } + +/** + * This function actually calculates the hash. + * Function is defined in FIPS 180-2 section 6.2.2 + * + * This function is the expanded version of the following loop. + * for(TUint i = 0; i < 64; ++i) + * { + * if(i >= 16) + * { + * iData[i] = SHA256_sigma1(iData[i-2]) + iData[i-7] + SHA256_sigma0(iData[i-15]) + iData[i-16]; + * } + * + * temp1 = tempH + SHA256_SIGMA1(tempE) + SHA_Ch(tempE,tempF,tempG) + K[i] + iData[i]; + * temp2 = SHA256_SIGMA0(tempA) + SHA_Maj(tempA,tempB,tempC); + * tempH = tempG; + * tempG = tempF; + * tempF = tempE; + * tempE = tempD + temp1; + * tempD = tempC; + * tempC = tempB; + * tempB = tempA; + * tempA = temp1 + temp2; + * } + */ +void CSHA224And256Impl::Block() + { + TUint tempA=iA; + TUint tempB=iB; + TUint tempC=iC; + TUint tempD=iD; + TUint tempE=iE; + TUint tempF=iF; + TUint tempG=iG; + TUint tempH=iH; + TUint temp1=0; + TUint temp2=0; + + CSHA256_16(tempA,tempB,tempC,tempD,tempE,tempF,tempG,tempH,temp1,temp2,K[0],iData[0]); + CSHA256_16(tempH,tempA,tempB,tempC,tempD,tempE,tempF,tempG,temp1,temp2,K[1],iData[1]); + CSHA256_16(tempG,tempH,tempA,tempB,tempC,tempD,tempE,tempF,temp1,temp2,K[2],iData[2]); + CSHA256_16(tempF,tempG,tempH,tempA,tempB,tempC,tempD,tempE,temp1,temp2,K[3],iData[3]); + CSHA256_16(tempE,tempF,tempG,tempH,tempA,tempB,tempC,tempD,temp1,temp2,K[4],iData[4]); + CSHA256_16(tempD,tempE,tempF,tempG,tempH,tempA,tempB,tempC,temp1,temp2,K[5],iData[5]); + CSHA256_16(tempC,tempD,tempE,tempF,tempG,tempH,tempA,tempB,temp1,temp2,K[6],iData[6]); + CSHA256_16(tempB,tempC,tempD,tempE,tempF,tempG,tempH,tempA,temp1,temp2,K[7],iData[7]); + + CSHA256_16(tempA,tempB,tempC,tempD,tempE,tempF,tempG,tempH,temp1,temp2,K[8],iData[8]); + CSHA256_16(tempH,tempA,tempB,tempC,tempD,tempE,tempF,tempG,temp1,temp2,K[9],iData[9]); + CSHA256_16(tempG,tempH,tempA,tempB,tempC,tempD,tempE,tempF,temp1,temp2,K[10],iData[10]); + CSHA256_16(tempF,tempG,tempH,tempA,tempB,tempC,tempD,tempE,temp1,temp2,K[11],iData[11]); + CSHA256_16(tempE,tempF,tempG,tempH,tempA,tempB,tempC,tempD,temp1,temp2,K[12],iData[12]); + CSHA256_16(tempD,tempE,tempF,tempG,tempH,tempA,tempB,tempC,temp1,temp2,K[13],iData[13]); + CSHA256_16(tempC,tempD,tempE,tempF,tempG,tempH,tempA,tempB,temp1,temp2,K[14],iData[14]); + CSHA256_16(tempB,tempC,tempD,tempE,tempF,tempG,tempH,tempA,temp1,temp2,K[15],iData[15]); + + CSHA256_48( tempA, tempB, tempC, tempD, tempE, tempF, tempG, tempH, temp1, temp2, + K[16], iData[16], iData[14], iData[9], iData[1], iData[0]); + CSHA256_48( tempH, tempA, tempB, tempC, tempD, tempE, tempF, tempG, temp1, temp2, + K[17], iData[17], iData[15], iData[10], iData[2], iData[1]); + CSHA256_48( tempG, tempH, tempA, tempB, tempC, tempD, tempE, tempF, temp1, temp2, + K[18], iData[18], iData[16], iData[11], iData[3], iData[2]); + CSHA256_48( tempF, tempG, tempH, tempA, tempB, tempC, tempD, tempE, temp1, temp2, + K[19], iData[19], iData[17], iData[12], iData[4], iData[3]); + CSHA256_48( tempE, tempF, tempG, tempH, tempA, tempB, tempC, tempD, temp1, temp2, + K[20], iData[20], iData[18], iData[13], iData[5], iData[4]); + CSHA256_48( tempD, tempE, tempF, tempG, tempH, tempA, tempB, tempC, temp1, temp2, + K[21], iData[21], iData[19], iData[14], iData[6], iData[5]); + CSHA256_48( tempC, tempD, tempE, tempF, tempG, tempH, tempA, tempB, temp1, temp2, + K[22], iData[22], iData[20], iData[15], iData[7], iData[6]); + CSHA256_48( tempB, tempC, tempD, tempE, tempF, tempG, tempH, tempA, temp1, temp2, + K[23], iData[23], iData[21], iData[16], iData[8], iData[7]); + + CSHA256_48( tempA, tempB, tempC, tempD, tempE, tempF, tempG, tempH, temp1, temp2, + K[24], iData[24], iData[22], iData[17], iData[9], iData[8]); + CSHA256_48( tempH, tempA, tempB, tempC, tempD, tempE, tempF, tempG, temp1, temp2, + K[25], iData[25], iData[23], iData[18], iData[10], iData[9]); + CSHA256_48( tempG, tempH, tempA, tempB, tempC, tempD, tempE, tempF, temp1, temp2, + K[26], iData[26], iData[24], iData[19], iData[11], iData[10]); + CSHA256_48( tempF, tempG, tempH, tempA, tempB, tempC, tempD, tempE, temp1, temp2, + K[27], iData[27], iData[25], iData[20], iData[12], iData[11]); + CSHA256_48( tempE, tempF, tempG, tempH, tempA, tempB, tempC, tempD, temp1, temp2, + K[28], iData[28], iData[26], iData[21], iData[13], iData[12]); + CSHA256_48( tempD, tempE, tempF, tempG, tempH, tempA, tempB, tempC, temp1, temp2, + K[29], iData[29], iData[27], iData[22], iData[14], iData[13]); + CSHA256_48( tempC, tempD, tempE, tempF, tempG, tempH, tempA, tempB, temp1, temp2, + K[30], iData[30], iData[28], iData[23], iData[15], iData[14]); + CSHA256_48( tempB, tempC, tempD, tempE, tempF, tempG, tempH, tempA, temp1, temp2, + K[31], iData[31], iData[29], iData[24], iData[16], iData[15]); + + CSHA256_48( tempA, tempB, tempC, tempD, tempE, tempF, tempG, tempH, temp1, temp2, + K[32], iData[32], iData[30], iData[25], iData[17], iData[16]); + CSHA256_48( tempH, tempA, tempB, tempC, tempD, tempE, tempF, tempG, temp1, temp2, + K[33], iData[33], iData[31], iData[26], iData[18], iData[17]); + CSHA256_48( tempG, tempH, tempA, tempB, tempC, tempD, tempE, tempF, temp1, temp2, + K[34], iData[34], iData[32], iData[27], iData[19], iData[18]); + CSHA256_48( tempF, tempG, tempH, tempA, tempB, tempC, tempD, tempE, temp1, temp2, + K[35], iData[35], iData[33], iData[28], iData[20], iData[19]); + CSHA256_48( tempE, tempF, tempG, tempH, tempA, tempB, tempC, tempD, temp1, temp2, + K[36], iData[36], iData[34], iData[29], iData[21], iData[20]); + CSHA256_48( tempD, tempE, tempF, tempG, tempH, tempA, tempB, tempC, temp1, temp2, + K[37], iData[37], iData[35], iData[30], iData[22], iData[21]); + CSHA256_48( tempC, tempD, tempE, tempF, tempG, tempH, tempA, tempB, temp1, temp2, + K[38], iData[38], iData[36], iData[31], iData[23], iData[22]); + CSHA256_48( tempB, tempC, tempD, tempE, tempF, tempG, tempH, tempA, temp1, temp2, + K[39], iData[39], iData[37], iData[32], iData[24], iData[23]); + + CSHA256_48( tempA, tempB, tempC, tempD, tempE, tempF, tempG, tempH, temp1, temp2, + K[40], iData[40], iData[38], iData[33], iData[25], iData[24]); + CSHA256_48( tempH, tempA, tempB, tempC, tempD, tempE, tempF, tempG, temp1, temp2, + K[41], iData[41], iData[39], iData[34], iData[26], iData[25]); + CSHA256_48( tempG, tempH, tempA, tempB, tempC, tempD, tempE, tempF, temp1, temp2, + K[42], iData[42], iData[40], iData[35], iData[27], iData[26]); + CSHA256_48( tempF, tempG, tempH, tempA, tempB, tempC, tempD, tempE, temp1, temp2, + K[43], iData[43], iData[41], iData[36], iData[28], iData[27]); + CSHA256_48( tempE, tempF, tempG, tempH, tempA, tempB, tempC, tempD, temp1, temp2, + K[44], iData[44], iData[42], iData[37], iData[29], iData[28]); + CSHA256_48( tempD, tempE, tempF, tempG, tempH, tempA, tempB, tempC, temp1, temp2, + K[45], iData[45], iData[43], iData[38], iData[30], iData[29]); + CSHA256_48( tempC, tempD, tempE, tempF, tempG, tempH, tempA, tempB, temp1, temp2, + K[46], iData[46], iData[44], iData[39], iData[31], iData[30]); + CSHA256_48( tempB, tempC, tempD, tempE, tempF, tempG, tempH, tempA, temp1, temp2, + K[47], iData[47], iData[45], iData[40], iData[32], iData[31]); + + CSHA256_48( tempA, tempB, tempC, tempD, tempE, tempF, tempG, tempH, temp1, temp2, + K[48], iData[48], iData[46], iData[41], iData[33], iData[32]); + CSHA256_48( tempH, tempA, tempB, tempC, tempD, tempE, tempF, tempG, temp1, temp2, + K[49], iData[49], iData[47], iData[42], iData[34], iData[33]); + CSHA256_48( tempG, tempH, tempA, tempB, tempC, tempD, tempE, tempF, temp1, temp2, + K[50], iData[50], iData[48], iData[43], iData[35], iData[34]); + CSHA256_48( tempF, tempG, tempH, tempA, tempB, tempC, tempD, tempE, temp1, temp2, + K[51], iData[51], iData[49], iData[44], iData[36], iData[35]); + CSHA256_48( tempE, tempF, tempG, tempH, tempA, tempB, tempC, tempD, temp1, temp2, + K[52], iData[52], iData[50], iData[45], iData[37], iData[36]); + CSHA256_48( tempD, tempE, tempF, tempG, tempH, tempA, tempB, tempC, temp1, temp2, + K[53], iData[53], iData[51], iData[46], iData[38], iData[37]); + CSHA256_48( tempC, tempD, tempE, tempF, tempG, tempH, tempA, tempB, temp1, temp2, + K[54], iData[54], iData[52], iData[47], iData[39], iData[38]); + CSHA256_48( tempB, tempC, tempD, tempE, tempF, tempG, tempH, tempA, temp1, temp2, + K[55], iData[55], iData[53], iData[48], iData[40], iData[39]); + + CSHA256_48( tempA, tempB, tempC, tempD, tempE, tempF, tempG, tempH, temp1, temp2, + K[56], iData[56], iData[54], iData[49], iData[41], iData[40]); + CSHA256_48( tempH, tempA, tempB, tempC, tempD, tempE, tempF, tempG, temp1, temp2, + K[57], iData[57], iData[55], iData[50], iData[42], iData[41]); + CSHA256_48( tempG, tempH, tempA, tempB, tempC, tempD, tempE, tempF, temp1, temp2, + K[58], iData[58], iData[56], iData[51], iData[43], iData[42]); + CSHA256_48( tempF, tempG, tempH, tempA, tempB, tempC, tempD, tempE, temp1, temp2, + K[59], iData[59], iData[57], iData[52], iData[44], iData[43]); + CSHA256_48( tempE, tempF, tempG, tempH, tempA, tempB, tempC, tempD, temp1, temp2, + K[60], iData[60], iData[58], iData[53], iData[45], iData[44]); + CSHA256_48( tempD, tempE, tempF, tempG, tempH, tempA, tempB, tempC, temp1, temp2, + K[61], iData[61], iData[59], iData[54], iData[46], iData[45]); + CSHA256_48( tempC, tempD, tempE, tempF, tempG, tempH, tempA, tempB, temp1, temp2, + K[62], iData[62], iData[60], iData[55], iData[47], iData[46]); + CSHA256_48( tempB, tempC, tempD, tempE, tempF, tempG, tempH, tempA, temp1, temp2, + K[63], iData[63], iData[61], iData[56], iData[48], iData[47]); + + iA+=tempA; + iB+=tempB; + iC+=tempC; + iD+=tempD; + iE+=tempE; + iF+=tempF; + iG+=tempG; + iH+=tempH; + + iNl=0; + } + +/** + * According to the standard, the message must be padded to an + * even 512 bits. The first padding bit must be a '1'. The last + * 64 bits represent the length of the original message. All bits + * in between should be 0. This helper function will pad the + * message according to those rules by filling the iData array + * accordingly. + */ +void CSHA224And256Impl::PadMessage() + { + const TUint padByte = 0x80; + + if(!(iNl&0x03)) + { + iData[iNl >> 2] = 0; + } + iData[iNl >> 2] |= padByte << ((3 - iNl&0x03) << 3) ; + + if (iNl >= (KSHA256BlockSize - 2*sizeof(TUint))) + { + if (iNl < (KSHA256BlockSize - sizeof(TUint))) + iData[(KSHA256BlockSize >> 2) - 1]=0; + Block(); + Mem::FillZ(iData, KSHA256BlockSize); + } + else + { + const TUint offset=(iNl+4)>>2; //+4 to account for the word added in the + //switch statement above + Mem::FillZ(iData+offset,(KSHA256BlockSize - offset*sizeof(TUint))); + } + + //Length in bits + TUint64 msgLength = iNh; + + iData[(KSHA256BlockSize >> 2) - 2] = (msgLength) >> 32; + iData[(KSHA256BlockSize >> 2) - 1] = (msgLength & 0xFFFFFFFF); + } + +inline void CSHA224And256Impl::CopyWordToHash(TUint aVal, TUint aIndex) + { + TUint value = MakeWord(reinterpret_cast(&aVal)); + Mem::Copy(const_cast(iHash.Ptr())+ (4*aIndex), &value, sizeof(aVal)); + } + +const TDes8& CSHA224And256Impl::Final() + { + AddLength(iNl); + PadMessage(); + Block(); + // + // Generate hash value into iHash + // + CopyWordToHash(iA, 0); + CopyWordToHash(iB, 1); + CopyWordToHash(iC, 2); + CopyWordToHash(iD, 3); + CopyWordToHash(iE, 4); + CopyWordToHash(iF, 5); + CopyWordToHash(iG, 6); + CopyWordToHash(iH, 7); + + return iHash; + } + +void CSHA224And256Impl::RestoreState() + { + iA = iACopy; + iB = iBCopy; + iC = iCCopy; + iD = iDCopy; + iE = iECopy; + iF = iFCopy; + iG = iGCopy; + iH = iHCopy; + iNl = iNlCopy; + iNh = iNhCopy; + Mem::Copy(iData, iDataCopy, KSHA256BlockSize*sizeof(TUint)); + } + +void CSHA224And256Impl::StoreState() + { + iACopy = iA; + iBCopy = iB; + iCCopy = iC; + iDCopy = iD; + iECopy = iE; + iFCopy = iF; + iGCopy = iG; + iHCopy = iH; + iNlCopy = iNl; + iNhCopy = iNh; + Mem::Copy(iDataCopy, iData, KSHA256BlockSize*sizeof(TUint)); + } + +// Implemented in hmacimpl.cpp or softwarehashbase.cpp +// but required as derived from MHash. No coverage here. +#ifdef _BullseyeCoverage +#pragma suppress_warnings on +#pragma BullseyeCoverage off +#pragma suppress_warnings off +#endif + diff -r 7e3f204e6c81 -r f9c11be8c0b3 cryptoplugins/cryptospiplugins/source/softwarecrypto/sha224and256impl.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/cryptoplugins/cryptospiplugins/source/softwarecrypto/sha224and256impl.h Tue Dec 01 11:12:04 2009 +0000 @@ -0,0 +1,94 @@ +/* +* Copyright (c) 2007-2009 Nokia Corporation and/or its subsidiary(-ies). +* All rights reserved. +* This component and the accompanying materials are made available +* under the terms of the License "Eclipse Public License v1.0" +* which accompanies this distribution, and is available +* at the URL "http://www.eclipse.org/legal/epl-v10.html". +* +* Initial Contributors: +* Nokia Corporation - initial contribution. +* +* Contributors: +* +* Description: +* +*/ + + + + +/** + @file + @internalComponent + @released +*/ + + +#ifndef __CRYPTOAPI_SOFTWARESHA224AND256IMPL_H_ +#define __CRYPTOAPI_SOFTWARESHA224AND256IMPL_H_ + + +#include "softwarehashbase.h" +#include "shacommon.h" + +namespace SoftwareCrypto + { + using namespace CryptoSpi; + + const TInt KSHA256BlockSize = 64; + const TInt KSHA224HashSize = 28; + const TInt KSHA256HashSize = 32; + + NONSHARABLE_CLASS(CSHA224And256Impl) : public CBase, public MSHA2Impl + { + public: + //NewL + static CSHA224And256Impl* NewL(); + CSHA224And256Impl(const CSHA224And256Impl& aSHA256Impl); + + // Functions from MSHA2Impl + virtual void RestoreState(); + virtual void StoreState(); + virtual void Reset(const TAny*); + virtual void Update(const TUint8* aData,TUint aLength); + virtual const TDes8& Final(void); + + private: + //Constructors + CSHA224And256Impl(); + inline void AddLength(const TUint aLength); + inline void CopyWordToHash(TUint aVal, TUint aIndex); + void Block(); + void PadMessage(); + + private: + TBuf8 iHash; + TUint iA; + TUint iB; + TUint iC; + TUint iD; + TUint iE; + TUint iF; + TUint iG; + TUint iH; + TUint iData[KSHA256BlockSize]; + + TUint iACopy; + TUint iBCopy; + TUint iCCopy; + TUint iDCopy; + TUint iECopy; + TUint iFCopy; + TUint iGCopy; + TUint iHCopy; + TUint iNlCopy; + TUint iNhCopy; + TUint iDataCopy[KSHA256BlockSize]; + + TUint iNl; + TUint64 iNh; + }; + } + +#endif // __CRYPTOAPI_SOFTWARESHA224AND256IMPL_H_ diff -r 7e3f204e6c81 -r f9c11be8c0b3 cryptoplugins/cryptospiplugins/source/softwarecrypto/sha2impl.cpp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/cryptoplugins/cryptospiplugins/source/softwarecrypto/sha2impl.cpp Tue Dec 01 11:12:04 2009 +0000 @@ -0,0 +1,329 @@ +/* +* Copyright (c) 2007-2009 Nokia Corporation and/or its subsidiary(-ies). +* All rights reserved. +* This component and the accompanying materials are made available +* under the terms of the License "Eclipse Public License v1.0" +* which accompanies this distribution, and is available +* at the URL "http://www.eclipse.org/legal/epl-v10.html". +* +* Initial Contributors: +* Nokia Corporation - initial contribution. +* +* Contributors: +* +* Description: +* software SHA2 implementation +* RFC 4634 (US Secure Hash Algorithms (SHA and HMAC-SHA)) +* FIPS 180-2 (With change notice) +* +*/ + + +/** + @file +*/ + +#include "sha2impl.h" + +#include +#include "pluginconfig.h" +#include "sha224and256impl.h" +#include "sha384and512impl.h" + +using namespace SoftwareCrypto; + +// Initial Hash Values of SHA2 algorithms +/** + * Initial Hash Value for SHA-224 + * + * These words were obtained by taking the first thirty-two bits + * of the fractional parts of the square roots of the first eight + * prime numbers. + * + * FIPS 180-2 Appendix + * FIPS 180-3 Section 5.3.2 + */ +const TUint SHA224InitVals[] = + { + 0xc1059ed8, // A + 0x367cd507, // B + 0x3070dd17, // C + 0xf70e5939, // D + 0xffc00b31, // E + 0x68581511, // F + 0x64f98fa7, // G + 0xbefa4fa4 // H + }; + +/** + * Initial Hash Value for SHA-256 + * + * These words were obtained by taking the first thirty-two bits + * of the fractional parts of the square roots of the first eight + * prime numbers. + * + * FIPS 180-2 Section 5.3.2 + */ +const TUint SHA256InitVals[] = + { + 0x6a09e667, // A + 0xbb67ae85, // B + 0x3c6ef372, // C + 0xa54ff53a, // D + 0x510e527f, // E + 0x9b05688c, // F + 0x1f83d9ab, // G + 0x5be0cd19 // H + }; + +/** + * Initial Hash Value for SHA-384 + * + * These words were obtained by taking the first sixty-four bits + * of the fractional parts of the square roots of the first eight + * prime numbers. + * + * FIPS 180-2 Section 5.3.3 + */ +const TUint64 SHA384InitVals[] = + { + UI64LIT(0xcbbb9d5dc1059ed8), // A + UI64LIT(0x629a292a367cd507), // B + UI64LIT(0x9159015a3070dd17), // C + UI64LIT(0x152fecd8f70e5939), // D + UI64LIT(0x67332667ffc00b31), // E + UI64LIT(0x8eb44a8768581511), // F + UI64LIT(0xdb0c2e0d64f98fa7), // G + UI64LIT(0x47b5481dbefa4fa4) // H + }; + +/** + * Initial Hash Value for SHA-512 + * + * These words were obtained by taking the first sixty-four bits + * of the fractional parts of the square roots of the first eight + * prime numbers. + * + * FIPS 180-2 Section 5.3.4 + */ +const TUint64 SHA512InitVals[] = + { + UI64LIT(0x6a09e667f3bcc908), // A + UI64LIT(0xbb67ae8584caa73b), // B + UI64LIT(0x3c6ef372fe94f82b), // C + UI64LIT(0xa54ff53a5f1d36f1), // D + UI64LIT(0x510e527fade682d1), // E + UI64LIT(0x9b05688c2b3e6c1f), // F + UI64LIT(0x1f83d9abfb41bd6b), // G + UI64LIT(0x5be0cd19137e2179) // H + }; + + +CSHA2Impl* CSHA2Impl::NewL(TInt32 aAlgorithmId) + { + CSHA2Impl* self = CSHA2Impl::NewLC(aAlgorithmId); + CleanupStack::Pop(self); + return self; + } + +CSHA2Impl* CSHA2Impl::NewLC(TInt32 aAlgorithmId) + { + CSHA2Impl* self = new (ELeave) CSHA2Impl(); + CleanupStack::PushL(self); + self->ConstructL(aAlgorithmId); + return self; + } + +void CSHA2Impl::ConstructL(const CSHA2Impl& aSHA2Impl) + { + iImplementationUid = aSHA2Impl.iImplementationUid; + iInitValues = aSHA2Impl.iInitValues; + iHashSize = aSHA2Impl.iHashSize; + switch(iImplementationUid.iUid) + { + case KCryptoPluginSha224: + case KCryptoPluginSha256: + { + const CSHA224And256Impl* const impl = static_cast(aSHA2Impl.iImplementation); + iImplementation = new (ELeave) CSHA224And256Impl(*impl); + break; + } + case KCryptoPluginSha384: + case KCryptoPluginSha512: + { + const CSHA384And512Impl* const impl = static_cast(aSHA2Impl.iImplementation); + iImplementation = new (ELeave) CSHA384And512Impl(*impl); + break; + } + default: + { + User::Leave(KErrNotSupported); + } + } + } + +void CSHA2Impl::ConstructL(TInt32 aAlgorithmId) + { + switch(aAlgorithmId) + { + case KCryptoPluginSha224: + { + iImplementation = CSHA224And256Impl::NewL(); + iInitValues = SHA224InitVals; + iImplementationUid = KCryptoPluginSha224Uid; + iHashSize = KSHA224HashSize; + break; + } + case KCryptoPluginSha256: + { + iImplementation = CSHA224And256Impl::NewL(); + iInitValues = SHA256InitVals; + iImplementationUid = KCryptoPluginSha256Uid; + iHashSize = KSHA256HashSize; + break; + } + case KCryptoPluginSha384: + { + iImplementation = CSHA384And512Impl::NewL(); + iInitValues = SHA384InitVals; + iImplementationUid = KCryptoPluginSha384Uid; + iHashSize = KSHA384HashSize; + break; + } + case KCryptoPluginSha512: + { + iImplementation = CSHA384And512Impl::NewL(); + iInitValues = SHA512InitVals; + iImplementationUid = KCryptoPluginSha512Uid; + iHashSize = KSHA512HashSize; + break; + } + default: + { + User::Leave(KErrNotSupported); + } + } + + Reset(); + } + +CSHA2Impl::~CSHA2Impl() + { + delete iImplementation; + } + +void CSHA2Impl::Reset() + { + iImplementation->Reset(iInitValues); + } + +void CSHA2Impl::Close() + { + delete this; + } + +MHash* CSHA2Impl::ReplicateL() + { + return CSHA2Impl::NewL(iImplementationUid.iUid); + } + +MHash* CSHA2Impl::CopyL() + { + CSHA2Impl* hash = new(ELeave) CSHA2Impl(); + CleanupStack::PushL(hash); + hash->ConstructL(*this); + CleanupStack::Pop(hash); + return hash; + } + +TUid CSHA2Impl::ImplementationUid() + { + return iImplementationUid; + } + +void CSHA2Impl::GetCharacteristicsL(const TCharacteristics*& aPluginCharacteristics) + { + aPluginCharacteristics=NULL; + TInt hashNum=sizeof(KHashCharacteristics)/sizeof(THashCharacteristics*); + for (TInt i=0;icmn.iImplementationUID == ImplementationUid().iUid) + { + aPluginCharacteristics = KHashCharacteristics[i]; + break; + } + } + } + +CExtendedCharacteristics* CSHA2Impl::CreateExtendedCharacteristicsL() + { + // All Symbian software plug-ins have unlimited concurrency, cannot be reserved + // for exclusive use and are not CERTIFIED to be standards compliant. + return CExtendedCharacteristics::NewL(KMaxTInt, EFalse); + } + +const CExtendedCharacteristics* CSHA2Impl::GetExtendedCharacteristicsL() + { + return CSHA2Impl::CreateExtendedCharacteristicsL(); + } + +TPtrC8 CSHA2Impl::Hash(const TDesC8& aMessage) + { + TPtrC8 ptr(KNullDesC8()); + iImplementation->Update(aMessage.Ptr(),aMessage.Size()); + iImplementation->StoreState(); + ptr.Set(iImplementation->Final().Ptr(), iHashSize); + iImplementation->RestoreState(); + return ptr; + } + +void CSHA2Impl::Update(const TDesC8& aMessage) + { + iImplementation->Update(aMessage.Ptr(),aMessage.Size()); + } + +TPtrC8 CSHA2Impl::Final(const TDesC8& aMessage) + { + TPtrC8 ptr(KNullDesC8()); + if (aMessage!=KNullDesC8()) + { + iImplementation->Update(aMessage.Ptr(),aMessage.Size()); + } + ptr.Set(iImplementation->Final().Ptr(), iHashSize); + Reset(); + return ptr; + } + +void CSHA2Impl::RestoreState() + { + iImplementation->RestoreState(); + } + +void CSHA2Impl::StoreState() + { + iImplementation->StoreState(); + } + +// Implemented in hmacimpl.cpp or softwarehashbase.cpp +// but required as derived from MHash. No coverage here. +#ifdef _BullseyeCoverage +#pragma suppress_warnings on +#pragma BullseyeCoverage off +#pragma suppress_warnings off +#endif + +TAny* CSHA2Impl::GetExtension(TUid /*aExtensionId*/) + { + return NULL; + } + +void CSHA2Impl::SetOperationModeL(TUid /*aOperationMode*/) + { + User::Leave(KErrNotSupported); + } + +void CSHA2Impl::SetKeyL(const CKey& /*aKey*/) + { + User::Leave(KErrNotSupported); + } + diff -r 7e3f204e6c81 -r f9c11be8c0b3 cryptoplugins/cryptospiplugins/source/softwarecrypto/sha2impl.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/cryptoplugins/cryptospiplugins/source/softwarecrypto/sha2impl.h Tue Dec 01 11:12:04 2009 +0000 @@ -0,0 +1,85 @@ +/* +* Copyright (c) 2007-2009 Nokia Corporation and/or its subsidiary(-ies). +* All rights reserved. +* This component and the accompanying materials are made available +* under the terms of the License "Eclipse Public License v1.0" +* which accompanies this distribution, and is available +* at the URL "http://www.eclipse.org/legal/epl-v10.html". +* +* Initial Contributors: +* Nokia Corporation - initial contribution. +* +* Contributors: +* +* Description: +* +*/ + + + + +/** + @file + @internalComponent + @released +*/ + + +#ifndef __CRYPTOAPI_SOFTWARESHA2IMPL_H_ +#define __CRYPTOAPI_SOFTWARESHA2IMPL_H_ + + +#include "softwarehashbase.h" + +namespace SoftwareCrypto + { + using namespace CryptoSpi; + class MSHA2Impl; + + NONSHARABLE_CLASS(CSHA2Impl) : public CBase, public MSoftwareHash + { + public: + //NewL & NewLC + static CSHA2Impl* NewL(TInt32 aAlgorithmId); + static CSHA2Impl* NewLC(TInt32 aAlgorithmId); + + //From MPlugin + void Reset(); + void Close(); + void GetCharacteristicsL(const TCharacteristics*& aPluginCharacteristics); + static CExtendedCharacteristics* CreateExtendedCharacteristicsL(); + const CExtendedCharacteristics* GetExtendedCharacteristicsL(); + TAny* GetExtension(TUid aExtensionId); + + //From MHash + TPtrC8 Hash(const TDesC8& aMessage); + void Update(const TDesC8& aMessage); + TPtrC8 Final(const TDesC8& aMessage); + MHash* ReplicateL(); + MHash* CopyL(); + void SetKeyL(const CKey& aKey); + void SetOperationModeL(TUid aOperationMode); + + //From MSoftwareHash + void RestoreState(); + void StoreState(); + + private: + //Constructors + void ConstructL(TInt32 aAlgorithmId); + void ConstructL(const CSHA2Impl& aSHA512Impl); + + //Destructor + ~CSHA2Impl(); + + TUid ImplementationUid(); + + private: + MSHA2Impl* iImplementation; + const TAny* iInitValues; + TUid iImplementationUid; + TUint iHashSize; + }; + } + +#endif //__CRYPTOAPI_SOFTWARESHA2IMPL_H_ diff -r 7e3f204e6c81 -r f9c11be8c0b3 cryptoplugins/cryptospiplugins/source/softwarecrypto/sha384and512impl.cpp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/cryptoplugins/cryptospiplugins/source/softwarecrypto/sha384and512impl.cpp Tue Dec 01 11:12:04 2009 +0000 @@ -0,0 +1,539 @@ +/* +* Copyright (c) 2007-2009 Nokia Corporation and/or its subsidiary(-ies). +* All rights reserved. +* This component and the accompanying materials are made available +* under the terms of the License "Eclipse Public License v1.0" +* which accompanies this distribution, and is available +* at the URL "http://www.eclipse.org/legal/epl-v10.html". +* +* Initial Contributors: +* Nokia Corporation - initial contribution. +* +* Contributors: +* +* Description: +* Common implementation of SHA384 and SHA512 +* RFC 4634 (US Secure Hash Algorithms (SHA and HMAC-SHA)) +* +*/ + + +/** + @file +*/ + +#include +#include "sha384and512impl.h" +#include "pluginconfig.h" + +/** + * SHA512 Constants + * + * SHA-512 uses a sequence of eighty constant 64-bit words. + * These words represent the first sixty-four bits of the fractional + * parts of the cube roots of the first eighty prime numbers. + * + * FIPS 180-2 Section 4.2.3 + */ +const TUint64 K[80] = + { + UI64LIT(0x428a2f98d728ae22), UI64LIT(0x7137449123ef65cd), UI64LIT(0xb5c0fbcfec4d3b2f), UI64LIT(0xe9b5dba58189dbbc), + UI64LIT(0x3956c25bf348b538), UI64LIT(0x59f111f1b605d019), UI64LIT(0x923f82a4af194f9b), UI64LIT(0xab1c5ed5da6d8118), + UI64LIT(0xd807aa98a3030242), UI64LIT(0x12835b0145706fbe), UI64LIT(0x243185be4ee4b28c), UI64LIT(0x550c7dc3d5ffb4e2), + UI64LIT(0x72be5d74f27b896f), UI64LIT(0x80deb1fe3b1696b1), UI64LIT(0x9bdc06a725c71235), UI64LIT(0xc19bf174cf692694), + UI64LIT(0xe49b69c19ef14ad2), UI64LIT(0xefbe4786384f25e3), UI64LIT(0x0fc19dc68b8cd5b5), UI64LIT(0x240ca1cc77ac9c65), + UI64LIT(0x2de92c6f592b0275), UI64LIT(0x4a7484aa6ea6e483), UI64LIT(0x5cb0a9dcbd41fbd4), UI64LIT(0x76f988da831153b5), + UI64LIT(0x983e5152ee66dfab), UI64LIT(0xa831c66d2db43210), UI64LIT(0xb00327c898fb213f), UI64LIT(0xbf597fc7beef0ee4), + UI64LIT(0xc6e00bf33da88fc2), UI64LIT(0xd5a79147930aa725), UI64LIT(0x06ca6351e003826f), UI64LIT(0x142929670a0e6e70), + UI64LIT(0x27b70a8546d22ffc), UI64LIT(0x2e1b21385c26c926), UI64LIT(0x4d2c6dfc5ac42aed), UI64LIT(0x53380d139d95b3df), + UI64LIT(0x650a73548baf63de), UI64LIT(0x766a0abb3c77b2a8), UI64LIT(0x81c2c92e47edaee6), UI64LIT(0x92722c851482353b), + UI64LIT(0xa2bfe8a14cf10364), UI64LIT(0xa81a664bbc423001), UI64LIT(0xc24b8b70d0f89791), UI64LIT(0xc76c51a30654be30), + UI64LIT(0xd192e819d6ef5218), UI64LIT(0xd69906245565a910), UI64LIT(0xf40e35855771202a), UI64LIT(0x106aa07032bbd1b8), + UI64LIT(0x19a4c116b8d2d0c8), UI64LIT(0x1e376c085141ab53), UI64LIT(0x2748774cdf8eeb99), UI64LIT(0x34b0bcb5e19b48a8), + UI64LIT(0x391c0cb3c5c95a63), UI64LIT(0x4ed8aa4ae3418acb), UI64LIT(0x5b9cca4f7763e373), UI64LIT(0x682e6ff3d6b2b8a3), + UI64LIT(0x748f82ee5defb2fc), UI64LIT(0x78a5636f43172f60), UI64LIT(0x84c87814a1f0ab72), UI64LIT(0x8cc702081a6439ec), + UI64LIT(0x90befffa23631e28), UI64LIT(0xa4506cebde82bde9), UI64LIT(0xbef9a3f7b2c67915), UI64LIT(0xc67178f2e372532b), + UI64LIT(0xca273eceea26619c), UI64LIT(0xd186b8c721c0c207), UI64LIT(0xeada7dd6cde0eb1e), UI64LIT(0xf57d4f7fee6ed178), + UI64LIT(0x06f067aa72176fba), UI64LIT(0x0a637dc5a2c898a6), UI64LIT(0x113f9804bef90dae), UI64LIT(0x1b710b35131c471b), + UI64LIT(0x28db77f523047d84), UI64LIT(0x32caab7b40c72493), UI64LIT(0x3c9ebe0a15c9bebc), UI64LIT(0x431d67c49c100d4c), + UI64LIT(0x4cc5d4becb3e42b6), UI64LIT(0x597f299cfc657e2a), UI64LIT(0x5fcb6fab3ad6faec), UI64LIT(0x6c44198c4a475817) + }; + +/** + * Define the SHA SIGMA and sigma macros + * + * FIPS 180-2 section 4.1.3 + */ +// Equation 4.10 +inline TUint64 SHA512_SIGMA0(TUint64 aWord) + { + return (SHA_ROTR(28,aWord) ^ SHA_ROTR(34,aWord) ^ SHA_ROTR(39,aWord)); + } +// Equation 4.11 +inline TUint64 SHA512_SIGMA1(TUint64 aWord) + { + return (SHA_ROTR(14,aWord) ^ SHA_ROTR(18,aWord) ^ SHA_ROTR(41,aWord)); + } +// Equation 4.12 +inline TUint64 SHA512_sigma0(TUint64 aWord) + { + return (SHA_ROTR(1, aWord) ^ SHA_ROTR(8, aWord) ^ SHA_SHR(7, aWord)); + } +// Equation 4.13 +inline TUint64 SHA512_sigma1(TUint64 aWord) + { + return (SHA_ROTR(19,aWord) ^ SHA_ROTR(61,aWord) ^ SHA_SHR(6,aWord)); + } + +// Macros +inline TUint64 Make64BitWord(const TUint8* aData) + { + TUint64 result = (TUint64)aData[0] << 56 | (TUint64)aData[1] << 48 | (TUint64)aData[2] << 40 | + (TUint64)aData[3] << 32 | (TUint64)aData[4] << 24 | (TUint64)aData[5] << 16 | + (TUint64)aData[6] << 8 | (TUint64)aData[7]; + return result; + } + + +using namespace SoftwareCrypto; + +CSHA384And512Impl* CSHA384And512Impl::NewL(TInt aHashSize) + { + CSHA384And512Impl* self=new (ELeave) CSHA384And512Impl(aHashSize); + return self; + } + +CSHA384And512Impl::CSHA384And512Impl(TInt aHashSize) : iHash(aHashSize) + { + } + +CSHA384And512Impl::CSHA384And512Impl(const CSHA384And512Impl& aSHA512Impl) + : iHash(aSHA512Impl.iHash), + iA(aSHA512Impl.iA), + iB(aSHA512Impl.iB), + iC(aSHA512Impl.iC), + iD(aSHA512Impl.iD), + iE(aSHA512Impl.iE), + iF(aSHA512Impl.iF), + iG(aSHA512Impl.iG), + iH(aSHA512Impl.iH), + iNl(aSHA512Impl.iNl), + iNh(aSHA512Impl.iNh), + iBlockIndex(aSHA512Impl.iBlockIndex) + { + Mem::Copy(iData, aSHA512Impl.iData, KSHA512BlockSize*sizeof(TUint64)); + } + +void CSHA384And512Impl::Reset(const TAny* aValueArr) + { + const TUint64* values = static_cast(aValueArr); + /** + * Initial Hash Value + * + * These words were obtained by taking the first thirty-two bits + * of the fractional parts of the square roots of the first eight + * prime numbers. + * + * FIPS 180-2 Section 5.3.2 + */ + iA = values[0]; + iB = values[1]; + iC = values[2]; + iD = values[3]; + iE = values[4]; + iF = values[5]; + iG = values[6]; + iH = values[7]; + iNh = 0; + iNl = 0; + iBlockIndex = 0; + } + +//This function will panic if the total input length is longer than 2^128 in bits +_LIT(KPanicString, "Message length exceeds supported length"); +inline void CSHA384And512Impl::AddLength(const TUint64 aLength) + { + TUint64 temp = iNl; + iNl += aLength << 3; + __ASSERT_ALWAYS(((iNh != KMaxTUint64) || (temp <= iNl)), User::Panic(KPanicString, KErrOverflow)); + iNh += (temp > iNl); + } + +// This assumes a big-endian architecture +void CSHA384And512Impl::Update(const TUint8* aData,TUint aLength) + { + while((aLength / 8) > 0 && (iBlockIndex % 8 == 0)) + { + iData[iBlockIndex>>3] = Make64BitWord(aData); + iBlockIndex+=8; + aData+=8; + aLength-=8; + if(iBlockIndex==KSHA512BlockSize) + { + Block(); + AddLength(KSHA512BlockSize); + } + } + + while(aLength--) + { + if(!(iBlockIndex&0x07)) + { + iData[iBlockIndex >> 3] = 0; + } + iData[iBlockIndex >> 3] |= static_cast(*aData) << ((7 - iBlockIndex&0x07) << 3) ; + ++aData; + ++iBlockIndex; + if(iBlockIndex==KSHA512BlockSize) + { + Block(); + AddLength(KSHA512BlockSize); + } + } + } + +static inline void CSHA512_16( const TUint64 aA, + const TUint64 aB, + const TUint64 aC, + TUint64& aD, + const TUint64 aE, + const TUint64 aF, + const TUint64 aG, + TUint64& aH, + TUint64 aTemp1, + TUint64 aTemp2, + const TUint64 aK, + const TUint64 aWord) + { + aTemp1 = aH + SHA512_SIGMA1(aE) + SHA_Ch(aE,aF,aG) + aK + aWord; + aTemp2 = SHA512_SIGMA0(aA) + SHA_Maj(aA,aB,aC); + aD = aD + aTemp1; + aH = aTemp1 + aTemp2; + } + +static inline void CSHA512_64( const TUint64 aA, + const TUint64 aB, + const TUint64 aC, + TUint64& aD, + const TUint64 aE, + const TUint64 aF, + const TUint64 aG, + TUint64& aH, + TUint64 aTemp1, + TUint64 aTemp2, + const TUint64 aK, + TUint64& aWord0, + const TUint64 aWord2, + const TUint64 aWord7, + const TUint64 aWord15, + const TUint64 aWord16) + { + aWord0 = SHA512_sigma1(aWord2) + aWord7 + SHA512_sigma0(aWord15) + aWord16; + CSHA512_16(aA, aB, aC, aD, aE, aF, aG, aH, aTemp1, aTemp2, aK, aWord0); + } + +/** + * This function actually calculates the hash. + * Function is defined in FIPS 180-2 section 6.3.2 + * + * This function is the expanded version of the following loop. + * for(TUint i = 0; i < 80; ++i) + * { + * if(i >= 16) + * { + * iData[i] = SHA512_sigma1(iData[i-2]) + iData[i-7] + SHA512_sigma0(iData[i-15]) + iData[i-16]; + * } + * + * temp1 = tempH + SHA512_SIGMA1(tempE) + SHA_Ch(tempE,tempF,tempG) + K[i] + iData[i]; + * temp2 = SHA512_SIGMA0(tempA) + SHA_Maj(tempA,tempB,tempC); + * tempH = tempG; + * tempG = tempF; + * tempF = tempE; + * tempE = tempD + temp1; + * tempD = tempC; + * tempC = tempB; + * tempB = tempA; + * tempA = temp1 + temp2; + * } + */ +void CSHA384And512Impl::Block() + { + TUint64 tempA=iA; + TUint64 tempB=iB; + TUint64 tempC=iC; + TUint64 tempD=iD; + TUint64 tempE=iE; + TUint64 tempF=iF; + TUint64 tempG=iG; + TUint64 tempH=iH; + TUint64 temp1=0; + TUint64 temp2=0; + + CSHA512_16(tempA,tempB,tempC,tempD,tempE,tempF,tempG,tempH,temp1,temp2,K[0],iData[0]); + CSHA512_16(tempH,tempA,tempB,tempC,tempD,tempE,tempF,tempG,temp1,temp2,K[1],iData[1]); + CSHA512_16(tempG,tempH,tempA,tempB,tempC,tempD,tempE,tempF,temp1,temp2,K[2],iData[2]); + CSHA512_16(tempF,tempG,tempH,tempA,tempB,tempC,tempD,tempE,temp1,temp2,K[3],iData[3]); + CSHA512_16(tempE,tempF,tempG,tempH,tempA,tempB,tempC,tempD,temp1,temp2,K[4],iData[4]); + CSHA512_16(tempD,tempE,tempF,tempG,tempH,tempA,tempB,tempC,temp1,temp2,K[5],iData[5]); + CSHA512_16(tempC,tempD,tempE,tempF,tempG,tempH,tempA,tempB,temp1,temp2,K[6],iData[6]); + CSHA512_16(tempB,tempC,tempD,tempE,tempF,tempG,tempH,tempA,temp1,temp2,K[7],iData[7]); + + CSHA512_16(tempA,tempB,tempC,tempD,tempE,tempF,tempG,tempH,temp1,temp2,K[8],iData[8]); + CSHA512_16(tempH,tempA,tempB,tempC,tempD,tempE,tempF,tempG,temp1,temp2,K[9],iData[9]); + CSHA512_16(tempG,tempH,tempA,tempB,tempC,tempD,tempE,tempF,temp1,temp2,K[10],iData[10]); + CSHA512_16(tempF,tempG,tempH,tempA,tempB,tempC,tempD,tempE,temp1,temp2,K[11],iData[11]); + CSHA512_16(tempE,tempF,tempG,tempH,tempA,tempB,tempC,tempD,temp1,temp2,K[12],iData[12]); + CSHA512_16(tempD,tempE,tempF,tempG,tempH,tempA,tempB,tempC,temp1,temp2,K[13],iData[13]); + CSHA512_16(tempC,tempD,tempE,tempF,tempG,tempH,tempA,tempB,temp1,temp2,K[14],iData[14]); + CSHA512_16(tempB,tempC,tempD,tempE,tempF,tempG,tempH,tempA,temp1,temp2,K[15],iData[15]); + + CSHA512_64( tempA, tempB, tempC, tempD, tempE, tempF, tempG, tempH, temp1, temp2, + K[16], iData[16], iData[14], iData[9], iData[1], iData[0]); + CSHA512_64( tempH, tempA, tempB, tempC, tempD, tempE, tempF, tempG, temp1, temp2, + K[17], iData[17], iData[15], iData[10], iData[2], iData[1]); + CSHA512_64( tempG, tempH, tempA, tempB, tempC, tempD, tempE, tempF, temp1, temp2, + K[18], iData[18], iData[16], iData[11], iData[3], iData[2]); + CSHA512_64( tempF, tempG, tempH, tempA, tempB, tempC, tempD, tempE, temp1, temp2, + K[19], iData[19], iData[17], iData[12], iData[4], iData[3]); + CSHA512_64( tempE, tempF, tempG, tempH, tempA, tempB, tempC, tempD, temp1, temp2, + K[20], iData[20], iData[18], iData[13], iData[5], iData[4]); + CSHA512_64( tempD, tempE, tempF, tempG, tempH, tempA, tempB, tempC, temp1, temp2, + K[21], iData[21], iData[19], iData[14], iData[6], iData[5]); + CSHA512_64( tempC, tempD, tempE, tempF, tempG, tempH, tempA, tempB, temp1, temp2, + K[22], iData[22], iData[20], iData[15], iData[7], iData[6]); + CSHA512_64( tempB, tempC, tempD, tempE, tempF, tempG, tempH, tempA, temp1, temp2, + K[23], iData[23], iData[21], iData[16], iData[8], iData[7]); + + CSHA512_64( tempA, tempB, tempC, tempD, tempE, tempF, tempG, tempH, temp1, temp2, + K[24], iData[24], iData[22], iData[17], iData[9], iData[8]); + CSHA512_64( tempH, tempA, tempB, tempC, tempD, tempE, tempF, tempG, temp1, temp2, + K[25], iData[25], iData[23], iData[18], iData[10], iData[9]); + CSHA512_64( tempG, tempH, tempA, tempB, tempC, tempD, tempE, tempF, temp1, temp2, + K[26], iData[26], iData[24], iData[19], iData[11], iData[10]); + CSHA512_64( tempF, tempG, tempH, tempA, tempB, tempC, tempD, tempE, temp1, temp2, + K[27], iData[27], iData[25], iData[20], iData[12], iData[11]); + CSHA512_64( tempE, tempF, tempG, tempH, tempA, tempB, tempC, tempD, temp1, temp2, + K[28], iData[28], iData[26], iData[21], iData[13], iData[12]); + CSHA512_64( tempD, tempE, tempF, tempG, tempH, tempA, tempB, tempC, temp1, temp2, + K[29], iData[29], iData[27], iData[22], iData[14], iData[13]); + CSHA512_64( tempC, tempD, tempE, tempF, tempG, tempH, tempA, tempB, temp1, temp2, + K[30], iData[30], iData[28], iData[23], iData[15], iData[14]); + CSHA512_64( tempB, tempC, tempD, tempE, tempF, tempG, tempH, tempA, temp1, temp2, + K[31], iData[31], iData[29], iData[24], iData[16], iData[15]); + + CSHA512_64( tempA, tempB, tempC, tempD, tempE, tempF, tempG, tempH, temp1, temp2, + K[32], iData[32], iData[30], iData[25], iData[17], iData[16]); + CSHA512_64( tempH, tempA, tempB, tempC, tempD, tempE, tempF, tempG, temp1, temp2, + K[33], iData[33], iData[31], iData[26], iData[18], iData[17]); + CSHA512_64( tempG, tempH, tempA, tempB, tempC, tempD, tempE, tempF, temp1, temp2, + K[34], iData[34], iData[32], iData[27], iData[19], iData[18]); + CSHA512_64( tempF, tempG, tempH, tempA, tempB, tempC, tempD, tempE, temp1, temp2, + K[35], iData[35], iData[33], iData[28], iData[20], iData[19]); + CSHA512_64( tempE, tempF, tempG, tempH, tempA, tempB, tempC, tempD, temp1, temp2, + K[36], iData[36], iData[34], iData[29], iData[21], iData[20]); + CSHA512_64( tempD, tempE, tempF, tempG, tempH, tempA, tempB, tempC, temp1, temp2, + K[37], iData[37], iData[35], iData[30], iData[22], iData[21]); + CSHA512_64( tempC, tempD, tempE, tempF, tempG, tempH, tempA, tempB, temp1, temp2, + K[38], iData[38], iData[36], iData[31], iData[23], iData[22]); + CSHA512_64( tempB, tempC, tempD, tempE, tempF, tempG, tempH, tempA, temp1, temp2, + K[39], iData[39], iData[37], iData[32], iData[24], iData[23]); + + CSHA512_64( tempA, tempB, tempC, tempD, tempE, tempF, tempG, tempH, temp1, temp2, + K[40], iData[40], iData[38], iData[33], iData[25], iData[24]); + CSHA512_64( tempH, tempA, tempB, tempC, tempD, tempE, tempF, tempG, temp1, temp2, + K[41], iData[41], iData[39], iData[34], iData[26], iData[25]); + CSHA512_64( tempG, tempH, tempA, tempB, tempC, tempD, tempE, tempF, temp1, temp2, + K[42], iData[42], iData[40], iData[35], iData[27], iData[26]); + CSHA512_64( tempF, tempG, tempH, tempA, tempB, tempC, tempD, tempE, temp1, temp2, + K[43], iData[43], iData[41], iData[36], iData[28], iData[27]); + CSHA512_64( tempE, tempF, tempG, tempH, tempA, tempB, tempC, tempD, temp1, temp2, + K[44], iData[44], iData[42], iData[37], iData[29], iData[28]); + CSHA512_64( tempD, tempE, tempF, tempG, tempH, tempA, tempB, tempC, temp1, temp2, + K[45], iData[45], iData[43], iData[38], iData[30], iData[29]); + CSHA512_64( tempC, tempD, tempE, tempF, tempG, tempH, tempA, tempB, temp1, temp2, + K[46], iData[46], iData[44], iData[39], iData[31], iData[30]); + CSHA512_64( tempB, tempC, tempD, tempE, tempF, tempG, tempH, tempA, temp1, temp2, + K[47], iData[47], iData[45], iData[40], iData[32], iData[31]); + + CSHA512_64( tempA, tempB, tempC, tempD, tempE, tempF, tempG, tempH, temp1, temp2, + K[48], iData[48], iData[46], iData[41], iData[33], iData[32]); + CSHA512_64( tempH, tempA, tempB, tempC, tempD, tempE, tempF, tempG, temp1, temp2, + K[49], iData[49], iData[47], iData[42], iData[34], iData[33]); + CSHA512_64( tempG, tempH, tempA, tempB, tempC, tempD, tempE, tempF, temp1, temp2, + K[50], iData[50], iData[48], iData[43], iData[35], iData[34]); + CSHA512_64( tempF, tempG, tempH, tempA, tempB, tempC, tempD, tempE, temp1, temp2, + K[51], iData[51], iData[49], iData[44], iData[36], iData[35]); + CSHA512_64( tempE, tempF, tempG, tempH, tempA, tempB, tempC, tempD, temp1, temp2, + K[52], iData[52], iData[50], iData[45], iData[37], iData[36]); + CSHA512_64( tempD, tempE, tempF, tempG, tempH, tempA, tempB, tempC, temp1, temp2, + K[53], iData[53], iData[51], iData[46], iData[38], iData[37]); + CSHA512_64( tempC, tempD, tempE, tempF, tempG, tempH, tempA, tempB, temp1, temp2, + K[54], iData[54], iData[52], iData[47], iData[39], iData[38]); + CSHA512_64( tempB, tempC, tempD, tempE, tempF, tempG, tempH, tempA, temp1, temp2, + K[55], iData[55], iData[53], iData[48], iData[40], iData[39]); + + CSHA512_64( tempA, tempB, tempC, tempD, tempE, tempF, tempG, tempH, temp1, temp2, + K[56], iData[56], iData[54], iData[49], iData[41], iData[40]); + CSHA512_64( tempH, tempA, tempB, tempC, tempD, tempE, tempF, tempG, temp1, temp2, + K[57], iData[57], iData[55], iData[50], iData[42], iData[41]); + CSHA512_64( tempG, tempH, tempA, tempB, tempC, tempD, tempE, tempF, temp1, temp2, + K[58], iData[58], iData[56], iData[51], iData[43], iData[42]); + CSHA512_64( tempF, tempG, tempH, tempA, tempB, tempC, tempD, tempE, temp1, temp2, + K[59], iData[59], iData[57], iData[52], iData[44], iData[43]); + CSHA512_64( tempE, tempF, tempG, tempH, tempA, tempB, tempC, tempD, temp1, temp2, + K[60], iData[60], iData[58], iData[53], iData[45], iData[44]); + CSHA512_64( tempD, tempE, tempF, tempG, tempH, tempA, tempB, tempC, temp1, temp2, + K[61], iData[61], iData[59], iData[54], iData[46], iData[45]); + CSHA512_64( tempC, tempD, tempE, tempF, tempG, tempH, tempA, tempB, temp1, temp2, + K[62], iData[62], iData[60], iData[55], iData[47], iData[46]); + CSHA512_64( tempB, tempC, tempD, tempE, tempF, tempG, tempH, tempA, temp1, temp2, + K[63], iData[63], iData[61], iData[56], iData[48], iData[47]); + + CSHA512_64( tempA, tempB, tempC, tempD, tempE, tempF, tempG, tempH, temp1, temp2, + K[64], iData[64], iData[62], iData[57], iData[49], iData[48]); + CSHA512_64( tempH, tempA, tempB, tempC, tempD, tempE, tempF, tempG, temp1, temp2, + K[65], iData[65], iData[63], iData[58], iData[50], iData[49]); + CSHA512_64( tempG, tempH, tempA, tempB, tempC, tempD, tempE, tempF, temp1, temp2, + K[66], iData[66], iData[64], iData[59], iData[51], iData[50]); + CSHA512_64( tempF, tempG, tempH, tempA, tempB, tempC, tempD, tempE, temp1, temp2, + K[67], iData[67], iData[65], iData[60], iData[52], iData[51]); + CSHA512_64( tempE, tempF, tempG, tempH, tempA, tempB, tempC, tempD, temp1, temp2, + K[68], iData[68], iData[66], iData[61], iData[53], iData[52]); + CSHA512_64( tempD, tempE, tempF, tempG, tempH, tempA, tempB, tempC, temp1, temp2, + K[69], iData[69], iData[67], iData[62], iData[54], iData[53]); + CSHA512_64( tempC, tempD, tempE, tempF, tempG, tempH, tempA, tempB, temp1, temp2, + K[70], iData[70], iData[68], iData[63], iData[55], iData[54]); + CSHA512_64( tempB, tempC, tempD, tempE, tempF, tempG, tempH, tempA, temp1, temp2, + K[71], iData[71], iData[69], iData[64], iData[56], iData[55]); + + CSHA512_64( tempA, tempB, tempC, tempD, tempE, tempF, tempG, tempH, temp1, temp2, + K[72], iData[72], iData[70], iData[65], iData[57], iData[56]); + CSHA512_64( tempH, tempA, tempB, tempC, tempD, tempE, tempF, tempG, temp1, temp2, + K[73], iData[73], iData[71], iData[66], iData[58], iData[57]); + CSHA512_64( tempG, tempH, tempA, tempB, tempC, tempD, tempE, tempF, temp1, temp2, + K[74], iData[74], iData[72], iData[67], iData[59], iData[58]); + CSHA512_64( tempF, tempG, tempH, tempA, tempB, tempC, tempD, tempE, temp1, temp2, + K[75], iData[75], iData[73], iData[68], iData[60], iData[59]); + CSHA512_64( tempE, tempF, tempG, tempH, tempA, tempB, tempC, tempD, temp1, temp2, + K[76], iData[76], iData[74], iData[69], iData[61], iData[60]); + CSHA512_64( tempD, tempE, tempF, tempG, tempH, tempA, tempB, tempC, temp1, temp2, + K[77], iData[77], iData[75], iData[70], iData[62], iData[61]); + CSHA512_64( tempC, tempD, tempE, tempF, tempG, tempH, tempA, tempB, temp1, temp2, + K[78], iData[78], iData[76], iData[71], iData[63], iData[62]); + CSHA512_64( tempB, tempC, tempD, tempE, tempF, tempG, tempH, tempA, temp1, temp2, + K[79], iData[79], iData[77], iData[72], iData[64], iData[63]); + + iA+=tempA; + iB+=tempB; + iC+=tempC; + iD+=tempD; + iE+=tempE; + iF+=tempF; + iG+=tempG; + iH+=tempH; + + iBlockIndex=0; + } + +/** + * According to the standard, the message must be padded to an + * even 512 bits. The first padding bit must be a '1'. The last + * 64 bits represent the length of the original message. All bits + * in between should be 0. This helper function will pad the + * message according to those rules by filling the iData array + * accordingly. + */ +void CSHA384And512Impl::PadMessage() + { + const TUint64 padByte = 0x80; + + if(!(iBlockIndex&0x07)) + { + iData[iBlockIndex >> 3] = 0; + } + iData[iBlockIndex >> 3] |= padByte << ((7 - iBlockIndex&0x07) << 3) ; + + if (iBlockIndex >= (KSHA512BlockSize - 2*sizeof(TUint64))) + { + if (iBlockIndex < (KSHA512BlockSize - sizeof(TUint64))) + iData[(KSHA512BlockSize>>3)-1]=0; + Block(); + Mem::FillZ(iData,KSHA512BlockSize); + } + else + { + const TUint offset=(iBlockIndex+8)>>3; //+8 to account for the word added in the + //switch statement above + Mem::FillZ(iData+offset, (KSHA512BlockSize - offset*sizeof(TUint64))); + } + + iData[(KSHA512BlockSize >> 3) - 2] = iNh; + iData[(KSHA512BlockSize >> 3) - 1] = iNl; + } + +inline void CSHA384And512Impl::CopyWordToHash(TUint64 aVal, TUint aIndex) + { + TUint64 value = Make64BitWord(reinterpret_cast(&aVal)); + Mem::Copy(const_cast(iHash.Ptr())+ (8*aIndex), &value, sizeof(aVal)); + } + +const TDesC8& CSHA384And512Impl::Final() + { + AddLength(iBlockIndex); + PadMessage(); + Block(); + // + // Generate hash value into iHash + // + CopyWordToHash(iA, 0); + CopyWordToHash(iB, 1); + CopyWordToHash(iC, 2); + CopyWordToHash(iD, 3); + CopyWordToHash(iE, 4); + CopyWordToHash(iF, 5); + CopyWordToHash(iG, 6); + CopyWordToHash(iH, 7); + + return iHash; + } + +void CSHA384And512Impl::RestoreState() + { + iA = iACopy; + iB = iBCopy; + iC = iCCopy; + iD = iDCopy; + iE = iECopy; + iF = iFCopy; + iG = iGCopy; + iH = iHCopy; + iNl = iNlCopy; + iNh = iNhCopy; + iBlockIndex = iBlockIndexCopy; + Mem::Copy((TAny*)iData, (TAny*)iDataCopy, KSHA512BlockSize*sizeof(TUint64)); + } + +void CSHA384And512Impl::StoreState() + { + iACopy = iA; + iBCopy = iB; + iCCopy = iC; + iDCopy = iD; + iECopy = iE; + iFCopy = iF; + iGCopy = iG; + iHCopy = iH; + iNlCopy = iNl; + iNhCopy = iNh; + iBlockIndexCopy = iBlockIndex; + Mem::Copy((TAny*)iDataCopy, (TAny*)iData, KSHA512BlockSize*sizeof(TUint64)); + } + +// Implemented in hmacimpl.cpp or softwarehashbase.cpp +// but required as derived from MHash. No coverage here. +#ifdef _BullseyeCoverage +#pragma suppress_warnings on +#pragma BullseyeCoverage off +#pragma suppress_warnings off +#endif + diff -r 7e3f204e6c81 -r f9c11be8c0b3 cryptoplugins/cryptospiplugins/source/softwarecrypto/sha384and512impl.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/cryptoplugins/cryptospiplugins/source/softwarecrypto/sha384and512impl.h Tue Dec 01 11:12:04 2009 +0000 @@ -0,0 +1,102 @@ +/* +* Copyright (c) 2007-2009 Nokia Corporation and/or its subsidiary(-ies). +* All rights reserved. +* This component and the accompanying materials are made available +* under the terms of the License "Eclipse Public License v1.0" +* which accompanies this distribution, and is available +* at the URL "http://www.eclipse.org/legal/epl-v10.html". +* +* Initial Contributors: +* Nokia Corporation - initial contribution. +* +* Contributors: +* +* Description: +* +*/ + + + + +/** + @file + @internalComponent + @released +*/ + + +#ifndef __CRYPTOAPI_SOFTWARESHA384AND512IMPL_H_ +#define __CRYPTOAPI_SOFTWARESHA384AND512IMPL_H_ + + +#include "softwarehashbase.h" +#include "shacommon.h" + +namespace SoftwareCrypto + { + using namespace CryptoSpi; + + const TInt KSHA512BlockSize = 128; + const TInt KSHA384HashSize = 48; + const TInt KSHA512HashSize = 64; + + NONSHARABLE_CLASS(CSHA384And512Impl) : public CBase, public MSHA2Impl + { + public: + //NewL + static CSHA384And512Impl* NewL(TInt aHashSize = KSHA512HashSize); + CSHA384And512Impl(const CSHA384And512Impl& aSHA512Impl); + + //From MSHAImpl + virtual void Reset(const TAny* aValueArr); + virtual const TDesC8& Final(void); + virtual void Update(const TUint8* aData,TUint aLength); + virtual void StoreState(); + virtual void RestoreState(); + + private: + //Constructors + CSHA384And512Impl(TInt aHashSize); + + private: + // Private member functions + /** + * @param aLength - Length of message added in bytes. + */ + inline void AddLength(const TUint64 aLength); + inline void CopyWordToHash(TUint64 aVal, TUint aIndex); + void Block(); + void PadMessage(); + + private: + TBuf8 iHash; + TUint64 iA; + TUint64 iB; + TUint64 iC; + TUint64 iD; + TUint64 iE; + TUint64 iF; + TUint64 iG; + TUint64 iH; + TUint64 iData[KSHA512BlockSize]; + + TUint64 iACopy; + TUint64 iBCopy; + TUint64 iCCopy; + TUint64 iDCopy; + TUint64 iECopy; + TUint64 iFCopy; + TUint64 iGCopy; + TUint64 iHCopy; + TUint64 iNlCopy; + TUint64 iNhCopy; + TUint iBlockIndexCopy; + TUint64 iDataCopy[KSHA512BlockSize]; + + TUint64 iNl; // Lower word of Message Length + TUint64 iNh; // Higher word of Message Length + TUint iBlockIndex; // Message Length in the current block + }; + } + +#endif // __CRYPTOAPI_SOFTWARESHA384AND512IMPL_H_ diff -r 7e3f204e6c81 -r f9c11be8c0b3 cryptoplugins/cryptospiplugins/source/softwarecrypto/shacommon.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/cryptoplugins/cryptospiplugins/source/softwarecrypto/shacommon.h Tue Dec 01 11:12:04 2009 +0000 @@ -0,0 +1,123 @@ +#ifndef __CRYPTOAPI_SOFTWARESHACOMMON_H_ +#define __CRYPTOAPI_SOFTWARESHACOMMON_H_/* +* Copyright (c) 2007-2009 Nokia Corporation and/or its subsidiary(-ies). +* All rights reserved. +* This component and the accompanying materials are made available +* under the terms of the License "Eclipse Public License v1.0" +* which accompanies this distribution, and is available +* at the URL "http://www.eclipse.org/legal/epl-v10.html". +* +* Initial Contributors: +* Nokia Corporation - initial contribution. +* +* Contributors: +* +* Description: +* sha256impl.h +* Same as used in SHA1 +* SHA_CH > CSHA1_F +* SHA_Maj > CSHA1_H +* SHA_Parity > CSHA1_G +* The following definitions are equivalent and potentially faster. +* #define SHA_Ch(x, y, z) (((x) & ((y) ^ (z))) ^ (z)) +* #define SHA_Maj(x, y, z) (((x) & ((y) | (z))) | ((y) & (z))) +* These functions are defined in FIPS 180-2 Section 4.1 +* Equation 4.1, 4.2, 4.3, 4.8, 4.9 +* +*/ + + + + +/** + @file + @internalComponent + @released +*/ +template +inline T SHA_Ch(T aX, T aY, T aZ) + { + return ((aX & aY) ^ ((~aX) & aZ)); + } + +template +inline T SHA_Maj(T aX, T aY, T aZ) + { + return ((aX & aY) ^ (aX & aZ) ^ (aY & aZ)); + } + +template +inline T SHA_Parity(T aX, T aY, T aZ) + { + return (aX ^ aY ^ aZ); + } + +/** + * Define the SHA shift, and rotate right macro + * Defined in FIPS 180-2 Section 3.2 + */ +/** + * SHA Right Shift operation: The right shift operation SHR^n(x), + * where x is a w-bit word and n is an integer with 0 <= n < w, + * is defined by SHR^n(x) = x >> n. + */ +template +inline T SHA_SHR(T aBits, T aWord) + { + return (aWord >> aBits); + } + +/** + * SHA Rotate Right Operation: The rotate right (circular right shift) operation + * ROTR^n(x), where x is a w-bit word and n is an integer with 0 <= n < w, + * is defined by ROTR n(x)=(x >> n) || (x << w - n). + */ +template +inline T SHA_ROTR(T aBits, T aWord) + { + TInt totalBits = sizeof(T) << 3; + return ((aWord >> aBits) | (aWord << (totalBits-aBits))); + } + +namespace SoftwareCrypto +{ + +NONSHARABLE_CLASS(MSHA2Impl) + { +public: + /** + * This function will reset the state of hash. + */ + virtual void Reset(const TAny*) = 0; + /** + * This function will finalize the hash and return + * the calculated hash. + * @return Final hash + */ + virtual const TDesC8& Final() = 0; + /** + * This function will add the message to the internal + * buffer and if the block size is reached then calcualte + * the hash till that point. + * @param aMessage Message to be updated. + * @param aLength Length of the message to be updated. + */ + virtual void Update(const TUint8* aMessage, TUint aLength) = 0; + /** + * This function will save the internal state of the hash. + */ + virtual void StoreState() = 0; + /** + * This function will retrieve the saved the internal state + * of the hash. + */ + virtual void RestoreState() = 0; + /** + * virtual distructor. + */ + virtual ~MSHA2Impl(){} + }; + +}//namespace SoftwareCrypto + +#endif //__CRYPTOAPI_SOFTWARESHACOMMON_H_ diff -r 7e3f204e6c81 -r f9c11be8c0b3 cryptoplugins/cryptospiplugins/source/softwarecrypto/signerimpl.cpp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/cryptoplugins/cryptospiplugins/source/softwarecrypto/signerimpl.cpp Tue Dec 01 11:12:04 2009 +0000 @@ -0,0 +1,108 @@ +/* +* Copyright (c) 2006-2009 Nokia Corporation and/or its subsidiary(-ies). +* All rights reserved. +* This component and the accompanying materials are made available +* under the terms of the License "Eclipse Public License v1.0" +* which accompanies this distribution, and is available +* at the URL "http://www.eclipse.org/legal/epl-v10.html". +* +* Initial Contributors: +* Nokia Corporation - initial contribution. +* +* Contributors: +* +* Description: +* +*/ + + +#include +#include +#include "keys.h" +#include + +#include "signerimpl.h" +#include "pluginconfig.h" + +using namespace SoftwareCrypto; + +CSignerImpl::CSignerImpl() + { + } + +CSignerImpl::~CSignerImpl() + { + delete iKey; + } + +void CSignerImpl::Close() + { + delete this; + } + +void CSignerImpl::Reset() + { + } + +TAny* CSignerImpl::GetExtension(TUid /*aExtensionId*/) + { + return 0; + } + +void CSignerImpl::GetCharacteristicsL(const TAny*& aPluginCharacteristics) + { + TInt numCiphers = sizeof(KSignerCharacteristics)/sizeof(TAsymmetricSignatureCharacteristics*); + TInt32 implUid = ImplementationUid().iUid; + for (TInt i = 0; i < numCiphers; ++i) + { + if (KSignerCharacteristics[i]->cmn.iImplementationUID == implUid) + { + aPluginCharacteristics = KSignerCharacteristics[i]; + break; + } + } + } + +void CSignerImpl::DoSetKeyL(const CKey& aPrivateKey) + { + delete iKey; + iKey = CKey::NewL(aPrivateKey); + } + +void CSignerImpl::ConstructL(const CKey& aPrivateKey) + { + SetKeyL(aPrivateKey); + } + + +// Methods implemented in subclass. No coverage here. +#ifdef _BullseyeCoverage +#pragma suppress_warnings on +#pragma BullseyeCoverage off +#pragma suppress_warnings off +#endif +void CSignerImpl::SetPaddingModeL(TUid /*aPaddingMode*/) + { + // Override in subclass + User::Leave(KErrNotSupported); + } + +void CSignerImpl::SetKeyL(const CKey& /*aPrivateKey*/) + { + // Override in subclass + User::Leave(KErrNotSupported); + } + +TInt CSignerImpl::GetMaximumInputLengthL() const + { + // Override in subclass + User::Leave(KErrNotSupported); + return 0; + } + +TInt CSignerImpl::GetMaximumOutputLengthL() const + { + // Override in subclass + User::Leave(KErrNotSupported); + return 0; + } diff -r 7e3f204e6c81 -r f9c11be8c0b3 cryptoplugins/cryptospiplugins/source/softwarecrypto/signerimpl.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/cryptoplugins/cryptospiplugins/source/softwarecrypto/signerimpl.h Tue Dec 01 11:12:04 2009 +0000 @@ -0,0 +1,95 @@ +/* +* Copyright (c) 2006-2009 Nokia Corporation and/or its subsidiary(-ies). +* All rights reserved. +* This component and the accompanying materials are made available +* under the terms of the License "Eclipse Public License v1.0" +* which accompanies this distribution, and is available +* at the URL "http://www.eclipse.org/legal/epl-v10.html". +* +* Initial Contributors: +* Nokia Corporation - initial contribution. +* +* Contributors: +* +* Description: +* +*/ + + +#ifndef __SIGNERIMPL_H__ +#define __SIGNERIMPL_H__ + +/** +@file +@internalComponent +@released +*/ + +#include +#include +#include +#include "signerplugin.h" +#include + +#include "common/inlines.h" + +/** + * Abstract base class for signer plug-ins. + */ +namespace SoftwareCrypto + { + using namespace CryptoSpi; + + NONSHARABLE_CLASS(CSignerImpl) : public CBase, public MSigner + { + public: + // Override MPlugin virtual functions + void Close(); + void Reset(); // Always call reset in super-class if you override this + TAny* GetExtension(TUid aExtensionId); + void GetCharacteristicsL(const TCharacteristics*& aPluginCharacteristics); + // End of MPlugin + + // Override MSignatureBase virtual functions + virtual void SetPaddingModeL(TUid aPaddingMode); + virtual void SetKeyL(const CKey& aPrivateKey); + virtual TInt GetMaximumInputLengthL() const; + virtual TInt GetMaximumOutputLengthL() const; + // End of MSignatureBase + + /// Destructor + ~CSignerImpl(); + + protected: + /// Constructor + CSignerImpl(); + + /** + Second phase of construction + @param aKey The signing key + */ + virtual void ConstructL(const CKey& aKey); + + /** + Helper function implemented by concrete cipher sub-class that allows + GetCharacteristicsL to return the correct characteristics object. + @return The implemention uid + */ + virtual TUid ImplementationUid() const = 0; + + /** + Store the signing key. The key length is also checked to meet export restrictions and + to ensure that it is appropriate for the cipher. + @param aKey The key + */ + virtual void DoSetKeyL(const CKey& aKey); + + protected: + /// the key, extracted from a CKey object + CKey* iKey; + + private: + }; + } + +#endif // __SIGNERIMPL_H__ diff -r 7e3f204e6c81 -r f9c11be8c0b3 cryptoplugins/cryptospiplugins/source/softwarecrypto/softwarehashbase.cpp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/cryptoplugins/cryptospiplugins/source/softwarecrypto/softwarehashbase.cpp Tue Dec 01 11:12:04 2009 +0000 @@ -0,0 +1,326 @@ +/* +* Copyright (c) 2007-2009 Nokia Corporation and/or its subsidiary(-ies). +* All rights reserved. +* This component and the accompanying materials are made available +* under the terms of the License "Eclipse Public License v1.0" +* which accompanies this distribution, and is available +* at the URL "http://www.eclipse.org/legal/epl-v10.html". +* +* Initial Contributors: +* Nokia Corporation - initial contribution. +* +* Contributors: +* +* Description: +* software hash base class implementation +* software hash base class implementation +* +*/ + + +/** + @file +*/ + +#include "softwarehashbase.h" + +#include +#include "pluginconfig.h" +#include "keys.h" +#include "md2impl.h" +#include "md5impl.h" +#include "md4impl.h" +#include "sha1impl.h" +#include "sha2impl.h" +#include "hmacimpl.h" + +using namespace SoftwareCrypto; + +CSoftwareHash* CSoftwareHash::NewL(TUid aAlgorithm, TUid aOperationMode, const CKey* aKey) + { + CSoftwareHash* self=NewLC(aAlgorithm, aOperationMode, aKey); + CleanupStack::Pop(); + return self; + } + +CSoftwareHash* CSoftwareHash::NewL(TUid aAlgorithm) + { + CSoftwareHash* self=NewLC(aAlgorithm, CryptoSpi::KHashModeUid, NULL); + CleanupStack::Pop(); + return self; + } + +CSoftwareHash* CSoftwareHash::NewLC(TUid aAlgorithm, TUid aOperationMode, const CKey* aKey) + { + CSoftwareHash* self=new (ELeave) CSoftwareHash(); + CleanupStack::PushL(self); + self->ConstructL(aAlgorithm, aOperationMode, aKey); + return self; + } + +CSoftwareHash::CSoftwareHash() + { + } + +CSoftwareHash::~CSoftwareHash() + { + if (iHashImpl) + { + iHashImpl->Close(); + } + + if (iHmacImpl) + { + iHmacImpl->Close(); + } + delete iKey; + } + +void CSoftwareHash::ConstructL(TUid aAlgorithm, TUid aOperationMode, const CKey* aKey) + { + // + // Only Hash and Hmac mode are supported. + // + if (aOperationMode!=KHmacModeUid && aOperationMode!=KHashModeUid) + { + User::Leave(KErrNotSupported); + } + + //Set the key if there is one + if (aKey) + { + SetKeyL(*aKey); + } + + switch (aAlgorithm.iUid) + { + case KCryptoPluginMd2: + { + iHashImpl=CMD2Impl::NewL(); + } + break; + + case KCryptoPluginMd5: + { + iHashImpl=CMD5Impl::NewL(); + } + break; + + case KCryptoPluginMd4: + { + iHashImpl=CMD4Impl::NewL(); + } + break; + + case KCryptoPluginSha1: + { + iHashImpl=CSHA1Impl::NewL(); + } + break; + + case KCryptoPluginSha224: + case KCryptoPluginSha256: + case KCryptoPluginSha384: + case KCryptoPluginSha512: + { + iHashImpl=CSHA2Impl::NewL(aAlgorithm.iUid); + } + break; + + default: + User::Leave(KErrNotSupported); + } + + SetOperationModeL(aOperationMode); + } + +void CSoftwareHash::SetOperationModeL(TUid aOperationMode) + { + switch (aOperationMode.iUid) + { + case KHmacMode: + { + // + //Only create hmac implementation if there isn't one + // + if (!iHmacImpl) + { + if (iKey) + { + iHmacImpl=CHMacImpl::NewL(*iKey, iHashImpl); + } + else + { + iHmacImpl=CHMacImpl::NewL(iHashImpl); + } + } + } + break; + + case KHashMode: + { + Reset(); + } + break; + + default: + User::Leave(KErrNotSupported); + } + + // + // Set the operation mode. + // + iOperationMode=aOperationMode; + } + +MSoftwareHash* CSoftwareHash::Impl() + { + MSoftwareHash* impl=NULL; + if (iOperationMode==KHashModeUid) + { + impl=iHashImpl; + } + else if (iOperationMode==KHmacModeUid && iKey) + { + impl=iHmacImpl; + } + return impl; + } + +void CSoftwareHash::SetKeyL(const CKey& aKey) + { + Reset(); + delete iKey; + iKey=CKey::NewL(aKey); + if (iHmacImpl) + { + iHmacImpl->SetKeyL(aKey); + } + } + +void CSoftwareHash::Reset() + { + if (iHashImpl) + { + iHashImpl->Reset(); + } + + if (iHmacImpl) + { + iHmacImpl->Reset(); + } + } + +void CSoftwareHash::Close() + { + delete this; + } + +void CSoftwareHash::GetCharacteristicsL(const TCharacteristics*& aPluginCharacteristics) + { + MSoftwareHash* impl=Impl(); + if (impl) + { + impl->GetCharacteristicsL(aPluginCharacteristics); + } + else + { + User::Leave(KErrNotReady); + } + } + +const CExtendedCharacteristics* CSoftwareHash::GetExtendedCharacteristicsL() + { + MSoftwareHash* impl=Impl(); + if (!impl) + { + User::Leave(KErrNotReady); + } + return impl->GetExtendedCharacteristicsL(); + } + +TAny* CSoftwareHash::GetExtension(TUid aExtensionId) + { + MSoftwareHash* impl=Impl(); + if (impl) + { + return impl->GetExtension(aExtensionId); + } + else + { + return NULL; + } + } + +TPtrC8 CSoftwareHash::Hash(const TDesC8& aMessage) + { + MSoftwareHash* impl=Impl(); + if (impl) + { + return impl->Hash(aMessage); + } + else + { + return KNullDesC8(); + } + } + +void CSoftwareHash::Update(const TDesC8& aMessage) + { + MSoftwareHash* impl=Impl(); + if (impl) + { + return impl->Update(aMessage); + } + } + +TPtrC8 CSoftwareHash::Final(const TDesC8& aMessage) + { + MSoftwareHash* impl=Impl(); + if (impl) + { + return impl->Final(aMessage); + } + else + { + return KNullDesC8(); + } + } + +MHash* CSoftwareHash::ReplicateL() + { + CSoftwareHash* that=new(ELeave)CSoftwareHash(); + CleanupStack::PushL(that); + if (this->iKey) + { + that->iKey=CKey::NewL(*this->iKey); + } + that->iOperationMode=this->iOperationMode; + that->iHashImpl=static_cast(this->iHashImpl->ReplicateL()); + if (this->iHmacImpl) + { + that->iHmacImpl=static_cast(this->iHmacImpl->ReplicateL()); + } + CleanupStack::Pop(); + return that; + } + +MHash* CSoftwareHash::CopyL() + { + CSoftwareHash* that=new(ELeave)CSoftwareHash(); + CleanupStack::PushL(that); + if (this->iKey) + { + that->iKey=CKey::NewL(*this->iKey); + } + that->iOperationMode=this->iOperationMode; + that->iHashImpl=static_cast(this->iHashImpl->CopyL()); + if (this->iHmacImpl) + { + that->iHmacImpl=static_cast(this->iHmacImpl->CopyL()); + } + CleanupStack::Pop(); + return that; + } + + diff -r 7e3f204e6c81 -r f9c11be8c0b3 cryptoplugins/cryptospiplugins/source/softwarecrypto/softwarehashbase.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/cryptoplugins/cryptospiplugins/source/softwarecrypto/softwarehashbase.h Tue Dec 01 11:12:04 2009 +0000 @@ -0,0 +1,130 @@ +/* +* Copyright (c) 2006-2009 Nokia Corporation and/or its subsidiary(-ies). +* All rights reserved. +* This component and the accompanying materials are made available +* under the terms of the License "Eclipse Public License v1.0" +* which accompanies this distribution, and is available +* at the URL "http://www.eclipse.org/legal/epl-v10.html". +* +* Initial Contributors: +* Nokia Corporation - initial contribution. +* +* Contributors: +* +* Description: +* Software hash base definition +* +*/ + + +/** + @file + @internalComponent + @released +*/ + +#ifndef __CRYPTOAPI_SOFTWAREHASHBASE_H__ +#define __CRYPTOAPI_SOFTWAREHASHBASE_H__ + +#include +#include "keys.h" + +namespace SoftwareCrypto + { + using namespace CryptoSpi; + /** + Interfaces for Software Hash + */ + class MSoftwareHash : public MHash + { + public: + /** + Restores the internal state of the message digest + to a previously stored state. + */ + virtual void RestoreState() = 0; + + /** + Stores the internal state of the message digest. + */ + virtual void StoreState() = 0; + }; + + /** + Proxy class Software Hash and Hmac implementation + */ + NONSHARABLE_CLASS(CSoftwareHash) : public MHash, public CBase + { + public: + // + //NewL & NewLC + // + static CSoftwareHash* NewL(TUid aAlgorithm, TUid aOperationMode, const CKey* aKey); + static CSoftwareHash* NewLC(TUid aAlgorithm, TUid aOperationMode, const CKey* aKey); + static CSoftwareHash* NewL(TUid aAlgorithm); + + // + // Destructor + // + ~CSoftwareHash(); + // + //From MPlugin + // + void Reset(); + void Close(); + void GetCharacteristicsL(const TCharacteristics*& aPluginCharacteristics); + const CExtendedCharacteristics* GetExtendedCharacteristicsL(); + TAny* GetExtension(TUid aExtensionId); + // + //From MHash + // + TPtrC8 Hash(const TDesC8& aMessage); + void Update(const TDesC8& aMessage); + TPtrC8 Final(const TDesC8& aMessage); + MHash* ReplicateL(); + MHash* CopyL(); + void SetKeyL(const CKey& aKey); + void SetOperationModeL(TUid aOperationMode); + + private: + // + //Constructor + // + CSoftwareHash(); + void ConstructL(TUid aAlgorithm, TUid aOperationMode, const CKey* aKey); + + // + //get the active implementation + // + MSoftwareHash* Impl(); + + private: + /** + The Key for HMAC mode operation + */ + CKey* iKey; + + /** + The Uid for the operation mode + */ + TUid iOperationMode; + + /** + The hash implementation + */ + MSoftwareHash* iHashImpl; + + /** + The Hmac implementation + */ + MSoftwareHash* iHmacImpl; + }; + + GLDEF_C inline TUint CMD_R(TUint a,TUint s) + { + return (a<>(32-s)); + } + } + + +#endif // __CRYPTOAPI_SOFTWAREHASHBASE_H__ diff -r 7e3f204e6c81 -r f9c11be8c0b3 cryptoplugins/cryptospiplugins/source/softwarecrypto/symmetriccipherimpl.cpp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/cryptoplugins/cryptospiplugins/source/softwarecrypto/symmetriccipherimpl.cpp Tue Dec 01 11:12:04 2009 +0000 @@ -0,0 +1,650 @@ +/* +* Copyright (c) 2007-2009 Nokia Corporation and/or its subsidiary(-ies). +* All rights reserved. +* This component and the accompanying materials are made available +* under the terms of the License "Eclipse Public License v1.0" +* which accompanies this distribution, and is available +* at the URL "http://www.eclipse.org/legal/epl-v10.html". +* +* Initial Contributors: +* Nokia Corporation - initial contribution. +* +* Contributors: +* +* Description: +* +*/ + + +#include "symmetriccipherimpl.h" + +#include +#include +#include +#include "keys.h" +#include +#include +#include "pluginconfig.h" +#include +#include "common/inlines.h" + +using namespace SoftwareCrypto; + +// +// Implementation of Symmetric Cipher class +// +CSymmetricCipherImpl::CSymmetricCipherImpl() + { + } + +void CSymmetricCipherImpl::ConstructL(const CKey& aKey) + { + DoSetKeyL(aKey); + } + +void CSymmetricCipherImpl::SecureDelete(HBufC8*& aBuffer) + { + if (aBuffer) + { + aBuffer->Des().FillZ(); + } + delete aBuffer; + aBuffer = 0; + } + +CSymmetricCipherImpl::~CSymmetricCipherImpl() + { + SecureDelete(iKey); + } + +void CSymmetricCipherImpl::Close() + { + delete this; + } + +TAny* CSymmetricCipherImpl::GetExtension(TUid /*aExtensionId*/) + { + return 0; + } + +void CSymmetricCipherImpl::GetCharacteristicsL(const TAny*& aPluginCharacteristics) + { + TInt numCiphers = sizeof(KSymmetricCipherCharacteristics)/sizeof(TSymmetricCipherCharacteristics*); + TInt32 implUid = ImplementationUid().iUid; + for (TInt i = 0; i < numCiphers; ++i) + { + if (KSymmetricCipherCharacteristics[i]->cmn.iImplementationUID == implUid) + { + aPluginCharacteristics = KSymmetricCipherCharacteristics[i]; + break; + } + } + } + +TInt CSymmetricCipherImpl::GetKeyStrength() const + { + return BytesToBits(iKey->Length()); + } + +HBufC8* CSymmetricCipherImpl::ExtractKeyDataLC(const CKey& aKey) const + { + const TDesC8& keyContent = aKey.GetTDesC8L(KSymmetricKeyParameterUid); + return keyContent.AllocLC(); + } + +TInt CSymmetricCipherImpl::KeySize() const + { + // return key size in BITS + return BytesToBits(iKeyBytes); + } + +void CSymmetricCipherImpl::DoSetKeyL(const CKey& aKey) + { + HBufC8* key = ExtractKeyDataLC(aKey); + TInt keyLength(key->Length()); + + TCrypto::IsSymmetricWeakEnoughL(BytesToBits(keyLength)); + if (! IsValidKeyLength(keyLength)) + { + CleanupStack::PopAndDestroy(key); + User::Leave(KErrNotSupported); + } + + SecureDelete(iKey); + CleanupStack::Pop(key); + iKey = key; + iKeyBytes = keyLength; + } + +// +// Implementation of Symmetric Stream Cipher +// +CSymmetricStreamCipherImpl::CSymmetricStreamCipherImpl() + { + } + +CSymmetricStreamCipherImpl::~CSymmetricStreamCipherImpl() + { + } + +void CSymmetricStreamCipherImpl::SetKeyL(const CKey& aKey) + { + DoSetKeyL(aKey); + TCrypto::IsSymmetricWeakEnoughL(GetKeyStrength()); + Reset(); + } + +void CSymmetricStreamCipherImpl::ConstructL(const CKey& aKey) + { + CSymmetricCipherImpl::ConstructL(aKey); + } + +TInt CSymmetricStreamCipherImpl::BlockSize() const + { + // return block size in BITS + return BYTE_BITS; + } + +void CSymmetricStreamCipherImpl::SetCryptoModeL(TUid /*aCryptoMode*/) + { + // Call the reset method. + Reset(); + } + +TInt CSymmetricStreamCipherImpl::MaxOutputLength(TInt aInputLength) const + { + return aInputLength; + } + +TInt CSymmetricStreamCipherImpl::MaxFinalOutputLength(TInt aInputLength) const + { + return aInputLength; + } + +void CSymmetricStreamCipherImpl::ProcessL(const TDesC8& aInput, TDes8& aOutput) + { + TInt outputIndex = aOutput.Size(); + + // aOutput may already have outputIndex bytes of data in it + // check there will still be enough space to process the result + __ASSERT_DEBUG(aOutput.MaxLength() - outputIndex >= MaxOutputLength(aInput.Length()), User::Panic(KCryptoPanic, ECryptoPanicOutputDescriptorOverflow)); + + aOutput.Append(aInput); + + TPtr8 transformBuf((TUint8*)(aOutput.Ptr()) + outputIndex, aInput.Size(), + aInput.Size()); + DoProcess(transformBuf); + } + +void CSymmetricStreamCipherImpl::ProcessFinalL(const TDesC8& aInput, TDes8& aOutput) + { + ProcessL(aInput, aOutput); + } + +// +// Implementation of Symmetric Block Cipher +// +CSymmetricBlockCipherImpl::CSymmetricBlockCipherImpl( + TUint8 aBlockBytes, + TUid aCryptoMode, + TUid aOperationMode, + TUid aPaddingMode) : + iBlockBytes(aBlockBytes), + iCryptoMode(aCryptoMode), + iOperationMode(aOperationMode), + iPaddingMode(aPaddingMode), + iBufferedPlaintextPtr(0,0,0), + iCtrUnusedKeystreamPtr(0,0,0) + { + } + +CSymmetricBlockCipherImpl::~CSymmetricBlockCipherImpl() + { + delete iPadding; + delete [] iRegister; + delete [] iCurrentCipherText; + delete iBufferedPlaintext; + delete iCtrUnusedKeystream; + iIv.Close(); + iInputStore.Close(); + iPaddingBlock.Close(); + } + + +void CSymmetricBlockCipherImpl::ConstructL(const CKey& aKey) + { + CSymmetricCipherImpl::ConstructL(aKey); + DoSetOperationModeL(iOperationMode); + DoSetCryptoModeL(iCryptoMode); + DoSetPaddingModeL(iPaddingMode); + + iInputStore.ReAllocL(iBlockBytes); + iPaddingBlock.ReAllocL(iBlockBytes); + + iRegister = new(ELeave) TUint32[iBlockBytes/4]; + iRegisterPtr = reinterpret_cast(iRegister); + + iCurrentCipherText = new(ELeave) TUint32[iBlockBytes/4]; + iCurrentCipherTextPtr = reinterpret_cast(iCurrentCipherText); + + iBufferedPlaintext = HBufC8::NewL(iBlockBytes); + iBufferedPlaintextPtr.Set(iBufferedPlaintext->Des()); + + iCtrUnusedKeystream = HBufC8::NewL(iBlockBytes); + iCtrUnusedKeystreamPtr.Set(iCtrUnusedKeystream->Des()); + } + +void CSymmetricBlockCipherImpl::Reset() + { + iInputStore.Zero(); + iPaddingBlock.Zero(); + iCtrUnusedKeystreamPtr.Zero(); + + if (iOperationMode.iUid == KOperationModeCBC) + { + // only copy the IV if it is already set + if (iIv.MaxLength() > 0) + { + Mem::Copy(iRegisterPtr, &iIv[0], iBlockBytes); + } + } + } + +void CSymmetricBlockCipherImpl::SetKeyL(const CKey& aKey) + { + DoSetKeyL(aKey); + TCrypto::IsSymmetricWeakEnoughL(GetKeyStrength()); + SetKeySchedule(); + Reset(); + } + +void CSymmetricBlockCipherImpl::SetOperationModeL(TUid aOperationMode) + { + DoSetOperationModeL(aOperationMode); + Reset(); + } + +void CSymmetricBlockCipherImpl::SetCryptoModeL(TUid aCryptoMode) + { + DoSetCryptoModeL(aCryptoMode); + SetKeySchedule(); + Reset(); + } + +void CSymmetricBlockCipherImpl::SetPaddingModeL(TUid aPaddingMode) + { + DoSetPaddingModeL(aPaddingMode); + Reset(); + } + +void CSymmetricBlockCipherImpl::SetIvL(const TDesC8& aIv) + { + if ((iOperationMode.iUid != KOperationModeCBC) && (iOperationMode.iUid != KOperationModeCTR)) + { + User::Leave(KErrNotSupported); + } + DoSetIvL(aIv); + Reset(); + } + +void CSymmetricBlockCipherImpl::DoSetOperationModeL(TUid aOperationMode) + { + switch (aOperationMode.iUid) + { + case KOperationModeNone: + case KOperationModeECB: + case KOperationModeCBC: + break; + case KOperationModeCTR: + SetCryptoModeL(KCryptoModeEncryptUid); + break; + default: + User::Leave(KErrNotSupported); + } + iOperationMode = aOperationMode; + } + +void CSymmetricBlockCipherImpl::DoSetCryptoModeL(TUid aCryptoMode) + { + switch (aCryptoMode.iUid) + { + case KCryptoModeEncrypt: + break; + case KCryptoModeDecrypt: + if (iOperationMode.iUid == KOperationModeCTR) + { + return; + } + break; + default: + User::Leave(KErrNotSupported); + } + iCryptoMode = aCryptoMode; + } + +void CSymmetricBlockCipherImpl::DoSetPaddingModeL(TUid aPaddingMode) + { + CPadding* padding(0); + switch (aPaddingMode.iUid) + { + case KPaddingModeNone: + padding = CPaddingNone::NewL(iBlockBytes); + break; + case KPaddingModeSSLv3: + padding = CPaddingSSLv3::NewL(iBlockBytes); + break; + case KPaddingModePKCS7: + padding = CPaddingPKCS7::NewL(iBlockBytes); + break; + default: + User::Leave(KErrNotSupported); + } + delete iPadding; + iPadding = padding; + iPaddingMode = aPaddingMode; + } + +void CSymmetricBlockCipherImpl::DoSetIvL(const TDesC8& aIv) + { + iIv.ReAllocL(iBlockBytes); + iIv.SetLength(iBlockBytes); + + iIv.Zero(); + if (aIv.Length() != iBlockBytes) + { + User::Leave(KErrArgument); + } + iIv = aIv; + Mem::Copy(iRegisterPtr, &iIv[0], iBlockBytes); //for CTR mode + + } + +TInt CSymmetricBlockCipherImpl::BlockSize() const + { + // return block size in BITS + if (iOperationMode.iUid == KOperationModeCTR) + { + return 8; + } + else + { + return BytesToBits(iBlockBytes); + } + } + +TInt CSymmetricBlockCipherImpl::MaxOutputLength(TInt aInputLength) const + { + if (iOperationMode.iUid == KOperationModeCTR) + { + return aInputLength; + } + else + { + // The maximum output length required for Process is equal to the + // size of the number of whole input blocks available. + // + // The block bytes is a power of two so we can use this to avoid + // doing a real mod operation + TUint inputStoreLength(iInputStore.Length()); + TInt rem = (aInputLength + inputStoreLength) & (iBlockBytes - 1); + return (aInputLength + inputStoreLength - rem); + } + } + +TInt CSymmetricBlockCipherImpl::MaxFinalOutputLength(TInt aInputLength) const + { + if (iOperationMode.iUid == KOperationModeCTR) + { + return aInputLength; + } + else if (iCryptoMode.iUid == KCryptoModeEncrypt) + { + return iPadding->MaxPaddedLength(iInputStore.Length() + aInputLength); + } + else + { + return iPadding->MaxUnPaddedLength(aInputLength + iInputStore.Size()); + } + } + +void CSymmetricBlockCipherImpl::ProcessL(const TDesC8& aInput, TDes8& aOutput) + { + // if we're running in CBC or CTR mode then we must have an IV set before we can + // do any processing ie call SetIvL() before this method + if ((iOperationMode.iUid == KOperationModeCBC) || (iOperationMode.iUid == KOperationModeCTR)) + { + if (iIv.MaxLength() == 0) + { + User::Leave(KErrNotSupported); + } + } + + TInt inputLength(aInput.Length()); + TInt inputStoreLength(iInputStore.Length()); + + if (MaxOutputLength(inputLength) > aOutput.MaxLength()) + { + User::Leave(KErrOverflow); + } + + if (iOperationMode.iUid == KOperationModeCTR) + { + ProcessCtrL(aInput, aOutput); + } + else + { + TUint8 blockSizeLog = CryptoLog2(iBlockBytes); + TInt wholeBlocks = (inputLength + inputStoreLength) >> blockSizeLog; + TInt wholeBlocksSize = wholeBlocks << blockSizeLog; + + if (wholeBlocks) + { + TInt outputLength(aOutput.Length()); + + if (inputStoreLength > 0) + { + aOutput.Append(iInputStore); + iInputStore.Zero(); + } + aOutput.Append(aInput.Left(wholeBlocksSize - inputStoreLength)); + Transform(const_cast(aOutput.Ptr()) + outputLength, wholeBlocks); + } + + TInt remainingBytes = inputLength + inputStoreLength - wholeBlocksSize; + if (remainingBytes > 0) + { + iInputStore.Append(aInput.Right(remainingBytes)); + } + } + } + +void CSymmetricBlockCipherImpl::ProcessFinalL(const TDesC8& aInput, TDes8& aOutput) + { + if (iOperationMode.iUid == KOperationModeCTR) + { + ProcessL(aInput, aOutput); + } + else + { + // if we're running in CBC mode then we must have an IV set before we can + // do any processing ie call SetIvL() before this method + if (iOperationMode.iUid == KOperationModeCBC) + { + if (iIv.MaxLength() == 0) + { + User::Leave(KErrNotSupported); + } + } + + if (iCryptoMode.iUid == KCryptoModeEncrypt) + { + return DoProcessFinalEncryptL(aInput, aOutput); + } + else + { + return DoProcessFinalDecryptL(aInput, aOutput); + } + } + } + +void CSymmetricBlockCipherImpl::DoProcessFinalEncryptL(const TDesC8& aInput, TDes8& aOutput) + { + if (MaxFinalOutputLength(aInput.Length()) > aOutput.MaxLength() - aOutput.Length()) + { + User::Leave(KErrOverflow); + } + + // process everything up to the last (possibly empty block) + TInt outputStartIndex = aOutput.Length(); + ProcessL(aInput, aOutput); + + // pad the plaintext + iPadding->PadL(iInputStore, iPaddingBlock); + + // if padding required + if (iPaddingBlock.Length() > 0) + { + iInputStore.Zero(); + + // make sure the output is a multiple of the block size + User::LeaveIfError(((aOutput.Length() - outputStartIndex + iPaddingBlock.Length()) % iBlockBytes) == 0 ? KErrNone : KErrInvalidPadding); + + outputStartIndex = aOutput.Length(); + aOutput.Append(iPaddingBlock); + iPaddingBlock.Zero(); + TransformEncrypt(const_cast(aOutput.Ptr()) + outputStartIndex, 1); + } + } + +void CSymmetricBlockCipherImpl::DoProcessFinalDecryptL(const TDesC8& aInput, TDes8& aOutput) + { + if (MaxFinalOutputLength(aInput.Length()) > aOutput.MaxLength() - aOutput.Length()) + { + User::Leave(KErrOverflow); + } + + // Input length (including inputstore) must be a multiple of the + // block size in length + if ((aInput.Length() + iInputStore.Length()) & (iBlockBytes - 1)) + { + User::Leave(KErrArgument); + } + + if(aInput.Length() > iBlockBytes) + { + HBufC8* processBuf = HBufC8::NewLC(MaxFinalOutputLength(aInput.Length())); + TPtr8 processPtr = processBuf->Des(); + + ProcessL(aInput, processPtr); + + ASSERT(iInputStore.Length()==0); // all the blocks should have been decrypted + + // Unpad processPtr into aOutput + iPadding->UnPadL(processPtr, aOutput); + + CleanupStack::PopAndDestroy(processBuf); + } + else + { + // now contains the final ciphertext block + iInputStore.Append(aInput); + + // Decrypt the last _padding_ blocksize into a new buffer + TransformDecrypt(const_cast(iInputStore.Ptr()), 1); + + // Unpad the last block and append to output + iPadding->UnPadL(iInputStore, aOutput); + } + + iPaddingBlock.Zero(); + iInputStore.Zero(); + } + + +/** +CTR mode behaves like a stream cipher, accepting input of any arbitrary length. This results +in a significant body of code that behaves fundamentally differently to the ECB and CBC modes. +ProcessCtrL() is called by ProcessL() when operating in CTR mode, wrapping up all this +functionality into a separate method for clarity. + +Encrypting zero-filled bytes will return the keystream since the output of Transformation is simply +the input XORed with the keystream. + +See: http://csrc.nist.gov/publications/nistpubs/800-38a/sp800-38a.pdf +*/ +void CSymmetricBlockCipherImpl::ProcessCtrL(const TDesC8& aInput, TDes8& aOutput) + { + TInt inputLength(aInput.Length()); + + TInt outputLength(aOutput.Length()); + TInt amountToXor = Min(iCtrUnusedKeystreamPtr.Length(), inputLength); + + // Try applying previously unused key stream bytes. + if (amountToXor > 0) + { + aOutput.Append(aInput.Left(amountToXor)); + for (TInt i = 0; i < amountToXor; ++i) + { + aOutput[outputLength + i] ^= iCtrUnusedKeystreamPtr[i]; + } + iCtrUnusedKeystreamPtr = iCtrUnusedKeystreamPtr.RightTPtr((iCtrUnusedKeystreamPtr.Length() - amountToXor)); + } + + TInt amountToEncode = inputLength - amountToXor; + + if ((iCtrUnusedKeystreamPtr.Length() == 0) && (amountToEncode > 0)) + { + // For each whole block's worth of input, transform it. + TInt wholeBlocks = (amountToEncode) / iBlockBytes; + TInt wholeBlocksSize = wholeBlocks * iBlockBytes; + outputLength = aOutput.Length(); + + if (wholeBlocks) + { + aOutput.Append(aInput.Mid(amountToXor, wholeBlocksSize)); + Transform(const_cast(aOutput.Ptr()) + outputLength, wholeBlocks); + } + + // CTR mode can handle arbitrary sized inputs. Here any remaining input data of less than the block size + // is padded with zeros and then transformed. On return this padded section of the block will contain the next + // sequence of keystream, which is copied to iCtrUnusedKeystream for use next time ProcessCtrL() is called. + TInt remainingBytes = amountToEncode - wholeBlocksSize; + iCtrUnusedKeystreamPtr = iCtrUnusedKeystream->Des(); + iCtrUnusedKeystreamPtr.SetMax(); + iCtrUnusedKeystreamPtr.FillZ(); + iCtrUnusedKeystreamPtr.Copy(aInput.Right(remainingBytes)); + iCtrUnusedKeystreamPtr.SetLength(iBlockBytes); + + Transform(const_cast(iCtrUnusedKeystreamPtr.Ptr()), 1); + + aOutput.Append(iCtrUnusedKeystreamPtr.Left(remainingBytes)); + + iCtrUnusedKeystreamPtr = iCtrUnusedKeystreamPtr.RightTPtr((iCtrUnusedKeystreamPtr.Length() - remainingBytes)); + } + } + + + +// Methods implemented in subclass. No coverage here. +#ifdef _BullseyeCoverage +#pragma suppress_warnings on +#pragma BullseyeCoverage off +#pragma suppress_warnings off +#endif +void CSymmetricStreamCipherImpl::SetOperationModeL(TUid /*aOperationMode*/) + { + // Override in subclass + User::Leave(KErrNotSupported); + } + +void CSymmetricStreamCipherImpl::SetPaddingModeL(TUid /*aPaddingMode*/) + { + // Override in subclass + User::Leave(KErrNotSupported); + } + +void CSymmetricStreamCipherImpl::SetIvL(const TDesC8& /*aIv*/) + { + // Override in subclass + User::Leave(KErrNotSupported); + } diff -r 7e3f204e6c81 -r f9c11be8c0b3 cryptoplugins/cryptospiplugins/source/softwarecrypto/symmetriccipherimpl.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/cryptoplugins/cryptospiplugins/source/softwarecrypto/symmetriccipherimpl.h Tue Dec 01 11:12:04 2009 +0000 @@ -0,0 +1,401 @@ +/* +* Copyright (c) 2006-2009 Nokia Corporation and/or its subsidiary(-ies). +* All rights reserved. +* This component and the accompanying materials are made available +* under the terms of the License "Eclipse Public License v1.0" +* which accompanies this distribution, and is available +* at the URL "http://www.eclipse.org/legal/epl-v10.html". +* +* Initial Contributors: +* Nokia Corporation - initial contribution. +* +* Contributors: +* +* Description: +* +*/ + + +#ifndef __SYMMETRICCIPHERIMPL_H__ +#define __SYMMETRICCIPHERIMPL_H__ + +/** +@file +@internalComponent +@released +*/ + +#include +#include +#include +#include +#include "symmetriccipherplugin.h" + +/** The maximum block size supported (in bytes) */ +const TUint KMaxBlockSizeSupported = 32; + +/** +Abstract base class for symmetric cipher plug-ins. +*/ +namespace SoftwareCrypto + { + using namespace CryptoSpi; + + NONSHARABLE_CLASS(CSymmetricCipherImpl) : public CBase, public MSymmetricCipher + { + public: + /** + Implemented by each cipher subclass to determine whether the + specified key length is valid for that cipher. + This is called by ConstructL and SetKeyL + @param aKeyLength The key length in bytes to verify. + */ + virtual TBool IsValidKeyLength(TInt aKeyBytes) const = 0; + + /** + Helper function implemented by concrete cipher sub-class that + allows GetCharacteristicsL to return the correct characteristics object. + @return The implemention uid + */ + virtual TUid ImplementationUid() const = 0; + + /** + Gets the strength of the current key, needed to check whether the cipher + may operate if strong cryptography is not enabled. + @return The strength of the current key + */ + virtual TInt GetKeyStrength() const; + + + // Override MPlugin virtual functions + void Close(); + TAny* GetExtension(TUid aExtensionId); + void GetCharacteristicsL(const TCharacteristics*& aPluginCharacteristics); + // End of MPlugin + + // Override MSymmetricCipherBase virtual functions + TInt KeySize() const; + + /// Destructor + ~CSymmetricCipherImpl(); + + protected: + + //Constructor + CSymmetricCipherImpl(); + + /** + Second phase of construction. Always call ConstructL in the super-class + if your override this method. + + @param aKey The key to initialise the cipher with. + */ + virtual void ConstructL(const CKey& aKey); + + /** + Extracts the raw symmetric key from a generic key object. The buffer + is placed on the cleanup stack. + + @param aKey The key object + @return A buffer containing the raw key value + */ + HBufC8* ExtractKeyDataLC(const CKey& aKey) const; + + /** + Zeros a buffer before deleting it to ensure that + the contents will not be visible to another process if the page + is re-used. + @param aBuffer The pointer (possibly null) to the buffer to delete. This + is set to null after deletion. + */ + void SecureDelete(HBufC8*& aBuffer); + + /** + Extracts the raw key from aKey and sets iKey and iKeyBytes + The key length is also checked to meet export restrictions and + to ensure that it is appropriate for the cipher. + @param aKey The key + */ + virtual void DoSetKeyL(const CKey& aKey); + + + protected: + /// the key, extracted from a CKey object + HBufC8* iKey; + + /// key size in bytes + TUint iKeyBytes; + + }; + + NONSHARABLE_CLASS(CSymmetricStreamCipherImpl) : public CSymmetricCipherImpl + { + public: + // Destructor + ~CSymmetricStreamCipherImpl(); + + // Override MSymmetricCipherBase virtual functions + TInt BlockSize() const; + void SetKeyL(const CKey& aKey); // override DoSetKeyL instead + void SetCryptoModeL(TUid aCryptoMode); + void SetOperationModeL(TUid aOperationMode); + void SetPaddingModeL(TUid aPaddingMode); + void SetIvL(const TDesC8& aIv); + TInt MaxOutputLength(TInt aInputLength) const; + TInt MaxFinalOutputLength(TInt aInputLength) const; + // End of MSymmetricCipherBase + + // Override MSymmetricCipher virtual functions + void ProcessL(const TDesC8& aInput, TDes8& aOutput); + void ProcessFinalL(const TDesC8& aInput, TDes8& aOutput); + // End of MSymmetricCipher + + protected: + // Constructor + CSymmetricStreamCipherImpl(); + + // Override CSymmetricCipherImpl virtual functions + virtual void ConstructL(const CKey& aKey); + + /** + Performs an encryption or decryption on supplied data. + @param aData On input, data to be transformed; + on return, transformed data. + */ + virtual void DoProcess(TDes8& aData) = 0; + }; + + NONSHARABLE_CLASS(CSymmetricBlockCipherImpl) : public CSymmetricCipherImpl + { + public: + + + /** + This function is invoked by SetKey and SetCryptoMode + allowing the cipher sub-class to rebuild it's key schedule. + N.B. It is assumed that the key schedule is NOT modified + by TransformEncrypt or TransformDecrypt + */ + virtual void SetKeySchedule() = 0; + + // Override MPlugin virtual functions + void Reset(); // Always call reset in super-class if you override this + // End of MPlugin virtual functions + + // Override MSymmetricCipherBase virtual functions + TInt BlockSize() const; + void SetKeyL(const CKey& aKey); // override DoSetKeyL instead + void SetCryptoModeL(TUid aCryptoMode); // override DoSetCryptoModeL instead + void SetOperationModeL(TUid aOperationMode); // override DoSetOperationMode instead + void SetPaddingModeL(TUid aPaddingMode); // override DoSetPaddingModeL instead + void SetIvL(const TDesC8& aIv); + + TInt MaxOutputLength(TInt aInputLength) const; + TInt MaxFinalOutputLength(TInt aInputLength) const; + // End of MSymmetricCipherBase + + // Override MSymmetricCipher virtual functions + void ProcessL(const TDesC8& aInput, TDes8& aOutput); + void ProcessFinalL(const TDesC8& aInput, TDes8& aOutput); + // End of MSymmetricCipher + + /// Destructor + ~CSymmetricBlockCipherImpl(); + protected: + /** + Constructor + @param aBlockBytes The block size in bytes + @param aOperationMode The mode of operation e.g. CBC + @param aCryptoMode Whether to encrypt or decrypt + */ + CSymmetricBlockCipherImpl( + TUint8 aBlockBytes, + TUid aOperationMode, + TUid aCryptoMode, + TUid aPaddingMode); + + // Override CSymmetricCipherImpl virtual functions + virtual void ConstructL(const CKey& aKey); + + /** + Validates and sets the crypto mode (iCryptoMode) + @param aCryptoMode The crypto mode + */ + virtual void DoSetCryptoModeL(TUid aCryptoMode); + + /** + Validates and sets the operation mode (iOperationMode) + @param aOperationMode The operation mode + */ + virtual void DoSetOperationModeL(TUid aOperationMode); + + /** + Validates and sets the padding mode (iPaddingMode & iPadding) + @param aPadding The desired padding mode + */ + virtual void DoSetPaddingModeL(TUid aPadding); + + void DoSetIvL(const TDesC8& aIv); + + inline void ModeEncryptStart(TUint8* aBuffer); + inline void ModeEncryptEnd(TUint8* aBuffer); + inline void ModeDecryptStart(TUint8* aBuffer); + inline void ModeDecryptEnd(TUint8* aBuffer); + + private: + + /** + Encrypts a number of blocks of data + + @param aBuffer The buffer containing exactly aNumBlocks of data to destructively encrypt + @param aNumBlocks The number of blocks of data to encrypt + */ + virtual void TransformEncrypt(TUint8* aBuffer, TUint aNumBlocks) = 0; + + /** + Decrypts a number of blocks of data + + @param aBuffer The buffer containing exactly aNumBlocks of data to destructively decrypt + @param aNumBlocks The number of blocks of data to decrypt + */ + virtual void TransformDecrypt(TUint8* aBuffer, TUint aNumBlocks) = 0; + + /// Pad the last block and encrypt + void DoProcessFinalEncryptL(const TDesC8& aInput, TDes8& aOutput); + + /// Decrypt and unpad the last block + void DoProcessFinalDecryptL(const TDesC8& aInput, TDes8& aOutput); + + inline void Transform(TUint8* aBuffer, TUint aNumBlocks); + + void ProcessCtrL(const TDesC8& aInput, TDes8& aOutput); + + protected: + + /// block size in bytes, current largest block size is 16 bytes (AES) + TUint8 iBlockBytes; + /// encryption or decryption + TUid iCryptoMode; + /// The block cipher mode e.g. ECB, CBC + TUid iOperationMode; + /// the current padding scheme + TUid iPaddingMode; + + /// the initialisation vector + RBuf8 iIv; + + /// current padding scheme implementation + CPadding* iPadding; + /// buffer to store blocks + RBuf8 iInputStore; + /// buffer to store input / output of padding + RBuf8 iPaddingBlock; + + /// The current block of cipher text - for CBC + TUint32* iCurrentCipherText; + /// A pointer to the current block of cipher text + TUint8* iCurrentCipherTextPtr; + + /** Used in both CBC and CTR mode. In CBC mode it stores the result of the last transform. In CTR mode + it stores the counter.*/ + TUint32* iRegister; + /** A pointer to iRegister.*/ + TUint8* iRegisterPtr; + + /** Used in CTR mode to buffer plaintext during encryption.*/ + HBufC8* iBufferedPlaintext; + /** Pointer to manipulate iBufferedPlaintext.*/ + TPtr8 iBufferedPlaintextPtr; + + /** CTR mode behaves like a stream cipher allowing arbitrary sized inputs to the encryption/decryption functions. + When handling an input whose length is not a multiple of the blocksize iCtrUnusedKeystream is used to buffer + the unused portions of keystream for use in the next call. Cleared in Reset().*/ + HBufC8* iCtrUnusedKeystream; + /** Pointer to manipulate iCtrUnusedKeystream.*/ + TPtr8 iCtrUnusedKeystreamPtr; + }; + + + inline void CSymmetricBlockCipherImpl::Transform(TUint8* aBuffer, TUint aNumBlocks) + { + if (iCryptoMode.iUid == KCryptoModeEncrypt) //if in CTR mode always in crypto mode encrypt + { + TransformEncrypt(aBuffer, aNumBlocks); + } + else if (iCryptoMode.iUid == KCryptoModeDecrypt) + { + TransformDecrypt(aBuffer, aNumBlocks); + } + else + { + ASSERT(EFalse); + } + } + + inline void CSymmetricBlockCipherImpl::ModeEncryptStart(TUint8* aBuffer) + { + if (iOperationMode.iUid == KOperationModeCBC) + { + for (TInt i = 0; i < iBlockBytes; ++i) + { + aBuffer[i] ^= iRegisterPtr[i]; + } + } + else if (iOperationMode.iUid == KOperationModeCTR) + { + iBufferedPlaintextPtr.Copy(aBuffer, iBlockBytes); + Mem::Copy(aBuffer, iRegister, iBlockBytes); + } + } + + inline void CSymmetricBlockCipherImpl::ModeEncryptEnd(TUint8* aBuffer) + { + if (iOperationMode.iUid == KOperationModeCBC) + { + for (TInt i = 0; i < iBlockBytes; ++i) + { + iRegisterPtr[i] = aBuffer[i]; + } + } + else if (iOperationMode.iUid == KOperationModeCTR) + { + //XOR the plaintext with the keystream and increment counter + for (TInt i = 0; i < iBlockBytes; ++i) + { + aBuffer[i] ^= iBufferedPlaintextPtr[i]; + } + for (TInt i = iBlockBytes - 1; i >= 0; --i) + { + if (++(iRegisterPtr[i]) != 0) break; + } + } + } + + inline void CSymmetricBlockCipherImpl::ModeDecryptStart(TUint8* aBuffer) + { + __ASSERT_DEBUG((iOperationMode.iUid != KOperationModeCTR), User::Panic(_L("CSymmetricBlockCipherImpl.h"), 1)); + if (iOperationMode.iUid == KOperationModeCBC) + { + for (TInt i = 0; i < iBlockBytes; ++i) + { + iCurrentCipherTextPtr[i] = aBuffer[i]; + } + } + } + + inline void CSymmetricBlockCipherImpl::ModeDecryptEnd(TUint8* aBuffer) + { + __ASSERT_DEBUG((iOperationMode.iUid != KOperationModeCTR), User::Panic(_L("CSymmetricBlockCipherImpl.h"), 2)); + if (iOperationMode.iUid == KOperationModeCBC) + { + // xor the output with the previous cipher text + for (TInt i = 0; i < iBlockBytes; ++i) + { + aBuffer[i] ^= iRegisterPtr[i]; + iRegisterPtr[i] = iCurrentCipherTextPtr[i]; + } + } + } + } + +#endif // __SYMMETRICCIPHERIMPL_H__ diff -r 7e3f204e6c81 -r f9c11be8c0b3 cryptoplugins/cryptospiplugins/source/softwarecrypto/verifierimpl.cpp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/cryptoplugins/cryptospiplugins/source/softwarecrypto/verifierimpl.cpp Tue Dec 01 11:12:04 2009 +0000 @@ -0,0 +1,108 @@ +/* +* Copyright (c) 2006-2009 Nokia Corporation and/or its subsidiary(-ies). +* All rights reserved. +* This component and the accompanying materials are made available +* under the terms of the License "Eclipse Public License v1.0" +* which accompanies this distribution, and is available +* at the URL "http://www.eclipse.org/legal/epl-v10.html". +* +* Initial Contributors: +* Nokia Corporation - initial contribution. +* +* Contributors: +* +* Description: +* +*/ + + +#include +#include +#include "keys.h" + +#include "verifierimpl.h" + +#include +#include "pluginconfig.h" + +using namespace SoftwareCrypto; + +CVerifierImpl::CVerifierImpl() + { + } + +CVerifierImpl::~CVerifierImpl() + { + delete iKey; + } + +void CVerifierImpl::Close() + { + delete this; + } + +void CVerifierImpl::Reset() + { + } + +TAny* CVerifierImpl::GetExtension(TUid /*aExtensionId*/) + { + return 0; + } + +void CVerifierImpl::GetCharacteristicsL(const TAny*& aPluginCharacteristics) + { + TInt numCiphers = sizeof(KVerifierCharacteristics)/sizeof(TAsymmetricSignatureCharacteristics*); + TInt32 implUid = ImplementationUid().iUid; + for (TInt i = 0; i < numCiphers; ++i) + { + if (KVerifierCharacteristics[i]->cmn.iImplementationUID == implUid) + { + aPluginCharacteristics = KVerifierCharacteristics[i]; + break; + } + } + } + +void CVerifierImpl::DoSetKeyL(const CKey& aKey) + { + delete iKey; + iKey = CKey::NewL(aKey); + } + +void CVerifierImpl::ConstructL(const CKey& aPrivateKey) + { + SetKeyL(aPrivateKey); + } + +// Methods implemented in subclass. No coverage here. +#ifdef _BullseyeCoverage +#pragma suppress_warnings on +#pragma BullseyeCoverage off +#pragma suppress_warnings off +#endif +void CVerifierImpl::SetPaddingModeL(TUid /*aPaddingMode*/) + { + // Override in subclass + User::Leave(KErrNotSupported); + } + +void CVerifierImpl::SetKeyL(const CKey& /*aPublicKey*/) + { + // Override in subclass + User::Leave(KErrNotSupported); + } + +TInt CVerifierImpl::GetMaximumInputLengthL() const + { + // Override in subclass + User::Leave(KErrNotSupported); + return 0; + } + +TInt CVerifierImpl::GetMaximumOutputLengthL() const + { + // Override in subclass + User::Leave(KErrNotSupported); + return 0; + } diff -r 7e3f204e6c81 -r f9c11be8c0b3 cryptoplugins/cryptospiplugins/source/softwarecrypto/verifierimpl.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/cryptoplugins/cryptospiplugins/source/softwarecrypto/verifierimpl.h Tue Dec 01 11:12:04 2009 +0000 @@ -0,0 +1,95 @@ +/* +* Copyright (c) 2007-2009 Nokia Corporation and/or its subsidiary(-ies). +* All rights reserved. +* This component and the accompanying materials are made available +* under the terms of the License "Eclipse Public License v1.0" +* which accompanies this distribution, and is available +* at the URL "http://www.eclipse.org/legal/epl-v10.html". +* +* Initial Contributors: +* Nokia Corporation - initial contribution. +* +* Contributors: +* +* Description: +* +*/ + + +#ifndef __VERIFIERIMPL_H__ +#define __VERIFIERIMPL_H__ + +/** +@file +@internalComponent +@released +*/ + +#include +#include +#include +#include +#include "verifierplugin.h" + +#include "common/inlines.h" + +/** + * Abstract base class for verifier plug-ins. + */ +namespace SoftwareCrypto + { + using namespace CryptoSpi; + + NONSHARABLE_CLASS(CVerifierImpl) : public CBase, public MVerifier + { + public: + // Override MPlugin virtual functions + void Close(); + void Reset(); // Always call reset in super-class if you override this + TAny* GetExtension(TUid aExtensionId); + void GetCharacteristicsL(const TCharacteristics*& aPluginCharacteristics); + // End of MPlugin + + // Override MSignatureBase virtual functions + virtual void SetPaddingModeL(TUid aPaddingMode); + virtual void SetKeyL(const CKey& aPrivateKey); + virtual TInt GetMaximumInputLengthL() const; + virtual TInt GetMaximumOutputLengthL() const; + // End of MSignatureBase + + // Override MVerifier virtual functions + virtual void VerifyL(const TDesC8& aInput, const CCryptoParams& aSignature, TBool& aVerificationResult) = 0; + virtual void InverseSignL(HBufC8*& aOutput, const CCryptoParams& aSignature) = 0; + // End of MVerifier + + /// Destructor + ~CVerifierImpl(); + + protected: + /// Constructor + CVerifierImpl(); + + virtual void ConstructL(const CKey& aKey); + + /** + Helper function implemented by concrete cipher sub-class that allows + GetCharacteristicsL to return the correct characteristics object. + @return The implemention uid + */ + virtual TUid ImplementationUid() const = 0; + + /** + Store the key to use for verifying. + The key length is also checked to meet export restrictions and + to ensure that it is appropriate for the cipher. + @param aKey The key + */ + virtual void DoSetKeyL(const CKey& aKey); + + protected: + /// the key + CKey* iKey; + }; + } + +#endif // __VERIFIERIMPL_H__ diff -r 7e3f204e6c81 -r f9c11be8c0b3 cryptoplugins/cryptospiplugins/test/h4drv/crypto_h4/tcrypto.cpp --- a/cryptoplugins/cryptospiplugins/test/h4drv/crypto_h4/tcrypto.cpp Thu Nov 12 16:07:39 2009 +0000 +++ b/cryptoplugins/cryptospiplugins/test/h4drv/crypto_h4/tcrypto.cpp Tue Dec 01 11:12:04 2009 +0000 @@ -31,6 +31,8 @@ #include #include #include +#include + _LIT(KTxtEPOC32EX,"tcrypto: mainL failed"); _LIT(KTxtPressAnyKey," [press any key]"); diff -r 7e3f204e6c81 -r f9c11be8c0b3 cryptoservices/certificateandkeymgmt/crypto/Signed.cpp --- a/cryptoservices/certificateandkeymgmt/crypto/Signed.cpp Thu Nov 12 16:07:39 2009 +0000 +++ b/cryptoservices/certificateandkeymgmt/crypto/Signed.cpp Tue Dec 01 11:12:04 2009 +0000 @@ -453,6 +453,27 @@ digest = CSHA1::NewL(); break; } + case ESHA224: + { + digest = CSHA2::NewL(E224Bit); + break; + } + case ESHA256: + { + digest = CSHA2::NewL(E256Bit); + break; + } + case ESHA384: + { + digest = CSHA2::NewL(E384Bit); + break; + } + case ESHA512: + { + digest = CSHA2::NewL(E512Bit); + break; + } + default: User::Leave(KErrArgument); } @@ -508,62 +529,8 @@ aStream.WriteInt32L(iEncoding->Length()); aStream.WriteL(*iEncoding); } -/* -EXPORT_C void CSignedObject::ConstructL(RReadStream& aStream, TSignedObjectParser* aParser, TKeyFactory* aFactory) - { - if (iParser != NULL) - { - delete iParser; - iParser = NULL; - } - iParser = aParser; - if (iKeyFactory != NULL) - { - delete iKeyFactory; - iKeyFactory = NULL; - } - iKeyFactory = aFactory; - if (iEncoding != NULL) - { - User::Leave(KErrGeneral); - } - TInt len = aStream.ReadInt32L(); - iEncoding = HBufC8::NewL(aStream,len); - DoConstructL(); - } -EXPORT_C void CSignedObject::ConstructL(const TPtrC8& aBinaryData, TSignedObjectParser* aParser, TKeyFactory* aFactory) - { - iParser = aParser; - iKeyFactory = aFactory; - //take a copy of the whole thing - iEncoding = aBinaryData.AllocL(); - DoConstructL(); - } -EXPORT_C void CSignedObject::ConstructL(const CSignedObject& aSignedObject, TSignedObjectParser* aParser, TKeyFactory* aFactory) - { - iParser = aParser; - iKeyFactory = aFactory; - iEncoding = aSignedObject.iEncoding->AllocL(); - iFingerprint = aSignedObject.iFingerprint->AllocL(); - iSignature = aSignedObject.iSignature->AllocL(); - iSigningAlgorithm = CSigningAlgorithmIdentifier::NewL(*(aSignedObject.iSigningAlgorithm)); - } - -void CSignedObject::DoConstructL() - { - //generate your fingerprint - CMD5* hash = CMD5::NewL(); - CleanupStack::PushL(hash); - iFingerprint = hash->Hash(Encoding()).AllocL(); - CleanupStack::PopAndDestroy(); - //ask the parser for the signature - iSignature = iParser->SignatureL(Encoding()); - //ask the parser for the algorithm ID - iSigningAlgorithm = iParser->AlgorithmIdL(Encoding()); - } -*/ //****************************************************************************************// //certificate base EXPORT_C CCertificate::~CCertificate() diff -r 7e3f204e6c81 -r f9c11be8c0b3 cryptoservices/certificateandkeymgmt/group/bld.inf --- a/cryptoservices/certificateandkeymgmt/group/bld.inf Thu Nov 12 16:07:39 2009 +0000 +++ b/cryptoservices/certificateandkeymgmt/group/bld.inf Tue Dec 01 11:12:04 2009 +0000 @@ -567,6 +567,10 @@ ../tcertstore/scripts/t_certstore.ini /epoc32/winscw/c/t_certstore.ini ../tcertstore/scripts/t_certstore_2.ini /epoc32/winscw/c/t_certstore_2.ini +../tcertstore/scripts/t_certstore_sha2.script /epoc32/winscw/c/tcertstore/scripts/t_certstore_sha2.script +../tcertstore/scripts/t_certstore_sha2.ini /epoc32/winscw/c/tcertstore/scripts/t_certstore_sha2.ini +../tcertstore/scripts/t_certstore_sha2.txt /epoc32/winscw/c/tcertstore/scripts/t_certstore_sha2.txt + ../tcertstore/runtest/nightrun.txt /epoc32/winscw/c/tcertstore/runtest/nightrun.txt diff -r 7e3f204e6c81 -r f9c11be8c0b3 cryptoservices/certificateandkeymgmt/inc/certmantests.iby --- a/cryptoservices/certificateandkeymgmt/inc/certmantests.iby Thu Nov 12 16:07:39 2009 +0000 +++ b/cryptoservices/certificateandkeymgmt/inc/certmantests.iby Tue Dec 01 11:12:04 2009 +0000 @@ -442,6 +442,9 @@ data = ABI_DIR\BUILD_DIR\t_certstore.exe sys\bin\t_certstore.exe //scripts +data = ZDRIVE\tcertstore\scripts\t_certstore_sha2.txt tcertstore\scripts\t_certstore_sha2.txt attrib=r +data = ZDRIVE\tcertstore\scripts\t_certstore_sha2.script tcertstore\scripts\t_certstore_sha2.script attrib=r +data = ZDRIVE\tcertstore\scripts\t_certstore_sha2.ini tcertstore\scripts\t_certstore_sha2.ini attrib=r data = ZDRIVE\tcertstoreconcurrent\scripts\certstoreconcurrent1.txt tcertstoreconcurrent\scripts\certstoreconcurrent1.txt attrib=r data = ZDRIVE\tcertstoreconcurrent\scripts\certstoreconcurrent2.txt tcertstoreconcurrent\scripts\certstoreconcurrent2.txt attrib=r data = ZDRIVE\tcertstoreconcurrent\scripts\certstoreconcurrent3.txt tcertstoreconcurrent\scripts\certstoreconcurrent3.txt attrib=r @@ -483,6 +486,10 @@ // Data +data = ZDRIVE\tcertstore\serv-rootCA-sha384.der \tcertstore\serv-rootCA-sha384.der attrib=r +data = ZDRIVE\tcertstore\serv-rootCA-sha256.der \tcertstore\serv-rootCA-sha256.der attrib=r +data = ZDRIVE\tcertstore\serv-rootCA-sha224.der \tcertstore\serv-rootCA-sha224.der attrib=r +data = ZDRIVE\tcertstore\serv-rootCA-sha512.der \tcertstore\serv-rootCA-sha512.der attrib=r data = ZDRIVE\tcertstore\thawteserverca.cer \tcertstore\thawteserverca.cer attrib=r data = ZDRIVE\tcertstore\Dsa-ca.cer \tcertstore\Dsa-ca.cer attrib=r data = ZDRIVE\tcertstore\ent-wtls.cer \tcertstore\ent-wtls.cer attrib=r diff -r 7e3f204e6c81 -r f9c11be8c0b3 cryptoservices/certificateandkeymgmt/inc/signed.h --- a/cryptoservices/certificateandkeymgmt/inc/signed.h Thu Nov 12 16:07:39 2009 +0000 +++ b/cryptoservices/certificateandkeymgmt/inc/signed.h Tue Dec 01 11:12:04 2009 +0000 @@ -51,7 +51,15 @@ /** A MD5 algorithm. */ EMD5, /** A SHA-1 algorithm. */ - ESHA1 + ESHA1, + /** A SHA-224 algorithm. */ + ESHA224, + /** A SHA-256 algorithm. */ + ESHA256, + /** A SHA-384 algorithm. */ + ESHA384, + /** A SHA-512 algorithm. */ + ESHA512 }; class CValidityPeriod : public CBase diff -r 7e3f204e6c81 -r f9c11be8c0b3 cryptoservices/certificateandkeymgmt/inc/x509cert.h --- a/cryptoservices/certificateandkeymgmt/inc/x509cert.h Thu Nov 12 16:07:39 2009 +0000 +++ b/cryptoservices/certificateandkeymgmt/inc/x509cert.h Tue Dec 01 11:12:04 2009 +0000 @@ -33,18 +33,31 @@ #include #include +_LIT(KRSA,"1.2.840.113549.1.1.1"); _LIT(KMD2WithRSA,"1.2.840.113549.1.1.2"); _LIT(KMD5WithRSA,"1.2.840.113549.1.1.4"); _LIT(KSHA1WithRSA,"1.2.840.113549.1.1.5"); -_LIT(KDSAWithSHA1,"1.2.840.10040.4.3"); + +_LIT(KSHA256WithRSA,"1.2.840.113549.1.1.11"); +_LIT(KSHA384WithRSA,"1.2.840.113549.1.1.12"); +_LIT(KSHA512WithRSA,"1.2.840.113549.1.1.13"); +_LIT(KSHA224WithRSA,"1.2.840.113549.1.1.14"); -_LIT(KRSA,"1.2.840.113549.1.1.1"); +_LIT(KDSA,"1.2.840.10040.4.1"); +_LIT(KDSAWithSHA1, "1.2.840.10040.4.3"); + _LIT(KDH,"1.2.840.10046.2.1"); -_LIT(KDSA,"1.2.840.10040.4.1"); + _LIT(KMD5,"1.2.840.113549.2.5"); _LIT(KMD2,"1.2.840.113549.2.2"); _LIT(KSHA1,"1.3.14.3.2.26"); +_LIT(KSHA256,"2.16.840.1.101.3.4.2.1"); +_LIT(KSHA384,"2.16.840.1.101.3.4.2.2"); +_LIT(KSHA512,"2.16.840.1.101.3.4.2.3"); +_LIT(KSHA224,"2.16.840.1.101.3.4.2.4"); + + /** The maximum number of allowed data elements. * * @since v7.0 */ diff -r 7e3f204e6c81 -r f9c11be8c0b3 cryptoservices/certificateandkeymgmt/tcertstore/scripts/t_certstore_sha2.ini --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/cryptoservices/certificateandkeymgmt/tcertstore/scripts/t_certstore_sha2.ini Tue Dec 01 11:12:04 2009 +0000 @@ -0,0 +1,148 @@ +[SEC-CERTMAN-TCERTSTORESHA2-0001-001] + + write + + +[SEC-CERTMAN-TCERTSTORESHA2-0001-002] + + X509 + + + + 0 + c:\tcertstore\serv-rootca-sha224.der + ca + + +[SEC-CERTMAN-TCERTSTORESHA2-0001-003] + + X509 + + + + 0 + c:\tcertstore\serv-rootca-sha256.der + ca + + +[SEC-CERTMAN-TCERTSTORESHA2-0001-004] + + X509 + + + + 0 + c:\tcertstore\serv-rootca-sha384.der + ca + + +[SEC-CERTMAN-TCERTSTORESHA2-0001-005] + + X509 + + + + 0 + c:\tcertstore\serv-rootca-sha512.der + ca + + +[SEC-CERTMAN-TCERTSTORESHA2-0001-006] + + + 1 + + +[SEC-CERTMAN-TCERTSTORESHA2-0001-007] + + + 1 + + +[SEC-CERTMAN-TCERTSTORESHA2-0001-008] + + + 1 + + +[SEC-CERTMAN-TCERTSTORESHA2-0001-009] + + + 1 + + + +[SEC-CERTMAN-TCERTSTORESHA2-0001-010] + + + + +[SEC-CERTMAN-TCERTSTORESHA2-0001-011] + + Server Authentication + 268441661 + + + +[SEC-CERTMAN-TCERTSTORESHA2-0001-012] + + + 268441661 + + + +[SEC-CERTMAN-TCERTSTORESHA2-0001-013] + + + 268441661 + + + +[SEC-CERTMAN-TCERTSTORESHA2-0001-014] + + + 268441661 + + + +[SEC-CERTMAN-TCERTSTORESHA2-0001-015] + + + 268441661 + + + + +[SEC-CERTMAN-TCERTSTORESHA2-0001-016] + + + +[SEC-CERTMAN-TCERTSTORESHA2-0001-017] + + ca + + + + +[SEC-CERTMAN-TCERTSTORESHA2-0001-018] + + ca + + + + + +[SEC-CERTMAN-TCERTSTORESHA2-0001-019] + + ca + + + + +[SEC-CERTMAN-TCERTSTORESHA2-0001-020] + + ca + + + + diff -r 7e3f204e6c81 -r f9c11be8c0b3 cryptoservices/certificateandkeymgmt/tcertstore/scripts/t_certstore_sha2.script --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/cryptoservices/certificateandkeymgmt/tcertstore/scripts/t_certstore_sha2.script Tue Dec 01 11:12:04 2009 +0000 @@ -0,0 +1,106 @@ +// +// Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies). +// All rights reserved. +// This component and the accompanying materials are made available +// under the terms of the License "Symbian Foundation License v1.0" +// which accompanies this distribution, and is available +// at the URL "http://www.symbianfoundation.org/legal/sfl-v10.html". +// +// Initial Contributors: +// Nokia Corporation - initial contribution. +// +// Contributors: +// +// Description: +// + +START_TESTCASE SEC-CERTMAN-TCERTSTORESHA2-0001 + +//! @SYMTestCaseID SEC-CERTMAN-TCERTSTORESHA2-0001 + +//! @SYMTestCaseDesc + +//! @SYMTestActions 1) Initializing a CUnifiedCertStore + +//! 2) Add the certificate -SHA224 + +//! 3) Add the certificate -SHA256 + +//! 4) Add the certificate -SHA384 + +//! 5) Add the certificate -SHA512 + +//! 6) Set the trust for Rootca-SHA224 + +//! 7) Set the trust for Rootca-SHA256 + +//! 8) Set the trust for Rootca-SHA384 + +//! 9) Set the trust for Rootca-SHA512 + +//! 10) Creating a CertificateAppInfoManager + +//! 11) Adding client TLS + +//! 12) Set trusters to the Rootca-SHA224 certificate + +//! 13) Set trusters to the Rootca-SHA256 certificate + +//! 14) Set trusters to the Rootca-SHA384 certificate + +//! 15) Set trusters to the Rootca-SHA512 certificate + +//! 16) Deleting the CertificateAppInfoManager + +//! 17) Deleting the certificates + +//! 18) Deleting the certificates + +//! 19) Deleting the certificates + +//! 20) Deleting the certificates + +RUN_TEST_STEP -1 CTestHandler init t_certstore_sha2.ini SEC-CERTMAN-TCERTSTORESHA2-0001-001 + +RUN_TEST_STEP -1 CTestHandler addcert t_certstore_sha2.ini SEC-CERTMAN-TCERTSTORESHA2-0001-002 + +RUN_TEST_STEP -1 CTestHandler addcert t_certstore_sha2.ini SEC-CERTMAN-TCERTSTORESHA2-0001-003 + +RUN_TEST_STEP -1 CTestHandler addcert t_certstore_sha2.ini SEC-CERTMAN-TCERTSTORESHA2-0001-004 + +RUN_TEST_STEP -1 CTestHandler addcert t_certstore_sha2.ini SEC-CERTMAN-TCERTSTORESHA2-0001-005 + +RUN_TEST_STEP -1 CTestHandler settrust t_certstore_sha2.ini SEC-CERTMAN-TCERTSTORESHA2-0001-006 + +RUN_TEST_STEP -1 CTestHandler settrust t_certstore_sha2.ini SEC-CERTMAN-TCERTSTORESHA2-0001-007 + +RUN_TEST_STEP -1 CTestHandler settrust t_certstore_sha2.ini SEC-CERTMAN-TCERTSTORESHA2-0001-008 + +RUN_TEST_STEP -1 CTestHandler settrust t_certstore_sha2.ini SEC-CERTMAN-TCERTSTORESHA2-0001-009 + +RUN_TEST_STEP -1 CTestHandler initappmanager t_certstore_sha2.ini SEC-CERTMAN-TCERTSTORESHA2-0001-010 + +RUN_TEST_STEP -1 CTestHandler addclient t_certstore_sha2.ini SEC-CERTMAN-TCERTSTORESHA2-0001-011 + +RUN_TEST_STEP -1 CTestHandler setapplications t_certstore_sha2.ini SEC-CERTMAN-TCERTSTORESHA2-0001-012 + +RUN_TEST_STEP -1 CTestHandler setapplications t_certstore_sha2.ini SEC-CERTMAN-TCERTSTORESHA2-0001-013 + +RUN_TEST_STEP -1 CTestHandler setapplications t_certstore_sha2.ini SEC-CERTMAN-TCERTSTORESHA2-0001-014 + +RUN_TEST_STEP -1 CTestHandler setapplications t_certstore_sha2.ini SEC-CERTMAN-TCERTSTORESHA2-0001-015 + +RUN_TEST_STEP -1 CTestHandler deleteappmanager t_certstore_sha2.ini SEC-CERTMAN-TCERTSTORESHA2-0001-016 + +RUN_TEST_STEP -1 CTestHandler deletecert t_certstore_sha2.ini SEC-CERTMAN-TCERTSTORESHA2-0001-017 + +RUN_TEST_STEP -1 CTestHandler deletecert t_certstore_sha2.ini SEC-CERTMAN-TCERTSTORESHA2-0001-018 + +RUN_TEST_STEP -1 CTestHandler deletecert t_certstore_sha2.ini SEC-CERTMAN-TCERTSTORESHA2-0001-019 + +RUN_TEST_STEP -1 CTestHandler deletecert t_certstore_sha2.ini SEC-CERTMAN-TCERTSTORESHA2-0001-020 + + +END_TESTCASE SEC-CERTMAN-TCERTSTORESHA2-0001 + + diff -r 7e3f204e6c81 -r f9c11be8c0b3 cryptoservices/certificateandkeymgmt/tcertstore/scripts/t_certstore_sha2.txt --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/cryptoservices/certificateandkeymgmt/tcertstore/scripts/t_certstore_sha2.txt Tue Dec 01 11:12:04 2009 +0000 @@ -0,0 +1,255 @@ + + Initializing a CUnifiedCertStore + init + + write + + + KErrNone + + + + + + Add the certificate -SHA224 + addcert + + X509 + + + + 0 + c:\tcertstore\serv-rootca-sha224.der + ca + + + KErrNone + + + + + Add the certificate -SHA256 + addcert + + X509 + + + + 0 + c:\tcertstore\serv-rootca-sha256.der + ca + + + KErrNone + + + + + Add the certificate -SHA384 + addcert + + X509 + + + + 0 + c:\tcertstore\serv-rootca-sha384.der + ca + + + KErrNone + + + + + Add the certificate -SHA512 + addcert + + X509 + + + + 0 + c:\tcertstore\serv-rootca-sha512.der + ca + + + KErrNone + + + + + + Set the trust for Rootca-SHA224 + settrust + + + 1 + + + KErrNone + + + + + Set the trust for Rootca-SHA256 + settrust + + + 1 + + + KErrNone + + + + + Set the trust for Rootca-SHA384 + settrust + + + 1 + + + KErrNone + + + + + Set the trust for Rootca-SHA512 + settrust + + + 1 + + + KErrNone + + + + + Creating a CertificateAppInfoManager + initappmanager + + + KErrNone + + + + + + Adding client TLS + addclient + + Server Authentication + 268441661 + + + KErrNone + + + + + Set trusters to the Rootca-SHA224 certificate + setapplications + + + 268441661 + + + KErrNone + + + + + Set trusters to the Rootca-SHA256 certificate + setapplications + + + 268441661 + + + KErrNone + + + + + Set trusters to the Rootca-SHA384 certificate + setapplications + + + 268441661 + + + KErrNone + + + + + Set trusters to the Rootca-SHA512 certificate + setapplications + + + 268441661 + + + KErrNone + + + + + Deleting the CertificateAppInfoManager + deleteappmanager + + + KErrNone + + + + + Deleting the certificates + deletecert + + ca + + + + KErrNone + + + + + Deleting the certificates + deletecert + + ca + + + + KErrNone + + + + + Deleting the certificates + deletecert + + ca + + + + KErrNone + + + + + Deleting the certificates + deletecert + + ca + + + + KErrNone + + diff -r 7e3f204e6c81 -r f9c11be8c0b3 cryptoservices/certificateandkeymgmt/x509/x509cert.cpp --- a/cryptoservices/certificateandkeymgmt/x509/x509cert.cpp Thu Nov 12 16:07:39 2009 +0000 +++ b/cryptoservices/certificateandkeymgmt/x509/x509cert.cpp Tue Dec 01 11:12:04 2009 +0000 @@ -304,6 +304,48 @@ CleanupStack::PopAndDestroy(2);//seq, oid return; } + + if (oidDes == KSHA224) + { + iAlgorithmId = ESHA224; + TASN1DecNull null; + null.DecodeDERL(*gen);//just to check the syntax is OK + iEncodedParams = HBufC8::NewL(1); + *iEncodedParams = KNullDesC8; + CleanupStack::PopAndDestroy(2);//seq, oid + return; + } + if (oidDes == KSHA256) + { + iAlgorithmId = ESHA256; + TASN1DecNull null; + null.DecodeDERL(*gen);//just to check the syntax is OK + iEncodedParams = HBufC8::NewL(1); + *iEncodedParams = KNullDesC8; + CleanupStack::PopAndDestroy(2);//seq, oid + return; + } + if (oidDes == KSHA384) + { + iAlgorithmId = ESHA384; + TASN1DecNull null; + null.DecodeDERL(*gen);//just to check the syntax is OK + iEncodedParams = HBufC8::NewL(1); + *iEncodedParams = KNullDesC8; + CleanupStack::PopAndDestroy(2);//seq, oid + return; + } + if (oidDes == KSHA512) + { + iAlgorithmId = ESHA512; + TASN1DecNull null; + null.DecodeDERL(*gen);//just to check the syntax is OK + iEncodedParams = HBufC8::NewL(1); + *iEncodedParams = KNullDesC8; + CleanupStack::PopAndDestroy(2);//seq, oid + return; + } + } User::Leave(KErrNotSupported); } @@ -340,6 +382,22 @@ case ESHA1: oid=CASN1EncObjectIdentifier::NewLC(KSHA1); break; + + case ESHA224: + oid=CASN1EncObjectIdentifier::NewLC(KSHA224); + break; + + case ESHA256: + oid=CASN1EncObjectIdentifier::NewLC(KSHA256); + break; + + case ESHA384: + oid=CASN1EncObjectIdentifier::NewLC(KSHA384); + break; + + case ESHA512: + oid=CASN1EncObjectIdentifier::NewLC(KSHA512); + break; default: User::Leave(KErrNotSupported); @@ -463,6 +521,39 @@ iDigestAlgorithm = CAlgorithmIdentifier::NewL(digestId, encodedParams->Des()); iAsymmetricAlgorithm = CAlgorithmIdentifier::NewL(algId, encodedParams->Des()); } + + if (oidDes == KSHA224WithRSA) + { + TAlgorithmId algId = ERSA; + TAlgorithmId digestId = ESHA224; + iDigestAlgorithm = CAlgorithmIdentifier::NewL(digestId, encodedParams->Des()); + iAsymmetricAlgorithm = CAlgorithmIdentifier::NewL(algId, encodedParams->Des()); + } + + if (oidDes == KSHA256WithRSA) + { + TAlgorithmId algId = ERSA; + TAlgorithmId digestId = ESHA256; + iDigestAlgorithm = CAlgorithmIdentifier::NewL(digestId, encodedParams->Des()); + iAsymmetricAlgorithm = CAlgorithmIdentifier::NewL(algId, encodedParams->Des()); + } + + if (oidDes == KSHA384WithRSA) + { + TAlgorithmId algId = ERSA; + TAlgorithmId digestId = ESHA384; + iDigestAlgorithm = CAlgorithmIdentifier::NewL(digestId, encodedParams->Des()); + iAsymmetricAlgorithm = CAlgorithmIdentifier::NewL(algId, encodedParams->Des()); + } + + if (oidDes == KSHA512WithRSA) + { + TAlgorithmId algId = ERSA; + TAlgorithmId digestId = ESHA512; + iDigestAlgorithm = CAlgorithmIdentifier::NewL(digestId, encodedParams->Des()); + iAsymmetricAlgorithm = CAlgorithmIdentifier::NewL(algId, encodedParams->Des()); + } + //???not sure if we should just leave here... if (iDigestAlgorithm == NULL) { diff -r 7e3f204e6c81 -r f9c11be8c0b3 cryptoservices/filebasedcertificateandkeystores/test/tcryptotokenhai/tcryptotokenhai.cpp --- a/cryptoservices/filebasedcertificateandkeystores/test/tcryptotokenhai/tcryptotokenhai.cpp Thu Nov 12 16:07:39 2009 +0000 +++ b/cryptoservices/filebasedcertificateandkeystores/test/tcryptotokenhai/tcryptotokenhai.cpp Tue Dec 01 11:12:04 2009 +0000 @@ -595,13 +595,10 @@ return EFalse; } break; - case TCTKeyAttributeFilter::EManageableKeys: - if (!aInfo.ManagementPolicy().CheckPolicy(RThread())) - { - return EFalse; - } - break; + // As this key store implementation is a hardware simulation, + // the support for managing through software interface has been diabled. + return EFalse; case TCTKeyAttributeFilter::EUsableOrManageableKeys: if (!aInfo.UsePolicy().CheckPolicy(RThread()) && diff -r 7e3f204e6c81 -r f9c11be8c0b3 cryptoservices/filebasedcertificateandkeystores/test/thwkeystore/common/tkeydetails.cpp --- a/cryptoservices/filebasedcertificateandkeystores/test/thwkeystore/common/tkeydetails.cpp Thu Nov 12 16:07:39 2009 +0000 +++ b/cryptoservices/filebasedcertificateandkeystores/test/thwkeystore/common/tkeydetails.cpp Tue Dec 01 11:12:04 2009 +0000 @@ -80,7 +80,11 @@ // set the access type to never extractable iAccessType |= CKeyInfoBase::ENeverExtractable; iAccessType |= CKeyInfoBase::ELocal; - + // Policy set for keys in hardware depends on the vendor requirements + // this reference implementation assumes that accessibility of keys + // does not need any restriction. Hence for the testing environment policy is set to always pass. + TSecurityPolicy temp(TSecurityPolicy::EAlwaysPass); + iUsePolicy = temp; } void CKeyDetails::ExternalizeL(RWriteStream& aWriteStream) const @@ -98,7 +102,7 @@ TPtr8 keyPtr = iPrivateKey->Des(); keyPtr.SetLength(stringLen); aWriteStream.WriteL(keyPtr); - + stringLen = iPublicKey->Length(); aWriteStream.WriteInt32L(stringLen); keyPtr = iPublicKey->Des(); @@ -127,4 +131,9 @@ TPtr8 publicKeyPtr((TUint8*)iPublicKey->Ptr(), stringLen, stringLen); publicKeyPtr.FillZ(stringLen); aReadStream.ReadL(publicKeyPtr); + // Policy set for keys in hardware depends on the vendor requirements + // this reference implementation assumes that accessibility of keys + // does not need any restriction. Hence for the testing environment policy is set to always pass. + TSecurityPolicy temp(TSecurityPolicy::EAlwaysPass); + iUsePolicy = temp; } diff -r 7e3f204e6c81 -r f9c11be8c0b3 cryptoservices/filebasedcertificateandkeystores/test/tkeystore/t_open.cpp --- a/cryptoservices/filebasedcertificateandkeystores/test/tkeystore/t_open.cpp Thu Nov 12 16:07:39 2009 +0000 +++ b/cryptoservices/filebasedcertificateandkeystores/test/tkeystore/t_open.cpp Tue Dec 01 11:12:04 2009 +0000 @@ -308,11 +308,10 @@ void COpenKey::ConstructL(const TTestActionSpec& aTestActionSpec) { - TInt pos = 0, err = 0; CKeyStoreTestAction::ConstructL(aTestActionSpec); #if (defined(SYMBIAN_ENABLE_SDP_WMDRM_SUPPORT) && defined(SYMBIAN_ENABLE_SDP_ECC)) - pos = 0; + TInt pos = 0, err = 0; TPtrC8 operationType = Input::ParseElement(aTestActionSpec.iActionBody, KOperationTypeStart, KOperationTypeEnd, pos, err); if(operationType.Compare(_L8("sign")) == 0) { diff -r 7e3f204e6c81 -r f9c11be8c0b3 cryptoservices/rootcertificates/data/SymbianA.der Binary file cryptoservices/rootcertificates/data/SymbianA.der has changed diff -r 7e3f204e6c81 -r f9c11be8c0b3 cryptoservices/rootcertificates/data/SymbianB.der Binary file cryptoservices/rootcertificates/data/SymbianB.der has changed diff -r 7e3f204e6c81 -r f9c11be8c0b3 cryptoservices/rootcertificates/data/SymbianSignedCerts.txt --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/cryptoservices/rootcertificates/data/SymbianSignedCerts.txt Tue Dec 01 11:12:04 2009 +0000 @@ -0,0 +1,103 @@ +# SymbianSignedCerts.txt +# +# Populates the SWI cert store with the Symbian Signed certificates + +[SymbianA] +file = c:\rootcerts\SymbianA.der +capability = TCB +capability = CommDD +capability = PowerMgmt +capability = MultimediaDD +capability = ReadDeviceData +capability = WriteDeviceData +capability = DRM +capability = TrustedUI +capability = ProtServ +capability = DiskAdmin +capability = NetworkControl +capability = AllFiles +capability = SwEvent +capability = NetworkServices +capability = LocalServices +capability = ReadUserData +capability = WriteUserData +capability = Location +capability = SurroundingsDD +capability = UserEnvironment +application = SWInstall +application = SWInstallOCSP + +[SymbianB] +file = c:\rootcerts\SymbianB.der +capability = TCB +capability = CommDD +capability = PowerMgmt +capability = MultimediaDD +capability = ReadDeviceData +capability = WriteDeviceData +capability = DRM +capability = TrustedUI +capability = ProtServ +capability = DiskAdmin +capability = NetworkControl +capability = AllFiles +capability = SwEvent +capability = NetworkServices +capability = LocalServices +capability = ReadUserData +capability = WriteUserData +capability = Location +capability = SurroundingsDD +capability = UserEnvironment +application = SWInstall +application = SWInstallOCSP + +[SymbianC] +file = c:\rootcerts\SymbianC.der +capability = TCB +capability = CommDD +capability = PowerMgmt +capability = MultimediaDD +capability = ReadDeviceData +capability = WriteDeviceData +capability = DRM +capability = TrustedUI +capability = ProtServ +capability = DiskAdmin +capability = NetworkControl +capability = AllFiles +capability = SwEvent +capability = NetworkServices +capability = LocalServices +capability = ReadUserData +capability = WriteUserData +capability = Location +capability = SurroundingsDD +capability = UserEnvironment +application = SWInstall +application = SWInstallOCSP + +[SymbianD] +file = c:\rootcerts\SymbianD.der +capability = TCB +capability = CommDD +capability = PowerMgmt +capability = MultimediaDD +capability = ReadDeviceData +capability = WriteDeviceData +capability = DRM +capability = TrustedUI +capability = ProtServ +capability = DiskAdmin +capability = NetworkControl +capability = AllFiles +capability = SwEvent +capability = NetworkServices +capability = LocalServices +capability = ReadUserData +capability = WriteUserData +capability = Location +capability = SurroundingsDD +capability = UserEnvironment +application = SWInstall +application = SWInstallOCSP diff -r 7e3f204e6c81 -r f9c11be8c0b3 cryptoservices/rootcertificates/data/swicertstore.dat Binary file cryptoservices/rootcertificates/data/swicertstore.dat has changed diff -r 7e3f204e6c81 -r f9c11be8c0b3 cryptoservices/rootcertificates/data/symbianc.der Binary file cryptoservices/rootcertificates/data/symbianc.der has changed diff -r 7e3f204e6c81 -r f9c11be8c0b3 cryptoservices/rootcertificates/data/symbiand.der Binary file cryptoservices/rootcertificates/data/symbiand.der has changed diff -r 7e3f204e6c81 -r f9c11be8c0b3 cryptoservices/rootcertificates/group/bld.inf --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/cryptoservices/rootcertificates/group/bld.inf Tue Dec 01 11:12:04 2009 +0000 @@ -0,0 +1,32 @@ +/* +* Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies). +* All rights reserved. +* This component and the accompanying materials are made available +* under the terms of the License "Eclipse Public License v1.0" +* which accompanies this distribution, and is available +* at the URL "http://www.eclipse.org/legal/epl-v10.html". +* +* Initial Contributors: +* Nokia Corporation - initial contribution. +* +* Contributors: +* +* Description: +* Exports SWI certificate store +* +*/ + +/** + @file +*/ + +PRJ_PLATFORMS +DEFAULT + +PRJ_EXPORTS +../data/swicertstore.dat /epoc32/release/winscw/udeb/Z/resource/swicertstore.dat +../data/swicertstore.dat /epoc32/release/winscw/urel/Z/resource/swicertstore.dat +../data/swicertstore.dat /epoc32/data/z/resource/swicertstore.dat + +// ROMKIT includes +rootcerts.iby /epoc32/rom/include/rootcerts.iby diff -r 7e3f204e6c81 -r f9c11be8c0b3 cryptoservices/rootcertificates/group/rootcerts.iby --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/cryptoservices/rootcertificates/group/rootcerts.iby Tue Dec 01 11:12:04 2009 +0000 @@ -0,0 +1,27 @@ +/* +* Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies). +* All rights reserved. +* This component and the accompanying materials are made available +* under the terms of the License "Eclipse Public License v1.0" +* which accompanies this distribution, and is available +* at the URL "http://www.eclipse.org/legal/epl-v10.html". +* +* Initial Contributors: +* Nokia Corporation - initial contribution. +* +* Contributors: +* +* Description: +* +*/ + +/** + @file +*/ + +#ifndef __ROOTCERTS_IBY__ +#define __ROOTCERTS_IBY__ + +data=ZRESOURCE\swicertstore.dat resource\swicertstore.dat + +#endif // __ROOTCERTS_IBY__ diff -r 7e3f204e6c81 -r f9c11be8c0b3 cryptoservices/rootcertificates/group/rootcerts.mrp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/cryptoservices/rootcertificates/group/rootcerts.mrp Tue Dec 01 11:12:04 2009 +0000 @@ -0,0 +1,8 @@ +component rootcerts +source \sf\os\security\cryptoservices\rootcertificates +exports \sf\os\security\cryptoservices\rootcertificates\group +notes_source \component_defs\release.src + + +ipr E + diff -r 7e3f204e6c81 -r f9c11be8c0b3 cryptoservices/rootcertificates/swicertstore.dat Binary file cryptoservices/rootcertificates/swicertstore.dat has changed diff -r 7e3f204e6c81 -r f9c11be8c0b3 package_definition.xml --- a/package_definition.xml Thu Nov 12 16:07:39 2009 +0000 +++ b/package_definition.xml Tue Dec 01 11:12:04 2009 +0000 @@ -68,6 +68,9 @@ + + +