Skip to content

[Breaking change]: AesGcm constructors without a tag size are obsolete #35338

Closed

Description

@vcsjones

Description

The constructors for System.Security.Cryptography.AesGcm that do not accept a tagSizeInBytes parameter have been marked obsolete in favor of new constructors that accept the required tag size.

Version

.NET 8 Preview 5

Previous behavior

The AesGcm(byte[] key) and AesGcm(ReadOnlySpan<byte> key) constructors were not obsolete.

New behavior

The AesGcm(byte[] key) and AesGcm(ReadOnlySpan<byte> key) constructors have been marked as obsolete.

Type of breaking change

  • Binary incompatible: Existing binaries may encounter a breaking change in behavior, such as failure to load or execute, and if so, require recompilation.
  • Source incompatible: When recompiled using the new SDK or component or to target the new runtime, existing source code may require source changes to compile successfully.
  • Behavioral change: Existing binaries may behave differently at run time.

Reason for change

AES-GCM supports tags of various lengths, from 12 to 16 bytes, depending on the platform. Previously, the AesGcm class would determine the desired tag size based on the size of the tag itself. For example, if Decrypt was used with a 14 byte tag, it was assumed the tag was supposed to be 14 bytes.

However, AES-GCM supports these various lengths by truncation. AES-GCM natively produces 16 byte tags, and shorter tags are produced by truncating the tag.

If callers of Decrypt get the tag from input and pass the tag as-is, this would effectively allow Decrypt to be used with the shortest possible tag, which reduces the effective size of the tag.

To help consumers ensure they are using tags of the correct size, new constructors for AesGcm were introduced which require up-front declaring the size of the expected tag. During Encrypt or Decrypt, the supplied tag parameter must match the size declared in the constructor.

Recommended action

Use a constructor that accepts the desired tag size.

For example, if 128-bit or 16-byte tags were being used, replace:

using AesGcm aes = new AesGcm(yourKey);

with

using AesGcm aes = new AesGcm(yourKey, tagSizeInBytes: 16);

Feature area

Cryptography

Affected APIs

  • M:System.Security.Cryptography.AesGcm.#ctor(System.Byte[])
  • M:System.Security.Cryptography.AesGcm.#ctor(System.ReadOnlySpan{System.Byte})

Associated WorkItem - 97019

Activity

  1. added
    breaking-change
    on May 15, 2023
  2. added
    ⌚ Not Triaged
    source incompatible
    on May 15, 2023
  3. added
    🏁 Release: .NET 8
    and removed
    ⌚ Not Triaged
    on May 15, 2023
  4. added
    🗺️ reQUEST
    on Jun 2, 2023
  5. added
    📌 seQUESTered
    and removed
    🗺️ reQUEST
    on Jun 3, 2023
  6. moved this from 🔖 Ready to 🏗 In progress in dotnet/docs June 2023 sprinton Jun 8, 2023
  7. ghost added
    in-pr
    on Jun 9, 2023
  8. moved this from 🏗 In progress to 👀 In review in dotnet/docs June 2023 sprinton Jun 9, 2023
  9. moved this from 👀 In review to ✅ Done in dotnet/docs June 2023 sprinton Jun 13, 2023
  10. moved this from 🆕 New to ✅ Done in .NET 8.0 work itemson Jun 13, 2023
  11. ghost removed
    in-pr
    on Jun 13, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

🏁 Release: .NET 8📌 seQUESTeredbreaking-changesource incompatible

Type

No type

Projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions