server/chal.c: Capture `master->algs.bulk' in a variable.
[tripe] / server / chal.c
index 71fde49..e6a3005 100644 (file)
@@ -9,19 +9,18 @@
  *
  * This file is part of Trivial IP Encryption (TrIPE).
  *
- * TrIPE is free software; you can redistribute it and/or modify
- * 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 free software: you can redistribute it and/or modify it under
+ * the terms of the GNU General Public License as published by the Free
+ * Software Foundation; either version 3 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.
+ * 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.
+ * along with TrIPE.  If not, see <https://www.gnu.org/licenses/>.
  */
 
 /*----- Header files ------------------------------------------------------*/
 
 /*----- Static variables --------------------------------------------------*/
 
-static bulkchal *bulk;
+static bulkchal *bchal;
 static uint32 oseq;
 static seqwin iseq;
 
-/*----- Main code ---------------------------------------------------------*/
+/*----- Challenges --------------------------------------------------------*/
 
 /* --- @c_genkey@ --- *
  *
@@ -47,11 +46,11 @@ static seqwin iseq;
 
 static void c_genkey(void)
 {
-  if (bulk && bulk->ops == master->algs.bulk->ops && oseq < 0x07ffffff)
-    return;
-  if (bulk) bulk->ops->freechal(bulk);
-  bulk = master->algs.bulk->ops->genchal(master->algs.bulk);
-  bulk->ops = master->algs.bulk->ops;
+  bulkalgs *bulk = master->algs.bulk;
+  if (bchal && bchal->ops == bulk->ops && oseq < 0x07ffffff) return;
+  if (bchal) bchal->ops->freechal(bchal);
+  bchal = bulk->ops->genchal(bulk);
+  bchal->ops = bulk->ops;
   oseq = 0;
   seq_reset(&iseq);
 }
@@ -71,8 +70,8 @@ int c_new(buf *b)
 
   c_genkey();
   p = BCUR(b);
-  if (buf_putu32(b, oseq++) || !buf_get(b, bulk->tagsz)) return (-1);
-  if (bulk->ops->chaltag(bulk, p, 4, p + 4)) return (-1);
+  if (buf_putu32(b, oseq++) || !buf_get(b, bchal->tagsz)) return (-1);
+  if (bchal->ops->chaltag(bchal, p, 4, p + 4)) return (-1);
   IF_TRACING(T_CHAL, {
     trace(T_CHAL, "chal: issuing challenge %lu", (unsigned long)(oseq - 1));
     trace_block(T_CRYPTO, "chal: challenge block", p, BCUR(b) - p);
@@ -95,17 +94,17 @@ int c_check(buf *b)
   size_t sz;
   uint32 seq;
 
-  if (!bulk) {
+  if (!bchal) {
     a_warn("CHAL", "impossible-challenge", A_END);
     goto fail;
   }
-  sz = 4 + bulk->tagsz;
+  sz = 4 + bchal->tagsz;
   if ((p = buf_get(b, sz)) == 0) {
     a_warn("CHAL", "invalid-challenge", A_END);
     goto fail;
   }
   IF_TRACING(T_CHAL, trace_block(T_CRYPTO, "chal: check challenge", p, sz); )
-  if (bulk->ops->chalvrf(bulk, p, 4, p + 4)) {
+  if (bchal->ops->chalvrf(bchal, p, 4, p + 4)) {
     a_warn("CHAL", "incorrect-tag", A_END);
     goto fail;
   }