Where to find FreeBSD sha256 utility source code

Viewed 79

FreeBSD provides set of utilities for computing SHA-2 hashes (sha256, sha512, etc). I want to find their source code. I don't need source code of the SHA-256 hash function itself, but I am looking for source code of the command-line utility, i.e. part which processes command-line options, input files, etc. I've cloned latest FreeBSD source code from the GitHub-based mirror repo, and searched for "sha256" over the whole repo, and it gave me a lot of matches, but still I couldn't find that exact one. Please point me, where I can find it, if you know. Note: please do not point me to Linux/GNU alternative, sha256sum, I am interested exactly in the code of the FreeBSD sha256 (and friends like sha384, sha512) utility.

2 Answers

The command line utility is md5, but the same executable has many different names. See md5(1). The source code is located at src/sbin/md5.

It uses a number of functions from the libmd library located at src/lib/libmd, but the crypto code seems to be in src/sys/crypto/sha2.

By default, the hash utilities come from OpenSSL in the base system. For example

$ less /usr/src/crypto/openssl/crypto/sha/sha256.c

/*
 * Copyright 2004-2016 The OpenSSL Project Authors. All Rights Reserved.
 *
...

You can upgrade the utilities from ports. In this case, you can find the source in /usr/ports. For example

$ cd /usr/ports/security/openssl
$ make fetch
$ make extract
$ less /usr/ports/security/openssl/work/openssl-1.1.1l/crypto/sha/sha256.c

/*
 * Copyright 2004-2016 The OpenSSL Project Authors. All Rights Reserved.
 *
...
Related