-
Notifications
You must be signed in to change notification settings - Fork 31
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: added EcDsa256 bit support for sign and verify (#651)
* add key256 in upgrade keys * updated security_key_generator for 256bit ecDsa key * imageSignerEcDsa 224+256 support * added verifierEcDsa for 256bit * upgraderPackBuilderFacade support both 224 and 256 ecdsa key * added unit test for material generator, fixed review comments * fix sonarqube and build without mbedtls * only include material generator test for emil_inlcude_mbedtls * reworked after review
- Loading branch information
Showing
17 changed files
with
794 additions
and
254 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,29 +1,66 @@ | ||
#include "upgrade/boot_loader/VerifierEcDsa.hpp" | ||
#include "infra/util/ByteRange.hpp" | ||
#include "infra/util/MemoryRange.hpp" | ||
#include "mbedtls/sha256.h" | ||
#include "uECC.h" | ||
|
||
namespace application | ||
{ | ||
VerifierEcDsa::VerifierEcDsa(infra::ConstByteRange key) | ||
: key(key) | ||
{ | ||
assert(key.size() == 56); | ||
} | ||
{} | ||
|
||
bool VerifierEcDsa::IsValid(hal::SynchronousFlash& flash, const hal::SynchronousFlash::Range& signature, const hal::SynchronousFlash::Range& data) const | ||
{ | ||
std::array<uint8_t, 32> messageHash = Hash(flash, data); | ||
std::array<uint8_t, 56> storedSignature; | ||
auto storedSignature = GetSignatureStorage(signature); | ||
|
||
if (signature.second - signature.first != storedSignature.size()) | ||
if (storedSignature.empty()) | ||
return false; | ||
|
||
flash.ReadBuffer(storedSignature, signature.first); | ||
|
||
return uECC_verify(key.begin(), | ||
messageHash.data(), | ||
messageHash.size(), | ||
storedSignature.data(), | ||
uECC_secp224r1()) == 1; | ||
storedSignature.begin(), | ||
GetCurve()) == 1; | ||
} | ||
|
||
VerifierEcDsa224::VerifierEcDsa224(infra::ConstByteRange key) | ||
: VerifierEcDsa(key) | ||
{ | ||
assert(key.size() == signSize); | ||
} | ||
|
||
infra::ByteRange VerifierEcDsa224::GetSignatureStorage(const hal::SynchronousFlash::Range& signature) const | ||
{ | ||
if (signature.second - signature.first != signatureStorage.size()) | ||
return infra::ByteRange(); | ||
else | ||
return infra::MakeRange(signatureStorage); | ||
} | ||
|
||
uECC_Curve VerifierEcDsa224::GetCurve() const | ||
{ | ||
return uECC_secp224r1(); | ||
} | ||
|
||
VerifierEcDsa256::VerifierEcDsa256(infra::ConstByteRange key) | ||
: VerifierEcDsa(key) | ||
{ | ||
assert(key.size() == signSize); | ||
} | ||
|
||
infra::ByteRange VerifierEcDsa256::GetSignatureStorage(const hal::SynchronousFlash::Range& signature) const | ||
{ | ||
if (signature.second - signature.first != signatureStorage.size()) | ||
return infra::ByteRange(); | ||
else | ||
return infra::MakeRange(signatureStorage); | ||
} | ||
|
||
uECC_Curve VerifierEcDsa256::GetCurve() const | ||
{ | ||
return uECC_secp256r1(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.