Feature request : Whirlpool hash algorithm


#1

Hello Jules ;)

We all need a JUCE implementation of the famous Whirlpool hash algorithm ! For protection stuff, it's an algorithm very useful, that lots of people use, instead of SHA256 (because it's 512 bits instead of 256) or MDA5 (because it's a very bad one) which are implemented yet in JUCE.

Do some people here from the forum would be interested by this ?

It is possible that Jules has received a few weeks ago something that would help him a lot to answer to this feature request :)

Thanks in advance !


#2

Ah! Sorry, I had that almost ready-to-go and forgot about it! Will post it asap..


#3

Thanks Jules ;)


#4

Yep thanks! BTW: The added class gives some (easy to fix) warnings in Visual Studio Community 2013:

1>c:\juce\modules\juce_cryptography\hashing\juce_whirlpool.cpp(178): warning C4245: 'initializing' : conversion from '__int64' to 'const juce::uint64', signed/unsigned mismatch (..\..\..\..\modules\juce_cryptography\juce_cryptography.cpp)


#5

Ta, will fix that.


#6

Hello again Jules !

I just want to share a possible modification of the class HashesComponent in the JUCE demo project :)

class HashesComponent  : public Component,
                         private TextEditor::Listener
{
public:
    HashesComponent()
    {
        addAndMakeVisible (hashGroup);
        hashGroup.setText ("Hashes");
        hashGroup.setColour (GroupComponent::outlineColourId, Colours::grey);
        hashGroup.setColour (GroupComponent::textColourId, Colours::white);

        addAndMakeVisible (hashEntryBox);
        hashEntryBox.setMultiLine (true);
        hashEntryBox.setColour (TextEditor::backgroundColourId, Colours::white.withAlpha (0.5f));

        hashEntryBox.setReturnKeyStartsNewLine (true);
        hashEntryBox.setText ("Type some text in this box and the resulting MD5, SHA and Whirlpool hashes will update below");
        hashEntryBox.addListener (this);

        hashLabel1.setText ("Text to Hash:", dontSendNotification);
        hashLabel2.setText ("MD5 Result:", dontSendNotification);
        hashLabel3.setText ("SHA Result:", dontSendNotification);
        hashLabel4.setText ("Whirlpool Result:", dontSendNotification);

        hashLabel1.attachToComponent (&hashEntryBox, true);
        hashLabel2.attachToComponent (&md5Result, true);
        hashLabel3.attachToComponent (&shaResult, true);
        hashLabel4.attachToComponent (&whirlpoolResult, true);

        addAndMakeVisible (md5Result);
        addAndMakeVisible (shaResult);
        addAndMakeVisible (whirlpoolResult);

        updateHashes();
    }

    void updateHashes()
    {
        updateMD5Result();
        updateSHA256Result();
        updateWhirlpoolResult();
    }

    void updateMD5Result()
    {
        const MD5 md5 (hashEntryBox.getText().toUTF8());

        md5Result.setText (md5.toHexString(), dontSendNotification);
    }

    void updateSHA256Result()
    {
        const SHA256 sha (hashEntryBox.getText().toUTF8());

        shaResult.setText (sha.toHexString(), dontSendNotification);
    }

    void updateWhirlpoolResult()
    {
        const Whirlpool whirlpool(hashEntryBox.getText().toUTF8());

        whirlpoolResult.setText(whirlpool.toHexString(), dontSendNotification);
    }

    void resized() override
    {
        Rectangle<int> area (getLocalBounds());
        hashGroup.setBounds (area);
        area.removeFromLeft (100);
        area.removeFromTop (10);
        area.reduce (5, 5);
        whirlpoolResult.setBounds(area.removeFromBottom(51).reduced(5));
        shaResult.setBounds (area.removeFromBottom (34).reduced (5));
        md5Result.setBounds (area.removeFromBottom (34).reduced (5));
        hashEntryBox.setBounds (area.reduced (5));
    }

private:
    GroupComponent hashGroup;
    TextEditor hashEntryBox;
    Label md5Result, shaResult, whirlpoolResult;
    Label hashLabel1, hashLabel2, hashLabel3, hashLabel4;

    void textEditorTextChanged (TextEditor& editor) override
    {
        if (&editor == &hashEntryBox)
            updateHashes();
    }

    void textEditorReturnKeyPressed (TextEditor& editor) override
    {
        if (&editor == &hashEntryBox)
            updateHashes();
    }

    void textEditorEscapeKeyPressed (TextEditor& editor) override
    {
        if (&editor == &hashEntryBox)
            updateHashes();
    }

    void textEditorFocusLost (TextEditor& editor) override
    {
        if (&editor == &hashEntryBox)
            updateHashes();
    }

    JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (HashesComponent)
};

 


#7

Cheers Ivan, will add that!