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.

108 lines
3.5KB

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