Skip to content

HKDF: Expand and DeriveKey throw invalid exceptions when outputLength is negative #42229

@andreimilto

Description

@andreimilto

Methods Expand and DeriveKey of the System.Security.Cryptography.HKDF class throw invalid exceptions when the argument outputLength has negative value.


In this example Expand throws ArgumentOutOfRangeException with the message Output keying material length can be at most 8160 bytes (255 * hash length).:

HKDF.Expand(HashAlgorithmName.SHA256, prk: new byte[32], outputLength: -1);

Instead the exception message should say that outputLength can't be negative (or that it must be positive - depends on whether 0 is considered a valid input).


Here DeriveKey throws OverflowException with the message Arithmetic operation resulted in an overflow.:

HKDF.DeriveKey(HashAlgorithmName.SHA256, ikm: new byte[32], outputLength: -1);

Instead the type of exception should be ArgumentOutOfRangeException and the message should say that the outputLength can't be negative (or that it must be positive - depends on whether 0 is considered a valid input).


Windows 10 x64 Pro, dotnet 5.0.0-preview.8.

Metadata

Metadata

Labels

area-System.Securitygood first issueIssue should be easy to implement, good for first-time contributorshelp wanted[up-for-grabs] Good issue for external contributors

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions