sha2.h

Go to the documentation of this file.
00001 /*
00002  * Copyright (C) 2005-2007, 2009, 2014  Internet Systems Consortium, Inc. ("ISC")
00003  *
00004  * Permission to use, copy, modify, and/or distribute this software for any
00005  * purpose with or without fee is hereby granted, provided that the above
00006  * copyright notice and this permission notice appear in all copies.
00007  *
00008  * THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES WITH
00009  * REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
00010  * AND FITNESS.  IN NO EVENT SHALL ISC BE LIABLE FOR ANY SPECIAL, DIRECT,
00011  * INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
00012  * LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE
00013  * OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
00014  * PERFORMANCE OF THIS SOFTWARE.
00015  */
00016 
00017 /* $Id: sha2.h,v 1.12 2009/10/22 02:21:31 each Exp $ */
00018 
00019 /*      $FreeBSD: src/sys/crypto/sha2/sha2.h,v 1.1.2.1 2001/07/03 11:01:36 ume Exp $    */
00020 /*      $KAME: sha2.h,v 1.3 2001/03/12 08:27:48 itojun Exp $    */
00021 
00022 /*
00023  * sha2.h
00024  *
00025  * Version 1.0.0beta1
00026  *
00027  * Written by Aaron D. Gifford <me@aarongifford.com>
00028  *
00029  * Copyright 2000 Aaron D. Gifford.  All rights reserved.
00030  *
00031  * Redistribution and use in source and binary forms, with or without
00032  * modification, are permitted provided that the following conditions
00033  * are met:
00034  * 1. Redistributions of source code must retain the above copyright
00035  *    notice, this list of conditions and the following disclaimer.
00036  * 2. Redistributions in binary form must reproduce the above copyright
00037  *    notice, this list of conditions and the following disclaimer in the
00038  *    documentation and/or other materials provided with the distribution.
00039  * 3. Neither the name of the copyright holder nor the names of contributors
00040  *    may be used to endorse or promote products derived from this software
00041  *    without specific prior written permission.
00042  *
00043  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR(S) AND CONTRIBUTOR(S) ``AS IS'' AND
00044  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
00045  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
00046  * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR(S) OR CONTRIBUTOR(S) BE LIABLE
00047  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
00048  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
00049  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
00050  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
00051  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
00052  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
00053  * SUCH DAMAGE.
00054  *
00055  */
00056 
00057 #ifndef ISC_SHA2_H
00058 #define ISC_SHA2_H
00059 
00060 #include <isc/lang.h>
00061 #include <isc/platform.h>
00062 #include <isc/types.h>
00063 
00064 /*** SHA-224/256/384/512 Various Length Definitions ***********************/
00065 
00066 #define ISC_SHA224_BLOCK_LENGTH         64U
00067 #define ISC_SHA224_DIGESTLENGTH 28U
00068 #define ISC_SHA224_DIGESTSTRINGLENGTH   (ISC_SHA224_DIGESTLENGTH * 2 + 1)
00069 #define ISC_SHA256_BLOCK_LENGTH         64U
00070 #define ISC_SHA256_DIGESTLENGTH 32U
00071 #define ISC_SHA256_DIGESTSTRINGLENGTH   (ISC_SHA256_DIGESTLENGTH * 2 + 1)
00072 #define ISC_SHA384_BLOCK_LENGTH         128
00073 #define ISC_SHA384_DIGESTLENGTH 48U
00074 #define ISC_SHA384_DIGESTSTRINGLENGTH   (ISC_SHA384_DIGESTLENGTH * 2 + 1)
00075 #define ISC_SHA512_BLOCK_LENGTH         128U
00076 #define ISC_SHA512_DIGESTLENGTH 64U
00077 #define ISC_SHA512_DIGESTSTRINGLENGTH   (ISC_SHA512_DIGESTLENGTH * 2 + 1)
00078 
00079 /*** SHA-256/384/512 Context Structures *******************************/
00080 
00081 #ifdef ISC_PLATFORM_OPENSSLHASH
00082 #include <openssl/evp.h>
00083 
00084 typedef EVP_MD_CTX isc_sha256_t;
00085 typedef EVP_MD_CTX isc_sha512_t;
00086 
00087 #elif PKCS11CRYPTO
00088 #include <pk11/pk11.h>
00089 
00090 typedef pk11_context_t isc_sha256_t;
00091 typedef pk11_context_t isc_sha512_t;
00092 
00093 #else
00094 
00095 /*
00096  * Keep buffer immediately after bitcount to preserve alignment.
00097  */
00098 typedef struct {
00099         isc_uint32_t    state[8];
00100         isc_uint64_t    bitcount;
00101         isc_uint8_t     buffer[ISC_SHA256_BLOCK_LENGTH];
00102 } isc_sha256_t;
00103 
00104 /*
00105  * Keep buffer immediately after bitcount to preserve alignment.
00106  */
00107 typedef struct {
00108         isc_uint64_t    state[8];
00109         isc_uint64_t    bitcount[2];
00110         isc_uint8_t     buffer[ISC_SHA512_BLOCK_LENGTH];
00111 } isc_sha512_t;
00112 #endif
00113 
00114 typedef isc_sha256_t isc_sha224_t;
00115 typedef isc_sha512_t isc_sha384_t;
00116 
00117 ISC_LANG_BEGINDECLS
00118 
00119 /*** SHA-224/256/384/512 Function Prototypes ******************************/
00120 
00121 void isc_sha224_init (isc_sha224_t *);
00122 void isc_sha224_invalidate (isc_sha224_t *);
00123 void isc_sha224_update (isc_sha224_t *, const isc_uint8_t *, size_t);
00124 void isc_sha224_final (isc_uint8_t[ISC_SHA224_DIGESTLENGTH], isc_sha224_t *);
00125 char *isc_sha224_end (isc_sha224_t *, char[ISC_SHA224_DIGESTSTRINGLENGTH]);
00126 char *isc_sha224_data (const isc_uint8_t *, size_t, char[ISC_SHA224_DIGESTSTRINGLENGTH]);
00127 
00128 void isc_sha256_init (isc_sha256_t *);
00129 void isc_sha256_invalidate (isc_sha256_t *);
00130 void isc_sha256_update (isc_sha256_t *, const isc_uint8_t *, size_t);
00131 void isc_sha256_final (isc_uint8_t[ISC_SHA256_DIGESTLENGTH], isc_sha256_t *);
00132 char *isc_sha256_end (isc_sha256_t *, char[ISC_SHA256_DIGESTSTRINGLENGTH]);
00133 char *isc_sha256_data (const isc_uint8_t *, size_t, char[ISC_SHA256_DIGESTSTRINGLENGTH]);
00134 
00135 void isc_sha384_init (isc_sha384_t *);
00136 void isc_sha384_invalidate (isc_sha384_t *);
00137 void isc_sha384_update (isc_sha384_t *, const isc_uint8_t *, size_t);
00138 void isc_sha384_final (isc_uint8_t[ISC_SHA384_DIGESTLENGTH], isc_sha384_t *);
00139 char *isc_sha384_end (isc_sha384_t *, char[ISC_SHA384_DIGESTSTRINGLENGTH]);
00140 char *isc_sha384_data (const isc_uint8_t *, size_t, char[ISC_SHA384_DIGESTSTRINGLENGTH]);
00141 
00142 void isc_sha512_init (isc_sha512_t *);
00143 void isc_sha512_invalidate (isc_sha512_t *);
00144 void isc_sha512_update (isc_sha512_t *, const isc_uint8_t *, size_t);
00145 void isc_sha512_final (isc_uint8_t[ISC_SHA512_DIGESTLENGTH], isc_sha512_t *);
00146 char *isc_sha512_end (isc_sha512_t *, char[ISC_SHA512_DIGESTSTRINGLENGTH]);
00147 char *isc_sha512_data (const isc_uint8_t *, size_t, char[ISC_SHA512_DIGESTSTRINGLENGTH]);
00148 
00149 ISC_LANG_ENDDECLS
00150 
00151 #endif /* ISC_SHA2_H */

Generated on Tue Apr 28 17:41:04 2015 by Doxygen 1.5.4 for BIND9 Internals 9.11.0pre-alpha