我使用OpenSSL 1.0.2k来处理软件上的私钥和公钥,而一些OSes (linux 390,aix,HPUX IA64)有一些问题,只在64位arch上。
没那么麻烦,但我很烦。我从缓冲区(DER data)得到RSA*结构,我只检查RSA公共指数以确保它是奇怪的。它适用于每一个OSes,除了上面的三个:似乎RSA->e是偶数的(显然,它不是)
以下是BIGNUM结构:
struct bignum_st {
BN_ULONG *d;
int top;
int dmax;
int neg;
int flags;
}; 调试时,我在功能操作系统d == 65537,d1 == 0上看到了这一点。在无功能操作系统上,d == 0,d1 == 65537。BN_is_odd是一个宏:
# define BN_is_odd(a) (((a)->top > 0) && ((a)->d[0] & 1))#include <stdio.h>
#include <openssl/pem.h>
int get_key(const unsigned char *buf, int len) {
RSA *rsa = d2i_RSA_PUBKEY(NULL, &buf, len);
if (rsa != NULL) {
if (rsa->e != NULL) {
printf("BN : <%s> (hex) -- <%s> (dec)\n", BN_bn2hex(rsa->e), BN_bn2dec(rsa->e));
if (BN_is_odd(rsa->e) == 0) {
printf("Error : RSA public exponent is even\n");
} else {
printf("RSA public exponent is OK.\n");
return 0;
}
}
RSA_free(rsa);
} else {
printf("Error : RSA is NULL\n");
}
return 1;
}
int main() {
const unsigned char data[] = { 0x30, 0x81, 0x9f, 0x30, 0x0d, 0x06, 0x09, 0x2a, 0x86, 0x48, 0x86, 0xf7, 0x0d, 0x01, 0x01, 0x01, 0x05, 0x00, 0x03, 0x81, 0x8d, 0x00, 0x30, 0x81, 0x89, 0x02, 0x81, 0x81, 0x00, 0xd6, 0x70, 0x5d, 0x67, 0xf2, 0xe1, 0x34, 0x82, 0xd5, 0x2d, 0x79, 0xdd, 0x42, 0x55, 0x41, 0xaf, 0x0c, 0xc2, 0xb4, 0xb0, 0x94, 0xc6, 0xa0, 0x40, 0x54, 0x2e, 0x0f, 0xa5, 0x12, 0x3d, 0x43, 0x96, 0x13, 0x2d, 0x17, 0x50, 0xe5, 0x9a, 0x5a, 0x6e, 0x99, 0xc7, 0xd2, 0x63, 0x4c, 0xcd, 0x57, 0xcb, 0x57, 0x7e, 0x1e, 0x5f, 0x97, 0xaa, 0xbd, 0xe5, 0xc0, 0x98, 0xd9, 0x07, 0x52, 0xdc, 0x27, 0xa4, 0x19, 0xb2, 0x81, 0x5d, 0xd5, 0x03, 0x5c, 0xd2, 0xb3, 0xb8, 0x28, 0xaa, 0xd7, 0xaf, 0x02, 0x08, 0x1c, 0x6c, 0xc2, 0xa4, 0x6c, 0x41, 0xd3, 0xa6, 0xae, 0x51, 0x69, 0xb7, 0xd5, 0x79, 0xb8, 0x62, 0x68, 0x9e, 0xa9, 0x44, 0x8e, 0xbe, 0xb1, 0x2e, 0x1a, 0x3c, 0x4b, 0x21, 0x7b, 0x7d, 0x36, 0xf0, 0x97, 0x98, 0x81, 0x63, 0xa6, 0xfa, 0xf8, 0x28, 0x22, 0x72, 0xfe, 0x16, 0xa8, 0x16, 0x89, 0xbb, 0x02, 0x03, 0x01, 0x00, 0x01 }; /* A DER buffer, valid with openssl rsa -pubin -in <file> -inform DER */
return get_key(data, sizeof data);
}在大多数系统中,我得到了"RSA公共指数可以“的输出。然而,在另一些情况下,我得到了"RSA公共指数是偶数“。打印的BIGNUM是正确的(010001 -- 65537)。
我理解为什么BIGNUM被认为是偶数。但是为什么在这三个OSes上有一个前导零点呢?(不过,那些32位的OSes没有问题)。对此表示赞赏的任何想法:)
发布于 2021-04-08 16:43:22
很可能,这是因为您已经用OpenSSL头文件编译了64位可执行文件,这意味着32位文件。
准确地说,opensslconf.h包含以下两个部分(第一个用于32位,第二个用于64位):
181 /* Only one for the following should be defined */
182 #undef SIXTY_FOUR_BIT_LONG
183 #undef SIXTY_FOUR_BIT
184 #define THIRTY_TWO_BIT
185 #endif或
181 /* Only one for the following should be defined */
182 #define SIXTY_FOUR_BIT_LONG
183 #undef SIXTY_FOUR_BIT
184 #undef THIRTY_TWO_BIT
185 #endif要使其与32位和64位兼容,请按以下方式编辑:
181 /* Only one for the following should be defined */
182 #undef SIXTY_FOUR_BIT_LONG
183 #undef SIXTY_FOUR_BIT
184 #undef THIRTY_TWO_BIT
185 #if defined(__64BIT__)
186 #define SIXTY_FOUR_BIT_LONG
187 #else
188 #define THIRTY_TWO_BIT
189 #endif
190 #endifhttp://lzsiga.users.sourceforge.net/aix-linking.html#Q0044
https://stackoverflow.com/questions/54369069
复制相似问题