Skip to content

Commit e3ecdd4

Browse files
committed
fix(ecdsa): correct unescape error in ECDSA Sign and ECDSA Verify op
1 parent c57556f commit e3ecdd4

File tree

2 files changed

+6
-6
lines changed

2 files changed

+6
-6
lines changed

src/core/operations/ECDSASign.mjs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
import Operation from "../Operation.mjs";
88
import OperationError from "../errors/OperationError.mjs";
9-
import { fromHex } from "../lib/Hex.mjs";
9+
import { fromHex, toHexFast } from "../lib/Hex.mjs";
1010
import { toBase64 } from "../lib/Base64.mjs";
1111
import r from "jsrsasign";
1212

@@ -25,7 +25,7 @@ class ECDSASign extends Operation {
2525
this.module = "Ciphers";
2626
this.description = "Sign a plaintext message with a PEM encoded EC key.";
2727
this.infoURL = "https://wikipedia.org/wiki/Elliptic_Curve_Digital_Signature_Algorithm";
28-
this.inputType = "string";
28+
this.inputType = "ArrayBuffer";
2929
this.outputType = "string";
3030
this.args = [
3131
{
@@ -58,7 +58,7 @@ class ECDSASign extends Operation {
5858
}
5959

6060
/**
61-
* @param {string} input
61+
* @param {ArrayBuffer} input
6262
* @param {Object[]} args
6363
* @returns {string}
6464
*/
@@ -79,7 +79,7 @@ class ECDSASign extends Operation {
7979
throw new OperationError("Provided key is not a private key.");
8080
}
8181
sig.init(key);
82-
const signatureASN1Hex = sig.signString(input);
82+
const signatureASN1Hex = sig.signHex(toHexFast(new Uint8Array(input)));
8383

8484
let result;
8585
switch (outputFormat) {

src/core/operations/ECDSAVerify.mjs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -151,8 +151,8 @@ class ECDSAVerify extends Operation {
151151
throw new OperationError("Provided key is not a public key.");
152152
}
153153
sig.init(key);
154-
const messageStr = Utils.convertToByteString(msg, msgFormat);
155-
sig.updateString(messageStr);
154+
const messageByteArray = Utils.convertToByteArray(msg, msgFormat);
155+
sig.updateHex(toHexFast(messageByteArray));
156156
const result = sig.verify(signatureASN1Hex);
157157
return result ? "Verified OK" : "Verification Failure";
158158
}

0 commit comments

Comments
 (0)