Skip to content

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

Description

@tetratorus

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')

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions