diff libtomcrypt/src/ciphers/rc6.c @ 1471:6dba84798cd5

Update to libtomcrypt 1.18.1, merged with Dropbear changes
author Matt Johnston <matt@ucc.asn.au>
date Fri, 09 Feb 2018 21:44:05 +0800
parents f849a5ca2efc
children
line wrap: on
line diff
--- a/libtomcrypt/src/ciphers/rc6.c	Thu Feb 08 23:11:40 2018 +0800
+++ b/libtomcrypt/src/ciphers/rc6.c	Fri Feb 09 21:44:05 2018 +0800
@@ -5,13 +5,11 @@
  *
  * The library is free for all purposes without any express
  * guarantee it works.
- *
- * Tom St Denis, [email protected], http://libtom.org
  */
 
 /**
    @file rc6.c
-   LTC_RC6 code by Tom St Denis 
+   LTC_RC6 code by Tom St Denis
 */
 #include "tomcrypt.h"
 
@@ -28,7 +26,7 @@
     &rc6_test,
     &rc6_done,
     &rc6_keysize,
-    NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL
+    NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL
 };
 
 static const ulong32 stab[44] = {
@@ -59,7 +57,7 @@
     LTC_ARGCHK(skey != NULL);
 
     /* test parameters */
-    if (num_rounds != 0 && num_rounds != 20) { 
+    if (num_rounds != 0 && num_rounds != 20) {
        return CRYPT_INVALID_ROUNDS;
     }
 
@@ -69,7 +67,7 @@
     }
 
     /* copy the key into the L array */
-    for (A = i = j = 0; i < (ulong32)keylen; ) { 
+    for (A = i = j = 0; i < (ulong32)keylen; ) {
         A = (A << 8) | ((ulong32)(key[i++] & 255));
         if (!(i & 3)) {
            L[j++] = BSWAP(A);
@@ -78,9 +76,9 @@
     }
 
     /* handle odd sized keys */
-    if (keylen & 3) { 
-       A <<= (8 * (4 - (keylen&3))); 
-       L[j++] = BSWAP(A); 
+    if (keylen & 3) {
+       A <<= (8 * (4 - (keylen&3)));
+       L[j++] = BSWAP(A);
     }
 
     /* setup the S array */
@@ -89,15 +87,15 @@
     /* mix buffer */
     s = 3 * MAX(44, j);
     l = j;
-    for (A = B = i = j = v = 0; v < s; v++) { 
+    for (A = B = i = j = v = 0; v < s; v++) {
         A = S[i] = ROLc(S[i] + A + B, 3);
         B = L[j] = ROL(L[j] + A + B, (A+B));
         if (++i == 44) { i = 0; }
         if (++j == l)  { j = 0; }
     }
-    
+
     /* copy to key */
-    for (i = 0; i < 44; i++) { 
+    for (i = 0; i < 44; i++) {
         skey->rc6.K[i] = S[i];
     }
     return CRYPT_OK;
@@ -127,7 +125,7 @@
 {
    ulong32 a,b,c,d,t,u, *K;
    int r;
-   
+
    LTC_ARGCHK(skey != NULL);
    LTC_ARGCHK(pt   != NULL);
    LTC_ARGCHK(ct   != NULL);
@@ -140,8 +138,8 @@
        t = (b * (b + b + 1)); t = ROLc(t, 5); \
        u = (d * (d + d + 1)); u = ROLc(u, 5); \
        a = ROL(a^t,u) + K[0];                \
-       c = ROL(c^u,t) + K[1]; K += 2;   
-    
+       c = ROL(c^u,t) + K[1]; K += 2;
+
    K = skey->rc6.K + 2;
    for (r = 0; r < 20; r += 4) {
        RND(a,b,c,d);
@@ -149,7 +147,7 @@
        RND(c,d,a,b);
        RND(d,a,b,c);
    }
-   
+
 #undef RND
 
    a += skey->rc6.K[42];
@@ -171,7 +169,7 @@
   Decrypts a block of text with LTC_RC6
   @param ct The input ciphertext (16 bytes)
   @param pt The output plaintext (16 bytes)
-  @param skey The key as scheduled 
+  @param skey The key as scheduled
 */
 #ifdef LTC_CLEAN_STACK
 static int _rc6_ecb_decrypt(const unsigned char *ct, unsigned char *pt, symmetric_key *skey)
@@ -185,26 +183,26 @@
    LTC_ARGCHK(skey != NULL);
    LTC_ARGCHK(pt   != NULL);
    LTC_ARGCHK(ct   != NULL);
-   
+
    LOAD32L(a,&ct[0]);LOAD32L(b,&ct[4]);LOAD32L(c,&ct[8]);LOAD32L(d,&ct[12]);
    a -= skey->rc6.K[42];
    c -= skey->rc6.K[43];
-   
+
 #define RND(a,b,c,d) \
        t = (b * (b + b + 1)); t = ROLc(t, 5); \
        u = (d * (d + d + 1)); u = ROLc(u, 5); \
        c = ROR(c - K[1], t) ^ u; \
        a = ROR(a - K[0], u) ^ t; K -= 2;
-   
+
    K = skey->rc6.K + 40;
-   
+
    for (r = 0; r < 20; r += 4) {
        RND(d,a,b,c);
        RND(c,d,a,b);
        RND(b,c,d,a);
        RND(a,b,c,d);
    }
-   
+
 #undef RND
 
    b -= skey->rc6.K[0];
@@ -231,7 +229,7 @@
 {
  #ifndef LTC_TEST
     return CRYPT_NOP;
- #else    
+ #else
    static const struct {
        int keylen;
        unsigned char key[32], pt[16], ct[16];
@@ -285,24 +283,8 @@
       rc6_ecb_decrypt(tmp[0], tmp[1], &key);
 
       /* compare */
-      if (XMEMCMP(tmp[0], tests[x].ct, 16) || XMEMCMP(tmp[1], tests[x].pt, 16)) {
-#if 0
-         printf("\n\nFailed test %d\n", x);
-         if (XMEMCMP(tmp[0], tests[x].ct, 16)) {
-            printf("Ciphertext:  ");
-            for (y = 0; y < 16; y++) printf("%02x ", tmp[0][y]);
-            printf("\nExpected  :  ");
-            for (y = 0; y < 16; y++) printf("%02x ", tests[x].ct[y]);
-            printf("\n");
-         }
-         if (XMEMCMP(tmp[1], tests[x].pt, 16)) {
-            printf("Plaintext:  ");
-            for (y = 0; y < 16; y++) printf("%02x ", tmp[0][y]);
-            printf("\nExpected :  ");
-            for (y = 0; y < 16; y++) printf("%02x ", tests[x].pt[y]);
-            printf("\n");
-         }
-#endif
+      if (compare_testvector(tmp[0], 16, tests[x].ct, 16, "RC6 Encrypt", x) ||
+            compare_testvector(tmp[1], 16, tests[x].pt, 16, "RC6 Decrypt", x)) {
          return CRYPT_FAIL_TESTVECTOR;
       }
 
@@ -316,11 +298,12 @@
   #endif
 }
 
-/** Terminate the context 
+/** Terminate the context
    @param skey    The scheduled key
 */
 void rc6_done(symmetric_key *skey)
 {
+  LTC_UNUSED_PARAM(skey);
 }
 
 /**
@@ -343,6 +326,6 @@
 
 
 
-/* $Source$ */
-/* $Revision$ */
-/* $Date$ */
+/* ref:         $Format:%D$ */
+/* git commit:  $Format:%H$ */
+/* commit time: $Format:%ai$ */