The JUCE cross-platform C++ framework, with DISTRHO/KXStudio specific changes
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

114 lines
3.9KB

  1. /*
  2. ==============================================================================
  3. This file is part of the JUCE library.
  4. Copyright (c) 2015 - ROLI Ltd.
  5. Permission is granted to use this software under the terms of either:
  6. a) the GPL v2 (or any later version)
  7. b) the Affero GPL v3
  8. Details of these licenses can be found at: www.gnu.org/licenses
  9. JUCE is distributed in the hope that it will be useful, but WITHOUT ANY
  10. WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
  11. A PARTICULAR PURPOSE. See the GNU General Public License for more details.
  12. ------------------------------------------------------------------------------
  13. To release a closed-source product which uses JUCE, commercial licenses are
  14. available: visit www.juce.com for more information.
  15. ==============================================================================
  16. */
  17. #ifndef JUCE_WHIRLPOOL_H_INCLUDED
  18. #define JUCE_WHIRLPOOL_H_INCLUDED
  19. //==============================================================================
  20. /**
  21. Whirlpool hash class.
  22. The Whirlpool algorithm was developed by
  23. <a href="mailto:pbarreto@scopus.com.br">Paulo S. L. M. Barreto</a> and
  24. <a href="mailto:vincent.rijmen@cryptomathic.com">Vincent Rijmen</a>.
  25. See
  26. P.S.L.M. Barreto, V. Rijmen,
  27. "The Whirlpool hashing function"
  28. NESSIE submission, 2000 (tweaked version, 2001),
  29. https://www.cosic.esat.kuleuven.ac.be/nessie/workshop/submissions/whirlpool.zip
  30. @see SHA256, MD5
  31. */
  32. class JUCE_API Whirlpool
  33. {
  34. public:
  35. //==============================================================================
  36. /** Creates an empty Whirlpool object.
  37. The default constructor just creates a hash filled with zeros. (This is not
  38. equal to the hash of an empty block of data).
  39. */
  40. Whirlpool() noexcept;
  41. /** Destructor. */
  42. ~Whirlpool() noexcept;
  43. /** Creates a copy of another Whirlpool. */
  44. Whirlpool (const Whirlpool& other) noexcept;
  45. /** Copies another Whirlpool. */
  46. Whirlpool& operator= (const Whirlpool& other) noexcept;
  47. //==============================================================================
  48. /** Creates a hash from a block of raw data. */
  49. explicit Whirlpool (const MemoryBlock&);
  50. /** Creates a hash from a block of raw data. */
  51. Whirlpool (const void* data, size_t numBytes);
  52. /** Creates a hash from the contents of a stream.
  53. This will read from the stream until the stream is exhausted, or until
  54. maxBytesToRead bytes have been read. If maxBytesToRead is negative, the entire
  55. stream will be read.
  56. */
  57. Whirlpool (InputStream& input, int64 maxBytesToRead = -1);
  58. /** Reads a file and generates the hash of its contents.
  59. If the file can't be opened, the hash will be left uninitialised
  60. (i.e. full of zeros).
  61. */
  62. explicit Whirlpool (const File& file);
  63. /** Creates a checksum from a UTF-8 buffer.
  64. E.g.
  65. @code Whirlpool checksum (myString.toUTF8());
  66. @endcode
  67. */
  68. explicit Whirlpool (CharPointer_UTF8 utf8Text) noexcept;
  69. //==============================================================================
  70. /** Returns the hash as a 64-byte block of data. */
  71. MemoryBlock getRawData() const;
  72. /** Returns the checksum as a 128-digit hex string. */
  73. String toHexString() const;
  74. //==============================================================================
  75. bool operator== (const Whirlpool&) const noexcept;
  76. bool operator!= (const Whirlpool&) const noexcept;
  77. private:
  78. //==============================================================================
  79. uint8 result [64];
  80. void process (const void*, size_t);
  81. JUCE_LEAK_DETECTOR (Whirlpool)
  82. };
  83. #endif // JUCE_WHIRLPOOL_H_INCLUDED