@@ -74,10 +74,15 @@ void mbedtls_sha256_starts( mbedtls_sha256_context *ctx, int is224 )
74
74
void mbedtls_sha256_process ( mbedtls_sha256_context * ctx , const unsigned char data [MBEDTLS_SHA256_BLOCK_SIZE ] )
75
75
{
76
76
if (ctx -> is224 == 0 ) {
77
- HAL_HASHEx_SHA256_Accumulate (& ctx -> hhash_sha256 , (uint8_t * ) data , MBEDTLS_SHA256_BLOCK_SIZE );
77
+ if (HAL_HASHEx_SHA256_Accumulate (& ctx -> hhash_sha256 , (uint8_t * ) data , MBEDTLS_SHA256_BLOCK_SIZE ) != 0 ) {
78
+ // return 0; // Return error code
79
+ }
78
80
} else {
79
- HAL_HASHEx_SHA224_Accumulate (& ctx -> hhash_sha256 , (uint8_t * ) data , MBEDTLS_SHA256_BLOCK_SIZE );
81
+ if (HAL_HASHEx_SHA224_Accumulate (& ctx -> hhash_sha256 , (uint8_t * ) data , MBEDTLS_SHA256_BLOCK_SIZE ) != 0 ) {
82
+ // return 0; // Return error code
83
+ }
80
84
}
85
+ // return 1;
81
86
}
82
87
83
88
void mbedtls_sha256_update ( mbedtls_sha256_context * ctx , const unsigned char * input , size_t ilen )
@@ -107,9 +112,13 @@ void mbedtls_sha256_update( mbedtls_sha256_context *ctx, const unsigned char *in
107
112
// now process every input as long as it is %4 bytes
108
113
size_t iter = currentlen / 4 ;
109
114
if (ctx -> is224 == 0 ) {
110
- HAL_HASHEx_SHA256_Accumulate (& ctx -> hhash_sha256 , (uint8_t * )(input + MBEDTLS_SHA256_BLOCK_SIZE - ctx -> sbuf_len ), (iter * 4 ));
115
+ if (HAL_HASHEx_SHA256_Accumulate (& ctx -> hhash_sha256 , (uint8_t * )(input + MBEDTLS_SHA256_BLOCK_SIZE - ctx -> sbuf_len ), (iter * 4 )) != 0 ) {
116
+ //return 1; // Return error code here
117
+ }
111
118
} else {
112
- HAL_HASHEx_SHA224_Accumulate (& ctx -> hhash_sha256 , (uint8_t * )(input + MBEDTLS_SHA256_BLOCK_SIZE - ctx -> sbuf_len ), (iter * 4 ));
119
+ if (HAL_HASHEx_SHA224_Accumulate (& ctx -> hhash_sha256 , (uint8_t * )(input + MBEDTLS_SHA256_BLOCK_SIZE - ctx -> sbuf_len ), (iter * 4 )) != 0 ) {
120
+ //return 1; // Return error code here
121
+ }
113
122
}
114
123
// sbuf is now fully accumulated, now copy 1 / 2 or 3 remaining bytes
115
124
ctx -> sbuf_len = currentlen % 4 ;
@@ -123,19 +132,28 @@ void mbedtls_sha256_finish( mbedtls_sha256_context *ctx, unsigned char output[32
123
132
{
124
133
if (ctx -> sbuf_len > 0 ) {
125
134
if (ctx -> is224 == 0 ) {
126
- HAL_HASHEx_SHA256_Accumulate (& ctx -> hhash_sha256 , ctx -> sbuf , ctx -> sbuf_len );
135
+ if (HAL_HASHEx_SHA256_Accumulate (& ctx -> hhash_sha256 , ctx -> sbuf , ctx -> sbuf_len ) != 0 ) {
136
+ //return 1; // Return error code here
137
+ }
127
138
} else {
128
- HAL_HASHEx_SHA224_Accumulate (& ctx -> hhash_sha256 , ctx -> sbuf , ctx -> sbuf_len );
139
+ if (HAL_HASHEx_SHA224_Accumulate (& ctx -> hhash_sha256 , ctx -> sbuf , ctx -> sbuf_len ) != 0 ) {
140
+ //return 1; // Return error code here
141
+ }
129
142
}
130
143
}
131
144
mbedtls_zeroize (ctx -> sbuf , MBEDTLS_SHA256_BLOCK_SIZE );
132
145
ctx -> sbuf_len = 0 ;
133
146
__HAL_HASH_START_DIGEST ();
134
147
135
- if (ctx -> is224 == 0 )
136
- HAL_HASHEx_SHA256_Finish (& ctx -> hhash_sha256 , output , 10 );
137
- else
138
- HAL_HASHEx_SHA224_Finish (& ctx -> hhash_sha256 , output , 10 );
148
+ if (ctx -> is224 == 0 ) {
149
+ if (HAL_HASHEx_SHA256_Finish (& ctx -> hhash_sha256 , output , 10 ) != 0 ) {
150
+ //return 1; // Return error code here
151
+ }
152
+ } else {
153
+ if (HAL_HASHEx_SHA224_Finish (& ctx -> hhash_sha256 , output , 10 ) != 0 ) {
154
+ //return 1; // Return error code here
155
+ }
156
+ }
139
157
}
140
158
141
159
#endif /*MBEDTLS_SHA256_ALT*/
0 commit comments