1*0090dad1Sjhigh /*
2*0090dad1Sjhigh * Argon2 reference source code package - reference C implementations
3*0090dad1Sjhigh *
4*0090dad1Sjhigh * Copyright 2015
5*0090dad1Sjhigh * Daniel Dinu, Dmitry Khovratovich, Jean-Philippe Aumasson, and Samuel Neves
6*0090dad1Sjhigh *
7*0090dad1Sjhigh * You may use this work under the terms of a Creative Commons CC0 1.0
8*0090dad1Sjhigh * License/Waiver or the Apache Public License 2.0, at your option. The terms of
9*0090dad1Sjhigh * these licenses can be found at:
10*0090dad1Sjhigh *
11*0090dad1Sjhigh * - CC0 1.0 Universal : http://creativecommons.org/publicdomain/zero/1.0
12*0090dad1Sjhigh * - Apache 2.0 : http://www.apache.org/licenses/LICENSE-2.0
13*0090dad1Sjhigh *
14*0090dad1Sjhigh * You should have received a copy of both of these licenses along with this
15*0090dad1Sjhigh * software. If not, they may be obtained at the above URLs.
16*0090dad1Sjhigh */
17*0090dad1Sjhigh
18*0090dad1Sjhigh #ifndef BLAKE_ROUND_MKA_H
19*0090dad1Sjhigh #define BLAKE_ROUND_MKA_H
20*0090dad1Sjhigh
21*0090dad1Sjhigh #include "blake2.h"
22*0090dad1Sjhigh #include "blake2-impl.h"
23*0090dad1Sjhigh
24*0090dad1Sjhigh /* designed by the Lyra PHC team */
fBlaMka(uint64_t x,uint64_t y)25*0090dad1Sjhigh static BLAKE2_INLINE uint64_t fBlaMka(uint64_t x, uint64_t y) {
26*0090dad1Sjhigh const uint64_t m = UINT64_C(0xFFFFFFFF);
27*0090dad1Sjhigh const uint64_t xy = (x & m) * (y & m);
28*0090dad1Sjhigh return x + y + 2 * xy;
29*0090dad1Sjhigh }
30*0090dad1Sjhigh
31*0090dad1Sjhigh #define G(a, b, c, d) \
32*0090dad1Sjhigh do { \
33*0090dad1Sjhigh a = fBlaMka(a, b); \
34*0090dad1Sjhigh d = rotr64(d ^ a, 32); \
35*0090dad1Sjhigh c = fBlaMka(c, d); \
36*0090dad1Sjhigh b = rotr64(b ^ c, 24); \
37*0090dad1Sjhigh a = fBlaMka(a, b); \
38*0090dad1Sjhigh d = rotr64(d ^ a, 16); \
39*0090dad1Sjhigh c = fBlaMka(c, d); \
40*0090dad1Sjhigh b = rotr64(b ^ c, 63); \
41*0090dad1Sjhigh } while ((void)0, 0)
42*0090dad1Sjhigh
43*0090dad1Sjhigh #define BLAKE2_ROUND_NOMSG(v0, v1, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, \
44*0090dad1Sjhigh v12, v13, v14, v15) \
45*0090dad1Sjhigh do { \
46*0090dad1Sjhigh G(v0, v4, v8, v12); \
47*0090dad1Sjhigh G(v1, v5, v9, v13); \
48*0090dad1Sjhigh G(v2, v6, v10, v14); \
49*0090dad1Sjhigh G(v3, v7, v11, v15); \
50*0090dad1Sjhigh G(v0, v5, v10, v15); \
51*0090dad1Sjhigh G(v1, v6, v11, v12); \
52*0090dad1Sjhigh G(v2, v7, v8, v13); \
53*0090dad1Sjhigh G(v3, v4, v9, v14); \
54*0090dad1Sjhigh } while ((void)0, 0)
55*0090dad1Sjhigh
56*0090dad1Sjhigh #endif
57