sha2.h

Go to the documentation of this file.
00001 /*      $FreeBSD: src/sys/crypto/sha2/sha2.h,v 1.1.2.1 2001/07/03 11:01:36 ume Exp $    */
00002 /*      $KAME: sha2.h,v 1.3 2001/03/12 08:27:48 itojun Exp $    */
00003 
00004 /*
00005  * sha2.h
00006  *
00007  * Version 1.0.0beta1
00008  *
00009  * Written by Aaron D. Gifford <me@aarongifford.com>
00010  *
00011  * Copyright 2000 Aaron D. Gifford.  All rights reserved.
00012  *
00013  * Redistribution and use in source and binary forms, with or without
00014  * modification, are permitted provided that the following conditions
00015  * are met:
00016  * 1. Redistributions of source code must retain the above copyright
00017  *    notice, this list of conditions and the following disclaimer.
00018  * 2. Redistributions in binary form must reproduce the above copyright
00019  *    notice, this list of conditions and the following disclaimer in the
00020  *    documentation and/or other materials provided with the distribution.
00021  * 3. Neither the name of the copyright holder nor the names of contributors
00022  *    may be used to endorse or promote products derived from this software
00023  *    without specific prior written permission.
00024  * 
00025  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR(S) AND CONTRIBUTOR(S) ``AS IS'' AND
00026  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
00027  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
00028  * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR(S) OR CONTRIBUTOR(S) BE LIABLE
00029  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
00030  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
00031  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
00032  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
00033  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
00034  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
00035  * SUCH DAMAGE.
00036  *
00037  */
00038 
00039 #ifndef __SHA2_H__
00040 #define __SHA2_H__
00041 
00042 #ifdef __cplusplus
00043 extern "C" {
00044 #endif
00045 
00046 /*** SHA-256/384/512 Various Length Definitions ***********************/
00047 #define SHA256_BLOCK_LENGTH             64
00048 #define SHA256_DIGEST_LENGTH            32
00049 #define SHA256_DIGEST_STRING_LENGTH     (SHA256_DIGEST_LENGTH * 2 + 1)
00050 #define SHA384_BLOCK_LENGTH             128
00051 #define SHA384_DIGEST_LENGTH            48
00052 #define SHA384_DIGEST_STRING_LENGTH     (SHA384_DIGEST_LENGTH * 2 + 1)
00053 #define SHA512_BLOCK_LENGTH             128
00054 #define SHA512_DIGEST_LENGTH            64
00055 #define SHA512_DIGEST_STRING_LENGTH     (SHA512_DIGEST_LENGTH * 2 + 1)
00056 
00057 #ifdef __minix
00058 #include <assert.h>
00059 #include <string.h>
00060 #include <sys/types.h>
00061 #include <minix/u64.h>
00062 
00063 typedef u8_t u_int8_t;  /* 1-byte  (8-bits)  */
00064 typedef u32_t u_int32_t;        /* 4-bytes (32-bits) */
00065 typedef u64_t u_int64_t;        /* 8-bytes (64-bits) */
00066 
00067 #ifndef __P
00068 #define __P(x) x
00069 #endif
00070 
00071 #define NO_64BIT        1
00072 #define MINIX_64BIT     1
00073 
00074 #define SHA2_BYTE_ORDER         0x04030201
00075 #define SHA2_LITTLE_ENDIAN      0x04030201
00076 #define SHA2_BIG_ENDIAN         0x01020204
00077 #define bcopy(s,d,l)    (memmove((d),(s),(l)))
00078 #define bzero(d,l)      (memset((d),'\0',(l)))
00079 #endif
00080 
00081 /*** SHA-256/384/512 Context Structures *******************************/
00082 /* NOTE: If your architecture does not define either u_intXX_t types or
00083  * uintXX_t (from inttypes.h), you may need to define things by hand
00084  * for your system:
00085  */
00086 #if 0
00087 typedef unsigned char u_int8_t;         /* 1-byte  (8-bits)  */
00088 typedef unsigned int u_int32_t;         /* 4-bytes (32-bits) */
00089 typedef unsigned long long u_int64_t;   /* 8-bytes (64-bits) */
00090 #endif
00091 /*
00092  * Most BSD systems already define u_intXX_t types, as does Linux.
00093  * Some systems, however, like Compaq's Tru64 Unix instead can use
00094  * uintXX_t types defined by very recent ANSI C standards and included
00095  * in the file:
00096  *
00097  *   #include <inttypes.h>
00098  *
00099  * If you choose to use <inttypes.h> then please define: 
00100  *
00101  *   #define SHA2_USE_INTTYPES_H
00102  *
00103  * Or on the command line during compile:
00104  *
00105  *   cc -DSHA2_USE_INTTYPES_H ...
00106  */
00107 #if 0 /*def SHA2_USE_INTTYPES_H*/
00108 
00109 typedef struct _SHA256_CTX {
00110         uint32_t        state[8];
00111         uint64_t        bitcount;
00112         uint8_t buffer[SHA256_BLOCK_LENGTH];
00113 } SHA256_CTX;
00114 typedef struct _SHA512_CTX {
00115         uint64_t        state[8];
00116         uint64_t        bitcount[2];
00117         uint8_t buffer[SHA512_BLOCK_LENGTH];
00118 } SHA512_CTX;
00119 
00120 #else /* SHA2_USE_INTTYPES_H */
00121 
00122 typedef struct _SHA256_CTX {
00123         u_int32_t       state[8];
00124         u_int64_t       bitcount;
00125         u_int8_t        buffer[SHA256_BLOCK_LENGTH];
00126 } SHA256_CTX;
00127 typedef struct _SHA512_CTX {
00128         u_int64_t       state[8];
00129         u_int64_t       bitcount[2];
00130         u_int8_t        buffer[SHA512_BLOCK_LENGTH];
00131 } SHA512_CTX;
00132 
00133 #endif /* SHA2_USE_INTTYPES_H */
00134 
00135 typedef SHA512_CTX SHA384_CTX;
00136 
00137 /*** SHA-256/384/512 Function Prototypes ******************************/
00138 
00139 void SHA256_Init __P((SHA256_CTX *));
00140 void SHA256_Update __P((SHA256_CTX*, const u_int8_t*, size_t));
00141 void SHA256_Final __P((u_int8_t[SHA256_DIGEST_LENGTH], SHA256_CTX*));
00142 char* SHA256_End __P((SHA256_CTX*, char[SHA256_DIGEST_STRING_LENGTH]));
00143 char* SHA256_Data __P((const u_int8_t*, size_t, char[SHA256_DIGEST_STRING_LENGTH]));
00144 
00145 void SHA384_Init __P((SHA384_CTX*));
00146 void SHA384_Update __P((SHA384_CTX*, const u_int8_t*, size_t));
00147 void SHA384_Final __P((u_int8_t[SHA384_DIGEST_LENGTH], SHA384_CTX*));
00148 char* SHA384_End __P((SHA384_CTX*, char[SHA384_DIGEST_STRING_LENGTH]));
00149 char* SHA384_Data __P((const u_int8_t*, size_t, char[SHA384_DIGEST_STRING_LENGTH]));
00150 
00151 void SHA512_Init __P((SHA512_CTX*));
00152 void SHA512_Update __P((SHA512_CTX*, const u_int8_t*, size_t));
00153 void SHA512_Final __P((u_int8_t[SHA512_DIGEST_LENGTH], SHA512_CTX*));
00154 char* SHA512_End __P((SHA512_CTX*, char[SHA512_DIGEST_STRING_LENGTH]));
00155 char* SHA512_Data __P((const u_int8_t*, size_t, char[SHA512_DIGEST_STRING_LENGTH]));
00156 
00157 #ifdef  __cplusplus
00158 }
00159 #endif /* __cplusplus */
00160 
00161 #endif /* __SHA2_H__ */
00162 
00163 /*
00164  * $PchId: sha2.h,v 1.1 2005/06/28 14:29:33 philip Exp $
00165  */

Generated on Fri Apr 14 22:57:18 2006 for minix by  doxygen 1.4.6