iPXE
Functions
random_nz.h File Reference

HMAC_DRBG algorithm. More...

#include <stdint.h>

Go to the source code of this file.

Functions

 FILE_LICENCE (GPL2_OR_LATER_OR_UBDL)
int get_random_nz (void *data, size_t len)
 Get random non-zero bytes.

Detailed Description

HMAC_DRBG algorithm.

Definition in file random_nz.h.


Function Documentation

FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL  )
int get_random_nz ( void *  data,
size_t  len 
)

Get random non-zero bytes.

Parameters:
dataOutput buffer
lenLength of output buffer
Return values:
rcReturn status code

This algorithm is designed to be isomorphic to the Simple Discard Method described in ANS X9.82 Part 1-2006 Section 9.2.1 (NIST SP 800-90 Section B.5.1.1).

Definition at line 62 of file random_nz.c.

References bytes, data, NULL, rbg_generate(), and rc.

Referenced by rsa_encrypt().

                                             {
        uint8_t *bytes = data;
        int rc;

        while ( len ) {

                /* Generate random byte */
                if ( ( rc = rbg_generate ( NULL, 0, 0, bytes, 1 ) ) != 0 )
                        return rc;

                /* Move to next byte if this byte is acceptable */
                if ( *bytes != 0 ) {
                        bytes++;
                        len--;
                }
        }

        return 0;
}