Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Add single function hash for MD2, MD5, SHA1
  • Loading branch information
lcn2 committed Jun 1, 2017
commit 01bc06ca9175a0f566e472885469f91ce939bc14
9 changes: 9 additions & 0 deletions md2.c
Original file line number Diff line number Diff line change
Expand Up @@ -102,3 +102,12 @@ void md2_final(MD2_CTX *ctx, BYTE hash[])

memcpy(hash, ctx->state, MD2_BLOCK_SIZE);
}

void md2(BYTE hash[], BYTE data[], size_t len)
{
MD2_CTX ctx;

md2_init(&ctx);
md2_update(&ctx, data, len);
md2_final(&ctx,hash);
}
1 change: 1 addition & 0 deletions md2.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,5 +33,6 @@ typedef struct {
void md2_init(MD2_CTX *ctx);
void md2_update(MD2_CTX *ctx, const BYTE data[], size_t len);
void md2_final(MD2_CTX *ctx, BYTE hash[]); // size of hash must be MD2_BLOCK_SIZE
void md2(BYTE hash[], BYTE data[], size_t len);

#endif // MD2_H
9 changes: 9 additions & 0 deletions md5.c
Original file line number Diff line number Diff line change
Expand Up @@ -187,3 +187,12 @@ void md5_final(MD5_CTX *ctx, BYTE hash[])
hash[i + 12] = (ctx->state[3] >> (i * 8)) & 0x000000ff;
}
}

void md5(BYTE hash[], BYTE data[], size_t len)
{
MD5_CTX ctx;

md5_init(&ctx);
md5_update(&ctx, data, len);
md5_final(&ctx,hash);
}
1 change: 1 addition & 0 deletions md5.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,5 +34,6 @@ typedef struct {
void md5_init(MD5_CTX *ctx);
void md5_update(MD5_CTX *ctx, const BYTE data[], size_t len);
void md5_final(MD5_CTX *ctx, BYTE hash[]);
void md5(BYTE hash[], BYTE data[], size_t len);

#endif // MD5_H
9 changes: 9 additions & 0 deletions sha1.c
Original file line number Diff line number Diff line change
Expand Up @@ -147,3 +147,12 @@ void sha1_final(SHA1_CTX *ctx, BYTE hash[])
hash[i + 16] = (ctx->state[4] >> (24 - i * 8)) & 0x000000ff;
}
}

void sha1(BYTE hash[], BYTE data[], size_t len)
{
SHA1_CTX ctx;

sha1_init(&ctx);
sha1_update(&ctx, data, len);
sha1_final(&ctx,hash);
}
1 change: 1 addition & 0 deletions sha1.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,5 +35,6 @@ typedef struct {
void sha1_init(SHA1_CTX *ctx);
void sha1_update(SHA1_CTX *ctx, const BYTE data[], size_t len);
void sha1_final(SHA1_CTX *ctx, BYTE hash[]);
void sha1(BYTE hash[], BYTE data[], size_t len);

#endif // SHA1_H