Showing results for 
Search instead for 
Did you mean: 

libHMAC.rts: Calculating HMAC hashes in TrafficScript

The need to calculate HMAC hashes cropped up here: TrafficScript can Tweet Too.  Currently (as of Stingray version 9.1), Stingray's 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.

Version history
Revision #:
1 of 1
Last update:
‎03-15-2013 04:01:AM
Updated by:
Labels (1)