Move md5 from ddsi to ddsrt

Signed-off-by: Jeroen Koekkoek <jeroen@koekkoek.nl>
This commit is contained in:
Jeroen Koekkoek 2019-04-10 14:23:33 +02:00 committed by eboasson
parent 63a5c87baf
commit 3bdd2a140d
17 changed files with 84 additions and 81 deletions

View file

@ -11,11 +11,12 @@
*/ */
#include <assert.h> #include <assert.h>
#include <string.h> #include <string.h>
#include "dds/ddsrt/md5.h"
#include "dds__key.h" #include "dds__key.h"
#include "dds__stream.h" #include "dds__stream.h"
#include "dds/ddsi/ddsi_serdata.h" #include "dds/ddsi/ddsi_serdata.h"
#include "dds/ddsi/q_bswap.h" #include "dds/ddsi/q_bswap.h"
#include "dds/ddsi/q_md5.h"
#ifndef NDEBUG #ifndef NDEBUG
static bool keyhash_is_reset(const dds_key_hash_t *kh) static bool keyhash_is_reset(const dds_key_hash_t *kh)
@ -112,14 +113,14 @@ void dds_key_gen (const dds_topic_descriptor_t * const desc, dds_key_hash_t * kh
else else
{ {
dds_stream_t os; dds_stream_t os;
md5_state_t md5st; ddsrt_md5_state_t md5st;
kh->m_iskey = 0; kh->m_iskey = 0;
dds_stream_init(&os, 64); dds_stream_init(&os, 64);
os.m_endian = 0; os.m_endian = 0;
dds_key_gen_stream (desc, &os, sample); dds_key_gen_stream (desc, &os, sample);
md5_init (&md5st); ddsrt_md5_init (&md5st);
md5_append (&md5st, os.m_buffer.p8, os.m_index); ddsrt_md5_append (&md5st, os.m_buffer.p8, os.m_index);
md5_finish (&md5st, (unsigned char *) kh->m_hash); ddsrt_md5_finish (&md5st, (unsigned char *) kh->m_hash);
dds_stream_fini (&os); dds_stream_fini (&os);
} }
} }

View file

@ -15,7 +15,7 @@
#include <string.h> #include <string.h>
#include "dds/ddsrt/heap.h" #include "dds/ddsrt/heap.h"
#include "dds/ddsi/q_md5.h" #include "dds/ddsrt/md5.h"
#include "dds/ddsi/q_bswap.h" #include "dds/ddsi/q_bswap.h"
#include "dds/ddsi/q_config.h" #include "dds/ddsi/q_config.h"
#include "dds/ddsi/q_freelist.h" #include "dds/ddsi/q_freelist.h"

View file

@ -16,7 +16,7 @@
#include "dds/dds.h" #include "dds/dds.h"
#include "dds/ddsrt/heap.h" #include "dds/ddsrt/heap.h"
#include "dds/ddsi/q_md5.h" #include "dds/ddsrt/md5.h"
#include "dds/ddsi/q_bswap.h" #include "dds/ddsi/q_bswap.h"
#include "dds/ddsi/q_config.h" #include "dds/ddsi/q_config.h"
#include "dds/ddsi/q_freelist.h" #include "dds/ddsi/q_freelist.h"

View file

@ -11,19 +11,19 @@
*/ */
#include <assert.h> #include <assert.h>
#include <string.h> #include <string.h>
#include "dds/ddsrt/endian.h"
#include "dds/ddsrt/md5.h"
#include "dds/ddsi/q_bswap.h" #include "dds/ddsi/q_bswap.h"
#include "dds/ddsi/q_config.h" #include "dds/ddsi/q_config.h"
#include "dds__stream.h" #include "dds__stream.h"
#include "dds__key.h" #include "dds__key.h"
#include "dds__alloc.h" #include "dds__alloc.h"
#include "dds/ddsi/q_md5.h"
#include "dds/ddsrt/endian.h"
//#define OP_DEBUG_READ 1 //#define OP_DEBUG_READ 1
//#define OP_DEBUG_WRITE 1 //#define OP_DEBUG_WRITE 1
//#define OP_DEBUG_KEY 1 //#define OP_DEBUG_KEY 1
#if defined OP_DEBUG_WRITE || defined OP_DEBUG_READ || defined OP_DEBUG_KEY #if defined OP_DEBUG_WRITE || defined OP_DEBUG_READ || defined OP_DEBUG_KEY
static const char * stream_op_type[11] = static const char * stream_op_type[11] =
{ {
@ -1612,14 +1612,14 @@ void dds_stream_read_keyhash
else else
{ {
dds_stream_t os; dds_stream_t os;
md5_state_t md5st; ddsrt_md5_state_t md5st;
kh->m_iskey = 0; kh->m_iskey = 0;
dds_stream_init (&os, 0); dds_stream_init (&os, 0);
os.m_endian = 0; os.m_endian = 0;
dds_stream_extract_key (is, &os, desc->m_ops, just_key); dds_stream_extract_key (is, &os, desc->m_ops, just_key);
md5_init (&md5st); ddsrt_md5_init (&md5st);
md5_append (&md5st, os.m_buffer.p8, os.m_index); ddsrt_md5_append (&md5st, os.m_buffer.p8, os.m_index);
md5_finish (&md5st, (unsigned char *) kh->m_hash); ddsrt_md5_finish (&md5st, (unsigned char *) kh->m_hash);
dds_stream_fini (&os); dds_stream_fini (&os);
} }
} }

View file

@ -39,7 +39,6 @@ PREPEND(srcs_ddsi "${CMAKE_CURRENT_LIST_DIR}/src"
q_init.c q_init.c
q_lat_estim.c q_lat_estim.c
q_lease.c q_lease.c
q_md5.c
q_misc.c q_misc.c
q_nwif.c q_nwif.c
q_pcap.c q_pcap.c
@ -97,7 +96,6 @@ PREPEND(hdrs_private_ddsi "${CMAKE_CURRENT_LIST_DIR}/include/dds/ddsi"
q_lat_estim.h q_lat_estim.h
q_lease.h q_lease.h
q_log.h q_log.h
q_md5.h
q_misc.h q_misc.h
q_nwif.h q_nwif.h
q_pcap.h q_pcap.h

View file

@ -14,7 +14,7 @@
#include <assert.h> #include <assert.h>
#include <string.h> #include <string.h>
#include "dds/ddsi/q_md5.h" #include "dds/ddsrt/md5.h"
#include "dds/ddsi/q_bswap.h" #include "dds/ddsi/q_bswap.h"
#include "dds/ddsi/q_config.h" #include "dds/ddsi/q_config.h"
#include "dds/ddsi/q_freelist.h" #include "dds/ddsi/q_freelist.h"

View file

@ -16,7 +16,7 @@
#include "dds/ddsrt/heap.h" #include "dds/ddsrt/heap.h"
#include "dds/ddsrt/log.h" #include "dds/ddsrt/log.h"
#include "dds/ddsi/q_md5.h" #include "dds/ddsrt/md5.h"
#include "dds/ddsi/q_bswap.h" #include "dds/ddsi/q_bswap.h"
#include "dds/ddsi/q_config.h" #include "dds/ddsi/q_config.h"
#include "dds/ddsi/q_freelist.h" #include "dds/ddsi/q_freelist.h"
@ -377,16 +377,16 @@ static struct ddsi_serdata *serdata_default_from_sample_plist (const struct ddsi
const char *topic_name = (const char *) (rawkey + sizeof(uint32_t)); const char *topic_name = (const char *) (rawkey + sizeof(uint32_t));
uint32_t topic_name_sz; uint32_t topic_name_sz;
uint32_t topic_name_sz_BE; uint32_t topic_name_sz_BE;
md5_state_t md5st; ddsrt_md5_state_t md5st;
md5_byte_t digest[16]; ddsrt_md5_byte_t digest[16];
topic_name_sz = (uint32_t) strlen (topic_name) + 1; topic_name_sz = (uint32_t) strlen (topic_name) + 1;
topic_name_sz_BE = toBE4u (topic_name_sz); topic_name_sz_BE = toBE4u (topic_name_sz);
d->keyhash.m_set = 1; d->keyhash.m_set = 1;
d->keyhash.m_iskey = 0; d->keyhash.m_iskey = 0;
md5_init (&md5st); ddsrt_md5_init (&md5st);
md5_append (&md5st, (const md5_byte_t *) &topic_name_sz_BE, sizeof (topic_name_sz_BE)); ddsrt_md5_append (&md5st, (const ddsrt_md5_byte_t *) &topic_name_sz_BE, sizeof (topic_name_sz_BE));
md5_append (&md5st, (const md5_byte_t *) topic_name, topic_name_sz); ddsrt_md5_append (&md5st, (const ddsrt_md5_byte_t *) topic_name, topic_name_sz);
md5_finish (&md5st, digest); ddsrt_md5_finish (&md5st, digest);
memcpy (d->keyhash.m_hash, digest, 16); memcpy (d->keyhash.m_hash, digest, 16);
#ifndef NDEBUG #ifndef NDEBUG
keysize = sizeof (uint32_t) + topic_name_sz; keysize = sizeof (uint32_t) + topic_name_sz;

View file

@ -15,13 +15,12 @@
#include <string.h> #include <string.h>
#include "dds/ddsrt/heap.h" #include "dds/ddsrt/heap.h"
#include "dds/ddsi/q_md5.h" #include "dds/ddsrt/md5.h"
#include "dds/ddsi/q_bswap.h" #include "dds/ddsi/q_bswap.h"
#include "dds/ddsi/q_config.h" #include "dds/ddsi/q_config.h"
#include "dds/ddsi/q_freelist.h" #include "dds/ddsi/q_freelist.h"
#include "dds/ddsi/ddsi_sertopic.h" #include "dds/ddsi/ddsi_sertopic.h"
#include "dds/ddsi/ddsi_serdata.h" #include "dds/ddsi/ddsi_serdata.h"
#include "dds/ddsi/q_md5.h"
struct ddsi_sertopic *ddsi_sertopic_ref (const struct ddsi_sertopic *sertopic_const) struct ddsi_sertopic *ddsi_sertopic_ref (const struct ddsi_sertopic *sertopic_const)
{ {
@ -48,13 +47,13 @@ void ddsi_sertopic_unref (struct ddsi_sertopic *sertopic)
uint32_t ddsi_sertopic_compute_serdata_basehash (const struct ddsi_serdata_ops *ops) uint32_t ddsi_sertopic_compute_serdata_basehash (const struct ddsi_serdata_ops *ops)
{ {
md5_state_t md5st; ddsrt_md5_state_t md5st;
md5_byte_t digest[16]; ddsrt_md5_byte_t digest[16];
uint32_t res; uint32_t res;
md5_init (&md5st); ddsrt_md5_init (&md5st);
md5_append (&md5st, (const md5_byte_t *) &ops, sizeof (ops)); ddsrt_md5_append (&md5st, (const ddsrt_md5_byte_t *) &ops, sizeof (ops));
md5_append (&md5st, (const md5_byte_t *) ops, sizeof (*ops)); ddsrt_md5_append (&md5st, (const ddsrt_md5_byte_t *) ops, sizeof (*ops));
md5_finish (&md5st, digest); ddsrt_md5_finish (&md5st, digest);
memcpy (&res, digest, sizeof (res)); memcpy (&res, digest, sizeof (res));
return res; return res;
} }

View file

@ -14,7 +14,7 @@
#include <assert.h> #include <assert.h>
#include <string.h> #include <string.h>
#include "dds/ddsi/q_md5.h" #include "dds/ddsrt/md5.h"
#include "dds/ddsi/q_bswap.h" #include "dds/ddsi/q_bswap.h"
#include "dds/ddsi/q_config.h" #include "dds/ddsi/q_config.h"
#include "dds/ddsi/q_freelist.h" #include "dds/ddsi/q_freelist.h"

View file

@ -18,6 +18,7 @@
#include "dds/version.h" #include "dds/version.h"
#include "dds/ddsrt/heap.h" #include "dds/ddsrt/heap.h"
#include "dds/ddsrt/log.h" #include "dds/ddsrt/log.h"
#include "dds/ddsrt/md5.h"
#include "dds/ddsrt/sync.h" #include "dds/ddsrt/sync.h"
#include "dds/util/ut_avl.h" #include "dds/util/ut_avl.h"
#include "dds/ddsi/q_protocol.h" #include "dds/ddsi/q_protocol.h"
@ -30,6 +31,7 @@
#include "dds/ddsi/q_xevent.h" #include "dds/ddsi/q_xevent.h"
#include "dds/ddsi/q_addrset.h" #include "dds/ddsi/q_addrset.h"
#include "dds/ddsi/q_ddsi_discovery.h" #include "dds/ddsi/q_ddsi_discovery.h"
#include "dds/ddsi/q_radmin.h" #include "dds/ddsi/q_radmin.h"
#include "dds/ddsi/q_ephash.h" #include "dds/ddsi/q_ephash.h"
#include "dds/ddsi/q_entity.h" #include "dds/ddsi/q_entity.h"
@ -40,7 +42,6 @@
#include "dds/ddsi/q_lease.h" #include "dds/ddsi/q_lease.h"
#include "dds/ddsi/q_error.h" #include "dds/ddsi/q_error.h"
#include "dds/ddsi/ddsi_serdata_default.h" #include "dds/ddsi/ddsi_serdata_default.h"
#include "dds/ddsi/q_md5.h"
#include "dds/ddsi/q_feature_check.h" #include "dds/ddsi/q_feature_check.h"
static int get_locator (nn_locator_t *loc, const nn_locators_t *locs, int uc_same_subnet) static int get_locator (nn_locator_t *loc, const nn_locators_t *locs, int uc_same_subnet)

View file

@ -13,6 +13,7 @@
#include <stddef.h> #include <stddef.h>
#include "dds/ddsrt/heap.h" #include "dds/ddsrt/heap.h"
#include "dds/ddsrt/md5.h"
#include "dds/ddsrt/process.h" #include "dds/ddsrt/process.h"
#include "dds/ddsrt/time.h" #include "dds/ddsrt/time.h"
#include "dds/ddsrt/string.h" #include "dds/ddsrt/string.h"
@ -21,7 +22,6 @@
#include "dds/util/ut_avl.h" #include "dds/util/ut_avl.h"
#include "dds/util/ut_thread_pool.h" #include "dds/util/ut_thread_pool.h"
#include "dds/ddsi/q_md5.h"
#include "dds/ddsi/q_protocol.h" #include "dds/ddsi/q_protocol.h"
#include "dds/ddsi/q_rtps.h" #include "dds/ddsi/q_rtps.h"
#include "dds/ddsi/q_misc.h" #include "dds/ddsi/q_misc.h"

View file

@ -12,8 +12,9 @@
#include <string.h> #include <string.h>
#include "dds/ddsi/q_misc.h" #include "dds/ddsi/q_misc.h"
#include "dds/ddsrt/md5.h"
#include "dds/ddsi/q_bswap.h" #include "dds/ddsi/q_bswap.h"
#include "dds/ddsi/q_md5.h"
extern inline seqno_t fromSN (const nn_sequence_number_t sn); extern inline seqno_t fromSN (const nn_sequence_number_t sn);
extern inline nn_sequence_number_t toSN (seqno_t n); extern inline nn_sequence_number_t toSN (seqno_t n);

View file

@ -17,15 +17,16 @@
#include "dds/ddsrt/ifaddrs.h" #include "dds/ddsrt/ifaddrs.h"
#include "dds/ddsrt/heap.h" #include "dds/ddsrt/heap.h"
#include "dds/ddsrt/md5.h"
#include "dds/ddsrt/string.h" #include "dds/ddsrt/string.h"
#include "dds/ddsrt/sockets.h" #include "dds/ddsrt/sockets.h"
#include "dds/ddsi/q_log.h" #include "dds/ddsi/q_log.h"
#include "dds/ddsi/q_nwif.h" #include "dds/ddsi/q_nwif.h"
#include "dds/ddsi/q_globals.h" #include "dds/ddsi/q_globals.h"
#include "dds/ddsi/q_config.h" #include "dds/ddsi/q_config.h"
#include "dds/ddsi/q_unused.h" #include "dds/ddsi/q_unused.h"
#include "dds/ddsi/q_md5.h"
#include "dds/ddsi/q_misc.h" #include "dds/ddsi/q_misc.h"
#include "dds/ddsi/q_addrset.h" /* unspec locator */ #include "dds/ddsi/q_addrset.h" /* unspec locator */
#include "dds/ddsi/q_feature_check.h" #include "dds/ddsi/q_feature_check.h"
@ -45,11 +46,11 @@ unsigned locator_to_hopefully_unique_uint32 (const nn_locator_t *src)
else else
{ {
#if DDSRT_HAVE_IPV6 #if DDSRT_HAVE_IPV6
md5_state_t st; ddsrt_md5_state_t st;
md5_byte_t digest[16]; ddsrt_md5_byte_t digest[16];
md5_init (&st); ddsrt_md5_init (&st);
md5_append (&st, (const md5_byte_t *) ((const struct sockaddr_in6 *) src)->sin6_addr.s6_addr, 16); ddsrt_md5_append (&st, (const ddsrt_md5_byte_t *) ((const struct sockaddr_in6 *) src)->sin6_addr.s6_addr, 16);
md5_finish (&st, digest); ddsrt_md5_finish (&st, digest);
memcpy (&id, digest, sizeof (id)); memcpy (&id, digest, sizeof (id));
#else #else
DDS_FATAL("IPv6 unavailable\n"); DDS_FATAL("IPv6 unavailable\n");

View file

@ -15,11 +15,11 @@
#include <stddef.h> #include <stddef.h>
#include "dds/ddsrt/heap.h" #include "dds/ddsrt/heap.h"
#include "dds/ddsrt/log.h"
#include "dds/ddsrt/md5.h"
#include "dds/ddsrt/sync.h" #include "dds/ddsrt/sync.h"
#include "dds/ddsrt/string.h" #include "dds/ddsrt/string.h"
#include "dds/ddsrt/log.h"
#include "dds/ddsi/q_md5.h"
#include "dds/util/ut_avl.h" #include "dds/util/ut_avl.h"
#include "dds__stream.h" #include "dds__stream.h"
#include "dds/ddsi/q_protocol.h" #include "dds/ddsi/q_protocol.h"
@ -44,6 +44,7 @@
#include "dds/ddsi/q_entity.h" #include "dds/ddsi/q_entity.h"
#include "dds/ddsi/q_xmsg.h" #include "dds/ddsi/q_xmsg.h"
#include "dds/ddsi/q_receive.h" #include "dds/ddsi/q_receive.h"
#include "dds/ddsi/q_transmit.h" #include "dds/ddsi/q_transmit.h"
#include "dds/ddsi/q_globals.h" #include "dds/ddsi/q_globals.h"
#include "dds/ddsi/q_static_assert.h" #include "dds/ddsi/q_static_assert.h"

View file

@ -89,7 +89,7 @@ list(APPEND sources
# network stack. In order to mix-and-match various compilers, architectures, # network stack. In order to mix-and-match various compilers, architectures,
# operating systems, etc input from the build system is required. # operating systems, etc input from the build system is required.
foreach(feature atomics cdtors environ heap ifaddrs random rusage foreach(feature atomics cdtors environ heap ifaddrs random rusage
sockets string sync threads time) sockets string sync threads time md5)
if(EXISTS "${include_path}/dds/ddsrt/${feature}.h") if(EXISTS "${include_path}/dds/ddsrt/${feature}.h")
list(APPEND headers "${include_path}/dds/ddsrt/${feature}.h") list(APPEND headers "${include_path}/dds/ddsrt/${feature}.h")
file(GLOB file(GLOB

View file

@ -59,8 +59,8 @@
1999-05-03 lpd Original version. 1999-05-03 lpd Original version.
*/ */
#ifndef md5_INCLUDED #ifndef DDSRT_MD5_H
# define md5_INCLUDED #define DDSRT_MD5_H
#include <stddef.h> #include <stddef.h>
@ -74,15 +74,15 @@
* efficiently on either one than if ARCH_IS_BIG_ENDIAN is defined. * efficiently on either one than if ARCH_IS_BIG_ENDIAN is defined.
*/ */
typedef unsigned char md5_byte_t; /* 8-bit byte */ typedef unsigned char ddsrt_md5_byte_t; /* 8-bit byte */
typedef unsigned int md5_word_t; /* 32-bit word */ typedef unsigned int ddsrt_md5_word_t; /* 32-bit word */
/* Define the state of the MD5 Algorithm. */ /* Define the state of the MD5 Algorithm. */
typedef struct md5_state_s { typedef struct ddsrt_md5_state_s {
md5_word_t count[2]; /* message length in bits, lsw first */ ddsrt_md5_word_t count[2]; /* message length in bits, lsw first */
md5_word_t abcd[4]; /* digest buffer */ ddsrt_md5_word_t abcd[4]; /* digest buffer */
md5_byte_t buf[64]; /* accumulate block */ ddsrt_md5_byte_t buf[64]; /* accumulate block */
} md5_state_t; } ddsrt_md5_state_t;
#ifdef __cplusplus #ifdef __cplusplus
extern "C" extern "C"
@ -90,16 +90,16 @@ extern "C"
#endif #endif
/* Initialize the algorithm. */ /* Initialize the algorithm. */
void md5_init(md5_state_t *pms); void ddsrt_md5_init(ddsrt_md5_state_t *pms);
/* Append a string to the message. */ /* Append a string to the message. */
void md5_append(md5_state_t *pms, const md5_byte_t *data, unsigned nbytes); void ddsrt_md5_append(ddsrt_md5_state_t *pms, const ddsrt_md5_byte_t *data, unsigned nbytes);
/* Finish the message and return the digest. */ /* Finish the message and return the digest. */
void md5_finish(md5_state_t *pms, md5_byte_t digest[16]); void ddsrt_md5_finish(ddsrt_md5_state_t *pms, ddsrt_md5_byte_t digest[16]);
#ifdef __cplusplus #ifdef __cplusplus
} /* end extern "C" */ } /* end extern "C" */
#endif #endif
#endif /* md5_INCLUDED */ #endif /* DDSRT_MD5_H */

View file

@ -63,9 +63,10 @@
1999-05-03 lpd Original version. 1999-05-03 lpd Original version.
*/ */
#include "dds/ddsi/q_md5.h"
#include <string.h> #include <string.h>
#include "dds/ddsrt/endian.h" /* big or little endianness */ #include "dds/ddsrt/endian.h" /* big or little endianness */
#include "dds/ddsrt/md5.h"
/* Byte order stuff hacked to use OSPL's macros */ /* Byte order stuff hacked to use OSPL's macros */
#undef BYTE_ORDER /* 1 = big-endian, -1 = little-endian, 0 = unknown */ #undef BYTE_ORDER /* 1 = big-endian, -1 = little-endian, 0 = unknown */
@ -77,7 +78,7 @@
# error "DDSRT_ENDIAN not defined" # error "DDSRT_ENDIAN not defined"
#endif #endif
#define T_MASK ((md5_word_t)~0) #define T_MASK ((ddsrt_md5_word_t)~0)
#define T1 /* 0xd76aa478 */ (T_MASK ^ 0x28955b87) #define T1 /* 0xd76aa478 */ (T_MASK ^ 0x28955b87)
#define T2 /* 0xe8c7b756 */ (T_MASK ^ 0x173848a9) #define T2 /* 0xe8c7b756 */ (T_MASK ^ 0x173848a9)
#define T3 0x242070db #define T3 0x242070db
@ -145,19 +146,19 @@
static void static void
md5_process(md5_state_t *pms, const md5_byte_t *data /*[64]*/) md5_process(ddsrt_md5_state_t *pms, const ddsrt_md5_byte_t *data /*[64]*/)
{ {
md5_word_t ddsrt_md5_word_t
a = pms->abcd[0], b = pms->abcd[1], a = pms->abcd[0], b = pms->abcd[1],
c = pms->abcd[2], d = pms->abcd[3]; c = pms->abcd[2], d = pms->abcd[3];
md5_word_t t; ddsrt_md5_word_t t;
#if BYTE_ORDER > 0 #if BYTE_ORDER > 0
/* Define storage only for big-endian CPUs. */ /* Define storage only for big-endian CPUs. */
md5_word_t X[16]; ddsrt_md5_word_t X[16];
#else #else
/* Define storage for little-endian or both types of CPUs. */ /* Define storage for little-endian or both types of CPUs. */
md5_word_t xbuf[16]; ddsrt_md5_word_t xbuf[16];
const md5_word_t *X; const ddsrt_md5_word_t *X;
#endif #endif
{ {
@ -169,7 +170,7 @@ md5_process(md5_state_t *pms, const md5_byte_t *data /*[64]*/)
*/ */
static const int w = 1; static const int w = 1;
if (*((const md5_byte_t *)&w)) /* dynamic little-endian */ if (*((const ddsrt_md5_byte_t *)&w)) /* dynamic little-endian */
#endif #endif
#if BYTE_ORDER <= 0 /* little-endian */ #if BYTE_ORDER <= 0 /* little-endian */
{ {
@ -177,9 +178,9 @@ md5_process(md5_state_t *pms, const md5_byte_t *data /*[64]*/)
* On little-endian machines, we can process properly aligned * On little-endian machines, we can process properly aligned
* data without copying it. * data without copying it.
*/ */
if (!((data - (const md5_byte_t *)0) & 3)) { if (!((data - (const ddsrt_md5_byte_t *)0) & 3)) {
/* data are properly aligned */ /* data are properly aligned */
X = (const md5_word_t *)data; X = (const ddsrt_md5_word_t *)data;
} else { } else {
/* not aligned */ /* not aligned */
memcpy(xbuf, data, 64); memcpy(xbuf, data, 64);
@ -196,7 +197,7 @@ md5_process(md5_state_t *pms, const md5_byte_t *data /*[64]*/)
* On big-endian machines, we must arrange the bytes in the * On big-endian machines, we must arrange the bytes in the
* right order. * right order.
*/ */
const md5_byte_t *xp = data; const ddsrt_md5_byte_t *xp = data;
int i; int i;
# if BYTE_ORDER == 0 # if BYTE_ORDER == 0
@ -326,7 +327,7 @@ md5_process(md5_state_t *pms, const md5_byte_t *data /*[64]*/)
} }
void void
md5_init(md5_state_t *pms) ddsrt_md5_init(ddsrt_md5_state_t *pms)
{ {
pms->count[0] = pms->count[1] = 0; pms->count[0] = pms->count[1] = 0;
pms->abcd[0] = 0x67452301; pms->abcd[0] = 0x67452301;
@ -336,12 +337,12 @@ md5_init(md5_state_t *pms)
} }
void void
md5_append(md5_state_t *pms, const md5_byte_t *data, unsigned nbytes) ddsrt_md5_append(ddsrt_md5_state_t *pms, const ddsrt_md5_byte_t *data, unsigned nbytes)
{ {
const md5_byte_t *p = data; const ddsrt_md5_byte_t *p = data;
unsigned left = nbytes; unsigned left = nbytes;
unsigned offset = (pms->count[0] >> 3) & 63; unsigned offset = (pms->count[0] >> 3) & 63;
md5_word_t nbits = (md5_word_t)(nbytes << 3); ddsrt_md5_word_t nbits = (ddsrt_md5_word_t)(nbytes << 3);
if (nbytes == 0) if (nbytes == 0)
return; return;
@ -374,24 +375,24 @@ md5_append(md5_state_t *pms, const md5_byte_t *data, unsigned nbytes)
} }
void void
md5_finish(md5_state_t *pms, md5_byte_t digest[16]) ddsrt_md5_finish(ddsrt_md5_state_t *pms, ddsrt_md5_byte_t digest[16])
{ {
static const md5_byte_t pad[64] = { static const ddsrt_md5_byte_t pad[64] = {
0x80, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0x80, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0
}; };
md5_byte_t data[8]; ddsrt_md5_byte_t data[8];
int i; int i;
/* Save the length before padding. */ /* Save the length before padding. */
for (i = 0; i < 8; ++i) for (i = 0; i < 8; ++i)
data[i] = (md5_byte_t)(pms->count[i >> 2] >> ((i & 3) << 3)); data[i] = (ddsrt_md5_byte_t)(pms->count[i >> 2] >> ((i & 3) << 3));
/* Pad to 56 bytes mod 64. */ /* Pad to 56 bytes mod 64. */
md5_append(pms, pad, ((55 - (pms->count[0] >> 3)) & 63) + 1); ddsrt_md5_append(pms, pad, ((55 - (pms->count[0] >> 3)) & 63) + 1);
/* Append the length. */ /* Append the length. */
md5_append(pms, data, 8); ddsrt_md5_append(pms, data, 8);
for (i = 0; i < 16; ++i) for (i = 0; i < 16; ++i)
digest[i] = (md5_byte_t)(pms->abcd[i >> 2] >> ((i & 3) << 3)); digest[i] = (ddsrt_md5_byte_t)(pms->abcd[i >> 2] >> ((i & 3) << 3));
} }