~ubuntu-branches/ubuntu/utopic/dropbear/utopic-proposed

« back to all changes in this revision

Viewing changes to libtomcrypt/src/ciphers/twofish/twofish.c

  • Committer: Bazaar Package Importer
  • Author(s): Gerrit Pape, Matt Johnston, Gerrit Pape
  • Date: 2008-03-27 20:08:06 UTC
  • mfrom: (1.4.1 upstream) (9 hardy)
  • mto: This revision was merged to the branch mainline in revision 10.
  • Revision ID: james.westby@ubuntu.com-20080327200806-c1hhdgt3ht2gk496
Tags: 0.51-1
[ Matt Johnston ]
* New upstream release.
  - Wait until a process exits before the server closes a connection,
    so that an exit code can be sent. This fixes problems with exit
    codes not being returned, which could cause scp to fail (closes:
    #448397, #472483).

[ Gerrit Pape ]
* debian/dropbear.postinst: don't print an error message if the
  update-service program is not installed (thx Matt).

Show diffs side-by-side

added added

removed removed

Lines of Context:
6
6
 * The library is free for all purposes without any express
7
7
 * guarantee it works.
8
8
 *
9
 
 * Tom St Denis, tomstdenis@gmail.com, http://libtomcrypt.org
 
9
 * Tom St Denis, tomstdenis@gmail.com, http://libtomcrypt.com
10
10
 */
11
11
 
12
12
 /** 
35
35
    &twofish_test,
36
36
    &twofish_done,
37
37
    &twofish_keysize,
38
 
    NULL, NULL, NULL, NULL, NULL, NULL, NULL
 
38
    NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL
39
39
};
40
40
 
41
41
/* the two polynomials */
414
414
   /* make the sboxes (large ram variant) */
415
415
   if (k == 2) {
416
416
        for (x = 0; x < 256; x++) {
417
 
           tmpx0 = sbox(0, x);
418
 
           tmpx1 = sbox(1, x);
 
417
           tmpx0 = (unsigned char)sbox(0, x);
 
418
           tmpx1 = (unsigned char)sbox(1, x);
419
419
           skey->twofish.S[0][x] = mds_column_mult(sbox(1, (sbox(0, tmpx0 ^ S[0]) ^ S[4])),0);
420
420
           skey->twofish.S[1][x] = mds_column_mult(sbox(0, (sbox(0, tmpx1 ^ S[1]) ^ S[5])),1);
421
421
           skey->twofish.S[2][x] = mds_column_mult(sbox(1, (sbox(1, tmpx0 ^ S[2]) ^ S[6])),2);
423
423
        }
424
424
   } else if (k == 3) {
425
425
        for (x = 0; x < 256; x++) {
426
 
           tmpx0 = sbox(0, x);
427
 
           tmpx1 = sbox(1, x);
 
426
           tmpx0 = (unsigned char)sbox(0, x);
 
427
           tmpx1 = (unsigned char)sbox(1, x);
428
428
           skey->twofish.S[0][x] = mds_column_mult(sbox(1, (sbox(0, sbox(0, tmpx1 ^ S[0]) ^ S[4]) ^ S[8])),0);
429
429
           skey->twofish.S[1][x] = mds_column_mult(sbox(0, (sbox(0, sbox(1, tmpx1 ^ S[1]) ^ S[5]) ^ S[9])),1);
430
430
           skey->twofish.S[2][x] = mds_column_mult(sbox(1, (sbox(1, sbox(0, tmpx0 ^ S[2]) ^ S[6]) ^ S[10])),2);
432
432
        }
433
433
   } else {
434
434
        for (x = 0; x < 256; x++) {
435
 
           tmpx0 = sbox(0, x);
436
 
           tmpx1 = sbox(1, x);
 
435
           tmpx0 = (unsigned char)sbox(0, x);
 
436
           tmpx1 = (unsigned char)sbox(1, x);
437
437
           skey->twofish.S[0][x] = mds_column_mult(sbox(1, (sbox(0, sbox(0, sbox(1, tmpx1 ^ S[0]) ^ S[4]) ^ S[8]) ^ S[12])),0);
438
438
           skey->twofish.S[1][x] = mds_column_mult(sbox(0, (sbox(0, sbox(1, sbox(1, tmpx0 ^ S[1]) ^ S[5]) ^ S[9]) ^ S[13])),1);
439
439
           skey->twofish.S[2][x] = mds_column_mult(sbox(1, (sbox(1, sbox(0, sbox(0, tmpx0 ^ S[2]) ^ S[6]) ^ S[10]) ^ S[14])),2);
467
467
  @param pt The input plaintext (16 bytes)
468
468
  @param ct The output ciphertext (16 bytes)
469
469
  @param skey The key as scheduled
 
470
  @return CRYPT_OK if successful
470
471
*/
471
472
#ifdef LTC_CLEAN_STACK
472
 
static void _twofish_ecb_encrypt(const unsigned char *pt, unsigned char *ct, symmetric_key *skey)
 
473
static int _twofish_ecb_encrypt(const unsigned char *pt, unsigned char *ct, symmetric_key *skey)
473
474
#else
474
 
void twofish_ecb_encrypt(const unsigned char *pt, unsigned char *ct, symmetric_key *skey)
 
475
int twofish_ecb_encrypt(const unsigned char *pt, unsigned char *ct, symmetric_key *skey)
475
476
#endif
476
477
{
477
478
    ulong32 a,b,c,d,ta,tb,tc,td,t1,t2, *k;
521
522
    /* store output */
522
523
    STORE32L(ta,&ct[0]); STORE32L(tb,&ct[4]);
523
524
    STORE32L(tc,&ct[8]); STORE32L(td,&ct[12]);
 
525
 
 
526
    return CRYPT_OK;
524
527
}
525
528
 
526
529
#ifdef LTC_CLEAN_STACK
527
 
void twofish_ecb_encrypt(const unsigned char *pt, unsigned char *ct, symmetric_key *skey)
 
530
int twofish_ecb_encrypt(const unsigned char *pt, unsigned char *ct, symmetric_key *skey)
528
531
{
529
 
   _twofish_ecb_encrypt(pt, ct, skey);
 
532
   int err = _twofish_ecb_encrypt(pt, ct, skey);
530
533
   burn_stack(sizeof(ulong32) * 10 + sizeof(int));
 
534
   return err;
531
535
}
532
536
#endif
533
537
 
536
540
  @param ct The input ciphertext (16 bytes)
537
541
  @param pt The output plaintext (16 bytes)
538
542
  @param skey The key as scheduled 
 
543
  @return CRYPT_OK if successful
539
544
*/
540
545
#ifdef LTC_CLEAN_STACK
541
 
static void _twofish_ecb_decrypt(const unsigned char *ct, unsigned char *pt, symmetric_key *skey)
 
546
static int _twofish_ecb_decrypt(const unsigned char *ct, unsigned char *pt, symmetric_key *skey)
542
547
#else
543
 
void twofish_ecb_decrypt(const unsigned char *ct, unsigned char *pt, symmetric_key *skey)
 
548
int twofish_ecb_decrypt(const unsigned char *ct, unsigned char *pt, symmetric_key *skey)
544
549
#endif
545
550
{
546
551
    ulong32 a,b,c,d,ta,tb,tc,td,t1,t2, *k;
593
598
    /* store */
594
599
    STORE32L(a, &pt[0]); STORE32L(b, &pt[4]);
595
600
    STORE32L(c, &pt[8]); STORE32L(d, &pt[12]);
 
601
    return CRYPT_OK;
596
602
}
597
603
 
598
604
#ifdef LTC_CLEAN_STACK
599
 
void twofish_ecb_decrypt(const unsigned char *ct, unsigned char *pt, symmetric_key *skey)
 
605
int twofish_ecb_decrypt(const unsigned char *ct, unsigned char *pt, symmetric_key *skey)
600
606
{
601
 
   _twofish_ecb_decrypt(ct, pt, skey);
 
607
   int err =_twofish_ecb_decrypt(ct, pt, skey);
602
608
   burn_stack(sizeof(ulong32) * 10 + sizeof(int));
 
609
   return err;
603
610
}
604
611
#endif
605
612
 
656
663
    }
657
664
    twofish_ecb_encrypt(tests[i].pt, tmp[0], &key);
658
665
    twofish_ecb_decrypt(tmp[0], tmp[1], &key);
659
 
    if (memcmp(tmp[0], tests[i].ct, 16) != 0 || memcmp(tmp[1], tests[i].pt, 16) != 0) {
 
666
    if (XMEMCMP(tmp[0], tests[i].ct, 16) != 0 || XMEMCMP(tmp[1], tests[i].pt, 16) != 0) {
 
667
#if 0
 
668
       printf("Twofish failed test %d, %d, %d\n", i, XMEMCMP(tmp[0], tests[i].ct, 16), XMEMCMP(tmp[1], tests[i].pt, 16));
 
669
#endif
660
670
       return CRYPT_FAIL_TESTVECTOR;
661
671
    }
662
672
      /* now see if we can encrypt all zero bytes 1000 times, decrypt and come back where we started */
704
714
 
705
715
 
706
716
/* $Source: /cvs/libtom/libtomcrypt/src/ciphers/twofish/twofish.c,v $ */
707
 
/* $Revision: 1.8 $ */
708
 
/* $Date: 2005/05/05 14:35:58 $ */
 
717
/* $Revision: 1.14 $ */
 
718
/* $Date: 2006/12/04 21:34:03 $ */