diff --git a/ssh.h b/ssh.h index 4054694a..ec7566f6 100644 --- a/ssh.h +++ b/ssh.h @@ -627,9 +627,9 @@ struct ssh2_macalg { void (*setkey)(ssh2_mac *, ptrlen key); void (*start)(ssh2_mac *); void (*genresult)(ssh2_mac *, unsigned char *); + const char *(*text_name)(ssh2_mac *); const char *name, *etm_name; int len, keylen; - const char *text_name; }; #define ssh2_mac_new(alg, cipher) ((alg)->new(alg, cipher)) @@ -637,6 +637,7 @@ struct ssh2_macalg { #define ssh2_mac_setkey(ctx, key) ((ctx)->vt->setkey(ctx, key)) #define ssh2_mac_start(ctx) ((ctx)->vt->start(ctx)) #define ssh2_mac_genresult(ctx, out) ((ctx)->vt->genresult(ctx, out)) +#define ssh2_mac_text_name(ctx) ((ctx)->vt->text_name(ctx)) #define ssh2_mac_alg(ctx) ((ctx)->vt) /* Centralised 'methods' for ssh2_mac, defined in sshmac.c. These run diff --git a/ssh2bpp.c b/ssh2bpp.c index 6a79221b..d6ae6a41 100644 --- a/ssh2bpp.c +++ b/ssh2bpp.c @@ -140,7 +140,7 @@ void ssh2_bpp_new_outgoing_crypto( ssh2_mac_setkey(s->out.mac, make_ptrlen(mac_key, mac->keylen)); bpp_logevent("Initialised %s outbound MAC algorithm%s%s", - ssh2_mac_alg(s->out.mac)->text_name, + ssh2_mac_text_name(s->out.mac), etm_mode ? " (in ETM mode)" : "", (s->out.cipher && ssh_cipher_alg(s->out.cipher)->required_mac ? @@ -197,7 +197,7 @@ void ssh2_bpp_new_incoming_crypto( ssh2_mac_setkey(s->in.mac, make_ptrlen(mac_key, mac->keylen)); bpp_logevent("Initialised %s inbound MAC algorithm%s%s", - ssh2_mac_alg(s->in.mac)->text_name, + ssh2_mac_text_name(s->in.mac), etm_mode ? " (in ETM mode)" : "", (s->in.cipher && ssh_cipher_alg(s->in.cipher)->required_mac ? diff --git a/sshccp.c b/sshccp.c index 1193b1fe..78129336 100644 --- a/sshccp.c +++ b/sshccp.c @@ -938,12 +938,17 @@ static void poly_genresult(ssh2_mac *mac, unsigned char *blk) poly1305_finalise(&ctx->mac, blk); } +static const char *poly_text_name(ssh2_mac *mac) +{ + return "Poly1305"; +} + const ssh2_macalg ssh2_poly1305 = { poly_ssh2_new, poly_ssh2_free, poly_setkey, - poly_start, poly_genresult, + poly_start, poly_genresult, poly_text_name, "", "", /* Not selectable individually, just part of ChaCha20-Poly1305 */ - 16, 0, "Poly1305" + 16, 0, }; static ssh_cipher *ccp_new(const ssh_cipheralg *alg) diff --git a/sshmd5.c b/sshmd5.c index 36b4c89e..6f0974fc 100644 --- a/sshmd5.c +++ b/sshmd5.c @@ -376,10 +376,14 @@ void hmacmd5_do_hmac(struct hmacmd5_context *ctx, ssh2_mac_genresult(&ctx->mac, hmac); } +static const char *hmacmd5_text_name(ssh2_mac *mac) +{ + return "HMAC-MD5"; +} + const ssh2_macalg ssh_hmac_md5 = { hmacmd5_ssh2_new, hmacmd5_ssh2_free, hmacmd5_ssh2_setkey, - hmacmd5_start, hmacmd5_genresult, + hmacmd5_start, hmacmd5_genresult, hmacmd5_text_name, "hmac-md5", "hmac-md5-etm@openssh.com", 16, 16, - "HMAC-MD5" }; diff --git a/sshsh256.c b/sshsh256.c index f9fd4e0a..2bb059f4 100644 --- a/sshsh256.c +++ b/sshsh256.c @@ -330,12 +330,16 @@ static void hmacsha256_genresult(ssh2_mac *mac, unsigned char *hmac) SHA256_Final(&s, hmac); } +static const char *hmacsha256_text_name(ssh2_mac *mac) +{ + return "HMAC-SHA-256"; +} + const ssh2_macalg ssh_hmac_sha256 = { hmacsha256_new, hmacsha256_free, hmacsha256_key, - hmacsha256_start, hmacsha256_genresult, + hmacsha256_start, hmacsha256_genresult, hmacsha256_text_name, "hmac-sha2-256", "hmac-sha2-256-etm@openssh.com", 32, 32, - "HMAC-SHA-256" }; #ifdef COMPILER_SUPPORTS_SHA_NI diff --git a/sshsha.c b/sshsha.c index f41740f7..2b9c1c80 100644 --- a/sshsha.c +++ b/sshsha.c @@ -375,36 +375,52 @@ void hmac_sha1_simple(const void *key, int keylen, SHA_Final(&states[1], output); } +static const char *hmacsha1_text_name(ssh2_mac *mac) +{ + return "HMAC-SHA1"; +} + +static const char *hmacsha196_text_name(ssh2_mac *mac) +{ + return "HMAC-SHA1-96"; +} + +static const char *hmacsha1bug_text_name(ssh2_mac *mac) +{ + return "bug-compatible HMAC-SHA1"; +} + +static const char *hmacsha196bug_text_name(ssh2_mac *mac) +{ + return "bug-compatible HMAC-SHA1-96"; +} + const ssh2_macalg ssh_hmac_sha1 = { hmacsha1_new, hmacsha1_free, hmacsha1_key, - hmacsha1_start, hmacsha1_genresult, + hmacsha1_start, hmacsha1_genresult, hmacsha1_text_name, "hmac-sha1", "hmac-sha1-etm@openssh.com", 20, 20, - "HMAC-SHA1" }; const ssh2_macalg ssh_hmac_sha1_96 = { hmacsha1_new, hmacsha1_free, hmacsha1_key, - hmacsha1_start, hmacsha1_genresult, + hmacsha1_start, hmacsha1_genresult, hmacsha196_text_name, "hmac-sha1-96", "hmac-sha1-96-etm@openssh.com", 12, 20, - "HMAC-SHA1-96" }; const ssh2_macalg ssh_hmac_sha1_buggy = { hmacsha1_new, hmacsha1_free, hmacsha1_key, - hmacsha1_start, hmacsha1_genresult, + hmacsha1_start, hmacsha1_genresult, hmacsha1bug_text_name, "hmac-sha1", NULL, 20, 16, - "bug-compatible HMAC-SHA1" }; const ssh2_macalg ssh_hmac_sha1_96_buggy = { hmacsha1_new, hmacsha1_free, hmacsha1_key, - hmacsha1_start, hmacsha1_genresult, + hmacsha1_start, hmacsha1_genresult, hmacsha196bug_text_name, "hmac-sha1-96", NULL, 12, 16, - "bug-compatible HMAC-SHA1-96" }; #ifdef COMPILER_SUPPORTS_SHA_NI