Skip to content

Conversation

@junaruga
Copy link
Member

@junaruga junaruga commented Jan 9, 2026

This PR is to fix test_cipher.rb in FIPS.

I used the FIPS-approved algorithm AES-256-CBC instead of FIPS-not-approved algorithm DES-EDE3-CBC, also used the FIPS-approved algorithm SHA256 instead of FIPS-not-approved algorithm MD5 in some tests to pass the tests.

I confirmed the CI passed on my fork repository.
https://github.com/junaruga/ruby-openssl/actions/runs/20862608486

cipher = OpenSSL::Cipher.new("DES-EDE3-CBC").encrypt
cipher.pkcs5_keyivgen(pass, salt, num, "MD5")
cipher = OpenSSL::Cipher.new("AES-256-CBC").encrypt
cipher.pkcs5_keyivgen(pass, salt, num, "SHA256")
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is OpenSSL::Cipher#pkcs5_keyivgen/EVP_BytesToKey() actually compliant if we use SHA-256? I suspect it isn't, but unifying on SHA-256 seems like a good idea.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Originally I saw that the test_pkcs5_keyivgen failed as follows with OpenSSL.debug = true due to the DES-EDE3-CBC.

Error: test_pkcs5_keyivgen(OpenSSL::TestCipher): OpenSSL::Cipher::CipherError: EVP_CipherInit_ex
/home/jaruga/var/git/ruby/openssl/test/openssl/test_cipher.rb:37:in 'OpenSSL::Cipher#encrypt'
/home/jaruga/var/git/ruby/openssl/test/openssl/test_cipher.rb:37:in 'OpenSSL::TestCipher#test_pkcs5_keyivgen'
     34:     salt = "\x01" * 8
     35:     num = 2048
     36:     pt = "data to be encrypted"
  => 37:     cipher = OpenSSL::Cipher.new("DES-EDE3-CBC").encrypt
     38:     cipher.pkcs5_keyivgen(pass, salt, num, "MD5")
     39:     s1 = cipher.update(pt) << cipher.final
     40:-

However, when I ran the test_pkcs5_keyivgen with the cipher.pkcs5_keyivgen(pass, salt, num, "MD5") instead of the cipher.pkcs5_keyivgen(pass, salt, num, "SHA256"), the cipher.pkcs5_keyivgen(pass, salt, num, "MD5") still passed in the FIPS case. But later steps failed somehow.

@rhenium rhenium merged commit dc01033 into ruby:master Jan 10, 2026
47 checks passed
@junaruga junaruga deleted the wip/fips-test-cipher branch January 12, 2026 15:24
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants