1db0850c3b637faaa7cbe1bab2e6c91ad2af35426Kenny Root/*
2db0850c3b637faaa7cbe1bab2e6c91ad2af35426Kenny Root * Copyright 2007 The Android Open Source Project
3db0850c3b637faaa7cbe1bab2e6c91ad2af35426Kenny Root *
4db0850c3b637faaa7cbe1bab2e6c91ad2af35426Kenny Root * Redistribution and use in source and binary forms, with or without
5db0850c3b637faaa7cbe1bab2e6c91ad2af35426Kenny Root * modification, are permitted provided that the following conditions are met:
6db0850c3b637faaa7cbe1bab2e6c91ad2af35426Kenny Root *     * Redistributions of source code must retain the above copyright
7db0850c3b637faaa7cbe1bab2e6c91ad2af35426Kenny Root *       notice, this list of conditions and the following disclaimer.
8db0850c3b637faaa7cbe1bab2e6c91ad2af35426Kenny Root *     * Redistributions in binary form must reproduce the above copyright
9db0850c3b637faaa7cbe1bab2e6c91ad2af35426Kenny Root *       notice, this list of conditions and the following disclaimer in the
10db0850c3b637faaa7cbe1bab2e6c91ad2af35426Kenny Root *       documentation and/or other materials provided with the distribution.
11db0850c3b637faaa7cbe1bab2e6c91ad2af35426Kenny Root *     * Neither the name of Google Inc. nor the names of its contributors may
12db0850c3b637faaa7cbe1bab2e6c91ad2af35426Kenny Root *       be used to endorse or promote products derived from this software
13db0850c3b637faaa7cbe1bab2e6c91ad2af35426Kenny Root *       without specific prior written permission.
14db0850c3b637faaa7cbe1bab2e6c91ad2af35426Kenny Root *
15db0850c3b637faaa7cbe1bab2e6c91ad2af35426Kenny Root * THIS SOFTWARE IS PROVIDED BY Google Inc. ``AS IS'' AND ANY EXPRESS OR
16db0850c3b637faaa7cbe1bab2e6c91ad2af35426Kenny Root * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
17db0850c3b637faaa7cbe1bab2e6c91ad2af35426Kenny Root * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO
18db0850c3b637faaa7cbe1bab2e6c91ad2af35426Kenny Root * EVENT SHALL Google Inc. BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
19db0850c3b637faaa7cbe1bab2e6c91ad2af35426Kenny Root * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
20db0850c3b637faaa7cbe1bab2e6c91ad2af35426Kenny Root * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
21db0850c3b637faaa7cbe1bab2e6c91ad2af35426Kenny Root * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
22db0850c3b637faaa7cbe1bab2e6c91ad2af35426Kenny Root * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
23db0850c3b637faaa7cbe1bab2e6c91ad2af35426Kenny Root * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
24db0850c3b637faaa7cbe1bab2e6c91ad2af35426Kenny Root * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
25db0850c3b637faaa7cbe1bab2e6c91ad2af35426Kenny Root */
26db0850c3b637faaa7cbe1bab2e6c91ad2af35426Kenny Root
27db0850c3b637faaa7cbe1bab2e6c91ad2af35426Kenny Root#ifndef SYSTEM_CORE_INCLUDE_MINCRYPT_HASH_INTERNAL_H_
28db0850c3b637faaa7cbe1bab2e6c91ad2af35426Kenny Root#define SYSTEM_CORE_INCLUDE_MINCRYPT_HASH_INTERNAL_H_
298e5b63d045e988f13d1ee9b7797db28fde15bbfcDoug Zongker
308e5b63d045e988f13d1ee9b7797db28fde15bbfcDoug Zongker#include <stdint.h>
318e5b63d045e988f13d1ee9b7797db28fde15bbfcDoug Zongker
328e5b63d045e988f13d1ee9b7797db28fde15bbfcDoug Zongker#ifdef __cplusplus
338e5b63d045e988f13d1ee9b7797db28fde15bbfcDoug Zongkerextern "C" {
348e5b63d045e988f13d1ee9b7797db28fde15bbfcDoug Zongker#endif  // __cplusplus
358e5b63d045e988f13d1ee9b7797db28fde15bbfcDoug Zongker
368e5b63d045e988f13d1ee9b7797db28fde15bbfcDoug Zongkerstruct HASH_CTX;  // forward decl
378e5b63d045e988f13d1ee9b7797db28fde15bbfcDoug Zongker
388e5b63d045e988f13d1ee9b7797db28fde15bbfcDoug Zongkertypedef struct HASH_VTAB {
398e5b63d045e988f13d1ee9b7797db28fde15bbfcDoug Zongker  void (* const init)(struct HASH_CTX*);
408e5b63d045e988f13d1ee9b7797db28fde15bbfcDoug Zongker  void (* const update)(struct HASH_CTX*, const void*, int);
418e5b63d045e988f13d1ee9b7797db28fde15bbfcDoug Zongker  const uint8_t* (* const final)(struct HASH_CTX*);
428e5b63d045e988f13d1ee9b7797db28fde15bbfcDoug Zongker  const uint8_t* (* const hash)(const void*, int, uint8_t*);
438e5b63d045e988f13d1ee9b7797db28fde15bbfcDoug Zongker  int size;
448e5b63d045e988f13d1ee9b7797db28fde15bbfcDoug Zongker} HASH_VTAB;
458e5b63d045e988f13d1ee9b7797db28fde15bbfcDoug Zongker
468e5b63d045e988f13d1ee9b7797db28fde15bbfcDoug Zongkertypedef struct HASH_CTX {
478e5b63d045e988f13d1ee9b7797db28fde15bbfcDoug Zongker  const HASH_VTAB * f;
488e5b63d045e988f13d1ee9b7797db28fde15bbfcDoug Zongker  uint64_t count;
498e5b63d045e988f13d1ee9b7797db28fde15bbfcDoug Zongker  uint8_t buf[64];
508e5b63d045e988f13d1ee9b7797db28fde15bbfcDoug Zongker  uint32_t state[8];  // upto SHA2
518e5b63d045e988f13d1ee9b7797db28fde15bbfcDoug Zongker} HASH_CTX;
528e5b63d045e988f13d1ee9b7797db28fde15bbfcDoug Zongker
538e5b63d045e988f13d1ee9b7797db28fde15bbfcDoug Zongker#define HASH_init(ctx) (ctx)->f->init(ctx)
548e5b63d045e988f13d1ee9b7797db28fde15bbfcDoug Zongker#define HASH_update(ctx, data, len) (ctx)->f->update(ctx, data, len)
558e5b63d045e988f13d1ee9b7797db28fde15bbfcDoug Zongker#define HASH_final(ctx) (ctx)->f->final(ctx)
568e5b63d045e988f13d1ee9b7797db28fde15bbfcDoug Zongker#define HASH_hash(data, len, digest) (ctx)->f->hash(data, len, digest)
578e5b63d045e988f13d1ee9b7797db28fde15bbfcDoug Zongker#define HASH_size(ctx) (ctx)->f->size
588e5b63d045e988f13d1ee9b7797db28fde15bbfcDoug Zongker
598e5b63d045e988f13d1ee9b7797db28fde15bbfcDoug Zongker#ifdef __cplusplus
608e5b63d045e988f13d1ee9b7797db28fde15bbfcDoug Zongker}
618e5b63d045e988f13d1ee9b7797db28fde15bbfcDoug Zongker#endif  // __cplusplus
628e5b63d045e988f13d1ee9b7797db28fde15bbfcDoug Zongker
63db0850c3b637faaa7cbe1bab2e6c91ad2af35426Kenny Root#endif  // SYSTEM_CORE_INCLUDE_MINCRYPT_HASH_INTERNAL_H_
64