md2.c 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. /*
  2. * Copyright 2019 The OpenSSL Project Authors. All Rights Reserved.
  3. *
  4. * Licensed under the Apache License 2.0 (the "License"). You may not use
  5. * this file except in compliance with the License. You can obtain a copy
  6. * in the file LICENSE in the source distribution or at
  7. * https://www.openssl.org/source/license.html
  8. */
  9. #include <openssl/md2.h>
  10. #include <openssl/crypto.h>
  11. #include <openssl/core_numbers.h>
  12. static int md2_final(void *ctx, unsigned char *md, size_t *size)
  13. {
  14. if (MD2_Final(md, ctx)) {
  15. *size = MD2_DIGEST_LENGTH;
  16. return 1;
  17. }
  18. return 0;
  19. }
  20. static void *md2_newctx(void)
  21. {
  22. MD2_CTX *ctx = OPENSSL_zalloc(sizeof(*ctx));
  23. return ctx;
  24. }
  25. static void md2_freectx(void *vctx)
  26. {
  27. MD2_CTX *ctx = (MD2_CTX *)vctx;
  28. OPENSSL_clear_free(ctx, sizeof(*ctx));
  29. }
  30. static void *md2_dupctx(void *ctx)
  31. {
  32. MD2_CTX *in = (MD2_CTX *)ctx;
  33. MD2_CTX *ret = OPENSSL_malloc(sizeof(*ret));
  34. *ret = *in;
  35. return ret;
  36. }
  37. static size_t md2_size(void)
  38. {
  39. return MD2_DIGEST_LENGTH;
  40. }
  41. extern const OSSL_DISPATCH md2_functions[];
  42. const OSSL_DISPATCH md2_functions[] = {
  43. { OSSL_FUNC_DIGEST_NEWCTX, (void (*)(void))md2_newctx },
  44. { OSSL_FUNC_DIGEST_INIT, (void (*)(void))MD2_Init },
  45. { OSSL_FUNC_DIGEST_UPDATE, (void (*)(void))MD2_Update },
  46. { OSSL_FUNC_DIGEST_FINAL, (void (*)(void))md2_final },
  47. { OSSL_FUNC_DIGEST_FREECTX, (void (*)(void))md2_freectx },
  48. { OSSL_FUNC_DIGEST_DUPCTX, (void (*)(void))md2_dupctx },
  49. { OSSL_FUNC_DIGEST_SIZE, (void (*)(void))md2_size },
  50. { 0, NULL }
  51. };