22 #if !defined(OPENSSL_NO_SHA) && !defined(OPENSSL_NO_SHA1)
31 static int MGF1(
unsigned char *mask,
long len,
32 const unsigned char *
seed,
long seedlen);
35 const unsigned char *from,
int flen,
36 const unsigned char *param,
int plen)
38 int i, emlen = tlen - 1;
39 unsigned char *db, *
seed;
61 memset(db + SHA_DIGEST_LENGTH, 0,
62 emlen - flen - 2 * SHA_DIGEST_LENGTH - 1);
63 db[emlen - flen - SHA_DIGEST_LENGTH - 1] = 0x01;
64 memcpy(db + emlen - flen - SHA_DIGEST_LENGTH, from, (
unsigned int) flen);
69 "\xaa\xfd\x12\xf6\x59\xca\xe6\x34\x89\xb4\x79\xe5\x07\x6d\xde\xc2\xf0\x6c\xb5\x8f",
80 if (MGF1(dbmask, emlen - SHA_DIGEST_LENGTH, seed, SHA_DIGEST_LENGTH) < 0)
85 if (MGF1(seedmask, SHA_DIGEST_LENGTH, db, emlen - SHA_DIGEST_LENGTH) < 0)
88 seed[i] ^= seedmask[i];
95 const unsigned char *from,
int flen,
int num,
96 const unsigned char *param,
int plen)
98 int i, dblen, mlen = -1;
99 const unsigned char *maskeddb;
102 unsigned char *padded_from;
133 padded_from = db + dblen;
134 memset(padded_from, 0, lzero);
135 memcpy(padded_from + lzero, from, flen);
139 if (MGF1(seed, SHA_DIGEST_LENGTH, maskeddb, dblen))
142 seed[i] ^= padded_from[i];
144 if (MGF1(db, dblen, seed, SHA_DIGEST_LENGTH))
146 for (i = 0; i < dblen; i++)
147 db[i] ^= maskeddb[i];
152 if (memcmp(db, phash, SHA_DIGEST_LENGTH) != 0 || bad)
156 for (i = SHA_DIGEST_LENGTH; i < dblen; i++)
159 if (i == dblen || db[i] != 0x01)
172 memcpy(to, db + i, mlen);
187 const unsigned char *
seed,
long seedlen,
const EVP_MD *dgst)
190 unsigned char cnt[4];
200 for (i = 0; outlen <
len; i++)
202 cnt[0] = (
unsigned char)((i >> 24) & 255);
203 cnt[1] = (
unsigned char)((i >> 16) & 255);
204 cnt[2] = (
unsigned char)((i >> 8)) & 255;
205 cnt[3] = (
unsigned char)(i & 255);
210 if (outlen + mdlen <= len)
220 memcpy(mask + outlen, md, len - outlen);
230 static int MGF1(
unsigned char *mask,
long len,
const unsigned char *
seed,