20
20
* You should have received a copy of the GNU Lesser General Public License
21
21
* along with the nettle library; see the file COPYING.LIB. If not, write to
22
* the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston,
22
* the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
40
40
#include "macros.h"
41
41
#include "memxor.h"
43
#ifdef WORDS_BIGENDIAN
44
#define LE_SWAP32(v) \
45
((ROTL32(8, v) & 0x00FF00FFUL) | \
46
(ROTL32(24, v) & 0xFF00FF00UL))
48
#define LE_SWAP32(v) (v)
51
#define QROUND(x0, x1, x2, x3) do { \
52
x1 ^= ROTL32(7, x0 + x3); \
53
x2 ^= ROTL32(9, x1 + x0); \
54
x3 ^= ROTL32(13, x2 + x1); \
55
x0 ^= ROTL32(18, x3 + x2); \
59
44
salsa20_crypt(struct salsa20_ctx *ctx,
69
54
uint32_t x[_SALSA20_INPUT_LENGTH];
71
memcpy (x, ctx->input, sizeof(x));
72
for (i = 0;i < 10;i ++)
74
QROUND(x[0], x[4], x[8], x[12]);
75
QROUND(x[5], x[9], x[13], x[1]);
76
QROUND(x[10], x[14], x[2], x[6]);
77
QROUND(x[15], x[3], x[7], x[11]);
79
QROUND(x[0], x[1], x[2], x[3]);
80
QROUND(x[5], x[6], x[7], x[4]);
81
QROUND(x[10], x[11], x[8], x[9]);
82
QROUND(x[15], x[12], x[13], x[14]);
85
for (i = 0;i < _SALSA20_INPUT_LENGTH;++i)
87
uint32_t t = x[i] + ctx->input[i];
56
_salsa20_core (x, ctx->input, 20);
91
58
ctx->input[9] += (++ctx->input[8] == 0);