1 /* contrib/pgcrypto/sha2.h */ 2 /* $OpenBSD: sha2.h,v 1.2 2004/04/28 23:11:57 millert Exp $ */ 3 4 /* 5 * FILE: sha2.h 6 * AUTHOR: Aaron D. Gifford <me@aarongifford.com> 7 * 8 * Copyright (c) 2000-2001, Aaron D. Gifford 9 * All rights reserved. 10 * 11 * Redistribution and use in source and binary forms, with or without 12 * modification, are permitted provided that the following conditions 13 * are met: 14 * 1. Redistributions of source code must retain the above copyright 15 * notice, this list of conditions and the following disclaimer. 16 * 2. Redistributions in binary form must reproduce the above copyright 17 * notice, this list of conditions and the following disclaimer in the 18 * documentation and/or other materials provided with the distribution. 19 * 3. Neither the name of the copyright holder nor the names of contributors 20 * may be used to endorse or promote products derived from this software 21 * without specific prior written permission. 22 * 23 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTOR(S) ``AS IS'' AND 24 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 25 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 26 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTOR(S) BE LIABLE 27 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 28 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 29 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 30 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 31 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 32 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 33 * SUCH DAMAGE. 34 * 35 * $From: sha2.h,v 1.1 2001/11/08 00:02:01 adg Exp adg $ 36 */ 37 38 #ifndef _SHA2_H 39 #define _SHA2_H 40 41 /* avoid conflict with OpenSSL */ 42 #define SHA224_Init pg_SHA224_Init 43 #define SHA224_Update pg_SHA224_Update 44 #define SHA224_Final pg_SHA224_Final 45 #define SHA256_Init pg_SHA256_Init 46 #define SHA256_Update pg_SHA256_Update 47 #define SHA256_Final pg_SHA256_Final 48 #define SHA384_Init pg_SHA384_Init 49 #define SHA384_Update pg_SHA384_Update 50 #define SHA384_Final pg_SHA384_Final 51 #define SHA512_Init pg_SHA512_Init 52 #define SHA512_Update pg_SHA512_Update 53 #define SHA512_Final pg_SHA512_Final 54 55 /*** SHA-224/256/384/512 Various Length Definitions ***********************/ 56 #define SHA224_BLOCK_LENGTH 64 57 #define SHA224_DIGEST_LENGTH 28 58 #define SHA224_DIGEST_STRING_LENGTH (SHA224_DIGEST_LENGTH * 2 + 1) 59 #define SHA256_BLOCK_LENGTH 64 60 #define SHA256_DIGEST_LENGTH 32 61 #define SHA256_DIGEST_STRING_LENGTH (SHA256_DIGEST_LENGTH * 2 + 1) 62 #define SHA384_BLOCK_LENGTH 128 63 #define SHA384_DIGEST_LENGTH 48 64 #define SHA384_DIGEST_STRING_LENGTH (SHA384_DIGEST_LENGTH * 2 + 1) 65 #define SHA512_BLOCK_LENGTH 128 66 #define SHA512_DIGEST_LENGTH 64 67 #define SHA512_DIGEST_STRING_LENGTH (SHA512_DIGEST_LENGTH * 2 + 1) 68 69 70 /*** SHA-256/384/512 Context Structures *******************************/ 71 typedef struct _SHA256_CTX 72 { 73 uint32 state[8]; 74 uint64 bitcount; 75 uint8 buffer[SHA256_BLOCK_LENGTH]; 76 } SHA256_CTX; 77 typedef struct _SHA512_CTX 78 { 79 uint64 state[8]; 80 uint64 bitcount[2]; 81 uint8 buffer[SHA512_BLOCK_LENGTH]; 82 } SHA512_CTX; 83 84 typedef SHA256_CTX SHA224_CTX; 85 typedef SHA512_CTX SHA384_CTX; 86 87 void SHA224_Init(SHA224_CTX *); 88 void SHA224_Update(SHA224_CTX *, const uint8 *, size_t); 89 void SHA224_Final(uint8[SHA224_DIGEST_LENGTH], SHA224_CTX *); 90 91 void SHA256_Init(SHA256_CTX *); 92 void SHA256_Update(SHA256_CTX *, const uint8 *, size_t); 93 void SHA256_Final(uint8[SHA256_DIGEST_LENGTH], SHA256_CTX *); 94 95 void SHA384_Init(SHA384_CTX *); 96 void SHA384_Update(SHA384_CTX *, const uint8 *, size_t); 97 void SHA384_Final(uint8[SHA384_DIGEST_LENGTH], SHA384_CTX *); 98 99 void SHA512_Init(SHA512_CTX *); 100 void SHA512_Update(SHA512_CTX *, const uint8 *, size_t); 101 void SHA512_Final(uint8[SHA512_DIGEST_LENGTH], SHA512_CTX *); 102 103 #endif /* _SHA2_H */ 104