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.

116 lines
3.8KB

  1. /*
  2. ==============================================================================
  3. This file is part of the JUCE library.
  4. Copyright (c) 2017 - ROLI Ltd.
  5. JUCE is an open source library subject to commercial or open-source
  6. licensing.
  7. By using JUCE, you agree to the terms of both the JUCE 5 End-User License
  8. Agreement and JUCE 5 Privacy Policy (both updated and effective as of the
  9. 27th April 2017).
  10. End User License Agreement: www.juce.com/juce-5-licence
  11. Privacy Policy: www.juce.com/juce-5-privacy-policy
  12. Or: You may also use this code under the terms of the GPL v3 (see
  13. www.gnu.org/licenses).
  14. JUCE IS PROVIDED "AS IS" WITHOUT ANY WARRANTY, AND ALL WARRANTIES, WHETHER
  15. EXPRESSED OR IMPLIED, INCLUDING MERCHANTABILITY AND FITNESS FOR PURPOSE, ARE
  16. DISCLAIMED.
  17. ==============================================================================
  18. */
  19. namespace juce
  20. {
  21. //==============================================================================
  22. /**
  23. Whirlpool hash class.
  24. The Whirlpool algorithm was developed by
  25. <a href="mailto:pbarreto@scopus.com.br">Paulo S. L. M. Barreto</a> and
  26. <a href="mailto:vincent.rijmen@cryptomathic.com">Vincent Rijmen</a>.
  27. See
  28. P.S.L.M. Barreto, V. Rijmen,
  29. "The Whirlpool hashing function"
  30. NESSIE submission, 2000 (tweaked version, 2001),
  31. https://www.cosic.esat.kuleuven.ac.be/nessie/workshop/submissions/whirlpool.zip
  32. @see SHA256, MD5
  33. @tags{Cryptography}
  34. */
  35. class JUCE_API Whirlpool
  36. {
  37. public:
  38. //==============================================================================
  39. /** Creates an empty Whirlpool object.
  40. The default constructor just creates a hash filled with zeros. (This is not
  41. equal to the hash of an empty block of data).
  42. */
  43. Whirlpool() noexcept;
  44. /** Destructor. */
  45. ~Whirlpool() noexcept;
  46. /** Creates a copy of another Whirlpool. */
  47. Whirlpool (const Whirlpool& other) noexcept;
  48. /** Copies another Whirlpool. */
  49. Whirlpool& operator= (const Whirlpool& other) noexcept;
  50. //==============================================================================
  51. /** Creates a hash from a block of raw data. */
  52. explicit Whirlpool (const MemoryBlock&);
  53. /** Creates a hash from a block of raw data. */
  54. Whirlpool (const void* data, size_t numBytes);
  55. /** Creates a hash from the contents of a stream.
  56. This will read from the stream until the stream is exhausted, or until
  57. maxBytesToRead bytes have been read. If maxBytesToRead is negative, the entire
  58. stream will be read.
  59. */
  60. Whirlpool (InputStream& input, int64 maxBytesToRead = -1);
  61. /** Reads a file and generates the hash of its contents.
  62. If the file can't be opened, the hash will be left uninitialised
  63. (i.e. full of zeros).
  64. */
  65. explicit Whirlpool (const File& file);
  66. /** Creates a checksum from a UTF-8 buffer.
  67. E.g.
  68. @code Whirlpool checksum (myString.toUTF8());
  69. @endcode
  70. */
  71. explicit Whirlpool (CharPointer_UTF8 utf8Text) noexcept;
  72. //==============================================================================
  73. /** Returns the hash as a 64-byte block of data. */
  74. MemoryBlock getRawData() const;
  75. /** Returns the checksum as a 128-digit hex string. */
  76. String toHexString() const;
  77. //==============================================================================
  78. bool operator== (const Whirlpool&) const noexcept;
  79. bool operator!= (const Whirlpool&) const noexcept;
  80. private:
  81. //==============================================================================
  82. uint8 result [64];
  83. void process (const void*, size_t);
  84. JUCE_LEAK_DETECTOR (Whirlpool)
  85. };
  86. } // namespace juce