summaryrefslogtreecommitdiff
path: root/src/lib/libcrypto/evp/evp_lib.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/lib/libcrypto/evp/evp_lib.c')
-rw-r--r--src/lib/libcrypto/evp/evp_lib.c205
1 files changed, 1 insertions, 204 deletions
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{