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

David Bremner david at tethera.net
Sun Nov 24 04:40:13 PST 2013


David Bremner <david at 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;
}


More information about the notmuch mailing list