summaryrefslogtreecommitdiff
path: root/common
diff options
context:
space:
mode:
authorYi Chou <yich@google.com>2023-05-03 13:03:32 +0800
committerChromeos LUCI <chromeos-scoped@luci-project-accounts.iam.gserviceaccount.com>2023-05-04 12:44:48 +0000
commita23038e937126cd4c1d15a714c3d7ea437ce72f7 (patch)
tree37ab2411d78abe1434ffdc7eaea7e95a732463cf /common
parent792817b81f3444374fb6ba625ec5bee5f0a97dc4 (diff)
downloadchrome-ec-a23038e937126cd4c1d15a714c3d7ea437ce72f7.tar.gz
Return the enum type for error and status
BUG=b:248508087 TEST=make V=1 BOARD=bloonchipper -j TEST=make runhosttests TEST=./util/compare_build.sh -b all => MATCH Force-Relevant-Builds: all Change-Id: I0177791509ae37a5d40793e219aedafe1e45430e Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/4502323 Commit-Queue: Yi Chou <yich@google.com> Reviewed-by: Tom Hughes <tomhughes@chromium.org> Tested-by: Yi Chou <yich@google.com>
Diffstat (limited to 'common')
-rw-r--r--common/fpsensor/fpsensor.cc17
-rw-r--r--common/fpsensor/fpsensor_crypto.cc44
-rw-r--r--common/mock/rollback_mock.c2
-rw-r--r--common/rollback.c4
-rw-r--r--common/test_util.c5
5 files changed, 40 insertions, 32 deletions
diff --git a/common/fpsensor/fpsensor.cc b/common/fpsensor/fpsensor.cc
index 7af7082420..77b9cd2d03 100644
--- a/common/fpsensor/fpsensor.cc
+++ b/common/fpsensor/fpsensor.cc
@@ -394,8 +394,9 @@ DECLARE_HOST_COMMAND(EC_CMD_FP_INFO, fp_command_info,
BUILD_ASSERT(FP_CONTEXT_NONCE_BYTES == 12);
-int validate_fp_buffer_offset(const uint32_t buffer_size, const uint32_t offset,
- const uint32_t size)
+enum ec_error_list validate_fp_buffer_offset(const uint32_t buffer_size,
+ const uint32_t offset,
+ const uint32_t size)
{
uint32_t bytes_requested;
@@ -419,7 +420,7 @@ static enum ec_status fp_command_frame(struct host_cmd_handler_args *args)
uint16_t fgr;
uint8_t key[SBP_ENC_KEY_LEN];
struct ec_fp_template_encryption_metadata *enc_info;
- int ret;
+ enum ec_error_list ret;
if (size > args->response_max)
return EC_RES_INVALID_PARAM;
@@ -561,7 +562,7 @@ static bool template_needs_validation_value(
return enc_info->struct_version == 3 && FP_TEMPLATE_FORMAT_VERSION == 4;
}
-static int
+static enum ec_status
validate_template_format(struct ec_fp_template_encryption_metadata *enc_info)
{
if (template_needs_validation_value(enc_info))
@@ -585,7 +586,6 @@ static enum ec_status fp_command_template(struct host_cmd_handler_args *args)
uint16_t idx = templ_valid;
uint8_t key[SBP_ENC_KEY_LEN];
struct ec_fp_template_encryption_metadata *enc_info;
- int ret;
/* Can we store one more template ? */
if (idx >= FP_MAX_FINGER_COUNT)
@@ -594,7 +594,8 @@ static enum ec_status fp_command_template(struct host_cmd_handler_args *args)
if (args->params_size !=
size + offsetof(struct ec_params_fp_template, data))
return EC_RES_INVALID_PARAM;
- ret = validate_fp_buffer_offset(sizeof(fp_enc_buffer), offset, size);
+ enum ec_error_list ret =
+ validate_fp_buffer_offset(sizeof(fp_enc_buffer), offset, size);
if (ret != EC_SUCCESS)
return EC_RES_INVALID_PARAM;
@@ -621,8 +622,8 @@ static enum ec_status fp_command_template(struct host_cmd_handler_args *args)
*/
enc_info = (struct ec_fp_template_encryption_metadata *)
fp_enc_buffer;
- ret = validate_template_format(enc_info);
- if (ret != EC_RES_SUCCESS) {
+ enum ec_status res = validate_template_format(enc_info);
+ if (res != EC_RES_SUCCESS) {
CPRINTS("fgr%d: Template format not supported", idx);
return EC_RES_INVALID_PARAM;
}
diff --git a/common/fpsensor/fpsensor_crypto.cc b/common/fpsensor/fpsensor_crypto.cc
index 7d950b8974..19efc4d068 100644
--- a/common/fpsensor/fpsensor_crypto.cc
+++ b/common/fpsensor/fpsensor_crypto.cc
@@ -31,9 +31,9 @@ test_mockable void compute_hmac_sha256(uint8_t *output, const uint8_t *key,
#error "fpsensor requires CONFIG_BORINGSSL_CRYPTO and ROLLBACK_SECRET_SIZE"
#endif
-test_export_static int get_ikm(uint8_t *ikm)
+test_export_static enum ec_error_list get_ikm(uint8_t *ikm)
{
- int ret;
+ enum ec_error_list ret;
if (!fp_tpm_seed_is_set()) {
CPRINTS("Seed hasn't been set.");
@@ -76,9 +76,10 @@ static void hkdf_extract(uint8_t *prk, const uint8_t *salt, size_t salt_size,
compute_hmac_sha256(prk, salt, salt_size, ikm, ikm_size);
}
-static int hkdf_expand_one_step(uint8_t *out_key, size_t out_key_size,
- uint8_t *prk, size_t prk_size, uint8_t *info,
- size_t info_size)
+static enum ec_error_list hkdf_expand_one_step(uint8_t *out_key,
+ size_t out_key_size,
+ uint8_t *prk, size_t prk_size,
+ uint8_t *info, size_t info_size)
{
uint8_t key_buf[SHA256_DIGEST_SIZE];
uint8_t message_buf[SHA256_DIGEST_SIZE + 1];
@@ -105,8 +106,9 @@ static int hkdf_expand_one_step(uint8_t *out_key, size_t out_key_size,
return EC_SUCCESS;
}
-int hkdf_expand(uint8_t *out_key, size_t L, const uint8_t *prk, size_t prk_size,
- const uint8_t *info, size_t info_size)
+enum ec_error_list hkdf_expand(uint8_t *out_key, size_t L, const uint8_t *prk,
+ size_t prk_size, const uint8_t *info,
+ size_t info_size)
{
/*
* "Expand" step of HKDF.
@@ -161,10 +163,11 @@ int hkdf_expand(uint8_t *out_key, size_t L, const uint8_t *prk, size_t prk_size,
#undef HASH_LEN
}
-int derive_positive_match_secret(uint8_t *output,
- const uint8_t *input_positive_match_salt)
+enum ec_error_list
+derive_positive_match_secret(uint8_t *output,
+ const uint8_t *input_positive_match_salt)
{
- int ret;
+ enum ec_error_list ret;
uint8_t ikm[CONFIG_ROLLBACK_SECRET_SIZE + sizeof(tpm_seed)];
uint8_t prk[SHA256_DIGEST_SIZE];
static const char info_prefix[] = "positive_match_secret for user ";
@@ -205,9 +208,9 @@ int derive_positive_match_secret(uint8_t *output,
return ret;
}
-int derive_encryption_key(uint8_t *out_key, const uint8_t *salt)
+enum ec_error_list derive_encryption_key(uint8_t *out_key, const uint8_t *salt)
{
- int ret;
+ enum ec_error_list ret;
uint8_t ikm[CONFIG_ROLLBACK_SECRET_SIZE + sizeof(tpm_seed)];
uint8_t prk[SHA256_DIGEST_SIZE];
@@ -239,9 +242,11 @@ int derive_encryption_key(uint8_t *out_key, const uint8_t *salt)
return ret;
}
-int aes_gcm_encrypt(const uint8_t *key, int key_size, const uint8_t *plaintext,
- uint8_t *ciphertext, int text_size, const uint8_t *nonce,
- int nonce_size, uint8_t *tag, int tag_size)
+enum ec_error_list aes_gcm_encrypt(const uint8_t *key, int key_size,
+ const uint8_t *plaintext,
+ uint8_t *ciphertext, int text_size,
+ const uint8_t *nonce, int nonce_size,
+ uint8_t *tag, int tag_size)
{
int res;
AES_KEY aes_key;
@@ -271,10 +276,11 @@ int aes_gcm_encrypt(const uint8_t *key, int key_size, const uint8_t *plaintext,
return EC_SUCCESS;
}
-int aes_gcm_decrypt(const uint8_t *key, int key_size, uint8_t *plaintext,
- const uint8_t *ciphertext, int text_size,
- const uint8_t *nonce, int nonce_size, const uint8_t *tag,
- int tag_size)
+enum ec_error_list aes_gcm_decrypt(const uint8_t *key, int key_size,
+ uint8_t *plaintext,
+ const uint8_t *ciphertext, int text_size,
+ const uint8_t *nonce, int nonce_size,
+ const uint8_t *tag, int tag_size)
{
int res;
AES_KEY aes_key;
diff --git a/common/mock/rollback_mock.c b/common/mock/rollback_mock.c
index 9395248a61..5b1be063c6 100644
--- a/common/mock/rollback_mock.c
+++ b/common/mock/rollback_mock.c
@@ -31,7 +31,7 @@ static const uint8_t fake_rollback_secret[] = {
BUILD_ASSERT(sizeof(fake_rollback_secret) == CONFIG_ROLLBACK_SECRET_SIZE);
/* Mock the rollback for unit or fuzz tests. */
-int rollback_get_secret(uint8_t *secret)
+enum ec_error_list rollback_get_secret(uint8_t *secret)
{
if (mock_ctrl_rollback.get_secret_fail)
return EC_ERROR_UNKNOWN;
diff --git a/common/rollback.c b/common/rollback.c
index e2860f86f7..8e29b97d28 100644
--- a/common/rollback.c
+++ b/common/rollback.c
@@ -153,9 +153,9 @@ failed:
}
#ifdef CONFIG_ROLLBACK_SECRET_SIZE
-test_mockable int rollback_get_secret(uint8_t *secret)
+test_mockable enum ec_error_list rollback_get_secret(uint8_t *secret)
{
- int ret = EC_ERROR_UNKNOWN;
+ enum ec_error_list ret = EC_ERROR_UNKNOWN;
struct rollback_data data;
if (get_latest_rollback(&data) < 0)
diff --git a/common/test_util.c b/common/test_util.c
index fd8caba10a..9316b36bf1 100644
--- a/common/test_util.c
+++ b/common/test_util.c
@@ -173,8 +173,9 @@ void test_run_multistep(void)
}
#ifdef HAS_TASK_HOSTCMD
-int test_send_host_command(int command, int version, const void *params,
- int params_size, void *resp, int resp_size)
+enum ec_status test_send_host_command(int command, int version,
+ const void *params, int params_size,
+ void *resp, int resp_size)
{
struct host_cmd_handler_args args;