diff options
-rw-r--r-- | crypto/cryptonight_aesni.h | 11 | ||||
-rw-r--r-- | minethd.cpp | 22 |
2 files changed, 21 insertions, 12 deletions
diff --git a/crypto/cryptonight_aesni.h b/crypto/cryptonight_aesni.h index 4ae7d6e..37672c6 100644 --- a/crypto/cryptonight_aesni.h +++ b/crypto/cryptonight_aesni.h @@ -61,7 +61,8 @@ static inline __m128i sl_xor(__m128i tmp1) return tmp1; } -static inline void aes_genkey_sub(__m128i* xout0, __m128i* xout2, uint8_t rcon) +template<uint8_t rcon> +static inline void aes_genkey_sub(__m128i* xout0, __m128i* xout2) { __m128i xout1 = _mm_aeskeygenassist_si128(*xout2, rcon); xout1 = _mm_shuffle_epi32(xout1, 0xFF); // see PSHUFD, set all elems to 4th elem @@ -99,28 +100,28 @@ static inline void aes_genkey(const __m128i* memory, __m128i* k0, __m128i* k1, _ if(SOFT_AES) soft_aes_genkey_sub(&xout0, &xout2, 0x01); else - aes_genkey_sub(&xout0, &xout2, 0x01); + aes_genkey_sub<0x01>(&xout0, &xout2); *k2 = xout0; *k3 = xout2; if(SOFT_AES) soft_aes_genkey_sub(&xout0, &xout2, 0x02); else - aes_genkey_sub(&xout0, &xout2, 0x02); + aes_genkey_sub<0x02>(&xout0, &xout2); *k4 = xout0; *k5 = xout2; if(SOFT_AES) soft_aes_genkey_sub(&xout0, &xout2, 0x04); else - aes_genkey_sub(&xout0, &xout2, 0x04); + aes_genkey_sub<0x04>(&xout0, &xout2); *k6 = xout0; *k7 = xout2; if(SOFT_AES) soft_aes_genkey_sub(&xout0, &xout2, 0x08); else - aes_genkey_sub(&xout0, &xout2, 0x08); + aes_genkey_sub<0x08>(&xout0, &xout2); *k8 = xout0; *k9 = xout2; } diff --git a/minethd.cpp b/minethd.cpp index 065b3f8..ca9a852 100644 --- a/minethd.cpp +++ b/minethd.cpp @@ -238,15 +238,23 @@ bool minethd::self_test() unsigned char out[64]; bool bResult; - cryptonight_hash_ctx("This is a test", 14, out, ctx0); - bResult = memcmp(out, "\xa0\x84\xf0\x1d\x14\x37\xa0\x9c\x69\x85\x40\x1b\x60\xd4\x35\x54\xae\x10\x58\x02\xc5\xf5\xd8\xa9\xb3\x25\x36\x49\xc0\xbe\x66\x05", 32) == 0; + if(jconf::inst()->HaveHardwareAes()) + { + cryptonight_hash_ctx("This is a test", 14, out, ctx0); + bResult = memcmp(out, "\xa0\x84\xf0\x1d\x14\x37\xa0\x9c\x69\x85\x40\x1b\x60\xd4\x35\x54\xae\x10\x58\x02\xc5\xf5\xd8\xa9\xb3\x25\x36\x49\xc0\xbe\x66\x05", 32) == 0; - cryptonight_hash_ctx_np("This is a test", 14, out, ctx0); - bResult &= memcmp(out, "\xa0\x84\xf0\x1d\x14\x37\xa0\x9c\x69\x85\x40\x1b\x60\xd4\x35\x54\xae\x10\x58\x02\xc5\xf5\xd8\xa9\xb3\x25\x36\x49\xc0\xbe\x66\x05", 32) == 0; + cryptonight_hash_ctx_np("This is a test", 14, out, ctx0); + bResult &= memcmp(out, "\xa0\x84\xf0\x1d\x14\x37\xa0\x9c\x69\x85\x40\x1b\x60\xd4\x35\x54\xae\x10\x58\x02\xc5\xf5\xd8\xa9\xb3\x25\x36\x49\xc0\xbe\x66\x05", 32) == 0; - cryptonight_double_hash_ctx("The quick brown fox jumps over the lazy dogThe quick brown fox jumps over the lazy log", 43, out, ctx0, ctx1); - bResult &= memcmp(out, "\x3e\xbb\x7f\x9f\x7d\x27\x3d\x7c\x31\x8d\x86\x94\x77\x55\x0c\xc8\x00\xcf\xb1\x1b\x0c\xad\xb7\xff\xbd\xf6\xf8\x9f\x3a\x47\x1c\x59" - "\xb4\x77\xd5\x02\xe4\xd8\x48\x7f\x42\xdf\xe3\x8e\xed\x73\x81\x7a\xda\x91\xb7\xe2\x63\xd2\x91\x71\xb6\x5c\x44\x3a\x01\x2a\x41\x22", 64) == 0; + cryptonight_double_hash_ctx("The quick brown fox jumps over the lazy dogThe quick brown fox jumps over the lazy log", 43, out, ctx0, ctx1); + bResult &= memcmp(out, "\x3e\xbb\x7f\x9f\x7d\x27\x3d\x7c\x31\x8d\x86\x94\x77\x55\x0c\xc8\x00\xcf\xb1\x1b\x0c\xad\xb7\xff\xbd\xf6\xf8\x9f\x3a\x47\x1c\x59" + "\xb4\x77\xd5\x02\xe4\xd8\x48\x7f\x42\xdf\xe3\x8e\xed\x73\x81\x7a\xda\x91\xb7\xe2\x63\xd2\x91\x71\xb6\x5c\x44\x3a\x01\x2a\x41\x22", 64) == 0; + } + else + { + cryptonight_hash_ctx_soft("This is a test", 14, out, ctx0); + bResult = memcmp(out, "\xa0\x84\xf0\x1d\x14\x37\xa0\x9c\x69\x85\x40\x1b\x60\xd4\x35\x54\xae\x10\x58\x02\xc5\xf5\xd8\xa9\xb3\x25\x36\x49\xc0\xbe\x66\x05", 32) == 0; + } cryptonight_free_ctx(ctx0); cryptonight_free_ctx(ctx1); |