diff libtomcrypt/src/ciphers/kseed.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/kseed.c	Thu Feb 08 23:11:40 2018 +0800
+++ b/libtomcrypt/src/ciphers/kseed.c	Fri Feb 09 21:44:05 2018 +0800
@@ -5,8 +5,6 @@
  *
  * The library is free for all purposes without any express
  * guarantee it works.
- *
- * Tom St Denis, [email protected], http://libtom.org
  */
 
 /**
@@ -29,7 +27,7 @@
    &kseed_test,
    &kseed_done,
    &kseed_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 SS0[256] = {
@@ -201,41 +199,41 @@
  */
 int kseed_setup(const unsigned char *key, int keylen, int num_rounds, symmetric_key *skey)
 {
-    int     i;
-    ulong32 tmp, k1, k2, k3, k4;
+   int     i;
+   ulong32 tmp, k1, k2, k3, k4;
 
-    if (keylen != 16) {
-       return CRYPT_INVALID_KEYSIZE;
-    }
-   
-    if (num_rounds != 16 && num_rounds != 0) {
-       return CRYPT_INVALID_ROUNDS;
-    }
+   if (keylen != 16) {
+      return CRYPT_INVALID_KEYSIZE;
+   }
+
+   if (num_rounds != 16 && num_rounds != 0) {
+      return CRYPT_INVALID_ROUNDS;
+   }
 
-    /* load key */
-    LOAD32H(k1, key);
-    LOAD32H(k2, key+4);
-    LOAD32H(k3, key+8);
-    LOAD32H(k4, key+12);
+   /* load key */
+   LOAD32H(k1, key);
+   LOAD32H(k2, key+4);
+   LOAD32H(k3, key+8);
+   LOAD32H(k4, key+12);
 
-    for (i = 0; i < 16; i++) {
-       skey->kseed.K[2*i+0] = G(k1 + k3 - KCi[i]);
-       skey->kseed.K[2*i+1] = G(k2 - k4 + KCi[i]);
-       if (i&1) {
-          tmp = k3;
-          k3 = ((k3 << 8) | (k4 >> 24)) & 0xFFFFFFFF;
-          k4 = ((k4 << 8) | (tmp >> 24)) & 0xFFFFFFFF;
-       } else {
-          tmp = k1;
-          k1 = ((k1 >> 8) | (k2 << 24)) & 0xFFFFFFFF;
-          k2 = ((k2 >> 8) | (tmp << 24)) & 0xFFFFFFFF;
+   for (i = 0; i < 16; i++) {
+      skey->kseed.K[2*i+0] = G(k1 + k3 - KCi[i]);
+      skey->kseed.K[2*i+1] = G(k2 - k4 + KCi[i]);
+      if (i&1) {
+         tmp = k3;
+         k3 = ((k3 << 8) | (k4 >> 24)) & 0xFFFFFFFF;
+         k4 = ((k4 << 8) | (tmp >> 24)) & 0xFFFFFFFF;
+      } else {
+         tmp = k1;
+         k1 = ((k1 >> 8) | (k2 << 24)) & 0xFFFFFFFF;
+         k2 = ((k2 >> 8) | (tmp << 24)) & 0xFFFFFFFF;
       }
       /* reverse keys for decrypt */
       skey->kseed.dK[2*(15-i)+0] = skey->kseed.K[2*i+0];
       skey->kseed.dK[2*(15-i)+1] = skey->kseed.K[2*i+1];
-    }
+   }
 
-    return CRYPT_OK;
+   return CRYPT_OK;
 }
 
 static void rounds(ulong32 *P, ulong32 *K)
@@ -275,7 +273,7 @@
   Decrypts a block of text with SEED
   @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
   @return CRYPT_OK if successful
 */
 int kseed_ecb_decrypt(const unsigned char *ct, unsigned char *pt, symmetric_key *skey)
@@ -293,11 +291,12 @@
    return CRYPT_OK;
 }
 
-/** Terminate the context 
+/** Terminate the context
    @param skey    The scheduled key
 */
 void kseed_done(symmetric_key *skey)
 {
+  LTC_UNUSED_PARAM(skey);
 }
 
 /**
@@ -345,7 +344,8 @@
        kseed_setup(tests[x].key, 16, 0, &skey);
        kseed_ecb_encrypt(tests[x].pt, buf[0], &skey);
        kseed_ecb_decrypt(buf[0], buf[1], &skey);
-       if (XMEMCMP(buf[0], tests[x].ct, 16) || XMEMCMP(buf[1], tests[x].pt, 16)) {
+       if (compare_testvector(buf[0], 16, tests[x].ct, 16, "KSEED Encrypt", x) ||
+             compare_testvector(buf[1], 16, tests[x].pt, 16, "KSEED Decrypt", x)) {
           return CRYPT_FAIL_TESTVECTOR;
        }
    }
@@ -371,6 +371,6 @@
 
 #endif
 
-/* $Source$ */
-/* $Revision$ */
-/* $Date$ */
+/* ref:         $Format:%D$ */
+/* git commit:  $Format:%H$ */
+/* commit time: $Format:%ai$ */