DaemonForums  

Go Back   DaemonForums > Miscellaneous > General software and network

General software and network General OS-independent software and network questions, X11, MTA, routing, etc.

Reply
 
Thread Tools Display Modes
  #1   (View Single Post)  
Old 15th September 2008
Sunnz's Avatar
Sunnz Sunnz is offline
Real Name: I don't have real time
Just a computer user...
 
Join Date: May 2008
Location: See Google Maps
Posts: 101
Thanked 1 Time in 1 Post
Default SHA-256?

Just wondering how would one do a SHA-256 checksum of files on BSD systems and Mac OS X?

Do you need to install some kind of software in ports to do so?

I have been using `openssl sha1 filename`, but sometimes I wonder if SHA-256 and others can be done as well.

Thanks.
__________________
She sells C shells by the seashore.
Reply With Quote
  #2   (View Single Post)  
Old 15th September 2008
18Googol2's Avatar
18Googol2 18Googol2 is offline
Real Name: whoami
Spam Deminer
 
Join Date: Apr 2008
Location: pwd
Posts: 283
Thanked 20 Times in 18 Posts
Default

FreeBSD comes with built-in command "sha256"
__________________
The power of plain text? It can control an entire OS
Reply With Quote
  #3   (View Single Post)  
Old 16th September 2008
Darwimy Darwimy is offline
Port Guard
 
Join Date: Jun 2008
Location: Germany
Posts: 36
Thanked 2 Times in 2 Posts
Default

'openssl dgst -sha256 filename' will also do the trick, but you need a recent version of OpenSSL (the one from FreeBSD 7.0 is fine).
Reply With Quote
  #4   (View Single Post)  
Old 17th September 2008
Sunnz's Avatar
Sunnz Sunnz is offline
Real Name: I don't have real time
Just a computer user...
 
Join Date: May 2008
Location: See Google Maps
Posts: 101
Thanked 1 Time in 1 Post
Default

So which version is that? Seems like OS X and OpenBSD 4.2 don't have it yet...
__________________
She sells C shells by the seashore.
Reply With Quote
  #5   (View Single Post)  
Old 17th September 2008
TerryP's Avatar
TerryP TerryP is offline
Arp Constable
 
Join Date: May 2008
Location: USofA
Posts: 1,547
Thanked 112 Times in 104 Posts
Default

Code:
Terry@dixie$ uname -r                                                      2:56
7.0-STABLE
Terry@dixie$ openssl version                                               2:57
OpenSSL 0.9.8e 23 Feb 2007
Terry@dixie$ openssl dgst -sha256 ~/.vimrc                                 2:57
SHA256(/usr/home/Terry/.vimrc)= d5b17cc1975d3095c6353f3fdced45ae867c06e02c1efb7c09662cdc796724b0
Terry@dixie$                                                               2:57
On my OpenBSD 4.3 system it says: OpenSSL 0.9.7j 04 May 2006, you can check the version you have likewise ($ openssl version).
__________________
My Journal

Thou shalt check the array bounds of all strings (indeed, all arrays), for surely where thou typest ``foo'' someone someday shall type ``supercalifragilisticexpialidocious''.
Reply With Quote
  #6   (View Single Post)  
Old 17th September 2008
J65nko J65nko is offline
Administrator
 
Join Date: May 2008
Location: Budel - the Netherlands
Posts: 3,135
Thanked 182 Times in 149 Posts
Default

From the OpenBSD 4.2 man page sha-1(1):
Code:
     The sha1 command is shorthand for

           cksum -a sha1

     The cksum(1) command can also be used to compute digests from the SHA-2
     family: sha256, sha384 and sha512.
From man cksum(1)
Code:
     -a algorithms
             Use the specified algorithm(s) instead of the default (cksum).
             Supported algorithms include cksum, md4, md5, rmd160, sha1,
             sha256, sha384, sha512, sum, and sysvsum.
__________________
You don't need to be a genius to debug a pf.conf firewall ruleset, you just need the guts to run tcpdump
Reply With Quote
  #7   (View Single Post)  
Old 26th September 2008
Sunnz's Avatar
Sunnz Sunnz is offline
Real Name: I don't have real time
Just a computer user...
 
Join Date: May 2008
Location: See Google Maps
Posts: 101
Thanked 1 Time in 1 Post
Default

Ah never knew that there is a cksum command, thanks alot!!
__________________
She sells C shells by the seashore.
Reply With Quote
  #8   (View Single Post)  
Old 26th June 2009
jbz jbz is offline
New User
 
Join Date: Jun 2009
Posts: 1
Thanked 0 Times in 0 Posts
Default

Quote:
Originally Posted by Sunnz View Post
Just wondering how would one do a SHA-256 checksum of files on BSD systems and Mac OS X?
Thanks.
If you want a GUI utility to do this OSX, you can use hashtab at:

http://www.beeblebrox.org/hashtab

Sorry about the weird url format, the forum won't let me post url's because I don't have enough posts apparently, but it is a pretty useful little free utility for generating all kind of checksums.


[EDIT: Carpetsmoker: Made proper link -- After 10 posts you'll be able to post links, this is an anti-spam measure, I'm sorry for the inconvenience.
Welcome to the forums and thanks for your contribution]

Last edited by Carpetsmoker; 26th June 2009 at 06:53 AM. Reason: Make link
Reply With Quote
  #9   (View Single Post)  
Old 27th June 2009
Sunnz's Avatar
Sunnz Sunnz is offline
Real Name: I don't have real time
Just a computer user...
 
Join Date: May 2008
Location: See Google Maps
Posts: 101
Thanked 1 Time in 1 Post
Default

Thanks jbz!!!
__________________
She sells C shells by the seashore.
Reply With Quote
Old 10th March 2012
AnilG AnilG is offline
Real Name: Anil Gee
Port Guard
 
Join Date: Sep 2010
Location: Sydney Australia
Posts: 20
Thanked 0 Times in 0 Posts
Default

I just wish someone had shared an example command line to do an actual checksum confirmation. I spent quite a few minutes working this one out. I think the man page synopsis may be wrong or inaccurate, and it doesn't mention exit status quietly used to confirm check. Also, big files take a small while to check so you can't do too many tests quickly and not sure if it's actually hung or waiting for input. I tried pipeing file into the command as well at one point.

On Mac OS X 10.6 Snow Leopard checking a FreeBSD SHA256 checksum.
I've downloaded a 2.1 GB ISO file and the checksums are provided inside a file called CHECKSUM.SHA256 (there's an MD5 list of checksums too).

$ grep dvd CHECKSUM.SHA256
SHA256 (FreeBSD-9.0-RELEASE-i386-dvd1.iso) = ebc75ecdbd0580fbe9e59373962e0fc452c4480082af563e5c d765aca1ecd705

$ /usr/bin/shasum -a 256 FreeBSD-9.0-RELEASE-i386-dvd1.iso
ebc75ecdbd0580fbe9e59373962e0fc452c4480082af563e5c d765aca1ecd705 FreeBSD-9.0-RELEASE-i386-dvd1.iso

$ /usr/bin/shasum -a 256 -c CHECKSUM.SHA256 FreeBSD-9.0-RELEASE-i386-dvd1.iso
$ echo $?
0
Reply With Quote
Old 10th March 2012
AnilG AnilG is offline
Real Name: Anil Gee
Port Guard
 
Join Date: Sep 2010
Location: Sydney Australia
Posts: 20
Thanked 0 Times in 0 Posts
Default

Actually, I still haven't got it right. The return status seems to always be 0.

Code:
-rw-------   1 anil  staff  2244231168 Mar 10 00:50:38 2012 FreeBSD-9.0-RELEASE-i386-dvd1.iso
-rw-------   1 anil  staff  2244231166 Mar 10 13:16:46 2012 test.iso

$ /usr/bin/shasum -a 256 -c CHECKSUM.SHA256 FreeBSD-9.0-RELEASE-i386-dvd1.iso 
$ echo $?
0

$ /usr/bin/shasum -a 256 -c CHECKSUM.SHA256 test.iso
$ echo $?
0
Reply With Quote
Old 10th March 2012
J65nko J65nko is offline
Administrator
 
Join Date: May 2008
Location: Budel - the Netherlands
Posts: 3,135
Thanked 182 Times in 149 Posts
Default

Doesn't the man page for shasum mention something similar like the OpenBSD man page cksum(1)?

Code:
EXIT STATUS
     The cksum and sum utilities exit 0 on success or >0 if an error occurred.
An error code of zero indicating success is quite standard on Unix and Unix-look-a-likes
__________________
You don't need to be a genius to debug a pf.conf firewall ruleset, you just need the guts to run tcpdump
Reply With Quote
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT. The time now is 01:21 PM.


Powered by vBulletin® Version 3.8.4
Copyright ©2000 - 2014, Jelsoft Enterprises Ltd.
Content copyright © 2007-2010, the authors
Daemon image copyright ©1988, Marshall Kirk McKusick