Browse Source

Padding the hex strings being hashed to 32 bytes

pull/5/head
Jør∂¡ 3 years ago
parent
commit
bb9c784b04
1 changed files with 12 additions and 4 deletions
  1. +12
    -4
      src/index.ts

+ 12
- 4
src/index.ts

@ -93,8 +93,8 @@ export function blind(m: BigInteger, signerR: Point): { mBlinded: BigInteger, us
const ainvrx = ainv.multiply(rx)
const mHex = m.toString(16)
const hHex = keccak256('0x' + mHex)
const h = BigInteger.fromHex(hHex.slice(2))
const hHex = keccak256('0x' + zeroPad(mHex, 32)).substr(2)
const h = BigInteger.fromHex(hHex)
const mBlinded = ainvrx.multiply(h)
return { mBlinded: mBlinded.mod(n), userSecretData: u }
@ -121,8 +121,8 @@ export function verify(m: BigInteger, s: UnblindedSignature, q: Point) {
const sG = G.multiply(s.s)
const mHex = m.toString(16)
const hHex = keccak256('0x' + mHex)
const h = BigInteger.fromHex(hHex.slice(2))
const hHex = keccak256('0x' + zeroPad(mHex, 32)).substr(2)
const h = BigInteger.fromHex(hHex)
const rx = s.f.affineX.mod(n)
const right = s.f.add(
@ -147,3 +147,11 @@ function random(bytes: number) {
} while (k.toString() == '0' && k.gcd(n).toString() != '1')
return k
}
function zeroPad(hexString: string, byteLength: number) {
if (hexString.length > (byteLength * 2)) throw new Error("Out of bounds")
while (hexString.length < (byteLength * 2)) {
hexString = "0" + hexString
}
return hexString
}

Loading…
Cancel
Save