Revert "Add new third party SHA-3 implementation to replace old obsolete one"
This reverts commit c6958cbbd6
.
Reason for revert: This implementation cannot generate digest noexcept, which is required by the QCryptographicHash API.
Change-Id: Iaf635d2738be378aa769b4631685163ba73c26e1
Task-number: QTBUG-71327
Reviewed-by: Mårten Nordheim <marten.nordheim@qt.io>
This commit is contained in:
parent
6e9a3d4209
commit
88dedfee1c
210
src/3rdparty/SHA-3/Endian.h
vendored
210
src/3rdparty/SHA-3/Endian.h
vendored
@ -1,210 +0,0 @@
|
||||
#ifndef ENDIAN_H_
|
||||
#define ENDIAN_H_
|
||||
|
||||
// Endianness conversion inlines - These will be optimised out on platforms where
|
||||
// it's not necessary, and will collapse to only the swapping code on
|
||||
// other big endian platforms.
|
||||
|
||||
inline bool littleEndian()
|
||||
{
|
||||
uint16_t tn;
|
||||
uint8_t test;
|
||||
|
||||
tn = 0xff00;
|
||||
test = *reinterpret_cast<uint8_t*>(&tn);
|
||||
if (!test)
|
||||
return true;
|
||||
else
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
inline uint16_t swapEndian(uint16_t in)
|
||||
{
|
||||
uint8_t b[2];
|
||||
uint16_t out[2];
|
||||
|
||||
b[0] = static_cast<uint8_t>(in >> 8);
|
||||
b[1] = static_cast<uint8_t>(in);
|
||||
|
||||
out[0] = ((b[1]) & 0x00FF);
|
||||
out[1] = ((b[0]) & 0x00FF);
|
||||
out[0] <<= 8;
|
||||
|
||||
return (out[0] | out[1]);
|
||||
}
|
||||
|
||||
inline uint32_t swapEndian(uint32_t in)
|
||||
{
|
||||
uint16_t b[2];
|
||||
uint32_t out[2];
|
||||
|
||||
b[0] = static_cast<uint16_t>(in >> 16);
|
||||
b[1] = static_cast<uint16_t>(in);
|
||||
b[0] = swapEndian(b[0]);
|
||||
b[1] = swapEndian(b[1]);
|
||||
|
||||
out[0] = ((b[1]) & 0x0000FFFF);
|
||||
out[1] = ((b[0]) & 0x0000FFFF);
|
||||
out[0] <<= 16;
|
||||
|
||||
return (out[0] | out[1]);
|
||||
}
|
||||
|
||||
inline uint64_t swapEndian(uint64_t in)
|
||||
{
|
||||
uint32_t b[2];
|
||||
uint64_t out[2];
|
||||
|
||||
b[0] = static_cast<uint32_t>(in >> 32);
|
||||
b[1] = static_cast<uint32_t>(in);
|
||||
b[0] = swapEndian(b[0]);
|
||||
b[1] = swapEndian(b[1]);
|
||||
|
||||
out[0] = ((b[1]) & 0x00000000FFFFFFFF);
|
||||
out[1] = ((b[0]) & 0x00000000FFFFFFFF);
|
||||
out[0] <<= 32;
|
||||
|
||||
return (out[0] | out[1]);
|
||||
}
|
||||
|
||||
|
||||
|
||||
inline uint16_t NativeToLittle(uint16_t in)
|
||||
{
|
||||
if (littleEndian())
|
||||
{
|
||||
return in;
|
||||
}
|
||||
else
|
||||
{
|
||||
return swapEndian(in);
|
||||
}
|
||||
}
|
||||
|
||||
inline uint32_t NativeToLittle(uint32_t in)
|
||||
{
|
||||
if (littleEndian())
|
||||
return in;
|
||||
else
|
||||
{
|
||||
return swapEndian(in);
|
||||
}
|
||||
}
|
||||
|
||||
inline uint64_t NativeToLittle(uint64_t in)
|
||||
{
|
||||
if (littleEndian())
|
||||
return in;
|
||||
else
|
||||
{
|
||||
return swapEndian(in);
|
||||
}
|
||||
}
|
||||
|
||||
inline uint16_t LittleToNative(uint16_t in)
|
||||
{
|
||||
if (littleEndian())
|
||||
return in;
|
||||
else
|
||||
{
|
||||
return swapEndian(in);
|
||||
}
|
||||
}
|
||||
|
||||
inline uint32_t LittleToNative(uint32_t in)
|
||||
{
|
||||
if (littleEndian())
|
||||
return in;
|
||||
else
|
||||
{
|
||||
return swapEndian(in);
|
||||
}
|
||||
}
|
||||
|
||||
inline uint64_t LittleToNative(uint64_t in)
|
||||
{
|
||||
if (littleEndian())
|
||||
return in;
|
||||
else
|
||||
{
|
||||
return swapEndian(in);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
inline uint16_t NativeToBig(uint16_t in)
|
||||
{
|
||||
if (littleEndian())
|
||||
{
|
||||
return swapEndian(in);
|
||||
}
|
||||
else
|
||||
{
|
||||
return in;
|
||||
}
|
||||
}
|
||||
|
||||
inline uint32_t NativeToBig(uint32_t in)
|
||||
{
|
||||
if (littleEndian())
|
||||
{
|
||||
return swapEndian(in);
|
||||
}
|
||||
else
|
||||
{
|
||||
return in;
|
||||
}
|
||||
}
|
||||
|
||||
inline uint64_t NativeToBig(uint64_t in)
|
||||
{
|
||||
if (littleEndian())
|
||||
{
|
||||
return swapEndian(in);
|
||||
}
|
||||
else
|
||||
{
|
||||
return in;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
inline uint16_t BigToNative(uint16_t in)
|
||||
{
|
||||
if (littleEndian())
|
||||
{
|
||||
return swapEndian(in);
|
||||
}
|
||||
else
|
||||
{
|
||||
return in;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
inline uint32_t BigToNative(uint32_t in)
|
||||
{
|
||||
if (littleEndian())
|
||||
{
|
||||
return swapEndian(in);
|
||||
}
|
||||
else
|
||||
{
|
||||
return in;
|
||||
}
|
||||
}
|
||||
|
||||
inline uint64_t BigToNative(uint64_t in)
|
||||
{
|
||||
if (littleEndian())
|
||||
{
|
||||
return swapEndian(in);
|
||||
}
|
||||
else
|
||||
{
|
||||
return in;
|
||||
}
|
||||
}
|
||||
|
||||
#endif //ENDIAN_H_
|
12
src/3rdparty/SHA-3/HashFunction.cpp
vendored
12
src/3rdparty/SHA-3/HashFunction.cpp
vendored
@ -1,12 +0,0 @@
|
||||
#include "stdafx.h"
|
||||
#include "HashFunction.h"
|
||||
|
||||
|
||||
HashFunction::HashFunction(void)
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
HashFunction::~HashFunction(void)
|
||||
{
|
||||
}
|
12
src/3rdparty/SHA-3/HashFunction.h
vendored
12
src/3rdparty/SHA-3/HashFunction.h
vendored
@ -1,12 +0,0 @@
|
||||
#pragma once
|
||||
|
||||
class HashFunction
|
||||
{
|
||||
public:
|
||||
HashFunction(void);
|
||||
virtual ~HashFunction(void);
|
||||
|
||||
virtual void addData(uint8_t input) = 0;
|
||||
virtual void addData(const uint8_t *input, unsigned int off, unsigned int len) = 0;
|
||||
};
|
||||
|
565
src/3rdparty/SHA-3/Keccak.cpp
vendored
565
src/3rdparty/SHA-3/Keccak.cpp
vendored
@ -1,565 +0,0 @@
|
||||
#include "stdafx.h"
|
||||
#include "Keccak.h"
|
||||
|
||||
#include "Endian.h"
|
||||
#include "Rotation.h"
|
||||
|
||||
// Constants of the Keccak algorithm.
|
||||
|
||||
namespace {
|
||||
constexpr uint64_t RC[] = {
|
||||
0x0000000000000001L, 0x0000000000008082L, 0x800000000000808aL,
|
||||
0x8000000080008000L, 0x000000000000808bL, 0x0000000080000001L,
|
||||
0x8000000080008081L, 0x8000000000008009L, 0x000000000000008aL,
|
||||
0x0000000000000088L, 0x0000000080008009L, 0x000000008000000aL,
|
||||
0x000000008000808bL, 0x800000000000008bL, 0x8000000000008089L,
|
||||
0x8000000000008003L, 0x8000000000008002L, 0x8000000000000080L,
|
||||
0x000000000000800aL, 0x800000008000000aL, 0x8000000080008081L,
|
||||
0x8000000000008080L, 0x0000000080000001L, 0x8000000080008008L
|
||||
};
|
||||
|
||||
constexpr int R[] = {
|
||||
0, 1, 62, 28, 27, 36, 44, 6, 55, 20, 3, 10, 43,
|
||||
25, 39, 41, 45, 15, 21, 8, 18, 2, 61, 56, 14
|
||||
};
|
||||
|
||||
constexpr int index(int x)
|
||||
{
|
||||
return x < 0 ? index(x + 5) : x % 5;
|
||||
}
|
||||
|
||||
constexpr int index(int x, int y)
|
||||
{
|
||||
return index(x) + 5 * index(y);
|
||||
}
|
||||
}
|
||||
|
||||
// Function to create the state structure for keccak application, of size length
|
||||
// (where length is the number of bits in the hash)
|
||||
KeccakBase::KeccakBase(unsigned int length_)
|
||||
{
|
||||
A = new uint64_t[25];
|
||||
memset(A, 0, 25*sizeof(uint64_t));
|
||||
blockLen = 200 - 2*(length_/8);
|
||||
buffer = new uint8_t[blockLen];
|
||||
memset(buffer, 0, blockLen*sizeof(uint8_t));
|
||||
bufferLen = 0;
|
||||
length = length_;
|
||||
}
|
||||
|
||||
KeccakBase::KeccakBase(const KeccakBase& other)
|
||||
: blockLen(other.blockLen)
|
||||
, bufferLen(other.bufferLen)
|
||||
, length(other.length)
|
||||
{
|
||||
A = new uint64_t[25];
|
||||
memcpy(A, other.A, 25*sizeof(uint64_t));
|
||||
buffer = new uint8_t[blockLen];
|
||||
memcpy(buffer, other.buffer, blockLen*sizeof(uint8_t));
|
||||
}
|
||||
|
||||
KeccakBase& KeccakBase::operator=(const KeccakBase& other)
|
||||
{
|
||||
if(this != &other)
|
||||
{
|
||||
memcpy(A, other.A, 25*sizeof(uint64_t));
|
||||
if (blockLen != other.blockLen)
|
||||
{
|
||||
blockLen = other.blockLen;
|
||||
delete[] buffer;
|
||||
buffer = new uint8_t[blockLen];
|
||||
length = other.length;
|
||||
}
|
||||
bufferLen = other.bufferLen;
|
||||
memcpy(buffer, other.buffer, blockLen*sizeof(uint8_t));
|
||||
}
|
||||
return *this;
|
||||
}
|
||||
|
||||
Sha3::Sha3(unsigned int len_) : KeccakBase(len_)
|
||||
{};
|
||||
|
||||
Sha3::Sha3(const Sha3& other) : KeccakBase(other)
|
||||
{};
|
||||
|
||||
Sha3& Sha3::operator=(const Sha3& other)
|
||||
{
|
||||
KeccakBase::operator=(other);
|
||||
return *this;
|
||||
}
|
||||
|
||||
Keccak::Keccak(unsigned int len_) : KeccakBase(len_)
|
||||
{};
|
||||
|
||||
Keccak::Keccak(const Keccak& other) : KeccakBase(other)
|
||||
{};
|
||||
|
||||
Keccak& Keccak::operator=(const Keccak& other)
|
||||
{
|
||||
KeccakBase::operator=(other);
|
||||
return *this;
|
||||
}
|
||||
|
||||
// Function to create the state structure for SHAKE application, of size length
|
||||
// (where length is the number of bits in the hash)
|
||||
Shake::Shake(unsigned int length_, unsigned int d_) : KeccakBase(length_)
|
||||
{
|
||||
d = d_;
|
||||
}
|
||||
|
||||
Shake::Shake(const Shake& other) : KeccakBase(other), d(other.d)
|
||||
{
|
||||
}
|
||||
|
||||
Shake& Shake::operator=(const Shake& other)
|
||||
{
|
||||
KeccakBase::operator=(other);
|
||||
d = other.d;
|
||||
return *this;
|
||||
}
|
||||
|
||||
KeccakBase::~KeccakBase()
|
||||
{
|
||||
delete[] A;
|
||||
delete[] buffer;
|
||||
}
|
||||
|
||||
void KeccakBase::reset()
|
||||
{
|
||||
for(unsigned int i = 0 ; i<25 ; i++)
|
||||
{
|
||||
A[i] = 0L;
|
||||
}
|
||||
bufferLen = 0;
|
||||
}
|
||||
|
||||
// keccakUpdate - Functions to pack input data into a block
|
||||
|
||||
// One byte input at a time - process buffer if it's empty
|
||||
void KeccakBase::addData(uint8_t input)
|
||||
{
|
||||
buffer[bufferLen] = input;
|
||||
if(++(bufferLen) == blockLen)
|
||||
{
|
||||
processBuffer();
|
||||
}
|
||||
}
|
||||
|
||||
// Process a larger buffer with varying amounts of data in it
|
||||
void KeccakBase::addData(const uint8_t *input, unsigned int off, unsigned int len)
|
||||
{
|
||||
while (len > 0)
|
||||
{
|
||||
unsigned int cpLen = 0;
|
||||
if((blockLen - bufferLen) > len)
|
||||
{
|
||||
cpLen = len;
|
||||
}
|
||||
else
|
||||
{
|
||||
cpLen = blockLen - bufferLen;
|
||||
}
|
||||
|
||||
for(unsigned int i = 0 ; i!=cpLen ; i++)
|
||||
{
|
||||
buffer[bufferLen+i] = input[off+i];
|
||||
}
|
||||
bufferLen += cpLen;
|
||||
off += cpLen;
|
||||
len -= cpLen;
|
||||
if(bufferLen == blockLen)
|
||||
{
|
||||
processBuffer();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
template <typename T1, typename T2, typename T3>
|
||||
std::vector<unsigned char> digest_generic(uint64_t *A, unsigned int hashLength, T1 paddingFunc, T2 processBufferFunc, T3 resetFunc)
|
||||
{
|
||||
unsigned int lengthInBytes = hashLength / 8;
|
||||
unsigned int lengthInQuads = lengthInBytes / 8;
|
||||
bool rollOverData = false;
|
||||
if (lengthInBytes % 8 != 0)
|
||||
{
|
||||
rollOverData = true;
|
||||
}
|
||||
|
||||
paddingFunc();
|
||||
processBufferFunc();
|
||||
std::vector<unsigned char> tmp;
|
||||
tmp.reserve(lengthInBytes);
|
||||
for (unsigned int i = 0; i < lengthInQuads; i++)
|
||||
{
|
||||
uint64_t b = A[i];
|
||||
for (unsigned int j = 0; j != 8; j++)
|
||||
{
|
||||
tmp.push_back((unsigned char)((b >> (8 * j)) & 0xFF));
|
||||
}
|
||||
}
|
||||
if (rollOverData)
|
||||
{
|
||||
uint64_t b = A[lengthInQuads];
|
||||
for (unsigned int i = 0; i != lengthInBytes % 8; i++)
|
||||
{
|
||||
tmp.push_back((unsigned char)((b >> (8 * i)) & 0xFF));
|
||||
}
|
||||
}
|
||||
|
||||
resetFunc();
|
||||
return tmp;
|
||||
}
|
||||
|
||||
// keccakDigest - called once all data has been few to the keccakUpdate functions
|
||||
// Pads the structure (in case the input is not a multiple of the block length)
|
||||
// returns the hash result in a char vector
|
||||
std::vector<unsigned char> Keccak::digest()
|
||||
{
|
||||
return digest_generic(A, length,
|
||||
[this]() { addPadding(); },
|
||||
[this]() { processBuffer(); },
|
||||
[this]() { reset(); });
|
||||
}
|
||||
|
||||
// sha3Digest - called once all data has been few to the keccakUpdate functions
|
||||
// Pads the structure (in case the input is not a multiple of the block length)
|
||||
// returns the hash result in a char vector
|
||||
std::vector<unsigned char> Sha3::digest()
|
||||
{
|
||||
return digest_generic(A, length,
|
||||
[this]() { addPadding(); },
|
||||
[this]() { processBuffer(); },
|
||||
[this]() { reset(); });
|
||||
}
|
||||
|
||||
// shakeDigest - called once all data has been few to the keccakUpdate functions
|
||||
// Pads the structure (in case the input is not a multiple of the block length)
|
||||
// returns the hash result in a char vector
|
||||
std::vector<unsigned char> Shake::digest()
|
||||
{
|
||||
return digest_generic(A, d,
|
||||
[this]() { addPadding(); },
|
||||
[this]() { processBuffer(); },
|
||||
[this]() { reset(); });
|
||||
}
|
||||
|
||||
void Sha3::addPadding()
|
||||
{
|
||||
if(bufferLen + 1 == blockLen)
|
||||
{
|
||||
buffer[bufferLen] = (uint8_t) 0x86;
|
||||
}
|
||||
else
|
||||
{
|
||||
buffer[bufferLen] = (uint8_t) 0x06;
|
||||
for(unsigned int i = bufferLen + 1 ; i < blockLen - 1 ; i++)
|
||||
{
|
||||
buffer[i] = 0;
|
||||
}
|
||||
buffer[blockLen - 1] = (uint8_t) 0x80;
|
||||
}
|
||||
}
|
||||
|
||||
void Keccak::addPadding()
|
||||
{
|
||||
if(bufferLen + 1 == blockLen)
|
||||
{
|
||||
buffer[bufferLen] = (uint8_t) 0x81;
|
||||
}
|
||||
else
|
||||
{
|
||||
buffer[bufferLen] = (uint8_t) 0x01;
|
||||
for(unsigned int i = bufferLen + 1 ; i < blockLen - 1 ; i++)
|
||||
{
|
||||
buffer[i] = 0;
|
||||
}
|
||||
buffer[blockLen - 1] = (uint8_t) 0x80;
|
||||
}
|
||||
}
|
||||
|
||||
void Shake::addPadding()
|
||||
{
|
||||
|
||||
if (bufferLen + 1 == blockLen)
|
||||
{
|
||||
buffer[bufferLen] = (uint8_t)0x9F;
|
||||
}
|
||||
else
|
||||
{
|
||||
buffer[bufferLen] = (uint8_t)0x1F;
|
||||
for (unsigned int i = bufferLen + 1; i < blockLen - 1; i++)
|
||||
{
|
||||
buffer[i] = 0;
|
||||
}
|
||||
buffer[blockLen - 1] = (uint8_t)0x80;
|
||||
}
|
||||
}
|
||||
|
||||
void KeccakBase::processBuffer()
|
||||
{
|
||||
for(unsigned int i = 0 ; i < blockLen/8 ; i++)
|
||||
{
|
||||
A[i] ^= LittleToNative(((uint64_t*)buffer)[i]);
|
||||
}
|
||||
keccakf();
|
||||
bufferLen = 0;
|
||||
}
|
||||
|
||||
|
||||
|
||||
struct keccakfState
|
||||
{
|
||||
uint64_t B[25];
|
||||
uint64_t C[5];
|
||||
uint64_t D[5];
|
||||
};
|
||||
|
||||
// Hash function proper.
|
||||
void KeccakBase::keccakf()
|
||||
{
|
||||
uint64_t *A_ = A;
|
||||
keccakfState kState;
|
||||
|
||||
|
||||
for(int n = 0 ; n < 24 ; n++)
|
||||
{
|
||||
int x = 0;
|
||||
kState.C[x] = A_[index(x, 0)] ^ A_[index(x, 1)] ^ A_[index(x, 2)] ^ A_[index(x, 3)] ^ A_[index(x, 4)];
|
||||
x = 1;
|
||||
kState.C[x] = A_[index(x, 0)] ^ A_[index(x, 1)] ^ A_[index(x, 2)] ^ A_[index(x, 3)] ^ A_[index(x, 4)];
|
||||
x = 2;
|
||||
kState.C[x] = A_[index(x, 0)] ^ A_[index(x, 1)] ^ A_[index(x, 2)] ^ A_[index(x, 3)] ^ A_[index(x, 4)];
|
||||
x = 3;
|
||||
kState.C[x] = A_[index(x, 0)] ^ A_[index(x, 1)] ^ A_[index(x, 2)] ^ A_[index(x, 3)] ^ A_[index(x, 4)];
|
||||
x = 4;
|
||||
kState.C[x] = A_[index(x, 0)] ^ A_[index(x, 1)] ^ A_[index(x, 2)] ^ A_[index(x, 3)] ^ A_[index(x, 4)];
|
||||
|
||||
int i;
|
||||
x = 0;
|
||||
int y = 0;
|
||||
kState.D[x] = kState.C[index(x - 1)] ^ rotateLeft(kState.C[index(x + 1)], 1);
|
||||
y = 0;
|
||||
A_[index(x, y)] ^= kState.D[x];
|
||||
y = 1;
|
||||
A_[index(x, y)] ^= kState.D[x];
|
||||
y = 2;
|
||||
A_[index(x, y)] ^= kState.D[x];
|
||||
y = 3;
|
||||
A_[index(x, y)] ^= kState.D[x];
|
||||
y = 4;
|
||||
A_[index(x, y)] ^= kState.D[x];
|
||||
x = 1;
|
||||
kState.D[x] = kState.C[index(x - 1)] ^ rotateLeft(kState.C[index(x + 1)], 1);
|
||||
y = 0;
|
||||
A_[index(x, y)] ^= kState.D[x];
|
||||
y = 1;
|
||||
A_[index(x, y)] ^= kState.D[x];
|
||||
y = 2;
|
||||
A_[index(x, y)] ^= kState.D[x];
|
||||
y = 3;
|
||||
A_[index(x, y)] ^= kState.D[x];
|
||||
y = 4;
|
||||
A_[index(x, y)] ^= kState.D[x];
|
||||
x = 2;
|
||||
kState.D[x] = kState.C[index(x - 1)] ^ rotateLeft(kState.C[index(x + 1)], 1);
|
||||
y = 0;
|
||||
A_[index(x, y)] ^= kState.D[x];
|
||||
y = 1;
|
||||
A_[index(x, y)] ^= kState.D[x];
|
||||
y = 2;
|
||||
A_[index(x, y)] ^= kState.D[x];
|
||||
y = 3;
|
||||
A_[index(x, y)] ^= kState.D[x];
|
||||
y = 4;
|
||||
A_[index(x, y)] ^= kState.D[x];
|
||||
x = 3;
|
||||
kState.D[x] = kState.C[index(x - 1)] ^ rotateLeft(kState.C[index(x + 1)], 1);
|
||||
y = 0;
|
||||
A_[index(x, y)] ^= kState.D[x];
|
||||
y = 1;
|
||||
A_[index(x, y)] ^= kState.D[x];
|
||||
y = 2;
|
||||
A_[index(x, y)] ^= kState.D[x];
|
||||
y = 3;
|
||||
A_[index(x, y)] ^= kState.D[x];
|
||||
y = 4;
|
||||
A_[index(x, y)] ^= kState.D[x];
|
||||
x = 4;
|
||||
kState.D[x] = kState.C[index(x - 1)] ^ rotateLeft(kState.C[index(x + 1)], 1);
|
||||
y = 0;
|
||||
A_[index(x, y)] ^= kState.D[x];
|
||||
y = 1;
|
||||
A_[index(x, y)] ^= kState.D[x];
|
||||
y = 2;
|
||||
A_[index(x, y)] ^= kState.D[x];
|
||||
y = 3;
|
||||
A_[index(x, y)] ^= kState.D[x];
|
||||
y = 4;
|
||||
A_[index(x, y)] ^= kState.D[x];
|
||||
|
||||
|
||||
x = 0;
|
||||
y = 0;
|
||||
i = index(x, y);
|
||||
kState.B[index(y, x * 2 + 3 * y)] = rotateLeft(A_[i], R[i]);
|
||||
y = 1;
|
||||
i = index(x, y);
|
||||
kState.B[index(y, x * 2 + 3 * y)] = rotateLeft(A_[i], R[i]);
|
||||
y = 2;
|
||||
i = index(x, y);
|
||||
kState.B[index(y, x * 2 + 3 * y)] = rotateLeft(A_[i], R[i]);
|
||||
y = 3;
|
||||
i = index(x, y);
|
||||
kState.B[index(y, x * 2 + 3 * y)] = rotateLeft(A_[i], R[i]);
|
||||
y = 4;
|
||||
i = index(x, y);
|
||||
kState.B[index(y, x * 2 + 3 * y)] = rotateLeft(A_[i], R[i]);
|
||||
x = 1;
|
||||
y = 0;
|
||||
i = index(x, y);
|
||||
kState.B[index(y, x * 2 + 3 * y)] = rotateLeft(A_[i], R[i]);
|
||||
y = 1;
|
||||
i = index(x, y);
|
||||
kState.B[index(y, x * 2 + 3 * y)] = rotateLeft(A_[i], R[i]);
|
||||
y = 2;
|
||||
i = index(x, y);
|
||||
kState.B[index(y, x * 2 + 3 * y)] = rotateLeft(A_[i], R[i]);
|
||||
y = 3;
|
||||
i = index(x, y);
|
||||
kState.B[index(y, x * 2 + 3 * y)] = rotateLeft(A_[i], R[i]);
|
||||
y = 4;
|
||||
i = index(x, y);
|
||||
kState.B[index(y, x * 2 + 3 * y)] = rotateLeft(A_[i], R[i]);
|
||||
x = 2;
|
||||
y = 0;
|
||||
i = index(x, y);
|
||||
kState.B[index(y, x * 2 + 3 * y)] = rotateLeft(A_[i], R[i]);
|
||||
y = 1;
|
||||
i = index(x, y);
|
||||
kState.B[index(y, x * 2 + 3 * y)] = rotateLeft(A_[i], R[i]);
|
||||
y = 2;
|
||||
i = index(x, y);
|
||||
kState.B[index(y, x * 2 + 3 * y)] = rotateLeft(A_[i], R[i]);
|
||||
y = 3;
|
||||
i = index(x, y);
|
||||
kState.B[index(y, x * 2 + 3 * y)] = rotateLeft(A_[i], R[i]);
|
||||
y = 4;
|
||||
i = index(x, y);
|
||||
kState.B[index(y, x * 2 + 3 * y)] = rotateLeft(A_[i], R[i]);
|
||||
x = 3;
|
||||
y = 0;
|
||||
i = index(x, y);
|
||||
kState.B[index(y, x * 2 + 3 * y)] = rotateLeft(A_[i], R[i]);
|
||||
y = 1;
|
||||
i = index(x, y);
|
||||
kState.B[index(y, x * 2 + 3 * y)] = rotateLeft(A_[i], R[i]);
|
||||
y = 2;
|
||||
i = index(x, y);
|
||||
kState.B[index(y, x * 2 + 3 * y)] = rotateLeft(A_[i], R[i]);
|
||||
y = 3;
|
||||
i = index(x, y);
|
||||
kState.B[index(y, x * 2 + 3 * y)] = rotateLeft(A_[i], R[i]);
|
||||
y = 4;
|
||||
i = index(x, y);
|
||||
kState.B[index(y, x * 2 + 3 * y)] = rotateLeft(A_[i], R[i]);
|
||||
x = 4;
|
||||
y = 0;
|
||||
i = index(x, y);
|
||||
kState.B[index(y, x * 2 + 3 * y)] = rotateLeft(A_[i], R[i]);
|
||||
y = 1;
|
||||
i = index(x, y);
|
||||
kState.B[index(y, x * 2 + 3 * y)] = rotateLeft(A_[i], R[i]);
|
||||
y = 2;
|
||||
i = index(x, y);
|
||||
kState.B[index(y, x * 2 + 3 * y)] = rotateLeft(A_[i], R[i]);
|
||||
y = 3;
|
||||
i = index(x, y);
|
||||
kState.B[index(y, x * 2 + 3 * y)] = rotateLeft(A_[i], R[i]);
|
||||
y = 4;
|
||||
i = index(x, y);
|
||||
kState.B[index(y, x * 2 + 3 * y)] = rotateLeft(A_[i], R[i]);
|
||||
|
||||
x = 0;
|
||||
y = 0;
|
||||
i = index(x, y);
|
||||
A_[i] = kState.B[i] ^ (~kState.B[index(x + 1, y)] & kState.B[index(x + 2, y)]);
|
||||
y = 1;
|
||||
i = index(x, y);
|
||||
A_[i] = kState.B[i] ^ (~kState.B[index(x + 1, y)] & kState.B[index(x + 2, y)]);
|
||||
y = 2;
|
||||
i = index(x, y);
|
||||
A_[i] = kState.B[i] ^ (~kState.B[index(x + 1, y)] & kState.B[index(x + 2, y)]);
|
||||
y = 3;
|
||||
i = index(x, y);
|
||||
A_[i] = kState.B[i] ^ (~kState.B[index(x + 1, y)] & kState.B[index(x + 2, y)]);
|
||||
y = 4;
|
||||
i = index(x, y);
|
||||
A_[i] = kState.B[i] ^ (~kState.B[index(x + 1, y)] & kState.B[index(x + 2, y)]);
|
||||
x = 1;
|
||||
y = 0;
|
||||
i = index(x, y);
|
||||
A_[i] = kState.B[i] ^ (~kState.B[index(x + 1, y)] & kState.B[index(x + 2, y)]);
|
||||
y = 1;
|
||||
i = index(x, y);
|
||||
A_[i] = kState.B[i] ^ (~kState.B[index(x + 1, y)] & kState.B[index(x + 2, y)]);
|
||||
y = 2;
|
||||
i = index(x, y);
|
||||
A_[i] = kState.B[i] ^ (~kState.B[index(x + 1, y)] & kState.B[index(x + 2, y)]);
|
||||
y = 3;
|
||||
i = index(x, y);
|
||||
A_[i] = kState.B[i] ^ (~kState.B[index(x + 1, y)] & kState.B[index(x + 2, y)]);
|
||||
y = 4;
|
||||
i = index(x, y);
|
||||
A_[i] = kState.B[i] ^ (~kState.B[index(x + 1, y)] & kState.B[index(x + 2, y)]);
|
||||
x = 2;
|
||||
y = 0;
|
||||
i = index(x, y);
|
||||
A_[i] = kState.B[i] ^ (~kState.B[index(x + 1, y)] & kState.B[index(x + 2, y)]);
|
||||
y = 1;
|
||||
i = index(x, y);
|
||||
A_[i] = kState.B[i] ^ (~kState.B[index(x + 1, y)] & kState.B[index(x + 2, y)]);
|
||||
y = 2;
|
||||
i = index(x, y);
|
||||
A_[i] = kState.B[i] ^ (~kState.B[index(x + 1, y)] & kState.B[index(x + 2, y)]);
|
||||
y = 3;
|
||||
i = index(x, y);
|
||||
A_[i] = kState.B[i] ^ (~kState.B[index(x + 1, y)] & kState.B[index(x + 2, y)]);
|
||||
y = 4;
|
||||
i = index(x, y);
|
||||
A_[i] = kState.B[i] ^ (~kState.B[index(x + 1, y)] & kState.B[index(x + 2, y)]);
|
||||
x = 3;
|
||||
y = 0;
|
||||
i = index(x, y);
|
||||
A_[i] = kState.B[i] ^ (~kState.B[index(x + 1, y)] & kState.B[index(x + 2, y)]);
|
||||
y = 1;
|
||||
i = index(x, y);
|
||||
A_[i] = kState.B[i] ^ (~kState.B[index(x + 1, y)] & kState.B[index(x + 2, y)]);
|
||||
y = 2;
|
||||
i = index(x, y);
|
||||
A_[i] = kState.B[i] ^ (~kState.B[index(x + 1, y)] & kState.B[index(x + 2, y)]);
|
||||
y = 3;
|
||||
i = index(x, y);
|
||||
A_[i] = kState.B[i] ^ (~kState.B[index(x + 1, y)] & kState.B[index(x + 2, y)]);
|
||||
y = 4;
|
||||
i = index(x, y);
|
||||
A_[i] = kState.B[i] ^ (~kState.B[index(x + 1, y)] & kState.B[index(x + 2, y)]);
|
||||
x = 4;
|
||||
y = 0;
|
||||
i = index(x, y);
|
||||
A_[i] = kState.B[i] ^ (~kState.B[index(x + 1, y)] & kState.B[index(x + 2, y)]);
|
||||
y = 1;
|
||||
i = index(x, y);
|
||||
A_[i] = kState.B[i] ^ (~kState.B[index(x + 1, y)] & kState.B[index(x + 2, y)]);
|
||||
y = 2;
|
||||
i = index(x, y);
|
||||
A_[i] = kState.B[i] ^ (~kState.B[index(x + 1, y)] & kState.B[index(x + 2, y)]);
|
||||
y = 3;
|
||||
i = index(x, y);
|
||||
A_[i] = kState.B[i] ^ (~kState.B[index(x + 1, y)] & kState.B[index(x + 2, y)]);
|
||||
y = 4;
|
||||
i = index(x, y);
|
||||
A_[i] = kState.B[i] ^ (~kState.B[index(x + 1, y)] & kState.B[index(x + 2, y)]);
|
||||
|
||||
A_[0] ^= RC[n];
|
||||
}
|
||||
}
|
61
src/3rdparty/SHA-3/Keccak.h
vendored
61
src/3rdparty/SHA-3/Keccak.h
vendored
@ -1,61 +0,0 @@
|
||||
#pragma once
|
||||
|
||||
#include "stdafx.h"
|
||||
#include "HashFunction.h"
|
||||
|
||||
// State structure
|
||||
class KeccakBase : public HashFunction
|
||||
{
|
||||
public:
|
||||
KeccakBase(unsigned int len);
|
||||
KeccakBase(const KeccakBase& other);
|
||||
virtual ~KeccakBase();
|
||||
KeccakBase& operator=(const KeccakBase& other);
|
||||
virtual std::vector<unsigned char> digest() = 0;
|
||||
virtual void addPadding() = 0;
|
||||
void reset();
|
||||
void keccakf();
|
||||
void addData(uint8_t input) override;
|
||||
void addData(const uint8_t *input, unsigned int off, unsigned int len) override;
|
||||
void processBuffer();
|
||||
protected:
|
||||
uint64_t *A;
|
||||
unsigned int blockLen;
|
||||
uint8_t *buffer;
|
||||
unsigned int bufferLen;
|
||||
unsigned int length;
|
||||
};
|
||||
|
||||
class Sha3 : public KeccakBase
|
||||
{
|
||||
public:
|
||||
Sha3(unsigned int len);
|
||||
Sha3(const Sha3& other);
|
||||
Sha3& operator=(const Sha3& other);
|
||||
std::vector<unsigned char> digest() override;
|
||||
void addPadding() override;
|
||||
private:
|
||||
};
|
||||
|
||||
class Keccak : public KeccakBase
|
||||
{
|
||||
public:
|
||||
Keccak(unsigned int len);
|
||||
Keccak(const Keccak& other);
|
||||
Keccak& operator=(const Keccak& other);
|
||||
std::vector<unsigned char> digest() override;
|
||||
void addPadding() override;
|
||||
private:
|
||||
};
|
||||
|
||||
class Shake : public KeccakBase
|
||||
{
|
||||
public:
|
||||
Shake(unsigned int len, unsigned int d_);
|
||||
Shake(const Shake& other);
|
||||
Shake& operator=(const Shake& other);
|
||||
std::vector<unsigned char> digest() override;
|
||||
void addPadding() override;
|
||||
private:
|
||||
unsigned int d;
|
||||
};
|
28
src/3rdparty/SHA-3/Rotation.h
vendored
28
src/3rdparty/SHA-3/Rotation.h
vendored
@ -1,28 +0,0 @@
|
||||
#ifndef ROTATION_H_
|
||||
#define ROTATION_H_
|
||||
|
||||
#include <cstdint>
|
||||
|
||||
// As we're not using assembly, we can't use the native rotation instructions
|
||||
// replace it with a small inline
|
||||
static inline uint64_t rotateLeft(uint64_t x, int n)
|
||||
{
|
||||
const unsigned int mask = (8*sizeof(x) - 1); // assumes width is a power of 2.
|
||||
|
||||
// assert ( (c<=mask) &&"rotate by type width or more");
|
||||
n &= mask;
|
||||
return (x << n) | (x >> ((-n)&mask));
|
||||
}
|
||||
|
||||
static inline uint64_t rotateRight(uint64_t x, int n)
|
||||
{
|
||||
const unsigned int mask = (8 * sizeof(x) - 1); // assumes width is a power of 2.
|
||||
|
||||
// assert ( (c<=mask) &&"rotate by type width or more");
|
||||
n &= mask;
|
||||
return (x >> n) | (x << ((-n)&mask));
|
||||
|
||||
}
|
||||
|
||||
#endif //ROTATION_H_
|
||||
|
11
src/3rdparty/SHA-3/license.txt
vendored
11
src/3rdparty/SHA-3/license.txt
vendored
@ -1,11 +0,0 @@
|
||||
Copyright 2017 Daniel Horne
|
||||
|
||||
Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
|
||||
|
||||
1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
|
||||
|
||||
2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
|
||||
|
||||
3. Neither the name of the copyright holder nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.
|
||||
|
||||
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
15
src/3rdparty/SHA-3/qt_attribution.json
vendored
15
src/3rdparty/SHA-3/qt_attribution.json
vendored
@ -1,15 +0,0 @@
|
||||
[
|
||||
{
|
||||
"Id": "SHA-3",
|
||||
"Name": "Secure Hash Algorithm SHA-3",
|
||||
"QDocModule": "qtcore",
|
||||
"QtUsage": "Used in Qt Core (QCryptographicHash).",
|
||||
"Homepage": "https://github.com/DuSTman31/SHA-3",
|
||||
"Description": "SHA-3, originally known as Keccak, is a cryptographic hash function.",
|
||||
"Version": "0bf9b8f4b22504202c22866458b7f6ba5445a41f",
|
||||
"License": "BSD 3-Clause \"New\" or \"Revised\" License",
|
||||
"LicenseId": "BSD-3-Clause",
|
||||
"LicenseFile": "license.txt",
|
||||
"Copyright": "Copyright 2017 Daniel Horne."
|
||||
}
|
||||
]
|
22
src/3rdparty/SHA-3/stdafx.h
vendored
22
src/3rdparty/SHA-3/stdafx.h
vendored
@ -1,22 +0,0 @@
|
||||
// stdafx.h : include file for standard system include files,
|
||||
// or project specific include files that are used frequently, but
|
||||
// are changed infrequently
|
||||
//
|
||||
|
||||
#pragma once
|
||||
|
||||
#ifdef _MSC_VER
|
||||
#include "targetver.h"
|
||||
#endif //_MSC_VER
|
||||
|
||||
#include <cstdio>
|
||||
#include <cstdint>
|
||||
#include <cstring>
|
||||
|
||||
#include <vector>
|
||||
#include <array>
|
||||
|
||||
#include <iostream>
|
||||
#include <sstream>
|
||||
|
||||
// TODO: reference additional headers your program requires here
|
Loading…
Reference in New Issue
Block a user