/[dtapublic]/projs/trunk/shared_source/c_datd/esrg_sha512.h
ViewVC logotype

Diff of /projs/trunk/shared_source/c_datd/esrg_sha512.h

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 56 by dashley, Sat Oct 29 01:53:01 2016 UTC revision 71 by dashley, Sat Nov 5 11:07:06 2016 UTC
# Line 1  Line 1 
1  //$Header$  //$Header$
2  //-------------------------------------------------------------------------------------------------  //-------------------------------------------------------------------------------------------------
3  //This file is part of "David T. Ashley's Shared Source Code", a set of shared components  //This file is part of "David T. Ashley's Shared Source Code", a set of shared components
4  //integrated into many of David T. Ashley's projects.  //integrated into many of David T. Ashley's projects.
5  //-------------------------------------------------------------------------------------------------  //-------------------------------------------------------------------------------------------------
6  //This source code and any program in which it is compiled/used is provided under the MIT License,  //This source code and any program in which it is compiled/used is provided under the MIT License,
7  //reproduced below.  //reproduced below.
8  //-------------------------------------------------------------------------------------------------  //-------------------------------------------------------------------------------------------------
9  //Permission is hereby granted, free of charge, to any person obtaining a copy of  //Permission is hereby granted, free of charge, to any person obtaining a copy of
10  //this software and associated documentation files(the "Software"), to deal in the  //this software and associated documentation files(the "Software"), to deal in the
11  //Software without restriction, including without limitation the rights to use,  //Software without restriction, including without limitation the rights to use,
12  //copy, modify, merge, publish, distribute, sublicense, and / or sell copies of the  //copy, modify, merge, publish, distribute, sublicense, and / or sell copies of the
13  //Software, and to permit persons to whom the Software is furnished to do so,  //Software, and to permit persons to whom the Software is furnished to do so,
14  //subject to the following conditions :  //subject to the following conditions :
15  //  //
16  //The above copyright notice and this permission notice shall be included in all  //The above copyright notice and this permission notice shall be included in all
17  //copies or substantial portions of the Software.  //copies or substantial portions of the Software.
18  //  //
19  //THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR  //THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
20  //IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,  //IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
21  //FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.IN NO EVENT SHALL THE  //FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.IN NO EVENT SHALL THE
22  //AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER  //AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
23  //LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,  //LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
24  //OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE  //OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
25  //SOFTWARE.  //SOFTWARE.
26  //-------------------------------------------------------------------------------------------------  //-------------------------------------------------------------------------------------------------
27  #ifndef ESRG_SHA512_H_INCLUDED  #ifndef ESRG_SHA512_H_INCLUDED
28     #define ESRG_SHA512_H_INCLUDED     #define ESRG_SHA512_H_INCLUDED
29    
30     #ifdef MODULE_ESRG_SHA512     #ifdef MODULE_ESRG_SHA512
31        #define DECMOD_ESRG_SHA512        #define DECMOD_ESRG_SHA512
32     #else     #else
33        #define DECMOD_ESRG_SHA512 extern        #define DECMOD_ESRG_SHA512 extern
34     #endif     #endif
35    
36     //Fundamental state for forming     //Fundamental state for forming
37     //SHA-512s.  Conceptually private to this module.     //SHA-512s.  Conceptually private to this module.
38     struct ESRG_SHA512_Sha512StateStruct     struct ESRG_SHA512_Sha512StateStruct
39        {        {
40        unsigned __int64 H0, H1, H2, H3, H4, H5, H6, H7;        unsigned __int64 H0, H1, H2, H3, H4, H5, H6, H7;
41           //Directly from FIPS 180-3.  In retrospect, this might have           //Directly from FIPS 180-3.  In retrospect, this might have
42               //been better implemented as an array.               //been better implemented as an array.
43        unsigned __int64 bit_count;        unsigned __int64 bit_count;
44           //The count of bits processed thus far.  The algorithm here           //The count of bits processed thus far.  The algorithm here
45           //works in bytes, not bits, so this is advanced by 8 on           //works in bytes, not bits, so this is advanced by 8 on
46           //each byte processed.  FIPS 180-3 calls for processing           //each byte processed.  FIPS 180-3 calls for processing
47               //messages up to length 2^128, but for obvious reasons               //messages up to length 2^128, but for obvious reasons
48               //we don't do that.  2^64-1 bits is in excess of 2^61-1               //we don't do that.  2^64-1 bits is in excess of 2^61-1
49               //bytes, or somewhere around 2,000 terabytes.  This               //bytes, or somewhere around 2,000 terabytes.  This
50               //isn't a practical limit with current computer technology.               //isn't a practical limit with current computer technology.
51        unsigned __int64 M[16];        unsigned __int64 M[16];
52           //These are the words corresponding to the chars (below).  We don't           //These are the words corresponding to the chars (below).  We don't
53           //dare union to extract them because of big-endian/little-endian concerns.           //dare union to extract them because of big-endian/little-endian concerns.
54               //The "M" nomenclature is from FIPS 180-3.  At the time the               //The "M" nomenclature is from FIPS 180-3.  At the time the
55               //SHA-512 rounds are done, the chars (below) are converted to words               //SHA-512 rounds are done, the chars (below) are converted to words
56               //(this field) so that the rounds can be done using the words.               //(this field) so that the rounds can be done using the words.
57        unsigned char buf[128];        unsigned char buf[128];
58           //We can't proceed to execute a round unless we have the           //We can't proceed to execute a round unless we have the
59           //full 1024 bits = 16 words = 128 bytes of data.  We must           //full 1024 bits = 16 words = 128 bytes of data.  We must
60           //buffer it because we can't count on being called with data           //buffer it because we can't count on being called with data
61           //blocks that are a multiple of 128.  We may have data hanging           //blocks that are a multiple of 128.  We may have data hanging
62           //around between calls.  We fill up this buffer from the low           //around between calls.  We fill up this buffer from the low
63           //end, i.e. [0], then [1], then [2], etc.           //end, i.e. [0], then [1], then [2], etc.
64        };        };
65    
66    
67     //Result structure, used to hold result.  Caller is allowed to     //Result structure, used to hold result.  Caller is allowed to
68     //pick it apart.     //pick it apart.
69     struct ESRG_SHA512_Sha512ResultStruct     struct ESRG_SHA512_Sha512ResultStruct
70        {        {
71        unsigned __int64 sha512_words[8];        unsigned __int64 sha512_words[8];
72               //Hash in binary form, as the 64-bit integers.               //Hash in binary form, as the 64-bit integers.
73        char             sha512_chars[129];        char             sha512_chars[129];
74           //Zero terminated string containing MD5 formed.           //Zero terminated string containing MD5 formed.
75        };        };
76    
77    
78     //Initializes the SHA512 calculation structure.     //Initializes the SHA512 calculation structure.
79     DECMOD_ESRG_SHA512     DECMOD_ESRG_SHA512
80     void ESRG_SHA512_Sha512StateStructOpen(struct ESRG_SHA512_Sha512StateStruct *arg);     void ESRG_SHA512_Sha512StateStructOpen(struct ESRG_SHA512_Sha512StateStruct *arg);
81    
82     //Adds data to it.  Zero length is OK.     //Adds data to it.  Zero length is OK.
83     DECMOD_ESRG_SHA512     DECMOD_ESRG_SHA512
84     void ESRG_SHA512_Sha512StateStructAddData(struct ESRG_SHA512_Sha512StateStruct *arg,     void ESRG_SHA512_Sha512StateStructAddData(struct ESRG_SHA512_Sha512StateStruct *arg,
85                                                                   void *data,                                                                   void *data,
86                                                                   unsigned len);                                                                   unsigned len);
87    
88     //Closes the structure and returns the SHA512.  This is destructive--one cannot     //Closes the structure and returns the SHA512.  This is destructive--one cannot
89     //continue adding characters.  All characters returned are lower-case.     //continue adding characters.  All characters returned are lower-case.
90     DECMOD_ESRG_SHA512     DECMOD_ESRG_SHA512
91     void ESRG_SHA512_Sha512StateStructClose(struct ESRG_SHA512_Sha512StateStruct  *state,     void ESRG_SHA512_Sha512StateStructClose(struct ESRG_SHA512_Sha512StateStruct  *state,
92                                             struct ESRG_SHA512_Sha512ResultStruct *result);                                             struct ESRG_SHA512_Sha512ResultStruct *result);
93    
94     //Returns version control information.     //Returns version control information.
95     DECMOD_ESRG_SHA512 const char *ESRG_SHA512_cvcinfo(void);     DECMOD_ESRG_SHA512 const char *ESRG_SHA512_cvcinfo(void);
96     DECMOD_ESRG_SHA512 const char *ESRG_SHA512_hvcinfo(void);     DECMOD_ESRG_SHA512 const char *ESRG_SHA512_hvcinfo(void);
97    
98     //Definition of the version of the H file, used for providing version control     //Definition of the version of the H file, used for providing version control
99     //information to external callers.     //information to external callers.
100     #define ESRG_SHA512_H_VERSION ("$Header$")     #define ESRG_SHA512_H_VERSION ("$Header$")
101    
102  #endif  #endif
103    
104  //End of esrg_sha512.h.  //End of esrg_sha512.h.

Legend:
Removed from v.56  
changed lines
  Added in v.71

dashley@gmail.com
ViewVC Help
Powered by ViewVC 1.1.25