• R/O
  • HTTP
  • SSH
  • HTTPS

mhash384: Commit

MHash-384 development repository


Commit MetaInfo

Revision3e429553338da6e8da0c132f649fd1ddb586c4ff (tree)
Time2020-04-27 00:43:53
AuthorLoRd_MuldeR <mulder2@gmx....>
CommiterLoRd_MuldeR

Log Message

Updated README file.

Change Summary

Incremental Difference

--- a/README.md
+++ b/README.md
@@ -517,6 +517,98 @@ Just follow the basic **MSYS2** setup procedure, as described on the [official w
517517
518518 pacman -S base-devel mingw-w64-i686-toolchain mingw-w64-x86_64-toolchain
519519
520+# Algorithm Description
521+
522+This section contains a *pseudo-code* description of the **MHash-384** algorithm:
523+
524+## Constants
525+
526+Pre-defined constants for MHash-384 computation:
527+
528+ const
529+ MHASH384_SIZE := 48 /*size of the hash, in bytes*/
530+ MHASH384_WORDS := 6 /*size of the hash, in 64-Bit words*/
531+ MHASH384_INI: array[0..MHASH384_WORDS-1] of UInt64 /*the initial state vector*/
532+ MHASH384_FIN: array[0..MHASH384_WORDS-1] of UInt64 /*byte indices for the finalization routine*/
533+ MHASH384_XOR: array[0..256, 0..MHASH384_WORDS-1] of UInt64 /*LUT for XOR (exclusive or) constants*/
534+ MHASH384_ADD: array[0..256, 0..MHASH384_WORDS-1] of UInt64 /*LUT for ADD (arithmetic addition) constants*/
535+ MHASH384_MIX: array[0..255, 0..MHASH384_WORDS-1] of Byte /*LUT containing the "mixing" indices*/
536+
537+***Note:*** The lookup tables **`MHASH384_XOR`** and **`MHASH384_ADD`** have been pre-computed in such a way that each of the 257 rows (each with a size of 48 Bytes) has a [hamming distance](https://en.wikipedia.org/wiki/Hamming_distance) of *at least* 182 bits to *any* other row. This ensures that, for each possible value an input byte can take, a *different* set of state bits will be "flipped" by the XOR (exclusive or) operation.
538+
539+## State
540+
541+The state of an ongoing MHash-384 computation:
542+
543+ type MHash384State = record
544+ rnd: UInt8
545+ hash: array[0..MHASH384_WORDS-1] of UInt64
546+
547+## Initialization
548+
549+Set up the MHash-384 state for a new hash computation:
550+
551+ procedure MHash384_Initialize
552+ state.rnd ← 0
553+ state.hash ← MHASH384_INI
554+
555+## Update Routine
556+
557+Update the MHash-384 state with the next *N* input (message) bytes:
558+
559+ procedure MHash384_Update
560+ input:
561+ message: array[0..N-1] of Byte
562+ for each Byte b in message do
563+ _MHash364_Iterate(MHASH384_XOR[b], MHASH384_ADD[b], MHASH384_MIX[rnd])
564+ state.rnd ← (state.rnd + 1) mod 256
565+
566+***Note:*** This routine can be invoked multiple times in order to process in the input message in "chunks" of arbitrary size.
567+
568+## Finalization Routine
569+
570+Compute the final hash value (digest), once all input has been processed:
571+
572+ procedure MHash384_Update
573+ var:
574+ previous: UInt16
575+ output:
576+ digest: array[0..MHASH384_SIZE-1] of Byte
577+ previous ← 256;
578+ for i = 0 to HASH384_SIZE-1 do
579+ _MHash364_Iterate(MHASH384_XOR[previous], MHASH384_ADD[previous], MHASH384_MIX[rnd])
580+ state.rnd ← (state.rnd + 1) mod 256
581+ previous ← (digest[i] ← _MHash384_GetByte(MHASH384_FIN[i]))
582+
583+## Iteration Routine
584+
585+Internal processing routine, used by the "update" and "finalization" routines:
586+
587+ procedure _MHash364_Iterate
588+ var:
589+ temp: array[0..MHASH384_WORDS-1] of UInt64
590+ input:
591+ xor_row: array[0..MHASH384_WORDS-1] of UInt64
592+ add_row: array[0..MHASH384_WORDS-1] of UInt64
593+ mix_row: array[0..MHASH384_WORDS-1] of Byte
594+ for i = 0 to HASH384_WORDS-1 do
595+ temp[i] ← Hash128to64(state.hash[i] + add_row[i], state.hash[mix_row[i]]) ⊻ xor_row[i]
596+ state.hash ← temp
597+
598+***Note:*** Here the **`⊻`** symbol denotes bit-wise *XOR* (exclusive or) operator. Furthermore, the **`Hash128to64()`** routine is adopted from the function of the same name that appears in Google's *CityHash*. Please see [here](https://github.com/google/cityhash/blob/master/src/city.h) for details!
599+
600+## Extract Byte
601+
602+Internal routine to extract a specific byte from the current state:
603+
604+ procedure _MHash384_GetByte
605+ input:
606+ index: Byte
607+ output:
608+ value: Byte
609+ value ← (state.hash[index ÷ 8] ≫ ((index mod 8) × 8)) mod 256
610+
611+***Note:*** Here the **`÷`** symbol denotes *integer division*, i.e. an arithmetic division in which the fractional part (remainder) is discarded. Furthermore, the **`≫`** symbol denotes the bit-wise *"right shift"* operator (shift bits to the right by **n** places).
520612
521613 # License
522614
Show on old repository browser