X-Git-Url: https://git.distorted.org.uk/u/mdw/putty/blobdiff_plain/8479e33ca623ad057fadf5b48c0638f42d9b4520..6292bb300bcc49b3e8d66510b08f9b06096ee8b4:/sshaes.c diff --git a/sshaes.c b/sshaes.c index d6a27663..361cc648 100644 --- a/sshaes.c +++ b/sshaes.c @@ -32,8 +32,6 @@ #include "ssh.h" -typedef unsigned int word32; - #define MAX_NR 14 /* max no of rounds */ #define MAX_NK 8 /* max no of words in input key */ #define MAX_NB 8 /* max no of words in cipher blk */ @@ -1023,8 +1021,21 @@ static void aes_ssh2_decrypt_blk(unsigned char *blk, int len) { aes_decrypt_cbc(blk, len, &scctx); } -struct ssh_cipher ssh_aes128_ssh2 = { - NULL, +void aes256_encrypt_pubkey(unsigned char *key, unsigned char *blk, int len) { + AESContext ctx; + aes_setup(&ctx, 16, key, 32); + memset(ctx.iv, 0, sizeof(ctx.iv)); + aes_encrypt_cbc(blk, len, &ctx); +} + +void aes256_decrypt_pubkey(unsigned char *key, unsigned char *blk, int len) { + AESContext ctx; + aes_setup(&ctx, 16, key, 32); + memset(ctx.iv, 0, sizeof(ctx.iv)); + aes_decrypt_cbc(blk, len, &ctx); +} + +static const struct ssh2_cipher ssh_aes128 = { aes_csiv, aes128_cskey, aes_sciv, aes128_sckey, aes_ssh2_encrypt_blk, @@ -1033,8 +1044,7 @@ struct ssh_cipher ssh_aes128_ssh2 = { 16, 128 }; -struct ssh_cipher ssh_aes192_ssh2 = { - NULL, +static const struct ssh2_cipher ssh_aes192 = { aes_csiv, aes192_cskey, aes_sciv, aes192_sckey, aes_ssh2_encrypt_blk, @@ -1043,8 +1053,7 @@ struct ssh_cipher ssh_aes192_ssh2 = { 16, 192 }; -struct ssh_cipher ssh_aes256_ssh2 = { - NULL, +static const struct ssh2_cipher ssh_aes256 = { aes_csiv, aes256_cskey, aes_sciv, aes256_sckey, aes_ssh2_encrypt_blk, @@ -1053,31 +1062,53 @@ struct ssh_cipher ssh_aes256_ssh2 = { 16, 256 }; -#ifdef TESTMODE +static const struct ssh2_cipher ssh_rijndael128 = { + aes_csiv, aes128_cskey, + aes_sciv, aes128_sckey, + aes_ssh2_encrypt_blk, + aes_ssh2_decrypt_blk, + "rijndael128-cbc", + 16, 128 +}; -#include +static const struct ssh2_cipher ssh_rijndael192 = { + aes_csiv, aes192_cskey, + aes_sciv, aes192_sckey, + aes_ssh2_encrypt_blk, + aes_ssh2_decrypt_blk, + "rijndael192-cbc", + 16, 192 +}; -int main(void) { - AESContext c; - static unsigned char key[32] = {}; - word32 block[32]; - int i, j, k; +static const struct ssh2_cipher ssh_rijndael256 = { + aes_csiv, aes256_cskey, + aes_sciv, aes256_sckey, + aes_ssh2_encrypt_blk, + aes_ssh2_decrypt_blk, + "rijndael256-cbc", + 16, 256 +}; - for (i = 16; i <= 32; i += 8) { - for (j = 16; j <= 32; j += 8) { - printf("b%d, k%d: ", i, j); - fflush(stdout); - aes_setup(&c, i, key, j); - memset(block, 0, sizeof(block)); - aes_encrypt(&c, block); - aes_decrypt(&c, block); - for (k = 0; k < i/4; k++) - printf("%08x ", block[k]); - printf("\n"); - } - } +static const struct ssh2_cipher ssh_rijndael_lysator = { + aes_csiv, aes256_cskey, + aes_sciv, aes256_sckey, + aes_ssh2_encrypt_blk, + aes_ssh2_decrypt_blk, + "rijndael-cbc@lysator.liu.se", + 16, 256 +}; - return 0; -} +static const struct ssh2_cipher *const aes_list[] = { + &ssh_aes256, + &ssh_rijndael256, + &ssh_rijndael_lysator, + &ssh_aes192, + &ssh_rijndael192, + &ssh_aes128, + &ssh_rijndael128, +}; -#endif +const struct ssh2_ciphers ssh2_aes = { + sizeof(aes_list) / sizeof(*aes_list), + aes_list +};