Exercise 2

Hash Functions for Verifying the Integrity of Files

Among the system commands on FreeBSD and Linux systems, there are hash functions (in order of importance):

FreeBSD Linux
sha256 sha256sum
sha1 sha1sum
sha384 sha384sum
md5 md5sum

Apply these hash functions to determine the hash values of files:

sha256sum /etc/services
f6183055fd949f9c53d49ee620f85d0150123ea691d25ed1bba0c641b4ee2f48  /etc/services
sha1sum /etc/services
a0d7a229bf049f7fe17e8445226236e4024535d0  /etc/services
sha384sum /etc/services
f5c538da3dc434041306491a3a08481fb67315e424e3becc8e7b450c1a3779e3a6f0bc49c2032f36010e4cab73bbf018  /etc/services
md5sum /etc/services
3975f0d8c4e1ecb25f035edfb1ba27ac  /etc/services

Copy the file /etc/services to your home directory and modify an entry. Observe that this changes the hash value.

OpenSSL

Also output the hash value using openssl:

openssl dgst -sha256 /etc/services
SHA2-256(/etc/services)= f6183055fd949f9c53d49ee620f85d0150123ea691d25ed1bba0c641b4ee2f48
openssl dgst -sha1 /etc/services
SHA1(/etc/services)= a0d7a229bf049f7fe17e8445226236e4024535d0
openssl dgst -sha384 /etc/services
SHA2-384(/etc/services)= f5c538da3dc434041306491a3a08481fb67315e424e3becc8e7b450c1a3779e3a6f0bc49c2032f36010e4cab73bbf018
openssl dgst -md5 /etc/services
MD5(/etc/services)= 3975f0d8c4e1ecb25f035edfb1ba27ac

OpenSSL also provides additional secure hash functions:

openssl dgst -list
Supported digests:
-blake2b512
-blake2s256
-md4
-md5
-md5-sha1
-ripemd
-ripemd160
-rmd160
-sha1
-sha224
-sha256
-sha3-224
-sha3-256
-sha3-384
-sha3-512
-sha384
-sha512
-sha512-224
-sha512-256
-shake128
-shake256
-sm3
-ssl3-md5
-ssl3-sha1
-whirlpool

Try out the new SHA-3 standard as well as SHA512, Whirlpool, and RIPEMD160:

openssl dgst -sha3-256 /etc/services
SHA3-256(/etc/services)= 2a3f7d6a1a910fadb360941a1a3cbd1bea3f5f63dd30a1877b49a002971648cd
openssl dgst -sha512 /etc/services
SHA2-512(/etc/services)= 47b0f3ee73af2d259bd206a026204be0ea25531a895a0b035a904b38fe5407bc3dd2beab7f8fcb3d760587e6159702ebdb9cbc4f508942befdf7f10c10c87888
openssl dgst -whirlpool -provider legacy /etc/services
WHIRLPOOL(/etc/services)= 7db0e3bb467da1fb065e823fc35998175fe20d1a90118fc17aeeea59e0ec8545b182f0e5076b9a6bd7086accd279723a148fff8c149299c6ee3f372f8a7be522
openssl dgst -ripemd160 -provider legacy /etc/services
RIPEMD-160(/etc/services)= ef6abb95cc940303498935b9483ff2bf96beaa90