summaryrefslogtreecommitdiff
path: root/host/lib
diff options
context:
space:
mode:
authorJoel Kitching <kitching@google.com>2019-07-31 14:12:30 +0800
committerCommit Bot <commit-bot@chromium.org>2019-08-13 04:36:52 +0000
commite6700f4c70fe72850ae4f3f5df19c9281ebcefc8 (patch)
tree0f2abff7be99bc140e288058fb2eeab6f8bb8b64 /host/lib
parenta5afd01feb0b4b45adbcd8ab38ab8a2ef2a2ef67 (diff)
downloadvboot-e6700f4c70fe72850ae4f3f5df19c9281ebcefc8.tar.gz
vboot: update vboot2 functions to use new vb2_error_t
To make explicit when vboot2 error codes should be returned, use the new vb2_error_t type on all functions which return VB2_ERROR_* constants. BUG=b:124141368, chromium:988410 TEST=make clean && make runtests BRANCH=none Change-Id: Idd3ee8afe8c78347783ce5fa829cb78f1e5719e2 Signed-off-by: Joel Kitching <kitching@google.com> Cq-Depend: chromium:1728113, chromium:1728499 Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/vboot_reference/+/1728292 Reviewed-by: Joel Kitching <kitching@chromium.org> Commit-Queue: Joel Kitching <kitching@chromium.org> Tested-by: Joel Kitching <kitching@chromium.org>
Diffstat (limited to 'host/lib')
-rw-r--r--host/lib/crossystem.c2
-rw-r--r--host/lib/file_keys.c4
-rw-r--r--host/lib/host_key2.c22
-rw-r--r--host/lib/host_misc.c2
-rw-r--r--host/lib/host_signature.c10
-rw-r--r--host/lib/host_signature2.c4
-rw-r--r--host/lib/include/file_keys.h4
-rw-r--r--host/lib/include/host_key.h21
-rw-r--r--host/lib/include/host_misc.h10
-rw-r--r--host/lib/include/host_signature.h10
10 files changed, 43 insertions, 46 deletions
diff --git a/host/lib/crossystem.c b/host/lib/crossystem.c
index 2b13258f..c8938225 100644
--- a/host/lib/crossystem.c
+++ b/host/lib/crossystem.c
@@ -187,7 +187,7 @@ static VbBuildOption VbScanBuildOption(void)
/* Determine whether the running OS image was built for debugging.
* Returns 1 if yes, 0 if no or indeterminate. */
-static int VbGetDebugBuild(void)
+static vb2_error_t VbGetDebugBuild(void)
{
return VB_BUILD_OPTION_DEBUG == VbScanBuildOption();
}
diff --git a/host/lib/file_keys.c b/host/lib/file_keys.c
index 7df7ceb2..e47091de 100644
--- a/host/lib/file_keys.c
+++ b/host/lib/file_keys.c
@@ -21,8 +21,8 @@
#include "host_common.h"
#include "signature_digest.h"
-int DigestFile(char *input_file, enum vb2_hash_algorithm alg,
- uint8_t *digest, uint32_t digest_size)
+vb2_error_t DigestFile(char *input_file, enum vb2_hash_algorithm alg,
+ uint8_t *digest, uint32_t digest_size)
{
int input_fd, len;
uint8_t data[VB2_SHA1_BLOCK_SIZE];
diff --git a/host/lib/host_key2.c b/host/lib/host_key2.c
index 64aab1b4..b76ac2ae 100644
--- a/host/lib/host_key2.c
+++ b/host/lib/host_key2.c
@@ -25,8 +25,8 @@
#include "vboot_common.h"
enum vb2_crypto_algorithm vb2_get_crypto_algorithm(
- enum vb2_hash_algorithm hash_alg,
- enum vb2_signature_algorithm sig_alg)
+ enum vb2_hash_algorithm hash_alg,
+ enum vb2_signature_algorithm sig_alg)
{
/* Make sure algorithms are in the range supported by crypto alg */
if (sig_alg < VB2_SIG_RSA1024 || sig_alg >= VB2_SIG_ALG_COUNT)
@@ -76,8 +76,8 @@ struct vb2_private_key *vb2_read_private_key(const char *filename)
}
struct vb2_private_key *vb2_read_private_key_pem(
- const char* filename,
- enum vb2_crypto_algorithm algorithm)
+ const char* filename,
+ enum vb2_crypto_algorithm algorithm)
{
if (algorithm >= VB2_ALG_COUNT) {
VB2_DEBUG("%s() called with invalid algorithm!\n",
@@ -124,8 +124,8 @@ void vb2_free_private_key(struct vb2_private_key *key)
free(key);
}
-int vb2_write_private_key(const char *filename,
- const struct vb2_private_key *key)
+vb2_error_t vb2_write_private_key(const char *filename,
+ const struct vb2_private_key *key)
{
/* Convert back to legacy vb1 algorithm enum */
uint64_t alg = vb2_get_crypto_algorithm(key->hash_alg, key->sig_alg);
@@ -187,8 +187,8 @@ struct vb2_packed_key *vb2_alloc_packed_key(uint32_t key_size,
return key;
}
-int vb2_copy_packed_key(struct vb2_packed_key *dest,
- const struct vb2_packed_key *src)
+vb2_error_t vb2_copy_packed_key(struct vb2_packed_key *dest,
+ const struct vb2_packed_key *src)
{
if (dest->key_size < src->key_size)
return VB2_ERROR_COPY_KEY_SIZE;
@@ -260,8 +260,8 @@ struct vb2_packed_key *vb2_read_packed_keyb(const char *filename,
return key;
}
-int vb2_write_packed_key(const char *filename,
- const struct vb2_packed_key *key)
+vb2_error_t vb2_write_packed_key(const char *filename,
+ const struct vb2_packed_key *key)
{
/* Copy the key, so its data is contiguous with the header */
struct vb2_packed_key *kcopy =
@@ -274,7 +274,7 @@ int vb2_write_packed_key(const char *filename,
}
/* Write the copy, then free it */
- int rv = vb2_write_file(filename, kcopy,
+ vb2_error_t rv = vb2_write_file(filename, kcopy,
kcopy->key_offset + kcopy->key_size);
free(kcopy);
return rv;
diff --git a/host/lib/host_misc.c b/host/lib/host_misc.c
index 250ca99d..3dc6112f 100644
--- a/host/lib/host_misc.c
+++ b/host/lib/host_misc.c
@@ -99,7 +99,7 @@ int ReadFileBit(const char* filename, int bitmask)
else return (value & bitmask ? 1 : 0);
}
-int WriteFile(const char* filename, const void *data, uint64_t size)
+vb2_error_t WriteFile(const char* filename, const void *data, uint64_t size)
{
FILE *f = fopen(filename, "wb");
if (!f) {
diff --git a/host/lib/host_signature.c b/host/lib/host_signature.c
index 22e52c97..cfa40d10 100644
--- a/host/lib/host_signature.c
+++ b/host/lib/host_signature.c
@@ -28,11 +28,8 @@
* [inbuf] passed redirected to stdin, and the stdout of the command is put
* back into [outbuf]. Returns -1 on error, 0 on success.
*/
-static int sign_external(uint32_t size,
- const uint8_t *inbuf,
- uint8_t *outbuf,
- uint32_t outbufsize,
- const char *pem_file,
+static int sign_external(uint32_t size, const uint8_t *inbuf, uint8_t *outbuf,
+ uint32_t outbufsize, const char *pem_file,
const char *external_signer)
{
int rv = 0, n;
@@ -113,8 +110,7 @@ static int sign_external(uint32_t size,
return rv;
}
-struct vb2_signature *vb2_external_signature(const uint8_t *data,
- uint32_t size,
+struct vb2_signature *vb2_external_signature(const uint8_t *data, uint32_t size,
const char *key_file,
uint32_t key_algorithm,
const char *external_signer)
diff --git a/host/lib/host_signature2.c b/host/lib/host_signature2.c
index 6baff961..2105bd90 100644
--- a/host/lib/host_signature2.c
+++ b/host/lib/host_signature2.c
@@ -49,8 +49,8 @@ void vb2_init_signature(struct vb2_signature *sig, uint8_t *sig_data,
sig->data_size = data_size;
}
-int vb2_copy_signature(struct vb2_signature *dest,
- const struct vb2_signature *src)
+vb2_error_t vb2_copy_signature(struct vb2_signature *dest,
+ const struct vb2_signature *src)
{
if (dest->sig_size < src->sig_size)
return VB2_ERROR_SIG_SIZE;
diff --git a/host/lib/include/file_keys.h b/host/lib/include/file_keys.h
index b4bdd322..8176cdbf 100644
--- a/host/lib/include/file_keys.h
+++ b/host/lib/include/file_keys.h
@@ -14,7 +14,7 @@
* hash algorithm [alg] and stores it into [digest], which is of size
* [digest_size]. Returns VB2_SUCCESS, or non-zero on error.
*/
-int DigestFile(char *input_file, enum vb2_hash_algorithm alg,
- uint8_t *digest, uint32_t digest_size);
+vb2_error_t DigestFile(char *input_file, enum vb2_hash_algorithm alg,
+ uint8_t *digest, uint32_t digest_size);
#endif /* VBOOT_REFERENCE_FILE_KEYS_H_ */
diff --git a/host/lib/include/host_key.h b/host/lib/include/host_key.h
index 0040b8a2..b00a501d 100644
--- a/host/lib/include/host_key.h
+++ b/host/lib/include/host_key.h
@@ -9,6 +9,7 @@
#define VBOOT_REFERENCE_HOST_KEY_H_
#include "2crypto.h"
+#include "2return_codes.h"
struct vb2_packed_key;
struct vb2_private_key;
@@ -22,8 +23,8 @@ struct vb2_private_key;
* @return The equivalent vb1 crypto algorithm or VB2_ALG_COUNT if error.
*/
enum vb2_crypto_algorithm vb2_get_crypto_algorithm(
- enum vb2_hash_algorithm hash_alg,
- enum vb2_signature_algorithm sig_alg);
+ enum vb2_hash_algorithm hash_alg,
+ enum vb2_signature_algorithm sig_alg);
/**
* Read a private key from a .pem file.
@@ -35,8 +36,8 @@ enum vb2_crypto_algorithm vb2_get_crypto_algorithm(
* @return The private key or NULL if error. Caller must free() it.
*/
struct vb2_private_key *vb2_read_private_key_pem(
- const char *filename,
- enum vb2_crypto_algorithm algorithm);
+ const char *filename,
+ enum vb2_crypto_algorithm algorithm);
/**
* Free a private key.
@@ -53,8 +54,8 @@ void vb2_free_private_key(struct vb2_private_key *key);
*
* @return VB2_SUCCESS, or non-zero if error.
*/
-int vb2_write_private_key(const char *filename,
- const struct vb2_private_key *key);
+vb2_error_t vb2_write_private_key(const char *filename,
+ const struct vb2_private_key *key);
/**
@@ -96,8 +97,8 @@ void vb2_init_packed_key(struct vb2_packed_key *key, uint8_t *key_data,
*
* @return VB2_SUCCESS, or non-zero if error.
*/
-int vb2_copy_packed_key(struct vb2_packed_key *dest,
- const struct vb2_packed_key *src);
+vb2_error_t vb2_copy_packed_key(struct vb2_packed_key *dest,
+ const struct vb2_packed_key *src);
/**
* Read a packed key from a .vbpubk file.
@@ -141,7 +142,7 @@ struct vb2_packed_key *vb2_read_packed_keyb(const char *filename,
*
* @return VB2_SUCCESS, or non-zero if error.
*/
-int vb2_write_packed_key(const char *filename,
- const struct vb2_packed_key *key);
+vb2_error_t vb2_write_packed_key(const char *filename,
+ const struct vb2_packed_key *key);
#endif /* VBOOT_REFERENCE_HOST_KEY_H_ */
diff --git a/host/lib/include/host_misc.h b/host/lib/include/host_misc.h
index 63a38943..65949508 100644
--- a/host/lib/include/host_misc.h
+++ b/host/lib/include/host_misc.h
@@ -41,7 +41,7 @@ int ReadFileBit(const char* filename, int bitmask);
/* Writes [size] bytes of [data] to [filename].
*
* Returns 0 if success, 1 if error. */
-int WriteFile(const char* filename, const void *data, uint64_t size);
+vb2_error_t WriteFile(const char* filename, const void *data, uint64_t size);
/**
* Read data from a file into a newly allocated buffer.
@@ -53,7 +53,8 @@ int WriteFile(const char* filename, const void *data, uint64_t size);
* @param size_ptr On exit, size of data will be stored here.
* @return VB2_SUCCESS, or non-zero if error.
*/
-int vb2_read_file(const char *filename, uint8_t **data_ptr, uint32_t *size_ptr);
+vb2_error_t vb2_read_file(const char *filename, uint8_t **data_ptr,
+ uint32_t *size_ptr);
/**
* Write data to a file from a buffer.
@@ -63,7 +64,8 @@ int vb2_read_file(const char *filename, uint8_t **data_ptr, uint32_t *size_ptr);
* @param size Number of bytes of data to write
* @return VB2_SUCCESS, or non-zero if error.
*/
-int vb2_write_file(const char *filename, const void *buf, uint32_t size);
+vb2_error_t vb2_write_file(const char *filename, const void *buf,
+ uint32_t size);
/**
* Write a buffer which starts with a standard vb21_struct_common header.
@@ -74,7 +76,7 @@ int vb2_write_file(const char *filename, const void *buf, uint32_t size);
* @param buf Buffer to write
* @return VB2_SUCCESS, or non-zero if error.
*/
-int vb21_write_object(const char *filename, const void *buf);
+vb2_error_t vb21_write_object(const char *filename, const void *buf);
/**
* Round up a size to a multiple of 32 bits (4 bytes).
diff --git a/host/lib/include/host_signature.h b/host/lib/include/host_signature.h
index fce664da..682840c4 100644
--- a/host/lib/include/host_signature.h
+++ b/host/lib/include/host_signature.h
@@ -45,8 +45,8 @@ struct vb2_signature *vb2_alloc_signature(uint32_t sig_size,
* @param src Source signature
*
* @return VB2_SUCCESS, or non-zero if error. */
-int vb2_copy_signature(struct vb2_signature *dest,
- const struct vb2_signature *src);
+vb2_error_t vb2_copy_signature(struct vb2_signature *dest,
+ const struct vb2_signature *src);
/**
* Calculate a SHA-512 digest-only signature.
@@ -68,8 +68,7 @@ struct vb2_signature *vb2_sha512_signature(const uint8_t *data, uint32_t size);
* @return The signature, or NULL if error. Caller must free() it.
*/
struct vb2_signature *vb2_calculate_signature(
- const uint8_t *data, uint32_t size,
- const struct vb2_private_key *key);
+ const uint8_t *data, uint32_t size, const struct vb2_private_key *key);
/**
* Calculate a signature for the data using an external signer.
@@ -82,8 +81,7 @@ struct vb2_signature *vb2_calculate_signature(
*
* @return The signature, or NULL if error. Caller must free() it.
*/
-struct vb2_signature *vb2_external_signature(const uint8_t *data,
- uint32_t size,
+struct vb2_signature *vb2_external_signature(const uint8_t *data, uint32_t size,
const char *key_file,
uint32_t key_algorithm,
const char *external_signer);