patches/ibmca.patch-0.96e-2
author yippi
Mon, 27 Sep 2010 21:07:51 +0000
changeset 20108 51df67ca9307
parent 9397 b16e349d18c5
permissions -rw-r--r--
I had these modules listed as being owned by me, but they are really owned by wangke, correcting.
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
9397
b16e349d18c5 the easy part of the reorg (most files moved around)
laca
parents:
diff changeset
     1
diff -urN -x /home/sbade/dontdirr openssl-engine-0.9.6e.base/crypto/engine/Makefile openssl-engine-0.9.6e.patch/crypto/engine/Makefile
b16e349d18c5 the easy part of the reorg (most files moved around)
laca
parents:
diff changeset
     2
--- openssl-engine-0.9.6e.base/crypto/engine/Makefile	Thu Feb  7 23:04:30 2002
b16e349d18c5 the easy part of the reorg (most files moved around)
laca
parents:
diff changeset
     3
+++ openssl-engine-0.9.6e.patch/crypto/engine/Makefile	Fri Aug  2 14:37:08 2002
b16e349d18c5 the easy part of the reorg (most files moved around)
laca
parents:
diff changeset
     4
@@ -24,10 +24,10 @@
b16e349d18c5 the easy part of the reorg (most files moved around)
laca
parents:
diff changeset
     5
 LIB=$(TOP)/libcrypto.a
b16e349d18c5 the easy part of the reorg (most files moved around)
laca
parents:
diff changeset
     6
 LIBSRC= engine_err.c engine_lib.c engine_list.c engine_openssl.c \
b16e349d18c5 the easy part of the reorg (most files moved around)
laca
parents:
diff changeset
     7
 	hw_atalla.c hw_cswift.c hw_ncipher.c hw_aep.c hw_sureware.c \
b16e349d18c5 the easy part of the reorg (most files moved around)
laca
parents:
diff changeset
     8
-	hw_ubsec.c hw_keyclient.c
b16e349d18c5 the easy part of the reorg (most files moved around)
laca
parents:
diff changeset
     9
+	hw_ubsec.c hw_keyclient.c hw_ibmca.c
b16e349d18c5 the easy part of the reorg (most files moved around)
laca
parents:
diff changeset
    10
 LIBOBJ= engine_err.o engine_lib.o engine_list.o engine_openssl.o \
b16e349d18c5 the easy part of the reorg (most files moved around)
laca
parents:
diff changeset
    11
 	hw_atalla.o hw_cswift.o hw_ncipher.o hw_aep.o hw_sureware.o \
b16e349d18c5 the easy part of the reorg (most files moved around)
laca
parents:
diff changeset
    12
-	hw_ubsec.o hw_keyclient.o
b16e349d18c5 the easy part of the reorg (most files moved around)
laca
parents:
diff changeset
    13
+	hw_ubsec.o hw_keyclient.o hw_ibmca.o
b16e349d18c5 the easy part of the reorg (most files moved around)
laca
parents:
diff changeset
    14
 
b16e349d18c5 the easy part of the reorg (most files moved around)
laca
parents:
diff changeset
    15
 SRC= $(LIBSRC)
b16e349d18c5 the easy part of the reorg (most files moved around)
laca
parents:
diff changeset
    16
 
b16e349d18c5 the easy part of the reorg (most files moved around)
laca
parents:
diff changeset
    17
diff -urN -x /home/sbade/dontdirr openssl-engine-0.9.6e.base/crypto/engine/Makefile.ssl openssl-engine-0.9.6e.patch/crypto/engine/Makefile.ssl
b16e349d18c5 the easy part of the reorg (most files moved around)
laca
parents:
diff changeset
    18
--- openssl-engine-0.9.6e.base/crypto/engine/Makefile.ssl	Thu Feb  7 23:04:30 2002
b16e349d18c5 the easy part of the reorg (most files moved around)
laca
parents:
diff changeset
    19
+++ openssl-engine-0.9.6e.patch/crypto/engine/Makefile.ssl	Fri Aug  2 14:37:08 2002
b16e349d18c5 the easy part of the reorg (most files moved around)
laca
parents:
diff changeset
    20
@@ -24,10 +24,10 @@
b16e349d18c5 the easy part of the reorg (most files moved around)
laca
parents:
diff changeset
    21
 LIB=$(TOP)/libcrypto.a
b16e349d18c5 the easy part of the reorg (most files moved around)
laca
parents:
diff changeset
    22
 LIBSRC= engine_err.c engine_lib.c engine_list.c engine_openssl.c \
b16e349d18c5 the easy part of the reorg (most files moved around)
laca
parents:
diff changeset
    23
 	hw_atalla.c hw_cswift.c hw_ncipher.c hw_aep.c hw_sureware.c \
b16e349d18c5 the easy part of the reorg (most files moved around)
laca
parents:
diff changeset
    24
-	hw_ubsec.c hw_keyclient.c
b16e349d18c5 the easy part of the reorg (most files moved around)
laca
parents:
diff changeset
    25
+	hw_ubsec.c hw_keyclient.c hw_ibmca.c
b16e349d18c5 the easy part of the reorg (most files moved around)
laca
parents:
diff changeset
    26
 LIBOBJ= engine_err.o engine_lib.o engine_list.o engine_openssl.o \
b16e349d18c5 the easy part of the reorg (most files moved around)
laca
parents:
diff changeset
    27
 	hw_atalla.o hw_cswift.o hw_ncipher.o hw_aep.o hw_sureware.o \
b16e349d18c5 the easy part of the reorg (most files moved around)
laca
parents:
diff changeset
    28
-	hw_ubsec.o hw_keyclient.o
b16e349d18c5 the easy part of the reorg (most files moved around)
laca
parents:
diff changeset
    29
+	hw_ubsec.o hw_keyclient.o hw_ibmca.o
b16e349d18c5 the easy part of the reorg (most files moved around)
laca
parents:
diff changeset
    30
 
b16e349d18c5 the easy part of the reorg (most files moved around)
laca
parents:
diff changeset
    31
 SRC= $(LIBSRC)
b16e349d18c5 the easy part of the reorg (most files moved around)
laca
parents:
diff changeset
    32
 
b16e349d18c5 the easy part of the reorg (most files moved around)
laca
parents:
diff changeset
    33
diff -urN -x /home/sbade/dontdirr openssl-engine-0.9.6e.base/crypto/engine/engine.h openssl-engine-0.9.6e.patch/crypto/engine/engine.h
b16e349d18c5 the easy part of the reorg (most files moved around)
laca
parents:
diff changeset
    34
--- openssl-engine-0.9.6e.base/crypto/engine/engine.h	Thu Feb  7 23:04:29 2002
b16e349d18c5 the easy part of the reorg (most files moved around)
laca
parents:
diff changeset
    35
+++ openssl-engine-0.9.6e.patch/crypto/engine/engine.h	Fri Aug  2 14:37:08 2002
b16e349d18c5 the easy part of the reorg (most files moved around)
laca
parents:
diff changeset
    36
@@ -406,6 +406,13 @@
b16e349d18c5 the easy part of the reorg (most files moved around)
laca
parents:
diff changeset
    37
 #define ENGINE_F_UBSEC_RNG_BYTES			 172
b16e349d18c5 the easy part of the reorg (most files moved around)
laca
parents:
diff changeset
    38
 #define ENGINE_F_UBSEC_RSA_MOD_EXP			 168
b16e349d18c5 the easy part of the reorg (most files moved around)
laca
parents:
diff changeset
    39
 #define ENGINE_F_UBSEC_RSA_MOD_EXP_CRT			 169
b16e349d18c5 the easy part of the reorg (most files moved around)
laca
parents:
diff changeset
    40
+#define ENGINE_F_IBMCA_FINISH				 180
b16e349d18c5 the easy part of the reorg (most files moved around)
laca
parents:
diff changeset
    41
+#define ENGINE_F_IBMCA_INIT				 181
b16e349d18c5 the easy part of the reorg (most files moved around)
laca
parents:
diff changeset
    42
+#define ENGINE_F_IBMCA_MOD_EXP				 182
b16e349d18c5 the easy part of the reorg (most files moved around)
laca
parents:
diff changeset
    43
+#define ENGINE_F_IBMCA_MOD_EXP_CRT			 183
b16e349d18c5 the easy part of the reorg (most files moved around)
laca
parents:
diff changeset
    44
+#define ENGINE_F_IBMCA_RAND_BYTES			 184
b16e349d18c5 the easy part of the reorg (most files moved around)
laca
parents:
diff changeset
    45
+#define ENGINE_F_IBMCA_RSA_MOD_EXP			 185
b16e349d18c5 the easy part of the reorg (most files moved around)
laca
parents:
diff changeset
    46
+
b16e349d18c5 the easy part of the reorg (most files moved around)
laca
parents:
diff changeset
    47
 
b16e349d18c5 the easy part of the reorg (most files moved around)
laca
parents:
diff changeset
    48
 /* Reason codes. */
b16e349d18c5 the easy part of the reorg (most files moved around)
laca
parents:
diff changeset
    49
 #define ENGINE_R_AEP_INIT_FAILURE			 132
b16e349d18c5 the easy part of the reorg (most files moved around)
laca
parents:
diff changeset
    50
diff -urN -x /home/sbade/dontdirr openssl-engine-0.9.6e.base/crypto/engine/engine_err.c openssl-engine-0.9.6e.patch/crypto/engine/engine_err.c
b16e349d18c5 the easy part of the reorg (most files moved around)
laca
parents:
diff changeset
    51
--- openssl-engine-0.9.6e.base/crypto/engine/engine_err.c	Thu Feb  7 23:04:27 2002
b16e349d18c5 the easy part of the reorg (most files moved around)
laca
parents:
diff changeset
    52
+++ openssl-engine-0.9.6e.patch/crypto/engine/engine_err.c	Fri Aug  2 14:37:08 2002
b16e349d18c5 the easy part of the reorg (most files moved around)
laca
parents:
diff changeset
    53
@@ -177,6 +177,12 @@
b16e349d18c5 the easy part of the reorg (most files moved around)
laca
parents:
diff changeset
    54
 {ERR_PACK(0,ENGINE_F_UBSEC_RNG_BYTES,0),	"UBSEC_RNG_BYTES"},
b16e349d18c5 the easy part of the reorg (most files moved around)
laca
parents:
diff changeset
    55
 {ERR_PACK(0,ENGINE_F_UBSEC_RSA_MOD_EXP,0),	"UBSEC_RSA_MOD_EXP"},
b16e349d18c5 the easy part of the reorg (most files moved around)
laca
parents:
diff changeset
    56
 {ERR_PACK(0,ENGINE_F_UBSEC_RSA_MOD_EXP_CRT,0),	"UBSEC_RSA_MOD_EXP_CRT"},
b16e349d18c5 the easy part of the reorg (most files moved around)
laca
parents:
diff changeset
    57
+{ERR_PACK(0,ENGINE_F_IBMCA_FINISH,0), "IBMCA_FINISH"},
b16e349d18c5 the easy part of the reorg (most files moved around)
laca
parents:
diff changeset
    58
+{ERR_PACK(0,ENGINE_F_IBMCA_INIT,0),   "IBMCA_INIT"},
b16e349d18c5 the easy part of the reorg (most files moved around)
laca
parents:
diff changeset
    59
+{ERR_PACK(0,ENGINE_F_IBMCA_MOD_EXP,0),        "IBMCA_MOD_EXP"},
b16e349d18c5 the easy part of the reorg (most files moved around)
laca
parents:
diff changeset
    60
+{ERR_PACK(0,ENGINE_F_IBMCA_MOD_EXP_CRT,0),    "IBMCA_MOD_EXP_CRT"},
b16e349d18c5 the easy part of the reorg (most files moved around)
laca
parents:
diff changeset
    61
+{ERR_PACK(0,ENGINE_F_IBMCA_RAND_BYTES,0),     "IBMCA_RAND_BYTES"},
b16e349d18c5 the easy part of the reorg (most files moved around)
laca
parents:
diff changeset
    62
+{ERR_PACK(0,ENGINE_F_IBMCA_RSA_MOD_EXP,0),    "IBMCA_RSA_MOD_EXP"},
b16e349d18c5 the easy part of the reorg (most files moved around)
laca
parents:
diff changeset
    63
 {0,NULL}
b16e349d18c5 the easy part of the reorg (most files moved around)
laca
parents:
diff changeset
    64
 	};
b16e349d18c5 the easy part of the reorg (most files moved around)
laca
parents:
diff changeset
    65
 
b16e349d18c5 the easy part of the reorg (most files moved around)
laca
parents:
diff changeset
    66
diff -urN -x /home/sbade/dontdirr openssl-engine-0.9.6e.base/crypto/engine/engine_int.h openssl-engine-0.9.6e.patch/crypto/engine/engine_int.h
b16e349d18c5 the easy part of the reorg (most files moved around)
laca
parents:
diff changeset
    67
--- openssl-engine-0.9.6e.base/crypto/engine/engine_int.h	Sat Nov 17 06:28:05 2001
b16e349d18c5 the easy part of the reorg (most files moved around)
laca
parents:
diff changeset
    68
+++ openssl-engine-0.9.6e.patch/crypto/engine/engine_int.h	Fri Aug  2 14:37:08 2002
b16e349d18c5 the easy part of the reorg (most files moved around)
laca
parents:
diff changeset
    69
@@ -151,6 +151,11 @@
b16e349d18c5 the easy part of the reorg (most files moved around)
laca
parents:
diff changeset
    70
 ENGINE *ENGINE_atalla();
b16e349d18c5 the easy part of the reorg (most files moved around)
laca
parents:
diff changeset
    71
 #endif /* !NO_HW_ATALLA */
b16e349d18c5 the easy part of the reorg (most files moved around)
laca
parents:
diff changeset
    72
 
b16e349d18c5 the easy part of the reorg (most files moved around)
laca
parents:
diff changeset
    73
+#ifndef NO_HW_IBMCA
b16e349d18c5 the easy part of the reorg (most files moved around)
laca
parents:
diff changeset
    74
+/* Returns a structure of ibmca methods. */
b16e349d18c5 the easy part of the reorg (most files moved around)
laca
parents:
diff changeset
    75
+ENGINE *ENGINE_ibmca();
b16e349d18c5 the easy part of the reorg (most files moved around)
laca
parents:
diff changeset
    76
+#endif /* !NO_HW_IBMCA */
b16e349d18c5 the easy part of the reorg (most files moved around)
laca
parents:
diff changeset
    77
+
b16e349d18c5 the easy part of the reorg (most files moved around)
laca
parents:
diff changeset
    78
 #ifndef NO_HW_AEP
b16e349d18c5 the easy part of the reorg (most files moved around)
laca
parents:
diff changeset
    79
 /* Returns a structure of AEP methods. */
b16e349d18c5 the easy part of the reorg (most files moved around)
laca
parents:
diff changeset
    80
 ENGINE *ENGINE_aep();
b16e349d18c5 the easy part of the reorg (most files moved around)
laca
parents:
diff changeset
    81
diff -urN -x /home/sbade/dontdirr openssl-engine-0.9.6e.base/crypto/engine/engine_list.c openssl-engine-0.9.6e.patch/crypto/engine/engine_list.c
b16e349d18c5 the easy part of the reorg (most files moved around)
laca
parents:
diff changeset
    82
--- openssl-engine-0.9.6e.base/crypto/engine/engine_list.c	Sat Nov 17 06:28:07 2001
b16e349d18c5 the easy part of the reorg (most files moved around)
laca
parents:
diff changeset
    83
+++ openssl-engine-0.9.6e.patch/crypto/engine/engine_list.c	Fri Aug  2 14:37:08 2002
b16e349d18c5 the easy part of the reorg (most files moved around)
laca
parents:
diff changeset
    84
@@ -215,6 +215,10 @@
b16e349d18c5 the easy part of the reorg (most files moved around)
laca
parents:
diff changeset
    85
 		return 0;
b16e349d18c5 the easy part of the reorg (most files moved around)
laca
parents:
diff changeset
    86
 #endif /* !NO_HW_KEYCLIENT */
b16e349d18c5 the easy part of the reorg (most files moved around)
laca
parents:
diff changeset
    87
 #endif /* !NO_HW */
b16e349d18c5 the easy part of the reorg (most files moved around)
laca
parents:
diff changeset
    88
+#ifndef NO_HW_IBMCA
b16e349d18c5 the easy part of the reorg (most files moved around)
laca
parents:
diff changeset
    89
+	if(!engine_list_add(ENGINE_ibmca()))
b16e349d18c5 the easy part of the reorg (most files moved around)
laca
parents:
diff changeset
    90
+		return 0;
b16e349d18c5 the easy part of the reorg (most files moved around)
laca
parents:
diff changeset
    91
+#endif /* !NO_HW_IBMCA */
b16e349d18c5 the easy part of the reorg (most files moved around)
laca
parents:
diff changeset
    92
 	engine_list_flag = 1;
b16e349d18c5 the easy part of the reorg (most files moved around)
laca
parents:
diff changeset
    93
 	return 1;
b16e349d18c5 the easy part of the reorg (most files moved around)
laca
parents:
diff changeset
    94
 	}
b16e349d18c5 the easy part of the reorg (most files moved around)
laca
parents:
diff changeset
    95
diff -urN -x /home/sbade/dontdirr openssl-engine-0.9.6e.base/crypto/engine/hw_ibmca.c openssl-engine-0.9.6e.patch/crypto/engine/hw_ibmca.c
b16e349d18c5 the easy part of the reorg (most files moved around)
laca
parents:
diff changeset
    96
--- openssl-engine-0.9.6e.base/crypto/engine/hw_ibmca.c	Thu Jan  1 01:00:00 1970
b16e349d18c5 the easy part of the reorg (most files moved around)
laca
parents:
diff changeset
    97
+++ openssl-engine-0.9.6e.patch/crypto/engine/hw_ibmca.c	Fri Aug  2 14:38:02 2002
b16e349d18c5 the easy part of the reorg (most files moved around)
laca
parents:
diff changeset
    98
@@ -0,0 +1,814 @@
b16e349d18c5 the easy part of the reorg (most files moved around)
laca
parents:
diff changeset
    99
+/* crypto/engine/hw_ibmca.c */
b16e349d18c5 the easy part of the reorg (most files moved around)
laca
parents:
diff changeset
   100
+/* Written by Geoff Thorpe ([email protected]) for the OpenSSL
b16e349d18c5 the easy part of the reorg (most files moved around)
laca
parents:
diff changeset
   101
+ * project 2000.
b16e349d18c5 the easy part of the reorg (most files moved around)
laca
parents:
diff changeset
   102
+ */
b16e349d18c5 the easy part of the reorg (most files moved around)
laca
parents:
diff changeset
   103
+/* ====================================================================
b16e349d18c5 the easy part of the reorg (most files moved around)
laca
parents:
diff changeset
   104
+ * Copyright (c) 1999 The OpenSSL Project.  All rights reserved.
b16e349d18c5 the easy part of the reorg (most files moved around)
laca
parents:
diff changeset
   105
+ *
b16e349d18c5 the easy part of the reorg (most files moved around)
laca
parents:
diff changeset
   106
+ * Redistribution and use in source and binary forms, with or without
b16e349d18c5 the easy part of the reorg (most files moved around)
laca
parents:
diff changeset
   107
+ * modification, are permitted provided that the following conditions
b16e349d18c5 the easy part of the reorg (most files moved around)
laca
parents:
diff changeset
   108
+ * are met:
b16e349d18c5 the easy part of the reorg (most files moved around)
laca
parents:
diff changeset
   109
+ *
b16e349d18c5 the easy part of the reorg (most files moved around)
laca
parents:
diff changeset
   110
+ * 1. Redistributions of source code must retain the above copyright
b16e349d18c5 the easy part of the reorg (most files moved around)
laca
parents:
diff changeset
   111
+ *    notice, this list of conditions and the following disclaimer.
b16e349d18c5 the easy part of the reorg (most files moved around)
laca
parents:
diff changeset
   112
+ *
b16e349d18c5 the easy part of the reorg (most files moved around)
laca
parents:
diff changeset
   113
+ * 2. Redistributions in binary form must reproduce the above copyright
b16e349d18c5 the easy part of the reorg (most files moved around)
laca
parents:
diff changeset
   114
+ *    notice, this list of conditions and the following disclaimer in
b16e349d18c5 the easy part of the reorg (most files moved around)
laca
parents:
diff changeset
   115
+ *    the documentation and/or other materials provided with the
b16e349d18c5 the easy part of the reorg (most files moved around)
laca
parents:
diff changeset
   116
+ *    distribution.
b16e349d18c5 the easy part of the reorg (most files moved around)
laca
parents:
diff changeset
   117
+ *
b16e349d18c5 the easy part of the reorg (most files moved around)
laca
parents:
diff changeset
   118
+ * 3. All advertising materials mentioning features or use of this
b16e349d18c5 the easy part of the reorg (most files moved around)
laca
parents:
diff changeset
   119
+ *    software must display the following acknowledgment:
b16e349d18c5 the easy part of the reorg (most files moved around)
laca
parents:
diff changeset
   120
+ *    "This product includes software developed by the OpenSSL Project
b16e349d18c5 the easy part of the reorg (most files moved around)
laca
parents:
diff changeset
   121
+ *    for use in the OpenSSL Toolkit. (http://www.OpenSSL.org/)"
b16e349d18c5 the easy part of the reorg (most files moved around)
laca
parents:
diff changeset
   122
+ *
b16e349d18c5 the easy part of the reorg (most files moved around)
laca
parents:
diff changeset
   123
+ * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
b16e349d18c5 the easy part of the reorg (most files moved around)
laca
parents:
diff changeset
   124
+ *    endorse or promote products derived from this software without
b16e349d18c5 the easy part of the reorg (most files moved around)
laca
parents:
diff changeset
   125
+ *    prior written permission. For written permission, please contact
b16e349d18c5 the easy part of the reorg (most files moved around)
laca
parents:
diff changeset
   126
+ *    [email protected].
b16e349d18c5 the easy part of the reorg (most files moved around)
laca
parents:
diff changeset
   127
+ *
b16e349d18c5 the easy part of the reorg (most files moved around)
laca
parents:
diff changeset
   128
+ * 5. Products derived from this software may not be called "OpenSSL"
b16e349d18c5 the easy part of the reorg (most files moved around)
laca
parents:
diff changeset
   129
+ *    nor may "OpenSSL" appear in their names without prior written
b16e349d18c5 the easy part of the reorg (most files moved around)
laca
parents:
diff changeset
   130
+ *    permission of the OpenSSL Project.
b16e349d18c5 the easy part of the reorg (most files moved around)
laca
parents:
diff changeset
   131
+ *
b16e349d18c5 the easy part of the reorg (most files moved around)
laca
parents:
diff changeset
   132
+ * 6. Redistributions of any form whatsoever must retain the following
b16e349d18c5 the easy part of the reorg (most files moved around)
laca
parents:
diff changeset
   133
+ *    acknowledgment:
b16e349d18c5 the easy part of the reorg (most files moved around)
laca
parents:
diff changeset
   134
+ *    "This product includes software developed by the OpenSSL Project
b16e349d18c5 the easy part of the reorg (most files moved around)
laca
parents:
diff changeset
   135
+ *    for use in the OpenSSL Toolkit (http://www.OpenSSL.org/)"
b16e349d18c5 the easy part of the reorg (most files moved around)
laca
parents:
diff changeset
   136
+ *
b16e349d18c5 the easy part of the reorg (most files moved around)
laca
parents:
diff changeset
   137
+ * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
b16e349d18c5 the easy part of the reorg (most files moved around)
laca
parents:
diff changeset
   138
+ * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
b16e349d18c5 the easy part of the reorg (most files moved around)
laca
parents:
diff changeset
   139
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
b16e349d18c5 the easy part of the reorg (most files moved around)
laca
parents:
diff changeset
   140
+ * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE OpenSSL PROJECT OR
b16e349d18c5 the easy part of the reorg (most files moved around)
laca
parents:
diff changeset
   141
+ * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
b16e349d18c5 the easy part of the reorg (most files moved around)
laca
parents:
diff changeset
   142
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
b16e349d18c5 the easy part of the reorg (most files moved around)
laca
parents:
diff changeset
   143
+ * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
b16e349d18c5 the easy part of the reorg (most files moved around)
laca
parents:
diff changeset
   144
+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
b16e349d18c5 the easy part of the reorg (most files moved around)
laca
parents:
diff changeset
   145
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
b16e349d18c5 the easy part of the reorg (most files moved around)
laca
parents:
diff changeset
   146
+ * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
b16e349d18c5 the easy part of the reorg (most files moved around)
laca
parents:
diff changeset
   147
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
b16e349d18c5 the easy part of the reorg (most files moved around)
laca
parents:
diff changeset
   148
+ * OF THE POSSIBILITY OF SUCH DAMAGE.
b16e349d18c5 the easy part of the reorg (most files moved around)
laca
parents:
diff changeset
   149
+ * ====================================================================
b16e349d18c5 the easy part of the reorg (most files moved around)
laca
parents:
diff changeset
   150
+ *
b16e349d18c5 the easy part of the reorg (most files moved around)
laca
parents:
diff changeset
   151
+ * This product includes cryptographic software written by Eric Young
b16e349d18c5 the easy part of the reorg (most files moved around)
laca
parents:
diff changeset
   152
+ * ([email protected]).  This product includes software written by Tim
b16e349d18c5 the easy part of the reorg (most files moved around)
laca
parents:
diff changeset
   153
+ * Hudson ([email protected]).
b16e349d18c5 the easy part of the reorg (most files moved around)
laca
parents:
diff changeset
   154
+ *
b16e349d18c5 the easy part of the reorg (most files moved around)
laca
parents:
diff changeset
   155
+ */
b16e349d18c5 the easy part of the reorg (most files moved around)
laca
parents:
diff changeset
   156
+
b16e349d18c5 the easy part of the reorg (most files moved around)
laca
parents:
diff changeset
   157
+/* (C) COPYRIGHT International Business Machines Corp. 2001 */
b16e349d18c5 the easy part of the reorg (most files moved around)
laca
parents:
diff changeset
   158
+
b16e349d18c5 the easy part of the reorg (most files moved around)
laca
parents:
diff changeset
   159
+#include <stdio.h>
b16e349d18c5 the easy part of the reorg (most files moved around)
laca
parents:
diff changeset
   160
+#include <openssl/crypto.h>
b16e349d18c5 the easy part of the reorg (most files moved around)
laca
parents:
diff changeset
   161
+#include "cryptlib.h"
b16e349d18c5 the easy part of the reorg (most files moved around)
laca
parents:
diff changeset
   162
+#include <openssl/dso.h>
b16e349d18c5 the easy part of the reorg (most files moved around)
laca
parents:
diff changeset
   163
+#include "engine_int.h"
b16e349d18c5 the easy part of the reorg (most files moved around)
laca
parents:
diff changeset
   164
+#include <openssl/engine.h>
b16e349d18c5 the easy part of the reorg (most files moved around)
laca
parents:
diff changeset
   165
+
b16e349d18c5 the easy part of the reorg (most files moved around)
laca
parents:
diff changeset
   166
+#ifndef NO_HW
b16e349d18c5 the easy part of the reorg (most files moved around)
laca
parents:
diff changeset
   167
+#ifndef NO_HW_IBMCA
b16e349d18c5 the easy part of the reorg (most files moved around)
laca
parents:
diff changeset
   168
+
b16e349d18c5 the easy part of the reorg (most files moved around)
laca
parents:
diff changeset
   169
+#ifdef FLAT_INC
b16e349d18c5 the easy part of the reorg (most files moved around)
laca
parents:
diff changeset
   170
+#include "ica_openssl_api.h"
b16e349d18c5 the easy part of the reorg (most files moved around)
laca
parents:
diff changeset
   171
+#else
b16e349d18c5 the easy part of the reorg (most files moved around)
laca
parents:
diff changeset
   172
+#include "vendor_defns/ica_openssl_api.h"
b16e349d18c5 the easy part of the reorg (most files moved around)
laca
parents:
diff changeset
   173
+#endif
b16e349d18c5 the easy part of the reorg (most files moved around)
laca
parents:
diff changeset
   174
+
b16e349d18c5 the easy part of the reorg (most files moved around)
laca
parents:
diff changeset
   175
+static const char *IBMCA_F1 = "icaOpenAdapter";
b16e349d18c5 the easy part of the reorg (most files moved around)
laca
parents:
diff changeset
   176
+static const char *IBMCA_F2 = "icaCloseAdapter";
b16e349d18c5 the easy part of the reorg (most files moved around)
laca
parents:
diff changeset
   177
+static const char *IBMCA_F3 = "icaRsaModExpo";
b16e349d18c5 the easy part of the reorg (most files moved around)
laca
parents:
diff changeset
   178
+static const char *IBMCA_F4 = "icaRandomNumberGenerate";
b16e349d18c5 the easy part of the reorg (most files moved around)
laca
parents:
diff changeset
   179
+static const char *IBMCA_F5 = "icaRsaCrt";
b16e349d18c5 the easy part of the reorg (most files moved around)
laca
parents:
diff changeset
   180
+
b16e349d18c5 the easy part of the reorg (most files moved around)
laca
parents:
diff changeset
   181
+ICA_ADAPTER_HANDLE handle=0;
b16e349d18c5 the easy part of the reorg (most files moved around)
laca
parents:
diff changeset
   182
+
b16e349d18c5 the easy part of the reorg (most files moved around)
laca
parents:
diff changeset
   183
+static int ibmca_init(void);
b16e349d18c5 the easy part of the reorg (most files moved around)
laca
parents:
diff changeset
   184
+static int ibmca_finish(void);
b16e349d18c5 the easy part of the reorg (most files moved around)
laca
parents:
diff changeset
   185
+
b16e349d18c5 the easy part of the reorg (most files moved around)
laca
parents:
diff changeset
   186
+/* BIGNUM stuff */
b16e349d18c5 the easy part of the reorg (most files moved around)
laca
parents:
diff changeset
   187
+static int ibmca_mod_exp(BIGNUM *r, BIGNUM *a, const BIGNUM *p,
b16e349d18c5 the easy part of the reorg (most files moved around)
laca
parents:
diff changeset
   188
+        const BIGNUM *m, BN_CTX *ctx);
b16e349d18c5 the easy part of the reorg (most files moved around)
laca
parents:
diff changeset
   189
+
b16e349d18c5 the easy part of the reorg (most files moved around)
laca
parents:
diff changeset
   190
+static int ibmca_mod_exp_crt(BIGNUM *r, BIGNUM *a, const BIGNUM *p,
b16e349d18c5 the easy part of the reorg (most files moved around)
laca
parents:
diff changeset
   191
+        const BIGNUM *q, const BIGNUM *dmp1, const BIGNUM *dmq1,
b16e349d18c5 the easy part of the reorg (most files moved around)
laca
parents:
diff changeset
   192
+        const BIGNUM *iqmp, BN_CTX *ctx);
b16e349d18c5 the easy part of the reorg (most files moved around)
laca
parents:
diff changeset
   193
+
b16e349d18c5 the easy part of the reorg (most files moved around)
laca
parents:
diff changeset
   194
+/* RSA stuff */
b16e349d18c5 the easy part of the reorg (most files moved around)
laca
parents:
diff changeset
   195
+static int ibmca_rsa_mod_exp(BIGNUM *r0, BIGNUM *I, RSA *rsa);
b16e349d18c5 the easy part of the reorg (most files moved around)
laca
parents:
diff changeset
   196
+/* This function is aliased to mod_exp (with the mont stuff dropped). */
b16e349d18c5 the easy part of the reorg (most files moved around)
laca
parents:
diff changeset
   197
+static int ibmca_mod_exp_mont(BIGNUM *r, BIGNUM *a, const BIGNUM *p,
b16e349d18c5 the easy part of the reorg (most files moved around)
laca
parents:
diff changeset
   198
+        const BIGNUM *m, BN_CTX *ctx, BN_MONT_CTX *m_ctx);
b16e349d18c5 the easy part of the reorg (most files moved around)
laca
parents:
diff changeset
   199
+
b16e349d18c5 the easy part of the reorg (most files moved around)
laca
parents:
diff changeset
   200
+/* DSA stuff */
b16e349d18c5 the easy part of the reorg (most files moved around)
laca
parents:
diff changeset
   201
+static int ibmca_dsa_mod_exp(DSA *dsa, BIGNUM *rr, BIGNUM *a1,
b16e349d18c5 the easy part of the reorg (most files moved around)
laca
parents:
diff changeset
   202
+        BIGNUM *p1, BIGNUM *a2, BIGNUM *p2, BIGNUM *m,
b16e349d18c5 the easy part of the reorg (most files moved around)
laca
parents:
diff changeset
   203
+        BN_CTX *ctx, BN_MONT_CTX *in_mont);
b16e349d18c5 the easy part of the reorg (most files moved around)
laca
parents:
diff changeset
   204
+static int ibmca_mod_exp_dsa(DSA *dsa, BIGNUM *r, BIGNUM *a,
b16e349d18c5 the easy part of the reorg (most files moved around)
laca
parents:
diff changeset
   205
+        const BIGNUM *p, const BIGNUM *m, BN_CTX *ctx,
b16e349d18c5 the easy part of the reorg (most files moved around)
laca
parents:
diff changeset
   206
+        BN_MONT_CTX *m_ctx);
b16e349d18c5 the easy part of the reorg (most files moved around)
laca
parents:
diff changeset
   207
+
b16e349d18c5 the easy part of the reorg (most files moved around)
laca
parents:
diff changeset
   208
+/* DH stuff */
b16e349d18c5 the easy part of the reorg (most files moved around)
laca
parents:
diff changeset
   209
+/* This function is alised to mod_exp (with the DH and mont dropped). */
b16e349d18c5 the easy part of the reorg (most files moved around)
laca
parents:
diff changeset
   210
+static int ibmca_mod_exp_dh(DH *dh, BIGNUM *r, BIGNUM *a, const BIGNUM *p,
b16e349d18c5 the easy part of the reorg (most files moved around)
laca
parents:
diff changeset
   211
+        const BIGNUM *m, BN_CTX *ctx, BN_MONT_CTX *m_ctx);
b16e349d18c5 the easy part of the reorg (most files moved around)
laca
parents:
diff changeset
   212
+
b16e349d18c5 the easy part of the reorg (most files moved around)
laca
parents:
diff changeset
   213
+/* RAND stuff */
b16e349d18c5 the easy part of the reorg (most files moved around)
laca
parents:
diff changeset
   214
+static int ibmca_rand_bytes(unsigned char *buf, int num);
b16e349d18c5 the easy part of the reorg (most files moved around)
laca
parents:
diff changeset
   215
+static int ibmca_rand_status(void);
b16e349d18c5 the easy part of the reorg (most files moved around)
laca
parents:
diff changeset
   216
+
b16e349d18c5 the easy part of the reorg (most files moved around)
laca
parents:
diff changeset
   217
+/* Our internal RSA_METHOD that we provide pointers to */
b16e349d18c5 the easy part of the reorg (most files moved around)
laca
parents:
diff changeset
   218
+static RSA_METHOD ibmca_rsa =
b16e349d18c5 the easy part of the reorg (most files moved around)
laca
parents:
diff changeset
   219
+        {
b16e349d18c5 the easy part of the reorg (most files moved around)
laca
parents:
diff changeset
   220
+        "Ibmca RSA method",
b16e349d18c5 the easy part of the reorg (most files moved around)
laca
parents:
diff changeset
   221
+        NULL,
b16e349d18c5 the easy part of the reorg (most files moved around)
laca
parents:
diff changeset
   222
+        NULL,
b16e349d18c5 the easy part of the reorg (most files moved around)
laca
parents:
diff changeset
   223
+        NULL,
b16e349d18c5 the easy part of the reorg (most files moved around)
laca
parents:
diff changeset
   224
+        NULL,
b16e349d18c5 the easy part of the reorg (most files moved around)
laca
parents:
diff changeset
   225
+        ibmca_rsa_mod_exp,
b16e349d18c5 the easy part of the reorg (most files moved around)
laca
parents:
diff changeset
   226
+        ibmca_mod_exp_mont,
b16e349d18c5 the easy part of the reorg (most files moved around)
laca
parents:
diff changeset
   227
+        NULL,
b16e349d18c5 the easy part of the reorg (most files moved around)
laca
parents:
diff changeset
   228
+        NULL,
b16e349d18c5 the easy part of the reorg (most files moved around)
laca
parents:
diff changeset
   229
+        0,
b16e349d18c5 the easy part of the reorg (most files moved around)
laca
parents:
diff changeset
   230
+        NULL,
b16e349d18c5 the easy part of the reorg (most files moved around)
laca
parents:
diff changeset
   231
+        NULL,
b16e349d18c5 the easy part of the reorg (most files moved around)
laca
parents:
diff changeset
   232
+        NULL
b16e349d18c5 the easy part of the reorg (most files moved around)
laca
parents:
diff changeset
   233
+        };
b16e349d18c5 the easy part of the reorg (most files moved around)
laca
parents:
diff changeset
   234
+
b16e349d18c5 the easy part of the reorg (most files moved around)
laca
parents:
diff changeset
   235
+/* Our internal DSA_METHOD that we provide pointers to */
b16e349d18c5 the easy part of the reorg (most files moved around)
laca
parents:
diff changeset
   236
+static DSA_METHOD ibmca_dsa =
b16e349d18c5 the easy part of the reorg (most files moved around)
laca
parents:
diff changeset
   237
+        {
b16e349d18c5 the easy part of the reorg (most files moved around)
laca
parents:
diff changeset
   238
+        "Ibmca DSA method",
b16e349d18c5 the easy part of the reorg (most files moved around)
laca
parents:
diff changeset
   239
+        NULL, /* dsa_do_sign */
b16e349d18c5 the easy part of the reorg (most files moved around)
laca
parents:
diff changeset
   240
+        NULL, /* dsa_sign_setup */
b16e349d18c5 the easy part of the reorg (most files moved around)
laca
parents:
diff changeset
   241
+        NULL, /* dsa_do_verify */
b16e349d18c5 the easy part of the reorg (most files moved around)
laca
parents:
diff changeset
   242
+        ibmca_dsa_mod_exp, /* dsa_mod_exp */
b16e349d18c5 the easy part of the reorg (most files moved around)
laca
parents:
diff changeset
   243
+        ibmca_mod_exp_dsa, /* bn_mod_exp */
b16e349d18c5 the easy part of the reorg (most files moved around)
laca
parents:
diff changeset
   244
+        NULL, /* init */
b16e349d18c5 the easy part of the reorg (most files moved around)
laca
parents:
diff changeset
   245
+        NULL, /* finish */
b16e349d18c5 the easy part of the reorg (most files moved around)
laca
parents:
diff changeset
   246
+        0, /* flags */
b16e349d18c5 the easy part of the reorg (most files moved around)
laca
parents:
diff changeset
   247
+        NULL /* app_data */
b16e349d18c5 the easy part of the reorg (most files moved around)
laca
parents:
diff changeset
   248
+        };
b16e349d18c5 the easy part of the reorg (most files moved around)
laca
parents:
diff changeset
   249
+
b16e349d18c5 the easy part of the reorg (most files moved around)
laca
parents:
diff changeset
   250
+/* Our internal DH_METHOD that we provide pointers to */
b16e349d18c5 the easy part of the reorg (most files moved around)
laca
parents:
diff changeset
   251
+static DH_METHOD ibmca_dh =
b16e349d18c5 the easy part of the reorg (most files moved around)
laca
parents:
diff changeset
   252
+        {
b16e349d18c5 the easy part of the reorg (most files moved around)
laca
parents:
diff changeset
   253
+        "Ibmca DH method",
b16e349d18c5 the easy part of the reorg (most files moved around)
laca
parents:
diff changeset
   254
+        NULL,
b16e349d18c5 the easy part of the reorg (most files moved around)
laca
parents:
diff changeset
   255
+        NULL,
b16e349d18c5 the easy part of the reorg (most files moved around)
laca
parents:
diff changeset
   256
+        ibmca_mod_exp_dh,
b16e349d18c5 the easy part of the reorg (most files moved around)
laca
parents:
diff changeset
   257
+        NULL,
b16e349d18c5 the easy part of the reorg (most files moved around)
laca
parents:
diff changeset
   258
+        NULL,
b16e349d18c5 the easy part of the reorg (most files moved around)
laca
parents:
diff changeset
   259
+        0,
b16e349d18c5 the easy part of the reorg (most files moved around)
laca
parents:
diff changeset
   260
+        NULL
b16e349d18c5 the easy part of the reorg (most files moved around)
laca
parents:
diff changeset
   261
+        };
b16e349d18c5 the easy part of the reorg (most files moved around)
laca
parents:
diff changeset
   262
+
b16e349d18c5 the easy part of the reorg (most files moved around)
laca
parents:
diff changeset
   263
+static RAND_METHOD ibmca_rand =
b16e349d18c5 the easy part of the reorg (most files moved around)
laca
parents:
diff changeset
   264
+        {
b16e349d18c5 the easy part of the reorg (most files moved around)
laca
parents:
diff changeset
   265
+        /* "IBMCA RAND method", */
b16e349d18c5 the easy part of the reorg (most files moved around)
laca
parents:
diff changeset
   266
+        NULL,
b16e349d18c5 the easy part of the reorg (most files moved around)
laca
parents:
diff changeset
   267
+        ibmca_rand_bytes,
b16e349d18c5 the easy part of the reorg (most files moved around)
laca
parents:
diff changeset
   268
+        NULL,
b16e349d18c5 the easy part of the reorg (most files moved around)
laca
parents:
diff changeset
   269
+        NULL,
b16e349d18c5 the easy part of the reorg (most files moved around)
laca
parents:
diff changeset
   270
+        ibmca_rand_bytes,
b16e349d18c5 the easy part of the reorg (most files moved around)
laca
parents:
diff changeset
   271
+        ibmca_rand_status,
b16e349d18c5 the easy part of the reorg (most files moved around)
laca
parents:
diff changeset
   272
+        };
b16e349d18c5 the easy part of the reorg (most files moved around)
laca
parents:
diff changeset
   273
+
b16e349d18c5 the easy part of the reorg (most files moved around)
laca
parents:
diff changeset
   274
+/* Our ENGINE structure. */
b16e349d18c5 the easy part of the reorg (most files moved around)
laca
parents:
diff changeset
   275
+static ENGINE engine_ibmca =
b16e349d18c5 the easy part of the reorg (most files moved around)
laca
parents:
diff changeset
   276
+        {
b16e349d18c5 the easy part of the reorg (most files moved around)
laca
parents:
diff changeset
   277
+        "ibmca",
b16e349d18c5 the easy part of the reorg (most files moved around)
laca
parents:
diff changeset
   278
+        "Ibmca hardware engine support",
b16e349d18c5 the easy part of the reorg (most files moved around)
laca
parents:
diff changeset
   279
+        &ibmca_rsa,
b16e349d18c5 the easy part of the reorg (most files moved around)
laca
parents:
diff changeset
   280
+        &ibmca_dsa,
b16e349d18c5 the easy part of the reorg (most files moved around)
laca
parents:
diff changeset
   281
+        &ibmca_dh,
b16e349d18c5 the easy part of the reorg (most files moved around)
laca
parents:
diff changeset
   282
+        &ibmca_rand,
b16e349d18c5 the easy part of the reorg (most files moved around)
laca
parents:
diff changeset
   283
+        ibmca_mod_exp,
b16e349d18c5 the easy part of the reorg (most files moved around)
laca
parents:
diff changeset
   284
+        NULL,
b16e349d18c5 the easy part of the reorg (most files moved around)
laca
parents:
diff changeset
   285
+        ibmca_init,
b16e349d18c5 the easy part of the reorg (most files moved around)
laca
parents:
diff changeset
   286
+        ibmca_finish,
b16e349d18c5 the easy part of the reorg (most files moved around)
laca
parents:
diff changeset
   287
+        NULL, /* no ctrl() */
b16e349d18c5 the easy part of the reorg (most files moved around)
laca
parents:
diff changeset
   288
+        NULL, /* no load_privkey() */
b16e349d18c5 the easy part of the reorg (most files moved around)
laca
parents:
diff changeset
   289
+        NULL, /* no load_pubkey() */
b16e349d18c5 the easy part of the reorg (most files moved around)
laca
parents:
diff changeset
   290
+        0, /* no flags */
b16e349d18c5 the easy part of the reorg (most files moved around)
laca
parents:
diff changeset
   291
+        0, 0, /* no references */
b16e349d18c5 the easy part of the reorg (most files moved around)
laca
parents:
diff changeset
   292
+        NULL, NULL /* unlinked */
b16e349d18c5 the easy part of the reorg (most files moved around)
laca
parents:
diff changeset
   293
+        };
b16e349d18c5 the easy part of the reorg (most files moved around)
laca
parents:
diff changeset
   294
+
b16e349d18c5 the easy part of the reorg (most files moved around)
laca
parents:
diff changeset
   295
+/* As this is only ever called once, there's no need for locking
b16e349d18c5 the easy part of the reorg (most files moved around)
laca
parents:
diff changeset
   296
+ * (indeed - the lock will already be held by our caller!!!) */
b16e349d18c5 the easy part of the reorg (most files moved around)
laca
parents:
diff changeset
   297
+ENGINE *ENGINE_ibmca()
b16e349d18c5 the easy part of the reorg (most files moved around)
laca
parents:
diff changeset
   298
+        {
b16e349d18c5 the easy part of the reorg (most files moved around)
laca
parents:
diff changeset
   299
+        RSA_METHOD *meth1;
b16e349d18c5 the easy part of the reorg (most files moved around)
laca
parents:
diff changeset
   300
+        DSA_METHOD *meth2;
b16e349d18c5 the easy part of the reorg (most files moved around)
laca
parents:
diff changeset
   301
+        DH_METHOD *meth3;
b16e349d18c5 the easy part of the reorg (most files moved around)
laca
parents:
diff changeset
   302
+
b16e349d18c5 the easy part of the reorg (most files moved around)
laca
parents:
diff changeset
   303
+        /* We know that the "PKCS1_SSLeay()" functions hook properly
b16e349d18c5 the easy part of the reorg (most files moved around)
laca
parents:
diff changeset
   304
+         * to the ibmca-specific mod_exp and mod_exp_crt so we use
b16e349d18c5 the easy part of the reorg (most files moved around)
laca
parents:
diff changeset
   305
+         * those functions. NB: We don't use ENGINE_openssl() or
b16e349d18c5 the easy part of the reorg (most files moved around)
laca
parents:
diff changeset
   306
+         * anything "more generic" because something like the RSAref
b16e349d18c5 the easy part of the reorg (most files moved around)
laca
parents:
diff changeset
   307
+         * code may not hook properly, and if you own one of these
b16e349d18c5 the easy part of the reorg (most files moved around)
laca
parents:
diff changeset
   308
+         * cards then you have the right to do RSA operations on it
b16e349d18c5 the easy part of the reorg (most files moved around)
laca
parents:
diff changeset
   309
+         * anyway! */
b16e349d18c5 the easy part of the reorg (most files moved around)
laca
parents:
diff changeset
   310
+        meth1 = RSA_PKCS1_SSLeay();
b16e349d18c5 the easy part of the reorg (most files moved around)
laca
parents:
diff changeset
   311
+        ibmca_rsa.rsa_pub_enc = meth1->rsa_pub_enc;
b16e349d18c5 the easy part of the reorg (most files moved around)
laca
parents:
diff changeset
   312
+        ibmca_rsa.rsa_pub_dec = meth1->rsa_pub_dec;
b16e349d18c5 the easy part of the reorg (most files moved around)
laca
parents:
diff changeset
   313
+        ibmca_rsa.rsa_priv_enc = meth1->rsa_priv_enc;
b16e349d18c5 the easy part of the reorg (most files moved around)
laca
parents:
diff changeset
   314
+        ibmca_rsa.rsa_priv_dec = meth1->rsa_priv_dec;
b16e349d18c5 the easy part of the reorg (most files moved around)
laca
parents:
diff changeset
   315
+
b16e349d18c5 the easy part of the reorg (most files moved around)
laca
parents:
diff changeset
   316
+        /* Use the DSA_OpenSSL() method and just hook the mod_exp-ish
b16e349d18c5 the easy part of the reorg (most files moved around)
laca
parents:
diff changeset
   317
+         * bits. */
b16e349d18c5 the easy part of the reorg (most files moved around)
laca
parents:
diff changeset
   318
+        meth2 = DSA_OpenSSL();
b16e349d18c5 the easy part of the reorg (most files moved around)
laca
parents:
diff changeset
   319
+        ibmca_dsa.dsa_do_sign = meth2->dsa_do_sign;
b16e349d18c5 the easy part of the reorg (most files moved around)
laca
parents:
diff changeset
   320
+        ibmca_dsa.dsa_sign_setup = meth2->dsa_sign_setup;
b16e349d18c5 the easy part of the reorg (most files moved around)
laca
parents:
diff changeset
   321
+        ibmca_dsa.dsa_do_verify = meth2->dsa_do_verify;
b16e349d18c5 the easy part of the reorg (most files moved around)
laca
parents:
diff changeset
   322
+
b16e349d18c5 the easy part of the reorg (most files moved around)
laca
parents:
diff changeset
   323
+        /* Much the same for Diffie-Hellman */
b16e349d18c5 the easy part of the reorg (most files moved around)
laca
parents:
diff changeset
   324
+        meth3 = DH_OpenSSL();
b16e349d18c5 the easy part of the reorg (most files moved around)
laca
parents:
diff changeset
   325
+        ibmca_dh.generate_key = meth3->generate_key;
b16e349d18c5 the easy part of the reorg (most files moved around)
laca
parents:
diff changeset
   326
+        ibmca_dh.compute_key = meth3->compute_key;
b16e349d18c5 the easy part of the reorg (most files moved around)
laca
parents:
diff changeset
   327
+        return &engine_ibmca;
b16e349d18c5 the easy part of the reorg (most files moved around)
laca
parents:
diff changeset
   328
+        }
b16e349d18c5 the easy part of the reorg (most files moved around)
laca
parents:
diff changeset
   329
+
b16e349d18c5 the easy part of the reorg (most files moved around)
laca
parents:
diff changeset
   330
+/* This is a process-global DSO handle used for loading and unloading
b16e349d18c5 the easy part of the reorg (most files moved around)
laca
parents:
diff changeset
   331
+ * the Ibmca library. NB: This is only set (or unset) during an
b16e349d18c5 the easy part of the reorg (most files moved around)
laca
parents:
diff changeset
   332
+ * init() or finish() call (reference counts permitting) and they're
b16e349d18c5 the easy part of the reorg (most files moved around)
laca
parents:
diff changeset
   333
+ * operating with global locks, so this should be thread-safe
b16e349d18c5 the easy part of the reorg (most files moved around)
laca
parents:
diff changeset
   334
+ * implicitly. */
b16e349d18c5 the easy part of the reorg (most files moved around)
laca
parents:
diff changeset
   335
+
b16e349d18c5 the easy part of the reorg (most files moved around)
laca
parents:
diff changeset
   336
+static DSO *ibmca_dso = NULL;
b16e349d18c5 the easy part of the reorg (most files moved around)
laca
parents:
diff changeset
   337
+
b16e349d18c5 the easy part of the reorg (most files moved around)
laca
parents:
diff changeset
   338
+/* These are the function pointers that are (un)set when the library has
b16e349d18c5 the easy part of the reorg (most files moved around)
laca
parents:
diff changeset
   339
+ * successfully (un)loaded. */
b16e349d18c5 the easy part of the reorg (most files moved around)
laca
parents:
diff changeset
   340
+
b16e349d18c5 the easy part of the reorg (most files moved around)
laca
parents:
diff changeset
   341
+static unsigned int    (ICA_CALL *p_icaOpenAdapter)();
b16e349d18c5 the easy part of the reorg (most files moved around)
laca
parents:
diff changeset
   342
+static unsigned int    (ICA_CALL *p_icaCloseAdapter)();
b16e349d18c5 the easy part of the reorg (most files moved around)
laca
parents:
diff changeset
   343
+static unsigned int    (ICA_CALL *p_icaRsaModExpo)();
b16e349d18c5 the easy part of the reorg (most files moved around)
laca
parents:
diff changeset
   344
+static unsigned int    (ICA_CALL *p_icaRandomNumberGenerate)();
b16e349d18c5 the easy part of the reorg (most files moved around)
laca
parents:
diff changeset
   345
+static unsigned int    (ICA_CALL *p_icaRsaCrt)();
b16e349d18c5 the easy part of the reorg (most files moved around)
laca
parents:
diff changeset
   346
+
b16e349d18c5 the easy part of the reorg (most files moved around)
laca
parents:
diff changeset
   347
+/* utility function to obtain a context */
b16e349d18c5 the easy part of the reorg (most files moved around)
laca
parents:
diff changeset
   348
+static int get_context(ICA_ADAPTER_HANDLE *p_handle)
b16e349d18c5 the easy part of the reorg (most files moved around)
laca
parents:
diff changeset
   349
+        {
b16e349d18c5 the easy part of the reorg (most files moved around)
laca
parents:
diff changeset
   350
+        unsigned int status=0;
b16e349d18c5 the easy part of the reorg (most files moved around)
laca
parents:
diff changeset
   351
+
b16e349d18c5 the easy part of the reorg (most files moved around)
laca
parents:
diff changeset
   352
+        status = p_icaOpenAdapter(0, p_handle);
b16e349d18c5 the easy part of the reorg (most files moved around)
laca
parents:
diff changeset
   353
+        if(status != 0)
b16e349d18c5 the easy part of the reorg (most files moved around)
laca
parents:
diff changeset
   354
+                return 0;
b16e349d18c5 the easy part of the reorg (most files moved around)
laca
parents:
diff changeset
   355
+        return 1;
b16e349d18c5 the easy part of the reorg (most files moved around)
laca
parents:
diff changeset
   356
+        }
b16e349d18c5 the easy part of the reorg (most files moved around)
laca
parents:
diff changeset
   357
+
b16e349d18c5 the easy part of the reorg (most files moved around)
laca
parents:
diff changeset
   358
+/* similarly to release one. */
b16e349d18c5 the easy part of the reorg (most files moved around)
laca
parents:
diff changeset
   359
+static void release_context(ICA_ADAPTER_HANDLE handle)
b16e349d18c5 the easy part of the reorg (most files moved around)
laca
parents:
diff changeset
   360
+        {
b16e349d18c5 the easy part of the reorg (most files moved around)
laca
parents:
diff changeset
   361
+        p_icaCloseAdapter(handle);
b16e349d18c5 the easy part of the reorg (most files moved around)
laca
parents:
diff changeset
   362
+        }
b16e349d18c5 the easy part of the reorg (most files moved around)
laca
parents:
diff changeset
   363
+
b16e349d18c5 the easy part of the reorg (most files moved around)
laca
parents:
diff changeset
   364
+/* (de)initialisation functions. */
b16e349d18c5 the easy part of the reorg (most files moved around)
laca
parents:
diff changeset
   365
+static int ibmca_init()
b16e349d18c5 the easy part of the reorg (most files moved around)
laca
parents:
diff changeset
   366
+        {
b16e349d18c5 the easy part of the reorg (most files moved around)
laca
parents:
diff changeset
   367
+
b16e349d18c5 the easy part of the reorg (most files moved around)
laca
parents:
diff changeset
   368
+        void          (*p1)();
b16e349d18c5 the easy part of the reorg (most files moved around)
laca
parents:
diff changeset
   369
+        void          (*p2)();
b16e349d18c5 the easy part of the reorg (most files moved around)
laca
parents:
diff changeset
   370
+        void          (*p3)();
b16e349d18c5 the easy part of the reorg (most files moved around)
laca
parents:
diff changeset
   371
+        void          (*p4)();
b16e349d18c5 the easy part of the reorg (most files moved around)
laca
parents:
diff changeset
   372
+        void          (*p5)();
b16e349d18c5 the easy part of the reorg (most files moved around)
laca
parents:
diff changeset
   373
+
b16e349d18c5 the easy part of the reorg (most files moved around)
laca
parents:
diff changeset
   374
+        if(ibmca_dso != NULL)
b16e349d18c5 the easy part of the reorg (most files moved around)
laca
parents:
diff changeset
   375
+                {
b16e349d18c5 the easy part of the reorg (most files moved around)
laca
parents:
diff changeset
   376
+                ENGINEerr(ENGINE_F_IBMCA_INIT,ENGINE_R_ALREADY_LOADED);
b16e349d18c5 the easy part of the reorg (most files moved around)
laca
parents:
diff changeset
   377
+                goto err;
b16e349d18c5 the easy part of the reorg (most files moved around)
laca
parents:
diff changeset
   378
+                }
b16e349d18c5 the easy part of the reorg (most files moved around)
laca
parents:
diff changeset
   379
+        /* Attempt to load libatasi.so/atasi.dll/whatever. Needs to be
b16e349d18c5 the easy part of the reorg (most files moved around)
laca
parents:
diff changeset
   380
+         * changed unfortunately because the Ibmca drivers don't have
b16e349d18c5 the easy part of the reorg (most files moved around)
laca
parents:
diff changeset
   381
+         * standard library names that can be platform-translated well. */
b16e349d18c5 the easy part of the reorg (most files moved around)
laca
parents:
diff changeset
   382
+        /* TODO: Work out how to actually map to the names the Ibmca
b16e349d18c5 the easy part of the reorg (most files moved around)
laca
parents:
diff changeset
   383
+         * drivers really use - for now a symbollic link needs to be
b16e349d18c5 the easy part of the reorg (most files moved around)
laca
parents:
diff changeset
   384
+         * created on the host system from libatasi.so to atasi.so on
b16e349d18c5 the easy part of the reorg (most files moved around)
laca
parents:
diff changeset
   385
+         * unix variants. */
b16e349d18c5 the easy part of the reorg (most files moved around)
laca
parents:
diff changeset
   386
+
b16e349d18c5 the easy part of the reorg (most files moved around)
laca
parents:
diff changeset
   387
+        ibmca_dso = DSO_load(NULL, IBMCA_LIBNAME, NULL,
b16e349d18c5 the easy part of the reorg (most files moved around)
laca
parents:
diff changeset
   388
+                DSO_FLAG_NAME_TRANSLATION);
b16e349d18c5 the easy part of the reorg (most files moved around)
laca
parents:
diff changeset
   389
+        if(ibmca_dso == NULL)
b16e349d18c5 the easy part of the reorg (most files moved around)
laca
parents:
diff changeset
   390
+                {
b16e349d18c5 the easy part of the reorg (most files moved around)
laca
parents:
diff changeset
   391
+                ENGINEerr(ENGINE_F_IBMCA_INIT,ENGINE_R_DSO_FAILURE);
b16e349d18c5 the easy part of the reorg (most files moved around)
laca
parents:
diff changeset
   392
+                goto err;
b16e349d18c5 the easy part of the reorg (most files moved around)
laca
parents:
diff changeset
   393
+                }
b16e349d18c5 the easy part of the reorg (most files moved around)
laca
parents:
diff changeset
   394
+
b16e349d18c5 the easy part of the reorg (most files moved around)
laca
parents:
diff changeset
   395
+        if(!(p1 = DSO_bind_func(
b16e349d18c5 the easy part of the reorg (most files moved around)
laca
parents:
diff changeset
   396
+                ibmca_dso, IBMCA_F1)) ||
b16e349d18c5 the easy part of the reorg (most files moved around)
laca
parents:
diff changeset
   397
+                !(p2 = DSO_bind_func(
b16e349d18c5 the easy part of the reorg (most files moved around)
laca
parents:
diff changeset
   398
+                        ibmca_dso, IBMCA_F2)) ||
b16e349d18c5 the easy part of the reorg (most files moved around)
laca
parents:
diff changeset
   399
+                !(p3 = DSO_bind_func(
b16e349d18c5 the easy part of the reorg (most files moved around)
laca
parents:
diff changeset
   400
+                        ibmca_dso, IBMCA_F3)) ||
b16e349d18c5 the easy part of the reorg (most files moved around)
laca
parents:
diff changeset
   401
+                !(p4 = DSO_bind_func(
b16e349d18c5 the easy part of the reorg (most files moved around)
laca
parents:
diff changeset
   402
+                        ibmca_dso, IBMCA_F4)) ||
b16e349d18c5 the easy part of the reorg (most files moved around)
laca
parents:
diff changeset
   403
+                !(p5 = DSO_bind_func(
b16e349d18c5 the easy part of the reorg (most files moved around)
laca
parents:
diff changeset
   404
+                        ibmca_dso, IBMCA_F5)))
b16e349d18c5 the easy part of the reorg (most files moved around)
laca
parents:
diff changeset
   405
+                {
b16e349d18c5 the easy part of the reorg (most files moved around)
laca
parents:
diff changeset
   406
+                ENGINEerr(ENGINE_F_IBMCA_INIT,ENGINE_R_DSO_FAILURE);
b16e349d18c5 the easy part of the reorg (most files moved around)
laca
parents:
diff changeset
   407
+                goto err;
b16e349d18c5 the easy part of the reorg (most files moved around)
laca
parents:
diff changeset
   408
+                }
b16e349d18c5 the easy part of the reorg (most files moved around)
laca
parents:
diff changeset
   409
+
b16e349d18c5 the easy part of the reorg (most files moved around)
laca
parents:
diff changeset
   410
+        /* Copy the pointers */
b16e349d18c5 the easy part of the reorg (most files moved around)
laca
parents:
diff changeset
   411
+
b16e349d18c5 the easy part of the reorg (most files moved around)
laca
parents:
diff changeset
   412
+	p_icaOpenAdapter =           (unsigned int (ICA_CALL *)())p1;
b16e349d18c5 the easy part of the reorg (most files moved around)
laca
parents:
diff changeset
   413
+	p_icaCloseAdapter =          (unsigned int (ICA_CALL *)())p2;
b16e349d18c5 the easy part of the reorg (most files moved around)
laca
parents:
diff changeset
   414
+	p_icaRsaModExpo =            (unsigned int (ICA_CALL *)())p3;
b16e349d18c5 the easy part of the reorg (most files moved around)
laca
parents:
diff changeset
   415
+	p_icaRandomNumberGenerate =  (unsigned int (ICA_CALL *)())p4;
b16e349d18c5 the easy part of the reorg (most files moved around)
laca
parents:
diff changeset
   416
+	p_icaRsaCrt =                (unsigned int (ICA_CALL *)())p5;
b16e349d18c5 the easy part of the reorg (most files moved around)
laca
parents:
diff changeset
   417
+
b16e349d18c5 the easy part of the reorg (most files moved around)
laca
parents:
diff changeset
   418
+        if(!get_context(&handle))
b16e349d18c5 the easy part of the reorg (most files moved around)
laca
parents:
diff changeset
   419
+                {
b16e349d18c5 the easy part of the reorg (most files moved around)
laca
parents:
diff changeset
   420
+                ENGINEerr(ENGINE_F_IBMCA_INIT,ENGINE_R_UNIT_FAILURE);
b16e349d18c5 the easy part of the reorg (most files moved around)
laca
parents:
diff changeset
   421
+                goto err;
b16e349d18c5 the easy part of the reorg (most files moved around)
laca
parents:
diff changeset
   422
+                }
b16e349d18c5 the easy part of the reorg (most files moved around)
laca
parents:
diff changeset
   423
+
b16e349d18c5 the easy part of the reorg (most files moved around)
laca
parents:
diff changeset
   424
+        return 1;
b16e349d18c5 the easy part of the reorg (most files moved around)
laca
parents:
diff changeset
   425
+ err:
b16e349d18c5 the easy part of the reorg (most files moved around)
laca
parents:
diff changeset
   426
+        if(ibmca_dso)
b16e349d18c5 the easy part of the reorg (most files moved around)
laca
parents:
diff changeset
   427
+                DSO_free(ibmca_dso);
b16e349d18c5 the easy part of the reorg (most files moved around)
laca
parents:
diff changeset
   428
+
b16e349d18c5 the easy part of the reorg (most files moved around)
laca
parents:
diff changeset
   429
+        p_icaOpenAdapter = NULL;
b16e349d18c5 the easy part of the reorg (most files moved around)
laca
parents:
diff changeset
   430
+        p_icaCloseAdapter = NULL;
b16e349d18c5 the easy part of the reorg (most files moved around)
laca
parents:
diff changeset
   431
+        p_icaRsaModExpo = NULL;
b16e349d18c5 the easy part of the reorg (most files moved around)
laca
parents:
diff changeset
   432
+        p_icaRandomNumberGenerate = NULL;
b16e349d18c5 the easy part of the reorg (most files moved around)
laca
parents:
diff changeset
   433
+
b16e349d18c5 the easy part of the reorg (most files moved around)
laca
parents:
diff changeset
   434
+        return 0;
b16e349d18c5 the easy part of the reorg (most files moved around)
laca
parents:
diff changeset
   435
+        }
b16e349d18c5 the easy part of the reorg (most files moved around)
laca
parents:
diff changeset
   436
+
b16e349d18c5 the easy part of the reorg (most files moved around)
laca
parents:
diff changeset
   437
+static int ibmca_finish()
b16e349d18c5 the easy part of the reorg (most files moved around)
laca
parents:
diff changeset
   438
+        {
b16e349d18c5 the easy part of the reorg (most files moved around)
laca
parents:
diff changeset
   439
+        if(ibmca_dso == NULL)
b16e349d18c5 the easy part of the reorg (most files moved around)
laca
parents:
diff changeset
   440
+                {
b16e349d18c5 the easy part of the reorg (most files moved around)
laca
parents:
diff changeset
   441
+                ENGINEerr(ENGINE_F_IBMCA_FINISH,ENGINE_R_NOT_LOADED);
b16e349d18c5 the easy part of the reorg (most files moved around)
laca
parents:
diff changeset
   442
+                return 0;
b16e349d18c5 the easy part of the reorg (most files moved around)
laca
parents:
diff changeset
   443
+                }
b16e349d18c5 the easy part of the reorg (most files moved around)
laca
parents:
diff changeset
   444
+        release_context(handle);
b16e349d18c5 the easy part of the reorg (most files moved around)
laca
parents:
diff changeset
   445
+        if(!DSO_free(ibmca_dso))
b16e349d18c5 the easy part of the reorg (most files moved around)
laca
parents:
diff changeset
   446
+                {
b16e349d18c5 the easy part of the reorg (most files moved around)
laca
parents:
diff changeset
   447
+                ENGINEerr(ENGINE_F_IBMCA_FINISH,ENGINE_R_DSO_FAILURE);
b16e349d18c5 the easy part of the reorg (most files moved around)
laca
parents:
diff changeset
   448
+                return 0;
b16e349d18c5 the easy part of the reorg (most files moved around)
laca
parents:
diff changeset
   449
+                }
b16e349d18c5 the easy part of the reorg (most files moved around)
laca
parents:
diff changeset
   450
+        ibmca_dso = NULL;
b16e349d18c5 the easy part of the reorg (most files moved around)
laca
parents:
diff changeset
   451
+
b16e349d18c5 the easy part of the reorg (most files moved around)
laca
parents:
diff changeset
   452
+        return 1;
b16e349d18c5 the easy part of the reorg (most files moved around)
laca
parents:
diff changeset
   453
+        }
b16e349d18c5 the easy part of the reorg (most files moved around)
laca
parents:
diff changeset
   454
+
b16e349d18c5 the easy part of the reorg (most files moved around)
laca
parents:
diff changeset
   455
+static int ibmca_mod_exp(BIGNUM *r, BIGNUM *a, const BIGNUM *p,
b16e349d18c5 the easy part of the reorg (most files moved around)
laca
parents:
diff changeset
   456
+        const BIGNUM *m, BN_CTX *ctx)
b16e349d18c5 the easy part of the reorg (most files moved around)
laca
parents:
diff changeset
   457
+        {
b16e349d18c5 the easy part of the reorg (most files moved around)
laca
parents:
diff changeset
   458
+        /* I need somewhere to store temporary serialised values for
b16e349d18c5 the easy part of the reorg (most files moved around)
laca
parents:
diff changeset
   459
+         * use with the Ibmca API calls. A neat cheat - I'll use
b16e349d18c5 the easy part of the reorg (most files moved around)
laca
parents:
diff changeset
   460
+         * BIGNUMs from the BN_CTX but access their arrays directly as
b16e349d18c5 the easy part of the reorg (most files moved around)
laca
parents:
diff changeset
   461
+         * byte arrays <grin>. This way I don't have to clean anything
b16e349d18c5 the easy part of the reorg (most files moved around)
laca
parents:
diff changeset
   462
+         * up. */
b16e349d18c5 the easy part of the reorg (most files moved around)
laca
parents:
diff changeset
   463
+
b16e349d18c5 the easy part of the reorg (most files moved around)
laca
parents:
diff changeset
   464
+        BIGNUM *argument=NULL;
b16e349d18c5 the easy part of the reorg (most files moved around)
laca
parents:
diff changeset
   465
+        BIGNUM *result=NULL;
b16e349d18c5 the easy part of the reorg (most files moved around)
laca
parents:
diff changeset
   466
+        BIGNUM *key=NULL;
b16e349d18c5 the easy part of the reorg (most files moved around)
laca
parents:
diff changeset
   467
+        int to_return;
b16e349d18c5 the easy part of the reorg (most files moved around)
laca
parents:
diff changeset
   468
+	int inLen, outLen, tmpLen;
b16e349d18c5 the easy part of the reorg (most files moved around)
laca
parents:
diff changeset
   469
+
b16e349d18c5 the easy part of the reorg (most files moved around)
laca
parents:
diff changeset
   470
+
b16e349d18c5 the easy part of the reorg (most files moved around)
laca
parents:
diff changeset
   471
+        ICA_KEY_RSA_MODEXPO *publKey=NULL;
b16e349d18c5 the easy part of the reorg (most files moved around)
laca
parents:
diff changeset
   472
+        unsigned int rc;
b16e349d18c5 the easy part of the reorg (most files moved around)
laca
parents:
diff changeset
   473
+
b16e349d18c5 the easy part of the reorg (most files moved around)
laca
parents:
diff changeset
   474
+        to_return = 0; /* expect failure */
b16e349d18c5 the easy part of the reorg (most files moved around)
laca
parents:
diff changeset
   475
+
b16e349d18c5 the easy part of the reorg (most files moved around)
laca
parents:
diff changeset
   476
+        if(!ibmca_dso)
b16e349d18c5 the easy part of the reorg (most files moved around)
laca
parents:
diff changeset
   477
+                {
b16e349d18c5 the easy part of the reorg (most files moved around)
laca
parents:
diff changeset
   478
+                ENGINEerr(ENGINE_F_IBMCA_MOD_EXP,ENGINE_R_NOT_LOADED);
b16e349d18c5 the easy part of the reorg (most files moved around)
laca
parents:
diff changeset
   479
+                goto err;
b16e349d18c5 the easy part of the reorg (most files moved around)
laca
parents:
diff changeset
   480
+                }
b16e349d18c5 the easy part of the reorg (most files moved around)
laca
parents:
diff changeset
   481
+        /* Prepare the params */
b16e349d18c5 the easy part of the reorg (most files moved around)
laca
parents:
diff changeset
   482
+        argument = BN_CTX_get(ctx);
b16e349d18c5 the easy part of the reorg (most files moved around)
laca
parents:
diff changeset
   483
+        result = BN_CTX_get(ctx);
b16e349d18c5 the easy part of the reorg (most files moved around)
laca
parents:
diff changeset
   484
+        key = BN_CTX_get(ctx);
b16e349d18c5 the easy part of the reorg (most files moved around)
laca
parents:
diff changeset
   485
+
b16e349d18c5 the easy part of the reorg (most files moved around)
laca
parents:
diff changeset
   486
+        if( !argument || !result || !key)
b16e349d18c5 the easy part of the reorg (most files moved around)
laca
parents:
diff changeset
   487
+                {
b16e349d18c5 the easy part of the reorg (most files moved around)
laca
parents:
diff changeset
   488
+                ENGINEerr(ENGINE_F_IBMCA_MOD_EXP,ENGINE_R_BN_CTX_FULL);
b16e349d18c5 the easy part of the reorg (most files moved around)
laca
parents:
diff changeset
   489
+                goto err;
b16e349d18c5 the easy part of the reorg (most files moved around)
laca
parents:
diff changeset
   490
+                }
b16e349d18c5 the easy part of the reorg (most files moved around)
laca
parents:
diff changeset
   491
+
b16e349d18c5 the easy part of the reorg (most files moved around)
laca
parents:
diff changeset
   492
+
b16e349d18c5 the easy part of the reorg (most files moved around)
laca
parents:
diff changeset
   493
+	if(!bn_wexpand(argument, m->top) || !bn_wexpand(result, m->top) ||
b16e349d18c5 the easy part of the reorg (most files moved around)
laca
parents:
diff changeset
   494
+                !bn_wexpand(key, sizeof(*publKey)/BN_BYTES))
b16e349d18c5 the easy part of the reorg (most files moved around)
laca
parents:
diff changeset
   495
+
b16e349d18c5 the easy part of the reorg (most files moved around)
laca
parents:
diff changeset
   496
+                {
b16e349d18c5 the easy part of the reorg (most files moved around)
laca
parents:
diff changeset
   497
+                ENGINEerr(ENGINE_F_IBMCA_MOD_EXP,ENGINE_R_BN_EXPAND_FAIL);
b16e349d18c5 the easy part of the reorg (most files moved around)
laca
parents:
diff changeset
   498
+                goto err;
b16e349d18c5 the easy part of the reorg (most files moved around)
laca
parents:
diff changeset
   499
+                }
b16e349d18c5 the easy part of the reorg (most files moved around)
laca
parents:
diff changeset
   500
+
b16e349d18c5 the easy part of the reorg (most files moved around)
laca
parents:
diff changeset
   501
+        publKey = (ICA_KEY_RSA_MODEXPO *)key->d;
b16e349d18c5 the easy part of the reorg (most files moved around)
laca
parents:
diff changeset
   502
+
b16e349d18c5 the easy part of the reorg (most files moved around)
laca
parents:
diff changeset
   503
+        if (publKey == NULL)
b16e349d18c5 the easy part of the reorg (most files moved around)
laca
parents:
diff changeset
   504
+                {
b16e349d18c5 the easy part of the reorg (most files moved around)
laca
parents:
diff changeset
   505
+                goto err;
b16e349d18c5 the easy part of the reorg (most files moved around)
laca
parents:
diff changeset
   506
+                }
b16e349d18c5 the easy part of the reorg (most files moved around)
laca
parents:
diff changeset
   507
+        memset(publKey, 0, sizeof(ICA_KEY_RSA_MODEXPO));
b16e349d18c5 the easy part of the reorg (most files moved around)
laca
parents:
diff changeset
   508
+
b16e349d18c5 the easy part of the reorg (most files moved around)
laca
parents:
diff changeset
   509
+        publKey->keyType   =  CORRECT_ENDIANNESS(ME_KEY_TYPE);
b16e349d18c5 the easy part of the reorg (most files moved around)
laca
parents:
diff changeset
   510
+        publKey->keyLength =  CORRECT_ENDIANNESS(sizeof(ICA_KEY_RSA_MODEXPO));
b16e349d18c5 the easy part of the reorg (most files moved around)
laca
parents:
diff changeset
   511
+        publKey->expOffset =  (char *) publKey->keyRecord - (char *) publKey;
b16e349d18c5 the easy part of the reorg (most files moved around)
laca
parents:
diff changeset
   512
+
b16e349d18c5 the easy part of the reorg (most files moved around)
laca
parents:
diff changeset
   513
+        /* A quirk of the card: the exponent length has to be the same
b16e349d18c5 the easy part of the reorg (most files moved around)
laca
parents:
diff changeset
   514
+     as the modulus (key) length */
b16e349d18c5 the easy part of the reorg (most files moved around)
laca
parents:
diff changeset
   515
+
b16e349d18c5 the easy part of the reorg (most files moved around)
laca
parents:
diff changeset
   516
+	outLen = BN_num_bytes(m);
b16e349d18c5 the easy part of the reorg (most files moved around)
laca
parents:
diff changeset
   517
+
b16e349d18c5 the easy part of the reorg (most files moved around)
laca
parents:
diff changeset
   518
+     /* Check for a modulus greater than 2048 bits (256 bytes) */
b16e349d18c5 the easy part of the reorg (most files moved around)
laca
parents:
diff changeset
   519
+     if ( outLen > 256 ) {
b16e349d18c5 the easy part of the reorg (most files moved around)
laca
parents:
diff changeset
   520
+           ENGINEerr(ENGINE_F_IBMCA_MOD_EXP,ENGINE_R_SIZE_TOO_LARGE_OR_TOO_SMALL);
b16e349d18c5 the easy part of the reorg (most files moved around)
laca
parents:
diff changeset
   521
+           goto err;
b16e349d18c5 the easy part of the reorg (most files moved around)
laca
parents:
diff changeset
   522
+     }
b16e349d18c5 the easy part of the reorg (most files moved around)
laca
parents:
diff changeset
   523
+     /* SAB End check for modulus length */
b16e349d18c5 the easy part of the reorg (most files moved around)
laca
parents:
diff changeset
   524
+
b16e349d18c5 the easy part of the reorg (most files moved around)
laca
parents:
diff changeset
   525
+
b16e349d18c5 the easy part of the reorg (most files moved around)
laca
parents:
diff changeset
   526
+	publKey->expLength = publKey->nLength = outLen;
b16e349d18c5 the easy part of the reorg (most files moved around)
laca
parents:
diff changeset
   527
+
b16e349d18c5 the easy part of the reorg (most files moved around)
laca
parents:
diff changeset
   528
+     /* SAB Check for underflow condition here */
b16e349d18c5 the easy part of the reorg (most files moved around)
laca
parents:
diff changeset
   529
+     /* if the size of the exponent length is less than the size of the parameter p,
b16e349d18c5 the easy part of the reorg (most files moved around)
laca
parents:
diff changeset
   530
+      * then we have a big problem and we will underlfow the keyRecord buffer
b16e349d18c5 the easy part of the reorg (most files moved around)
laca
parents:
diff changeset
   531
+      * who knows what will happen then  
b16e349d18c5 the easy part of the reorg (most files moved around)
laca
parents:
diff changeset
   532
+      * */
b16e349d18c5 the easy part of the reorg (most files moved around)
laca
parents:
diff changeset
   533
+     if ( outLen < BN_num_bytes(p) ) {
b16e349d18c5 the easy part of the reorg (most files moved around)
laca
parents:
diff changeset
   534
+           ENGINEerr(ENGINE_F_IBMCA_MOD_EXP,ENGINE_R_SIZE_TOO_LARGE_OR_TOO_SMALL);
b16e349d18c5 the easy part of the reorg (most files moved around)
laca
parents:
diff changeset
   535
+           goto err;
b16e349d18c5 the easy part of the reorg (most files moved around)
laca
parents:
diff changeset
   536
+     }
b16e349d18c5 the easy part of the reorg (most files moved around)
laca
parents:
diff changeset
   537
+     /* SAB End Check for underflow */
b16e349d18c5 the easy part of the reorg (most files moved around)
laca
parents:
diff changeset
   538
+
b16e349d18c5 the easy part of the reorg (most files moved around)
laca
parents:
diff changeset
   539
+
b16e349d18c5 the easy part of the reorg (most files moved around)
laca
parents:
diff changeset
   540
+        BN_bn2bin(p, &publKey->keyRecord[publKey->expLength -
b16e349d18c5 the easy part of the reorg (most files moved around)
laca
parents:
diff changeset
   541
+                BN_num_bytes(p)]);
b16e349d18c5 the easy part of the reorg (most files moved around)
laca
parents:
diff changeset
   542
+        BN_bn2bin(m, &publKey->keyRecord[publKey->expLength]);
b16e349d18c5 the easy part of the reorg (most files moved around)
laca
parents:
diff changeset
   543
+
b16e349d18c5 the easy part of the reorg (most files moved around)
laca
parents:
diff changeset
   544
+
b16e349d18c5 the easy part of the reorg (most files moved around)
laca
parents:
diff changeset
   545
+
b16e349d18c5 the easy part of the reorg (most files moved around)
laca
parents:
diff changeset
   546
+        publKey->modulusBitLength = CORRECT_ENDIANNESS(publKey->nLength * 8);
b16e349d18c5 the easy part of the reorg (most files moved around)
laca
parents:
diff changeset
   547
+        publKey->nOffset   = CORRECT_ENDIANNESS(publKey->expOffset + 
b16e349d18c5 the easy part of the reorg (most files moved around)
laca
parents:
diff changeset
   548
+						publKey->expLength);
b16e349d18c5 the easy part of the reorg (most files moved around)
laca
parents:
diff changeset
   549
+
b16e349d18c5 the easy part of the reorg (most files moved around)
laca
parents:
diff changeset
   550
+        publKey->expOffset = CORRECT_ENDIANNESS((char *) publKey->keyRecord - 
b16e349d18c5 the easy part of the reorg (most files moved around)
laca
parents:
diff changeset
   551
+						(char *) publKey);
b16e349d18c5 the easy part of the reorg (most files moved around)
laca
parents:
diff changeset
   552
+
b16e349d18c5 the easy part of the reorg (most files moved around)
laca
parents:
diff changeset
   553
+
b16e349d18c5 the easy part of the reorg (most files moved around)
laca
parents:
diff changeset
   554
+	tmpLen = outLen;
b16e349d18c5 the easy part of the reorg (most files moved around)
laca
parents:
diff changeset
   555
+
b16e349d18c5 the easy part of the reorg (most files moved around)
laca
parents:
diff changeset
   556
+
b16e349d18c5 the easy part of the reorg (most files moved around)
laca
parents:
diff changeset
   557
+         
b16e349d18c5 the easy part of the reorg (most files moved around)
laca
parents:
diff changeset
   558
+	publKey->expLength = publKey->nLength = CORRECT_ENDIANNESS(tmpLen);
b16e349d18c5 the easy part of the reorg (most files moved around)
laca
parents:
diff changeset
   559
+
b16e349d18c5 the easy part of the reorg (most files moved around)
laca
parents:
diff changeset
   560
+  /* Prepare the argument */
b16e349d18c5 the easy part of the reorg (most files moved around)
laca
parents:
diff changeset
   561
+
b16e349d18c5 the easy part of the reorg (most files moved around)
laca
parents:
diff changeset
   562
+	memset(argument->d, 0, outLen);
b16e349d18c5 the easy part of the reorg (most files moved around)
laca
parents:
diff changeset
   563
+	BN_bn2bin(a, (unsigned char *)argument->d + outLen -
b16e349d18c5 the easy part of the reorg (most files moved around)
laca
parents:
diff changeset
   564
+                 BN_num_bytes(a));
b16e349d18c5 the easy part of the reorg (most files moved around)
laca
parents:
diff changeset
   565
+
b16e349d18c5 the easy part of the reorg (most files moved around)
laca
parents:
diff changeset
   566
+	inLen = outLen;
b16e349d18c5 the easy part of the reorg (most files moved around)
laca
parents:
diff changeset
   567
+
b16e349d18c5 the easy part of the reorg (most files moved around)
laca
parents:
diff changeset
   568
+  /* Perform the operation */
b16e349d18c5 the easy part of the reorg (most files moved around)
laca
parents:
diff changeset
   569
+
b16e349d18c5 the easy part of the reorg (most files moved around)
laca
parents:
diff changeset
   570
+          if( (rc = p_icaRsaModExpo(handle, inLen,(unsigned char *)argument->d,
b16e349d18c5 the easy part of the reorg (most files moved around)
laca
parents:
diff changeset
   571
+                publKey, &outLen, (unsigned char *)result->d))
b16e349d18c5 the easy part of the reorg (most files moved around)
laca
parents:
diff changeset
   572
+                !=0 )
b16e349d18c5 the easy part of the reorg (most files moved around)
laca
parents:
diff changeset
   573
+
b16e349d18c5 the easy part of the reorg (most files moved around)
laca
parents:
diff changeset
   574
+                {
b16e349d18c5 the easy part of the reorg (most files moved around)
laca
parents:
diff changeset
   575
+                ENGINEerr(ENGINE_F_IBMCA_MOD_EXP,ENGINE_R_REQUEST_FAILED);
b16e349d18c5 the easy part of the reorg (most files moved around)
laca
parents:
diff changeset
   576
+                goto err;
b16e349d18c5 the easy part of the reorg (most files moved around)
laca
parents:
diff changeset
   577
+                }
b16e349d18c5 the easy part of the reorg (most files moved around)
laca
parents:
diff changeset
   578
+
b16e349d18c5 the easy part of the reorg (most files moved around)
laca
parents:
diff changeset
   579
+
b16e349d18c5 the easy part of the reorg (most files moved around)
laca
parents:
diff changeset
   580
+        /* Convert the response */
b16e349d18c5 the easy part of the reorg (most files moved around)
laca
parents:
diff changeset
   581
+        BN_bin2bn((unsigned char *)result->d, outLen, r);
b16e349d18c5 the easy part of the reorg (most files moved around)
laca
parents:
diff changeset
   582
+        to_return = 1;
b16e349d18c5 the easy part of the reorg (most files moved around)
laca
parents:
diff changeset
   583
+ err:
b16e349d18c5 the easy part of the reorg (most files moved around)
laca
parents:
diff changeset
   584
+        if(argument) ctx->tos--;
b16e349d18c5 the easy part of the reorg (most files moved around)
laca
parents:
diff changeset
   585
+        if(result) ctx->tos--;
b16e349d18c5 the easy part of the reorg (most files moved around)
laca
parents:
diff changeset
   586
+        if(key) ctx->tos--;
b16e349d18c5 the easy part of the reorg (most files moved around)
laca
parents:
diff changeset
   587
+
b16e349d18c5 the easy part of the reorg (most files moved around)
laca
parents:
diff changeset
   588
+        return to_return;
b16e349d18c5 the easy part of the reorg (most files moved around)
laca
parents:
diff changeset
   589
+        }
b16e349d18c5 the easy part of the reorg (most files moved around)
laca
parents:
diff changeset
   590
+
b16e349d18c5 the easy part of the reorg (most files moved around)
laca
parents:
diff changeset
   591
+static int ibmca_rsa_mod_exp(BIGNUM *r0, BIGNUM *I, RSA *rsa)
b16e349d18c5 the easy part of the reorg (most files moved around)
laca
parents:
diff changeset
   592
+        {
b16e349d18c5 the easy part of the reorg (most files moved around)
laca
parents:
diff changeset
   593
+        BN_CTX *ctx;
b16e349d18c5 the easy part of the reorg (most files moved around)
laca
parents:
diff changeset
   594
+        int to_return = 0;
b16e349d18c5 the easy part of the reorg (most files moved around)
laca
parents:
diff changeset
   595
+
b16e349d18c5 the easy part of the reorg (most files moved around)
laca
parents:
diff changeset
   596
+        if((ctx = BN_CTX_new()) == NULL)
b16e349d18c5 the easy part of the reorg (most files moved around)
laca
parents:
diff changeset
   597
+                goto err;
b16e349d18c5 the easy part of the reorg (most files moved around)
laca
parents:
diff changeset
   598
+        if(!rsa->p || !rsa->q || !rsa->dmp1 || !rsa->dmq1 || !rsa->iqmp)
b16e349d18c5 the easy part of the reorg (most files moved around)
laca
parents:
diff changeset
   599
+                {
b16e349d18c5 the easy part of the reorg (most files moved around)
laca
parents:
diff changeset
   600
+                if(!rsa->d || !rsa->n)
b16e349d18c5 the easy part of the reorg (most files moved around)
laca
parents:
diff changeset
   601
+                        {
b16e349d18c5 the easy part of the reorg (most files moved around)
laca
parents:
diff changeset
   602
+                        ENGINEerr(ENGINE_F_IBMCA_RSA_MOD_EXP,
b16e349d18c5 the easy part of the reorg (most files moved around)
laca
parents:
diff changeset
   603
+                                ENGINE_R_MISSING_KEY_COMPONENTS);
b16e349d18c5 the easy part of the reorg (most files moved around)
laca
parents:
diff changeset
   604
+                        goto err;
b16e349d18c5 the easy part of the reorg (most files moved around)
laca
parents:
diff changeset
   605
+                        }
b16e349d18c5 the easy part of the reorg (most files moved around)
laca
parents:
diff changeset
   606
+                to_return = ibmca_mod_exp(r0, I, rsa->d, rsa->n, ctx);
b16e349d18c5 the easy part of the reorg (most files moved around)
laca
parents:
diff changeset
   607
+                }
b16e349d18c5 the easy part of the reorg (most files moved around)
laca
parents:
diff changeset
   608
+        else
b16e349d18c5 the easy part of the reorg (most files moved around)
laca
parents:
diff changeset
   609
+                {
b16e349d18c5 the easy part of the reorg (most files moved around)
laca
parents:
diff changeset
   610
+                to_return = ibmca_mod_exp_crt(r0, I, rsa->p, rsa->q, rsa->dmp1,
b16e349d18c5 the easy part of the reorg (most files moved around)
laca
parents:
diff changeset
   611
+                        rsa->dmq1, rsa->iqmp, ctx);
b16e349d18c5 the easy part of the reorg (most files moved around)
laca
parents:
diff changeset
   612
+                }
b16e349d18c5 the easy part of the reorg (most files moved around)
laca
parents:
diff changeset
   613
+ err:
b16e349d18c5 the easy part of the reorg (most files moved around)
laca
parents:
diff changeset
   614
+        if(ctx)
b16e349d18c5 the easy part of the reorg (most files moved around)
laca
parents:
diff changeset
   615
+                BN_CTX_free(ctx);
b16e349d18c5 the easy part of the reorg (most files moved around)
laca
parents:
diff changeset
   616
+        return to_return;
b16e349d18c5 the easy part of the reorg (most files moved around)
laca
parents:
diff changeset
   617
+        }
b16e349d18c5 the easy part of the reorg (most files moved around)
laca
parents:
diff changeset
   618
+
b16e349d18c5 the easy part of the reorg (most files moved around)
laca
parents:
diff changeset
   619
+/* Ein kleines chinesisches "Restessen"  */
b16e349d18c5 the easy part of the reorg (most files moved around)
laca
parents:
diff changeset
   620
+static int ibmca_mod_exp_crt(BIGNUM *r, BIGNUM *a, const BIGNUM *p,
b16e349d18c5 the easy part of the reorg (most files moved around)
laca
parents:
diff changeset
   621
+        const BIGNUM *q, const BIGNUM *dmp1,
b16e349d18c5 the easy part of the reorg (most files moved around)
laca
parents:
diff changeset
   622
+        const BIGNUM *dmq1, const BIGNUM *iqmp, BN_CTX *ctx)
b16e349d18c5 the easy part of the reorg (most files moved around)
laca
parents:
diff changeset
   623
+        {
b16e349d18c5 the easy part of the reorg (most files moved around)
laca
parents:
diff changeset
   624
+
b16e349d18c5 the easy part of the reorg (most files moved around)
laca
parents:
diff changeset
   625
+        BIGNUM *argument = NULL;
b16e349d18c5 the easy part of the reorg (most files moved around)
laca
parents:
diff changeset
   626
+        BIGNUM *result = NULL;
b16e349d18c5 the easy part of the reorg (most files moved around)
laca
parents:
diff changeset
   627
+        BIGNUM *key = NULL;
b16e349d18c5 the easy part of the reorg (most files moved around)
laca
parents:
diff changeset
   628
+  
b16e349d18c5 the easy part of the reorg (most files moved around)
laca
parents:
diff changeset
   629
+	unsigned int keyRecordSize;
b16e349d18c5 the easy part of the reorg (most files moved around)
laca
parents:
diff changeset
   630
+
b16e349d18c5 the easy part of the reorg (most files moved around)
laca
parents:
diff changeset
   631
+        int to_return = 0; /* expect failure */
b16e349d18c5 the easy part of the reorg (most files moved around)
laca
parents:
diff changeset
   632
+
b16e349d18c5 the easy part of the reorg (most files moved around)
laca
parents:
diff changeset
   633
+        char                *pkey=NULL;
b16e349d18c5 the easy part of the reorg (most files moved around)
laca
parents:
diff changeset
   634
+        ICA_KEY_RSA_CRT     *privKey=NULL;
b16e349d18c5 the easy part of the reorg (most files moved around)
laca
parents:
diff changeset
   635
+        int inLen, outLen;
b16e349d18c5 the easy part of the reorg (most files moved around)
laca
parents:
diff changeset
   636
+
b16e349d18c5 the easy part of the reorg (most files moved around)
laca
parents:
diff changeset
   637
+        int rc;
b16e349d18c5 the easy part of the reorg (most files moved around)
laca
parents:
diff changeset
   638
+        unsigned int        offset, pSize, qSize;
b16e349d18c5 the easy part of the reorg (most files moved around)
laca
parents:
diff changeset
   639
+
b16e349d18c5 the easy part of the reorg (most files moved around)
laca
parents:
diff changeset
   640
+        /* Prepare the params */
b16e349d18c5 the easy part of the reorg (most files moved around)
laca
parents:
diff changeset
   641
+
b16e349d18c5 the easy part of the reorg (most files moved around)
laca
parents:
diff changeset
   642
+        argument = BN_CTX_get(ctx);
b16e349d18c5 the easy part of the reorg (most files moved around)
laca
parents:
diff changeset
   643
+        result = BN_CTX_get(ctx);
b16e349d18c5 the easy part of the reorg (most files moved around)
laca
parents:
diff changeset
   644
+        key = BN_CTX_get(ctx);
b16e349d18c5 the easy part of the reorg (most files moved around)
laca
parents:
diff changeset
   645
+
b16e349d18c5 the easy part of the reorg (most files moved around)
laca
parents:
diff changeset
   646
+        if(!argument || !result || !key)
b16e349d18c5 the easy part of the reorg (most files moved around)
laca
parents:
diff changeset
   647
+                {
b16e349d18c5 the easy part of the reorg (most files moved around)
laca
parents:
diff changeset
   648
+                ENGINEerr(ENGINE_F_IBMCA_MOD_EXP_CRT,ENGINE_R_BN_CTX_FULL);
b16e349d18c5 the easy part of the reorg (most files moved around)
laca
parents:
diff changeset
   649
+                goto err;
b16e349d18c5 the easy part of the reorg (most files moved around)
laca
parents:
diff changeset
   650
+                }
b16e349d18c5 the easy part of the reorg (most files moved around)
laca
parents:
diff changeset
   651
+
b16e349d18c5 the easy part of the reorg (most files moved around)
laca
parents:
diff changeset
   652
+	if(!bn_wexpand(argument, p->top + q->top) ||
b16e349d18c5 the easy part of the reorg (most files moved around)
laca
parents:
diff changeset
   653
+                !bn_wexpand(result, p->top + q->top) ||
b16e349d18c5 the easy part of the reorg (most files moved around)
laca
parents:
diff changeset
   654
+                !bn_wexpand(key, sizeof(*privKey)/BN_BYTES ))
b16e349d18c5 the easy part of the reorg (most files moved around)
laca
parents:
diff changeset
   655
+                {
b16e349d18c5 the easy part of the reorg (most files moved around)
laca
parents:
diff changeset
   656
+                ENGINEerr(ENGINE_F_IBMCA_MOD_EXP_CRT,ENGINE_R_BN_EXPAND_FAIL);
b16e349d18c5 the easy part of the reorg (most files moved around)
laca
parents:
diff changeset
   657
+                goto err;
b16e349d18c5 the easy part of the reorg (most files moved around)
laca
parents:
diff changeset
   658
+                }
b16e349d18c5 the easy part of the reorg (most files moved around)
laca
parents:
diff changeset
   659
+
b16e349d18c5 the easy part of the reorg (most files moved around)
laca
parents:
diff changeset
   660
+        privKey = (ICA_KEY_RSA_CRT *)key->d;
b16e349d18c5 the easy part of the reorg (most files moved around)
laca
parents:
diff changeset
   661
+        memset(privKey, 0, sizeof(ICA_KEY_RSA_CRT));
b16e349d18c5 the easy part of the reorg (most files moved around)
laca
parents:
diff changeset
   662
+
b16e349d18c5 the easy part of the reorg (most files moved around)
laca
parents:
diff changeset
   663
+     /* SAB Add, check that the total size in bytes of the parameters does not
b16e349d18c5 the easy part of the reorg (most files moved around)
laca
parents:
diff changeset
   664
+      * exceede the buffer space we have 
b16e349d18c5 the easy part of the reorg (most files moved around)
laca
parents:
diff changeset
   665
+      * do this first because if it exceeds the 
b16e349d18c5 the easy part of the reorg (most files moved around)
laca
parents:
diff changeset
   666
+      */
b16e349d18c5 the easy part of the reorg (most files moved around)
laca
parents:
diff changeset
   667
+      keyRecordSize = BN_num_bytes(p) + BN_num_bytes(q) + BN_num_bytes(dmp1) + 
b16e349d18c5 the easy part of the reorg (most files moved around)
laca
parents:
diff changeset
   668
+		BN_num_bytes(dmq1) +  + BN_num_bytes(iqmp);
b16e349d18c5 the easy part of the reorg (most files moved around)
laca
parents:
diff changeset
   669
+		// DELETE BN_num_bytes(dmq1) + BN_num_bytes(q) + BN_num_bytes(iqmp);
b16e349d18c5 the easy part of the reorg (most files moved around)
laca
parents:
diff changeset
   670
+
b16e349d18c5 the easy part of the reorg (most files moved around)
laca
parents:
diff changeset
   671
+      if (keyRecordSize > sizeof(privKey->keyRecord)) {
b16e349d18c5 the easy part of the reorg (most files moved around)
laca
parents:
diff changeset
   672
+                ENGINEerr(ENGINE_F_IBMCA_MOD_EXP_CRT,ENGINE_R_SIZE_TOO_LARGE_OR_TOO_SMALL);
b16e349d18c5 the easy part of the reorg (most files moved around)
laca
parents:
diff changeset
   673
+                goto err;
b16e349d18c5 the easy part of the reorg (most files moved around)
laca
parents:
diff changeset
   674
+      }
b16e349d18c5 the easy part of the reorg (most files moved around)
laca
parents:
diff changeset
   675
+
b16e349d18c5 the easy part of the reorg (most files moved around)
laca
parents:
diff changeset
   676
+     /* SAB add, check that the size of the split of q  are not greater than 2048 (256 bytes) */
b16e349d18c5 the easy part of the reorg (most files moved around)
laca
parents:
diff changeset
   677
+     if ( (BN_num_bytes(q) + BN_num_bytes(dmq1)  ) > 256 ) {
b16e349d18c5 the easy part of the reorg (most files moved around)
laca
parents:
diff changeset
   678
+                ENGINEerr(ENGINE_F_IBMCA_MOD_EXP_CRT,ENGINE_R_SIZE_TOO_LARGE_OR_TOO_SMALL);
b16e349d18c5 the easy part of the reorg (most files moved around)
laca
parents:
diff changeset
   679
+                goto err;
b16e349d18c5 the easy part of the reorg (most files moved around)
laca
parents:
diff changeset
   680
+     }
b16e349d18c5 the easy part of the reorg (most files moved around)
laca
parents:
diff changeset
   681
+
b16e349d18c5 the easy part of the reorg (most files moved around)
laca
parents:
diff changeset
   682
+     /* SAB add, check that the size of the parts of P are  not greater than 2048 (256 bytes) */
b16e349d18c5 the easy part of the reorg (most files moved around)
laca
parents:
diff changeset
   683
+     if ( (BN_num_bytes(p) + BN_num_bytes(dmp1)  ) > 256 ) {
b16e349d18c5 the easy part of the reorg (most files moved around)
laca
parents:
diff changeset
   684
+                ENGINEerr(ENGINE_F_IBMCA_MOD_EXP_CRT,ENGINE_R_SIZE_TOO_LARGE_OR_TOO_SMALL);
b16e349d18c5 the easy part of the reorg (most files moved around)
laca
parents:
diff changeset
   685
+                goto err;
b16e349d18c5 the easy part of the reorg (most files moved around)
laca
parents:
diff changeset
   686
+     }
b16e349d18c5 the easy part of the reorg (most files moved around)
laca
parents:
diff changeset
   687
+
b16e349d18c5 the easy part of the reorg (most files moved around)
laca
parents:
diff changeset
   688
+
b16e349d18c5 the easy part of the reorg (most files moved around)
laca
parents:
diff changeset
   689
+        privKey->keyType =  CORRECT_ENDIANNESS(CRT_KEY_TYPE);
b16e349d18c5 the easy part of the reorg (most files moved around)
laca
parents:
diff changeset
   690
+        privKey->keyLength = CORRECT_ENDIANNESS(sizeof(ICA_KEY_RSA_CRT));
b16e349d18c5 the easy part of the reorg (most files moved around)
laca
parents:
diff changeset
   691
+        privKey->modulusBitLength = CORRECT_ENDIANNESS(BN_num_bytes(q) * 2 * 8);
b16e349d18c5 the easy part of the reorg (most files moved around)
laca
parents:
diff changeset
   692
+
b16e349d18c5 the easy part of the reorg (most files moved around)
laca
parents:
diff changeset
   693
+        /*
b16e349d18c5 the easy part of the reorg (most files moved around)
laca
parents:
diff changeset
   694
+         * p,dp & qInv are 1 QWORD Larger
b16e349d18c5 the easy part of the reorg (most files moved around)
laca
parents:
diff changeset
   695
+         */
b16e349d18c5 the easy part of the reorg (most files moved around)
laca
parents:
diff changeset
   696
+        privKey->pLength = CORRECT_ENDIANNESS(BN_num_bytes(p)+8);
b16e349d18c5 the easy part of the reorg (most files moved around)
laca
parents:
diff changeset
   697
+        privKey->qLength = CORRECT_ENDIANNESS(BN_num_bytes(q));
b16e349d18c5 the easy part of the reorg (most files moved around)
laca
parents:
diff changeset
   698
+        privKey->dpLength = CORRECT_ENDIANNESS(BN_num_bytes(dmp1)+8);
b16e349d18c5 the easy part of the reorg (most files moved around)
laca
parents:
diff changeset
   699
+        privKey->dqLength = CORRECT_ENDIANNESS(BN_num_bytes(dmq1));
b16e349d18c5 the easy part of the reorg (most files moved around)
laca
parents:
diff changeset
   700
+        privKey->qInvLength = CORRECT_ENDIANNESS(BN_num_bytes(iqmp)+8);
b16e349d18c5 the easy part of the reorg (most files moved around)
laca
parents:
diff changeset
   701
+
b16e349d18c5 the easy part of the reorg (most files moved around)
laca
parents:
diff changeset
   702
+        offset = (char *) privKey->keyRecord
b16e349d18c5 the easy part of the reorg (most files moved around)
laca
parents:
diff changeset
   703
+                  - (char *) privKey;
b16e349d18c5 the easy part of the reorg (most files moved around)
laca
parents:
diff changeset
   704
+
b16e349d18c5 the easy part of the reorg (most files moved around)
laca
parents:
diff changeset
   705
+        qSize = BN_num_bytes(q);
b16e349d18c5 the easy part of the reorg (most files moved around)
laca
parents:
diff changeset
   706
+        pSize = qSize + 8;   /*  1 QWORD larger */
b16e349d18c5 the easy part of the reorg (most files moved around)
laca
parents:
diff changeset
   707
+
b16e349d18c5 the easy part of the reorg (most files moved around)
laca
parents:
diff changeset
   708
+/* SAB  probably a little redundant, but we'll verify that each of the 
b16e349d18c5 the easy part of the reorg (most files moved around)
laca
parents:
diff changeset
   709
+   components which make up a keyrecord sent to the card does not 
b16e349d18c5 the easy part of the reorg (most files moved around)
laca
parents:
diff changeset
   710
+   exceed the space that is allocate for it.  This handles the
b16e349d18c5 the easy part of the reorg (most files moved around)
laca
parents:
diff changeset
   711
+   case where even if the total length does not exceed keyrecord size, if
b16e349d18c5 the easy part of the reorg (most files moved around)
laca
parents:
diff changeset
   712
+   the operands are funny sized causing potential side affects to either
b16e349d18c5 the easy part of the reorg (most files moved around)
laca
parents:
diff changeset
   713
+   the card or result */
b16e349d18c5 the easy part of the reorg (most files moved around)
laca
parents:
diff changeset
   714
+
b16e349d18c5 the easy part of the reorg (most files moved around)
laca
parents:
diff changeset
   715
+   if (  ((BN_num_bytes(p)) > pSize ) || 
b16e349d18c5 the easy part of the reorg (most files moved around)
laca
parents:
diff changeset
   716
+         ((BN_num_bytes(dmp1)) > pSize ) || 
b16e349d18c5 the easy part of the reorg (most files moved around)
laca
parents:
diff changeset
   717
+         ((BN_num_bytes(iqmp)) > pSize ) || 
b16e349d18c5 the easy part of the reorg (most files moved around)
laca
parents:
diff changeset
   718
+	 ((BN_num_bytes(q)) > qSize ) || 
b16e349d18c5 the easy part of the reorg (most files moved around)
laca
parents:
diff changeset
   719
+	 ((BN_num_bytes(dmq1)) > qSize )  ) {
b16e349d18c5 the easy part of the reorg (most files moved around)
laca
parents:
diff changeset
   720
+
b16e349d18c5 the easy part of the reorg (most files moved around)
laca
parents:
diff changeset
   721
+                ENGINEerr(ENGINE_F_IBMCA_MOD_EXP_CRT,ENGINE_R_SIZE_TOO_LARGE_OR_TOO_SMALL);
b16e349d18c5 the easy part of the reorg (most files moved around)
laca
parents:
diff changeset
   722
+                goto err;
b16e349d18c5 the easy part of the reorg (most files moved around)
laca
parents:
diff changeset
   723
+
b16e349d18c5 the easy part of the reorg (most files moved around)
laca
parents:
diff changeset
   724
+   }
b16e349d18c5 the easy part of the reorg (most files moved around)
laca
parents:
diff changeset
   725
+
b16e349d18c5 the easy part of the reorg (most files moved around)
laca
parents:
diff changeset
   726
+
b16e349d18c5 the easy part of the reorg (most files moved around)
laca
parents:
diff changeset
   727
+        
b16e349d18c5 the easy part of the reorg (most files moved around)
laca
parents:
diff changeset
   728
+
b16e349d18c5 the easy part of the reorg (most files moved around)
laca
parents:
diff changeset
   729
+        /* these offset values are ignored on all platforms except Intel
b16e349d18c5 the easy part of the reorg (most files moved around)
laca
parents:
diff changeset
   730
+         * in libica
b16e349d18c5 the easy part of the reorg (most files moved around)
laca
parents:
diff changeset
   731
+         * */
b16e349d18c5 the easy part of the reorg (most files moved around)
laca
parents:
diff changeset
   732
+        privKey->dpOffset = CORRECT_ENDIANNESS(offset);
b16e349d18c5 the easy part of the reorg (most files moved around)
laca
parents:
diff changeset
   733
+
b16e349d18c5 the easy part of the reorg (most files moved around)
laca
parents:
diff changeset
   734
+	offset += pSize;
b16e349d18c5 the easy part of the reorg (most files moved around)
laca
parents:
diff changeset
   735
+	privKey->dqOffset = CORRECT_ENDIANNESS(offset);
b16e349d18c5 the easy part of the reorg (most files moved around)
laca
parents:
diff changeset
   736
+
b16e349d18c5 the easy part of the reorg (most files moved around)
laca
parents:
diff changeset
   737
+	offset += qSize;
b16e349d18c5 the easy part of the reorg (most files moved around)
laca
parents:
diff changeset
   738
+	privKey->pOffset = CORRECT_ENDIANNESS(offset);
b16e349d18c5 the easy part of the reorg (most files moved around)
laca
parents:
diff changeset
   739
+
b16e349d18c5 the easy part of the reorg (most files moved around)
laca
parents:
diff changeset
   740
+	offset += pSize;
b16e349d18c5 the easy part of the reorg (most files moved around)
laca
parents:
diff changeset
   741
+	privKey->qOffset = CORRECT_ENDIANNESS(offset);
b16e349d18c5 the easy part of the reorg (most files moved around)
laca
parents:
diff changeset
   742
+
b16e349d18c5 the easy part of the reorg (most files moved around)
laca
parents:
diff changeset
   743
+	offset += qSize;
b16e349d18c5 the easy part of the reorg (most files moved around)
laca
parents:
diff changeset
   744
+	privKey->qInvOffset = CORRECT_ENDIANNESS(offset);
b16e349d18c5 the easy part of the reorg (most files moved around)
laca
parents:
diff changeset
   745
+
b16e349d18c5 the easy part of the reorg (most files moved around)
laca
parents:
diff changeset
   746
+        /* Start at the beginning of the buffer. */
b16e349d18c5 the easy part of the reorg (most files moved around)
laca
parents:
diff changeset
   747
+        pkey = (char *) privKey->keyRecord;
b16e349d18c5 the easy part of the reorg (most files moved around)
laca
parents:
diff changeset
   748
+
b16e349d18c5 the easy part of the reorg (most files moved around)
laca
parents:
diff changeset
   749
+        /* SAB First check that we won't underflow the buffer... */
b16e349d18c5 the easy part of the reorg (most files moved around)
laca
parents:
diff changeset
   750
+        /* p greater in size than pSize will cause us to underflow */
b16e349d18c5 the easy part of the reorg (most files moved around)
laca
parents:
diff changeset
   751
+        /* should really check the other data sizes as well before doing the copies */
b16e349d18c5 the easy part of the reorg (most files moved around)
laca
parents:
diff changeset
   752
+        /* no sense doing any copies if the sizes and offsets will create a bad buffer */
b16e349d18c5 the easy part of the reorg (most files moved around)
laca
parents:
diff changeset
   753
+        /* although the check for total lengths not exceeding total space should help */
b16e349d18c5 the easy part of the reorg (most files moved around)
laca
parents:
diff changeset
   754
+
b16e349d18c5 the easy part of the reorg (most files moved around)
laca
parents:
diff changeset
   755
+        if ( pSize < BN_num_bytes(p)){
b16e349d18c5 the easy part of the reorg (most files moved around)
laca
parents:
diff changeset
   756
+                ENGINEerr(ENGINE_F_IBMCA_MOD_EXP_CRT,ENGINE_R_SIZE_TOO_LARGE_OR_TOO_SMALL);
b16e349d18c5 the easy part of the reorg (most files moved around)
laca
parents:
diff changeset
   757
+                goto err;
b16e349d18c5 the easy part of the reorg (most files moved around)
laca
parents:
diff changeset
   758
+        }
b16e349d18c5 the easy part of the reorg (most files moved around)
laca
parents:
diff changeset
   759
+
b16e349d18c5 the easy part of the reorg (most files moved around)
laca
parents:
diff changeset
   760
+
b16e349d18c5 the easy part of the reorg (most files moved around)
laca
parents:
diff changeset
   761
+        /* pkey += pSize - BN_num_bytes(p); this line is wrong  SAB  this is so that the field is padded with leading zeros */
b16e349d18c5 the easy part of the reorg (most files moved around)
laca
parents:
diff changeset
   762
+        pkey += pSize - BN_num_bytes(dmp1);  /* SAB  this is so that the field is padded with leading zeros */
b16e349d18c5 the easy part of the reorg (most files moved around)
laca
parents:
diff changeset
   763
+
b16e349d18c5 the easy part of the reorg (most files moved around)
laca
parents:
diff changeset
   764
+        BN_bn2bin(dmp1, pkey);
b16e349d18c5 the easy part of the reorg (most files moved around)
laca
parents:
diff changeset
   765
+        pkey += BN_num_bytes(dmp1);   /* move the pointer */
b16e349d18c5 the easy part of the reorg (most files moved around)
laca
parents:
diff changeset
   766
+
b16e349d18c5 the easy part of the reorg (most files moved around)
laca
parents:
diff changeset
   767
+        BN_bn2bin(dmq1, pkey);    /* Copy dmq1 */
b16e349d18c5 the easy part of the reorg (most files moved around)
laca
parents:
diff changeset
   768
+        pkey += qSize ;          /* dmq1 is qSize but somewhere we should really check this */
b16e349d18c5 the easy part of the reorg (most files moved around)
laca
parents:
diff changeset
   769
+        pkey += pSize - BN_num_bytes(p); /* the next field is padded with leading zeros */
b16e349d18c5 the easy part of the reorg (most files moved around)
laca
parents:
diff changeset
   770
+
b16e349d18c5 the easy part of the reorg (most files moved around)
laca
parents:
diff changeset
   771
+        BN_bn2bin(p, pkey);
b16e349d18c5 the easy part of the reorg (most files moved around)
laca
parents:
diff changeset
   772
+
b16e349d18c5 the easy part of the reorg (most files moved around)
laca
parents:
diff changeset
   773
+        pkey += BN_num_bytes(p);  /* move the pointer however many bytes we moved it */
b16e349d18c5 the easy part of the reorg (most files moved around)
laca
parents:
diff changeset
   774
+
b16e349d18c5 the easy part of the reorg (most files moved around)
laca
parents:
diff changeset
   775
+        BN_bn2bin(q, pkey);
b16e349d18c5 the easy part of the reorg (most files moved around)
laca
parents:
diff changeset
   776
+
b16e349d18c5 the easy part of the reorg (most files moved around)
laca
parents:
diff changeset
   777
+        pkey += qSize ;    /* Move the pointer to the next offset in the buffer */
b16e349d18c5 the easy part of the reorg (most files moved around)
laca
parents:
diff changeset
   778
+        pkey += pSize - BN_num_bytes(iqmp);  /* Another zero padded field */
b16e349d18c5 the easy part of the reorg (most files moved around)
laca
parents:
diff changeset
   779
+        BN_bn2bin(iqmp, pkey);
b16e349d18c5 the easy part of the reorg (most files moved around)
laca
parents:
diff changeset
   780
+
b16e349d18c5 the easy part of the reorg (most files moved around)
laca
parents:
diff changeset
   781
+        /* Prepare the argument and response */
b16e349d18c5 the easy part of the reorg (most files moved around)
laca
parents:
diff changeset
   782
+
b16e349d18c5 the easy part of the reorg (most files moved around)
laca
parents:
diff changeset
   783
+	outLen = CORRECT_ENDIANNESS(privKey->qLength) * 2;  /* correct endianess is used here because the privKey structures
b16e349d18c5 the easy part of the reorg (most files moved around)
laca
parents:
diff changeset
   784
+                                                            fields were converted  for endianess above  This makes it into
b16e349d18c5 the easy part of the reorg (most files moved around)
laca
parents:
diff changeset
   785
+                                                            native */
b16e349d18c5 the easy part of the reorg (most files moved around)
laca
parents:
diff changeset
   786
+
b16e349d18c5 the easy part of the reorg (most files moved around)
laca
parents:
diff changeset
   787
+     if (outLen > 256 ) {
b16e349d18c5 the easy part of the reorg (most files moved around)
laca
parents:
diff changeset
   788
+                ENGINEerr(ENGINE_F_IBMCA_MOD_EXP_CRT,ENGINE_R_SIZE_TOO_LARGE_OR_TOO_SMALL);
b16e349d18c5 the easy part of the reorg (most files moved around)
laca
parents:
diff changeset
   789
+                goto err;
b16e349d18c5 the easy part of the reorg (most files moved around)
laca
parents:
diff changeset
   790
+     }
b16e349d18c5 the easy part of the reorg (most files moved around)
laca
parents:
diff changeset
   791
+
b16e349d18c5 the easy part of the reorg (most files moved around)
laca
parents:
diff changeset
   792
+
b16e349d18c5 the easy part of the reorg (most files moved around)
laca
parents:
diff changeset
   793
+     /* SAB Need to check for underflow as well as the case where  outLen is < the argument which would clobber
b16e349d18c5 the easy part of the reorg (most files moved around)
laca
parents:
diff changeset
   794
+      * the prior buffers */
b16e349d18c5 the easy part of the reorg (most files moved around)
laca
parents:
diff changeset
   795
+     if ( outLen < BN_num_bytes(a)) {
b16e349d18c5 the easy part of the reorg (most files moved around)
laca
parents:
diff changeset
   796
+                ENGINEerr(ENGINE_F_IBMCA_MOD_EXP_CRT,ENGINE_R_BN_EXPAND_FAIL);
b16e349d18c5 the easy part of the reorg (most files moved around)
laca
parents:
diff changeset
   797
+     }
b16e349d18c5 the easy part of the reorg (most files moved around)
laca
parents:
diff changeset
   798
+
b16e349d18c5 the easy part of the reorg (most files moved around)
laca
parents:
diff changeset
   799
+     /* This will pad with leading zeros if the argument is less than the key length   this shouldnot really
b16e349d18c5 the easy part of the reorg (most files moved around)
laca
parents:
diff changeset
   800
+      * happen, but since the callers really are responsible for the padding, we need to make sure we have it 
b16e349d18c5 the easy part of the reorg (most files moved around)
laca
parents:
diff changeset
   801
+      * proper */
b16e349d18c5 the easy part of the reorg (most files moved around)
laca
parents:
diff changeset
   802
+
b16e349d18c5 the easy part of the reorg (most files moved around)
laca
parents:
diff changeset
   803
+        BN_bn2bin(a, (unsigned char *)argument->d + outLen -
b16e349d18c5 the easy part of the reorg (most files moved around)
laca
parents:
diff changeset
   804
+                          BN_num_bytes(a));
b16e349d18c5 the easy part of the reorg (most files moved around)
laca
parents:
diff changeset
   805
+
b16e349d18c5 the easy part of the reorg (most files moved around)
laca
parents:
diff changeset
   806
+
b16e349d18c5 the easy part of the reorg (most files moved around)
laca
parents:
diff changeset
   807
+        inLen = outLen;
b16e349d18c5 the easy part of the reorg (most files moved around)
laca
parents:
diff changeset
   808
+
b16e349d18c5 the easy part of the reorg (most files moved around)
laca
parents:
diff changeset
   809
+        memset(result->d, 0, outLen);
b16e349d18c5 the easy part of the reorg (most files moved around)
laca
parents:
diff changeset
   810
+
b16e349d18c5 the easy part of the reorg (most files moved around)
laca
parents:
diff changeset
   811
+        /* Perform the operation */
b16e349d18c5 the easy part of the reorg (most files moved around)
laca
parents:
diff changeset
   812
+
b16e349d18c5 the easy part of the reorg (most files moved around)
laca
parents:
diff changeset
   813
+        if ( (rc = p_icaRsaCrt(handle, inLen, (unsigned char *)argument->d,
b16e349d18c5 the easy part of the reorg (most files moved around)
laca
parents:
diff changeset
   814
+                privKey, &outLen, (unsigned char *)result->d)) != 0)
b16e349d18c5 the easy part of the reorg (most files moved around)
laca
parents:
diff changeset
   815
+                {
b16e349d18c5 the easy part of the reorg (most files moved around)
laca
parents:
diff changeset
   816
+                ENGINEerr(ENGINE_F_IBMCA_MOD_EXP_CRT,ENGINE_R_REQUEST_FAILED);
b16e349d18c5 the easy part of the reorg (most files moved around)
laca
parents:
diff changeset
   817
+                goto err;
b16e349d18c5 the easy part of the reorg (most files moved around)
laca
parents:
diff changeset
   818
+                }
b16e349d18c5 the easy part of the reorg (most files moved around)
laca
parents:
diff changeset
   819
+
b16e349d18c5 the easy part of the reorg (most files moved around)
laca
parents:
diff changeset
   820
+        /* Convert the response */
b16e349d18c5 the easy part of the reorg (most files moved around)
laca
parents:
diff changeset
   821
+
b16e349d18c5 the easy part of the reorg (most files moved around)
laca
parents:
diff changeset
   822
+        BN_bin2bn((unsigned char *)result->d, outLen, r);
b16e349d18c5 the easy part of the reorg (most files moved around)
laca
parents:
diff changeset
   823
+        to_return = 1;
b16e349d18c5 the easy part of the reorg (most files moved around)
laca
parents:
diff changeset
   824
+
b16e349d18c5 the easy part of the reorg (most files moved around)
laca
parents:
diff changeset
   825
+ err:
b16e349d18c5 the easy part of the reorg (most files moved around)
laca
parents:
diff changeset
   826
+        if(argument) ctx->tos--;
b16e349d18c5 the easy part of the reorg (most files moved around)
laca
parents:
diff changeset
   827
+        if(result) ctx->tos--;
b16e349d18c5 the easy part of the reorg (most files moved around)
laca
parents:
diff changeset
   828
+        if(key) ctx->tos--;
b16e349d18c5 the easy part of the reorg (most files moved around)
laca
parents:
diff changeset
   829
+        return to_return;
b16e349d18c5 the easy part of the reorg (most files moved around)
laca
parents:
diff changeset
   830
+
b16e349d18c5 the easy part of the reorg (most files moved around)
laca
parents:
diff changeset
   831
+        }
b16e349d18c5 the easy part of the reorg (most files moved around)
laca
parents:
diff changeset
   832
+
b16e349d18c5 the easy part of the reorg (most files moved around)
laca
parents:
diff changeset
   833
+/* This code was liberated and adapted from the commented-out code in
b16e349d18c5 the easy part of the reorg (most files moved around)
laca
parents:
diff changeset
   834
+ * dsa_ossl.c. Because of the unoptimised form of the Ibmca acceleration
b16e349d18c5 the easy part of the reorg (most files moved around)
laca
parents:
diff changeset
   835
+ * (it doesn't have a CRT form for RSA), this function means that an
b16e349d18c5 the easy part of the reorg (most files moved around)
laca
parents:
diff changeset
   836
+ * Ibmca system running with a DSA server certificate can handshake
b16e349d18c5 the easy part of the reorg (most files moved around)
laca
parents:
diff changeset
   837
+ * around 5 or 6 times faster/more than an equivalent system running with
b16e349d18c5 the easy part of the reorg (most files moved around)
laca
parents:
diff changeset
   838
+ * RSA. Just check out the "signs" statistics from the RSA and DSA parts
b16e349d18c5 the easy part of the reorg (most files moved around)
laca
parents:
diff changeset
   839
+ * of "openssl speed -engine ibmca dsa1024 rsa1024". */
b16e349d18c5 the easy part of the reorg (most files moved around)
laca
parents:
diff changeset
   840
+static int ibmca_dsa_mod_exp(DSA *dsa, BIGNUM *rr, BIGNUM *a1,
b16e349d18c5 the easy part of the reorg (most files moved around)
laca
parents:
diff changeset
   841
+        BIGNUM *p1, BIGNUM *a2, BIGNUM *p2, BIGNUM *m,
b16e349d18c5 the easy part of the reorg (most files moved around)
laca
parents:
diff changeset
   842
+        BN_CTX *ctx, BN_MONT_CTX *in_mont)
b16e349d18c5 the easy part of the reorg (most files moved around)
laca
parents:
diff changeset
   843
+        {
b16e349d18c5 the easy part of the reorg (most files moved around)
laca
parents:
diff changeset
   844
+        BIGNUM t;
b16e349d18c5 the easy part of the reorg (most files moved around)
laca
parents:
diff changeset
   845
+        int to_return = 0;
b16e349d18c5 the easy part of the reorg (most files moved around)
laca
parents:
diff changeset
   846
+
b16e349d18c5 the easy part of the reorg (most files moved around)
laca
parents:
diff changeset
   847
+        BN_init(&t);
b16e349d18c5 the easy part of the reorg (most files moved around)
laca
parents:
diff changeset
   848
+        /* let rr = a1 ^ p1 mod m */
b16e349d18c5 the easy part of the reorg (most files moved around)
laca
parents:
diff changeset
   849
+        if (!ibmca_mod_exp(rr,a1,p1,m,ctx)) goto end;
b16e349d18c5 the easy part of the reorg (most files moved around)
laca
parents:
diff changeset
   850
+        /* let t = a2 ^ p2 mod m */
b16e349d18c5 the easy part of the reorg (most files moved around)
laca
parents:
diff changeset
   851
+        if (!ibmca_mod_exp(&t,a2,p2,m,ctx)) goto end;
b16e349d18c5 the easy part of the reorg (most files moved around)
laca
parents:
diff changeset
   852
+        /* let rr = rr * t mod m */
b16e349d18c5 the easy part of the reorg (most files moved around)
laca
parents:
diff changeset
   853
+        if (!BN_mod_mul(rr,rr,&t,m,ctx)) goto end;
b16e349d18c5 the easy part of the reorg (most files moved around)
laca
parents:
diff changeset
   854
+        to_return = 1;
b16e349d18c5 the easy part of the reorg (most files moved around)
laca
parents:
diff changeset
   855
+ end:
b16e349d18c5 the easy part of the reorg (most files moved around)
laca
parents:
diff changeset
   856
+        BN_free(&t);
b16e349d18c5 the easy part of the reorg (most files moved around)
laca
parents:
diff changeset
   857
+        return to_return;
b16e349d18c5 the easy part of the reorg (most files moved around)
laca
parents:
diff changeset
   858
+        }
b16e349d18c5 the easy part of the reorg (most files moved around)
laca
parents:
diff changeset
   859
+
b16e349d18c5 the easy part of the reorg (most files moved around)
laca
parents:
diff changeset
   860
+
b16e349d18c5 the easy part of the reorg (most files moved around)
laca
parents:
diff changeset
   861
+static int ibmca_mod_exp_dsa(DSA *dsa, BIGNUM *r, BIGNUM *a,
b16e349d18c5 the easy part of the reorg (most files moved around)
laca
parents:
diff changeset
   862
+        const BIGNUM *p, const BIGNUM *m, BN_CTX *ctx,
b16e349d18c5 the easy part of the reorg (most files moved around)
laca
parents:
diff changeset
   863
+        BN_MONT_CTX *m_ctx)
b16e349d18c5 the easy part of the reorg (most files moved around)
laca
parents:
diff changeset
   864
+        {
b16e349d18c5 the easy part of the reorg (most files moved around)
laca
parents:
diff changeset
   865
+        return ibmca_mod_exp(r, a, p, m, ctx);
b16e349d18c5 the easy part of the reorg (most files moved around)
laca
parents:
diff changeset
   866
+        }
b16e349d18c5 the easy part of the reorg (most files moved around)
laca
parents:
diff changeset
   867
+
b16e349d18c5 the easy part of the reorg (most files moved around)
laca
parents:
diff changeset
   868
+/* This function is aliased to mod_exp (with the mont stuff dropped). */
b16e349d18c5 the easy part of the reorg (most files moved around)
laca
parents:
diff changeset
   869
+static int ibmca_mod_exp_mont(BIGNUM *r, BIGNUM *a, const BIGNUM *p,
b16e349d18c5 the easy part of the reorg (most files moved around)
laca
parents:
diff changeset
   870
+        const BIGNUM *m, BN_CTX *ctx, BN_MONT_CTX *m_ctx)
b16e349d18c5 the easy part of the reorg (most files moved around)
laca
parents:
diff changeset
   871
+        {
b16e349d18c5 the easy part of the reorg (most files moved around)
laca
parents:
diff changeset
   872
+        return ibmca_mod_exp(r, a, p, m, ctx);
b16e349d18c5 the easy part of the reorg (most files moved around)
laca
parents:
diff changeset
   873
+        }
b16e349d18c5 the easy part of the reorg (most files moved around)
laca
parents:
diff changeset
   874
+
b16e349d18c5 the easy part of the reorg (most files moved around)
laca
parents:
diff changeset
   875
+/* This function is aliased to mod_exp (with the dh and mont dropped). */
b16e349d18c5 the easy part of the reorg (most files moved around)
laca
parents:
diff changeset
   876
+static int ibmca_mod_exp_dh(DH *dh, BIGNUM *r, BIGNUM *a, const BIGNUM *p,
b16e349d18c5 the easy part of the reorg (most files moved around)
laca
parents:
diff changeset
   877
+        const BIGNUM *m, BN_CTX *ctx, BN_MONT_CTX *m_ctx)
b16e349d18c5 the easy part of the reorg (most files moved around)
laca
parents:
diff changeset
   878
+        {
b16e349d18c5 the easy part of the reorg (most files moved around)
laca
parents:
diff changeset
   879
+        return ibmca_mod_exp(r, a, p, m, ctx);
b16e349d18c5 the easy part of the reorg (most files moved around)
laca
parents:
diff changeset
   880
+        }
b16e349d18c5 the easy part of the reorg (most files moved around)
laca
parents:
diff changeset
   881
+
b16e349d18c5 the easy part of the reorg (most files moved around)
laca
parents:
diff changeset
   882
+/* Random bytes are good */
b16e349d18c5 the easy part of the reorg (most files moved around)
laca
parents:
diff changeset
   883
+static int ibmca_rand_bytes(unsigned char *buf, int num)
b16e349d18c5 the easy part of the reorg (most files moved around)
laca
parents:
diff changeset
   884
+        {
b16e349d18c5 the easy part of the reorg (most files moved around)
laca
parents:
diff changeset
   885
+        int to_return = 0; /* assume failure */
b16e349d18c5 the easy part of the reorg (most files moved around)
laca
parents:
diff changeset
   886
+        unsigned int ret;
b16e349d18c5 the easy part of the reorg (most files moved around)
laca
parents:
diff changeset
   887
+
b16e349d18c5 the easy part of the reorg (most files moved around)
laca
parents:
diff changeset
   888
+
b16e349d18c5 the easy part of the reorg (most files moved around)
laca
parents:
diff changeset
   889
+        if(handle == 0)
b16e349d18c5 the easy part of the reorg (most files moved around)
laca
parents:
diff changeset
   890
+                {
b16e349d18c5 the easy part of the reorg (most files moved around)
laca
parents:
diff changeset
   891
+                ENGINEerr(ENGINE_F_IBMCA_RAND_BYTES,ENGINE_R_NOT_INITIALISED);
b16e349d18c5 the easy part of the reorg (most files moved around)
laca
parents:
diff changeset
   892
+                goto err;
b16e349d18c5 the easy part of the reorg (most files moved around)
laca
parents:
diff changeset
   893
+                }
b16e349d18c5 the easy part of the reorg (most files moved around)
laca
parents:
diff changeset
   894
+
b16e349d18c5 the easy part of the reorg (most files moved around)
laca
parents:
diff changeset
   895
+        ret = p_icaRandomNumberGenerate(handle, num, buf);
b16e349d18c5 the easy part of the reorg (most files moved around)
laca
parents:
diff changeset
   896
+        if (ret < 0)
b16e349d18c5 the easy part of the reorg (most files moved around)
laca
parents:
diff changeset
   897
+                {
b16e349d18c5 the easy part of the reorg (most files moved around)
laca
parents:
diff changeset
   898
+                ENGINEerr(ENGINE_F_IBMCA_RAND_BYTES,ENGINE_R_REQUEST_FAILED);
b16e349d18c5 the easy part of the reorg (most files moved around)
laca
parents:
diff changeset
   899
+                goto err;
b16e349d18c5 the easy part of the reorg (most files moved around)
laca
parents:
diff changeset
   900
+                }
b16e349d18c5 the easy part of the reorg (most files moved around)
laca
parents:
diff changeset
   901
+        to_return = 1;
b16e349d18c5 the easy part of the reorg (most files moved around)
laca
parents:
diff changeset
   902
+ err:
b16e349d18c5 the easy part of the reorg (most files moved around)
laca
parents:
diff changeset
   903
+        return to_return;
b16e349d18c5 the easy part of the reorg (most files moved around)
laca
parents:
diff changeset
   904
+        }
b16e349d18c5 the easy part of the reorg (most files moved around)
laca
parents:
diff changeset
   905
+
b16e349d18c5 the easy part of the reorg (most files moved around)
laca
parents:
diff changeset
   906
+static int ibmca_rand_status(void)
b16e349d18c5 the easy part of the reorg (most files moved around)
laca
parents:
diff changeset
   907
+        {
b16e349d18c5 the easy part of the reorg (most files moved around)
laca
parents:
diff changeset
   908
+        return 1;
b16e349d18c5 the easy part of the reorg (most files moved around)
laca
parents:
diff changeset
   909
+        }
b16e349d18c5 the easy part of the reorg (most files moved around)
laca
parents:
diff changeset
   910
+
b16e349d18c5 the easy part of the reorg (most files moved around)
laca
parents:
diff changeset
   911
+#endif /* !NO_HW_IBMCA */
b16e349d18c5 the easy part of the reorg (most files moved around)
laca
parents:
diff changeset
   912
+#endif /* !NO_HW */
b16e349d18c5 the easy part of the reorg (most files moved around)
laca
parents:
diff changeset
   913
diff -urN -x /home/sbade/dontdirr openssl-engine-0.9.6e.base/crypto/engine/vendor_defns/ica_openssl_api.h openssl-engine-0.9.6e.patch/crypto/engine/vendor_defns/ica_openssl_api.h
b16e349d18c5 the easy part of the reorg (most files moved around)
laca
parents:
diff changeset
   914
--- openssl-engine-0.9.6e.base/crypto/engine/vendor_defns/ica_openssl_api.h	Thu Jan  1 01:00:00 1970
b16e349d18c5 the easy part of the reorg (most files moved around)
laca
parents:
diff changeset
   915
+++ openssl-engine-0.9.6e.patch/crypto/engine/vendor_defns/ica_openssl_api.h	Fri Aug  2 14:37:08 2002
b16e349d18c5 the easy part of the reorg (most files moved around)
laca
parents:
diff changeset
   916
@@ -0,0 +1,189 @@
b16e349d18c5 the easy part of the reorg (most files moved around)
laca
parents:
diff changeset
   917
+
b16e349d18c5 the easy part of the reorg (most files moved around)
laca
parents:
diff changeset
   918
+#ifndef __ICA_OPENSSL_API_H__
b16e349d18c5 the easy part of the reorg (most files moved around)
laca
parents:
diff changeset
   919
+#define __ICA_OPENSSL_API_H__
b16e349d18c5 the easy part of the reorg (most files moved around)
laca
parents:
diff changeset
   920
+
b16e349d18c5 the easy part of the reorg (most files moved around)
laca
parents:
diff changeset
   921
+/**
b16e349d18c5 the easy part of the reorg (most files moved around)
laca
parents:
diff changeset
   922
+ ** abstract data types for API
b16e349d18c5 the easy part of the reorg (most files moved around)
laca
parents:
diff changeset
   923
+ **/
b16e349d18c5 the easy part of the reorg (most files moved around)
laca
parents:
diff changeset
   924
+
b16e349d18c5 the easy part of the reorg (most files moved around)
laca
parents:
diff changeset
   925
+#define ICA_ADAPTER_HANDLE int
b16e349d18c5 the easy part of the reorg (most files moved around)
laca
parents:
diff changeset
   926
+
b16e349d18c5 the easy part of the reorg (most files moved around)
laca
parents:
diff changeset
   927
+#if defined(linux) || defined (_AIX) || defined(sun)
b16e349d18c5 the easy part of the reorg (most files moved around)
laca
parents:
diff changeset
   928
+#define ICA_CALL 
b16e349d18c5 the easy part of the reorg (most files moved around)
laca
parents:
diff changeset
   929
+#endif
b16e349d18c5 the easy part of the reorg (most files moved around)
laca
parents:
diff changeset
   930
+
b16e349d18c5 the easy part of the reorg (most files moved around)
laca
parents:
diff changeset
   931
+#if defined(WIN32) || defined(_WIN32)
b16e349d18c5 the easy part of the reorg (most files moved around)
laca
parents:
diff changeset
   932
+#define ICA_CALL  __stdcall
b16e349d18c5 the easy part of the reorg (most files moved around)
laca
parents:
diff changeset
   933
+#endif
b16e349d18c5 the easy part of the reorg (most files moved around)
laca
parents:
diff changeset
   934
+
b16e349d18c5 the easy part of the reorg (most files moved around)
laca
parents:
diff changeset
   935
+/*------------------------------------------------*
b16e349d18c5 the easy part of the reorg (most files moved around)
laca
parents:
diff changeset
   936
+ | RSA defines and typedefs                       |
b16e349d18c5 the easy part of the reorg (most files moved around)
laca
parents:
diff changeset
   937
+ *------------------------------------------------*/
b16e349d18c5 the easy part of the reorg (most files moved around)
laca
parents:
diff changeset
   938
+ /*
b16e349d18c5 the easy part of the reorg (most files moved around)
laca
parents:
diff changeset
   939
+ * All data elements of the RSA key are in big-endian format
b16e349d18c5 the easy part of the reorg (most files moved around)
laca
parents:
diff changeset
   940
+ * Modulus-Exponent form of key
b16e349d18c5 the easy part of the reorg (most files moved around)
laca
parents:
diff changeset
   941
+ *
b16e349d18c5 the easy part of the reorg (most files moved around)
laca
parents:
diff changeset
   942
+ */
b16e349d18c5 the easy part of the reorg (most files moved around)
laca
parents:
diff changeset
   943
+ #define MAX_EXP_SIZE 256
b16e349d18c5 the easy part of the reorg (most files moved around)
laca
parents:
diff changeset
   944
+ #define MAX_MODULUS_SIZE 256
b16e349d18c5 the easy part of the reorg (most files moved around)
laca
parents:
diff changeset
   945
+ #define MAX_MODEXP_SIZE  (MAX_EXP_SIZE + MAX_MODULUS_SIZE)
b16e349d18c5 the easy part of the reorg (most files moved around)
laca
parents:
diff changeset
   946
+
b16e349d18c5 the easy part of the reorg (most files moved around)
laca
parents:
diff changeset
   947
+ #define MAX_OPERAND_SIZE  MAX_EXP_SIZE
b16e349d18c5 the easy part of the reorg (most files moved around)
laca
parents:
diff changeset
   948
+
b16e349d18c5 the easy part of the reorg (most files moved around)
laca
parents:
diff changeset
   949
+ typedef unsigned char ICA_KEY_RSA_MODEXPO_REC[MAX_MODEXP_SIZE];
b16e349d18c5 the easy part of the reorg (most files moved around)
laca
parents:
diff changeset
   950
+ /*
b16e349d18c5 the easy part of the reorg (most files moved around)
laca
parents:
diff changeset
   951
+ * All data elements of the RSA key are in big-endian format
b16e349d18c5 the easy part of the reorg (most files moved around)
laca
parents:
diff changeset
   952
+ * Chinese Remainder Thereom(CRT) form of key
b16e349d18c5 the easy part of the reorg (most files moved around)
laca
parents:
diff changeset
   953
+ * Used only for Decrypt, the encrypt form is typically Modulus-Exponent
b16e349d18c5 the easy part of the reorg (most files moved around)
laca
parents:
diff changeset
   954
+ *
b16e349d18c5 the easy part of the reorg (most files moved around)
laca
parents:
diff changeset
   955
+ */
b16e349d18c5 the easy part of the reorg (most files moved around)
laca
parents:
diff changeset
   956
+ #define MAX_BP_SIZE 136
b16e349d18c5 the easy part of the reorg (most files moved around)
laca
parents:
diff changeset
   957
+ #define MAX_BQ_SIZE 128
b16e349d18c5 the easy part of the reorg (most files moved around)
laca
parents:
diff changeset
   958
+ #define MAX_NP_SIZE 136
b16e349d18c5 the easy part of the reorg (most files moved around)
laca
parents:
diff changeset
   959
+ #define MAX_NQ_SIZE 128
b16e349d18c5 the easy part of the reorg (most files moved around)
laca
parents:
diff changeset
   960
+ #define MAX_QINV_SIZE 136
b16e349d18c5 the easy part of the reorg (most files moved around)
laca
parents:
diff changeset
   961
+ #define MAX_RSACRT_SIZE (MAX_BP_SIZE+MAX_BQ_SIZE+MAX_NP_SIZE+MAX_NQ_SIZE+MAX_QINV_SIZE)
b16e349d18c5 the easy part of the reorg (most files moved around)
laca
parents:
diff changeset
   962
+
b16e349d18c5 the easy part of the reorg (most files moved around)
laca
parents:
diff changeset
   963
+#define RSA_GEN_OPERAND_MAX   256 /* bytes */
b16e349d18c5 the easy part of the reorg (most files moved around)
laca
parents:
diff changeset
   964
+
b16e349d18c5 the easy part of the reorg (most files moved around)
laca
parents:
diff changeset
   965
+typedef unsigned char ICA_KEY_RSA_CRT_REC[MAX_RSACRT_SIZE];
b16e349d18c5 the easy part of the reorg (most files moved around)
laca
parents:
diff changeset
   966
+/*------------------------------------------------*
b16e349d18c5 the easy part of the reorg (most files moved around)
laca
parents:
diff changeset
   967
+ | RSA key token types                            |
b16e349d18c5 the easy part of the reorg (most files moved around)
laca
parents:
diff changeset
   968
+ *------------------------------------------------*/
b16e349d18c5 the easy part of the reorg (most files moved around)
laca
parents:
diff changeset
   969
+
b16e349d18c5 the easy part of the reorg (most files moved around)
laca
parents:
diff changeset
   970
+#define  RSA_PUBLIC_MODULUS_EXPONENT        3
b16e349d18c5 the easy part of the reorg (most files moved around)
laca
parents:
diff changeset
   971
+#define  RSA_PKCS_PRIVATE_CHINESE_REMAINDER 6
b16e349d18c5 the easy part of the reorg (most files moved around)
laca
parents:
diff changeset
   972
+
b16e349d18c5 the easy part of the reorg (most files moved around)
laca
parents:
diff changeset
   973
+#define KEYTYPE_MODEXPO         1
b16e349d18c5 the easy part of the reorg (most files moved around)
laca
parents:
diff changeset
   974
+#define KEYTYPE_PKCSCRT         2
b16e349d18c5 the easy part of the reorg (most files moved around)
laca
parents:
diff changeset
   975
+
b16e349d18c5 the easy part of the reorg (most files moved around)
laca
parents:
diff changeset
   976
+
b16e349d18c5 the easy part of the reorg (most files moved around)
laca
parents:
diff changeset
   977
+/*------------------------------------------------*
b16e349d18c5 the easy part of the reorg (most files moved around)
laca
parents:
diff changeset
   978
+ | RSA Key Token format                           |
b16e349d18c5 the easy part of the reorg (most files moved around)
laca
parents:
diff changeset
   979
+ *------------------------------------------------*/
b16e349d18c5 the easy part of the reorg (most files moved around)
laca
parents:
diff changeset
   980
+
b16e349d18c5 the easy part of the reorg (most files moved around)
laca
parents:
diff changeset
   981
+/*
b16e349d18c5 the easy part of the reorg (most files moved around)
laca
parents:
diff changeset
   982
+ * NOTE:  All the fields in the ICA_KEY_RSA_MODEXPO structure
b16e349d18c5 the easy part of the reorg (most files moved around)
laca
parents:
diff changeset
   983
+ *        (lengths, offsets, exponents, modulus, etc.) are
b16e349d18c5 the easy part of the reorg (most files moved around)
laca
parents:
diff changeset
   984
+ *        stored in big-endian format
b16e349d18c5 the easy part of the reorg (most files moved around)
laca
parents:
diff changeset
   985
+ */
b16e349d18c5 the easy part of the reorg (most files moved around)
laca
parents:
diff changeset
   986
+
b16e349d18c5 the easy part of the reorg (most files moved around)
laca
parents:
diff changeset
   987
+typedef struct _ICA_KEY_RSA_MODEXPO
b16e349d18c5 the easy part of the reorg (most files moved around)
laca
parents:
diff changeset
   988
+{   unsigned int  keyType;             /* RSA key type.               */
b16e349d18c5 the easy part of the reorg (most files moved around)
laca
parents:
diff changeset
   989
+    unsigned int  keyLength;           /* Total length of the token.  */
b16e349d18c5 the easy part of the reorg (most files moved around)
laca
parents:
diff changeset
   990
+    unsigned int  modulusBitLength;    /* Modulus n bit length.       */
b16e349d18c5 the easy part of the reorg (most files moved around)
laca
parents:
diff changeset
   991
+                                       /* -- Start of the data length.*/
b16e349d18c5 the easy part of the reorg (most files moved around)
laca
parents:
diff changeset
   992
+    unsigned int  nLength;             /* Modulus n = p * q           */
b16e349d18c5 the easy part of the reorg (most files moved around)
laca
parents:
diff changeset
   993
+    unsigned int  expLength;           /* exponent (public or private)*/
b16e349d18c5 the easy part of the reorg (most files moved around)
laca
parents:
diff changeset
   994
+                                       /*   e = 1/d * mod(p-1)(q-1)   */
b16e349d18c5 the easy part of the reorg (most files moved around)
laca
parents:
diff changeset
   995
+                                       /* -- Start of the data offsets*/
b16e349d18c5 the easy part of the reorg (most files moved around)
laca
parents:
diff changeset
   996
+    unsigned int  nOffset;             /* Modulus n .                 */
b16e349d18c5 the easy part of the reorg (most files moved around)
laca
parents:
diff changeset
   997
+    unsigned int  expOffset;           /* exponent (public or private)*/
b16e349d18c5 the easy part of the reorg (most files moved around)
laca
parents:
diff changeset
   998
+    unsigned char reserved[112];       /* reserved area               */
b16e349d18c5 the easy part of the reorg (most files moved around)
laca
parents:
diff changeset
   999
+                                       /* -- Start of the variable -- */
b16e349d18c5 the easy part of the reorg (most files moved around)
laca
parents:
diff changeset
  1000
+                                       /* -- length token data.    -- */
b16e349d18c5 the easy part of the reorg (most files moved around)
laca
parents:
diff changeset
  1001
+    ICA_KEY_RSA_MODEXPO_REC keyRecord;
b16e349d18c5 the easy part of the reorg (most files moved around)
laca
parents:
diff changeset
  1002
+} ICA_KEY_RSA_MODEXPO;
b16e349d18c5 the easy part of the reorg (most files moved around)
laca
parents:
diff changeset
  1003
+#define SZ_HEADER_MODEXPO (sizeof(ICA_KEY_RSA_MODEXPO) - sizeof(ICA_KEY_RSA_MODEXPO_REC))
b16e349d18c5 the easy part of the reorg (most files moved around)
laca
parents:
diff changeset
  1004
+
b16e349d18c5 the easy part of the reorg (most files moved around)
laca
parents:
diff changeset
  1005
+/*
b16e349d18c5 the easy part of the reorg (most files moved around)
laca
parents:
diff changeset
  1006
+ * NOTE:  All the fields in the ICA_KEY_RSA_CRT structure
b16e349d18c5 the easy part of the reorg (most files moved around)
laca
parents:
diff changeset
  1007
+ *        (lengths, offsets, exponents, modulus, etc.) are
b16e349d18c5 the easy part of the reorg (most files moved around)
laca
parents:
diff changeset
  1008
+ *        stored in big-endian format
b16e349d18c5 the easy part of the reorg (most files moved around)
laca
parents:
diff changeset
  1009
+ */
b16e349d18c5 the easy part of the reorg (most files moved around)
laca
parents:
diff changeset
  1010
+
b16e349d18c5 the easy part of the reorg (most files moved around)
laca
parents:
diff changeset
  1011
+typedef struct _ICA_KEY_RSA_CRT
b16e349d18c5 the easy part of the reorg (most files moved around)
laca
parents:
diff changeset
  1012
+{   unsigned int  keyType;             /* RSA key type.               */
b16e349d18c5 the easy part of the reorg (most files moved around)
laca
parents:
diff changeset
  1013
+    unsigned int  keyLength;           /* Total length of the token.  */
b16e349d18c5 the easy part of the reorg (most files moved around)
laca
parents:
diff changeset
  1014
+    unsigned int  modulusBitLength;    /* Modulus n bit length.       */
b16e349d18c5 the easy part of the reorg (most files moved around)
laca
parents:
diff changeset
  1015
+                                       /* -- Start of the data length.*/
b16e349d18c5 the easy part of the reorg (most files moved around)
laca
parents:
diff changeset
  1016
+#if _AIX
b16e349d18c5 the easy part of the reorg (most files moved around)
laca
parents:
diff changeset
  1017
+    unsigned int  nLength;             /* Modulus n = p * q           */
b16e349d18c5 the easy part of the reorg (most files moved around)
laca
parents:
diff changeset
  1018
+#endif
b16e349d18c5 the easy part of the reorg (most files moved around)
laca
parents:
diff changeset
  1019
+    unsigned int  pLength;             /* Prime number p .            */
b16e349d18c5 the easy part of the reorg (most files moved around)
laca
parents:
diff changeset
  1020
+    unsigned int  qLength;             /* Prime number q .            */
b16e349d18c5 the easy part of the reorg (most files moved around)
laca
parents:
diff changeset
  1021
+    unsigned int  dpLength;            /* dp = d * mod(p-1) .         */
b16e349d18c5 the easy part of the reorg (most files moved around)
laca
parents:
diff changeset
  1022
+    unsigned int  dqLength;            /* dq = d * mod(q-1) .         */
b16e349d18c5 the easy part of the reorg (most files moved around)
laca
parents:
diff changeset
  1023
+    unsigned int  qInvLength;          /* PKCS: qInv = Ap/q           */
b16e349d18c5 the easy part of the reorg (most files moved around)
laca
parents:
diff changeset
  1024
+                                       /* -- Start of the data offsets*/
b16e349d18c5 the easy part of the reorg (most files moved around)
laca
parents:
diff changeset
  1025
+#if _AIX
b16e349d18c5 the easy part of the reorg (most files moved around)
laca
parents:
diff changeset
  1026
+    unsigned int  nOffset;             /* Modulus n .                 */
b16e349d18c5 the easy part of the reorg (most files moved around)
laca
parents:
diff changeset
  1027
+#endif
b16e349d18c5 the easy part of the reorg (most files moved around)
laca
parents:
diff changeset
  1028
+    unsigned int  pOffset;             /* Prime number p .            */
b16e349d18c5 the easy part of the reorg (most files moved around)
laca
parents:
diff changeset
  1029
+    unsigned int  qOffset;             /* Prime number q .            */
b16e349d18c5 the easy part of the reorg (most files moved around)
laca
parents:
diff changeset
  1030
+    unsigned int  dpOffset;            /* dp .                        */
b16e349d18c5 the easy part of the reorg (most files moved around)
laca
parents:
diff changeset
  1031
+    unsigned int  dqOffset;            /* dq .                        */
b16e349d18c5 the easy part of the reorg (most files moved around)
laca
parents:
diff changeset
  1032
+    unsigned int  qInvOffset;          /* qInv for PKCS               */
b16e349d18c5 the easy part of the reorg (most files moved around)
laca
parents:
diff changeset
  1033
+#if _AIX
b16e349d18c5 the easy part of the reorg (most files moved around)
laca
parents:
diff changeset
  1034
+    unsigned char reserved[80];        /* reserved area               */
b16e349d18c5 the easy part of the reorg (most files moved around)
laca
parents:
diff changeset
  1035
+#else
b16e349d18c5 the easy part of the reorg (most files moved around)
laca
parents:
diff changeset
  1036
+    unsigned char reserved[88];        /* reserved area               */
b16e349d18c5 the easy part of the reorg (most files moved around)
laca
parents:
diff changeset
  1037
+#endif
b16e349d18c5 the easy part of the reorg (most files moved around)
laca
parents:
diff changeset
  1038
+                                       /* -- Start of the variable -- */
b16e349d18c5 the easy part of the reorg (most files moved around)
laca
parents:
diff changeset
  1039
+                                       /* -- length token data.    -- */
b16e349d18c5 the easy part of the reorg (most files moved around)
laca
parents:
diff changeset
  1040
+    ICA_KEY_RSA_CRT_REC keyRecord;
b16e349d18c5 the easy part of the reorg (most files moved around)
laca
parents:
diff changeset
  1041
+} ICA_KEY_RSA_CRT;
b16e349d18c5 the easy part of the reorg (most files moved around)
laca
parents:
diff changeset
  1042
+#define SZ_HEADER_CRT (sizeof(ICA_KEY_RSA_CRT) - sizeof(ICA_KEY_RSA_CRT_REC))
b16e349d18c5 the easy part of the reorg (most files moved around)
laca
parents:
diff changeset
  1043
+
b16e349d18c5 the easy part of the reorg (most files moved around)
laca
parents:
diff changeset
  1044
+unsigned int
b16e349d18c5 the easy part of the reorg (most files moved around)
laca
parents:
diff changeset
  1045
+icaOpenAdapter( unsigned int        adapterId,
b16e349d18c5 the easy part of the reorg (most files moved around)
laca
parents:
diff changeset
  1046
+	        ICA_ADAPTER_HANDLE *pAdapterHandle );
b16e349d18c5 the easy part of the reorg (most files moved around)
laca
parents:
diff changeset
  1047
+
b16e349d18c5 the easy part of the reorg (most files moved around)
laca
parents:
diff changeset
  1048
+unsigned int
b16e349d18c5 the easy part of the reorg (most files moved around)
laca
parents:
diff changeset
  1049
+icaCloseAdapter( ICA_ADAPTER_HANDLE adapterHandle );
b16e349d18c5 the easy part of the reorg (most files moved around)
laca
parents:
diff changeset
  1050
+
b16e349d18c5 the easy part of the reorg (most files moved around)
laca
parents:
diff changeset
  1051
+unsigned int
b16e349d18c5 the easy part of the reorg (most files moved around)
laca
parents:
diff changeset
  1052
+icaRsaModExpo( ICA_ADAPTER_HANDLE    hAdapterHandle,
b16e349d18c5 the easy part of the reorg (most files moved around)
laca
parents:
diff changeset
  1053
+	       unsigned int          inputDataLength,
b16e349d18c5 the easy part of the reorg (most files moved around)
laca
parents:
diff changeset
  1054
+	       unsigned char        *pInputData,
b16e349d18c5 the easy part of the reorg (most files moved around)
laca
parents:
diff changeset
  1055
+	       ICA_KEY_RSA_MODEXPO  *pKeyModExpo,
b16e349d18c5 the easy part of the reorg (most files moved around)
laca
parents:
diff changeset
  1056
+	       unsigned int         *pOutputDataLength,
b16e349d18c5 the easy part of the reorg (most files moved around)
laca
parents:
diff changeset
  1057
+	       unsigned char        *pOutputData );
b16e349d18c5 the easy part of the reorg (most files moved around)
laca
parents:
diff changeset
  1058
+
b16e349d18c5 the easy part of the reorg (most files moved around)
laca
parents:
diff changeset
  1059
+unsigned int
b16e349d18c5 the easy part of the reorg (most files moved around)
laca
parents:
diff changeset
  1060
+icaRsaCrt( ICA_ADAPTER_HANDLE     hAdapterHandle,
b16e349d18c5 the easy part of the reorg (most files moved around)
laca
parents:
diff changeset
  1061
+	   unsigned int           inputDataLength,
b16e349d18c5 the easy part of the reorg (most files moved around)
laca
parents:
diff changeset
  1062
+	   unsigned char         *pInputData,
b16e349d18c5 the easy part of the reorg (most files moved around)
laca
parents:
diff changeset
  1063
+	   ICA_KEY_RSA_CRT       *pKeyCrt,
b16e349d18c5 the easy part of the reorg (most files moved around)
laca
parents:
diff changeset
  1064
+	   unsigned int          *pOutputDataLength,
b16e349d18c5 the easy part of the reorg (most files moved around)
laca
parents:
diff changeset
  1065
+	   unsigned char         *pOutputData );
b16e349d18c5 the easy part of the reorg (most files moved around)
laca
parents:
diff changeset
  1066
+
b16e349d18c5 the easy part of the reorg (most files moved around)
laca
parents:
diff changeset
  1067
+unsigned int
b16e349d18c5 the easy part of the reorg (most files moved around)
laca
parents:
diff changeset
  1068
+icaRandomNumberGenerate( ICA_ADAPTER_HANDLE  hAdapterHandle,
b16e349d18c5 the easy part of the reorg (most files moved around)
laca
parents:
diff changeset
  1069
+			 unsigned int        outputDataLength,
b16e349d18c5 the easy part of the reorg (most files moved around)
laca
parents:
diff changeset
  1070
+			 unsigned char      *pOutputData );
b16e349d18c5 the easy part of the reorg (most files moved around)
laca
parents:
diff changeset
  1071
+
b16e349d18c5 the easy part of the reorg (most files moved around)
laca
parents:
diff changeset
  1072
+/* Specific macros and definitions to not have IFDEF;s all over the
b16e349d18c5 the easy part of the reorg (most files moved around)
laca
parents:
diff changeset
  1073
+   main code */
b16e349d18c5 the easy part of the reorg (most files moved around)
laca
parents:
diff changeset
  1074
+
b16e349d18c5 the easy part of the reorg (most files moved around)
laca
parents:
diff changeset
  1075
+#if (_AIX)
b16e349d18c5 the easy part of the reorg (most files moved around)
laca
parents:
diff changeset
  1076
+static const char *IBMCA_LIBNAME = "/lib/libica.a(shr.o)";
b16e349d18c5 the easy part of the reorg (most files moved around)
laca
parents:
diff changeset
  1077
+#elif (WIN32)
b16e349d18c5 the easy part of the reorg (most files moved around)
laca
parents:
diff changeset
  1078
+static const char *IBMCA_LIBNAME = "cryptica";
b16e349d18c5 the easy part of the reorg (most files moved around)
laca
parents:
diff changeset
  1079
+#else
b16e349d18c5 the easy part of the reorg (most files moved around)
laca
parents:
diff changeset
  1080
+static const char *IBMCA_LIBNAME = "ica";
b16e349d18c5 the easy part of the reorg (most files moved around)
laca
parents:
diff changeset
  1081
+#endif
b16e349d18c5 the easy part of the reorg (most files moved around)
laca
parents:
diff changeset
  1082
+
b16e349d18c5 the easy part of the reorg (most files moved around)
laca
parents:
diff changeset
  1083
+#if (WIN32)
b16e349d18c5 the easy part of the reorg (most files moved around)
laca
parents:
diff changeset
  1084
+/*
b16e349d18c5 the easy part of the reorg (most files moved around)
laca
parents:
diff changeset
  1085
+ The ICA_KEY_RSA_MODEXPO & ICA_KEY_RSA_CRT lengths and
b16e349d18c5 the easy part of the reorg (most files moved around)
laca
parents:
diff changeset
  1086
+ offsets must be in big-endian format.
b16e349d18c5 the easy part of the reorg (most files moved around)
laca
parents:
diff changeset
  1087
+
b16e349d18c5 the easy part of the reorg (most files moved around)
laca
parents:
diff changeset
  1088
+*/
b16e349d18c5 the easy part of the reorg (most files moved around)
laca
parents:
diff changeset
  1089
+#define CORRECT_ENDIANNESS(b) (  \
b16e349d18c5 the easy part of the reorg (most files moved around)
laca
parents:
diff changeset
  1090
+                             (((unsigned long) (b) & 0x000000ff) << 24) |  \
b16e349d18c5 the easy part of the reorg (most files moved around)
laca
parents:
diff changeset
  1091
+                             (((unsigned long) (b) & 0x0000ff00) <<  8) |  \
b16e349d18c5 the easy part of the reorg (most files moved around)
laca
parents:
diff changeset
  1092
+                             (((unsigned long) (b) & 0x00ff0000) >>  8) |  \
b16e349d18c5 the easy part of the reorg (most files moved around)
laca
parents:
diff changeset
  1093
+                             (((unsigned long) (b) & 0xff000000) >> 24)    \
b16e349d18c5 the easy part of the reorg (most files moved around)
laca
parents:
diff changeset
  1094
+                             )
b16e349d18c5 the easy part of the reorg (most files moved around)
laca
parents:
diff changeset
  1095
+#define CRT_KEY_TYPE   RSA_PKCS_PRIVATE_CHINESE_REMAINDER
b16e349d18c5 the easy part of the reorg (most files moved around)
laca
parents:
diff changeset
  1096
+#define ME_KEY_TYPE    RSA_PUBLIC_MODULUS_EXPONENT
b16e349d18c5 the easy part of the reorg (most files moved around)
laca
parents:
diff changeset
  1097
+#else
b16e349d18c5 the easy part of the reorg (most files moved around)
laca
parents:
diff changeset
  1098
+#define CORRECT_ENDIANNESS(b) (b)
b16e349d18c5 the easy part of the reorg (most files moved around)
laca
parents:
diff changeset
  1099
+#define CRT_KEY_TYPE       KEYTYPE_PKCSCRT
b16e349d18c5 the easy part of the reorg (most files moved around)
laca
parents:
diff changeset
  1100
+#define ME_KEY_TYPE        KEYTYPE_MODEXPO
b16e349d18c5 the easy part of the reorg (most files moved around)
laca
parents:
diff changeset
  1101
+#endif
b16e349d18c5 the easy part of the reorg (most files moved around)
laca
parents:
diff changeset
  1102
+
b16e349d18c5 the easy part of the reorg (most files moved around)
laca
parents:
diff changeset
  1103
+
b16e349d18c5 the easy part of the reorg (most files moved around)
laca
parents:
diff changeset
  1104
+
b16e349d18c5 the easy part of the reorg (most files moved around)
laca
parents:
diff changeset
  1105
+#endif   /* __ICA_OPENSSL_API_H__ */