最近学习boringssl,发现没找到EVP_aes_128_ecb在哪里实现的
饶了一大圈,发现它的定义很无语
cpp
#define EVP_CIPHER_FUNCTION(keybits, mode) \
const EVP_CIPHER *EVP_aes_##keybits##_##mode(void) { \
return aes_##keybits##_##mode##_generic(); \
}
EVP_CIPHER_FUNCTION(128, cbc)
EVP_CIPHER_FUNCTION(128, ctr)
EVP_CIPHER_FUNCTION(128, ofb)
EVP_CIPHER_FUNCTION(128, gcm)
EVP_CIPHER_FUNCTION(192, cbc)
EVP_CIPHER_FUNCTION(192, ctr)
EVP_CIPHER_FUNCTION(192, ofb)
EVP_CIPHER_FUNCTION(192, gcm)
EVP_CIPHER_FUNCTION(256, cbc)
EVP_CIPHER_FUNCTION(256, ctr)
EVP_CIPHER_FUNCTION(256, ofb)
EVP_CIPHER_FUNCTION(256, gcm)
EVP_ECB_CIPHER_FUNCTION(128)
EVP_ECB_CIPHER_FUNCTION(192)
EVP_ECB_CIPHER_FUNCTION(256)
随便拿EVP_CIPHER_FUNCTION(128, cbc)展开
cpp
EVP_CIPHER_FUNCTION(128, cbc) = const EVP_CIPHER *EVP_aes_128_cbc(void) { \
return aes_128_cbc_generic(); \
}
这里的 aes_128_cbc_generic参考boringssl DEFINE_LOCAL_DATA
其实有方向的情况下可以用gcc -E ./src/crypto/fipsmodule/cipher/e_aes.c -o test.i -I include/
-E,只执行到预编译,直接输出预编译结果【有目标的情况下】
可以看看如下的预编译结果
cpp
# 855 "./src/crypto/fipsmodule/cipher/e_aes.c"
const EVP_CIPHER *EVP_aes_128_cbc(void) { return aes_128_cbc_generic(); }
const EVP_CIPHER *EVP_aes_128_ctr(void) { return aes_128_ctr_generic(); }
const EVP_CIPHER *EVP_aes_128_ofb(void) { return aes_128_ofb_generic(); }
const EVP_CIPHER *EVP_aes_128_gcm(void) { return aes_128_gcm_generic(); }
const EVP_CIPHER *EVP_aes_192_cbc(void) { return aes_192_cbc_generic(); }
const EVP_CIPHER *EVP_aes_192_ctr(void) { return aes_192_ctr_generic(); }
const EVP_CIPHER *EVP_aes_192_ofb(void) { return aes_192_ofb_generic(); }
const EVP_CIPHER *EVP_aes_192_gcm(void) { return aes_192_gcm_generic(); }
const EVP_CIPHER *EVP_aes_256_cbc(void) { return aes_256_cbc_generic(); }
const EVP_CIPHER *EVP_aes_256_ctr(void) { return aes_256_ctr_generic(); }
const EVP_CIPHER *EVP_aes_256_ofb(void) { return aes_256_ofb_generic(); }
const EVP_CIPHER *EVP_aes_256_gcm(void) { return aes_256_gcm_generic(); }
const EVP_CIPHER *EVP_aes_128_ecb(void) { if (hwaes_capable()) { return aes_hw_128_ecb(); } return aes_128_ecb_generic(); }
const EVP_CIPHER *EVP_aes_192_ecb(void) { if (hwaes_capable()) { return aes_hw_192_ecb(); } return aes_192_ecb_generic(); }
const EVP_CIPHER *EVP_aes_256_ecb(void) { if (hwaes_capable()) { return aes_hw_256_ecb(); } return aes_256_ecb_generic(); }
文件 "./src/crypto/fipsmodule/cipher/e_aes.c + 行号;855