private_key = crypto.PKey()
# read private file for from file
with open(expand_filename(_('output.private_key_file')), 'rb') as f:
keystring = f.read()
private_key = crypto.load_privatekey(crypto.FILETYPE_ASN1, keystring)
# generate hash over data and sign it, sw_bin is data from a binary ELF file
sign = crypto.sign(private_key, sw_bin, "sha256")
/**
* Register the hash method and set hash index for method
* @return void
*/
void
set_hash_index()
{
if( register_hash(&sha256_desc) == -1 )
{
print_string("Error: registering sha256 hash\n");
}
hash_index = find_hash(hash_method);
}
/*
* Get the hash index
* @return int - hash index
*/
int
get_hash_index()
{
return(hash_index);
}
/**
* calculate a hash256 over data
*
* @param data - array of data
* @param datasize - length of array
* @param unsigned char* - address where calculated hash is stored
* @param unsigned long* - address where length of hash is stored
* @return bool - true if hash calculated otherwise false
*/
bool
get_data_hash(unsigned char* data,
int datasize,
unsigned char* hash,
unsigned long* hash_len)
{
/* required to engage math library */
ltc_mp = ltm_desc;
set_hash_index();
if( (hash_memory(get_hash_index(), data, datasize, hash, hash_len)) != CRYPT_OK )
{
print_string("Failed to calculate hash on data\n");
return(false);
}
return(true);
}