From 92cc475e05d14e983c64bc74446718b088a2a95e Mon Sep 17 00:00:00 2001 From: Nir Berman Date: Mon, 29 Jan 2024 12:22:44 +0200 Subject: [PATCH] Added NO-HASH option for ECDSA, for cases the data is already hashed --- src/mechs/ec/crypto.ts | 3 +++ src/mechs/ec/ec_dsa.ts | 3 +++ 2 files changed, 6 insertions(+) diff --git a/src/mechs/ec/crypto.ts b/src/mechs/ec/crypto.ts index e1e5341..9972eb1 100644 --- a/src/mechs/ec/crypto.ts +++ b/src/mechs/ec/crypto.ts @@ -156,6 +156,9 @@ export class EcCrypto implements types.IContainer { } public prepareData(hashAlgorithm: string, data: Buffer): Buffer { + if (hashAlgorithm === "NO-HASH") { + return utils.prepareData(data) + } else { // use nodejs crypto for digest calculating return utils.digest(hashAlgorithm.replace("-", ""), data); } diff --git a/src/mechs/ec/ec_dsa.ts b/src/mechs/ec/ec_dsa.ts index 6a42c6d..366f30a 100644 --- a/src/mechs/ec/ec_dsa.ts +++ b/src/mechs/ec/ec_dsa.ts @@ -116,6 +116,9 @@ export class EcdsaProvider extends core.EcdsaProvider implements types.IContaine case "SHA-512": algName = "ECDSA_SHA512"; break; + case "NO-HASH": + algName = "ECDSA"; + break; default: throw new core.OperationError(`Cannot create PKCS11 mechanism from algorithm '${hashAlg}'`); }