diff options
author | Randall Spangler <rspangler@chromium.org> | 2016-10-11 15:28:16 -0700 |
---|---|---|
committer | chrome-bot <chrome-bot@chromium.org> | 2016-10-13 17:27:07 -0700 |
commit | fb267154d29356937eb304234793ab2e28ad0bab (patch) | |
tree | 609b8d39adab9b4cf8c7dac8859d76541e50e75f /host/lib/signature_digest.c | |
parent | a1001da56512fdcd3bd648a5a04da03ffea3e91b (diff) | |
download | vboot-fb267154d29356937eb304234793ab2e28ad0bab.tar.gz |
Fix indentation in firmware and host libs
vboot_reference originally used 2-space indentation, rather than
kernel-style tabs. This makes it painful to maintain given that newer
source files are kernel-style.
Re-indent the files that need it, and reflow comments.
No functionality changes.
BUG=none
BRANCH=none
TEST=make runtests
Change-Id: I7dabed41f69434b1988a52600c0cb1eac8c8d7e6
Signed-off-by: Randall Spangler <rspangler@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/396488
Reviewed-by: Daisuke Nojiri <dnojiri@chromium.org>
Diffstat (limited to 'host/lib/signature_digest.c')
-rw-r--r-- | host/lib/signature_digest.c | 107 |
1 files changed, 56 insertions, 51 deletions
diff --git a/host/lib/signature_digest.c b/host/lib/signature_digest.c index b56233a0..ca560c94 100644 --- a/host/lib/signature_digest.c +++ b/host/lib/signature_digest.c @@ -17,63 +17,68 @@ #include "host_common.h" #include "signature_digest.h" - -uint8_t* PrependDigestInfo(unsigned int algorithm, uint8_t* digest) { - const int digest_size = vb2_digest_size(vb2_crypto_to_hash(algorithm)); - const int digestinfo_size = digestinfo_size_map[algorithm]; - const uint8_t* digestinfo = hash_digestinfo_map[algorithm]; - uint8_t* p = malloc(digestinfo_size + digest_size); - Memcpy(p, digestinfo, digestinfo_size); - Memcpy(p + digestinfo_size, digest, digest_size); - return p; +uint8_t* PrependDigestInfo(unsigned int algorithm, uint8_t* digest) +{ + const int digest_size = vb2_digest_size(vb2_crypto_to_hash(algorithm)); + const int digestinfo_size = digestinfo_size_map[algorithm]; + const uint8_t* digestinfo = hash_digestinfo_map[algorithm]; + uint8_t* p = malloc(digestinfo_size + digest_size); + Memcpy(p, digestinfo, digestinfo_size); + Memcpy(p + digestinfo_size, digest, digest_size); + return p; } uint8_t* SignatureDigest(const uint8_t* buf, uint64_t len, - unsigned int algorithm) { - uint8_t* info_digest = NULL; + unsigned int algorithm) +{ + uint8_t* info_digest = NULL; - uint8_t digest[VB2_SHA512_DIGEST_SIZE]; /* Longest digest */ + uint8_t digest[VB2_SHA512_DIGEST_SIZE]; /* Longest digest */ - if (algorithm >= kNumAlgorithms) { - VBDEBUG(("SignatureDigest() called with invalid algorithm!\n")); - } else if (VB2_SUCCESS == vb2_digest_buffer(buf, len, - vb2_crypto_to_hash(algorithm), - digest, sizeof(digest))) { - info_digest = PrependDigestInfo(algorithm, digest); - } - return info_digest; + if (algorithm >= kNumAlgorithms) { + VBDEBUG(("SignatureDigest() called with invalid algorithm!\n")); + } else if (VB2_SUCCESS == + vb2_digest_buffer(buf, len, vb2_crypto_to_hash(algorithm), + digest, sizeof(digest))) { + info_digest = PrependDigestInfo(algorithm, digest); + } + return info_digest; } uint8_t* SignatureBuf(const uint8_t* buf, uint64_t len, const char* key_file, - unsigned int algorithm) { - FILE* key_fp = NULL; - RSA* key = NULL; - uint8_t* signature = NULL; - uint8_t* signature_digest = SignatureDigest(buf, len, algorithm); - const int digest_size = vb2_digest_size(vb2_crypto_to_hash(algorithm)); - int signature_digest_len = (digest_size + digestinfo_size_map[algorithm]); - key_fp = fopen(key_file, "r"); - if (!key_fp) { - VBDEBUG(("SignatureBuf(): Couldn't open key file: %s\n", key_file)); - free(signature_digest); - return NULL; - } - if ((key = PEM_read_RSAPrivateKey(key_fp, NULL, NULL, NULL))) - signature = (uint8_t*) malloc(siglen_map[algorithm]); - else - VBDEBUG(("SignatureBuf(): Couldn't read private key from file: %s\n", - key_file)); - if (signature) { - if (-1 == RSA_private_encrypt(signature_digest_len, /* Input length. */ - signature_digest, /* Input data. */ - signature, /* Output signature. */ - key, /* Key to use. */ - RSA_PKCS1_PADDING)) /* Padding to use. */ - VBDEBUG(("SignatureBuf(): RSA_private_encrypt() failed.\n")); - } - fclose(key_fp); - if (key) - RSA_free(key); - free(signature_digest); - return signature; + unsigned int algorithm) +{ + FILE* key_fp = NULL; + RSA* key = NULL; + uint8_t* signature = NULL; + uint8_t* signature_digest = SignatureDigest(buf, len, algorithm); + const int digest_size = vb2_digest_size(vb2_crypto_to_hash(algorithm)); + int signature_digest_len = digest_size + digestinfo_size_map[algorithm]; + key_fp = fopen(key_file, "r"); + if (!key_fp) { + VBDEBUG(("SignatureBuf(): Couldn't open key file: %s\n", + key_file)); + free(signature_digest); + return NULL; + } + if ((key = PEM_read_RSAPrivateKey(key_fp, NULL, NULL, NULL))) + signature = (uint8_t*) malloc(siglen_map[algorithm]); + else + VBDEBUG(("SignatureBuf(): Couldn't read private key from: %s\n", + key_file)); + if (signature) { + if (-1 == RSA_private_encrypt( + signature_digest_len, /* Input length. */ + signature_digest, /* Input data. */ + signature, /* Output signature. */ + key, /* Key to use. */ + RSA_PKCS1_PADDING)) /* Padding to use. */ + VBDEBUG(("SignatureBuf(): " + "RSA_private_encrypt() failed.\n")); + } + fclose(key_fp); + if (key) + RSA_free(key); + free(signature_digest); + return signature; } |