sha256 (and its cousins) have a -c argument to validate against a given checksum. This works fine on files. Example: $ echo test > file $ sha256 file SHA256 (file) = f2ca1bb6c7e907d06dafe4687e579fce76b37e4e93b7605022da52e6ccc26fd2 $ sha256 -c f2ca1bb6c7e907d06dafe4687e579fce76b37e4e93b7605022da52e6ccc26fd2 file; echo $? SHA256 (file) = f2ca1bb6c7e907d06dafe4687e579fce76b37e4e93b7605022da52e6ccc26fd2 0 $ sha256 -c dead1bb6c7e907d06dafe4687e579fce76b37e4e93b7605022da52e6ccc26beef file; echo $? SHA256 (file) = f2ca1bb6c7e907d06dafe4687e579fce76b37e4e93b7605022da52e6ccc26fd2 [ Failed ] 2 However, stdin appears to either be always positive or false positive: $ cat file | sha256 f2ca1bb6c7e907d06dafe4687e579fce76b37e4e93b7605022da52e6ccc26fd2 $ cat file | sha256 -c f2ca1bb6c7e907d06dafe4687e579fce76b37e4e93b7605022da52e6ccc26fd2; echo $? 0 $ cat file | sha256 -c dead1bb6c7e907d06dafe4687e579fce76b37e4e93b7605022da52e6ccc2beef; echo $? 0 I think that sha256 -c should give an error or warning with stdin since it is not handled properly, or preferably function as expected. It would be easy to be misled by the current behavior. Please let me know if you need anything else from me. Thank you!
Thank you for the report Teran
A commit references this bug: Author: allanjude Date: Fri Jun 19 19:16:26 UTC 2020 New revision: 362412 URL: https://svnweb.freebsd.org/changeset/base/362412 Log: md5(1): fix -c flag to work with input on stdin Previously, the -p and -c flags were ignored when reading from stdin Additionally, -s and -c can be used together now. PR: 247295 Reviewed by: kevans MFC after: 2 weeks Relnotes: yes Sponsored by: Klara Inc. Differential Revision: https://reviews.freebsd.org/D25362 Changes: head/sbin/md5/md5.c
Great, thank you so much! Awesome work!
^Triage: Pending merges to stable (?), set to + after merge
A commit references this bug: Author: allanjude Date: Sat Jul 11 14:55:12 UTC 2020 New revision: 363096 URL: https://svnweb.freebsd.org/changeset/base/363096 Log: MFC r346369 Close filedescriptors when done with them. MFC r362412 fix -c flag to work with input on stdin PR: 247295 Sponsored by: Klara Inc. Event: July 2020 Bugathon Changes: _U stable/12/ stable/12/sbin/md5/md5.c
Merged to stable/12, not merged to stable/11 because it is too far behind, and the last release has already been made.