/***************************************************************************************************** * Description: Bitcoin Block Hashing * * Author: Dengxue Yan, Washington University in St. Louis * * Email: Dengxue.Yan@wustl.edu * * Rev History: * * Dengxue Yan 10-20-2016 15:30 -- 1.00 Create *****************************************************************************************************/ //==================================================================================================== // Declaration of header files //---------------------------------------------------------------------------------------------------- // Lib headers #include #include #include // Self-defined headers #include "sha256.h" //==================================================================================================== // Functions implementation //---------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------- // Interface functions //---------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------- // Function: BitcoinBlockHashing // Input: BYTE const *input: the bitcoin orginal array // int size: it should be 80 bytes // Output: BYTE *output: the output of the bitcoin block after hash algorithm // the size should be SHA256_BLOCK_SIZE // Return: int: The status of function //Description: Bitcoin Block Hashing Algorithm // // Dengxue Yan 10-20-2016 15:30 Create //---------------------------------------------------------------------------------------------------- int BitcoinBlockHashing(BYTE *output, BYTE const *input, int size) { SHA256_CTX ctx; if ((NULL == output) || (NULL == input) || (80 != size)) { printf("BitcoinBlockHashing Function entry check failed\n"); return -1; } sha256_init(&ctx); sha256_update(&ctx, input, size); sha256_final(&ctx, output); sha256_init(&ctx); sha256_update(&ctx, output, SHA256_BLOCK_SIZE); sha256_final(&ctx, output); return 0; }