summaryrefslogtreecommitdiff
path: root/host
diff options
context:
space:
mode:
Diffstat (limited to 'host')
-rw-r--r--host/arch/x86/lib/crossystem_arch.c2
-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
-rw-r--r--host/lib21/host_fw_preamble.c12
-rw-r--r--host/lib21/host_key.c55
-rw-r--r--host/lib21/host_keyblock.c11
-rw-r--r--host/lib21/host_misc.c9
-rw-r--r--host/lib21/host_signature.c45
-rw-r--r--host/lib21/include/host_fw_preamble2.h12
-rw-r--r--host/lib21/include/host_key2.h52
-rw-r--r--host/lib21/include/host_keyblock2.h11
-rw-r--r--host/lib21/include/host_misc2.h2
-rw-r--r--host/lib21/include/host_signature2.h39
21 files changed, 162 insertions, 177 deletions
diff --git a/host/arch/x86/lib/crossystem_arch.c b/host/arch/x86/lib/crossystem_arch.c
index cda86e8d..68ab67db 100644
--- a/host/arch/x86/lib/crossystem_arch.c
+++ b/host/arch/x86/lib/crossystem_arch.c
@@ -442,7 +442,7 @@ static const char* VbReadMainFwType(char* dest, int size)
/* Read the recovery reason. Returns the reason code or -1 if error. */
-static int VbGetRecoveryReason(void)
+static vb2_error_t VbGetRecoveryReason(void)
{
unsigned value;
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);
diff --git a/host/lib21/host_fw_preamble.c b/host/lib21/host_fw_preamble.c
index ebe3ce94..7220b32e 100644
--- a/host/lib21/host_fw_preamble.c
+++ b/host/lib21/host_fw_preamble.c
@@ -16,13 +16,11 @@
#include "host_signature2.h"
#include "vb21_common.h"
-int vb21_fw_preamble_create(struct vb21_fw_preamble **fp_ptr,
- const struct vb2_private_key *signing_key,
- const struct vb21_signature **hash_list,
- uint32_t hash_count,
- uint32_t fw_version,
- uint32_t flags,
- const char *desc)
+vb2_error_t vb21_fw_preamble_create(struct vb21_fw_preamble **fp_ptr,
+ const struct vb2_private_key *signing_key,
+ const struct vb21_signature **hash_list,
+ uint32_t hash_count, uint32_t fw_version,
+ uint32_t flags, const char *desc)
{
struct vb21_fw_preamble fp = {
.c.magic = VB21_MAGIC_FW_PREAMBLE,
diff --git a/host/lib21/host_key.c b/host/lib21/host_key.c
index 76fbf285..1154bec9 100644
--- a/host/lib21/host_key.c
+++ b/host/lib21/host_key.c
@@ -138,9 +138,8 @@ void vb2_private_key_free(struct vb2_private_key *key)
free(key);
}
-int vb21_private_key_unpack(struct vb2_private_key **key_ptr,
- const uint8_t *buf,
- uint32_t size)
+vb2_error_t vb21_private_key_unpack(struct vb2_private_key **key_ptr,
+ const uint8_t *buf, uint32_t size)
{
const struct vb21_packed_private_key *pkey =
(const struct vb21_packed_private_key *)buf;
@@ -214,12 +213,12 @@ int vb21_private_key_unpack(struct vb2_private_key **key_ptr,
return VB2_SUCCESS;
}
-int vb21_private_key_read(struct vb2_private_key **key_ptr,
- const char *filename)
+vb2_error_t vb21_private_key_read(struct vb2_private_key **key_ptr,
+ const char *filename)
{
uint32_t size = 0;
uint8_t *buf = NULL;
- int rv;
+ vb2_error_t rv;
*key_ptr = NULL;
@@ -234,8 +233,8 @@ int vb21_private_key_read(struct vb2_private_key **key_ptr,
return rv;
}
-int vb2_private_key_read_pem(struct vb2_private_key **key_ptr,
- const char *filename)
+vb2_error_t vb2_private_key_read_pem(struct vb2_private_key **key_ptr,
+ const char *filename)
{
struct vb2_private_key *key;
FILE *f;
@@ -266,7 +265,8 @@ int vb2_private_key_read_pem(struct vb2_private_key **key_ptr,
return VB2_SUCCESS;
}
-int vb2_private_key_set_desc(struct vb2_private_key *key, const char *desc)
+vb2_error_t vb2_private_key_set_desc(struct vb2_private_key *key,
+ const char *desc)
{
if (key->desc)
free(key->desc);
@@ -282,8 +282,8 @@ int vb2_private_key_set_desc(struct vb2_private_key *key, const char *desc)
return VB2_SUCCESS;
}
-int vb21_private_key_write(const struct vb2_private_key *key,
- const char *filename)
+vb2_error_t vb21_private_key_write(const struct vb2_private_key *key,
+ const char *filename)
{
struct vb21_packed_private_key pkey = {
.c.magic = VB21_MAGIC_PACKED_PRIVATE_KEY,
@@ -297,7 +297,7 @@ int vb21_private_key_write(const struct vb2_private_key *key,
uint8_t *buf;
uint8_t *rsabuf = NULL;
int rsalen = 0;
- int rv;
+ vb2_error_t rv;
memcpy(&pkey.id, &key->id, sizeof(pkey.id));
@@ -338,8 +338,8 @@ int vb21_private_key_write(const struct vb2_private_key *key,
return rv ? VB2_ERROR_PRIVATE_KEY_WRITE_FILE : VB2_SUCCESS;
}
-int vb2_private_key_hash(const struct vb2_private_key **key_ptr,
- enum vb2_hash_algorithm hash_alg)
+vb2_error_t vb2_private_key_hash(const struct vb2_private_key **key_ptr,
+ enum vb2_hash_algorithm hash_alg)
{
*key_ptr = NULL;
@@ -388,8 +388,8 @@ int vb2_private_key_hash(const struct vb2_private_key **key_ptr,
}
}
-int vb2_public_key_alloc(struct vb2_public_key **key_ptr,
- enum vb2_signature_algorithm sig_alg)
+vb2_error_t vb2_public_key_alloc(struct vb2_public_key **key_ptr,
+ enum vb2_signature_algorithm sig_alg)
{
struct vb2_public_key *key;
uint32_t key_data_size = vb2_packed_key_size(sig_alg);
@@ -429,8 +429,8 @@ uint8_t *vb2_public_key_packed_data(struct vb2_public_key *key)
return (uint8_t *)(key->id + 1);
}
-int vb2_public_key_read_keyb(struct vb2_public_key **key_ptr,
- const char *filename)
+vb2_error_t vb2_public_key_read_keyb(struct vb2_public_key **key_ptr,
+ const char *filename)
{
struct vb2_public_key *key = NULL;
uint8_t *key_data, *key_buf;
@@ -475,7 +475,8 @@ int vb2_public_key_read_keyb(struct vb2_public_key **key_ptr,
return VB2_SUCCESS;
}
-int vb2_public_key_set_desc(struct vb2_public_key *key, const char *desc)
+vb2_error_t vb2_public_key_set_desc(struct vb2_public_key *key,
+ const char *desc)
{
if (key->desc)
free((void *)key->desc);
@@ -491,8 +492,8 @@ int vb2_public_key_set_desc(struct vb2_public_key *key, const char *desc)
return VB2_SUCCESS;
}
-int vb21_packed_key_read(struct vb21_packed_key **key_ptr,
- const char *filename)
+vb2_error_t vb21_packed_key_read(struct vb21_packed_key **key_ptr,
+ const char *filename)
{
struct vb2_public_key key;
uint8_t *buf;
@@ -512,8 +513,8 @@ int vb21_packed_key_read(struct vb21_packed_key **key_ptr,
return VB2_SUCCESS;
}
-int vb21_public_key_pack(struct vb21_packed_key **key_ptr,
- const struct vb2_public_key *pubk)
+vb2_error_t vb21_public_key_pack(struct vb21_packed_key **key_ptr,
+ const struct vb2_public_key *pubk)
{
struct vb21_packed_key key = {
.c.magic = VB21_MAGIC_PACKED_KEY,
@@ -571,8 +572,8 @@ int vb21_public_key_pack(struct vb21_packed_key **key_ptr,
return VB2_SUCCESS;
}
-int vb2_public_key_hash(struct vb2_public_key *key,
- enum vb2_hash_algorithm hash_alg)
+vb2_error_t vb2_public_key_hash(struct vb2_public_key *key,
+ enum vb2_hash_algorithm hash_alg)
{
switch (hash_alg) {
#if VB2_SUPPORT_SHA1
@@ -635,8 +636,8 @@ enum vb2_signature_algorithm vb2_rsa_sig_alg(struct rsa_st *rsa)
return VB2_SIG_INVALID;
}
-int vb21_public_key_write(const struct vb2_public_key *key,
- const char *filename)
+vb2_error_t vb21_public_key_write(const struct vb2_public_key *key,
+ const char *filename)
{
struct vb21_packed_key *pkey;
int ret;
diff --git a/host/lib21/host_keyblock.c b/host/lib21/host_keyblock.c
index cb8c3127..9c5959a4 100644
--- a/host/lib21/host_keyblock.c
+++ b/host/lib21/host_keyblock.c
@@ -15,12 +15,11 @@
#include "host_misc.h"
#include "host_signature2.h"
-int vb21_keyblock_create(struct vb21_keyblock **kb_ptr,
- const struct vb2_public_key *data_key,
- const struct vb2_private_key **signing_keys,
- uint32_t signing_key_count,
- uint32_t flags,
- const char *desc)
+vb2_error_t vb21_keyblock_create(struct vb21_keyblock **kb_ptr,
+ const struct vb2_public_key *data_key,
+ const struct vb2_private_key **signing_keys,
+ uint32_t signing_key_count, uint32_t flags,
+ const char *desc)
{
struct vb21_keyblock kb = {
.c.magic = VB21_MAGIC_KEYBLOCK,
diff --git a/host/lib21/host_misc.c b/host/lib21/host_misc.c
index 59c8c0a8..9d375681 100644
--- a/host/lib21/host_misc.c
+++ b/host/lib21/host_misc.c
@@ -17,7 +17,8 @@
#include "host_common.h"
#include "host_misc2.h"
-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)
{
FILE *f;
uint8_t *buf;
@@ -61,7 +62,7 @@ int vb2_read_file(const char *filename, uint8_t **data_ptr, uint32_t *size_ptr)
return VB2_SUCCESS;
}
-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)
{
FILE *f = fopen(filename, "wb");
@@ -81,7 +82,7 @@ int vb2_write_file(const char *filename, const void *buf, uint32_t size)
return VB2_SUCCESS;
}
-int vb21_write_object(const char *filename, const void *buf)
+vb2_error_t vb21_write_object(const char *filename, const void *buf)
{
const struct vb21_struct_common *cptr = buf;
@@ -136,7 +137,7 @@ static const char *onebyte(const char *str, uint8_t *vptr)
return str;
}
-int vb2_str_to_id(const char *str, struct vb2_id *id)
+vb2_error_t vb2_str_to_id(const char *str, struct vb2_id *id)
{
uint8_t val = 0;
int i;
diff --git a/host/lib21/host_signature.c b/host/lib21/host_signature.c
index 5339b075..51320e7b 100644
--- a/host/lib21/host_signature.c
+++ b/host/lib21/host_signature.c
@@ -17,9 +17,8 @@
#include "host_signature2.h"
#include "host_misc.h"
-int vb2_digest_info(enum vb2_hash_algorithm hash_alg,
- const uint8_t **buf_ptr,
- uint32_t *size_ptr)
+vb2_error_t vb2_digest_info(enum vb2_hash_algorithm hash_alg,
+ const uint8_t **buf_ptr, uint32_t *size_ptr)
{
*buf_ptr = NULL;
*size_ptr = 0;
@@ -68,11 +67,9 @@ int vb2_digest_info(enum vb2_hash_algorithm hash_alg,
}
}
-int vb21_sign_data(struct vb21_signature **sig_ptr,
- const uint8_t *data,
- uint32_t size,
- const struct vb2_private_key *key,
- const char *desc)
+vb2_error_t vb21_sign_data(struct vb21_signature **sig_ptr, const uint8_t *data,
+ uint32_t size, const struct vb2_private_key *key,
+ const char *desc)
{
struct vb21_signature s = {
.c.magic = VB21_MAGIC_SIGNATURE,
@@ -172,9 +169,9 @@ int vb21_sign_data(struct vb21_signature **sig_ptr,
return VB2_SUCCESS;
}
-int vb21_sig_size_for_key(uint32_t *size_ptr,
- const struct vb2_private_key *key,
- const char *desc)
+vb2_error_t vb21_sig_size_for_key(uint32_t *size_ptr,
+ const struct vb2_private_key *key,
+ const char *desc)
{
uint32_t size = vb2_sig_size(key->sig_alg, key->hash_alg);
@@ -188,12 +185,12 @@ int vb21_sig_size_for_key(uint32_t *size_ptr,
return VB2_SUCCESS;
}
-int vb21_sig_size_for_keys(uint32_t *size_ptr,
- const struct vb2_private_key **key_list,
- uint32_t key_count)
+vb2_error_t vb21_sig_size_for_keys(uint32_t *size_ptr,
+ const struct vb2_private_key **key_list,
+ uint32_t key_count)
{
uint32_t total = 0, size = 0;
- int rv, i;
+ vb2_error_t rv, i;
*size_ptr = 0;
@@ -208,14 +205,13 @@ int vb21_sig_size_for_keys(uint32_t *size_ptr,
return VB2_SUCCESS;
}
-int vb21_sign_object(uint8_t *buf,
- uint32_t sig_offset,
- const struct vb2_private_key *key,
- const char *desc)
+vb2_error_t vb21_sign_object(uint8_t *buf, uint32_t sig_offset,
+ const struct vb2_private_key *key,
+ const char *desc)
{
struct vb21_struct_common *c = (struct vb21_struct_common *)buf;
struct vb21_signature *sig = NULL;
- int rv;
+ vb2_error_t rv;
rv = vb21_sign_data(&sig, buf, sig_offset, key, desc);
if (rv)
@@ -232,14 +228,13 @@ int vb21_sign_object(uint8_t *buf,
return VB2_SUCCESS;
}
-int vb21_sign_object_multiple(uint8_t *buf,
- uint32_t sig_offset,
- const struct vb2_private_key **key_list,
- uint32_t key_count)
+vb2_error_t vb21_sign_object_multiple(uint8_t *buf, uint32_t sig_offset,
+ const struct vb2_private_key **key_list,
+ uint32_t key_count)
{
struct vb21_struct_common *c = (struct vb21_struct_common *)buf;
uint32_t sig_next = sig_offset;
- int rv, i;
+ vb2_error_t rv, i;
for (i = 0; i < key_count; i++) {
struct vb21_signature *sig = NULL;
diff --git a/host/lib21/include/host_fw_preamble2.h b/host/lib21/include/host_fw_preamble2.h
index e759edc5..d0bed1ef 100644
--- a/host/lib21/include/host_fw_preamble2.h
+++ b/host/lib21/include/host_fw_preamble2.h
@@ -24,12 +24,10 @@ struct vb21_signature;
* @param desc Description for preamble, or NULL if none
* @return VB2_SUCCESS, or non-zero error code if failure.
*/
-int vb21_fw_preamble_create(struct vb21_fw_preamble **fp_ptr,
- const struct vb2_private_key *signing_key,
- const struct vb21_signature **hash_list,
- uint32_t hash_count,
- uint32_t fw_version,
- uint32_t flags,
- const char *desc);
+vb2_error_t vb21_fw_preamble_create(struct vb21_fw_preamble **fp_ptr,
+ const struct vb2_private_key *signing_key,
+ const struct vb21_signature **hash_list,
+ uint32_t hash_count, uint32_t fw_version,
+ uint32_t flags, const char *desc);
#endif /* VBOOT_REFERENCE_HOST_FW_PREAMBLE2_H_ */
diff --git a/host/lib21/include/host_key2.h b/host/lib21/include/host_key2.h
index 5ce41c06..d8a90f5f 100644
--- a/host/lib21/include/host_key2.h
+++ b/host/lib21/include/host_key2.h
@@ -9,6 +9,7 @@
#define VBOOT_REFERENCE_HOST_KEY2_H_
#include "2id.h"
+#include "2return_codes.h"
#include "2struct.h"
struct vb2_public_key;
@@ -98,9 +99,8 @@ void vb2_private_key_free(struct vb2_private_key *key);
* @param size Size of buffer in bytes
* @return VB2_SUCCESS, or non-zero error code if error.
*/
-int vb21_private_key_unpack(struct vb2_private_key **key_ptr,
- const uint8_t *buf,
- uint32_t size);
+vb2_error_t vb21_private_key_unpack(struct vb2_private_key **key_ptr,
+ const uint8_t *buf, uint32_t size);
/**
* Read a private key from vb21_packed_private_key format.
@@ -110,8 +110,8 @@ int vb21_private_key_unpack(struct vb2_private_key **key_ptr,
* @param filename File to read key data from.
* @return VB2_SUCCESS, or non-zero error code if error.
*/
-int vb21_private_key_read(struct vb2_private_key **key_ptr,
- const char *filename);
+vb2_error_t vb21_private_key_read(struct vb2_private_key **key_ptr,
+ const char *filename);
/**
* Read a private key from a .pem file.
@@ -124,8 +124,8 @@ int vb21_private_key_read(struct vb2_private_key **key_ptr,
* @param filename File to read key data from.
* @return VB2_SUCCESS, or non-zero error code if error.
*/
-int vb2_private_key_read_pem(struct vb2_private_key **key_ptr,
- const char *filename);
+vb2_error_t vb2_private_key_read_pem(struct vb2_private_key **key_ptr,
+ const char *filename);
/**
* Set the description of a private key.
@@ -134,7 +134,8 @@ int vb2_private_key_read_pem(struct vb2_private_key **key_ptr,
* @param desc Description string, or NULL if no description.
* @return VB2_SUCCESS, or non-zero error code if error.
*/
-int vb2_private_key_set_desc(struct vb2_private_key *key, const char *desc);
+vb2_error_t vb2_private_key_set_desc(struct vb2_private_key *key,
+ const char *desc);
/**
* Write a private key to vb21_packed_private_key format.
@@ -143,8 +144,8 @@ int vb2_private_key_set_desc(struct vb2_private_key *key, const char *desc);
* @param filename File to write key data to.
* @return VB2_SUCCESS, or non-zero error code if error.
*/
-int vb21_private_key_write(const struct vb2_private_key *key,
- const char *filename);
+vb2_error_t vb21_private_key_write(const struct vb2_private_key *key,
+ const char *filename);
/**
* Get a private key for an unsigned hash
@@ -154,8 +155,8 @@ int vb21_private_key_write(const struct vb2_private_key *key,
* @param hash_alg Hash algorithm to use
* @return VB2_SUCCESS, or non-zero error code if error.
*/
-int vb2_private_key_hash(const struct vb2_private_key **key_ptr,
- enum vb2_hash_algorithm hash_alg);
+vb2_error_t vb2_private_key_hash(const struct vb2_private_key **key_ptr,
+ enum vb2_hash_algorithm hash_alg);
/**
* Allocate a public key buffer of sufficient size for the signature algorithm.
@@ -168,8 +169,8 @@ int vb2_private_key_hash(const struct vb2_private_key **key_ptr,
* @param sig_alg Signature algorithm for key.
* @return VB2_SUCCESS, or non-zero error code if error.
*/
-int vb2_public_key_alloc(struct vb2_public_key **key_ptr,
- enum vb2_signature_algorithm sig_alg);
+vb2_error_t vb2_public_key_alloc(struct vb2_public_key **key_ptr,
+ enum vb2_signature_algorithm sig_alg);
/**
* Return the packed data for a key allocated with vb2_public_key_alloc().
@@ -202,8 +203,8 @@ void vb2_public_key_free(struct vb2_public_key *key);
* @return VB2_SUCCESS, or non-zero error code if error.
*/
-int vb2_public_key_read_keyb(struct vb2_public_key **key_ptr,
- const char *filename);
+vb2_error_t vb2_public_key_read_keyb(struct vb2_public_key **key_ptr,
+ const char *filename);
/**
* Set the description of a public key.
@@ -212,7 +213,8 @@ int vb2_public_key_read_keyb(struct vb2_public_key **key_ptr,
* @param desc Description string, or NULL if no description.
* @return VB2_SUCCESS, or non-zero error code if error.
*/
-int vb2_public_key_set_desc(struct vb2_public_key *key, const char *desc);
+vb2_error_t vb2_public_key_set_desc(struct vb2_public_key *key,
+ const char *desc);
/**
* Read a public key in vb21_packed_key format.
@@ -221,8 +223,8 @@ int vb2_public_key_set_desc(struct vb2_public_key *key, const char *desc);
* Caller is responsible for calling free() on this.
* @return VB2_SUCCESS, or non-zero if error.
*/
-int vb21_packed_key_read(struct vb21_packed_key **key_ptr,
- const char *filename);
+vb2_error_t vb21_packed_key_read(struct vb21_packed_key **key_ptr,
+ const char *filename);
/**
* Pack a public key into vb21_packed_key format.
@@ -233,8 +235,8 @@ int vb21_packed_key_read(struct vb21_packed_key **key_ptr,
* this.
* @return VB2_SUCCESS, or non-zero if error.
*/
-int vb21_public_key_pack(struct vb21_packed_key **key_ptr,
- const struct vb2_public_key *pubk);
+vb2_error_t vb21_public_key_pack(struct vb21_packed_key **key_ptr,
+ const struct vb2_public_key *pubk);
/**
* Get a public key for an unsigned hash.
@@ -243,8 +245,8 @@ int vb21_public_key_pack(struct vb21_packed_key **key_ptr,
* @param hash_alg Hash algorithm to use
* @return VB2_SUCCESS, or non-zero error code if error.
*/
-int vb2_public_key_hash(struct vb2_public_key *key,
- enum vb2_hash_algorithm hash_alg);
+vb2_error_t vb2_public_key_hash(struct vb2_public_key *key,
+ enum vb2_hash_algorithm hash_alg);
/**
@@ -262,7 +264,7 @@ enum vb2_signature_algorithm vb2_rsa_sig_alg(struct rsa_st *rsa);
* @param filename File to write key data to.
* @return VB2_SUCCESS, or non-zero error code if error.
*/
-int vb21_public_key_write(const struct vb2_public_key *key,
- const char *filename);
+vb2_error_t vb21_public_key_write(const struct vb2_public_key *key,
+ const char *filename);
#endif /* VBOOT_REFERENCE_HOST_KEY2_H_ */
diff --git a/host/lib21/include/host_keyblock2.h b/host/lib21/include/host_keyblock2.h
index 6abfdc98..faa51d26 100644
--- a/host/lib21/include/host_keyblock2.h
+++ b/host/lib21/include/host_keyblock2.h
@@ -25,11 +25,10 @@ struct vb21_keyblock;
* taken from the data key.
* @return VB2_SUCCESS, or non-zero error code if failure.
*/
-int vb21_keyblock_create(struct vb21_keyblock **kb_ptr,
- const struct vb2_public_key *data_key,
- const struct vb2_private_key **signing_keys,
- uint32_t signing_key_count,
- uint32_t flags,
- const char *desc);
+vb2_error_t vb21_keyblock_create(struct vb21_keyblock **kb_ptr,
+ const struct vb2_public_key *data_key,
+ const struct vb2_private_key **signing_keys,
+ uint32_t signing_key_count, uint32_t flags,
+ const char *desc);
#endif /* VBOOT_REFERENCE_HOST_KEYBLOCK2_H_ */
diff --git a/host/lib21/include/host_misc2.h b/host/lib21/include/host_misc2.h
index 5d891cad..795ebb23 100644
--- a/host/lib21/include/host_misc2.h
+++ b/host/lib21/include/host_misc2.h
@@ -21,6 +21,6 @@
* @param id Destination for binary representation
* @return VB2_SUCCESS, or non-zero if error.
*/
-int vb2_str_to_id(const char *str, struct vb2_id *id);
+vb2_error_t vb2_str_to_id(const char *str, struct vb2_id *id);
#endif /* VBOOT_REFERENCE_HOST_MISC2_H_ */
diff --git a/host/lib21/include/host_signature2.h b/host/lib21/include/host_signature2.h
index 5faf6da7..0b1784af 100644
--- a/host/lib21/include/host_signature2.h
+++ b/host/lib21/include/host_signature2.h
@@ -21,9 +21,8 @@ struct vb21_signature;
* @param size_ptr On success, contains the info size in bytes
* @return VB2_SUCCESS, or non-zero error code on failure.
*/
-int vb2_digest_info(enum vb2_hash_algorithm hash_alg,
- const uint8_t **buf_ptr,
- uint32_t *size_ptr);
+vb2_error_t vb2_digest_info(enum vb2_hash_algorithm hash_alg,
+ const uint8_t **buf_ptr, uint32_t *size_ptr);
/**
* Sign data buffer
@@ -37,11 +36,9 @@ int vb2_digest_info(enum vb2_hash_algorithm hash_alg,
* key description will be used.
* @return VB2_SUCCESS, or non-zero error code on failure.
*/
-int vb21_sign_data(struct vb21_signature **sig_ptr,
- const uint8_t *data,
- uint32_t size,
- const struct vb2_private_key *key,
- const char *desc);
+vb2_error_t vb21_sign_data(struct vb21_signature **sig_ptr, const uint8_t *data,
+ uint32_t size, const struct vb2_private_key *key,
+ const char *desc);
/**
* Calculate the signature size for a private key.
@@ -52,9 +49,9 @@ int vb21_sign_data(struct vb21_signature **sig_ptr,
* key description will be used.
* @return VB2_SUCCESS, or non-zero error code on failure.
*/
-int vb21_sig_size_for_key(uint32_t *size_ptr,
- const struct vb2_private_key *key,
- const char *desc);
+vb2_error_t vb21_sig_size_for_key(uint32_t *size_ptr,
+ const struct vb2_private_key *key,
+ const char *desc);
/**
* Calculate the total signature size for a list of keys.
@@ -64,9 +61,9 @@ int vb21_sig_size_for_key(uint32_t *size_ptr,
* @param key_count Number of keys.
* @return VB2_SUCCESS, or non-zero error code on failure.
*/
-int vb21_sig_size_for_keys(uint32_t *size_ptr,
- const struct vb2_private_key **key_list,
- uint32_t key_count);
+vb2_error_t vb21_sig_size_for_keys(uint32_t *size_ptr,
+ const struct vb2_private_key **key_list,
+ uint32_t key_count);
/**
* Sign object with a key.
@@ -78,10 +75,9 @@ int vb21_sig_size_for_keys(uint32_t *size_ptr,
* @param key Key to sign object with
* @param desc If non-null, description to use for signature
*/
-int vb21_sign_object(uint8_t *buf,
- uint32_t sig_offset,
- const struct vb2_private_key *key,
- const char *desc);
+vb2_error_t vb21_sign_object(uint8_t *buf, uint32_t sig_offset,
+ const struct vb2_private_key *key,
+ const char *desc);
/**
* Sign object with list of keys.
@@ -93,9 +89,8 @@ int vb21_sign_object(uint8_t *buf,
* @param key_list List of keys to sign object with
* @param key_count Number of keys in list
*/
-int vb21_sign_object_multiple(uint8_t *buf,
- uint32_t sig_offset,
- const struct vb2_private_key **key_list,
- uint32_t key_count);
+vb2_error_t vb21_sign_object_multiple(uint8_t *buf, uint32_t sig_offset,
+ const struct vb2_private_key **key_list,
+ uint32_t key_count);
#endif /* VBOOT_REFERENCE_HOST_SIGNATURE2_H_ */