mirror of
https://github.com/espressif/openthread.git
synced 2026-09-11 03:30:09 +00:00
[ecdsa] use reference (instead of pointer) for output length (#5015)
This commit is contained in:
committed by
Jonathan Hui
parent
615bf36d88
commit
19e2d148a1
@@ -98,7 +98,7 @@ otError otCryptoEcdsaSign(uint8_t * aOutput,
|
||||
const uint8_t *aPrivateKey,
|
||||
uint16_t aPrivateKeyLength)
|
||||
{
|
||||
return Ecdsa::Sign(aOutput, aOutputLength, aInputHash, aInputHashLength, aPrivateKey, aPrivateKeyLength);
|
||||
return Ecdsa::Sign(aOutput, *aOutputLength, aInputHash, aInputHashLength, aPrivateKey, aPrivateKeyLength);
|
||||
}
|
||||
|
||||
#endif // OPENTHREAD_CONFIG_ECDSA_ENABLE
|
||||
|
||||
@@ -47,7 +47,7 @@ namespace Crypto {
|
||||
#if OPENTHREAD_CONFIG_ECDSA_ENABLE
|
||||
|
||||
otError Ecdsa::Sign(uint8_t * aOutput,
|
||||
uint16_t * aOutputLength,
|
||||
uint16_t & aOutputLength,
|
||||
const uint8_t *aInputHash,
|
||||
uint16_t aInputHashLength,
|
||||
const uint8_t *aPrivateKey,
|
||||
@@ -79,15 +79,15 @@ otError Ecdsa::Sign(uint8_t * aOutput,
|
||||
VerifyOrExit(mbedtls_ecdsa_sign(&ctx.grp, &rMpi, &sMpi, &ctx.d, aInputHash, aInputHashLength,
|
||||
mbedtls_ctr_drbg_random, Random::Crypto::MbedTlsContextGet()) == 0,
|
||||
error = OT_ERROR_FAILED);
|
||||
VerifyOrExit(mbedtls_mpi_size(&rMpi) + mbedtls_mpi_size(&sMpi) <= *aOutputLength, error = OT_ERROR_NO_BUFS);
|
||||
VerifyOrExit(mbedtls_mpi_size(&rMpi) + mbedtls_mpi_size(&sMpi) <= aOutputLength, error = OT_ERROR_NO_BUFS);
|
||||
|
||||
// Concatenate the two octet sequences in the order R and then S.
|
||||
VerifyOrExit(mbedtls_mpi_write_binary(&rMpi, aOutput, mbedtls_mpi_size(&rMpi)) == 0, error = OT_ERROR_FAILED);
|
||||
*aOutputLength = static_cast<uint16_t>(mbedtls_mpi_size(&rMpi));
|
||||
aOutputLength = static_cast<uint16_t>(mbedtls_mpi_size(&rMpi));
|
||||
|
||||
VerifyOrExit(mbedtls_mpi_write_binary(&sMpi, aOutput + *aOutputLength, mbedtls_mpi_size(&sMpi)) == 0,
|
||||
VerifyOrExit(mbedtls_mpi_write_binary(&sMpi, aOutput + aOutputLength, mbedtls_mpi_size(&sMpi)) == 0,
|
||||
error = OT_ERROR_FAILED);
|
||||
*aOutputLength += mbedtls_mpi_size(&sMpi);
|
||||
aOutputLength += mbedtls_mpi_size(&sMpi);
|
||||
|
||||
exit:
|
||||
mbedtls_mpi_free(&rMpi);
|
||||
|
||||
@@ -75,7 +75,7 @@ public:
|
||||
*
|
||||
*/
|
||||
static otError Sign(uint8_t * aOutput,
|
||||
uint16_t * aOutputLength,
|
||||
uint16_t & aOutputLength,
|
||||
const uint8_t *aInputHash,
|
||||
uint16_t aInputHashLength,
|
||||
const uint8_t *aPrivateKey,
|
||||
|
||||
Reference in New Issue
Block a user