Exemplo n.º 1
0
static void speck64_decrypt
(
	const kripto_block *s,
	const void *ct,
	void *pt
)
{
	uint32_t a;
	uint32_t b;
	unsigned int i;

	a = LOAD32B(CU8(ct));
	b = LOAD32B(CU8(ct) + 4);

	for(i = s->rounds; i--;)
		IR(a, b, s->k[i]);

	STORE32B(a, U8(pt));
	STORE32B(b, U8(pt) + 4);
}
Exemplo n.º 2
0
/**
 * Terminate the hash to get the digest
 * @param md  The hash state
 * @param out [out] The destination of the hash (32 bytes)
 * @return CRYPT_OK if successful
*/
int sha256_done(struct sha256_state *md, unsigned char *out)
{
	int i;

	if (md->curlen >= sizeof(md->buf))
		return -1;

	/* increase the length of the message */
	md->length += md->curlen * 8;

	/* append the '1' bit */
	md->buf[md->curlen++] = (unsigned char) 0x80;

	/* if the length is currently above 56 bytes we append zeros
	 * then compress.  Then we can fall back to padding zeros and length
	 * encoding like normal.
	 */
	if (md->curlen > 56) {
		while (md->curlen < SHA256_BLOCK_SIZE)
			md->buf[md->curlen++] = (unsigned char) 0;

		sha256_compress(md, md->buf);
		md->curlen = 0;
	}

	/* pad up to 56 bytes of zeroes */
	while (md->curlen < 56)
		md->buf[md->curlen++] = (unsigned char) 0;

	/* store length */
	STORE64B(md->buf + 56, md->length);
	sha256_compress(md, md->buf);

	/* copy output */
	for (i = 0; i < 8; i++)
		STORE32B(out + (4 * i), md->state[i]);

	return 0;
}