GUACAMOLE-96: Include recommended key length for each TOTP mode.

This commit is contained in:
Michael Jumper
2017-11-20 10:37:23 -08:00
parent 78c398f45d
commit 4178a4b8b3

View File

@@ -124,19 +124,19 @@ public class TOTPGenerator {
* TOTP mode which generates hashes using SHA1. TOTP in SHA1 mode * TOTP mode which generates hashes using SHA1. TOTP in SHA1 mode
* requires 160-bit keys. * requires 160-bit keys.
*/ */
SHA1("HmacSHA1"), SHA1("HmacSHA1", 20),
/** /**
* TOTP mode which generates hashes using SHA256. TOTP in SHA256 mode * TOTP mode which generates hashes using SHA256. TOTP in SHA256 mode
* requires 256-bit keys. * requires 256-bit keys.
*/ */
SHA256("HmacSHA256"), SHA256("HmacSHA256", 32),
/** /**
* TOTP mode which generates hashes using SHA512. TOTP in SHA512 mode * TOTP mode which generates hashes using SHA512. TOTP in SHA512 mode
* requires 512-bit keys. * requires 512-bit keys.
*/ */
SHA512("HmacSHA512"); SHA512("HmacSHA512", 64);
/** /**
* The name of the HMAC algorithm which the TOTP implementation should * The name of the HMAC algorithm which the TOTP implementation should
@@ -145,6 +145,13 @@ public class TOTPGenerator {
*/ */
private final String algorithmName; private final String algorithmName;
/**
* The recommended length of keys generated for TOTP in this mode, in
* bytes. Keys are recommended to be the same length as the hash
* involved.
*/
private final int recommendedKeyLength;
/** /**
* Creates a new TOTP operating mode which is associated with the * Creates a new TOTP operating mode which is associated with the
* given HMAC algorithm. * given HMAC algorithm.
@@ -153,9 +160,14 @@ public class TOTPGenerator {
* The name of the HMAC algorithm which the TOTP implementation * The name of the HMAC algorithm which the TOTP implementation
* should use when operating in this mode, in the format required * should use when operating in this mode, in the format required
* by Mac.getInstance(). * by Mac.getInstance().
*
* @param recommendedKeyLength
* The recommended length of keys generated for TOTP in this mode,
* in bytes.
*/ */
private Mode(String algorithmName) { private Mode(String algorithmName, int recommendedKeyLength) {
this.algorithmName = algorithmName; this.algorithmName = algorithmName;
this.recommendedKeyLength = recommendedKeyLength;
} }
/** /**
@@ -171,6 +183,19 @@ public class TOTPGenerator {
return algorithmName; return algorithmName;
} }
/**
* Returns the recommended length of keys generated for TOTP in this
* mode, in bytes. Keys are recommended to be the same length as the
* hash involved.
*
* @return
* The recommended length of keys generated for TOTP in this mode,
* in bytes.
*/
public int getRecommendedKeyLength() {
return recommendedKeyLength;
}
} }
/** /**