Skip to content
This repository has been archived by the owner on Oct 31, 2023. It is now read-only.

Bug in Sha512Random.split(1) #116

Open
gafter opened this issue Jul 29, 2022 · 0 comments
Open

Bug in Sha512Random.split(1) #116

gafter opened this issue Jul 29, 2022 · 0 comments
Assignees

Comments

@gafter
Copy link
Contributor

gafter commented Jul 29, 2022

There is a bug in Sha512Random.split(1) exposed by the following test.

    @Test fun split_One() {
        val k1 = RandomKey()
        val k2 = k1.split(1)[0];
        val k3 = k2.split(1)[0];
    }

The bug is in these lines:

    override fun split(n: Int): List<Sha512Random> {
        if (hasBeenUsed && !permitsReuse)
            throw IllegalStateException("RandomKey instance has already been used.")
        hasBeenUsed = true
        // No need to split if n==1
        if (n == 1) return listOf(this)

The code invalidates this and then returns it as if it is valid.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants