2
0

blake2.h 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120
  1. /*
  2. * Copyright 2019-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. #ifndef OSSL_PROV_BLAKE2_H
  10. # define OSSL_PROV_BLAKE2_H
  11. # include <openssl/opensslconf.h>
  12. # include <openssl/e_os2.h>
  13. # include <stddef.h>
  14. # define BLAKE2S_BLOCKBYTES 64
  15. # define BLAKE2S_OUTBYTES 32
  16. # define BLAKE2S_KEYBYTES 32
  17. # define BLAKE2S_SALTBYTES 8
  18. # define BLAKE2S_PERSONALBYTES 8
  19. # define BLAKE2B_BLOCKBYTES 128
  20. # define BLAKE2B_OUTBYTES 64
  21. # define BLAKE2B_KEYBYTES 64
  22. # define BLAKE2B_SALTBYTES 16
  23. # define BLAKE2B_PERSONALBYTES 16
  24. struct blake2s_param_st {
  25. uint8_t digest_length; /* 1 */
  26. uint8_t key_length; /* 2 */
  27. uint8_t fanout; /* 3 */
  28. uint8_t depth; /* 4 */
  29. uint8_t leaf_length[4];/* 8 */
  30. uint8_t node_offset[6];/* 14 */
  31. uint8_t node_depth; /* 15 */
  32. uint8_t inner_length; /* 16 */
  33. uint8_t salt[BLAKE2S_SALTBYTES]; /* 24 */
  34. uint8_t personal[BLAKE2S_PERSONALBYTES]; /* 32 */
  35. };
  36. typedef struct blake2s_param_st BLAKE2S_PARAM;
  37. struct blake2s_ctx_st {
  38. uint32_t h[8];
  39. uint32_t t[2];
  40. uint32_t f[2];
  41. uint8_t buf[BLAKE2S_BLOCKBYTES];
  42. size_t buflen;
  43. size_t outlen;
  44. };
  45. struct blake2b_param_st {
  46. uint8_t digest_length; /* 1 */
  47. uint8_t key_length; /* 2 */
  48. uint8_t fanout; /* 3 */
  49. uint8_t depth; /* 4 */
  50. uint8_t leaf_length[4];/* 8 */
  51. uint8_t node_offset[8];/* 16 */
  52. uint8_t node_depth; /* 17 */
  53. uint8_t inner_length; /* 18 */
  54. uint8_t reserved[14]; /* 32 */
  55. uint8_t salt[BLAKE2B_SALTBYTES]; /* 48 */
  56. uint8_t personal[BLAKE2B_PERSONALBYTES]; /* 64 */
  57. };
  58. typedef struct blake2b_param_st BLAKE2B_PARAM;
  59. struct blake2b_ctx_st {
  60. uint64_t h[8];
  61. uint64_t t[2];
  62. uint64_t f[2];
  63. uint8_t buf[BLAKE2B_BLOCKBYTES];
  64. size_t buflen;
  65. size_t outlen;
  66. };
  67. #define BLAKE2B_DIGEST_LENGTH 64
  68. #define BLAKE2S_DIGEST_LENGTH 32
  69. typedef struct blake2s_ctx_st BLAKE2S_CTX;
  70. typedef struct blake2b_ctx_st BLAKE2B_CTX;
  71. int ossl_blake2s256_init(void *ctx);
  72. int ossl_blake2b512_init(void *ctx);
  73. int ossl_blake2b_init(BLAKE2B_CTX *c, const BLAKE2B_PARAM *P);
  74. int ossl_blake2b_init_key(BLAKE2B_CTX *c, const BLAKE2B_PARAM *P,
  75. const void *key);
  76. int ossl_blake2b_update(BLAKE2B_CTX *c, const void *data, size_t datalen);
  77. int ossl_blake2b_final(unsigned char *md, BLAKE2B_CTX *c);
  78. /*
  79. * These setters are internal and do not check the validity of their parameters.
  80. * See blake2b_mac_ctrl for validation logic.
  81. */
  82. void ossl_blake2b_param_init(BLAKE2B_PARAM *P);
  83. void ossl_blake2b_param_set_digest_length(BLAKE2B_PARAM *P, uint8_t outlen);
  84. void ossl_blake2b_param_set_key_length(BLAKE2B_PARAM *P, uint8_t keylen);
  85. void ossl_blake2b_param_set_personal(BLAKE2B_PARAM *P, const uint8_t *personal,
  86. size_t length);
  87. void ossl_blake2b_param_set_salt(BLAKE2B_PARAM *P, const uint8_t *salt,
  88. size_t length);
  89. int ossl_blake2s_init(BLAKE2S_CTX *c, const BLAKE2S_PARAM *P);
  90. int ossl_blake2s_init_key(BLAKE2S_CTX *c, const BLAKE2S_PARAM *P,
  91. const void *key);
  92. int ossl_blake2s_update(BLAKE2S_CTX *c, const void *data, size_t datalen);
  93. int ossl_blake2s_final(unsigned char *md, BLAKE2S_CTX *c);
  94. void ossl_blake2s_param_init(BLAKE2S_PARAM *P);
  95. void ossl_blake2s_param_set_digest_length(BLAKE2S_PARAM *P, uint8_t outlen);
  96. void ossl_blake2s_param_set_key_length(BLAKE2S_PARAM *P, uint8_t keylen);
  97. void ossl_blake2s_param_set_personal(BLAKE2S_PARAM *P, const uint8_t *personal,
  98. size_t length);
  99. void ossl_blake2s_param_set_salt(BLAKE2S_PARAM *P, const uint8_t *salt,
  100. size_t length);
  101. #endif /* OSSL_PROV_BLAKE2_H */