Skip to content

Commit 1d67ae5

Browse files
committed
Spacer didn't really do anything
1 parent 5b3ab85 commit 1d67ae5

1 file changed

Lines changed: 0 additions & 21 deletions

File tree

  • app/src/main/kotlin/com/darkrockstudios/app/securecamera/security

app/src/main/kotlin/com/darkrockstudios/app/securecamera/security/SharedKey.kt

Lines changed: 0 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ package com.darkrockstudios.app.securecamera.security
22

33
import dev.whyoleg.cryptography.random.CryptographyRandom
44
import java.nio.ByteBuffer
5-
import kotlin.random.Random
65

76
class ShardedKey(
87
key: ByteArray
@@ -20,26 +19,6 @@ class ShardedKey(
2019
part1.put(part1Array)
2120
part1.flip()
2221

23-
// Best effort to ensure the two key parts don't live next to each other in memory.
24-
// This will be released once the constructor returns (or when ever the GC runs next)
25-
val spacerSize = Random.nextInt(978, 2893)
26-
val spacer = ByteBuffer.allocateDirect(spacerSize)
27-
val spacerArray = ByteArray(spacerSize)
28-
CryptographyRandom.nextBytes(spacerArray)
29-
spacer.put(spacerArray)
30-
spacer.flip()
31-
32-
// Use it so it doesn't get optimized out
33-
(0..Random.nextInt(13)).forEachIndexed { i, _ ->
34-
val x = spacer.get(0) + spacer.get(i)
35-
// Almost never true, but compiler doesn't know that
36-
if (System.nanoTime() % 10000 == 0L) {
37-
// Side effect that's rarely executed
38-
println("$x")
39-
println(System.identityHashCode(spacer))
40-
}
41-
}
42-
4322
// Randomly size the storage buffer so it is not the exact length of an AES key
4423
val part2Size = keySize + CryptographyRandom.nextInt(5, 111)
4524
part2 = ByteBuffer.allocateDirect(part2Size)

0 commit comments

Comments
 (0)