Code Monkey home page Code Monkey logo

Comments (9)

indutny avatar indutny commented on August 20, 2024

@mrose17 Looking into it...

I could tell for sure that your public key thing is the same up to the curve modulus. For some reason curve25519 package does not mod it before returning to you.

Also curve25519 C module seems to amend the public key before using it, but it seems that even when uncommenting section in your example - it still differs.

from elliptic.

indutny avatar indutny commented on August 20, 2024

I wonder if it could be that Adam is using http://elligator.cr.yp.to/poster.pdf in his donna code.

from elliptic.

indutny avatar indutny commented on August 20, 2024

Ok, figured it out :) It does everything in reverse!

var elliptic   = require('./lib/elliptic.js')
  , ec         = new elliptic.ec('curve25519')
  , mysecret   = new Buffer('00843b75caa5bdb940f740b7d9262e2ae9937c946dca7b0d18617ff5a1a33f46', 'hex')
  , rev = new Buffer(32);


 mysecret[0] &= 248
 mysecret[31] &= 127
 mysecret[31] |= 64
for (var i = 0; i < 32; i++)
  rev[i] = mysecret[32 - i - 1];

var mykey      = ec.keyFromPrivate(rev)
  , yourpublic = new Buffer('97b22cf64c25ae2db61d07618ff291086feff2ae8779e57be59e988c33916b0f', 'hex')
  , yourkey    = ec.keyFromPublic(yourpublic)
  , shared     = mykey.derive(yourkey.getPublic())

console.log('               my private key ='+mykey.getPrivate('hex') + '\n')

console.log('    old pkg says my public key='+'200b85ac0e08d3fd0a0be90436765119037d30b7bff56f07cfab51ec1691837f')
// !!!!!!!!
// This one is reversed!
// !!!!!!!!
console.log('    new pkg says my public key='+mykey.getPublic('hex') + '\n')

console.log('  old pkg says your public key='+yourpublic.toString('hex'))
console.log('  new pkg says your public key='+yourkey.getPublic('hex') + '\n')

console.log('old pkg says the shared secret='+'91bae78939e897c5996417c77c5e3e19f82f4143acb34ef23848d3b6cc1f9930')
console.log('new pkg says the shared secret='+shared.toString(16))

from elliptic.

indutny avatar indutny commented on August 20, 2024

Thanks for sharing, though!

from elliptic.

mrose17 avatar mrose17 commented on August 20, 2024

thanks for looking into this. very odd. i was expecting something less esoteric. ok, so basically, the trick is to know when the flip the results for transmission to the other side (my public key) or use (derived shared secret). i've updated the gist above to reflect that.

https://gist.github.com/mrose17/36a9f5ada76bfab4b8bc

sorry for the confusion!

from elliptic.

indutny avatar indutny commented on August 20, 2024
/Users/indutny/Code/indutny/elliptic/2.js:26
curve25519.makeSecretKey(C_mysecret)
           ^
TypeError: Object #<Object> has no method 'makeSecretKey'
    at Object.<anonymous> (/Users/indutny/Code/indutny/elliptic/2.js:26:12)
    at Module._compile (module.js:456:26)
    at Object.Module._extensions..js (module.js:474:10)
    at Module.load (module.js:356:32)
    at Function.Module._load (module.js:312:12)
    at Function.Module.runMain (module.js:497:10)
    at startup (node.js:119:16)
    at node.js:929:3

from elliptic.

mrose17 avatar mrose17 commented on August 20, 2024

hmmm... just to confirm, we're talking about this package

https://github.com/thejh/node-curve25519

(or at least that's the one i'm talking about!)

from elliptic.

indutny avatar indutny commented on August 20, 2024

Yeah, it is just your gist that does not work :) May be you are using older version?

from elliptic.

mrose17 avatar mrose17 commented on August 20, 2024

sorry about that. here's what i did:

  1. (temporarily) add this dependency to package.json for elliptic:

        "curve25519": "git://github.com/thejh/node-curve25519.git"
    
  2. the usual npm -l install

  3. ran this gist: https://gist.github.com/mrose17/36a9f5ada76bfab4b8bc

maybe there is a version mismatch, but i'm not sure how i did that...

from elliptic.

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.