From the wikipedia entry on SHA-256 I'm a bit confused about which operations actually go into the algorithm. From the pseudo code it appears the operations are $\texttt{xor}$, $\texttt{and}$, rotate, shift, and addition. But further down it says that $\texttt{or}$ also goes into the algorithm. This description (p 5-6) makes no mention of $\texttt{or}$.

So, which is it?


2 Answers 2


A quick look at the SHA-256 and SHA-512 implementations in Bouncy Castle do not show up any OR calculations, except to implement the rotation. The implementation of rotate (in Sum and Sigma) can however just as easily use XOR if required.

Anyway, if it would be present: A or B = (A xor B) xor (A and B) - and it's gone again.


The functions used by SHA-2, called $Ch$ and $Maj$ are defined like this in the standard:

$$Ch(x, y, z) = (x \land y) \oplus (\lnot x \land z)$$ $$Maj(x, y, z) = (x \land y) \oplus (x \land z) \oplus (y \land z)$$

However, an equivalent way to define them replaces the XOR with OR, as the standard (pdf) states:

Each of the algorithms include $Ch(x, y, z)$ and $Maj(x, y, z)$ functions; the exclusive-OR operation ($\oplus$) in these functions may be replaced by a bitwise OR operation ($\lor$) and produce identical results.

Of course, any functionally complete set of operators is sufficient to implement the functions, but at least some implementations (e.g. PyPy) do elect to use OR here.

  • 1
    $\begingroup$ And these different methods helps a lot when trying to optimize the algorithm for different architectures. $\endgroup$
    – pipe
    Commented Dec 30, 2015 at 5:43

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.