import * as asn1js from "asn1js"; import * as pvutils from "pvutils"; import { AlgorithmIdentifier } from "./AlgorithmIdentifier"; import { EMPTY_BUFFER } from "./constants"; import type { CryptoEngineAlgorithmOperation, CryptoEngineAlgorithmParams, ICryptoEngine } from "./CryptoEngine/CryptoEngineInterface"; import { ArgumentError } from "./errors";
//#region Crypto engine related function
export { ICryptoEngine } from "./CryptoEngine/CryptoEngineInterface";
if ((typeof process !== "undefined") && ("pid" in process) && (typeof global !== "undefined") && (typeof window === "undefined")) { // We are in Node if (typeof (global as any)[process.pid] === "undefined") {
(global as any)[process.pid] = {};
} else { if (typeof (global as any)[process.pid] !== "object") { thrownew Error(`Name global.${process.pid} already exists and it is not an object`);
}
}
if (typeof (global as any)[process.pid].pkijs === "undefined") {
(global as any)[process.pid].pkijs = {};
} else { if (typeof (global as any)[process.pid].pkijs !== "object") { thrownew Error(`Name global.${process.pid}.pkijs already exists and it is not an object`);
}
}
(global as any)[process.pid].pkijs.engine = {
name: name,
crypto,
};
} else { // We are in browser
engine = {
name: name,
crypto,
};
}
}
export function getEngine(): GlobalCryptoEngine { //#region We are in Node if ((typeof process !== "undefined") && ("pid" in process) && (typeof global !== "undefined") && (typeof window === "undefined")) {
let _engine;
try {
_engine = (global as any)[process.pid].pkijs.engine;
} catch { thrownew Error("Please call 'setEngine' before call to 'getEngine'");
}
ArgumentError.assert(zBuffer, "zBuffer", "ArrayBuffer"); if (zBuffer.byteLength === 0) thrownew ArgumentError("'zBuffer' has zero length, error");
ArgumentError.assert(SharedInfo, "SharedInfo", "ArrayBuffer"); if (Counter > 255) thrownew ArgumentError("Please set 'Counter' argument to value less or equal to 255"); //#endregion
//#region Create a combined ArrayBuffer for digesting
combinedBuffer = pvutils.utilConcatBuf(combinedBuffer, zBuffer);
combinedBuffer = pvutils.utilConcatBuf(combinedBuffer, counterBuffer);
combinedBuffer = pvutils.utilConcatBuf(combinedBuffer, SharedInfo); //#endregion
//#region Return digest of combined ArrayBuffer and information about current counter const result = await crypto.digest(
{ name: hashFunction },
combinedBuffer);
return {
counter: Counter,
result
}; //#endregion
}
//#region Check of input parameters switch (hashFunction.toUpperCase()) { case"SHA-1":
hashLength = 160; // In bits break; case"SHA-256":
hashLength = 256; // In bits break; case"SHA-384":
hashLength = 384; // In bits break; case"SHA-512":
hashLength = 512; // In bits break; default: thrownew ArgumentError(`Unknown hash function: ${hashFunction}`);
}
ArgumentError.assert(Zbuffer, "Zbuffer", "ArrayBuffer"); if (Zbuffer.byteLength === 0) thrownew ArgumentError("'Zbuffer' has zero length, error");
ArgumentError.assert(SharedInfo, "SharedInfo", "ArrayBuffer"); //#endregion
//#region Calculated maximum value of "Counter" variable const quotient = keydatalen / hashLength;
if (Math.floor(quotient) > 0) {
maxCounter = Math.floor(quotient);
if ((quotient - maxCounter) > 0)
maxCounter++;
} //#endregion
//#region Create an array of "kdfWithCounter" const incomingResult = []; for (let i = 1; i <= maxCounter; i++)
incomingResult.push(await kdfWithCounter(hashFunction, Zbuffer, i, SharedInfo, crypto)); //#endregion
//#region Return combined digest with specified length //#region Initial variables
let combinedBuffer = EMPTY_BUFFER;
let currentCounter = 1;
let found = true; //#endregion
//#region Combine all buffer together while (found) {
found = false;
for (const result of incomingResult) { if (result.counter === currentCounter) {
combinedBuffer = pvutils.utilConcatBuf(combinedBuffer, result.result);
found = true; break;
}
}
currentCounter++;
} //#endregion
//#region Create output buffer with specified length
keydatalen >>= 3; // Divide by 8 since "keydatalen" is in bits
if (combinedBuffer.byteLength > keydatalen) { const newBuffer = new ArrayBuffer(keydatalen); const newView = new Uint8Array(newBuffer); const combinedView = new Uint8Array(combinedBuffer);
for (let i = 0; i < keydatalen; i++)
newView[i] = combinedView[i];
return newBuffer;
}
return combinedBuffer; // Since the situation when "combinedBuffer.byteLength < keydatalen" here we have only "combinedBuffer.byteLength === keydatalen" //#endregion //#endregion
} //#endregion
import { CryptoEngine } from "./CryptoEngine/CryptoEngine";
Messung V0.5 in Prozent
¤ Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.0.3Bemerkung:
(vorverarbeitet am 2026-08-28)
¤
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.