diff options
author | tb <> | 2022-01-10 13:42:28 +0000 |
---|---|---|
committer | tb <> | 2022-01-10 13:42:28 +0000 |
commit | a99850ca0f1189f9c4b1fa9810f054ddb2622d83 (patch) | |
tree | 2bc925230c4c9e6d5030de84f085dab06f9d25b2 /src/lib/libcrypto/evp/evp_lib.c | |
parent | 80e49b6de2faa815afabe6d27b0845ffe123db72 (diff) | |
download | openbsd-a99850ca0f1189f9c4b1fa9810f054ddb2622d83.tar.gz openbsd-a99850ca0f1189f9c4b1fa9810f054ddb2622d83.tar.bz2 openbsd-a99850ca0f1189f9c4b1fa9810f054ddb2622d83.zip |
Prepare to provide the EVP_MD_meth_* API
This allows implementations to add their own EVP_MD_METHODs.
Only the setters are provided.
This is used by erlang for the otp_test_engine.
ok inoguchi jsing
Diffstat (limited to 'src/lib/libcrypto/evp/evp_lib.c')
-rw-r--r-- | src/lib/libcrypto/evp/evp_lib.c | 110 |
1 files changed, 109 insertions, 1 deletions
diff --git a/src/lib/libcrypto/evp/evp_lib.c b/src/lib/libcrypto/evp/evp_lib.c index c96813987f..0e354d6272 100644 --- a/src/lib/libcrypto/evp/evp_lib.c +++ b/src/lib/libcrypto/evp/evp_lib.c | |||
@@ -1,4 +1,4 @@ | |||
1 | /* $OpenBSD: evp_lib.c,v 1.23 2022/01/09 15:15:25 tb Exp $ */ | 1 | /* $OpenBSD: evp_lib.c,v 1.24 2022/01/10 13:42:28 tb Exp $ */ |
2 | /* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) | 2 | /* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) |
3 | * All rights reserved. | 3 | * All rights reserved. |
4 | * | 4 | * |
@@ -371,6 +371,114 @@ EVP_MD_flags(const EVP_MD *md) | |||
371 | return md->flags; | 371 | return md->flags; |
372 | } | 372 | } |
373 | 373 | ||
374 | EVP_MD * | ||
375 | EVP_MD_meth_new(int md_type, int pkey_type) | ||
376 | { | ||
377 | EVP_MD *md; | ||
378 | |||
379 | if ((md = calloc(1, sizeof(*md))) == NULL) | ||
380 | return NULL; | ||
381 | |||
382 | md->type = md_type; | ||
383 | md->pkey_type = pkey_type; | ||
384 | |||
385 | return md; | ||
386 | } | ||
387 | |||
388 | EVP_MD * | ||
389 | EVP_MD_meth_dup(const EVP_MD *md) | ||
390 | { | ||
391 | EVP_MD *to; | ||
392 | |||
393 | if ((to = EVP_MD_meth_new(md->type, md->pkey_type)) == NULL) | ||
394 | return NULL; | ||
395 | |||
396 | memcpy(to, md, sizeof(*to)); | ||
397 | |||
398 | return to; | ||
399 | } | ||
400 | |||
401 | void | ||
402 | EVP_MD_meth_free(EVP_MD *md) | ||
403 | { | ||
404 | freezero(md, sizeof(*md)); | ||
405 | } | ||
406 | |||
407 | int | ||
408 | EVP_MD_meth_set_input_blocksize(EVP_MD *md, int blocksize) | ||
409 | { | ||
410 | md->block_size = blocksize; | ||
411 | return 1; | ||
412 | } | ||
413 | |||
414 | int | ||
415 | EVP_MD_meth_set_result_size(EVP_MD *md, int result_size) | ||
416 | { | ||
417 | md->md_size = result_size; | ||
418 | return 1; | ||
419 | } | ||
420 | |||
421 | int | ||
422 | EVP_MD_meth_set_app_datasize(EVP_MD *md, int datasize) | ||
423 | { | ||
424 | md->ctx_size = datasize; | ||
425 | return 1; | ||
426 | } | ||
427 | |||
428 | int | ||
429 | EVP_MD_meth_set_flags(EVP_MD *md, unsigned long flags) | ||
430 | { | ||
431 | md->flags = flags; | ||
432 | return 1; | ||
433 | } | ||
434 | |||
435 | int | ||
436 | EVP_MD_meth_set_init(EVP_MD *md, int (*init)(EVP_MD_CTX *ctx)) | ||
437 | { | ||
438 | md->init = init; | ||
439 | return 1; | ||
440 | } | ||
441 | |||
442 | int | ||
443 | EVP_MD_meth_set_update(EVP_MD *md, | ||
444 | int (*update)(EVP_MD_CTX *ctx, const void *data, size_t count)) | ||
445 | { | ||
446 | md->update = update; | ||
447 | return 1; | ||
448 | } | ||
449 | |||
450 | int | ||
451 | EVP_MD_meth_set_final(EVP_MD *md, | ||
452 | int (*final)(EVP_MD_CTX *ctx, unsigned char *md)) | ||
453 | { | ||
454 | md->final = final; | ||
455 | return 1; | ||
456 | } | ||
457 | |||
458 | int | ||
459 | EVP_MD_meth_set_copy(EVP_MD *md, | ||
460 | int (*copy)(EVP_MD_CTX *to, const EVP_MD_CTX *from)) | ||
461 | { | ||
462 | md->copy = copy; | ||
463 | return 1; | ||
464 | } | ||
465 | |||
466 | int | ||
467 | EVP_MD_meth_set_cleanup(EVP_MD *md, | ||
468 | int (*cleanup)(EVP_MD_CTX *ctx)) | ||
469 | { | ||
470 | md->cleanup = cleanup; | ||
471 | return 1; | ||
472 | } | ||
473 | |||
474 | int | ||
475 | EVP_MD_meth_set_ctrl(EVP_MD *md, | ||
476 | int (*ctrl)(EVP_MD_CTX *ctx, int cmd, int p1, void *p2)) | ||
477 | { | ||
478 | md->md_ctrl = ctrl; | ||
479 | return 1; | ||
480 | } | ||
481 | |||
374 | const EVP_MD * | 482 | const EVP_MD * |
375 | EVP_MD_CTX_md(const EVP_MD_CTX *ctx) | 483 | EVP_MD_CTX_md(const EVP_MD_CTX *ctx) |
376 | { | 484 | { |