Module Name: src Committed By: christos Date: Mon Sep 26 14:50:54 UTC 2016
Modified Files: src/sys/opencrypto: aesxcbcmac.c Log Message: >From Alexander Nasonov: - Make constants static: Shrinks code and data size. - Avoid overflow in limit calculation. - Use uint8_t instead of u_char to match types While here: - Remove unnecessary casts - s/u_int8_t/uint8_t/g To generate a diff of this commit: cvs rdiff -u -r1.1 -r1.2 src/sys/opencrypto/aesxcbcmac.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files.
Modified files: Index: src/sys/opencrypto/aesxcbcmac.c diff -u src/sys/opencrypto/aesxcbcmac.c:1.1 src/sys/opencrypto/aesxcbcmac.c:1.2 --- src/sys/opencrypto/aesxcbcmac.c:1.1 Tue May 24 15:10:08 2011 +++ src/sys/opencrypto/aesxcbcmac.c Mon Sep 26 10:50:54 2016 @@ -1,4 +1,4 @@ -/* $NetBSD: aesxcbcmac.c,v 1.1 2011/05/24 19:10:08 drochner Exp $ */ +/* $NetBSD: aesxcbcmac.c,v 1.2 2016/09/26 14:50:54 christos Exp $ */ /* * Copyright (C) 1995, 1996, 1997, 1998 and 2003 WIDE Project. @@ -30,7 +30,7 @@ */ #include <sys/cdefs.h> -__KERNEL_RCSID(0, "$NetBSD: aesxcbcmac.c,v 1.1 2011/05/24 19:10:08 drochner Exp $"); +__KERNEL_RCSID(0, "$NetBSD: aesxcbcmac.c,v 1.2 2016/09/26 14:50:54 christos Exp $"); #include <sys/param.h> #include <sys/systm.h> @@ -39,17 +39,20 @@ __KERNEL_RCSID(0, "$NetBSD: aesxcbcmac.c #include <opencrypto/aesxcbcmac.h> int -aes_xcbc_mac_init(void *vctx, const u_int8_t *key, u_int16_t keylen) +aes_xcbc_mac_init(void *vctx, const uint8_t *key, u_int16_t keylen) { - u_int8_t k1seed[AES_BLOCKSIZE] = { 1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1 }; - u_int8_t k2seed[AES_BLOCKSIZE] = { 2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2 }; - u_int8_t k3seed[AES_BLOCKSIZE] = { 3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3 }; + static const uint8_t k1seed[AES_BLOCKSIZE] = + { 1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1 }; + static const uint8_t k2seed[AES_BLOCKSIZE] = + { 2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2 }; + static const uint8_t k3seed[AES_BLOCKSIZE] = + { 3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3 }; u_int32_t r_ks[(RIJNDAEL_MAXNR+1)*4]; aesxcbc_ctx *ctx; - u_int8_t k1[AES_BLOCKSIZE]; + uint8_t k1[AES_BLOCKSIZE]; - ctx = (aesxcbc_ctx *)vctx; - memset(ctx, 0, sizeof(aesxcbc_ctx)); + ctx = vctx; + memset(ctx, 0, sizeof(*ctx)); if ((ctx->r_nr = rijndaelKeySetupEnc(r_ks, key, keylen * 8)) == 0) return -1; @@ -67,14 +70,14 @@ aes_xcbc_mac_init(void *vctx, const u_in } int -aes_xcbc_mac_loop(void *vctx, const u_int8_t *addr, u_int16_t len) +aes_xcbc_mac_loop(void *vctx, const uint8_t *addr, u_int16_t len) { - u_int8_t buf[AES_BLOCKSIZE]; + uint8_t buf[AES_BLOCKSIZE]; aesxcbc_ctx *ctx; - const u_int8_t *ep; + const uint8_t *ep; int i; - ctx = (aesxcbc_ctx *)vctx; + ctx = vctx; ep = addr + len; if (ctx->buflen == sizeof(ctx->buf)) { @@ -98,7 +101,7 @@ aes_xcbc_mac_loop(void *vctx, const u_in ctx->buflen = 0; } /* due to the special processing for M[n], "=" case is not included */ - while (addr + AES_BLOCKSIZE < ep) { + while (ep - addr > AES_BLOCKSIZE) { memcpy(buf, addr, AES_BLOCKSIZE); for (i = 0; i < sizeof(buf); i++) buf[i] ^= ctx->e[i]; @@ -113,13 +116,13 @@ aes_xcbc_mac_loop(void *vctx, const u_in } void -aes_xcbc_mac_result(u_int8_t *addr, void *vctx) +aes_xcbc_mac_result(uint8_t *addr, void *vctx) { - u_char digest[AES_BLOCKSIZE]; + uint8_t digest[AES_BLOCKSIZE]; aesxcbc_ctx *ctx; int i; - ctx = (aesxcbc_ctx *)vctx; + ctx = vctx; if (ctx->buflen == sizeof(ctx->buf)) { for (i = 0; i < sizeof(ctx->buf); i++) {