m_blake2s.c 1.3 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 BLAKE2s_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 BLAKE2s_Update(EVP_MD_CTX_md_data(ctx), data, count);
  28. }
  29. static int final(EVP_MD_CTX *ctx, unsigned char *md)
  30. {
  31. return BLAKE2s_Final(md, EVP_MD_CTX_md_data(ctx));
  32. }
  33. static const EVP_MD blake2s_md = {
  34. NID_blake2s256,
  35. 0,
  36. BLAKE2S_DIGEST_LENGTH,
  37. 0,
  38. init,
  39. update,
  40. final,
  41. NULL,
  42. NULL,
  43. BLAKE2S_BLOCKBYTES,
  44. sizeof(EVP_MD *) + sizeof(BLAKE2S_CTX),
  45. };
  46. const EVP_MD *EVP_blake2s256(void)
  47. {
  48. return &blake2s_md;
  49. }
  50. #endif