mirror of
https://github.com/Xahau/xahau.js.git
synced 2025-11-29 16:45:49 +00:00
JS: Crypto: Fix ECDSA DER signature encoding.
This commit is contained in:
@@ -5,12 +5,18 @@ sjcl.ecc.ecdsa.secretKey.prototype.signDER = function(hash, paranoia) {
|
|||||||
sjcl.ecc.ecdsa.secretKey.prototype.encodeDER = function(rs) {
|
sjcl.ecc.ecdsa.secretKey.prototype.encodeDER = function(rs) {
|
||||||
var w = sjcl.bitArray,
|
var w = sjcl.bitArray,
|
||||||
R = this._curve.r,
|
R = this._curve.r,
|
||||||
l = R.bitLength(),
|
l = R.bitLength();
|
||||||
r = sjcl.bn.fromBits(w.bitSlice(rs,0,l)).toBits(),
|
|
||||||
s = sjcl.bn.fromBits(w.bitSlice(rs,l,2*l)).toBits();
|
|
||||||
|
|
||||||
var rb = sjcl.codec.bytes.fromBits(r),
|
var rb = sjcl.codec.bytes.fromBits(w.bitSlice(rs,0,l)),
|
||||||
sb = sjcl.codec.bytes.fromBits(s);
|
sb = sjcl.codec.bytes.fromBits(w.bitSlice(rs,l,2*l));
|
||||||
|
|
||||||
|
// Drop empty leading bytes
|
||||||
|
while (!rb[0] && rb.length) rb.shift();
|
||||||
|
while (!sb[0] && sb.length) sb.shift();
|
||||||
|
|
||||||
|
// If high bit is set, prepend an extra zero byte (DER signed integer)
|
||||||
|
if (rb[0] & 0x80) rb.unshift(0);
|
||||||
|
if (sb[0] & 0x80) sb.unshift(0);
|
||||||
|
|
||||||
var buffer = [].concat(
|
var buffer = [].concat(
|
||||||
0x30,
|
0x30,
|
||||||
|
|||||||
Reference in New Issue
Block a user