Drizzled Public API Documentation

CSSha1.h
00001 /* Copyright (C) 2008 PrimeBase Technologies GmbH, Germany
00002  *
00003  * PrimeBase S3Daemon
00004  *
00005  * This program is free software; you can redistribute it and/or modify
00006  * it under the terms of the GNU General Public License as published by
00007  * the Free Software Foundation; either version 2 of the License, or
00008  * (at your option) any later version.
00009  *
00010  * This program is distributed in the hope that it will be useful,
00011  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00012  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00013  * GNU General Public License for more details.
00014  *
00015  * You should have received a copy of the GNU General Public License
00016  * along with this program; if not, write to the Free Software
00017  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
00018  *
00019  *  Modified by Barry Leslie on 10/21/08.
00020  *  I have put a C++ wrapper around the data and functions to create an sha1 class.
00021  *
00022  */
00023 /*
00024   Original Source from: http://www.faqs.org/rfcs/rfc3174.html
00025   and MySQL mysys/sha1.c build 5.1.24.
00026 
00027  DESCRIPTION
00028    This file implements the Secure Hashing Algorithm 1 as
00029    defined in FIPS PUB 180-1 published April 17, 1995.
00030 
00031    The SHA-1, produces a 160-bit message digest for a given data
00032    stream.  It should take about 2**n steps to find a message with the
00033    same digest as a given message and 2**(n/2) to find any two
00034    messages with the same digest, when n is the digest size in bits.
00035    Therefore, this algorithm can serve as a means of providing a
00036    "fingerprint" for a message.
00037 
00038  PORTABILITY ISSUES
00039    SHA-1 is defined in terms of 32-bit "words".  This code uses
00040    <stdint.h> (included via "sha1.h" to define 32 and 8 bit unsigned
00041    integer types.  If your C compiler does not support 32 bit unsigned
00042    integers, this code is not appropriate.
00043 
00044  CAVEATS
00045    SHA-1 is designed to work with messages less than 2^64 bits long.
00046    Although SHA-1 allows a message digest to be generated for messages
00047    of any number of bits less than 2^64, this implementation only
00048    works with messages with a length that is a multiple of the size of
00049    an 8-bit character.
00050 
00051 */
00052 
00053 #pragma once
00054 #ifndef __CSSHA1_H__
00055 #define __CSSHA1_H__
00056 #include <string.h>
00057 
00058 #define SHA1_HASH_SIZE 20
00059 
00060 typedef struct {
00061   uint8_t val[SHA1_HASH_SIZE];
00062 } Sha1Digest;
00063 
00064 class CSSha1 : public CSObject {
00065   private:
00066   
00067   uint64_t  Length;               // Message length in bits   
00068   uint32_t Intermediate_Hash[SHA1_HASH_SIZE/4]; // Message Digest  
00069   bool Computed;                  // Is the digest computed?
00070   int16_t Message_Block_Index;          // Index into message block array  
00071   uint8_t Message_Block[64];            // 512-bit message blocks      
00072 
00073   void sha1_pad();
00074   void sha1_process();
00075 
00076   public:
00077   CSSha1() {sha1_reset();}
00078   
00079   void sha1_reset();
00080   void sha1_input(const void *data, size_t len);
00081   void sha1_digest(Sha1Digest *digest);
00082   
00083 };
00084 
00085 #endif // __CSSHA1_H__
00086