Permalink
Browse files

padLen <= 0 is illegal, it seems

XXX CBC mode code in racoon is tweaked to do if (padLen == 16) padLen = 0;
is it right?  why it is not done for the kernel?
  • Loading branch information...
1 parent 4d78fec commit e70a9f6526774448112b6cb7b5156df7c6a27730 itojun committed Oct 18, 2002
@@ -1,4 +1,4 @@
-/* $KAME: rijndael-api-fst.c,v 1.5 2002/10/18 23:43:52 itojun Exp $ */
+/* $KAME: rijndael-api-fst.c,v 1.6 2002/10/18 23:50:12 itojun Exp $ */
/*
* rijndael-api-fst.c v2.3 April '2000
@@ -224,7 +224,7 @@ int rijndael_padEncrypt(cipherInstance *cipher, keyInstance *key,
outBuffer += 16;
}
padLen = 16 - (inputOctets - 16*numBlocks);
- if (padLen < 0 || padLen > 16)
+ if (padLen <= 0 || padLen > 16)
panic("rijndael_padEncrypt(ECB)");
bcopy(input, block, 16 - padLen);
for (cp = block + 16 - padLen; cp < block + 16; cp++)
@@ -248,11 +248,13 @@ int rijndael_padEncrypt(cipherInstance *cipher, keyInstance *key,
padLen = 16 - (inputOctets - 16*numBlocks);
#else
padLen = 16 - inputOctets % 16;
+#endif
+ if (padLen <= 0 || padLen > 16)
+ panic("rijndael_padEncrypt(CBC)");
+#if 1
if (padLen == 16)
padLen = 0;
#endif
- if (padLen < 0 || padLen > 16)
- panic("rijndael_padEncrypt(CBC)");
for (i = 0; i < 16 - padLen; i++) {
block[i] = input[i] ^ iv[i];
}
@@ -1,4 +1,4 @@
-/* $KAME: rijndael-api-fst.c,v 1.13 2002/10/18 23:43:52 itojun Exp $ */
+/* $KAME: rijndael-api-fst.c,v 1.14 2002/10/18 23:50:12 itojun Exp $ */
/*
* rijndael-api-fst.c v2.3 April '2000
@@ -219,7 +219,7 @@ int rijndael_padEncrypt(cipherInstance *cipher, keyInstance *key,
outBuffer += 16;
}
padLen = 16 - (inputOctets - 16*numBlocks);
- if (padLen < 0 || padLen > 16)
+ if (padLen <= 0 || padLen > 16)
panic("rijndael_padEncrypt(ECB)");
bcopy(input, block, 16 - padLen);
for (cp = block + 16 - padLen; cp < block + 16; cp++)
@@ -240,7 +240,7 @@ int rijndael_padEncrypt(cipherInstance *cipher, keyInstance *key,
outBuffer += 16;
}
padLen = 16 - (inputOctets - 16*numBlocks);
- if (padLen < 0 || padLen > 16)
+ if (padLen <= 0 || padLen > 16)
panic("rijndael_padEncrypt(CBC)");
for (i = 0; i < 16 - padLen; i++) {
block[i] = input[i] ^ iv[i];

0 comments on commit e70a9f6

Please sign in to comment.