m_blake2b.c 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. /*
  2. * Copyright 2016 The OpenSSL Project Authors. All Rights Reserved.
  3. *
  4. * Licensed under the OpenSSL license (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. /*
  10. * Derived from the BLAKE2 reference implementation written by Samuel Neves.
  11. * Copyright 2012, Samuel Neves <sneves@dei.uc.pt>
  12. * More information about the BLAKE2 hash function and its implementations
  13. * can be found at https://blake2.net.
  14. */
  15. #include "internal/cryptlib.h"
  16. #ifndef OPENSSL_NO_BLAKE2
  17. # include <openssl/evp.h>
  18. # include <openssl/objects.h>
  19. # include "blake2_locl.h"
  20. # include "internal/evp_int.h"
  21. static int init(EVP_MD_CTX *ctx)
  22. {
  23. return BLAKE2b_Init(EVP_MD_CTX_md_data(ctx));
  24. }
  25. static int update(EVP_MD_CTX *ctx, const void *data, size_t count)
  26. {
  27. return BLAKE2b_Update(EVP_MD_CTX_md_data(ctx), data, count);
  28. }
  29. static int final(EVP_MD_CTX *ctx, unsigned char *md)
  30. {
  31. return BLAKE2b_Final(md, EVP_MD_CTX_md_data(ctx));
  32. }
  33. static const EVP_MD blake2b_md = {
  34. NID_blake2b512,
  35. 0,
  36. BLAKE2B_DIGEST_LENGTH,
  37. 0,
  38. init,
  39. update,
  40. final,
  41. NULL,
  42. NULL,
  43. BLAKE2B_BLOCKBYTES,
  44. sizeof(EVP_MD *) + sizeof(BLAKE2B_CTX),
  45. };
  46. const EVP_MD *EVP_blake2b512(void)
  47. {
  48. return (&blake2b_md);
  49. }
  50. #endif