Cleanups.
[u/mdw/catacomb] / sslprf.c
index e9682e5..866ef89 100644 (file)
--- a/sslprf.c
+++ b/sslprf.c
@@ -1,13 +1,13 @@
 /* -*-c-*-
  *
- * $Id: sslprf.c,v 1.1 2001/04/06 22:05:10 mdw Exp $
+ * $Id: sslprf.c,v 1.2 2004/04/08 01:36:15 mdw Exp $
  *
  * The SSL pseudo-random function
  *
  * (c) 2001 Straylight/Edgeware
  */
 
-/*----- Licensing notice --------------------------------------------------* 
+/*----- Licensing notice --------------------------------------------------*
  *
  * This file is part of Catacomb.
  *
  * it under the terms of the GNU Library General Public License as
  * published by the Free Software Foundation; either version 2 of the
  * License, or (at your option) any later version.
- * 
+ *
  * Catacomb 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 Library General Public License for more details.
- * 
+ *
  * You should have received a copy of the GNU Library General Public
  * License along with Catacomb; if not, write to the Free
  * Software Foundation, Inc., 59 Temple Place - Suite 330, Boston,
  * MA 02111-1307, USA.
  */
 
-/*----- Revision history --------------------------------------------------* 
- *
- * $Log: sslprf.c,v $
- * Revision 1.1  2001/04/06 22:05:10  mdw
- * Add support for SSL pseudo-random function.
- *
- */
-
 /*----- Header files ------------------------------------------------------*/
 
 #include <mLib/alloc.h>
@@ -66,24 +58,24 @@ static void step(sslprf_ctx *c)
   ghash *h, *hh;
   octet *p;
 
-  h = c->ci->init();
+  h = GH_INIT(c->ci);
   x = 'A' + c->i - 1;
   for (sz = c->i++; sz > 0; sz -= n) {
     n = sz;
     if (n > sizeof(buf))
       n = sizeof(buf);
     memset(buf, x, n);
-    h->ops->hash(h, buf, n);
+    GH_HASH(h, buf, n);
   }
-  h->ops->hash(h, c->k, c->ksz);
-  h->ops->hash(h, c->sd, c->sdsz);
-  p = h->ops->done(h, 0);
+  GH_HASH(h, c->k, c->ksz);
+  GH_HASH(h, c->sd, c->sdsz);
+  p = GH_DONE(h, 0);
 
-  hh = c->co->init();
-  hh->ops->hash(hh, c->k, c->ksz);
-  hh->ops->hash(hh, p, c->ihashsz);
-  c->p = hh->ops->done(hh, 0);
-  h->ops->destroy(h);
+  hh = GH_INIT(c->co);
+  GH_HASH(hh, c->k, c->ksz);
+  GH_HASH(hh, p, c->ihashsz);
+  c->p = GH_DONE(hh, 0);
+  GH_DESTROY(h);
 
   c->h = hh;
   c->sz = c->ohashsz;
@@ -138,7 +130,7 @@ void sslprf_encrypt(sslprf_ctx *c, const void *src, void *dest, size_t sz)
 
   while (sz) {
     if (!c->sz) {
-      c->h->ops->destroy(c->h);
+      GH_DESTROY(c->h);
       step(c);
     }
     n = c->sz;
@@ -170,7 +162,7 @@ void sslprf_encrypt(sslprf_ctx *c, const void *src, void *dest, size_t sz)
 
 void sslprf_free(sslprf_ctx *c)
 {
-  c->h->ops->destroy(c->h);
+  GH_DESTROY(c->h);
 }
 
 /* --- Generic random number generator --- */
@@ -247,7 +239,7 @@ static int grmisc(grand *r, unsigned op, ...)
     } break;
     default:
       GRAND_BADOP;
-      break;      
+      break;
   }
 
   va_end(ap);
@@ -340,9 +332,9 @@ static int v_generate(dstr *v)
   if (memcmp(v[2].buf, d.buf, d.len) != 0) {
     ok = 0;
     printf("\nfail sslprf:"
-          "\n\tkey        = ");
+          "\n\tkey        = ");
     type_hex.dump(&v[0], stdout);
-    printf("\n\tseed       = "); type_hex.dump(&v[1], stdout);
+    printf("\n\tseed      = "); type_hex.dump(&v[1], stdout);
     printf("\n\texpected   = "); type_hex.dump(&v[2], stdout);
     printf("\n\tcalculated = "); type_hex.dump(&d, stdout);
     putchar('\n');