use SecureRamdom()
This commit is contained in:
parent
1d6a48d01d
commit
d2711135db
|
@ -6,6 +6,7 @@ import info.nightscout.shared.utils.DateUtil
|
||||||
import java.net.DatagramPacket
|
import java.net.DatagramPacket
|
||||||
import java.net.DatagramSocket
|
import java.net.DatagramSocket
|
||||||
import java.net.InetAddress
|
import java.net.InetAddress
|
||||||
|
import java.security.SecureRandom
|
||||||
import javax.inject.Inject
|
import javax.inject.Inject
|
||||||
import javax.inject.Singleton
|
import javax.inject.Singleton
|
||||||
|
|
||||||
|
@ -195,6 +196,6 @@ class SntpClient @Inject constructor(
|
||||||
buffer[offset++] = (fraction shr 16).toByte()
|
buffer[offset++] = (fraction shr 16).toByte()
|
||||||
buffer[offset++] = (fraction shr 8).toByte()
|
buffer[offset++] = (fraction shr 8).toByte()
|
||||||
// low order bits should be random data
|
// low order bits should be random data
|
||||||
buffer[offset] = (Math.random() * 255.0).toInt().toByte()
|
buffer[offset] = SecureRandom().nextInt(256).toByte()
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -22,7 +22,7 @@ import info.nightscout.shared.sharedPreferences.SP
|
||||||
import info.nightscout.shared.utils.T
|
import info.nightscout.shared.utils.T
|
||||||
import io.reactivex.rxjava3.disposables.CompositeDisposable
|
import io.reactivex.rxjava3.disposables.CompositeDisposable
|
||||||
import io.reactivex.rxjava3.kotlin.plusAssign
|
import io.reactivex.rxjava3.kotlin.plusAssign
|
||||||
import java.lang.Math.random
|
import java.security.SecureRandom
|
||||||
import java.util.Calendar
|
import java.util.Calendar
|
||||||
import java.util.GregorianCalendar
|
import java.util.GregorianCalendar
|
||||||
import javax.inject.Inject
|
import javax.inject.Inject
|
||||||
|
@ -100,7 +100,7 @@ class RandomBgPlugin @Inject constructor(
|
||||||
|
|
||||||
val cal = GregorianCalendar()
|
val cal = GregorianCalendar()
|
||||||
val currentMinute = cal[Calendar.MINUTE] + (cal[Calendar.HOUR_OF_DAY] % 2) * 60
|
val currentMinute = cal[Calendar.MINUTE] + (cal[Calendar.HOUR_OF_DAY] % 2) * 60
|
||||||
val bgMgdl = min + ((max - min) + (max - min) * sin(currentMinute / period * 2 * PI)) / 2 + (random() - 0.5) * (max - min) * 0.4
|
val bgMgdl = min + ((max - min) + (max - min) * sin(currentMinute / period * 2 * PI)) / 2 + (SecureRandom().nextDouble() - 0.5) * (max - min) * 0.4
|
||||||
|
|
||||||
cal[Calendar.MILLISECOND] = 0
|
cal[Calendar.MILLISECOND] = 0
|
||||||
cal[Calendar.SECOND] = 0
|
cal[Calendar.SECOND] = 0
|
||||||
|
|
|
@ -12,7 +12,6 @@ import info.nightscout.interfaces.Config
|
||||||
import info.nightscout.rx.logging.AAPSLogger
|
import info.nightscout.rx.logging.AAPSLogger
|
||||||
import info.nightscout.rx.logging.LTag
|
import info.nightscout.rx.logging.LTag
|
||||||
import java.security.SecureRandom
|
import java.security.SecureRandom
|
||||||
import java.util.Random
|
|
||||||
|
|
||||||
class SessionEstablisher(
|
class SessionEstablisher(
|
||||||
private val aapsLogger: AAPSLogger,
|
private val aapsLogger: AAPSLogger,
|
||||||
|
@ -26,7 +25,7 @@ class SessionEstablisher(
|
||||||
|
|
||||||
private val controllerIV = ByteArray(IV_SIZE)
|
private val controllerIV = ByteArray(IV_SIZE)
|
||||||
private var nodeIV = ByteArray(IV_SIZE)
|
private var nodeIV = ByteArray(IV_SIZE)
|
||||||
private val identifier = Random().nextInt().toByte()
|
private val identifier = SecureRandom().nextInt().toByte()
|
||||||
private val milenage = Milenage(aapsLogger, config, ltk, eapSqn)
|
private val milenage = Milenage(aapsLogger, config, ltk, eapSqn)
|
||||||
|
|
||||||
init {
|
init {
|
||||||
|
|
|
@ -13,6 +13,7 @@ import info.nightscout.androidaps.plugins.pump.omnipod.eros.driver.manager.ErosP
|
||||||
import info.nightscout.androidaps.plugins.pump.omnipod.eros.rileylink.manager.OmnipodRileyLinkCommunicationManager
|
import info.nightscout.androidaps.plugins.pump.omnipod.eros.rileylink.manager.OmnipodRileyLinkCommunicationManager
|
||||||
import info.nightscout.rx.logging.AAPSLogger
|
import info.nightscout.rx.logging.AAPSLogger
|
||||||
import org.joda.time.DateTimeZone
|
import org.joda.time.DateTimeZone
|
||||||
|
import java.security.SecureRandom
|
||||||
import java.util.Random
|
import java.util.Random
|
||||||
|
|
||||||
class AssignAddressAction(
|
class AssignAddressAction(
|
||||||
|
@ -55,7 +56,7 @@ class AssignAddressAction(
|
||||||
|
|
||||||
companion object {
|
companion object {
|
||||||
|
|
||||||
private val random: Random = Random()
|
private val random: Random = SecureRandom()
|
||||||
private fun generateRandomAddress(): Int =
|
private fun generateRandomAddress(): Int =
|
||||||
// Create random address with 20 bits to match PDM, could easily use 24 bits instead
|
// Create random address with 20 bits to match PDM, could easily use 24 bits instead
|
||||||
0x1f000000 or (random.nextInt() and 0x000fffff)
|
0x1f000000 or (random.nextInt() and 0x000fffff)
|
||||||
|
|
Loading…
Reference in a new issue