help / color / mirror / Atom feed
From: wvxvw <>
Subject: GNAT.SHA256 produces result different from sha257sum on Linux
Date: Sat, 04 Nov 2023 15:39:37 +0100	[thread overview]
Message-ID: <> (raw)

Hello. (Sorry for duplication, the first attempt to send this sent it as
a response to an unrelated thread).

I'm learning Ada as well as how to use Usenet, so don't be too harsh.
As a learning exercise, I want to write a program that, beside other
things, needs to compute SHA256 hashes.  I discovered GNAT.SHA256
library and was able to use it (by calling Digest(<some string>)),
however the result is different from what I'd get for the same string
with running sha256sum.

Eg, with GNAT.SHA256 for string "foo" I get:

❯ ./bin/test_sha --arg foo
❯ echo foo | sha256sum -
b5bb9d8014a0f9b1d61e21e796d78dccdf1352f23cd32812f4850b878ae4944c  -

My Ada code looks (with some unrelated stuff removed) like this:

with GNAT.Command_Line;   use GNAT.Command_Line;
with GNAT.SHA256;         use GNAT.SHA256;

procedure Main is
      case Getopt ("-arg=") is
         when '-' =>
            if Full_Switch = "-arg" then
               Put_Line (Digest (Parameter));
            end if;
      end case;
   end loop;
end Main;

My understanding is that there are plenty of configuration settings to
how the checksum is computed, but I know very little about it.  My goal
is to produce the same checksum as would be produced by sha256sum
though, as the checksums are to be used outside of my program.

Finally: is GNAT.SHA256 a good way to go if I need this functionality (I
don't care about portability, if that's a concern)?


             reply	other threads:[~2023-11-04 14:39 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-11-04 14:39 wvxvw [this message]
2023-11-04 15:09 ` GNAT.SHA256 produces result different from sha257sum on Linux Jeffrey R.Carter
2023-11-04 16:48   ` wvxvw
2023-11-04 17:53     ` Ben Bacarisse
2023-11-04 19:26       ` wvxvw
2023-11-04 16:49   ` Niklas Holsti
2023-11-04 17:39     ` Jeffrey R.Carter
replies disabled

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox