Skip to content

Bug: challenge_response.c uses predictable rand()/srand() for nonce generation #4861

@508704820

Description

@508704820

Bug: C challenge-response uses rand()/srand() — predictable nonce

Severity: High (Security)

File: src/anti_spoof/challenge_response.c, generate_challenge() (line 300) and main() (line 519)

Description:
The C implementation uses rand() seeded with srand(time(NULL) ^ read_timebase()) to generate challenge nonces. Both rand() (Mersenne Twister/LCG) and the seed are predictable:

  1. Line 300: c.nonce[i] = (unsigned char)(rand() ^ (c.timestamp >> (i % 8))); — XOR with known timestamp doesn't help if rand() output is predictable
  2. Line 519: srand((unsigned int)time(NULL) ^ (unsigned int)read_timebase()) — seed is guessable

Impact:

Expected Fix:
Use getrandom() (Linux) or SecRandomCopyBytes() (macOS) for nonce generation. On PowerPC, use the timebase register directly as entropy source.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions