/* Choose SHA S/W or H/W context and initialize it * * try_hw: * 0: Initialize S/W context * 1: Try acquiring SHA H/W resource first and initialize its H/W context if successful. If failed, initialize S/W context. */ static void mbedtls_sha256_init_internal(mbedtls_sha256_context *ctx, int try_hw) { if (try_hw && crypto_sha_acquire()) { ctx->active_ctx = &ctx->hw_ctx; mbedtls_sha256_hw_init(&ctx->hw_ctx); } else { ctx->active_ctx = &ctx->sw_ctx; mbedtls_sha256_sw_init(&ctx->sw_ctx); } }
void mbedtls_sha256_init(mbedtls_sha256_context *ctx) { if (crypto_sha_acquire()) { ctx->ishw = 1; mbedtls_sha256_hw_init(&ctx->hw_ctx); } else { ctx->ishw = 0; mbedtls_sha256_sw_init(&ctx->sw_ctx); } }