diff -Naur -X symlinks openssl-0.9.8o.orig/apps/dgst.c openssl-0.9.8o/apps/dgst.c
--- openssl-0.9.8o.orig/apps/dgst.c	2010-09-07 16:38:51.627699944 -0400
+++ openssl-0.9.8o/apps/dgst.c	2010-09-22 15:26:59.423376446 -0400
@@ -205,6 +205,7 @@
 			{
 			if (--argc < 1) break;
 			engine= *(++argv);
+			e = setup_engine(bio_err, engine, 0);
 			}
 #endif
 		else if (strcmp(*argv,"-hex") == 0)
@@ -231,15 +232,15 @@
 		argv++;
 		}
 
-	if (md == NULL)
-		md=EVP_md5();
-
 	if(do_verify && !sigfile) {
 		BIO_printf(bio_err, "No signature to verify: use the -signature option\n");
 		err = 1; 
 		goto end;
 	}
 
+	if (md == NULL)
+		md=EVP_md5();
+
 	if ((argc > 0) && (argv[0][0] == '-')) /* bad option */
 		{
 		BIO_printf(bio_err,"unknown option '%s'\n",*argv);
@@ -291,9 +292,6 @@
 		goto end;
 		}
 
-#ifndef OPENSSL_NO_ENGINE
-        e = setup_engine(bio_err, engine, 0);
-#endif
 
 	in=BIO_new(BIO_s_file());
 	bmd=BIO_new(BIO_f_md());
@@ -397,9 +395,9 @@
 		}
 
 	/* we use md as a filter, reading from 'in' */
-	if (!BIO_set_md(bmd,md))
+	if (!(err = BIO_set_md(bmd,md)))
 		{
-		BIO_printf(bio_err, "Error setting digest %s\n", pname);
+		BIO_printf(bio_err, "Error setting digest %s (%d)\n", pname, err);
 		ERR_print_errors(bio_err);
 		goto end;
 		}
diff -Naur -X symlinks openssl-0.9.8o.orig/apps/enc.c openssl-0.9.8o/apps/enc.c
--- openssl-0.9.8o.orig/apps/enc.c	2010-09-07 16:38:51.637700020 -0400
+++ openssl-0.9.8o/apps/enc.c	2010-09-22 15:26:59.423376446 -0400
@@ -524,6 +524,7 @@
 			EVP_BytesToKey(cipher,dgst,sptr,
 				(unsigned char *)str,
 				strlen(str),1,key,iv);
+
 			/* zero the complete buffer or the string
 			 * passed from the command line
 			 * bug picked up by
@@ -577,6 +578,11 @@
 		if (nopad)
 			EVP_CIPHER_CTX_set_padding(ctx, 0);
 
+		/* This is required for variable length ciphers to work */
+		if(ctx->cipher->flags & EVP_CIPH_VARIABLE_LENGTH) {
+			EVP_CIPHER_CTX_set_key_length(ctx, 16);
+		}
+
 		if (!EVP_CipherInit_ex(ctx, NULL, NULL, key, iv, enc))
 			{
 			BIO_printf(bio_err, "Error setting cipher %s\n",
diff -Naur -X symlinks openssl-0.9.8o.orig/apps/openssl.c openssl-0.9.8o/apps/openssl.c
--- openssl-0.9.8o.orig/apps/openssl.c	2010-09-07 16:38:51.617699664 -0400
+++ openssl-0.9.8o/apps/openssl.c	2010-09-22 15:26:59.423376446 -0400
@@ -113,6 +113,8 @@
 #include <stdio.h>
 #include <string.h>
 #include <stdlib.h>
+#include <signal.h>
+
 #define OPENSSL_C /* tells apps.h to use complete apps_startup() */
 #include "apps.h"
 #include <openssl/bio.h>
@@ -215,21 +217,49 @@
 	}
 
 
+static char *to_free=NULL;
+static LHASH *prog=NULL;
+static ARGS arg;
+
+void exit_handler(int exit)
+{
+	fprintf(stderr, "In exit handler\n");
+	fflush(stderr);
+	if (to_free)
+		OPENSSL_free(to_free);
+	if (config != NULL)
+		{
+		NCONF_free(config);
+		config=NULL;
+		}
+	if (prog != NULL) lh_free(prog);
+	if (arg.data != NULL) OPENSSL_free(arg.data);
+
+	apps_shutdown();
+
+	CRYPTO_mem_leaks(bio_err);
+	if (bio_err != NULL) {
+		BIO_free(bio_err);
+		bio_err=NULL;
+	}
+	return;
+}
+
 int main(int Argc, char *Argv[])
 	{
-	ARGS arg;
 #define PROG_NAME_SIZE	39
 	char pname[PROG_NAME_SIZE+1];
 	FUNCTION f,*fp;
 	MS_STATIC const char *prompt;
 	MS_STATIC char buf[1024];
-	char *to_free=NULL;
 	int n,i,ret=0;
 	int argc;
 	char **argv,*p;
-	LHASH *prog=NULL;
 	long errline;
  
+	signal(SIGTERM, exit_handler);
+	signal(SIGKILL, exit_handler);
+
 	arg.data=NULL;
 	arg.count=0;
 
diff -Naur -X symlinks openssl-0.9.8o.orig/apps/speed.c openssl-0.9.8o/apps/speed.c
--- openssl-0.9.8o.orig/apps/speed.c	2010-09-07 16:38:51.627699944 -0400
+++ openssl-0.9.8o/apps/speed.c	2010-09-22 15:26:59.423376446 -0400
@@ -104,6 +104,10 @@
 #include OPENSSL_UNISTD
 #endif
 
+#include <sched.h>
+
+#define RMISEC_CUSTOM
+
 #ifndef OPENSSL_SYS_NETWARE
 #include <signal.h>
 #endif
@@ -290,7 +294,7 @@
 #define RSA_NUM		4
 #define DSA_NUM		3
 
-#define EC_NUM       16
+#define EC_NUM       35
 #define MAX_ECDH_SIZE 256
 
 static const char *names[ALGOR_NUM]={
@@ -662,6 +666,26 @@
 #define R_EC_B409    14
 #define R_EC_B571    15
 
+#define R_EC_secp160k1  16
+#define R_EC_secp160r2  17
+#define R_EC_wtls9_160  18
+#define R_EC_brap160r1  19
+#define R_EC_secp192k1  20
+#define R_EC_prim192v2  21
+#define R_EC_prim192v3  22
+#define R_EC_brap192r1  23
+#define R_EC_secp224k1  24
+#define R_EC_brap224r1  25
+#define R_EC_secp256k1  26
+#define R_EC_brap256r1  27
+#define R_EC_brap384r1  28
+#define R_EC_secp512r1  29
+#define R_EC_brap512r1  30
+#define R_EC_sect163r1  31
+#define R_EC_ctnb191v1  32
+#define R_EC_ctnb191v2  33
+#define R_EC_ctnb191v3  34
+
 #ifndef OPENSSL_NO_RSA
 	RSA *rsa_key[RSA_NUM];
 	long rsa_c[RSA_NUM][2];
@@ -702,7 +726,26 @@
 	NID_sect233r1,
 	NID_sect283r1,
 	NID_sect409r1,
-	NID_sect571r1
+	NID_sect571r1,
+        NID_secp160k1,
+        NID_secp160r2,
+        NID_wap_wsg_idm_ecid_wtls9,
+        NID_brap160r1,
+        NID_secp192k1,
+        NID_X9_62_prime192v2,
+        NID_X9_62_prime192v3,
+        NID_brap192r1,
+        NID_secp224k1,
+        NID_brap224r1,
+        NID_secp256k1,
+        NID_brap256r1,
+        NID_brap384r1,
+        NID_secp512r1,
+        NID_brap512r1,
+        NID_sect163r1,
+        NID_X9_62_c2tnb191v1,
+        NID_X9_62_c2tnb191v2,
+        NID_X9_62_c2tnb191v3,
 	}; 
 	static const char * test_curves_names[EC_NUM] = 
 	{
@@ -723,13 +766,36 @@
 	"nistb233",
 	"nistb283",
 	"nistb409",
-	"nistb571"
+	"nistb571",
+        "secp160k1",
+        "secp160r2",
+        "wtls9_160",
+        "brap160r1",
+        "secp192k1",
+        "prim192v2",
+        "prim192v3",
+        "brap192r1",
+        "secp224k1",
+        "brap224r1",
+        "secp256k1",
+        "brap256r1",
+        "brap384r1",
+        "secp512r1",
+        "brap512r1",
+        "sect163r1",
+        "ctnb191v1",
+        "ctnb191v2",
+        "ctnb191v3",
 	};
 	static int test_curves_bits[EC_NUM] =
         {
         160, 192, 224, 256, 384, 521,
         163, 233, 283, 409, 571,
-        163, 233, 283, 409, 571
+        163, 233, 283, 409, 571,
+        160, 160, 160, 160, 192,
+        192, 192, 192, 224, 224,
+        256, 256, 384, 512, 512,
+        163, 191, 191, 191,
         };
 
 #endif
@@ -890,6 +956,36 @@
 			   means all of them should be run) */
 			j--;
 			}
+#ifdef RMISEC_CUSTOM
+		else if	((argc > 0) && (strcmp(*argv,"-enginecmd") == 0))
+			{
+			const char *tmp = strchr(*argv, ' ');
+			argc--;
+			argv++;
+			if(e == NULL)
+				{
+				BIO_printf(bio_err,"no engine set.\n");
+				goto end;
+				}
+			if(argc == 0)
+				{
+				BIO_printf(bio_err,"no engine parameter given\n");
+				goto end;
+				}
+
+			// if tmp points to next parameter,
+			// then pass NULL to engine control.
+			if(tmp != NULL && *tmp == '-')
+				{
+				tmp = NULL;
+				}
+			if(!ENGINE_ctrl_cmd(e, *argv, 0, (void *)tmp, 0, 0))
+				{
+				BIO_printf(bio_err,"%s is an unknown cipher or digest\n",*argv);
+				goto end;
+				}
+			}
+#endif //RMISEC_CUSTOM
 #endif
 #ifndef NO_FORK
 		else if	((argc > 0) && (strcmp(*argv,"-multi") == 0))
@@ -1106,6 +1202,24 @@
 		else if (strcmp(*argv,"ecdsab283") == 0) ecdsa_doit[R_EC_B283]=2;
 		else if (strcmp(*argv,"ecdsab409") == 0) ecdsa_doit[R_EC_B409]=2;
 		else if (strcmp(*argv,"ecdsab571") == 0) ecdsa_doit[R_EC_B571]=2;
+                else if (strcmp(*argv,"ecdsasecp160k1") == 0) ecdsa_doit[R_EC_secp160k1]=2;
+                else if (strcmp(*argv,"ecdsasecp160r2") == 0) ecdsa_doit[R_EC_secp160r2]=2;
+                else if (strcmp(*argv,"ecdsawtls9_160") == 0) ecdsa_doit[R_EC_wtls9_160]=2;
+                else if (strcmp(*argv,"ecdsabrap160r1") == 0) ecdsa_doit[R_EC_brap160r1]=2;
+                else if (strcmp(*argv,"ecdsasecp192k1") == 0) ecdsa_doit[R_EC_secp192k1]=2;
+                else if (strcmp(*argv,"ecdsaprim192v2") == 0) ecdsa_doit[R_EC_prim192v2]=2;
+                else if (strcmp(*argv,"ecdsaprim192v3") == 0) ecdsa_doit[R_EC_prim192v3]=2;
+                else if (strcmp(*argv,"ecdsabrap192r1") == 0) ecdsa_doit[R_EC_brap192r1]=2;
+                else if (strcmp(*argv,"ecdsasecp224k1") == 0) ecdsa_doit[R_EC_secp224k1]=2;
+                else if (strcmp(*argv,"ecdsabrap224r1") == 0) ecdsa_doit[R_EC_brap224r1]=2;
+                else if (strcmp(*argv,"ecdsabrap256r1") == 0) ecdsa_doit[R_EC_brap256r1]=2;
+                else if (strcmp(*argv,"ecdsabrap384r1") == 0) ecdsa_doit[R_EC_brap384r1]=2;
+                else if (strcmp(*argv,"ecdsasecp512r1") == 0) ecdsa_doit[R_EC_secp512r1]=2;
+                else if (strcmp(*argv,"ecdsabrap512r1") == 0) ecdsa_doit[R_EC_brap512r1]=2;
+                else if (strcmp(*argv,"ecdsasect163r1") == 0) ecdsa_doit[R_EC_sect163r1]=2;
+                else if (strcmp(*argv,"ecdsactnb191v1") == 0) ecdsa_doit[R_EC_ctnb191v1]=2;
+                else if (strcmp(*argv,"ecdsactnb191v2") == 0) ecdsa_doit[R_EC_ctnb191v2]=2;
+                else if (strcmp(*argv,"ecdsactnb191v3") == 0) ecdsa_doit[R_EC_ctnb191v3]=2;
 		else if (strcmp(*argv,"ecdsa") == 0)
 			{
 			for (i=0; i < EC_NUM; i++)
@@ -1130,6 +1244,24 @@
 		else if (strcmp(*argv,"ecdhb283") == 0) ecdh_doit[R_EC_B283]=2;
 		else if (strcmp(*argv,"ecdhb409") == 0) ecdh_doit[R_EC_B409]=2;
 		else if (strcmp(*argv,"ecdhb571") == 0) ecdh_doit[R_EC_B571]=2;
+                else if (strcmp(*argv,"ecdhsecp160k1") == 0) ecdh_doit[R_EC_secp160k1]=2;
+                else if (strcmp(*argv,"ecdhsecp160r2") == 0) ecdh_doit[R_EC_secp160r2]=2;
+                else if (strcmp(*argv,"ecdhwtls9_160") == 0) ecdh_doit[R_EC_wtls9_160]=2;
+                else if (strcmp(*argv,"ecdhbrap160r1") == 0) ecdh_doit[R_EC_brap160r1]=2;
+                else if (strcmp(*argv,"ecdhsecp192k1") == 0) ecdsa_doit[R_EC_secp192k1]=2;
+                else if (strcmp(*argv,"ecdhprim192v2") == 0) ecdh_doit[R_EC_prim192v2]=2;
+                else if (strcmp(*argv,"ecdhprim192v3") == 0) ecdh_doit[R_EC_prim192v3]=2;
+                else if (strcmp(*argv,"ecdhbrap192r1") == 0) ecdh_doit[R_EC_brap192r1]=2;
+                else if (strcmp(*argv,"ecdhsecp224k1") == 0) ecdh_doit[R_EC_secp224k1]=2;
+                else if (strcmp(*argv,"ecdhbrap224r1") == 0) ecdh_doit[R_EC_brap224r1]=2;
+                else if (strcmp(*argv,"ecdhbrap256r1") == 0) ecdh_doit[R_EC_brap256r1]=2;
+                else if (strcmp(*argv,"ecdhbrap384r1") == 0) ecdh_doit[R_EC_brap384r1]=2;
+                else if (strcmp(*argv,"ecdhsecp512r1") == 0) ecdh_doit[R_EC_secp512r1]=2;
+                else if (strcmp(*argv,"ecdhbrap512r1") == 0) ecdh_doit[R_EC_brap512r1]=2;
+                else if (strcmp(*argv,"ecdhsect163r1") == 0) ecdh_doit[R_EC_sect163r1]=2;
+                else if (strcmp(*argv,"ecdhctnb191v1") == 0) ecdh_doit[R_EC_ctnb191v1]=2;
+                else if (strcmp(*argv,"ecdhctnb191v2") == 0) ecdh_doit[R_EC_ctnb191v2]=2;
+                else if (strcmp(*argv,"ecdhctnb191v3") == 0) ecdh_doit[R_EC_ctnb191v3]=2;
 		else if (strcmp(*argv,"ecdh") == 0)
 			{
 			for (i=0; i < EC_NUM; i++)
@@ -1220,12 +1352,22 @@
 			BIO_printf(bio_err,"ecdsap160 ecdsap192 ecdsap224 ecdsap256 ecdsap384 ecdsap521\n");
 			BIO_printf(bio_err,"ecdsak163 ecdsak233 ecdsak283 ecdsak409 ecdsak571\n");
 			BIO_printf(bio_err,"ecdsab163 ecdsab233 ecdsab283 ecdsab409 ecdsab571\n");
+                        BIO_printf(bio_err,"ecdsasecp160k1 ecdsasecp160r2 ecdsawtls9_160 ecdsabrap160r1\n");
+                        BIO_printf(bio_err,"ecdsasecp192k1 ecdsaprim192v2 ecdsaprim192v3 ecdsabrap192r1\n");
+                        BIO_printf(bio_err,"ecdsasecp224k1 ecdsabrap224r1 ecdsabrap256r1 ecdsabrap384r1\n");
+                        BIO_printf(bio_err,"ecdsasecp512r1 ecdsabrap512r1 ecdsasect163r1 ecdsactnb191v1\n");
+                        BIO_printf(bio_err,"ecdsactnb191v2 ecdsactnb191v3\n");
 			BIO_printf(bio_err,"ecdsa\n");
 #endif
 #ifndef OPENSSL_NO_ECDH
 			BIO_printf(bio_err,"ecdhp160  ecdhp192  ecdhp224  ecdhp256  ecdhp384  ecdhp521\n");
 			BIO_printf(bio_err,"ecdhk163  ecdhk233  ecdhk283  ecdhk409  ecdhk571\n");
 			BIO_printf(bio_err,"ecdhb163  ecdhb233  ecdhb283  ecdhb409  ecdhb571\n");
+                        BIO_printf(bio_err,"ecdhsecp160k1 ecdhsecp160r2 ecdhwtls9_160 ecdhbrap160r1\n");
+                        BIO_printf(bio_err,"ecdhsecp192k1 ecdhprim192v2 ecdhprim192v3 ecdhbrap192r1\n");
+                        BIO_printf(bio_err,"ecdhsecp224k1 ecdhbrap224r1 ecdhbrap256r1 ecdhbrap384r1\n");
+                        BIO_printf(bio_err,"ecdhsecp512r1 ecdhbrap512r1 ecdhsect163r1 ecdhctnb191v1\n");
+                        BIO_printf(bio_err,"ecdhctnb191v2 ecdhctnb191v3\n");
 			BIO_printf(bio_err,"ecdh\n");
 #endif
 
@@ -1267,6 +1409,7 @@
 #endif
 #ifndef OPENSSL_NO_ENGINE
 			BIO_printf(bio_err,"-engine e       use engine e, possibly a hardware device.\n");
+			BIO_printf(bio_err,"-enginecmd cmd  send control commands to engine after initialization.\n");
 #endif
 			BIO_printf(bio_err,"-evp e          use EVP e.\n");
 			BIO_printf(bio_err,"-decrypt        time decryption instead of encryption (only EVP).\n");
@@ -1297,6 +1440,14 @@
 			rsa_doit[i]=1;
 		for (i=0; i<DSA_NUM; i++)
 			dsa_doit[i]=1;
+#ifndef OPENSSL_NO_ECDSA
+		for (i=0; i<EC_NUM; i++)
+			ecdsa_doit[i]=1;
+#endif
+#ifndef OPENSSL_NO_ECDH
+		for (i=0; i<EC_NUM; i++)
+			ecdh_doit[i]=1;
+#endif
 		}
 	for (i=0; i<ALGOR_NUM; i++)
 		if (doit[i]) pr_header++;
@@ -2173,6 +2324,7 @@
 #endif
 
 	RAND_pseudo_bytes(buf,20);
+
 #ifndef OPENSSL_NO_DSA
 	if (RAND_status() != 1)
 		{
@@ -2335,7 +2487,8 @@
 				ecdsasiglen, ecdsa[j]);
 			if (ret != 1) 
 				{
-				BIO_printf(bio_err,"ECDSA verify failure.  No ECDSA verify will be done.\n");
+				BIO_printf(bio_err,"ECDSA verify failure.  "
+					   "No ECDSA verify will be done.\n");
 				ERR_print_errors(bio_err);
 				ecdsa_doit[j] = 0;
 				} 
@@ -2791,7 +2944,6 @@
 			usertime=0;
 			return 0;
 			}
-		printf("Forked child %d\n",n);
 		}
 
 	/* for now, assume the pipe is long enough to take all the output */
diff -Naur -X symlinks openssl-0.9.8o.orig/apps/speed.c.rej openssl-0.9.8o/apps/speed.c.rej
--- openssl-0.9.8o.orig/apps/speed.c.rej	1969-12-31 19:00:00.000000000 -0500
+++ openssl-0.9.8o/apps/speed.c.rej	2010-09-22 15:26:59.423376446 -0400
@@ -0,0 +1,45 @@
+--- apps/speed.c	2007-11-15 08:33:47.000000000 -0500
++++ apps/speed.c	2009-09-25 10:22:22.000000000 -0400
+@@ -2908,18 +3061,35 @@
+ 	int fd[2];
+ 	int *fds;
+ 	static char sep[]=":";
++	unsigned long i;
++	int num_cpus = 1, t;
++
++	/* calculating number of cpus */
++	sched_getaffinity(0, sizeof(unsigned long), &i);
++	while(i) {
++		num_cpus += i & 1?1:0;
++		i >>= 1;
++	}
++	num_cpus --;
+ 
+ 	fds=malloc(multi*sizeof *fds);
+-	for(n=0 ; n < multi ; ++n)
+-		{
+-		pipe(fd);
+-		if(fork())
+-			{
++	for(n=0, t = 0; n < multi ; ++n) {
++		pid_t cid;
++		if(pipe(fd)) {
++			fprintf(stderr, "Error creating pipe for child %d\n", n);
++		}
++		if((cid = fork())) {
+ 			close(fd[1]);
+ 			fds[n]=fd[0];
++			fprintf(stderr, "Forked child %d: 0x%x\n",n, cid);
++			t = ((t + 1) % num_cpus);
++		} else {
++			i = (1 << t);
++			if(sched_setaffinity(0, sizeof(unsigned long), &i) < 0) {
++				printf("Error setting affinity %lx %d %s\n", i, errno,
++				       strerror(errno));
++				exit(1);
+ 			}
+-		else
+-			{
+ 			close(fd[0]);
+ 			close(1);
+ 			dup(fd[1]);
diff -Naur -X symlinks openssl-0.9.8o.orig/certs/argena.pem openssl-0.9.8o/certs/argena.pem
--- openssl-0.9.8o.orig/certs/argena.pem	1969-12-31 19:00:00.000000000 -0500
+++ openssl-0.9.8o/certs/argena.pem	2010-09-22 15:26:59.423376446 -0400
@@ -0,0 +1,39 @@
+-----BEGIN CERTIFICATE-----
+MIIG0zCCBbugAwIBAgIBADANBgkqhkiG9w0BAQUFADCBzDELMAkGA1UEBhMCQVQx
+EDAOBgNVBAgTB0F1c3RyaWExDzANBgNVBAcTBlZpZW5uYTE6MDgGA1UEChMxQVJH
+RSBEQVRFTiAtIEF1c3RyaWFuIFNvY2lldHkgZm9yIERhdGEgUHJvdGVjdGlvbjEl
+MCMGA1UECxMcQS1DRVJUIENlcnRpZmljYXRpb24gU2VydmljZTEYMBYGA1UEAxMP
+QS1DRVJUIEFEVkFOQ0VEMR0wGwYJKoZIhvcNAQkBFg5pbmZvQGEtY2VydC5hdDAe
+Fw0wNDEwMjMxNDE0MTRaFw0xMTEwMjMxNDE0MTRaMIHMMQswCQYDVQQGEwJBVDEQ
+MA4GA1UECBMHQXVzdHJpYTEPMA0GA1UEBxMGVmllbm5hMTowOAYDVQQKEzFBUkdF
+IERBVEVOIC0gQXVzdHJpYW4gU29jaWV0eSBmb3IgRGF0YSBQcm90ZWN0aW9uMSUw
+IwYDVQQLExxBLUNFUlQgQ2VydGlmaWNhdGlvbiBTZXJ2aWNlMRgwFgYDVQQDEw9B
+LUNFUlQgQURWQU5DRUQxHTAbBgkqhkiG9w0BCQEWDmluZm9AYS1jZXJ0LmF0MIIB
+IjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEA3euXIy+mnf6BYKbK+QH5k679
+tUFqeT8jlZxMew8eNiHuw9KoxWBzL6KksK+5uK7Gatw+sbAYntEGE80P+Jg1hADM
+e+Fr5V0bc6QS3gkVtfUCW/RIvfMM39oxvmqJmOgPnJU7H6+nmLtsq61tv9kVJi/2
+4Y5wXW3odet72sF57EoG6s78w0BUVLNcMngS9bZZzmdG3/d6JbkGgoNF/8DcgCBJ
+W/t0JrcIzyppXIOVtUzzOrrU86zuUgT3Rtkl5kjG7DEHpFb9H0fTOY1v8+gRoaO6
+2gA0PCiysgVZjwgVeYe3KAg11nznyleDv198uK3Dc1oXIGYjJx2FpKWUvAuAEwID
+AQABo4ICvDCCArgwHQYDVR0OBBYEFDd/Pj6ZcWDKJNSRE3nQdCm0qCTYMIH5BgNV
+HSMEgfEwge6AFDd/Pj6ZcWDKJNSRE3nQdCm0qCTYoYHSpIHPMIHMMQswCQYDVQQG
+EwJBVDEQMA4GA1UECBMHQXVzdHJpYTEPMA0GA1UEBxMGVmllbm5hMTowOAYDVQQK
+EzFBUkdFIERBVEVOIC0gQXVzdHJpYW4gU29jaWV0eSBmb3IgRGF0YSBQcm90ZWN0
+aW9uMSUwIwYDVQQLExxBLUNFUlQgQ2VydGlmaWNhdGlvbiBTZXJ2aWNlMRgwFgYD
+VQQDEw9BLUNFUlQgQURWQU5DRUQxHTAbBgkqhkiG9w0BCQEWDmluZm9AYS1jZXJ0
+LmF0ggEAMA8GA1UdEwEB/wQFMAMBAf8wCwYDVR0PBAQDAgHmMEcGA1UdJQRAMD4G
+CCsGAQUFBwMBBggrBgEFBQcDAgYIKwYBBQUHAwMGCCsGAQUFBwMEBggrBgEFBQcD
+CAYKKwYBBAGCNwoDBDARBglghkgBhvhCAQEEBAMCAP8wUQYDVR0gBEowSDBGBggq
+KAAYAQEBAzA6MDgGCCsGAQUFBwIBFixodHRwOi8vd3d3LmEtY2VydC5hdC9jZXJ0
+aWZpY2F0ZS1wb2xpY3kuaHRtbDA7BglghkgBhvhCAQgELhYsaHR0cDovL3d3dy5h
+LWNlcnQuYXQvY2VydGlmaWNhdGUtcG9saWN5Lmh0bWwwGQYDVR0RBBIwEIEOaW5m
+b0BhLWNlcnQuYXQwLwYDVR0SBCgwJoEOaW5mb0BhLWNlcnQuYXSGFGh0dHA6Ly93
+d3cuYS1jZXJ0LmF0MEUGA1UdHwQ+MDwwOqA4oDaGNGh0dHBzOi8vc2VjdXJlLmEt
+Y2VydC5hdC9jZ2ktYmluL2EtY2VydC1hZHZhbmNlZC5jZ2kwDQYJKoZIhvcNAQEF
+BQADggEBACX1IvgfdG2rvfv35O48vSEvcVaEdlN8USFBHWz3JRAozgzvaBtwHkjK
+Zwt5l/BWOtjbvHfRjDt7ijlBEcxOOrNC1ffyMHwHrXpvff6YpQ5wnxmIYEQcURiG
+HMqruEX0WkuDNgSKwefsgXs27eeBauHgNGVcTYH1rmHu/ZyLpLxOyJQ2PCzA1DzW
+3rWkIX92ogJ7lTRdWrbxwUL1XGinxnnaQ74+/y0pI9JNEv7ic2tpkweRMpkedaLW
+msC1+orfKTebsg69aMaCx7o6jNONRmR/7TVaPf8/k6g52cHZ9YWjQvup22b5rWxG
+J5r5LZ4vCPmF4+T4lutjUYAa/lGuQTg=
+-----END CERTIFICATE-----
diff -Naur -X symlinks openssl-0.9.8o.orig/certs/argeng.pem openssl-0.9.8o/certs/argeng.pem
--- openssl-0.9.8o.orig/certs/argeng.pem	1969-12-31 19:00:00.000000000 -0500
+++ openssl-0.9.8o/certs/argeng.pem	2010-09-22 15:26:59.423376446 -0400
@@ -0,0 +1,23 @@
+-----BEGIN CERTIFICATE-----
+MIIDwzCCAyygAwIBAgIBADANBgkqhkiG9w0BAQQFADCBmDELMAkGA1UEBhMCQVQx
+EDAOBgNVBAgTB0F1c3RyaWExDzANBgNVBAcTBlZpZW5uYTFCMEAGA1UEChM5QXJn
+ZSBEYXRlbiBPZXN0ZXJyZWljaGlzY2hlIEdlc2VsbHNjaGFmdCBmdWVyIERhdGVu
+c2NodXR6MSIwIAYJKoZIhvcNAQkBFhNhLWNlcnRAYXJnZWRhdGVuLmF0MB4XDTAx
+MDIxMjExMzAzMFoXDTA5MDIxMjExMzAzMFowgZgxCzAJBgNVBAYTAkFUMRAwDgYD
+VQQIEwdBdXN0cmlhMQ8wDQYDVQQHEwZWaWVubmExQjBABgNVBAoTOUFyZ2UgRGF0
+ZW4gT2VzdGVycmVpY2hpc2NoZSBHZXNlbGxzY2hhZnQgZnVlciBEYXRlbnNjaHV0
+ejEiMCAGCSqGSIb3DQEJARYTYS1jZXJ0QGFyZ2VkYXRlbi5hdDCBnzANBgkqhkiG
+9w0BAQEFAAOBjQAwgYkCgYEAwgsHqoNtmmrJ86+e1I4hOVBaL4kokqKN2IPOIL+1
+XwY8vfOOUfPEdhWpaC0ldt7VYrksgDiUccgH0FROANWK2GkfKMDzjjXHysR04uEb
+Om7Kqjqn0nproOGkFG+QvBZgs+Ws+HXNFJA6V76fU4+JXq4452LSK4Lr5YcBquu3
+NJECAwEAAaOCARkwggEVMB0GA1UdDgQWBBQ0j59zH/G31zRjgK1y2P//tSAWZjCB
+xQYDVR0jBIG9MIG6gBQ0j59zH/G31zRjgK1y2P//tSAWZqGBnqSBmzCBmDELMAkG
+A1UEBhMCQVQxEDAOBgNVBAgTB0F1c3RyaWExDzANBgNVBAcTBlZpZW5uYTFCMEAG
+A1UEChM5QXJnZSBEYXRlbiBPZXN0ZXJyZWljaGlzY2hlIEdlc2VsbHNjaGFmdCBm
+dWVyIERhdGVuc2NodXR6MSIwIAYJKoZIhvcNAQkBFhNhLWNlcnRAYXJnZWRhdGVu
+LmF0ggEAMAwGA1UdEwQFMAMBAf8wCwYDVR0PBAQDAgEGMBEGCWCGSAGG+EIBAQQE
+AwICBDANBgkqhkiG9w0BAQQFAAOBgQBFuJYncqMYB6gXQS3eDOI90BEHfFTKy/dV
+AV+K7QdAYikWmqgBheRdPKddJdccPy/Zl/p3ZT7GhDyC5f3wZjcuu8AJ27BNwbCA
+x54dgxgCNcyPm79nY8MRtEdEpoRGdSsFKJemz6hpXM++MWFciyrRWIIA44XB0Gv3
+US0spjsDPQ==
+-----END CERTIFICATE-----
diff -Naur -X symlinks openssl-0.9.8o.orig/certs/demo/nortelCA.pem openssl-0.9.8o/certs/demo/nortelCA.pem
--- openssl-0.9.8o.orig/certs/demo/nortelCA.pem	1969-12-31 19:00:00.000000000 -0500
+++ openssl-0.9.8o/certs/demo/nortelCA.pem	2010-09-22 15:26:59.423376446 -0400
@@ -0,0 +1,16 @@
+-----BEGIN CERTIFICATE-----
+MIICajCCAdMCBDGA0QUwDQYJKoZIhvcNAQEEBQAwfTELMAkGA1UEBhMCQ2ExDzAN
+BgNVBAcTBk5lcGVhbjEeMBwGA1UECxMVTm8gTGlhYmlsaXR5IEFjY2VwdGVkMR8w
+HQYDVQQKExZGb3IgRGVtbyBQdXJwb3NlcyBPbmx5MRwwGgYDVQQDExNFbnRydXN0
+IERlbW8gV2ViIENBMB4XDTk2MDQyNjEzMzUwMVoXDTA2MDQyNjEzMzUwMVowfTEL
+MAkGA1UEBhMCQ2ExDzANBgNVBAcTBk5lcGVhbjEeMBwGA1UECxMVTm8gTGlhYmls
+aXR5IEFjY2VwdGVkMR8wHQYDVQQKExZGb3IgRGVtbyBQdXJwb3NlcyBPbmx5MRww
+GgYDVQQDExNFbnRydXN0IERlbW8gV2ViIENBMIGdMA0GCSqGSIb3DQEBAQUAA4GL
+ADCBhwKBgQCaroS7O1DA0hm4IefNYU1cx/nqOmzEnk291d1XqznDeF4wEgakbkCc
+zTKxK791yNpXG5RmngqH7cygDRTHZJ6mfCRn0wGC+AI00F2vYTGqPGRQL1N3lZT0
+YDKFC0SQeMMjFIZ1aeQigroFQnHo0VB3zWIMpNkka8PY9lxHZAmWwQIBAzANBgkq
+hkiG9w0BAQQFAAOBgQBAx0UMVA1s54lMQyXjMX5kj99FJN5itb8bK1Rk+cegPQPF
+cWO9SEWyEjjBjIkjjzAwBkaEszFsNGxemxtXvwjIm1xEUMTVlPEWTs2qnDvAUA9W
+YqhWbhH0toGT36236QAsqCZ76rbTRVSSX2BHyJwJMG2tCRv7kRJ//NIgxj3H4w==
+-----END CERTIFICATE-----
+
diff -Naur -X symlinks openssl-0.9.8o.orig/certs/demo/timCA.pem openssl-0.9.8o/certs/demo/timCA.pem
--- openssl-0.9.8o.orig/certs/demo/timCA.pem	1969-12-31 19:00:00.000000000 -0500
+++ openssl-0.9.8o/certs/demo/timCA.pem	2010-09-22 15:26:59.423376446 -0400
@@ -0,0 +1,16 @@
+Tims test GCI CA
+
+-----BEGIN CERTIFICATE-----
+MIIB8DCCAZoCAQAwDQYJKoZIhvcNAQEEBQAwgYIxCzAJBgNVBAYTAkFVMRMwEQYD
+VQQIEwpRdWVlbnNsYW5kMREwDwYDVQQHEwhCcmlzYmFuZTEaMBgGA1UEChMRQ3J5
+cHRTb2Z0IFB0eSBMdGQxFDASBgNVBAsTC2RldmVsb3BtZW50MRkwFwYDVQQDExBD
+cnlwdFNvZnQgRGV2IENBMB4XDTk3MDMyMjEzMzQwNFoXDTk4MDMyMjEzMzQwNFow
+gYIxCzAJBgNVBAYTAkFVMRMwEQYDVQQIEwpRdWVlbnNsYW5kMREwDwYDVQQHEwhC
+cmlzYmFuZTEaMBgGA1UEChMRQ3J5cHRTb2Z0IFB0eSBMdGQxFDASBgNVBAsTC2Rl
+dmVsb3BtZW50MRkwFwYDVQQDExBDcnlwdFNvZnQgRGV2IENBMFwwDQYJKoZIhvcN
+AQEBBQADSwAwSAJBAOAOAqogG5QwAmLhzyO4CoRnx/wVy4NZP4dxJy83O1EnL0rw
+OdsamJKvPOLHgSXo3gDu9uVyvCf/QJmZAmC5ml8CAwEAATANBgkqhkiG9w0BAQQF
+AANBADRRS/GVdd7rAqRW6SdmgLJduOU2yq3avBu99kRqbp9A/dLu6r6jU+eP4oOA
+TfdbFZtAAD2Hx9jUtY3tfdrJOb8= 
+-----END CERTIFICATE-----
+
diff -Naur -X symlinks openssl-0.9.8o.orig/certs/demo/tjhCA.pem openssl-0.9.8o/certs/demo/tjhCA.pem
--- openssl-0.9.8o.orig/certs/demo/tjhCA.pem	1969-12-31 19:00:00.000000000 -0500
+++ openssl-0.9.8o/certs/demo/tjhCA.pem	2010-09-22 15:26:59.423376446 -0400
@@ -0,0 +1,15 @@
+-----BEGIN CERTIFICATE-----
+MIICVjCCAgACAQAwDQYJKoZIhvcNAQEEBQAwgbUxCzAJBgNVBAYTAkFVMRMwEQYD
+VQQIEwpRdWVlbnNsYW5kMREwDwYDVQQHEwhCcmlzYmFuZTEaMBgGA1UEChMRQ3J5
+cHRTb2Z0IFB0eSBMdGQxLDAqBgNVBAsTI1dPUlRITEVTUyBDRVJUSUZJQ0FUSU9O
+IEFVVEhPUklUSUVTMTQwMgYDVQQDEytaRVJPIFZBTFVFIENBIC0gREVNT05TVFJB
+VElPTiBQVVJQT1NFUyBPTkxZMB4XDTk3MDQwMzEzMjI1NFoXDTk4MDQwMzEzMjI1
+NFowgbUxCzAJBgNVBAYTAkFVMRMwEQYDVQQIEwpRdWVlbnNsYW5kMREwDwYDVQQH
+EwhCcmlzYmFuZTEaMBgGA1UEChMRQ3J5cHRTb2Z0IFB0eSBMdGQxLDAqBgNVBAsT
+I1dPUlRITEVTUyBDRVJUSUZJQ0FUSU9OIEFVVEhPUklUSUVTMTQwMgYDVQQDEyta
+RVJPIFZBTFVFIENBIC0gREVNT05TVFJBVElPTiBQVVJQT1NFUyBPTkxZMFwwDQYJ
+KoZIhvcNAQEBBQADSwAwSAJBAOZ7T7yqP/tyspcko3yPY1y0Cm2EmwNvzW4QgVXR
+Fjs3HmJ4xtSpXdo6mwcGezL3Abt/aQXaxv9PU8xt+Jr0OFUCAwEAATANBgkqhkiG
+9w0BAQQFAANBAOQpYmGgyCqCy1OljgJhCqQOu627oVlHzK1L+t9vBaMfn40AVUR4
+WzQVWO31KTgi5vTK1U+3h46fgUWqQ0h+6rU=
+-----END CERTIFICATE-----
diff -Naur -X symlinks openssl-0.9.8o.orig/certs/demo/vsigntca.pem openssl-0.9.8o/certs/demo/vsigntca.pem
--- openssl-0.9.8o.orig/certs/demo/vsigntca.pem	1969-12-31 19:00:00.000000000 -0500
+++ openssl-0.9.8o/certs/demo/vsigntca.pem	2010-09-22 15:26:59.423376446 -0400
@@ -0,0 +1,18 @@
+subject=/O=VeriSign, Inc/OU=www.verisign.com/repository/TestCPS Incorp. By Ref. Liab. LTD./OU=For VeriSign authorized testing only. No assurances (C)VS1997
+notBefore=Mar  4 00:00:00 1997 GMT
+notAfter=Mar  4 23:59:59 2025 GMT
+-----BEGIN CERTIFICATE-----
+MIICTTCCAfcCEEdoCqpuXxnoK27q7d58Qc4wDQYJKoZIhvcNAQEEBQAwgakxFjAU
+BgNVBAoTDVZlcmlTaWduLCBJbmMxRzBFBgNVBAsTPnd3dy52ZXJpc2lnbi5jb20v
+cmVwb3NpdG9yeS9UZXN0Q1BTIEluY29ycC4gQnkgUmVmLiBMaWFiLiBMVEQuMUYw
+RAYDVQQLEz1Gb3IgVmVyaVNpZ24gYXV0aG9yaXplZCB0ZXN0aW5nIG9ubHkuIE5v
+IGFzc3VyYW5jZXMgKEMpVlMxOTk3MB4XDTk3MDMwNDAwMDAwMFoXDTI1MDMwNDIz
+NTk1OVowgakxFjAUBgNVBAoTDVZlcmlTaWduLCBJbmMxRzBFBgNVBAsTPnd3dy52
+ZXJpc2lnbi5jb20vcmVwb3NpdG9yeS9UZXN0Q1BTIEluY29ycC4gQnkgUmVmLiBM
+aWFiLiBMVEQuMUYwRAYDVQQLEz1Gb3IgVmVyaVNpZ24gYXV0aG9yaXplZCB0ZXN0
+aW5nIG9ubHkuIE5vIGFzc3VyYW5jZXMgKEMpVlMxOTk3MFwwDQYJKoZIhvcNAQEB
+BQADSwAwSAJBAMak6xImJx44jMKcbkACy5/CyMA2fqXK4PlzTtCxRq5tFkDzne7s
+cI8oFK/J+gFZNE3bjidDxf07O3JOYG9RGx8CAwEAATANBgkqhkiG9w0BAQQFAANB
+ADT523tENOKrEheZFpsJx1UUjPrG7TwYc/C4NBHrZI4gZJcKVFIfNulftVS6UMYW
+ToLEMaUojc3DuNXHG21PDG8=
+-----END CERTIFICATE-----
diff -Naur -X symlinks openssl-0.9.8o.orig/certs/eng1.pem openssl-0.9.8o/certs/eng1.pem
--- openssl-0.9.8o.orig/certs/eng1.pem	1969-12-31 19:00:00.000000000 -0500
+++ openssl-0.9.8o/certs/eng1.pem	2010-09-22 15:26:59.423376446 -0400
@@ -0,0 +1,23 @@
+-----BEGIN CERTIFICATE-----
+MIID3TCCAsWgAwIBAgIBADANBgkqhkiG9w0BAQUFADCBqDELMAkGA1UEBhMCQ0Ex
+CzAJBgNVBAgTAk9OMRAwDgYDVQQHEwdUb3JvbnRvMRgwFgYDVQQKEw9CYW5rRW5n
+aW5lIEluYy4xKTAnBgNVBAsTIENlcnRpZmljYXRpb24gQXV0aG9yaXR5IERpdmlz
+aW9uMRMwEQYDVQQDEwpiYW5rZW5naW5lMSAwHgYJKoZIhvcNAQkBFhFjYUBiYW5r
+ZW5naW5lLmNvbTAeFw05ODAxMDEwMDAwMDBaFw0zODAxMTcwMDAwMDBaMIGoMQsw
+CQYDVQQGEwJDQTELMAkGA1UECBMCT04xEDAOBgNVBAcTB1Rvcm9udG8xGDAWBgNV
+BAoTD0JhbmtFbmdpbmUgSW5jLjEpMCcGA1UECxMgQ2VydGlmaWNhdGlvbiBBdXRo
+b3JpdHkgRGl2aXNpb24xEzARBgNVBAMTCmJhbmtlbmdpbmUxIDAeBgkqhkiG9w0B
+CQEWEWNhQGJhbmtlbmdpbmUuY29tMIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIB
+CgKCAQEA14LoTUAl1/hEy+Kh1kLHiBdW2zD3V4IhM7xxTVKsYsIH56nr69ATTIxU
+P36eRzeZ137qt1AxHFjDCidk3m1Ul6l59ProPexdslLLM2npM3f2cteg+toyiYiS
+EJKjyzIu1xF1j9qzGkymSY/4DsXLZNk9FaczxMk/Ooc6Os1M3AverL4VG4rYIb6f
+eR32cIKJ9Q1fGuyKk7ipq1XQfPW8a8TgZdbHbe7U9Gk3iasGMHHvpR9Ep3mGbgdT
+uQ98SBEuIwe1BUCGg/MXpVy48MNXfAMotBgGw4pl9yqSjMni2FB+E9Q9DHFs2RgX
+MqzKuo8zcPxKx2kZ6Arj8+27dw2clQIDAQABoxAwDjAMBgNVHRMEBTADAQH/MA0G
+CSqGSIb3DQEBBQUAA4IBAQBauupHX9EhpC/r57d6b5kkeWvognxIP9//TO4iw3qb
+zIXEkPXmJmwVzlzoKJWqiya+aw19SP0+G6CzsFOBo/9ehmz+hZ8bhYX4MjlWzX5u
+Tnkhz172j9fOBUmrTVPkcRIs6zjCD5PQAGoBPP1/Zdy2N36lZ0U7lg07Opirj/yJ
+PSJeM2j0fwIFAroiVckvdT0BVwB6S/cPaAQGPghbbr1YGSmYrMriSv825ILJUfxz
+rJYunGR9FiY9Ob7+jwJwiZMS4CxSPktutxr/3hOvr1+ALS7IcVakhhA3PuZAJbdH
+FRclR9qMM8aBnBZmf+Uv3K3uhT+UBzzY654U9Yi1JYnA
+-----END CERTIFICATE-----
diff -Naur -X symlinks openssl-0.9.8o.orig/certs/eng2.pem openssl-0.9.8o/certs/eng2.pem
--- openssl-0.9.8o.orig/certs/eng2.pem	1969-12-31 19:00:00.000000000 -0500
+++ openssl-0.9.8o/certs/eng2.pem	2010-09-22 15:26:59.433377232 -0400
@@ -0,0 +1,23 @@
+-----BEGIN CERTIFICATE-----
+MIID3TCCAsWgAwIBAgIBADANBgkqhkiG9w0BAQUFADCBqDELMAkGA1UEBhMCQ0Ex
+CzAJBgNVBAgTAk9OMRAwDgYDVQQHEwdUb3JvbnRvMRgwFgYDVQQKEw9DZXJ0RW5n
+aW5lIEluYy4xKTAnBgNVBAsTIENlcnRpZmljYXRpb24gQXV0aG9yaXR5IERpdmlz
+aW9uMRMwEQYDVQQDEwpjZXJ0ZW5naW5lMSAwHgYJKoZIhvcNAQkBFhFjYUBjZXJ0
+ZW5naW5lLmNvbTAeFw05ODAxMDEwMDAwMDBaFw0zODAxMTcwMDAwMDBaMIGoMQsw
+CQYDVQQGEwJDQTELMAkGA1UECBMCT04xEDAOBgNVBAcTB1Rvcm9udG8xGDAWBgNV
+BAoTD0NlcnRFbmdpbmUgSW5jLjEpMCcGA1UECxMgQ2VydGlmaWNhdGlvbiBBdXRo
+b3JpdHkgRGl2aXNpb24xEzARBgNVBAMTCmNlcnRlbmdpbmUxIDAeBgkqhkiG9w0B
+CQEWEWNhQGNlcnRlbmdpbmUuY29tMIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIB
+CgKCAQEA7aTXURShaeVt9u/dP3Q2dVib3jTCZvEyc6yfpGgaYWewXWuP4HOSfI4h
+GZblbpl+dzJc6RjhR+pguIRtbT5FJB8SJGjRqoujBEOQOxtVtc2fjM9Dqh0iOvMW
+WS6buxHG55GVrHAQaO5HXEScKQBa9ZyNmpSXPTEBrDMej1OAGOkc524/TZrgFPF4
+AiJLLkxCcP8NuzUKlW3WzNMSSoCtjkUKy4wjSLlAWCFM0T9Df6/+Z8ZUQTzHoKCD
+ncH5Qnynd7DlOwKQ2JwwxRhYGiGVTUN0GUq7qA11kW3+vnbFesKQXoF6o2PVx9s2
+YXviI2NXXUjZ0pVnsnFCc45Pm8XojwIDAQABoxAwDjAMBgNVHRMEBTADAQH/MA0G
+CSqGSIb3DQEBBQUAA4IBAQBP/aHOKJ00Akzc9HWM1X30hlWZFBaQi4pqD4Uhk8+p
+KzzwFP5DRLBOz8TYBbtdXrS6hxVMr2sqWmhVkuyepWhHZazKGyHY/y0FbOXsewAV
+1QxxSyx7ve89pCKv4/w0rQcP916iHc8Y/TCpmz7eITa3GId+8H/XTaBi8GBp9X9O
+w8m25FmEB1NT+eJwefvfdKowjy4tSorKdW/eJspxNuTSRGmUy8G71W5dYvgpAlx6
+mdnHyzxEGvRYNNI2bS0ifXgbEFNWqSas9q34ea5KOpkJu8T/KyXfSb6rPOsBSb0t
+wMowwGtCVH2C4Lw/8zo0EjhMpTOsPaub408PrZ+NQ2bl
+-----END CERTIFICATE-----
diff -Naur -X symlinks openssl-0.9.8o.orig/certs/eng3.pem openssl-0.9.8o/certs/eng3.pem
--- openssl-0.9.8o.orig/certs/eng3.pem	1969-12-31 19:00:00.000000000 -0500
+++ openssl-0.9.8o/certs/eng3.pem	2010-09-22 15:26:59.433377232 -0400
@@ -0,0 +1,34 @@
+-----BEGIN CERTIFICATE-----
+MIIF3TCCA8WgAwIBAgIBADANBgkqhkiG9w0BAQUFADCBqDELMAkGA1UEBhMCQ0Ex
+CzAJBgNVBAgTAk9OMRAwDgYDVQQHEwdUb3JvbnRvMRgwFgYDVQQKEw9Gb3J0RW5n
+aW5lIEluYy4xKTAnBgNVBAsTIENlcnRpZmljYXRpb24gQXV0aG9yaXR5IERpdmlz
+aW9uMRMwEQYDVQQDEwpmb3J0ZW5naW5lMSAwHgYJKoZIhvcNAQkBFhFjYUBmb3J0
+ZW5naW5lLmNvbTAeFw05ODAxMDEwMDAwMDBaFw0zODAxMTcwMDAwMDBaMIGoMQsw
+CQYDVQQGEwJDQTELMAkGA1UECBMCT04xEDAOBgNVBAcTB1Rvcm9udG8xGDAWBgNV
+BAoTD0ZvcnRFbmdpbmUgSW5jLjEpMCcGA1UECxMgQ2VydGlmaWNhdGlvbiBBdXRo
+b3JpdHkgRGl2aXNpb24xEzARBgNVBAMTCmZvcnRlbmdpbmUxIDAeBgkqhkiG9w0B
+CQEWEWNhQGZvcnRlbmdpbmUuY29tMIICIjANBgkqhkiG9w0BAQEFAAOCAg8AMIIC
+CgKCAgEAyr7GbpwDxx1v3EYbo0gcO+ligEhlDqG2e7u/AbWGoVAqc8+q6auUJUtz
+4i7oh0yNadu1o9kpXW+znkgO0zlrgjGskqqMO1ooppzTJdFy/P8gR6x1Iuv3kWtX
+OuzwPPEjv09LWlhyJsN+oU4ztTVf07I0Q9zYupcoDQ58XKRheI9KdDB2DYSmxywA
+WSLQwIeG0Qa7gvokeQlpkgkEC7viEecJ3752KXBJHnh7As51mxnlpmG6sDy67Eli
+HDw5tHETRqbtnscGBjskGQBqR5xt7+QnnthZrN8HJHDoa9zgGephwizhkL44lXLF
+YK9W5XhFbblw2c+mAcHkokRiwD7CPeIoyD2a/Jcw3n5hegKTlNhd4BFGVF6JR7gF
+OFk2QfHXit5uthsij9Xhl7WAgQUqLgggD9MphqPf4nY66OZUJV9ZsmB+Qfp8UizB
+0WAOegactKVyRqHtRa+KIEXQXNtZgjcmMk9CYkP0nIbKtgKXaH6+9VMHNOryCnFE
+7pSsuPUkypncFWCHGSeiFO3w4w4J4csltxBADQzxfRu5KZnlToQN7bVpI/Q31tVX
+E5bjrJcq6Oj/OTqZ3ID+OqbkUdAg0ggjRKcTgxnLHd/AbMzJ6PsclDDf7cLs0WSl
+xMxQR/z5bNST1rNtT9rsiv2TOhfvCBxO9AOjBioO8PLO032HTNECAwEAAaMQMA4w
+DAYDVR0TBAUwAwEB/zANBgkqhkiG9w0BAQUFAAOCAgEAVyBpPWfT2VOyvVpslGKx
+8h0+CWP8cilygGRtZJ5dAJzc//1REAHdvK+TgZ4Foz3dqHhXI+RNN0FpzuWaYMjW
+ZTS0kAmcOQuGY1Oo4PGlPHI21pNz29oFDTJr0ZmLBJ4JKVsE2soJg55jdk9MZHA7
+K//7HH9RsmrWZOE5DZDlrxp6+naixhMwnlPKKisIy9GNZUPqGdUWABMdB/BUVVNl
+NU5TtWpIXUClMd8a+eoKcItBeYXowkHOBpinPkDX3clFDIUfWiw0Ro08s8SrrFqR
+8Szwbrj52Xv1RM56oGqCjnkvJctxihODV7NcpxoAFjIZokDom0q6zPrrTUsLFQov
+Plovc3w5hmALiDMshaTvE1nm3Psn4yQ+FlRE8epTZrQiIGypZkZC6lcz0mYawueW
+cThYWGFhVG4ktQzOjjNRsNxopW+W7cF1zQTxiWUDnxIKSj7gtdQ2jiubxEEhfVag
+r8DMtAccNVTZVURpGi56TptOOuotrTqqC+2GviW4hlxvdvmuQN0OlXlUwzz2Trxc
+FamNnuA54lZw/8arLtxsFmHrcnPw53+1spumLD0S5UkxHNu40h6LIVpZz3H+0rLz
+uFofTfiyMjcfK2AyHQTgUCbsrvgNuLDQUbyFGVchdFUkhztX3DhEVnxnnrpY4BVj
+QdTqWIvw7lGlSuDCjxEQAOc=
+-----END CERTIFICATE-----
diff -Naur -X symlinks openssl-0.9.8o.orig/certs/eng4.pem openssl-0.9.8o/certs/eng4.pem
--- openssl-0.9.8o.orig/certs/eng4.pem	1969-12-31 19:00:00.000000000 -0500
+++ openssl-0.9.8o/certs/eng4.pem	2010-09-22 15:26:59.433377232 -0400
@@ -0,0 +1,23 @@
+-----BEGIN CERTIFICATE-----
+MIID3TCCAsWgAwIBAgIBADANBgkqhkiG9w0BAQUFADCBqDELMAkGA1UEBhMCQ0Ex
+CzAJBgNVBAgTAk9OMRAwDgYDVQQHEwdUb3JvbnRvMRgwFgYDVQQKEw9NYWlsRW5n
+aW5lIEluYy4xKTAnBgNVBAsTIENlcnRpZmljYXRpb24gQXV0aG9yaXR5IERpdmlz
+aW9uMRMwEQYDVQQDEwptYWlsZW5naW5lMSAwHgYJKoZIhvcNAQkBFhFjYUBtYWls
+ZW5naW5lLmNvbTAeFw05ODAxMDEwMDAwMDBaFw0zODAxMTcwMDAwMDBaMIGoMQsw
+CQYDVQQGEwJDQTELMAkGA1UECBMCT04xEDAOBgNVBAcTB1Rvcm9udG8xGDAWBgNV
+BAoTD01haWxFbmdpbmUgSW5jLjEpMCcGA1UECxMgQ2VydGlmaWNhdGlvbiBBdXRo
+b3JpdHkgRGl2aXNpb24xEzARBgNVBAMTCm1haWxlbmdpbmUxIDAeBgkqhkiG9w0B
+CQEWEWNhQG1haWxlbmdpbmUuY29tMIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIB
+CgKCAQEAqXmfsU+lx+NFmn6tN17RTOyaddHqLnr/3rzEDIyT9TN+tF9TG7jmK7lJ
+Jrj5arQ3nTFaLF8JuND2U1z/cLPw6/TX+1tE3v3CNUDSjaisyUDiUyp3TE8hMMMz
+zfZQn0JsGgNhhWxqyzjhRQGtKL4+xtn8VsF/8zGgZYke7nlmVKz/FslDFTnNoodL
+BAEGiu9JQS9qqpbSs20NdZ6LXPL2A4iTjnsNFBW3jIMVIn/JVVyaycU7ue2oFviD
+vLNpkVZcR7A+jjIdIumOc5VSF0y7y74cQC5YwkR2mLK7UBYDK6NCY3ta/C4M8NsM
+0FpmvRl0+A1ivZtVwqI98dxDtp7HeQIDAQABoxAwDjAMBgNVHRMEBTADAQH/MA0G
+CSqGSIb3DQEBBQUAA4IBAQAjfNn5BCzxylBDakFQGWKE/P43PRibMOEzfd7+DzbY
+WIekoz3i00DwoH3b6j4gwlDJRAOq4dF6/Pt/uBOHDo/op+ef+9ErmKPd+ehXN9h3
+7QbccTgz7DtVwA4iRlDRLru+JuXzT+OsCHuFZMOLJ+KD2JAGh3W68JjdcLkrlcpt
+AU0wc5aOHPPfEBdIah8y8QtNzXRVzoBt8zzvgCARkXxTS2u/9QaXR1hML0JtDgQS
+SdZ6Kd8SN6yzqxD+buYD5sOfJmjBF/n3lqFHNMHnnGXy2TAXZtIAWzffU3A0cGPB
+N6FZ026a86HbF1X4k+xszhbJu/ikczyuWnCJIg3fTYSD
+-----END CERTIFICATE-----
diff -Naur -X symlinks openssl-0.9.8o.orig/certs/eng5.pem openssl-0.9.8o/certs/eng5.pem
--- openssl-0.9.8o.orig/certs/eng5.pem	1969-12-31 19:00:00.000000000 -0500
+++ openssl-0.9.8o/certs/eng5.pem	2010-09-22 15:26:59.433377232 -0400
@@ -0,0 +1,23 @@
+-----BEGIN CERTIFICATE-----
+MIID6TCCAtGgAwIBAgIBADANBgkqhkiG9w0BAQUFADCBrjELMAkGA1UEBhMCQ0Ex
+CzAJBgNVBAgTAk9OMRAwDgYDVQQHEwdUb3JvbnRvMRowGAYDVQQKExFUcmFkZXJF
+bmdpbmUgSW5jLjEpMCcGA1UECxMgQ2VydGlmaWNhdGlvbiBBdXRob3JpdHkgRGl2
+aXNpb24xFTATBgNVBAMTDHRyYWRlcmVuZ2luZTEiMCAGCSqGSIb3DQEJARYTY2FA
+dHJhZGVyZW5naW5lLmNvbTAeFw05ODAxMDEwMDAwMDBaFw0zODAxMTcwMDAwMDBa
+MIGuMQswCQYDVQQGEwJDQTELMAkGA1UECBMCT04xEDAOBgNVBAcTB1Rvcm9udG8x
+GjAYBgNVBAoTEVRyYWRlckVuZ2luZSBJbmMuMSkwJwYDVQQLEyBDZXJ0aWZpY2F0
+aW9uIEF1dGhvcml0eSBEaXZpc2lvbjEVMBMGA1UEAxMMdHJhZGVyZW5naW5lMSIw
+IAYJKoZIhvcNAQkBFhNjYUB0cmFkZXJlbmdpbmUuY29tMIIBIjANBgkqhkiG9w0B
+AQEFAAOCAQ8AMIIBCgKCAQEAzyX5QE+5SN+zgNn1v3zp9HmP4hQOWW8WuEVItZVP
+9bt/xj5NeJd1kyPL/SqnF2qHcL3o/74r0Ga55aKHniwKYgQTlp5ELGfQ568QQeN9
+xNIHtUXeStI9zCNZyZC+4YqObdMR/ivKA/WsLfUVMl2lV5JzJJz1BOE0gKEYiEyz
+gIq5oLzkP/mOXoHRvWSZD2D0eHYIO7ovV2epVFK7g7p+dC4QoeIUEli+GF/Myg88
+dV/qmi+Sybck2RLPXa8Nh27/ETVQ7kE1Eafmx7EyCqIhG+5lwJAy3HwHUBwAYuzj
+iuZz5lD8aQmr8SKuvy3eOH9SVN5wh3YBlrNGwTStkESVLwIDAQABoxAwDjAMBgNV
+HRMEBTADAQH/MA0GCSqGSIb3DQEBBQUAA4IBAQAWOPAUhZd3x9EQiFJcuxFTMd9q
+axgcriCzJsM6D96sYGko9xTeLhX/lr1bliVYI5AlupoLXAdMzGHJkOgaTirKjQXr
+F9nymDdUWKe3TmwGob5016nQlH7qRKvGO3hka0rOGRK2U/2JT/4Qp8iH/DFi6cyM
+uP0q8n64SAkxZXLzUuFQXqf7U/SNjzb9XJQEIAdjp7eYd3Qb4jDsDcX0FrKMF1aV
+r0dCDnS7am7WTXPYCDGdSkPgEHEtLYIYH3lZp5sKdVZ9wl4F0WNFkRWRUr7AXPjw
+50uLmUNmKCd8JZLMGA1TRNSTi7U9EcrWt0OkMWm74T2WVnAgNsDv2WrWsGfj
+-----END CERTIFICATE-----
diff -Naur -X symlinks openssl-0.9.8o.orig/certs/expired/factory.pem openssl-0.9.8o/certs/expired/factory.pem
--- openssl-0.9.8o.orig/certs/expired/factory.pem	1969-12-31 19:00:00.000000000 -0500
+++ openssl-0.9.8o/certs/expired/factory.pem	2010-09-22 15:26:59.433377232 -0400
@@ -0,0 +1,15 @@
+-----BEGIN CERTIFICATE-----
+MIICTTCCAbagAwIBAgIBADANBgkqhkiG9w0BAQQFADBMMQswCQYDVQQGEwJHQjEM
+MAoGA1UEChMDVUNMMRgwFgYDVQQLEw9JQ0UtVEVMIFByb2plY3QxFTATBgNVBAMT
+DFRydXN0RmFjdG9yeTAeFw05NzA0MjIxNDM5MTRaFw05ODA0MjIxNDM5MTRaMEwx
+CzAJBgNVBAYTAkdCMQwwCgYDVQQKEwNVQ0wxGDAWBgNVBAsTD0lDRS1URUwgUHJv
+amVjdDEVMBMGA1UEAxMMVHJ1c3RGYWN0b3J5MIGcMAoGBFUIAQECAgQAA4GNADCB
+iQKBgQCEieR8NcXkUW1f0G6aC6u0i8q/98JqS6RxK5YmHIGKCkuTWAUjzLfUa4dt
+U9igGCjTuxaDqlzEim+t/02pmiBZT9HaX++35MjQPUWmsChcYU5WyzGErXi+rQaw
+zlwS73zM8qiPj/97lXYycWhgL0VaiDSPxRXEUdWoaGruom4mNQIDAQABo0IwQDAd
+BgNVHQ4EFgQUHal1LZr7oVg5z6lYzrhTgZRCmcUwDgYDVR0PAQH/BAQDAgH2MA8G
+A1UdEwEB/wQFMAMBAf8wDQYJKoZIhvcNAQEEBQADgYEAfaggfl6FZoioecjv0dq8
+/DXo/u11iMZvXn08gjX/zl2b4wtPbShOSY5FhkSm8GeySasz+/Nwb/uzfnIhokWi
+lfPZHtlCWtXbIy/TN51eJyq04ceDCQDWvLC2enVg9KB+GJ34b5c5VaPRzq8MBxsA
+S7ELuYGtmYgYm9NZOIr7yU0=
+-----END CERTIFICATE-----
diff -Naur -X symlinks openssl-0.9.8o.orig/certs/expired/ICE-CA.pem openssl-0.9.8o/certs/expired/ICE-CA.pem
--- openssl-0.9.8o.orig/certs/expired/ICE-CA.pem	1969-12-31 19:00:00.000000000 -0500
+++ openssl-0.9.8o/certs/expired/ICE-CA.pem	2010-09-22 15:26:59.433377232 -0400
@@ -0,0 +1,59 @@
+Certificate:
+    Data:
+        Version: 3 (0x2)
+        Serial Number: 1 (0x1)
+        Signature Algorithm: md5WithRSAEncryption
+        Issuer: O=European ICE-TEL project, OU=V3-Certification Authority
+        Validity
+            Not Before: Apr  2 17:35:53 1997 GMT
+            Not After : Apr  2 17:35:53 1998 GMT
+        Subject: O=European ICE-TEL project, OU=V3-Certification Authority, L=Darmstadt
+        Subject Public Key Info:
+            Public Key Algorithm: rsa
+            RSA Public Key: (512 bit)
+                Modulus (512 bit):
+                    00:82:75:ba:f6:d1:60:b5:f9:15:b3:6a:dd:29:8f:
+                    8b:a4:6f:1a:88:e0:50:43:40:0b:79:41:d5:d3:16:
+                    44:7d:74:65:17:42:06:52:0b:e9:50:c8:10:cd:24:
+                    e2:ae:8d:22:30:73:e6:b4:b7:93:1f:e5:6e:a2:ae:
+                    49:11:a5:c9:45
+                Exponent: 65537 (0x10001)
+        X509v3 extensions:
+            X509v3 Authority Key Identifier: 
+                0.........z.."p......e..
+            X509v3 Subject Key Identifier: 
+                ..~r..:..B.44fu......3
+            X509v3 Key Usage: critical
+                ....
+            X509v3 Certificate Policies: critical
+                0.0...*...
+            X509v3 Subject Alternative Name: 
+                0!..secude-support@darmstadt.gmd.de
+            X509v3 Issuer Alternative Name: 
+                0I..ice-tel-ca@darmstadt.gmd.de.*http://www.darmstadt.gmd.de/ice-tel/euroca
+            X509v3 Basic Constraints: critical
+                0....
+            X509v3 CRL Distribution Points: 
+                0200...,.*http://www.darmstadt.gmd.de/ice-tel/euroca
+    Signature Algorithm: md5WithRSAEncryption
+        17:a2:88:b7:99:5a:05:41:e4:13:34:67:e6:1f:3e:26:ec:4b:
+        69:f9:3e:28:22:be:9d:1c:ab:41:6f:0c:00:85:fe:45:74:f6:
+        98:f0:ce:9b:65:53:4a:50:42:c7:d4:92:bd:d7:a2:a8:3d:98:
+        88:73:cd:60:28:79:a3:fc:48:7a
+-----BEGIN CERTIFICATE-----
+MIICzDCCAnagAwIBAgIBATANBgkqhkiG9w0BAQQFADBIMSEwHwYDVQQKExhFdXJv
+cGVhbiBJQ0UtVEVMIHByb2plY3QxIzAhBgNVBAsTGlYzLUNlcnRpZmljYXRpb24g
+QXV0aG9yaXR5MB4XDTk3MDQwMjE3MzU1M1oXDTk4MDQwMjE3MzU1M1owXDEhMB8G
+A1UEChMYRXVyb3BlYW4gSUNFLVRFTCBwcm9qZWN0MSMwIQYDVQQLExpWMy1DZXJ0
+aWZpY2F0aW9uIEF1dGhvcml0eTESMBAGA1UEBxMJRGFybXN0YWR0MFkwCgYEVQgB
+AQICAgADSwAwSAJBAIJ1uvbRYLX5FbNq3SmPi6RvGojgUENAC3lB1dMWRH10ZRdC
+BlIL6VDIEM0k4q6NIjBz5rS3kx/lbqKuSRGlyUUCAwEAAaOCATgwggE0MB8GA1Ud
+IwQYMBaAFIr3yNUOx3ro1yJw4AuJ1bbsZbzPMB0GA1UdDgQWBBR+cvL4OoacQog0
+NGZ1w9T80aIRMzAOBgNVHQ8BAf8EBAMCAfYwFAYDVR0gAQH/BAowCDAGBgQqAwQF
+MCoGA1UdEQQjMCGBH3NlY3VkZS1zdXBwb3J0QGRhcm1zdGFkdC5nbWQuZGUwUgYD
+VR0SBEswSYEbaWNlLXRlbC1jYUBkYXJtc3RhZHQuZ21kLmRlhipodHRwOi8vd3d3
+LmRhcm1zdGFkdC5nbWQuZGUvaWNlLXRlbC9ldXJvY2EwDwYDVR0TAQH/BAUwAwEB
+/zA7BgNVHR8ENDAyMDCgLqAshipodHRwOi8vd3d3LmRhcm1zdGFkdC5nbWQuZGUv
+aWNlLXRlbC9ldXJvY2EwDQYJKoZIhvcNAQEEBQADQQAXooi3mVoFQeQTNGfmHz4m
+7Etp+T4oIr6dHKtBbwwAhf5FdPaY8M6bZVNKUELH1JK916KoPZiIc81gKHmj/Eh6
+-----END CERTIFICATE-----
diff -Naur -X symlinks openssl-0.9.8o.orig/certs/expired/ICE-root.pem openssl-0.9.8o/certs/expired/ICE-root.pem
--- openssl-0.9.8o.orig/certs/expired/ICE-root.pem	1969-12-31 19:00:00.000000000 -0500
+++ openssl-0.9.8o/certs/expired/ICE-root.pem	2010-09-22 15:26:59.433377232 -0400
@@ -0,0 +1,48 @@
+Certificate:
+    Data:
+        Version: 3 (0x2)
+        Serial Number: 0 (0x0)
+        Signature Algorithm: md5WithRSAEncryption
+        Issuer: O=European ICE-TEL project, OU=V3-Certification Authority
+        Validity
+            Not Before: Apr  2 17:33:36 1997 GMT
+            Not After : Apr  2 17:33:36 1998 GMT
+        Subject: O=European ICE-TEL project, OU=V3-Certification Authority
+        Subject Public Key Info:
+            Public Key Algorithm: rsa
+            RSA Public Key: (512 bit)
+                Modulus (512 bit):
+                    00:80:3e:eb:ae:47:a9:fe:10:54:0b:81:8b:9c:2b:
+                    82:ab:3a:61:36:65:8b:f3:73:9f:ac:ac:7a:15:a7:
+                    13:8f:b4:c4:ba:a3:0f:bc:a5:58:8d:cc:b1:93:31:
+                    9e:81:9e:8c:19:61:86:fa:52:73:54:d1:97:76:22:
+                    e7:c7:9f:41:cd
+                Exponent: 65537 (0x10001)
+        X509v3 extensions:
+            X509v3 Subject Key Identifier: 
+                ........z.."p......e..
+            X509v3 Key Usage: critical
+                ....
+            X509v3 Subject Alternative Name: 
+                0I.*http://www.darmstadt.gmd.de/ice-tel/euroca..ice-tel-ca@darmstadt.gmd.de
+            X509v3 Basic Constraints: critical
+                0....
+    Signature Algorithm: md5WithRSAEncryption
+        76:69:61:db:b7:cf:8b:06:9e:d8:8c:96:53:d2:4d:a8:23:a6:
+        03:44:e8:8f:24:a5:c0:84:a8:4b:77:d4:2d:2b:7d:37:91:67:
+        f2:2c:ce:02:31:4c:6b:cc:ce:f2:68:a6:11:11:ab:7d:88:b8:
+        7e:22:9f:25:06:60:bd:79:30:3d
+-----BEGIN CERTIFICATE-----
+MIICFjCCAcCgAwIBAgIBADANBgkqhkiG9w0BAQQFADBIMSEwHwYDVQQKExhFdXJv
+cGVhbiBJQ0UtVEVMIHByb2plY3QxIzAhBgNVBAsTGlYzLUNlcnRpZmljYXRpb24g
+QXV0aG9yaXR5MB4XDTk3MDQwMjE3MzMzNloXDTk4MDQwMjE3MzMzNlowSDEhMB8G
+A1UEChMYRXVyb3BlYW4gSUNFLVRFTCBwcm9qZWN0MSMwIQYDVQQLExpWMy1DZXJ0
+aWZpY2F0aW9uIEF1dGhvcml0eTBZMAoGBFUIAQECAgIAA0sAMEgCQQCAPuuuR6n+
+EFQLgYucK4KrOmE2ZYvzc5+srHoVpxOPtMS6ow+8pViNzLGTMZ6BnowZYYb6UnNU
+0Zd2IufHn0HNAgMBAAGjgZcwgZQwHQYDVR0OBBYEFIr3yNUOx3ro1yJw4AuJ1bbs
+ZbzPMA4GA1UdDwEB/wQEAwIB9jBSBgNVHREESzBJhipodHRwOi8vd3d3LmRhcm1z
+dGFkdC5nbWQuZGUvaWNlLXRlbC9ldXJvY2GBG2ljZS10ZWwtY2FAZGFybXN0YWR0
+LmdtZC5kZTAPBgNVHRMBAf8EBTADAQH/MA0GCSqGSIb3DQEBBAUAA0EAdmlh27fP
+iwae2IyWU9JNqCOmA0TojySlwISoS3fULSt9N5Fn8izOAjFMa8zO8mimERGrfYi4
+fiKfJQZgvXkwPQ==
+-----END CERTIFICATE-----
diff -Naur -X symlinks openssl-0.9.8o.orig/certs/expired/ICE-user.pem openssl-0.9.8o/certs/expired/ICE-user.pem
--- openssl-0.9.8o.orig/certs/expired/ICE-user.pem	1969-12-31 19:00:00.000000000 -0500
+++ openssl-0.9.8o/certs/expired/ICE-user.pem	2010-09-22 15:26:59.433377232 -0400
@@ -0,0 +1,63 @@
+Certificate:
+    Data:
+        Version: 3 (0x2)
+        Serial Number: 1 (0x1)
+        Signature Algorithm: md5WithRSAEncryption
+        Issuer: O=European ICE-TEL project, OU=V3-Certification Authority, L=Darmstadt
+        Validity
+            Not Before: Apr  2 17:35:59 1997 GMT
+            Not After : Apr  2 17:35:59 1998 GMT
+        Subject: O=European ICE-TEL project, OU=V3-Certification Authority, L=Darmstadt, CN=USER
+        Subject Public Key Info:
+            Public Key Algorithm: rsa
+            RSA Public Key: (512 bit)
+                Modulus (512 bit):
+                    00:a8:a8:53:63:49:1b:93:c3:c3:0b:6c:88:11:55:
+                    de:7e:6a:e2:f9:52:a0:dc:69:25:c4:c8:bf:55:e1:
+                    31:a8:ce:e4:a9:29:85:99:8a:15:9a:de:f6:2f:e1:
+                    b4:50:5f:5e:04:75:a6:f4:76:dc:3c:0e:39:dc:3a:
+                    be:3e:a4:61:8b
+                Exponent: 65537 (0x10001)
+        X509v3 extensions:
+            X509v3 Authority Key Identifier: 
+                0...~r..:..B.44fu......3
+            X509v3 Subject Key Identifier: 
+                ...... .*...1.*.......
+            X509v3 Key Usage: critical
+                ....
+            X509v3 Certificate Policies: critical
+                0.0...*...0.......
+            X509v3 Subject Alternative Name: 
+                0:..user@darmstadt.gmd.de.!http://www.darmstadt.gmd.de/~user
+            X509v3 Issuer Alternative Name: 
+                0....gmdca@gmd.de..http://www.gmd.de..saturn.darmstadt.gmd.de.\1!0...U.
+..European ICE-TEL project1#0!..U....V3-Certification Authority1.0...U....Darmstadt..141.12.62.26
+            X509v3 Basic Constraints: critical
+                0.
+            X509v3 CRL Distribution Points: 
+                0.0.......gmdca@gmd.de
+    Signature Algorithm: md5WithRSAEncryption
+        69:0c:e1:b7:a7:f2:d8:fb:e8:69:c0:13:cd:37:ad:21:06:22:
+        4d:e8:c6:db:f1:04:0b:b7:e0:b3:d6:0c:81:03:ce:c3:6a:3e:
+        c7:e7:24:24:a4:92:64:c2:83:83:06:42:53:0e:6f:09:1e:84:
+        9a:f7:6f:63:9b:94:99:83:d6:a4
+-----BEGIN CERTIFICATE-----
+MIIDTzCCAvmgAwIBAgIBATANBgkqhkiG9w0BAQQFADBcMSEwHwYDVQQKExhFdXJv
+cGVhbiBJQ0UtVEVMIHByb2plY3QxIzAhBgNVBAsTGlYzLUNlcnRpZmljYXRpb24g
+QXV0aG9yaXR5MRIwEAYDVQQHEwlEYXJtc3RhZHQwHhcNOTcwNDAyMTczNTU5WhcN
+OTgwNDAyMTczNTU5WjBrMSEwHwYDVQQKExhFdXJvcGVhbiBJQ0UtVEVMIHByb2pl
+Y3QxIzAhBgNVBAsTGlYzLUNlcnRpZmljYXRpb24gQXV0aG9yaXR5MRIwEAYDVQQH
+EwlEYXJtc3RhZHQxDTALBgNVBAMTBFVTRVIwWTAKBgRVCAEBAgICAANLADBIAkEA
+qKhTY0kbk8PDC2yIEVXefmri+VKg3GklxMi/VeExqM7kqSmFmYoVmt72L+G0UF9e
+BHWm9HbcPA453Dq+PqRhiwIDAQABo4IBmDCCAZQwHwYDVR0jBBgwFoAUfnLy+DqG
+nEKINDRmdcPU/NGiETMwHQYDVR0OBBYEFJfc4B8gjSoRmLUx4Sq/ucIYiMrPMA4G
+A1UdDwEB/wQEAwIB8DAcBgNVHSABAf8EEjAQMAYGBCoDBAUwBgYECQgHBjBDBgNV
+HREEPDA6gRV1c2VyQGRhcm1zdGFkdC5nbWQuZGWGIWh0dHA6Ly93d3cuZGFybXN0
+YWR0LmdtZC5kZS9+dXNlcjCBsQYDVR0SBIGpMIGmgQxnbWRjYUBnbWQuZGWGEWh0
+dHA6Ly93d3cuZ21kLmRlghdzYXR1cm4uZGFybXN0YWR0LmdtZC5kZaRcMSEwHwYD
+VQQKExhFdXJvcGVhbiBJQ0UtVEVMIHByb2plY3QxIzAhBgNVBAsTGlYzLUNlcnRp
+ZmljYXRpb24gQXV0aG9yaXR5MRIwEAYDVQQHEwlEYXJtc3RhZHSHDDE0MS4xMi42
+Mi4yNjAMBgNVHRMBAf8EAjAAMB0GA1UdHwQWMBQwEqAQoA6BDGdtZGNhQGdtZC5k
+ZTANBgkqhkiG9w0BAQQFAANBAGkM4ben8tj76GnAE803rSEGIk3oxtvxBAu34LPW
+DIEDzsNqPsfnJCSkkmTCg4MGQlMObwkehJr3b2OblJmD1qQ=
+-----END CERTIFICATE-----
diff -Naur -X symlinks openssl-0.9.8o.orig/certs/expired/RegTP-4R.pem openssl-0.9.8o/certs/expired/RegTP-4R.pem
--- openssl-0.9.8o.orig/certs/expired/RegTP-4R.pem	1969-12-31 19:00:00.000000000 -0500
+++ openssl-0.9.8o/certs/expired/RegTP-4R.pem	2010-09-22 15:26:59.433377232 -0400
@@ -0,0 +1,19 @@
+issuer= CN=4R-CA 1:PN+0.2.262.1.10.7.20=#130131,O=Regulierungsbeh\C3\88orde f\C3\88ur Telekommunikation und Post,C=DE
+notBefore=Jan 21 16:04:53 1999 GMT
+notAfter=Jan 21 16:04:53 2004 GMT
+subject= CN=4R-CA 1:PN+0.2.262.1.10.7.20=#130131,O=Regulierungsbeh\C3\88orde f\C3\88ur Telekommunikation und Post,C=DE
+-----BEGIN CERTIFICATE-----
+MIICZzCCAdOgAwIBAgIEOwVn1DAKBgYrJAMDAQIFADBvMQswCQYDVQQGEwJERTE9
+MDsGA1UEChQ0UmVndWxpZXJ1bmdzYmVoyG9yZGUgZsh1ciBUZWxla29tbXVuaWth
+dGlvbiB1bmQgUG9zdDEhMAwGBwKCBgEKBxQTATEwEQYDVQQDFAo0Ui1DQSAxOlBO
+MCIYDzE5OTkwMTIxMTYwNDUzWhgPMjAwNDAxMjExNjA0NTNaMG8xCzAJBgNVBAYT
+AkRFMT0wOwYDVQQKFDRSZWd1bGllcnVuZ3NiZWjIb3JkZSBmyHVyIFRlbGVrb21t
+dW5pa2F0aW9uIHVuZCBQb3N0MSEwDAYHAoIGAQoHFBMBMTARBgNVBAMUCjRSLUNB
+IDE6UE4wgZ8wDQYJKoZIhvcNAQEBBQADgY0AMIGJAoGAjzHbq2asUlqeWbXTQHso
+aVF6YIPVH3c/B2cbuy9HJ/lnE6x0asOzM2DGDqi47xkdAxPc0LZ0fxO87rkmz7xs
+jJObnVrMXpyUSDSp5Y0wqKJdsFdr6mGFOQZteIti8AJnr8xMkwnWVyuOlEXsFe1h
+5gxwQXrOcPinE6qu1t/3PmECBMAAAAGjEjAQMA4GA1UdDwEB/wQEAwIBBjAKBgYr
+JAMDAQIFAAOBgQA+RdocBmA2VV9E5aKPBcp01tdZAvvW9Tve3docArVKR/4/yvSX
+Z+wvzzk+uu4qBp49HN3nqPYMrzbTmjBFu4ce5fkZ7dHF0W1sSBL0rox5z36Aq2re
+JjfEOEmSnNe0+opuh4FSVOssXblXTE8lEQU0FhhItgDx2ADnWZibaxLG4w==
+-----END CERTIFICATE-----
diff -Naur -X symlinks openssl-0.9.8o.orig/certs/expired/rsa-cca.pem openssl-0.9.8o/certs/expired/rsa-cca.pem
--- openssl-0.9.8o.orig/certs/expired/rsa-cca.pem	1969-12-31 19:00:00.000000000 -0500
+++ openssl-0.9.8o/certs/expired/rsa-cca.pem	2010-09-22 15:26:59.433377232 -0400
@@ -0,0 +1,19 @@
+subject=/C=US/O=RSA Data Security, Inc./OU=Commercial Certification Authority
+issuer= /C=US/O=RSA Data Security, Inc./OU=Commercial Certification Authority
+notBefore=941104185834Z
+notAfter =991103185834Z
+-----BEGIN X509 CERTIFICATE-----
+
+MIICIzCCAZACBQJBAAAWMA0GCSqGSIb3DQEBAgUAMFwxCzAJBgNVBAYTAlVTMSAw
+HgYDVQQKExdSU0EgRGF0YSBTZWN1cml0eSwgSW5jLjErMCkGA1UECxMiQ29tbWVy
+Y2lhbCBDZXJ0aWZpY2F0aW9uIEF1dGhvcml0eTAeFw05NDExMDQxODU4MzRaFw05
+OTExMDMxODU4MzRaMFwxCzAJBgNVBAYTAlVTMSAwHgYDVQQKExdSU0EgRGF0YSBT
+ZWN1cml0eSwgSW5jLjErMCkGA1UECxMiQ29tbWVyY2lhbCBDZXJ0aWZpY2F0aW9u
+IEF1dGhvcml0eTCBmzANBgkqhkiG9w0BAQEFAAOBiQAwgYUCfgCk+4Fie84QJ93o
+975sbsZwmdu41QUDaSiCnHJ/lj+O7Kwpkj+KFPhCdr69XQO5kNTQvAayUTNfxMK/
+touPmbZiImDd298ggrTKoi8tUO2UMt7gVY3UaOLgTNLNBRYulWZcYVI4HlGogqHE
+7yXpCuaLK44xZtn42f29O2nZ6wIDAQABMA0GCSqGSIb3DQEBAgUAA34AdrW2EP4j
+9/dZYkuwX5zBaLxJu7NJbyFHXSudVMQAKD+YufKKg5tgf+tQx6sFEC097TgCwaVI
+0v5loMC86qYjFmZsGySp8+x5NRhPJsjjr1BKx6cxa9B8GJ1Qv6km+iYrRpwUqbtb
+MJhCKLVLU7tDCZJAuqiqWqTGtotXTcU=
+-----END X509 CERTIFICATE-----
diff -Naur -X symlinks openssl-0.9.8o.orig/certs/expired/rsa-ssca.pem openssl-0.9.8o/certs/expired/rsa-ssca.pem
--- openssl-0.9.8o.orig/certs/expired/rsa-ssca.pem	1969-12-31 19:00:00.000000000 -0500
+++ openssl-0.9.8o/certs/expired/rsa-ssca.pem	2010-09-22 15:26:59.433377232 -0400
@@ -0,0 +1,19 @@
+subject=/C=US/O=RSA Data Security, Inc./OU=Secure Server Certification Authority
+issuer= /C=US/O=RSA Data Security, Inc./OU=Secure Server Certification Authority
+notBefore=941109235417Z
+notAfter =991231235417Z
+-----BEGIN X509 CERTIFICATE-----
+
+MIICKTCCAZYCBQJBAAABMA0GCSqGSIb3DQEBAgUAMF8xCzAJBgNVBAYTAlVTMSAw
+HgYDVQQKExdSU0EgRGF0YSBTZWN1cml0eSwgSW5jLjEuMCwGA1UECxMlU2VjdXJl
+IFNlcnZlciBDZXJ0aWZpY2F0aW9uIEF1dGhvcml0eTAeFw05NDExMDkyMzU0MTda
+Fw05OTEyMzEyMzU0MTdaMF8xCzAJBgNVBAYTAlVTMSAwHgYDVQQKExdSU0EgRGF0
+YSBTZWN1cml0eSwgSW5jLjEuMCwGA1UECxMlU2VjdXJlIFNlcnZlciBDZXJ0aWZp
+Y2F0aW9uIEF1dGhvcml0eTCBmzANBgkqhkiG9w0BAQEFAAOBiQAwgYUCfgCSznrB
+roM+WqqJg1esJQF2DK2ujiw3zus1eGRUA+WEQFHJv48I4oqCCNIWhjdV6bEhAq12
+aIGaBaJLyUslZiJWbIgHj/eBWW2EB2VwE3F2Ppt3TONQiVaYSLkdpykaEy5KEVmc
+HhXVSVQsczppgrGXOZxtcGdI5d0t1sgeewIDAQABMA0GCSqGSIb3DQEBAgUAA34A
+iNHReSHO4ovo+MF9NFM/YYPZtgs4F7boviGNjwC4i1N+RGceIr2XJ+CchcxK9oU7
+suK+ktPlDemvXA4MRpX/oRxePug2WHpzpgr4IhFrwwk4fia7c+8AvQKk8xQNMD9h
+cHsg/jKjn7P0Z1LctO6EjJY2IN6BCINxIYoPnqk=
+-----END X509 CERTIFICATE-----
diff -Naur -X symlinks openssl-0.9.8o.orig/certs/expired/vsign2.pem openssl-0.9.8o/certs/expired/vsign2.pem
--- openssl-0.9.8o.orig/certs/expired/vsign2.pem	1969-12-31 19:00:00.000000000 -0500
+++ openssl-0.9.8o/certs/expired/vsign2.pem	2010-09-22 15:26:59.433377232 -0400
@@ -0,0 +1,18 @@
+subject=/C=US/O=VeriSign, Inc./OU=Class 2 Public Primary Certification Authority
+notBefore=Jan 29 00:00:00 1996 GMT
+notAfter=Jan  7 23:59:59 2004 GMT
+-----BEGIN CERTIFICATE-----
+MIICPTCCAaYCEQC6WslMBTuS1qe2307QU5INMA0GCSqGSIb3DQEBAgUAMF8xCzAJ
+BgNVBAYTAlVTMRcwFQYDVQQKEw5WZXJpU2lnbiwgSW5jLjE3MDUGA1UECxMuQ2xh
+c3MgMiBQdWJsaWMgUHJpbWFyeSBDZXJ0aWZpY2F0aW9uIEF1dGhvcml0eTAeFw05
+NjAxMjkwMDAwMDBaFw0wNDAxMDcyMzU5NTlaMF8xCzAJBgNVBAYTAlVTMRcwFQYD
+VQQKEw5WZXJpU2lnbiwgSW5jLjE3MDUGA1UECxMuQ2xhc3MgMiBQdWJsaWMgUHJp
+bWFyeSBDZXJ0aWZpY2F0aW9uIEF1dGhvcml0eTCBnzANBgkqhkiG9w0BAQEFAAOB
+jQAwgYkCgYEAtlqLow1qI4OAa885h/QhEzMGTCWi7VUSl8WngLn6g8EgoPovFQ18
+oWBrfnks+gYPOq72G2+x0v8vKFJfg31LxHq3+GYfgFT8t8KOWUoUV0bRmpO+QZED
+uxWAk1zr58wIbD8+s0r8/0tsI9VQgiZEGY4jw3HqGSRHBJ51v8imAB8CAwEAATAN
+BgkqhkiG9w0BAQIFAAOBgQC2AB+TV6QHp0DOZUA/VV7t7/pUSaUw1iF8YYfug5ML
+v7Qz8pisnwa/TqjOFIFMywROWMPPX+5815pvy0GKt3+BuP+EYcYnQ2UdDOyxAArd
+G6S7x3ggKLKi3TaVLuFUT79guXdoEZkj6OpS6KoATmdOu5C1RZtG644W78QzWzM9
+1Q==
+-----END CERTIFICATE-----
diff -Naur -X symlinks openssl-0.9.8o.orig/certs/expired/vsign3.pem openssl-0.9.8o/certs/expired/vsign3.pem
--- openssl-0.9.8o.orig/certs/expired/vsign3.pem	1969-12-31 19:00:00.000000000 -0500
+++ openssl-0.9.8o/certs/expired/vsign3.pem	2010-09-22 15:26:59.433377232 -0400
@@ -0,0 +1,18 @@
+subject=/C=US/O=VeriSign, Inc./OU=Class 3 Public Primary Certification Authority
+notBefore=Jan 29 00:00:00 1996 GMT
+notAfter=Jan  7 23:59:59 2004 GMT
+-----BEGIN CERTIFICATE-----
+MIICPTCCAaYCEQDknv3zOugOz6URPhmkJAIyMA0GCSqGSIb3DQEBAgUAMF8xCzAJ
+BgNVBAYTAlVTMRcwFQYDVQQKEw5WZXJpU2lnbiwgSW5jLjE3MDUGA1UECxMuQ2xh
+c3MgMyBQdWJsaWMgUHJpbWFyeSBDZXJ0aWZpY2F0aW9uIEF1dGhvcml0eTAeFw05
+NjAxMjkwMDAwMDBaFw0wNDAxMDcyMzU5NTlaMF8xCzAJBgNVBAYTAlVTMRcwFQYD
+VQQKEw5WZXJpU2lnbiwgSW5jLjE3MDUGA1UECxMuQ2xhc3MgMyBQdWJsaWMgUHJp
+bWFyeSBDZXJ0aWZpY2F0aW9uIEF1dGhvcml0eTCBnzANBgkqhkiG9w0BAQEFAAOB
+jQAwgYkCgYEAyVxZnvIbigEUtBDfBEDb41evakVAj4QMC9Ez2dkRz+4CWB8l9yqo
+RAWq7AMfeH+ek7maAKojfdashaJjRcdyJ8z0TMZ1cdI5709C8HXfCpDGjiBvmA/4
+rCNfcCk2pMmG57GaIMtTpYXnPb59mv4kRTPcdhXtD6JxZExlLoFoRacCAwEAATAN
+BgkqhkiG9w0BAQIFAAOBgQBhcOwvP579K+ZoVCGwZ3kIDCCWMYoNer62Jt95LCJp
+STbjl3diYaIy13pUITa6Ask05yXaRDWw0lyAXbOU+Pms7qRgdSoflUkjsUp89LNH
+ciFbfperVKxi513srpvSybIk+4Kt6WcVS7qqpvCXoPawl1cAyAw8CaCCBLpB2veZ
+pA==
+-----END CERTIFICATE-----
diff -Naur -X symlinks openssl-0.9.8o.orig/certs/RegTP-5R.pem openssl-0.9.8o/certs/RegTP-5R.pem
--- openssl-0.9.8o.orig/certs/RegTP-5R.pem	1969-12-31 19:00:00.000000000 -0500
+++ openssl-0.9.8o/certs/RegTP-5R.pem	2010-09-22 15:26:59.433377232 -0400
@@ -0,0 +1,19 @@
+issuer= CN=5R-CA 1:PN+0.2.262.1.10.7.20=#130131,O=Regulierungsbeh\C3\88orde f\C3\88ur Telekommunikation und Post,C=DE
+notBefore=Mar 22 08:55:51 2000 GMT
+notAfter=Mar 22 08:55:51 2005 GMT
+subject= CN=5R-CA 1:PN+0.2.262.1.10.7.20=#130131,O=Regulierungsbeh\C3\88orde f\C3\88ur Telekommunikation und Post,C=DE
+-----BEGIN CERTIFICATE-----
+MIICaDCCAdSgAwIBAgIDDIOqMAoGBiskAwMBAgUAMG8xCzAJBgNVBAYTAkRFMT0w
+OwYDVQQKFDRSZWd1bGllcnVuZ3NiZWjIb3JkZSBmyHVyIFRlbGVrb21tdW5pa2F0
+aW9uIHVuZCBQb3N0MSEwDAYHAoIGAQoHFBMBMTARBgNVBAMUCjVSLUNBIDE6UE4w
+IhgPMjAwMDAzMjIwODU1NTFaGA8yMDA1MDMyMjA4NTU1MVowbzELMAkGA1UEBhMC
+REUxPTA7BgNVBAoUNFJlZ3VsaWVydW5nc2JlaMhvcmRlIGbIdXIgVGVsZWtvbW11
+bmlrYXRpb24gdW5kIFBvc3QxITAMBgcCggYBCgcUEwExMBEGA1UEAxQKNVItQ0Eg
+MTpQTjCBoTANBgkqhkiG9w0BAQEFAAOBjwAwgYsCgYEAih5BUycfBpqKhU8RDsaS
+vV5AtzWeXQRColL9CH3t0DKnhjKAlJ8iccFtJNv+d3bh8bb9sh0maRSo647xP7hs
+HTjKgTE4zM5BYNfXvST79OtcMgAzrnDiGjQIIWv8xbfV1MqxxdtZJygrwzRMb9jG
+CAGoJEymoyzAMNG7tSdBWnUCBQDAAAABoxIwEDAOBgNVHQ8BAf8EBAMCAQYwCgYG
+KyQDAwECBQADgYEAOaK8ihVSBUcL2IdVBxZYYUKwMz5m7H3zqhN8W9w+iafWudH6
+b+aahkbENEwzg3C3v5g8nze7v7ssacQze657LHjP+e7ksUDIgcS4R1pU2eN16bjS
+P/qGPF3rhrIEHoK5nJULkjkZYTtNiOvmQ/+G70TXDi3Os/TwLlWRvu+7YLM=
+-----END CERTIFICATE-----
diff -Naur -X symlinks openssl-0.9.8o.orig/certs/RegTP-6R.pem openssl-0.9.8o/certs/RegTP-6R.pem
--- openssl-0.9.8o.orig/certs/RegTP-6R.pem	1969-12-31 19:00:00.000000000 -0500
+++ openssl-0.9.8o/certs/RegTP-6R.pem	2010-09-22 15:26:59.433377232 -0400
@@ -0,0 +1,19 @@
+issuer= CN=6R-Ca 1:PN+0.2.262.1.10.7.20=#130131,O=Regulierungsbeh\C3\88orde f\C3\88ur Telekommunikation und Post,C=DE
+notBefore=Feb  1 09:52:17 2001 GMT
+notAfter=Jun  1 09:52:17 2005 GMT
+subject= CN=6R-Ca 1:PN+0.2.262.1.10.7.20=#130131,O=Regulierungsbeh\C3\88orde f\C3\88ur Telekommunikation und Post,C=DE
+-----BEGIN CERTIFICATE-----
+MIICaDCCAdSgAwIBAgIDMtGNMAoGBiskAwMBAgUAMG8xCzAJBgNVBAYTAkRFMT0w
+OwYDVQQKFDRSZWd1bGllcnVuZ3NiZWjIb3JkZSBmyHVyIFRlbGVrb21tdW5pa2F0
+aW9uIHVuZCBQb3N0MSEwDAYHAoIGAQoHFBMBMTARBgNVBAMUCjZSLUNhIDE6UE4w
+IhgPMjAwMTAyMDEwOTUyMTdaGA8yMDA1MDYwMTA5NTIxN1owbzELMAkGA1UEBhMC
+REUxPTA7BgNVBAoUNFJlZ3VsaWVydW5nc2JlaMhvcmRlIGbIdXIgVGVsZWtvbW11
+bmlrYXRpb24gdW5kIFBvc3QxITAMBgcCggYBCgcUEwExMBEGA1UEAxQKNlItQ2Eg
+MTpQTjCBoTANBgkqhkiG9w0BAQEFAAOBjwAwgYsCgYEAg6KrFSTNXKqe+2GKGeW2
+wTmbVeflNkp5H/YxA9K1zmEn5XjKm0S0jH4Wfms6ipPlURVaFwTfnB1s++AnJAWf
+mayaE9BP/pdIY6WtZGgW6aZc32VDMCMKPWyBNyagsJVDmzlakIA5cXBVa7Xqqd3P
+ew8i2feMnQXcqHfDv02CW88CBQDAAAABoxIwEDAOBgNVHQ8BAf8EBAMCAQYwCgYG
+KyQDAwECBQADgYEAOkqkUwdaTCt8wcJLA2zLuOwL5ADHMWLhv6gr5zEF+VckA6qe
+IVLVf8e7fYlRmzQd+5OJcGglCQJLGT+ZplI3Mjnrd4plkoTNKV4iOzBcvJD7K4tn
+XPvs9wCFcC7QU7PLvc1FDsAlr7e4wyefZRDL+wbqNfI7QZTSF1ubLd9AzeQ=
+-----END CERTIFICATE-----
diff -Naur -X symlinks openssl-0.9.8o.orig/certs/thawteCb.pem openssl-0.9.8o/certs/thawteCb.pem
--- openssl-0.9.8o.orig/certs/thawteCb.pem	1969-12-31 19:00:00.000000000 -0500
+++ openssl-0.9.8o/certs/thawteCb.pem	2010-09-22 15:26:59.433377232 -0400
@@ -0,0 +1,19 @@
+-----BEGIN CERTIFICATE-----
+MIIDEzCCAnygAwIBAgIBATANBgkqhkiG9w0BAQQFADCBxDELMAkGA1UEBhMCWkEx
+FTATBgNVBAgTDFdlc3Rlcm4gQ2FwZTESMBAGA1UEBxMJQ2FwZSBUb3duMR0wGwYD
+VQQKExRUaGF3dGUgQ29uc3VsdGluZyBjYzEoMCYGA1UECxMfQ2VydGlmaWNhdGlv
+biBTZXJ2aWNlcyBEaXZpc2lvbjEZMBcGA1UEAxMQVGhhd3RlIFNlcnZlciBDQTEm
+MCQGCSqGSIb3DQEJARYXc2VydmVyLWNlcnRzQHRoYXd0ZS5jb20wHhcNOTYwODAx
+MDAwMDAwWhcNMjAxMjMxMjM1OTU5WjCBxDELMAkGA1UEBhMCWkExFTATBgNVBAgT
+DFdlc3Rlcm4gQ2FwZTESMBAGA1UEBxMJQ2FwZSBUb3duMR0wGwYDVQQKExRUaGF3
+dGUgQ29uc3VsdGluZyBjYzEoMCYGA1UECxMfQ2VydGlmaWNhdGlvbiBTZXJ2aWNl
+cyBEaXZpc2lvbjEZMBcGA1UEAxMQVGhhd3RlIFNlcnZlciBDQTEmMCQGCSqGSIb3
+DQEJARYXc2VydmVyLWNlcnRzQHRoYXd0ZS5jb20wgZ8wDQYJKoZIhvcNAQEBBQAD
+gY0AMIGJAoGBANOkUG7I/1Zr5s9dtuoMaHVHoqrC2oQl/Kj0R1HahbUgdJSGHg91
+yekIYfUGbTBuFRkC6VLAYttNmZ7iagxEOM3+vuNkCXDF/rFrKbYvScg71CcEJRCX
+L+eQbcAoQpnXTEPew/UhbVSfXcNY4cDk2VuwuNy0e982OsK1ZiIS1ocNAgMBAAGj
+EzARMA8GA1UdEwEB/wQFMAMBAf8wDQYJKoZIhvcNAQEEBQADgYEAB/pMaVz7lcxG
+7oWDTSEwjsrZqG9JGubaUeNgcGyEYRGhGshIPllDfU+VPaGLtwtimHp1it2ITk6e
+QNuozDJ0uW8NxuOzRAvZim+aKZuZGCg70eNAKJpaPNW15yAbi8qkq43pUdniTCxZ
+qdq5snUb9kLy78fyGPmJvKP/iiMucEc=
+-----END CERTIFICATE-----
diff -Naur -X symlinks openssl-0.9.8o.orig/certs/thawteCp.pem openssl-0.9.8o/certs/thawteCp.pem
--- openssl-0.9.8o.orig/certs/thawteCp.pem	1969-12-31 19:00:00.000000000 -0500
+++ openssl-0.9.8o/certs/thawteCp.pem	2010-09-22 15:26:59.433377232 -0400
@@ -0,0 +1,19 @@
+-----BEGIN CERTIFICATE-----
+MIIDJzCCApCgAwIBAgIBATANBgkqhkiG9w0BAQQFADCBzjELMAkGA1UEBhMCWkEx
+FTATBgNVBAgTDFdlc3Rlcm4gQ2FwZTESMBAGA1UEBxMJQ2FwZSBUb3duMR0wGwYD
+VQQKExRUaGF3dGUgQ29uc3VsdGluZyBjYzEoMCYGA1UECxMfQ2VydGlmaWNhdGlv
+biBTZXJ2aWNlcyBEaXZpc2lvbjEhMB8GA1UEAxMYVGhhd3RlIFByZW1pdW0gU2Vy
+dmVyIENBMSgwJgYJKoZIhvcNAQkBFhlwcmVtaXVtLXNlcnZlckB0aGF3dGUuY29t
+MB4XDTk2MDgwMTAwMDAwMFoXDTIwMTIzMTIzNTk1OVowgc4xCzAJBgNVBAYTAlpB
+MRUwEwYDVQQIEwxXZXN0ZXJuIENhcGUxEjAQBgNVBAcTCUNhcGUgVG93bjEdMBsG
+A1UEChMUVGhhd3RlIENvbnN1bHRpbmcgY2MxKDAmBgNVBAsTH0NlcnRpZmljYXRp
+b24gU2VydmljZXMgRGl2aXNpb24xITAfBgNVBAMTGFRoYXd0ZSBQcmVtaXVtIFNl
+cnZlciBDQTEoMCYGCSqGSIb3DQEJARYZcHJlbWl1bS1zZXJ2ZXJAdGhhd3RlLmNv
+bTCBnzANBgkqhkiG9w0BAQEFAAOBjQAwgYkCgYEA0jY2aovXwlue2oFBYo847kkE
+VdbQ7xwblRZH7xhINTpS9CtqBo87L+pW46+GjZ4X9560ZXUCTe/LCaIhUdib0GfQ
+ug2SBhRz1JPLlyoAnFxODLz6FVL88kRu2hFKbgifLy3j+ao6hnO2RlNYyIkFvYMR
+uHM/qgeN9EJN50CdHDcCAwEAAaMTMBEwDwYDVR0TAQH/BAUwAwEB/zANBgkqhkiG
+9w0BAQQFAAOBgQAmSCwWwlj66BZ0DKqqX1Q/8tfJeGBeXm43YyJ3Nn6yF8Q0ufUI
+hfzJATj/Tb7yFkJD57taRvvBxhEf8UqwKEbJw8RCfbz6q1lu1bdRiBHjpIUZa4JM
+pAwSremkrj/xw0llmozFyD4lt5SZu5IycQfwhl7tUCemDaYj+bvLpgcUQg==
+-----END CERTIFICATE-----
diff -Naur -X symlinks openssl-0.9.8o.orig/certs/vsign1.pem openssl-0.9.8o/certs/vsign1.pem
--- openssl-0.9.8o.orig/certs/vsign1.pem	1969-12-31 19:00:00.000000000 -0500
+++ openssl-0.9.8o/certs/vsign1.pem	2010-09-22 15:26:59.433377232 -0400
@@ -0,0 +1,17 @@
+subject=/C=US/O=VeriSign, Inc./OU=Class 1 Public Primary Certification Authority
+notBefore=Jan 29 00:00:00 1996 GMT
+notAfter=Jan  7 23:59:59 2020 GMT
+-----BEGIN CERTIFICATE-----
+MIICPDCCAaUCEDJQM89Q0VbzXIGtZVxPyCUwDQYJKoZIhvcNAQECBQAwXzELMAkG
+A1UEBhMCVVMxFzAVBgNVBAoTDlZlcmlTaWduLCBJbmMuMTcwNQYDVQQLEy5DbGFz
+cyAxIFB1YmxpYyBQcmltYXJ5IENlcnRpZmljYXRpb24gQXV0aG9yaXR5MB4XDTk2
+MDEyOTAwMDAwMFoXDTIwMDEwNzIzNTk1OVowXzELMAkGA1UEBhMCVVMxFzAVBgNV
+BAoTDlZlcmlTaWduLCBJbmMuMTcwNQYDVQQLEy5DbGFzcyAxIFB1YmxpYyBQcmlt
+YXJ5IENlcnRpZmljYXRpb24gQXV0aG9yaXR5MIGfMA0GCSqGSIb3DQEBAQUAA4GN
+ADCBiQKBgQDlGb9to1ZhLZlIcfZn3rmN67eehoAKkQ76OCWvRoiC5XOooJskXQ0f
+zGVuDLDQVoQYh5oGmxChc9+0WDlrbsH2FdWoqD+qEgaNMax/sDTXjzRniAnNFBHi
+TkVWaR94AoDa3EeRKbs2yWNcxeDXLYd7obcysHswuiovMaruo2fa2wIDAQABMA0G
+CSqGSIb3DQEBAgUAA4GBAEtEZmBoZOSYG/OwcuaViXzde7OVwB0u2NgZ0C00PcZQ
+mhCGjKo/O6gE/DdSlcPZydvN8oYGxLEb8IKIMEKOF1AcZHq4PplJdJf8rAJD+5YM
+VgQlDHx8h50kp9jwMim1pN9dokzFFjKoQvZFprY2ueC/ZTaTwtLXa9zeWdaiNfhF
+-----END CERTIFICATE-----
diff -Naur -X symlinks openssl-0.9.8o.orig/certs/vsign3.pem openssl-0.9.8o/certs/vsign3.pem
--- openssl-0.9.8o.orig/certs/vsign3.pem	1969-12-31 19:00:00.000000000 -0500
+++ openssl-0.9.8o/certs/vsign3.pem	2010-09-22 15:26:59.433377232 -0400
@@ -0,0 +1,17 @@
+subject=/C=US/O=VeriSign, Inc./OU=Class 3 Public Primary Certification Authority
+notBefore=Jan 29 00:00:00 1996 GMT
+notAfter=Aug  1 23:59:59 2028 GMT
+-----BEGIN CERTIFICATE-----
+MIICPDCCAaUCEHC65B0Q2Sk0tjjKewPMur8wDQYJKoZIhvcNAQECBQAwXzELMAkG
+A1UEBhMCVVMxFzAVBgNVBAoTDlZlcmlTaWduLCBJbmMuMTcwNQYDVQQLEy5DbGFz
+cyAzIFB1YmxpYyBQcmltYXJ5IENlcnRpZmljYXRpb24gQXV0aG9yaXR5MB4XDTk2
+MDEyOTAwMDAwMFoXDTI4MDgwMTIzNTk1OVowXzELMAkGA1UEBhMCVVMxFzAVBgNV
+BAoTDlZlcmlTaWduLCBJbmMuMTcwNQYDVQQLEy5DbGFzcyAzIFB1YmxpYyBQcmlt
+YXJ5IENlcnRpZmljYXRpb24gQXV0aG9yaXR5MIGfMA0GCSqGSIb3DQEBAQUAA4GN
+ADCBiQKBgQDJXFme8huKARS0EN8EQNvjV69qRUCPhAwL0TPZ2RHP7gJYHyX3KqhE
+BarsAx94f56TuZoAqiN91qyFomNFx3InzPRMxnVx0jnvT0Lwdd8KkMaOIG+YD/is
+I19wKTakyYbnsZogy1Olhec9vn2a/iRFM9x2Fe0PonFkTGUugWhFpwIDAQABMA0G
+CSqGSIb3DQEBAgUAA4GBALtMEivPLCYATxQT3ab7/AoRhIzzKBxnki98tsX63/Do
+lbwdj2wsqFHMc9ikwFPwTtYmwHYBV4GSXiHx0bH/59AhWM1pF+NEHJwZRDmJXNyc
+AA9WjQKZ7aKQRUzkuxCkPfAyAw7xzvjoyVGM5mKf5p/AfbdynMk2OmufTqj/ZA1k
+-----END CERTIFICATE-----
diff -Naur -X symlinks openssl-0.9.8o.orig/certs/vsignss.pem openssl-0.9.8o/certs/vsignss.pem
--- openssl-0.9.8o.orig/certs/vsignss.pem	1969-12-31 19:00:00.000000000 -0500
+++ openssl-0.9.8o/certs/vsignss.pem	2010-09-22 15:26:59.433377232 -0400
@@ -0,0 +1,17 @@
+subject=/C=US/O=RSA Data Security, Inc./OU=Secure Server Certification Authority
+notBefore=Nov  9 00:00:00 1994 GMT
+notAfter=Jan  7 23:59:59 2010 GMT
+-----BEGIN CERTIFICATE-----
+MIICNDCCAaECEAKtZn5ORf5eV288mBle3cAwDQYJKoZIhvcNAQECBQAwXzELMAkG
+A1UEBhMCVVMxIDAeBgNVBAoTF1JTQSBEYXRhIFNlY3VyaXR5LCBJbmMuMS4wLAYD
+VQQLEyVTZWN1cmUgU2VydmVyIENlcnRpZmljYXRpb24gQXV0aG9yaXR5MB4XDTk0
+MTEwOTAwMDAwMFoXDTEwMDEwNzIzNTk1OVowXzELMAkGA1UEBhMCVVMxIDAeBgNV
+BAoTF1JTQSBEYXRhIFNlY3VyaXR5LCBJbmMuMS4wLAYDVQQLEyVTZWN1cmUgU2Vy
+dmVyIENlcnRpZmljYXRpb24gQXV0aG9yaXR5MIGbMA0GCSqGSIb3DQEBAQUAA4GJ
+ADCBhQJ+AJLOesGugz5aqomDV6wlAXYMra6OLDfO6zV4ZFQD5YRAUcm/jwjiioII
+0haGN1XpsSECrXZogZoFokvJSyVmIlZsiAeP94FZbYQHZXATcXY+m3dM41CJVphI
+uR2nKRoTLkoRWZweFdVJVCxzOmmCsZc5nG1wZ0jl3S3WyB57AgMBAAEwDQYJKoZI
+hvcNAQECBQADfgBl3X7hsuyw4jrg7HFGmhkRuNPHoLQDQCYCPgmc4RKz0Vr2N6W3
+YQO2WxZpO8ZECAyIUwxrl0nHPjXcbLm7qt9cuzovk2C2qUtN8iD3zV9/ZHuO3ABc
+1/p3yjkWWW8O6tO1g39NTUJWdrTJXwT4OPjr0l91X817/OWOgHz8UA==
+-----END CERTIFICATE-----
diff -Naur -X symlinks openssl-0.9.8o.orig/certs/wellsfgo.pem openssl-0.9.8o/certs/wellsfgo.pem
--- openssl-0.9.8o.orig/certs/wellsfgo.pem	1969-12-31 19:00:00.000000000 -0500
+++ openssl-0.9.8o/certs/wellsfgo.pem	2010-09-22 15:26:59.433377232 -0400
@@ -0,0 +1,23 @@
+-----BEGIN CERTIFICATE-----
+MIID5TCCAs2gAwIBAgIEOeSXnjANBgkqhkiG9w0BAQUFADCBgjELMAkGA1UEBhMC
+VVMxFDASBgNVBAoTC1dlbGxzIEZhcmdvMSwwKgYDVQQLEyNXZWxscyBGYXJnbyBD
+ZXJ0aWZpY2F0aW9uIEF1dGhvcml0eTEvMC0GA1UEAxMmV2VsbHMgRmFyZ28gUm9v
+dCBDZXJ0aWZpY2F0ZSBBdXRob3JpdHkwHhcNMDAxMDExMTY0MTI4WhcNMjEwMTE0
+MTY0MTI4WjCBgjELMAkGA1UEBhMCVVMxFDASBgNVBAoTC1dlbGxzIEZhcmdvMSww
+KgYDVQQLEyNXZWxscyBGYXJnbyBDZXJ0aWZpY2F0aW9uIEF1dGhvcml0eTEvMC0G
+A1UEAxMmV2VsbHMgRmFyZ28gUm9vdCBDZXJ0aWZpY2F0ZSBBdXRob3JpdHkwggEi
+MA0GCSqGSIb3DQEBAQUAA4IBDwAwggEKAoIBAQDVqDM7Jvk0/82bfuUER84A4n13
+5zHCLielTWi5MbqNQ1mXx3Oqfz1cQJ4F5aHiidlMuD+b+Qy0yGIZLEWukR5zcUHE
+SxP9cMIlrCL1dQu3U+SlK93OvRw6esP3E48mVJwWa2uv+9iWsWCaSOAlIiR5NM4O
+JgALTqv9i86C1y8IcGjBqAr5dE8Hq6T54oN+J3N0Prj5OEL8pahbSCOz6+MlsoCu
+ltQKnMJ4msZoGK43YjdeUXWoWGPAUe5AeH6orxqg4bB4nVCMe+ez/I4jsNtlAHCE
+AQgAFG5Uhpq6zPk3EPbg3oQtnaSFN9OH4xXQwReQfhkhahKpdv0SAulPIV4XAgMB
+AAGjYTBfMA8GA1UdEwEB/wQFMAMBAf8wTAYDVR0gBEUwQzBBBgtghkgBhvt7hwcB
+CzAyMDAGCCsGAQUFBwIBFiRodHRwOi8vd3d3LndlbGxzZmFyZ28uY29tL2NlcnRw
+b2xpY3kwDQYJKoZIhvcNAQEFBQADggEBANIn3ZwKdyu7IvICtUpKkfnRLb7kuxpo
+7w6kAOnu5+/u9vnldKTC2FJYxHT7zmu1Oyl5GFrvm+0fazbuSCUlFLZWohDo7qd/
+0D+j0MNdJu4HzMPBJCGHHt8qElNvQRbn7a6U+oxy+hNH8Dx+rn0ROhPs7fpvcmR7
+nX1/Jv16+yWt6j4pf0zjAFcysLPp7VMX2YuyFA4w6OXVE8Zkr8QA1dhYJPz1j+zx
+x32l2w8n0cbyQIjmH/ZhqPRCyLk306m+LFZ4wnKbWV01QIroTmMatukgalHizqSQ
+33ZwmVxwQ023tqcZZE6St8WRPH9IFmV7Fv3L/PvZ1dZPIWU7Sn9Ho/s=
+-----END CERTIFICATE-----
diff -Naur -X symlinks openssl-0.9.8o.orig/CHANGES.RMISEC openssl-0.9.8o/CHANGES.RMISEC
--- openssl-0.9.8o.orig/CHANGES.RMISEC	1969-12-31 19:00:00.000000000 -0500
+++ openssl-0.9.8o/CHANGES.RMISEC	2010-09-22 15:26:59.433377232 -0400
@@ -0,0 +1,29 @@
+openssl and crypto driver in release R095
+~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+
+Bug fixes :
+
+    * the L2 bits were not set by the crypto driver, resulting is low
+      performance for all the encryptions and authentications
+    * the crypto driver was looping for the response to an rsa operation
+      from the security engine instead of sleeping 
+
+New features :
+
+    * add support for hardware acceleration of aes192, sha256, rc4, dsa512,
+      dsa1024 to the crypto library and openssl
+    * move to the latest openssl, which supports sha256, sha512, ecdsa, ecdh,
+      dynamic engines and in some cases a faster
+    * modify openssl to support our engine as a dynamic engine dyn_rmisec.so
+      (dynamic engines are a new feature of openssl, providing dyn_rmisec.so is
+      now sufficient, it is no longer necessary to provide a patch to openssl)
+    * adapt the crypto driver to linux 2.6.16, the accelaration of linux ipsec
+      was lost within linux (linux kernel support for hardware acceleration of
+      ipsec is broken)
+    * update the documentation of openssl and the crypto driver 
+
+Performance improvements :
+
+    * the L2 bits bug fix results in significantly higher performance for all
+      the encryptions and authentications
+    * rsa performance is 1/3 higher for verify operations with latest openssl 
diff -Naur -X symlinks openssl-0.9.8o.orig/crypto/ec/ec_curve.c openssl-0.9.8o/crypto/ec/ec_curve.c
--- openssl-0.9.8o.orig/crypto/ec/ec_curve.c	2010-09-07 16:38:50.157699768 -0400
+++ openssl-0.9.8o/crypto/ec/ec_curve.c	2010-09-22 15:26:59.433377232 -0400
@@ -1032,6 +1032,91 @@
 	"\tNot suitable for ECDSA.\n\tQuestionable extension field!"
 	};
 
+static const EC_CURVE_DATA _EC_BRAINPOOL_P160R1 = {
+        NID_X9_62_prime_field,
+        "E95E4A5F737059DC60DFC7AD95B3D8139515620F",
+        "340E7BE2A280EB74E2BE61BADA745D97E8F7C300",
+        "1E589A8595423412134FAA2DBDEC95C8D8675E58",
+        "BED5AF16EA3F6A4F62938C4631EB5AF7BDBCDBC3",
+        "1667CB477A1A8EC338F94741669C976316DA6321",
+        "E95E4A5F737059DC60DF5991D45029409E60FC09",1,
+        NULL, 0,
+        "brainpoolP160r1"
+        };
+
+static const EC_CURVE_DATA _EC_BRAINPOOL_P192R1 = {
+        NID_X9_62_prime_field,
+        "C302F41D932A36CDA7A3463093D18DB78FCE476DE1A86297",
+        "6A91174076B1E0E19C39C031FE8685C1CAE040E5C69A28EF",
+        "469A28EF7C28CCA3DC721D044F4496BCCA7EF4146FBF25C9",
+        "C0A0647EAAB6A48753B033C56CB0F0900A2F5C4853375FD6",
+        "14B690866ABD5BB88B5F4828C1490002E6773FA2FA299B8F",
+        "C302F41D932A36CDA7A3462F9E9E916B5BE8F1029AC4ACC1",1,
+        NULL, 0,
+        "brainpoolP192r1"
+        };
+
+static const EC_CURVE_DATA _EC_BRAINPOOL_P224R1 = {
+        NID_X9_62_prime_field,
+        "D7C134AA264366862A18302575D1D787B09F075797DA89F57EC8C0FF",
+        "68A5E62CA9CE6C1C299803A6C1530B514E182AD8B0042A59CAD29F43",
+        "2580F63CCFE44138870713B1A92369E33E2135D266DBB372386C400B",
+        "D9029AD2C7E5CF4340823B2A87DC68C9E4CE3174C1E6EFDEE12C07D",
+        "58AA56F772C0726F24C6B89E4ECDAC24354B9E99CAA3F6D3761402CD",
+        "D7C134AA264366862A18302575D0FB98D116BC4B6DDEBCA3A5A7939F",1,
+        NULL, 0,
+        "brainpoolP224r1"
+        };
+
+static const EC_CURVE_DATA _EC_BRAINPOOL_P256R1 = {
+        NID_X9_62_prime_field,
+        "A9FB57DBA1EEA9BC3E660A909D838D726E3BF623D52620282013481D1F6E5377",
+        "7D5A0975FC2C3057EEF67530417AFFE7FB8055C126DC5C6CE94A4B44F330B5D9",
+        "26DC5C6CE94A4B44F330B5D9BBD77CBF958416295CF7E1CE6BCCDC18FF8C07B6",
+        "8BD2AEB9CB7E57CB2C4B482FFC81B7AFB9DE27E1E3BD23C23A4453BD9ACE3262",
+        "547EF835C3DAC4FD97F8461A14611DC9C27745132DED8E545C1D54C72F046997",
+        "A9FB57DBA1EEA9BC3E660A909D838D718C397AA3B561A6F7901E0E82974856A7",1,
+        NULL, 0,
+        "brainpoolP256r1"
+        };
+
+static const EC_CURVE_DATA _EC_BRAINPOOL_P384R1 = {
+        NID_X9_62_prime_field,
+        "8CB91E82A3386D280F5D6F7E50E641DF152F7109ED5456B412B1DA197FB71123ACD3A729901D1A71874700133107EC53",
+        "7BC382C63D8C150C3C72080ACE05AFA0C2BEA28E4FB22787139165EFBA91F90F8AA5814A503AD4EB04A8C7DD22CE2826",
+        "4A8C7DD22CE28268B39B55416F0447C2FB77DE107DCD2A62E880EA53EEB62D57CB4390295DBC9943AB78696FA504C11",
+        "1D1C64F068CF45FFA2A63A81B7C13F6B8847A3E77EF14FE3DB7FCAFE0CBD10E8E826E03436D646AAEF87B2E247D4AF1E",
+        "8ABE1D7520F9C2A45CB1EB8E95CFD55262B70B29FEEC5864E19C054FF99129280E4646217791811142820341263C5315",
+        "8CB91E82A3386D280F5D6F7E50E641DF152F7109ED5456B31F166E6CAC0425A7CF3AB6AF6B7FC3103B883202E9046565",1,
+        NULL, 0,
+        "brainpoolP384r1"
+        };
+
+static const EC_CURVE_DATA _EC_NIST_PRIME_512 = {
+        NID_X9_62_prime_field,
+        "AADD9DB8DBE9C48B3FD4E6AE33C9FC07CB308DB3B3C9D20ED6639CCA703308717D4D9B009BC66842AECDA12AE6A380E62881FF2F2D82C68528AA6056583A48F3",
+        "7830A3318B603B89E2327145AC234CC594CBDD8D3DF91610A83441CAEA9863BC2DED5D5AA8253AA10A2EF1C98B9AC8B57F1117A72BF2C7B9E7C1AC4D77FC94CA",
+        "3DF91610A83441CAEA9863BC2DED5D5AA8253AA10A2EF1C98B9AC8B57F1117A72BF2C7B9E7C1AC4D77FC94CADC083E67984050B75EBAE5DD2809BD638016F723",
+        "81AEE4BDD82ED9645A21322E9C4C6A9385ED9F70B5D916C1B43B62EEF4D0098EFF3B1F78E2D0D48D50D1687B93B97D5F7C6D5047406A5E688B352209BCB9F822",
+        "7DDE385D566332ECC0EABFA9CF7822FDF209F70024A57B1AA000C55B881F8111B2DCDE494A5F485E5BCA4BD88A2763AED1CA2B2FA8F0540678CD1E0F3AD80892",
+        "AADD9DB8DBE9C48B3FD4E6AE33C9FC07CB308DB3B3C9D20ED6639CCA70330870553E5C414CA92619418661197FAC10471DB1D381085DDADDB58796829CA90069",1,
+        NULL, 0,
+        "NIST/SECG curve over a 512 bit prime field"
+        };
+
+static const EC_CURVE_DATA _EC_BRAINPOOL_P512R1 = {
+        NID_X9_62_prime_field,
+        "AADD9DB8DBE9C48B3FD4E6AE33C9FC07CB308DB3B3C9D20ED6639CCA703308717D4D9B009BC66842AECDA12AE6A380E62881FF2F2D82C68528AA6056583A48F3",
+        "7830A3318B603B89E2327145AC234CC594CBDD8D3DF91610A83441CAEA9863BC2DED5D5AA8253AA10A2EF1C98B9AC8B57F1117A72BF2C7B9E7C1AC4D77FC94CA",
+        "3DF91610A83441CAEA9863BC2DED5D5AA8253AA10A2EF1C98B9AC8B57F1117A72BF2C7B9E7C1AC4D77FC94CADC083E67984050B75EBAE5DD2809BD638016F723",
+        "81AEE4BDD82ED9645A21322E9C4C6A9385ED9F70B5D916C1B43B62EEF4D0098EFF3B1F78E2D0D48D50D1687B93B97D5F7C6D5047406A5E688B352209BCB9F822",
+        "7DDE385D566332ECC0EABFA9CF7822FDF209F70024A57B1AA000C55B881F8111B2DCDE494A5F485E5BCA4BD88A2763AED1CA2B2FA8F0540678CD1E0F3AD80892",
+        "AADD9DB8DBE9C48B3FD4E6AE33C9FC07CB308DB3B3C9D20ED6639CCA70330870553E5C414CA92619418661197FAC10471DB1D381085DDADDB58796829CA90069",1,
+        NULL, 0,
+        "brainpoolP512r1"
+        };
+
+
 typedef struct _ec_list_element_st {
 	int	nid;
 	const EC_CURVE_DATA *data;
@@ -1116,6 +1201,13 @@
 	/* IPSec curves */
 	{ NID_ipsec3, &_EC_IPSEC_155_ID3},
 	{ NID_ipsec4, &_EC_IPSEC_185_ID4},
+        { NID_brap160r1, &_EC_BRAINPOOL_P160R1},
+        { NID_brap192r1, &_EC_BRAINPOOL_P192R1},
+        { NID_brap224r1, &_EC_BRAINPOOL_P224R1},
+        { NID_brap256r1, &_EC_BRAINPOOL_P256R1},
+        { NID_brap384r1, &_EC_BRAINPOOL_P384R1},
+        { NID_secp512r1, &_EC_NIST_PRIME_512},
+        { NID_brap512r1, &_EC_BRAINPOOL_P512R1},
 };
 
 static size_t curve_list_length = sizeof(curve_list)/sizeof(ec_list_element);
diff -Naur -X symlinks openssl-0.9.8o.orig/crypto/ec/ec_cvt.c openssl-0.9.8o/crypto/ec/ec_cvt.c
--- openssl-0.9.8o.orig/crypto/ec/ec_cvt.c	2010-09-07 16:38:50.157699768 -0400
+++ openssl-0.9.8o/crypto/ec/ec_cvt.c	2010-09-22 15:26:59.433377232 -0400
@@ -71,15 +71,23 @@
 
 #include <openssl/err.h>
 #include "ec_lcl.h"
-
+#ifndef OPENSSL_NO_ENGINE
+#include <openssl/engine.h>
+#endif
 
 EC_GROUP *EC_GROUP_new_curve_GFp(const BIGNUM *p, const BIGNUM *a, const BIGNUM *b, BN_CTX *ctx)
 	{
 	const EC_METHOD *meth;
 	EC_GROUP *ret;
 
+#ifndef OPENSSL_NO_ENGINE
+	ENGINE *engine;
+	if ( !(engine = ENGINE_get_default_EC()) ||
+	     !(meth = ENGINE_get_EC_GFp_nist(engine)))
 	meth = EC_GFp_nist_method();
-	
+#else /* OPENSSL_NO_ENGINE */
+	meth = EC_GFp_nist_method();
+#endif /* OPENSSL_NO_ENGINE */
 	ret = EC_GROUP_new(meth);
 	if (ret == NULL)
 		return NULL;
@@ -106,7 +114,12 @@
 		ERR_clear_error();
 
 		EC_GROUP_clear_free(ret);
+#ifndef OPENSSL_NO_ENGINE
+		if (!engine || !(meth = ENGINE_get_EC_GFp_mont(engine)))
+		meth = EC_GFp_mont_method();
+#else
 		meth = EC_GFp_mont_method();
+#endif
 
 		ret = EC_GROUP_new(meth);
 		if (ret == NULL)
@@ -128,7 +141,14 @@
 	const EC_METHOD *meth;
 	EC_GROUP *ret;
 	
+#ifndef OPENSSL_NO_ENGINE
+	ENGINE *engine;
+	if ( !(engine = ENGINE_get_default_EC()) ||
+	     !(meth = ENGINE_get_EC_GF2m_simple(engine)))
+		meth = EC_GF2m_simple_method();
+#else
 	meth = EC_GF2m_simple_method();
+#endif
 	
 	ret = EC_GROUP_new(meth);
 	if (ret == NULL)
diff -Naur -X symlinks openssl-0.9.8o.orig/crypto/ec/ec_lcl.h openssl-0.9.8o/crypto/ec/ec_lcl.h
--- openssl-0.9.8o.orig/crypto/ec/ec_lcl.h	2010-09-07 16:38:50.127698906 -0400
+++ openssl-0.9.8o/crypto/ec/ec_lcl.h	2010-09-22 15:26:59.433377232 -0400
@@ -227,6 +227,7 @@
 	void *field_data1; /* method-specific (e.g., Montgomery structure) */
 	void *field_data2; /* method-specific */
 	int (*field_mod_func)(BIGNUM *, const BIGNUM *, const BIGNUM *,	BN_CTX *); /* method-specific */
+	BIGNUM con2k;
 } /* EC_GROUP */;
 
 struct ec_key_st {
diff -Naur -X symlinks openssl-0.9.8o.orig/crypto/ec/ec_lib.c openssl-0.9.8o/crypto/ec/ec_lib.c
--- openssl-0.9.8o.orig/crypto/ec/ec_lib.c	2010-09-07 16:38:50.157699768 -0400
+++ openssl-0.9.8o/crypto/ec/ec_lib.c	2010-09-22 15:26:59.433377232 -0400
@@ -1118,11 +1118,15 @@
 int EC_POINTs_mul(const EC_GROUP *group, EC_POINT *r, const BIGNUM *scalar,
 	size_t num, const EC_POINT *points[], const BIGNUM *scalars[], BN_CTX *ctx)
 	{
+	int err;
+
 	if (group->meth->mul == 0)
 		/* use default */
-		return ec_wNAF_mul(group, r, scalar, num, points, scalars, ctx);
+		err = ec_wNAF_mul(group, r, scalar, num, points, scalars, ctx);
+	else
+		err = group->meth->mul(group, r, scalar, num, points, scalars, ctx);
 
-	return group->meth->mul(group, r, scalar, num, points, scalars, ctx);
+	return err;
 	}
 
 int EC_POINT_mul(const EC_GROUP *group, EC_POINT *r, const BIGNUM *g_scalar,
diff -Naur -X symlinks openssl-0.9.8o.orig/crypto/ec/ec_mult.c openssl-0.9.8o/crypto/ec/ec_mult.c
--- openssl-0.9.8o.orig/crypto/ec/ec_mult.c	2010-09-07 16:38:50.147700297 -0400
+++ openssl-0.9.8o/crypto/ec/ec_mult.c	2010-09-22 15:26:59.433377232 -0400
@@ -335,6 +335,8 @@
 		  (b) >=   20 ? 2 : \
 		  1))
 
+void print_ec_point(const EC_POINT *r);
+
 /* Compute
  *      \sum scalars[i]*points[i],
  * also including
@@ -639,6 +641,7 @@
 			for (j = 1; j < (1u << (wsize[i] - 1)); j++)
 				{
 				if (!EC_POINT_add(group, val_sub[i][j], val_sub[i][j - 1], tmp, ctx)) goto err;
+
 				}
 			}
 		}
diff -Naur -X symlinks openssl-0.9.8o.orig/crypto/ec/ecp_smpl.c openssl-0.9.8o/crypto/ec/ecp_smpl.c
--- openssl-0.9.8o.orig/crypto/ec/ecp_smpl.c	2010-09-07 16:38:50.157699768 -0400
+++ openssl-0.9.8o/crypto/ec/ecp_smpl.c	2010-09-22 15:26:59.433377232 -0400
@@ -132,6 +132,7 @@
 	BN_init(&group->field);
 	BN_init(&group->a);
 	BN_init(&group->b);
+	BN_init(&group->con2k);
 	group->a_is_minus3 = 0;
 	return 1;
 	}
@@ -142,6 +143,7 @@
 	BN_free(&group->field);
 	BN_free(&group->a);
 	BN_free(&group->b);
+	BN_free(&group->con2k);
 	}
 
 
@@ -150,6 +152,7 @@
 	BN_clear_free(&group->field);
 	BN_clear_free(&group->a);
 	BN_clear_free(&group->b);
+	BN_clear_free(&group->con2k);
 	}
 
 
@@ -158,6 +161,7 @@
 	if (!BN_copy(&dest->field, &src->field)) return 0;
 	if (!BN_copy(&dest->a, &src->a)) return 0;
 	if (!BN_copy(&dest->b, &src->b)) return 0;
+	if (!BN_copy(&dest->con2k, &src->con2k)) return 0;
 
 	dest->a_is_minus3 = src->a_is_minus3;
 
diff -Naur -X symlinks openssl-0.9.8o.orig/crypto/ec/Makefile openssl-0.9.8o/crypto/ec/Makefile
--- openssl-0.9.8o.orig/crypto/ec/Makefile	2010-09-07 16:38:50.127698906 -0400
+++ openssl-0.9.8o/crypto/ec/Makefile	2010-09-22 15:26:59.433377232 -0400
@@ -122,13 +122,18 @@
 ec_curve.o: ../../include/openssl/safestack.h ../../include/openssl/stack.h
 ec_curve.o: ../../include/openssl/symhacks.h ec_curve.c ec_lcl.h
 ec_cvt.o: ../../include/openssl/asn1.h ../../include/openssl/bio.h
-ec_cvt.o: ../../include/openssl/bn.h ../../include/openssl/crypto.h
-ec_cvt.o: ../../include/openssl/e_os2.h ../../include/openssl/ec.h
-ec_cvt.o: ../../include/openssl/err.h ../../include/openssl/lhash.h
-ec_cvt.o: ../../include/openssl/obj_mac.h ../../include/openssl/opensslconf.h
+ec_cvt.o: ../../include/openssl/bn.h ../../include/openssl/buffer.h
+ec_cvt.o: ../../include/openssl/crypto.h ../../include/openssl/e_os2.h
+ec_cvt.o: ../../include/openssl/ec.h ../../include/openssl/ecdh.h
+ec_cvt.o: ../../include/openssl/ecdsa.h ../../include/openssl/engine.h
+ec_cvt.o: ../../include/openssl/err.h ../../include/openssl/evp.h
+ec_cvt.o: ../../include/openssl/lhash.h ../../include/openssl/obj_mac.h
+ec_cvt.o: ../../include/openssl/objects.h ../../include/openssl/opensslconf.h
 ec_cvt.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h
-ec_cvt.o: ../../include/openssl/safestack.h ../../include/openssl/stack.h
-ec_cvt.o: ../../include/openssl/symhacks.h ec_cvt.c ec_lcl.h
+ec_cvt.o: ../../include/openssl/pkcs7.h ../../include/openssl/safestack.h
+ec_cvt.o: ../../include/openssl/sha.h ../../include/openssl/stack.h
+ec_cvt.o: ../../include/openssl/symhacks.h ../../include/openssl/x509.h
+ec_cvt.o: ../../include/openssl/x509_vfy.h ec_cvt.c ec_lcl.h
 ec_err.o: ../../include/openssl/asn1.h ../../include/openssl/bio.h
 ec_err.o: ../../include/openssl/crypto.h ../../include/openssl/e_os2.h
 ec_err.o: ../../include/openssl/ec.h ../../include/openssl/err.h
diff -Naur -X symlinks openssl-0.9.8o.orig/crypto/ecdsa/ecs_ossl.c openssl-0.9.8o/crypto/ecdsa/ecs_ossl.c
--- openssl-0.9.8o.orig/crypto/ecdsa/ecs_ossl.c	2010-09-07 16:38:50.017699286 -0400
+++ openssl-0.9.8o/crypto/ecdsa/ecs_ossl.c	2010-09-22 15:26:59.433377232 -0400
@@ -60,6 +60,19 @@
 #include <openssl/err.h>
 #include <openssl/obj_mac.h>
 #include <openssl/bn.h>
+#include "ec/ec_lcl.h"
+
+void print_ec_point(const EC_POINT *r)
+{
+	fprintf(stderr, "x=");
+	BN_print_fp(stderr, &r->X);
+	fprintf(stderr, "\ny=");
+	BN_print_fp(stderr, &r->Y);
+	fprintf(stderr, "\nz=");
+	BN_print_fp(stderr, &r->Z);
+	fprintf(stderr, "\n");
+	return;
+}
 
 static ECDSA_SIG *ecdsa_do_sign(const unsigned char *dgst, int dlen, 
 		const BIGNUM *, const BIGNUM *, EC_KEY *eckey);
diff -Naur -X symlinks openssl-0.9.8o.orig/crypto/ecdsa/ecs_vrf.c openssl-0.9.8o/crypto/ecdsa/ecs_vrf.c
--- openssl-0.9.8o.orig/crypto/ecdsa/ecs_vrf.c	2010-09-07 16:38:50.017699286 -0400
+++ openssl-0.9.8o/crypto/ecdsa/ecs_vrf.c	2010-09-22 15:26:59.433377232 -0400
@@ -87,9 +87,18 @@
 	int ret=-1;
 
 	s = ECDSA_SIG_new();
-	if (s == NULL) return(ret);
-	if (d2i_ECDSA_SIG(&s, &sigbuf, sig_len) == NULL) goto err;
+	if (s == NULL) {
+		printf("%s:%d s=NULL\n", __FUNCTION__, __LINE__);
+		return(ret);
+	}
+	if (d2i_ECDSA_SIG(&s, &sigbuf, sig_len) == NULL) {
+		printf("%s:%d\n", __FUNCTION__, __LINE__);
+		goto err;
+	}
 	ret=ECDSA_do_verify(dgst, dgst_len, s, eckey);
+	if(ret != 1) {
+		printf("%s:%d ret=%d\n", __FUNCTION__, __LINE__, ret);
+	}
 err:
 	ECDSA_SIG_free(s);
 	return(ret);
diff -Naur -X symlinks openssl-0.9.8o.orig/crypto/ecdsa/Makefile openssl-0.9.8o/crypto/ecdsa/Makefile
--- openssl-0.9.8o.orig/crypto/ecdsa/Makefile	2010-09-07 16:38:50.017699286 -0400
+++ openssl-0.9.8o/crypto/ecdsa/Makefile	2010-09-22 15:26:59.433377232 -0400
@@ -113,7 +113,8 @@
 ecs_ossl.o: ../../include/openssl/opensslconf.h
 ecs_ossl.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h
 ecs_ossl.o: ../../include/openssl/safestack.h ../../include/openssl/stack.h
-ecs_ossl.o: ../../include/openssl/symhacks.h ecs_locl.h ecs_ossl.c
+ecs_ossl.o: ../../include/openssl/symhacks.h ../ec/ec_lcl.h ecs_locl.h
+ecs_ossl.o: ecs_ossl.c
 ecs_sign.o: ../../include/openssl/asn1.h ../../include/openssl/bio.h
 ecs_sign.o: ../../include/openssl/buffer.h ../../include/openssl/crypto.h
 ecs_sign.o: ../../include/openssl/e_os2.h ../../include/openssl/ec.h
diff -Naur -X symlinks openssl-0.9.8o.orig/crypto/engine/eng_all.c openssl-0.9.8o/crypto/engine/eng_all.c
--- openssl-0.9.8o.orig/crypto/engine/eng_all.c	2010-09-07 16:38:50.557700334 -0400
+++ openssl-0.9.8o/crypto/engine/eng_all.c	2010-09-22 15:26:59.443387564 -0400
@@ -98,6 +98,9 @@
 #ifndef OPENSSL_NO_HW_UBSEC
 	ENGINE_load_ubsec();
 #endif
+#ifndef OPENSSL_NO_HW_RMISEC
+	ENGINE_load_rmisec();
+#endif
 #endif
 #if !defined(OPENSSL_NO_GMP) && !defined(OPENSSL_NO_HW_GMP)
 	ENGINE_load_gmp();
diff -Naur -X symlinks openssl-0.9.8o.orig/crypto/engine/eng_dyn.c openssl-0.9.8o/crypto/engine/eng_dyn.c
--- openssl-0.9.8o.orig/crypto/engine/eng_dyn.c	2010-09-07 16:38:50.537700408 -0400
+++ openssl-0.9.8o/crypto/engine/eng_dyn.c	2010-09-22 15:26:59.443387564 -0400
@@ -170,9 +170,9 @@
 		if(ctx->dynamic_dso)
 			DSO_free(ctx->dynamic_dso);
 		if(ctx->DYNAMIC_LIBNAME)
-			OPENSSL_free((void*)ctx->DYNAMIC_LIBNAME);
+			OPENSSL_free(ctx->DYNAMIC_LIBNAME);
 		if(ctx->engine_id)
-			OPENSSL_free((void*)ctx->engine_id);
+			OPENSSL_free(ctx->engine_id);
 		if(ctx->dirs)
 			sk_pop_free(ctx->dirs, int_free_str);
 		OPENSSL_free(ctx);
@@ -337,7 +337,7 @@
 		if(p && (strlen((const char *)p) < 1))
 			p = NULL;
 		if(ctx->DYNAMIC_LIBNAME)
-			OPENSSL_free((void*)ctx->DYNAMIC_LIBNAME);
+			OPENSSL_free(ctx->DYNAMIC_LIBNAME);
 		if(p)
 			ctx->DYNAMIC_LIBNAME = BUF_strdup(p);
 		else
@@ -351,7 +351,7 @@
 		if(p && (strlen((const char *)p) < 1))
 			p = NULL;
 		if(ctx->engine_id)
-			OPENSSL_free((void*)ctx->engine_id);
+			OPENSSL_free(ctx->engine_id);
 		if(p)
 			ctx->engine_id = BUF_strdup(p);
 		else
diff -Naur -X symlinks openssl-0.9.8o.orig/crypto/engine/eng_fat.c openssl-0.9.8o/crypto/engine/eng_fat.c
--- openssl-0.9.8o.orig/crypto/engine/eng_fat.c	2010-09-07 16:38:50.557700334 -0400
+++ openssl-0.9.8o/crypto/engine/eng_fat.c	2010-09-22 15:26:59.443387564 -0400
@@ -87,6 +87,10 @@
 	if((flags & ENGINE_METHOD_ECDSA) && !ENGINE_set_default_ECDSA(e))
 		return 0;
 #endif
+#ifndef OPENSSL_NO_EC
+        if((flags & ENGINE_METHOD_EC) && !ENGINE_set_default_EC(e))
+                return 0;
+#endif
 	if((flags & ENGINE_METHOD_RAND) && !ENGINE_set_default_RAND(e))
 		return 0;
 	return 1;
@@ -107,6 +111,8 @@
 		*pflags |= ENGINE_METHOD_ECDH;
 	else if (!strncmp(alg, "ECDSA", len))
 		*pflags |= ENGINE_METHOD_ECDSA;
+        else if (!strncmp(alg, "EC", len))
+                *pflags |= ENGINE_METHOD_EC;
 	else if (!strncmp(alg, "DH", len))
 		*pflags |= ENGINE_METHOD_DH;
 	else if (!strncmp(alg, "RAND", len))
@@ -153,6 +159,9 @@
 #ifndef OPENSSL_NO_ECDSA
 	ENGINE_register_ECDSA(e);
 #endif
+#ifndef OPENSSL_NO_EC
+        ENGINE_register_EC(e);
+#endif
 	ENGINE_register_RAND(e);
 	return 1;
 	}
diff -Naur -X symlinks openssl-0.9.8o.orig/crypto/engine/engine.h openssl-0.9.8o/crypto/engine/engine.h
--- openssl-0.9.8o.orig/crypto/engine/engine.h	2010-09-07 16:38:50.557700334 -0400
+++ openssl-0.9.8o/crypto/engine/engine.h	2010-09-22 15:26:59.443387564 -0400
@@ -113,6 +113,7 @@
 #define ENGINE_METHOD_CIPHERS		(unsigned int)0x0040
 #define ENGINE_METHOD_DIGESTS		(unsigned int)0x0080
 #define ENGINE_METHOD_STORE		(unsigned int)0x0100
+#define ENGINE_METHOD_EC                (unsigned int)0x0200
 /* Obvious all-or-nothing cases. */
 #define ENGINE_METHOD_ALL		(unsigned int)0xFFFF
 #define ENGINE_METHOD_NONE		(unsigned int)0x0000
@@ -335,7 +336,11 @@
 void ENGINE_load_nuron(void);
 void ENGINE_load_sureware(void);
 void ENGINE_load_ubsec(void);
+#ifndef OPENSSL_NO_HW_RMISEC
+void ENGINE_load_rmisec(void);
 #endif
+#endif
+
 void ENGINE_load_cryptodev(void);
 void ENGINE_load_padlock(void);
 void ENGINE_load_builtin_engines(void);
@@ -374,6 +379,10 @@
 void ENGINE_unregister_ECDSA(ENGINE *e);
 void ENGINE_register_all_ECDSA(void);
 
+int ENGINE_register_EC(ENGINE *e);
+void ENGINE_unregister_EC(ENGINE *e);
+void ENGINE_register_all_EC(void);
+
 int ENGINE_register_DH(ENGINE *e);
 void ENGINE_unregister_DH(ENGINE *e);
 void ENGINE_register_all_DH(void);
@@ -460,6 +469,9 @@
 int ENGINE_set_DSA(ENGINE *e, const DSA_METHOD *dsa_meth);
 int ENGINE_set_ECDH(ENGINE *e, const ECDH_METHOD *ecdh_meth);
 int ENGINE_set_ECDSA(ENGINE *e, const ECDSA_METHOD *ecdsa_meth);
+int ENGINE_set_EC_GFp_nist(ENGINE *e, const EC_METHOD *ec_meth);
+int ENGINE_set_EC_GFp_mont(ENGINE *e, const EC_METHOD *ec_meth);
+int ENGINE_set_EC_GF2m_simple(ENGINE *e, const EC_METHOD *ec_meth);
 int ENGINE_set_DH(ENGINE *e, const DH_METHOD *dh_meth);
 int ENGINE_set_RAND(ENGINE *e, const RAND_METHOD *rand_meth);
 int ENGINE_set_STORE(ENGINE *e, const STORE_METHOD *store_meth);
@@ -497,6 +509,9 @@
 const DSA_METHOD *ENGINE_get_DSA(const ENGINE *e);
 const ECDH_METHOD *ENGINE_get_ECDH(const ENGINE *e);
 const ECDSA_METHOD *ENGINE_get_ECDSA(const ENGINE *e);
+const EC_METHOD *ENGINE_get_EC_GFp_nist(const ENGINE *e);
+const EC_METHOD *ENGINE_get_EC_GFp_mont(const ENGINE *e);
+const EC_METHOD *ENGINE_get_EC_GF2m_simple(const ENGINE *e);
 const DH_METHOD *ENGINE_get_DH(const ENGINE *e);
 const RAND_METHOD *ENGINE_get_RAND(const ENGINE *e);
 const STORE_METHOD *ENGINE_get_STORE(const ENGINE *e);
@@ -556,6 +571,7 @@
 ENGINE *ENGINE_get_default_DSA(void);
 ENGINE *ENGINE_get_default_ECDH(void);
 ENGINE *ENGINE_get_default_ECDSA(void);
+ENGINE *ENGINE_get_default_EC(void);
 ENGINE *ENGINE_get_default_DH(void);
 ENGINE *ENGINE_get_default_RAND(void);
 /* These functions can be used to get a functional reference to perform
@@ -573,6 +589,7 @@
 int ENGINE_set_default_DSA(ENGINE *e);
 int ENGINE_set_default_ECDH(ENGINE *e);
 int ENGINE_set_default_ECDSA(ENGINE *e);
+int ENGINE_set_default_EC(ENGINE *e);
 int ENGINE_set_default_DH(ENGINE *e);
 int ENGINE_set_default_RAND(ENGINE *e);
 int ENGINE_set_default_ciphers(ENGINE *e);
diff -Naur -X symlinks openssl-0.9.8o.orig/crypto/engine/enginetest.c openssl-0.9.8o/crypto/engine/enginetest.c
--- openssl-0.9.8o.orig/crypto/engine/enginetest.c	2010-09-07 16:38:50.567700620 -0400
+++ openssl-0.9.8o/crypto/engine/enginetest.c	2010-09-22 15:26:59.443387564 -0400
@@ -258,8 +258,8 @@
 		}
 	for(loop = 0; loop < 512; loop++)
 		{
-		OPENSSL_free((void *)ENGINE_get_id(block[loop]));
-		OPENSSL_free((void *)ENGINE_get_name(block[loop]));
+		CRYPTO_free(ENGINE_get_id(block[loop]));
+		CRYPTO_free(ENGINE_get_name(block[loop]));
 		}
 	printf("\nTests completed happily\n");
 	to_return = 0;
diff -Naur -X symlinks openssl-0.9.8o.orig/crypto/engine/eng_int.h openssl-0.9.8o/crypto/engine/eng_int.h
--- openssl-0.9.8o.orig/crypto/engine/eng_int.h	2010-09-07 16:38:50.557700334 -0400
+++ openssl-0.9.8o/crypto/engine/eng_int.h	2010-09-22 15:26:59.443387564 -0400
@@ -154,6 +154,9 @@
 	const DH_METHOD *dh_meth;
 	const ECDH_METHOD *ecdh_meth;
 	const ECDSA_METHOD *ecdsa_meth;
+	const EC_METHOD *ec_gfp_nist_meth;
+	const EC_METHOD *ec_gfp_mont_meth;
+	const EC_METHOD *ec_gf2m_simple_meth;
 	const RAND_METHOD *rand_meth;
 	const STORE_METHOD *store_meth;
 	/* Cipher handling is via this callback */
diff -Naur -X symlinks openssl-0.9.8o.orig/crypto/engine/eng_openssl.c openssl-0.9.8o/crypto/engine/eng_openssl.c
--- openssl-0.9.8o.orig/crypto/engine/eng_openssl.c	2010-09-07 16:38:50.547700044 -0400
+++ openssl-0.9.8o/crypto/engine/eng_openssl.c	2010-09-22 15:26:59.443387564 -0400
@@ -146,6 +146,11 @@
 #ifndef OPENSSL_NO_ECDSA
 			|| !ENGINE_set_ECDSA(e, ECDSA_OpenSSL())
 #endif
+#ifndef OPENSSL_NO_EC
+                        || !ENGINE_set_EC_GFp_nist(e, EC_GFp_nist_method())
+                        || !ENGINE_set_EC_GFp_mont(e, EC_GFp_mont_method())
+                        || !ENGINE_set_EC_GF2m_simple(e, EC_GF2m_simple_method())
+#endif
 #ifndef OPENSSL_NO_DH
 			|| !ENGINE_set_DH(e, DH_get_default_method())
 #endif
diff -Naur -X symlinks openssl-0.9.8o.orig/crypto/engine/Makefile openssl-0.9.8o/crypto/engine/Makefile
--- openssl-0.9.8o.orig/crypto/engine/Makefile	2010-09-07 16:38:50.557700334 -0400
+++ openssl-0.9.8o/crypto/engine/Makefile	2010-09-22 15:26:59.443387564 -0400
@@ -21,12 +21,14 @@
 	eng_table.c eng_pkey.c eng_fat.c eng_all.c \
 	tb_rsa.c tb_dsa.c tb_ecdsa.c tb_dh.c tb_ecdh.c tb_rand.c tb_store.c \
 	tb_cipher.c tb_digest.c \
-	eng_openssl.c eng_cnf.c eng_dyn.c eng_cryptodev.c eng_padlock.c
+	eng_openssl.c eng_cnf.c eng_dyn.c eng_cryptodev.c eng_padlock.c \
+        tb_ec.c
 LIBOBJ= eng_err.o eng_lib.o eng_list.o eng_init.o eng_ctrl.o \
 	eng_table.o eng_pkey.o eng_fat.o eng_all.o \
 	tb_rsa.o tb_dsa.o tb_ecdsa.o tb_dh.o tb_ecdh.o tb_rand.o tb_store.o \
 	tb_cipher.o tb_digest.o \
-	eng_openssl.o eng_cnf.o eng_dyn.o eng_cryptodev.o eng_padlock.o
+	eng_openssl.o eng_cnf.o eng_dyn.o eng_cryptodev.o eng_padlock.o \
+        tb_ec.o
 
 SRC= $(LIBSRC)
 
diff -Naur -X symlinks openssl-0.9.8o.orig/crypto/engine/tb_ec.c openssl-0.9.8o/crypto/engine/tb_ec.c
--- openssl-0.9.8o.orig/crypto/engine/tb_ec.c	1969-12-31 19:00:00.000000000 -0500
+++ openssl-0.9.8o/crypto/engine/tb_ec.c	2010-09-22 15:26:59.443387564 -0400
@@ -0,0 +1,139 @@
+/* ====================================================================
+ * Copyright (c) 2000-2002 The OpenSSL Project.  All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer. 
+ *
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in
+ *    the documentation and/or other materials provided with the
+ *    distribution.
+ *
+ * 3. All advertising materials mentioning features or use of this
+ *    software must display the following acknowledgment:
+ *    "This product includes software developed by the OpenSSL Project
+ *    for use in the OpenSSL Toolkit. (http://www.OpenSSL.org/)"
+ *
+ * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
+ *    endorse or promote products derived from this software without
+ *    prior written permission. For written permission, please contact
+ *    licensing@OpenSSL.org.
+ *
+ * 5. Products derived from this software may not be called "OpenSSL"
+ *    nor may "OpenSSL" appear in their names without prior written
+ *    permission of the OpenSSL Project.
+ *
+ * 6. Redistributions of any form whatsoever must retain the following
+ *    acknowledgment:
+ *    "This product includes software developed by the OpenSSL Project
+ *    for use in the OpenSSL Toolkit (http://www.OpenSSL.org/)"
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
+ * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE OpenSSL PROJECT OR
+ * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+ * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
+ * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
+ * OF THE POSSIBILITY OF SUCH DAMAGE.
+ * ====================================================================
+ *
+ * This product includes cryptographic software written by Eric Young
+ * (eay@cryptsoft.com).  This product includes software written by Tim
+ * Hudson (tjh@cryptsoft.com).
+ *
+ */
+
+#include "eng_int.h"
+
+/* If this symbol is defined then ENGINE_get_default_EC(), the function that is
+ * used by EC to hook in implementation code and cache defaults (etc), will
+ * display brief debugging summaries to stderr with the 'nid'. */
+/* #define ENGINE_EC_DEBUG */
+
+static ENGINE_TABLE *ec_table = NULL;
+static const int dummy_nid = 1;
+
+void ENGINE_unregister_EC(ENGINE *e)
+	{
+	engine_table_unregister(&ec_table, e);
+	}
+
+static void engine_unregister_all_EC(void)
+	{
+	engine_table_cleanup(&ec_table);
+	}
+
+int ENGINE_register_EC(ENGINE *e)
+	{
+	if(e->ec_gfp_nist_meth)
+		return engine_table_register(&ec_table,
+				engine_unregister_all_EC, e, &dummy_nid, 1, 0);
+	return 1;
+	}
+
+void ENGINE_register_all_EC()
+	{
+	ENGINE *e;
+
+	for(e=ENGINE_get_first() ; e ; e=ENGINE_get_next(e))
+		ENGINE_register_EC(e);
+	}
+
+int ENGINE_set_default_EC(ENGINE *e)
+	{
+	if(e->ec_gfp_nist_meth) {
+		return engine_table_register(&ec_table,
+				engine_unregister_all_EC, e, &dummy_nid, 1, 1);
+	}
+	return 1;
+	}
+
+/* Exposed API function to get a functional reference from the implementation
+ * table (ie. try to get a functional reference from the tabled structural
+ * references). */
+ENGINE *ENGINE_get_default_EC(void)
+	{
+	ENGINE *e;
+	e = engine_table_select(&ec_table, dummy_nid);
+	return e;
+	}
+
+/* Obtains an EC implementation from an ENGINE functional reference */
+const EC_METHOD *ENGINE_get_EC_GFp_nist(const ENGINE *e)
+        {
+        return e->ec_gfp_nist_meth;
+        }
+const EC_METHOD *ENGINE_get_EC_GFp_mont(const ENGINE *e)
+        {
+        return e->ec_gfp_mont_meth;
+        }
+const EC_METHOD *ENGINE_get_EC_GF2m_simple(const ENGINE *e)
+        {
+        return e->ec_gf2m_simple_meth;
+        }
+
+/* Sets an EC implementation in an ENGINE structure */
+int ENGINE_set_EC_GFp_nist(ENGINE *e, const EC_METHOD *ec_meth)
+        {
+        e->ec_gfp_nist_meth = ec_meth;
+        return 1;
+        }
+int ENGINE_set_EC_GFp_mont(ENGINE *e, const EC_METHOD *ec_meth)
+        {
+        e->ec_gfp_mont_meth = ec_meth;
+        return 1;
+        }
+int ENGINE_set_EC_GF2m_simple(ENGINE *e, const EC_METHOD *ec_meth)
+        {
+        e->ec_gf2m_simple_meth = ec_meth;
+        return 1;
+        }
diff -Naur -X symlinks openssl-0.9.8o.orig/crypto/evp/bio_md.c openssl-0.9.8o/crypto/evp/bio_md.c
--- openssl-0.9.8o.orig/crypto/evp/bio_md.c	2010-09-07 16:38:50.357699375 -0400
+++ openssl-0.9.8o/crypto/evp/bio_md.c	2010-09-22 15:26:59.443387564 -0400
@@ -128,7 +128,7 @@
 	ret=BIO_read(b->next_bio,out,outl);
 	if (b->init)
 		{
-		if (ret > 0)
+		if (ret >= 0)
 			{
 			EVP_DigestUpdate(ctx,(unsigned char *)out,
 				(unsigned int)ret);
diff -Naur -X symlinks openssl-0.9.8o.orig/crypto/evp/evp_key.c openssl-0.9.8o/crypto/evp/evp_key.c
--- openssl-0.9.8o.orig/crypto/evp/evp_key.c	2010-09-07 16:38:50.337700415 -0400
+++ openssl-0.9.8o/crypto/evp/evp_key.c	2010-09-22 15:26:59.443387564 -0400
@@ -114,7 +114,12 @@
 	EVP_MD_CTX c;
 	unsigned char md_buf[EVP_MAX_MD_SIZE];
 	int niv,nkey,addmd=0;
-	unsigned int mds=0,i;
+	unsigned int mds = 0,i, l = 0;
+	char *d = NULL;
+
+	if(d == NULL) {
+		return 0;
+	}
 
 	nkey=type->key_len;
 	niv=type->iv_len;
@@ -126,13 +131,40 @@
 	EVP_MD_CTX_init(&c);
 	for (;;)
 		{
+		if(c.flags & EVP_MD_CTX_FLAG_ONESHOT) {
+			d = (char *)OPENSSL_malloc(count + datal +
+						   PKCS5_SALT_LEN + 16);
+		}
+
 		if (!EVP_DigestInit_ex(&c,md, NULL))
 			return 0;
-		if (addmd++)
+		if (addmd++) {
+			if(d != NULL) {
+				memcpy(d, &md_buf[0], mds);
+				l += mds;
+			} else {
 			EVP_DigestUpdate(&c,&(md_buf[0]),mds);
+			}
+		}
+
+		if(d != NULL) {
+			memcpy(d + l, data, datal);
+			l += datal;
+		} else {
 		EVP_DigestUpdate(&c,data,datal);
-		if (salt != NULL)
+		}
+
+		if (salt != NULL) {
+			if(d != NULL) {
+				memcpy(d + l, salt, PKCS5_SALT_LEN);
+				l += PKCS5_SALT_LEN;
+			} else {
 			EVP_DigestUpdate(&c,salt,PKCS5_SALT_LEN);
+			}
+		}
+		if(d != NULL) {
+			EVP_DigestUpdate(&c, d, l);
+		}
 		EVP_DigestFinal_ex(&c,&(md_buf[0]),&mds);
 
 		for (i=1; i<(unsigned int)count; i++)
@@ -166,6 +198,8 @@
 				i++;
 				}
 			}
+		if(d != NULL)
+			OPENSSL_free(d);
 		if ((nkey == 0) && (niv == 0)) break;
 		}
 	EVP_MD_CTX_cleanup(&c);
diff -Naur -X symlinks openssl-0.9.8o.orig/crypto/md5/asm/md5-sparcv9.S openssl-0.9.8o/crypto/md5/asm/md5-sparcv9.S
--- openssl-0.9.8o.orig/crypto/md5/asm/md5-sparcv9.S	1969-12-31 19:00:00.000000000 -0500
+++ openssl-0.9.8o/crypto/md5/asm/md5-sparcv9.S	2010-09-22 15:26:59.443387564 -0400
@@ -0,0 +1,1031 @@
+.ident	"md5-sparcv9.S, Version 1.0"
+.ident	"SPARC V9 ISA artwork by Andy Polyakov <appro@fy.chalmers.se>"
+.file	"md5-sparcv9.S"
+
+/*
+ * ====================================================================
+ * Copyright (c) 1999 Andy Polyakov <appro@fy.chalmers.se>.
+ *
+ * Rights for redistribution and usage in source and binary forms are
+ * granted as long as above copyright notices are retained. Warranty
+ * of any kind is (of course:-) disclaimed.
+ * ====================================================================
+ */
+
+/*
+ * This is my modest contribution to OpenSSL project (see
+ * http://www.openssl.org/ for more information about it) and is an
+ * assembler implementation of MD5 block hash function. I've hand-coded
+ * this for the sole reason to reach UltraSPARC-specific "load in
+ * little-endian byte order" instruction. This gives up to 15%
+ * performance improvement for cases when input message is aligned at
+ * 32 bits boundary. The module was tested under both 32 *and* 64 bit
+ * kernels. For updates see http://fy.chalmers.se/~appro/hpe/.
+ *
+ * To compile with SC4.x/SC5.x:
+ *
+ *	cc -xarch=v[9|8plus] -DOPENSSL_SYSNAME_ULTRASPARC -DMD5_BLOCK_DATA_ORDER \
+ *		-c md5-sparcv9.S
+ *
+ * and with gcc:
+ *
+ *	gcc -mcpu=ultrasparc -DOPENSSL_SYSNAME_ULTRASPARC -DMD5_BLOCK_DATA_ORDER \
+ *		-c md5-sparcv9.S
+ *
+ * or if above fails (it does if you have gas):
+ *
+ *	gcc -E -DOPENSSL_SYSNAMEULTRASPARC -DMD5_BLOCK_DATA_ORDER md5_block.sparc.S | \
+ *		as -xarch=v8plus /dev/fd/0 -o md5-sparcv9.o
+ */
+
+#include <openssl/e_os2.h>
+
+#define	A	%o0
+#define B	%o1
+#define	C	%o2
+#define	D	%o3
+#define	T1	%o4
+#define	T2	%o5
+
+#define	R0	%l0
+#define	R1	%l1
+#define	R2	%l2
+#define	R3	%l3
+#define	R4	%l4
+#define	R5	%l5
+#define	R6	%l6
+#define	R7	%l7
+#define	R8	%i3
+#define	R9	%i4
+#define	R10	%i5
+#define	R11	%g1
+#define R12	%g2
+#define	R13	%g3
+#define RX	%g4
+
+#define Aptr	%i0+0
+#define Bptr	%i0+4
+#define Cptr	%i0+8
+#define Dptr	%i0+12
+
+#define Aval	R5	/* those not used at the end of the last round */
+#define Bval	R6
+#define Cval	R7
+#define Dval	R8
+
+#if defined(MD5_BLOCK_DATA_ORDER)
+# if defined(OPENSSL_SYSNAME_ULTRASPARC)
+#  define	LOAD			lda
+#  define	X(i)			[%i1+i*4]%asi
+#  define	md5_block		md5_block_asm_data_order_aligned
+#  define	ASI_PRIMARY_LITTLE	0x88
+# else
+#  error "MD5_BLOCK_DATA_ORDER is supported only on UltraSPARC!"
+# endif
+#else
+# define	LOAD			ld
+# define	X(i)			[%i1+i*4]
+# define	md5_block		md5_block_asm_host_order
+#endif
+
+.section        ".text",#alloc,#execinstr
+
+#if defined(__SUNPRO_C) && defined(__sparcv9)
+  /* They've said -xarch=v9 at command line */
+  .register	%g2,#scratch
+  .register	%g3,#scratch
+# define	FRAME	-192
+#elif defined(__GNUC__) && defined(__arch64__)
+  /* They've said -m64 at command line */
+  .register     %g2,#scratch
+  .register     %g3,#scratch
+# define        FRAME   -192
+#else
+# define	FRAME	-96
+#endif
+
+.align  32
+
+.global md5_block
+md5_block:
+	save	%sp,FRAME,%sp
+
+	ld	[Dptr],D
+	ld	[Cptr],C
+	ld	[Bptr],B
+	ld	[Aptr],A
+#ifdef ASI_PRIMARY_LITTLE
+	rd	%asi,%o7	! How dare I? Well, I just do:-)
+	wr	%g0,ASI_PRIMARY_LITTLE,%asi
+#endif
+	LOAD	X(0),R0
+
+.Lmd5_block_loop:
+
+!!!!!!!!Round 0
+
+	xor	C,D,T1
+	sethi	%hi(0xd76aa478),T2
+	and	T1,B,T1
+	or	T2,%lo(0xd76aa478),T2	!=
+	xor	T1,D,T1
+	add	T1,R0,T1
+	LOAD	X(1),R1
+	add	T1,T2,T1		!=
+	add	A,T1,A
+	sll	A,7,T2
+	srl	A,32-7,A
+	or	A,T2,A			!=
+	 xor	 B,C,T1
+	add	A,B,A
+
+	sethi	%hi(0xe8c7b756),T2
+	and	T1,A,T1			!=
+	or	T2,%lo(0xe8c7b756),T2
+	xor	T1,C,T1
+	LOAD	X(2),R2
+	add	T1,R1,T1		!=
+	add	T1,T2,T1
+	add	D,T1,D
+	sll	D,12,T2
+	srl	D,32-12,D		!=
+	or	D,T2,D
+	 xor	 A,B,T1
+	add	D,A,D
+
+	sethi	%hi(0x242070db),T2	!=
+	and	T1,D,T1
+	or	T2,%lo(0x242070db),T2
+	xor	T1,B,T1
+	add	T1,R2,T1		!=
+	LOAD	X(3),R3
+	add	T1,T2,T1
+	add	C,T1,C
+	sll	C,17,T2			!=
+	srl	C,32-17,C
+	or	C,T2,C
+	 xor	 D,A,T1
+	add	C,D,C			!=
+
+	sethi	%hi(0xc1bdceee),T2
+	and	T1,C,T1
+	or	T2,%lo(0xc1bdceee),T2
+	xor	T1,A,T1			!=
+	add	T1,R3,T1
+	LOAD	X(4),R4
+	add	T1,T2,T1
+	add	B,T1,B			!=
+	sll	B,22,T2
+	srl	B,32-22,B
+	or	B,T2,B
+	 xor	 C,D,T1			!=
+	add	B,C,B
+
+	sethi	%hi(0xf57c0faf),T2
+	and	T1,B,T1
+	or	T2,%lo(0xf57c0faf),T2	!=
+	xor	T1,D,T1
+	add	T1,R4,T1
+	LOAD	X(5),R5
+	add	T1,T2,T1		!=
+	add	A,T1,A
+	sll	A,7,T2
+	srl	A,32-7,A
+	or	A,T2,A			!=
+	 xor	 B,C,T1
+	add	A,B,A
+
+	sethi	%hi(0x4787c62a),T2
+	and	T1,A,T1			!=
+	or	T2,%lo(0x4787c62a),T2
+	xor	T1,C,T1
+	LOAD	X(6),R6
+	add	T1,R5,T1		!=
+	add	T1,T2,T1
+	add	D,T1,D
+	sll	D,12,T2
+	srl	D,32-12,D		!=
+	or	D,T2,D
+	 xor	 A,B,T1
+	add	D,A,D
+
+	sethi	%hi(0xa8304613),T2	!=
+	and	T1,D,T1
+	or	T2,%lo(0xa8304613),T2
+	xor	T1,B,T1
+	add	T1,R6,T1		!=
+	LOAD	X(7),R7
+	add	T1,T2,T1
+	add	C,T1,C
+	sll	C,17,T2			!=
+	srl	C,32-17,C
+	or	C,T2,C
+	 xor	 D,A,T1
+	add	C,D,C			!=
+
+	sethi	%hi(0xfd469501),T2
+	and	T1,C,T1
+	or	T2,%lo(0xfd469501),T2
+	xor	T1,A,T1			!=
+	add	T1,R7,T1
+	LOAD	X(8),R8
+	add	T1,T2,T1
+	add	B,T1,B			!=
+	sll	B,22,T2
+	srl	B,32-22,B
+	or	B,T2,B
+	 xor	 C,D,T1			!=
+	add	B,C,B
+
+	sethi	%hi(0x698098d8),T2
+	and	T1,B,T1
+	or	T2,%lo(0x698098d8),T2	!=
+	xor	T1,D,T1
+	add	T1,R8,T1
+	LOAD	X(9),R9
+	add	T1,T2,T1		!=
+	add	A,T1,A
+	sll	A,7,T2
+	srl	A,32-7,A
+	or	A,T2,A			!=
+	 xor	 B,C,T1
+	add	A,B,A
+
+	sethi	%hi(0x8b44f7af),T2
+	and	T1,A,T1			!=
+	or	T2,%lo(0x8b44f7af),T2
+	xor	T1,C,T1
+	LOAD	X(10),R10
+	add	T1,R9,T1		!=
+	add	T1,T2,T1
+	add	D,T1,D
+	sll	D,12,T2
+	srl	D,32-12,D		!=
+	or	D,T2,D
+	 xor	 A,B,T1
+	add	D,A,D
+
+	sethi	%hi(0xffff5bb1),T2	!=
+	and	T1,D,T1
+	or	T2,%lo(0xffff5bb1),T2
+	xor	T1,B,T1
+	add	T1,R10,T1		!=
+	LOAD	X(11),R11
+	add	T1,T2,T1
+	add	C,T1,C
+	sll	C,17,T2			!=
+	srl	C,32-17,C
+	or	C,T2,C
+	 xor	 D,A,T1
+	add	C,D,C			!=
+
+	sethi	%hi(0x895cd7be),T2
+	and	T1,C,T1
+	or	T2,%lo(0x895cd7be),T2
+	xor	T1,A,T1			!=
+	add	T1,R11,T1
+	LOAD	X(12),R12
+	add	T1,T2,T1
+	add	B,T1,B			!=
+	sll	B,22,T2
+	srl	B,32-22,B
+	or	B,T2,B
+	 xor	 C,D,T1			!=
+	add	B,C,B
+
+	sethi	%hi(0x6b901122),T2
+	and	T1,B,T1
+	or	T2,%lo(0x6b901122),T2	!=
+	xor	T1,D,T1
+	add	T1,R12,T1
+	LOAD	X(13),R13
+	add	T1,T2,T1		!=
+	add	A,T1,A
+	sll	A,7,T2
+	srl	A,32-7,A
+	or	A,T2,A			!=
+	 xor	 B,C,T1
+	add	A,B,A
+
+	sethi	%hi(0xfd987193),T2
+	and	T1,A,T1			!=
+	or	T2,%lo(0xfd987193),T2
+	xor	T1,C,T1
+	LOAD	X(14),RX
+	add	T1,R13,T1		!=
+	add	T1,T2,T1
+	add	D,T1,D
+	sll	D,12,T2
+	srl	D,32-12,D		!=
+	or	D,T2,D
+	 xor	 A,B,T1
+	add	D,A,D
+
+	sethi	%hi(0xa679438e),T2	!=
+	and	T1,D,T1
+	or	T2,%lo(0xa679438e),T2
+	xor	T1,B,T1
+	add	T1,RX,T1		!=
+	LOAD	X(15),RX
+	add	T1,T2,T1
+	add	C,T1,C
+	sll	C,17,T2			!=
+	srl	C,32-17,C
+	or	C,T2,C
+	 xor	 D,A,T1
+	add	C,D,C			!=
+
+	sethi	%hi(0x49b40821),T2
+	and	T1,C,T1
+	or	T2,%lo(0x49b40821),T2
+	xor	T1,A,T1			!=
+	add	T1,RX,T1
+	!pre-LOADed	X(1),R1
+	add	T1,T2,T1
+	add	B,T1,B
+	sll	B,22,T2			!=
+	srl	B,32-22,B
+	or	B,T2,B
+	add	B,C,B
+
+!!!!!!!!Round 1
+
+	xor	B,C,T1			!=
+	sethi	%hi(0xf61e2562),T2
+	and	T1,D,T1
+	or	T2,%lo(0xf61e2562),T2
+	xor	T1,C,T1			!=
+	add	T1,R1,T1
+	!pre-LOADed	X(6),R6
+	add	T1,T2,T1
+	add	A,T1,A
+	sll	A,5,T2			!=
+	srl	A,32-5,A
+	or	A,T2,A
+	add	A,B,A
+
+	xor	A,B,T1			!=
+	sethi	%hi(0xc040b340),T2
+	and	T1,C,T1
+	or	T2,%lo(0xc040b340),T2
+	xor	T1,B,T1			!=
+	add	T1,R6,T1
+	!pre-LOADed	X(11),R11
+	add	T1,T2,T1
+	add	D,T1,D
+	sll	D,9,T2			!=
+	srl	D,32-9,D
+	or	D,T2,D
+	add	D,A,D
+
+	xor	D,A,T1			!=
+	sethi	%hi(0x265e5a51),T2
+	and	T1,B,T1
+	or	T2,%lo(0x265e5a51),T2
+	xor	T1,A,T1			!=
+	add	T1,R11,T1
+	!pre-LOADed	X(0),R0
+	add	T1,T2,T1
+	add	C,T1,C
+	sll	C,14,T2			!=
+	srl	C,32-14,C
+	or	C,T2,C
+	add	C,D,C
+
+	xor	C,D,T1			!=
+	sethi	%hi(0xe9b6c7aa),T2
+	and	T1,A,T1
+	or	T2,%lo(0xe9b6c7aa),T2
+	xor	T1,D,T1			!=
+	add	T1,R0,T1
+	!pre-LOADed	X(5),R5
+	add	T1,T2,T1
+	add	B,T1,B
+	sll	B,20,T2			!=
+	srl	B,32-20,B
+	or	B,T2,B
+	add	B,C,B
+
+	xor	B,C,T1			!=
+	sethi	%hi(0xd62f105d),T2
+	and	T1,D,T1
+	or	T2,%lo(0xd62f105d),T2
+	xor	T1,C,T1			!=
+	add	T1,R5,T1
+	!pre-LOADed	X(10),R10
+	add	T1,T2,T1
+	add	A,T1,A
+	sll	A,5,T2			!=
+	srl	A,32-5,A
+	or	A,T2,A
+	add	A,B,A
+
+	xor	A,B,T1			!=
+	sethi	%hi(0x02441453),T2
+	and	T1,C,T1
+	or	T2,%lo(0x02441453),T2
+	xor	T1,B,T1			!=
+	add	T1,R10,T1
+	LOAD	X(15),RX
+	add	T1,T2,T1
+	add	D,T1,D			!=
+	sll	D,9,T2
+	srl	D,32-9,D
+	or	D,T2,D
+	add	D,A,D			!=
+
+	xor	D,A,T1
+	sethi	%hi(0xd8a1e681),T2
+	and	T1,B,T1
+	or	T2,%lo(0xd8a1e681),T2	!=
+	xor	T1,A,T1
+	add	T1,RX,T1
+	!pre-LOADed	X(4),R4
+	add	T1,T2,T1
+	add	C,T1,C			!=
+	sll	C,14,T2
+	srl	C,32-14,C
+	or	C,T2,C
+	add	C,D,C			!=
+
+	xor	C,D,T1
+	sethi	%hi(0xe7d3fbc8),T2
+	and	T1,A,T1
+	or	T2,%lo(0xe7d3fbc8),T2	!=
+	xor	T1,D,T1
+	add	T1,R4,T1
+	!pre-LOADed	X(9),R9
+	add	T1,T2,T1
+	add	B,T1,B			!=
+	sll	B,20,T2
+	srl	B,32-20,B
+	or	B,T2,B
+	add	B,C,B			!=
+
+	xor	B,C,T1
+	sethi	%hi(0x21e1cde6),T2
+	and	T1,D,T1
+	or	T2,%lo(0x21e1cde6),T2	!=
+	xor	T1,C,T1
+	add	T1,R9,T1
+	LOAD	X(14),RX
+	add	T1,T2,T1		!=
+	add	A,T1,A
+	sll	A,5,T2
+	srl	A,32-5,A
+	or	A,T2,A			!=
+	add	A,B,A
+
+	xor	A,B,T1
+	sethi	%hi(0xc33707d6),T2
+	and	T1,C,T1			!=
+	or	T2,%lo(0xc33707d6),T2
+	xor	T1,B,T1
+	add	T1,RX,T1
+	!pre-LOADed	X(3),R3
+	add	T1,T2,T1		!=
+	add	D,T1,D
+	sll	D,9,T2
+	srl	D,32-9,D
+	or	D,T2,D			!=
+	add	D,A,D
+
+	xor	D,A,T1
+	sethi	%hi(0xf4d50d87),T2
+	and	T1,B,T1			!=
+	or	T2,%lo(0xf4d50d87),T2
+	xor	T1,A,T1
+	add	T1,R3,T1
+	!pre-LOADed	X(8),R8
+	add	T1,T2,T1		!=
+	add	C,T1,C
+	sll	C,14,T2
+	srl	C,32-14,C
+	or	C,T2,C			!=
+	add	C,D,C
+
+	xor	C,D,T1
+	sethi	%hi(0x455a14ed),T2
+	and	T1,A,T1			!=
+	or	T2,%lo(0x455a14ed),T2
+	xor	T1,D,T1
+	add	T1,R8,T1
+	!pre-LOADed	X(13),R13
+	add	T1,T2,T1		!=
+	add	B,T1,B
+	sll	B,20,T2
+	srl	B,32-20,B
+	or	B,T2,B			!=
+	add	B,C,B
+
+	xor	B,C,T1
+	sethi	%hi(0xa9e3e905),T2
+	and	T1,D,T1			!=
+	or	T2,%lo(0xa9e3e905),T2
+	xor	T1,C,T1
+	add	T1,R13,T1
+	!pre-LOADed	X(2),R2
+	add	T1,T2,T1		!=
+	add	A,T1,A
+	sll	A,5,T2
+	srl	A,32-5,A
+	or	A,T2,A			!=
+	add	A,B,A
+
+	xor	A,B,T1
+	sethi	%hi(0xfcefa3f8),T2
+	and	T1,C,T1			!=
+	or	T2,%lo(0xfcefa3f8),T2
+	xor	T1,B,T1
+	add	T1,R2,T1
+	!pre-LOADed	X(7),R7
+	add	T1,T2,T1		!=
+	add	D,T1,D
+	sll	D,9,T2
+	srl	D,32-9,D
+	or	D,T2,D			!=
+	add	D,A,D
+
+	xor	D,A,T1
+	sethi	%hi(0x676f02d9),T2
+	and	T1,B,T1			!=
+	or	T2,%lo(0x676f02d9),T2
+	xor	T1,A,T1
+	add	T1,R7,T1
+	!pre-LOADed	X(12),R12
+	add	T1,T2,T1		!=
+	add	C,T1,C
+	sll	C,14,T2
+	srl	C,32-14,C
+	or	C,T2,C			!=
+	add	C,D,C
+
+	xor	C,D,T1
+	sethi	%hi(0x8d2a4c8a),T2
+	and	T1,A,T1			!=
+	or	T2,%lo(0x8d2a4c8a),T2
+	xor	T1,D,T1
+	add	T1,R12,T1
+	!pre-LOADed	X(5),R5
+	add	T1,T2,T1		!=
+	add	B,T1,B
+	sll	B,20,T2
+	srl	B,32-20,B
+	or	B,T2,B			!=
+	add	B,C,B
+
+!!!!!!!!Round 2
+
+	xor	B,C,T1
+	sethi	%hi(0xfffa3942),T2
+	xor	T1,D,T1			!=
+	or	T2,%lo(0xfffa3942),T2
+	add	T1,R5,T1
+	!pre-LOADed	X(8),R8
+	add	T1,T2,T1
+	add	A,T1,A			!=
+	sll	A,4,T2
+	srl	A,32-4,A
+	or	A,T2,A
+	add	A,B,A			!=
+
+	xor	A,B,T1
+	sethi	%hi(0x8771f681),T2
+	xor	T1,C,T1
+	or	T2,%lo(0x8771f681),T2	!=
+	add	T1,R8,T1
+	!pre-LOADed	X(11),R11
+	add	T1,T2,T1
+	add	D,T1,D
+	sll	D,11,T2			!=
+	srl	D,32-11,D
+	or	D,T2,D
+	add	D,A,D
+
+	xor	D,A,T1			!=
+	sethi	%hi(0x6d9d6122),T2
+	xor	T1,B,T1
+	or	T2,%lo(0x6d9d6122),T2
+	add	T1,R11,T1		!=
+	LOAD	X(14),RX
+	add	T1,T2,T1
+	add	C,T1,C
+	sll	C,16,T2			!=
+	srl	C,32-16,C
+	or	C,T2,C
+	add	C,D,C
+
+	xor	C,D,T1			!=
+	sethi	%hi(0xfde5380c),T2
+	xor	T1,A,T1
+	or	T2,%lo(0xfde5380c),T2
+	add	T1,RX,T1		!=
+	!pre-LOADed	X(1),R1
+	add	T1,T2,T1
+	add	B,T1,B
+	sll	B,23,T2
+	srl	B,32-23,B		!=
+	or	B,T2,B
+	add	B,C,B
+
+	xor	B,C,T1
+	sethi	%hi(0xa4beea44),T2	!=
+	xor	T1,D,T1
+	or	T2,%lo(0xa4beea44),T2
+	add	T1,R1,T1
+	!pre-LOADed	X(4),R4
+	add	T1,T2,T1		!=
+	add	A,T1,A
+	sll	A,4,T2
+	srl	A,32-4,A
+	or	A,T2,A			!=
+	add	A,B,A
+
+	xor	A,B,T1
+	sethi	%hi(0x4bdecfa9),T2
+	xor	T1,C,T1			!=
+	or	T2,%lo(0x4bdecfa9),T2
+	add	T1,R4,T1
+	!pre-LOADed	X(7),R7
+	add	T1,T2,T1
+	add	D,T1,D			!=
+	sll	D,11,T2
+	srl	D,32-11,D
+	or	D,T2,D
+	add	D,A,D			!=
+
+	xor	D,A,T1
+	sethi	%hi(0xf6bb4b60),T2
+	xor	T1,B,T1
+	or	T2,%lo(0xf6bb4b60),T2	!=
+	add	T1,R7,T1
+	!pre-LOADed	X(10),R10
+	add	T1,T2,T1
+	add	C,T1,C
+	sll	C,16,T2			!=
+	srl	C,32-16,C
+	or	C,T2,C
+	add	C,D,C
+
+	xor	C,D,T1			!=
+	sethi	%hi(0xbebfbc70),T2
+	xor	T1,A,T1
+	or	T2,%lo(0xbebfbc70),T2
+	add	T1,R10,T1		!=
+	!pre-LOADed	X(13),R13
+	add	T1,T2,T1
+	add	B,T1,B
+	sll	B,23,T2
+	srl	B,32-23,B		!=
+	or	B,T2,B
+	add	B,C,B
+
+	xor	B,C,T1
+	sethi	%hi(0x289b7ec6),T2	!=
+	xor	T1,D,T1
+	or	T2,%lo(0x289b7ec6),T2
+	add	T1,R13,T1
+	!pre-LOADed	X(0),R0
+	add	T1,T2,T1		!=
+	add	A,T1,A
+	sll	A,4,T2
+	srl	A,32-4,A
+	or	A,T2,A			!=
+	add	A,B,A
+
+	xor	A,B,T1
+	sethi	%hi(0xeaa127fa),T2
+	xor	T1,C,T1			!=
+	or	T2,%lo(0xeaa127fa),T2
+	add	T1,R0,T1
+	!pre-LOADed	X(3),R3
+	add	T1,T2,T1
+	add	D,T1,D			!=
+	sll	D,11,T2
+	srl	D,32-11,D
+	or	D,T2,D
+	add	D,A,D			!=
+
+	xor	D,A,T1
+	sethi	%hi(0xd4ef3085),T2
+	xor	T1,B,T1
+	or	T2,%lo(0xd4ef3085),T2	!=
+	add	T1,R3,T1
+	!pre-LOADed	X(6),R6
+	add	T1,T2,T1
+	add	C,T1,C
+	sll	C,16,T2			!=
+	srl	C,32-16,C
+	or	C,T2,C
+	add	C,D,C
+
+	xor	C,D,T1			!=
+	sethi	%hi(0x04881d05),T2
+	xor	T1,A,T1
+	or	T2,%lo(0x04881d05),T2
+	add	T1,R6,T1		!=
+	!pre-LOADed	X(9),R9
+	add	T1,T2,T1
+	add	B,T1,B
+	sll	B,23,T2
+	srl	B,32-23,B		!=
+	or	B,T2,B
+	add	B,C,B
+
+	xor	B,C,T1
+	sethi	%hi(0xd9d4d039),T2	!=
+	xor	T1,D,T1
+	or	T2,%lo(0xd9d4d039),T2
+	add	T1,R9,T1
+	!pre-LOADed	X(12),R12
+	add	T1,T2,T1		!=
+	add	A,T1,A
+	sll	A,4,T2
+	srl	A,32-4,A
+	or	A,T2,A			!=
+	add	A,B,A
+
+	xor	A,B,T1
+	sethi	%hi(0xe6db99e5),T2
+	xor	T1,C,T1			!=
+	or	T2,%lo(0xe6db99e5),T2
+	add	T1,R12,T1
+	LOAD	X(15),RX
+	add	T1,T2,T1		!=
+	add	D,T1,D
+	sll	D,11,T2
+	srl	D,32-11,D
+	or	D,T2,D			!=
+	add	D,A,D
+
+	xor	D,A,T1
+	sethi	%hi(0x1fa27cf8),T2
+	xor	T1,B,T1			!=
+	or	T2,%lo(0x1fa27cf8),T2
+	add	T1,RX,T1
+	!pre-LOADed	X(2),R2
+	add	T1,T2,T1
+	add	C,T1,C			!=
+	sll	C,16,T2
+	srl	C,32-16,C
+	or	C,T2,C
+	add	C,D,C			!=
+
+	xor	C,D,T1
+	sethi	%hi(0xc4ac5665),T2
+	xor	T1,A,T1
+	or	T2,%lo(0xc4ac5665),T2	!=
+	add	T1,R2,T1
+	!pre-LOADed	X(0),R0
+	add	T1,T2,T1
+	add	B,T1,B
+	sll	B,23,T2			!=
+	srl	B,32-23,B
+	or	B,T2,B
+	add	B,C,B
+
+!!!!!!!!Round 3
+
+	orn	B,D,T1			!=
+	sethi	%hi(0xf4292244),T2
+	xor	T1,C,T1
+	or	T2,%lo(0xf4292244),T2
+	add	T1,R0,T1		!=
+	!pre-LOADed	X(7),R7
+	add	T1,T2,T1
+	add	A,T1,A
+	sll	A,6,T2
+	srl	A,32-6,A		!=
+	or	A,T2,A
+	add	A,B,A
+
+	orn	A,C,T1
+	sethi	%hi(0x432aff97),T2	!=
+	xor	T1,B,T1
+	or	T2,%lo(0x432aff97),T2
+	LOAD	X(14),RX
+	add	T1,R7,T1		!=
+	add	T1,T2,T1
+	add	D,T1,D
+	sll	D,10,T2
+	srl	D,32-10,D		!=
+	or	D,T2,D
+	add	D,A,D
+
+	orn	D,B,T1
+	sethi	%hi(0xab9423a7),T2	!=
+	xor	T1,A,T1
+	or	T2,%lo(0xab9423a7),T2
+	add	T1,RX,T1
+	!pre-LOADed	X(5),R5
+	add	T1,T2,T1		!=
+	add	C,T1,C
+	sll	C,15,T2
+	srl	C,32-15,C
+	or	C,T2,C			!=
+	add	C,D,C
+
+	orn	C,A,T1
+	sethi	%hi(0xfc93a039),T2
+	xor	T1,D,T1			!=
+	or	T2,%lo(0xfc93a039),T2
+	add	T1,R5,T1
+	!pre-LOADed	X(12),R12
+	add	T1,T2,T1
+	add	B,T1,B			!=
+	sll	B,21,T2
+	srl	B,32-21,B
+	or	B,T2,B
+	add	B,C,B			!=
+
+	orn	B,D,T1
+	sethi	%hi(0x655b59c3),T2
+	xor	T1,C,T1
+	or	T2,%lo(0x655b59c3),T2	!=
+	add	T1,R12,T1
+	!pre-LOADed	X(3),R3
+	add	T1,T2,T1
+	add	A,T1,A
+	sll	A,6,T2			!=
+	srl	A,32-6,A
+	or	A,T2,A
+	add	A,B,A
+
+	orn	A,C,T1			!=
+	sethi	%hi(0x8f0ccc92),T2
+	xor	T1,B,T1
+	or	T2,%lo(0x8f0ccc92),T2
+	add	T1,R3,T1		!=
+	!pre-LOADed	X(10),R10
+	add	T1,T2,T1
+	add	D,T1,D
+	sll	D,10,T2
+	srl	D,32-10,D		!=
+	or	D,T2,D
+	add	D,A,D
+
+	orn	D,B,T1
+	sethi	%hi(0xffeff47d),T2	!=
+	xor	T1,A,T1
+	or	T2,%lo(0xffeff47d),T2
+	add	T1,R10,T1
+	!pre-LOADed	X(1),R1
+	add	T1,T2,T1		!=
+	add	C,T1,C
+	sll	C,15,T2
+	srl	C,32-15,C
+	or	C,T2,C			!=
+	add	C,D,C
+
+	orn	C,A,T1
+	sethi	%hi(0x85845dd1),T2
+	xor	T1,D,T1			!=
+	or	T2,%lo(0x85845dd1),T2
+	add	T1,R1,T1
+	!pre-LOADed	X(8),R8
+	add	T1,T2,T1
+	add	B,T1,B			!=
+	sll	B,21,T2
+	srl	B,32-21,B
+	or	B,T2,B
+	add	B,C,B			!=
+
+	orn	B,D,T1
+	sethi	%hi(0x6fa87e4f),T2
+	xor	T1,C,T1
+	or	T2,%lo(0x6fa87e4f),T2	!=
+	add	T1,R8,T1
+	LOAD	X(15),RX
+	add	T1,T2,T1
+	add	A,T1,A			!=
+	sll	A,6,T2
+	srl	A,32-6,A
+	or	A,T2,A
+	add	A,B,A			!=
+
+	orn	A,C,T1
+	sethi	%hi(0xfe2ce6e0),T2
+	xor	T1,B,T1
+	or	T2,%lo(0xfe2ce6e0),T2	!=
+	add	T1,RX,T1
+	!pre-LOADed	X(6),R6
+	add	T1,T2,T1
+	add	D,T1,D
+	sll	D,10,T2			!=
+	srl	D,32-10,D
+	or	D,T2,D
+	add	D,A,D
+
+	orn	D,B,T1			!=
+	sethi	%hi(0xa3014314),T2
+	xor	T1,A,T1
+	or	T2,%lo(0xa3014314),T2
+	add	T1,R6,T1		!=
+	!pre-LOADed	X(13),R13
+	add	T1,T2,T1
+	add	C,T1,C
+	sll	C,15,T2
+	srl	C,32-15,C		!=
+	or	C,T2,C
+	add	C,D,C
+
+	orn	C,A,T1
+	sethi	%hi(0x4e0811a1),T2	!=
+	xor	T1,D,T1
+	or	T2,%lo(0x4e0811a1),T2
+	!pre-LOADed	X(4),R4
+	 ld	 [Aptr],Aval
+	add	T1,R13,T1		!=
+	add	T1,T2,T1
+	add	B,T1,B
+	sll	B,21,T2
+	srl	B,32-21,B		!=
+	or	B,T2,B
+	add	B,C,B
+
+	orn	B,D,T1
+	sethi	%hi(0xf7537e82),T2	!=
+	xor	T1,C,T1
+	or	T2,%lo(0xf7537e82),T2
+	!pre-LOADed	X(11),R11
+	 ld	 [Dptr],Dval
+	add	T1,R4,T1		!=
+	add	T1,T2,T1
+	add	A,T1,A
+	sll	A,6,T2
+	srl	A,32-6,A		!=
+	or	A,T2,A
+	add	A,B,A
+
+	orn	A,C,T1
+	sethi	%hi(0xbd3af235),T2	!=
+	xor	T1,B,T1
+	or	T2,%lo(0xbd3af235),T2
+	!pre-LOADed	X(2),R2
+	 ld	 [Cptr],Cval
+	add	T1,R11,T1		!=
+	add	T1,T2,T1
+	add	D,T1,D
+	sll	D,10,T2
+	srl	D,32-10,D		!=
+	or	D,T2,D
+	add	D,A,D
+
+	orn	D,B,T1
+	sethi	%hi(0x2ad7d2bb),T2	!=
+	xor	T1,A,T1
+	or	T2,%lo(0x2ad7d2bb),T2
+	!pre-LOADed	X(9),R9
+	 ld	 [Bptr],Bval
+	add	T1,R2,T1		!=
+	 add	 Aval,A,Aval
+	add	T1,T2,T1
+	 st	 Aval,[Aptr]
+	add	C,T1,C			!=
+	sll	C,15,T2
+	 add	 Dval,D,Dval
+	srl	C,32-15,C
+	or	C,T2,C			!=
+	 st	 Dval,[Dptr]
+	add	C,D,C
+
+	orn	C,A,T1
+	sethi	%hi(0xeb86d391),T2	!=
+	xor	T1,D,T1
+	or	T2,%lo(0xeb86d391),T2
+	add	T1,R9,T1
+	!pre-LOADed	X(0),R0
+	 mov	 Aval,A			!=
+	add	T1,T2,T1
+	 mov	 Dval,D
+	add	B,T1,B
+	sll	B,21,T2			!=
+	 add	 Cval,C,Cval
+	srl	B,32-21,B
+	 st	 Cval,[Cptr]
+	or	B,T2,B			!=
+	add	B,C,B
+
+	deccc	%i2
+	mov	Cval,C
+	add	B,Bval,B		!=
+	inc	64,%i1
+	nop
+	st	B,[Bptr]
+	nop				!=
+
+#ifdef	OPENSSL_SYSNAME_ULTRASPARC
+	bg,a,pt	%icc,.Lmd5_block_loop
+#else
+	bg,a	.Lmd5_block_loop
+#endif
+	LOAD	X(0),R0
+
+#ifdef ASI_PRIMARY_LITTLE
+	wr	%g0,%o7,%asi
+#endif
+	ret
+	restore	%g0,0,%o0
+
+.type	md5_block,#function
+.size	md5_block,(.-md5_block)
diff -Naur -X symlinks openssl-0.9.8o.orig/crypto/md5/md5.c openssl-0.9.8o/crypto/md5/md5.c
--- openssl-0.9.8o.orig/crypto/md5/md5.c	2010-09-07 16:38:50.907699504 -0400
+++ openssl-0.9.8o/crypto/md5/md5.c	2010-09-22 15:26:59.443387564 -0400
@@ -109,7 +109,7 @@
 	for (;;)
 		{
 		i=read(fd,buf,BUFSIZE);
-		if (i <= 0) break;
+		if (i < 0) break;
 		MD5_Update(&c,buf,(unsigned long)i);
 		}
 	MD5_Final(&(md[0]),&c);
diff -Naur -X symlinks openssl-0.9.8o.orig/crypto/objects/objects.txt openssl-0.9.8o/crypto/objects/objects.txt
--- openssl-0.9.8o.orig/crypto/objects/objects.txt	2010-09-07 16:38:51.347700857 -0400
+++ openssl-0.9.8o/crypto/objects/objects.txt	2010-09-22 15:26:59.443387564 -0400
@@ -141,6 +141,15 @@
 wap-wsg-idm-ecid 11	: wap-wsg-idm-ecid-wtls11
 wap-wsg-idm-ecid 12	: wap-wsg-idm-ecid-wtls12
 
+# XLS
+secg-ellipticCurve 40           : secp512r1
+!Alias brainpool wap-wsg 5
+brainpool 1                     : brap160r1
+brainpool 2                     : brap192r1
+brainpool 3                     : brap224r1
+brainpool 4                     : brap256r1
+brainpool 5                     : brap384r1
+brainpool 6                     : brap512r1
 
 ISO-US 113533 7 66 10	: CAST5-CBC		: cast5-cbc
 			: CAST5-ECB		: cast5-ecb
diff -Naur -X symlinks openssl-0.9.8o.orig/crypto/objects/obj_mac.h openssl-0.9.8o/crypto/objects/obj_mac.h
--- openssl-0.9.8o.orig/crypto/objects/obj_mac.h	2010-09-07 16:38:51.327699856 -0400
+++ openssl-0.9.8o/crypto/objects/obj_mac.h	2010-09-22 15:26:59.443387564 -0400
@@ -511,6 +511,36 @@
 #define NID_wap_wsg_idm_ecid_wtls12		745
 #define OBJ_wap_wsg_idm_ecid_wtls12		OBJ_wap_wsg_idm_ecid,12L
 
+#define SN_secp512r1		"secp512r1"
+#define NID_secp512r1		751
+#define OBJ_secp512r1		OBJ_secg_ellipticCurve,40L
+
+#define OBJ_brainpool		OBJ_wap_wsg,5L
+
+#define SN_brap160r1		"brap160r1"
+#define NID_brap160r1		752
+#define OBJ_brap160r1		OBJ_brainpool,1L
+
+#define SN_brap192r1		"brap192r1"
+#define NID_brap192r1		753
+#define OBJ_brap192r1		OBJ_brainpool,2L
+
+#define SN_brap224r1		"brap224r1"
+#define NID_brap224r1		754
+#define OBJ_brap224r1		OBJ_brainpool,3L
+
+#define SN_brap256r1		"brap256r1"
+#define NID_brap256r1		755
+#define OBJ_brap256r1		OBJ_brainpool,4L
+
+#define SN_brap384r1		"brap384r1"
+#define NID_brap384r1		756
+#define OBJ_brap384r1		OBJ_brainpool,5L
+
+#define SN_brap512r1		"brap512r1"
+#define NID_brap512r1		757
+#define OBJ_brap512r1		OBJ_brainpool,6L
+
 #define SN_cast5_cbc		"CAST5-CBC"
 #define LN_cast5_cbc		"cast5-cbc"
 #define NID_cast5_cbc		108
diff -Naur -X symlinks openssl-0.9.8o.orig/crypto/objects/o_names.c openssl-0.9.8o/crypto/objects/o_names.c
--- openssl-0.9.8o.orig/crypto/objects/o_names.c	2010-09-07 16:38:51.347700857 -0400
+++ openssl-0.9.8o/crypto/objects/o_names.c	2010-09-22 15:26:59.443387564 -0400
@@ -322,7 +322,7 @@
 	for(n=0 ; n < d.n ; ++n)
 		fn(d.names[n],arg);
 
-	OPENSSL_free((void *)d.names);
+	OPENSSL_free(d.names);
 	}
 
 static int free_type;
diff -Naur -X symlinks openssl-0.9.8o.orig/crypto/opensslconf.h openssl-0.9.8o/crypto/opensslconf.h
--- openssl-0.9.8o.orig/crypto/opensslconf.h	2010-09-07 16:38:51.197699245 -0400
+++ openssl-0.9.8o/crypto/opensslconf.h	2010-09-22 15:26:59.443387564 -0400
@@ -133,14 +133,14 @@
  * - Intel P6 because partial register stalls are very expensive;
  * - elder Alpha because it lacks byte load/store instructions;
  */
-#define RC4_INT unsigned int
+#define RC4_INT unsigned char
 #endif
 #if !defined(RC4_CHUNK)
 /*
  * This enables code handling data aligned at natural CPU word
  * boundary. See crypto/rc4/rc4_enc.c for further details.
  */
-#undef RC4_CHUNK
+#define RC4_CHUNK unsigned long
 #endif
 #endif
 
@@ -148,7 +148,7 @@
 /* If this is set to 'unsigned int' on a DEC Alpha, this gives about a
  * %20 speed up (longs are 8 bytes, int's are 4). */
 #ifndef DES_LONG
-#define DES_LONG unsigned long
+#define DES_LONG unsigned int
 #endif
 #endif
 
@@ -162,9 +162,9 @@
 /* The prime number generation stuff may not work when
  * EIGHT_BIT but I don't care since I've only used this mode
  * for debuging the bignum libraries */
-#undef SIXTY_FOUR_BIT_LONG
+#define SIXTY_FOUR_BIT_LONG
 #undef SIXTY_FOUR_BIT
-#define THIRTY_TWO_BIT
+#undef THIRTY_TWO_BIT
 #undef SIXTEEN_BIT
 #undef EIGHT_BIT
 #endif
@@ -178,7 +178,7 @@
 
 #if defined(HEADER_BF_LOCL_H) && !defined(CONFIG_HEADER_BF_LOCL_H)
 #define CONFIG_HEADER_BF_LOCL_H
-#undef BF_PTR
+#define BF_PTR
 #endif /* HEADER_BF_LOCL_H */
 
 #if defined(HEADER_DES_LOCL_H) && !defined(CONFIG_HEADER_DES_LOCL_H)
@@ -208,7 +208,7 @@
 /* Unroll the inner loop, this sometimes helps, sometimes hinders.
  * Very mucy CPU dependant */
 #ifndef DES_UNROLL
-#undef DES_UNROLL
+#define DES_UNROLL
 #endif
 
 /* These default values were supplied by
diff -Naur -X symlinks openssl-0.9.8o.orig/crypto/rand/md_rand.c openssl-0.9.8o/crypto/rand/md_rand.c
--- openssl-0.9.8o.orig/crypto/rand/md_rand.c	2010-09-07 16:38:50.177700318 -0400
+++ openssl-0.9.8o/crypto/rand/md_rand.c	2010-09-22 15:26:59.443387564 -0400
@@ -198,6 +198,7 @@
 	unsigned char local_md[MD_DIGEST_LENGTH];
 	EVP_MD_CTX m;
 	int do_not_lock;
+	unsigned char *tmp = NULL;
 
 	/*
 	 * (Based on the rand(3) manpage)
@@ -265,8 +266,9 @@
 		j=(j > MD_DIGEST_LENGTH)?MD_DIGEST_LENGTH:j;
 
 		MD_Init(&m);
-		MD_Update(&m,local_md,MD_DIGEST_LENGTH);
 		k=(st_idx+j)-STATE_SIZE;
+		if(!(m.flags & EVP_MD_CTX_FLAG_ONESHOT)) {
+			MD_Update(&m,local_md,MD_DIGEST_LENGTH);
 		if (k > 0)
 			{
 			MD_Update(&m,&(state[st_idx]),j-k);
@@ -277,7 +279,34 @@
 			
 		MD_Update(&m,buf,j);
 		MD_Update(&m,(unsigned char *)&(md_c[0]),sizeof(md_c));
+		} else {
+			int i = 0;
+			tmp = OPENSSL_malloc(MD_DIGEST_LENGTH + 2*j + sizeof(md_c));
+			if(tmp == NULL) return;
+
+			memcpy(tmp, md, MD_DIGEST_LENGTH);
+			i += (sizeof md);
+			if(k > 0) {
+				memcpy(tmp + i, &(state[st_idx]), j-k);
+				i += j-k;
+				memcpy(tmp + i, &(state[0]), k);
+				i += k;
+			} else {
+				memcpy(tmp + i, &(state[st_idx]), j);
+				i += j;
+			}
+			memcpy(tmp + i, buf, j);
+			i += j;
+			memcpy(tmp + i, (unsigned char *)&(md_c[0]), sizeof(md_c));
+			i += sizeof(md_c);
+			MD_Update(&m, tmp, i);
+		}
+
 		MD_Final(&m,local_md);
+		if(tmp) {
+			OPENSSL_free(tmp);
+			tmp = NULL;
+		}
 		md_c[1]++;
 
 		buf=(const char *)buf + j;
@@ -331,6 +360,7 @@
 	long md_c[2];
 	unsigned char local_md[MD_DIGEST_LENGTH];
 	EVP_MD_CTX m;
+	unsigned char *tmp = NULL;
 #ifndef GETPID_IS_MEANINGLESS
 	pid_t curr_pid = getpid();
 #endif
@@ -467,6 +497,10 @@
 		j=(num >= MD_DIGEST_LENGTH/2)?MD_DIGEST_LENGTH/2:num;
 		num-=j;
 		MD_Init(&m);
+
+		k=(st_idx+MD_DIGEST_LENGTH/2)-st_num;
+		if(!(m.flags & EVP_MD_CTX_FLAG_ONESHOT)) {
+
 #ifndef GETPID_IS_MEANINGLESS
 		if (curr_pid) /* just in the first iteration to save time */
 			{
@@ -479,7 +513,6 @@
 #ifndef PURIFY
 		MD_Update(&m,buf,j); /* purify complains */
 #endif
-		k=(st_idx+MD_DIGEST_LENGTH/2)-st_num;
 		if (k > 0)
 			{
 			MD_Update(&m,&(state[st_idx]),MD_DIGEST_LENGTH/2-k);
@@ -487,7 +520,46 @@
 			}
 		else
 			MD_Update(&m,&(state[st_idx]),MD_DIGEST_LENGTH/2);
+		} else {
+			int i = 0;
+			tmp = OPENSSL_malloc(sizeof(pid_t) + j + 2 * MD_DIGEST_LENGTH +
+					     sizeof(md_c));
+
+			if(tmp == NULL) return 0;
+#ifndef GETPID_IS_MEANINGLESS
+			if(curr_pid) {
+				memcpy(tmp, &curr_pid, sizeof curr_pid);
+				i += sizeof(curr_pid);
+			}
+#endif
+			memcpy(tmp + i, local_md, MD_DIGEST_LENGTH);
+			i += MD_DIGEST_LENGTH;
+
+			memcpy(tmp + i, (unsigned char *)&(md_c[0]), sizeof(md_c));
+			i += sizeof(md_c);
+#ifndef PURIFY
+			memcpy(tmp + i, buf, j);
+			i += j;
+#endif
+			if(k > 0) {
+				memcpy(tmp + i, &(state[st_idx]), MD_DIGEST_LENGTH/2-k);
+				i += (MD_DIGEST_LENGTH/2-k);
+
+				memcpy(tmp + i, &(state[0]), k);
+				i += k;
+			} else {
+				memcpy(tmp + i, &(state[st_idx]), MD_DIGEST_LENGTH>>1);
+				i += (MD_DIGEST_LENGTH >> 1);
+			}
+
+			MD_Update(&m, tmp, i);
+		}
+
 		MD_Final(&m,local_md);
+		if(tmp) {
+			OPENSSL_free(tmp);
+			tmp = NULL;
+		}
 
 		for (i=0; i<MD_DIGEST_LENGTH/2; i++)
 			{
@@ -500,12 +572,33 @@
 		}
 
 	MD_Init(&m);
+	if(!(m.flags & EVP_MD_CTX_FLAG_ONESHOT)) {
 	MD_Update(&m,(unsigned char *)&(md_c[0]),sizeof(md_c));
 	MD_Update(&m,local_md,MD_DIGEST_LENGTH);
 	CRYPTO_w_lock(CRYPTO_LOCK_RAND);
 	MD_Update(&m,md,MD_DIGEST_LENGTH);
+	} else {
+		int i = 0;
+		tmp = OPENSSL_malloc(sizeof(md_c) + 2 * MD_DIGEST_LENGTH);
+		if(tmp == NULL) return 0;
+
+		memcpy(tmp, (unsigned char *)&(md_c[0]), sizeof(md_c));
+		i += sizeof(md_c);
+
+		memcpy(tmp + i, local_md, MD_DIGEST_LENGTH);
+		i += MD_DIGEST_LENGTH;
+
+		CRYPTO_w_lock(CRYPTO_LOCK_RAND);
+		memcpy(tmp + i, md, MD_DIGEST_LENGTH);
+		i += MD_DIGEST_LENGTH;
+		MD_Update(&m, tmp, i);
+	}
 	MD_Final(&m,md);
 	CRYPTO_w_unlock(CRYPTO_LOCK_RAND);
+	if(tmp) {
+		OPENSSL_free(tmp);
+		tmp = NULL;
+	}
 
 	EVP_MD_CTX_cleanup(&m);
 	if (ok)
diff -Naur -X symlinks openssl-0.9.8o.orig/crypto/rsa/rsa_eay.c openssl-0.9.8o/crypto/rsa/rsa_eay.c
--- openssl-0.9.8o.orig/crypto/rsa/rsa_eay.c	2010-09-07 16:38:50.977709956 -0400
+++ openssl-0.9.8o/crypto/rsa/rsa_eay.c	2010-09-22 15:26:59.453378796 -0400
@@ -393,6 +393,23 @@
 		goto err;
 		}
 
+	if (padding == RSA_X931_PADDING) {
+		BIGNUM *div, *rem;
+		div = BN_CTX_get(ctx);
+		rem = BN_CTX_get(ctx);
+		if(!div || !rem)
+			goto err;
+		if(!(BN_is_odd(rsa->e))) { /* if it is even */
+			BN_div(div, rem, f, rsa->n, ctx);
+			if(BN_is_word(div, -1))
+				BN_rshift1(f,f);
+			else if(!(BN_is_word(div, 1)))
+				goto err;
+		}
+	}
+
+
+
 	if (!(rsa->flags & RSA_FLAG_NO_BLINDING))
 		{
 		blinding = rsa_get_blinding(rsa, &local_blinding, ctx);
@@ -611,6 +628,7 @@
 	{
 	BIGNUM *f,*ret;
 	int i,num=0,r= -1;
+	unsigned int numb;
 	unsigned char *p;
 	unsigned char *buf=NULL;
 	BN_CTX *ctx=NULL;
@@ -642,6 +660,7 @@
 	f = BN_CTX_get(ctx);
 	ret = BN_CTX_get(ctx);
 	num=BN_num_bytes(rsa->n);
+	numb = BN_num_bits(rsa->n);
 	buf = OPENSSL_malloc(num);
 	if(!f || !ret || !buf)
 		{
@@ -672,8 +691,55 @@
 	if (!rsa->meth->bn_mod_exp(ret,f,rsa->e,rsa->n,ctx,
 		rsa->_method_mod_n)) goto err;
 
-	if ((padding == RSA_X931_PADDING) && ((ret->d[0] & 0xf) != 12))
-		BN_sub(ret, rsa->n, ret);
+	if (padding == RSA_X931_PADDING) {
+		char temp[1];
+		BIGNUM *range1, *range2, *one;
+		range1 = BN_CTX_get(ctx);
+		range2 = BN_CTX_get(ctx);
+		one = BN_CTX_get(ctx);
+		if(!range1 || !range2 || !one) {
+			RSAerr(RSA_F_RSA_EAY_PUBLIC_DECRYPT,ERR_R_MALLOC_FAILURE);
+			goto err;
+		}
+		temp[0] = 2;
+		if (BN_bin2bn(temp, 1 ,range1) == NULL) goto err;
+		if (BN_bin2bn(temp, 1 ,range2) == NULL) goto err;
+		temp[0] = 1;
+		if (BN_bin2bn(temp, 1 ,one) == NULL) goto err;
+
+		/* if e is odd */
+		if(BN_is_odd(rsa->e)) {
+			if((ret->d[0] & 0xf) != 12) {
+				BN_sub(ret, rsa->n, ret); /* n - rr */
+				if ((ret->d[0] & 0xf) != 12) {
+					goto err;
+				}
+			}
+		} else { /* if e is even */
+			if((ret->d[0] & 0x7) == 1)
+				BN_sub(ret, rsa->n, ret); /* n - rr */
+			else if((ret->d[0] & 0x7) == 6)
+				BN_mul(ret, ret, range1, ctx); /* multiply by 2 */
+			else if((ret->d[0] & 0x7) == 7) {
+				BN_sub(ret, rsa->n, ret);  /* n - rr */
+				BN_mul(ret, ret, range1, ctx); /* multiply by 2 */
+			} else if(!((ret->d[0] & 0x7) == 4))
+				goto err;
+		}
+
+		BN_lshift(range1, range1, (numb - 2) - 1);  /* 2^(k-2) -- 2^n = 2 << (n-1) */
+		BN_lshift(range2, range2, (numb - 1) - 1); /* 2^(k-1)*/
+		BN_sub(range2, range2, one);
+
+		if(BN_cmp(ret, range1) < 0) {
+			goto err;
+		}
+
+		if(BN_cmp(ret, range2) > 0) {
+			goto err;
+		}
+
+	}
 
 	p=buf;
 	i=BN_bn2bin(ret,p);
diff -Naur -X symlinks openssl-0.9.8o.orig/crypto/rsa/rsa_sign.c openssl-0.9.8o/crypto/rsa/rsa_sign.c
--- openssl-0.9.8o.orig/crypto/rsa/rsa_sign.c	2010-09-07 16:38:50.977709956 -0400
+++ openssl-0.9.8o/crypto/rsa/rsa_sign.c	2010-09-22 15:26:59.453378796 -0400
@@ -262,8 +262,14 @@
 			{
 			RSAerr(RSA_F_RSA_VERIFY,RSA_R_BAD_SIGNATURE);
 			}
-		else
+		else {
+			/* make sure the digest is at the end */
+			if(memcmp(m, &((unsigned char *)s)[i - m_len], m_len) == 0)
 			ret=1;
+			else
+				ret = 0;
+
+		}
 	}
 err:
 	if (sig != NULL) X509_SIG_free(sig);
diff -Naur -X symlinks openssl-0.9.8o.orig/crypto/sha/sha1.c openssl-0.9.8o/crypto/sha/sha1.c
--- openssl-0.9.8o.orig/crypto/sha/sha1.c	2010-09-07 16:38:50.647699933 -0400
+++ openssl-0.9.8o/crypto/sha/sha1.c	2010-09-22 15:26:59.453378796 -0400
@@ -109,7 +109,7 @@
 	for (;;)
 		{
 		i=read(fd,buf,BUFSIZE);
-		if (i <= 0) break;
+		if (i < 0) break;
 		SHA1_Update(&c,buf,(unsigned long)i);
 		}
 	SHA1_Final(&(md[0]),&c);
diff -Naur -X symlinks openssl-0.9.8o.orig/crypto/txt_db/txt_db.c openssl-0.9.8o/crypto/txt_db/txt_db.c
--- openssl-0.9.8o.orig/crypto/txt_db/txt_db.c	2010-09-07 16:38:50.477699546 -0400
+++ openssl-0.9.8o/crypto/txt_db/txt_db.c	2010-09-22 15:26:59.453378796 -0400
@@ -378,7 +378,7 @@
 						OPENSSL_free(p[n]);
 					}
 				}
-			OPENSSL_free(sk_value(db->data,i));
+			OPENSSL_free(p);
 			}
 		sk_free(db->data);
 		}
diff -Naur -X symlinks openssl-0.9.8o.orig/crypto/ui/ui_lib.c openssl-0.9.8o/crypto/ui/ui_lib.c
--- openssl-0.9.8o.orig/crypto/ui/ui_lib.c	2010-09-07 16:38:50.877699562 -0400
+++ openssl-0.9.8o/crypto/ui/ui_lib.c	2010-09-22 15:26:59.453378796 -0400
@@ -99,13 +99,13 @@
 	{
 	if (uis->flags & OUT_STRING_FREEABLE)
 		{
-		OPENSSL_free((char *)uis->out_string);
+		OPENSSL_free(uis->out_string);
 		switch(uis->type)
 			{
 		case UIT_BOOLEAN:
-			OPENSSL_free((char *)uis->_.boolean_data.action_desc);
-			OPENSSL_free((char *)uis->_.boolean_data.ok_chars);
-			OPENSSL_free((char *)uis->_.boolean_data.cancel_chars);
+			OPENSSL_free(uis->_.boolean_data.action_desc);
+			OPENSSL_free(uis->_.boolean_data.ok_chars);
+			OPENSSL_free(uis->_.boolean_data.cancel_chars);
 			break;
 		default:
 			break;
diff -Naur -X symlinks openssl-0.9.8o.orig/enc_test.sh openssl-0.9.8o/enc_test.sh
--- openssl-0.9.8o.orig/enc_test.sh	1969-12-31 19:00:00.000000000 -0500
+++ openssl-0.9.8o/enc_test.sh	2010-09-22 15:26:59.453378796 -0400
@@ -0,0 +1,59 @@
+#!/bin/sh
+
+ALGO=aes-256-cbc
+#ALGO=rc4
+SALTED="-salt -S 1234567812345678"
+rm -f ${ALGO}-result.txt
+
+if [ -z $1 ]; then
+    echo '12345678'  > clear.txt
+    FILE=clear.txt
+fi
+
+./bin/openssl enc -engine rmisec -${ALGO} -k 123  ${SALTED} -in ${FILE} -out a.enc
+./bin/openssl enc -d -engine rmisec -${ALGO} -k 123  ${SALTED} -in a.enc -out a.dec
+
+./bin/openssl enc -${ALGO} -k 123  ${SALTED} -in ${FILE} -out b.enc
+./bin/openssl enc -d -${ALGO} -k 123  ${SALTED} -in b.enc -out b.dec
+
+
+./bin/openssl enc -d -engine rmisec -${ALGO} -k 123  ${SALTED} -in b.enc -out ba.dec
+./bin/openssl enc -d -${ALGO} -k 123  ${SALTED} -in a.enc -out ab.dec
+
+RESULT=
+
+diff -q ${FILE} a.dec
+if [ $? -ne 0 ]; then
+    echo 'Test failed: encrypt with offload, decrypt with offload'
+    RESULT=-1
+fi
+
+diff -q ${FILE} b.dec
+if [ $? -ne 0 ]; then
+    echo 'Test failed: encrypt with software, decrypt with software'
+    RESULT=-1
+fi
+
+diff -q ${FILE} ab.dec
+if [ $? -ne 0 ]; then
+    echo 'Test failed: encrypt with offload, decrypt with software'
+    RESULT=-1
+fi
+
+diff -q ${FILE} ba.dec
+if [ $? -ne 0 ]; then
+    echo 'Test failed: encrypt with software, decrypt with offload'
+    RESULT=-1
+fi
+
+if [ -z ${RESULT} ]; then
+    echo 'Test passed'
+    rm -f *.enc *.dec clear.txt
+    exit 0
+fi
+
+od -Ax -t x1 a.enc > ${ALGO}-result.txt
+od -Ax -t x1 b.enc >> ${ALGO}-result.txt
+cat ${ALGO}-result.txt
+od -Ax -t x1 *.dec
+
diff -Naur -X symlinks openssl-0.9.8o.orig/engines/e_4758cca.c openssl-0.9.8o/engines/e_4758cca.c
--- openssl-0.9.8o.orig/engines/e_4758cca.c	2010-09-07 16:38:51.587700142 -0400
+++ openssl-0.9.8o/engines/e_4758cca.c	2010-09-22 15:26:59.453378796 -0400
@@ -140,7 +140,7 @@
 static void free_CCA4758_LIB_NAME(void)
 	{
 	if(CCA4758_LIB_NAME)
-		OPENSSL_free((void*)CCA4758_LIB_NAME);
+		OPENSSL_free(CCA4758_LIB_NAME);
 	CCA4758_LIB_NAME = NULL;
 	}
 static long set_CCA4758_LIB_NAME(const char *name)
diff -Naur -X symlinks openssl-0.9.8o.orig/engines/e_aep.c openssl-0.9.8o/engines/e_aep.c
--- openssl-0.9.8o.orig/engines/e_aep.c	2010-09-07 16:38:51.587700142 -0400
+++ openssl-0.9.8o/engines/e_aep.c	2010-09-22 15:26:59.453378796 -0400
@@ -394,7 +394,7 @@
 static void free_AEP_LIBNAME(void)
 	{
 	if(AEP_LIBNAME)
-		OPENSSL_free((void*)AEP_LIBNAME);
+		OPENSSL_free(AEP_LIBNAME);
 	AEP_LIBNAME = NULL;
 	}
 static long set_AEP_LIBNAME(const char *name)
diff -Naur -X symlinks openssl-0.9.8o.orig/engines/e_atalla.c openssl-0.9.8o/engines/e_atalla.c
--- openssl-0.9.8o.orig/engines/e_atalla.c	2010-09-07 16:38:51.587700142 -0400
+++ openssl-0.9.8o/engines/e_atalla.c	2010-09-22 15:26:59.453378796 -0400
@@ -313,7 +313,7 @@
 static void free_ATALLA_LIBNAME(void)
 	{
 		if(ATALLA_LIBNAME)
-			OPENSSL_free((void*)ATALLA_LIBNAME);
+			OPENSSL_free(ATALLA_LIBNAME);
 		ATALLA_LIBNAME = NULL;
 	}
 static long set_ATALLA_LIBNAME(const char *name)
diff -Naur -X symlinks openssl-0.9.8o.orig/engines/e_chil.c openssl-0.9.8o/engines/e_chil.c
--- openssl-0.9.8o.orig/engines/e_chil.c	2010-09-07 16:38:51.567699691 -0400
+++ openssl-0.9.8o/engines/e_chil.c	2010-09-22 15:26:59.453378796 -0400
@@ -443,7 +443,7 @@
 static void free_HWCRHK_LIBNAME(void)
 	{
 	if(HWCRHK_LIBNAME)
-		OPENSSL_free((void*)HWCRHK_LIBNAME);
+		OPENSSL_free(HWCRHK_LIBNAME);
 	HWCRHK_LIBNAME = NULL;
 	}
 static const char *get_HWCRHK_LIBNAME(void)
diff -Naur -X symlinks openssl-0.9.8o.orig/engines/e_cswift.c openssl-0.9.8o/engines/e_cswift.c
--- openssl-0.9.8o.orig/engines/e_cswift.c	2010-09-07 16:38:51.587700142 -0400
+++ openssl-0.9.8o/engines/e_cswift.c	2010-09-22 15:26:59.453378796 -0400
@@ -332,7 +332,7 @@
 static void free_CSWIFT_LIBNAME(void)
 	{
 	if(CSWIFT_LIBNAME)
-		OPENSSL_free((void*)CSWIFT_LIBNAME);
+		OPENSSL_free(CSWIFT_LIBNAME);
 	CSWIFT_LIBNAME = NULL;
 	}
 static long set_CSWIFT_LIBNAME(const char *name)
diff -Naur -X symlinks openssl-0.9.8o.orig/engines/e_nuron.c openssl-0.9.8o/engines/e_nuron.c
--- openssl-0.9.8o.orig/engines/e_nuron.c	2010-09-07 16:38:51.587700142 -0400
+++ openssl-0.9.8o/engines/e_nuron.c	2010-09-22 15:26:59.453378796 -0400
@@ -89,7 +89,7 @@
 static void free_NURON_LIBNAME(void)
 	{
 	if(NURON_LIBNAME)
-		OPENSSL_free((void*)NURON_LIBNAME);
+		OPENSSL_free(NURON_LIBNAME);
 	NURON_LIBNAME = NULL;
 	}
 static long set_NURON_LIBNAME(const char *name)
diff -Naur -X symlinks openssl-0.9.8o.orig/engines/e_rmisec.c openssl-0.9.8o/engines/e_rmisec.c
--- openssl-0.9.8o.orig/engines/e_rmisec.c	1969-12-31 19:00:00.000000000 -0500
+++ openssl-0.9.8o/engines/e_rmisec.c	2010-09-22 15:26:59.463377483 -0400
@@ -0,0 +1,4739 @@
+/********************************************************************
+Copyright 2003-2009 RMI Corporation (RMI) All rights reserved.
+Redistribution and use in source and binary forms, with or without
+modification, are permitted provided that the following conditions are
+met:
+1. Redistributions of source code must retain the above copyright
+notice, this list of conditions and the following disclaimer.
+2. Redistributions in binary form must reproduce the above copyright
+notice, this list of conditions and the following disclaimer in
+the documentation and/or other materials provided with the
+distribution.
+THIS SOFTWARE IS PROVIDED BY RMI Corporation. ``AS IS'' AND
+ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL RMI OR CONTRIBUTORS BE LIABLE
+FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
+THE POSSIBILITY OF SUCH DAMAGE.
+********************************************************************/
+/* Crypto/engine/e_rmisec.c */
+/* Written by Geoff Thorpe (geoff@geoffthorpe.net) for the OpenSSL
+ * project 2000.
+ * ====================================================================
+ * Copyright (c) 1999-2001 The OpenSSL Project.  All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ *
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in
+ *    the documentation and/or other materials provided with the
+ *    distribution.
+ *
+ * 3. All advertising materials mentioning features or use of this
+ *    software must display the following acknowledgment:
+ *    "This product includes software developed by the OpenSSL Project
+ *    for use in the OpenSSL Toolkit. (http://www.OpenSSL.org/)"
+ *
+ * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
+ *    endorse or promote products derived from this software without
+ *    prior written permission. For written permission, please contact
+ *    licensing@OpenSSL.org.
+ *
+ * 5. Products derived from this software may not be called "OpenSSL"
+ *    nor may "OpenSSL" appear in their names without prior written
+ *    permission of the OpenSSL Project.
+ *
+ * 6. Redistributions of any form whatsoever must retain the following
+ *    acknowledgment:
+ *    "This product includes software developed by the OpenSSL Project
+ *    for use in the OpenSSL Toolkit (http://www.OpenSSL.org/)"
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
+ * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE OpenSSL PROJECT OR
+ * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+ * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
+ * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
+ * OF THE POSSIBILITY OF SUCH DAMAGE.
+ * ====================================================================
+ *
+ * This product includes cryptographic software written by Eric Young
+ * (eay@cryptsoft.com).  This product includes software written by Tim
+ * Hudson (tjh@cryptsoft.com).
+ *
+ */
+
+#include <stdio.h>
+#include <unistd.h>
+#include <fcntl.h>
+#include <stdint.h>
+#include <string.h>
+#include <openssl/crypto.h>
+#include <openssl/dso.h>
+#include <openssl/engine.h>
+#include <xlr_fast_syscall.h>
+
+#ifndef OPENSSL_NO_RSA
+#include <openssl/rsa.h>
+#endif
+#ifndef OPENSSL_NO_DSA
+#include <openssl/dsa.h>
+#endif
+
+#ifndef OPENSSL_NO_EC
+#include "ec/ec_lcl.h"
+#include "ec/ec.h"
+#endif
+#ifndef OPENSSL_NO_ECDSA
+#include "openssl/ec.h"
+#include "openssl/ecdsa.h"
+#include "ecdsa/ecs_locl.h"
+#endif
+
+#ifndef OPENSSL_NO_HW
+#ifndef OPENSSL_NO_HW_RMISEC
+
+#define RMISEC_NO_MD5_INIT
+/* #define RMISEC_NO_MD5_UPDATE */
+#define RMISEC_NO_MD5_FINAL
+#define RMISEC_NO_SHA1_INIT
+/* #define RMISEC_NO_SHA1_UPDATE */
+#define RMISEC_NO_SHA1_FINAL
+
+#include "vendor_defns/rmisec_wrapper.h"
+
+#define RMISEC_LIB_NAME "rmisec engine"
+#include "e_rmisec_err.c"
+
+#define FAIL_TO_SOFTWARE -15
+
+#define RMIHACK_BN_RMI_CONSTANT    0x0100    /* badness waiting to happen */
+
+
+static int engine_digests ( ENGINE *e, const EVP_MD **digest,
+                            const int **nids, int nid );
+static int engine_ciphers ( ENGINE *e, const EVP_CIPHER **cipher,
+                            const int **nids, int nid );
+
+static int rmisec_destroy(ENGINE *e);
+static int rmisec_init(ENGINE *e);
+static int rmisec_finish(ENGINE *e);
+static int rmisec_ctrl(ENGINE *e, int cmd, long i, void *p, void (*f)());
+
+static int openssl_rmisec_mod_exp(BIGNUM *r, const BIGNUM *a, const BIGNUM *p,
+				  const BIGNUM *m, BN_CTX *ctx, BN_MONT_CTX *m_ctx);
+
+#ifndef OPENSSL_NO_RSA
+static int rmisec_rsa_mod_exp(BIGNUM *r0, const BIGNUM *I, RSA *rsa, BN_CTX *ctx);
+#endif
+
+#ifndef OPENSSL_NO_DSA
+static int rmisec_dsa_mod_exp(DSA *dsa, BIGNUM *rr, BIGNUM *a1,
+        BIGNUM *p1, BIGNUM *a2, BIGNUM *p2, BIGNUM *m,
+        BN_CTX *ctx, BN_MONT_CTX *in_mont);
+
+static int rmisec_mod_exp_dsa(DSA *dsa, BIGNUM *r, BIGNUM *a,
+        const BIGNUM *p, const BIGNUM *m, BN_CTX *ctx,
+        BN_MONT_CTX *m_ctx);
+#endif
+
+#ifndef OPENSSL_NO_DH
+static int rmisec_dh_mod_exp(const DH *dh, BIGNUM *r, const BIGNUM *a,
+        const BIGNUM *p, const BIGNUM *m, BN_CTX *ctx,
+        BN_MONT_CTX *m_ctx);
+#endif
+
+#ifndef OPENSSL_NO_ECDSA
+static ECDSA_SIG *rmisec_ec_dsa_do_sign(const unsigned char *dgst, int dlen,
+                const BIGNUM *, const BIGNUM *, EC_KEY *eckey);
+static int rmisec_ec_dsa_sign_setup(EC_KEY *eckey, BN_CTX *ctx_in, BIGNUM **kinvp,
+                BIGNUM **rp);
+static int rmisec_ec_dsa_do_verify(const unsigned char *dgst, int dgst_len,
+                const ECDSA_SIG *sig, EC_KEY *eckey);
+#endif
+
+#ifndef OPENSSL_NO_EC
+static int rmisec_ec_gfp_add(const EC_GROUP *, EC_POINT *r, const EC_POINT *a, const EC_POINT *b, BN_CTX *);
+static int rmisec_ec_gfp_dbl(const EC_GROUP *, EC_POINT *r, const EC_POINT *a, BN_CTX *);
+static int rmisec_ec_gfp_is_on_curve(const EC_GROUP *, const EC_POINT *, BN_CTX *);
+static int rmisec_ec_gfp_mul(const EC_GROUP *group, EC_POINT *r, const BIGNUM *scalar,
+                size_t num, const EC_POINT *points[], const BIGNUM *scalars[], BN_CTX *);
+static int rmisec_ec_gfp_field_mul(const EC_GROUP *, BIGNUM *r, const BIGNUM *a, const BIGNUM *b, BN_CTX *);
+static int rmisec_ec_gfp_field_inv(const EC_GROUP *, BIGNUM *r, const BIGNUM *a, BN_CTX *) __attribute__((unused));
+static int rmisec_ec_gfp_field_div(const EC_GROUP *, BIGNUM *r, const BIGNUM *a, const BIGNUM *b, BN_CTX *) __attribute__((unused));
+static int rmisec_ec_gfp_field_red(const EC_GROUP *, BIGNUM *r, const BIGNUM *a, BN_CTX *) __attribute__((unused));
+static int rmisec_ec_gfp_field_add(const EC_GROUP *, BIGNUM *r, const BIGNUM *a, const BIGNUM *b, BN_CTX *) __attribute__((unused));
+static int rmisec_ec_gfp_field_sub(const EC_GROUP *, BIGNUM *r, const BIGNUM *a, const BIGNUM *b, BN_CTX *) __attribute__((unused));
+static int rmisec_ec_gfp_field_sqr(const EC_GROUP *, BIGNUM *r, const BIGNUM *a, BN_CTX *);
+static int rmisec_ec_gf2m_mul(const EC_GROUP *group, EC_POINT *r, const BIGNUM *scalar,
+                size_t num, const EC_POINT *points[], const BIGNUM *scalars[], BN_CTX *);
+static int rmisec_ec_gf2m_field_mul(const EC_GROUP *group, BIGNUM *r, const BIGNUM *a, const BIGNUM *b,BN_CTX *ctx);
+static int rmisec_ec_gf2m_field_sqr(const EC_GROUP *group, BIGNUM *r, const BIGNUM *a, BN_CTX *ctx);
+static int rmisec_ec_gf2m_field_div(const EC_GROUP *group, BIGNUM *r, const BIGNUM *a, const BIGNUM *b,BN_CTX *ctx);
+#endif
+
+#define RMISEC_CMD_SO_PATH      ENGINE_CMD_BASE
+#define RMISEC_CMD_RSA_TOGGLE_CRT	ENGINE_CMD_BASE + 1
+static const ENGINE_CMD_DEFN rmisec_cmd_defns[] = {
+    {RMISEC_CMD_SO_PATH,
+        "SO_PATH",
+        "Specifies the path to the 'rmisec' shared library",
+        ENGINE_CMD_FLAG_STRING},
+    {RMISEC_CMD_RSA_TOGGLE_CRT,
+        "RSA_TOGGLE_CRT",
+        "Control usage of CRT implementation in RSA.",
+        ENGINE_CMD_FLAG_NO_INPUT},
+    {0, NULL, NULL, 0}
+    };
+
+#ifndef OPENSSL_NO_RSA
+/* Our internal RSA_METHOD that we provide pointers to */
+static RSA_METHOD rmisec_rsa =
+    {
+    "RMISEC RSA method",
+    NULL,
+    NULL,
+    NULL,
+    NULL,
+    rmisec_rsa_mod_exp,
+    openssl_rmisec_mod_exp,
+    NULL,
+    NULL,
+    RSA_FLAG_CACHE_PUBLIC | RSA_FLAG_EXT_PKEY,
+    NULL,
+    NULL,
+    NULL
+    };
+#endif
+
+#ifndef OPENSSL_NO_DSA
+/* Our internal DSA_METHOD that we provide pointers to */
+static DSA_METHOD rmisec_dsa =
+    {
+    "RMISEC DSA method",
+    NULL,                /* dsa_do_sign */
+    NULL,                /* dsa_sign_setup */
+    NULL,                /* dsa_do_verify */
+    rmisec_dsa_mod_exp,  /* dsa_mod_exp */
+    rmisec_mod_exp_dsa,  /* bn_mod_exp */
+    NULL,                /* init */
+    NULL,                /* finish */
+    0,                   /* flags */
+    NULL,                /* app_data */
+    NULL,                /* dsa_paramgen */
+    NULL                 /* dsa_keygen */
+    };
+#endif
+
+#ifndef OPENSSL_NO_DH
+/* Our internal DH_METHOD that we provide pointers to */
+static DH_METHOD rmisec_dh =
+    {
+    "RMISEC DH method",
+    NULL,
+    NULL,
+    rmisec_dh_mod_exp,
+    NULL,
+    NULL,
+    DH_FLAG_CACHE_MONT_P,
+    NULL
+    };
+#endif
+
+#ifndef OPENSSL_NO_ECDSA
+/* Our internal ECDSA_METHOD that we provide pointers to */
+static ECDSA_METHOD rmisec_ec_dsa = {
+        "RMISEC ECDSA method",
+        rmisec_ec_dsa_do_sign,
+        rmisec_ec_dsa_sign_setup,
+        rmisec_ec_dsa_do_verify,
+#if 0
+        NULL, /* init     */
+        NULL, /* finish   */
+#endif
+        0,    /* flags    */
+        NULL  /* app_data */
+};
+#endif
+
+#ifndef OPENSSL_NO_EC
+static void print_ec_point(const EC_POINT *r) __attribute__((unused));
+
+static void print_ec_point(const EC_POINT *r)
+{
+	fprintf(stderr, "x=");
+	BN_print_fp(stderr, &r->X);
+	fprintf(stderr, "\ny=");
+	BN_print_fp(stderr, &r->Y);
+	fprintf(stderr, "\nz=");
+	BN_print_fp(stderr, &r->Z);
+	fprintf(stderr, "\n");
+	return;
+}
+
+
+/* Our internal EC_METHOD that we provide pointers to */
+static EC_METHOD rmisec_ec_gfp_nist = {
+	.add = rmisec_ec_gfp_add,
+	.dbl = rmisec_ec_gfp_dbl,
+	.is_on_curve = rmisec_ec_gfp_is_on_curve,
+	.mul = rmisec_ec_gfp_mul,
+	.field_mul = rmisec_ec_gfp_field_mul,
+	.field_sqr = rmisec_ec_gfp_field_sqr,
+};
+static EC_METHOD rmisec_ec_gfp_mont = {
+                .add = rmisec_ec_gfp_add,
+                .dbl = rmisec_ec_gfp_dbl,
+                .is_on_curve = rmisec_ec_gfp_is_on_curve,
+                .mul = rmisec_ec_gfp_mul,
+                .field_mul = rmisec_ec_gfp_field_mul,
+		.field_sqr = rmisec_ec_gfp_field_sqr,
+};
+static EC_METHOD rmisec_ec_gf2m_simple = {
+                .mul = rmisec_ec_gf2m_mul,
+                .field_mul = rmisec_ec_gf2m_field_mul,
+                .field_sqr = rmisec_ec_gf2m_field_sqr,
+                .field_div = rmisec_ec_gf2m_field_div,
+};
+#endif
+
+/* RSA CRT control flag. */
+static char rsa_crt_enabled = 1;
+static int crt_count = 0;
+
+/* Constants used when creating the ENGINE */
+static const char *engine_rmisec_id = "rmisec";
+static const char *engine_rmisec_name = "RMISEC hardware engine support";
+
+/* Global Device Descriptor */
+int RMISEC_GLOBAL_FD = -1;
+
+//#define DPK_CIPHER_DIGEST_OFF
+/* DEBUG CONTROL */
+//#define RMISEC_DEBUG
+
+#ifdef RMISEC_DEBUG
+/*  DEBUG HELPER */
+void print_buf (const char *desc, const void *data, int len)
+{
+    int i;
+    unsigned char *dp = (unsigned char *)data;
+
+    fprintf (stderr, "%s: ", desc);
+    for (i=0; i < len; i++) {
+        if ((i % 16) == 0) fprintf (stderr, "\n");
+        fprintf (stderr, " %02x", *dp++);
+    }
+    fprintf (stderr, "\n");
+    fflush(stderr);
+}
+#endif /* RMISEC_DEBUG */
+
+#ifdef RMISEC_DEBUG
+#define DBG_PRINT(fmt, args...) { \
+            fprintf(stderr, fmt, ##args); \
+            fflush(stderr); \
+        }
+#define DBG_PRINT_BUF(hdr, buf, len) { \
+            print_buf((hdr), (buf), (len)); \
+        }
+#else
+#define DBG_PRINT(fmt, args...)
+#define DBG_PRINT_BUF(hdr, buf, len)
+#endif /* RMISEC_DEBUG */
+
+#ifndef OPENSSL_NO_EC
+static void rmisec_ec_copy(EC_METHOD *rmisec_ec_gfp, const EC_METHOD *meth_ec) {
+    rmisec_ec_gfp->field_type = meth_ec->field_type;
+    rmisec_ec_gfp->group_init = meth_ec->group_init;
+    rmisec_ec_gfp->group_finish = meth_ec->group_finish;
+    rmisec_ec_gfp->group_clear_finish = meth_ec->group_clear_finish;
+    rmisec_ec_gfp->group_copy = meth_ec->group_copy;
+    rmisec_ec_gfp->group_set_curve = meth_ec->group_set_curve;
+    rmisec_ec_gfp->group_get_curve = meth_ec->group_get_curve;
+    rmisec_ec_gfp->group_get_degree = meth_ec->group_get_degree;
+    rmisec_ec_gfp->group_check_discriminant = meth_ec->group_check_discriminant;
+    rmisec_ec_gfp->point_init = meth_ec->point_init;
+    rmisec_ec_gfp->point_finish = meth_ec->point_finish;
+    rmisec_ec_gfp->point_clear_finish = meth_ec->point_clear_finish;
+    rmisec_ec_gfp->point_copy = meth_ec->point_copy;
+    rmisec_ec_gfp->point_set_to_infinity = meth_ec->point_set_to_infinity;
+    rmisec_ec_gfp->point_set_Jprojective_coordinates_GFp = meth_ec->point_set_Jprojective_coordinates_GFp;
+    rmisec_ec_gfp->point_get_Jprojective_coordinates_GFp = meth_ec->point_get_Jprojective_coordinates_GFp;
+    rmisec_ec_gfp->point_set_affine_coordinates = meth_ec->point_set_affine_coordinates;
+    rmisec_ec_gfp->point_get_affine_coordinates = meth_ec->point_get_affine_coordinates;
+    rmisec_ec_gfp->point_set_compressed_coordinates = meth_ec->point_set_compressed_coordinates;
+    rmisec_ec_gfp->point2oct = meth_ec->point2oct;
+    rmisec_ec_gfp->oct2point = meth_ec->oct2point;
+    rmisec_ec_gfp->is_at_infinity = meth_ec->is_at_infinity;
+    rmisec_ec_gfp->invert = meth_ec->invert;
+    rmisec_ec_gfp->make_affine = meth_ec->make_affine;
+    rmisec_ec_gfp->points_make_affine = meth_ec->points_make_affine;
+    rmisec_ec_gfp->field_encode = meth_ec->field_encode;
+    rmisec_ec_gfp->field_decode = meth_ec->field_decode;
+    rmisec_ec_gfp->field_set_to_one = meth_ec->field_set_to_one;
+}
+static void rmisec_ec_gfp_copy(EC_METHOD *rmisec_ec_gfp, const EC_METHOD *meth_ec) {
+    rmisec_ec_copy(rmisec_ec_gfp, meth_ec);
+}
+static void rmisec_ec_gf2m_copy(EC_METHOD *rmisec_ec_gf2m, const EC_METHOD *meth_ec) {
+    rmisec_ec_gf2m->add = meth_ec->add;
+    rmisec_ec_gf2m->dbl = meth_ec->dbl;
+    rmisec_ec_gf2m->is_on_curve = meth_ec->is_on_curve;
+    rmisec_ec_copy(rmisec_ec_gf2m, meth_ec);
+}
+#endif
+
+/* This internal function is used by ENGINE_rmisec() and possibly by the
+ * "dynamic" ENGINE support too */
+static int bind_helper(ENGINE *e)
+    {
+	init_cached_proc_id();
+#ifndef OPENSSL_NO_RSA
+    const RSA_METHOD *meth_rsa;
+#endif
+#ifndef OPENSSL_NO_DSA
+    const DSA_METHOD  *meth_dsa;
+#endif
+#ifndef OPENSSL_NO_DH
+    const DH_METHOD *meth_dh;
+#endif
+#ifndef OPENSSL_NO_ECDSA
+    const ECDSA_METHOD  *meth_ecdsa;
+#endif
+    if(!ENGINE_set_id(e, engine_rmisec_id) ||
+            !ENGINE_set_name(e, engine_rmisec_name) ||
+#ifndef OPENSSL_NO_RSA
+            !ENGINE_set_RSA(e, &rmisec_rsa) ||
+#endif
+#ifndef OPENSSL_NO_DSA
+            !ENGINE_set_DSA(e, &rmisec_dsa) ||
+#endif
+#ifndef OPENSSL_NO_ECDSA
+            (is_xls() &&
+            !ENGINE_set_ECDSA(e, &rmisec_ec_dsa)) ||
+#endif
+#ifndef OPENSSL_NO_EC
+            (is_xls() &&
+            (!ENGINE_set_EC_GFp_nist(e, &rmisec_ec_gfp_nist) ||
+            !ENGINE_set_EC_GFp_mont(e, &rmisec_ec_gfp_mont) ||
+            !ENGINE_set_EC_GF2m_simple(e, &rmisec_ec_gf2m_simple))) ||
+#endif
+#ifndef OPENSSL_NO_DH
+            !ENGINE_set_DH(e, &rmisec_dh) ||
+#endif
+            !ENGINE_set_destroy_function(e, rmisec_destroy) ||
+            !ENGINE_set_init_function(e, rmisec_init) ||
+            !ENGINE_set_finish_function(e, rmisec_finish) ||
+            !ENGINE_set_ctrl_function(e, rmisec_ctrl) ||
+#ifdef DPK_CIPHER_DIGEST_OFF
+            !ENGINE_set_cmd_defns(e, rmisec_cmd_defns) ) {
+#else
+            !ENGINE_set_cmd_defns(e, rmisec_cmd_defns) ||
+            !ENGINE_set_digests ( e, engine_digests ) ||
+            !ENGINE_set_ciphers ( e, engine_ciphers ) ) {
+#endif
+        return 0;
+    }
+#ifndef OPENSSL_NO_RSA
+    /* We know that the "PKCS1_SSLeay()" functions hook properly
+     * to the RMI-specific mod_exp and mod_exp_crt so we use
+     * those functions. NB: We don't use ENGINE_openssl() or
+     * anything "more generic" because something like the RSAref
+     * code may not hook properly, and if you own one of these
+     * cards then you have the right to do RSA operations on it
+     * anyway! */
+    meth_rsa = RSA_PKCS1_SSLeay();
+
+    rmisec_rsa.rsa_pub_enc = meth_rsa->rsa_pub_enc;
+    rmisec_rsa.rsa_pub_dec = meth_rsa->rsa_pub_dec;
+    rmisec_rsa.rsa_priv_enc = meth_rsa->rsa_priv_enc;
+    rmisec_rsa.rsa_priv_dec = meth_rsa->rsa_priv_dec;
+#endif
+
+#ifndef OPENSSL_NO_DSA
+    /* Use the DSA_OpenSSL() method and just hook the mod_exp-ish
+     * bits. */
+    meth_dsa = DSA_OpenSSL();
+    rmisec_dsa.dsa_do_sign    = meth_dsa->dsa_do_sign;
+    rmisec_dsa.dsa_sign_setup = meth_dsa->dsa_sign_setup;
+    rmisec_dsa.dsa_do_verify  = meth_dsa->dsa_do_verify;
+
+    rmisec_dsa = *DSA_get_default_method();
+    rmisec_dsa.dsa_mod_exp = rmisec_dsa_mod_exp;
+    rmisec_dsa.bn_mod_exp = rmisec_mod_exp_dsa;
+#endif
+
+#ifndef OPENSSL_NO_DH
+    /* Much the same for Diffie-Hellman */
+    meth_dh = DH_OpenSSL();
+    rmisec_dh.generate_key = meth_dh->generate_key;
+    rmisec_dh.compute_key = meth_dh->compute_key;
+#endif
+
+    if (is_xls()) {
+#ifndef OPENSSL_NO_ECDSA
+        meth_ecdsa = ECDSA_OpenSSL();
+        rmisec_ec_dsa.ecdsa_do_sign    = meth_ecdsa->ecdsa_do_sign;
+        rmisec_ec_dsa.ecdsa_sign_setup = meth_ecdsa->ecdsa_sign_setup;
+        rmisec_ec_dsa.ecdsa_do_verify  = meth_ecdsa->ecdsa_do_verify;
+#endif
+
+#ifndef OPENSSL_NO_EC
+        rmisec_ec_gfp_copy(&rmisec_ec_gfp_nist, EC_GFp_nist_method());
+        rmisec_ec_gfp_copy(&rmisec_ec_gfp_mont, EC_GFp_mont_method());
+        rmisec_ec_gf2m_copy(&rmisec_ec_gf2m_simple, EC_GF2m_simple_method());
+#endif
+    }
+
+    /* Ensure the rmisec error handling is set up */
+    ERR_load_RMISEC_strings();
+    return 1;
+    }
+
+#ifdef OPENSSL_NO_DYNAMIC_ENGINE
+static ENGINE *engine_rmisec(void)
+{
+	ENGINE *ret = NULL;
+
+	ret = ENGINE_new();
+	if(!ret) {
+		RMISECerr(RMISEC_F_RMISEC_INIT, RMISEC_R_MEM_ALLOC_FAILURE);
+		return NULL;
+	}
+
+	if(!rmisec_init(ret)) {
+		return NULL;
+	}
+
+
+	if(!bind_helper(ret)) {
+		rmisec_finish(ret);
+		ENGINE_free(ret);
+		return NULL;
+	}
+
+	return ret;
+}
+
+void ENGINE_load_rmisec(void)
+{
+	/* Copied from eng_[openssl|dyn].c */
+	ENGINE *toadd = engine_rmisec();
+	if(!toadd) return;
+	if(ENGINE_add(toadd) == 0) {
+		RMISECerr(RMISEC_F_RMISEC_INIT, RMISEC_R_DSO_FAILURE);
+	}
+	ENGINE_free(toadd);
+	ERR_clear_error();
+}
+#endif
+
+/*
+ * This is a process-global DSO handle used for loading and unloading
+ * the RMISEC library.
+ * NB: This is only set (or unset) during an * init() or finish() call
+ * (reference counts permitting) and they're operating with global locks,
+ * so this should be thread-safe implicitly.
+ */
+static DSO *rmisec_dso = NULL;
+
+/*
+ * These are the function pointers that are (un)set when the library has
+ * successfully (un)loaded.
+ */
+static t_RMISEC_bytes_to_bits *p_RMISEC_bytes_to_bits = NULL;
+static t_RMISEC_bits_to_bytes *p_RMISEC_bits_to_bytes = NULL;
+
+static t_RMISEC_open  *p_RMISEC_open = NULL;
+static t_RMISEC_close *p_RMISEC_close = NULL;
+static t_RMISEC_op_init  *p_RMISEC_op_init = NULL;
+static t_RMISEC_op_cleanup *p_RMISEC_op_cleanup = NULL;
+
+#if !(defined(OPENSSL_NO_RSA) && defined(OPENSSL_NO_DH))
+static t_RMISEC_mod_exp     *p_RMISEC_mod_exp = NULL;
+#endif /* OPENSSL_NO_DH && OPENSSL_NO_RSA */
+
+#ifndef OPENSSL_NO_ECC
+static t_RMISEC_ecc_gfp_mul *p_RMISEC_ecc_gfp_mul = NULL;
+static t_RMISEC_ecc_gfp_add *p_RMISEC_ecc_gfp_add = NULL;
+static t_RMISEC_ecc_gfp_dbl *p_RMISEC_ecc_gfp_dbl = NULL;
+static t_RMISEC_ecc_gfp_vfy *p_RMISEC_ecc_gfp_vfy = NULL;
+static t_RMISEC_ecc_gf2m_mul *p_RMISEC_ecc_gf2m_mul = NULL;
+static t_RMISEC_ecc_gfp_field_mul *p_RMISEC_ecc_gfp_field_mul = NULL;
+static t_RMISEC_ecc_gfp_field_div *p_RMISEC_ecc_gfp_field_div = NULL;
+static t_RMISEC_ecc_gfp_field_inv *p_RMISEC_ecc_gfp_field_inv = NULL;
+static t_RMISEC_ecc_gfp_field_red *p_RMISEC_ecc_gfp_field_red = NULL;
+static t_RMISEC_ecc_gfp_field_add *p_RMISEC_ecc_gfp_field_add = NULL;
+static t_RMISEC_ecc_gfp_field_sub *p_RMISEC_ecc_gfp_field_sub = NULL;
+static t_RMISEC_ecc_gf2m_field_mul *p_RMISEC_ecc_gf2m_field_mul = NULL;
+static t_RMISEC_ecc_gf2m_field_inv *p_RMISEC_ecc_gf2m_field_inv = NULL;
+#endif /* OPENSSL_NO_ECC */
+
+#ifndef OPENSSL_NO_MD5
+static t_RMISEC_md5  *p_RMISEC_md5 = NULL ;
+#endif /* OPENSSL_NO_MD5 */
+
+#ifndef OPENSSL_NO_SHA
+#ifndef OPENSSL_NO_SHA1
+static t_RMISEC_sha1  *p_RMISEC_sha1 = NULL ;
+#endif /* OPENSSL_NO_SHA1 */
+#ifndef OPENSSL_NO_SHA256
+static t_RMISEC_sha256  *p_RMISEC_sha256 = NULL ;
+#endif /* OPENSSL_NO_SHA256 */
+#ifndef OPENSSL_NO_SHA384
+static t_RMISEC_sha384  *p_RMISEC_sha384 = NULL ;
+#endif /* OPENSSL_NO_SHA1 */
+#ifndef OPENSSL_NO_SHA512
+static t_RMISEC_sha512  *p_RMISEC_sha512 = NULL ;
+#endif /* OPENSSL_NO_SHA512 */
+#endif /* OPENSSL_NO_SHA */
+
+#ifndef OPENSSL_NO_DES
+static t_RMISEC_des_cipher *p_RMISEC_des_cipher = NULL ;
+static t_RMISEC_des_cipher *p_RMISEC_3des_cipher = NULL ;
+#endif /* OPENSSL_NO_DES */
+
+#ifndef OPENSSL_NO_AES
+static t_RMISEC_aes128_cipher  *p_RMISEC_aes128_cipher = NULL ;
+static t_RMISEC_aes192_cipher  *p_RMISEC_aes192_cipher = NULL ;
+static t_RMISEC_aes256_cipher  *p_RMISEC_aes256_cipher = NULL ;
+#endif /* OPENSSL_NO_AES */
+#if 0
+#ifndef OPENSSL_NO_RC4
+static t_RMISEC_arc4_cipher  *p_RMISEC_arc4_cipher = NULL ;
+#endif /* OPENSSL_NO_RC4 */
+#endif /* 0 */
+
+const static int max_key_len = 1024;  /* Phoenix Ver 1.0 */
+
+#ifdef ENGINE_DYNAMIC_SUPPORT
+extern t_RMISEC_bytes_to_bits rmilib_bytes_to_bits;
+extern t_RMISEC_bits_to_bytes rmilib_bits_to_bytes;
+extern t_RMISEC_open rmilib_open;
+extern t_RMISEC_close rmilib_close;
+
+#if !(defined(OPENSSL_NO_RSA) && defined(OPENSSL_NO_DH))
+extern t_RMISEC_mod_exp rmilib_mod_exp;
+#endif
+#ifndef OPENSSL_NO_ECC
+extern t_RMISEC_ecc_gfp_mul rmilib_ecc_gfp_mul;
+extern t_RMISEC_ecc_gfp_add rmilib_ecc_gfp_add;
+extern t_RMISEC_ecc_gfp_dbl rmilib_ecc_gfp_dbl;
+extern t_RMISEC_ecc_gfp_vfy rmilib_ecc_gfp_vfy;
+extern t_RMISEC_ecc_gf2m_mul rmilib_ecc_gf2m_mul;
+extern t_RMISEC_ecc_gfp_field_mul rmilib_ecc_gfp_field_mul;
+extern t_RMISEC_ecc_gfp_field_div rmilib_ecc_gfp_field_div;
+extern t_RMISEC_ecc_gfp_field_inv rmilib_ecc_gfp_field_inv;
+extern t_RMISEC_ecc_gfp_field_red rmilib_ecc_gfp_field_red;
+extern t_RMISEC_ecc_gfp_field_add rmilib_ecc_gfp_field_add;
+extern t_RMISEC_ecc_gfp_field_sub rmilib_ecc_gfp_field_sub;
+extern t_RMISEC_ecc_gf2m_field_mul rmilib_ecc_gf2m_field_mul;
+extern t_RMISEC_ecc_gf2m_field_inv rmilib_ecc_gf2m_field_inv;
+#endif
+#ifndef OPENSSL_NO_MD5
+extern t_RMISEC_md5 rmilib_md5 ;
+#endif /* OPENSSL_NO_MD5 */
+#ifndef OPENSSL_NO_SHA
+#ifndef OPENSSL_NO_SHA1
+extern t_RMISEC_sha1 rmilib_sha1 ;
+#endif /* OPENSSL_NO_SHA1 */
+#ifndef OPENSSL_NO_SHA256
+extern t_RMISEC_sha256 rmilib_sha256 ;
+#endif /* OPENSSL_NO_SHA256 */
+#ifndef OPENSSL_NO_SHA384
+extern t_RMISEC_sha384 rmilib_sha384 ;
+#endif /* OPENSSL_NO_SHA384 */
+#ifndef OPENSSL_NO_SHA512
+extern t_RMISEC_sha512 rmilib_sha512 ;
+#endif /* OPENSSL_NO_SHA512 */
+#endif /* OPENSSL_NO_SHA */
+#ifndef OPENSSL_NO_DES
+extern t_RMISEC_des_cipher rmilib_des_cipher ;
+extern t_RMISEC_3des_cipher rmilib_3des_cipher ;
+#endif /* OPENSSL_NO_DES */
+#ifndef OPENSSL_NO_AES
+extern t_RMISEC_aes128_cipher rmilib_aes128_cipher ;
+extern t_RMISEC_aes192_cipher rmilib_aes192_cipher ;
+extern t_RMISEC_aes256_cipher rmilib_aes256_cipher ;
+#endif /* OPENSSL_NO_AES */
+#if 0
+#ifndef OPENSSL_NO_RC4
+extern t_RMISEC_arc4_cipher rmilib_arc4_cipher ;
+#endif /* OPENSSL_NO_RC4 */
+#endif /* 0 */
+#else /* ENGINE_DYNAMIC_SUPPORT */
+/*
+ * These are the static string constants for the DSO file name and the function
+ * symbol names to bind to.
+ */
+static const char *RMISEC_LIBNAME = NULL;
+static const char *get_RMISEC_LIBNAME(void)
+{
+    if(RMISEC_LIBNAME)
+        return RMISEC_LIBNAME;
+    return "rmisec_lib";
+}
+static void free_RMISEC_LIBNAME(void)
+{
+    if(RMISEC_LIBNAME)
+        OPENSSL_free((void *)RMISEC_LIBNAME);
+    RMISEC_LIBNAME = NULL;
+}
+static long set_RMISEC_LIBNAME(const char *name)
+{
+    free_RMISEC_LIBNAME();
+    return (((RMISEC_LIBNAME = BUF_strdup(name)) != NULL) ? 1 : 0);
+}
+
+
+static const char *RMISEC_F1 = "rmisec_bytes_to_bits";
+static const char *RMISEC_F2 = "rmisec_bits_to_bytes";
+static const char *RMISEC_F3 = "rmisec_lib_init";
+static const char *RMISEC_F4 = "rmisec_lib_cleanup";
+
+#if !(defined(OPENSSL_NO_RSA) && defined(OPENSSL_NO_DH))
+static const char *RMISEC_F5 = "rmisec_mod_exp";
+#endif
+#ifndef OPENSSL_NO_ECC
+static const char *RMISEC_F17 = "rmisec_ecc_gfp_mul";
+static const char *RMISEC_F18 = "rmisec_ecc_gfp_add";
+static const char *RMISEC_F19 = "rmisec_ecc_gfp_dbl";
+static const char *RMISEC_F20 = "rmisec_ecc_gfp_vfy";
+static const char *RMISEC_F21 = "rmisec_ecc_gf2m_mul";
+static const char *RMISEC_F22 = "rmisec_ecc_gfp_field_mul";
+static const char *RMISEC_F23 = "rmisec_ecc_gfp_field_div";
+static const char *RMISEC_F24 = "rmisec_ecc_gf2m_field_mul";
+static const char *RMISEC_F25 = "rmisec_ecc_gf2m_field_inv";
+static const char *RMISEC_F26 = "rmisec_ecc_gfp_field_inv";
+static const char *RMISEC_F27 = "rmisec_ecc_gfp_field_div";
+static const char *RMISEC_F28 = "rmisec_ecc_gfp_field_red";
+static const char *RMISEC_F29 = "rmisec_ecc_gfp_field_add";
+static const char *RMISEC_F30 = "rmisec_ecc_gfp_field_sub";
+static const char *RMISEC_F31 = "rmisec_op_init";
+static const char *RMISEC_F32 = "rmisec_op_cleanup";
+
+#endif /* OPENSSL_NO_ECC */
+#ifndef OPENSSL_NO_MD5
+static const char *RMISEC_F6 = "rmisec_md5" ;
+#endif /* OPENSSL_NO_MD5 */
+#ifndef OPENSSL_NO_SHA
+#ifndef OPENSSL_NO_SHA1
+static const char *RMISEC_F7 = "rmisec_sha1" ;
+#endif /* OPENSSL_NO_SHA1 */
+#ifndef OPENSSL_NO_SHA256
+static const char *RMISEC_F14 = "rmisec_sha256" ;
+#endif /* OPENSSL_NO_SHA256 */
+#ifndef OPENSSL_NO_SHA384
+static const char *RMISEC_F15 = "rmisec_sha384" ;
+#endif /* OPENSSL_NO_SHA384 */
+#ifndef OPENSSL_NO_SHA512
+static const char *RMISEC_F16 = "rmisec_sha512" ;
+#endif /* OPENSSL_NO_SHA512 */
+#endif /* OPENSSL_NO_SHA */
+#ifndef OPENSSL_NO_DES
+static const char *RMISEC_F8 = "rmisec_des_cipher" ;
+static const char *RMISEC_F9 = "rmisec_3des_cipher" ;
+#endif /* OPENSSL_NO_DES */
+#ifndef OPENSSL_NO_AES
+static const char *RMISEC_F10 = "rmisec_aes128_cipher" ;
+static const char *RMISEC_F13 = "rmisec_aes192_cipher" ;
+static const char *RMISEC_F11 = "rmisec_aes256_cipher" ;
+#endif /* OPENSSL_NO_AES */
+#if 0
+#ifndef OPENSSL_NO_RC4
+static const char *RMISEC_F12 = "rmisec_arc4_cipher" ;
+#endif /* OPENSSL_NO_RC4 */
+#endif /* 0 */
+#endif /* ENGINE_DYNAMIC_SUPPORT */
+
+/* Destructor (complements the "ENGINE_rmisec()" constructor) */
+static int rmisec_destroy(ENGINE *e)
+{
+#ifndef ENGINE_DYNAMIC_SUPPORT
+    free_RMISEC_LIBNAME();
+#endif /* ENGINE_DYNAMIC_SUPPORT */
+    ERR_unload_RMISEC_strings();
+    return 1;
+}
+
+/* initialisation functions. */
+static int rmisec_init(ENGINE *e)
+{
+	int fd;
+#ifndef ENGINE_DYNAMIC_SUPPORT
+    t_RMISEC_bytes_to_bits *p1 = NULL;
+    t_RMISEC_bits_to_bytes *p2 = NULL;
+    t_RMISEC_open          *p3 = NULL;
+    t_RMISEC_close         *p4 = NULL;
+#if !(defined(OPENSSL_NO_RSA) && defined(OPENSSL_NO_DH))
+    t_RMISEC_mod_exp       *p5 = NULL;
+#endif
+#ifndef OPENSSL_NO_ECC
+    t_RMISEC_ecc_gfp_mul  *p17 = NULL;
+    t_RMISEC_ecc_gfp_add  *p18 = NULL;
+    t_RMISEC_ecc_gfp_dbl  *p19 = NULL;
+    t_RMISEC_ecc_gfp_vfy  *p20 = NULL;
+    t_RMISEC_ecc_gf2m_mul *p21 = NULL;
+    t_RMISEC_ecc_gfp_field_mul *p22 = NULL;
+    t_RMISEC_ecc_gfp_field_div *p23 = NULL;
+    t_RMISEC_ecc_gf2m_field_mul *p24 = NULL;
+    t_RMISEC_ecc_gf2m_field_inv *p25 = NULL;
+    t_RMISEC_ecc_gfp_field_inv *p26 = NULL;
+    t_RMISEC_ecc_gfp_field_div *p27 = NULL;
+    t_RMISEC_ecc_gfp_field_red *p28 = NULL;
+    t_RMISEC_ecc_gfp_field_add *p29 = NULL;
+    t_RMISEC_ecc_gfp_field_sub *p30 = NULL;
+    t_RMISEC_op_init           *p31 = NULL;
+    t_RMISEC_op_cleanup        *p32 = NULL;
+#endif
+#ifndef OPENSSL_NO_MD5
+    t_RMISEC_md5           *p6 = NULL;
+#endif /* OPENSSL_NO_MD5 */
+#ifndef OPENSSL_NO_SHA
+#ifndef OPENSSL_NO_SHA1
+    t_RMISEC_sha1          *p7 = NULL;
+#endif /* OPENSSL_NO_SHA1 */
+#ifndef OPENSSL_NO_SHA256
+    t_RMISEC_sha256        *p14 = NULL;
+#endif /* OPENSSL_NO_SHA256 */
+#ifndef OPENSSL_NO_SHA384
+    t_RMISEC_sha384        *p15 = NULL;
+#endif /* OPENSSL_NO_SHA384 */
+#ifndef OPENSSL_NO_SHA512
+    t_RMISEC_sha512        *p16 = NULL;
+#endif /* OPENSSL_NO_SHA512 */
+#endif /* OPENSSL_NO_SHA */
+#ifndef OPENSSL_NO_DES
+    t_RMISEC_des_cipher    *p8 = NULL;
+    t_RMISEC_3des_cipher   *p9 = NULL;
+#endif /* OPENSSL_NO_DES */
+#ifndef OPENSSL_NO_AES
+    t_RMISEC_aes128_cipher *p10 = NULL;
+    t_RMISEC_aes192_cipher *p13 = NULL;
+    t_RMISEC_aes256_cipher *p11 = NULL;
+#endif /* OPENSSL_NO_AES */
+#if 0
+#ifndef OPENSSL_NO_RC4
+    t_RMISEC_arc4_cipher *p12 = NULL;
+#endif /* OPENSSL_NO_RC4 */
+#endif /* 0 */
+
+
+    DBG_PRINT("%s:%d Initializing OpenSSL Engine for RMI SAE\n",
+	      __FUNCTION__, __LINE__);
+    if(rmisec_dso != NULL)
+    {
+        RMISECerr(RMISEC_F_RMISEC_INIT, RMISEC_R_ALREADY_LOADED);
+        goto err;
+    }
+
+    /*
+     * Attempt to load librmisec.so/rmisec.dll/whatever.
+     */
+    rmisec_dso = DSO_load(NULL, get_RMISEC_LIBNAME(), NULL, 0);
+    if(rmisec_dso == NULL)
+    {
+        RMISECerr(RMISEC_F_RMISEC_INIT, RMISEC_R_DSO_FAILURE);
+        goto err;
+    }
+
+    if (!(p1 = (t_RMISEC_bytes_to_bits *) DSO_bind_func(rmisec_dso, RMISEC_F1)) ||
+        !(p2 = (t_RMISEC_bits_to_bytes *) DSO_bind_func(rmisec_dso, RMISEC_F2)) ||
+        !(p3 = (t_RMISEC_open *) DSO_bind_func(rmisec_dso, RMISEC_F3)) ||
+        !(p4 = (t_RMISEC_close *) DSO_bind_func(rmisec_dso, RMISEC_F4)) ||
+#if !(defined(OPENSSL_NO_RSA) && defined(OPENSSL_NO_DH))
+        !(p5 = (t_RMISEC_mod_exp *)
+                    DSO_bind_func(rmisec_dso, RMISEC_F5)) ||
+#endif
+#ifndef OPENSSL_NO_ECC
+        !(p17 = (t_RMISEC_ecc_gfp_mul *) DSO_bind_func(rmisec_dso, RMISEC_F17)) ||
+        !(p18 = (t_RMISEC_ecc_gfp_add *) DSO_bind_func(rmisec_dso, RMISEC_F18)) ||
+        !(p19 = (t_RMISEC_ecc_gfp_dbl *) DSO_bind_func(rmisec_dso, RMISEC_F19)) ||
+        !(p20 = (t_RMISEC_ecc_gfp_vfy *) DSO_bind_func(rmisec_dso, RMISEC_F20)) ||
+        !(p21 = (t_RMISEC_ecc_gf2m_mul *) DSO_bind_func(rmisec_dso, RMISEC_F21)) ||
+        !(p22 = (t_RMISEC_ecc_gfp_field_mul *) DSO_bind_func(rmisec_dso, RMISEC_F22)) ||
+        !(p23 = (t_RMISEC_ecc_gfp_field_div *) DSO_bind_func(rmisec_dso, RMISEC_F23)) ||
+        !(p24 = (t_RMISEC_ecc_gf2m_field_mul *) DSO_bind_func(rmisec_dso, RMISEC_F24)) ||
+        !(p25 = (t_RMISEC_ecc_gf2m_field_inv *) DSO_bind_func(rmisec_dso, RMISEC_F25)) ||
+        !(p26 = (t_RMISEC_ecc_gfp_field_inv *) DSO_bind_func(rmisec_dso, RMISEC_F26)) ||
+        !(p27 = (t_RMISEC_ecc_gfp_field_div *) DSO_bind_func(rmisec_dso, RMISEC_F27)) ||
+        !(p28 = (t_RMISEC_ecc_gfp_field_red *) DSO_bind_func(rmisec_dso, RMISEC_F28)) ||
+        !(p29 = (t_RMISEC_ecc_gfp_field_add *) DSO_bind_func(rmisec_dso, RMISEC_F29)) ||
+        !(p30 = (t_RMISEC_ecc_gfp_field_sub *) DSO_bind_func(rmisec_dso, RMISEC_F30)) ||
+        !(p31 = (t_RMISEC_op_init *) DSO_bind_func(rmisec_dso, RMISEC_F31)) ||
+        !(p32 = (t_RMISEC_op_cleanup *) DSO_bind_func(rmisec_dso, RMISEC_F32)) ||
+#endif
+#ifndef OPENSSL_NO_MD5
+        !(p6 = (t_RMISEC_md5 *) DSO_bind_func(rmisec_dso, RMISEC_F6)) ||
+#endif /* OPENSSL_NO_MD5 */
+#ifndef OPENSSL_NO_SHA
+#ifndef OPENSSL_NO_SHA1
+        !(p7 = (t_RMISEC_sha1 *) DSO_bind_func(rmisec_dso, RMISEC_F7)) ||
+#endif /* OPENSSL_NO_SHA1 */
+#ifndef OPENSSL_NO_SHA256
+        !(p14 = (t_RMISEC_sha256 *) DSO_bind_func(rmisec_dso, RMISEC_F14)) ||
+#endif /* OPENSSL_NO_SHA256 */
+#ifndef OPENSSL_NO_SHA384
+        !(p15 = (t_RMISEC_sha384 *) DSO_bind_func(rmisec_dso, RMISEC_F15)) ||
+#endif /* OPENSSL_NO_SHA384 */
+#ifndef OPENSSL_NO_SHA512
+        !(p16 = (t_RMISEC_sha512 *) DSO_bind_func(rmisec_dso, RMISEC_F16)) ||
+#endif /* OPENSSL_NO_SHA512 */
+#endif /* OPENSSL_NO_SHA */
+#ifndef OPENSSL_NO_DES
+        !(p8 = (t_RMISEC_des_cipher *) DSO_bind_func(rmisec_dso, RMISEC_F8)) ||
+        !(p9 = (t_RMISEC_3des_cipher *) DSO_bind_func(rmisec_dso, RMISEC_F9)) ||
+#endif /* OPENSSL_NO_DES */
+#ifndef OPENSSL_NO_AES
+        !(p10 = (t_RMISEC_aes128_cipher *)
+                    DSO_bind_func(rmisec_dso, RMISEC_F10)) ||
+        !(p13 = (t_RMISEC_aes192_cipher *)
+                    DSO_bind_func(rmisec_dso, RMISEC_F13)) ||
+        !(p11 = (t_RMISEC_aes256_cipher *)
+                    DSO_bind_func(rmisec_dso, RMISEC_F11)) ||
+#endif /* OPENSSL_NO_AES */
+#if 0
+#ifndef OPENSSL_NO_RC4
+        !(p12 = (t_RMISEC_arc4_cipher *)
+                    DSO_bind_func(rmisec_dso, RMISEC_F12)) ||
+#endif /* OPENSSL_NO_RC4 */
+#endif /* 0 */
+        (0))
+    {
+        RMISECerr(RMISEC_F_RMISEC_INIT, RMISEC_R_DSO_FAILURE);
+        goto err;
+    }
+
+    /* Copy the pointers */
+    p_RMISEC_bytes_to_bits = p1;
+    p_RMISEC_bits_to_bytes = p2;
+    p_RMISEC_open = p3;
+    p_RMISEC_close = p4;
+#if !(defined(OPENSSL_NO_RSA) && defined(OPENSSL_NO_DH))
+    p_RMISEC_mod_exp = p5;
+#endif
+#ifndef OPENSSL_NO_ECC
+    p_RMISEC_ecc_gfp_mul = p17;
+    p_RMISEC_ecc_gfp_add = p18;
+    p_RMISEC_ecc_gfp_dbl = p19;
+    p_RMISEC_ecc_gfp_vfy = p20;
+    p_RMISEC_ecc_gf2m_mul = p21;
+    p_RMISEC_ecc_gfp_field_mul = p22;
+    p_RMISEC_ecc_gfp_field_div = p23;
+    p_RMISEC_ecc_gf2m_field_mul = p24;
+    p_RMISEC_ecc_gf2m_field_inv = p25;
+    p_RMISEC_ecc_gfp_field_inv = p26;
+    p_RMISEC_ecc_gfp_field_div = p27;
+    p_RMISEC_ecc_gfp_field_red = p28;
+    p_RMISEC_ecc_gfp_field_add = p29;
+    p_RMISEC_ecc_gfp_field_sub = p30;
+    p_RMISEC_op_init = p31;
+    p_RMISEC_op_cleanup = p32;
+#endif
+#ifndef OPENSSL_NO_MD5
+    p_RMISEC_md5 = p6;
+#endif /* OPENSSL_NO_MD5 */
+#ifndef OPENSSL_NO_SHA
+#ifndef OPENSSL_NO_SHA1
+    p_RMISEC_sha1 = p7;
+#endif /* OPENSSL_NO_SHA1 */
+#ifndef OPENSSL_NO_SHA256
+    p_RMISEC_sha256 = p14;
+#endif /* OPENSSL_NO_SHA256 */
+#ifndef OPENSSL_NO_SHA384
+    p_RMISEC_sha384 = p15;
+#endif /* OPENSSL_NO_SHA384 */
+#ifndef OPENSSL_NO_SHA512
+    p_RMISEC_sha512 = p16;
+#endif /* OPENSSL_NO_SHA512 */
+#endif /* OPENSSL_NO_SHA */
+#ifndef OPENSSL_NO_DES
+    p_RMISEC_des_cipher = p8;
+    p_RMISEC_3des_cipher = p9;
+#endif /* OPENSSL_NO_DES */
+#ifndef OPENSSL_NO_AES
+    p_RMISEC_aes128_cipher = p10;
+    p_RMISEC_aes192_cipher = p13;
+    p_RMISEC_aes256_cipher = p11;
+#endif /* OPENSSL_NO_AES */
+#if 0
+#ifndef OPENSSL_NO_RC4
+    p_RMISEC_arc4_cipher = p12;
+#endif /* OPENSSL_NO_RC4 */
+#endif /* 0 */
+
+
+#else /* ENGINE_DYNAMIC_SUPPORT */
+
+
+
+    p_RMISEC_bytes_to_bits = rmisec_bytes_to_bits;
+    p_RMISEC_bits_to_bytes = rmisec_bits_to_bytes;
+    p_RMISEC_open = rmisec_lib_init;
+    p_RMISEC_close = rmisec_lib_cleanup;
+#if !(defined(OPENSSL_NO_RSA) && defined(OPENSSL_NO_DH))
+    p_RMISEC_mod_exp = rmisec_mod_exp;
+#endif
+#ifndef OPENSSL_NO_ECC
+    p_RMISEC_ecc_gfp_mul = rmisec_ecc_gfp_mul;
+    p_RMISEC_ecc_gfp_add = rmisec_ecc_gfp_add;
+    p_RMISEC_ecc_gfp_dbl = rmisec_ecc_gfp_dbl;
+    p_RMISEC_ecc_gfp_vfy = rmisec_ecc_gfp_vfy;
+    p_RMISEC_ecc_gf2m_mul = rmisec_ecc_gf2m_mul;
+    p_RMISEC_ecc_gfp_field_mul = rmisec_ecc_gfp_field_mul;
+    p_RMISEC_ecc_gfp_field_div = rmisec_ecc_gfp_field_div;
+    p_RMISEC_ecc_gfp_field_inv = rmisec_ecc_gfp_field_inv;
+    p_RMISEC_ecc_gfp_field_red = rmisec_ecc_gfp_field_red;
+    p_RMISEC_ecc_gfp_field_add = rmisec_ecc_gfp_field_add;
+    p_RMISEC_ecc_gfp_field_sub = rmisec_ecc_gfp_field_sub;
+    p_RMISEC_ecc_gf2m_field_mul = rmisec_ecc_gf2m_field_mul;
+    p_RMISEC_ecc_gf2m_field_inv = rmisec_ecc_gf2m_field_inv;
+#endif
+#ifndef OPENSSL_NO_MD5
+    p_RMISEC_md5 = rmisec_md5 ;
+#endif /* OPENSSL_NO_MD5 */
+#ifndef OPENSSL_NO_SHA
+#ifndef OPENSSL_NO_SHA1
+    p_RMISEC_sha1 = rmisec_sha1 ;
+#endif /* OPENSSL_NO_SHA1 */
+#ifndef OPENSSL_NO_SHA256
+    p_RMISEC_sha256 = rmisec_sha256 ;
+#endif /* OPENSSL_NO_SHA256 */
+#ifndef OPENSSL_NO_SHA384
+    p_RMISEC_sha384 = rmisec_sha384 ;
+#endif /* OPENSSL_NO_SHA384 */
+#ifndef OPENSSL_NO_SHA512
+    p_RMISEC_sha512 = rmisec_sha512 ;
+#endif /* OPENSSL_NO_SHA512 */
+#endif /* OPENSSL_NO_SHA */
+#ifndef OPENSSL_NO_DES
+    p_RMISEC_des_cipher = rmisec_des_cipher ;
+    p_RMISEC_3des_cipher = rmisec_3des_cipher ;
+#endif /* OPENSSL_NO_DES */
+#ifndef OPENSSL_NO_AES
+    p_RMISEC_aes128_cipher = rmisec_aes128_cipher ;
+    p_RMISEC_aes192_cipher = rmisec_aes192_cipher ;
+    p_RMISEC_aes256_cipher = rmisec_aes256_cipher ;
+#endif /* OPENSSL_NO_AES */
+#if 0
+#ifndef OPENSSL_NO_RC4
+    p_RMISEC_arc4_cipher = rmisec_arc4_cipher ;
+#endif /* OPENSSL_NO_RC4 */
+#endif /* 0 */
+#endif /* ENGINE_DYNAMIC_SUPPORT */
+
+    /* Perform an open to see if there's actually any unit running. */
+    if (p_RMISEC_open() < 0) {
+	    RMISECerr(RMISEC_F_RMISEC_INIT, RMISEC_R_UNIT_FAILURE);
+	    RMISEC_GLOBAL_FD = -1;
+	    goto err;
+    }
+
+    fd = open("/dev/rmisae", O_RDWR);
+    if(fd < 0) {
+	    RMISECerr(RMISEC_F_RMISEC_INIT, RMISEC_R_UNIT_FAILURE);
+	    RMISEC_GLOBAL_FD = -1;
+	    goto err;
+    } else {
+	    RMISEC_GLOBAL_FD = fd;
+    }
+    DBG_PRINT("\t**ENGINE:rmisec_init(): fd=%d **\n", RMISEC_GLOBAL_FD);
+
+    return 1;
+
+err:
+#ifndef ENGINE_DYNAMIC_SUPPORT
+    if(rmisec_dso)
+        DSO_free(rmisec_dso);
+    p_RMISEC_bytes_to_bits = NULL;
+    p_RMISEC_bits_to_bytes = NULL;
+    p_RMISEC_open = NULL;
+    p_RMISEC_close = NULL;
+    p_RMISEC_op_init = NULL;
+    p_RMISEC_op_cleanup = NULL;
+#if !(defined(OPENSSL_NO_RSA) && defined(OPENSSL_NO_DH))
+    p_RMISEC_mod_exp = NULL;
+#endif
+#ifndef OPENSSL_NO_MD5
+    p_RMISEC_md5 = NULL;
+#endif /* OPENSSL_NO_MD5 */
+#ifndef OPENSSL_NO_SHA
+#ifndef OPENSSL_NO_SHA1
+    p_RMISEC_sha1 = NULL;
+#endif /* OPENSSL_NO_SHA1 */
+#ifndef OPENSSL_NO_SHA256
+    p_RMISEC_sha256 = NULL;
+#endif /* OPENSSL_NO_SHA256 */
+#endif /* OPENSSL_NO_SHA */
+#ifndef OPENSSL_NO_DES
+    p_RMISEC_des_cipher = NULL;
+    p_RMISEC_3des_cipher = NULL;
+#endif /* OPENSSL_NO_DES */
+#ifndef OPENSSL_NO_AES
+    p_RMISEC_aes128_cipher = NULL;
+    p_RMISEC_aes192_cipher = NULL;
+    p_RMISEC_aes256_cipher = NULL;
+#endif /* OPENSSL_NO_AES */
+#if 0
+#ifndef OPENSSL_NO_RC4
+    p_RMISEC_arc4_cipher = NULL;
+#endif /* OPENSSL_NO_RC4 */
+#endif /* 0 */
+#endif /* ENGINE_DYNAMIC_SUPPORT */
+    return 0;
+}
+
+static int rmisec_finish(ENGINE *e)
+{
+    DBG_PRINT("\t**ENGINE: rmisec_finish(): DSO=%p **\n",
+                     rmisec_dso);
+
+#ifndef ENGINE_DYNAMIC_SUPPORT
+    free_RMISEC_LIBNAME();
+    if(rmisec_dso == NULL)
+    {
+        RMISECerr(RMISEC_F_RMISEC_FINISH, RMISEC_R_NOT_LOADED);
+        return 0;
+    }
+
+    p_RMISEC_close();
+    close(RMISEC_GLOBAL_FD);
+    RMISEC_GLOBAL_FD = -1;
+//    fprintf(stderr, "%s:%d crt_count=%d\n", __FUNCTION__, __LINE__, crt_count);
+
+    DBG_PRINT("\t**ENGINE: rmisec_finish(): pre DSO_free() **\n");
+
+    if(!DSO_free(rmisec_dso))
+    {
+        RMISECerr(RMISEC_F_RMISEC_FINISH, RMISEC_R_DSO_FAILURE);
+        return 0;
+    }
+
+    DBG_PRINT("\t**ENGINE: rmisec_finish(): post DSO_free() **\n");
+
+    rmisec_dso = NULL;
+    p_RMISEC_bytes_to_bits = NULL;
+    p_RMISEC_bits_to_bytes = NULL;
+    p_RMISEC_open = NULL;
+    p_RMISEC_close = NULL;
+    p_RMISEC_op_init = NULL;
+    p_RMISEC_op_cleanup = NULL;
+#if !(defined(OPENSSL_NO_RSA) && defined(OPENSSL_NO_DH))
+    p_RMISEC_mod_exp = NULL;
+#endif
+#ifndef OPENSSL_NO_MD5
+    p_RMISEC_md5 = NULL;
+#endif /* OPENSSL_NO_MD5 */
+#ifndef OPENSSL_NO_SHA
+#ifndef OPENSSL_NO_SHA1
+    p_RMISEC_sha1 = NULL;
+#endif /* OPENSSL_NO_SHA1 */
+#ifndef OPENSSL_NO_SHA256
+    p_RMISEC_sha256 = NULL;
+#endif /* OPENSSL_NO_SHA256 */
+#endif /* OPENSSL_NO_SHA */
+#ifndef OPENSSL_NO_DES
+    p_RMISEC_des_cipher = NULL;
+    p_RMISEC_3des_cipher = NULL;
+#endif /* OPENSSL_NO_DES */
+#ifndef OPENSSL_NO_AES
+    p_RMISEC_aes128_cipher = NULL;
+    p_RMISEC_aes192_cipher = NULL;
+    p_RMISEC_aes256_cipher = NULL;
+#endif /* OPENSSL_NO_AES */
+#if 0
+#ifndef OPENSSL_NO_RC4
+    p_RMISEC_arc4_cipher = NULL;
+#endif /* OPENSSL_NO_RC4 */
+#endif /* 0 */
+#endif /* ENGINE_DYNAMIC_SUPPORT */
+    return 1;
+}
+
+static int rmisec_ctrl(ENGINE *e, int cmd, long i, void *p, void (*f)())
+{
+    int initialised = ((rmisec_dso == NULL) ? 0 : 1);
+    DBG_PRINT("%s:%d cmd=%d i=%ld p=%p f=%p \n", __FUNCTION__,
+		  __LINE__, cmd, i, p, f);
+
+    switch(cmd) {
+    case RMISEC_CMD_SO_PATH:
+        if (p == NULL)
+        {
+            RMISECerr(RMISEC_F_RMISEC_CTRL,ERR_R_PASSED_NULL_PARAMETER);
+            return 0;
+        }
+        if (initialised)
+        {
+            RMISECerr(RMISEC_F_RMISEC_CTRL,RMISEC_R_ALREADY_LOADED);
+            return 0;
+        }
+#ifndef ENGINE_DYNAMIC_SUPPORT
+        return set_RMISEC_LIBNAME((const char *)p);
+#endif /* ENGINE_DYNAMIC_SUPPORT */
+    case RMISEC_CMD_RSA_TOGGLE_CRT:
+	rsa_crt_enabled = !rsa_crt_enabled;
+	return 1;
+    default:
+        break;
+    }
+    RMISECerr(RMISEC_F_RMISEC_CTRL,RMISEC_R_CTRL_COMMAND_NOT_IMPLEMENTED);
+    return 0;
+}
+
+/*
+ * Calculate constant for our Modulo Exponentiation Method.
+ *   k = number of bits for n
+ *   constant = 2^(2*(k + 2)) mod n
+ */
+extern BIO *bio_err;
+static
+int rmisec_calc_modexp_constant (const BIGNUM *n,
+                                 BIGNUM *constant, BN_CTX *ctx)
+{
+    BIGNUM two, exp;
+    int    retval = 0;
+
+    BN_init(&two);
+    BN_init(&exp);
+
+    BN_init(constant);
+
+    do {
+
+        /* exp=(k + 2) */
+        if (BN_set_word(&two,2) == 0)  break;
+        if (BN_set_word(&exp,BN_num_bits(n)) == 0)  break;
+        if (BN_add(&exp, &exp, &two) == 0)  break;
+
+        /* exp=2*(k + 2) */
+        if (BN_mul(&exp, &two, &exp, ctx) == 0)  break;
+
+        /* constant = 2^exp mod n */
+        if (BN_mod_exp(constant, &two, &exp, n, ctx) == 0)  break;
+
+        retval = 1;
+    } while (0);
+    return (retval);
+}
+
+/*
+ * compute r = a ^ p mod m
+ */
+static int openssl_rmisec_mod_exp(BIGNUM *r, const BIGNUM *a,
+				  const BIGNUM *p, const BIGNUM *m,
+				  BN_CTX *ctx, BN_MONT_CTX *m_ctx)
+{
+    unsigned char  result[(max_key_len >> 3)];  /* max_key_len */
+    int     max_bytes;
+    int     y_len = 0;
+    int     a_len = 0;
+    int     retval = 0;
+    BIGNUM  *con2k = NULL;
+
+    op_handle_t handle = RMISAE_HANDLE_INITIALIZER;
+
+    y_len = BN_num_bits(m);
+
+    unsigned char  constant[256];
+    unsigned char  exponent[256];
+    unsigned char  modulus[256];
+    unsigned char  message[256];
+    int err = 1;
+
+#ifdef SAE_BYPASS
+    if(err) {
+	    return BN_mod_exp(r, a, p, m, ctx);
+    }
+#endif /* SAE_BYPASS */
+
+    if (RMISEC_GLOBAL_FD < 0 || p_RMISEC_mod_exp == NULL  ||
+	!(y_len == 512 || y_len == 1024))
+	    return BN_mod_exp(r, a, p, m, ctx);
+
+    do {
+#ifndef ENGINE_DYNAMIC_SUPPORT
+      if (rmisec_dso == NULL) {
+            RMISECerr(RMISEC_F_RMISEC_MOD_EXP, RMISEC_R_NOT_LOADED);
+	    err = 0;
+            break;
+        }
+#endif /* ENGINE_DYNAMIC_SUPPORT */
+
+        max_bytes = (max_key_len >> 3);
+
+        /* Check if hardware can handle the key size */
+        y_len = BN_num_bits(m);
+	/*        if(y_len != 512 && y_len != 1024 && y_len != 2048) */
+        if (y_len > max_key_len) {
+            RMISECerr(RMISEC_F_RMISEC_MOD_EXP,
+                      RMISEC_R_SIZE_TOO_LARGE_OR_TOO_SMALL);
+	    err = 0;
+            break;
+        }
+
+
+        /* Check if hardware can handle the message size */
+	a_len = BN_num_bits(a);
+        if (y_len < a_len) {
+            RMISECerr(RMISEC_F_RMISEC_MOD_EXP,
+                      RMISEC_R_SIZE_TOO_LARGE_OR_TOO_SMALL);
+	    err = 0;
+            break;
+        }
+
+        /*
+         *  Calculate the Constant
+         */
+        if ((m_ctx != NULL) &&
+            ((m_ctx->flags & RMIHACK_BN_RMI_CONSTANT) != 0)) {
+            con2k = &m_ctx->N;
+        }
+        else {
+            /*
+             * We need to calculate the constant temporarily or
+             * hijack the Montgomery Product context.
+             */
+            if (m_ctx == NULL) {
+                if ((con2k = BN_new()) == NULL) {
+                    RMISECerr(RMISEC_F_RMISEC_RSA_MOD_EXP,
+                              RMISEC_R_MEM_ALLOC_FAILURE);
+		    err = 0;
+                    break;
+                }
+            }
+            else {
+                /* hijack the Mont Prod context for our constant */
+                int  save_flags;
+
+                save_flags = m_ctx->flags;
+                BN_MONT_CTX_init (m_ctx);
+                m_ctx->flags = save_flags | RMIHACK_BN_RMI_CONSTANT;
+                con2k = &m_ctx->N;
+            }
+	    if (rmisec_calc_modexp_constant (m, con2k, ctx) == 0) {
+    	        /* !FIX! */
+                RMISECerr(RMISEC_F_RMISEC_MOD_EXP,
+                          RMISEC_R_CONST_CALC_FAILURE);
+		err = 0;
+                break;
+            }
+        }
+
+        memset (&message[0], 0, sizeof(message));
+        BN_bn2bin(a, &message[0]);
+
+        memset (&constant[0], 0, sizeof(constant));
+        BN_bn2bin(con2k, &constant[0]);
+
+        memset (&exponent[0], 0, sizeof(exponent));
+        BN_bn2bin(p, &exponent[0]);
+
+        memset (&modulus[0], 0, sizeof(modulus));
+        BN_bn2bin(m, &modulus[0]);
+
+	err = p_RMISEC_op_init(RMISEC_GLOBAL_FD, &handle);
+	if(err) {
+		fprintf(stderr, "%s:%d err %d\n", __FUNCTION__, __LINE__, err);
+		RMISECerr(RMISEC_F_RMISEC_MOD_EXP,
+			  RMISEC_R_REQUEST_FAILED);
+		err = 0;
+		break;
+	}
+	err = p_RMISEC_mod_exp (handle, &message[0], BN_num_bits(a),
+				&modulus[0], BN_num_bits(m),
+				&exponent[0], BN_num_bits(p),
+				&constant[0], BN_num_bits(con2k),
+				&result[0], &y_len);
+
+	p_RMISEC_op_cleanup(&handle);
+	if(!IS_SUCCESS_SAEOP(err)) {
+		fprintf(stderr, "%s:%d err %d\n", __FUNCTION__, __LINE__, err);
+		RMISECerr(RMISEC_F_RMISEC_MOD_EXP,
+			  RMISEC_R_REQUEST_FAILED);
+		err = 0;
+		break;
+	}
+
+//        DBG_PRINT("%s:%d AFTER IOCTL \n", __FUNCTION__, __LINE__);
+
+#if 0
+        {
+           unsigned char *bnb;
+
+        bnb = &result[0];
+        DBG_PRINT("Result  Len=%d  %02x %02x %02x %02x %02x %02x %02x %02x \n",
+                  y_len,
+                  bnb[0],bnb[1],bnb[2],bnb[3], bnb[4],bnb[5],bnb[6],bnb[7]);
+        }
+#endif
+        if (BN_bin2bn(result, CEIL(y_len, 3), r) == NULL) {
+            //RMISECerr(RMISEC_F_RMISEC_MOD_EXP,
+            //          RMISEC_R_REQUEST_FAILED);
+            DBG_PRINT("Result BN_bin2bn !FAILED! \n");
+            break;
+        }
+
+#ifdef RMISEC_DEBUG
+        {
+             BIGNUM  sw_result;
+             unsigned char  sw_rb[256];
+
+             BN_init(&sw_result);
+             BN_mod_exp(&sw_result, a, p, m, ctx);
+
+             memset (&sw_rb[0], 0, sizeof(sw_rb));
+             BN_bn2bin(&sw_result, &sw_rb[0]);
+
+	     if(BN_ucmp(&sw_result, r) != 0) {
+		     print_buf ("Message", message, BN_num_bytes(a));
+
+		     print_buf ("Exponent", exponent, BN_num_bytes(p));
+
+		     print_buf ("Modulus", modulus, BN_num_bytes(m));
+
+		     print_buf ("Constant", constant, BN_num_bytes(m));
+		     DBG_PRINT("SW Result   Len=%d:%d (bits:bytes)  \n",
+			       BN_num_bits(&sw_result), BN_num_bytes(&sw_result));
+		     DBG_PRINT_BUF("SW RESULT: ", &sw_rb[0], BN_num_bytes(&sw_result));
+		     DBG_PRINT("HW Result   Len=%d:%d (bits:bytes)  \n",
+			       BN_num_bits(r), BN_num_bytes(r));
+		     DBG_PRINT_BUF("HW RESULT: ", &result[0], BN_num_bytes(r));
+
+		     fflush(stderr);
+	     }
+        }
+#endif
+
+        retval = 1;
+    } while (0);
+
+    if ((m_ctx == NULL) && (con2k != NULL))
+	    BN_free(con2k);   /* temp Constant */
+
+    /* revert to software */
+    if (retval == 0) {
+        return BN_mod_exp(r, a, p, m, ctx);
+    }
+
+    /*  ????  */
+    if (r != NULL)
+        r->top = (BN_num_bits(m) + BN_BITS2 - 1) / BN_BITS2;
+
+    return err;
+}
+
+/*
+ * rmisec_mod_exp_crt:  compute modular exponential using CRT
+ *			 y1 = (x|p)**edp | p
+ *			 y2 = (x|q)**edq | q
+ *			 r = y2 + (qinv * (y1 - y2) | p) * q
+ */
+static int rmisec_mod_exp_crt(BIGNUM *r, const BIGNUM *a, RSA *rsa,
+			      BN_CTX *ctx) {
+    BIGNUM ap;
+    BIGNUM aq;
+    BIGNUM y1;
+    BIGNUM y2;
+    BIGNUM tmp;
+    BIGNUM *p, *q, *dmp1, *dmq1, *iqmp;
+    BN_MONT_CTX *m_ctx;
+
+    if(!(r && a && rsa && ctx)) {
+	return 0;
+    }
+
+    p = rsa->p;
+    q = rsa->q;
+    dmp1 = rsa->dmp1;
+    dmq1 = rsa->dmq1;
+    iqmp = rsa->iqmp;
+    m_ctx = rsa->_method_mod_n;
+
+    BN_init(&ap);
+    BN_init(&aq);
+    BN_init(&y1);
+    BN_init(&y2);
+
+    BN_mod(&ap, a, p, ctx);
+    BN_mod(&aq, a, q, ctx);
+
+   // MONT_CONST calc for p
+   if(rsa->_method_mod_p == NULL) {
+	BN_MONT_CTX *p_const = BN_MONT_CTX_new();
+	if(p_const == NULL) {
+	    RMISECerr(RMISEC_F_RMISEC_RSA_MOD_EXP,
+		      RMISEC_R_MEM_ALLOC_FAILURE);
+	    return 0;
+	}
+
+	if(BN_MONT_CTX_set(p_const, p, ctx) == 0) {
+	    RMISECerr(RMISEC_F_RMISEC_MOD_EXP,
+		      RMISEC_R_CONST_CALC_FAILURE);
+	    return 0;
+	}
+
+	CRYPTO_w_lock(CRYPTO_LOCK_RSA);
+	if(rsa->_method_mod_p == NULL) {
+	    rsa->_method_mod_p = p_const;
+	    p_const = NULL;
+	}
+	CRYPTO_w_unlock(CRYPTO_LOCK_RSA);
+	if(p_const) {
+	    BN_MONT_CTX_free(p_const);
+	    p_const = NULL;
+	}
+   }
+
+   // MONT_CONST calc for q
+   if(rsa->_method_mod_q == NULL) {
+	BN_MONT_CTX *q_const = BN_MONT_CTX_new();
+	if(q_const == NULL) {
+	    RMISECerr(RMISEC_F_RMISEC_RSA_MOD_EXP,
+		      RMISEC_R_MEM_ALLOC_FAILURE);
+	    return 0;
+	}
+
+	if(BN_MONT_CTX_set(q_const, q, ctx) == 0) {
+	    RMISECerr(RMISEC_F_RMISEC_MOD_EXP,
+		      RMISEC_R_CONST_CALC_FAILURE);
+	    return 0;
+	}
+
+	CRYPTO_w_lock(CRYPTO_LOCK_RSA);
+	if(rsa->_method_mod_q == NULL) {
+	    rsa->_method_mod_q = q_const;
+	    q_const = NULL;
+	}
+	CRYPTO_w_unlock(CRYPTO_LOCK_RSA);
+	if(q_const) {
+	    BN_MONT_CTX_free(q_const);
+	    q_const = NULL;
+	}
+   }
+
+   // y1
+    if(openssl_rmisec_mod_exp(&y1, &ap, dmp1, p, ctx, rsa->_method_mod_p) == 0) {
+	return 0;
+    }
+
+  // y2
+    if(openssl_rmisec_mod_exp(&y2, &aq, dmq1, q, ctx, rsa->_method_mod_q) == 0) {
+	return 0;
+    }
+
+   // rest of calcs
+    BN_init(&tmp);
+
+    BN_sub(&tmp, &y1, &y2);
+    BN_mod_mul(&tmp, iqmp, &tmp, p, ctx);
+
+    BN_mul(&tmp, &tmp, q, ctx);
+    BN_add(r, &y2, &tmp);
+
+    BN_free(&tmp);
+    BN_free(&y1);
+    BN_free(&y2);
+    BN_free(&ap);
+    BN_free(&aq);
+
+    return 1;
+}
+
+
+#ifndef OPENSSL_NO_RSA
+/*
+ *  compute r0 = r0 ^ I mod rsa->n
+ */
+static int rmisec_rsa_mod_exp(BIGNUM *r0, const BIGNUM *I, RSA *rsa, BN_CTX *ctx)
+{
+    int to_return = 0;
+    int n_len = 0;
+
+    do {
+
+        if ((rsa->d == NULL) || (rsa->n == NULL)) {
+            RMISECerr(RMISEC_F_RMISEC_RSA_MOD_EXP,
+                      RMISEC_R_MISSING_KEY_COMPONENTS);
+            break;
+        }
+
+        if (rsa->_method_mod_n == NULL) {
+            BN_MONT_CTX* bn_mont_ctx;
+
+            if ((bn_mont_ctx = BN_MONT_CTX_new()) == NULL)
+                break;
+
+            if (BN_MONT_CTX_set(bn_mont_ctx,rsa->n,ctx) == 0) {
+                BN_MONT_CTX_free(bn_mont_ctx);
+                break;
+            }
+
+            /* other thread may have finished first */
+            if (rsa->_method_mod_n == NULL) {
+                CRYPTO_w_lock(CRYPTO_LOCK_RSA);
+                if (rsa->_method_mod_n == NULL) {
+                    rsa->_method_mod_n = bn_mont_ctx;
+                    bn_mont_ctx = NULL;
+                }
+                CRYPTO_w_unlock(CRYPTO_LOCK_RSA);
+            }
+            if (bn_mont_ctx)
+                BN_MONT_CTX_free(bn_mont_ctx);
+        }
+
+        /* crt is good for 1024 bit keys and greater since
+	 * hw supports 512 and 1024 bits */
+	n_len = BN_num_bits(rsa->n);
+	if(rsa_crt_enabled && n_len >= 1024) {
+		crt_count++;
+	    if (rmisec_mod_exp_crt(r0, I, rsa, ctx) == 0) {
+		RMISECerr( RMISEC_F_RMISEC_RSA_MOD_EXP,
+		           RMISEC_R_REQUEST_FAILED);
+		break;
+	    }
+        } else {
+            if (openssl_rmisec_mod_exp(r0,I,rsa->d,rsa->n,
+                               ctx,rsa->_method_mod_n) == 0) {
+                RMISECerr( RMISEC_F_RMISEC_RSA_MOD_EXP,
+                           RMISEC_R_REQUEST_FAILED);
+                break;
+            }
+        }
+
+        to_return = 1;
+
+    } while (0);
+
+    return to_return;
+}
+#endif /* OPENSSL_NO_RSA */
+
+#ifndef OPENSSL_NO_DSA
+static int rmisec_dsa_mod_exp(DSA *dsa, BIGNUM *rr, BIGNUM *a1,
+        BIGNUM *p1, BIGNUM *a2, BIGNUM *p2, BIGNUM *m,
+        BN_CTX *ctx, BN_MONT_CTX *in_mont)
+{
+        BIGNUM t;
+        int to_return = 0;
+
+        /* Check if hardware can handle the key size */
+        if (BN_num_bits(m) > max_key_len)
+		return BN_mod_exp2_mont(rr, a1, p1, a2, p2, m, ctx, in_mont);
+
+	BN_init(&t);
+        /* let rr = a1 ^ p1 mod m */
+        if (!openssl_rmisec_mod_exp(rr,a1,p1,m,ctx,in_mont)) goto end;
+        /* let t = a2 ^ p2 mod m */
+        if (!openssl_rmisec_mod_exp(&t,a2,p2,m,ctx,in_mont)) goto end;
+        /* let rr = rr * t mod m */
+        if (!BN_mod_mul(rr,rr,&t,m,ctx)) goto end;
+        to_return = 1;
+ end:
+        BN_free(&t);
+        return to_return;
+}
+
+static int rmisec_mod_exp_dsa(DSA *dsa, BIGNUM *r, BIGNUM *a,
+        const BIGNUM *p, const BIGNUM *m, BN_CTX *ctx,
+        BN_MONT_CTX *m_ctx)
+{
+        /* Check if hardware can handle the key size */
+        if (BN_num_bits(m) > max_key_len)
+                return BN_mod_exp_mont(r, a, p, m, ctx, m_ctx);
+        return openssl_rmisec_mod_exp(r, a, p, m, ctx, m_ctx);
+}
+#endif
+
+
+#if 0
+/* This function is aliased to mod_exp  */
+static int rmisec_mod_exp_mont(BIGNUM *r, const BIGNUM *a, const BIGNUM *p,
+		const BIGNUM *m, BN_CTX *ctx, BN_MONT_CTX *m_ctx)
+{
+    return openssl_rmisec_mod_exp(r, a, p, m, ctx, m_ctx);
+}
+#endif
+
+#ifndef OPENSSL_NO_DH
+/* This function is aliased to mod_exp */
+static int rmisec_dh_mod_exp(const DH *dh, BIGNUM *r,
+               const BIGNUM *a, const BIGNUM *p,
+               const BIGNUM *m, BN_CTX *ctx, BN_MONT_CTX *m_ctx)
+{
+    return openssl_rmisec_mod_exp(r, a, p, m, ctx, m_ctx);
+}
+#endif
+
+
+/* This stuff is needed if this ENGINE is being compiled into a self-contained
+ * shared-library. */
+#ifndef OPENSSL_NO_DYNAMIC_ENGINE
+static int bind_fn(ENGINE *e, const char *id)
+{
+    if (id && (strcmp(id, engine_rmisec_id) != 0))
+        return 0;
+    if (!bind_helper(e))
+        return 0;
+    return 1;
+}
+IMPLEMENT_DYNAMIC_CHECK_FN()
+IMPLEMENT_DYNAMIC_BIND_FN(bind_fn)
+#endif /* OPENSSL_NO_DYNAMIC_ENGINE */
+
+/*
+ *  Cipher and Digest Includes
+ */
+#include <openssl/evp.h>
+#include <openssl/sha.h>
+#include <openssl/md5.h>
+#include <openssl/des.h>
+#include <openssl/aes.h>
+#include <openssl/rc4.h>
+
+/*
+ * symetric computation
+ */
+static int engine_digest_nids [ ] = { NID_sha1, NID_sha256, NID_sha384, NID_sha512, NID_md5 } ;
+static int engine_digest_nids_num = 5 ;
+static int engine_cipher_nids [ ] = { NID_des_cbc,
+                                      NID_des_ede3_cbc,
+                                      NID_aes_128_cbc,
+                                      NID_aes_192_cbc,
+                                      NID_aes_256_cbc,
+                                      NID_rc4,
+                                     } ;
+static int engine_cipher_nids_num = 6;
+
+
+/* Function prototype ... */
+static int engine_digest_init (EVP_MD_CTX *ctx);
+
+static int engine_digest_update (EVP_MD_CTX *ctx,
+				 const void *data, size_t count);
+
+/*  SHA1 stuff */
+#if 0
+static int engine_sha1_init ( EVP_MD_CTX *ctx ) ;
+static int engine_sha1_update ( EVP_MD_CTX *ctx,
+                                const void *data, size_t count ) ;
+#endif
+static int engine_sha1_final ( EVP_MD_CTX *ctx, unsigned char *md ) ;
+
+/*  SHA256 stuff */
+static int engine_sha256_init ( EVP_MD_CTX *ctx ) ;
+static int engine_sha256_update ( EVP_MD_CTX *ctx,
+                                const void *data, size_t count ) ;
+static int engine_sha256_final ( EVP_MD_CTX *ctx, unsigned char *md ) ;
+
+static int engine_sha384_init ( EVP_MD_CTX *ctx ) ;
+static int engine_sha384_update ( EVP_MD_CTX *ctx,
+                                const void *data, size_t count ) ;
+static int engine_sha384_final ( EVP_MD_CTX *ctx, unsigned char *md ) ;
+
+static int engine_sha512_init ( EVP_MD_CTX *ctx ) ;
+static int engine_sha512_update ( EVP_MD_CTX *ctx,
+                                const void *data, size_t count ) ;
+static int engine_sha512_final ( EVP_MD_CTX *ctx, unsigned char *md ) ;
+
+/*  MD5 stuff */
+#if 0
+static int engine_md5_init ( EVP_MD_CTX *ctx ) ;
+static int engine_md5_update ( EVP_MD_CTX *ctx,
+                               const void *data, size_t count ) ;
+#endif
+static int engine_md5_final ( EVP_MD_CTX *ctx, unsigned char *md ) ;
+
+static int engine_md_cleanup ( EVP_MD_CTX *ctx ) ;
+static int engine_md_copy ( EVP_MD_CTX *to, const EVP_MD_CTX *from ) ;
+
+static int engine_md_cleanup2 ( EVP_MD_CTX *ctx ) ;
+static int engine_md_copy2 ( EVP_MD_CTX *to, const EVP_MD_CTX *from ) ;
+
+
+/* AES-128 Stuff */
+static int engine_aes_128_init_key ( EVP_CIPHER_CTX *ctx, const unsigned char *key, const unsigned char *iv, int enc ) ;
+static int engine_aes_128_cbc_cipher ( EVP_CIPHER_CTX *ctx, unsigned char *out, const unsigned char *in, unsigned int inl ) ;
+
+/* AES-192 Stuff */
+static int engine_aes_192_init_key ( EVP_CIPHER_CTX *ctx, const unsigned char *key, const unsigned char *iv, int enc ) ;
+static int engine_aes_192_cbc_cipher ( EVP_CIPHER_CTX *ctx, unsigned char *out, const unsigned char *in, unsigned int inl ) ;
+
+/* AES-256 Stuff */
+static int engine_aes_256_init_key ( EVP_CIPHER_CTX *ctx, const unsigned char *key, const unsigned char *iv, int enc ) ;
+static int engine_aes_256_cbc_cipher ( EVP_CIPHER_CTX *ctx, unsigned char *out, const unsigned char *in, unsigned int inl ) ;
+
+/* DES Stuff */
+static int engine_des_init_key ( EVP_CIPHER_CTX *ctx, const unsigned char *key, const unsigned char *iv, int enc ) ;
+static int engine_des_cbc_cipher ( EVP_CIPHER_CTX *ctx, unsigned char *out, const unsigned char *in, unsigned int inl ) ;
+
+/*  3DES Stuff */
+static int engine_des_ede3_init_key ( EVP_CIPHER_CTX *ctx, const unsigned char *key, const unsigned char *iv, int enc ) ;
+static int engine_des_ede3_cbc_cipher ( EVP_CIPHER_CTX *ctx, unsigned char *out,const unsigned char *in, unsigned int inl ) ;
+
+#if 0
+/* RC4 Stuff */
+static int engine_arc4_init_key ( EVP_CIPHER_CTX *ctx, const unsigned char *key, const unsigned char *iv, int enc ) ;
+static int engine_arc4_cipher ( EVP_CIPHER_CTX *ctx, unsigned char *out, const unsigned char *in, unsigned int inl ) ;
+#endif /* 0 */
+
+static int engine_cipher_cleanup ( EVP_CIPHER_CTX *ctx ) ;  /* cleanup ctx */
+
+/* The one for SHA1 ... */
+static const EVP_MD engine_sha1_md =
+{
+    NID_sha1,
+    NID_sha1WithRSAEncryption,
+    SHA_DIGEST_LENGTH,
+    0, //EVP_MD_FLAG_ONESHOT,
+    engine_digest_init,
+    engine_digest_update,
+    engine_sha1_final,
+    engine_md_copy2,
+    engine_md_cleanup2,
+    EVP_PKEY_RSA_method,
+    SHA_CBLOCK,
+    sizeof(RMI_MD_DATA)
+} ;
+
+/* The one for SHA256 ... */
+static const EVP_MD engine_sha256_md =
+{
+    NID_sha256,
+    NID_sha256WithRSAEncryption,
+    SHA256_DIGEST_LENGTH,
+    EVP_MD_FLAG_ONESHOT,
+    engine_sha256_init,
+    engine_sha256_update,
+    engine_sha256_final,
+    engine_md_copy,
+    engine_md_cleanup,
+    EVP_PKEY_RSA_method,
+    SHA256_CBLOCK,
+    SHA256_DIGEST_LENGTH
+} ;
+
+/* The one for SHA384 ... */
+static const EVP_MD engine_sha384_md =
+{
+    NID_sha384,
+    NID_sha384WithRSAEncryption,
+    SHA384_DIGEST_LENGTH,
+    EVP_MD_FLAG_ONESHOT,
+    engine_sha384_init,
+    engine_sha384_update,
+    engine_sha384_final,
+    engine_md_copy,
+    engine_md_cleanup,
+    EVP_PKEY_RSA_method,
+    SHA512_CBLOCK,
+    SHA384_DIGEST_LENGTH
+} ;
+
+/* The one for SHA512 ... */
+static const EVP_MD engine_sha512_md =
+{
+    NID_sha512,
+    NID_sha512WithRSAEncryption,
+    SHA512_DIGEST_LENGTH,
+    EVP_MD_FLAG_ONESHOT,
+    engine_sha512_init,
+    engine_sha512_update,
+    engine_sha512_final,
+    engine_md_copy,
+    engine_md_cleanup,
+    EVP_PKEY_RSA_method,
+    SHA512_CBLOCK,
+    SHA512_DIGEST_LENGTH
+} ;
+
+static const EVP_MD engine_md5_md =
+{
+    NID_md5,                     /* int type;                   */
+    NID_md5WithRSAEncryption,    /* int pkey_type;              */
+    MD5_DIGEST_LENGTH,           /* int md_size;                */
+    0, // EVP_MD_FLAG_ONESHOT,
+    engine_digest_init,             /* int (*init)();              */
+    engine_digest_update,           /* int (*update)();            */
+    engine_md5_final,            /* int (*final)();             */
+    engine_md_copy2,              /* int (*copy)();              */
+    engine_md_cleanup2,           /* int (*cleanup)();           */
+    EVP_PKEY_RSA_method,         /* int (*sign)(), int (*verify)(),
+                                    int required_pkey_type[5];  */
+    MD5_CBLOCK,                  /* int block_size;             */
+    sizeof(RMI_MD_DATA)          /* int ctx_size;               */
+} ;
+
+
+/*
+ *   AES Cipher definition
+ *
+ */
+
+/*
+ * This should be a hidden type, but EVP requires that the size be known
+ *
+ * struct aes_key_st {
+ *   unsigned long rd_key[4 *(AES_MAXNR + 1)];
+ *   int rounds;
+ * };
+ * typedef struct aes_key_st AES_KEY;
+ */
+
+/*  AES_128_CBC */
+static const EVP_CIPHER engine_aes_128_cbc =
+{
+    NID_aes_128_cbc,             /* nid                    */
+    AES_BLOCK_SIZE,              /* block_size             */
+    16,     /* 128 bits */       /* key_len                */
+    AES_BLOCK_SIZE,              /* iv_len                 */
+    //EVP_CIPH_VARIABLE_LENGTH,    /* flags                  */
+    EVP_CIPH_CBC_MODE,           /* flags                  */
+    engine_aes_128_init_key,     /* (*init)                */
+    engine_aes_128_cbc_cipher,   /* (*do_cipher)           */
+    engine_cipher_cleanup,       /* (*cleanup)             */
+    sizeof ( RMI_AES_KEY ),      /* ctx_size               */
+    EVP_CIPHER_set_asn1_iv,      /* (*set_asn1_parameters) */
+    EVP_CIPHER_get_asn1_iv,      /* (*get_asn1_parameters) */
+    NULL,                        /* (*ctrl)                */
+    NULL                         /* *app_data              */
+};
+
+/*  AES_192_CBC */
+static const EVP_CIPHER engine_aes_192_cbc =
+{
+    NID_aes_192_cbc,             /* nid                    */
+    AES_BLOCK_SIZE,              /* block_size             */
+    24,     /* 192 bits */       /* key_len                */
+    AES_BLOCK_SIZE,              /* iv_len                 */
+    //EVP_CIPH_VARIABLE_LENGTH,    /* flags                  */
+    EVP_CIPH_CBC_MODE,           /* flags                  */
+    engine_aes_192_init_key,     /* (*init)                */
+    engine_aes_192_cbc_cipher,   /* (*do_cipher)           */
+    engine_cipher_cleanup,       /* (*cleanup)             */
+    sizeof ( RMI_AES_KEY ),      /* ctx_size               */
+    EVP_CIPHER_set_asn1_iv,      /* (*set_asn1_parameters) */
+    EVP_CIPHER_get_asn1_iv,      /* (*get_asn1_parameters) */
+    NULL,                        /* (*ctrl)                */
+    NULL                         /* *app_data              */
+};
+
+/*  AES_256_CBC */
+static const EVP_CIPHER engine_aes_256_cbc =
+{
+    NID_aes_256_cbc,             /* nid                    */
+    AES_BLOCK_SIZE,              /* block_size             */
+    32,      /* 256 bits */      /* key_len                */
+    AES_BLOCK_SIZE,              /* iv_len                 */
+    //EVP_CIPH_VARIABLE_LENGTH,    /* flags                  */
+    EVP_CIPH_CBC_MODE,           /* flags                  */
+    engine_aes_256_init_key,     /* (*init)                */
+    engine_aes_256_cbc_cipher,   /* (*do_cipher)           */
+    engine_cipher_cleanup,       /* (*cleanup)             */
+    sizeof ( RMI_AES_KEY ),      /* ctx_size               */
+    EVP_CIPHER_set_asn1_iv,      /* (*set_asn1_parameters) */
+    EVP_CIPHER_get_asn1_iv,      /* (*get_asn1_parameters) */
+    NULL,                        /* (*ctrl)                */
+    NULL                         /* *app_data              */
+};
+
+
+/*
+ *   DES Cipher definition
+ *
+ */
+static const EVP_CIPHER engine_des_cbc =
+{
+    NID_des_cbc,                 /* nid                    */
+    8,                           /* block_size             */
+    8,                           /* key_len                */
+    8,                           /* iv_len                 */
+    EVP_CIPH_CBC_MODE,           /* flags                  */
+    engine_des_init_key,         /* (*init)                */
+    engine_des_cbc_cipher,       /* (*do_cipher)           */
+    engine_cipher_cleanup,       /* (*cleanup)             */
+    sizeof(RMI_DES_KEY),         /* ctx_size               */
+    EVP_CIPHER_set_asn1_iv,      /* (*set_asn1_parameters) */
+    EVP_CIPHER_get_asn1_iv,      /* (*get_asn1_parameters) */
+    NULL,                        /* (*ctrl)                */
+    NULL                         /* *app_data              */
+};
+
+
+/*
+ *   DES Cipher definition
+ *
+ */
+
+#define des_data(ctx)                ( (DES_EDE_KEY *) ( ctx )->cipher_data )
+
+static const EVP_CIPHER engine_des_ede3_cbc =
+{
+    NID_des_ede3_cbc,            /* nid                    */
+    8,                           /* block_size             */
+    24,                          /* key_len                */
+    8,                           /* iv_len                 */
+    EVP_CIPH_CBC_MODE,           /* flags                  */
+    engine_des_ede3_init_key,    /* (*init)                */
+    engine_des_ede3_cbc_cipher,  /* (*do_cipher)           */
+    engine_cipher_cleanup,       /* (*cleanup)             */
+    sizeof(RMI_3DES_KEY),        /* ctx_size               */
+    EVP_CIPHER_set_asn1_iv,      /* (*set_asn1_parameters) */
+    EVP_CIPHER_get_asn1_iv,      /* (*get_asn1_parameters) */
+    NULL,                        /* (*ctrl)                */
+    NULL                         /* *app_data              */
+};
+
+#if 0
+/*  ARC4 */
+
+static const EVP_CIPHER engine_arc4 =
+{
+    NID_rc4,                     /* nid                    */
+    1,                           /* block_size             */
+    RMI_ARC4_KEY_LENGTH,         /* key_len                */
+    0,                           /* iv_len                 */
+    EVP_CIPH_STREAM_CIPHER |
+    EVP_CIPH_VARIABLE_LENGTH,    /* flags                  */
+    engine_arc4_init_key,        /* (*init)                */
+    engine_arc4_cipher,          /* (*do_cipher)           */
+    engine_cipher_cleanup,       /* (*cleanup)             */
+    sizeof ( RMI_ARC4_KEY ),     /* ctx_size               */
+    EVP_CIPHER_set_asn1_iv,      /* (*set_asn1_parameters) */
+    EVP_CIPHER_get_asn1_iv,      /* (*get_asn1_parameters) */
+    NULL,                        /* (*ctrl)                */
+    NULL                         /* *app_data              */
+};
+#endif /* 0 */
+
+/* General function cloned on hw_openbsd_dev_crypto one ... */
+static int engine_digests (ENGINE *e, const EVP_MD **digest,
+			   const int **nids, int nid)
+{
+    //DBG_PRINT( "\t**engine_digests():  ENTER **\n");
+
+    if ( digest == NULL ) {
+        /* We are returning a list of supported nids */
+        *nids = engine_digest_nids ;
+         DBG_PRINT("\t**engine_digests(): digest==NULL** !\n");
+        return engine_digest_nids_num ;
+    }
+    /* We are being asked for a specific digest */
+    if ( nid == NID_md5 ) {
+        *digest = &engine_md5_md ;
+         DBG_PRINT("\t**engine_digests(): nid == NID_md5** !\n");
+    }
+    else if ( nid == NID_sha1 ) {
+        *digest = &engine_sha1_md ;
+         DBG_PRINT( "\t**engine_digests(): nid == NID_sha1** !\n");
+    }
+    else if ( nid == NID_sha256 ) {
+        *digest = &engine_sha256_md ;
+         DBG_PRINT( "\t**engine_digests(): nid == NID_sha256** !\n");
+    }
+    else if ( nid == NID_sha384 ) {
+        *digest = &engine_sha384_md ;
+         DBG_PRINT( "\t**engine_digests(): nid == NID_sha384** !\n");
+    }
+    else if ( nid == NID_sha512 ) {
+        *digest = &engine_sha512_md ;
+         DBG_PRINT( "\t**engine_digests(): nid == NID_sha512** !\n");
+    }
+    else {
+        *digest = NULL ;
+         //DBG_PRINT( "\t**engine_digests(): nid == NULL** !\n");
+        return 0 ;
+    }
+    return 1 ;
+}
+
+
+static int engine_digest_init(EVP_MD_CTX *ctx)
+{
+    RMI_MD_DATA  *data;
+
+    data = (RMI_MD_DATA *) ctx->md_data;
+    if (data != NULL) {
+        data->len = 0;
+        data->max_len = RMI_DGST_BUF_BLKSIZE;
+        data->data = OPENSSL_malloc (RMI_DGST_BUF_BLKSIZE);
+        if (data->data == NULL) {
+            DBG_PRINT("%s:%d OPENSSL_malloc(%d)==NULL **\n",
+		      __FUNCTION__, __LINE__, RMI_DGST_BUF_BLKSIZE);
+            return 0;
+        }
+    }
+    return 1;
+}
+
+static int engine_digest_update(EVP_MD_CTX *ctx,
+				const void *msg,
+				size_t msg_size)
+{
+	int ret = 0;
+	RMI_MD_DATA *md_buf = NULL;
+
+	if(!msg_size) return 1;
+
+	if(ctx && ctx->md_data &&
+	   ((RMI_MD_DATA *)(ctx->md_data))->data) {
+		md_buf = (RMI_MD_DATA *)ctx->md_data;
+		if(msg_size > (md_buf->max_len - md_buf->len)) {
+			unsigned char *new = OPENSSL_malloc(md_buf->max_len +
+							    msg_size);
+			if(new == NULL) {
+				return 0;
+			}
+			memcpy(new, md_buf->data, md_buf->len);
+			OPENSSL_free(md_buf->data);
+			md_buf->data = new;
+			md_buf->max_len += msg_size;
+		}
+#if 0
+		fprintf(stderr, "%s:%d ctx=%p msg=%p msg_size=%zu buf=%p len=%u "
+			"max_len=%u\n", __FUNCTION__, __LINE__, ctx, msg,
+			msg_size, md_buf->data, md_buf->len, md_buf->max_len);
+#endif
+
+		memcpy(md_buf->data + md_buf->len, msg, msg_size);
+		md_buf->len += msg_size;
+		ret = 1;
+	}
+	return ret;
+}
+
+static int engine_sha1_final ( EVP_MD_CTX *ctx, unsigned char *md )
+{
+    op_handle_t handle = RMISAE_HANDLE_INITIALIZER;
+    int ret;
+    RMI_MD_DATA *md_buf = (RMI_MD_DATA *)ctx->md_data;
+
+    if(RMISEC_GLOBAL_FD < 0) {
+	    fprintf(stderr, "%s:%d Security file descriptor not initialized\n",
+		    __FUNCTION__, __LINE__);
+	    return 0;
+    }
+
+#if 0
+    fprintf(stderr, "%s:%d ctx=%p buf=%p len=%u\n", __FUNCTION__,
+	    __LINE__, ctx, md_buf->data, md_buf->len);
+#endif
+
+    if(!(RMISEC_GLOBAL_FD < 0 || md_buf->len <= 0)) {
+	    ret = p_RMISEC_op_init(RMISEC_GLOBAL_FD, &handle);
+	    if(ret) {
+		    return 0;
+	    }
+	    ret = p_RMISEC_sha1(handle, (const unsigned char *)md_buf->data,
+				md_buf->len, md);
+	    p_RMISEC_op_cleanup(&handle);
+    } else {
+	    SHA1(md_buf->data, md_buf->len, md);
+	    ret = RMISAE_SUCCESS;
+    }
+    return IS_SUCCESS_SAEOP(ret);
+}
+
+#if 0 /* COMMENTED OUT */
+/* SHA1stuff Functions
+ */
+static int engine_sha1_init ( EVP_MD_CTX *ctx )
+{
+    /*
+     * Everything is done in a single ioctl call in sha1_final().
+     */
+
+    //DBG_PRINT("\t**engine_sha1_init(): ENTER**\n");
+    /* Init our digest storage */
+#ifndef ONESHOT
+    RMI_MD_DATA  *data;
+
+    data = (RMI_MD_DATA *) ctx->md_data;
+    if (data != NULL) {
+        data->len = 0;
+        data->max_len = RMI_DGST_BUF_BLKSIZE;
+        data->data = OPENSSL_malloc (RMI_DGST_BUF_BLKSIZE);
+        if (data->data == NULL) {
+            DBG_PRINT("\t**engine_sha1_init(): OPENSSL_malloc(%d)==NULL **\n",
+                 RMI_DGST_BUF_BLKSIZE);
+            return 0;
+        }
+    }
+    //DBG_PRINT("\t**engine_sha1_init(): len=%d  data=%p  RETURN(1)**\n",
+    //         data->len, data->data);
+    return 1 ;
+#else
+    ctx->flags |= EVP_MD_CTX_FLAG_ONESHOT;
+    DBG_PRINT("%s:%d ENTER\n", __FUNCTION__, __LINE__);
+#endif
+    return 1;
+}
+
+static int engine_sha1_final ( EVP_MD_CTX *ctx, unsigned char *md )
+{
+    DBG_PRINT("%s:%d ENTER\n", __FUNCTION__, __LINE__);
+    memcpy(md, (unsigned char *)ctx->md_data, SHA_DIGEST_LENGTH);
+    return 1;
+}
+
+#endif /* 0 - COMMENTED OUT */
+
+/* SHA256 stuff Functions
+ */
+static int engine_sha256_init ( EVP_MD_CTX *ctx )
+{
+    ctx->flags |= EVP_MD_CTX_FLAG_ONESHOT;
+    return 1;
+}
+
+
+static int engine_sha256_update ( EVP_MD_CTX *ctx,
+                                const void *message,
+                                size_t msg_size )
+{
+    op_handle_t handle = RMISAE_HANDLE_INITIALIZER;
+    int ret;
+    unsigned char *buf = (unsigned char *)ctx->md_data;
+
+    if(RMISEC_GLOBAL_FD < 0) {
+	    fprintf(stderr, "%s:%d Security file descriptor not initialized\n",
+		    __FUNCTION__, __LINE__);
+	    return 0;
+    }
+
+    if(msg_size) {
+	    ret = p_RMISEC_op_init(RMISEC_GLOBAL_FD, &handle);
+	    if(ret) {
+		    return 0;
+	    }
+
+	    ret = p_RMISEC_sha256(handle, (const unsigned char *)message, msg_size, buf);
+	    if(IS_SUCCESS_SAEOP(ret)) {
+		    ret = 1;
+	    }
+	    p_RMISEC_op_cleanup(&handle);
+    } else {
+	    SHA256(message, msg_size, buf);
+	    ret = RMISAE_SUCCESS;
+    }
+    return ret;
+}
+
+static int engine_sha256_final ( EVP_MD_CTX *ctx, unsigned char *md )
+{
+    memcpy(md, (unsigned char *)ctx->md_data, SHA256_DIGEST_LENGTH);
+    return 1;
+}
+
+/* SHA384 stuff Functions
+ */
+static int engine_sha384_init ( EVP_MD_CTX *ctx )
+{
+    ctx->flags |= EVP_MD_CTX_FLAG_ONESHOT;
+    return 1;
+}
+
+
+static int engine_sha384_update ( EVP_MD_CTX *ctx,
+                                const void *message,
+                                size_t msg_size )
+{
+    op_handle_t handle = RMISAE_HANDLE_INITIALIZER;
+    int ret;
+    unsigned char *buf = (unsigned char *)ctx->md_data;
+
+    if(msg_size) {
+	    if(RMISEC_GLOBAL_FD < 0) {
+		    fprintf(stderr, "%s:%d Security file descriptor not initialized\n",
+			    __FUNCTION__, __LINE__);
+		    return 0;
+	    }
+
+	    ret  = p_RMISEC_op_init(RMISEC_GLOBAL_FD, &handle);
+	    if(ret) {
+		    return 0;
+	    }
+	    ret = p_RMISEC_sha384(handle, (const unsigned char *)message, msg_size, buf);
+	    if(IS_SUCCESS_SAEOP(ret)) {
+		    ret = 1;
+	    }
+	    p_RMISEC_op_cleanup(&handle);
+    } else {
+	    SHA384(message, msg_size, buf);
+	    ret = RMISAE_SUCCESS;
+    }
+    return ret;
+}
+
+static int engine_sha384_final ( EVP_MD_CTX *ctx, unsigned char *md )
+{
+    memcpy(md, (unsigned char *)ctx->md_data, SHA384_DIGEST_LENGTH);
+    return 1;
+}
+
+/* SHA512 stuff Functions
+ */
+static int engine_sha512_init ( EVP_MD_CTX *ctx )
+{
+    ctx->flags |= EVP_MD_CTX_FLAG_ONESHOT;
+    return 1;
+}
+
+
+static int engine_sha512_update ( EVP_MD_CTX *ctx,
+                                const void *message,
+                                size_t msg_size )
+{
+    op_handle_t handle = RMISAE_HANDLE_INITIALIZER;
+    int ret;
+    unsigned char *buf = (unsigned char *)ctx->md_data;
+
+    if(msg_size) {
+	    if(RMISEC_GLOBAL_FD < 0) {
+		    fprintf(stderr, "%s:%d Security file descriptor not initialized\n",
+			    __FUNCTION__, __LINE__);
+		    return 0;
+	    }
+
+	    ret  = p_RMISEC_op_init(RMISEC_GLOBAL_FD, &handle);
+	    if(ret) {
+		    return 0;
+	    }
+	    ret = p_RMISEC_sha512(handle, (const unsigned char *)message, msg_size, buf);
+	    if(IS_SUCCESS_SAEOP(ret)) {
+		    ret = 1;
+	    }
+	    p_RMISEC_op_cleanup(&handle);
+    } else {
+	    SHA512(message, msg_size, buf);
+	    ret = RMISAE_SUCCESS;
+    }
+    return ret;
+}
+
+static int engine_sha512_final ( EVP_MD_CTX *ctx, unsigned char *md )
+{
+    memcpy(md, (unsigned char *)ctx->md_data, SHA512_DIGEST_LENGTH);
+    return 1;
+}
+
+/* MD5 stuff Functions
+ */
+static int engine_md5_final ( EVP_MD_CTX *ctx, unsigned char *md )
+{
+    op_handle_t handle = RMISAE_HANDLE_INITIALIZER;
+    int ret;
+    RMI_MD_DATA *md_buf = (RMI_MD_DATA *)ctx->md_data;
+
+    if(RMISEC_GLOBAL_FD < 0) {
+	    fprintf(stderr, "%s:%d Security file descriptor not initialized\n",
+		    __FUNCTION__, __LINE__);
+	    return 0;
+    }
+
+    DBG_PRINT("%s:%d ENTER size=%zu\n", __FUNCTION__, __LINE__, msg_size);
+    if(!(RMISEC_GLOBAL_FD < 0 || md_buf->len <= 0)) {
+	    ret = p_RMISEC_op_init(RMISEC_GLOBAL_FD, &handle);
+	    if(ret) {
+		    return 0;
+	    }
+	    ret = p_RMISEC_md5(handle, (const unsigned char *)md_buf->data,
+			       md_buf->len, md);
+	    p_RMISEC_op_cleanup(&handle);
+    } else {
+	    MD5(md_buf->data, md_buf->len, md);
+	    ret = RMISAE_SUCCESS;
+    }
+    return IS_SUCCESS_SAEOP(ret);
+}
+
+
+#if 0 /* COMMENTED_OUT */
+static int engine_md5_init ( EVP_MD_CTX *ctx )
+{
+    ctx->flags |= EVP_MD_CTX_FLAG_ONESHOT;
+    return 1;
+}
+
+
+static int engine_md5_update ( EVP_MD_CTX *ctx,
+                               const void *message, size_t msg_size )
+{
+    op_handle_t handle = RMISAE_HANDLE_INITIALIZER;
+    unsigned char *buf  = (unsigned  char *)ctx->md_data;
+    int ret;
+
+    if(msg_size) {
+	    if(RMISEC_GLOBAL_FD < 0) {
+		    fprintf(stderr, "%s:%d Security file descriptor not initialized\n",
+			    __FUNCTION__, __LINE__);
+		    return 0;
+	    }
+
+	    ret  = p_RMISEC_op_init(RMISEC_GLOBAL_FD, &handle);
+	    if(ret) {
+		    return 0;
+	    }
+
+	    DBG_PRINT("%s:%d ctx=%p md_data=%p\n", __FUNCTION__, __LINE__, ctx, buf);
+	    ret = p_RMISEC_md5(handle, (const unsigned char *)message, msg_size, buf);
+	    if(IS_SUCCESS_SAEOP(ret)) {
+		    ret = 1;
+	    }
+	    p_RMISEC_op_cleanup(&handle);
+    } else {
+	    MD5(message, msg_size, buf);
+	    ret = RMISAE_SUCCESS;
+    }
+    return ret;
+}
+
+
+static int engine_md5_final ( EVP_MD_CTX *ctx, unsigned char *md )
+{
+    memcpy(md, ((unsigned char *)ctx->md_data), MD5_DIGEST_LENGTH);
+    return 1;
+}
+#endif /* COMMENTED_OUT */
+
+static int engine_md_cleanup2 ( EVP_MD_CTX *ctx )
+{
+    RMI_MD_DATA *md_data;
+
+    //DBG_PRINT("\t**engine_md_cleanup(): ENTER**\n");
+
+    if ((ctx == NULL) || (ctx->md_data == NULL))
+        return 1;
+
+    md_data = (RMI_MD_DATA *) ctx->md_data ;
+
+    if (md_data->data != NULL)
+        OPENSSL_free (md_data->data);
+    md_data->data = NULL;
+    md_data->len = md_data->max_len = 0;
+
+    //DBG_PRINT("\t**engine_md_cleanup(): RETURN(1)**\n");
+    return 1 ;
+}
+
+static int engine_md_cleanup ( EVP_MD_CTX *ctx )
+{
+    return 1;
+}
+
+static int engine_md_copy2 ( EVP_MD_CTX *to, const EVP_MD_CTX *from )
+{
+    const RMI_MD_DATA *from_md = (RMI_MD_DATA *)from->md_data ;
+    RMI_MD_DATA *to_md= (RMI_MD_DATA *)to->md_data ;
+
+#if 0
+    fprintf(stderr, "%s:%d from=%p to=%p fbuf=%p fbuf_max_len=%u "
+	    "tbuf=%p tbuf_max_len=%u\n", __FUNCTION__, __LINE__,
+	    from, to, from_md->data, from_md->max_len,
+	    to_md->data, to_md->max_len);
+#endif
+
+    if ((to_md->data = OPENSSL_malloc ( from_md->max_len )) == NULL) {
+	    DBG_PRINT("\t**engine_md_copy(): !FAIL! RETURN(0)**\n");
+	    return 0;
+    }
+
+    memcpy ( to_md->data, from_md->data, from_md->len ) ;
+    to_md->max_len = from_md->max_len;
+    to_md->len = from_md->len;
+    return 1;
+}
+
+static int engine_md_copy ( EVP_MD_CTX *to, const EVP_MD_CTX *from )
+{
+    DBG_PRINT("%s:%d md_data=%p from=%p to=%p\n", __FUNCTION__, __LINE__,
+	      from->md_data, from, to);
+    memcpy((unsigned char *)to->md_data, (unsigned char *)from->md_data,
+	   from->digest->ctx_size);
+    return 1;
+}
+
+
+/* General function cloned on hw_openbsd_dev_crypto one ... */
+static int engine_ciphers (ENGINE *e, const EVP_CIPHER **cipher,
+			   const int **nids, int nid)
+{
+
+    if (cipher == NULL) {
+        /* We are returning a list of supported nids */
+        *nids = engine_cipher_nids ;
+        return engine_cipher_nids_num ;
+    }
+    /* We are being asked for a specific cipher */
+    if ( nid == NID_aes_128_cbc ) {
+        *cipher = &engine_aes_128_cbc  ;
+    }
+    else if ( nid == NID_aes_192_cbc ) {
+        *cipher = &engine_aes_192_cbc  ;
+    }
+    else if ( nid == NID_aes_256_cbc ) {
+        *cipher = &engine_aes_256_cbc  ;
+    }
+    else if ( nid == NID_des_cbc ) {
+        *cipher = &engine_des_cbc ;
+    }
+    else if ( nid == NID_des_ede3_cbc ) {
+        *cipher = &engine_des_ede3_cbc ;
+    }
+#if 0
+    else if ( nid == NID_rc4 ) {
+        *cipher = &engine_arc4  ;
+    }
+#endif /* 0 */
+    else {
+        *cipher = NULL ;
+        return 0 ;
+    }
+
+    return 1 ;
+}
+
+
+static int engine_aes_128_init_key ( EVP_CIPHER_CTX *ctx, const unsigned char *key, const unsigned char *iv, int enc )
+{
+    RMI_AES_KEY *key_info = NULL ;
+
+    key_info = (RMI_AES_KEY *) ( ctx->cipher_data ) ;
+
+    key_info->key_size = ctx->key_len;
+
+    memcpy ( &( key_info->key [ 0 ] ), key, ctx->key_len ) ;
+    if( iv ) {
+        memcpy ( &( key_info->iv  [ 0 ] ), iv,  AES_BLOCK_SIZE ) ;
+        memcpy ( &( ctx->iv  [ 0 ] ),      iv,  AES_BLOCK_SIZE ) ;
+    }
+
+    DBG_PRINT_BUF("**ENGINE: aes-128-cbc-init  IV: ", iv, 16);
+    DBG_PRINT_BUF("**ENGINE: aes-128-cbc-init  KEY: ", key, 16);
+
+    return 1;
+}
+
+
+static int engine_aes_128_cbc_cipher ( EVP_CIPHER_CTX *ctx,
+                                       unsigned char *out,
+                                       const unsigned char *in,
+                                       unsigned int in_len )
+{
+    unsigned char  save_iv[AES_BLOCK_SIZE];
+    RMI_AES_KEY    *key_info = NULL ;
+    int            to_return = 0 ;
+    op_handle_t handle = RMISAE_HANDLE_INITIALIZER;
+
+    if(RMISEC_GLOBAL_FD < 0) {
+	    fprintf(stderr, "%s:%d Security file descriptor not initialized\n",
+		    __FUNCTION__, __LINE__);
+	    return 0;
+    }
+
+    if ((ctx == NULL) || (out == NULL) || (in == NULL) || (in_len == 0)) {
+        DBG_PRINT("engine_aes_128_cbc_cipher: "
+                "ctx=%p  out=%p  in=%p  in_len=%d \n",
+                ctx, out, in, in_len);
+        return (0);
+    }
+    if ((in_len % ctx->cipher->block_size) != 0) {
+        DBG_PRINT("engine_aes_128_cbc_cipher: in_len(%d) MOD (%d) != 0  \n",
+                   in_len, ctx->cipher->block_size);
+        return (0);
+    }
+
+    if (p_RMISEC_aes128_cipher == NULL) {
+        DBG_PRINT("engine_aes_128_cbc_cipher: NULL Function Ptr \n");
+        return (0);
+    }
+
+    key_info = (RMI_AES_KEY *) ( ctx->cipher_data ) ;
+    if (key_info == NULL) {
+        DBG_PRINT("engine_aes_128_cbc_cipher: NULL Key_Info Ptr \n");
+        return (0);
+    }
+
+    if (ctx->encrypt == 0) { /* decrypt ? */
+        memcpy ( &save_iv[0],
+                 (void *)(in + (in_len - ctx->cipher->iv_len)),
+                 ctx->cipher->iv_len );
+    }
+
+    DBG_PRINT_BUF("**ENGINE: aes-128-cbc-cipher  IV: ", ctx->iv, 16);
+    DBG_PRINT_BUF("**ENGINE: aes-128-cbc-cipher  KEY: ", key_info->key, 16);
+    to_return = p_RMISEC_op_init(RMISEC_GLOBAL_FD, &handle);
+    if(to_return) {
+	    fprintf(stderr,
+		    "%s:%d Handle init failed. error=%d\n",
+		    __FILE__, __LINE__, to_return);
+	    return 0;
+    }
+
+    to_return = p_RMISEC_aes128_cipher ( handle,
+                                         key_info->key,
+                                         ctx->iv,
+                                         ctx->encrypt,
+                                         in, in_len, out ) ;
+
+    p_RMISEC_op_cleanup(&handle);
+
+    if (!IS_SUCCESS_SAEOP(to_return)) {
+        /* Do in software */
+        AES_KEY aes128_ks;
+
+        DBG_PRINT("engine_aes_128_cbc_cipher: HW Error - Revert to SW\n");
+        if( ctx->encrypt )
+            AES_set_encrypt_key(key_info->key,128,&aes128_ks);
+        else
+            AES_set_decrypt_key(key_info->key,128,&aes128_ks);
+
+        AES_cbc_encrypt( in, out, in_len, &aes128_ks,
+                         ctx->iv, ctx->encrypt );
+        to_return = RMISAE_SUCCESS;
+    } else {
+        void *iv;
+
+        if (ctx->encrypt == 0) {  /* decrypt ? */
+            iv = &save_iv[0]; /* saved before CIPHER op */
+        }
+        else {
+            iv = (void *)(out + (in_len - ctx->cipher->iv_len));
+        }
+#ifdef OPENSSL_EVP_NOT_USED
+        memcpy ( key_info->iv, iv, ctx->cipher->iv_len );
+#endif
+        memcpy ( ctx->iv, iv, ctx->cipher->iv_len );
+    }
+
+    return to_return ;
+}
+
+static int engine_aes_192_init_key ( EVP_CIPHER_CTX *ctx, const unsigned char *key, const unsigned char *iv, int enc )
+{
+    RMI_AES_KEY *key_info = NULL ;
+
+    /*  DPK DEBUG */
+    DBG_PRINT("\t**ENGINE: ENTER engine_aes_192_init **\n");
+
+    key_info = (RMI_AES_KEY *) ( ctx->cipher_data ) ;
+
+    key_info->key_size = ctx->key_len;
+
+    memcpy ( &( key_info->key [ 0 ] ), key, ctx->key_len ) ;
+    if( iv ) {
+        memcpy ( &( key_info->iv  [ 0 ] ), iv,  AES_BLOCK_SIZE ) ;
+        memcpy ( &( ctx->iv  [ 0 ] ),      iv,  AES_BLOCK_SIZE ) ;
+    }
+
+    DBG_PRINT_BUF("**ENGINE: aes-192-cbc-init  IV: ", ctx->iv, 16);
+    DBG_PRINT_BUF("**ENGINE: aes-192-cbc-init  KEY: ", key_info->key, 24 );
+
+    /*  DPK DEBUG */
+    DBG_PRINT("\t**ENGINE: EXIT engine_aes_192_init **\n");
+
+    return 1;
+}
+
+static int engine_aes_192_cbc_cipher ( EVP_CIPHER_CTX *ctx,
+                                       unsigned char *out,
+                                       const unsigned char *in,
+                                       unsigned int in_len )
+{
+    unsigned char  save_iv[AES_BLOCK_SIZE];
+    RMI_AES_KEY    *key_info = NULL ;
+    int            to_return = 0 ;
+    op_handle_t handle = RMISAE_HANDLE_INITIALIZER;
+
+    /*  DPK DEBUG */
+    DBG_PRINT("\t**ENGINE: ENTER engine_aes_192_cbc_cipher **\n");
+
+    if(RMISEC_GLOBAL_FD < 0) {
+	    fprintf(stderr, "%s:%d Security file descriptor not initialized\n",
+		    __FUNCTION__, __LINE__);
+	    return 0;
+    }
+
+    if ((ctx == NULL) || (out == NULL) || (in == NULL) || (in_len == 0)) {
+     DBG_PRINT("engine_aes_192_cbc_cipher: ctx=%p  out=%p  in=%p  in_len=%d \n",
+                ctx, out, in, in_len);
+        return (0);
+    }
+    if ((in_len % ctx->cipher->block_size) != 0) {
+        DBG_PRINT("engine_aes_192_cbc_cipher: in_len(%d) MOD (%d) != 0  \n",
+                 in_len, ctx->cipher->block_size);
+        return (0);
+    }
+
+    if (p_RMISEC_aes192_cipher == NULL) {
+        DBG_PRINT("engine_aes_192_cbc_cipher: NULL Function Ptr \n");
+        return (0);
+    }
+
+    key_info = (RMI_AES_KEY *) ( ctx->cipher_data ) ;
+    if (key_info == NULL) {
+        DBG_PRINT("engine_aes_192_cbc_cipher: NULL Key_Info Ptr \n");
+        return (0);
+    }
+
+    if (ctx->encrypt == 0) { /* decrypt ? */
+        memcpy ( &save_iv[0],
+                 (void *)(in + (in_len - ctx->cipher->iv_len)),
+                 ctx->cipher->iv_len );
+    }
+
+    DBG_PRINT("\t**ENGINE: engine_aes_192_cbc_cipher before LIB call **\n");
+
+    DBG_PRINT_BUF("**ENGINE: aes-192-cbc-cipher  IV: ", ctx->iv, 16);
+    DBG_PRINT_BUF("**ENGINE: aes-192-cbc-cipher  KEY: ", key_info->key, 24);
+
+    to_return = p_RMISEC_op_init(RMISEC_GLOBAL_FD, &handle);
+    if(to_return) {
+	    fprintf(stderr,
+		    "%s:%d Handle init failed. error=%d\n",
+		    __FILE__, __LINE__, to_return);
+	    return 0;
+    }
+
+    to_return = p_RMISEC_aes192_cipher ( handle,
+                                         key_info->key,
+                                         ctx->iv,
+                                         ctx->encrypt,
+                                         in, in_len, out ) ;
+
+    p_RMISEC_op_cleanup(&handle);
+
+    if (!IS_SUCCESS_SAEOP(to_return)) {
+        /* Do in software */
+        AES_KEY aes192_ks;
+
+        DBG_PRINT("engine_aes_192_cbc_cipher: HW Error - Revert to SW\n");
+        if( ctx->encrypt )
+            AES_set_encrypt_key(key_info->key,192,&aes192_ks);
+        else
+            AES_set_decrypt_key(key_info->key,192,&aes192_ks);
+
+        AES_cbc_encrypt( in, out, in_len, &aes192_ks,
+                         ctx->iv, ctx->encrypt );
+        to_return = RMISAE_SUCCESS;
+    } else {
+        void *iv;
+
+        if (ctx->encrypt == 0) {  /* decrypt ? */
+            iv = &save_iv[0];  /* saved before CIPHER op */
+        }
+        else {
+            iv = (void *)(out + (in_len - ctx->cipher->iv_len));
+        }
+#ifdef OPENSSL_EVP_NOT_USED
+        memcpy ( key_info->iv, iv, ctx->cipher->iv_len );
+#endif
+        memcpy ( ctx->iv, iv, ctx->cipher->iv_len );
+    }
+
+    /*  DPK DEBUG */
+    DBG_PRINT("\t**ENGINE: EXIT engine_aes_192_cbc_cipher **\n");
+    return to_return ;
+}
+
+static int engine_aes_256_init_key ( EVP_CIPHER_CTX *ctx, const unsigned char *key, const unsigned char *iv, int enc )
+{
+    RMI_AES_KEY *key_info = NULL ;
+
+    /*  DPK DEBUG */
+    DBG_PRINT("\t**ENGINE: ENTER engine_aes_256_init **\n");
+
+    key_info = (RMI_AES_KEY *) ( ctx->cipher_data ) ;
+
+    key_info->key_size = ctx->key_len;
+
+    memcpy ( &( key_info->key [ 0 ] ), key, ctx->key_len ) ;
+    if( iv ) {
+        memcpy ( &( key_info->iv  [ 0 ] ), iv,  AES_BLOCK_SIZE ) ;
+        memcpy ( &( ctx->iv  [ 0 ] ),      iv,  AES_BLOCK_SIZE ) ;
+    }
+
+    DBG_PRINT_BUF("**ENGINE: aes-256-cbc-init  IV: ", ctx->iv, 16);
+    DBG_PRINT_BUF("**ENGINE: aes-256-cbc-init  KEY: ", key_info->key, 32 );
+
+    /*  DPK DEBUG */
+    DBG_PRINT("\t**ENGINE: EXIT engine_aes_256_init **\n");
+
+    return 1;
+}
+
+
+static int engine_aes_256_cbc_cipher ( EVP_CIPHER_CTX *ctx,
+                                       unsigned char *out,
+                                       const unsigned char *in,
+                                       unsigned int in_len )
+{
+    unsigned char  save_iv[AES_BLOCK_SIZE];
+    RMI_AES_KEY    *key_info = NULL ;
+    int            to_return = 0 ;
+    op_handle_t    handle = RMISAE_HANDLE_INITIALIZER;
+
+    /*  DPK DEBUG */
+    DBG_PRINT("\t**ENGINE: ENTER engine_aes_256_cbc_cipher **\n");
+
+    if(RMISEC_GLOBAL_FD < 0) {
+	    fprintf(stderr, "%s:%d Security file descriptor not initialized\n",
+		    __FUNCTION__, __LINE__);
+	    return 0;
+    }
+
+    if ((ctx == NULL) || (out == NULL) || (in == NULL) || (in_len == 0)) {
+     DBG_PRINT("engine_aes_256_cbc_cipher: ctx=%p  out=%p  in=%p  in_len=%d \n",
+                ctx, out, in, in_len);
+        return (0);
+    }
+    if ((in_len % ctx->cipher->block_size) != 0) {
+        DBG_PRINT("engine_aes_256_cbc_cipher: in_len(%d) MOD (%d) != 0  \n",
+                 in_len, ctx->cipher->block_size);
+        return (0);
+    }
+
+    if (p_RMISEC_aes256_cipher == NULL) {
+        DBG_PRINT("engine_aes_256_cbc_cipher: NULL Function Ptr \n");
+        return (0);
+    }
+
+    key_info = (RMI_AES_KEY *) ( ctx->cipher_data ) ;
+    if (key_info == NULL) {
+        DBG_PRINT("engine_aes_256_cbc_cipher: NULL Key_Info Ptr \n");
+        return (0);
+    }
+
+    if (ctx->encrypt == 0) { /* decrypt ? */
+        memcpy ( &save_iv[0],
+                 (void *)(in + (in_len - ctx->cipher->iv_len)),
+                 ctx->cipher->iv_len );
+    }
+
+    DBG_PRINT("\t**ENGINE: engine_aes_256_cbc_cipher before LIB call **\n");
+
+    DBG_PRINT_BUF("**ENGINE: aes-256-cbc-cipher  IV: ", ctx->iv, 16);
+    DBG_PRINT_BUF("**ENGINE: aes-256-cbc-cipher  KEY: ", key_info->key, 32);
+
+    to_return = p_RMISEC_op_init(RMISEC_GLOBAL_FD, &handle);
+    if(to_return) {
+	    fprintf(stderr,
+		    "%s:%d Handle init failed. error=%d\n",
+		    __FUNCTION__, __LINE__, to_return);
+	    return 0;
+    }
+
+    to_return = p_RMISEC_aes256_cipher ( handle,
+                                         key_info->key,
+                                         ctx->iv,
+                                         ctx->encrypt,
+                                         in, in_len, out ) ;
+
+    p_RMISEC_op_cleanup(&handle);
+
+    if (!IS_SUCCESS_SAEOP(to_return)) {
+        /* Do in software */
+        AES_KEY aes256_ks;
+
+        DBG_PRINT("engine_aes_256_cbc_cipher: HW Error - Revert to SW\n");
+        if( ctx->encrypt )
+            AES_set_encrypt_key(key_info->key,256,&aes256_ks);
+        else
+            AES_set_decrypt_key(key_info->key,256,&aes256_ks);
+
+        AES_cbc_encrypt( in, out, in_len, &aes256_ks,
+                         ctx->iv, ctx->encrypt );
+        to_return = RMISAE_SUCCESS;
+    } else {
+        void *iv;
+
+        if (ctx->encrypt == 0) {  /* decrypt ? */
+            iv = &save_iv[0];  /* saved before CIPHER op */
+        }
+        else {
+            iv = (void *)(out + (in_len - ctx->cipher->iv_len));
+        }
+#ifdef OPENSSL_EVP_NOT_USED
+        memcpy ( key_info->iv, iv, ctx->cipher->iv_len );
+#endif
+        memcpy ( ctx->iv, iv, ctx->cipher->iv_len );
+    }
+
+    /*  DPK DEBUG */
+    DBG_PRINT("\t**ENGINE: EXIT engine_aes_256_cbc_cipher **\n");
+
+    return to_return ;
+}
+
+
+static int engine_des_init_key ( EVP_CIPHER_CTX *ctx, const unsigned char *key,
+				 const unsigned char *iv, int enc)
+{
+    int to_return = 0 ;
+    RMI_DES_KEY *key_info = NULL ;
+    DBG_PRINT("%s:%d ENTER\n", __FUNCTION__, __LINE__);
+
+    key_info = (RMI_DES_KEY *)(ctx->cipher_data) ;
+    memset(key_info, 0, sizeof(RMI_DES_KEY));
+
+    key_info->key_size = ctx->key_len;
+
+    memcpy (&(key_info->des_key[0]), key, ctx->key_len) ;
+    memcpy (&(key_info->des_iv [0]), iv, RMI_DES_BLOCK_SIZE);
+    to_return = 1 ;
+
+    return to_return ;
+}
+
+
+static int engine_des_cbc_cipher (EVP_CIPHER_CTX *ctx,
+                                  unsigned char *out,
+                                  const unsigned char *in, unsigned int in_len)
+{
+    unsigned char  save_iv[RMI_DES_BLOCK_SIZE];
+    RMI_DES_KEY    *key_info = NULL ;
+    int            to_return = 0 ;
+    op_handle_t    handle = RMISAE_HANDLE_INITIALIZER;
+
+    DBG_PRINT("\t**ENGINE: des-cbc  op=%s \n",
+              (ctx->encrypt ? "encrypt" : "decrypt"));
+
+    if(RMISEC_GLOBAL_FD < 0) {
+	    fprintf(stderr, "%s:%d Security file descriptor not initialized\n",
+		    __FUNCTION__, __LINE__);
+	    return 0;
+    }
+
+    if ((ctx == NULL) || (out == NULL) ||
+        (in == NULL) || (in_len == 0)) {
+        DBG_PRINT("engine_des_cbc_cipher: ctx=%p  out=%p  in=%p  in_len=%d \n",
+                  ctx, out, in, in_len);
+        return (0);
+    }
+    if ((in_len % ctx->cipher->block_size) != 0) {
+        DBG_PRINT("engine_des_cbc_cipher: in_len(%d) MOD (%d) != 0  \n",
+                  in_len, ctx->cipher->block_size);
+        return (0);
+    }
+
+    if (p_RMISEC_des_cipher == NULL) {
+        DBG_PRINT("engine_des_cbc_cipher: NULL Function Ptr \n");
+        return (0);
+    }
+
+    key_info = (RMI_DES_KEY *) ( ctx->cipher_data ) ;
+    if (key_info == NULL) {
+        DBG_PRINT("engine_des_cbc_cipher: NULL Key_Info Ptr \n");
+        return (0);
+    }
+
+    if (ctx->encrypt == 0) { /* decrypt ? */
+        memcpy ( &save_iv[0],
+                 (void *)(in + (in_len - ctx->cipher->iv_len)),
+                 ctx->cipher->iv_len );
+    }
+
+    DBG_PRINT_BUF("**ENGINE: des-cbc  KEY: ", key_info->des_key, 8);
+    DBG_PRINT_BUF("**ENGINE: des-cbc  IV: ", key_info->des_iv, 8);
+    DBG_PRINT_BUF("**ENGINE: des-cbc  INPUT: ", (void *)in, in_len);
+
+    to_return = p_RMISEC_op_init(RMISEC_GLOBAL_FD, &handle);
+    if(to_return) {
+	    fprintf(stderr,
+		    "%s:%d Handle init failed. error=%d\n",
+		    __FUNCTION__, __LINE__, to_return);
+	    return 0;
+    }
+
+    to_return = p_RMISEC_des_cipher ( handle,
+                                      key_info->des_key,
+                                      ctx->iv,
+                                      ctx->encrypt,
+                                      (void *)in, in_len,
+                                      out ) ;
+
+    p_RMISEC_op_cleanup(&handle);
+    if (!IS_SUCCESS_SAEOP(to_return)) {
+        DES_cblock *deskey = (DES_cblock *)&key_info->des_key[0];
+        DBG_PRINT("engine_des_cbc_cipher: HW Error - Revert to SW\n");
+
+        /* Do in software */
+        DES_key_schedule des_sch;
+
+        DES_set_key_unchecked( deskey, &des_sch );
+
+        DES_ncbc_encrypt( in, out, in_len, &des_sch,
+                          (DES_cblock *)ctx->iv, ctx->encrypt);
+
+        to_return = RMISAE_SUCCESS;
+    } else {
+	    DBG_PRINT_BUF("**ENGINE: des-cbc  OUTPUT: ", out, in_len);
+	    void *iv;
+
+	    if (ctx->encrypt == 0) {  /* decrypt ? */
+		    iv = &save_iv[0];  /* saved before CIPHER op */
+	    }
+	    else {
+		    iv = (void *)(out + (in_len - ctx->cipher->iv_len));
+	    }
+#ifdef OPENSSL_EVP_NOT_USED
+	    memcpy ( key_info->des_iv, iv, ctx->cipher->iv_len );
+#endif
+	    memcpy ( ctx->iv, iv, ctx->cipher->iv_len );
+	    DBG_PRINT_BUF("**ENGINE: des-cbc  IV: ", ctx->iv, 8);
+    }
+    return to_return ;
+}
+
+
+static int engine_des_ede3_init_key ( EVP_CIPHER_CTX *ctx, const unsigned char *key, const unsigned char *iv, int enc )
+{
+    RMI_3DES_KEY *key_info = NULL ;
+
+    key_info = (RMI_3DES_KEY *) ( ctx->cipher_data ) ;
+    memset(key_info, 0, sizeof(RMI_3DES_KEY));
+
+    key_info->key_size = ctx->key_len;
+    memcpy(&(key_info->des3_key[0]), key, ctx->key_len);
+    memcpy(&(key_info->des3_iv[0]), iv, RMI_DES_BLOCK_SIZE);
+
+    return 1;
+}
+
+
+static int engine_des_ede3_cbc_cipher ( EVP_CIPHER_CTX *ctx,
+                                        unsigned char *out,
+                                        const unsigned char *in,
+                                        unsigned int in_len )
+{
+    unsigned char  save_iv[RMI_DES_BLOCK_SIZE];
+    RMI_3DES_KEY *key_info = NULL ;
+    int          to_return = 0 ;
+    op_handle_t handle = RMISAE_HANDLE_INITIALIZER;
+
+    DBG_PRINT("\t**ENGINE: engine_des_ede3_cbc  op=%s \n",
+              (ctx->encrypt ? "encrypt" : "decrypt"));
+
+    if(RMISEC_GLOBAL_FD < 0) {
+	    fprintf(stderr, "%s:%d Security file descriptor not initialized\n",
+		    __FUNCTION__, __LINE__);
+	    return 0;
+    }
+
+    if ((ctx == NULL) || (out == NULL) ||
+        (in == NULL) || (in_len == 0)) {
+        DBG_PRINT("\t**ENGINE: engine_des_ede3_cbc: "
+                "ctx=%p  out=%p  in=%p  in_len=%d \n",
+                ctx, out, in, in_len);
+        return (0);
+    }
+    if ((in_len % ctx->cipher->block_size) != 0) {
+       DBG_PRINT("\t**ENGINE: "
+                 "engine_des_ede3_cbc: in_len(%d) MOD (%d) != 0 \n",
+                 in_len, ctx->cipher->block_size);
+        return (0);
+    }
+
+    if (p_RMISEC_3des_cipher == NULL) {
+       DBG_PRINT("\t**ENGINE: engine_des_ede3_cbc_cipher:"
+                 " NULL Function Ptr \n");
+        return (0);
+    }
+    key_info = (RMI_3DES_KEY *) ( ctx->cipher_data ) ;
+    if (key_info == NULL) {
+      DBG_PRINT("\t**ENGINE: engine_des_ede3_cbc_cipher: "
+                        "NULL Key_Info Ptr \n");
+        return (0);
+    }
+
+    if (ctx->encrypt == 0) { /* decrypt ? */
+        memcpy ( &save_iv[0],
+                 (void *)(in + (in_len - ctx->cipher->iv_len)),
+                 ctx->cipher->iv_len );
+    }
+
+    to_return = p_RMISEC_op_init(RMISEC_GLOBAL_FD, &handle);
+    if(to_return) {
+	    fprintf(stderr,
+		    "%s:%d Handle init failed. error=%d\n",
+		    __FUNCTION__, __LINE__, to_return);
+	    return 0;
+    }
+
+    to_return = p_RMISEC_3des_cipher ( handle,
+                                       key_info->des3_key,
+                                       ctx->iv,
+                                       ctx->encrypt,
+                                       (void *)in, in_len, out ) ;
+
+    p_RMISEC_op_cleanup(&handle);
+    if (!IS_SUCCESS_SAEOP(to_return)) {
+        DES_cblock *deskey = (DES_cblock *)&key_info->des3_key[0];
+
+        DBG_PRINT("engine_des_ede3_cbc_cipher: HW Error - Revert to SW\n");
+
+        /* Do in software */
+        DES_key_schedule des_sch1;
+        DES_key_schedule des_sch2;
+        DES_key_schedule des_sch3;
+
+        DES_set_key_unchecked( (const_DES_cblock *)deskey[0], &des_sch1 );
+        DES_set_key_unchecked( (const_DES_cblock *)deskey[1], &des_sch2 );
+        DES_set_key_unchecked( (const_DES_cblock *)deskey[2], &des_sch3 );
+
+        DES_ede3_cbc_encrypt( in, out, in_len,
+                              &des_sch1, &des_sch2, &des_sch3,
+                              (DES_cblock *)ctx->iv, ctx->encrypt);
+        to_return = RMISAE_SUCCESS;
+    } else {
+        void *iv = NULL;
+
+        if (ctx->encrypt == 0) {  /* decrypt ? */
+		iv = &save_iv[0];  /* saved before CIPHER op */
+        }
+        else {
+            iv = (void *)(out + (in_len - ctx->cipher->iv_len));
+        }
+#ifdef OPENSSL_EVP_NOT_USED
+        memcpy ( key_info->des3_iv, iv, ctx->cipher->iv_len );
+#endif
+        memcpy ( ctx->iv, iv, ctx->cipher->iv_len );
+    }
+
+    return to_return ;
+}
+
+#if 0
+static int engine_arc4_init_key (EVP_CIPHER_CTX *ctx, const unsigned char *key,
+				 const unsigned char *iv, int enc )
+{
+    RMI_ARC4_KEY *key_info = NULL ;
+    int          to_return = 0 ;
+
+    key_info = (RMI_ARC4_KEY *) ( ctx->cipher_data ) ;
+
+    key_info->rc4_key_len = ctx->key_len;
+    memcpy ( &( key_info->rc4_key [ 0 ] ), key, ctx->key_len ) ;
+    key_info->rc4_load = 0;
+#ifdef OPENSSL_EVP_NOT_USED
+    memcpy ( &( key_info->iv  [ 0 ] ), iv,  8 ) ;
+#endif
+
+    to_return = 1 ;
+
+    return to_return ;
+}
+
+static void print_text(unsigned char *buf, int len)
+{
+        int i;
+        unsigned char *ptr;
+
+        ptr = buf;
+        if (!buf) {
+                printf("Oops... passed null ptr to %s\n",__FUNCTION__);
+                return;
+        }
+
+        printf("\n");
+        for (i = 0; i < len; i++) {
+                printf("%02x",ptr[i]);
+                if (i % 16 == 15)
+                        printf("\n");
+        }
+        printf("\n");
+
+}
+
+static int engine_arc4_cipher ( EVP_CIPHER_CTX *ctx,
+                                        unsigned char *out,
+                                        const unsigned char *in,
+                                        unsigned int in_len )
+{
+    RMI_ARC4_KEY *key_info = NULL ;
+    int          to_return = 0 ;
+    op_handle_t handle = RMISAE_HANDLE_INITIALIZER;
+
+    if(RMISEC_GLOBAL_FD < 0) {
+	    fprintf(stderr, "%s:%d Security file descriptor not initialized\n",
+		    __FUNCTION__, __LINE__);
+	    return 0;
+    }
+
+    DBG_PRINT("\t**ENGINE: engine_arc4  op=%s \n",
+              (ctx->encrypt ? "encrypt" : "decrypt"));
+
+    if ((ctx == NULL) || (out == NULL) ||
+        (in == NULL) || (in_len == 0)) {
+        DBG_PRINT("\t**ENGINE: engine_arc4: "
+                "ctx=%p  out=%p  in=%p  in_len=%d \n",
+                ctx, out, in, in_len);
+        return (0);
+    }
+
+    if (p_RMISEC_arc4_cipher == NULL) {
+       DBG_PRINT("\t**ENGINE: engine_arc4_cipher:"
+                 " NULL Function Ptr \n");
+        return (0);
+    }
+    key_info = (RMI_ARC4_KEY *) ( ctx->cipher_data ) ;
+    if (key_info == NULL) {
+      DBG_PRINT("\t**ENGINE: engine_arc4_cipher: "
+                        "NULL Key_Info Ptr \n");
+        return (0);
+    }
+
+    to_return = p_RMISEC_op_init(RMISEC_GLOBAL_FD, &handle);
+    if(to_return) {
+	    fprintf(stderr,
+		    "%s:%d Handle init failed. error=%d\n",
+		    __FUNCTION__, __LINE__, to_return);
+	    return 0;
+    }
+
+
+    to_return = p_RMISEC_arc4_cipher (handle,
+				      key_info->rc4_key,
+				      key_info->rc4_key_len,
+				      (void *)in, in_len, out,
+				      key_info->rc4_load,
+				      CIPHER_SAVE_STATE,
+				      key_info->rc4_state);
+
+    p_RMISEC_op_cleanup(&handle);
+
+    if (!IS_SUCCESS_SAEOP(to_return)) {
+        RC4_KEY ks;
+        DBG_PRINT("engine_arc4_cipher: HW Error - Revert to SW\n");
+
+        /* Do in software */
+
+        memcpy(ks.data,key_info->rc4_state,256);
+        ks.x = key_info->rc4_state[262];
+        ks.y = key_info->rc4_state[263];
+
+	printf("printing start state from openssl:\n");
+	print_text(key_info->rc4_state, 264);
+
+        if (!key_info->rc4_load)
+        RC4_set_key(&ks,key_info->rc4_key_len, key_info->rc4_key);
+        RC4(&ks,in_len,in,out);
+        memcpy(key_info->rc4_state,ks.data,256);
+        key_info->rc4_state[262] = ks.x;
+        key_info->rc4_state[263] = ks.y;
+        to_return = 0 ;
+        key_info->rc4_load = 1;
+	printf("printing saved state from openssl:\n");
+	print_text(key_info->rc4_state, 264);
+	return 16;
+    } else {
+        key_info->rc4_load = 1;
+    }
+
+
+//    to_return = !to_return ;
+    return to_return ;
+}
+#endif /* 0 */
+
+static int engine_cipher_cleanup ( EVP_CIPHER_CTX *ctx )
+{
+#if 0
+    /* Do something here ?  */
+    if ( ctx->cipher->nid == NID_aes_128_cbc ) {
+    }
+    else if ( ctx->cipher->nid == NID_aes_192_cbc ) {
+    }
+    else if ( ctx->cipher->nid == NID_aes_256_cbc ) {
+    }
+    else if ( ctx->cipher->nid == NID_des_cbc ) {
+    }
+    else if ( ctx->cipher->nid == NID_des_ede3_cbc ) {
+    }
+    else if ( ctx->cipher->nid == NID_rc4 ) {
+    }
+#endif
+    return 1 ;
+}
+
+#ifndef OPENSSL_NO_ECDSA
+static ECDSA_SIG *rmisec_ec_dsa_do_sign(const unsigned char *dgst, int dlen,
+                const BIGNUM *in_kinv, const BIGNUM *in_r, EC_KEY *eckey) {
+    printf("Enter function %s\n",__FUNCTION__);
+    exit(0);
+    return 0;
+}
+static int rmisec_ec_dsa_sign_setup(EC_KEY *eckey, BN_CTX *ctx_in, BIGNUM **kinvp,
+                BIGNUM **rp) {
+    printf("Enter function %s\n",__FUNCTION__);
+    exit(0);
+    return 0;
+}
+static int rmisec_ec_dsa_do_verify(const unsigned char *dgst, int dgst_len,
+                const ECDSA_SIG *sig, EC_KEY *eckey) {
+    printf("Enter function %s\n",__FUNCTION__);
+    exit(0);
+    return 0;
+}
+#endif /* OPENSSL_NO_ECDSA */
+
+#ifndef OPENSSL_NO_EC
+
+static ECC_Mode_t inline
+get_gfp_degree(int degree) {
+	switch(degree) {
+	case 160:
+		return RMI_ECC_PRIME_160;
+	case 192:
+		return RMI_ECC_PRIME_192;
+	case 224:
+		return RMI_ECC_PRIME_224;
+	case 256:
+		return RMI_ECC_PRIME_256;
+	case 384:
+		return RMI_ECC_PRIME_384;
+	case 512:
+		return RMI_ECC_PRIME_512;
+	}
+	return -1;
+}
+
+static ECC_Mode_t inline
+get_gf2m_degree(int degree) {
+	switch(degree) {
+	case 163:
+		return RMI_ECC_BINARY_163;
+	case 191:
+		return RMI_ECC_BINARY_191;
+	case 233:
+		return RMI_ECC_BINARY_233;
+	}
+	return -1;
+}
+
+extern int BN_hex2bn(BIGNUM **a, const char *str);
+static int rmisec_ec_gfp_add(const EC_GROUP *group, EC_POINT *r,
+			     const EC_POINT *point1,
+			     const EC_POINT *point2, BN_CTX *ctx) {
+
+	op_handle_t handle = RMISAE_HANDLE_INITIALIZER;
+	BIGNUM *a = NULL, *n = NULL, *x1 = NULL, *con2k = NULL,
+		*y1 = NULL, *x2 = NULL, *y2 = NULL, *s_x = NULL, *s_y = NULL;
+	const BIGNUM *c;
+    int err = 1;
+    unsigned char rmisec_x1[256],
+                  rmisec_y1[256],
+                  rmisec_x2[256],
+                  rmisec_y2[256],
+                  rmisec_a[256],
+                  rmisec_n[256],
+                  rmisec_const[256],
+                  rmisec_s_x[256],
+                  rmisec_s_y[256];
+    int s_x_len, s_y_len;
+    int degree;
+    ECC_Mode_t deg;
+
+#ifdef SAE_BYPASS
+    if(err) {
+	    return ec_GFp_simple_add(group, r, point1, point2, ctx);
+    }
+#endif /* SAE_BYPASS */
+
+    degree = group->meth->group_get_degree(group);
+    deg = get_gfp_degree(degree);
+
+    if (RMISEC_GLOBAL_FD < 0 || p_RMISEC_ecc_gfp_add == NULL ||
+	deg == -1) {
+        return ec_GFp_simple_add(group, r, point1, point2, ctx);
+    }
+
+    /*
+     *  2) Point addition             R(x_r, y_r) = P(x_p, y_p) + Q(x_q, y_q)
+     *
+     *                 DATA IN                 DATA OUT
+     *                 =======                 ========
+     * src+glb_off->   x_p      dst+glb_off->  x_r
+     *                 y_p                     y_r
+     *                 x_q                     2x(3/4/6/8)=
+     *                 y_q                     6/8/12/16 dw
+     *                 a
+     *                 m
+     *                 cst
+     *                 7x(3/4/6/8)=
+     *                 21/28/42/56 dw */
+    BN_CTX_start(ctx);
+
+    /* build a and n */
+    x1 = BN_CTX_get(ctx);
+    x2 = BN_CTX_get(ctx);
+    y1 = BN_CTX_get(ctx);
+    y2 = BN_CTX_get(ctx);
+    a = BN_CTX_get(ctx);
+    n = BN_CTX_get(ctx);
+    if (!group->meth->group_get_curve(group, n, a, 0, ctx)) {
+	    err = 0;
+	    goto err;
+    }
+
+    memset (rmisec_a, 0, sizeof(rmisec_a));
+    BN_bn2bin(a, rmisec_a);
+    memset (rmisec_n, 0, sizeof(rmisec_n));
+    BN_bn2bin(n, rmisec_n);
+
+    c = &group->con2k;
+    if (!BN_num_bits(&group->con2k)) {
+	    /* build const */
+	    c = con2k = BN_CTX_get(ctx);
+	    if (rmisec_calc_modexp_constant (n, con2k, ctx) == 0) {
+		    RMISECerr(RMISEC_F_RMISEC_MOD_EXP,
+			      RMISEC_R_CONST_CALC_FAILURE);
+		    err = 0;
+		    goto err;
+	    }
+    }
+
+    memset (rmisec_const, 0, sizeof(rmisec_const));
+    BN_bn2bin(c, rmisec_const);
+
+
+    /* build (x1, y1) */
+    group->meth->point_get_affine_coordinates(group, point1, x1, y1, ctx);
+    memset (rmisec_x1, 0, sizeof(rmisec_x1));
+    BN_bn2bin(x1, rmisec_x1);
+    memset (rmisec_y1, 0, sizeof(rmisec_y1));
+    BN_bn2bin(y1, rmisec_y1);
+
+    /* build (x2, y2) */
+    group->meth->point_get_affine_coordinates(group, point2, x2, y2, ctx);
+    memset (rmisec_x2, 0, sizeof(rmisec_x2));
+    BN_bn2bin(x2, rmisec_x2);
+    memset (rmisec_y2, 0, sizeof(rmisec_y2));
+    BN_bn2bin(y2, rmisec_y2);
+
+    /* hw computes (r_x, r_y) = (x1, y1) + (x2, y2) mod n, with y^2 = x^3 + a*x + b */
+    if((err = p_RMISEC_op_init(RMISEC_GLOBAL_FD, &handle))) {
+	    err = 0;
+	    goto err;
+    }
+
+    err = p_RMISEC_ecc_gfp_add (handle, deg,
+				rmisec_x1, BN_num_bits(x1),
+				rmisec_y1, BN_num_bits(y1),
+				rmisec_x2, BN_num_bits(x2),
+				rmisec_y2, BN_num_bits(y2),
+				rmisec_a, BN_num_bits(a),
+				rmisec_n, BN_num_bits(n),
+				rmisec_const, BN_num_bits(c),
+				rmisec_s_x, &s_x_len,
+				rmisec_s_y, &s_y_len);
+
+    p_RMISEC_op_cleanup(&handle);
+    if(!IS_SUCCESS_SAEOP(err)) {
+ 	    fprintf(stderr, "%s:%d err %d\n", __FUNCTION__, __LINE__, err);
+	    RMISECerr(RMISEC_F_RMISEC_ECC_ADD, RMISEC_R_REQUEST_FAILED);
+	    err = 0;
+	    goto err;
+    }
+
+    s_x = BN_CTX_get(ctx);
+    s_y = BN_CTX_get(ctx);
+    if (!BN_bin2bn(rmisec_s_x, CEIL(s_x_len, 3), s_x) ||
+        !BN_bin2bn(rmisec_s_y, CEIL(s_y_len, 3), s_y)) {
+        DBG_PRINT("Result BN_bin2bn !FAILED! \n");
+	err = 0;
+        goto err;
+    }
+    if (BN_is_zero(s_x) && BN_is_zero(s_y)) {
+        if (!EC_POINT_set_to_infinity(group, r)) {
+		err = 0;
+		goto err;
+	}
+    }
+    else if (!group->meth->point_set_affine_coordinates(group, r, s_x, s_y, ctx)) {
+	    fprintf(stderr, "%s:%d err %d\n", __FUNCTION__, __LINE__, err);
+	    RMISECerr(RMISEC_F_RMISEC_ECC_ADD,
+		      RMISEC_R_REQUEST_FAILED);
+	    err = 0;
+	    goto err;
+    }
+err:
+    BN_CTX_end(ctx);
+    return err;
+}
+
+static int rmisec_ec_gfp_dbl(const EC_GROUP *group, EC_POINT *r,
+			     const EC_POINT *point, BN_CTX *ctx) {
+    op_handle_t handle = RMISAE_HANDLE_INITIALIZER;
+    BIGNUM *a = NULL, *n = NULL, *x = NULL, *con2k = NULL,
+	    *y = NULL, *s_x = NULL, *s_y = NULL;
+    const BIGNUM *c;
+
+    int err = 1;
+    unsigned char rmisec_x[256],
+                  rmisec_y[256],
+                  rmisec_a[256],
+                  rmisec_n[256],
+                  rmisec_const[256],
+                  rmisec_s_x[256],
+                  rmisec_s_y[256];
+    int s_x_len, s_y_len;
+    int degree;
+    ECC_Mode_t deg;
+
+#ifdef SAE_BYPASS
+    if(err) {
+	    return ec_GFp_simple_dbl(group, r, point, ctx);
+    }
+#endif /* SAE_BYPASS */
+
+    degree = group->meth->group_get_degree(group);
+    deg = get_gfp_degree(degree);
+
+    if (RMISEC_GLOBAL_FD < 0 || p_RMISEC_ecc_gfp_dbl == NULL ||
+	deg == -1) {
+        return ec_GFp_simple_dbl(group, r, point, ctx);
+    }
+
+    /*
+     *  2) Point addition             R(x_r, y_r) = P(x_p, y_p) + Q(x_q, y_q)
+     *
+     *                 DATA IN                 DATA OUT
+     *                 =======                 ========
+     * src+glb_off->   x_p      dst+glb_off->  x_r
+     *                 y_p                     y_r
+     *                 x_q                     2x(3/4/6/8)=
+     *                 y_q                     6/8/12/16 dw
+     *                 a
+     *                 m
+     *                 cst
+     *                 7x(3/4/6/8)=
+     *                 21/28/42/56 dw */
+    BN_CTX_start(ctx);
+
+    /* build a and n */
+    x = BN_CTX_get(ctx);
+    y = BN_CTX_get(ctx);
+    a = BN_CTX_get(ctx);
+    n = BN_CTX_get(ctx);
+    if (!group->meth->group_get_curve(group, n, a, 0, ctx)) {
+	    fprintf(stderr, "%s:%d aborted\n", __FUNCTION__, __LINE__);
+	    err = 0;
+	    goto err;
+    }
+    memset (rmisec_a, 0, sizeof(rmisec_a));
+    BN_bn2bin(a, rmisec_a);
+    memset (rmisec_n, 0, sizeof(rmisec_n));
+    BN_bn2bin(n, rmisec_n);
+
+    c = &group->con2k;
+    if (!BN_num_bits(&group->con2k)) {
+	    /* build const */
+	    c = con2k = BN_CTX_get(ctx);
+	    if (rmisec_calc_modexp_constant (n, con2k, ctx) == 0) {
+		    RMISECerr(RMISEC_F_RMISEC_MOD_EXP,
+			      RMISEC_R_CONST_CALC_FAILURE);
+		    fprintf(stderr, "%s:%d aborted\n", __FUNCTION__, __LINE__);
+		    err = 0;
+		    goto err;
+	    }
+    }
+
+    memset(rmisec_const, 0, sizeof(rmisec_const));
+    BN_bn2bin(c, rmisec_const);
+
+    /* build (x, y) */
+    group->meth->point_get_affine_coordinates(group, point, x, y, ctx);
+    memset (rmisec_x, 0, sizeof(rmisec_x));
+    BN_bn2bin(x, rmisec_x);
+    memset (rmisec_y, 0, sizeof(rmisec_y));
+    BN_bn2bin(y, rmisec_y);
+
+    /* hw computes (r_x, r_y) = (x, y) + (x, y) mod n, with y^2 = x^3 + a*x + b */
+    if((err = p_RMISEC_op_init(RMISEC_GLOBAL_FD, &handle))) {
+	    fprintf(stderr, "%s:%d aborted\n", __FUNCTION__, __LINE__);
+	    err = 0;
+	    goto err;
+    }
+
+    err = p_RMISEC_ecc_gfp_dbl (handle, deg,
+                           rmisec_x, BN_num_bits(x),
+                           rmisec_y, BN_num_bits(y),
+                           rmisec_a, BN_num_bits(a),
+                           rmisec_n, BN_num_bits(n),
+                           rmisec_const, BN_num_bits(c),
+                           rmisec_s_x, &s_x_len,
+                           rmisec_s_y, &s_y_len);
+    p_RMISEC_op_cleanup(&handle);
+    if(!IS_SUCCESS_SAEOP(err)) {
+	    fprintf(stderr, "%s:%d err %d\n", __FUNCTION__, __LINE__, err);
+	    RMISECerr(RMISEC_F_RMISEC_ECC_DBL,
+		      RMISEC_R_REQUEST_FAILED);
+	    err = 0;
+	    goto err;
+    }
+
+    s_x = BN_CTX_get(ctx);
+    s_y = BN_CTX_get(ctx);
+    if (!BN_bin2bn(rmisec_s_x, CEIL(s_x_len, 3), s_x) ||
+        !BN_bin2bn(rmisec_s_y, CEIL(s_y_len, 3), s_y)) {
+	    DBG_PRINT("Result BN_bin2bn !FAILED! \n");
+		fprintf(stderr, "%s:%d aborted\n", __FUNCTION__, __LINE__);
+		err = 0;
+		goto err;
+    }
+    if (BN_is_zero(s_x) && BN_is_zero(s_y)) {
+        if (!EC_POINT_set_to_infinity(group, r)) goto err;
+    }
+    else if (!group->meth->point_set_affine_coordinates(group, r, s_x, s_y, ctx)) {
+	    fprintf(stderr, "%s:%d err %d\n", __FUNCTION__, __LINE__, err);
+	    RMISECerr(RMISEC_F_RMISEC_ECC_DBL,
+		      RMISEC_R_REQUEST_FAILED);
+	    err = 0;
+	    goto err;
+    }
+
+err:
+    BN_CTX_end(ctx);
+    return err;
+}
+
+static int rmisec_ec_gfp_is_on_curve(const EC_GROUP *group, const EC_POINT *point, BN_CTX *ctx) {
+    op_handle_t handle = RMISAE_HANDLE_INITIALIZER;
+    BIGNUM *a, *b, *n, *x, *y, *con2k;
+    const BIGNUM *c;
+    int err = 1;
+    int result = 0;
+    unsigned char rmisec_x[256],
+                  rmisec_y[256],
+                  rmisec_a[256],
+                  rmisec_b[256],
+                  rmisec_n[256],
+                  rmisec_const[256];
+    int degree;
+    ECC_Mode_t deg;
+
+    degree = group->meth->group_get_degree(group);
+    deg = get_gfp_degree(degree);
+    if (RMISEC_GLOBAL_FD < 0 || p_RMISEC_ecc_gfp_vfy == NULL || deg == -1)
+	    return ec_GFp_simple_is_on_curve(group, point, ctx);
+
+    /*
+     *  4) Point verification         Is_On_Curve = P(x_p, y_p) on curve ? 1 : 0
+     *
+     *                 DATA IN                 DATA OUT
+     *                 =======                 ========
+     * src+glb_off->   x_p      dst+glb_off->  Is_On_Curve
+     *                 y_p                     1 dw
+     *                 a
+     *                 b
+     *                 m
+     *                 cst
+     *                 6x(3/4/6/8)=
+     *                 18/24/36/48 dw
+     */
+    BN_CTX_start(ctx);
+
+    /* build a, b and n */
+    a = BN_CTX_get(ctx);
+    b = BN_CTX_get(ctx);
+    n = BN_CTX_get(ctx);
+    if (!group->meth->group_get_curve(group, n, a, b, ctx)) {
+	    fprintf(stderr, "%s:%d aborted\n", __FUNCTION__, __LINE__);
+	    err = 0;
+	    goto err;
+    }
+
+    memset (rmisec_a, 0, sizeof(rmisec_a));
+    BN_bn2bin(a, rmisec_a);
+    memset (rmisec_b, 0, sizeof(rmisec_b));
+    BN_bn2bin(b, rmisec_b);
+    memset (rmisec_n, 0, sizeof(rmisec_n));
+    BN_bn2bin(n, rmisec_n);
+
+    c = &group->con2k;
+    if (!BN_num_bits(&group->con2k)) {
+	    /* build const */
+	    c = con2k = BN_CTX_get(ctx);
+	    if (rmisec_calc_modexp_constant (n, con2k, ctx) == 0) {
+		    RMISECerr(RMISEC_F_RMISEC_MOD_EXP,
+			      RMISEC_R_CONST_CALC_FAILURE);
+		    fprintf(stderr, "%s:%d aborted\n", __FUNCTION__, __LINE__);
+		    err = 0;
+		    goto err;
+	    }
+    }
+    memset (rmisec_const, 0, sizeof(rmisec_const));
+    BN_bn2bin(c, rmisec_const);
+
+    /* build (x, y) */
+    x = BN_CTX_get(ctx);
+    y = BN_CTX_get(ctx);
+    group->meth->point_get_affine_coordinates(group, point, x, y, ctx);
+    memset (rmisec_x, 0, sizeof(rmisec_x));
+    BN_bn2bin(x, rmisec_x);
+    memset (rmisec_y, 0, sizeof(rmisec_y));
+    BN_bn2bin(y, rmisec_y);
+
+    if((err = p_RMISEC_op_init(RMISEC_GLOBAL_FD, &handle))) {
+	    fprintf(stderr, "%s:%d aborted\n", __FUNCTION__, __LINE__);
+	    err = 0;
+	    goto err;
+    }
+
+    /* hw computes (r_x, r_y) = (x, y) + (x, y) mod n, with y^2 = x^3 + a*x + b */
+    err = p_RMISEC_ecc_gfp_vfy (handle, deg,
+				rmisec_x, BN_num_bits(x),
+				rmisec_y, BN_num_bits(y),
+				rmisec_a, BN_num_bits(a),
+				rmisec_b, BN_num_bits(b),
+				rmisec_n, BN_num_bits(n),
+				rmisec_const, BN_num_bits(c),
+				(unsigned int *)&result);
+    p_RMISEC_op_cleanup(&handle);
+
+    if(!IS_SUCCESS_SAEOP(err)) {
+	    fprintf(stderr, "%s:%d err %d\n", __FUNCTION__, __LINE__, err);
+	    RMISECerr(RMISEC_F_RMISEC_ECC_VFY,
+		      RMISEC_R_REQUEST_FAILED);
+	    err = 0;
+	    goto err;
+    }
+
+    /* no failures, so the return value is, if on curve or not */
+    err = result;
+err:
+    BN_CTX_end(ctx);
+    return err;
+}
+
+static int rmisec_ec_gfp_mul(const EC_GROUP *group, EC_POINT *r, const BIGNUM *scalar,
+                size_t num, const EC_POINT *points[], const BIGNUM *scalars[], BN_CTX *ctx) {
+    int i;
+    const EC_POINT *generator;
+    BIGNUM *a, *n, *x, *y, *s_x, *s_y, *con2k;
+    const BIGNUM *c;
+    int err;
+    unsigned char rmisec_x[256],
+                  rmisec_y[256],
+                  rmisec_a[256],
+                  rmisec_k[256],
+                  rmisec_n[256],
+                  rmisec_const[256],
+                  rmisec_r_x[256],
+                  rmisec_r_y[256],
+                  rmisec_s_x[256],
+                  rmisec_s_y[256];
+    int r_x_len, r_y_len, s_x_len, s_y_len;
+    int first_sum, degree;
+    ECC_Mode_t deg;
+    op_handle_t handle = RMISAE_HANDLE_INITIALIZER;
+
+    degree = group->meth->group_get_degree(group);
+    deg = get_gfp_degree(degree);
+
+    if (RMISEC_GLOBAL_FD < 0 || p_RMISEC_ecc_gfp_mul == NULL ||
+        p_RMISEC_ecc_gfp_add == NULL ||
+        p_RMISEC_ecc_gfp_dbl == NULL ||
+	deg == -1) {
+        return ec_wNAF_mul(group, r, scalar, num, points, scalars, ctx);
+    }
+
+    /*
+     * Point multiplication       R(x_r, y_r) = k . P(x_p, y_p)
+     *
+     *                 DATA IN                 DATA OUT
+     *                 =======                 ========
+     * src+glb_off->   x_p      dst+glb_off->  x_r
+     *                 x_p                     y_r
+     *                 y_p                     2x(3/4/6/8)=
+     *                 y_p                     6/8/12/16 dw
+     *                 A
+     *                 k
+     *                 n
+     *                 cst
+     *                 7x(3/4/6/8)+(4/4/8/8)=
+     *                 25/32/50/64 dw */
+    BN_CTX_start(ctx);
+ 
+    /* build a and n */
+    a = BN_CTX_get(ctx);
+    n = BN_CTX_get(ctx);
+    if (!group->meth->group_get_curve(group, n, a, 0, ctx)) goto err;
+    memset (rmisec_a, 0, sizeof(rmisec_a));
+    BN_bn2bin(a, rmisec_a);
+    memset (rmisec_n, 0, sizeof(rmisec_n));
+    BN_bn2bin(n, rmisec_n);
+
+    c = &group->con2k;
+    if (!BN_num_bits(&group->con2k)) {
+        /* build const */
+	    c = con2k = BN_CTX_get(ctx);
+	    if (rmisec_calc_modexp_constant (n, con2k, ctx) == 0) {
+		    RMISECerr(RMISEC_F_RMISEC_MOD_EXP,
+			      RMISEC_R_CONST_CALC_FAILURE);
+		    goto err;
+	    }
+    }
+
+    memset (rmisec_const, 0, sizeof(rmisec_const));
+    BN_bn2bin(c, rmisec_const);
+
+    /* build point */
+    generator = EC_GROUP_get0_generator(group);
+    x = BN_CTX_get(ctx);
+    y = BN_CTX_get(ctx);
+    s_x = BN_CTX_get(ctx);
+    s_y = BN_CTX_get(ctx);
+
+    first_sum = 0;
+
+    for (i=0;i<num+1;i++) {
+
+        if (!(i == 0 ? scalar : scalars[i-1])) continue;
+
+        /* build (x, y) */
+        group->meth->point_get_affine_coordinates(group,
+						  i == 0 ? generator : points[i-1],
+						  x, y, ctx);
+        memset (rmisec_x, 0, sizeof(rmisec_x));
+        BN_bn2bin(x, rmisec_x);
+        memset (rmisec_y, 0, sizeof(rmisec_y));
+        BN_bn2bin(y, rmisec_y);
+
+        /* build k */
+        memset (rmisec_k, 0, sizeof(rmisec_k));
+        BN_bn2bin(i == 0 ? scalar : scalars[i-1], rmisec_k);
+
+	if((err = p_RMISEC_op_init(RMISEC_GLOBAL_FD, &handle))) {
+		fprintf(stderr, "%s:%d err=%d\n", __FUNCTION__, __LINE__, err);
+		err = 0;
+		goto err;
+	}
+
+        /* hw computes (r_x, r_y) = k * (x, y) mod n, with y^2 = x^3 + a*x + b */
+        if (!first_sum) {
+            if ((err = p_RMISEC_ecc_gfp_mul (handle, deg,
+                               rmisec_x, BN_num_bits(x),
+                               rmisec_y, BN_num_bits(y),
+                               rmisec_a, BN_num_bits(a),
+                               rmisec_k, BN_num_bits(i == 0 ? scalar : scalars[i-1]),
+                               rmisec_n, BN_num_bits(n),
+                               rmisec_const, BN_num_bits(c),
+                               rmisec_s_x, &s_x_len,
+                               rmisec_s_y, &s_y_len)) != RMISAE_SUCCESS) {
+                printf("err %d\n",err);
+		p_RMISEC_op_cleanup(&handle);
+                RMISECerr(RMISEC_F_RMISEC_ECC_MUL,
+                          RMISEC_R_REQUEST_FAILED);
+                goto err;
+            }
+            first_sum = 1;
+        }
+        else {
+            if ((err = p_RMISEC_ecc_gfp_mul (handle, deg,
+                               rmisec_x, BN_num_bits(x),
+                               rmisec_y, BN_num_bits(y),
+                               rmisec_a, BN_num_bits(a),
+                               rmisec_k, BN_num_bits(i == 0 ? scalar : scalars[i-1]),
+                               rmisec_n, BN_num_bits(n),
+                               rmisec_const, BN_num_bits(c),
+                               rmisec_r_x, &r_x_len,
+                               rmisec_r_y, &r_y_len)) != RMISAE_SUCCESS) {
+                fprintf(stderr, "%s:%d err %d\n", __FUNCTION__, __LINE__, err);
+		p_RMISEC_op_cleanup(&handle);
+                RMISECerr(RMISEC_F_RMISEC_ECC_MUL,
+                          RMISEC_R_REQUEST_FAILED);
+                goto err;
+            }
+	    p_RMISEC_op_cleanup(&handle);
+
+	    if((err = p_RMISEC_op_init(RMISEC_GLOBAL_FD, &handle))) {
+		    fprintf(stderr, "%s:%d err=%d\n", __FUNCTION__, __LINE__, err);
+		    err = 0;
+		    goto err;
+	    }
+
+            if ((s_x_len == r_x_len && !memcmp(rmisec_s_x,rmisec_r_x, CEIL(s_x_len, 3))) &&
+                (s_y_len == r_y_len && !memcmp(rmisec_s_y,rmisec_r_y, CEIL(s_y_len, 3)))) {
+		    if ((err = p_RMISEC_ecc_gfp_dbl (handle, deg,
+                                       rmisec_s_x, s_x_len,
+                                       rmisec_s_y, s_y_len,
+                                       rmisec_a, BN_num_bits(a),
+                                       rmisec_n, BN_num_bits(n),
+                                       rmisec_const, BN_num_bits(c),
+                                       rmisec_s_x, &s_x_len,
+                                       rmisec_s_y, &s_y_len)) != RMISAE_SUCCESS) {
+                    fprintf(stderr, "%s:%d err %d\n", __FUNCTION__, __LINE__, err);
+		p_RMISEC_op_cleanup(&handle);
+                    RMISECerr(RMISEC_F_RMISEC_ECC_MUL,
+                              RMISEC_R_REQUEST_FAILED);
+                    goto err;
+                }
+            }
+            else {
+                if ((err = p_RMISEC_ecc_gfp_add (handle, deg,
+                                       rmisec_s_x, s_x_len,
+                                       rmisec_s_y, s_y_len,
+                                       rmisec_r_x, r_x_len,
+                                       rmisec_r_y, r_y_len,
+                                       rmisec_a, BN_num_bits(a),
+                                       rmisec_n, BN_num_bits(n),
+                                       rmisec_const, BN_num_bits(c),
+                                       rmisec_s_x, &s_x_len,
+                                       rmisec_s_y, &s_y_len)) != RMISAE_SUCCESS) {
+                    fprintf(stderr, "%s:%d err %d\n", __FUNCTION__, __LINE__, err);
+		p_RMISEC_op_cleanup(&handle);
+                    RMISECerr(RMISEC_F_RMISEC_ECC_MUL,
+                              RMISEC_R_REQUEST_FAILED);
+                    goto err;
+                }
+            }
+        }
+	p_RMISEC_op_cleanup(&handle);
+    }
+
+    if (!BN_bin2bn(rmisec_s_x, CEIL(s_x_len, 3), s_x) ||
+        !BN_bin2bn(rmisec_s_y, CEIL(s_y_len, 3), s_y)) {
+        DBG_PRINT("Result BN_bin2bn !FAILED! \n");
+        goto err;
+    }
+    if (BN_is_zero(s_x) && BN_is_zero(s_y)) {
+        if (!EC_POINT_set_to_infinity(group, r)) goto err;
+    }
+    else if (!group->meth->point_set_affine_coordinates(group, r, s_x, s_y, ctx)) {
+        RMISECerr(RMISEC_F_RMISEC_ECC_MUL,
+                  RMISEC_R_REQUEST_FAILED);
+        goto err;
+    }
+err:
+    BN_CTX_end(ctx);
+    return 1;
+}
+
+static int rmisec_ec_gfp_field_mul(const EC_GROUP *group, BIGNUM *r, const BIGNUM *a, const BIGNUM *b, BN_CTX *ctx) {
+    unsigned char rmisec_a[256],
+                  rmisec_b[256],
+                  rmisec_n[256],
+                  rmisec_const[256],
+                  rmisec_r[256];
+    int a_len, b_len, n_len, r_len;
+    op_handle_t handle = RMISAE_HANDLE_INITIALIZER;
+    int degree;
+    int err = 1;
+    ECC_Mode_t deg;
+    BIGNUM *n, *con2k = NULL;
+    const BIGNUM *c;
+
+#ifdef SAE_BYPASS
+    if(err) {
+	    return ec_GFp_simple_field_mul(group,r,a,b,ctx);
+    }
+#endif /* SAE_BYPASS */
+
+    degree = group->meth->group_get_degree(group);
+    deg = get_gfp_degree(degree);
+
+    if (RMISEC_GLOBAL_FD < 0 || p_RMISEC_ecc_gfp_field_mul == NULL || deg == -1)
+	    return ec_GFp_simple_field_mul(group,r,a,b,ctx);
+
+    BN_CTX_start(ctx);
+    memset (rmisec_a, 0, sizeof(rmisec_a));
+    BN_bn2bin(a, rmisec_a);
+    a_len = BN_num_bits(a);
+    memset (rmisec_b, 0, sizeof(rmisec_b));
+    BN_bn2bin(b, rmisec_b);
+    b_len = BN_num_bits(b);
+    memset (rmisec_n, 0, sizeof(rmisec_n));
+    n = BN_CTX_get(ctx);
+    BN_copy(n, &group->order);
+    BN_bn2bin(n, rmisec_n);
+    n_len = BN_num_bits(n);
+
+    c = &group->con2k;
+    if (!BN_num_bits(&group->con2k)) {
+        /* build const */
+	    c = con2k = BN_CTX_get(ctx);
+	    if (rmisec_calc_modexp_constant (n, con2k, ctx) == 0) {
+		    fprintf(stderr, "%s:%d aborted\n", __FUNCTION__, __LINE__);
+		    RMISECerr(RMISEC_F_RMISEC_MOD_EXP,
+			      RMISEC_R_CONST_CALC_FAILURE);
+		    err = 0;
+		    goto err;
+	    }
+    }
+    memset (rmisec_const, 0, sizeof(rmisec_const));
+    BN_bn2bin(c, rmisec_const);
+
+    if((err = p_RMISEC_op_init(RMISEC_GLOBAL_FD, &handle))) {
+	    fprintf(stderr, "%s:%d aborted\n", __FUNCTION__, __LINE__);
+	    err = 0;
+	    goto err;
+    }
+
+    if ((err = p_RMISEC_ecc_gfp_field_mul (handle, deg,
+					   rmisec_a, a_len,
+					   rmisec_b, b_len,
+					   rmisec_n, n_len,
+					   rmisec_const,
+					   BN_num_bits(c),
+					   rmisec_r, &r_len)) != RMISAE_SUCCESS) {
+	    fprintf(stderr, "%s:%d err %d\n", __FUNCTION__, __LINE__, err);
+	    RMISECerr(RMISEC_F_RMISEC_ECC_FIELD_MUL,
+		      RMISEC_R_REQUEST_FAILED);
+	    err = 0;
+	    goto err;
+    }
+
+    if (!BN_bin2bn(rmisec_r, CEIL(r_len, 3), r)) {
+	    fprintf(stderr, "%s:%d aborted\n", __FUNCTION__, __LINE__);
+	    DBG_PRINT("Result BN_bin2bn !FAILED! \n");
+	    err = 0;
+	    goto err;
+    }
+err:
+    p_RMISEC_op_cleanup(&handle);
+    BN_CTX_end(ctx);
+    return err;
+}
+
+static int rmisec_ec_gfp_field_inv(const EC_GROUP *group, BIGNUM *r,
+				   const BIGNUM *a, BN_CTX *ctx)
+{
+    unsigned char rmisec_a[256],
+                  rmisec_n[256],
+                  rmisec_r[256];
+    int a_len, n_len, r_len;
+    op_handle_t handle = RMISAE_HANDLE_INITIALIZER;
+    int degree;
+    ECC_Mode_t deg;
+    int err = 1;
+    BIGNUM *n;
+
+#ifdef SAE_BYPASS
+    if(err) {
+	    return (BN_mod_inverse(r, a, &group->order, ctx) != NULL);
+    }
+#endif /* SAE_BYPASS */
+
+    degree = group->meth->group_get_degree(group);
+    deg = get_gfp_degree(degree);
+
+    if (RMISEC_GLOBAL_FD < 0 || p_RMISEC_ecc_gfp_field_inv == NULL || deg == -1)
+        return (BN_mod_inverse(r, a, &group->order, ctx) != NULL);
+
+    BN_CTX_start(ctx);
+    memset (rmisec_a, 0, sizeof(rmisec_a));
+    BN_bn2bin(a, rmisec_a);
+    a_len = BN_num_bits(a);
+    memset (rmisec_n, 0, sizeof(rmisec_n));
+    n = BN_CTX_get(ctx);
+    BN_copy(n, &group->order);
+    BN_bn2bin(n, rmisec_n);
+    n_len = BN_num_bits(n);
+
+    if((err = p_RMISEC_op_init(RMISEC_GLOBAL_FD, &handle))) {
+	    fprintf(stderr, "%s:%d aborted\n", __FUNCTION__, __LINE__);
+	    err = 0;
+	    goto err;
+    }
+
+    if ((err = p_RMISEC_ecc_gfp_field_inv ( handle, deg,
+                           rmisec_a, a_len,
+                           rmisec_n, n_len,
+                           rmisec_r, &r_len)) != RMISAE_SUCCESS) {
+	    fprintf(stderr, "%s:%d err %d\n", __FUNCTION__, __LINE__, err);
+	    RMISECerr(RMISEC_F_RMISEC_ECC_FIELD_INV,
+		      RMISEC_R_REQUEST_FAILED);
+	    err = 0;
+	    goto err;
+    }
+
+    if (!BN_bin2bn(rmisec_r, CEIL(r_len, 3), r)) {
+	    DBG_PRINT("Result BN_bin2bn !FAILED! \n");
+	    fprintf(stderr, "%s:%d aborted\n", __FUNCTION__, __LINE__);
+	    err = 0;
+	    goto err;
+    }
+err:
+    p_RMISEC_op_cleanup(&handle);
+    BN_CTX_end(ctx);
+    return err;
+}
+
+static int rmisec_ec_gfp_field_sqr(const EC_GROUP *group, BIGNUM *r,
+				   const BIGNUM *a, BN_CTX *ctx) {
+    unsigned char rmisec_a[256],
+                  rmisec_n[256],
+                  rmisec_const[256],
+                  rmisec_r[256];
+    int a_len, n_len, r_len;
+    op_handle_t handle = RMISAE_HANDLE_INITIALIZER;
+    int degree;
+    ECC_Mode_t deg;
+    int err = 1;
+    BIGNUM *n = 0, *con2k;
+    const BIGNUM *c;
+
+#ifdef SAE_BYPASS
+    if(err) {
+        return ec_GFp_simple_field_sqr(group,r,a,ctx);
+    }
+#endif /* SAE_BYPASS */
+
+    degree = group->meth->group_get_degree(group);
+    deg = get_gfp_degree(degree);
+
+    if (RMISEC_GLOBAL_FD < 0 || p_RMISEC_ecc_gfp_field_mul == NULL || deg == -1)
+        return ec_GFp_simple_field_sqr(group,r,a,ctx);
+
+    BN_CTX_start(ctx);
+    memset (rmisec_a, 0, sizeof(rmisec_a));
+    BN_bn2bin(a, rmisec_a);
+    a_len = BN_num_bits(a);
+    memset (rmisec_n, 0, sizeof(rmisec_n));
+    n = BN_CTX_get(ctx);
+    BN_copy(n, &group->order);
+    BN_bn2bin(n, rmisec_n);
+    n_len = BN_num_bits(n);
+
+    c = &group->con2k;
+    if (!BN_num_bits(&group->con2k)) {
+        /* build const */
+	    c = con2k = BN_CTX_get(ctx);
+	    if (rmisec_calc_modexp_constant (n, con2k, ctx) == 0) {
+		    RMISECerr(RMISEC_F_RMISEC_MOD_EXP,
+			      RMISEC_R_CONST_CALC_FAILURE);
+		    fprintf(stderr, "%s:%d aborted\n", __FUNCTION__, __LINE__);
+		    err = 0;
+		    goto err;
+	    }
+    }
+    memset (rmisec_const, 0, sizeof(rmisec_const));
+    BN_bn2bin(c, rmisec_const);
+
+    if((err = p_RMISEC_op_init(RMISEC_GLOBAL_FD, &handle))) {
+	    fprintf(stderr, "%s:%d aborted\n", __FUNCTION__, __LINE__);
+	    err = 0;
+	    goto err;
+    }
+
+    if ((err = p_RMISEC_ecc_gfp_field_mul (handle, deg,
+					   rmisec_a, a_len,
+					   rmisec_a, a_len,
+					   rmisec_n, n_len,
+					   rmisec_const,
+					   BN_num_bits(c),
+					   rmisec_r, &r_len)) != RMISAE_SUCCESS) {
+	    fprintf(stderr, "%s:%d err %d\n", __FUNCTION__, __LINE__, err);
+	    RMISECerr(RMISEC_F_RMISEC_ECC_FIELD_MUL,
+		      RMISEC_R_REQUEST_FAILED);
+	    err = 0;
+	    goto err;
+    }
+
+    if (!BN_bin2bn(rmisec_r, CEIL(r_len, 3), r)) {
+        DBG_PRINT("Result BN_bin2bn !FAILED! \n");
+        goto err;
+    }
+err:
+    p_RMISEC_op_cleanup(&handle);
+    BN_CTX_end(ctx);
+    return err;
+}
+
+static int rmisec_ec_gfp_field_div(const EC_GROUP *group, BIGNUM *r,
+				   const BIGNUM *a, const BIGNUM *b, BN_CTX *ctx) {
+    unsigned char rmisec_a[256],
+                  rmisec_b[256],
+                  rmisec_n[256],
+                  rmisec_r[256];
+    int a_len, b_len, n_len, r_len;
+    op_handle_t handle = RMISAE_HANDLE_INITIALIZER;
+    int degree;
+    ECC_Mode_t deg;
+    int err = 1;
+    BIGNUM *n;
+
+#ifdef SAE_BYPASS
+    if(err) {
+	    return BN_mod_mul(r, a, b, &group->order, ctx);
+    }
+#endif /* SAE_BYPASS */
+
+    degree = group->meth->group_get_degree(group);
+    deg = get_gfp_degree(degree);
+
+    if (RMISEC_GLOBAL_FD < 0 || p_RMISEC_ecc_gfp_field_mul == NULL || deg == -1)
+        return BN_mod_mul(r, a, b, &group->order, ctx);
+
+    BN_CTX_start(ctx);
+    memset (rmisec_a, 0, sizeof(rmisec_a));
+    BN_bn2bin(a, rmisec_a);
+    a_len = BN_num_bits(a);
+    memset (rmisec_b, 0, sizeof(rmisec_b));
+    BN_bn2bin(b, rmisec_b);
+    b_len = BN_num_bits(b);
+    memset (rmisec_n, 0, sizeof(rmisec_n));
+    n = BN_CTX_get(ctx);
+    BN_copy(n, &group->order);
+    BN_bn2bin(n, rmisec_n);
+    n_len = BN_num_bits(n);
+
+    if((err = p_RMISEC_op_init(RMISEC_GLOBAL_FD, &handle))) {
+	    fprintf(stderr, "%s:%d aborted\n", __FUNCTION__, __LINE__);
+	    err = 0;
+	    goto err;
+    }
+
+    if ((err = p_RMISEC_ecc_gfp_field_div (handle, deg,
+                           rmisec_a, a_len,
+                           rmisec_b, b_len,
+                           rmisec_n, n_len,
+                           rmisec_r, &r_len)) != RMISAE_SUCCESS) {
+	    fprintf(stderr, "%s:%d err %d\n", __FUNCTION__, __LINE__, err);
+	    RMISECerr(RMISEC_F_RMISEC_ECC_FIELD_DIV,
+		      RMISEC_R_REQUEST_FAILED);
+	    err = 0;
+	    goto err;
+    }
+
+    if (!BN_bin2bn(rmisec_r, CEIL(r_len, 3), r)) {
+	    DBG_PRINT("Result BN_bin2bn !FAILED! \n");
+	    fprintf(stderr, "%s:%d aborted\n", __FUNCTION__, __LINE__);
+	    err = 0;
+	    goto err;
+    }
+err:
+    p_RMISEC_op_cleanup(&handle);
+    BN_CTX_end(ctx);
+    return err;
+}
+
+static int rmisec_ec_gfp_field_red(const EC_GROUP *group, BIGNUM *r,
+				   const BIGNUM *a, BN_CTX *ctx) {
+    unsigned char rmisec_a[256],
+                  rmisec_n[256],
+                  rmisec_r[256];
+    int a_len, n_len, r_len;
+    op_handle_t handle = RMISAE_HANDLE_INITIALIZER;
+    int degree;
+    ECC_Mode_t deg;
+    int err = 1;
+    BIGNUM *n;
+
+#ifdef SAE_BYPASS
+    if(err) {
+	    return BN_nnmod(r, a, &group->order, ctx);
+    }
+#endif /* SAE_BYPASS */
+
+    degree = group->meth->group_get_degree(group);
+    deg = get_gfp_degree(degree);
+
+    if (RMISEC_GLOBAL_FD < 0 || p_RMISEC_ecc_gfp_field_mul == NULL || deg == -1)
+        return BN_nnmod(r, a, &group->order, ctx);
+
+    BN_CTX_start(ctx);
+    memset (rmisec_a, 0, sizeof(rmisec_a));
+    BN_bn2bin(a, rmisec_a);
+    a_len = BN_num_bits(a);
+    memset (rmisec_n, 0, sizeof(rmisec_n));
+    n = BN_CTX_get(ctx);
+    BN_copy(n, &group->order);
+    BN_bn2bin(n, rmisec_n);
+    n_len = BN_num_bits(n);
+
+    if((err = p_RMISEC_op_init(RMISEC_GLOBAL_FD, &handle))) {
+	    fprintf(stderr, "%s:%d aborted\n", __FUNCTION__, __LINE__);
+	    err = 0;
+	    goto err;
+    }
+
+    if ((err = p_RMISEC_ecc_gfp_field_red ( handle, deg,
+                           rmisec_a, a_len,
+                           rmisec_n, n_len,
+                           rmisec_r, &r_len)) != RMISAE_SUCCESS) {
+	    fprintf(stderr, "%s:%d err %d\n", __FUNCTION__, __LINE__, err);
+	    RMISECerr(RMISEC_F_RMISEC_ECC_FIELD_RED,
+		      RMISEC_R_REQUEST_FAILED);
+	    err = 0;
+	    goto err;
+    }
+
+    if (!BN_bin2bn(rmisec_r, CEIL(r_len, 3), r)) {
+	    DBG_PRINT("Result BN_bin2bn !FAILED! \n");
+	    fprintf(stderr, "%s:%d aborted\n", __FUNCTION__, __LINE__);
+	    err = 0;
+	    goto err;
+    }
+err:
+    p_RMISEC_op_cleanup(&handle);
+    BN_CTX_end(ctx);
+    return err;
+}
+
+static int rmisec_ec_gfp_field_add(const EC_GROUP *group, BIGNUM *r,
+				   const BIGNUM *a, const BIGNUM *b, BN_CTX *ctx) {
+    unsigned char rmisec_a[256],
+                  rmisec_b[256],
+                  rmisec_n[256],
+                  rmisec_r[256];
+    int a_len, b_len, n_len, r_len;
+    op_handle_t handle = RMISAE_HANDLE_INITIALIZER;
+    int degree;
+    ECC_Mode_t deg;
+    int err = 1;
+    BIGNUM *n;
+
+#ifdef SAE_BYPASS
+    if(err) {
+	    return BN_mod_add(r, a, b, &group->order, ctx);
+    }
+#endif /* SAE_BYPASS */
+
+    degree = group->meth->group_get_degree(group);
+    deg = get_gfp_degree(degree);
+
+    if (RMISEC_GLOBAL_FD < 0 || p_RMISEC_ecc_gfp_field_mul == NULL || deg == -1)
+        return BN_mod_add(r, a, b, &group->order, ctx);
+
+    BN_CTX_start(ctx);
+    memset (rmisec_a, 0, sizeof(rmisec_a));
+    BN_bn2bin(a, rmisec_a);
+    a_len = BN_num_bits(a);
+    memset (rmisec_b, 0, sizeof(rmisec_b));
+    BN_bn2bin(b, rmisec_b);
+    b_len = BN_num_bits(b);
+    memset (rmisec_n, 0, sizeof(rmisec_n));
+    n = BN_CTX_get(ctx);
+    BN_copy(n, &group->order);
+    BN_bn2bin(n, rmisec_n);
+    n_len = BN_num_bits(n);
+
+    if((err = p_RMISEC_op_init(RMISEC_GLOBAL_FD, &handle))) {
+	    goto err;
+    }
+
+    if ((err = p_RMISEC_ecc_gfp_field_add (handle, deg,
+                           rmisec_a, a_len,
+                           rmisec_b, b_len,
+                           rmisec_n, n_len,
+                           rmisec_r, &r_len)) != RMISAE_SUCCESS) {
+	    fprintf(stderr, "%s:%d err %d\n", __FUNCTION__, __LINE__, err);
+	    RMISECerr(RMISEC_F_RMISEC_ECC_FIELD_ADD,
+		      RMISEC_R_REQUEST_FAILED);
+	    err = 0;
+	    goto err;
+    }
+
+    if (!BN_bin2bn(rmisec_r, CEIL(r_len, 3), r)) {
+	    DBG_PRINT("Result BN_bin2bn !FAILED! \n");
+	    fprintf(stderr, "%s:%d aborted\n", __FUNCTION__, __LINE__);
+	    err = 0;
+	    goto err;
+    }
+err:
+    p_RMISEC_op_cleanup(&handle);
+    BN_CTX_end(ctx);
+    return err;
+}
+static int rmisec_ec_gfp_field_sub(const EC_GROUP *group, BIGNUM *r,
+				   const BIGNUM *a, const BIGNUM *b, BN_CTX *ctx) {
+    unsigned char rmisec_a[256],
+                  rmisec_b[256],
+                  rmisec_n[256],
+                  rmisec_r[256];
+    int a_len, b_len, n_len, r_len;
+    op_handle_t handle = RMISAE_HANDLE_INITIALIZER;
+    int degree;
+    ECC_Mode_t deg;
+    int err = 1;
+    BIGNUM *n;
+
+#ifdef SAE_BYPASS
+    if(err) {
+	    return BN_mod_sub(r, a, b, &group->order, ctx);
+    }
+#endif /* SAE_BYPASS */
+
+    degree = group->meth->group_get_degree(group);
+    deg = get_gfp_degree(degree);
+
+    if (RMISEC_GLOBAL_FD < 0 || p_RMISEC_ecc_gfp_field_mul == NULL || deg == -1)
+        return BN_mod_sub(r, a, b, &group->order, ctx);
+
+    BN_CTX_start(ctx);
+    memset (rmisec_a, 0, sizeof(rmisec_a));
+    BN_bn2bin(a, rmisec_a);
+    a_len = BN_num_bits(a);
+    memset (rmisec_b, 0, sizeof(rmisec_b));
+    BN_bn2bin(b, rmisec_b);
+    b_len = BN_num_bits(b);
+    memset (rmisec_n, 0, sizeof(rmisec_n));
+    n = BN_CTX_get(ctx);
+    BN_copy(n, &group->order);
+    BN_bn2bin(n, rmisec_n);
+    n_len = BN_num_bits(n);
+
+    if((err = p_RMISEC_op_init(RMISEC_GLOBAL_FD, &handle))) {
+	    fprintf(stderr, "%s:%d aborted\n", __FUNCTION__, __LINE__);
+	    err = 0;
+	    goto err;
+    }
+
+    if ((err = p_RMISEC_ecc_gfp_field_sub (handle, deg,
+                           rmisec_a, a_len,
+                           rmisec_b, b_len,
+                           rmisec_n, n_len,
+                           rmisec_r, &r_len)) != RMISAE_SUCCESS) {
+	    fprintf(stderr, "%s:%d err %d\n", __FUNCTION__, __LINE__, err);
+	    RMISECerr(RMISEC_F_RMISEC_ECC_FIELD_SUB,
+		      RMISEC_R_REQUEST_FAILED);
+	    err = 0;
+	    goto err;
+    }
+
+    if (!BN_bin2bn(rmisec_r, CEIL(r_len, 3), r)) {
+	    DBG_PRINT("Result BN_bin2bn !FAILED! \n");
+	    fprintf(stderr, "%s:%d aborted\n", __FUNCTION__, __LINE__);
+	    err = 0;
+	    goto err;
+    }
+err:
+    p_RMISEC_op_cleanup(&handle);
+    BN_CTX_end(ctx);
+    return err;
+}
+
+static int rmisec_ec_gf2m_field_mul(const EC_GROUP *group, BIGNUM *r,
+				    const BIGNUM *a, const BIGNUM *b, BN_CTX *ctx) {
+    unsigned char rmisec_a[256],
+                  rmisec_b[256],
+                  rmisec_r[256];
+    int a_len, b_len, r_len;
+    op_handle_t handle = RMISAE_HANDLE_INITIALIZER;
+    int degree;
+    ECC_Mode_t deg;
+    int err = 1;
+
+    degree = group->meth->group_get_degree(group);
+    deg = get_gf2m_degree(degree);
+
+    if (RMISEC_GLOBAL_FD < 0 || p_RMISEC_ecc_gf2m_field_mul == NULL || deg == -1)
+        return ec_GF2m_simple_field_mul(group,r,a,b,ctx);
+
+    memset (rmisec_a, 0, sizeof(rmisec_a));
+    BN_bn2bin(a, rmisec_a);
+    a_len = BN_num_bits(a);
+    memset (rmisec_b, 0, sizeof(rmisec_b));
+    BN_bn2bin(b, rmisec_b);
+    b_len = BN_num_bits(b);
+
+    if((err = p_RMISEC_op_init(RMISEC_GLOBAL_FD, &handle))) {
+	    fprintf(stderr, "%s:%d aborted\n", __FUNCTION__, __LINE__);
+	    err = 0;
+	    goto err;
+    }
+
+    if ((err = p_RMISEC_ecc_gf2m_field_mul (handle, deg,
+                           rmisec_a, a_len,
+                           rmisec_b, b_len,
+                           rmisec_r, &r_len)) != RMISAE_SUCCESS) {
+	    fprintf(stderr, "%s:%d err %d\n", __FUNCTION__, __LINE__, err);
+	    RMISECerr(RMISEC_F_RMISEC_ECC_GF2M_FIELD_MUL,
+		      RMISEC_R_REQUEST_FAILED);
+	    err = 0;
+	    goto err;
+    }
+
+    if (!BN_bin2bn(rmisec_r, CEIL(r_len, 3), r)) {
+	    DBG_PRINT("Result BN_bin2bn !FAILED! \n");
+	    fprintf(stderr, "%s:%d aborted\n", __FUNCTION__, __LINE__);
+	    err = 0;
+	    goto err;
+    }
+err:
+    p_RMISEC_op_cleanup(&handle);
+    return err;
+}
+
+static int rmisec_ec_gf2m_field_sqr(const EC_GROUP *group, BIGNUM *r,
+				    const BIGNUM *a, BN_CTX *ctx) {
+    unsigned char rmisec_a[256],
+                  rmisec_r[256];
+    int a_len, r_len;
+    op_handle_t handle = RMISAE_HANDLE_INITIALIZER;
+    int degree;
+    ECC_Mode_t deg;
+    int err = 1;
+
+    degree = group->meth->group_get_degree(group);
+    deg = get_gf2m_degree(degree);
+
+    if (RMISEC_GLOBAL_FD < 0 || p_RMISEC_ecc_gf2m_field_mul == NULL || deg == -1)
+        return ec_GF2m_simple_field_sqr(group,r,a,ctx);
+
+    memset (rmisec_a, 0, sizeof(rmisec_a));
+    BN_bn2bin(a, rmisec_a);
+    a_len = BN_num_bits(a);
+
+    if((err = p_RMISEC_op_init(RMISEC_GLOBAL_FD, &handle))) {
+	    fprintf(stderr, "%s:%d aborted\n", __FUNCTION__, __LINE__);
+	    err = 0;
+	    goto err;
+    }
+
+    if ((err = p_RMISEC_ecc_gf2m_field_mul (handle, deg,
+                           rmisec_a, a_len,
+                           rmisec_a, a_len,
+                           rmisec_r, &r_len)) != RMISAE_SUCCESS) {
+	    fprintf(stderr, "%s:%d err %d\n", __FUNCTION__, __LINE__, err);
+	    RMISECerr(RMISEC_F_RMISEC_ECC_GF2M_FIELD_SQR,
+		      RMISEC_R_REQUEST_FAILED);
+	    err = 0;
+	    goto err;
+    }
+
+    if (!BN_bin2bn(rmisec_r, CEIL(r_len, 3), r)) {
+	    DBG_PRINT("Result BN_bin2bn !FAILED! \n");
+	    fprintf(stderr, "%s:%d aborted\n", __FUNCTION__, __LINE__);
+	    err = 0;
+	    goto err;
+    }
+err:
+    p_RMISEC_op_cleanup(&handle);
+    return err;
+}
+
+static int rmisec_ec_gf2m_field_div(const EC_GROUP *group, BIGNUM *r,
+				    const BIGNUM *a, const BIGNUM *b,BN_CTX *ctx) {
+    unsigned char rmisec_a[256],
+                  rmisec_b[256],
+                  rmisec_c[256],
+                  rmisec_r[256];
+    int a_len, b_len, c_len, r_len;
+    op_handle_t handle = RMISAE_HANDLE_INITIALIZER;
+    int degree;
+    ECC_Mode_t deg;
+    int err = 1;
+
+    degree = group->meth->group_get_degree(group);
+    deg = get_gf2m_degree(degree);
+
+    if (RMISEC_GLOBAL_FD < 0 || p_RMISEC_ecc_gf2m_field_inv == NULL ||
+	p_RMISEC_ecc_gf2m_field_mul == NULL || deg == -1)
+        return ec_GF2m_simple_field_div(group,r,a,b,ctx);
+
+    memset (rmisec_b, 0, sizeof(rmisec_b));
+    BN_bn2bin(b, rmisec_b);
+    b_len = BN_num_bits(b);
+
+    if((err = p_RMISEC_op_init(RMISEC_GLOBAL_FD, &handle))) {
+	    fprintf(stderr, "%s:%d aborted\n", __FUNCTION__, __LINE__);
+	    err = 0;
+	    goto err;
+    }
+
+    if ((err = p_RMISEC_ecc_gf2m_field_inv (handle, deg,
+                           rmisec_b, b_len,
+                           rmisec_c, &c_len)) != RMISAE_SUCCESS) {
+	    fprintf(stderr, "%s:%d err %d\n", __FUNCTION__, __LINE__, err);
+	    RMISECerr(RMISEC_F_RMISEC_ECC_FIELD_DIV,
+		      RMISEC_R_REQUEST_FAILED);
+	    err = 0;
+	    goto err;
+    }
+    memset (rmisec_a, 0, sizeof(rmisec_a));
+    BN_bn2bin(a, rmisec_a);
+    a_len = BN_num_bits(a);
+
+    if ((err = p_RMISEC_ecc_gf2m_field_mul (handle, deg,
+                           rmisec_a, a_len,
+                           rmisec_c, c_len,
+                           rmisec_r, &r_len)) != RMISAE_SUCCESS) {
+	    fprintf(stderr, "%s:%d err %d\n", __FUNCTION__, __LINE__, err);
+	    RMISECerr(RMISEC_F_RMISEC_ECC_FIELD_DIV,
+		      RMISEC_R_REQUEST_FAILED);
+	    err = 0;
+	    goto err;
+    }
+
+    if (!BN_bin2bn(rmisec_r, CEIL(r_len, 3), r)) {
+	    DBG_PRINT("Result BN_bin2bn !FAILED! \n");
+	    fprintf(stderr, "%s:%d aborted\n", __FUNCTION__, __LINE__);
+	    err = 0;
+	    goto err;
+    }
+err:
+    p_RMISEC_op_cleanup(&handle);
+    return err;
+}
+
+static int rmisec_ec_gf2m_mul(const EC_GROUP *group, EC_POINT *s, const BIGNUM *scalar,
+			      size_t num, const EC_POINT *points[],
+			      const BIGNUM *scalars[], BN_CTX *ctx) {
+    int i;
+    const EC_POINT *generator;
+    EC_POINT *r = 0;
+    op_handle_t handle = RMISAE_HANDLE_INITIALIZER;
+    int degree;
+    ECC_Mode_t deg;
+    BIGNUM *b, *x, *y, *s_x, *s_y, *r_x, *r_y;
+    int err = 1;
+
+    unsigned char rmisec_x[256],
+                  rmisec_y[256],
+                  rmisec_b[256],
+                  rmisec_k[256],
+                  rmisec_s_x[256],
+                  rmisec_s_y[256];
+    int s_x_len, s_y_len;
+    int first_sum = 0;
+
+    degree = group->meth->group_get_degree(group);
+    deg = get_gf2m_degree(degree);
+
+    if (RMISEC_GLOBAL_FD < 0 || p_RMISEC_ecc_gf2m_mul == NULL || deg == -1)
+        return ec_GF2m_simple_mul(group, (EC_POINT *)s, scalar, num, points,
+				  scalars, ctx);
+
+    /*
+     * Point multiplication       R(x_r, y_r) = k . P(x_p, y_p)
+     *
+     *                 DATA IN                 DATA OUT
+     *                 =======                 ========
+     * src+glb_off->   b        dst+glb_off->  x_r
+     *                 k                       y_r
+     *                 x_p                     2x(3/4)
+     *                 y_p                     6/8 dw
+     *                 4x(3/4)=
+     *                 12/16 dw
+     */
+    BN_CTX_start(ctx);
+
+    /* build b */
+    b = BN_CTX_get(ctx);
+    if (!group->meth->group_get_curve(group, 0, 0, b, ctx)) goto err;
+    memset (rmisec_b, 0, sizeof(rmisec_b));
+    BN_bn2bin(b, rmisec_b);
+
+    /* build point */
+    generator = EC_GROUP_get0_generator(group);
+    x = BN_CTX_get(ctx);
+    y = BN_CTX_get(ctx);
+    s_x = BN_CTX_get(ctx);
+    s_y = BN_CTX_get(ctx);
+    r_x = BN_CTX_get(ctx);
+    r_y = BN_CTX_get(ctx);
+
+    for (i=0;i<num+1;i++) {
+
+        if (!(i == 0 ? scalar : scalars[i-1])) continue;
+
+        /* build (x, y) */
+        group->meth->point_get_affine_coordinates(group,
+						  i == 0 ? generator : points[i-1],
+						  x, y, ctx);
+        memset (rmisec_x, 0, sizeof(rmisec_x));
+        BN_bn2bin(x, rmisec_x);
+        memset (rmisec_y, 0, sizeof(rmisec_y));
+        BN_bn2bin(y, rmisec_y);
+
+        /* build k */
+        memset (rmisec_k, 0, sizeof(rmisec_k));
+        BN_bn2bin(i == 0 ? scalar : scalars[i-1], rmisec_k);
+
+        /* hw computes (r_x, r_y) = k * (x, y), with y^2 + x*y = x^3 + a*x + b */
+	if((err = p_RMISEC_op_init(RMISEC_GLOBAL_FD, &handle))) {
+		goto err;
+	}
+
+       if ((err = p_RMISEC_ecc_gf2m_mul (handle, deg,
+                               rmisec_x, BN_num_bits(x),
+                               rmisec_y, BN_num_bits(y),
+                               rmisec_b, BN_num_bits(b),
+                               rmisec_k, BN_num_bits(i == 0 ? scalar : scalars[i-1]),
+                               rmisec_s_x, &s_x_len,
+                               rmisec_s_y, &s_y_len)) != RMISAE_SUCCESS) {
+	    fprintf(stderr, "%s:%d err %d\n", __FUNCTION__, __LINE__, err);
+            RMISECerr(RMISEC_F_RMISEC_ECC_GF2M_MUL,
+                      RMISEC_R_REQUEST_FAILED);
+	    err = 0;
+            goto err;
+        }
+        if (!BN_bin2bn(rmisec_s_x, CEIL(s_x_len, 3), s_x) ||
+            !BN_bin2bn(rmisec_s_y, CEIL(s_y_len, 3), s_y)) {
+		DBG_PRINT("Result BN_bin2bn !FAILED! \n");
+		fprintf(stderr, "%s:%d aborted\n", __FUNCTION__, __LINE__);
+		err = 0;
+		goto err;
+        }
+        if (!first_sum) {
+            if (BN_is_zero(s_x) && BN_is_zero(s_y)) {
+                if (!EC_POINT_set_to_infinity(group, s)) {
+			fprintf(stderr, "%s:%d aborted\n", __FUNCTION__, __LINE__);
+			err = 0;
+			goto err;
+		}
+            }
+            else if (!group->meth->point_set_affine_coordinates(group, (EC_POINT *)s, s_x, s_y, ctx)) {
+                RMISECerr(RMISEC_F_RMISEC_ECC_GF2M_MUL,
+                          RMISEC_R_REQUEST_FAILED);
+		fprintf(stderr, "%s:%d aborted\n", __FUNCTION__, __LINE__);
+		err = 0;
+                goto err;
+            }
+            first_sum = 1;
+        }
+        else {
+            if (!r) r = EC_POINT_new(group);
+            if (BN_is_zero(s_x) && BN_is_zero(s_y)) {
+                if (!EC_POINT_set_to_infinity(group, r)) {
+			fprintf(stderr, "%s:%d aborted\n", __FUNCTION__, __LINE__);
+			err = 0;
+			goto err;
+		}
+            }
+            else if (!group->meth->point_set_affine_coordinates(group, (EC_POINT *)r, s_x, s_y, ctx)) {
+		    RMISECerr(RMISEC_F_RMISEC_ECC_GF2M_MUL,
+			      RMISEC_R_REQUEST_FAILED);
+		    fprintf(stderr, "%s:%d aborted\n", __FUNCTION__, __LINE__);
+		    err = 0;
+		    goto err;
+            }
+            if (!group->meth->add(group, s, r, s, ctx)) {
+                RMISECerr(RMISEC_F_RMISEC_ECC_GF2M_MUL,
+                          RMISEC_R_REQUEST_FAILED);
+		fprintf(stderr, "%s:%d aborted\n", __FUNCTION__, __LINE__);
+		err = 0;
+                goto err;
+            }
+        }
+    }
+err:
+    p_RMISEC_op_cleanup(&handle);
+    if (r) EC_POINT_free((EC_POINT *)r);
+    BN_CTX_end(ctx);
+    return err;
+}
+#endif /* OPENSSL_NO_EC */
+#endif /* !OPENSSL_NO_HW_RMISEC */
+#endif /* !OPENSSL_NO_HW */
+
diff -Naur -X symlinks openssl-0.9.8o.orig/engines/e_rmisec_err.c openssl-0.9.8o/engines/e_rmisec_err.c
--- openssl-0.9.8o.orig/engines/e_rmisec_err.c	1969-12-31 19:00:00.000000000 -0500
+++ openssl-0.9.8o/engines/e_rmisec_err.c	2010-09-22 15:26:59.463377483 -0400
@@ -0,0 +1,168 @@
+/***********************************************************************
+Copyright 2003-2006 Raza Microelectronics, Inc.(RMI).
+This is a derived work from software originally provided by the external
+entity identified below. The licensing terms and warranties specified in
+the header of the original work apply to this derived work.
+Contribution by RMI: use the xlr crypto library
+*****************************#RMI_1#**********************************/
+
+/* e_rmisec_err.c */
+/* ====================================================================
+ * Copyright (c) 1999 The OpenSSL Project.  All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer. 
+ *
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in
+ *    the documentation and/or other materials provided with the
+ *    distribution.
+ *
+ * 3. All advertising materials mentioning features or use of this
+ *    software must display the following acknowledgment:
+ *    "This product includes software developed by the OpenSSL Project
+ *    for use in the OpenSSL Toolkit. (http://www.OpenSSL.org/)"
+ *
+ * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
+ *    endorse or promote products derived from this software without
+ *    prior written permission. For written permission, please contact
+ *    openssl-core@OpenSSL.org.
+ *
+ * 5. Products derived from this software may not be called "OpenSSL"
+ *    nor may "OpenSSL" appear in their names without prior written
+ *    permission of the OpenSSL Project.
+ *
+ * 6. Redistributions of any form whatsoever must retain the following
+ *    acknowledgment:
+ *    "This product includes software developed by the OpenSSL Project
+ *    for use in the OpenSSL Toolkit (http://www.OpenSSL.org/)"
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
+ * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE OpenSSL PROJECT OR
+ * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+ * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
+ * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
+ * OF THE POSSIBILITY OF SUCH DAMAGE.
+ * ====================================================================
+ *
+ * This product includes cryptographic software written by Eric Young
+ * (eay@cryptsoft.com).  This product includes software written by Tim
+ * Hudson (tjh@cryptsoft.com).
+ *
+ */
+
+/* NOTE: this file was auto generated by the mkerr.pl script: any changes
+ * made to it will be overwritten when the script next updates this file,
+ * only reason strings will be preserved.
+ */
+
+#include <stdio.h>
+#include <openssl/err.h>
+#include "e_rmisec_err.h"
+
+/* BEGIN ERROR CODES */
+#ifndef OPENSSL_NO_ERR
+static ERR_STRING_DATA RMISEC_str_functs[]=
+	{
+{ERR_PACK(0,RMISEC_F_RMISEC_CTRL,0),	"RMISEC_CTRL"},
+{ERR_PACK(0,RMISEC_F_RMISEC_FINISH,0),	"RMISEC_FINISH"},
+{ERR_PACK(0,RMISEC_F_RMISEC_INIT,0),	"RMISEC_INIT"},
+{ERR_PACK(0,RMISEC_F_RMISEC_MOD_EXP,0),	"RMISEC_MOD_EXP"},
+{ERR_PACK(0,RMISEC_F_RMISEC_RSA_MOD_EXP,0),	"RMISEC_RSA_MOD_EXP"},
+{ERR_PACK(0,RMISEC_F_RMISEC_RSA_MOD_EXP_CRT,0),	"RMISEC_RSA_MOD_EXP_CRT"},
+{ERR_PACK(0,RMISEC_F_RMISEC_DH_MOD_EXP,0),	"RMISEC_DH_MOD_EXP"},
+{ERR_PACK(0,RMISEC_F_RMISEC_RNG_BYTES,0),	"RMISEC_RNG_BYTES"},
+{ERR_PACK(0,RMISEC_F_RMISEC_ECC_MUL,0),         "RMISEC_ECC_MUL"},
+{ERR_PACK(0,RMISEC_F_RMISEC_ECC_ADD,0),         "RMISEC_ECC_ADD"},
+{ERR_PACK(0,RMISEC_F_RMISEC_ECC_DBL,0),         "RMISEC_ECC_DBL"},
+{ERR_PACK(0,RMISEC_F_RMISEC_ECC_VFY,0),         "RMISEC_ECC_VFY"},
+{ERR_PACK(0,RMISEC_F_RMISEC_ECC_GF2M_FIELD_MUL,0),"RMISEC_ECC_GF2M_FIELD_MUL"},
+{ERR_PACK(0,RMISEC_F_RMISEC_ECC_GF2M_FIELD_SQR,0),"RMISEC_ECC_GF2M_FIELD_SQR"},
+{ERR_PACK(0,RMISEC_F_RMISEC_ECC_FIELD_MUL,0),     "RMISEC_ECC_FIELD_MUL"},
+{ERR_PACK(0,RMISEC_F_RMISEC_ECC_FIELD_DIV,0),     "RMISEC_ECC_FIELD_DIV"},
+{ERR_PACK(0,RMISEC_F_RMISEC_ECC_GF2M_MUL,0),      "RMISEC_ECC_GF2M_MUL"},
+{0,NULL}
+	};
+
+static ERR_STRING_DATA RMISEC_str_reasons[]=
+	{
+{RMISEC_R_ALREADY_LOADED                  ,"already loaded"},
+{RMISEC_R_BN_EXPAND_FAIL                  ,"bn expand fail"},
+{RMISEC_R_CTRL_COMMAND_NOT_IMPLEMENTED    ,"ctrl command not implemented"},
+{RMISEC_R_DSO_FAILURE                     ,"dso failure"},
+{RMISEC_R_MISSING_KEY_COMPONENTS          ,"missing key components"},
+{RMISEC_R_NOT_LOADED                      ,"not loaded"},
+{RMISEC_R_REQUEST_FAILED                  ,"request failed"},
+{RMISEC_R_SIZE_TOO_LARGE_OR_TOO_SMALL     ,"size too large or too small"},
+{RMISEC_R_UNIT_FAILURE                    ,"unit failure"},
+{RMISEC_R_CONST_CALC_FAILURE              ,"constant calculation failure"},
+{RMISEC_R_MEM_ALLOC_FAILURE               ,"memory allocation failure"},
+{0,NULL}
+	};
+
+#endif
+
+#ifdef RMISEC_LIB_NAME
+static ERR_STRING_DATA RMISEC_lib_name[]=
+        {
+{0	,RMISEC_LIB_NAME},
+{0,NULL}
+	};
+#endif
+
+
+static int RMISEC_lib_error_code=0;
+static int RMISEC_error_init=1;
+
+static void ERR_load_RMISEC_strings(void)
+	{
+	if (RMISEC_lib_error_code == 0)
+		RMISEC_lib_error_code=ERR_get_next_error_library();
+
+	if (RMISEC_error_init)
+		{
+		RMISEC_error_init=0;
+#ifndef OPENSSL_NO_ERR
+		ERR_load_strings(RMISEC_lib_error_code,RMISEC_str_functs);
+		ERR_load_strings(RMISEC_lib_error_code,RMISEC_str_reasons);
+#endif
+
+#ifdef RMISEC_LIB_NAME
+		RMISEC_lib_name->error = ERR_PACK(RMISEC_lib_error_code,0,0);
+		ERR_load_strings(0,RMISEC_lib_name);
+#endif
+		}
+	}
+
+static void ERR_unload_RMISEC_strings(void)
+	{
+	if (RMISEC_error_init == 0)
+		{
+#ifndef OPENSSL_NO_ERR
+		ERR_unload_strings(RMISEC_lib_error_code,RMISEC_str_functs);
+		ERR_unload_strings(RMISEC_lib_error_code,RMISEC_str_reasons);
+#endif
+
+#ifdef RMISEC_LIB_NAME
+		ERR_unload_strings(0,RMISEC_lib_name);
+#endif
+		RMISEC_error_init=1;
+		}
+	}
+
+static void ERR_RMISEC_error(int function, int reason, char *file, int line)
+	{
+	if (RMISEC_lib_error_code == 0)
+		RMISEC_lib_error_code=ERR_get_next_error_library();
+	ERR_PUT_error(RMISEC_lib_error_code,function,reason,file,line);
+	}
diff -Naur -X symlinks openssl-0.9.8o.orig/engines/e_rmisec_err.h openssl-0.9.8o/engines/e_rmisec_err.h
--- openssl-0.9.8o.orig/engines/e_rmisec_err.h	1969-12-31 19:00:00.000000000 -0500
+++ openssl-0.9.8o/engines/e_rmisec_err.h	2010-09-22 15:26:59.463377483 -0400
@@ -0,0 +1,120 @@
+/***********************************************************************
+Copyright 2003-2006 Raza Microelectronics, Inc.(RMI).
+This is a derived work from software originally provided by the external
+entity identified below. The licensing terms and warranties specified in
+the header of the original work apply to this derived work.
+Contribution by RMI: use the xlr crypto library
+*****************************#RMI_1#**********************************/
+
+/* ====================================================================
+ * Copyright (c) 2001 The OpenSSL Project.  All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer. 
+ *
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in
+ *    the documentation and/or other materials provided with the
+ *    distribution.
+ *
+ * 3. All advertising materials mentioning features or use of this
+ *    software must display the following acknowledgment:
+ *    "This product includes software developed by the OpenSSL Project
+ *    for use in the OpenSSL Toolkit. (http://www.openssl.org/)"
+ *
+ * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
+ *    endorse or promote products derived from this software without
+ *    prior written permission. For written permission, please contact
+ *    openssl-core@openssl.org.
+ *
+ * 5. Products derived from this software may not be called "OpenSSL"
+ *    nor may "OpenSSL" appear in their names without prior written
+ *    permission of the OpenSSL Project.
+ *
+ * 6. Redistributions of any form whatsoever must retain the following
+ *    acknowledgment:
+ *    "This product includes software developed by the OpenSSL Project
+ *    for use in the OpenSSL Toolkit (http://www.openssl.org/)"
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
+ * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE OpenSSL PROJECT OR
+ * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+ * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
+ * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
+ * OF THE POSSIBILITY OF SUCH DAMAGE.
+ * ====================================================================
+ *
+ * This product includes cryptographic software written by Eric Young
+ * (eay@cryptsoft.com).  This product includes software written by Tim
+ * Hudson (tjh@cryptsoft.com).
+ *
+ */
+
+#ifndef HEADER_RMISEC_ERR_H
+#define HEADER_RMISEC_ERR_H
+
+#ifdef	__cplusplus
+extern "C" {
+#endif	/* __cplusplus */
+
+/* BEGIN ERROR CODES */
+/* The following lines are auto generated by the script mkerr.pl. Any changes
+ * made after this point may be overwritten when the script is next run.
+ */
+static void ERR_load_RMISEC_strings(void);
+static void ERR_unload_RMISEC_strings(void);
+static void ERR_RMISEC_error(int function, int reason, char *file, int line);
+#define RMISECerr(f,r) ERR_RMISEC_error((f),(r),__FILE__,__LINE__)
+
+/* Error codes for the RMISEC functions. */
+
+/* Function codes. */
+#define RMISEC_F_RMISEC_CTRL                 100
+#define RMISEC_F_RMISEC_FINISH               101
+#define RMISEC_F_RMISEC_INIT                 102
+#define RMISEC_F_RMISEC_MOD_EXP              103
+#define RMISEC_F_RMISEC_RSA_MOD_EXP          104
+#define RMISEC_F_RMISEC_RSA_MOD_EXP_CRT      105
+#define RMISEC_F_RMISEC_DH_MOD_EXP           106
+#define RMISEC_F_RMISEC_RNG_BYTES            107
+#define RMISEC_F_RMISEC_ECC_MUL              108
+#define RMISEC_F_RMISEC_ECC_ADD              109
+#define RMISEC_F_RMISEC_ECC_DBL              110
+#define RMISEC_F_RMISEC_ECC_VFY              111
+#define RMISEC_F_RMISEC_ECC_GF2M_FIELD_MUL   112
+#define RMISEC_F_RMISEC_ECC_GF2M_FIELD_SQR   113
+#define RMISEC_F_RMISEC_ECC_FIELD_MUL        114
+#define RMISEC_F_RMISEC_ECC_FIELD_DIV        115
+#define RMISEC_F_RMISEC_ECC_FIELD_INV        116
+#define RMISEC_F_RMISEC_ECC_FIELD_RED        117
+#define RMISEC_F_RMISEC_ECC_FIELD_ADD        118
+#define RMISEC_F_RMISEC_ECC_FIELD_SUB        119
+#define RMISEC_F_RMISEC_ECC_GF2M_MUL         120
+
+/* Reason codes. */
+#define RMISEC_R_ALREADY_LOADED	             100
+#define RMISEC_R_BN_EXPAND_FAIL              101
+#define RMISEC_R_CTRL_COMMAND_NOT_IMPLEMENTED   102
+#define RMISEC_R_DSO_FAILURE                 103
+#define RMISEC_R_MISSING_KEY_COMPONENTS      104
+#define RMISEC_R_NOT_LOADED                  105
+#define RMISEC_R_REQUEST_FAILED              106
+#define RMISEC_R_SIZE_TOO_LARGE_OR_TOO_SMALL 107
+#define RMISEC_R_UNIT_FAILURE                108
+#define RMISEC_R_CONST_CALC_FAILURE          109
+#define RMISEC_R_MEM_ALLOC_FAILURE           110
+
+#ifdef  __cplusplus
+}
+#endif
+#endif
diff -Naur -X symlinks openssl-0.9.8o.orig/engines/e_ubsec.c openssl-0.9.8o/engines/e_ubsec.c
--- openssl-0.9.8o.orig/engines/e_ubsec.c	2010-09-07 16:38:51.587700142 -0400
+++ openssl-0.9.8o/engines/e_ubsec.c	2010-09-22 15:26:59.463377483 -0400
@@ -331,7 +331,7 @@
 static void free_UBSEC_LIBNAME(void)
 	{
 	if(UBSEC_LIBNAME)
-		OPENSSL_free((void*)UBSEC_LIBNAME);
+		OPENSSL_free(UBSEC_LIBNAME);
 	UBSEC_LIBNAME = NULL;
 	}
 static long set_UBSEC_LIBNAME(const char *name)
diff -Naur -X symlinks openssl-0.9.8o.orig/engines/Makefile openssl-0.9.8o/engines/Makefile
--- openssl-0.9.8o.orig/engines/Makefile	2010-09-07 16:38:51.587700142 -0400
+++ openssl-0.9.8o/engines/Makefile	2010-09-22 15:26:59.463377483 -0400
@@ -5,7 +5,7 @@
 DIR=	engines
 TOP=	..
 CC=	cc
-INCLUDES= -I../include
+INCLUDES= -I../include -I../crypto
 CFLAG=-g
 MAKEFILE=	Makefile
 AR=		ar r
@@ -20,7 +20,7 @@
 APPS=
 
 LIB=$(TOP)/libcrypto.a
-LIBNAMES= 4758cca aep atalla cswift gmp chil nuron sureware ubsec capi
+LIBNAMES= 4758cca aep atalla cswift gmp chil nuron sureware ubsec capi rmisec
 
 LIBSRC=	e_4758cca.c \
 	e_aep.c \
@@ -31,7 +31,8 @@
 	e_nuron.c \
 	e_sureware.c \
 	e_ubsec.c \
-	e_capi.c
+	e_capi.c \
+	e_rmisec.c
 LIBOBJ= e_4758cca.o \
 	e_aep.o \
 	e_atalla.o \
@@ -41,7 +42,8 @@
 	e_nuron.o \
 	e_sureware.o \
 	e_ubsec.o \
-	e_capi.o
+	e_capi.o \
+	e_rmisec.o
 
 SRC= $(LIBSRC)
 
@@ -55,7 +57,8 @@
 	e_nuron_err.c e_nuron_err.h \
 	e_sureware_err.c e_sureware_err.h \
 	e_ubsec_err.c e_ubsec_err.h \
-	e_capi_err.c e_capi_err.h
+	e_capi_err.c e_capi_err.h \
+	e_rmisec_err.c e_rmisec_err.h
 
 ALL=    $(GENERAL) $(SRC) $(HEADER)
 
diff -Naur -X symlinks openssl-0.9.8o.orig/engines/vendor_defns/rmisec_wrapper.h openssl-0.9.8o/engines/vendor_defns/rmisec_wrapper.h
--- openssl-0.9.8o.orig/engines/vendor_defns/rmisec_wrapper.h	1969-12-31 19:00:00.000000000 -0500
+++ openssl-0.9.8o/engines/vendor_defns/rmisec_wrapper.h	2010-09-22 15:26:59.463377483 -0400
@@ -0,0 +1,317 @@
+/********************************************************************
+Copyright 2003-2009 RMI Corporation (RMI) All rights reserved.
+Redistribution and use in source and binary forms, with or without
+modification, are permitted provided that the following conditions are
+met:
+1. Redistributions of source code must retain the above copyright
+notice, this list of conditions and the following disclaimer.
+2. Redistributions in binary form must reproduce the above copyright
+notice, this list of conditions and the following disclaimer in
+the documentation and/or other materials provided with the
+distribution.
+THIS SOFTWARE IS PROVIDED BY RMI Corporation. ``AS IS'' AND
+ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL RMI OR CONTRIBUTORS BE LIABLE
+FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
+THE POSSIBILITY OF SUCH DAMAGE.
+********************************************************************/
+/*
+ * RMI Phoenix Security Engine  
+ *
+ * hw_rmisec.c:    OpenSSL-ENGINE header for Vendor Defs
+ *
+ * Revision History:
+ *
+ * 04/01/2004  DPK   Created
+ */
+
+#ifndef _HW_RMISEC_H_
+#define _HW_RMISEC_H_
+#include <rmisae.h>
+
+#ifdef	__cplusplus
+extern "C" {
+#endif	/* __cplusplus */
+
+#define CEIL(n, bits) ((n + ((1 << bits) - 1)) >> bits)
+#define CEIL_VALUE(n, bits) (CEIL(n, bits))
+
+#define RMI_MAX_KEYSIZE_RSA       2048
+#define RMI_MAX_KEYSIZE_RSA_CRT   1024
+
+#define RMI_MAX_PUBLIC_KEY_BITS   (1024)
+#define RMI_MAX_PUBLIC_KEY_BYTES  (1024/8)
+
+#define RMI_SHA1_BIT_SIZE         (160)
+#define RMI_SHA256_BIT_SIZE       (256)
+#define RMI_SHA384_BIT_SIZE       (512)
+#define RMI_SHA512_BIT_SIZE       (512)
+
+#define RMI_DES_KEY_LENGTH        8
+#define RMI_3DES_KEY_LENGTH       24
+#define RMI_DES_BLOCK_SIZE        8
+
+#define RMI_AES_128_KEY_LENGTH    16
+#define RMI_AES_192_KEY_LENGTH    24
+#define RMI_AES_256_KEY_LENGTH    32 
+#define RMI_AES_512_KEY_LENGTH    64
+#define RMI_MAX_CRYPTO_KEY_LENGTH 32 
+#define RMI_MAX_MAC_KEY_LENGTH    64
+#define RMI_AES_BLOCK_SIZE        16
+ 
+#define RMI_ARC4_KEY_LENGTH        32 
+#define RMI_MAX_CRYPTO_KEY_LENGTH  32 
+#define RMI_ARC4_STATE_SIZE        264
+
+#define RMI_MD5_DIGEST_LENGTH     16
+#define RMI_SHA_DIGEST_LENGTH     20
+#define RMI_MAX_DIGEST_LENGTH     RMI_SHA_DIGEST_LENGTH
+
+//#define RMISEC_DEVICE_NAME 		((unsigned char *)"/dev/rmisec")
+#define RMISEC_DEVICE_NAME 		((unsigned char *)"/dev/xlr_crypto")
+
+typedef struct rmisec_crypto_context_s {
+	unsigned int	flags;
+	unsigned char	crypto[RMI_MAX_CRYPTO_KEY_LENGTH];
+	unsigned char 	auth[RMI_MAX_MAC_KEY_LENGTH];
+} rmisec_crypto_context_t, *rmisec_crypto_context_p;
+
+/*
+ * Memory type
+ */
+typedef struct rmi_num_s {
+	unsigned long num_len;
+	unsigned char *num;
+} rmi_num_t;
+#define RMI_NUM  rmi_num_t
+
+typedef struct rmi_data_s {
+	unsigned long data_len;
+	unsigned char *data;
+} rmi_data_t;
+
+#define RMI_DATA rmi_data_t
+
+
+typedef struct
+{
+    unsigned char des_key [ RMI_DES_KEY_LENGTH ] ;
+    unsigned char des_iv [ RMI_DES_BLOCK_SIZE ] ;
+    int           key_size;
+} RMI_DES_KEY;
+
+typedef struct
+{
+    unsigned char des3_key [ RMI_3DES_KEY_LENGTH ] ;
+    unsigned char des3_iv [ RMI_DES_BLOCK_SIZE ] ;
+    int           key_size;
+} RMI_3DES_KEY;
+
+typedef struct
+{
+    unsigned char   key[RMI_AES_BLOCK_SIZE*4];
+    unsigned char   iv [RMI_AES_BLOCK_SIZE];
+    int             key_size;
+} RMI_AES_KEY;
+
+typedef struct
+{
+    unsigned char rc4_key[RMI_ARC4_KEY_LENGTH] ;
+    unsigned int rc4_key_len;
+    unsigned int rc4_load;
+    unsigned char rc4_state[RMI_ARC4_STATE_SIZE];
+} RMI_ARC4_KEY;
+
+
+/* Define a data structure for digests operations */
+#define RMI_DGST_BUF_BLKSIZE    2048
+typedef struct RMI_data_st
+{
+	unsigned int  len;
+	unsigned int  max_len;
+	unsigned char *data; 
+} RMI_MD_DATA ;
+
+/* 
+ * Predeclare the function pointer types that we dynamically load from the DSO.
+ */
+typedef int t_RMISEC_bytes_to_bits(unsigned char *n, int bytes);
+
+typedef int t_RMISEC_bits_to_bytes(int bits);
+
+typedef int t_RMISEC_open(void);
+
+typedef int t_RMISEC_close();
+
+typedef int t_RMISEC_op_init(int, op_handle_pt);
+
+typedef int t_RMISEC_op_cleanup(op_handle_pt);
+
+typedef int t_RMISEC_mod_exp (op_handle_t handle,
+			      const unsigned char *x, int x_len,
+			      const unsigned char *m, int m_len,
+			      const unsigned char *e, int e_len,
+			      const unsigned char *c, int c_len,
+			      unsigned char *y, int *y_len);
+
+typedef int t_RMISEC_ecc_mul (op_handle_t handle, int degree,
+        unsigned char *x, int x_len, unsigned char *y, int y_len,
+        unsigned char *a, int a_len, unsigned char *k, int k_len,
+        unsigned char *n, int n_len, unsigned char *c, int c_len,
+        unsigned char *r_x, int *r_x_len, unsigned char *r_y, int *r_y_len);
+typedef int t_RMISEC_ecc_add (op_handle_t handle, int degree,
+        unsigned char *x1, int x1_len, unsigned char *y1, int y1_len,
+        unsigned char *x2, int x2_len, unsigned char *y2, int y2_len,
+        unsigned char *a, int a_len, unsigned char *n, int n_len,
+        unsigned char *c, int c_len, unsigned char *r_x, int *r_x_len,
+        unsigned char *r_y, int *r_y_len);
+typedef int t_RMISEC_ecc_dbl (op_handle_t handle, int degree,
+        unsigned char *x, int x_len, unsigned char *y, int y_len,
+        unsigned char *a, int a_len, unsigned char *n, int n_len,
+        unsigned char *c, int c_len, unsigned char *r_x, int *r_x_len,
+        unsigned char *r_y, int *r_y_len);
+typedef int t_RMISEC_ecc_vfy (op_handle_t handle, int degree,
+        unsigned char *x, int x_len, unsigned char *y, int y_len,
+        unsigned char *a, int a_len, unsigned char *b, int b_len,
+        unsigned char *n, int n_len, unsigned char *c, int c_len,
+        unsigned int *s);
+typedef int t_RMISEC_ecc_gfp_mul (op_handle_t handle, int degree,
+        unsigned char *x, int x_len, unsigned char *y, int y_len,
+        unsigned char *a, int a_len, unsigned char *k, int k_len,
+        unsigned char *n, int n_len, unsigned char *c, int c_len,
+        unsigned char *r_x, int *r_x_len, unsigned char *r_y, int *r_y_len);
+typedef int t_RMISEC_ecc_gfp_add (op_handle_t handle, int degree,
+        unsigned char *x1, int x1_len, unsigned char *y1, int y1_len,
+        unsigned char *x2, int x2_len, unsigned char *y2, int y2_len,
+        unsigned char *a, int a_len, unsigned char *n, int n_len,
+        unsigned char *c, int c_len, unsigned char *r_x, int *r_x_len,
+        unsigned char *r_y, int *r_y_len);
+typedef int t_RMISEC_ecc_gfp_dbl (op_handle_t handle, int degree,
+        unsigned char *x, int x_len, unsigned char *y, int y_len,
+        unsigned char *a, int a_len, unsigned char *n, int n_len,
+        unsigned char *c, int c_len, unsigned char *r_x, int *r_x_len,
+        unsigned char *r_y, int *r_y_len);
+typedef int t_RMISEC_ecc_gfp_vfy (op_handle_t handle, int degree, 
+        unsigned char *x, int x_len, unsigned char *y, int y_len,
+        unsigned char *a, int a_len, unsigned char *b, int b_len,
+        unsigned char *n, int n_len, unsigned char *c, int c_len,
+        unsigned int *s);
+typedef int t_RMISEC_ecc_gf2m_mul (op_handle_t handle, int degree,
+        unsigned char *x, int x_len, unsigned char *y, int y_len,
+        unsigned char *b, int b_len, unsigned char *k, int k_len,
+        unsigned char *r_x, int *r_x_len, unsigned char *r_y, int *r_y_len);
+typedef int t_RMISEC_ecc_gfp_field_add (op_handle_t handle, int degree,
+        unsigned char *x, int x_len, unsigned char *y, int y_len,
+        unsigned char *n, int n_len, unsigned char *r, int *r_len);
+typedef int t_RMISEC_ecc_gfp_field_sub (op_handle_t handle, int degree,
+        unsigned char *x, int x_len, unsigned char *y, int y_len,
+        unsigned char *n, int n_len, unsigned char *r, int *r_len);
+typedef int t_RMISEC_ecc_gfp_field_mul (op_handle_t handle, int degree,
+        unsigned char *x, int x_len, unsigned char *y, int y_len,
+        unsigned char *n, int n_len, unsigned char *c, int c_len,
+        unsigned char *r, int *r_len);
+typedef int t_RMISEC_ecc_gfp_field_div (op_handle_t handle, int degree,
+        unsigned char *x, int x_len, unsigned char *y, int y_len,
+        unsigned char *n, int n_len, unsigned char *r, int *r_len);
+typedef int t_RMISEC_ecc_gfp_field_inv (op_handle_t handle, int degree,
+        unsigned char *x, int x_len, unsigned char *n, int n_len,
+        unsigned char *r, int *r_len);
+typedef int t_RMISEC_ecc_gfp_field_red (op_handle_t handle, int degree,
+        unsigned char *x, int x_len, unsigned char *n, int n_len,
+        unsigned char *r, int *r_len);
+typedef int t_RMISEC_ecc_gf2m_field_inv (op_handle_t handle, int degree,
+        unsigned char *x, int x_len, unsigned char *r, int *r_len);
+typedef int t_RMISEC_ecc_gf2m_field_mul (op_handle_t handle, int degree,
+        unsigned char *x, int x_len, unsigned char *y, int y_len,
+        unsigned char *r, int *r_len);
+typedef int t_RMISEC_ecc_gf2m_field_add (op_handle_t handle, int degree,
+        unsigned char *x, int x_len, unsigned char *y, int y_len,
+        unsigned char *r, int *r_len);
+
+/*
+ * Symetric API
+ */
+
+
+/*
+ * Functions for Digest (MD5, SHA1, SHA256) stuff
+ */
+typedef int t_RMISEC_md5 ( op_handle_t handle, 
+                           const unsigned char *data, unsigned int byte_count,
+                           unsigned char *digest ) ;
+
+typedef int t_RMISEC_sha1 ( op_handle_t handle, 
+                            const unsigned char *data, unsigned int byte_count,
+                            unsigned char *digest ) ;
+
+typedef int t_RMISEC_sha256 ( op_handle_t handle,
+                            const unsigned char *data, unsigned int byte_count,
+                            unsigned char *digest ) ;
+
+typedef int t_RMISEC_sha384 ( op_handle_t handle,
+                            const unsigned char *data, unsigned int byte_count,
+                            unsigned char *digest ) ;
+
+typedef int t_RMISEC_sha512 ( op_handle_t handle,
+                            const unsigned char *data, unsigned int byte_count,
+                            unsigned char *digest ) ;
+
+typedef int t_RMISEC_aes128_cipher ( op_handle_t handle,
+                                     const unsigned char *key,
+                                     const unsigned char *iv,
+                                     unsigned int op,
+                                     const unsigned char *input, unsigned int in_len,
+                                     unsigned char *output);
+
+typedef int t_RMISEC_aes192_cipher ( op_handle_t handle,
+                                     const unsigned char *key,
+                                     const unsigned char *iv,
+                                     unsigned int op,
+                                     const unsigned char *input, unsigned int in_len,
+                                     unsigned char *output);
+
+typedef int t_RMISEC_aes256_cipher ( op_handle_t handle,
+                                     const unsigned char *key,
+                                     const unsigned char *iv,
+                                     unsigned int op,
+                                     const unsigned char *input, unsigned int in_len,
+                                     unsigned char *output);
+
+
+typedef int t_RMISEC_des_cipher ( op_handle_t handle,
+                                  const unsigned char *key,
+                                  const unsigned char *iv,
+                                  unsigned int op,
+                                  const unsigned char *input, unsigned int in_len,
+                                  unsigned char *output);
+
+typedef int t_RMISEC_3des_cipher ( op_handle_t handle,
+                                   const unsigned char *key,
+                                   const unsigned char *iv,
+                                   unsigned int op,
+                                   const unsigned char *input, unsigned int in_len,
+                                   unsigned char *output);
+
+typedef int t_RMISEC_arc4_cipher ( op_handle_t handle,
+                                   const unsigned char *key,
+                                   int key_len,
+                                   const unsigned char *input,
+                                   unsigned int  input_len,
+                                   unsigned char *output,
+                                   int load_state,
+                                   int save_state,
+                                   unsigned char *state);
+
+#undef KEY
+
+#ifdef	__cplusplus
+}
+#endif	/* __cplusplus */
+
+#endif	/* !_HW_RMISEC_H_ */
diff -Naur -X symlinks openssl-0.9.8o.orig/README.RMISEC openssl-0.9.8o/README.RMISEC
--- openssl-0.9.8o.orig/README.RMISEC	1969-12-31 19:00:00.000000000 -0500
+++ openssl-0.9.8o/README.RMISEC	2010-09-22 15:26:59.463377483 -0400
@@ -0,0 +1,241 @@
+OpenSSL 0.9.8i with RMISAE security engine
+
+OpenSSL with RMISEC Engine
+==============================================================
+
+RMI provides a OpenSSL ENGINE definition to integrate the 
+security engine driver with the OpenSSL crypto library.  This 
+accelerates Message Digest (MD5,SHA-1,SHA-256,SHA-384,SHA-512),
+Symmetric Key Cipher (AES-128/192/256-CBC,DES-CBC,3DES-CBC, ARC4),
+modular exponentiation for 512-bit/1024-bit RSA Encryption
+and Diffie-Hellman Public/Shared values.
+
+On the XLS processors, the security engine also provides
+acceleration of Elliptic Curve Cryptography (GF(p) 160, 192, 224,
+256, 384, 512 and GF(2^m) 163, 191, 233). (*)
+
+  (*) Note: For GF(p) all algorithms with these number of bits are
+      supported, but for GF(2^m) the subset of algorithms supported
+      is : NIST-B163, NIST curve K-163, SECT-163R1, X9.62 C2-TNB191V1,
+      X9.62 C2-TNB191V2, X9.62 C2-TNB191V3, NIST-K233, NIST-B233,
+
+Guidelines:
+==============================================================
+- Modular Exponentiation operations will be done in software
+  if key size is not 512-bit or 1024-bit
+
+- ECC is supported from driver and is not integrated into
+  OpenSSL
+
+Statistics:
+==============================================================
+Statistics may be observed using the PROC filesystem.
+(PROC filesystem must be mounted;   $mount none /proc -t proc)
+
+- Display statistics
+$ cat /proc/rmi/rmisae/stats
+
+Requirements:
+==============================================================
+
+1)  Fastsyscall library
+2)  RMISAE Security Engine Driver
+3)  RMISAE OpenSSL Dynamic Shared Object
+4)  OpenSSL with RMISEC Engine
+
+1) RMISAE Security Engine Driver and Shared Object Library
+==============================================================
+
+RMISAE security engine is the latest version of security driver.  
+Apart from supporting existing feature set, the new driver supports
+fragments and cipher operations on data greater than 16Kb. It is
+delivered as a kernel module and can be loaded on RMI Linux 1.6 which
+has been compiled with the provided patch.
+
+Please refer to the README.txt under the security library sources
+for further details about compilation and basic validation testing
+of the driver.
+
+In order for OpenSSL to use the library, the shared libary must be
+present in LD_LIBRARY_PATH.
+ $ export LD_LIBRARY_PATH=<path to security library sources>:.
+
+3) OpenSSL with RMISEC Engine
+==============================================================
+
+A modified version of the OpenSSL library is distributed with
+the RMI Linux Applications.  It has ENGINE support for the RMI CPS
+family of processors.
+
+The location of source: apps/poc/openssl
+
+
+3) OpenSSL with RMISEC Engine
+==============================================================
+The package must be configured as follows:
+ $ cd apps/poc/openssl
+ $ ./config --prefix=<prefix-1> --openssldir=<prefix-2>
+   -I<fast_syscall directory> -I <path to shared_sources>
+   -L<fast_syscall directory> -lfast_syscall shared
+ $ make all install
+	prefix-1, where you want to install openssl.
+	prefix-2, path for the openssl directory.
+	path to shared_sources should be <absolute_path_to_rmisec_lib>/common
+	fast_syscall directory should also be absolute path to fast_syscall
+	directory
+
+Set the LD_LIBRARY_PATH to enable RMISAE OpenSSL Security engine to load
+RMISAE Security library:
+ $ export LD_LIBRARY_PATH=<prefix>/lib:<path to librmisec_lib.so>:<path to fast syscall library>:$LD_LIBRARY_PATH
+
+ Usage of OpenSSL Application
+==============================================================
+
+The build of the OpenSSL library creates an application with
+the same name:  apps/poc/openssl
+
+You can get usage information about this application from OpenSSL:
+http://www.openssl.org/docs/apps/openssl.html
+
+Examples using Security Engine:
+
+ $ <prefix-1>/bin/openssl dgst -engine rmisec -md5 <prefix-2>/openssl.cnf
+
+output should be...
+
+   engine "rmisec" set.
+   MD5(oid.cnf)= 74e01d80e5e158615525222907f4840e
+
+RMISEC engine control command:
+RSA_TOGGLE_CRT: To toggle the use of CRT in RSA Decryption algorithm. This
+		control command does not take any parameter.
+		Default: enabled.
+
+Other interesting usage:
+
+ $ <prefix-1>/bin/openssl speed -evp md5 -engine rmisec -elapsed -multi 32
+ $ <prefix-1>/bin/openssl speed -evp sha1 -engine rmisec -elapsed -multi 32
+ $ <prefix-1>/bin/openssl speed -evp sha256 -engine rmisec -elapsed -multi 32
+ $ <prefix-1>/bin/openssl speed -evp sha384 -engine rmisec -elapsed -multi 32
+ $ <prefix-1>/bin/openssl speed -evp sha512 -engine rmisec -elapsed -multi 32
+ $ <prefix-1>/bin/openssl speed -evp rc4 -engine rmisec -elapsed -multi 32
+ $ <prefix-1>/bin/openssl speed -evp des -engine rmisec -elapsed -multi 32
+ $ <prefix-1>/bin/openssl speed -evp des3 -engine rmisec -elapsed -multi 32
+ $ <prefix-1>/bin/openssl speed -evp aes128 -engine rmisec -elapsed -multi 32
+ $ <prefix-1>/bin/openssl speed -evp aes192 -engine rmisec -elapsed -multi 32
+ $ <prefix-1>/bin/openssl speed -evp aes256 -engine rmisec -elapsed -multi 32
+ $ <prefix-1>/bin/openssl speed rsa1024 -engine rmisec -elapsed -multi 32
+ $ <prefix-1>/bin/openssl speed rsa1024 -engine rmisec -enginecmd RSA_TOGGLE_CRT -elapsed -multi 32
+
+On XLS only:
+ $ <prefix-1>/bin/openssl speed ecdsa -engine rmisec -elapsed -multi 4
+ $ <prefix-1>/bin/openssl speed ecdh -engine rmisec -elapsed -multi 4
+
+Application considerations for OpenSSL ENGINE support
+==============================================================
+
+For examples on how to write applications to use openssl with rmisec support,
+please take a look openssl/apps/speed.c and other apps in that directory.
+
+The basic steps are as follows:
+
+static ENGINE *try_load_engine(BIO *err, const char *engine, int debug)
+        {
+        ENGINE *e = ENGINE_by_id("dynamic");
+        if (e)
+                {
+                if (!ENGINE_ctrl_cmd_string(e, "SO_PATH", engine, 0)
+                        || !ENGINE_ctrl_cmd_string(e, "LOAD", NULL, 0))
+                        {
+                        ENGINE_free(e);
+                        e = NULL;
+                        }
+                }
+        return e;
+        }
+
+ENGINE *setup_engine(BIO *err, const char *engine, int debug)
+        {
+        ENGINE *e = NULL;
+
+        if (engine)
+                {
+                if(strcmp(engine, "auto") == 0)
+                        {
+                        BIO_printf(err,"enabling auto ENGINE support\n");
+                        ENGINE_register_all_complete();
+                        return NULL;
+                        }
+                if((e = ENGINE_by_id(engine)) == NULL) {
+                        printf("FAILED to lookup engine=\"%s\"\n", engine);
+                        exit(-1);
+                }
+                if ((e = try_load_engine(err, engine, debug)) == NULL)
+                {
+                        BIO_printf(err,"invalid engine \"%s\"\n", engine);
+                        ERR_print_errors(err);
+                        return NULL;
+                }
+                if (debug)
+                        {
+                        ENGINE_ctrl(e, ENGINE_CTRL_SET_LOGSTREAM,
+                                0, err, 0);
+                        }
+                if(!ENGINE_set_default(e, ENGINE_METHOD_ALL))
+                        {
+                        BIO_printf(err,"can't use that engine\n");
+                        ERR_print_errors(err);
+                        ENGINE_free(e);
+                        return NULL;
+                        }
+
+                BIO_printf(err,"engine \"%s\" set.\n", ENGINE_get_id(e));
+
+                /* Free our "structural" reference. */
+                ENGINE_free(e);
+                }
+        return e;
+        }
+
+
+
+#include <crypto.h>
+#include <openssl/bio.h>
+{
+
+#if SSLEAY_VERSION_NUMBER >= 0x00907000L
+    /* Load all bundled ENGINEs into memory and make them visible */
+    ENGINE_load_builtin_engines();
+    if (!setup_engine(0, "rmisec", 0)) {
+	fprintf(stderr, "Failed to setup rmisec engine!\n");
+	exit(-1);
+    }
+
+    /* Register all of them for every algorithm they collectively implement */
+    ENGINE_register_all_complete();
+#endif
+}
+
+---------------------------------------------------------------------
+10/22/2007
+Speed patch for taking engine control commands
+==============================================
+apps/speed.c is the performance benchmarking program in OpenSSL.  This
+program is modified to take -enginecmd to take engine control parameters.
+-enginecmd "<control command string>[ <param>]"
+After initialization, the speed application will invoke the ENGINE_ctrl
+with the control command and param, if any.  The entire engine control
+command must be in quote and <param> must be separated from the control
+command string by a space.  The -enginecmd must be specified after -engine
+command in the command-line.
+
+RMISEC engine support RSA_TOGGLE_CRT command.  It does not take any
+additional parameter.
+---------------------------------------------------------------------
+04/10/2009
+The RMISEC crypto engine has been modified to work with the latest
+version of crypto driver.  Minor bugs in OpenSSL related to 0 length
+digests and code cleanup related to unnecessary casting has been
+cleaned.
+ECC integration to OpenSSL will be done in a subsequent release.
+----------------------------------------------------------------------
diff -Naur -X symlinks openssl-0.9.8o.orig/README.RMISEC.CROSS openssl-0.9.8o/README.RMISEC.CROSS
--- openssl-0.9.8o.orig/README.RMISEC.CROSS	1969-12-31 19:00:00.000000000 -0500
+++ openssl-0.9.8o/README.RMISEC.CROSS	2010-09-22 15:26:59.463377483 -0400
@@ -0,0 +1,50 @@
+
+
+*****PLEASE NOTE*********
+
+This is NOT the recommended way to build OpenSSL for the XLR.
+It has not been tested and is UNSUPPORTED at this time.
+
+Instead, please use the steps described in README.RMISEC in this
+directory.
+
+
+
+********************************************************
+Steps to Cross-Compile OpenSSL on RMI development machines:
+===============================================================
+
+The following steps assume you have gunzipped/untarred OpenSSL 
+distribution tarball and your shell's current working directory 
+is OpenSSL (i.e. openssl-0.9.7d).
+
+1.)  Set PATH
+> export PATH=/tools/mipscross/mips-linux/mips-linux/bin:$PATH
+
+
+2.)  Configure OpenSSL  
+
+> ./Configure linux-mips -I/usr/local/rmi/mipscross/linux/mips-linux/include -L/usr/local/rmi/mipscross/linux/mips-linux/lib no-asm
+
+
+3.) Copy the C-RunTime Libs to "apps" and "test" directories:
+
+>  cp /usr/local/rmi/mipscross/linux/mips-linux/lib/crt?.o apps/.
+>  cp /usr/local/rmi/mipscross/linux/mips-linux/lib/crt?.o test/.
+
+
+* - It appears that the LIB path set in the Configure are not passed 
+    to the archiver (ar).   
+
+
+** IMPORTANT **
+YOU WILL NEED TO MAKE librmisec.so (drivers/char/rmisec/lib) 
+AND COPY THIS SHARED-OBJECT LIBRARY TO (/usr/lib/.)
+ IN YOUR LINUX USERLAND.
+
+** AND **
+YOU WILL NEED TO MAKE THE LINUX RMISEC DEVICE IN YOUR USERLAND
+> mknod /dev/xlr_crypto c 242 1
+> chmod o+w /dev/xlr_crypto
+
+
diff -Naur -X symlinks openssl-0.9.8o.orig/run-perf.sh openssl-0.9.8o/run-perf.sh
--- openssl-0.9.8o.orig/run-perf.sh	1969-12-31 19:00:00.000000000 -0500
+++ openssl-0.9.8o/run-perf.sh	2010-09-22 15:26:59.463377483 -0400
@@ -0,0 +1,44 @@
+#!/bin/sh
+RUNDGST=1
+RUNRSA=1
+THREADS='1 2 4 8 16 32 64'
+RSABITS="512 1024 2048 1024 2048"
+ALGOS="md5 sha1 sha256 sha384 sha512 rc4 des des3 aes128 aes192 aes256"
+
+cat /dev/null>/tmp/err-log.txt
+rm -f /tmp/openssl-algo*.txt
+if [ x${RUNDGST} != x ]; then
+for j in `echo "$ALGOS"`; do
+#    echo "Running $j algorithm";
+    echo "$j" > /tmp/openssl-algo-$j.txt;
+    echo    "	   16          64          256         1024         8192"  >> /tmp/openssl-algo-$j.txt;
+    for i in `echo "${THREADS}"`; do
+#        echo -n "Running $i threads...";
+        echo -n "$i:	">> /tmp/openssl-algo-$j.txt;
+        (./openssl speed -evp $j -engine rmisec -elapsed -multi $i || exit) 2>>/tmp/err-log.txt | grep '^evp'|sed -e 's/^evp *//g' >> /tmp/openssl-algo-$j.txt;
+#	echo "done";
+    done
+    cat /tmp/openssl-algo-$j.txt
+    rm /tmp/openssl-algo-$j.txt
+done;
+fi
+
+EXTRACMDS=
+if [ x${RUNRSA} != x ]; then
+for j in `echo "$RSABITS"`; do
+#    echo "Running rsa$j algorithm";
+    echo "rsa$j" > /tmp/openssl-algo-rsa$j.txt;
+    echo "           sign    verify    sign/s    verify/s" >> /tmp/openssl-algo-rsa$j.txt;
+    for i in `echo "${THREADS}"`; do
+#        echo -n "Running $i threads...";
+        echo -n "$i:	">> /tmp/openssl-algo-rsa$j.txt;
+        (./openssl speed rsa$j -engine rmisec $EXTRACMDS -elapsed -multi $i || exit) 2>>/tmp/err-log.txt | grep '^rsa'|sed -e 's/^rsa *[0-9]* bits *//g' >> /tmp/openssl-algo-rsa$j.txt;
+#	echo "done";
+    done;
+    if [ $j = "2048" ]; then
+	EXTRACMDS="-enginecmd RSA_TOGGLE_CRT";
+    fi
+    cat /tmp/openssl-algo-rsa$j.txt
+    rm /tmp/openssl-algo-rsa$j.txt
+done;
+fi
diff -Naur -X symlinks openssl-0.9.8o.orig/ssl/s3_enc.c openssl-0.9.8o/ssl/s3_enc.c
--- openssl-0.9.8o.orig/ssl/s3_enc.c	2010-09-07 16:38:49.927701267 -0400
+++ openssl-0.9.8o/ssl/s3_enc.c	2010-09-22 15:26:59.463377483 -0400
@@ -554,6 +554,8 @@
 	int npad,n;
 	unsigned int i;
 	unsigned char md_buf[EVP_MAX_MD_SIZE];
+	char *tmp = NULL;
+	int t = 0;
 	EVP_MD_CTX ctx;
 
 	EVP_MD_CTX_init(&ctx);
@@ -563,20 +565,64 @@
 	n=EVP_MD_CTX_size(&ctx);
 	npad=(48/n)*n;
 
+	if(ctx.flags & EVP_MD_CTX_FLAG_ONESHOT) {
+	   tmp = OPENSSL_malloc(len + s->session->master_key_length + npad);
+	   if(tmp == NULL) return 0;
+	}
+
+	if(!tmp) {
 	if (sender != NULL)
 		EVP_DigestUpdate(&ctx,sender,len);
 	EVP_DigestUpdate(&ctx,s->session->master_key,
 		s->session->master_key_length);
 	EVP_DigestUpdate(&ctx,ssl3_pad_1,npad);
+	} else {
+		if(sender != NULL) {
+			memcpy(tmp, sender, len);
+			t = len;
+		}
+		memcpy(tmp + t, s->session->master_key,
+		       s->session->master_key_length);
+		t += s->session->master_key_length;
+
+		memcpy(tmp + t, ssl3_pad_1, npad);
+	}
 	EVP_DigestFinal_ex(&ctx,md_buf,&i);
 
+        if(tmp) {
+		OPENSSL_free(tmp);
+		tmp = NULL;
+	}
+
 	EVP_DigestInit_ex(&ctx,EVP_MD_CTX_md(&ctx), NULL);
+
+	if(ctx.flags & EVP_MD_CTX_FLAG_ONESHOT) {
+	   tmp = OPENSSL_malloc(s->session->master_key_length + npad + i);
+	   if(tmp == NULL) return 0;
+	}
+	   t = 0;
+	   if(!tmp) {
 	EVP_DigestUpdate(&ctx,s->session->master_key,
 		s->session->master_key_length);
 	EVP_DigestUpdate(&ctx,ssl3_pad_2,npad);
 	EVP_DigestUpdate(&ctx,md_buf,i);
+	   } else {
+		   memcpy(tmp, s->session->master_key,
+			  s->session->master_key_length);
+		   t = s->session->master_key_length;
+
+		   memcpy(tmp + t, ssl3_pad_2, npad);
+		   t += npad;
+
+		   memcpy(tmp + t, md_buf, i);
+	   }
 	EVP_DigestFinal_ex(&ctx,p,&ret);
 
+        if(tmp) {
+		OPENSSL_free(tmp);
+		tmp = NULL;
+	}
+
 	EVP_MD_CTX_cleanup(&ctx);
 
 	return((int)ret);
