0
我有一個96字節長的ecdsa簽名,使用原始格式的智能卡使用sha384算法創建。它由兩個長度爲整數r和s的長整數字組成。 ecdsa簽名位於由sign_ptr指向的緩衝區中。我使用此功能轉換RAW格式 簽名改成buf_out在ASN1格式(C):將原始格式ecdsa sha384 csr簽名轉換爲ASN1格式
int convert_ecdsa_sha384_sign(char **buf_out, char *sign_ptr)
{
buf_out[0]=0x30; /* Type = Sequence of */
buf_out[2]=0x02; /* Type = Integer */
/* Verify if negative bit is set */
if (!(sign_ptr[0] & 0x80))
{
buf_out[3]=0x30; /* Length */
memcpy(&(buf_out[4]), sign_ptr, 48); /* Copy first integer */
}
else
{
/* Negative bit is set. Add one padding byte */
buf_out[3]=0x31; /* Length */
buf_out[4]=0x00; /* Padding */
memcpy(&(buf_out[5]), sign_ptr, 48); /* Copy first integer */
sign_offset += 1;
}
buf_out[52+sign_offset]=0x02; /* Type = Integer */
/* Verify if negative bit is set */
if (!(sign_ptr[48] & 0x80))
{
buf_out[53+sign_offset]=0x30; /* Length */
memcpy(((&(buf_out[54]))+ sign_offset), sign_ptr + 48, 48); /* Copy second integer */
}
else
{
/* Negative bit is set. Add one padding byte */
buf_out[53+sign_offset]=0x31; /* Length */
buf_out[54+sign_offset]=0x00; /* Padding */
memcpy(((&(buf_out[55]))+ sign_offset), sign_ptr + 48, 48); /* Copy second integer */
sign_offset += 1;
}
buf_out[1]= 100 + sign_offset; /* Total signature length */
return 1;
}
我想知道如果有一個相當於OpenSSL的功能,可以幫我做這在一個更優雅的方式?我看過很多d2i函數(d2i_ASN1_xxxx,ASN1_item_d2i,ASN_d2i_func等),但不清楚哪一個適合。
信息:http://www.codeproject.com/Articles/25590/Cryptographic-Interoperability-Digital-Signatures – Andrew