From mboxrd@z Thu Jan 1 00:00:00 1970 Path: eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail From: 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 Message-ID: <87bkc9mmld.fsf@bsb.me.uk> References: <87bkc9h9au.fsf@gmail.com> <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 Xref: news.eternal-september.org comp.lang.ada:65841 List-Id: wvxvw writes: > "Jeffrey R.Carter" 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.