hc
2023-11-06 9df731a176aab8e03b984b681b1bea01ccff6644
u-boot/lib/avb/libavb/avb_sha512.c
....@@ -38,33 +38,6 @@
3838 #include <android_avb/avb_sha.h>
3939 #include <android_avb/avb_util.h>
4040
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
6841 #define SHFR(x, n) (x >> n)
6942 #define ROTR(x, n) ((x >> n) | (x << ((sizeof(x) << 3) - n)))
7043 #define ROTL(x, n) ((x << n) | (x >> ((sizeof(x) << 3) - n)))
....@@ -160,6 +133,19 @@
160133 /* SHA-512 implementation */
161134
162135 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
163149 #ifdef UNROLL_LOOPS_SHA512
164150 ctx->h[0] = sha512_h0[0];
165151 ctx->h[1] = sha512_h0[1];
....@@ -347,6 +333,15 @@
347333 }
348334
349335 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
+
350345 size_t block_nb;
351346 size_t new_len, rem_len, tmp_len;
352347 const uint8_t* shifted_data;
....@@ -378,6 +373,15 @@
378373 }
379374
380375 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
+
381385 size_t block_nb;
382386 size_t pm_len;
383387 uint64_t len_b;
....@@ -414,4 +418,3 @@
414418
415419 return ctx->buf;
416420 }
417
-#endif