Re: notmuch sha1 implementation broken on (some) big-endian architectures

Subject: Re: notmuch sha1 implementation broken on (some) big-endian architectures

Date: Sun, 24 Nov 2013 08:40:13 -0400

To: notmuch@notmuchmail.org

Cc:

From: David Bremner


David Bremner <david@tethera.net> writes:

> The following code, when linked with libnotmuch.a and libutil.a does a
> passable imitation of sha1sum on amd64 (and I guess also i386) but
> computes a different digest on powerpc and probably sparc and s390x.
>
> In the long run we should maybe outsource hash computations to
> e.g. librhash, but I'd like a simpler fix for 0.17, if possible

Out of curiousity, I tried out a similar example with librhash, and it
works fine on powerpc.

#include <errno.h>
#include "rhash.h" /* LibRHash interface */

int main(int argc, char *argv[])
{
  char digest[64];
  char output[130];

  rhash_library_init(); /* initialize static data */

  int res = rhash_file(RHASH_SHA1, argv[1], digest);
  if(res < 0) {
    fprintf(stderr, "LibRHash error: %s: %s\n", argv[1], strerror(errno));
    return 1;
  }

  /* convert binary digest to hexadecimal string */
  rhash_print_bytes(output, digest, rhash_get_digest_size(RHASH_SHA1),RHPR_HEX);

  printf("%s (%s) = %s\n", rhash_get_name(RHASH_SHA1), argv[1], output);
  return 0;
}

Thread: