chiark / gitweb /
mon/tripemon.in: Add per-peer key selection and mobile options.
[tripe] / server / keymgmt.c
index d28421fe977e555e3bff1d62b2f1752ad807c050..17325dce2d96e7ca78f029a4fd126d6344c865d9 100644 (file)
@@ -180,7 +180,7 @@ static int algs_get(algswitch *a, dstr *e, key_file *kf, key *k)
   const char *p;
   const bulkcrypto *bulk;
   char *q, *qq;
-  dstr d = DSTR_INIT;
+  dstr d = DSTR_INIT, dd = DSTR_INIT;
   int rc = -1;
 
   /* --- Hash function --- */
@@ -225,6 +225,25 @@ static int algs_get(algswitch *a, dstr *e, key_file *kf, key *k)
     }
   }
 
+  /* --- Block cipher for miscellaneous use --- */
+
+  if (!(a->bulk->prim & BCP_BLKC))
+    a->b = 0;
+  else {
+    if ((p = key_getattr(kf, k, "blkc")) == 0) {
+      dstr_reset(&dd);
+      dstr_puts(&dd, a->c ? a->c->name : "rijndael-");
+      if ((q = strrchr(dd.buf, '-')) != 0) *q = 0;
+      p = dd.buf;
+    }
+    dstr_reset(&d);
+    dstr_putf(&d, "%s-ecb", p);
+    if ((a->b = gcipher_byname(d.buf)) == 0) {
+      a_format(e, "unknown-blkc", "%s", p, A_END);
+      goto done;
+    }
+  }
+
   /* --- Message authentication for bulk data --- */
 
   if (!(a->bulk->prim & BCP_MAC)) {
@@ -270,6 +289,7 @@ static int algs_get(algswitch *a, dstr *e, key_file *kf, key *k)
   rc = 0;
 done:
   dstr_destroy(&d);
+  dstr_destroy(&dd);
   return (rc);
 }
 
@@ -313,6 +333,12 @@ static int algs_check(algswitch *a, dstr *e, const group *g)
             A_END);
     return (-1);
   }
+  if (a->b && (a->bksz = keysz(a->hashsz, a->b->keysz)) == 0) {
+    a_format(e, "blkc", "%.*s", strlen(a->b->name) - 4, a->b->name,
+            "no-key-size", "%lu", (unsigned long)a->hashsz,
+            A_END);
+    return (-1);
+  }
 
   /* --- Derive the data limit --- */
 
@@ -347,7 +373,8 @@ int km_samealgsp(const kdata *kdx, const kdata *kdy)
 {
   const algswitch *a = &kdx->algs, *aa = &kdy->algs;
 
-  return (group_samep(kdx->g, kdy->g) && a->c == aa->c &&
+  return (group_samep(kdx->g, kdy->g) &&
+         a->c == aa->c && a->b == aa->b &&
          a->mgf == aa->mgf && a->h == aa->h &&
          a->m == aa->m && a->tagsz == aa->tagsz);
 }