"Sputnik" help |

Sputnik
Help

Description

Initializes a hash context for subsequent hashing operations. The function supports various hash algorithms and optional parameters, allowing for flexibility in hash computation.

Parameters

<algo> | The hash algorithm to use. |

<options> | Optional. Hashing options, defaults to @HashOptDefault. |

<key> | Optional. Only used if <options> is set to @HashOptHMac. |

Return Value

Success: | Returns hash context that can be used for subsequent hashing operations. |

Failure: | Returns null. |

Remarks

This function is a preparatory step for hashing data using different algorithms and options. It sets up the hash context based on the specified algorithm and options, preparing it for subsequent data input.

See HashAlgos and Hash for a list of hashes.

Related

HashUpdate, HashFinal, HashCopy, HashUpdateFile, HashUpdateStreamExample

Example of usage:

my$hash=HashInit("gost");HashUpdate($hash,"Cat");say HashFinal($hash);my$hash=HashInit("gost");HashUpdate($hash,"Cat");HashUpdate($hash,"Dog");say HashFinal($hash);// PRINTS// CEA32112D34163EB607E8F19CC8C8E2D2B11268088D35F71757AABA6A11D40B8// 5D32789DD6F8F25FBDEE44F875FABC1556AE8A97F3619EE8CE04D548595D0973

In the given example, two hash computations are showcased using the **GOST**
hash algorithm in **Sputnik**. In the first instance, the hash
context is initialized with the string "Cat," and the resulting hash
is calculated and printed. In the second case, the same hash context is updated
with an additional string, "Dog," before finalizing and printing the
resulting hash. The hash values demonstrate the unique fingerprints generated
by the **GOST** algorithm for the given input data. The ability
to update the hash context allows for the incremental hashing of data, and each
distinct input produces a different hash output, highlighting the cryptographic
strength of the **GOST** hash function.

Using the **HMac**:

my$hash=HashInit("gost",@HashOptHMac,"secretKey");HashUpdate($hash,"Cat");HashUpdate($hash,"Dog");say HashFinal($hash);// PRINTS// 56FAFEECA6A4A191D893A4E0C34EBA828AC30F9D46D38CDECE6A15E949478DA4

In this example, a hash context is initialized using the **GOST**
hash algorithm with **HMAC** (**Hash-Based Message Authentication
Code**) enabled by specifying **@HashOptHMac** as an option.
The **HMAC** requires a secret key, in this case, "**secretKey**."
The **HashUpdate** function is then used to update the hash context
with the strings "Cat" and "Dog." Finally, HashFinal is
called to obtain the resulting hash value. The output, "**56FAFEECA6A4A191D893A4E0C34EBA828AC30F9D46D38CDECE6A15E949478DA4**,"
represents the **GOST** hash of the concatenated strings "Cat"
and "Dog" with the specified secret key. This demonstrates the usage
of **HMAC** for secure hash computations with a shared secret key.

Contact

Cheryl (uberfox@hotmail.com)

Homepage

http://ubersoft.org