mirror of
https://git.tartarus.org/simon/putty.git
synced 2025-01-09 17:38:00 +00:00
Make lots more algorithm structures globally visible.
Previously, lots of individual ssh2_cipheralg structures were declared static, and only available to the rest of the code via a smaller number of 'ssh2_ciphers' objects that wrapped them into lists. But I'm going to want to access individual ciphers directly in the testing system I'm currently working on, so I'm giving all those objects external linkage and declaring them in ssh.h. Also, I've made up an entirely new one, namely exposing MD5 as an instance of the general ssh_hashalg abstraction, which it has no need to be for the purposes of actually using it in SSH. But, again, this will let me treat it the same as all the other hashes in the test system. No functional change, for the moment.
This commit is contained in:
parent
f3295e0fb5
commit
84f98c5bf9
21
ssh.h
21
ssh.h
@ -864,12 +864,28 @@ struct ssh2_userkey {
|
||||
extern const struct ssh1_cipheralg ssh1_3des;
|
||||
extern const struct ssh1_cipheralg ssh1_des;
|
||||
extern const struct ssh1_cipheralg ssh1_blowfish;
|
||||
extern const struct ssh2_cipheralg ssh_3des_ssh2_ctr;
|
||||
extern const struct ssh2_cipheralg ssh_3des_ssh2;
|
||||
extern const struct ssh2_cipheralg ssh_des_ssh2;
|
||||
extern const struct ssh2_cipheralg ssh_des_sshcom_ssh2;
|
||||
extern const struct ssh2_cipheralg ssh_aes256_ctr;
|
||||
extern const struct ssh2_cipheralg ssh_aes256;
|
||||
extern const struct ssh2_cipheralg ssh_aes192_ctr;
|
||||
extern const struct ssh2_cipheralg ssh_aes192;
|
||||
extern const struct ssh2_cipheralg ssh_aes128_ctr;
|
||||
extern const struct ssh2_cipheralg ssh_aes128;
|
||||
extern const struct ssh2_cipheralg ssh_blowfish_ssh2_ctr;
|
||||
extern const struct ssh2_cipheralg ssh_blowfish_ssh2;
|
||||
extern const struct ssh2_cipheralg ssh_arcfour256_ssh2;
|
||||
extern const struct ssh2_cipheralg ssh_arcfour128_ssh2;
|
||||
extern const struct ssh2_cipheralg ssh2_chacha20_poly1305;
|
||||
extern const struct ssh2_ciphers ssh2_3des;
|
||||
extern const struct ssh2_ciphers ssh2_des;
|
||||
extern const struct ssh2_ciphers ssh2_aes;
|
||||
extern const struct ssh2_ciphers ssh2_blowfish;
|
||||
extern const struct ssh2_ciphers ssh2_arcfour;
|
||||
extern const struct ssh2_ciphers ssh2_ccp;
|
||||
extern const struct ssh_hashalg ssh_md5;
|
||||
extern const struct ssh_hashalg ssh_sha1;
|
||||
extern const struct ssh_hashalg ssh_sha256;
|
||||
extern const struct ssh_hashalg ssh_sha384;
|
||||
@ -879,6 +895,10 @@ extern const struct ssh_kexes ssh_diffiehellman_group14;
|
||||
extern const struct ssh_kexes ssh_diffiehellman_gex;
|
||||
extern const struct ssh_kexes ssh_gssk5_sha1_kex;
|
||||
extern const struct ssh_kexes ssh_rsa_kex;
|
||||
extern const struct ssh_kex ssh_ec_kex_curve25519;
|
||||
extern const struct ssh_kex ssh_ec_kex_nistp256;
|
||||
extern const struct ssh_kex ssh_ec_kex_nistp384;
|
||||
extern const struct ssh_kex ssh_ec_kex_nistp521;
|
||||
extern const struct ssh_kexes ssh_ecdh_kex;
|
||||
extern const ssh_keyalg ssh_dss;
|
||||
extern const ssh_keyalg ssh_rsa;
|
||||
@ -892,6 +912,7 @@ extern const struct ssh2_macalg ssh_hmac_sha1_buggy;
|
||||
extern const struct ssh2_macalg ssh_hmac_sha1_96;
|
||||
extern const struct ssh2_macalg ssh_hmac_sha1_96_buggy;
|
||||
extern const struct ssh2_macalg ssh_hmac_sha256;
|
||||
extern const struct ssh2_macalg ssh2_poly1305;
|
||||
extern const struct ssh_compression_alg ssh_zlib;
|
||||
|
||||
typedef struct AESContext AESContext;
|
||||
|
14
sshaes.c
14
sshaes.c
@ -1089,7 +1089,7 @@ static void aes_ssh2_sdctr_method(ssh2_cipher *cipher, void *blk, int len)
|
||||
aes_sdctr(blk, len, &ctx->context);
|
||||
}
|
||||
|
||||
static const struct ssh2_cipheralg ssh_aes128_ctr = {
|
||||
const struct ssh2_cipheralg ssh_aes128_ctr = {
|
||||
aes_ssh2_new, aes_ssh2_free, aes_ssh2_setiv, aes_ssh2_setkey,
|
||||
aes_ssh2_sdctr_method, aes_ssh2_sdctr_method, NULL, NULL,
|
||||
"aes128-ctr",
|
||||
@ -1097,7 +1097,7 @@ static const struct ssh2_cipheralg ssh_aes128_ctr = {
|
||||
NULL
|
||||
};
|
||||
|
||||
static const struct ssh2_cipheralg ssh_aes192_ctr = {
|
||||
const struct ssh2_cipheralg ssh_aes192_ctr = {
|
||||
aes_ssh2_new, aes_ssh2_free, aes_ssh2_setiv, aes_ssh2_setkey,
|
||||
aes_ssh2_sdctr_method, aes_ssh2_sdctr_method, NULL, NULL,
|
||||
"aes192-ctr",
|
||||
@ -1105,7 +1105,7 @@ static const struct ssh2_cipheralg ssh_aes192_ctr = {
|
||||
NULL
|
||||
};
|
||||
|
||||
static const struct ssh2_cipheralg ssh_aes256_ctr = {
|
||||
const struct ssh2_cipheralg ssh_aes256_ctr = {
|
||||
aes_ssh2_new, aes_ssh2_free, aes_ssh2_setiv, aes_ssh2_setkey,
|
||||
aes_ssh2_sdctr_method, aes_ssh2_sdctr_method, NULL, NULL,
|
||||
"aes256-ctr",
|
||||
@ -1113,7 +1113,7 @@ static const struct ssh2_cipheralg ssh_aes256_ctr = {
|
||||
NULL
|
||||
};
|
||||
|
||||
static const struct ssh2_cipheralg ssh_aes128 = {
|
||||
const struct ssh2_cipheralg ssh_aes128 = {
|
||||
aes_ssh2_new, aes_ssh2_free, aes_ssh2_setiv, aes_ssh2_setkey,
|
||||
aes_ssh2_encrypt, aes_ssh2_decrypt, NULL, NULL,
|
||||
"aes128-cbc",
|
||||
@ -1121,7 +1121,7 @@ static const struct ssh2_cipheralg ssh_aes128 = {
|
||||
NULL
|
||||
};
|
||||
|
||||
static const struct ssh2_cipheralg ssh_aes192 = {
|
||||
const struct ssh2_cipheralg ssh_aes192 = {
|
||||
aes_ssh2_new, aes_ssh2_free, aes_ssh2_setiv, aes_ssh2_setkey,
|
||||
aes_ssh2_encrypt, aes_ssh2_decrypt, NULL, NULL,
|
||||
"aes192-cbc",
|
||||
@ -1129,7 +1129,7 @@ static const struct ssh2_cipheralg ssh_aes192 = {
|
||||
NULL
|
||||
};
|
||||
|
||||
static const struct ssh2_cipheralg ssh_aes256 = {
|
||||
const struct ssh2_cipheralg ssh_aes256 = {
|
||||
aes_ssh2_new, aes_ssh2_free, aes_ssh2_setiv, aes_ssh2_setkey,
|
||||
aes_ssh2_encrypt, aes_ssh2_decrypt, NULL, NULL,
|
||||
"aes256-cbc",
|
||||
@ -1137,6 +1137,8 @@ static const struct ssh2_cipheralg ssh_aes256 = {
|
||||
NULL
|
||||
};
|
||||
|
||||
/* This cipher is just ssh_aes256 under a different protocol
|
||||
* identifier; we leave it 'static' because testcrypt won't need it */
|
||||
static const struct ssh2_cipheralg ssh_rijndael_lysator = {
|
||||
aes_ssh2_new, aes_ssh2_free, aes_ssh2_setiv, aes_ssh2_setkey,
|
||||
aes_ssh2_encrypt, aes_ssh2_decrypt, NULL, NULL,
|
||||
|
@ -679,7 +679,7 @@ const struct ssh1_cipheralg ssh1_blowfish = {
|
||||
8, "Blowfish-128 CBC"
|
||||
};
|
||||
|
||||
static const struct ssh2_cipheralg ssh_blowfish_ssh2 = {
|
||||
const struct ssh2_cipheralg ssh_blowfish_ssh2 = {
|
||||
blowfish_ssh2_new, blowfish_ssh2_free,
|
||||
blowfish_ssh2_setiv, blowfish_ssh2_setkey,
|
||||
blowfish_ssh2_encrypt_blk, blowfish_ssh2_decrypt_blk, NULL, NULL,
|
||||
@ -688,7 +688,7 @@ static const struct ssh2_cipheralg ssh_blowfish_ssh2 = {
|
||||
NULL
|
||||
};
|
||||
|
||||
static const struct ssh2_cipheralg ssh_blowfish_ssh2_ctr = {
|
||||
const struct ssh2_cipheralg ssh_blowfish_ssh2_ctr = {
|
||||
blowfish_ssh2_new, blowfish_ssh2_free,
|
||||
blowfish_ssh2_setiv, blowfish_ssh2_setkey,
|
||||
blowfish_ssh2_sdctr, blowfish_ssh2_sdctr, NULL, NULL,
|
||||
|
4
sshccp.c
4
sshccp.c
@ -938,7 +938,7 @@ static void poly_genresult(ssh2_mac *mac, unsigned char *blk)
|
||||
poly1305_finalise(&ctx->mac, blk);
|
||||
}
|
||||
|
||||
static const struct ssh2_macalg ssh2_poly1305 = {
|
||||
const struct ssh2_macalg ssh2_poly1305 = {
|
||||
poly_ssh2_new, poly_ssh2_free, poly_setkey,
|
||||
poly_start, poly_genresult,
|
||||
|
||||
@ -1026,7 +1026,7 @@ static void ccp_decrypt_length(ssh2_cipher *cipher, void *blk, int len,
|
||||
chacha20_decrypt(&ctx->a_cipher, blk, len);
|
||||
}
|
||||
|
||||
static const struct ssh2_cipheralg ssh2_chacha20_poly1305 = {
|
||||
const struct ssh2_cipheralg ssh2_chacha20_poly1305 = {
|
||||
|
||||
ccp_new,
|
||||
ccp_free,
|
||||
|
8
sshdes.c
8
sshdes.c
@ -1070,7 +1070,7 @@ void des_decrypt_xdmauth(const void *keydata, void *blk, int len)
|
||||
des_cbc_decrypt(blk, len, &dc);
|
||||
}
|
||||
|
||||
static const struct ssh2_cipheralg ssh_3des_ssh2 = {
|
||||
const struct ssh2_cipheralg ssh_3des_ssh2 = {
|
||||
des3_ssh2_new, des3_ssh2_free, des3_ssh2_setiv, des3_ssh2_setkey,
|
||||
des3_ssh2_encrypt_blk, des3_ssh2_decrypt_blk, NULL, NULL,
|
||||
"3des-cbc",
|
||||
@ -1078,7 +1078,7 @@ static const struct ssh2_cipheralg ssh_3des_ssh2 = {
|
||||
NULL
|
||||
};
|
||||
|
||||
static const struct ssh2_cipheralg ssh_3des_ssh2_ctr = {
|
||||
const struct ssh2_cipheralg ssh_3des_ssh2_ctr = {
|
||||
des3_ssh2_new, des3_ssh2_free, des3_ssh2_setiv, des3_ssh2_setkey,
|
||||
des3_ssh2_sdctr, des3_ssh2_sdctr, NULL, NULL,
|
||||
"3des-ctr",
|
||||
@ -1094,7 +1094,7 @@ static const struct ssh2_cipheralg ssh_3des_ssh2_ctr = {
|
||||
* apparently aren't the only people to do so, so we sigh
|
||||
* and implement it anyway.
|
||||
*/
|
||||
static const struct ssh2_cipheralg ssh_des_ssh2 = {
|
||||
const struct ssh2_cipheralg ssh_des_ssh2 = {
|
||||
des_ssh2_new, des_ssh2_free, des_ssh2_setiv, des_ssh2_setkey,
|
||||
des_ssh2_encrypt_blk, des_ssh2_decrypt_blk, NULL, NULL,
|
||||
"des-cbc",
|
||||
@ -1102,7 +1102,7 @@ static const struct ssh2_cipheralg ssh_des_ssh2 = {
|
||||
NULL
|
||||
};
|
||||
|
||||
static const struct ssh2_cipheralg ssh_des_sshcom_ssh2 = {
|
||||
const struct ssh2_cipheralg ssh_des_sshcom_ssh2 = {
|
||||
des_ssh2_new, des_ssh2_free, des_ssh2_setiv, des_ssh2_setkey,
|
||||
des_ssh2_encrypt_blk, des_ssh2_decrypt_blk, NULL, NULL,
|
||||
"des-cbc@ssh.com",
|
||||
|
8
sshecc.c
8
sshecc.c
@ -1396,7 +1396,7 @@ static const struct eckex_extra kex_extra_curve25519 = {
|
||||
ssh_ecdhkex_m_getpublic,
|
||||
ssh_ecdhkex_m_getkey,
|
||||
};
|
||||
static const struct ssh_kex ssh_ec_kex_curve25519 = {
|
||||
const struct ssh_kex ssh_ec_kex_curve25519 = {
|
||||
"curve25519-sha256@libssh.org", NULL, KEXTYPE_ECDH,
|
||||
&ssh_sha256, &kex_extra_curve25519,
|
||||
};
|
||||
@ -1408,7 +1408,7 @@ const struct eckex_extra kex_extra_nistp256 = {
|
||||
ssh_ecdhkex_w_getpublic,
|
||||
ssh_ecdhkex_w_getkey,
|
||||
};
|
||||
static const struct ssh_kex ssh_ec_kex_nistp256 = {
|
||||
const struct ssh_kex ssh_ec_kex_nistp256 = {
|
||||
"ecdh-sha2-nistp256", NULL, KEXTYPE_ECDH,
|
||||
&ssh_sha256, &kex_extra_nistp256,
|
||||
};
|
||||
@ -1420,7 +1420,7 @@ const struct eckex_extra kex_extra_nistp384 = {
|
||||
ssh_ecdhkex_w_getpublic,
|
||||
ssh_ecdhkex_w_getkey,
|
||||
};
|
||||
static const struct ssh_kex ssh_ec_kex_nistp384 = {
|
||||
const struct ssh_kex ssh_ec_kex_nistp384 = {
|
||||
"ecdh-sha2-nistp384", NULL, KEXTYPE_ECDH,
|
||||
&ssh_sha384, &kex_extra_nistp384,
|
||||
};
|
||||
@ -1432,7 +1432,7 @@ const struct eckex_extra kex_extra_nistp521 = {
|
||||
ssh_ecdhkex_w_getpublic,
|
||||
ssh_ecdhkex_w_getkey,
|
||||
};
|
||||
static const struct ssh_kex ssh_ec_kex_nistp521 = {
|
||||
const struct ssh_kex ssh_ec_kex_nistp521 = {
|
||||
"ecdh-sha2-nistp521", NULL, KEXTYPE_ECDH,
|
||||
&ssh_sha512, &kex_extra_nistp521,
|
||||
};
|
||||
|
51
sshmd5.c
51
sshmd5.c
@ -211,6 +211,57 @@ void MD5Simple(void const *p, unsigned len, unsigned char output[16])
|
||||
smemclr(&s, sizeof(s));
|
||||
}
|
||||
|
||||
/* ----------------------------------------------------------------------
|
||||
* Thin abstraction for things where hashes are pluggable.
|
||||
*/
|
||||
|
||||
struct md5_hash {
|
||||
struct MD5Context state;
|
||||
ssh_hash hash;
|
||||
};
|
||||
|
||||
static ssh_hash *md5_new(const struct ssh_hashalg *alg)
|
||||
{
|
||||
struct md5_hash *h = snew(struct md5_hash);
|
||||
MD5Init(&h->state);
|
||||
h->hash.vt = alg;
|
||||
BinarySink_DELEGATE_INIT(&h->hash, &h->state);
|
||||
return &h->hash;
|
||||
}
|
||||
|
||||
static ssh_hash *md5_copy(ssh_hash *hashold)
|
||||
{
|
||||
struct md5_hash *hold, *hnew;
|
||||
ssh_hash *hashnew = md5_new(hashold->vt);
|
||||
|
||||
hold = container_of(hashold, struct md5_hash, hash);
|
||||
hnew = container_of(hashnew, struct md5_hash, hash);
|
||||
|
||||
hnew->state = hold->state;
|
||||
BinarySink_COPIED(&hnew->state);
|
||||
|
||||
return hashnew;
|
||||
}
|
||||
|
||||
static void md5_free(ssh_hash *hash)
|
||||
{
|
||||
struct md5_hash *h = container_of(hash, struct md5_hash, hash);
|
||||
|
||||
smemclr(h, sizeof(*h));
|
||||
sfree(h);
|
||||
}
|
||||
|
||||
static void md5_final(ssh_hash *hash, unsigned char *output)
|
||||
{
|
||||
struct md5_hash *h = container_of(hash, struct md5_hash, hash);
|
||||
MD5Final(output, &h->state);
|
||||
md5_free(hash);
|
||||
}
|
||||
|
||||
const struct ssh_hashalg ssh_md5 = {
|
||||
md5_new, md5_copy, md5_final, md5_free, 16, "MD5"
|
||||
};
|
||||
|
||||
/* ----------------------------------------------------------------------
|
||||
* The above is the MD5 algorithm itself. Now we implement the
|
||||
* HMAC wrapper on it.
|
||||
|
Loading…
Reference in New Issue
Block a user