| | | 1 | | using System; |
| | | 2 | | using System.Collections.Generic; |
| | | 3 | | |
| | | 4 | | namespace Renci.SshNet.Security.Chaos.NaCl.Internal.Salsa |
| | | 5 | | { |
| | | 6 | | internal class Salsa20 |
| | | 7 | | { |
| | | 8 | | public const uint SalsaConst0 = 0x61707865; |
| | | 9 | | public const uint SalsaConst1 = 0x3320646e; |
| | | 10 | | public const uint SalsaConst2 = 0x79622d32; |
| | | 11 | | public const uint SalsaConst3 = 0x6b206574; |
| | | 12 | | |
| | | 13 | | internal static void HSalsa20(byte[] output, int outputOffset, byte[] key, int keyOffset, byte[] nonce, int nonc |
| | 0 | 14 | | { |
| | | 15 | | Array16<UInt32> state; |
| | 0 | 16 | | state.x0 = SalsaConst0; |
| | 0 | 17 | | state.x1 = ByteIntegerConverter.LoadLittleEndian32(key, keyOffset + 0); |
| | 0 | 18 | | state.x2 = ByteIntegerConverter.LoadLittleEndian32(key, keyOffset + 4); |
| | 0 | 19 | | state.x3 = ByteIntegerConverter.LoadLittleEndian32(key, keyOffset + 8); |
| | 0 | 20 | | state.x4 = ByteIntegerConverter.LoadLittleEndian32(key, keyOffset + 12); |
| | 0 | 21 | | state.x5 = SalsaConst1; |
| | 0 | 22 | | state.x6 = ByteIntegerConverter.LoadLittleEndian32(nonce, nonceOffset + 0); |
| | 0 | 23 | | state.x7 = ByteIntegerConverter.LoadLittleEndian32(nonce, nonceOffset + 4); |
| | 0 | 24 | | state.x8 = ByteIntegerConverter.LoadLittleEndian32(nonce, nonceOffset + 8); |
| | 0 | 25 | | state.x9 = ByteIntegerConverter.LoadLittleEndian32(nonce, nonceOffset + 12); |
| | 0 | 26 | | state.x10 = SalsaConst2; |
| | 0 | 27 | | state.x11 = ByteIntegerConverter.LoadLittleEndian32(key, keyOffset + 16); |
| | 0 | 28 | | state.x12 = ByteIntegerConverter.LoadLittleEndian32(key, keyOffset + 20); |
| | 0 | 29 | | state.x13 = ByteIntegerConverter.LoadLittleEndian32(key, keyOffset + 24); |
| | 0 | 30 | | state.x14 = ByteIntegerConverter.LoadLittleEndian32(key, keyOffset + 28); |
| | 0 | 31 | | state.x15 = SalsaConst3; |
| | | 32 | | |
| | 0 | 33 | | SalsaCore.HSalsa(out state, ref state, 20); |
| | | 34 | | |
| | 0 | 35 | | ByteIntegerConverter.StoreLittleEndian32(output, outputOffset + 0, state.x0); |
| | 0 | 36 | | ByteIntegerConverter.StoreLittleEndian32(output, outputOffset + 4, state.x5); |
| | 0 | 37 | | ByteIntegerConverter.StoreLittleEndian32(output, outputOffset + 8, state.x10); |
| | 0 | 38 | | ByteIntegerConverter.StoreLittleEndian32(output, outputOffset + 12, state.x15); |
| | 0 | 39 | | ByteIntegerConverter.StoreLittleEndian32(output, outputOffset + 16, state.x6); |
| | 0 | 40 | | ByteIntegerConverter.StoreLittleEndian32(output, outputOffset + 20, state.x7); |
| | 0 | 41 | | ByteIntegerConverter.StoreLittleEndian32(output, outputOffset + 24, state.x8); |
| | 0 | 42 | | ByteIntegerConverter.StoreLittleEndian32(output, outputOffset + 28, state.x9); |
| | 0 | 43 | | } |
| | | 44 | | } |
| | | 45 | | } |