groestl.h 3.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  1. /* Groestl hash from https://github.com/Groestlcoin/vanitygen
  2. * Trezor adaptation by Yura Pakhuchiy <pakhuchiy@gmail.com>. */
  3. /**
  4. * Groestl interface. This code implements Groestl with the recommended
  5. * parameters for SHA-3, with outputs of 224, 256, 384 and 512 bits.
  6. *
  7. * ==========================(LICENSE BEGIN)============================
  8. *
  9. * Copyright (c) 2007-2010 Projet RNRT SAPHIR
  10. *
  11. * Permission is hereby granted, free of charge, to any person obtaining
  12. * a copy of this software and associated documentation files (the
  13. * "Software"), to deal in the Software without restriction, including
  14. * without limitation the rights to use, copy, modify, merge, publish,
  15. * distribute, sublicense, and/or sell copies of the Software, and to
  16. * permit persons to whom the Software is furnished to do so, subject to
  17. * the following conditions:
  18. *
  19. * The above copyright notice and this permission notice shall be
  20. * included in all copies or substantial portions of the Software.
  21. *
  22. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
  23. * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  24. * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
  25. * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
  26. * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
  27. * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
  28. * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
  29. *
  30. * ===========================(LICENSE END)=============================
  31. *
  32. * @file sph_groestl.h
  33. * @author Thomas Pornin <thomas.pornin@cryptolog.com>
  34. */
  35. #ifndef GROESTL_H__
  36. #define GROESTL_H__
  37. #include <stddef.h>
  38. /**
  39. * This structure is a context for Groestl-384 and Groestl-512 computations:
  40. * it contains the intermediate values and some data from the last
  41. * entered block. Once a Groestl computation has been performed, the
  42. * context can be reused for another computation.
  43. *
  44. * The contents of this structure are private. A running Groestl
  45. * computation can be cloned by copying the context (e.g. with a simple
  46. * <code>memcpy()</code>).
  47. */
  48. typedef struct {
  49. unsigned char buf[128]; /* first field, for alignment */
  50. size_t ptr;
  51. union {
  52. uint64_t wide[16];
  53. uint32_t narrow[32];
  54. } state;
  55. uint64_t count;
  56. } sph_groestl_big_context;
  57. typedef sph_groestl_big_context GROESTL512_CTX;
  58. /**
  59. * Initialize a Groestl-512 context. This process performs no memory allocation.
  60. *
  61. * @param cc the Groestl-512 context (pointer to a
  62. * <code>GROESTL512_CTX</code>)
  63. */
  64. void groestl512_Init(void* cc);
  65. /**
  66. * Process some data bytes. It is acceptable that <code>len</code> is zero
  67. * (in which case this function does nothing).
  68. *
  69. * @param cc the Groestl-512 context
  70. * @param data the input data
  71. * @param len the input data length (in bytes)
  72. */
  73. void groestl512_Update(void* cc, const void* data, size_t len);
  74. /**
  75. * Terminate the current Groestl-512 computation and output the result into
  76. * the provided buffer. The destination buffer must be wide enough to
  77. * accomodate the result (64 bytes). The context is automatically
  78. * reinitialized.
  79. *
  80. * @param cc the Groestl-512 context
  81. * @param dst the destination buffer
  82. */
  83. void groestl512_Final(void* cc, void* dst);
  84. /* Calculate double Groestl-512 hash and truncate it to 256-bits. */
  85. void groestl512_DoubleTrunc(void* cc, void* dst);
  86. #endif