2018-12-11 20:00:30 +00:00
|
|
|
/*
|
|
|
|
Copyright (c) 2018 tevador
|
|
|
|
|
|
|
|
This file is part of RandomX.
|
|
|
|
|
|
|
|
RandomX is free software: you can redistribute it and/or modify
|
|
|
|
it under the terms of the GNU General Public License as published by
|
|
|
|
the Free Software Foundation, either version 3 of the License, or
|
|
|
|
(at your option) any later version.
|
|
|
|
|
|
|
|
RandomX is distributed in the hope that it will be useful,
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
GNU General Public License for more details.
|
|
|
|
|
|
|
|
You should have received a copy of the GNU General Public License
|
|
|
|
along with RandomX. If not, see<http://www.gnu.org/licenses/>.
|
|
|
|
*/
|
|
|
|
|
|
|
|
/* Original code from Argon2 reference source code package used under CC0 Licence
|
|
|
|
* https://github.com/P-H-C/phc-winner-argon2
|
|
|
|
* Copyright 2015
|
|
|
|
* Daniel Dinu, Dmitry Khovratovich, Jean-Philippe Aumasson, and Samuel Neves
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef PORTABLE_BLAKE2_IMPL_H
|
|
|
|
#define PORTABLE_BLAKE2_IMPL_H
|
|
|
|
|
|
|
|
#include <stdint.h>
|
|
|
|
|
2019-02-09 14:45:26 +00:00
|
|
|
#include "endian.h"
|
2018-12-11 20:00:30 +00:00
|
|
|
|
2019-02-09 14:45:26 +00:00
|
|
|
static FORCE_INLINE uint64_t load48(const void *src) {
|
2018-12-11 20:00:30 +00:00
|
|
|
const uint8_t *p = (const uint8_t *)src;
|
|
|
|
uint64_t w = *p++;
|
|
|
|
w |= (uint64_t)(*p++) << 8;
|
|
|
|
w |= (uint64_t)(*p++) << 16;
|
|
|
|
w |= (uint64_t)(*p++) << 24;
|
|
|
|
w |= (uint64_t)(*p++) << 32;
|
|
|
|
w |= (uint64_t)(*p++) << 40;
|
|
|
|
return w;
|
|
|
|
}
|
|
|
|
|
2019-02-09 14:45:26 +00:00
|
|
|
static FORCE_INLINE void store48(void *dst, uint64_t w) {
|
2018-12-11 20:00:30 +00:00
|
|
|
uint8_t *p = (uint8_t *)dst;
|
|
|
|
*p++ = (uint8_t)w;
|
|
|
|
w >>= 8;
|
|
|
|
*p++ = (uint8_t)w;
|
|
|
|
w >>= 8;
|
|
|
|
*p++ = (uint8_t)w;
|
|
|
|
w >>= 8;
|
|
|
|
*p++ = (uint8_t)w;
|
|
|
|
w >>= 8;
|
|
|
|
*p++ = (uint8_t)w;
|
|
|
|
w >>= 8;
|
|
|
|
*p++ = (uint8_t)w;
|
|
|
|
}
|
|
|
|
|
2019-02-09 14:45:26 +00:00
|
|
|
static FORCE_INLINE uint32_t rotr32(const uint32_t w, const unsigned c) {
|
2018-12-11 20:00:30 +00:00
|
|
|
return (w >> c) | (w << (32 - c));
|
|
|
|
}
|
|
|
|
|
2019-02-09 14:45:26 +00:00
|
|
|
static FORCE_INLINE uint64_t rotr64(const uint64_t w, const unsigned c) {
|
2018-12-11 20:00:30 +00:00
|
|
|
return (w >> c) | (w << (64 - c));
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif
|