mirror of
https://bitbucket.org/smil3y/katie.git
synced 2025-02-23 18:32:55 +00:00
make OpenSSL required
This commit is contained in:
parent
5e4c0c0ad2
commit
a4c82a4316
65 changed files with 84 additions and 6565 deletions
|
@ -57,12 +57,6 @@ katie_setup_paths()
|
|||
option(WITH_THREADS "Build threads support" ON)
|
||||
add_feature_info(threads WITH_THREADS "an open source something")
|
||||
|
||||
option(WITH_OPENSSL "Build openssl support" ON)
|
||||
add_feature_info(openssl WITH_OPENSSL "an open source something")
|
||||
|
||||
option(WITH_ZLIB "Build zlib support" ON)
|
||||
add_feature_info(zlib WITH_ZLIB "an open source something")
|
||||
|
||||
option(WITH_NIS "Build nis support" ON)
|
||||
add_feature_info(nis WITH_NIS "an open source something")
|
||||
|
||||
|
@ -246,19 +240,19 @@ set_package_properties(ZLIB PROPERTIES
|
|||
TYPE REQUIRED
|
||||
)
|
||||
|
||||
find_package(PythonInterp)
|
||||
set_package_properties(PythonInterp PROPERTIES
|
||||
PURPOSE "UI class maps generator script"
|
||||
DESCRIPTION "Programming language that lets you work quickly"
|
||||
URL "https://www.python.org/"
|
||||
TYPE RECOMMENDED
|
||||
)
|
||||
|
||||
find_package(OpenSSL)
|
||||
set_package_properties(OpenSSL PROPERTIES
|
||||
PURPOSE "Required for HTTPS support"
|
||||
DESCRIPTION "Support for secure network communications (SSL and TLS)"
|
||||
URL "http://openssl.org"
|
||||
TYPE REQUIRED
|
||||
)
|
||||
|
||||
find_package(PythonInterp)
|
||||
set_package_properties(PythonInterp PROPERTIES
|
||||
PURPOSE "UI class maps generator script"
|
||||
DESCRIPTION "Programming language that lets you work quickly"
|
||||
URL "https://www.python.org/"
|
||||
TYPE RECOMMENDED
|
||||
)
|
||||
|
||||
|
@ -496,10 +490,6 @@ if(NOT WITH_EGL OR NOT EGL_FOUND)
|
|||
katie_definition(-DQT_NO_EGL)
|
||||
endif()
|
||||
|
||||
if(NOT WITH_OPENSSL OR NOT OPENSSL_FOUND)
|
||||
katie_definition(-DQT_NO_OPENSSL)
|
||||
endif()
|
||||
|
||||
if(NOT WITH_FREETYPE OR NOT FREETYPE_FOUND)
|
||||
set(WITH_FONTCONFIG OFF)
|
||||
katie_definition(-DQT_NO_FREETYPE)
|
||||
|
|
1
README
1
README
|
@ -41,7 +41,6 @@ There are several things you should be aware before considering Katie:
|
|||
- building with LTO is possible and supported, if the toolchain can handle it
|
||||
- alternative libc implementations support
|
||||
- support for generating SHA-224, SHA-256, SHA-384, SHA-512 hash sums (SHA-2)
|
||||
- support for generating SHA3-224, SHA3-256, SHA3-384, SHA3-512 hash sums
|
||||
- desktop files, Shell profile and dynamic linker/loader config are installed
|
||||
to ease vendors and deployment in general
|
||||
|
||||
|
|
265
src/3rdparty/md4/md4.cpp
vendored
265
src/3rdparty/md4/md4.cpp
vendored
|
@ -1,265 +0,0 @@
|
|||
/*
|
||||
* MD4 (RFC-1320) message digest.
|
||||
* Modified from MD5 code by Andrey Panin <pazke@donpac.ru>
|
||||
*
|
||||
* Written by Solar Designer <solar@openwall.com> in 2001, and placed in
|
||||
* the public domain. There's absolutely no warranty.
|
||||
*
|
||||
* This differs from Colin Plumb's older public domain implementation in
|
||||
* that no 32-bit integer data type is required, there's no compile-time
|
||||
* endianness configuration, and the function prototypes match OpenSSL's.
|
||||
* The primary goals are portability and ease of use.
|
||||
*
|
||||
* This implementation is meant to be fast, but not as fast as possible.
|
||||
* Some known optimizations are not included to reduce source code size
|
||||
* and avoid compile-time configuration.
|
||||
*/
|
||||
|
||||
#include "md4.h"
|
||||
|
||||
#include <string.h>
|
||||
|
||||
QT_BEGIN_NAMESPACE
|
||||
|
||||
/*
|
||||
* The basic MD4 functions.
|
||||
*/
|
||||
#define F(x, y, z) ((z) ^ ((x) & ((y) ^ (z))))
|
||||
#define G(x, y, z) (((x) & (y)) | ((x) & (z)) | ((y) & (z)))
|
||||
#define H(x, y, z) ((x) ^ (y) ^ (z))
|
||||
|
||||
/*
|
||||
* The MD4 transformation for all four rounds.
|
||||
*/
|
||||
#define STEP(f, a, b, c, d, x, s) \
|
||||
(a) += f((b), (c), (d)) + (x); \
|
||||
(a) = ((a) << (s)) | ((a) >> (32 - (s)))
|
||||
|
||||
|
||||
/*
|
||||
* SET reads 4 input bytes in little-endian byte order and stores them
|
||||
* in a properly aligned word in host byte order.
|
||||
*
|
||||
* The check for little-endian architectures which tolerate unaligned
|
||||
* memory accesses is just an optimization. Nothing will break if it
|
||||
* doesn't work.
|
||||
*/
|
||||
#if defined(__i386__) || defined(__x86_64__)
|
||||
#define SET(n) \
|
||||
(*(const quint32 *)&ptr[(n) * 4])
|
||||
#define GET(n) \
|
||||
SET(n)
|
||||
#else
|
||||
#define SET(n) \
|
||||
(ctx->block[(n)] = \
|
||||
(quint32)ptr[(n) * 4] | \
|
||||
((quint32)ptr[(n) * 4 + 1] << 8) | \
|
||||
((quint32)ptr[(n) * 4 + 2] << 16) | \
|
||||
((quint32)ptr[(n) * 4 + 3] << 24))
|
||||
#define GET(n) \
|
||||
(ctx->block[(n)])
|
||||
#endif
|
||||
|
||||
/*
|
||||
* This processes one or more 64-byte data blocks, but does NOT update
|
||||
* the bit counters. There're no alignment requirements.
|
||||
*/
|
||||
static const unsigned char *body(struct md4_context *ctx, const unsigned char *data, size_t size)
|
||||
{
|
||||
const unsigned char *ptr;
|
||||
quint32 a, b, c, d;
|
||||
quint32 saved_a, saved_b, saved_c, saved_d;
|
||||
|
||||
ptr = data;
|
||||
|
||||
a = ctx->a;
|
||||
b = ctx->b;
|
||||
c = ctx->c;
|
||||
d = ctx->d;
|
||||
|
||||
do {
|
||||
saved_a = a;
|
||||
saved_b = b;
|
||||
saved_c = c;
|
||||
saved_d = d;
|
||||
|
||||
/* Round 1 */
|
||||
STEP(F, a, b, c, d, SET( 0), 3);
|
||||
STEP(F, d, a, b, c, SET( 1), 7);
|
||||
STEP(F, c, d, a, b, SET( 2), 11);
|
||||
STEP(F, b, c, d, a, SET( 3), 19);
|
||||
|
||||
STEP(F, a, b, c, d, SET( 4), 3);
|
||||
STEP(F, d, a, b, c, SET( 5), 7);
|
||||
STEP(F, c, d, a, b, SET( 6), 11);
|
||||
STEP(F, b, c, d, a, SET( 7), 19);
|
||||
|
||||
STEP(F, a, b, c, d, SET( 8), 3);
|
||||
STEP(F, d, a, b, c, SET( 9), 7);
|
||||
STEP(F, c, d, a, b, SET(10), 11);
|
||||
STEP(F, b, c, d, a, SET(11), 19);
|
||||
|
||||
STEP(F, a, b, c, d, SET(12), 3);
|
||||
STEP(F, d, a, b, c, SET(13), 7);
|
||||
STEP(F, c, d, a, b, SET(14), 11);
|
||||
STEP(F, b, c, d, a, SET(15), 19);
|
||||
/* Round 2 */
|
||||
STEP(G, a, b, c, d, GET( 0) + 0x5A827999, 3);
|
||||
STEP(G, d, a, b, c, GET( 4) + 0x5A827999, 5);
|
||||
STEP(G, c, d, a, b, GET( 8) + 0x5A827999, 9);
|
||||
STEP(G, b, c, d, a, GET(12) + 0x5A827999, 13);
|
||||
|
||||
STEP(G, a, b, c, d, GET( 1) + 0x5A827999, 3);
|
||||
STEP(G, d, a, b, c, GET( 5) + 0x5A827999, 5);
|
||||
STEP(G, c, d, a, b, GET( 9) + 0x5A827999, 9);
|
||||
STEP(G, b, c, d, a, GET(13) + 0x5A827999, 13);
|
||||
|
||||
STEP(G, a, b, c, d, GET( 2) + 0x5A827999, 3);
|
||||
STEP(G, d, a, b, c, GET( 6) + 0x5A827999, 5);
|
||||
STEP(G, c, d, a, b, GET(10) + 0x5A827999, 9);
|
||||
STEP(G, b, c, d, a, GET(14) + 0x5A827999, 13);
|
||||
|
||||
STEP(G, a, b, c, d, GET( 3) + 0x5A827999, 3);
|
||||
STEP(G, d, a, b, c, GET( 7) + 0x5A827999, 5);
|
||||
STEP(G, c, d, a, b, GET(11) + 0x5A827999, 9);
|
||||
STEP(G, b, c, d, a, GET(15) + 0x5A827999, 13);
|
||||
/* Round 3 */
|
||||
STEP(H, a, b, c, d, GET( 0) + 0x6ED9EBA1, 3);
|
||||
STEP(H, d, a, b, c, GET( 8) + 0x6ED9EBA1, 9);
|
||||
STEP(H, c, d, a, b, GET( 4) + 0x6ED9EBA1, 11);
|
||||
STEP(H, b, c, d, a, GET(12) + 0x6ED9EBA1, 15);
|
||||
|
||||
STEP(H, a, b, c, d, GET( 2) + 0x6ED9EBA1, 3);
|
||||
STEP(H, d, a, b, c, GET(10) + 0x6ED9EBA1, 9);
|
||||
STEP(H, c, d, a, b, GET( 6) + 0x6ED9EBA1, 11);
|
||||
STEP(H, b, c, d, a, GET(14) + 0x6ED9EBA1, 15);
|
||||
|
||||
STEP(H, a, b, c, d, GET( 1) + 0x6ED9EBA1, 3);
|
||||
STEP(H, d, a, b, c, GET( 9) + 0x6ED9EBA1, 9);
|
||||
STEP(H, c, d, a, b, GET( 5) + 0x6ED9EBA1, 11);
|
||||
STEP(H, b, c, d, a, GET(13) + 0x6ED9EBA1, 15);
|
||||
|
||||
STEP(H, a, b, c, d, GET( 3) + 0x6ED9EBA1, 3);
|
||||
STEP(H, d, a, b, c, GET(11) + 0x6ED9EBA1, 9);
|
||||
STEP(H, c, d, a, b, GET( 7) + 0x6ED9EBA1, 11);
|
||||
STEP(H, b, c, d, a, GET(15) + 0x6ED9EBA1, 15);
|
||||
|
||||
a += saved_a;
|
||||
b += saved_b;
|
||||
c += saved_c;
|
||||
d += saved_d;
|
||||
|
||||
ptr += 64;
|
||||
} while (size -= 64);
|
||||
|
||||
ctx->a = a;
|
||||
ctx->b = b;
|
||||
ctx->c = c;
|
||||
ctx->d = d;
|
||||
|
||||
return ptr;
|
||||
}
|
||||
|
||||
static void md4_init(struct md4_context *ctx)
|
||||
{
|
||||
ctx->a = 0x67452301;
|
||||
ctx->b = 0xefcdab89;
|
||||
ctx->c = 0x98badcfe;
|
||||
ctx->d = 0x10325476;
|
||||
|
||||
ctx->lo = 0;
|
||||
ctx->hi = 0;
|
||||
}
|
||||
|
||||
static void md4_update(struct md4_context *ctx, const unsigned char *data, size_t size)
|
||||
{
|
||||
/* @UNSAFE */
|
||||
quint32 saved_lo;
|
||||
unsigned long used, free;
|
||||
|
||||
saved_lo = ctx->lo;
|
||||
if ((ctx->lo = (saved_lo + size) & 0x1fffffff) < saved_lo)
|
||||
ctx->hi++;
|
||||
ctx->hi += size >> 29;
|
||||
|
||||
used = saved_lo & 0x3f;
|
||||
|
||||
if (used) {
|
||||
free = 64 - used;
|
||||
|
||||
if (size < free) {
|
||||
memcpy(&ctx->buffer[used], data, size);
|
||||
return;
|
||||
}
|
||||
|
||||
memcpy(&ctx->buffer[used], data, free);
|
||||
data = (const unsigned char *) data + free;
|
||||
size -= free;
|
||||
body(ctx, ctx->buffer, 64);
|
||||
}
|
||||
|
||||
if (size >= 64) {
|
||||
data = body(ctx, data, size & ~(unsigned long)0x3f);
|
||||
size &= 0x3f;
|
||||
}
|
||||
|
||||
memcpy(ctx->buffer, data, size);
|
||||
}
|
||||
|
||||
static void md4_final(struct md4_context *ctx, unsigned char result[MD4_RESULTLEN])
|
||||
{
|
||||
/* @UNSAFE */
|
||||
unsigned long used, free;
|
||||
|
||||
used = ctx->lo & 0x3f;
|
||||
|
||||
ctx->buffer[used++] = 0x80;
|
||||
|
||||
free = 64 - used;
|
||||
|
||||
if (free < 8) {
|
||||
memset(&ctx->buffer[used], 0, free);
|
||||
body(ctx, ctx->buffer, 64);
|
||||
used = 0;
|
||||
free = 64;
|
||||
}
|
||||
|
||||
memset(&ctx->buffer[used], 0, free - 8);
|
||||
|
||||
ctx->lo <<= 3;
|
||||
ctx->buffer[56] = ctx->lo;
|
||||
ctx->buffer[57] = ctx->lo >> 8;
|
||||
ctx->buffer[58] = ctx->lo >> 16;
|
||||
ctx->buffer[59] = ctx->lo >> 24;
|
||||
ctx->buffer[60] = ctx->hi;
|
||||
ctx->buffer[61] = ctx->hi >> 8;
|
||||
ctx->buffer[62] = ctx->hi >> 16;
|
||||
ctx->buffer[63] = ctx->hi >> 24;
|
||||
|
||||
body(ctx, ctx->buffer, 64);
|
||||
|
||||
result[0] = ctx->a;
|
||||
result[1] = ctx->a >> 8;
|
||||
result[2] = ctx->a >> 16;
|
||||
result[3] = ctx->a >> 24;
|
||||
result[4] = ctx->b;
|
||||
result[5] = ctx->b >> 8;
|
||||
result[6] = ctx->b >> 16;
|
||||
result[7] = ctx->b >> 24;
|
||||
result[8] = ctx->c;
|
||||
result[9] = ctx->c >> 8;
|
||||
result[10] = ctx->c >> 16;
|
||||
result[11] = ctx->c >> 24;
|
||||
result[12] = ctx->d;
|
||||
result[13] = ctx->d >> 8;
|
||||
result[14] = ctx->d >> 16;
|
||||
result[15] = ctx->d >> 24;
|
||||
|
||||
memset(ctx, 0, sizeof(*ctx));
|
||||
}
|
||||
|
||||
#undef F
|
||||
#undef G
|
||||
#undef H
|
||||
|
||||
QT_END_NAMESPACE
|
31
src/3rdparty/md4/md4.h
vendored
31
src/3rdparty/md4/md4.h
vendored
|
@ -1,31 +0,0 @@
|
|||
/*
|
||||
* This is an OpenSSL-compatible implementation of the RSA Data Security,
|
||||
* Inc. MD4 Message-Digest Algorithm.
|
||||
*
|
||||
* Written by Solar Designer <solar@openwall.com> in 2001, and placed in
|
||||
* the public domain. See md4.c for more information.
|
||||
*/
|
||||
|
||||
#ifndef __MD4_H
|
||||
#define __MD4_H
|
||||
|
||||
#include <qglobal.h>
|
||||
|
||||
QT_BEGIN_NAMESPACE
|
||||
|
||||
#define MD4_RESULTLEN (128/8)
|
||||
|
||||
struct md4_context {
|
||||
quint32 lo, hi;
|
||||
quint32 a, b, c, d;
|
||||
unsigned char buffer[64];
|
||||
quint32 block[MD4_RESULTLEN];
|
||||
};
|
||||
|
||||
static void md4_init(struct md4_context *ctx);
|
||||
static void md4_update(struct md4_context *ctx, const unsigned char *data, size_t size);
|
||||
static void md4_final(struct md4_context *ctx, unsigned char result[MD4_RESULTLEN]);
|
||||
|
||||
QT_END_NAMESPACE
|
||||
|
||||
#endif
|
247
src/3rdparty/md5/md5.cpp
vendored
247
src/3rdparty/md5/md5.cpp
vendored
|
@ -1,247 +0,0 @@
|
|||
/*
|
||||
* This code implements the MD5 message-digest algorithm.
|
||||
* The algorithm is due to Ron Rivest. This code was
|
||||
* written by Colin Plumb in 1993, no copyright is claimed.
|
||||
* This code is in the public domain; do with it what you wish.
|
||||
*
|
||||
* Equivalent code is available from RSA Data Security, Inc.
|
||||
* This code has been tested against that, and is equivalent,
|
||||
* except that you don't need to include two pages of legalese
|
||||
* with every copy.
|
||||
*
|
||||
* To compute the message digest of a chunk of bytes, declare an
|
||||
* MD5Context structure, pass it to MD5Init, call MD5Update as
|
||||
* needed on buffers full of bytes, and then call MD5Final, which
|
||||
* will fill a supplied 16-byte array with the digest.
|
||||
*
|
||||
* Changed so as no longer to depend on Colin Plumb's `usual.h' header
|
||||
* definitions; now uses stuff from dpkg's config.h.
|
||||
* - Ian Jackson <ian@chiark.greenend.org.uk>.
|
||||
* Still in the public domain.
|
||||
*/
|
||||
|
||||
#include <string.h> /* for memcpy() */
|
||||
#ifndef _WIN32_WCE
|
||||
#include <sys/types.h> /* for stupid systems */
|
||||
#else
|
||||
#include <windef.h>
|
||||
#include <types.h>
|
||||
#endif
|
||||
|
||||
#include "md5.h"
|
||||
|
||||
QT_BEGIN_NAMESPACE
|
||||
|
||||
static void
|
||||
byteSwap(UWORD32 *buf, unsigned words)
|
||||
{
|
||||
const quint32 byteOrderTest = 0x1;
|
||||
if (((char *)&byteOrderTest)[0] == 0) {
|
||||
md5byte *p = (md5byte *)buf;
|
||||
|
||||
do {
|
||||
*buf++ = (UWORD32)((unsigned)p[3] << 8 | p[2]) << 16 |
|
||||
((unsigned)p[1] << 8 | p[0]);
|
||||
p += 4;
|
||||
} while (--words);
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* Start MD5 accumulation. Set bit count to 0 and buffer to mysterious
|
||||
* initialization constants.
|
||||
*/
|
||||
static void
|
||||
MD5Init(struct MD5Context *ctx)
|
||||
{
|
||||
ctx->buf[0] = 0x67452301;
|
||||
ctx->buf[1] = 0xefcdab89;
|
||||
ctx->buf[2] = 0x98badcfe;
|
||||
ctx->buf[3] = 0x10325476;
|
||||
|
||||
ctx->bytes[0] = 0;
|
||||
ctx->bytes[1] = 0;
|
||||
}
|
||||
|
||||
/*
|
||||
* Update context to reflect the concatenation of another buffer full
|
||||
* of bytes.
|
||||
*/
|
||||
static void
|
||||
MD5Update(struct MD5Context *ctx, md5byte const *buf, unsigned len)
|
||||
{
|
||||
UWORD32 t;
|
||||
|
||||
/* Update byte count */
|
||||
|
||||
t = ctx->bytes[0];
|
||||
if ((ctx->bytes[0] = t + len) < t)
|
||||
ctx->bytes[1]++; /* Carry from low to high */
|
||||
|
||||
t = 64 - (t & 0x3f); /* Space available in ctx->in (at least 1) */
|
||||
if (t > len) {
|
||||
memcpy((md5byte *)ctx->in + 64 - t, buf, len);
|
||||
return;
|
||||
}
|
||||
/* First chunk is an odd size */
|
||||
memcpy((md5byte *)ctx->in + 64 - t, buf, t);
|
||||
byteSwap(ctx->in, 16);
|
||||
MD5Transform(ctx->buf, ctx->in);
|
||||
buf += t;
|
||||
len -= t;
|
||||
|
||||
/* Process data in 64-byte chunks */
|
||||
while (len >= 64) {
|
||||
memcpy(ctx->in, buf, 64);
|
||||
byteSwap(ctx->in, 16);
|
||||
MD5Transform(ctx->buf, ctx->in);
|
||||
buf += 64;
|
||||
len -= 64;
|
||||
}
|
||||
|
||||
/* Handle any remaining bytes of data. */
|
||||
memcpy(ctx->in, buf, len);
|
||||
}
|
||||
|
||||
/*
|
||||
* Final wrapup - pad to 64-byte boundary with the bit pattern
|
||||
* 1 0* (64-bit count of bits processed, MSB-first)
|
||||
*/
|
||||
static void
|
||||
MD5Final(struct MD5Context *ctx, md5byte digest[16])
|
||||
{
|
||||
int count = ctx->bytes[0] & 0x3f; /* Number of bytes in ctx->in */
|
||||
md5byte *p = (md5byte *)ctx->in + count;
|
||||
|
||||
/* Set the first char of padding to 0x80. There is always room. */
|
||||
*p++ = 0x80;
|
||||
|
||||
/* Bytes of padding needed to make 56 bytes (-8..55) */
|
||||
count = 56 - 1 - count;
|
||||
|
||||
if (count < 0) { /* Padding forces an extra block */
|
||||
memset(p, 0, count + 8);
|
||||
byteSwap(ctx->in, 16);
|
||||
MD5Transform(ctx->buf, ctx->in);
|
||||
p = (md5byte *)ctx->in;
|
||||
count = 56;
|
||||
}
|
||||
memset(p, 0, count);
|
||||
byteSwap(ctx->in, 14);
|
||||
|
||||
/* Append length in bits and transform */
|
||||
ctx->in[14] = ctx->bytes[0] << 3;
|
||||
ctx->in[15] = ctx->bytes[1] << 3 | ctx->bytes[0] >> 29;
|
||||
MD5Transform(ctx->buf, ctx->in);
|
||||
|
||||
byteSwap(ctx->buf, 4);
|
||||
memcpy(digest, ctx->buf, 16);
|
||||
memset(ctx, 0, sizeof(*ctx)); /* In case it's sensitive */
|
||||
}
|
||||
|
||||
#ifndef ASM_MD5
|
||||
|
||||
/* The four core functions - F1 is optimized somewhat */
|
||||
|
||||
/* #define F1(x, y, z) (x & y | ~x & z) */
|
||||
#define F1(x, y, z) (z ^ (x & (y ^ z)))
|
||||
#define F2(x, y, z) F1(z, x, y)
|
||||
#define F3(x, y, z) (x ^ y ^ z)
|
||||
#define F4(x, y, z) (y ^ (x | ~z))
|
||||
|
||||
/* This is the central step in the MD5 algorithm. */
|
||||
#define MD5STEP(f,w,x,y,z,in,s) \
|
||||
(w += f(x,y,z) + in, w = (w<<s | w>>(32-s)) + x)
|
||||
|
||||
/*
|
||||
* The core of the MD5 algorithm, this alters an existing MD5 hash to
|
||||
* reflect the addition of 16 longwords of new data. MD5Update blocks
|
||||
* the data and converts bytes into longwords for this routine.
|
||||
*/
|
||||
static void
|
||||
MD5Transform(UWORD32 buf[4], UWORD32 const in[16])
|
||||
{
|
||||
UWORD32 a, b, c, d;
|
||||
|
||||
a = buf[0];
|
||||
b = buf[1];
|
||||
c = buf[2];
|
||||
d = buf[3];
|
||||
|
||||
MD5STEP(F1, a, b, c, d, in[0] + 0xd76aa478, 7);
|
||||
MD5STEP(F1, d, a, b, c, in[1] + 0xe8c7b756, 12);
|
||||
MD5STEP(F1, c, d, a, b, in[2] + 0x242070db, 17);
|
||||
MD5STEP(F1, b, c, d, a, in[3] + 0xc1bdceee, 22);
|
||||
MD5STEP(F1, a, b, c, d, in[4] + 0xf57c0faf, 7);
|
||||
MD5STEP(F1, d, a, b, c, in[5] + 0x4787c62a, 12);
|
||||
MD5STEP(F1, c, d, a, b, in[6] + 0xa8304613, 17);
|
||||
MD5STEP(F1, b, c, d, a, in[7] + 0xfd469501, 22);
|
||||
MD5STEP(F1, a, b, c, d, in[8] + 0x698098d8, 7);
|
||||
MD5STEP(F1, d, a, b, c, in[9] + 0x8b44f7af, 12);
|
||||
MD5STEP(F1, c, d, a, b, in[10] + 0xffff5bb1, 17);
|
||||
MD5STEP(F1, b, c, d, a, in[11] + 0x895cd7be, 22);
|
||||
MD5STEP(F1, a, b, c, d, in[12] + 0x6b901122, 7);
|
||||
MD5STEP(F1, d, a, b, c, in[13] + 0xfd987193, 12);
|
||||
MD5STEP(F1, c, d, a, b, in[14] + 0xa679438e, 17);
|
||||
MD5STEP(F1, b, c, d, a, in[15] + 0x49b40821, 22);
|
||||
|
||||
MD5STEP(F2, a, b, c, d, in[1] + 0xf61e2562, 5);
|
||||
MD5STEP(F2, d, a, b, c, in[6] + 0xc040b340, 9);
|
||||
MD5STEP(F2, c, d, a, b, in[11] + 0x265e5a51, 14);
|
||||
MD5STEP(F2, b, c, d, a, in[0] + 0xe9b6c7aa, 20);
|
||||
MD5STEP(F2, a, b, c, d, in[5] + 0xd62f105d, 5);
|
||||
MD5STEP(F2, d, a, b, c, in[10] + 0x02441453, 9);
|
||||
MD5STEP(F2, c, d, a, b, in[15] + 0xd8a1e681, 14);
|
||||
MD5STEP(F2, b, c, d, a, in[4] + 0xe7d3fbc8, 20);
|
||||
MD5STEP(F2, a, b, c, d, in[9] + 0x21e1cde6, 5);
|
||||
MD5STEP(F2, d, a, b, c, in[14] + 0xc33707d6, 9);
|
||||
MD5STEP(F2, c, d, a, b, in[3] + 0xf4d50d87, 14);
|
||||
MD5STEP(F2, b, c, d, a, in[8] + 0x455a14ed, 20);
|
||||
MD5STEP(F2, a, b, c, d, in[13] + 0xa9e3e905, 5);
|
||||
MD5STEP(F2, d, a, b, c, in[2] + 0xfcefa3f8, 9);
|
||||
MD5STEP(F2, c, d, a, b, in[7] + 0x676f02d9, 14);
|
||||
MD5STEP(F2, b, c, d, a, in[12] + 0x8d2a4c8a, 20);
|
||||
|
||||
MD5STEP(F3, a, b, c, d, in[5] + 0xfffa3942, 4);
|
||||
MD5STEP(F3, d, a, b, c, in[8] + 0x8771f681, 11);
|
||||
MD5STEP(F3, c, d, a, b, in[11] + 0x6d9d6122, 16);
|
||||
MD5STEP(F3, b, c, d, a, in[14] + 0xfde5380c, 23);
|
||||
MD5STEP(F3, a, b, c, d, in[1] + 0xa4beea44, 4);
|
||||
MD5STEP(F3, d, a, b, c, in[4] + 0x4bdecfa9, 11);
|
||||
MD5STEP(F3, c, d, a, b, in[7] + 0xf6bb4b60, 16);
|
||||
MD5STEP(F3, b, c, d, a, in[10] + 0xbebfbc70, 23);
|
||||
MD5STEP(F3, a, b, c, d, in[13] + 0x289b7ec6, 4);
|
||||
MD5STEP(F3, d, a, b, c, in[0] + 0xeaa127fa, 11);
|
||||
MD5STEP(F3, c, d, a, b, in[3] + 0xd4ef3085, 16);
|
||||
MD5STEP(F3, b, c, d, a, in[6] + 0x04881d05, 23);
|
||||
MD5STEP(F3, a, b, c, d, in[9] + 0xd9d4d039, 4);
|
||||
MD5STEP(F3, d, a, b, c, in[12] + 0xe6db99e5, 11);
|
||||
MD5STEP(F3, c, d, a, b, in[15] + 0x1fa27cf8, 16);
|
||||
MD5STEP(F3, b, c, d, a, in[2] + 0xc4ac5665, 23);
|
||||
|
||||
MD5STEP(F4, a, b, c, d, in[0] + 0xf4292244, 6);
|
||||
MD5STEP(F4, d, a, b, c, in[7] + 0x432aff97, 10);
|
||||
MD5STEP(F4, c, d, a, b, in[14] + 0xab9423a7, 15);
|
||||
MD5STEP(F4, b, c, d, a, in[5] + 0xfc93a039, 21);
|
||||
MD5STEP(F4, a, b, c, d, in[12] + 0x655b59c3, 6);
|
||||
MD5STEP(F4, d, a, b, c, in[3] + 0x8f0ccc92, 10);
|
||||
MD5STEP(F4, c, d, a, b, in[10] + 0xffeff47d, 15);
|
||||
MD5STEP(F4, b, c, d, a, in[1] + 0x85845dd1, 21);
|
||||
MD5STEP(F4, a, b, c, d, in[8] + 0x6fa87e4f, 6);
|
||||
MD5STEP(F4, d, a, b, c, in[15] + 0xfe2ce6e0, 10);
|
||||
MD5STEP(F4, c, d, a, b, in[6] + 0xa3014314, 15);
|
||||
MD5STEP(F4, b, c, d, a, in[13] + 0x4e0811a1, 21);
|
||||
MD5STEP(F4, a, b, c, d, in[4] + 0xf7537e82, 6);
|
||||
MD5STEP(F4, d, a, b, c, in[11] + 0xbd3af235, 10);
|
||||
MD5STEP(F4, c, d, a, b, in[2] + 0x2ad7d2bb, 15);
|
||||
MD5STEP(F4, b, c, d, a, in[9] + 0xeb86d391, 21);
|
||||
|
||||
buf[0] += a;
|
||||
buf[1] += b;
|
||||
buf[2] += c;
|
||||
buf[3] += d;
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
QT_END_NAMESPACE
|
48
src/3rdparty/md5/md5.h
vendored
48
src/3rdparty/md5/md5.h
vendored
|
@ -1,48 +0,0 @@
|
|||
/*
|
||||
* This is the header file for the MD5 message-digest algorithm.
|
||||
* The algorithm is due to Ron Rivest. This code was
|
||||
* written by Colin Plumb in 1993, no copyright is claimed.
|
||||
* This code is in the public domain; do with it what you wish.
|
||||
*
|
||||
* Equivalent code is available from RSA Data Security, Inc.
|
||||
* This code has been tested against that, and is equivalent,
|
||||
* except that you don't need to include two pages of legalese
|
||||
* with every copy.
|
||||
*
|
||||
* To compute the message digest of a chunk of bytes, declare an
|
||||
* MD5Context structure, pass it to MD5Init, call MD5Update as
|
||||
* needed on buffers full of bytes, and then call MD5Final, which
|
||||
* will fill a supplied 16-byte array with the digest.
|
||||
*
|
||||
* Changed so as no longer to depend on Colin Plumb's `usual.h'
|
||||
* header definitions; now uses stuff from dpkg's config.h
|
||||
* - Ian Jackson <ian@chiark.greenend.org.uk>.
|
||||
* Still in the public domain.
|
||||
*/
|
||||
|
||||
#ifndef MD5_H
|
||||
#define MD5_H
|
||||
|
||||
#include <qglobal.h>
|
||||
#include <qbytearray.h>
|
||||
#include <qstring.h>
|
||||
|
||||
QT_BEGIN_NAMESPACE
|
||||
|
||||
typedef unsigned char md5byte;
|
||||
typedef quint32 UWORD32;
|
||||
|
||||
struct MD5Context {
|
||||
UWORD32 buf[4];
|
||||
UWORD32 bytes[2];
|
||||
UWORD32 in[16];
|
||||
};
|
||||
|
||||
static void MD5Init(struct MD5Context *context);
|
||||
static void MD5Update(struct MD5Context *context, md5byte const *buf, unsigned len);
|
||||
static void MD5Final(struct MD5Context *context, unsigned char digest[16]);
|
||||
static void MD5Transform(UWORD32 buf[4], UWORD32 const in[16]);
|
||||
|
||||
QT_END_NAMESPACE
|
||||
|
||||
#endif /* !MD5_H */
|
28
src/3rdparty/rfc6234/sha-private.h
vendored
28
src/3rdparty/rfc6234/sha-private.h
vendored
|
@ -1,28 +0,0 @@
|
|||
/************************ sha-private.h ************************/
|
||||
/***************** See RFC 6234 for details. *******************/
|
||||
#ifndef _SHA_PRIVATE__H
|
||||
#define _SHA_PRIVATE__H
|
||||
/*
|
||||
* These definitions are defined in FIPS 180-3, section 4.1.
|
||||
* Ch() and Maj() are defined identically in sections 4.1.1,
|
||||
* 4.1.2, and 4.1.3.
|
||||
*
|
||||
* The definitions used in FIPS 180-3 are as follows:
|
||||
*/
|
||||
|
||||
#ifndef USE_MODIFIED_MACROS
|
||||
#define SHA_Ch(x,y,z) (((x) & (y)) ^ ((~(x)) & (z)))
|
||||
#define SHA_Maj(x,y,z) (((x) & (y)) ^ ((x) & (z)) ^ ((y) & (z)))
|
||||
#else /* USE_MODIFIED_MACROS */
|
||||
/*
|
||||
* The following definitions are equivalent and potentially faster.
|
||||
*/
|
||||
|
||||
#define SHA_Ch(x, y, z) (((x) & ((y) ^ (z))) ^ (z))
|
||||
#define SHA_Maj(x, y, z) (((x) & ((y) | (z))) | ((y) & (z)))
|
||||
|
||||
#endif /* USE_MODIFIED_MACROS */
|
||||
|
||||
#define SHA_Parity(x, y, z) ((x) ^ (y) ^ (z))
|
||||
|
||||
#endif /* _SHA_PRIVATE__H */
|
357
src/3rdparty/rfc6234/sha.h
vendored
357
src/3rdparty/rfc6234/sha.h
vendored
|
@ -1,357 +0,0 @@
|
|||
/**************************** sha.h ****************************/
|
||||
/***************** See RFC 6234 for details. *******************/
|
||||
/*
|
||||
Copyright (c) 2011 IETF Trust and the persons identified as
|
||||
authors of the code. All rights reserved.
|
||||
|
||||
Redistribution and use in source and binary forms, with or
|
||||
without modification, are permitted provided that the following
|
||||
conditions are met:
|
||||
|
||||
- Redistributions of source code must retain the above
|
||||
copyright notice, this list of conditions and
|
||||
the following disclaimer.
|
||||
|
||||
- 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.
|
||||
|
||||
- Neither the name of Internet Society, IETF or IETF Trust, nor
|
||||
the names of specific 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 OWNER 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.
|
||||
*/
|
||||
#ifndef _SHA_H_
|
||||
#define _SHA_H_
|
||||
|
||||
/*
|
||||
* Description:
|
||||
* This file implements the Secure Hash Algorithms
|
||||
* as defined in the U.S. National Institute of Standards
|
||||
* and Technology Federal Information Processing Standards
|
||||
* Publication (FIPS PUB) 180-3 published in October 2008
|
||||
* and formerly defined in its predecessors, FIPS PUB 180-1
|
||||
* and FIP PUB 180-2.
|
||||
*
|
||||
* A combined document showing all algorithms is available at
|
||||
* http://csrc.nist.gov/publications/fips/
|
||||
* fips180-3/fips180-3_final.pdf
|
||||
*
|
||||
* The five hashes are defined in these sizes:
|
||||
* SHA-1 20 byte / 160 bit
|
||||
* SHA-224 28 byte / 224 bit
|
||||
* SHA-256 32 byte / 256 bit
|
||||
* SHA-384 48 byte / 384 bit
|
||||
* SHA-512 64 byte / 512 bit
|
||||
*
|
||||
* Compilation Note:
|
||||
* These files may be compiled with two options:
|
||||
* USE_32BIT_ONLY - use 32-bit arithmetic only, for systems
|
||||
* without 64-bit integers
|
||||
*
|
||||
* USE_MODIFIED_MACROS - use alternate form of the SHA_Ch()
|
||||
* and SHA_Maj() macros that are equivalent
|
||||
* and potentially faster on many systems
|
||||
*
|
||||
*/
|
||||
|
||||
// stdint.h include commented out by Nokia, it is not available on all platforms.
|
||||
// #include <stdint.h>
|
||||
/*
|
||||
* If you do not have the ISO standard stdint.h header file, then you
|
||||
* must typedef the following:
|
||||
* name meaning
|
||||
* uint64_t unsigned 64-bit integer
|
||||
* uint32_t unsigned 32-bit integer
|
||||
* uint8_t unsigned 8-bit integer (i.e., unsigned char)
|
||||
* int_least16_t integer of >= 16 bits
|
||||
*
|
||||
* See stdint-example.h
|
||||
*/
|
||||
|
||||
#ifndef _SHA_enum_
|
||||
#define _SHA_enum_
|
||||
/*
|
||||
* All SHA functions return one of these values.
|
||||
*/
|
||||
enum {
|
||||
shaSuccess = 0,
|
||||
shaNull, /* Null pointer parameter */
|
||||
shaInputTooLong, /* input data too long */
|
||||
shaStateError, /* called Input after FinalBits or Result */
|
||||
shaBadParam /* passed a bad parameter */
|
||||
};
|
||||
#endif /* _SHA_enum_ */
|
||||
|
||||
/*
|
||||
* These constants hold size information for each of the SHA
|
||||
* hashing operations
|
||||
*/
|
||||
enum {
|
||||
SHA1_Message_Block_Size = 64, SHA224_Message_Block_Size = 64,
|
||||
SHA256_Message_Block_Size = 64, SHA384_Message_Block_Size = 128,
|
||||
SHA512_Message_Block_Size = 128,
|
||||
USHA_Max_Message_Block_Size = SHA512_Message_Block_Size,
|
||||
|
||||
SHA1HashSize = 20, SHA224HashSize = 28, SHA256HashSize = 32,
|
||||
SHA384HashSize = 48, SHA512HashSize = 64,
|
||||
USHAMaxHashSize = SHA512HashSize,
|
||||
|
||||
SHA1HashSizeBits = 160, SHA224HashSizeBits = 224,
|
||||
SHA256HashSizeBits = 256, SHA384HashSizeBits = 384,
|
||||
SHA512HashSizeBits = 512, USHAMaxHashSizeBits = SHA512HashSizeBits
|
||||
};
|
||||
|
||||
/*
|
||||
* These constants are used in the USHA (Unified SHA) functions.
|
||||
*/
|
||||
typedef enum SHAversion {
|
||||
SHA1, SHA224, SHA256, SHA384, SHA512
|
||||
} SHAversion;
|
||||
|
||||
/*
|
||||
* This structure will hold context information for the SHA-1
|
||||
* hashing operation.
|
||||
*/
|
||||
typedef struct SHA1Context {
|
||||
uint32_t Intermediate_Hash[SHA1HashSize/4]; /* Message Digest */
|
||||
|
||||
uint32_t Length_High; /* Message length in bits */
|
||||
uint32_t Length_Low; /* Message length in bits */
|
||||
|
||||
int_least16_t Message_Block_Index; /* Message_Block array index */
|
||||
/* 512-bit message blocks */
|
||||
uint8_t Message_Block[SHA1_Message_Block_Size];
|
||||
|
||||
int Computed; /* Is the hash computed? */
|
||||
int Corrupted; /* Cumulative corruption code */
|
||||
} SHA1Context;
|
||||
|
||||
/*
|
||||
* This structure will hold context information for the SHA-256
|
||||
* hashing operation.
|
||||
*/
|
||||
typedef struct SHA256Context {
|
||||
uint32_t Intermediate_Hash[SHA256HashSize/4]; /* Message Digest */
|
||||
|
||||
uint32_t Length_High; /* Message length in bits */
|
||||
uint32_t Length_Low; /* Message length in bits */
|
||||
|
||||
int_least16_t Message_Block_Index; /* Message_Block array index */
|
||||
/* 512-bit message blocks */
|
||||
uint8_t Message_Block[SHA256_Message_Block_Size];
|
||||
|
||||
int Computed; /* Is the hash computed? */
|
||||
int Corrupted; /* Cumulative corruption code */
|
||||
} SHA256Context;
|
||||
|
||||
/*
|
||||
* This structure will hold context information for the SHA-512
|
||||
* hashing operation.
|
||||
*/
|
||||
typedef struct SHA512Context {
|
||||
#ifdef USE_32BIT_ONLY
|
||||
uint32_t Intermediate_Hash[SHA512HashSize/4]; /* Message Digest */
|
||||
uint32_t Length[4]; /* Message length in bits */
|
||||
#else /* !USE_32BIT_ONLY */
|
||||
uint64_t Intermediate_Hash[SHA512HashSize/8]; /* Message Digest */
|
||||
uint64_t Length_High, Length_Low; /* Message length in bits */
|
||||
#endif /* USE_32BIT_ONLY */
|
||||
|
||||
int_least16_t Message_Block_Index; /* Message_Block array index */
|
||||
/* 1024-bit message blocks */
|
||||
uint8_t Message_Block[SHA512_Message_Block_Size];
|
||||
|
||||
int Computed; /* Is the hash computed?*/
|
||||
int Corrupted; /* Cumulative corruption code */
|
||||
} SHA512Context;
|
||||
|
||||
/*
|
||||
* This structure will hold context information for the SHA-224
|
||||
* hashing operation. It uses the SHA-256 structure for computation.
|
||||
*/
|
||||
typedef struct SHA256Context SHA224Context;
|
||||
|
||||
/*
|
||||
* This structure will hold context information for the SHA-384
|
||||
* hashing operation. It uses the SHA-512 structure for computation.
|
||||
*/
|
||||
typedef struct SHA512Context SHA384Context;
|
||||
|
||||
/*
|
||||
* This structure holds context information for all SHA
|
||||
* hashing operations.
|
||||
*/
|
||||
typedef struct USHAContext {
|
||||
int whichSha; /* which SHA is being used */
|
||||
union {
|
||||
SHA1Context sha1Context;
|
||||
SHA224Context sha224Context; SHA256Context sha256Context;
|
||||
SHA384Context sha384Context; SHA512Context sha512Context;
|
||||
} ctx;
|
||||
} USHAContext;
|
||||
|
||||
/*
|
||||
* This structure will hold context information for the HMAC
|
||||
* keyed-hashing operation.
|
||||
*/
|
||||
typedef struct HMACContext {
|
||||
int whichSha; /* which SHA is being used */
|
||||
int hashSize; /* hash size of SHA being used */
|
||||
int blockSize; /* block size of SHA being used */
|
||||
USHAContext shaContext; /* SHA context */
|
||||
unsigned char k_opad[USHA_Max_Message_Block_Size];
|
||||
/* outer padding - key XORd with opad */
|
||||
int Computed; /* Is the MAC computed? */
|
||||
int Corrupted; /* Cumulative corruption code */
|
||||
|
||||
} HMACContext;
|
||||
|
||||
/*
|
||||
* This structure will hold context information for the HKDF
|
||||
* extract-and-expand Key Derivation Functions.
|
||||
*/
|
||||
typedef struct HKDFContext {
|
||||
int whichSha; /* which SHA is being used */
|
||||
HMACContext hmacContext;
|
||||
int hashSize; /* hash size of SHA being used */
|
||||
unsigned char prk[USHAMaxHashSize];
|
||||
/* pseudo-random key - output of hkdfInput */
|
||||
int Computed; /* Is the key material computed? */
|
||||
int Corrupted; /* Cumulative corruption code */
|
||||
} HKDFContext;
|
||||
|
||||
/*
|
||||
* Function Prototypes
|
||||
*/
|
||||
|
||||
/* SHA-1 */
|
||||
extern int SHA1Reset(SHA1Context *);
|
||||
extern int SHA1Input(SHA1Context *, const uint8_t *bytes,
|
||||
unsigned int bytecount);
|
||||
extern int SHA1FinalBits(SHA1Context *, uint8_t bits,
|
||||
unsigned int bit_count);
|
||||
extern int SHA1Result(SHA1Context *,
|
||||
uint8_t Message_Digest[SHA1HashSize]);
|
||||
|
||||
/* SHA-224 */
|
||||
extern int SHA224Reset(SHA224Context *);
|
||||
extern int SHA224Input(SHA224Context *, const uint8_t *bytes,
|
||||
unsigned int bytecount);
|
||||
extern int SHA224FinalBits(SHA224Context *, uint8_t bits,
|
||||
unsigned int bit_count);
|
||||
extern int SHA224Result(SHA224Context *,
|
||||
uint8_t Message_Digest[SHA224HashSize]);
|
||||
|
||||
/* SHA-256 */
|
||||
extern int SHA256Reset(SHA256Context *);
|
||||
extern int SHA256Input(SHA256Context *, const uint8_t *bytes,
|
||||
unsigned int bytecount);
|
||||
extern int SHA256FinalBits(SHA256Context *, uint8_t bits,
|
||||
unsigned int bit_count);
|
||||
extern int SHA256Result(SHA256Context *,
|
||||
uint8_t Message_Digest[SHA256HashSize]);
|
||||
|
||||
/* SHA-384 */
|
||||
extern int SHA384Reset(SHA384Context *);
|
||||
extern int SHA384Input(SHA384Context *, const uint8_t *bytes,
|
||||
unsigned int bytecount);
|
||||
extern int SHA384FinalBits(SHA384Context *, uint8_t bits,
|
||||
unsigned int bit_count);
|
||||
extern int SHA384Result(SHA384Context *,
|
||||
uint8_t Message_Digest[SHA384HashSize]);
|
||||
|
||||
/* SHA-512 */
|
||||
extern int SHA512Reset(SHA512Context *);
|
||||
extern int SHA512Input(SHA512Context *, const uint8_t *bytes,
|
||||
unsigned int bytecount);
|
||||
extern int SHA512FinalBits(SHA512Context *, uint8_t bits,
|
||||
unsigned int bit_count);
|
||||
extern int SHA512Result(SHA512Context *,
|
||||
uint8_t Message_Digest[SHA512HashSize]);
|
||||
|
||||
/* Unified SHA functions, chosen by whichSha */
|
||||
extern int USHAReset(USHAContext *context, SHAversion whichSha);
|
||||
extern int USHAInput(USHAContext *context,
|
||||
const uint8_t *bytes, unsigned int bytecount);
|
||||
extern int USHAFinalBits(USHAContext *context,
|
||||
uint8_t bits, unsigned int bit_count);
|
||||
extern int USHAResult(USHAContext *context,
|
||||
uint8_t Message_Digest[USHAMaxHashSize]);
|
||||
extern int USHABlockSize(enum SHAversion whichSha);
|
||||
extern int USHAHashSize(enum SHAversion whichSha);
|
||||
extern int USHAHashSizeBits(enum SHAversion whichSha);
|
||||
extern const char *USHAHashName(enum SHAversion whichSha);
|
||||
|
||||
/*
|
||||
* HMAC Keyed-Hashing for Message Authentication, RFC 2104,
|
||||
* for all SHAs.
|
||||
* This interface allows a fixed-length text input to be used.
|
||||
*/
|
||||
extern int hmac(SHAversion whichSha, /* which SHA algorithm to use */
|
||||
const unsigned char *text, /* pointer to data stream */
|
||||
int text_len, /* length of data stream */
|
||||
const unsigned char *key, /* pointer to authentication key */
|
||||
int key_len, /* length of authentication key */
|
||||
uint8_t digest[USHAMaxHashSize]); /* caller digest to fill in */
|
||||
|
||||
/*
|
||||
* HMAC Keyed-Hashing for Message Authentication, RFC 2104,
|
||||
* for all SHAs.
|
||||
* This interface allows any length of text input to be used.
|
||||
*/
|
||||
extern int hmacReset(HMACContext *context, enum SHAversion whichSha,
|
||||
const unsigned char *key, int key_len);
|
||||
extern int hmacInput(HMACContext *context, const unsigned char *text,
|
||||
int text_len);
|
||||
extern int hmacFinalBits(HMACContext *context, uint8_t bits,
|
||||
unsigned int bit_count);
|
||||
extern int hmacResult(HMACContext *context,
|
||||
uint8_t digest[USHAMaxHashSize]);
|
||||
|
||||
/*
|
||||
* HKDF HMAC-based Extract-and-Expand Key Derivation Function,
|
||||
* RFC 5869, for all SHAs.
|
||||
*/
|
||||
extern int hkdf(SHAversion whichSha, const unsigned char *salt,
|
||||
int salt_len, const unsigned char *ikm, int ikm_len,
|
||||
const unsigned char *info, int info_len,
|
||||
uint8_t okm[ ], int okm_len);
|
||||
extern int hkdfExtract(SHAversion whichSha, const unsigned char *salt,
|
||||
int salt_len, const unsigned char *ikm,
|
||||
int ikm_len, uint8_t prk[USHAMaxHashSize]);
|
||||
extern int hkdfExpand(SHAversion whichSha, const uint8_t prk[ ],
|
||||
int prk_len, const unsigned char *info,
|
||||
int info_len, uint8_t okm[ ], int okm_len);
|
||||
|
||||
/*
|
||||
* HKDF HMAC-based Extract-and-Expand Key Derivation Function,
|
||||
* RFC 5869, for all SHAs.
|
||||
* This interface allows any length of text input to be used.
|
||||
*/
|
||||
extern int hkdfReset(HKDFContext *context, enum SHAversion whichSha,
|
||||
const unsigned char *salt, int salt_len);
|
||||
extern int hkdfInput(HKDFContext *context, const unsigned char *ikm,
|
||||
int ikm_len);
|
||||
extern int hkdfFinalBits(HKDFContext *context, uint8_t ikm_bits,
|
||||
unsigned int ikm_bit_count);
|
||||
extern int hkdfResult(HKDFContext *context,
|
||||
uint8_t prk[USHAMaxHashSize],
|
||||
const unsigned char *info, int info_len,
|
||||
uint8_t okm[USHAMaxHashSize], int okm_len);
|
||||
#endif /* _SHA_H_ */
|
583
src/3rdparty/rfc6234/sha224-256.c
vendored
583
src/3rdparty/rfc6234/sha224-256.c
vendored
|
@ -1,583 +0,0 @@
|
|||
/************************* sha224-256.c ************************/
|
||||
/***************** See RFC 6234 for details. *******************/
|
||||
/* Copyright (c) 2011 IETF Trust and the persons identified as */
|
||||
/* authors of the code. All rights reserved. */
|
||||
/* See sha.h for terms of use and redistribution. */
|
||||
|
||||
/*
|
||||
* Description:
|
||||
* This file implements the Secure Hash Algorithms SHA-224 and
|
||||
* SHA-256 as defined in the U.S. National Institute of Standards
|
||||
* and Technology Federal Information Processing Standards
|
||||
* Publication (FIPS PUB) 180-3 published in October 2008
|
||||
* and formerly defined in its predecessors, FIPS PUB 180-1
|
||||
* and FIP PUB 180-2.
|
||||
*
|
||||
* A combined document showing all algorithms is available at
|
||||
* http://csrc.nist.gov/publications/fips/
|
||||
* fips180-3/fips180-3_final.pdf
|
||||
*
|
||||
* The SHA-224 and SHA-256 algorithms produce 224-bit and 256-bit
|
||||
* message digests for a given data stream. It should take about
|
||||
* 2**n steps to find a message with the same digest as a given
|
||||
* message and 2**(n/2) to find any two messages with the same
|
||||
* digest, when n is the digest size in bits. Therefore, this
|
||||
* algorithm can serve as a means of providing a
|
||||
* "fingerprint" for a message.
|
||||
*
|
||||
* Portability Issues:
|
||||
* SHA-224 and SHA-256 are defined in terms of 32-bit "words".
|
||||
* This code uses <stdint.h> (included via "sha.h") to define 32-
|
||||
* and 8-bit unsigned integer types. If your C compiler does not
|
||||
* support 32-bit unsigned integers, this code is not
|
||||
* appropriate.
|
||||
*
|
||||
* Caveats:
|
||||
* SHA-224 and SHA-256 are designed to work with messages less
|
||||
* than 2^64 bits long. This implementation uses SHA224/256Input()
|
||||
* to hash the bits that are a multiple of the size of an 8-bit
|
||||
* octet, and then optionally uses SHA224/256FinalBits()
|
||||
* to hash the final few bits of the input.
|
||||
*/
|
||||
|
||||
#include "sha.h"
|
||||
#include "sha-private.h"
|
||||
|
||||
/* Define the SHA shift, rotate left, and rotate right macros */
|
||||
#define SHA256_SHR(bits,word) ((word) >> (bits))
|
||||
#define SHA256_ROTL(bits,word) \
|
||||
(((word) << (bits)) | ((word) >> (32-(bits))))
|
||||
#define SHA256_ROTR(bits,word) \
|
||||
(((word) >> (bits)) | ((word) << (32-(bits))))
|
||||
|
||||
/* Define the SHA SIGMA and sigma macros */
|
||||
#define SHA256_SIGMA0(word) \
|
||||
(SHA256_ROTR( 2,word) ^ SHA256_ROTR(13,word) ^ SHA256_ROTR(22,word))
|
||||
#define SHA256_SIGMA1(word) \
|
||||
(SHA256_ROTR( 6,word) ^ SHA256_ROTR(11,word) ^ SHA256_ROTR(25,word))
|
||||
#define SHA256_sigma0(word) \
|
||||
(SHA256_ROTR( 7,word) ^ SHA256_ROTR(18,word) ^ SHA256_SHR( 3,word))
|
||||
#define SHA256_sigma1(word) \
|
||||
(SHA256_ROTR(17,word) ^ SHA256_ROTR(19,word) ^ SHA256_SHR(10,word))
|
||||
|
||||
/*
|
||||
* Add "length" to the length.
|
||||
* Set Corrupted when overflow has occurred.
|
||||
*/
|
||||
/* addTemp commented out by Nokia, static variables are not thread-safe */
|
||||
/* static uint32_t addTemp; */
|
||||
/* 'M' appended to Macro name by Nokia */
|
||||
#define SHA224_256AddLengthM(context, length) \
|
||||
(addTemp = (context)->Length_Low, (context)->Corrupted = \
|
||||
(((context)->Length_Low += (length)) < addTemp) && \
|
||||
(++(context)->Length_High == 0) ? shaInputTooLong : \
|
||||
(context)->Corrupted )
|
||||
|
||||
/* Local Function Prototypes */
|
||||
static int SHA224_256Reset(SHA256Context *context, uint32_t *H0);
|
||||
static void SHA224_256ProcessMessageBlock(SHA256Context *context);
|
||||
static void SHA224_256Finalize(SHA256Context *context,
|
||||
uint8_t Pad_Byte);
|
||||
static void SHA224_256PadMessage(SHA256Context *context,
|
||||
uint8_t Pad_Byte);
|
||||
static int SHA224_256ResultN(SHA256Context *context,
|
||||
uint8_t Message_Digest[ ], int HashSize);
|
||||
|
||||
/* Initial Hash Values: FIPS 180-3 section 5.3.2 */
|
||||
static uint32_t SHA224_H0[SHA256HashSize/4] = {
|
||||
0xC1059ED8, 0x367CD507, 0x3070DD17, 0xF70E5939,
|
||||
0xFFC00B31, 0x68581511, 0x64F98FA7, 0xBEFA4FA4
|
||||
};
|
||||
|
||||
/* Initial Hash Values: FIPS 180-3 section 5.3.3 */
|
||||
static uint32_t SHA256_H0[SHA256HashSize/4] = {
|
||||
0x6A09E667, 0xBB67AE85, 0x3C6EF372, 0xA54FF53A,
|
||||
0x510E527F, 0x9B05688C, 0x1F83D9AB, 0x5BE0CD19
|
||||
};
|
||||
|
||||
/*
|
||||
* SHA224Reset
|
||||
*
|
||||
* Description:
|
||||
* This function will initialize the SHA224Context in preparation
|
||||
* for computing a new SHA224 message digest.
|
||||
*
|
||||
* Parameters:
|
||||
* context: [in/out]
|
||||
* The context to reset.
|
||||
*
|
||||
* Returns:
|
||||
* sha Error Code.
|
||||
*/
|
||||
int SHA224Reset(SHA224Context *context)
|
||||
{
|
||||
return SHA224_256Reset(context, SHA224_H0);
|
||||
}
|
||||
|
||||
/*
|
||||
* SHA224Input
|
||||
*
|
||||
* Description:
|
||||
* This function accepts an array of octets as the next portion
|
||||
* of the message.
|
||||
*
|
||||
* Parameters:
|
||||
* context: [in/out]
|
||||
* The SHA context to update.
|
||||
* message_array[ ]: [in]
|
||||
* An array of octets representing the next portion of
|
||||
* the message.
|
||||
* length: [in]
|
||||
* The length of the message in message_array.
|
||||
*
|
||||
* Returns:
|
||||
* sha Error Code.
|
||||
*
|
||||
*/
|
||||
int SHA224Input(SHA224Context *context, const uint8_t *message_array,
|
||||
unsigned int length)
|
||||
{
|
||||
return SHA256Input(context, message_array, length);
|
||||
}
|
||||
|
||||
/*
|
||||
* SHA224FinalBits
|
||||
*
|
||||
* Description:
|
||||
* This function will add in any final bits of the message.
|
||||
*
|
||||
* Parameters:
|
||||
* context: [in/out]
|
||||
* The SHA context to update.
|
||||
* message_bits: [in]
|
||||
* The final bits of the message, in the upper portion of the
|
||||
* byte. (Use 0b###00000 instead of 0b00000### to input the
|
||||
* three bits ###.)
|
||||
* length: [in]
|
||||
* The number of bits in message_bits, between 1 and 7.
|
||||
*
|
||||
* Returns:
|
||||
* sha Error Code.
|
||||
*/
|
||||
int SHA224FinalBits(SHA224Context *context,
|
||||
uint8_t message_bits, unsigned int length)
|
||||
{
|
||||
return SHA256FinalBits(context, message_bits, length);
|
||||
}
|
||||
|
||||
/*
|
||||
* SHA224Result
|
||||
*
|
||||
* Description:
|
||||
* This function will return the 224-bit message digest
|
||||
* into the Message_Digest array provided by the caller.
|
||||
* NOTE:
|
||||
* The first octet of hash is stored in the element with index 0,
|
||||
* the last octet of hash in the element with index 27.
|
||||
*
|
||||
* Parameters:
|
||||
* context: [in/out]
|
||||
* The context to use to calculate the SHA hash.
|
||||
* Message_Digest[ ]: [out]
|
||||
* Where the digest is returned.
|
||||
*
|
||||
* Returns:
|
||||
* sha Error Code.
|
||||
*/
|
||||
int SHA224Result(SHA224Context *context,
|
||||
uint8_t Message_Digest[SHA224HashSize])
|
||||
{
|
||||
return SHA224_256ResultN(context, Message_Digest, SHA224HashSize);
|
||||
}
|
||||
|
||||
/*
|
||||
* SHA256Reset
|
||||
*
|
||||
* Description:
|
||||
* This function will initialize the SHA256Context in preparation
|
||||
* for computing a new SHA256 message digest.
|
||||
*
|
||||
* Parameters:
|
||||
* context: [in/out]
|
||||
* The context to reset.
|
||||
*
|
||||
* Returns:
|
||||
* sha Error Code.
|
||||
*/
|
||||
int SHA256Reset(SHA256Context *context)
|
||||
{
|
||||
return SHA224_256Reset(context, SHA256_H0);
|
||||
}
|
||||
|
||||
/*
|
||||
* SHA256Input
|
||||
*
|
||||
* Description:
|
||||
* This function accepts an array of octets as the next portion
|
||||
* of the message.
|
||||
*
|
||||
* Parameters:
|
||||
* context: [in/out]
|
||||
* The SHA context to update.
|
||||
* message_array[ ]: [in]
|
||||
* An array of octets representing the next portion of
|
||||
* the message.
|
||||
* length: [in]
|
||||
* The length of the message in message_array.
|
||||
*
|
||||
* Returns:
|
||||
* sha Error Code.
|
||||
*/
|
||||
int SHA256Input(SHA256Context *context, const uint8_t *message_array,
|
||||
unsigned int length)
|
||||
{
|
||||
if (!context) return shaNull;
|
||||
if (!length) return shaSuccess;
|
||||
if (!message_array) return shaNull;
|
||||
if (context->Computed) return context->Corrupted = shaStateError;
|
||||
if (context->Corrupted) return context->Corrupted;
|
||||
|
||||
while (length--) {
|
||||
context->Message_Block[context->Message_Block_Index++] =
|
||||
*message_array;
|
||||
|
||||
if ((SHA224_256AddLength(context, 8) == shaSuccess) &&
|
||||
(context->Message_Block_Index == SHA256_Message_Block_Size))
|
||||
SHA224_256ProcessMessageBlock(context);
|
||||
|
||||
message_array++;
|
||||
}
|
||||
|
||||
return context->Corrupted;
|
||||
|
||||
}
|
||||
|
||||
/*
|
||||
* SHA256FinalBits
|
||||
*
|
||||
* Description:
|
||||
* This function will add in any final bits of the message.
|
||||
*
|
||||
* Parameters:
|
||||
* context: [in/out]
|
||||
* The SHA context to update.
|
||||
* message_bits: [in]
|
||||
* The final bits of the message, in the upper portion of the
|
||||
* byte. (Use 0b###00000 instead of 0b00000### to input the
|
||||
* three bits ###.)
|
||||
* length: [in]
|
||||
* The number of bits in message_bits, between 1 and 7.
|
||||
*
|
||||
* Returns:
|
||||
* sha Error Code.
|
||||
*/
|
||||
int SHA256FinalBits(SHA256Context *context,
|
||||
uint8_t message_bits, unsigned int length)
|
||||
{
|
||||
static uint8_t masks[8] = {
|
||||
/* 0 0b00000000 */ 0x00, /* 1 0b10000000 */ 0x80,
|
||||
/* 2 0b11000000 */ 0xC0, /* 3 0b11100000 */ 0xE0,
|
||||
/* 4 0b11110000 */ 0xF0, /* 5 0b11111000 */ 0xF8,
|
||||
/* 6 0b11111100 */ 0xFC, /* 7 0b11111110 */ 0xFE
|
||||
};
|
||||
static uint8_t markbit[8] = {
|
||||
/* 0 0b10000000 */ 0x80, /* 1 0b01000000 */ 0x40,
|
||||
/* 2 0b00100000 */ 0x20, /* 3 0b00010000 */ 0x10,
|
||||
/* 4 0b00001000 */ 0x08, /* 5 0b00000100 */ 0x04,
|
||||
/* 6 0b00000010 */ 0x02, /* 7 0b00000001 */ 0x01
|
||||
};
|
||||
|
||||
if (!context) return shaNull;
|
||||
if (!length) return shaSuccess;
|
||||
if (context->Corrupted) return context->Corrupted;
|
||||
if (context->Computed) return context->Corrupted = shaStateError;
|
||||
if (length >= 8) return context->Corrupted = shaBadParam;
|
||||
|
||||
SHA224_256AddLength(context, length);
|
||||
SHA224_256Finalize(context, (uint8_t)
|
||||
((message_bits & masks[length]) | markbit[length]));
|
||||
|
||||
return context->Corrupted;
|
||||
}
|
||||
|
||||
/*
|
||||
* SHA256Result
|
||||
*
|
||||
* Description:
|
||||
* This function will return the 256-bit message digest
|
||||
* into the Message_Digest array provided by the caller.
|
||||
* NOTE:
|
||||
* The first octet of hash is stored in the element with index 0,
|
||||
* the last octet of hash in the element with index 31.
|
||||
*
|
||||
* Parameters:
|
||||
* context: [in/out]
|
||||
* The context to use to calculate the SHA hash.
|
||||
* Message_Digest[ ]: [out]
|
||||
* Where the digest is returned.
|
||||
*
|
||||
* Returns:
|
||||
* sha Error Code.
|
||||
*/
|
||||
int SHA256Result(SHA256Context *context,
|
||||
uint8_t Message_Digest[SHA256HashSize])
|
||||
{
|
||||
return SHA224_256ResultN(context, Message_Digest, SHA256HashSize);
|
||||
}
|
||||
|
||||
/*
|
||||
* SHA224_256Reset
|
||||
*
|
||||
* Description:
|
||||
* This helper function will initialize the SHA256Context in
|
||||
* preparation for computing a new SHA-224 or SHA-256 message digest.
|
||||
*
|
||||
* Parameters:
|
||||
* context: [in/out]
|
||||
* The context to reset.
|
||||
* H0[ ]: [in]
|
||||
* The initial hash value array to use.
|
||||
*
|
||||
* Returns:
|
||||
* sha Error Code.
|
||||
*/
|
||||
static int SHA224_256Reset(SHA256Context *context, uint32_t *H0)
|
||||
{
|
||||
if (!context) return shaNull;
|
||||
|
||||
context->Length_High = context->Length_Low = 0;
|
||||
context->Message_Block_Index = 0;
|
||||
|
||||
context->Intermediate_Hash[0] = H0[0];
|
||||
context->Intermediate_Hash[1] = H0[1];
|
||||
context->Intermediate_Hash[2] = H0[2];
|
||||
context->Intermediate_Hash[3] = H0[3];
|
||||
context->Intermediate_Hash[4] = H0[4];
|
||||
context->Intermediate_Hash[5] = H0[5];
|
||||
context->Intermediate_Hash[6] = H0[6];
|
||||
context->Intermediate_Hash[7] = H0[7];
|
||||
|
||||
context->Computed = 0;
|
||||
context->Corrupted = shaSuccess;
|
||||
|
||||
return shaSuccess;
|
||||
}
|
||||
|
||||
/*
|
||||
* SHA224_256ProcessMessageBlock
|
||||
*
|
||||
* Description:
|
||||
* This helper function will process the next 512 bits of the
|
||||
* message stored in the Message_Block array.
|
||||
*
|
||||
* Parameters:
|
||||
* context: [in/out]
|
||||
* The SHA context to update.
|
||||
*
|
||||
* Returns:
|
||||
* Nothing.
|
||||
*
|
||||
* Comments:
|
||||
* Many of the variable names in this code, especially the
|
||||
* single character names, were used because those were the
|
||||
* names used in the Secure Hash Standard.
|
||||
*/
|
||||
static void SHA224_256ProcessMessageBlock(SHA256Context *context)
|
||||
{
|
||||
/* Constants defined in FIPS 180-3, section 4.2.2 */
|
||||
static const uint32_t K[64] = {
|
||||
0x428a2f98, 0x71374491, 0xb5c0fbcf, 0xe9b5dba5, 0x3956c25b,
|
||||
0x59f111f1, 0x923f82a4, 0xab1c5ed5, 0xd807aa98, 0x12835b01,
|
||||
0x243185be, 0x550c7dc3, 0x72be5d74, 0x80deb1fe, 0x9bdc06a7,
|
||||
0xc19bf174, 0xe49b69c1, 0xefbe4786, 0x0fc19dc6, 0x240ca1cc,
|
||||
0x2de92c6f, 0x4a7484aa, 0x5cb0a9dc, 0x76f988da, 0x983e5152,
|
||||
0xa831c66d, 0xb00327c8, 0xbf597fc7, 0xc6e00bf3, 0xd5a79147,
|
||||
0x06ca6351, 0x14292967, 0x27b70a85, 0x2e1b2138, 0x4d2c6dfc,
|
||||
0x53380d13, 0x650a7354, 0x766a0abb, 0x81c2c92e, 0x92722c85,
|
||||
0xa2bfe8a1, 0xa81a664b, 0xc24b8b70, 0xc76c51a3, 0xd192e819,
|
||||
0xd6990624, 0xf40e3585, 0x106aa070, 0x19a4c116, 0x1e376c08,
|
||||
0x2748774c, 0x34b0bcb5, 0x391c0cb3, 0x4ed8aa4a, 0x5b9cca4f,
|
||||
0x682e6ff3, 0x748f82ee, 0x78a5636f, 0x84c87814, 0x8cc70208,
|
||||
0x90befffa, 0xa4506ceb, 0xbef9a3f7, 0xc67178f2
|
||||
};
|
||||
int t, t4; /* Loop counter */
|
||||
uint32_t temp1, temp2; /* Temporary word value */
|
||||
uint32_t W[64]; /* Word sequence */
|
||||
uint32_t A, B, C, D, E, F, G, H; /* Word buffers */
|
||||
|
||||
/*
|
||||
* Initialize the first 16 words in the array W
|
||||
*/
|
||||
for (t = t4 = 0; t < 16; t++, t4 += 4)
|
||||
W[t] = (((uint32_t)context->Message_Block[t4]) << 24) |
|
||||
(((uint32_t)context->Message_Block[t4 + 1]) << 16) |
|
||||
(((uint32_t)context->Message_Block[t4 + 2]) << 8) |
|
||||
(((uint32_t)context->Message_Block[t4 + 3]));
|
||||
|
||||
for (t = 16; t < 64; t++)
|
||||
W[t] = SHA256_sigma1(W[t-2]) + W[t-7] +
|
||||
SHA256_sigma0(W[t-15]) + W[t-16];
|
||||
|
||||
A = context->Intermediate_Hash[0];
|
||||
B = context->Intermediate_Hash[1];
|
||||
C = context->Intermediate_Hash[2];
|
||||
D = context->Intermediate_Hash[3];
|
||||
E = context->Intermediate_Hash[4];
|
||||
F = context->Intermediate_Hash[5];
|
||||
G = context->Intermediate_Hash[6];
|
||||
H = context->Intermediate_Hash[7];
|
||||
|
||||
for (t = 0; t < 64; t++) {
|
||||
temp1 = H + SHA256_SIGMA1(E) + SHA_Ch(E,F,G) + K[t] + W[t];
|
||||
temp2 = SHA256_SIGMA0(A) + SHA_Maj(A,B,C);
|
||||
H = G;
|
||||
G = F;
|
||||
F = E;
|
||||
E = D + temp1;
|
||||
D = C;
|
||||
C = B;
|
||||
B = A;
|
||||
A = temp1 + temp2;
|
||||
}
|
||||
|
||||
context->Intermediate_Hash[0] += A;
|
||||
context->Intermediate_Hash[1] += B;
|
||||
context->Intermediate_Hash[2] += C;
|
||||
context->Intermediate_Hash[3] += D;
|
||||
context->Intermediate_Hash[4] += E;
|
||||
context->Intermediate_Hash[5] += F;
|
||||
context->Intermediate_Hash[6] += G;
|
||||
context->Intermediate_Hash[7] += H;
|
||||
|
||||
context->Message_Block_Index = 0;
|
||||
}
|
||||
|
||||
/*
|
||||
* SHA224_256Finalize
|
||||
*
|
||||
* Description:
|
||||
* This helper function finishes off the digest calculations.
|
||||
*
|
||||
* Parameters:
|
||||
* context: [in/out]
|
||||
* The SHA context to update.
|
||||
* Pad_Byte: [in]
|
||||
* The last byte to add to the message block before the 0-padding
|
||||
* and length. This will contain the last bits of the message
|
||||
* followed by another single bit. If the message was an
|
||||
* exact multiple of 8-bits long, Pad_Byte will be 0x80.
|
||||
*
|
||||
* Returns:
|
||||
* sha Error Code.
|
||||
*/
|
||||
static void SHA224_256Finalize(SHA256Context *context,
|
||||
uint8_t Pad_Byte)
|
||||
{
|
||||
int i;
|
||||
SHA224_256PadMessage(context, Pad_Byte);
|
||||
/* message may be sensitive, so clear it out */
|
||||
for (i = 0; i < SHA256_Message_Block_Size; ++i)
|
||||
context->Message_Block[i] = 0;
|
||||
context->Length_High = 0; /* and clear length */
|
||||
context->Length_Low = 0;
|
||||
context->Computed = 1;
|
||||
}
|
||||
|
||||
/*
|
||||
* SHA224_256PadMessage
|
||||
*
|
||||
* Description:
|
||||
* According to the standard, the message must be padded to the next
|
||||
* even multiple of 512 bits. The first padding bit must be a '1'.
|
||||
* The last 64 bits represent the length of the original message.
|
||||
* All bits in between should be 0. This helper function will pad
|
||||
* the message according to those rules by filling the
|
||||
* Message_Block array accordingly. When it returns, it can be
|
||||
* assumed that the message digest has been computed.
|
||||
*
|
||||
* Parameters:
|
||||
* context: [in/out]
|
||||
* The context to pad.
|
||||
* Pad_Byte: [in]
|
||||
* The last byte to add to the message block before the 0-padding
|
||||
* and length. This will contain the last bits of the message
|
||||
* followed by another single bit. If the message was an
|
||||
* exact multiple of 8-bits long, Pad_Byte will be 0x80.
|
||||
*
|
||||
* Returns:
|
||||
* Nothing.
|
||||
*/
|
||||
static void SHA224_256PadMessage(SHA256Context *context,
|
||||
uint8_t Pad_Byte)
|
||||
{
|
||||
/*
|
||||
* Check to see if the current message block is too small to hold
|
||||
* the initial padding bits and length. If so, we will pad the
|
||||
* block, process it, and then continue padding into a second
|
||||
* block.
|
||||
*/
|
||||
if (context->Message_Block_Index >= (SHA256_Message_Block_Size-8)) {
|
||||
context->Message_Block[context->Message_Block_Index++] = Pad_Byte;
|
||||
while (context->Message_Block_Index < SHA256_Message_Block_Size)
|
||||
context->Message_Block[context->Message_Block_Index++] = 0;
|
||||
SHA224_256ProcessMessageBlock(context);
|
||||
} else
|
||||
context->Message_Block[context->Message_Block_Index++] = Pad_Byte;
|
||||
|
||||
while (context->Message_Block_Index < (SHA256_Message_Block_Size-8))
|
||||
context->Message_Block[context->Message_Block_Index++] = 0;
|
||||
|
||||
/*
|
||||
* Store the message length as the last 8 octets
|
||||
*/
|
||||
context->Message_Block[56] = (uint8_t)(context->Length_High >> 24);
|
||||
context->Message_Block[57] = (uint8_t)(context->Length_High >> 16);
|
||||
context->Message_Block[58] = (uint8_t)(context->Length_High >> 8);
|
||||
context->Message_Block[59] = (uint8_t)(context->Length_High);
|
||||
context->Message_Block[60] = (uint8_t)(context->Length_Low >> 24);
|
||||
context->Message_Block[61] = (uint8_t)(context->Length_Low >> 16);
|
||||
context->Message_Block[62] = (uint8_t)(context->Length_Low >> 8);
|
||||
context->Message_Block[63] = (uint8_t)(context->Length_Low);
|
||||
|
||||
SHA224_256ProcessMessageBlock(context);
|
||||
}
|
||||
|
||||
/*
|
||||
* SHA224_256ResultN
|
||||
*
|
||||
* Description:
|
||||
* This helper function will return the 224-bit or 256-bit message
|
||||
* digest into the Message_Digest array provided by the caller.
|
||||
* NOTE:
|
||||
* The first octet of hash is stored in the element with index 0,
|
||||
* the last octet of hash in the element with index 27/31.
|
||||
*
|
||||
* Parameters:
|
||||
* context: [in/out]
|
||||
* The context to use to calculate the SHA hash.
|
||||
* Message_Digest[ ]: [out]
|
||||
* Where the digest is returned.
|
||||
* HashSize: [in]
|
||||
* The size of the hash, either 28 or 32.
|
||||
*
|
||||
* Returns:
|
||||
* sha Error Code.
|
||||
*/
|
||||
static int SHA224_256ResultN(SHA256Context *context,
|
||||
uint8_t Message_Digest[ ], int HashSize)
|
||||
{
|
||||
int i;
|
||||
|
||||
if (!context) return shaNull;
|
||||
if (!Message_Digest) return shaNull;
|
||||
if (context->Corrupted) return context->Corrupted;
|
||||
|
||||
if (!context->Computed)
|
||||
SHA224_256Finalize(context, 0x80);
|
||||
|
||||
for (i = 0; i < HashSize; ++i)
|
||||
Message_Digest[i] = (uint8_t)
|
||||
(context->Intermediate_Hash[i>>2] >> 8 * ( 3 - ( i & 0x03 ) ));
|
||||
|
||||
return shaSuccess;
|
||||
}
|
1034
src/3rdparty/rfc6234/sha384-512.c
vendored
1034
src/3rdparty/rfc6234/sha384-512.c
vendored
File diff suppressed because it is too large
Load diff
256
src/3rdparty/sha1/sha1.cpp
vendored
256
src/3rdparty/sha1/sha1.cpp
vendored
|
@ -1,256 +0,0 @@
|
|||
/****************************************************************************
|
||||
**
|
||||
** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
|
||||
** All rights reserved.
|
||||
** Contact: http://www.qt.io/licensing/
|
||||
**
|
||||
** This file is part of the Qt Toolkit.
|
||||
**
|
||||
** $QT_BEGIN_LICENSE:LGPL$
|
||||
** Commercial License Usage
|
||||
** Licensees holding valid commercial Qt licenses may use this file in
|
||||
** accordance with the commercial license agreement provided with the
|
||||
** Software or, alternatively, in accordance with the terms contained in
|
||||
** a written agreement between you and The Qt Company. For licensing terms
|
||||
** and conditions see http://www.qt.io/terms-conditions. For further
|
||||
** information use the contact form at http://www.qt.io/contact-us.
|
||||
**
|
||||
** GNU Lesser General Public License Usage
|
||||
** Alternatively, this file may be used under the terms of the GNU Lesser
|
||||
** General Public License version 2.1 or version 3 as published by the Free
|
||||
** Software Foundation and appearing in the file LICENSE.LGPLv21 and
|
||||
** LICENSE.LGPLv3 included in the packaging of this file. Please review the
|
||||
** following information to ensure the GNU Lesser General Public License
|
||||
** requirements will be met: https://www.gnu.org/licenses/lgpl.html and
|
||||
** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
|
||||
**
|
||||
** As a special exception, The Qt Company gives you certain additional
|
||||
** rights. These rights are described in The Qt Company LGPL Exception
|
||||
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
|
||||
**
|
||||
** GNU General Public License Usage
|
||||
** Alternatively, this file may be used under the terms of the GNU
|
||||
** General Public License version 3.0 as published by the Free Software
|
||||
** Foundation and appearing in the file LICENSE.GPL included in the
|
||||
** packaging of this file. Please review the following information to
|
||||
** ensure the GNU General Public License version 3.0 requirements will be
|
||||
** met: http://www.gnu.org/copyleft/gpl.html.
|
||||
**
|
||||
** $QT_END_LICENSE$
|
||||
**
|
||||
****************************************************************************/
|
||||
|
||||
/*
|
||||
Based on the public domain implementation of the SHA-1 algorithm
|
||||
Copyright (C) Dominik Reichl <dominik.reichl@t-online.de>
|
||||
*/
|
||||
#include <QtCore/qendian.h>
|
||||
|
||||
QT_BEGIN_NAMESPACE
|
||||
|
||||
// Test Vectors (from FIPS PUB 180-1)
|
||||
//
|
||||
// SHA1("abc") =
|
||||
// A9993E36 4706816A BA3E2571 7850C26C 9CD0D89D
|
||||
//
|
||||
// SHA1("abcdbcdecdefdefgefghfghighijhijkijkljklmklmnlmnomnopnopq") =
|
||||
// 84983E44 1C3BD26E BAAE4AA1 F95129E5 E54670F1
|
||||
//
|
||||
// SHA1(A million repetitions of "a") =
|
||||
// 34AA973C D4C4DAA4 F61EEB2B DBAD2731 6534016F
|
||||
//
|
||||
|
||||
|
||||
// #define or #undef this, if you want the to wipe all
|
||||
// temporary variables after processing
|
||||
#define SHA1_WIPE_VARIABLES
|
||||
|
||||
|
||||
struct Sha1State
|
||||
{
|
||||
quint32 h0;
|
||||
quint32 h1;
|
||||
quint32 h2;
|
||||
quint32 h3;
|
||||
quint32 h4;
|
||||
|
||||
quint64 messageSize;
|
||||
unsigned char buffer[64];
|
||||
};
|
||||
|
||||
|
||||
typedef union
|
||||
{
|
||||
quint8 bytes[64];
|
||||
quint32 words[16];
|
||||
} Sha1Chunk;
|
||||
|
||||
static inline quint32 rol32(quint32 value, unsigned int shift)
|
||||
{
|
||||
return ((value << shift) | (value >> (32 - shift)));
|
||||
}
|
||||
|
||||
static inline quint32 sha1Word(Sha1Chunk *chunk, const uint position)
|
||||
{
|
||||
return (chunk->words[position & 0xf] = rol32( chunk->words[(position+13) & 0xf]
|
||||
^ chunk->words[(position+ 8) & 0xf]
|
||||
^ chunk->words[(position+ 2) & 0xf]
|
||||
^ chunk->words[(position) & 0xf], 1));
|
||||
}
|
||||
|
||||
static inline void sha1Round0(Sha1Chunk *chunk, const uint position,
|
||||
quint32 &v, quint32 &w, quint32 &x, quint32 &y, quint32 &z)
|
||||
{
|
||||
z += ((( w & (x ^ y)) ^ y) + chunk->words[position] + 0x5A827999 + rol32(v, 5));
|
||||
w = rol32(w, 30);
|
||||
}
|
||||
|
||||
static inline void sha1Round1(Sha1Chunk *chunk, const uint position,
|
||||
quint32 &v, quint32 &w, quint32 &x, quint32 &y, quint32 &z)
|
||||
{
|
||||
z += ((( w & (x ^ y)) ^ y) + sha1Word(chunk,position) + 0x5A827999 + rol32(v, 5));
|
||||
w = rol32(w, 30);
|
||||
}
|
||||
|
||||
static inline void sha1Round2(Sha1Chunk *chunk, const uint position,
|
||||
quint32 &v, quint32 &w, quint32 &x, quint32 &y, quint32 &z)
|
||||
{
|
||||
z += (( w ^ x ^ y) + sha1Word(chunk, position) + 0x6ED9EBA1 + rol32(v, 5));
|
||||
w = rol32(w, 30);
|
||||
}
|
||||
|
||||
static inline void sha1Round3(Sha1Chunk *chunk, const uint position,
|
||||
quint32 &v, quint32 &w, quint32 &x, quint32 &y, quint32 &z)
|
||||
{
|
||||
z += (((( w | x) & y) | (w & x)) + sha1Word(chunk, position) + 0x8F1BBCDC + rol32(v, 5));
|
||||
w = rol32(w, 30);
|
||||
}
|
||||
|
||||
static inline void sha1Round4(Sha1Chunk *chunk, const uint position,
|
||||
quint32 &v, quint32 &w, quint32 &x, quint32 &y, quint32 &z)
|
||||
{
|
||||
z += ((w ^ x ^ y) + sha1Word(chunk, position) + 0xCA62C1D6 + rol32(v, 5));
|
||||
w = rol32(w, 30);
|
||||
}
|
||||
|
||||
static inline void sha1ProcessChunk(Sha1State *state, const unsigned char *buffer)
|
||||
{
|
||||
// Copy state[] to working vars
|
||||
quint32 a = state->h0;
|
||||
quint32 b = state->h1;
|
||||
quint32 c = state->h2;
|
||||
quint32 d = state->h3;
|
||||
quint32 e = state->h4;
|
||||
|
||||
quint8 chunkBuffer[64];
|
||||
memcpy(chunkBuffer, buffer, 64);
|
||||
|
||||
Sha1Chunk *chunk = reinterpret_cast<Sha1Chunk*>(&chunkBuffer);
|
||||
|
||||
for (int i = 0; i < 16; ++i)
|
||||
chunk->words[i] = qFromBigEndian(chunk->words[i]);
|
||||
|
||||
sha1Round0(chunk, 0, a,b,c,d,e); sha1Round0(chunk, 1, e,a,b,c,d); sha1Round0(chunk, 2, d,e,a,b,c); sha1Round0(chunk, 3, c,d,e,a,b);
|
||||
sha1Round0(chunk, 4, b,c,d,e,a); sha1Round0(chunk, 5, a,b,c,d,e); sha1Round0(chunk, 6, e,a,b,c,d); sha1Round0(chunk, 7, d,e,a,b,c);
|
||||
sha1Round0(chunk, 8, c,d,e,a,b); sha1Round0(chunk, 9, b,c,d,e,a); sha1Round0(chunk, 10, a,b,c,d,e); sha1Round0(chunk, 11, e,a,b,c,d);
|
||||
sha1Round0(chunk, 12, d,e,a,b,c); sha1Round0(chunk, 13, c,d,e,a,b); sha1Round0(chunk, 14, b,c,d,e,a); sha1Round0(chunk, 15, a,b,c,d,e);
|
||||
sha1Round1(chunk, 16, e,a,b,c,d); sha1Round1(chunk, 17, d,e,a,b,c); sha1Round1(chunk, 18, c,d,e,a,b); sha1Round1(chunk, 19, b,c,d,e,a);
|
||||
sha1Round2(chunk, 20, a,b,c,d,e); sha1Round2(chunk, 21, e,a,b,c,d); sha1Round2(chunk, 22, d,e,a,b,c); sha1Round2(chunk, 23, c,d,e,a,b);
|
||||
sha1Round2(chunk, 24, b,c,d,e,a); sha1Round2(chunk, 25, a,b,c,d,e); sha1Round2(chunk, 26, e,a,b,c,d); sha1Round2(chunk, 27, d,e,a,b,c);
|
||||
sha1Round2(chunk, 28, c,d,e,a,b); sha1Round2(chunk, 29, b,c,d,e,a); sha1Round2(chunk, 30, a,b,c,d,e); sha1Round2(chunk, 31, e,a,b,c,d);
|
||||
sha1Round2(chunk, 32, d,e,a,b,c); sha1Round2(chunk, 33, c,d,e,a,b); sha1Round2(chunk, 34, b,c,d,e,a); sha1Round2(chunk, 35, a,b,c,d,e);
|
||||
sha1Round2(chunk, 36, e,a,b,c,d); sha1Round2(chunk, 37, d,e,a,b,c); sha1Round2(chunk, 38, c,d,e,a,b); sha1Round2(chunk, 39, b,c,d,e,a);
|
||||
sha1Round3(chunk, 40, a,b,c,d,e); sha1Round3(chunk, 41, e,a,b,c,d); sha1Round3(chunk, 42, d,e,a,b,c); sha1Round3(chunk, 43, c,d,e,a,b);
|
||||
sha1Round3(chunk, 44, b,c,d,e,a); sha1Round3(chunk, 45, a,b,c,d,e); sha1Round3(chunk, 46, e,a,b,c,d); sha1Round3(chunk, 47, d,e,a,b,c);
|
||||
sha1Round3(chunk, 48, c,d,e,a,b); sha1Round3(chunk, 49, b,c,d,e,a); sha1Round3(chunk, 50, a,b,c,d,e); sha1Round3(chunk, 51, e,a,b,c,d);
|
||||
sha1Round3(chunk, 52, d,e,a,b,c); sha1Round3(chunk, 53, c,d,e,a,b); sha1Round3(chunk, 54, b,c,d,e,a); sha1Round3(chunk, 55, a,b,c,d,e);
|
||||
sha1Round3(chunk, 56, e,a,b,c,d); sha1Round3(chunk, 57, d,e,a,b,c); sha1Round3(chunk, 58, c,d,e,a,b); sha1Round3(chunk, 59, b,c,d,e,a);
|
||||
sha1Round4(chunk, 60, a,b,c,d,e); sha1Round4(chunk, 61, e,a,b,c,d); sha1Round4(chunk, 62, d,e,a,b,c); sha1Round4(chunk, 63, c,d,e,a,b);
|
||||
sha1Round4(chunk, 64, b,c,d,e,a); sha1Round4(chunk, 65, a,b,c,d,e); sha1Round4(chunk, 66, e,a,b,c,d); sha1Round4(chunk, 67, d,e,a,b,c);
|
||||
sha1Round4(chunk, 68, c,d,e,a,b); sha1Round4(chunk, 69, b,c,d,e,a); sha1Round4(chunk, 70, a,b,c,d,e); sha1Round4(chunk, 71, e,a,b,c,d);
|
||||
sha1Round4(chunk, 72, d,e,a,b,c); sha1Round4(chunk, 73, c,d,e,a,b); sha1Round4(chunk, 74, b,c,d,e,a); sha1Round4(chunk, 75, a,b,c,d,e);
|
||||
sha1Round4(chunk, 76, e,a,b,c,d); sha1Round4(chunk, 77, d,e,a,b,c); sha1Round4(chunk, 78, c,d,e,a,b); sha1Round4(chunk, 79, b,c,d,e,a);
|
||||
|
||||
// Add the working vars back into state
|
||||
state->h0 += a;
|
||||
state->h1 += b;
|
||||
state->h2 += c;
|
||||
state->h3 += d;
|
||||
state->h4 += e;
|
||||
|
||||
// Wipe variables
|
||||
#ifdef SHA1_WIPE_VARIABLES
|
||||
a = b = c = d = e = 0;
|
||||
memset(chunkBuffer, 0, 64);
|
||||
#endif
|
||||
}
|
||||
|
||||
static inline void sha1InitState(Sha1State *state)
|
||||
{
|
||||
state->h0 = 0x67452301;
|
||||
state->h1 = 0xEFCDAB89;
|
||||
state->h2 = 0x98BADCFE;
|
||||
state->h3 = 0x10325476;
|
||||
state->h4 = 0xC3D2E1F0;
|
||||
|
||||
state->messageSize = 0;
|
||||
}
|
||||
|
||||
static inline void sha1Update(Sha1State *state, const unsigned char *data, qint64 len)
|
||||
{
|
||||
quint32 rest = static_cast<quint32>(state->messageSize & Q_UINT64_C(63));
|
||||
|
||||
quint64 availableData = static_cast<quint64>(len) + static_cast<quint64>(rest);
|
||||
state->messageSize += len;
|
||||
|
||||
if (availableData < Q_UINT64_C(64)) {
|
||||
memcpy(&state->buffer[rest], &data[0], len);
|
||||
|
||||
} else {
|
||||
qint64 i = static_cast<qint64>(64 - rest);
|
||||
memcpy(&state->buffer[rest], &data[0], static_cast<qint32>(i));
|
||||
sha1ProcessChunk(state, state->buffer);
|
||||
|
||||
qint64 lastI = len - ((len + rest) & Q_INT64_C(63));
|
||||
for( ; i < lastI; i += 64)
|
||||
sha1ProcessChunk(state, &data[i]);
|
||||
|
||||
memcpy(&state->buffer[0], &data[i], len - i);
|
||||
}
|
||||
}
|
||||
|
||||
static inline void sha1FinalizeState(Sha1State *state)
|
||||
{
|
||||
quint64 messageSize = state->messageSize;
|
||||
unsigned char sizeInBits[8];
|
||||
qToBigEndian(messageSize << 3, sizeInBits);
|
||||
|
||||
sha1Update(state, (const unsigned char *)"\200", 1);
|
||||
|
||||
unsigned char zero[64];
|
||||
memset(zero, 0, 64);
|
||||
if (static_cast<int>(messageSize & 63) > 56 - 1) {
|
||||
sha1Update(state, zero, 64 - 1 - static_cast<int>(messageSize & 63));
|
||||
sha1Update(state, zero, 64 - 8);
|
||||
} else {
|
||||
sha1Update(state, zero, 64 - 1 - 8 - static_cast<int>(messageSize & 63));
|
||||
}
|
||||
|
||||
sha1Update(state, sizeInBits, 8);
|
||||
#ifdef SHA1_WIPE_VARIABLES
|
||||
memset(state->buffer, 0, 64);
|
||||
memset(zero, 0, 64);
|
||||
state->messageSize = 0;
|
||||
#endif
|
||||
}
|
||||
|
||||
static inline void sha1ToHash(Sha1State *state, unsigned char* buffer)
|
||||
{
|
||||
qToBigEndian(state->h0, buffer);
|
||||
qToBigEndian(state->h1, buffer + 4);
|
||||
qToBigEndian(state->h2, buffer + 8);
|
||||
qToBigEndian(state->h3, buffer + 12);
|
||||
qToBigEndian(state->h4, buffer + 16);
|
||||
}
|
||||
|
||||
QT_END_NAMESPACE
|
555
src/3rdparty/sha3/KeccakF-1600-32-rvk.macros
vendored
555
src/3rdparty/sha3/KeccakF-1600-32-rvk.macros
vendored
|
@ -1,555 +0,0 @@
|
|||
/*
|
||||
The Keccak sponge function, designed by Guido Bertoni, Joan Daemen,
|
||||
Michaël Peeters and Gilles Van Assche. For more information, feedback or
|
||||
questions, please refer to our website: http://keccak.noekeon.org/
|
||||
|
||||
Implementation by Ronny Van Keer,
|
||||
hereby denoted as "the implementer".
|
||||
|
||||
To the extent possible under law, the implementer has waived all copyright
|
||||
and related or neighboring rights to the source code in this file.
|
||||
http://creativecommons.org/publicdomain/zero/1.0/
|
||||
*/
|
||||
|
||||
static const UINT32 KeccakF1600RoundConstants_int2[2*24] =
|
||||
{
|
||||
0x00000001UL, 0x00000000UL,
|
||||
0x00000000UL, 0x00000089UL,
|
||||
0x00000000UL, 0x8000008bUL,
|
||||
0x00000000UL, 0x80008080UL,
|
||||
0x00000001UL, 0x0000008bUL,
|
||||
0x00000001UL, 0x00008000UL,
|
||||
0x00000001UL, 0x80008088UL,
|
||||
0x00000001UL, 0x80000082UL,
|
||||
0x00000000UL, 0x0000000bUL,
|
||||
0x00000000UL, 0x0000000aUL,
|
||||
0x00000001UL, 0x00008082UL,
|
||||
0x00000000UL, 0x00008003UL,
|
||||
0x00000001UL, 0x0000808bUL,
|
||||
0x00000001UL, 0x8000000bUL,
|
||||
0x00000001UL, 0x8000008aUL,
|
||||
0x00000001UL, 0x80000081UL,
|
||||
0x00000000UL, 0x80000081UL,
|
||||
0x00000000UL, 0x80000008UL,
|
||||
0x00000000UL, 0x00000083UL,
|
||||
0x00000000UL, 0x80008003UL,
|
||||
0x00000001UL, 0x80008088UL,
|
||||
0x00000000UL, 0x80000088UL,
|
||||
0x00000001UL, 0x00008000UL,
|
||||
0x00000000UL, 0x80008082UL
|
||||
};
|
||||
|
||||
#undef rounds
|
||||
|
||||
#define rounds \
|
||||
{ \
|
||||
UINT32 Da0, De0, Di0, Do0, Du0; \
|
||||
UINT32 Da1, De1, Di1, Do1, Du1; \
|
||||
UINT32 Ba, Be, Bi, Bo, Bu; \
|
||||
UINT32 Aba0, Abe0, Abi0, Abo0, Abu0; \
|
||||
UINT32 Aba1, Abe1, Abi1, Abo1, Abu1; \
|
||||
UINT32 Aga0, Age0, Agi0, Ago0, Agu0; \
|
||||
UINT32 Aga1, Age1, Agi1, Ago1, Agu1; \
|
||||
UINT32 Aka0, Ake0, Aki0, Ako0, Aku0; \
|
||||
UINT32 Aka1, Ake1, Aki1, Ako1, Aku1; \
|
||||
UINT32 Ama0, Ame0, Ami0, Amo0, Amu0; \
|
||||
UINT32 Ama1, Ame1, Ami1, Amo1, Amu1; \
|
||||
UINT32 Asa0, Ase0, Asi0, Aso0, Asu0; \
|
||||
UINT32 Asa1, Ase1, Asi1, Aso1, Asu1; \
|
||||
UINT32 Cw, Cx, Cy, Cz; \
|
||||
UINT32 Eba0, Ebe0, Ebi0, Ebo0, Ebu0; \
|
||||
UINT32 Eba1, Ebe1, Ebi1, Ebo1, Ebu1; \
|
||||
UINT32 Ega0, Ege0, Egi0, Ego0, Egu0; \
|
||||
UINT32 Ega1, Ege1, Egi1, Ego1, Egu1; \
|
||||
UINT32 Eka0, Eke0, Eki0, Eko0, Eku0; \
|
||||
UINT32 Eka1, Eke1, Eki1, Eko1, Eku1; \
|
||||
UINT32 Ema0, Eme0, Emi0, Emo0, Emu0; \
|
||||
UINT32 Ema1, Eme1, Emi1, Emo1, Emu1; \
|
||||
UINT32 Esa0, Ese0, Esi0, Eso0, Esu0; \
|
||||
UINT32 Esa1, Ese1, Esi1, Eso1, Esu1; \
|
||||
const UINT32 * pRoundConstants = KeccakF1600RoundConstants_int2; \
|
||||
UINT32 i; \
|
||||
\
|
||||
copyFromState(A, state) \
|
||||
\
|
||||
for( i = 12; i != 0; --i ) { \
|
||||
Cx = Abu0^Agu0^Aku0^Amu0^Asu0; \
|
||||
Du1 = Abe1^Age1^Ake1^Ame1^Ase1; \
|
||||
Da0 = Cx^ROL32(Du1, 1); \
|
||||
Cz = Abu1^Agu1^Aku1^Amu1^Asu1; \
|
||||
Du0 = Abe0^Age0^Ake0^Ame0^Ase0; \
|
||||
Da1 = Cz^Du0; \
|
||||
\
|
||||
Cw = Abi0^Agi0^Aki0^Ami0^Asi0; \
|
||||
Do0 = Cw^ROL32(Cz, 1); \
|
||||
Cy = Abi1^Agi1^Aki1^Ami1^Asi1; \
|
||||
Do1 = Cy^Cx; \
|
||||
\
|
||||
Cx = Aba0^Aga0^Aka0^Ama0^Asa0; \
|
||||
De0 = Cx^ROL32(Cy, 1); \
|
||||
Cz = Aba1^Aga1^Aka1^Ama1^Asa1; \
|
||||
De1 = Cz^Cw; \
|
||||
\
|
||||
Cy = Abo1^Ago1^Ako1^Amo1^Aso1; \
|
||||
Di0 = Du0^ROL32(Cy, 1); \
|
||||
Cw = Abo0^Ago0^Ako0^Amo0^Aso0; \
|
||||
Di1 = Du1^Cw; \
|
||||
\
|
||||
Du0 = Cw^ROL32(Cz, 1); \
|
||||
Du1 = Cy^Cx; \
|
||||
\
|
||||
Aba0 ^= Da0; \
|
||||
Ba = Aba0; \
|
||||
Age0 ^= De0; \
|
||||
Be = ROL32(Age0, 22); \
|
||||
Aki1 ^= Di1; \
|
||||
Bi = ROL32(Aki1, 22); \
|
||||
Amo1 ^= Do1; \
|
||||
Bo = ROL32(Amo1, 11); \
|
||||
Asu0 ^= Du0; \
|
||||
Bu = ROL32(Asu0, 7); \
|
||||
Eba0 = Ba ^((~Be)& Bi ) ^ *(pRoundConstants++); \
|
||||
Ebe0 = Be ^((~Bi)& Bo ); \
|
||||
Ebi0 = Bi ^((~Bo)& Bu ); \
|
||||
Ebo0 = Bo ^((~Bu)& Ba ); \
|
||||
Ebu0 = Bu ^((~Ba)& Be ); \
|
||||
\
|
||||
Abo0 ^= Do0; \
|
||||
Ba = ROL32(Abo0, 14); \
|
||||
Agu0 ^= Du0; \
|
||||
Be = ROL32(Agu0, 10); \
|
||||
Aka1 ^= Da1; \
|
||||
Bi = ROL32(Aka1, 2); \
|
||||
Ame1 ^= De1; \
|
||||
Bo = ROL32(Ame1, 23); \
|
||||
Asi1 ^= Di1; \
|
||||
Bu = ROL32(Asi1, 31); \
|
||||
Ega0 = Ba ^((~Be)& Bi ); \
|
||||
Ege0 = Be ^((~Bi)& Bo ); \
|
||||
Egi0 = Bi ^((~Bo)& Bu ); \
|
||||
Ego0 = Bo ^((~Bu)& Ba ); \
|
||||
Egu0 = Bu ^((~Ba)& Be ); \
|
||||
\
|
||||
Abe1 ^= De1; \
|
||||
Ba = ROL32(Abe1, 1); \
|
||||
Agi0 ^= Di0; \
|
||||
Be = ROL32(Agi0, 3); \
|
||||
Ako1 ^= Do1; \
|
||||
Bi = ROL32(Ako1, 13); \
|
||||
Amu0 ^= Du0; \
|
||||
Bo = ROL32(Amu0, 4); \
|
||||
Asa0 ^= Da0; \
|
||||
Bu = ROL32(Asa0, 9); \
|
||||
Eka0 = Ba ^((~Be)& Bi ); \
|
||||
Eke0 = Be ^((~Bi)& Bo ); \
|
||||
Eki0 = Bi ^((~Bo)& Bu ); \
|
||||
Eko0 = Bo ^((~Bu)& Ba ); \
|
||||
Eku0 = Bu ^((~Ba)& Be ); \
|
||||
\
|
||||
Abu1 ^= Du1; \
|
||||
Ba = ROL32(Abu1, 14); \
|
||||
Aga0 ^= Da0; \
|
||||
Be = ROL32(Aga0, 18); \
|
||||
Ake0 ^= De0; \
|
||||
Bi = ROL32(Ake0, 5); \
|
||||
Ami1 ^= Di1; \
|
||||
Bo = ROL32(Ami1, 8); \
|
||||
Aso0 ^= Do0; \
|
||||
Bu = ROL32(Aso0, 28); \
|
||||
Ema0 = Ba ^((~Be)& Bi ); \
|
||||
Eme0 = Be ^((~Bi)& Bo ); \
|
||||
Emi0 = Bi ^((~Bo)& Bu ); \
|
||||
Emo0 = Bo ^((~Bu)& Ba ); \
|
||||
Emu0 = Bu ^((~Ba)& Be ); \
|
||||
\
|
||||
Abi0 ^= Di0; \
|
||||
Ba = ROL32(Abi0, 31); \
|
||||
Ago1 ^= Do1; \
|
||||
Be = ROL32(Ago1, 28); \
|
||||
Aku1 ^= Du1; \
|
||||
Bi = ROL32(Aku1, 20); \
|
||||
Ama1 ^= Da1; \
|
||||
Bo = ROL32(Ama1, 21); \
|
||||
Ase0 ^= De0; \
|
||||
Bu = ROL32(Ase0, 1); \
|
||||
Esa0 = Ba ^((~Be)& Bi ); \
|
||||
Ese0 = Be ^((~Bi)& Bo ); \
|
||||
Esi0 = Bi ^((~Bo)& Bu ); \
|
||||
Eso0 = Bo ^((~Bu)& Ba ); \
|
||||
Esu0 = Bu ^((~Ba)& Be ); \
|
||||
\
|
||||
Aba1 ^= Da1; \
|
||||
Ba = Aba1; \
|
||||
Age1 ^= De1; \
|
||||
Be = ROL32(Age1, 22); \
|
||||
Aki0 ^= Di0; \
|
||||
Bi = ROL32(Aki0, 21); \
|
||||
Amo0 ^= Do0; \
|
||||
Bo = ROL32(Amo0, 10); \
|
||||
Asu1 ^= Du1; \
|
||||
Bu = ROL32(Asu1, 7); \
|
||||
Eba1 = Ba ^((~Be)& Bi ); \
|
||||
Eba1 ^= *(pRoundConstants++); \
|
||||
Ebe1 = Be ^((~Bi)& Bo ); \
|
||||
Ebi1 = Bi ^((~Bo)& Bu ); \
|
||||
Ebo1 = Bo ^((~Bu)& Ba ); \
|
||||
Ebu1 = Bu ^((~Ba)& Be ); \
|
||||
\
|
||||
Abo1 ^= Do1; \
|
||||
Ba = ROL32(Abo1, 14); \
|
||||
Agu1 ^= Du1; \
|
||||
Be = ROL32(Agu1, 10); \
|
||||
Aka0 ^= Da0; \
|
||||
Bi = ROL32(Aka0, 1); \
|
||||
Ame0 ^= De0; \
|
||||
Bo = ROL32(Ame0, 22); \
|
||||
Asi0 ^= Di0; \
|
||||
Bu = ROL32(Asi0, 30); \
|
||||
Ega1 = Ba ^((~Be)& Bi ); \
|
||||
Ege1 = Be ^((~Bi)& Bo ); \
|
||||
Egi1 = Bi ^((~Bo)& Bu ); \
|
||||
Ego1 = Bo ^((~Bu)& Ba ); \
|
||||
Egu1 = Bu ^((~Ba)& Be ); \
|
||||
\
|
||||
Abe0 ^= De0; \
|
||||
Ba = Abe0; \
|
||||
Agi1 ^= Di1; \
|
||||
Be = ROL32(Agi1, 3); \
|
||||
Ako0 ^= Do0; \
|
||||
Bi = ROL32(Ako0, 12); \
|
||||
Amu1 ^= Du1; \
|
||||
Bo = ROL32(Amu1, 4); \
|
||||
Asa1 ^= Da1; \
|
||||
Bu = ROL32(Asa1, 9); \
|
||||
Eka1 = Ba ^((~Be)& Bi ); \
|
||||
Eke1 = Be ^((~Bi)& Bo ); \
|
||||
Eki1 = Bi ^((~Bo)& Bu ); \
|
||||
Eko1 = Bo ^((~Bu)& Ba ); \
|
||||
Eku1 = Bu ^((~Ba)& Be ); \
|
||||
\
|
||||
Abu0 ^= Du0; \
|
||||
Ba = ROL32(Abu0, 13); \
|
||||
Aga1 ^= Da1; \
|
||||
Be = ROL32(Aga1, 18); \
|
||||
Ake1 ^= De1; \
|
||||
Bi = ROL32(Ake1, 5); \
|
||||
Ami0 ^= Di0; \
|
||||
Bo = ROL32(Ami0, 7); \
|
||||
Aso1 ^= Do1; \
|
||||
Bu = ROL32(Aso1, 28); \
|
||||
Ema1 = Ba ^((~Be)& Bi ); \
|
||||
Eme1 = Be ^((~Bi)& Bo ); \
|
||||
Emi1 = Bi ^((~Bo)& Bu ); \
|
||||
Emo1 = Bo ^((~Bu)& Ba ); \
|
||||
Emu1 = Bu ^((~Ba)& Be ); \
|
||||
\
|
||||
Abi1 ^= Di1; \
|
||||
Ba = ROL32(Abi1, 31); \
|
||||
Ago0 ^= Do0; \
|
||||
Be = ROL32(Ago0, 27); \
|
||||
Aku0 ^= Du0; \
|
||||
Bi = ROL32(Aku0, 19); \
|
||||
Ama0 ^= Da0; \
|
||||
Bo = ROL32(Ama0, 20); \
|
||||
Ase1 ^= De1; \
|
||||
Bu = ROL32(Ase1, 1); \
|
||||
Esa1 = Ba ^((~Be)& Bi ); \
|
||||
Ese1 = Be ^((~Bi)& Bo ); \
|
||||
Esi1 = Bi ^((~Bo)& Bu ); \
|
||||
Eso1 = Bo ^((~Bu)& Ba ); \
|
||||
Esu1 = Bu ^((~Ba)& Be ); \
|
||||
\
|
||||
Cx = Ebu0^Egu0^Eku0^Emu0^Esu0; \
|
||||
Du1 = Ebe1^Ege1^Eke1^Eme1^Ese1; \
|
||||
Da0 = Cx^ROL32(Du1, 1); \
|
||||
Cz = Ebu1^Egu1^Eku1^Emu1^Esu1; \
|
||||
Du0 = Ebe0^Ege0^Eke0^Eme0^Ese0; \
|
||||
Da1 = Cz^Du0; \
|
||||
\
|
||||
Cw = Ebi0^Egi0^Eki0^Emi0^Esi0; \
|
||||
Do0 = Cw^ROL32(Cz, 1); \
|
||||
Cy = Ebi1^Egi1^Eki1^Emi1^Esi1; \
|
||||
Do1 = Cy^Cx; \
|
||||
\
|
||||
Cx = Eba0^Ega0^Eka0^Ema0^Esa0; \
|
||||
De0 = Cx^ROL32(Cy, 1); \
|
||||
Cz = Eba1^Ega1^Eka1^Ema1^Esa1; \
|
||||
De1 = Cz^Cw; \
|
||||
\
|
||||
Cy = Ebo1^Ego1^Eko1^Emo1^Eso1; \
|
||||
Di0 = Du0^ROL32(Cy, 1); \
|
||||
Cw = Ebo0^Ego0^Eko0^Emo0^Eso0; \
|
||||
Di1 = Du1^Cw; \
|
||||
\
|
||||
Du0 = Cw^ROL32(Cz, 1); \
|
||||
Du1 = Cy^Cx; \
|
||||
\
|
||||
Eba0 ^= Da0; \
|
||||
Ba = Eba0; \
|
||||
Ege0 ^= De0; \
|
||||
Be = ROL32(Ege0, 22); \
|
||||
Eki1 ^= Di1; \
|
||||
Bi = ROL32(Eki1, 22); \
|
||||
Emo1 ^= Do1; \
|
||||
Bo = ROL32(Emo1, 11); \
|
||||
Esu0 ^= Du0; \
|
||||
Bu = ROL32(Esu0, 7); \
|
||||
Aba0 = Ba ^((~Be)& Bi ); \
|
||||
Aba0 ^= *(pRoundConstants++); \
|
||||
Abe0 = Be ^((~Bi)& Bo ); \
|
||||
Abi0 = Bi ^((~Bo)& Bu ); \
|
||||
Abo0 = Bo ^((~Bu)& Ba ); \
|
||||
Abu0 = Bu ^((~Ba)& Be ); \
|
||||
\
|
||||
Ebo0 ^= Do0; \
|
||||
Ba = ROL32(Ebo0, 14); \
|
||||
Egu0 ^= Du0; \
|
||||
Be = ROL32(Egu0, 10); \
|
||||
Eka1 ^= Da1; \
|
||||
Bi = ROL32(Eka1, 2); \
|
||||
Eme1 ^= De1; \
|
||||
Bo = ROL32(Eme1, 23); \
|
||||
Esi1 ^= Di1; \
|
||||
Bu = ROL32(Esi1, 31); \
|
||||
Aga0 = Ba ^((~Be)& Bi ); \
|
||||
Age0 = Be ^((~Bi)& Bo ); \
|
||||
Agi0 = Bi ^((~Bo)& Bu ); \
|
||||
Ago0 = Bo ^((~Bu)& Ba ); \
|
||||
Agu0 = Bu ^((~Ba)& Be ); \
|
||||
\
|
||||
Ebe1 ^= De1; \
|
||||
Ba = ROL32(Ebe1, 1); \
|
||||
Egi0 ^= Di0; \
|
||||
Be = ROL32(Egi0, 3); \
|
||||
Eko1 ^= Do1; \
|
||||
Bi = ROL32(Eko1, 13); \
|
||||
Emu0 ^= Du0; \
|
||||
Bo = ROL32(Emu0, 4); \
|
||||
Esa0 ^= Da0; \
|
||||
Bu = ROL32(Esa0, 9); \
|
||||
Aka0 = Ba ^((~Be)& Bi ); \
|
||||
Ake0 = Be ^((~Bi)& Bo ); \
|
||||
Aki0 = Bi ^((~Bo)& Bu ); \
|
||||
Ako0 = Bo ^((~Bu)& Ba ); \
|
||||
Aku0 = Bu ^((~Ba)& Be ); \
|
||||
\
|
||||
Ebu1 ^= Du1; \
|
||||
Ba = ROL32(Ebu1, 14); \
|
||||
Ega0 ^= Da0; \
|
||||
Be = ROL32(Ega0, 18); \
|
||||
Eke0 ^= De0; \
|
||||
Bi = ROL32(Eke0, 5); \
|
||||
Emi1 ^= Di1; \
|
||||
Bo = ROL32(Emi1, 8); \
|
||||
Eso0 ^= Do0; \
|
||||
Bu = ROL32(Eso0, 28); \
|
||||
Ama0 = Ba ^((~Be)& Bi ); \
|
||||
Ame0 = Be ^((~Bi)& Bo ); \
|
||||
Ami0 = Bi ^((~Bo)& Bu ); \
|
||||
Amo0 = Bo ^((~Bu)& Ba ); \
|
||||
Amu0 = Bu ^((~Ba)& Be ); \
|
||||
\
|
||||
Ebi0 ^= Di0; \
|
||||
Ba = ROL32(Ebi0, 31); \
|
||||
Ego1 ^= Do1; \
|
||||
Be = ROL32(Ego1, 28); \
|
||||
Eku1 ^= Du1; \
|
||||
Bi = ROL32(Eku1, 20); \
|
||||
Ema1 ^= Da1; \
|
||||
Bo = ROL32(Ema1, 21); \
|
||||
Ese0 ^= De0; \
|
||||
Bu = ROL32(Ese0, 1); \
|
||||
Asa0 = Ba ^((~Be)& Bi ); \
|
||||
Ase0 = Be ^((~Bi)& Bo ); \
|
||||
Asi0 = Bi ^((~Bo)& Bu ); \
|
||||
Aso0 = Bo ^((~Bu)& Ba ); \
|
||||
Asu0 = Bu ^((~Ba)& Be ); \
|
||||
\
|
||||
Eba1 ^= Da1; \
|
||||
Ba = Eba1; \
|
||||
Ege1 ^= De1; \
|
||||
Be = ROL32(Ege1, 22); \
|
||||
Eki0 ^= Di0; \
|
||||
Bi = ROL32(Eki0, 21); \
|
||||
Emo0 ^= Do0; \
|
||||
Bo = ROL32(Emo0, 10); \
|
||||
Esu1 ^= Du1; \
|
||||
Bu = ROL32(Esu1, 7); \
|
||||
Aba1 = Ba ^((~Be)& Bi ); \
|
||||
Aba1 ^= *(pRoundConstants++); \
|
||||
Abe1 = Be ^((~Bi)& Bo ); \
|
||||
Abi1 = Bi ^((~Bo)& Bu ); \
|
||||
Abo1 = Bo ^((~Bu)& Ba ); \
|
||||
Abu1 = Bu ^((~Ba)& Be ); \
|
||||
\
|
||||
Ebo1 ^= Do1; \
|
||||
Ba = ROL32(Ebo1, 14); \
|
||||
Egu1 ^= Du1; \
|
||||
Be = ROL32(Egu1, 10); \
|
||||
Eka0 ^= Da0; \
|
||||
Bi = ROL32(Eka0, 1); \
|
||||
Eme0 ^= De0; \
|
||||
Bo = ROL32(Eme0, 22); \
|
||||
Esi0 ^= Di0; \
|
||||
Bu = ROL32(Esi0, 30); \
|
||||
Aga1 = Ba ^((~Be)& Bi ); \
|
||||
Age1 = Be ^((~Bi)& Bo ); \
|
||||
Agi1 = Bi ^((~Bo)& Bu ); \
|
||||
Ago1 = Bo ^((~Bu)& Ba ); \
|
||||
Agu1 = Bu ^((~Ba)& Be ); \
|
||||
\
|
||||
Ebe0 ^= De0; \
|
||||
Ba = Ebe0; \
|
||||
Egi1 ^= Di1; \
|
||||
Be = ROL32(Egi1, 3); \
|
||||
Eko0 ^= Do0; \
|
||||
Bi = ROL32(Eko0, 12); \
|
||||
Emu1 ^= Du1; \
|
||||
Bo = ROL32(Emu1, 4); \
|
||||
Esa1 ^= Da1; \
|
||||
Bu = ROL32(Esa1, 9); \
|
||||
Aka1 = Ba ^((~Be)& Bi ); \
|
||||
Ake1 = Be ^((~Bi)& Bo ); \
|
||||
Aki1 = Bi ^((~Bo)& Bu ); \
|
||||
Ako1 = Bo ^((~Bu)& Ba ); \
|
||||
Aku1 = Bu ^((~Ba)& Be ); \
|
||||
\
|
||||
Ebu0 ^= Du0; \
|
||||
Ba = ROL32(Ebu0, 13); \
|
||||
Ega1 ^= Da1; \
|
||||
Be = ROL32(Ega1, 18); \
|
||||
Eke1 ^= De1; \
|
||||
Bi = ROL32(Eke1, 5); \
|
||||
Emi0 ^= Di0; \
|
||||
Bo = ROL32(Emi0, 7); \
|
||||
Eso1 ^= Do1; \
|
||||
Bu = ROL32(Eso1, 28); \
|
||||
Ama1 = Ba ^((~Be)& Bi ); \
|
||||
Ame1 = Be ^((~Bi)& Bo ); \
|
||||
Ami1 = Bi ^((~Bo)& Bu ); \
|
||||
Amo1 = Bo ^((~Bu)& Ba ); \
|
||||
Amu1 = Bu ^((~Ba)& Be ); \
|
||||
\
|
||||
Ebi1 ^= Di1; \
|
||||
Ba = ROL32(Ebi1, 31); \
|
||||
Ego0 ^= Do0; \
|
||||
Be = ROL32(Ego0, 27); \
|
||||
Eku0 ^= Du0; \
|
||||
Bi = ROL32(Eku0, 19); \
|
||||
Ema0 ^= Da0; \
|
||||
Bo = ROL32(Ema0, 20); \
|
||||
Ese1 ^= De1; \
|
||||
Bu = ROL32(Ese1, 1); \
|
||||
Asa1 = Ba ^((~Be)& Bi ); \
|
||||
Ase1 = Be ^((~Bi)& Bo ); \
|
||||
Asi1 = Bi ^((~Bo)& Bu ); \
|
||||
Aso1 = Bo ^((~Bu)& Ba ); \
|
||||
Asu1 = Bu ^((~Ba)& Be ); \
|
||||
} \
|
||||
copyToState(state, A) \
|
||||
}
|
||||
|
||||
#define copyFromState(X, state) \
|
||||
X##ba0 = state[ 0]; \
|
||||
X##ba1 = state[ 1]; \
|
||||
X##be0 = state[ 2]; \
|
||||
X##be1 = state[ 3]; \
|
||||
X##bi0 = state[ 4]; \
|
||||
X##bi1 = state[ 5]; \
|
||||
X##bo0 = state[ 6]; \
|
||||
X##bo1 = state[ 7]; \
|
||||
X##bu0 = state[ 8]; \
|
||||
X##bu1 = state[ 9]; \
|
||||
X##ga0 = state[10]; \
|
||||
X##ga1 = state[11]; \
|
||||
X##ge0 = state[12]; \
|
||||
X##ge1 = state[13]; \
|
||||
X##gi0 = state[14]; \
|
||||
X##gi1 = state[15]; \
|
||||
X##go0 = state[16]; \
|
||||
X##go1 = state[17]; \
|
||||
X##gu0 = state[18]; \
|
||||
X##gu1 = state[19]; \
|
||||
X##ka0 = state[20]; \
|
||||
X##ka1 = state[21]; \
|
||||
X##ke0 = state[22]; \
|
||||
X##ke1 = state[23]; \
|
||||
X##ki0 = state[24]; \
|
||||
X##ki1 = state[25]; \
|
||||
X##ko0 = state[26]; \
|
||||
X##ko1 = state[27]; \
|
||||
X##ku0 = state[28]; \
|
||||
X##ku1 = state[29]; \
|
||||
X##ma0 = state[30]; \
|
||||
X##ma1 = state[31]; \
|
||||
X##me0 = state[32]; \
|
||||
X##me1 = state[33]; \
|
||||
X##mi0 = state[34]; \
|
||||
X##mi1 = state[35]; \
|
||||
X##mo0 = state[36]; \
|
||||
X##mo1 = state[37]; \
|
||||
X##mu0 = state[38]; \
|
||||
X##mu1 = state[39]; \
|
||||
X##sa0 = state[40]; \
|
||||
X##sa1 = state[41]; \
|
||||
X##se0 = state[42]; \
|
||||
X##se1 = state[43]; \
|
||||
X##si0 = state[44]; \
|
||||
X##si1 = state[45]; \
|
||||
X##so0 = state[46]; \
|
||||
X##so1 = state[47]; \
|
||||
X##su0 = state[48]; \
|
||||
X##su1 = state[49]; \
|
||||
|
||||
#define copyToState(state, X) \
|
||||
state[ 0] = X##ba0; \
|
||||
state[ 1] = X##ba1; \
|
||||
state[ 2] = X##be0; \
|
||||
state[ 3] = X##be1; \
|
||||
state[ 4] = X##bi0; \
|
||||
state[ 5] = X##bi1; \
|
||||
state[ 6] = X##bo0; \
|
||||
state[ 7] = X##bo1; \
|
||||
state[ 8] = X##bu0; \
|
||||
state[ 9] = X##bu1; \
|
||||
state[10] = X##ga0; \
|
||||
state[11] = X##ga1; \
|
||||
state[12] = X##ge0; \
|
||||
state[13] = X##ge1; \
|
||||
state[14] = X##gi0; \
|
||||
state[15] = X##gi1; \
|
||||
state[16] = X##go0; \
|
||||
state[17] = X##go1; \
|
||||
state[18] = X##gu0; \
|
||||
state[19] = X##gu1; \
|
||||
state[20] = X##ka0; \
|
||||
state[21] = X##ka1; \
|
||||
state[22] = X##ke0; \
|
||||
state[23] = X##ke1; \
|
||||
state[24] = X##ki0; \
|
||||
state[25] = X##ki1; \
|
||||
state[26] = X##ko0; \
|
||||
state[27] = X##ko1; \
|
||||
state[28] = X##ku0; \
|
||||
state[29] = X##ku1; \
|
||||
state[30] = X##ma0; \
|
||||
state[31] = X##ma1; \
|
||||
state[32] = X##me0; \
|
||||
state[33] = X##me1; \
|
||||
state[34] = X##mi0; \
|
||||
state[35] = X##mi1; \
|
||||
state[36] = X##mo0; \
|
||||
state[37] = X##mo1; \
|
||||
state[38] = X##mu0; \
|
||||
state[39] = X##mu1; \
|
||||
state[40] = X##sa0; \
|
||||
state[41] = X##sa1; \
|
||||
state[42] = X##se0; \
|
||||
state[43] = X##se1; \
|
||||
state[44] = X##si0; \
|
||||
state[45] = X##si1; \
|
||||
state[46] = X##so0; \
|
||||
state[47] = X##so1; \
|
||||
state[48] = X##su0; \
|
||||
state[49] = X##su1; \
|
||||
|
26
src/3rdparty/sha3/KeccakF-1600-32.macros
vendored
26
src/3rdparty/sha3/KeccakF-1600-32.macros
vendored
|
@ -1,26 +0,0 @@
|
|||
/*
|
||||
The Keccak sponge function, designed by Guido Bertoni, Joan Daemen,
|
||||
Michaël Peeters and Gilles Van Assche. For more information, feedback or
|
||||
questions, please refer to our website: http://keccak.noekeon.org/
|
||||
|
||||
Implementation by the designers,
|
||||
hereby denoted as "the implementer".
|
||||
|
||||
To the extent possible under law, the implementer has waived all copyright
|
||||
and related or neighboring rights to the source code in this file.
|
||||
http://creativecommons.org/publicdomain/zero/1.0/
|
||||
*/
|
||||
|
||||
#ifdef UseSchedule
|
||||
#if (UseSchedule == 1)
|
||||
#include "KeccakF-1600-32-s1.macros"
|
||||
#elif (UseSchedule == 2)
|
||||
#include "KeccakF-1600-32-s2.macros"
|
||||
#elif (UseSchedule == 3)
|
||||
#include "KeccakF-1600-32-rvk.macros"
|
||||
#else
|
||||
#error "This schedule is not supported."
|
||||
#endif
|
||||
#else
|
||||
#include "KeccakF-1600-32-s1.macros"
|
||||
#endif
|
728
src/3rdparty/sha3/KeccakF-1600-64.macros
vendored
728
src/3rdparty/sha3/KeccakF-1600-64.macros
vendored
|
@ -1,728 +0,0 @@
|
|||
/*
|
||||
Code automatically generated by KeccakTools!
|
||||
|
||||
The Keccak sponge function, designed by Guido Bertoni, Joan Daemen,
|
||||
Michaël Peeters and Gilles Van Assche. For more information, feedback or
|
||||
questions, please refer to our website: http://keccak.noekeon.org/
|
||||
|
||||
Implementation by the designers,
|
||||
hereby denoted as "the implementer".
|
||||
|
||||
To the extent possible under law, the implementer has waived all copyright
|
||||
and related or neighboring rights to the source code in this file.
|
||||
http://creativecommons.org/publicdomain/zero/1.0/
|
||||
*/
|
||||
|
||||
#define declareABCDE \
|
||||
UINT64 Aba, Abe, Abi, Abo, Abu; \
|
||||
UINT64 Aga, Age, Agi, Ago, Agu; \
|
||||
UINT64 Aka, Ake, Aki, Ako, Aku; \
|
||||
UINT64 Ama, Ame, Ami, Amo, Amu; \
|
||||
UINT64 Asa, Ase, Asi, Aso, Asu; \
|
||||
UINT64 Bba, Bbe, Bbi, Bbo, Bbu; \
|
||||
UINT64 Bga, Bge, Bgi, Bgo, Bgu; \
|
||||
UINT64 Bka, Bke, Bki, Bko, Bku; \
|
||||
UINT64 Bma, Bme, Bmi, Bmo, Bmu; \
|
||||
UINT64 Bsa, Bse, Bsi, Bso, Bsu; \
|
||||
UINT64 Ca, Ce, Ci, Co, Cu; \
|
||||
UINT64 Da, De, Di, Do, Du; \
|
||||
UINT64 Eba, Ebe, Ebi, Ebo, Ebu; \
|
||||
UINT64 Ega, Ege, Egi, Ego, Egu; \
|
||||
UINT64 Eka, Eke, Eki, Eko, Eku; \
|
||||
UINT64 Ema, Eme, Emi, Emo, Emu; \
|
||||
UINT64 Esa, Ese, Esi, Eso, Esu; \
|
||||
|
||||
#define prepareTheta \
|
||||
Ca = Aba^Aga^Aka^Ama^Asa; \
|
||||
Ce = Abe^Age^Ake^Ame^Ase; \
|
||||
Ci = Abi^Agi^Aki^Ami^Asi; \
|
||||
Co = Abo^Ago^Ako^Amo^Aso; \
|
||||
Cu = Abu^Agu^Aku^Amu^Asu; \
|
||||
|
||||
#ifdef UseBebigokimisa
|
||||
// --- Code for round, with prepare-theta (lane complementing pattern 'bebigokimisa')
|
||||
// --- 64-bit lanes mapped to 64-bit words
|
||||
#define thetaRhoPiChiIotaPrepareTheta(i, A, E) \
|
||||
Da = Cu^ROL64(Ce, 1); \
|
||||
De = Ca^ROL64(Ci, 1); \
|
||||
Di = Ce^ROL64(Co, 1); \
|
||||
Do = Ci^ROL64(Cu, 1); \
|
||||
Du = Co^ROL64(Ca, 1); \
|
||||
\
|
||||
A##ba ^= Da; \
|
||||
Bba = A##ba; \
|
||||
A##ge ^= De; \
|
||||
Bbe = ROL64(A##ge, 44); \
|
||||
A##ki ^= Di; \
|
||||
Bbi = ROL64(A##ki, 43); \
|
||||
A##mo ^= Do; \
|
||||
Bbo = ROL64(A##mo, 21); \
|
||||
A##su ^= Du; \
|
||||
Bbu = ROL64(A##su, 14); \
|
||||
E##ba = Bba ^( Bbe | Bbi ); \
|
||||
E##ba ^= KeccakF1600RoundConstants[i]; \
|
||||
Ca = E##ba; \
|
||||
E##be = Bbe ^((~Bbi)| Bbo ); \
|
||||
Ce = E##be; \
|
||||
E##bi = Bbi ^( Bbo & Bbu ); \
|
||||
Ci = E##bi; \
|
||||
E##bo = Bbo ^( Bbu | Bba ); \
|
||||
Co = E##bo; \
|
||||
E##bu = Bbu ^( Bba & Bbe ); \
|
||||
Cu = E##bu; \
|
||||
\
|
||||
A##bo ^= Do; \
|
||||
Bga = ROL64(A##bo, 28); \
|
||||
A##gu ^= Du; \
|
||||
Bge = ROL64(A##gu, 20); \
|
||||
A##ka ^= Da; \
|
||||
Bgi = ROL64(A##ka, 3); \
|
||||
A##me ^= De; \
|
||||
Bgo = ROL64(A##me, 45); \
|
||||
A##si ^= Di; \
|
||||
Bgu = ROL64(A##si, 61); \
|
||||
E##ga = Bga ^( Bge | Bgi ); \
|
||||
Ca ^= E##ga; \
|
||||
E##ge = Bge ^( Bgi & Bgo ); \
|
||||
Ce ^= E##ge; \
|
||||
E##gi = Bgi ^( Bgo |(~Bgu)); \
|
||||
Ci ^= E##gi; \
|
||||
E##go = Bgo ^( Bgu | Bga ); \
|
||||
Co ^= E##go; \
|
||||
E##gu = Bgu ^( Bga & Bge ); \
|
||||
Cu ^= E##gu; \
|
||||
\
|
||||
A##be ^= De; \
|
||||
Bka = ROL64(A##be, 1); \
|
||||
A##gi ^= Di; \
|
||||
Bke = ROL64(A##gi, 6); \
|
||||
A##ko ^= Do; \
|
||||
Bki = ROL64(A##ko, 25); \
|
||||
A##mu ^= Du; \
|
||||
Bko = ROL64(A##mu, 8); \
|
||||
A##sa ^= Da; \
|
||||
Bku = ROL64(A##sa, 18); \
|
||||
E##ka = Bka ^( Bke | Bki ); \
|
||||
Ca ^= E##ka; \
|
||||
E##ke = Bke ^( Bki & Bko ); \
|
||||
Ce ^= E##ke; \
|
||||
E##ki = Bki ^((~Bko)& Bku ); \
|
||||
Ci ^= E##ki; \
|
||||
E##ko = (~Bko)^( Bku | Bka ); \
|
||||
Co ^= E##ko; \
|
||||
E##ku = Bku ^( Bka & Bke ); \
|
||||
Cu ^= E##ku; \
|
||||
\
|
||||
A##bu ^= Du; \
|
||||
Bma = ROL64(A##bu, 27); \
|
||||
A##ga ^= Da; \
|
||||
Bme = ROL64(A##ga, 36); \
|
||||
A##ke ^= De; \
|
||||
Bmi = ROL64(A##ke, 10); \
|
||||
A##mi ^= Di; \
|
||||
Bmo = ROL64(A##mi, 15); \
|
||||
A##so ^= Do; \
|
||||
Bmu = ROL64(A##so, 56); \
|
||||
E##ma = Bma ^( Bme & Bmi ); \
|
||||
Ca ^= E##ma; \
|
||||
E##me = Bme ^( Bmi | Bmo ); \
|
||||
Ce ^= E##me; \
|
||||
E##mi = Bmi ^((~Bmo)| Bmu ); \
|
||||
Ci ^= E##mi; \
|
||||
E##mo = (~Bmo)^( Bmu & Bma ); \
|
||||
Co ^= E##mo; \
|
||||
E##mu = Bmu ^( Bma | Bme ); \
|
||||
Cu ^= E##mu; \
|
||||
\
|
||||
A##bi ^= Di; \
|
||||
Bsa = ROL64(A##bi, 62); \
|
||||
A##go ^= Do; \
|
||||
Bse = ROL64(A##go, 55); \
|
||||
A##ku ^= Du; \
|
||||
Bsi = ROL64(A##ku, 39); \
|
||||
A##ma ^= Da; \
|
||||
Bso = ROL64(A##ma, 41); \
|
||||
A##se ^= De; \
|
||||
Bsu = ROL64(A##se, 2); \
|
||||
E##sa = Bsa ^((~Bse)& Bsi ); \
|
||||
Ca ^= E##sa; \
|
||||
E##se = (~Bse)^( Bsi | Bso ); \
|
||||
Ce ^= E##se; \
|
||||
E##si = Bsi ^( Bso & Bsu ); \
|
||||
Ci ^= E##si; \
|
||||
E##so = Bso ^( Bsu | Bsa ); \
|
||||
Co ^= E##so; \
|
||||
E##su = Bsu ^( Bsa & Bse ); \
|
||||
Cu ^= E##su; \
|
||||
\
|
||||
|
||||
// --- Code for round (lane complementing pattern 'bebigokimisa')
|
||||
// --- 64-bit lanes mapped to 64-bit words
|
||||
#define thetaRhoPiChiIota(i, A, E) \
|
||||
Da = Cu^ROL64(Ce, 1); \
|
||||
De = Ca^ROL64(Ci, 1); \
|
||||
Di = Ce^ROL64(Co, 1); \
|
||||
Do = Ci^ROL64(Cu, 1); \
|
||||
Du = Co^ROL64(Ca, 1); \
|
||||
\
|
||||
A##ba ^= Da; \
|
||||
Bba = A##ba; \
|
||||
A##ge ^= De; \
|
||||
Bbe = ROL64(A##ge, 44); \
|
||||
A##ki ^= Di; \
|
||||
Bbi = ROL64(A##ki, 43); \
|
||||
A##mo ^= Do; \
|
||||
Bbo = ROL64(A##mo, 21); \
|
||||
A##su ^= Du; \
|
||||
Bbu = ROL64(A##su, 14); \
|
||||
E##ba = Bba ^( Bbe | Bbi ); \
|
||||
E##ba ^= KeccakF1600RoundConstants[i]; \
|
||||
E##be = Bbe ^((~Bbi)| Bbo ); \
|
||||
E##bi = Bbi ^( Bbo & Bbu ); \
|
||||
E##bo = Bbo ^( Bbu | Bba ); \
|
||||
E##bu = Bbu ^( Bba & Bbe ); \
|
||||
\
|
||||
A##bo ^= Do; \
|
||||
Bga = ROL64(A##bo, 28); \
|
||||
A##gu ^= Du; \
|
||||
Bge = ROL64(A##gu, 20); \
|
||||
A##ka ^= Da; \
|
||||
Bgi = ROL64(A##ka, 3); \
|
||||
A##me ^= De; \
|
||||
Bgo = ROL64(A##me, 45); \
|
||||
A##si ^= Di; \
|
||||
Bgu = ROL64(A##si, 61); \
|
||||
E##ga = Bga ^( Bge | Bgi ); \
|
||||
E##ge = Bge ^( Bgi & Bgo ); \
|
||||
E##gi = Bgi ^( Bgo |(~Bgu)); \
|
||||
E##go = Bgo ^( Bgu | Bga ); \
|
||||
E##gu = Bgu ^( Bga & Bge ); \
|
||||
\
|
||||
A##be ^= De; \
|
||||
Bka = ROL64(A##be, 1); \
|
||||
A##gi ^= Di; \
|
||||
Bke = ROL64(A##gi, 6); \
|
||||
A##ko ^= Do; \
|
||||
Bki = ROL64(A##ko, 25); \
|
||||
A##mu ^= Du; \
|
||||
Bko = ROL64(A##mu, 8); \
|
||||
A##sa ^= Da; \
|
||||
Bku = ROL64(A##sa, 18); \
|
||||
E##ka = Bka ^( Bke | Bki ); \
|
||||
E##ke = Bke ^( Bki & Bko ); \
|
||||
E##ki = Bki ^((~Bko)& Bku ); \
|
||||
E##ko = (~Bko)^( Bku | Bka ); \
|
||||
E##ku = Bku ^( Bka & Bke ); \
|
||||
\
|
||||
A##bu ^= Du; \
|
||||
Bma = ROL64(A##bu, 27); \
|
||||
A##ga ^= Da; \
|
||||
Bme = ROL64(A##ga, 36); \
|
||||
A##ke ^= De; \
|
||||
Bmi = ROL64(A##ke, 10); \
|
||||
A##mi ^= Di; \
|
||||
Bmo = ROL64(A##mi, 15); \
|
||||
A##so ^= Do; \
|
||||
Bmu = ROL64(A##so, 56); \
|
||||
E##ma = Bma ^( Bme & Bmi ); \
|
||||
E##me = Bme ^( Bmi | Bmo ); \
|
||||
E##mi = Bmi ^((~Bmo)| Bmu ); \
|
||||
E##mo = (~Bmo)^( Bmu & Bma ); \
|
||||
E##mu = Bmu ^( Bma | Bme ); \
|
||||
\
|
||||
A##bi ^= Di; \
|
||||
Bsa = ROL64(A##bi, 62); \
|
||||
A##go ^= Do; \
|
||||
Bse = ROL64(A##go, 55); \
|
||||
A##ku ^= Du; \
|
||||
Bsi = ROL64(A##ku, 39); \
|
||||
A##ma ^= Da; \
|
||||
Bso = ROL64(A##ma, 41); \
|
||||
A##se ^= De; \
|
||||
Bsu = ROL64(A##se, 2); \
|
||||
E##sa = Bsa ^((~Bse)& Bsi ); \
|
||||
E##se = (~Bse)^( Bsi | Bso ); \
|
||||
E##si = Bsi ^( Bso & Bsu ); \
|
||||
E##so = Bso ^( Bsu | Bsa ); \
|
||||
E##su = Bsu ^( Bsa & Bse ); \
|
||||
\
|
||||
|
||||
#else // UseBebigokimisa
|
||||
// --- Code for round, with prepare-theta
|
||||
// --- 64-bit lanes mapped to 64-bit words
|
||||
#define thetaRhoPiChiIotaPrepareTheta(i, A, E) \
|
||||
Da = Cu^ROL64(Ce, 1); \
|
||||
De = Ca^ROL64(Ci, 1); \
|
||||
Di = Ce^ROL64(Co, 1); \
|
||||
Do = Ci^ROL64(Cu, 1); \
|
||||
Du = Co^ROL64(Ca, 1); \
|
||||
\
|
||||
A##ba ^= Da; \
|
||||
Bba = A##ba; \
|
||||
A##ge ^= De; \
|
||||
Bbe = ROL64(A##ge, 44); \
|
||||
A##ki ^= Di; \
|
||||
Bbi = ROL64(A##ki, 43); \
|
||||
A##mo ^= Do; \
|
||||
Bbo = ROL64(A##mo, 21); \
|
||||
A##su ^= Du; \
|
||||
Bbu = ROL64(A##su, 14); \
|
||||
E##ba = Bba ^((~Bbe)& Bbi ); \
|
||||
E##ba ^= KeccakF1600RoundConstants[i]; \
|
||||
Ca = E##ba; \
|
||||
E##be = Bbe ^((~Bbi)& Bbo ); \
|
||||
Ce = E##be; \
|
||||
E##bi = Bbi ^((~Bbo)& Bbu ); \
|
||||
Ci = E##bi; \
|
||||
E##bo = Bbo ^((~Bbu)& Bba ); \
|
||||
Co = E##bo; \
|
||||
E##bu = Bbu ^((~Bba)& Bbe ); \
|
||||
Cu = E##bu; \
|
||||
\
|
||||
A##bo ^= Do; \
|
||||
Bga = ROL64(A##bo, 28); \
|
||||
A##gu ^= Du; \
|
||||
Bge = ROL64(A##gu, 20); \
|
||||
A##ka ^= Da; \
|
||||
Bgi = ROL64(A##ka, 3); \
|
||||
A##me ^= De; \
|
||||
Bgo = ROL64(A##me, 45); \
|
||||
A##si ^= Di; \
|
||||
Bgu = ROL64(A##si, 61); \
|
||||
E##ga = Bga ^((~Bge)& Bgi ); \
|
||||
Ca ^= E##ga; \
|
||||
E##ge = Bge ^((~Bgi)& Bgo ); \
|
||||
Ce ^= E##ge; \
|
||||
E##gi = Bgi ^((~Bgo)& Bgu ); \
|
||||
Ci ^= E##gi; \
|
||||
E##go = Bgo ^((~Bgu)& Bga ); \
|
||||
Co ^= E##go; \
|
||||
E##gu = Bgu ^((~Bga)& Bge ); \
|
||||
Cu ^= E##gu; \
|
||||
\
|
||||
A##be ^= De; \
|
||||
Bka = ROL64(A##be, 1); \
|
||||
A##gi ^= Di; \
|
||||
Bke = ROL64(A##gi, 6); \
|
||||
A##ko ^= Do; \
|
||||
Bki = ROL64(A##ko, 25); \
|
||||
A##mu ^= Du; \
|
||||
Bko = ROL64(A##mu, 8); \
|
||||
A##sa ^= Da; \
|
||||
Bku = ROL64(A##sa, 18); \
|
||||
E##ka = Bka ^((~Bke)& Bki ); \
|
||||
Ca ^= E##ka; \
|
||||
E##ke = Bke ^((~Bki)& Bko ); \
|
||||
Ce ^= E##ke; \
|
||||
E##ki = Bki ^((~Bko)& Bku ); \
|
||||
Ci ^= E##ki; \
|
||||
E##ko = Bko ^((~Bku)& Bka ); \
|
||||
Co ^= E##ko; \
|
||||
E##ku = Bku ^((~Bka)& Bke ); \
|
||||
Cu ^= E##ku; \
|
||||
\
|
||||
A##bu ^= Du; \
|
||||
Bma = ROL64(A##bu, 27); \
|
||||
A##ga ^= Da; \
|
||||
Bme = ROL64(A##ga, 36); \
|
||||
A##ke ^= De; \
|
||||
Bmi = ROL64(A##ke, 10); \
|
||||
A##mi ^= Di; \
|
||||
Bmo = ROL64(A##mi, 15); \
|
||||
A##so ^= Do; \
|
||||
Bmu = ROL64(A##so, 56); \
|
||||
E##ma = Bma ^((~Bme)& Bmi ); \
|
||||
Ca ^= E##ma; \
|
||||
E##me = Bme ^((~Bmi)& Bmo ); \
|
||||
Ce ^= E##me; \
|
||||
E##mi = Bmi ^((~Bmo)& Bmu ); \
|
||||
Ci ^= E##mi; \
|
||||
E##mo = Bmo ^((~Bmu)& Bma ); \
|
||||
Co ^= E##mo; \
|
||||
E##mu = Bmu ^((~Bma)& Bme ); \
|
||||
Cu ^= E##mu; \
|
||||
\
|
||||
A##bi ^= Di; \
|
||||
Bsa = ROL64(A##bi, 62); \
|
||||
A##go ^= Do; \
|
||||
Bse = ROL64(A##go, 55); \
|
||||
A##ku ^= Du; \
|
||||
Bsi = ROL64(A##ku, 39); \
|
||||
A##ma ^= Da; \
|
||||
Bso = ROL64(A##ma, 41); \
|
||||
A##se ^= De; \
|
||||
Bsu = ROL64(A##se, 2); \
|
||||
E##sa = Bsa ^((~Bse)& Bsi ); \
|
||||
Ca ^= E##sa; \
|
||||
E##se = Bse ^((~Bsi)& Bso ); \
|
||||
Ce ^= E##se; \
|
||||
E##si = Bsi ^((~Bso)& Bsu ); \
|
||||
Ci ^= E##si; \
|
||||
E##so = Bso ^((~Bsu)& Bsa ); \
|
||||
Co ^= E##so; \
|
||||
E##su = Bsu ^((~Bsa)& Bse ); \
|
||||
Cu ^= E##su; \
|
||||
\
|
||||
|
||||
// --- Code for round
|
||||
// --- 64-bit lanes mapped to 64-bit words
|
||||
#define thetaRhoPiChiIota(i, A, E) \
|
||||
Da = Cu^ROL64(Ce, 1); \
|
||||
De = Ca^ROL64(Ci, 1); \
|
||||
Di = Ce^ROL64(Co, 1); \
|
||||
Do = Ci^ROL64(Cu, 1); \
|
||||
Du = Co^ROL64(Ca, 1); \
|
||||
\
|
||||
A##ba ^= Da; \
|
||||
Bba = A##ba; \
|
||||
A##ge ^= De; \
|
||||
Bbe = ROL64(A##ge, 44); \
|
||||
A##ki ^= Di; \
|
||||
Bbi = ROL64(A##ki, 43); \
|
||||
A##mo ^= Do; \
|
||||
Bbo = ROL64(A##mo, 21); \
|
||||
A##su ^= Du; \
|
||||
Bbu = ROL64(A##su, 14); \
|
||||
E##ba = Bba ^((~Bbe)& Bbi ); \
|
||||
E##ba ^= KeccakF1600RoundConstants[i]; \
|
||||
E##be = Bbe ^((~Bbi)& Bbo ); \
|
||||
E##bi = Bbi ^((~Bbo)& Bbu ); \
|
||||
E##bo = Bbo ^((~Bbu)& Bba ); \
|
||||
E##bu = Bbu ^((~Bba)& Bbe ); \
|
||||
\
|
||||
A##bo ^= Do; \
|
||||
Bga = ROL64(A##bo, 28); \
|
||||
A##gu ^= Du; \
|
||||
Bge = ROL64(A##gu, 20); \
|
||||
A##ka ^= Da; \
|
||||
Bgi = ROL64(A##ka, 3); \
|
||||
A##me ^= De; \
|
||||
Bgo = ROL64(A##me, 45); \
|
||||
A##si ^= Di; \
|
||||
Bgu = ROL64(A##si, 61); \
|
||||
E##ga = Bga ^((~Bge)& Bgi ); \
|
||||
E##ge = Bge ^((~Bgi)& Bgo ); \
|
||||
E##gi = Bgi ^((~Bgo)& Bgu ); \
|
||||
E##go = Bgo ^((~Bgu)& Bga ); \
|
||||
E##gu = Bgu ^((~Bga)& Bge ); \
|
||||
\
|
||||
A##be ^= De; \
|
||||
Bka = ROL64(A##be, 1); \
|
||||
A##gi ^= Di; \
|
||||
Bke = ROL64(A##gi, 6); \
|
||||
A##ko ^= Do; \
|
||||
Bki = ROL64(A##ko, 25); \
|
||||
A##mu ^= Du; \
|
||||
Bko = ROL64(A##mu, 8); \
|
||||
A##sa ^= Da; \
|
||||
Bku = ROL64(A##sa, 18); \
|
||||
E##ka = Bka ^((~Bke)& Bki ); \
|
||||
E##ke = Bke ^((~Bki)& Bko ); \
|
||||
E##ki = Bki ^((~Bko)& Bku ); \
|
||||
E##ko = Bko ^((~Bku)& Bka ); \
|
||||
E##ku = Bku ^((~Bka)& Bke ); \
|
||||
\
|
||||
A##bu ^= Du; \
|
||||
Bma = ROL64(A##bu, 27); \
|
||||
A##ga ^= Da; \
|
||||
Bme = ROL64(A##ga, 36); \
|
||||
A##ke ^= De; \
|
||||
Bmi = ROL64(A##ke, 10); \
|
||||
A##mi ^= Di; \
|
||||
Bmo = ROL64(A##mi, 15); \
|
||||
A##so ^= Do; \
|
||||
Bmu = ROL64(A##so, 56); \
|
||||
E##ma = Bma ^((~Bme)& Bmi ); \
|
||||
E##me = Bme ^((~Bmi)& Bmo ); \
|
||||
E##mi = Bmi ^((~Bmo)& Bmu ); \
|
||||
E##mo = Bmo ^((~Bmu)& Bma ); \
|
||||
E##mu = Bmu ^((~Bma)& Bme ); \
|
||||
\
|
||||
A##bi ^= Di; \
|
||||
Bsa = ROL64(A##bi, 62); \
|
||||
A##go ^= Do; \
|
||||
Bse = ROL64(A##go, 55); \
|
||||
A##ku ^= Du; \
|
||||
Bsi = ROL64(A##ku, 39); \
|
||||
A##ma ^= Da; \
|
||||
Bso = ROL64(A##ma, 41); \
|
||||
A##se ^= De; \
|
||||
Bsu = ROL64(A##se, 2); \
|
||||
E##sa = Bsa ^((~Bse)& Bsi ); \
|
||||
E##se = Bse ^((~Bsi)& Bso ); \
|
||||
E##si = Bsi ^((~Bso)& Bsu ); \
|
||||
E##so = Bso ^((~Bsu)& Bsa ); \
|
||||
E##su = Bsu ^((~Bsa)& Bse ); \
|
||||
\
|
||||
|
||||
#endif // UseBebigokimisa
|
||||
|
||||
const UINT64 KeccakF1600RoundConstants[24] = {
|
||||
0x0000000000000001ULL,
|
||||
0x0000000000008082ULL,
|
||||
0x800000000000808aULL,
|
||||
0x8000000080008000ULL,
|
||||
0x000000000000808bULL,
|
||||
0x0000000080000001ULL,
|
||||
0x8000000080008081ULL,
|
||||
0x8000000000008009ULL,
|
||||
0x000000000000008aULL,
|
||||
0x0000000000000088ULL,
|
||||
0x0000000080008009ULL,
|
||||
0x000000008000000aULL,
|
||||
0x000000008000808bULL,
|
||||
0x800000000000008bULL,
|
||||
0x8000000000008089ULL,
|
||||
0x8000000000008003ULL,
|
||||
0x8000000000008002ULL,
|
||||
0x8000000000000080ULL,
|
||||
0x000000000000800aULL,
|
||||
0x800000008000000aULL,
|
||||
0x8000000080008081ULL,
|
||||
0x8000000000008080ULL,
|
||||
0x0000000080000001ULL,
|
||||
0x8000000080008008ULL };
|
||||
|
||||
#define copyFromStateAndXor576bits(X, state, input) \
|
||||
X##ba = state[ 0]^input[ 0]; \
|
||||
X##be = state[ 1]^input[ 1]; \
|
||||
X##bi = state[ 2]^input[ 2]; \
|
||||
X##bo = state[ 3]^input[ 3]; \
|
||||
X##bu = state[ 4]^input[ 4]; \
|
||||
X##ga = state[ 5]^input[ 5]; \
|
||||
X##ge = state[ 6]^input[ 6]; \
|
||||
X##gi = state[ 7]^input[ 7]; \
|
||||
X##go = state[ 8]^input[ 8]; \
|
||||
X##gu = state[ 9]; \
|
||||
X##ka = state[10]; \
|
||||
X##ke = state[11]; \
|
||||
X##ki = state[12]; \
|
||||
X##ko = state[13]; \
|
||||
X##ku = state[14]; \
|
||||
X##ma = state[15]; \
|
||||
X##me = state[16]; \
|
||||
X##mi = state[17]; \
|
||||
X##mo = state[18]; \
|
||||
X##mu = state[19]; \
|
||||
X##sa = state[20]; \
|
||||
X##se = state[21]; \
|
||||
X##si = state[22]; \
|
||||
X##so = state[23]; \
|
||||
X##su = state[24]; \
|
||||
|
||||
#define copyFromStateAndXor832bits(X, state, input) \
|
||||
X##ba = state[ 0]^input[ 0]; \
|
||||
X##be = state[ 1]^input[ 1]; \
|
||||
X##bi = state[ 2]^input[ 2]; \
|
||||
X##bo = state[ 3]^input[ 3]; \
|
||||
X##bu = state[ 4]^input[ 4]; \
|
||||
X##ga = state[ 5]^input[ 5]; \
|
||||
X##ge = state[ 6]^input[ 6]; \
|
||||
X##gi = state[ 7]^input[ 7]; \
|
||||
X##go = state[ 8]^input[ 8]; \
|
||||
X##gu = state[ 9]^input[ 9]; \
|
||||
X##ka = state[10]^input[10]; \
|
||||
X##ke = state[11]^input[11]; \
|
||||
X##ki = state[12]^input[12]; \
|
||||
X##ko = state[13]; \
|
||||
X##ku = state[14]; \
|
||||
X##ma = state[15]; \
|
||||
X##me = state[16]; \
|
||||
X##mi = state[17]; \
|
||||
X##mo = state[18]; \
|
||||
X##mu = state[19]; \
|
||||
X##sa = state[20]; \
|
||||
X##se = state[21]; \
|
||||
X##si = state[22]; \
|
||||
X##so = state[23]; \
|
||||
X##su = state[24]; \
|
||||
|
||||
#define copyFromStateAndXor1024bits(X, state, input) \
|
||||
X##ba = state[ 0]^input[ 0]; \
|
||||
X##be = state[ 1]^input[ 1]; \
|
||||
X##bi = state[ 2]^input[ 2]; \
|
||||
X##bo = state[ 3]^input[ 3]; \
|
||||
X##bu = state[ 4]^input[ 4]; \
|
||||
X##ga = state[ 5]^input[ 5]; \
|
||||
X##ge = state[ 6]^input[ 6]; \
|
||||
X##gi = state[ 7]^input[ 7]; \
|
||||
X##go = state[ 8]^input[ 8]; \
|
||||
X##gu = state[ 9]^input[ 9]; \
|
||||
X##ka = state[10]^input[10]; \
|
||||
X##ke = state[11]^input[11]; \
|
||||
X##ki = state[12]^input[12]; \
|
||||
X##ko = state[13]^input[13]; \
|
||||
X##ku = state[14]^input[14]; \
|
||||
X##ma = state[15]^input[15]; \
|
||||
X##me = state[16]; \
|
||||
X##mi = state[17]; \
|
||||
X##mo = state[18]; \
|
||||
X##mu = state[19]; \
|
||||
X##sa = state[20]; \
|
||||
X##se = state[21]; \
|
||||
X##si = state[22]; \
|
||||
X##so = state[23]; \
|
||||
X##su = state[24]; \
|
||||
|
||||
#define copyFromStateAndXor1088bits(X, state, input) \
|
||||
X##ba = state[ 0]^input[ 0]; \
|
||||
X##be = state[ 1]^input[ 1]; \
|
||||
X##bi = state[ 2]^input[ 2]; \
|
||||
X##bo = state[ 3]^input[ 3]; \
|
||||
X##bu = state[ 4]^input[ 4]; \
|
||||
X##ga = state[ 5]^input[ 5]; \
|
||||
X##ge = state[ 6]^input[ 6]; \
|
||||
X##gi = state[ 7]^input[ 7]; \
|
||||
X##go = state[ 8]^input[ 8]; \
|
||||
X##gu = state[ 9]^input[ 9]; \
|
||||
X##ka = state[10]^input[10]; \
|
||||
X##ke = state[11]^input[11]; \
|
||||
X##ki = state[12]^input[12]; \
|
||||
X##ko = state[13]^input[13]; \
|
||||
X##ku = state[14]^input[14]; \
|
||||
X##ma = state[15]^input[15]; \
|
||||
X##me = state[16]^input[16]; \
|
||||
X##mi = state[17]; \
|
||||
X##mo = state[18]; \
|
||||
X##mu = state[19]; \
|
||||
X##sa = state[20]; \
|
||||
X##se = state[21]; \
|
||||
X##si = state[22]; \
|
||||
X##so = state[23]; \
|
||||
X##su = state[24]; \
|
||||
|
||||
#define copyFromStateAndXor1152bits(X, state, input) \
|
||||
X##ba = state[ 0]^input[ 0]; \
|
||||
X##be = state[ 1]^input[ 1]; \
|
||||
X##bi = state[ 2]^input[ 2]; \
|
||||
X##bo = state[ 3]^input[ 3]; \
|
||||
X##bu = state[ 4]^input[ 4]; \
|
||||
X##ga = state[ 5]^input[ 5]; \
|
||||
X##ge = state[ 6]^input[ 6]; \
|
||||
X##gi = state[ 7]^input[ 7]; \
|
||||
X##go = state[ 8]^input[ 8]; \
|
||||
X##gu = state[ 9]^input[ 9]; \
|
||||
X##ka = state[10]^input[10]; \
|
||||
X##ke = state[11]^input[11]; \
|
||||
X##ki = state[12]^input[12]; \
|
||||
X##ko = state[13]^input[13]; \
|
||||
X##ku = state[14]^input[14]; \
|
||||
X##ma = state[15]^input[15]; \
|
||||
X##me = state[16]^input[16]; \
|
||||
X##mi = state[17]^input[17]; \
|
||||
X##mo = state[18]; \
|
||||
X##mu = state[19]; \
|
||||
X##sa = state[20]; \
|
||||
X##se = state[21]; \
|
||||
X##si = state[22]; \
|
||||
X##so = state[23]; \
|
||||
X##su = state[24]; \
|
||||
|
||||
#define copyFromStateAndXor1344bits(X, state, input) \
|
||||
X##ba = state[ 0]^input[ 0]; \
|
||||
X##be = state[ 1]^input[ 1]; \
|
||||
X##bi = state[ 2]^input[ 2]; \
|
||||
X##bo = state[ 3]^input[ 3]; \
|
||||
X##bu = state[ 4]^input[ 4]; \
|
||||
X##ga = state[ 5]^input[ 5]; \
|
||||
X##ge = state[ 6]^input[ 6]; \
|
||||
X##gi = state[ 7]^input[ 7]; \
|
||||
X##go = state[ 8]^input[ 8]; \
|
||||
X##gu = state[ 9]^input[ 9]; \
|
||||
X##ka = state[10]^input[10]; \
|
||||
X##ke = state[11]^input[11]; \
|
||||
X##ki = state[12]^input[12]; \
|
||||
X##ko = state[13]^input[13]; \
|
||||
X##ku = state[14]^input[14]; \
|
||||
X##ma = state[15]^input[15]; \
|
||||
X##me = state[16]^input[16]; \
|
||||
X##mi = state[17]^input[17]; \
|
||||
X##mo = state[18]^input[18]; \
|
||||
X##mu = state[19]^input[19]; \
|
||||
X##sa = state[20]^input[20]; \
|
||||
X##se = state[21]; \
|
||||
X##si = state[22]; \
|
||||
X##so = state[23]; \
|
||||
X##su = state[24]; \
|
||||
|
||||
#define copyFromState(X, state) \
|
||||
X##ba = state[ 0]; \
|
||||
X##be = state[ 1]; \
|
||||
X##bi = state[ 2]; \
|
||||
X##bo = state[ 3]; \
|
||||
X##bu = state[ 4]; \
|
||||
X##ga = state[ 5]; \
|
||||
X##ge = state[ 6]; \
|
||||
X##gi = state[ 7]; \
|
||||
X##go = state[ 8]; \
|
||||
X##gu = state[ 9]; \
|
||||
X##ka = state[10]; \
|
||||
X##ke = state[11]; \
|
||||
X##ki = state[12]; \
|
||||
X##ko = state[13]; \
|
||||
X##ku = state[14]; \
|
||||
X##ma = state[15]; \
|
||||
X##me = state[16]; \
|
||||
X##mi = state[17]; \
|
||||
X##mo = state[18]; \
|
||||
X##mu = state[19]; \
|
||||
X##sa = state[20]; \
|
||||
X##se = state[21]; \
|
||||
X##si = state[22]; \
|
||||
X##so = state[23]; \
|
||||
X##su = state[24]; \
|
||||
|
||||
#define copyToState(state, X) \
|
||||
state[ 0] = X##ba; \
|
||||
state[ 1] = X##be; \
|
||||
state[ 2] = X##bi; \
|
||||
state[ 3] = X##bo; \
|
||||
state[ 4] = X##bu; \
|
||||
state[ 5] = X##ga; \
|
||||
state[ 6] = X##ge; \
|
||||
state[ 7] = X##gi; \
|
||||
state[ 8] = X##go; \
|
||||
state[ 9] = X##gu; \
|
||||
state[10] = X##ka; \
|
||||
state[11] = X##ke; \
|
||||
state[12] = X##ki; \
|
||||
state[13] = X##ko; \
|
||||
state[14] = X##ku; \
|
||||
state[15] = X##ma; \
|
||||
state[16] = X##me; \
|
||||
state[17] = X##mi; \
|
||||
state[18] = X##mo; \
|
||||
state[19] = X##mu; \
|
||||
state[20] = X##sa; \
|
||||
state[21] = X##se; \
|
||||
state[22] = X##si; \
|
||||
state[23] = X##so; \
|
||||
state[24] = X##su; \
|
||||
|
||||
#define copyStateVariables(X, Y) \
|
||||
X##ba = Y##ba; \
|
||||
X##be = Y##be; \
|
||||
X##bi = Y##bi; \
|
||||
X##bo = Y##bo; \
|
||||
X##bu = Y##bu; \
|
||||
X##ga = Y##ga; \
|
||||
X##ge = Y##ge; \
|
||||
X##gi = Y##gi; \
|
||||
X##go = Y##go; \
|
||||
X##gu = Y##gu; \
|
||||
X##ka = Y##ka; \
|
||||
X##ke = Y##ke; \
|
||||
X##ki = Y##ki; \
|
||||
X##ko = Y##ko; \
|
||||
X##ku = Y##ku; \
|
||||
X##ma = Y##ma; \
|
||||
X##me = Y##me; \
|
||||
X##mi = Y##mi; \
|
||||
X##mo = Y##mo; \
|
||||
X##mu = Y##mu; \
|
||||
X##sa = Y##sa; \
|
||||
X##se = Y##se; \
|
||||
X##si = Y##si; \
|
||||
X##so = Y##so; \
|
||||
X##su = Y##su; \
|
||||
|
6
src/3rdparty/sha3/KeccakF-1600-int-set.h
vendored
6
src/3rdparty/sha3/KeccakF-1600-int-set.h
vendored
|
@ -1,6 +0,0 @@
|
|||
#define ProvideFast576
|
||||
#define ProvideFast832
|
||||
#define ProvideFast1024
|
||||
#define ProvideFast1088
|
||||
#define ProvideFast1152
|
||||
#define ProvideFast1344
|
46
src/3rdparty/sha3/KeccakF-1600-interface.h
vendored
46
src/3rdparty/sha3/KeccakF-1600-interface.h
vendored
|
@ -1,46 +0,0 @@
|
|||
/*
|
||||
The Keccak sponge function, designed by Guido Bertoni, Joan Daemen,
|
||||
Michaël Peeters and Gilles Van Assche. For more information, feedback or
|
||||
questions, please refer to our website: http://keccak.noekeon.org/
|
||||
|
||||
Implementation by the designers,
|
||||
hereby denoted as "the implementer".
|
||||
|
||||
To the extent possible under law, the implementer has waived all copyright
|
||||
and related or neighboring rights to the source code in this file.
|
||||
http://creativecommons.org/publicdomain/zero/1.0/
|
||||
*/
|
||||
|
||||
#ifndef _KeccakPermutationInterface_h_
|
||||
#define _KeccakPermutationInterface_h_
|
||||
|
||||
#include "KeccakF-1600-int-set.h"
|
||||
|
||||
static void KeccakInitialize( void );
|
||||
static void KeccakInitializeState(unsigned char *state);
|
||||
static void KeccakPermutation(unsigned char *state);
|
||||
#ifdef ProvideFast576
|
||||
static void KeccakAbsorb576bits(unsigned char *state, const unsigned char *data);
|
||||
#endif
|
||||
#ifdef ProvideFast832
|
||||
static void KeccakAbsorb832bits(unsigned char *state, const unsigned char *data);
|
||||
#endif
|
||||
#ifdef ProvideFast1024
|
||||
static void KeccakAbsorb1024bits(unsigned char *state, const unsigned char *data);
|
||||
#endif
|
||||
#ifdef ProvideFast1088
|
||||
static void KeccakAbsorb1088bits(unsigned char *state, const unsigned char *data);
|
||||
#endif
|
||||
#ifdef ProvideFast1152
|
||||
static void KeccakAbsorb1152bits(unsigned char *state, const unsigned char *data);
|
||||
#endif
|
||||
#ifdef ProvideFast1344
|
||||
static void KeccakAbsorb1344bits(unsigned char *state, const unsigned char *data);
|
||||
#endif
|
||||
static void KeccakAbsorb(unsigned char *state, const unsigned char *data, unsigned int laneCount);
|
||||
#ifdef ProvideFast1024
|
||||
static void KeccakExtract1024bits(const unsigned char *state, unsigned char *data);
|
||||
#endif
|
||||
static void KeccakExtract(const unsigned char *state, unsigned char *data, unsigned int laneCount);
|
||||
|
||||
#endif
|
|
@ -1,4 +0,0 @@
|
|||
#define Unrolling 2
|
||||
//#define UseBebigokimisa
|
||||
//#define UseInterleaveTables
|
||||
#define UseSchedule 3
|
524
src/3rdparty/sha3/KeccakF-1600-opt32.c
vendored
524
src/3rdparty/sha3/KeccakF-1600-opt32.c
vendored
|
@ -1,524 +0,0 @@
|
|||
/*
|
||||
The Keccak sponge function, designed by Guido Bertoni, Joan Daemen,
|
||||
Michaël Peeters and Gilles Van Assche. For more information, feedback or
|
||||
questions, please refer to our website: http://keccak.noekeon.org/
|
||||
|
||||
Implementation by the designers,
|
||||
hereby denoted as "the implementer".
|
||||
|
||||
To the extent possible under law, the implementer has waived all copyright
|
||||
and related or neighboring rights to the source code in this file.
|
||||
http://creativecommons.org/publicdomain/zero/1.0/
|
||||
*/
|
||||
|
||||
#include <string.h>
|
||||
#include "brg_endian.h"
|
||||
#include "KeccakF-1600-opt32-settings.h"
|
||||
#include "KeccakF-1600-interface.h"
|
||||
|
||||
typedef unsigned char UINT8;
|
||||
typedef unsigned short UINT16;
|
||||
typedef unsigned int UINT32;
|
||||
typedef unsigned long long int UINT64;
|
||||
|
||||
#ifdef UseInterleaveTables
|
||||
int interleaveTablesBuilt = 0;
|
||||
UINT16 interleaveTable[65536];
|
||||
UINT16 deinterleaveTable[65536];
|
||||
|
||||
static void buildInterleaveTables()
|
||||
{
|
||||
UINT32 i, j;
|
||||
UINT16 x;
|
||||
|
||||
if (!interleaveTablesBuilt) {
|
||||
for(i=0; i<65536; i++) {
|
||||
x = 0;
|
||||
for(j=0; j<16; j++) {
|
||||
if (i & (1 << j))
|
||||
x |= (1 << (j/2 + 8*(j%2)));
|
||||
}
|
||||
interleaveTable[i] = x;
|
||||
deinterleaveTable[x] = (UINT16)i;
|
||||
}
|
||||
interleaveTablesBuilt = 1;
|
||||
}
|
||||
}
|
||||
|
||||
#if (PLATFORM_BYTE_ORDER == IS_LITTLE_ENDIAN)
|
||||
|
||||
#define xor2bytesIntoInterleavedWords(even, odd, source, j) \
|
||||
i##j = interleaveTable[((const UINT16*)source)[j]]; \
|
||||
((UINT8*)even)[j] ^= i##j & 0xFF; \
|
||||
((UINT8*)odd)[j] ^= i##j >> 8;
|
||||
|
||||
#define setInterleavedWordsInto2bytes(dest, even, odd, j) \
|
||||
d##j = deinterleaveTable[((even >> (j*8)) & 0xFF) ^ (((odd >> (j*8)) & 0xFF) << 8)]; \
|
||||
((UINT16*)dest)[j] = d##j;
|
||||
|
||||
#else // (PLATFORM_BYTE_ORDER == IS_BIG_ENDIAN)
|
||||
|
||||
#define xor2bytesIntoInterleavedWords(even, odd, source, j) \
|
||||
i##j = interleaveTable[source[2*j] ^ ((UINT16)source[2*j+1] << 8)]; \
|
||||
*even ^= (i##j & 0xFF) << (j*8); \
|
||||
*odd ^= ((i##j >> 8) & 0xFF) << (j*8);
|
||||
|
||||
#define setInterleavedWordsInto2bytes(dest, even, odd, j) \
|
||||
d##j = deinterleaveTable[((even >> (j*8)) & 0xFF) ^ (((odd >> (j*8)) & 0xFF) << 8)]; \
|
||||
dest[2*j] = d##j & 0xFF; \
|
||||
dest[2*j+1] = d##j >> 8;
|
||||
|
||||
#endif // Endianness
|
||||
|
||||
static void xor8bytesIntoInterleavedWords(UINT32 *even, UINT32 *odd, const UINT8* source)
|
||||
{
|
||||
UINT16 i0, i1, i2, i3;
|
||||
|
||||
xor2bytesIntoInterleavedWords(even, odd, source, 0)
|
||||
xor2bytesIntoInterleavedWords(even, odd, source, 1)
|
||||
xor2bytesIntoInterleavedWords(even, odd, source, 2)
|
||||
xor2bytesIntoInterleavedWords(even, odd, source, 3)
|
||||
}
|
||||
|
||||
#define xorLanesIntoState(laneCount, state, input) \
|
||||
{ \
|
||||
int i; \
|
||||
for(i=0; i<(laneCount); i++) \
|
||||
xor8bytesIntoInterleavedWords(state+i*2, state+i*2+1, input+i*8); \
|
||||
}
|
||||
|
||||
static void setInterleavedWordsInto8bytes(UINT8* dest, UINT32 even, UINT32 odd)
|
||||
{
|
||||
UINT16 d0, d1, d2, d3;
|
||||
|
||||
setInterleavedWordsInto2bytes(dest, even, odd, 0)
|
||||
setInterleavedWordsInto2bytes(dest, even, odd, 1)
|
||||
setInterleavedWordsInto2bytes(dest, even, odd, 2)
|
||||
setInterleavedWordsInto2bytes(dest, even, odd, 3)
|
||||
}
|
||||
|
||||
#define extractLanes(laneCount, state, data) \
|
||||
{ \
|
||||
int i; \
|
||||
for(i=0; i<(laneCount); i++) \
|
||||
setInterleavedWordsInto8bytes(data+i*8, ((UINT32*)state)[i*2], ((UINT32*)state)[i*2+1]); \
|
||||
}
|
||||
|
||||
#else // No interleaving tables
|
||||
|
||||
#if (PLATFORM_BYTE_ORDER == IS_LITTLE_ENDIAN)
|
||||
|
||||
// Credit: Henry S. Warren, Hacker's Delight, Addison-Wesley, 2002
|
||||
#define xorInterleavedLE(rateInLanes, state, input) \
|
||||
{ \
|
||||
const UINT32 * pI = (const UINT32 *)input; \
|
||||
UINT32 * pS = state; \
|
||||
UINT32 t, x0, x1; \
|
||||
int i; \
|
||||
for (i = (int)(rateInLanes)-1; i >= 0; --i) \
|
||||
{ \
|
||||
x0 = *(pI++); \
|
||||
t = (x0 ^ (x0 >> 1)) & 0x22222222UL; x0 = x0 ^ t ^ (t << 1); \
|
||||
t = (x0 ^ (x0 >> 2)) & 0x0C0C0C0CUL; x0 = x0 ^ t ^ (t << 2); \
|
||||
t = (x0 ^ (x0 >> 4)) & 0x00F000F0UL; x0 = x0 ^ t ^ (t << 4); \
|
||||
t = (x0 ^ (x0 >> 8)) & 0x0000FF00UL; x0 = x0 ^ t ^ (t << 8); \
|
||||
x1 = *(pI++); \
|
||||
t = (x1 ^ (x1 >> 1)) & 0x22222222UL; x1 = x1 ^ t ^ (t << 1); \
|
||||
t = (x1 ^ (x1 >> 2)) & 0x0C0C0C0CUL; x1 = x1 ^ t ^ (t << 2); \
|
||||
t = (x1 ^ (x1 >> 4)) & 0x00F000F0UL; x1 = x1 ^ t ^ (t << 4); \
|
||||
t = (x1 ^ (x1 >> 8)) & 0x0000FF00UL; x1 = x1 ^ t ^ (t << 8); \
|
||||
*(pS++) ^= (UINT16)x0 | (x1 << 16); \
|
||||
*(pS++) ^= (x0 >> 16) | (x1 & 0xFFFF0000); \
|
||||
} \
|
||||
}
|
||||
|
||||
#define xorLanesIntoState(laneCount, state, input) \
|
||||
xorInterleavedLE(laneCount, state, input)
|
||||
|
||||
#else // (PLATFORM_BYTE_ORDER == IS_BIG_ENDIAN)
|
||||
|
||||
// Credit: Henry S. Warren, Hacker's Delight, Addison-Wesley, 2002
|
||||
static UINT64 toInterleaving(UINT64 x)
|
||||
{
|
||||
UINT64 t;
|
||||
|
||||
t = (x ^ (x >> 1)) & 0x2222222222222222ULL; x = x ^ t ^ (t << 1);
|
||||
t = (x ^ (x >> 2)) & 0x0C0C0C0C0C0C0C0CULL; x = x ^ t ^ (t << 2);
|
||||
t = (x ^ (x >> 4)) & 0x00F000F000F000F0ULL; x = x ^ t ^ (t << 4);
|
||||
t = (x ^ (x >> 8)) & 0x0000FF000000FF00ULL; x = x ^ t ^ (t << 8);
|
||||
t = (x ^ (x >> 16)) & 0x00000000FFFF0000ULL; x = x ^ t ^ (t << 16);
|
||||
|
||||
return x;
|
||||
}
|
||||
|
||||
static void xor8bytesIntoInterleavedWords(UINT32* evenAndOdd, const UINT8* source)
|
||||
{
|
||||
// This can be optimized
|
||||
UINT64 sourceWord =
|
||||
(UINT64)source[0]
|
||||
^ (((UINT64)source[1]) << 8)
|
||||
^ (((UINT64)source[2]) << 16)
|
||||
^ (((UINT64)source[3]) << 24)
|
||||
^ (((UINT64)source[4]) << 32)
|
||||
^ (((UINT64)source[5]) << 40)
|
||||
^ (((UINT64)source[6]) << 48)
|
||||
^ (((UINT64)source[7]) << 56);
|
||||
UINT64 evenAndOddWord = toInterleaving(sourceWord);
|
||||
evenAndOdd[0] ^= (UINT32)evenAndOddWord;
|
||||
evenAndOdd[1] ^= (UINT32)(evenAndOddWord >> 32);
|
||||
}
|
||||
|
||||
#define xorLanesIntoState(laneCount, state, input) \
|
||||
{ \
|
||||
unsigned i; \
|
||||
for(i=0; i<(laneCount); i++) \
|
||||
xor8bytesIntoInterleavedWords(state+i*2, input+i*8); \
|
||||
}
|
||||
|
||||
#endif // Endianness
|
||||
|
||||
// Credit: Henry S. Warren, Hacker's Delight, Addison-Wesley, 2002
|
||||
static UINT64 fromInterleaving(UINT64 x)
|
||||
{
|
||||
UINT64 t;
|
||||
|
||||
t = (x ^ (x >> 16)) & 0x00000000FFFF0000ULL; x = x ^ t ^ (t << 16);
|
||||
t = (x ^ (x >> 8)) & 0x0000FF000000FF00ULL; x = x ^ t ^ (t << 8);
|
||||
t = (x ^ (x >> 4)) & 0x00F000F000F000F0ULL; x = x ^ t ^ (t << 4);
|
||||
t = (x ^ (x >> 2)) & 0x0C0C0C0C0C0C0C0CULL; x = x ^ t ^ (t << 2);
|
||||
t = (x ^ (x >> 1)) & 0x2222222222222222ULL; x = x ^ t ^ (t << 1);
|
||||
|
||||
return x;
|
||||
}
|
||||
|
||||
static void setInterleavedWordsInto8bytes(UINT8* dest, UINT32* evenAndOdd)
|
||||
{
|
||||
#if (PLATFORM_BYTE_ORDER == IS_LITTLE_ENDIAN)
|
||||
((UINT64*)dest)[0] = fromInterleaving(*(UINT64*)evenAndOdd);
|
||||
#else // (PLATFORM_BYTE_ORDER == IS_BIG_ENDIAN)
|
||||
// This can be optimized
|
||||
UINT64 evenAndOddWord = (UINT64)evenAndOdd[0] ^ ((UINT64)evenAndOdd[1] << 32);
|
||||
UINT64 destWord = fromInterleaving(evenAndOddWord);
|
||||
dest[0] = destWord & 0xFF;
|
||||
dest[1] = (destWord >> 8) & 0xFF;
|
||||
dest[2] = (destWord >> 16) & 0xFF;
|
||||
dest[3] = (destWord >> 24) & 0xFF;
|
||||
dest[4] = (destWord >> 32) & 0xFF;
|
||||
dest[5] = (destWord >> 40) & 0xFF;
|
||||
dest[6] = (destWord >> 48) & 0xFF;
|
||||
dest[7] = (destWord >> 56) & 0xFF;
|
||||
#endif // Endianness
|
||||
}
|
||||
|
||||
#define extractLanes(laneCount, state, data) \
|
||||
{ \
|
||||
unsigned i; \
|
||||
for(i=0; i<(laneCount); i++) \
|
||||
setInterleavedWordsInto8bytes(data+i*8, (UINT32*)state+i*2); \
|
||||
}
|
||||
|
||||
#endif // With or without interleaving tables
|
||||
|
||||
#if defined(_MSC_VER)
|
||||
#define ROL32(a, offset) _rotl(a, offset)
|
||||
#elif (defined (__arm__) && defined(__ARMCC_VERSION))
|
||||
#define ROL32(a, offset) __ror(a, 32-(offset))
|
||||
#else
|
||||
#define ROL32(a, offset) ((((UINT32)a) << (offset)) ^ (((UINT32)a) >> (32-(offset))))
|
||||
#endif
|
||||
|
||||
#include "KeccakF-1600-unrolling.macros"
|
||||
#include "KeccakF-1600-32.macros"
|
||||
|
||||
#if (UseSchedule == 3)
|
||||
|
||||
#ifdef UseBebigokimisa
|
||||
#error "No lane complementing with schedule 3."
|
||||
#endif
|
||||
|
||||
#if (Unrolling != 2)
|
||||
#error "Only unrolling 2 is supported by schedule 3."
|
||||
#endif
|
||||
|
||||
static void KeccakPermutationOnWords(UINT32 *state)
|
||||
{
|
||||
rounds
|
||||
}
|
||||
|
||||
static void KeccakPermutationOnWordsAfterXoring(UINT32 *state, const UINT8 *input, unsigned int laneCount)
|
||||
{
|
||||
xorLanesIntoState(laneCount, state, input)
|
||||
rounds
|
||||
}
|
||||
|
||||
#ifdef ProvideFast576
|
||||
static void KeccakPermutationOnWordsAfterXoring576bits(UINT32 *state, const UINT8 *input)
|
||||
{
|
||||
xorLanesIntoState(9, state, input)
|
||||
rounds
|
||||
}
|
||||
#endif
|
||||
|
||||
#ifdef ProvideFast832
|
||||
static void KeccakPermutationOnWordsAfterXoring832bits(UINT32 *state, const UINT8 *input)
|
||||
{
|
||||
xorLanesIntoState(13, state, input)
|
||||
rounds
|
||||
}
|
||||
#endif
|
||||
|
||||
#ifdef ProvideFast1024
|
||||
static void KeccakPermutationOnWordsAfterXoring1024bits(UINT32 *state, const UINT8 *input)
|
||||
{
|
||||
xorLanesIntoState(16, state, input)
|
||||
rounds
|
||||
}
|
||||
#endif
|
||||
|
||||
#ifdef ProvideFast1088
|
||||
static void KeccakPermutationOnWordsAfterXoring1088bits(UINT32 *state, const UINT8 *input)
|
||||
{
|
||||
xorLanesIntoState(17, state, input)
|
||||
rounds
|
||||
}
|
||||
#endif
|
||||
|
||||
#ifdef ProvideFast1152
|
||||
static void KeccakPermutationOnWordsAfterXoring1152bits(UINT32 *state, const UINT8 *input)
|
||||
{
|
||||
xorLanesIntoState(18, state, input)
|
||||
rounds
|
||||
}
|
||||
#endif
|
||||
|
||||
#ifdef ProvideFast1344
|
||||
static void KeccakPermutationOnWordsAfterXoring1344bits(UINT32 *state, const UINT8 *input)
|
||||
{
|
||||
xorLanesIntoState(21, state, input)
|
||||
rounds
|
||||
}
|
||||
#endif
|
||||
|
||||
#else // (Schedule != 3)
|
||||
|
||||
static void KeccakPermutationOnWords(UINT32 *state)
|
||||
{
|
||||
declareABCDE
|
||||
#if (Unrolling != 24)
|
||||
unsigned int i;
|
||||
#endif
|
||||
|
||||
copyFromState(A, state)
|
||||
rounds
|
||||
}
|
||||
|
||||
static void KeccakPermutationOnWordsAfterXoring(UINT32 *state, const UINT8 *input, unsigned int laneCount)
|
||||
{
|
||||
declareABCDE
|
||||
unsigned int i;
|
||||
|
||||
xorLanesIntoState(laneCount, state, input)
|
||||
copyFromState(A, state)
|
||||
rounds
|
||||
}
|
||||
|
||||
#ifdef ProvideFast576
|
||||
static void KeccakPermutationOnWordsAfterXoring576bits(UINT32 *state, const UINT8 *input)
|
||||
{
|
||||
declareABCDE
|
||||
unsigned int i;
|
||||
|
||||
xorLanesIntoState(9, state, input)
|
||||
copyFromState(A, state)
|
||||
rounds
|
||||
}
|
||||
#endif
|
||||
|
||||
#ifdef ProvideFast832
|
||||
static void KeccakPermutationOnWordsAfterXoring832bits(UINT32 *state, const UINT8 *input)
|
||||
{
|
||||
declareABCDE
|
||||
unsigned int i;
|
||||
|
||||
xorLanesIntoState(13, state, input)
|
||||
copyFromState(A, state)
|
||||
rounds
|
||||
}
|
||||
#endif
|
||||
|
||||
#ifdef ProvideFast1024
|
||||
static void KeccakPermutationOnWordsAfterXoring1024bits(UINT32 *state, const UINT8 *input)
|
||||
{
|
||||
declareABCDE
|
||||
unsigned int i;
|
||||
|
||||
xorLanesIntoState(16, state, input)
|
||||
copyFromState(A, state)
|
||||
rounds
|
||||
}
|
||||
#endif
|
||||
|
||||
#ifdef ProvideFast1088
|
||||
static void KeccakPermutationOnWordsAfterXoring1088bits(UINT32 *state, const UINT8 *input)
|
||||
{
|
||||
declareABCDE
|
||||
unsigned int i;
|
||||
|
||||
xorLanesIntoState(17, state, input)
|
||||
copyFromState(A, state)
|
||||
rounds
|
||||
}
|
||||
#endif
|
||||
|
||||
#ifdef ProvideFast1152
|
||||
static void KeccakPermutationOnWordsAfterXoring1152bits(UINT32 *state, const UINT8 *input)
|
||||
{
|
||||
declareABCDE
|
||||
unsigned int i;
|
||||
|
||||
xorLanesIntoState(18, state, input)
|
||||
copyFromState(A, state)
|
||||
rounds
|
||||
}
|
||||
#endif
|
||||
|
||||
#ifdef ProvideFast1344
|
||||
static void KeccakPermutationOnWordsAfterXoring1344bits(UINT32 *state, const UINT8 *input)
|
||||
{
|
||||
declareABCDE
|
||||
unsigned int i;
|
||||
|
||||
xorLanesIntoState(21, state, input)
|
||||
copyFromState(A, state)
|
||||
rounds
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
||||
|
||||
static void KeccakInitialize()
|
||||
{
|
||||
#ifdef UseInterleaveTables
|
||||
buildInterleaveTables();
|
||||
#endif
|
||||
}
|
||||
|
||||
static void KeccakInitializeState(unsigned char *state)
|
||||
{
|
||||
memset(state, 0, 200);
|
||||
#ifdef UseBebigokimisa
|
||||
((UINT32*)state)[ 2] = ~(UINT32)0;
|
||||
((UINT32*)state)[ 3] = ~(UINT32)0;
|
||||
((UINT32*)state)[ 4] = ~(UINT32)0;
|
||||
((UINT32*)state)[ 5] = ~(UINT32)0;
|
||||
((UINT32*)state)[16] = ~(UINT32)0;
|
||||
((UINT32*)state)[17] = ~(UINT32)0;
|
||||
((UINT32*)state)[24] = ~(UINT32)0;
|
||||
((UINT32*)state)[25] = ~(UINT32)0;
|
||||
((UINT32*)state)[34] = ~(UINT32)0;
|
||||
((UINT32*)state)[35] = ~(UINT32)0;
|
||||
((UINT32*)state)[40] = ~(UINT32)0;
|
||||
((UINT32*)state)[41] = ~(UINT32)0;
|
||||
#endif
|
||||
}
|
||||
|
||||
static void KeccakPermutation(unsigned char *state)
|
||||
{
|
||||
// We assume the state is always stored as interleaved 32-bit words
|
||||
KeccakPermutationOnWords((UINT32*)state);
|
||||
}
|
||||
|
||||
#ifdef ProvideFast576
|
||||
static void KeccakAbsorb576bits(unsigned char *state, const unsigned char *data)
|
||||
{
|
||||
KeccakPermutationOnWordsAfterXoring576bits((UINT32*)state, data);
|
||||
}
|
||||
#endif
|
||||
|
||||
#ifdef ProvideFast832
|
||||
static void KeccakAbsorb832bits(unsigned char *state, const unsigned char *data)
|
||||
{
|
||||
KeccakPermutationOnWordsAfterXoring832bits((UINT32*)state, data);
|
||||
}
|
||||
#endif
|
||||
|
||||
#ifdef ProvideFast1024
|
||||
static void KeccakAbsorb1024bits(unsigned char *state, const unsigned char *data)
|
||||
{
|
||||
KeccakPermutationOnWordsAfterXoring1024bits((UINT32*)state, data);
|
||||
}
|
||||
#endif
|
||||
|
||||
#ifdef ProvideFast1088
|
||||
static void KeccakAbsorb1088bits(unsigned char *state, const unsigned char *data)
|
||||
{
|
||||
KeccakPermutationOnWordsAfterXoring1088bits((UINT32*)state, data);
|
||||
}
|
||||
#endif
|
||||
|
||||
#ifdef ProvideFast1152
|
||||
static void KeccakAbsorb1152bits(unsigned char *state, const unsigned char *data)
|
||||
{
|
||||
KeccakPermutationOnWordsAfterXoring1152bits((UINT32*)state, data);
|
||||
}
|
||||
#endif
|
||||
|
||||
#ifdef ProvideFast1344
|
||||
static void KeccakAbsorb1344bits(unsigned char *state, const unsigned char *data)
|
||||
{
|
||||
KeccakPermutationOnWordsAfterXoring1344bits((UINT32*)state, data);
|
||||
}
|
||||
#endif
|
||||
|
||||
static void KeccakAbsorb(unsigned char *state, const unsigned char *data, unsigned int laneCount)
|
||||
{
|
||||
KeccakPermutationOnWordsAfterXoring((UINT32*)state, data, laneCount);
|
||||
}
|
||||
|
||||
#ifdef ProvideFast1024
|
||||
static void KeccakExtract1024bits(const unsigned char *state, unsigned char *data)
|
||||
{
|
||||
extractLanes(16, state, data)
|
||||
#ifdef UseBebigokimisa
|
||||
((UINT32*)data)[ 2] = ~((UINT32*)data)[ 2];
|
||||
((UINT32*)data)[ 3] = ~((UINT32*)data)[ 3];
|
||||
((UINT32*)data)[ 4] = ~((UINT32*)data)[ 4];
|
||||
((UINT32*)data)[ 5] = ~((UINT32*)data)[ 5];
|
||||
((UINT32*)data)[16] = ~((UINT32*)data)[16];
|
||||
((UINT32*)data)[17] = ~((UINT32*)data)[17];
|
||||
((UINT32*)data)[24] = ~((UINT32*)data)[24];
|
||||
((UINT32*)data)[25] = ~((UINT32*)data)[25];
|
||||
#endif
|
||||
}
|
||||
#endif
|
||||
|
||||
static void KeccakExtract(const unsigned char *state, unsigned char *data, unsigned int laneCount)
|
||||
{
|
||||
extractLanes(laneCount, state, data)
|
||||
#ifdef UseBebigokimisa
|
||||
if (laneCount > 1) {
|
||||
((UINT32*)data)[ 2] = ~((UINT32*)data)[ 2];
|
||||
((UINT32*)data)[ 3] = ~((UINT32*)data)[ 3];
|
||||
if (laneCount > 2) {
|
||||
((UINT32*)data)[ 4] = ~((UINT32*)data)[ 4];
|
||||
((UINT32*)data)[ 5] = ~((UINT32*)data)[ 5];
|
||||
if (laneCount > 8) {
|
||||
((UINT32*)data)[16] = ~((UINT32*)data)[16];
|
||||
((UINT32*)data)[17] = ~((UINT32*)data)[17];
|
||||
if (laneCount > 12) {
|
||||
((UINT32*)data)[24] = ~((UINT32*)data)[24];
|
||||
((UINT32*)data)[25] = ~((UINT32*)data)[25];
|
||||
if (laneCount > 17) {
|
||||
((UINT32*)data)[34] = ~((UINT32*)data)[34];
|
||||
((UINT32*)data)[35] = ~((UINT32*)data)[35];
|
||||
if (laneCount > 20) {
|
||||
((UINT32*)data)[40] = ~((UINT32*)data)[40];
|
||||
((UINT32*)data)[41] = ~((UINT32*)data)[41];
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif
|
||||
}
|
|
@ -1,7 +0,0 @@
|
|||
#define Unrolling 24
|
||||
#define UseBebigokimisa
|
||||
//#define UseSSE
|
||||
//#define UseOnlySIMD64
|
||||
//#define UseMMX
|
||||
//#define UseSHLD
|
||||
//#define UseXOP
|
512
src/3rdparty/sha3/KeccakF-1600-opt64.c
vendored
512
src/3rdparty/sha3/KeccakF-1600-opt64.c
vendored
|
@ -1,512 +0,0 @@
|
|||
/*
|
||||
The Keccak sponge function, designed by Guido Bertoni, Joan Daemen,
|
||||
Michaël Peeters and Gilles Van Assche. For more information, feedback or
|
||||
questions, please refer to our website: http://keccak.noekeon.org/
|
||||
|
||||
Implementation by the designers,
|
||||
hereby denoted as "the implementer".
|
||||
|
||||
To the extent possible under law, the implementer has waived all copyright
|
||||
and related or neighboring rights to the source code in this file.
|
||||
http://creativecommons.org/publicdomain/zero/1.0/
|
||||
*/
|
||||
|
||||
#include <string.h>
|
||||
#include "brg_endian.h"
|
||||
#include "KeccakF-1600-opt64-settings.h"
|
||||
#include "KeccakF-1600-interface.h"
|
||||
|
||||
typedef unsigned char UINT8;
|
||||
typedef unsigned long long int UINT64;
|
||||
|
||||
#if defined(UseSSE) || defined(UseXOP)
|
||||
#if defined(__GNUC__)
|
||||
#define ALIGN __attribute__ ((aligned(32)))
|
||||
#elif defined(_MSC_VER)
|
||||
#define ALIGN __declspec(align(32))
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#ifndef ALIGN
|
||||
# define ALIGN
|
||||
#endif
|
||||
|
||||
#if defined(UseSSE)
|
||||
#include <x86intrin.h>
|
||||
typedef __m128i V64;
|
||||
typedef __m128i V128;
|
||||
typedef union {
|
||||
V128 v128;
|
||||
UINT64 v64[2];
|
||||
} V6464;
|
||||
|
||||
#define ANDnu64(a, b) _mm_andnot_si128(a, b)
|
||||
#define LOAD64(a) _mm_loadl_epi64((const V64 *)&(a))
|
||||
#define CONST64(a) _mm_loadl_epi64((const V64 *)&(a))
|
||||
#define ROL64(a, o) _mm_or_si128(_mm_slli_epi64(a, o), _mm_srli_epi64(a, 64-(o)))
|
||||
#define STORE64(a, b) _mm_storel_epi64((V64 *)&(a), b)
|
||||
#define XOR64(a, b) _mm_xor_si128(a, b)
|
||||
#define XOReq64(a, b) a = _mm_xor_si128(a, b)
|
||||
#define SHUFFLEBYTES128(a, b) _mm_shuffle_epi8(a, b)
|
||||
|
||||
#define ANDnu128(a, b) _mm_andnot_si128(a, b)
|
||||
#define LOAD6464(a, b) _mm_set_epi64((__m64)(a), (__m64)(b))
|
||||
#define CONST128(a) _mm_load_si128((const V128 *)&(a))
|
||||
#define LOAD128(a) _mm_load_si128((const V128 *)&(a))
|
||||
#define LOAD128u(a) _mm_loadu_si128((const V128 *)&(a))
|
||||
#define ROL64in128(a, o) _mm_or_si128(_mm_slli_epi64(a, o), _mm_srli_epi64(a, 64-(o)))
|
||||
#define STORE128(a, b) _mm_store_si128((V128 *)&(a), b)
|
||||
#define XOR128(a, b) _mm_xor_si128(a, b)
|
||||
#define XOReq128(a, b) a = _mm_xor_si128(a, b)
|
||||
#define GET64LOLO(a, b) _mm_unpacklo_epi64(a, b)
|
||||
#define GET64HIHI(a, b) _mm_unpackhi_epi64(a, b)
|
||||
#define COPY64HI2LO(a) _mm_shuffle_epi32(a, 0xEE)
|
||||
#define COPY64LO2HI(a) _mm_shuffle_epi32(a, 0x44)
|
||||
#define ZERO128() _mm_setzero_si128()
|
||||
|
||||
#ifdef UseOnlySIMD64
|
||||
#include "KeccakF-1600-simd64.macros"
|
||||
#else
|
||||
ALIGN const UINT64 rho8_56[2] = {0x0605040302010007, 0x080F0E0D0C0B0A09};
|
||||
#include "KeccakF-1600-simd128.macros"
|
||||
#endif
|
||||
|
||||
#ifdef UseBebigokimisa
|
||||
#error "UseBebigokimisa cannot be used in combination with UseSSE"
|
||||
#endif
|
||||
#elif defined(UseXOP)
|
||||
#include <x86intrin.h>
|
||||
typedef __m128i V64;
|
||||
typedef __m128i V128;
|
||||
|
||||
#define LOAD64(a) _mm_loadl_epi64((const V64 *)&(a))
|
||||
#define CONST64(a) _mm_loadl_epi64((const V64 *)&(a))
|
||||
#define STORE64(a, b) _mm_storel_epi64((V64 *)&(a), b)
|
||||
#define XOR64(a, b) _mm_xor_si128(a, b)
|
||||
#define XOReq64(a, b) a = _mm_xor_si128(a, b)
|
||||
|
||||
#define ANDnu128(a, b) _mm_andnot_si128(a, b)
|
||||
#define LOAD6464(a, b) _mm_set_epi64((__m64)(a), (__m64)(b))
|
||||
#define CONST128(a) _mm_load_si128((const V128 *)&(a))
|
||||
#define LOAD128(a) _mm_load_si128((const V128 *)&(a))
|
||||
#define LOAD128u(a) _mm_loadu_si128((const V128 *)&(a))
|
||||
#define STORE128(a, b) _mm_store_si128((V128 *)&(a), b)
|
||||
#define XOR128(a, b) _mm_xor_si128(a, b)
|
||||
#define XOReq128(a, b) a = _mm_xor_si128(a, b)
|
||||
#define ZERO128() _mm_setzero_si128()
|
||||
|
||||
#define SWAP64(a) _mm_shuffle_epi32(a, 0x4E)
|
||||
#define GET64LOLO(a, b) _mm_unpacklo_epi64(a, b)
|
||||
#define GET64HIHI(a, b) _mm_unpackhi_epi64(a, b)
|
||||
#define GET64LOHI(a, b) ((__m128i)_mm_blend_pd((__m128d)a, (__m128d)b, 2))
|
||||
#define GET64HILO(a, b) SWAP64(GET64LOHI(b, a))
|
||||
#define COPY64HI2LO(a) _mm_shuffle_epi32(a, 0xEE)
|
||||
#define COPY64LO2HI(a) _mm_shuffle_epi32(a, 0x44)
|
||||
|
||||
#define ROL6464same(a, o) _mm_roti_epi64(a, o)
|
||||
#define ROL6464(a, r1, r2) _mm_rot_epi64(a, CONST128( rot_##r1##_##r2 ))
|
||||
ALIGN const UINT64 rot_0_20[2] = { 0, 20};
|
||||
ALIGN const UINT64 rot_44_3[2] = {44, 3};
|
||||
ALIGN const UINT64 rot_43_45[2] = {43, 45};
|
||||
ALIGN const UINT64 rot_21_61[2] = {21, 61};
|
||||
ALIGN const UINT64 rot_14_28[2] = {14, 28};
|
||||
ALIGN const UINT64 rot_1_36[2] = { 1, 36};
|
||||
ALIGN const UINT64 rot_6_10[2] = { 6, 10};
|
||||
ALIGN const UINT64 rot_25_15[2] = {25, 15};
|
||||
ALIGN const UINT64 rot_8_56[2] = { 8, 56};
|
||||
ALIGN const UINT64 rot_18_27[2] = {18, 27};
|
||||
ALIGN const UINT64 rot_62_55[2] = {62, 55};
|
||||
ALIGN const UINT64 rot_39_41[2] = {39, 41};
|
||||
|
||||
#if defined(UseSimulatedXOP)
|
||||
// For debugging purposes, when XOP is not available
|
||||
#undef ROL6464
|
||||
#undef ROL6464same
|
||||
#define ROL6464same(a, o) _mm_or_si128(_mm_slli_epi64(a, o), _mm_srli_epi64(a, 64-(o)))
|
||||
V128 ROL6464(V128 a, int r0, int r1)
|
||||
{
|
||||
V128 a0 = ROL64(a, r0);
|
||||
V128 a1 = COPY64HI2LO(ROL64(a, r1));
|
||||
return GET64LOLO(a0, a1);
|
||||
}
|
||||
#endif
|
||||
|
||||
#include "KeccakF-1600-xop.macros"
|
||||
|
||||
#ifdef UseBebigokimisa
|
||||
#error "UseBebigokimisa cannot be used in combination with UseXOP"
|
||||
#endif
|
||||
#elif defined(UseMMX)
|
||||
#include <mmintrin.h>
|
||||
typedef __m64 V64;
|
||||
#define ANDnu64(a, b) _mm_andnot_si64(a, b)
|
||||
|
||||
#if (defined(_MSC_VER) || defined (__INTEL_COMPILER))
|
||||
#define LOAD64(a) *(V64*)&(a)
|
||||
#define CONST64(a) *(V64*)&(a)
|
||||
#define STORE64(a, b) *(V64*)&(a) = b
|
||||
#else
|
||||
#define LOAD64(a) (V64)a
|
||||
#define CONST64(a) (V64)a
|
||||
#define STORE64(a, b) a = (UINT64)b
|
||||
#endif
|
||||
#define ROL64(a, o) _mm_or_si64(_mm_slli_si64(a, o), _mm_srli_si64(a, 64-(o)))
|
||||
#define XOR64(a, b) _mm_xor_si64(a, b)
|
||||
#define XOReq64(a, b) a = _mm_xor_si64(a, b)
|
||||
|
||||
#include "KeccakF-1600-simd64.macros"
|
||||
|
||||
#ifdef UseBebigokimisa
|
||||
#error "UseBebigokimisa cannot be used in combination with UseMMX"
|
||||
#endif
|
||||
#else
|
||||
#if defined(_MSC_VER)
|
||||
#define ROL64(a, offset) _rotl64(a, offset)
|
||||
#elif defined(UseSHLD)
|
||||
#define ROL64(x,N) ({ \
|
||||
register UINT64 __out; \
|
||||
register UINT64 __in = x; \
|
||||
__asm__ ("shld %2,%0,%0" : "=r"(__out) : "0"(__in), "i"(N)); \
|
||||
__out; \
|
||||
})
|
||||
#else
|
||||
#define ROL64(a, offset) ((((UINT64)a) << offset) ^ (((UINT64)a) >> (64-offset)))
|
||||
#endif
|
||||
|
||||
#include "KeccakF-1600-64.macros"
|
||||
#endif
|
||||
|
||||
#include "KeccakF-1600-unrolling.macros"
|
||||
|
||||
static void KeccakPermutationOnWords(UINT64 *state)
|
||||
{
|
||||
declareABCDE
|
||||
#if (Unrolling != 24)
|
||||
unsigned int i;
|
||||
#endif
|
||||
|
||||
copyFromState(A, state)
|
||||
rounds
|
||||
#if defined(UseMMX)
|
||||
_mm_empty();
|
||||
#endif
|
||||
}
|
||||
|
||||
static void KeccakPermutationOnWordsAfterXoring(UINT64 *state, const UINT64 *input, unsigned int laneCount)
|
||||
{
|
||||
declareABCDE
|
||||
#if (Unrolling != 24)
|
||||
unsigned int i;
|
||||
#endif
|
||||
unsigned int j;
|
||||
|
||||
for(j=0; j<laneCount; j++)
|
||||
state[j] ^= input[j];
|
||||
copyFromState(A, state)
|
||||
rounds
|
||||
#if defined(UseMMX)
|
||||
_mm_empty();
|
||||
#endif
|
||||
}
|
||||
|
||||
#ifdef ProvideFast576
|
||||
static void KeccakPermutationOnWordsAfterXoring576bits(UINT64 *state, const UINT64 *input)
|
||||
{
|
||||
declareABCDE
|
||||
#if (Unrolling != 24)
|
||||
unsigned int i;
|
||||
#endif
|
||||
|
||||
copyFromStateAndXor576bits(A, state, input)
|
||||
rounds
|
||||
#if defined(UseMMX)
|
||||
_mm_empty();
|
||||
#endif
|
||||
}
|
||||
#endif
|
||||
|
||||
#ifdef ProvideFast832
|
||||
static void KeccakPermutationOnWordsAfterXoring832bits(UINT64 *state, const UINT64 *input)
|
||||
{
|
||||
declareABCDE
|
||||
#if (Unrolling != 24)
|
||||
unsigned int i;
|
||||
#endif
|
||||
|
||||
copyFromStateAndXor832bits(A, state, input)
|
||||
rounds
|
||||
#if defined(UseMMX)
|
||||
_mm_empty();
|
||||
#endif
|
||||
}
|
||||
#endif
|
||||
|
||||
#ifdef ProvideFast1024
|
||||
static void KeccakPermutationOnWordsAfterXoring1024bits(UINT64 *state, const UINT64 *input)
|
||||
{
|
||||
declareABCDE
|
||||
#if (Unrolling != 24)
|
||||
unsigned int i;
|
||||
#endif
|
||||
|
||||
copyFromStateAndXor1024bits(A, state, input)
|
||||
rounds
|
||||
#if defined(UseMMX)
|
||||
_mm_empty();
|
||||
#endif
|
||||
}
|
||||
#endif
|
||||
|
||||
#ifdef ProvideFast1088
|
||||
static void KeccakPermutationOnWordsAfterXoring1088bits(UINT64 *state, const UINT64 *input)
|
||||
{
|
||||
declareABCDE
|
||||
#if (Unrolling != 24)
|
||||
unsigned int i;
|
||||
#endif
|
||||
|
||||
copyFromStateAndXor1088bits(A, state, input)
|
||||
rounds
|
||||
#if defined(UseMMX)
|
||||
_mm_empty();
|
||||
#endif
|
||||
}
|
||||
#endif
|
||||
|
||||
#ifdef ProvideFast1152
|
||||
static void KeccakPermutationOnWordsAfterXoring1152bits(UINT64 *state, const UINT64 *input)
|
||||
{
|
||||
declareABCDE
|
||||
#if (Unrolling != 24)
|
||||
unsigned int i;
|
||||
#endif
|
||||
|
||||
copyFromStateAndXor1152bits(A, state, input)
|
||||
rounds
|
||||
#if defined(UseMMX)
|
||||
_mm_empty();
|
||||
#endif
|
||||
}
|
||||
#endif
|
||||
|
||||
#ifdef ProvideFast1344
|
||||
static void KeccakPermutationOnWordsAfterXoring1344bits(UINT64 *state, const UINT64 *input)
|
||||
{
|
||||
declareABCDE
|
||||
#if (Unrolling != 24)
|
||||
unsigned int i;
|
||||
#endif
|
||||
|
||||
copyFromStateAndXor1344bits(A, state, input)
|
||||
rounds
|
||||
#if defined(UseMMX)
|
||||
_mm_empty();
|
||||
#endif
|
||||
}
|
||||
#endif
|
||||
|
||||
static void KeccakInitialize()
|
||||
{
|
||||
}
|
||||
|
||||
static void KeccakInitializeState(unsigned char *state)
|
||||
{
|
||||
memset(state, 0, 200);
|
||||
#ifdef UseBebigokimisa
|
||||
((UINT64*)state)[ 1] = ~(UINT64)0;
|
||||
((UINT64*)state)[ 2] = ~(UINT64)0;
|
||||
((UINT64*)state)[ 8] = ~(UINT64)0;
|
||||
((UINT64*)state)[12] = ~(UINT64)0;
|
||||
((UINT64*)state)[17] = ~(UINT64)0;
|
||||
((UINT64*)state)[20] = ~(UINT64)0;
|
||||
#endif
|
||||
}
|
||||
|
||||
static void KeccakPermutation(unsigned char *state)
|
||||
{
|
||||
// We assume the state is always stored as words
|
||||
KeccakPermutationOnWords((UINT64*)state);
|
||||
}
|
||||
|
||||
#if (PLATFORM_BYTE_ORDER == IS_BIG_ENDIAN)
|
||||
static void fromBytesToWord(UINT64 *word, const UINT8 *bytes)
|
||||
{
|
||||
unsigned int i;
|
||||
|
||||
*word = 0;
|
||||
for(i=0; i<(64/8); i++)
|
||||
*word |= (UINT64)(bytes[i]) << (8*i);
|
||||
}
|
||||
#endif
|
||||
|
||||
#ifdef ProvideFast576
|
||||
static void KeccakAbsorb576bits(unsigned char *state, const unsigned char *data)
|
||||
{
|
||||
#if (PLATFORM_BYTE_ORDER == IS_LITTLE_ENDIAN)
|
||||
KeccakPermutationOnWordsAfterXoring576bits((UINT64*)state, (const UINT64*)data);
|
||||
#else
|
||||
UINT64 dataAsWords[9];
|
||||
unsigned int i;
|
||||
|
||||
for(i=0; i<9; i++)
|
||||
fromBytesToWord(dataAsWords+i, data+(i*8));
|
||||
KeccakPermutationOnWordsAfterXoring576bits((UINT64*)state, dataAsWords);
|
||||
#endif
|
||||
}
|
||||
#endif
|
||||
|
||||
#ifdef ProvideFast832
|
||||
static void KeccakAbsorb832bits(unsigned char *state, const unsigned char *data)
|
||||
{
|
||||
#if (PLATFORM_BYTE_ORDER == IS_LITTLE_ENDIAN)
|
||||
KeccakPermutationOnWordsAfterXoring832bits((UINT64*)state, (const UINT64*)data);
|
||||
#else
|
||||
UINT64 dataAsWords[13];
|
||||
unsigned int i;
|
||||
|
||||
for(i=0; i<13; i++)
|
||||
fromBytesToWord(dataAsWords+i, data+(i*8));
|
||||
KeccakPermutationOnWordsAfterXoring832bits((UINT64*)state, dataAsWords);
|
||||
#endif
|
||||
}
|
||||
#endif
|
||||
|
||||
#ifdef ProvideFast1024
|
||||
static void KeccakAbsorb1024bits(unsigned char *state, const unsigned char *data)
|
||||
{
|
||||
#if (PLATFORM_BYTE_ORDER == IS_LITTLE_ENDIAN)
|
||||
KeccakPermutationOnWordsAfterXoring1024bits((UINT64*)state, (const UINT64*)data);
|
||||
#else
|
||||
UINT64 dataAsWords[16];
|
||||
unsigned int i;
|
||||
|
||||
for(i=0; i<16; i++)
|
||||
fromBytesToWord(dataAsWords+i, data+(i*8));
|
||||
KeccakPermutationOnWordsAfterXoring1024bits((UINT64*)state, dataAsWords);
|
||||
#endif
|
||||
}
|
||||
#endif
|
||||
|
||||
#ifdef ProvideFast1088
|
||||
static void KeccakAbsorb1088bits(unsigned char *state, const unsigned char *data)
|
||||
{
|
||||
#if (PLATFORM_BYTE_ORDER == IS_LITTLE_ENDIAN)
|
||||
KeccakPermutationOnWordsAfterXoring1088bits((UINT64*)state, (const UINT64*)data);
|
||||
#else
|
||||
UINT64 dataAsWords[17];
|
||||
unsigned int i;
|
||||
|
||||
for(i=0; i<17; i++)
|
||||
fromBytesToWord(dataAsWords+i, data+(i*8));
|
||||
KeccakPermutationOnWordsAfterXoring1088bits((UINT64*)state, dataAsWords);
|
||||
#endif
|
||||
}
|
||||
#endif
|
||||
|
||||
#ifdef ProvideFast1152
|
||||
static void KeccakAbsorb1152bits(unsigned char *state, const unsigned char *data)
|
||||
{
|
||||
#if (PLATFORM_BYTE_ORDER == IS_LITTLE_ENDIAN)
|
||||
KeccakPermutationOnWordsAfterXoring1152bits((UINT64*)state, (const UINT64*)data);
|
||||
#else
|
||||
UINT64 dataAsWords[18];
|
||||
unsigned int i;
|
||||
|
||||
for(i=0; i<18; i++)
|
||||
fromBytesToWord(dataAsWords+i, data+(i*8));
|
||||
KeccakPermutationOnWordsAfterXoring1152bits((UINT64*)state, dataAsWords);
|
||||
#endif
|
||||
}
|
||||
#endif
|
||||
|
||||
#ifdef ProvideFast1344
|
||||
static void KeccakAbsorb1344bits(unsigned char *state, const unsigned char *data)
|
||||
{
|
||||
#if (PLATFORM_BYTE_ORDER == IS_LITTLE_ENDIAN)
|
||||
KeccakPermutationOnWordsAfterXoring1344bits((UINT64*)state, (const UINT64*)data);
|
||||
#else
|
||||
UINT64 dataAsWords[21];
|
||||
unsigned int i;
|
||||
|
||||
for(i=0; i<21; i++)
|
||||
fromBytesToWord(dataAsWords+i, data+(i*8));
|
||||
KeccakPermutationOnWordsAfterXoring1344bits((UINT64*)state, dataAsWords);
|
||||
#endif
|
||||
}
|
||||
#endif
|
||||
|
||||
static void KeccakAbsorb(unsigned char *state, const unsigned char *data, unsigned int laneCount)
|
||||
{
|
||||
#if (PLATFORM_BYTE_ORDER == IS_LITTLE_ENDIAN)
|
||||
KeccakPermutationOnWordsAfterXoring((UINT64*)state, (const UINT64*)data, laneCount);
|
||||
#else
|
||||
UINT64 dataAsWords[25];
|
||||
unsigned int i;
|
||||
|
||||
for(i=0; i<laneCount; i++)
|
||||
fromBytesToWord(dataAsWords+i, data+(i*8));
|
||||
KeccakPermutationOnWordsAfterXoring((UINT64*)state, dataAsWords, laneCount);
|
||||
#endif
|
||||
}
|
||||
|
||||
#if (PLATFORM_BYTE_ORDER == IS_BIG_ENDIAN)
|
||||
static void fromWordToBytes(UINT8 *bytes, const UINT64 word)
|
||||
{
|
||||
unsigned int i;
|
||||
|
||||
for(i=0; i<(64/8); i++)
|
||||
bytes[i] = (word >> (8*i)) & 0xFF;
|
||||
}
|
||||
#endif
|
||||
|
||||
#ifdef ProvideFast1024
|
||||
static void KeccakExtract1024bits(const unsigned char *state, unsigned char *data)
|
||||
{
|
||||
#if (PLATFORM_BYTE_ORDER == IS_LITTLE_ENDIAN)
|
||||
memcpy(data, state, 128);
|
||||
#else
|
||||
unsigned int i;
|
||||
|
||||
for(i=0; i<16; i++)
|
||||
fromWordToBytes(data+(i*8), ((const UINT64*)state)[i]);
|
||||
#endif
|
||||
#ifdef UseBebigokimisa
|
||||
((UINT64*)data)[ 1] = ~((UINT64*)data)[ 1];
|
||||
((UINT64*)data)[ 2] = ~((UINT64*)data)[ 2];
|
||||
((UINT64*)data)[ 8] = ~((UINT64*)data)[ 8];
|
||||
((UINT64*)data)[12] = ~((UINT64*)data)[12];
|
||||
#endif
|
||||
}
|
||||
#endif
|
||||
|
||||
static void KeccakExtract(const unsigned char *state, unsigned char *data, unsigned int laneCount)
|
||||
{
|
||||
#if (PLATFORM_BYTE_ORDER == IS_LITTLE_ENDIAN)
|
||||
memcpy(data, state, laneCount*8);
|
||||
#else
|
||||
unsigned int i;
|
||||
|
||||
for(i=0; i<laneCount; i++)
|
||||
fromWordToBytes(data+(i*8), ((const UINT64*)state)[i]);
|
||||
#endif
|
||||
#ifdef UseBebigokimisa
|
||||
if (laneCount > 1) {
|
||||
((UINT64*)data)[ 1] = ~((UINT64*)data)[ 1];
|
||||
if (laneCount > 2) {
|
||||
((UINT64*)data)[ 2] = ~((UINT64*)data)[ 2];
|
||||
if (laneCount > 8) {
|
||||
((UINT64*)data)[ 8] = ~((UINT64*)data)[ 8];
|
||||
if (laneCount > 12) {
|
||||
((UINT64*)data)[12] = ~((UINT64*)data)[12];
|
||||
if (laneCount > 17) {
|
||||
((UINT64*)data)[17] = ~((UINT64*)data)[17];
|
||||
if (laneCount > 20) {
|
||||
((UINT64*)data)[20] = ~((UINT64*)data)[20];
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif
|
||||
}
|
124
src/3rdparty/sha3/KeccakF-1600-unrolling.macros
vendored
124
src/3rdparty/sha3/KeccakF-1600-unrolling.macros
vendored
|
@ -1,124 +0,0 @@
|
|||
/*
|
||||
The Keccak sponge function, designed by Guido Bertoni, Joan Daemen,
|
||||
Michaël Peeters and Gilles Van Assche. For more information, feedback or
|
||||
questions, please refer to our website: http://keccak.noekeon.org/
|
||||
|
||||
Implementation by the designers,
|
||||
hereby denoted as "the implementer".
|
||||
|
||||
To the extent possible under law, the implementer has waived all copyright
|
||||
and related or neighboring rights to the source code in this file.
|
||||
http://creativecommons.org/publicdomain/zero/1.0/
|
||||
*/
|
||||
|
||||
#if (Unrolling == 24)
|
||||
#define rounds \
|
||||
prepareTheta \
|
||||
thetaRhoPiChiIotaPrepareTheta( 0, A, E) \
|
||||
thetaRhoPiChiIotaPrepareTheta( 1, E, A) \
|
||||
thetaRhoPiChiIotaPrepareTheta( 2, A, E) \
|
||||
thetaRhoPiChiIotaPrepareTheta( 3, E, A) \
|
||||
thetaRhoPiChiIotaPrepareTheta( 4, A, E) \
|
||||
thetaRhoPiChiIotaPrepareTheta( 5, E, A) \
|
||||
thetaRhoPiChiIotaPrepareTheta( 6, A, E) \
|
||||
thetaRhoPiChiIotaPrepareTheta( 7, E, A) \
|
||||
thetaRhoPiChiIotaPrepareTheta( 8, A, E) \
|
||||
thetaRhoPiChiIotaPrepareTheta( 9, E, A) \
|
||||
thetaRhoPiChiIotaPrepareTheta(10, A, E) \
|
||||
thetaRhoPiChiIotaPrepareTheta(11, E, A) \
|
||||
thetaRhoPiChiIotaPrepareTheta(12, A, E) \
|
||||
thetaRhoPiChiIotaPrepareTheta(13, E, A) \
|
||||
thetaRhoPiChiIotaPrepareTheta(14, A, E) \
|
||||
thetaRhoPiChiIotaPrepareTheta(15, E, A) \
|
||||
thetaRhoPiChiIotaPrepareTheta(16, A, E) \
|
||||
thetaRhoPiChiIotaPrepareTheta(17, E, A) \
|
||||
thetaRhoPiChiIotaPrepareTheta(18, A, E) \
|
||||
thetaRhoPiChiIotaPrepareTheta(19, E, A) \
|
||||
thetaRhoPiChiIotaPrepareTheta(20, A, E) \
|
||||
thetaRhoPiChiIotaPrepareTheta(21, E, A) \
|
||||
thetaRhoPiChiIotaPrepareTheta(22, A, E) \
|
||||
thetaRhoPiChiIota(23, E, A) \
|
||||
copyToState(state, A)
|
||||
#elif (Unrolling == 12)
|
||||
#define rounds \
|
||||
prepareTheta \
|
||||
for(i=0; i<24; i+=12) { \
|
||||
thetaRhoPiChiIotaPrepareTheta(i , A, E) \
|
||||
thetaRhoPiChiIotaPrepareTheta(i+ 1, E, A) \
|
||||
thetaRhoPiChiIotaPrepareTheta(i+ 2, A, E) \
|
||||
thetaRhoPiChiIotaPrepareTheta(i+ 3, E, A) \
|
||||
thetaRhoPiChiIotaPrepareTheta(i+ 4, A, E) \
|
||||
thetaRhoPiChiIotaPrepareTheta(i+ 5, E, A) \
|
||||
thetaRhoPiChiIotaPrepareTheta(i+ 6, A, E) \
|
||||
thetaRhoPiChiIotaPrepareTheta(i+ 7, E, A) \
|
||||
thetaRhoPiChiIotaPrepareTheta(i+ 8, A, E) \
|
||||
thetaRhoPiChiIotaPrepareTheta(i+ 9, E, A) \
|
||||
thetaRhoPiChiIotaPrepareTheta(i+10, A, E) \
|
||||
thetaRhoPiChiIotaPrepareTheta(i+11, E, A) \
|
||||
} \
|
||||
copyToState(state, A)
|
||||
#elif (Unrolling == 8)
|
||||
#define rounds \
|
||||
prepareTheta \
|
||||
for(i=0; i<24; i+=8) { \
|
||||
thetaRhoPiChiIotaPrepareTheta(i , A, E) \
|
||||
thetaRhoPiChiIotaPrepareTheta(i+1, E, A) \
|
||||
thetaRhoPiChiIotaPrepareTheta(i+2, A, E) \
|
||||
thetaRhoPiChiIotaPrepareTheta(i+3, E, A) \
|
||||
thetaRhoPiChiIotaPrepareTheta(i+4, A, E) \
|
||||
thetaRhoPiChiIotaPrepareTheta(i+5, E, A) \
|
||||
thetaRhoPiChiIotaPrepareTheta(i+6, A, E) \
|
||||
thetaRhoPiChiIotaPrepareTheta(i+7, E, A) \
|
||||
} \
|
||||
copyToState(state, A)
|
||||
#elif (Unrolling == 6)
|
||||
#define rounds \
|
||||
prepareTheta \
|
||||
for(i=0; i<24; i+=6) { \
|
||||
thetaRhoPiChiIotaPrepareTheta(i , A, E) \
|
||||
thetaRhoPiChiIotaPrepareTheta(i+1, E, A) \
|
||||
thetaRhoPiChiIotaPrepareTheta(i+2, A, E) \
|
||||
thetaRhoPiChiIotaPrepareTheta(i+3, E, A) \
|
||||
thetaRhoPiChiIotaPrepareTheta(i+4, A, E) \
|
||||
thetaRhoPiChiIotaPrepareTheta(i+5, E, A) \
|
||||
} \
|
||||
copyToState(state, A)
|
||||
#elif (Unrolling == 4)
|
||||
#define rounds \
|
||||
prepareTheta \
|
||||
for(i=0; i<24; i+=4) { \
|
||||
thetaRhoPiChiIotaPrepareTheta(i , A, E) \
|
||||
thetaRhoPiChiIotaPrepareTheta(i+1, E, A) \
|
||||
thetaRhoPiChiIotaPrepareTheta(i+2, A, E) \
|
||||
thetaRhoPiChiIotaPrepareTheta(i+3, E, A) \
|
||||
} \
|
||||
copyToState(state, A)
|
||||
#elif (Unrolling == 3)
|
||||
#define rounds \
|
||||
prepareTheta \
|
||||
for(i=0; i<24; i+=3) { \
|
||||
thetaRhoPiChiIotaPrepareTheta(i , A, E) \
|
||||
thetaRhoPiChiIotaPrepareTheta(i+1, E, A) \
|
||||
thetaRhoPiChiIotaPrepareTheta(i+2, A, E) \
|
||||
copyStateVariables(A, E) \
|
||||
} \
|
||||
copyToState(state, A)
|
||||
#elif (Unrolling == 2)
|
||||
#define rounds \
|
||||
prepareTheta \
|
||||
for(i=0; i<24; i+=2) { \
|
||||
thetaRhoPiChiIotaPrepareTheta(i , A, E) \
|
||||
thetaRhoPiChiIotaPrepareTheta(i+1, E, A) \
|
||||
} \
|
||||
copyToState(state, A)
|
||||
#elif (Unrolling == 1)
|
||||
#define rounds \
|
||||
prepareTheta \
|
||||
for(i=0; i<24; i++) { \
|
||||
thetaRhoPiChiIotaPrepareTheta(i , A, E) \
|
||||
copyStateVariables(A, E) \
|
||||
} \
|
||||
copyToState(state, A)
|
||||
#else
|
||||
#error "Unrolling is not correctly specified!"
|
||||
#endif
|
82
src/3rdparty/sha3/KeccakNISTInterface.c
vendored
82
src/3rdparty/sha3/KeccakNISTInterface.c
vendored
|
@ -1,82 +0,0 @@
|
|||
/*
|
||||
The Keccak sponge function, designed by Guido Bertoni, Joan Daemen,
|
||||
Michaël Peeters and Gilles Van Assche. For more information, feedback or
|
||||
questions, please refer to our website: http://keccak.noekeon.org/
|
||||
|
||||
Implementation by the designers,
|
||||
hereby denoted as "the implementer".
|
||||
|
||||
To the extent possible under law, the implementer has waived all copyright
|
||||
and related or neighboring rights to the source code in this file.
|
||||
http://creativecommons.org/publicdomain/zero/1.0/
|
||||
*/
|
||||
|
||||
#include <string.h>
|
||||
//#include "KeccakNISTInterface.h"
|
||||
#include "KeccakF-1600-interface.h"
|
||||
|
||||
static HashReturn s3Init(hashState *state, int hashbitlen)
|
||||
{
|
||||
switch(hashbitlen) {
|
||||
case 0: // Default parameters, arbitrary length output
|
||||
InitSponge((spongeState*)state, 1024, 576);
|
||||
break;
|
||||
case 224:
|
||||
InitSponge((spongeState*)state, 1152, 448);
|
||||
break;
|
||||
case 256:
|
||||
InitSponge((spongeState*)state, 1088, 512);
|
||||
break;
|
||||
case 384:
|
||||
InitSponge((spongeState*)state, 832, 768);
|
||||
break;
|
||||
case 512:
|
||||
InitSponge((spongeState*)state, 576, 1024);
|
||||
break;
|
||||
default:
|
||||
return BAD_HASHLEN;
|
||||
}
|
||||
state->fixedOutputLength = hashbitlen;
|
||||
return SUCCESS;
|
||||
}
|
||||
|
||||
static HashReturn s3Update(hashState *state, const BitSequence *data, DataLength databitlen)
|
||||
{
|
||||
if ((databitlen % 8) == 0)
|
||||
return (HashReturn) Absorb((spongeState*)state, data, databitlen);
|
||||
else {
|
||||
HashReturn ret = (HashReturn) Absorb((spongeState*)state, data, databitlen - (databitlen % 8));
|
||||
if (ret == SUCCESS) {
|
||||
unsigned char lastByte;
|
||||
// Align the last partial byte to the least significant bits
|
||||
lastByte = data[databitlen/8] >> (8 - (databitlen % 8));
|
||||
return (HashReturn) Absorb((spongeState*)state, &lastByte, databitlen % 8);
|
||||
}
|
||||
else
|
||||
return ret;
|
||||
}
|
||||
}
|
||||
|
||||
static HashReturn s3Final(hashState *state, BitSequence *hashval)
|
||||
{
|
||||
return (HashReturn) Squeeze(state, hashval, state->fixedOutputLength);
|
||||
}
|
||||
|
||||
#ifndef QT_KATIE
|
||||
static HashReturn s3Hash(int hashbitlen, const BitSequence *data, DataLength databitlen, BitSequence *hashval)
|
||||
{
|
||||
hashState state;
|
||||
HashReturn result;
|
||||
|
||||
if ((hashbitlen != 224) && (hashbitlen != 256) && (hashbitlen != 384) && (hashbitlen != 512))
|
||||
return BAD_HASHLEN; // Only the four fixed output lengths available through this API
|
||||
result = s3Init(&state, hashbitlen);
|
||||
if (result != SUCCESS)
|
||||
return result;
|
||||
result = s3Update(&state, data, databitlen);
|
||||
if (result != SUCCESS)
|
||||
return result;
|
||||
result = s3Final(&state, hashval);
|
||||
return result;
|
||||
}
|
||||
#endif
|
70
src/3rdparty/sha3/KeccakNISTInterface.h
vendored
70
src/3rdparty/sha3/KeccakNISTInterface.h
vendored
|
@ -1,70 +0,0 @@
|
|||
/*
|
||||
The Keccak sponge function, designed by Guido Bertoni, Joan Daemen,
|
||||
Michaël Peeters and Gilles Van Assche. For more information, feedback or
|
||||
questions, please refer to our website: http://keccak.noekeon.org/
|
||||
|
||||
Implementation by the designers,
|
||||
hereby denoted as "the implementer".
|
||||
|
||||
To the extent possible under law, the implementer has waived all copyright
|
||||
and related or neighboring rights to the source code in this file.
|
||||
http://creativecommons.org/publicdomain/zero/1.0/
|
||||
*/
|
||||
|
||||
#ifndef _KeccakNISTInterface_h_
|
||||
#define _KeccakNISTInterface_h_
|
||||
|
||||
#include "KeccakSponge.h"
|
||||
|
||||
typedef unsigned char BitSequence;
|
||||
typedef unsigned long long DataLength;
|
||||
typedef enum { SUCCESS = 0, FAIL = 1, BAD_HASHLEN = 2 } HashReturn;
|
||||
|
||||
typedef spongeState hashState;
|
||||
|
||||
/**
|
||||
* Function to initialize the state of the Keccak[r, c] sponge function.
|
||||
* The rate r and capacity c values are determined from @a hashbitlen.
|
||||
* @param state Pointer to the state of the sponge function to be initialized.
|
||||
* @param hashbitlen The desired number of output bits,
|
||||
* or 0 for Keccak[] with default parameters
|
||||
* and arbitrarily-long output.
|
||||
* @pre The value of hashbitlen must be one of 0, 224, 256, 384 and 512.
|
||||
* @return SUCCESS if successful, BAD_HASHLEN if the value of hashbitlen is incorrect.
|
||||
*/
|
||||
static HashReturn s3Init(hashState *state, int hashbitlen);
|
||||
/**
|
||||
* Function to give input data for the sponge function to absorb.
|
||||
* @param state Pointer to the state of the sponge function initialized by Init().
|
||||
* @param data Pointer to the input data.
|
||||
* When @a databitLen is not a multiple of 8, the last bits of data must be
|
||||
* in the most significant bits of the last byte.
|
||||
* @param databitLen The number of input bits provided in the input data.
|
||||
* @pre In the previous call to Absorb(), databitLen was a multiple of 8.
|
||||
* @return SUCCESS if successful, FAIL otherwise.
|
||||
*/
|
||||
static HashReturn s3Update(hashState *state, const BitSequence *data, DataLength databitlen);
|
||||
/**
|
||||
* Function to squeeze output data from the sponge function.
|
||||
* If @a hashbitlen was not 0 in the call to Init(), the number of output bits is equal to @a hashbitlen.
|
||||
* If @a hashbitlen was 0 in the call to Init(), the output bits must be extracted using the Squeeze() function.
|
||||
* @param state Pointer to the state of the sponge function initialized by Init().
|
||||
* @param hashval Pointer to the buffer where to store the output data.
|
||||
* @return SUCCESS if successful, FAIL otherwise.
|
||||
*/
|
||||
static HashReturn s3Final(hashState *state, BitSequence *hashval);
|
||||
/**
|
||||
* Function to compute a hash using the Keccak[r, c] sponge function.
|
||||
* The rate r and capacity c values are determined from @a hashbitlen.
|
||||
* @param hashbitlen The desired number of output bits.
|
||||
* @param data Pointer to the input data.
|
||||
* When @a databitLen is not a multiple of 8, the last bits of data must be
|
||||
* in the most significant bits of the last byte.
|
||||
* @param databitLen The number of input bits provided in the input data.
|
||||
* @param hashval Pointer to the buffer where to store the output data.
|
||||
* @pre The value of hashbitlen must be one of 224, 256, 384 and 512.
|
||||
* @return SUCCESS if successful, BAD_HASHLEN if the value of hashbitlen is incorrect.
|
||||
*/
|
||||
static HashReturn s3Hash(int hashbitlen, const BitSequence *data, DataLength databitlen, BitSequence *hashval);
|
||||
|
||||
#endif
|
266
src/3rdparty/sha3/KeccakSponge.c
vendored
266
src/3rdparty/sha3/KeccakSponge.c
vendored
|
@ -1,266 +0,0 @@
|
|||
/*
|
||||
The Keccak sponge function, designed by Guido Bertoni, Joan Daemen,
|
||||
Michaël Peeters and Gilles Van Assche. For more information, feedback or
|
||||
questions, please refer to our website: http://keccak.noekeon.org/
|
||||
|
||||
Implementation by the designers,
|
||||
hereby denoted as "the implementer".
|
||||
|
||||
To the extent possible under law, the implementer has waived all copyright
|
||||
and related or neighboring rights to the source code in this file.
|
||||
http://creativecommons.org/publicdomain/zero/1.0/
|
||||
*/
|
||||
|
||||
#include <string.h>
|
||||
#include "KeccakSponge.h"
|
||||
#include "KeccakF-1600-interface.h"
|
||||
#ifdef KeccakReference
|
||||
#include "displayIntermediateValues.h"
|
||||
#endif
|
||||
|
||||
static int InitSponge(spongeState *state, unsigned int rate, unsigned int capacity)
|
||||
{
|
||||
if (rate+capacity != 1600)
|
||||
return 1;
|
||||
if ((rate <= 0) || (rate >= 1600) || ((rate % 64) != 0))
|
||||
return 1;
|
||||
KeccakInitialize();
|
||||
state->rate = rate;
|
||||
state->capacity = capacity;
|
||||
state->fixedOutputLength = 0;
|
||||
KeccakInitializeState(state->state);
|
||||
memset(state->dataQueue, 0, KeccakMaximumRateInBytes);
|
||||
state->bitsInQueue = 0;
|
||||
state->squeezing = 0;
|
||||
state->bitsAvailableForSqueezing = 0;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static void AbsorbQueue(spongeState *state)
|
||||
{
|
||||
// state->bitsInQueue is assumed to be equal to state->rate
|
||||
#ifdef KeccakReference
|
||||
displayBytes(1, "Block to be absorbed", state->dataQueue, state->rate/8);
|
||||
#endif
|
||||
#ifdef ProvideFast576
|
||||
if (state->rate == 576)
|
||||
KeccakAbsorb576bits(state->state, state->dataQueue);
|
||||
else
|
||||
#endif
|
||||
#ifdef ProvideFast832
|
||||
if (state->rate == 832)
|
||||
KeccakAbsorb832bits(state->state, state->dataQueue);
|
||||
else
|
||||
#endif
|
||||
#ifdef ProvideFast1024
|
||||
if (state->rate == 1024)
|
||||
KeccakAbsorb1024bits(state->state, state->dataQueue);
|
||||
else
|
||||
#endif
|
||||
#ifdef ProvideFast1088
|
||||
if (state->rate == 1088)
|
||||
KeccakAbsorb1088bits(state->state, state->dataQueue);
|
||||
else
|
||||
#endif
|
||||
#ifdef ProvideFast1152
|
||||
if (state->rate == 1152)
|
||||
KeccakAbsorb1152bits(state->state, state->dataQueue);
|
||||
else
|
||||
#endif
|
||||
#ifdef ProvideFast1344
|
||||
if (state->rate == 1344)
|
||||
KeccakAbsorb1344bits(state->state, state->dataQueue);
|
||||
else
|
||||
#endif
|
||||
KeccakAbsorb(state->state, state->dataQueue, state->rate/64);
|
||||
state->bitsInQueue = 0;
|
||||
}
|
||||
|
||||
static int Absorb(spongeState *state, const unsigned char *data, unsigned long long databitlen)
|
||||
{
|
||||
unsigned long long i, j, wholeBlocks;
|
||||
unsigned int partialBlock, partialByte;
|
||||
const unsigned char *curData;
|
||||
|
||||
if ((state->bitsInQueue % 8) != 0)
|
||||
return 1; // Only the last call may contain a partial byte
|
||||
if (state->squeezing)
|
||||
return 1; // Too late for additional input
|
||||
|
||||
i = 0;
|
||||
while(i < databitlen) {
|
||||
if ((state->bitsInQueue == 0) && (databitlen >= state->rate) && (i <= (databitlen-state->rate))) {
|
||||
wholeBlocks = (databitlen-i)/state->rate;
|
||||
curData = data+i/8;
|
||||
#ifdef ProvideFast576
|
||||
if (state->rate == 576) {
|
||||
for(j=0; j<wholeBlocks; j++, curData+=576/8) {
|
||||
#ifdef KeccakReference
|
||||
displayBytes(1, "Block to be absorbed", curData, state->rate/8);
|
||||
#endif
|
||||
KeccakAbsorb576bits(state->state, curData);
|
||||
}
|
||||
}
|
||||
else
|
||||
#endif
|
||||
#ifdef ProvideFast832
|
||||
if (state->rate == 832) {
|
||||
for(j=0; j<wholeBlocks; j++, curData+=832/8) {
|
||||
#ifdef KeccakReference
|
||||
displayBytes(1, "Block to be absorbed", curData, state->rate/8);
|
||||
#endif
|
||||
KeccakAbsorb832bits(state->state, curData);
|
||||
}
|
||||
}
|
||||
else
|
||||
#endif
|
||||
#ifdef ProvideFast1024
|
||||
if (state->rate == 1024) {
|
||||
for(j=0; j<wholeBlocks; j++, curData+=1024/8) {
|
||||
#ifdef KeccakReference
|
||||
displayBytes(1, "Block to be absorbed", curData, state->rate/8);
|
||||
#endif
|
||||
KeccakAbsorb1024bits(state->state, curData);
|
||||
}
|
||||
}
|
||||
else
|
||||
#endif
|
||||
#ifdef ProvideFast1088
|
||||
if (state->rate == 1088) {
|
||||
for(j=0; j<wholeBlocks; j++, curData+=1088/8) {
|
||||
#ifdef KeccakReference
|
||||
displayBytes(1, "Block to be absorbed", curData, state->rate/8);
|
||||
#endif
|
||||
KeccakAbsorb1088bits(state->state, curData);
|
||||
}
|
||||
}
|
||||
else
|
||||
#endif
|
||||
#ifdef ProvideFast1152
|
||||
if (state->rate == 1152) {
|
||||
for(j=0; j<wholeBlocks; j++, curData+=1152/8) {
|
||||
#ifdef KeccakReference
|
||||
displayBytes(1, "Block to be absorbed", curData, state->rate/8);
|
||||
#endif
|
||||
KeccakAbsorb1152bits(state->state, curData);
|
||||
}
|
||||
}
|
||||
else
|
||||
#endif
|
||||
#ifdef ProvideFast1344
|
||||
if (state->rate == 1344) {
|
||||
for(j=0; j<wholeBlocks; j++, curData+=1344/8) {
|
||||
#ifdef KeccakReference
|
||||
displayBytes(1, "Block to be absorbed", curData, state->rate/8);
|
||||
#endif
|
||||
KeccakAbsorb1344bits(state->state, curData);
|
||||
}
|
||||
}
|
||||
else
|
||||
#endif
|
||||
{
|
||||
for(j=0; j<wholeBlocks; j++, curData+=state->rate/8) {
|
||||
#ifdef KeccakReference
|
||||
displayBytes(1, "Block to be absorbed", curData, state->rate/8);
|
||||
#endif
|
||||
KeccakAbsorb(state->state, curData, state->rate/64);
|
||||
}
|
||||
}
|
||||
i += wholeBlocks*state->rate;
|
||||
}
|
||||
else {
|
||||
partialBlock = (unsigned int)(databitlen - i);
|
||||
if (partialBlock+state->bitsInQueue > state->rate)
|
||||
partialBlock = state->rate-state->bitsInQueue;
|
||||
partialByte = partialBlock % 8;
|
||||
partialBlock -= partialByte;
|
||||
memcpy(state->dataQueue+state->bitsInQueue/8, data+i/8, partialBlock/8);
|
||||
state->bitsInQueue += partialBlock;
|
||||
i += partialBlock;
|
||||
if (state->bitsInQueue == state->rate)
|
||||
AbsorbQueue(state);
|
||||
if (partialByte > 0) {
|
||||
unsigned char mask = (1 << partialByte)-1;
|
||||
state->dataQueue[state->bitsInQueue/8] = data[i/8] & mask;
|
||||
state->bitsInQueue += partialByte;
|
||||
i += partialByte;
|
||||
}
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
static void PadAndSwitchToSqueezingPhase(spongeState *state)
|
||||
{
|
||||
// Note: the bits are numbered from 0=LSB to 7=MSB
|
||||
if (state->bitsInQueue + 1 == state->rate) {
|
||||
state->dataQueue[state->bitsInQueue/8 ] |= 1 << (state->bitsInQueue % 8);
|
||||
AbsorbQueue(state);
|
||||
memset(state->dataQueue, 0, state->rate/8);
|
||||
}
|
||||
else {
|
||||
memset(state->dataQueue + (state->bitsInQueue+7)/8, 0, state->rate/8 - (state->bitsInQueue+7)/8);
|
||||
state->dataQueue[state->bitsInQueue/8 ] |= 1 << (state->bitsInQueue % 8);
|
||||
}
|
||||
state->dataQueue[(state->rate-1)/8] |= 1 << ((state->rate-1) % 8);
|
||||
AbsorbQueue(state);
|
||||
|
||||
#ifdef KeccakReference
|
||||
displayText(1, "--- Switching to squeezing phase ---");
|
||||
#endif
|
||||
#ifdef ProvideFast1024
|
||||
if (state->rate == 1024) {
|
||||
KeccakExtract1024bits(state->state, state->dataQueue);
|
||||
state->bitsAvailableForSqueezing = 1024;
|
||||
}
|
||||
else
|
||||
#endif
|
||||
{
|
||||
KeccakExtract(state->state, state->dataQueue, state->rate/64);
|
||||
state->bitsAvailableForSqueezing = state->rate;
|
||||
}
|
||||
#ifdef KeccakReference
|
||||
displayBytes(1, "Block available for squeezing", state->dataQueue, state->bitsAvailableForSqueezing/8);
|
||||
#endif
|
||||
state->squeezing = 1;
|
||||
}
|
||||
|
||||
static int Squeeze(spongeState *state, unsigned char *output, unsigned long long outputLength)
|
||||
{
|
||||
unsigned long long i;
|
||||
unsigned int partialBlock;
|
||||
|
||||
if (!state->squeezing)
|
||||
PadAndSwitchToSqueezingPhase(state);
|
||||
if ((outputLength % 8) != 0)
|
||||
return 1; // Only multiple of 8 bits are allowed, truncation can be done at user level
|
||||
|
||||
i = 0;
|
||||
while(i < outputLength) {
|
||||
if (state->bitsAvailableForSqueezing == 0) {
|
||||
KeccakPermutation(state->state);
|
||||
#ifdef ProvideFast1024
|
||||
if (state->rate == 1024) {
|
||||
KeccakExtract1024bits(state->state, state->dataQueue);
|
||||
state->bitsAvailableForSqueezing = 1024;
|
||||
}
|
||||
else
|
||||
#endif
|
||||
{
|
||||
KeccakExtract(state->state, state->dataQueue, state->rate/64);
|
||||
state->bitsAvailableForSqueezing = state->rate;
|
||||
}
|
||||
#ifdef KeccakReference
|
||||
displayBytes(1, "Block available for squeezing", state->dataQueue, state->bitsAvailableForSqueezing/8);
|
||||
#endif
|
||||
}
|
||||
partialBlock = state->bitsAvailableForSqueezing;
|
||||
if ((unsigned long long)partialBlock > outputLength - i)
|
||||
partialBlock = (unsigned int)(outputLength - i);
|
||||
memcpy(output+i/8, state->dataQueue+(state->rate-state->bitsAvailableForSqueezing)/8, partialBlock/8);
|
||||
state->bitsAvailableForSqueezing -= partialBlock;
|
||||
i += partialBlock;
|
||||
}
|
||||
return 0;
|
||||
}
|
80
src/3rdparty/sha3/KeccakSponge.h
vendored
80
src/3rdparty/sha3/KeccakSponge.h
vendored
|
@ -1,80 +0,0 @@
|
|||
/*
|
||||
The Keccak sponge function, designed by Guido Bertoni, Joan Daemen,
|
||||
Michaël Peeters and Gilles Van Assche. For more information, feedback or
|
||||
questions, please refer to our website: http://keccak.noekeon.org/
|
||||
|
||||
Implementation by the designers,
|
||||
hereby denoted as "the implementer".
|
||||
|
||||
To the extent possible under law, the implementer has waived all copyright
|
||||
and related or neighboring rights to the source code in this file.
|
||||
http://creativecommons.org/publicdomain/zero/1.0/
|
||||
*/
|
||||
|
||||
#ifndef _KeccakSponge_h_
|
||||
#define _KeccakSponge_h_
|
||||
|
||||
#define KeccakPermutationSize 1600
|
||||
#define KeccakPermutationSizeInBytes (KeccakPermutationSize/8)
|
||||
#define KeccakMaximumRate 1536
|
||||
#define KeccakMaximumRateInBytes (KeccakMaximumRate/8)
|
||||
|
||||
#if defined(UseSSE) || defined(UseXOP)
|
||||
#if defined(__GNUC__)
|
||||
#define ALIGN __attribute__ ((aligned(32)))
|
||||
#elif defined(_MSC_VER)
|
||||
#define ALIGN __declspec(align(32))
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#ifndef ALIGN
|
||||
# define ALIGN
|
||||
#endif
|
||||
|
||||
ALIGN typedef struct spongeStateStruct {
|
||||
ALIGN unsigned char state[KeccakPermutationSizeInBytes];
|
||||
ALIGN unsigned char dataQueue[KeccakMaximumRateInBytes];
|
||||
unsigned int rate;
|
||||
unsigned int capacity;
|
||||
unsigned int bitsInQueue;
|
||||
unsigned int fixedOutputLength;
|
||||
int squeezing;
|
||||
unsigned int bitsAvailableForSqueezing;
|
||||
} spongeState;
|
||||
|
||||
/**
|
||||
* Function to initialize the state of the Keccak[r, c] sponge function.
|
||||
* The sponge function is set to the absorbing phase.
|
||||
* @param state Pointer to the state of the sponge function to be initialized.
|
||||
* @param rate The value of the rate r.
|
||||
* @param capacity The value of the capacity c.
|
||||
* @pre One must have r+c=1600 and the rate a multiple of 64 bits in this implementation.
|
||||
* @return Zero if successful, 1 otherwise.
|
||||
*/
|
||||
static int InitSponge(spongeState *state, unsigned int rate, unsigned int capacity);
|
||||
/**
|
||||
* Function to give input data for the sponge function to absorb.
|
||||
* @param state Pointer to the state of the sponge function initialized by InitSponge().
|
||||
* @param data Pointer to the input data.
|
||||
* When @a databitLen is not a multiple of 8, the last bits of data must be
|
||||
* in the least significant bits of the last byte.
|
||||
* @param databitLen The number of input bits provided in the input data.
|
||||
* @pre In the previous call to Absorb(), databitLen was a multiple of 8.
|
||||
* @pre The sponge function must be in the absorbing phase,
|
||||
* i.e., Squeeze() must not have been called before.
|
||||
* @return Zero if successful, 1 otherwise.
|
||||
*/
|
||||
static int Absorb(spongeState *state, const unsigned char *data, unsigned long long databitlen);
|
||||
/**
|
||||
* Function to squeeze output data from the sponge function.
|
||||
* If the sponge function was in the absorbing phase, this function
|
||||
* switches it to the squeezing phase.
|
||||
* @param state Pointer to the state of the sponge function initialized by InitSponge().
|
||||
* @param output Pointer to the buffer where to store the output data.
|
||||
* @param outputLength The number of output bits desired.
|
||||
* It must be a multiple of 8.
|
||||
* @return Zero if successful, 1 otherwise.
|
||||
*/
|
||||
static int Squeeze(spongeState *state, unsigned char *output, unsigned long long outputLength);
|
||||
|
||||
#endif
|
142
src/3rdparty/sha3/brg_endian.h
vendored
142
src/3rdparty/sha3/brg_endian.h
vendored
|
@ -1,142 +0,0 @@
|
|||
/*
|
||||
---------------------------------------------------------------------------
|
||||
Copyright (c) 1998-2008, Brian Gladman, Worcester, UK. All rights reserved.
|
||||
|
||||
LICENSE TERMS
|
||||
|
||||
The redistribution and use of this software (with or without changes)
|
||||
is allowed without the payment of fees or royalties provided that:
|
||||
|
||||
1. source code distributions include the above copyright notice, this
|
||||
list of conditions and the following disclaimer;
|
||||
|
||||
2. binary distributions include the above copyright notice, this list
|
||||
of conditions and the following disclaimer in their documentation;
|
||||
|
||||
3. the name of the copyright holder is not used to endorse products
|
||||
built using this software without specific written permission.
|
||||
|
||||
DISCLAIMER
|
||||
|
||||
This software is provided 'as is' with no explicit or implied warranties
|
||||
in respect of its properties, including, but not limited to, correctness
|
||||
and/or fitness for purpose.
|
||||
---------------------------------------------------------------------------
|
||||
Issue Date: 20/12/2007
|
||||
Changes for ARM 9/9/2010
|
||||
*/
|
||||
|
||||
#ifndef _BRG_ENDIAN_H
|
||||
#define _BRG_ENDIAN_H
|
||||
|
||||
#define IS_BIG_ENDIAN 4321 /* byte 0 is most significant (mc68k) */
|
||||
#define IS_LITTLE_ENDIAN 1234 /* byte 0 is least significant (i386) */
|
||||
|
||||
#if 0
|
||||
/* Include files where endian defines and byteswap functions may reside */
|
||||
#if defined( __sun )
|
||||
# include <sys/isa_defs.h>
|
||||
#elif defined( __FreeBSD__ ) || defined( __OpenBSD__ ) || defined( __NetBSD__ )
|
||||
# include <sys/endian.h>
|
||||
#elif defined( BSD ) && ( BSD >= 199103 ) || defined( __APPLE__ ) || \
|
||||
defined( __CYGWIN32__ ) || defined( __DJGPP__ ) || defined( __osf__ )
|
||||
# include <machine/endian.h>
|
||||
#elif defined( __linux__ ) || defined( __GNUC__ ) || defined( __GNU_LIBRARY__ )
|
||||
# if !defined( __MINGW32__ ) && !defined( _AIX )
|
||||
# include <endian.h>
|
||||
# if !defined( __BEOS__ )
|
||||
# include <byteswap.h>
|
||||
# endif
|
||||
# endif
|
||||
#endif
|
||||
#endif
|
||||
|
||||
/* Now attempt to set the define for platform byte order using any */
|
||||
/* of the four forms SYMBOL, _SYMBOL, __SYMBOL & __SYMBOL__, which */
|
||||
/* seem to encompass most endian symbol definitions */
|
||||
|
||||
#if defined( BIG_ENDIAN ) && defined( LITTLE_ENDIAN )
|
||||
# if defined( BYTE_ORDER ) && BYTE_ORDER == BIG_ENDIAN
|
||||
# define PLATFORM_BYTE_ORDER IS_BIG_ENDIAN
|
||||
# elif defined( BYTE_ORDER ) && BYTE_ORDER == LITTLE_ENDIAN
|
||||
# define PLATFORM_BYTE_ORDER IS_LITTLE_ENDIAN
|
||||
# endif
|
||||
#elif defined( BIG_ENDIAN )
|
||||
# define PLATFORM_BYTE_ORDER IS_BIG_ENDIAN
|
||||
#elif defined( LITTLE_ENDIAN )
|
||||
# define PLATFORM_BYTE_ORDER IS_LITTLE_ENDIAN
|
||||
#endif
|
||||
|
||||
#if defined( _BIG_ENDIAN ) && defined( _LITTLE_ENDIAN )
|
||||
# if defined( _BYTE_ORDER ) && _BYTE_ORDER == _BIG_ENDIAN
|
||||
# define PLATFORM_BYTE_ORDER IS_BIG_ENDIAN
|
||||
# elif defined( _BYTE_ORDER ) && _BYTE_ORDER == _LITTLE_ENDIAN
|
||||
# define PLATFORM_BYTE_ORDER IS_LITTLE_ENDIAN
|
||||
# endif
|
||||
#elif defined( _BIG_ENDIAN )
|
||||
# define PLATFORM_BYTE_ORDER IS_BIG_ENDIAN
|
||||
#elif defined( _LITTLE_ENDIAN )
|
||||
# define PLATFORM_BYTE_ORDER IS_LITTLE_ENDIAN
|
||||
#endif
|
||||
|
||||
#if defined( __BIG_ENDIAN ) && defined( __LITTLE_ENDIAN )
|
||||
# if defined( __BYTE_ORDER ) && __BYTE_ORDER == __BIG_ENDIAN
|
||||
# define PLATFORM_BYTE_ORDER IS_BIG_ENDIAN
|
||||
# elif defined( __BYTE_ORDER ) && __BYTE_ORDER == __LITTLE_ENDIAN
|
||||
# define PLATFORM_BYTE_ORDER IS_LITTLE_ENDIAN
|
||||
# endif
|
||||
#elif defined( __BIG_ENDIAN )
|
||||
# define PLATFORM_BYTE_ORDER IS_BIG_ENDIAN
|
||||
#elif defined( __LITTLE_ENDIAN )
|
||||
# define PLATFORM_BYTE_ORDER IS_LITTLE_ENDIAN
|
||||
#endif
|
||||
|
||||
#if defined( __BIG_ENDIAN__ ) && defined( __LITTLE_ENDIAN__ )
|
||||
# if defined( __BYTE_ORDER__ ) && __BYTE_ORDER__ == __BIG_ENDIAN__
|
||||
# define PLATFORM_BYTE_ORDER IS_BIG_ENDIAN
|
||||
# elif defined( __BYTE_ORDER__ ) && __BYTE_ORDER__ == __LITTLE_ENDIAN__
|
||||
# define PLATFORM_BYTE_ORDER IS_LITTLE_ENDIAN
|
||||
# endif
|
||||
#elif defined( __BIG_ENDIAN__ )
|
||||
# define PLATFORM_BYTE_ORDER IS_BIG_ENDIAN
|
||||
#elif defined( __LITTLE_ENDIAN__ )
|
||||
# define PLATFORM_BYTE_ORDER IS_LITTLE_ENDIAN
|
||||
#endif
|
||||
|
||||
/* if the platform byte order could not be determined, then try to */
|
||||
/* set this define using common machine defines */
|
||||
#if !defined(PLATFORM_BYTE_ORDER)
|
||||
|
||||
#if defined( __alpha__ ) || defined( __alpha ) || defined( i386 ) || \
|
||||
defined( __i386__ ) || defined( _M_I86 ) || defined( _M_IX86 ) || \
|
||||
defined( __OS2__ ) || defined( sun386 ) || defined( __TURBOC__ ) || \
|
||||
defined( vax ) || defined( vms ) || defined( VMS ) || \
|
||||
defined( __VMS ) || defined( _M_X64 )
|
||||
# define PLATFORM_BYTE_ORDER IS_LITTLE_ENDIAN
|
||||
|
||||
#elif defined( AMIGA ) || defined( applec ) || defined( __AS400__ ) || \
|
||||
defined( _CRAY ) || defined( __hppa ) || defined( __hp9000 ) || \
|
||||
defined( ibm370 ) || defined( mc68000 ) || defined( m68k ) || \
|
||||
defined( __MRC__ ) || defined( __MVS__ ) || defined( __MWERKS__ ) || \
|
||||
defined( sparc ) || defined( __sparc) || defined( SYMANTEC_C ) || \
|
||||
defined( __VOS__ ) || defined( __TIGCC__ ) || defined( __TANDEM ) || \
|
||||
defined( THINK_C ) || defined( __VMCMS__ ) || defined( _AIX )
|
||||
# define PLATFORM_BYTE_ORDER IS_BIG_ENDIAN
|
||||
|
||||
#elif defined(__arm__)
|
||||
# ifdef __BIG_ENDIAN
|
||||
# define PLATFORM_BYTE_ORDER IS_BIG_ENDIAN
|
||||
# else
|
||||
# define PLATFORM_BYTE_ORDER IS_LITTLE_ENDIAN
|
||||
# endif
|
||||
#elif 1 /* **** EDIT HERE IF NECESSARY **** */
|
||||
# define PLATFORM_BYTE_ORDER IS_LITTLE_ENDIAN
|
||||
#elif 0 /* **** EDIT HERE IF NECESSARY **** */
|
||||
# define PLATFORM_BYTE_ORDER IS_BIG_ENDIAN
|
||||
#else
|
||||
# error Please edit lines 132 or 134 in brg_endian.h to set the platform byte order
|
||||
#endif
|
||||
|
||||
#endif
|
||||
|
||||
#endif
|
|
@ -1,5 +1,5 @@
|
|||
add_definitions(-DQT_BUILD_CORE_LIB)
|
||||
set(EXTRA_CORE_LIBS ${ZLIB_LIBRARIES})
|
||||
set(EXTRA_CORE_LIBS ${ZLIB_LIBRARIES} ${OPENSSL_LIBRARIES})
|
||||
|
||||
set(CORE_PUBLIC_HEADERS
|
||||
${CORE_PUBLIC_HEADERS}
|
||||
|
|
|
@ -42,89 +42,9 @@
|
|||
#include <qcryptographichash.h>
|
||||
#include <qiodevice.h>
|
||||
|
||||
#include "../../3rdparty/md5/md5.h"
|
||||
#include "../../3rdparty/md5/md5.cpp"
|
||||
#include "../../3rdparty/md4/md4.h"
|
||||
#include "../../3rdparty/md4/md4.cpp"
|
||||
#include "../../3rdparty/sha1/sha1.cpp"
|
||||
|
||||
typedef unsigned char BitSequence;
|
||||
typedef unsigned long long DataLength;
|
||||
typedef enum { SUCCESS = 0, FAIL = 1, BAD_HASHLEN = 2 } HashReturn;
|
||||
|
||||
#include "../../3rdparty/sha3/KeccakSponge.c"
|
||||
typedef spongeState hashState;
|
||||
|
||||
#include "../../3rdparty/sha3/KeccakNISTInterface.c"
|
||||
|
||||
/*
|
||||
This lets us choose between SHA3 implementations at build time.
|
||||
*/
|
||||
typedef spongeState SHA3Context;
|
||||
typedef HashReturn (SHA3Init)(hashState *state, int hashbitlen);
|
||||
typedef HashReturn (SHA3Update)(hashState *state, const BitSequence *data, DataLength databitlen);
|
||||
typedef HashReturn (SHA3Final)(hashState *state, BitSequence *hashval);
|
||||
|
||||
#if QT_POINTER_SIZE == 8 // 64 bit version
|
||||
#include "../../3rdparty/sha3/KeccakF-1600-opt64.c"
|
||||
#else // 32 bit optimised fallback
|
||||
#include "../../3rdparty/sha3/KeccakF-1600-opt32.c"
|
||||
#endif
|
||||
static SHA3Init * const sha3Init = s3Init;
|
||||
static SHA3Update * const sha3Update = s3Update;
|
||||
static SHA3Final * const sha3Final = s3Final;
|
||||
|
||||
/*
|
||||
These #defines replace the typedefs needed by the RFC6234 code. Normally
|
||||
the typedefs would come from from stdint.h, but since this header is not
|
||||
available on all platforms (MSVC 2008, for example), we #define them to the
|
||||
Qt equivalents.
|
||||
*/
|
||||
#define uint64_t QT_PREPEND_NAMESPACE(quint64)
|
||||
#define uint32_t QT_PREPEND_NAMESPACE(quint32)
|
||||
#define uint8_t QT_PREPEND_NAMESPACE(quint8)
|
||||
#define int_least16_t QT_PREPEND_NAMESPACE(qint16)
|
||||
|
||||
// Header from rfc6234 with 1 modification:
|
||||
// sha1.h - commented out '#include <stdint.h>' on line 74
|
||||
#include "../../3rdparty/rfc6234/sha.h"
|
||||
|
||||
/*
|
||||
These 2 functions replace macros of the same name in sha224-256.c and
|
||||
sha384-512.c. Originally, these macros relied on a global static 'addTemp'
|
||||
variable. We do not want this for 2 reasons:
|
||||
|
||||
1. since we are including the sources directly, the declaration of the 2 conflict
|
||||
|
||||
2. static variables are not thread-safe, we do not want multiple threads
|
||||
computing a hash to corrupt one another
|
||||
*/
|
||||
static int SHA224_256AddLength(SHA256Context *context, unsigned int length);
|
||||
static int SHA384_512AddLength(SHA512Context *context, unsigned int length);
|
||||
|
||||
// Sources from rfc6234, with 4 modifications:
|
||||
// sha224-256.c - commented out 'static uint32_t addTemp;' on line 68
|
||||
// sha224-256.c - appended 'M' to the SHA224_256AddLength macro on line 70
|
||||
#include "../../3rdparty/rfc6234/sha224-256.c"
|
||||
// sha384-512.c - commented out 'static uint64_t addTemp;' on line 302
|
||||
// sha384-512.c - appended 'M' to the SHA224_256AddLength macro on line 304
|
||||
#include "../../3rdparty/rfc6234/sha384-512.c"
|
||||
|
||||
#undef uint64_t
|
||||
#undef uint32_t
|
||||
#undef uint68_t
|
||||
#undef int_least16_t
|
||||
|
||||
static inline int SHA224_256AddLength(SHA256Context *context, unsigned int length)
|
||||
{
|
||||
QT_PREPEND_NAMESPACE(quint32) addTemp;
|
||||
return SHA224_256AddLengthM(context, length);
|
||||
}
|
||||
static inline int SHA384_512AddLength(SHA512Context *context, unsigned int length)
|
||||
{
|
||||
QT_PREPEND_NAMESPACE(quint64) addTemp;
|
||||
return SHA384_512AddLengthM(context, length);
|
||||
}
|
||||
#include <openssl/md5.h>
|
||||
#include <openssl/md4.h>
|
||||
#include <openssl/sha.h>
|
||||
|
||||
QT_BEGIN_NAMESPACE
|
||||
|
||||
|
@ -133,14 +53,13 @@ class QCryptographicHashPrivate
|
|||
public:
|
||||
QCryptographicHash::Algorithm method;
|
||||
union {
|
||||
MD5Context md5Context;
|
||||
md4_context md4Context;
|
||||
Sha1State sha1Context;
|
||||
SHA224Context sha224Context;
|
||||
SHA256Context sha256Context;
|
||||
SHA384Context sha384Context;
|
||||
SHA512Context sha512Context;
|
||||
SHA3Context sha3Context;
|
||||
MD4_CTX md4Context;
|
||||
MD5_CTX md5Context;
|
||||
SHA_CTX sha1Context;
|
||||
SHA256_CTX sha224Context;
|
||||
SHA256_CTX sha256Context;
|
||||
SHA512_CTX sha384Context;
|
||||
SHA512_CTX sha512Context;
|
||||
};
|
||||
QByteArray result;
|
||||
};
|
||||
|
@ -171,10 +90,6 @@ public:
|
|||
\value Sha256 Generate an SHA-256 hash sum (SHA-2). Introduced in Katie 4.9
|
||||
\value Sha384 Generate an SHA-384 hash sum (SHA-2). Introduced in Katie 4.9
|
||||
\value Sha512 Generate an SHA-512 hash sum (SHA-2). Introduced in Katie 4.9
|
||||
\value Sha3_224 Generate an SHA3-224 hash sum. Introduced in Katie 4.9
|
||||
\value Sha3_256 Generate an SHA3-256 hash sum. Introduced in Katie 4.9
|
||||
\value Sha3_384 Generate an SHA3-384 hash sum. Introduced in Katie 4.9
|
||||
\value Sha3_512 Generate an SHA3-512 hash sum. Introduced in Katie 4.9
|
||||
*/
|
||||
|
||||
/*!
|
||||
|
@ -201,38 +116,26 @@ QCryptographicHash::~QCryptographicHash()
|
|||
void QCryptographicHash::reset()
|
||||
{
|
||||
switch (d->method) {
|
||||
case Sha1:
|
||||
sha1InitState(&d->sha1Context);
|
||||
break;
|
||||
case Md4:
|
||||
md4_init(&d->md4Context);
|
||||
MD4_Init(&d->md4Context);
|
||||
break;
|
||||
case Md5:
|
||||
MD5Init(&d->md5Context);
|
||||
MD5_Init(&d->md5Context);
|
||||
break;
|
||||
case Sha1:
|
||||
SHA1_Init(&d->sha1Context);
|
||||
break;
|
||||
case Sha224:
|
||||
SHA224Reset(&d->sha224Context);
|
||||
SHA224_Init(&d->sha224Context);
|
||||
break;
|
||||
case Sha256:
|
||||
SHA256Reset(&d->sha256Context);
|
||||
SHA256_Init(&d->sha256Context);
|
||||
break;
|
||||
case Sha384:
|
||||
SHA384Reset(&d->sha384Context);
|
||||
SHA384_Init(&d->sha384Context);
|
||||
break;
|
||||
case Sha512:
|
||||
SHA512Reset(&d->sha512Context);
|
||||
break;
|
||||
case Sha3_224:
|
||||
sha3Init(&d->sha3Context, 224);
|
||||
break;
|
||||
case Sha3_256:
|
||||
sha3Init(&d->sha3Context, 256);
|
||||
break;
|
||||
case Sha3_384:
|
||||
sha3Init(&d->sha3Context, 384);
|
||||
break;
|
||||
case Sha3_512:
|
||||
sha3Init(&d->sha3Context, 512);
|
||||
SHA512_Init(&d->sha512Context);
|
||||
break;
|
||||
}
|
||||
d->result.clear();
|
||||
|
@ -245,38 +148,26 @@ void QCryptographicHash::reset()
|
|||
void QCryptographicHash::addData(const char *data, int length)
|
||||
{
|
||||
switch (d->method) {
|
||||
case Sha1:
|
||||
sha1Update(&d->sha1Context, (const unsigned char *)data, length);
|
||||
break;
|
||||
case Md4:
|
||||
md4_update(&d->md4Context, (const unsigned char *)data, length);
|
||||
MD4_Update(&d->md4Context, (const unsigned char *)data, length);
|
||||
break;
|
||||
case Md5:
|
||||
MD5Update(&d->md5Context, (const unsigned char *)data, length);
|
||||
MD5_Update(&d->md5Context, (const unsigned char *)data, length);
|
||||
break;
|
||||
case Sha1:
|
||||
SHA1_Update(&d->sha1Context, (const unsigned char *)data, length);
|
||||
break;
|
||||
case Sha224:
|
||||
SHA224Input(&d->sha224Context, reinterpret_cast<const unsigned char *>(data), length);
|
||||
SHA224_Update(&d->sha224Context, reinterpret_cast<const unsigned char *>(data), length);
|
||||
break;
|
||||
case Sha256:
|
||||
SHA256Input(&d->sha256Context, reinterpret_cast<const unsigned char *>(data), length);
|
||||
SHA256_Update(&d->sha256Context, reinterpret_cast<const unsigned char *>(data), length);
|
||||
break;
|
||||
case Sha384:
|
||||
SHA384Input(&d->sha384Context, reinterpret_cast<const unsigned char *>(data), length);
|
||||
SHA384_Update(&d->sha384Context, reinterpret_cast<const unsigned char *>(data), length);
|
||||
break;
|
||||
case Sha512:
|
||||
SHA512Input(&d->sha512Context, reinterpret_cast<const unsigned char *>(data), length);
|
||||
break;
|
||||
case Sha3_224:
|
||||
sha3Update(&d->sha3Context, reinterpret_cast<const BitSequence *>(data), length*8);
|
||||
break;
|
||||
case Sha3_256:
|
||||
sha3Update(&d->sha3Context, reinterpret_cast<const BitSequence *>(data), length*8);
|
||||
break;
|
||||
case Sha3_384:
|
||||
sha3Update(&d->sha3Context, reinterpret_cast<const BitSequence *>(data), length*8);
|
||||
break;
|
||||
case Sha3_512:
|
||||
sha3Update(&d->sha3Context, reinterpret_cast<const BitSequence *>(data), length*8);
|
||||
SHA512_Update(&d->sha512Context, reinterpret_cast<const unsigned char *>(data), length);
|
||||
break;
|
||||
}
|
||||
d->result.clear();
|
||||
|
@ -316,71 +207,46 @@ QByteArray QCryptographicHash::result() const
|
|||
return d->result;
|
||||
|
||||
switch (d->method) {
|
||||
case Sha1: {
|
||||
Sha1State copy = d->sha1Context;
|
||||
d->result.resize(20);
|
||||
sha1FinalizeState(©);
|
||||
sha1ToHash(©, (unsigned char *)d->result.data());
|
||||
break;
|
||||
}
|
||||
case Md4: {
|
||||
md4_context copy = d->md4Context;
|
||||
d->result.resize(MD4_RESULTLEN);
|
||||
md4_final(©, (unsigned char *)d->result.data());
|
||||
MD4_CTX copy = d->md4Context;
|
||||
d->result.resize(16);
|
||||
MD4_Final((unsigned char *)d->result.data(), ©);
|
||||
break;
|
||||
}
|
||||
case Md5: {
|
||||
MD5Context copy = d->md5Context;
|
||||
MD5_CTX copy = d->md5Context;
|
||||
d->result.resize(16);
|
||||
MD5Final(©, (unsigned char *)d->result.data());
|
||||
MD5_Final((unsigned char *)d->result.data(), ©);
|
||||
break;
|
||||
}
|
||||
case Sha1: {
|
||||
SHA_CTX copy = d->sha1Context;
|
||||
d->result.resize(20);
|
||||
SHA1_Final((unsigned char *)d->result.data(), ©);
|
||||
break;
|
||||
}
|
||||
case Sha224: {
|
||||
SHA224Context copy = d->sha224Context;
|
||||
d->result.resize(SHA224HashSize);
|
||||
SHA224Result(©, reinterpret_cast<unsigned char *>(d->result.data()));
|
||||
SHA256_CTX copy = d->sha224Context;
|
||||
d->result.resize(57);
|
||||
SHA224_Final(reinterpret_cast<unsigned char *>(d->result.data()), ©);
|
||||
break;
|
||||
}
|
||||
case Sha256:{
|
||||
SHA256Context copy = d->sha256Context;
|
||||
d->result.resize(SHA256HashSize);
|
||||
SHA256Result(©, reinterpret_cast<unsigned char *>(d->result.data()));
|
||||
SHA256_CTX copy = d->sha256Context;
|
||||
d->result.resize(65);
|
||||
SHA256_Final(reinterpret_cast<unsigned char *>(d->result.data()), ©);
|
||||
break;
|
||||
}
|
||||
case Sha384:{
|
||||
SHA384Context copy = d->sha384Context;
|
||||
d->result.resize(SHA384HashSize);
|
||||
SHA384Result(©, reinterpret_cast<unsigned char *>(d->result.data()));
|
||||
SHA512_CTX copy = d->sha384Context;
|
||||
d->result.resize(97);
|
||||
SHA384_Final(reinterpret_cast<unsigned char *>(d->result.data()), ©);
|
||||
break;
|
||||
}
|
||||
case Sha512:{
|
||||
SHA512Context copy = d->sha512Context;
|
||||
d->result.resize(SHA512HashSize);
|
||||
SHA512Result(©, reinterpret_cast<unsigned char *>(d->result.data()));
|
||||
break;
|
||||
}
|
||||
case Sha3_224: {
|
||||
SHA3Context copy = d->sha3Context;
|
||||
d->result.resize(224/8);
|
||||
sha3Final(©, reinterpret_cast<BitSequence *>(d->result.data()));
|
||||
break;
|
||||
}
|
||||
case Sha3_256: {
|
||||
SHA3Context copy = d->sha3Context;
|
||||
d->result.resize(256/8);
|
||||
sha3Final(©, reinterpret_cast<BitSequence *>(d->result.data()));
|
||||
break;
|
||||
}
|
||||
case Sha3_384: {
|
||||
SHA3Context copy = d->sha3Context;
|
||||
d->result.resize(384/8);
|
||||
sha3Final(©, reinterpret_cast<BitSequence *>(d->result.data()));
|
||||
break;
|
||||
}
|
||||
case Sha3_512: {
|
||||
SHA3Context copy = d->sha3Context;
|
||||
d->result.resize(512/8);
|
||||
sha3Final(©, reinterpret_cast<BitSequence *>(d->result.data()));
|
||||
SHA512_CTX copy = d->sha512Context;
|
||||
d->result.resize(129);
|
||||
SHA512_Final(reinterpret_cast<unsigned char *>(d->result.data()), ©);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -62,11 +62,7 @@ public:
|
|||
Sha224,
|
||||
Sha256,
|
||||
Sha384,
|
||||
Sha512,
|
||||
Sha3_224,
|
||||
Sha3_256,
|
||||
Sha3_384,
|
||||
Sha3_512
|
||||
Sha512
|
||||
};
|
||||
|
||||
explicit QCryptographicHash(Algorithm method);
|
||||
|
|
|
@ -123,9 +123,3 @@ set(EXTRA_CORE_LIBS
|
|||
${EXTRA_CORE_LIBS}
|
||||
m
|
||||
)
|
||||
|
||||
include_directories(
|
||||
${CMAKE_SOURCE_DIR}/src/3rdparty/md5
|
||||
${CMAKE_SOURCE_DIR}/src/3rdparty/md4
|
||||
${CMAKE_SOURCE_DIR}/src/3rdparty/sha3
|
||||
)
|
||||
|
|
|
@ -121,9 +121,7 @@ public:
|
|||
void _q_slotError(QAbstractSocket::SocketError);
|
||||
void _q_slotClosed();
|
||||
void _q_slotBytesWritten(qint64 numBytes);
|
||||
#ifndef QT_NO_OPENSSL
|
||||
void _q_slotEncryptedBytesWritten(qint64 numBytes);
|
||||
#endif
|
||||
void _q_slotDoFinished();
|
||||
void _q_slotSendRequest();
|
||||
void _q_continuePost();
|
||||
|
@ -364,15 +362,6 @@ void QHttpSetHostRequest::start(QHttp *http)
|
|||
http->d_func()->port = port;
|
||||
http->d_func()->mode = mode;
|
||||
|
||||
#ifdef QT_NO_OPENSSL
|
||||
if (mode == QHttp::ConnectionModeHttps) {
|
||||
// SSL requested but no SSL support compiled in
|
||||
http->d_func()->finishedWithError(QLatin1String(QT_TRANSLATE_NOOP("QHttp", "HTTPS connection requested but SSL support not compiled in")),
|
||||
QHttp::UnknownError);
|
||||
return;
|
||||
}
|
||||
#endif
|
||||
|
||||
http->d_func()->finishedWithSuccess();
|
||||
}
|
||||
|
||||
|
@ -2057,10 +2046,6 @@ int QHttp::setHost(const QString &hostName, quint16 port)
|
|||
*/
|
||||
int QHttp::setHost(const QString &hostName, ConnectionMode mode, quint16 port)
|
||||
{
|
||||
#ifdef QT_NO_OPENSSL
|
||||
if (mode == ConnectionModeHttps)
|
||||
qWarning("QHttp::setHost: HTTPS connection requested but SSL support not compiled in");
|
||||
#endif
|
||||
Q_D(QHttp);
|
||||
if (port == 0)
|
||||
port = (mode == ConnectionModeHttp) ? 80 : 443;
|
||||
|
@ -2419,11 +2404,9 @@ void QHttpPrivate::_q_slotSendRequest()
|
|||
int connectionPort = port;
|
||||
bool sslInUse = false;
|
||||
|
||||
#ifndef QT_NO_OPENSSL
|
||||
QSslSocket *sslSocket = qobject_cast<QSslSocket *>(socket);
|
||||
if (mode == QHttp::ConnectionModeHttps || (sslSocket && sslSocket->isEncrypted()))
|
||||
sslInUse = true;
|
||||
#endif
|
||||
|
||||
#ifndef QT_NO_NETWORKPROXY
|
||||
bool cachingProxyInUse = false;
|
||||
|
@ -2491,21 +2474,15 @@ void QHttpPrivate::_q_slotSendRequest()
|
|||
// existing one?
|
||||
if (socket->peerName() != connectionHost || socket->peerPort() != connectionPort
|
||||
|| socket->state() != QTcpSocket::ConnectedState
|
||||
#ifndef QT_NO_OPENSSL
|
||||
|| (sslSocket && sslSocket->isEncrypted() != (mode == QHttp::ConnectionModeHttps))
|
||||
#endif
|
||||
) {
|
||||
|| (sslSocket && sslSocket->isEncrypted() != (mode == QHttp::ConnectionModeHttps))) {
|
||||
socket->blockSignals(true);
|
||||
socket->abort();
|
||||
socket->blockSignals(false);
|
||||
|
||||
setState(QHttp::Connecting);
|
||||
#ifndef QT_NO_OPENSSL
|
||||
if (sslSocket && mode == QHttp::ConnectionModeHttps) {
|
||||
sslSocket->connectToHostEncrypted(hostName, port);
|
||||
} else
|
||||
#endif
|
||||
{
|
||||
} else {
|
||||
socket->connectToHost(connectionHost, connectionPort);
|
||||
}
|
||||
} else {
|
||||
|
@ -2664,13 +2641,11 @@ void QHttpPrivate::_q_slotError(QAbstractSocket::SocketError err)
|
|||
closeConn();
|
||||
}
|
||||
|
||||
#ifndef QT_NO_OPENSSL
|
||||
void QHttpPrivate::_q_slotEncryptedBytesWritten(qint64 written)
|
||||
{
|
||||
Q_UNUSED(written);
|
||||
postMoreData();
|
||||
}
|
||||
#endif
|
||||
|
||||
void QHttpPrivate::_q_slotBytesWritten(qint64 written)
|
||||
{
|
||||
|
@ -2691,13 +2666,9 @@ void QHttpPrivate::postMoreData()
|
|||
|
||||
// the following is backported code from Qt 4.6 QNetworkAccessManager.
|
||||
// We also have to check the encryptedBytesToWrite() if it is an SSL socket.
|
||||
#ifndef QT_NO_OPENSSL
|
||||
QSslSocket *sslSocket = qobject_cast<QSslSocket*>(socket);
|
||||
// if it is really an ssl socket, check more than just bytesToWrite()
|
||||
if ((socket->bytesToWrite() + (sslSocket ? sslSocket->encryptedBytesToWrite() : 0)) == 0) {
|
||||
#else
|
||||
if (socket->bytesToWrite() == 0) {
|
||||
#endif
|
||||
int max = qMin<qint64>(4096, postDevice->size() - postDevice->pos());
|
||||
QByteArray arr;
|
||||
arr.resize(max);
|
||||
|
@ -3099,11 +3070,9 @@ void QHttpPrivate::setSock(QTcpSocket *sock)
|
|||
deleteSocket = (sock == 0);
|
||||
socket = sock;
|
||||
if (!socket) {
|
||||
#ifndef QT_NO_OPENSSL
|
||||
if (QSslSocket::supportsSsl())
|
||||
socket = new QSslSocket();
|
||||
else
|
||||
#endif
|
||||
socket = new QTcpSocket();
|
||||
}
|
||||
|
||||
|
@ -3119,14 +3088,12 @@ void QHttpPrivate::setSock(QTcpSocket *sock)
|
|||
q, SIGNAL(proxyAuthenticationRequired(QNetworkProxy,QAuthenticator*)));
|
||||
#endif
|
||||
|
||||
#ifndef QT_NO_OPENSSL
|
||||
if (qobject_cast<QSslSocket *>(socket)) {
|
||||
QObject::connect(socket, SIGNAL(sslErrors(QList<QSslError>)),
|
||||
q, SIGNAL(sslErrors(QList<QSslError>)));
|
||||
QObject::connect(socket, SIGNAL(encryptedBytesWritten(qint64)),
|
||||
q, SLOT(_q_slotEncryptedBytesWritten(qint64)));
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
/*!
|
||||
|
@ -3138,7 +3105,6 @@ void QHttpPrivate::setSock(QTcpSocket *sock)
|
|||
|
||||
\sa QSslSocket QSslSocket::sslErrors()
|
||||
*/
|
||||
#ifndef QT_NO_OPENSSL
|
||||
void QHttp::ignoreSslErrors()
|
||||
{
|
||||
Q_D(QHttp);
|
||||
|
@ -3146,12 +3112,9 @@ void QHttp::ignoreSslErrors()
|
|||
if (sslSocket)
|
||||
sslSocket->ignoreSslErrors();
|
||||
}
|
||||
#endif
|
||||
|
||||
QT_END_NAMESPACE
|
||||
|
||||
|
||||
|
||||
#endif
|
||||
|
||||
#include "moc_qhttp.h"
|
||||
|
|
|
@ -249,9 +249,7 @@ public:
|
|||
public Q_SLOTS:
|
||||
void abort();
|
||||
|
||||
#ifndef QT_NO_OPENSSL
|
||||
void ignoreSslErrors();
|
||||
#endif
|
||||
|
||||
Q_SIGNALS:
|
||||
void stateChanged(int);
|
||||
|
@ -271,9 +269,7 @@ Q_SIGNALS:
|
|||
#endif
|
||||
void authenticationRequired(const QString &hostname, quint16 port, QAuthenticator *);
|
||||
|
||||
#ifndef QT_NO_OPENSSL
|
||||
void sslErrors(const QList<QSslError> &errors);
|
||||
#endif
|
||||
|
||||
private:
|
||||
Q_DISABLE_COPY(QHttp)
|
||||
|
@ -285,9 +281,7 @@ private:
|
|||
Q_PRIVATE_SLOT(d_func(), void _q_slotError(QAbstractSocket::SocketError))
|
||||
Q_PRIVATE_SLOT(d_func(), void _q_slotClosed())
|
||||
Q_PRIVATE_SLOT(d_func(), void _q_slotBytesWritten(qint64 numBytes))
|
||||
#ifndef QT_NO_OPENSSL
|
||||
Q_PRIVATE_SLOT(d_func(), void _q_slotEncryptedBytesWritten(qint64 numBytes))
|
||||
#endif
|
||||
Q_PRIVATE_SLOT(d_func(), void _q_slotDoFinished())
|
||||
Q_PRIVATE_SLOT(d_func(), void _q_slotSendRequest())
|
||||
Q_PRIVATE_SLOT(d_func(), void _q_continuePost())
|
||||
|
|
|
@ -57,14 +57,10 @@
|
|||
|
||||
#ifndef QT_NO_HTTP
|
||||
|
||||
#ifndef QT_NO_OPENSSL
|
||||
# include <qsslsocket_p.h>
|
||||
# include <QtNetwork/qsslkey.h>
|
||||
# include <QtNetwork/qsslcipher.h>
|
||||
# include <QtNetwork/qsslconfiguration.h>
|
||||
#endif
|
||||
|
||||
|
||||
#include <qsslsocket_p.h>
|
||||
#include <QtNetwork/qsslkey.h>
|
||||
#include <QtNetwork/qsslcipher.h>
|
||||
#include <QtNetwork/qsslconfiguration.h>
|
||||
|
||||
QT_BEGIN_NAMESPACE
|
||||
|
||||
|
@ -131,11 +127,9 @@ void QHttpNetworkConnectionPrivate::pauseConnection()
|
|||
|
||||
// Disable all socket notifiers
|
||||
for (int i = 0; i < channelCount; i++) {
|
||||
#ifndef QT_NO_OPENSSL
|
||||
if (encrypt)
|
||||
QSslSocketPrivate::pauseSocketNotifiers(static_cast<QSslSocket*>(channels[i].socket));
|
||||
else
|
||||
#endif
|
||||
QAbstractSocketPrivate::pauseSocketNotifiers(channels[i].socket);
|
||||
}
|
||||
}
|
||||
|
@ -145,11 +139,9 @@ void QHttpNetworkConnectionPrivate::resumeConnection()
|
|||
state = RunningState;
|
||||
// Enable all socket notifiers
|
||||
for (int i = 0; i < channelCount; i++) {
|
||||
#ifndef QT_NO_OPENSSL
|
||||
if (encrypt)
|
||||
QSslSocketPrivate::resumeSocketNotifiers(static_cast<QSslSocket*>(channels[i].socket));
|
||||
else
|
||||
#endif
|
||||
QAbstractSocketPrivate::resumeSocketNotifiers(channels[i].socket);
|
||||
|
||||
// Resume pending upload if needed
|
||||
|
@ -974,7 +966,6 @@ QNetworkProxy QHttpNetworkConnection::transparentProxy() const
|
|||
|
||||
|
||||
// SSL support below
|
||||
#ifndef QT_NO_OPENSSL
|
||||
void QHttpNetworkConnection::setSslConfiguration(const QSslConfiguration &config)
|
||||
{
|
||||
Q_D(QHttpNetworkConnection);
|
||||
|
@ -1022,8 +1013,6 @@ void QHttpNetworkConnection::ignoreSslErrors(const QList<QSslError> &errors, int
|
|||
}
|
||||
}
|
||||
|
||||
#endif //QT_NO_OPENSSL
|
||||
|
||||
#ifndef QT_NO_NETWORKPROXY
|
||||
// only called from QHttpNetworkConnectionChannel::_q_proxyAuthenticationRequired, not
|
||||
// from QHttpNetworkConnectionChannel::handleAuthenticationChallenge
|
||||
|
|
|
@ -56,6 +56,8 @@
|
|||
#include <QtNetwork/qnetworkreply.h>
|
||||
#include <QtNetwork/qabstractsocket.h>
|
||||
#include <QtNetwork/qnetworksession.h>
|
||||
#include <QtNetwork/qsslsocket.h>
|
||||
#include <QtNetwork/qsslerror.h>
|
||||
|
||||
#include <qobject_p.h>
|
||||
#include <qauthenticator.h>
|
||||
|
@ -70,13 +72,6 @@
|
|||
|
||||
#ifndef QT_NO_HTTP
|
||||
|
||||
#ifndef QT_NO_OPENSSL
|
||||
# include <QtNetwork/qsslsocket.h>
|
||||
# include <QtNetwork/qsslerror.h>
|
||||
#else
|
||||
# include <QtNetwork/qtcpsocket.h>
|
||||
#endif
|
||||
|
||||
QT_BEGIN_NAMESPACE
|
||||
|
||||
class QHttpNetworkRequest;
|
||||
|
@ -118,11 +113,9 @@ public:
|
|||
|
||||
QHttpNetworkConnectionChannel *channels() const;
|
||||
|
||||
#ifndef QT_NO_OPENSSL
|
||||
void setSslConfiguration(const QSslConfiguration &config);
|
||||
void ignoreSslErrors(int channel = -1);
|
||||
void ignoreSslErrors(const QList<QSslError> &errors, int channel = -1);
|
||||
#endif
|
||||
|
||||
private:
|
||||
Q_DECLARE_PRIVATE(QHttpNetworkConnection)
|
||||
|
|
|
@ -42,18 +42,14 @@
|
|||
#include "qhttpnetworkconnection_p.h"
|
||||
#include "qhttpnetworkconnectionchannel_p.h"
|
||||
#include "qnoncontiguousbytedevice_p.h"
|
||||
|
||||
#include <QtNetwork/qsslkey.h>
|
||||
#include <QtNetwork/qsslcipher.h>
|
||||
#include <QtNetwork/qsslconfiguration.h>
|
||||
#include <qpair.h>
|
||||
#include <qdebug.h>
|
||||
|
||||
#ifndef QT_NO_HTTP
|
||||
|
||||
#ifndef QT_NO_OPENSSL
|
||||
# include <QtNetwork/qsslkey.h>
|
||||
# include <QtNetwork/qsslcipher.h>
|
||||
# include <QtNetwork/qsslconfiguration.h>
|
||||
#endif
|
||||
|
||||
#ifndef QT_NO_BEARERMANAGEMENT
|
||||
#include "qnetworksession_p.h"
|
||||
#endif
|
||||
|
@ -77,9 +73,7 @@ QHttpNetworkConnectionChannel::QHttpNetworkConnectionChannel()
|
|||
, proxyAuthMethod(QAuthenticatorPrivate::None)
|
||||
, authenticationCredentialsSent(false)
|
||||
, proxyCredentialsSent(false)
|
||||
#ifndef QT_NO_OPENSSL
|
||||
, ignoreAllSslErrors(false)
|
||||
#endif
|
||||
, pipeliningSupported(PipeliningSupportUnknown)
|
||||
, connection(0)
|
||||
{
|
||||
|
@ -89,14 +83,10 @@ QHttpNetworkConnectionChannel::QHttpNetworkConnectionChannel()
|
|||
|
||||
void QHttpNetworkConnectionChannel::init()
|
||||
{
|
||||
#ifndef QT_NO_OPENSSL
|
||||
if (connection->d_func()->encrypt)
|
||||
socket = new QSslSocket;
|
||||
else
|
||||
socket = new QTcpSocket;
|
||||
#else
|
||||
socket = new QTcpSocket;
|
||||
#endif
|
||||
#ifndef QT_NO_BEARERMANAGEMENT
|
||||
//push session down to socket
|
||||
if (networkSession)
|
||||
|
@ -142,7 +132,6 @@ void QHttpNetworkConnectionChannel::init()
|
|||
Qt::DirectConnection);
|
||||
#endif
|
||||
|
||||
#ifndef QT_NO_OPENSSL
|
||||
QSslSocket *sslSocket = qobject_cast<QSslSocket*>(socket);
|
||||
if (sslSocket) {
|
||||
// won't be a sslSocket if encrypt is false
|
||||
|
@ -156,7 +145,6 @@ void QHttpNetworkConnectionChannel::init()
|
|||
this, SLOT(_q_encryptedBytesWritten(qint64)),
|
||||
Qt::QueuedConnection);
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
|
@ -261,16 +249,10 @@ bool QHttpNetworkConnectionChannel::sendRequest()
|
|||
const qint64 socketWriteMaxSize = 16*1024;
|
||||
|
||||
|
||||
#ifndef QT_NO_OPENSSL
|
||||
QSslSocket *sslSocket = qobject_cast<QSslSocket*>(socket);
|
||||
// if it is really an ssl socket, check more than just bytesToWrite()
|
||||
while ((socket->bytesToWrite() + (sslSocket ? sslSocket->encryptedBytesToWrite() : 0))
|
||||
<= socketBufferFill && bytesTotal != written)
|
||||
#else
|
||||
while (socket->bytesToWrite() <= socketBufferFill
|
||||
&& bytesTotal != written)
|
||||
#endif
|
||||
{
|
||||
<= socketBufferFill && bytesTotal != written) {
|
||||
// get pointer to upload data
|
||||
qint64 currentReadSize = 0;
|
||||
qint64 desiredReadSize = qMin(socketWriteMaxSize, bytesTotal - written);
|
||||
|
@ -615,7 +597,6 @@ bool QHttpNetworkConnectionChannel::ensureConnection()
|
|||
}
|
||||
#endif
|
||||
if (ssl) {
|
||||
#ifndef QT_NO_OPENSSL
|
||||
QSslSocket *sslSocket = qobject_cast<QSslSocket*>(socket);
|
||||
sslSocket->connectToHostEncrypted(connectHost, connectPort);
|
||||
if (ignoreAllSslErrors)
|
||||
|
@ -626,9 +607,6 @@ bool QHttpNetworkConnectionChannel::ensureConnection()
|
|||
// the QHttpNetworkReply anyway, so let's grow only that and not
|
||||
// here and there.
|
||||
socket->setReadBufferSize(64*1024);
|
||||
#else
|
||||
connection->d_func()->emitReplyError(socket, reply, QNetworkReply::ProtocolUnknownError);
|
||||
#endif
|
||||
} else {
|
||||
// In case of no proxy we can use the Unbuffered QTcpSocket
|
||||
#ifndef QT_NO_NETWORKPROXY
|
||||
|
@ -1111,9 +1089,8 @@ void QHttpNetworkConnectionChannel::_q_error(QAbstractSocket::SocketError socket
|
|||
// in memory and we will not recieve more data on the socket.
|
||||
reply->setReadBufferSize(0);
|
||||
_q_receiveReply();
|
||||
#ifndef QT_NO_OPENSSL
|
||||
if (ssl) {
|
||||
// QT_NO_OPENSSL. The QSslSocket can still have encrypted bytes in the plainsocket.
|
||||
// The QSslSocket can still have encrypted bytes in the plainsocket.
|
||||
// So we need to check this if the socket is a QSslSocket. When the socket is flushed
|
||||
// it will force a decrypt of the encrypted data in the plainsocket.
|
||||
QSslSocket *sslSocket = static_cast<QSslSocket*>(socket);
|
||||
|
@ -1127,7 +1104,6 @@ void QHttpNetworkConnectionChannel::_q_error(QAbstractSocket::SocketError socket
|
|||
beforeFlush = afterFlush;
|
||||
}
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
errorCode = QNetworkReply::RemoteHostClosedError;
|
||||
|
@ -1191,7 +1167,6 @@ void QHttpNetworkConnectionChannel::_q_uploadDataReadyRead()
|
|||
}
|
||||
}
|
||||
|
||||
#ifndef QT_NO_OPENSSL
|
||||
void QHttpNetworkConnectionChannel::_q_encrypted()
|
||||
{
|
||||
if (!socket)
|
||||
|
@ -1228,8 +1203,6 @@ void QHttpNetworkConnectionChannel::_q_encryptedBytesWritten(qint64 bytes)
|
|||
// otherwise we do nothing
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
void QHttpNetworkConnectionChannel::setConnection(QHttpNetworkConnection *c)
|
||||
{
|
||||
// Inlining this function in the header leads to compiler error on
|
||||
|
|
|
@ -55,6 +55,8 @@
|
|||
#include <QtNetwork/qnetworkrequest.h>
|
||||
#include <QtNetwork/qnetworkreply.h>
|
||||
#include <QtNetwork/qabstractsocket.h>
|
||||
#include <QtNetwork/qsslsocket.h>
|
||||
#include <QtNetwork/qsslerror.h>
|
||||
|
||||
#include <qobject_p.h>
|
||||
#include <qauthenticator.h>
|
||||
|
@ -69,13 +71,6 @@
|
|||
|
||||
#ifndef QT_NO_HTTP
|
||||
|
||||
#ifndef QT_NO_OPENSSL
|
||||
# include <QtNetwork/qsslsocket.h>
|
||||
# include <QtNetwork/qsslerror.h>
|
||||
#else
|
||||
# include <QtNetwork/qtcpsocket.h>
|
||||
#endif
|
||||
|
||||
QT_BEGIN_NAMESPACE
|
||||
|
||||
class QHttpNetworkRequest;
|
||||
|
@ -115,10 +110,8 @@ public:
|
|||
QAuthenticator proxyAuthenticator;
|
||||
bool authenticationCredentialsSent;
|
||||
bool proxyCredentialsSent;
|
||||
#ifndef QT_NO_OPENSSL
|
||||
bool ignoreAllSslErrors;
|
||||
QList<QSslError> ignoreSslErrorsList;
|
||||
#endif
|
||||
#ifndef QT_NO_BEARERMANAGEMENT
|
||||
QSharedPointer<QNetworkSession> networkSession;
|
||||
#endif
|
||||
|
@ -178,11 +171,9 @@ public:
|
|||
|
||||
void _q_uploadDataReadyRead();
|
||||
|
||||
#ifndef QT_NO_OPENSSL
|
||||
void _q_encrypted(); // start sending request (https)
|
||||
void _q_sslErrors(const QList<QSslError> &errors); // ssl errors from the socket
|
||||
void _q_encryptedBytesWritten(qint64 bytes); // proceed sending
|
||||
#endif
|
||||
};
|
||||
|
||||
QT_END_NAMESPACE
|
||||
|
|
|
@ -46,11 +46,9 @@
|
|||
|
||||
#ifndef QT_NO_HTTP
|
||||
|
||||
#ifndef QT_NO_OPENSSL
|
||||
# include <QtNetwork/qsslkey.h>
|
||||
# include <QtNetwork/qsslcipher.h>
|
||||
# include <QtNetwork/qsslconfiguration.h>
|
||||
#endif
|
||||
#include <QtNetwork/qsslkey.h>
|
||||
#include <QtNetwork/qsslcipher.h>
|
||||
#include <QtNetwork/qsslconfiguration.h>
|
||||
|
||||
QT_BEGIN_NAMESPACE
|
||||
|
||||
|
@ -957,8 +955,6 @@ void QHttpNetworkReplyPrivate::eraseData()
|
|||
|
||||
|
||||
// SSL support below
|
||||
#ifndef QT_NO_OPENSSL
|
||||
|
||||
QSslConfiguration QHttpNetworkReply::sslConfiguration() const
|
||||
{
|
||||
Q_D(const QHttpNetworkReply);
|
||||
|
@ -995,9 +991,6 @@ void QHttpNetworkReply::ignoreSslErrors(const QList<QSslError> &errors)
|
|||
}
|
||||
|
||||
|
||||
#endif //QT_NO_OPENSSL
|
||||
|
||||
|
||||
QT_END_NAMESPACE
|
||||
|
||||
#endif // QT_NO_HTTP
|
||||
|
|
|
@ -143,7 +143,6 @@ public:
|
|||
|
||||
QHttpNetworkConnection* connection();
|
||||
|
||||
#ifndef QT_NO_OPENSSL
|
||||
QSslConfiguration sslConfiguration() const;
|
||||
void setSslConfiguration(const QSslConfiguration &config);
|
||||
void ignoreSslErrors();
|
||||
|
@ -151,7 +150,6 @@ public:
|
|||
|
||||
Q_SIGNALS:
|
||||
void sslErrors(const QList<QSslError> &errors);
|
||||
#endif
|
||||
|
||||
Q_SIGNALS:
|
||||
void readyRead();
|
||||
|
|
|
@ -273,12 +273,10 @@ void QHttpThreadDelegate::startRequest()
|
|||
#else
|
||||
httpConnection = new QNetworkAccessCachedHttpConnection(urlCopy.host(), urlCopy.port(), ssl, networkSession);
|
||||
#endif
|
||||
#ifndef QT_NO_OPENSSL
|
||||
// Set the QSslConfiguration from this QNetworkRequest.
|
||||
if (ssl && incomingSslConfiguration != QSslConfiguration::defaultConfiguration()) {
|
||||
httpConnection->setSslConfiguration(incomingSslConfiguration);
|
||||
}
|
||||
#endif
|
||||
|
||||
#ifndef QT_NO_NETWORKPROXY
|
||||
httpConnection->setTransparentProxy(transparentProxy);
|
||||
|
@ -315,9 +313,7 @@ void QHttpThreadDelegate::startRequest()
|
|||
// some signals are only interesting when normal asynchronous style is used
|
||||
connect(httpReply,SIGNAL(readyRead()), this, SLOT(readyReadSlot()));
|
||||
connect(httpReply,SIGNAL(dataReadProgress(int,int)), this, SLOT(dataReadProgressSlot(int,int)));
|
||||
#ifndef QT_NO_OPENSSL
|
||||
connect(httpReply,SIGNAL(sslErrors(QList<QSslError>)), this, SLOT(sslErrorsSlot(QList<QSslError>)));
|
||||
#endif
|
||||
|
||||
// In the asynchronous HTTP case we can just forward those signals
|
||||
// Connect the reply signals that we can directly forward
|
||||
|
@ -424,10 +420,8 @@ void QHttpThreadDelegate::finishedSlot()
|
|||
emit downloadData(httpReply->readAny());
|
||||
}
|
||||
|
||||
#ifndef QT_NO_OPENSSL
|
||||
if (ssl)
|
||||
emit sslConfigurationChanged(httpReply->sslConfiguration());
|
||||
#endif
|
||||
|
||||
if (httpReply->statusCode() >= 400) {
|
||||
// it's an error reply
|
||||
|
@ -476,10 +470,8 @@ void QHttpThreadDelegate::finishedWithErrorSlot(QNetworkReply::NetworkError erro
|
|||
qDebug() << "QHttpThreadDelegate::finishedWithErrorSlot() thread=" << QThread::currentThreadId() << "error=" << errorCode << detail;
|
||||
#endif
|
||||
|
||||
#ifndef QT_NO_OPENSSL
|
||||
if (ssl)
|
||||
emit sslConfigurationChanged(httpReply->sslConfiguration());
|
||||
#endif
|
||||
emit error(errorCode,detail);
|
||||
emit downloadFinished();
|
||||
|
||||
|
@ -515,10 +507,8 @@ void QHttpThreadDelegate::headerChangedSlot()
|
|||
qDebug() << "QHttpThreadDelegate::headerChangedSlot() thread=" << QThread::currentThreadId();
|
||||
#endif
|
||||
|
||||
#ifndef QT_NO_OPENSSL
|
||||
if (ssl)
|
||||
emit sslConfigurationChanged(httpReply->sslConfiguration());
|
||||
#endif
|
||||
|
||||
// Is using a zerocopy buffer allowed by user and possible with this reply?
|
||||
if (httpReply->supportsUserProvidedDownloadBuffer()
|
||||
|
@ -578,8 +568,6 @@ void QHttpThreadDelegate::cacheCredentialsSlot(const QHttpNetworkRequest &reques
|
|||
authenticationManager->cacheCredentials(request.url(), authenticator);
|
||||
}
|
||||
|
||||
|
||||
#ifndef QT_NO_OPENSSL
|
||||
void QHttpThreadDelegate::sslErrorsSlot(const QList<QSslError> &errors)
|
||||
{
|
||||
if (!httpReply)
|
||||
|
@ -595,7 +583,6 @@ void QHttpThreadDelegate::sslErrorsSlot(const QList<QSslError> &errors)
|
|||
if (!specificErrors.isEmpty())
|
||||
httpReply->ignoreSslErrors(specificErrors);
|
||||
}
|
||||
#endif
|
||||
|
||||
void QHttpThreadDelegate::synchronousAuthenticationRequiredSlot(const QHttpNetworkRequest &request, QAuthenticator *a)
|
||||
{
|
||||
|
|
|
@ -88,9 +88,7 @@ public:
|
|||
|
||||
// incoming
|
||||
bool ssl;
|
||||
#ifndef QT_NO_OPENSSL
|
||||
QSslConfiguration incomingSslConfiguration;
|
||||
#endif
|
||||
QHttpNetworkRequest httpRequest;
|
||||
qint64 downloadBufferMaximumSize;
|
||||
qint64 readBufferMaxSize;
|
||||
|
@ -134,10 +132,8 @@ signals:
|
|||
#ifndef QT_NO_NETWORKPROXY
|
||||
void proxyAuthenticationRequired(const QNetworkProxy &, QAuthenticator *);
|
||||
#endif
|
||||
#ifndef QT_NO_OPENSSL
|
||||
void sslErrors(const QList<QSslError> &, bool *, QList<QSslError> *);
|
||||
void sslConfigurationChanged(const QSslConfiguration);
|
||||
#endif
|
||||
void downloadMetaData(QList<QPair<QByteArray,QByteArray> >,int,QString,bool,QSharedPointer<char>,qint64);
|
||||
void downloadProgress(qint64, qint64);
|
||||
void downloadData(QByteArray);
|
||||
|
@ -162,9 +158,7 @@ protected slots:
|
|||
void synchronousHeaderChangedSlot();
|
||||
void dataReadProgressSlot(int done, int total);
|
||||
void cacheCredentialsSlot(const QHttpNetworkRequest &request, QAuthenticator *authenticator);
|
||||
#ifndef QT_NO_OPENSSL
|
||||
void sslErrorsSlot(const QList<QSslError> &errors);
|
||||
#endif
|
||||
|
||||
void synchronousAuthenticationRequiredSlot(const QHttpNetworkRequest &request, QAuthenticator *);
|
||||
#ifndef QT_NO_NETWORKPROXY
|
||||
|
|
|
@ -354,11 +354,7 @@ void QNetworkAccessBackend::redirectionRequested(const QUrl &target)
|
|||
|
||||
void QNetworkAccessBackend::sslErrors(const QList<QSslError> &errors)
|
||||
{
|
||||
#ifndef QT_NO_OPENSSL
|
||||
reply->sslErrors(errors);
|
||||
#else
|
||||
Q_UNUSED(errors);
|
||||
#endif
|
||||
}
|
||||
|
||||
/*!
|
||||
|
|
|
@ -197,9 +197,8 @@ QNetworkAccessHttpBackend::QNetworkAccessHttpBackend()
|
|||
, pendingDownloadProgressEmissions(new QAtomicInt())
|
||||
, loadingFromCache(false)
|
||||
, usingZerocopyDownloadBuffer(false)
|
||||
#ifndef QT_NO_OPENSSL
|
||||
, pendingSslConfiguration(0), pendingIgnoreAllSslErrors(false)
|
||||
#endif
|
||||
, pendingSslConfiguration(0)
|
||||
, pendingIgnoreAllSslErrors(false)
|
||||
, resumeOffset(0)
|
||||
{
|
||||
}
|
||||
|
@ -209,9 +208,7 @@ QNetworkAccessHttpBackend::~QNetworkAccessHttpBackend()
|
|||
// This will do nothing if the request was already finished or aborted
|
||||
emit abortHttpRequest();
|
||||
|
||||
#ifndef QT_NO_OPENSSL
|
||||
delete pendingSslConfiguration;
|
||||
#endif
|
||||
}
|
||||
|
||||
/*
|
||||
|
@ -375,10 +372,8 @@ void QNetworkAccessHttpBackend::postRequest()
|
|||
#ifndef QT_NO_NETWORKPROXY
|
||||
qRegisterMetaType<QNetworkProxy>("QNetworkProxy");
|
||||
#endif
|
||||
#ifndef QT_NO_OPENSSL
|
||||
qRegisterMetaType<QList<QSslError> >("QList<QSslError>");
|
||||
qRegisterMetaType<QSslConfiguration>("QSslConfiguration");
|
||||
#endif
|
||||
qRegisterMetaType<QList<QPair<QByteArray,QByteArray> > >("QList<QPair<QByteArray,QByteArray> >");
|
||||
qRegisterMetaType<QHttpNetworkRequest>("QHttpNetworkRequest");
|
||||
qRegisterMetaType<QNetworkReply::NetworkError>("QNetworkReply::NetworkError");
|
||||
|
@ -538,10 +533,8 @@ void QNetworkAccessHttpBackend::postRequest()
|
|||
delegate->transparentProxy = transparentProxy;
|
||||
#endif
|
||||
delegate->ssl = ssl;
|
||||
#ifndef QT_NO_OPENSSL
|
||||
if (ssl)
|
||||
delegate->incomingSslConfiguration = request().sslConfiguration();
|
||||
#endif
|
||||
|
||||
// Do we use synchronous HTTP?
|
||||
delegate->synchronous = isSynchronous();
|
||||
|
@ -575,11 +568,9 @@ void QNetworkAccessHttpBackend::postRequest()
|
|||
connect(delegate, SIGNAL(error(QNetworkReply::NetworkError,QString)),
|
||||
this, SLOT(httpError(QNetworkReply::NetworkError,QString)),
|
||||
Qt::QueuedConnection);
|
||||
#ifndef QT_NO_OPENSSL
|
||||
connect(delegate, SIGNAL(sslConfigurationChanged(QSslConfiguration)),
|
||||
this, SLOT(replySslConfigurationChanged(QSslConfiguration)),
|
||||
Qt::QueuedConnection);
|
||||
#endif
|
||||
// Those need to report back, therefire BlockingQueuedConnection
|
||||
connect(delegate, SIGNAL(authenticationRequired(QHttpNetworkRequest,QAuthenticator*)),
|
||||
this, SLOT(httpAuthenticationRequired(QHttpNetworkRequest,QAuthenticator*)),
|
||||
|
@ -589,11 +580,9 @@ void QNetworkAccessHttpBackend::postRequest()
|
|||
this, SLOT(proxyAuthenticationRequired(QNetworkProxy,QAuthenticator*)),
|
||||
Qt::BlockingQueuedConnection);
|
||||
#endif
|
||||
#ifndef QT_NO_OPENSSL
|
||||
connect(delegate, SIGNAL(sslErrors(QList<QSslError>,bool*,QList<QSslError>*)),
|
||||
this, SLOT(replySslErrors(QList<QSslError>,bool*,QList<QSslError>*)),
|
||||
Qt::BlockingQueuedConnection);
|
||||
#endif
|
||||
// This signal we will use to start the request.
|
||||
connect(this, SIGNAL(startHttpRequest()), delegate, SLOT(startRequest()));
|
||||
connect(this, SIGNAL(abortHttpRequest()), delegate, SLOT(abortRequest()));
|
||||
|
@ -888,7 +877,6 @@ void QNetworkAccessHttpBackend::httpError(QNetworkReply::NetworkError errorCode,
|
|||
error(errorCode, errorString);
|
||||
}
|
||||
|
||||
#ifndef QT_NO_OPENSSL
|
||||
void QNetworkAccessHttpBackend::replySslErrors(
|
||||
const QList<QSslError> &list, bool *ignoreAll, QList<QSslError> *toBeIgnored)
|
||||
{
|
||||
|
@ -909,7 +897,6 @@ void QNetworkAccessHttpBackend::replySslConfigurationChanged(const QSslConfigura
|
|||
else if (!c.isNull())
|
||||
pendingSslConfiguration = new QSslConfiguration(c);
|
||||
}
|
||||
#endif
|
||||
|
||||
// Coming from QNonContiguousByteDeviceThreadForwardImpl in HTTP thread
|
||||
void QNetworkAccessHttpBackend::resetUploadDataSlot(bool *r)
|
||||
|
@ -1006,7 +993,6 @@ void QNetworkAccessHttpBackend::copyFinished(QIODevice *dev)
|
|||
finished();
|
||||
}
|
||||
|
||||
#ifndef QT_NO_OPENSSL
|
||||
void QNetworkAccessHttpBackend::ignoreSslErrors()
|
||||
{
|
||||
pendingIgnoreAllSslErrors = true;
|
||||
|
@ -1033,7 +1019,6 @@ void QNetworkAccessHttpBackend::setSslConfiguration(const QSslConfiguration &new
|
|||
// her/his QSslConfiguration on the QNetworkRequest.
|
||||
Q_UNUSED(newconfig);
|
||||
}
|
||||
#endif
|
||||
|
||||
QNetworkCacheMetaData QNetworkAccessHttpBackend::fetchCacheMetaData(const QNetworkCacheMetaData &oldMetaData) const
|
||||
{
|
||||
|
|
|
@ -88,13 +88,11 @@ public:
|
|||
virtual void emitReadBufferFreed(qint64 size);
|
||||
|
||||
virtual void copyFinished(QIODevice *);
|
||||
#ifndef QT_NO_OPENSSL
|
||||
virtual void ignoreSslErrors();
|
||||
virtual void ignoreSslErrors(const QList<QSslError> &errors);
|
||||
|
||||
virtual void fetchSslConfiguration(QSslConfiguration &configuration) const;
|
||||
virtual void setSslConfiguration(const QSslConfiguration &configuration);
|
||||
#endif
|
||||
QNetworkCacheMetaData fetchCacheMetaData(const QNetworkCacheMetaData &metaData) const;
|
||||
|
||||
// we return true since HTTP needs to send PUT/POST data again after having authenticated
|
||||
|
@ -121,10 +119,8 @@ private slots:
|
|||
void replyDownloadProgressSlot(qint64,qint64);
|
||||
void httpAuthenticationRequired(const QHttpNetworkRequest &request, QAuthenticator *auth);
|
||||
void httpError(QNetworkReply::NetworkError error, const QString &errorString);
|
||||
#ifndef QT_NO_OPENSSL
|
||||
void replySslErrors(const QList<QSslError> &, bool *, QList<QSslError> *);
|
||||
void replySslConfigurationChanged(const QSslConfiguration&);
|
||||
#endif
|
||||
|
||||
// From QNonContiguousByteDeviceThreadForwardImpl in HTTP thread:
|
||||
void resetUploadDataSlot(bool *r);
|
||||
|
@ -145,11 +141,9 @@ private:
|
|||
QByteDataBuffer pendingDownloadData;
|
||||
bool usingZerocopyDownloadBuffer;
|
||||
|
||||
#ifndef QT_NO_OPENSSL
|
||||
QSslConfiguration *pendingSslConfiguration;
|
||||
bool pendingIgnoreAllSslErrors;
|
||||
QList<QSslError> pendingIgnoreSslErrorsList;
|
||||
#endif
|
||||
|
||||
quint64 resumeOffset;
|
||||
|
||||
|
|
|
@ -1002,9 +1002,7 @@ QNetworkReply *QNetworkAccessManager::createRequest(QNetworkAccessManager::Opera
|
|||
priv->backend->reply = priv;
|
||||
}
|
||||
|
||||
#ifndef QT_NO_OPENSSL
|
||||
reply->setSslConfiguration(request.sslConfiguration());
|
||||
#endif
|
||||
|
||||
// fourth step: setup the reply
|
||||
priv->setup(op, request, outgoingData);
|
||||
|
@ -1032,14 +1030,10 @@ void QNetworkAccessManagerPrivate::_q_replyFinished()
|
|||
|
||||
void QNetworkAccessManagerPrivate::_q_replySslErrors(const QList<QSslError> &errors)
|
||||
{
|
||||
#ifndef QT_NO_OPENSSL
|
||||
Q_Q(QNetworkAccessManager);
|
||||
QNetworkReply *reply = qobject_cast<QNetworkReply *>(q->sender());
|
||||
if (reply)
|
||||
emit q->sslErrors(reply, errors);
|
||||
#else
|
||||
Q_UNUSED(errors);
|
||||
#endif
|
||||
}
|
||||
|
||||
QNetworkReply *QNetworkAccessManagerPrivate::postProcess(QNetworkReply *reply)
|
||||
|
@ -1047,11 +1041,7 @@ QNetworkReply *QNetworkAccessManagerPrivate::postProcess(QNetworkReply *reply)
|
|||
Q_Q(QNetworkAccessManager);
|
||||
QNetworkReplyPrivate::setManager(reply, q);
|
||||
q->connect(reply, SIGNAL(finished()), SLOT(_q_replyFinished()));
|
||||
#ifndef QT_NO_OPENSSL
|
||||
/* In case we're compiled without SSL support, we don't have this signal and we need to
|
||||
* avoid getting a connection error. */
|
||||
q->connect(reply, SIGNAL(sslErrors(QList<QSslError>)), SLOT(_q_replySslErrors(QList<QSslError>)));
|
||||
#endif
|
||||
#ifndef QT_NO_BEARERMANAGEMENT
|
||||
activeReplyCount++;
|
||||
#endif
|
||||
|
|
|
@ -140,9 +140,7 @@ Q_SIGNALS:
|
|||
#endif
|
||||
void authenticationRequired(QNetworkReply *reply, QAuthenticator *authenticator);
|
||||
void finished(QNetworkReply *reply);
|
||||
#ifndef QT_NO_OPENSSL
|
||||
void sslErrors(QNetworkReply *reply, const QList<QSslError> &errors);
|
||||
#endif
|
||||
|
||||
#if !defined(QT_NO_BEARERMANAGEMENT)
|
||||
void networkSessionConnected();
|
||||
|
|
|
@ -557,7 +557,6 @@ QVariant QNetworkReply::attribute(QNetworkRequest::Attribute code) const
|
|||
return d_func()->attributes.value(code);
|
||||
}
|
||||
|
||||
#ifndef QT_NO_OPENSSL
|
||||
/*!
|
||||
Returns the SSL configuration and state associated with this
|
||||
reply, if SSL was used. It will contain the remote server's
|
||||
|
@ -629,7 +628,6 @@ void QNetworkReply::ignoreSslErrors(const QList<QSslError> &errors)
|
|||
qt_metacall(QMetaObject::InvokeMetaMethod, id, arr);
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
/*!
|
||||
If this function is called, SSL errors related to network
|
||||
|
|
|
@ -133,11 +133,9 @@ public:
|
|||
// attributes
|
||||
QVariant attribute(QNetworkRequest::Attribute code) const;
|
||||
|
||||
#ifndef QT_NO_OPENSSL
|
||||
QSslConfiguration sslConfiguration() const;
|
||||
void setSslConfiguration(const QSslConfiguration &configuration);
|
||||
void ignoreSslErrors(const QList<QSslError> &errors);
|
||||
#endif
|
||||
|
||||
public Q_SLOTS:
|
||||
virtual void ignoreSslErrors();
|
||||
|
@ -146,9 +144,7 @@ Q_SIGNALS:
|
|||
void metaDataChanged();
|
||||
void finished();
|
||||
void error(QNetworkReply::NetworkError);
|
||||
#ifndef QT_NO_OPENSSL
|
||||
void sslErrors(const QList<QSslError> &errors);
|
||||
#endif
|
||||
|
||||
void uploadProgress(qint64 bytesSent, qint64 bytesTotal);
|
||||
void downloadProgress(qint64 bytesReceived, qint64 bytesTotal);
|
||||
|
|
|
@ -843,12 +843,8 @@ void QNetworkReplyImplPrivate::redirectionRequested(const QUrl &target)
|
|||
|
||||
void QNetworkReplyImplPrivate::sslErrors(const QList<QSslError> &errors)
|
||||
{
|
||||
#ifndef QT_NO_OPENSSL
|
||||
Q_Q(QNetworkReplyImpl);
|
||||
emit q->sslErrors(errors);
|
||||
#else
|
||||
Q_UNUSED(errors);
|
||||
#endif
|
||||
}
|
||||
|
||||
QNetworkReplyImpl::QNetworkReplyImpl(QObject *parent)
|
||||
|
@ -956,7 +952,6 @@ void QNetworkReplyImpl::setReadBufferSize(qint64 size)
|
|||
}
|
||||
}
|
||||
|
||||
#ifndef QT_NO_OPENSSL
|
||||
QSslConfiguration QNetworkReplyImpl::sslConfigurationImplementation() const
|
||||
{
|
||||
Q_D(const QNetworkReplyImpl);
|
||||
|
@ -986,7 +981,6 @@ void QNetworkReplyImpl::ignoreSslErrorsImplementation(const QList<QSslError> &er
|
|||
if (d->backend)
|
||||
d->backend->ignoreSslErrors(errors);
|
||||
}
|
||||
#endif // QT_NO_OPENSSL
|
||||
|
||||
/*!
|
||||
\internal
|
||||
|
|
|
@ -87,12 +87,10 @@ public:
|
|||
virtual qint64 readData(char *data, qint64 maxlen);
|
||||
virtual bool event(QEvent *);
|
||||
|
||||
#ifndef QT_NO_OPENSSL
|
||||
Q_INVOKABLE QSslConfiguration sslConfigurationImplementation() const;
|
||||
Q_INVOKABLE void setSslConfigurationImplementation(const QSslConfiguration &configuration);
|
||||
virtual void ignoreSslErrors();
|
||||
Q_INVOKABLE virtual void ignoreSslErrorsImplementation(const QList<QSslError> &errors);
|
||||
#endif
|
||||
|
||||
Q_DECLARE_PRIVATE(QNetworkReplyImpl)
|
||||
Q_PRIVATE_SLOT(d_func(), void _q_startOperation())
|
||||
|
|
|
@ -278,15 +278,11 @@ class QNetworkRequestPrivate: public QSharedData, public QNetworkHeadersPrivate
|
|||
public:
|
||||
inline QNetworkRequestPrivate()
|
||||
: priority(QNetworkRequest::NormalPriority)
|
||||
#ifndef QT_NO_OPENSSL
|
||||
, sslConfiguration(0)
|
||||
#endif
|
||||
{ qRegisterMetaType<QNetworkRequest>(); }
|
||||
~QNetworkRequestPrivate()
|
||||
{
|
||||
#ifndef QT_NO_OPENSSL
|
||||
delete sslConfiguration;
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
|
@ -296,11 +292,9 @@ public:
|
|||
url = other.url;
|
||||
priority = other.priority;
|
||||
|
||||
#ifndef QT_NO_OPENSSL
|
||||
sslConfiguration = 0;
|
||||
if (other.sslConfiguration)
|
||||
sslConfiguration = new QSslConfiguration(*other.sslConfiguration);
|
||||
#endif
|
||||
}
|
||||
|
||||
inline bool operator==(const QNetworkRequestPrivate &other) const
|
||||
|
@ -314,9 +308,7 @@ public:
|
|||
|
||||
QUrl url;
|
||||
QNetworkRequest::Priority priority;
|
||||
#ifndef QT_NO_OPENSSL
|
||||
mutable QSslConfiguration *sslConfiguration;
|
||||
#endif
|
||||
};
|
||||
|
||||
/*!
|
||||
|
@ -515,7 +507,6 @@ void QNetworkRequest::setAttribute(Attribute code, const QVariant &value)
|
|||
d->attributes.remove(code);
|
||||
}
|
||||
|
||||
#ifndef QT_NO_OPENSSL
|
||||
/*!
|
||||
Returns this network request's SSL configuration. By default, no
|
||||
SSL settings are specified.
|
||||
|
@ -548,7 +539,6 @@ void QNetworkRequest::setSslConfiguration(const QSslConfiguration &config)
|
|||
else
|
||||
*d->sslConfiguration = config;
|
||||
}
|
||||
#endif
|
||||
|
||||
/*!
|
||||
\since 4.6
|
||||
|
|
|
@ -132,10 +132,8 @@ public:
|
|||
QVariant attribute(Attribute code, const QVariant &defaultValue = QVariant()) const;
|
||||
void setAttribute(Attribute code, const QVariant &value);
|
||||
|
||||
#ifndef QT_NO_OPENSSL
|
||||
QSslConfiguration sslConfiguration() const;
|
||||
void setSslConfiguration(const QSslConfiguration &configuration);
|
||||
#endif
|
||||
|
||||
void setOriginatingObject(QObject *object);
|
||||
QObject *originatingObject() const;
|
||||
|
|
|
@ -380,12 +380,9 @@
|
|||
#include <qtimer.h>
|
||||
#include <qelapsedtimer.h>
|
||||
#include <qscopedvaluerollback.h>
|
||||
#include <qsslsocket.h>
|
||||
#include "qnetworkcommon_p.h"
|
||||
|
||||
#ifndef QT_NO_OPENSSL
|
||||
#include <QtNetwork/qsslsocket.h>
|
||||
#endif
|
||||
|
||||
#include <qthread_p.h>
|
||||
|
||||
#ifdef QABSTRACTSOCKET_DEBUG
|
||||
|
@ -1578,10 +1575,8 @@ bool QAbstractSocket::setSocketDescriptor(int socketDescriptor, SocketState sock
|
|||
OpenMode openMode)
|
||||
{
|
||||
Q_D(QAbstractSocket);
|
||||
#ifndef QT_NO_OPENSSL
|
||||
if (QSslSocket *socket = qobject_cast<QSslSocket *>(this))
|
||||
return socket->setSocketDescriptor(socketDescriptor, socketState, openMode);
|
||||
#endif
|
||||
|
||||
d->resetSocketLayer();
|
||||
d->socketEngine = QAbstractSocketEngine::createSocketEngine(socketDescriptor, this);
|
||||
|
@ -1630,12 +1625,10 @@ bool QAbstractSocket::setSocketDescriptor(int socketDescriptor, SocketState sock
|
|||
*/
|
||||
void QAbstractSocket::setSocketOption(QAbstractSocket::SocketOption option, const QVariant &value)
|
||||
{
|
||||
#ifndef QT_NO_OPENSSL
|
||||
if (QSslSocket *sslSocket = qobject_cast<QSslSocket*>(this)) {
|
||||
sslSocket->setSocketOption(option, value);
|
||||
return;
|
||||
}
|
||||
#endif
|
||||
|
||||
if (!d_func()->socketEngine)
|
||||
return;
|
||||
|
@ -1667,11 +1660,9 @@ void QAbstractSocket::setSocketOption(QAbstractSocket::SocketOption option, cons
|
|||
*/
|
||||
QVariant QAbstractSocket::socketOption(QAbstractSocket::SocketOption option)
|
||||
{
|
||||
#ifndef QT_NO_OPENSSL
|
||||
if (QSslSocket *sslSocket = qobject_cast<QSslSocket*>(this)) {
|
||||
return sslSocket->socketOption(option);
|
||||
}
|
||||
#endif
|
||||
|
||||
if (!d_func()->socketEngine)
|
||||
return QVariant();
|
||||
|
@ -1735,12 +1726,10 @@ bool QAbstractSocket::waitForConnected(int msecs)
|
|||
return true;
|
||||
}
|
||||
|
||||
#ifndef QT_NO_OPENSSL
|
||||
// Manual polymorphism; this function is not virtual, but has an overload
|
||||
// in QSslSocket.
|
||||
if (QSslSocket *socket = qobject_cast<QSslSocket *>(this))
|
||||
return socket->waitForConnected(msecs);
|
||||
#endif
|
||||
|
||||
bool wasPendingClose = d->pendingClose;
|
||||
d->pendingClose = false;
|
||||
|
@ -1961,12 +1950,10 @@ bool QAbstractSocket::waitForBytesWritten(int msecs)
|
|||
bool QAbstractSocket::waitForDisconnected(int msecs)
|
||||
{
|
||||
Q_D(QAbstractSocket);
|
||||
#ifndef QT_NO_OPENSSL
|
||||
// Manual polymorphism; this function is not virtual, but has an overload
|
||||
// in QSslSocket.
|
||||
if (QSslSocket *socket = qobject_cast<QSslSocket *>(this))
|
||||
return socket->waitForDisconnected(msecs);
|
||||
#endif
|
||||
|
||||
// require calling connectToHost() before waitForDisconnected()
|
||||
if (state() == UnconnectedState) {
|
||||
|
@ -2029,12 +2016,10 @@ void QAbstractSocket::abort()
|
|||
#endif
|
||||
if (d->state == UnconnectedState)
|
||||
return;
|
||||
#ifndef QT_NO_OPENSSL
|
||||
if (QSslSocket *socket = qobject_cast<QSslSocket *>(this)) {
|
||||
socket->abort();
|
||||
return;
|
||||
}
|
||||
#endif
|
||||
if (d->connectTimer) {
|
||||
d->connectTimer->stop();
|
||||
delete d->connectTimer;
|
||||
|
@ -2088,12 +2073,10 @@ bool QAbstractSocket::atEnd() const
|
|||
bool QAbstractSocket::flush()
|
||||
{
|
||||
Q_D(QAbstractSocket);
|
||||
#ifndef QT_NO_OPENSSL
|
||||
// Manual polymorphism; flush() isn't virtual, but QSslSocket overloads
|
||||
// it.
|
||||
if (QSslSocket *socket = qobject_cast<QSslSocket *>(this))
|
||||
return socket->flush();
|
||||
#endif
|
||||
Q_CHECK_SOCKETENGINE(false);
|
||||
return d->flush();
|
||||
}
|
||||
|
@ -2590,14 +2573,12 @@ void QAbstractSocket::setReadBufferSize(qint64 size)
|
|||
{
|
||||
Q_D(QAbstractSocket);
|
||||
|
||||
#ifndef QT_NO_OPENSSL
|
||||
// Manual polymorphism; setReadBufferSize() isn't virtual, but QSslSocket overloads
|
||||
// it.
|
||||
if (QSslSocket *socket = qobject_cast<QSslSocket *>(this)) {
|
||||
socket->setReadBufferSize(size);
|
||||
return;
|
||||
}
|
||||
#endif
|
||||
|
||||
if (d->readBufferMaxSize == size)
|
||||
return;
|
||||
|
|
|
@ -107,10 +107,6 @@
|
|||
\value StateOrProvinceName "ST" The state or province.
|
||||
*/
|
||||
|
||||
#include <QtCore/qglobal.h>
|
||||
|
||||
#ifndef QT_NO_OPENSSL
|
||||
|
||||
#include "qsslsocket_openssl_p.h"
|
||||
#include "qsslcertificate.h"
|
||||
#include "qsslcertificate_p.h"
|
||||
|
@ -985,7 +981,3 @@ QDebug operator<<(QDebug debug, QSslCertificate::SubjectInfo info)
|
|||
#endif
|
||||
|
||||
QT_END_NAMESPACE
|
||||
|
||||
#endif // QT_NO_OPENSSL
|
||||
|
||||
|
||||
|
|
|
@ -50,15 +50,10 @@
|
|||
#include <QtCore/qsharedpointer.h>
|
||||
#include <QtNetwork/qssl.h>
|
||||
|
||||
typedef struct x509_st X509; // ### check if this works
|
||||
|
||||
QT_BEGIN_HEADER
|
||||
|
||||
QT_BEGIN_NAMESPACE
|
||||
|
||||
|
||||
#ifndef QT_NO_OPENSSL
|
||||
|
||||
class QDateTime;
|
||||
class QIODevice;
|
||||
class QSslKey;
|
||||
|
@ -129,8 +124,6 @@ Q_NETWORK_EXPORT QDebug operator<<(QDebug debug, const QSslCertificate &certific
|
|||
Q_NETWORK_EXPORT QDebug operator<<(QDebug debug, QSslCertificate::SubjectInfo info);
|
||||
#endif
|
||||
|
||||
#endif // QT_NO_OPENSSL
|
||||
|
||||
QT_END_NAMESPACE
|
||||
|
||||
QT_END_HEADER
|
||||
|
|
|
@ -58,10 +58,6 @@
|
|||
\sa QSslSocket, QSslKey
|
||||
*/
|
||||
|
||||
#include <QtCore/qglobal.h>
|
||||
|
||||
#ifndef QT_NO_OPENSSL
|
||||
|
||||
#include "qsslcipher.h"
|
||||
#include "qsslcipher_p.h"
|
||||
#include "qsslsocket.h"
|
||||
|
@ -240,7 +236,3 @@ QDebug operator<<(QDebug debug, const QSslCipher &cipher)
|
|||
#endif
|
||||
|
||||
QT_END_NAMESPACE
|
||||
|
||||
#endif // QT_NO_OPENSSL
|
||||
|
||||
|
||||
|
|
|
@ -51,9 +51,6 @@ QT_BEGIN_HEADER
|
|||
|
||||
QT_BEGIN_NAMESPACE
|
||||
|
||||
|
||||
#ifndef QT_NO_OPENSSL
|
||||
|
||||
class QSslCipherPrivate;
|
||||
class Q_NETWORK_EXPORT QSslCipher
|
||||
{
|
||||
|
@ -87,8 +84,6 @@ class QDebug;
|
|||
Q_NETWORK_EXPORT QDebug operator<<(QDebug debug, const QSslCipher &cipher);
|
||||
#endif
|
||||
|
||||
#endif // QT_NO_OPENSSL
|
||||
|
||||
QT_END_NAMESPACE
|
||||
|
||||
QT_END_HEADER
|
||||
|
|
|
@ -39,10 +39,6 @@
|
|||
**
|
||||
****************************************************************************/
|
||||
|
||||
#include <QtCore/qglobal.h>
|
||||
|
||||
#ifndef QT_NO_OPENSSL
|
||||
|
||||
#include "qsslconfiguration.h"
|
||||
#include "qsslconfiguration_p.h"
|
||||
#include "qsslsocket.h"
|
||||
|
@ -576,7 +572,3 @@ void QSslConfiguration::setDefaultConfiguration(const QSslConfiguration &configu
|
|||
}
|
||||
|
||||
QT_END_NAMESPACE
|
||||
|
||||
#endif // QT_NO_OPENSSL
|
||||
|
||||
|
||||
|
|
|
@ -65,9 +65,6 @@ QT_BEGIN_HEADER
|
|||
|
||||
QT_BEGIN_NAMESPACE
|
||||
|
||||
|
||||
#ifndef QT_NO_OPENSSL
|
||||
|
||||
template<typename T> class QList;
|
||||
class QSslCertificate;
|
||||
class QSslCipher;
|
||||
|
@ -131,8 +128,6 @@ private:
|
|||
QSharedDataPointer<QSslConfigurationPrivate> d;
|
||||
};
|
||||
|
||||
#endif // QT_NO_OPENSSL
|
||||
|
||||
QT_END_NAMESPACE
|
||||
|
||||
QT_END_HEADER
|
||||
|
|
|
@ -91,10 +91,6 @@
|
|||
\sa QSslError::errorString()
|
||||
*/
|
||||
|
||||
#include <QtCore/qglobal.h>
|
||||
|
||||
#ifndef QT_NO_OPENSSL
|
||||
|
||||
#include "qsslerror.h"
|
||||
#include "qsslsocket.h"
|
||||
#ifndef QT_NO_DEBUG_STREAM
|
||||
|
@ -323,7 +319,3 @@ QDebug operator<<(QDebug debug, const QSslError::SslError &error)
|
|||
#endif
|
||||
|
||||
QT_END_NAMESPACE
|
||||
|
||||
#endif // QT_NO_OPENSSL
|
||||
|
||||
|
||||
|
|
|
@ -50,9 +50,6 @@ QT_BEGIN_HEADER
|
|||
|
||||
QT_BEGIN_NAMESPACE
|
||||
|
||||
|
||||
#ifndef QT_NO_OPENSSL
|
||||
|
||||
class QSslErrorPrivate;
|
||||
class Q_NETWORK_EXPORT QSslError
|
||||
{
|
||||
|
@ -114,8 +111,6 @@ Q_NETWORK_EXPORT QDebug operator<<(QDebug debug, const QSslError &error);
|
|||
Q_NETWORK_EXPORT QDebug operator<<(QDebug debug, const QSslError::SslError &error);
|
||||
#endif
|
||||
|
||||
#endif // QT_NO_OPENSSL
|
||||
|
||||
QT_END_NAMESPACE
|
||||
|
||||
QT_END_HEADER
|
||||
|
|
|
@ -55,10 +55,6 @@
|
|||
\sa QSslSocket, QSslCertificate, QSslCipher
|
||||
*/
|
||||
|
||||
#include <QtCore/qglobal.h>
|
||||
|
||||
#ifndef QT_NO_OPENSSL
|
||||
|
||||
#include "qsslsocket_openssl_p.h"
|
||||
#include "qsslkey.h"
|
||||
#include "qsslkey_p.h"
|
||||
|
@ -462,7 +458,3 @@ QDebug operator<<(QDebug debug, const QSslKey &key)
|
|||
#endif
|
||||
|
||||
QT_END_NAMESPACE
|
||||
|
||||
#endif // QT_NO_OPENSSL
|
||||
|
||||
|
||||
|
|
|
@ -52,9 +52,6 @@ QT_BEGIN_HEADER
|
|||
|
||||
QT_BEGIN_NAMESPACE
|
||||
|
||||
|
||||
#ifndef QT_NO_OPENSSL
|
||||
|
||||
template <typename A, typename B> struct QPair;
|
||||
|
||||
class QIODevice;
|
||||
|
@ -101,8 +98,6 @@ class QDebug;
|
|||
Q_NETWORK_EXPORT QDebug operator<<(QDebug debug, const QSslKey &key);
|
||||
#endif
|
||||
|
||||
#endif // QT_NO_OPENSSL
|
||||
|
||||
QT_END_NAMESPACE
|
||||
|
||||
QT_END_HEADER
|
||||
|
|
|
@ -292,10 +292,6 @@
|
|||
\sa peerVerifyError()
|
||||
*/
|
||||
|
||||
#include <QtCore/qglobal.h>
|
||||
|
||||
#ifndef QT_NO_OPENSSL
|
||||
|
||||
#include "qsslcipher.h"
|
||||
#include "qsslsocket.h"
|
||||
#include "qsslsocket_openssl_p.h"
|
||||
|
@ -2316,7 +2312,5 @@ QList<QByteArray> QSslSocketPrivate::unixRootCertDirectories()
|
|||
|
||||
QT_END_NAMESPACE
|
||||
|
||||
#endif // QT_NO_OPENSSL
|
||||
|
||||
#include "moc_qsslsocket.h"
|
||||
|
||||
|
|
|
@ -45,18 +45,13 @@
|
|||
|
||||
#include <QtCore/qlist.h>
|
||||
#include <QtCore/qregexp.h>
|
||||
#ifndef QT_NO_OPENSSL
|
||||
# include <QtNetwork/qtcpsocket.h>
|
||||
# include <QtNetwork/qsslerror.h>
|
||||
#endif
|
||||
#include <QtNetwork/qtcpsocket.h>
|
||||
#include <QtNetwork/qsslerror.h>
|
||||
|
||||
QT_BEGIN_HEADER
|
||||
|
||||
QT_BEGIN_NAMESPACE
|
||||
|
||||
|
||||
#ifndef QT_NO_OPENSSL
|
||||
|
||||
class QDir;
|
||||
class QSslCipher;
|
||||
class QSslCertificate;
|
||||
|
@ -213,13 +208,9 @@ private:
|
|||
friend class QSslSocketBackendPrivate;
|
||||
};
|
||||
|
||||
#endif // QT_NO_OPENSSL
|
||||
|
||||
QT_END_NAMESPACE
|
||||
|
||||
#ifndef QT_NO_OPENSSL
|
||||
Q_DECLARE_METATYPE(QList<QSslError>)
|
||||
#endif
|
||||
|
||||
QT_END_HEADER
|
||||
|
||||
|
|
|
@ -42,10 +42,6 @@
|
|||
//#define QSSLSOCKET_DEBUG
|
||||
//#define QT_DECRYPT_SSL_TRAFFIC
|
||||
|
||||
#include <QtCore/qglobal.h>
|
||||
|
||||
#ifndef QT_NO_OPENSSL
|
||||
|
||||
#include "qsslsocket_openssl_p.h"
|
||||
#include "qsslsocket.h"
|
||||
#include "qsslcertificate_p.h"
|
||||
|
@ -504,7 +500,6 @@ bool QSslSocketPrivate::supportsSsl()
|
|||
|
||||
bool QSslSocketPrivate::ensureLibraryLoaded()
|
||||
{
|
||||
#ifndef QT_NO_OPENSSL
|
||||
// Check if the library itself needs to be initialized.
|
||||
QMutexLocker locker(openssl_locks()->initLock());
|
||||
if (!s_libraryLoaded) {
|
||||
|
@ -529,12 +524,8 @@ bool QSslSocketPrivate::ensureLibraryLoaded()
|
|||
int attempts = 500;
|
||||
do {
|
||||
if (attempts < 500) {
|
||||
#ifdef Q_OS_UNIX
|
||||
struct timespec ts = {0, 33333333};
|
||||
nanosleep(&ts, 0);
|
||||
#else
|
||||
Sleep(3);
|
||||
#endif
|
||||
randomish.msec = attempts;
|
||||
}
|
||||
randomish.stack = (void *)&randomish;
|
||||
|
@ -547,9 +538,6 @@ bool QSslSocketPrivate::ensureLibraryLoaded()
|
|||
}
|
||||
}
|
||||
return true;
|
||||
#else
|
||||
return false;
|
||||
#endif // QT_NO_OPENSSL
|
||||
}
|
||||
|
||||
void QSslSocketPrivate::ensureCiphersAndCertsLoaded()
|
||||
|
@ -1242,7 +1230,3 @@ bool QSslSocketBackendPrivate::isMatchingHostname(const QString &cn, const QStri
|
|||
}
|
||||
|
||||
QT_END_NAMESPACE
|
||||
|
||||
#endif // QT_NO_OPENSSL
|
||||
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue