I am attempting to use the Stanford Javascript Crypto Library to generate an CMAC-AES token for an OAuth 2.0 assertion, but I'm far from being an expert with cryptography. Can someone give an example using sjcl or any open-license js library out there? I'm not even sure it's possible using sjcl's existing functions.
I tried using an options object like I saw in this question, but I don't understand the modes or other options, and I couldn't find any documentation on this. I figure the salt and iv (to be a reproduceable MAC) would have to be static, but I don't know what values they should be.
// is there a way that works?
var token = sjcl.encrypt(secret,assertion,{salt:foo,iv:bar});
A little background... this is for a rewrite of native mobile apps (iOS and android) to a single hybrid app (Cordova, HTML, CSS, and JavaScript), and I would like to keep as much code shared in JavaScript as possible. This won't be running in an "insecure" browser environment, but rather the native WebViews. If you know of other security issues, please I'd like to hear them.
Otherwise I guess I'll have to write a plugin to pass the CMAC from native implementations.
Forgot to mention, I'm also using Dojo and I'm aware of dojox.encoding.crypto but the problem is the same for me. Not sure if it can do CMAC or how much modification it would take to make it work.
Spent too much time this weekend coming up with this solution, but I finally got it working. It's amazing how many places it can go wrong. This is a dojo AMD module so it can easily be loaded using a "require". Usage is demonstrated by the test vectors that follow (ignore the subkey tests in normal usage). One quirk: make sure you are passing the key and messages as hex encoded strings. I plan to make it a little friendlier and accept utf8String encoded strings as well, but with sjcl.codec it is fairly easy to do that on your own.
I'd appreciate any feedback, especially for the padding function and my usage of the bitArray methods.
Here are the test vectors
You could have a look at it and implement it yourself. Implementing CMAC should be doable if you have an AES primitive block encrypt working. Trickiest part is probably making sure that you use real bytes instead of any other type that is within JavaScript.
AES CMAC is NIST approved so you could test against test factors.