1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19 package org.apache.commons.crypto.jna;
20
21 import java.nio.ByteBuffer;
22
23 import org.apache.commons.crypto.Crypto;
24
25 import com.sun.jna.Native;
26 import com.sun.jna.NativeLong;
27 import com.sun.jna.ptr.PointerByReference;
28
29 final class OpenSsl11XNativeJna implements OpenSslInterfaceNativeJna {
30
31 static final boolean INIT_OK;
32
33 static final Throwable INIT_ERROR;
34
35 static {
36 boolean ok = false;
37 Throwable thrown = null;
38 try {
39 final String libName = System.getProperty(Crypto.CONF_PREFIX + OpenSslNativeJna.class.getSimpleName(), "crypto");
40 OpenSslJna.debug("Native.register('%s')", libName);
41 Native.register(libName);
42 ok = true;
43 } catch (final Exception | UnsatisfiedLinkError e) {
44 thrown = e;
45 } finally {
46 INIT_OK = ok;
47 INIT_ERROR = thrown;
48 }
49 }
50
51
52
53
54
55
56
57
58
59
60 public static native PointerByReference ENGINE_by_id(String id);
61
62
63
64
65
66
67
68
69 public static native int ENGINE_finish(PointerByReference e);
70
71
72
73
74
75
76
77
78 public static native int ENGINE_free(PointerByReference e);
79
80
81
82
83
84
85
86
87
88 public static native int ENGINE_init(PointerByReference e);
89
90
91
92
93
94
95
96
97
98
99 public static native int ENGINE_set_default(PointerByReference e, int flags);
100
101
102
103
104
105
106
107
108
109
110
111
112 public static native String ERR_error_string(NativeLong err, char[] null_);
113
114
115
116
117 public static native NativeLong ERR_peek_error();
118
119
120
121
122 public static native PointerByReference EVP_aes_128_cbc();
123
124
125
126
127 public static native PointerByReference EVP_aes_128_ctr();
128
129
130
131
132 public static native PointerByReference EVP_aes_192_cbc();
133
134
135
136
137 public static native PointerByReference EVP_aes_192_ctr();
138
139
140
141
142 public static native PointerByReference EVP_aes_256_cbc();
143
144
145
146
147 public static native PointerByReference EVP_aes_256_ctr();
148
149
150
151
152
153
154
155
156 public static native void EVP_CIPHER_CTX_free(PointerByReference c);
157
158
159
160
161
162
163 public static native PointerByReference EVP_CIPHER_CTX_new();
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182 public static native int EVP_CIPHER_CTX_set_padding(PointerByReference c, int pad);
183
184
185
186
187
188
189
190
191
192
193
194
195 public static native int EVP_CipherFinal_ex(PointerByReference ctx, ByteBuffer bout,
196 int[] outl);
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218 public static native int EVP_CipherInit_ex(PointerByReference ctx, PointerByReference cipher,
219 PointerByReference impl, byte[] key, byte[] iv, int enc);
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236 public static native int EVP_CipherUpdate(PointerByReference ctx, ByteBuffer bout, int[] outl,
237 ByteBuffer in, int inl);
238
239
240
241
242
243
244
245
246
247
248 public static native String OpenSSL_version(int type);
249
250
251
252
253
254
255
256
257
258
259 public static native int RAND_bytes(ByteBuffer buf, int num);
260
261
262
263
264
265
266
267 public static native PointerByReference RAND_get_rand_method();
268
269
270
271 @Override
272 public PointerByReference _ENGINE_by_id(final String string) {
273 return ENGINE_by_id(string);
274 }
275
276 @Override
277 public int _ENGINE_cleanup() {
278 return 0;
279 }
280
281 @Override
282 public int _ENGINE_finish(final PointerByReference rdrandEngine) {
283 return ENGINE_finish(rdrandEngine);
284 }
285
286 @Override
287 public int _ENGINE_free(final PointerByReference rdrandEngine) {
288 return ENGINE_free(rdrandEngine);
289 }
290
291 @Override
292 public int _ENGINE_init(final PointerByReference rdrandEngine) {
293 return ENGINE_init(rdrandEngine);
294 }
295
296 @Override
297 public void _ENGINE_load_rdrand() {
298
299 }
300
301 @Override
302 public int _ENGINE_set_default(final PointerByReference rdrandEngine, final int flags) {
303 return ENGINE_set_default(rdrandEngine, flags);
304 }
305
306 @Override
307 public String _ERR_error_string(final NativeLong err, final char[] buff) {
308 return ERR_error_string(err, buff);
309 }
310
311 @Override
312 public NativeLong _ERR_peek_error() {
313 return ERR_peek_error();
314 }
315
316 @Override
317 public PointerByReference _EVP_aes_128_cbc() {
318 return EVP_aes_128_cbc();
319 }
320
321 @Override
322 public PointerByReference _EVP_aes_128_ctr() {
323 return EVP_aes_128_ctr();
324 }
325
326 @Override
327 public PointerByReference _EVP_aes_192_cbc() {
328 return EVP_aes_192_cbc();
329 }
330
331 @Override
332 public PointerByReference _EVP_aes_192_ctr() {
333 return EVP_aes_192_ctr();
334 }
335
336 @Override
337 public PointerByReference _EVP_aes_256_cbc() {
338 return EVP_aes_256_cbc();
339 }
340
341 @Override
342 public PointerByReference _EVP_aes_256_ctr() {
343 return EVP_aes_256_ctr();
344 }
345
346 @Override
347 public void _EVP_CIPHER_CTX_cleanup(final PointerByReference context) {
348
349 }
350
351 @Override
352 public void _EVP_CIPHER_CTX_free(final PointerByReference context) {
353 EVP_CIPHER_CTX_free(context);
354 }
355
356 @Override
357 public PointerByReference _EVP_CIPHER_CTX_new() {
358 return EVP_CIPHER_CTX_new();
359 }
360
361 @Override
362 public int _EVP_CIPHER_CTX_set_padding(final PointerByReference context, final int padding) {
363 return EVP_CIPHER_CTX_set_padding(context, padding);
364 }
365
366 @Override
367 public int _EVP_CipherFinal_ex(final PointerByReference context, final ByteBuffer outBuffer, final int[] outlen) {
368 return EVP_CipherFinal_ex(context, outBuffer, outlen);
369 }
370
371 @Override
372 public int _EVP_CipherInit_ex(final PointerByReference context, final PointerByReference algo, final PointerByReference impl, final byte[] encoded,
373 final byte[] iv, final int cipherMode) {
374 return EVP_CipherInit_ex(context, algo, impl, encoded, iv, cipherMode);
375 }
376
377 @Override
378 public int _EVP_CipherUpdate(final PointerByReference context, final ByteBuffer outBuffer, final int[] outlen, final ByteBuffer inBuffer,
379 final int remaining) {
380 return EVP_CipherUpdate(context, outBuffer, outlen, inBuffer, remaining);
381 }
382
383 @Override
384 public Throwable _INIT_ERROR() {
385 return INIT_ERROR;
386 }
387
388 @Override
389 public boolean _INIT_OK() {
390 return INIT_OK;
391 }
392
393 @Override
394 public String _OpenSSL_version(final int i) {
395 return OpenSSL_version(i);
396 }
397
398 @Override
399 public int _RAND_bytes(final ByteBuffer buf, final int length) {
400 return RAND_bytes(buf, length) ;
401 }
402
403 @Override
404 public PointerByReference _RAND_get_rand_method() {
405 return RAND_get_rand_method();
406 }
407
408 @Override
409 public PointerByReference _RAND_SSLeay() {
410 return null;
411 }
412
413 }