Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-17 09:55:58

0001 /*  $OpenBSD: sha2.h,v 1.6 2004/06/22 01:57:30 jfb Exp $    */
0002 
0003 /*
0004  * FILE:    sha2.h
0005  * AUTHOR:  Aaron D. Gifford <me@aarongifford.com>
0006  * 
0007  * Copyright (c) 2000-2001, Aaron D. Gifford
0008  * All rights reserved.
0009  *
0010  * Redistribution and use in source and binary forms, with or without
0011  * modification, are permitted provided that the following conditions
0012  * are met:
0013  * 1. Redistributions of source code must retain the above copyright
0014  *    notice, this list of conditions and the following disclaimer.
0015  * 2. Redistributions in binary form must reproduce the above copyright
0016  *    notice, this list of conditions and the following disclaimer in the
0017  *    documentation and/or other materials provided with the distribution.
0018  * 3. Neither the name of the copyright holder nor the names of contributors
0019  *    may be used to endorse or promote products derived from this software
0020  *    without specific prior written permission.
0021  * 
0022  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTOR(S) ``AS IS'' AND
0023  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
0024  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
0025  * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTOR(S) BE LIABLE
0026  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
0027  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
0028  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
0029  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
0030  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
0031  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
0032  * SUCH DAMAGE.
0033  *
0034  * $From: sha2.h,v 1.1 2001/11/08 00:02:01 adg Exp adg $
0035  */
0036 
0037 #ifndef _SHA2_H
0038 #define _SHA2_H
0039 
0040 #include <sys/types.h>
0041 
0042 #include <stdint.h>
0043 
0044 /*** SHA-256/384/512 Various Length Definitions ***********************/
0045 #define SHA256_BLOCK_LENGTH     64
0046 #define SHA256_DIGEST_LENGTH        32
0047 #define SHA256_DIGEST_STRING_LENGTH (SHA256_DIGEST_LENGTH * 2 + 1)
0048 #define SHA384_BLOCK_LENGTH     128
0049 #define SHA384_DIGEST_LENGTH        48
0050 #define SHA384_DIGEST_STRING_LENGTH (SHA384_DIGEST_LENGTH * 2 + 1)
0051 #define SHA512_BLOCK_LENGTH     128
0052 #define SHA512_DIGEST_LENGTH        64
0053 #define SHA512_DIGEST_STRING_LENGTH (SHA512_DIGEST_LENGTH * 2 + 1)
0054 
0055 
0056 /*** SHA-256/384/512 Context Structure *******************************/
0057 typedef struct _SHA2_CTX {
0058     union {
0059         uint32_t    st32[8];
0060         uint64_t    st64[8];
0061     } state;
0062     uint64_t    bitcount[2];
0063     uint8_t     buffer[SHA512_BLOCK_LENGTH];
0064 } SHA2_CTX;
0065 
0066 #ifdef __cplusplus
0067 extern "C" {
0068 #endif
0069 
0070 void SHA256Init(SHA2_CTX *);
0071 void SHA256Transform(uint32_t state[8], const uint8_t [SHA256_BLOCK_LENGTH]);
0072 void SHA256Update(SHA2_CTX *, const uint8_t *, size_t);
0073 void SHA256Pad(SHA2_CTX *);
0074 void SHA256Final(uint8_t [SHA256_DIGEST_LENGTH], SHA2_CTX *);
0075 char *SHA256End(SHA2_CTX *, char *);
0076 char *SHA256File(const char *, char *);
0077 char *SHA256FileChunk(const char *, char *, off_t, off_t);
0078 char *SHA256Data(const uint8_t *, size_t, char *);
0079 
0080 void SHA384Init(SHA2_CTX *);
0081 void SHA384Transform(uint64_t state[8], const uint8_t [SHA384_BLOCK_LENGTH]);
0082 void SHA384Update(SHA2_CTX *, const uint8_t *, size_t);
0083 void SHA384Pad(SHA2_CTX *);
0084 void SHA384Final(uint8_t [SHA384_DIGEST_LENGTH], SHA2_CTX *);
0085 char *SHA384End(SHA2_CTX *, char *);
0086 char *SHA384File(const char *, char *);
0087 char *SHA384FileChunk(const char *, char *, off_t, off_t);
0088 char *SHA384Data(const uint8_t *, size_t, char *);
0089 
0090 void SHA512Init(SHA2_CTX *);
0091 void SHA512Transform(uint64_t state[8], const uint8_t [SHA512_BLOCK_LENGTH]);
0092 void SHA512Update(SHA2_CTX *, const uint8_t *, size_t);
0093 void SHA512Pad(SHA2_CTX *);
0094 void SHA512Final(uint8_t [SHA512_DIGEST_LENGTH], SHA2_CTX *);
0095 char *SHA512End(SHA2_CTX *, char *);
0096 char *SHA512File(const char *, char *);
0097 char *SHA512FileChunk(const char *, char *, off_t, off_t);
0098 char *SHA512Data(const uint8_t *, size_t, char *);
0099 
0100 #ifdef __cplusplus
0101 }
0102 #endif
0103 
0104 #endif /* _SHA2_H */