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.

112 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. #pragma once
  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. */
  33. class JUCE_API Whirlpool
  34. {
  35. public:
  36. //==============================================================================
  37. /** Creates an empty Whirlpool object.
  38. The default constructor just creates a hash filled with zeros. (This is not
  39. equal to the hash of an empty block of data).
  40. */
  41. Whirlpool() noexcept;
  42. /** Destructor. */
  43. ~Whirlpool() noexcept;
  44. /** Creates a copy of another Whirlpool. */
  45. Whirlpool (const Whirlpool& other) noexcept;
  46. /** Copies another Whirlpool. */
  47. Whirlpool& operator= (const Whirlpool& other) noexcept;
  48. //==============================================================================
  49. /** Creates a hash from a block of raw data. */
  50. explicit Whirlpool (const MemoryBlock&);
  51. /** Creates a hash from a block of raw data. */
  52. Whirlpool (const void* data, size_t numBytes);
  53. /** Creates a hash from the contents of a stream.
  54. This will read from the stream until the stream is exhausted, or until
  55. maxBytesToRead bytes have been read. If maxBytesToRead is negative, the entire
  56. stream will be read.
  57. */
  58. Whirlpool (InputStream& input, int64 maxBytesToRead = -1);
  59. /** Reads a file and generates the hash of its contents.
  60. If the file can't be opened, the hash will be left uninitialised
  61. (i.e. full of zeros).
  62. */
  63. explicit Whirlpool (const File& file);
  64. /** Creates a checksum from a UTF-8 buffer.
  65. E.g.
  66. @code Whirlpool checksum (myString.toUTF8());
  67. @endcode
  68. */
  69. explicit Whirlpool (CharPointer_UTF8 utf8Text) noexcept;
  70. //==============================================================================
  71. /** Returns the hash as a 64-byte block of data. */
  72. MemoryBlock getRawData() const;
  73. /** Returns the checksum as a 128-digit hex string. */
  74. String toHexString() const;
  75. //==============================================================================
  76. bool operator== (const Whirlpool&) const noexcept;
  77. bool operator!= (const Whirlpool&) const noexcept;
  78. private:
  79. //==============================================================================
  80. uint8 result [64];
  81. void process (const void*, size_t);
  82. JUCE_LEAK_DETECTOR (Whirlpool)
  83. };