Revision bc17cc01 libavutil/des.c

View differences:

libavutil/des.c
293 293
#endif
294 294

  
295 295
int av_des_init(AVDES *d, const uint8_t *key, int key_bits, int decrypt) {
296
    if (key_bits != 64)
296
    if (key_bits != 64 && key_bits != 192)
297 297
        return -1;
298
    d->triple_des = 0;
298
    d->triple_des = key_bits > 64;
299 299
    gen_roundkeys(d->round_keys[0], AV_RB64(key));
300
    if (d->triple_des) {
301
        gen_roundkeys(d->round_keys[1], AV_RB64(key +  8));
302
        gen_roundkeys(d->round_keys[2], AV_RB64(key + 16));
303
    }
300 304
    return 0;
301 305
}
302 306

  
......
306 310
        uint64_t dst_val;
307 311
        uint64_t src_val = src ? be2me_64(*(const uint64_t *)src) : 0;
308 312
        if (decrypt) {
313
            if (d->triple_des) {
314
                src_val = des_encdec(src_val, d->round_keys[2], 1);
315
                src_val = des_encdec(src_val, d->round_keys[1], 0);
316
            }
309 317
            dst_val = des_encdec(src_val, d->round_keys[0], 1) ^ iv_val;
310 318
            iv_val = iv ? src_val : 0;
311 319
        } else {
312 320
            dst_val = des_encdec(src_val ^ iv_val, d->round_keys[0], 0);
321
            if (d->triple_des) {
322
                dst_val = des_encdec(dst_val, d->round_keys[1], 1);
323
                dst_val = des_encdec(dst_val, d->round_keys[2], 0);
324
            }
313 325
            iv_val = iv ? dst_val : 0;
314 326
        }
315 327
        *(uint64_t *)dst = be2me_64(dst_val);

Also available in: Unified diff