ses->hs_used = 1;
hifn_newsession(u_int32_t *sidp, struct cryptoini *cri){	struct cryptoini *c;	struct hifn_softc *sc = NULL;	int i, mac = 0, cry = 0, comp = 0, sesn;	struct hifn_session *ses = NULL;	if (sidp == NULL || cri == NULL)		return (EINVAL);	for (i = 0; i < hifn_cd.cd_ndevs; i++) {		sc = hifn_cd.cd_devs[i];		if (sc == NULL)			break;		if (sc->sc_cid == (*sidp))			break;	}	if (sc == NULL)		return (EINVAL);	if (sc->sc_sessions == NULL) {		ses = sc->sc_sessions = (struct hifn_session *)malloc(		    sizeof(*ses), M_DEVBUF, M_NOWAIT);		if (ses == NULL)			return (ENOMEM);		sesn = 0;		sc->sc_nsessions = 1;	} else {		for (sesn = 0; sesn < sc->sc_nsessions; sesn++) {			if (!sc->sc_sessions[sesn].hs_used) {				ses = &sc->sc_sessions[sesn];				break;			}		}		if (ses == NULL) {			sesn = sc->sc_nsessions;			ses = (struct hifn_session *)malloc((sesn + 1) *			    sizeof(*ses), M_DEVBUF, M_NOWAIT);			if (ses == NULL)				return (ENOMEM);			bcopy(sc->sc_sessions, ses, sesn * sizeof(*ses));			bzero(sc->sc_sessions, sesn * sizeof(*ses));			free(sc->sc_sessions, M_DEVBUF);			sc->sc_sessions = ses;			ses = &sc->sc_sessions[sesn];			sc->sc_nsessions++;		}	}	bzero(ses, sizeof(*ses));	ses->hs_used = 1;	for (c = cri; c != NULL; c = c->cri_next) {		switch (c->cri_alg) {		case CRYPTO_MD5:		case CRYPTO_SHA1:		case CRYPTO_MD5_HMAC:		case CRYPTO_SHA1_HMAC:			if (mac)				return (EINVAL);			mac = 1;			break;		case CRYPTO_DES_CBC:		case CRYPTO_3DES_CBC:		case CRYPTO_AES_CBC:			get_random_bytes(ses->hs_iv,			    (c->cri_alg == CRYPTO_AES_CBC ?			    HIFN_AES_IV_LENGTH : HIFN_IV_LENGTH));			/*FALLTHROUGH*/		case CRYPTO_ARC4:			if (cry)				return (EINVAL);			cry = 1;			break;		case CRYPTO_LZS_COMP:			if (comp)				return (EINVAL);			comp = 1;			break;		default:			return (EINVAL);		}	}	if (mac == 0 && cry == 0 && comp == 0)		return (EINVAL);	/*	 * XXX only want to support compression without chaining to	 * MAC/crypt engine right now	 */	if ((comp && mac) || (comp && cry))		return (EINVAL);	*sidp = HIFN_SID(sc->sc_dv.dv_unit, sesn);	return (0);}