Boost logo

Boost :

Subject: Re: [boost] Message Hashing Interface (SHA-1/256/384/512, MD4/5)
From: Scott McMurray (me22.ca+boost_at_[hidden])
Date: 2010-04-06 12:55:44


On 6 April 2010 10:55, Rob Riggs <rob_at_[hidden]> wrote:
>
> This is also the scheme used by crypto++ (C++), the Perl API, PyCrypto
> (Python) and openssl (C).  I think the Boost crypto hash API should more
> closely mimic the existing de facto standard interfaces as much as possible.
>

Thanks for the references. They're not completely consistent, though.

>From Python: "digest(): Return the hash value of this hashing object,
as a string containing 8-bit data. The object is not altered in any
way by this function; you can continue updating the object after
calling this function."

>From Java6: "The digest method can be called once for a given number
of updates. After digest has been called, the MessageDigest object is
reset to its initialized state."

I do like the idea that digest() be const, since conceptually it's
just inspecting the result of the previous updates.

Here's a hybrid idea, with definitions to show equivalences:

class hash {
  public:
    void update(byte);
    void reset() { *this = hash(); }
    digest_type digest() const {
        return hash(*this).end_of_message();
    }
    digest_type end_message() {
        digest_type h = digest();
        reset();
        return h;
    }
};

That way it provides for rolling or message-oriented digests, and
adapts for the other as best it can if needed.

Is that a reasonable compromise?

~ Scott

P.S. Interestingly, with 64-bit processors, SHA-512 is faster for me
than SHA-1.


Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk