Skip to content
This repository was archived by the owner on Feb 5, 2021. It is now read-only.

Implemented optimal CMAC calculation for WebCrypto#156

Open
Traktormaster wants to merge 4 commits intomiscreant:developfrom
Traktormaster:develop
Open

Implemented optimal CMAC calculation for WebCrypto#156
Traktormaster wants to merge 4 commits intomiscreant:developfrom
Traktormaster:develop

Conversation

@Traktormaster
Copy link
Copy Markdown

I've found myself in a situation where this AES-SIV implementation would be great for use, but its performance was very lacking.

After digging a bit I've found that the CMAC calculation is very badly optimized and (unlike the PMAC) it should be trivial to improve.

I've basically solved the TODO in the cmac.ts that said: use AES-CBC with a span of multiple blocks instead of encryptBlock to encrypt many blocks in a single call to the WebCrypto API.

I've added the necessary interface changes and compatibility for the software aes fallback provider. Of course the performance of that is not any better. Unit tests are still passing.

In summary this change improved the performance of AES-CMAC-SIV.
For example, the encoding performance improved from 400KB/s to 120MB/s!

@Traktormaster
Copy link
Copy Markdown
Author

The second optimization further reduces the number of CBC encrypt calls by batching the data together and only calling encrypt once in CMAC.finalize().

This helps some more when a lot of small messages are to be handled. For example: encrypting 2000 100B messages took 0.95 seconds before the second patch, while the same only needs 0.6 seconds to complete now. It's a ~30% improvement for this type of load. There is no performance change for encrypting a small number of large messages.

This has the trade-off of having to batch and prepare all the data in a single buffer. This uses more RAM, but is vastly superior in execution time.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant