#!/bin/bash

## Copyright (C) 2012 - 2025 ENCRYPTED SUPPORT LLC <adrelanos@whonix.org>
## See the file COPYING for copying conditions.

check_entropy() {
   # Check entropy available bits, 112 is FIPS-140 requirement
   local entropy_file entropy_size
   entropy_file="/proc/sys/kernel/random/entropy_avail"
   entropy_size="$(cat "$entropy_file")"
   if [ "${entropy_size}" -lt "112" ]; then
      local MSG="<p>Entropy Available Check Result: low. <code>$entropy_file</code>: <code>$entropy_size</code> Please report this issue!</p>"
      $output_x ${output_opts[@]} --messagex --typex "warning" --message "$MSG"
      $output_cli ${output_opts[@]} --messagecli --typecli "warning" --message "$MSG"
      EXIT_CODE="1"
   else
      local MSG="<p>Entropy Available Check Result: ok. <code>$entropy_file</code>: <code>$entropy_size</code></p>"
      if [ "$verbose" -ge "1" ]; then
         $output_x ${output_opts[@]} --messagex --typex "info" --message "$MSG"
         $output_cli ${output_opts[@]} --messagecli --typecli "info" --message "$MSG"
      fi
   fi
}
