From 8609b717aad05a1d2d49cca8727ede94495c1ec1 Mon Sep 17 00:00:00 2001 From: Lin Jinhan Date: Mon, 2 Dec 2019 17:08:39 +0800 Subject: [PATCH] cmd: crypto: unifiy hash output variable rk1808 is not support SHA512. Change-Id: Ica8c1a04553e862915417c36db6362df049e002e Signed-off-by: Lin Jinhan --- cmd/crypto.c | 61 ++++++++++++++++++++++++++++------------------------ 1 file changed, 33 insertions(+), 28 deletions(-) diff --git a/cmd/crypto.c b/cmd/crypto.c index 329ced8ef4..f2e1aaba57 100644 --- a/cmd/crypto.c +++ b/cmd/crypto.c @@ -233,15 +233,8 @@ static int do_crypto(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]) sha256_context sha256_ctx; sha512_context sha512_ctx; rsa_key rsa_key; - u8 sha256_out0[32]; - u8 sha256_out1[32]; - u8 sha1_out0[20]; - u8 sha1_out1[20]; - u8 rsa_out[256]; - u8 md5_out0[16]; - u8 md5_out1[16]; - u8 sha512_out0[64]; - u8 sha512_out1[64]; + u8 hard_out[256]; + u8 soft_out[64]; u32 cap; /* CRYPTO_V1 TODO: SHA512 is not available */ @@ -249,7 +242,10 @@ static int do_crypto(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]) cap = CRYPTO_MD5 | CRYPTO_SHA1 | CRYPTO_SHA256 | CRYPTO_RSA2048; #else - cap = CRYPTO_MD5 | CRYPTO_SHA1 | CRYPTO_SHA256 | CRYPTO_SHA512 | + cap = CRYPTO_MD5 | CRYPTO_SHA1 | CRYPTO_SHA256 | +#if !defined(CONFIG_ROCKCHIP_RK1808) + CRYPTO_SHA512 | +#endif CRYPTO_RSA2048 | CRYPTO_TRNG; #endif dev = crypto_get_device(cap); @@ -262,10 +258,11 @@ static int do_crypto(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]) if (cap & CRYPTO_MD5) { csha_ctx.algo = CRYPTO_MD5; csha_ctx.length = sizeof(foo_data); + memset(hard_out, 0x00, sizeof(hard_out)); crypto_sha_csum(dev, &csha_ctx, (char *)foo_data, - sizeof(foo_data), md5_out0); - md5(foo_data, sizeof(foo_data), md5_out1); - dump_hash("MD5", md5_out0, md5_out1, + sizeof(foo_data), hard_out); + md5(foo_data, sizeof(foo_data), soft_out); + dump_hash("MD5", hard_out, soft_out, crypto_algo_nbits(csha_ctx.algo)); } @@ -273,12 +270,13 @@ static int do_crypto(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]) if (cap & CRYPTO_SHA1) { csha_ctx.algo = CRYPTO_SHA1; csha_ctx.length = sizeof(foo_data); + memset(hard_out, 0x00, sizeof(hard_out)); crypto_sha_csum(dev, &csha_ctx, (char *)foo_data, - sizeof(foo_data), sha1_out0); + sizeof(foo_data), hard_out); sha1_starts(&sha1_ctx); sha1_update(&sha1_ctx, (const u8 *)foo_data, sizeof(foo_data)); - sha1_finish(&sha1_ctx, sha1_out1); - dump_hash("SHA1", sha1_out0, sha1_out1, + sha1_finish(&sha1_ctx, soft_out); + dump_hash("SHA1", hard_out, soft_out, crypto_algo_nbits(csha_ctx.algo)); } @@ -286,13 +284,14 @@ static int do_crypto(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]) if (cap & CRYPTO_SHA512) { csha_ctx.algo = CRYPTO_SHA512; csha_ctx.length = sizeof(foo_data); + memset(hard_out, 0x00, sizeof(hard_out)); crypto_sha_csum(dev, &csha_ctx, (char *)foo_data, - sizeof(foo_data), sha512_out0); + sizeof(foo_data), hard_out); sha512_starts(&sha512_ctx); sha512_update(&sha512_ctx, (const u8 *)foo_data, sizeof(foo_data)); - sha512_finish(&sha512_ctx, sha512_out1); - dump_hash("SHA512", sha512_out0, sha512_out1, + sha512_finish(&sha512_ctx, soft_out); + dump_hash("SHA512", hard_out, soft_out, crypto_algo_nbits(csha_ctx.algo)); } @@ -300,13 +299,14 @@ static int do_crypto(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]) if (cap & CRYPTO_SHA256) { csha_ctx.algo = CRYPTO_SHA256; csha_ctx.length = sizeof(foo_data); + memset(hard_out, 0x00, sizeof(hard_out)); crypto_sha_csum(dev, &csha_ctx, (char *)foo_data, - sizeof(foo_data), sha256_out0); + sizeof(foo_data), hard_out); sha256_starts(&sha256_ctx); sha256_update(&sha256_ctx, (const u8 *)foo_data, sizeof(foo_data)); - sha256_finish(&sha256_ctx, sha256_out1); - dump_hash("SHA256", sha256_out0, sha256_out1, + sha256_finish(&sha256_ctx, soft_out); + dump_hash("SHA256", hard_out, soft_out, crypto_algo_nbits(csha_ctx.algo)); } @@ -319,16 +319,21 @@ static int do_crypto(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]) #ifdef CONFIG_ROCKCHIP_CRYPTO_V1 rsa_key.c = (u32 *)&rsa2048_c; #endif - crypto_rsa_verify(dev, &rsa_key, rsa2048_sha256_sign, rsa_out); - dump_hash("RSA2048-SHA256", rsa_out, - sha256_out1, crypto_algo_nbits(csha_ctx.algo)); + memset(hard_out, 0x00, sizeof(hard_out)); + crypto_rsa_verify(dev, &rsa_key, rsa2048_sha256_sign, hard_out); + sha256_starts(&sha256_ctx); + sha256_update(&sha256_ctx, (const u8 *)foo_data, + sizeof(foo_data)); + sha256_finish(&sha256_ctx, soft_out); + dump_hash("RSA2048-SHA256", hard_out, + soft_out, crypto_algo_nbits(csha_ctx.algo)); } /* TRNG */ if (cap & CRYPTO_TRNG) { - memset(rsa_out, 0x00, sizeof(rsa_out)); - crypto_get_trng(dev, rsa_out, sizeof(rsa_out)); - dump_hex("TRNG", rsa_out, sizeof(rsa_out)); + memset(hard_out, 0x00, sizeof(hard_out)); + crypto_get_trng(dev, hard_out, sizeof(hard_out)); + dump_hex("TRNG", hard_out, sizeof(hard_out)); } return 0;