mirror of
https://git.tartarus.org/simon/putty.git
synced 2025-07-03 12:32:47 -05:00
Change vtable defs to use C99 designated initialisers.
This is a sweeping change applied across the whole code base by a spot of Emacs Lisp. Now, everywhere I declare a vtable filled with function pointers (and the occasional const data member), all the members of the vtable structure are initialised by name using the '.fieldname = value' syntax introduced in C99. We were already using this syntax for a handful of things in the new key-generation progress report system, so it's not new to the code base as a whole. The advantage is that now, when a vtable only declares a subset of the available fields, I can initialise the rest to NULL or zero just by leaving them out. This is most dramatic in a couple of the outlying vtables in things like psocks (which has a ConnectionLayerVtable containing only one non-NULL method), but less dramatically, it means that the new 'flags' field in BackendVtable can be completely left out of every backend definition except for the SUPDUP one which defines it to a nonzero value. Similarly, the test_for_upstream method only used by SSH doesn't have to be mentioned in the rest of the backends; network Plugs for listening sockets don't have to explicitly null out 'receive' and 'sent', and vice versa for 'accepting', and so on. While I'm at it, I've normalised the declarations so they don't use the unnecessarily verbose 'struct' keyword. Also a handful of them weren't const; now they are.
This commit is contained in:
45
sshccp.c
45
sshccp.c
@ -944,11 +944,17 @@ static const char *poly_text_name(ssh2_mac *mac)
|
||||
}
|
||||
|
||||
const ssh2_macalg ssh2_poly1305 = {
|
||||
poly_ssh2_new, poly_ssh2_free, poly_setkey,
|
||||
poly_start, poly_genresult, poly_text_name,
|
||||
|
||||
"", "", /* Not selectable individually, just part of ChaCha20-Poly1305 */
|
||||
16, 0,
|
||||
.new = poly_ssh2_new,
|
||||
.free = poly_ssh2_free,
|
||||
.setkey = poly_setkey,
|
||||
.start = poly_start,
|
||||
.genresult = poly_genresult,
|
||||
.text_name = poly_text_name,
|
||||
.name = "",
|
||||
.etm_name = "", /* Not selectable individually, just part of
|
||||
* ChaCha20-Poly1305 */
|
||||
.len = 16,
|
||||
.keylen = 0,
|
||||
};
|
||||
|
||||
static ssh_cipher *ccp_new(const ssh_cipheralg *alg)
|
||||
@ -1032,20 +1038,21 @@ static void ccp_decrypt_length(ssh_cipher *cipher, void *blk, int len,
|
||||
}
|
||||
|
||||
const ssh_cipheralg ssh2_chacha20_poly1305 = {
|
||||
|
||||
ccp_new,
|
||||
ccp_free,
|
||||
ccp_iv,
|
||||
ccp_key,
|
||||
ccp_encrypt,
|
||||
ccp_decrypt,
|
||||
ccp_encrypt_length,
|
||||
ccp_decrypt_length,
|
||||
|
||||
"chacha20-poly1305@openssh.com",
|
||||
1, 512, 64, SSH_CIPHER_SEPARATE_LENGTH, "ChaCha20",
|
||||
|
||||
&ssh2_poly1305
|
||||
.new = ccp_new,
|
||||
.free = ccp_free,
|
||||
.setiv = ccp_iv,
|
||||
.setkey = ccp_key,
|
||||
.encrypt = ccp_encrypt,
|
||||
.decrypt = ccp_decrypt,
|
||||
.encrypt_length = ccp_encrypt_length,
|
||||
.decrypt_length = ccp_decrypt_length,
|
||||
.ssh2_id = "chacha20-poly1305@openssh.com",
|
||||
.blksize = 1,
|
||||
.real_keybits = 512,
|
||||
.padded_keybytes = 64,
|
||||
.flags = SSH_CIPHER_SEPARATE_LENGTH,
|
||||
.text_name = "ChaCha20",
|
||||
.required_mac = &ssh2_poly1305,
|
||||
};
|
||||
|
||||
static const ssh_cipheralg *const ccp_list[] = {
|
||||
|
Reference in New Issue
Block a user