Commit aa75e6df authored by Pavel Tvrdík's avatar Pavel Tvrdík
Browse files

MD5: change interface of md5_final()

originally:
  void md5_final(unsigned char digest[16], struct md5_context *ctx);

newly:
  byte * md5_final(md5_context *ctx);
parent 0a8abdf6
Loading
Loading
Loading
Loading
+2 −0
Original line number Diff line number Diff line
@@ -9,6 +9,8 @@
#ifndef _BIRD_CONF_H_
#define _BIRD_CONF_H_

#include "sysdep/config.h"
#include "lib/ip.h"
#include "lib/resource.h"
#include "lib/timer.h"

+11 −5
Original line number Diff line number Diff line
@@ -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 md5_init(struct md5_context *ctx)
void md5_init(md5_context *ctx)
{
    ctx->buf[0] = 0x67452301;
    ctx->buf[1] = 0xefcdab89;
@@ -53,7 +53,7 @@ void md5_init(struct md5_context *ctx)
 * Update context to reflect the concatenation of another buffer full
 * of bytes.
 */
void md5_update(struct md5_context *ctx, unsigned char const *buf, unsigned len)
void md5_update(md5_context *ctx, unsigned char const *buf, unsigned len)
{
    u32 t;

@@ -101,7 +101,7 @@ void md5_update(struct md5_context *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 md5_final(unsigned char digest[16], struct md5_context *ctx)
byte *md5_final(md5_context *ctx)
{
    unsigned count;
    unsigned char *p;
@@ -138,8 +138,14 @@ void md5_final(unsigned char digest[16], struct md5_context *ctx)

    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 */

    return (byte*) ctx->buf;
}

/* I am a hard paranoid */
void md5_erase_ctx(md5_context *ctx)
{
  memset((char *) ctx, 0, sizeof(*ctx));	/* In case it's sensitive */
}

/* The four core functions - F1 is optimized somewhat */
+6 −4
Original line number Diff line number Diff line
@@ -15,15 +15,17 @@
#define MD5_HEX_SIZE	33
#define MD5_BLOCK_SIZE	64

struct md5_context {
typedef struct
{
  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_init(md5_context *context);
void md5_update(md5_context *context, unsigned char const *buf, unsigned len);
byte *md5_final(md5_context *context);

void md5_transform(u32 buf[4], u32 const in[16]);


+2 −3
Original line number Diff line number Diff line
@@ -16,12 +16,11 @@
static void
get_md5(const char *str, char (*out_hash)[MD5_HEX_SIZE])
{
  unsigned char hash[MD5_SIZE];
  struct md5_context ctxt;
  md5_context ctxt;

  md5_init(&ctxt);
  md5_update(&ctxt, str, strlen(str));
  md5_final(hash, &ctxt);
  byte *hash = md5_final(&ctxt);

  int i;
  for(i = 0; i < MD5_SIZE; i++)
+1 −0
Original line number Diff line number Diff line
@@ -9,6 +9,7 @@
#ifndef _BIRD_RESOURCE_H_
#define _BIRD_RESOURCE_H_

#include <stddef.h>
#include "lib/lists.h"

/* Resource */
Loading