legacy_blake2.c 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. /*
  2. * Copyright 2019-2023 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 "crypto/evp.h"
  10. #include "prov/blake2.h" /* diverse BLAKE2 macros */
  11. #include "legacy_meth.h"
  12. /*
  13. * Local hack to adapt the BLAKE2 init functions to what the
  14. * legacy function signatures demand.
  15. */
  16. static int blake2s_init(BLAKE2S_CTX *C)
  17. {
  18. BLAKE2S_PARAM P;
  19. ossl_blake2s_param_init(&P);
  20. return ossl_blake2s_init(C, &P);
  21. }
  22. static int blake2b_init(BLAKE2B_CTX *C)
  23. {
  24. BLAKE2B_PARAM P;
  25. ossl_blake2b_param_init(&P);
  26. return ossl_blake2b_init(C, &P);
  27. }
  28. #define blake2s_update ossl_blake2s_update
  29. #define blake2b_update ossl_blake2b_update
  30. #define blake2s_final ossl_blake2s_final
  31. #define blake2b_final ossl_blake2b_final
  32. IMPLEMENT_LEGACY_EVP_MD_METH_LC(blake2s_int, blake2s)
  33. IMPLEMENT_LEGACY_EVP_MD_METH_LC(blake2b_int, blake2b)
  34. static const EVP_MD blake2b_md = {
  35. NID_blake2b512,
  36. 0,
  37. BLAKE2B_DIGEST_LENGTH,
  38. 0,
  39. EVP_ORIG_GLOBAL,
  40. LEGACY_EVP_MD_METH_TABLE(blake2b_int_init, blake2b_int_update,
  41. blake2b_int_final, NULL, BLAKE2B_BLOCKBYTES),
  42. };
  43. const EVP_MD *EVP_blake2b512(void)
  44. {
  45. return &blake2b_md;
  46. }
  47. static const EVP_MD blake2s_md = {
  48. NID_blake2s256,
  49. 0,
  50. BLAKE2S_DIGEST_LENGTH,
  51. 0,
  52. EVP_ORIG_GLOBAL,
  53. LEGACY_EVP_MD_METH_TABLE(blake2s_int_init, blake2s_int_update,
  54. blake2s_int_final, NULL, BLAKE2S_BLOCKBYTES),
  55. };
  56. const EVP_MD *EVP_blake2s256(void)
  57. {
  58. return &blake2s_md;
  59. }