Skip to content

Add support for HMAC based on sha256 (128b keys). #669

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 26 additions & 12 deletions print-esp.c
Original file line number Diff line number Diff line change
Expand Up @@ -409,6 +409,25 @@ int espprint_decode_hex(netdissect_options *ndo,
return i;
}

static int
strendswith(const char *str, const char *end)
{
char *p;
const size_t str_len = strlen(str);
const size_t end_len = strlen(end);

/*
* Find substring at the end of given substring. If present,
* cut str by placing '\0' right before ending substring.
*/
if (str_len > end_len && !strcmp(str + str_len - end_len, end)) {
p = strstr(str, end);
*p = '\0';
return 1;
}
return 0;
}

/*
* decode the form: SPINUM@IP <tab> ALGONAME:0xsecret
*/
Expand All @@ -421,7 +440,7 @@ espprint_decode_encalgo(netdissect_options *ndo,
size_t i;
const EVP_CIPHER *evp;
int authlen = 0;
char *colon, *p;
char *colon;

colon = strchr(decode, ':');
if (colon == NULL) {
Expand All @@ -430,18 +449,13 @@ espprint_decode_encalgo(netdissect_options *ndo,
}
*colon = '\0';

if (strlen(decode) > strlen("-hmac96") &&
!strcmp(decode + strlen(decode) - strlen("-hmac96"),
"-hmac96")) {
p = strstr(decode, "-hmac96");
*p = '\0';
if (strendswith(decode, "-hmac96"))
authlen = 12;
}
if (strlen(decode) > strlen("-cbc") &&
!strcmp(decode + strlen(decode) - strlen("-cbc"), "-cbc")) {
p = strstr(decode, "-cbc");
*p = '\0';
}

if (strendswith(decode, "-hmac-sha256-128"))
authlen = 16;

(void)strendswith(decode, "-cbc");
evp = EVP_get_cipherbyname(decode);

if (!evp) {
Expand Down