summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authortb <>2023-12-29 06:08:01 +0000
committertb <>2023-12-29 06:08:01 +0000
commitb1150f6e908de063136ab31bd074926d0a966d5e (patch)
tree2f04a5e51430f5cc8d529123b6fee7cf4fad4f9a /src
parent55b5efee44a1a983840a2ae8e17bca6699ea0eb5 (diff)
downloadopenbsd-b1150f6e908de063136ab31bd074926d0a966d5e.tar.gz
openbsd-b1150f6e908de063136ab31bd074926d0a966d5e.tar.bz2
openbsd-b1150f6e908de063136ab31bd074926d0a966d5e.zip
Move the middle part of evp_lib.c to evp_digest.c
These are ~200 lines of EVP_MD API that separated two parts of the file dedicated to EVP_CIPHER thingies.
Diffstat (limited to 'src')
-rw-r--r--src/lib/libcrypto/evp/evp_digest.c205
-rw-r--r--src/lib/libcrypto/evp/evp_lib.c205
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
371int
372EVP_MD_block_size(const EVP_MD *md)
373{
374 return md->block_size;
375}
376
377int
378EVP_MD_type(const EVP_MD *md)
379{
380 return md->type;
381}
382
383int
384EVP_MD_pkey_type(const EVP_MD *md)
385{
386 return md->pkey_type;
387}
388
389int
390EVP_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
399unsigned long
400EVP_MD_flags(const EVP_MD *md)
401{
402 return md->flags;
403}
404
405EVP_MD *
406EVP_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
419EVP_MD *
420EVP_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
432void
433EVP_MD_meth_free(EVP_MD *md)
434{
435 freezero(md, sizeof(*md));
436}
437
438int
439EVP_MD_meth_set_input_blocksize(EVP_MD *md, int blocksize)
440{
441 md->block_size = blocksize;
442 return 1;
443}
444
445int
446EVP_MD_meth_set_result_size(EVP_MD *md, int result_size)
447{
448 md->md_size = result_size;
449 return 1;
450}
451
452int
453EVP_MD_meth_set_app_datasize(EVP_MD *md, int datasize)
454{
455 md->ctx_size = datasize;
456 return 1;
457}
458
459int
460EVP_MD_meth_set_flags(EVP_MD *md, unsigned long flags)
461{
462 md->flags = flags;
463 return 1;
464}
465
466int
467EVP_MD_meth_set_init(EVP_MD *md, int (*init)(EVP_MD_CTX *ctx))
468{
469 md->init = init;
470 return 1;
471}
472
473int
474EVP_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
481int
482EVP_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
489int
490EVP_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
497int
498EVP_MD_meth_set_cleanup(EVP_MD *md,
499 int (*cleanup)(EVP_MD_CTX *ctx))
500{
501 md->cleanup = cleanup;
502 return 1;
503}
504
505int
506EVP_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
513const EVP_MD *
514EVP_MD_CTX_md(const EVP_MD_CTX *ctx)
515{
516 if (!ctx)
517 return NULL;
518 return ctx->digest;
519}
520
521void *
522EVP_MD_CTX_md_data(const EVP_MD_CTX *ctx)
523{
524 return ctx->md_data;
525}
526
527EVP_PKEY_CTX *
528EVP_MD_CTX_pkey_ctx(const EVP_MD_CTX *ctx)
529{
530 return ctx->pctx;
531}
532
533void
534EVP_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
556void
557EVP_MD_CTX_set_flags(EVP_MD_CTX *ctx, int flags)
558{
559 ctx->flags |= flags;
560}
561
562void
563EVP_MD_CTX_clear_flags(EVP_MD_CTX *ctx, int flags)
564{
565 ctx->flags &= ~flags;
566}
567
568int
569EVP_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
346int
347EVP_MD_block_size(const EVP_MD *md)
348{
349 return md->block_size;
350}
351
352int
353EVP_MD_type(const EVP_MD *md)
354{
355 return md->type;
356}
357
358int
359EVP_MD_pkey_type(const EVP_MD *md)
360{
361 return md->pkey_type;
362}
363
364int
365EVP_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
374unsigned long
375EVP_MD_flags(const EVP_MD *md)
376{
377 return md->flags;
378}
379
380EVP_MD *
381EVP_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
394EVP_MD *
395EVP_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
407void
408EVP_MD_meth_free(EVP_MD *md)
409{
410 freezero(md, sizeof(*md));
411}
412
413int
414EVP_MD_meth_set_input_blocksize(EVP_MD *md, int blocksize)
415{
416 md->block_size = blocksize;
417 return 1;
418}
419
420int
421EVP_MD_meth_set_result_size(EVP_MD *md, int result_size)
422{
423 md->md_size = result_size;
424 return 1;
425}
426
427int
428EVP_MD_meth_set_app_datasize(EVP_MD *md, int datasize)
429{
430 md->ctx_size = datasize;
431 return 1;
432}
433
434int
435EVP_MD_meth_set_flags(EVP_MD *md, unsigned long flags)
436{
437 md->flags = flags;
438 return 1;
439}
440
441int
442EVP_MD_meth_set_init(EVP_MD *md, int (*init)(EVP_MD_CTX *ctx))
443{
444 md->init = init;
445 return 1;
446}
447
448int
449EVP_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
456int
457EVP_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
464int
465EVP_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
472int
473EVP_MD_meth_set_cleanup(EVP_MD *md,
474 int (*cleanup)(EVP_MD_CTX *ctx))
475{
476 md->cleanup = cleanup;
477 return 1;
478}
479
480int
481EVP_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
488const EVP_MD *
489EVP_MD_CTX_md(const EVP_MD_CTX *ctx)
490{
491 if (!ctx)
492 return NULL;
493 return ctx->digest;
494}
495
496void *
497EVP_MD_CTX_md_data(const EVP_MD_CTX *ctx)
498{
499 return ctx->md_data;
500}
501
502EVP_PKEY_CTX *
503EVP_MD_CTX_pkey_ctx(const EVP_MD_CTX *ctx)
504{
505 return ctx->pctx;
506}
507
508void
509EVP_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
531void
532EVP_MD_CTX_set_flags(EVP_MD_CTX *ctx, int flags)
533{
534 ctx->flags |= flags;
535}
536
537void
538EVP_MD_CTX_clear_flags(EVP_MD_CTX *ctx, int flags)
539{
540 ctx->flags &= ~flags;
541}
542
543int
544EVP_MD_CTX_test_flags(const EVP_MD_CTX *ctx, int flags)
545{
546 return (ctx->flags & flags);
547}
548
549void 346void
550EVP_CIPHER_CTX_set_flags(EVP_CIPHER_CTX *ctx, int flags) 347EVP_CIPHER_CTX_set_flags(EVP_CIPHER_CTX *ctx, int flags)
551{ 348{