Hash$Hash

HashLib ››
Parent Previous Next

HASH$Hash


Returns the hash of a string, according to the specified hash algorithm.


Format

HASH$Hash index, source, target, key, resultlength


Arguments

index

Pointer to a 32-bit integer value that indicates the hash algorithm to use. This must match an installed algorithm. The following hash algorithms are provided with UOS by default.


Mnuemonic

Description

Hash_Plaintext

No hashing is done. The service returns the passed string, unaltered.



Secure hashes        

Hash_MD5

MD5 hash

Hash_SHA1

Original SHA hash

Hash_SHA224

224 bit SHA hash

Hash_SHA256

256 bit SHA hash

Hash_SHA384

384 bit SHA hash

Hash_SHA512

512 bit SHA hash

Hash_HMAC_MD5

MD5 keyed hash

Hash_HMAC_SHA1

SHA keyed hash

Hash_HMAC_SHA256

256 bit SHA keyed hash

Hash_HMAC_SHA512

512 bit SHA keyed hash


Error checking hashes        

Hash_Checksum

32 bit checksum

Hash_XOR8

8 bit XOR hash

Hash_XOR16

16 bit XOR hash

Hash_XOR32

32 bit XOR hash

Hash_CRC16

16 bit Cyclic Redundancy Check

Hash_CRC32

32 bit Cyclic Redundancy Check

Hash_Adler32

32 bit Adler hash

       

Hashtable hashes        

Hash_ELF

ELF hash

Hash_Knuth

Donald Knuth hash


Note: when security is needed, only Hash_SHA384, Hash_SHA512, or Hash_HMAC_SHA512 should be used. Other "secure" hashes are not considered to be strong enough to secure passwords.


source

A pointer to an SRB which points to the data string to hash.


target

A pointer to an SRB which points to the buffer to receive the hashed data. The buffer should be large enough to contain the resulting hash.


key

A pointer to an SRB which contains a key to use for keyed hashes. This is ignored if a non-keyed hash is specified.


resultlength

A pointer to where a 32-bit integer value can be written. The value written indicates the number of bytes written to the target buffer. If the data is truncated due to the buffer being too small to receive all of the data, UOSErr_Buffer_Overflow is returned by the service and the value written to this location will be the size of the data actually written (the receiving buffer size).


Description

This service returns a hashed value of the passed data. In the case of Hash_Plaintext, the service returns a copy of the passed string. If the calling code does not know the result size of the hash, it should check the resulting length; if the result length is equal to the receiving buffer size, the receiving buffer should be increased and the hash attempted again. This should be repeated until the result length is less than the receiving buffer size, which will guarantee that the entire hash is returned. Note that the above hash sizes indicate the number of bits in the result.


Condition Values Returned

Value

Meaning

SS_NORMAL

Normal completion

HASHLIB_Invalid_Hash

The specified hash index did not match an installed hash algorithm.

HASHLIB_No_Data

Either or both of the source and target buffers was not provided.

UOSErr_Buffer_Overflow

The receive buffer was too small to contain the entire hash value.