fork of what I have been writing
ES_CW2_Starter_STARFISH/CryptoMining.h@11:038d3ba0d720, 2020-03-06 (annotated)
- Committer:
- kubitz
- Date:
- Fri Mar 06 14:27:16 2020 +0000
- Revision:
- 11:038d3ba0d720
File tree - restructured
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
kubitz | 11:038d3ba0d720 | 1 | // Crypto mining variables |
kubitz | 11:038d3ba0d720 | 2 | uint8_t sequence[] = {0x45, 0x6D, 0x62, 0x65, 0x64, 0x64, 0x65, 0x64, |
kubitz | 11:038d3ba0d720 | 3 | 0x20, 0x53, 0x79, 0x73, 0x74, 0x65, 0x6D, 0x73, |
kubitz | 11:038d3ba0d720 | 4 | 0x20, 0x61, 0x72, 0x65, 0x20, 0x66, 0x75, 0x6E, |
kubitz | 11:038d3ba0d720 | 5 | 0x20, 0x61, 0x6E, 0x64, 0x20, 0x64, 0x6F, 0x20, |
kubitz | 11:038d3ba0d720 | 6 | 0x61, 0x77, 0x65, 0x73, 0x6F, 0x6D, 0x65, 0x20, |
kubitz | 11:038d3ba0d720 | 7 | 0x74, 0x68, 0x69, 0x6E, 0x67, 0x73, 0x21, 0x20, |
kubitz | 11:038d3ba0d720 | 8 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
kubitz | 11:038d3ba0d720 | 9 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}; |
kubitz | 11:038d3ba0d720 | 10 | uint64_t *key = (uint64_t *)&sequence[48]; |
kubitz | 11:038d3ba0d720 | 11 | uint64_t *nonce = (uint64_t *)&sequence[56]; |
kubitz | 11:038d3ba0d720 | 12 | uint32_t successful_nonce = 0; |
kubitz | 11:038d3ba0d720 | 13 | uint32_t last_nonce_number = 0; |
kubitz | 11:038d3ba0d720 | 14 | uint8_t hash[32]; |
kubitz | 11:038d3ba0d720 | 15 | Mail<uint64_t, 16> crypto_mail; |
kubitz | 11:038d3ba0d720 | 16 | |
kubitz | 11:038d3ba0d720 | 17 | |
kubitz | 11:038d3ba0d720 | 18 | // Function declartion: |
kubitz | 11:038d3ba0d720 | 19 | // Thread that prints the successful nonces |
kubitz | 11:038d3ba0d720 | 20 | void thread_crypto_print(); |
kubitz | 11:038d3ba0d720 | 21 | // Adds email with successful nonce to Mailbox to be retrieved by thread_crypto_print() |
kubitz | 11:038d3ba0d720 | 22 | void putMessageCrypto(uint64_t nonce); |
kubitz | 11:038d3ba0d720 | 23 | |
kubitz | 11:038d3ba0d720 | 24 | // Thread to print successful Hashes |
kubitz | 11:038d3ba0d720 | 25 | void thread_crypto_print() |
kubitz | 11:038d3ba0d720 | 26 | { |
kubitz | 11:038d3ba0d720 | 27 | while (true) |
kubitz | 11:038d3ba0d720 | 28 | { |
kubitz | 11:038d3ba0d720 | 29 | osEvent evt = crypto_mail.get(); |
kubitz | 11:038d3ba0d720 | 30 | if (evt.status == osEventMail) |
kubitz | 11:038d3ba0d720 | 31 | { |
kubitz | 11:038d3ba0d720 | 32 | uint64_t *matching_nonce = (uint64_t *)evt.value.p; |
kubitz | 11:038d3ba0d720 | 33 | pc.printf("Matching nonce found: %llu \n\r",(long long) *matching_nonce); |
kubitz | 11:038d3ba0d720 | 34 | crypto_mail.free(matching_nonce); |
kubitz | 11:038d3ba0d720 | 35 | } |
kubitz | 11:038d3ba0d720 | 36 | } |
kubitz | 11:038d3ba0d720 | 37 | } |
kubitz | 11:038d3ba0d720 | 38 | |
kubitz | 11:038d3ba0d720 | 39 | // Put message in Mail box for Crypto printing |
kubitz | 11:038d3ba0d720 | 40 | void putMessageCrypto(uint64_t nonce) |
kubitz | 11:038d3ba0d720 | 41 | { |
kubitz | 11:038d3ba0d720 | 42 | uint64_t *mail = crypto_mail.alloc(); |
kubitz | 11:038d3ba0d720 | 43 | *mail = nonce; |
kubitz | 11:038d3ba0d720 | 44 | crypto_mail.put(mail); |
kubitz | 11:038d3ba0d720 | 45 | } |
kubitz | 11:038d3ba0d720 | 46 |