summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNiklas Hallqvist <niklas@cvs.openbsd.org>1999-03-31 20:30:56 +0000
committerNiklas Hallqvist <niklas@cvs.openbsd.org>1999-03-31 20:30:56 +0000
commitd1fea6f27045b8a981c435047f1298b6787eec33 (patch)
treec3b01419d6984fe046aa2a36f11b586b885911cb
parent5e6f85f538f2bbaa36a7a77071d4bcc61aac3b2b (diff)
Merge with EOM 1.5
Stylistic fixes
-rw-r--r--sbin/isakmpd/prf.c60
1 files changed, 30 insertions, 30 deletions
diff --git a/sbin/isakmpd/prf.c b/sbin/isakmpd/prf.c
index 1405d12b309..d94a2175cd6 100644
--- a/sbin/isakmpd/prf.c
+++ b/sbin/isakmpd/prf.c
@@ -1,8 +1,8 @@
-/* $OpenBSD: prf.c,v 1.4 1999/02/26 03:49:27 niklas Exp $ */
-/* $EOM: prf.c,v 1.4 1999/02/25 11:39:19 niklas Exp $ */
+/* $OpenBSD: prf.c,v 1.5 1999/03/31 20:30:55 niklas Exp $ */
+/* $EOM: prf.c,v 1.5 1999/03/31 20:17:38 niklas Exp $ */
/*
- * Copyright (c) 1998 Niels Provos. All rights reserved.
+ * Copyright (c) 1998, 1999 Niels Provos. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
@@ -74,55 +74,54 @@ prf_hash_final (unsigned char *digest, struct prf_hash_ctx *ctx)
* Obtain a Pseudo-Random Function for us. At the moment this is
* the HMAC version of a hash. See RFC-2104 for reference.
*/
-
struct prf *
prf_alloc (enum prfs type, int subtype, char *shared, int sharedsize)
{
struct hash *hash;
struct prf *prf;
+ struct prf_hash_ctx *prfctx;
switch (type)
{
case PRF_HMAC:
hash = hash_get (subtype);
- if (hash == NULL)
- return NULL;
+ if (!hash)
+ return 0;
break;
default:
- log_print ("Unkown PRF type %d in prf_alloc()", type);
- return NULL;
+ log_print ("prf_alloc: unknown PRF type %d", type);
+ return 0;
}
- if ((prf = malloc (sizeof (struct prf))) == NULL)
+ prf = malloc (sizeof *prf);
+ if (!prf)
{
- log_print ("Out of memory for struct prf in prf_alloc()");
- return NULL;
+ log_error ("prf_alloc: malloc (%d) failed", sizeof *prf);
+ return 0;
}
if (type == PRF_HMAC)
{
- struct prf_hash_ctx *prfctx;
-
- /* Obtain needed memory */
- prfctx = malloc (sizeof (struct prf_hash_ctx));
- if (prfctx == NULL)
+ /* Obtain needed memory. */
+ prfctx = malloc (sizeof *prfctx);
+ if (!prfctx)
{
- log_print ("Out of memory for struct prf_hash_ctx in prf_alloc()");
+ log_error ("prf_alloc: malloc (%d) failed", sizeof *prfctx);
goto cleanprf;
}
prf->prfctx = prfctx;
prfctx->ctx = malloc (hash->ctxsize);
- if (prfctx->ctx == NULL)
+ if (!prfctx->ctx)
{
- log_print ("Out of memory for ctx in prf_alloc()");
+ log_error ("prf_alloc: malloc (%d) failed", hash->ctxsize);
goto cleanprfctx;
}
prfctx->ctx2 = malloc (hash->ctxsize);
- if (prfctx->ctx2 == NULL)
+ if (!prfctx->ctx2)
{
- log_print ("Out of memory for ctx2 in prf_alloc()");
+ log_error ("prf_alloc: malloc (%d) failed", hash->ctxsize);
free (prfctx->ctx);
goto cleanprfctx;
}
@@ -130,16 +129,16 @@ prf_alloc (enum prfs type, int subtype, char *shared, int sharedsize)
prf->blocksize = hash->hashsize;
prfctx->hash = hash;
- /* Use the correct function pointers */
- prf->Init = (void (*) (void *)) prf_hash_init;
+ /* Use the correct function pointers. */
+ prf->Init = (void (*) (void *))prf_hash_init;
prf->Update
- = (void (*) (void *, unsigned char *, unsigned int)) prf_hash_update;
- prf->Final = (void (*) (unsigned char *, void *)) prf_hash_final;
+ = (void (*) (void *, unsigned char *, unsigned int))prf_hash_update;
+ prf->Final = (void (*) (unsigned char *, void *))prf_hash_final;
- /* Init HMAC contexts */
+ /* Init HMAC contexts. */
hash->HMACInit (hash, shared, sharedsize);
- /* Save contexts */
+ /* Save contexts. */
memcpy (prfctx->ctx, hash->ctx, hash->ctxsize);
memcpy (prfctx->ctx2, hash->ctx2, hash->ctxsize);
}
@@ -150,16 +149,17 @@ prf_alloc (enum prfs type, int subtype, char *shared, int sharedsize)
free (prf->prfctx);
cleanprf:
free (prf);
- return NULL;
+ return 0;
}
-
+/* Deallocate the PRF pointed to by PRF. */
void
prf_free (struct prf *prf)
{
+ struct prf_hash_ctx *prfctx = prf->prfctx;
+
if (prf->type == PRF_HMAC)
{
- struct prf_hash_ctx *prfctx = prf->prfctx;
free (prfctx->ctx2);
free (prfctx->ctx);
}