static void Sha256_WriteByteBlock(CSha256 *p) { uint32_t data32[16]; unsigned i; for (i = 0; i < 16; i++) data32[i] = ((uint32_t)(p->buffer[i * 4 ]) << 24) + ((uint32_t)(p->buffer[i * 4 + 1]) << 16) + ((uint32_t)(p->buffer[i * 4 + 2]) << 8) + ((uint32_t)(p->buffer[i * 4 + 3])); Sha256_Transform(p->state, data32); }
static void Sha256_WritebyteBlock(SHA256Context *p) { ulong32 data32[16]; unsigned i; for (i = 0; i < 16; i++) data32[i] = ((ulong32)(p->buffer[i * 4 ]) << 24) + ((ulong32)(p->buffer[i * 4 + 1]) << 16) + ((ulong32)(p->buffer[i * 4 + 2]) << 8) + ((ulong32)(p->buffer[i * 4 + 3])); Sha256_Transform(p->state, data32); }
static void Sha256_Final(Sha256ContextType *context, uint8_t hash[]) { uint32_t i; i = context->DataLen; // Pad whatever data is left in the buffer. if (context->DataLen < 56) { context->Data[i++] = 0x80; while (i < 56) context->Data[i++] = 0x00; } else { context->Data[i++] = 0x80; while (i < 64) context->Data[i++] = 0x00; Sha256_Transform(context,context->Data); memset(context->Data, 0, 56); } // Append to the padding the total message's length in bits and transform. DBL_INT_ADD(context->BitLen[0], context->BitLen[1], context->DataLen * 8); PUT_UINT32(context->BitLen[0], context->Data, 60); PUT_UINT32(context->BitLen[1], context->Data, 56); Sha256_Transform(context, context->Data); // Copy result into output buffer PUT_UINT32(context->State[0], hash, 0); PUT_UINT32(context->State[1], hash, 4); PUT_UINT32(context->State[2], hash, 8); PUT_UINT32(context->State[3], hash, 12); PUT_UINT32(context->State[4], hash, 16); PUT_UINT32(context->State[5], hash, 20); PUT_UINT32(context->State[6], hash, 24); PUT_UINT32(context->State[7], hash, 28); }
static void Sha256_Update(Sha256ContextType *context, const uint8_t *data, uint32_t dataLen) { uint32_t i; for (i = 0; i < dataLen; i++) { context->Data[context->DataLen] = data[i]; context->DataLen++; if (context->DataLen == 64) { Sha256_Transform(context,context->Data); DBL_INT_ADD(context->BitLen[0], context->BitLen[1], 512); context->DataLen = 0; } } }