Project

cmac

0.0
No commit activity in last 3 years
No release in over 3 years
A ruby implementation of RFC4493, RFC4494, and RFC4615. CMAC is a message authentication code (MAC) built using AES-128.
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
 Dependencies

Development

= 10.5.0
= 3.4.0
 Project Readme

CMAC Build Status

This gem is ruby implementation of the Cipher-based Message Authentication Code (CMAC) as defined in RFC4493, RFC4494, and RFC4615. Message authentication codes provide integrity protection of data given that two parties share a secret key.

key = OpenSSL::Random.random_bytes(16)
message = 'attack at dawn'
cmac = CMAC.new(key)
cmac.sign(message)
 => "\xF6\xB8\xC1L]s\xBF\x1A\x87<\xA4\xA1Z\xE0f\xAA"

Once you've obtained the signature (also called a tag) of a message you can use CMAC to verify it as well.

tag = "\xF6\xB8\xC1L]s\xBF\x1A\x87<\xA4\xA1Z\xE0f\xAA"
cmac.valid_message?(tag, message)
 => true
cmac.valid_message?(tag, 'attack at dusk')
 => false

CMAC can also be used with a variable length input key as described in RFC4615.

key = 'setec astronomy'
message = 'attack at dawn'
cmac = CMAC.new(key)
cmac.sign(message)
 => "\\\x11\x90\xE6\x91\xB2\xC4\x82`\x90\xA6\xEC:\x0E\x1C\xF3"