diff options
author | Vadim Bendebury <vbendeb@chromium.org> | 2020-04-22 17:38:58 -0700 |
---|---|---|
committer | Commit Bot <commit-bot@chromium.org> | 2020-05-14 07:25:57 +0000 |
commit | 69a887265d737c628a3c55a03b923917cf1b471e (patch) | |
tree | f962af23da7cfdfb8695eca5731c59708bacec9d | |
parent | 8d785e9597c9db3444c01d15dff732bef85fad5a (diff) | |
download | chrome-ec-69a887265d737c628a3c55a03b923917cf1b471e.tar.gz |
crypto_api: use const void
This is a minor API clean up, it is not entirely clear why const void
pointers were not used originally, but using this type for input data
(and void pointer for output) makes interfacing with the library much
easier.
Also modified cases where the first parameter of DCRYPTO_SHA1_hash()
was typecasted unnecessarily.
BUG=none
TEST=make buildall succeeds, Cr50 image supports booting a Chrome OS
device just fine.
Signed-off-by: Vadim Bendebury <vbendeb@chromium.org>
Change-Id: Ic8a670aa7b26598ea323182845c184b7f1d715a1
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/2163568
Reviewed-by: Andrey Pronin <apronin@chromium.org>
-rw-r--r-- | chip/g/crypto_api.c | 8 | ||||
-rw-r--r-- | chip/g/dcrypto/app_cipher.c | 5 | ||||
-rw-r--r-- | chip/g/upgrade_fw.c | 2 | ||||
-rw-r--r-- | chip/host/dcrypto/app_cipher.c | 8 | ||||
-rw-r--r-- | include/crypto_api.h | 4 | ||||
-rw-r--r-- | test/nvmem.c | 6 |
6 files changed, 16 insertions, 17 deletions
diff --git a/chip/g/crypto_api.c b/chip/g/crypto_api.c index 9c0c7bb8f5..075472238d 100644 --- a/chip/g/crypto_api.c +++ b/chip/g/crypto_api.c @@ -7,8 +7,8 @@ #include "crypto_api.h" #include "dcrypto.h" -void app_compute_hash(uint8_t *p_buf, size_t num_bytes, - uint8_t *p_hash, size_t hash_len) +void app_compute_hash(const void *p_buf, size_t num_bytes, void *p_hash, + size_t hash_len) { uint8_t sha1_digest[SHA_DIGEST_SIZE]; @@ -16,12 +16,12 @@ void app_compute_hash(uint8_t *p_buf, size_t num_bytes, * Use the built in dcrypto engine to generate the sha1 hash of the * buffer. */ - DCRYPTO_SHA1_hash((uint8_t *)p_buf, num_bytes, sha1_digest); + DCRYPTO_SHA1_hash(p_buf, num_bytes, sha1_digest); memcpy(p_hash, sha1_digest, MIN(hash_len, sizeof(sha1_digest))); if (hash_len > sizeof(sha1_digest)) - memset(p_hash + sizeof(sha1_digest), 0, + memset((uint8_t *)p_hash + sizeof(sha1_digest), 0, hash_len - sizeof(sha1_digest)); } diff --git a/chip/g/dcrypto/app_cipher.c b/chip/g/dcrypto/app_cipher.c index e465598718..125b443ee6 100644 --- a/chip/g/dcrypto/app_cipher.c +++ b/chip/g/dcrypto/app_cipher.c @@ -323,7 +323,7 @@ static int command_loop(struct test_info *pinfo) * Prepare the hash of the original data to be able to verify * results. */ - DCRYPTO_SHA1_hash((uint8_t *)(pinfo->p), pinfo->test_blob_size, sha); + DCRYPTO_SHA1_hash(pinfo->p, pinfo->test_blob_size, sha); /* Use the hash as an IV for the cipher. */ memcpy(sha_after, sha, sizeof(sha_after)); @@ -369,8 +369,7 @@ static int command_loop(struct test_info *pinfo) return EC_ERROR_UNKNOWN; } - DCRYPTO_SHA1_hash((uint8_t *)(pinfo->p), - pinfo->test_blob_size, sha_after); + DCRYPTO_SHA1_hash(pinfo->p, pinfo->test_blob_size, sha_after); if (memcmp(sha, sha_after, sizeof(sha))) { ccprintf("\n" "sha1 before and after mismatch, %d to go!\n", diff --git a/chip/g/upgrade_fw.c b/chip/g/upgrade_fw.c index 276eac8f92..727af4b7d9 100644 --- a/chip/g/upgrade_fw.c +++ b/chip/g/upgrade_fw.c @@ -148,7 +148,7 @@ int usb_pdu_valid(struct upgrade_command *cmd_body, size_t cmd_size) cmd.block_base); /* Check if the block was received properly. */ - DCRYPTO_SHA1_hash((uint8_t *)&cmd_body->block_base, + DCRYPTO_SHA1_hash(&cmd_body->block_base, body_size + sizeof(cmd_body->block_base), sha1_digest); if (memcmp(sha1_digest, &cmd_body->block_digest, diff --git a/chip/host/dcrypto/app_cipher.c b/chip/host/dcrypto/app_cipher.c index ab52484753..4c4809005c 100644 --- a/chip/host/dcrypto/app_cipher.c +++ b/chip/host/dcrypto/app_cipher.c @@ -6,8 +6,8 @@ #include "dcrypto.h" #include "util.h" -void app_compute_hash(uint8_t *p_buf, size_t num_bytes, - uint8_t *p_hash, size_t hash_len) +void app_compute_hash(const void *p_buf, size_t num_bytes, void *p_hash, + size_t hash_len) { uint8_t digest[SHA256_DIGEST_SIZE]; @@ -15,12 +15,12 @@ void app_compute_hash(uint8_t *p_buf, size_t num_bytes, * Use the built in dcrypto engine to generate the sha1 hash of the * buffer. */ - DCRYPTO_SHA256_hash((uint8_t *)p_buf, num_bytes, digest); + DCRYPTO_SHA256_hash(p_buf, num_bytes, digest); memcpy(p_hash, digest, MIN(hash_len, sizeof(digest))); if (hash_len > sizeof(digest)) - memset(p_hash + sizeof(digest), 0, + memset((uint8_t *)p_hash + sizeof(digest), 0, hash_len - sizeof(digest)); } diff --git a/include/crypto_api.h b/include/crypto_api.h index 8a8ccacf99..d3e3cfaa4a 100644 --- a/include/crypto_api.h +++ b/include/crypto_api.h @@ -26,8 +26,8 @@ extern "C" { * value exceeds SHA1 size (20 bytes), the rest of the * hash is filled up with zeros. */ -void app_compute_hash(uint8_t *p_buf, size_t num_bytes, - uint8_t *p_hash, size_t hash_len); +void app_compute_hash(const void *p_buf, size_t num_bytes, void *p_hash, + size_t hash_len); #define CIPHER_SALT_SIZE 16 diff --git a/test/nvmem.c b/test/nvmem.c index c07637e8de..80ea75479b 100644 --- a/test/nvmem.c +++ b/test/nvmem.c @@ -63,8 +63,8 @@ int app_cipher(const void *salt_p, void *out_p, const void *in_p, size_t size) return 1; } -void app_compute_hash(uint8_t *p_buf, size_t num_bytes, - uint8_t *p_hash, size_t hash_bytes) +void app_compute_hash(const void *p_buf, size_t num_bytes, void *p_hash, + size_t hash_bytes) { uint32_t crc; uint32_t *p_data; @@ -95,7 +95,7 @@ void app_compute_hash(uint8_t *p_buf, size_t num_bytes, for (n = 0; n < hash_bytes; n += sizeof(crc)) { size_t copy_bytes = MIN(sizeof(crc), hash_bytes - n); - memcpy(p_hash + n, &crc, copy_bytes); + memcpy((uint8_t *)p_hash + n, &crc, copy_bytes); } } |