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

sha: implement SHA engine calls #136

Merged
merged 1 commit into from
Jan 29, 2023

Conversation

DacoTaco
Copy link
Member

@DacoTaco DacoTaco commented Jan 22, 2023

while looking through the reverse engineering of the SHA engine for starstruck i noticed it was actually super easy to use, and applications like priiloader could use it to validate content integrity.
this would mean all software based sha implementations can be replaced with the hardware implementation on the wii.

this has been tested with the following code :

//input should always be 64bit aligned, in the actual code this was not on the stack but rather a global
u8 input[0x0400000] [[gnu::aligned(64)]];

//actual test
gprintf("starting context\n");
sha_context context [[gnu::aligned(32)]];
u32 output[5] [[gnu::aligned(32)]];
memset(output, 0, sizeof(output));
ret = SHA_InitializeContext(&context);
if(ret < 0)
{
	gprintf("failed to reset SHA : %d.\n", ret);
	return 0;
}

memcpy(input, input_bin, input_bin_size);
gprintf("copied %d bytes of data\n", input_bin_size);

ret = SHA_Calculate(&context, input, input_bin_size, output);
if(ret < 0)
{
	gprintf("failed to calc SHA : %d.\n", ret);
	return 0;
}

gprintf("final hash : %08X %08X %08X %08X %08X %08X\n", output[0], output[1], output[2], output[3], output[4]);
gprintf("test successful!\n");

@DacoTaco DacoTaco force-pushed the feature/shaEngine branch 2 times, most recently from 27a6b9e to 08d3f74 Compare January 22, 2023 12:43
@DacoTaco DacoTaco merged commit 3b7d98c into devkitPro:master Jan 29, 2023
@DacoTaco DacoTaco deleted the feature/shaEngine branch February 4, 2023 19:34
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants