16de2e5a9f46dcd05c5bbc407ddac8fb05a82c78fKenny Root/* 26de2e5a9f46dcd05c5bbc407ddac8fb05a82c78fKenny Root * Copyright 2007 The Android Open Source Project 36de2e5a9f46dcd05c5bbc407ddac8fb05a82c78fKenny Root * 46de2e5a9f46dcd05c5bbc407ddac8fb05a82c78fKenny Root * Redistribution and use in source and binary forms, with or without 56de2e5a9f46dcd05c5bbc407ddac8fb05a82c78fKenny Root * modification, are permitted provided that the following conditions are met: 66de2e5a9f46dcd05c5bbc407ddac8fb05a82c78fKenny Root * * Redistributions of source code must retain the above copyright 76de2e5a9f46dcd05c5bbc407ddac8fb05a82c78fKenny Root * notice, this list of conditions and the following disclaimer. 86de2e5a9f46dcd05c5bbc407ddac8fb05a82c78fKenny Root * * Redistributions in binary form must reproduce the above copyright 96de2e5a9f46dcd05c5bbc407ddac8fb05a82c78fKenny Root * notice, this list of conditions and the following disclaimer in the 106de2e5a9f46dcd05c5bbc407ddac8fb05a82c78fKenny Root * documentation and/or other materials provided with the distribution. 116de2e5a9f46dcd05c5bbc407ddac8fb05a82c78fKenny Root * * Neither the name of Google Inc. nor the names of its contributors may 126de2e5a9f46dcd05c5bbc407ddac8fb05a82c78fKenny Root * be used to endorse or promote products derived from this software 136de2e5a9f46dcd05c5bbc407ddac8fb05a82c78fKenny Root * without specific prior written permission. 146de2e5a9f46dcd05c5bbc407ddac8fb05a82c78fKenny Root * 156de2e5a9f46dcd05c5bbc407ddac8fb05a82c78fKenny Root * THIS SOFTWARE IS PROVIDED BY Google Inc. ``AS IS'' AND ANY EXPRESS OR 166de2e5a9f46dcd05c5bbc407ddac8fb05a82c78fKenny Root * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 176de2e5a9f46dcd05c5bbc407ddac8fb05a82c78fKenny Root * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO 186de2e5a9f46dcd05c5bbc407ddac8fb05a82c78fKenny Root * EVENT SHALL Google Inc. BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 196de2e5a9f46dcd05c5bbc407ddac8fb05a82c78fKenny Root * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 206de2e5a9f46dcd05c5bbc407ddac8fb05a82c78fKenny Root * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; 216de2e5a9f46dcd05c5bbc407ddac8fb05a82c78fKenny Root * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, 226de2e5a9f46dcd05c5bbc407ddac8fb05a82c78fKenny Root * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR 236de2e5a9f46dcd05c5bbc407ddac8fb05a82c78fKenny Root * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF 246de2e5a9f46dcd05c5bbc407ddac8fb05a82c78fKenny Root * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 256de2e5a9f46dcd05c5bbc407ddac8fb05a82c78fKenny Root */ 266de2e5a9f46dcd05c5bbc407ddac8fb05a82c78fKenny Root 27fca75c837bebfbd51927156158de36fc517742f7Mattias Nissler#ifndef CONSTRAINEDCRYPTO_HASH_INTERNAL_H_ 28fca75c837bebfbd51927156158de36fc517742f7Mattias Nissler#define CONSTRAINEDCRYPTO_HASH_INTERNAL_H_ 29259756979dd8e19d63a663aea2c765cb85fa3647Doug Zongker 30259756979dd8e19d63a663aea2c765cb85fa3647Doug Zongker#include <stdint.h> 31259756979dd8e19d63a663aea2c765cb85fa3647Doug Zongker 32259756979dd8e19d63a663aea2c765cb85fa3647Doug Zongker#ifdef __cplusplus 33259756979dd8e19d63a663aea2c765cb85fa3647Doug Zongkerextern "C" { 34259756979dd8e19d63a663aea2c765cb85fa3647Doug Zongker#endif // __cplusplus 35259756979dd8e19d63a663aea2c765cb85fa3647Doug Zongker 36259756979dd8e19d63a663aea2c765cb85fa3647Doug Zongkerstruct HASH_CTX; // forward decl 37259756979dd8e19d63a663aea2c765cb85fa3647Doug Zongker 38259756979dd8e19d63a663aea2c765cb85fa3647Doug Zongkertypedef struct HASH_VTAB { 39259756979dd8e19d63a663aea2c765cb85fa3647Doug Zongker void (* const init)(struct HASH_CTX*); 40259756979dd8e19d63a663aea2c765cb85fa3647Doug Zongker void (* const update)(struct HASH_CTX*, const void*, int); 41259756979dd8e19d63a663aea2c765cb85fa3647Doug Zongker const uint8_t* (* const final)(struct HASH_CTX*); 42259756979dd8e19d63a663aea2c765cb85fa3647Doug Zongker const uint8_t* (* const hash)(const void*, int, uint8_t*); 43259756979dd8e19d63a663aea2c765cb85fa3647Doug Zongker int size; 44259756979dd8e19d63a663aea2c765cb85fa3647Doug Zongker} HASH_VTAB; 45259756979dd8e19d63a663aea2c765cb85fa3647Doug Zongker 46259756979dd8e19d63a663aea2c765cb85fa3647Doug Zongkertypedef struct HASH_CTX { 47259756979dd8e19d63a663aea2c765cb85fa3647Doug Zongker const HASH_VTAB * f; 48259756979dd8e19d63a663aea2c765cb85fa3647Doug Zongker uint64_t count; 49259756979dd8e19d63a663aea2c765cb85fa3647Doug Zongker uint8_t buf[64]; 50259756979dd8e19d63a663aea2c765cb85fa3647Doug Zongker uint32_t state[8]; // upto SHA2 51259756979dd8e19d63a663aea2c765cb85fa3647Doug Zongker} HASH_CTX; 52259756979dd8e19d63a663aea2c765cb85fa3647Doug Zongker 53259756979dd8e19d63a663aea2c765cb85fa3647Doug Zongker#define HASH_init(ctx) (ctx)->f->init(ctx) 54259756979dd8e19d63a663aea2c765cb85fa3647Doug Zongker#define HASH_update(ctx, data, len) (ctx)->f->update(ctx, data, len) 55259756979dd8e19d63a663aea2c765cb85fa3647Doug Zongker#define HASH_final(ctx) (ctx)->f->final(ctx) 56259756979dd8e19d63a663aea2c765cb85fa3647Doug Zongker#define HASH_hash(data, len, digest) (ctx)->f->hash(data, len, digest) 57259756979dd8e19d63a663aea2c765cb85fa3647Doug Zongker#define HASH_size(ctx) (ctx)->f->size 58259756979dd8e19d63a663aea2c765cb85fa3647Doug Zongker 59259756979dd8e19d63a663aea2c765cb85fa3647Doug Zongker#ifdef __cplusplus 60259756979dd8e19d63a663aea2c765cb85fa3647Doug Zongker} 61259756979dd8e19d63a663aea2c765cb85fa3647Doug Zongker#endif // __cplusplus 62259756979dd8e19d63a663aea2c765cb85fa3647Doug Zongker 63fca75c837bebfbd51927156158de36fc517742f7Mattias Nissler#endif // CONSTRAINEDCRYPTO_HASH_INTERNAL_H_ 64