satsolver 0.16.3
|
00001 /* 00002 * FILE: sha2.h 00003 * AUTHOR: Aaron D. Gifford <me@aarongifford.com> 00004 * 00005 * Copyright (c) 2000-2001, Aaron D. Gifford 00006 * All rights reserved. 00007 * 00008 * Redistribution and use in source and binary forms, with or without 00009 * modification, are permitted provided that the following conditions 00010 * are met: 00011 * 1. Redistributions of source code must retain the above copyright 00012 * notice, this list of conditions and the following disclaimer. 00013 * 2. Redistributions in binary form must reproduce the above copyright 00014 * notice, this list of conditions and the following disclaimer in the 00015 * documentation and/or other materials provided with the distribution. 00016 * 3. Neither the name of the copyright holder nor the names of contributors 00017 * may be used to endorse or promote products derived from this software 00018 * without specific prior written permission. 00019 * 00020 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTOR(S) ``AS IS'' AND 00021 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 00022 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 00023 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTOR(S) BE LIABLE 00024 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 00025 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 00026 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 00027 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 00028 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 00029 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 00030 * SUCH DAMAGE. 00031 * 00032 * $Id: sha2.h,v 1.1 2001/11/08 00:02:01 adg Exp adg $ 00033 */ 00034 00035 #include <inttypes.h> 00036 00037 00038 /*** SHA-256/384/512 Various Length Definitions ***********************/ 00039 #define SHA256_BLOCK_LENGTH 64 00040 #define SHA256_DIGEST_LENGTH 32 00041 #define SHA256_DIGEST_STRING_LENGTH (SHA256_DIGEST_LENGTH * 2 + 1) 00042 #define SHA384_BLOCK_LENGTH 128 00043 #define SHA384_DIGEST_LENGTH 48 00044 #define SHA384_DIGEST_STRING_LENGTH (SHA384_DIGEST_LENGTH * 2 + 1) 00045 #define SHA512_BLOCK_LENGTH 128 00046 #define SHA512_DIGEST_LENGTH 64 00047 #define SHA512_DIGEST_STRING_LENGTH (SHA512_DIGEST_LENGTH * 2 + 1) 00048 00049 00050 /*** SHA-256/384/512 Context Structures *******************************/ 00051 /* NOTE: If your architecture does not define either u_intXX_t types or 00052 * uintXX_t (from inttypes.h), you may need to define things by hand 00053 * for your system: 00054 */ 00055 typedef struct _SHA256_CTX { 00056 uint32_t state[8]; 00057 uint64_t bitcount; 00058 uint8_t buffer[SHA256_BLOCK_LENGTH]; 00059 } SHA256_CTX; 00060 typedef struct _SHA512_CTX { 00061 uint64_t state[8]; 00062 uint64_t bitcount[2]; 00063 uint8_t buffer[SHA512_BLOCK_LENGTH]; 00064 } SHA512_CTX; 00065 00066 typedef SHA512_CTX SHA384_CTX; 00067 00068 00069 /*** SHA-256/384/512 Function Prototypes ******************************/ 00070 void sat_SHA256_Init(SHA256_CTX *); 00071 void sat_SHA256_Update(SHA256_CTX*, const uint8_t*, size_t); 00072 void sat_SHA256_Final(uint8_t[SHA256_DIGEST_LENGTH], SHA256_CTX*); 00073 char* sat_SHA256_End(SHA256_CTX*, char[SHA256_DIGEST_STRING_LENGTH]); 00074 char* sat_SHA256_Data(const uint8_t*, size_t, char[SHA256_DIGEST_STRING_LENGTH]); 00075 00076 void sat_SHA384_Init(SHA384_CTX*); 00077 void sat_SHA384_Update(SHA384_CTX*, const uint8_t*, size_t); 00078 void sat_SHA384_Final(uint8_t[SHA384_DIGEST_LENGTH], SHA384_CTX*); 00079 char* sat_SHA384_End(SHA384_CTX*, char[SHA384_DIGEST_STRING_LENGTH]); 00080 char* sat_SHA384_Data(const uint8_t*, size_t, char[SHA384_DIGEST_STRING_LENGTH]); 00081 00082 void sat_SHA512_Init(SHA512_CTX*); 00083 void sat_SHA512_Update(SHA512_CTX*, const uint8_t*, size_t); 00084 void sat_SHA512_Final(uint8_t[SHA512_DIGEST_LENGTH], SHA512_CTX*); 00085 char* sat_SHA512_End(SHA512_CTX*, char[SHA512_DIGEST_STRING_LENGTH]); 00086 char* sat_SHA512_Data(const uint8_t*, size_t, char[SHA512_DIGEST_STRING_LENGTH]);