Ethan Yonker | 1e4a199 | 2014-11-06 09:05:01 -0600 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2007 The Android Open Source Project |
| 3 | * |
| 4 | * Redistribution and use in source and binary forms, with or without |
| 5 | * modification, are permitted provided that the following conditions are met: |
| 6 | * * Redistributions of source code must retain the above copyright |
| 7 | * notice, this list of conditions and the following disclaimer. |
| 8 | * * Redistributions in binary form must reproduce the above copyright |
| 9 | * notice, this list of conditions and the following disclaimer in the |
| 10 | * documentation and/or other materials provided with the distribution. |
| 11 | * * Neither the name of Google Inc. nor the names of its contributors may |
| 12 | * be used to endorse or promote products derived from this software |
| 13 | * without specific prior written permission. |
| 14 | * |
| 15 | * THIS SOFTWARE IS PROVIDED BY Google Inc. ``AS IS'' AND ANY EXPRESS OR |
| 16 | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF |
| 17 | * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO |
| 18 | * EVENT SHALL Google Inc. BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
| 19 | * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, |
| 20 | * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; |
| 21 | * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, |
| 22 | * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR |
| 23 | * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF |
| 24 | * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 25 | */ |
Dees Troy | bb4c0cb | 2013-11-02 20:25:14 +0000 | [diff] [blame] | 26 | |
Ethan Yonker | 1e4a199 | 2014-11-06 09:05:01 -0600 | [diff] [blame] | 27 | #ifndef SYSTEM_CORE_INCLUDE_MINCRYPT_HASH_INTERNAL_H_ |
| 28 | #define SYSTEM_CORE_INCLUDE_MINCRYPT_HASH_INTERNAL_H_ |
Dees Troy | bb4c0cb | 2013-11-02 20:25:14 +0000 | [diff] [blame] | 29 | |
| 30 | #include <stdint.h> |
| 31 | |
| 32 | #ifdef __cplusplus |
| 33 | extern "C" { |
| 34 | #endif // __cplusplus |
| 35 | |
| 36 | struct HASH_CTX; // forward decl |
| 37 | |
| 38 | typedef struct HASH_VTAB { |
| 39 | void (* const init)(struct HASH_CTX*); |
| 40 | void (* const update)(struct HASH_CTX*, const void*, int); |
| 41 | const uint8_t* (* const final)(struct HASH_CTX*); |
| 42 | const uint8_t* (* const hash)(const void*, int, uint8_t*); |
| 43 | int size; |
| 44 | } HASH_VTAB; |
| 45 | |
| 46 | typedef struct HASH_CTX { |
| 47 | const HASH_VTAB * f; |
| 48 | uint64_t count; |
| 49 | uint8_t buf[64]; |
| 50 | uint32_t state[8]; // upto SHA2 |
| 51 | } HASH_CTX; |
| 52 | |
| 53 | #define HASH_init(ctx) (ctx)->f->init(ctx) |
| 54 | #define HASH_update(ctx, data, len) (ctx)->f->update(ctx, data, len) |
| 55 | #define HASH_final(ctx) (ctx)->f->final(ctx) |
| 56 | #define HASH_hash(data, len, digest) (ctx)->f->hash(data, len, digest) |
| 57 | #define HASH_size(ctx) (ctx)->f->size |
| 58 | |
| 59 | #ifdef __cplusplus |
| 60 | } |
| 61 | #endif // __cplusplus |
| 62 | |
Ethan Yonker | 1e4a199 | 2014-11-06 09:05:01 -0600 | [diff] [blame] | 63 | #endif // SYSTEM_CORE_INCLUDE_MINCRYPT_HASH_INTERNAL_H_ |