mirror of
https://github.com/espressif/openthread.git
synced 2026-09-02 07:10:08 +00:00
[crypto] remove legacy otCryptoEcdsaSign (#8514)
This API was introduced for convenience but it's not used anymore.
This commit is contained in:
@@ -253,7 +253,6 @@ LOCAL_SRC_FILES := \
|
||||
src/core/crypto/aes_ccm.cpp \
|
||||
src/core/crypto/aes_ecb.cpp \
|
||||
src/core/crypto/crypto_platform.cpp \
|
||||
src/core/crypto/ecdsa.cpp \
|
||||
src/core/crypto/hkdf_sha256.cpp \
|
||||
src/core/crypto/hmac_sha256.cpp \
|
||||
src/core/crypto/mbedtls.cpp \
|
||||
|
||||
@@ -105,28 +105,6 @@ void otCryptoAesCcm(const otCryptoKey *aKey,
|
||||
bool aEncrypt,
|
||||
void *aTag);
|
||||
|
||||
/**
|
||||
* This method creates ECDSA sign.
|
||||
*
|
||||
* @param[out] aOutput An output buffer where ECDSA sign should be stored.
|
||||
* @param[in,out] aOutputLength The length of the @p aOutput buffer.
|
||||
* @param[in] aInputHash An input hash.
|
||||
* @param[in] aInputHashLength The length of the @p aInputHash buffer.
|
||||
* @param[in] aPrivateKey A private key in PEM format.
|
||||
* @param[in] aPrivateKeyLength The length of the @p aPrivateKey buffer.
|
||||
*
|
||||
* @retval OT_ERROR_NONE ECDSA sign has been created successfully.
|
||||
* @retval OT_ERROR_NO_BUFS Output buffer is too small.
|
||||
* @retval OT_ERROR_INVALID_ARGS Private key is not valid EC Private Key.
|
||||
* @retval OT_ERROR_FAILED Error during signing.
|
||||
*/
|
||||
otError otCryptoEcdsaSign(uint8_t *aOutput,
|
||||
uint16_t *aOutputLength,
|
||||
const uint8_t *aInputHash,
|
||||
uint16_t aInputHashLength,
|
||||
const uint8_t *aPrivateKey,
|
||||
uint16_t aPrivateKeyLength);
|
||||
|
||||
/**
|
||||
* @}
|
||||
*
|
||||
|
||||
@@ -53,7 +53,7 @@ extern "C" {
|
||||
* @note This number versions both OpenThread platform and user APIs.
|
||||
*
|
||||
*/
|
||||
#define OPENTHREAD_API_VERSION (267)
|
||||
#define OPENTHREAD_API_VERSION (268)
|
||||
|
||||
/**
|
||||
* @addtogroup api-instance
|
||||
|
||||
@@ -461,7 +461,6 @@ openthread_core_files = [
|
||||
"crypto/aes_ecb.hpp",
|
||||
"crypto/context_size.hpp",
|
||||
"crypto/crypto_platform.cpp",
|
||||
"crypto/ecdsa.cpp",
|
||||
"crypto/ecdsa.hpp",
|
||||
"crypto/hkdf_sha256.cpp",
|
||||
"crypto/hkdf_sha256.hpp",
|
||||
|
||||
@@ -120,7 +120,6 @@ set(COMMON_SOURCES
|
||||
crypto/aes_ccm.cpp
|
||||
crypto/aes_ecb.cpp
|
||||
crypto/crypto_platform.cpp
|
||||
crypto/ecdsa.cpp
|
||||
crypto/hkdf_sha256.cpp
|
||||
crypto/hmac_sha256.cpp
|
||||
crypto/mbedtls.cpp
|
||||
|
||||
@@ -210,7 +210,6 @@ SOURCES_COMMON = \
|
||||
crypto/aes_ccm.cpp \
|
||||
crypto/aes_ecb.cpp \
|
||||
crypto/crypto_platform.cpp \
|
||||
crypto/ecdsa.cpp \
|
||||
crypto/hkdf_sha256.cpp \
|
||||
crypto/hmac_sha256.cpp \
|
||||
crypto/mbedtls.cpp \
|
||||
|
||||
@@ -89,22 +89,3 @@ void otCryptoAesCcm(const otCryptoKey *aKey,
|
||||
aesCcm.Payload(aPlainText, aCipherText, aLength, aEncrypt ? AesCcm::kEncrypt : AesCcm::kDecrypt);
|
||||
aesCcm.Finalize(aTag);
|
||||
}
|
||||
|
||||
#if OPENTHREAD_CONFIG_ECDSA_ENABLE
|
||||
|
||||
otError otCryptoEcdsaSign(uint8_t *aOutput,
|
||||
uint16_t *aOutputLength,
|
||||
const uint8_t *aInputHash,
|
||||
uint16_t aInputHashLength,
|
||||
const uint8_t *aPrivateKey,
|
||||
uint16_t aPrivateKeyLength)
|
||||
{
|
||||
AssertPointerIsNotNull(aOutput);
|
||||
AssertPointerIsNotNull(aOutputLength);
|
||||
AssertPointerIsNotNull(aInputHash);
|
||||
AssertPointerIsNotNull(aPrivateKey);
|
||||
|
||||
return Ecdsa::Sign(aOutput, *aOutputLength, aInputHash, aInputHashLength, aPrivateKey, aPrivateKeyLength);
|
||||
}
|
||||
|
||||
#endif // OPENTHREAD_CONFIG_ECDSA_ENABLE
|
||||
|
||||
@@ -62,13 +62,13 @@ public:
|
||||
static constexpr uint8_t kBlockSize = 16; ///< AES-128 block size (bytes).
|
||||
|
||||
/**
|
||||
* Constructor to initialize the mbedtls_aes_context.
|
||||
* Constructor to initialize the AES operation.
|
||||
*
|
||||
*/
|
||||
AesEcb(void);
|
||||
|
||||
/**
|
||||
* Destructor to free the mbedtls_aes_context.
|
||||
* Destructor to free the AES context.
|
||||
*
|
||||
*/
|
||||
~AesEcb(void);
|
||||
|
||||
@@ -1,127 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 2018, The OpenThread Authors.
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
* 3. Neither the name of the copyright holder nor the
|
||||
* names of its contributors may be used to endorse or promote products
|
||||
* derived from this software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
||||
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
|
||||
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
||||
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
||||
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
||||
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
||||
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
* POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
/**
|
||||
* @file
|
||||
* This file implements ECDSA signing.
|
||||
*/
|
||||
|
||||
#include "ecdsa.hpp"
|
||||
|
||||
#if OPENTHREAD_CONFIG_ECDSA_ENABLE
|
||||
|
||||
#include <string.h>
|
||||
|
||||
#include <mbedtls/ctr_drbg.h>
|
||||
#include <mbedtls/ecdsa.h>
|
||||
#include <mbedtls/pk.h>
|
||||
#include <mbedtls/version.h>
|
||||
|
||||
#include "common/code_utils.hpp"
|
||||
#include "common/debug.hpp"
|
||||
#include "common/random.hpp"
|
||||
#include "crypto/mbedtls.hpp"
|
||||
|
||||
namespace ot {
|
||||
namespace Crypto {
|
||||
namespace Ecdsa {
|
||||
|
||||
Error Sign(uint8_t *aOutput,
|
||||
uint16_t &aOutputLength,
|
||||
const uint8_t *aInputHash,
|
||||
uint16_t aInputHashLength,
|
||||
const uint8_t *aPrivateKey,
|
||||
uint16_t aPrivateKeyLength)
|
||||
{
|
||||
Error error = kErrorNone;
|
||||
mbedtls_ecdsa_context ctx;
|
||||
mbedtls_pk_context pkCtx;
|
||||
mbedtls_ecp_keypair *keypair;
|
||||
mbedtls_mpi rMpi;
|
||||
mbedtls_mpi sMpi;
|
||||
|
||||
mbedtls_pk_init(&pkCtx);
|
||||
mbedtls_ecdsa_init(&ctx);
|
||||
mbedtls_mpi_init(&rMpi);
|
||||
mbedtls_mpi_init(&sMpi);
|
||||
|
||||
// Parse a private key in PEM format.
|
||||
#if (MBEDTLS_VERSION_NUMBER >= 0x03000000)
|
||||
VerifyOrExit(mbedtls_pk_parse_key(&pkCtx, aPrivateKey, aPrivateKeyLength, nullptr, 0, MbedTls::CryptoSecurePrng,
|
||||
nullptr) == 0,
|
||||
error = kErrorInvalidArgs);
|
||||
#else
|
||||
VerifyOrExit(mbedtls_pk_parse_key(&pkCtx, aPrivateKey, aPrivateKeyLength, nullptr, 0) == 0,
|
||||
error = kErrorInvalidArgs);
|
||||
#endif
|
||||
VerifyOrExit(mbedtls_pk_get_type(&pkCtx) == MBEDTLS_PK_ECKEY, error = kErrorInvalidArgs);
|
||||
|
||||
keypair = mbedtls_pk_ec(pkCtx);
|
||||
OT_ASSERT(keypair != nullptr);
|
||||
|
||||
VerifyOrExit(mbedtls_ecdsa_from_keypair(&ctx, keypair) == 0, error = kErrorFailed);
|
||||
|
||||
// Sign using ECDSA.
|
||||
#if OPENTHREAD_CONFIG_DETERMINISTIC_ECDSA_ENABLE
|
||||
#if (MBEDTLS_VERSION_NUMBER >= 0x02130000)
|
||||
VerifyOrExit(mbedtls_ecdsa_sign_det_ext(&ctx.MBEDTLS_PRIVATE(grp), &rMpi, &sMpi, &ctx.MBEDTLS_PRIVATE(d),
|
||||
aInputHash, aInputHashLength, MBEDTLS_MD_SHA256, MbedTls::CryptoSecurePrng,
|
||||
nullptr));
|
||||
#else
|
||||
VerifyOrExit(mbedtls_ecdsa_sign_det(&ctx.MBEDTLS_PRIVATE(grp), &rMpi, &sMpi, &ctx.MBEDTLS_PRIVATE(d), aInputHash,
|
||||
aInputHashLength, MBEDTLS_MD_SHA256));
|
||||
#endif
|
||||
#else
|
||||
VerifyOrExit(mbedtls_ecdsa_sign(&ctx.MBEDTLS_PRIVATE(grp), &rMpi, &sMpi, &ctx.MBEDTLS_PRIVATE(d), aInputHash,
|
||||
aInputHashLength, MbedTls::CryptoSecurePrng, nullptr) == 0,
|
||||
error = kErrorFailed);
|
||||
#endif
|
||||
VerifyOrExit(mbedtls_mpi_size(&rMpi) + mbedtls_mpi_size(&sMpi) <= aOutputLength, error = kErrorNoBufs);
|
||||
|
||||
// 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 = kErrorFailed);
|
||||
aOutputLength = static_cast<uint16_t>(mbedtls_mpi_size(&rMpi));
|
||||
|
||||
VerifyOrExit(mbedtls_mpi_write_binary(&sMpi, aOutput + aOutputLength, mbedtls_mpi_size(&sMpi)) == 0,
|
||||
error = kErrorFailed);
|
||||
aOutputLength += mbedtls_mpi_size(&sMpi);
|
||||
|
||||
exit:
|
||||
mbedtls_mpi_free(&rMpi);
|
||||
mbedtls_mpi_free(&sMpi);
|
||||
mbedtls_ecdsa_free(&ctx);
|
||||
mbedtls_pk_free(&pkCtx);
|
||||
|
||||
return error;
|
||||
}
|
||||
|
||||
} // namespace Ecdsa
|
||||
} // namespace Crypto
|
||||
} // namespace ot
|
||||
|
||||
#endif // OPENTHREAD_CONFIG_ECDSA_ENABLE
|
||||
@@ -245,29 +245,6 @@ public:
|
||||
} OT_TOOL_PACKED_END;
|
||||
};
|
||||
|
||||
/**
|
||||
* This function creates an ECDSA signature.
|
||||
*
|
||||
* @param[out] aOutput An output buffer where ECDSA sign should be stored.
|
||||
* @param[in,out] aOutputLength The length of the @p aOutput buffer.
|
||||
* @param[in] aInputHash An input hash.
|
||||
* @param[in] aInputHashLength The length of the @p aInputHash buffer.
|
||||
* @param[in] aPrivateKey A private key in PEM format.
|
||||
* @param[in] aPrivateKeyLength The length of the @p aPrivateKey buffer.
|
||||
*
|
||||
* @retval kErrorNone ECDSA sign has been created successfully.
|
||||
* @retval kErrorNoBufs Output buffer is too small.
|
||||
* @retval kErrorInvalidArgs Private key is not valid EC Private Key.
|
||||
* @retval kErrorFailed Error during signing.
|
||||
*
|
||||
*/
|
||||
Error Sign(uint8_t *aOutput,
|
||||
uint16_t &aOutputLength,
|
||||
const uint8_t *aInputHash,
|
||||
uint16_t aInputHashLength,
|
||||
const uint8_t *aPrivateKey,
|
||||
uint16_t aPrivateKeyLength);
|
||||
|
||||
/**
|
||||
* @}
|
||||
*
|
||||
|
||||
Reference in New Issue
Block a user