GithubHelp home page GithubHelp logo

holepunchto / hypercore-crypto Goto Github PK

View Code? Open in Web Editor NEW
35.0 35.0 14.0 33 KB

The crypto primitives used in hypercore, extracted into a separate module

License: MIT License

JavaScript 100.00%

hypercore-crypto's People

Contributors

andrewosh avatar chm-diederichs avatar kasperisager avatar mafintosh 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

Watchers

 avatar  avatar  avatar  avatar

hypercore-crypto's Issues

browser: buf.writeUInt32BE is not a function

Hey,

Today we update hypercore-crypto and it seems that b4a is missing some buffer operations for the browser, one of them is writeUInt32BE and it breaks the encodeUInt64 of hypercore-crypto.

index.js?fc28:14 Uncaught (in promise) TypeError: buf.writeUInt32BE is not a function
    at Object.exports.encode (index.js?fc28:14)
    at encodeUInt64 (index.js?4681:184)
    at Object.exports.data (index.js?4681:104)
    at MerkleGenerator.exports.leaf [as _leaf] (index.js?4681:112)
    at MerkleGenerator.next (generator.js?b45a:37)
    at Feed._append (index.js?d11e:1500)
    at work (index.js?d11e:158)
    at Feed.append [as _batch] (index.js?3518:44)
    at Feed.append (index.js?d11e:1404)
    at eval (index.js?44d0:106)

crypto.discoveryKey seems to have the arguments in the wrong order

sodium.crypto_generichash expects an input buffer of arbitrary length and an optional key. According to sodium docs the input is hashed, and the optional key "can be used to make sure that different applications generate different fingerprints even if they process the same data." and different keys "are very likely to produce distinct fingerprints". This "very likely" seems to suggest that this is not as reliable as a hash.

The sodium-native docs say the input is the second arg, and key is the third arg, however discoveryKey seems to call the arguments in the wrong order:

exports.discoveryKey = function (tree) {
  var digest = bufferAlloc(32)
  sodium.crypto_generichash(digest, HYPERCORE, tree)
  return digest
}

As far as I understand, HYPERCORE should be the key. I understand from #3 that tree is actually the publicKey. The consequence of this (I think, although I don't know the internals of sodium) is that the hash is not as guaranteed against collisions. It may be that this doesn't matter and changing the key is being hashed with the same algorithm as the input, but it doesn't seem like this was the intended way for this to work.

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.