椭圆

快速椭圆-曲线密码学在平版javascript中被执行.
注:请看 http://safecurves.cr.yp.to/ (中文(简体) ) 在选择曲线前 你的密码操作.
奖励
ECC比普通的RSA密码要慢得多,JS的执行是: 更慢一点.
基准
$ node benchmarks/index.js
Benchmarking: sign
elliptic#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: verify
elliptic#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: gen
elliptic#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: ecdh
elliptic#ecdh x 136 ops/sec ±0.85% (156 runs sampled)
------------------------
Fastest is elliptic#ecdh
========================
API 密码
ECDSA 数据交换系统
var EC = require('elliptic').ec;
// Create and initialize EC context
// (better do it once and reuse it)
var ec = new EC('secp256k1');
// Generate keys
var key = ec.genKeyPair();
// Sign the message's hash (input must be an array, or a hex-string)
var msgHash = [ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 ];
var signature = key.sign(msgHash);
// Export DER encoded signature in Array
var derSign = signature.toDER();
// Verify signature
console.log(key.verify(msgHash, derSign));
// CHECK WITH NO PRIVATE KEY
var pubPoint = key.getPublic();
var x = pubPoint.getX();
var y = pubPoint.getY();
// Public Key MUST be either:
// 1) '04' + hex string of x + hex string of y; or
// 2) object with two hex string properties (x and y); or
// 3) object with two buffer properties (x and y)
var pub = pubPoint.encode('hex'); // case 1
var pub = { x: x.toString('hex'), y: y.toString('hex') }; // case 2
var pub = { x: x.toBuffer(), y: y.toBuffer() }; // case 3
var pub = { x: x.toArrayLike(Buffer), y: y.toArrayLike(Buffer) }; // case 3
// Import public key
var key = ec.keyFromPublic(pub, 'hex');
// Signature MUST be either:
// 1) DER-encoded signature as hex-string; or
// 2) DER-encoded signature as buffer; or
// 3) object with two hex-string properties (r and s); or
// 4) object with two buffer properties (r and s)
var signature = '3046022100...'; // case 1
var signature = new Buffer('...'); // case 2
var signature = { r: 'b1fc...', s: '9c42...' }; // case 3
// Verify signature
console.log(key.verify(msgHash, signature));
萨尔瓦多
var EdDSA = require('elliptic').eddsa;
// Create and initialize EdDSA context
// (better do it once and reuse it)
var ec = new EdDSA('ed25519');
// Create key pair from secret
var key = ec.keyFromSecret('693e3c...'); // hex string, array or Buffer
// Sign the message's hash (input must be an array, or a hex-string)
var msgHash = [ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 ];
var signature = key.sign(msgHash).toHex();
// Verify signature
console.log(key.verify(msgHash, signature));
// CHECK WITH NO PRIVATE KEY
// Import public key
var pub = '0a1af638...';
var key = ec.keyFromPublic(pub, 'hex');
// Verify signature
var signature = '70bed1...';
console.log(key.verify(msgHash, signature));
ECDH 人权委
var EC = require('elliptic').ec;
var ec = new EC('curve25519');
// Generate keys
var key1 = ec.genKeyPair();
var key2 = ec.genKeyPair();
var shared1 = key1.derive(key2.getPublic());
var shared2 = key2.derive(key1.getPublic());
console.log('Both shared secrets are BN instances');
console.log(shared1.toString(16));
console.log(shared2.toString(16));
三名及三名以上成员:
var EC = require('elliptic').ec;
var ec = new EC('curve25519');
var A = ec.genKeyPair();
var B = ec.genKeyPair();
var C = ec.genKeyPair();
var AB = A.getPublic().mul(B.getPrivate())
var BC = B.getPublic().mul(C.getPrivate())
var CA = C.getPublic().mul(A.getPrivate())
var ABC = AB.mul(C.getPrivate())
var BCA = BC.mul(A.getPrivate())
var CAB = CA.mul(B.getPrivate())
console.log(ABC.getX().toString(16))
console.log(BCA.getX().toString(16))
console.log(CAB.getX().toString(16))
注: .derive() 返回 a 比利时 举个例子.
支持的曲线
椭圆形.js 支持以下曲线类型 :
- 短网点
- 蒙哥马利
- 爱德华兹
- 扭曲了爱德华兹
以下曲线“ presets” 嵌入到库中 :
secp256k1p192p224p256p384p521curve25519ed25519
注: curve25519 无法用于 ECDSA, 使用 ed25519 换句话说.
执行详情
ECDSA正在使用决定论 k 按数值生成 RFC6979 (法语)大多数
曲线操作在非亚芬坐标上进行(投影)
不同情况使用各种窗口技术.
所有业务均在减少范围内使用 bn.js (中文(简体) ),散列是,这是 国家 hash.js (英语)
相关项目
自由主义
这个软件根据麻省理工学院的许可证获得许可.
版权由Fedor Indutny提供, 2014.
特此免费准许任何人获得 本软件和相关文档文件的复制件 “软件”,在软件中不受限制地处理,包括 不限制使用、复制、修改、合并、出版、, 软件的分发、分版和/或销售,并允许 提供软件的人 下列条件:
上述版权通知和本许可通知应当包括: 软件的所有副本或大部分.
软件被提供"AS IS", 没有任何恐惧, EXPRESS ,包括但不局限于 紧迫性,特别是目的和非目的的证明。 内 对于任何索赔, 都不得使用任何连锁电话或警察电话, 转让或其他责任,以契约、条约或 产生于、出自或与溶剂有关的 在软件中使用或其他交易.