at.gadermaier.argon2.model.Block Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of LockLogin Show documentation
Show all versions of LockLogin Show documentation
Adds an extra protection to your Bukkit-Spigot-Paper/BungeeCord server with this plugins that adds 2FA to his security system
The newest version!
package at.gadermaier.argon2.model;
import at.gadermaier.argon2.Util;
import java.util.Arrays;
import static at.gadermaier.argon2.Constants.ARGON2_BLOCK_SIZE;
import static at.gadermaier.argon2.Constants.ARGON2_QWORDS_IN_BLOCK;
public class Block {
/* 128 * 8 Byte QWords */
public long[] v;
public Block() {
v = new long[ARGON2_QWORDS_IN_BLOCK];
}
public void fromBytes(byte[] input) {
assert (input.length == ARGON2_BLOCK_SIZE);
for (int i = 0; i < v.length; i++) {
byte[] slice = Arrays.copyOfRange(input, i * 8, (i + 1) * 8);
v[i] = Util.littleEndianBytesToLong(slice);
}
}
public byte[] toBytes() {
byte[] result = new byte[ARGON2_BLOCK_SIZE];
for (int i = 0; i < v.length; i++) {
byte[] bytes = Util.longToLittleEndianBytes(v[i]);
System.arraycopy(bytes, 0, result, i * bytes.length, bytes.length);
}
return result;
}
public void copyBlock(Block other) {
System.arraycopy(other.v, 0, v, 0, v.length);
}
public void xor(Block b1, Block b2) {
for (int i = 0; i < v.length; i++) {
v[i] = b1.v[i] ^ b2.v[i];
}
}
public void xor(Block b1, Block b2, Block b3) {
for (int i = 0; i < v.length; i++) {
v[i] = b1.v[i] ^ b2.v[i] ^ b3.v[i];
}
}
public void xorWith(Block other) {
for (int i = 0; i < v.length; i++) {
v[i] = v[i] ^ other.v[i];
}
}
@Override
public String toString() {
StringBuilder result = new StringBuilder();
for (long value : v) {
result.append(Util.bytesToHexString(Util.longToLittleEndianBytes(value)));
}
return result.toString();
}
void clear() {
Arrays.fill(v, 0);
}
}
© 2015 - 2024 Weber Informatics LLC | Privacy Policy