package net.java.otr4j.context.auth;

import java.math.BigInteger;
import java.security.InvalidAlgorithmParameterException;
import java.security.InvalidKeyException;
import java.security.KeyPair;
import java.security.NoSuchAlgorithmException;
import java.security.NoSuchProviderException;
import javax.crypto.BadPaddingException;
import javax.crypto.IllegalBlockSizeException;
import javax.crypto.NoSuchPaddingException;
import javax.crypto.interfaces.DHPublicKey;
import org.apache.log4j.Logger;

import net.java.otr4j.Utils;
import net.java.otr4j.crypto.CryptoConstants;
import net.java.otr4j.crypto.CryptoUtils;

public class AuthenticationInfo {

	private static Logger logger = Logger.getLogger(AuthenticationInfo.class);

	public AuthenticationState authenticationState;
	public byte[] r;

	public DHPublicKey theirDHPublicKey;
	public byte[] theirDHPublicKeyEncrypted;
	public byte[] theirDHPublicKeyHash;

	public KeyPair ourDHKeyPair;
	public int ourDHPrivateKeyID;
	public byte[] ourDHPublicKeyHash;
	public byte[] ourDHPublicKeyEncrypted;

	public BigInteger s;
	public byte[] c;
	public byte[] m1;
	public byte[] m2;
	public byte[] cp;
	public byte[] m1p;
	public byte[] m2p;

	public byte[] ourXEncrypted;
	public byte[] ourXEncryptedMac;

	public KeyPair ourLongTermKeyPair;

	public void initialize() throws NoSuchAlgorithmException,
			InvalidAlgorithmParameterException, NoSuchProviderException,
			InvalidKeyException, NoSuchPaddingException,
			IllegalBlockSizeException, BadPaddingException {
		this.authenticationState = AuthenticationState.NONE;
		
		logger.debug("Picking random key r.");
		this.r = Utils.getRandomBytes(CryptoConstants.AES_KEY_BYTE_LENGTH);

		logger.debug("Generating own D-H key pair.");
		this.ourDHKeyPair = CryptoUtils.generateDHKeyPair();
		this.ourDHPrivateKeyID = 1;

		byte[] gx = ((DHPublicKey) ourDHKeyPair.getPublic()).getY()
				.toByteArray();

		logger.debug("Hashing gx");
		this.ourDHPublicKeyHash = CryptoUtils.sha256Hash(gx);

		logger.debug("Encrypting gx");
		this.ourDHPublicKeyEncrypted = CryptoUtils.aesEncrypt(r, gx);
	}
}

@@ -739,24 +739,118 @@
 .class);%0D%0A%0D%0A
+%09public AuthenticationInfo() %7B%0D%0A%09%09this.authenticationState = AuthenticationState.NONE;%0D%0A%09%7D%0D%0A%0D%0A
 %09public Auth
@@ -1707,18 +1707,16 @@
 .NONE;%0D%0A
-%09%09
 %0D%0A%09%09logg

Set AuthenticationState on ctor to prevent null reference exceptions.