Giter Club home page Giter Club logo

curve255js's Introduction

curve255js

Javascript implementation of the Curve25519 elliptic cryptography function by Daniel J. Bernstein.

Synopsis:

var my_public_key = curve25519(my_secret);
var shared_secret = curve25519(my_secret, public_key);

As in curve25519-donna, some bits in the private key are altered to harden the operation of the function. If you need the private key to be unmodified for your protocol, use curve25519_raw(private_key, public_key).

Private and public keys are represented by arrays of 16-bit values, starting from the least significant ones:

key = arr[0] + arr[1] × 2^16 + arr[2] × 2^32 + … + arr[15] × 2^(16 × 15)

Please note that, while the main function is free of conditional branching, its actual constant-time operation is dependent on the Javascript implementation of numerical operations being also constant-time.

Testing

For consistency and conformance testing, you can run the script test-curve25519.coffee under tests/

The output should be identical to test-curve25519.c from the reference implementation: http://cr.yp.to/ecdh/curve25519-20050915.tar.gz

Contributors

Among the contributors, in no particular order:

Graydon Hoare: suggested clamping the private key by default for increased safety and uniformity with other implementations.

liliakai: spotted an unused argument in some of the functions

RyanC: removed dependency of a function to the Javascript Math library

Guy Kloss: performance improvements through bit-shift operations

maxrmp: reported about the support of full 256-bit public keys

If you are one of the contributors and want to add yourself or change the information here, please do submit a pull request.

Copyright and MIT licensing

Copyright (c) 2007, 2013, 2014 Michele Bini

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

curve255js's People

Contributors

rev22 avatar ryancdotorg 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

Watchers

 avatar  avatar  avatar

curve255js's Issues

Question: cannot match public key with that from Whisper and Donna

As an example, I use the private key

a0e7cb1a31ef588cf7c0a7d537a1a02d72d47667a7964f1d8e35f904e95f3d65 (hex)

With the Whisper implementation (curve25519-java at https://github.com/WhisperSystems/curve25519-java) and the Donna implementation (https://github.com/agl/curve25519-donna) of Curve 25519 I get the same result when computing the corresponding public key. The result (public key) is:

8b61c39e39eed90fc4c1cec39a4bea0db61dfbaa3753c1cd38df8a570a67a241 (hex)

However, I am unable to reproduce this result with curve255.js. I am a beginner at JavaScript. Here is the JavaScript code I thought would reproduce the results of Whisper and Donna implementations:

var privHex = "a0e7cb1a31ef588cf7c0a7d537a1a02d72d47667a7964f1d8e35f904e95f3d65";
var priv = c255lhexdecode(privHex);
var pub = curve25519(priv);
var pubHex = c255lhexencode(pub);
console.log("pubHex: " + pubHex);

The output I get is

pubHex: 04a4b47444f345546698dcfc885a3f087ac979f53a1eb7fc55e9164105f37c13

Not the expected 8b61.. How come? I am probably doing something wrong? I tried several variants of the above with no success.

Verifying?

Is it possible to verify with this library also?

something like verify(signature, message, publicKey);

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.