Prepare the project for javadocs

This commit is contained in:
Gabriele C
2015-11-21 01:27:06 +01:00
parent adcd70b91d
commit 118c79401a
168 changed files with 4375 additions and 422 deletions
@@ -39,9 +39,9 @@ public class BinTools {
*
* @param b
* Input bytes. May be <code>null</code>.
* @return Hexadecimal representation of b. Uppercase A-F, two characters
* per byte. Empty string on <code>null</code> input.
*/
* per byte. Empty string on <code>null</code> input. */
public static String bin2hex(final byte[] b) {
if (b == null) {
return "";
@@ -61,10 +61,10 @@ public class BinTools {
* @param s
* String containing hexadecimal digits. May be <code>null</code>
* . On odd length leading zero will be assumed.
* @return Array on bytes, non-<code>null</code>.
* @throws IllegalArgumentException
* when string contains non-hex character
*/
* @return Array on bytes, non-<code>null</code>. * @throws IllegalArgumentException
* when string contains non-hex character */
public static byte[] hex2bin(final String s) {
String m = s;
if (s == null) {
@@ -88,10 +88,10 @@ public class BinTools {
*
* @param c
* 0-9, a-f, A-F allowd.
* @return 0-15
* @throws IllegalArgumentException
* on non-hex character
*/
* @return 0-15 * @throws IllegalArgumentException
* on non-hex character */
public static int hex2bin(char c) {
if (c >= '0' && c <= '9') {
return (c - '0');
@@ -105,6 +105,10 @@ public class BinTools {
throw new IllegalArgumentException("Input string may only contain hex digits, but found '" + c + "'");
}
/**
* Method main.
* @param args String[]
*/
public static void main(String[] args) {
byte b[] = new byte[256];
byte bb = 0;
@@ -65,6 +65,11 @@ public class MacBasedPRF implements PRF {
}
}
/**
* Constructor for MacBasedPRF.
* @param macAlgorithm String
* @param provider String
*/
public MacBasedPRF(String macAlgorithm, String provider) {
this.macAlgorithm = macAlgorithm;
try {
@@ -75,15 +80,31 @@ public class MacBasedPRF implements PRF {
}
}
/**
* Method doFinal.
* @param M byte[]
* @return byte[]
* @see fr.xephi.authme.security.pbkdf2.PRF#doFinal(byte[])
*/
public byte[] doFinal(byte[] M) {
byte[] r = mac.doFinal(M);
return r;
}
/**
* Method getHLen.
* @return int
* @see fr.xephi.authme.security.pbkdf2.PRF#getHLen()
*/
public int getHLen() {
return hLen;
}
/**
* Method init.
* @param P byte[]
* @see fr.xephi.authme.security.pbkdf2.PRF#init(byte[])
*/
public void init(byte[] P) {
try {
mac.init(new SecretKeySpec(P, macAlgorithm));
@@ -39,8 +39,8 @@ public interface PBKDF2 {
*
* @param inputPassword
* Candidate password to compute the derived key for.
* @return internal byte array
*/
* @return internal byte array */
public abstract byte[] deriveKey(String inputPassword);
/**
@@ -50,8 +50,8 @@ public interface PBKDF2 {
* Candidate password to compute the derived key for.
* @param dkLen
* Specify desired key length
* @return internal byte array
*/
* @return internal byte array */
public abstract byte[] deriveKey(String inputPassword, int dkLen);
/**
@@ -61,16 +61,16 @@ public interface PBKDF2 {
*
* @param inputPassword
* Candidate password to compute the derived key for.
* @return <code>true</code> password match; <code>false</code> incorrect
* password
*/
* password */
public abstract boolean verifyKey(String inputPassword);
/**
* Allow reading of configured parameters.
*
* @return Currently set parameters.
*/
* @return Currently set parameters. */
public abstract PBKDF2Parameters getParameters();
/**
@@ -83,8 +83,8 @@ public interface PBKDF2 {
/**
* Get currently set Pseudo Random Function.
*
* @return Currently set Pseudo Random Function
*/
* @return Currently set Pseudo Random Function */
public abstract PRF getPseudoRandomFunction();
/**
@@ -112,10 +112,23 @@ public class PBKDF2Engine implements PBKDF2 {
this.prf = prf;
}
/**
* Method deriveKey.
* @param inputPassword String
* @return byte[]
* @see fr.xephi.authme.security.pbkdf2.PBKDF2#deriveKey(String)
*/
public byte[] deriveKey(String inputPassword) {
return deriveKey(inputPassword, 0);
}
/**
* Method deriveKey.
* @param inputPassword String
* @param dkLen int
* @return byte[]
* @see fr.xephi.authme.security.pbkdf2.PBKDF2#deriveKey(String, int)
*/
public byte[] deriveKey(String inputPassword, int dkLen) {
byte[] r = null;
byte P[] = null;
@@ -140,6 +153,12 @@ public class PBKDF2Engine implements PBKDF2 {
return r;
}
/**
* Method verifyKey.
* @param inputPassword String
* @return boolean
* @see fr.xephi.authme.security.pbkdf2.PBKDF2#verifyKey(String)
*/
public boolean verifyKey(String inputPassword) {
byte[] referenceKey = getParameters().getDerivedKey();
if (referenceKey == null || referenceKey.length == 0) {
@@ -172,6 +191,11 @@ public class PBKDF2Engine implements PBKDF2 {
prf.init(P);
}
/**
* Method getPseudoRandomFunction.
* @return PRF
* @see fr.xephi.authme.security.pbkdf2.PBKDF2#getPseudoRandomFunction()
*/
public PRF getPseudoRandomFunction() {
return prf;
}
@@ -179,7 +203,7 @@ public class PBKDF2Engine implements PBKDF2 {
/**
* Core Password Based Key Derivation Function 2.
*
* @see <a href="http://tools.ietf.org/html/rfc2898">RFC 2898 5.2</a>
* @param prf
* Pseudo Random Function (i.e. HmacSHA1)
* @param S
@@ -188,8 +212,8 @@ public class PBKDF2Engine implements PBKDF2 {
* Iteration count (see RFC 2898 4.2)
* @param dkLen
* desired length of derived key.
* @return internal byte array
*/
* @return internal byte array * @see <a href="http://tools.ietf.org/html/rfc2898">RFC 2898 5.2</a> */
protected byte[] PBKDF2(PRF prf, byte[] S, int c, int dkLen) {
if (S == null) {
S = new byte[0];
@@ -215,12 +239,12 @@ public class PBKDF2Engine implements PBKDF2 {
/**
* Integer division with ceiling function.
*
* @see <a href="http://tools.ietf.org/html/rfc2898">RFC 2898 5.2 Step
* 2.</a>
* @param a
* @param b
* @return ceil(a/b)
*/
* @return ceil(a/b) * @see <a href="http://tools.ietf.org/html/rfc2898">RFC 2898 5.2 Step
* 2.</a> */
protected int ceil(int a, int b) {
int m = 0;
if (a % b > 0) {
@@ -232,8 +256,7 @@ public class PBKDF2Engine implements PBKDF2 {
/**
* Function F.
*
* @see <a href="http://tools.ietf.org/html/rfc2898">RFC 2898 5.2 Step
* 3.</a>
* @param dest
* Destination byte buffer
* @param offset
@@ -245,7 +268,8 @@ public class PBKDF2Engine implements PBKDF2 {
* @param c
* Iteration count
* @param blockIndex
*/
* @see <a href="http://tools.ietf.org/html/rfc2898">RFC 2898 5.2 Step
* 3.</a> */
protected void _F(byte[] dest, int offset, PRF prf, byte[] S, int c,
int blockIndex) {
int hLen = prf.getHLen();
@@ -279,12 +303,12 @@ public class PBKDF2Engine implements PBKDF2 {
/**
* Four-octet encoding of the integer i, most significant octet first.
*
* @see <a href="http://tools.ietf.org/html/rfc2898">RFC 2898 5.2 Step
* 3.</a>
* @param dest
* @param offset
* @param i
*/
* @see <a href="http://tools.ietf.org/html/rfc2898">RFC 2898 5.2 Step
* 3.</a> */
protected void INT(byte[] dest, int offset, int i) {
dest[offset + 0] = (byte) (i / (256 * 256 * 256));
dest[offset + 1] = (byte) (i / (256 * 256));
@@ -292,14 +316,29 @@ public class PBKDF2Engine implements PBKDF2 {
dest[offset + 3] = (byte) (i);
}
/**
* Method getParameters.
* @return PBKDF2Parameters
* @see fr.xephi.authme.security.pbkdf2.PBKDF2#getParameters()
*/
public PBKDF2Parameters getParameters() {
return parameters;
}
/**
* Method setParameters.
* @param parameters PBKDF2Parameters
* @see fr.xephi.authme.security.pbkdf2.PBKDF2#setParameters(PBKDF2Parameters)
*/
public void setParameters(PBKDF2Parameters parameters) {
this.parameters = parameters;
}
/**
* Method setPseudoRandomFunction.
* @param prf PRF
* @see fr.xephi.authme.security.pbkdf2.PBKDF2#setPseudoRandomFunction(PRF)
*/
public void setPseudoRandomFunction(PRF prf) {
this.prf = prf;
}
@@ -316,9 +355,9 @@ public class PBKDF2Engine implements PBKDF2 {
*
* @param args
* Supply the password as argument.
* @throws IOException
* @throws NoSuchAlgorithmException
*/
* @throws IOException * @throws NoSuchAlgorithmException */
public static void main(String[] args)
throws IOException, NoSuchAlgorithmException {
String password = "password";
@@ -38,8 +38,8 @@ public interface PBKDF2Formatter {
*
* @param p
* Parameters object to output.
* @return String representation
*/
* @return String representation */
public abstract String toString(PBKDF2Parameters p);
/**
@@ -48,8 +48,9 @@ public interface PBKDF2Formatter {
*
* @param s
* String representation of parameters to decode.
* @param p PBKDF2Parameters
* @return <code>false</code> syntax OK, <code>true</code> some syntax
* issue.
*/
* issue. */
public abstract boolean fromString(PBKDF2Parameters p, String s);
}
@@ -33,6 +33,13 @@ package fr.xephi.authme.security.pbkdf2;
*/
public class PBKDF2HexFormatter implements PBKDF2Formatter {
/**
* Method fromString.
* @param p PBKDF2Parameters
* @param s String
* @return boolean
* @see fr.xephi.authme.security.pbkdf2.PBKDF2Formatter#fromString(PBKDF2Parameters, String)
*/
public boolean fromString(PBKDF2Parameters p, String s) {
if (p == null || s == null) {
return true;
@@ -53,6 +60,12 @@ public class PBKDF2HexFormatter implements PBKDF2Formatter {
return false;
}
/**
* Method toString.
* @param p PBKDF2Parameters
* @return String
* @see fr.xephi.authme.security.pbkdf2.PBKDF2Formatter#toString(PBKDF2Parameters)
*/
public String toString(PBKDF2Parameters p) {
String s = BinTools.bin2hex(p.getSalt()) + ":" + String.valueOf(p.getIterationCount()) + ":" + BinTools.bin2hex(p.getDerivedKey());
return s;
@@ -109,42 +109,82 @@ public class PBKDF2Parameters {
this.derivedKey = derivedKey;
}
/**
* Method getIterationCount.
* @return int
*/
public int getIterationCount() {
return iterationCount;
}
/**
* Method setIterationCount.
* @param iterationCount int
*/
public void setIterationCount(int iterationCount) {
this.iterationCount = iterationCount;
}
/**
* Method getSalt.
* @return byte[]
*/
public byte[] getSalt() {
return salt;
}
/**
* Method setSalt.
* @param salt byte[]
*/
public void setSalt(byte[] salt) {
this.salt = salt;
}
/**
* Method getDerivedKey.
* @return byte[]
*/
public byte[] getDerivedKey() {
return derivedKey;
}
/**
* Method setDerivedKey.
* @param derivedKey byte[]
*/
public void setDerivedKey(byte[] derivedKey) {
this.derivedKey = derivedKey;
}
/**
* Method getHashAlgorithm.
* @return String
*/
public String getHashAlgorithm() {
return hashAlgorithm;
}
/**
* Method setHashAlgorithm.
* @param hashAlgorithm String
*/
public void setHashAlgorithm(String hashAlgorithm) {
this.hashAlgorithm = hashAlgorithm;
}
/**
* Method getHashCharset.
* @return String
*/
public String getHashCharset() {
return hashCharset;
}
/**
* Method setHashCharset.
* @param hashCharset String
*/
public void setHashCharset(String hashCharset) {
this.hashCharset = hashCharset;
}
@@ -48,14 +48,14 @@ public interface PRF {
* @param M
* Input data/message etc. Together with any data supplied during
* initilization.
* @return Random bytes of hLen length.
*/
* @return Random bytes of hLen length. */
public byte[] doFinal(byte[] M);
/**
* Query block size of underlying algorithm/mechanism.
*
* @return block size
*/
* @return block size */
public int getHLen();
}