summaryrefslogtreecommitdiffstats
path: root/lib/libskey
diff options
context:
space:
mode:
authormillert <millert@openbsd.org>2003-04-03 17:48:50 +0000
committermillert <millert@openbsd.org>2003-04-03 17:48:50 +0000
commitd4a8371fd42b51da49821614a8efadec750ca024 (patch)
treea92782dda2bb480a20ce7a7cd855159a6139507d /lib/libskey
parentDeal with files w/o a trailing newline before EOF. Found by mpech@ (diff)
downloadwireguard-openbsd-d4a8371fd42b51da49821614a8efadec750ca024.tar.xz
wireguard-openbsd-d4a8371fd42b51da49821614a8efadec750ca024.zip
Use snprintf() and strlcpy() throughout.
Diffstat (limited to 'lib/libskey')
-rw-r--r--lib/libskey/put.c53
-rw-r--r--lib/libskey/skeylogin.c47
-rw-r--r--lib/libskey/skeysubr.c98
3 files changed, 65 insertions, 133 deletions
diff --git a/lib/libskey/put.c b/lib/libskey/put.c
index 0876138ad1b..1177a364a65 100644
--- a/lib/libskey/put.c
+++ b/lib/libskey/put.c
@@ -8,7 +8,7 @@
*
* Dictionary lookup and extraction.
*
- * $OpenBSD: put.c,v 1.12 2002/06/22 02:13:10 deraadt Exp $
+ * $OpenBSD: put.c,v 1.13 2003/04/03 17:48:50 millert Exp $
*/
#include <stdio.h>
@@ -322,13 +322,11 @@ static const char * const Wp[2048] = {
};
/*
- * Encode 8 bytes in 'c' as a string of English words.
- * Returns a pointer to a static buffer
+ * Encode 8 bytes in 'c' as a string of 6 four-letter English words separated
+ * by spaces. The 'out' pointer must have at least 30 bytes for storage.
*/
char *
-btoe(engout, c)
- char *engout;
- char *c;
+btoe(char *engout, char *c)
{
char cp[10]; /* add in room for the parity 2 bits + extract() slop */
int p, i, indices[6];
@@ -350,7 +348,7 @@ btoe(engout, c)
indices[4] = extract(cp, 44, 11);
indices[5] = extract(cp, 55, 11);
- sprintf(engout, "%.4s %.4s %.4s %.4s %.4s %.4s", Wp[indices[0]],
+ snprintf(engout, 30, "%.4s %.4s %.4s %.4s %.4s %.4s", Wp[indices[0]],
Wp[indices[1]], Wp[indices[2]], Wp[indices[3]],
Wp[indices[4]], Wp[indices[5]]);
@@ -358,16 +356,15 @@ btoe(engout, c)
}
/*
- * convert English to binary
+ * Converts the 6 space-separated english words in 'e' to binary form.
+ * The 'out' variable must be at least SKEY_BINKEY_SIZE bytes in size.
* returns 1 OK - all good words and parity is OK
* 0 word not in data base
* -1 badly formed in put ie > 4 char word
* -2 words OK but parity is wrong
*/
int
-etob(out, e)
- char *out;
- char *e;
+etob(char *out, char *e)
{
char *word;
int i, p, v, l, low, high;
@@ -378,8 +375,7 @@ etob(out, e)
if (e == NULL)
return(-1);
- (void)strncpy(input, e, sizeof(input) - 1);
- input[sizeof(input) - 1] = '\0';
+ (void)strlcpy(input, e, sizeof(input));
(void)memset(b, 0, sizeof(b));
(void)memset(out, 0, SKEY_BINKEY_SIZE);
for (i = 0, p = 0; i < 6; i++, p += 11) {
@@ -416,13 +412,14 @@ etob(out, e)
return(1);
}
-/* Display 8 bytes as a series of 16-bit hex digits */
+/*
+ * Format 8 bytes as a series of four 16-bit hex digits.
+ * The 'out' pointer must have at least 20 bytes for storage.
+ */
char *
-put8(out, s)
- char *out;
- char *s;
+put8(char *out, char *s)
{
- (void)sprintf(out, "%02X%02X %02X%02X %02X%02X %02X%02X",
+ (void)snprintf(out, 20, "%02X%02X %02X%02X %02X%02X %02X%02X",
s[0] & 0xff, s[1] & 0xff, s[2] & 0xff,
s[3] & 0xff, s[4] & 0xff, s[5] & 0xff,
s[6] & 0xff, s[7] & 0xff);
@@ -433,10 +430,7 @@ put8(out, s)
/* Dictionary binary search */
static int
-wsrch(w, low, high)
- char *w;
- int low;
- int high;
+wsrch(char *w, int low, int high)
{
int i, j;
@@ -464,11 +458,7 @@ wsrch(w, low, high)
}
static void
-insert(s, x, start, length)
- char *s;
- int x;
- int start;
- int length;
+insert(char *s, int x, int start, int length)
{
unsigned char cl;
unsigned char cc;
@@ -499,10 +489,8 @@ insert(s, x, start, length)
}
static void
-standard(word)
- char *word;
+standard(char *word)
{
-
while (*word) {
if (!isascii(*word))
break;
@@ -520,10 +508,7 @@ standard(word)
/* Extract 'length' bits from the char array 's' starting with bit 'start' */
static unsigned int
-extract(s, start, length)
- char *s;
- int start;
- int length;
+extract(char *s, int start, int length)
{
unsigned char cl;
unsigned char cc;
diff --git a/lib/libskey/skeylogin.c b/lib/libskey/skeylogin.c
index f6170a581bb..620378d53c5 100644
--- a/lib/libskey/skeylogin.c
+++ b/lib/libskey/skeylogin.c
@@ -10,7 +10,7 @@
*
* S/Key verification check, lookups, and authentication.
*
- * $OpenBSD: skeylogin.c,v 1.48 2002/11/16 22:54:46 millert Exp $
+ * $OpenBSD: skeylogin.c,v 1.49 2003/04/03 17:48:50 millert Exp $
*/
#include <sys/param.h>
@@ -47,10 +47,7 @@ static char *tgetline(int, char *, size_t, int);
* record.
*/
int
-skeychallenge(mp, name, ss)
- struct skey *mp;
- char *name;
- char *ss;
+skeychallenge(struct skey *mp, char *name, char *ss)
{
int rval;
@@ -85,9 +82,7 @@ skeychallenge(mp, name, ss)
* 1: entry not found
*/
int
-skeylookup(mp, name)
- struct skey *mp;
- char *name;
+skeylookup(struct skey *mp, char *name)
{
struct stat statbuf;
size_t nread;
@@ -184,8 +179,7 @@ skeylookup(mp, name)
* 1: no more entries, keydir is closed.
*/
int
-skeygetnext(mp)
- struct skey *mp;
+skeygetnext(struct skey *mp)
{
struct dirent entry, *dp;
int rval;
@@ -226,9 +220,7 @@ skeygetnext(mp)
* The database file is always closed by this call.
*/
int
-skeyverify(mp, response)
- struct skey *mp;
- char *response;
+skeyverify(struct skey *mp, char *response)
{
char key[SKEY_BINKEY_SIZE];
char fkey[SKEY_BINKEY_SIZE];
@@ -308,8 +300,7 @@ skeyverify(mp, response)
*
*/
int
-skey_haskey(username)
- char *username;
+skey_haskey(char *username)
{
struct skey skey;
int i;
@@ -330,8 +321,7 @@ skey_haskey(username)
*
*/
char *
-skey_keyinfo(username)
- char *username;
+skey_keyinfo(char *username)
{
int i;
static char str[SKEY_MAX_CHALLENGE];
@@ -358,9 +348,7 @@ skey_keyinfo(username)
*
*/
int
-skey_passcheck(username, passwd)
- char *username;
- char *passwd;
+skey_passcheck(char *username, char *passwd)
{
int i;
struct skey skey;
@@ -382,8 +370,7 @@ skey_passcheck(username, passwd)
* hash_collapse()
*/
static u_int32_t
-hash_collapse(s)
- u_char *s;
+hash_collapse(u_char *s)
{
int len, target;
u_int32_t i;
@@ -406,9 +393,7 @@ hash_collapse(s)
*
*/
static void
-skey_fakeprompt(username, skeyprompt)
- char *username;
- char *skeyprompt;
+skey_fakeprompt(char *username, char *skeyprompt)
{
int i;
u_int ptr;
@@ -530,8 +515,7 @@ skey_fakeprompt(username, skeyprompt)
*
*/
int
-skey_authenticate(username)
- char *username;
+skey_authenticate(char *username)
{
int i;
char pbuf[SKEY_MAX_PW_LEN+1], skeyprompt[SKEY_MAX_CHALLENGE+1];
@@ -567,8 +551,7 @@ skey_authenticate(username)
* 0: record was successfully unlocked
*/
int
-skey_unlock(mp)
- struct skey *mp;
+skey_unlock(struct skey *mp)
{
if (mp->logname == NULL || mp->keyfile == NULL)
return (-1);
@@ -580,11 +563,7 @@ skey_unlock(mp)
* Get a line of input (optionally timing out) and place it in buf.
*/
static char *
-tgetline(fd, buf, bufsiz, timeout)
- int fd;
- char *buf;
- size_t bufsiz;
- int timeout;
+tgetline(int fd, char *buf, size_t bufsiz, int timeout)
{
size_t left;
int n;
diff --git a/lib/libskey/skeysubr.c b/lib/libskey/skeysubr.c
index 1b9cce1980a..30e38a0bd92 100644
--- a/lib/libskey/skeysubr.c
+++ b/lib/libskey/skeysubr.c
@@ -9,7 +9,7 @@
*
* S/Key misc routines.
*
- * $OpenBSD: skeysubr.c,v 1.25 2002/05/29 18:53:15 deraadt Exp $
+ * $OpenBSD: skeysubr.c,v 1.26 2003/04/03 17:48:50 millert Exp $
*/
#include <stdio.h>
@@ -61,23 +61,19 @@ static struct skey_algorithm_table skey_algorithm_table[] = {
/*
* Crunch a key:
- * concatenate the seed and the password, run through hash function and
- * collapse to 64 bits. This is defined as the user's starting key.
+ * Concatenate the seed and the password, run through hash function and
+ * collapse to 64 bits. This is defined as the user's starting key.
+ * The result pointer must have at least SKEY_BINKEY_SIZE bytes of storage.
+ * The seed and password may be of any length.
*/
int
-keycrunch(result, seed, passwd)
- char *result; /* SKEY_BINKEY_SIZE result */
- char *seed; /* Seed, any length */
- char *passwd; /* Password, any length */
+keycrunch(char *result, char *seed, char *passwd)
{
return(skey_algorithm_table[skey_hash_type].keycrunch(result, seed, passwd));
}
static int
-keycrunch_md4(result, seed, passwd)
- char *result; /* SKEY_BINKEY_SIZE result */
- char *seed; /* Seed, any length */
- char *passwd; /* Password, any length */
+keycrunch_md4(char *result, char *seed, char *passwd)
{
char *buf = NULL;
MD4_CTX md;
@@ -119,10 +115,7 @@ keycrunch_md4(result, seed, passwd)
}
static int
-keycrunch_md5(result, seed, passwd)
- char *result; /* SKEY_BINKEY_SIZE result */
- char *seed; /* Seed, any length */
- char *passwd; /* Password, any length */
+keycrunch_md5(char *result, char *seed, char *passwd)
{
char *buf;
MD5_CTX md;
@@ -164,10 +157,7 @@ keycrunch_md5(result, seed, passwd)
}
static int
-keycrunch_sha1(result, seed, passwd)
- char *result; /* SKEY_BINKEY_SIZE result */
- char *seed; /* Seed, any length */
- char *passwd; /* Password, any length */
+keycrunch_sha1(char *result, char *seed, char *passwd)
{
char *buf;
SHA1_CTX sha;
@@ -220,10 +210,7 @@ keycrunch_sha1(result, seed, passwd)
}
static int
-keycrunch_rmd160(result, seed, passwd)
- char *result; /* SKEY_BINKEY_SIZE result */
- char *seed; /* Seed, any length */
- char *passwd; /* Password, any length */
+keycrunch_rmd160(char *result, char *seed, char *passwd)
{
char *buf;
RMD160_CTX rmd;
@@ -270,16 +257,14 @@ keycrunch_rmd160(result, seed, passwd)
* Takes SKEY_BINKEY_SIZE bytes and returns SKEY_BINKEY_SIZE bytes in place.
*/
void
-f(x)
- char *x;
+f(char *x)
{
(void)skey_algorithm_table[skey_hash_type].keycrunch(x, NULL, NULL);
}
/* Strip trailing cr/lf from a line of text */
void
-rip(buf)
- char *buf;
+rip(char *buf)
{
buf += strcspn(buf, "\r\n");
@@ -289,9 +274,7 @@ rip(buf)
/* Read in secret password (turns off echo) */
char *
-readpass(buf, n)
- char *buf;
- int n;
+readpass(char *buf, int n)
{
void (*old_handler)();
@@ -319,9 +302,7 @@ readpass(buf, n)
/* Read in an s/key OTP (does not turn off echo) */
char *
-readskey(buf, n)
- char *buf;
- int n;
+readskey(char *buf, int n)
{
(void)fgets(buf, n, stdin);
rip(buf);
@@ -333,8 +314,7 @@ readskey(buf, n)
/* Signal handler for trapping ^C */
static void
-trapped(sig)
- int sig;
+trapped(int sig)
{
write(STDERR_FILENO, "^C\n", 3);
@@ -345,13 +325,11 @@ trapped(sig)
}
/*
- * Convert 8-byte hex-ascii string to binary array
+ * Convert 16-byte hex-ascii string to 8-byte binary array
* Returns 0 on success, -1 on error
*/
int
-atob8(out, in)
- char *out;
- char *in;
+atob8(char *out, char *in)
{
int i;
int val;
@@ -375,28 +353,23 @@ atob8(out, in)
return(0);
}
-/* Convert 8-byte binary array to hex-ascii string */
+/* Convert 8-byte binary array to 16-byte hex-ascii string */
int
-btoa8(out, in)
- char *out;
- char *in;
+btoa8(char *out, char *in)
{
- int i;
-
if (in == NULL || out == NULL)
return(-1);
- for (i=0; i < 8; i++) {
- (void)sprintf(out, "%02x", *in++ & 0xff);
- out += 2;
- }
+ (void)snprintf(out, 17, "%02x%02x%02x%02x%02x%02x%02x%02x",
+ in[0] & 0xff, in[1] & 0xff, in[2] & 0xff, in[3] & 0xff,
+ in[4] & 0xff, in[5] & 0xff, in[6] & 0xff, in[7] & 0xff);
+
return(0);
}
/* Convert hex digit to binary integer */
int
-htoi(c)
- int c;
+htoi(int c)
{
if ('0' <= c && c <= '9')
return(c - '0');
@@ -409,8 +382,7 @@ htoi(c)
/* Skip leading spaces from the string */
char *
-skipspace(cp)
- char *cp;
+skipspace(char *cp)
{
while (*cp == ' ' || *cp == '\t')
cp++;
@@ -423,8 +395,7 @@ skipspace(cp)
/* Remove backspaced over characters from the string */
void
-backspace(buf)
- char *buf;
+backspace(char *buf)
{
char bs = 0x8;
char *cp = buf;
@@ -449,8 +420,7 @@ backspace(buf)
/* Make sure line is all seven bits */
void
-sevenbit(s)
- char *s;
+sevenbit(char *s)
{
while (*s)
*s++ &= 0x7f;
@@ -458,8 +428,7 @@ sevenbit(s)
/* Set hash algorithm type */
char *
-skey_set_algorithm(new)
- char *new;
+skey_set_algorithm(char *new)
{
int i;
@@ -475,15 +444,14 @@ skey_set_algorithm(new)
/* Get current hash type */
const char *
-skey_get_algorithm()
+skey_get_algorithm(void)
{
return(skey_algorithm_table[skey_hash_type].name);
}
/* Turn echo on/off */
static void
-skey_echo(action)
- int action;
+skey_echo(int action)
{
static struct termios term;
static int echo = 0;
@@ -505,12 +473,12 @@ skey_echo(action)
/* Convert string to lower case */
static void
-lowcase(s)
- char *s;
+lowcase(char *s)
{
char *p;
- for (p = s; *p; p++)
+ for (p = s; *p; p++) {
if (isupper(*p))
*p = tolower(*p);
+ }
}