Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for CMAC #802

Open
kmfukuda opened this issue Sep 19, 2024 · 2 comments
Open

Add support for CMAC #802

kmfukuda opened this issue Sep 19, 2024 · 2 comments

Comments

@kmfukuda
Copy link

kmfukuda commented Sep 19, 2024

I have been using CMAC with AES-128, or AES-CMAC as specified in RFC 4493, with the help of a gem that targets that RFC.
In several months, I will need to use CMAC with more ciphers, which is outside the scope of such gems.
After looking for alternative implementations, I think it would be best to make OpenSSL's CMAC implementation available to Ruby code.

@rhenium
Copy link
Member

rhenium commented Oct 29, 2024

FWIW: Since CMAC is available through the EVP_PKEY API (see the man page EVP_PKEY-CMAC(7)), OpenSSL::PKey automatically supports it. However, with a limitation that the message must be given as a single String.

k = ["2b7e1516 28aed2a6 abf71588 09cf4f3c".split.join].pack("H*")
m = ["6bc1bee2 2e409f96 e93d7e11 7393172a".split.join].pack("H*")
pkey = OpenSSL::PKey.generate_key("CMAC", priv: k, cipher: "aes-128-cbc")
mac = pkey.sign(nil, m)
p mac.unpack1("H*")
#=> "070a16b46b4d4144f79bdd9dd04a287c"

@kmfukuda
Copy link
Author

kmfukuda commented Nov 8, 2024

Thanks. I couldn't start using a feature that I knew was already considered legacy.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

No branches or pull requests

2 participants