blake2_locl.h 2.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  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 <stddef.h>
  16. #include "e_os.h"
  17. #define BLAKE2S_BLOCKBYTES 64
  18. #define BLAKE2S_OUTBYTES 32
  19. #define BLAKE2S_KEYBYTES 32
  20. #define BLAKE2S_SALTBYTES 8
  21. #define BLAKE2S_PERSONALBYTES 8
  22. #define BLAKE2B_BLOCKBYTES 128
  23. #define BLAKE2B_OUTBYTES 64
  24. #define BLAKE2B_KEYBYTES 64
  25. #define BLAKE2B_SALTBYTES 16
  26. #define BLAKE2B_PERSONALBYTES 16
  27. struct blake2s_param_st {
  28. uint8_t digest_length; /* 1 */
  29. uint8_t key_length; /* 2 */
  30. uint8_t fanout; /* 3 */
  31. uint8_t depth; /* 4 */
  32. uint8_t leaf_length[4];/* 8 */
  33. uint8_t node_offset[6];/* 14 */
  34. uint8_t node_depth; /* 15 */
  35. uint8_t inner_length; /* 16 */
  36. uint8_t salt[BLAKE2S_SALTBYTES]; /* 24 */
  37. uint8_t personal[BLAKE2S_PERSONALBYTES]; /* 32 */
  38. };
  39. typedef struct blake2s_param_st BLAKE2S_PARAM;
  40. struct blake2s_ctx_st {
  41. uint32_t h[8];
  42. uint32_t t[2];
  43. uint32_t f[2];
  44. uint8_t buf[BLAKE2S_BLOCKBYTES];
  45. size_t buflen;
  46. };
  47. struct blake2b_param_st {
  48. uint8_t digest_length; /* 1 */
  49. uint8_t key_length; /* 2 */
  50. uint8_t fanout; /* 3 */
  51. uint8_t depth; /* 4 */
  52. uint8_t leaf_length[4];/* 8 */
  53. uint8_t node_offset[8];/* 16 */
  54. uint8_t node_depth; /* 17 */
  55. uint8_t inner_length; /* 18 */
  56. uint8_t reserved[14]; /* 32 */
  57. uint8_t salt[BLAKE2B_SALTBYTES]; /* 48 */
  58. uint8_t personal[BLAKE2B_PERSONALBYTES]; /* 64 */
  59. };
  60. typedef struct blake2b_param_st BLAKE2B_PARAM;
  61. struct blake2b_ctx_st {
  62. uint64_t h[8];
  63. uint64_t t[2];
  64. uint64_t f[2];
  65. uint8_t buf[BLAKE2B_BLOCKBYTES];
  66. size_t buflen;
  67. };
  68. #define BLAKE2B_DIGEST_LENGTH 64
  69. #define BLAKE2S_DIGEST_LENGTH 32
  70. typedef struct blake2s_ctx_st BLAKE2S_CTX;
  71. typedef struct blake2b_ctx_st BLAKE2B_CTX;
  72. int BLAKE2b_Init(BLAKE2B_CTX *c);
  73. int BLAKE2b_Update(BLAKE2B_CTX *c, const void *data, size_t datalen);
  74. int BLAKE2b_Final(unsigned char *md, BLAKE2B_CTX *c);
  75. int BLAKE2s_Init(BLAKE2S_CTX *c);
  76. int BLAKE2s_Update(BLAKE2S_CTX *c, const void *data, size_t datalen);
  77. int BLAKE2s_Final(unsigned char *md, BLAKE2S_CTX *c);