check length of private key components before setting

the card functions only accepts key components of correct size
so here we add 0 before if they're shorter (usually one byte shorter)
thus fixing the issue where the card returned 6f00
This commit is contained in:
Klas Lindfors
2014-11-12 14:08:11 +01:00
parent d0cef2f469
commit 36468219c2
3 changed files with 41 additions and 12 deletions
+12
View File
@@ -203,3 +203,15 @@ int get_object_id(enum enum_slot slot) {
}
return object;
}
bool set_component_with_len(unsigned char **in_ptr, const BIGNUM *bn, int element_len) {
int real_len = BN_num_bytes(bn);
*in_ptr += set_length(*in_ptr, element_len);
if(real_len > element_len) {
return false;
}
memset(*in_ptr, 0, (size_t)(element_len - real_len));
*in_ptr += element_len - real_len;
*in_ptr += BN_bn2bin(bn, *in_ptr);
return true;
}