Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/sys/opencrypto From Alexander Nasonov:



details:   https://anonhg.NetBSD.org/src/rev/b3b8e7d98f69
branches:  trunk
changeset: 347959:b3b8e7d98f69
user:      christos <christos%NetBSD.org@localhost>
date:      Mon Sep 26 14:50:54 2016 +0000

description:
>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

diffstat:

 sys/opencrypto/aesxcbcmac.c |  37 ++++++++++++++++++++-----------------
 1 files changed, 20 insertions(+), 17 deletions(-)

diffs (91 lines):

diff -r c182aa5442ea -r b3b8e7d98f69 sys/opencrypto/aesxcbcmac.c
--- a/sys/opencrypto/aesxcbcmac.c       Mon Sep 26 00:21:22 2016 +0000
+++ b/sys/opencrypto/aesxcbcmac.c       Mon Sep 26 14:50:54 2016 +0000
@@ -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 @@
 #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 @@
 }
 
 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 @@
                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 @@
 }
 
 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++) {



Home | Main Index | Thread Index | Old Index