Monero
blamka-round-ref.h
Go to the documentation of this file.
1 /*
2 Copyright (c) 2018-2019, tevador <tevador@gmail.com>
3 
4 All rights reserved.
5 
6 Redistribution and use in source and binary forms, with or without
7 modification, are permitted provided that the following conditions are met:
8  * Redistributions of source code must retain the above copyright
9  notice, this list of conditions and the following disclaimer.
10  * Redistributions in binary form must reproduce the above copyright
11  notice, this list of conditions and the following disclaimer in the
12  documentation and/or other materials provided with the distribution.
13  * Neither the name of the copyright holder nor the
14  names of its contributors may be used to endorse or promote products
15  derived from this software without specific prior written permission.
16 
17 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
18 ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
19 WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
20 DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
21 FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
22 DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
23 SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
24 CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
25 OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
26 OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27 */
28 
29 /* Original code from Argon2 reference source code package used under CC0 Licence
30  * https://github.com/P-H-C/phc-winner-argon2
31  * Copyright 2015
32  * Daniel Dinu, Dmitry Khovratovich, Jean-Philippe Aumasson, and Samuel Neves
33 */
34 
35 #ifndef BLAKE_ROUND_MKA_H
36 #define BLAKE_ROUND_MKA_H
37 
38 #include "blake2.h"
39 #include "blake2-impl.h"
40 
41  /* designed by the Lyra PHC team */
43  const uint64_t m = UINT64_C(0xFFFFFFFF);
44  const uint64_t xy = (x & m) * (y & m);
45  return x + y + 2 * xy;
46 }
47 
48 #define G(a, b, c, d) \
49  do { \
50  a = fBlaMka(a, b); \
51  d = rotr64(d ^ a, 32); \
52  c = fBlaMka(c, d); \
53  b = rotr64(b ^ c, 24); \
54  a = fBlaMka(a, b); \
55  d = rotr64(d ^ a, 16); \
56  c = fBlaMka(c, d); \
57  b = rotr64(b ^ c, 63); \
58  } while ((void)0, 0)
59 
60 #define BLAKE2_ROUND_NOMSG(v0, v1, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, \
61  v12, v13, v14, v15) \
62  do { \
63  G(v0, v4, v8, v12); \
64  G(v1, v5, v9, v13); \
65  G(v2, v6, v10, v14); \
66  G(v3, v7, v11, v15); \
67  G(v0, v5, v10, v15); \
68  G(v1, v6, v11, v12); \
69  G(v2, v7, v8, v13); \
70  G(v3, v4, v9, v14); \
71  } while ((void)0, 0)
72 
73 #endif
#define FORCE_INLINE
Definition: endian.h:10
unsigned __int64 uint64_t
Definition: stdint.h:136
#define UINT64_C(val)
Definition: stdint.h:284
static FORCE_INLINE uint64_t fBlaMka(uint64_t x, uint64_t y)
Definition: blamka-round-ref.h:42