~ubuntu-branches/debian/squeeze/putty/squeeze

« back to all changes in this revision

Viewing changes to sshaes.c

  • Committer: Bazaar Package Importer
  • Author(s): Colin Watson
  • Date: 2008-05-28 09:28:32 UTC
  • mfrom: (4.1.4 hardy)
  • Revision ID: james.westby@ubuntu.com-20080528092832-88epkb3d4s1zsw61
Tags: 0.60-3
* Move putty to Applications/Network/Communication menu sub-section.
* Use dh_desktop.

Show diffs side-by-side

added added

removed removed

Lines of Context:
38
38
 
39
39
#define mulby2(x) ( ((x&0x7F) << 1) ^ (x & 0x80 ? 0x1B : 0) )
40
40
 
41
 
#define GET_32BIT_MSB_FIRST(cp) \
42
 
  (((unsigned long)(unsigned char)(cp)[3]) | \
43
 
  ((unsigned long)(unsigned char)(cp)[2] << 8) | \
44
 
  ((unsigned long)(unsigned char)(cp)[1] << 16) | \
45
 
  ((unsigned long)(unsigned char)(cp)[0] << 24))
46
 
 
47
 
#define PUT_32BIT_MSB_FIRST(cp, value) do { \
48
 
  (cp)[3] = (value); \
49
 
  (cp)[2] = (value) >> 8; \
50
 
  (cp)[1] = (value) >> 16; \
51
 
  (cp)[0] = (value) >> 24; } while (0)
52
 
 
53
41
typedef struct AESContext AESContext;
54
42
 
55
43
struct AESContext {
1083
1071
    memcpy(ctx->iv, iv, sizeof(iv));
1084
1072
}
1085
1073
 
 
1074
static void aes_sdctr(unsigned char *blk, int len, AESContext *ctx)
 
1075
{
 
1076
    word32 iv[4], b[4], tmp;
 
1077
    int i;
 
1078
 
 
1079
    assert((len & 15) == 0);
 
1080
 
 
1081
    memcpy(iv, ctx->iv, sizeof(iv));
 
1082
 
 
1083
    while (len > 0) {
 
1084
        memcpy(b, iv, sizeof(b));
 
1085
        aes_encrypt(ctx, b);
 
1086
        for (i = 0; i < 4; i++) {
 
1087
            tmp = GET_32BIT_MSB_FIRST(blk + 4 * i);
 
1088
            PUT_32BIT_MSB_FIRST(blk + 4 * i, tmp ^ b[i]);
 
1089
        }
 
1090
        for (i = 3; i >= 0; i--)
 
1091
            if ((iv[i] = (iv[i] + 1) & 0xffffffff) != 0)
 
1092
                break;
 
1093
        blk += 16;
 
1094
        len -= 16;
 
1095
    }
 
1096
 
 
1097
    memcpy(ctx->iv, iv, sizeof(iv));
 
1098
}
 
1099
 
1086
1100
static void *aes_make_context(void)
1087
1101
{
1088
1102
    return snew(AESContext);
1131
1145
    aes_decrypt_cbc(blk, len, ctx);
1132
1146
}
1133
1147
 
 
1148
static void aes_ssh2_sdctr(void *handle, unsigned char *blk, int len)
 
1149
{
 
1150
    AESContext *ctx = (AESContext *)handle;
 
1151
    aes_sdctr(blk, len, ctx);
 
1152
}
 
1153
 
1134
1154
void aes256_encrypt_pubkey(unsigned char *key, unsigned char *blk, int len)
1135
1155
{
1136
1156
    AESContext ctx;
1149
1169
    memset(&ctx, 0, sizeof(ctx));
1150
1170
}
1151
1171
 
 
1172
static const struct ssh2_cipher ssh_aes128_ctr = {
 
1173
    aes_make_context, aes_free_context, aes_iv, aes128_key,
 
1174
    aes_ssh2_sdctr, aes_ssh2_sdctr,
 
1175
    "aes128-ctr",
 
1176
    16, 128, 0, "AES-128 SDCTR"
 
1177
};
 
1178
 
 
1179
static const struct ssh2_cipher ssh_aes192_ctr = {
 
1180
    aes_make_context, aes_free_context, aes_iv, aes192_key,
 
1181
    aes_ssh2_sdctr, aes_ssh2_sdctr,
 
1182
    "aes192-ctr",
 
1183
    16, 192, 0, "AES-192 SDCTR"
 
1184
};
 
1185
 
 
1186
static const struct ssh2_cipher ssh_aes256_ctr = {
 
1187
    aes_make_context, aes_free_context, aes_iv, aes256_key,
 
1188
    aes_ssh2_sdctr, aes_ssh2_sdctr,
 
1189
    "aes256-ctr",
 
1190
    16, 256, 0, "AES-256 SDCTR"
 
1191
};
 
1192
 
1152
1193
static const struct ssh2_cipher ssh_aes128 = {
1153
1194
    aes_make_context, aes_free_context, aes_iv, aes128_key,
1154
1195
    aes_ssh2_encrypt_blk, aes_ssh2_decrypt_blk,
1155
1196
    "aes128-cbc",
1156
 
    16, 128, "AES-128"
 
1197
    16, 128, SSH_CIPHER_IS_CBC, "AES-128 CBC"
1157
1198
};
1158
1199
 
1159
1200
static const struct ssh2_cipher ssh_aes192 = {
1160
1201
    aes_make_context, aes_free_context, aes_iv, aes192_key,
1161
1202
    aes_ssh2_encrypt_blk, aes_ssh2_decrypt_blk,
1162
1203
    "aes192-cbc",
1163
 
    16, 192, "AES-192"
 
1204
    16, 192, SSH_CIPHER_IS_CBC, "AES-192 CBC"
1164
1205
};
1165
1206
 
1166
1207
static const struct ssh2_cipher ssh_aes256 = {
1167
1208
    aes_make_context, aes_free_context, aes_iv, aes256_key,
1168
1209
    aes_ssh2_encrypt_blk, aes_ssh2_decrypt_blk,
1169
1210
    "aes256-cbc",
1170
 
    16, 256, "AES-256"
1171
 
};
1172
 
 
1173
 
static const struct ssh2_cipher ssh_rijndael128 = {
1174
 
    aes_make_context, aes_free_context, aes_iv, aes128_key,
1175
 
    aes_ssh2_encrypt_blk, aes_ssh2_decrypt_blk,
1176
 
    "rijndael128-cbc",
1177
 
    16, 128, "AES-128"
1178
 
};
1179
 
 
1180
 
static const struct ssh2_cipher ssh_rijndael192 = {
1181
 
    aes_make_context, aes_free_context, aes_iv, aes192_key,
1182
 
    aes_ssh2_encrypt_blk, aes_ssh2_decrypt_blk,
1183
 
    "rijndael192-cbc",
1184
 
    16, 192, "AES-192"
1185
 
};
1186
 
 
1187
 
static const struct ssh2_cipher ssh_rijndael256 = {
1188
 
    aes_make_context, aes_free_context, aes_iv, aes256_key,
1189
 
    aes_ssh2_encrypt_blk, aes_ssh2_decrypt_blk,
1190
 
    "rijndael256-cbc",
1191
 
    16, 256, "AES-256"
 
1211
    16, 256, SSH_CIPHER_IS_CBC, "AES-256 CBC"
1192
1212
};
1193
1213
 
1194
1214
static const struct ssh2_cipher ssh_rijndael_lysator = {
1195
1215
    aes_make_context, aes_free_context, aes_iv, aes256_key,
1196
1216
    aes_ssh2_encrypt_blk, aes_ssh2_decrypt_blk,
1197
1217
    "rijndael-cbc@lysator.liu.se",
1198
 
    16, 256, "AES-256"
 
1218
    16, 256, SSH_CIPHER_IS_CBC, "AES-256 CBC"
1199
1219
};
1200
1220
 
1201
1221
static const struct ssh2_cipher *const aes_list[] = {
 
1222
    &ssh_aes256_ctr,
1202
1223
    &ssh_aes256,
1203
 
    &ssh_rijndael256,
1204
1224
    &ssh_rijndael_lysator,
 
1225
    &ssh_aes192_ctr,
1205
1226
    &ssh_aes192,
1206
 
    &ssh_rijndael192,
 
1227
    &ssh_aes128_ctr,
1207
1228
    &ssh_aes128,
1208
 
    &ssh_rijndael128,
1209
1229
};
1210
1230
 
1211
1231
const struct ssh2_ciphers ssh2_aes = {