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.

115 lines
3.8KB

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