| .. | .. |
|---|
| 38 | 38 | #include <android_avb/avb_sha.h> |
|---|
| 39 | 39 | #include <android_avb/avb_util.h> |
|---|
| 40 | 40 | |
|---|
| 41 | | -/* Crypto-v1 is not support sha512 */ |
|---|
| 42 | | -#ifdef CONFIG_ROCKCHIP_CRYPTO_V2 |
|---|
| 43 | | -void avb_sha512_init(AvbSHA512Ctx* ctx) { |
|---|
| 44 | | - ctx->crypto_ctx.algo = CRYPTO_SHA512; |
|---|
| 45 | | - ctx->crypto_ctx.length = ctx->tot_len; |
|---|
| 46 | | - memset(ctx->buf, 0, sizeof(ctx->buf)); |
|---|
| 47 | | - |
|---|
| 48 | | - ctx->crypto_dev = crypto_get_device(ctx->crypto_ctx.algo); |
|---|
| 49 | | - if (!ctx->crypto_dev) |
|---|
| 50 | | - avb_error("Can't get sha512 crypto device\n"); |
|---|
| 51 | | - else |
|---|
| 52 | | - crypto_sha_init(ctx->crypto_dev, &ctx->crypto_ctx); |
|---|
| 53 | | -} |
|---|
| 54 | | - |
|---|
| 55 | | -void avb_sha512_update(AvbSHA512Ctx* ctx, const uint8_t* data, size_t len) { |
|---|
| 56 | | - if (ctx->crypto_dev) |
|---|
| 57 | | - crypto_sha_update(ctx->crypto_dev, (u32 *)data, len); |
|---|
| 58 | | -} |
|---|
| 59 | | - |
|---|
| 60 | | -uint8_t* avb_sha512_final(AvbSHA512Ctx* ctx) { |
|---|
| 61 | | - if (ctx->crypto_dev) |
|---|
| 62 | | - crypto_sha_final(ctx->crypto_dev, &ctx->crypto_ctx, ctx->buf); |
|---|
| 63 | | - |
|---|
| 64 | | - return ctx->buf; |
|---|
| 65 | | -} |
|---|
| 66 | | - |
|---|
| 67 | | -#else |
|---|
| 68 | 41 | #define SHFR(x, n) (x >> n) |
|---|
| 69 | 42 | #define ROTR(x, n) ((x >> n) | (x << ((sizeof(x) << 3) - n))) |
|---|
| 70 | 43 | #define ROTL(x, n) ((x << n) | (x >> ((sizeof(x) << 3) - n))) |
|---|
| .. | .. |
|---|
| 160 | 133 | /* SHA-512 implementation */ |
|---|
| 161 | 134 | |
|---|
| 162 | 135 | void avb_sha512_init(AvbSHA512Ctx* ctx) { |
|---|
| 136 | +/* Crypto-v1 is not support sha512 */ |
|---|
| 137 | +#ifdef CONFIG_ROCKCHIP_CRYPTO_V2 |
|---|
| 138 | + ctx->crypto_ctx.algo = CRYPTO_SHA512; |
|---|
| 139 | + ctx->crypto_ctx.length = ctx->tot_len; |
|---|
| 140 | + memset(ctx->buf, 0, sizeof(ctx->buf)); |
|---|
| 141 | + |
|---|
| 142 | + ctx->crypto_dev = crypto_get_device(ctx->crypto_ctx.algo); |
|---|
| 143 | + /* If there is no available crypto device, calculate in software instead. */ |
|---|
| 144 | + if (ctx->crypto_dev) { |
|---|
| 145 | + crypto_sha_init(ctx->crypto_dev, &ctx->crypto_ctx); |
|---|
| 146 | + return; |
|---|
| 147 | + } |
|---|
| 148 | +#endif |
|---|
| 163 | 149 | #ifdef UNROLL_LOOPS_SHA512 |
|---|
| 164 | 150 | ctx->h[0] = sha512_h0[0]; |
|---|
| 165 | 151 | ctx->h[1] = sha512_h0[1]; |
|---|
| .. | .. |
|---|
| 347 | 333 | } |
|---|
| 348 | 334 | |
|---|
| 349 | 335 | void avb_sha512_update(AvbSHA512Ctx* ctx, const uint8_t* data, size_t len) { |
|---|
| 336 | +/* Crypto-v1 is not support sha512 */ |
|---|
| 337 | +#ifdef CONFIG_ROCKCHIP_CRYPTO_V2 |
|---|
| 338 | + /* If there is no available crypto device, calculate in software instead. */ |
|---|
| 339 | + if (ctx->crypto_dev) { |
|---|
| 340 | + crypto_sha_update(ctx->crypto_dev, (u32 *)data, len); |
|---|
| 341 | + return; |
|---|
| 342 | + } |
|---|
| 343 | +#endif |
|---|
| 344 | + |
|---|
| 350 | 345 | size_t block_nb; |
|---|
| 351 | 346 | size_t new_len, rem_len, tmp_len; |
|---|
| 352 | 347 | const uint8_t* shifted_data; |
|---|
| .. | .. |
|---|
| 378 | 373 | } |
|---|
| 379 | 374 | |
|---|
| 380 | 375 | uint8_t* avb_sha512_final(AvbSHA512Ctx* ctx) { |
|---|
| 376 | +/* Crypto-v1 is not support sha512 */ |
|---|
| 377 | +#ifdef CONFIG_ROCKCHIP_CRYPTO_V2 |
|---|
| 378 | + /* If there is no available crypto device, calculate in software instead. */ |
|---|
| 379 | + if (ctx->crypto_dev) { |
|---|
| 380 | + crypto_sha_final(ctx->crypto_dev, &ctx->crypto_ctx, ctx->buf); |
|---|
| 381 | + return ctx->buf; |
|---|
| 382 | + } |
|---|
| 383 | +#endif |
|---|
| 384 | + |
|---|
| 381 | 385 | size_t block_nb; |
|---|
| 382 | 386 | size_t pm_len; |
|---|
| 383 | 387 | uint64_t len_b; |
|---|
| .. | .. |
|---|
| 414 | 418 | |
|---|
| 415 | 419 | return ctx->buf; |
|---|
| 416 | 420 | } |
|---|
| 417 | | -#endif |
|---|