Secure Hash IV
We are looking into the Secure Hash IV primitive, but don’t seem to get it to work. Could you please provide a small sample on how to use this primitive?
I’ve found an issue in some old code in SmartDeck that is probably the cause of your issues. I will get it fixed as soon as I can (hopefully this week) and e-mail you that along with an example (which I’ll also post here).
Thanks for reporting this.
The issues in the simulator (ver 2.3.1) with SECURE_HASH_IV primitive have been found and fixed. A patch for registered SmartDeck users is available on request.
Here is an example of using this primitive.
#pragma attribute("aid", "F1000005")
#pragma attribute("dir", "611B4F04F1000005501343523330352053454355524520484153482020")
void main (void)
// Start a completely new hash - erase buffers
pRemainder = 0;
dwPrevHashedBytes = 0;
wLenMsgRem = 0;
// Set up some data at various points
bData = 0x5A;
bData = 0xA5;
bData = 0xFF;
// SHA-1 hash using the non IV primitive for range of data
multosSecureHash(140, 20, bHash1, bData);
// Use IV primitive to do the hash in two parts
// Part 1: Bytes 0-119
multosSecureHashIV(120, 20, bHash2, bData, bIMHash, &dwPrevHashedBytes;, &wLenMsgRem;, &pRemainder;);
// Part 2: Bytes 120-139
multosSecureHashIV(20, 20, bHash2, bData+120, bIMHash, &dwPrevHashedBytes;, &wLenMsgRem;, &pRemainder;);
// Compare hashes, should match
if(memcmp(bHash1, bHash2, 20) == 0)
Here is a bit more info on usage of this primitive. If you are writing something to hash a long stream of data calling the APDU multiple times, this is how you could do it.
pRemainder = bRemain;
wLenMsgRem = 0;
// On entry, pRemainder points to the buffer storing the remainder from the previous call
multosSecureHashIV(Lc, 32, bHash2, pub, bIMHash, &dwPrevHashedBytes;, &wLenMsgRem;, &pRemainder;);
// On exit, pRemainder points to the data in public that was not hashed. That data needs to be saved for the next calculation