C 13
BitcoinBlockHashing.c Guest on 8th November 2020 05:48:59 PM
  1. /*****************************************************************************************************
  2. * Description:                 Bitcoin Block Hashing
  3. *
  4. * Author:                      Dengxue Yan, Washington University in St. Louis
  5. *
  6. * Email:                       [email protected]
  7. *
  8. * Rev History:
  9. *       <Author>        <Date>        <Hardware>     <Version>        <Description>
  10. *     Dengxue Yan   10-20-2016 15:30       --           1.00             Create
  11. *****************************************************************************************************/
  12. //====================================================================================================
  13. // Declaration of header files
  14. //----------------------------------------------------------------------------------------------------
  15. // Lib headers
  16. #include <stdio.h>
  17. #include <memory.h>
  18. #include <string.h>
  19.  
  20. // Self-defined headers
  21. #include "sha256.h"
  22.  
  23. //====================================================================================================
  24. // Functions implementation
  25. //----------------------------------------------------------------------------------------------------
  26. //----------------------------------------------------------------------------------------------------
  27. // Interface functions
  28. //----------------------------------------------------------------------------------------------------
  29. //----------------------------------------------------------------------------------------------------
  30. //   Function: BitcoinBlockHashing
  31. //      Input: BYTE const *input: the bitcoin orginal array
  32. //             int size: it should be 80 bytes
  33. //     Output: BYTE *output: the output of the bitcoin block after hash algorithm
  34. //                           the size should be SHA256_BLOCK_SIZE
  35. //     Return: int: The status of function
  36. //Description: Bitcoin Block Hashing Algorithm
  37. //    <AUTHOR>        <MODIFYTIME>            <REASON>
  38. //   Dengxue Yan     10-20-2016 15:30           Create
  39. //----------------------------------------------------------------------------------------------------
  40. int BitcoinBlockHashing(BYTE *output, BYTE const *input, int size)
  41. {
  42.         SHA256_CTX ctx;
  43.  
  44.     if ((NULL == output) || (NULL == input) || (80 != size))
  45.     {
  46.         printf("BitcoinBlockHashing Function entry check failed\n");
  47.         return -1;
  48.     }
  49.  
  50.     sha256_init(&ctx);
  51.     sha256_update(&ctx, input, size);
  52.     sha256_final(&ctx, output);
  53.  
  54.     sha256_init(&ctx);
  55.     sha256_update(&ctx, output, SHA256_BLOCK_SIZE);
  56.     sha256_final(&ctx, output);
  57.  
  58.     return 0;
  59. }

Paste is for source code and general debugging text.

Login or Register to edit, delete and keep track of your pastes and more.

Raw Paste

Login or Register to edit or fork this paste. It's free.