Problem:
- HMAC_SHA256 and HMAC_SHA512 almost the same. Differences are:
OUTPUT_SIZEof the hash- magic number constants which can be derived from
OUTPUT_SIZE
- Code duplication is error prone and causes maintenance issues.
Solution:
- Eliminate magic numbers by making
OUTPUT_SIZEa compile-time constant and deriving the other constants from it. - Compile-time constants permit container type creation, type-based bounds checking, and range-based iteration instead of run-time branching.
- Elimination of run-time eval and magic numbers allows templatization to reduce code duplication.
- Old type names and header files are preserved via
usingdeclarations to limit the scope of the change.
Note:
- This is a rethink which takes into account the comments from #11735