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 44162852Sdes#include <openssl/opensslv.h> 45162852Sdes 46162852Sdes#if !defined(HAVE_EVP_SHA256) && !defined(HAVE_SHA256_UPDATE) && \ 47162852Sdes (OPENSSL_VERSION_NUMBER >= 0x00907000L) 48162852Sdes 49162852Sdes/*** SHA-256/384/512 Various Length Definitions ***********************/ 50162852Sdes#define SHA256_BLOCK_LENGTH 64 51162852Sdes#define SHA256_DIGEST_LENGTH 32 52162852Sdes#define SHA256_DIGEST_STRING_LENGTH (SHA256_DIGEST_LENGTH * 2 + 1) 53162852Sdes#define SHA384_BLOCK_LENGTH 128 54162852Sdes#define SHA384_DIGEST_LENGTH 48 55162852Sdes#define SHA384_DIGEST_STRING_LENGTH (SHA384_DIGEST_LENGTH * 2 + 1) 56162852Sdes#define SHA512_BLOCK_LENGTH 128 57162852Sdes#define SHA512_DIGEST_LENGTH 64 58162852Sdes#define SHA512_DIGEST_STRING_LENGTH (SHA512_DIGEST_LENGTH * 2 + 1) 59162852Sdes 60162852Sdes 61162852Sdes/*** SHA-256/384/512 Context Structures *******************************/ 62162852Sdestypedef struct _SHA256_CTX { 63162852Sdes u_int32_t state[8]; 64162852Sdes u_int64_t bitcount; 65162852Sdes u_int8_t buffer[SHA256_BLOCK_LENGTH]; 66162852Sdes} SHA256_CTX; 67162852Sdestypedef struct _SHA512_CTX { 68162852Sdes u_int64_t state[8]; 69162852Sdes u_int64_t bitcount[2]; 70162852Sdes u_int8_t buffer[SHA512_BLOCK_LENGTH]; 71162852Sdes} SHA512_CTX; 72162852Sdes 73162852Sdes#if 0 74162852Sdestypedef SHA512_CTX SHA384_CTX; 75162852Sdes#endif 76162852Sdes 77162852Sdesvoid SHA256_Init(SHA256_CTX *); 78162852Sdesvoid SHA256_Transform(u_int32_t state[8], const u_int8_t [SHA256_BLOCK_LENGTH]); 79162852Sdesvoid SHA256_Update(SHA256_CTX *, const u_int8_t *, size_t) 80162852Sdes __attribute__((__bounded__(__string__,2,3))); 81162852Sdesvoid SHA256_Pad(SHA256_CTX *); 82162852Sdesvoid SHA256_Final(u_int8_t [SHA256_DIGEST_LENGTH], SHA256_CTX *) 83162852Sdes __attribute__((__bounded__(__minbytes__,1,SHA256_DIGEST_LENGTH))); 84162852Sdeschar *SHA256_End(SHA256_CTX *, char *) 85162852Sdes __attribute__((__bounded__(__minbytes__,2,SHA256_DIGEST_STRING_LENGTH))); 86162852Sdeschar *SHA256_File(const char *, char *) 87162852Sdes __attribute__((__bounded__(__minbytes__,2,SHA256_DIGEST_STRING_LENGTH))); 88162852Sdeschar *SHA256_FileChunk(const char *, char *, off_t, off_t) 89162852Sdes __attribute__((__bounded__(__minbytes__,2,SHA256_DIGEST_STRING_LENGTH))); 90162852Sdeschar *SHA256_Data(const u_int8_t *, size_t, char *) 91162852Sdes __attribute__((__bounded__(__string__,1,2))) 92162852Sdes __attribute__((__bounded__(__minbytes__,3,SHA256_DIGEST_STRING_LENGTH))); 93162852Sdes 94162852Sdes#if 0 95162852Sdesvoid SHA384_Init(SHA384_CTX *); 96162852Sdesvoid SHA384_Transform(u_int64_t state[8], const u_int8_t [SHA384_BLOCK_LENGTH]); 97162852Sdesvoid SHA384_Update(SHA384_CTX *, const u_int8_t *, size_t) 98162852Sdes __attribute__((__bounded__(__string__,2,3))); 99162852Sdesvoid SHA384_Pad(SHA384_CTX *); 100162852Sdesvoid SHA384_Final(u_int8_t [SHA384_DIGEST_LENGTH], SHA384_CTX *) 101162852Sdes __attribute__((__bounded__(__minbytes__,1,SHA384_DIGEST_LENGTH))); 102162852Sdeschar *SHA384_End(SHA384_CTX *, char *) 103162852Sdes __attribute__((__bounded__(__minbytes__,2,SHA384_DIGEST_STRING_LENGTH))); 104162852Sdeschar *SHA384_File(const char *, char *) 105162852Sdes __attribute__((__bounded__(__minbytes__,2,SHA384_DIGEST_STRING_LENGTH))); 106162852Sdeschar *SHA384_FileChunk(const char *, char *, off_t, off_t) 107162852Sdes __attribute__((__bounded__(__minbytes__,2,SHA384_DIGEST_STRING_LENGTH))); 108162852Sdeschar *SHA384_Data(const u_int8_t *, size_t, char *) 109162852Sdes __attribute__((__bounded__(__string__,1,2))) 110162852Sdes __attribute__((__bounded__(__minbytes__,3,SHA384_DIGEST_STRING_LENGTH))); 111162852Sdes#endif /* 0 */ 112162852Sdes 113162852Sdesvoid SHA512_Init(SHA512_CTX *); 114162852Sdesvoid SHA512_Transform(u_int64_t state[8], const u_int8_t [SHA512_BLOCK_LENGTH]); 115162852Sdesvoid SHA512_Update(SHA512_CTX *, const u_int8_t *, size_t) 116162852Sdes __attribute__((__bounded__(__string__,2,3))); 117162852Sdesvoid SHA512_Pad(SHA512_CTX *); 118162852Sdesvoid SHA512_Final(u_int8_t [SHA512_DIGEST_LENGTH], SHA512_CTX *) 119162852Sdes __attribute__((__bounded__(__minbytes__,1,SHA512_DIGEST_LENGTH))); 120162852Sdeschar *SHA512_End(SHA512_CTX *, char *) 121162852Sdes __attribute__((__bounded__(__minbytes__,2,SHA512_DIGEST_STRING_LENGTH))); 122162852Sdeschar *SHA512_File(const char *, char *) 123162852Sdes __attribute__((__bounded__(__minbytes__,2,SHA512_DIGEST_STRING_LENGTH))); 124162852Sdeschar *SHA512_FileChunk(const char *, char *, off_t, off_t) 125162852Sdes __attribute__((__bounded__(__minbytes__,2,SHA512_DIGEST_STRING_LENGTH))); 126162852Sdeschar *SHA512_Data(const u_int8_t *, size_t, char *) 127162852Sdes __attribute__((__bounded__(__string__,1,2))) 128162852Sdes __attribute__((__bounded__(__minbytes__,3,SHA512_DIGEST_STRING_LENGTH))); 129162852Sdes 130162852Sdes#endif /* !defined(HAVE_EVP_SHA256) && !defined(HAVE_SHA256_UPDATE) && \ 131162852Sdes (OPENSSL_VERSION_NUMBER >= 0x00907000L) */ 132162852Sdes 133162852Sdes#endif /* _SSHSHA2_H */ 134