Skip to content

Commit a8e9f21

Browse files
authored
Provider behavior fixes (#102)
* Check that ECDSA signature is a sequence of two integers without trailing data * Return authenticated bytes for AEAD ciphers if out is NULL
1 parent 405a016 commit a8e9f21

File tree

2 files changed

+18
-2
lines changed

2 files changed

+18
-2
lines changed

ScosslCommon/src/scossl_aes_aead.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -176,7 +176,7 @@ SCOSSL_STATUS scossl_aes_gcm_cipher(SCOSSL_CIPHER_GCM_CTX *ctx, INT32 encrypt,
176176
{
177177
// Auth Data Passed in
178178
SymCryptGcmAuthPart(&ctx->state, in, inl);
179-
*outl = 0;
179+
*outl = inl;
180180
return SCOSSL_SUCCESS;
181181
}
182182

@@ -638,7 +638,7 @@ SCOSSL_STATUS scossl_aes_ccm_cipher(SCOSSL_CIPHER_CCM_CTX *ctx, INT32 encrypt,
638638
if (out == NULL)
639639
{
640640
// Auth Data Passed in
641-
*outl = 0;
641+
*outl = cbAuthdata;
642642
return SCOSSL_SUCCESS;
643643
}
644644
}

ScosslCommon/src/scossl_ecc.c

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -362,6 +362,15 @@ static SCOSSL_STATUS scossl_ecdsa_remove_der(_In_reads_bytes_(cbDerSignature) PC
362362
goto cleanup;
363363
}
364364

365+
if (pbS + cbS != pbSeq + cbSeq)
366+
{
367+
SCOSSL_LOG_ERROR(SCOSSL_ERR_F_ECDSA_REMOVE_DER, ERR_R_PASSED_INVALID_ARGUMENT,
368+
"Unexpected value in sequence");
369+
SCOSSL_LOG_BYTES_DEBUG(SCOSSL_ERR_F_ECDSA_REMOVE_DER, ERR_R_PASSED_INVALID_ARGUMENT,
370+
"pbDerSignature", pbDerSignature, cbDerSignature);
371+
goto cleanup;
372+
}
373+
365374
// Check R's validity
366375
if (((pbR[0] & 0x80) == 0x80) || // R is negative
367376
((cbR > 1) && (pbR[0] == 0x00) && ((pbR[1] & 0x80) != 0x80))) // R is non-zero, and has a redundant leading 0 byte
@@ -412,6 +421,13 @@ static SCOSSL_STATUS scossl_ecdsa_remove_der(_In_reads_bytes_(cbDerSignature) PC
412421
return res;
413422
}
414423

424+
/*
425+
ECDSA-Sig-Value ::= SEQUENCE {
426+
r INTEGER,
427+
s INTEGER
428+
}
429+
*/
430+
415431
// Quick hack function to generate precisely the DER encodings which we want for ECDSA signatures for the NIST prime curves
416432
// Takes 2 same-size big-endian integers output from SymCrypt and encodes them in the minimally sized (strict) equivalent DER encoding
417433
// Returns SCOSSL_SUCCESS on success, or SCOSSL_FAILURE on failure.

0 commit comments

Comments
 (0)