Skip to content

PK should not be generated with random_bytes #1169

Description

@kpp

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;
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    P2Medium priority

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions