diff options
author | Hans-Joerg Hoexer <hshoexer@cvs.openbsd.org> | 2007-09-13 21:26:42 +0000 |
---|---|---|
committer | Hans-Joerg Hoexer <hshoexer@cvs.openbsd.org> | 2007-09-13 21:26:42 +0000 |
commit | 3454a69c9970cde59eaff98270a9b20a0a0fe163 (patch) | |
tree | 33364f0cf53e08323db1a1ee8a7816306d1001fd | |
parent | 183780867808cc69f00f0dabcd596ef8905aa53b (diff) |
Here too: Convert MALLOC/FREE to malloc/free and use M_ZERO where applicable.
error spotting and ok krw@
-rw-r--r-- | sys/crypto/cryptodev.c | 33 | ||||
-rw-r--r-- | sys/crypto/cryptosoft.c | 21 | ||||
-rw-r--r-- | sys/crypto/deflate.c | 21 | ||||
-rw-r--r-- | sys/crypto/xform.c | 44 |
4 files changed, 51 insertions, 68 deletions
diff --git a/sys/crypto/cryptodev.c b/sys/crypto/cryptodev.c index 5d7b1bfdb15..e35ab4a2bd6 100644 --- a/sys/crypto/cryptodev.c +++ b/sys/crypto/cryptodev.c @@ -1,4 +1,4 @@ -/* $OpenBSD: cryptodev.c,v 1.66 2006/10/25 15:10:25 tedu Exp $ */ +/* $OpenBSD: cryptodev.c,v 1.67 2007/09/13 21:26:41 hshoexer Exp $ */ /* * Copyright (c) 2001 Theo de Raadt @@ -222,8 +222,8 @@ cryptof_ioctl(struct file *fp, u_long cmd, caddr_t data, struct proc *p) goto bail; } - MALLOC(crie.cri_key, u_int8_t *, - crie.cri_klen / 8, M_XDATA, M_WAITOK); + crie.cri_key = malloc(crie.cri_klen / 8, M_XDATA, + M_WAITOK); if ((error = copyin(sop->key, crie.cri_key, crie.cri_klen / 8))) goto bail; @@ -240,8 +240,8 @@ cryptof_ioctl(struct file *fp, u_long cmd, caddr_t data, struct proc *p) } if (cria.cri_klen) { - MALLOC(cria.cri_key, u_int8_t *, - cria.cri_klen / 8, M_XDATA, M_WAITOK); + cria.cri_key = malloc(cria.cri_klen / 8, + M_XDATA, M_WAITOK); if ((error = copyin(sop->mackey, cria.cri_key, cria.cri_klen / 8))) goto bail; @@ -268,9 +268,9 @@ cryptof_ioctl(struct file *fp, u_long cmd, caddr_t data, struct proc *p) bail: if (error) { if (crie.cri_key) - FREE(crie.cri_key, M_XDATA); + free(crie.cri_key, M_XDATA); if (cria.cri_key) - FREE(cria.cri_key, M_XDATA); + free(cria.cri_key, M_XDATA); } break; case CIOCFSESSION: @@ -528,8 +528,7 @@ cryptodev_key(struct crypt_kop *kop) return (EINVAL); } - krp = malloc(sizeof *krp, M_XDATA, M_WAITOK); - bzero(krp, sizeof *krp); + krp = malloc(sizeof *krp, M_XDATA, M_WAITOK | M_ZERO); krp->krp_op = kop->crk_op; krp->krp_status = kop->crk_status; krp->krp_iparams = kop->crk_iparams; @@ -623,7 +622,7 @@ cryptof_close(struct file *fp, struct proc *p) TAILQ_REMOVE(&fcr->csessions, cse, next); (void)csefree(cse); } - FREE(fcr, M_XDATA); + free(fcr, M_XDATA); fp->f_data = NULL; return 0; } @@ -672,14 +671,13 @@ cryptoioctl(dev_t dev, u_long cmd, caddr_t data, int flag, struct proc *p) switch (cmd) { case CRIOGET: - MALLOC(fcr, struct fcrypt *, - sizeof(struct fcrypt), M_XDATA, M_WAITOK); + fcr = malloc(sizeof(struct fcrypt), M_XDATA, M_WAITOK); TAILQ_INIT(&fcr->csessions); fcr->sesn = 0; error = falloc(p, &f, &fd); if (error) { - FREE(fcr, M_XDATA); + free(fcr, M_XDATA); return (error); } f->f_flag = FREAD | FWRITE; @@ -742,8 +740,7 @@ csecreate(struct fcrypt *fcr, u_int64_t sid, caddr_t key, u_int64_t keylen, { struct csession *cse; - MALLOC(cse, struct csession *, sizeof(struct csession), - M_XDATA, M_NOWAIT); + cse = malloc(sizeof(struct csession), M_XDATA, M_NOWAIT); if (cse == NULL) return NULL; cse->key = key; @@ -766,9 +763,9 @@ csefree(struct csession *cse) error = crypto_freesession(cse->sid); if (cse->key) - FREE(cse->key, M_XDATA); + free(cse->key, M_XDATA); if (cse->mackey) - FREE(cse->mackey, M_XDATA); - FREE(cse, M_XDATA); + free(cse->mackey, M_XDATA); + free(cse, M_XDATA); return (error); } diff --git a/sys/crypto/cryptosoft.c b/sys/crypto/cryptosoft.c index 0a42e570d6c..bf7313d792a 100644 --- a/sys/crypto/cryptosoft.c +++ b/sys/crypto/cryptosoft.c @@ -1,4 +1,4 @@ -/* $OpenBSD: cryptosoft.c,v 1.47 2007/09/10 22:19:42 henric Exp $ */ +/* $OpenBSD: cryptosoft.c,v 1.48 2007/09/13 21:26:41 hshoexer Exp $ */ /* * The author of this code is Angelos D. Keromytis (angelos@cis.upenn.edu) @@ -467,7 +467,7 @@ swcr_compdec(struct cryptodesc *crd, struct swcr_data *sw, * copy in a buffer. */ - MALLOC(data, u_int8_t *, crd->crd_len, M_CRYPTO_DATA, M_NOWAIT); + data = malloc(crd->crd_len, M_CRYPTO_DATA, M_NOWAIT); if (data == NULL) return (EINVAL); COPYDATA(outtype, buf, crd->crd_skip, crd->crd_len, data); @@ -477,7 +477,7 @@ swcr_compdec(struct cryptodesc *crd, struct swcr_data *sw, else result = cxf->decompress(data, crd->crd_len, &out); - FREE(data, M_CRYPTO_DATA); + free(data, M_CRYPTO_DATA); if (result == 0) return EINVAL; @@ -489,7 +489,7 @@ swcr_compdec(struct cryptodesc *crd, struct swcr_data *sw, if (crd->crd_flags & CRD_F_COMP) { if (result > crd->crd_len) { /* Compression was useless, we lost time */ - FREE(out, M_CRYPTO_DATA); + free(out, M_CRYPTO_DATA); return 0; } } @@ -520,7 +520,7 @@ swcr_compdec(struct cryptodesc *crd, struct swcr_data *sw, } } } - FREE(out, M_CRYPTO_DATA); + free(out, M_CRYPTO_DATA); return 0; } @@ -554,7 +554,7 @@ swcr_newsession(u_int32_t *sid, struct cryptoini *cri) swcr_sesnum *= 2; swd = malloc(swcr_sesnum * sizeof(struct swcr_data *), - M_CRYPTO_DATA, M_NOWAIT); + M_CRYPTO_DATA, M_NOWAIT | M_ZERO); if (swd == NULL) { /* Reset session number */ if (swcr_sesnum == CRYPTO_SW_SESSIONS) @@ -564,8 +564,6 @@ swcr_newsession(u_int32_t *sid, struct cryptoini *cri) return ENOBUFS; } - bzero(swd, swcr_sesnum * sizeof(struct swcr_data *)); - /* Copy existing sessions */ if (swcr_sessions) { bcopy(swcr_sessions, swd, @@ -580,13 +578,12 @@ swcr_newsession(u_int32_t *sid, struct cryptoini *cri) *sid = i; while (cri) { - MALLOC(*swd, struct swcr_data *, sizeof(struct swcr_data), - M_CRYPTO_DATA, M_NOWAIT); + swd = malloc(sizeof(struct swcr_data), M_CRYPTO_DATA, + M_NOWAIT | M_ZERO); if (*swd == NULL) { swcr_freesession(i); return ENOBUFS; } - bzero(*swd, sizeof(struct swcr_data)); switch (cri->cri_alg) { case CRYPTO_DES_CBC: @@ -820,7 +817,7 @@ swcr_freesession(u_int64_t tid) break; } - FREE(swd, M_CRYPTO_DATA); + free(swd, M_CRYPTO_DATA); } return 0; } diff --git a/sys/crypto/deflate.c b/sys/crypto/deflate.c index 7592ef28dbc..06fd01ffc28 100644 --- a/sys/crypto/deflate.c +++ b/sys/crypto/deflate.c @@ -1,4 +1,4 @@ -/* $OpenBSD: deflate.c,v 1.4 2005/03/24 11:43:40 hshoexer Exp $ */ +/* $OpenBSD: deflate.c,v 1.5 2007/09/13 21:26:41 hshoexer Exp $ */ /* * Copyright (c) 2001 Jean-Jacques Bernard-Gundol (jj@wabbitt.org) @@ -69,8 +69,7 @@ deflate_global(u_int8_t *data, u_int32_t size, int comp, u_int8_t **out) zbuf.avail_in = size; /* Total length of data to be processed */ if (comp == 0) { - MALLOC(buf[i].out, u_int8_t *, (u_long) size, M_CRYPTO_DATA, - M_NOWAIT); + buf[i].out = malloc((u_long)size, M_CRYPTO_DATA, M_NOWAIT); if (buf[i].out == NULL) goto bad; buf[i].size = size; @@ -83,9 +82,7 @@ deflate_global(u_int8_t *data, u_int32_t size, int comp, u_int8_t **out) * decompression. If it's not sufficient, it will need to be * updated while the decompression is going on */ - - MALLOC(buf[i].out, u_int8_t *, (u_long) (size * 4), - M_CRYPTO_DATA, M_NOWAIT); + buf[i].out = malloc((u_long)(size * 4), M_CRYPTO_DATA, M_NOWAIT); if (buf[i].out == NULL) goto bad; buf[i].size = size * 4; @@ -111,8 +108,8 @@ deflate_global(u_int8_t *data, u_int32_t size, int comp, u_int8_t **out) goto end; else if (zbuf.avail_out == 0 && i < (ZBUF - 1)) { /* we need more output space, allocate size */ - MALLOC(buf[i].out, u_int8_t *, (u_long) size, - M_CRYPTO_DATA, M_NOWAIT); + buf[i].out = malloc((u_long)size, M_CRYPTO_DATA, + M_NOWAIT); if (buf[i].out == NULL) goto bad; zbuf.next_out = buf[i].out; @@ -127,7 +124,7 @@ deflate_global(u_int8_t *data, u_int32_t size, int comp, u_int8_t **out) end: result = count = zbuf.total_out; - MALLOC(*out, u_int8_t *, (u_long) result, M_CRYPTO_DATA, M_NOWAIT); + *out = malloc((u_long)result, M_CRYPTO_DATA, M_NOWAIT); if (*out == NULL) goto bad; if (comp) @@ -139,13 +136,13 @@ end: if (count > buf[j].size) { bcopy(buf[j].out, *out, buf[j].size); *out += buf[j].size; - FREE(buf[j].out, M_CRYPTO_DATA); + free(buf[j].out, M_CRYPTO_DATA); count -= buf[j].size; } else { /* it should be the last buffer */ bcopy(buf[j].out, *out, count); *out += count; - FREE(buf[j].out, M_CRYPTO_DATA); + free(buf[j].out, M_CRYPTO_DATA); count = 0; } } @@ -155,7 +152,7 @@ end: bad: *out = NULL; for (j = 0; buf[j].flag != 0; j++) - FREE(buf[j].out, M_CRYPTO_DATA); + free(buf[j].out, M_CRYPTO_DATA); if (comp) inflateEnd(&zbuf); else diff --git a/sys/crypto/xform.c b/sys/crypto/xform.c index 6970fb030c2..17ce706202c 100644 --- a/sys/crypto/xform.c +++ b/sys/crypto/xform.c @@ -1,4 +1,4 @@ -/* $OpenBSD: xform.c,v 1.32 2007/09/10 22:19:42 henric Exp $ */ +/* $OpenBSD: xform.c,v 1.33 2007/09/13 21:26:41 hshoexer Exp $ */ /* * The authors of this code are John Ioannidis (ji@tla.org), * Angelos D. Keromytis (kermit@csd.uch.gr) and @@ -299,8 +299,7 @@ des1_decrypt(caddr_t key, u_int8_t *blk) int des1_setkey(u_int8_t **sched, u_int8_t *key, int len) { - MALLOC(*sched, u_int8_t *, 128, M_CRYPTO_DATA, M_WAITOK); - bzero(*sched, 128); + *sched = malloc(128, M_CRYPTO_DATA, M_WAITOK | M_ZERO); if (des_set_key(key, *sched) < 0) { des1_zerokey(sched); @@ -314,7 +313,7 @@ void des1_zerokey(u_int8_t **sched) { bzero(*sched, 128); - FREE(*sched, M_CRYPTO_DATA); + free(*sched, M_CRYPTO_DATA); *sched = NULL; } @@ -333,8 +332,7 @@ des3_decrypt(caddr_t key, u_int8_t *blk) int des3_setkey(u_int8_t **sched, u_int8_t *key, int len) { - MALLOC(*sched, u_int8_t *, 384, M_CRYPTO_DATA, M_WAITOK); - bzero(*sched, 384); + *sched = malloc(384, M_CRYPTO_DATA, M_WAITOK | M_ZERO); if (des_set_key(key, *sched) < 0 || des_set_key(key + 8, *sched + 128) < 0 || des_set_key(key + 16, *sched + 256) < 0) { @@ -349,7 +347,7 @@ void des3_zerokey(u_int8_t **sched) { bzero(*sched, 384); - FREE(*sched, M_CRYPTO_DATA); + free(*sched, M_CRYPTO_DATA); *sched = NULL; } @@ -368,8 +366,7 @@ blf_decrypt(caddr_t key, u_int8_t *blk) int blf_setkey(u_int8_t **sched, u_int8_t *key, int len) { - MALLOC(*sched, u_int8_t *, sizeof(blf_ctx), M_CRYPTO_DATA, M_WAITOK); - bzero(*sched, sizeof(blf_ctx)); + *sched = malloc(sizeof(blf_ctx), M_CRYPTO_DATA, M_WAITOK | M_ZERO); blf_key((blf_ctx *)*sched, key, len); return 0; @@ -379,7 +376,7 @@ void blf_zerokey(u_int8_t **sched) { bzero(*sched, sizeof(blf_ctx)); - FREE(*sched, M_CRYPTO_DATA); + free(*sched, M_CRYPTO_DATA); *sched = NULL; } @@ -419,8 +416,7 @@ cast5_decrypt(caddr_t key, u_int8_t *blk) int cast5_setkey(u_int8_t **sched, u_int8_t *key, int len) { - MALLOC(*sched, u_int8_t *, sizeof(cast_key), M_CRYPTO_DATA, M_WAITOK); - bzero(*sched, sizeof(cast_key)); + *sched = malloc(sizeof(cast_key), M_CRYPTO_DATA, M_WAITOK | M_ZERO); cast_setkey((cast_key *)*sched, key, len); return 0; @@ -430,7 +426,7 @@ void cast5_zerokey(u_int8_t **sched) { bzero(*sched, sizeof(cast_key)); - FREE(*sched, M_CRYPTO_DATA); + free(*sched, M_CRYPTO_DATA); *sched = NULL; } @@ -449,9 +445,8 @@ skipjack_decrypt(caddr_t key, u_int8_t *blk) int skipjack_setkey(u_int8_t **sched, u_int8_t *key, int len) { - MALLOC(*sched, u_int8_t *, 10 * sizeof(u_int8_t *), M_CRYPTO_DATA, - M_WAITOK); - bzero(*sched, 10 * sizeof(u_int8_t *)); + *sched = malloc(10 * sizeof(u_int8_t *), M_CRYPTO_DATA, M_WAITOK | + M_ZERO); subkey_table_gen(key, (u_int8_t **) *sched); return 0; @@ -465,11 +460,11 @@ skipjack_zerokey(u_int8_t **sched) for (k = 0; k < 10; k++) { if (((u_int8_t **)(*sched))[k]) { bzero(((u_int8_t **)(*sched))[k], 0x100); - FREE(((u_int8_t **)(*sched))[k], M_CRYPTO_DATA); + free(((u_int8_t **)(*sched))[k], M_CRYPTO_DATA); } } bzero(*sched, 10 * sizeof(u_int8_t *)); - FREE(*sched, M_CRYPTO_DATA); + free(*sched, M_CRYPTO_DATA); *sched = NULL; } @@ -488,9 +483,7 @@ rijndael128_decrypt(caddr_t key, u_int8_t *blk) int rijndael128_setkey(u_int8_t **sched, u_int8_t *key, int len) { - MALLOC(*sched, u_int8_t *, sizeof(rijndael_ctx), M_CRYPTO_DATA, - M_WAITOK); - bzero(*sched, sizeof(rijndael_ctx)); + *sched = malloc(sizeof(rijndael_ctx), M_CRYPTO_DATA, M_WAITOK | M_ZERO); if (rijndael_set_key((rijndael_ctx *)*sched, (u_char *)key, len * 8) < 0) { @@ -505,7 +498,7 @@ void rijndael128_zerokey(u_int8_t **sched) { bzero(*sched, sizeof(rijndael_ctx)); - FREE(*sched, M_CRYPTO_DATA); + free(*sched, M_CRYPTO_DATA); *sched = NULL; } @@ -557,9 +550,8 @@ aes_ctr_setkey(u_int8_t **sched, u_int8_t *key, int len) if (len < AESCTR_NONCESIZE) return -1; - MALLOC(*sched, u_int8_t *, sizeof(struct aes_ctr_ctx), M_CRYPTO_DATA, - M_WAITOK); - bzero(*sched, sizeof(struct aes_ctr_ctx)); + *sched = malloc(sizeof(struct aes_ctr_ctx), M_CRYPTO_DATA, M_WAITOK | + M_ZERO); ctx = (struct aes_ctr_ctx *)*sched; ctx->ac_nr = rijndaelKeySetupEnc(ctx->ac_ek, (u_char *)key, (len - AESCTR_NONCESIZE) * 8); @@ -575,7 +567,7 @@ void aes_ctr_zerokey(u_int8_t **sched) { bzero(*sched, sizeof(struct aes_ctr_ctx)); - FREE(*sched, M_CRYPTO_DATA); + free(*sched, M_CRYPTO_DATA); *sched = NULL; } |