News for hackers. Stuff that matters.
Re:What Is the Randomart Image For? by coldpie on Tuesday February 21, 2023 @11:34AM (#34883107)
It is a bit of effort, but you can make the computer do the verification for you by writing (or generating) a simple text file. Using Perl shasum because I'm on a mac at the moment, but Linux sha256sum works the same:

    $ echo hi > some_file
    $ shasum -a 256 some_file > check
    $ cat check
    98ea6e4f216f2fb4b69fff9b3a44842c38686ca685f3f55dc48c5d3fb1107be4  some_file
    $ shasum -a 256 -c check
    some_file: OK
    $ echo $?
    0
    $ echo bye > some_file
    $ shasum -a 256 -c check
    some_file: FAILED
    shasum: WARNING: 1 computed checksum did NOT match
    $ echo $?
    1
Re:What Is the Randomart Image For? by johnmaguire on Tuesday February 21, 2023 @11:50AM (#34883366)
Something like this also works:

    hash="4e575a5ee4af2925477c9eea887ff560d23a586dbaf90b616d26c47ec429ca13"
    [[ "$hash" == "$(shasum -a 256 file | awk '{print $1 }')" ]] && echo "Valid" || echo "Invalid checksum"
I use that little if-statement in some build systems.
Re:What Is the Randomart Image For? by coldpie on Tuesday February 21, 2023 @11:56AM (#34883424)
See my edit, apparently shasum's -c can read from stdin so you could simplify your scriptlet even further :)
Re:What Is the Randomart Image For? by lozf on Wednesday February 22, 2023 @06:55AM (#34894349)
Indeed,

      echo '98ea6e4f216f2fb4b69fff9b3a44842c38686ca685f3f55dc48c5d3fb1107be4  some_file' | sha256sum -c   
also works (with and without passing `-n` to echo, because the `-c` option ensures the file is checked without even noticing any new line). Thanks :)
Re:What Is the Randomart Image For? by jpdaigle on Tuesday February 21, 2023 @05:14PM (#34888371)
Any hash calculations using a "read from stdin or a pipe" strategy, in my experience, is fraught with issues caused by an extra newline at the end of the input possibly being there today, and not in later checks, or vice-versa.

When people claim they wrote a prediction at some later date, they always have to document the EXACT command used to avoid this, e.g. `echo "smart prediction" | md5sum`

Re:What Is the Randomart Image For? by coldpie on Wednesday February 22, 2023 @08:40AM (#34895253)
Sure. The case in question is verifying a hash someone else gave you, so the problem you mention is present regardless of what verification method you're using.