tests/crypto/test_ecc_dsa/src/test_ecc_utils.c
/*
 * Convert hex string to byte string
 * Return number of bytes written to buf, or 0 on error
 */
Convert hex string to byte string
Return number of bytes written to buf, or 0 on error
Convert hex string to byte string Return number of bytes written to buf or 0 on error
int hex_to_num_str(u8_t *buf, const size_t buflen, const char *hex,
		   const size_t hexlen)
{
	int dec;
	if (buflen < hexlen / 2 + hexlen % 2) {
		return 0;
	}
	if (hexlen % 2) {
		dec = hex_to_num(hex[0]);
		if (dec == -1) {
			return 0;
		}
		buf[0] = dec;
		buf++;
		hex++;
	}
	for (size_t i = 0; i < hexlen / 2; i++) {
		dec = hex_to_num(hex[2 * i]);
		if (dec == -1) {
			return 0;
		}
		buf[i] = dec << 4;
		dec = hex_to_num(hex[2 * i + 1]);
		if (dec == -1) {
			return 0;
		}
		buf[i] += dec;
	}
	return hexlen / 2 + hexlen % 2;
}
int hex_to_num_str ( u8_t * buf , const size_t buflen , const char * hex , const size_t hexlen ) { int dec ; if ( buflen < hexlen / 2 + hexlen % 2 ) { return 0 ; } if ( hexlen % 2 ) { dec = hex_to_num ( hex [ 0 ] ) ; if ( dec == -1 ) { return 0 ; } buf [ 0 ] = dec ; buf ++ ; hex ++ ; } for ( size_t i = 0 ; i < hexlen / 2 ; i ++ ) { dec = hex_to_num ( hex [ 2 * i ] ) ; if ( dec == -1 ) { return 0 ; } buf [ i ] = dec << 4 ; dec = hex_to_num ( hex [ 2 * i + 1 ] ) ; if ( dec == -1 ) { return 0 ; } buf [ i ] += dec ; } return hexlen / 2 + hexlen % 2 ; }
Convert hex string to byte string
 Return number of bytes written to buf, or 0 on error
Convert hex string to byte string Return number of bytes written to buf or 0 on error
/* if hexlen is uneven, insert leading zero nibble */ /* regular hex conversion */