OpenSSL  1.0.1c
 All Classes Files Functions Variables Typedefs Enumerations Enumerator Macros
ica_openssl_api.h
Go to the documentation of this file.
1 
2 #ifndef __ICA_OPENSSL_API_H__
3 #define __ICA_OPENSSL_API_H__
4 
9 #define ICA_ADAPTER_HANDLE int
10 
11 #if defined(linux) || defined (_AIX)
12 #define ICA_CALL
13 #endif
14 
15 #if defined(WIN32) || defined(_WIN32)
16 #define ICA_CALL __stdcall
17 #endif
18 
19 /*------------------------------------------------*
20  | RSA defines and typedefs |
21  *------------------------------------------------*/
22  /*
23  * All data elements of the RSA key are in big-endian format
24  * Modulus-Exponent form of key
25  *
26  */
27  #define MAX_EXP_SIZE 256
28  #define MAX_MODULUS_SIZE 256
29  #define MAX_MODEXP_SIZE (MAX_EXP_SIZE + MAX_MODULUS_SIZE)
30 
31  #define MAX_OPERAND_SIZE MAX_EXP_SIZE
32 
33  typedef unsigned char ICA_KEY_RSA_MODEXPO_REC[MAX_MODEXP_SIZE];
34  /*
35  * All data elements of the RSA key are in big-endian format
36  * Chinese Remainder Thereom(CRT) form of key
37  * Used only for Decrypt, the encrypt form is typically Modulus-Exponent
38  *
39  */
40  #define MAX_BP_SIZE 136
41  #define MAX_BQ_SIZE 128
42  #define MAX_NP_SIZE 136
43  #define MAX_NQ_SIZE 128
44  #define MAX_QINV_SIZE 136
45  #define MAX_RSACRT_SIZE (MAX_BP_SIZE+MAX_BQ_SIZE+MAX_NP_SIZE+MAX_NQ_SIZE+MAX_QINV_SIZE)
46 
47 #define RSA_GEN_OPERAND_MAX 256 /* bytes */
48 
49 typedef unsigned char ICA_KEY_RSA_CRT_REC[MAX_RSACRT_SIZE];
50 /*------------------------------------------------*
51  | RSA key token types |
52  *------------------------------------------------*/
53 
54 #define RSA_PUBLIC_MODULUS_EXPONENT 3
55 #define RSA_PKCS_PRIVATE_CHINESE_REMAINDER 6
56 
57 #define KEYTYPE_MODEXPO 1
58 #define KEYTYPE_PKCSCRT 2
59 
60 
61 /*------------------------------------------------*
62  | RSA Key Token format |
63  *------------------------------------------------*/
64 
65 /*
66  * NOTE: All the fields in the ICA_KEY_RSA_MODEXPO structure
67  * (lengths, offsets, exponents, modulus, etc.) are
68  * stored in big-endian format
69  */
70 
71 typedef struct _ICA_KEY_RSA_MODEXPO
72 { unsigned int keyType; /* RSA key type. */
73  unsigned int keyLength; /* Total length of the token. */
74  unsigned int modulusBitLength; /* Modulus n bit length. */
75  /* -- Start of the data length.*/
76  unsigned int nLength; /* Modulus n = p * q */
77  unsigned int expLength; /* exponent (public or private)*/
78  /* e = 1/d * mod(p-1)(q-1) */
79  /* -- Start of the data offsets*/
80  unsigned int nOffset; /* Modulus n . */
81  unsigned int expOffset; /* exponent (public or private)*/
82  unsigned char reserved[112]; /* reserved area */
83  /* -- Start of the variable -- */
84  /* -- length token data. -- */
87 #define SZ_HEADER_MODEXPO (sizeof(ICA_KEY_RSA_MODEXPO) - sizeof(ICA_KEY_RSA_MODEXPO_REC))
88 
89 /*
90  * NOTE: All the fields in the ICA_KEY_RSA_CRT structure
91  * (lengths, offsets, exponents, modulus, etc.) are
92  * stored in big-endian format
93  */
94 
95 typedef struct _ICA_KEY_RSA_CRT
96 { unsigned int keyType; /* RSA key type. */
97  unsigned int keyLength; /* Total length of the token. */
98  unsigned int modulusBitLength; /* Modulus n bit length. */
99  /* -- Start of the data length.*/
100 #if _AIX
101  unsigned int nLength; /* Modulus n = p * q */
102 #endif
103  unsigned int pLength; /* Prime number p . */
104  unsigned int qLength; /* Prime number q . */
105  unsigned int dpLength; /* dp = d * mod(p-1) . */
106  unsigned int dqLength; /* dq = d * mod(q-1) . */
107  unsigned int qInvLength; /* PKCS: qInv = Ap/q */
108  /* -- Start of the data offsets*/
109 #if _AIX
110  unsigned int nOffset; /* Modulus n . */
111 #endif
112  unsigned int pOffset; /* Prime number p . */
113  unsigned int qOffset; /* Prime number q . */
114  unsigned int dpOffset; /* dp . */
115  unsigned int dqOffset; /* dq . */
116  unsigned int qInvOffset; /* qInv for PKCS */
117 #if _AIX
118  unsigned char reserved[80]; /* reserved area */
119 #else
120  unsigned char reserved[88]; /* reserved area */
121 #endif
122  /* -- Start of the variable -- */
123  /* -- length token data. -- */
126 #define SZ_HEADER_CRT (sizeof(ICA_KEY_RSA_CRT) - sizeof(ICA_KEY_RSA_CRT_REC))
127 
128 unsigned int
129 icaOpenAdapter( unsigned int adapterId,
130  ICA_ADAPTER_HANDLE *pAdapterHandle );
131 
132 unsigned int
133 icaCloseAdapter( ICA_ADAPTER_HANDLE adapterHandle );
134 
135 unsigned int
136 icaRsaModExpo( ICA_ADAPTER_HANDLE hAdapterHandle,
137  unsigned int inputDataLength,
138  unsigned char *pInputData,
139  ICA_KEY_RSA_MODEXPO *pKeyModExpo,
140  unsigned int *pOutputDataLength,
141  unsigned char *pOutputData );
142 
143 unsigned int
144 icaRsaCrt( ICA_ADAPTER_HANDLE hAdapterHandle,
145  unsigned int inputDataLength,
146  unsigned char *pInputData,
147  ICA_KEY_RSA_CRT *pKeyCrt,
148  unsigned int *pOutputDataLength,
149  unsigned char *pOutputData );
150 
151 unsigned int
153  unsigned int outputDataLength,
154  unsigned char *pOutputData );
155 
156 /* Specific macros and definitions to not have IFDEF;s all over the
157  main code */
158 
159 #if (_AIX)
160 static const char *IBMCA_LIBNAME = "/lib/libica.a(shr.o)";
161 #elif (WIN32)
162 static const char *IBMCA_LIBNAME = "cryptica";
163 #else
164 static const char *IBMCA_LIBNAME = "ica";
165 #endif
166 
167 #if (WIN32)
168 /*
169  The ICA_KEY_RSA_MODEXPO & ICA_KEY_RSA_CRT lengths and
170  offsets must be in big-endian format.
171 
172 */
173 #define CORRECT_ENDIANNESS(b) ( \
174  (((unsigned long) (b) & 0x000000ff) << 24) | \
175  (((unsigned long) (b) & 0x0000ff00) << 8) | \
176  (((unsigned long) (b) & 0x00ff0000) >> 8) | \
177  (((unsigned long) (b) & 0xff000000) >> 24) \
178  )
179 #define CRT_KEY_TYPE RSA_PKCS_PRIVATE_CHINESE_REMAINDER
180 #define ME_KEY_TYPE RSA_PUBLIC_MODULUS_EXPONENT
181 #else
182 #define CORRECT_ENDIANNESS(b) (b)
183 #define CRT_KEY_TYPE KEYTYPE_PKCSCRT
184 #define ME_KEY_TYPE KEYTYPE_MODEXPO
185 #endif
186 
187 
188 
189 #endif /* __ICA_OPENSSL_API_H__ */