src/C/FreeBSD/FreeBSD-10.0/opencrypto/cryptosoft.c
/*
 * Compute keyed-hash authenticator.
 */
Compute keyed-hash authenticator.
Compute keyed - hash authenticator .
static int
swcr_authcompute(struct cryptodesc *crd, struct swcr_data *sw, caddr_t buf,
    int flags)
{
	unsigned char aalg[HASH_MAX_LEN];
	struct auth_hash *axf;
	union authctx ctx;
	int err;
	if (sw->sw_ictx == 0)
		return EINVAL;
	axf = sw->sw_axf;
	if (crd->crd_flags & CRD_F_KEY_EXPLICIT)
		swcr_authprepare(axf, sw, crd->crd_key, crd->crd_klen);
	bcopy(sw->sw_ictx, &ctx, axf->ctxsize);
	err = crypto_apply(flags, buf, crd->crd_skip, crd->crd_len,
	    (int (*)(void *, void *, unsigned int))axf->Update, (caddr_t)&ctx);
	if (err)
		return err;
	switch (sw->sw_alg) {
	case CRYPTO_MD5_HMAC:
	case CRYPTO_SHA1_HMAC:
	case CRYPTO_SHA2_256_HMAC:
	case CRYPTO_SHA2_384_HMAC:
	case CRYPTO_SHA2_512_HMAC:
	case CRYPTO_RIPEMD160_HMAC:
		if (sw->sw_octx == NULL)
			return EINVAL;
		axf->Final(aalg, &ctx);
		bcopy(sw->sw_octx, &ctx, axf->ctxsize);
		axf->Update(&ctx, aalg, axf->hashsize);
		axf->Final(aalg, &ctx);
		break;
	case CRYPTO_MD5_KPDK:
	case CRYPTO_SHA1_KPDK:
		if (sw->sw_octx == NULL)
			return EINVAL;
		axf->Update(&ctx, sw->sw_octx, sw->sw_klen);
		axf->Final(aalg, &ctx);
		break;
	case CRYPTO_NULL_HMAC:
		axf->Final(aalg, &ctx);
		break;
	}
	crypto_copyback(flags, buf, crd->crd_inject,
	    sw->sw_mlen == 0 ? axf->hashsize : sw->sw_mlen, aalg);
	return 0;
}
static int swcr_authcompute ( struct cryptodesc * crd , struct swcr_data * sw , caddr_t buf , int flags ) { unsigned char aalg [ HASH_MAX_LEN ] ; struct auth_hash * axf ; union authctx ctx ; int err ; if ( sw -> sw_ictx == 0 ) return EINVAL ; axf = sw -> sw_axf ; if ( crd -> crd_flags & CRD_F_KEY_EXPLICIT ) swcr_authprepare ( axf , sw , crd -> crd_key , crd -> crd_klen ) ; bcopy ( sw -> sw_ictx , & ctx , axf -> ctxsize ) ; err = crypto_apply ( flags , buf , crd -> crd_skip , crd -> crd_len , ( int ( * ) ( void * , void * , unsigned int ) ) axf -> Update , ( caddr_t ) & ctx ) ; if ( err ) return err ; switch ( sw -> sw_alg ) { case CRYPTO_MD5_HMAC : case CRYPTO_SHA1_HMAC : case CRYPTO_SHA2_256_HMAC : case CRYPTO_SHA2_384_HMAC : case CRYPTO_SHA2_512_HMAC : case CRYPTO_RIPEMD160_HMAC : if ( sw -> sw_octx == NULL ) return EINVAL ; axf -> Final ( aalg , & ctx ) ; bcopy ( sw -> sw_octx , & ctx , axf -> ctxsize ) ; axf -> Update ( & ctx , aalg , axf -> hashsize ) ; axf -> Final ( aalg , & ctx ) ; break ; case CRYPTO_MD5_KPDK : case CRYPTO_SHA1_KPDK : if ( sw -> sw_octx == NULL ) return EINVAL ; axf -> Update ( & ctx , sw -> sw_octx , sw -> sw_klen ) ; axf -> Final ( aalg , & ctx ) ; break ; case CRYPTO_NULL_HMAC : axf -> Final ( aalg , & ctx ) ; break ; } crypto_copyback ( flags , buf , crd -> crd_inject , sw -> sw_mlen == 0 ? axf -> hashsize : sw -> sw_mlen , aalg ) ; return 0 ; }
Compute keyed-hash authenticator.
Compute keyed - hash authenticator .
/* If we have no key saved, return error. */ /*
		 * Add the trailing copy of the key (see comment in
		 * swcr_authprepare()) after the data:
		 *   ALGO( .., key, algofill )
		 * and let Final() do the proper, natural "algofill"
		 * padding.
		 */ /* Inject the authentication data */