md5.h revision 25b3c049e70834cf33790a28643ab058b507b35c
15f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/* Declaration of functions and data types used for MD5 sum computing
25f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer   library functions.
35f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer   Copyright (C) 1995,1996,1997,1999-2001,2004,2005,2008 Red Hat, Inc.
45f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer   This file is part of Red Hat elfutils.
50bc735ffcfb223c0186419547abaa5c84482663eChris Lattner   Written by Ulrich Drepper <drepper@redhat.com>, 1995.
60bc735ffcfb223c0186419547abaa5c84482663eChris Lattner
75f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer   Red Hat elfutils is free software; you can redistribute it and/or modify
85f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer   it under the terms of the GNU General Public License as published by the
95f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer   Free Software Foundation; version 2 of the License.
105f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
115f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer   Red Hat elfutils is distributed in the hope that it will be useful, but
125f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer   WITHOUT ANY WARRANTY; without even the implied warranty of
135f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
145f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer   General Public License for more details.
155f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
165f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer   You should have received a copy of the GNU General Public License along
17207f4d8543529221932af82836016a2ef066c917Peter Collingbourne   with Red Hat elfutils; if not, write to the Free Software Foundation,
182e1cd4264d363ca869bf37ef160902f211d21b8cDouglas Gregor   Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301 USA.
19e7d07d113677a39026ff5119b8b67f6fe8ca9793Ted Kremenek
20ca1bdd7c269a2390d43c040a60511edd017ee130Douglas Gregor   Red Hat elfutils is an included package of the Open Invention Network.
21fe6b2d481d91140923f4541f273b253291884214Douglas Gregor   An included package of the Open Invention Network is a package for which
22ad75653f81dece1c806e9c28dd7e7582c9929a27Ted Kremenek   Open Invention Network licensees cross-license their patents.  No patent
23ab452ba8323d1985e08bade2bced588cddf2cc28Douglas Gregor   license is granted, either expressly or impliedly, by designation as an
24d249e1d1f1498b81314459ceda19d6ff25c278adDouglas Gregor   included package.  Should you wish to participate in the Open Invention
257532dc66648cfe7432c9fe66dec5225f0ab301c6Douglas Gregor   Network licensing program, please visit www.openinventionnetwork.com
26464175bba1318bef7905122e9fda20cff926df78Chris Lattner   <http://www.openinventionnetwork.com>.  */
2750d62d1b4a98adbc83de8f8cd1379ea1c25656f7Douglas Gregor
28046861b912ed72bdc364d7905180ee63e5b08870Anders Carlsson#ifndef _MD5_H
29464175bba1318bef7905122e9fda20cff926df78Chris Lattner#define _MD5_H 1
3068d331a78e655d97294e94fcfa63f92cc1f40578Steve Naroff
314f32786ac45210143654390177105eb749b614e9Ted Kremenek#include <limits.h>
322cf2634ffdb4f7c8d46cef3f8e60a55993f1c57aDouglas Gregor#include <stdint.h>
33432a8893f7e30d141d7f279bd00b741a3cdac81fFariborz Jahanian#include <stdio.h>
346c2b6eb8d836da19007f7540709e16d5e39a1cbaChris Lattner
355f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer#define MD5_DIGEST_SIZE 16
365f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer#define MD5_BLOCK_SIZE 64
37b7cfe88e88cb4f46308de89cf3f0c81bfe624128Chris Lattner
38b7cfe88e88cb4f46308de89cf3f0c81bfe624128Chris Lattnertypedef uint32_t md5_uint32;
39bf9e48cbaaa23d990dbedf9489513500bd0b9751Daniel Dunbartypedef uintptr_t md5_uintptr;
40b7cfe88e88cb4f46308de89cf3f0c81bfe624128Chris Lattner
41b7cfe88e88cb4f46308de89cf3f0c81bfe624128Chris Lattner/* Structure to save state of computation between the single steps.  */
425f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerstruct md5_ctx
43a9376d470ccb0eac74fe09a6b2a18a890f1d17c4Chris Lattner{
44e91593ef084479340582b2ba177b44be50a717b7Daniel Dunbar  md5_uint32 A;
455e530af5d51572a0ed5dbe50da54bd333840c63dDavid Chisnall  md5_uint32 B;
46bdc601b196c48d4cd56a5ceb45d41ae4e87371abKen Dyck  md5_uint32 C;
47aea67dbd653a2dd6dd5cc2159279e81e855b2482Douglas Gregor  md5_uint32 D;
48e91593ef084479340582b2ba177b44be50a717b7Daniel Dunbar
492cf2634ffdb4f7c8d46cef3f8e60a55993f1c57aDouglas Gregor  md5_uint32 total[2];
507b90340c9c7d07aef4e301e72b5e8a30d5f4f0c8Argyrios Kyrtzidis  md5_uint32 buflen;
51c7229c338c21ef26b01ef3ecf9eec4fd373fa9ecChris Lattner  char buffer[128] __attribute__ ((__aligned__ (__alignof__ (md5_uint32))));
52e91593ef084479340582b2ba177b44be50a717b7Daniel Dunbar};
53e91593ef084479340582b2ba177b44be50a717b7Daniel Dunbar
54d934112e6170b0fd940d8e40db6936cea2cdcf62Douglas Gregor/*
55071cc7deffad608165b1ddd5263e8bf181861520Charles Davis * The following three functions are build up the low level used in
56e91593ef084479340582b2ba177b44be50a717b7Daniel Dunbar * the functions `md5_stream' and `md5_buffer'.
573478eb6872d836600caf45b0f81c2065d685d6e0Ted Kremenek */
58f53df2398e07d13be9962b95aebc19b31706fa33Anders Carlsson
59f53df2398e07d13be9962b95aebc19b31706fa33Anders Carlsson/* Initialize structure containing state of computation.
60e91593ef084479340582b2ba177b44be50a717b7Daniel Dunbar   (RFC 1321, 3.3: Step 3)  */
610d8df780aef1acda5962347a32591efc629b6748Anders Carlssonextern void md5_init_ctx (struct md5_ctx *ctx);
6214110477887e3dc168ffc6c191e72d705051f99ePeter Collingbourne
630d8df780aef1acda5962347a32591efc629b6748Anders Carlsson/* Starting with the result of former calls of this function (or the
640d8df780aef1acda5962347a32591efc629b6748Anders Carlsson   initialization function update the context for the next LEN bytes
65c56f34a1c1779de15330bdb3eec39b3418802d47Daniel Dunbar   starting at BUFFER.
66e91593ef084479340582b2ba177b44be50a717b7Daniel Dunbar   It is necessary that LEN is a multiple of 64!!! */
670c01d18094100db92d38daa923c95661512db203John McCallextern void md5_process_block (const void *buffer, size_t len,
68e91593ef084479340582b2ba177b44be50a717b7Daniel Dunbar			       struct md5_ctx *ctx);
693e1274f2b99cb99c03cc8e2c6517c37d330b597aDouglas Gregor
700d8df780aef1acda5962347a32591efc629b6748Anders Carlsson/* Starting with the result of former calls of this function (or the
71e91593ef084479340582b2ba177b44be50a717b7Daniel Dunbar   initialization function update the context for the next LEN bytes
72e91593ef084479340582b2ba177b44be50a717b7Daniel Dunbar   starting at BUFFER.
73e91593ef084479340582b2ba177b44be50a717b7Daniel Dunbar   It is NOT required that LEN is a multiple of 64.  */
740d8df780aef1acda5962347a32591efc629b6748Anders Carlssonextern void md5_process_bytes (const void *buffer, size_t len,
75ed97649e9574b9d854fa4d6109c9333ae0993554John McCall			       struct md5_ctx *ctx);
76eec51cf1ba5f0e62c9cdb81b5c63babdd6e649abJohn McCall
771eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump/* Process the remaining bytes in the buffer and put result from CTX
781b63e4f732dbc73d90abf886b4d21f8e3a165f6dChris Lattner   in first 16 bytes following RESBUF.  The result is always in little
791eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump   endian byte order, so that a byte-wise output yields to the wanted
805f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer   ASCII representation of the message digest.
815f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
824f32786ac45210143654390177105eb749b614e9Ted Kremenek   IMPORTANT: On some systems it is required that RESBUF is correctly
83ef99001908e799c388f1363b1e607dad5f5b57d3John McCall   aligned for a 32 bits value.  */
84ef99001908e799c388f1363b1e607dad5f5b57d3John McCallextern void *md5_finish_ctx (struct md5_ctx *ctx, void *resbuf);
854ba2a17694148e16eaa8d3917f657ffcd3667be4Jay Foad
864ba2a17694148e16eaa8d3917f657ffcd3667be4Jay Foad
874ba2a17694148e16eaa8d3917f657ffcd3667be4Jay Foad/* Put result from CTX in first 16 bytes following RESBUF.  The result is
884ba2a17694148e16eaa8d3917f657ffcd3667be4Jay Foad   always in little endian byte order, so that a byte-wise output yields
894ba2a17694148e16eaa8d3917f657ffcd3667be4Jay Foad   to the wanted ASCII representation of the message digest.
904ba2a17694148e16eaa8d3917f657ffcd3667be4Jay Foad
914ba2a17694148e16eaa8d3917f657ffcd3667be4Jay Foad   IMPORTANT: On some systems it is required that RESBUF is correctly
924ba2a17694148e16eaa8d3917f657ffcd3667be4Jay Foad   aligned for a 32 bits value.  */
934ba2a17694148e16eaa8d3917f657ffcd3667be4Jay Foadextern void *md5_read_ctx (const struct md5_ctx *ctx, void *resbuf);
944ba2a17694148e16eaa8d3917f657ffcd3667be4Jay Foad
954ba2a17694148e16eaa8d3917f657ffcd3667be4Jay Foad
964ba2a17694148e16eaa8d3917f657ffcd3667be4Jay Foad/* Compute MD5 message digest for bytes read from STREAM.  The
974ba2a17694148e16eaa8d3917f657ffcd3667be4Jay Foad   resulting message digest number will be written into the 16 bytes
984ba2a17694148e16eaa8d3917f657ffcd3667be4Jay Foad   beginning at RESBLOCK.  */
994ba2a17694148e16eaa8d3917f657ffcd3667be4Jay Foadextern int md5_stream (FILE *stream, void *resblock);
1004ba2a17694148e16eaa8d3917f657ffcd3667be4Jay Foad
1018026f6d82f7fa544bc0453714fe94bca62a1196eSebastian Redl/* Compute MD5 message digest for LEN bytes beginning at BUFFER.  The
1028026f6d82f7fa544bc0453714fe94bca62a1196eSebastian Redl   result is always in little endian byte order, so that a byte-wise
1034ba2a17694148e16eaa8d3917f657ffcd3667be4Jay Foad   output yields to the wanted ASCII representation of the message
1044ba2a17694148e16eaa8d3917f657ffcd3667be4Jay Foad   digest.  */
1054ba2a17694148e16eaa8d3917f657ffcd3667be4Jay Foadextern void *md5_buffer (const char *buffer, size_t len, void *resblock);
1064ba2a17694148e16eaa8d3917f657ffcd3667be4Jay Foad
1074ba2a17694148e16eaa8d3917f657ffcd3667be4Jay Foad#endif /* md5.h */
108c3069d618f4661d923cb1b5c4525b082fce73b04Douglas Gregor