OhGodAPet

Untitled

Jan 24th, 2018
507
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 9.09 KB | None | 0 0
  1. diff --git a/algo/x16r.c b/algo/x16r.c
  2. index f6f3608..7485155 100644
  3. --- a/algo/x16r.c
  4. +++ b/algo/x16r.c
  5. @@ -47,141 +47,174 @@ enum Algo {
  6. };
  7.  
  8. static __thread uint32_t s_ntime = UINT32_MAX;
  9. -static __thread char hashOrder[HASH_FUNC_COUNT + 1] = { 0 };
  10. +static __thread uint8_t hashOrder[HASH_FUNC_COUNT + 1] = { 0 };
  11.  
  12. -static void getAlgoString(const uint8_t* prevblock, char *output)
  13. +static void getAlgoString(const uint8_t* prevblock, uint8_t *output)
  14. {
  15. - char *sptr = output;
  16. for (int j = 0; j < HASH_FUNC_COUNT; j++) {
  17. - uint8_t b = (15 - j) >> 1; // 16 first ascii hex chars (lsb in uint256)
  18. - uint8_t algoDigit = (j & 1) ? prevblock[b] & 0xF : prevblock[b] >> 4;
  19. - if (algoDigit >= 10)
  20. - sprintf(sptr, "%c", 'A' + (algoDigit - 10));
  21. - else
  22. - sprintf(sptr, "%u", (uint32_t) algoDigit);
  23. - sptr++;
  24. + uint8_t b = (15 - j) >> 1;
  25. + output[j] = (j & 1) ? prevblock[j + 4] & 0x0F : prevblock[j + 4] >> 4;
  26. }
  27. - *sptr = '\0';
  28. }
  29.  
  30. -void x16r_hash(void* output, const void* input)
  31. +void x16blake(void *out, const void *in, uint32_t size)
  32. {
  33. - uint32_t _ALIGN(128) hash[64/4];
  34. -
  35. sph_blake512_context ctx_blake;
  36. - sph_bmw512_context ctx_bmw;
  37. - sph_groestl512_context ctx_groestl;
  38. +
  39. + sph_blake512_init(&ctx_blake);
  40. + sph_blake512(&ctx_blake, in, size);
  41. + sph_blake512_close(&ctx_blake, out);
  42. +}
  43. +
  44. +void x16bmw(void *out, const void *in, uint32_t size)
  45. +{
  46. + sph_bmw512_context ctx_bmw;
  47. +
  48. + sph_bmw512_init(&ctx_bmw);
  49. + sph_bmw512(&ctx_bmw, in, size);
  50. + sph_bmw512_close(&ctx_bmw, out);
  51. +}
  52. +
  53. +void x16groestl(void *out, const void *in, uint32_t size)
  54. +{
  55. + sph_groestl512_context ctx_groestl;
  56. +
  57. + sph_groestl512_init(&ctx_groestl);
  58. + sph_groestl512(&ctx_groestl, in, size);
  59. + sph_groestl512_close(&ctx_groestl, out);
  60. +}
  61. +
  62. +void x16jh(void *out, const void *in, uint32_t size)
  63. +{
  64. + sph_jh512_context ctx_jh;
  65. +
  66. + sph_jh512_init(&ctx_jh);
  67. + sph_jh512(&ctx_jh, in, size);
  68. + sph_jh512_close(&ctx_jh, out);
  69. +}
  70. +
  71. +void x16keccak(void *out, const void *in, uint32_t size)
  72. +{
  73. + sph_keccak512_context ctx_keccak;
  74. +
  75. + sph_keccak512_init(&ctx_keccak);
  76. + sph_keccak512(&ctx_keccak, in, size);
  77. + sph_keccak512_close(&ctx_keccak, out);
  78. +}
  79. +
  80. +void x16skein(void *out, const void *in, uint32_t size)
  81. +{
  82. sph_skein512_context ctx_skein;
  83. - sph_jh512_context ctx_jh;
  84. - sph_keccak512_context ctx_keccak;
  85. - sph_luffa512_context ctx_luffa1;
  86. - sph_cubehash512_context ctx_cubehash1;
  87. - sph_shavite512_context ctx_shavite1;
  88. - sph_simd512_context ctx_simd1;
  89. - sph_echo512_context ctx_echo1;
  90. - sph_hamsi512_context ctx_hamsi1;
  91. - sph_fugue512_context ctx_fugue1;
  92. - sph_shabal512_context ctx_shabal1;
  93. - sph_whirlpool_context ctx_whirlpool1;
  94. - sph_sha512_context ctx_sha512;
  95. +
  96. + sph_skein512_init(&ctx_skein);
  97. + sph_skein512(&ctx_skein, in, size);
  98. + sph_skein512_close(&ctx_skein, out);
  99. +}
  100.  
  101. - void *in = (void*) input;
  102. - int size = 80;
  103. +void x16luffa(void *out, const void *in, uint32_t size)
  104. +{
  105. + sph_luffa512_context ctx_luffa;
  106. +
  107. + sph_luffa512_init(&ctx_luffa);
  108. + sph_luffa512(&ctx_luffa, in, size);
  109. + sph_luffa512_close(&ctx_luffa, out);
  110. +}
  111.  
  112. - if (s_ntime == UINT32_MAX) {
  113. - const uint8_t* in8 = (uint8_t*) input;
  114. - getAlgoString(&in8[4], hashOrder);
  115. - }
  116. +void x16cubehash(void *out, const void *in, uint32_t size)
  117. +{
  118. + sph_cubehash512_context ctx_cubehash;
  119. +
  120. + sph_cubehash512_init(&ctx_cubehash);
  121. + sph_cubehash512(&ctx_cubehash, in, size);
  122. + sph_cubehash512_close(&ctx_cubehash, out);
  123. +}
  124. +
  125. +void x16shavite(void *out, const void *in, uint32_t size)
  126. +{
  127. + sph_shavite512_context ctx_shavite;
  128. +
  129. + sph_shavite512_init(&ctx_shavite);
  130. + sph_shavite512(&ctx_shavite, in, size);
  131. + sph_shavite512_close(&ctx_shavite, out);
  132. +}
  133.  
  134. +void x16simd(void *out, const void *in, uint32_t size)
  135. +{
  136. + sph_simd512_context ctx_simd;
  137. +
  138. + sph_simd512_init(&ctx_simd);
  139. + sph_simd512(&ctx_simd, in, size);
  140. + sph_simd512_close(&ctx_simd, out);
  141. +}
  142. +
  143. +void x16echo(void *out, const void *in, uint32_t size)
  144. +{
  145. + sph_echo512_context ctx_echo;
  146. +
  147. + sph_echo512_init(&ctx_echo);
  148. + sph_echo512(&ctx_echo, in, size);
  149. + sph_echo512_close(&ctx_echo, out);
  150. +}
  151. +
  152. +void x16hamsi(void *out, const void *in, uint32_t size)
  153. +{
  154. + sph_hamsi512_context ctx_hamsi;
  155. +
  156. + sph_hamsi512_init(&ctx_hamsi);
  157. + sph_hamsi512(&ctx_hamsi, in, size);
  158. + sph_hamsi512_close(&ctx_hamsi, out);
  159. +}
  160. +
  161. +void x16fugue(void *out, const void *in, uint32_t size)
  162. +{
  163. + sph_fugue512_context ctx_fugue;
  164. +
  165. + sph_fugue512_init(&ctx_fugue);
  166. + sph_fugue512(&ctx_fugue, in, size);
  167. + sph_fugue512_close(&ctx_fugue, out);
  168. +}
  169. +
  170. +void x16shabal(void *out, const void *in, uint32_t size)
  171. +{
  172. + sph_shabal512_context ctx_shabal;
  173. +
  174. + sph_shabal512_init(&ctx_shabal);
  175. + sph_shabal512(&ctx_shabal, in, size);
  176. + sph_shabal512_close(&ctx_shabal, out);
  177. +}
  178. +
  179. +void x16whirlpool(void *out, const void *in, uint32_t size)
  180. +{
  181. + sph_whirlpool_context ctx_whirlpool;
  182. +
  183. + sph_whirlpool_init(&ctx_whirlpool);
  184. + sph_whirlpool(&ctx_whirlpool, in, size);
  185. + sph_whirlpool_close(&ctx_whirlpool, out);
  186. +}
  187. +
  188. +void x16sha512(void *out, const void *in, uint32_t size)
  189. +{
  190. + sph_sha512_context ctx_sha;
  191. +
  192. + sph_sha512_init(&ctx_sha);
  193. + sph_sha512(&ctx_sha, in, size);
  194. + sph_sha512_close(&ctx_sha, out);
  195. +}
  196. +
  197. +void (* const AlgoList[16])(void *, const void *, uint32_t) = {x16blake, x16bmw, x16groestl, x16jh, x16keccak, x16skein, x16luffa, x16cubehash, x16shavite, x16simd, x16echo, x16hamsi, x16fugue, x16shabal, x16whirlpool, x16sha512};
  198. +
  199. +
  200. +void x16r_hash(void *output, const void *input)
  201. +{
  202. + uint32_t _ALIGN(128) hash[64/4];
  203. + void *in = (void*) input;
  204. + int size = 80;
  205. +
  206. for (int i = 0; i < 16; i++)
  207. {
  208. - const char elem = hashOrder[i];
  209. - const uint8_t algo = elem >= 'A' ? elem - 'A' + 10 : elem - '0';
  210. -
  211. - switch (algo) {
  212. - case BLAKE:
  213. - sph_blake512_init(&ctx_blake);
  214. - sph_blake512(&ctx_blake, in, size);
  215. - sph_blake512_close(&ctx_blake, hash);
  216. - break;
  217. - case BMW:
  218. - sph_bmw512_init(&ctx_bmw);
  219. - sph_bmw512(&ctx_bmw, in, size);
  220. - sph_bmw512_close(&ctx_bmw, hash);
  221. - break;
  222. - case GROESTL:
  223. - sph_groestl512_init(&ctx_groestl);
  224. - sph_groestl512(&ctx_groestl, in, size);
  225. - sph_groestl512_close(&ctx_groestl, hash);
  226. - break;
  227. - case SKEIN:
  228. - sph_skein512_init(&ctx_skein);
  229. - sph_skein512(&ctx_skein, in, size);
  230. - sph_skein512_close(&ctx_skein, hash);
  231. - break;
  232. - case JH:
  233. - sph_jh512_init(&ctx_jh);
  234. - sph_jh512(&ctx_jh, in, size);
  235. - sph_jh512_close(&ctx_jh, hash);
  236. - break;
  237. - case KECCAK:
  238. - sph_keccak512_init(&ctx_keccak);
  239. - sph_keccak512(&ctx_keccak, in, size);
  240. - sph_keccak512_close(&ctx_keccak, hash);
  241. - break;
  242. - case LUFFA:
  243. - sph_luffa512_init(&ctx_luffa1);
  244. - sph_luffa512(&ctx_luffa1, in, size);
  245. - sph_luffa512_close(&ctx_luffa1, hash);
  246. - break;
  247. - case CUBEHASH:
  248. - sph_cubehash512_init(&ctx_cubehash1);
  249. - sph_cubehash512(&ctx_cubehash1, in, size);
  250. - sph_cubehash512_close(&ctx_cubehash1, hash);
  251. - break;
  252. - case SHAVITE:
  253. - sph_shavite512_init(&ctx_shavite1);
  254. - sph_shavite512(&ctx_shavite1, in, size);
  255. - sph_shavite512_close(&ctx_shavite1, hash);
  256. - break;
  257. - case SIMD:
  258. - sph_simd512_init(&ctx_simd1);
  259. - sph_simd512(&ctx_simd1, in, size);
  260. - sph_simd512_close(&ctx_simd1, hash);
  261. - break;
  262. - case ECHO:
  263. - sph_echo512_init(&ctx_echo1);
  264. - sph_echo512(&ctx_echo1, in, size);
  265. - sph_echo512_close(&ctx_echo1, hash);
  266. - break;
  267. - case HAMSI:
  268. - sph_hamsi512_init(&ctx_hamsi1);
  269. - sph_hamsi512(&ctx_hamsi1, in, size);
  270. - sph_hamsi512_close(&ctx_hamsi1, hash);
  271. - break;
  272. - case FUGUE:
  273. - sph_fugue512_init(&ctx_fugue1);
  274. - sph_fugue512(&ctx_fugue1, in, size);
  275. - sph_fugue512_close(&ctx_fugue1, hash);
  276. - break;
  277. - case SHABAL:
  278. - sph_shabal512_init(&ctx_shabal1);
  279. - sph_shabal512(&ctx_shabal1, in, size);
  280. - sph_shabal512_close(&ctx_shabal1, hash);
  281. - break;
  282. - case WHIRLPOOL:
  283. - sph_whirlpool_init(&ctx_whirlpool1);
  284. - sph_whirlpool(&ctx_whirlpool1, in, size);
  285. - sph_whirlpool_close(&ctx_whirlpool1, hash);
  286. - break;
  287. - case SHA512:
  288. - sph_sha512_init(&ctx_sha512);
  289. - sph_sha512(&ctx_sha512,(const void*) in, size);
  290. - sph_sha512_close(&ctx_sha512,(void*) hash);
  291. - break;
  292. - }
  293. - in = (void*) hash;
  294. - size = 64;
  295. + const uint8_t algo = ((i & 1) ? ((uint8_t *)input)[4 + (((15 - i) >> 1))] & 0x0F : ((uint8_t *)input)[4 + (((15 - i) >> 1))] >> 4);
  296. + if(!i) AlgoList[algo](hash, input, 80);
  297. + else AlgoList[algo](hash, hash, 64);
  298. }
  299. memcpy(output, hash, 32);
  300. }
  301. @@ -202,9 +235,9 @@ int scanhash_x16r(int thr_id, struct work *work, uint32_t max_nonce, uint64_t *h
  302.  
  303. if (s_ntime != pdata[17]) {
  304. uint32_t ntime = swab32(pdata[17]);
  305. - getAlgoString((const char*) (&endiandata[1]), hashOrder);
  306. + //getAlgoString((const char*) (&endiandata[1]), hashOrder);
  307. s_ntime = ntime;
  308. - if (opt_debug && !thr_id) applog(LOG_DEBUG, "hash order %s (%08x)", hashOrder, ntime);
  309. + if (opt_debug && !thr_id) applog(LOG_DEBUG, "hash order %01X%01X%01X%01X (%08x)", hashOrder[0], hashOrder[1], hashOrder[2], hashOrder[3], ntime);
  310. }
  311.  
  312. if (opt_benchmark)
Advertisement
Add Comment
Please, Sign In to add comment