Rocksolid Light

Welcome to RetroBBS

mail  files  register  newsreader  groups  login

Message-ID:  

"We came. We saw. We kicked its ass." -- Bill Murray, _Ghostbusters_


devel / comp.lang.ada / Re: GNAT.SHA256 produces result different from sha257sum on Linux

SubjectAuthor
* GNAT.SHA256 produces result different from sha257sum on Linuxwvxvw
`* Re: GNAT.SHA256 produces result different from sha257sum on LinuxJeffrey R.Carter
 +* Re: GNAT.SHA256 produces result different from sha257sum on Linuxwvxvw
 |`* Re: GNAT.SHA256 produces result different from sha257sum on LinuxBen Bacarisse
 | `- Re: GNAT.SHA256 produces result different from sha257sum on Linuxwvxvw
 `* Re: GNAT.SHA256 produces result different from sha257sum on LinuxNiklas Holsti
  `- Re: GNAT.SHA256 produces result different from sha257sum on LinuxJeffrey R.Carter

1
GNAT.SHA256 produces result different from sha257sum on Linux

<87bkc9h9au.fsf@gmail.com>

  copy mid

https://www.rocksolidbbs.com/devel/article-flat.php?id=10247&group=comp.lang.ada#10247

  copy link   Newsgroups: comp.lang.ada
Path: i2pn2.org!i2pn.org!news.hispagatos.org!eternal-september.org!feeder2.eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: olegsivokon@gmail.com (wvxvw)
Newsgroups: comp.lang.ada
Subject: GNAT.SHA256 produces result different from sha257sum on Linux
Date: Sat, 04 Nov 2023 15:39:37 +0100
Organization: A noiseless patient Spider
Lines: 42
Message-ID: <87bkc9h9au.fsf@gmail.com>
MIME-Version: 1.0
Content-Type: text/plain; charset=utf-8
Content-Transfer-Encoding: 8bit
Injection-Info: dont-email.me; posting-host="d272cbac82ad59a2f68bf01ec9dc5e6d";
logging-data="3584007"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1+gqadqOSOw4fk4E7DtjsGu"
User-Agent: Gnus/5.13 (Gnus v5.13)
Cancel-Lock: sha1:HJbDqgiKIhwM8XPbTb8z5/vP0oo=
sha1:+bFPo8uvp52c3Ms4aBX/XpjSTpc=
 by: wvxvw - Sat, 4 Nov 2023 14:39 UTC

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
2c26b46b68ffc68ff99b453c1d30413413422d706483bfa0f98a5e886266e7ae
❯ 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
loop
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)?

Thanks!

Re: GNAT.SHA256 produces result different from sha257sum on Linux

<ui5ms6$3d0f4$1@dont-email.me>

  copy mid

https://www.rocksolidbbs.com/devel/article-flat.php?id=10248&group=comp.lang.ada#10248

  copy link   Newsgroups: comp.lang.ada
Path: i2pn2.org!i2pn.org!news.hispagatos.org!eternal-september.org!feeder2.eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: spam.jrcarter.not@spam.acm.org.not (Jeffrey R.Carter)
Newsgroups: comp.lang.ada
Subject: Re: GNAT.SHA256 produces result different from sha257sum on Linux
Date: Sat, 4 Nov 2023 16:09:58 +0100
Organization: A noiseless patient Spider
Lines: 20
Message-ID: <ui5ms6$3d0f4$1@dont-email.me>
References: <87bkc9h9au.fsf@gmail.com>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 8bit
Injection-Date: Sat, 4 Nov 2023 15:09:58 -0000 (UTC)
Injection-Info: dont-email.me; posting-host="f17349dfb81b20de3803c6a532a5ed26";
logging-data="3572196"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX19lUeO9qGEjqQb7ZUn9ZMb9ZjFVJXrfp0s="
User-Agent: Mozilla Thunderbird
Cancel-Lock: sha1:Cu8iuwx9bJRdq+tLQhI6gtC9jsM=
Content-Language: en-US
In-Reply-To: <87bkc9h9au.fsf@gmail.com>
 by: Jeffrey R.Carter - Sat, 4 Nov 2023 15:09 UTC

On 2023-11-04 15:39, wvxvw wrote:
>
> ❯ ./bin/test_sha --arg foo
> 2c26b46b68ffc68ff99b453c1d30413413422d706483bfa0f98a5e886266e7ae
> ❯ echo foo | sha256sum -
> b5bb9d8014a0f9b1d61e21e796d78dccdf1352f23cd32812f4850b878ae4944c -

I think the problem may be that echo adds an LF:

$ echo foo | hd
00000000 66 6f 6f 0a |foo.|

Since sha256sum expects to work on arbitrary files, it would include the LF in
its input.

--
Jeff Carter
"You can never forget too much about C++."
115

Re: GNAT.SHA256 produces result different from sha257sum on Linux

<877cmxh3cs.fsf@gmail.com>

  copy mid

https://www.rocksolidbbs.com/devel/article-flat.php?id=10249&group=comp.lang.ada#10249

  copy link   Newsgroups: comp.lang.ada
Path: i2pn2.org!i2pn.org!news.hispagatos.org!eternal-september.org!feeder2.eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: olegsivokon@gmail.com (wvxvw)
Newsgroups: comp.lang.ada
Subject: Re: GNAT.SHA256 produces result different from sha257sum on Linux
Date: Sat, 04 Nov 2023 17:48:03 +0100
Organization: A noiseless patient Spider
Lines: 13
Message-ID: <877cmxh3cs.fsf@gmail.com>
References: <87bkc9h9au.fsf@gmail.com> <ui5ms6$3d0f4$1@dont-email.me>
MIME-Version: 1.0
Content-Type: text/plain
Injection-Info: dont-email.me; posting-host="d272cbac82ad59a2f68bf01ec9dc5e6d";
logging-data="3627524"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX19EBmQJ2emxX2+NcvjYQrzQ"
User-Agent: Gnus/5.13 (Gnus v5.13)
Cancel-Lock: sha1:dl7hTi3+2lHmEhsdDbe7PRyrSLg=
sha1:BxpWLBocz5oAxLbg8r3kl5FgEGs=
 by: wvxvw - Sat, 4 Nov 2023 16:48 UTC

"Jeffrey R.Carter" <spam.jrcarter.not@spam.acm.org.not> writes:

> I think the problem may be that echo adds an LF:
>
> $ echo foo | hd
> 00000000 66 6f 6f 0a |foo.|
>
> Since sha256sum expects to work on arbitrary files, it would include
> the LF in its input.

Hi, thanks for the idea, but no, that's not it. With the line end added
I get 04e1806fda6bdbc9e5e3534edd993c7c2bf03173f5489742db53d1e8b0ef8c61
from Ada.

Re: GNAT.SHA256 produces result different from sha257sum on Linux

<kqnb1mFnvc6U1@mid.individual.net>

  copy mid

https://www.rocksolidbbs.com/devel/article-flat.php?id=10250&group=comp.lang.ada#10250

  copy link   Newsgroups: comp.lang.ada
Path: i2pn2.org!i2pn.org!news.swapon.de!fu-berlin.de!uni-berlin.de!individual.net!not-for-mail
From: niklas.holsti@tidorum.invalid (Niklas Holsti)
Newsgroups: comp.lang.ada
Subject: Re: GNAT.SHA256 produces result different from sha257sum on Linux
Date: Sat, 4 Nov 2023 18:49:58 +0200
Organization: Tidorum Ltd
Lines: 21
Message-ID: <kqnb1mFnvc6U1@mid.individual.net>
References: <87bkc9h9au.fsf@gmail.com> <ui5ms6$3d0f4$1@dont-email.me>
Mime-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 8bit
X-Trace: individual.net mglADFlhDgVCXshnP5Jq1gnfUwSehitq4TBfnFj3eU15q5ZLYo
Cancel-Lock: sha1:sY+Gt4u2HfG5ypI8w6A6oHGzLxM= sha256:a1UoL3jmMpvYuY/r96SMkaQW9slJoJ1rZWAKQGSS4H8=
User-Agent: Mozilla Thunderbird
Content-Language: en-US
In-Reply-To: <ui5ms6$3d0f4$1@dont-email.me>
 by: Niklas Holsti - Sat, 4 Nov 2023 16:49 UTC

On 2023-11-04 17:09, Jeffrey R.Carter wrote:
> On 2023-11-04 15:39, wvxvw wrote:
>>
>> ❯ ./bin/test_sha --arg foo
>> 2c26b46b68ffc68ff99b453c1d30413413422d706483bfa0f98a5e886266e7ae
>> ❯ echo foo | sha256sum -
>> b5bb9d8014a0f9b1d61e21e796d78dccdf1352f23cd32812f4850b878ae4944c  -
>
> I think the problem may be that echo adds an LF:
>
> $ echo foo | hd
> 00000000  66 6f 6f 0a                                       |foo.|
>
> Since sha256sum expects to work on arbitrary files, it would include the
> LF in its input.

Some implementations of "echo" accept an option "-n" to suppress the
trailing newline (LF). The OP could try that option as a quick check of
this answer (which seems very plausible).

Re: GNAT.SHA256 produces result different from sha257sum on Linux

<ui5vl7$3d0f4$2@dont-email.me>

  copy mid

https://www.rocksolidbbs.com/devel/article-flat.php?id=10251&group=comp.lang.ada#10251

  copy link   Newsgroups: comp.lang.ada
Path: i2pn2.org!i2pn.org!news.hispagatos.org!eternal-september.org!feeder2.eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: spam.jrcarter.not@spam.acm.org.not (Jeffrey R.Carter)
Newsgroups: comp.lang.ada
Subject: Re: GNAT.SHA256 produces result different from sha257sum on Linux
Date: Sat, 4 Nov 2023 18:39:51 +0100
Organization: A noiseless patient Spider
Lines: 40
Message-ID: <ui5vl7$3d0f4$2@dont-email.me>
References: <87bkc9h9au.fsf@gmail.com> <ui5ms6$3d0f4$1@dont-email.me>
<kqnb1mFnvc6U1@mid.individual.net>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 8bit
Injection-Date: Sat, 4 Nov 2023 17:39:51 -0000 (UTC)
Injection-Info: dont-email.me; posting-host="f17349dfb81b20de3803c6a532a5ed26";
logging-data="3572196"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX192FZxXWX8WVCp9r/KjE7A8IRXRpluS+OU="
User-Agent: Mozilla Thunderbird
Cancel-Lock: sha1:ge2GXh8iZKqpGZubRuHOnSxc3Ik=
Content-Language: en-US
In-Reply-To: <kqnb1mFnvc6U1@mid.individual.net>
 by: Jeffrey R.Carter - Sat, 4 Nov 2023 17:39 UTC

> On 2023-11-04 17:09, Jeffrey R.Carter wrote:
>> On 2023-11-04 15:39, wvxvw wrote:
>>>
>>> ❯ ./bin/test_sha --arg foo
>>> 2c26b46b68ffc68ff99b453c1d30413413422d706483bfa0f98a5e886266e7ae
>>> ❯ echo foo | sha256sum -
>>> b5bb9d8014a0f9b1d61e21e796d78dccdf1352f23cd32812f4850b878ae4944c  -
>>
>> I think the problem may be that echo adds an LF:
>>
>> $ echo foo | hd
>> 00000000  66 6f 6f 0a                                       |foo.|
>>
>> Since sha256sum expects to work on arbitrary files, it would include the LF in
>> its input.

wvxvw wrote:
>
> Hi, thanks for the idea, but no, that's not it. With the line end added
> I get 04e1806fda6bdbc9e5e3534edd993c7c2bf03173f5489742db53d1e8b0ef8c61
> from Ada.

On 2023-11-04 17:49, Niklas Holsti wrote:
>
> Some implementations of "echo" accept an option "-n" to suppress the trailing
> newline (LF). The OP could try that option as a quick check of this answer
> (which seems very plausible).

$ echo -n foo | hd
00000000 66 6f 6f |foo|
$ echo -n foo | sha256sum -
2c26b46b68ffc68ff99b453c1d30413413422d706483bfa0f98a5e886266e7ae -

Interesting results.

--
Jeff Carter
"You can never forget too much about C++."
115

Re: GNAT.SHA256 produces result different from sha257sum on Linux

<87bkc9mmld.fsf@bsb.me.uk>

  copy mid

https://www.rocksolidbbs.com/devel/article-flat.php?id=10252&group=comp.lang.ada#10252

  copy link   Newsgroups: comp.lang.ada
Path: i2pn2.org!i2pn.org!news.hispagatos.org!eternal-september.org!feeder2.eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: ben.usenet@bsb.me.uk (Ben Bacarisse)
Newsgroups: comp.lang.ada
Subject: Re: GNAT.SHA256 produces result different from sha257sum on Linux
Date: Sat, 04 Nov 2023 17:53:34 +0000
Organization: A noiseless patient Spider
Lines: 43
Message-ID: <87bkc9mmld.fsf@bsb.me.uk>
References: <87bkc9h9au.fsf@gmail.com> <ui5ms6$3d0f4$1@dont-email.me>
<877cmxh3cs.fsf@gmail.com>
MIME-Version: 1.0
Content-Type: text/plain; charset=utf-8
Content-Transfer-Encoding: 8bit
Injection-Info: dont-email.me; posting-host="8ef8456b775bd62642107cf5437b1a77";
logging-data="3655288"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX19WaeRiW9W5Fwz615O+wzTg0AE7N08XQwA="
User-Agent: Gnus/5.13 (Gnus v5.13)
Cancel-Lock: sha1:AKQmA43cFLMVvttYMg0f5MWo+B4=
sha1:yTK9SOcOtoXdHvIlEf/21Hk5Dfw=
X-BSB-Auth: 1.e53430e674c9af45c5d1.20231104175334GMT.87bkc9mmld.fsf@bsb.me.uk
 by: Ben Bacarisse - Sat, 4 Nov 2023 17:53 UTC

wvxvw <olegsivokon@gmail.com> writes:

> "Jeffrey R.Carter" <spam.jrcarter.not@spam.acm.org.not> writes:
>
>> I think the problem may be that echo adds an LF:
>>
>> $ echo foo | hd
>> 00000000 66 6f 6f 0a |foo.|
>>
>> Since sha256sum expects to work on arbitrary files, it would include
>> the LF in its input.
>
> Hi, thanks for the idea, but no, that's not it.

You say that's not it, but with the newline removed, sha256sum gives the
same hash as your original test code:

$ printf foo | sha256sum -
2c26b46b68ffc68ff99b453c1d30413413422d706483bfa0f98a5e886266e7ae -

From your earlier post:
> Eg, with GNAT.SHA256 for string "foo" I get:
>
> ❯ ./bin/test_sha --arg foo
> 2c26b46b68ffc68ff99b453c1d30413413422d706483bfa0f98a5e886266e7ae

> With the line end added
> I get 04e1806fda6bdbc9e5e3534edd993c7c2bf03173f5489742db53d1e8b0ef8c61
> from Ada.

Ah! You didn't add a newline! I can get the same hash by guesswork:

$ printf foo\\\\n >input
$ sha256sum input
04e1806fda6bdbc9e5e3534edd993c7c2bf03173f5489742db53d1e8b0ef8c61 input
$ hd input
00000000 66 6f 6f 5c 6e |foo\n|
00000005

What you added to the test string was a backslash and a letter n.

--
Ben.

Re: GNAT.SHA256 produces result different from sha257sum on Linux

<8734xlgw0l.fsf@gmail.com>

  copy mid

https://www.rocksolidbbs.com/devel/article-flat.php?id=10253&group=comp.lang.ada#10253

  copy link   Newsgroups: comp.lang.ada
Path: i2pn2.org!i2pn.org!news.hispagatos.org!eternal-september.org!feeder2.eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: olegsivokon@gmail.com (wvxvw)
Newsgroups: comp.lang.ada
Subject: Re: GNAT.SHA256 produces result different from sha257sum on Linux
Date: Sat, 04 Nov 2023 20:26:34 +0100
Organization: A noiseless patient Spider
Lines: 22
Message-ID: <8734xlgw0l.fsf@gmail.com>
References: <87bkc9h9au.fsf@gmail.com> <ui5ms6$3d0f4$1@dont-email.me>
<877cmxh3cs.fsf@gmail.com> <87bkc9mmld.fsf@bsb.me.uk>
MIME-Version: 1.0
Content-Type: text/plain
Injection-Info: dont-email.me; posting-host="d272cbac82ad59a2f68bf01ec9dc5e6d";
logging-data="3706884"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX18lfjFWxR+ScwvwG1IbUaG0"
User-Agent: Gnus/5.13 (Gnus v5.13)
Cancel-Lock: sha1:FheHSADzU8FbHUUzbUcvLvSAATg=
sha1:rfweWZMGYzWuP0l6jBnkkkVXGqw=
 by: wvxvw - Sat, 4 Nov 2023 19:26 UTC

Ben Bacarisse <ben.usenet@bsb.me.uk> writes:

> Ah! You didn't add a newline! I can get the same hash by guesswork:
>
> $ printf foo\\\\n >input
> $ sha256sum input
> 04e1806fda6bdbc9e5e3534edd993c7c2bf03173f5489742db53d1e8b0ef8c61 input
> $ hd input
> 00000000 66 6f 6f 5c 6e |foo\n|
> 00000005
>
> What you added to the test string was a backslash and a letter n.

Yeah, thanks! I realized this too by trying to do this in Python:

>>> import hashlib
>>> hashlib.sha256('foo'.encode()).hexdigest()
'2c26b46b68ffc68ff99b453c1d30413413422d706483bfa0f98a5e886266e7ae'
>>> hashlib.sha256('foo\n'.encode()).hexdigest()
'b5bb9d8014a0f9b1d61e21e796d78dccdf1352f23cd32812f4850b878ae4944c'

Thanks again.

1
server_pubkey.txt

rocksolid light 0.9.8
clearnet tor