bastion.c 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138
  1. #include "miner.h"
  2. #include <stdio.h>
  3. #include <string.h>
  4. #include <openssl/sha.h>
  5. #include <stdint.h>
  6. #include <stdlib.h>
  7. #include "sha3/sph_hefty1.h"
  8. #include "sha3/sph_luffa.h"
  9. #include "sha3/sph_fugue.h"
  10. #include "sha3/sph_skein.h"
  11. #include "sha3/sph_whirlpool.h"
  12. #include "sha3/sph_shabal.h"
  13. #include "sha3/sph_echo.h"
  14. #include "sha3/sph_hamsi.h"
  15. void bastionhash(void *output, const void *input)
  16. {
  17. unsigned char _ALIGN(128) hash[64] = { 0 };
  18. sph_echo512_context ctx_echo;
  19. sph_luffa512_context ctx_luffa;
  20. sph_fugue512_context ctx_fugue;
  21. sph_whirlpool_context ctx_whirlpool;
  22. sph_shabal512_context ctx_shabal;
  23. sph_skein512_context ctx_skein;
  24. sph_hamsi512_context ctx_hamsi;
  25. HEFTY1(input, 80, hash);
  26. sph_luffa512_init(&ctx_luffa);
  27. sph_luffa512(&ctx_luffa, hash, 64);
  28. sph_luffa512_close(&ctx_luffa, hash);
  29. if (hash[0] & 0x8)
  30. {
  31. sph_fugue512_init(&ctx_fugue);
  32. sph_fugue512(&ctx_fugue, hash, 64);
  33. sph_fugue512_close(&ctx_fugue, hash);
  34. } else {
  35. sph_skein512_init(&ctx_skein);
  36. sph_skein512(&ctx_skein, hash, 64);
  37. sph_skein512_close(&ctx_skein, hash);
  38. }
  39. sph_whirlpool_init(&ctx_whirlpool);
  40. sph_whirlpool(&ctx_whirlpool, hash, 64);
  41. sph_whirlpool_close(&ctx_whirlpool, hash);
  42. sph_fugue512_init(&ctx_fugue);
  43. sph_fugue512(&ctx_fugue, hash, 64);
  44. sph_fugue512_close(&ctx_fugue, hash);
  45. if (hash[0] & 0x8)
  46. {
  47. sph_echo512_init(&ctx_echo);
  48. sph_echo512(&ctx_echo, hash, 64);
  49. sph_echo512_close(&ctx_echo, hash);
  50. } else {
  51. sph_luffa512_init(&ctx_luffa);
  52. sph_luffa512(&ctx_luffa, hash, 64);
  53. sph_luffa512_close(&ctx_luffa, hash);
  54. }
  55. sph_shabal512_init(&ctx_shabal);
  56. sph_shabal512(&ctx_shabal, hash, 64);
  57. sph_shabal512_close(&ctx_shabal, hash);
  58. sph_skein512_init(&ctx_skein);
  59. sph_skein512(&ctx_skein, hash, 64);
  60. sph_skein512_close(&ctx_skein, hash);
  61. if (hash[0] & 0x8)
  62. {
  63. sph_shabal512_init(&ctx_shabal);
  64. sph_shabal512(&ctx_shabal, hash, 64);
  65. sph_shabal512_close(&ctx_shabal, hash);
  66. } else {
  67. sph_whirlpool_init(&ctx_whirlpool);
  68. sph_whirlpool(&ctx_whirlpool, hash, 64);
  69. sph_whirlpool_close(&ctx_whirlpool, hash);
  70. }
  71. sph_shabal512_init(&ctx_shabal);
  72. sph_shabal512(&ctx_shabal, hash, 64);
  73. sph_shabal512_close(&ctx_shabal, hash);
  74. if (hash[0] & 0x8)
  75. {
  76. sph_hamsi512_init(&ctx_hamsi);
  77. sph_hamsi512(&ctx_hamsi, hash, 64);
  78. sph_hamsi512_close(&ctx_hamsi, hash);
  79. } else {
  80. sph_luffa512_init(&ctx_luffa);
  81. sph_luffa512(&ctx_luffa, hash, 64);
  82. sph_luffa512_close(&ctx_luffa, hash);
  83. }
  84. memcpy(output, hash, 32);
  85. }
  86. int scanhash_bastion(int thr_id, struct work *work, uint32_t max_nonce, uint64_t *hashes_done)
  87. {
  88. uint32_t _ALIGN(64) hash32[8];
  89. uint32_t _ALIGN(64) endiandata[20];
  90. uint32_t *pdata = work->data;
  91. uint32_t *ptarget = work->target;
  92. const uint32_t Htarg = ptarget[7];
  93. const uint32_t first_nonce = pdata[19];
  94. uint32_t n = first_nonce;
  95. for (int i=0; i < 19; i++) {
  96. be32enc(&endiandata[i], pdata[i]);
  97. }
  98. do {
  99. be32enc(&endiandata[19], n);
  100. bastionhash(hash32, endiandata);
  101. if (hash32[7] < Htarg && fulltest(hash32, ptarget)) {
  102. work_set_target_ratio(work, hash32);
  103. *hashes_done = n - first_nonce + 1;
  104. pdata[19] = n;
  105. return true;
  106. }
  107. n++;
  108. } while (n < max_nonce && !work_restart[thr_id].restart);
  109. *hashes_done = n - first_nonce + 1;
  110. pdata[19] = n;
  111. return 0;
  112. }