0
0
mirror of https://gitlab.nic.cz/labs/bird.git synced 2025-01-08 18:11:54 +00:00

MD5: change naming style

MD5Init         -> md5_init
MD5Update       -> md5_update
MD5Transform    -> md5_transform
MD5Final        -> md5_final
MD5Context      -> md5_context
This commit is contained in:
Pavel Tvrdík 2015-05-13 09:32:00 +02:00
parent 5aa9ab0cfd
commit 1512c11ddc
5 changed files with 47 additions and 43 deletions

View File

@ -38,7 +38,7 @@ void byteReverse(unsigned char *buf, unsigned longs)
* Start MD5 accumulation. Set bit count to 0 and buffer to mysterious
* initialization constants.
*/
void MD5Init(struct MD5Context *ctx)
void md5_init(struct md5_context *ctx)
{
ctx->buf[0] = 0x67452301;
ctx->buf[1] = 0xefcdab89;
@ -53,7 +53,7 @@ void MD5Init(struct MD5Context *ctx)
* Update context to reflect the concatenation of another buffer full
* of bytes.
*/
void MD5Update(struct MD5Context *ctx, unsigned char const *buf, unsigned len)
void md5_update(struct md5_context *ctx, unsigned char const *buf, unsigned len)
{
u32 t;
@ -78,7 +78,7 @@ void MD5Update(struct MD5Context *ctx, unsigned char const *buf, unsigned len)
}
memcpy(p, buf, t);
byteReverse(ctx->in, 16);
MD5Transform(ctx->buf, (u32 *) ctx->in);
md5_transform(ctx->buf, (u32 *) ctx->in);
buf += t;
len -= t;
}
@ -87,7 +87,7 @@ void MD5Update(struct MD5Context *ctx, unsigned char const *buf, unsigned len)
while (len >= 64) {
memcpy(ctx->in, buf, 64);
byteReverse(ctx->in, 16);
MD5Transform(ctx->buf, (u32 *) ctx->in);
md5_transform(ctx->buf, (u32 *) ctx->in);
buf += 64;
len -= 64;
}
@ -101,7 +101,7 @@ void MD5Update(struct MD5Context *ctx, unsigned char const *buf, unsigned len)
* Final wrapup - pad to 64-byte boundary with the bit pattern
* 1 0* (64-bit count of bits processed, MSB-first)
*/
void MD5Final(unsigned char digest[16], struct MD5Context *ctx)
void md5_final(unsigned char digest[16], struct md5_context *ctx)
{
unsigned count;
unsigned char *p;
@ -122,7 +122,7 @@ void MD5Final(unsigned char digest[16], struct MD5Context *ctx)
/* Two lots of padding: Pad the first block to 64 bytes */
memset(p, 0, count);
byteReverse(ctx->in, 16);
MD5Transform(ctx->buf, (u32 *) ctx->in);
md5_transform(ctx->buf, (u32 *) ctx->in);
/* Now fill the next block with 56 bytes */
memset(ctx->in, 0, 56);
@ -136,7 +136,7 @@ void MD5Final(unsigned char digest[16], struct MD5Context *ctx)
((u32 *) ctx->in)[14] = ctx->bits[0];
((u32 *) ctx->in)[15] = ctx->bits[1];
MD5Transform(ctx->buf, (u32 *) ctx->in);
md5_transform(ctx->buf, (u32 *) ctx->in);
byteReverse((unsigned char *) ctx->buf, 4);
memcpy(digest, ctx->buf, 16);
memset((char *) ctx, 0, sizeof(ctx)); /* In case it's sensitive */
@ -159,7 +159,7 @@ void MD5Final(unsigned char digest[16], struct MD5Context *ctx)
* reflect the addition of 16 longwords of new data. MD5Update blocks
* the data and converts bytes into longwords for this routine.
*/
void MD5Transform(u32 buf[4], u32 const in[16])
void md5_transform(u32 buf[4], u32 const in[16])
{
register u32 a, b, c, d;

View File

@ -8,16 +8,23 @@
* Can be freely distributed and used under the terms of the GNU GPL.
*/
struct MD5Context {
u32 buf[4];
u32 bits[2];
unsigned char in[64];
};
#ifndef _BIRD_MD5_H_
#define _BIRD_MD5_H_
#define MD5_SIZE 16
#define MD5_HEX_SIZE 33
#define MD5_BLOCK_SIZE 64
struct md5_context {
u32 buf[4];
u32 bits[2];
unsigned char in[64];
} md5_context;
void md5_init(struct md5_context *context);
void md5_update(struct md5_context *context, unsigned char const *buf, unsigned len);
void md5_final(unsigned char digest[16], struct md5_context *context);
void md5_transform(u32 buf[4], u32 const in[16]);
void MD5Init(struct MD5Context *context);
void MD5Update(struct MD5Context *context, unsigned char const *buf,
unsigned len);
void MD5Final(unsigned char digest[16], struct MD5Context *context);
void MD5Transform(u32 buf[4], u32 const in[16]);
#endif /* _BIRD_MD5_H_ */

View File

@ -13,18 +13,15 @@
#include "lib/md5.h"
#include "lib/md5.c" /* REMOVE ME */
#define MD5_SIZE 16
#define MD5_HEX_SIZE 33
static void
get_md5(const char *str, char (*out_hash)[MD5_HEX_SIZE])
{
unsigned char hash[MD5_SIZE];
struct MD5Context ctxt;
struct md5_context ctxt;
MD5Init(&ctxt);
MD5Update(&ctxt, str, strlen(str));
MD5Final(hash, &ctxt);
md5_init(&ctxt);
md5_update(&ctxt, str, strlen(str));
md5_final(hash, &ctxt);
int i;
for(i = 0; i < MD5_SIZE; i++)

View File

@ -108,11 +108,11 @@ ospf_pkt_finalize(struct ospf_iface *ifa, struct ospf_packet *pkt)
char password[OSPF_AUTH_CRYPT_SIZE];
strncpy(password, passwd->password, sizeof(password));
struct MD5Context ctxt;
MD5Init(&ctxt);
MD5Update(&ctxt, (char *) pkt, plen);
MD5Update(&ctxt, password, OSPF_AUTH_CRYPT_SIZE);
MD5Final(tail, &ctxt);
struct md5_context ctxt;
md5_init(&ctxt);
md5_update(&ctxt, (char *) pkt, plen);
md5_update(&ctxt, password, OSPF_AUTH_CRYPT_SIZE);
md5_final(tail, &ctxt);
break;
default:
@ -180,11 +180,11 @@ ospf_pkt_checkauth(struct ospf_neighbor *n, struct ospf_iface *ifa, struct ospf_
strncpy(passwd, pass->password, OSPF_AUTH_CRYPT_SIZE);
struct MD5Context ctxt;
MD5Init(&ctxt);
MD5Update(&ctxt, (char *) pkt, plen);
MD5Update(&ctxt, passwd, OSPF_AUTH_CRYPT_SIZE);
MD5Final(md5sum, &ctxt);
struct md5_context ctxt;
md5_init(&ctxt);
md5_update(&ctxt, (char *) pkt, plen);
md5_update(&ctxt, passwd, OSPF_AUTH_CRYPT_SIZE);
md5_final(md5sum, &ctxt);
if (memcmp(md5sum, tail, OSPF_AUTH_CRYPT_SIZE))
DROP("wrong MD5 digest", pass->id);

View File

@ -57,7 +57,7 @@ rip_incoming_authentication( struct proto *p, struct rip_block_auth *block, stru
{
struct password_item *pass = NULL, *ptmp;
struct rip_md5_tail *tail;
struct MD5Context ctxt;
struct md5_context ctxt;
char md5sum_packet[16];
char md5sum_computed[16];
struct neighbor *neigh = neigh_find(p, &whotoldme, 0);
@ -97,9 +97,9 @@ rip_incoming_authentication( struct proto *p, struct rip_block_auth *block, stru
memcpy(md5sum_packet, tail->md5, 16);
strncpy(tail->md5, pass->password, 16);
MD5Init(&ctxt);
MD5Update(&ctxt, (char *) packet, ntohs(block->packetlen) + sizeof(struct rip_block_auth) );
MD5Final(md5sum_computed, &ctxt);
md5_init(&ctxt);
md5_update(&ctxt, (char *) packet, ntohs(block->packetlen) + sizeof(struct rip_block_auth) );
md5_final(md5sum_computed, &ctxt);
if (memcmp(md5sum_packet, md5sum_computed, 16))
return 1;
}
@ -136,7 +136,7 @@ rip_outgoing_authentication( struct proto *p, struct rip_block_auth *block, stru
case AT_MD5:
{
struct rip_md5_tail *tail;
struct MD5Context ctxt;
struct md5_context ctxt;
static u32 sequence = 0;
if (num > PACKET_MD5_MAX)
@ -157,9 +157,9 @@ rip_outgoing_authentication( struct proto *p, struct rip_block_auth *block, stru
tail->mustbe0001 = 0x0100;
strncpy(tail->md5, passwd->password, 16);
MD5Init(&ctxt);
MD5Update(&ctxt, (char *) packet, PACKETLEN(num) + sizeof(struct rip_md5_tail));
MD5Final(tail->md5, &ctxt);
md5_init(&ctxt);
md5_update(&ctxt, (char *) packet, PACKETLEN(num) + sizeof(struct rip_md5_tail));
md5_final(tail->md5, &ctxt);
return PACKETLEN(num) + block->authlen;
}
default: