1240075Sdes/* OpenBSD: sha2.h,v 1.6 2004/06/22 01:57:30 jfb Exp */ 2162852Sdes 3162852Sdes/* 4162852Sdes * FILE: sha2.h 5162852Sdes * AUTHOR: Aaron D. Gifford <me@aarongifford.com> 6162852Sdes * 7162852Sdes * Copyright (c) 2000-2001, Aaron D. Gifford 8162852Sdes * All rights reserved. 9162852Sdes * 10162852Sdes * Redistribution and use in source and binary forms, with or without 11162852Sdes * modification, are permitted provided that the following conditions 12162852Sdes * are met: 13162852Sdes * 1. Redistributions of source code must retain the above copyright 14162852Sdes * notice, this list of conditions and the following disclaimer. 15162852Sdes * 2. Redistributions in binary form must reproduce the above copyright 16162852Sdes * notice, this list of conditions and the following disclaimer in the 17162852Sdes * documentation and/or other materials provided with the distribution. 18162852Sdes * 3. Neither the name of the copyright holder nor the names of contributors 19162852Sdes * may be used to endorse or promote products derived from this software 20162852Sdes * without specific prior written permission. 21162852Sdes * 22162852Sdes * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTOR(S) ``AS IS'' AND 23162852Sdes * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 24162852Sdes * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 25162852Sdes * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTOR(S) BE LIABLE 26162852Sdes * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 27162852Sdes * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 28162852Sdes * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 29162852Sdes * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 30162852Sdes * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 31162852Sdes * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 32162852Sdes * SUCH DAMAGE. 33162852Sdes * 34162852Sdes * $From: sha2.h,v 1.1 2001/11/08 00:02:01 adg Exp adg $ 35162852Sdes */ 36162852Sdes 37162852Sdes/* OPENBSD ORIGINAL: include/sha2.h */ 38162852Sdes 39162852Sdes#ifndef _SSHSHA2_H 40162852Sdes#define _SSHSHA2_H 41162852Sdes 42162852Sdes#include "includes.h" 43162852Sdes 44295367Sdes#ifdef WITH_OPENSSL 45295367Sdes# include <openssl/opensslv.h> 46295367Sdes# if !defined(HAVE_EVP_SHA256) && (OPENSSL_VERSION_NUMBER >= 0x00907000L) 47295367Sdes# define _NEED_SHA2 1 48295367Sdes# endif 49295367Sdes#else 50295367Sdes# define _NEED_SHA2 1 51295367Sdes#endif 52162852Sdes 53295367Sdes#if defined(_NEED_SHA2) && !defined(HAVE_SHA256_UPDATE) 54162852Sdes 55162852Sdes/*** SHA-256/384/512 Various Length Definitions ***********************/ 56162852Sdes#define SHA256_BLOCK_LENGTH 64 57162852Sdes#define SHA256_DIGEST_LENGTH 32 58162852Sdes#define SHA256_DIGEST_STRING_LENGTH (SHA256_DIGEST_LENGTH * 2 + 1) 59162852Sdes#define SHA384_BLOCK_LENGTH 128 60162852Sdes#define SHA384_DIGEST_LENGTH 48 61162852Sdes#define SHA384_DIGEST_STRING_LENGTH (SHA384_DIGEST_LENGTH * 2 + 1) 62162852Sdes#define SHA512_BLOCK_LENGTH 128 63162852Sdes#define SHA512_DIGEST_LENGTH 64 64162852Sdes#define SHA512_DIGEST_STRING_LENGTH (SHA512_DIGEST_LENGTH * 2 + 1) 65162852Sdes 66162852Sdes 67162852Sdes/*** SHA-256/384/512 Context Structures *******************************/ 68162852Sdestypedef struct _SHA256_CTX { 69162852Sdes u_int32_t state[8]; 70162852Sdes u_int64_t bitcount; 71162852Sdes u_int8_t buffer[SHA256_BLOCK_LENGTH]; 72162852Sdes} SHA256_CTX; 73162852Sdestypedef struct _SHA512_CTX { 74162852Sdes u_int64_t state[8]; 75162852Sdes u_int64_t bitcount[2]; 76162852Sdes u_int8_t buffer[SHA512_BLOCK_LENGTH]; 77162852Sdes} SHA512_CTX; 78162852Sdes 79162852Sdestypedef SHA512_CTX SHA384_CTX; 80162852Sdes 81162852Sdesvoid SHA256_Init(SHA256_CTX *); 82162852Sdesvoid SHA256_Transform(u_int32_t state[8], const u_int8_t [SHA256_BLOCK_LENGTH]); 83162852Sdesvoid SHA256_Update(SHA256_CTX *, const u_int8_t *, size_t) 84162852Sdes __attribute__((__bounded__(__string__,2,3))); 85162852Sdesvoid SHA256_Pad(SHA256_CTX *); 86162852Sdesvoid SHA256_Final(u_int8_t [SHA256_DIGEST_LENGTH], SHA256_CTX *) 87162852Sdes __attribute__((__bounded__(__minbytes__,1,SHA256_DIGEST_LENGTH))); 88162852Sdeschar *SHA256_End(SHA256_CTX *, char *) 89162852Sdes __attribute__((__bounded__(__minbytes__,2,SHA256_DIGEST_STRING_LENGTH))); 90162852Sdeschar *SHA256_File(const char *, char *) 91162852Sdes __attribute__((__bounded__(__minbytes__,2,SHA256_DIGEST_STRING_LENGTH))); 92162852Sdeschar *SHA256_FileChunk(const char *, char *, off_t, off_t) 93162852Sdes __attribute__((__bounded__(__minbytes__,2,SHA256_DIGEST_STRING_LENGTH))); 94162852Sdeschar *SHA256_Data(const u_int8_t *, size_t, char *) 95162852Sdes __attribute__((__bounded__(__string__,1,2))) 96162852Sdes __attribute__((__bounded__(__minbytes__,3,SHA256_DIGEST_STRING_LENGTH))); 97162852Sdes 98162852Sdesvoid SHA384_Init(SHA384_CTX *); 99162852Sdesvoid SHA384_Transform(u_int64_t state[8], const u_int8_t [SHA384_BLOCK_LENGTH]); 100162852Sdesvoid SHA384_Update(SHA384_CTX *, const u_int8_t *, size_t) 101162852Sdes __attribute__((__bounded__(__string__,2,3))); 102162852Sdesvoid SHA384_Pad(SHA384_CTX *); 103162852Sdesvoid SHA384_Final(u_int8_t [SHA384_DIGEST_LENGTH], SHA384_CTX *) 104162852Sdes __attribute__((__bounded__(__minbytes__,1,SHA384_DIGEST_LENGTH))); 105162852Sdeschar *SHA384_End(SHA384_CTX *, char *) 106162852Sdes __attribute__((__bounded__(__minbytes__,2,SHA384_DIGEST_STRING_LENGTH))); 107162852Sdeschar *SHA384_File(const char *, char *) 108162852Sdes __attribute__((__bounded__(__minbytes__,2,SHA384_DIGEST_STRING_LENGTH))); 109162852Sdeschar *SHA384_FileChunk(const char *, char *, off_t, off_t) 110162852Sdes __attribute__((__bounded__(__minbytes__,2,SHA384_DIGEST_STRING_LENGTH))); 111162852Sdeschar *SHA384_Data(const u_int8_t *, size_t, char *) 112162852Sdes __attribute__((__bounded__(__string__,1,2))) 113162852Sdes __attribute__((__bounded__(__minbytes__,3,SHA384_DIGEST_STRING_LENGTH))); 114162852Sdes 115162852Sdesvoid SHA512_Init(SHA512_CTX *); 116162852Sdesvoid SHA512_Transform(u_int64_t state[8], const u_int8_t [SHA512_BLOCK_LENGTH]); 117162852Sdesvoid SHA512_Update(SHA512_CTX *, const u_int8_t *, size_t) 118162852Sdes __attribute__((__bounded__(__string__,2,3))); 119162852Sdesvoid SHA512_Pad(SHA512_CTX *); 120162852Sdesvoid SHA512_Final(u_int8_t [SHA512_DIGEST_LENGTH], SHA512_CTX *) 121162852Sdes __attribute__((__bounded__(__minbytes__,1,SHA512_DIGEST_LENGTH))); 122162852Sdeschar *SHA512_End(SHA512_CTX *, char *) 123162852Sdes __attribute__((__bounded__(__minbytes__,2,SHA512_DIGEST_STRING_LENGTH))); 124162852Sdeschar *SHA512_File(const char *, char *) 125162852Sdes __attribute__((__bounded__(__minbytes__,2,SHA512_DIGEST_STRING_LENGTH))); 126162852Sdeschar *SHA512_FileChunk(const char *, char *, off_t, off_t) 127162852Sdes __attribute__((__bounded__(__minbytes__,2,SHA512_DIGEST_STRING_LENGTH))); 128162852Sdeschar *SHA512_Data(const u_int8_t *, size_t, char *) 129162852Sdes __attribute__((__bounded__(__string__,1,2))) 130162852Sdes __attribute__((__bounded__(__minbytes__,3,SHA512_DIGEST_STRING_LENGTH))); 131162852Sdes 132295367Sdes#endif /* defined(_NEED_SHA2) && !defined(HAVE_SHA256_UPDATE) */ 133162852Sdes 134162852Sdes#endif /* _SSHSHA2_H */ 135