@@ -14,6 +14,12 @@ void common_hal_hashlib_hash_update(hashlib_hash_obj_t *self, const uint8_t *dat
1414 mbedtls_sha1_update_ret (& self -> sha1 , data , datalen );
1515 return ;
1616 }
17+ #if CIRCUITPY_HASHLIB_SHA256
18+ else if (self -> hash_type == MBEDTLS_SSL_HASH_SHA256 ) {
19+ mbedtls_sha256_update_ret (& self -> sha256 , data , datalen );
20+ return ;
21+ }
22+ #endif
1723}
1824
1925void common_hal_hashlib_hash_digest (hashlib_hash_obj_t * self , uint8_t * data , size_t datalen ) {
@@ -28,11 +34,25 @@ void common_hal_hashlib_hash_digest(hashlib_hash_obj_t *self, uint8_t *data, siz
2834 mbedtls_sha1_finish_ret (& self -> sha1 , data );
2935 mbedtls_sha1_clone (& self -> sha1 , & copy );
3036 }
37+ #if CIRCUITPY_HASHLIB_SHA256
38+ else if (self -> hash_type == MBEDTLS_SSL_HASH_SHA256 ) {
39+ mbedtls_sha256_context copy ;
40+ mbedtls_sha256_clone (& copy , & self -> sha256 );
41+ mbedtls_sha256_finish_ret (& self -> sha256 , data );
42+ mbedtls_sha256_clone (& self -> sha256 , & copy );
43+ }
44+ #endif
3145}
3246
3347size_t common_hal_hashlib_hash_get_digest_size (hashlib_hash_obj_t * self ) {
3448 if (self -> hash_type == MBEDTLS_SSL_HASH_SHA1 ) {
3549 return 20 ;
3650 }
51+ #if CIRCUITPY_HASHLIB_SHA256
52+ else if (self -> hash_type == MBEDTLS_SSL_HASH_SHA256 ) {
53+ return 32 ;
54+ }
55+ #endif
56+
3757 return 0 ;
3858}
0 commit comments