Skip to content

Commit

Permalink
Allocate and deallocate memory for encryption contexts within cryptos…
Browse files Browse the repository at this point in the history
…oft,

rather than requiring each algorithm to provide their own memory handling.
This matches the interface already provided by cryptosoft for
authentication algorithms and removes the need for zerokey functions.

ok mikeb@
  • Loading branch information
4a6f656c committed Aug 25, 2013
1 parent 7106f51 commit 2dbd8e1
Show file tree
Hide file tree
Showing 3 changed files with 79 additions and 172 deletions.
18 changes: 14 additions & 4 deletions sys/crypto/cryptosoft.c
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/* $OpenBSD: cryptosoft.c,v 1.68 2012/12/11 14:49:31 mikeb Exp $ */
/* $OpenBSD: cryptosoft.c,v 1.69 2013/08/25 14:26:56 jsing Exp $ */

/*
* The author of this code is Angelos D. Keromytis (angelos@cis.upenn.edu)
Expand Down Expand Up @@ -824,7 +824,15 @@ swcr_newsession(u_int32_t *sid, struct cryptoini *cri)
txf = &enc_xform_null;
goto enccommon;
enccommon:
if (txf->setkey(&((*swd)->sw_kschedule), cri->cri_key,
if (txf->ctxsize > 0) {
(*swd)->sw_kschedule = malloc(txf->ctxsize,
M_CRYPTO_DATA, M_NOWAIT | M_ZERO);
if ((*swd)->sw_kschedule == NULL) {
swcr_freesession(i);
return EINVAL;
}
}
if (txf->setkey((*swd)->sw_kschedule, cri->cri_key,
cri->cri_klen / 8) < 0) {
swcr_freesession(i);
return EINVAL;
Expand Down Expand Up @@ -1013,8 +1021,10 @@ swcr_freesession(u_int64_t tid)
case CRYPTO_NULL:
txf = swd->sw_exf;

if (swd->sw_kschedule)
txf->zerokey(&(swd->sw_kschedule));
if (swd->sw_kschedule) {
explicit_bzero(swd->sw_kschedule, txf->ctxsize);
free(swd->sw_kschedule, M_CRYPTO_DATA);
}
break;

case CRYPTO_MD5_HMAC:
Expand Down

0 comments on commit 2dbd8e1

Please sign in to comment.