【发布时间】:2020-01-12 16:33:54
【问题描述】:
我正在尝试在基于 C++ 的应用程序中包含不同的 IPSec 算法。我想使用这里描述的 AES-XCBC 算法:http://www.faqs.org/rfcs/rfc3566.html
我查看了 OpenSSL 的 API,但没有找到适合 AES-XCBC 的 API,例如 OpenSSL 的 wiki 中描述的 AES_GCM:https://www.openssl.org/docs/man1.1.0/man3/EVP_EncryptInit_ex.html
但是能够从 OpenSwan 库中找到这个测试程序:https://github.com/xelerance/Openswan/blob/6055fc6fa444f3d5b89ad0f7d3ec277eedaa9282/lib/libcrypto/libaes/test_main_mac.c
我修改了程序以使用 RFC 3566 中算法描述链接中的第二个测试向量,例如:
Key (K) : 000102030405060708090a0b0c0d0e0f
Message (M) : 000102
AES-XCBC-MAC : 5b376580ae2f19afe7219ceef172756f
#include <stdio.h>
#include <sys/types.h>
#include <string.h>
#include "aes.h"
#include "aes_xcbc_mac.h"
#define STR "Hola guasssso c|mo estais ...012"
void print_hash(const u_int8_t *hash) {
printf("%08x %08x %08x %08x\n",
*(u_int32_t*)(&hash[0]),
*(u_int32_t*)(&hash[4]),
*(u_int32_t*)(&hash[8]),
*(u_int32_t*)(&hash[12]));
}
int main(int argc, char *argv[]) {
aes_block key= { 0x00010203, 0x04050607, 0x08090a0b, 0x0c0d0e0f };
u_int8_t hash[16];
unsigned char str[3] = {0x00, 0x01, 0x02};
aes_context_mac ctx;
AES_xcbc_mac_set_key(&ctx, (u_int8_t *)&key, sizeof(key));
AES_xcbc_mac_hash(&ctx, (u_int8_t *) &str, sizeof(str), hash);
print_has(hash);
str[2]='x';
AES_xcbc_mac_hash(&ctx,(u_int8_t *) &str, sizeof(str), hash);
print_hash(hash);
return 0;
}
为上述输入打印的输出是:
b176b661 d551b66f 64889d60 18e71c76
这与 RFC 3566 中的预期 mac 不同。我是否正确使用了 API?这个算法有参考实现吗?
【问题讨论】:
标签: c++ algorithm openssl cryptography ipsec