Git Product home page Git Product logo

blake2's People

Contributors

codahale avatar kr avatar tv42 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

blake2's Issues

Sum changes internal state

It looks like digest.Sum modifies its internal state:

https://github.com/codahale/blake2/blob/3fa823583a/blake2b.go#L153

C.blake2b_final(d.state, (*C.uint8_t)(&digest[0]), C.uint8_t(d.Size()))

The contract for hash.Hash.Sum prohibits this:

https://godoc.org/hash#Hash.Sum

Sum appends the current hash to b and returns the resulting slice.
It does not change the underlying hash state.

The user should be able to get the sum, then continue writing, then get another sum, etc. Other crypto hash implementations with this problem (where computing the sum is destructive) conform to this requirement by copying the internal state before summing. For example,

https://github.com/golang/go/blob/53c92f95a8/src/crypto/sha256/sha256.go#L129-L130

and

https://github.com/golang/crypto/blob/aedad9a179/sha3/sha3.go#L187-L189

The allocation is unfortunate, but necessary.

I'm pretty sure this could be fixed the same way in this package. Looks like blake2b_state has no internal pointers so it should be safe to copy. Maybe like:

unc (d *digest) Sum(buf []byte) []byte {
    digest := make([]byte, d.Size())
    // Make a copy of d.state so that caller can keep writing and summing.
    s := *d.state
    C.blake2b_final(&s, (*C.uint8_t)(&digest[0]), C.uint8_t(d.Size()))
    return append(buf, digest...)
}

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.