Re: small changes in aesxcbcmac.c

2016-09-25 Thread Eric Haszlakiewicz
On September 25, 2016 5:01:16 PM EDT, Alexander Nasonov  wrote:
>The first change shrinks aes_xcbc_mac_init by 183 bytes on amd64
>(from 562 to 379 bytes).

Do you mean it shrinks its stack usage?  Or does that change to static const 
vars somehow shrink the function itself?

Eric




Re: small changes in aesxcbcmac.c

2016-09-25 Thread Rhialto
On Sun 25 Sep 2016 at 22:01:16 +0100, Alexander Nasonov wrote:
> - while (addr + AES_BLOCKSIZE < ep) {
> + while (ep - addr > AES_BLOCKSIZE) {

I think that if ep points beyond tbe buffer (apart from the
just-past-the-end location), the subtraction is just as undefined
behaviour as before...

-Olaf.
-- 
___ Olaf 'Rhialto' Seibert  -- Wayland: Those who don't understand X
\X/ rhialto/at/xs4all.nl-- are condemned to reinvent it. Poorly.


signature.asc
Description: PGP signature


small changes in aesxcbcmac.c

2016-09-25 Thread Alexander Nasonov
The first change shrinks aes_xcbc_mac_init by 183 bytes on amd64
(from 562 to 379 bytes).
The second change avoids a comparison with an address that may
point beyond the end of a buffer.
The third change is stylistic.
Alex
--- sys/opencrypto/aesxcbcmac.c.orig2016-09-25 21:44:25.344941650 +0100
+++ sys/opencrypto/aesxcbcmac.c 2016-09-25 13:21:43.364224984 +0100
@@ -41,9 +41,12 @@
 int
 aes_xcbc_mac_init(void *vctx, const u_int8_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 u_int8_t k1seed[AES_BLOCKSIZE] =
+   { 1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1 };
+   static const u_int8_t k2seed[AES_BLOCKSIZE] =
+   { 2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2 };
+   static const u_int8_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];
@@ -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];
@@ -115,7 +118,7 @@
 void
 aes_xcbc_mac_result(u_int8_t *addr, void *vctx)
 {
-   u_char digest[AES_BLOCKSIZE];
+   u_int8_t digest[AES_BLOCKSIZE];
aesxcbc_ctx *ctx;
int i;