adding rsa_import_radix tests
This commit is contained in:
parent
a2c87f54de
commit
bbbbf5f1d5
@ -46,6 +46,25 @@ static const unsigned char openssl_private_rsa[] = {
|
||||
0x78, 0x18, 0x5a, 0x79, 0x3d, 0x2e, 0x8e, 0x7e, 0x86, 0x0a, 0xe6, 0xa8, 0x33, 0xc1, 0x04, 0x17,
|
||||
0x4a, 0x9f, };
|
||||
|
||||
/* private keay - hexadecimal */
|
||||
char *hex_d = "C862B9EADE44531D5697D9979E1ACF301E0A8845862930A34D9F616573E0D6878FB6F306A382DC7CACFE9B289AAEFDFBFE2F0ED89704E3BB1FD1EC0DBAA3497F47AC8A44047E86B739423FAD1EB70EA551F440631EFDBDEA9F419FA8901D6F0A5A9513110D80AF5F64988A2C786865B02B8BA25387CAF16404ABF27BDB83C881";
|
||||
char *hex_dP = "6DEBC32D2EF05EA488310529008AD195299B83CF75DB31E37A27DE3A74300C764CD4502A402D39D99963A95D80AE53CA943F05231EF80504E1B835F217B3A089";
|
||||
char *hex_dQ = "AB9088FA600829509A438BA050CCD85AFE976463717422A320025ACFEBC6169554D1CBAB8D1AC600FA08929C71D552523596714B8B920CD0E9BFAD630BA5E9B1";
|
||||
char *hex_e = "010001";
|
||||
char *hex_N = "CF9ADE648ADAC83320A9D783311954B29A85A7A1B77533B6A9AC8424B3DEDB7D852D9665E53F7295249F2868CA4FDB441C3E60128ADD26A5EBFF0B5ED48838492A6E5BBF123747BD056BBCDBF3EEE4118E41687C6113D742C880BE368FDC088B4FACA4E2760CC9636C495893EDCCAADC253B0A603F8B543AC34D31E794A444FD";
|
||||
char *hex_p = "F7BE5E23C3323FBF8B8E3AEEFCFCCBE5F7F10BBC4282AED57A3ECAF7D5693F6425A21FB77575059242EBB8F1F30A05E394D1557835A036A09B7C92846CDDDC4D";
|
||||
char *hex_q = "D6860E85420B0408842160F00E0D88FD1E3610654F1E53B40872805C3F596617E698F2E96C7A064CAC763DED8CA1CEAD1BBDB47D28BCE30E388D99D805B5A371";
|
||||
char *hex_qP = "DCCC27C8E4DC6248D59BAFF5AB60F621FD53E2B75D09C91AA104A9FC612C5D04583A5A39F14A215667FDCC20A38F78185A793D2E8E7E860AE6A833C104174A9F";
|
||||
|
||||
/* private keay - decimal */
|
||||
char *dec_d = "140715588362011445903700789698620706303856890313846506579552319155852306603445626455616876267358538338151320072087950597426668358843246116141391746806252390039505422193715556188330352166601762210959618868365359433828069868584168017348772565936127608284367789455480066115411950431014508224203325089671253575809";
|
||||
char *dec_dP = "5757027123463051531073361217943880203685183318942602176865989327630429772398553254013771630974725523559703665512845231173916766336576994271809362147385481";
|
||||
char *dec_dQ = "8985566687080619280443708121716583572314829758991088624433980393739288226842152842353421251125477168722728289150354056572727675764519591179919295246625201";
|
||||
char *dec_e = "65537";
|
||||
char *dec_N = "145785157837445763858971808379627955816432214431353481009581718367907499729204464589803079767521523397316119124291441688063985017444589154155338311524887989148444674974298105211582428885045820631376256167593861203305479546421254276833052913791538765775697977909548553897629170045372476652935456198173974086909";
|
||||
char *dec_p = "12975386429272921390465467849934248466500992474501042673679976015025637113752114471707151502138750486193421113099777767227628554763059580218432153760685133";
|
||||
char *dec_q = "11235515692122231999359687466333538198133993435121038200055897831921312127192760781281669977582095991578071163376390471936482431583372835883432943212143473";
|
||||
char *dec_qP = "11564102464723136702427739477324729528451027211272900753079601723449664482225846595388433622640284454614991112736446376964904474099700895632145077333609119";
|
||||
|
||||
/*** openssl public RSA key in DER format */
|
||||
static const unsigned char openssl_public_rsa[] = {
|
||||
@ -119,6 +138,46 @@ static int rsa_compat_test(void)
|
||||
}
|
||||
rsa_free(&key);
|
||||
|
||||
/* try import private key from raw hexadecimal numbers */
|
||||
DO(rsa_import_radix(16, hex_N, hex_e, hex_d, hex_p, hex_q, hex_dP, hex_dQ, hex_qP, &key));
|
||||
len = sizeof(buf);
|
||||
DO(rsa_export(buf, &len, PK_PRIVATE, &key));
|
||||
if (len != sizeof(openssl_private_rsa) || memcmp(buf, openssl_private_rsa, len)) {
|
||||
fprintf(stderr, "RSA private export failed to match rsa_import_radix(16, ..)\n");
|
||||
return 1;
|
||||
}
|
||||
rsa_free(&key);
|
||||
|
||||
/* try import private key from raw decimal numbers */
|
||||
DO(rsa_import_radix(10, dec_N, dec_e, dec_d, dec_p, dec_q, dec_dP, dec_dQ, dec_qP, &key));
|
||||
len = sizeof(buf);
|
||||
DO(rsa_export(buf, &len, PK_PRIVATE, &key));
|
||||
if (len != sizeof(openssl_private_rsa) || memcmp(buf, openssl_private_rsa, len)) {
|
||||
fprintf(stderr, "RSA private export failed to match rsa_import_radix(10, ..)\n");
|
||||
return 1;
|
||||
}
|
||||
rsa_free(&key);
|
||||
|
||||
/* try import public key from raw hexadecimal numbers */
|
||||
DO(rsa_import_radix(16, hex_N, hex_e, NULL, NULL, NULL, NULL, NULL, NULL, &key));
|
||||
len = sizeof(buf);
|
||||
DO(rsa_export(buf, &len, PK_PUBLIC, &key));
|
||||
if (len != sizeof(openssl_public_rsa_stripped) || memcmp(buf, openssl_public_rsa_stripped, len)) {
|
||||
fprintf(stderr, "RSA public export failed to match rsa_import_radix(16, ..)\n");
|
||||
return 1;
|
||||
}
|
||||
rsa_free(&key);
|
||||
|
||||
/* try import public key from raw decimal numbers */
|
||||
DO(rsa_import_radix(10, dec_N, dec_e, NULL, NULL, NULL, NULL, NULL, NULL, &key));
|
||||
len = sizeof(buf);
|
||||
DO(rsa_export(buf, &len, PK_PUBLIC, &key));
|
||||
if (len != sizeof(openssl_public_rsa_stripped) || memcmp(buf, openssl_public_rsa_stripped, len)) {
|
||||
fprintf(stderr, "RSA public export failed to match rsa_import_radix(10, ..)\n");
|
||||
return 1;
|
||||
}
|
||||
rsa_free(&key);
|
||||
|
||||
/* try export in SubjectPublicKeyInfo format of the public key */
|
||||
DO(rsa_import(openssl_public_rsa, sizeof(openssl_public_rsa), &key));
|
||||
len = sizeof(buf);
|
||||
|
Loading…
Reference in New Issue
Block a user