1*f6bf8f90Stedu /* $OpenBSD: sha2.h,v 1.10 2016/09/03 17:00:29 tedu Exp $ */ 262c0070cSmillert 362c0070cSmillert /* 462c0070cSmillert * FILE: sha2.h 562c0070cSmillert * AUTHOR: Aaron D. Gifford <me@aarongifford.com> 662c0070cSmillert * 762c0070cSmillert * Copyright (c) 2000-2001, Aaron D. Gifford 862c0070cSmillert * All rights reserved. 962c0070cSmillert * 1062c0070cSmillert * Redistribution and use in source and binary forms, with or without 1162c0070cSmillert * modification, are permitted provided that the following conditions 1262c0070cSmillert * are met: 1362c0070cSmillert * 1. Redistributions of source code must retain the above copyright 1462c0070cSmillert * notice, this list of conditions and the following disclaimer. 1562c0070cSmillert * 2. Redistributions in binary form must reproduce the above copyright 1662c0070cSmillert * notice, this list of conditions and the following disclaimer in the 1762c0070cSmillert * documentation and/or other materials provided with the distribution. 1862c0070cSmillert * 3. Neither the name of the copyright holder nor the names of contributors 1962c0070cSmillert * may be used to endorse or promote products derived from this software 2062c0070cSmillert * without specific prior written permission. 2162c0070cSmillert * 2262c0070cSmillert * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTOR(S) ``AS IS'' AND 2362c0070cSmillert * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 2462c0070cSmillert * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 2562c0070cSmillert * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTOR(S) BE LIABLE 2662c0070cSmillert * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 2762c0070cSmillert * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 2862c0070cSmillert * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 2962c0070cSmillert * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 3062c0070cSmillert * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 3162c0070cSmillert * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 3262c0070cSmillert * SUCH DAMAGE. 3362c0070cSmillert * 3462c0070cSmillert * $From: sha2.h,v 1.1 2001/11/08 00:02:01 adg Exp adg $ 3562c0070cSmillert */ 3662c0070cSmillert 3762c0070cSmillert #ifndef _SHA2_H 3862c0070cSmillert #define _SHA2_H 3962c0070cSmillert 4062c0070cSmillert 4162c0070cSmillert /*** SHA-256/384/512 Various Length Definitions ***********************/ 422c851520Smillert #define SHA224_BLOCK_LENGTH 64 432c851520Smillert #define SHA224_DIGEST_LENGTH 28 442c851520Smillert #define SHA224_DIGEST_STRING_LENGTH (SHA224_DIGEST_LENGTH * 2 + 1) 4562c0070cSmillert #define SHA256_BLOCK_LENGTH 64 4662c0070cSmillert #define SHA256_DIGEST_LENGTH 32 4762c0070cSmillert #define SHA256_DIGEST_STRING_LENGTH (SHA256_DIGEST_LENGTH * 2 + 1) 4862c0070cSmillert #define SHA384_BLOCK_LENGTH 128 4962c0070cSmillert #define SHA384_DIGEST_LENGTH 48 5062c0070cSmillert #define SHA384_DIGEST_STRING_LENGTH (SHA384_DIGEST_LENGTH * 2 + 1) 5162c0070cSmillert #define SHA512_BLOCK_LENGTH 128 5262c0070cSmillert #define SHA512_DIGEST_LENGTH 64 5362c0070cSmillert #define SHA512_DIGEST_STRING_LENGTH (SHA512_DIGEST_LENGTH * 2 + 1) 54*f6bf8f90Stedu #define SHA512_256_BLOCK_LENGTH 128 55*f6bf8f90Stedu #define SHA512_256_DIGEST_LENGTH 32 56*f6bf8f90Stedu #define SHA512_256_DIGEST_STRING_LENGTH (SHA512_256_DIGEST_LENGTH * 2 + 1) 5762c0070cSmillert 5862c0070cSmillert 592c851520Smillert /*** SHA-224/256/384/512 Context Structure *******************************/ 604ef0b5fdSdjm typedef struct _SHA2_CTX { 614ef0b5fdSdjm union { 624ef0b5fdSdjm u_int32_t st32[8]; 634ef0b5fdSdjm u_int64_t st64[8]; 644ef0b5fdSdjm } state; 6562c0070cSmillert u_int64_t bitcount[2]; 6662c0070cSmillert u_int8_t buffer[SHA512_BLOCK_LENGTH]; 674ef0b5fdSdjm } SHA2_CTX; 6862c0070cSmillert 6962c0070cSmillert __BEGIN_DECLS 702c851520Smillert void SHA224Init(SHA2_CTX *); 712c851520Smillert void SHA224Transform(u_int32_t state[8], const u_int8_t [SHA224_BLOCK_LENGTH]); 722c851520Smillert void SHA224Update(SHA2_CTX *, const u_int8_t *, size_t) 732c851520Smillert __attribute__((__bounded__(__string__,2,3))); 742c851520Smillert void SHA224Pad(SHA2_CTX *); 752c851520Smillert void SHA224Final(u_int8_t [SHA224_DIGEST_LENGTH], SHA2_CTX *) 762c851520Smillert __attribute__((__bounded__(__minbytes__,1,SHA224_DIGEST_LENGTH))); 772c851520Smillert char *SHA224End(SHA2_CTX *, char *) 782c851520Smillert __attribute__((__bounded__(__minbytes__,2,SHA224_DIGEST_STRING_LENGTH))); 792c851520Smillert char *SHA224File(const char *, char *) 802c851520Smillert __attribute__((__bounded__(__minbytes__,2,SHA224_DIGEST_STRING_LENGTH))); 812c851520Smillert char *SHA224FileChunk(const char *, char *, off_t, off_t) 822c851520Smillert __attribute__((__bounded__(__minbytes__,2,SHA224_DIGEST_STRING_LENGTH))); 832c851520Smillert char *SHA224Data(const u_int8_t *, size_t, char *) 842c851520Smillert __attribute__((__bounded__(__string__,1,2))) 852c851520Smillert __attribute__((__bounded__(__minbytes__,3,SHA224_DIGEST_STRING_LENGTH))); 862c851520Smillert 874ef0b5fdSdjm void SHA256Init(SHA2_CTX *); 884ef0b5fdSdjm void SHA256Transform(u_int32_t state[8], const u_int8_t [SHA256_BLOCK_LENGTH]); 894ef0b5fdSdjm void SHA256Update(SHA2_CTX *, const u_int8_t *, size_t) 9086ad99fcSmillert __attribute__((__bounded__(__string__,2,3))); 914ef0b5fdSdjm void SHA256Pad(SHA2_CTX *); 924ef0b5fdSdjm void SHA256Final(u_int8_t [SHA256_DIGEST_LENGTH], SHA2_CTX *) 9386ad99fcSmillert __attribute__((__bounded__(__minbytes__,1,SHA256_DIGEST_LENGTH))); 944ef0b5fdSdjm char *SHA256End(SHA2_CTX *, char *) 9586ad99fcSmillert __attribute__((__bounded__(__minbytes__,2,SHA256_DIGEST_STRING_LENGTH))); 964ef0b5fdSdjm char *SHA256File(const char *, char *) 9786ad99fcSmillert __attribute__((__bounded__(__minbytes__,2,SHA256_DIGEST_STRING_LENGTH))); 984ef0b5fdSdjm char *SHA256FileChunk(const char *, char *, off_t, off_t) 999dfc8d30Smillert __attribute__((__bounded__(__minbytes__,2,SHA256_DIGEST_STRING_LENGTH))); 1004ef0b5fdSdjm char *SHA256Data(const u_int8_t *, size_t, char *) 10186ad99fcSmillert __attribute__((__bounded__(__string__,1,2))) 10286ad99fcSmillert __attribute__((__bounded__(__minbytes__,3,SHA256_DIGEST_STRING_LENGTH))); 10362c0070cSmillert 1044ef0b5fdSdjm void SHA384Init(SHA2_CTX *); 1054ef0b5fdSdjm void SHA384Transform(u_int64_t state[8], const u_int8_t [SHA384_BLOCK_LENGTH]); 1064ef0b5fdSdjm void SHA384Update(SHA2_CTX *, const u_int8_t *, size_t) 10786ad99fcSmillert __attribute__((__bounded__(__string__,2,3))); 1084ef0b5fdSdjm void SHA384Pad(SHA2_CTX *); 1094ef0b5fdSdjm void SHA384Final(u_int8_t [SHA384_DIGEST_LENGTH], SHA2_CTX *) 11086ad99fcSmillert __attribute__((__bounded__(__minbytes__,1,SHA384_DIGEST_LENGTH))); 1114ef0b5fdSdjm char *SHA384End(SHA2_CTX *, char *) 11286ad99fcSmillert __attribute__((__bounded__(__minbytes__,2,SHA384_DIGEST_STRING_LENGTH))); 1134ef0b5fdSdjm char *SHA384File(const char *, char *) 11486ad99fcSmillert __attribute__((__bounded__(__minbytes__,2,SHA384_DIGEST_STRING_LENGTH))); 1154ef0b5fdSdjm char *SHA384FileChunk(const char *, char *, off_t, off_t) 1169dfc8d30Smillert __attribute__((__bounded__(__minbytes__,2,SHA384_DIGEST_STRING_LENGTH))); 1174ef0b5fdSdjm char *SHA384Data(const u_int8_t *, size_t, char *) 11886ad99fcSmillert __attribute__((__bounded__(__string__,1,2))) 11986ad99fcSmillert __attribute__((__bounded__(__minbytes__,3,SHA384_DIGEST_STRING_LENGTH))); 12062c0070cSmillert 1214ef0b5fdSdjm void SHA512Init(SHA2_CTX *); 1224ef0b5fdSdjm void SHA512Transform(u_int64_t state[8], const u_int8_t [SHA512_BLOCK_LENGTH]); 1234ef0b5fdSdjm void SHA512Update(SHA2_CTX *, const u_int8_t *, size_t) 12486ad99fcSmillert __attribute__((__bounded__(__string__,2,3))); 1254ef0b5fdSdjm void SHA512Pad(SHA2_CTX *); 1264ef0b5fdSdjm void SHA512Final(u_int8_t [SHA512_DIGEST_LENGTH], SHA2_CTX *) 12786ad99fcSmillert __attribute__((__bounded__(__minbytes__,1,SHA512_DIGEST_LENGTH))); 1284ef0b5fdSdjm char *SHA512End(SHA2_CTX *, char *) 12986ad99fcSmillert __attribute__((__bounded__(__minbytes__,2,SHA512_DIGEST_STRING_LENGTH))); 1304ef0b5fdSdjm char *SHA512File(const char *, char *) 13186ad99fcSmillert __attribute__((__bounded__(__minbytes__,2,SHA512_DIGEST_STRING_LENGTH))); 1324ef0b5fdSdjm char *SHA512FileChunk(const char *, char *, off_t, off_t) 1339dfc8d30Smillert __attribute__((__bounded__(__minbytes__,2,SHA512_DIGEST_STRING_LENGTH))); 1344ef0b5fdSdjm char *SHA512Data(const u_int8_t *, size_t, char *) 13586ad99fcSmillert __attribute__((__bounded__(__string__,1,2))) 13686ad99fcSmillert __attribute__((__bounded__(__minbytes__,3,SHA512_DIGEST_STRING_LENGTH))); 137*f6bf8f90Stedu 138*f6bf8f90Stedu void SHA512_256Init(SHA2_CTX *); 139*f6bf8f90Stedu void SHA512_256Transform(u_int64_t state[8], const u_int8_t [SHA512_256_BLOCK_LENGTH]); 140*f6bf8f90Stedu void SHA512_256Update(SHA2_CTX *, const u_int8_t *, size_t) 141*f6bf8f90Stedu __attribute__((__bounded__(__string__,2,3))); 142*f6bf8f90Stedu void SHA512_256Pad(SHA2_CTX *); 143*f6bf8f90Stedu void SHA512_256Final(u_int8_t [SHA512_256_DIGEST_LENGTH], SHA2_CTX *) 144*f6bf8f90Stedu __attribute__((__bounded__(__minbytes__,1,SHA512_256_DIGEST_LENGTH))); 145*f6bf8f90Stedu char *SHA512_256End(SHA2_CTX *, char *) 146*f6bf8f90Stedu __attribute__((__bounded__(__minbytes__,2,SHA512_256_DIGEST_STRING_LENGTH))); 147*f6bf8f90Stedu char *SHA512_256File(const char *, char *) 148*f6bf8f90Stedu __attribute__((__bounded__(__minbytes__,2,SHA512_256_DIGEST_STRING_LENGTH))); 149*f6bf8f90Stedu char *SHA512_256FileChunk(const char *, char *, off_t, off_t) 150*f6bf8f90Stedu __attribute__((__bounded__(__minbytes__,2,SHA512_256_DIGEST_STRING_LENGTH))); 151*f6bf8f90Stedu char *SHA512_256Data(const u_int8_t *, size_t, char *) 152*f6bf8f90Stedu __attribute__((__bounded__(__string__,1,2))) 153*f6bf8f90Stedu __attribute__((__bounded__(__minbytes__,3,SHA512_256_DIGEST_STRING_LENGTH))); 15462c0070cSmillert __END_DECLS 15562c0070cSmillert 15662c0070cSmillert #endif /* _SHA2_H */ 157