kovacs-levent / Blake3-Python

This repository contains the source code for our Applied Cryptography Project Seminar class project at Eötvös Loránd University (ELTE). Our project is a native python implementation of the BLAKE3 hashing algorithm.
1 stars 2 forks source link

Create one-call hash function #8

Closed kovacs-levent closed 3 years ago

kovacs-levent commented 4 years ago

Given all components, we should implement a function which produces the BLAKE3 hash of a given input, callable somehow like this:

import blake3

input="hash input" hash = blake3.hash(input)

Encoding of the data is not specified at this point, get back to me with this when the time comes.

kovacs-levent commented 4 years ago

Also, the function names are not set to stone, I'll modify the issue when we have more info on how to implement this.

kovacs-levent commented 3 years ago

I'm kinda having a two-call hash at this point. You have to feed the hash input by calling the update() function on the hash and then the finalize() function essentially collects the hash output from the constructed chunk state.

It is certainly possible to make a func hash(), which could get the input and then output the hash instantly without calling finalize().

However, the state is stored in the hasher class and is updated with the update() function. It's a key function for the hash construction and if the chunk state is updated through both hash() and update() the results could be confusing (if someone uses update() on the hash beforehand, but afterwards calls hash() should the previously updated state be kept, or discarded?

I think the hash() function should always start with a clean state, because it's supposed to hash the input provided without any previous updates on the hash. A new class which uses the class blake3 and has the hash() function is a better solution rather than adding hash() to the blake3 class. Then this class constructs a new state every time the hash is called. This would be a cleanest solution to this problem I think.

kovacs-levent commented 3 years ago

The hash can be called by supplying the input and the wanted length. The length defaults to 64 bytes if not given, this needs to be changed to 32 because that's the minimal output size, not 64.