chiark / gitweb /
server/tests.at (AWAIT_KXDONE): Ignore the correct server messages.
[tripe] / server / chal.c
index 5258cf9c66c1ef24e573ea3998a08af071e85c41..387f0db1fb29e182d36b28d9df979d7ebce21082 100644 (file)
@@ -1,13 +1,11 @@
 /* -*-c-*-
- *
- * $Id$
  *
  * Cryptographic challenges
  *
  * (c) 2005 Straylight/Edgeware
  */
 
-/*----- Licensing notice --------------------------------------------------* 
+/*----- Licensing notice --------------------------------------------------*
  *
  * This file is part of Trivial IP Encryption (TrIPE).
  *
  * it under the terms of the GNU General Public License as published by
  * the Free Software Foundation; either version 2 of the License, or
  * (at your option) any later version.
- * 
+ *
  * TrIPE is distributed in the hope that it will be useful,
  * but WITHOUT ANY WARRANTY; without even the implied warranty of
  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  * GNU General Public License for more details.
- * 
+ *
  * You should have received a copy of the GNU General Public License
  * along with TrIPE; if not, write to the Free Software Foundation,
  * Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
@@ -49,16 +47,16 @@ static seqwin iseq;
 
 static void c_genkey(void)
 {
-  if (mac && GM_CLASS(mac) == algs.m && oseq < 0x07ffffff) return;
+  if (mac && GM_CLASS(mac) == master->algs.m && oseq < 0x07ffffff) return;
   if (mac) GM_DESTROY(mac);
-  assert(algs.mksz < sizeof(buf_t));
-  rand_get(RAND_GLOBAL, buf_t, algs.mksz);
-  mac = GM_KEY(algs.m, buf_t, algs.mksz);
+  assert(master->algs.mksz < sizeof(buf_t));
+  rand_get(RAND_GLOBAL, buf_t, master->algs.mksz);
+  mac = GM_KEY(master->algs.m, buf_t, master->algs.mksz);
   oseq = 0;
   seq_reset(&iseq);
   IF_TRACING(T_CHAL, {
     trace(T_CHAL, "chal: generated new challenge key");
-    trace_block(T_CRYPTO, "chal: new key", buf_t, algs.mksz);
+    trace_block(T_CRYPTO, "chal: new key", buf_t, master->algs.mksz);
   })
 }
 
@@ -81,7 +79,7 @@ int c_new(buf *b)
   if (buf_putu32(b, oseq++)) return (-1);
   h = GM_INIT(mac);
   GH_HASH(h, p, BCUR(b) - p);
-  buf_put(b, GH_DONE(h, 0), algs.tagsz);
+  buf_put(b, GH_DONE(h, 0), master->algs.tagsz);
   GH_DESTROY(h);
   if (BBAD(b)) return (-1);
   IF_TRACING(T_CHAL, {
@@ -103,7 +101,7 @@ int c_new(buf *b)
 int c_check(buf *b)
 {
   const octet *p;
-  size_t sz = 4 + algs.tagsz;
+  size_t sz = 4 + master->algs.tagsz;
   uint32 seq;
   ghash *h;
   int ok;
@@ -119,14 +117,14 @@ int c_check(buf *b)
   }
   h = GM_INIT(mac);
   GH_HASH(h, p, 4);
-  ok = (memcmp(GH_DONE(h, 0), p + 4, algs.tagsz) == 0);
+  ok = ct_memeq(GH_DONE(h, 0), p + 4, master->algs.tagsz);
   GH_DESTROY(h);
   if (!ok) {
     a_warn("CHAL", "incorrect-tag", A_END);
     goto fail;
   }
   seq = LOAD32(p);
-  if (seq_check(&iseq, LOAD32(p), "CHAL"))
+  if (seq_check(&iseq, seq, "CHAL"))
     goto fail;
   T( trace(T_CHAL, "chal: checked challenge %lu", (unsigned long)seq); )
   return (0);