From 22c244342ee6f54e10824582a6dc9e3b3bd431ed Mon Sep 17 00:00:00 2001 From: "Angelos D. Keromytis" Date: Sat, 5 May 2001 00:31:35 +0000 Subject: Use the M_CRYPTO_DATA and M_CRYPTO_OPS malloc types. --- sys/crypto/crypto.c | 14 +++++++------- sys/crypto/cryptosoft.c | 37 +++++++++++++++++++++---------------- sys/crypto/skipjack.c | 7 +++---- sys/crypto/xform.c | 30 ++++++++++++++++-------------- 4 files changed, 47 insertions(+), 41 deletions(-) (limited to 'sys') diff --git a/sys/crypto/crypto.c b/sys/crypto/crypto.c index 03b642fe32e..256eeb88db1 100644 --- a/sys/crypto/crypto.c +++ b/sys/crypto/crypto.c @@ -1,4 +1,4 @@ -/* $OpenBSD: crypto.c,v 1.15 2000/12/13 08:34:05 provos Exp $ */ +/* $OpenBSD: crypto.c,v 1.16 2001/05/05 00:31:34 angelos Exp $ */ /* * The author of this code is Angelos D. Keromytis (angelos@cis.upenn.edu) @@ -164,7 +164,7 @@ crypto_get_driverid(void) { crypto_drivers_num = CRYPTO_DRIVERS_INITIAL; crypto_drivers = malloc(crypto_drivers_num * sizeof(struct cryptocap), - M_XDATA, M_NOWAIT); + M_CRYPTO_DATA, M_NOWAIT); if (crypto_drivers == NULL) { crypto_drivers_num = 0; @@ -188,7 +188,7 @@ crypto_get_driverid(void) return -1; newdrv = malloc(2 * crypto_drivers_num * sizeof(struct cryptocap), - M_XDATA, M_NOWAIT); + M_CRYPTO_DATA, M_NOWAIT); if (newdrv == NULL) return -1; @@ -373,7 +373,7 @@ crypto_freereq(struct cryptop *crp) crp->crp_desc = crd->crd_next; if (crypto_queue_num + 1 > crypto_queue_max) - FREE(crd, M_XDATA); + FREE(crd, M_CRYPTO_OPS); else { crd->crd_next = cryptodesc_queue; @@ -383,7 +383,7 @@ crypto_freereq(struct cryptop *crp) } if (crypto_queue_num + 1 > crypto_queue_max) - FREE(crp, M_XDATA); + FREE(crp, M_CRYPTO_OPS); else { crp->crp_next = cryptop_queue; @@ -406,7 +406,7 @@ crypto_getreq(int num) if (cryptop_queue == NULL) { - MALLOC(crp, struct cryptop *, sizeof(struct cryptop), M_XDATA, + MALLOC(crp, struct cryptop *, sizeof(struct cryptop), M_CRYPTO_OPS, M_NOWAIT); if (crp == NULL) { @@ -428,7 +428,7 @@ crypto_getreq(int num) if (cryptodesc_queue == NULL) { MALLOC(crd, struct cryptodesc *, sizeof(struct cryptodesc), - M_XDATA, M_NOWAIT); + M_CRYPTO_OPS, M_NOWAIT); if (crd == NULL) { splx(s); diff --git a/sys/crypto/cryptosoft.c b/sys/crypto/cryptosoft.c index 770259768e0..cfdf483b36f 100644 --- a/sys/crypto/cryptosoft.c +++ b/sys/crypto/cryptosoft.c @@ -1,4 +1,4 @@ -/* $OpenBSD: cryptosoft.c,v 1.17 2000/11/17 04:07:05 angelos Exp $ */ +/* $OpenBSD: cryptosoft.c,v 1.18 2001/05/05 00:31:34 angelos Exp $ */ /* * The author of this code is Angelos D. Keromytis (angelos@cis.upenn.edu) @@ -400,7 +400,7 @@ swcr_newsession(u_int32_t *sid, struct cryptoini *cri) swcr_sesnum *= 2; swd = malloc(swcr_sesnum * sizeof(struct swcr_data *), - M_XDATA, M_NOWAIT); + M_CRYPTO_DATA, M_NOWAIT); if (swd == NULL) { /* Reset session number */ @@ -419,7 +419,7 @@ swcr_newsession(u_int32_t *sid, struct cryptoini *cri) { bcopy(swcr_sessions, swd, (swcr_sesnum / 2) * sizeof(struct swcr_data *)); - free(swcr_sessions, M_XDATA); + free(swcr_sessions, M_CRYPTO_DATA); } swcr_sessions = swd; @@ -430,8 +430,8 @@ swcr_newsession(u_int32_t *sid, struct cryptoini *cri) while (cri) { - MALLOC(*swd, struct swcr_data *, sizeof(struct swcr_data), M_XDATA, - M_NOWAIT); + MALLOC(*swd, struct swcr_data *, sizeof(struct swcr_data), + M_CRYPTO_DATA, M_NOWAIT); if (*swd == NULL) { swcr_freesession(i); @@ -469,7 +469,8 @@ swcr_newsession(u_int32_t *sid, struct cryptoini *cri) enccommon: txf->setkey(&((*swd)->sw_kschedule), cri->cri_key, cri->cri_klen / 8); - (*swd)->sw_iv = malloc(txf->blocksize, M_XDATA, M_NOWAIT); + (*swd)->sw_iv = malloc(txf->blocksize, M_CRYPTO_DATA, + M_NOWAIT); if ((*swd)->sw_iv == NULL) { swcr_freesession(i); @@ -493,14 +494,16 @@ swcr_newsession(u_int32_t *sid, struct cryptoini *cri) axf = &auth_hash_hmac_ripemd_160_96; authcommon: - (*swd)->sw_ictx = malloc(axf->ctxsize, M_XDATA, M_NOWAIT); + (*swd)->sw_ictx = malloc(axf->ctxsize, M_CRYPTO_DATA, + M_NOWAIT); if ((*swd)->sw_ictx == NULL) { swcr_freesession(i); return ENOBUFS; } - (*swd)->sw_octx = malloc(axf->ctxsize, M_XDATA, M_NOWAIT); + (*swd)->sw_octx = malloc(axf->ctxsize, M_CRYPTO_DATA, + M_NOWAIT); if ((*swd)->sw_octx == NULL) { swcr_freesession(i); @@ -539,7 +542,8 @@ swcr_newsession(u_int32_t *sid, struct cryptoini *cri) axf = &auth_hash_key_sha1; auth2common: - (*swd)->sw_ictx = malloc(axf->ctxsize, M_XDATA, M_NOWAIT); + (*swd)->sw_ictx = malloc(axf->ctxsize, M_CRYPTO_DATA, + M_NOWAIT); if ((*swd)->sw_ictx == NULL) { swcr_freesession(i); @@ -547,7 +551,8 @@ swcr_newsession(u_int32_t *sid, struct cryptoini *cri) } /* Store the key so we can "append" it to the payload */ - (*swd)->sw_octx = malloc(cri->cri_klen / 8, M_XDATA, M_NOWAIT); + (*swd)->sw_octx = malloc(cri->cri_klen / 8, M_CRYPTO_DATA, + M_NOWAIT); if ((*swd)->sw_octx == NULL) { swcr_freesession(i); @@ -615,7 +620,7 @@ swcr_freesession(u_int64_t tid) txf->zerokey(&(swd->sw_kschedule)); if (swd->sw_iv) - free(swd->sw_iv, M_XDATA); + free(swd->sw_iv, M_CRYPTO_DATA); break; case CRYPTO_MD5_HMAC: @@ -626,13 +631,13 @@ swcr_freesession(u_int64_t tid) if (swd->sw_ictx) { bzero(swd->sw_ictx, axf->ctxsize); - free(swd->sw_ictx, M_XDATA); + free(swd->sw_ictx, M_CRYPTO_DATA); } if (swd->sw_octx) { bzero(swd->sw_octx, axf->ctxsize); - free(swd->sw_octx, M_XDATA); + free(swd->sw_octx, M_CRYPTO_DATA); } break; @@ -643,18 +648,18 @@ swcr_freesession(u_int64_t tid) if (swd->sw_ictx) { bzero(swd->sw_ictx, axf->ctxsize); - free(swd->sw_ictx, M_XDATA); + free(swd->sw_ictx, M_CRYPTO_DATA); } if (swd->sw_octx) { bzero(swd->sw_octx, swd->sw_klen); - free(swd->sw_octx, M_XDATA); + free(swd->sw_octx, M_CRYPTO_DATA); } break; } - FREE(swd, M_XDATA); + FREE(swd, M_CRYPTO_DATA); } return 0; diff --git a/sys/crypto/skipjack.c b/sys/crypto/skipjack.c index 3afe824b30d..8e4784ba990 100644 --- a/sys/crypto/skipjack.c +++ b/sys/crypto/skipjack.c @@ -1,4 +1,4 @@ -/* $OpenBSD: skipjack.c,v 1.2 2000/06/06 06:49:47 deraadt Exp $ */ +/* $OpenBSD: skipjack.c,v 1.3 2001/05/05 00:31:34 angelos Exp $ */ /* * Further optimized test implementation of SKIPJACK algorithm @@ -68,9 +68,8 @@ subkey_table_gen (u_int8_t *key, u_int8_t **key_tables) for (k = 0; k < 10; k++) { u_int8_t key_byte = key [k]; - u_int8_t * table = (u_int8_t *) malloc(0x100, M_XDATA, M_WAITOK); - /* XXX */ - + u_int8_t * table = (u_int8_t *) malloc(0x100, M_CRYPTO_DATA, + M_WAITOK); key_tables [k] = table; for (i = 0; i < 0x100; i++) table [i] = ftable [i ^ key_byte]; diff --git a/sys/crypto/xform.c b/sys/crypto/xform.c index 11b811e254b..ff62cf8dfc1 100644 --- a/sys/crypto/xform.c +++ b/sys/crypto/xform.c @@ -1,4 +1,4 @@ -/* $OpenBSD: xform.c,v 1.4 2000/11/17 04:07:05 angelos Exp $ */ +/* $OpenBSD: xform.c,v 1.5 2001/05/05 00:31:34 angelos Exp $ */ /* * The authors of this code are John Ioannidis (ji@tla.org), @@ -207,7 +207,7 @@ des1_decrypt(caddr_t key, u_int8_t *blk) void des1_setkey(u_int8_t **sched, u_int8_t *key, int len) { - MALLOC(*sched, u_int8_t *, 128, M_XDATA, M_WAITOK); + MALLOC(*sched, u_int8_t *, 128, M_CRYPTO_DATA, M_WAITOK); bzero(*sched, 128); des_set_key(key, *sched); } @@ -216,7 +216,7 @@ void des1_zerokey(u_int8_t **sched) { bzero(*sched, 128); - FREE(*sched, M_XDATA); + FREE(*sched, M_CRYPTO_DATA); *sched = NULL; } @@ -235,7 +235,7 @@ des3_decrypt(caddr_t key, u_int8_t *blk) void des3_setkey(u_int8_t **sched, u_int8_t *key, int len) { - MALLOC(*sched, u_int8_t *, 384, M_XDATA, M_WAITOK); + MALLOC(*sched, u_int8_t *, 384, M_CRYPTO_DATA, M_WAITOK); bzero(*sched, 384); des_set_key(key, *sched); des_set_key(key + 8, *sched + 128); @@ -246,7 +246,7 @@ void des3_zerokey(u_int8_t **sched) { bzero(*sched, 384); - FREE(*sched, M_XDATA); + FREE(*sched, M_CRYPTO_DATA); *sched = NULL; } @@ -265,7 +265,7 @@ blf_decrypt(caddr_t key, u_int8_t *blk) void blf_setkey(u_int8_t **sched, u_int8_t *key, int len) { - MALLOC(*sched, u_int8_t *, sizeof(blf_ctx), M_XDATA, M_WAITOK); + MALLOC(*sched, u_int8_t *, sizeof(blf_ctx), M_CRYPTO_DATA, M_WAITOK); bzero(*sched, sizeof(blf_ctx)); blf_key((blf_ctx *)*sched, key, len); } @@ -274,7 +274,7 @@ void blf_zerokey(u_int8_t **sched) { bzero(*sched, sizeof(blf_ctx)); - FREE(*sched, M_XDATA); + FREE(*sched, M_CRYPTO_DATA); *sched = NULL; } @@ -293,7 +293,7 @@ cast5_decrypt(caddr_t key, u_int8_t *blk) void cast5_setkey(u_int8_t **sched, u_int8_t *key, int len) { - MALLOC(*sched, u_int8_t *, sizeof(blf_ctx), M_XDATA, M_WAITOK); + MALLOC(*sched, u_int8_t *, sizeof(blf_ctx), M_CRYPTO_DATA, M_WAITOK); bzero(*sched, sizeof(blf_ctx)); cast_setkey((cast_key *)*sched, key, len); } @@ -302,7 +302,7 @@ void cast5_zerokey(u_int8_t **sched) { bzero(*sched, sizeof(cast_key)); - FREE(*sched, M_XDATA); + FREE(*sched, M_CRYPTO_DATA); *sched = NULL; } @@ -321,7 +321,8 @@ skipjack_decrypt(caddr_t key, u_int8_t *blk) void skipjack_setkey(u_int8_t **sched, u_int8_t *key, int len) { - MALLOC(*sched, u_int8_t *, 10 * sizeof(u_int8_t *), M_XDATA, M_WAITOK); + MALLOC(*sched, u_int8_t *, 10 * sizeof(u_int8_t *), M_CRYPTO_DATA, + M_WAITOK); bzero(*sched, 10 * sizeof(u_int8_t *)); subkey_table_gen(key, (u_int8_t **) *sched); } @@ -335,10 +336,10 @@ skipjack_zerokey(u_int8_t **sched) if (((u_int8_t **)(*sched))[k]) { bzero(((u_int8_t **)(*sched))[k], 0x100); - FREE(((u_int8_t **)(*sched))[k], M_XDATA); + FREE(((u_int8_t **)(*sched))[k], M_CRYPTO_DATA); } bzero(*sched, 10 * sizeof(u_int8_t *)); - FREE(*sched, M_XDATA); + FREE(*sched, M_CRYPTO_DATA); *sched = NULL; } @@ -358,7 +359,8 @@ rijndael128_decrypt(caddr_t key, u_int8_t *blk) void rijndael128_setkey(u_int8_t **sched, u_int8_t *key, int len) { - MALLOC(*sched, u_int8_t *, 2 * sizeof(rijndael_ctx), M_XDATA, M_WAITOK); + MALLOC(*sched, u_int8_t *, 2 * sizeof(rijndael_ctx), M_CRYPTO_DATA, + M_WAITOK); bzero(*sched, 2 * sizeof(rijndael_ctx)); rijndael_set_key((rijndael_ctx *) *sched, (u4byte *) key, len * 8, 1); rijndael_set_key(((rijndael_ctx *) *sched) + 1, (u4byte *) key, len * 8, 0); @@ -368,7 +370,7 @@ void rijndael128_zerokey(u_int8_t **sched) { bzero(*sched, 2 * sizeof(rijndael_ctx)); - FREE(*sched, M_XDATA); + FREE(*sched, M_CRYPTO_DATA); *sched = NULL; } -- cgit v1.2.3