Skip to content

s_rng_ansic hangs if system clock does not advance on its own #711

@niansa

Description

@niansa

Prerequisites

  • Checked the developer manual
  • Checked that your issue isn't already filed: https://github.com/issues?utf8=✓&q=repo%3Alibtom%2Flibtomcrypt
  • Checked that your issue isn't due to the fact that you're using asymmetric cryptography and you forgot linking in and/or setting an MPI provider (usually this causes either random crashes or runtime errors like LTC_ARGCHK 'ltc_mp.name != NULL' failure ...). c.f. Ch. "Math Descriptors" of the developer manual.
  • Checked that your issue isn't related to TomsFastMath's limitation that PK operations can by default only be done with max. 2048bit keys

Description

s_rng_ansic expects the clock to advance on its own, causing an infinite loop on cooperatively-scheduled systems where the clock only advances when yielding the thread.

#0  0x001e9fe8 in clock ()
#1  0x0015eb60 in s_rng_ansic (buf=0x8007b20 ".1:53431)", len=63, callback=0x0) at libtomcrypt/src/prngs/rng_get_bytes.c:69
#2  0x0015ec8c in rng_get_bytes (out=0x8007b20 ".1:53431)", outlen=64, callback=0x0) at libtomcrypt/src/prngs/rng_get_bytes.c:163

Steps to Reproduce

One public system that causes this issue I was able to find is the Nintendo 3DS, using dev kit pro.

  1. Download devkitpro
  2. Create a project with it targeting Nintendo 3DS
  3. Call rng_get_bytes

Alternatively:

  1. Override clock() to always return the same value
  2. Call rng_get_bytes

Version

v1.18.2-1013-g9a13375d

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions