su_md5.h 2.88 KB
Newer Older
Pekka Pessi's avatar
Pekka Pessi committed
1 2 3 4 5 6 7
/*
 * This file is part of the Sofia-SIP package
 *
 * Copyright (C) 2005 Nokia Corporation.
 *
 * Contact: Pekka Pessi <pekka.pessi@nokia.com>
 *
8
 * This library is free software; you can redistribute it and/or
Pekka Pessi's avatar
Pekka Pessi committed
9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25
 * modify it under the terms of the GNU Lesser General Public License
 * as published by the Free Software Foundation; either version 2.1 of
 * the License, or (at your option) any later version.
 *
 * This library is distributed in the hope that it will be useful, but
 * WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with this library; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
 * 02110-1301 USA
 *
 */

#ifndef SU_MD5_H /**  Defined when su_md5.h has been included. */
Pekka Pessi's avatar
Pekka Pessi committed
26
#define SU_MD5_H
Pekka Pessi's avatar
Pekka Pessi committed
27 28 29 30 31 32 33 34 35 36 37 38 39

/**@defgroup su_md5 MD5 Digest
 *
 * The MD5 message digest algorithm is described in RFC 1321 by R. Rivest,
 * 1992.  The algorithm takes as input a octet string of arbitrary length
 * and generates a 128-bit hash value, "message digest" from the message
 * contents.
 *
 * While some message collisions (different messages with same MD5 digest)
 * has been generated, using collisions in an actual attack is much harder
 * and MD5 can be considered as cryptographically strong.
 */

Pekka Pessi's avatar
Pekka Pessi committed
40
/** @file sofia-sip/su_md5.h MD5 digest interface.
Pekka Pessi's avatar
Pekka Pessi committed
41 42
 *
 * @author <Pekka.Pessi@nokia.com>
43
 */
Pekka Pessi's avatar
Pekka Pessi committed
44 45

#ifndef SU_TYPES_H
46
#include "sofia-sip/su_types.h"
Pekka Pessi's avatar
Pekka Pessi committed
47 48
#endif

49 50
SOFIA_BEGIN_DECLS

Pekka Pessi's avatar
Pekka Pessi committed
51 52 53 54 55 56 57 58 59
/** MD5 context. */
typedef struct su_md5_t {
  uint32_t buf[4];
  uint32_t bits[2];
  uint8_t  in[64];
} su_md5_t;

#define SU_MD5_DIGEST_SIZE 16

60 61 62
SOFIAPUBFUN void su_md5_init(su_md5_t *context);
SOFIAPUBFUN void su_md5_deinit(su_md5_t *context);
SOFIAPUBFUN void su_md5_update(su_md5_t *context,
63
			       void const *buf, usize_t len);
64 65
SOFIAPUBFUN void su_md5_strupdate(su_md5_t *ctx, char const *s);
SOFIAPUBFUN void su_md5_str0update(su_md5_t *ctx, char const *s);
Pekka Pessi's avatar
Pekka Pessi committed
66

67
SOFIAPUBFUN void su_md5_iupdate(su_md5_t *context,
68
				void const *buf, usize_t len);
69 70
SOFIAPUBFUN void su_md5_striupdate(su_md5_t *ctx, char const *s);
SOFIAPUBFUN void su_md5_stri0update(su_md5_t *ctx, char const *s);
Pekka Pessi's avatar
Pekka Pessi committed
71

72 73 74 75
SOFIAPUBFUN void su_md5_digest(su_md5_t const *ctx,
			       uint8_t digest[SU_MD5_DIGEST_SIZE]);
SOFIAPUBFUN void su_md5_hexdigest(su_md5_t const *ctx,
				  char digest[2 * SU_MD5_DIGEST_SIZE + 1]);
Pekka Pessi's avatar
Pekka Pessi committed
76 77 78 79 80 81 82 83 84 85

#define SU_MD5_STRUPDATE(ctx, s) \
 ((s) ? su_md5_update(ctx, (s), strlen(s)) : (void)0)
#define SU_MD5_STR0UPDATE(ctx, s) \
 su_md5_update(ctx, (s) ? (s) : "", (s) ? strlen(s) + 1 : 1)
#define SU_MD5_STRIUPDATE(ctx, s) \
  ((s) ? su_md5_iupdate(ctx, (s), strlen(s)) : (void)0)
#define SU_MD5_STRI0UPDATE(ctx, s) \
  su_md5_iupdate(ctx, (s) ? (s) : "", (s) ? strlen(s) : 1)

86 87
SOFIA_END_DECLS

Pekka Pessi's avatar
Pekka Pessi committed
88
#endif /* !defined(MD5_H) */