Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

PK should not be generated with random_bytes #1169

Closed
kpp opened this issue Sep 17, 2018 · 3 comments
Closed

PK should not be generated with random_bytes #1169

kpp opened this issue Sep 17, 2018 · 3 comments
Labels
P2 Medium priority
Milestone

Comments

@kpp
Copy link

kpp commented Sep 17, 2018

https://github.com/TokTok/c-toxcore/blob/2abc00693cc99f277c7c8fe1a201ec33becb01f1/toxcore/DHT.c#L2743..L2751

Since you have a function named public_key_valid, PK from random_bytes generates an invalid PK each 1/2 attempt.

void random_bytes(uint8_t *data, size_t length)
{
    randombytes(data, length); // from NaCl
}

bool public_key_valid(const uint8_t *public_key)
{
    if (public_key[31] >= 128) { /* Last bit of key is always zero. */
        return 0;
    }

    return 1;
}
@iphydf iphydf added this to the v0.2.x milestone Sep 17, 2018
@iphydf iphydf added P1 High priority P2 Medium priority and removed P1 High priority labels Sep 17, 2018
@iphydf
Copy link
Member

iphydf commented Sep 17, 2018

Thanks. The keys generated there aren't real keys, they are random keys to seed the DHT search list.

This issue still makes sense to fix, but it's not breaking anything. We never actually find or even want to find these keys.

@kpp
Copy link
Author

kpp commented Sep 17, 2018

We never actually find or even want to find these keys.

Actually DHT sends NodesRequest with PKs of fake friends to fill the Kademlia tree faster. It does not break anything, but it smells a little.

@iphydf
Copy link
Member

iphydf commented Sep 17, 2018

Correct, we send requests for them, but we don't want to find them. I agree it smells and we should fix that. The correct fix involves stronger typing and ensuring that values of type "Public_Key" are never invalid.

This issue was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
P2 Medium priority
Projects
None yet
Development

No branches or pull requests

3 participants