File tree Expand file tree Collapse file tree 5 files changed +75
-0
lines changed
features/mbedtls/targets/TARGET_NUVOTON Expand file tree Collapse file tree 5 files changed +75
-0
lines changed Original file line number Diff line number Diff line change @@ -51,6 +51,21 @@ void mbedtls_sha1_free(mbedtls_sha1_context *ctx)
51
51
void mbedtls_sha1_clone (mbedtls_sha1_context * dst ,
52
52
const mbedtls_sha1_context * src )
53
53
{
54
+ // If dst is H/W context, we need to change it to S/W context first before cloning to.
55
+ while (dst -> ishw ) {
56
+ mbedtls_sha1_free (dst );
57
+ // We just want S/W context, so we lock SHA H/W resource if it is available.
58
+ if (crypto_sha_acquire ()) {
59
+ mbedtls_sha1_init (dst );
60
+ crypto_sha_release ();
61
+ }
62
+ else {
63
+ mbedtls_sha1_init (dst );
64
+ }
65
+
66
+ // We still have potential to get H/W context due to race condition. Retry if need be.
67
+ }
68
+
54
69
if (src -> ishw ) {
55
70
// Clone S/W ctx from H/W ctx
56
71
dst -> ishw = 0 ;
Original file line number Diff line number Diff line change @@ -51,6 +51,21 @@ void mbedtls_sha256_free(mbedtls_sha256_context *ctx)
51
51
void mbedtls_sha256_clone (mbedtls_sha256_context * dst ,
52
52
const mbedtls_sha256_context * src )
53
53
{
54
+ // If dst is H/W context, we need to change it to S/W context first before cloning to.
55
+ while (dst -> ishw ) {
56
+ mbedtls_sha256_free (dst );
57
+ // We just want S/W context, so we lock SHA H/W resource if it is available.
58
+ if (crypto_sha_acquire ()) {
59
+ mbedtls_sha256_init (dst );
60
+ crypto_sha_release ();
61
+ }
62
+ else {
63
+ mbedtls_sha256_init (dst );
64
+ }
65
+
66
+ // We still have potential to get H/W context due to race condition. Retry if need be.
67
+ }
68
+
54
69
if (src -> ishw ) {
55
70
// Clone S/W ctx from H/W ctx
56
71
dst -> ishw = 0 ;
Original file line number Diff line number Diff line change @@ -51,6 +51,21 @@ void mbedtls_sha512_free(mbedtls_sha512_context *ctx)
51
51
void mbedtls_sha512_clone (mbedtls_sha512_context * dst ,
52
52
const mbedtls_sha512_context * src )
53
53
{
54
+ // If dst is H/W context, we need to change it to S/W context first before cloning to.
55
+ while (dst -> ishw ) {
56
+ mbedtls_sha512_free (dst );
57
+ // We just want S/W context, so we lock SHA H/W resource if it is available.
58
+ if (crypto_sha_acquire ()) {
59
+ mbedtls_sha512_init (dst );
60
+ crypto_sha_release ();
61
+ }
62
+ else {
63
+ mbedtls_sha512_init (dst );
64
+ }
65
+
66
+ // We still have potential to get H/W context due to race condition. Retry if need be.
67
+ }
68
+
54
69
if (src -> ishw ) {
55
70
// Clone S/W ctx from H/W ctx
56
71
dst -> ishw = 0 ;
Original file line number Diff line number Diff line change @@ -51,6 +51,21 @@ void mbedtls_sha1_free(mbedtls_sha1_context *ctx)
51
51
void mbedtls_sha1_clone (mbedtls_sha1_context * dst ,
52
52
const mbedtls_sha1_context * src )
53
53
{
54
+ // If dst is H/W context, we need to change it to S/W context first before cloning to.
55
+ while (dst -> ishw ) {
56
+ mbedtls_sha1_free (dst );
57
+ // We just want S/W context, so we lock SHA H/W resource if it is available.
58
+ if (crypto_sha_acquire ()) {
59
+ mbedtls_sha1_init (dst );
60
+ crypto_sha_release ();
61
+ }
62
+ else {
63
+ mbedtls_sha1_init (dst );
64
+ }
65
+
66
+ // We still have potential to get H/W context due to race condition. Retry if need be.
67
+ }
68
+
54
69
if (src -> ishw ) {
55
70
// Clone S/W ctx from H/W ctx
56
71
dst -> ishw = 0 ;
Original file line number Diff line number Diff line change @@ -51,6 +51,21 @@ void mbedtls_sha256_free(mbedtls_sha256_context *ctx)
51
51
void mbedtls_sha256_clone (mbedtls_sha256_context * dst ,
52
52
const mbedtls_sha256_context * src )
53
53
{
54
+ // If dst is H/W context, we need to change it to S/W context first before cloning to.
55
+ while (dst -> ishw ) {
56
+ mbedtls_sha256_free (dst );
57
+ // We just want S/W context, so we lock SHA H/W resource if it is available.
58
+ if (crypto_sha_acquire ()) {
59
+ mbedtls_sha256_init (dst );
60
+ crypto_sha_release ();
61
+ }
62
+ else {
63
+ mbedtls_sha256_init (dst );
64
+ }
65
+
66
+ // We still have potential to get H/W context due to race condition. Retry if need be.
67
+ }
68
+
54
69
if (src -> ishw ) {
55
70
// Clone S/W ctx from H/W ctx
56
71
dst -> ishw = 0 ;
You can’t perform that action at this time.
0 commit comments