1443 if (logger.isLoggable(Level.FINEST)) {
1444 traceOutput(DP_CLASS_NAME, "unwrap",
1445 "DIGEST35:Unwrapped (w/padding): ", msgWithPadding);
1446 traceOutput(DP_CLASS_NAME, "unwrap", "DIGEST36:MAC: ", mac);
1447 traceOutput(DP_CLASS_NAME, "unwrap", "DIGEST37:messageType: ",
1448 msgType);
1449 traceOutput(DP_CLASS_NAME, "unwrap", "DIGEST38:sequenceNum: ",
1450 seqNum);
1451 }
1452
1453 int msgLength = msgWithPadding.length;
1454 int blockSize = decCipher.getBlockSize();
1455 if (blockSize > 1) {
1456 // get value of last octet of the byte array
1457 msgLength -= (int)msgWithPadding[msgWithPadding.length - 1];
1458 if (msgLength < 0) {
1459 // Discard message and do not increment sequence number
1460 if (logger.isLoggable(Level.INFO)) {
1461 logger.log(Level.INFO,
1462 "DIGEST39:Incorrect padding: {0}",
1463 new Byte(msgWithPadding[msgWithPadding.length - 1]));
1464 }
1465 return EMPTY_BYTE_ARRAY;
1466 }
1467 }
1468
1469 /* Re-calculate MAC to ensure integrity */
1470 byte[] expectedMac = getHMAC(peerKi, seqNum, msgWithPadding,
1471 0, msgLength);
1472
1473 if (logger.isLoggable(Level.FINEST)) {
1474 traceOutput(DP_CLASS_NAME, "unwrap", "DIGEST40:KisMAC: ",
1475 expectedMac);
1476 }
1477
1478 // First, compare MACs before updating state
1479 if (!Arrays.equals(mac, expectedMac)) {
1480 // Discard message and do not increment sequence number
1481 logger.log(Level.INFO, "DIGEST41:Unmatched MACs");
1482 return EMPTY_BYTE_ARRAY;
1483 }
|
1443 if (logger.isLoggable(Level.FINEST)) {
1444 traceOutput(DP_CLASS_NAME, "unwrap",
1445 "DIGEST35:Unwrapped (w/padding): ", msgWithPadding);
1446 traceOutput(DP_CLASS_NAME, "unwrap", "DIGEST36:MAC: ", mac);
1447 traceOutput(DP_CLASS_NAME, "unwrap", "DIGEST37:messageType: ",
1448 msgType);
1449 traceOutput(DP_CLASS_NAME, "unwrap", "DIGEST38:sequenceNum: ",
1450 seqNum);
1451 }
1452
1453 int msgLength = msgWithPadding.length;
1454 int blockSize = decCipher.getBlockSize();
1455 if (blockSize > 1) {
1456 // get value of last octet of the byte array
1457 msgLength -= (int)msgWithPadding[msgWithPadding.length - 1];
1458 if (msgLength < 0) {
1459 // Discard message and do not increment sequence number
1460 if (logger.isLoggable(Level.INFO)) {
1461 logger.log(Level.INFO,
1462 "DIGEST39:Incorrect padding: {0}",
1463 msgWithPadding[msgWithPadding.length - 1]);
1464 }
1465 return EMPTY_BYTE_ARRAY;
1466 }
1467 }
1468
1469 /* Re-calculate MAC to ensure integrity */
1470 byte[] expectedMac = getHMAC(peerKi, seqNum, msgWithPadding,
1471 0, msgLength);
1472
1473 if (logger.isLoggable(Level.FINEST)) {
1474 traceOutput(DP_CLASS_NAME, "unwrap", "DIGEST40:KisMAC: ",
1475 expectedMac);
1476 }
1477
1478 // First, compare MACs before updating state
1479 if (!Arrays.equals(mac, expectedMac)) {
1480 // Discard message and do not increment sequence number
1481 logger.log(Level.INFO, "DIGEST41:Unmatched MACs");
1482 return EMPTY_BYTE_ARRAY;
1483 }
|