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 |
| 6 /* SHA-1, 256 and 512 functions. */ |
| 7 |
| 8 #ifndef VBOOT_REFERENCE_SHA_H_ |
| 9 #define VBOOT_REFERENCE_SHA_H_ |
| 10 |
| 11 #include <inttypes.h> |
| 12 #include <string.h> |
| 13 |
| 14 #define SHA1_DIGEST_SIZE 20 |
| 15 #define SHA1_BLOCK_SIZE 64 |
| 16 |
| 17 #define SHA256_DIGEST_SIZE 32 |
| 18 #define SHA256_BLOCK_SIZE 64 |
| 19 |
| 20 #define SHA512_DIGEST_SIZE 64 |
| 21 #define SHA512_BLOCK_SIZE 128 |
| 22 |
| 23 typedef struct SHA1_CTX { |
| 24 uint64_t count; |
| 25 uint32_t state[5]; |
| 26 #if defined(HAVE_ENDIAN_H) && defined(HAVE_LITTLE_ENDIAN) |
| 27 union { |
| 28 uint8_t b[64]; |
| 29 uint32_t w[16]; |
| 30 } buf; |
| 31 #else |
| 32 uint8_t buf[64]; |
| 33 #endif |
| 34 } SHA1_CTX; |
| 35 |
| 36 typedef struct { |
| 37 uint32_t h[8]; |
| 38 uint32_t tot_len; |
| 39 uint32_t len; |
| 40 uint8_t block[2 * SHA256_BLOCK_SIZE]; |
| 41 uint8_t buf[SHA256_DIGEST_SIZE]; /* Used for storing the final digest. */ |
| 42 } SHA256_CTX; |
| 43 |
| 44 typedef struct { |
| 45 uint64_t h[8]; |
| 46 uint32_t tot_len; |
| 47 uint32_t len; |
| 48 uint8_t block[2 * SHA512_BLOCK_SIZE]; |
| 49 uint8_t buf[SHA512_DIGEST_SIZE]; /* Used for storing the final digest. */ |
| 50 } SHA512_CTX; |
| 51 |
| 52 |
| 53 void SHA1_init(SHA1_CTX* ctx); |
| 54 void SHA1_update(SHA1_CTX* ctx, const uint8_t* data, int len); |
| 55 uint8_t* SHA1_final(SHA1_CTX* ctx); |
| 56 /* Convenience function for SHA-1. Computes hash on [data] of length [len]. |
| 57 * and stores it into [digest]. [digest] should be pre-allocated to |
| 58 * SHA1_DIGEST_SIZE bytes. |
| 59 */ |
| 60 uint8_t* SHA1(const void* data, int len, uint8_t* digest); |
| 61 |
| 62 void SHA256_init(SHA256_CTX* ctx); |
| 63 void SHA256_update(SHA256_CTX* ctx, const uint8_t* data, int len); |
| 64 uint8_t* SHA256_final(SHA256_CTX* ctx); |
| 65 uint8_t* SHA256(const uint8_t* data, int len, uint8_t* digest); |
| 66 |
| 67 void SHA512_init(SHA512_CTX* ctx); |
| 68 void SHA512_update(SHA512_CTX* ctx, const uint8_t* data, int len); |
| 69 uint8_t* SHA512_final(SHA512_CTX* ctx); |
| 70 uint8_t* SHA512(const uint8_t* data, int len, uint8_t* digest); |
| 71 |
| 72 |
| 73 #endif /* VBOOT_REFERENCE_SHA_H_ */ |
OLD | NEW |