diff --git a/src/core/crypto/nacl_catapult.ts b/src/core/crypto/nacl_catapult.ts index 3524415b3b..30022073c6 100644 --- a/src/core/crypto/nacl_catapult.ts +++ b/src/core/crypto/nacl_catapult.ts @@ -669,28 +669,6 @@ const unpack25519 = (o, n) => { o[15] &= 0x7fff; }; -export const cleanup = (arr) => { - for (let i = 0; i < arr.length; i++) { - arr[i] = 0; - } -}; - -export const crypto_shared_key_hash = (shared, pk, sk, hashfunc) => { - const d = new Uint8Array(64); - const p = [gf(), gf(), gf(), gf()]; - - hashfunc(d, sk, 32); - d[0] &= 248; - d[31] &= 127; - d[31] |= 64; - - const q = [gf(), gf(), gf(), gf()]; - // tslint:disable: no-use-before-declare - unpackneg(q, pk); - scalarmult(p, q, d); - pack(shared, p); -}; - export const crypto_verify_32 = (x, xi, y, yi) => { return vn(x, xi, y, yi, 32); }; @@ -728,47 +706,6 @@ export const add = (p, q) => { M(p[3], e, h); }; -export const modL = (r, x) => { - // tslint:disable-next-line:one-variable-per-declaration - let carry, i, j, k; - for (i = 63; i >= 32; --i) { - carry = 0; - for (j = i - 32, k = i - 12; j < k; ++j) { - x[j] += carry - 16 * x[i] * L[j - (i - 32)]; - carry = (x[j] + 128) >> 8; - x[j] -= carry * 256; - } - x[j] += carry; - x[i] = 0; - } - carry = 0; - for (j = 0; j < 32; j++) { - x[j] += carry - (x[31] >> 4) * L[j]; - carry = x[j] >> 8; - x[j] &= 255; - } - for (j = 0; j < 32; j++) { - x[j] -= carry * L[j]; - } - for (i = 0; i < 32; i++) { - x[i + 1] += x[i] >> 8; - r[i] = x[i] & 255; - } -}; - -export const reduce = (r) => { - // tslint:disable-next-line:one-variable-per-declaration - let x = new Float64Array(64), - i; - for (i = 0; i < 64; i++) { - x[i] = r[i]; - } - for (i = 0; i < 64; i++) { - r[i] = 0; - } - modL(r, x); -}; - export const pack = (r, p) => { // tslint:disable-next-line:one-variable-per-declaration const tx = gf(), @@ -797,64 +734,6 @@ export const scalarmult = (p, q, s) => { } }; -export const scalarbase = (p, s) => { - const q = [gf(), gf(), gf(), gf()]; - set25519(q[0], X); - set25519(q[1], Y); - set25519(q[2], gf1); - M(q[3], X, Y); - scalarmult(p, q, s); -}; - -export const unpackneg = (r, p) => { - // tslint:disable-next-line:one-variable-per-declaration - const t = gf(), - chk = gf(), - num = gf(), - den = gf(), - den2 = gf(), - den4 = gf(), - den6 = gf(); - - set25519(r[2], gf1); - unpack25519(r[1], p); - S(num, r[1]); - M(den, num, D); - Z(num, num, r[2]); - A(den, r[2], den); - - S(den2, den); - S(den4, den2); - M(den6, den4, den2); - M(t, den6, num); - M(t, t, den); - - pow2523(t, t); - M(t, t, num); - M(t, t, den); - M(t, t, den); - M(r[0], t, den); - - S(chk, r[0]); - M(chk, chk, den); - if (neq25519(chk, num)) { - M(r[0], r[0], I); - } - - S(chk, r[0]); - M(chk, chk, den); - if (neq25519(chk, num)) { - return -1; - } - - if (par25519(r[0]) === (p[31] >> 7)) { - Z(r[0], gf0, r[0]); - } - - M(r[3], r[0], r[1]); - return 0; -}; - export const unpack = (r, p) => { // tslint:disable-next-line:one-variable-per-declaration const t = gf(), diff --git a/src/model/transaction/Transaction.ts b/src/model/transaction/Transaction.ts index 725dee952c..2ae1fde1c3 100644 --- a/src/model/transaction/Transaction.ts +++ b/src/model/transaction/Transaction.ts @@ -138,11 +138,11 @@ export abstract class Transaction { TransactionType.AGGREGATE_COMPLETE, ].find((type: TransactionType) => entityType === type) !== undefined; - // 1) take "R" part of a signature (first 32 bytes) - const signatureR: Uint8Array = transactionBytes.slice(8, 8 + 32); + // 1) add full signature + const signature: Uint8Array = transactionBytes.slice(8, 8 + 64); // 2) add public key to match sign/verify behavior (32 bytes) - const pubKeyIdx: number = signatureR.length; + const pubKeyIdx: number = signature.length; const publicKey: Uint8Array = transactionBytes.slice(8 + 64, 8 + 64 + 32); // 3) add generationHash (32 bytes) @@ -162,12 +162,12 @@ export abstract class Transaction { // 5) concatenate binary hash parts // layout: `signature_R || signerPublicKey || generationHash || EntityDataBuffer` const entityHashBytes: Uint8Array = new Uint8Array( - signatureR.length + signature.length + publicKey.length + generationHash.length + transactionBody.length, ); - entityHashBytes.set(signatureR, 0); + entityHashBytes.set(signature, 0); entityHashBytes.set(publicKey, pubKeyIdx); entityHashBytes.set(generationHash, generationHashIdx); entityHashBytes.set(transactionBody, transactionBodyIdx); diff --git a/test/model/transaction/Transaction.spec.ts b/test/model/transaction/Transaction.spec.ts index 2c89d2a57f..eaeeee963b 100644 --- a/test/model/transaction/Transaction.spec.ts +++ b/test/model/transaction/Transaction.spec.ts @@ -255,7 +255,7 @@ describe('Transaction', () => { ); // expected values - const knownHash_sha3 = '709373248659274C5933BEA2920942D6C7B48B9C2DA4BAEE233510E71495931F'; + const knownHash_sha3 = 'F0F5A62A0863D45E832B50EFF4E2F68157268A5D1674EC1068D82EC5F88D950B'; const generationHashBytes = Array.from(Convert.hexToUint8('988C4CDCE4D188013C13DE7914C7FD4D626169EF256722F61C52EFBE06BD5A2C')); const generationHashBytes_mt = Array.from(Convert.hexToUint8('17FA4747F5014B50413CCF968749604D728D7065DC504291EEE556899A534CBB'));