md5: Add const qualifiers

This commit is contained in:
Samuel Thibault 2024-10-19 21:47:02 +02:00
parent 4ed2811210
commit e856f0a920
2 changed files with 6 additions and 6 deletions

10
md5.c
View file

@ -46,7 +46,7 @@
* doesn't work. * doesn't work.
*/ */
#if defined(__i386__) || defined(__vax__) #if defined(__i386__) || defined(__vax__)
# define SET(n) (*(MD5_u32plus *)&ptr[(n) * 4]) # define SET(n) (*(const MD5_u32plus *)&ptr[(n) * 4])
# define GET(n) SET(n) # define GET(n) SET(n)
#else #else
# define SET(n) \ # define SET(n) \
@ -63,9 +63,9 @@
* This processes one or more 64-byte data blocks, but does NOT update * This processes one or more 64-byte data blocks, but does NOT update
* the bit counters. There're no alignment requirements. * the bit counters. There're no alignment requirements.
*/ */
static void *body(MD5_CTX *ctx, void *data, unsigned long size) static const void *body(MD5_CTX *ctx, const void *data, unsigned long size)
{ {
unsigned char *ptr; const unsigned char *ptr;
MD5_u32plus a, b, c, d; MD5_u32plus a, b, c, d;
MD5_u32plus saved_a, saved_b, saved_c, saved_d; MD5_u32plus saved_a, saved_b, saved_c, saved_d;
@ -181,7 +181,7 @@ void MD5_Init(MD5_CTX *ctx)
ctx->hi = 0; ctx->hi = 0;
} }
void MD5_Update(MD5_CTX *ctx, void *data, unsigned long size) void MD5_Update(MD5_CTX *ctx, const void *data, unsigned long size)
{ {
MD5_u32plus saved_lo; MD5_u32plus saved_lo;
unsigned long used, free; unsigned long used, free;
@ -205,7 +205,7 @@ void MD5_Update(MD5_CTX *ctx, void *data, unsigned long size)
} }
memcpy(&ctx->buffer[used], data, free); memcpy(&ctx->buffer[used], data, free);
data = (unsigned char *)data + free; data = (const unsigned char *)data + free;
size -= free; size -= free;
body(ctx, ctx->buffer, MD5_BLOCK_SZ); body(ctx, ctx->buffer, MD5_BLOCK_SZ);
} }

2
md5.h
View file

@ -23,7 +23,7 @@ typedef struct {
} MD5_CTX; } MD5_CTX;
extern void MD5_Init(MD5_CTX *ctx); extern void MD5_Init(MD5_CTX *ctx);
extern void MD5_Update(MD5_CTX *ctx, void *data, unsigned long size); extern void MD5_Update(MD5_CTX *ctx, const void *data, unsigned long size);
extern void MD5_Final(unsigned char *result, MD5_CTX *ctx); extern void MD5_Final(unsigned char *result, MD5_CTX *ctx);
#endif /* __MD5_H__ */ #endif /* __MD5_H__ */