if(length < digestLength + ivLength + 5) {
if(logMINOR) Logger.minor(this, "Too short: "+length+" should be at least "+(digestLength + ivLength + 5));
return false;
}
// IV at the beginning
PCFBMode pcfb = PCFBMode.create(authKey, buf, offset);
// Then the hash, then the data
// => Data starts at ivLength + digestLength
// Decrypt the hash
byte[] hash = Arrays.copyOfRange(buf, offset+ivLength, offset+ivLength+digestLength);
pcfb.blockDecipher(hash, 0, hash.length);
int dataStart = ivLength + digestLength + offset+2;
int byte1 = ((pcfb.decipher(buf[dataStart-2])) & 0xff);
int byte2 = ((pcfb.decipher(buf[dataStart-1])) & 0xff);
int dataLength = (byte1 << 8) + byte2;
if(logMINOR) Logger.minor(this, "Data length: "+dataLength+" (1 = "+byte1+" 2 = "+byte2+ ')');
if(dataLength > length - (ivLength+hash.length+2)) {
if(logMINOR) Logger.minor(this, "Invalid data length "+dataLength+" ("+(length - (ivLength+hash.length+2))+") in tryProcessAuthAnon");
return false;
}
// Decrypt the data
byte[] payload = Arrays.copyOfRange(buf, dataStart, dataStart+dataLength);
pcfb.blockDecipher(payload, 0, payload.length);
byte[] realHash = SHA256.digest(payload);
if(MessageDigest.isEqual(realHash, hash)) {
// Got one