Turn ssh2_mac's text_name field into a method.

This allows a MAC implementation to construct its textual name at run
time. Nothing yet uses that flexibility, though.
This commit is contained in:
Simon Tatham 2019-01-20 11:32:26 +00:00
Родитель 836a75ba69
Коммит 1df39eb0a4
6 изменённых файлов: 47 добавлений и 17 удалений

3
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

Просмотреть файл

@ -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 ?

Просмотреть файл

@ -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)

Просмотреть файл

@ -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"
};

Просмотреть файл

@ -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

Просмотреть файл

@ -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