Skip to content

Commit

Permalink
ADDED SHA1 function
Browse files Browse the repository at this point in the history
  • Loading branch information
willemt committed Sep 21, 2014
1 parent db3ff69 commit 32b50bf
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 8 deletions.
15 changes: 15 additions & 0 deletions sha1.c
Original file line number Diff line number Diff line change
Expand Up @@ -279,3 +279,18 @@ void SHA1Final(
memset(&finalcount, '\0', sizeof(finalcount));
}

void SHA1(
char *hash_out,
const char *str,
int len)
{
SHA1_CTX ctx;
unsigned int ii;

SHA1Init(&ctx);
for (ii=0; ii<len; ii+=1)
SHA1Update(&ctx, (const unsigned char*)str + ii, 1);
SHA1Final((unsigned char *)hash_out, &ctx);
hash_out[20] = '\0';
}

21 changes: 13 additions & 8 deletions sha1.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@
#define SHA1_H

/*
SHA-1 in C
By Steve Reid <[email protected]>
100% Public Domain
*/
SHA-1 in C
By Steve Reid <[email protected]>
100% Public Domain
*/

typedef struct
{
Expand All @@ -17,21 +17,26 @@ typedef struct
void SHA1Transform(
uint32_t state[5],
const unsigned char buffer[64]
);
);

void SHA1Init(
SHA1_CTX * context
);
);

void SHA1Update(
SHA1_CTX * context,
const unsigned char *data,
uint32_t len
);
);

void SHA1Final(
unsigned char digest[20],
SHA1_CTX * context
);
);

void SHA1(
char *hash_out,
const char *str,
int len);

#endif /* SHA1_H */

0 comments on commit 32b50bf

Please sign in to comment.