BLAKE and BLAKE2 are hash functions based on the ChaCha stream cipher, and was one of the finalists in the NIST competition for SHA-3 [article].
Blake |
Test vectors
The following are test vectors for Blake Version 1:
BLAKE-512("") = A8CFBBD73726062DF0C6864DDA65DEFE58EF0CC52A5625090FA17601E1EECD1B 628E94F396AE402A00ACC9EAB77B4D4C2E852AAAA25A636D80AF3FC7913EF5B8 BLAKE-512("The quick brown fox jumps over the lazy dog") = 1F7E26F63B6AD25A0896FD978FD050A1766391D2FD0471A77AFB975E5034B7AD 2D9CCF8DFB47ABBBE656E1B82FBC634BA42CE186E8DC5E1CE09A885D41F43451
And for Version 2:
BLAKE2b-512("") = 786A02F742015903C6C6FD852552D272912F4740E15847618A86E217F71F5419 D25E1031AFEE585313896444934EB04B903A685B1448B755D56F701AFE9BE2CE BLAKE2b-512("The quick brown fox jumps over the lazy dog") = A8ADD4BDDDFD93E4877D2746E62817B116364A1FA7BC148D95090BC7333B3673 F82401CF7AA2E4CB1ECD90296E3F14CB5413F8ED77BE73045B13914CDCD6A918
Code
The following is an outline of Blake 2. For Blake 2 we define a digest size in bytes. For a 224-bit hash we have 224/8 bytes which is 28 bytes:
from pyblake2 import blake2b from blake import BLAKE data="" print(('Input:',data)) print('-----Blake Version 1 ---------') print('Blake 224-bit:', BLAKE(224).hexdigest(data)) print('Blake 256-bit:', BLAKE(256).hexdigest(data)) print('Blake 384-bit:', BLAKE(384).hexdigest(data)) print('Blake 512-bit:', BLAKE(512).hexdigest(data)) print('\n-----Blake Version 2 ---------') h = blake2b(digest_size=28) h.update(data.encode()) print('Blake 2 224-bit:',h.hexdigest()) h = blake2b(digest_size=32) h.update(data.encode()) print('Blake 2 256-bit:',h.hexdigest()) h = blake2b(digest_size=48) h.update(data.encode()) print('Blake 2 384-bit:',h.hexdigest()) h = blake2b(digest_size=64) h.update(data.encode())