Skip to content
Snippets Groups Projects
Commit 4e9ef78a authored by Constantin Papizh's avatar Constantin Papizh
Browse files

Qt-based project build fixed

parent c782f907
No related branches found
No related tags found
1 merge request!42Qt-based project build fixed
......@@ -31,6 +31,7 @@ HEADERS += $$PWD/include/dap_enc.h \
$$PWD/include/dap_enc_dilithium.h \
$$PWD/include/dap_enc_ringct20.h \
$$PWD/include/dap_enc_salsa2012.h \
$$PWD/include/dap_enc_SEED.h \
$$PWD/include/dap_crypto_common.h \
$$PWD/include/dap_cert.h \
$$PWD/include/dap_cert_file.h \
......@@ -67,6 +68,7 @@ SOURCES += $$PWD/src/dap_enc.c \
$$PWD/src/dap_hash.c \
$$PWD/src/dap_hash_fusion.c \
$$PWD/src/dap_hash_keccak.c \
$$PWD/src/dap_enc_SEED.c \
$$PWD/src/XKCP/lib/high/Keccak/FIPS202/SimpleFIPS202.c \
$$PWD/src/XKCP/lib/high/Keccak/SP800-185/SP800-185.c \
$$PWD/src/XKCP/lib/high/Keccak/SP800-185/SP800-185.inc
......
#include "blowfish.h"
#include "bf_local.h"
#include "memory.h"
/*
* Blowfish as implemented from 'Blowfish: Springer-Verlag paper' (From
* LECTURE NOTES IN COMPUTER SCIENCE 809, FAST SOFTWARE ENCRYPTION, CAMBRIDGE
* SECURITY WORKSHOP, CAMBRIDGE, U.K., DECEMBER 9-11, 1993)
*/
#if (BF_ROUNDS != 16) && (BF_ROUNDS != 20)
# error If you set BF_ROUNDS to some value other than 16 or 20, you will have \
to modify the code.
#endif
//#include<stdio.h>
void BF_encrypt(BF_LONG *data, const BF_KEY *key)
{
register BF_LONG l, r;
register const BF_LONG *p, *s;
p = key->P;
s = &(key->S[0]);
l = data[0];
r = data[1];
l ^= p[0];
BF_ENC(r, l, s, p[1]);
BF_ENC(l, r, s, p[2]);
BF_ENC(r, l, s, p[3]);
BF_ENC(l, r, s, p[4]);
BF_ENC(r, l, s, p[5]);
BF_ENC(l, r, s, p[6]);
BF_ENC(r, l, s, p[7]);
BF_ENC(l, r, s, p[8]);
BF_ENC(r, l, s, p[9]);
BF_ENC(l, r, s, p[10]);
BF_ENC(r, l, s, p[11]);
BF_ENC(l, r, s, p[12]);
BF_ENC(r, l, s, p[13]);
BF_ENC(l, r, s, p[14]);
BF_ENC(r, l, s, p[15]);
BF_ENC(l, r, s, p[16]);
# if BF_ROUNDS == 20
BF_ENC(r, l, s, p[17]);
BF_ENC(l, r, s, p[18]);
BF_ENC(r, l, s, p[19]);
BF_ENC(l, r, s, p[20]);
# endif
r ^= p[BF_ROUNDS + 1];
data[1] = l & 0xffffffffU;
data[0] = r & 0xffffffffU;
}
void BF_decrypt(BF_LONG *data, const BF_KEY *key)
{
register BF_LONG l, r;
register const BF_LONG *p, *s;
p = key->P;
s = &(key->S[0]);
l = data[0];
r = data[1];
l ^= p[BF_ROUNDS + 1];
# if BF_ROUNDS == 20
BF_ENC(r, l, s, p[20]);
BF_ENC(l, r, s, p[19]);
BF_ENC(r, l, s, p[18]);
BF_ENC(l, r, s, p[17]);
# endif
BF_ENC(r, l, s, p[16]);
BF_ENC(l, r, s, p[15]);
BF_ENC(r, l, s, p[14]);
BF_ENC(l, r, s, p[13]);
BF_ENC(r, l, s, p[12]);
BF_ENC(l, r, s, p[11]);
BF_ENC(r, l, s, p[10]);
BF_ENC(l, r, s, p[9]);
BF_ENC(r, l, s, p[8]);
BF_ENC(l, r, s, p[7]);
BF_ENC(r, l, s, p[6]);
BF_ENC(l, r, s, p[5]);
BF_ENC(r, l, s, p[4]);
BF_ENC(l, r, s, p[3]);
BF_ENC(r, l, s, p[2]);
BF_ENC(l, r, s, p[1]);
r ^= p[0];
data[1] = l & 0xffffffffU;
data[0] = r & 0xffffffffU;
}
void BF_cbc_encrypt(const unsigned char *in, unsigned char *out, long length,
const BF_KEY *schedule, unsigned char *ivec, int encrypt)
{
register BF_LONG tin0, tin1;
register BF_LONG tout0, tout1, xor0, xor1;
register long l = length;
BF_LONG tin[2];
if (encrypt) {
n2l(ivec, tout0);
n2l(ivec, tout1);
ivec -= 8;
for (l -= 8; l >= 0; l -= 8) {
n2l(in, tin0);
n2l(in, tin1);
tin0 ^= tout0;
tin1 ^= tout1;
tin[0] = tin0;
tin[1] = tin1;
BF_encrypt(tin, schedule);
tout0 = tin[0];
tout1 = tin[1];
l2n(tout0, out);
l2n(tout1, out);
}
if (1||l != -8) {
unsigned char tmpin[16];
unsigned char *ptmpin = tmpin;
memcpy(tmpin, in, l + 8);
memcpy(tmpin + l + 8, &length, 4);
int pad_length = (8-(l + 8 + 4 + 1)%8)%8;
for(int i = 0; i < pad_length; ++i)
{
tmpin[l+8+4+i]=16;//prng better
}
tmpin[l+8+4+pad_length]=pad_length;
// for(int i = 0; i < l + 8 + 4 +1 +pad_length; ++i)
// {
// printf("%.2x ", tmpin[i]);
// }
// printf("\n");fflush(stdout);
n2l(ptmpin, tin0);
n2l(ptmpin, tin1);
tin0 ^= tout0;
tin1 ^= tout1;
tin[0] = tin0;
tin[1] = tin1;
BF_encrypt(tin, schedule);
tout0 = tin[0];
tout1 = tin[1];
l2n(tout0, out);
l2n(tout1, out);
if(l+8+4+pad_length + 1 == 16)
{
n2l(ptmpin, tin0);
n2l(ptmpin, tin1);
tin0 ^= tout0;
tin1 ^= tout1;
tin[0] = tin0;
tin[1] = tin1;
BF_encrypt(tin, schedule);
tout0 = tin[0];
tout1 = tin[1];
l2n(tout0, out);
l2n(tout1, out);
}
// n2ln(in, tin0, tin1, l + 8);
// tin0 ^= tout0;
// tin1 ^= tout1;
// tin[0] = tin0;
// tin[1] = tin1;
// BF_encrypt(tin, schedule);
// tout0 = tin[0];
// tout1 = tin[1];
// l2n(tout0, out);
// l2n(tout1, out);
}
l2n(tout0, ivec);
l2n(tout1, ivec);
} else {
n2l(ivec, xor0);
n2l(ivec, xor1);
ivec -= 8;
for (l -= 8; l >= 0; l -= 8) {
n2l(in, tin0);
n2l(in, tin1);
tin[0] = tin0;
tin[1] = tin1;
BF_decrypt(tin, schedule);
tout0 = tin[0] ^ xor0;
tout1 = tin[1] ^ xor1;
l2n(tout0, out);
l2n(tout1, out);
xor0 = tin0;
xor1 = tin1;
}
if (l != -8) {
n2l(in, tin0);
n2l(in, tin1);
tin[0] = tin0;
tin[1] = tin1;
BF_decrypt(tin, schedule);
tout0 = tin[0] ^ xor0;
tout1 = tin[1] ^ xor1;
l2nn(tout0, tout1, out, l + 8);
xor0 = tin0;
xor1 = tin1;
}
l2n(xor0, ivec);
l2n(xor1, ivec);
}
tin0 = tin1 = tout0 = tout1 = xor0 = xor1 = 0;
tin[0] = tin[1] = 0;
}
#include "blowfish.h"
#include "bf_local.h"
/*
* The input and output encrypted as though 64bit ofb mode is being used.
* The extra state information to record how much of the 64bit block we have
* used is contained in *num;
*/
void BF_ofb64_encrypt(const unsigned char *in, unsigned char *out,
long length, const BF_KEY *schedule,
unsigned char *ivec, int *num)
{
register BF_LONG v0, v1, t;
register int n = *num;
register long l = length;
unsigned char d[8];
register char *dp;
BF_LONG ti[2];
unsigned char *iv;
int save = 0;
iv = (unsigned char *)ivec;
n2l(iv, v0);
n2l(iv, v1);
ti[0] = v0;
ti[1] = v1;
dp = (char *)d;
l2n(v0, dp);
l2n(v1, dp);
while (l--) {
if (n == 0) {
BF_encrypt((BF_LONG *)ti, schedule);
dp = (char *)d;
t = ti[0];
l2n(t, dp);
t = ti[1];
l2n(t, dp);
save++;
}
*(out++) = *(in++) ^ d[n];
n = (n + 1) & 0x07;
}
if (save) {
v0 = ti[0];
v1 = ti[1];
iv = (unsigned char *)ivec;
l2n(v0, iv);
l2n(v1, iv);
}
t = v0 = v1 = ti[0] = ti[1] = 0;
*num = n;
}
#include <stdio.h>
#include <string.h>
#include "blowfish.h"
#include "bf_local.h"
#include "bf_pi.h"
void BF_set_key(BF_KEY *key, int len, const unsigned char *data)
{
int i;
BF_LONG *p, ri, in[2];
const unsigned char *d, *end;
memcpy(key, &bf_init, sizeof(BF_KEY));
p = key->P;
if (len > ((BF_ROUNDS + 2) * 4))
len = (BF_ROUNDS + 2) * 4;
d = data;
end = &(data[len]);
for (i = 0; i < (BF_ROUNDS + 2); i++) {
ri = *(d++);
if (d >= end)
d = data;
ri <<= 8;
ri |= *(d++);
if (d >= end)
d = data;
ri <<= 8;
ri |= *(d++);
if (d >= end)
d = data;
ri <<= 8;
ri |= *(d++);
if (d >= end)
d = data;
p[i] ^= ri;
}
in[0] = 0L;
in[1] = 0L;
for (i = 0; i < (BF_ROUNDS + 2); i += 2) {
BF_encrypt(in, key);
p[i] = in[0];
p[i + 1] = in[1];
}
p = key->S;
for (i = 0; i < 4 * 256; i += 2) {
BF_encrypt(in, key);
p[i] = in[0];
p[i + 1] = in[1];
}
}
//max using key size = (BF_ROUNDS + 2)*4 bytes = 72 bytes
#ifndef BLOWFISH_H
# define BLOWFISH_H
#define BLOWFISH_H
#include "inttypes.h"
# define BF_BLOCK 8
# define BF_ENCRYPT 1
......@@ -23,11 +24,10 @@ typedef struct bf_key_st {
BF_LONG S[4 * 256];
} BF_KEY;
# ifdef __cplusplus
extern "C" {
# endif
# define BF_BLOCK 8
void BF_set_key(BF_KEY *key, int len,
const unsigned char *data);
......@@ -54,5 +54,5 @@ const char *BF_options(void);
# ifdef __cplusplus
}
# endif
# endif
#endif
INCLUDEPATH += $$PWD
HEADERS += $$PWD/blowfish.h \
$$PWD/bf_local.h \
$$PWD/bf_pi.h
$$PWD/bf_local.h
SOURCES += $$PWD/bf_cfb64.c \
$$PWD/bf_ecb.c \
$$PWD/bf_enc.c \
$$PWD/bf_ofb64.c \
$$PWD/bf_skey.c
SOURCES += $$PWD/blowfish.c
......@@ -5,13 +5,11 @@ HEADERS += $$PWD/ntt.h \
$$PWD/poly.h \
$$PWD/reduce.h \
$$PWD/ring.h \
$$PWD/ringct20_params.h \
$$PWD/verify.inc
$$PWD/ringct20_params.h
SOURCES += $$PWD/ntt.c \
$$PWD/poly.c \
$$PWD/precomp.c \
$$PWD/reduce.c \
$$PWD/ring.c \
$$PWD/ringct20_params.c \
$$PWD/verify.c
$$PWD/ringct20_params.c
......@@ -2,7 +2,6 @@ HEADERS += $$PWD/tesla_params.h
SOURCES += $$PWD/consts.c \
$$PWD/poly.c \
$$PWD/sample.c \
$$PWD/sign.c \
$$PWD/tesla_params.c
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment