Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

toArray() returns unpadded Buffer arrays, resulting in Bad MAC error #90

Open
tetratorus opened this issue Mar 21, 2023 · 1 comment
Open

Comments

@tetratorus
Copy link

tetratorus commented Mar 21, 2023

resolve(Buffer.from(Px.toArray()));

Px is a BN, and the toArray() method on BN doesn't have padding. So if it starts with two leading zeros (eg. '00928cfa...', happens with 1/256 probability), the length of the resulting Buffer will only be length 31 instead of length 32.

Reproducible example

var encryption = {
  ciphertext: Buffer.from('e614aff7db97b01d4b0d5cfb1387b4763cb369f74d743bed95020330d57e3ae91a574bd7ae89da0885eb5f6e332a296f', 'hex'),
  ephemPublicKey: Buffer.from('04fb0a7c19defeaeeb34defbc47be3c9a4c1de500895c1e1e8ce6d0991595217f8e76c4594968e8c77d83c26f4f1ee496c40c7ac48816a4ee2edf38c550d8916a0', 'hex'),
  iv: Buffer.from('456f0c039cb2224849082c3d0feebec1', 'hex'),
  mac: Buffer.from('df7352dcdf2ee10c939276791515340479b526920a155b8ac932a5a26ea4c924', 'hex')
}

var decryptionKey = Buffer.from('78bb3f8efcd59ebc8c4f0dee865ba10e375869921c62caa5b3b46699504bb280', 'hex')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants