sha2.h

Go to the documentation of this file.
00001 /*
00002  * FILE:        sha2.h
00003  * AUTHOR:      Aaron D. Gifford - http://www.aarongifford.com/
00004  * 
00005  * Copyright (c) 2000-2001, Aaron D. Gifford
00006  * All rights reserved.
00007  *
00008  * Modified by Jelte Jansen to fit in ldns, and not clash with any
00009  * system-defined SHA code.
00010  * Changes:
00011  *  - Renamed (external) functions and constants to fit ldns style
00012  *  - Removed uintXX vs. u_intXX smartness, since ldns needs uintXX
00013  *    anyway
00014  *  - BYTE ORDER check replaced by simple ifdef as defined or not by
00015  *    configure.ac
00016  *  - Removed _End and _Data functions
00017  *  - Added ldns_shaX(data, len, digest) functions
00018  * 
00019  * Redistribution and use in source and binary forms, with or without
00020  * modification, are permitted provided that the following conditions
00021  * are met:
00022  * 1. Redistributions of source code must retain the above copyright
00023  *    notice, this list of conditions and the following disclaimer.
00024  * 2. Redistributions in binary form must reproduce the above copyright
00025  *    notice, this list of conditions and the following disclaimer in the
00026  *    documentation and/or other materials provided with the distribution.
00027  * 3. Neither the name of the copyright holder nor the names of contributors
00028  *    may be used to endorse or promote products derived from this software
00029  *    without specific prior written permission.
00030  * 
00031  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTOR(S) ``AS IS'' AND
00032  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
00033  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
00034  * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTOR(S) BE LIABLE
00035  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
00036  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
00037  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
00038  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
00039  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
00040  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
00041  * SUCH DAMAGE.
00042  *
00043  * $Id: sha2.h,v 1.1 2001/11/08 00:02:01 adg Exp adg $
00044  */
00045 
00046 #ifndef __LDNS_SHA2_H__
00047 #define __LDNS_SHA2_H__
00048 
00049 #ifdef __cplusplus
00050 extern "C" {
00051 #endif
00052 
00053 
00054 /*
00055  * Import u_intXX_t size_t type definitions from system headers.  You
00056  * may need to change this, or define these things yourself in this
00057  * file.
00058  */
00059 #include <sys/types.h>
00060 
00061 #if LDNS_BUILD_CONFIG_HAVE_INTTYPES_H
00062 
00063 #include <inttypes.h>
00064 
00065 #endif /* LDNS_BUILD_CONFIG_HAVE_INTTYPES_H */
00066 
00067 
00068 /*** SHA-256/384/512 Various Length Definitions ***********************/
00069 #define LDNS_SHA256_BLOCK_LENGTH                64
00070 #define LDNS_SHA256_DIGEST_LENGTH               32
00071 #define LDNS_SHA256_DIGEST_STRING_LENGTH        (LDNS_SHA256_DIGEST_LENGTH * 2 + 1)
00072 #define LDNS_SHA384_BLOCK_LENGTH                128
00073 #define LDNS_SHA384_DIGEST_LENGTH               48
00074 #define LDNS_SHA384_DIGEST_STRING_LENGTH        (LDNS_SHA384_DIGEST_LENGTH * 2 + 1)
00075 #define LDNS_SHA512_BLOCK_LENGTH                128
00076 #define LDNS_SHA512_DIGEST_LENGTH               64
00077 #define LDNS_SHA512_DIGEST_STRING_LENGTH        (LDNS_SHA512_DIGEST_LENGTH * 2 + 1)
00078 
00079 
00080 /*** SHA-256/384/512 Context Structures *******************************/
00081 
00082 typedef struct _ldns_sha256_CTX {
00083         uint32_t        state[8];
00084         uint64_t        bitcount;
00085         uint8_t buffer[LDNS_SHA256_BLOCK_LENGTH];
00086 } ldns_sha256_CTX;
00087 typedef struct _ldns_sha512_CTX {
00088         uint64_t        state[8];
00089         uint64_t        bitcount[2];
00090         uint8_t buffer[LDNS_SHA512_BLOCK_LENGTH];
00091 } ldns_sha512_CTX;
00092 
00093 typedef ldns_sha512_CTX ldns_sha384_CTX;
00094 
00095 
00096 /*** SHA-256/384/512 Function Prototypes ******************************/
00097 void ldns_sha256_init(ldns_sha256_CTX *);
00098 void ldns_sha256_update(ldns_sha256_CTX*, const uint8_t*, size_t);
00099 void ldns_sha256_final(uint8_t[LDNS_SHA256_DIGEST_LENGTH], ldns_sha256_CTX*);
00100 
00101 void ldns_sha384_init(ldns_sha384_CTX*);
00102 void ldns_sha384_update(ldns_sha384_CTX*, const uint8_t*, size_t);
00103 void ldns_sha384_final(uint8_t[LDNS_SHA384_DIGEST_LENGTH], ldns_sha384_CTX*);
00104 
00105 void ldns_sha512_init(ldns_sha512_CTX*);
00106 void ldns_sha512_update(ldns_sha512_CTX*, const uint8_t*, size_t);
00107 void ldns_sha512_final(uint8_t[LDNS_SHA512_DIGEST_LENGTH], ldns_sha512_CTX*);
00108 
00119 unsigned char *ldns_sha256(unsigned char *data, unsigned int data_len, unsigned char *digest);
00120 
00131 unsigned char *ldns_sha384(unsigned char *data, unsigned int data_len, unsigned char *digest);
00132 
00143 unsigned char *ldns_sha512(unsigned char *data, unsigned int data_len, unsigned char *digest);
00144 
00145 #ifdef  __cplusplus
00146 }
00147 #endif /* __cplusplus */
00148 
00149 #endif /* __LDNS_SHA2_H__ */

Generated on Wed Dec 19 16:56:56 2012 for ldns by  doxygen 1.4.7