Skip to content

Commit

Permalink
Fix build with clang 15: get rid of the 30-year old PROTO_LIST
Browse files Browse the repository at this point in the history
hack to deal with some prehistoric compilers. Switch public
API to use char *, not unsigned char *, which is kinda pointless.
Also make arguments const where appropriate.
  • Loading branch information
sobomax committed Mar 24, 2023
1 parent b6f00e8 commit a07ae74
Show file tree
Hide file tree
Showing 8 changed files with 24 additions and 42 deletions.
28 changes: 13 additions & 15 deletions md5.c
Original file line number Diff line number Diff line change
Expand Up @@ -60,13 +60,11 @@ documentation and/or software.
#define S43 15
#define S44 21

static void MD5Transform PROTO_LIST ((UINT4 [4], unsigned char [64]));
static void Encode PROTO_LIST
((unsigned char *, UINT4 *, unsigned int));
static void Decode PROTO_LIST
((UINT4 *, unsigned char *, unsigned int));
static void MD5_memcpy PROTO_LIST ((POINTER, POINTER, unsigned int));
static void MD5_memset PROTO_LIST ((POINTER, int, unsigned int));
static void MD5Transform(UINT4 [4], const unsigned char [64]);
static void Encode(unsigned char *, UINT4 *, unsigned int);
static void Decode(UINT4 *, const unsigned char *, unsigned int);
static void MD5_memcpy(POINTER, POINTER, unsigned int);
static void MD5_memset(POINTER, int, unsigned int);

static unsigned char PADDING[64] = {
0x80, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
Expand Down Expand Up @@ -130,7 +128,7 @@ void MD5Init (MD5_CTX *context)
unsigned char *input - input block
unsigned int inputLen - length of input block
*/
void MD5Update (MD5_CTX *context, unsigned char *input, unsigned int inputLen)
void MD5Update (MD5_CTX *context, const char *input, unsigned int inputLen)
{
unsigned int i, index, partLen;

Expand All @@ -154,7 +152,7 @@ void MD5Update (MD5_CTX *context, unsigned char *input, unsigned int inputLen)
MD5Transform (context->state, context->buffer);

for (i = partLen; i + 63 < inputLen; i += 64)
MD5Transform (context->state, &input[i]);
MD5Transform (context->state, (const unsigned char *)(&input[i]));

index = 0;
}
Expand All @@ -172,7 +170,7 @@ void MD5Update (MD5_CTX *context, unsigned char *input, unsigned int inputLen)
unsigned char digest[16] - message digest
MD5_CTX *context - context
*/
void MD5Final (unsigned char digest[16], MD5_CTX *context)
void MD5Final (char digest[16], MD5_CTX *context)
{
unsigned char bits[8];
unsigned int index, padLen;
Expand All @@ -184,13 +182,13 @@ void MD5Final (unsigned char digest[16], MD5_CTX *context)
*/
index = (unsigned int)((context->count[0] >> 3) & 0x3f);
padLen = (index < 56) ? (56 - index) : (120 - index);
MD5Update (context, PADDING, padLen);
MD5Update (context, (const char *)PADDING, padLen);

/* Append length (before padding) */
MD5Update (context, bits, 8);
MD5Update (context, (const char *)bits, 8);

/* Store state in digest */
Encode (digest, context->state, 16);
Encode ((unsigned char *)digest, context->state, 16);

/* Zeroize sensitive information.
*/
Expand All @@ -199,7 +197,7 @@ void MD5Final (unsigned char digest[16], MD5_CTX *context)

/* MD5 basic transformation. Transforms state based on block.
*/
static void MD5Transform (UINT4 state[4], unsigned char block[64])
static void MD5Transform (UINT4 state[4], const unsigned char block[64])
{
UINT4 a = state[0], b = state[1], c = state[2], d = state[3], x[16];

Expand Down Expand Up @@ -305,7 +303,7 @@ static void Encode (unsigned char *output, UINT4 *input, unsigned int len)
/* Decodes input (unsigned char) into output (UINT4). Assumes len is
a multiple of 4.
*/
static void Decode (UINT4 *output, unsigned char *input, unsigned int len)
static void Decode (UINT4 *output, const unsigned char *input, unsigned int len)
{
unsigned int i, j;

Expand Down
7 changes: 3 additions & 4 deletions md5.h
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,8 @@ typedef struct {
unsigned char buffer[64]; /* input buffer */
} MD5_CTX;

void MD5Init PROTO_LIST ((MD5_CTX *));
void MD5Update PROTO_LIST
((MD5_CTX *, unsigned char *, unsigned int));
void MD5Final PROTO_LIST ((unsigned char [16], MD5_CTX *));
void MD5Init(MD5_CTX *);
void MD5Update(MD5_CTX *, const char *, unsigned int);
void MD5Final(char [16], MD5_CTX *);

#endif /* MD5_H */
15 changes: 0 additions & 15 deletions md5global.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,6 @@ The following makes PROTOTYPES default to 0 if it has not already
#ifndef MD5GLOBAL_H
#define MD5GLOBAL_H


#ifndef PROTOTYPES
#define PROTOTYPES 0
#endif

/* POINTER defines a generic pointer type */
typedef unsigned char *POINTER;

Expand All @@ -24,14 +19,4 @@ typedef unsigned short int UINT2;
/* UINT4 defines a four byte word */
typedef unsigned int UINT4;

/* PROTO_LIST is defined depending on how PROTOTYPES is defined above.
If using PROTOTYPES, then PROTO_LIST returns the list, otherwise it
returns an empty list.
*/
#if PROTOTYPES
#define PROTO_LIST(list) list
#else
#define PROTO_LIST(list) ()
#endif

#endif /* MD5GLOBAL_H */
6 changes: 3 additions & 3 deletions md5utils.c
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@
void MD5StringArray(char *dest, str src[], unsigned int size)
{
MD5_CTX context;
unsigned char digest[16];
char digest[16];
int i, len;
char *tmp;

Expand Down Expand Up @@ -77,8 +77,8 @@ int MD5File(char *dest, const char *file_name)

MD5_CTX context;
FILE *input;
unsigned char buffer[32768];
unsigned char hash[16];
char buffer[32768];
char hash[16];
unsigned int counter, size;

struct stat stats;
Expand Down
2 changes: 1 addition & 1 deletion modules/proto_smpp/smpp.c
Original file line number Diff line number Diff line change
Expand Up @@ -1547,7 +1547,7 @@ static int recv_smpp_msg(smpp_header_t *header, smpp_deliver_sm_t *body,

if (body->data_coding == SMPP_CODING_UCS2) {
memset(sms_body,0,2*MAX_SMS_CHARACTERS);
body_str.len = string2hex((unsigned char *)body->short_message,
body_str.len = string2hex((char *)body->short_message,
body->sm_length,sms_body);

body_str.s = sms_body;
Expand Down
4 changes: 2 additions & 2 deletions modules/sip_i/sip_i.c
Original file line number Diff line number Diff line change
Expand Up @@ -759,7 +759,7 @@ int get_param_pval(int isup_params_idx, int subfield_idx, int byte_idx,
} else { /* else print param as hex representation */
pv_tr_res_buf[0] = '0';
pv_tr_res_buf[1] = 'x';
string2hex(p->val, p->len, pv_tr_res_buf + 2);
string2hex((const char *)p->val, p->len, pv_tr_res_buf + 2);
res->flags = PV_VAL_STR;
res->rs.len = 2 * p->len + 2;
res->rs.s = pv_tr_res_buf;
Expand Down Expand Up @@ -856,7 +856,7 @@ int get_param_pval_str(int isup_params_idx, int subfield_idx,
/* no aliases, print whole param as hex */
pv_tr_res_buf[0] = '0';
pv_tr_res_buf[1] = 'x';
string2hex(p->val, p->len, pv_tr_res_buf + 2);
string2hex((const char *)p->val, p->len, pv_tr_res_buf + 2);
res->flags = PV_VAL_STR;
res->rs.len = 2 * p->len + 2;
res->rs.s = pv_tr_res_buf;
Expand Down
2 changes: 1 addition & 1 deletion strcommon.c
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ int unescape_xml(char *dst, const char *src, int src_len)
void compute_md5(char *dst, const char *src, int src_len)
{
MD5_CTX context;
unsigned char digest[16];
char digest[16];
MD5Init (&context);
MD5Update (&context, src, src_len);
MD5Final (digest, &context);
Expand Down
2 changes: 1 addition & 1 deletion ut.h
Original file line number Diff line number Diff line change
Expand Up @@ -433,7 +433,7 @@ inline static int hexstr2int(char *c, int len, unsigned int *val)

/* double output length assumed ; does NOT zero-terminate */
inline static int string2hex(
/* input */ unsigned char *str, int len,
/* input */ const char *str, int len,
/* output */ char *hex )
{
int orig_len;
Expand Down

0 comments on commit a07ae74

Please sign in to comment.