# sha1sum -c



## gsad (Mar 12, 2011)

I use [cmd=]sha1sum -c[/cmd] in Ubuntu. What is its equivalent in FreeBSD?


----------



## wblock@ (Mar 12, 2011)

`# openssl sha1 -c [b]filename[/b]`

I think.  Remember that not everyone who knows FreeBSD is intimately familiar with other operating systems, so it's helpful to tell what a command does.


----------



## DutchDaemon (Mar 13, 2011)

shasum(1) looks like a good contender. SHA1 is the default.


```
$ pkg_info -W /usr/local/bin/shasum
/usr/local/bin/shasum was installed by package perl-5.10.1_3
```

It's almost impossible not to have it installed.


----------



## gordon@ (Mar 13, 2011)

Or just use sha1(1). It's part of the base system.


----------



## wblock@ (Mar 13, 2011)

Yes, but it doesn't have the -c option.  There ought to be an easier way to do this, but all that comes to mind is
`% sha1 -q -s "testing" | sed 's%\(..\)%\1:%g'`


----------



## gordon@ (Mar 13, 2011)

wblock said:
			
		

> Yes, but it doesn't have the -c option.  There ought to be an easier way to do this, but all that comes to mind is
> `% sha1 -q -s "testing" | sed 's%\(..\)%\1:%g'`



So if you already have a file with the sha1 checksums do this:

`% sha1 /path/to/file | diff -u /path/to/file.sha -`


----------



## wblock@ (Mar 13, 2011)

Sorry, confusion on my part.  -c is not to put colons every two characters in the checksum (sha1 on Linux), but to read checksums from a file.  Doh.


----------



## gsad (Mar 13, 2011)

Sorry for being vague in my original post, take 2:

I use [cmd=]sha1sum -c knownhashes.txt[/cmd] to check verify a file of list of known hashes against the checksum'med files. Knownhashes.txt is a file created by [cmd=]sha1sum *.doc > knownhashes.txt[/cmd]

In FreeBSD, I created a file of known hashes by [cmd=]sha1 *.doc > sha1file.txt[/cmd] How do I check sha1file.txt to verify the files? Is it possible to check the file without installing a new ports?


----------



## gordon@ (Mar 13, 2011)

Do this:

`% sha1 *.doc | diff -u sha1file.txt -`


----------



## DutchDaemon (Mar 13, 2011)

```
NAME
       shasum - Print or Check SHA Checksums

SYNOPSIS
	Usage: shasum [OPTION] [FILE]...
	   or: [B]shasum [OPTION] --check [FILE][/B]
	Print or check SHA checksums.
	With no FILE, or when FILE is -, read standard input.

	 -a, --algorithm    1 (default), 224, 256, 384, 512
	 -b, --binary	    read files in binary mode (default on DOS/Windows)
	 [B]-c, --check	    check SHA sums against given list[/B]
```

shasum(1). Tried it? It's part of Perl, so you probably already have it ...


----------



## gsad (Mar 14, 2011)

@gordon, thanks, I think that's my only option.
@DutchDaemon, yes I did. but it expects the format which is output of sha1sum, it fails if the file of known hashes was generated by sha1 command


----------



## anomie (Mar 14, 2011)

gsad said:
			
		

> I use [cmd=]sha1sum -c[/cmd] in Ubuntu. What is its equivalent in FreeBSD?



Recent, related thread on this very topic (just with a different digest).


----------



## gordon@ (Mar 15, 2011)

anomie said:
			
		

> Recent, related thread on this very topic (just with a different digest).



My advice in that thread looks remarkably familiar. =)


----------



## DutchDaemon (Mar 15, 2011)

I actually got a request to merge these threads, but I felt it would be confusing.


----------

