StRoot  1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
StHyperHashMd5.h
1 /* Declaration of functions and data types used for MD5 sum computing
2  library functions.
3  Copyright (C) 1995-1997,1999,2000,2001,2004,2005,2006,2008
4  Free Software Foundation, Inc.
5  This file is part of the GNU C Library.
6 
7  This program is free software; you can redistribute it and/or modify it
8  under the terms of the GNU General Public License as published by the
9  Free Software Foundation; either version 3, or (at your option) any
10  later version.
11 
12  This program is distributed in the hope that it will be useful,
13  but WITHOUT ANY WARRANTY; without even the implied warranty of
14  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15  GNU General Public License for more details.
16 
17  You should have received a copy of the GNU General Public License
18  along with this program; if not, write to the Free Software Foundation,
19  Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */
20 
21 #ifndef __ST_HYPERHASH_MD5_H
22 #define __ST_HYPERHASH_MD5_H
23 
24 #include <string>
25 #include <cstdio>
26 #include <stdint.h>
27 
28 namespace StHyperHash
29 {
30 
31 #define ST_MD5_DIGEST_SIZE 16
32 #define ST_MD5_BLOCK_SIZE 64
33 
34 #ifndef __GNUC_PREREQ
35 # if defined __GNUC__ && defined __GNUC_MINOR__
36 # define __GNUC_PREREQ(maj, min) \
37  ((__GNUC__ << 16) + __GNUC_MINOR__ >= ((maj) << 16) + (min))
38 # else
39 # define __GNUC_PREREQ(maj, min) 0
40 # endif
41 #endif
42 
43 #ifndef _LIBC
44 # define __st_md5_buffer st_md5_buffer
45 # define __st_md5_finish_ctx st_md5_finish_ctx
46 # define __st_md5_init_ctx st_md5_init_ctx
47 # define __st_md5_process_block st_md5_process_block
48 # define __st_md5_process_bytes st_md5_process_bytes
49 # define __st_md5_read_ctx st_md5_read_ctx
50 # define __st_md5_stream st_md5_stream
51 #endif
52 
53 /* Structure to save state of computation between the single steps. */
54 struct st_md5_ctx {
55  uint32_t A;
56  uint32_t B;
57  uint32_t C;
58  uint32_t D;
59 
60  uint32_t total[2];
61  uint32_t buflen;
62  uint32_t buffer[32];
63 };
64 
65 /*
66  * The following three functions are build up the low level used in
67  * the functions `st_md5_stream' and `st_md5_buffer'.
68  */
69 
70 /* Initialize structure containing state of computation.
71  (RFC 1321, 3.3: Step 3) */
72 extern void __st_md5_init_ctx (struct st_md5_ctx *ctx) ;
73 
74 /* Starting with the result of former calls of this function (or the
75  initialization function update the context for the next LEN bytes
76  starting at BUFFER.
77  It is necessary that LEN is a multiple of 64!!! */
78 extern void __st_md5_process_block (const void *buffer, size_t len,
79  struct st_md5_ctx *ctx) ;
80 
81 /* Starting with the result of former calls of this function (or the
82  initialization function update the context for the next LEN bytes
83  starting at BUFFER.
84  It is NOT required that LEN is a multiple of 64. */
85 extern void __st_md5_process_bytes (const void *buffer, size_t len,
86  struct st_md5_ctx *ctx) ;
87 
88 /* Process the remaining bytes in the buffer and put result from CTX
89  in first 16 bytes following RESBUF. The result is always in little
90  endian byte order, so that a byte-wise output yields to the wanted
91  ASCII representation of the message digest. */
92 extern void *__st_md5_finish_ctx (struct st_md5_ctx *ctx, void *resbuf) ;
93 
94 
95 /* Put result from CTX in first 16 bytes following RESBUF. The result is
96  always in little endian byte order, so that a byte-wise output yields
97  to the wanted ASCII representation of the message digest. */
98 extern void *__st_md5_read_ctx (const struct st_md5_ctx *ctx, void *resbuf) ;
99 
100 
101 /* Compute MD5 message digest for bytes read from STREAM. The
102  resulting message digest number will be written into the 16 bytes
103  beginning at RESBLOCK. */
104 extern int __st_md5_stream (FILE *stream, void *resblock) ;
105 
106 /* Compute MD5 message digest for LEN bytes beginning at BUFFER. The
107  result is always in little endian byte order, so that a byte-wise
108  output yields to the wanted ASCII representation of the message
109  digest. */
110 extern void *__st_md5_buffer (const char *buffer, size_t len,
111  void *resblock) ;
112 
113 std::string md5sum(const std::string& str);
114 
115 } // namespace StHyperHash
116 
117 #endif /* StHyperHashMd5.h */