loudmouth/md5.h
author Mikael Berthe <mikael@lilotux.net>
Mon, 13 Jun 2022 18:01:27 +0200
changeset 745 7785b42dd7bc
parent 607 e2bd14357c9a
permissions -rw-r--r--
Merge pull request #46 from nekopsykose/fix-asyncns-addrinfo fix macro define for freeaddrinfo with asyncns committer: GitHub <noreply@github.com>
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 217
diff changeset
     1
/* -*- mode: c; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
217
16d512c3ce31 Added base64.[ch] and md5.[ch] from Senko
Mikael Hallendal <micke@imendio.com>
parents:
diff changeset
     2
/*
16d512c3ce31 Added base64.[ch] and md5.[ch] from Senko
Mikael Hallendal <micke@imendio.com>
parents:
diff changeset
     3
  Copyright (C) 1999, 2002 Aladdin Enterprises.  All rights reserved.
16d512c3ce31 Added base64.[ch] and md5.[ch] from Senko
Mikael Hallendal <micke@imendio.com>
parents:
diff changeset
     4
16d512c3ce31 Added base64.[ch] and md5.[ch] from Senko
Mikael Hallendal <micke@imendio.com>
parents:
diff changeset
     5
  This software is provided 'as-is', without any express or implied
16d512c3ce31 Added base64.[ch] and md5.[ch] from Senko
Mikael Hallendal <micke@imendio.com>
parents:
diff changeset
     6
  warranty.  In no event will the authors be held liable for any damages
16d512c3ce31 Added base64.[ch] and md5.[ch] from Senko
Mikael Hallendal <micke@imendio.com>
parents:
diff changeset
     7
  arising from the use of this software.
16d512c3ce31 Added base64.[ch] and md5.[ch] from Senko
Mikael Hallendal <micke@imendio.com>
parents:
diff changeset
     8
16d512c3ce31 Added base64.[ch] and md5.[ch] from Senko
Mikael Hallendal <micke@imendio.com>
parents:
diff changeset
     9
  Permission is granted to anyone to use this software for any purpose,
16d512c3ce31 Added base64.[ch] and md5.[ch] from Senko
Mikael Hallendal <micke@imendio.com>
parents:
diff changeset
    10
  including commercial applications, and to alter it and redistribute it
16d512c3ce31 Added base64.[ch] and md5.[ch] from Senko
Mikael Hallendal <micke@imendio.com>
parents:
diff changeset
    11
  freely, subject to the following restrictions:
16d512c3ce31 Added base64.[ch] and md5.[ch] from Senko
Mikael Hallendal <micke@imendio.com>
parents:
diff changeset
    12
16d512c3ce31 Added base64.[ch] and md5.[ch] from Senko
Mikael Hallendal <micke@imendio.com>
parents:
diff changeset
    13
  1. The origin of this software must not be misrepresented; you must not
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 217
diff changeset
    14
  claim that you wrote the original software. If you use this software
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 217
diff changeset
    15
  in a product, an acknowledgment in the product documentation would be
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 217
diff changeset
    16
  appreciated but is not required.
217
16d512c3ce31 Added base64.[ch] and md5.[ch] from Senko
Mikael Hallendal <micke@imendio.com>
parents:
diff changeset
    17
  2. Altered source versions must be plainly marked as such, and must not be
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 217
diff changeset
    18
  misrepresented as being the original software.
217
16d512c3ce31 Added base64.[ch] and md5.[ch] from Senko
Mikael Hallendal <micke@imendio.com>
parents:
diff changeset
    19
  3. This notice may not be removed or altered from any source distribution.
16d512c3ce31 Added base64.[ch] and md5.[ch] from Senko
Mikael Hallendal <micke@imendio.com>
parents:
diff changeset
    20
16d512c3ce31 Added base64.[ch] and md5.[ch] from Senko
Mikael Hallendal <micke@imendio.com>
parents:
diff changeset
    21
  L. Peter Deutsch
16d512c3ce31 Added base64.[ch] and md5.[ch] from Senko
Mikael Hallendal <micke@imendio.com>
parents:
diff changeset
    22
  ghost@aladdin.com
16d512c3ce31 Added base64.[ch] and md5.[ch] from Senko
Mikael Hallendal <micke@imendio.com>
parents:
diff changeset
    23
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 217
diff changeset
    24
*/
217
16d512c3ce31 Added base64.[ch] and md5.[ch] from Senko
Mikael Hallendal <micke@imendio.com>
parents:
diff changeset
    25
/* $Id: md5.h,v 1.4 2002/04/13 19:20:28 lpd Exp $ */
16d512c3ce31 Added base64.[ch] and md5.[ch] from Senko
Mikael Hallendal <micke@imendio.com>
parents:
diff changeset
    26
/*
16d512c3ce31 Added base64.[ch] and md5.[ch] from Senko
Mikael Hallendal <micke@imendio.com>
parents:
diff changeset
    27
  Independent implementation of MD5 (RFC 1321).
16d512c3ce31 Added base64.[ch] and md5.[ch] from Senko
Mikael Hallendal <micke@imendio.com>
parents:
diff changeset
    28
16d512c3ce31 Added base64.[ch] and md5.[ch] from Senko
Mikael Hallendal <micke@imendio.com>
parents:
diff changeset
    29
  This code implements the MD5 Algorithm defined in RFC 1321, whose
16d512c3ce31 Added base64.[ch] and md5.[ch] from Senko
Mikael Hallendal <micke@imendio.com>
parents:
diff changeset
    30
  text is available at
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 217
diff changeset
    31
  http://www.ietf.org/rfc/rfc1321.txt
217
16d512c3ce31 Added base64.[ch] and md5.[ch] from Senko
Mikael Hallendal <micke@imendio.com>
parents:
diff changeset
    32
  The code is derived from the text of the RFC, including the test suite
16d512c3ce31 Added base64.[ch] and md5.[ch] from Senko
Mikael Hallendal <micke@imendio.com>
parents:
diff changeset
    33
  (section A.5) but excluding the rest of Appendix A.  It does not include
16d512c3ce31 Added base64.[ch] and md5.[ch] from Senko
Mikael Hallendal <micke@imendio.com>
parents:
diff changeset
    34
  any code or documentation that is identified in the RFC as being
16d512c3ce31 Added base64.[ch] and md5.[ch] from Senko
Mikael Hallendal <micke@imendio.com>
parents:
diff changeset
    35
  copyrighted.
16d512c3ce31 Added base64.[ch] and md5.[ch] from Senko
Mikael Hallendal <micke@imendio.com>
parents:
diff changeset
    36
16d512c3ce31 Added base64.[ch] and md5.[ch] from Senko
Mikael Hallendal <micke@imendio.com>
parents:
diff changeset
    37
  The original and principal author of md5.h is L. Peter Deutsch
16d512c3ce31 Added base64.[ch] and md5.[ch] from Senko
Mikael Hallendal <micke@imendio.com>
parents:
diff changeset
    38
  <ghost@aladdin.com>.  Other authors are noted in the change history
16d512c3ce31 Added base64.[ch] and md5.[ch] from Senko
Mikael Hallendal <micke@imendio.com>
parents:
diff changeset
    39
  that follows (in reverse chronological order):
16d512c3ce31 Added base64.[ch] and md5.[ch] from Senko
Mikael Hallendal <micke@imendio.com>
parents:
diff changeset
    40
16d512c3ce31 Added base64.[ch] and md5.[ch] from Senko
Mikael Hallendal <micke@imendio.com>
parents:
diff changeset
    41
  2002-04-13 lpd Removed support for non-ANSI compilers; removed
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 217
diff changeset
    42
  references to Ghostscript; clarified derivation from RFC 1321;
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 217
diff changeset
    43
  now handles byte order either statically or dynamically.
217
16d512c3ce31 Added base64.[ch] and md5.[ch] from Senko
Mikael Hallendal <micke@imendio.com>
parents:
diff changeset
    44
  1999-11-04 lpd Edited comments slightly for automatic TOC extraction.
16d512c3ce31 Added base64.[ch] and md5.[ch] from Senko
Mikael Hallendal <micke@imendio.com>
parents:
diff changeset
    45
  1999-10-18 lpd Fixed typo in header comment (ansi2knr rather than md5);
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 217
diff changeset
    46
  added conditionalization for C++ compilation from Martin
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 217
diff changeset
    47
  Purschke <purschke@bnl.gov>.
217
16d512c3ce31 Added base64.[ch] and md5.[ch] from Senko
Mikael Hallendal <micke@imendio.com>
parents:
diff changeset
    48
  1999-05-03 lpd Original version.
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 217
diff changeset
    49
*/
217
16d512c3ce31 Added base64.[ch] and md5.[ch] from Senko
Mikael Hallendal <micke@imendio.com>
parents:
diff changeset
    50
16d512c3ce31 Added base64.[ch] and md5.[ch] from Senko
Mikael Hallendal <micke@imendio.com>
parents:
diff changeset
    51
#ifndef md5_INCLUDED
16d512c3ce31 Added base64.[ch] and md5.[ch] from Senko
Mikael Hallendal <micke@imendio.com>
parents:
diff changeset
    52
#  define md5_INCLUDED
16d512c3ce31 Added base64.[ch] and md5.[ch] from Senko
Mikael Hallendal <micke@imendio.com>
parents:
diff changeset
    53
16d512c3ce31 Added base64.[ch] and md5.[ch] from Senko
Mikael Hallendal <micke@imendio.com>
parents:
diff changeset
    54
/*
16d512c3ce31 Added base64.[ch] and md5.[ch] from Senko
Mikael Hallendal <micke@imendio.com>
parents:
diff changeset
    55
 * This package supports both compile-time and run-time determination of CPU
16d512c3ce31 Added base64.[ch] and md5.[ch] from Senko
Mikael Hallendal <micke@imendio.com>
parents:
diff changeset
    56
 * byte order.  If ARCH_IS_BIG_ENDIAN is defined as 0, the code will be
16d512c3ce31 Added base64.[ch] and md5.[ch] from Senko
Mikael Hallendal <micke@imendio.com>
parents:
diff changeset
    57
 * compiled to run only on little-endian CPUs; if ARCH_IS_BIG_ENDIAN is
16d512c3ce31 Added base64.[ch] and md5.[ch] from Senko
Mikael Hallendal <micke@imendio.com>
parents:
diff changeset
    58
 * defined as non-zero, the code will be compiled to run only on big-endian
16d512c3ce31 Added base64.[ch] and md5.[ch] from Senko
Mikael Hallendal <micke@imendio.com>
parents:
diff changeset
    59
 * CPUs; if ARCH_IS_BIG_ENDIAN is not defined, the code will be compiled to
16d512c3ce31 Added base64.[ch] and md5.[ch] from Senko
Mikael Hallendal <micke@imendio.com>
parents:
diff changeset
    60
 * run on either big- or little-endian CPUs, but will run slightly less
16d512c3ce31 Added base64.[ch] and md5.[ch] from Senko
Mikael Hallendal <micke@imendio.com>
parents:
diff changeset
    61
 * efficiently on either one than if ARCH_IS_BIG_ENDIAN is defined.
16d512c3ce31 Added base64.[ch] and md5.[ch] from Senko
Mikael Hallendal <micke@imendio.com>
parents:
diff changeset
    62
 */
16d512c3ce31 Added base64.[ch] and md5.[ch] from Senko
Mikael Hallendal <micke@imendio.com>
parents:
diff changeset
    63
16d512c3ce31 Added base64.[ch] and md5.[ch] from Senko
Mikael Hallendal <micke@imendio.com>
parents:
diff changeset
    64
typedef unsigned char md5_byte_t; /* 8-bit byte */
16d512c3ce31 Added base64.[ch] and md5.[ch] from Senko
Mikael Hallendal <micke@imendio.com>
parents:
diff changeset
    65
typedef unsigned int md5_word_t; /* 32-bit word */
16d512c3ce31 Added base64.[ch] and md5.[ch] from Senko
Mikael Hallendal <micke@imendio.com>
parents:
diff changeset
    66
16d512c3ce31 Added base64.[ch] and md5.[ch] from Senko
Mikael Hallendal <micke@imendio.com>
parents:
diff changeset
    67
/* Define the state of the MD5 Algorithm. */
16d512c3ce31 Added base64.[ch] and md5.[ch] from Senko
Mikael Hallendal <micke@imendio.com>
parents:
diff changeset
    68
typedef struct md5_state_s {
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 217
diff changeset
    69
    md5_word_t count[2];    /* message length in bits, lsw first */
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 217
diff changeset
    70
    md5_word_t abcd[4];     /* digest buffer */
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 217
diff changeset
    71
    md5_byte_t buf[64];     /* accumulate block */
217
16d512c3ce31 Added base64.[ch] and md5.[ch] from Senko
Mikael Hallendal <micke@imendio.com>
parents:
diff changeset
    72
} md5_state_t;
16d512c3ce31 Added base64.[ch] and md5.[ch] from Senko
Mikael Hallendal <micke@imendio.com>
parents:
diff changeset
    73
16d512c3ce31 Added base64.[ch] and md5.[ch] from Senko
Mikael Hallendal <micke@imendio.com>
parents:
diff changeset
    74
#ifdef __cplusplus
607
e2bd14357c9a Some style fixes
Frank Zschockelt <lm@freakysoft.de>
parents: 518
diff changeset
    75
extern "C"
217
16d512c3ce31 Added base64.[ch] and md5.[ch] from Senko
Mikael Hallendal <micke@imendio.com>
parents:
diff changeset
    76
{
16d512c3ce31 Added base64.[ch] and md5.[ch] from Senko
Mikael Hallendal <micke@imendio.com>
parents:
diff changeset
    77
#endif
16d512c3ce31 Added base64.[ch] and md5.[ch] from Senko
Mikael Hallendal <micke@imendio.com>
parents:
diff changeset
    78
16d512c3ce31 Added base64.[ch] and md5.[ch] from Senko
Mikael Hallendal <micke@imendio.com>
parents:
diff changeset
    79
/* Initialize the algorithm. */
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 217
diff changeset
    80
    void md5_init(md5_state_t *pms);
217
16d512c3ce31 Added base64.[ch] and md5.[ch] from Senko
Mikael Hallendal <micke@imendio.com>
parents:
diff changeset
    81
16d512c3ce31 Added base64.[ch] and md5.[ch] from Senko
Mikael Hallendal <micke@imendio.com>
parents:
diff changeset
    82
/* Append a string to the message. */
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 217
diff changeset
    83
    void md5_append(md5_state_t *pms, const md5_byte_t *data, int nbytes);
217
16d512c3ce31 Added base64.[ch] and md5.[ch] from Senko
Mikael Hallendal <micke@imendio.com>
parents:
diff changeset
    84
16d512c3ce31 Added base64.[ch] and md5.[ch] from Senko
Mikael Hallendal <micke@imendio.com>
parents:
diff changeset
    85
/* Finish the message and return the digest. */
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 217
diff changeset
    86
    void md5_finish(md5_state_t *pms, md5_byte_t digest[16]);
217
16d512c3ce31 Added base64.[ch] and md5.[ch] from Senko
Mikael Hallendal <micke@imendio.com>
parents:
diff changeset
    87
16d512c3ce31 Added base64.[ch] and md5.[ch] from Senko
Mikael Hallendal <micke@imendio.com>
parents:
diff changeset
    88
#ifdef __cplusplus
16d512c3ce31 Added base64.[ch] and md5.[ch] from Senko
Mikael Hallendal <micke@imendio.com>
parents:
diff changeset
    89
}  /* end extern "C" */
16d512c3ce31 Added base64.[ch] and md5.[ch] from Senko
Mikael Hallendal <micke@imendio.com>
parents:
diff changeset
    90
#endif
16d512c3ce31 Added base64.[ch] and md5.[ch] from Senko
Mikael Hallendal <micke@imendio.com>
parents:
diff changeset
    91
16d512c3ce31 Added base64.[ch] and md5.[ch] from Senko
Mikael Hallendal <micke@imendio.com>
parents:
diff changeset
    92
#endif /* md5_INCLUDED */