Back to home page

EIC code displayed by LXR

 
 

    


Warning, file /include/sha2.h was not indexed or was modified since last indexation (in which case cross-reference links may be missing, inaccurate or erroneous).

0001 /*  $OpenBSD: sha2.h,v 1.10 2016/09/03 17:00:29 tedu 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-224/256/384/512 Various Length Definitions ***********************/
0045 #define SHA224_BLOCK_LENGTH     64
0046 #define SHA224_DIGEST_LENGTH        28
0047 #define SHA224_DIGEST_STRING_LENGTH (SHA224_DIGEST_LENGTH * 2 + 1)
0048 #define SHA256_BLOCK_LENGTH     64
0049 #define SHA256_DIGEST_LENGTH        32
0050 #define SHA256_DIGEST_STRING_LENGTH (SHA256_DIGEST_LENGTH * 2 + 1)
0051 #define SHA384_BLOCK_LENGTH     128
0052 #define SHA384_DIGEST_LENGTH        48
0053 #define SHA384_DIGEST_STRING_LENGTH (SHA384_DIGEST_LENGTH * 2 + 1)
0054 #define SHA512_BLOCK_LENGTH     128
0055 #define SHA512_DIGEST_LENGTH        64
0056 #define SHA512_DIGEST_STRING_LENGTH (SHA512_DIGEST_LENGTH * 2 + 1)
0057 #define SHA512_256_BLOCK_LENGTH     128
0058 #define SHA512_256_DIGEST_LENGTH    32
0059 #define SHA512_256_DIGEST_STRING_LENGTH (SHA512_256_DIGEST_LENGTH * 2 + 1)
0060 
0061 
0062 /*** SHA-224/256/384/512 Context Structure *******************************/
0063 typedef struct _SHA2_CTX {
0064     union {
0065         uint32_t    st32[8];
0066         uint64_t    st64[8];
0067     } state;
0068     uint64_t    bitcount[2];
0069     uint8_t     buffer[SHA512_BLOCK_LENGTH];
0070 } SHA2_CTX;
0071 
0072 #ifdef __cplusplus
0073 extern "C" {
0074 #endif
0075 
0076 void SHA224Init(SHA2_CTX *);
0077 void SHA224Transform(uint32_t state[8], const uint8_t [SHA224_BLOCK_LENGTH]);
0078 void SHA224Update(SHA2_CTX *, const uint8_t *, size_t);
0079 void SHA224Pad(SHA2_CTX *);
0080 void SHA224Final(uint8_t [SHA224_DIGEST_LENGTH], SHA2_CTX *);
0081 char *SHA224End(SHA2_CTX *, char *);
0082 char *SHA224File(const char *, char *);
0083 char *SHA224FileChunk(const char *, char *, off_t, off_t);
0084 char *SHA224Data(const uint8_t *, size_t, char *);
0085 
0086 void SHA256Init(SHA2_CTX *);
0087 void SHA256Transform(uint32_t state[8], const uint8_t [SHA256_BLOCK_LENGTH]);
0088 void SHA256Update(SHA2_CTX *, const uint8_t *, size_t);
0089 void SHA256Pad(SHA2_CTX *);
0090 void SHA256Final(uint8_t [SHA256_DIGEST_LENGTH], SHA2_CTX *);
0091 char *SHA256End(SHA2_CTX *, char *);
0092 char *SHA256File(const char *, char *);
0093 char *SHA256FileChunk(const char *, char *, off_t, off_t);
0094 char *SHA256Data(const uint8_t *, size_t, char *);
0095 
0096 void SHA384Init(SHA2_CTX *);
0097 void SHA384Transform(uint64_t state[8], const uint8_t [SHA384_BLOCK_LENGTH]);
0098 void SHA384Update(SHA2_CTX *, const uint8_t *, size_t);
0099 void SHA384Pad(SHA2_CTX *);
0100 void SHA384Final(uint8_t [SHA384_DIGEST_LENGTH], SHA2_CTX *);
0101 char *SHA384End(SHA2_CTX *, char *);
0102 char *SHA384File(const char *, char *);
0103 char *SHA384FileChunk(const char *, char *, off_t, off_t);
0104 char *SHA384Data(const uint8_t *, size_t, char *);
0105 
0106 void SHA512Init(SHA2_CTX *);
0107 void SHA512Transform(uint64_t state[8], const uint8_t [SHA512_BLOCK_LENGTH]);
0108 void SHA512Update(SHA2_CTX *, const uint8_t *, size_t);
0109 void SHA512Pad(SHA2_CTX *);
0110 void SHA512Final(uint8_t [SHA512_DIGEST_LENGTH], SHA2_CTX *);
0111 char *SHA512End(SHA2_CTX *, char *);
0112 char *SHA512File(const char *, char *);
0113 char *SHA512FileChunk(const char *, char *, off_t, off_t);
0114 char *SHA512Data(const uint8_t *, size_t, char *);
0115 
0116 void SHA512_256Init(SHA2_CTX *);
0117 void SHA512_256Transform(uint64_t state[8], const uint8_t [SHA512_256_BLOCK_LENGTH]);
0118 void SHA512_256Update(SHA2_CTX *, const uint8_t *, size_t);
0119 void SHA512_256Pad(SHA2_CTX *);
0120 void SHA512_256Final(uint8_t [SHA512_256_DIGEST_LENGTH], SHA2_CTX *);
0121 char *SHA512_256End(SHA2_CTX *, char *);
0122 char *SHA512_256File(const char *, char *);
0123 char *SHA512_256FileChunk(const char *, char *, off_t, off_t);
0124 char *SHA512_256Data(const uint8_t *, size_t, char *);
0125 
0126 #ifdef __cplusplus
0127 }
0128 #endif
0129 
0130 #endif /* _SHA2_H */