├── README.md ├── fpga_miner_aws ├── CMakeLists.txt ├── README.md ├── algo │ ├── blakecoin.c │ ├── decred.c │ ├── groestl.c │ ├── myr-groestl.c │ ├── nist5.c │ ├── phi.c │ ├── poly.c │ ├── sha2.c │ ├── skunk.c │ └── tribus.c ├── api.c ├── api │ ├── API.class │ ├── API.java │ ├── index.php │ ├── local-sample.php │ └── websocket.htm ├── compat.h ├── compat │ ├── jansson │ │ ├── CMakeLists.txt │ │ ├── config.h │ │ ├── dump.c │ │ ├── hashtable.c │ │ ├── hashtable.h │ │ ├── jansson.h │ │ ├── jansson_private.h │ │ ├── load.c │ │ ├── strbuffer.c │ │ ├── strbuffer.h │ │ ├── utf.c │ │ ├── utf.h │ │ ├── util.h │ │ └── value.c │ ├── winansi.c │ └── winansi.h ├── elist.h ├── fpga-miner.c ├── fpga_miner ├── fpgautils.c ├── fpgautils.h ├── miner.h ├── sha3 │ ├── aes_helper.c │ ├── blake.c │ ├── cubehash.c │ ├── echo.c │ ├── fugue.c │ ├── gost.c │ ├── groestl.c │ ├── haval.c │ ├── haval_helper.c │ ├── jh.c │ ├── keccak.c │ ├── luffa.c │ ├── md_helper.c │ ├── mod_blakecoin.c │ ├── sha2.c │ ├── shabal.c │ ├── skein.c │ ├── sph_blake.h │ ├── sph_cubehash.h │ ├── sph_echo.h │ ├── sph_fugue.h │ ├── sph_gost.h │ ├── sph_groestl.h │ ├── sph_haval.h │ ├── sph_jh.h │ ├── sph_keccak.h │ ├── sph_luffa.h │ ├── sph_sha2.h │ ├── sph_shabal.h │ ├── sph_skein.h │ └── sph_types.h └── util.c ├── grs ├── cl_common_defines.vh ├── cl_id_defines.vh ├── cl_miner_defines.vh ├── grostl512.v ├── miner.v ├── miner_top.v ├── mix_bytes.v ├── permutation_p.v └── permutation_q.v ├── myr_grs ├── cl_common_defines.vh ├── cl_id_defines.vh ├── cl_miner_defines.vh ├── grostl512.v ├── miner.v ├── miner_top.v ├── mix_bytes.v ├── permutation_p.v ├── permutation_q.v └── sha256_pipes2.v ├── phi1612 ├── cl_common_defines.vh ├── cl_id_defines.vh ├── cl_miner_defines.vh ├── cube.v ├── echo.v ├── fugue.v ├── fugue_smix.v ├── gost.v ├── jh.v ├── miner.v ├── miner_top.v └── skein.v ├── skunk ├── cl_common_defines.vh ├── cl_id_defines.vh ├── cl_miner_defines.vh ├── cube.v ├── fugue.v ├── fugue_smix.v ├── gost.v ├── miner.v ├── miner_top.v └── skein.v └── tribus ├── cl_common_defines.vh ├── cl_id_defines.vh ├── cl_miner_defines.vh ├── echo.v ├── jh.v ├── keccak.v ├── miner.v └── miner_top.v /README.md: -------------------------------------------------------------------------------- 1 | # FPGA Miner & Verilog Code For Mining Using AWS 2 | 3 | In light of the recent push to leverage the newer Xilinx FPGA chips for crypto mining, I am providing some examples that can be tested using AWS F1 instances. 4 | 5 | Please keep in mind, none of the code I have provided is profitable for mining using AWS, (but they may provide a good return on the VCU1525 boards), and these are the unoptomized verions of my algos. Also, I don't personally mine using AWS as I find it quite cumbersome...but I provided the full verilog / miner as AWS is a great place to test out your builds. 6 | 7 | I am simply posting these as educational tools so that others can learn from them and improve upon them. You will need to tweak the I/O to match the board that you intent to run them on. 8 | 9 | Best of luck to all of you miners out there... 10 | 11 | If you find this FPGA code helpful, feel free to leave a tip - BTC: 1AxiWd4oAccnGuT6TJxDtEX7nJs1veTviQ 12 | -------------------------------------------------------------------------------- /fpga_miner_aws/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | cmake_minimum_required (VERSION 2.8) 2 | 3 | project(fpga_miner) 4 | 5 | message(STATUS "Creating Make for 'fpga_miner'...") 6 | 7 | # Confirm CURL Has Been Installed 8 | find_path( CURL_INCLUDE_DIR curl/curl.h PATHS ${PC_CURL_INCLUDEDIR} ${PC_CURL_INCLUDE_DIRS} PATH_SUFFIXES include ) 9 | find_library( CURL_LIBRARIES NAMES curl PATHS ${PC_CURL_LIBDIR} ${PC_CURL_LIBRARY_DIRS} PATH_SUFFIXES lib ) 10 | 11 | IF (CURL_INCLUDE_DIR AND CURL_LIBRARIES) 12 | SET(CURL_FOUND TRUE) 13 | ELSE (CURL_INCLUDE_DIR AND CURL_LIBRARIES) 14 | SET(CURL_FOUND FALSE) 15 | ENDIF (CURL_INCLUDE_DIR AND CURL_LIBRARIES) 16 | 17 | IF (CURL_FOUND) 18 | message(STATUS " CURL: Found") 19 | ELSE (CURL_FOUND) 20 | message(STATUS " CURL: Not Found!") 21 | ENDIF (CURL_FOUND) 22 | 23 | # Confirm AWS SDK Has Been Installed 24 | SET(AWS_SDK_INCLUDE_DIRS /path/to/include/aws CACHE STRING "aws-cpp-sdk include directories") 25 | SET(AWS_SDK_CORE_LIB "-l:/path/to/libaws-cpp-sdk-core.so" CACHE STRING "aws-cpp-sdk link core lib") 26 | 27 | FIND_PATH( AWS_SDK_INCLUDE_DIRS curl/curl.h PATHS ${AWS_SDK_INCLUDE_DIRS} PATH_SUFFIXES include ) 28 | FIND_LIBRARY( AWS_SDK_CORE_LIB NAMES fpga_mgmt PATHS ${AWS_SDK_CORE_LIB} PATH_SUFFIXES lib ) 29 | 30 | IF (AWS_SDK_INCLUDE_DIRS AND AWS_SDK_CORE_LIB) 31 | SET(SDK_FOUND TRUE) 32 | ELSE (AWS_SDK_INCLUDE_DIRS AND AWS_SDK_CORE_LIB) 33 | SET(SDK_FOUND FALSE) 34 | ENDIF (AWS_SDK_INCLUDE_DIRS AND AWS_SDK_CORE_LIB) 35 | 36 | IF (SDK_FOUND) 37 | message(STATUS " AWS SDK: Found") 38 | ELSE (SDK_FOUND) 39 | message(STATUS " AWS SDK: Not Found!") 40 | ENDIF (SDK_FOUND) 41 | 42 | add_subdirectory(compat/jansson) 43 | 44 | include_directories( ~/aws-fpga/sdk/userspace/include ~/aws-fpga/sdk/userspace/include/hal ${PROJECT_SOURCE_DIR} ${PROJECT_SOURCE_DIR}/algo ${PROJECT_SOURCE_DIR}/compat/jansson ${CURL_INCLUDE_DIR} ${LIBUSB_INCLUDE_DIR} ${AWS_SDK_INCLUDE_DIRS}) 45 | 46 | set(SRC_LIST fpga-miner.c 47 | api.c 48 | fpgautils.c 49 | util.c 50 | ./algo/blakecoin.c 51 | ./algo/decred.c 52 | ./algo/groestl.c 53 | ./algo/myr-groestl.c 54 | ./algo/nist5.c 55 | ./algo/phi.c 56 | ./algo/poly.c 57 | ./algo/sha2.c 58 | ./algo/skunk.c 59 | ./algo/tribus.c 60 | ./sha3/mod_blakecoin.c 61 | ./sha3/blake.c 62 | ./sha3/cubehash.c 63 | ./sha3/fugue.c 64 | ./sha3/echo.c 65 | ./sha3/gost.c 66 | ./sha3/groestl.c 67 | ./sha3/haval.c 68 | ./sha3/jh.c 69 | ./sha3/keccak.c 70 | ./sha3/luffa.c 71 | ./sha3/sha2.c 72 | ./sha3/shabal.c 73 | ./sha3/skein.c 74 | ) 75 | 76 | set(TARGET_NAME fpga_miner) 77 | 78 | IF ( WIN32 ) 79 | add_executable(${TARGET_NAME} ${SRC_LIST} ./compat/winansi.c) 80 | ELSE ( WIN32 ) 81 | add_executable(${TARGET_NAME} ${SRC_LIST}) 82 | ENDIF ( WIN32 ) 83 | 84 | target_link_libraries(${TARGET_NAME} crypto pthread ${CURL_LIBRARIES} jansson fpga_mgmt) 85 | 86 | IF(WIN32) 87 | target_link_libraries(${TARGET_NAME} libcurl Ws2_32) 88 | ENDIF(WIN32) 89 | 90 | IF(UNIX) 91 | target_link_libraries(${TARGET_NAME} m) 92 | ENDIF(UNIX) 93 | 94 | set_target_properties( ${TARGET_NAME} PROPERTIES RUNTIME_OUTPUT_DIRECTORY ${PROJECT_SOURCE_DIR} ) 95 | -------------------------------------------------------------------------------- /fpga_miner_aws/README.md: -------------------------------------------------------------------------------- 1 | This miner can be used to interface with bitstreams on the AWS F1 instances 2 | 3 | Please note that this I/O is specific for the bitstream. If your bitstream uses a different I/O pattern (i.e. opposite endianness) you will need to make that adjustment in the fpga_miner.c code. 4 | -------------------------------------------------------------------------------- /fpga_miner_aws/algo/blakecoin.c: -------------------------------------------------------------------------------- 1 | #include "miner.h" 2 | 3 | #define BLAKE32_ROUNDS 8 4 | #include "sha3/sph_blake.h" 5 | 6 | void blakecoin_init(void *cc); 7 | void blakecoin(void *cc, const void *data, size_t len); 8 | void blakecoin_close(void *cc, void *dst); 9 | 10 | #include 11 | #include 12 | #include 13 | 14 | static __thread sph_blake256_context blake_mid; 15 | static __thread bool ctx_midstate_done = false; 16 | 17 | void blakecoinmidstate(void *state, const void *input) 18 | { 19 | sph_blake256_context ctx; 20 | 21 | blakecoin_init(&ctx); 22 | blakecoin(&ctx, input, 64); 23 | 24 | // Copy Midstate 25 | memcpy(state, &ctx.H[0], 32); 26 | } 27 | 28 | void blakecoinhash(void *state, const void *input) 29 | { 30 | sph_blake256_context ctx; 31 | 32 | blakecoin_init(&ctx); 33 | blakecoin(&ctx, input, 80); 34 | blakecoin_close(&ctx, state); 35 | } 36 | 37 | ////void blakecoinhash(void *state, const void *input) 38 | //{ 39 | // sph_blake256_context ctx; 40 | // 41 | // uint8_t *ending = (uint8_t*) input; 42 | // ending += 64; 43 | // 44 | // // do one memcopy to get a fresh context 45 | // if (!ctx_midstate_done) { 46 | // blakecoin_init(&blake_mid); 47 | // blakecoin(&blake_mid, input, 64); 48 | // ctx_midstate_done = true; 49 | // } 50 | // memcpy(&ctx, &blake_mid, sizeof(blake_mid)); 51 | // 52 | // blakecoin(&ctx, ending, 16); 53 | // blakecoin_close(&ctx, state); 54 | //} 55 | 56 | int scanhash_blakecoin(int thr_id, struct work *work, uint32_t max_nonce, uint64_t *hashes_done) 57 | { 58 | int kk; 59 | uint32_t _ALIGN(128) hash32[8]; 60 | uint32_t _ALIGN(128) endiandata[20]; 61 | uint32_t *pdata = work->data; 62 | uint32_t *ptarget = work->target; 63 | 64 | const uint32_t first_nonce = pdata[19]; 65 | const uint32_t HTarget = opt_benchmark ? 0x7f : ptarget[7]; 66 | uint32_t n = first_nonce; 67 | 68 | ctx_midstate_done = false; 69 | 70 | // we need big endian data... 71 | for (kk = 0; kk < 19; kk++) { 72 | be32enc(&endiandata[kk], pdata[kk]); 73 | } 74 | 75 | #ifdef DEBUG_ALGO 76 | applog(LOG_DEBUG,"[%d] Target=%08x %08x", thr_id, ptarget[6], ptarget[7]); 77 | #endif 78 | 79 | do { 80 | be32enc(&endiandata[19], n); 81 | blakecoinhash(hash32, endiandata); 82 | 83 | if (hash32[7] <= HTarget && fulltest(hash32, ptarget)) { 84 | work_set_target_ratio(work, hash32); 85 | *hashes_done = n - first_nonce + 1; 86 | return 1; 87 | } 88 | 89 | n++; pdata[19] = n; 90 | 91 | } while (n < max_nonce && !work_restart[thr_id].restart); 92 | 93 | *hashes_done = n - first_nonce + 1; 94 | pdata[19] = n; 95 | return 0; 96 | } 97 | -------------------------------------------------------------------------------- /fpga_miner_aws/algo/decred.c: -------------------------------------------------------------------------------- 1 | #include "miner.h" 2 | 3 | #include "sha3/sph_blake.h" 4 | 5 | #include 6 | #include 7 | #include 8 | 9 | static __thread sph_blake256_context blake_mid; 10 | static __thread bool ctx_midstate_done = false; 11 | 12 | void decred_midstate(void *state, const void *input) 13 | { 14 | sph_blake256_context ctx; 15 | 16 | sph_blake256_init(&ctx); 17 | sph_blake256(&ctx, input, 128); 18 | 19 | // Copy Midstate 20 | memcpy(state, &ctx.H[0], 32); 21 | } 22 | 23 | void decred_hash(void *state, const void *input) 24 | { 25 | sph_blake256_context ctx; 26 | 27 | sph_blake256_init(&ctx); 28 | sph_blake256(&ctx, input, 180); 29 | sph_blake256_close(&ctx, state); 30 | } 31 | 32 | ////void decred_hash(void *state, const void *input) 33 | //{ 34 | // #define MIDSTATE_LEN 128 35 | // sph_blake256_context ctx; 36 | // 37 | // uint8_t *ending = (uint8_t*) input; 38 | // ending += MIDSTATE_LEN; 39 | // 40 | // if (!ctx_midstate_done) { 41 | // sph_blake256_init(&blake_mid); 42 | // sph_blake256(&blake_mid, input, MIDSTATE_LEN); 43 | // ctx_midstate_done = true; 44 | // } 45 | // memcpy(&ctx, &blake_mid, sizeof(blake_mid)); 46 | // 47 | // sph_blake256(&ctx, ending, (180 - MIDSTATE_LEN)); 48 | // sph_blake256_close(&ctx, state); 49 | //} 50 | 51 | void decred_hash_simple(void *state, const void *input) 52 | { 53 | sph_blake256_context ctx; 54 | sph_blake256_init(&ctx); 55 | sph_blake256(&ctx, input, 180); 56 | sph_blake256_close(&ctx, state); 57 | } 58 | 59 | int scanhash_decred(int thr_id, struct work *work, uint32_t max_nonce, uint64_t *hashes_done) 60 | { 61 | uint32_t _ALIGN(128) endiandata[48]; 62 | uint32_t _ALIGN(128) hash32[8]; 63 | uint32_t *pdata = work->data; 64 | uint32_t *ptarget = work->target; 65 | 66 | #define DCR_NONCE_OFT32 35 67 | 68 | const uint32_t first_nonce = pdata[DCR_NONCE_OFT32]; 69 | const uint32_t HTarget = opt_benchmark ? 0x7f : ptarget[7]; 70 | 71 | uint32_t n = first_nonce; 72 | 73 | ctx_midstate_done = false; 74 | 75 | #if 1 76 | memcpy(endiandata, pdata, 180); 77 | #else 78 | for (int k=0; k < (180/4); k++) 79 | be32enc(&endiandata[k], pdata[k]); 80 | #endif 81 | 82 | #ifdef DEBUG_ALGO 83 | if (!thr_id) applog(LOG_DEBUG,"[%d] Target=%08x %08x", thr_id, ptarget[6], ptarget[7]); 84 | #endif 85 | 86 | do { 87 | //be32enc(&endiandata[DCR_NONCE_OFT32], n); 88 | endiandata[DCR_NONCE_OFT32] = n; 89 | decred_hash(hash32, endiandata); 90 | 91 | if (hash32[7] <= HTarget && fulltest(hash32, ptarget)) { 92 | work_set_target_ratio(work, hash32); 93 | *hashes_done = n - first_nonce + 1; 94 | #ifdef DEBUG_ALGO 95 | applog(LOG_BLUE, "Nonce : %08x %08x", n, swab32(n)); 96 | applog_hash(ptarget); 97 | applog_compare_hash(hash32, ptarget); 98 | #endif 99 | pdata[DCR_NONCE_OFT32] = n; 100 | return 1; 101 | } 102 | 103 | n++; 104 | 105 | } while (n < max_nonce && !work_restart[thr_id].restart); 106 | 107 | *hashes_done = n - first_nonce + 1; 108 | pdata[DCR_NONCE_OFT32] = n; 109 | return 0; 110 | } 111 | -------------------------------------------------------------------------------- /fpga_miner_aws/algo/groestl.c: -------------------------------------------------------------------------------- 1 | #include "miner.h" 2 | 3 | #include 4 | #include 5 | #include 6 | #include 7 | 8 | #include "sha3/sph_groestl.h" 9 | 10 | // static __thread sph_groestl512_context ctx; 11 | 12 | void groestlhash(void *output, const void *input) 13 | { 14 | uint32_t _ALIGN(32) hash[16]; 15 | sph_groestl512_context ctx; 16 | 17 | // memset(&hash[0], 0, sizeof(hash)); 18 | 19 | sph_groestl512_init(&ctx); 20 | sph_groestl512(&ctx, input, 80); 21 | sph_groestl512_close(&ctx, hash); 22 | 23 | //sph_groestl512_init(&ctx); 24 | sph_groestl512(&ctx, hash, 64); 25 | sph_groestl512_close(&ctx, hash); 26 | 27 | memcpy(output, hash, 32); 28 | } 29 | 30 | int scanhash_groestl(int thr_id, struct work *work, uint32_t max_nonce, uint64_t *hashes_done) 31 | { 32 | int k; 33 | uint32_t _ALIGN(128) hash[8]; 34 | uint32_t _ALIGN(128) endiandata[20]; 35 | uint32_t *pdata = work->data; 36 | uint32_t *ptarget = work->target; 37 | 38 | const uint32_t Htarg = ptarget[7]; 39 | const uint32_t first_nonce = pdata[19]; 40 | uint32_t nonce = first_nonce; 41 | 42 | if (opt_benchmark) 43 | ptarget[7] = 0x00ff; 44 | 45 | for (k = 0; k < 19; k++) 46 | be32enc(&endiandata[k], pdata[k]); 47 | 48 | do { 49 | be32enc(&endiandata[19], nonce); 50 | groestlhash(hash, endiandata); 51 | 52 | if (hash[7] <= Htarg && fulltest(hash, ptarget)) { 53 | work_set_target_ratio(work, hash); 54 | pdata[19] = nonce; 55 | *hashes_done = pdata[19] - first_nonce; 56 | return 1; 57 | } 58 | nonce++; 59 | 60 | } while (nonce < max_nonce && !work_restart[thr_id].restart); 61 | 62 | pdata[19] = nonce; 63 | *hashes_done = pdata[19] - first_nonce + 1; 64 | return 0; 65 | } 66 | -------------------------------------------------------------------------------- /fpga_miner_aws/algo/myr-groestl.c: -------------------------------------------------------------------------------- 1 | #include "miner.h" 2 | 3 | #include 4 | #include 5 | #include 6 | #include 7 | 8 | #include "sha3/sph_groestl.h" 9 | #include "sha3/sph_sha2.h" 10 | 11 | void myriadhash(void *output, const void *input) 12 | { 13 | uint32_t _ALIGN(32) hash[16]; 14 | sph_groestl512_context ctx; 15 | sph_sha256_context sha_ctx; 16 | 17 | // memset(&hash[0], 0, sizeof(hash)); 18 | 19 | sph_groestl512_init(&ctx); 20 | sph_groestl512(&ctx, input, 80); 21 | sph_groestl512_close(&ctx, hash); 22 | 23 | sph_sha256_init(&sha_ctx); 24 | sph_sha256(&sha_ctx, hash, 64); 25 | sph_sha256_close(&sha_ctx, hash); 26 | 27 | memcpy(output, hash, 32); 28 | } 29 | 30 | int scanhash_myriad(int thr_id, struct work *work, uint32_t max_nonce, uint64_t *hashes_done) 31 | { 32 | int i; 33 | uint32_t _ALIGN(128) hash[8]; 34 | uint32_t _ALIGN(128) endiandata[20]; 35 | uint32_t *pdata = work->data; 36 | uint32_t *ptarget = work->target; 37 | 38 | const uint32_t Htarg = ptarget[7]; 39 | const uint32_t first_nonce = pdata[19]; 40 | uint32_t nonce = first_nonce; 41 | 42 | if (opt_benchmark) 43 | ptarget[7] = 0x0000ff; 44 | 45 | for (i = 0; i < 19; i++) { 46 | be32enc(&endiandata[i], pdata[i]); 47 | } 48 | 49 | do { 50 | be32enc(&endiandata[19], nonce); 51 | myriadhash(hash, endiandata); 52 | 53 | if (hash[7] <= Htarg && fulltest(hash, ptarget)) { 54 | work_set_target_ratio(work, hash); 55 | pdata[19] = nonce; 56 | *hashes_done = pdata[19] - first_nonce; 57 | return 1; 58 | } 59 | nonce++; 60 | 61 | } while (nonce < max_nonce && !work_restart[thr_id].restart); 62 | 63 | pdata[19] = nonce; 64 | *hashes_done = pdata[19] - first_nonce + 1; 65 | return 0; 66 | } 67 | -------------------------------------------------------------------------------- /fpga_miner_aws/algo/nist5.c: -------------------------------------------------------------------------------- 1 | /*- 2 | * Copyright 2017 tpruvot 3 | * All rights reserved. 4 | * 5 | * Redistribution and use in source and binary forms, with or without 6 | * modification, are permitted provided that the following conditions 7 | * are met: 8 | * 1. Redistributions of source code must retain the above copyright 9 | * notice, this list of conditions and the following disclaimer. 10 | * 2. Redistributions in binary form must reproduce the above copyright 11 | * notice, this list of conditions and the following disclaimer in the 12 | * documentation and/or other materials provided with the distribution. 13 | * 14 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 15 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 16 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 17 | * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 18 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 19 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 20 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 21 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 22 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 23 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 24 | * SUCH DAMAGE. 25 | * 26 | * This file was originally written by Colin Percival as part of the Tarsnap 27 | * online backup system. 28 | */ 29 | 30 | #include "miner.h" 31 | 32 | #include 33 | #include 34 | #include 35 | 36 | #include 37 | #include 38 | #include 39 | 40 | #include 41 | #include 42 | #include 43 | #include 44 | #include 45 | 46 | static inline void be32enc_vect(uint32_t *dst, const uint32_t *src, uint32_t len) 47 | { 48 | uint32_t i; 49 | for (i = 0; i < len; i++) 50 | dst[i] = htobe32(src[i]); 51 | } 52 | 53 | void nist5_midstate(void *state, const void *input) 54 | { 55 | uint64_t *s = (uint64_t *)state; 56 | 57 | sph_skein512_context ctx_skein; 58 | 59 | sph_skein512_init(&ctx_skein); 60 | sph_skein512(&ctx_skein, input, 80); 61 | 62 | s[0] = ctx_skein.h0; 63 | s[1] = ctx_skein.h1; 64 | s[2] = ctx_skein.h2; 65 | s[3] = ctx_skein.h3; 66 | s[4] = ctx_skein.h4; 67 | s[5] = ctx_skein.h5; 68 | s[6] = ctx_skein.h6; 69 | s[7] = ctx_skein.h7; 70 | } 71 | 72 | void nist5_hash(void *state, const void *input) 73 | { 74 | sph_blake512_context ctx_blake; 75 | sph_groestl512_context ctx_groestl; 76 | sph_jh512_context ctx_jh; 77 | sph_keccak512_context ctx_keccak; 78 | sph_skein512_context ctx_skein; 79 | 80 | uint8_t hash[64]; 81 | 82 | sph_blake512_init(&ctx_blake); 83 | sph_blake512(&ctx_blake, input, 80); 84 | sph_blake512_close(&ctx_blake, (void*)hash); 85 | 86 | sph_groestl512_init(&ctx_groestl); 87 | sph_groestl512(&ctx_groestl, (const void*)hash, 64); 88 | sph_groestl512_close(&ctx_groestl, (void*)hash); 89 | 90 | sph_jh512_init(&ctx_jh); 91 | sph_jh512(&ctx_jh, (const void*)hash, 64); 92 | sph_jh512_close(&ctx_jh, (void*)hash); 93 | 94 | sph_keccak512_init(&ctx_keccak); 95 | sph_keccak512(&ctx_keccak, (const void*)hash, 64); 96 | sph_keccak512_close(&ctx_keccak, (void*)hash); 97 | 98 | sph_skein512_init(&ctx_skein); 99 | sph_skein512(&ctx_skein, (const void*)hash, 64); 100 | sph_skein512_close(&ctx_skein, (void*)hash); 101 | 102 | memcpy(state, hash, 32); 103 | 104 | } 105 | 106 | int scanhash_nist5(int thr_id, struct work *work, uint32_t max_nonce, uint64_t *hashes_done) 107 | { 108 | int i, m; 109 | uint32_t _ALIGN(128) hash32[8]; 110 | uint32_t _ALIGN(128) endiandata[20]; 111 | uint32_t *pdata = work->data; 112 | uint32_t *ptarget = work->target; 113 | const uint32_t first_nonce = pdata[19]; 114 | const uint32_t Htarg = ptarget[7]; 115 | uint32_t n = pdata[19] - 1; 116 | 117 | uint64_t htmax[] = { 118 | 0, 119 | 0xF, 120 | 0xFF, 121 | 0xFFF, 122 | 0xFFFF, 123 | 0x10000000 124 | }; 125 | uint32_t masks[] = { 126 | 0xFFFFFFFF, 127 | 0xFFFFFFF0, 128 | 0xFFFFFF00, 129 | 0xFFFFF000, 130 | 0xFFFF0000, 131 | 0 132 | }; 133 | 134 | // we need bigendian data... 135 | for (i=0; i < 19; i++) { 136 | be32enc(&endiandata[i], pdata[i]); 137 | } 138 | 139 | for (m=0; m < 6; m++) { 140 | if (Htarg <= htmax[m]) { 141 | uint32_t mask = masks[m]; 142 | do { 143 | pdata[19] = ++n; 144 | be32enc(&endiandata[19], n); 145 | nist5_hash(hash32, endiandata); 146 | 147 | if (!(n % 0x1000) && !thr_id) printf("."); 148 | if (!(hash32[7] & mask)) { 149 | printf("[%d]",thr_id); 150 | if (fulltest(hash32, ptarget)) { 151 | work_set_target_ratio(work, hash32); 152 | *hashes_done = n - first_nonce + 1; 153 | return 1; 154 | } 155 | } 156 | } while (n < max_nonce && !work_restart[thr_id].restart); 157 | // see blake.c if else to understand the loop on htmax => mask 158 | break; 159 | } 160 | } 161 | 162 | *hashes_done = n - first_nonce + 1; 163 | pdata[19] = n; 164 | return 0; 165 | } -------------------------------------------------------------------------------- /fpga_miner_aws/algo/phi.c: -------------------------------------------------------------------------------- 1 | /*- 2 | * Copyright 2017 tpruvot 3 | * All rights reserved. 4 | * 5 | * Redistribution and use in source and binary forms, with or without 6 | * modification, are permitted provided that the following conditions 7 | * are met: 8 | * 1. Redistributions of source code must retain the above copyright 9 | * notice, this list of conditions and the following disclaimer. 10 | * 2. Redistributions in binary form must reproduce the above copyright 11 | * notice, this list of conditions and the following disclaimer in the 12 | * documentation and/or other materials provided with the distribution. 13 | * 14 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 15 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 16 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 17 | * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 18 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 19 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 20 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 21 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 22 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 23 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 24 | * SUCH DAMAGE. 25 | * 26 | * This file was originally written by Colin Percival as part of the Tarsnap 27 | * online backup system. 28 | */ 29 | 30 | #include "miner.h" 31 | 32 | #include 33 | #include 34 | #include 35 | 36 | #include 37 | #include 38 | #include 39 | #include 40 | #include "sha3/sph_gost.h" 41 | #include 42 | 43 | static inline void be32enc_vect(uint32_t *dst, const uint32_t *src, uint32_t len) 44 | { 45 | uint32_t i; 46 | for (i = 0; i < len; i++) 47 | dst[i] = htobe32(src[i]); 48 | } 49 | 50 | void phi_midstate(void *state, const void *input) 51 | { 52 | uint64_t *s = (uint64_t *)state; 53 | 54 | sph_skein512_context ctx_skein; 55 | 56 | sph_skein512_init(&ctx_skein); 57 | sph_skein512(&ctx_skein, input, 80); 58 | 59 | s[0] = ctx_skein.h0; 60 | s[1] = ctx_skein.h1; 61 | s[2] = ctx_skein.h2; 62 | s[3] = ctx_skein.h3; 63 | s[4] = ctx_skein.h4; 64 | s[5] = ctx_skein.h5; 65 | s[6] = ctx_skein.h6; 66 | s[7] = ctx_skein.h7; 67 | } 68 | 69 | void phi_hash(void *state, const void *input) 70 | { 71 | sph_skein512_context ctx_skein; 72 | sph_jh512_context ctx_jh; 73 | sph_cubehash512_context ctx_cubehash; 74 | sph_fugue512_context ctx_fugue; 75 | sph_gost512_context ctx_gost; 76 | sph_echo512_context ctx_echo; 77 | 78 | uint32_t hashA[16]; 79 | 80 | sph_skein512_init(&ctx_skein); 81 | sph_skein512 (&ctx_skein, input, 80); 82 | sph_skein512_close (&ctx_skein, hashA); 83 | 84 | sph_jh512_init(&ctx_jh); 85 | sph_jh512 (&ctx_jh, hashA, 64); 86 | sph_jh512_close(&ctx_jh, hashA); 87 | 88 | sph_cubehash512_init(&ctx_cubehash); 89 | sph_cubehash512 (&ctx_cubehash, hashA, 64); 90 | sph_cubehash512_close(&ctx_cubehash, hashA); 91 | 92 | sph_fugue512_init(&ctx_fugue); 93 | sph_fugue512 (&ctx_fugue, hashA, 64); 94 | sph_fugue512_close(&ctx_fugue, hashA); 95 | 96 | sph_gost512_init(&ctx_gost); 97 | sph_gost512 (&ctx_gost, hashA, 64); 98 | sph_gost512_close(&ctx_gost, hashA); 99 | 100 | sph_echo512_init(&ctx_echo); 101 | sph_echo512 (&ctx_echo, hashA, 64); 102 | sph_echo512_close(&ctx_echo, hashA); 103 | 104 | memcpy(state, hashA, 32); 105 | } 106 | 107 | int scanhash_phi(int thr_id, struct work *work, uint32_t max_nonce, uint64_t *hashes_done) 108 | { 109 | int k; 110 | uint32_t _ALIGN(128) hash[8]; 111 | uint32_t _ALIGN(128) endiandata[20]; 112 | uint32_t *pdata = work->data; 113 | uint32_t *ptarget = work->target; 114 | 115 | const uint32_t Htarg = ptarget[7]; 116 | const uint32_t first_nonce = pdata[19]; 117 | uint32_t nonce = first_nonce; 118 | 119 | if (opt_benchmark) 120 | ptarget[7] = 0x00ff; 121 | 122 | for (k = 0; k < 19; k++) 123 | be32enc(&endiandata[k], pdata[k]); 124 | 125 | do { 126 | be32enc(&endiandata[19], nonce); 127 | phi_hash(hash, endiandata); 128 | 129 | if (hash[7] <= Htarg && fulltest(hash, ptarget)) { 130 | work_set_target_ratio(work, hash); 131 | pdata[19] = nonce; 132 | *hashes_done = pdata[19] - first_nonce; 133 | return 1; 134 | } 135 | nonce++; 136 | 137 | } while (nonce < max_nonce && !work_restart[thr_id].restart); 138 | 139 | pdata[19] = nonce; 140 | *hashes_done = pdata[19] - first_nonce + 1; 141 | return 0; 142 | } 143 | -------------------------------------------------------------------------------- /fpga_miner_aws/algo/poly.c: -------------------------------------------------------------------------------- 1 | /*- 2 | * Copyright 2017 tpruvot 3 | * All rights reserved. 4 | * 5 | * Redistribution and use in source and binary forms, with or without 6 | * modification, are permitted provided that the following conditions 7 | * are met: 8 | * 1. Redistributions of source code must retain the above copyright 9 | * notice, this list of conditions and the following disclaimer. 10 | * 2. Redistributions in binary form must reproduce the above copyright 11 | * notice, this list of conditions and the following disclaimer in the 12 | * documentation and/or other materials provided with the distribution. 13 | * 14 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 15 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 16 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 17 | * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 18 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 19 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 20 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 21 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 22 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 23 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 24 | * SUCH DAMAGE. 25 | * 26 | * This file was originally written by Colin Percival as part of the Tarsnap 27 | * online backup system. 28 | */ 29 | 30 | #include "miner.h" 31 | 32 | #include 33 | #include 34 | #include 35 | 36 | #include 37 | #include 38 | #include 39 | #include 40 | #include 41 | #include "sha3/sph_gost.h" 42 | 43 | static inline void be32enc_vect(uint32_t *dst, const uint32_t *src, uint32_t len) 44 | { 45 | uint32_t i; 46 | for (i = 0; i < len; i++) 47 | dst[i] = htobe32(src[i]); 48 | } 49 | 50 | void poly_midstate(void *state, const void *input) 51 | { 52 | uint64_t *s = (uint64_t *)state; 53 | 54 | sph_skein512_context ctx_skein; 55 | 56 | sph_skein512_init(&ctx_skein); 57 | sph_skein512(&ctx_skein, input, 80); 58 | 59 | s[0] = ctx_skein.h0; 60 | s[1] = ctx_skein.h1; 61 | s[2] = ctx_skein.h2; 62 | s[3] = ctx_skein.h3; 63 | s[4] = ctx_skein.h4; 64 | s[5] = ctx_skein.h5; 65 | s[6] = ctx_skein.h6; 66 | s[7] = ctx_skein.h7; 67 | } 68 | 69 | void poly_hash(void *state, const void *input) 70 | { 71 | sph_skein512_context ctx_skein; 72 | sph_shabal512_context ctx_shabal; 73 | sph_echo512_context ctx_echo; 74 | sph_luffa512_context ctx_luffa; 75 | sph_fugue512_context ctx_fugue; 76 | sph_gost512_context ctx_gost; 77 | 78 | uint32_t hashA[16]; 79 | 80 | sph_skein512_init(&ctx_skein); 81 | sph_skein512 (&ctx_skein, input, 80); 82 | sph_skein512_close (&ctx_skein, hashA); 83 | 84 | sph_shabal512_init(&ctx_shabal); 85 | sph_shabal512(&ctx_shabal, hashA, 64); 86 | sph_shabal512_close(&ctx_shabal, hashA); 87 | 88 | sph_echo512_init(&ctx_echo); 89 | sph_echo512 (&ctx_echo, hashA, 64); 90 | sph_echo512_close(&ctx_echo, hashA); 91 | 92 | sph_luffa512_init(&ctx_luffa); 93 | sph_luffa512(&ctx_luffa, hashA, 64); 94 | sph_luffa512_close(&ctx_luffa, hashA); 95 | 96 | sph_fugue512_init(&ctx_fugue); 97 | sph_fugue512 (&ctx_fugue, hashA, 64); 98 | sph_fugue512_close(&ctx_fugue, hashA); 99 | 100 | sph_gost512_init(&ctx_gost); 101 | sph_gost512 (&ctx_gost, hashA, 64); 102 | sph_gost512_close(&ctx_gost, hashA); 103 | 104 | memcpy(state, hashA, 32); 105 | } 106 | 107 | int scanhash_poly(int thr_id, struct work *work, uint32_t max_nonce, uint64_t *hashes_done) 108 | { 109 | int k; 110 | uint32_t _ALIGN(128) hash[8]; 111 | uint32_t _ALIGN(128) endiandata[20]; 112 | uint32_t *pdata = work->data; 113 | uint32_t *ptarget = work->target; 114 | 115 | const uint32_t Htarg = ptarget[7]; 116 | const uint32_t first_nonce = pdata[19]; 117 | uint32_t nonce = first_nonce; 118 | 119 | if (opt_benchmark) 120 | ptarget[7] = 0x00ff; 121 | 122 | for (k = 0; k < 19; k++) 123 | be32enc(&endiandata[k], pdata[k]); 124 | 125 | do { 126 | be32enc(&endiandata[19], nonce); 127 | poly_hash(hash, endiandata); 128 | 129 | if (hash[7] <= Htarg && fulltest(hash, ptarget)) { 130 | work_set_target_ratio(work, hash); 131 | pdata[19] = nonce; 132 | *hashes_done = pdata[19] - first_nonce; 133 | return 1; 134 | } 135 | nonce++; 136 | 137 | } while (nonce < max_nonce && !work_restart[thr_id].restart); 138 | 139 | pdata[19] = nonce; 140 | *hashes_done = pdata[19] - first_nonce + 1; 141 | return 0; 142 | } 143 | -------------------------------------------------------------------------------- /fpga_miner_aws/algo/skunk.c: -------------------------------------------------------------------------------- 1 | /*- 2 | * Copyright 2017 tpruvot 3 | * All rights reserved. 4 | * 5 | * Redistribution and use in source and binary forms, with or without 6 | * modification, are permitted provided that the following conditions 7 | * are met: 8 | * 1. Redistributions of source code must retain the above copyright 9 | * notice, this list of conditions and the following disclaimer. 10 | * 2. Redistributions in binary form must reproduce the above copyright 11 | * notice, this list of conditions and the following disclaimer in the 12 | * documentation and/or other materials provided with the distribution. 13 | * 14 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 15 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 16 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 17 | * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 18 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 19 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 20 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 21 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 22 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 23 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 24 | * SUCH DAMAGE. 25 | * 26 | * This file was originally written by Colin Percival as part of the Tarsnap 27 | * online backup system. 28 | */ 29 | 30 | #include "miner.h" 31 | 32 | #include 33 | #include 34 | #include 35 | 36 | #include 37 | #include 38 | #include 39 | #include 40 | 41 | /* Move init out of loop, so init once externally, 42 | and then use one single memcpy with that bigger memory block */ 43 | typedef struct { 44 | sph_skein512_context skein1; 45 | sph_cubehash512_context cubehash1; 46 | sph_fugue512_context fugue1; 47 | sph_gost512_context gost1; 48 | } Xhash_context_holder; 49 | 50 | static Xhash_context_holder base_contexts; 51 | 52 | static void init_Xhash_contexts() 53 | { 54 | sph_skein512_init(&base_contexts.skein1); 55 | sph_cubehash512_init(&base_contexts.cubehash1); 56 | sph_fugue512_init(&base_contexts.fugue1); 57 | sph_gost512_init(&base_contexts.gost1); 58 | } 59 | 60 | static inline void be32enc_vect(uint32_t *dst, const uint32_t *src, uint32_t len) 61 | { 62 | uint32_t i; 63 | for (i = 0; i < len; i++) 64 | dst[i] = htobe32(src[i]); 65 | } 66 | 67 | void skunk_midstate(void *state, const void *input) 68 | { 69 | uint64_t *s = (uint64_t *)state; 70 | 71 | init_Xhash_contexts(); 72 | Xhash_context_holder ctx; 73 | memcpy(&ctx, &base_contexts, sizeof(base_contexts)); 74 | 75 | sph_skein512(&ctx.skein1, input, 80); 76 | 77 | // Copy Midstate 78 | s[0] = ctx.skein1.h0; 79 | s[1] = ctx.skein1.h1; 80 | s[2] = ctx.skein1.h2; 81 | s[3] = ctx.skein1.h3; 82 | s[4] = ctx.skein1.h4; 83 | s[5] = ctx.skein1.h5; 84 | s[6] = ctx.skein1.h6; 85 | s[7] = ctx.skein1.h7; 86 | } 87 | 88 | void skunk_hash(void *state, const void *input) 89 | { 90 | init_Xhash_contexts(); 91 | 92 | Xhash_context_holder ctx; 93 | 94 | uint32_t hash[16]; 95 | 96 | memcpy(&ctx, &base_contexts, sizeof(base_contexts)); 97 | 98 | sph_skein512(&ctx.skein1, input, 80); 99 | sph_skein512_close(&ctx.skein1, hash); 100 | 101 | sph_cubehash512(&ctx.cubehash1, hash, 64); 102 | sph_cubehash512_close(&ctx.cubehash1, hash); 103 | 104 | sph_fugue512(&ctx.fugue1, hash, 64); 105 | sph_fugue512_close(&ctx.fugue1, hash); 106 | 107 | sph_gost512(&ctx.gost1, hash, 64); 108 | sph_gost512_close(&ctx.gost1, hash); 109 | 110 | memcpy(state, hash, 32); 111 | } 112 | 113 | int scanhash_skunk(int thr_id, struct work *work, uint32_t max_nonce, uint64_t *hashes_done) 114 | { 115 | int k; 116 | uint32_t _ALIGN(128) hash[8]; 117 | uint32_t _ALIGN(128) endiandata[20]; 118 | uint32_t *pdata = work->data; 119 | uint32_t *ptarget = work->target; 120 | 121 | const uint32_t Htarg = ptarget[7]; 122 | const uint32_t first_nonce = pdata[19]; 123 | uint32_t nonce = first_nonce; 124 | 125 | if (opt_benchmark) 126 | ptarget[7] = 0x00ff; 127 | 128 | for (k = 0; k < 19; k++) 129 | be32enc(&endiandata[k], pdata[k]); 130 | 131 | do { 132 | be32enc(&endiandata[19], nonce); 133 | skunk_hash(hash, endiandata); 134 | 135 | if (hash[7] <= Htarg && fulltest(hash, ptarget)) { 136 | work_set_target_ratio(work, hash); 137 | pdata[19] = nonce; 138 | *hashes_done = pdata[19] - first_nonce; 139 | return 1; 140 | } 141 | nonce++; 142 | 143 | } while (nonce < max_nonce && !work_restart[thr_id].restart); 144 | 145 | pdata[19] = nonce; 146 | *hashes_done = pdata[19] - first_nonce + 1; 147 | return 0; 148 | } 149 | -------------------------------------------------------------------------------- /fpga_miner_aws/algo/tribus.c: -------------------------------------------------------------------------------- 1 | /*- 2 | * Copyright 2017 tpruvot 3 | * All rights reserved. 4 | * 5 | * Redistribution and use in source and binary forms, with or without 6 | * modification, are permitted provided that the following conditions 7 | * are met: 8 | * 1. Redistributions of source code must retain the above copyright 9 | * notice, this list of conditions and the following disclaimer. 10 | * 2. Redistributions in binary form must reproduce the above copyright 11 | * notice, this list of conditions and the following disclaimer in the 12 | * documentation and/or other materials provided with the distribution. 13 | * 14 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 15 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 16 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 17 | * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 18 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 19 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 20 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 21 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 22 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 23 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 24 | * SUCH DAMAGE. 25 | * 26 | * This file was originally written by Colin Percival as part of the Tarsnap 27 | * online backup system. 28 | */ 29 | 30 | #include "miner.h" 31 | 32 | #include 33 | #include 34 | #include 35 | 36 | #include 37 | #include 38 | #include 39 | 40 | static inline void be32enc_vect(uint32_t *dst, const uint32_t *src, uint32_t len) 41 | { 42 | uint32_t i; 43 | for (i = 0; i < len; i++) 44 | dst[i] = htobe32(src[i]); 45 | } 46 | 47 | void tribus_midstate(void *state, const void *input) 48 | { 49 | int i; 50 | uint64_t m[16]; 51 | unsigned char *s = (unsigned char *)state; 52 | 53 | sph_jh512_context ctx_jh; 54 | 55 | sph_jh512_init(&ctx_jh); 56 | sph_jh512(&ctx_jh, input, 80); 57 | 58 | m[0] = ctx_jh.H.wide[0]; 59 | m[1] = ctx_jh.H.wide[1]; 60 | m[2] = ctx_jh.H.wide[2]; 61 | m[3] = ctx_jh.H.wide[3]; 62 | m[4] = ctx_jh.H.wide[4]; 63 | m[5] = ctx_jh.H.wide[5]; 64 | m[6] = ctx_jh.H.wide[6]; 65 | m[7] = ctx_jh.H.wide[7]; 66 | m[8] = ctx_jh.H.wide[8]; 67 | m[9] = ctx_jh.H.wide[9]; 68 | m[10] = ctx_jh.H.wide[10]; 69 | m[11] = ctx_jh.H.wide[11]; 70 | m[12] = ctx_jh.H.wide[12]; 71 | m[13] = ctx_jh.H.wide[13]; 72 | m[14] = ctx_jh.H.wide[14]; 73 | m[15] = ctx_jh.H.wide[15]; 74 | 75 | unsigned char *h = (unsigned char *)m; 76 | 77 | for (i = 0; i < 128; i++) { 78 | s[i] = h[127 - i]; 79 | } 80 | 81 | } 82 | 83 | void tribus_hash(void *state, const void *input) 84 | { 85 | sph_jh512_context ctx_jh; 86 | sph_keccak512_context ctx_keccak; 87 | sph_echo512_context ctx_echo; 88 | 89 | uint8_t hash[64]; 90 | 91 | sph_jh512_init(&ctx_jh); 92 | sph_jh512(&ctx_jh, input, 80); 93 | sph_jh512_close(&ctx_jh, (void*)hash); 94 | 95 | sph_keccak512_init(&ctx_keccak); 96 | sph_keccak512(&ctx_keccak, (const void*)hash, 64); 97 | sph_keccak512_close(&ctx_keccak, (void*)hash); 98 | 99 | sph_echo512_init(&ctx_echo); 100 | sph_echo512(&ctx_echo, (const void*)hash, 64); 101 | sph_echo512_close(&ctx_echo, (void*)hash); 102 | 103 | memcpy(state, hash, 32); 104 | 105 | } 106 | 107 | int scanhash_tribus(int thr_id, struct work *work, uint32_t max_nonce, uint64_t *hashes_done) 108 | { 109 | int i, m; 110 | uint32_t _ALIGN(128) hash32[8]; 111 | uint32_t _ALIGN(128) endiandata[20]; 112 | uint32_t *pdata = work->data; 113 | uint32_t *ptarget = work->target; 114 | const uint32_t first_nonce = pdata[19]; 115 | const uint32_t Htarg = ptarget[7]; 116 | uint32_t n = pdata[19] - 1; 117 | 118 | uint64_t htmax[] = { 119 | 0, 120 | 0xF, 121 | 0xFF, 122 | 0xFFF, 123 | 0xFFFF, 124 | 0x10000000 125 | }; 126 | uint32_t masks[] = { 127 | 0xFFFFFFFF, 128 | 0xFFFFFFF0, 129 | 0xFFFFFF00, 130 | 0xFFFFF000, 131 | 0xFFFF0000, 132 | 0 133 | }; 134 | 135 | // we need bigendian data... 136 | for (i=0; i < 19; i++) { 137 | be32enc(&endiandata[i], pdata[i]); 138 | } 139 | 140 | for (m=0; m < 6; m++) { 141 | if (Htarg <= htmax[m]) { 142 | uint32_t mask = masks[m]; 143 | do { 144 | pdata[19] = ++n; 145 | be32enc(&endiandata[19], n); 146 | tribus_hash(hash32, endiandata); 147 | if (!(n % 0x1000) && !thr_id) printf("."); 148 | if (!(hash32[7] & mask)) { 149 | printf("[%d]",thr_id); 150 | if (fulltest(hash32, ptarget)) { 151 | work_set_target_ratio(work, hash32); 152 | *hashes_done = n - first_nonce + 1; 153 | return 1; 154 | } 155 | } 156 | } while (n < max_nonce && !work_restart[thr_id].restart); 157 | // see blake.c if else to understand the loop on htmax => mask 158 | break; 159 | } 160 | } 161 | 162 | *hashes_done = n - first_nonce + 1; 163 | pdata[19] = n; 164 | return 0; 165 | } -------------------------------------------------------------------------------- /fpga_miner_aws/api/API.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mih0/FPGA_Mining_AWS/4c0324bade530e263196d335dd1fb1834232641b/fpga_miner_aws/api/API.class -------------------------------------------------------------------------------- /fpga_miner_aws/api/API.java: -------------------------------------------------------------------------------- 1 | import java.net.*; 2 | import java.io.*; 3 | 4 | class API 5 | { 6 | static private final int MAXRECEIVESIZE = 65535; 7 | 8 | static private Socket socket = null; 9 | 10 | private void closeAll() throws Exception 11 | { 12 | if (socket != null) 13 | { 14 | socket.close(); 15 | socket = null; 16 | } 17 | } 18 | 19 | public void display(String result) throws Exception 20 | { 21 | String value; 22 | String name; 23 | String[] sections = result.split("\\|", 0); 24 | 25 | for (int i = 0; i < sections.length; i++) 26 | { 27 | if (sections[i].trim().length() > 0) 28 | { 29 | String[] data = sections[i].split(",", 0); 30 | 31 | for (int j = 0; j < data.length; j++) 32 | { 33 | String[] nameval = data[j].split("=", 2); 34 | 35 | if (j == 0) 36 | { 37 | if (nameval.length > 1 38 | && Character.isDigit(nameval[1].charAt(0))) 39 | name = nameval[0] + nameval[1]; 40 | else 41 | name = nameval[0]; 42 | 43 | System.out.println("[" + name + "] =>"); 44 | System.out.println("("); 45 | } 46 | 47 | if (nameval.length > 1) 48 | { 49 | name = nameval[0]; 50 | value = nameval[1]; 51 | } 52 | else 53 | { 54 | name = "" + j; 55 | value = nameval[0]; 56 | } 57 | 58 | System.out.println(" ["+name+"] => "+value); 59 | } 60 | System.out.println(")"); 61 | } 62 | } 63 | } 64 | 65 | public void process(String cmd, InetAddress ip, int port) throws Exception 66 | { 67 | StringBuffer sb = new StringBuffer(); 68 | char buf[] = new char[MAXRECEIVESIZE]; 69 | int len = 0; 70 | 71 | System.out.println("Attempting to send '"+cmd+"' to "+ip.getHostAddress()+":"+port); 72 | 73 | try 74 | { 75 | socket = new Socket(ip, port); 76 | PrintStream ps = new PrintStream(socket.getOutputStream()); 77 | ps.print(cmd.toCharArray()); 78 | ps.flush(); 79 | 80 | InputStreamReader isr = new InputStreamReader(socket.getInputStream()); 81 | while (0x80085 > 0) 82 | { 83 | len = isr.read(buf, 0, MAXRECEIVESIZE); 84 | if (len < 1) 85 | break; 86 | sb.append(buf, 0, len); 87 | if (buf[len-1] == '\0') 88 | break; 89 | } 90 | 91 | closeAll(); 92 | } 93 | catch (IOException ioe) 94 | { 95 | System.err.println(ioe.toString()); 96 | closeAll(); 97 | return; 98 | } 99 | 100 | String result = sb.toString(); 101 | 102 | System.out.println("Answer='"+result+"'"); 103 | 104 | display(result); 105 | } 106 | 107 | public API(String command, String _ip, String _port) throws Exception 108 | { 109 | InetAddress ip; 110 | int port; 111 | 112 | try 113 | { 114 | ip = InetAddress.getByName(_ip); 115 | } 116 | catch (UnknownHostException uhe) 117 | { 118 | System.err.println("Unknown host " + _ip + ": " + uhe); 119 | return; 120 | } 121 | 122 | try 123 | { 124 | port = Integer.parseInt(_port); 125 | } 126 | catch (NumberFormatException nfe) 127 | { 128 | System.err.println("Invalid port " + _port + ": " + nfe); 129 | return; 130 | } 131 | 132 | process(command, ip, port); 133 | } 134 | 135 | public static void main(String[] params) throws Exception 136 | { 137 | String command = "summary"; 138 | String ip = "127.0.0.1"; 139 | String port = "4048"; 140 | 141 | if (params.length > 0 && params[0].trim().length() > 0) 142 | command = params[0].trim(); 143 | 144 | if (params.length > 1 && params[1].trim().length() > 0) 145 | ip = params[1].trim(); 146 | 147 | if (params.length > 2 && params[2].trim().length() > 0) 148 | port = params[2].trim(); 149 | 150 | new API(command, ip, port); 151 | } 152 | } -------------------------------------------------------------------------------- /fpga_miner_aws/api/index.php: -------------------------------------------------------------------------------- 1 | 'local-sample.php', 7 | //'EPSYTOUR'=>'epsytour.php', /* copy local.php file and edit target IP:PORT */ 8 | ); 9 | 10 | // 3 seconds max. 11 | set_time_limit(3); 12 | error_reporting(0); 13 | 14 | function getdataFromPears() 15 | { 16 | global $host, $configs; 17 | $data = array(); 18 | foreach ($configs as $name => $conf) { 19 | 20 | $json = file_get_contents($host.$conf); 21 | 22 | $data[$name] = json_decode($json, TRUE); 23 | } 24 | return $data; 25 | } 26 | 27 | function ignoreField($key) 28 | { 29 | $ignored = array('API','VER','GPU','CARD','GPUS','CPU'); 30 | return in_array($key, $ignored); 31 | } 32 | 33 | function translateField($key) 34 | { 35 | $intl = array(); 36 | $intl['NAME'] = 'Software'; 37 | $intl['VER'] = 'Version'; 38 | 39 | $intl['ALGO'] = 'Algorithm'; 40 | $intl['GPUS'] = 'GPUs'; 41 | $intl['CPUS'] = 'Threads'; 42 | $intl['KHS'] = 'Hash rate (kH/s)'; 43 | $intl['ACC'] = 'Accepted shares'; 44 | $intl['ACCMN'] = 'Accepted / mn'; 45 | $intl['REJ'] = 'Rejected'; 46 | $intl['DIFF'] = 'Difficulty'; 47 | $intl['UPTIME'] = 'Miner up time'; 48 | $intl['TS'] = 'Last update'; 49 | 50 | $intl['TEMP'] = 'T°c'; 51 | $intl['FAN'] = 'Fan %'; 52 | $intl['FREQ'] = 'Freq.'; 53 | $intl['PST'] = 'P-State'; 54 | 55 | if (isset($intl[$key])) 56 | return $intl[$key]; 57 | else 58 | return $key; 59 | } 60 | 61 | function translateValue($key,$val,$data=array()) 62 | { 63 | switch ($key) { 64 | case 'UPTIME': 65 | $min = floor(intval($val) / 60); 66 | $sec = intval($val) % 60; 67 | $val = "${min}mn${sec}s"; 68 | if ($min > 180) { 69 | $hrs = floor($min / 60); 70 | $min = $min % 60; 71 | $val = "${hrs}h${min}mn"; 72 | } 73 | break; 74 | case 'NAME': 75 | $val = $data['NAME'].' '.$data['VER']; 76 | break; 77 | case 'FREQ': 78 | $val = sprintf("%d MHz", round(floatval($val)/1000.0)); 79 | break; 80 | case 'TS': 81 | $val = strftime("%H:%M:%S", (int) $val); 82 | break; 83 | } 84 | return $val; 85 | } 86 | 87 | function displayData($data) 88 | { 89 | $htm = ''; 90 | $totals = array(); 91 | foreach ($data as $name => $stats) { 92 | $htm .= ''."\n"; 93 | $htm .= '\n"; 94 | if (!empty($stats)) { 95 | $summary = (array) $stats['summary']; 96 | foreach ($summary as $key=>$val) { 97 | if (!empty($val) && !ignoreField($key)) 98 | $htm .= ''. 99 | '\n"; 100 | } 101 | if (isset($summary['KHS'])) 102 | @ $totals[$summary['ALGO']] += floatval($summary['KHS']); 103 | foreach ($stats['threads'] as $g=>$gpu) { 104 | $card = isset($gpu['CARD']) ? $gpu['CARD'] : ''; 105 | $htm .= '\n"; 106 | foreach ($gpu as $key=>$val) { 107 | if (!empty($val) && !ignoreField($key)) 108 | $htm .= ''. 109 | '\n"; 110 | } 111 | } 112 | } 113 | $htm .= "
'.$name."
'.translateField($key).''.translateValue($key, $val, $summary)."
'.$g." $card
'.translateField($key).''.translateValue($key, $val)."
\n"; 114 | } 115 | // totals 116 | if (!empty($totals)) { 117 | $htm .= '

Total Hash rate

'."\n"; 118 | foreach ($totals as $algo => $hashrate) { 119 | $htm .= '
  • '.$algo.":$hashrate kH/s
  • \n"; 120 | } 121 | $htm .= '
    '; 122 | } 123 | return $htm; 124 | } 125 | 126 | $data = getdataFromPears(); 127 | 128 | ?> 129 | 130 | 131 | cpuminer rig api sample 132 | 133 | 134 | 182 | 183 | 184 | 187 | 188 |
    189 | 190 |
    191 | 192 | 195 | 196 | 197 | 198 | -------------------------------------------------------------------------------- /fpga_miner_aws/api/local-sample.php: -------------------------------------------------------------------------------- 1 | 0) { 27 | $err = socket_last_error($socket); 28 | echo "."; 29 | if ($timeout > 1 && ($err == 115 || $err == 114)) { 30 | $timeout--; 31 | usleep(50); 32 | $res = socket_connect($socket, API_HOST, $port); 33 | continue; 34 | } 35 | $error = socket_strerror($err); 36 | $msg = "socket connect($port) failed"; 37 | echo "ERR: $msg '$error'\n"; 38 | socket_close($socket); 39 | return NULL; 40 | } 41 | 42 | socket_set_block($socket); 43 | 44 | return $socket; 45 | } 46 | 47 | function readsockline($socket) 48 | { 49 | $line = ''; 50 | while (true) { 51 | $byte = socket_read($socket, 1); 52 | if ($byte === false || $byte === '') 53 | break; 54 | if ($byte === "\0") 55 | break; 56 | $line .= $byte; 57 | } 58 | return $line; 59 | } 60 | 61 | 62 | function request($cmd) 63 | { 64 | $socket = getsock(API_PORT); 65 | if ($socket == null) 66 | return NULL; 67 | 68 | socket_write($socket, $cmd, strlen($cmd)); 69 | $line = readsockline($socket); 70 | socket_close($socket); 71 | 72 | if (strlen($line) == 0) { 73 | echo "WARN: '$cmd' returned nothing\n"; 74 | return $line; 75 | } 76 | 77 | echo "$cmd returned '$line'\n"; 78 | 79 | $data = array(); 80 | 81 | $objs = explode('|', $line); 82 | foreach ($objs as $obj) 83 | { 84 | if (strlen($obj) > 0) 85 | { 86 | $items = explode(';', $obj); 87 | $item = $items[0]; 88 | $id = explode('=', $items[0], 2); 89 | if (count($id) == 1) 90 | $name = $id[0]; 91 | else 92 | $name = $id[0].$id[1]; 93 | 94 | if (strlen($name) == 0) 95 | $name = 'null'; 96 | 97 | if (isset($data[$name])) { 98 | $num = 1; 99 | while (isset($data[$name.$num])) 100 | $num++; 101 | $name .= $num; 102 | } 103 | 104 | $counter = 0; 105 | foreach ($items as $item) 106 | { 107 | $id = explode('=', $item, 2); 108 | if (count($id) == 2) 109 | $data[$name][$id[0]] = $id[1]; 110 | else 111 | $data[$name][$counter] = $id[0]; 112 | 113 | $counter++; 114 | } 115 | 116 | } 117 | } 118 | if ($cmd == 'summary') 119 | return array_pop($data); 120 | else 121 | return $data; 122 | } 123 | 124 | ob_start(); 125 | 126 | error_reporting(0); 127 | 128 | $summary = request('summary'); 129 | $threads = request('threads'); 130 | $histo = request('histo'); 131 | 132 | ob_end_clean(); /* swap to debug */ 133 | //echo ob_get_clean()."\n"; 134 | 135 | header("Content-Type: application/json"); 136 | echo json_encode(compact('summary', 'threads', 'histo'))."\n"; 137 | ?> 138 | -------------------------------------------------------------------------------- /fpga_miner_aws/api/websocket.htm: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | Simple WebSocket call sample 6 | 7 | 8 |
    9 | 68 | 69 | 70 | -------------------------------------------------------------------------------- /fpga_miner_aws/compat.h: -------------------------------------------------------------------------------- 1 | #ifndef __COMPAT_H__ 2 | #define __COMPAT_H__ 3 | 4 | #ifdef WIN32 5 | 6 | #include 7 | 8 | #define sleep(secs) Sleep((secs) * 1000) 9 | 10 | enum { 11 | PRIO_PROCESS = 0, 12 | }; 13 | 14 | extern int opt_priority; 15 | static __inline int setpriority(int which, int who, int prio) 16 | { 17 | switch (opt_priority) { 18 | case 5: 19 | prio = THREAD_PRIORITY_TIME_CRITICAL; 20 | break; 21 | case 4: 22 | prio = THREAD_PRIORITY_HIGHEST; 23 | break; 24 | case 3: 25 | prio = THREAD_PRIORITY_ABOVE_NORMAL; 26 | break; 27 | case 2: 28 | prio = THREAD_PRIORITY_NORMAL; 29 | break; 30 | case 1: 31 | prio = THREAD_PRIORITY_BELOW_NORMAL; 32 | break; 33 | case 0: 34 | default: 35 | prio = THREAD_PRIORITY_IDLE; 36 | } 37 | return -!SetThreadPriority(GetCurrentThread(), prio); 38 | } 39 | 40 | #ifdef _MSC_VER 41 | #define snprintf(...) _snprintf(__VA_ARGS__) 42 | #define strdup(...) _strdup(__VA_ARGS__) 43 | #define strncasecmp(x,y,z) _strnicmp(x,y,z) 44 | #define strcasecmp(x,y) _stricmp(x,y) 45 | #define __func__ __FUNCTION__ 46 | #define __thread __declspec(thread) 47 | #define _ALIGN(x) __declspec(align(x)) 48 | typedef int ssize_t; 49 | 50 | #include 51 | // This static var is made to be compatible with linux/mingw (no free on string result) 52 | // This is not thread safe but we only use that once on process start 53 | static char dirname_buffer[_MAX_PATH] = { 0 }; 54 | static __inline char * dirname(char *file) { 55 | char drive[_MAX_DRIVE] = { 0 }; 56 | char dir[_MAX_DIR] = { 0 }; 57 | char fname[_MAX_FNAME], ext[_MAX_EXT]; 58 | _splitpath_s(file, drive, _MAX_DRIVE, dir, _MAX_DIR, fname, _MAX_FNAME, ext, _MAX_EXT); 59 | if (dir && strlen(dir) && dir[strlen(dir)-1] == '\\') { 60 | dir[strlen(dir) - 1] = '\0'; 61 | } 62 | sprintf(dirname_buffer, "%s%s", drive, dir); 63 | return &dirname_buffer[0]; 64 | } 65 | #endif 66 | 67 | #endif /* WIN32 */ 68 | 69 | #ifndef _MSC_VER 70 | #define _ALIGN(x) __attribute__ ((aligned(x))) 71 | #endif 72 | 73 | #undef unlikely 74 | #undef likely 75 | #if defined(__GNUC__) && (__GNUC__ > 2) && defined(__OPTIMIZE__) 76 | #define unlikely(expr) (__builtin_expect(!!(expr), 0)) 77 | #define likely(expr) (__builtin_expect(!!(expr), 1)) 78 | #else 79 | #define unlikely(expr) (expr) 80 | #define likely(expr) (expr) 81 | #endif 82 | 83 | #ifndef WIN32 84 | #define MAX_PATH PATH_MAX 85 | #endif 86 | 87 | #endif /* __COMPAT_H__ */ 88 | -------------------------------------------------------------------------------- /fpga_miner_aws/compat/jansson/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | 2 | include_directories(${PROJECT_SOURCE_DIR}/compat/jansson) 3 | 4 | add_library(jansson dump.c 5 | hashtable.c 6 | load.c 7 | strbuffer.c 8 | utf.c 9 | value.c) -------------------------------------------------------------------------------- /fpga_miner_aws/compat/jansson/config.h: -------------------------------------------------------------------------------- 1 | /* config.h. Generated from config.h.in by configure. */ 2 | /* config.h.in. Generated from configure.ac by autoheader. */ 3 | 4 | /* Define to 1 if you have the header file. */ 5 | #define HAVE_DLFCN_H 1 6 | 7 | /* Define to 1 if you have the header file. */ 8 | #define HAVE_INTTYPES_H 1 9 | 10 | /* Define to 1 if you have the header file. */ 11 | #define HAVE_MEMORY_H 1 12 | 13 | /* Define to 1 if you have the header file. */ 14 | #define HAVE_STDINT_H 1 15 | 16 | /* Define to 1 if you have the header file. */ 17 | #define HAVE_STDLIB_H 1 18 | 19 | /* Define to 1 if you have the header file. */ 20 | #define HAVE_STRINGS_H 1 21 | 22 | /* Define to 1 if you have the header file. */ 23 | #define HAVE_STRING_H 1 24 | 25 | /* Define to 1 if you have the header file. */ 26 | #define HAVE_SYS_STAT_H 1 27 | 28 | /* Define to 1 if you have the header file. */ 29 | #define HAVE_SYS_TYPES_H 1 30 | 31 | /* Define to 1 if you have the header file. */ 32 | #define HAVE_UNISTD_H 1 33 | 34 | /* Define to the sub-directory in which libtool stores uninstalled libraries. 35 | */ 36 | #define LT_OBJDIR ".libs/" 37 | 38 | /* Name of package */ 39 | #define PACKAGE "jansson" 40 | 41 | /* Define to the address where bug reports for this package should be sent. */ 42 | #define PACKAGE_BUGREPORT "petri@digip.org" 43 | 44 | /* Define to the full name of this package. */ 45 | #define PACKAGE_NAME "jansson" 46 | 47 | /* Define to the full name and version of this package. */ 48 | #define PACKAGE_STRING "jansson 1.3" 49 | 50 | /* Define to the one symbol short name of this package. */ 51 | #define PACKAGE_TARNAME "jansson" 52 | 53 | /* Define to the home page for this package. */ 54 | #define PACKAGE_URL "" 55 | 56 | /* Define to the version of this package. */ 57 | #define PACKAGE_VERSION "1.3" 58 | 59 | /* Define to 1 if you have the ANSI C header files. */ 60 | #define STDC_HEADERS 1 61 | 62 | /* Version number of package */ 63 | #define VERSION "1.3" 64 | 65 | /* Define to `__inline__' or `__inline' if that's what the C compiler 66 | calls it, or to nothing if 'inline' is not supported under any name. */ 67 | #ifndef __cplusplus 68 | /* #undef inline */ 69 | #endif 70 | 71 | /* Define to the type of a signed integer type of width exactly 32 bits if 72 | such a type exists and the standard includes do not define it. */ 73 | /* #undef int32_t */ 74 | -------------------------------------------------------------------------------- /fpga_miner_aws/compat/jansson/hashtable.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2009, 2010 Petri Lehtinen 3 | * 4 | * This library is free software; you can redistribute it and/or modify 5 | * it under the terms of the MIT license. See LICENSE for details. 6 | */ 7 | 8 | #ifndef HASHTABLE_H 9 | #define HASHTABLE_H 10 | 11 | typedef unsigned int (*key_hash_fn)(const void *key); 12 | typedef int (*key_cmp_fn)(const void *key1, const void *key2); 13 | typedef void (*free_fn)(void *key); 14 | 15 | struct hashtable_list { 16 | struct hashtable_list *prev; 17 | struct hashtable_list *next; 18 | }; 19 | 20 | struct hashtable_pair { 21 | void *key; 22 | void *value; 23 | unsigned int hash; 24 | struct hashtable_list list; 25 | }; 26 | 27 | struct hashtable_bucket { 28 | struct hashtable_list *first; 29 | struct hashtable_list *last; 30 | }; 31 | 32 | typedef struct hashtable { 33 | unsigned int size; 34 | struct hashtable_bucket *buckets; 35 | unsigned int num_buckets; /* index to primes[] */ 36 | struct hashtable_list list; 37 | 38 | key_hash_fn hash_key; 39 | key_cmp_fn cmp_keys; /* returns non-zero for equal keys */ 40 | free_fn free_key; 41 | free_fn free_value; 42 | } hashtable_t; 43 | 44 | /** 45 | * hashtable_create - Create a hashtable object 46 | * 47 | * @hash_key: The key hashing function 48 | * @cmp_keys: The key compare function. Returns non-zero for equal and 49 | * zero for unequal unequal keys 50 | * @free_key: If non-NULL, called for a key that is no longer referenced. 51 | * @free_value: If non-NULL, called for a value that is no longer referenced. 52 | * 53 | * Returns a new hashtable object that should be freed with 54 | * hashtable_destroy when it's no longer used, or NULL on failure (out 55 | * of memory). 56 | */ 57 | hashtable_t *hashtable_create(key_hash_fn hash_key, key_cmp_fn cmp_keys, 58 | free_fn free_key, free_fn free_value); 59 | 60 | /** 61 | * hashtable_destroy - Destroy a hashtable object 62 | * 63 | * @hashtable: The hashtable 64 | * 65 | * Destroys a hashtable created with hashtable_create(). 66 | */ 67 | void hashtable_destroy(hashtable_t *hashtable); 68 | 69 | /** 70 | * hashtable_init - Initialize a hashtable object 71 | * 72 | * @hashtable: The (statically allocated) hashtable object 73 | * @hash_key: The key hashing function 74 | * @cmp_keys: The key compare function. Returns non-zero for equal and 75 | * zero for unequal unequal keys 76 | * @free_key: If non-NULL, called for a key that is no longer referenced. 77 | * @free_value: If non-NULL, called for a value that is no longer referenced. 78 | * 79 | * Initializes a statically allocated hashtable object. The object 80 | * should be cleared with hashtable_close when it's no longer used. 81 | * 82 | * Returns 0 on success, -1 on error (out of memory). 83 | */ 84 | int hashtable_init(hashtable_t *hashtable, 85 | key_hash_fn hash_key, key_cmp_fn cmp_keys, 86 | free_fn free_key, free_fn free_value); 87 | 88 | /** 89 | * hashtable_close - Release all resources used by a hashtable object 90 | * 91 | * @hashtable: The hashtable 92 | * 93 | * Destroys a statically allocated hashtable object. 94 | */ 95 | void hashtable_close(hashtable_t *hashtable); 96 | 97 | /** 98 | * hashtable_set - Add/modify value in hashtable 99 | * 100 | * @hashtable: The hashtable object 101 | * @key: The key 102 | * @value: The value 103 | * 104 | * If a value with the given key already exists, its value is replaced 105 | * with the new value. 106 | * 107 | * Key and value are "stealed" in the sense that hashtable frees them 108 | * automatically when they are no longer used. The freeing is 109 | * accomplished by calling free_key and free_value functions that were 110 | * supplied to hashtable_new. In case one or both of the free 111 | * functions is NULL, the corresponding item is not "stealed". 112 | * 113 | * Returns 0 on success, -1 on failure (out of memory). 114 | */ 115 | int hashtable_set(hashtable_t *hashtable, void *key, void *value); 116 | 117 | /** 118 | * hashtable_get - Get a value associated with a key 119 | * 120 | * @hashtable: The hashtable object 121 | * @key: The key 122 | * 123 | * Returns value if it is found, or NULL otherwise. 124 | */ 125 | void *hashtable_get(hashtable_t *hashtable, const void *key); 126 | 127 | /** 128 | * hashtable_del - Remove a value from the hashtable 129 | * 130 | * @hashtable: The hashtable object 131 | * @key: The key 132 | * 133 | * Returns 0 on success, or -1 if the key was not found. 134 | */ 135 | int hashtable_del(hashtable_t *hashtable, const void *key); 136 | 137 | /** 138 | * hashtable_clear - Clear hashtable 139 | * 140 | * @hashtable: The hashtable object 141 | * 142 | * Removes all items from the hashtable. 143 | */ 144 | void hashtable_clear(hashtable_t *hashtable); 145 | 146 | /** 147 | * hashtable_iter - Iterate over hashtable 148 | * 149 | * @hashtable: The hashtable object 150 | * 151 | * Returns an opaque iterator to the first element in the hashtable. 152 | * The iterator should be passed to hashtable_iter_* functions. 153 | * The hashtable items are not iterated over in any particular order. 154 | * 155 | * There's no need to free the iterator in any way. The iterator is 156 | * valid as long as the item that is referenced by the iterator is not 157 | * deleted. Other values may be added or deleted. In particular, 158 | * hashtable_iter_next() may be called on an iterator, and after that 159 | * the key/value pair pointed by the old iterator may be deleted. 160 | */ 161 | void *hashtable_iter(hashtable_t *hashtable); 162 | 163 | /** 164 | * hashtable_iter_at - Return an iterator at a specific key 165 | * 166 | * @hashtable: The hashtable object 167 | * @key: The key that the iterator should point to 168 | * 169 | * Like hashtable_iter() but returns an iterator pointing to a 170 | * specific key. 171 | */ 172 | void *hashtable_iter_at(hashtable_t *hashtable, const void *key); 173 | 174 | /** 175 | * hashtable_iter_next - Advance an iterator 176 | * 177 | * @hashtable: The hashtable object 178 | * @iter: The iterator 179 | * 180 | * Returns a new iterator pointing to the next element in the 181 | * hashtable or NULL if the whole hastable has been iterated over. 182 | */ 183 | void *hashtable_iter_next(hashtable_t *hashtable, void *iter); 184 | 185 | /** 186 | * hashtable_iter_key - Retrieve the key pointed by an iterator 187 | * 188 | * @iter: The iterator 189 | */ 190 | void *hashtable_iter_key(void *iter); 191 | 192 | /** 193 | * hashtable_iter_value - Retrieve the value pointed by an iterator 194 | * 195 | * @iter: The iterator 196 | */ 197 | void *hashtable_iter_value(void *iter); 198 | 199 | /** 200 | * hashtable_iter_set - Set the value pointed by an iterator 201 | * 202 | * @iter: The iterator 203 | * @value: The value to set 204 | */ 205 | void hashtable_iter_set(hashtable_t *hashtable, void *iter, void *value); 206 | 207 | #endif 208 | -------------------------------------------------------------------------------- /fpga_miner_aws/compat/jansson/jansson.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2009, 2010 Petri Lehtinen 3 | * 4 | * Jansson is free software; you can redistribute it and/or modify 5 | * it under the terms of the MIT license. See LICENSE for details. 6 | */ 7 | 8 | #ifndef JANSSON_H 9 | #define JANSSON_H 10 | 11 | #include 12 | 13 | #ifndef __cplusplus 14 | #define JSON_INLINE inline 15 | #else 16 | #define JSON_INLINE inline 17 | extern "C" { 18 | #endif 19 | 20 | /* types */ 21 | 22 | typedef enum { 23 | JSON_OBJECT, 24 | JSON_ARRAY, 25 | JSON_STRING, 26 | JSON_INTEGER, 27 | JSON_REAL, 28 | JSON_TRUE, 29 | JSON_FALSE, 30 | JSON_NULL 31 | } json_type; 32 | 33 | typedef struct { 34 | json_type type; 35 | unsigned long refcount; 36 | } json_t; 37 | 38 | #define json_typeof(json) ((json)->type) 39 | #define json_is_object(json) (json && json_typeof(json) == JSON_OBJECT) 40 | #define json_is_array(json) (json && json_typeof(json) == JSON_ARRAY) 41 | #define json_is_string(json) (json && json_typeof(json) == JSON_STRING) 42 | #define json_is_integer(json) (json && json_typeof(json) == JSON_INTEGER) 43 | #define json_is_real(json) (json && json_typeof(json) == JSON_REAL) 44 | #define json_is_number(json) (json_is_integer(json) || json_is_real(json)) 45 | #define json_is_true(json) (json && json_typeof(json) == JSON_TRUE) 46 | #define json_is_false(json) (json && json_typeof(json) == JSON_FALSE) 47 | #define json_is_boolean(json) (json_is_true(json) || json_is_false(json)) 48 | #define json_is_null(json) (json && json_typeof(json) == JSON_NULL) 49 | 50 | /* construction, destruction, reference counting */ 51 | 52 | json_t *json_object(void); 53 | json_t *json_array(void); 54 | json_t *json_string(const char *value); 55 | json_t *json_string_nocheck(const char *value); 56 | json_t *json_integer(int value); 57 | json_t *json_real(double value); 58 | json_t *json_true(void); 59 | json_t *json_false(void); 60 | json_t *json_null(void); 61 | 62 | static JSON_INLINE 63 | json_t *json_incref(json_t *json) 64 | { 65 | if(json && json->refcount != (unsigned int)-1) 66 | ++json->refcount; 67 | return json; 68 | } 69 | 70 | /* do not call json_delete directly */ 71 | void json_delete(json_t *json); 72 | 73 | static JSON_INLINE 74 | void json_decref(json_t *json) 75 | { 76 | if(json && json->refcount != (unsigned int)-1 && --json->refcount == 0) 77 | json_delete(json); 78 | } 79 | 80 | 81 | /* getters, setters, manipulation */ 82 | 83 | unsigned int json_object_size(const json_t *object); 84 | json_t *json_object_get(const json_t *object, const char *key); 85 | int json_object_set_new(json_t *object, const char *key, json_t *value); 86 | int json_object_set_new_nocheck(json_t *object, const char *key, json_t *value); 87 | int json_object_del(json_t *object, const char *key); 88 | int json_object_clear(json_t *object); 89 | int json_object_update(json_t *object, json_t *other); 90 | void *json_object_iter(json_t *object); 91 | void *json_object_iter_at(json_t *object, const char *key); 92 | void *json_object_iter_next(json_t *object, void *iter); 93 | const char *json_object_iter_key(void *iter); 94 | json_t *json_object_iter_value(void *iter); 95 | int json_object_iter_set_new(json_t *object, void *iter, json_t *value); 96 | 97 | static JSON_INLINE 98 | int json_object_set(json_t *object, const char *key, json_t *value) 99 | { 100 | return json_object_set_new(object, key, json_incref(value)); 101 | } 102 | 103 | static JSON_INLINE 104 | int json_object_set_nocheck(json_t *object, const char *key, json_t *value) 105 | { 106 | return json_object_set_new_nocheck(object, key, json_incref(value)); 107 | } 108 | 109 | static inline 110 | int json_object_iter_set(json_t *object, void *iter, json_t *value) 111 | { 112 | return json_object_iter_set_new(object, iter, json_incref(value)); 113 | } 114 | 115 | unsigned int json_array_size(const json_t *array); 116 | json_t *json_array_get(const json_t *array, unsigned int index); 117 | int json_array_set_new(json_t *array, unsigned int index, json_t *value); 118 | int json_array_append_new(json_t *array, json_t *value); 119 | int json_array_insert_new(json_t *array, unsigned int index, json_t *value); 120 | int json_array_remove(json_t *array, unsigned int index); 121 | int json_array_clear(json_t *array); 122 | int json_array_extend(json_t *array, json_t *other); 123 | 124 | static JSON_INLINE 125 | int json_array_set(json_t *array, unsigned int index, json_t *value) 126 | { 127 | return json_array_set_new(array, index, json_incref(value)); 128 | } 129 | 130 | static JSON_INLINE 131 | int json_array_append(json_t *array, json_t *value) 132 | { 133 | return json_array_append_new(array, json_incref(value)); 134 | } 135 | 136 | static JSON_INLINE 137 | int json_array_insert(json_t *array, unsigned int index, json_t *value) 138 | { 139 | return json_array_insert_new(array, index, json_incref(value)); 140 | } 141 | 142 | const char *json_string_value(const json_t *string); 143 | int json_integer_value(const json_t *integer); 144 | double json_real_value(const json_t *real); 145 | double json_number_value(const json_t *json); 146 | 147 | int json_string_set(json_t *string, const char *value); 148 | int json_string_set_nocheck(json_t *string, const char *value); 149 | int json_integer_set(json_t *integer, int value); 150 | int json_real_set(json_t *real, double value); 151 | 152 | 153 | /* equality */ 154 | 155 | int json_equal(json_t *value1, json_t *value2); 156 | 157 | 158 | /* copying */ 159 | 160 | json_t *json_copy(json_t *value); 161 | json_t *json_deep_copy(json_t *value); 162 | 163 | 164 | /* loading, printing */ 165 | 166 | #define JSON_ERROR_TEXT_LENGTH 160 167 | 168 | typedef struct { 169 | char text[JSON_ERROR_TEXT_LENGTH]; 170 | int line; 171 | } json_error_t; 172 | 173 | json_t *json_loads(const char *input, json_error_t *error); 174 | json_t *json_loadf(FILE *input, json_error_t *error); 175 | json_t *json_load_file(const char *path, json_error_t *error); 176 | 177 | #define JSON_INDENT(n) (n & 0xFF) 178 | #define JSON_COMPACT 0x100 179 | #define JSON_ENSURE_ASCII 0x200 180 | #define JSON_SORT_KEYS 0x400 181 | #define JSON_PRESERVE_ORDER 0x800 182 | 183 | char *json_dumps(const json_t *json, unsigned long flags); 184 | int json_dumpf(const json_t *json, FILE *output, unsigned long flags); 185 | int json_dump_file(const json_t *json, const char *path, unsigned long flags); 186 | 187 | #ifdef __cplusplus 188 | } 189 | #endif 190 | 191 | #endif 192 | -------------------------------------------------------------------------------- /fpga_miner_aws/compat/jansson/jansson_private.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2009, 2010 Petri Lehtinen 3 | * 4 | * Jansson is free software; you can redistribute it and/or modify 5 | * it under the terms of the MIT license. See LICENSE for details. 6 | */ 7 | 8 | #ifndef JANSSON_PRIVATE_H 9 | #define JANSSON_PRIVATE_H 10 | 11 | #include "jansson.h" 12 | #include "hashtable.h" 13 | 14 | #define container_of(ptr_, type_, member_) \ 15 | ((type_ *)((char *)ptr_ - (size_t)&((type_ *)0)->member_)) 16 | 17 | typedef struct { 18 | json_t json; 19 | hashtable_t hashtable; 20 | unsigned long serial; 21 | int visited; 22 | } json_object_t; 23 | 24 | typedef struct { 25 | json_t json; 26 | unsigned int size; 27 | unsigned int entries; 28 | json_t **table; 29 | int visited; 30 | } json_array_t; 31 | 32 | typedef struct { 33 | json_t json; 34 | char *value; 35 | } json_string_t; 36 | 37 | typedef struct { 38 | json_t json; 39 | double value; 40 | } json_real_t; 41 | 42 | typedef struct { 43 | json_t json; 44 | int value; 45 | } json_integer_t; 46 | 47 | #define json_to_object(json_) container_of(json_, json_object_t, json) 48 | #define json_to_array(json_) container_of(json_, json_array_t, json) 49 | #define json_to_string(json_) container_of(json_, json_string_t, json) 50 | #define json_to_real(json_) container_of(json_, json_real_t, json) 51 | #define json_to_integer(json_) container_of(json_, json_integer_t, json) 52 | 53 | typedef struct { 54 | unsigned long serial; 55 | char key[]; 56 | } object_key_t; 57 | 58 | const object_key_t *jsonp_object_iter_fullkey(void *iter); 59 | 60 | #endif 61 | -------------------------------------------------------------------------------- /fpga_miner_aws/compat/jansson/strbuffer.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2009, 2010 Petri Lehtinen 3 | * 4 | * Jansson is free software; you can redistribute it and/or modify 5 | * it under the terms of the MIT license. See LICENSE for details. 6 | */ 7 | 8 | #define _GNU_SOURCE 9 | #include 10 | #include 11 | #include "strbuffer.h" 12 | #include "util.h" 13 | 14 | #define STRBUFFER_MIN_SIZE 16 15 | #define STRBUFFER_FACTOR 2 16 | 17 | int strbuffer_init(strbuffer_t *strbuff) 18 | { 19 | strbuff->size = STRBUFFER_MIN_SIZE; 20 | strbuff->length = 0; 21 | 22 | strbuff->value = malloc(strbuff->size); 23 | if(!strbuff->value) 24 | return -1; 25 | 26 | /* initialize to empty */ 27 | strbuff->value[0] = '\0'; 28 | return 0; 29 | } 30 | 31 | void strbuffer_close(strbuffer_t *strbuff) 32 | { 33 | free(strbuff->value); 34 | strbuff->size = 0; 35 | strbuff->length = 0; 36 | strbuff->value = NULL; 37 | } 38 | 39 | void strbuffer_clear(strbuffer_t *strbuff) 40 | { 41 | strbuff->length = 0; 42 | strbuff->value[0] = '\0'; 43 | } 44 | 45 | const char *strbuffer_value(const strbuffer_t *strbuff) 46 | { 47 | return strbuff->value; 48 | } 49 | 50 | char *strbuffer_steal_value(strbuffer_t *strbuff) 51 | { 52 | char *result = strbuff->value; 53 | strbuffer_init(strbuff); 54 | return result; 55 | } 56 | 57 | int strbuffer_append(strbuffer_t *strbuff, const char *string) 58 | { 59 | return strbuffer_append_bytes(strbuff, string, strlen(string)); 60 | } 61 | 62 | int strbuffer_append_byte(strbuffer_t *strbuff, char byte) 63 | { 64 | return strbuffer_append_bytes(strbuff, &byte, 1); 65 | } 66 | 67 | int strbuffer_append_bytes(strbuffer_t *strbuff, const char *data, int size) 68 | { 69 | if(strbuff->length + size >= strbuff->size) 70 | { 71 | strbuff->size = max(strbuff->size * STRBUFFER_FACTOR, 72 | strbuff->length + size + 1); 73 | 74 | strbuff->value = realloc(strbuff->value, strbuff->size); 75 | if(!strbuff->value) 76 | return -1; 77 | } 78 | 79 | memcpy(strbuff->value + strbuff->length, data, size); 80 | strbuff->length += size; 81 | strbuff->value[strbuff->length] = '\0'; 82 | 83 | return 0; 84 | } 85 | 86 | char strbuffer_pop(strbuffer_t *strbuff) 87 | { 88 | if(strbuff->length > 0) { 89 | char c = strbuff->value[--strbuff->length]; 90 | strbuff->value[strbuff->length] = '\0'; 91 | return c; 92 | } 93 | else 94 | return '\0'; 95 | } 96 | -------------------------------------------------------------------------------- /fpga_miner_aws/compat/jansson/strbuffer.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2009, 2010 Petri Lehtinen 3 | * 4 | * Jansson is free software; you can redistribute it and/or modify 5 | * it under the terms of the MIT license. See LICENSE for details. 6 | */ 7 | 8 | #ifndef STRBUFFER_H 9 | #define STRBUFFER_H 10 | 11 | typedef struct { 12 | char *value; 13 | int length; /* bytes used */ 14 | int size; /* bytes allocated */ 15 | } strbuffer_t; 16 | 17 | int strbuffer_init(strbuffer_t *strbuff); 18 | void strbuffer_close(strbuffer_t *strbuff); 19 | 20 | void strbuffer_clear(strbuffer_t *strbuff); 21 | 22 | const char *strbuffer_value(const strbuffer_t *strbuff); 23 | char *strbuffer_steal_value(strbuffer_t *strbuff); 24 | 25 | int strbuffer_append(strbuffer_t *strbuff, const char *string); 26 | int strbuffer_append_byte(strbuffer_t *strbuff, char byte); 27 | int strbuffer_append_bytes(strbuffer_t *strbuff, const char *data, int size); 28 | 29 | char strbuffer_pop(strbuffer_t *strbuff); 30 | 31 | #endif 32 | -------------------------------------------------------------------------------- /fpga_miner_aws/compat/jansson/utf.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2009, 2010 Petri Lehtinen 3 | * 4 | * Jansson is free software; you can redistribute it and/or modify 5 | * it under the terms of the MIT license. See LICENSE for details. 6 | */ 7 | 8 | #include 9 | #include "utf.h" 10 | 11 | int utf8_encode(int32_t codepoint, char *buffer, int *size) 12 | { 13 | if(codepoint < 0) 14 | return -1; 15 | else if(codepoint < 0x80) 16 | { 17 | buffer[0] = (char)codepoint; 18 | *size = 1; 19 | } 20 | else if(codepoint < 0x800) 21 | { 22 | buffer[0] = 0xC0 + ((codepoint & 0x7C0) >> 6); 23 | buffer[1] = 0x80 + ((codepoint & 0x03F)); 24 | *size = 2; 25 | } 26 | else if(codepoint < 0x10000) 27 | { 28 | buffer[0] = 0xE0 + ((codepoint & 0xF000) >> 12); 29 | buffer[1] = 0x80 + ((codepoint & 0x0FC0) >> 6); 30 | buffer[2] = 0x80 + ((codepoint & 0x003F)); 31 | *size = 3; 32 | } 33 | else if(codepoint <= 0x10FFFF) 34 | { 35 | buffer[0] = 0xF0 + ((codepoint & 0x1C0000) >> 18); 36 | buffer[1] = 0x80 + ((codepoint & 0x03F000) >> 12); 37 | buffer[2] = 0x80 + ((codepoint & 0x000FC0) >> 6); 38 | buffer[3] = 0x80 + ((codepoint & 0x00003F)); 39 | *size = 4; 40 | } 41 | else 42 | return -1; 43 | 44 | return 0; 45 | } 46 | 47 | int utf8_check_first(char byte) 48 | { 49 | unsigned char u = (unsigned char)byte; 50 | 51 | if(u < 0x80) 52 | return 1; 53 | 54 | if(0x80 <= u && u <= 0xBF) { 55 | /* second, third or fourth byte of a multi-byte 56 | sequence, i.e. a "continuation byte" */ 57 | return 0; 58 | } 59 | else if(u == 0xC0 || u == 0xC1) { 60 | /* overlong encoding of an ASCII byte */ 61 | return 0; 62 | } 63 | else if(0xC2 <= u && u <= 0xDF) { 64 | /* 2-byte sequence */ 65 | return 2; 66 | } 67 | 68 | else if(0xE0 <= u && u <= 0xEF) { 69 | /* 3-byte sequence */ 70 | return 3; 71 | } 72 | else if(0xF0 <= u && u <= 0xF4) { 73 | /* 4-byte sequence */ 74 | return 4; 75 | } 76 | else { /* u >= 0xF5 */ 77 | /* Restricted (start of 4-, 5- or 6-byte sequence) or invalid 78 | UTF-8 */ 79 | return 0; 80 | } 81 | } 82 | 83 | int utf8_check_full(const char *buffer, int size, int32_t *codepoint) 84 | { 85 | int i; 86 | int32_t value = 0; 87 | unsigned char u = (unsigned char)buffer[0]; 88 | 89 | if(size == 2) 90 | { 91 | value = u & 0x1F; 92 | } 93 | else if(size == 3) 94 | { 95 | value = u & 0xF; 96 | } 97 | else if(size == 4) 98 | { 99 | value = u & 0x7; 100 | } 101 | else 102 | return 0; 103 | 104 | for(i = 1; i < size; i++) 105 | { 106 | u = (unsigned char)buffer[i]; 107 | 108 | if(u < 0x80 || u > 0xBF) { 109 | /* not a continuation byte */ 110 | return 0; 111 | } 112 | 113 | value = (value << 6) + (u & 0x3F); 114 | } 115 | 116 | if(value > 0x10FFFF) { 117 | /* not in Unicode range */ 118 | return 0; 119 | } 120 | 121 | else if(0xD800 <= value && value <= 0xDFFF) { 122 | /* invalid code point (UTF-16 surrogate halves) */ 123 | return 0; 124 | } 125 | 126 | else if((size == 2 && value < 0x80) || 127 | (size == 3 && value < 0x800) || 128 | (size == 4 && value < 0x10000)) { 129 | /* overlong encoding */ 130 | return 0; 131 | } 132 | 133 | if(codepoint) 134 | *codepoint = value; 135 | 136 | return 1; 137 | } 138 | 139 | const char *utf8_iterate(const char *buffer, int32_t *codepoint) 140 | { 141 | int count; 142 | int32_t value; 143 | 144 | if(!*buffer) 145 | return buffer; 146 | 147 | count = utf8_check_first(buffer[0]); 148 | if(count <= 0) 149 | return NULL; 150 | 151 | if(count == 1) 152 | value = (unsigned char)buffer[0]; 153 | else 154 | { 155 | if(!utf8_check_full(buffer, count, &value)) 156 | return NULL; 157 | } 158 | 159 | if(codepoint) 160 | *codepoint = value; 161 | 162 | return buffer + count; 163 | } 164 | 165 | int utf8_check_string(const char *string, int length) 166 | { 167 | int i; 168 | 169 | if(length == -1) 170 | length = strlen(string); 171 | 172 | for(i = 0; i < length; i++) 173 | { 174 | int count = utf8_check_first(string[i]); 175 | if(count == 0) 176 | return 0; 177 | else if(count > 1) 178 | { 179 | if(i + count > length) 180 | return 0; 181 | 182 | if(!utf8_check_full(&string[i], count, NULL)) 183 | return 0; 184 | 185 | i += count - 1; 186 | } 187 | } 188 | 189 | return 1; 190 | } 191 | -------------------------------------------------------------------------------- /fpga_miner_aws/compat/jansson/utf.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2009, 2010 Petri Lehtinen 3 | * 4 | * Jansson is free software; you can redistribute it and/or modify 5 | * it under the terms of the MIT license. See LICENSE for details. 6 | */ 7 | 8 | #ifndef UTF_H 9 | #define UTF_H 10 | 11 | #include 12 | 13 | #ifdef HAVE_INTTYPES_H 14 | /* inttypes.h includes stdint.h in a standard environment, so there's 15 | no need to include stdint.h separately. If inttypes.h doesn't define 16 | int32_t, it's defined in config.h. */ 17 | #include 18 | #endif 19 | 20 | int utf8_encode(int codepoint, char *buffer, int *size); 21 | 22 | int utf8_check_first(char byte); 23 | int utf8_check_full(const char *buffer, int size, int32_t *codepoint); 24 | const char *utf8_iterate(const char *buffer, int32_t *codepoint); 25 | 26 | int utf8_check_string(const char *string, int length); 27 | 28 | #endif 29 | -------------------------------------------------------------------------------- /fpga_miner_aws/compat/jansson/util.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2009, 2010 Petri Lehtinen 3 | * 4 | * Jansson is free software; you can redistribute it and/or modify 5 | * it under the terms of the MIT license. See LICENSE for details. 6 | */ 7 | 8 | #ifndef UTIL_H 9 | #define UTIL_H 10 | 11 | #define max(a, b) ((a) > (b) ? (a) : (b)) 12 | 13 | #endif 14 | -------------------------------------------------------------------------------- /fpga_miner_aws/compat/winansi.c: -------------------------------------------------------------------------------- 1 | /** 2 | * Old Git implementation of windows terminal colors (2009) 3 | * before use of a threaded wrapper. 4 | */ 5 | 6 | #undef NOGDI 7 | #include 8 | #include 9 | #include 10 | #include 11 | #include 12 | #include 13 | 14 | #include "winansi.h" 15 | /* 16 | * Copyright 2008 Peter Harris 17 | */ 18 | 19 | /* 20 | Functions to be wrapped: 21 | */ 22 | #undef printf 23 | #undef fprintf 24 | #undef fputs 25 | #undef vfprintf 26 | /* TODO: write */ 27 | 28 | /* 29 | ANSI codes used by git: m, K 30 | 31 | This file is git-specific. Therefore, this file does not attempt 32 | to implement any codes that are not used by git. 33 | */ 34 | 35 | static HANDLE console; 36 | static WORD plain_attr; 37 | static WORD attr; 38 | static int negative; 39 | 40 | static void init(void) 41 | { 42 | CONSOLE_SCREEN_BUFFER_INFO sbi; 43 | 44 | static int initialized = 0; 45 | if (initialized) 46 | return; 47 | 48 | console = GetStdHandle(STD_OUTPUT_HANDLE); 49 | if (console == INVALID_HANDLE_VALUE) 50 | console = NULL; 51 | 52 | if (!console) 53 | return; 54 | 55 | GetConsoleScreenBufferInfo(console, &sbi); 56 | attr = plain_attr = sbi.wAttributes; 57 | negative = 0; 58 | 59 | initialized = 1; 60 | } 61 | 62 | static int write_console(const char *str, int len) 63 | { 64 | /* convert utf-8 to utf-16, write directly to console */ 65 | int wlen = MultiByteToWideChar(CP_UTF8, 0, str, len, NULL, 0); 66 | wchar_t *wbuf = (wchar_t *)alloca(wlen * sizeof(wchar_t)); 67 | MultiByteToWideChar(CP_UTF8, 0, str, len, wbuf, wlen); 68 | 69 | WriteConsoleW(console, wbuf, wlen, NULL, NULL); 70 | 71 | /* return original (utf-8 encoded) length */ 72 | return len; 73 | } 74 | 75 | #define FOREGROUND_ALL (FOREGROUND_RED | FOREGROUND_GREEN | FOREGROUND_BLUE) 76 | #define BACKGROUND_ALL (BACKGROUND_RED | BACKGROUND_GREEN | BACKGROUND_BLUE) 77 | 78 | static void set_console_attr(void) 79 | { 80 | WORD attributes = attr; 81 | if (negative) { 82 | attributes &= ~FOREGROUND_ALL; 83 | attributes &= ~BACKGROUND_ALL; 84 | 85 | /* This could probably use a bitmask 86 | instead of a series of ifs */ 87 | if (attr & FOREGROUND_RED) 88 | attributes |= BACKGROUND_RED; 89 | if (attr & FOREGROUND_GREEN) 90 | attributes |= BACKGROUND_GREEN; 91 | if (attr & FOREGROUND_BLUE) 92 | attributes |= BACKGROUND_BLUE; 93 | 94 | if (attr & BACKGROUND_RED) 95 | attributes |= FOREGROUND_RED; 96 | if (attr & BACKGROUND_GREEN) 97 | attributes |= FOREGROUND_GREEN; 98 | if (attr & BACKGROUND_BLUE) 99 | attributes |= FOREGROUND_BLUE; 100 | } 101 | SetConsoleTextAttribute(console, attributes); 102 | } 103 | 104 | static void erase_in_line(void) 105 | { 106 | CONSOLE_SCREEN_BUFFER_INFO sbi; 107 | DWORD dummy; /* Needed for Windows 7 (or Vista) regression */ 108 | 109 | if (!console) 110 | return; 111 | 112 | GetConsoleScreenBufferInfo(console, &sbi); 113 | FillConsoleOutputCharacterA(console, ' ', 114 | sbi.dwSize.X - sbi.dwCursorPosition.X, sbi.dwCursorPosition, 115 | &dummy); 116 | } 117 | 118 | 119 | static const char *set_attr(const char *str) 120 | { 121 | const char *func; 122 | size_t len = strspn(str, "0123456789;"); 123 | func = str + len; 124 | 125 | switch (*func) { 126 | case 'm': 127 | do { 128 | long val = strtol(str, (char **)&str, 10); 129 | switch (val) { 130 | case 0: /* reset */ 131 | attr = plain_attr; 132 | negative = 0; 133 | break; 134 | case 1: /* bold */ 135 | attr |= FOREGROUND_INTENSITY; 136 | break; 137 | case 2: /* faint */ 138 | case 22: /* normal */ 139 | attr &= ~FOREGROUND_INTENSITY; 140 | break; 141 | case 3: /* italic */ 142 | /* Unsupported */ 143 | break; 144 | case 4: /* underline */ 145 | case 21: /* double underline */ 146 | /* Wikipedia says this flag does nothing */ 147 | /* Furthermore, mingw doesn't define this flag 148 | attr |= COMMON_LVB_UNDERSCORE; */ 149 | break; 150 | case 24: /* no underline */ 151 | /* attr &= ~COMMON_LVB_UNDERSCORE; */ 152 | break; 153 | case 5: /* slow blink */ 154 | case 6: /* fast blink */ 155 | /* We don't have blink, but we do have 156 | background intensity */ 157 | attr |= BACKGROUND_INTENSITY; 158 | break; 159 | case 25: /* no blink */ 160 | attr &= ~BACKGROUND_INTENSITY; 161 | break; 162 | case 7: /* negative */ 163 | negative = 1; 164 | break; 165 | case 27: /* positive */ 166 | negative = 0; 167 | break; 168 | case 8: /* conceal */ 169 | case 28: /* reveal */ 170 | /* Unsupported */ 171 | break; 172 | case 30: /* Black */ 173 | attr &= ~FOREGROUND_ALL; 174 | break; 175 | case 31: /* Red */ 176 | attr &= ~FOREGROUND_ALL; 177 | attr |= FOREGROUND_RED; 178 | break; 179 | case 32: /* Green */ 180 | attr &= ~FOREGROUND_ALL; 181 | attr |= FOREGROUND_GREEN; 182 | break; 183 | case 33: /* Yellow */ 184 | attr &= ~FOREGROUND_ALL; 185 | attr |= FOREGROUND_RED | FOREGROUND_GREEN; 186 | break; 187 | case 34: /* Blue */ 188 | attr &= ~FOREGROUND_ALL; 189 | attr |= FOREGROUND_BLUE; 190 | break; 191 | case 35: /* Magenta */ 192 | attr &= ~FOREGROUND_ALL; 193 | attr |= FOREGROUND_RED | FOREGROUND_BLUE; 194 | break; 195 | case 36: /* Cyan */ 196 | attr &= ~FOREGROUND_ALL; 197 | attr |= FOREGROUND_GREEN | FOREGROUND_BLUE; 198 | break; 199 | case 37: /* White */ 200 | attr |= FOREGROUND_RED | 201 | FOREGROUND_GREEN | 202 | FOREGROUND_BLUE; 203 | break; 204 | case 38: /* Unknown */ 205 | break; 206 | case 39: /* reset */ 207 | attr &= ~FOREGROUND_ALL; 208 | attr |= (plain_attr & FOREGROUND_ALL); 209 | break; 210 | case 40: /* Black */ 211 | attr &= ~BACKGROUND_ALL; 212 | break; 213 | case 41: /* Red */ 214 | attr &= ~BACKGROUND_ALL; 215 | attr |= BACKGROUND_RED; 216 | break; 217 | case 42: /* Green */ 218 | attr &= ~BACKGROUND_ALL; 219 | attr |= BACKGROUND_GREEN; 220 | break; 221 | case 43: /* Yellow */ 222 | attr &= ~BACKGROUND_ALL; 223 | attr |= BACKGROUND_RED | BACKGROUND_GREEN; 224 | break; 225 | case 44: /* Blue */ 226 | attr &= ~BACKGROUND_ALL; 227 | attr |= BACKGROUND_BLUE; 228 | break; 229 | case 45: /* Magenta */ 230 | attr &= ~BACKGROUND_ALL; 231 | attr |= BACKGROUND_RED | BACKGROUND_BLUE; 232 | break; 233 | case 46: /* Cyan */ 234 | attr &= ~BACKGROUND_ALL; 235 | attr |= BACKGROUND_GREEN | BACKGROUND_BLUE; 236 | break; 237 | case 47: /* White */ 238 | attr |= BACKGROUND_RED | 239 | BACKGROUND_GREEN | 240 | BACKGROUND_BLUE; 241 | break; 242 | case 48: /* Unknown */ 243 | break; 244 | case 49: /* reset */ 245 | attr &= ~BACKGROUND_ALL; 246 | attr |= (plain_attr & BACKGROUND_ALL); 247 | break; 248 | default: 249 | /* Unsupported code */ 250 | break; 251 | } 252 | str++; 253 | } while (*(str - 1) == ';'); 254 | 255 | set_console_attr(); 256 | break; 257 | case 'K': 258 | erase_in_line(); 259 | break; 260 | default: 261 | /* Unsupported code */ 262 | break; 263 | } 264 | 265 | return func + 1; 266 | } 267 | 268 | static int ansi_emulate(const char *str, FILE *stream) 269 | { 270 | int rv = 0; 271 | const char *pos = str; 272 | 273 | fflush(stream); 274 | 275 | while (*pos) { 276 | pos = strstr(str, "\033["); 277 | if (pos) { 278 | int len = (int) (pos - str); 279 | 280 | if (len) { 281 | int out_len = write_console(str, len); 282 | rv += out_len; 283 | if (out_len < len) 284 | return rv; 285 | } 286 | 287 | str = pos + 2; 288 | rv += 2; 289 | 290 | pos = set_attr(str); 291 | rv += (int) (pos - str); 292 | str = pos; 293 | } 294 | else { 295 | int len = (int) strlen(str); 296 | rv += write_console(str, len); 297 | return rv; 298 | } 299 | } 300 | return rv; 301 | } 302 | 303 | int winansi_fputs(const char *str, FILE *stream) 304 | { 305 | int rv; 306 | 307 | if (!isatty(fileno(stream))) 308 | return fputs(str, stream); 309 | 310 | init(); 311 | 312 | if (!console) 313 | return fputs(str, stream); 314 | 315 | rv = ansi_emulate(str, stream); 316 | 317 | if (rv >= 0) 318 | return 0; 319 | else 320 | return EOF; 321 | } 322 | 323 | int winansi_vfprintf(FILE *stream, const char *format, va_list list) 324 | { 325 | int len, rv; 326 | char small_buf[256] = { 0 }; 327 | char *buf = small_buf; 328 | va_list cp; 329 | 330 | if (!isatty(fileno(stream))) 331 | goto abort; 332 | 333 | init(); 334 | 335 | if (!console) 336 | goto abort; 337 | 338 | va_copy(cp, list); 339 | len = vsnprintf(small_buf, sizeof(small_buf), format, cp); 340 | #ifdef WIN32 341 | /* bug on long strings without that */ 342 | if (len == -1) 343 | len = _vscprintf(format, cp); 344 | #endif 345 | va_end(cp); 346 | 347 | if (len > sizeof(small_buf) - 1) { 348 | buf = malloc(len + 1); 349 | if (!buf) 350 | goto abort; 351 | 352 | len = vsnprintf(buf, len + 1, format, list); 353 | #ifdef WIN32 354 | if (len == -1) 355 | len = _vscprintf(format, list); 356 | #endif 357 | } 358 | 359 | rv = ansi_emulate(buf, stream); 360 | 361 | if (buf != small_buf) 362 | free(buf); 363 | return rv; 364 | 365 | abort: 366 | rv = vfprintf(stream, format, list); 367 | return rv; 368 | } 369 | 370 | int winansi_fprintf(FILE *stream, const char *format, ...) 371 | { 372 | va_list list; 373 | int rv; 374 | 375 | va_start(list, format); 376 | rv = winansi_vfprintf(stream, format, list); 377 | va_end(list); 378 | 379 | return rv; 380 | } 381 | 382 | int winansi_printf(const char *format, ...) 383 | { 384 | va_list list; 385 | int rv; 386 | 387 | va_start(list, format); 388 | rv = winansi_vfprintf(stdout, format, list); 389 | va_end(list); 390 | 391 | return rv; 392 | } -------------------------------------------------------------------------------- /fpga_miner_aws/compat/winansi.h: -------------------------------------------------------------------------------- 1 | /* 2 | * ANSI emulation wrappers 3 | */ 4 | #ifdef WIN32 5 | #include 6 | #include 7 | #include 8 | 9 | #define isatty(fd) _isatty(fd) 10 | //#define fileno(fd) _fileno(fd) 11 | 12 | #ifdef __cplusplus 13 | extern "C" { 14 | #endif 15 | int winansi_fputs(const char *str, FILE *stream); 16 | int winansi_printf(const char *format, ...); 17 | int winansi_fprintf(FILE *stream, const char *format, ...); 18 | int winansi_vfprintf(FILE *stream, const char *format, va_list list); 19 | #ifdef __cplusplus 20 | } 21 | #endif 22 | 23 | #undef fputs 24 | #undef fprintf 25 | #undef vfprintf 26 | 27 | #define fputs winansi_fputs 28 | #define printf winansi_printf 29 | #define fprintf winansi_fprintf 30 | #define vfprintf winansi_vfprintf 31 | 32 | #endif -------------------------------------------------------------------------------- /fpga_miner_aws/elist.h: -------------------------------------------------------------------------------- 1 | #ifndef _LINUX_LIST_H 2 | #define _LINUX_LIST_H 3 | 4 | /* 5 | * Simple doubly linked list implementation. 6 | * 7 | * Some of the internal functions ("__xxx") are useful when 8 | * manipulating whole lists rather than single entries, as 9 | * sometimes we already know the next/prev entries and we can 10 | * generate better code by using them directly rather than 11 | * using the generic single-entry routines. 12 | */ 13 | 14 | struct list_head { 15 | struct list_head *next, *prev; 16 | }; 17 | 18 | #define LIST_HEAD_INIT(name) { &(name), &(name) } 19 | 20 | #define LIST_HEAD(name) \ 21 | struct list_head name = LIST_HEAD_INIT(name) 22 | 23 | #define INIT_LIST_HEAD(ptr) do { \ 24 | (ptr)->next = (ptr); (ptr)->prev = (ptr); \ 25 | } while (0) 26 | 27 | /* 28 | * Insert a new entry between two known consecutive entries. 29 | * 30 | * This is only for internal list manipulation where we know 31 | * the prev/next entries already! 32 | */ 33 | static inline void __list_add(struct list_head *nlh, 34 | struct list_head *prev, 35 | struct list_head *next) 36 | { 37 | next->prev = nlh; 38 | nlh->next = next; 39 | nlh->prev = prev; 40 | prev->next = nlh; 41 | } 42 | 43 | /** 44 | * list_add - add a new entry 45 | * @new: new entry to be added 46 | * @head: list head to add it after 47 | * 48 | * Insert a new entry after the specified head. 49 | * This is good for implementing stacks. 50 | */ 51 | static inline void list_add(struct list_head *nlh, struct list_head *head) 52 | { 53 | __list_add(nlh, head, head->next); 54 | } 55 | 56 | /** 57 | * list_add_tail - add a new entry 58 | * @new: new entry to be added 59 | * @head: list head to add it before 60 | * 61 | * Insert a new entry before the specified head. 62 | * This is useful for implementing queues. 63 | */ 64 | static inline void list_add_tail(struct list_head *nlh, struct list_head *head) 65 | { 66 | __list_add(nlh, head->prev, head); 67 | } 68 | 69 | /* 70 | * Delete a list entry by making the prev/next entries 71 | * point to each other. 72 | * 73 | * This is only for internal list manipulation where we know 74 | * the prev/next entries already! 75 | */ 76 | static inline void __list_del(struct list_head *prev, struct list_head *next) 77 | { 78 | next->prev = prev; 79 | prev->next = next; 80 | } 81 | 82 | /** 83 | * list_del - deletes entry from list. 84 | * @entry: the element to delete from the list. 85 | * Note: list_empty on entry does not return true after this, the entry is in an undefined state. 86 | */ 87 | static inline void list_del(struct list_head *entry) 88 | { 89 | __list_del(entry->prev, entry->next); 90 | entry->next = NULL; 91 | entry->prev = NULL; 92 | } 93 | 94 | /** 95 | * list_del_init - deletes entry from list and reinitialize it. 96 | * @entry: the element to delete from the list. 97 | */ 98 | static inline void list_del_init(struct list_head *entry) 99 | { 100 | __list_del(entry->prev, entry->next); 101 | INIT_LIST_HEAD(entry); 102 | } 103 | 104 | /** 105 | * list_move - delete from one list and add as another's head 106 | * @list: the entry to move 107 | * @head: the head that will precede our entry 108 | */ 109 | static inline void list_move(struct list_head *list, struct list_head *head) 110 | { 111 | __list_del(list->prev, list->next); 112 | list_add(list, head); 113 | } 114 | 115 | /** 116 | * list_move_tail - delete from one list and add as another's tail 117 | * @list: the entry to move 118 | * @head: the head that will follow our entry 119 | */ 120 | static inline void list_move_tail(struct list_head *list, 121 | struct list_head *head) 122 | { 123 | __list_del(list->prev, list->next); 124 | list_add_tail(list, head); 125 | } 126 | 127 | /** 128 | * list_empty - tests whether a list is empty 129 | * @head: the list to test. 130 | */ 131 | static inline int list_empty(struct list_head *head) 132 | { 133 | return head->next == head; 134 | } 135 | 136 | static inline void __list_splice(struct list_head *list, 137 | struct list_head *head) 138 | { 139 | struct list_head *first = list->next; 140 | struct list_head *last = list->prev; 141 | struct list_head *at = head->next; 142 | 143 | first->prev = head; 144 | head->next = first; 145 | 146 | last->next = at; 147 | at->prev = last; 148 | } 149 | 150 | /** 151 | * list_splice - join two lists 152 | * @list: the new list to add. 153 | * @head: the place to add it in the first list. 154 | */ 155 | static inline void list_splice(struct list_head *list, struct list_head *head) 156 | { 157 | if (!list_empty(list)) 158 | __list_splice(list, head); 159 | } 160 | 161 | /** 162 | * list_splice_init - join two lists and reinitialise the emptied list. 163 | * @list: the new list to add. 164 | * @head: the place to add it in the first list. 165 | * 166 | * The list at @list is reinitialised 167 | */ 168 | static inline void list_splice_init(struct list_head *list, 169 | struct list_head *head) 170 | { 171 | if (!list_empty(list)) { 172 | __list_splice(list, head); 173 | INIT_LIST_HEAD(list); 174 | } 175 | } 176 | 177 | /** 178 | * list_entry - get the struct for this entry 179 | * @ptr: the &struct list_head pointer. 180 | * @type: the type of the struct this is embedded in. 181 | * @member: the name of the list_struct within the struct. 182 | */ 183 | #define list_entry(ptr, type, member) \ 184 | ((type *)((char *)(ptr)-(unsigned long)(&((type *)0)->member))) 185 | 186 | /** 187 | * list_for_each - iterate over a list 188 | * @pos: the &struct list_head to use as a loop counter. 189 | * @head: the head for your list. 190 | */ 191 | #define list_for_each(pos, head) \ 192 | for (pos = (head)->next; pos != (head); \ 193 | pos = pos->next) 194 | /** 195 | * list_for_each_prev - iterate over a list backwards 196 | * @pos: the &struct list_head to use as a loop counter. 197 | * @head: the head for your list. 198 | */ 199 | #define list_for_each_prev(pos, head) \ 200 | for (pos = (head)->prev; pos != (head); \ 201 | pos = pos->prev) 202 | 203 | /** 204 | * list_for_each_safe - iterate over a list safe against removal of list entry 205 | * @pos: the &struct list_head to use as a loop counter. 206 | * @n: another &struct list_head to use as temporary storage 207 | * @head: the head for your list. 208 | */ 209 | #define list_for_each_safe(pos, n, head) \ 210 | for (pos = (head)->next, n = pos->next; pos != (head); \ 211 | pos = n, n = pos->next) 212 | 213 | /** 214 | * list_for_each_entry - iterate over list of given type 215 | * @pos: the type * to use as a loop counter. 216 | * @head: the head for your list. 217 | * @member: the name of the list_struct within the struct. 218 | * @type: the type of the struct. 219 | */ 220 | #define list_for_each_entry(pos, head, member, type) \ 221 | for (pos = list_entry((head)->next, type, member); \ 222 | &pos->member != (head); \ 223 | pos = list_entry(pos->member.next, type, member)) 224 | 225 | /** 226 | * list_for_each_entry_safe - iterate over list of given type safe against removal of list entry 227 | * @pos: the type * to use as a loop counter. 228 | * @n: another type * to use as temporary storage 229 | * @head: the head for your list. 230 | * @member: the name of the list_struct within the struct. 231 | * @type: the type of the struct. 232 | */ 233 | #define list_for_each_entry_safe(pos, n, head, member, type) \ 234 | for (pos = list_entry((head)->next, type, member), \ 235 | n = list_entry(pos->member.next, type, member); \ 236 | &pos->member != (head); \ 237 | pos = n, n = list_entry(n->member.next, type, member)) 238 | 239 | /** 240 | * list_for_each_entry_continue - iterate over list of given type 241 | * continuing after existing point 242 | * @pos: the type * to use as a loop counter. 243 | * @head: the head for your list. 244 | * @member: the name of the list_struct within the struct. 245 | * @type: the type of the struct. 246 | */ 247 | #define list_for_each_entry_continue(pos, head, member, type) \ 248 | for (pos = list_entry(pos->member.next, type, member), \ 249 | prefetch(pos->member.next); \ 250 | &pos->member != (head); \ 251 | pos = list_entry(pos->member.next, type, member), \ 252 | prefetch(pos->member.next)) 253 | 254 | #endif 255 | -------------------------------------------------------------------------------- /fpga_miner_aws/fpga_miner: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mih0/FPGA_Mining_AWS/4c0324bade530e263196d335dd1fb1834232641b/fpga_miner_aws/fpga_miner -------------------------------------------------------------------------------- /fpga_miner_aws/fpgautils.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2013 Con Kolivas 3 | * Copyright 2012 Luke Dashjr 4 | * Copyright 2012 Andrew Smith 5 | * 6 | * This program is free software; you can redistribute it and/or modify it 7 | * under the terms of the GNU General Public License as published by the Free 8 | * Software Foundation; either version 3 of the License, or (at your option) 9 | * any later version. See COPYING for more details. 10 | */ 11 | 12 | #include 13 | #include 14 | 15 | #ifndef WIN32 16 | #include 17 | #include 18 | #include 19 | #include 20 | #ifndef O_CLOEXEC 21 | #define O_CLOEXEC 0 22 | #endif 23 | #endif 24 | 25 | #include "miner.h" 26 | #include "fpgautils.h" 27 | 28 | int serial_open(const char *devpath, unsigned long baud, signed short timeout, bool purge) 29 | { 30 | #ifdef WIN32 31 | HANDLE hSerial = CreateFile(devpath, GENERIC_READ | GENERIC_WRITE, 0, NULL, OPEN_EXISTING, 0, NULL); 32 | if (unlikely(hSerial == INVALID_HANDLE_VALUE)) 33 | { 34 | DWORD e = GetLastError(); 35 | switch (e) { 36 | case ERROR_ACCESS_DENIED: 37 | applog(LOG_ERR, "Do not have user privileges required to open %s", devpath); 38 | break; 39 | case ERROR_SHARING_VIOLATION: 40 | applog(LOG_ERR, "%s is already in use by another process", devpath); 41 | break; 42 | default: 43 | applog(LOG_DEBUG, "Open %s failed, GetLastError:%d", devpath, (int)e); 44 | break; 45 | } 46 | return -1; 47 | } 48 | 49 | // thanks to af_newbie for pointers about this 50 | COMMCONFIG comCfg = {0}; 51 | comCfg.dwSize = sizeof(COMMCONFIG); 52 | comCfg.wVersion = 1; 53 | comCfg.dcb.DCBlength = sizeof(DCB); 54 | comCfg.dcb.BaudRate = baud; 55 | comCfg.dcb.fBinary = 1; 56 | comCfg.dcb.fDtrControl = DTR_CONTROL_ENABLE; 57 | comCfg.dcb.fRtsControl = RTS_CONTROL_ENABLE; 58 | comCfg.dcb.ByteSize = 8; 59 | 60 | SetCommConfig(hSerial, &comCfg, sizeof(comCfg)); 61 | 62 | // Code must specify a valid timeout value (0 means don't timeout) 63 | const DWORD ctoms = (timeout * 100); 64 | COMMTIMEOUTS cto = {ctoms, 0, ctoms, 0, ctoms}; 65 | SetCommTimeouts(hSerial, &cto); 66 | 67 | if (purge) { 68 | PurgeComm(hSerial, PURGE_RXABORT); 69 | PurgeComm(hSerial, PURGE_TXABORT); 70 | PurgeComm(hSerial, PURGE_RXCLEAR); 71 | PurgeComm(hSerial, PURGE_TXCLEAR); 72 | } 73 | 74 | return _open_osfhandle((intptr_t)hSerial, 0); 75 | #else 76 | int fdDev = open(devpath, O_RDWR | O_CLOEXEC | O_NOCTTY); 77 | 78 | if (unlikely(fdDev == -1)) 79 | { 80 | if (errno == EACCES) 81 | applog(LOG_ERR, "Do not have user privileges required to open %s", devpath); 82 | else 83 | applog(LOG_DEBUG, "Open %s failed, errno:%d", devpath, errno); 84 | 85 | return -1; 86 | } 87 | 88 | struct termios my_termios; 89 | 90 | tcgetattr(fdDev, &my_termios); 91 | 92 | switch (baud) { 93 | case 0: 94 | break; 95 | case 19200: 96 | cfsetispeed(&my_termios, B19200); 97 | cfsetospeed(&my_termios, B19200); 98 | break; 99 | case 38400: 100 | cfsetispeed(&my_termios, B38400); 101 | cfsetospeed(&my_termios, B38400); 102 | break; 103 | case 57600: 104 | cfsetispeed(&my_termios, B57600); 105 | cfsetospeed(&my_termios, B57600); 106 | break; 107 | case 115200: 108 | cfsetispeed(&my_termios, B115200); 109 | cfsetospeed(&my_termios, B115200); 110 | break; 111 | default: 112 | applog(LOG_WARNING, "Unrecognized baud rate: %lu", baud); 113 | } 114 | 115 | my_termios.c_cflag &= ~(CSIZE | PARENB); 116 | my_termios.c_cflag |= CS8; 117 | my_termios.c_cflag |= CREAD; 118 | my_termios.c_cflag |= CLOCAL; 119 | 120 | my_termios.c_iflag &= ~(IGNBRK | BRKINT | PARMRK | 121 | ISTRIP | INLCR | IGNCR | ICRNL | IXON); 122 | my_termios.c_oflag &= ~OPOST; 123 | my_termios.c_lflag &= ~(ECHO | ECHONL | ICANON | ISIG | IEXTEN); 124 | 125 | // Code must specify a valid timeout value (0 means don't timeout) 126 | my_termios.c_cc[VTIME] = (cc_t)timeout; 127 | my_termios.c_cc[VMIN] = 0; 128 | 129 | tcsetattr(fdDev, TCSANOW, &my_termios); 130 | 131 | if (purge) 132 | tcflush(fdDev, TCIOFLUSH); 133 | return fdDev; 134 | #endif 135 | } 136 | 137 | // ssize_t _serial_read(int fd, char *buf, size_t bufsiz, char *eol) 138 | // { 139 | // ssize_t len, tlen = 0; 140 | // while (bufsiz) { 141 | // len = read(fd, buf, eol ? 1 : bufsiz); 142 | // if (unlikely(len == -1)) 143 | // break; 144 | // tlen += len; 145 | // if (eol && *eol == buf[0]) 146 | // break; 147 | // buf += len; 148 | // bufsiz -= len; 149 | // } 150 | // return tlen; 151 | // } 152 | 153 | FILE *open_bitstream(const char *filename) 154 | { 155 | char fullpath[PATH_MAX]; 156 | strcpy(fullpath, "./bitstreams/"); 157 | strcat(fullpath, filename); 158 | 159 | return fopen(fullpath, "rb"); 160 | } 161 | -------------------------------------------------------------------------------- /fpga_miner_aws/fpgautils.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2012 Luke Dashjr 3 | * 4 | * This program is free software; you can redistribute it and/or modify it 5 | * under the terms of the GNU General Public License as published by the Free 6 | * Software Foundation; either version 3 of the License, or (at your option) 7 | * any later version. See COPYING for more details. 8 | */ 9 | 10 | #ifndef FPGAUTILS_H 11 | #define FPGAUTILS_H 12 | 13 | #ifndef PATH_MAX 14 | #define PATH_MAX 4095 15 | #endif 16 | 17 | extern int serial_open(const char *devpath, unsigned long baud, signed short timeout, bool purge); 18 | extern FILE *open_bitstream(const char *filename); 19 | 20 | #endif 21 | -------------------------------------------------------------------------------- /fpga_miner_aws/sha3/haval_helper.c: -------------------------------------------------------------------------------- 1 | /* $Id: haval_helper.c 218 2010-06-08 17:06:34Z tp $ */ 2 | /* 3 | * Helper code, included (three times !) by HAVAL implementation. 4 | * 5 | * TODO: try to merge this with md_helper.c. 6 | * 7 | * ==========================(LICENSE BEGIN)============================ 8 | * 9 | * Copyright (c) 2007-2010 Projet RNRT SAPHIR 10 | * 11 | * Permission is hereby granted, free of charge, to any person obtaining 12 | * a copy of this software and associated documentation files (the 13 | * "Software"), to deal in the Software without restriction, including 14 | * without limitation the rights to use, copy, modify, merge, publish, 15 | * distribute, sublicense, and/or sell copies of the Software, and to 16 | * permit persons to whom the Software is furnished to do so, subject to 17 | * the following conditions: 18 | * 19 | * The above copyright notice and this permission notice shall be 20 | * included in all copies or substantial portions of the Software. 21 | * 22 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 23 | * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 24 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. 25 | * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY 26 | * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, 27 | * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE 28 | * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 29 | * 30 | * ===========================(LICENSE END)============================= 31 | * 32 | * @author Thomas Pornin 33 | */ 34 | 35 | #include "sph_haval.h" 36 | 37 | #undef SPH_XCAT 38 | #define SPH_XCAT(a, b) SPH_XCAT_(a, b) 39 | #undef SPH_XCAT_ 40 | #define SPH_XCAT_(a, b) a ## b 41 | 42 | static void 43 | #ifdef SPH_UPTR 44 | SPH_XCAT(SPH_XCAT(haval, PASSES), _short) 45 | #else 46 | SPH_XCAT(haval, PASSES) 47 | #endif 48 | (sph_haval_context *sc, const void *data, size_t len) 49 | { 50 | unsigned current; 51 | 52 | #if SPH_64 53 | current = (unsigned)sc->count & 127U; 54 | #else 55 | current = (unsigned)sc->count_low & 127U; 56 | #endif 57 | while (len > 0) { 58 | unsigned clen; 59 | #if !SPH_64 60 | sph_u32 clow, clow2; 61 | #endif 62 | 63 | clen = 128U - current; 64 | if (clen > len) 65 | clen = (unsigned) len; 66 | memcpy(sc->buf + current, data, clen); 67 | data = (const unsigned char *)data + clen; 68 | current += clen; 69 | len -= clen; 70 | if (current == 128U) { 71 | DSTATE; 72 | IN_PREPARE(sc->buf); 73 | 74 | RSTATE; 75 | SPH_XCAT(CORE, PASSES)(INW); 76 | WSTATE; 77 | current = 0; 78 | } 79 | #if SPH_64 80 | sc->count += clen; 81 | #else 82 | clow = sc->count_low; 83 | clow2 = SPH_T32(clow + clen); 84 | sc->count_low = clow2; 85 | if (clow2 < clow) 86 | sc->count_high ++; 87 | #endif 88 | } 89 | } 90 | 91 | #ifdef SPH_UPTR 92 | static void 93 | SPH_XCAT(haval, PASSES)(sph_haval_context *sc, const void *data, size_t len) 94 | { 95 | unsigned current; 96 | size_t orig_len; 97 | #if !SPH_64 98 | sph_u32 clow, clow2; 99 | #endif 100 | DSTATE; 101 | 102 | if (len < 256U) { 103 | SPH_XCAT(SPH_XCAT(haval, PASSES), _short)(sc, data, len); 104 | return; 105 | } 106 | #if SPH_64 107 | current = (unsigned)sc->count & 127U; 108 | #else 109 | current = (unsigned)sc->count_low & 127U; 110 | #endif 111 | if (current > 0) { 112 | unsigned clen; 113 | 114 | clen = 128U - current; 115 | SPH_XCAT(SPH_XCAT(haval, PASSES), _short)(sc, data, clen); 116 | data = (const unsigned char *)data + clen; 117 | len -= clen; 118 | } 119 | #if !SPH_UNALIGNED 120 | if (((SPH_UPTR)data & 3U) != 0) { 121 | SPH_XCAT(SPH_XCAT(haval, PASSES), _short)(sc, data, len); 122 | return; 123 | } 124 | #endif 125 | orig_len = len; 126 | RSTATE; 127 | while (len >= 128U) { 128 | IN_PREPARE(data); 129 | 130 | SPH_XCAT(CORE, PASSES)(INW); 131 | data = (const unsigned char *)data + 128U; 132 | len -= 128U; 133 | } 134 | WSTATE; 135 | if (len > 0) 136 | memcpy(sc->buf, data, len); 137 | #if SPH_64 138 | sc->count += (sph_u64)orig_len; 139 | #else 140 | clow = sc->count_low; 141 | clow2 = SPH_T32(clow + orig_len); 142 | sc->count_low = clow2; 143 | if (clow2 < clow) 144 | sc->count_high ++; 145 | orig_len >>= 12; 146 | orig_len >>= 10; 147 | orig_len >>= 10; 148 | sc->count_high += orig_len; 149 | #endif 150 | } 151 | #endif 152 | 153 | static void 154 | SPH_XCAT(SPH_XCAT(haval, PASSES), _close)(sph_haval_context *sc, 155 | unsigned ub, unsigned n, void *dst) 156 | { 157 | unsigned current; 158 | DSTATE; 159 | 160 | #if SPH_64 161 | current = (unsigned)sc->count & 127U; 162 | #else 163 | current = (unsigned)sc->count_low & 127U; 164 | #endif 165 | sc->buf[current ++] = (0x01 << n) | ((ub & 0xFF) >> (8 - n)); 166 | RSTATE; 167 | if (current > 118U) { 168 | memset(sc->buf + current, 0, 128U - current); 169 | 170 | do { 171 | IN_PREPARE(sc->buf); 172 | 173 | SPH_XCAT(CORE, PASSES)(INW); 174 | } while (0); 175 | current = 0; 176 | } 177 | memset(sc->buf + current, 0, 118U - current); 178 | sc->buf[118] = 0x01 | (PASSES << 3); 179 | sc->buf[119] = sc->olen << 3; 180 | #if SPH_64 181 | sph_enc64le_aligned(sc->buf + 120, SPH_T64(sc->count << 3)); 182 | #else 183 | sph_enc32le_aligned(sc->buf + 120, SPH_T32(sc->count_low << 3)); 184 | sph_enc32le_aligned(sc->buf + 124, 185 | SPH_T32((sc->count_high << 3) | (sc->count_low >> 29))); 186 | #endif 187 | do { 188 | IN_PREPARE(sc->buf); 189 | 190 | SPH_XCAT(CORE, PASSES)(INW); 191 | } while (0); 192 | 193 | WSTATE; 194 | haval_out(sc, dst); 195 | haval_init(sc, sc->olen, sc->passes); 196 | } 197 | 198 | -------------------------------------------------------------------------------- /fpga_miner_aws/sha3/sph_gost.h: -------------------------------------------------------------------------------- 1 | /* $Id: sph_gost.h 216 2010-06-08 09:46:57Z tp $ */ 2 | /** 3 | * GOST interface. This is the interface for GOST R 12 with the 4 | * recommended parameters for SHA-3, with output lengths 256 5 | * and 512 bits. 6 | * 7 | * ==========================(LICENSE BEGIN)============================ 8 | * 9 | * Copyright (c) 2007-2010 Projet RNRT SAPHIR 10 | * 11 | * Permission is hereby granted, free of charge, to any person obtaining 12 | * a copy of this software and associated documentation files (the 13 | * "Software"), to deal in the Software without restriction, including 14 | * without limitation the rights to use, copy, modify, merge, publish, 15 | * distribute, sublicense, and/or sell copies of the Software, and to 16 | * permit persons to whom the Software is furnished to do so, subject to 17 | * the following conditions: 18 | * 19 | * The above copyright notice and this permission notice shall be 20 | * included in all copies or substantial portions of the Software. 21 | * 22 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 23 | * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 24 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. 25 | * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY 26 | * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, 27 | * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE 28 | * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 29 | * 30 | * ===========================(LICENSE END)============================= 31 | * 32 | * @file sph_gost.h 33 | * @author Thomas Pornin 34 | */ 35 | 36 | #ifndef SPH_GOST_H__ 37 | #define SPH_GOST_H__ 38 | 39 | #ifdef __cplusplus 40 | extern "C"{ 41 | #endif 42 | 43 | #include 44 | #include "sph_types.h" 45 | 46 | /** 47 | * Output size (in bits) for GOST-256. 48 | */ 49 | #define SPH_SIZE_gost256 256 50 | 51 | /** 52 | * Output size (in bits) for GOST-512. 53 | */ 54 | #define SPH_SIZE_gost512 512 55 | 56 | /** 57 | * This structure is a context for Keccak computations: it contains the 58 | * intermediate values and some data from the last entered block. Once a 59 | * GOST computation has been performed, the context can be reused for 60 | * another computation. 61 | * 62 | * The contents of this structure are private. A running GOST computation 63 | * can be cloned by copying the context (e.g. with a simple 64 | * memcpy()). 65 | */ 66 | 67 | /** 68 | * This structure is a context for Gost-256 computations. 69 | */ 70 | 71 | typedef struct { 72 | #ifndef DOXYGEN_IGNORE 73 | unsigned char buf[32]; /* first field, for alignment */ 74 | size_t ptr; 75 | sph_u32 V[3][8]; 76 | #endif 77 | } sph_gost256_context; 78 | 79 | /** 80 | * This structure is a context for Gost-512 computations. 81 | */ 82 | typedef struct { 83 | #ifndef DOXYGEN_IGNORE 84 | unsigned char buf[64]; /* first field, for alignment */ 85 | size_t ptr; 86 | sph_u32 V[5][8]; 87 | #endif 88 | } sph_gost512_context; 89 | 90 | 91 | /** 92 | * Initialize a GOST-256 context. This process performs no memory allocation. 93 | * 94 | * @param cc the GOST-256 context (pointer to a 95 | * sph_gost256_context) 96 | */ 97 | void sph_gost256_init(void *cc); 98 | 99 | /** 100 | * Process some data bytes. It is acceptable that len is zero 101 | * (in which case this function does nothing). 102 | * 103 | * @param cc the Gost-256 context 104 | * @param data the input data 105 | * @param len the input data length (in bytes) 106 | */ 107 | void sph_gost256(void *cc, const void *data, size_t len); 108 | 109 | /** 110 | * Terminate the current GOST-256 computation and output the result into 111 | * the provided buffer. The destination buffer must be wide enough to 112 | * accomodate the result (32 bytes). The context is automatically 113 | * reinitialized. 114 | * 115 | * @param cc the GOST-256 context 116 | * @param dst the destination buffer 117 | */ 118 | void sph_gost256_close(void *cc, void *dst); 119 | 120 | /** 121 | * Add a few additional bits (0 to 7) to the current computation, then 122 | * terminate it and output the result in the provided buffer, which must 123 | * be wide enough to accomodate the result (32 bytes). If bit number i 124 | * in ub has value 2^i, then the extra bits are those 125 | * numbered 7 downto 8-n (this is the big-endian convention at the byte 126 | * level). The context is automatically reinitialized. 127 | * 128 | * @param cc the GOST-256 context 129 | * @param ub the extra bits 130 | * @param n the number of extra bits (0 to 7) 131 | * @param dst the destination buffer 132 | */ 133 | void sph_gost256_addbits_and_close( 134 | void *cc, unsigned ub, unsigned n, void *dst); 135 | 136 | /** 137 | * Initialize a Gost-512 context. This process performs no memory allocation. 138 | * 139 | * @param cc the GOST-512 context (pointer to a 140 | * sph_gost512_context) 141 | */ 142 | void sph_gost512_init(void *cc); 143 | 144 | /** 145 | * Process some data bytes. It is acceptable that len is zero 146 | * (in which case this function does nothing). 147 | * 148 | * @param cc the GOST-512 context 149 | * @param data the input data 150 | * @param len the input data length (in bytes) 151 | */ 152 | void sph_gost512(void *cc, const void *data, size_t len); 153 | 154 | /** 155 | * Terminate the current GOST-512 computation and output the result into 156 | * the provided buffer. The destination buffer must be wide enough to 157 | * accomodate the result (64 bytes). The context is automatically 158 | * reinitialized. 159 | * 160 | * @param cc the GOST-512 context 161 | * @param dst the destination buffer 162 | */ 163 | void sph_gost512_close(void *cc, void *dst); 164 | 165 | /** 166 | * Add a few additional bits (0 to 7) to the current computation, then 167 | * terminate it and output the result in the provided buffer, which must 168 | * be wide enough to accomodate the result (64 bytes). If bit number i 169 | * in ub has value 2^i, then the extra bits are those 170 | * numbered 7 downto 8-n (this is the big-endian convention at the byte 171 | * level). The context is automatically reinitialized. 172 | * 173 | * @param cc the GOST-512 context 174 | * @param ub the extra bits 175 | * @param n the number of extra bits (0 to 7) 176 | * @param dst the destination buffer 177 | */ 178 | void sph_gost512_addbits_and_close( 179 | void *cc, unsigned ub, unsigned n, void *dst); 180 | 181 | #ifdef __cplusplus 182 | } 183 | #endif 184 | 185 | #endif 186 | -------------------------------------------------------------------------------- /grs/cl_common_defines.vh: -------------------------------------------------------------------------------- 1 | // Amazon FPGA Hardware Development Kit 2 | // 3 | // Copyright 2016 Amazon.com, Inc. or its affiliates. All Rights Reserved. 4 | // 5 | // Licensed under the Amazon Software License (the "License"). You may not use 6 | // this file except in compliance with the License. A copy of the License is 7 | // located at 8 | // 9 | // http://aws.amazon.com/asl/ 10 | // 11 | // or in the "license" file accompanying this file. This file is distributed on 12 | // an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, express or 13 | // implied. See the License for the specific language governing permissions and 14 | // limitations under the License. 15 | 16 | `ifndef CL_COMMON_DEFAULTS 17 | `define CL_COMMON_DEFAULTS 18 | 19 | // Value to return for PCIS access to unimplemented register address 20 | `define UNIMPLEMENTED_REG_VALUE 32'hdeaddead 21 | 22 | // CL Register Addresses 23 | `define HELLO_WORLD_REG_ADDR 32'h0000_0500 24 | `define VLED_REG_ADDR 32'h0000_0504 25 | 26 | `endif 27 | -------------------------------------------------------------------------------- /grs/cl_id_defines.vh: -------------------------------------------------------------------------------- 1 | // Amazon FPGA Hardware Development Kit 2 | // 3 | // Copyright 2016 Amazon.com, Inc. or its affiliates. All Rights Reserved. 4 | // 5 | // Licensed under the Amazon Software License (the "License"). You may not use 6 | // this file except in compliance with the License. A copy of the License is 7 | // located at 8 | // 9 | // http://aws.amazon.com/asl/ 10 | // 11 | // or in the "license" file accompanying this file. This file is distributed on 12 | // an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, express or 13 | // implied. See the License for the specific language governing permissions and 14 | // limitations under the License. 15 | 16 | // CL_SH_ID0 17 | // - PCIe Vendor/Device ID Values 18 | // 31:16: PCIe Device ID 19 | // 15: 0: PCIe Vendor ID 20 | // - A Vendor ID value of 0x8086 is not valid. 21 | // - If using a Vendor ID value of 0x1D0F (Amazon) then valid 22 | // values for Device ID's are in the range of 0xF000 - 0xF0FF. 23 | // - A Vendor/Device ID of 0 (zero) is not valid. 24 | `define CL_SH_ID0 32'hF000_1D0F 25 | 26 | // CL_SH_ID1 27 | // - PCIe Subsystem/Subsystem Vendor ID Values 28 | // 31:16: PCIe Subsystem ID 29 | // 15: 0: PCIe Subsystem Vendor ID 30 | // - A PCIe Subsystem/Subsystem Vendor ID of 0 (zero) is not valid 31 | `define CL_SH_ID1 32'h1D51_FEDD 32 | -------------------------------------------------------------------------------- /grs/cl_miner_defines.vh: -------------------------------------------------------------------------------- 1 | // Amazon FPGA Hardware Development Kit 2 | // 3 | // Copyright 2016 Amazon.com, Inc. or its affiliates. All Rights Reserved. 4 | // 5 | // Licensed under the Amazon Software License (the "License"). You may not use 6 | // this file except in compliance with the License. A copy of the License is 7 | // located at 8 | // 9 | // http://aws.amazon.com/asl/ 10 | // 11 | // or in the "license" file accompanying this file. This file is distributed on 12 | // an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, express or 13 | // implied. See the License for the specific language governing permissions and 14 | // limitations under the License. 15 | 16 | `ifndef CL_MINER_DEFINES 17 | `define CL_MINER_DEFINES 18 | 19 | //Put module name of the CL design here. This is used to instantiate in top.sv 20 | `define CL_NAME cl_miner 21 | 22 | //Highly recommeneded. For lib FIFO block, uses less async reset (take advantage of 23 | // FPGA flop init capability). This will help with routing resources. 24 | `define FPGA_LESS_RST 25 | 26 | // Uncomment to disable Virtual JTAG 27 | //`define DISABLE_VJTAG_DEBUG 28 | 29 | `endif -------------------------------------------------------------------------------- /grs/miner.v: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2016 Sprocket 3 | * 4 | * This is free software: you can redistribute it and/or modify 5 | * it under the terms of the GNU Affero General Public License with 6 | * additional permissions to the one published by the Free Software 7 | * Foundation, either version 3 of the License, or (at your option) 8 | * any later version. For more information see LICENSE. 9 | * 10 | * This program is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | * GNU Affero General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU Affero General Public License 16 | * along with this program. If not, see . 17 | */ 18 | 19 | module miner # ( 20 | parameter CORES = 32'd1 21 | ) ( 22 | input clk, 23 | input reset, 24 | input [639:0] block, 25 | input [31:0] nonce_start, 26 | output nonce_found, 27 | output [31:0] nonce_out 28 | ); 29 | 30 | localparam OFFSET = 32'd172; 31 | 32 | wire [511:0] hash1; 33 | wire [511:0] hash2; 34 | 35 | reg reset_d, reset_q; 36 | reg [647:0] block0_d, block0_q; 37 | reg [647:0] block1_d, block1_q; 38 | reg [31:0] target_d, target_q; 39 | reg [31:0] nonce_d, nonce_q; 40 | reg [31:0] nonce_out_d, nonce_out_q; 41 | reg [31:0] hash_out_d, hash_out_q; 42 | reg nonce_found_d, nonce_found_q; 43 | 44 | assign nonce_found = nonce_found_q; 45 | assign nonce_out = nonce_out_q; 46 | 47 | groestl512 groestl_1 ( clk, block0_q, hash1 ); 48 | groestl512 groestl_2 ( clk, block1_q, hash2 ); 49 | 50 | always @ ( * ) begin 51 | 52 | if ( reset_q ) begin 53 | 54 | nonce_d = nonce_start; 55 | 56 | nonce_found_d = 1'b0; 57 | nonce_out_d = 32'd0; 58 | hash_out_d = 32'd0; 59 | 60 | end 61 | else begin 62 | 63 | nonce_d = nonce_q + CORES; 64 | 65 | nonce_out_d = nonce_q - (CORES * OFFSET); 66 | hash_out_d = { hash2[263:256], hash2[271:264], hash2[279:272], hash2[287:280] }; 67 | 68 | if ( hash_out_d <= target_d ) 69 | nonce_found_d = 1'b1; 70 | else 71 | nonce_found_d = 1'b0; 72 | 73 | end 74 | 75 | block0_d = { block[639:32], nonce_q, 8'h80 }; 76 | block1_d = { hash1, 8'h80, 128'd0 }; 77 | target_d = block[31:0]; 78 | 79 | reset_d = reset; 80 | 81 | end 82 | 83 | always @ (posedge clk) begin 84 | 85 | block0_q <= block0_d; 86 | block1_q <= block1_d; 87 | target_q <= target_d; 88 | 89 | nonce_q <= nonce_d; 90 | nonce_out_q <= nonce_out_d; 91 | hash_out_q <= hash_out_d; 92 | 93 | nonce_found_q <= nonce_found_d; 94 | 95 | reset_q <= reset_d; 96 | 97 | // $display ("Hash1 : %x", hash1); 98 | // $display ("Hash2 : %x", hash2); 99 | $display("Nonce: %x, Hash: %x, Found: %d", nonce_out_d, hash_out_d, nonce_found_d ); 100 | 101 | end 102 | 103 | endmodule 104 | -------------------------------------------------------------------------------- /grs/mix_bytes.v: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2017 Sprocket 3 | * 4 | * This is free software: you can redistribute it and/or modify 5 | * it under the terms of the GNU Affero General Public License with 6 | * additional permissions to the one published by the Free Software 7 | * Foundation, either version 3 of the License, or (at your option) 8 | * any later version. For more information see LICENSE. 9 | * 10 | * This program is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | * GNU Affero General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU Affero General Public License 16 | * along with this program. If not, see . 17 | */ 18 | 19 | module mix_bytes( 20 | input clk, 21 | input [1023:0] in, 22 | output reg [1023:0] out 23 | ); 24 | 25 | wire [7:0] gf2 [0:255] = { 26 | 8'h00, 8'h02, 8'h04, 8'h06, 8'h08, 8'h0a, 8'h0c, 8'h0e, 8'h10, 8'h12, 8'h14, 8'h16, 8'h18, 8'h1a, 8'h1c, 8'h1e, 27 | 8'h20, 8'h22, 8'h24, 8'h26, 8'h28, 8'h2a, 8'h2c, 8'h2e, 8'h30, 8'h32, 8'h34, 8'h36, 8'h38, 8'h3a, 8'h3c, 8'h3e, 28 | 8'h40, 8'h42, 8'h44, 8'h46, 8'h48, 8'h4a, 8'h4c, 8'h4e, 8'h50, 8'h52, 8'h54, 8'h56, 8'h58, 8'h5a, 8'h5c, 8'h5e, 29 | 8'h60, 8'h62, 8'h64, 8'h66, 8'h68, 8'h6a, 8'h6c, 8'h6e, 8'h70, 8'h72, 8'h74, 8'h76, 8'h78, 8'h7a, 8'h7c, 8'h7e, 30 | 8'h80, 8'h82, 8'h84, 8'h86, 8'h88, 8'h8a, 8'h8c, 8'h8e, 8'h90, 8'h92, 8'h94, 8'h96, 8'h98, 8'h9a, 8'h9c, 8'h9e, 31 | 8'ha0, 8'ha2, 8'ha4, 8'ha6, 8'ha8, 8'haa, 8'hac, 8'hae, 8'hb0, 8'hb2, 8'hb4, 8'hb6, 8'hb8, 8'hba, 8'hbc, 8'hbe, 32 | 8'hc0, 8'hc2, 8'hc4, 8'hc6, 8'hc8, 8'hca, 8'hcc, 8'hce, 8'hd0, 8'hd2, 8'hd4, 8'hd6, 8'hd8, 8'hda, 8'hdc, 8'hde, 33 | 8'he0, 8'he2, 8'he4, 8'he6, 8'he8, 8'hea, 8'hec, 8'hee, 8'hf0, 8'hf2, 8'hf4, 8'hf6, 8'hf8, 8'hfa, 8'hfc, 8'hfe, 34 | 8'h1b, 8'h19, 8'h1f, 8'h1d, 8'h13, 8'h11, 8'h17, 8'h15, 8'h0b, 8'h09, 8'h0f, 8'h0d, 8'h03, 8'h01, 8'h07, 8'h05, 35 | 8'h3b, 8'h39, 8'h3f, 8'h3d, 8'h33, 8'h31, 8'h37, 8'h35, 8'h2b, 8'h29, 8'h2f, 8'h2d, 8'h23, 8'h21, 8'h27, 8'h25, 36 | 8'h5b, 8'h59, 8'h5f, 8'h5d, 8'h53, 8'h51, 8'h57, 8'h55, 8'h4b, 8'h49, 8'h4f, 8'h4d, 8'h43, 8'h41, 8'h47, 8'h45, 37 | 8'h7b, 8'h79, 8'h7f, 8'h7d, 8'h73, 8'h71, 8'h77, 8'h75, 8'h6b, 8'h69, 8'h6f, 8'h6d, 8'h63, 8'h61, 8'h67, 8'h65, 38 | 8'h9b, 8'h99, 8'h9f, 8'h9d, 8'h93, 8'h91, 8'h97, 8'h95, 8'h8b, 8'h89, 8'h8f, 8'h8d, 8'h83, 8'h81, 8'h87, 8'h85, 39 | 8'hbb, 8'hb9, 8'hbf, 8'hbd, 8'hb3, 8'hb1, 8'hb7, 8'hb5, 8'hab, 8'ha9, 8'haf, 8'had, 8'ha3, 8'ha1, 8'ha7, 8'ha5, 40 | 8'hdb, 8'hd9, 8'hdf, 8'hdd, 8'hd3, 8'hd1, 8'hd7, 8'hd5, 8'hcb, 8'hc9, 8'hcf, 8'hcd, 8'hc3, 8'hc1, 8'hc7, 8'hc5, 41 | 8'hfb, 8'hf9, 8'hff, 8'hfd, 8'hf3, 8'hf1, 8'hf7, 8'hf5, 8'heb, 8'he9, 8'hef, 8'hed, 8'he3, 8'he1, 8'he7, 8'he5 42 | }; 43 | 44 | reg [63:0] m0, m1, m2, m3, m4, m5, m6, m7; 45 | reg [63:0] m8, m9, m10,m11,m12,m13,m14,m15; 46 | 47 | reg [1023:0] m; 48 | 49 | always @ (*) begin 50 | 51 | m0 <= GF_Mult(in[1023:960]); 52 | m1 <= GF_Mult(in[959:896]); 53 | m2 <= GF_Mult(in[895:832]); 54 | m3 <= GF_Mult(in[831:768]); 55 | m4 <= GF_Mult(in[767:704]); 56 | m5 <= GF_Mult(in[703:640]); 57 | m6 <= GF_Mult(in[639:576]); 58 | m7 <= GF_Mult(in[575:512]); 59 | m8 <= GF_Mult(in[511:448]); 60 | m9 <= GF_Mult(in[447:384]); 61 | m10 <= GF_Mult(in[383:320]); 62 | m11 <= GF_Mult(in[319:256]); 63 | m12 <= GF_Mult(in[255:192]); 64 | m13 <= GF_Mult(in[191:128]); 65 | m14 <= GF_Mult(in[127: 64]); 66 | m15 <= GF_Mult(in[ 63: 0]); 67 | 68 | end 69 | 70 | always @ (*) begin 71 | m <= {m0,m1,m2,m3,m4,m5,m6,m7,m8,m9,m10,m11,m12,m13,m14,m15}; 72 | end 73 | 74 | always @ (posedge clk) begin 75 | out <= m; 76 | end 77 | 78 | 79 | // Perform GF(256) Multiplications On a Row 80 | function [63:0] GF_Mult; 81 | input [63:0] in; 82 | 83 | reg [7:0] b0,b1,b2,b3,b4,b5,b6,b7; 84 | reg [7:0] b0_x2,b1_x2,b2_x2,b3_x2,b4_x2,b5_x2,b6_x2,b7_x2; 85 | reg [7:0] b0_x4,b1_x4,b2_x4,b3_x4,b4_x4,b5_x4,b6_x4,b7_x4; 86 | 87 | begin 88 | 89 | {b0,b1,b2,b3,b4,b5,b6,b7} = in; 90 | 91 | b0_x2 = gf2[b0]; 92 | b1_x2 = gf2[b1]; 93 | b2_x2 = gf2[b2]; 94 | b3_x2 = gf2[b3]; 95 | b4_x2 = gf2[b4]; 96 | b5_x2 = gf2[b5]; 97 | b6_x2 = gf2[b6]; 98 | b7_x2 = gf2[b7]; 99 | 100 | b0_x4 = gf2[gf2[b0]]; 101 | b1_x4 = gf2[gf2[b1]]; 102 | b2_x4 = gf2[gf2[b2]]; 103 | b3_x4 = gf2[gf2[b3]]; 104 | b4_x4 = gf2[gf2[b4]]; 105 | b5_x4 = gf2[gf2[b5]]; 106 | b6_x4 = gf2[gf2[b6]]; 107 | b7_x4 = gf2[gf2[b7]]; 108 | 109 | GF_Mult = { 110 | b0_x2 ^ b1_x2 ^ b2_x2 ^ b2 ^ b3_x4 ^ b4_x4 ^ b4 ^ b5_x2 ^ b5 ^ b6_x4 ^b6 ^ b7_x4 ^ b7_x2 ^ b7, 111 | b1_x2 ^ b2_x2 ^ b3_x2 ^ b3 ^ b4_x4 ^ b5_x4 ^ b5 ^ b6_x2 ^ b6 ^ b7_x4 ^b7 ^ b0_x4 ^ b0_x2 ^ b0, 112 | b2_x2 ^ b3_x2 ^ b4_x2 ^ b4 ^ b5_x4 ^ b6_x4 ^ b6 ^ b7_x2 ^ b7 ^ b0_x4 ^b0 ^ b1_x4 ^ b1_x2 ^ b1, 113 | b3_x2 ^ b4_x2 ^ b5_x2 ^ b5 ^ b6_x4 ^ b7_x4 ^ b7 ^ b0_x2 ^ b0 ^ b1_x4 ^b1 ^ b2_x4 ^ b2_x2 ^ b2, 114 | b4_x2 ^ b5_x2 ^ b6_x2 ^ b6 ^ b7_x4 ^ b0_x4 ^ b0 ^ b1_x2 ^ b1 ^ b2_x4 ^b2 ^ b3_x4 ^ b3_x2 ^ b3, 115 | b5_x2 ^ b6_x2 ^ b7_x2 ^ b7 ^ b0_x4 ^ b1_x4 ^ b1 ^ b2_x2 ^ b2 ^ b3_x4 ^b3 ^ b4_x4 ^ b4_x2 ^ b4, 116 | b6_x2 ^ b7_x2 ^ b0_x2 ^ b0 ^ b1_x4 ^ b2_x4 ^ b2 ^ b3_x2 ^ b3 ^ b4_x4 ^b4 ^ b5_x4 ^ b5_x2 ^ b5, 117 | b7_x2 ^ b0_x2 ^ b1_x2 ^ b1 ^ b2_x4 ^ b3_x4 ^ b3 ^ b4_x2 ^ b4 ^ b5_x4 ^b5 ^ b6_x4 ^ b6_x2 ^ b6 118 | }; 119 | 120 | end 121 | endfunction 122 | 123 | endmodule 124 | -------------------------------------------------------------------------------- /grs/permutation_p.v: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2016 Sprocket 3 | * 4 | * This is free software: you can redistribute it and/or modify 5 | * it under the terms of the GNU Affero General Public License with 6 | * additional permissions to the one published by the Free Software 7 | * Foundation, either version 3 of the License, or (at your option) 8 | * any later version. For more information see LICENSE. 9 | * 10 | * This program is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | * GNU Affero General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU Affero General Public License 16 | * along with this program. If not, see . 17 | */ 18 | module permutation_p ( 19 | input clk, 20 | input [3:0] round, 21 | input [1023:0] in, 22 | output [1023:0] out 23 | ); 24 | 25 | reg [1023:0] t0; 26 | 27 | wire [7:0] s_box [0:255] = { 28 | 8'h63, 8'h7C, 8'h77, 8'h7B, 8'hF2, 8'h6B, 8'h6F, 8'hC5, 8'h30, 8'h01, 8'h67, 8'h2B, 8'hFE, 8'hD7, 8'hAB, 8'h76, 29 | 8'hCA, 8'h82, 8'hC9, 8'h7D, 8'hFA, 8'h59, 8'h47, 8'hF0, 8'hAD, 8'hD4, 8'hA2, 8'hAF, 8'h9C, 8'hA4, 8'h72, 8'hC0, 30 | 8'hB7, 8'hFD, 8'h93, 8'h26, 8'h36, 8'h3F, 8'hF7, 8'hCC, 8'h34, 8'hA5, 8'hE5, 8'hF1, 8'h71, 8'hD8, 8'h31, 8'h15, 31 | 8'h04, 8'hC7, 8'h23, 8'hC3, 8'h18, 8'h96, 8'h05, 8'h9A, 8'h07, 8'h12, 8'h80, 8'hE2, 8'hEB, 8'h27, 8'hB2, 8'h75, 32 | 8'h09, 8'h83, 8'h2C, 8'h1A, 8'h1B, 8'h6E, 8'h5A, 8'hA0, 8'h52, 8'h3B, 8'hD6, 8'hB3, 8'h29, 8'hE3, 8'h2F, 8'h84, 33 | 8'h53, 8'hD1, 8'h00, 8'hED, 8'h20, 8'hFC, 8'hB1, 8'h5B, 8'h6A, 8'hCB, 8'hBE, 8'h39, 8'h4A, 8'h4C, 8'h58, 8'hCF, 34 | 8'hD0, 8'hEF, 8'hAA, 8'hFB, 8'h43, 8'h4D, 8'h33, 8'h85, 8'h45, 8'hF9, 8'h02, 8'h7F, 8'h50, 8'h3C, 8'h9F, 8'hA8, 35 | 8'h51, 8'hA3, 8'h40, 8'h8F, 8'h92, 8'h9D, 8'h38, 8'hF5, 8'hBC, 8'hB6, 8'hDA, 8'h21, 8'h10, 8'hFF, 8'hF3, 8'hD2, 36 | 8'hCD, 8'h0C, 8'h13, 8'hEC, 8'h5F, 8'h97, 8'h44, 8'h17, 8'hC4, 8'hA7, 8'h7E, 8'h3D, 8'h64, 8'h5D, 8'h19, 8'h73, 37 | 8'h60, 8'h81, 8'h4F, 8'hDC, 8'h22, 8'h2A, 8'h90, 8'h88, 8'h46, 8'hEE, 8'hB8, 8'h14, 8'hDE, 8'h5E, 8'h0B, 8'hDB, 38 | 8'hE0, 8'h32, 8'h3A, 8'h0A, 8'h49, 8'h06, 8'h24, 8'h5C, 8'hC2, 8'hD3, 8'hAC, 8'h62, 8'h91, 8'h95, 8'hE4, 8'h79, 39 | 8'hE7, 8'hC8, 8'h37, 8'h6D, 8'h8D, 8'hD5, 8'h4E, 8'hA9, 8'h6C, 8'h56, 8'hF4, 8'hEA, 8'h65, 8'h7A, 8'hAE, 8'h08, 40 | 8'hBA, 8'h78, 8'h25, 8'h2E, 8'h1C, 8'hA6, 8'hB4, 8'hC6, 8'hE8, 8'hDD, 8'h74, 8'h1F, 8'h4B, 8'hBD, 8'h8B, 8'h8A, 41 | 8'h70, 8'h3E, 8'hB5, 8'h66, 8'h48, 8'h03, 8'hF6, 8'h0E, 8'h61, 8'h35, 8'h57, 8'hB9, 8'h86, 8'hC1, 8'h1D, 8'h9E, 42 | 8'hE1, 8'hF8, 8'h98, 8'h11, 8'h69, 8'hD9, 8'h8E, 8'h94, 8'h9B, 8'h1E, 8'h87, 8'hE9, 8'hCE, 8'h55, 8'h28, 8'hDF, 43 | 8'h8C, 8'hA1, 8'h89, 8'h0D, 8'hBF, 8'hE6, 8'h42, 8'h68, 8'h41, 8'h99, 8'h2D, 8'h0F, 8'hB0, 8'h54, 8'hBB, 8'h16 44 | }; 45 | 46 | reg [7:0] a0, a1, a2, a3, a4, a5, a6, a7, a8, a9, a10,a11,a12,a13,a14,a15; 47 | reg [7:0] a16,a17,a18,a19,a20,a21,a22,a23,a24,a25,a26,a27,a28,a29,a30,a31; 48 | reg [7:0] a32,a33,a34,a35,a36,a37,a38,a39,a40,a41,a42,a43,a44,a45,a46,a47; 49 | reg [7:0] a48,a49,a50,a51,a52,a53,a54,a55,a56,a57,a58,a59,a60,a61,a62,a63; 50 | reg [7:0] a64,a65,a66,a67,a68,a69,a70,a71,a72,a73,a74,a75,a76,a77,a78,a79; 51 | reg [7:0] a80,a81,a82,a83,a84,a85,a86,a87,a88,a89,a90,a91,a92,a93,a94,a95; 52 | reg [7:0] a96,a97,a98,a99,a100,a101,a102,a103,a104,a105,a106,a107,a108,a109,a110,a111; 53 | reg [7:0] a112,a113,a114,a115,a116,a117,a118,a119,a120,a121,a122,a123,a124,a125,a126,a127; 54 | 55 | always @ (*) begin 56 | 57 | a0 <= s_box[in[1016 +: 8] ^ {4'h0,round}]; 58 | a1 <= s_box[in[944 +: 8]]; 59 | a2 <= s_box[in[ 872 +: 8]]; 60 | a3 <= s_box[in[800 +: 8]]; 61 | a4 <= s_box[in[728 +: 8]]; 62 | a5 <= s_box[in[656 +: 8]]; 63 | a6 <= s_box[in[584 +: 8]]; 64 | a7 <= s_box[in[256 +: 8]]; 65 | a8 <= s_box[in[952 +: 8] ^ {4'h1,round}]; 66 | a9 <= s_box[in[ 880 +: 8]]; 67 | a10 <= s_box[in[808 +: 8]]; 68 | a11 <= s_box[in[736 +: 8]]; 69 | a12 <= s_box[in[664 +: 8]]; 70 | a13 <= s_box[in[592 +: 8]]; 71 | a14 <= s_box[in[520 +: 8]]; 72 | a15 <= s_box[in[192 +: 8]]; 73 | a16 <= s_box[in[ 888 +: 8] ^ {4'h2,round}]; 74 | a17 <= s_box[in[816 +: 8]]; 75 | a18 <= s_box[in[ 744 +: 8]]; 76 | a19 <= s_box[in[672 +: 8]]; 77 | a20 <= s_box[in[600 +: 8]]; 78 | a21 <= s_box[in[528 +: 8]]; 79 | a22 <= s_box[in[456 +: 8]]; 80 | a23 <= s_box[in[128 +: 8]]; 81 | a24 <= s_box[in[824 +: 8] ^ {4'h3,round}]; 82 | a25 <= s_box[in[ 752 +: 8]]; 83 | a26 <= s_box[in[680 +: 8]]; 84 | a27 <= s_box[in[608 +: 8]]; 85 | a28 <= s_box[in[536 +: 8]]; 86 | a29 <= s_box[in[464 +: 8]]; 87 | a30 <= s_box[in[392 +: 8]]; 88 | a31 <= s_box[in[ 64 +: 8]]; 89 | a32 <= s_box[in[ 760 +: 8] ^ {4'h4,round}]; 90 | a33 <= s_box[in[688 +: 8]]; 91 | a34 <= s_box[in[ 616 +: 8]]; 92 | a35 <= s_box[in[544 +: 8]]; 93 | a36 <= s_box[in[472 +: 8]]; 94 | a37 <= s_box[in[400 +: 8]]; 95 | a38 <= s_box[in[328 +: 8]]; 96 | a39 <= s_box[in[ 0 +: 8]]; 97 | a40 <= s_box[in[696 +: 8] ^ {4'h5,round}]; 98 | a41 <= s_box[in[ 624 +: 8]]; 99 | a42 <= s_box[in[552 +: 8]]; 100 | a43 <= s_box[in[480 +: 8]]; 101 | a44 <= s_box[in[408 +: 8]]; 102 | a45 <= s_box[in[336 +: 8]]; 103 | a46 <= s_box[in[264 +: 8]]; 104 | a47 <= s_box[in[960 +: 8]]; 105 | a48 <= s_box[in[ 632 +: 8] ^ {4'h6,round}]; 106 | a49 <= s_box[in[560 +: 8]]; 107 | a50 <= s_box[in[ 488 +: 8]]; 108 | a51 <= s_box[in[416 +: 8]]; 109 | a52 <= s_box[in[344 +: 8]]; 110 | a53 <= s_box[in[272 +: 8]]; 111 | a54 <= s_box[in[200 +: 8]]; 112 | a55 <= s_box[in[896 +: 8]]; 113 | a56 <= s_box[in[568 +: 8] ^ {4'h7,round}]; 114 | a57 <= s_box[in[ 496 +: 8]]; 115 | a58 <= s_box[in[424 +: 8]]; 116 | a59 <= s_box[in[352 +: 8]]; 117 | a60 <= s_box[in[280 +: 8]]; 118 | a61 <= s_box[in[208 +: 8]]; 119 | a62 <= s_box[in[136 +: 8]]; 120 | a63 <= s_box[in[832 +: 8]]; 121 | a64 <= s_box[in[ 504 +: 8] ^ {4'h8,round}]; 122 | a65 <= s_box[in[432 +: 8]]; 123 | a66 <= s_box[in[ 360 +: 8]]; 124 | a67 <= s_box[in[288 +: 8]]; 125 | a68 <= s_box[in[216 +: 8]]; 126 | a69 <= s_box[in[144 +: 8]]; 127 | a70 <= s_box[in[ 72 +: 8]]; 128 | a71 <= s_box[in[768 +: 8]]; 129 | a72 <= s_box[in[440 +: 8] ^ {4'h9,round}]; 130 | a73 <= s_box[in[ 368 +: 8]]; 131 | a74 <= s_box[in[296 +: 8]]; 132 | a75 <= s_box[in[224 +: 8]]; 133 | a76 <= s_box[in[152 +: 8]]; 134 | a77 <= s_box[in[ 80 +: 8]]; 135 | a78 <= s_box[in[ 8 +: 8]]; 136 | a79 <= s_box[in[704 +: 8]]; 137 | a80 <= s_box[in[ 376 +: 8] ^ {4'hA,round}]; 138 | a81 <= s_box[in[304 +: 8]]; 139 | a82 <= s_box[in[ 232 +: 8]]; 140 | a83 <= s_box[in[160 +: 8]]; 141 | a84 <= s_box[in[ 88 +: 8]]; 142 | a85 <= s_box[in[ 16 +: 8]]; 143 | a86 <= s_box[in[968 +: 8]]; 144 | a87 <= s_box[in[640 +: 8]]; 145 | a88 <= s_box[in[312 +: 8] ^ {4'hB,round}]; 146 | a89 <= s_box[in[ 240 +: 8]]; 147 | a90 <= s_box[in[168 +: 8]]; 148 | a91 <= s_box[in[ 96 +: 8]]; 149 | a92 <= s_box[in[ 24 +: 8]]; 150 | a93 <= s_box[in[976 +: 8]]; 151 | a94 <= s_box[in[904 +: 8]]; 152 | a95 <= s_box[in[576 +: 8]]; 153 | a96 <= s_box[in[ 248 +: 8] ^ {4'hC,round}]; 154 | a97 <= s_box[in[176 +: 8]]; 155 | a98 <= s_box[in[ 104 +: 8]]; 156 | a99 <= s_box[in[ 32 +: 8]]; 157 | a100 <= s_box[in[984 +: 8]]; 158 | a101 <= s_box[in[912 +: 8]]; 159 | a102 <= s_box[in[840 +: 8]]; 160 | a103 <= s_box[in[512 +: 8]]; 161 | a104 <= s_box[in[184 +: 8] ^ {4'hD,round}]; 162 | a105 <= s_box[in[ 112 +: 8]]; 163 | a106 <= s_box[in[ 40 +: 8]]; 164 | a107 <= s_box[in[992 +: 8]]; 165 | a108 <= s_box[in[920 +: 8]]; 166 | a109 <= s_box[in[848 +: 8]]; 167 | a110 <= s_box[in[776 +: 8]]; 168 | a111 <= s_box[in[448 +: 8]]; 169 | a112 <= s_box[in[ 120 +: 8] ^ {4'hE,round}]; 170 | a113 <= s_box[in[ 48 +: 8]]; 171 | a114 <= s_box[in[1000 +: 8]]; 172 | a115 <= s_box[in[928 +: 8]]; 173 | a116 <= s_box[in[856 +: 8]]; 174 | a117 <= s_box[in[784 +: 8]]; 175 | a118 <= s_box[in[712 +: 8]]; 176 | a119 <= s_box[in[384 +: 8]]; 177 | a120 <= s_box[in[ 56 +: 8] ^ {4'hF,round}]; 178 | a121 <= s_box[in[1008 +: 8]]; 179 | a122 <= s_box[in[936 +: 8]]; 180 | a123 <= s_box[in[864 +: 8]]; 181 | a124 <= s_box[in[792 +: 8]]; 182 | a125 <= s_box[in[720 +: 8]]; 183 | a126 <= s_box[in[648 +: 8]]; 184 | a127 <= s_box[in[320 +: 8]]; 185 | 186 | end 187 | 188 | always @ (posedge clk) begin 189 | 190 | t0 <= { 191 | a0, a1, a2, a3, a4, a5, a6, a7, a8, a9, a10,a11,a12,a13,a14,a15, 192 | a16,a17,a18,a19,a20,a21,a22,a23,a24,a25,a26,a27,a28,a29,a30,a31, 193 | a32,a33,a34,a35,a36,a37,a38,a39,a40,a41,a42,a43,a44,a45,a46,a47, 194 | a48,a49,a50,a51,a52,a53,a54,a55,a56,a57,a58,a59,a60,a61,a62,a63, 195 | a64,a65,a66,a67,a68,a69,a70,a71,a72,a73,a74,a75,a76,a77,a78,a79, 196 | a80,a81,a82,a83,a84,a85,a86,a87,a88,a89,a90,a91,a92,a93,a94,a95, 197 | a96,a97,a98,a99,a100,a101,a102,a103,a104,a105,a106,a107,a108,a109,a110,a111, 198 | a112,a113,a114,a115,a116,a117,a118,a119,a120,a121,a122,a123,a124,a125,a126,a127 199 | }; 200 | 201 | end 202 | 203 | mix_bytes mb00 (clk, t0, out); 204 | 205 | endmodule 206 | -------------------------------------------------------------------------------- /grs/permutation_q.v: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2016 Sprocket 3 | * 4 | * This is free software: you can redistribute it and/or modify 5 | * it under the terms of the GNU Affero General Public License with 6 | * additional permissions to the one published by the Free Software 7 | * Foundation, either version 3 of the License, or (at your option) 8 | * any later version. For more information see LICENSE. 9 | * 10 | * This program is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | * GNU Affero General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU Affero General Public License 16 | * along with this program. If not, see . 17 | */ 18 | 19 | module permutation_q ( 20 | input clk, 21 | input [3:0] round, 22 | input [1023:0] in, 23 | output [1023:0] out 24 | ); 25 | 26 | reg [1023:0] t0, t1; 27 | 28 | wire [7:0] s_box [0:255] = { 29 | 8'h63, 8'h7C, 8'h77, 8'h7B, 8'hF2, 8'h6B, 8'h6F, 8'hC5, 8'h30, 8'h01, 8'h67, 8'h2B, 8'hFE, 8'hD7, 8'hAB, 8'h76, 30 | 8'hCA, 8'h82, 8'hC9, 8'h7D, 8'hFA, 8'h59, 8'h47, 8'hF0, 8'hAD, 8'hD4, 8'hA2, 8'hAF, 8'h9C, 8'hA4, 8'h72, 8'hC0, 31 | 8'hB7, 8'hFD, 8'h93, 8'h26, 8'h36, 8'h3F, 8'hF7, 8'hCC, 8'h34, 8'hA5, 8'hE5, 8'hF1, 8'h71, 8'hD8, 8'h31, 8'h15, 32 | 8'h04, 8'hC7, 8'h23, 8'hC3, 8'h18, 8'h96, 8'h05, 8'h9A, 8'h07, 8'h12, 8'h80, 8'hE2, 8'hEB, 8'h27, 8'hB2, 8'h75, 33 | 8'h09, 8'h83, 8'h2C, 8'h1A, 8'h1B, 8'h6E, 8'h5A, 8'hA0, 8'h52, 8'h3B, 8'hD6, 8'hB3, 8'h29, 8'hE3, 8'h2F, 8'h84, 34 | 8'h53, 8'hD1, 8'h00, 8'hED, 8'h20, 8'hFC, 8'hB1, 8'h5B, 8'h6A, 8'hCB, 8'hBE, 8'h39, 8'h4A, 8'h4C, 8'h58, 8'hCF, 35 | 8'hD0, 8'hEF, 8'hAA, 8'hFB, 8'h43, 8'h4D, 8'h33, 8'h85, 8'h45, 8'hF9, 8'h02, 8'h7F, 8'h50, 8'h3C, 8'h9F, 8'hA8, 36 | 8'h51, 8'hA3, 8'h40, 8'h8F, 8'h92, 8'h9D, 8'h38, 8'hF5, 8'hBC, 8'hB6, 8'hDA, 8'h21, 8'h10, 8'hFF, 8'hF3, 8'hD2, 37 | 8'hCD, 8'h0C, 8'h13, 8'hEC, 8'h5F, 8'h97, 8'h44, 8'h17, 8'hC4, 8'hA7, 8'h7E, 8'h3D, 8'h64, 8'h5D, 8'h19, 8'h73, 38 | 8'h60, 8'h81, 8'h4F, 8'hDC, 8'h22, 8'h2A, 8'h90, 8'h88, 8'h46, 8'hEE, 8'hB8, 8'h14, 8'hDE, 8'h5E, 8'h0B, 8'hDB, 39 | 8'hE0, 8'h32, 8'h3A, 8'h0A, 8'h49, 8'h06, 8'h24, 8'h5C, 8'hC2, 8'hD3, 8'hAC, 8'h62, 8'h91, 8'h95, 8'hE4, 8'h79, 40 | 8'hE7, 8'hC8, 8'h37, 8'h6D, 8'h8D, 8'hD5, 8'h4E, 8'hA9, 8'h6C, 8'h56, 8'hF4, 8'hEA, 8'h65, 8'h7A, 8'hAE, 8'h08, 41 | 8'hBA, 8'h78, 8'h25, 8'h2E, 8'h1C, 8'hA6, 8'hB4, 8'hC6, 8'hE8, 8'hDD, 8'h74, 8'h1F, 8'h4B, 8'hBD, 8'h8B, 8'h8A, 42 | 8'h70, 8'h3E, 8'hB5, 8'h66, 8'h48, 8'h03, 8'hF6, 8'h0E, 8'h61, 8'h35, 8'h57, 8'hB9, 8'h86, 8'hC1, 8'h1D, 8'h9E, 43 | 8'hE1, 8'hF8, 8'h98, 8'h11, 8'h69, 8'hD9, 8'h8E, 8'h94, 8'h9B, 8'h1E, 8'h87, 8'hE9, 8'hCE, 8'h55, 8'h28, 8'hDF, 44 | 8'h8C, 8'hA1, 8'h89, 8'h0D, 8'hBF, 8'hE6, 8'h42, 8'h68, 8'h41, 8'h99, 8'h2D, 8'h0F, 8'hB0, 8'h54, 8'hBB, 8'h16 45 | }; 46 | 47 | reg [7:0] a0, a1, a2, a3, a4, a5, a6, a7, a8, a9, a10,a11,a12,a13,a14,a15; 48 | reg [7:0] a16,a17,a18,a19,a20,a21,a22,a23,a24,a25,a26,a27,a28,a29,a30,a31; 49 | reg [7:0] a32,a33,a34,a35,a36,a37,a38,a39,a40,a41,a42,a43,a44,a45,a46,a47; 50 | reg [7:0] a48,a49,a50,a51,a52,a53,a54,a55,a56,a57,a58,a59,a60,a61,a62,a63; 51 | reg [7:0] a64,a65,a66,a67,a68,a69,a70,a71,a72,a73,a74,a75,a76,a77,a78,a79; 52 | reg [7:0] a80,a81,a82,a83,a84,a85,a86,a87,a88,a89,a90,a91,a92,a93,a94,a95; 53 | reg [7:0] a96,a97,a98,a99,a100,a101,a102,a103,a104,a105,a106,a107,a108,a109,a110,a111; 54 | reg [7:0] a112,a113,a114,a115,a116,a117,a118,a119,a120,a121,a122,a123,a124,a125,a126,a127; 55 | 56 | always @ (*) begin 57 | 58 | a0 <= s_box[in[952 +: 8]]; 59 | a1 <= s_box[in[816 +: 8]]; 60 | a2 <= s_box[in[680 +: 8]]; 61 | a3 <= s_box[in[288 +: 8]]; 62 | a4 <= s_box[in[984 +: 8]]; 63 | a5 <= s_box[in[848 +: 8]]; 64 | a6 <= s_box[in[712 +: 8]]; 65 | a7 <= s_box[~in[576 +: 8] ^ { 4'h9, 4'hF - round } ]; 66 | a8 <= s_box[in[888 +: 8]]; 67 | a9 <= s_box[in[752 +: 8]]; 68 | a10 <= s_box[in[616 +: 8]]; 69 | a11 <= s_box[in[224 +: 8]]; 70 | a12 <= s_box[in[920 +: 8]]; 71 | a13 <= s_box[in[784 +: 8]]; 72 | a14 <= s_box[in[648 +: 8]]; 73 | a15 <= s_box[~in[512 +: 8] ^ { 4'h8, 4'hF - round } ]; 74 | a16 <= s_box[in[824 +: 8]]; 75 | a17 <= s_box[in[688 +: 8]]; 76 | a18 <= s_box[in[552 +: 8]]; 77 | a19 <= s_box[in[160 +: 8]]; 78 | a20 <= s_box[in[856 +: 8]]; 79 | a21 <= s_box[in[720 +: 8]]; 80 | a22 <= s_box[in[584 +: 8]]; 81 | a23 <= s_box[~in[448 +: 8] ^ { 4'h7, 4'hF - round } ]; 82 | a24 <= s_box[in[760 +: 8]]; 83 | a25 <= s_box[in[624 +: 8]]; 84 | a26 <= s_box[in[488 +: 8]]; 85 | a27 <= s_box[in[96 +: 8]]; 86 | a28 <= s_box[in[792 +: 8]]; 87 | a29 <= s_box[in[656 +: 8]]; 88 | a30 <= s_box[in[520 +: 8]]; 89 | a31 <= s_box[~in[384 +: 8] ^ { 4'h6, 4'hF - round } ]; 90 | a32 <= s_box[in[696 +: 8]]; 91 | a33 <= s_box[in[560 +: 8]]; 92 | a34 <= s_box[in[424 +: 8]]; 93 | a35 <= s_box[in[32 +: 8]]; 94 | a36 <= s_box[in[728 +: 8]]; 95 | a37 <= s_box[in[592 +: 8]]; 96 | a38 <= s_box[in[456 +: 8]]; 97 | a39 <= s_box[~in[320 +: 8] ^ { 4'h5, 4'hF - round } ]; 98 | a40 <= s_box[in[632 +: 8]]; 99 | a41 <= s_box[in[496 +: 8]]; 100 | a42 <= s_box[in[360 +: 8]]; 101 | a43 <= s_box[in[992 +: 8]]; 102 | a44 <= s_box[in[664 +: 8]]; 103 | a45 <= s_box[in[528 +: 8]]; 104 | a46 <= s_box[in[392 +: 8]]; 105 | a47 <= s_box[~in[256 +: 8] ^ { 4'h4, 4'hF - round } ]; 106 | a48 <= s_box[in[568 +: 8]]; 107 | a49 <= s_box[in[432 +: 8]]; 108 | a50 <= s_box[in[296 +: 8]]; 109 | a51 <= s_box[in[928 +: 8]]; 110 | a52 <= s_box[in[600 +: 8]]; 111 | a53 <= s_box[in[464 +: 8]]; 112 | a54 <= s_box[in[328 +: 8]]; 113 | a55 <= s_box[~in[192 +: 8] ^ { 4'h3, 4'hF - round } ]; 114 | a56 <= s_box[in[504 +: 8]]; 115 | a57 <= s_box[in[368 +: 8]]; 116 | a58 <= s_box[in[232 +: 8]]; 117 | a59 <= s_box[in[864 +: 8]]; 118 | a60 <= s_box[in[536 +: 8]]; 119 | a61 <= s_box[in[400 +: 8]]; 120 | a62 <= s_box[in[264 +: 8]]; 121 | a63 <= s_box[~in[128 +: 8] ^ { 4'h2, 4'hF - round } ]; 122 | a64 <= s_box[in[440 +: 8]]; 123 | a65 <= s_box[in[304 +: 8]]; 124 | a66 <= s_box[in[168 +: 8]]; 125 | a67 <= s_box[in[800 +: 8]]; 126 | a68 <= s_box[in[472 +: 8]]; 127 | a69 <= s_box[in[336 +: 8]]; 128 | a70 <= s_box[in[200 +: 8]]; 129 | a71 <= s_box[~in[64 +: 8] ^ { 4'h1, 4'hF - round } ]; 130 | a72 <= s_box[in[376 +: 8]]; 131 | a73 <= s_box[in[240 +: 8]]; 132 | a74 <= s_box[in[104 +: 8]]; 133 | a75 <= s_box[in[736 +: 8]]; 134 | a76 <= s_box[in[408 +: 8]]; 135 | a77 <= s_box[in[272 +: 8]]; 136 | a78 <= s_box[in[136 +: 8]]; 137 | a79 <= s_box[~in[0 +: 8] ^ { 4'h0, 4'hF - round } ]; 138 | a80 <= s_box[in[312 +: 8]]; 139 | a81 <= s_box[in[176 +: 8]]; 140 | a82 <= s_box[in[40 +: 8]]; 141 | a83 <= s_box[in[672 +: 8]]; 142 | a84 <= s_box[in[344 +: 8]]; 143 | a85 <= s_box[in[208 +: 8]]; 144 | a86 <= s_box[in[72 +: 8]]; 145 | a87 <= s_box[~in[960 +: 8] ^ { 4'hF, 4'hF - round } ]; 146 | a88 <= s_box[in[248 +: 8]]; 147 | a89 <= s_box[in[112 +: 8]]; 148 | a90 <= s_box[in[1000 +: 8]]; 149 | a91 <= s_box[in[608 +: 8]]; 150 | a92 <= s_box[in[280 +: 8]]; 151 | a93 <= s_box[in[144 +: 8]]; 152 | a94 <= s_box[in[8 +: 8]]; 153 | a95 <= s_box[~in[896 +: 8] ^ { 4'hE, 4'hF - round } ]; 154 | a96 <= s_box[in[184 +: 8]]; 155 | a97 <= s_box[in[48 +: 8]]; 156 | a98 <= s_box[in[936 +: 8]]; 157 | a99 <= s_box[in[544 +: 8]]; 158 | a100 <= s_box[in[216 +: 8]]; 159 | a101 <= s_box[in[80 +: 8]]; 160 | a102 <= s_box[in[968 +: 8]]; 161 | a103 <= s_box[~in[832 +: 8] ^ { 4'hD, 4'hF - round } ]; 162 | a104 <= s_box[in[120 +: 8]]; 163 | a105 <= s_box[in[1008 +: 8]]; 164 | a106 <= s_box[in[872 +: 8]]; 165 | a107 <= s_box[in[480 +: 8]]; 166 | a108 <= s_box[in[152 +: 8]]; 167 | a109 <= s_box[in[16 +: 8]]; 168 | a110 <= s_box[in[904 +: 8]]; 169 | a111 <= s_box[~in[768 +: 8] ^ { 4'hC, 4'hF - round } ]; 170 | a112 <= s_box[in[56 +: 8]]; 171 | a113 <= s_box[in[944 +: 8]]; 172 | a114 <= s_box[in[808 +: 8]]; 173 | a115 <= s_box[in[416 +: 8]]; 174 | a116 <= s_box[in[88 +: 8]]; 175 | a117 <= s_box[in[976 +: 8]]; 176 | a118 <= s_box[in[840 +: 8]]; 177 | a119 <= s_box[~in[704 +: 8] ^ { 4'hB, 4'hF - round } ]; 178 | a120 <= s_box[in[1016 +: 8]]; 179 | a121 <= s_box[in[880 +: 8]]; 180 | a122 <= s_box[in[744 +: 8]]; 181 | a123 <= s_box[in[352 +: 8]]; 182 | a124 <= s_box[in[24 +: 8]]; 183 | a125 <= s_box[in[912 +: 8]]; 184 | a126 <= s_box[in[776 +: 8]]; 185 | a127 <= s_box[~in[640 +: 8] ^ { 4'hA, 4'hF - round } ]; 186 | 187 | end 188 | 189 | always @ (*) begin 190 | 191 | t0 <= { 192 | a0, a1, a2, a3, a4, a5, a6, a7, a8, a9, a10,a11,a12,a13,a14,a15, 193 | a16,a17,a18,a19,a20,a21,a22,a23,a24,a25,a26,a27,a28,a29,a30,a31, 194 | a32,a33,a34,a35,a36,a37,a38,a39,a40,a41,a42,a43,a44,a45,a46,a47, 195 | a48,a49,a50,a51,a52,a53,a54,a55,a56,a57,a58,a59,a60,a61,a62,a63, 196 | a64,a65,a66,a67,a68,a69,a70,a71,a72,a73,a74,a75,a76,a77,a78,a79, 197 | a80,a81,a82,a83,a84,a85,a86,a87,a88,a89,a90,a91,a92,a93,a94,a95, 198 | a96,a97,a98,a99,a100,a101,a102,a103,a104,a105,a106,a107,a108,a109,a110,a111, 199 | a112,a113,a114,a115,a116,a117,a118,a119,a120,a121,a122,a123,a124,a125,a126,a127 200 | }; 201 | 202 | end 203 | 204 | always @ (posedge clk) begin 205 | 206 | t1 <= t0; 207 | 208 | end 209 | 210 | mix_bytes mb00 (clk, t1, out); 211 | 212 | endmodule 213 | -------------------------------------------------------------------------------- /myr_grs/cl_common_defines.vh: -------------------------------------------------------------------------------- 1 | // Amazon FPGA Hardware Development Kit 2 | // 3 | // Copyright 2016 Amazon.com, Inc. or its affiliates. All Rights Reserved. 4 | // 5 | // Licensed under the Amazon Software License (the "License"). You may not use 6 | // this file except in compliance with the License. A copy of the License is 7 | // located at 8 | // 9 | // http://aws.amazon.com/asl/ 10 | // 11 | // or in the "license" file accompanying this file. This file is distributed on 12 | // an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, express or 13 | // implied. See the License for the specific language governing permissions and 14 | // limitations under the License. 15 | 16 | `ifndef CL_COMMON_DEFAULTS 17 | `define CL_COMMON_DEFAULTS 18 | 19 | // Value to return for PCIS access to unimplemented register address 20 | `define UNIMPLEMENTED_REG_VALUE 32'hdeaddead 21 | 22 | // CL Register Addresses 23 | `define HELLO_WORLD_REG_ADDR 32'h0000_0500 24 | `define VLED_REG_ADDR 32'h0000_0504 25 | 26 | `endif 27 | -------------------------------------------------------------------------------- /myr_grs/cl_id_defines.vh: -------------------------------------------------------------------------------- 1 | // Amazon FPGA Hardware Development Kit 2 | // 3 | // Copyright 2016 Amazon.com, Inc. or its affiliates. All Rights Reserved. 4 | // 5 | // Licensed under the Amazon Software License (the "License"). You may not use 6 | // this file except in compliance with the License. A copy of the License is 7 | // located at 8 | // 9 | // http://aws.amazon.com/asl/ 10 | // 11 | // or in the "license" file accompanying this file. This file is distributed on 12 | // an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, express or 13 | // implied. See the License for the specific language governing permissions and 14 | // limitations under the License. 15 | 16 | // CL_SH_ID0 17 | // - PCIe Vendor/Device ID Values 18 | // 31:16: PCIe Device ID 19 | // 15: 0: PCIe Vendor ID 20 | // - A Vendor ID value of 0x8086 is not valid. 21 | // - If using a Vendor ID value of 0x1D0F (Amazon) then valid 22 | // values for Device ID's are in the range of 0xF000 - 0xF0FF. 23 | // - A Vendor/Device ID of 0 (zero) is not valid. 24 | `define CL_SH_ID0 32'hF000_1D0F 25 | 26 | // CL_SH_ID1 27 | // - PCIe Subsystem/Subsystem Vendor ID Values 28 | // 31:16: PCIe Subsystem ID 29 | // 15: 0: PCIe Subsystem Vendor ID 30 | // - A PCIe Subsystem/Subsystem Vendor ID of 0 (zero) is not valid 31 | `define CL_SH_ID1 32'h1D51_FEDD 32 | -------------------------------------------------------------------------------- /myr_grs/cl_miner_defines.vh: -------------------------------------------------------------------------------- 1 | // Amazon FPGA Hardware Development Kit 2 | // 3 | // Copyright 2016 Amazon.com, Inc. or its affiliates. All Rights Reserved. 4 | // 5 | // Licensed under the Amazon Software License (the "License"). You may not use 6 | // this file except in compliance with the License. A copy of the License is 7 | // located at 8 | // 9 | // http://aws.amazon.com/asl/ 10 | // 11 | // or in the "license" file accompanying this file. This file is distributed on 12 | // an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, express or 13 | // implied. See the License for the specific language governing permissions and 14 | // limitations under the License. 15 | 16 | `ifndef CL_MINER_DEFINES 17 | `define CL_MINER_DEFINES 18 | 19 | //Put module name of the CL design here. This is used to instantiate in top.sv 20 | `define CL_NAME cl_miner 21 | 22 | //Highly recommeneded. For lib FIFO block, uses less async reset (take advantage of 23 | // FPGA flop init capability). This will help with routing resources. 24 | `define FPGA_LESS_RST 25 | 26 | // Uncomment to disable Virtual JTAG 27 | //`define DISABLE_VJTAG_DEBUG 28 | 29 | `endif -------------------------------------------------------------------------------- /myr_grs/miner.v: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2017 Sprocket 3 | * 4 | * This is free software: you can redistribute it and/or modify 5 | * it under the terms of the GNU Affero General Public License with 6 | * additional permissions to the one published by the Free Software 7 | * Foundation, either version 3 of the License, or (at your option) 8 | * any later version. For more information see LICENSE. 9 | * 10 | * This program is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | * GNU Affero General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU Affero General Public License 16 | * along with this program. If not, see . 17 | */ 18 | 19 | module miner # ( 20 | parameter CORES = 32'd1 21 | ) ( 22 | input clk, 23 | input reset, 24 | input [639:0] block, 25 | input [31:0] nonce_start, 26 | output nonce_found, 27 | output [31:0] nonce_out 28 | ); 29 | 30 | localparam OFFSET = 32'd341; 31 | 32 | wire [511:0] hash1; 33 | wire [255:0] hash2; 34 | wire [31:0] hash3; 35 | 36 | reg reset_d, reset_q; 37 | reg [607:0] block_d, block_q; 38 | reg [31:0] target_d, target_q; 39 | reg [31:0] nonce_d, nonce_q; 40 | reg [31:0] nonce_out_d, nonce_out_q; 41 | reg nonce_found_d, nonce_found_q; 42 | 43 | reg [511:0] hash1_d, hash1_q; 44 | reg [255:0] hash2_d, hash2_q; 45 | 46 | assign nonce_found = nonce_found_q; 47 | assign nonce_out = nonce_out_q; 48 | 49 | grostl512 grostl ( clk, block_q, nonce_q, hash1 ); 50 | sha256_pipe130 sha256_1 ( clk, hash1_q, hash2 ); 51 | sha256_pipe123 sha256_2 ( clk, hash2_q, hash3 ); 52 | 53 | always @ ( * ) begin 54 | 55 | if ( reset_q ) begin 56 | 57 | block_d <= block[639:32]; 58 | target_d <= block[31:0]; 59 | 60 | nonce_d <= nonce_start; 61 | 62 | nonce_found_d <= 1'b0; 63 | nonce_out_d <= 32'd0; 64 | 65 | end 66 | else begin 67 | 68 | block_d <= block_q; 69 | target_d <= target_q; 70 | nonce_d <= nonce_q + CORES; 71 | 72 | nonce_out_d <= nonce_q - (CORES * OFFSET); 73 | 74 | if ( hash3 <= target_d ) 75 | nonce_found_d <= 1'b1; 76 | else 77 | nonce_found_d <= 1'b0; 78 | 79 | end 80 | 81 | hash1_d <= hash1; 82 | hash2_d <= hash2; 83 | 84 | reset_d <= reset; 85 | 86 | end 87 | 88 | always @ (posedge clk) begin 89 | 90 | block_q <= block_d; 91 | target_q <= target_d; 92 | 93 | nonce_q <= nonce_d; 94 | nonce_out_q <= nonce_out_d; 95 | 96 | nonce_found_q <= nonce_found_d; 97 | 98 | hash1_q <= hash1_d; 99 | hash2_q <= hash2_d; 100 | 101 | reset_q <= reset_d; 102 | 103 | $display("Hash: %x", hash3); 104 | 105 | end 106 | 107 | endmodule 108 | -------------------------------------------------------------------------------- /myr_grs/mix_bytes.v: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2016 Sprocket 3 | * 4 | * This is free software: you can redistribute it and/or modify 5 | * it under the terms of the GNU Affero General Public License with 6 | * additional permissions to the one published by the Free Software 7 | * Foundation, either version 3 of the License, or (at your option) 8 | * any later version. For more information see LICENSE. 9 | * 10 | * This program is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | * GNU Affero General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU Affero General Public License 16 | * along with this program. If not, see . 17 | */ 18 | 19 | module mix_bytes( 20 | input clk, 21 | input [1023:0] in, 22 | output [1023:0] out 23 | ); 24 | 25 | wire [63:0] m0, m1, m2, m3, m4, m5, m6, m7; 26 | wire [63:0] m8, m9, m10,m11,m12,m13,m14,m15; 27 | 28 | mix_chunk mc0 (clk, in[1023:960], m0); 29 | mix_chunk mc1 (clk, in[959:896], m1); 30 | mix_chunk mc2 (clk, in[895:832], m2); 31 | mix_chunk mc3 (clk, in[831:768], m3); 32 | mix_chunk mc4 (clk, in[767:704], m4); 33 | mix_chunk mc5 (clk, in[703:640], m5); 34 | mix_chunk mc6 (clk, in[639:576], m6); 35 | mix_chunk mc7 (clk, in[575:512], m7); 36 | mix_chunk mc8 (clk, in[511:448], m8); 37 | mix_chunk mc9 (clk, in[447:384], m9); 38 | mix_chunk mc10 (clk, in[383:320], m10); 39 | mix_chunk mc11 (clk, in[319:256], m11); 40 | mix_chunk mc12 (clk, in[255:192], m12); 41 | mix_chunk mc13 (clk, in[191:128], m13); 42 | mix_chunk mc14 (clk, in[127: 64], m14); 43 | mix_chunk mc15 (clk, in[ 63: 0], m15); 44 | 45 | assign out = {m0,m1,m2,m3,m4,m5,m6,m7,m8,m9,m10,m11,m12,m13,m14,m15}; 46 | 47 | endmodule 48 | 49 | module mix_chunk ( 50 | input clk, 51 | input [63:0] in, 52 | output reg [63:0] out 53 | ); 54 | 55 | wire [7:0] b0,b1,b2,b3,b4,b5,b6,b7; 56 | wire [7:0] o0,o1,o2,o3,o4,o5,o6,o7; 57 | 58 | assign {b0,b1,b2,b3,b4,b5,b6,b7} = in; 59 | 60 | mix_chunk2 mc0 (b0,b1,b2,b3,b4,b5,b6,b7,o0); 61 | mix_chunk2 mc1 (b1,b2,b3,b4,b5,b6,b7,b0,o1); 62 | mix_chunk2 mc2 (b2,b3,b4,b5,b6,b7,b0,b1,o2); 63 | mix_chunk2 mc3 (b3,b4,b5,b6,b7,b0,b1,b2,o3); 64 | mix_chunk2 mc4 (b4,b5,b6,b7,b0,b1,b2,b3,o4); 65 | mix_chunk2 mc5 (b5,b6,b7,b0,b1,b2,b3,b4,o5); 66 | mix_chunk2 mc6 (b6,b7,b0,b1,b2,b3,b4,b5,o6); 67 | mix_chunk2 mc7 (b7,b0,b1,b2,b3,b4,b5,b6,o7); 68 | 69 | reg [63:0] o; 70 | 71 | always @ (*) begin 72 | o <= { o0, o1, o2, o3, o4, o5, o6, o7 }; 73 | end 74 | 75 | always @ (posedge clk) begin 76 | out <= o; 77 | end 78 | 79 | endmodule 80 | 81 | module mix_chunk2( 82 | input [7:0] in0, 83 | input [7:0] in1, 84 | input [7:0] in2, 85 | input [7:0] in3, 86 | input [7:0] in4, 87 | input [7:0] in5, 88 | input [7:0] in6, 89 | input [7:0] in7, 90 | output [7:0] out 91 | ); 92 | 93 | assign out = mult_2(in0) ^ mult_2(in1) ^ mult_3(in2) ^ mult_4(in3) ^ mult_5(in4) ^ mult_3(in5) ^ mult_5(in6) ^ mult_7(in7); 94 | 95 | // Calculate GF(256) Multiplication (x2) 96 | function [7:0] mult_2; 97 | input [7:0] n; 98 | begin 99 | mult_2 = {n[6],n[5],n[4],n[3]^n[7],n[2]^n[7],n[1],n[0]^n[7],n[7]}; 100 | end 101 | endfunction 102 | 103 | // Calculate GF(256) Multiplication (x3) 104 | function [7:0] mult_3; 105 | input [7:0] n; 106 | begin 107 | mult_3 = {n[6]^n[7],n[5]^n[6],n[4]^n[5],n[3]^n[7]^n[4],n[2]^n[7]^n[3],n[1]^n[2],n[0]^n[7]^n[1],n[7]^n[0]}; 108 | end 109 | endfunction 110 | 111 | // Calculate GF(256) Multiplication (x4) 112 | function [7:0] mult_4; 113 | input [7:0] n; 114 | begin 115 | mult_4 = {n[5],n[4],n[3]^n[7],n[2]^n[7]^n[6],n[6]^n[1],n[0]^n[7],n[6]^n[7],n[6]}; 116 | end 117 | endfunction 118 | 119 | // Calculate GF(256) Multiplication (x5) 120 | function [7:0] mult_5; 121 | input [7:0] n; 122 | begin 123 | mult_5 = {n[5]^n[7],n[4]^n[6],n[3]^n[7]^n[5],n[2]^n[7]^n[6]^n[4],n[6]^n[1]^n[3],n[0]^n[7]^n[2],n[6]^n[7]^n[1],n[6]^n[0]}; 124 | end 125 | endfunction 126 | 127 | // Calculate GF(256) Multiplication (x7) 128 | function [7:0] mult_7; 129 | input [7:0] n; 130 | begin 131 | mult_7 = {n[5]^n[7]^n[6],n[4]^n[6]^n[5],n[3]^n[7]^n[5]^n[4],n[2]^n[7]^n[6]^n[4]^n[3]^n[7],n[6]^n[1]^n[3]^n[2]^n[7],n[0]^n[7]^n[2]^n[1],n[6]^n[7]^n[1]^n[0]^n[7],n[6]^n[0]^n[7]}; 132 | end 133 | endfunction 134 | 135 | endmodule 136 | -------------------------------------------------------------------------------- /myr_grs/permutation_p.v: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2016 Sprocket 3 | * 4 | * This is free software: you can redistribute it and/or modify 5 | * it under the terms of the GNU Affero General Public License with 6 | * additional permissions to the one published by the Free Software 7 | * Foundation, either version 3 of the License, or (at your option) 8 | * any later version. For more information see LICENSE. 9 | * 10 | * This program is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | * GNU Affero General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU Affero General Public License 16 | * along with this program. If not, see . 17 | */ 18 | module permutation_p ( 19 | input clk, 20 | input [3:0] round, 21 | input [1023:0] in, 22 | output [1023:0] out 23 | ); 24 | 25 | reg [1023:0] t0; 26 | 27 | wire [7:0] s_box [0:255] = { 28 | 8'h63, 8'h7C, 8'h77, 8'h7B, 8'hF2, 8'h6B, 8'h6F, 8'hC5, 8'h30, 8'h01, 8'h67, 8'h2B, 8'hFE, 8'hD7, 8'hAB, 8'h76, 29 | 8'hCA, 8'h82, 8'hC9, 8'h7D, 8'hFA, 8'h59, 8'h47, 8'hF0, 8'hAD, 8'hD4, 8'hA2, 8'hAF, 8'h9C, 8'hA4, 8'h72, 8'hC0, 30 | 8'hB7, 8'hFD, 8'h93, 8'h26, 8'h36, 8'h3F, 8'hF7, 8'hCC, 8'h34, 8'hA5, 8'hE5, 8'hF1, 8'h71, 8'hD8, 8'h31, 8'h15, 31 | 8'h04, 8'hC7, 8'h23, 8'hC3, 8'h18, 8'h96, 8'h05, 8'h9A, 8'h07, 8'h12, 8'h80, 8'hE2, 8'hEB, 8'h27, 8'hB2, 8'h75, 32 | 8'h09, 8'h83, 8'h2C, 8'h1A, 8'h1B, 8'h6E, 8'h5A, 8'hA0, 8'h52, 8'h3B, 8'hD6, 8'hB3, 8'h29, 8'hE3, 8'h2F, 8'h84, 33 | 8'h53, 8'hD1, 8'h00, 8'hED, 8'h20, 8'hFC, 8'hB1, 8'h5B, 8'h6A, 8'hCB, 8'hBE, 8'h39, 8'h4A, 8'h4C, 8'h58, 8'hCF, 34 | 8'hD0, 8'hEF, 8'hAA, 8'hFB, 8'h43, 8'h4D, 8'h33, 8'h85, 8'h45, 8'hF9, 8'h02, 8'h7F, 8'h50, 8'h3C, 8'h9F, 8'hA8, 35 | 8'h51, 8'hA3, 8'h40, 8'h8F, 8'h92, 8'h9D, 8'h38, 8'hF5, 8'hBC, 8'hB6, 8'hDA, 8'h21, 8'h10, 8'hFF, 8'hF3, 8'hD2, 36 | 8'hCD, 8'h0C, 8'h13, 8'hEC, 8'h5F, 8'h97, 8'h44, 8'h17, 8'hC4, 8'hA7, 8'h7E, 8'h3D, 8'h64, 8'h5D, 8'h19, 8'h73, 37 | 8'h60, 8'h81, 8'h4F, 8'hDC, 8'h22, 8'h2A, 8'h90, 8'h88, 8'h46, 8'hEE, 8'hB8, 8'h14, 8'hDE, 8'h5E, 8'h0B, 8'hDB, 38 | 8'hE0, 8'h32, 8'h3A, 8'h0A, 8'h49, 8'h06, 8'h24, 8'h5C, 8'hC2, 8'hD3, 8'hAC, 8'h62, 8'h91, 8'h95, 8'hE4, 8'h79, 39 | 8'hE7, 8'hC8, 8'h37, 8'h6D, 8'h8D, 8'hD5, 8'h4E, 8'hA9, 8'h6C, 8'h56, 8'hF4, 8'hEA, 8'h65, 8'h7A, 8'hAE, 8'h08, 40 | 8'hBA, 8'h78, 8'h25, 8'h2E, 8'h1C, 8'hA6, 8'hB4, 8'hC6, 8'hE8, 8'hDD, 8'h74, 8'h1F, 8'h4B, 8'hBD, 8'h8B, 8'h8A, 41 | 8'h70, 8'h3E, 8'hB5, 8'h66, 8'h48, 8'h03, 8'hF6, 8'h0E, 8'h61, 8'h35, 8'h57, 8'hB9, 8'h86, 8'hC1, 8'h1D, 8'h9E, 42 | 8'hE1, 8'hF8, 8'h98, 8'h11, 8'h69, 8'hD9, 8'h8E, 8'h94, 8'h9B, 8'h1E, 8'h87, 8'hE9, 8'hCE, 8'h55, 8'h28, 8'hDF, 43 | 8'h8C, 8'hA1, 8'h89, 8'h0D, 8'hBF, 8'hE6, 8'h42, 8'h68, 8'h41, 8'h99, 8'h2D, 8'h0F, 8'hB0, 8'h54, 8'hBB, 8'h16 44 | }; 45 | 46 | reg [7:0] a0, a1, a2, a3, a4, a5, a6, a7, a8, a9, a10,a11,a12,a13,a14,a15; 47 | reg [7:0] a16,a17,a18,a19,a20,a21,a22,a23,a24,a25,a26,a27,a28,a29,a30,a31; 48 | reg [7:0] a32,a33,a34,a35,a36,a37,a38,a39,a40,a41,a42,a43,a44,a45,a46,a47; 49 | reg [7:0] a48,a49,a50,a51,a52,a53,a54,a55,a56,a57,a58,a59,a60,a61,a62,a63; 50 | reg [7:0] a64,a65,a66,a67,a68,a69,a70,a71,a72,a73,a74,a75,a76,a77,a78,a79; 51 | reg [7:0] a80,a81,a82,a83,a84,a85,a86,a87,a88,a89,a90,a91,a92,a93,a94,a95; 52 | reg [7:0] a96,a97,a98,a99,a100,a101,a102,a103,a104,a105,a106,a107,a108,a109,a110,a111; 53 | reg [7:0] a112,a113,a114,a115,a116,a117,a118,a119,a120,a121,a122,a123,a124,a125,a126,a127; 54 | 55 | always @ (*) begin 56 | 57 | a0 <= s_box[in[1016 +: 8] ^ {4'h0,round}]; 58 | a1 <= s_box[in[944 +: 8]]; 59 | a2 <= s_box[in[ 872 +: 8]]; 60 | a3 <= s_box[in[800 +: 8]]; 61 | a4 <= s_box[in[728 +: 8]]; 62 | a5 <= s_box[in[656 +: 8]]; 63 | a6 <= s_box[in[584 +: 8]]; 64 | a7 <= s_box[in[256 +: 8]]; 65 | a8 <= s_box[in[952 +: 8] ^ {4'h1,round}]; 66 | a9 <= s_box[in[ 880 +: 8]]; 67 | a10 <= s_box[in[808 +: 8]]; 68 | a11 <= s_box[in[736 +: 8]]; 69 | a12 <= s_box[in[664 +: 8]]; 70 | a13 <= s_box[in[592 +: 8]]; 71 | a14 <= s_box[in[520 +: 8]]; 72 | a15 <= s_box[in[192 +: 8]]; 73 | a16 <= s_box[in[ 888 +: 8] ^ {4'h2,round}]; 74 | a17 <= s_box[in[816 +: 8]]; 75 | a18 <= s_box[in[ 744 +: 8]]; 76 | a19 <= s_box[in[672 +: 8]]; 77 | a20 <= s_box[in[600 +: 8]]; 78 | a21 <= s_box[in[528 +: 8]]; 79 | a22 <= s_box[in[456 +: 8]]; 80 | a23 <= s_box[in[128 +: 8]]; 81 | a24 <= s_box[in[824 +: 8] ^ {4'h3,round}]; 82 | a25 <= s_box[in[ 752 +: 8]]; 83 | a26 <= s_box[in[680 +: 8]]; 84 | a27 <= s_box[in[608 +: 8]]; 85 | a28 <= s_box[in[536 +: 8]]; 86 | a29 <= s_box[in[464 +: 8]]; 87 | a30 <= s_box[in[392 +: 8]]; 88 | a31 <= s_box[in[ 64 +: 8]]; 89 | a32 <= s_box[in[ 760 +: 8] ^ {4'h4,round}]; 90 | a33 <= s_box[in[688 +: 8]]; 91 | a34 <= s_box[in[ 616 +: 8]]; 92 | a35 <= s_box[in[544 +: 8]]; 93 | a36 <= s_box[in[472 +: 8]]; 94 | a37 <= s_box[in[400 +: 8]]; 95 | a38 <= s_box[in[328 +: 8]]; 96 | a39 <= s_box[in[ 0 +: 8]]; 97 | a40 <= s_box[in[696 +: 8] ^ {4'h5,round}]; 98 | a41 <= s_box[in[ 624 +: 8]]; 99 | a42 <= s_box[in[552 +: 8]]; 100 | a43 <= s_box[in[480 +: 8]]; 101 | a44 <= s_box[in[408 +: 8]]; 102 | a45 <= s_box[in[336 +: 8]]; 103 | a46 <= s_box[in[264 +: 8]]; 104 | a47 <= s_box[in[960 +: 8]]; 105 | a48 <= s_box[in[ 632 +: 8] ^ {4'h6,round}]; 106 | a49 <= s_box[in[560 +: 8]]; 107 | a50 <= s_box[in[ 488 +: 8]]; 108 | a51 <= s_box[in[416 +: 8]]; 109 | a52 <= s_box[in[344 +: 8]]; 110 | a53 <= s_box[in[272 +: 8]]; 111 | a54 <= s_box[in[200 +: 8]]; 112 | a55 <= s_box[in[896 +: 8]]; 113 | a56 <= s_box[in[568 +: 8] ^ {4'h7,round}]; 114 | a57 <= s_box[in[ 496 +: 8]]; 115 | a58 <= s_box[in[424 +: 8]]; 116 | a59 <= s_box[in[352 +: 8]]; 117 | a60 <= s_box[in[280 +: 8]]; 118 | a61 <= s_box[in[208 +: 8]]; 119 | a62 <= s_box[in[136 +: 8]]; 120 | a63 <= s_box[in[832 +: 8]]; 121 | a64 <= s_box[in[ 504 +: 8] ^ {4'h8,round}]; 122 | a65 <= s_box[in[432 +: 8]]; 123 | a66 <= s_box[in[ 360 +: 8]]; 124 | a67 <= s_box[in[288 +: 8]]; 125 | a68 <= s_box[in[216 +: 8]]; 126 | a69 <= s_box[in[144 +: 8]]; 127 | a70 <= s_box[in[ 72 +: 8]]; 128 | a71 <= s_box[in[768 +: 8]]; 129 | a72 <= s_box[in[440 +: 8] ^ {4'h9,round}]; 130 | a73 <= s_box[in[ 368 +: 8]]; 131 | a74 <= s_box[in[296 +: 8]]; 132 | a75 <= s_box[in[224 +: 8]]; 133 | a76 <= s_box[in[152 +: 8]]; 134 | a77 <= s_box[in[ 80 +: 8]]; 135 | a78 <= s_box[in[ 8 +: 8]]; 136 | a79 <= s_box[in[704 +: 8]]; 137 | a80 <= s_box[in[ 376 +: 8] ^ {4'hA,round}]; 138 | a81 <= s_box[in[304 +: 8]]; 139 | a82 <= s_box[in[ 232 +: 8]]; 140 | a83 <= s_box[in[160 +: 8]]; 141 | a84 <= s_box[in[ 88 +: 8]]; 142 | a85 <= s_box[in[ 16 +: 8]]; 143 | a86 <= s_box[in[968 +: 8]]; 144 | a87 <= s_box[in[640 +: 8]]; 145 | a88 <= s_box[in[312 +: 8] ^ {4'hB,round}]; 146 | a89 <= s_box[in[ 240 +: 8]]; 147 | a90 <= s_box[in[168 +: 8]]; 148 | a91 <= s_box[in[ 96 +: 8]]; 149 | a92 <= s_box[in[ 24 +: 8]]; 150 | a93 <= s_box[in[976 +: 8]]; 151 | a94 <= s_box[in[904 +: 8]]; 152 | a95 <= s_box[in[576 +: 8]]; 153 | a96 <= s_box[in[ 248 +: 8] ^ {4'hC,round}]; 154 | a97 <= s_box[in[176 +: 8]]; 155 | a98 <= s_box[in[ 104 +: 8]]; 156 | a99 <= s_box[in[ 32 +: 8]]; 157 | a100 <= s_box[in[984 +: 8]]; 158 | a101 <= s_box[in[912 +: 8]]; 159 | a102 <= s_box[in[840 +: 8]]; 160 | a103 <= s_box[in[512 +: 8]]; 161 | a104 <= s_box[in[184 +: 8] ^ {4'hD,round}]; 162 | a105 <= s_box[in[ 112 +: 8]]; 163 | a106 <= s_box[in[ 40 +: 8]]; 164 | a107 <= s_box[in[992 +: 8]]; 165 | a108 <= s_box[in[920 +: 8]]; 166 | a109 <= s_box[in[848 +: 8]]; 167 | a110 <= s_box[in[776 +: 8]]; 168 | a111 <= s_box[in[448 +: 8]]; 169 | a112 <= s_box[in[ 120 +: 8] ^ {4'hE,round}]; 170 | a113 <= s_box[in[ 48 +: 8]]; 171 | a114 <= s_box[in[1000 +: 8]]; 172 | a115 <= s_box[in[928 +: 8]]; 173 | a116 <= s_box[in[856 +: 8]]; 174 | a117 <= s_box[in[784 +: 8]]; 175 | a118 <= s_box[in[712 +: 8]]; 176 | a119 <= s_box[in[384 +: 8]]; 177 | a120 <= s_box[in[ 56 +: 8] ^ {4'hF,round}]; 178 | a121 <= s_box[in[1008 +: 8]]; 179 | a122 <= s_box[in[936 +: 8]]; 180 | a123 <= s_box[in[864 +: 8]]; 181 | a124 <= s_box[in[792 +: 8]]; 182 | a125 <= s_box[in[720 +: 8]]; 183 | a126 <= s_box[in[648 +: 8]]; 184 | a127 <= s_box[in[320 +: 8]]; 185 | 186 | end 187 | 188 | always @ (posedge clk) begin 189 | 190 | t0 <= { 191 | a0, a1, a2, a3, a4, a5, a6, a7, a8, a9, a10,a11,a12,a13,a14,a15, 192 | a16,a17,a18,a19,a20,a21,a22,a23,a24,a25,a26,a27,a28,a29,a30,a31, 193 | a32,a33,a34,a35,a36,a37,a38,a39,a40,a41,a42,a43,a44,a45,a46,a47, 194 | a48,a49,a50,a51,a52,a53,a54,a55,a56,a57,a58,a59,a60,a61,a62,a63, 195 | a64,a65,a66,a67,a68,a69,a70,a71,a72,a73,a74,a75,a76,a77,a78,a79, 196 | a80,a81,a82,a83,a84,a85,a86,a87,a88,a89,a90,a91,a92,a93,a94,a95, 197 | a96,a97,a98,a99,a100,a101,a102,a103,a104,a105,a106,a107,a108,a109,a110,a111, 198 | a112,a113,a114,a115,a116,a117,a118,a119,a120,a121,a122,a123,a124,a125,a126,a127 199 | }; 200 | 201 | end 202 | 203 | mix_bytes mb00 (clk, t0, out); 204 | 205 | endmodule 206 | -------------------------------------------------------------------------------- /myr_grs/permutation_q.v: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2016 Sprocket 3 | * 4 | * This is free software: you can redistribute it and/or modify 5 | * it under the terms of the GNU Affero General Public License with 6 | * additional permissions to the one published by the Free Software 7 | * Foundation, either version 3 of the License, or (at your option) 8 | * any later version. For more information see LICENSE. 9 | * 10 | * This program is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | * GNU Affero General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU Affero General Public License 16 | * along with this program. If not, see . 17 | */ 18 | 19 | module permutation_q ( 20 | input clk, 21 | input [3:0] round, 22 | input [1023:0] in, 23 | output [1023:0] out 24 | ); 25 | 26 | reg [1023:0] t0, t1; 27 | 28 | wire [7:0] s_box [0:255] = { 29 | 8'h63, 8'h7C, 8'h77, 8'h7B, 8'hF2, 8'h6B, 8'h6F, 8'hC5, 8'h30, 8'h01, 8'h67, 8'h2B, 8'hFE, 8'hD7, 8'hAB, 8'h76, 30 | 8'hCA, 8'h82, 8'hC9, 8'h7D, 8'hFA, 8'h59, 8'h47, 8'hF0, 8'hAD, 8'hD4, 8'hA2, 8'hAF, 8'h9C, 8'hA4, 8'h72, 8'hC0, 31 | 8'hB7, 8'hFD, 8'h93, 8'h26, 8'h36, 8'h3F, 8'hF7, 8'hCC, 8'h34, 8'hA5, 8'hE5, 8'hF1, 8'h71, 8'hD8, 8'h31, 8'h15, 32 | 8'h04, 8'hC7, 8'h23, 8'hC3, 8'h18, 8'h96, 8'h05, 8'h9A, 8'h07, 8'h12, 8'h80, 8'hE2, 8'hEB, 8'h27, 8'hB2, 8'h75, 33 | 8'h09, 8'h83, 8'h2C, 8'h1A, 8'h1B, 8'h6E, 8'h5A, 8'hA0, 8'h52, 8'h3B, 8'hD6, 8'hB3, 8'h29, 8'hE3, 8'h2F, 8'h84, 34 | 8'h53, 8'hD1, 8'h00, 8'hED, 8'h20, 8'hFC, 8'hB1, 8'h5B, 8'h6A, 8'hCB, 8'hBE, 8'h39, 8'h4A, 8'h4C, 8'h58, 8'hCF, 35 | 8'hD0, 8'hEF, 8'hAA, 8'hFB, 8'h43, 8'h4D, 8'h33, 8'h85, 8'h45, 8'hF9, 8'h02, 8'h7F, 8'h50, 8'h3C, 8'h9F, 8'hA8, 36 | 8'h51, 8'hA3, 8'h40, 8'h8F, 8'h92, 8'h9D, 8'h38, 8'hF5, 8'hBC, 8'hB6, 8'hDA, 8'h21, 8'h10, 8'hFF, 8'hF3, 8'hD2, 37 | 8'hCD, 8'h0C, 8'h13, 8'hEC, 8'h5F, 8'h97, 8'h44, 8'h17, 8'hC4, 8'hA7, 8'h7E, 8'h3D, 8'h64, 8'h5D, 8'h19, 8'h73, 38 | 8'h60, 8'h81, 8'h4F, 8'hDC, 8'h22, 8'h2A, 8'h90, 8'h88, 8'h46, 8'hEE, 8'hB8, 8'h14, 8'hDE, 8'h5E, 8'h0B, 8'hDB, 39 | 8'hE0, 8'h32, 8'h3A, 8'h0A, 8'h49, 8'h06, 8'h24, 8'h5C, 8'hC2, 8'hD3, 8'hAC, 8'h62, 8'h91, 8'h95, 8'hE4, 8'h79, 40 | 8'hE7, 8'hC8, 8'h37, 8'h6D, 8'h8D, 8'hD5, 8'h4E, 8'hA9, 8'h6C, 8'h56, 8'hF4, 8'hEA, 8'h65, 8'h7A, 8'hAE, 8'h08, 41 | 8'hBA, 8'h78, 8'h25, 8'h2E, 8'h1C, 8'hA6, 8'hB4, 8'hC6, 8'hE8, 8'hDD, 8'h74, 8'h1F, 8'h4B, 8'hBD, 8'h8B, 8'h8A, 42 | 8'h70, 8'h3E, 8'hB5, 8'h66, 8'h48, 8'h03, 8'hF6, 8'h0E, 8'h61, 8'h35, 8'h57, 8'hB9, 8'h86, 8'hC1, 8'h1D, 8'h9E, 43 | 8'hE1, 8'hF8, 8'h98, 8'h11, 8'h69, 8'hD9, 8'h8E, 8'h94, 8'h9B, 8'h1E, 8'h87, 8'hE9, 8'hCE, 8'h55, 8'h28, 8'hDF, 44 | 8'h8C, 8'hA1, 8'h89, 8'h0D, 8'hBF, 8'hE6, 8'h42, 8'h68, 8'h41, 8'h99, 8'h2D, 8'h0F, 8'hB0, 8'h54, 8'hBB, 8'h16 45 | }; 46 | 47 | reg [7:0] a0, a1, a2, a3, a4, a5, a6, a7, a8, a9, a10,a11,a12,a13,a14,a15; 48 | reg [7:0] a16,a17,a18,a19,a20,a21,a22,a23,a24,a25,a26,a27,a28,a29,a30,a31; 49 | reg [7:0] a32,a33,a34,a35,a36,a37,a38,a39,a40,a41,a42,a43,a44,a45,a46,a47; 50 | reg [7:0] a48,a49,a50,a51,a52,a53,a54,a55,a56,a57,a58,a59,a60,a61,a62,a63; 51 | reg [7:0] a64,a65,a66,a67,a68,a69,a70,a71,a72,a73,a74,a75,a76,a77,a78,a79; 52 | reg [7:0] a80,a81,a82,a83,a84,a85,a86,a87,a88,a89,a90,a91,a92,a93,a94,a95; 53 | reg [7:0] a96,a97,a98,a99,a100,a101,a102,a103,a104,a105,a106,a107,a108,a109,a110,a111; 54 | reg [7:0] a112,a113,a114,a115,a116,a117,a118,a119,a120,a121,a122,a123,a124,a125,a126,a127; 55 | 56 | always @ (*) begin 57 | 58 | a0 <= s_box[~in[952 +: 8]]; 59 | a1 <= s_box[~in[816 +: 8]]; 60 | a2 <= s_box[~in[680 +: 8]]; 61 | a3 <= s_box[~in[288 +: 8]]; 62 | a4 <= s_box[~in[984 +: 8]]; 63 | a5 <= s_box[~in[848 +: 8]]; 64 | a6 <= s_box[~in[712 +: 8]]; 65 | a7 <= s_box[in[576 +: 8] ^ { 4'h9, 4'hF - round } ]; 66 | a8 <= s_box[~in[888 +: 8]]; 67 | a9 <= s_box[~in[752 +: 8]]; 68 | a10 <= s_box[~in[616 +: 8]]; 69 | a11 <= s_box[~in[224 +: 8]]; 70 | a12 <= s_box[~in[920 +: 8]]; 71 | a13 <= s_box[~in[784 +: 8]]; 72 | a14 <= s_box[~in[648 +: 8]]; 73 | a15 <= s_box[in[512 +: 8] ^ { 4'h8, 4'hF - round } ]; 74 | a16 <= s_box[~in[824 +: 8]]; 75 | a17 <= s_box[~in[688 +: 8]]; 76 | a18 <= s_box[~in[552 +: 8]]; 77 | a19 <= s_box[~in[160 +: 8]]; 78 | a20 <= s_box[~in[856 +: 8]]; 79 | a21 <= s_box[~in[720 +: 8]]; 80 | a22 <= s_box[~in[584 +: 8]]; 81 | a23 <= s_box[in[448 +: 8] ^ { 4'h7, 4'hF - round } ]; 82 | a24 <= s_box[~in[760 +: 8]]; 83 | a25 <= s_box[~in[624 +: 8]]; 84 | a26 <= s_box[~in[488 +: 8]]; 85 | a27 <= s_box[~in[96 +: 8]]; 86 | a28 <= s_box[~in[792 +: 8]]; 87 | a29 <= s_box[~in[656 +: 8]]; 88 | a30 <= s_box[~in[520 +: 8]]; 89 | a31 <= s_box[in[384 +: 8] ^ { 4'h6, 4'hF - round } ]; 90 | a32 <= s_box[~in[696 +: 8]]; 91 | a33 <= s_box[~in[560 +: 8]]; 92 | a34 <= s_box[~in[424 +: 8]]; 93 | a35 <= s_box[~in[32 +: 8]]; 94 | a36 <= s_box[~in[728 +: 8]]; 95 | a37 <= s_box[~in[592 +: 8]]; 96 | a38 <= s_box[~in[456 +: 8]]; 97 | a39 <= s_box[in[320 +: 8] ^ { 4'h5, 4'hF - round } ]; 98 | a40 <= s_box[~in[632 +: 8]]; 99 | a41 <= s_box[~in[496 +: 8]]; 100 | a42 <= s_box[~in[360 +: 8]]; 101 | a43 <= s_box[~in[992 +: 8]]; 102 | a44 <= s_box[~in[664 +: 8]]; 103 | a45 <= s_box[~in[528 +: 8]]; 104 | a46 <= s_box[~in[392 +: 8]]; 105 | a47 <= s_box[in[256 +: 8] ^ { 4'h4, 4'hF - round } ]; 106 | a48 <= s_box[~in[568 +: 8]]; 107 | a49 <= s_box[~in[432 +: 8]]; 108 | a50 <= s_box[~in[296 +: 8]]; 109 | a51 <= s_box[~in[928 +: 8]]; 110 | a52 <= s_box[~in[600 +: 8]]; 111 | a53 <= s_box[~in[464 +: 8]]; 112 | a54 <= s_box[~in[328 +: 8]]; 113 | a55 <= s_box[in[192 +: 8] ^ { 4'h3, 4'hF - round } ]; 114 | a56 <= s_box[~in[504 +: 8]]; 115 | a57 <= s_box[~in[368 +: 8]]; 116 | a58 <= s_box[~in[232 +: 8]]; 117 | a59 <= s_box[~in[864 +: 8]]; 118 | a60 <= s_box[~in[536 +: 8]]; 119 | a61 <= s_box[~in[400 +: 8]]; 120 | a62 <= s_box[~in[264 +: 8]]; 121 | a63 <= s_box[in[128 +: 8] ^ { 4'h2, 4'hF - round } ]; 122 | a64 <= s_box[~in[440 +: 8]]; 123 | a65 <= s_box[~in[304 +: 8]]; 124 | a66 <= s_box[~in[168 +: 8]]; 125 | a67 <= s_box[~in[800 +: 8]]; 126 | a68 <= s_box[~in[472 +: 8]]; 127 | a69 <= s_box[~in[336 +: 8]]; 128 | a70 <= s_box[~in[200 +: 8]]; 129 | a71 <= s_box[in[64 +: 8] ^ { 4'h1, 4'hF - round } ]; 130 | a72 <= s_box[~in[376 +: 8]]; 131 | a73 <= s_box[~in[240 +: 8]]; 132 | a74 <= s_box[~in[104 +: 8]]; 133 | a75 <= s_box[~in[736 +: 8]]; 134 | a76 <= s_box[~in[408 +: 8]]; 135 | a77 <= s_box[~in[272 +: 8]]; 136 | a78 <= s_box[~in[136 +: 8]]; 137 | a79 <= s_box[in[0 +: 8] ^ { 4'h0, 4'hF - round } ]; 138 | a80 <= s_box[~in[312 +: 8]]; 139 | a81 <= s_box[~in[176 +: 8]]; 140 | a82 <= s_box[~in[40 +: 8]]; 141 | a83 <= s_box[~in[672 +: 8]]; 142 | a84 <= s_box[~in[344 +: 8]]; 143 | a85 <= s_box[~in[208 +: 8]]; 144 | a86 <= s_box[~in[72 +: 8]]; 145 | a87 <= s_box[in[960 +: 8] ^ { 4'hF, 4'hF - round } ]; 146 | a88 <= s_box[~in[248 +: 8]]; 147 | a89 <= s_box[~in[112 +: 8]]; 148 | a90 <= s_box[~in[1000 +: 8]]; 149 | a91 <= s_box[~in[608 +: 8]]; 150 | a92 <= s_box[~in[280 +: 8]]; 151 | a93 <= s_box[~in[144 +: 8]]; 152 | a94 <= s_box[~in[8 +: 8]]; 153 | a95 <= s_box[in[896 +: 8] ^ { 4'hE, 4'hF - round } ]; 154 | a96 <= s_box[~in[184 +: 8]]; 155 | a97 <= s_box[~in[48 +: 8]]; 156 | a98 <= s_box[~in[936 +: 8]]; 157 | a99 <= s_box[~in[544 +: 8]]; 158 | a100 <= s_box[~in[216 +: 8]]; 159 | a101 <= s_box[~in[80 +: 8]]; 160 | a102 <= s_box[~in[968 +: 8]]; 161 | a103 <= s_box[in[832 +: 8] ^ { 4'hD, 4'hF - round } ]; 162 | a104 <= s_box[~in[120 +: 8]]; 163 | a105 <= s_box[~in[1008 +: 8]]; 164 | a106 <= s_box[~in[872 +: 8]]; 165 | a107 <= s_box[~in[480 +: 8]]; 166 | a108 <= s_box[~in[152 +: 8]]; 167 | a109 <= s_box[~in[16 +: 8]]; 168 | a110 <= s_box[~in[904 +: 8]]; 169 | a111 <= s_box[in[768 +: 8] ^ { 4'hC, 4'hF - round } ]; 170 | a112 <= s_box[~in[56 +: 8]]; 171 | a113 <= s_box[~in[944 +: 8]]; 172 | a114 <= s_box[~in[808 +: 8]]; 173 | a115 <= s_box[~in[416 +: 8]]; 174 | a116 <= s_box[~in[88 +: 8]]; 175 | a117 <= s_box[~in[976 +: 8]]; 176 | a118 <= s_box[~in[840 +: 8]]; 177 | a119 <= s_box[in[704 +: 8] ^ { 4'hB, 4'hF - round } ]; 178 | a120 <= s_box[~in[1016 +: 8]]; 179 | a121 <= s_box[~in[880 +: 8]]; 180 | a122 <= s_box[~in[744 +: 8]]; 181 | a123 <= s_box[~in[352 +: 8]]; 182 | a124 <= s_box[~in[24 +: 8]]; 183 | a125 <= s_box[~in[912 +: 8]]; 184 | a126 <= s_box[~in[776 +: 8]]; 185 | a127 <= s_box[in[640 +: 8] ^ { 4'hA, 4'hF - round } ]; 186 | 187 | end 188 | 189 | always @ (*) begin 190 | 191 | t0 <= { 192 | a0, a1, a2, a3, a4, a5, a6, a7, a8, a9, a10,a11,a12,a13,a14,a15, 193 | a16,a17,a18,a19,a20,a21,a22,a23,a24,a25,a26,a27,a28,a29,a30,a31, 194 | a32,a33,a34,a35,a36,a37,a38,a39,a40,a41,a42,a43,a44,a45,a46,a47, 195 | a48,a49,a50,a51,a52,a53,a54,a55,a56,a57,a58,a59,a60,a61,a62,a63, 196 | a64,a65,a66,a67,a68,a69,a70,a71,a72,a73,a74,a75,a76,a77,a78,a79, 197 | a80,a81,a82,a83,a84,a85,a86,a87,a88,a89,a90,a91,a92,a93,a94,a95, 198 | a96,a97,a98,a99,a100,a101,a102,a103,a104,a105,a106,a107,a108,a109,a110,a111, 199 | a112,a113,a114,a115,a116,a117,a118,a119,a120,a121,a122,a123,a124,a125,a126,a127 200 | }; 201 | 202 | end 203 | 204 | always @ (posedge clk) begin 205 | 206 | t1 <= t0; 207 | 208 | end 209 | 210 | mix_bytes mb00 (clk, t1, out); 211 | 212 | endmodule 213 | -------------------------------------------------------------------------------- /phi1612/cl_common_defines.vh: -------------------------------------------------------------------------------- 1 | // Amazon FPGA Hardware Development Kit 2 | // 3 | // Copyright 2016 Amazon.com, Inc. or its affiliates. All Rights Reserved. 4 | // 5 | // Licensed under the Amazon Software License (the "License"). You may not use 6 | // this file except in compliance with the License. A copy of the License is 7 | // located at 8 | // 9 | // http://aws.amazon.com/asl/ 10 | // 11 | // or in the "license" file accompanying this file. This file is distributed on 12 | // an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, express or 13 | // implied. See the License for the specific language governing permissions and 14 | // limitations under the License. 15 | 16 | `ifndef CL_COMMON_DEFAULTS 17 | `define CL_COMMON_DEFAULTS 18 | 19 | // Value to return for PCIS access to unimplemented register address 20 | `define UNIMPLEMENTED_REG_VALUE 32'hdeaddead 21 | 22 | // CL Register Addresses 23 | `define HELLO_WORLD_REG_ADDR 32'h0000_0500 24 | `define VLED_REG_ADDR 32'h0000_0504 25 | 26 | `endif 27 | -------------------------------------------------------------------------------- /phi1612/cl_id_defines.vh: -------------------------------------------------------------------------------- 1 | // Amazon FPGA Hardware Development Kit 2 | // 3 | // Copyright 2016 Amazon.com, Inc. or its affiliates. All Rights Reserved. 4 | // 5 | // Licensed under the Amazon Software License (the "License"). You may not use 6 | // this file except in compliance with the License. A copy of the License is 7 | // located at 8 | // 9 | // http://aws.amazon.com/asl/ 10 | // 11 | // or in the "license" file accompanying this file. This file is distributed on 12 | // an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, express or 13 | // implied. See the License for the specific language governing permissions and 14 | // limitations under the License. 15 | 16 | // CL_SH_ID0 17 | // - PCIe Vendor/Device ID Values 18 | // 31:16: PCIe Device ID 19 | // 15: 0: PCIe Vendor ID 20 | // - A Vendor ID value of 0x8086 is not valid. 21 | // - If using a Vendor ID value of 0x1D0F (Amazon) then valid 22 | // values for Device ID's are in the range of 0xF000 - 0xF0FF. 23 | // - A Vendor/Device ID of 0 (zero) is not valid. 24 | `define CL_SH_ID0 32'hF000_1D0F 25 | 26 | // CL_SH_ID1 27 | // - PCIe Subsystem/Subsystem Vendor ID Values 28 | // 31:16: PCIe Subsystem ID 29 | // 15: 0: PCIe Subsystem Vendor ID 30 | // - A PCIe Subsystem/Subsystem Vendor ID of 0 (zero) is not valid 31 | `define CL_SH_ID1 32'h1D51_FEDD 32 | -------------------------------------------------------------------------------- /phi1612/cl_miner_defines.vh: -------------------------------------------------------------------------------- 1 | // Amazon FPGA Hardware Development Kit 2 | // 3 | // Copyright 2016 Amazon.com, Inc. or its affiliates. All Rights Reserved. 4 | // 5 | // Licensed under the Amazon Software License (the "License"). You may not use 6 | // this file except in compliance with the License. A copy of the License is 7 | // located at 8 | // 9 | // http://aws.amazon.com/asl/ 10 | // 11 | // or in the "license" file accompanying this file. This file is distributed on 12 | // an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, express or 13 | // implied. See the License for the specific language governing permissions and 14 | // limitations under the License. 15 | 16 | `ifndef CL_MINER_DEFINES 17 | `define CL_MINER_DEFINES 18 | 19 | //Put module name of the CL design here. This is used to instantiate in top.sv 20 | `define CL_NAME cl_miner 21 | 22 | //Highly recommeneded. For lib FIFO block, uses less async reset (take advantage of 23 | // FPGA flop init capability). This will help with routing resources. 24 | `define FPGA_LESS_RST 25 | 26 | // Uncomment to disable Virtual JTAG 27 | `define DISABLE_VJTAG_DEBUG 28 | 29 | `endif -------------------------------------------------------------------------------- /phi1612/fugue_smix.v: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2017 Sprocket 3 | * 4 | * This is free software: you can redistribute it and/or modify 5 | * it under the terms of the GNU Affero General Public License with 6 | * additional permissions to the one published by the Free Software 7 | * Foundation, either version 3 of the License, or (at your option) 8 | * any later version. For more information see LICENSE. 9 | * 10 | * This program is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | * GNU Affero General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU Affero General Public License 16 | * along with this program. If not, see . 17 | */ 18 | 19 | module smix ( 20 | input clk, 21 | input [31:0] s0, 22 | input [31:0] s1, 23 | input [31:0] s2, 24 | input [31:0] s3, 25 | output [127:0] out 26 | ); 27 | 28 | wire [7:0] s_box [0:255] = { 29 | 8'h63, 8'h7C, 8'h77, 8'h7B, 8'hF2, 8'h6B, 8'h6F, 8'hC5, 8'h30, 8'h01, 8'h67, 8'h2B, 8'hFE, 8'hD7, 8'hAB, 8'h76, 30 | 8'hCA, 8'h82, 8'hC9, 8'h7D, 8'hFA, 8'h59, 8'h47, 8'hF0, 8'hAD, 8'hD4, 8'hA2, 8'hAF, 8'h9C, 8'hA4, 8'h72, 8'hC0, 31 | 8'hB7, 8'hFD, 8'h93, 8'h26, 8'h36, 8'h3F, 8'hF7, 8'hCC, 8'h34, 8'hA5, 8'hE5, 8'hF1, 8'h71, 8'hD8, 8'h31, 8'h15, 32 | 8'h04, 8'hC7, 8'h23, 8'hC3, 8'h18, 8'h96, 8'h05, 8'h9A, 8'h07, 8'h12, 8'h80, 8'hE2, 8'hEB, 8'h27, 8'hB2, 8'h75, 33 | 8'h09, 8'h83, 8'h2C, 8'h1A, 8'h1B, 8'h6E, 8'h5A, 8'hA0, 8'h52, 8'h3B, 8'hD6, 8'hB3, 8'h29, 8'hE3, 8'h2F, 8'h84, 34 | 8'h53, 8'hD1, 8'h00, 8'hED, 8'h20, 8'hFC, 8'hB1, 8'h5B, 8'h6A, 8'hCB, 8'hBE, 8'h39, 8'h4A, 8'h4C, 8'h58, 8'hCF, 35 | 8'hD0, 8'hEF, 8'hAA, 8'hFB, 8'h43, 8'h4D, 8'h33, 8'h85, 8'h45, 8'hF9, 8'h02, 8'h7F, 8'h50, 8'h3C, 8'h9F, 8'hA8, 36 | 8'h51, 8'hA3, 8'h40, 8'h8F, 8'h92, 8'h9D, 8'h38, 8'hF5, 8'hBC, 8'hB6, 8'hDA, 8'h21, 8'h10, 8'hFF, 8'hF3, 8'hD2, 37 | 8'hCD, 8'h0C, 8'h13, 8'hEC, 8'h5F, 8'h97, 8'h44, 8'h17, 8'hC4, 8'hA7, 8'h7E, 8'h3D, 8'h64, 8'h5D, 8'h19, 8'h73, 38 | 8'h60, 8'h81, 8'h4F, 8'hDC, 8'h22, 8'h2A, 8'h90, 8'h88, 8'h46, 8'hEE, 8'hB8, 8'h14, 8'hDE, 8'h5E, 8'h0B, 8'hDB, 39 | 8'hE0, 8'h32, 8'h3A, 8'h0A, 8'h49, 8'h06, 8'h24, 8'h5C, 8'hC2, 8'hD3, 8'hAC, 8'h62, 8'h91, 8'h95, 8'hE4, 8'h79, 40 | 8'hE7, 8'hC8, 8'h37, 8'h6D, 8'h8D, 8'hD5, 8'h4E, 8'hA9, 8'h6C, 8'h56, 8'hF4, 8'hEA, 8'h65, 8'h7A, 8'hAE, 8'h08, 41 | 8'hBA, 8'h78, 8'h25, 8'h2E, 8'h1C, 8'hA6, 8'hB4, 8'hC6, 8'hE8, 8'hDD, 8'h74, 8'h1F, 8'h4B, 8'hBD, 8'h8B, 8'h8A, 42 | 8'h70, 8'h3E, 8'hB5, 8'h66, 8'h48, 8'h03, 8'hF6, 8'h0E, 8'h61, 8'h35, 8'h57, 8'hB9, 8'h86, 8'hC1, 8'h1D, 8'h9E, 43 | 8'hE1, 8'hF8, 8'h98, 8'h11, 8'h69, 8'hD9, 8'h8E, 8'h94, 8'h9B, 8'h1E, 8'h87, 8'hE9, 8'hCE, 8'h55, 8'h28, 8'hDF, 44 | 8'h8C, 8'hA1, 8'h89, 8'h0D, 8'hBF, 8'hE6, 8'h42, 8'h68, 8'h41, 8'h99, 8'h2D, 8'h0F, 8'hB0, 8'h54, 8'hBB, 8'h16 45 | }; 46 | 47 | wire [7:0] sb00x, sb01x, sb02x, sb03x; 48 | wire [7:0] sb10x, sb11x, sb12x, sb13x; 49 | wire [7:0] sb20x, sb21x, sb22x, sb23x; 50 | wire [7:0] sb30x, sb31x, sb32x, sb33x; 51 | 52 | assign sb00x = s_box[s0[31:24]]; 53 | assign sb01x = s_box[s0[23:16]]; 54 | assign sb02x = s_box[s0[15: 8]]; 55 | assign sb03x = s_box[s0[ 7: 0]]; 56 | 57 | assign sb10x = s_box[s1[31:24]]; 58 | assign sb11x = s_box[s1[23:16]]; 59 | assign sb12x = s_box[s1[15: 8]]; 60 | assign sb13x = s_box[s1[ 7: 0]]; 61 | 62 | assign sb20x = s_box[s2[31:24]]; 63 | assign sb21x = s_box[s2[23:16]]; 64 | assign sb22x = s_box[s2[15: 8]]; 65 | assign sb23x = s_box[s2[ 7: 0]]; 66 | 67 | assign sb30x = s_box[s3[31:24]]; 68 | assign sb31x = s_box[s3[23:16]]; 69 | assign sb32x = s_box[s3[15: 8]]; 70 | assign sb33x = s_box[s3[ 7: 0]]; 71 | 72 | reg [7:0] sb00, sb01, sb02, sb03; 73 | reg [7:0] sb10, sb11, sb12, sb13; 74 | reg [7:0] sb20, sb21, sb22, sb23; 75 | reg [7:0] sb30, sb31, sb32, sb33; 76 | 77 | reg [7:0] gf2_00, gf2_01, gf2_02, gf2_03; 78 | reg [7:0] gf2_10, gf2_11, gf2_12, gf2_13; 79 | reg [7:0] gf2_20, gf2_21, gf2_22, gf2_23; 80 | reg [7:0] gf2_30, gf2_31, gf2_32, gf2_33; 81 | 82 | reg [7:0] gf4_00, gf4_01, gf4_02, gf4_03; 83 | reg [7:0] gf4_10, gf4_11, gf4_12, gf4_13; 84 | reg [7:0] gf4_20, gf4_21, gf4_22, gf4_23; 85 | reg [7:0] gf4_30, gf4_31, gf4_32, gf4_33; 86 | 87 | assign out[127:120] = sb00 ^ gf4_01 ^ gf4_02 ^ gf2_02 ^ sb02 ^ sb03 ^ sb10 ^ sb20 ^ sb30; 88 | assign out[119:112] = sb01 ^ sb10 ^ sb11 ^ gf4_12 ^ gf4_13 ^ gf2_13 ^ sb13 ^ sb21 ^ sb31; 89 | assign out[111:104] = sb02 ^ sb12 ^ gf4_20 ^ gf2_20 ^ sb20 ^ sb21 ^ sb22 ^ gf4_23 ^ sb32; 90 | assign out[103: 96] = sb03 ^ sb13 ^ sb23 ^ gf4_30 ^ gf4_31 ^ gf2_31 ^ sb31 ^ sb32 ^ sb33; 91 | assign out[ 95: 88] = gf4_11 ^ gf4_12 ^ gf2_12 ^ sb12 ^ sb13 ^ sb20 ^ sb30; 92 | assign out[ 87: 80] = sb01 ^ sb20 ^ gf4_22 ^ gf4_23 ^ gf2_23 ^ sb23 ^ sb31; 93 | assign out[ 79: 72] = sb02 ^ sb12 ^ gf4_30 ^ gf2_30 ^ sb30 ^ sb31 ^ gf4_33; 94 | assign out[ 71: 64] = gf4_00 ^ gf4_01 ^ gf2_01 ^ sb01 ^ sb02 ^ sb13 ^ sb23; 95 | assign out[ 63: 56] = gf4_10 ^ gf2_10 ^ sb10 ^ gf4_20 ^ gf2_20 ^ gf4_21 ^ gf4_22 ^ gf2_22 ^ sb22 ^ sb23 ^ gf4_30 ^ gf2_30 ^ sb30; 96 | assign out[ 55: 48] = gf4_01 ^ gf2_01 ^ sb01 ^ gf4_21 ^ gf2_21 ^ sb21 ^ sb30 ^ gf4_31 ^ gf2_31 ^ gf4_32 ^ gf4_33 ^ gf2_33 ^ sb33; 97 | assign out[ 47: 40] = gf4_00 ^ gf2_00 ^ sb00 ^ sb01 ^ gf4_02 ^ gf2_02 ^ gf4_03 ^ gf4_12 ^ gf2_12 ^ sb12 ^ gf4_32 ^ gf2_32 ^ sb32; 98 | assign out[ 39: 32] = gf4_03 ^ gf2_03 ^ sb03 ^ gf4_10 ^ gf4_11 ^ gf2_11 ^ sb11 ^ sb12 ^ gf4_13 ^ gf2_13 ^ gf4_23 ^ gf2_23 ^ sb23; 99 | assign out[ 31: 24] = gf4_10 ^ gf4_20 ^ gf4_30 ^ sb30 ^ gf4_31 ^ gf4_32 ^ gf2_32 ^ sb32 ^ sb33; 100 | assign out[ 23: 16] = sb00 ^ gf4_01 ^ sb01 ^ gf4_02 ^ gf4_03 ^ gf2_03 ^ sb03 ^ gf4_21 ^ gf4_31; 101 | assign out[ 15: 8] = gf4_02 ^ gf4_10 ^ gf2_10 ^ sb10 ^ sb11 ^ gf4_12 ^ sb12 ^ gf4_13 ^ gf4_32; 102 | assign out[ 7: 0] = gf4_03 ^ gf4_13 ^ gf4_20 ^ gf4_21 ^ gf2_21 ^ sb21 ^ sb22 ^ gf4_23 ^ sb23; 103 | 104 | 105 | always @ (posedge clk) begin 106 | 107 | sb00 <= sb00x; 108 | sb01 <= sb01x; 109 | sb02 <= sb02x; 110 | sb03 <= sb03x; 111 | 112 | sb10 <= sb10x; 113 | sb11 <= sb11x; 114 | sb12 <= sb12x; 115 | sb13 <= sb13x; 116 | 117 | sb20 <= sb20x; 118 | sb21 <= sb21x; 119 | sb22 <= sb22x; 120 | sb23 <= sb23x; 121 | 122 | sb30 <= sb30x; 123 | sb31 <= sb31x; 124 | sb32 <= sb32x; 125 | sb33 <= sb33x; 126 | 127 | gf2_00 <= gf_2(sb00x); 128 | gf2_01 <= gf_2(sb01x); 129 | gf2_02 <= gf_2(sb02x); 130 | gf2_03 <= gf_2(sb03x); 131 | 132 | gf2_10 <= gf_2(sb10x); 133 | gf2_11 <= gf_2(sb11x); 134 | gf2_12 <= gf_2(sb12x); 135 | gf2_13 <= gf_2(sb13x); 136 | 137 | gf2_20 <= gf_2(sb20x); 138 | gf2_21 <= gf_2(sb21x); 139 | gf2_22 <= gf_2(sb22x); 140 | gf2_23 <= gf_2(sb23x); 141 | 142 | gf2_30 <= gf_2(sb30x); 143 | gf2_31 <= gf_2(sb31x); 144 | gf2_32 <= gf_2(sb32x); 145 | gf2_33 <= gf_2(sb33x); 146 | 147 | gf4_00 <= gf_4(sb00x); 148 | gf4_01 <= gf_4(sb01x); 149 | gf4_02 <= gf_4(sb02x); 150 | gf4_03 <= gf_4(sb03x); 151 | 152 | gf4_10 <= gf_4(sb10x); 153 | gf4_11 <= gf_4(sb11x); 154 | gf4_12 <= gf_4(sb12x); 155 | gf4_13 <= gf_4(sb13x); 156 | 157 | gf4_20 <= gf_4(sb20x); 158 | gf4_21 <= gf_4(sb21x); 159 | gf4_22 <= gf_4(sb22x); 160 | gf4_23 <= gf_4(sb23x); 161 | 162 | gf4_30 <= gf_4(sb30x); 163 | gf4_31 <= gf_4(sb31x); 164 | gf4_32 <= gf_4(sb32x); 165 | gf4_33 <= gf_4(sb33x); 166 | 167 | end 168 | 169 | // always @ (posedge clk) begin 170 | // 171 | // out[127:120] <= sb00 ^ gf4_01 ^ gf4_02 ^ gf2_02 ^ sb02 ^ sb03 ^ sb10 ^ sb20 ^ sb30; 172 | // out[119:112] <= sb01 ^ sb10 ^ sb11 ^ gf4_12 ^ gf4_13 ^ gf2_13 ^ sb13 ^ sb21 ^ sb31; 173 | // out[111:104] <= sb02 ^ sb12 ^ gf4_20 ^ gf2_20 ^ sb20 ^ sb21 ^ sb22 ^ gf4_23 ^ sb32; 174 | // out[103: 96] <= sb03 ^ sb13 ^ sb23 ^ gf4_30 ^ gf4_31 ^ gf2_31 ^ sb31 ^ sb32 ^ sb33; 175 | // out[ 95: 88] <= gf4_11 ^ gf4_12 ^ gf2_12 ^ sb12 ^ sb13 ^ sb20 ^ sb30; 176 | // out[ 87: 80] <= sb01 ^ sb20 ^ gf4_22 ^ gf4_23 ^ gf2_23 ^ sb23 ^ sb31; 177 | // out[ 79: 72] <= sb02 ^ sb12 ^ gf4_30 ^ gf2_30 ^ sb30 ^ sb31 ^ gf4_33; 178 | // out[ 71: 64] <= gf4_00 ^ gf4_01 ^ gf2_01 ^ sb01 ^ sb02 ^ sb13 ^ sb23; 179 | // out[ 63: 56] <= gf4_10 ^ gf2_10 ^ sb10 ^ gf4_20 ^ gf2_20 ^ gf4_21 ^ gf4_22 ^ gf2_22 ^ sb22 ^ sb23 ^ gf4_30 ^ gf2_30 ^ sb30; 180 | // out[ 55: 48] <= gf4_01 ^ gf2_01 ^ sb01 ^ gf4_21 ^ gf2_21 ^ sb21 ^ sb30 ^ gf4_31 ^ gf2_31 ^ gf4_32 ^ gf4_33 ^ gf2_33 ^ sb33; 181 | // out[ 47: 40] <= gf4_00 ^ gf2_00 ^ sb00 ^ sb01 ^ gf4_02 ^ gf2_02 ^ gf4_03 ^ gf4_12 ^ gf2_12 ^ sb12 ^ gf4_32 ^ gf2_32 ^ sb32; 182 | // out[ 39: 32] <= gf4_03 ^ gf2_03 ^ sb03 ^ gf4_10 ^ gf4_11 ^ gf2_11 ^ sb11 ^ sb12 ^ gf4_13 ^ gf2_13 ^ gf4_23 ^ gf2_23 ^ sb23; 183 | // out[ 31: 24] <= gf4_10 ^ gf4_20 ^ gf4_30 ^ sb30 ^ gf4_31 ^ gf4_32 ^ gf2_32 ^ sb32 ^ sb33; 184 | // out[ 23: 16] <= sb00 ^ gf4_01 ^ sb01 ^ gf4_02 ^ gf4_03 ^ gf2_03 ^ sb03 ^ gf4_21 ^ gf4_31; 185 | // out[ 15: 8] <= gf4_02 ^ gf4_10 ^ gf2_10 ^ sb10 ^ sb11 ^ gf4_12 ^ sb12 ^ gf4_13 ^ gf4_32; 186 | // out[ 7: 0] <= gf4_03 ^ gf4_13 ^ gf4_20 ^ gf4_21 ^ gf2_21 ^ sb21 ^ sb22 ^ gf4_23 ^ sb23; 187 | // 188 | // end 189 | 190 | // Calculate GF(256) Multiplication (x2) 191 | function [7:0] gf_2; 192 | input [7:0] n; 193 | begin 194 | gf_2 = {n[6],n[5],n[4],n[3]^n[7],n[2]^n[7],n[1],n[0]^n[7],n[7]}; 195 | end 196 | endfunction 197 | 198 | // Calculate GF(256) Multiplication (x4) 199 | function [7:0] gf_4; 200 | input [7:0] n; 201 | begin 202 | gf_4 = {n[5],n[4],n[3]^n[7],n[2]^n[7]^n[6],n[6]^n[1],n[0]^n[7],n[6]^n[7],n[6]}; 203 | end 204 | endfunction 205 | 206 | endmodule 207 | -------------------------------------------------------------------------------- /phi1612/miner.v: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2017 Sprocket 3 | * 4 | * This is free software: you can redistribute it and/or modify 5 | * it under the terms of the GNU Affero General Public License with 6 | * additional permissions to the one published by the Free Software 7 | * Foundation, either version 3 of the License, or (at your option) 8 | * any later version. For more information see LICENSE. 9 | * 10 | * This program is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | * GNU Affero General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU Affero General Public License 16 | * along with this program. If not, see . 17 | */ 18 | 19 | module miner # ( 20 | parameter CORES = 32'd1 21 | ) ( 22 | input clk, 23 | input reset, 24 | input [639:0] block, 25 | input [31:0] nonce_start, 26 | output nonce_found, 27 | output [31:0] nonce_out 28 | ); 29 | 30 | localparam OFFSET = 32'd635; 31 | 32 | wire [511:0] hash1, hash2, hash3, hash4, hash5; 33 | wire [31:0] hash6; 34 | 35 | reg [511:0] midstate_d, midstate_q; 36 | reg [95:0] data_d, data_q; 37 | reg [31:0] target_d, target_q; 38 | reg [31:0] nonce_d, nonce_q; 39 | reg [31:0] nonce_out_d, nonce_out_q; 40 | reg nonce_found_d, nonce_found_q; 41 | reg reset_d, reset_q; 42 | 43 | reg [511:0] hash1_d, hash1_q, hash2_d, hash2_q, hash3_d, hash3_q, hash4_d, hash4_q, hash5_d, hash5_q; 44 | reg [31:0] hash6_d, hash6_q; 45 | 46 | reg phase_d = 1'b0, phase_q = 1'b0; 47 | 48 | assign nonce_found = nonce_found_q; 49 | assign nonce_out = nonce_out_q; 50 | 51 | skein512 skein ( clk, midstate_q, data_q, nonce_q, hash1 ); 52 | JH512 jh ( clk, hash1_q, hash2 ); 53 | cube512 cube ( clk, hash2_q, hash3 ); 54 | fugue512 fugue ( clk, hash3_q, hash4 ); 55 | gost512 gost ( clk, hash4_q, hash5 ); 56 | echo512 echo ( clk, hash5_q, hash6 ); 57 | 58 | always @ (*) begin 59 | 60 | phase_d <= ~phase_q; 61 | 62 | if ( reset_q ) begin 63 | 64 | nonce_d <= nonce_start; 65 | nonce_out_d <= nonce_start - (CORES * OFFSET); 66 | 67 | nonce_found_d <= 1'b0; 68 | 69 | end 70 | else begin 71 | 72 | if ( phase_q ) begin 73 | nonce_d <= nonce_q + CORES; 74 | nonce_out_d <= nonce_out_q + CORES; 75 | 76 | if ( hash6_q <= target_q ) 77 | nonce_found_d <= 1'b1; 78 | else 79 | nonce_found_d <= 1'b0; 80 | end 81 | else begin 82 | nonce_d <= nonce_q; 83 | nonce_out_d <= nonce_out_q; 84 | 85 | nonce_found_d <= 1'b0; 86 | end 87 | 88 | end 89 | 90 | hash1_d <= hash1; 91 | hash2_d <= hash2; 92 | hash3_d <= hash3; 93 | hash4_d <= hash4; 94 | hash5_d <= hash5; 95 | hash6_d <= hash6; 96 | reset_d <= reset; 97 | 98 | midstate_d <= block[639:128]; 99 | data_d <= block[127:32]; 100 | target_d <= block[31:0]; 101 | 102 | reset_d <= reset; 103 | 104 | end 105 | 106 | always @ (posedge clk) begin 107 | 108 | phase_q <= phase_d; 109 | 110 | midstate_q <= midstate_d; 111 | data_q <= data_d; 112 | target_q <= target_d; 113 | 114 | nonce_q <= nonce_d; 115 | nonce_out_q <= nonce_out_d; 116 | 117 | hash1_q <= hash1_d; 118 | hash2_q <= hash2_d; 119 | hash3_q <= hash3_d; 120 | hash4_q <= hash4_d; 121 | hash5_q <= hash5_d; 122 | hash6_q <= hash6_d; 123 | 124 | nonce_found_q <= nonce_found_d; 125 | 126 | reset_q <= reset_d; 127 | 128 | $display ("Nonce: %X, Hash: %X, Found: %d", nonce_out_d, hash6_q, nonce_found_d); 129 | // $display (" H1: %x", hash1); 130 | // $display (" H2: %x", hash2); 131 | // $display (" H3: %x", hash3); 132 | // $display (" H4: %x", hash4); 133 | // $display (" H5: %x", hash5); 134 | // $display (" H6: %x", hash6); 135 | 136 | end 137 | 138 | endmodule 139 | -------------------------------------------------------------------------------- /skunk/cl_common_defines.vh: -------------------------------------------------------------------------------- 1 | // Amazon FPGA Hardware Development Kit 2 | // 3 | // Copyright 2016 Amazon.com, Inc. or its affiliates. All Rights Reserved. 4 | // 5 | // Licensed under the Amazon Software License (the "License"). You may not use 6 | // this file except in compliance with the License. A copy of the License is 7 | // located at 8 | // 9 | // http://aws.amazon.com/asl/ 10 | // 11 | // or in the "license" file accompanying this file. This file is distributed on 12 | // an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, express or 13 | // implied. See the License for the specific language governing permissions and 14 | // limitations under the License. 15 | 16 | `ifndef CL_COMMON_DEFAULTS 17 | `define CL_COMMON_DEFAULTS 18 | 19 | // Value to return for PCIS access to unimplemented register address 20 | `define UNIMPLEMENTED_REG_VALUE 32'hdeaddead 21 | 22 | // CL Register Addresses 23 | `define HELLO_WORLD_REG_ADDR 32'h0000_0500 24 | `define VLED_REG_ADDR 32'h0000_0504 25 | 26 | `endif 27 | -------------------------------------------------------------------------------- /skunk/cl_id_defines.vh: -------------------------------------------------------------------------------- 1 | // Amazon FPGA Hardware Development Kit 2 | // 3 | // Copyright 2016 Amazon.com, Inc. or its affiliates. All Rights Reserved. 4 | // 5 | // Licensed under the Amazon Software License (the "License"). You may not use 6 | // this file except in compliance with the License. A copy of the License is 7 | // located at 8 | // 9 | // http://aws.amazon.com/asl/ 10 | // 11 | // or in the "license" file accompanying this file. This file is distributed on 12 | // an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, express or 13 | // implied. See the License for the specific language governing permissions and 14 | // limitations under the License. 15 | 16 | // CL_SH_ID0 17 | // - PCIe Vendor/Device ID Values 18 | // 31:16: PCIe Device ID 19 | // 15: 0: PCIe Vendor ID 20 | // - A Vendor ID value of 0x8086 is not valid. 21 | // - If using a Vendor ID value of 0x1D0F (Amazon) then valid 22 | // values for Device ID's are in the range of 0xF000 - 0xF0FF. 23 | // - A Vendor/Device ID of 0 (zero) is not valid. 24 | `define CL_SH_ID0 32'hF000_1D0F 25 | 26 | // CL_SH_ID1 27 | // - PCIe Subsystem/Subsystem Vendor ID Values 28 | // 31:16: PCIe Subsystem ID 29 | // 15: 0: PCIe Subsystem Vendor ID 30 | // - A PCIe Subsystem/Subsystem Vendor ID of 0 (zero) is not valid 31 | `define CL_SH_ID1 32'h1D51_FEDD 32 | -------------------------------------------------------------------------------- /skunk/cl_miner_defines.vh: -------------------------------------------------------------------------------- 1 | // Amazon FPGA Hardware Development Kit 2 | // 3 | // Copyright 2016 Amazon.com, Inc. or its affiliates. All Rights Reserved. 4 | // 5 | // Licensed under the Amazon Software License (the "License"). You may not use 6 | // this file except in compliance with the License. A copy of the License is 7 | // located at 8 | // 9 | // http://aws.amazon.com/asl/ 10 | // 11 | // or in the "license" file accompanying this file. This file is distributed on 12 | // an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, express or 13 | // implied. See the License for the specific language governing permissions and 14 | // limitations under the License. 15 | 16 | `ifndef CL_MINER_DEFINES 17 | `define CL_MINER_DEFINES 18 | 19 | //Put module name of the CL design here. This is used to instantiate in top.sv 20 | `define CL_NAME cl_miner 21 | 22 | //Highly recommeneded. For lib FIFO block, uses less async reset (take advantage of 23 | // FPGA flop init capability). This will help with routing resources. 24 | `define FPGA_LESS_RST 25 | 26 | // Uncomment to disable Virtual JTAG 27 | //`define DISABLE_VJTAG_DEBUG 28 | 29 | `endif -------------------------------------------------------------------------------- /skunk/fugue_smix.v: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2017 Sprocket 3 | * 4 | * This is free software: you can redistribute it and/or modify 5 | * it under the terms of the GNU Affero General Public License with 6 | * additional permissions to the one published by the Free Software 7 | * Foundation, either version 3 of the License, or (at your option) 8 | * any later version. For more information see LICENSE. 9 | * 10 | * This program is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | * GNU Affero General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU Affero General Public License 16 | * along with this program. If not, see . 17 | */ 18 | 19 | (* ram_style = "distributed" *) 20 | module smix ( 21 | input [31:0] s0, 22 | input [31:0] s1, 23 | input [31:0] s2, 24 | input [31:0] s3, 25 | output [127:0] out 26 | ); 27 | 28 | wire [7:0] gf2 [0:255] = { 29 | 8'h00, 8'h02, 8'h04, 8'h06, 8'h08, 8'h0a, 8'h0c, 8'h0e, 8'h10, 8'h12, 8'h14, 8'h16, 8'h18, 8'h1a, 8'h1c, 8'h1e, 30 | 8'h20, 8'h22, 8'h24, 8'h26, 8'h28, 8'h2a, 8'h2c, 8'h2e, 8'h30, 8'h32, 8'h34, 8'h36, 8'h38, 8'h3a, 8'h3c, 8'h3e, 31 | 8'h40, 8'h42, 8'h44, 8'h46, 8'h48, 8'h4a, 8'h4c, 8'h4e, 8'h50, 8'h52, 8'h54, 8'h56, 8'h58, 8'h5a, 8'h5c, 8'h5e, 32 | 8'h60, 8'h62, 8'h64, 8'h66, 8'h68, 8'h6a, 8'h6c, 8'h6e, 8'h70, 8'h72, 8'h74, 8'h76, 8'h78, 8'h7a, 8'h7c, 8'h7e, 33 | 8'h80, 8'h82, 8'h84, 8'h86, 8'h88, 8'h8a, 8'h8c, 8'h8e, 8'h90, 8'h92, 8'h94, 8'h96, 8'h98, 8'h9a, 8'h9c, 8'h9e, 34 | 8'ha0, 8'ha2, 8'ha4, 8'ha6, 8'ha8, 8'haa, 8'hac, 8'hae, 8'hb0, 8'hb2, 8'hb4, 8'hb6, 8'hb8, 8'hba, 8'hbc, 8'hbe, 35 | 8'hc0, 8'hc2, 8'hc4, 8'hc6, 8'hc8, 8'hca, 8'hcc, 8'hce, 8'hd0, 8'hd2, 8'hd4, 8'hd6, 8'hd8, 8'hda, 8'hdc, 8'hde, 36 | 8'he0, 8'he2, 8'he4, 8'he6, 8'he8, 8'hea, 8'hec, 8'hee, 8'hf0, 8'hf2, 8'hf4, 8'hf6, 8'hf8, 8'hfa, 8'hfc, 8'hfe, 37 | 8'h1b, 8'h19, 8'h1f, 8'h1d, 8'h13, 8'h11, 8'h17, 8'h15, 8'h0b, 8'h09, 8'h0f, 8'h0d, 8'h03, 8'h01, 8'h07, 8'h05, 38 | 8'h3b, 8'h39, 8'h3f, 8'h3d, 8'h33, 8'h31, 8'h37, 8'h35, 8'h2b, 8'h29, 8'h2f, 8'h2d, 8'h23, 8'h21, 8'h27, 8'h25, 39 | 8'h5b, 8'h59, 8'h5f, 8'h5d, 8'h53, 8'h51, 8'h57, 8'h55, 8'h4b, 8'h49, 8'h4f, 8'h4d, 8'h43, 8'h41, 8'h47, 8'h45, 40 | 8'h7b, 8'h79, 8'h7f, 8'h7d, 8'h73, 8'h71, 8'h77, 8'h75, 8'h6b, 8'h69, 8'h6f, 8'h6d, 8'h63, 8'h61, 8'h67, 8'h65, 41 | 8'h9b, 8'h99, 8'h9f, 8'h9d, 8'h93, 8'h91, 8'h97, 8'h95, 8'h8b, 8'h89, 8'h8f, 8'h8d, 8'h83, 8'h81, 8'h87, 8'h85, 42 | 8'hbb, 8'hb9, 8'hbf, 8'hbd, 8'hb3, 8'hb1, 8'hb7, 8'hb5, 8'hab, 8'ha9, 8'haf, 8'had, 8'ha3, 8'ha1, 8'ha7, 8'ha5, 43 | 8'hdb, 8'hd9, 8'hdf, 8'hdd, 8'hd3, 8'hd1, 8'hd7, 8'hd5, 8'hcb, 8'hc9, 8'hcf, 8'hcd, 8'hc3, 8'hc1, 8'hc7, 8'hc5, 44 | 8'hfb, 8'hf9, 8'hff, 8'hfd, 8'hf3, 8'hf1, 8'hf7, 8'hf5, 8'heb, 8'he9, 8'hef, 8'hed, 8'he3, 8'he1, 8'he7, 8'he5 45 | }; 46 | 47 | wire [7:0] s_box [0:255] = { 48 | 8'h63, 8'h7C, 8'h77, 8'h7B, 8'hF2, 8'h6B, 8'h6F, 8'hC5, 8'h30, 8'h01, 8'h67, 8'h2B, 8'hFE, 8'hD7, 8'hAB, 8'h76, 49 | 8'hCA, 8'h82, 8'hC9, 8'h7D, 8'hFA, 8'h59, 8'h47, 8'hF0, 8'hAD, 8'hD4, 8'hA2, 8'hAF, 8'h9C, 8'hA4, 8'h72, 8'hC0, 50 | 8'hB7, 8'hFD, 8'h93, 8'h26, 8'h36, 8'h3F, 8'hF7, 8'hCC, 8'h34, 8'hA5, 8'hE5, 8'hF1, 8'h71, 8'hD8, 8'h31, 8'h15, 51 | 8'h04, 8'hC7, 8'h23, 8'hC3, 8'h18, 8'h96, 8'h05, 8'h9A, 8'h07, 8'h12, 8'h80, 8'hE2, 8'hEB, 8'h27, 8'hB2, 8'h75, 52 | 8'h09, 8'h83, 8'h2C, 8'h1A, 8'h1B, 8'h6E, 8'h5A, 8'hA0, 8'h52, 8'h3B, 8'hD6, 8'hB3, 8'h29, 8'hE3, 8'h2F, 8'h84, 53 | 8'h53, 8'hD1, 8'h00, 8'hED, 8'h20, 8'hFC, 8'hB1, 8'h5B, 8'h6A, 8'hCB, 8'hBE, 8'h39, 8'h4A, 8'h4C, 8'h58, 8'hCF, 54 | 8'hD0, 8'hEF, 8'hAA, 8'hFB, 8'h43, 8'h4D, 8'h33, 8'h85, 8'h45, 8'hF9, 8'h02, 8'h7F, 8'h50, 8'h3C, 8'h9F, 8'hA8, 55 | 8'h51, 8'hA3, 8'h40, 8'h8F, 8'h92, 8'h9D, 8'h38, 8'hF5, 8'hBC, 8'hB6, 8'hDA, 8'h21, 8'h10, 8'hFF, 8'hF3, 8'hD2, 56 | 8'hCD, 8'h0C, 8'h13, 8'hEC, 8'h5F, 8'h97, 8'h44, 8'h17, 8'hC4, 8'hA7, 8'h7E, 8'h3D, 8'h64, 8'h5D, 8'h19, 8'h73, 57 | 8'h60, 8'h81, 8'h4F, 8'hDC, 8'h22, 8'h2A, 8'h90, 8'h88, 8'h46, 8'hEE, 8'hB8, 8'h14, 8'hDE, 8'h5E, 8'h0B, 8'hDB, 58 | 8'hE0, 8'h32, 8'h3A, 8'h0A, 8'h49, 8'h06, 8'h24, 8'h5C, 8'hC2, 8'hD3, 8'hAC, 8'h62, 8'h91, 8'h95, 8'hE4, 8'h79, 59 | 8'hE7, 8'hC8, 8'h37, 8'h6D, 8'h8D, 8'hD5, 8'h4E, 8'hA9, 8'h6C, 8'h56, 8'hF4, 8'hEA, 8'h65, 8'h7A, 8'hAE, 8'h08, 60 | 8'hBA, 8'h78, 8'h25, 8'h2E, 8'h1C, 8'hA6, 8'hB4, 8'hC6, 8'hE8, 8'hDD, 8'h74, 8'h1F, 8'h4B, 8'hBD, 8'h8B, 8'h8A, 61 | 8'h70, 8'h3E, 8'hB5, 8'h66, 8'h48, 8'h03, 8'hF6, 8'h0E, 8'h61, 8'h35, 8'h57, 8'hB9, 8'h86, 8'hC1, 8'h1D, 8'h9E, 62 | 8'hE1, 8'hF8, 8'h98, 8'h11, 8'h69, 8'hD9, 8'h8E, 8'h94, 8'h9B, 8'h1E, 8'h87, 8'hE9, 8'hCE, 8'h55, 8'h28, 8'hDF, 63 | 8'h8C, 8'hA1, 8'h89, 8'h0D, 8'hBF, 8'hE6, 8'h42, 8'h68, 8'h41, 8'h99, 8'h2D, 8'h0F, 8'hB0, 8'h54, 8'hBB, 8'h16 64 | }; 65 | 66 | wire [7:0] sb00, sb01, sb02, sb03; 67 | wire [7:0] sb10, sb11, sb12, sb13; 68 | wire [7:0] sb20, sb21, sb22, sb23; 69 | wire [7:0] sb30, sb31, sb32, sb33; 70 | 71 | assign sb00 = s_box[s0[31:24]]; 72 | assign sb01 = s_box[s0[23:16]]; 73 | assign sb02 = s_box[s0[15: 8]]; 74 | assign sb03 = s_box[s0[ 7: 0]]; 75 | 76 | assign sb10 = s_box[s1[31:24]]; 77 | assign sb11 = s_box[s1[23:16]]; 78 | assign sb12 = s_box[s1[15: 8]]; 79 | assign sb13 = s_box[s1[ 7: 0]]; 80 | 81 | assign sb20 = s_box[s2[31:24]]; 82 | assign sb21 = s_box[s2[23:16]]; 83 | assign sb22 = s_box[s2[15: 8]]; 84 | assign sb23 = s_box[s2[ 7: 0]]; 85 | 86 | assign sb30 = s_box[s3[31:24]]; 87 | assign sb31 = s_box[s3[23:16]]; 88 | assign sb32 = s_box[s3[15: 8]]; 89 | assign sb33 = s_box[s3[ 7: 0]]; 90 | 91 | assign out[127:120] = sb00 ^ gf2[gf2[sb01]] ^ gf2[gf2[sb02]] ^ gf2[sb02] ^ sb02 ^ sb03 ^ sb10 ^ sb20 ^ sb30; 92 | assign out[119:112] = sb01 ^ sb10 ^ sb11 ^ gf2[gf2[sb12]] ^ gf2[gf2[sb13]] ^ gf2[sb13] ^ sb13 ^ sb21 ^ sb31; 93 | assign out[111:104] = sb02 ^ sb12 ^ gf2[gf2[sb20]] ^ gf2[sb20] ^ sb20 ^ sb21 ^ sb22 ^ gf2[gf2[sb23]] ^ sb32; 94 | assign out[103: 96] = sb03 ^ sb13 ^ sb23 ^ gf2[gf2[sb30]] ^ gf2[gf2[sb31]] ^ gf2[sb31] ^ sb31 ^ sb32 ^ sb33; 95 | assign out[ 95: 88] = gf2[gf2[sb11]] ^ gf2[gf2[sb12]] ^ gf2[sb12] ^ sb12 ^ sb13 ^ sb20 ^ sb30; 96 | assign out[ 87: 80] = sb01 ^ sb20 ^ gf2[gf2[sb22]] ^ gf2[gf2[sb23]] ^ gf2[sb23] ^ sb23 ^ sb31; 97 | assign out[ 79: 72] = sb02 ^ sb12 ^ gf2[gf2[sb30]] ^ gf2[sb30] ^ sb30 ^ sb31 ^ gf2[gf2[sb33]]; 98 | assign out[ 71: 64] = gf2[gf2[sb00]] ^ gf2[gf2[sb01]] ^ gf2[sb01] ^ sb01 ^ sb02 ^ sb13 ^ sb23; 99 | assign out[ 63: 56] = gf2[gf2[sb10]] ^ gf2[sb10] ^ sb10 ^ gf2[gf2[sb20]] ^ gf2[sb20] ^ gf2[gf2[sb21]] ^ gf2[gf2[sb22]] ^ gf2[sb22] ^ sb22 ^ sb23 ^ gf2[gf2[sb30]] ^ gf2[sb30] ^ sb30; 100 | assign out[ 55: 48] = gf2[gf2[sb01]] ^ gf2[sb01] ^ sb01 ^ gf2[gf2[sb21]] ^ gf2[sb21] ^ sb21 ^ sb30 ^ gf2[gf2[sb31]] ^ gf2[sb31] ^ gf2[gf2[sb32]] ^ gf2[gf2[sb33]] ^ gf2[sb33] ^ sb33; 101 | assign out[ 47: 40] = gf2[gf2[sb00]] ^ gf2[sb00] ^ sb00 ^ sb01 ^ gf2[gf2[sb02]] ^ gf2[sb02] ^ gf2[gf2[sb03]] ^ gf2[gf2[sb12]] ^ gf2[sb12] ^ sb12 ^ gf2[gf2[sb32]] ^ gf2[sb32] ^ sb32; 102 | assign out[ 39: 32] = gf2[gf2[sb03]] ^ gf2[sb03] ^ sb03 ^ gf2[gf2[sb10]] ^ gf2[gf2[sb11]] ^ gf2[sb11] ^ sb11 ^ sb12 ^ gf2[gf2[sb13]] ^ gf2[sb13] ^ gf2[gf2[sb23]] ^ gf2[sb23] ^ sb23; 103 | assign out[ 31: 24] = gf2[gf2[sb10]] ^ gf2[gf2[sb20]] ^ gf2[gf2[sb30]] ^ sb30 ^ gf2[gf2[sb31]] ^ gf2[gf2[sb32]] ^ gf2[sb32] ^ sb32 ^ sb33; 104 | assign out[ 23: 16] = sb00 ^ gf2[gf2[sb01]] ^ sb01 ^ gf2[gf2[sb02]] ^ gf2[gf2[sb03]] ^ gf2[sb03] ^ sb03 ^ gf2[gf2[sb21]] ^ gf2[gf2[sb31]]; 105 | assign out[ 15: 8] = gf2[gf2[sb02]] ^ gf2[gf2[sb10]] ^ gf2[sb10] ^ sb10 ^ sb11 ^ gf2[gf2[sb12]] ^ sb12 ^ gf2[gf2[sb13]] ^ gf2[gf2[sb32]]; 106 | assign out[ 7: 0] = gf2[gf2[sb03]] ^ gf2[gf2[sb13]] ^ gf2[gf2[sb20]] ^ gf2[gf2[sb21]] ^ gf2[sb21] ^ sb21 ^ sb22 ^ gf2[gf2[sb23]] ^ sb23; 107 | 108 | endmodule 109 | -------------------------------------------------------------------------------- /skunk/miner.v: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2017 Sprocket 3 | * 4 | * This is free software: you can redistribute it and/or modify 5 | * it under the terms of the GNU Affero General Public License with 6 | * additional permissions to the one published by the Free Software 7 | * Foundation, either version 3 of the License, or (at your option) 8 | * any later version. For more information see LICENSE. 9 | * 10 | * This program is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | * GNU Affero General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU Affero General Public License 16 | * along with this program. If not, see . 17 | */ 18 | 19 | module miner # ( 20 | parameter CORES = 32'd1 21 | ) ( 22 | input clk, 23 | input reset, 24 | input [639:0] block, 25 | input [31:0] nonce_start, 26 | output nonce_found, 27 | output [31:0] nonce_out 28 | ); 29 | 30 | localparam OFFSET = 32'd733; 31 | 32 | wire [511:0] hash1, hash2, hash3, hash4; 33 | 34 | reg [511:0] midstate_d, midstate_q; 35 | reg [95:0] data_d, data_q; 36 | reg [31:0] target_d, target_q; 37 | reg [31:0] nonce_d, nonce_q; 38 | reg [31:0] nonce_out_d, nonce_out_q; 39 | reg nonce_found_d, nonce_found_q; 40 | reg reset_d, reset_q; 41 | 42 | reg [511:0] hash1_d, hash1_q, hash2_d, hash2_q, hash3_d, hash3_q; 43 | reg [31:0] hash4_d, hash4_q; 44 | 45 | assign nonce_found = nonce_found_q; 46 | assign nonce_out = nonce_out_q; 47 | 48 | skein512 skein ( clk, midstate_q, data_q, nonce_q, hash1 ); 49 | cube512 cube ( clk, hash1_q, hash2 ); 50 | fugue512 fugue ( clk, hash2_q, hash3 ); 51 | gost512 gost ( clk, hash3_q, hash4 ); 52 | 53 | always @ (*) begin 54 | 55 | if ( reset_q ) begin 56 | 57 | nonce_d <= nonce_start; 58 | nonce_out_d <= nonce_start - (CORES * OFFSET); 59 | 60 | nonce_found_d <= 1'b0; 61 | 62 | end 63 | else begin 64 | 65 | nonce_d <= nonce_q + CORES; 66 | nonce_out_d <= nonce_out_q + CORES; 67 | 68 | if ( hash4_q <= target_q ) 69 | nonce_found_d <= 1'b1; 70 | else 71 | nonce_found_d <= 1'b0; 72 | 73 | end 74 | 75 | midstate_d <= block[639:128]; 76 | data_d <= block[127:32]; 77 | target_d <= block[31:0]; 78 | 79 | hash1_d <= hash1; 80 | hash2_d <= hash2; 81 | hash3_d <= hash3; 82 | hash4_d <= hash4[287:256]; 83 | reset_d <= reset; 84 | 85 | end 86 | 87 | always @ (posedge clk) begin 88 | 89 | midstate_q <= midstate_d; 90 | data_q <= data_d; 91 | target_q <= target_d; 92 | 93 | nonce_q <= nonce_d; 94 | nonce_out_q <= nonce_out_d; 95 | 96 | hash1_q <= hash1_d; 97 | hash2_q <= hash2_d; 98 | hash3_q <= hash3_d; 99 | hash4_q <= hash4_d; 100 | 101 | nonce_found_q <= nonce_found_d; 102 | 103 | reset_q <= reset_d; 104 | 105 | $display ("Nonce: %X, Hash: %X, Found: %d", nonce_out_d, hash4_q, nonce_found_d); 106 | // $display (" H1: %x", hash1); 107 | // $display (" H2: %x", hash2); 108 | // $display (" H3: %x", hash3); 109 | // $display (" H4: %x", hash4[511:256]); 110 | 111 | end 112 | 113 | endmodule 114 | -------------------------------------------------------------------------------- /tribus/cl_common_defines.vh: -------------------------------------------------------------------------------- 1 | // Amazon FPGA Hardware Development Kit 2 | // 3 | // Copyright 2016 Amazon.com, Inc. or its affiliates. All Rights Reserved. 4 | // 5 | // Licensed under the Amazon Software License (the "License"). You may not use 6 | // this file except in compliance with the License. A copy of the License is 7 | // located at 8 | // 9 | // http://aws.amazon.com/asl/ 10 | // 11 | // or in the "license" file accompanying this file. This file is distributed on 12 | // an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, express or 13 | // implied. See the License for the specific language governing permissions and 14 | // limitations under the License. 15 | 16 | `ifndef CL_COMMON_DEFAULTS 17 | `define CL_COMMON_DEFAULTS 18 | 19 | // Value to return for PCIS access to unimplemented register address 20 | `define UNIMPLEMENTED_REG_VALUE 32'hdeaddead 21 | 22 | // CL Register Addresses 23 | `define HELLO_WORLD_REG_ADDR 32'h0000_0500 24 | `define VLED_REG_ADDR 32'h0000_0504 25 | 26 | `endif 27 | -------------------------------------------------------------------------------- /tribus/cl_id_defines.vh: -------------------------------------------------------------------------------- 1 | // Amazon FPGA Hardware Development Kit 2 | // 3 | // Copyright 2016 Amazon.com, Inc. or its affiliates. All Rights Reserved. 4 | // 5 | // Licensed under the Amazon Software License (the "License"). You may not use 6 | // this file except in compliance with the License. A copy of the License is 7 | // located at 8 | // 9 | // http://aws.amazon.com/asl/ 10 | // 11 | // or in the "license" file accompanying this file. This file is distributed on 12 | // an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, express or 13 | // implied. See the License for the specific language governing permissions and 14 | // limitations under the License. 15 | 16 | // CL_SH_ID0 17 | // - PCIe Vendor/Device ID Values 18 | // 31:16: PCIe Device ID 19 | // 15: 0: PCIe Vendor ID 20 | // - A Vendor ID value of 0x8086 is not valid. 21 | // - If using a Vendor ID value of 0x1D0F (Amazon) then valid 22 | // values for Device ID's are in the range of 0xF000 - 0xF0FF. 23 | // - A Vendor/Device ID of 0 (zero) is not valid. 24 | `define CL_SH_ID0 32'hF000_1D0F 25 | 26 | // CL_SH_ID1 27 | // - PCIe Subsystem/Subsystem Vendor ID Values 28 | // 31:16: PCIe Subsystem ID 29 | // 15: 0: PCIe Subsystem Vendor ID 30 | // - A PCIe Subsystem/Subsystem Vendor ID of 0 (zero) is not valid 31 | `define CL_SH_ID1 32'h1D51_FEDD 32 | -------------------------------------------------------------------------------- /tribus/cl_miner_defines.vh: -------------------------------------------------------------------------------- 1 | // Amazon FPGA Hardware Development Kit 2 | // 3 | // Copyright 2016 Amazon.com, Inc. or its affiliates. All Rights Reserved. 4 | // 5 | // Licensed under the Amazon Software License (the "License"). You may not use 6 | // this file except in compliance with the License. A copy of the License is 7 | // located at 8 | // 9 | // http://aws.amazon.com/asl/ 10 | // 11 | // or in the "license" file accompanying this file. This file is distributed on 12 | // an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, express or 13 | // implied. See the License for the specific language governing permissions and 14 | // limitations under the License. 15 | 16 | `ifndef CL_MINER_DEFINES 17 | `define CL_MINER_DEFINES 18 | 19 | //Put module name of the CL design here. This is used to instantiate in top.sv 20 | `define CL_NAME cl_miner 21 | 22 | //Highly recommeneded. For lib FIFO block, uses less async reset (take advantage of 23 | // FPGA flop init capability). This will help with routing resources. 24 | `define FPGA_LESS_RST 25 | 26 | // Uncomment to disable Virtual JTAG 27 | `define DISABLE_VJTAG_DEBUG 28 | 29 | `endif -------------------------------------------------------------------------------- /tribus/miner.v: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2017 Sprocket 3 | * 4 | * This is free software: you can redistribute it and/or modify 5 | * it under the terms of the GNU Affero General Public License with 6 | * additional permissions to the one published by the Free Software 7 | * Foundation, either version 3 of the License, or (at your option) 8 | * any later version. For more information see LICENSE. 9 | * 10 | * This program is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | * GNU Affero General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU Affero General Public License 16 | * along with this program. If not, see . 17 | */ 18 | 19 | module miner # ( 20 | parameter CORES = 32'd1 21 | ) ( 22 | input clk, 23 | input reset, 24 | input [1151:0] block, 25 | input [31:0] nonce_start, 26 | output nonce_found, 27 | output [31:0] nonce_out 28 | ); 29 | 30 | localparam OFFSET = 32'd242; 31 | 32 | wire [511:0] hash1, hash2; 33 | wire [31:0] hash3; 34 | 35 | reg [1023:0] midstate_d, midstate_q; 36 | reg [127:0] data_d, data_q; 37 | reg [31:0] target_d, target_q; 38 | reg [31:0] nonce_d, nonce_q; 39 | reg [31:0] nonce_out_d, nonce_out_q; 40 | reg nonce_found_d, nonce_found_q; 41 | reg reset_d, reset_q; 42 | 43 | reg [511:0] hash1_d, hash1_q, hash2_d, hash2_q; 44 | reg [31:0] hash3_d, hash3_q; 45 | 46 | assign nonce_found = nonce_found_q; 47 | assign nonce_out = nonce_out_q; 48 | 49 | JH512 jh ( clk, midstate_q, data_q, hash1 ); 50 | keccak512 keccak ( clk, hash1_q, hash2 ); 51 | echo512 echo ( clk, hash2_q, hash3 ); 52 | 53 | always @ (*) begin 54 | 55 | if ( reset_q ) begin 56 | 57 | nonce_d <= nonce_start; 58 | nonce_out_d <= nonce_start - (CORES * OFFSET); 59 | 60 | nonce_found_d <= 1'b0; 61 | 62 | end 63 | else begin 64 | 65 | nonce_d <= nonce_q + CORES; 66 | nonce_out_d <= nonce_out_q + CORES; 67 | 68 | if ( hash3_q <= target_q ) 69 | nonce_found_d <= 1'b1; 70 | else 71 | nonce_found_d <= 1'b0; 72 | 73 | end 74 | 75 | hash1_d <= hash1; 76 | hash2_d <= hash2; 77 | hash3_d <= hash3; 78 | reset_d <= reset; 79 | 80 | midstate_d <= block[1151:128]; 81 | data_d <= { block[127:32], nonce_q }; 82 | target_d <= block[31:0]; 83 | 84 | reset_d <= reset; 85 | 86 | end 87 | 88 | always @ (posedge clk) begin 89 | 90 | midstate_q <= midstate_d; 91 | data_q <= data_d; 92 | target_q <= target_d; 93 | 94 | nonce_q <= nonce_d; 95 | nonce_out_q <= nonce_out_d; 96 | 97 | hash1_q <= hash1_d; 98 | hash2_q <= hash2_d; 99 | hash3_q <= hash3_d; 100 | 101 | nonce_found_q <= nonce_found_d; 102 | 103 | reset_q <= reset_d; 104 | 105 | $display ("Nonce: %X, Hash: %X, Found: %d", nonce_out_d, hash3_q, nonce_found_d); 106 | // $display (" H1: %x", hash1); 107 | // $display (" H2: %x", hash2); 108 | // $display (" H3: %x", hash3); 109 | 110 | end 111 | 112 | endmodule 113 | --------------------------------------------------------------------------------