lib_hash_drbg/src/sha256.c
/*
 * Convert a byte array to a hex string
 *  Read each byte, and convert it to two hex characters.
 *  Copy the hex characters to the output buffer.
 *  Add a trailing '\0' to the buffer, to make it a valide C string.
 *
 *  If the output buffer is not long enough to hold the entire string,
 *   return an error.
 *
 * Parameters:
 * uint8_t* in     - byte array
 * uint32_t inlen  - length of byte array
 * uint8_t* out    - hex string with terminating '\0'
 * uint32_t outlen - length of output string buffer
 *
 * Return code:
 * 0 - Error if output buffer is not at least 2*x+1 as long as the input byte array
 * 1 - Ok
 */
Convert a byte array to a hex string
Read each byte, and convert it to two hex characters.
Copy the hex characters to the output buffer.
Add a trailing '\0' to the buffer, to make it a valide C string.

If the output buffer is not long enough to hold the entire string,
return an error.

uint8_t* in     - byte array
uint32_t inlen  - length of byte array
uint8_t* out    - hex string with terminating '\0'
uint32_t outlen - length of output string buffer

Return code:
0 - Error if output buffer is not at least 2*x+1 as long as the input byte array
1 - Ok
Convert a byte array to a hex string Read each byte and convert it to two hex characters . Copy the hex characters to the output buffer . Add a trailing ' \ 0 ' to the buffer to make it a valide C string . If the output buffer is not long enough to hold the entire string return an error . uint8_t * in - byte array uint32_t inlen - length of byte array uint8_t * out - hex string with terminating ' \ 0 ' uint32_t outlen - length of output string buffer Return code : 0 - Error if output buffer is not at least 2 * x + 1 as long as the input byte array 1 - Ok
int
bytes_to_hex(const uint8_t* in, uint32_t inlen, char* out, uint32_t outlen)
{
    uint32_t i;
    const char hex[17] = "0123456789abcdef";
    if ((2*inlen+1) > outlen) {
        return 0;
    }
    for (i = 0; i < inlen; i += 1) {
        *out++ = hex[in[i] >> 4];
        *out++ = hex[in[i] & 0x0f];
    }
    *out = '\0';
    return 1;  
}
int bytes_to_hex ( const uint8_t * in , uint32_t inlen , char * out , uint32_t outlen ) { uint32_t i ; const char hex [ 17 ] = " " ; if ( ( 2 * inlen + 1 ) > outlen ) { return 0 ; } for ( i = 0 ; i < inlen ; i += 1 ) { * out ++ = hex [ in [ i ] >> 4 ] ; * out ++ = hex [ in [ i ] & 0x0f ] ; } * out = ' \0 ' ; return 1 ; }
Convert a byte array to a hex string
  Read each byte, and convert it to two hex characters.
Convert a byte array to a hex string Read each byte and convert it to two hex characters .
/*
     * Verify output buffer is long enough to hold all of the data
     */ /*
     * Convert each byte into two hex characters,
     *  and append them to the output string
     */ /*
     * Tack on a '\0' at the end to make it a valid C string
     */ /* All is well */