Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(171)

Side by Side Diff: src/platform/vboot_reference/include/sha_utility.h

Issue 579007: Add generic wrappers for performing message digest operations. (Closed)
Patch Set: Created 10 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(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 algorithms (one at a 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, int 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(uint8_t* buf, int len, int sig_algorithm);
52
53 #endif /* VBOOT_REFERENCE_SHA_UTILITY_H_ */
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698