Skip to main content

3. Operations on Words

The following logical operators will be applied to words in all four hash operations specified herein. SHA-224 and SHA-256 operate on 32-bit words while SHA-384 and SHA-512 operate on 64-bit words.

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)