asmcrypto / asmcrypto.js

JavaScript Cryptographic Library with performance in mind.
MIT License
659 stars 182 forks source link

asmCrypto.Modulus can break when leading zeroes are supplied #101

Closed sorgloomer closed 7 years ago

sorgloomer commented 8 years ago

While the following two represent the same number:

console.log(
  new asmCrypto.BigNumber(asmCrypto.hex_to_bytes("AABBCCDDAABBCCDD")).toString()
); // "aabbccddaabbccdd"

console.log(
  new asmCrypto.BigNumber(asmCrypto.hex_to_bytes("00AABBCCDDAABBCCDD")).toString()
); // "aabbccddaabbccdd"

The comodulus inside the Modulus class behaves differently:

console.log(
  new asmCrypto.Modulus(asmCrypto.hex_to_bytes("AABBCCDDAABBCCDD")).comodulusRemainder.toString()
); // "5544332255443323"

console.log(
  new asmCrypto.Modulus(asmCrypto.hex_to_bytes("00AABBCCDDAABBCCDD")).comodulusRemainder.toString()
); // "6ad813226ad81321"

It seems to appear only when the significant part of the number is a multiple of 4 bytes long.