mirror of https://github.com/ARMmbed/mbed-os.git
[NUC472/M487] Fix context clone corner case in SHA alter.
As destination/source contexts are the same, we return immediately.pull/4925/head
parent
d96bcda606
commit
acff29e6f2
|
@ -63,6 +63,11 @@ void mbedtls_sha1_free(mbedtls_sha1_context *ctx)
|
||||||
void mbedtls_sha1_clone(mbedtls_sha1_context *dst,
|
void mbedtls_sha1_clone(mbedtls_sha1_context *dst,
|
||||||
const mbedtls_sha1_context *src)
|
const mbedtls_sha1_context *src)
|
||||||
{
|
{
|
||||||
|
// Corner case: Destination/source contexts are the same
|
||||||
|
if (dst == src) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
// If dst is H/W context, we need to change it to S/W context first before cloning to.
|
// If dst is H/W context, we need to change it to S/W context first before cloning to.
|
||||||
if (dst->active_ctx == &dst->hw_ctx) {
|
if (dst->active_ctx == &dst->hw_ctx) {
|
||||||
mbedtls_sha1_free(dst);
|
mbedtls_sha1_free(dst);
|
||||||
|
|
|
@ -63,6 +63,11 @@ void mbedtls_sha256_free(mbedtls_sha256_context *ctx)
|
||||||
void mbedtls_sha256_clone(mbedtls_sha256_context *dst,
|
void mbedtls_sha256_clone(mbedtls_sha256_context *dst,
|
||||||
const mbedtls_sha256_context *src)
|
const mbedtls_sha256_context *src)
|
||||||
{
|
{
|
||||||
|
// Corner case: Destination/source contexts are the same
|
||||||
|
if (dst == src) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
// If dst is H/W context, we need to change it to S/W context first before cloning to.
|
// If dst is H/W context, we need to change it to S/W context first before cloning to.
|
||||||
if (dst->active_ctx == &dst->hw_ctx) {
|
if (dst->active_ctx == &dst->hw_ctx) {
|
||||||
mbedtls_sha256_free(dst);
|
mbedtls_sha256_free(dst);
|
||||||
|
|
|
@ -63,6 +63,11 @@ void mbedtls_sha512_free(mbedtls_sha512_context *ctx)
|
||||||
void mbedtls_sha512_clone(mbedtls_sha512_context *dst,
|
void mbedtls_sha512_clone(mbedtls_sha512_context *dst,
|
||||||
const mbedtls_sha512_context *src)
|
const mbedtls_sha512_context *src)
|
||||||
{
|
{
|
||||||
|
// Corner case: Destination/source contexts are the same
|
||||||
|
if (dst == src) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
// If dst is H/W context, we need to change it to S/W context first before cloning to.
|
// If dst is H/W context, we need to change it to S/W context first before cloning to.
|
||||||
if (dst->active_ctx == &dst->hw_ctx) {
|
if (dst->active_ctx == &dst->hw_ctx) {
|
||||||
mbedtls_sha512_free(dst);
|
mbedtls_sha512_free(dst);
|
||||||
|
|
|
@ -63,6 +63,11 @@ void mbedtls_sha1_free(mbedtls_sha1_context *ctx)
|
||||||
void mbedtls_sha1_clone(mbedtls_sha1_context *dst,
|
void mbedtls_sha1_clone(mbedtls_sha1_context *dst,
|
||||||
const mbedtls_sha1_context *src)
|
const mbedtls_sha1_context *src)
|
||||||
{
|
{
|
||||||
|
// Corner case: Destination/source contexts are the same
|
||||||
|
if (dst == src) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
// If dst is H/W context, we need to change it to S/W context first before cloning to.
|
// If dst is H/W context, we need to change it to S/W context first before cloning to.
|
||||||
if (dst->active_ctx == &dst->hw_ctx) {
|
if (dst->active_ctx == &dst->hw_ctx) {
|
||||||
mbedtls_sha1_free(dst);
|
mbedtls_sha1_free(dst);
|
||||||
|
|
|
@ -63,6 +63,11 @@ void mbedtls_sha256_free(mbedtls_sha256_context *ctx)
|
||||||
void mbedtls_sha256_clone(mbedtls_sha256_context *dst,
|
void mbedtls_sha256_clone(mbedtls_sha256_context *dst,
|
||||||
const mbedtls_sha256_context *src)
|
const mbedtls_sha256_context *src)
|
||||||
{
|
{
|
||||||
|
// Corner case: Destination/source contexts are the same
|
||||||
|
if (dst == src) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
// If dst is H/W context, we need to change it to S/W context first before cloning to.
|
// If dst is H/W context, we need to change it to S/W context first before cloning to.
|
||||||
if (dst->active_ctx == &dst->hw_ctx) {
|
if (dst->active_ctx == &dst->hw_ctx) {
|
||||||
mbedtls_sha256_free(dst);
|
mbedtls_sha256_free(dst);
|
||||||
|
|
Loading…
Reference in New Issue