PointyCastle / pointycastle

Moved into the Bouncy Castle project: https://github.com/bcgit/pc-dart
MIT License
271 stars 75 forks source link

Add Mac: CMAC ("AES/CMAC") #174

Closed paulreimer closed 5 years ago

paulreimer commented 5 years ago

Based on BouncyCastle sources, using the test vectors from the AES-CMAC RFC: https://tools.ietf.org/html/rfc4493

Those test vectors are binary plaintext, so I refactored _runMacTest to use accept UInt8List.

I'm not strong in Java, Dart, or crypto, please review accordingly.

paulreimer commented 5 years ago

This PR requires #175 (ISO7816-4 padding) to be merged first.

paulreimer commented 5 years ago

I don't know why there is a separate macs/CBCBlockCipherMac and macs/CMac class in BouncyCastle, with very similar (but slightly different) implementations. I'm porting the other one as well, and I will add it to this PR in the same manner that BouncyCastle has it (that is, two nearly identical algorithms in the same macs/ folder).

I'll note that that my goal is to get AES-CCM working (by porting BouncyCastle's CCMBlockCipher.java), and that one uses the CBCBlockCipherMac. Other than that, I'm not sure which one is best, or just to ship them both?

stevenroose commented 5 years ago

Sorry for the late review. I was hoping someone who actually uses this library could perhaps review this..

It looks quite good, even though I didn't verify the validity of the test vectors.

I found one nit, once addressed, I can merge this.

stevenroose commented 5 years ago

Thanks for the contribution!