| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051 |
- /*
- Copyright (c) 2019 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/>.
- */
- #include "blake2/blake2.h"
- #include "blake2/endian.h"
- #include "Blake2Generator.hpp"
- #include "common.hpp"
- namespace RandomX {
- Blake2Generator::Blake2Generator(const void* seed, int nonce) : dataIndex(sizeof(data)) {
- memset(data, 0, sizeof(data));
- memcpy(data, seed, SeedSize);
- store32(&data[60], nonce);
- }
- uint8_t Blake2Generator::getByte() {
- checkData(1);
- return data[dataIndex++];
- }
- uint32_t Blake2Generator::getInt32() {
- checkData(4);
- auto ret = load32(&data[dataIndex]);
- dataIndex += 4;
- return ret;
- }
- void Blake2Generator::checkData(const size_t bytesNeeded) {
- if (dataIndex + bytesNeeded > sizeof(data)) {
- blake2b(data, sizeof(data), data, sizeof(data), nullptr, 0);
- dataIndex = 0;
- }
- }
- }
|