/* * SHA-256 context setup */ void mbedtls_sha256_starts(mbedtls_sha256_context *ctx, int is224) { if (ctx->active_ctx == &ctx->hw_ctx) { mbedtls_sha256_hw_starts(&ctx->hw_ctx, is224); } else if (ctx->active_ctx == &ctx->sw_ctx) { mbedtls_sha256_sw_starts(&ctx->sw_ctx, is224); } }
/* * SHA-256 context setup */ void mbedtls_sha256_starts(mbedtls_sha256_context *ctx, int is224) { if (ctx->ishw) { mbedtls_sha256_hw_starts(&ctx->hw_ctx, is224); } else { mbedtls_sha256_sw_starts(&ctx->sw_ctx, is224); } }
void mbedtls_sha256_hw_finish(crypto_sha_context *ctx, unsigned char output[32]) { // H/W SHA cannot handle zero data well. Fall back to S/W SHA. if (ctx->total) { crypto_sha_update_nobuf(ctx, ctx->buffer, ctx->buffer_left, 1); ctx->buffer_left = 0; crypto_sha_getinternstate(output, ctx->is224 ? 28 : 32); CRPT->SHA_CTL |= CRPT_SHA_CTL_STOP_Msk; } else { mbedtls_sha256_sw_context ctx_sw; mbedtls_sha256_sw_init(&ctx_sw); mbedtls_sha256_sw_starts(&ctx_sw, ctx->is224); mbedtls_sha256_sw_finish(&ctx_sw, output); mbedtls_sha256_sw_free(&ctx_sw); } }