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

I don't understand why the follow code is written like this #2

Open
Huoke opened this issue Jan 31, 2019 · 1 comment
Open

I don't understand why the follow code is written like this #2

Huoke opened this issue Jan 31, 2019 · 1 comment

Comments

@Huoke
Copy link

Huoke commented Jan 31, 2019

I don't understand why the follow code is written like this.
According to the MD5 algorithm, it is filled with first 1 and 0 at last. Why do we need this step?
` for (offset = initial_len + 1; offset < new_len; offset++)
msg[offset] = 0;

// append the len in bits at the end of the buffer.
to_bytes(initial_len*8, msg + new_len);

// initial_len>>29 == initial_len*8>>32, but avoids overflow.
to_bytes(initial_len>>29, msg + new_len + 4);`
@JialongWang1224
Copy link

in the above:
msg = (uint8_t*)malloc(new_len + 8); memcpy(msg, initial_msg, initial_len);``
so the 0 to initial of msg is the true msg, the initial to new_len should be the padding, so we need to msg[initial_len]=0x80 and the msg[offset]=0

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

No branches or pull requests

2 participants