blamka-round-ref.h 2.7 KB

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