1 /* Declaration of functions and data types used for MD5 sum computing 2 library functions. 3 Copyright (C) 1995,1996,1997,1999-2001,2004,2005,2008 Red Hat, Inc. 4 This file is part of Red Hat elfutils. 5 Written by Ulrich Drepper <drepper@redhat.com>, 1995. 6 7 Red Hat elfutils is free software; you can redistribute it and/or modify 8 it under the terms of the GNU General Public License as published by the 9 Free Software Foundation; version 2 of the License. 10 11 Red Hat elfutils is distributed in the hope that it will be useful, but 12 WITHOUT ANY WARRANTY; without even the implied warranty of 13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 14 General Public License for more details. 15 16 You should have received a copy of the GNU General Public License along 17 with Red Hat elfutils; if not, write to the Free Software Foundation, 18 Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301 USA. 19 20 Red Hat elfutils is an included package of the Open Invention Network. 21 An included package of the Open Invention Network is a package for which 22 Open Invention Network licensees cross-license their patents. No patent 23 license is granted, either expressly or impliedly, by designation as an 24 included package. Should you wish to participate in the Open Invention 25 Network licensing program, please visit www.openinventionnetwork.com 26 <http://www.openinventionnetwork.com>. */ 27 28 #ifndef _MD5_H 29 #define _MD5_H 1 30 31 #include <limits.h> 32 #include <stdint.h> 33 #include <stdio.h> 34 35 #define MD5_DIGEST_SIZE 16 36 #define MD5_BLOCK_SIZE 64 37 38 typedef uint32_t md5_uint32; 39 typedef uintptr_t md5_uintptr; 40 41 /* Structure to save state of computation between the single steps. */ 42 struct md5_ctx 43 { 44 md5_uint32 A; 45 md5_uint32 B; 46 md5_uint32 C; 47 md5_uint32 D; 48 49 md5_uint32 total[2]; 50 md5_uint32 buflen; 51 char buffer[128] __attribute__ ((__aligned__ (__alignof__ (md5_uint32)))); 52 }; 53 54 /* 55 * The following three functions are build up the low level used in 56 * the functions `md5_stream' and `md5_buffer'. 57 */ 58 59 /* Initialize structure containing state of computation. 60 (RFC 1321, 3.3: Step 3) */ 61 extern void md5_init_ctx (struct md5_ctx *ctx); 62 63 /* Starting with the result of former calls of this function (or the 64 initialization function update the context for the next LEN bytes 65 starting at BUFFER. 66 It is necessary that LEN is a multiple of 64!!! */ 67 extern void md5_process_block (const void *buffer, size_t len, 68 struct md5_ctx *ctx); 69 70 /* Starting with the result of former calls of this function (or the 71 initialization function update the context for the next LEN bytes 72 starting at BUFFER. 73 It is NOT required that LEN is a multiple of 64. */ 74 extern void md5_process_bytes (const void *buffer, size_t len, 75 struct md5_ctx *ctx); 76 77 /* Process the remaining bytes in the buffer and put result from CTX 78 in first 16 bytes following RESBUF. The result is always in little 79 endian byte order, so that a byte-wise output yields to the wanted 80 ASCII representation of the message digest. 81 82 IMPORTANT: On some systems it is required that RESBUF is correctly 83 aligned for a 32 bits value. */ 84 extern void *md5_finish_ctx (struct md5_ctx *ctx, void *resbuf); 85 86 87 /* Put result from CTX in first 16 bytes following RESBUF. The result is 88 always in little endian byte order, so that a byte-wise output yields 89 to the wanted ASCII representation of the message digest. 90 91 IMPORTANT: On some systems it is required that RESBUF is correctly 92 aligned for a 32 bits value. */ 93 extern void *md5_read_ctx (const struct md5_ctx *ctx, void *resbuf); 94 95 96 /* Compute MD5 message digest for bytes read from STREAM. The 97 resulting message digest number will be written into the 16 bytes 98 beginning at RESBLOCK. */ 99 extern int md5_stream (FILE *stream, void *resblock); 100 101 /* Compute MD5 message digest for LEN bytes beginning at BUFFER. The 102 result is always in little endian byte order, so that a byte-wise 103 output yields to the wanted ASCII representation of the message 104 digest. */ 105 extern void *md5_buffer (const char *buffer, size_t len, void *resblock); 106 107 #endif /* md5.h */ 108