Package org.cryptacular.generator
Class AbstractOTPGenerator
java.lang.Object
org.cryptacular.generator.AbstractOTPGenerator
- Direct Known Subclasses:
HOTPGenerator,TOTPGenerator
-
Field Summary
FieldsModifier and TypeFieldDescriptionprotected static final intDefault number of digits to generate.private static final int[]Array of modulus values indexed per number of digits in OTP output.private final intNumber of digits in generated OTP. -
Constructor Summary
ConstructorsConstructorDescriptionCreates a new abstract OTP generator.AbstractOTPGenerator(int numberOfDigits) Creates a new abstract OTP generator. -
Method Summary
Modifier and TypeMethodDescriptionprotected intgenerateInternal(byte[] key, long count) Internal OTP generation method.protected abstract org.bouncycastle.crypto.Digestintprivate inttruncate(byte[] hmac) Truncates HMAC output onto an unsigned (i.e.
-
Field Details
-
DEFAULT_NUMBER_OF_DIGITS
protected static final int DEFAULT_NUMBER_OF_DIGITSDefault number of digits to generate.- See Also:
-
MODULUS
private static final int[] MODULUSArray of modulus values indexed per number of digits in OTP output. -
numberOfDigits
private final int numberOfDigitsNumber of digits in generated OTP.
-
-
Constructor Details
-
AbstractOTPGenerator
public AbstractOTPGenerator()Creates a new abstract OTP generator. -
AbstractOTPGenerator
public AbstractOTPGenerator(int numberOfDigits) Creates a new abstract OTP generator.- Parameters:
numberOfDigits- Number of digits in generated OTP. MUST be in the range 6 - 9.
-
-
Method Details
-
getNumberOfDigits
public int getNumberOfDigits()- Returns:
- Number of digits in generated OTP.
-
generateInternal
protected int generateInternal(byte[] key, long count) Internal OTP generation method.- Parameters:
key- Per-user key.count- Counter moving factor.- Returns:
- Integer OTP.
-
getDigest
protected abstract org.bouncycastle.crypto.Digest getDigest()- Returns:
- Digest algorithm used for HMAC operation.
-
truncate
private int truncate(byte[] hmac) Truncates HMAC output onto an unsigned (i.e. 31-bit) integer using the strategy discussed in RFC 4226, section 5.3.- Parameters:
hmac- HMAC output.- Returns:
- Truncated output.
-