Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
FIPS mode support needs to be enabled at compile time, by configuring Erlang/OTP with --enable-fips option. In FIPS mode the non-FIPS algorithms are disabled and raise error notsup. The rest of the functions are rewritten to use the high level EVP interface when compiled in FIPS mode. Non-FIPS build still use the old code path. The supported protocols list is properly updated in FIPS-mode to advertise only the enabled protocols. FIPS mode is by default even if Erlang/OTP was built with FIPS support. It needs to be turned on at runtime. The official approach is to set the fips_mode application environment parameter of the crypto application to true. This would turn FIPS mode on when the NIF is loaded and would prevent loading the module on error. An other method is provided via the crypto:enable_fips_mode/1 function, but it is not recommended to be used in production, as it won't prevent the use of the crypto module in case of an error, and would risk OpenSSL crashing the emulator. It is very useful for test suites however that need to check both validated and not validated functionality. Some implementation details: Using the EVP interface raises similar issues with context copying as in commit 651b949. However, since FIPS mode require OpenSSL 1.0.1 backward compatibility with 0.9.8 is not an issue here, so we are free to provide a functional interface by context copying. The downside is that cipher states are no longer compatible between FIPS and non-FIPS builds, and that the new nif resource context values have a much more limited use in the Erlang VM (e.g. you cannot persist them). The digest_type_t structure used to store the NID of the hash function, but it is now changed to the function that returns the EVP_MD pointer. The reason is that the NID can be retrieved from the EVP_MD structure (the type field), but EVP_get_digestbynid cannot be used reliably to retrieve the EVP_MD from the NID.
- Loading branch information