25#include <Library/BaseLib.h>
26#include <Library/BaseMemoryLib.h>
29#define U32V(v) ((UINT32)(v) & 0xFFFFFFFFU)
30#define ROTATE(v, c) (LRotU32 ((v), (c)))
31#define XOR(v, w) ((v) ^ (w))
32#define PLUS(v, w) (U32V((v) + (w)))
33#define PLUSONE(v) (PLUS((v), 1))
34#define LOAD32_LE(a) (ReadUnaligned32 ((UINT32 *)(a)))
35#define STORE32_LE(a, v) (WriteUnaligned32 ((UINT32 *)(a), (v)))
37#define QUARTERROUND(a, b, c, d) \
39 d = ROTATE(XOR(d, a), 16); \
41 b = ROTATE(XOR(b, c), 12); \
43 d = ROTATE(XOR(d, a), 8); \
45 b = ROTATE(XOR(b, c), 7);
55 Context->Input[0] = 0x61707865U;
56 Context->Input[1] = 0x3320646EU;
57 Context->Input[2] = 0x79622d32U;
58 Context->Input[3] = 0x6B206574U;
65 Context->Input[10] =
LOAD32_LE (Key + 24);
66 Context->Input[11] =
LOAD32_LE (Key + 28);
76 IN CONST UINT8 *Source,
77 OUT UINT8 *Destination,
123 J0 = Context->Input[0];
124 J1 = Context->Input[1];
125 J2 = Context->Input[2];
126 J3 = Context->Input[3];
127 J4 = Context->Input[4];
128 J5 = Context->Input[5];
129 J6 = Context->Input[6];
130 J7 = Context->Input[7];
131 J8 = Context->Input[8];
132 J9 = Context->Input[9];
133 J10 = Context->Input[10];
134 J11 = Context->Input[11];
135 J12 = Context->Input[12];
136 J13 = Context->Input[13];
137 J14 = Context->Input[14];
138 J15 = Context->Input[15];
141 if (
Length <
sizeof (Tmp)) {
145 Ctarget = Destination;
166 for (Index = 20; Index > 0; Index -= 2) {
187 X10 =
PLUS (X10, J10);
188 X11 =
PLUS (X11, J11);
189 X12 =
PLUS (X12, J12);
190 X13 =
PLUS (X13, J13);
191 X14 =
PLUS (X14, J14);
192 X15 =
PLUS (X15, J15);
234 if (
Length <=
sizeof (Tmp)) {
235 if (
Length <
sizeof (Tmp)) {
239 Context->Input[12] = J12;
240 Context->Input[13] = J13;
246 Destination +=
sizeof (Tmp);
247 Source +=
sizeof (Tmp);
VOID ChaChaCryptBuffer(IN OUT CHACHA_CONTEXT *Context, IN CONST UINT8 *Source, OUT UINT8 *Destination, IN UINT32 Length)
VOID ChaChaInitCtx(OUT CHACHA_CONTEXT *Context, IN CONST UINT8 *Key, IN CONST UINT8 *Iv, IN UINT32 Counter)
#define QUARTERROUND(a, b, c, d)
VOID *EFIAPI CopyMem(OUT VOID *DestinationBuffer, IN CONST VOID *SourceBuffer, IN UINTN Length)
VOID *EFIAPI ZeroMem(OUT VOID *Buffer, IN UINTN Length)