static void md5_final(void *ctx, u8 *out)
{
	struct md5_ctx *mctx = ctx;
	const unsigned int offset = mctx->byte_count & 0x3f;
	char *p = (char *)mctx->block + offset;
	int padding = 56 - (offset + 1);

	*p++ = 0x80;
	if (padding < 0) {
		memset(p, 0x00, padding + sizeof (u64));
		md5_transform_helper(mctx);
		p = (char *)mctx->block;
		padding = 56;
	}

	memset(p, 0, padding);
	mctx->block[14] = mctx->byte_count << 3;
	mctx->block[15] = mctx->byte_count >> 29;
	le32_to_cpu_array(mctx->block, (sizeof(mctx->block) -
	                  sizeof(u64)) / sizeof(u32));
	md5_transform(mctx->hash, mctx->block);
	cpu_to_le32_array(mctx->hash, sizeof(mctx->hash) / sizeof(u32));
	memcpy(out, mctx->hash, sizeof(mctx->hash));
	memset(mctx, 0, sizeof(*mctx));
}
/*
 * Final wrapup - pad to 64-byte boundary with the bit pattern 
 * 1 0* (64-bit count of bits processed, MSB-first)
 */
static inline void
md5_final (md5_ctx_t * ctx, u8 out[16])
{
	/* Number of bytes in ctx->in */
	const int offset = ctx->byte_count & 0x3f;

	/* p points after last content byte in ctx->in */
	u8 *p = (u8 *) ctx->in + offset;

	/* Bytes of padding needed to make 56 bytes (-8..55) */
	int padding = 56 - (offset + 1);

	/* Set the first byte of padding to 0x80.  There is always room. */
	*p++ = 0x80;

	if (padding < 0) {	/* Padding forces an extra block */
		memset (p, 0x00, padding + sizeof (u64));

		md5_transform_helper (ctx);

		p = (u8 *) ctx->in;
		padding = 56;
	}

	/* pad remaining bytes w/ 0x00 */
	memset (p, 0x00, padding);

	/* Append length in bits and transform */
	ctx->in[14] = ctx->byte_count << 3;	/* low order word first */
	ctx->in[15] = ctx->byte_count >> 29;

	/* keep the appended bit-count words in host order! */
	le32_to_cpu_array (ctx->in,
			   (sizeof (ctx->in) - sizeof (u64)) / sizeof (u32));
	md5_transform (ctx->hash, ctx->in);

	/* convert digest buf from host to LE byteorder */
	cpu_to_le32_array (ctx->hash, sizeof (ctx->hash) / sizeof (u32));

	/* copy to output buffer */
	memcpy (out, ctx->hash, sizeof (ctx->hash));

	/* wipe context */
	memset (ctx, 0, sizeof (ctx));
}
Example #3
0
/*! \fn static void md5_final(struct crypto_tfm *tfm, u8 *out)
 *  \ingroup IFX_MD5_FUNCTIONS
 *  \brief compute final md5 value   
 *  \param tfm linux crypto algo transform  
 *  \param out final md5 output value  
*/                                 
static int md5_final(struct shash_desc *desc, u8 *out)
{
    struct md5_ctx *mctx = shash_desc_ctx(desc);
    const unsigned int offset = mctx->byte_count & 0x3f;
    char *p = (char *)mctx->block + offset;
    int padding = 56 - (offset + 1);
    volatile struct deu_hash_t *hashs = (struct deu_hash_t *) HASH_START;
    unsigned long flag;

    *p++ = 0x80;
    if (padding < 0) {
        memset(p, 0x00, padding + sizeof (u64));
        md5_transform_helper(mctx);
        p = (char *)mctx->block;
        padding = 56;
    }

    memset(p, 0, padding);
    mctx->block[14] = endian_swap(mctx->byte_count << 3);
    mctx->block[15] = endian_swap(mctx->byte_count >> 29);

#if 0
    le32_to_cpu_array(mctx->block, (sizeof(mctx->block) -
                      sizeof(u64)) / sizeof(u32));
#endif

    md5_transform(mctx, mctx->hash, mctx->block);                                                 

    CRTCL_SECT_START;

    *((u32 *) out + 0) = endian_swap (hashs->D1R);
    *((u32 *) out + 1) = endian_swap (hashs->D2R);
    *((u32 *) out + 2) = endian_swap (hashs->D3R);
    *((u32 *) out + 3) = endian_swap (hashs->D4R);

    CRTCL_SECT_END;

    // Wipe context
    memset(mctx, 0, sizeof(*mctx));

    return 0;
}
Example #4
0
void cryptohash_md4_finalize(struct md4_ctx *ctx, uint8_t *out)
{
    static uint8_t padding[64] = { 0x80, };
    uint64_t bits;
    uint32_t index, padlen;

    /* add padding and update data with it */
    bits = cpu_to_le64(ctx->sz << 3);

    /* pad out to 56 */
    index = (uint32_t) (ctx->sz & 0x3f);
    padlen = (index < 56) ? (56 - index) : ((64 + 56) - index);
    cryptohash_md4_update(ctx, padding, padlen);

    /* append length */
    cryptohash_md4_update(ctx, (uint8_t *) &bits, sizeof(bits));

    /* output hash */
    le32_to_cpu_array((uint32_t *) out, ctx->h, 4);
}
static inline void md5_transform_helper(struct md5_ctx *ctx)
{
	le32_to_cpu_array(ctx->block, sizeof(ctx->block) / sizeof(u32));
	md5_transform(ctx->hash, ctx->block);
}
static inline void
md5_transform_helper (md5_ctx_t * ctx)
{
	le32_to_cpu_array (ctx->in, sizeof (ctx->in) / sizeof (u32));
	md5_transform (ctx->hash, ctx->in);
}