-
Notifications
You must be signed in to change notification settings - Fork 5.2k
Description
The native shim for OpenSSL asserts that the msg parameter is not null:
runtime/src/native/libs/System.Security.Cryptography.Native/pal_evp_pkey_ml_dsa.c
Line 161 in 1b090a9
| assert(msg); |
However it can be null when signing an empty message, as ReadOnlySpan<byte>.Empty will marshal as NULL. This unit test reproduces it:
[Fact]
public static void MlDsaNullMessage()
{
using MLDsa mldsa = MLDsa.GenerateKey(MLDsaAlgorithm.MLDsa44);
byte[] signature = new byte[mldsa.Algorithm.SignatureSizeInBytes];
_ = mldsa.SignData(ReadOnlySpan<byte>.Empty, signature);
}The active test run was aborted. Reason: Test host process crashed : dotnet: /home/vcsjones/Projects/runtime/src/native/libs/System.Security.Cryptography.Native/pal_evp_pkey_ml_dsa.c:81: int32_t CryptoNative_MLDsaSignPure(EVP_PKEY *, void *, uint8_t *, int32_t, uint8_t *, int32_t, uint8_t *, int32_t): Assertion `msg' failed.
The two ways to fix this are:
- If
EVP_PKEY_signpermitstbsto beNULL(as long astbslenis 0) then we can relax the assert. - If
EVP_PKEY_signrequires a non-NULL tbs, we can either handle that in the native shim (put an empty buffer on the stack), or useGetNonNullPinnableReferencefrom the managed side.
Additionally, we should make sure context works correctly as well for "null-span" contexts, and that everything has proper unit test coverage. Verify should be tested as well.