NOTE: Please take a look at http://safecurves.cr.yp.to/ before choosing a curve for your cryptography operations.
ECC is much slower than regular RSA cryptography, the JS implementations are even more slower.
$ node benchmarks/index.jsBenchmarking: signelliptic#sign x 262 ops/sec ±0.51% (177 runs sampled)eccjs#sign x 55.91 ops/sec ±0.90% (144 runs sampled)------------------------Fastest is elliptic#sign========================Benchmarking: verifyelliptic#verify x 113 ops/sec ±0.50% (166 runs sampled)eccjs#verify x 48.56 ops/sec ±0.36% (125 runs sampled)------------------------Fastest is elliptic#verify========================Benchmarking: genelliptic#gen x 294 ops/sec ±0.43% (176 runs sampled)eccjs#gen x 62.25 ops/sec ±0.63% (129 runs sampled)------------------------Fastest is elliptic#gen========================Benchmarking: ecdhelliptic#ecdh x 136 ops/sec ±0.85% (156 runs sampled)------------------------Fastest is elliptic#ecdh========================
var EC = ec;// Create and initialize EC context// (better do it once and reuse it)var ec = 'secp256k1';// Generate keysvar key = ec;// Sign message (must be an array, or it'll be treated as a hex sequence)var msg = 0 1 2 3 4 5 6 7 8 9 10 ;var signature = key;// Export DER encoded signature in Arrayvar derSign = signature;// Verify signatureconsole;// CHECK WITH NO PRIVATE KEY// Public key as '04 + x + y'var pub = '04bb1fa3...';// Signature MUST be either:// 1) hex-string of DER-encoded signature; or// 2) DER-encoded signature as buffer; or// 3) object with two hex-string properties (r and s)var signature = 'b102ac...'; // case 1var signature = '...'; // case 2var signature = r: 'b1fc...' s: '9c42...' ; // case 3// Import public keyvar key = ec;// Verify signatureconsole;
var EdDSA = eddsa;// Create and initialize EdDSA context// (better do it once and reuse it)var ec = 'ed25519';// Create key pair from secretvar key = ec; // hex string, array or Buffer// Sign message (must be an array, or it'll be treated as a hex sequence)var msg = 0 1 2 3 4 5 6 7 8 9 10 ;var signature = key;// Verify signatureconsole;// CHECK WITH NO PRIVATE KEY// Import public keyvar pub = '0a1af638...';var key = ec;// Verify signaturevar signature = '70bed1...';console;
var EC = ec;var ec = 'curve25519';// Generate keysvar key1 = ec;var key2 = ec;var shared1 = key1;var shared2 = key2;console;console;console;
three and more members:
var EC = ec;var ec = 'curve25519';var A = ec;var B = ec;var C = ec;var AB = Avar BC = Bvar CA = Cvar ABC = ABvar BCA = BCvar CAB = CAconsoleconsoleconsole
.derive() returns a BN instance.
Elliptic.js support following curve types:
Following curve 'presets' are embedded into the library:
curve25519 could not be used for ECDSA, use
ECDSA is using deterministic
k value generation as per RFC6979. Most of
the curve operations are performed on non-affine coordinates (either projective
or extended), various windowing techniques are used for different cases.
ellipticfor browser and secp256k1-node for node)
This software is licensed under the MIT License.
Copyright Fedor Indutny, 2014.
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.