File:  [ELWIX - Embedded LightWeight unIX -] / embedaddon / ipsec-tools / src / racoon / missing / crypto / sha2 / sha2.h
Revision 1.1.1.1 (vendor branch): download - view: text, annotated - select for diffs - revision graph
Tue Feb 21 22:39:10 2012 UTC (12 years, 5 months ago) by misho
Branches: ipsec-tools, MAIN
CVS tags: v0_8_2p2, v0_8_1p0, v0_8_1, v0_8_0p0, v0_8_0, HEAD
ipsec-tools

    1: /*	$NetBSD: sha2.h,v 1.4 2006/09/09 16:22:36 manu Exp $	*/
    2: 
    3: /*	$KAME: sha2.h,v 1.2 2001/08/08 22:09:27 sakane Exp $	*/
    4: 
    5: /*
    6:  * sha2.h
    7:  *
    8:  * Version 1.0.0beta1
    9:  *
   10:  * Written by Aaron D. Gifford <me@aarongifford.com>
   11:  *
   12:  * Copyright 2000 Aaron D. Gifford.  All rights reserved.
   13:  *
   14:  * Redistribution and use in source and binary forms, with or without
   15:  * modification, are permitted provided that the following conditions
   16:  * are met:
   17:  * 1. Redistributions of source code must retain the above copyright
   18:  *    notice, this list of conditions and the following disclaimer.
   19:  * 2. Redistributions in binary form must reproduce the above copyright
   20:  *    notice, this list of conditions and the following disclaimer in the
   21:  *    documentation and/or other materials provided with the distribution.
   22:  * 3. Neither the name of the copyright holder nor the names of contributors
   23:  *    may be used to endorse or promote products derived from this software
   24:  *    without specific prior written permission.
   25:  * 
   26:  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR(S) AND CONTRIBUTOR(S) ``AS IS'' AND
   27:  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
   28:  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
   29:  * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR(S) OR CONTRIBUTOR(S) BE LIABLE
   30:  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
   31:  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
   32:  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
   33:  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
   34:  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
   35:  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
   36:  * SUCH DAMAGE.
   37:  *
   38:  */
   39: 
   40: #ifndef __SHA2_H__
   41: #define __SHA2_H__
   42: 
   43: #ifdef __cplusplus
   44: extern "C" {
   45: #endif
   46: 
   47: 
   48: /*** SHA-256/384/512 Various Length Definitions ***********************/
   49: #define SHA256_BLOCK_LENGTH		64
   50: #define SHA256_DIGEST_LENGTH		32
   51: #define SHA256_DIGEST_STRING_LENGTH	(SHA256_DIGEST_LENGTH * 2 + 1)
   52: #define SHA384_BLOCK_LENGTH		128
   53: #define SHA384_DIGEST_LENGTH		48
   54: #define SHA384_DIGEST_STRING_LENGTH	(SHA384_DIGEST_LENGTH * 2 + 1)
   55: #define SHA512_BLOCK_LENGTH		128
   56: #define SHA512_DIGEST_LENGTH		64
   57: #define SHA512_DIGEST_STRING_LENGTH	(SHA512_DIGEST_LENGTH * 2 + 1)
   58: 
   59: 
   60: /*** SHA-256/384/512 Context Structures *******************************/
   61: /* NOTE: If your architecture does not define either u_intXX_t types or
   62:  * uintXX_t (from inttypes.h), you may need to define things by hand
   63:  * for your system:
   64:  */
   65: #if 0
   66: typedef unsigned char u_int8_t;		/* 1-byte  (8-bits)  */
   67: typedef unsigned int u_int32_t;		/* 4-bytes (32-bits) */
   68: typedef unsigned long long u_int64_t;	/* 8-bytes (64-bits) */
   69: #endif
   70: 
   71: #ifndef HAVE_SHA2_IN_SHA_H
   72: /*
   73:  * Most BSD systems already define u_intXX_t types, as does Linux.
   74:  * Some systems, however, like Compaq's Tru64 Unix instead can use
   75:  * uintXX_t types defined by very recent ANSI C standards and included
   76:  * in the file:
   77:  *
   78:  *   #include <inttypes.h>
   79:  *
   80:  * If you choose to use <inttypes.h> then please define: 
   81:  *
   82:  *   #define SHA2_USE_INTTYPES_H
   83:  *
   84:  * Or on the command line during compile:
   85:  *
   86:  *   cc -DSHA2_USE_INTTYPES_H ...
   87:  */
   88: #if 0 /*def SHA2_USE_INTTYPES_H*/
   89: 
   90: typedef struct _SHA256_CTX {
   91: 	uint32_t	state[8];
   92: 	uint64_t	bitcount;
   93: 	uint8_t	buffer[SHA256_BLOCK_LENGTH];
   94: } SHA256_CTX;
   95: typedef struct _SHA512_CTX {
   96: 	uint64_t	state[8];
   97: 	uint64_t	bitcount[2];
   98: 	uint8_t	buffer[SHA512_BLOCK_LENGTH];
   99: } SHA512_CTX;
  100: 
  101: #else /* SHA2_USE_INTTYPES_H */
  102: 
  103: typedef struct _SHA256_CTX {
  104: 	u_int32_t	state[8];
  105: 	u_int64_t	bitcount;
  106: 	u_int8_t	buffer[SHA256_BLOCK_LENGTH];
  107: } SHA256_CTX;
  108: typedef struct _SHA512_CTX {
  109: 	u_int64_t	state[8];
  110: 	u_int64_t	bitcount[2];
  111: 	u_int8_t	buffer[SHA512_BLOCK_LENGTH];
  112: } SHA512_CTX;
  113: 
  114: #endif /* SHA2_USE_INTTYPES_H */
  115: #endif /* HAVE_SHA2_IN_SHA_H */
  116: 
  117: typedef SHA512_CTX SHA384_CTX;
  118: 
  119: 
  120: /*** SHA-256/384/512 Function Prototypes ******************************/
  121: 
  122: #ifndef HAVE_SHA2_IN_SHA_H
  123: void SHA256_Init __P((SHA256_CTX *));
  124: void SHA256_Update __P((SHA256_CTX*, const u_int8_t*, size_t));
  125: void SHA256_Final __P((u_int8_t[SHA256_DIGEST_LENGTH], SHA256_CTX*));
  126: #endif /* HAVE_SHA2_IN_SHA_H */
  127: char* SHA256_End __P((SHA256_CTX*, char[SHA256_DIGEST_STRING_LENGTH]));
  128: char* SHA256_Data __P((const u_int8_t*, size_t, char[SHA256_DIGEST_STRING_LENGTH]));
  129: 
  130: #ifndef HAVE_SHA2_IN_SHA_H
  131: void SHA384_Init __P((SHA384_CTX*));
  132: void SHA384_Update __P((SHA384_CTX*, const u_int8_t*, size_t));
  133: void SHA384_Final __P((u_int8_t[SHA384_DIGEST_LENGTH], SHA384_CTX*));
  134: #endif /* HAVE_SHA2_IN_SHA_H */
  135: char* SHA384_End __P((SHA384_CTX*, char[SHA384_DIGEST_STRING_LENGTH]));
  136: char* SHA384_Data __P((const u_int8_t*, size_t, char[SHA384_DIGEST_STRING_LENGTH]));
  137: 
  138: #ifndef HAVE_SHA2_IN_SHA_H
  139: void SHA512_Init __P((SHA512_CTX*));
  140: void SHA512_Update __P((SHA512_CTX*, const u_int8_t*, size_t));
  141: void SHA512_Final __P((u_int8_t[SHA512_DIGEST_LENGTH], SHA512_CTX*));
  142: #endif /* HAVE_SHA2_IN_SHA_H */
  143: char* SHA512_End __P((SHA512_CTX*, char[SHA512_DIGEST_STRING_LENGTH]));
  144: char* SHA512_Data __P((const u_int8_t*, size_t, char[SHA512_DIGEST_STRING_LENGTH]));
  145: 
  146: struct env_md_st *EVP_sha2_256 __P((void));
  147: struct env_md_st *EVP_sha2_384 __P((void));
  148: struct env_md_st *EVP_sha2_512 __P((void));
  149: 
  150: #ifdef HAVE_SHA2_IN_SHA_H
  151: #define EVP_sha2_256 EVP_sha256
  152: #define EVP_sha2_384 EVP_sha384
  153: #define EVP_sha2_512 EVP_sha512
  154: #endif
  155: 
  156: #ifdef	__cplusplus
  157: }
  158: #endif /* __cplusplus */
  159: 
  160: #endif /* __SHA2_H__ */
  161: 

FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>