Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/spider-gazelle/cmac
Crystal implementation of the Cipher-based Message Authentication Code (CMAC)
https://github.com/spider-gazelle/cmac
Last synced: about 1 month ago
JSON representation
Crystal implementation of the Cipher-based Message Authentication Code (CMAC)
- Host: GitHub
- URL: https://github.com/spider-gazelle/cmac
- Owner: spider-gazelle
- License: mit
- Created: 2019-12-14T11:34:58.000Z (almost 5 years ago)
- Default Branch: master
- Last Pushed: 2023-10-16T06:54:10.000Z (about 1 year ago)
- Last Synced: 2024-08-01T17:33:08.088Z (4 months ago)
- Language: Crystal
- Size: 7.81 KB
- Stars: 5
- Watchers: 4
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
- awesome-crystal - cmac - Crystal implementation of Cipher-based Message Authentication Code (CMAC) (Cryptography)
- awesome-crystal - cmac - Crystal implementation of Cipher-based Message Authentication Code (CMAC) (Cryptography)
README
# Crystal Lang CMAC
[![CI](https://github.com/spider-gazelle/cmac/actions/workflows/ci.yml/badge.svg)](https://github.com/spider-gazelle/cmac/actions/workflows/ci.yml)
Crystal implementation of the Cipher-based Message Authentication Code (CMAC) as defined in [RFC4493](http://tools.ietf.org/html/rfc4493), [RFC4494](http://tools.ietf.org/html/rfc4494), and [RFC4615](http://tools.ietf.org/html/rfc4615). Message authentication codes provide integrity protection of data given that two parties share a secret key.
```crystal
key = Random.new.random_bytes(16)
message = "attack at dawn"
cmac = CMAC.new(key)
cmac.sign(message)
=> Bytes[246, 184, 193, 76, 93, 115, 191, 26, 135, 60, 164, 161, 90, 224, 102, 170]
```Once you've obtained the signature (also called a tag) of a message you can use CMAC to verify it as well.
```crystal
tag = Bytes[246, 184, 193, 76, 93, 115, 191, 26, 135, 60, 164, 161, 90, 224, 102, 170]
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.
```crystal
key = "setec astronomy"
message = "attack at dawn"
cmac = CMAC.new(key)
cmac.sign(message)
=> Bytes[92, 17, 144, 230, 145, 178, 196, 130, 96, 144, 166, 236, 58, 14, 28, 243]
```