Files
OpenCellular/include/sha_utility.h
Gaurav Shah 08df9b88a3 Vboot Reference: Add the "real" reference firmware verification function (VerifyFirmware).
The old VerifyFirmware function (now called VerifyFirmwareImage) works on the FirmwareImage structure. This CL adds a verification function which can be used directly on packed binary verified boot firmware blobs. This function can be used as the reference implementation for verified boot in firmware. In addition, all functions that work on FirmwareImage structure have been renames to distinguish them from those which work on binary firmware blobs.

In addition, this adds some new crypto utility functions and refactors old ones.
BUG=670
TEST=Added tests for the new function and they pass.

Review URL: http://codereview.chromium.org/650105
2010-02-23 16:16:23 -08:00

54 lines
1.7 KiB
C

/* Copyright (c) 2010 The Chromium OS Authors. All rights reserved.
* Use of this source code is governed by a BSD-style license that can be
* found in the LICENSE file.
*
* Utility functions for message digests.
*/
#ifndef VBOOT_REFERENCE_SHA_UTILITY_H_
#define VBOOT_REFERENCE_SHA_UTILITY_H_
#include <inttypes.h>
#include "sha.h"
#define SHA1_DIGEST_ALGORITHM 0
#define SHA256_DIGEST_ALGORITHM 1
#define SHA512_DIGEST_ALGORITHM 2
/* A generic digest context structure which can be used to represent
* the SHA*_CTX for multiple digest algorithms.
*/
typedef struct DigestContext {
SHA1_CTX* sha1_ctx;
SHA256_CTX* sha256_ctx;
SHA512_CTX* sha512_ctx;
int algorithm; /* Hashing algorithm to use. */
} DigestContext;
/* Wrappers for message digest algorithms. These are useful when the hashing
* operation is being done in parallel with something else. DigestContext tracks
* and stores the state of any digest algorithm (one at any given time).
*/
/* Initialize a digest context for use with signature algorithm [algorithm]. */
void DigestInit(DigestContext* ctx, int sig_algorithm);
void DigestUpdate(DigestContext* ctx, const uint8_t* data, int len);
/* Caller owns the returned digest and must free it. */
uint8_t* DigestFinal(DigestContext* ctx);
/* Returns the appropriate digest for the data in [input_file]
* based on the signature [algorithm].
* Caller owns the returned digest and must free it.
*/
uint8_t* DigestFile(char* input_file, int sig_algorithm);
/* Returns the appropriate digest of [buf] of length
* [len] based on the signature [algorithm].
* Caller owns the returned digest and must free it.
*/
uint8_t* DigestBuf(const uint8_t* buf, int len, int sig_algorithm);
#endif /* VBOOT_REFERENCE_SHA_UTILITY_H_ */