Skip to content

fix(ecdsa): correct unescape error in ECDSA Sign and Verify op #2076

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions src/core/operations/ECDSASign.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

import Operation from "../Operation.mjs";
import OperationError from "../errors/OperationError.mjs";
import { fromHex } from "../lib/Hex.mjs";
import { fromHex, toHexFast } from "../lib/Hex.mjs";
import { toBase64 } from "../lib/Base64.mjs";
import r from "jsrsasign";

Expand All @@ -25,7 +25,7 @@ class ECDSASign extends Operation {
this.module = "Ciphers";
this.description = "Sign a plaintext message with a PEM encoded EC key.";
this.infoURL = "https://wikipedia.org/wiki/Elliptic_Curve_Digital_Signature_Algorithm";
this.inputType = "string";
this.inputType = "ArrayBuffer";
this.outputType = "string";
this.args = [
{
Expand Down Expand Up @@ -58,7 +58,7 @@ class ECDSASign extends Operation {
}

/**
* @param {string} input
* @param {ArrayBuffer} input
* @param {Object[]} args
* @returns {string}
*/
Expand All @@ -79,7 +79,7 @@ class ECDSASign extends Operation {
throw new OperationError("Provided key is not a private key.");
}
sig.init(key);
const signatureASN1Hex = sig.signString(input);
const signatureASN1Hex = sig.signHex(toHexFast(new Uint8Array(input)));

let result;
switch (outputFormat) {
Expand Down
4 changes: 2 additions & 2 deletions src/core/operations/ECDSAVerify.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -151,8 +151,8 @@ class ECDSAVerify extends Operation {
throw new OperationError("Provided key is not a public key.");
}
sig.init(key);
const messageStr = Utils.convertToByteString(msg, msgFormat);
sig.updateString(messageStr);
const messageByteArray = Utils.convertToByteArray(msg, msgFormat);
sig.updateHex(toHexFast(messageByteArray));
const result = sig.verify(signatureASN1Hex);
return result ? "Verified OK" : "Verification Failure";
}
Expand Down
Loading