Skip to content

HmacSha256 truncates a key whose length does not fit an int #88

Description

@SeanTAllen

HmacSha256.apply narrows the key length to I32 and hands it to HMAC:

@HMAC(@EVP_sha256(), key.cpointer(), key.size().i32(),
  data.cpointer(), data.size(), arr.cpointer(), Pointer[U32])

HMAC takes an int for the key length, so the declaration is right. Nothing checks that the key's size fits in one.

A key of 2^32 + 5 bytes narrows to 5. HMAC reads the first five bytes of it and returns a MAC for a key the caller never passed. Nothing raises.

A key between 2^31 and 2^32 bytes narrows to a negative length. HMAC returns NULL and writes nothing.

data.size() is passed as a USize and does not narrow. Only the key does.

apply takes a ByteSeq, which admits both sizes.

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

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions