summaryrefslogtreecommitdiffstats
path: root/crypto/heimdal/lib/krb5/n-fold.c
diff options
context:
space:
mode:
Diffstat (limited to 'crypto/heimdal/lib/krb5/n-fold.c')
-rw-r--r--crypto/heimdal/lib/krb5/n-fold.c23
1 files changed, 17 insertions, 6 deletions
diff --git a/crypto/heimdal/lib/krb5/n-fold.c b/crypto/heimdal/lib/krb5/n-fold.c
index d0db5e8..53528cf 100644
--- a/crypto/heimdal/lib/krb5/n-fold.c
+++ b/crypto/heimdal/lib/krb5/n-fold.c
@@ -32,21 +32,23 @@
#include "krb5_locl.h"
-RCSID("$Id: n-fold.c,v 1.6 1999/08/27 09:03:41 joda Exp $");
+RCSID("$Id: n-fold.c 22190 2007-12-06 16:24:22Z lha $");
-static void
+static krb5_error_code
rr13(unsigned char *buf, size_t len)
{
unsigned char *tmp;
int bytes = (len + 7) / 8;
int i;
if(len == 0)
- return;
+ return 0;
{
const int bits = 13 % len;
const int lbit = len % 8;
tmp = malloc(bytes);
+ if (tmp == NULL)
+ return ENOMEM;
memcpy(tmp, buf, bytes);
if(lbit) {
/* pad final byte with inital bits */
@@ -75,9 +77,10 @@ rr13(unsigned char *buf, size_t len)
}
free(tmp);
}
+ return 0;
}
-/* Add `b' to `a', both beeing one's complement numbers. */
+/* Add `b' to `a', both being one's complement numbers. */
static void
add1(unsigned char *a, unsigned char *b, size_t len)
{
@@ -95,22 +98,28 @@ add1(unsigned char *a, unsigned char *b, size_t len)
}
}
-void
+krb5_error_code KRB5_LIB_FUNCTION
_krb5_n_fold(const void *str, size_t len, void *key, size_t size)
{
/* if len < size we need at most N * len bytes, ie < 2 * size;
if len > size we need at most 2 * len */
+ krb5_error_code ret = 0;
size_t maxlen = 2 * max(size, len);
size_t l = 0;
unsigned char *tmp = malloc(maxlen);
unsigned char *buf = malloc(len);
+ if (tmp == NULL || buf == NULL)
+ return ENOMEM;
+
memcpy(buf, str, len);
memset(key, 0, size);
do {
memcpy(tmp + l, buf, len);
l += len;
- rr13(buf, len * 8);
+ ret = rr13(buf, len * 8);
+ if (ret)
+ goto out;
while(l >= size) {
add1(key, tmp, size);
l -= size;
@@ -119,8 +128,10 @@ _krb5_n_fold(const void *str, size_t len, void *key, size_t size)
memmove(tmp, tmp + size, l);
}
} while(l != 0);
+out:
memset(buf, 0, len);
free(buf);
memset(tmp, 0, maxlen);
free(tmp);
+ return ret;
}
OpenPOWER on IntegriCloud