[Tinyos-devel] Re: PATCH for TinySec
Irfan Acar
irfan.acar at komes.com.tr
Sat Jul 8 02:39:52 PDT 2006
> --- CBCMAC.nc 7 Oct 2003 21:46:22 -0000 1.2
> +++ CBCMAC.nc 7 Jul 2006 17:41:52 -0000
> @@ -155,7 +155,7 @@
> for (i = 0; i < msgLen; i++) {
> // unroll
> partial[pos++] ^= msg[i];
> - if (pos == 7) {
> + if (pos == 8) {
> if (!call BlockCipher.encrypt (&context->cc, partial, partial)) {
> return FAIL;
> }
>
The patch below fixes the bug mentioned and a couple other problems.
1) Hard-coded values are expressed in terms of CBCMAC_BLOCK_SIZE.
2) Incorrect uint8_t declarations replaced with uint16_t.
--- CBCMAC.nc
+++ CBCMAC.nc
@@ -114,11 +114,11 @@
// temp buffer to hold length buffer which we'll encrypt to the
// real "partial" stored in the context.
uint8_t partial[CBCMAC_BLOCK_SIZE];
- // length divided by 8 [ ie num blocks]
- uint8_t numBlocks = length >> 3;
- memset (partial, 0, 6);
- partial[6] = (numBlocks >> 8) & 0xff;
- partial[7] = (numBlocks & 0xff);
+ // length divided by CBCMAC_BLOCK_SIZE [ ie num blocks]
+ uint16_t numBlocks = length / CBCMAC_BLOCK_SIZE;
+ memset (partial, 0, CBCMAC_BLOCK_SIZE-2);
+ partial[CBCMAC_BLOCK_SIZE-2] = (numBlocks >> 8) & 0xff;
+ partial[CBCMAC_BLOCK_SIZE-1] = (numBlocks & 0xff);
((CBCMACContext*) context->context)->length = length;
((CBCMACContext*) context->context)->blockPos = 0;
@@ -143,7 +143,8 @@
async command result_t MAC.incrementalMAC (MACContext * context, uint8_t * msg,
uint16_t msgLen)
{
- uint8_t i, pos = ((CBCMACContext*) context->context)->blockPos;
+ uint16_t i;
+ uint8_t pos = ((CBCMACContext*) context->context)->blockPos;
uint8_t * partial = ((CBCMACContext*) context->context)->partial;
// only proceed if the we're expecting less than msgLen of data.
@@ -155,7 +156,7 @@
for (i = 0; i < msgLen; i++) {
// unroll
partial[pos++] ^= msg[i];
- if (pos == 7) {
+ if (pos == CBCMAC_BLOCK_SIZE) {
if (!call BlockCipher.encrypt (&context->cc, partial, partial)) {
return FAIL;
}
@@ -192,7 +193,7 @@
uint8_t * partial = ((CBCMACContext*) context->context)->partial;
// make sure they're asking for a valid mac size and that we've received
// all the data that we're expecting.
- if (! macSize || macSize > 8 ||
+ if (! macSize || macSize > CBCMAC_BLOCK_SIZE ||
((CBCMACContext*) context->context)->length) {
dbg(DBG_CRYPTO,"MAC getIncrementalMAC failure: length left %d.\n",
((CBCMACContext*) context->context)->length);
More information about the Tinyos-devel
mailing list