os/security/crypto/weakcryptospi/source/cryptoswitch/cryptoswitch.cpp
changeset 0 bde4ae8d615e
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/os/security/crypto/weakcryptospi/source/cryptoswitch/cryptoswitch.cpp	Fri Jun 15 03:10:57 2012 +0200
     1.3 @@ -0,0 +1,83 @@
     1.4 +/*
     1.5 +* Copyright (c) 2004-2009 Nokia Corporation and/or its subsidiary(-ies).
     1.6 +* All rights reserved.
     1.7 +* This component and the accompanying materials are made available
     1.8 +* under the terms of the License "Eclipse Public License v1.0"
     1.9 +* which accompanies this distribution, and is available
    1.10 +* at the URL "http://www.eclipse.org/legal/epl-v10.html".
    1.11 +*
    1.12 +* Initial Contributors:
    1.13 +* Nokia Corporation - initial contribution.
    1.14 +*
    1.15 +* Contributors:
    1.16 +*
    1.17 +* Description: 
    1.18 +*
    1.19 +*/
    1.20 +
    1.21 +
    1.22 +#include <emulator.h>
    1.23 +
    1.24 +
    1.25 +extern "C" {
    1.26 +
    1.27 +#include "cryptography_stubs.h"
    1.28 +
    1.29 +FARPROC vector[MAX_ORDINAL+1];
    1.30 +
    1.31 +void fill_vector(HINSTANCE aDll)
    1.32 +	{
    1.33 +	int i;
    1.34 +	for (i=1;i<=MAX_ORDINAL;i++)
    1.35 +		{
    1.36 +		vector[i] = GetProcAddress(aDll, (LPCSTR)i);
    1.37 +		}
    1.38 +	vector[0] = (FARPROC)1;		// initialised
    1.39 +	}
    1.40 +
    1.41 +void init_vector()
    1.42 +	{
    1.43 +	__LOCK_HOST;		// prevent deadlock with EKA2 scheduler
    1.44 +
    1.45 +	HINSTANCE instance;
    1.46 +	
    1.47 +	// Try for strong cryptography
    1.48 +	//
    1.49 +	instance = LoadLibraryA("strong_cryptography.dll"); 
    1.50 +	if (instance != NULL)
    1.51 +		{
    1.52 +		fill_vector(instance);
    1.53 +		return;
    1.54 +		}
    1.55 +		
    1.56 +	// Try for weak cryptography
    1.57 +	//
    1.58 +	instance = LoadLibraryA("weak_cryptography.dll"); 
    1.59 +	if (instance != NULL)
    1.60 +		{
    1.61 +		fill_vector(instance);
    1.62 +		return;
    1.63 +		}
    1.64 +	
    1.65 +	// die
    1.66 +	//
    1.67 +	OutputDebugStringA("Unable to load cryptography implementation");
    1.68 +	_asm int 3;
    1.69 +	}
    1.70 +	
    1.71 +__declspec(naked) void common_dispatch()
    1.72 +	{
    1.73 +	_asm cmp	dword ptr vector,0		// initialised?
    1.74 +	_asm jne  	call_though_vector
    1.75 +	_asm push	eax
    1.76 +	_asm push	ecx
    1.77 +	_asm push	edx
    1.78 +	_asm call	init_vector
    1.79 +	_asm pop	edx
    1.80 +	_asm pop 	ecx
    1.81 +	_asm pop 	eax
    1.82 +call_though_vector:
    1.83 +	_asm jmp	[vector+eax*4]
    1.84 +	}
    1.85 +
    1.86 +}