Skip to content

Commit 7cdffeb

Browse files
J8k3claude
andcommitted
fix(dukpt): add KSN/BDK to JSON output for AES and TDES DUKPT derive operations
AES DUKPT IK JSON was missing ksn, iki, counter; working key was missing ksn. TDES DUKPT IPEK and session key JSON were missing ksn and bdk. Both now mirror the full derivation context, making json=true self-contained for debugging and cross-validation. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
1 parent d7a32d1 commit 7cdffeb

2 files changed

Lines changed: 8 additions & 3 deletions

File tree

src/core/operations/DeriveDUKPTAESKey.mjs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -305,8 +305,9 @@ class DeriveDUKPTAESKey extends Operation {
305305

306306
if (deriveMode === "Initial Key (IK)") {
307307
if (outputJson) {
308-
const out = { inputKeyType, ik: hex(ik) };
308+
const out = { inputKeyType, ksn: hex(ksn), iki: hex(iki), counter: `0x${counter.toString(16).padStart(8, "0").toUpperCase()}` };
309309
if (inputKeyType === "BDK") out.bdk = hex(inputKey);
310+
out.ik = hex(ik);
310311
return JSON.stringify(out, null, 4);
311312
}
312313
return hex(ik);
@@ -317,7 +318,7 @@ class DeriveDUKPTAESKey extends Operation {
317318
const wkKey = deriveWorkingKey(txKey, iki, counter, purpose);
318319

319320
if (outputJson) {
320-
const out = { inputKeyType, iki: hex(iki), counter: `0x${counter.toString(16).padStart(8, "0").toUpperCase()}` };
321+
const out = { inputKeyType, ksn: hex(ksn), iki: hex(iki), counter: `0x${counter.toString(16).padStart(8, "0").toUpperCase()}` };
321322
if (inputKeyType === "BDK") out.bdk = hex(inputKey);
322323
out.ik = hex(ik);
323324
out.transactionKey = hex(txKey);

src/core/operations/DeriveDUKPTKey.mjs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -253,9 +253,11 @@ class DeriveDUKPTKey extends Operation {
253253
const ipek = deriveIpek(bdk, ksn);
254254
const ipekHex = toHexFast(ipek).toUpperCase();
255255

256+
const ksnHexOut = toHexFast(ksn).toUpperCase();
257+
256258
if (mode === "Derive IPEK") {
257259
if (outputJson) {
258-
return JSON.stringify({ mode, ipek: ipekHex }, null, 4);
260+
return JSON.stringify({ mode, ksn: ksnHexOut, bdk: toHexFast(bdk).toUpperCase(), ipek: ipekHex }, null, 4);
259261
}
260262
return ipekHex;
261263
}
@@ -267,6 +269,8 @@ class DeriveDUKPTKey extends Operation {
267269
if (outputJson) {
268270
return JSON.stringify({
269271
mode,
272+
ksn: ksnHexOut,
273+
bdk: toHexFast(bdk).toUpperCase(),
270274
ipek: ipekHex,
271275
sessionBase: toHexFast(sessionBase).toUpperCase(),
272276
variant,

0 commit comments

Comments
 (0)