GithubHelp home page GithubHelp logo

Comments (8)

sneves avatar sneves commented on June 3, 2024

Yes, that is strange and should not happen. Do you have a reproducible case?

from blake2.

hajes avatar hajes commented on June 3, 2024

In Python I used following and it always failed:

BLOCKSIZE = os.statvfs(os.getcwd()).f_bsize # determine optimal/prefered block size of file system

with open(f, 'rb') as afile:
buf = afile.read(BLOCKSIZE)
chk.update(buf)
l[f] = chk.hexdigest()
afile.close()

It automatically detects file system block size...my Apple SSD has got 1MB whereas external HDD has got 65kB for example. Unless, both blocksizes are not equal there is problem as confirmed by using official b2sum.

Ever since I use fixed blocksize all seems to be ok until I used b2sum. I noticed in b2sum source code there is buffer size of 37kB or so.

Hard to say what happen if you play with buffer/blocksize on different OS

Of course it may be some multiOS issue as well !

Blake2 is not official under macOS and it has been installed by brew install coreutils

Python Blake2 implementation is considered as extra compared to core hash functions. Various Python OS implantation give different names fro Blake2, which should be no issue.

from blake2.

sneves avatar sneves commented on June 3, 2024

I'm not sure how to reproduce this. Does the following script fail for you? (Feel free to adjust parameters or sizes as you please)

from hashlib import blake2b
import os

MAX_LEN = 1234
DATA = os.urandom(MAX_LEN)

reference = blake2b(DATA).digest()

for step in range(1,MAX_LEN):
  obj2 = blake2b()
  for chunk in [DATA[i:i+step] for i in range(0, len(DATA), step)]:
    obj2.update(chunk)
  assert(obj2.digest() == reference)

print("ok")

from blake2.

hajes avatar hajes commented on June 3, 2024

your script prints ok

where I use it is as following:

  • read list of files inside source directory (usually on CF card from camera)
  • create hash for each file as shown in function above by [still in source path]
  • copy files to destination (usually SSD)
  • create checksum fo copied files [destination path]
  • compare checksum created in source and destination

In other words if I create checksum of file in source with read blocksize 1MB and check the very same file in destination path but read blocksize different than 1MB - checksum fails.

from blake2.

sneves avatar sneves commented on June 3, 2024
BLOCKSIZE = os.statvfs(os.getcwd()).f_bsize	# determine optimal/prefered block size of file system

with open(f, 'rb') as afile:
  buf = afile.read(BLOCKSIZE)
  chk.update(buf)
l[f] = chk.hexdigest()
afile.close()

I assume this is the correct indentation? If so, aren't you just reading the first BLOCKSIZE bytes of the file?

from blake2.

hajes avatar hajes commented on June 3, 2024

Last two lines false indentation, it suppose to be in cycle as above by.

I have no idea, I used this code from some guy on internet. It suppose to read file by chunks defined by blocksize. If you don't specify blocksize/buffer it reads whole file into memory...I often copy larger files than my 16GB RAM.

https://docs.python.org/3.4/library/io.html?highlight=io#io.BufferedIOBase.read

from blake2.

sneves avatar sneves commented on June 3, 2024

To hash the entire file, you have to do something like

with open(f, 'rb') as fd:
  chk = blake2b()
  while True:
    chunk = fd.read(BLOCKSIZE)
    if not chunk:
      break
    chk.update(chunk)
print(chk.hexdigest())

So I don't think blake2 is the problem here.

from blake2.

hajes avatar hajes commented on June 3, 2024

thanks for info, I will try.

from blake2.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.