import java.math.BigInteger;
import java.nio.charset.StandardCharsets;
import java.util.ArrayList;
+import java.util.Base64;
import java.util.Collections;
import java.util.Comparator;
import java.util.HashMap;
private final DataBroker dataBroker;
private final DeviceTransactionManager deviceTransactionManager;
private final OpenRoadmInterfaces openRoadmInterfaces;
- //FNV1 128 bit hash constants
- private static final BigInteger FNV_PRIME = new BigInteger("309485009821345068724781371");
- private static final BigInteger FNV_INIT = new BigInteger("6c62272e07bb014262b821756295c58d", 16);
- private static final BigInteger FNV_MOD = new BigInteger("2").pow(128);
+ //FNV1 64 bit hash constants
+ private static final BigInteger FNV_PRIME = new BigInteger("100000001b3", 16);
+ private static final BigInteger FNV_INIT = new BigInteger("cbf29ce484222325", 16);
+ private static final BigInteger FNV_MOD = new BigInteger("2").pow(64);
public PortMappingVersion221(DataBroker dataBroker, DeviceTransactionManager deviceTransactionManager,
OpenRoadmInterfaces openRoadmInterfaces) {
}
/**
- * Implements the FNV-1 128bit algorithm.
+ * Implements the FNV-1 64bit algorithm.
+ * FNV-1 128bit would be ideal for 16 bytes but we need an overhead for Base64 encoding.
+ * Otherwise, the hash cannot be stored in a UTF-8 string.
* https://www.wikiwand.com/en/Fowler%E2%80%93Noll%E2%80%93Vo_hash_function#/FNV-1_hash
* https://github.com/pmdamora/fnv-cracker-app/blob/master/src/main/java/passwordcrack/cracking/HashChecker.java
* @param stringdata the String to be hashed
hash = hash.xor(BigInteger.valueOf((int) b & 0xff));
}
- return hash.toString(16);
+ return Base64.getEncoder().encodeToString(hash.toByteArray());
}
}