Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added hash function description #11

Merged
merged 2 commits into from Sep 27, 2018
Merged

Added hash function description #11

merged 2 commits into from Sep 27, 2018

Conversation

hwwhww
Copy link
Contributor

@hwwhww hwwhww commented Sep 26, 2018

  • Added a section for hash function description.
  • Not sure where is good to put it... so I add Appendix section currently, it can be changed.

Copy link
Contributor

@terencechain terencechain left a comment

LGTM!

Copy link
Contributor

@mratsim mratsim left a comment

LGTM, with small typo.

One thing of note. The Blake2 function is defined like so:

        FUNCTION BLAKE2( d[0..dd-1], ll, kk, nn )
        |
        |     h[0..7] := IV[0..7]          // Initialization Vector.
        |
        |     // Parameter block p[0]
        |     h[0] := h[0] ^ 0x01010000 ^ (kk << 8) ^ nn
        |
        |     // Process padded key and data blocks
        |     IF dd > 1 THEN
        |     |       FOR i = 0 TO dd - 2 DO
        |     |       |       h := F( h, d[i], (i + 1) * bb, FALSE )
        |     |       END FOR.
        |     END IF.
        |
        |     // Final block.
        |     IF kk = 0 THEN
        |     |       h := F( h, d[dd - 1], ll, TRUE )
        |     ELSE
        |     |       h := F( h, d[dd - 1], ll + bb, TRUE )
        |     END IF.
        |
        |     RETURN first "nn" bytes from little-endian word array h[].
        |
        END FUNCTION.

So we're completely in line with the Blake2 author intentions ("RETURN first "nn" bytes from little-endian word array h[].") and this is called blake2b256

        Algorithm     | Target | Collision | Hash | Hash ASN.1 |
           Identifier |  Arch  |  Security |  nn  | OID Suffix |
       ---------------+--------+-----------+------+------------+
        id-blake2b160 | 64-bit |   2**80   |  20  |   x.1.5    |
        id-blake2b256 | 64-bit |   2**128  |  32  |   x.1.8    |
        id-blake2b384 | 64-bit |   2**192  |  48  |   x.1.12   |
        id-blake2b512 | 64-bit |   2**256  |  64  |   x.1.16   |

## Appendix A - Hash function
The general hash function `hash(x)` in this specification is defined as:

`hash(x) := BLAKE2b(x)[0:32]`, where `BLAKE2b` algorithm is deifned in [RFC7693](https://tools.ietf.org/html/rfc7693) and input `x` is bytes type.
Copy link
Contributor

@mratsim mratsim Sep 27, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

defined

Copy link
Contributor Author

@hwwhww hwwhww Sep 27, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the catch!

@hwwhww
Copy link
Contributor Author

hwwhww commented Sep 27, 2018

@terenc3t @mratsim thanks for the reviews! I updated a bit. 🙂

@djrtwo
Copy link
Contributor

djrtwo commented Sep 27, 2018

lgtm!

@djrtwo djrtwo merged commit 5cfa735 into ethereum:master Sep 27, 2018
hwwhww pushed a commit that referenced this pull request Jul 23, 2020
Co-authored-by: Alex Beregszaszi <alex@rtfs.hu>
hwwhww pushed a commit that referenced this pull request Jul 23, 2020
Co-authored-by: Alex Beregszaszi <alex@rtfs.hu>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants