Skip to content

Instantly share code, notes, and snippets.

@vdudouyt
Created November 9, 2016 07:13
Show Gist options
  • Save vdudouyt/9c946109f1c709b6d5835e77901800a4 to your computer and use it in GitHub Desktop.
Save vdudouyt/9c946109f1c709b6d5835e77901800a4 to your computer and use it in GitHub Desktop.
/*
* @seed: 20 bytes
* @result: 120 bytes (but use first 107 bytes only)
*/
int mgf1(char *seed, BYTE *result)
{
int hlen = 20;
int length = 127 - hlen;
int i, d = 0;
for(i = 0; i <= length; i += hlen)
{
unsigned char C[4];
SHA1_CTX ctx;
format_int(C, i, 4, MP_BIG_ENDIAN);
sha1_init(&ctx);
sha1_update(&ctx, seed, 20);
sha1_update(&ctx, C, 4);
sha1_final(&ctx, &result[d * 20]);
d++;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment