3. 字上的操作
以下逻辑运算符将应用于本文规定的四种哈希操作中的字. SHA-224 和 SHA-256 对 32 位字进行操作, 而 SHA-384 和 SHA-512 对 64 位字进行操作.
In the operations below, x<<n is obtained as follows: discard the leftmost n bits of x and then pad the result with n zeroed bits on the right (the result will still be the same number of bits). Similarly, x>>n is obtained as follows: discard the rightmost n bits of x and then prepend the result with n zeroed bits on the left (the result will still be the same number of bits).
a. Bitwise logical word operations
X AND Y = bitwise logical "and" of X and Y.
X OR Y = bitwise logical "inclusive-or" of X and Y.
X XOR Y = bitwise logical "exclusive-or" of X and Y.
NOT X = bitwise logical "complement" of X.
Example:
01101100101110011101001001111011
XOR 01100101110000010110100110110111
--------------------------------
= 00001001011110001011101111001100
b. The operation X + Y is defined as follows: words X and Y represent w-bit integers x and y, where 0 <= x < 2^w and 0 <= y < 2^w. For positive integers n and m, let
n mod m
be the remainder upon dividing n by m. Compute
z = (x + y) mod 2^w.
Then 0 <= z < 2^w. Convert z to a word, Z, and define Z = X + Y.
c. The right shift operation SHR^n(x), where x is a w-bit word and n is an integer with 0 <= n < w, is defined by
SHR^n(x) = x>>n
d. The rotate right (circular right shift) operation ROTR^n(x), where x is a w-bit word and n is an integer with 0 <= n < w, is defined by
ROTR^n(x) = (x>>n) OR (x<<(w-n))
e. The rotate left (circular left shift) operation ROTL^n(x), where x is a w-bit word and n is an integer with 0 <= n < w, is defined by
ROTL^n(X) = (x<<n) OR (x>>(w-n))
Note the following equivalence relationships, where w is fixed in each relationship:
ROTL^n(x) = ROTR^(w-n)(x)
ROTR^n(x) = ROTL^(w-n)(x)