libalpm
Arch Linux Package Manager Library
sha2.h
Go to the documentation of this file.
00001 /*
00002  *  SHA-224 and SHA-256 cryptographic hash function
00003  *
00004  *  Copyright (C) 2006-2010, Brainspark B.V.
00005  *
00006  *  This file is part of PolarSSL (http://www.polarssl.org)
00007  *  Lead Maintainer: Paul Bakker <polarssl_maintainer at polarssl.org>
00008  *
00009  *  All rights reserved.
00010  *
00011  *  This program is free software; you can redistribute it and/or modify
00012  *  it under the terms of the GNU General Public License as published by
00013  *  the Free Software Foundation; either version 2 of the License, or
00014  *  (at your option) any later version.
00015  *
00016  *  This program is distributed in the hope that it will be useful,
00017  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
00018  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00019  *  GNU General Public License for more details.
00020  *
00021  *  You should have received a copy of the GNU General Public License
00022  *  along with this program.  If not, see <http://www.gnu.org/licenses/>.
00023  */
00024 #ifndef _SHA2_H
00025 #define _SHA2_H
00026 
00027 #include <string.h>
00028 
00029 /**
00030  * \brief          SHA-256 context structure
00031  */
00032 typedef struct
00033 {
00034     unsigned long total[2];     /*!< number of bytes processed  */
00035     unsigned long state[8];     /*!< intermediate digest state  */
00036     unsigned char buffer[64];   /*!< data block being processed */
00037 
00038     int is224;                  /*!< 0 => SHA-256, else SHA-224 */
00039 }
00040 sha2_context;
00041 
00042 /**
00043  * \brief          Output = SHA-256( input buffer )
00044  *
00045  * \param input    buffer holding the  data
00046  * \param ilen     length of the input data
00047  * \param output   SHA-224/256 checksum result
00048  * \param is224    0 = use SHA256, 1 = use SHA224
00049  */
00050 void sha2( const unsigned char *input, size_t ilen,
00051            unsigned char output[32], int is224 );
00052 
00053 /**
00054  * \brief          Output = SHA-256( file contents )
00055  *
00056  * \param path     input file name
00057  * \param output   SHA-224/256 checksum result
00058  * \param is224    0 = use SHA256, 1 = use SHA224
00059  *
00060  * \return         0 if successful, 1 if fopen failed,
00061  *                 or 2 if fread failed
00062  */
00063 int sha2_file( const char *path, unsigned char output[32], int is224 );
00064 
00065 #endif /* sha2.h */