4 # Helper to check a file matches its known hash
6 # $1: the full path to the file to check
7 # $2: the path of the file containing all the the expected hashes
12 # Does the hash-file exist?
13 if [ ! -f "${h_file}" ]; then
17 # Check one hash for a file
19 # $2: file (full path)
25 # Note: md5 is supported, but undocumented on purpose.
26 # Note: sha3 is not supported, since there is currently no implementation
27 # (the NIST has yet to publish the parameters).
30 sha224|sha256|sha384|sha512
) ;;
31 *) # Unknown hash, exit with error
32 printf "ERROR: unknown hash '%s' for '%s'\n" \
33 "${_h}" "${_file##*/}" >&2
38 # Do the hashes match?
39 _hash
=$
( ${_h}sum "${_file}" |cut
-d ' ' -f 1 )
40 if [ "${_hash}" = "${_known}" ]; then
41 printf "%s: OK (%s: %s)\n" "${_file##*/}" "${_h}" "${_hash}"
45 printf "ERROR: %s has wrong %s hash:\n" "${_file##*/}" "${_h}" >&2
46 printf "ERROR: expected: %s\n" "${_known}" >&2
47 printf "ERROR: got : %s\n" "${_hash}" >&2
48 printf "ERROR: Incomplete download, or man-in-the-middle (MITM) attack\n" >&2
53 # Do we know one or more hashes for that file?
58 # Skip comments and empty lines
62 if [ "${f}" = "${file##*/}" ]; then
63 check_one_hash
"${t}" "${h}" "${file}"
70 if [ ${nb_checks} -eq 0 ]; then
71 if [ -n "${BR2_ENFORCE_CHECK_HASH}" ]; then
72 printf "ERROR: No hash found for %s\n" "${file}" >&2
75 printf "WARNING: No hash found for %s\n" "${file}" >&2