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