Changeset 407e251 in mainline


Ignore:
Timestamp:
2024-06-12T20:50:42Z (6 weeks ago)
Author:
Miroslav Cimerman <mc@…>
Children:
d85d4f2
Parents:
c4ed9fa
Message:

Add option for 16-bit random number generation

Location:
uspace/lib/c
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • uspace/lib/c/generic/rndgen.c

    rc4ed9fa r407e251  
    9292}
    9393
     94/** Generate random 16-bit integer.
     95 *
     96 * @param rndgen Random number generator
     97 * @param rw Place to store random 16-bit integer
     98 * @return EOK on success or error code
     99 */
     100errno_t rndgen_uint16(rndgen_t *rndgen, uint16_t *rw)
     101{
     102        int i;
     103        uint8_t b;
     104        uint16_t w;
     105        errno_t rc;
     106
     107        w = 0;
     108        for (i = 0; i < 2; i++) {
     109                rc = rndgen_uint8(rndgen, &b);
     110                if (rc != EOK)
     111                        return rc;
     112
     113                w = (w << 8) | b;
     114        }
     115
     116        *rw = w;
     117        return EOK;
     118}
     119
    94120/** Generate random 32-bit integer.
    95121 *
  • uspace/lib/c/include/rndgen.h

    rc4ed9fa r407e251  
    4747extern void rndgen_destroy(rndgen_t *);
    4848extern errno_t rndgen_uint8(rndgen_t *, uint8_t *);
     49extern errno_t rndgen_uint16(rndgen_t *, uint16_t *);
    4950extern errno_t rndgen_uint32(rndgen_t *, uint32_t *);
    5051
Note: See TracChangeset for help on using the changeset viewer.