MCPcopy Create free account
hub / github.com/Meituan-Dianping/SQLAdvisor / EVP_BytesToKey

Function EVP_BytesToKey

extra/yassl/src/ssl.cpp:1048–1124  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1046
1047
1048int EVP_BytesToKey(const EVP_CIPHER* type, const EVP_MD* md, const byte* salt,
1049 const byte* data, int sz, int count, byte* key, byte* iv)
1050{
1051 // only support MD5 for now
1052 if (strncmp(md, "MD5", 3)) return 0;
1053
1054 int keyLen = 0;
1055 int ivLen = 0;
1056
1057 // only support CBC DES and AES for now
1058 if (strncmp(type, "DES-CBC", 7) == 0) {
1059 keyLen = DES_KEY_SZ;
1060 ivLen = DES_IV_SZ;
1061 }
1062 else if (strncmp(type, "DES-EDE3-CBC", 12) == 0) {
1063 keyLen = DES_EDE_KEY_SZ;
1064 ivLen = DES_IV_SZ;
1065 }
1066 else if (strncmp(type, "AES-128-CBC", 11) == 0) {
1067 keyLen = AES_128_KEY_SZ;
1068 ivLen = AES_IV_SZ;
1069 }
1070 else if (strncmp(type, "AES-192-CBC", 11) == 0) {
1071 keyLen = AES_192_KEY_SZ;
1072 ivLen = AES_IV_SZ;
1073 }
1074 else if (strncmp(type, "AES-256-CBC", 11) == 0) {
1075 keyLen = AES_256_KEY_SZ;
1076 ivLen = AES_IV_SZ;
1077 }
1078 else
1079 return 0;
1080
1081 yaSSL::MD5 myMD;
1082 uint digestSz = myMD.get_digestSize();
1083 byte digest[SHA_LEN]; // max size
1084
1085 int keyLeft = keyLen;
1086 int ivLeft = ivLen;
1087 int keyOutput = 0;
1088
1089 while (keyOutput < (keyLen + ivLen)) {
1090 int digestLeft = digestSz;
1091 // D_(i - 1)
1092 if (keyOutput) // first time D_0 is empty
1093 myMD.update(digest, digestSz);
1094 // data
1095 myMD.update(data, sz);
1096 // salt
1097 if (salt)
1098 myMD.update(salt, EVP_SALT_SZ);
1099 myMD.get_digest(digest);
1100 // count
1101 for (int j = 1; j < count; j++) {
1102 myMD.update(digest, digestSz);
1103 myMD.get_digest(digest);
1104 }
1105

Callers 2

read_fileFunction · 0.85
test_openSSL_desFunction · 0.85

Calls 4

minFunction · 0.85
get_digestSizeMethod · 0.80
get_digestMethod · 0.80
updateMethod · 0.45

Tested by 1

test_openSSL_desFunction · 0.68