OLD | NEW |
(Empty) | |
| 1 /* Copyright (c) 2010 The Chromium OS Authors. All rights reserved. |
| 2 * Use of this source code is governed by a BSD-style license that can be |
| 3 * found in the LICENSE file. |
| 4 * |
| 5 * Utility functions for message digests. |
| 6 */ |
| 7 |
| 8 #ifndef VBOOT_REFERENCE_SHA_UTILITY_H_ |
| 9 #define VBOOT_REFERENCE_SHA_UTILITY_H_ |
| 10 |
| 11 #include <inttypes.h> |
| 12 |
| 13 #include "sha.h" |
| 14 |
| 15 #define SHA1_DIGEST_ALGORITHM 0 |
| 16 #define SHA256_DIGEST_ALGORITHM 1 |
| 17 #define SHA512_DIGEST_ALGORITHM 2 |
| 18 |
| 19 /* A generic digest context structure which can be used to represent |
| 20 * the SHA*_CTX for multiple digest algorithms. |
| 21 */ |
| 22 typedef struct DigestContext { |
| 23 SHA1_CTX* sha1_ctx; |
| 24 SHA256_CTX* sha256_ctx; |
| 25 SHA512_CTX* sha512_ctx; |
| 26 int algorithm; /* Hashing algorithm to use. */ |
| 27 } DigestContext; |
| 28 |
| 29 /* Wrappers for message digest algorithms. These are useful when the hashing |
| 30 * operation is being done in parallel with something else. DigestContext tracks |
| 31 * and stores the state of any digest algorithm (one at any given time). |
| 32 */ |
| 33 |
| 34 /* Initialize a digest context for use with signature algorithm [algorithm]. */ |
| 35 void DigestInit(DigestContext* ctx, int sig_algorithm); |
| 36 void DigestUpdate(DigestContext* ctx, const uint8_t* data, uint64_t len); |
| 37 |
| 38 /* Caller owns the returned digest and must free it. */ |
| 39 uint8_t* DigestFinal(DigestContext* ctx); |
| 40 |
| 41 /* Returns the appropriate digest for the data in [input_file] |
| 42 * based on the signature [algorithm]. |
| 43 * Caller owns the returned digest and must free it. |
| 44 */ |
| 45 uint8_t* DigestFile(char* input_file, int sig_algorithm); |
| 46 |
| 47 /* Returns the appropriate digest of [buf] of length |
| 48 * [len] based on the signature [algorithm]. |
| 49 * Caller owns the returned digest and must free it. |
| 50 */ |
| 51 uint8_t* DigestBuf(const uint8_t* buf, uint64_t len, int sig_algorithm); |
| 52 |
| 53 #endif /* VBOOT_REFERENCE_SHA_UTILITY_H_ */ |
OLD | NEW |