[botan-devel] How to compute running hash value?

William K. Foster wkf at alum.mit.edu
Sun Mar 27 19:02:10 EDT 2011


Hello Jack,

This is new code.  I want to keep a running hash to look for corruption in a
stream of data and not have to start over from the beginning if a fail point
is detected, by computing a running value and checking along the way, I only
have to go back to the point of last successful hash when corruption arises.

Thanks.

-William


On Sun, Mar 27, 2011 at 1:44 PM, Jack Lloyd <lloyd at randombit.net> wrote:

>
> The hash objects do not natively support this notion; final() resets
> the state for processing a new message.
>
> This copy trick would probably work. However, do keep in mind that
> this won't necessarily work if the _hash object is not actually an
> instance of the SHA_512 class. For instance, the algorithm factory may
> have actually returned an instance of a class that talks to CryptoAPI
> or some CUDA code or /dev/crypto or PKCS #11 or who knows what. This
> is currently hypothetical for SHA-512, but this may not be the case in
> the future.
>
> Do you need this for compatability with something, or is this new
> code? It kind of sounds like what you really want is some kind of tree
> hashing scheme.
>
> -Jack
>
> On Sat, Mar 26, 2011 at 04:00:03PM -0700, William K. Foster wrote:
> > Hi,
> >
> > I think I have a solution, before wanting to do an interim call to
> final()
> > use the copy constructor to make a new object, then do final() on the
> copy,
> > leaving the original alone to continue computing:
> >
> >   const SHA_512 &myHash = *static_cast<SHA_512 *>(_hash);
> >   SHA_512 tmpHash(myHash);
> >
> >   SecureVector<byte> result1 = tmpHash.final();
> >
> > Let me know if my thinking is flawed.
> >
> > Thanks.
> >
> > -William
> >
> >
> > On Sat, Mar 26, 2011 at 1:45 PM, William K. Foster <wkf at alum.mit.edu>
> wrote:
> >
> > > Hello,
> > >
> > > I have a long stream of data and I would like to periodically have an
> > > interim sha-512 hash value and wonder how to write this correctly.
> > >
> > > Here is what I am thinking but wonder if it works correctly?
> > >
> > >   HashFunction *_hash = Botan::get_hash("SHA-512");
> > >
> > >   _hash->clear();
> > >   _hash->update(message1, msg1Length);
> > >
> > >   SecureVector<byte> result1 = _hash->final();
> > >
> > >   _hash->update(message2, msg2Length);
> > >
> > >   SecureVector<byte> result2 = _hash->final();
> > >
> > >   _hash->update(message3, msg3Length);
> > >
> > >   SecureVector<byte> result3 = _hash->final();
> > >
> > > Will the above result3 be identical to the following computation of
> > > result3:
> > >
> > >   HashFunction *_hash = Botan::get_hash("SHA-512");
> > >
> > >   _hash->clear();
> > >   _hash->update(message1, msg1Length);
> > >
> > >   _hash->update(message2, msg2Length);
> > >
> > >   _hash->update(message3, msg3Length);
> > >
> > >   SecureVector<byte> result3 = _hash->final();
> > >
> > > Or does calling final() multiple times change the result in subsequent
> > > final()s, and if so, is there a way to undo the effect of calling
> final() so
> > > that further update()s may be performed?
> > >
> > > Thanks.
> > >
> > > -William
> > >
>
> > _______________________________________________
> > botan-devel mailing list
> > botan-devel at randombit.net
> > http://lists.randombit.net/mailman/listinfo/botan-devel
>
> _______________________________________________
> botan-devel mailing list
> botan-devel at randombit.net
> http://lists.randombit.net/mailman/listinfo/botan-devel
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.randombit.net/pipermail/botan-devel/attachments/20110327/da1f4405/attachment.html>


More information about the botan-devel mailing list