New upstream version 1.3.1
Mathieu Malaterre
2 years ago
0 | Changes 1.3.1: | |
1 | * fix: fix -Wconversion warnings (by Ondrej Mosnacek) | |
2 | * fix: fix bad data types in _kcapi_common_send_meta (by Ondrej Mosnacek) | |
3 | * fix: Version symbols to maintain ABI compatibility (by Simo Sorce) | |
4 | ||
0 | 5 | Changes 1.3.0: |
1 | 6 | * fix: disable io_getevents on systems that do not support it (by Khem Raj) |
2 | 7 | * fix: remove prctl PR_SET_DUMPABLE to allow library to be debugged - as the library does not store any sensitive data in data structures it owns, such security precautions may not be necessary considering the benefit of allowing regular debugging |
10 | 10 | dnl a decimal point are pre-releases. |
11 | 11 | m4_define([__KCAPI_MAJVERSION], [1]) |
12 | 12 | m4_define([__KCAPI_MINVERSION], [3]) |
13 | m4_define([__KCAPI_PATCHLEVEL], [0]) | |
13 | m4_define([__KCAPI_PATCHLEVEL], [1]) | |
14 | 14 | m4_define([KCAPI_VERSION], [__KCAPI_MAJVERSION.__KCAPI_MINVERSION.__KCAPI_PATCHLEVEL]) |
15 | 15 | |
16 | 16 | AC_INIT([libkcapi], [KCAPI_VERSION]) |
76 | 76 | static char *srctree, *kernsrctree; |
77 | 77 | |
78 | 78 | static char **all_list = NULL; |
79 | static unsigned int all_list_len = 0; | |
79 | static size_t all_list_len = 0; | |
80 | 80 | |
81 | 81 | static void consume_symbol(const char *sym) |
82 | 82 | { |
83 | unsigned int i; | |
83 | size_t i; | |
84 | 84 | |
85 | 85 | for (i = 0; i < all_list_len; i++) { |
86 | 86 | if (!all_list[i]) |
360 | 360 | { |
361 | 361 | char *vec[4]; /* kerneldoc -list file NULL */ |
362 | 362 | pid_t pid; |
363 | ssize_t ret, i, count, start; | |
363 | ssize_t ret; | |
364 | 364 | char real_filename[PATH_MAX + 1]; |
365 | 365 | int pipefd[2]; |
366 | 366 | char *data, *str; |
367 | size_t data_len = 0; | |
367 | size_t i, count, start, data_len = 0; | |
368 | 368 | |
369 | 369 | vec[0] = KERNELDOC; |
370 | 370 | vec[1] = LIST; |
423 | 423 | |
424 | 424 | count = 0; |
425 | 425 | /* poor man's strtok, but with counting */ |
426 | for (i = 0; i < (int)data_len; i++) { | |
426 | for (i = 0; i < data_len; i++) { | |
427 | 427 | if (data[i] == '\n') { |
428 | 428 | count++; |
429 | 429 | data[i] = '\0'; |
430 | 430 | } |
431 | 431 | } |
432 | 432 | start = all_list_len; |
433 | all_list_len += (unsigned int)count; | |
433 | all_list_len += count; | |
434 | 434 | all_list = realloc(all_list, sizeof(char *) * all_list_len); |
435 | 435 | if (!all_list) { |
436 | 436 | perror("realloc"); |
437 | 437 | exit(1); |
438 | 438 | } |
439 | 439 | str = data; |
440 | for (i = 0; i < (int)data_len && start != all_list_len; i++) { | |
440 | for (i = 0; i < data_len && start != all_list_len; i++) { | |
441 | 441 | if (data[i] == '\0') { |
442 | 442 | all_list[start] = str; |
443 | 443 | str = data + i + 1; |
348 | 348 | |
349 | 349 | #if __GNUC__ >= 4 |
350 | 350 | # define DSO_PUBLIC __attribute__ ((visibility ("default"))) |
351 | ||
352 | # define IMPL_SYMVER(name, version) \ | |
353 | __asm__(".global impl_" #name ";"\ | |
354 | ".symver impl_" #name ",kcapi_" #name "@@LIBKCAPI_" version);\ | |
355 | __attribute__ ((visibility ("default"))) | |
356 | ||
357 | # define ORIG_SYMVER(name, version) \ | |
358 | __asm__(".global orig_" #name ";"\ | |
359 | ".symver orig_" #name ",kcapi_" #name "@LIBKCAPI_" version);\ | |
360 | __attribute__ ((visibility ("default"))) | |
361 | ||
351 | 362 | #else |
352 | # define DSO_PUBLIC | |
363 | # error "Compiler version too old" | |
353 | 364 | #endif |
354 | 365 | |
355 | 366 | #ifdef __cplusplus |
54 | 54 | return 0; |
55 | 55 | } |
56 | 56 | |
57 | DSO_PUBLIC | |
58 | void kcapi_aead_setassoclen(struct kcapi_handle *handle, size_t assoclen) | |
57 | IMPL_SYMVER(aead_setassoclen, "1.3.1") | |
58 | void impl_aead_setassoclen(struct kcapi_handle *handle, size_t assoclen) | |
59 | 59 | { |
60 | 60 | handle->aead.assoclen = assoclen; |
61 | 61 | } |
62 | 62 | |
63 | DSO_PUBLIC | |
64 | void kcapi_aead_getdata_input(struct kcapi_handle *handle, | |
65 | uint8_t *encdata, size_t encdatalen, int enc, | |
66 | uint8_t **aad, size_t *aadlen, | |
67 | uint8_t **data, size_t *datalen, | |
68 | uint8_t **tag, size_t *taglen) | |
63 | ORIG_SYMVER(aead_setassoclen, "0.12.0") | |
64 | void orig_aead_setassoclen(struct kcapi_handle *handle, uint32_t assoclen) | |
65 | { | |
66 | handle->aead.assoclen = assoclen; | |
67 | } | |
68 | ||
69 | IMPL_SYMVER(aead_getdata_input, "1.3.1") | |
70 | void impl_aead_getdata_input(struct kcapi_handle *handle, | |
71 | uint8_t *encdata, size_t encdatalen, int enc, | |
72 | uint8_t **aad, size_t *aadlen, | |
73 | uint8_t **data, size_t *datalen, | |
74 | uint8_t **tag, size_t *taglen) | |
69 | 75 | { |
70 | 76 | uint8_t *l_aad, *l_data, *l_tag; |
71 | 77 | size_t l_aadlen, l_datalen, l_taglen; |
115 | 121 | *taglen = l_taglen; |
116 | 122 | } |
117 | 123 | |
118 | DSO_PUBLIC | |
119 | void kcapi_aead_getdata_output(struct kcapi_handle *handle, | |
120 | uint8_t *encdata, size_t encdatalen, int enc, | |
121 | uint8_t **aad, size_t *aadlen, | |
122 | uint8_t **data, size_t *datalen, | |
123 | uint8_t **tag, size_t *taglen) | |
124 | ORIG_SYMVER(aead_getdata_input, "0.13.0") | |
125 | void orig_aead_getdata_input(struct kcapi_handle *handle, | |
126 | uint8_t *encdata, uint32_t encdatalen, int enc, | |
127 | uint8_t **aad, uint32_t *aadlen, | |
128 | uint8_t **data, uint32_t *datalen, | |
129 | uint8_t **tag, uint32_t *taglen) | |
130 | { | |
131 | size_t s_aadlen; | |
132 | size_t s_datalen; | |
133 | size_t s_taglen; | |
134 | ||
135 | impl_aead_getdata_input(handle, encdata, encdatalen, enc, | |
136 | aad, aadlen?(&s_aadlen):NULL, | |
137 | data, datalen?(&s_datalen):NULL, | |
138 | tag, taglen?(&s_taglen):NULL); | |
139 | ||
140 | if (aadlen) | |
141 | *aadlen = (uint32_t)s_aadlen; | |
142 | ||
143 | if (datalen) | |
144 | *datalen = (uint32_t)s_datalen; | |
145 | ||
146 | if (taglen) | |
147 | *taglen = (uint32_t)s_taglen; | |
148 | } | |
149 | ||
150 | IMPL_SYMVER(aead_getdata_output, "1.3.1") | |
151 | void impl_aead_getdata_output(struct kcapi_handle *handle, | |
152 | uint8_t *encdata, size_t encdatalen, int enc, | |
153 | uint8_t **aad, size_t *aadlen, | |
154 | uint8_t **data, size_t *datalen, | |
155 | uint8_t **tag, size_t *taglen) | |
124 | 156 | { |
125 | 157 | uint8_t *l_aad, *l_data, *l_tag; |
126 | 158 | size_t l_aadlen, l_datalen, l_taglen; |
181 | 213 | *taglen = l_taglen; |
182 | 214 | } |
183 | 215 | |
184 | DSO_PUBLIC | |
185 | ssize_t kcapi_aead_encrypt(struct kcapi_handle *handle, | |
186 | const uint8_t *in, size_t inlen, | |
187 | const uint8_t *iv, | |
188 | uint8_t *out, size_t outlen, int access) | |
216 | ORIG_SYMVER(aead_getdata_output, "0.13.0") | |
217 | void orig_aead_getdata_output(struct kcapi_handle *handle, | |
218 | uint8_t *encdata, uint32_t encdatalen, int enc, | |
219 | uint8_t **aad, uint32_t *aadlen, | |
220 | uint8_t **data, uint32_t *datalen, | |
221 | uint8_t **tag, uint32_t *taglen) | |
222 | { | |
223 | size_t s_aadlen; | |
224 | size_t s_datalen; | |
225 | size_t s_taglen; | |
226 | ||
227 | impl_aead_getdata_output(handle, encdata, encdatalen, enc, | |
228 | aad, aadlen?(&s_aadlen):NULL, | |
229 | data, datalen?(&s_datalen):NULL, | |
230 | tag, taglen?(&s_taglen):NULL); | |
231 | ||
232 | if (aadlen) | |
233 | *aadlen = (uint32_t)s_aadlen; | |
234 | ||
235 | if (datalen) | |
236 | *datalen = (uint32_t)s_datalen; | |
237 | ||
238 | if (taglen) | |
239 | *taglen = (uint32_t)s_taglen; | |
240 | } | |
241 | ||
242 | IMPL_SYMVER(aead_encrypt, "1.3.1") | |
243 | ssize_t impl_aead_encrypt(struct kcapi_handle *handle, | |
244 | const uint8_t *in, size_t inlen, | |
245 | const uint8_t *iv, | |
246 | uint8_t *out, size_t outlen, int access) | |
189 | 247 | { |
190 | 248 | ssize_t ret = 0; |
191 | 249 | |
200 | 258 | return ret; |
201 | 259 | } |
202 | 260 | |
261 | ORIG_SYMVER(aead_encrypt, "0.12.0") | |
262 | int32_t orig_aead_encrypt(struct kcapi_handle *handle, | |
263 | const uint8_t *in, uint32_t inlen, | |
264 | const uint8_t *iv, | |
265 | uint8_t *out, uint32_t outlen, int access) | |
266 | { | |
267 | return (int32_t)impl_aead_encrypt(handle, in, inlen, iv, out, outlen, | |
268 | access); | |
269 | } | |
270 | ||
203 | 271 | /* |
204 | 272 | * Fallback function if AIO is not present, but caller requested AIO operation. |
205 | 273 | */ |
234 | 302 | return ret; |
235 | 303 | } |
236 | 304 | |
237 | DSO_PUBLIC | |
238 | ssize_t kcapi_aead_encrypt_aio(struct kcapi_handle *handle, struct iovec *iniov, | |
239 | struct iovec *outiov, size_t iovlen, | |
240 | const uint8_t *iv, int access) | |
305 | IMPL_SYMVER(aead_encrypt_aio, "1.3.1") | |
306 | ssize_t impl_aead_encrypt_aio(struct kcapi_handle *handle, struct iovec *iniov, | |
307 | struct iovec *outiov, size_t iovlen, | |
308 | const uint8_t *iv, int access) | |
241 | 309 | { |
242 | 310 | ssize_t ret = 0; |
243 | 311 | |
252 | 320 | iv); |
253 | 321 | } |
254 | 322 | |
255 | DSO_PUBLIC | |
256 | ssize_t kcapi_aead_decrypt(struct kcapi_handle *handle, | |
257 | const uint8_t *in, size_t inlen, | |
258 | const uint8_t *iv, | |
259 | uint8_t *out, size_t outlen, int access) | |
323 | ORIG_SYMVER(aead_encrypt_aio, "0.12.0") | |
324 | int32_t orig_aead_encrypt_aio(struct kcapi_handle *handle, struct iovec *iniov, | |
325 | struct iovec *outiov, uint32_t iovlen, | |
326 | const uint8_t *iv, int access) | |
327 | { | |
328 | return (int32_t)impl_aead_encrypt_aio(handle, iniov, outiov, iovlen, | |
329 | iv, access); | |
330 | } | |
331 | ||
332 | IMPL_SYMVER(aead_decrypt, "1.3.1") | |
333 | ssize_t impl_aead_decrypt(struct kcapi_handle *handle, | |
334 | const uint8_t *in, size_t inlen, | |
335 | const uint8_t *iv, | |
336 | uint8_t *out, size_t outlen, int access) | |
260 | 337 | { |
261 | 338 | handle->cipher.iv = iv; |
262 | 339 | return _kcapi_cipher_crypt(handle, in, inlen, out, outlen, access, |
263 | 340 | ALG_OP_DECRYPT); |
341 | } | |
342 | ||
343 | ORIG_SYMVER(aead_decrypt, "0.12.0") | |
344 | int32_t orig_aead_decrypt(struct kcapi_handle *handle, | |
345 | const uint8_t *in, uint32_t inlen, | |
346 | const uint8_t *iv, | |
347 | uint8_t *out, uint32_t outlen, int access) | |
348 | { | |
349 | return (int32_t)impl_aead_decrypt(handle, in, inlen, iv, out, outlen, | |
350 | access); | |
264 | 351 | } |
265 | 352 | |
266 | 353 | /* |
297 | 384 | return ret; |
298 | 385 | } |
299 | 386 | |
300 | DSO_PUBLIC | |
301 | ssize_t kcapi_aead_decrypt_aio(struct kcapi_handle *handle, struct iovec *iniov, | |
302 | struct iovec *outiov, size_t iovlen, | |
303 | const uint8_t *iv, int access) | |
387 | IMPL_SYMVER(aead_decrypt_aio, "1.3.1") | |
388 | ssize_t impl_aead_decrypt_aio(struct kcapi_handle *handle, struct iovec *iniov, | |
389 | struct iovec *outiov, size_t iovlen, | |
390 | const uint8_t *iv, int access) | |
304 | 391 | { |
305 | 392 | ssize_t ret = 0; |
306 | 393 | |
316 | 403 | iv); |
317 | 404 | } |
318 | 405 | |
319 | DSO_PUBLIC | |
320 | ssize_t kcapi_aead_stream_init_enc(struct kcapi_handle *handle, | |
321 | const uint8_t *iv, | |
322 | struct iovec *iov, size_t iovlen) | |
406 | ORIG_SYMVER(aead_decrypt_aio, "0.12.0") | |
407 | int32_t orig_aead_decrypt_aio(struct kcapi_handle *handle, struct iovec *iniov, | |
408 | struct iovec *outiov, uint32_t iovlen, | |
409 | const uint8_t *iv, int access) | |
410 | { | |
411 | return (int32_t)impl_aead_decrypt_aio(handle, iniov, outiov, iovlen, | |
412 | iv, access); | |
413 | } | |
414 | ||
415 | IMPL_SYMVER(aead_stream_init_enc, "1.3.1") | |
416 | ssize_t impl_aead_stream_init_enc(struct kcapi_handle *handle, | |
417 | const uint8_t *iv, | |
418 | struct iovec *iov, size_t iovlen) | |
323 | 419 | { |
324 | 420 | handle->cipher.iv = iv; |
325 | 421 | return _kcapi_common_send_meta(handle, iov, iovlen, ALG_OP_ENCRYPT, |
326 | 422 | MSG_MORE); |
327 | 423 | } |
328 | 424 | |
329 | DSO_PUBLIC | |
330 | ssize_t kcapi_aead_stream_init_dec(struct kcapi_handle *handle, | |
331 | const uint8_t *iv, | |
332 | struct iovec *iov, size_t iovlen) | |
425 | ORIG_SYMVER(aead_stream_init_enc, "0.12.0") | |
426 | int32_t orig_aead_stream_init_enc(struct kcapi_handle *handle, | |
427 | const uint8_t *iv, | |
428 | struct iovec *iov, uint32_t iovlen) | |
429 | { | |
430 | return (int32_t)impl_aead_stream_init_enc(handle, iv, iov, iovlen); | |
431 | } | |
432 | ||
433 | IMPL_SYMVER(aead_stream_init_dec, "1.3.1") | |
434 | ssize_t impl_aead_stream_init_dec(struct kcapi_handle *handle, | |
435 | const uint8_t *iv, | |
436 | struct iovec *iov, size_t iovlen) | |
333 | 437 | { |
334 | 438 | handle->cipher.iv = iv; |
335 | 439 | return _kcapi_common_send_meta(handle, iov, iovlen, ALG_OP_DECRYPT, |
336 | 440 | MSG_MORE); |
337 | 441 | } |
338 | 442 | |
339 | DSO_PUBLIC | |
340 | ssize_t kcapi_aead_stream_update(struct kcapi_handle *handle, | |
341 | struct iovec *iov, size_t iovlen) | |
443 | ORIG_SYMVER(aead_stream_init_dec, "0.12.0") | |
444 | int32_t orig_aead_stream_init_dec(struct kcapi_handle *handle, | |
445 | const uint8_t *iv, | |
446 | struct iovec *iov, uint32_t iovlen) | |
447 | { | |
448 | return (int32_t)impl_aead_stream_init_dec(handle, iv, iov, iovlen); | |
449 | } | |
450 | ||
451 | IMPL_SYMVER(aead_stream_update, "1.3.1") | |
452 | ssize_t impl_aead_stream_update(struct kcapi_handle *handle, | |
453 | struct iovec *iov, size_t iovlen) | |
342 | 454 | { |
343 | 455 | if (handle->processed_sg <= handle->flags.alg_max_pages) |
344 | 456 | return _kcapi_common_vmsplice_iov(handle, iov, iovlen, |
347 | 459 | return _kcapi_common_send_data(handle, iov, iovlen, MSG_MORE); |
348 | 460 | } |
349 | 461 | |
350 | DSO_PUBLIC | |
351 | ssize_t kcapi_aead_stream_update_last(struct kcapi_handle *handle, | |
352 | struct iovec *iov, size_t iovlen) | |
462 | ORIG_SYMVER(aead_stream_update, "0.12.0") | |
463 | int32_t orig_aead_stream_update(struct kcapi_handle *handle, | |
464 | struct iovec *iov, uint32_t iovlen) | |
465 | { | |
466 | return (int32_t)impl_aead_stream_update(handle, iov, iovlen); | |
467 | } | |
468 | ||
469 | IMPL_SYMVER(aead_stream_update_last, "1.3.1") | |
470 | ssize_t impl_aead_stream_update_last(struct kcapi_handle *handle, | |
471 | struct iovec *iov, size_t iovlen) | |
353 | 472 | { |
354 | 473 | if (handle->processed_sg <= handle->flags.alg_max_pages) |
355 | 474 | return _kcapi_common_vmsplice_iov(handle, iov, iovlen, 0); |
357 | 476 | return _kcapi_common_send_data(handle, iov, iovlen, 0); |
358 | 477 | } |
359 | 478 | |
360 | DSO_PUBLIC | |
361 | ssize_t kcapi_aead_stream_op(struct kcapi_handle *handle, | |
362 | struct iovec *iov, size_t iovlen) | |
479 | ORIG_SYMVER(aead_stream_update_last, "0.12.0") | |
480 | int32_t orig_aead_stream_update_last(struct kcapi_handle *handle, | |
481 | struct iovec *iov, uint32_t iovlen) | |
482 | { | |
483 | return (int32_t)impl_aead_stream_update_last(handle, iov, iovlen); | |
484 | } | |
485 | ||
486 | IMPL_SYMVER(aead_stream_op, "1.3.1") | |
487 | ssize_t impl_aead_stream_op(struct kcapi_handle *handle, | |
488 | struct iovec *iov, size_t iovlen) | |
363 | 489 | { |
364 | 490 | if (!iov) { |
365 | 491 | kcapi_dolog(KCAPI_LOG_ERR, |
370 | 496 | return _kcapi_common_recv_data(handle, iov, iovlen); |
371 | 497 | } |
372 | 498 | |
499 | ORIG_SYMVER(aead_stream_op, "0.12.0") | |
500 | int32_t orig_aead_stream_op(struct kcapi_handle *handle, | |
501 | struct iovec *iov, uint32_t iovlen) | |
502 | { | |
503 | return (int32_t)impl_aead_stream_op(handle, iov, iovlen); | |
504 | } | |
505 | ||
373 | 506 | DSO_PUBLIC |
374 | 507 | uint32_t kcapi_aead_ivsize(struct kcapi_handle *handle) |
375 | 508 | { |
394 | 527 | return tfm->info.aead_maxauthsize; |
395 | 528 | } |
396 | 529 | |
397 | DSO_PUBLIC | |
398 | size_t kcapi_aead_inbuflen_enc(struct kcapi_handle *handle, | |
399 | size_t inlen, size_t assoclen, size_t taglen) | |
530 | IMPL_SYMVER(aead_inbuflen_enc, "1.3.1") | |
531 | size_t impl_aead_inbuflen_enc(struct kcapi_handle *handle, | |
532 | size_t inlen, size_t assoclen, size_t taglen) | |
400 | 533 | { |
401 | 534 | size_t len = inlen + assoclen; |
402 | 535 | |
406 | 539 | return len; |
407 | 540 | } |
408 | 541 | |
409 | DSO_PUBLIC | |
410 | size_t kcapi_aead_inbuflen_dec(struct kcapi_handle *handle, | |
411 | size_t inlen, size_t assoclen, size_t taglen) | |
542 | ORIG_SYMVER(aead_inbuflen_enc, "0.13.0") | |
543 | uint32_t orig_aead_inbuflen_enc(struct kcapi_handle *handle, | |
544 | uint32_t inlen, uint32_t assoclen, | |
545 | uint32_t taglen) | |
546 | { | |
547 | return (uint32_t)impl_aead_inbuflen_enc(handle, inlen, assoclen, | |
548 | taglen); | |
549 | } | |
550 | ||
551 | IMPL_SYMVER(aead_inbuflen_dec, "1.3.1") | |
552 | size_t impl_aead_inbuflen_dec(struct kcapi_handle *handle, | |
553 | size_t inlen, size_t assoclen, size_t taglen) | |
412 | 554 | { |
413 | 555 | (void)handle; |
414 | 556 | return (inlen + assoclen + taglen); |
415 | 557 | } |
416 | 558 | |
417 | DSO_PUBLIC | |
418 | size_t kcapi_aead_outbuflen_enc(struct kcapi_handle *handle, | |
419 | size_t inlen, size_t assoclen, | |
420 | size_t taglen) | |
559 | ORIG_SYMVER(aead_inbuflen_dec, "0.13.0") | |
560 | uint32_t orig_aead_inbuflen_dec(struct kcapi_handle *handle, | |
561 | uint32_t inlen, uint32_t assoclen, | |
562 | uint32_t taglen) | |
563 | { | |
564 | return (uint32_t)impl_aead_inbuflen_dec(handle, inlen, assoclen, | |
565 | taglen); | |
566 | } | |
567 | ||
568 | IMPL_SYMVER(aead_outbuflen_enc, "1.3.1") | |
569 | size_t impl_aead_outbuflen_enc(struct kcapi_handle *handle, | |
570 | size_t inlen, size_t assoclen, | |
571 | size_t taglen) | |
421 | 572 | { |
422 | 573 | struct kcapi_handle_tfm *tfm = handle->tfm; |
423 | 574 | uint32_t bs = tfm->info.blocksize; |
430 | 581 | return outlen; |
431 | 582 | } |
432 | 583 | |
433 | DSO_PUBLIC | |
434 | size_t kcapi_aead_outbuflen_dec(struct kcapi_handle *handle, | |
435 | size_t inlen, size_t assoclen, | |
436 | size_t taglen) | |
584 | ORIG_SYMVER(aead_outbuflen_enc, "0.13.0") | |
585 | uint32_t orig_aead_outbuflen_enc(struct kcapi_handle *handle, | |
586 | uint32_t inlen, uint32_t assoclen, | |
587 | uint32_t taglen) | |
588 | { | |
589 | return (uint32_t)impl_aead_outbuflen_enc(handle, inlen, assoclen, | |
590 | taglen); | |
591 | } | |
592 | ||
593 | IMPL_SYMVER(aead_outbuflen_dec, "1.3.1") | |
594 | size_t impl_aead_outbuflen_dec(struct kcapi_handle *handle, | |
595 | size_t inlen, size_t assoclen, | |
596 | size_t taglen) | |
437 | 597 | { |
438 | 598 | struct kcapi_handle_tfm *tfm = handle->tfm; |
439 | 599 | uint32_t bs = tfm->info.blocksize; |
447 | 607 | outlen = 1; |
448 | 608 | |
449 | 609 | return outlen; |
610 | } | |
611 | ||
612 | ORIG_SYMVER(aead_outbuflen_dec, "0.13.0") | |
613 | uint32_t orig_aead_outbuflen_dec(struct kcapi_handle *handle, | |
614 | uint32_t inlen, uint32_t assoclen, | |
615 | uint32_t taglen) | |
616 | { | |
617 | return (uint32_t)impl_aead_outbuflen_dec(handle, inlen, assoclen, | |
618 | taglen); | |
450 | 619 | } |
451 | 620 | |
452 | 621 | DSO_PUBLIC |
51 | 51 | return (ret >= 0) ? ret : -errno; |
52 | 52 | } |
53 | 53 | |
54 | DSO_PUBLIC | |
55 | ssize_t kcapi_akcipher_encrypt(struct kcapi_handle *handle, | |
56 | const uint8_t *in, size_t inlen, | |
57 | uint8_t *out, size_t outlen, int access) | |
54 | IMPL_SYMVER(akcipher_encrypt, "1.3.1") | |
55 | ssize_t impl_akcipher_encrypt(struct kcapi_handle *handle, | |
56 | const uint8_t *in, size_t inlen, | |
57 | uint8_t *out, size_t outlen, int access) | |
58 | 58 | { |
59 | 59 | return _kcapi_cipher_crypt(handle, in, inlen, out, outlen, access, |
60 | 60 | ALG_OP_ENCRYPT); |
61 | 61 | } |
62 | 62 | |
63 | DSO_PUBLIC | |
64 | ssize_t kcapi_akcipher_decrypt(struct kcapi_handle *handle, | |
65 | const uint8_t *in, size_t inlen, | |
66 | uint8_t *out, size_t outlen, int access) | |
63 | ORIG_SYMVER(akcipher_encrypt, "0.12.0") | |
64 | int32_t orig_akcipher_encrypt(struct kcapi_handle *handle, | |
65 | const uint8_t *in, uint32_t inlen, | |
66 | uint8_t *out, uint32_t outlen, int access) | |
67 | { | |
68 | return (int32_t)_kcapi_cipher_crypt(handle, in, inlen, out, outlen, | |
69 | access, ALG_OP_ENCRYPT); | |
70 | } | |
71 | ||
72 | IMPL_SYMVER(akcipher_decrypt, "1.3.1") | |
73 | ssize_t impl_akcipher_decrypt(struct kcapi_handle *handle, | |
74 | const uint8_t *in, size_t inlen, | |
75 | uint8_t *out, size_t outlen, int access) | |
67 | 76 | { |
68 | 77 | return _kcapi_cipher_crypt(handle, in, inlen, out, outlen, access, |
69 | 78 | ALG_OP_DECRYPT); |
70 | 79 | } |
71 | 80 | |
72 | DSO_PUBLIC | |
73 | ssize_t kcapi_akcipher_sign(struct kcapi_handle *handle, | |
74 | const uint8_t *in, size_t inlen, | |
75 | uint8_t *out, size_t outlen, int access) | |
81 | ORIG_SYMVER(akcipher_decrypt, "0.12.0") | |
82 | int32_t orig_akcipher_decrypt(struct kcapi_handle *handle, | |
83 | const uint8_t *in, uint32_t inlen, | |
84 | uint8_t *out, uint32_t outlen, int access) | |
85 | { | |
86 | return (int32_t)_kcapi_cipher_crypt(handle, in, inlen, out, outlen, | |
87 | access, ALG_OP_DECRYPT); | |
88 | } | |
89 | ||
90 | IMPL_SYMVER(akcipher_sign, "1.3.1") | |
91 | ssize_t impl_akcipher_sign(struct kcapi_handle *handle, | |
92 | const uint8_t *in, size_t inlen, | |
93 | uint8_t *out, size_t outlen, int access) | |
76 | 94 | { |
77 | 95 | return _kcapi_cipher_crypt(handle, in, inlen, out, outlen, access, |
78 | 96 | ALG_OP_SIGN); |
79 | 97 | } |
80 | 98 | |
81 | DSO_PUBLIC | |
82 | ssize_t kcapi_akcipher_verify(struct kcapi_handle *handle, | |
83 | const uint8_t *in, size_t inlen, | |
84 | uint8_t *out, size_t outlen, int access) | |
99 | ORIG_SYMVER(akcipher_sign, "0.12.0") | |
100 | int32_t orig_akcipher_sign(struct kcapi_handle *handle, | |
101 | const uint8_t *in, uint32_t inlen, | |
102 | uint8_t *out, uint32_t outlen, int access) | |
103 | { | |
104 | return (int32_t)_kcapi_cipher_crypt(handle, in, inlen, out, outlen, | |
105 | access, ALG_OP_SIGN); | |
106 | } | |
107 | ||
108 | IMPL_SYMVER(akcipher_verify, "1.3.1") | |
109 | ssize_t impl_akcipher_verify(struct kcapi_handle *handle, | |
110 | const uint8_t *in, size_t inlen, | |
111 | uint8_t *out, size_t outlen, int access) | |
85 | 112 | { |
86 | 113 | return _kcapi_cipher_crypt(handle, in, inlen, out, outlen, access, |
87 | 114 | ALG_OP_VERIFY); |
88 | 115 | } |
89 | 116 | |
90 | DSO_PUBLIC | |
91 | ssize_t kcapi_akcipher_stream_init_enc(struct kcapi_handle *handle, | |
92 | struct iovec *iov, size_t iovlen) | |
117 | ORIG_SYMVER(akcipher_verify, "0.12.0") | |
118 | int32_t orig_akcipher_verify(struct kcapi_handle *handle, | |
119 | const uint8_t *in, uint32_t inlen, | |
120 | uint8_t *out, uint32_t outlen, int access) | |
121 | { | |
122 | return (int32_t)_kcapi_cipher_crypt(handle, in, inlen, out, outlen, | |
123 | access, ALG_OP_VERIFY); | |
124 | } | |
125 | ||
126 | IMPL_SYMVER(akcipher_stream_init_enc, "1.3.1") | |
127 | ssize_t impl_akcipher_stream_init_enc(struct kcapi_handle *handle, | |
128 | struct iovec *iov, size_t iovlen) | |
93 | 129 | { |
94 | 130 | return _kcapi_common_send_meta(handle, iov, iovlen, ALG_OP_ENCRYPT, |
95 | 131 | MSG_MORE); |
96 | 132 | } |
97 | 133 | |
98 | DSO_PUBLIC | |
99 | ssize_t kcapi_akcipher_stream_init_dec(struct kcapi_handle *handle, | |
100 | struct iovec *iov, size_t iovlen) | |
134 | ORIG_SYMVER(akcipher_stream_init_enc, "0.12.0") | |
135 | int32_t orig_akcipher_stream_init_enc(struct kcapi_handle *handle, | |
136 | struct iovec *iov, uint32_t iovlen) | |
137 | { | |
138 | return (int32_t)_kcapi_common_send_meta(handle, iov, iovlen, | |
139 | ALG_OP_ENCRYPT, MSG_MORE); | |
140 | } | |
141 | ||
142 | IMPL_SYMVER(akcipher_stream_init_dec, "1.3.1") | |
143 | ssize_t impl_akcipher_stream_init_dec(struct kcapi_handle *handle, | |
144 | struct iovec *iov, size_t iovlen) | |
101 | 145 | { |
102 | 146 | return _kcapi_common_send_meta(handle, iov, iovlen, ALG_OP_DECRYPT, |
103 | 147 | MSG_MORE); |
104 | 148 | } |
105 | 149 | |
106 | DSO_PUBLIC | |
107 | ssize_t kcapi_akcipher_stream_init_sgn(struct kcapi_handle *handle, | |
108 | struct iovec *iov, size_t iovlen) | |
150 | ORIG_SYMVER(akcipher_stream_init_dec, "0.12.0") | |
151 | int32_t orig_akcipher_stream_init_dec(struct kcapi_handle *handle, | |
152 | struct iovec *iov, uint32_t iovlen) | |
153 | { | |
154 | return (int32_t)_kcapi_common_send_meta(handle, iov, iovlen, | |
155 | ALG_OP_DECRYPT, MSG_MORE); | |
156 | } | |
157 | ||
158 | IMPL_SYMVER(akcipher_stream_init_sgn, "1.3.1") | |
159 | ssize_t impl_akcipher_stream_init_sgn(struct kcapi_handle *handle, | |
160 | struct iovec *iov, size_t iovlen) | |
109 | 161 | { |
110 | 162 | return _kcapi_common_send_meta(handle, iov, iovlen, ALG_OP_SIGN, |
111 | 163 | MSG_MORE); |
112 | 164 | } |
113 | 165 | |
114 | DSO_PUBLIC | |
115 | ssize_t kcapi_akcipher_stream_init_vfy(struct kcapi_handle *handle, | |
116 | struct iovec *iov, size_t iovlen) | |
166 | ORIG_SYMVER(akcipher_stream_init_sgn, "0.12.0") | |
167 | int32_t orig_akcipher_stream_init_sgn(struct kcapi_handle *handle, | |
168 | struct iovec *iov, uint32_t iovlen) | |
169 | { | |
170 | return (int32_t)_kcapi_common_send_meta(handle, iov, iovlen, | |
171 | ALG_OP_SIGN, MSG_MORE); | |
172 | } | |
173 | ||
174 | IMPL_SYMVER(akcipher_stream_init_vfy, "1.3.1") | |
175 | ssize_t impl_akcipher_stream_init_vfy(struct kcapi_handle *handle, | |
176 | struct iovec *iov, size_t iovlen) | |
117 | 177 | { |
118 | 178 | return _kcapi_common_send_meta(handle, iov, iovlen, ALG_OP_VERIFY, |
119 | 179 | MSG_MORE); |
120 | 180 | } |
121 | 181 | |
122 | DSO_PUBLIC | |
123 | ssize_t kcapi_akcipher_stream_update(struct kcapi_handle *handle, | |
124 | struct iovec *iov, size_t iovlen) | |
182 | ORIG_SYMVER(akcipher_stream_init_vfy, "0.12.0") | |
183 | int32_t orig_akcipher_stream_init_vfy(struct kcapi_handle *handle, | |
184 | struct iovec *iov, uint32_t iovlen) | |
185 | { | |
186 | return (int32_t)_kcapi_common_send_meta(handle, iov, iovlen, | |
187 | ALG_OP_VERIFY, MSG_MORE); | |
188 | } | |
189 | ||
190 | IMPL_SYMVER(akcipher_stream_update, "1.3.1") | |
191 | ssize_t impl_akcipher_stream_update(struct kcapi_handle *handle, | |
192 | struct iovec *iov, size_t iovlen) | |
125 | 193 | { |
126 | 194 | if (handle->processed_sg < handle->flags.alg_max_pages) |
127 | 195 | return _kcapi_common_vmsplice_iov(handle, iov, iovlen, |
130 | 198 | return _kcapi_common_send_data(handle, iov, iovlen, MSG_MORE); |
131 | 199 | } |
132 | 200 | |
133 | DSO_PUBLIC | |
134 | ssize_t kcapi_akcipher_stream_update_last(struct kcapi_handle *handle, | |
135 | struct iovec *iov, size_t iovlen) | |
201 | ORIG_SYMVER(akcipher_stream_update, "0.12.0") | |
202 | int32_t orig_akcipher_stream_update(struct kcapi_handle *handle, | |
203 | struct iovec *iov, uint32_t iovlen) | |
204 | { | |
205 | return (int32_t)impl_akcipher_stream_update(handle, iov, iovlen); | |
206 | } | |
207 | ||
208 | IMPL_SYMVER(akcipher_stream_update_last, "1.3.1") | |
209 | ssize_t impl_akcipher_stream_update_last(struct kcapi_handle *handle, | |
210 | struct iovec *iov, size_t iovlen) | |
136 | 211 | { |
137 | 212 | if (handle->processed_sg < handle->flags.alg_max_pages) |
138 | 213 | return _kcapi_common_vmsplice_iov(handle, iov, iovlen, 0); |
140 | 215 | return _kcapi_common_send_data(handle, iov, iovlen, 0); |
141 | 216 | } |
142 | 217 | |
143 | DSO_PUBLIC | |
144 | ssize_t kcapi_akcipher_stream_op(struct kcapi_handle *handle, | |
145 | struct iovec *iov, size_t iovlen) | |
218 | ORIG_SYMVER(akcipher_stream_update_last, "0.12.0") | |
219 | int32_t orig_akcipher_stream_update_last(struct kcapi_handle *handle, | |
220 | struct iovec *iov, uint32_t iovlen) | |
221 | { | |
222 | return (int32_t)impl_akcipher_stream_update_last(handle, iov, iovlen); | |
223 | } | |
224 | ||
225 | IMPL_SYMVER(akcipher_stream_op, "1.3.1") | |
226 | ssize_t impl_akcipher_stream_op(struct kcapi_handle *handle, | |
227 | struct iovec *iov, size_t iovlen) | |
146 | 228 | { |
147 | 229 | if (!iov || !iovlen) { |
148 | 230 | kcapi_dolog(KCAPI_LOG_ERR, |
150 | 232 | return -EINVAL; |
151 | 233 | } |
152 | 234 | return _kcapi_common_recv_data(handle, iov, iovlen); |
235 | } | |
236 | ||
237 | ORIG_SYMVER(akcipher_stream_op, "0.12.0") | |
238 | int32_t orig_akcipher_stream_op(struct kcapi_handle *handle, | |
239 | struct iovec *iov, uint32_t iovlen) | |
240 | { | |
241 | return (int32_t)impl_akcipher_stream_op(handle, iov, iovlen); | |
153 | 242 | } |
154 | 243 | |
155 | 244 | static ssize_t |
209 | 298 | return ret; |
210 | 299 | } |
211 | 300 | |
212 | DSO_PUBLIC | |
213 | ssize_t kcapi_akcipher_encrypt_aio(struct kcapi_handle *handle, | |
214 | struct iovec *iniov, struct iovec *outiov, | |
215 | size_t iovlen, int access) | |
301 | IMPL_SYMVER(akcipher_encrypt_aio, "1.3.1") | |
302 | ssize_t impl_akcipher_encrypt_aio(struct kcapi_handle *handle, | |
303 | struct iovec *iniov, struct iovec *outiov, | |
304 | size_t iovlen, int access) | |
216 | 305 | { |
217 | 306 | ssize_t ret; |
218 | 307 | |
223 | 312 | |
224 | 313 | return _kcapi_akcipher_encrypt_aio_fallback(handle, iniov, outiov, |
225 | 314 | iovlen); |
315 | } | |
316 | ||
317 | ORIG_SYMVER(akcipher_encrypt_aio, "0.14.0") | |
318 | int32_t orig_akcipher_encrypt_aio(struct kcapi_handle *handle, | |
319 | struct iovec *iniov, struct iovec *outiov, | |
320 | uint32_t iovlen, int access) | |
321 | { | |
322 | return (int32_t)impl_akcipher_encrypt_aio(handle, iniov, outiov, | |
323 | iovlen, access); | |
226 | 324 | } |
227 | 325 | |
228 | 326 | /* |
258 | 356 | return ret; |
259 | 357 | } |
260 | 358 | |
261 | DSO_PUBLIC | |
262 | ssize_t kcapi_akcipher_decrypt_aio(struct kcapi_handle *handle, | |
263 | struct iovec *iniov, struct iovec *outiov, | |
264 | size_t iovlen, int access) | |
359 | IMPL_SYMVER(akcipher_decrypt_aio, "1.3.1") | |
360 | ssize_t impl_akcipher_decrypt_aio(struct kcapi_handle *handle, | |
361 | struct iovec *iniov, struct iovec *outiov, | |
362 | size_t iovlen, int access) | |
265 | 363 | { |
266 | 364 | ssize_t ret; |
267 | 365 | |
272 | 370 | |
273 | 371 | return _kcapi_akcipher_decrypt_aio_fallback(handle, iniov, outiov, |
274 | 372 | iovlen); |
373 | } | |
374 | ||
375 | ORIG_SYMVER(akcipher_decrypt_aio, "0.14.0") | |
376 | int32_t orig_akcipher_decrypt_aio(struct kcapi_handle *handle, | |
377 | struct iovec *iniov, struct iovec *outiov, | |
378 | uint32_t iovlen, int access) | |
379 | { | |
380 | return (int32_t)impl_akcipher_decrypt_aio(handle, iniov, outiov, | |
381 | iovlen, access); | |
275 | 382 | } |
276 | 383 | |
277 | 384 | /* |
307 | 414 | return ret; |
308 | 415 | } |
309 | 416 | |
310 | DSO_PUBLIC | |
311 | ssize_t kcapi_akcipher_sign_aio(struct kcapi_handle *handle, | |
312 | struct iovec *iniov, struct iovec *outiov, | |
313 | size_t iovlen, int access) | |
417 | IMPL_SYMVER(akcipher_sign_aio, "1.3.1") | |
418 | ssize_t impl_akcipher_sign_aio(struct kcapi_handle *handle, | |
419 | struct iovec *iniov, struct iovec *outiov, | |
420 | size_t iovlen, int access) | |
314 | 421 | { |
315 | 422 | ssize_t ret; |
316 | 423 | |
320 | 427 | return ret; |
321 | 428 | |
322 | 429 | return _kcapi_akcipher_sign_aio_fallback(handle, iniov, outiov, iovlen); |
430 | } | |
431 | ||
432 | ORIG_SYMVER(akcipher_sign_aio, "0.14.0") | |
433 | int32_t orig_akcipher_sign_aio(struct kcapi_handle *handle, | |
434 | struct iovec *iniov, struct iovec *outiov, | |
435 | uint32_t iovlen, int access) | |
436 | { | |
437 | return (int32_t)impl_akcipher_sign_aio(handle, iniov, outiov, iovlen, | |
438 | access); | |
323 | 439 | } |
324 | 440 | |
325 | 441 | /* |
355 | 471 | return ret; |
356 | 472 | } |
357 | 473 | |
358 | DSO_PUBLIC | |
359 | ssize_t kcapi_akcipher_verify_aio(struct kcapi_handle *handle, | |
360 | struct iovec *iniov, struct iovec *outiov, | |
361 | size_t iovlen, int access) | |
474 | IMPL_SYMVER(akcipher_verify_aio, "1.3.1") | |
475 | ssize_t impl_akcipher_verify_aio(struct kcapi_handle *handle, | |
476 | struct iovec *iniov, struct iovec *outiov, | |
477 | size_t iovlen, int access) | |
362 | 478 | { |
363 | 479 | ssize_t ret; |
364 | 480 | |
370 | 486 | return _kcapi_akcipher_verify_aio_fallback(handle, iniov, outiov, |
371 | 487 | iovlen); |
372 | 488 | } |
489 | ||
490 | ORIG_SYMVER(akcipher_verify_aio, "0.14.0") | |
491 | int32_t orig_akcipher_verify_aio(struct kcapi_handle *handle, | |
492 | struct iovec *iniov, struct iovec *outiov, | |
493 | uint32_t iovlen, int access) | |
494 | { | |
495 | return (int32_t)impl_akcipher_verify_aio(handle, iniov, outiov, | |
496 | iovlen, access); | |
497 | } |
91 | 91 | # error "Endianess not defined" |
92 | 92 | #endif |
93 | 93 | |
94 | DSO_PUBLIC | |
95 | ssize_t kcapi_kdf_dpi(struct kcapi_handle *handle, | |
96 | const uint8_t *src, size_t slen, | |
97 | uint8_t *dst, size_t dlen) | |
94 | IMPL_SYMVER(kdf_dpi, "1.3.1") | |
95 | ssize_t impl_kdf_dpi(struct kcapi_handle *handle, | |
96 | const uint8_t *src, size_t slen, | |
97 | uint8_t *dst, size_t dlen) | |
98 | 98 | { |
99 | 99 | uint32_t h = kcapi_md_digestsize(handle); |
100 | 100 | ssize_t err = 0; |
163 | 163 | return err; |
164 | 164 | } |
165 | 165 | |
166 | DSO_PUBLIC | |
167 | ssize_t kcapi_kdf_fb(struct kcapi_handle *handle, | |
168 | const uint8_t *src, size_t slen, | |
169 | uint8_t *dst, size_t dlen) | |
166 | ORIG_SYMVER(kdf_dpi, "0.12.0") | |
167 | int32_t orig_kdf_dpi(struct kcapi_handle *handle, | |
168 | const uint8_t *src, uint32_t slen, | |
169 | uint8_t *dst, uint32_t dlen) | |
170 | { | |
171 | return (int32_t)impl_kdf_dpi(handle, src, slen, dst, dlen); | |
172 | } | |
173 | ||
174 | IMPL_SYMVER(kdf_fb, "1.3.1") | |
175 | ssize_t impl_kdf_fb(struct kcapi_handle *handle, | |
176 | const uint8_t *src, size_t slen, | |
177 | uint8_t *dst, size_t dlen) | |
170 | 178 | { |
171 | 179 | uint32_t h = kcapi_md_digestsize(handle); |
172 | 180 | ssize_t err = 0; |
236 | 244 | return err; |
237 | 245 | } |
238 | 246 | |
239 | DSO_PUBLIC | |
240 | ssize_t kcapi_kdf_ctr(struct kcapi_handle *handle, | |
241 | const uint8_t *src, size_t slen, | |
242 | uint8_t *dst, size_t dlen) | |
247 | ORIG_SYMVER(kdf_fb, "0.12.0") | |
248 | int32_t orig_kdf_fb(struct kcapi_handle *handle, | |
249 | const uint8_t *src, uint32_t slen, | |
250 | uint8_t *dst, uint32_t dlen) | |
251 | { | |
252 | return (int32_t)impl_kdf_fb(handle, src, slen, dst, dlen); | |
253 | } | |
254 | ||
255 | IMPL_SYMVER(kdf_ctr, "1.3.1") | |
256 | ssize_t impl_kdf_ctr(struct kcapi_handle *handle, | |
257 | const uint8_t *src, size_t slen, | |
258 | uint8_t *dst, size_t dlen) | |
243 | 259 | { |
244 | 260 | uint32_t h = kcapi_md_digestsize(handle); |
245 | 261 | ssize_t err = 0; |
290 | 306 | return err; |
291 | 307 | } |
292 | 308 | |
309 | ORIG_SYMVER(kdf_ctr, "0.12.0") | |
310 | int32_t orig_kdf_ctr(struct kcapi_handle *handle, | |
311 | const uint8_t *src, uint32_t slen, | |
312 | uint8_t *dst, uint32_t dlen) | |
313 | { | |
314 | return (int32_t)impl_kdf_ctr(handle, src, slen, dst, dlen); | |
315 | } | |
316 | ||
293 | 317 | /* |
294 | 318 | * RFC 5869 KDF |
295 | 319 | */ |
296 | DSO_PUBLIC | |
297 | ssize_t kcapi_hkdf(const char *hashname, | |
298 | const uint8_t *ikm, size_t ikmlen, | |
299 | const uint8_t *salt, uint32_t saltlen, | |
300 | const uint8_t *info, size_t infolen, | |
301 | uint8_t *dst, size_t dlen) | |
320 | IMPL_SYMVER(hkdf, "1.3.1") | |
321 | ssize_t impl_hkdf(const char *hashname, | |
322 | const uint8_t *ikm, size_t ikmlen, | |
323 | const uint8_t *salt, uint32_t saltlen, | |
324 | const uint8_t *info, size_t infolen, | |
325 | uint8_t *dst, size_t dlen) | |
302 | 326 | { |
303 | 327 | #define HKDF_MAXHASH 64 |
304 | 328 | uint32_t h; |
408 | 432 | return err; |
409 | 433 | } |
410 | 434 | |
435 | ORIG_SYMVER(hkdf, "0.14.0") | |
436 | int32_t orig_hkdf(const char *hashname, | |
437 | const uint8_t *ikm, uint32_t ikmlen, | |
438 | const uint8_t *salt, uint32_t saltlen, | |
439 | const uint8_t *info, uint32_t infolen, | |
440 | uint8_t *dst, uint32_t dlen) | |
441 | { | |
442 | return (int32_t)impl_hkdf(hashname, ikm, ikmlen, salt, saltlen, | |
443 | info, infolen, dst, dlen); | |
444 | } | |
445 | ||
411 | 446 | static inline uint64_t kcapi_get_time(void) |
412 | 447 | { |
413 | 448 | struct timespec time; |
528 | 563 | kcapi_xor_32(dst, src, size); |
529 | 564 | } |
530 | 565 | |
531 | DSO_PUBLIC | |
532 | ssize_t kcapi_pbkdf(const char *hashname, | |
533 | const uint8_t *pw, uint32_t pwlen, | |
534 | const uint8_t *salt, size_t saltlen, | |
535 | uint32_t count, | |
536 | uint8_t *key, size_t keylen) | |
566 | IMPL_SYMVER(pbkdf, "1.3.1") | |
567 | ssize_t impl_pbkdf(const char *hashname, | |
568 | const uint8_t *pw, uint32_t pwlen, | |
569 | const uint8_t *salt, size_t saltlen, | |
570 | uint32_t count, | |
571 | uint8_t *key, size_t keylen) | |
537 | 572 | { |
538 | 573 | struct kcapi_handle *handle; |
539 | 574 | uint8_t *key_orig = key; |
621 | 656 | return err; |
622 | 657 | } |
623 | 658 | |
659 | ORIG_SYMVER(pbkdf, "0.12.0") | |
660 | int32_t orig_pbkdf(const char *hashname, | |
661 | const uint8_t *pw, uint32_t pwlen, | |
662 | const uint8_t *salt, uint32_t saltlen, | |
663 | uint32_t count, | |
664 | uint8_t *key, uint32_t keylen) | |
665 | { | |
666 | return (int32_t)impl_pbkdf(hashname, pw, pwlen, salt, saltlen, count, | |
667 | key, keylen); | |
668 | } |
38 | 38 | /************************************************************ |
39 | 39 | * Common helper used within the lib and as an API |
40 | 40 | ************************************************************/ |
41 | DSO_PUBLIC | |
42 | void kcapi_memset_secure(void *s, int c, size_t n) | |
41 | IMPL_SYMVER(memset_secure, "1.3.1") | |
42 | void impl_memset_secure(void *s, int c, size_t n) | |
43 | 43 | { |
44 | 44 | memset(s, c, n); |
45 | 45 | __asm__ __volatile__("" : : "r" (s) : "memory"); |
46 | } | |
47 | ||
48 | ORIG_SYMVER(memset_secure, "0.12.0") | |
49 | void orig_memset_secure(void *s, int c, uint32_t n) | |
50 | { | |
51 | impl_memset_secure(s, c, n); | |
46 | 52 | } |
47 | 53 | |
48 | 54 | /************************************************************ |
124 | 130 | |
125 | 131 | /* plaintext / ciphertext data */ |
126 | 132 | struct cmsghdr *header = NULL; |
127 | size_t *type = NULL; | |
133 | uint32_t *type = NULL; | |
128 | 134 | struct msghdr msg; |
129 | 135 | |
130 | 136 | /* IV data */ |
134 | 140 | 0; |
135 | 141 | |
136 | 142 | /* AEAD data */ |
137 | size_t *assoclen = NULL; | |
143 | uint32_t *assoclen = NULL; | |
138 | 144 | size_t assoc_msg_size = handle->aead.assoclen ? |
139 | 145 | CMSG_SPACE(sizeof(*assoclen)) : 0; |
140 | 146 | |
204 | 210 | header->cmsg_type = ALG_SET_AEAD_ASSOCLEN; |
205 | 211 | header->cmsg_len = CMSG_LEN(sizeof(*assoclen)); |
206 | 212 | assoclen = (void*)CMSG_DATA(header); |
207 | *assoclen = handle->aead.assoclen; | |
213 | *assoclen = (uint32_t)handle->aead.assoclen; | |
208 | 214 | } |
209 | 215 | |
210 | 216 | ret = sendmsg(*_kcapi_get_opfd(handle), &msg, (int)flags); |
71 | 71 | return _kcapi_common_setkey(handle, key, keylen); |
72 | 72 | } |
73 | 73 | |
74 | DSO_PUBLIC | |
75 | ssize_t kcapi_kpp_keygen(struct kcapi_handle *handle, | |
76 | uint8_t *pubkey, size_t pubkeylen, int access) | |
74 | IMPL_SYMVER(kpp_keygen, "1.3.1") | |
75 | ssize_t impl_kpp_keygen(struct kcapi_handle *handle, | |
76 | uint8_t *pubkey, size_t pubkeylen, int access) | |
77 | 77 | { |
78 | 78 | return _kcapi_cipher_crypt(handle, NULL, 0, pubkey, pubkeylen, access, |
79 | 79 | ALG_OP_KEYGEN); |
80 | 80 | } |
81 | 81 | |
82 | DSO_PUBLIC | |
83 | ssize_t kcapi_kpp_ssgen(struct kcapi_handle *handle, | |
84 | const uint8_t *pubkey, size_t pubkeylen, | |
85 | uint8_t *ss, size_t sslen, int access) | |
82 | ORIG_SYMVER(kpp_keygen, "1.0.0") | |
83 | int32_t orig_kpp_keygen(struct kcapi_handle *handle, | |
84 | uint8_t *pubkey, uint32_t pubkeylen, int access) | |
85 | { | |
86 | return (int32_t)_kcapi_cipher_crypt(handle, NULL, 0, pubkey, pubkeylen, | |
87 | access, ALG_OP_KEYGEN); | |
88 | } | |
89 | ||
90 | IMPL_SYMVER(kpp_ssgen, "1.3.1") | |
91 | ssize_t impl_kpp_ssgen(struct kcapi_handle *handle, | |
92 | const uint8_t *pubkey, size_t pubkeylen, | |
93 | uint8_t *ss, size_t sslen, int access) | |
86 | 94 | { |
87 | 95 | return _kcapi_cipher_crypt(handle, pubkey, pubkeylen, ss, sslen, access, |
88 | 96 | ALG_OP_SSGEN); |
97 | } | |
98 | ||
99 | ORIG_SYMVER(kpp_ssgen, "1.0.0") | |
100 | int32_t orig_kpp_ssgen(struct kcapi_handle *handle, | |
101 | const uint8_t *pubkey, uint32_t pubkeylen, | |
102 | uint8_t *ss, uint32_t sslen, int access) | |
103 | { | |
104 | return (int32_t)_kcapi_cipher_crypt(handle, pubkey, pubkeylen, ss, | |
105 | sslen, access, ALG_OP_SSGEN); | |
89 | 106 | } |
90 | 107 | |
91 | 108 | static ssize_t |
113 | 130 | return processed; |
114 | 131 | } |
115 | 132 | |
116 | DSO_PUBLIC | |
117 | ssize_t kcapi_kpp_keygen_aio(struct kcapi_handle *handle, struct iovec *outiov, | |
118 | size_t iovlen, int access) | |
133 | IMPL_SYMVER(kpp_keygen_aio, "1.3.1") | |
134 | ssize_t impl_kpp_keygen_aio(struct kcapi_handle *handle, struct iovec *outiov, | |
135 | size_t iovlen, int access) | |
119 | 136 | { |
120 | 137 | return _kcapi_kpp_crypt_aio(handle, NULL, outiov, iovlen, access, |
121 | 138 | ALG_OP_KEYGEN); |
122 | 139 | } |
123 | 140 | |
124 | DSO_PUBLIC | |
125 | ssize_t kcapi_kpp_ssgen_aio(struct kcapi_handle *handle, | |
126 | struct iovec *iniov, struct iovec *outiov, | |
127 | size_t iovlen, int access) | |
141 | ORIG_SYMVER(kpp_keygen_aio, "1.0.0") | |
142 | int32_t orig_kpp_keygen_aio(struct kcapi_handle *handle, struct iovec *outiov, | |
143 | uint32_t iovlen, int access) | |
144 | { | |
145 | return (int32_t)_kcapi_kpp_crypt_aio(handle, NULL, outiov, iovlen, | |
146 | access, ALG_OP_KEYGEN); | |
147 | } | |
148 | ||
149 | IMPL_SYMVER(kpp_ssgen_aio, "1.3.1") | |
150 | ssize_t impl_kpp_ssgen_aio(struct kcapi_handle *handle, | |
151 | struct iovec *iniov, struct iovec *outiov, | |
152 | size_t iovlen, int access) | |
128 | 153 | { |
129 | 154 | return _kcapi_kpp_crypt_aio(handle, iniov, outiov, iovlen, access, |
130 | 155 | ALG_OP_SSGEN); |
131 | 156 | } |
157 | ||
158 | ORIG_SYMVER(kpp_ssgen_aio, "1.0.0") | |
159 | int32_t orig_kpp_ssgen_aio(struct kcapi_handle *handle, | |
160 | struct iovec *iniov, struct iovec *outiov, | |
161 | uint32_t iovlen, int access) | |
162 | { | |
163 | return (int32_t)_kcapi_kpp_crypt_aio(handle, iniov, outiov, iovlen, | |
164 | access, ALG_OP_SSGEN); | |
165 | } |
97 | 97 | return _kcapi_common_recv_data(handle, &iov, 1); |
98 | 98 | } |
99 | 99 | |
100 | DSO_PUBLIC | |
101 | ssize_t kcapi_md_final(struct kcapi_handle *handle, | |
102 | uint8_t *buffer, size_t len) | |
100 | IMPL_SYMVER(md_final, "1.3.1") | |
101 | ssize_t impl_md_final(struct kcapi_handle *handle, | |
102 | uint8_t *buffer, size_t len) | |
103 | 103 | { |
104 | 104 | return _kcapi_md_final(handle, buffer, len); |
105 | 105 | } |
106 | 106 | |
107 | DSO_PUBLIC | |
108 | ssize_t kcapi_md_digest(struct kcapi_handle *handle, | |
107 | ORIG_SYMVER(md_final, "0.12.0") | |
108 | int32_t orig_md_final(struct kcapi_handle *handle, | |
109 | uint8_t *buffer, uint32_t len) | |
110 | { | |
111 | return (int32_t)_kcapi_md_final(handle, buffer, len); | |
112 | } | |
113 | ||
114 | IMPL_SYMVER(md_digest, "1.3.1") | |
115 | ssize_t impl_md_digest(struct kcapi_handle *handle, | |
109 | 116 | const uint8_t *in, size_t inlen, |
110 | 117 | uint8_t *out, size_t outlen) |
111 | 118 | { |
117 | 124 | return _kcapi_md_final(handle, out, outlen); |
118 | 125 | } |
119 | 126 | |
127 | ORIG_SYMVER(md_digest, "0.12.0") | |
128 | int32_t orig_md_digest(struct kcapi_handle *handle, | |
129 | const uint8_t *in, uint32_t inlen, | |
130 | uint8_t *out, uint32_t outlen) | |
131 | { | |
132 | return (int32_t)impl_md_digest(handle, in, inlen, out, outlen); | |
133 | } | |
134 | ||
120 | 135 | DSO_PUBLIC |
121 | 136 | uint32_t kcapi_md_digestsize(struct kcapi_handle *handle) |
122 | 137 | { |
150 | 165 | return ret; |
151 | 166 | } |
152 | 167 | |
153 | DSO_PUBLIC | |
154 | ssize_t kcapi_md_sha1(const uint8_t *in, size_t inlen, | |
155 | uint8_t *out, size_t outlen) | |
168 | IMPL_SYMVER(md_sha1, "1.3.1") | |
169 | ssize_t impl_md_sha1(const uint8_t *in, size_t inlen, | |
170 | uint8_t *out, size_t outlen) | |
156 | 171 | { |
157 | 172 | return kcapi_md_conv_common("sha1", in, inlen, out, outlen); |
158 | 173 | } |
159 | 174 | |
160 | DSO_PUBLIC | |
161 | ssize_t kcapi_md_sha224(const uint8_t *in, size_t inlen, | |
162 | uint8_t *out, size_t outlen) | |
175 | ORIG_SYMVER(md_sha1, "1.0.0") | |
176 | int32_t orig_md_sha1(const uint8_t *in, uint32_t inlen, | |
177 | uint8_t *out, uint32_t outlen) | |
178 | { | |
179 | return (int32_t)kcapi_md_conv_common("sha1", in, inlen, out, outlen); | |
180 | } | |
181 | ||
182 | IMPL_SYMVER(md_sha224, "1.3.1") | |
183 | ssize_t impl_md_sha224(const uint8_t *in, size_t inlen, | |
184 | uint8_t *out, size_t outlen) | |
163 | 185 | { |
164 | 186 | return kcapi_md_conv_common("sha224", in, inlen, out, outlen); |
165 | 187 | } |
166 | 188 | |
167 | DSO_PUBLIC | |
168 | ssize_t kcapi_md_sha256(const uint8_t *in, size_t inlen, | |
169 | uint8_t *out, size_t outlen) | |
189 | ORIG_SYMVER(md_sha224, "1.0.0") | |
190 | int32_t orig_md_sha224(const uint8_t *in, uint32_t inlen, | |
191 | uint8_t *out, uint32_t outlen) | |
192 | { | |
193 | return (int32_t)kcapi_md_conv_common("sha224", in, inlen, out, outlen); | |
194 | } | |
195 | ||
196 | IMPL_SYMVER(md_sha256, "1.3.1") | |
197 | ssize_t impl_md_sha256(const uint8_t *in, size_t inlen, | |
198 | uint8_t *out, size_t outlen) | |
170 | 199 | { |
171 | 200 | return kcapi_md_conv_common("sha256", in, inlen, out, outlen); |
172 | 201 | } |
173 | 202 | |
174 | DSO_PUBLIC | |
175 | ssize_t kcapi_md_sha384(const uint8_t *in, size_t inlen, | |
176 | uint8_t *out, size_t outlen) | |
203 | ORIG_SYMVER(md_sha256, "1.0.0") | |
204 | ssize_t orig_md_sha256(const uint8_t *in, uint32_t inlen, | |
205 | uint8_t *out, uint32_t outlen) | |
206 | { | |
207 | return (int32_t)kcapi_md_conv_common("sha256", in, inlen, out, outlen); | |
208 | } | |
209 | ||
210 | IMPL_SYMVER(md_sha384, "1.3.1") | |
211 | ssize_t impl_md_sha384(const uint8_t *in, size_t inlen, | |
212 | uint8_t *out, size_t outlen) | |
177 | 213 | { |
178 | 214 | return kcapi_md_conv_common("sha384", in, inlen, out, outlen); |
179 | 215 | } |
180 | 216 | |
181 | DSO_PUBLIC | |
182 | ssize_t kcapi_md_sha512(const uint8_t *in, size_t inlen, | |
183 | uint8_t *out, size_t outlen) | |
217 | ORIG_SYMVER(md_sha384, "1.0.0") | |
218 | int32_t orig_md_sha384(const uint8_t *in, uint32_t inlen, | |
219 | uint8_t *out, uint32_t outlen) | |
220 | { | |
221 | return (int32_t)kcapi_md_conv_common("sha384", in, inlen, out, outlen); | |
222 | } | |
223 | ||
224 | IMPL_SYMVER(md_sha512, "1.3.1") | |
225 | ssize_t impl_md_sha512(const uint8_t *in, size_t inlen, | |
226 | uint8_t *out, size_t outlen) | |
184 | 227 | { |
185 | 228 | return kcapi_md_conv_common("sha512", in, inlen, out, outlen); |
229 | } | |
230 | ||
231 | ORIG_SYMVER(md_sha512, "1.0.0") | |
232 | int32_t orig_md_sha512(const uint8_t *in, uint32_t inlen, | |
233 | uint8_t *out, uint32_t outlen) | |
234 | { | |
235 | return (int32_t)kcapi_md_conv_common("sha512", in, inlen, out, outlen); | |
186 | 236 | } |
187 | 237 | |
188 | 238 | static inline ssize_t kcapi_md_mac_conv_common(const char *name, |
206 | 256 | return ret; |
207 | 257 | } |
208 | 258 | |
209 | DSO_PUBLIC | |
210 | ssize_t kcapi_md_hmac_sha1(const uint8_t *key, uint32_t keylen, | |
211 | const uint8_t *in, size_t inlen, | |
212 | uint8_t *out, size_t outlen) | |
259 | IMPL_SYMVER(md_hmac_sha1, "1.3.1") | |
260 | ssize_t impl_md_hmac_sha1(const uint8_t *key, uint32_t keylen, | |
261 | const uint8_t *in, size_t inlen, | |
262 | uint8_t *out, size_t outlen) | |
213 | 263 | { |
214 | 264 | return kcapi_md_mac_conv_common("hmac(sha1)", key, keylen, in, inlen, |
215 | 265 | out, outlen); |
216 | 266 | } |
217 | 267 | |
218 | DSO_PUBLIC | |
219 | ssize_t kcapi_md_hmac_sha224(const uint8_t *key, uint32_t keylen, | |
220 | const uint8_t *in, size_t inlen, | |
221 | uint8_t *out, size_t outlen) | |
268 | ORIG_SYMVER(md_hmac_sha1, "1.0.0") | |
269 | int32_t orig_md_hmac_sha1(const uint8_t *key, uint32_t keylen, | |
270 | const uint8_t *in, uint32_t inlen, | |
271 | uint8_t *out, uint32_t outlen) | |
272 | { | |
273 | return (int32_t)kcapi_md_mac_conv_common("hmac(sha1)", key, keylen, | |
274 | in, inlen, out, outlen); | |
275 | } | |
276 | ||
277 | IMPL_SYMVER(md_hmac_sha224, "1.3.1") | |
278 | ssize_t impl_md_hmac_sha224(const uint8_t *key, uint32_t keylen, | |
279 | const uint8_t *in, size_t inlen, | |
280 | uint8_t *out, size_t outlen) | |
222 | 281 | { |
223 | 282 | return kcapi_md_mac_conv_common("hmac(sha224)", key, keylen, in, inlen, |
224 | 283 | out, outlen); |
225 | 284 | } |
226 | 285 | |
227 | DSO_PUBLIC | |
228 | ssize_t kcapi_md_hmac_sha256(const uint8_t *key, uint32_t keylen, | |
229 | const uint8_t *in, size_t inlen, | |
230 | uint8_t *out, size_t outlen) | |
286 | ORIG_SYMVER(md_hmac_sha224, "1.0.0") | |
287 | int32_t orig_md_hmac_sha224(const uint8_t *key, uint32_t keylen, | |
288 | const uint8_t *in, uint32_t inlen, | |
289 | uint8_t *out, uint32_t outlen) | |
290 | { | |
291 | return (int32_t)kcapi_md_mac_conv_common("hmac(sha224)", key, keylen, | |
292 | in, inlen, out, outlen); | |
293 | } | |
294 | ||
295 | IMPL_SYMVER(md_hmac_sha256, "1.3.1") | |
296 | ssize_t impl_md_hmac_sha256(const uint8_t *key, uint32_t keylen, | |
297 | const uint8_t *in, size_t inlen, | |
298 | uint8_t *out, size_t outlen) | |
231 | 299 | { |
232 | 300 | return kcapi_md_mac_conv_common("hmac(sha256)", key, keylen, in, inlen, |
233 | 301 | out, outlen); |
234 | 302 | } |
235 | 303 | |
236 | DSO_PUBLIC | |
237 | ssize_t kcapi_md_hmac_sha384(const uint8_t *key, uint32_t keylen, | |
238 | const uint8_t *in, size_t inlen, | |
239 | uint8_t *out, size_t outlen) | |
304 | ORIG_SYMVER(md_hmac_sha256, "1.0.0") | |
305 | int32_t orig_md_hmac_sha256(const uint8_t *key, uint32_t keylen, | |
306 | const uint8_t *in, uint32_t inlen, | |
307 | uint8_t *out, uint32_t outlen) | |
308 | { | |
309 | return (int32_t)kcapi_md_mac_conv_common("hmac(sha256)", key, keylen, | |
310 | in, inlen, out, outlen); | |
311 | } | |
312 | ||
313 | IMPL_SYMVER(md_hmac_sha384, "1.3.1") | |
314 | ssize_t impl_md_hmac_sha384(const uint8_t *key, uint32_t keylen, | |
315 | const uint8_t *in, size_t inlen, | |
316 | uint8_t *out, size_t outlen) | |
240 | 317 | { |
241 | 318 | return kcapi_md_mac_conv_common("hmac(sha384)", key, keylen, in, inlen, |
242 | 319 | out, outlen); |
243 | 320 | } |
244 | 321 | |
245 | DSO_PUBLIC | |
246 | ssize_t kcapi_md_hmac_sha512(const uint8_t *key, uint32_t keylen, | |
247 | const uint8_t *in, size_t inlen, | |
248 | uint8_t *out, size_t outlen) | |
322 | ORIG_SYMVER(md_hmac_sha384, "1.0.0") | |
323 | int32_t orig_md_hmac_sha384(const uint8_t *key, uint32_t keylen, | |
324 | const uint8_t *in, uint32_t inlen, | |
325 | uint8_t *out, uint32_t outlen) | |
326 | { | |
327 | return (int32_t)kcapi_md_mac_conv_common("hmac(sha384)", key, keylen, | |
328 | in, inlen, out, outlen); | |
329 | } | |
330 | ||
331 | IMPL_SYMVER(md_hmac_sha512, "1.3.1") | |
332 | ssize_t impl_md_hmac_sha512(const uint8_t *key, uint32_t keylen, | |
333 | const uint8_t *in, size_t inlen, | |
334 | uint8_t *out, size_t outlen) | |
249 | 335 | { |
250 | 336 | return kcapi_md_mac_conv_common("hmac(sha512)", key, keylen, in, inlen, |
251 | 337 | out, outlen); |
252 | 338 | } |
339 | ||
340 | ORIG_SYMVER(md_hmac_sha512, "1.0.0") | |
341 | int32_t orig_md_hmac_sha512(const uint8_t *key, uint32_t keylen, | |
342 | const uint8_t *in, uint32_t inlen, | |
343 | uint8_t *out, uint32_t outlen) | |
344 | { | |
345 | return (int32_t)kcapi_md_mac_conv_common("hmac(sha512)", key, keylen, | |
346 | in, inlen, out, outlen); | |
347 | } |
49 | 49 | return _kcapi_common_setkey(handle, seed, seedlen); |
50 | 50 | } |
51 | 51 | |
52 | DSO_PUBLIC | |
53 | ssize_t kcapi_rng_generate(struct kcapi_handle *handle, | |
54 | uint8_t *buffer, size_t len) | |
52 | IMPL_SYMVER(rng_generate, "1.3.1") | |
53 | ssize_t impl_rng_generate(struct kcapi_handle *handle, | |
54 | uint8_t *buffer, size_t len) | |
55 | 55 | { |
56 | 56 | ssize_t out = 0; |
57 | 57 | struct iovec iov; |
71 | 71 | } |
72 | 72 | |
73 | 73 | return out; |
74 | } | |
75 | ||
76 | ORIG_SYMVER(rng_generate, "0.12.0") | |
77 | int32_t orig_rng_generate(struct kcapi_handle *handle, | |
78 | uint8_t *buffer, uint32_t len) | |
79 | { | |
80 | return (int32_t)impl_rng_generate(handle, buffer, len); | |
74 | 81 | } |
75 | 82 | |
76 | 83 | DSO_PUBLIC |
150 | 157 | #define KCAPI_APP_ALIGN 8 |
151 | 158 | #define __aligned(x) __attribute__((aligned(x))) |
152 | 159 | |
153 | DSO_PUBLIC | |
154 | ssize_t kcapi_rng_get_bytes(uint8_t *buffer, size_t outlen) | |
160 | IMPL_SYMVER(rng_get_bytes, "1.3.1") | |
161 | ssize_t impl_rng_get_bytes(uint8_t *buffer, size_t outlen) | |
155 | 162 | { |
156 | 163 | struct kcapi_handle *handle; |
157 | 164 | uint8_t buf[KCAPI_RNG_BUFSIZE] __aligned(KCAPI_APP_ALIGN); |
225 | 232 | _kcapi_handle_destroy(handle); |
226 | 233 | return ret; |
227 | 234 | } |
235 | ||
236 | ORIG_SYMVER(rng_get_bytes, "1.0.0") | |
237 | int32_t orig_rng_get_bytes(uint8_t *buffer, uint32_t outlen) | |
238 | { | |
239 | return (int32_t)impl_rng_get_bytes(buffer, outlen); | |
240 | } |
40 | 40 | return _kcapi_common_setkey(handle, key, keylen); |
41 | 41 | } |
42 | 42 | |
43 | DSO_PUBLIC | |
44 | ssize_t kcapi_cipher_encrypt(struct kcapi_handle *handle, | |
45 | const uint8_t *in, size_t inlen, | |
46 | const uint8_t *iv, | |
47 | uint8_t *out, size_t outlen, int access) | |
43 | IMPL_SYMVER(cipher_encrypt, "1.3.1") | |
44 | ssize_t impl_cipher_encrypt(struct kcapi_handle *handle, | |
45 | const uint8_t *in, size_t inlen, | |
46 | const uint8_t *iv, | |
47 | uint8_t *out, size_t outlen, int access) | |
48 | 48 | { |
49 | 49 | struct kcapi_handle_tfm *tfm = handle->tfm; |
50 | 50 | uint32_t bs = tfm->info.blocksize; |
58 | 58 | handle->cipher.iv = iv; |
59 | 59 | return _kcapi_cipher_crypt_chunk(handle, in, inlen, out, outlen, access, |
60 | 60 | ALG_OP_ENCRYPT); |
61 | } | |
62 | ||
63 | ORIG_SYMVER(cipher_encrypt, "0.12.0") | |
64 | int32_t orig_cipher_encrypt(struct kcapi_handle *handle, | |
65 | const uint8_t *in, uint32_t inlen, | |
66 | const uint8_t *iv, | |
67 | uint8_t *out, uint32_t outlen, int access) | |
68 | { | |
69 | return (int32_t)impl_cipher_encrypt(handle, in, inlen, iv, out, outlen, | |
70 | access); | |
61 | 71 | } |
62 | 72 | |
63 | 73 | /* |
76 | 86 | return kcapi_cipher_stream_op(handle, outiov, iovlen); |
77 | 87 | } |
78 | 88 | |
79 | DSO_PUBLIC | |
80 | ssize_t kcapi_cipher_encrypt_aio(struct kcapi_handle *handle, | |
81 | struct iovec *iniov, struct iovec *outiov, | |
82 | size_t iovlen, const uint8_t *iv, int access) | |
89 | IMPL_SYMVER(cipher_encrypt_aio, "1.3.1") | |
90 | ssize_t impl_cipher_encrypt_aio(struct kcapi_handle *handle, | |
91 | struct iovec *iniov, struct iovec *outiov, | |
92 | size_t iovlen, const uint8_t *iv, int access) | |
83 | 93 | { |
84 | 94 | ssize_t ret; |
85 | 95 | |
94 | 104 | iovlen, iv); |
95 | 105 | } |
96 | 106 | |
97 | DSO_PUBLIC | |
98 | ssize_t kcapi_cipher_decrypt(struct kcapi_handle *handle, | |
99 | const uint8_t *in, size_t inlen, | |
100 | const uint8_t *iv, | |
101 | uint8_t *out, size_t outlen, int access) | |
107 | ORIG_SYMVER(cipher_encrypt_aio, "0.12.0") | |
108 | int32_t orig_cipher_encrypt_aio(struct kcapi_handle *handle, | |
109 | struct iovec *iniov, struct iovec *outiov, | |
110 | uint32_t iovlen, const uint8_t *iv, | |
111 | int access) | |
112 | { | |
113 | return (int32_t)impl_cipher_encrypt_aio(handle, iniov, outiov, iovlen, | |
114 | iv, access); | |
115 | } | |
116 | ||
117 | IMPL_SYMVER(cipher_decrypt, "1.3.1") | |
118 | ssize_t impl_cipher_decrypt(struct kcapi_handle *handle, | |
119 | const uint8_t *in, size_t inlen, | |
120 | const uint8_t *iv, | |
121 | uint8_t *out, size_t outlen, int access) | |
102 | 122 | { |
103 | 123 | struct kcapi_handle_tfm *tfm = handle->tfm; |
104 | 124 | |
116 | 136 | handle->cipher.iv = iv; |
117 | 137 | return _kcapi_cipher_crypt_chunk(handle, in, inlen, out, outlen, access, |
118 | 138 | ALG_OP_DECRYPT); |
139 | } | |
140 | ||
141 | ORIG_SYMVER(cipher_decrypt, "0.12.0") | |
142 | int32_t orig_cipher_decrypt(struct kcapi_handle *handle, | |
143 | const uint8_t *in, uint32_t inlen, | |
144 | const uint8_t *iv, | |
145 | uint8_t *out, uint32_t outlen, int access) | |
146 | { | |
147 | return (int32_t)impl_cipher_decrypt(handle, in, inlen, iv, out, outlen, | |
148 | access); | |
119 | 149 | } |
120 | 150 | |
121 | 151 | /* |
134 | 164 | return kcapi_cipher_stream_op(handle, outiov, iovlen); |
135 | 165 | } |
136 | 166 | |
137 | DSO_PUBLIC | |
138 | ssize_t kcapi_cipher_decrypt_aio(struct kcapi_handle *handle, | |
139 | struct iovec *iniov, struct iovec *outiov, | |
140 | size_t iovlen, const uint8_t *iv, int access) | |
167 | IMPL_SYMVER(cipher_decrypt_aio, "1.3.1") | |
168 | ssize_t impl_cipher_decrypt_aio(struct kcapi_handle *handle, | |
169 | struct iovec *iniov, struct iovec *outiov, | |
170 | size_t iovlen, const uint8_t *iv, int access) | |
141 | 171 | { |
142 | 172 | ssize_t ret; |
143 | 173 | |
152 | 182 | iovlen, iv); |
153 | 183 | } |
154 | 184 | |
155 | DSO_PUBLIC | |
156 | ssize_t kcapi_cipher_stream_init_enc(struct kcapi_handle *handle, | |
157 | const uint8_t *iv, | |
158 | struct iovec *iov, size_t iovlen) | |
185 | ORIG_SYMVER(cipher_decrypt_aio, "0.12.0") | |
186 | int32_t orig_cipher_decrypt_aio(struct kcapi_handle *handle, | |
187 | struct iovec *iniov, struct iovec *outiov, | |
188 | uint32_t iovlen, const uint8_t *iv, int access) | |
189 | { | |
190 | return (int32_t)impl_cipher_decrypt_aio(handle, iniov, outiov, iovlen, | |
191 | iv, access); | |
192 | } | |
193 | ||
194 | IMPL_SYMVER(cipher_stream_init_enc, "1.3.1") | |
195 | ssize_t impl_cipher_stream_init_enc(struct kcapi_handle *handle, | |
196 | const uint8_t *iv, | |
197 | struct iovec *iov, size_t iovlen) | |
159 | 198 | { |
160 | 199 | handle->cipher.iv = iv; |
161 | 200 | return _kcapi_common_send_meta(handle, iov, iovlen, ALG_OP_ENCRYPT, |
162 | 201 | MSG_MORE); |
163 | 202 | } |
164 | 203 | |
165 | DSO_PUBLIC | |
166 | ssize_t kcapi_cipher_stream_init_dec(struct kcapi_handle *handle, | |
167 | const uint8_t *iv, | |
168 | struct iovec *iov, size_t iovlen) | |
204 | ORIG_SYMVER(cipher_stream_init_enc, "0.12.0") | |
205 | int32_t orig_cipher_stream_init_enc(struct kcapi_handle *handle, | |
206 | const uint8_t *iv, | |
207 | struct iovec *iov, uint32_t iovlen) | |
208 | { | |
209 | return (int32_t)impl_cipher_stream_init_enc(handle, iv, iov, iovlen); | |
210 | } | |
211 | ||
212 | IMPL_SYMVER(cipher_stream_init_dec, "1.3.1") | |
213 | ssize_t impl_cipher_stream_init_dec(struct kcapi_handle *handle, | |
214 | const uint8_t *iv, | |
215 | struct iovec *iov, size_t iovlen) | |
169 | 216 | { |
170 | 217 | handle->cipher.iv = iv; |
171 | 218 | return _kcapi_common_send_meta(handle, iov, iovlen, ALG_OP_DECRYPT, |
172 | 219 | MSG_MORE); |
173 | 220 | } |
174 | 221 | |
175 | DSO_PUBLIC | |
176 | ssize_t kcapi_cipher_stream_update(struct kcapi_handle *handle, | |
177 | struct iovec *iov, size_t iovlen) | |
222 | ORIG_SYMVER(cipher_stream_init_dec, "0.12.0") | |
223 | int32_t orig_cipher_stream_init_dec(struct kcapi_handle *handle, | |
224 | const uint8_t *iv, | |
225 | struct iovec *iov, uint32_t iovlen) | |
226 | { | |
227 | return (int32_t)impl_cipher_stream_init_dec(handle, iv, iov, iovlen); | |
228 | } | |
229 | ||
230 | IMPL_SYMVER(cipher_stream_update, "1.3.1") | |
231 | ssize_t impl_cipher_stream_update(struct kcapi_handle *handle, | |
232 | struct iovec *iov, size_t iovlen) | |
178 | 233 | { |
179 | 234 | if (handle->processed_sg <= handle->flags.alg_max_pages) |
180 | 235 | return _kcapi_common_vmsplice_iov(handle, iov, iovlen, |
183 | 238 | return _kcapi_common_send_data(handle, iov, iovlen, MSG_MORE); |
184 | 239 | } |
185 | 240 | |
186 | DSO_PUBLIC | |
187 | ssize_t kcapi_cipher_stream_update_last(struct kcapi_handle *handle, | |
188 | struct iovec *iov, size_t iovlen) | |
241 | ORIG_SYMVER(cipher_stream_update, "0.12.0") | |
242 | int32_t orig_cipher_stream_update(struct kcapi_handle *handle, | |
243 | struct iovec *iov, uint32_t iovlen) | |
244 | { | |
245 | return (int32_t)impl_cipher_stream_update(handle, iov, iovlen); | |
246 | } | |
247 | ||
248 | IMPL_SYMVER(cipher_stream_update_last, "1.3.1") | |
249 | ssize_t impl_cipher_stream_update_last(struct kcapi_handle *handle, | |
250 | struct iovec *iov, size_t iovlen) | |
189 | 251 | { |
190 | 252 | if (handle->processed_sg <= handle->flags.alg_max_pages) |
191 | 253 | return _kcapi_common_vmsplice_iov(handle, iov, iovlen, 0); |
193 | 255 | return _kcapi_common_send_data(handle, iov, iovlen, 0); |
194 | 256 | } |
195 | 257 | |
196 | DSO_PUBLIC | |
197 | ssize_t kcapi_cipher_stream_op(struct kcapi_handle *handle, | |
198 | struct iovec *iov, size_t iovlen) | |
258 | ORIG_SYMVER(cipher_stream_update_last, "1.2.0") | |
259 | int32_t orig_cipher_stream_update_last(struct kcapi_handle *handle, | |
260 | struct iovec *iov, uint32_t iovlen) | |
261 | { | |
262 | return (int32_t)impl_cipher_stream_update_last(handle, iov, iovlen); | |
263 | } | |
264 | ||
265 | IMPL_SYMVER(cipher_stream_op, "1.3.1") | |
266 | ssize_t impl_cipher_stream_op(struct kcapi_handle *handle, | |
267 | struct iovec *iov, size_t iovlen) | |
199 | 268 | { |
200 | 269 | if (!iov || !iovlen) { |
201 | 270 | kcapi_dolog(KCAPI_LOG_ERR, |
205 | 274 | return _kcapi_common_recv_data(handle, iov, iovlen); |
206 | 275 | } |
207 | 276 | |
277 | ORIG_SYMVER(cipher_stream_op, "0.12.0") | |
278 | int32_t orig_cipher_stream_op(struct kcapi_handle *handle, | |
279 | struct iovec *iov, uint32_t iovlen) | |
280 | { | |
281 | return (int32_t)impl_cipher_stream_op(handle, iov, iovlen); | |
282 | } | |
283 | ||
208 | 284 | DSO_PUBLIC |
209 | 285 | uint32_t kcapi_cipher_ivsize(struct kcapi_handle *handle) |
210 | 286 | { |
266 | 342 | return ret; |
267 | 343 | } |
268 | 344 | |
269 | DSO_PUBLIC | |
270 | ssize_t kcapi_cipher_enc_aes_cbc(const uint8_t *key, uint32_t keylen, | |
271 | const uint8_t *in, size_t inlen, | |
272 | const uint8_t *iv, | |
273 | uint8_t *out, size_t outlen) | |
345 | IMPL_SYMVER(cipher_enc_aes_cbc, "1.3.1") | |
346 | ssize_t impl_cipher_enc_aes_cbc(const uint8_t *key, uint32_t keylen, | |
347 | const uint8_t *in, size_t inlen, | |
348 | const uint8_t *iv, | |
349 | uint8_t *out, size_t outlen) | |
274 | 350 | { |
275 | 351 | return kcapi_cipher_conv_enc_common("cbc(aes)", key, keylen, in, inlen, |
276 | 352 | iv, out, outlen); |
277 | 353 | } |
278 | 354 | |
279 | DSO_PUBLIC | |
280 | ssize_t kcapi_cipher_enc_aes_ctr(const uint8_t *key, uint32_t keylen, | |
281 | const uint8_t *in, size_t inlen, | |
282 | const uint8_t *ctr, | |
283 | uint8_t *out, size_t outlen) | |
355 | ORIG_SYMVER(cipher_enc_aes_cbc, "1.0.0") | |
356 | int32_t orig_cipher_enc_aes_cbc(const uint8_t *key, uint32_t keylen, | |
357 | const uint8_t *in, uint32_t inlen, | |
358 | const uint8_t *iv, | |
359 | uint8_t *out, uint32_t outlen) | |
360 | { | |
361 | return (int32_t)kcapi_cipher_conv_enc_common("cbc(aes)", key, keylen, | |
362 | in, inlen, iv, | |
363 | out, outlen); | |
364 | } | |
365 | ||
366 | IMPL_SYMVER(cipher_enc_aes_ctr, "1.3.1") | |
367 | ssize_t impl_cipher_enc_aes_ctr(const uint8_t *key, uint32_t keylen, | |
368 | const uint8_t *in, size_t inlen, | |
369 | const uint8_t *ctr, | |
370 | uint8_t *out, size_t outlen) | |
284 | 371 | { |
285 | 372 | return kcapi_cipher_conv_enc_common("ctr(aes)", key, keylen, in, inlen, |
286 | 373 | ctr, out, outlen); |
287 | 374 | } |
288 | 375 | |
289 | DSO_PUBLIC | |
290 | ssize_t kcapi_cipher_dec_aes_cbc(const uint8_t *key, uint32_t keylen, | |
291 | const uint8_t *in, size_t inlen, | |
292 | const uint8_t *iv, | |
293 | uint8_t *out, size_t outlen) | |
376 | ORIG_SYMVER(cipher_enc_aes_ctr, "1.0.0") | |
377 | int32_t orig_cipher_enc_aes_ctr(const uint8_t *key, uint32_t keylen, | |
378 | const uint8_t *in, uint32_t inlen, | |
379 | const uint8_t *ctr, | |
380 | uint8_t *out, uint32_t outlen) | |
381 | { | |
382 | return (int32_t)kcapi_cipher_conv_enc_common("ctr(aes)", key, keylen, | |
383 | in, inlen, ctr, | |
384 | out, outlen); | |
385 | } | |
386 | ||
387 | IMPL_SYMVER(cipher_dec_aes_cbc, "1.3.1") | |
388 | ssize_t impl_cipher_dec_aes_cbc(const uint8_t *key, uint32_t keylen, | |
389 | const uint8_t *in, size_t inlen, | |
390 | const uint8_t *iv, | |
391 | uint8_t *out, size_t outlen) | |
294 | 392 | { |
295 | 393 | return kcapi_cipher_conv_dec_common("cbc(aes)", key, keylen, in, inlen, |
296 | 394 | iv, out, outlen); |
297 | 395 | } |
298 | 396 | |
299 | DSO_PUBLIC | |
300 | ssize_t kcapi_cipher_dec_aes_ctr(const uint8_t *key, uint32_t keylen, | |
301 | const uint8_t *in, size_t inlen, | |
302 | const uint8_t *ctr, | |
303 | uint8_t *out, size_t outlen) | |
397 | ORIG_SYMVER(cipher_dec_aes_cbc, "1.0.0") | |
398 | int32_t orig_cipher_dec_aes_cbc(const uint8_t *key, uint32_t keylen, | |
399 | const uint8_t *in, uint32_t inlen, | |
400 | const uint8_t *iv, | |
401 | uint8_t *out, uint32_t outlen) | |
402 | { | |
403 | return (int32_t)kcapi_cipher_conv_dec_common("cbc(aes)", key, keylen, | |
404 | in, inlen, iv, | |
405 | out, outlen); | |
406 | } | |
407 | ||
408 | IMPL_SYMVER(cipher_dec_aes_ctr, "1.3.1") | |
409 | ssize_t impl_cipher_dec_aes_ctr(const uint8_t *key, uint32_t keylen, | |
410 | const uint8_t *in, size_t inlen, | |
411 | const uint8_t *ctr, | |
412 | uint8_t *out, size_t outlen) | |
304 | 413 | { |
305 | 414 | return kcapi_cipher_conv_dec_common("ctr(aes)", key, keylen, in, inlen, |
306 | 415 | ctr, out, outlen); |
307 | 416 | } |
417 | ||
418 | ORIG_SYMVER(cipher_dec_aes_ctr, "1.0.0") | |
419 | int32_t orig_cipher_dec_aes_ctr(const uint8_t *key, uint32_t keylen, | |
420 | const uint8_t *in, uint32_t inlen, | |
421 | const uint8_t *ctr, | |
422 | uint8_t *out, uint32_t outlen) | |
423 | { | |
424 | return (int32_t)kcapi_cipher_conv_dec_common("ctr(aes)", key, keylen, | |
425 | in, inlen, ctr, | |
426 | out, outlen); | |
427 | } |
159 | 159 | kcapi_get_maxsplicesize; |
160 | 160 | kcapi_set_maxsplicesize; |
161 | 161 | } LIBKCAPI_1.2.1; |
162 | ||
163 | LIBKCAPI_1.3.1 { | |
164 | kcapi_cipher_encrypt; | |
165 | kcapi_cipher_encrypt_aio; | |
166 | kcapi_cipher_decrypt; | |
167 | kcapi_cipher_decrypt_aio; | |
168 | kcapi_cipher_stream_init_enc; | |
169 | kcapi_cipher_stream_init_dec; | |
170 | kcapi_cipher_stream_update; | |
171 | kcapi_cipher_stream_op; | |
172 | kcapi_cipher_enc_aes_cbc; | |
173 | kcapi_cipher_dec_aes_cbc; | |
174 | kcapi_cipher_enc_aes_ctr; | |
175 | kcapi_cipher_dec_aes_ctr; | |
176 | kcapi_aead_getdata_input; | |
177 | kcapi_aead_getdata_output; | |
178 | kcapi_aead_encrypt; | |
179 | kcapi_aead_encrypt_aio; | |
180 | kcapi_aead_decrypt; | |
181 | kcapi_aead_decrypt_aio; | |
182 | kcapi_aead_setassoclen; | |
183 | kcapi_aead_stream_init_enc; | |
184 | kcapi_aead_stream_init_dec; | |
185 | kcapi_aead_stream_update; | |
186 | kcapi_aead_stream_update_last; | |
187 | kcapi_aead_stream_op; | |
188 | kcapi_aead_inbuflen_enc; | |
189 | kcapi_aead_inbuflen_dec; | |
190 | kcapi_aead_outbuflen_enc; | |
191 | kcapi_aead_outbuflen_dec; | |
192 | kcapi_md_update; | |
193 | kcapi_md_final; | |
194 | kcapi_md_digest; | |
195 | kcapi_md_sha1; | |
196 | kcapi_md_sha224; | |
197 | kcapi_md_sha256; | |
198 | kcapi_md_sha384; | |
199 | kcapi_md_sha512; | |
200 | kcapi_md_hmac_sha1; | |
201 | kcapi_md_hmac_sha224; | |
202 | kcapi_md_hmac_sha256; | |
203 | kcapi_md_hmac_sha384; | |
204 | kcapi_md_hmac_sha512; | |
205 | kcapi_rng_generate; | |
206 | kcapi_rng_get_bytes; | |
207 | kcapi_memset_secure; | |
208 | kcapi_akcipher_encrypt; | |
209 | kcapi_akcipher_decrypt; | |
210 | kcapi_akcipher_sign; | |
211 | kcapi_akcipher_verify; | |
212 | kcapi_akcipher_stream_init_enc; | |
213 | kcapi_akcipher_stream_init_dec; | |
214 | kcapi_akcipher_stream_init_sgn; | |
215 | kcapi_akcipher_stream_init_vfy; | |
216 | kcapi_akcipher_stream_update; | |
217 | kcapi_akcipher_stream_update_last; | |
218 | kcapi_akcipher_stream_op; | |
219 | kcapi_akcipher_encrypt_aio; | |
220 | kcapi_akcipher_decrypt_aio; | |
221 | kcapi_akcipher_sign_aio; | |
222 | kcapi_akcipher_verify_aio; | |
223 | kcapi_kpp_keygen; | |
224 | kcapi_kpp_ssgen; | |
225 | kcapi_kpp_keygen_aio; | |
226 | kcapi_kpp_ssgen_aio; | |
227 | kcapi_kdf_dpi; | |
228 | kcapi_kdf_fb; | |
229 | kcapi_kdf_ctr; | |
230 | kcapi_pbkdf; | |
231 | kcapi_hkdf; | |
232 | } LIBKCAPI_1.3.0; |