Add x22i algo support, based on ccminer-x22i code, cleaned

Personal note: imo a factor for 256 would have been useful

Signed-off-by: Tanguy Pruvot <tanguy.pruvot@gmail.com>
This commit is contained in:
Tanguy Pruvot 2018-10-02 22:45:09 +02:00
parent 6889836ac7
commit 8ad60658e4
14 changed files with 1562 additions and 3 deletions

2
.gitignore vendored
View file

@ -1,5 +1,7 @@
*.o *.o
*.a *.a
.deps
.dirstamp
stratum/stratum stratum/stratum
stratum/blocknotify stratum/blocknotify
blocknotify/blocknotify blocknotify/blocknotify

File diff suppressed because it is too large Load diff

View file

@ -0,0 +1,73 @@
///////////////////////////////////////////////////////////////////////////////////////////////
//
// SWIFFTX ANSI C OPTIMIZED 32BIT IMPLEMENTATION FOR NIST SHA-3 COMPETITION
//
// SWIFFTX.h
//
// October 2008
//
// This file is the exact copy from the reference implementation.
//
///////////////////////////////////////////////////////////////////////////////////////////////
#ifndef __SWIFFTX__
#define __SWIFFTX__
#ifdef __cplusplus
extern "C"{
#endif
// See the remarks concerning compatibility issues inside stdint.h.
#include "stdint.h"
#include "stdbool.h"
// The size of SWIFFTX input in bytes.
#define SWIFFTX_INPUT_BLOCK_SIZE 256
// The size of output block in bytes. The compression function of SWIFFT outputs a block of
// this size (i.e., this is the size of the resulting hash value).
#define SWIFFTX_OUTPUT_BLOCK_SIZE 65
// Computes the result of a single SWIFFT operation.
// This is the simple implementation, where our main concern is to show our design principles.
// It is made more efficient in the optimized version, by using FFT instead of DFT, and
// through other speed-up techniques.
//
// Parameters:
// - input: the input string. Consists of 8*m input bytes, where each octet passes the DFT
// processing.
// - m: the length of the input in bytes.
// - output: the resulting hash value of SWIFFT, of size 65 bytes (520 bit). This is the
// result of summing the dot products of the DFTS with the A's after applying the base
// change transformation
// - A: the A's coefficients to work with (since every SWIFFT in SWIFFTX uses different As).
// A single application of SWIFFT uses 64*m A's.
void ComputeSingleSWIFFT(unsigned char *input, unsigned short m,
unsigned char output[SWIFFTX_OUTPUT_BLOCK_SIZE],
const swift_int16_t *a);
// Computes the result of a single SWIFFTX operation.
// NOTE: for simplicity we use 'ComputeSingleSWIFFT()' as a subroutine. This is only to show
// the design idea. In the optimized versions we don't do this for efficiency concerns, since
// there we compute the first part (which doesn't involve the A coefficients) only once for all
// of the 3 invocations of SWIFFT. This enables us to introduce a significant speedup.
//
// Parameters:
// - input: the input input of 256 bytes (2048 bit).
// - output: the resulting hash value of SWIFFT, of size 64 bytes (512 bit).
// - doSMooth: if true, a final smoothing stage is performed and the output is of size 512 bits.
//
// Returns:
// - Success value.
void ComputeSingleSWIFFTX(unsigned char input[SWIFFTX_INPUT_BLOCK_SIZE],
unsigned char output[SWIFFTX_OUTPUT_BLOCK_SIZE],
bool doSmooth);
// Calculates the powers of OMEGA and generates the bit reversal permutation.
// You must call this function before doing SWIFFT/X, otherwise you will get zeroes everywhere.
void InitializeSWIFFTX();
#ifdef __cplusplus
}
#endif
#endif // __SWIFFTX__

View file

@ -0,0 +1,39 @@
/*
inttypes.h
Contributors:
Created by Marek Michalkiewicz <marekm@linux.org.pl>
THIS SOFTWARE IS NOT COPYRIGHTED
This source code is offered for use in the public domain. You may
use, modify or distribute it freely.
This code is distributed in the hope that it will be useful, but
WITHOUT ANY WARRANTY. ALL WARRANTIES, EXPRESS OR IMPLIED ARE HEREBY
DISCLAIMED. This includes but is not limited to warranties of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
*/
#ifndef __INTTYPES_H_
#define __INTTYPES_H_
/* Use [u]intN_t if you need exactly N bits.
XXX - doesn't handle the -mint8 option. */
typedef signed char swift_int8_t;
typedef unsigned char swift_uint8_t;
typedef int swift_int16_t;
typedef unsigned int swift_uint16_t;
typedef long swift_int32_t;
typedef unsigned long swift_uint32_t;
typedef long long swift_int64_t;
typedef unsigned long long swift_uint64_t;
//typedef swift_int16_t intptr_t;
//typedef swift_uint16_t uintptr_t;
#endif

View file

@ -0,0 +1,46 @@
/*
* Copyright (c) 2000 Jeroen Ruigrok van der Werven <asmodai@FreeBSD.org>
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR 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 AUTHOR 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.
*
* $FreeBSD: src/include/stdbool.h,v 1.6 2002/08/16 07:33:14 alfred Exp $
*/
#ifndef _STDBOOL_H_
#define _STDBOOL_H_
#define __bool_true_false_are_defined 1
#ifndef __cplusplus
#define false 0
#define true 1
#define bool _Bool
#if __STDC_VERSION__ < 199901L && __GNUC__ < 3
typedef int _Bool;
#endif
#endif /* !__cplusplus */
#endif /* !_STDBOOL_H_ */

View file

@ -0,0 +1,54 @@
#ifndef _SWIFFT_STDINT_H
#define _SWIFFT_STDINT_H
///////////////////////////////////////////////////////////////////////////////////////////////
//
// A note from SWIFFTX implementers:
//
// Although the submission was targeted for Microsoft Visual Studio 2005 compiler, we strived
// to make the code as portable as possible. This is why we preferred to use the types defined
// here, instead of Microsoft-specific types. We compiled the code with gcc to make this sure.
// However, we couldn't use this header as is, due to VS2005 compiler objections. This is why
// we commented out certain defines and clearly marked it.
// To compile our code on gcc you may define SYS_STDINT.
//
///////////////////////////////////////////////////////////////////////////////////////////////
#ifdef SYS_STDINT
#include <stdint.h>
#else
#include "inttypes.h"
// The following was commented out by SWIFFTX implementers:
// __BEGIN_DECLS
typedef swift_int8_t swifftx_int_least8_t;
typedef swift_int16_t swifftx_int_least16_t;
typedef swift_int32_t swifftx_int_least32_t;
typedef swift_uint8_t swifftx_uint_least8_t;
typedef swift_uint16_t swifftx_uint_least16_t;
typedef swift_uint32_t swifftx_uint_least32_t;
#ifndef __STRICT_ANSI__
typedef swift_int64_t swifftx_int_least64_t;
typedef swift_uint64_t swifftx_uint_least64_t;
#endif
/*typedef signed char int_fast8_t;
typedef signed long int int_fast16_t;
typedef signed long int int_fast32_t;
typedef signed long long int int_fast64_t;
typedef unsigned char uint_fast8_t;
typedef unsigned long int uint_fast16_t;
typedef unsigned long int uint_fast32_t;
typedef unsigned long long int uint_fast64_t;*/
// The following was commented out by SWIFFTX implementers:
// #include <endian.h>
// __END_DECLS
#endif
#endif

View file

@ -10,6 +10,7 @@ LDFLAGS=-O2 -lgmp
SOURCES=lyra2re.c lyra2v2.c Lyra2.c lyra2z.c Lyra2-z.c Sponge.c allium.c \ SOURCES=lyra2re.c lyra2v2.c Lyra2.c lyra2z.c Lyra2-z.c Sponge.c allium.c \
c11.c x11.c x12.c x13.c hsr14.c sm3.c x14.c x15.c x17.c \ c11.c x11.c x12.c x13.c hsr14.c sm3.c x14.c x15.c x17.c \
x22i.c SWIFFTX/SWIFFTX.c \
blake.c blakecoin.c blake2s.c jha.c keccak.c lbry.c tribus.c \ blake.c blakecoin.c blake2s.c jha.c keccak.c lbry.c tribus.c \
deep.c fresh.c groestl.c neoscrypt.c nist5.c quark.c qubit.c skein.c skein2.c \ deep.c fresh.c groestl.c neoscrypt.c nist5.c quark.c qubit.c skein.c skein2.c \
bitcore.c timetravel.c x11evo.c x16r.c x16s.c xevan.c bastion.c hmq17.c sonoa.c \ bitcore.c timetravel.c x11evo.c x16r.c x16s.c xevan.c bastion.c hmq17.c sonoa.c \
@ -42,3 +43,4 @@ clean:
rm -f *.o rm -f *.o
rm -f ar2/*.o rm -f ar2/*.o
rm -f blake2/*.o rm -f blake2/*.o
rm -f SWIFFTX/*.o

146
stratum/algos/x22i.c Normal file
View file

@ -0,0 +1,146 @@
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sha3/sph_blake.h>
#include <sha3/sph_bmw.h>
#include <sha3/sph_groestl.h>
#include <sha3/sph_jh.h>
#include <sha3/sph_keccak.h>
#include <sha3/sph_skein.h>
#include <sha3/sph_luffa.h>
#include <sha3/sph_cubehash.h>
#include <sha3/sph_shavite.h>
#include <sha3/sph_simd.h>
#include <sha3/sph_echo.h>
#include <sha3/sph_hamsi.h>
#include <sha3/sph_fugue.h>
#include <sha3/sph_shabal.h>
#include <sha3/sph_whirlpool.h>
#include <sha3/sph_sha2.h>
#include <sha3/sph_haval.h>
#include <sha3/sph_tiger.h>
#include "SWIFFTX/SWIFFTX.h"
#include "gost.h"
#include "Lyra2.h"
#include "common.h"
void x22i_hash(const char* input, char* output, uint32_t len)
{
sph_blake512_context ctx_blake;
sph_bmw512_context ctx_bmw;
sph_groestl512_context ctx_groestl;
sph_skein512_context ctx_skein;
sph_jh512_context ctx_jh;
sph_keccak512_context ctx_keccak;
sph_luffa512_context ctx_luffa;
sph_cubehash512_context ctx_cubehash;
sph_shavite512_context ctx_shavite;
sph_simd512_context ctx_simd;
sph_echo512_context ctx_echo;
sph_hamsi512_context ctx_hamsi;
sph_fugue512_context ctx_fugue;
sph_shabal512_context ctx_shabal;
sph_whirlpool_context ctx_whirlpool;
sph_sha512_context ctx_sha512;
sph_haval256_5_context ctx_haval;
sph_tiger_context ctx_tiger;
sph_gost512_context ctx_gost;
sph_sha256_context ctx_sha;
unsigned char _ALIGN(128) hash[64 * 4] = {0};
unsigned char _ALIGN(128) hash2[64];
sph_blake512_init(&ctx_blake);
sph_blake512(&ctx_blake, input, len);
sph_blake512_close (&ctx_blake, hash);
sph_bmw512_init(&ctx_bmw);
sph_bmw512(&ctx_bmw, hash, 64);
sph_bmw512_close(&ctx_bmw, hash);
sph_groestl512_init(&ctx_groestl);
sph_groestl512(&ctx_groestl, hash, 64);
sph_groestl512_close(&ctx_groestl, hash);
sph_skein512_init(&ctx_skein);
sph_skein512(&ctx_skein, hash, 64);
sph_skein512_close(&ctx_skein, hash);
sph_jh512_init(&ctx_jh);
sph_jh512(&ctx_jh, hash, 64);
sph_jh512_close(&ctx_jh, hash);
sph_keccak512_init(&ctx_keccak);
sph_keccak512(&ctx_keccak, hash, 64);
sph_keccak512_close(&ctx_keccak, hash);
sph_luffa512_init(&ctx_luffa);
sph_luffa512(&ctx_luffa, hash, 64);
sph_luffa512_close (&ctx_luffa, hash);
sph_cubehash512_init(&ctx_cubehash);
sph_cubehash512(&ctx_cubehash, hash, 64);
sph_cubehash512_close(&ctx_cubehash, hash);
sph_shavite512_init(&ctx_shavite);
sph_shavite512(&ctx_shavite, hash, 64);
sph_shavite512_close(&ctx_shavite, hash);
sph_simd512_init(&ctx_simd);
sph_simd512(&ctx_simd, hash, 64);
sph_simd512_close(&ctx_simd, hash);
sph_echo512_init(&ctx_echo);
sph_echo512(&ctx_echo, hash, 64);
sph_echo512_close(&ctx_echo, hash);
sph_hamsi512_init(&ctx_hamsi);
sph_hamsi512(&ctx_hamsi, hash, 64);
sph_hamsi512_close(&ctx_hamsi, hash);
sph_fugue512_init(&ctx_fugue);
sph_fugue512(&ctx_fugue, hash, 64);
sph_fugue512_close(&ctx_fugue, hash);
sph_shabal512_init(&ctx_shabal);
sph_shabal512(&ctx_shabal, (const void*) hash, 64);
sph_shabal512_close(&ctx_shabal, &hash[64]);
sph_whirlpool_init(&ctx_whirlpool);
sph_whirlpool (&ctx_whirlpool, (const void*) &hash[64], 64);
sph_whirlpool_close(&ctx_whirlpool, &hash[128]);
sph_sha512_init(&ctx_sha512);
sph_sha512(&ctx_sha512,(const void*) &hash[128], 64);
sph_sha512_close(&ctx_sha512,(void*) &hash[192]);
InitializeSWIFFTX();
ComputeSingleSWIFFTX((unsigned char*)hash, (unsigned char*)hash2, false);
memset(hash, 0, 64);
sph_haval256_5_init(&ctx_haval);
sph_haval256_5(&ctx_haval,(const void*) hash2, 64);
sph_haval256_5_close(&ctx_haval,hash);
memset(hash2, 0, 64);
sph_tiger_init(&ctx_tiger);
sph_tiger (&ctx_tiger, (const void*) hash, 64);
sph_tiger_close(&ctx_tiger, (void*) hash2);
memset(hash, 0, 64);
LYRA2((void*) hash, 32, (const void*) hash2, 32, (const void*) hash2, 32, 1, 4, 4);
sph_gost512_init(&ctx_gost);
sph_gost512 (&ctx_gost, (const void*) hash, 64);
sph_gost512_close(&ctx_gost, (void*) hash);
sph_sha256_init(&ctx_sha);
sph_sha256 (&ctx_sha, (const void*) hash, 64);
sph_sha256_close(&ctx_sha, (void*) hash);
memcpy(output, hash, 32);
}

16
stratum/algos/x22i.h Normal file
View file

@ -0,0 +1,16 @@
#ifndef X22I_H
#define X22I_H
#ifdef __cplusplus
extern "C" {
#endif
#include <stdint.h>
void x22i_hash(const char* input, char* output, uint32_t len);
#ifdef __cplusplus
}
#endif
#endif

View file

@ -299,7 +299,10 @@ void coinbase_create(YAAMP_COIND *coind, YAAMP_JOB_TEMPLATE *templ, json_value *
base58_decode(charity_payee, script_payee); base58_decode(charity_payee, script_payee);
json_int_t charity_amount = (available * coind->charity_percent) / 100; json_int_t charity_amount = json_get_int(json_result, "payee_amount");
if (charity_amount <= 0)
charity_amount = (available * coind->charity_percent) / 100;
available -= charity_amount; available -= charity_amount;
coind->charity_amount = charity_amount; coind->charity_amount = charity_amount;
@ -314,6 +317,8 @@ void coinbase_create(YAAMP_COIND *coind, YAAMP_JOB_TEMPLATE *templ, json_value *
strcat(templ->coinb2, "00000000"); // locktime strcat(templ->coinb2, "00000000"); // locktime
coind->reward = (double)available/100000000*coind->reward_mul; coind->reward = (double)available/100000000*coind->reward_mul;
//debuglog("INFO %s block available %f, charity %f miner %f\n", coind->symbol,
// (double) available/1e8, (double) charity_amount/1e8, coind->reward);
return; return;
} }

View file

@ -0,0 +1,16 @@
[TCP]
server = yaamp.com
port = 3223
password = tu8tu5
[SQL]
host = yaampdb
database = yaamp
username = root
password = patofpaq
[STRATUM]
algo = x22i
difficulty = 0.008
max_ttf = 50000

View file

@ -120,6 +120,7 @@ YAAMP_ALGO g_algos[] =
{"x14", x14_hash, 1, 0, 0}, {"x14", x14_hash, 1, 0, 0},
{"x15", x15_hash, 1, 0, 0}, {"x15", x15_hash, 1, 0, 0},
{"x17", x17_hash, 1, 0, 0}, {"x17", x17_hash, 1, 0, 0},
{"x22i", x22i_hash, 1, 0, 0},
{"x11evo", x11evo_hash, 1, 0, 0}, {"x11evo", x11evo_hash, 1, 0, 0},
{"xevan", xevan_hash, 0x100, 0, 0}, {"xevan", xevan_hash, 0x100, 0, 0},

View file

@ -156,6 +156,7 @@ void sha256_double_hash_hex(const char *input, char *output, unsigned int len);
#include "algos/x16r.h" #include "algos/x16r.h"
#include "algos/x16s.h" #include "algos/x16s.h"
#include "algos/x17.h" #include "algos/x17.h"
#include "algos/x22i.h"
#include "algos/xevan.h" #include "algos/xevan.h"
#include "algos/hmq17.h" #include "algos/hmq17.h"
#include "algos/nist5.h" #include "algos/nist5.h"

View file

@ -48,6 +48,7 @@ function yaamp_get_algos()
'x16r', 'x16r',
'x16s', 'x16s',
'x17', 'x17',
'x22i',
'xevan', 'xevan',
'groestl', // dmd-gr -m 256 (deprecated) 'groestl', // dmd-gr -m 256 (deprecated)
'dmd-gr', 'dmd-gr',
@ -155,7 +156,8 @@ function getAlgoColors($algo)
'x16r' => '#f0b080', 'x16r' => '#f0b080',
'x16s' => '#f0b080', 'x16s' => '#f0b080',
'x17' => '#f0b0a0', 'x17' => '#f0b0a0',
'xevan' => '#f0b0a0', 'x22i' => '#f0a090',
'xevan' => '#f0b0a0',
'allium' => '#80a0d0', 'allium' => '#80a0d0',
'argon2' => '#e0d0e0', 'argon2' => '#e0d0e0',
'argon2d-dyn' => '#e0d0e0', 'argon2d-dyn' => '#e0d0e0',
@ -233,7 +235,8 @@ function getAlgoPort($algo)
'x16r' => 3636, 'x16r' => 3636,
'x16s' => 3663, 'x16s' => 3663,
'x17' => 3737, 'x17' => 3737,
'aergo' => 3691, 'x22i' => 3223,
'aergo' => 3691,
'xevan' => 3739, 'xevan' => 3739,
'hmq1725' => 3747, 'hmq1725' => 3747,
'nist5' => 3833, 'nist5' => 3833,