Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Generate Authenticode for the entire PE file #604

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
23 changes: 17 additions & 6 deletions pe.c
Original file line number Diff line number Diff line change
Expand Up @@ -285,14 +285,16 @@ generate_hash(char *data, unsigned int datasize,
goto done;
}

#if 1
}
#else // we have to migrate to doing this later :/
SumOfBytesHashed += hashsize;
}

/* Hash all remaining data */
if (datasize > SumOfBytesHashed) {
/* Hash all remaining data. If SecDir->Size is > 0 this code should not
* be entered. If it is, there are still things to hash. For a file
* without a SecDir, we need to hash what remains. */
if (datasize > SumOfBytesHashed + context->SecDir->Size) {
char padbuf[8];
ZeroMem(padbuf, 8);

hashbase = data + SumOfBytesHashed;
hashsize = datasize - SumOfBytesHashed;

Expand All @@ -306,8 +308,17 @@ generate_hash(char *data, unsigned int datasize,
}

SumOfBytesHashed += hashsize;
hashsize = ALIGN_VALUE(SumOfBytesHashed, 8) - SumOfBytesHashed;

if (hashsize) {
if (!(Sha256Update(sha256ctx, padbuf, hashsize)) ||
!(Sha1Update(sha1ctx, padbuf, hashsize))) {
perror(L"Unable to generate hash\n");
efi_status = EFI_OUT_OF_RESOURCES;
goto done;
}
}
}
#endif

if (!(Sha256Final(sha256ctx, sha256hash)) ||
!(Sha1Final(sha1ctx, sha1hash))) {
Expand Down