diff options
Diffstat (limited to '')
| -rw-r--r-- | src/lib/libcrypto/evp/evp_digest.c | 205 | ||||
| -rw-r--r-- | src/lib/libcrypto/evp/evp_lib.c | 205 |
2 files changed, 205 insertions, 205 deletions
diff --git a/src/lib/libcrypto/evp/evp_digest.c b/src/lib/libcrypto/evp/evp_digest.c index deb282e4ec..583c454845 100644 --- a/src/lib/libcrypto/evp/evp_digest.c +++ b/src/lib/libcrypto/evp/evp_digest.c | |||
| @@ -1,4 +1,4 @@ | |||
| 1 | /* $OpenBSD: evp_digest.c,v 1.1 2023/12/29 05:57:24 tb Exp $ */ | 1 | /* $OpenBSD: evp_digest.c,v 1.2 2023/12/29 06:08:01 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 | * |
| @@ -367,3 +367,206 @@ EVP_MD_CTX_ctrl(EVP_MD_CTX *ctx, int type, int arg, void *ptr) | |||
| 367 | } | 367 | } |
| 368 | return ret; | 368 | return ret; |
| 369 | } | 369 | } |
| 370 | |||
| 371 | int | ||
| 372 | EVP_MD_block_size(const EVP_MD *md) | ||
| 373 | { | ||
| 374 | return md->block_size; | ||
| 375 | } | ||
| 376 | |||
| 377 | int | ||
| 378 | EVP_MD_type(const EVP_MD *md) | ||
| 379 | { | ||
| 380 | return md->type; | ||
| 381 | } | ||
| 382 | |||
| 383 | int | ||
| 384 | EVP_MD_pkey_type(const EVP_MD *md) | ||
| 385 | { | ||
| 386 | return md->pkey_type; | ||
| 387 | } | ||
| 388 | |||
| 389 | int | ||
| 390 | EVP_MD_size(const EVP_MD *md) | ||
| 391 | { | ||
| 392 | if (!md) { | ||
| 393 | EVPerror(EVP_R_MESSAGE_DIGEST_IS_NULL); | ||
| 394 | return -1; | ||
| 395 | } | ||
| 396 | return md->md_size; | ||
| 397 | } | ||
| 398 | |||
| 399 | unsigned long | ||
| 400 | EVP_MD_flags(const EVP_MD *md) | ||
| 401 | { | ||
| 402 | return md->flags; | ||
| 403 | } | ||
| 404 | |||
| 405 | EVP_MD * | ||
| 406 | EVP_MD_meth_new(int md_type, int pkey_type) | ||
| 407 | { | ||
| 408 | EVP_MD *md; | ||
| 409 | |||
| 410 | if ((md = calloc(1, sizeof(*md))) == NULL) | ||
| 411 | return NULL; | ||
| 412 | |||
| 413 | md->type = md_type; | ||
| 414 | md->pkey_type = pkey_type; | ||
| 415 | |||
| 416 | return md; | ||
| 417 | } | ||
| 418 | |||
| 419 | EVP_MD * | ||
| 420 | EVP_MD_meth_dup(const EVP_MD *md) | ||
| 421 | { | ||
| 422 | EVP_MD *to; | ||
| 423 | |||
| 424 | if ((to = EVP_MD_meth_new(md->type, md->pkey_type)) == NULL) | ||
| 425 | return NULL; | ||
| 426 | |||
| 427 | memcpy(to, md, sizeof(*to)); | ||
| 428 | |||
| 429 | return to; | ||
| 430 | } | ||
| 431 | |||
| 432 | void | ||
| 433 | EVP_MD_meth_free(EVP_MD *md) | ||
| 434 | { | ||
| 435 | freezero(md, sizeof(*md)); | ||
| 436 | } | ||
| 437 | |||
| 438 | int | ||
| 439 | EVP_MD_meth_set_input_blocksize(EVP_MD *md, int blocksize) | ||
| 440 | { | ||
| 441 | md->block_size = blocksize; | ||
| 442 | return 1; | ||
| 443 | } | ||
| 444 | |||
| 445 | int | ||
| 446 | EVP_MD_meth_set_result_size(EVP_MD *md, int result_size) | ||
| 447 | { | ||
| 448 | md->md_size = result_size; | ||
| 449 | return 1; | ||
| 450 | } | ||
| 451 | |||
| 452 | int | ||
| 453 | EVP_MD_meth_set_app_datasize(EVP_MD *md, int datasize) | ||
| 454 | { | ||
| 455 | md->ctx_size = datasize; | ||
| 456 | return 1; | ||
| 457 | } | ||
| 458 | |||
| 459 | int | ||
| 460 | EVP_MD_meth_set_flags(EVP_MD *md, unsigned long flags) | ||
| 461 | { | ||
| 462 | md->flags = flags; | ||
| 463 | return 1; | ||
| 464 | } | ||
| 465 | |||
| 466 | int | ||
| 467 | EVP_MD_meth_set_init(EVP_MD *md, int (*init)(EVP_MD_CTX *ctx)) | ||
| 468 | { | ||
| 469 | md->init = init; | ||
| 470 | return 1; | ||
| 471 | } | ||
| 472 | |||
| 473 | int | ||
| 474 | EVP_MD_meth_set_update(EVP_MD *md, | ||
| 475 | int (*update)(EVP_MD_CTX *ctx, const void *data, size_t count)) | ||
| 476 | { | ||
| 477 | md->update = update; | ||
| 478 | return 1; | ||
| 479 | } | ||
| 480 | |||
| 481 | int | ||
| 482 | EVP_MD_meth_set_final(EVP_MD *md, | ||
| 483 | int (*final)(EVP_MD_CTX *ctx, unsigned char *md)) | ||
| 484 | { | ||
| 485 | md->final = final; | ||
| 486 | return 1; | ||
| 487 | } | ||
| 488 | |||
| 489 | int | ||
| 490 | EVP_MD_meth_set_copy(EVP_MD *md, | ||
| 491 | int (*copy)(EVP_MD_CTX *to, const EVP_MD_CTX *from)) | ||
| 492 | { | ||
| 493 | md->copy = copy; | ||
| 494 | return 1; | ||
| 495 | } | ||
| 496 | |||
| 497 | int | ||
| 498 | EVP_MD_meth_set_cleanup(EVP_MD *md, | ||
| 499 | int (*cleanup)(EVP_MD_CTX *ctx)) | ||
| 500 | { | ||
| 501 | md->cleanup = cleanup; | ||
| 502 | return 1; | ||
| 503 | } | ||
| 504 | |||
| 505 | int | ||
| 506 | EVP_MD_meth_set_ctrl(EVP_MD *md, | ||
| 507 | int (*ctrl)(EVP_MD_CTX *ctx, int cmd, int p1, void *p2)) | ||
| 508 | { | ||
| 509 | md->md_ctrl = ctrl; | ||
| 510 | return 1; | ||
| 511 | } | ||
| 512 | |||
| 513 | const EVP_MD * | ||
| 514 | EVP_MD_CTX_md(const EVP_MD_CTX *ctx) | ||
| 515 | { | ||
| 516 | if (!ctx) | ||
| 517 | return NULL; | ||
| 518 | return ctx->digest; | ||
| 519 | } | ||
| 520 | |||
| 521 | void * | ||
| 522 | EVP_MD_CTX_md_data(const EVP_MD_CTX *ctx) | ||
| 523 | { | ||
| 524 | return ctx->md_data; | ||
| 525 | } | ||
| 526 | |||
| 527 | EVP_PKEY_CTX * | ||
| 528 | EVP_MD_CTX_pkey_ctx(const EVP_MD_CTX *ctx) | ||
| 529 | { | ||
| 530 | return ctx->pctx; | ||
| 531 | } | ||
| 532 | |||
| 533 | void | ||
| 534 | EVP_MD_CTX_set_pkey_ctx(EVP_MD_CTX *ctx, EVP_PKEY_CTX *pctx) | ||
| 535 | { | ||
| 536 | if (EVP_MD_CTX_test_flags(ctx, EVP_MD_CTX_FLAG_KEEP_PKEY_CTX)) { | ||
| 537 | EVP_MD_CTX_clear_flags(ctx, EVP_MD_CTX_FLAG_KEEP_PKEY_CTX); | ||
| 538 | } else { | ||
| 539 | EVP_PKEY_CTX_free(ctx->pctx); | ||
| 540 | } | ||
| 541 | |||
| 542 | ctx->pctx = pctx; | ||
| 543 | |||
| 544 | if (pctx != NULL) { | ||
| 545 | /* | ||
| 546 | * For unclear reasons it was decided that the caller keeps | ||
| 547 | * ownership of pctx. So a flag was invented to make sure we | ||
| 548 | * don't free it in EVP_MD_CTX_cleanup(). We also need to | ||
| 549 | * unset it in EVP_MD_CTX_copy_ex(). Fortunately, the flag | ||
| 550 | * isn't public... | ||
| 551 | */ | ||
| 552 | EVP_MD_CTX_set_flags(ctx, EVP_MD_CTX_FLAG_KEEP_PKEY_CTX); | ||
| 553 | } | ||
| 554 | } | ||
| 555 | |||
| 556 | void | ||
| 557 | EVP_MD_CTX_set_flags(EVP_MD_CTX *ctx, int flags) | ||
| 558 | { | ||
| 559 | ctx->flags |= flags; | ||
| 560 | } | ||
| 561 | |||
| 562 | void | ||
| 563 | EVP_MD_CTX_clear_flags(EVP_MD_CTX *ctx, int flags) | ||
| 564 | { | ||
| 565 | ctx->flags &= ~flags; | ||
| 566 | } | ||
| 567 | |||
| 568 | int | ||
| 569 | EVP_MD_CTX_test_flags(const EVP_MD_CTX *ctx, int flags) | ||
| 570 | { | ||
| 571 | return (ctx->flags & flags); | ||
| 572 | } | ||
diff --git a/src/lib/libcrypto/evp/evp_lib.c b/src/lib/libcrypto/evp/evp_lib.c index 622d40dbdf..3288129442 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.30 2023/12/15 13:28:30 tb Exp $ */ | 1 | /* $OpenBSD: evp_lib.c,v 1.31 2023/12/29 06:08:01 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 | * |
| @@ -343,209 +343,6 @@ EVP_CIPHER_CTX_set_iv(EVP_CIPHER_CTX *ctx, const unsigned char *iv, size_t len) | |||
| 343 | return 1; | 343 | return 1; |
| 344 | } | 344 | } |
| 345 | 345 | ||
| 346 | int | ||
| 347 | EVP_MD_block_size(const EVP_MD *md) | ||
| 348 | { | ||
| 349 | return md->block_size; | ||
| 350 | } | ||
| 351 | |||
| 352 | int | ||
| 353 | EVP_MD_type(const EVP_MD *md) | ||
| 354 | { | ||
| 355 | return md->type; | ||
| 356 | } | ||
| 357 | |||
| 358 | int | ||
| 359 | EVP_MD_pkey_type(const EVP_MD *md) | ||
| 360 | { | ||
| 361 | return md->pkey_type; | ||
| 362 | } | ||
| 363 | |||
| 364 | int | ||
| 365 | EVP_MD_size(const EVP_MD *md) | ||
| 366 | { | ||
| 367 | if (!md) { | ||
| 368 | EVPerror(EVP_R_MESSAGE_DIGEST_IS_NULL); | ||
| 369 | return -1; | ||
| 370 | } | ||
| 371 | return md->md_size; | ||
| 372 | } | ||
| 373 | |||
| 374 | unsigned long | ||
| 375 | EVP_MD_flags(const EVP_MD *md) | ||
| 376 | { | ||
| 377 | return md->flags; | ||
| 378 | } | ||
| 379 | |||
| 380 | EVP_MD * | ||
| 381 | EVP_MD_meth_new(int md_type, int pkey_type) | ||
| 382 | { | ||
| 383 | EVP_MD *md; | ||
| 384 | |||
| 385 | if ((md = calloc(1, sizeof(*md))) == NULL) | ||
| 386 | return NULL; | ||
| 387 | |||
| 388 | md->type = md_type; | ||
| 389 | md->pkey_type = pkey_type; | ||
| 390 | |||
| 391 | return md; | ||
| 392 | } | ||
| 393 | |||
| 394 | EVP_MD * | ||
| 395 | EVP_MD_meth_dup(const EVP_MD *md) | ||
| 396 | { | ||
| 397 | EVP_MD *to; | ||
| 398 | |||
| 399 | if ((to = EVP_MD_meth_new(md->type, md->pkey_type)) == NULL) | ||
| 400 | return NULL; | ||
| 401 | |||
| 402 | memcpy(to, md, sizeof(*to)); | ||
| 403 | |||
| 404 | return to; | ||
| 405 | } | ||
| 406 | |||
| 407 | void | ||
| 408 | EVP_MD_meth_free(EVP_MD *md) | ||
| 409 | { | ||
| 410 | freezero(md, sizeof(*md)); | ||
| 411 | } | ||
| 412 | |||
| 413 | int | ||
| 414 | EVP_MD_meth_set_input_blocksize(EVP_MD *md, int blocksize) | ||
| 415 | { | ||
| 416 | md->block_size = blocksize; | ||
| 417 | return 1; | ||
| 418 | } | ||
| 419 | |||
| 420 | int | ||
| 421 | EVP_MD_meth_set_result_size(EVP_MD *md, int result_size) | ||
| 422 | { | ||
| 423 | md->md_size = result_size; | ||
| 424 | return 1; | ||
| 425 | } | ||
| 426 | |||
| 427 | int | ||
| 428 | EVP_MD_meth_set_app_datasize(EVP_MD *md, int datasize) | ||
| 429 | { | ||
| 430 | md->ctx_size = datasize; | ||
| 431 | return 1; | ||
| 432 | } | ||
| 433 | |||
| 434 | int | ||
| 435 | EVP_MD_meth_set_flags(EVP_MD *md, unsigned long flags) | ||
| 436 | { | ||
| 437 | md->flags = flags; | ||
| 438 | return 1; | ||
| 439 | } | ||
| 440 | |||
| 441 | int | ||
| 442 | EVP_MD_meth_set_init(EVP_MD *md, int (*init)(EVP_MD_CTX *ctx)) | ||
| 443 | { | ||
| 444 | md->init = init; | ||
| 445 | return 1; | ||
| 446 | } | ||
| 447 | |||
| 448 | int | ||
| 449 | EVP_MD_meth_set_update(EVP_MD *md, | ||
| 450 | int (*update)(EVP_MD_CTX *ctx, const void *data, size_t count)) | ||
| 451 | { | ||
| 452 | md->update = update; | ||
| 453 | return 1; | ||
| 454 | } | ||
| 455 | |||
| 456 | int | ||
| 457 | EVP_MD_meth_set_final(EVP_MD *md, | ||
| 458 | int (*final)(EVP_MD_CTX *ctx, unsigned char *md)) | ||
| 459 | { | ||
| 460 | md->final = final; | ||
| 461 | return 1; | ||
| 462 | } | ||
| 463 | |||
| 464 | int | ||
| 465 | EVP_MD_meth_set_copy(EVP_MD *md, | ||
| 466 | int (*copy)(EVP_MD_CTX *to, const EVP_MD_CTX *from)) | ||
| 467 | { | ||
| 468 | md->copy = copy; | ||
| 469 | return 1; | ||
| 470 | } | ||
| 471 | |||
| 472 | int | ||
| 473 | EVP_MD_meth_set_cleanup(EVP_MD *md, | ||
| 474 | int (*cleanup)(EVP_MD_CTX *ctx)) | ||
| 475 | { | ||
| 476 | md->cleanup = cleanup; | ||
| 477 | return 1; | ||
| 478 | } | ||
| 479 | |||
| 480 | int | ||
| 481 | EVP_MD_meth_set_ctrl(EVP_MD *md, | ||
| 482 | int (*ctrl)(EVP_MD_CTX *ctx, int cmd, int p1, void *p2)) | ||
| 483 | { | ||
| 484 | md->md_ctrl = ctrl; | ||
| 485 | return 1; | ||
| 486 | } | ||
| 487 | |||
| 488 | const EVP_MD * | ||
| 489 | EVP_MD_CTX_md(const EVP_MD_CTX *ctx) | ||
| 490 | { | ||
| 491 | if (!ctx) | ||
| 492 | return NULL; | ||
| 493 | return ctx->digest; | ||
| 494 | } | ||
| 495 | |||
| 496 | void * | ||
| 497 | EVP_MD_CTX_md_data(const EVP_MD_CTX *ctx) | ||
| 498 | { | ||
| 499 | return ctx->md_data; | ||
| 500 | } | ||
| 501 | |||
| 502 | EVP_PKEY_CTX * | ||
| 503 | EVP_MD_CTX_pkey_ctx(const EVP_MD_CTX *ctx) | ||
| 504 | { | ||
| 505 | return ctx->pctx; | ||
| 506 | } | ||
| 507 | |||
| 508 | void | ||
| 509 | EVP_MD_CTX_set_pkey_ctx(EVP_MD_CTX *ctx, EVP_PKEY_CTX *pctx) | ||
| 510 | { | ||
| 511 | if (EVP_MD_CTX_test_flags(ctx, EVP_MD_CTX_FLAG_KEEP_PKEY_CTX)) { | ||
| 512 | EVP_MD_CTX_clear_flags(ctx, EVP_MD_CTX_FLAG_KEEP_PKEY_CTX); | ||
| 513 | } else { | ||
| 514 | EVP_PKEY_CTX_free(ctx->pctx); | ||
| 515 | } | ||
| 516 | |||
| 517 | ctx->pctx = pctx; | ||
| 518 | |||
| 519 | if (pctx != NULL) { | ||
| 520 | /* | ||
| 521 | * For unclear reasons it was decided that the caller keeps | ||
| 522 | * ownership of pctx. So a flag was invented to make sure we | ||
| 523 | * don't free it in EVP_MD_CTX_cleanup(). We also need to | ||
| 524 | * unset it in EVP_MD_CTX_copy_ex(). Fortunately, the flag | ||
| 525 | * isn't public... | ||
| 526 | */ | ||
| 527 | EVP_MD_CTX_set_flags(ctx, EVP_MD_CTX_FLAG_KEEP_PKEY_CTX); | ||
| 528 | } | ||
| 529 | } | ||
| 530 | |||
| 531 | void | ||
| 532 | EVP_MD_CTX_set_flags(EVP_MD_CTX *ctx, int flags) | ||
| 533 | { | ||
| 534 | ctx->flags |= flags; | ||
| 535 | } | ||
| 536 | |||
| 537 | void | ||
| 538 | EVP_MD_CTX_clear_flags(EVP_MD_CTX *ctx, int flags) | ||
| 539 | { | ||
| 540 | ctx->flags &= ~flags; | ||
| 541 | } | ||
| 542 | |||
| 543 | int | ||
| 544 | EVP_MD_CTX_test_flags(const EVP_MD_CTX *ctx, int flags) | ||
| 545 | { | ||
| 546 | return (ctx->flags & flags); | ||
| 547 | } | ||
| 548 | |||
| 549 | void | 346 | void |
| 550 | EVP_CIPHER_CTX_set_flags(EVP_CIPHER_CTX *ctx, int flags) | 347 | EVP_CIPHER_CTX_set_flags(EVP_CIPHER_CTX *ctx, int flags) |
| 551 | { | 348 | { |
