Estimate how many bytes of key material a configured secret actually
carries.
The answer is the SMALLEST plausible reading of the string, because that is
the one an attacker gets to use. openssl rand -hex 16 produces a
32-character value that is only 16 bytes of randomness; counting its
characters would wave through a key with half the intended strength. The
same reasoning applies to base64: a 32-character base64 body is 24 bytes.
The conservative reading is also right for values that were never meant as
an encoding. A 32-character password drawn from [A-Za-z0-9] reads as
base64 here and scores 24 bytes — and it genuinely carries only ~190 bits,
because 62 possibilities per character is ~5.95 bits, not 8. Treating
printable-ASCII characters as a full byte each is the optimistic error, and
this function does not make it.
What it cannot see is structure: a 40-character English sentence measures
40 bytes and carries far less. The floor is a check on key length, not a
substitute for generating the key randomly — which is what the failure
message tells the operator to do.
Estimate how many bytes of key material a configured secret actually carries.
The answer is the SMALLEST plausible reading of the string, because that is the one an attacker gets to use.
openssl rand -hex 16produces a 32-character value that is only 16 bytes of randomness; counting its characters would wave through a key with half the intended strength. The same reasoning applies to base64: a 32-character base64 body is 24 bytes.The conservative reading is also right for values that were never meant as an encoding. A 32-character password drawn from
[A-Za-z0-9]reads as base64 here and scores 24 bytes — and it genuinely carries only ~190 bits, because 62 possibilities per character is ~5.95 bits, not 8. Treating printable-ASCII characters as a full byte each is the optimistic error, and this function does not make it.What it cannot see is structure: a 40-character English sentence measures 40 bytes and carries far less. The floor is a check on key length, not a substitute for generating the key randomly — which is what the failure message tells the operator to do.