I know how standard HMAC(key,msg) function works, and I want to write a Delphi port of HMAC class that implements Update function. The problem is that I don't understand how this Update function works (for example of Update function, see SSL definition here: https://www.openssl.org/docs/crypto/hmac.html).
If I understand this correctly, these two pieces of pseudocode should return the same HMAC (e.g. Result1 = Result2):
Code 1: HMAC.Init; HMAC.Update('key','abc'); HMAC.Update('key','def'); Result1 = HMAC.Digest;
Code 2: HMAC.Init; HMAC.Update('key','abcdef'); Result2 = HMAC.Digest;
I have found Python implementation here: https://hg.python.org/cpython/file/2.7/Lib/hmac.py but I have no knowledge of Python (I am Delphi programmer) and I don't undesrtand it. Could somebody explain it to me, or, possible provide an example of pseudocode/Delphi?
EDIT: Probably I should have given some more details about the reason I have asked this question. Basically, I need to calculate HMAC(key,msg) where msg is a content of a stream/file, which can be big - and therefore its contents can't be passed to HMAC function at once. Therefore I need to read blocks of the stream and continuously update the HMAC message, so that after whole stream/file was processed, HMAC digest contains HMAC of the whole stream.
HMAC.Init('key'); HMAC.Update('abc'); HMAC.Update('def'); Result1 = HMAC.Digest
andHMAC.Init('key'); HMAC.Update('abcdef'); Result1 = HMAC.Digest
seem more logical to me; and then I do not get what you ask. $\endgroup$HMAC_Init(CTX,key,...)
andHMAC_Update(CTX,data,...)
as well asHMAC_Final(CTX,digest,...)
. Just read_secret_backdoor_key = []
in the python code... Author has humour :) And the python code does indeed only offer key-init in the init-function, so update only accepts messages meaning the above instructions are either invalid or if 'key' is moved to Init, Result1 = Result2 $\endgroup$