@Override public int getDisplaySize() { return MathUtils.convertLongToInt(value.length * 2L); }
protected byte[] generateSalt() { return MathUtils.secureRandomBytes(Constants.FILE_BLOCK_SIZE); }
private static byte[] getPaddedArrayCopy(byte[] data, int blockSize) { int size = MathUtils.roundUpInt(data.length, blockSize); byte[] newData = DataUtils.newBytes(size); System.arraycopy(data, 0, newData, 0, data.length); return newData; }
private static int getBufferSize(DataHandler handler, boolean compress, long remaining) { if (remaining < 0 || remaining > Integer.MAX_VALUE) { remaining = Integer.MAX_VALUE; } int inplace = handler.getMaxLengthInplaceLob(); long m = compress ? Constants.IO_BUFFER_SIZE_COMPRESS : Constants.IO_BUFFER_SIZE; if (m < remaining && m <= inplace) { // using "1L" to force long arithmetic because // inplace could be Integer.MAX_VALUE m = Math.min(remaining, inplace + 1L); // the buffer size must be bigger than the inplace lob, otherwise we // can't know if it must be stored in-place or not m = MathUtils.roundUpLong(m, Constants.IO_BUFFER_SIZE); } m = Math.min(remaining, m); m = MathUtils.convertLongToInt(m); if (m < 0) { m = Integer.MAX_VALUE; } return (int) m; }
delay = MathUtils.secureRandomInt((int) delay); try { Thread.sleep(delay); delay += Math.abs(MathUtils.secureRandomLong() % 100); try { Thread.sleep(delay);
/** * Get the next temporary file name part (the part in the middle). * * @param newRandom if the random part of the filename should change * @return the file name part */ protected static synchronized String getNextTempFileNamePart(boolean newRandom) { if (newRandom || tempRandom == null) { tempRandom = MathUtils.randomInt(Integer.MAX_VALUE) + "."; } return tempRandom + tempSequence++; }
/** * Create a new UUID using the pseudo random number generator. * * @return the new UUID */ public static ValueUuid getNewRandom() { long high = MathUtils.secureRandomLong(); long low = MathUtils.secureRandomLong(); // version 4 (random) high = (high & (~0xf000L)) | 0x4000L; // variant (Leach-Salz) low = (low & 0x3fffffffffffffffL) | 0x8000000000000000L; return new ValueUuid(high, low); }
@Override protected int compareSecure(Value o, CompareMode mode) { ValueTimestamp t = (ValueTimestamp) o; int c = MathUtils.compareLong(dateValue, t.dateValue); if (c != 0) { return c; } return MathUtils.compareLong(nanos, t.nanos); }
@Override protected int compareSecure(Value o, CompareMode mode) { ValueByte v = (ValueByte) o; return MathUtils.compareInt(value, v.value); }
int p = low + MathUtils.randomInt(high - low); X pivot = array[p]; int m = (low + high) >>> 1;
@Override protected int compareSecure(Value o, CompareMode mode) { if (o == this) { return 0; } ValueUuid v = (ValueUuid) o; if (high == v.high) { return MathUtils.compareLong(low, v.low); } return high > v.high ? 1 : -1; }
@Override protected int compareSecure(Value o, CompareMode mode) { ValueShort v = (ValueShort) o; return MathUtils.compareInt(value, v.value); }
int getPrecisionAsInt() { return MathUtils.convertLongToInt(precision); }
private void init() throws IOException { if (xts != null) { return; } this.size = base.size() - HEADER_LENGTH; boolean newFile = size < 0; byte[] salt; if (newFile) { byte[] header = Arrays.copyOf(HEADER, BLOCK_SIZE); salt = MathUtils.secureRandomBytes(SALT_LENGTH); System.arraycopy(salt, 0, header, SALT_POS, salt.length); DataUtils.writeFully(base, 0, ByteBuffer.wrap(header)); size = 0; } else { salt = new byte[SALT_LENGTH]; DataUtils.readFully(base, SALT_POS, ByteBuffer.wrap(salt)); if ((size & BLOCK_SIZE_MASK) != 0) { size -= BLOCK_SIZE; } } AES cipher = new AES(); cipher.setKey(SHA256.getPBKDF2(encryptionKey, salt, HASH_ITERATIONS, 16)); encryptionKey = null; xts = new XTS(cipher); }
/** * Fill up the buffer with empty space and an (initially empty) checksum * until the size is a multiple of Constants.FILE_BLOCK_SIZE. */ public void fillAligned() { int position = buff.position(); // 0..6 > 8, 7..14 > 16, 15..22 > 24, ... int len = MathUtils.roundUpInt(position + 2, Constants.FILE_BLOCK_SIZE); ensureCapacity(len - position); buff.position(len); }
sqlStatementExecutor.executeNextStatement(); } else { int sleep = 1 + MathUtils.randomInt(10); while (true) { try {
@Override protected int compareSecure(Value o, CompareMode mode) { ValueLong v = (ValueLong) o; return MathUtils.compareLong(value, v.value); }
@Override protected int compareSecure(Value o, CompareMode mode) { ValueInt v = (ValueInt) o; return MathUtils.compareInt(value, v.value); }
public void setLobBlockSize(long blockSize) { this.lobBlockSize = MathUtils.convertLongToInt(blockSize); }
private byte[] calculateLobMac(long lobId) { byte[] lobMacSalt = null; if (session != null) { lobMacSalt = session.getLobMacSalt(); } if (lobMacSalt == null) { lobMacSalt = MathUtils.secureRandomBytes(LOB_MAC_SALT_LENGTH); if (session != null) { session.setLobMacSalt(lobMacSalt); } } byte[] data = new byte[8]; Utils.writeLong(data, 0, lobId); byte[] hmacData = SHA256.getHashWithSalt(data, lobMacSalt); return hmacData; }