PseudoRandomFunction Class — netty Architecture
Architecture documentation for the PseudoRandomFunction class in PseudoRandomFunction.java from the netty codebase.
Entity Profile
Dependency Diagram
graph TD 431b76bc_7e00_cc48_26d9_b766666a6d12["PseudoRandomFunction"] 7873ecf3_9523_25e1_80a4_b17cd4661c87["PseudoRandomFunction.java"] 431b76bc_7e00_cc48_26d9_b766666a6d12 -->|defined in| 7873ecf3_9523_25e1_80a4_b17cd4661c87 c9b0cd52_ac5a_ccd9_36b8_89cd486497ff["PseudoRandomFunction()"] 431b76bc_7e00_cc48_26d9_b766666a6d12 -->|method| c9b0cd52_ac5a_ccd9_36b8_89cd486497ff a87902db_61fe_7a64_914d_ac398f987472["hash()"] 431b76bc_7e00_cc48_26d9_b766666a6d12 -->|method| a87902db_61fe_7a64_914d_ac398f987472 78dde20e_4bff_6001_62fe_1c7953a28da7["concat()"] 431b76bc_7e00_cc48_26d9_b766666a6d12 -->|method| 78dde20e_4bff_6001_62fe_1c7953a28da7
Relationship Graph
Source Code
handler/src/main/java/io/netty/handler/ssl/PseudoRandomFunction.java lines 36–94
final class PseudoRandomFunction {
/**
* Constructor never to be called.
*/
private PseudoRandomFunction() {
}
/**
* Use a single hash function to expand a secret and seed into an
* arbitrary quantity of output.
*
* P_hash(secret, seed) = HMAC_hash(secret, A(1) + seed) +
* HMAC_hash(secret, A(2) + seed) +
* HMAC_hash(secret, A(3) + seed) + ...
* where + indicates concatenation.
* A() is defined as:
* A(0) = seed
* A(i) = HMAC_hash(secret, A(i-1))
* @param secret The starting secret to use for expansion
* @param label An ascii string without a length byte or trailing null character.
* @param seed The seed of the hash
* @param length The number of bytes to return
* @param algo the hmac algorithm to use
* @return The expanded secrets
* @throws IllegalArgumentException if the algo could not be found.
*/
static byte[] hash(byte[] secret, byte[] label, byte[] seed, int length, String algo) {
checkPositiveOrZero(length, "length");
try {
Mac hmac = Mac.getInstance(algo);
hmac.init(new SecretKeySpec(secret, algo));
/*
* P_hash(secret, seed) = HMAC_hash(secret, A(1) + seed) +
* HMAC_hash(secret, A(2) + seed) + HMAC_hash(secret, A(3) + seed) + ...
* where + indicates concatenation. A() is defined as: A(0) = seed, A(i)
* = HMAC_hash(secret, A(i-1))
*/
int iterations = (int) Math.ceil(length / (double) hmac.getMacLength());
byte[] expansion = EmptyArrays.EMPTY_BYTES;
byte[] data = concat(label, seed);
byte[] A = data;
for (int i = 0; i < iterations; i++) {
A = hmac.doFinal(A);
expansion = concat(expansion, hmac.doFinal(concat(A, data)));
}
return Arrays.copyOf(expansion, length);
} catch (GeneralSecurityException e) {
throw new IllegalArgumentException("Could not find algo: " + algo, e);
}
}
private static byte[] concat(byte[] first, byte[] second) {
byte[] result = Arrays.copyOf(first, first.length + second.length);
System.arraycopy(second, 0, result, first.length, second.length);
return result;
}
}
Source
Frequently Asked Questions
What is the PseudoRandomFunction class?
PseudoRandomFunction is a class in the netty codebase, defined in handler/src/main/java/io/netty/handler/ssl/PseudoRandomFunction.java.
Where is PseudoRandomFunction defined?
PseudoRandomFunction is defined in handler/src/main/java/io/netty/handler/ssl/PseudoRandomFunction.java at line 36.
Analyze Your Own Codebase
Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.
Try Supermodel Free