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 OpenSsl10XNativeJna 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 public static native int ENGINE_cleanup();
68
69
70
71
72
73
74
75
76 public static native int ENGINE_finish(PointerByReference e);
77
78
79
80
81
82
83
84
85 public static native int ENGINE_free(PointerByReference e);
86
87
88
89
90
91
92
93
94
95 public static native int ENGINE_init(PointerByReference e);
96
97
98
99
100 public static native void ENGINE_load_rdrand();
101
102
103
104
105
106
107
108
109
110
111 public static native int ENGINE_set_default(PointerByReference e, int flags);
112
113
114
115
116
117
118
119
120
121
122
123
124 public static native String ERR_error_string(NativeLong err, char[] null_);
125
126
127
128
129
130 public static native void ERR_load_crypto_strings();
131
132
133
134
135 public static native NativeLong ERR_peek_error();
136
137
138
139
140 public static native PointerByReference EVP_aes_128_cbc();
141
142
143
144
145 public static native PointerByReference EVP_aes_128_ctr();
146
147
148
149
150 public static native PointerByReference EVP_aes_192_cbc();
151
152
153
154
155 public static native PointerByReference EVP_aes_192_ctr();
156
157
158
159
160 public static native PointerByReference EVP_aes_256_cbc();
161
162
163
164
165 public static native PointerByReference EVP_aes_256_ctr();
166
167
168
169
170
171
172
173
174 public static native void EVP_CIPHER_CTX_cleanup(PointerByReference c);
175
176
177
178
179
180
181
182
183 public static native void EVP_CIPHER_CTX_free(PointerByReference c);
184
185
186
187
188
189
190
191
192 public static native void EVP_CIPHER_CTX_init(PointerByReference p);
193
194
195
196
197
198
199 public static native PointerByReference EVP_CIPHER_CTX_new();
200
201
202
203
204
205
206
207
208
209
210 public static native int EVP_CIPHER_CTX_set_padding(PointerByReference c, int pad);
211
212
213
214
215
216
217
218
219
220
221
222
223 public static native int EVP_CipherFinal_ex(PointerByReference ctx, ByteBuffer bout,
224 int[] outl);
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245 public static native int EVP_CipherInit_ex(PointerByReference ctx, PointerByReference cipher,
246 PointerByReference impl, byte[] key, byte[] iv, int enc);
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263 public static native int EVP_CipherUpdate(PointerByReference ctx, ByteBuffer bout, int[] outl,
264 ByteBuffer in, int inl);
265
266
267
268
269
270
271
272
273
274
275 public static native int RAND_bytes(ByteBuffer buf, int num);
276
277
278
279
280
281
282
283 public static native PointerByReference RAND_get_rand_method();
284
285
286
287
288
289
290 public static native PointerByReference RAND_SSLeay();
291
292
293
294
295
296
297 public static native NativeLong SSLeay();
298
299
300
301
302
303
304
305
306
307
308
309
310 public static native String SSLeay_version(int type);
311
312
313
314
315 @Override
316 public PointerByReference _ENGINE_by_id(final String string) {
317 return ENGINE_by_id(string);
318 }
319
320 @Override
321 public int _ENGINE_cleanup() {
322 return ENGINE_cleanup();
323 }
324
325 @Override
326 public int _ENGINE_finish(final PointerByReference rdrandEngine) {
327 return ENGINE_finish(rdrandEngine);
328 }
329
330 @Override
331 public int _ENGINE_free(final PointerByReference rdrandEngine) {
332 return ENGINE_free(rdrandEngine);
333 }
334
335 @Override
336 public int _ENGINE_init(final PointerByReference rdrandEngine) {
337 return ENGINE_init(rdrandEngine);
338 }
339
340 @Override
341 public void _ENGINE_load_rdrand() {
342 ENGINE_load_rdrand();
343 }
344
345 @Override
346 public int _ENGINE_set_default(final PointerByReference rdrandEngine, final int flags) {
347 return ENGINE_set_default(rdrandEngine, flags);
348 }
349
350 @Override
351 public String _ERR_error_string(final NativeLong err, final char[] buff) {
352 return ERR_error_string(err, buff);
353 }
354
355 @Override
356 public NativeLong _ERR_peek_error() {
357 return ERR_peek_error();
358 }
359
360 @Override
361 public PointerByReference _EVP_aes_128_cbc() {
362 return EVP_aes_128_cbc();
363 }
364
365 @Override
366 public PointerByReference _EVP_aes_128_ctr() {
367 return EVP_aes_128_ctr();
368 }
369
370 @Override
371 public PointerByReference _EVP_aes_192_cbc() {
372 return EVP_aes_192_cbc();
373 }
374
375 @Override
376 public PointerByReference _EVP_aes_192_ctr() {
377 return EVP_aes_192_ctr();
378 }
379
380 @Override
381 public PointerByReference _EVP_aes_256_cbc() {
382 return EVP_aes_256_cbc();
383 }
384
385 @Override
386 public PointerByReference _EVP_aes_256_ctr() {
387 return EVP_aes_256_ctr();
388 }
389
390 @Override
391 public void _EVP_CIPHER_CTX_cleanup(final PointerByReference context) {
392 EVP_CIPHER_CTX_cleanup(context);
393 }
394
395 @Override
396 public void _EVP_CIPHER_CTX_free(final PointerByReference context) {
397 EVP_CIPHER_CTX_free(context);
398 }
399
400 @Override
401 public PointerByReference _EVP_CIPHER_CTX_new() {
402 return EVP_CIPHER_CTX_new();
403 }
404
405 @Override
406 public int _EVP_CIPHER_CTX_set_padding(final PointerByReference context, final int padding) {
407 return EVP_CIPHER_CTX_set_padding(context, padding);
408 }
409
410 @Override
411 public int _EVP_CipherFinal_ex(final PointerByReference context, final ByteBuffer outBuffer, final int[] outlen) {
412 return EVP_CipherFinal_ex(context, outBuffer, outlen);
413 }
414
415 @Override
416 public int _EVP_CipherInit_ex(final PointerByReference context, final PointerByReference algo, final PointerByReference impl, final byte[] encoded,
417 final byte[] iv, final int cipherMode) {
418 return EVP_CipherInit_ex(context, algo, impl, encoded, iv, cipherMode);
419 }
420
421 @Override
422 public int _EVP_CipherUpdate(final PointerByReference context, final ByteBuffer outBuffer, final int[] outlen, final ByteBuffer inBuffer,
423 final int remaining) {
424 return EVP_CipherUpdate(context, outBuffer, outlen, inBuffer, remaining);
425 }
426
427 @Override
428 public Throwable _INIT_ERROR() {
429 return INIT_ERROR;
430 }
431
432 @Override
433 public boolean _INIT_OK() {
434 return INIT_OK;
435 }
436
437 @Override
438 public String _OpenSSL_version(final int i) {
439 return SSLeay_version(i);
440 }
441
442 @Override
443 public int _RAND_bytes(final ByteBuffer buf, final int length) {
444 return RAND_bytes(buf, length) ;
445 }
446
447 @Override
448 public PointerByReference _RAND_get_rand_method() {
449 return RAND_get_rand_method();
450 }
451
452 @Override
453 public PointerByReference _RAND_SSLeay() {
454 return RAND_SSLeay();
455 }
456 }