交换uint64_t的高位和低位的数学意义是什么?
What is the mathematical meaning of swap high part and low part of a uint64_t?
代码来自sha256、
的开源项目
uint64_t swapE64(uint64_t val) {
uint64_t x = val;
x = (x & 0xffffffff00000000) >> 32 | (x & 0x00000000ffffffff) << 32;
x = (x & 0xffff0000ffff0000) >> 16 | (x & 0x0000ffff0000ffff) << 16;
x = (x & 0xff00ff00ff00ff00) >> 8 | (x & 0x00ff00ff00ff00ff) << 8;
return x;
}
这个函数并不复杂,但是我不知道它的数学含义和用法
我的错,我问的不是很清楚。在不同的环境下使用不同的字节序表示,很明显,这个函数会保持数据的意义相同,但是在相同的字节序表示下,这意味着什么?
绝对会改变数据的含义,还是有其他原因需要交换?
维基百科上 SHA256 的 pseudocode 中说
Pre-processing: append the bit '1' to the message append k bits '0',
where k is the minimum number >= 0 such that the resulting message
length (modulo 512 in bits) is 448. append length of message (without the '1' bit or padding), in bits, as 64-bit big-endian
integer
(this will make the entire post-processed length a multiple of 512 bits)
x86/x86_64 Linux 和 Unix 是小端。
它将消息的长度转换为大字节序以将其添加到消息的末尾,它在 sha256.c 的 L105 的源代码中执行此操作,并且该部分代码是唯一的位置其中 swapE64
函数被调用:
https://github.com/noryb009/sha256/blob/77a185c837417ea3fc502289215738766a8f8046/sha256.c#L100
代码来自sha256、
的开源项目uint64_t swapE64(uint64_t val) {
uint64_t x = val;
x = (x & 0xffffffff00000000) >> 32 | (x & 0x00000000ffffffff) << 32;
x = (x & 0xffff0000ffff0000) >> 16 | (x & 0x0000ffff0000ffff) << 16;
x = (x & 0xff00ff00ff00ff00) >> 8 | (x & 0x00ff00ff00ff00ff) << 8;
return x;
}
这个函数并不复杂,但是我不知道它的数学含义和用法
我的错,我问的不是很清楚。在不同的环境下使用不同的字节序表示,很明显,这个函数会保持数据的意义相同,但是在相同的字节序表示下,这意味着什么?
绝对会改变数据的含义,还是有其他原因需要交换?
维基百科上 SHA256 的 pseudocode 中说
Pre-processing: append the bit '1' to the message append k bits '0', where k is the minimum number >= 0 such that the resulting message length (modulo 512 in bits) is 448. append length of message (without the '1' bit or padding), in bits, as 64-bit big-endian integer (this will make the entire post-processed length a multiple of 512 bits)
x86/x86_64 Linux 和 Unix 是小端。
它将消息的长度转换为大字节序以将其添加到消息的末尾,它在 sha256.c 的 L105 的源代码中执行此操作,并且该部分代码是唯一的位置其中 swapE64
函数被调用:
https://github.com/noryb009/sha256/blob/77a185c837417ea3fc502289215738766a8f8046/sha256.c#L100