# Understanding non-linearity in Salsa20 over various rings

In his design of Salsa20, Bernstein writes to ensure non-linearity he chose

32-bit addition (breaking linearity over $$Z/2$$), 32-bit xor (breaking linearity over \$Z/2^32), and constant-distance 32-bit rotation (diffusing changes from high bits to low bits).

Can you help me understand this? A linear function is one such that $$f(ax+by) = af(x) + bf(y)$$. It sounds like whether addition and xor are linear depends on which definition of addition and multiplication you are using, which depends on which ring you are using, but rotation is linear in any ring.

Also, $$f$$ takes one input, whereas 32 bit add or xor take two inputs, each of which is a portion of the 512 bit element. I assume a 2-ary function is linear if, fixing the first input makes a linear 1-ary function.

It sounds like whether addition and xor are linear depends on which definition of addition and multiplication you are using, which depends on which ring you are using

That is quite correct; operations that are linear in one ring need not be linear in a different one.

but rotation is linear in any ring

Nope; rotation is not linear in the ring $$\mathbb{Z}/{2^{32}}$$

Here's an example: let $$F(x)$$ be $$x$$ rotated right one position.

Then, $$F(1+1) = F(2) = 1$$, however $$F(1) + F(1) = 2^{31} + 2^{31} = 0$$, hence $$F$$ is not linear.

I assume a 2-ary function is linear if, fixing the first input makes a linear 1-ary function.

No; if that were the case, then multiplication would be a linear operation (because if you fix one of the inputs, it is linear in the other).