Skip to content

ManagedAuthenticatedEncryptor is broken on NETFX #65889

Description

@BrennanConroy

#59424 refactored parts of DataProtection to use newer crypto APIs that allowed Span<T> usage. However, it introduced 2 bugs in the CalculateAndValidateMac method for apps targeting < .NET 5+.

First:

correctHashArray = validationAlgorithm.ComputeHash(payloadArray, macOffset, eofOffset - macOffset);

This is using the wrong offsets for computing the hash, it should be ComputeHash(payloadArray, ivOffset, macOffset - ivOffset)

Second:

if (!CryptoUtil.TimeConstantBuffersAreEqual(correctHash, payloadMacSpan))

This is comparing against correctHash which is assigned an array (or stackalloc) but never used, but we're writing the computed hash (see first code snippet) to a new array and assigning it to correctHashArray. So we end up comparing something against nothing which always fails.

This is actually the saving grace, because this check always fails the scenario is just completely unusable instead of broken in a bad way.

Metadata

Metadata

Assignees

No one assigned

    Labels

    area-dataprotectionIncludes: DataProtectionbugThis issue describes a behavior which is not expected - a bug.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions