Header And Logo

PostgreSQL
| The world's most advanced open source database.

sha2.h

Go to the documentation of this file.
00001 /*  contrib/pgcrypto/sha2.h */
00002 /*  $OpenBSD: sha2.h,v 1.2 2004/04/28 23:11:57 millert Exp $    */
00003 
00004 /*
00005  * FILE:    sha2.h
00006  * AUTHOR:  Aaron D. Gifford <[email protected]>
00007  *
00008  * Copyright (c) 2000-2001, Aaron D. Gifford
00009  * All rights reserved.
00010  *
00011  * Redistribution and use in source and binary forms, with or without
00012  * modification, are permitted provided that the following conditions
00013  * are met:
00014  * 1. Redistributions of source code must retain the above copyright
00015  *    notice, this list of conditions and the following disclaimer.
00016  * 2. Redistributions in binary form must reproduce the above copyright
00017  *    notice, this list of conditions and the following disclaimer in the
00018  *    documentation and/or other materials provided with the distribution.
00019  * 3. Neither the name of the copyright holder nor the names of contributors
00020  *    may be used to endorse or promote products derived from this software
00021  *    without specific prior written permission.
00022  *
00023  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTOR(S) ``AS IS'' AND
00024  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
00025  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
00026  * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTOR(S) BE LIABLE
00027  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
00028  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
00029  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
00030  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
00031  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
00032  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
00033  * SUCH DAMAGE.
00034  *
00035  * $From: sha2.h,v 1.1 2001/11/08 00:02:01 adg Exp adg $
00036  */
00037 
00038 #ifndef _SHA2_H
00039 #define _SHA2_H
00040 
00041 /* avoid conflict with OpenSSL */
00042 #define SHA256_Init pg_SHA256_Init
00043 #define SHA256_Update pg_SHA256_Update
00044 #define SHA256_Final pg_SHA256_Final
00045 #define SHA384_Init pg_SHA384_Init
00046 #define SHA384_Update pg_SHA384_Update
00047 #define SHA384_Final pg_SHA384_Final
00048 #define SHA512_Init pg_SHA512_Init
00049 #define SHA512_Update pg_SHA512_Update
00050 #define SHA512_Final pg_SHA512_Final
00051 
00052 /*** SHA-224/256/384/512 Various Length Definitions ***********************/
00053 #define SHA224_BLOCK_LENGTH     64
00054 #define SHA224_DIGEST_LENGTH        28
00055 #define SHA224_DIGEST_STRING_LENGTH (SHA224_DIGEST_LENGTH * 2 + 1)
00056 #define SHA256_BLOCK_LENGTH     64
00057 #define SHA256_DIGEST_LENGTH        32
00058 #define SHA256_DIGEST_STRING_LENGTH (SHA256_DIGEST_LENGTH * 2 + 1)
00059 #define SHA384_BLOCK_LENGTH     128
00060 #define SHA384_DIGEST_LENGTH        48
00061 #define SHA384_DIGEST_STRING_LENGTH (SHA384_DIGEST_LENGTH * 2 + 1)
00062 #define SHA512_BLOCK_LENGTH     128
00063 #define SHA512_DIGEST_LENGTH        64
00064 #define SHA512_DIGEST_STRING_LENGTH (SHA512_DIGEST_LENGTH * 2 + 1)
00065 
00066 
00067 /*** SHA-256/384/512 Context Structures *******************************/
00068 typedef struct _SHA256_CTX
00069 {
00070     uint32      state[8];
00071     uint64      bitcount;
00072     uint8       buffer[SHA256_BLOCK_LENGTH];
00073 } SHA256_CTX;
00074 typedef struct _SHA512_CTX
00075 {
00076     uint64      state[8];
00077     uint64      bitcount[2];
00078     uint8       buffer[SHA512_BLOCK_LENGTH];
00079 } SHA512_CTX;
00080 
00081 typedef SHA256_CTX SHA224_CTX;
00082 typedef SHA512_CTX SHA384_CTX;
00083 
00084 void        SHA224_Init(SHA224_CTX *);
00085 void        SHA224_Update(SHA224_CTX *, const uint8 *, size_t);
00086 void        SHA224_Final(uint8[SHA224_DIGEST_LENGTH], SHA224_CTX *);
00087 
00088 void        SHA256_Init(SHA256_CTX *);
00089 void        SHA256_Update(SHA256_CTX *, const uint8 *, size_t);
00090 void        SHA256_Final(uint8[SHA256_DIGEST_LENGTH], SHA256_CTX *);
00091 
00092 void        SHA384_Init(SHA384_CTX *);
00093 void        SHA384_Update(SHA384_CTX *, const uint8 *, size_t);
00094 void        SHA384_Final(uint8[SHA384_DIGEST_LENGTH], SHA384_CTX *);
00095 
00096 void        SHA512_Init(SHA512_CTX *);
00097 void        SHA512_Update(SHA512_CTX *, const uint8 *, size_t);
00098 void        SHA512_Final(uint8[SHA512_DIGEST_LENGTH], SHA512_CTX *);
00099 
00100 #endif   /* _SHA2_H */