1*86d7f5d3SJohn Marino /* Declaration of functions and data types used for MD5 sum computing 2*86d7f5d3SJohn Marino library functions. 3*86d7f5d3SJohn Marino Copyright (C) 1995-1997,1999-2005 Free Software Foundation, Inc. 4*86d7f5d3SJohn Marino 5*86d7f5d3SJohn Marino NOTE: The canonical source of this file is maintained with the GNU C 6*86d7f5d3SJohn Marino Library. Bugs can be reported to bug-glibc@prep.ai.mit.edu. 7*86d7f5d3SJohn Marino 8*86d7f5d3SJohn Marino This program is free software; you can redistribute it and/or modify it 9*86d7f5d3SJohn Marino under the terms of the GNU General Public License as published by the 10*86d7f5d3SJohn Marino Free Software Foundation; either version 2, or (at your option) any 11*86d7f5d3SJohn Marino later version. 12*86d7f5d3SJohn Marino 13*86d7f5d3SJohn Marino This program is distributed in the hope that it will be useful, 14*86d7f5d3SJohn Marino but WITHOUT ANY WARRANTY; without even the implied warranty of 15*86d7f5d3SJohn Marino MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16*86d7f5d3SJohn Marino GNU General Public License for more details. 17*86d7f5d3SJohn Marino 18*86d7f5d3SJohn Marino You should have received a copy of the GNU General Public License 19*86d7f5d3SJohn Marino along with this program; if not, write to the Free Software Foundation, 20*86d7f5d3SJohn Marino Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ 21*86d7f5d3SJohn Marino 22*86d7f5d3SJohn Marino #ifndef _MD5_H 23*86d7f5d3SJohn Marino #define _MD5_H 1 24*86d7f5d3SJohn Marino 25*86d7f5d3SJohn Marino #include <stdio.h> 26*86d7f5d3SJohn Marino 27*86d7f5d3SJohn Marino #if HAVE_INTTYPES_H 28*86d7f5d3SJohn Marino # include <inttypes.h> 29*86d7f5d3SJohn Marino #endif 30*86d7f5d3SJohn Marino #if HAVE_STDINT_H || _LIBC 31*86d7f5d3SJohn Marino # include <stdint.h> 32*86d7f5d3SJohn Marino #endif 33*86d7f5d3SJohn Marino 34*86d7f5d3SJohn Marino #ifndef __GNUC_PREREQ 35*86d7f5d3SJohn Marino # if defined __GNUC__ && defined __GNUC_MINOR__ 36*86d7f5d3SJohn Marino # define __GNUC_PREREQ(maj, min) \ 37*86d7f5d3SJohn Marino ((__GNUC__ << 16) + __GNUC_MINOR__ >= ((maj) << 16) + (min)) 38*86d7f5d3SJohn Marino # else 39*86d7f5d3SJohn Marino # define __GNUC_PREREQ(maj, min) 0 40*86d7f5d3SJohn Marino # endif 41*86d7f5d3SJohn Marino #endif 42*86d7f5d3SJohn Marino 43*86d7f5d3SJohn Marino #ifndef __THROW 44*86d7f5d3SJohn Marino # if defined __cplusplus && __GNUC_PREREQ (2,8) 45*86d7f5d3SJohn Marino # define __THROW throw () 46*86d7f5d3SJohn Marino # else 47*86d7f5d3SJohn Marino # define __THROW 48*86d7f5d3SJohn Marino # endif 49*86d7f5d3SJohn Marino #endif 50*86d7f5d3SJohn Marino 51*86d7f5d3SJohn Marino #ifndef __attribute__ 52*86d7f5d3SJohn Marino # if ! __GNUC_PREREQ (2,8) || __STRICT_ANSI__ 53*86d7f5d3SJohn Marino # define __attribute__(x) 54*86d7f5d3SJohn Marino # endif 55*86d7f5d3SJohn Marino #endif 56*86d7f5d3SJohn Marino 57*86d7f5d3SJohn Marino #ifndef _LIBC 58*86d7f5d3SJohn Marino # define __md5_buffer md5_buffer 59*86d7f5d3SJohn Marino # define __md5_finish_ctx md5_finish_ctx 60*86d7f5d3SJohn Marino # define __md5_init_ctx md5_init_ctx 61*86d7f5d3SJohn Marino # define __md5_process_block md5_process_block 62*86d7f5d3SJohn Marino # define __md5_process_bytes md5_process_bytes 63*86d7f5d3SJohn Marino # define __md5_read_ctx md5_read_ctx 64*86d7f5d3SJohn Marino # define __md5_stream md5_stream 65*86d7f5d3SJohn Marino #endif 66*86d7f5d3SJohn Marino 67*86d7f5d3SJohn Marino typedef uint32_t md5_uint32; 68*86d7f5d3SJohn Marino 69*86d7f5d3SJohn Marino /* Structure to save state of computation between the single steps. */ 70*86d7f5d3SJohn Marino struct md5_ctx 71*86d7f5d3SJohn Marino { 72*86d7f5d3SJohn Marino md5_uint32 A; 73*86d7f5d3SJohn Marino md5_uint32 B; 74*86d7f5d3SJohn Marino md5_uint32 C; 75*86d7f5d3SJohn Marino md5_uint32 D; 76*86d7f5d3SJohn Marino 77*86d7f5d3SJohn Marino md5_uint32 total[2]; 78*86d7f5d3SJohn Marino md5_uint32 buflen; 79*86d7f5d3SJohn Marino char buffer[128] __attribute__ ((__aligned__ (__alignof__ (md5_uint32)))); 80*86d7f5d3SJohn Marino }; 81*86d7f5d3SJohn Marino 82*86d7f5d3SJohn Marino /* 83*86d7f5d3SJohn Marino * The following three functions are build up the low level used in 84*86d7f5d3SJohn Marino * the functions `md5_stream' and `md5_buffer'. 85*86d7f5d3SJohn Marino */ 86*86d7f5d3SJohn Marino 87*86d7f5d3SJohn Marino /* Initialize structure containing state of computation. 88*86d7f5d3SJohn Marino (RFC 1321, 3.3: Step 3) */ 89*86d7f5d3SJohn Marino extern void __md5_init_ctx (struct md5_ctx *ctx) __THROW; 90*86d7f5d3SJohn Marino 91*86d7f5d3SJohn Marino /* Starting with the result of former calls of this function (or the 92*86d7f5d3SJohn Marino initialization function update the context for the next LEN bytes 93*86d7f5d3SJohn Marino starting at BUFFER. 94*86d7f5d3SJohn Marino It is necessary that LEN is a multiple of 64!!! */ 95*86d7f5d3SJohn Marino extern void __md5_process_block (const void *buffer, size_t len, 96*86d7f5d3SJohn Marino struct md5_ctx *ctx) __THROW; 97*86d7f5d3SJohn Marino 98*86d7f5d3SJohn Marino /* Starting with the result of former calls of this function (or the 99*86d7f5d3SJohn Marino initialization function update the context for the next LEN bytes 100*86d7f5d3SJohn Marino starting at BUFFER. 101*86d7f5d3SJohn Marino It is NOT required that LEN is a multiple of 64. */ 102*86d7f5d3SJohn Marino extern void __md5_process_bytes (const void *buffer, size_t len, 103*86d7f5d3SJohn Marino struct md5_ctx *ctx) __THROW; 104*86d7f5d3SJohn Marino 105*86d7f5d3SJohn Marino /* Process the remaining bytes in the buffer and put result from CTX 106*86d7f5d3SJohn Marino in first 16 bytes following RESBUF. The result is always in little 107*86d7f5d3SJohn Marino endian byte order, so that a byte-wise output yields to the wanted 108*86d7f5d3SJohn Marino ASCII representation of the message digest. 109*86d7f5d3SJohn Marino 110*86d7f5d3SJohn Marino IMPORTANT: On some systems it is required that RESBUF be correctly 111*86d7f5d3SJohn Marino aligned for a 32 bits value. */ 112*86d7f5d3SJohn Marino extern void *__md5_finish_ctx (struct md5_ctx *ctx, void *resbuf) __THROW; 113*86d7f5d3SJohn Marino 114*86d7f5d3SJohn Marino 115*86d7f5d3SJohn Marino /* Put result from CTX in first 16 bytes following RESBUF. The result is 116*86d7f5d3SJohn Marino always in little endian byte order, so that a byte-wise output yields 117*86d7f5d3SJohn Marino to the wanted ASCII representation of the message digest. 118*86d7f5d3SJohn Marino 119*86d7f5d3SJohn Marino IMPORTANT: On some systems it is required that RESBUF is correctly 120*86d7f5d3SJohn Marino aligned for a 32 bits value. */ 121*86d7f5d3SJohn Marino extern void *__md5_read_ctx (const struct md5_ctx *ctx, void *resbuf) __THROW; 122*86d7f5d3SJohn Marino 123*86d7f5d3SJohn Marino 124*86d7f5d3SJohn Marino /* Compute MD5 message digest for bytes read from STREAM. The 125*86d7f5d3SJohn Marino resulting message digest number will be written into the 16 bytes 126*86d7f5d3SJohn Marino beginning at RESBLOCK. */ 127*86d7f5d3SJohn Marino extern int __md5_stream (FILE *stream, void *resblock) __THROW; 128*86d7f5d3SJohn Marino 129*86d7f5d3SJohn Marino /* Compute MD5 message digest for LEN bytes beginning at BUFFER. The 130*86d7f5d3SJohn Marino result is always in little endian byte order, so that a byte-wise 131*86d7f5d3SJohn Marino output yields to the wanted ASCII representation of the message 132*86d7f5d3SJohn Marino digest. */ 133*86d7f5d3SJohn Marino extern void *__md5_buffer (const char *buffer, size_t len, 134*86d7f5d3SJohn Marino void *resblock) __THROW; 135*86d7f5d3SJohn Marino 136*86d7f5d3SJohn Marino #endif /* md5.h */ 137