The Android Open Source Project | dd7bc33 | 2009-03-03 19:32:55 -0800 | [diff] [blame] | 1 | /* sha.h |
| 2 | ** |
| 3 | ** Copyright 2008, The Android Open Source Project |
| 4 | ** |
| 5 | ** Redistribution and use in source and binary forms, with or without |
| 6 | ** modification, are permitted provided that the following conditions are met: |
| 7 | ** * Redistributions of source code must retain the above copyright |
| 8 | ** notice, this list of conditions and the following disclaimer. |
| 9 | ** * Redistributions in binary form must reproduce the above copyright |
| 10 | ** notice, this list of conditions and the following disclaimer in the |
| 11 | ** documentation and/or other materials provided with the distribution. |
| 12 | ** * Neither the name of Google Inc. nor the names of its contributors may |
| 13 | ** be used to endorse or promote products derived from this software |
| 14 | ** without specific prior written permission. |
| 15 | ** |
Doug Zongker | a6de77d | 2009-08-17 15:38:31 -0700 | [diff] [blame^] | 16 | ** THIS SOFTWARE IS PROVIDED BY Google Inc. ``AS IS'' AND ANY EXPRESS OR |
The Android Open Source Project | dd7bc33 | 2009-03-03 19:32:55 -0800 | [diff] [blame] | 17 | ** IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF |
Doug Zongker | a6de77d | 2009-08-17 15:38:31 -0700 | [diff] [blame^] | 18 | ** MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO |
The Android Open Source Project | dd7bc33 | 2009-03-03 19:32:55 -0800 | [diff] [blame] | 19 | ** EVENT SHALL Google Inc. BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
| 20 | ** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, |
Doug Zongker | a6de77d | 2009-08-17 15:38:31 -0700 | [diff] [blame^] | 21 | ** PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; |
| 22 | ** OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, |
| 23 | ** WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR |
The Android Open Source Project | dd7bc33 | 2009-03-03 19:32:55 -0800 | [diff] [blame] | 24 | ** OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF |
| 25 | ** ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 26 | */ |
| 27 | |
| 28 | #ifndef _EMBEDDED_SHA_H_ |
| 29 | #define _EMBEDDED_SHA_H_ |
| 30 | |
| 31 | #include <inttypes.h> |
Doug Zongker | a6de77d | 2009-08-17 15:38:31 -0700 | [diff] [blame^] | 32 | #include <endian.h> |
The Android Open Source Project | dd7bc33 | 2009-03-03 19:32:55 -0800 | [diff] [blame] | 33 | |
| 34 | #ifdef __cplusplus |
| 35 | extern "C" { |
| 36 | #endif |
| 37 | |
| 38 | typedef struct SHA_CTX { |
| 39 | uint64_t count; |
The Android Open Source Project | dd7bc33 | 2009-03-03 19:32:55 -0800 | [diff] [blame] | 40 | uint32_t state[5]; |
Doug Zongker | a6de77d | 2009-08-17 15:38:31 -0700 | [diff] [blame^] | 41 | #if __BYTE_ORDER == __LITTLE_ENDIAN |
| 42 | union { |
| 43 | uint8_t b[64]; |
| 44 | uint32_t w[16]; |
| 45 | } buf; |
| 46 | #else |
| 47 | uint8_t buf[64]; |
| 48 | #endif |
The Android Open Source Project | dd7bc33 | 2009-03-03 19:32:55 -0800 | [diff] [blame] | 49 | } SHA_CTX; |
| 50 | |
Doug Zongker | a6de77d | 2009-08-17 15:38:31 -0700 | [diff] [blame^] | 51 | void SHA_init(SHA_CTX* ctx); |
| 52 | void SHA_update(SHA_CTX* ctx, const void* data, int len); |
| 53 | const uint8_t* SHA_final(SHA_CTX* ctx); |
The Android Open Source Project | dd7bc33 | 2009-03-03 19:32:55 -0800 | [diff] [blame] | 54 | |
| 55 | /* Convenience method. Returns digest parameter value. */ |
Doug Zongker | a6de77d | 2009-08-17 15:38:31 -0700 | [diff] [blame^] | 56 | const uint8_t* SHA(const void* data, int len, uint8_t* digest); |
The Android Open Source Project | dd7bc33 | 2009-03-03 19:32:55 -0800 | [diff] [blame] | 57 | |
| 58 | #define SHA_DIGEST_SIZE 20 |
| 59 | |
| 60 | #ifdef __cplusplus |
| 61 | } |
| 62 | #endif |
| 63 | |
| 64 | #endif |