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 */ 26 27 #ifndef SYSTEM_CORE_INCLUDE_MINCRYPT_HASH_INTERNAL_H_ 28 #define SYSTEM_CORE_INCLUDE_MINCRYPT_HASH_INTERNAL_H_ 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*, uint32_t); 41 const uint8_t* (* const final)(struct HASH_CTX*); 42 const uint8_t* (* const hash)(const void*, uint32_t, uint8_t*); 43 int size; 44 } HASH_VTAB; 45 46 typedef struct HASH_CTX { 47 const HASH_VTAB * f; 48 uint64_t count; 49 union { 50 uint8_t buf[64]; 51 uint32_t buf32[64 / 4]; 52 }; 53 uint32_t state[8]; // upto SHA2 54 } HASH_CTX; 55 56 #define HASH_init(ctx) (ctx)->f->init(ctx) 57 #define HASH_update(ctx, data, len) (ctx)->f->update(ctx, data, len) 58 #define HASH_final(ctx) (ctx)->f->final(ctx) 59 #define HASH_hash(data, len, digest) (ctx)->f->hash(data, len, digest) 60 #define HASH_size(ctx) (ctx)->f->size 61 62 #ifdef __cplusplus 63 } 64 #endif // __cplusplus 65 66 #endif // SYSTEM_CORE_INCLUDE_MINCRYPT_HASH_INTERNAL_H_ 67