The need to calculate HMAC hashes cropped up here: TrafficScript can Tweet Too. Currently (as of Stingray version 9.1), TrafficScript language does not contain HMAC-MD5 or HMAC-SHA1 hash functions, so it was necessary to create a library to implement these operations.
Copy and paste the following library from GitHub, saving it as libHMAC.rts in your rules catalog:
Import the library into your TrafficScript rule as follows:
import libHMAC.rts as hmac;
Invoke the HMAC hash functions like this:
$digestMD5 = hmac.MD5( $key, $data );
$digestSHA1 = hmac.SHA1( $key, $data );
To test the performance and correct operation of the library, you can use the following TrafficScript rule. Assign it to an HTTP virtual server (as a request rule) and then request a page (any page) from the virtual server using your web browser. The rule will take approximately 15 seconds to run before giving you the results.
On my test system, I could achieve about 1,500 operations (slightly more with MD5 than SHA1). Allowing CPU resource for other operations, that suggests a few 100 HMAC operations per core in a production system. The rule runs on a single core, so if you attach it to real traffic, the effective capability will increase with the number of cores.