deps/scrypt/sha256.cpp
/* Initialize an HMAC-SHA256 operation with the given key. */
Initialize an HMAC-SHA256 operation with the given key.
Initialize an HMAC - SHA256 operation with the given key .
void
HMAC_SHA256_Init(HMAC_SHA256_CTX * ctx, const void * _K, size_t Klen)
{
	unsigned char pad[64];
	unsigned char khash[32];
	const unsigned char * K = (const unsigned char*)_K;
	size_t i;
	if (Klen > 64) {
		SHA256_Init(&ctx->ictx);
		SHA256_Update(&ctx->ictx, K, Klen);
		SHA256_Final(khash, &ctx->ictx);
		K = khash;
		Klen = 32;
	}
	SHA256_Init(&ctx->ictx);
	memset(pad, 0x36, 64);
	for (i = 0; i < Klen; i++)
		pad[i] ^= K[i];
	SHA256_Update(&ctx->ictx, pad, 64);
	SHA256_Init(&ctx->octx);
	memset(pad, 0x5c, 64);
	for (i = 0; i < Klen; i++)
		pad[i] ^= K[i];
	SHA256_Update(&ctx->octx, pad, 64);
	memset(khash, 0, 32);
}
void HMAC_SHA256_Init ( HMAC_SHA256_CTX * ctx , const void * _K , size_t Klen ) { unsigned char pad [ 64 ] ; unsigned char khash [ 32 ] ; const unsigned char * K = ( const unsigned char * ) _K ; size_t i ; if ( Klen > 64 ) { SHA256_Init ( & ctx -> ictx ) ; SHA256_Update ( & ctx -> ictx , K , Klen ) ; SHA256_Final ( khash , & ctx -> ictx ) ; K = khash ; Klen = 32 ; } SHA256_Init ( & ctx -> ictx ) ; memset ( pad , 0x36 , 64 ) ; for ( i = 0 ; i < Klen ; i ++ ) pad [ i ] ^= K [ i ] ; SHA256_Update ( & ctx -> ictx , pad , 64 ) ; SHA256_Init ( & ctx -> octx ) ; memset ( pad , 0x5c , 64 ) ; for ( i = 0 ; i < Klen ; i ++ ) pad [ i ] ^= K [ i ] ; SHA256_Update ( & ctx -> octx , pad , 64 ) ; memset ( khash , 0 , 32 ) ; }
Initialize an HMAC-SHA256 operation with the given key.
Initialize an HMAC - SHA256 operation with the given key .
/* If Klen > 64, the key is really SHA256(K). */ /* Inner SHA256 operation is SHA256(K xor [block of 0x36] || data). */ /* Outer SHA256 operation is SHA256(K xor [block of 0x5c] || hash). */ /* Clean the stack. */