null_prov.c 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. /*
  2. * Copyright 2021 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/crypto.h>
  10. #include "prov/digestcommon.h"
  11. #include "prov/implementations.h"
  12. typedef struct {
  13. unsigned char nothing;
  14. } NULLMD_CTX;
  15. static int null_init(NULLMD_CTX *ctx)
  16. {
  17. return 1;
  18. }
  19. static int null_update(NULLMD_CTX *ctx, const void *data, size_t datalen)
  20. {
  21. return 1;
  22. }
  23. static int null_final(unsigned char *md, NULLMD_CTX *ctx)
  24. {
  25. return 1;
  26. }
  27. /*
  28. * We must override the PROV_FUNC_DIGEST_FINAL as dgstsize == 0
  29. * and that would cause compilation warnings with the default implementation.
  30. */
  31. #undef PROV_FUNC_DIGEST_FINAL
  32. #define PROV_FUNC_DIGEST_FINAL(name, dgstsize, fin) \
  33. static OSSL_FUNC_digest_final_fn name##_internal_final; \
  34. static int name##_internal_final(void *ctx, unsigned char *out, size_t *outl, \
  35. size_t outsz) \
  36. { \
  37. if (ossl_prov_is_running() && fin(out, ctx)) { \
  38. *outl = dgstsize; \
  39. return 1; \
  40. } \
  41. return 0; \
  42. }
  43. IMPLEMENT_digest_functions(nullmd, NULLMD_CTX,
  44. 0, 0, 0,
  45. null_init, null_update, null_final)