tests/crypto/test_ecc_dsa/src/test_ecc_utils.c
/*
 * Convert hex string to zero-padded nanoECC scalar
 */
Convert hex string to zero-padded nanoECC scalar
Convert hex string to zero - padded nanoECC scalar
int str_to_scalar(u32_t *scalar, u32_t num_word32, char *str)
{
	u32_t num_bytes = 4 * num_word32;
	u8_t tmp[num_bytes];
	size_t hexlen = strlen(str);
	int padding;
	int rc;
	padding = 2 * num_bytes - strlen(str);
	if (padding < 0) {
		TC_PRINT("Error: 2*num_bytes(%d) < strlen(hex) (%zu)\n",
			 2 * num_bytes, strlen(str));
		return TC_FAIL;
	}
	memset(tmp, 0, padding / 2);
	rc = hex_to_num_str(tmp + padding / 2, num_bytes, str, hexlen);
	if (rc == 0) {
		return TC_FAIL;
	}
	ecc_bytes2native(scalar, tmp);
	return TC_PASS;
}
int str_to_scalar ( u32_t * scalar , u32_t num_word32 , char * str ) { u32_t num_bytes = 4 * num_word32 ; u8_t tmp [ num_bytes ] ; size_t hexlen = strlen ( str ) ; int padding ; int rc ; padding = 2 * num_bytes - strlen ( str ) ; if ( padding < 0 ) { TC_PRINT ( " \n " , 2 * num_bytes , strlen ( str ) ) ; return TC_FAIL ; } memset ( tmp , 0 , padding / 2 ) ; rc = hex_to_num_str ( tmp + padding / 2 , num_bytes , str , hexlen ) ; if ( rc == 0 ) { return TC_FAIL ; } ecc_bytes2native ( scalar , tmp ) ; return TC_PASS ; }
Convert hex string to zero-padded nanoECC scalar
Convert hex string to zero - padded nanoECC scalar