"Sputnik" help  
Sputnik Help
HashUpdateStream(<hashContext>, <stream>, [<length>])


Updates a hash context with the contents of a stream during a hashing operation. This function reads data from the stream in 4096-byte chunks, allowing for incremental hashing without loading the entire content into memory.


<hashContext> The hash context to be updated.
<stream> The stream from which to read data for inclusion in the hash computation.
[<length>] Optional. Specifies how much data to read from the stream. The default is -1, indicating reading until the end of the stream.

Return Value

Success: Returns an integer representing the actual number of bytes read from the stream and included in the hash computation.
Failure: Returns -1.


Use HashUpdateStream in conjunction with HashInit to incrementally hash data from streams. The function reads data from the stream in 4096-byte chunks, optimizing the hashing process for memory efficiency.


HashInit, HashUpdate, HashFinal, HashCopy, HashUpdateFile


Example of usage:

my $hash = HashInit("gost", @HashOptHMac, "secretKey");
my $file1 = FileOpen("SputnikWin.dll", "o/r/r");
my $file2 = FileOpen("SputnikNative.dll", "o/r/r");
HashUpdateStream($hash, $file1);
HashUpdateStream($hash, $file2);
say HashFinal($hash);

// 75AFFD0DC35818A89E4712127526C5B4750BC5575A67B24EE6FEB23AD070FE8A

my $hash = HashInit("gost", @HashOptHMac, "secretKey");
HashUpdateFile($hash, "SputnikWin.dll");
HashUpdateFile($hash, "SputnikNative.dll");
say HashFinal($hash);

// 75AFFD0DC35818A89E4712127526C5B4750BC5575A67B24EE6FEB23AD070FE8A

In this example, two approaches are shown for updating a hash context with the contents of multiple files using the GOST hash algorithm with HMAC and a secret key.

The first approach uses HashUpdateStream to incrementally update the hash context by reading from two opened files (SputnikWin.dll and SputnikNative.dll) in stream mode. The files are processed in chunks, and the resulting hash is obtained with HashFinal. The second approach uses HashUpdateFile to directly update the hash context with the contents of the same two files. Both approaches produce the same final hash value, demonstrating the equivalence of these methods. The HMAC key "secretKey" is utilized to enhance the security of the hashing process. The final hash value represents the HMAC-GOST hash of the concatenated contents of the specified files with the provided secret key.

Cheryl (uberfox@hotmail.com)