adding dsa_import_radix tests
This commit is contained in:
parent
43517bca83
commit
ac6f69e8fe
@ -44,6 +44,20 @@ static const unsigned char openssl_priv_dsa[] = {
|
||||
0xd8, 0x1f, 0xc5
|
||||
};
|
||||
|
||||
/* private key - raw hexadecimal numbers */
|
||||
char *hex_g = "3B92E4FF5929150B08995A7BF2AD1440556FA047FF9099B344B3D4FC451505AE6722439CBA3710A5894737ECCCF5AEADA8B47A35CB9D935CEDE6B07E9694C4A60C7DD6708A094F814A0EC213FBEB16BFEAA4F456FF723005DE8A443FBEC6852655D62D1D1EDB15DAA445833C1797980B8D87F3490D90BDA9AB676E87687223DC";
|
||||
char *hex_p = "C50A37515CABD618D5A270BD4A6F6B4AF9E139950F2B99387D9A64D64CB5967ADCEDACA8ACC61B655ADEDB0061251A182CEEA10790625E4D123190C70321FA09E7B173D78EAFDBFDBFB3EFADD1A12A036DE706924A852AFF7A0166531FEAC66741845AC06CED62F9C2626205A4FA48A066EC35C9A811FEB981ABEEBE31B6BFCF";
|
||||
char *hex_q = "AA5BD7F4E5062413E58835CA00C7A635716194C5";
|
||||
char *hex_x = "9936E5E4E9FB28BE91F5065FE8C935B3F5D81FC5";
|
||||
char *hex_y = "5316B0FBBF598A5E5595C14FAC43B80853E6CF0D9223FAB184595239BFCBF22D383ADD935205497E2B12C46173E36F54BD96E5A7AAA95A58A4B767D2C0BDC81EB13A124F98C005EF395D6ABAB70B3BD8B795DD796EA2D28473470388B464D9B9B84FF1C934BBF97366F57C2E11FEC331E60838596781EB6D4127D70D74AFA035";
|
||||
|
||||
/* private key - raw decimal numbers */
|
||||
char *dec_g = "41834149751984197912953436480983170533071735026506895442815002322147255782590882063707309354781506433716654796985480894012184326029507913813728323760888731712844346877576824916725534905000120412305763983626878322597033839508975868744887842375259196379140567488975525420966465471602331600963525846901216912348";
|
||||
char *dec_p = "138366127874251453574215823372867983172559870428080754538874699342292548213873551009389476481395012375639515165022292709776266658812209612126692196557051247870332681145778007636026326219557730049370214260237710845864302921876857532769906463917243319959886290876544710558897185626634470575981605420411381006287";
|
||||
char *dec_q = "972576611327916959546542817054443329226761409733";
|
||||
char *dec_x = "874699854785640347852049895863914110365034094533";
|
||||
char *dec_y = "58346825863862115220306694056113472976936045407556113559931032566376300411053620606958863235131122432665794570437845128216268156672161823000705623178942581094085367656740608001229642983928728905397237964247962716781137229394844332774819193277135681825866994604976120931444766148118918668354923664000689348661";
|
||||
|
||||
/* The public part of test_dsa.key in SubjectPublicKeyInfo format */
|
||||
static const unsigned char openssl_pub_dsa[] = {
|
||||
0x30, 0x82, 0x01, 0xb6, 0x30, 0x82, 0x01, 0x2b, 0x06, 0x07, 0x2a, 0x86,
|
||||
@ -88,8 +102,8 @@ static const unsigned char openssl_pub_dsa[] = {
|
||||
static int dsa_compat_test(void)
|
||||
{
|
||||
dsa_key key;
|
||||
unsigned char tmp[1024];
|
||||
unsigned long x;
|
||||
unsigned char tmp[1024], buf[1024];
|
||||
unsigned long x, len;
|
||||
|
||||
DO(dsa_import(openssl_priv_dsa, sizeof(openssl_priv_dsa), &key));
|
||||
|
||||
@ -112,6 +126,46 @@ static int dsa_compat_test(void)
|
||||
DO((memcmp(tmp, openssl_pub_dsa, sizeof(openssl_pub_dsa)) == 0)?CRYPT_OK:CRYPT_ERROR);
|
||||
dsa_free(&key);
|
||||
|
||||
/* try import private key from raw hexadecimal numbers */
|
||||
DO(dsa_import_radix(16, hex_p, hex_q, hex_g, hex_x, hex_y, &key));
|
||||
len = sizeof(buf);
|
||||
DO(dsa_export(buf, &len, PK_PRIVATE | PK_STD, &key));
|
||||
if (len != sizeof(openssl_priv_dsa) || memcmp(buf, openssl_priv_dsa, len)) {
|
||||
fprintf(stderr, "DSA private export failed to match dsa_import_radix(16, ..)\n");
|
||||
return 1;
|
||||
}
|
||||
dsa_free(&key);
|
||||
|
||||
/* try import private key from raw decimal numbers */
|
||||
DO(dsa_import_radix(10, dec_p, dec_q, dec_g, dec_x, dec_y, &key));
|
||||
len = sizeof(buf);
|
||||
DO(dsa_export(buf, &len, PK_PRIVATE | PK_STD, &key));
|
||||
if (len != sizeof(openssl_priv_dsa) || memcmp(buf, openssl_priv_dsa, len)) {
|
||||
fprintf(stderr, "DSA private export failed to match dsa_import_radix(10, ..)\n");
|
||||
return 1;
|
||||
}
|
||||
dsa_free(&key);
|
||||
|
||||
/* try import public key from raw hexadecimal numbers */
|
||||
DO(dsa_import_radix(16, hex_p, hex_q, hex_g, NULL, hex_y, &key));
|
||||
len = sizeof(buf);
|
||||
DO(dsa_export(buf, &len, PK_PUBLIC | PK_STD, &key));
|
||||
if (len != sizeof(openssl_pub_dsa) || memcmp(buf, openssl_pub_dsa, len)) {
|
||||
fprintf(stderr, "DSA public export failed to match dsa_import_radix(16, ..)\n");
|
||||
return 1;
|
||||
}
|
||||
dsa_free(&key);
|
||||
|
||||
/* try import public key from raw decimal numbers */
|
||||
DO(dsa_import_radix(10, dec_p, dec_q, dec_g, NULL, dec_y, &key));
|
||||
len = sizeof(buf);
|
||||
DO(dsa_export(buf, &len, PK_PUBLIC | PK_STD, &key));
|
||||
if (len != sizeof(openssl_pub_dsa) || memcmp(buf, openssl_pub_dsa, len)) {
|
||||
fprintf(stderr, "DSA public export failed to match dsa_import_radix(10, ..)\n");
|
||||
return 1;
|
||||
}
|
||||
dsa_free(&key);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user