Skip to content

Add support for CMAC #802

Open
Open

Description

@kmfukuda

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.

Activity

  1. deleted a comment from Kami-prog on Sep 25, 2024
  2. rhenium commented on Oct 29, 2024

    @rhenium
    Member

    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"
  3. kmfukuda commented on Nov 8, 2024

    @kmfukuda
    Author

    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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions